]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.13.9-201404111815.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.9-201404111815.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 b9e9bd8..bf49b92 100644
239 --- a/Documentation/kernel-parameters.txt
240 +++ b/Documentation/kernel-parameters.txt
241 @@ -1033,6 +1033,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 @@ -2018,6 +2022,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 @@ -2285,6 +2293,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 652f972..20ef4fb 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 @@ -311,9 +312,15 @@ endif
306 # If the user is running make -s (silent mode), suppress echoing of
307 # commands
308
309 +ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
310 +ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
311 + quiet=silent_
312 +endif
313 +else # make-3.8x
314 ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
315 quiet=silent_
316 endif
317 +endif
318
319 export quiet Q KBUILD_VERBOSE
320
321 @@ -417,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
322 # Rules shared between *config targets and build targets
323
324 # Basic helpers built in scripts/
325 -PHONY += scripts_basic
326 -scripts_basic:
327 +PHONY += scripts_basic gcc-plugins
328 +scripts_basic: gcc-plugins
329 $(Q)$(MAKE) $(build)=scripts/basic
330 $(Q)rm -f .tmp_quiet_recordmcount
331
332 @@ -579,6 +586,72 @@ else
333 KBUILD_CFLAGS += -O2
334 endif
335
336 +ifndef DISABLE_PAX_PLUGINS
337 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
338 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
339 +else
340 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
341 +endif
342 +ifneq ($(PLUGINCC),)
343 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
344 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
345 +endif
346 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
347 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
348 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
349 +endif
350 +ifdef CONFIG_KALLOCSTAT_PLUGIN
351 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
352 +endif
353 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
354 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
355 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
356 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
357 +endif
358 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
359 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
360 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
361 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
362 +endif
363 +endif
364 +ifdef CONFIG_CHECKER_PLUGIN
365 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
366 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
367 +endif
368 +endif
369 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
370 +ifdef CONFIG_PAX_SIZE_OVERFLOW
371 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
372 +endif
373 +ifdef CONFIG_PAX_LATENT_ENTROPY
374 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
375 +endif
376 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
377 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
378 +endif
379 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
380 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
381 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
382 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
383 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
384 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
385 +ifeq ($(KBUILD_EXTMOD),)
386 +gcc-plugins:
387 + $(Q)$(MAKE) $(build)=tools/gcc
388 +else
389 +gcc-plugins: ;
390 +endif
391 +else
392 +gcc-plugins:
393 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
394 + $(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.))
395 +else
396 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
397 +endif
398 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
399 +endif
400 +endif
401 +
402 include $(srctree)/arch/$(SRCARCH)/Makefile
403
404 ifdef CONFIG_READABLE_ASM
405 @@ -619,7 +692,7 @@ endif
406
407 ifdef CONFIG_DEBUG_INFO
408 KBUILD_CFLAGS += -g
409 -KBUILD_AFLAGS += -gdwarf-2
410 +KBUILD_AFLAGS += -Wa,--gdwarf-2
411 endif
412
413 ifdef CONFIG_DEBUG_INFO_REDUCED
414 @@ -754,7 +827,7 @@ export mod_sign_cmd
415
416
417 ifeq ($(KBUILD_EXTMOD),)
418 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
419 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
420
421 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
422 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
423 @@ -803,6 +876,8 @@ endif
424
425 # The actual objects are generated when descending,
426 # make sure no implicit rule kicks in
427 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
428 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
429 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
430
431 # Handle descending into subdirectories listed in $(vmlinux-dirs)
432 @@ -812,7 +887,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
433 # Error messages still appears in the original language
434
435 PHONY += $(vmlinux-dirs)
436 -$(vmlinux-dirs): prepare scripts
437 +$(vmlinux-dirs): gcc-plugins prepare scripts
438 $(Q)$(MAKE) $(build)=$@
439
440 define filechk_kernel.release
441 @@ -855,10 +930,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
442
443 archprepare: archheaders archscripts prepare1 scripts_basic
444
445 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
446 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
447 prepare0: archprepare FORCE
448 $(Q)$(MAKE) $(build)=.
449
450 # All the preparing..
451 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
452 prepare: prepare0
453
454 # Generate some files
455 @@ -966,6 +1044,8 @@ all: modules
456 # using awk while concatenating to the final file.
457
458 PHONY += modules
459 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
460 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
461 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
462 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
463 @$(kecho) ' Building modules, stage 2.';
464 @@ -981,7 +1061,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
465
466 # Target to prepare building external modules
467 PHONY += modules_prepare
468 -modules_prepare: prepare scripts
469 +modules_prepare: gcc-plugins prepare scripts
470
471 # Target to install modules
472 PHONY += modules_install
473 @@ -1047,7 +1127,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
474 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
475 signing_key.priv signing_key.x509 x509.genkey \
476 extra_certificates signing_key.x509.keyid \
477 - signing_key.x509.signer
478 + signing_key.x509.signer tools/gcc/size_overflow_hash.h \
479 + tools/gcc/randomize_layout_seed.h
480
481 # clean - Delete most, but leave enough to build external modules
482 #
483 @@ -1087,6 +1168,7 @@ distclean: mrproper
484 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
485 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
486 -o -name '.*.rej' \
487 + -o -name '.*.rej' -o -name '*.so' \
488 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
489 -type f -print | xargs rm -f
490
491 @@ -1248,6 +1330,8 @@ PHONY += $(module-dirs) modules
492 $(module-dirs): crmodverdir $(objtree)/Module.symvers
493 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
494
495 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
496 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
497 modules: $(module-dirs)
498 @$(kecho) ' Building modules, stage 2.';
499 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
500 @@ -1387,17 +1471,21 @@ else
501 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
502 endif
503
504 -%.s: %.c prepare scripts FORCE
505 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
506 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
507 +%.s: %.c gcc-plugins prepare scripts FORCE
508 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
509 %.i: %.c prepare scripts FORCE
510 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
511 -%.o: %.c prepare scripts FORCE
512 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514 +%.o: %.c gcc-plugins prepare scripts FORCE
515 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
516 %.lst: %.c prepare scripts FORCE
517 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
518 -%.s: %.S prepare scripts FORCE
519 +%.s: %.S gcc-plugins prepare scripts FORCE
520 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
521 -%.o: %.S prepare scripts FORCE
522 +%.o: %.S gcc-plugins prepare scripts FORCE
523 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
524 %.symtypes: %.c prepare scripts FORCE
525 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
526 @@ -1407,11 +1495,15 @@ endif
527 $(cmd_crmodverdir)
528 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
529 $(build)=$(build-dir)
530 -%/: prepare scripts FORCE
531 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
532 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
533 +%/: gcc-plugins prepare scripts FORCE
534 $(cmd_crmodverdir)
535 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
536 $(build)=$(build-dir)
537 -%.ko: prepare scripts FORCE
538 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
539 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
540 +%.ko: gcc-plugins prepare scripts FORCE
541 $(cmd_crmodverdir)
542 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
543 $(build)=$(build-dir) $(@:.ko=.o)
544 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
545 index 78b03ef..da28a51 100644
546 --- a/arch/alpha/include/asm/atomic.h
547 +++ b/arch/alpha/include/asm/atomic.h
548 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
549 #define atomic_dec(v) atomic_sub(1,(v))
550 #define atomic64_dec(v) atomic64_sub(1,(v))
551
552 +#define atomic64_read_unchecked(v) atomic64_read(v)
553 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
554 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
555 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
556 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
557 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
558 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
559 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
560 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
561 +
562 #define smp_mb__before_atomic_dec() smp_mb()
563 #define smp_mb__after_atomic_dec() smp_mb()
564 #define smp_mb__before_atomic_inc() smp_mb()
565 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
566 index ad368a9..fbe0f25 100644
567 --- a/arch/alpha/include/asm/cache.h
568 +++ b/arch/alpha/include/asm/cache.h
569 @@ -4,19 +4,19 @@
570 #ifndef __ARCH_ALPHA_CACHE_H
571 #define __ARCH_ALPHA_CACHE_H
572
573 +#include <linux/const.h>
574
575 /* Bytes per L1 (data) cache line. */
576 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
577 -# define L1_CACHE_BYTES 64
578 # define L1_CACHE_SHIFT 6
579 #else
580 /* Both EV4 and EV5 are write-through, read-allocate,
581 direct-mapped, physical.
582 */
583 -# define L1_CACHE_BYTES 32
584 # define L1_CACHE_SHIFT 5
585 #endif
586
587 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
588 #define SMP_CACHE_BYTES L1_CACHE_BYTES
589
590 #endif
591 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
592 index 968d999..d36b2df 100644
593 --- a/arch/alpha/include/asm/elf.h
594 +++ b/arch/alpha/include/asm/elf.h
595 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
596
597 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
598
599 +#ifdef CONFIG_PAX_ASLR
600 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
601 +
602 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
603 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
604 +#endif
605 +
606 /* $0 is set by ld.so to a pointer to a function which might be
607 registered using atexit. This provides a mean for the dynamic
608 linker to call DT_FINI functions for shared libraries that have
609 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
610 index aab14a0..b4fa3e7 100644
611 --- a/arch/alpha/include/asm/pgalloc.h
612 +++ b/arch/alpha/include/asm/pgalloc.h
613 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
614 pgd_set(pgd, pmd);
615 }
616
617 +static inline void
618 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
619 +{
620 + pgd_populate(mm, pgd, pmd);
621 +}
622 +
623 extern pgd_t *pgd_alloc(struct mm_struct *mm);
624
625 static inline void
626 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
627 index d8f9b7e..f6222fa 100644
628 --- a/arch/alpha/include/asm/pgtable.h
629 +++ b/arch/alpha/include/asm/pgtable.h
630 @@ -102,6 +102,17 @@ struct vm_area_struct;
631 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
632 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
633 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
634 +
635 +#ifdef CONFIG_PAX_PAGEEXEC
636 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
637 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
638 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
639 +#else
640 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
641 +# define PAGE_COPY_NOEXEC PAGE_COPY
642 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
643 +#endif
644 +
645 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
646
647 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
648 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
649 index 2fd00b7..cfd5069 100644
650 --- a/arch/alpha/kernel/module.c
651 +++ b/arch/alpha/kernel/module.c
652 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
653
654 /* The small sections were sorted to the end of the segment.
655 The following should definitely cover them. */
656 - gp = (u64)me->module_core + me->core_size - 0x8000;
657 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
658 got = sechdrs[me->arch.gotsecindex].sh_addr;
659
660 for (i = 0; i < n; i++) {
661 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
662 index 1402fcc..0b1abd2 100644
663 --- a/arch/alpha/kernel/osf_sys.c
664 +++ b/arch/alpha/kernel/osf_sys.c
665 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
666 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
667
668 static unsigned long
669 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
670 - unsigned long limit)
671 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
672 + unsigned long limit, unsigned long flags)
673 {
674 struct vm_unmapped_area_info info;
675 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
676
677 info.flags = 0;
678 info.length = len;
679 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
680 info.high_limit = limit;
681 info.align_mask = 0;
682 info.align_offset = 0;
683 + info.threadstack_offset = offset;
684 return vm_unmapped_area(&info);
685 }
686
687 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
688 merely specific addresses, but regions of memory -- perhaps
689 this feature should be incorporated into all ports? */
690
691 +#ifdef CONFIG_PAX_RANDMMAP
692 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
693 +#endif
694 +
695 if (addr) {
696 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
697 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
698 if (addr != (unsigned long) -ENOMEM)
699 return addr;
700 }
701
702 /* Next, try allocating at TASK_UNMAPPED_BASE. */
703 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
704 - len, limit);
705 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
706 +
707 if (addr != (unsigned long) -ENOMEM)
708 return addr;
709
710 /* Finally, try allocating in low memory. */
711 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
712 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
713
714 return addr;
715 }
716 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
717 index 98838a0..b304fb4 100644
718 --- a/arch/alpha/mm/fault.c
719 +++ b/arch/alpha/mm/fault.c
720 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
721 __reload_thread(pcb);
722 }
723
724 +#ifdef CONFIG_PAX_PAGEEXEC
725 +/*
726 + * PaX: decide what to do with offenders (regs->pc = fault address)
727 + *
728 + * returns 1 when task should be killed
729 + * 2 when patched PLT trampoline was detected
730 + * 3 when unpatched PLT trampoline was detected
731 + */
732 +static int pax_handle_fetch_fault(struct pt_regs *regs)
733 +{
734 +
735 +#ifdef CONFIG_PAX_EMUPLT
736 + int err;
737 +
738 + do { /* PaX: patched PLT emulation #1 */
739 + unsigned int ldah, ldq, jmp;
740 +
741 + err = get_user(ldah, (unsigned int *)regs->pc);
742 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
743 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
744 +
745 + if (err)
746 + break;
747 +
748 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
749 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
750 + jmp == 0x6BFB0000U)
751 + {
752 + unsigned long r27, addr;
753 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
754 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
755 +
756 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
757 + err = get_user(r27, (unsigned long *)addr);
758 + if (err)
759 + break;
760 +
761 + regs->r27 = r27;
762 + regs->pc = r27;
763 + return 2;
764 + }
765 + } while (0);
766 +
767 + do { /* PaX: patched PLT emulation #2 */
768 + unsigned int ldah, lda, br;
769 +
770 + err = get_user(ldah, (unsigned int *)regs->pc);
771 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
772 + err |= get_user(br, (unsigned int *)(regs->pc+8));
773 +
774 + if (err)
775 + break;
776 +
777 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
778 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
779 + (br & 0xFFE00000U) == 0xC3E00000U)
780 + {
781 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
782 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
783 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
784 +
785 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
786 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
787 + return 2;
788 + }
789 + } while (0);
790 +
791 + do { /* PaX: unpatched PLT emulation */
792 + unsigned int br;
793 +
794 + err = get_user(br, (unsigned int *)regs->pc);
795 +
796 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
797 + unsigned int br2, ldq, nop, jmp;
798 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
799 +
800 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
801 + err = get_user(br2, (unsigned int *)addr);
802 + err |= get_user(ldq, (unsigned int *)(addr+4));
803 + err |= get_user(nop, (unsigned int *)(addr+8));
804 + err |= get_user(jmp, (unsigned int *)(addr+12));
805 + err |= get_user(resolver, (unsigned long *)(addr+16));
806 +
807 + if (err)
808 + break;
809 +
810 + if (br2 == 0xC3600000U &&
811 + ldq == 0xA77B000CU &&
812 + nop == 0x47FF041FU &&
813 + jmp == 0x6B7B0000U)
814 + {
815 + regs->r28 = regs->pc+4;
816 + regs->r27 = addr+16;
817 + regs->pc = resolver;
818 + return 3;
819 + }
820 + }
821 + } while (0);
822 +#endif
823 +
824 + return 1;
825 +}
826 +
827 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
828 +{
829 + unsigned long i;
830 +
831 + printk(KERN_ERR "PAX: bytes at PC: ");
832 + for (i = 0; i < 5; i++) {
833 + unsigned int c;
834 + if (get_user(c, (unsigned int *)pc+i))
835 + printk(KERN_CONT "???????? ");
836 + else
837 + printk(KERN_CONT "%08x ", c);
838 + }
839 + printk("\n");
840 +}
841 +#endif
842
843 /*
844 * This routine handles page faults. It determines the address,
845 @@ -133,8 +251,29 @@ retry:
846 good_area:
847 si_code = SEGV_ACCERR;
848 if (cause < 0) {
849 - if (!(vma->vm_flags & VM_EXEC))
850 + if (!(vma->vm_flags & VM_EXEC)) {
851 +
852 +#ifdef CONFIG_PAX_PAGEEXEC
853 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
854 + goto bad_area;
855 +
856 + up_read(&mm->mmap_sem);
857 + switch (pax_handle_fetch_fault(regs)) {
858 +
859 +#ifdef CONFIG_PAX_EMUPLT
860 + case 2:
861 + case 3:
862 + return;
863 +#endif
864 +
865 + }
866 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
867 + do_group_exit(SIGKILL);
868 +#else
869 goto bad_area;
870 +#endif
871 +
872 + }
873 } else if (!cause) {
874 /* Allow reads even for write-only mappings */
875 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
876 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
877 index 47085a0..f975a53 100644
878 --- a/arch/arm/Kconfig
879 +++ b/arch/arm/Kconfig
880 @@ -1830,7 +1830,7 @@ config ALIGNMENT_TRAP
881
882 config UACCESS_WITH_MEMCPY
883 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
884 - depends on MMU
885 + depends on MMU && !PAX_MEMORY_UDEREF
886 default y if CPU_FEROCEON
887 help
888 Implement faster copy_to_user and clear_user methods for CPU
889 @@ -2102,6 +2102,7 @@ config XIP_PHYS_ADDR
890 config KEXEC
891 bool "Kexec system call (EXPERIMENTAL)"
892 depends on (!SMP || PM_SLEEP_SMP)
893 + depends on !GRKERNSEC_KMEM
894 help
895 kexec is a system call that implements the ability to shutdown your
896 current kernel, and to start another kernel. It is like a reboot
897 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
898 index 62d2cb5..09d45e3 100644
899 --- a/arch/arm/include/asm/atomic.h
900 +++ b/arch/arm/include/asm/atomic.h
901 @@ -18,17 +18,35 @@
902 #include <asm/barrier.h>
903 #include <asm/cmpxchg.h>
904
905 +#ifdef CONFIG_GENERIC_ATOMIC64
906 +#include <asm-generic/atomic64.h>
907 +#endif
908 +
909 #define ATOMIC_INIT(i) { (i) }
910
911 #ifdef __KERNEL__
912
913 +#define _ASM_EXTABLE(from, to) \
914 +" .pushsection __ex_table,\"a\"\n"\
915 +" .align 3\n" \
916 +" .long " #from ", " #to"\n" \
917 +" .popsection"
918 +
919 /*
920 * On ARM, ordinary assignment (str instruction) doesn't clear the local
921 * strex/ldrex monitor on some implementations. The reason we can use it for
922 * atomic_set() is the clrex or dummy strex done on every exception return.
923 */
924 #define atomic_read(v) (*(volatile int *)&(v)->counter)
925 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
926 +{
927 + return v->counter;
928 +}
929 #define atomic_set(v,i) (((v)->counter) = (i))
930 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
931 +{
932 + v->counter = i;
933 +}
934
935 #if __LINUX_ARM_ARCH__ >= 6
936
937 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
938
939 prefetchw(&v->counter);
940 __asm__ __volatile__("@ atomic_add\n"
941 +"1: ldrex %1, [%3]\n"
942 +" adds %0, %1, %4\n"
943 +
944 +#ifdef CONFIG_PAX_REFCOUNT
945 +" bvc 3f\n"
946 +"2: bkpt 0xf103\n"
947 +"3:\n"
948 +#endif
949 +
950 +" strex %1, %0, [%3]\n"
951 +" teq %1, #0\n"
952 +" bne 1b"
953 +
954 +#ifdef CONFIG_PAX_REFCOUNT
955 +"\n4:\n"
956 + _ASM_EXTABLE(2b, 4b)
957 +#endif
958 +
959 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
960 + : "r" (&v->counter), "Ir" (i)
961 + : "cc");
962 +}
963 +
964 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
965 +{
966 + unsigned long tmp;
967 + int result;
968 +
969 + prefetchw(&v->counter);
970 + __asm__ __volatile__("@ atomic_add_unchecked\n"
971 "1: ldrex %0, [%3]\n"
972 " add %0, %0, %4\n"
973 " strex %1, %0, [%3]\n"
974 @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
975 smp_mb();
976
977 __asm__ __volatile__("@ atomic_add_return\n"
978 +"1: ldrex %1, [%3]\n"
979 +" adds %0, %1, %4\n"
980 +
981 +#ifdef CONFIG_PAX_REFCOUNT
982 +" bvc 3f\n"
983 +" mov %0, %1\n"
984 +"2: bkpt 0xf103\n"
985 +"3:\n"
986 +#endif
987 +
988 +" strex %1, %0, [%3]\n"
989 +" teq %1, #0\n"
990 +" bne 1b"
991 +
992 +#ifdef CONFIG_PAX_REFCOUNT
993 +"\n4:\n"
994 + _ASM_EXTABLE(2b, 4b)
995 +#endif
996 +
997 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
998 + : "r" (&v->counter), "Ir" (i)
999 + : "cc");
1000 +
1001 + smp_mb();
1002 +
1003 + return result;
1004 +}
1005 +
1006 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1007 +{
1008 + unsigned long tmp;
1009 + int result;
1010 +
1011 + smp_mb();
1012 +
1013 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1014 "1: ldrex %0, [%3]\n"
1015 " add %0, %0, %4\n"
1016 " strex %1, %0, [%3]\n"
1017 @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1018
1019 prefetchw(&v->counter);
1020 __asm__ __volatile__("@ atomic_sub\n"
1021 +"1: ldrex %1, [%3]\n"
1022 +" subs %0, %1, %4\n"
1023 +
1024 +#ifdef CONFIG_PAX_REFCOUNT
1025 +" bvc 3f\n"
1026 +"2: bkpt 0xf103\n"
1027 +"3:\n"
1028 +#endif
1029 +
1030 +" strex %1, %0, [%3]\n"
1031 +" teq %1, #0\n"
1032 +" bne 1b"
1033 +
1034 +#ifdef CONFIG_PAX_REFCOUNT
1035 +"\n4:\n"
1036 + _ASM_EXTABLE(2b, 4b)
1037 +#endif
1038 +
1039 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1040 + : "r" (&v->counter), "Ir" (i)
1041 + : "cc");
1042 +}
1043 +
1044 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1045 +{
1046 + unsigned long tmp;
1047 + int result;
1048 +
1049 + prefetchw(&v->counter);
1050 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1051 "1: ldrex %0, [%3]\n"
1052 " sub %0, %0, %4\n"
1053 " strex %1, %0, [%3]\n"
1054 @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1055 smp_mb();
1056
1057 __asm__ __volatile__("@ atomic_sub_return\n"
1058 -"1: ldrex %0, [%3]\n"
1059 -" sub %0, %0, %4\n"
1060 +"1: ldrex %1, [%3]\n"
1061 +" subs %0, %1, %4\n"
1062 +
1063 +#ifdef CONFIG_PAX_REFCOUNT
1064 +" bvc 3f\n"
1065 +" mov %0, %1\n"
1066 +"2: bkpt 0xf103\n"
1067 +"3:\n"
1068 +#endif
1069 +
1070 " strex %1, %0, [%3]\n"
1071 " teq %1, #0\n"
1072 " bne 1b"
1073 +
1074 +#ifdef CONFIG_PAX_REFCOUNT
1075 +"\n4:\n"
1076 + _ASM_EXTABLE(2b, 4b)
1077 +#endif
1078 +
1079 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1080 : "r" (&v->counter), "Ir" (i)
1081 : "cc");
1082 @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1083 return oldval;
1084 }
1085
1086 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1087 +{
1088 + unsigned long oldval, res;
1089 +
1090 + smp_mb();
1091 +
1092 + do {
1093 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1094 + "ldrex %1, [%3]\n"
1095 + "mov %0, #0\n"
1096 + "teq %1, %4\n"
1097 + "strexeq %0, %5, [%3]\n"
1098 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1099 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1100 + : "cc");
1101 + } while (res);
1102 +
1103 + smp_mb();
1104 +
1105 + return oldval;
1106 +}
1107 +
1108 #else /* ARM_ARCH_6 */
1109
1110 #ifdef CONFIG_SMP
1111 @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1112
1113 return val;
1114 }
1115 +
1116 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1117 +{
1118 + return atomic_add_return(i, v);
1119 +}
1120 +
1121 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1122 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1123 +{
1124 + (void) atomic_add_return(i, v);
1125 +}
1126
1127 static inline int atomic_sub_return(int i, atomic_t *v)
1128 {
1129 @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1130 return val;
1131 }
1132 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1133 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1134 +{
1135 + (void) atomic_sub_return(i, v);
1136 +}
1137
1138 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1139 {
1140 @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1141 return ret;
1142 }
1143
1144 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1145 +{
1146 + return atomic_cmpxchg(v, old, new);
1147 +}
1148 +
1149 #endif /* __LINUX_ARM_ARCH__ */
1150
1151 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1152 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1153 +{
1154 + return xchg(&v->counter, new);
1155 +}
1156
1157 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1158 {
1159 @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1160 }
1161
1162 #define atomic_inc(v) atomic_add(1, v)
1163 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1164 +{
1165 + atomic_add_unchecked(1, v);
1166 +}
1167 #define atomic_dec(v) atomic_sub(1, v)
1168 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1169 +{
1170 + atomic_sub_unchecked(1, v);
1171 +}
1172
1173 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1174 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1175 +{
1176 + return atomic_add_return_unchecked(1, v) == 0;
1177 +}
1178 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1179 #define atomic_inc_return(v) (atomic_add_return(1, v))
1180 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1181 +{
1182 + return atomic_add_return_unchecked(1, v);
1183 +}
1184 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1185 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1186
1187 @@ -221,6 +410,14 @@ typedef struct {
1188 long long counter;
1189 } atomic64_t;
1190
1191 +#ifdef CONFIG_PAX_REFCOUNT
1192 +typedef struct {
1193 + long long counter;
1194 +} atomic64_unchecked_t;
1195 +#else
1196 +typedef atomic64_t atomic64_unchecked_t;
1197 +#endif
1198 +
1199 #define ATOMIC64_INIT(i) { (i) }
1200
1201 #ifdef CONFIG_ARM_LPAE
1202 @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1203 return result;
1204 }
1205
1206 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1207 +{
1208 + long long result;
1209 +
1210 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1211 +" ldrd %0, %H0, [%1]"
1212 + : "=&r" (result)
1213 + : "r" (&v->counter), "Qo" (v->counter)
1214 + );
1215 +
1216 + return result;
1217 +}
1218 +
1219 static inline void atomic64_set(atomic64_t *v, long long i)
1220 {
1221 __asm__ __volatile__("@ atomic64_set\n"
1222 @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1223 : "r" (&v->counter), "r" (i)
1224 );
1225 }
1226 +
1227 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1228 +{
1229 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1230 +" strd %2, %H2, [%1]"
1231 + : "=Qo" (v->counter)
1232 + : "r" (&v->counter), "r" (i)
1233 + );
1234 +}
1235 #else
1236 static inline long long atomic64_read(const atomic64_t *v)
1237 {
1238 @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1239 return result;
1240 }
1241
1242 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1243 +{
1244 + long long result;
1245 +
1246 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1247 +" ldrexd %0, %H0, [%1]"
1248 + : "=&r" (result)
1249 + : "r" (&v->counter), "Qo" (v->counter)
1250 + );
1251 +
1252 + return result;
1253 +}
1254 +
1255 static inline void atomic64_set(atomic64_t *v, long long i)
1256 {
1257 long long tmp;
1258 @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1259 : "r" (&v->counter), "r" (i)
1260 : "cc");
1261 }
1262 +
1263 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1264 +{
1265 + long long tmp;
1266 +
1267 + prefetchw(&v->counter);
1268 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1269 +"1: ldrexd %0, %H0, [%2]\n"
1270 +" strexd %0, %3, %H3, [%2]\n"
1271 +" teq %0, #0\n"
1272 +" bne 1b"
1273 + : "=&r" (tmp), "=Qo" (v->counter)
1274 + : "r" (&v->counter), "r" (i)
1275 + : "cc");
1276 +}
1277 #endif
1278
1279 static inline void atomic64_add(long long i, atomic64_t *v)
1280 @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1281 __asm__ __volatile__("@ atomic64_add\n"
1282 "1: ldrexd %0, %H0, [%3]\n"
1283 " adds %Q0, %Q0, %Q4\n"
1284 +" adcs %R0, %R0, %R4\n"
1285 +
1286 +#ifdef CONFIG_PAX_REFCOUNT
1287 +" bvc 3f\n"
1288 +"2: bkpt 0xf103\n"
1289 +"3:\n"
1290 +#endif
1291 +
1292 +" strexd %1, %0, %H0, [%3]\n"
1293 +" teq %1, #0\n"
1294 +" bne 1b"
1295 +
1296 +#ifdef CONFIG_PAX_REFCOUNT
1297 +"\n4:\n"
1298 + _ASM_EXTABLE(2b, 4b)
1299 +#endif
1300 +
1301 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1302 + : "r" (&v->counter), "r" (i)
1303 + : "cc");
1304 +}
1305 +
1306 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1307 +{
1308 + long long result;
1309 + unsigned long tmp;
1310 +
1311 + prefetchw(&v->counter);
1312 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1313 +"1: ldrexd %0, %H0, [%3]\n"
1314 +" adds %Q0, %Q0, %Q4\n"
1315 " adc %R0, %R0, %R4\n"
1316 " strexd %1, %0, %H0, [%3]\n"
1317 " teq %1, #0\n"
1318 @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_add_return\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " adds %Q0, %Q0, %Q4\n"
1322 +" adcs %R0, %R0, %R4\n"
1323 +
1324 +#ifdef CONFIG_PAX_REFCOUNT
1325 +" bvc 3f\n"
1326 +" mov %0, %1\n"
1327 +" mov %H0, %H1\n"
1328 +"2: bkpt 0xf103\n"
1329 +"3:\n"
1330 +#endif
1331 +
1332 +" strexd %1, %0, %H0, [%3]\n"
1333 +" teq %1, #0\n"
1334 +" bne 1b"
1335 +
1336 +#ifdef CONFIG_PAX_REFCOUNT
1337 +"\n4:\n"
1338 + _ASM_EXTABLE(2b, 4b)
1339 +#endif
1340 +
1341 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1342 + : "r" (&v->counter), "r" (i)
1343 + : "cc");
1344 +
1345 + smp_mb();
1346 +
1347 + return result;
1348 +}
1349 +
1350 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1351 +{
1352 + long long result;
1353 + unsigned long tmp;
1354 +
1355 + smp_mb();
1356 +
1357 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1358 +"1: ldrexd %0, %H0, [%3]\n"
1359 +" adds %Q0, %Q0, %Q4\n"
1360 " adc %R0, %R0, %R4\n"
1361 " strexd %1, %0, %H0, [%3]\n"
1362 " teq %1, #0\n"
1363 @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1364 __asm__ __volatile__("@ atomic64_sub\n"
1365 "1: ldrexd %0, %H0, [%3]\n"
1366 " subs %Q0, %Q0, %Q4\n"
1367 +" sbcs %R0, %R0, %R4\n"
1368 +
1369 +#ifdef CONFIG_PAX_REFCOUNT
1370 +" bvc 3f\n"
1371 +"2: bkpt 0xf103\n"
1372 +"3:\n"
1373 +#endif
1374 +
1375 +" strexd %1, %0, %H0, [%3]\n"
1376 +" teq %1, #0\n"
1377 +" bne 1b"
1378 +
1379 +#ifdef CONFIG_PAX_REFCOUNT
1380 +"\n4:\n"
1381 + _ASM_EXTABLE(2b, 4b)
1382 +#endif
1383 +
1384 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1385 + : "r" (&v->counter), "r" (i)
1386 + : "cc");
1387 +}
1388 +
1389 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1390 +{
1391 + long long result;
1392 + unsigned long tmp;
1393 +
1394 + prefetchw(&v->counter);
1395 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1396 +"1: ldrexd %0, %H0, [%3]\n"
1397 +" subs %Q0, %Q0, %Q4\n"
1398 " sbc %R0, %R0, %R4\n"
1399 " strexd %1, %0, %H0, [%3]\n"
1400 " teq %1, #0\n"
1401 @@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1402 __asm__ __volatile__("@ atomic64_sub_return\n"
1403 "1: ldrexd %0, %H0, [%3]\n"
1404 " subs %Q0, %Q0, %Q4\n"
1405 -" sbc %R0, %R0, %R4\n"
1406 +" sbcs %R0, %R0, %R4\n"
1407 +
1408 +#ifdef CONFIG_PAX_REFCOUNT
1409 +" bvc 3f\n"
1410 +" mov %0, %1\n"
1411 +" mov %H0, %H1\n"
1412 +"2: bkpt 0xf103\n"
1413 +"3:\n"
1414 +#endif
1415 +
1416 " strexd %1, %0, %H0, [%3]\n"
1417 " teq %1, #0\n"
1418 " bne 1b"
1419 +
1420 +#ifdef CONFIG_PAX_REFCOUNT
1421 +"\n4:\n"
1422 + _ASM_EXTABLE(2b, 4b)
1423 +#endif
1424 +
1425 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1426 : "r" (&v->counter), "r" (i)
1427 : "cc");
1428
1429 - smp_mb();
1430 -
1431 return result;
1432 }
1433
1434 @@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1435 return oldval;
1436 }
1437
1438 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1439 + long long new)
1440 +{
1441 + long long oldval;
1442 + unsigned long res;
1443 +
1444 + smp_mb();
1445 +
1446 + do {
1447 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1448 + "ldrexd %1, %H1, [%3]\n"
1449 + "mov %0, #0\n"
1450 + "teq %1, %4\n"
1451 + "teqeq %H1, %H4\n"
1452 + "strexdeq %0, %5, %H5, [%3]"
1453 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1454 + : "r" (&ptr->counter), "r" (old), "r" (new)
1455 + : "cc");
1456 + } while (res);
1457 +
1458 + smp_mb();
1459 +
1460 + return oldval;
1461 +}
1462 +
1463 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1464 {
1465 long long result;
1466 @@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1467 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1468 {
1469 long long result;
1470 - unsigned long tmp;
1471 + u64 tmp;
1472
1473 smp_mb();
1474
1475 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1476 -"1: ldrexd %0, %H0, [%3]\n"
1477 -" subs %Q0, %Q0, #1\n"
1478 -" sbc %R0, %R0, #0\n"
1479 +"1: ldrexd %1, %H1, [%3]\n"
1480 +" subs %Q0, %Q1, #1\n"
1481 +" sbcs %R0, %R1, #0\n"
1482 +
1483 +#ifdef CONFIG_PAX_REFCOUNT
1484 +" bvc 3f\n"
1485 +" mov %Q0, %Q1\n"
1486 +" mov %R0, %R1\n"
1487 +"2: bkpt 0xf103\n"
1488 +"3:\n"
1489 +#endif
1490 +
1491 " teq %R0, #0\n"
1492 -" bmi 2f\n"
1493 +" bmi 4f\n"
1494 " strexd %1, %0, %H0, [%3]\n"
1495 " teq %1, #0\n"
1496 " bne 1b\n"
1497 -"2:"
1498 +"4:\n"
1499 +
1500 +#ifdef CONFIG_PAX_REFCOUNT
1501 + _ASM_EXTABLE(2b, 4b)
1502 +#endif
1503 +
1504 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1505 : "r" (&v->counter)
1506 : "cc");
1507 @@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1508 " teq %0, %5\n"
1509 " teqeq %H0, %H5\n"
1510 " moveq %1, #0\n"
1511 -" beq 2f\n"
1512 +" beq 4f\n"
1513 " adds %Q0, %Q0, %Q6\n"
1514 -" adc %R0, %R0, %R6\n"
1515 +" adcs %R0, %R0, %R6\n"
1516 +
1517 +#ifdef CONFIG_PAX_REFCOUNT
1518 +" bvc 3f\n"
1519 +"2: bkpt 0xf103\n"
1520 +"3:\n"
1521 +#endif
1522 +
1523 " strexd %2, %0, %H0, [%4]\n"
1524 " teq %2, #0\n"
1525 " bne 1b\n"
1526 -"2:"
1527 +"4:\n"
1528 +
1529 +#ifdef CONFIG_PAX_REFCOUNT
1530 + _ASM_EXTABLE(2b, 4b)
1531 +#endif
1532 +
1533 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1534 : "r" (&v->counter), "r" (u), "r" (a)
1535 : "cc");
1536 @@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1537
1538 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1539 #define atomic64_inc(v) atomic64_add(1LL, (v))
1540 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1541 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1542 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1543 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1544 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1545 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1546 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1547 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1548 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1549 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1550 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1551 index 75fe66b..ba3dee4 100644
1552 --- a/arch/arm/include/asm/cache.h
1553 +++ b/arch/arm/include/asm/cache.h
1554 @@ -4,8 +4,10 @@
1555 #ifndef __ASMARM_CACHE_H
1556 #define __ASMARM_CACHE_H
1557
1558 +#include <linux/const.h>
1559 +
1560 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1561 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1562 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1563
1564 /*
1565 * Memory returned by kmalloc() may be used for DMA, so we must make
1566 @@ -24,5 +26,6 @@
1567 #endif
1568
1569 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1570 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1571
1572 #endif
1573 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1574 index ab91ebb..2c2afeb 100644
1575 --- a/arch/arm/include/asm/cacheflush.h
1576 +++ b/arch/arm/include/asm/cacheflush.h
1577 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1578 void (*dma_unmap_area)(const void *, size_t, int);
1579
1580 void (*dma_flush_range)(const void *, const void *);
1581 -};
1582 +} __no_const;
1583
1584 /*
1585 * Select the calling method
1586 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1587 index 6dcc164..b14d917 100644
1588 --- a/arch/arm/include/asm/checksum.h
1589 +++ b/arch/arm/include/asm/checksum.h
1590 @@ -37,7 +37,19 @@ __wsum
1591 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1592
1593 __wsum
1594 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1595 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1596 +
1597 +static inline __wsum
1598 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1599 +{
1600 + __wsum ret;
1601 + pax_open_userland();
1602 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1603 + pax_close_userland();
1604 + return ret;
1605 +}
1606 +
1607 +
1608
1609 /*
1610 * Fold a partial checksum without adding pseudo headers
1611 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1612 index df2fbba..63fe3e1 100644
1613 --- a/arch/arm/include/asm/cmpxchg.h
1614 +++ b/arch/arm/include/asm/cmpxchg.h
1615 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1616
1617 #define xchg(ptr,x) \
1618 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1619 +#define xchg_unchecked(ptr,x) \
1620 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1621
1622 #include <asm-generic/cmpxchg-local.h>
1623
1624 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1625 index 6ddbe44..b5e38b1 100644
1626 --- a/arch/arm/include/asm/domain.h
1627 +++ b/arch/arm/include/asm/domain.h
1628 @@ -48,18 +48,37 @@
1629 * Domain types
1630 */
1631 #define DOMAIN_NOACCESS 0
1632 -#define DOMAIN_CLIENT 1
1633 #ifdef CONFIG_CPU_USE_DOMAINS
1634 +#define DOMAIN_USERCLIENT 1
1635 +#define DOMAIN_KERNELCLIENT 1
1636 #define DOMAIN_MANAGER 3
1637 +#define DOMAIN_VECTORS DOMAIN_USER
1638 #else
1639 +
1640 +#ifdef CONFIG_PAX_KERNEXEC
1641 #define DOMAIN_MANAGER 1
1642 +#define DOMAIN_KERNEXEC 3
1643 +#else
1644 +#define DOMAIN_MANAGER 1
1645 +#endif
1646 +
1647 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1648 +#define DOMAIN_USERCLIENT 0
1649 +#define DOMAIN_UDEREF 1
1650 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1651 +#else
1652 +#define DOMAIN_USERCLIENT 1
1653 +#define DOMAIN_VECTORS DOMAIN_USER
1654 +#endif
1655 +#define DOMAIN_KERNELCLIENT 1
1656 +
1657 #endif
1658
1659 #define domain_val(dom,type) ((type) << (2*(dom)))
1660
1661 #ifndef __ASSEMBLY__
1662
1663 -#ifdef CONFIG_CPU_USE_DOMAINS
1664 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1665 static inline void set_domain(unsigned val)
1666 {
1667 asm volatile(
1668 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1669 isb();
1670 }
1671
1672 -#define modify_domain(dom,type) \
1673 - do { \
1674 - struct thread_info *thread = current_thread_info(); \
1675 - unsigned int domain = thread->cpu_domain; \
1676 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1677 - thread->cpu_domain = domain | domain_val(dom, type); \
1678 - set_domain(thread->cpu_domain); \
1679 - } while (0)
1680 -
1681 +extern void modify_domain(unsigned int dom, unsigned int type);
1682 #else
1683 static inline void set_domain(unsigned val) { }
1684 static inline void modify_domain(unsigned dom, unsigned type) { }
1685 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1686 index f4b46d3..abc9b2b 100644
1687 --- a/arch/arm/include/asm/elf.h
1688 +++ b/arch/arm/include/asm/elf.h
1689 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1690 the loader. We need to make sure that it is out of the way of the program
1691 that it will "exec", and that there is sufficient room for the brk. */
1692
1693 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1694 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1695 +
1696 +#ifdef CONFIG_PAX_ASLR
1697 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1698 +
1699 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1700 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1701 +#endif
1702
1703 /* When the program starts, a1 contains a pointer to a function to be
1704 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1705 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1706 extern void elf_set_personality(const struct elf32_hdr *);
1707 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1708
1709 -struct mm_struct;
1710 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1711 -#define arch_randomize_brk arch_randomize_brk
1712 -
1713 #ifdef CONFIG_MMU
1714 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1715 struct linux_binprm;
1716 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1717 index de53547..52b9a28 100644
1718 --- a/arch/arm/include/asm/fncpy.h
1719 +++ b/arch/arm/include/asm/fncpy.h
1720 @@ -81,7 +81,9 @@
1721 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1722 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1723 \
1724 + pax_open_kernel(); \
1725 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1726 + pax_close_kernel(); \
1727 flush_icache_range((unsigned long)(dest_buf), \
1728 (unsigned long)(dest_buf) + (size)); \
1729 \
1730 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1731 index e42cf59..7b94b8f 100644
1732 --- a/arch/arm/include/asm/futex.h
1733 +++ b/arch/arm/include/asm/futex.h
1734 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1735 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1736 return -EFAULT;
1737
1738 + pax_open_userland();
1739 +
1740 smp_mb();
1741 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1742 "1: ldrex %1, [%4]\n"
1743 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1744 : "cc", "memory");
1745 smp_mb();
1746
1747 + pax_close_userland();
1748 +
1749 *uval = val;
1750 return ret;
1751 }
1752 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1753 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1754 return -EFAULT;
1755
1756 + pax_open_userland();
1757 +
1758 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1759 "1: " TUSER(ldr) " %1, [%4]\n"
1760 " teq %1, %2\n"
1761 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1762 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1763 : "cc", "memory");
1764
1765 + pax_close_userland();
1766 +
1767 *uval = val;
1768 return ret;
1769 }
1770 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 return -EFAULT;
1772
1773 pagefault_disable(); /* implies preempt_disable() */
1774 + pax_open_userland();
1775
1776 switch (op) {
1777 case FUTEX_OP_SET:
1778 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1779 ret = -ENOSYS;
1780 }
1781
1782 + pax_close_userland();
1783 pagefault_enable(); /* subsumes preempt_enable() */
1784
1785 if (!ret) {
1786 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1787 index 83eb2f7..ed77159 100644
1788 --- a/arch/arm/include/asm/kmap_types.h
1789 +++ b/arch/arm/include/asm/kmap_types.h
1790 @@ -4,6 +4,6 @@
1791 /*
1792 * This is the "bare minimum". AIO seems to require this.
1793 */
1794 -#define KM_TYPE_NR 16
1795 +#define KM_TYPE_NR 17
1796
1797 #endif
1798 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1799 index 9e614a1..3302cca 100644
1800 --- a/arch/arm/include/asm/mach/dma.h
1801 +++ b/arch/arm/include/asm/mach/dma.h
1802 @@ -22,7 +22,7 @@ struct dma_ops {
1803 int (*residue)(unsigned int, dma_t *); /* optional */
1804 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1805 const char *type;
1806 -};
1807 +} __do_const;
1808
1809 struct dma_struct {
1810 void *addr; /* single DMA address */
1811 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1812 index 2fe141f..192dc01 100644
1813 --- a/arch/arm/include/asm/mach/map.h
1814 +++ b/arch/arm/include/asm/mach/map.h
1815 @@ -27,13 +27,16 @@ struct map_desc {
1816 #define MT_MINICLEAN 6
1817 #define MT_LOW_VECTORS 7
1818 #define MT_HIGH_VECTORS 8
1819 -#define MT_MEMORY 9
1820 +#define MT_MEMORY_RWX 9
1821 #define MT_ROM 10
1822 -#define MT_MEMORY_NONCACHED 11
1823 +#define MT_MEMORY_NONCACHED_RX 11
1824 #define MT_MEMORY_DTCM 12
1825 #define MT_MEMORY_ITCM 13
1826 #define MT_MEMORY_SO 14
1827 #define MT_MEMORY_DMA_READY 15
1828 +#define MT_MEMORY_RW 16
1829 +#define MT_MEMORY_RX 17
1830 +#define MT_MEMORY_NONCACHED_RW 18
1831
1832 #ifdef CONFIG_MMU
1833 extern void iotable_init(struct map_desc *, int);
1834 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835 index f94784f..9a09a4a 100644
1836 --- a/arch/arm/include/asm/outercache.h
1837 +++ b/arch/arm/include/asm/outercache.h
1838 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1839 #endif
1840 void (*set_debug)(unsigned long);
1841 void (*resume)(void);
1842 -};
1843 +} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848 index 4355f0e..cd9168e 100644
1849 --- a/arch/arm/include/asm/page.h
1850 +++ b/arch/arm/include/asm/page.h
1851 @@ -23,6 +23,7 @@
1852
1853 #else
1854
1855 +#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863 -};
1864 +} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869 index 78a7793..e3dc06c 100644
1870 --- a/arch/arm/include/asm/pgalloc.h
1871 +++ b/arch/arm/include/asm/pgalloc.h
1872 @@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876 +#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885 +{
1886 + pud_populate(mm, pud, pmd);
1887 +}
1888 +
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905 +{
1906 +#ifdef CONFIG_ARM_LPAE
1907 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908 +#else
1909 + if (addr & SECTION_SIZE)
1910 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911 + else
1912 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913 +#endif
1914 + flush_pmd_entry(pmdp);
1915 +}
1916 +
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930 index 5cfba15..f415e1a 100644
1931 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933 @@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941 +
1942 /*
1943 * - section
1944 */
1945 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949 @@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957 @@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966 index 86a659a..70e0120 100644
1967 --- a/arch/arm/include/asm/pgtable-2level.h
1968 +++ b/arch/arm/include/asm/pgtable-2level.h
1969 @@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974 +#define L_PTE_PXN (_AT(pteval_t, 0))
1975 +
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980 index 626989f..9d67a33 100644
1981 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983 @@ -75,6 +75,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992 index 1d15673..04d626a 100644
1993 --- a/arch/arm/include/asm/pgtable-3level.h
1994 +++ b/arch/arm/include/asm/pgtable-3level.h
1995 @@ -82,6 +82,7 @@
1996 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2003 @@ -95,6 +96,7 @@
2004 /*
2005 * To be used in assembly code with the upper page attributes.
2006 */
2007 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2008 #define L_PTE_XN_HIGH (1 << (54 - 32))
2009 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2010
2011 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2012 index 1571d12..b8a9b43 100644
2013 --- a/arch/arm/include/asm/pgtable.h
2014 +++ b/arch/arm/include/asm/pgtable.h
2015 @@ -33,6 +33,9 @@
2016 #include <asm/pgtable-2level.h>
2017 #endif
2018
2019 +#define ktla_ktva(addr) (addr)
2020 +#define ktva_ktla(addr) (addr)
2021 +
2022 /*
2023 * Just any arbitrary offset to the start of the vmalloc VM area: the
2024 * current 8MB value just means that there will be a 8MB "hole" after the
2025 @@ -48,6 +51,9 @@
2026 #define LIBRARY_TEXT_START 0x0c000000
2027
2028 #ifndef __ASSEMBLY__
2029 +extern pteval_t __supported_pte_mask;
2030 +extern pmdval_t __supported_pmd_mask;
2031 +
2032 extern void __pte_error(const char *file, int line, pte_t);
2033 extern void __pmd_error(const char *file, int line, pmd_t);
2034 extern void __pgd_error(const char *file, int line, pgd_t);
2035 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2037 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2038
2039 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2040 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2041 +
2042 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2043 +#include <asm/domain.h>
2044 +#include <linux/thread_info.h>
2045 +#include <linux/preempt.h>
2046 +
2047 +static inline int test_domain(int domain, int domaintype)
2048 +{
2049 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2050 +}
2051 +#endif
2052 +
2053 +#ifdef CONFIG_PAX_KERNEXEC
2054 +static inline unsigned long pax_open_kernel(void) {
2055 +#ifdef CONFIG_ARM_LPAE
2056 + /* TODO */
2057 +#else
2058 + preempt_disable();
2059 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2060 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2061 +#endif
2062 + return 0;
2063 +}
2064 +
2065 +static inline unsigned long pax_close_kernel(void) {
2066 +#ifdef CONFIG_ARM_LPAE
2067 + /* TODO */
2068 +#else
2069 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2070 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2071 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2072 + preempt_enable_no_resched();
2073 +#endif
2074 + return 0;
2075 +}
2076 +#else
2077 +static inline unsigned long pax_open_kernel(void) { return 0; }
2078 +static inline unsigned long pax_close_kernel(void) { return 0; }
2079 +#endif
2080 +
2081 /*
2082 * This is the lowest virtual address we can permit any user space
2083 * mapping to be mapped at. This is particularly important for
2084 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2085 /*
2086 * The pgprot_* and protection_map entries will be fixed up in runtime
2087 * to include the cachable and bufferable bits based on memory policy,
2088 - * as well as any architecture dependent bits like global/ASID and SMP
2089 - * shared mapping bits.
2090 + * as well as any architecture dependent bits like global/ASID, PXN,
2091 + * and SMP shared mapping bits.
2092 */
2093 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2094
2095 @@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2096 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2097 {
2098 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2099 - L_PTE_NONE | L_PTE_VALID;
2100 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2101 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2102 return pte;
2103 }
2104 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2105 index c4ae171..ea0c0c2 100644
2106 --- a/arch/arm/include/asm/psci.h
2107 +++ b/arch/arm/include/asm/psci.h
2108 @@ -29,7 +29,7 @@ struct psci_operations {
2109 int (*cpu_off)(struct psci_power_state state);
2110 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2111 int (*migrate)(unsigned long cpuid);
2112 -};
2113 +} __no_const;
2114
2115 extern struct psci_operations psci_ops;
2116 extern struct smp_operations psci_smp_ops;
2117 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2118 index 22a3b9b..7f214ee 100644
2119 --- a/arch/arm/include/asm/smp.h
2120 +++ b/arch/arm/include/asm/smp.h
2121 @@ -112,7 +112,7 @@ struct smp_operations {
2122 int (*cpu_disable)(unsigned int cpu);
2123 #endif
2124 #endif
2125 -};
2126 +} __no_const;
2127
2128 /*
2129 * set platform specific SMP operations
2130 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2131 index 71a06b2..8bb9ae1 100644
2132 --- a/arch/arm/include/asm/thread_info.h
2133 +++ b/arch/arm/include/asm/thread_info.h
2134 @@ -88,9 +88,9 @@ struct thread_info {
2135 .flags = 0, \
2136 .preempt_count = INIT_PREEMPT_COUNT, \
2137 .addr_limit = KERNEL_DS, \
2138 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2139 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2140 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2141 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2142 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2143 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2144 .restart_block = { \
2145 .fn = do_no_restart_syscall, \
2146 }, \
2147 @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2148 #define TIF_SYSCALL_AUDIT 9
2149 #define TIF_SYSCALL_TRACEPOINT 10
2150 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2151 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2152 +/* within 8 bits of TIF_SYSCALL_TRACE
2153 + * to meet flexible second operand requirements
2154 + */
2155 +#define TIF_GRSEC_SETXID 12
2156 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2157 #define TIF_USING_IWMMXT 17
2158 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2159 #define TIF_RESTORE_SIGMASK 20
2160 @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2161 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2162 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2163 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2164 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2165
2166 /* Checks for any syscall work in entry-common.S */
2167 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2168 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2169 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2170
2171 /*
2172 * Change these and you break ASM code in entry-common.S
2173 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2174 index 72abdc5..35acac1 100644
2175 --- a/arch/arm/include/asm/uaccess.h
2176 +++ b/arch/arm/include/asm/uaccess.h
2177 @@ -18,6 +18,7 @@
2178 #include <asm/domain.h>
2179 #include <asm/unified.h>
2180 #include <asm/compiler.h>
2181 +#include <asm/pgtable.h>
2182
2183 #if __LINUX_ARM_ARCH__ < 6
2184 #include <asm-generic/uaccess-unaligned.h>
2185 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2186 static inline void set_fs(mm_segment_t fs)
2187 {
2188 current_thread_info()->addr_limit = fs;
2189 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2190 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2191 }
2192
2193 #define segment_eq(a,b) ((a) == (b))
2194
2195 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2196 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2197 +
2198 +static inline void pax_open_userland(void)
2199 +{
2200 +
2201 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2202 + if (segment_eq(get_fs(), USER_DS)) {
2203 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2204 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2205 + }
2206 +#endif
2207 +
2208 +}
2209 +
2210 +static inline void pax_close_userland(void)
2211 +{
2212 +
2213 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2214 + if (segment_eq(get_fs(), USER_DS)) {
2215 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2216 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2217 + }
2218 +#endif
2219 +
2220 +}
2221 +
2222 #define __addr_ok(addr) ({ \
2223 unsigned long flag; \
2224 __asm__("cmp %2, %0; movlo %0, #0" \
2225 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2226
2227 #define get_user(x,p) \
2228 ({ \
2229 + int __e; \
2230 might_fault(); \
2231 - __get_user_check(x,p); \
2232 + pax_open_userland(); \
2233 + __e = __get_user_check(x,p); \
2234 + pax_close_userland(); \
2235 + __e; \
2236 })
2237
2238 extern int __put_user_1(void *, unsigned int);
2239 @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2240
2241 #define put_user(x,p) \
2242 ({ \
2243 + int __e; \
2244 might_fault(); \
2245 - __put_user_check(x,p); \
2246 + pax_open_userland(); \
2247 + __e = __put_user_check(x,p); \
2248 + pax_close_userland(); \
2249 + __e; \
2250 })
2251
2252 #else /* CONFIG_MMU */
2253 @@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2254
2255 #endif /* CONFIG_MMU */
2256
2257 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2258 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2259
2260 #define user_addr_max() \
2261 @@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2262 #define __get_user(x,ptr) \
2263 ({ \
2264 long __gu_err = 0; \
2265 + pax_open_userland(); \
2266 __get_user_err((x),(ptr),__gu_err); \
2267 + pax_close_userland(); \
2268 __gu_err; \
2269 })
2270
2271 #define __get_user_error(x,ptr,err) \
2272 ({ \
2273 + pax_open_userland(); \
2274 __get_user_err((x),(ptr),err); \
2275 + pax_close_userland(); \
2276 (void) 0; \
2277 })
2278
2279 @@ -319,13 +360,17 @@ do { \
2280 #define __put_user(x,ptr) \
2281 ({ \
2282 long __pu_err = 0; \
2283 + pax_open_userland(); \
2284 __put_user_err((x),(ptr),__pu_err); \
2285 + pax_close_userland(); \
2286 __pu_err; \
2287 })
2288
2289 #define __put_user_error(x,ptr,err) \
2290 ({ \
2291 + pax_open_userland(); \
2292 __put_user_err((x),(ptr),err); \
2293 + pax_close_userland(); \
2294 (void) 0; \
2295 })
2296
2297 @@ -425,11 +470,44 @@ do { \
2298
2299
2300 #ifdef CONFIG_MMU
2301 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2302 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2303 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2304 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2305 +
2306 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2307 +{
2308 + unsigned long ret;
2309 +
2310 + check_object_size(to, n, false);
2311 + pax_open_userland();
2312 + ret = ___copy_from_user(to, from, n);
2313 + pax_close_userland();
2314 + return ret;
2315 +}
2316 +
2317 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2318 +{
2319 + unsigned long ret;
2320 +
2321 + check_object_size(from, n, true);
2322 + pax_open_userland();
2323 + ret = ___copy_to_user(to, from, n);
2324 + pax_close_userland();
2325 + return ret;
2326 +}
2327 +
2328 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2329 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2330 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2331 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2332 +
2333 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2334 +{
2335 + unsigned long ret;
2336 + pax_open_userland();
2337 + ret = ___clear_user(addr, n);
2338 + pax_close_userland();
2339 + return ret;
2340 +}
2341 +
2342 #else
2343 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2344 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2345 @@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2346
2347 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2348 {
2349 + if ((long)n < 0)
2350 + return n;
2351 +
2352 if (access_ok(VERIFY_READ, from, n))
2353 n = __copy_from_user(to, from, n);
2354 else /* security hole - plug it */
2355 @@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2356
2357 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2358 {
2359 + if ((long)n < 0)
2360 + return n;
2361 +
2362 if (access_ok(VERIFY_WRITE, to, n))
2363 n = __copy_to_user(to, from, n);
2364 return n;
2365 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2366 index 5af0ed1..cea83883 100644
2367 --- a/arch/arm/include/uapi/asm/ptrace.h
2368 +++ b/arch/arm/include/uapi/asm/ptrace.h
2369 @@ -92,7 +92,7 @@
2370 * ARMv7 groups of PSR bits
2371 */
2372 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2373 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2374 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2375 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2376 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2377
2378 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2379 index 1f031dd..d9b5e4a 100644
2380 --- a/arch/arm/kernel/armksyms.c
2381 +++ b/arch/arm/kernel/armksyms.c
2382 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2383
2384 /* networking */
2385 EXPORT_SYMBOL(csum_partial);
2386 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2387 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2388 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2389 EXPORT_SYMBOL(__csum_ipv6_magic);
2390
2391 @@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2392 #ifdef CONFIG_MMU
2393 EXPORT_SYMBOL(copy_page);
2394
2395 -EXPORT_SYMBOL(__copy_from_user);
2396 -EXPORT_SYMBOL(__copy_to_user);
2397 -EXPORT_SYMBOL(__clear_user);
2398 +EXPORT_SYMBOL(___copy_from_user);
2399 +EXPORT_SYMBOL(___copy_to_user);
2400 +EXPORT_SYMBOL(___clear_user);
2401
2402 EXPORT_SYMBOL(__get_user_1);
2403 EXPORT_SYMBOL(__get_user_2);
2404 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2405 index b3fb8c9..59cfab2 100644
2406 --- a/arch/arm/kernel/entry-armv.S
2407 +++ b/arch/arm/kernel/entry-armv.S
2408 @@ -47,6 +47,87 @@
2409 9997:
2410 .endm
2411
2412 + .macro pax_enter_kernel
2413 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2414 + @ make aligned space for saved DACR
2415 + sub sp, sp, #8
2416 + @ save regs
2417 + stmdb sp!, {r1, r2}
2418 + @ read DACR from cpu_domain into r1
2419 + mov r2, sp
2420 + @ assume 8K pages, since we have to split the immediate in two
2421 + bic r2, r2, #(0x1fc0)
2422 + bic r2, r2, #(0x3f)
2423 + ldr r1, [r2, #TI_CPU_DOMAIN]
2424 + @ store old DACR on stack
2425 + str r1, [sp, #8]
2426 +#ifdef CONFIG_PAX_KERNEXEC
2427 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2428 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2429 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2430 +#endif
2431 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2432 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2433 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2434 +#endif
2435 + @ write r1 to current_thread_info()->cpu_domain
2436 + str r1, [r2, #TI_CPU_DOMAIN]
2437 + @ write r1 to DACR
2438 + mcr p15, 0, r1, c3, c0, 0
2439 + @ instruction sync
2440 + instr_sync
2441 + @ restore regs
2442 + ldmia sp!, {r1, r2}
2443 +#endif
2444 + .endm
2445 +
2446 + .macro pax_open_userland
2447 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2448 + @ save regs
2449 + stmdb sp!, {r0, r1}
2450 + @ read DACR from cpu_domain into r1
2451 + mov r0, sp
2452 + @ assume 8K pages, since we have to split the immediate in two
2453 + bic r0, r0, #(0x1fc0)
2454 + bic r0, r0, #(0x3f)
2455 + ldr r1, [r0, #TI_CPU_DOMAIN]
2456 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2457 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2458 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2459 + @ write r1 to current_thread_info()->cpu_domain
2460 + str r1, [r0, #TI_CPU_DOMAIN]
2461 + @ write r1 to DACR
2462 + mcr p15, 0, r1, c3, c0, 0
2463 + @ instruction sync
2464 + instr_sync
2465 + @ restore regs
2466 + ldmia sp!, {r0, r1}
2467 +#endif
2468 + .endm
2469 +
2470 + .macro pax_close_userland
2471 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2472 + @ save regs
2473 + stmdb sp!, {r0, r1}
2474 + @ read DACR from cpu_domain into r1
2475 + mov r0, sp
2476 + @ assume 8K pages, since we have to split the immediate in two
2477 + bic r0, r0, #(0x1fc0)
2478 + bic r0, r0, #(0x3f)
2479 + ldr r1, [r0, #TI_CPU_DOMAIN]
2480 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2481 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2482 + @ write r1 to current_thread_info()->cpu_domain
2483 + str r1, [r0, #TI_CPU_DOMAIN]
2484 + @ write r1 to DACR
2485 + mcr p15, 0, r1, c3, c0, 0
2486 + @ instruction sync
2487 + instr_sync
2488 + @ restore regs
2489 + ldmia sp!, {r0, r1}
2490 +#endif
2491 + .endm
2492 +
2493 .macro pabt_helper
2494 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2495 #ifdef MULTI_PABORT
2496 @@ -89,11 +170,15 @@
2497 * Invalid mode handlers
2498 */
2499 .macro inv_entry, reason
2500 +
2501 + pax_enter_kernel
2502 +
2503 sub sp, sp, #S_FRAME_SIZE
2504 ARM( stmib sp, {r1 - lr} )
2505 THUMB( stmia sp, {r0 - r12} )
2506 THUMB( str sp, [sp, #S_SP] )
2507 THUMB( str lr, [sp, #S_LR] )
2508 +
2509 mov r1, #\reason
2510 .endm
2511
2512 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2513 .macro svc_entry, stack_hole=0
2514 UNWIND(.fnstart )
2515 UNWIND(.save {r0 - pc} )
2516 +
2517 + pax_enter_kernel
2518 +
2519 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2520 +
2521 #ifdef CONFIG_THUMB2_KERNEL
2522 SPFIX( str r0, [sp] ) @ temporarily saved
2523 SPFIX( mov r0, sp )
2524 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2525 ldmia r0, {r3 - r5}
2526 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2527 mov r6, #-1 @ "" "" "" ""
2528 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2529 + @ offset sp by 8 as done in pax_enter_kernel
2530 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2531 +#else
2532 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2533 +#endif
2534 SPFIX( addeq r2, r2, #4 )
2535 str r3, [sp, #-4]! @ save the "real" r0 copied
2536 @ from the exception stack
2537 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2538 .macro usr_entry
2539 UNWIND(.fnstart )
2540 UNWIND(.cantunwind ) @ don't unwind the user space
2541 +
2542 + pax_enter_kernel_user
2543 +
2544 sub sp, sp, #S_FRAME_SIZE
2545 ARM( stmib sp, {r1 - r12} )
2546 THUMB( stmia sp, {r0 - r12} )
2547 @@ -416,7 +513,9 @@ __und_usr:
2548 tst r3, #PSR_T_BIT @ Thumb mode?
2549 bne __und_usr_thumb
2550 sub r4, r2, #4 @ ARM instr at LR - 4
2551 + pax_open_userland
2552 1: ldrt r0, [r4]
2553 + pax_close_userland
2554 ARM_BE8(rev r0, r0) @ little endian instruction
2555
2556 @ r0 = 32-bit ARM instruction which caused the exception
2557 @@ -450,10 +549,14 @@ __und_usr_thumb:
2558 */
2559 .arch armv6t2
2560 #endif
2561 + pax_open_userland
2562 2: ldrht r5, [r4]
2563 + pax_close_userland
2564 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2565 blo __und_usr_fault_16 @ 16bit undefined instruction
2566 + pax_open_userland
2567 3: ldrht r0, [r2]
2568 + pax_close_userland
2569 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2570 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2571 orr r0, r0, r5, lsl #16
2572 @@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2573 */
2574 .pushsection .fixup, "ax"
2575 .align 2
2576 -4: mov pc, r9
2577 +4: pax_close_userland
2578 + mov pc, r9
2579 .popsection
2580 .pushsection __ex_table,"a"
2581 .long 1b, 4b
2582 @@ -692,7 +796,7 @@ ENTRY(__switch_to)
2583 THUMB( str lr, [ip], #4 )
2584 ldr r4, [r2, #TI_TP_VALUE]
2585 ldr r5, [r2, #TI_TP_VALUE + 4]
2586 -#ifdef CONFIG_CPU_USE_DOMAINS
2587 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2588 ldr r6, [r2, #TI_CPU_DOMAIN]
2589 #endif
2590 switch_tls r1, r4, r5, r3, r7
2591 @@ -701,7 +805,7 @@ ENTRY(__switch_to)
2592 ldr r8, =__stack_chk_guard
2593 ldr r7, [r7, #TSK_STACK_CANARY]
2594 #endif
2595 -#ifdef CONFIG_CPU_USE_DOMAINS
2596 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2597 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2598 #endif
2599 mov r5, r0
2600 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2601 index a2dcafd..1048b5a 100644
2602 --- a/arch/arm/kernel/entry-common.S
2603 +++ b/arch/arm/kernel/entry-common.S
2604 @@ -10,18 +10,46 @@
2605
2606 #include <asm/unistd.h>
2607 #include <asm/ftrace.h>
2608 +#include <asm/domain.h>
2609 #include <asm/unwind.h>
2610
2611 +#include "entry-header.S"
2612 +
2613 #ifdef CONFIG_NEED_RET_TO_USER
2614 #include <mach/entry-macro.S>
2615 #else
2616 .macro arch_ret_to_user, tmp1, tmp2
2617 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2618 + @ save regs
2619 + stmdb sp!, {r1, r2}
2620 + @ read DACR from cpu_domain into r1
2621 + mov r2, sp
2622 + @ assume 8K pages, since we have to split the immediate in two
2623 + bic r2, r2, #(0x1fc0)
2624 + bic r2, r2, #(0x3f)
2625 + ldr r1, [r2, #TI_CPU_DOMAIN]
2626 +#ifdef CONFIG_PAX_KERNEXEC
2627 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2628 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2629 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2630 +#endif
2631 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2632 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2633 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2634 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2635 +#endif
2636 + @ write r1 to current_thread_info()->cpu_domain
2637 + str r1, [r2, #TI_CPU_DOMAIN]
2638 + @ write r1 to DACR
2639 + mcr p15, 0, r1, c3, c0, 0
2640 + @ instruction sync
2641 + instr_sync
2642 + @ restore regs
2643 + ldmia sp!, {r1, r2}
2644 +#endif
2645 .endm
2646 #endif
2647
2648 -#include "entry-header.S"
2649 -
2650 -
2651 .align 5
2652 /*
2653 * This is the fast syscall return path. We do as little as
2654 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2655 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2656 #endif
2657
2658 + /*
2659 + * do this here to avoid a performance hit of wrapping the code above
2660 + * that directly dereferences userland to parse the SWI instruction
2661 + */
2662 + pax_enter_kernel_user
2663 +
2664 adr tbl, sys_call_table @ load syscall table pointer
2665
2666 #if defined(CONFIG_OABI_COMPAT)
2667 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2668 index 39f89fb..d612bd9 100644
2669 --- a/arch/arm/kernel/entry-header.S
2670 +++ b/arch/arm/kernel/entry-header.S
2671 @@ -184,6 +184,60 @@
2672 msr cpsr_c, \rtemp @ switch back to the SVC mode
2673 .endm
2674
2675 + .macro pax_enter_kernel_user
2676 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2677 + @ save regs
2678 + stmdb sp!, {r0, r1}
2679 + @ read DACR from cpu_domain into r1
2680 + mov r0, sp
2681 + @ assume 8K pages, since we have to split the immediate in two
2682 + bic r0, r0, #(0x1fc0)
2683 + bic r0, r0, #(0x3f)
2684 + ldr r1, [r0, #TI_CPU_DOMAIN]
2685 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2686 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2687 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2688 +#endif
2689 +#ifdef CONFIG_PAX_KERNEXEC
2690 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2691 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2692 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2693 +#endif
2694 + @ write r1 to current_thread_info()->cpu_domain
2695 + str r1, [r0, #TI_CPU_DOMAIN]
2696 + @ write r1 to DACR
2697 + mcr p15, 0, r1, c3, c0, 0
2698 + @ instruction sync
2699 + instr_sync
2700 + @ restore regs
2701 + ldmia sp!, {r0, r1}
2702 +#endif
2703 + .endm
2704 +
2705 + .macro pax_exit_kernel
2706 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2707 + @ save regs
2708 + stmdb sp!, {r0, r1}
2709 + @ read old DACR from stack into r1
2710 + ldr r1, [sp, #(8 + S_SP)]
2711 + sub r1, r1, #8
2712 + ldr r1, [r1]
2713 +
2714 + @ write r1 to current_thread_info()->cpu_domain
2715 + mov r0, sp
2716 + @ assume 8K pages, since we have to split the immediate in two
2717 + bic r0, r0, #(0x1fc0)
2718 + bic r0, r0, #(0x3f)
2719 + str r1, [r0, #TI_CPU_DOMAIN]
2720 + @ write r1 to DACR
2721 + mcr p15, 0, r1, c3, c0, 0
2722 + @ instruction sync
2723 + instr_sync
2724 + @ restore regs
2725 + ldmia sp!, {r0, r1}
2726 +#endif
2727 + .endm
2728 +
2729 #ifndef CONFIG_THUMB2_KERNEL
2730 .macro svc_exit, rpsr, irq = 0
2731 .if \irq != 0
2732 @@ -203,6 +257,9 @@
2733 blne trace_hardirqs_off
2734 #endif
2735 .endif
2736 +
2737 + pax_exit_kernel
2738 +
2739 msr spsr_cxsf, \rpsr
2740 #if defined(CONFIG_CPU_V6)
2741 ldr r0, [sp]
2742 @@ -266,6 +323,9 @@
2743 blne trace_hardirqs_off
2744 #endif
2745 .endif
2746 +
2747 + pax_exit_kernel
2748 +
2749 ldr lr, [sp, #S_SP] @ top of the stack
2750 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2751 clrex @ clear the exclusive monitor
2752 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2753 index 918875d..cd5fa27 100644
2754 --- a/arch/arm/kernel/fiq.c
2755 +++ b/arch/arm/kernel/fiq.c
2756 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2757 void *base = vectors_page;
2758 unsigned offset = FIQ_OFFSET;
2759
2760 + pax_open_kernel();
2761 memcpy(base + offset, start, length);
2762 + pax_close_kernel();
2763 +
2764 if (!cache_is_vipt_nonaliasing())
2765 flush_icache_range((unsigned long)base + offset, offset +
2766 length);
2767 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2768 index 32f317e..710ae07 100644
2769 --- a/arch/arm/kernel/head.S
2770 +++ b/arch/arm/kernel/head.S
2771 @@ -52,7 +52,9 @@
2772 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2773
2774 .macro pgtbl, rd, phys
2775 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2776 + mov \rd, #TEXT_OFFSET
2777 + sub \rd, #PG_DIR_SIZE
2778 + add \rd, \rd, \phys
2779 .endm
2780
2781 /*
2782 @@ -436,7 +438,7 @@ __enable_mmu:
2783 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2784 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2785 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2786 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2787 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2788 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2789 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2790 #endif
2791 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2792 index 45e4781..8eac93d 100644
2793 --- a/arch/arm/kernel/module.c
2794 +++ b/arch/arm/kernel/module.c
2795 @@ -38,12 +38,39 @@
2796 #endif
2797
2798 #ifdef CONFIG_MMU
2799 -void *module_alloc(unsigned long size)
2800 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2801 {
2802 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2803 + return NULL;
2804 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2805 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2806 + GFP_KERNEL, prot, NUMA_NO_NODE,
2807 __builtin_return_address(0));
2808 }
2809 +
2810 +void *module_alloc(unsigned long size)
2811 +{
2812 +
2813 +#ifdef CONFIG_PAX_KERNEXEC
2814 + return __module_alloc(size, PAGE_KERNEL);
2815 +#else
2816 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2817 +#endif
2818 +
2819 +}
2820 +
2821 +#ifdef CONFIG_PAX_KERNEXEC
2822 +void module_free_exec(struct module *mod, void *module_region)
2823 +{
2824 + module_free(mod, module_region);
2825 +}
2826 +EXPORT_SYMBOL(module_free_exec);
2827 +
2828 +void *module_alloc_exec(unsigned long size)
2829 +{
2830 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2831 +}
2832 +EXPORT_SYMBOL(module_alloc_exec);
2833 +#endif
2834 #endif
2835
2836 int
2837 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2838 index 07314af..c46655c 100644
2839 --- a/arch/arm/kernel/patch.c
2840 +++ b/arch/arm/kernel/patch.c
2841 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2842 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2843 int size;
2844
2845 + pax_open_kernel();
2846 if (thumb2 && __opcode_is_thumb16(insn)) {
2847 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2848 size = sizeof(u16);
2849 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2850 *(u32 *)addr = insn;
2851 size = sizeof(u32);
2852 }
2853 + pax_close_kernel();
2854
2855 flush_icache_range((uintptr_t)(addr),
2856 (uintptr_t)(addr) + size);
2857 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2858 index 92f7b15..7048500 100644
2859 --- a/arch/arm/kernel/process.c
2860 +++ b/arch/arm/kernel/process.c
2861 @@ -217,6 +217,7 @@ void machine_power_off(void)
2862
2863 if (pm_power_off)
2864 pm_power_off();
2865 + BUG();
2866 }
2867
2868 /*
2869 @@ -230,7 +231,7 @@ void machine_power_off(void)
2870 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2871 * to use. Implementing such co-ordination would be essentially impossible.
2872 */
2873 -void machine_restart(char *cmd)
2874 +__noreturn void machine_restart(char *cmd)
2875 {
2876 local_irq_disable();
2877 smp_send_stop();
2878 @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2879
2880 show_regs_print_info(KERN_DEFAULT);
2881
2882 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2883 - print_symbol("LR is at %s\n", regs->ARM_lr);
2884 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2885 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2886 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2887 "sp : %08lx ip : %08lx fp : %08lx\n",
2888 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2889 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2890 return 0;
2891 }
2892
2893 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2894 -{
2895 - unsigned long range_end = mm->brk + 0x02000000;
2896 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2897 -}
2898 -
2899 #ifdef CONFIG_MMU
2900 #ifdef CONFIG_KUSER_HELPERS
2901 /*
2902 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2903
2904 static int __init gate_vma_init(void)
2905 {
2906 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2907 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2908 return 0;
2909 }
2910 arch_initcall(gate_vma_init);
2911 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2912
2913 const char *arch_vma_name(struct vm_area_struct *vma)
2914 {
2915 - return is_gate_vma(vma) ? "[vectors]" :
2916 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2917 - "[sigpage]" : NULL;
2918 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2919 }
2920
2921 -static struct page *signal_page;
2922 -extern struct page *get_signal_page(void);
2923 -
2924 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2925 {
2926 struct mm_struct *mm = current->mm;
2927 - unsigned long addr;
2928 - int ret;
2929 -
2930 - if (!signal_page)
2931 - signal_page = get_signal_page();
2932 - if (!signal_page)
2933 - return -ENOMEM;
2934
2935 down_write(&mm->mmap_sem);
2936 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2937 - if (IS_ERR_VALUE(addr)) {
2938 - ret = addr;
2939 - goto up_fail;
2940 - }
2941 -
2942 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2943 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2944 - &signal_page);
2945 -
2946 - if (ret == 0)
2947 - mm->context.sigpage = addr;
2948 -
2949 - up_fail:
2950 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2951 up_write(&mm->mmap_sem);
2952 - return ret;
2953 + return 0;
2954 }
2955 #endif
2956 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2957 index 4693188..4596c5e 100644
2958 --- a/arch/arm/kernel/psci.c
2959 +++ b/arch/arm/kernel/psci.c
2960 @@ -24,7 +24,7 @@
2961 #include <asm/opcodes-virt.h>
2962 #include <asm/psci.h>
2963
2964 -struct psci_operations psci_ops;
2965 +struct psci_operations psci_ops __read_only;
2966
2967 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2968
2969 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2970 index 0dd3b79..e018f64 100644
2971 --- a/arch/arm/kernel/ptrace.c
2972 +++ b/arch/arm/kernel/ptrace.c
2973 @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2974 return current_thread_info()->syscall;
2975 }
2976
2977 +#ifdef CONFIG_GRKERNSEC_SETXID
2978 +extern void gr_delayed_cred_worker(void);
2979 +#endif
2980 +
2981 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2982 {
2983 current_thread_info()->syscall = scno;
2984
2985 +#ifdef CONFIG_GRKERNSEC_SETXID
2986 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2987 + gr_delayed_cred_worker();
2988 +#endif
2989 +
2990 /* Do the secure computing check first; failures should be fast. */
2991 if (secure_computing(scno) == -1)
2992 return -1;
2993 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2994 index 987a7f5..ab0c397 100644
2995 --- a/arch/arm/kernel/setup.c
2996 +++ b/arch/arm/kernel/setup.c
2997 @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2998 unsigned int elf_hwcap __read_mostly;
2999 EXPORT_SYMBOL(elf_hwcap);
3000
3001 +pteval_t __supported_pte_mask __read_only;
3002 +pmdval_t __supported_pmd_mask __read_only;
3003
3004 #ifdef MULTI_CPU
3005 -struct processor processor __read_mostly;
3006 +struct processor processor __read_only;
3007 #endif
3008 #ifdef MULTI_TLB
3009 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3010 +struct cpu_tlb_fns cpu_tlb __read_only;
3011 #endif
3012 #ifdef MULTI_USER
3013 -struct cpu_user_fns cpu_user __read_mostly;
3014 +struct cpu_user_fns cpu_user __read_only;
3015 #endif
3016 #ifdef MULTI_CACHE
3017 -struct cpu_cache_fns cpu_cache __read_mostly;
3018 +struct cpu_cache_fns cpu_cache __read_only;
3019 #endif
3020 #ifdef CONFIG_OUTER_CACHE
3021 -struct outer_cache_fns outer_cache __read_mostly;
3022 +struct outer_cache_fns outer_cache __read_only;
3023 EXPORT_SYMBOL(outer_cache);
3024 #endif
3025
3026 @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3027 asm("mrc p15, 0, %0, c0, c1, 4"
3028 : "=r" (mmfr0));
3029 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3030 - (mmfr0 & 0x000000f0) >= 0x00000030)
3031 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3032 cpu_arch = CPU_ARCH_ARMv7;
3033 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3034 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3035 + __supported_pte_mask |= L_PTE_PXN;
3036 + __supported_pmd_mask |= PMD_PXNTABLE;
3037 + }
3038 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3039 (mmfr0 & 0x000000f0) == 0x00000020)
3040 cpu_arch = CPU_ARCH_ARMv6;
3041 else
3042 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3043 index 04d6388..5115238 100644
3044 --- a/arch/arm/kernel/signal.c
3045 +++ b/arch/arm/kernel/signal.c
3046 @@ -23,8 +23,6 @@
3047
3048 extern const unsigned long sigreturn_codes[7];
3049
3050 -static unsigned long signal_return_offset;
3051 -
3052 #ifdef CONFIG_CRUNCH
3053 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3054 {
3055 @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3056 * except when the MPU has protected the vectors
3057 * page from PL0
3058 */
3059 - retcode = mm->context.sigpage + signal_return_offset +
3060 - (idx << 2) + thumb;
3061 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3062 } else
3063 #endif
3064 {
3065 @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3066 } while (thread_flags & _TIF_WORK_MASK);
3067 return 0;
3068 }
3069 -
3070 -struct page *get_signal_page(void)
3071 -{
3072 - unsigned long ptr;
3073 - unsigned offset;
3074 - struct page *page;
3075 - void *addr;
3076 -
3077 - page = alloc_pages(GFP_KERNEL, 0);
3078 -
3079 - if (!page)
3080 - return NULL;
3081 -
3082 - addr = page_address(page);
3083 -
3084 - /* Give the signal return code some randomness */
3085 - offset = 0x200 + (get_random_int() & 0x7fc);
3086 - signal_return_offset = offset;
3087 -
3088 - /*
3089 - * Copy signal return handlers into the vector page, and
3090 - * set sigreturn to be a pointer to these.
3091 - */
3092 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3093 -
3094 - ptr = (unsigned long)addr + offset;
3095 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3096 -
3097 - return page;
3098 -}
3099 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3100 index dc894ab..f929a0d 100644
3101 --- a/arch/arm/kernel/smp.c
3102 +++ b/arch/arm/kernel/smp.c
3103 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3104
3105 static DECLARE_COMPLETION(cpu_running);
3106
3107 -static struct smp_operations smp_ops;
3108 +static struct smp_operations smp_ops __read_only;
3109
3110 void __init smp_set_ops(struct smp_operations *ops)
3111 {
3112 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3113 index 4636d56..ce4ec3d 100644
3114 --- a/arch/arm/kernel/traps.c
3115 +++ b/arch/arm/kernel/traps.c
3116 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3117 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3118 {
3119 #ifdef CONFIG_KALLSYMS
3120 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3121 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3122 #else
3123 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3124 #endif
3125 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3126 static int die_owner = -1;
3127 static unsigned int die_nest_count;
3128
3129 +extern void gr_handle_kernel_exploit(void);
3130 +
3131 static unsigned long oops_begin(void)
3132 {
3133 int cpu;
3134 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3135 panic("Fatal exception in interrupt");
3136 if (panic_on_oops)
3137 panic("Fatal exception");
3138 +
3139 + gr_handle_kernel_exploit();
3140 +
3141 if (signr)
3142 do_exit(signr);
3143 }
3144 @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3145 * The user helper at 0xffff0fe0 must be used instead.
3146 * (see entry-armv.S for details)
3147 */
3148 + pax_open_kernel();
3149 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3150 + pax_close_kernel();
3151 }
3152 return 0;
3153
3154 @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3155 kuser_init(vectors_base);
3156
3157 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3158 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3159 +
3160 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3161 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3162 +#endif
3163 +
3164 #else /* ifndef CONFIG_CPU_V7M */
3165 /*
3166 * on V7-M there is no need to copy the vector table to a dedicated
3167 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3168 index 7bcee5c..e2f3249 100644
3169 --- a/arch/arm/kernel/vmlinux.lds.S
3170 +++ b/arch/arm/kernel/vmlinux.lds.S
3171 @@ -8,7 +8,11 @@
3172 #include <asm/thread_info.h>
3173 #include <asm/memory.h>
3174 #include <asm/page.h>
3175 -
3176 +
3177 +#ifdef CONFIG_PAX_KERNEXEC
3178 +#include <asm/pgtable.h>
3179 +#endif
3180 +
3181 #define PROC_INFO \
3182 . = ALIGN(4); \
3183 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3184 @@ -34,7 +38,7 @@
3185 #endif
3186
3187 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3188 - defined(CONFIG_GENERIC_BUG)
3189 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3190 #define ARM_EXIT_KEEP(x) x
3191 #define ARM_EXIT_DISCARD(x)
3192 #else
3193 @@ -90,6 +94,11 @@ SECTIONS
3194 _text = .;
3195 HEAD_TEXT
3196 }
3197 +
3198 +#ifdef CONFIG_PAX_KERNEXEC
3199 + . = ALIGN(1<<SECTION_SHIFT);
3200 +#endif
3201 +
3202 .text : { /* Real text segment */
3203 _stext = .; /* Text and read-only data */
3204 __exception_text_start = .;
3205 @@ -112,6 +121,8 @@ SECTIONS
3206 ARM_CPU_KEEP(PROC_INFO)
3207 }
3208
3209 + _etext = .; /* End of text section */
3210 +
3211 RO_DATA(PAGE_SIZE)
3212
3213 . = ALIGN(4);
3214 @@ -142,7 +153,9 @@ SECTIONS
3215
3216 NOTES
3217
3218 - _etext = .; /* End of text and rodata section */
3219 +#ifdef CONFIG_PAX_KERNEXEC
3220 + . = ALIGN(1<<SECTION_SHIFT);
3221 +#endif
3222
3223 #ifndef CONFIG_XIP_KERNEL
3224 . = ALIGN(PAGE_SIZE);
3225 @@ -220,6 +233,11 @@ SECTIONS
3226 . = PAGE_OFFSET + TEXT_OFFSET;
3227 #else
3228 __init_end = .;
3229 +
3230 +#ifdef CONFIG_PAX_KERNEXEC
3231 + . = ALIGN(1<<SECTION_SHIFT);
3232 +#endif
3233 +
3234 . = ALIGN(THREAD_SIZE);
3235 __data_loc = .;
3236 #endif
3237 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3238 index 2a700e0..745b980 100644
3239 --- a/arch/arm/kvm/arm.c
3240 +++ b/arch/arm/kvm/arm.c
3241 @@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3242 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3243
3244 /* The VMID used in the VTTBR */
3245 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3246 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3247 static u8 kvm_next_vmid;
3248 static DEFINE_SPINLOCK(kvm_vmid_lock);
3249
3250 @@ -397,7 +397,7 @@ void force_vm_exit(const cpumask_t *mask)
3251 */
3252 static bool need_new_vmid_gen(struct kvm *kvm)
3253 {
3254 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3255 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3256 }
3257
3258 /**
3259 @@ -430,7 +430,7 @@ static void update_vttbr(struct kvm *kvm)
3260
3261 /* First user of a new VMID generation? */
3262 if (unlikely(kvm_next_vmid == 0)) {
3263 - atomic64_inc(&kvm_vmid_gen);
3264 + atomic64_inc_unchecked(&kvm_vmid_gen);
3265 kvm_next_vmid = 1;
3266
3267 /*
3268 @@ -447,7 +447,7 @@ static void update_vttbr(struct kvm *kvm)
3269 kvm_call_hyp(__kvm_flush_vm_context);
3270 }
3271
3272 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3273 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3274 kvm->arch.vmid = kvm_next_vmid;
3275 kvm_next_vmid++;
3276
3277 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3278 index 14a0d98..7771a7d 100644
3279 --- a/arch/arm/lib/clear_user.S
3280 +++ b/arch/arm/lib/clear_user.S
3281 @@ -12,14 +12,14 @@
3282
3283 .text
3284
3285 -/* Prototype: int __clear_user(void *addr, size_t sz)
3286 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3287 * Purpose : clear some user memory
3288 * Params : addr - user memory address to clear
3289 * : sz - number of bytes to clear
3290 * Returns : number of bytes NOT cleared
3291 */
3292 ENTRY(__clear_user_std)
3293 -WEAK(__clear_user)
3294 +WEAK(___clear_user)
3295 stmfd sp!, {r1, lr}
3296 mov r2, #0
3297 cmp r1, #4
3298 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3299 USER( strnebt r2, [r0])
3300 mov r0, #0
3301 ldmfd sp!, {r1, pc}
3302 -ENDPROC(__clear_user)
3303 +ENDPROC(___clear_user)
3304 ENDPROC(__clear_user_std)
3305
3306 .pushsection .fixup,"ax"
3307 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3308 index 66a477a..bee61d3 100644
3309 --- a/arch/arm/lib/copy_from_user.S
3310 +++ b/arch/arm/lib/copy_from_user.S
3311 @@ -16,7 +16,7 @@
3312 /*
3313 * Prototype:
3314 *
3315 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3316 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3317 *
3318 * Purpose:
3319 *
3320 @@ -84,11 +84,11 @@
3321
3322 .text
3323
3324 -ENTRY(__copy_from_user)
3325 +ENTRY(___copy_from_user)
3326
3327 #include "copy_template.S"
3328
3329 -ENDPROC(__copy_from_user)
3330 +ENDPROC(___copy_from_user)
3331
3332 .pushsection .fixup,"ax"
3333 .align 0
3334 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3335 index 6ee2f67..d1cce76 100644
3336 --- a/arch/arm/lib/copy_page.S
3337 +++ b/arch/arm/lib/copy_page.S
3338 @@ -10,6 +10,7 @@
3339 * ASM optimised string functions
3340 */
3341 #include <linux/linkage.h>
3342 +#include <linux/const.h>
3343 #include <asm/assembler.h>
3344 #include <asm/asm-offsets.h>
3345 #include <asm/cache.h>
3346 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3347 index d066df6..df28194 100644
3348 --- a/arch/arm/lib/copy_to_user.S
3349 +++ b/arch/arm/lib/copy_to_user.S
3350 @@ -16,7 +16,7 @@
3351 /*
3352 * Prototype:
3353 *
3354 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3355 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3356 *
3357 * Purpose:
3358 *
3359 @@ -88,11 +88,11 @@
3360 .text
3361
3362 ENTRY(__copy_to_user_std)
3363 -WEAK(__copy_to_user)
3364 +WEAK(___copy_to_user)
3365
3366 #include "copy_template.S"
3367
3368 -ENDPROC(__copy_to_user)
3369 +ENDPROC(___copy_to_user)
3370 ENDPROC(__copy_to_user_std)
3371
3372 .pushsection .fixup,"ax"
3373 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3374 index 7d08b43..f7ca7ea 100644
3375 --- a/arch/arm/lib/csumpartialcopyuser.S
3376 +++ b/arch/arm/lib/csumpartialcopyuser.S
3377 @@ -57,8 +57,8 @@
3378 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3379 */
3380
3381 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3382 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3383 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3384 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3385
3386 #include "csumpartialcopygeneric.S"
3387
3388 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3389 index 5306de3..aed6d03 100644
3390 --- a/arch/arm/lib/delay.c
3391 +++ b/arch/arm/lib/delay.c
3392 @@ -28,7 +28,7 @@
3393 /*
3394 * Default to the loop-based delay implementation.
3395 */
3396 -struct arm_delay_ops arm_delay_ops = {
3397 +struct arm_delay_ops arm_delay_ops __read_only = {
3398 .delay = __loop_delay,
3399 .const_udelay = __loop_const_udelay,
3400 .udelay = __loop_udelay,
3401 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3402 index 3e58d71..029817c 100644
3403 --- a/arch/arm/lib/uaccess_with_memcpy.c
3404 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3405 @@ -136,7 +136,7 @@ out:
3406 }
3407
3408 unsigned long
3409 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3410 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3411 {
3412 /*
3413 * This test is stubbed out of the main function above to keep
3414 @@ -190,7 +190,7 @@ out:
3415 return n;
3416 }
3417
3418 -unsigned long __clear_user(void __user *addr, unsigned long n)
3419 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3420 {
3421 /* See rational for this in __copy_to_user() above. */
3422 if (n < 64)
3423 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3424 index f3407a5..bd4256f 100644
3425 --- a/arch/arm/mach-kirkwood/common.c
3426 +++ b/arch/arm/mach-kirkwood/common.c
3427 @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3428 clk_gate_ops.disable(hw);
3429 }
3430
3431 -static struct clk_ops clk_gate_fn_ops;
3432 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3433 +{
3434 + return clk_gate_ops.is_enabled(hw);
3435 +}
3436 +
3437 +static struct clk_ops clk_gate_fn_ops = {
3438 + .enable = clk_gate_fn_enable,
3439 + .disable = clk_gate_fn_disable,
3440 + .is_enabled = clk_gate_fn_is_enabled,
3441 +};
3442
3443 static struct clk __init *clk_register_gate_fn(struct device *dev,
3444 const char *name,
3445 @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3446 gate_fn->fn_en = fn_en;
3447 gate_fn->fn_dis = fn_dis;
3448
3449 - /* ops is the gate ops, but with our enable/disable functions */
3450 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3451 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3452 - clk_gate_fn_ops = clk_gate_ops;
3453 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3454 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3455 - }
3456 -
3457 clk = clk_register(dev, &gate_fn->gate.hw);
3458
3459 if (IS_ERR(clk))
3460 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3461 index 827d1500..2885dc6 100644
3462 --- a/arch/arm/mach-omap2/board-n8x0.c
3463 +++ b/arch/arm/mach-omap2/board-n8x0.c
3464 @@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3465 }
3466 #endif
3467
3468 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3469 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3470 .late_init = n8x0_menelaus_late_init,
3471 };
3472
3473 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3474 index ab43755..ccfa231 100644
3475 --- a/arch/arm/mach-omap2/gpmc.c
3476 +++ b/arch/arm/mach-omap2/gpmc.c
3477 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3478 };
3479
3480 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3481 -static struct irq_chip gpmc_irq_chip;
3482 static int gpmc_irq_start;
3483
3484 static struct resource gpmc_mem_root;
3485 @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3486
3487 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3488
3489 +static struct irq_chip gpmc_irq_chip = {
3490 + .name = "gpmc",
3491 + .irq_startup = gpmc_irq_noop_ret,
3492 + .irq_enable = gpmc_irq_enable,
3493 + .irq_disable = gpmc_irq_disable,
3494 + .irq_shutdown = gpmc_irq_noop,
3495 + .irq_ack = gpmc_irq_noop,
3496 + .irq_mask = gpmc_irq_noop,
3497 + .irq_unmask = gpmc_irq_noop,
3498 +
3499 +};
3500 +
3501 static int gpmc_setup_irq(void)
3502 {
3503 int i;
3504 @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3505 return gpmc_irq_start;
3506 }
3507
3508 - gpmc_irq_chip.name = "gpmc";
3509 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3510 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3511 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3512 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3513 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3514 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3515 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3516 -
3517 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3518 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3519
3520 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3521 index f991016..145ebeb 100644
3522 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3523 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3524 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3525 int (*finish_suspend)(unsigned long cpu_state);
3526 void (*resume)(void);
3527 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3528 -};
3529 +} __no_const;
3530
3531 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3532 static struct powerdomain *mpuss_pd;
3533 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3534 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3535 {}
3536
3537 -struct cpu_pm_ops omap_pm_ops = {
3538 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3539 .finish_suspend = default_finish_suspend,
3540 .resume = dummy_cpu_resume,
3541 .scu_prepare = dummy_scu_prepare,
3542 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3543 index 3664562..72f85c6 100644
3544 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3545 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3546 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3547 return NOTIFY_OK;
3548 }
3549
3550 -static struct notifier_block __refdata irq_hotplug_notifier = {
3551 +static struct notifier_block irq_hotplug_notifier = {
3552 .notifier_call = irq_cpu_hotplug_notify,
3553 };
3554
3555 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3556 index e0a398c..a470fa5 100644
3557 --- a/arch/arm/mach-omap2/omap_device.c
3558 +++ b/arch/arm/mach-omap2/omap_device.c
3559 @@ -508,7 +508,7 @@ void omap_device_delete(struct omap_device *od)
3560 struct platform_device __init *omap_device_build(const char *pdev_name,
3561 int pdev_id,
3562 struct omap_hwmod *oh,
3563 - void *pdata, int pdata_len)
3564 + const void *pdata, int pdata_len)
3565 {
3566 struct omap_hwmod *ohs[] = { oh };
3567
3568 @@ -536,7 +536,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3569 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3570 int pdev_id,
3571 struct omap_hwmod **ohs,
3572 - int oh_cnt, void *pdata,
3573 + int oh_cnt, const void *pdata,
3574 int pdata_len)
3575 {
3576 int ret = -ENOMEM;
3577 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3578 index 78c02b3..c94109a 100644
3579 --- a/arch/arm/mach-omap2/omap_device.h
3580 +++ b/arch/arm/mach-omap2/omap_device.h
3581 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3582 /* Core code interface */
3583
3584 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3585 - struct omap_hwmod *oh, void *pdata,
3586 + struct omap_hwmod *oh, const void *pdata,
3587 int pdata_len);
3588
3589 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3590 struct omap_hwmod **oh, int oh_cnt,
3591 - void *pdata, int pdata_len);
3592 + const void *pdata, int pdata_len);
3593
3594 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3595 struct omap_hwmod **ohs, int oh_cnt);
3596 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3597 index 8a1b5e0..5f30074 100644
3598 --- a/arch/arm/mach-omap2/omap_hwmod.c
3599 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3600 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3601 int (*init_clkdm)(struct omap_hwmod *oh);
3602 void (*update_context_lost)(struct omap_hwmod *oh);
3603 int (*get_context_lost)(struct omap_hwmod *oh);
3604 -};
3605 +} __no_const;
3606
3607 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3608 -static struct omap_hwmod_soc_ops soc_ops;
3609 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3610
3611 /* omap_hwmod_list contains all registered struct omap_hwmods */
3612 static LIST_HEAD(omap_hwmod_list);
3613 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3614 index 95fee54..cfa9cf1 100644
3615 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3616 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3617 @@ -10,6 +10,7 @@
3618
3619 #include <linux/kernel.h>
3620 #include <linux/init.h>
3621 +#include <asm/pgtable.h>
3622
3623 #include "powerdomain.h"
3624
3625 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3626
3627 void __init am43xx_powerdomains_init(void)
3628 {
3629 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3630 + pax_open_kernel();
3631 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3632 + pax_close_kernel();
3633 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3634 pwrdm_register_pwrdms(powerdomains_am43xx);
3635 pwrdm_complete_init();
3636 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3637 index d15c7bb..b2d1f0c 100644
3638 --- a/arch/arm/mach-omap2/wd_timer.c
3639 +++ b/arch/arm/mach-omap2/wd_timer.c
3640 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3641 struct omap_hwmod *oh;
3642 char *oh_name = "wd_timer2";
3643 char *dev_name = "omap_wdt";
3644 - struct omap_wd_timer_platform_data pdata;
3645 + static struct omap_wd_timer_platform_data pdata = {
3646 + .read_reset_sources = prm_read_reset_sources
3647 + };
3648
3649 if (!cpu_class_is_omap2() || of_have_populated_dt())
3650 return 0;
3651 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3652 return -EINVAL;
3653 }
3654
3655 - pdata.read_reset_sources = prm_read_reset_sources;
3656 -
3657 pdev = omap_device_build(dev_name, id, oh, &pdata,
3658 sizeof(struct omap_wd_timer_platform_data));
3659 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3660 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3661 index b82dcae..44ee5b6 100644
3662 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3663 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3664 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3665 bool entered_lp2 = false;
3666
3667 if (tegra_pending_sgi())
3668 - ACCESS_ONCE(abort_flag) = true;
3669 + ACCESS_ONCE_RW(abort_flag) = true;
3670
3671 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3672
3673 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3674 index bdb3564..cebb96f 100644
3675 --- a/arch/arm/mach-ux500/setup.h
3676 +++ b/arch/arm/mach-ux500/setup.h
3677 @@ -39,13 +39,6 @@ extern void ux500_timer_init(void);
3678 .type = MT_DEVICE, \
3679 }
3680
3681 -#define __MEM_DEV_DESC(x, sz) { \
3682 - .virtual = IO_ADDRESS(x), \
3683 - .pfn = __phys_to_pfn(x), \
3684 - .length = sz, \
3685 - .type = MT_MEMORY, \
3686 -}
3687 -
3688 extern struct smp_operations ux500_smp_ops;
3689 extern void ux500_cpu_die(unsigned int cpu);
3690
3691 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3692 index 1f8fed9..14d7823 100644
3693 --- a/arch/arm/mm/Kconfig
3694 +++ b/arch/arm/mm/Kconfig
3695 @@ -446,7 +446,7 @@ config CPU_32v5
3696
3697 config CPU_32v6
3698 bool
3699 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3700 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3701 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3702
3703 config CPU_32v6K
3704 @@ -601,6 +601,7 @@ config CPU_CP15_MPU
3705
3706 config CPU_USE_DOMAINS
3707 bool
3708 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3709 help
3710 This option enables or disables the use of domain switching
3711 via the set_fs() function.
3712 @@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3713 config KUSER_HELPERS
3714 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3715 default y
3716 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3717 help
3718 Warning: disabling this option may break user programs.
3719
3720 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3721 See Documentation/arm/kernel_user_helpers.txt for details.
3722
3723 However, the fixed address nature of these helpers can be used
3724 - by ROP (return orientated programming) authors when creating
3725 + by ROP (Return Oriented Programming) authors when creating
3726 exploits.
3727
3728 If all of the binaries and libraries which run on your platform
3729 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3730 index 9240364..a2b8cf3 100644
3731 --- a/arch/arm/mm/alignment.c
3732 +++ b/arch/arm/mm/alignment.c
3733 @@ -212,10 +212,12 @@ union offset_union {
3734 #define __get16_unaligned_check(ins,val,addr) \
3735 do { \
3736 unsigned int err = 0, v, a = addr; \
3737 + pax_open_userland(); \
3738 __get8_unaligned_check(ins,v,a,err); \
3739 val = v << ((BE) ? 8 : 0); \
3740 __get8_unaligned_check(ins,v,a,err); \
3741 val |= v << ((BE) ? 0 : 8); \
3742 + pax_close_userland(); \
3743 if (err) \
3744 goto fault; \
3745 } while (0)
3746 @@ -229,6 +231,7 @@ union offset_union {
3747 #define __get32_unaligned_check(ins,val,addr) \
3748 do { \
3749 unsigned int err = 0, v, a = addr; \
3750 + pax_open_userland(); \
3751 __get8_unaligned_check(ins,v,a,err); \
3752 val = v << ((BE) ? 24 : 0); \
3753 __get8_unaligned_check(ins,v,a,err); \
3754 @@ -237,6 +240,7 @@ union offset_union {
3755 val |= v << ((BE) ? 8 : 16); \
3756 __get8_unaligned_check(ins,v,a,err); \
3757 val |= v << ((BE) ? 0 : 24); \
3758 + pax_close_userland(); \
3759 if (err) \
3760 goto fault; \
3761 } while (0)
3762 @@ -250,6 +254,7 @@ union offset_union {
3763 #define __put16_unaligned_check(ins,val,addr) \
3764 do { \
3765 unsigned int err = 0, v = val, a = addr; \
3766 + pax_open_userland(); \
3767 __asm__( FIRST_BYTE_16 \
3768 ARM( "1: "ins" %1, [%2], #1\n" ) \
3769 THUMB( "1: "ins" %1, [%2]\n" ) \
3770 @@ -269,6 +274,7 @@ union offset_union {
3771 " .popsection\n" \
3772 : "=r" (err), "=&r" (v), "=&r" (a) \
3773 : "0" (err), "1" (v), "2" (a)); \
3774 + pax_close_userland(); \
3775 if (err) \
3776 goto fault; \
3777 } while (0)
3778 @@ -282,6 +288,7 @@ union offset_union {
3779 #define __put32_unaligned_check(ins,val,addr) \
3780 do { \
3781 unsigned int err = 0, v = val, a = addr; \
3782 + pax_open_userland(); \
3783 __asm__( FIRST_BYTE_32 \
3784 ARM( "1: "ins" %1, [%2], #1\n" ) \
3785 THUMB( "1: "ins" %1, [%2]\n" ) \
3786 @@ -311,6 +318,7 @@ union offset_union {
3787 " .popsection\n" \
3788 : "=r" (err), "=&r" (v), "=&r" (a) \
3789 : "0" (err), "1" (v), "2" (a)); \
3790 + pax_close_userland(); \
3791 if (err) \
3792 goto fault; \
3793 } while (0)
3794 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3795 index 447da6f..77a5057 100644
3796 --- a/arch/arm/mm/cache-l2x0.c
3797 +++ b/arch/arm/mm/cache-l2x0.c
3798 @@ -45,7 +45,7 @@ struct l2x0_of_data {
3799 void (*setup)(const struct device_node *, u32 *, u32 *);
3800 void (*save)(void);
3801 struct outer_cache_fns outer_cache;
3802 -};
3803 +} __do_const;
3804
3805 static bool of_init = false;
3806
3807 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3808 index 84e6f77..0b52f31 100644
3809 --- a/arch/arm/mm/context.c
3810 +++ b/arch/arm/mm/context.c
3811 @@ -43,7 +43,7 @@
3812 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3813
3814 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3815 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3816 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3817 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3818
3819 static DEFINE_PER_CPU(atomic64_t, active_asids);
3820 @@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3821 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3822 {
3823 u64 asid = atomic64_read(&mm->context.id);
3824 - u64 generation = atomic64_read(&asid_generation);
3825 + u64 generation = atomic64_read_unchecked(&asid_generation);
3826
3827 if (asid != 0 && is_reserved_asid(asid)) {
3828 /*
3829 @@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3830 */
3831 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3832 if (asid == NUM_USER_ASIDS) {
3833 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3834 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3835 &asid_generation);
3836 flush_context(cpu);
3837 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3838 @@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3839 cpu_set_reserved_ttbr0();
3840
3841 asid = atomic64_read(&mm->context.id);
3842 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3843 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3844 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3845 goto switch_mm_fastpath;
3846
3847 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3848 /* Check that our ASID belongs to the current generation. */
3849 asid = atomic64_read(&mm->context.id);
3850 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3851 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3852 asid = new_context(mm, cpu);
3853 atomic64_set(&mm->context.id, asid);
3854 }
3855 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3856 index eb8830a..5360ce7 100644
3857 --- a/arch/arm/mm/fault.c
3858 +++ b/arch/arm/mm/fault.c
3859 @@ -25,6 +25,7 @@
3860 #include <asm/system_misc.h>
3861 #include <asm/system_info.h>
3862 #include <asm/tlbflush.h>
3863 +#include <asm/sections.h>
3864
3865 #include "fault.h"
3866
3867 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3868 if (fixup_exception(regs))
3869 return;
3870
3871 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3872 + if (addr < TASK_SIZE) {
3873 + if (current->signal->curr_ip)
3874 + 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),
3875 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3876 + else
3877 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3878 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3879 + }
3880 +#endif
3881 +
3882 +#ifdef CONFIG_PAX_KERNEXEC
3883 + if ((fsr & FSR_WRITE) &&
3884 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3885 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3886 + {
3887 + if (current->signal->curr_ip)
3888 + 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),
3889 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3890 + else
3891 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3892 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3893 + }
3894 +#endif
3895 +
3896 /*
3897 * No handler, we'll have to terminate things with extreme prejudice.
3898 */
3899 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3900 }
3901 #endif
3902
3903 +#ifdef CONFIG_PAX_PAGEEXEC
3904 + if (fsr & FSR_LNX_PF) {
3905 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3906 + do_group_exit(SIGKILL);
3907 + }
3908 +#endif
3909 +
3910 tsk->thread.address = addr;
3911 tsk->thread.error_code = fsr;
3912 tsk->thread.trap_no = 14;
3913 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3914 }
3915 #endif /* CONFIG_MMU */
3916
3917 +#ifdef CONFIG_PAX_PAGEEXEC
3918 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3919 +{
3920 + long i;
3921 +
3922 + printk(KERN_ERR "PAX: bytes at PC: ");
3923 + for (i = 0; i < 20; i++) {
3924 + unsigned char c;
3925 + if (get_user(c, (__force unsigned char __user *)pc+i))
3926 + printk(KERN_CONT "?? ");
3927 + else
3928 + printk(KERN_CONT "%02x ", c);
3929 + }
3930 + printk("\n");
3931 +
3932 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3933 + for (i = -1; i < 20; i++) {
3934 + unsigned long c;
3935 + if (get_user(c, (__force unsigned long __user *)sp+i))
3936 + printk(KERN_CONT "???????? ");
3937 + else
3938 + printk(KERN_CONT "%08lx ", c);
3939 + }
3940 + printk("\n");
3941 +}
3942 +#endif
3943 +
3944 /*
3945 * First Level Translation Fault Handler
3946 *
3947 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3948 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3949 struct siginfo info;
3950
3951 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3952 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3953 + if (current->signal->curr_ip)
3954 + 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),
3955 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3956 + else
3957 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3958 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3959 + goto die;
3960 + }
3961 +#endif
3962 +
3963 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3964 return;
3965
3966 +die:
3967 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3968 inf->name, fsr, addr);
3969
3970 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3971 ifsr_info[nr].name = name;
3972 }
3973
3974 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
3975 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3976 +
3977 asmlinkage void __exception
3978 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3979 {
3980 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3981 struct siginfo info;
3982 + unsigned long pc = instruction_pointer(regs);
3983 +
3984 + if (user_mode(regs)) {
3985 + unsigned long sigpage = current->mm->context.sigpage;
3986 +
3987 + if (sigpage <= pc && pc < sigpage + 7*4) {
3988 + if (pc < sigpage + 3*4)
3989 + sys_sigreturn(regs);
3990 + else
3991 + sys_rt_sigreturn(regs);
3992 + return;
3993 + }
3994 + if (pc == 0xffff0f60UL) {
3995 + /*
3996 + * PaX: __kuser_cmpxchg64 emulation
3997 + */
3998 + // TODO
3999 + //regs->ARM_pc = regs->ARM_lr;
4000 + //return;
4001 + }
4002 + if (pc == 0xffff0fa0UL) {
4003 + /*
4004 + * PaX: __kuser_memory_barrier emulation
4005 + */
4006 + // dmb(); implied by the exception
4007 + regs->ARM_pc = regs->ARM_lr;
4008 + return;
4009 + }
4010 + if (pc == 0xffff0fc0UL) {
4011 + /*
4012 + * PaX: __kuser_cmpxchg emulation
4013 + */
4014 + // TODO
4015 + //long new;
4016 + //int op;
4017 +
4018 + //op = FUTEX_OP_SET << 28;
4019 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4020 + //regs->ARM_r0 = old != new;
4021 + //regs->ARM_pc = regs->ARM_lr;
4022 + //return;
4023 + }
4024 + if (pc == 0xffff0fe0UL) {
4025 + /*
4026 + * PaX: __kuser_get_tls emulation
4027 + */
4028 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4029 + regs->ARM_pc = regs->ARM_lr;
4030 + return;
4031 + }
4032 + }
4033 +
4034 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4035 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4036 + if (current->signal->curr_ip)
4037 + 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),
4038 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4039 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4040 + else
4041 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4042 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4043 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4044 + goto die;
4045 + }
4046 +#endif
4047 +
4048 +#ifdef CONFIG_PAX_REFCOUNT
4049 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4050 + unsigned int bkpt;
4051 +
4052 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4053 + current->thread.error_code = ifsr;
4054 + current->thread.trap_no = 0;
4055 + pax_report_refcount_overflow(regs);
4056 + fixup_exception(regs);
4057 + return;
4058 + }
4059 + }
4060 +#endif
4061
4062 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4063 return;
4064
4065 +die:
4066 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4067 inf->name, ifsr, addr);
4068
4069 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4070 index cf08bdf..772656c 100644
4071 --- a/arch/arm/mm/fault.h
4072 +++ b/arch/arm/mm/fault.h
4073 @@ -3,6 +3,7 @@
4074
4075 /*
4076 * Fault status register encodings. We steal bit 31 for our own purposes.
4077 + * Set when the FSR value is from an instruction fault.
4078 */
4079 #define FSR_LNX_PF (1 << 31)
4080 #define FSR_WRITE (1 << 11)
4081 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4082 }
4083 #endif
4084
4085 +/* valid for LPAE and !LPAE */
4086 +static inline int is_xn_fault(unsigned int fsr)
4087 +{
4088 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4089 +}
4090 +
4091 +static inline int is_domain_fault(unsigned int fsr)
4092 +{
4093 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4094 +}
4095 +
4096 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4097 unsigned long search_exception_table(unsigned long addr);
4098
4099 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4100 index ac1d883..5a7bb91 100644
4101 --- a/arch/arm/mm/init.c
4102 +++ b/arch/arm/mm/init.c
4103 @@ -30,6 +30,8 @@
4104 #include <asm/setup.h>
4105 #include <asm/tlb.h>
4106 #include <asm/fixmap.h>
4107 +#include <asm/system_info.h>
4108 +#include <asm/cp15.h>
4109
4110 #include <asm/mach/arch.h>
4111 #include <asm/mach/map.h>
4112 @@ -682,7 +684,46 @@ void free_initmem(void)
4113 {
4114 #ifdef CONFIG_HAVE_TCM
4115 extern char __tcm_start, __tcm_end;
4116 +#endif
4117
4118 +#ifdef CONFIG_PAX_KERNEXEC
4119 + unsigned long addr;
4120 + pgd_t *pgd;
4121 + pud_t *pud;
4122 + pmd_t *pmd;
4123 + int cpu_arch = cpu_architecture();
4124 + unsigned int cr = get_cr();
4125 +
4126 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4127 + /* make pages tables, etc before .text NX */
4128 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4129 + pgd = pgd_offset_k(addr);
4130 + pud = pud_offset(pgd, addr);
4131 + pmd = pmd_offset(pud, addr);
4132 + __section_update(pmd, addr, PMD_SECT_XN);
4133 + }
4134 + /* make init NX */
4135 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4136 + pgd = pgd_offset_k(addr);
4137 + pud = pud_offset(pgd, addr);
4138 + pmd = pmd_offset(pud, addr);
4139 + __section_update(pmd, addr, PMD_SECT_XN);
4140 + }
4141 + /* make kernel code/rodata RX */
4142 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4143 + pgd = pgd_offset_k(addr);
4144 + pud = pud_offset(pgd, addr);
4145 + pmd = pmd_offset(pud, addr);
4146 +#ifdef CONFIG_ARM_LPAE
4147 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4148 +#else
4149 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4150 +#endif
4151 + }
4152 + }
4153 +#endif
4154 +
4155 +#ifdef CONFIG_HAVE_TCM
4156 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4157 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4158 #endif
4159 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4160 index f123d6e..04bf569 100644
4161 --- a/arch/arm/mm/ioremap.c
4162 +++ b/arch/arm/mm/ioremap.c
4163 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4164 unsigned int mtype;
4165
4166 if (cached)
4167 - mtype = MT_MEMORY;
4168 + mtype = MT_MEMORY_RX;
4169 else
4170 - mtype = MT_MEMORY_NONCACHED;
4171 + mtype = MT_MEMORY_NONCACHED_RX;
4172
4173 return __arm_ioremap_caller(phys_addr, size, mtype,
4174 __builtin_return_address(0));
4175 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4176 index 5e85ed3..b10a7ed 100644
4177 --- a/arch/arm/mm/mmap.c
4178 +++ b/arch/arm/mm/mmap.c
4179 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4180 struct vm_area_struct *vma;
4181 int do_align = 0;
4182 int aliasing = cache_is_vipt_aliasing();
4183 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4184 struct vm_unmapped_area_info info;
4185
4186 /*
4187 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4188 if (len > TASK_SIZE)
4189 return -ENOMEM;
4190
4191 +#ifdef CONFIG_PAX_RANDMMAP
4192 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4193 +#endif
4194 +
4195 if (addr) {
4196 if (do_align)
4197 addr = COLOUR_ALIGN(addr, pgoff);
4198 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4199 addr = PAGE_ALIGN(addr);
4200
4201 vma = find_vma(mm, addr);
4202 - if (TASK_SIZE - len >= addr &&
4203 - (!vma || addr + len <= vma->vm_start))
4204 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4205 return addr;
4206 }
4207
4208 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4209 info.high_limit = TASK_SIZE;
4210 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4211 info.align_offset = pgoff << PAGE_SHIFT;
4212 + info.threadstack_offset = offset;
4213 return vm_unmapped_area(&info);
4214 }
4215
4216 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4217 unsigned long addr = addr0;
4218 int do_align = 0;
4219 int aliasing = cache_is_vipt_aliasing();
4220 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4221 struct vm_unmapped_area_info info;
4222
4223 /*
4224 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4225 return addr;
4226 }
4227
4228 +#ifdef CONFIG_PAX_RANDMMAP
4229 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4230 +#endif
4231 +
4232 /* requesting a specific address */
4233 if (addr) {
4234 if (do_align)
4235 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4236 else
4237 addr = PAGE_ALIGN(addr);
4238 vma = find_vma(mm, addr);
4239 - if (TASK_SIZE - len >= addr &&
4240 - (!vma || addr + len <= vma->vm_start))
4241 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4242 return addr;
4243 }
4244
4245 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4246 info.high_limit = mm->mmap_base;
4247 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4248 info.align_offset = pgoff << PAGE_SHIFT;
4249 + info.threadstack_offset = offset;
4250 addr = vm_unmapped_area(&info);
4251
4252 /*
4253 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4254 {
4255 unsigned long random_factor = 0UL;
4256
4257 +#ifdef CONFIG_PAX_RANDMMAP
4258 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4259 +#endif
4260 +
4261 /* 8 bits of randomness in 20 address space bits */
4262 if ((current->flags & PF_RANDOMIZE) &&
4263 !(current->personality & ADDR_NO_RANDOMIZE))
4264 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4265
4266 if (mmap_is_legacy()) {
4267 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4268 +
4269 +#ifdef CONFIG_PAX_RANDMMAP
4270 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4271 + mm->mmap_base += mm->delta_mmap;
4272 +#endif
4273 +
4274 mm->get_unmapped_area = arch_get_unmapped_area;
4275 } else {
4276 mm->mmap_base = mmap_base(random_factor);
4277 +
4278 +#ifdef CONFIG_PAX_RANDMMAP
4279 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4280 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4281 +#endif
4282 +
4283 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4284 }
4285 }
4286 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4287 index 911d433..8580952 100644
4288 --- a/arch/arm/mm/mmu.c
4289 +++ b/arch/arm/mm/mmu.c
4290 @@ -38,6 +38,22 @@
4291 #include "mm.h"
4292 #include "tcm.h"
4293
4294 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4295 +void modify_domain(unsigned int dom, unsigned int type)
4296 +{
4297 + struct thread_info *thread = current_thread_info();
4298 + unsigned int domain = thread->cpu_domain;
4299 + /*
4300 + * DOMAIN_MANAGER might be defined to some other value,
4301 + * use the arch-defined constant
4302 + */
4303 + domain &= ~domain_val(dom, 3);
4304 + thread->cpu_domain = domain | domain_val(dom, type);
4305 + set_domain(thread->cpu_domain);
4306 +}
4307 +EXPORT_SYMBOL(modify_domain);
4308 +#endif
4309 +
4310 /*
4311 * empty_zero_page is a special page that is used for
4312 * zero-initialized data and COW.
4313 @@ -230,11 +246,19 @@ __setup("noalign", noalign_setup);
4314
4315 #endif /* ifdef CONFIG_CPU_CP15 / else */
4316
4317 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4318 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4319 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4320 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4321
4322 -static struct mem_type mem_types[] = {
4323 +#ifdef CONFIG_PAX_KERNEXEC
4324 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4325 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4326 +#else
4327 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4328 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4329 +#endif
4330 +
4331 +static struct mem_type mem_types[] __read_only = {
4332 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4333 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4334 L_PTE_SHARED,
4335 @@ -266,16 +290,16 @@ static struct mem_type mem_types[] = {
4336 [MT_UNCACHED] = {
4337 .prot_pte = PROT_PTE_DEVICE,
4338 .prot_l1 = PMD_TYPE_TABLE,
4339 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4340 + .prot_sect = PROT_SECT_DEVICE,
4341 .domain = DOMAIN_IO,
4342 },
4343 [MT_CACHECLEAN] = {
4344 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4345 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4346 .domain = DOMAIN_KERNEL,
4347 },
4348 #ifndef CONFIG_ARM_LPAE
4349 [MT_MINICLEAN] = {
4350 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4351 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4352 .domain = DOMAIN_KERNEL,
4353 },
4354 #endif
4355 @@ -283,36 +307,54 @@ static struct mem_type mem_types[] = {
4356 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4357 L_PTE_RDONLY,
4358 .prot_l1 = PMD_TYPE_TABLE,
4359 - .domain = DOMAIN_USER,
4360 + .domain = DOMAIN_VECTORS,
4361 },
4362 [MT_HIGH_VECTORS] = {
4363 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4364 L_PTE_USER | L_PTE_RDONLY,
4365 .prot_l1 = PMD_TYPE_TABLE,
4366 - .domain = DOMAIN_USER,
4367 + .domain = DOMAIN_VECTORS,
4368 },
4369 - [MT_MEMORY] = {
4370 + [MT_MEMORY_RWX] = {
4371 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4372 .prot_l1 = PMD_TYPE_TABLE,
4373 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4374 .domain = DOMAIN_KERNEL,
4375 },
4376 + [MT_MEMORY_RW] = {
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 + .domain = DOMAIN_KERNEL,
4381 + },
4382 + [MT_MEMORY_RX] = {
4383 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4384 + .prot_l1 = PMD_TYPE_TABLE,
4385 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4386 + .domain = DOMAIN_KERNEL,
4387 + },
4388 [MT_ROM] = {
4389 - .prot_sect = PMD_TYPE_SECT,
4390 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4391 .domain = DOMAIN_KERNEL,
4392 },
4393 - [MT_MEMORY_NONCACHED] = {
4394 + [MT_MEMORY_NONCACHED_RW] = {
4395 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4396 L_PTE_MT_BUFFERABLE,
4397 .prot_l1 = PMD_TYPE_TABLE,
4398 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4399 .domain = DOMAIN_KERNEL,
4400 },
4401 + [MT_MEMORY_NONCACHED_RX] = {
4402 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4403 + L_PTE_MT_BUFFERABLE,
4404 + .prot_l1 = PMD_TYPE_TABLE,
4405 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4406 + .domain = DOMAIN_KERNEL,
4407 + },
4408 [MT_MEMORY_DTCM] = {
4409 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4410 - L_PTE_XN,
4411 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4412 .prot_l1 = PMD_TYPE_TABLE,
4413 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4414 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4415 .domain = DOMAIN_KERNEL,
4416 },
4417 [MT_MEMORY_ITCM] = {
4418 @@ -322,10 +364,10 @@ static struct mem_type mem_types[] = {
4419 },
4420 [MT_MEMORY_SO] = {
4421 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4422 - L_PTE_MT_UNCACHED | L_PTE_XN,
4423 + L_PTE_MT_UNCACHED,
4424 .prot_l1 = PMD_TYPE_TABLE,
4425 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4426 - PMD_SECT_UNCACHED | PMD_SECT_XN,
4427 + PMD_SECT_UNCACHED,
4428 .domain = DOMAIN_KERNEL,
4429 },
4430 [MT_MEMORY_DMA_READY] = {
4431 @@ -411,9 +453,35 @@ static void __init build_mem_type_table(void)
4432 * to prevent speculative instruction fetches.
4433 */
4434 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4435 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4436 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4437 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4438 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4439 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4440 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4441 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4442 +
4443 + /* Mark other regions on ARMv6+ as execute-never */
4444 +
4445 +#ifdef CONFIG_PAX_KERNEXEC
4446 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4447 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4448 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4449 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4450 +#ifndef CONFIG_ARM_LPAE
4451 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4452 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4453 +#endif
4454 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4455 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4456 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4457 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4458 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4459 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4460 +#endif
4461 +
4462 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4463 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4464 }
4465 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4466 /*
4467 @@ -475,6 +543,9 @@ static void __init build_mem_type_table(void)
4468 * from SVC mode and no access from userspace.
4469 */
4470 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4471 +#ifdef CONFIG_PAX_KERNEXEC
4472 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4473 +#endif
4474 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4475 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4476 #endif
4477 @@ -492,11 +563,17 @@ static void __init build_mem_type_table(void)
4478 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4479 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4480 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4481 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4482 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4483 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4484 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4485 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4486 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4487 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4488 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4489 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4490 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4491 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4492 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4493 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4494 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4495 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4496 }
4497 }
4498
4499 @@ -507,15 +584,20 @@ static void __init build_mem_type_table(void)
4500 if (cpu_arch >= CPU_ARCH_ARMv6) {
4501 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4502 /* Non-cacheable Normal is XCB = 001 */
4503 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4504 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4505 + PMD_SECT_BUFFERED;
4506 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4507 PMD_SECT_BUFFERED;
4508 } else {
4509 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4510 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4511 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4512 + PMD_SECT_TEX(1);
4513 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4514 PMD_SECT_TEX(1);
4515 }
4516 } else {
4517 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4518 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4519 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4520 }
4521
4522 #ifdef CONFIG_ARM_LPAE
4523 @@ -531,6 +613,8 @@ static void __init build_mem_type_table(void)
4524 vecs_pgprot |= PTE_EXT_AF;
4525 #endif
4526
4527 + user_pgprot |= __supported_pte_mask;
4528 +
4529 for (i = 0; i < 16; i++) {
4530 pteval_t v = pgprot_val(protection_map[i]);
4531 protection_map[i] = __pgprot(v | user_pgprot);
4532 @@ -548,10 +632,15 @@ static void __init build_mem_type_table(void)
4533
4534 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4535 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4536 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4537 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4538 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4539 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4540 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4541 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4542 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4543 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4544 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4545 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4546 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4547 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4548 mem_types[MT_ROM].prot_sect |= cp->pmd;
4549
4550 switch (cp->pmd) {
4551 @@ -1193,18 +1282,15 @@ void __init arm_mm_memblock_reserve(void)
4552 * called function. This means you can't use any function or debugging
4553 * method which may touch any device, otherwise the kernel _will_ crash.
4554 */
4555 +
4556 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4557 +
4558 static void __init devicemaps_init(const struct machine_desc *mdesc)
4559 {
4560 struct map_desc map;
4561 unsigned long addr;
4562 - void *vectors;
4563
4564 - /*
4565 - * Allocate the vector page early.
4566 - */
4567 - vectors = early_alloc(PAGE_SIZE * 2);
4568 -
4569 - early_trap_init(vectors);
4570 + early_trap_init(&vectors);
4571
4572 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4573 pmd_clear(pmd_off_k(addr));
4574 @@ -1244,7 +1330,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4575 * location (0xffff0000). If we aren't using high-vectors, also
4576 * create a mapping at the low-vectors virtual address.
4577 */
4578 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4579 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4580 map.virtual = 0xffff0000;
4581 map.length = PAGE_SIZE;
4582 #ifdef CONFIG_KUSER_HELPERS
4583 @@ -1316,8 +1402,39 @@ static void __init map_lowmem(void)
4584 map.pfn = __phys_to_pfn(start);
4585 map.virtual = __phys_to_virt(start);
4586 map.length = end - start;
4587 - map.type = MT_MEMORY;
4588
4589 +#ifdef CONFIG_PAX_KERNEXEC
4590 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4591 + struct map_desc kernel;
4592 + struct map_desc initmap;
4593 +
4594 + /* when freeing initmem we will make this RW */
4595 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4596 + initmap.virtual = (unsigned long)__init_begin;
4597 + initmap.length = _sdata - __init_begin;
4598 + initmap.type = MT_MEMORY_RWX;
4599 + create_mapping(&initmap);
4600 +
4601 + /* when freeing initmem we will make this RX */
4602 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4603 + kernel.virtual = (unsigned long)_stext;
4604 + kernel.length = __init_begin - _stext;
4605 + kernel.type = MT_MEMORY_RWX;
4606 + create_mapping(&kernel);
4607 +
4608 + if (map.virtual < (unsigned long)_stext) {
4609 + map.length = (unsigned long)_stext - map.virtual;
4610 + map.type = MT_MEMORY_RWX;
4611 + create_mapping(&map);
4612 + }
4613 +
4614 + map.pfn = __phys_to_pfn(__pa(_sdata));
4615 + map.virtual = (unsigned long)_sdata;
4616 + map.length = end - __pa(_sdata);
4617 + }
4618 +#endif
4619 +
4620 + map.type = MT_MEMORY_RW;
4621 create_mapping(&map);
4622 }
4623 }
4624 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4625 index a5bc92d..0bb4730 100644
4626 --- a/arch/arm/plat-omap/sram.c
4627 +++ b/arch/arm/plat-omap/sram.c
4628 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4629 * Looks like we need to preserve some bootloader code at the
4630 * beginning of SRAM for jumping to flash for reboot to work...
4631 */
4632 + pax_open_kernel();
4633 memset_io(omap_sram_base + omap_sram_skip, 0,
4634 omap_sram_size - omap_sram_skip);
4635 + pax_close_kernel();
4636 }
4637 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4638 index ce6d763..cfea917 100644
4639 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4640 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4641 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4642 int (*started)(unsigned ch);
4643 int (*flush)(unsigned ch);
4644 int (*stop)(unsigned ch);
4645 -};
4646 +} __no_const;
4647
4648 extern void *samsung_dmadev_get_ops(void);
4649 extern void *s3c_dma_get_ops(void);
4650 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4651 index 7ecc2b2..5e56c66 100644
4652 --- a/arch/arm64/include/asm/uaccess.h
4653 +++ b/arch/arm64/include/asm/uaccess.h
4654 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4655 flag; \
4656 })
4657
4658 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4659 #define access_ok(type, addr, size) __range_ok(addr, size)
4660
4661 /*
4662 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4663 index c3a58a1..78fbf54 100644
4664 --- a/arch/avr32/include/asm/cache.h
4665 +++ b/arch/avr32/include/asm/cache.h
4666 @@ -1,8 +1,10 @@
4667 #ifndef __ASM_AVR32_CACHE_H
4668 #define __ASM_AVR32_CACHE_H
4669
4670 +#include <linux/const.h>
4671 +
4672 #define L1_CACHE_SHIFT 5
4673 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4674 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4675
4676 /*
4677 * Memory returned by kmalloc() may be used for DMA, so we must make
4678 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4679 index d232888..87c8df1 100644
4680 --- a/arch/avr32/include/asm/elf.h
4681 +++ b/arch/avr32/include/asm/elf.h
4682 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4683 the loader. We need to make sure that it is out of the way of the program
4684 that it will "exec", and that there is sufficient room for the brk. */
4685
4686 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4687 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4688
4689 +#ifdef CONFIG_PAX_ASLR
4690 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4691 +
4692 +#define PAX_DELTA_MMAP_LEN 15
4693 +#define PAX_DELTA_STACK_LEN 15
4694 +#endif
4695
4696 /* This yields a mask that user programs can use to figure out what
4697 instruction set this CPU supports. This could be done in user space,
4698 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4699 index 479330b..53717a8 100644
4700 --- a/arch/avr32/include/asm/kmap_types.h
4701 +++ b/arch/avr32/include/asm/kmap_types.h
4702 @@ -2,9 +2,9 @@
4703 #define __ASM_AVR32_KMAP_TYPES_H
4704
4705 #ifdef CONFIG_DEBUG_HIGHMEM
4706 -# define KM_TYPE_NR 29
4707 +# define KM_TYPE_NR 30
4708 #else
4709 -# define KM_TYPE_NR 14
4710 +# define KM_TYPE_NR 15
4711 #endif
4712
4713 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4714 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4715 index 0eca933..eb78c7b 100644
4716 --- a/arch/avr32/mm/fault.c
4717 +++ b/arch/avr32/mm/fault.c
4718 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4719
4720 int exception_trace = 1;
4721
4722 +#ifdef CONFIG_PAX_PAGEEXEC
4723 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4724 +{
4725 + unsigned long i;
4726 +
4727 + printk(KERN_ERR "PAX: bytes at PC: ");
4728 + for (i = 0; i < 20; i++) {
4729 + unsigned char c;
4730 + if (get_user(c, (unsigned char *)pc+i))
4731 + printk(KERN_CONT "???????? ");
4732 + else
4733 + printk(KERN_CONT "%02x ", c);
4734 + }
4735 + printk("\n");
4736 +}
4737 +#endif
4738 +
4739 /*
4740 * This routine handles page faults. It determines the address and the
4741 * problem, and then passes it off to one of the appropriate routines.
4742 @@ -176,6 +193,16 @@ bad_area:
4743 up_read(&mm->mmap_sem);
4744
4745 if (user_mode(regs)) {
4746 +
4747 +#ifdef CONFIG_PAX_PAGEEXEC
4748 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4749 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4750 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4751 + do_group_exit(SIGKILL);
4752 + }
4753 + }
4754 +#endif
4755 +
4756 if (exception_trace && printk_ratelimit())
4757 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4758 "sp %08lx ecr %lu\n",
4759 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4760 index 568885a..f8008df 100644
4761 --- a/arch/blackfin/include/asm/cache.h
4762 +++ b/arch/blackfin/include/asm/cache.h
4763 @@ -7,6 +7,7 @@
4764 #ifndef __ARCH_BLACKFIN_CACHE_H
4765 #define __ARCH_BLACKFIN_CACHE_H
4766
4767 +#include <linux/const.h>
4768 #include <linux/linkage.h> /* for asmlinkage */
4769
4770 /*
4771 @@ -14,7 +15,7 @@
4772 * Blackfin loads 32 bytes for cache
4773 */
4774 #define L1_CACHE_SHIFT 5
4775 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4776 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4777 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4778
4779 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4780 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4781 index aea2718..3639a60 100644
4782 --- a/arch/cris/include/arch-v10/arch/cache.h
4783 +++ b/arch/cris/include/arch-v10/arch/cache.h
4784 @@ -1,8 +1,9 @@
4785 #ifndef _ASM_ARCH_CACHE_H
4786 #define _ASM_ARCH_CACHE_H
4787
4788 +#include <linux/const.h>
4789 /* Etrax 100LX have 32-byte cache-lines. */
4790 -#define L1_CACHE_BYTES 32
4791 #define L1_CACHE_SHIFT 5
4792 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4793
4794 #endif /* _ASM_ARCH_CACHE_H */
4795 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4796 index 7caf25d..ee65ac5 100644
4797 --- a/arch/cris/include/arch-v32/arch/cache.h
4798 +++ b/arch/cris/include/arch-v32/arch/cache.h
4799 @@ -1,11 +1,12 @@
4800 #ifndef _ASM_CRIS_ARCH_CACHE_H
4801 #define _ASM_CRIS_ARCH_CACHE_H
4802
4803 +#include <linux/const.h>
4804 #include <arch/hwregs/dma.h>
4805
4806 /* A cache-line is 32 bytes. */
4807 -#define L1_CACHE_BYTES 32
4808 #define L1_CACHE_SHIFT 5
4809 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4810
4811 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4812
4813 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4814 index b86329d..6709906 100644
4815 --- a/arch/frv/include/asm/atomic.h
4816 +++ b/arch/frv/include/asm/atomic.h
4817 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4818 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4819 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4820
4821 +#define atomic64_read_unchecked(v) atomic64_read(v)
4822 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4823 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4824 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4825 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4826 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4827 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4828 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4829 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4830 +
4831 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4832 {
4833 int c, old;
4834 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4835 index 2797163..c2a401d 100644
4836 --- a/arch/frv/include/asm/cache.h
4837 +++ b/arch/frv/include/asm/cache.h
4838 @@ -12,10 +12,11 @@
4839 #ifndef __ASM_CACHE_H
4840 #define __ASM_CACHE_H
4841
4842 +#include <linux/const.h>
4843
4844 /* bytes per L1 cache line */
4845 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4846 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4847 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4848
4849 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4850 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4851 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4852 index 43901f2..0d8b865 100644
4853 --- a/arch/frv/include/asm/kmap_types.h
4854 +++ b/arch/frv/include/asm/kmap_types.h
4855 @@ -2,6 +2,6 @@
4856 #ifndef _ASM_KMAP_TYPES_H
4857 #define _ASM_KMAP_TYPES_H
4858
4859 -#define KM_TYPE_NR 17
4860 +#define KM_TYPE_NR 18
4861
4862 #endif
4863 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4864 index 836f147..4cf23f5 100644
4865 --- a/arch/frv/mm/elf-fdpic.c
4866 +++ b/arch/frv/mm/elf-fdpic.c
4867 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4868 {
4869 struct vm_area_struct *vma;
4870 struct vm_unmapped_area_info info;
4871 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4872
4873 if (len > TASK_SIZE)
4874 return -ENOMEM;
4875 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4876 if (addr) {
4877 addr = PAGE_ALIGN(addr);
4878 vma = find_vma(current->mm, addr);
4879 - if (TASK_SIZE - len >= addr &&
4880 - (!vma || addr + len <= vma->vm_start))
4881 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4882 goto success;
4883 }
4884
4885 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4886 info.high_limit = (current->mm->start_stack - 0x00200000);
4887 info.align_mask = 0;
4888 info.align_offset = 0;
4889 + info.threadstack_offset = offset;
4890 addr = vm_unmapped_area(&info);
4891 if (!(addr & ~PAGE_MASK))
4892 goto success;
4893 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4894 index f4ca594..adc72fd6 100644
4895 --- a/arch/hexagon/include/asm/cache.h
4896 +++ b/arch/hexagon/include/asm/cache.h
4897 @@ -21,9 +21,11 @@
4898 #ifndef __ASM_CACHE_H
4899 #define __ASM_CACHE_H
4900
4901 +#include <linux/const.h>
4902 +
4903 /* Bytes per L1 cache line */
4904 -#define L1_CACHE_SHIFT (5)
4905 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4906 +#define L1_CACHE_SHIFT 5
4907 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4908
4909 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4910 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4911 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4912 index 4e4119b..dd7de0a 100644
4913 --- a/arch/ia64/Kconfig
4914 +++ b/arch/ia64/Kconfig
4915 @@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4916 config KEXEC
4917 bool "kexec system call"
4918 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4919 + depends on !GRKERNSEC_KMEM
4920 help
4921 kexec is a system call that implements the ability to shutdown your
4922 current kernel, and to start another kernel. It is like a reboot
4923 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4924 index 6e6fe18..a6ae668 100644
4925 --- a/arch/ia64/include/asm/atomic.h
4926 +++ b/arch/ia64/include/asm/atomic.h
4927 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4928 #define atomic64_inc(v) atomic64_add(1, (v))
4929 #define atomic64_dec(v) atomic64_sub(1, (v))
4930
4931 +#define atomic64_read_unchecked(v) atomic64_read(v)
4932 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4933 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4934 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4935 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4936 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4937 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4938 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4939 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4940 +
4941 /* Atomic operations are already serializing */
4942 #define smp_mb__before_atomic_dec() barrier()
4943 #define smp_mb__after_atomic_dec() barrier()
4944 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4945 index 988254a..e1ee885 100644
4946 --- a/arch/ia64/include/asm/cache.h
4947 +++ b/arch/ia64/include/asm/cache.h
4948 @@ -1,6 +1,7 @@
4949 #ifndef _ASM_IA64_CACHE_H
4950 #define _ASM_IA64_CACHE_H
4951
4952 +#include <linux/const.h>
4953
4954 /*
4955 * Copyright (C) 1998-2000 Hewlett-Packard Co
4956 @@ -9,7 +10,7 @@
4957
4958 /* Bytes per L1 (data) cache line. */
4959 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4960 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4961 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4962
4963 #ifdef CONFIG_SMP
4964 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4965 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4966 index 5a83c5c..4d7f553 100644
4967 --- a/arch/ia64/include/asm/elf.h
4968 +++ b/arch/ia64/include/asm/elf.h
4969 @@ -42,6 +42,13 @@
4970 */
4971 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4972
4973 +#ifdef CONFIG_PAX_ASLR
4974 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4975 +
4976 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4977 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4978 +#endif
4979 +
4980 #define PT_IA_64_UNWIND 0x70000001
4981
4982 /* IA-64 relocations: */
4983 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4984 index 5767cdf..7462574 100644
4985 --- a/arch/ia64/include/asm/pgalloc.h
4986 +++ b/arch/ia64/include/asm/pgalloc.h
4987 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4988 pgd_val(*pgd_entry) = __pa(pud);
4989 }
4990
4991 +static inline void
4992 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4993 +{
4994 + pgd_populate(mm, pgd_entry, pud);
4995 +}
4996 +
4997 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4998 {
4999 return quicklist_alloc(0, GFP_KERNEL, NULL);
5000 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5001 pud_val(*pud_entry) = __pa(pmd);
5002 }
5003
5004 +static inline void
5005 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5006 +{
5007 + pud_populate(mm, pud_entry, pmd);
5008 +}
5009 +
5010 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5011 {
5012 return quicklist_alloc(0, GFP_KERNEL, NULL);
5013 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5014 index 7935115..c0eca6a 100644
5015 --- a/arch/ia64/include/asm/pgtable.h
5016 +++ b/arch/ia64/include/asm/pgtable.h
5017 @@ -12,7 +12,7 @@
5018 * David Mosberger-Tang <davidm@hpl.hp.com>
5019 */
5020
5021 -
5022 +#include <linux/const.h>
5023 #include <asm/mman.h>
5024 #include <asm/page.h>
5025 #include <asm/processor.h>
5026 @@ -142,6 +142,17 @@
5027 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5028 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5029 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5030 +
5031 +#ifdef CONFIG_PAX_PAGEEXEC
5032 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5033 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5034 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5035 +#else
5036 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5037 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5038 +# define PAGE_COPY_NOEXEC PAGE_COPY
5039 +#endif
5040 +
5041 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5042 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5043 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5044 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5045 index 45698cd..e8e2dbc 100644
5046 --- a/arch/ia64/include/asm/spinlock.h
5047 +++ b/arch/ia64/include/asm/spinlock.h
5048 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5049 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5050
5051 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5052 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5053 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5054 }
5055
5056 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5057 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5058 index 449c8c0..3d4b1e9 100644
5059 --- a/arch/ia64/include/asm/uaccess.h
5060 +++ b/arch/ia64/include/asm/uaccess.h
5061 @@ -70,6 +70,7 @@
5062 && ((segment).seg == KERNEL_DS.seg \
5063 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5064 })
5065 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5066 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5067
5068 /*
5069 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5070 static inline unsigned long
5071 __copy_to_user (void __user *to, const void *from, unsigned long count)
5072 {
5073 + if (count > INT_MAX)
5074 + return count;
5075 +
5076 + if (!__builtin_constant_p(count))
5077 + check_object_size(from, count, true);
5078 +
5079 return __copy_user(to, (__force void __user *) from, count);
5080 }
5081
5082 static inline unsigned long
5083 __copy_from_user (void *to, const void __user *from, unsigned long count)
5084 {
5085 + if (count > INT_MAX)
5086 + return count;
5087 +
5088 + if (!__builtin_constant_p(count))
5089 + check_object_size(to, count, false);
5090 +
5091 return __copy_user((__force void __user *) to, from, count);
5092 }
5093
5094 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5095 ({ \
5096 void __user *__cu_to = (to); \
5097 const void *__cu_from = (from); \
5098 - long __cu_len = (n); \
5099 + unsigned long __cu_len = (n); \
5100 \
5101 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5102 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5103 + if (!__builtin_constant_p(n)) \
5104 + check_object_size(__cu_from, __cu_len, true); \
5105 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5106 + } \
5107 __cu_len; \
5108 })
5109
5110 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5111 ({ \
5112 void *__cu_to = (to); \
5113 const void __user *__cu_from = (from); \
5114 - long __cu_len = (n); \
5115 + unsigned long __cu_len = (n); \
5116 \
5117 __chk_user_ptr(__cu_from); \
5118 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5119 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5120 + if (!__builtin_constant_p(n)) \
5121 + check_object_size(__cu_to, __cu_len, false); \
5122 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5123 + } \
5124 __cu_len; \
5125 })
5126
5127 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5128 index 24603be..948052d 100644
5129 --- a/arch/ia64/kernel/module.c
5130 +++ b/arch/ia64/kernel/module.c
5131 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5132 void
5133 module_free (struct module *mod, void *module_region)
5134 {
5135 - if (mod && mod->arch.init_unw_table &&
5136 - module_region == mod->module_init) {
5137 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5138 unw_remove_unwind_table(mod->arch.init_unw_table);
5139 mod->arch.init_unw_table = NULL;
5140 }
5141 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5142 }
5143
5144 static inline int
5145 +in_init_rx (const struct module *mod, uint64_t addr)
5146 +{
5147 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5148 +}
5149 +
5150 +static inline int
5151 +in_init_rw (const struct module *mod, uint64_t addr)
5152 +{
5153 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5154 +}
5155 +
5156 +static inline int
5157 in_init (const struct module *mod, uint64_t addr)
5158 {
5159 - return addr - (uint64_t) mod->module_init < mod->init_size;
5160 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5161 +}
5162 +
5163 +static inline int
5164 +in_core_rx (const struct module *mod, uint64_t addr)
5165 +{
5166 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5167 +}
5168 +
5169 +static inline int
5170 +in_core_rw (const struct module *mod, uint64_t addr)
5171 +{
5172 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5173 }
5174
5175 static inline int
5176 in_core (const struct module *mod, uint64_t addr)
5177 {
5178 - return addr - (uint64_t) mod->module_core < mod->core_size;
5179 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5180 }
5181
5182 static inline int
5183 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5184 break;
5185
5186 case RV_BDREL:
5187 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5188 + if (in_init_rx(mod, val))
5189 + val -= (uint64_t) mod->module_init_rx;
5190 + else if (in_init_rw(mod, val))
5191 + val -= (uint64_t) mod->module_init_rw;
5192 + else if (in_core_rx(mod, val))
5193 + val -= (uint64_t) mod->module_core_rx;
5194 + else if (in_core_rw(mod, val))
5195 + val -= (uint64_t) mod->module_core_rw;
5196 break;
5197
5198 case RV_LTV:
5199 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5200 * addresses have been selected...
5201 */
5202 uint64_t gp;
5203 - if (mod->core_size > MAX_LTOFF)
5204 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5205 /*
5206 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5207 * at the end of the module.
5208 */
5209 - gp = mod->core_size - MAX_LTOFF / 2;
5210 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5211 else
5212 - gp = mod->core_size / 2;
5213 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5214 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5215 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5216 mod->arch.gp = gp;
5217 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5218 }
5219 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5220 index ab33328..f39506c 100644
5221 --- a/arch/ia64/kernel/palinfo.c
5222 +++ b/arch/ia64/kernel/palinfo.c
5223 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5224 return NOTIFY_OK;
5225 }
5226
5227 -static struct notifier_block __refdata palinfo_cpu_notifier =
5228 +static struct notifier_block palinfo_cpu_notifier =
5229 {
5230 .notifier_call = palinfo_cpu_callback,
5231 .priority = 0,
5232 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5233 index 41e33f8..65180b2a 100644
5234 --- a/arch/ia64/kernel/sys_ia64.c
5235 +++ b/arch/ia64/kernel/sys_ia64.c
5236 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5237 unsigned long align_mask = 0;
5238 struct mm_struct *mm = current->mm;
5239 struct vm_unmapped_area_info info;
5240 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5241
5242 if (len > RGN_MAP_LIMIT)
5243 return -ENOMEM;
5244 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5245 if (REGION_NUMBER(addr) == RGN_HPAGE)
5246 addr = 0;
5247 #endif
5248 +
5249 +#ifdef CONFIG_PAX_RANDMMAP
5250 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5251 + addr = mm->free_area_cache;
5252 + else
5253 +#endif
5254 +
5255 if (!addr)
5256 addr = TASK_UNMAPPED_BASE;
5257
5258 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5259 info.high_limit = TASK_SIZE;
5260 info.align_mask = align_mask;
5261 info.align_offset = 0;
5262 + info.threadstack_offset = offset;
5263 return vm_unmapped_area(&info);
5264 }
5265
5266 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5267 index 0ccb28f..8992469 100644
5268 --- a/arch/ia64/kernel/vmlinux.lds.S
5269 +++ b/arch/ia64/kernel/vmlinux.lds.S
5270 @@ -198,7 +198,7 @@ SECTIONS {
5271 /* Per-cpu data: */
5272 . = ALIGN(PERCPU_PAGE_SIZE);
5273 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5274 - __phys_per_cpu_start = __per_cpu_load;
5275 + __phys_per_cpu_start = per_cpu_load;
5276 /*
5277 * ensure percpu data fits
5278 * into percpu page size
5279 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5280 index 7225dad..2a7c8256 100644
5281 --- a/arch/ia64/mm/fault.c
5282 +++ b/arch/ia64/mm/fault.c
5283 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5284 return pte_present(pte);
5285 }
5286
5287 +#ifdef CONFIG_PAX_PAGEEXEC
5288 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5289 +{
5290 + unsigned long i;
5291 +
5292 + printk(KERN_ERR "PAX: bytes at PC: ");
5293 + for (i = 0; i < 8; i++) {
5294 + unsigned int c;
5295 + if (get_user(c, (unsigned int *)pc+i))
5296 + printk(KERN_CONT "???????? ");
5297 + else
5298 + printk(KERN_CONT "%08x ", c);
5299 + }
5300 + printk("\n");
5301 +}
5302 +#endif
5303 +
5304 # define VM_READ_BIT 0
5305 # define VM_WRITE_BIT 1
5306 # define VM_EXEC_BIT 2
5307 @@ -151,8 +168,21 @@ retry:
5308 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5309 goto bad_area;
5310
5311 - if ((vma->vm_flags & mask) != mask)
5312 + if ((vma->vm_flags & mask) != mask) {
5313 +
5314 +#ifdef CONFIG_PAX_PAGEEXEC
5315 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5316 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5317 + goto bad_area;
5318 +
5319 + up_read(&mm->mmap_sem);
5320 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5321 + do_group_exit(SIGKILL);
5322 + }
5323 +#endif
5324 +
5325 goto bad_area;
5326 + }
5327
5328 /*
5329 * If for any reason at all we couldn't handle the fault, make
5330 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5331 index 68232db..6ca80af 100644
5332 --- a/arch/ia64/mm/hugetlbpage.c
5333 +++ b/arch/ia64/mm/hugetlbpage.c
5334 @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5335 unsigned long pgoff, unsigned long flags)
5336 {
5337 struct vm_unmapped_area_info info;
5338 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5339
5340 if (len > RGN_MAP_LIMIT)
5341 return -ENOMEM;
5342 @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5343 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5344 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5345 info.align_offset = 0;
5346 + info.threadstack_offset = offset;
5347 return vm_unmapped_area(&info);
5348 }
5349
5350 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5351 index 88504ab..cbb6c9f 100644
5352 --- a/arch/ia64/mm/init.c
5353 +++ b/arch/ia64/mm/init.c
5354 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5355 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5356 vma->vm_end = vma->vm_start + PAGE_SIZE;
5357 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5358 +
5359 +#ifdef CONFIG_PAX_PAGEEXEC
5360 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5361 + vma->vm_flags &= ~VM_EXEC;
5362 +
5363 +#ifdef CONFIG_PAX_MPROTECT
5364 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5365 + vma->vm_flags &= ~VM_MAYEXEC;
5366 +#endif
5367 +
5368 + }
5369 +#endif
5370 +
5371 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5372 down_write(&current->mm->mmap_sem);
5373 if (insert_vm_struct(current->mm, vma)) {
5374 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5375 index 40b3ee9..8c2c112 100644
5376 --- a/arch/m32r/include/asm/cache.h
5377 +++ b/arch/m32r/include/asm/cache.h
5378 @@ -1,8 +1,10 @@
5379 #ifndef _ASM_M32R_CACHE_H
5380 #define _ASM_M32R_CACHE_H
5381
5382 +#include <linux/const.h>
5383 +
5384 /* L1 cache line size */
5385 #define L1_CACHE_SHIFT 4
5386 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5387 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5388
5389 #endif /* _ASM_M32R_CACHE_H */
5390 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5391 index 82abd15..d95ae5d 100644
5392 --- a/arch/m32r/lib/usercopy.c
5393 +++ b/arch/m32r/lib/usercopy.c
5394 @@ -14,6 +14,9 @@
5395 unsigned long
5396 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5397 {
5398 + if ((long)n < 0)
5399 + return n;
5400 +
5401 prefetch(from);
5402 if (access_ok(VERIFY_WRITE, to, n))
5403 __copy_user(to,from,n);
5404 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5405 unsigned long
5406 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5407 {
5408 + if ((long)n < 0)
5409 + return n;
5410 +
5411 prefetchw(to);
5412 if (access_ok(VERIFY_READ, from, n))
5413 __copy_user_zeroing(to,from,n);
5414 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5415 index 0395c51..5f26031 100644
5416 --- a/arch/m68k/include/asm/cache.h
5417 +++ b/arch/m68k/include/asm/cache.h
5418 @@ -4,9 +4,11 @@
5419 #ifndef __ARCH_M68K_CACHE_H
5420 #define __ARCH_M68K_CACHE_H
5421
5422 +#include <linux/const.h>
5423 +
5424 /* bytes per L1 cache line */
5425 #define L1_CACHE_SHIFT 4
5426 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5427 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5428
5429 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5430
5431 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5432 index 0424315..defcca9 100644
5433 --- a/arch/metag/mm/hugetlbpage.c
5434 +++ b/arch/metag/mm/hugetlbpage.c
5435 @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5436 info.high_limit = TASK_SIZE;
5437 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5438 info.align_offset = 0;
5439 + info.threadstack_offset = 0;
5440 return vm_unmapped_area(&info);
5441 }
5442
5443 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5444 index 4efe96a..60e8699 100644
5445 --- a/arch/microblaze/include/asm/cache.h
5446 +++ b/arch/microblaze/include/asm/cache.h
5447 @@ -13,11 +13,12 @@
5448 #ifndef _ASM_MICROBLAZE_CACHE_H
5449 #define _ASM_MICROBLAZE_CACHE_H
5450
5451 +#include <linux/const.h>
5452 #include <asm/registers.h>
5453
5454 #define L1_CACHE_SHIFT 5
5455 /* word-granular cache in microblaze */
5456 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5457 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5458
5459 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5460
5461 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5462 index 650de39..6982b02 100644
5463 --- a/arch/mips/Kconfig
5464 +++ b/arch/mips/Kconfig
5465 @@ -2268,6 +2268,7 @@ source "kernel/Kconfig.preempt"
5466
5467 config KEXEC
5468 bool "Kexec system call"
5469 + depends on !GRKERNSEC_KMEM
5470 help
5471 kexec is a system call that implements the ability to shutdown your
5472 current kernel, and to start another kernel. It is like a reboot
5473 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5474 index 02f2444..506969c 100644
5475 --- a/arch/mips/cavium-octeon/dma-octeon.c
5476 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5477 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5478 if (dma_release_from_coherent(dev, order, vaddr))
5479 return;
5480
5481 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5482 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5483 }
5484
5485 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5486 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5487 index 7eed2f2..c4e385d 100644
5488 --- a/arch/mips/include/asm/atomic.h
5489 +++ b/arch/mips/include/asm/atomic.h
5490 @@ -21,15 +21,39 @@
5491 #include <asm/cmpxchg.h>
5492 #include <asm/war.h>
5493
5494 +#ifdef CONFIG_GENERIC_ATOMIC64
5495 +#include <asm-generic/atomic64.h>
5496 +#endif
5497 +
5498 #define ATOMIC_INIT(i) { (i) }
5499
5500 +#ifdef CONFIG_64BIT
5501 +#define _ASM_EXTABLE(from, to) \
5502 +" .section __ex_table,\"a\"\n" \
5503 +" .dword " #from ", " #to"\n" \
5504 +" .previous\n"
5505 +#else
5506 +#define _ASM_EXTABLE(from, to) \
5507 +" .section __ex_table,\"a\"\n" \
5508 +" .word " #from ", " #to"\n" \
5509 +" .previous\n"
5510 +#endif
5511 +
5512 /*
5513 * atomic_read - read atomic variable
5514 * @v: pointer of type atomic_t
5515 *
5516 * Atomically reads the value of @v.
5517 */
5518 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5519 +static inline int atomic_read(const atomic_t *v)
5520 +{
5521 + return (*(volatile const int *) &v->counter);
5522 +}
5523 +
5524 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5525 +{
5526 + return (*(volatile const int *) &v->counter);
5527 +}
5528
5529 /*
5530 * atomic_set - set atomic variable
5531 @@ -38,7 +62,15 @@
5532 *
5533 * Atomically sets the value of @v to @i.
5534 */
5535 -#define atomic_set(v, i) ((v)->counter = (i))
5536 +static inline void atomic_set(atomic_t *v, int i)
5537 +{
5538 + v->counter = i;
5539 +}
5540 +
5541 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5542 +{
5543 + v->counter = i;
5544 +}
5545
5546 /*
5547 * atomic_add - add integer to atomic variable
5548 @@ -47,7 +79,67 @@
5549 *
5550 * Atomically adds @i to @v.
5551 */
5552 -static __inline__ void atomic_add(int i, atomic_t * v)
5553 +static __inline__ void atomic_add(int i, atomic_t *v)
5554 +{
5555 + int temp;
5556 +
5557 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5558 + __asm__ __volatile__(
5559 + " .set mips3 \n"
5560 + "1: ll %0, %1 # atomic_add \n"
5561 +#ifdef CONFIG_PAX_REFCOUNT
5562 + /* Exception on overflow. */
5563 + "2: add %0, %2 \n"
5564 +#else
5565 + " addu %0, %2 \n"
5566 +#endif
5567 + " sc %0, %1 \n"
5568 + " beqzl %0, 1b \n"
5569 +#ifdef CONFIG_PAX_REFCOUNT
5570 + "3: \n"
5571 + _ASM_EXTABLE(2b, 3b)
5572 +#endif
5573 + " .set mips0 \n"
5574 + : "=&r" (temp), "+m" (v->counter)
5575 + : "Ir" (i));
5576 + } else if (kernel_uses_llsc) {
5577 + __asm__ __volatile__(
5578 + " .set mips3 \n"
5579 + "1: ll %0, %1 # atomic_add \n"
5580 +#ifdef CONFIG_PAX_REFCOUNT
5581 + /* Exception on overflow. */
5582 + "2: add %0, %2 \n"
5583 +#else
5584 + " addu %0, %2 \n"
5585 +#endif
5586 + " sc %0, %1 \n"
5587 + " beqz %0, 1b \n"
5588 +#ifdef CONFIG_PAX_REFCOUNT
5589 + "3: \n"
5590 + _ASM_EXTABLE(2b, 3b)
5591 +#endif
5592 + " .set mips0 \n"
5593 + : "=&r" (temp), "+m" (v->counter)
5594 + : "Ir" (i));
5595 + } else {
5596 + unsigned long flags;
5597 +
5598 + raw_local_irq_save(flags);
5599 + __asm__ __volatile__(
5600 +#ifdef CONFIG_PAX_REFCOUNT
5601 + /* Exception on overflow. */
5602 + "1: add %0, %1 \n"
5603 + "2: \n"
5604 + _ASM_EXTABLE(1b, 2b)
5605 +#else
5606 + " addu %0, %1 \n"
5607 +#endif
5608 + : "+r" (v->counter) : "Ir" (i));
5609 + raw_local_irq_restore(flags);
5610 + }
5611 +}
5612 +
5613 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5614 {
5615 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5616 int temp;
5617 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5618 *
5619 * Atomically subtracts @i from @v.
5620 */
5621 -static __inline__ void atomic_sub(int i, atomic_t * v)
5622 +static __inline__ void atomic_sub(int i, atomic_t *v)
5623 +{
5624 + int temp;
5625 +
5626 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5627 + __asm__ __volatile__(
5628 + " .set mips3 \n"
5629 + "1: ll %0, %1 # atomic64_sub \n"
5630 +#ifdef CONFIG_PAX_REFCOUNT
5631 + /* Exception on overflow. */
5632 + "2: sub %0, %2 \n"
5633 +#else
5634 + " subu %0, %2 \n"
5635 +#endif
5636 + " sc %0, %1 \n"
5637 + " beqzl %0, 1b \n"
5638 +#ifdef CONFIG_PAX_REFCOUNT
5639 + "3: \n"
5640 + _ASM_EXTABLE(2b, 3b)
5641 +#endif
5642 + " .set mips0 \n"
5643 + : "=&r" (temp), "+m" (v->counter)
5644 + : "Ir" (i));
5645 + } else if (kernel_uses_llsc) {
5646 + __asm__ __volatile__(
5647 + " .set mips3 \n"
5648 + "1: ll %0, %1 # atomic64_sub \n"
5649 +#ifdef CONFIG_PAX_REFCOUNT
5650 + /* Exception on overflow. */
5651 + "2: sub %0, %2 \n"
5652 +#else
5653 + " subu %0, %2 \n"
5654 +#endif
5655 + " sc %0, %1 \n"
5656 + " beqz %0, 1b \n"
5657 +#ifdef CONFIG_PAX_REFCOUNT
5658 + "3: \n"
5659 + _ASM_EXTABLE(2b, 3b)
5660 +#endif
5661 + " .set mips0 \n"
5662 + : "=&r" (temp), "+m" (v->counter)
5663 + : "Ir" (i));
5664 + } else {
5665 + unsigned long flags;
5666 +
5667 + raw_local_irq_save(flags);
5668 + __asm__ __volatile__(
5669 +#ifdef CONFIG_PAX_REFCOUNT
5670 + /* Exception on overflow. */
5671 + "1: sub %0, %1 \n"
5672 + "2: \n"
5673 + _ASM_EXTABLE(1b, 2b)
5674 +#else
5675 + " subu %0, %1 \n"
5676 +#endif
5677 + : "+r" (v->counter) : "Ir" (i));
5678 + raw_local_irq_restore(flags);
5679 + }
5680 +}
5681 +
5682 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5683 {
5684 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5685 int temp;
5686 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5687 /*
5688 * Same as above, but return the result value
5689 */
5690 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5691 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5692 +{
5693 + int result;
5694 + int temp;
5695 +
5696 + smp_mb__before_llsc();
5697 +
5698 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5699 + __asm__ __volatile__(
5700 + " .set mips3 \n"
5701 + "1: ll %1, %2 # atomic_add_return \n"
5702 +#ifdef CONFIG_PAX_REFCOUNT
5703 + "2: add %0, %1, %3 \n"
5704 +#else
5705 + " addu %0, %1, %3 \n"
5706 +#endif
5707 + " sc %0, %2 \n"
5708 + " beqzl %0, 1b \n"
5709 +#ifdef CONFIG_PAX_REFCOUNT
5710 + " b 4f \n"
5711 + " .set noreorder \n"
5712 + "3: b 5f \n"
5713 + " move %0, %1 \n"
5714 + " .set reorder \n"
5715 + _ASM_EXTABLE(2b, 3b)
5716 +#endif
5717 + "4: addu %0, %1, %3 \n"
5718 +#ifdef CONFIG_PAX_REFCOUNT
5719 + "5: \n"
5720 +#endif
5721 + " .set mips0 \n"
5722 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5723 + : "Ir" (i));
5724 + } else if (kernel_uses_llsc) {
5725 + __asm__ __volatile__(
5726 + " .set mips3 \n"
5727 + "1: ll %1, %2 # atomic_add_return \n"
5728 +#ifdef CONFIG_PAX_REFCOUNT
5729 + "2: add %0, %1, %3 \n"
5730 +#else
5731 + " addu %0, %1, %3 \n"
5732 +#endif
5733 + " sc %0, %2 \n"
5734 + " bnez %0, 4f \n"
5735 + " b 1b \n"
5736 +#ifdef CONFIG_PAX_REFCOUNT
5737 + " .set noreorder \n"
5738 + "3: b 5f \n"
5739 + " move %0, %1 \n"
5740 + " .set reorder \n"
5741 + _ASM_EXTABLE(2b, 3b)
5742 +#endif
5743 + "4: addu %0, %1, %3 \n"
5744 +#ifdef CONFIG_PAX_REFCOUNT
5745 + "5: \n"
5746 +#endif
5747 + " .set mips0 \n"
5748 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5749 + : "Ir" (i));
5750 + } else {
5751 + unsigned long flags;
5752 +
5753 + raw_local_irq_save(flags);
5754 + __asm__ __volatile__(
5755 + " lw %0, %1 \n"
5756 +#ifdef CONFIG_PAX_REFCOUNT
5757 + /* Exception on overflow. */
5758 + "1: add %0, %2 \n"
5759 +#else
5760 + " addu %0, %2 \n"
5761 +#endif
5762 + " sw %0, %1 \n"
5763 +#ifdef CONFIG_PAX_REFCOUNT
5764 + /* Note: Dest reg is not modified on overflow */
5765 + "2: \n"
5766 + _ASM_EXTABLE(1b, 2b)
5767 +#endif
5768 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5769 + raw_local_irq_restore(flags);
5770 + }
5771 +
5772 + smp_llsc_mb();
5773 +
5774 + return result;
5775 +}
5776 +
5777 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5778 {
5779 int result;
5780
5781 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5782 return result;
5783 }
5784
5785 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5786 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5787 +{
5788 + int result;
5789 + int temp;
5790 +
5791 + smp_mb__before_llsc();
5792 +
5793 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5794 + __asm__ __volatile__(
5795 + " .set mips3 \n"
5796 + "1: ll %1, %2 # atomic_sub_return \n"
5797 +#ifdef CONFIG_PAX_REFCOUNT
5798 + "2: sub %0, %1, %3 \n"
5799 +#else
5800 + " subu %0, %1, %3 \n"
5801 +#endif
5802 + " sc %0, %2 \n"
5803 + " beqzl %0, 1b \n"
5804 +#ifdef CONFIG_PAX_REFCOUNT
5805 + " b 4f \n"
5806 + " .set noreorder \n"
5807 + "3: b 5f \n"
5808 + " move %0, %1 \n"
5809 + " .set reorder \n"
5810 + _ASM_EXTABLE(2b, 3b)
5811 +#endif
5812 + "4: subu %0, %1, %3 \n"
5813 +#ifdef CONFIG_PAX_REFCOUNT
5814 + "5: \n"
5815 +#endif
5816 + " .set mips0 \n"
5817 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5818 + : "Ir" (i), "m" (v->counter)
5819 + : "memory");
5820 + } else if (kernel_uses_llsc) {
5821 + __asm__ __volatile__(
5822 + " .set mips3 \n"
5823 + "1: ll %1, %2 # atomic_sub_return \n"
5824 +#ifdef CONFIG_PAX_REFCOUNT
5825 + "2: sub %0, %1, %3 \n"
5826 +#else
5827 + " subu %0, %1, %3 \n"
5828 +#endif
5829 + " sc %0, %2 \n"
5830 + " bnez %0, 4f \n"
5831 + " b 1b \n"
5832 +#ifdef CONFIG_PAX_REFCOUNT
5833 + " .set noreorder \n"
5834 + "3: b 5f \n"
5835 + " move %0, %1 \n"
5836 + " .set reorder \n"
5837 + _ASM_EXTABLE(2b, 3b)
5838 +#endif
5839 + "4: subu %0, %1, %3 \n"
5840 +#ifdef CONFIG_PAX_REFCOUNT
5841 + "5: \n"
5842 +#endif
5843 + " .set mips0 \n"
5844 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5845 + : "Ir" (i));
5846 + } else {
5847 + unsigned long flags;
5848 +
5849 + raw_local_irq_save(flags);
5850 + __asm__ __volatile__(
5851 + " lw %0, %1 \n"
5852 +#ifdef CONFIG_PAX_REFCOUNT
5853 + /* Exception on overflow. */
5854 + "1: sub %0, %2 \n"
5855 +#else
5856 + " subu %0, %2 \n"
5857 +#endif
5858 + " sw %0, %1 \n"
5859 +#ifdef CONFIG_PAX_REFCOUNT
5860 + /* Note: Dest reg is not modified on overflow */
5861 + "2: \n"
5862 + _ASM_EXTABLE(1b, 2b)
5863 +#endif
5864 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5865 + raw_local_irq_restore(flags);
5866 + }
5867 +
5868 + smp_llsc_mb();
5869 +
5870 + return result;
5871 +}
5872 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5873 {
5874 int result;
5875
5876 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5877 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5878 * The function returns the old value of @v minus @i.
5879 */
5880 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5881 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5882 {
5883 int result;
5884
5885 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5886 return result;
5887 }
5888
5889 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5890 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5891 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5892 +{
5893 + return cmpxchg(&v->counter, old, new);
5894 +}
5895 +
5896 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5897 + int new)
5898 +{
5899 + return cmpxchg(&(v->counter), old, new);
5900 +}
5901 +
5902 +static inline int atomic_xchg(atomic_t *v, int new)
5903 +{
5904 + return xchg(&v->counter, new);
5905 +}
5906 +
5907 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5908 +{
5909 + return xchg(&(v->counter), new);
5910 +}
5911
5912 /**
5913 * __atomic_add_unless - add unless the number is a given value
5914 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5915
5916 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5917 #define atomic_inc_return(v) atomic_add_return(1, (v))
5918 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5919 +{
5920 + return atomic_add_return_unchecked(1, v);
5921 +}
5922
5923 /*
5924 * atomic_sub_and_test - subtract value from variable and test result
5925 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5926 * other cases.
5927 */
5928 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5929 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5930 +{
5931 + return atomic_add_return_unchecked(1, v) == 0;
5932 +}
5933
5934 /*
5935 * atomic_dec_and_test - decrement by 1 and test
5936 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5937 * Atomically increments @v by 1.
5938 */
5939 #define atomic_inc(v) atomic_add(1, (v))
5940 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5941 +{
5942 + atomic_add_unchecked(1, v);
5943 +}
5944
5945 /*
5946 * atomic_dec - decrement and test
5947 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5948 * Atomically decrements @v by 1.
5949 */
5950 #define atomic_dec(v) atomic_sub(1, (v))
5951 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5952 +{
5953 + atomic_sub_unchecked(1, v);
5954 +}
5955
5956 /*
5957 * atomic_add_negative - add and test if negative
5958 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5959 * @v: pointer of type atomic64_t
5960 *
5961 */
5962 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5963 +static inline long atomic64_read(const atomic64_t *v)
5964 +{
5965 + return (*(volatile const long *) &v->counter);
5966 +}
5967 +
5968 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5969 +{
5970 + return (*(volatile const long *) &v->counter);
5971 +}
5972
5973 /*
5974 * atomic64_set - set atomic variable
5975 * @v: pointer of type atomic64_t
5976 * @i: required value
5977 */
5978 -#define atomic64_set(v, i) ((v)->counter = (i))
5979 +static inline void atomic64_set(atomic64_t *v, long i)
5980 +{
5981 + v->counter = i;
5982 +}
5983 +
5984 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5985 +{
5986 + v->counter = i;
5987 +}
5988
5989 /*
5990 * atomic64_add - add integer to atomic variable
5991 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5992 *
5993 * Atomically adds @i to @v.
5994 */
5995 -static __inline__ void atomic64_add(long i, atomic64_t * v)
5996 +static __inline__ void atomic64_add(long i, atomic64_t *v)
5997 +{
5998 + long temp;
5999 +
6000 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6001 + __asm__ __volatile__(
6002 + " .set mips3 \n"
6003 + "1: lld %0, %1 # atomic64_add \n"
6004 +#ifdef CONFIG_PAX_REFCOUNT
6005 + /* Exception on overflow. */
6006 + "2: dadd %0, %2 \n"
6007 +#else
6008 + " daddu %0, %2 \n"
6009 +#endif
6010 + " scd %0, %1 \n"
6011 + " beqzl %0, 1b \n"
6012 +#ifdef CONFIG_PAX_REFCOUNT
6013 + "3: \n"
6014 + _ASM_EXTABLE(2b, 3b)
6015 +#endif
6016 + " .set mips0 \n"
6017 + : "=&r" (temp), "+m" (v->counter)
6018 + : "Ir" (i));
6019 + } else if (kernel_uses_llsc) {
6020 + __asm__ __volatile__(
6021 + " .set mips3 \n"
6022 + "1: lld %0, %1 # atomic64_add \n"
6023 +#ifdef CONFIG_PAX_REFCOUNT
6024 + /* Exception on overflow. */
6025 + "2: dadd %0, %2 \n"
6026 +#else
6027 + " daddu %0, %2 \n"
6028 +#endif
6029 + " scd %0, %1 \n"
6030 + " beqz %0, 1b \n"
6031 +#ifdef CONFIG_PAX_REFCOUNT
6032 + "3: \n"
6033 + _ASM_EXTABLE(2b, 3b)
6034 +#endif
6035 + " .set mips0 \n"
6036 + : "=&r" (temp), "+m" (v->counter)
6037 + : "Ir" (i));
6038 + } else {
6039 + unsigned long flags;
6040 +
6041 + raw_local_irq_save(flags);
6042 + __asm__ __volatile__(
6043 +#ifdef CONFIG_PAX_REFCOUNT
6044 + /* Exception on overflow. */
6045 + "1: dadd %0, %1 \n"
6046 + "2: \n"
6047 + _ASM_EXTABLE(1b, 2b)
6048 +#else
6049 + " daddu %0, %1 \n"
6050 +#endif
6051 + : "+r" (v->counter) : "Ir" (i));
6052 + raw_local_irq_restore(flags);
6053 + }
6054 +}
6055 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6056 {
6057 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6058 long temp;
6059 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6060 *
6061 * Atomically subtracts @i from @v.
6062 */
6063 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6064 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6065 +{
6066 + long temp;
6067 +
6068 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6069 + __asm__ __volatile__(
6070 + " .set mips3 \n"
6071 + "1: lld %0, %1 # atomic64_sub \n"
6072 +#ifdef CONFIG_PAX_REFCOUNT
6073 + /* Exception on overflow. */
6074 + "2: dsub %0, %2 \n"
6075 +#else
6076 + " dsubu %0, %2 \n"
6077 +#endif
6078 + " scd %0, %1 \n"
6079 + " beqzl %0, 1b \n"
6080 +#ifdef CONFIG_PAX_REFCOUNT
6081 + "3: \n"
6082 + _ASM_EXTABLE(2b, 3b)
6083 +#endif
6084 + " .set mips0 \n"
6085 + : "=&r" (temp), "+m" (v->counter)
6086 + : "Ir" (i));
6087 + } else if (kernel_uses_llsc) {
6088 + __asm__ __volatile__(
6089 + " .set mips3 \n"
6090 + "1: lld %0, %1 # atomic64_sub \n"
6091 +#ifdef CONFIG_PAX_REFCOUNT
6092 + /* Exception on overflow. */
6093 + "2: dsub %0, %2 \n"
6094 +#else
6095 + " dsubu %0, %2 \n"
6096 +#endif
6097 + " scd %0, %1 \n"
6098 + " beqz %0, 1b \n"
6099 +#ifdef CONFIG_PAX_REFCOUNT
6100 + "3: \n"
6101 + _ASM_EXTABLE(2b, 3b)
6102 +#endif
6103 + " .set mips0 \n"
6104 + : "=&r" (temp), "+m" (v->counter)
6105 + : "Ir" (i));
6106 + } else {
6107 + unsigned long flags;
6108 +
6109 + raw_local_irq_save(flags);
6110 + __asm__ __volatile__(
6111 +#ifdef CONFIG_PAX_REFCOUNT
6112 + /* Exception on overflow. */
6113 + "1: dsub %0, %1 \n"
6114 + "2: \n"
6115 + _ASM_EXTABLE(1b, 2b)
6116 +#else
6117 + " dsubu %0, %1 \n"
6118 +#endif
6119 + : "+r" (v->counter) : "Ir" (i));
6120 + raw_local_irq_restore(flags);
6121 + }
6122 +}
6123 +
6124 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6125 {
6126 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6127 long temp;
6128 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6129 /*
6130 * Same as above, but return the result value
6131 */
6132 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6133 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6134 +{
6135 + long result;
6136 + long temp;
6137 +
6138 + smp_mb__before_llsc();
6139 +
6140 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6141 + __asm__ __volatile__(
6142 + " .set mips3 \n"
6143 + "1: lld %1, %2 # atomic64_add_return \n"
6144 +#ifdef CONFIG_PAX_REFCOUNT
6145 + "2: dadd %0, %1, %3 \n"
6146 +#else
6147 + " daddu %0, %1, %3 \n"
6148 +#endif
6149 + " scd %0, %2 \n"
6150 + " beqzl %0, 1b \n"
6151 +#ifdef CONFIG_PAX_REFCOUNT
6152 + " b 4f \n"
6153 + " .set noreorder \n"
6154 + "3: b 5f \n"
6155 + " move %0, %1 \n"
6156 + " .set reorder \n"
6157 + _ASM_EXTABLE(2b, 3b)
6158 +#endif
6159 + "4: daddu %0, %1, %3 \n"
6160 +#ifdef CONFIG_PAX_REFCOUNT
6161 + "5: \n"
6162 +#endif
6163 + " .set mips0 \n"
6164 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6165 + : "Ir" (i));
6166 + } else if (kernel_uses_llsc) {
6167 + __asm__ __volatile__(
6168 + " .set mips3 \n"
6169 + "1: lld %1, %2 # atomic64_add_return \n"
6170 +#ifdef CONFIG_PAX_REFCOUNT
6171 + "2: dadd %0, %1, %3 \n"
6172 +#else
6173 + " daddu %0, %1, %3 \n"
6174 +#endif
6175 + " scd %0, %2 \n"
6176 + " bnez %0, 4f \n"
6177 + " b 1b \n"
6178 +#ifdef CONFIG_PAX_REFCOUNT
6179 + " .set noreorder \n"
6180 + "3: b 5f \n"
6181 + " move %0, %1 \n"
6182 + " .set reorder \n"
6183 + _ASM_EXTABLE(2b, 3b)
6184 +#endif
6185 + "4: daddu %0, %1, %3 \n"
6186 +#ifdef CONFIG_PAX_REFCOUNT
6187 + "5: \n"
6188 +#endif
6189 + " .set mips0 \n"
6190 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6191 + : "Ir" (i), "m" (v->counter)
6192 + : "memory");
6193 + } else {
6194 + unsigned long flags;
6195 +
6196 + raw_local_irq_save(flags);
6197 + __asm__ __volatile__(
6198 + " ld %0, %1 \n"
6199 +#ifdef CONFIG_PAX_REFCOUNT
6200 + /* Exception on overflow. */
6201 + "1: dadd %0, %2 \n"
6202 +#else
6203 + " daddu %0, %2 \n"
6204 +#endif
6205 + " sd %0, %1 \n"
6206 +#ifdef CONFIG_PAX_REFCOUNT
6207 + /* Note: Dest reg is not modified on overflow */
6208 + "2: \n"
6209 + _ASM_EXTABLE(1b, 2b)
6210 +#endif
6211 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6212 + raw_local_irq_restore(flags);
6213 + }
6214 +
6215 + smp_llsc_mb();
6216 +
6217 + return result;
6218 +}
6219 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6220 {
6221 long result;
6222
6223 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6224 return result;
6225 }
6226
6227 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6228 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6229 +{
6230 + long result;
6231 + long temp;
6232 +
6233 + smp_mb__before_llsc();
6234 +
6235 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6236 + long temp;
6237 +
6238 + __asm__ __volatile__(
6239 + " .set mips3 \n"
6240 + "1: lld %1, %2 # atomic64_sub_return \n"
6241 +#ifdef CONFIG_PAX_REFCOUNT
6242 + "2: dsub %0, %1, %3 \n"
6243 +#else
6244 + " dsubu %0, %1, %3 \n"
6245 +#endif
6246 + " scd %0, %2 \n"
6247 + " beqzl %0, 1b \n"
6248 +#ifdef CONFIG_PAX_REFCOUNT
6249 + " b 4f \n"
6250 + " .set noreorder \n"
6251 + "3: b 5f \n"
6252 + " move %0, %1 \n"
6253 + " .set reorder \n"
6254 + _ASM_EXTABLE(2b, 3b)
6255 +#endif
6256 + "4: dsubu %0, %1, %3 \n"
6257 +#ifdef CONFIG_PAX_REFCOUNT
6258 + "5: \n"
6259 +#endif
6260 + " .set mips0 \n"
6261 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6262 + : "Ir" (i), "m" (v->counter)
6263 + : "memory");
6264 + } else if (kernel_uses_llsc) {
6265 + __asm__ __volatile__(
6266 + " .set mips3 \n"
6267 + "1: lld %1, %2 # atomic64_sub_return \n"
6268 +#ifdef CONFIG_PAX_REFCOUNT
6269 + "2: dsub %0, %1, %3 \n"
6270 +#else
6271 + " dsubu %0, %1, %3 \n"
6272 +#endif
6273 + " scd %0, %2 \n"
6274 + " bnez %0, 4f \n"
6275 + " b 1b \n"
6276 +#ifdef CONFIG_PAX_REFCOUNT
6277 + " .set noreorder \n"
6278 + "3: b 5f \n"
6279 + " move %0, %1 \n"
6280 + " .set reorder \n"
6281 + _ASM_EXTABLE(2b, 3b)
6282 +#endif
6283 + "4: dsubu %0, %1, %3 \n"
6284 +#ifdef CONFIG_PAX_REFCOUNT
6285 + "5: \n"
6286 +#endif
6287 + " .set mips0 \n"
6288 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6289 + : "Ir" (i), "m" (v->counter)
6290 + : "memory");
6291 + } else {
6292 + unsigned long flags;
6293 +
6294 + raw_local_irq_save(flags);
6295 + __asm__ __volatile__(
6296 + " ld %0, %1 \n"
6297 +#ifdef CONFIG_PAX_REFCOUNT
6298 + /* Exception on overflow. */
6299 + "1: dsub %0, %2 \n"
6300 +#else
6301 + " dsubu %0, %2 \n"
6302 +#endif
6303 + " sd %0, %1 \n"
6304 +#ifdef CONFIG_PAX_REFCOUNT
6305 + /* Note: Dest reg is not modified on overflow */
6306 + "2: \n"
6307 + _ASM_EXTABLE(1b, 2b)
6308 +#endif
6309 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6310 + raw_local_irq_restore(flags);
6311 + }
6312 +
6313 + smp_llsc_mb();
6314 +
6315 + return result;
6316 +}
6317 +
6318 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6319 {
6320 long result;
6321
6322 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6323 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6324 * The function returns the old value of @v minus @i.
6325 */
6326 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6327 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6328 {
6329 long result;
6330
6331 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6332 return result;
6333 }
6334
6335 -#define atomic64_cmpxchg(v, o, n) \
6336 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6337 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6338 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6339 +{
6340 + return cmpxchg(&v->counter, old, new);
6341 +}
6342 +
6343 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6344 + long new)
6345 +{
6346 + return cmpxchg(&(v->counter), old, new);
6347 +}
6348 +
6349 +static inline long atomic64_xchg(atomic64_t *v, long new)
6350 +{
6351 + return xchg(&v->counter, new);
6352 +}
6353 +
6354 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6355 +{
6356 + return xchg(&(v->counter), new);
6357 +}
6358
6359 /**
6360 * atomic64_add_unless - add unless the number is a given value
6361 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6362
6363 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6364 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6365 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6366
6367 /*
6368 * atomic64_sub_and_test - subtract value from variable and test result
6369 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6370 * other cases.
6371 */
6372 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6373 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6374
6375 /*
6376 * atomic64_dec_and_test - decrement by 1 and test
6377 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6378 * Atomically increments @v by 1.
6379 */
6380 #define atomic64_inc(v) atomic64_add(1, (v))
6381 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6382
6383 /*
6384 * atomic64_dec - decrement and test
6385 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6386 * Atomically decrements @v by 1.
6387 */
6388 #define atomic64_dec(v) atomic64_sub(1, (v))
6389 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6390
6391 /*
6392 * atomic64_add_negative - add and test if negative
6393 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6394 index b4db69f..8f3b093 100644
6395 --- a/arch/mips/include/asm/cache.h
6396 +++ b/arch/mips/include/asm/cache.h
6397 @@ -9,10 +9,11 @@
6398 #ifndef _ASM_CACHE_H
6399 #define _ASM_CACHE_H
6400
6401 +#include <linux/const.h>
6402 #include <kmalloc.h>
6403
6404 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6405 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6406 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6407
6408 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6409 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6410 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6411 index a66359e..d3d474a 100644
6412 --- a/arch/mips/include/asm/elf.h
6413 +++ b/arch/mips/include/asm/elf.h
6414 @@ -373,13 +373,16 @@ extern const char *__elf_platform;
6415 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6416 #endif
6417
6418 +#ifdef CONFIG_PAX_ASLR
6419 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6420 +
6421 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6422 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6423 +#endif
6424 +
6425 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6426 struct linux_binprm;
6427 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6428 int uses_interp);
6429
6430 -struct mm_struct;
6431 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6432 -#define arch_randomize_brk arch_randomize_brk
6433 -
6434 #endif /* _ASM_ELF_H */
6435 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6436 index c1f6afa..38cc6e9 100644
6437 --- a/arch/mips/include/asm/exec.h
6438 +++ b/arch/mips/include/asm/exec.h
6439 @@ -12,6 +12,6 @@
6440 #ifndef _ASM_EXEC_H
6441 #define _ASM_EXEC_H
6442
6443 -extern unsigned long arch_align_stack(unsigned long sp);
6444 +#define arch_align_stack(x) ((x) & ~0xfUL)
6445
6446 #endif /* _ASM_EXEC_H */
6447 diff --git a/arch/mips/include/asm/ftrace.h b/arch/mips/include/asm/ftrace.h
6448 index ce35c9a..434321c 100644
6449 --- a/arch/mips/include/asm/ftrace.h
6450 +++ b/arch/mips/include/asm/ftrace.h
6451 @@ -22,12 +22,12 @@ extern void _mcount(void);
6452 #define safe_load(load, src, dst, error) \
6453 do { \
6454 asm volatile ( \
6455 - "1: " load " %[" STR(dst) "], 0(%[" STR(src) "])\n"\
6456 - " li %[" STR(error) "], 0\n" \
6457 + "1: " load " %[dest], 0(%[source])\n" \
6458 + " li %[err], 0\n" \
6459 "2:\n" \
6460 \
6461 ".section .fixup, \"ax\"\n" \
6462 - "3: li %[" STR(error) "], 1\n" \
6463 + "3: li %[err], 1\n" \
6464 " j 2b\n" \
6465 ".previous\n" \
6466 \
6467 @@ -35,8 +35,8 @@ do { \
6468 STR(PTR) "\t1b, 3b\n\t" \
6469 ".previous\n" \
6470 \
6471 - : [dst] "=&r" (dst), [error] "=r" (error)\
6472 - : [src] "r" (src) \
6473 + : [dest] "=&r" (dst), [err] "=r" (error)\
6474 + : [source] "r" (src) \
6475 : "memory" \
6476 ); \
6477 } while (0)
6478 @@ -44,12 +44,12 @@ do { \
6479 #define safe_store(store, src, dst, error) \
6480 do { \
6481 asm volatile ( \
6482 - "1: " store " %[" STR(src) "], 0(%[" STR(dst) "])\n"\
6483 - " li %[" STR(error) "], 0\n" \
6484 + "1: " store " %[source], 0(%[dest])\n"\
6485 + " li %[err], 0\n" \
6486 "2:\n" \
6487 \
6488 ".section .fixup, \"ax\"\n" \
6489 - "3: li %[" STR(error) "], 1\n" \
6490 + "3: li %[err], 1\n" \
6491 " j 2b\n" \
6492 ".previous\n" \
6493 \
6494 @@ -57,8 +57,8 @@ do { \
6495 STR(PTR) "\t1b, 3b\n\t" \
6496 ".previous\n" \
6497 \
6498 - : [error] "=r" (error) \
6499 - : [dst] "r" (dst), [src] "r" (src)\
6500 + : [err] "=r" (error) \
6501 + : [dest] "r" (dst), [source] "r" (src)\
6502 : "memory" \
6503 ); \
6504 } while (0)
6505 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6506 index 9e8ef59..1139d6b 100644
6507 --- a/arch/mips/include/asm/hw_irq.h
6508 +++ b/arch/mips/include/asm/hw_irq.h
6509 @@ -10,7 +10,7 @@
6510
6511 #include <linux/atomic.h>
6512
6513 -extern atomic_t irq_err_count;
6514 +extern atomic_unchecked_t irq_err_count;
6515
6516 /*
6517 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6518 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6519 index d44622c..64990d2 100644
6520 --- a/arch/mips/include/asm/local.h
6521 +++ b/arch/mips/include/asm/local.h
6522 @@ -12,15 +12,25 @@ typedef struct
6523 atomic_long_t a;
6524 } local_t;
6525
6526 +typedef struct {
6527 + atomic_long_unchecked_t a;
6528 +} local_unchecked_t;
6529 +
6530 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6531
6532 #define local_read(l) atomic_long_read(&(l)->a)
6533 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6534 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6535 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6536
6537 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6538 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6539 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6540 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6541 #define local_inc(l) atomic_long_inc(&(l)->a)
6542 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6543 #define local_dec(l) atomic_long_dec(&(l)->a)
6544 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6545
6546 /*
6547 * Same as above, but return the result value
6548 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6549 return result;
6550 }
6551
6552 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6553 +{
6554 + unsigned long result;
6555 +
6556 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6557 + unsigned long temp;
6558 +
6559 + __asm__ __volatile__(
6560 + " .set mips3 \n"
6561 + "1:" __LL "%1, %2 # local_add_return \n"
6562 + " addu %0, %1, %3 \n"
6563 + __SC "%0, %2 \n"
6564 + " beqzl %0, 1b \n"
6565 + " addu %0, %1, %3 \n"
6566 + " .set mips0 \n"
6567 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6568 + : "Ir" (i), "m" (l->a.counter)
6569 + : "memory");
6570 + } else if (kernel_uses_llsc) {
6571 + unsigned long temp;
6572 +
6573 + __asm__ __volatile__(
6574 + " .set mips3 \n"
6575 + "1:" __LL "%1, %2 # local_add_return \n"
6576 + " addu %0, %1, %3 \n"
6577 + __SC "%0, %2 \n"
6578 + " beqz %0, 1b \n"
6579 + " addu %0, %1, %3 \n"
6580 + " .set mips0 \n"
6581 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6582 + : "Ir" (i), "m" (l->a.counter)
6583 + : "memory");
6584 + } else {
6585 + unsigned long flags;
6586 +
6587 + local_irq_save(flags);
6588 + result = l->a.counter;
6589 + result += i;
6590 + l->a.counter = result;
6591 + local_irq_restore(flags);
6592 + }
6593 +
6594 + return result;
6595 +}
6596 +
6597 static __inline__ long local_sub_return(long i, local_t * l)
6598 {
6599 unsigned long result;
6600 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6601
6602 #define local_cmpxchg(l, o, n) \
6603 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6604 +#define local_cmpxchg_unchecked(l, o, n) \
6605 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6606 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6607
6608 /**
6609 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6610 index f6be474..12ad554 100644
6611 --- a/arch/mips/include/asm/page.h
6612 +++ b/arch/mips/include/asm/page.h
6613 @@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6614 #ifdef CONFIG_CPU_MIPS32
6615 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6616 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6617 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6618 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6619 #else
6620 typedef struct { unsigned long long pte; } pte_t;
6621 #define pte_val(x) ((x).pte)
6622 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6623 index b336037..5b874cc 100644
6624 --- a/arch/mips/include/asm/pgalloc.h
6625 +++ b/arch/mips/include/asm/pgalloc.h
6626 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6627 {
6628 set_pud(pud, __pud((unsigned long)pmd));
6629 }
6630 +
6631 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6632 +{
6633 + pud_populate(mm, pud, pmd);
6634 +}
6635 #endif
6636
6637 /*
6638 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6639 index 008324d..f67c239 100644
6640 --- a/arch/mips/include/asm/pgtable.h
6641 +++ b/arch/mips/include/asm/pgtable.h
6642 @@ -20,6 +20,9 @@
6643 #include <asm/io.h>
6644 #include <asm/pgtable-bits.h>
6645
6646 +#define ktla_ktva(addr) (addr)
6647 +#define ktva_ktla(addr) (addr)
6648 +
6649 struct mm_struct;
6650 struct vm_area_struct;
6651
6652 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6653 index 25da651..ae2a259 100644
6654 --- a/arch/mips/include/asm/smtc_proc.h
6655 +++ b/arch/mips/include/asm/smtc_proc.h
6656 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6657
6658 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6659
6660 -extern atomic_t smtc_fpu_recoveries;
6661 +extern atomic_unchecked_t smtc_fpu_recoveries;
6662
6663 #endif /* __ASM_SMTC_PROC_H */
6664 diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h
6665 index 33e8dbf..81d8432 100644
6666 --- a/arch/mips/include/asm/syscall.h
6667 +++ b/arch/mips/include/asm/syscall.h
6668 @@ -39,14 +39,14 @@ static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
6669
6670 #ifdef CONFIG_32BIT
6671 case 4: case 5: case 6: case 7:
6672 - return get_user(*arg, (int *)usp + 4 * n);
6673 + return get_user(*arg, (int *)usp + n);
6674 #endif
6675
6676 #ifdef CONFIG_64BIT
6677 case 4: case 5: case 6: case 7:
6678 #ifdef CONFIG_MIPS32_O32
6679 if (test_thread_flag(TIF_32BIT_REGS))
6680 - return get_user(*arg, (int *)usp + 4 * n);
6681 + return get_user(*arg, (int *)usp + n);
6682 else
6683 #endif
6684 *arg = regs->regs[4 + n];
6685 @@ -83,11 +83,10 @@ static inline void syscall_get_arguments(struct task_struct *task,
6686 unsigned int i, unsigned int n,
6687 unsigned long *args)
6688 {
6689 - unsigned long arg;
6690 int ret;
6691
6692 while (n--)
6693 - ret |= mips_get_syscall_arg(&arg, task, regs, i++);
6694 + ret |= mips_get_syscall_arg(args++, task, regs, i++);
6695
6696 /*
6697 * No way to communicate an error because this is a void function.
6698 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6699 index 4f58ef6..5e7081b 100644
6700 --- a/arch/mips/include/asm/thread_info.h
6701 +++ b/arch/mips/include/asm/thread_info.h
6702 @@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6703 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6704 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6705 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6706 +/* li takes a 32bit immediate */
6707 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6708 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6709
6710 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6711 @@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6712 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6713 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6714 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6715 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6716
6717 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6718 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6719 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6720
6721 /* work to do in syscall_trace_leave() */
6722 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6723 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6724 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6725
6726 /* work to do on interrupt/exception return */
6727 #define _TIF_WORK_MASK \
6728 @@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6729 /* work to do on any return to u-space */
6730 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6731 _TIF_WORK_SYSCALL_EXIT | \
6732 - _TIF_SYSCALL_TRACEPOINT)
6733 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6734
6735 /*
6736 * We stash processor id into a COP0 register to retrieve it fast
6737 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6738 index f3fa375..3af6637 100644
6739 --- a/arch/mips/include/asm/uaccess.h
6740 +++ b/arch/mips/include/asm/uaccess.h
6741 @@ -128,6 +128,7 @@ extern u64 __ua_limit;
6742 __ok == 0; \
6743 })
6744
6745 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6746 #define access_ok(type, addr, size) \
6747 likely(__access_ok((addr), (size), __access_mask))
6748
6749 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6750 index 1188e00..41cf144 100644
6751 --- a/arch/mips/kernel/binfmt_elfn32.c
6752 +++ b/arch/mips/kernel/binfmt_elfn32.c
6753 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6754 #undef ELF_ET_DYN_BASE
6755 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6756
6757 +#ifdef CONFIG_PAX_ASLR
6758 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6759 +
6760 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6761 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6762 +#endif
6763 +
6764 #include <asm/processor.h>
6765 #include <linux/module.h>
6766 #include <linux/elfcore.h>
6767 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6768 index 202e581..689ca79 100644
6769 --- a/arch/mips/kernel/binfmt_elfo32.c
6770 +++ b/arch/mips/kernel/binfmt_elfo32.c
6771 @@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6772 #undef ELF_ET_DYN_BASE
6773 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6774
6775 +#ifdef CONFIG_PAX_ASLR
6776 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6777 +
6778 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6779 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6780 +#endif
6781 +
6782 #include <asm/processor.h>
6783
6784 /*
6785 diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c
6786 index 185ba25..374ed74 100644
6787 --- a/arch/mips/kernel/ftrace.c
6788 +++ b/arch/mips/kernel/ftrace.c
6789 @@ -111,11 +111,10 @@ static int ftrace_modify_code_2(unsigned long ip, unsigned int new_code1,
6790 safe_store_code(new_code1, ip, faulted);
6791 if (unlikely(faulted))
6792 return -EFAULT;
6793 - ip += 4;
6794 - safe_store_code(new_code2, ip, faulted);
6795 + safe_store_code(new_code2, ip + 4, faulted);
6796 if (unlikely(faulted))
6797 return -EFAULT;
6798 - flush_icache_range(ip, ip + 8); /* original ip + 12 */
6799 + flush_icache_range(ip, ip + 8);
6800 return 0;
6801 }
6802 #endif
6803 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6804 index 2b91fe8..fe4f6b4 100644
6805 --- a/arch/mips/kernel/i8259.c
6806 +++ b/arch/mips/kernel/i8259.c
6807 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6808 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6809 spurious_irq_mask |= irqmask;
6810 }
6811 - atomic_inc(&irq_err_count);
6812 + atomic_inc_unchecked(&irq_err_count);
6813 /*
6814 * Theoretically we do not have to handle this IRQ,
6815 * but in Linux this does not cause problems and is
6816 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6817 index 44a1f79..2bd6aa3 100644
6818 --- a/arch/mips/kernel/irq-gt641xx.c
6819 +++ b/arch/mips/kernel/irq-gt641xx.c
6820 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6821 }
6822 }
6823
6824 - atomic_inc(&irq_err_count);
6825 + atomic_inc_unchecked(&irq_err_count);
6826 }
6827
6828 void __init gt641xx_irq_init(void)
6829 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6830 index d1fea7a..45602ea 100644
6831 --- a/arch/mips/kernel/irq.c
6832 +++ b/arch/mips/kernel/irq.c
6833 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6834 printk("unexpected IRQ # %d\n", irq);
6835 }
6836
6837 -atomic_t irq_err_count;
6838 +atomic_unchecked_t irq_err_count;
6839
6840 int arch_show_interrupts(struct seq_file *p, int prec)
6841 {
6842 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6843 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6844 return 0;
6845 }
6846
6847 asmlinkage void spurious_interrupt(void)
6848 {
6849 - atomic_inc(&irq_err_count);
6850 + atomic_inc_unchecked(&irq_err_count);
6851 }
6852
6853 void __init init_IRQ(void)
6854 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6855 index ddc7610..8c58f17 100644
6856 --- a/arch/mips/kernel/process.c
6857 +++ b/arch/mips/kernel/process.c
6858 @@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6859 out:
6860 return pc;
6861 }
6862 -
6863 -/*
6864 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6865 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6866 - */
6867 -unsigned long arch_align_stack(unsigned long sp)
6868 -{
6869 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6870 - sp -= get_random_int() & ~PAGE_MASK;
6871 -
6872 - return sp & ALMASK;
6873 -}
6874 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6875 index b52e1d2..1a3ca09 100644
6876 --- a/arch/mips/kernel/ptrace.c
6877 +++ b/arch/mips/kernel/ptrace.c
6878 @@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6879 return ret;
6880 }
6881
6882 +#ifdef CONFIG_GRKERNSEC_SETXID
6883 +extern void gr_delayed_cred_worker(void);
6884 +#endif
6885 +
6886 /*
6887 * Notification of system call entry/exit
6888 * - triggered by current->work.syscall_trace
6889 @@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6890 tracehook_report_syscall_entry(regs))
6891 ret = -1;
6892
6893 +#ifdef CONFIG_GRKERNSEC_SETXID
6894 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6895 + gr_delayed_cred_worker();
6896 +#endif
6897 +
6898 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6899 trace_sys_enter(regs, regs->regs[2]);
6900
6901 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6902 index 07fc524..b9d7f28 100644
6903 --- a/arch/mips/kernel/reset.c
6904 +++ b/arch/mips/kernel/reset.c
6905 @@ -13,6 +13,7 @@
6906 #include <linux/reboot.h>
6907
6908 #include <asm/reboot.h>
6909 +#include <asm/bug.h>
6910
6911 /*
6912 * Urgs ... Too many MIPS machines to handle this in a generic way.
6913 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6914 {
6915 if (_machine_restart)
6916 _machine_restart(command);
6917 + BUG();
6918 }
6919
6920 void machine_halt(void)
6921 {
6922 if (_machine_halt)
6923 _machine_halt();
6924 + BUG();
6925 }
6926
6927 void machine_power_off(void)
6928 {
6929 if (pm_power_off)
6930 pm_power_off();
6931 + BUG();
6932 }
6933 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6934 index c10aa84..9ec2e60 100644
6935 --- a/arch/mips/kernel/smtc-proc.c
6936 +++ b/arch/mips/kernel/smtc-proc.c
6937 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6938
6939 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6940
6941 -atomic_t smtc_fpu_recoveries;
6942 +atomic_unchecked_t smtc_fpu_recoveries;
6943
6944 static int smtc_proc_show(struct seq_file *m, void *v)
6945 {
6946 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6947 for(i = 0; i < NR_CPUS; i++)
6948 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6949 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6950 - atomic_read(&smtc_fpu_recoveries));
6951 + atomic_read_unchecked(&smtc_fpu_recoveries));
6952 return 0;
6953 }
6954
6955 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6956 smtc_cpu_stats[i].selfipis = 0;
6957 }
6958
6959 - atomic_set(&smtc_fpu_recoveries, 0);
6960 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6961
6962 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6963 }
6964 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6965 index dfc1b91..11a2c07 100644
6966 --- a/arch/mips/kernel/smtc.c
6967 +++ b/arch/mips/kernel/smtc.c
6968 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6969 }
6970 smtc_ipi_qdump();
6971 printk("%d Recoveries of \"stolen\" FPU\n",
6972 - atomic_read(&smtc_fpu_recoveries));
6973 + atomic_read_unchecked(&smtc_fpu_recoveries));
6974 }
6975
6976
6977 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6978 index 84536bf..79caa4d 100644
6979 --- a/arch/mips/kernel/sync-r4k.c
6980 +++ b/arch/mips/kernel/sync-r4k.c
6981 @@ -21,8 +21,8 @@
6982 #include <asm/mipsregs.h>
6983
6984 static atomic_t count_start_flag = ATOMIC_INIT(0);
6985 -static atomic_t count_count_start = ATOMIC_INIT(0);
6986 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6987 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6988 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6989 static atomic_t count_reference = ATOMIC_INIT(0);
6990
6991 #define COUNTON 100
6992 @@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6993
6994 for (i = 0; i < NR_LOOPS; i++) {
6995 /* slaves loop on '!= 2' */
6996 - while (atomic_read(&count_count_start) != 1)
6997 + while (atomic_read_unchecked(&count_count_start) != 1)
6998 mb();
6999 - atomic_set(&count_count_stop, 0);
7000 + atomic_set_unchecked(&count_count_stop, 0);
7001 smp_wmb();
7002
7003 /* this lets the slaves write their count register */
7004 - atomic_inc(&count_count_start);
7005 + atomic_inc_unchecked(&count_count_start);
7006
7007 /*
7008 * Everyone initialises count in the last loop:
7009 @@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
7010 /*
7011 * Wait for all slaves to leave the synchronization point:
7012 */
7013 - while (atomic_read(&count_count_stop) != 1)
7014 + while (atomic_read_unchecked(&count_count_stop) != 1)
7015 mb();
7016 - atomic_set(&count_count_start, 0);
7017 + atomic_set_unchecked(&count_count_start, 0);
7018 smp_wmb();
7019 - atomic_inc(&count_count_stop);
7020 + atomic_inc_unchecked(&count_count_stop);
7021 }
7022 /* Arrange for an interrupt in a short while */
7023 write_c0_compare(read_c0_count() + COUNTON);
7024 @@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
7025 initcount = atomic_read(&count_reference);
7026
7027 for (i = 0; i < NR_LOOPS; i++) {
7028 - atomic_inc(&count_count_start);
7029 - while (atomic_read(&count_count_start) != 2)
7030 + atomic_inc_unchecked(&count_count_start);
7031 + while (atomic_read_unchecked(&count_count_start) != 2)
7032 mb();
7033
7034 /*
7035 @@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
7036 if (i == NR_LOOPS-1)
7037 write_c0_count(initcount);
7038
7039 - atomic_inc(&count_count_stop);
7040 - while (atomic_read(&count_count_stop) != 2)
7041 + atomic_inc_unchecked(&count_count_stop);
7042 + while (atomic_read_unchecked(&count_count_stop) != 2)
7043 mb();
7044 }
7045 /* Arrange for an interrupt in a short while */
7046 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7047 index f9c8746..78b64e3 100644
7048 --- a/arch/mips/kernel/traps.c
7049 +++ b/arch/mips/kernel/traps.c
7050 @@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7051 siginfo_t info;
7052
7053 prev_state = exception_enter();
7054 - die_if_kernel("Integer overflow", regs);
7055 + if (unlikely(!user_mode(regs))) {
7056 +
7057 +#ifdef CONFIG_PAX_REFCOUNT
7058 + if (fixup_exception(regs)) {
7059 + pax_report_refcount_overflow(regs);
7060 + exception_exit(prev_state);
7061 + return;
7062 + }
7063 +#endif
7064 +
7065 + die("Integer overflow", regs);
7066 + }
7067
7068 info.si_code = FPE_INTOVF;
7069 info.si_signo = SIGFPE;
7070 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7071 index becc42b..9e43d4b 100644
7072 --- a/arch/mips/mm/fault.c
7073 +++ b/arch/mips/mm/fault.c
7074 @@ -28,6 +28,23 @@
7075 #include <asm/highmem.h> /* For VMALLOC_END */
7076 #include <linux/kdebug.h>
7077
7078 +#ifdef CONFIG_PAX_PAGEEXEC
7079 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7080 +{
7081 + unsigned long i;
7082 +
7083 + printk(KERN_ERR "PAX: bytes at PC: ");
7084 + for (i = 0; i < 5; i++) {
7085 + unsigned int c;
7086 + if (get_user(c, (unsigned int *)pc+i))
7087 + printk(KERN_CONT "???????? ");
7088 + else
7089 + printk(KERN_CONT "%08x ", c);
7090 + }
7091 + printk("\n");
7092 +}
7093 +#endif
7094 +
7095 /*
7096 * This routine handles page faults. It determines the address,
7097 * and the problem, and then passes it off to one of the appropriate
7098 @@ -199,6 +216,14 @@ bad_area:
7099 bad_area_nosemaphore:
7100 /* User mode accesses just cause a SIGSEGV */
7101 if (user_mode(regs)) {
7102 +
7103 +#ifdef CONFIG_PAX_PAGEEXEC
7104 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7105 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7106 + do_group_exit(SIGKILL);
7107 + }
7108 +#endif
7109 +
7110 tsk->thread.cp0_badvaddr = address;
7111 tsk->thread.error_code = write;
7112 #if 0
7113 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7114 index f1baadd..5472dca 100644
7115 --- a/arch/mips/mm/mmap.c
7116 +++ b/arch/mips/mm/mmap.c
7117 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7118 struct vm_area_struct *vma;
7119 unsigned long addr = addr0;
7120 int do_color_align;
7121 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7122 struct vm_unmapped_area_info info;
7123
7124 if (unlikely(len > TASK_SIZE))
7125 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7126 do_color_align = 1;
7127
7128 /* requesting a specific address */
7129 +
7130 +#ifdef CONFIG_PAX_RANDMMAP
7131 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7132 +#endif
7133 +
7134 if (addr) {
7135 if (do_color_align)
7136 addr = COLOUR_ALIGN(addr, pgoff);
7137 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7138 addr = PAGE_ALIGN(addr);
7139
7140 vma = find_vma(mm, addr);
7141 - if (TASK_SIZE - len >= addr &&
7142 - (!vma || addr + len <= vma->vm_start))
7143 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7144 return addr;
7145 }
7146
7147 info.length = len;
7148 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7149 info.align_offset = pgoff << PAGE_SHIFT;
7150 + info.threadstack_offset = offset;
7151
7152 if (dir == DOWN) {
7153 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7154 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7155 {
7156 unsigned long random_factor = 0UL;
7157
7158 +#ifdef CONFIG_PAX_RANDMMAP
7159 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7160 +#endif
7161 +
7162 if (current->flags & PF_RANDOMIZE) {
7163 random_factor = get_random_int();
7164 random_factor = random_factor << PAGE_SHIFT;
7165 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7166
7167 if (mmap_is_legacy()) {
7168 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7169 +
7170 +#ifdef CONFIG_PAX_RANDMMAP
7171 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7172 + mm->mmap_base += mm->delta_mmap;
7173 +#endif
7174 +
7175 mm->get_unmapped_area = arch_get_unmapped_area;
7176 } else {
7177 mm->mmap_base = mmap_base(random_factor);
7178 +
7179 +#ifdef CONFIG_PAX_RANDMMAP
7180 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7181 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7182 +#endif
7183 +
7184 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7185 }
7186 }
7187
7188 -static inline unsigned long brk_rnd(void)
7189 -{
7190 - unsigned long rnd = get_random_int();
7191 -
7192 - rnd = rnd << PAGE_SHIFT;
7193 - /* 8MB for 32bit, 256MB for 64bit */
7194 - if (TASK_IS_32BIT_ADDR)
7195 - rnd = rnd & 0x7ffffful;
7196 - else
7197 - rnd = rnd & 0xffffffful;
7198 -
7199 - return rnd;
7200 -}
7201 -
7202 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7203 -{
7204 - unsigned long base = mm->brk;
7205 - unsigned long ret;
7206 -
7207 - ret = PAGE_ALIGN(base + brk_rnd());
7208 -
7209 - if (ret < mm->brk)
7210 - return mm->brk;
7211 -
7212 - return ret;
7213 -}
7214 -
7215 int __virt_addr_valid(const volatile void *kaddr)
7216 {
7217 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7218 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7219 index 59cccd9..f39ac2f 100644
7220 --- a/arch/mips/pci/pci-octeon.c
7221 +++ b/arch/mips/pci/pci-octeon.c
7222 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7223
7224
7225 static struct pci_ops octeon_pci_ops = {
7226 - octeon_read_config,
7227 - octeon_write_config,
7228 + .read = octeon_read_config,
7229 + .write = octeon_write_config,
7230 };
7231
7232 static struct resource octeon_pci_mem_resource = {
7233 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7234 index 5e36c33..eb4a17b 100644
7235 --- a/arch/mips/pci/pcie-octeon.c
7236 +++ b/arch/mips/pci/pcie-octeon.c
7237 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7238 }
7239
7240 static struct pci_ops octeon_pcie0_ops = {
7241 - octeon_pcie0_read_config,
7242 - octeon_pcie0_write_config,
7243 + .read = octeon_pcie0_read_config,
7244 + .write = octeon_pcie0_write_config,
7245 };
7246
7247 static struct resource octeon_pcie0_mem_resource = {
7248 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7249 };
7250
7251 static struct pci_ops octeon_pcie1_ops = {
7252 - octeon_pcie1_read_config,
7253 - octeon_pcie1_write_config,
7254 + .read = octeon_pcie1_read_config,
7255 + .write = octeon_pcie1_write_config,
7256 };
7257
7258 static struct resource octeon_pcie1_mem_resource = {
7259 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7260 };
7261
7262 static struct pci_ops octeon_dummy_ops = {
7263 - octeon_dummy_read_config,
7264 - octeon_dummy_write_config,
7265 + .read = octeon_dummy_read_config,
7266 + .write = octeon_dummy_write_config,
7267 };
7268
7269 static struct resource octeon_dummy_mem_resource = {
7270 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7271 index a2358b4..7cead4f 100644
7272 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7273 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7274 @@ -187,9 +187,9 @@ void
7275 cont_nmi_dump(void)
7276 {
7277 #ifndef REAL_NMI_SIGNAL
7278 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7279 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7280
7281 - atomic_inc(&nmied_cpus);
7282 + atomic_inc_unchecked(&nmied_cpus);
7283 #endif
7284 /*
7285 * Only allow 1 cpu to proceed
7286 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7287 udelay(10000);
7288 }
7289 #else
7290 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7291 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7292 #endif
7293
7294 /*
7295 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7296 index a046b30..6799527 100644
7297 --- a/arch/mips/sni/rm200.c
7298 +++ b/arch/mips/sni/rm200.c
7299 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7300 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7301 spurious_irq_mask |= irqmask;
7302 }
7303 - atomic_inc(&irq_err_count);
7304 + atomic_inc_unchecked(&irq_err_count);
7305 /*
7306 * Theoretically we do not have to handle this IRQ,
7307 * but in Linux this does not cause problems and is
7308 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7309 index 41e873b..34d33a7 100644
7310 --- a/arch/mips/vr41xx/common/icu.c
7311 +++ b/arch/mips/vr41xx/common/icu.c
7312 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7313
7314 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7315
7316 - atomic_inc(&irq_err_count);
7317 + atomic_inc_unchecked(&irq_err_count);
7318
7319 return -1;
7320 }
7321 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7322 index ae0e4ee..e8f0692 100644
7323 --- a/arch/mips/vr41xx/common/irq.c
7324 +++ b/arch/mips/vr41xx/common/irq.c
7325 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7326 irq_cascade_t *cascade;
7327
7328 if (irq >= NR_IRQS) {
7329 - atomic_inc(&irq_err_count);
7330 + atomic_inc_unchecked(&irq_err_count);
7331 return;
7332 }
7333
7334 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7335 ret = cascade->get_irq(irq);
7336 irq = ret;
7337 if (ret < 0)
7338 - atomic_inc(&irq_err_count);
7339 + atomic_inc_unchecked(&irq_err_count);
7340 else
7341 irq_dispatch(irq);
7342 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7343 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7344 index 967d144..db12197 100644
7345 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7346 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7347 @@ -11,12 +11,14 @@
7348 #ifndef _ASM_PROC_CACHE_H
7349 #define _ASM_PROC_CACHE_H
7350
7351 +#include <linux/const.h>
7352 +
7353 /* L1 cache */
7354
7355 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7356 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7357 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7358 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7359 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7360 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7361
7362 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7363 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7364 index bcb5df2..84fabd2 100644
7365 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7366 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7367 @@ -16,13 +16,15 @@
7368 #ifndef _ASM_PROC_CACHE_H
7369 #define _ASM_PROC_CACHE_H
7370
7371 +#include <linux/const.h>
7372 +
7373 /*
7374 * L1 cache
7375 */
7376 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7377 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7378 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7379 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7380 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7381 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7382
7383 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7384 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7385 index 4ce7a01..449202a 100644
7386 --- a/arch/openrisc/include/asm/cache.h
7387 +++ b/arch/openrisc/include/asm/cache.h
7388 @@ -19,11 +19,13 @@
7389 #ifndef __ASM_OPENRISC_CACHE_H
7390 #define __ASM_OPENRISC_CACHE_H
7391
7392 +#include <linux/const.h>
7393 +
7394 /* FIXME: How can we replace these with values from the CPU...
7395 * they shouldn't be hard-coded!
7396 */
7397
7398 -#define L1_CACHE_BYTES 16
7399 #define L1_CACHE_SHIFT 4
7400 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7401
7402 #endif /* __ASM_OPENRISC_CACHE_H */
7403 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7404 index 472886c..00e7df9 100644
7405 --- a/arch/parisc/include/asm/atomic.h
7406 +++ b/arch/parisc/include/asm/atomic.h
7407 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7408 return dec;
7409 }
7410
7411 +#define atomic64_read_unchecked(v) atomic64_read(v)
7412 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7413 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7414 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7415 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7416 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7417 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7418 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7419 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7420 +
7421 #endif /* !CONFIG_64BIT */
7422
7423
7424 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7425 index 47f11c7..3420df2 100644
7426 --- a/arch/parisc/include/asm/cache.h
7427 +++ b/arch/parisc/include/asm/cache.h
7428 @@ -5,6 +5,7 @@
7429 #ifndef __ARCH_PARISC_CACHE_H
7430 #define __ARCH_PARISC_CACHE_H
7431
7432 +#include <linux/const.h>
7433
7434 /*
7435 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7436 @@ -15,13 +16,13 @@
7437 * just ruin performance.
7438 */
7439 #ifdef CONFIG_PA20
7440 -#define L1_CACHE_BYTES 64
7441 #define L1_CACHE_SHIFT 6
7442 #else
7443 -#define L1_CACHE_BYTES 32
7444 #define L1_CACHE_SHIFT 5
7445 #endif
7446
7447 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7448 +
7449 #ifndef __ASSEMBLY__
7450
7451 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7452 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7453 index ad2b503..bdf1651 100644
7454 --- a/arch/parisc/include/asm/elf.h
7455 +++ b/arch/parisc/include/asm/elf.h
7456 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7457
7458 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7459
7460 +#ifdef CONFIG_PAX_ASLR
7461 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7462 +
7463 +#define PAX_DELTA_MMAP_LEN 16
7464 +#define PAX_DELTA_STACK_LEN 16
7465 +#endif
7466 +
7467 /* This yields a mask that user programs can use to figure out what
7468 instruction set this CPU supports. This could be done in user space,
7469 but it's not easy, and we've already done it here. */
7470 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7471 index f213f5b..0af3e8e 100644
7472 --- a/arch/parisc/include/asm/pgalloc.h
7473 +++ b/arch/parisc/include/asm/pgalloc.h
7474 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7475 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7476 }
7477
7478 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7479 +{
7480 + pgd_populate(mm, pgd, pmd);
7481 +}
7482 +
7483 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7484 {
7485 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7486 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7487 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7488 #define pmd_free(mm, x) do { } while (0)
7489 #define pgd_populate(mm, pmd, pte) BUG()
7490 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7491
7492 #endif
7493
7494 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7495 index 34899b5..02dd060 100644
7496 --- a/arch/parisc/include/asm/pgtable.h
7497 +++ b/arch/parisc/include/asm/pgtable.h
7498 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7499 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7500 #define PAGE_COPY PAGE_EXECREAD
7501 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7502 +
7503 +#ifdef CONFIG_PAX_PAGEEXEC
7504 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7505 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7506 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7507 +#else
7508 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7509 +# define PAGE_COPY_NOEXEC PAGE_COPY
7510 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7511 +#endif
7512 +
7513 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7514 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7515 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7516 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7517 index 4006964..fcb3cc2 100644
7518 --- a/arch/parisc/include/asm/uaccess.h
7519 +++ b/arch/parisc/include/asm/uaccess.h
7520 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7521 const void __user *from,
7522 unsigned long n)
7523 {
7524 - int sz = __compiletime_object_size(to);
7525 + size_t sz = __compiletime_object_size(to);
7526 int ret = -EFAULT;
7527
7528 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7529 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7530 ret = __copy_from_user(to, from, n);
7531 else
7532 copy_from_user_overflow();
7533 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7534 index 50dfafc..b9fc230 100644
7535 --- a/arch/parisc/kernel/module.c
7536 +++ b/arch/parisc/kernel/module.c
7537 @@ -98,16 +98,38 @@
7538
7539 /* three functions to determine where in the module core
7540 * or init pieces the location is */
7541 +static inline int in_init_rx(struct module *me, void *loc)
7542 +{
7543 + return (loc >= me->module_init_rx &&
7544 + loc < (me->module_init_rx + me->init_size_rx));
7545 +}
7546 +
7547 +static inline int in_init_rw(struct module *me, void *loc)
7548 +{
7549 + return (loc >= me->module_init_rw &&
7550 + loc < (me->module_init_rw + me->init_size_rw));
7551 +}
7552 +
7553 static inline int in_init(struct module *me, void *loc)
7554 {
7555 - return (loc >= me->module_init &&
7556 - loc <= (me->module_init + me->init_size));
7557 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7558 +}
7559 +
7560 +static inline int in_core_rx(struct module *me, void *loc)
7561 +{
7562 + return (loc >= me->module_core_rx &&
7563 + loc < (me->module_core_rx + me->core_size_rx));
7564 +}
7565 +
7566 +static inline int in_core_rw(struct module *me, void *loc)
7567 +{
7568 + return (loc >= me->module_core_rw &&
7569 + loc < (me->module_core_rw + me->core_size_rw));
7570 }
7571
7572 static inline int in_core(struct module *me, void *loc)
7573 {
7574 - return (loc >= me->module_core &&
7575 - loc <= (me->module_core + me->core_size));
7576 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7577 }
7578
7579 static inline int in_local(struct module *me, void *loc)
7580 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7581 }
7582
7583 /* align things a bit */
7584 - me->core_size = ALIGN(me->core_size, 16);
7585 - me->arch.got_offset = me->core_size;
7586 - me->core_size += gots * sizeof(struct got_entry);
7587 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7588 + me->arch.got_offset = me->core_size_rw;
7589 + me->core_size_rw += gots * sizeof(struct got_entry);
7590
7591 - me->core_size = ALIGN(me->core_size, 16);
7592 - me->arch.fdesc_offset = me->core_size;
7593 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7594 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7595 + me->arch.fdesc_offset = me->core_size_rw;
7596 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7597
7598 me->arch.got_max = gots;
7599 me->arch.fdesc_max = fdescs;
7600 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7601
7602 BUG_ON(value == 0);
7603
7604 - got = me->module_core + me->arch.got_offset;
7605 + got = me->module_core_rw + me->arch.got_offset;
7606 for (i = 0; got[i].addr; i++)
7607 if (got[i].addr == value)
7608 goto out;
7609 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7610 #ifdef CONFIG_64BIT
7611 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7612 {
7613 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7614 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7615
7616 if (!value) {
7617 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7618 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7619
7620 /* Create new one */
7621 fdesc->addr = value;
7622 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7623 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7624 return (Elf_Addr)fdesc;
7625 }
7626 #endif /* CONFIG_64BIT */
7627 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7628
7629 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7630 end = table + sechdrs[me->arch.unwind_section].sh_size;
7631 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7632 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7633
7634 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7635 me->arch.unwind_section, table, end, gp);
7636 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7637 index 0d3a9d4..20a99b0 100644
7638 --- a/arch/parisc/kernel/sys_parisc.c
7639 +++ b/arch/parisc/kernel/sys_parisc.c
7640 @@ -33,9 +33,11 @@
7641 #include <linux/utsname.h>
7642 #include <linux/personality.h>
7643
7644 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7645 +static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7646 + unsigned long flags)
7647 {
7648 struct vm_unmapped_area_info info;
7649 + unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7650
7651 info.flags = 0;
7652 info.length = len;
7653 @@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7654 info.high_limit = TASK_SIZE;
7655 info.align_mask = 0;
7656 info.align_offset = 0;
7657 + info.threadstack_offset = offset;
7658 return vm_unmapped_area(&info);
7659 }
7660
7661 @@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7662 }
7663
7664 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7665 - unsigned long len, unsigned long pgoff)
7666 + unsigned long len, unsigned long pgoff, unsigned long flags)
7667 {
7668 struct vm_unmapped_area_info info;
7669 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7670
7671 info.flags = 0;
7672 info.length = len;
7673 @@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7674 info.high_limit = TASK_SIZE;
7675 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7676 info.align_offset = shared_align_offset(filp, pgoff);
7677 + info.threadstack_offset = offset;
7678 return vm_unmapped_area(&info);
7679 }
7680
7681 @@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7682 return -EINVAL;
7683 return addr;
7684 }
7685 - if (!addr)
7686 + if (!addr) {
7687 addr = TASK_UNMAPPED_BASE;
7688
7689 +#ifdef CONFIG_PAX_RANDMMAP
7690 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7691 + addr += current->mm->delta_mmap;
7692 +#endif
7693 +
7694 + }
7695 +
7696 if (filp || (flags & MAP_SHARED))
7697 - addr = get_shared_area(filp, addr, len, pgoff);
7698 + addr = get_shared_area(filp, addr, len, pgoff, flags);
7699 else
7700 - addr = get_unshared_area(addr, len);
7701 + addr = get_unshared_area(addr, len, flags);
7702
7703 return addr;
7704 }
7705 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7706 index 1cd1d0c..44ec918 100644
7707 --- a/arch/parisc/kernel/traps.c
7708 +++ b/arch/parisc/kernel/traps.c
7709 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7710
7711 down_read(&current->mm->mmap_sem);
7712 vma = find_vma(current->mm,regs->iaoq[0]);
7713 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7714 - && (vma->vm_flags & VM_EXEC)) {
7715 -
7716 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7717 fault_address = regs->iaoq[0];
7718 fault_space = regs->iasq[0];
7719
7720 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7721 index 9d08c71..e2b4d20 100644
7722 --- a/arch/parisc/mm/fault.c
7723 +++ b/arch/parisc/mm/fault.c
7724 @@ -15,6 +15,7 @@
7725 #include <linux/sched.h>
7726 #include <linux/interrupt.h>
7727 #include <linux/module.h>
7728 +#include <linux/unistd.h>
7729
7730 #include <asm/uaccess.h>
7731 #include <asm/traps.h>
7732 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7733 static unsigned long
7734 parisc_acctyp(unsigned long code, unsigned int inst)
7735 {
7736 - if (code == 6 || code == 16)
7737 + if (code == 6 || code == 7 || code == 16)
7738 return VM_EXEC;
7739
7740 switch (inst & 0xf0000000) {
7741 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7742 }
7743 #endif
7744
7745 +#ifdef CONFIG_PAX_PAGEEXEC
7746 +/*
7747 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7748 + *
7749 + * returns 1 when task should be killed
7750 + * 2 when rt_sigreturn trampoline was detected
7751 + * 3 when unpatched PLT trampoline was detected
7752 + */
7753 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7754 +{
7755 +
7756 +#ifdef CONFIG_PAX_EMUPLT
7757 + int err;
7758 +
7759 + do { /* PaX: unpatched PLT emulation */
7760 + unsigned int bl, depwi;
7761 +
7762 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7763 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7764 +
7765 + if (err)
7766 + break;
7767 +
7768 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7769 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7770 +
7771 + err = get_user(ldw, (unsigned int *)addr);
7772 + err |= get_user(bv, (unsigned int *)(addr+4));
7773 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7774 +
7775 + if (err)
7776 + break;
7777 +
7778 + if (ldw == 0x0E801096U &&
7779 + bv == 0xEAC0C000U &&
7780 + ldw2 == 0x0E881095U)
7781 + {
7782 + unsigned int resolver, map;
7783 +
7784 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7785 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7786 + if (err)
7787 + break;
7788 +
7789 + regs->gr[20] = instruction_pointer(regs)+8;
7790 + regs->gr[21] = map;
7791 + regs->gr[22] = resolver;
7792 + regs->iaoq[0] = resolver | 3UL;
7793 + regs->iaoq[1] = regs->iaoq[0] + 4;
7794 + return 3;
7795 + }
7796 + }
7797 + } while (0);
7798 +#endif
7799 +
7800 +#ifdef CONFIG_PAX_EMUTRAMP
7801 +
7802 +#ifndef CONFIG_PAX_EMUSIGRT
7803 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7804 + return 1;
7805 +#endif
7806 +
7807 + do { /* PaX: rt_sigreturn emulation */
7808 + unsigned int ldi1, ldi2, bel, nop;
7809 +
7810 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7811 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7812 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7813 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7814 +
7815 + if (err)
7816 + break;
7817 +
7818 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7819 + ldi2 == 0x3414015AU &&
7820 + bel == 0xE4008200U &&
7821 + nop == 0x08000240U)
7822 + {
7823 + regs->gr[25] = (ldi1 & 2) >> 1;
7824 + regs->gr[20] = __NR_rt_sigreturn;
7825 + regs->gr[31] = regs->iaoq[1] + 16;
7826 + regs->sr[0] = regs->iasq[1];
7827 + regs->iaoq[0] = 0x100UL;
7828 + regs->iaoq[1] = regs->iaoq[0] + 4;
7829 + regs->iasq[0] = regs->sr[2];
7830 + regs->iasq[1] = regs->sr[2];
7831 + return 2;
7832 + }
7833 + } while (0);
7834 +#endif
7835 +
7836 + return 1;
7837 +}
7838 +
7839 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7840 +{
7841 + unsigned long i;
7842 +
7843 + printk(KERN_ERR "PAX: bytes at PC: ");
7844 + for (i = 0; i < 5; i++) {
7845 + unsigned int c;
7846 + if (get_user(c, (unsigned int *)pc+i))
7847 + printk(KERN_CONT "???????? ");
7848 + else
7849 + printk(KERN_CONT "%08x ", c);
7850 + }
7851 + printk("\n");
7852 +}
7853 +#endif
7854 +
7855 int fixup_exception(struct pt_regs *regs)
7856 {
7857 const struct exception_table_entry *fix;
7858 @@ -210,8 +321,33 @@ retry:
7859
7860 good_area:
7861
7862 - if ((vma->vm_flags & acc_type) != acc_type)
7863 + if ((vma->vm_flags & acc_type) != acc_type) {
7864 +
7865 +#ifdef CONFIG_PAX_PAGEEXEC
7866 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7867 + (address & ~3UL) == instruction_pointer(regs))
7868 + {
7869 + up_read(&mm->mmap_sem);
7870 + switch (pax_handle_fetch_fault(regs)) {
7871 +
7872 +#ifdef CONFIG_PAX_EMUPLT
7873 + case 3:
7874 + return;
7875 +#endif
7876 +
7877 +#ifdef CONFIG_PAX_EMUTRAMP
7878 + case 2:
7879 + return;
7880 +#endif
7881 +
7882 + }
7883 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7884 + do_group_exit(SIGKILL);
7885 + }
7886 +#endif
7887 +
7888 goto bad_area;
7889 + }
7890
7891 /*
7892 * If for any reason at all we couldn't handle the fault, make
7893 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7894 index b44b52c..4cd253c 100644
7895 --- a/arch/powerpc/Kconfig
7896 +++ b/arch/powerpc/Kconfig
7897 @@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7898 config KEXEC
7899 bool "kexec system call"
7900 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7901 + depends on !GRKERNSEC_KMEM
7902 help
7903 kexec is a system call that implements the ability to shutdown your
7904 current kernel, and to start another kernel. It is like a reboot
7905 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7906 index e3b1d41..8e81edf 100644
7907 --- a/arch/powerpc/include/asm/atomic.h
7908 +++ b/arch/powerpc/include/asm/atomic.h
7909 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7910 return t1;
7911 }
7912
7913 +#define atomic64_read_unchecked(v) atomic64_read(v)
7914 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7915 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7916 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7917 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7918 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7919 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7920 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7921 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7922 +
7923 #endif /* __powerpc64__ */
7924
7925 #endif /* __KERNEL__ */
7926 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7927 index 9e495c9..b6878e5 100644
7928 --- a/arch/powerpc/include/asm/cache.h
7929 +++ b/arch/powerpc/include/asm/cache.h
7930 @@ -3,6 +3,7 @@
7931
7932 #ifdef __KERNEL__
7933
7934 +#include <linux/const.h>
7935
7936 /* bytes per L1 cache line */
7937 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7938 @@ -22,7 +23,7 @@
7939 #define L1_CACHE_SHIFT 7
7940 #endif
7941
7942 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7943 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7944
7945 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7946
7947 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7948 index 935b5e7..7001d2d 100644
7949 --- a/arch/powerpc/include/asm/elf.h
7950 +++ b/arch/powerpc/include/asm/elf.h
7951 @@ -28,8 +28,19 @@
7952 the loader. We need to make sure that it is out of the way of the program
7953 that it will "exec", and that there is sufficient room for the brk. */
7954
7955 -extern unsigned long randomize_et_dyn(unsigned long base);
7956 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7957 +#define ELF_ET_DYN_BASE (0x20000000)
7958 +
7959 +#ifdef CONFIG_PAX_ASLR
7960 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7961 +
7962 +#ifdef __powerpc64__
7963 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7964 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7965 +#else
7966 +#define PAX_DELTA_MMAP_LEN 15
7967 +#define PAX_DELTA_STACK_LEN 15
7968 +#endif
7969 +#endif
7970
7971 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7972
7973 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7974 (0x7ff >> (PAGE_SHIFT - 12)) : \
7975 (0x3ffff >> (PAGE_SHIFT - 12)))
7976
7977 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7978 -#define arch_randomize_brk arch_randomize_brk
7979 -
7980 -
7981 #ifdef CONFIG_SPU_BASE
7982 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7983 #define NT_SPU 1
7984 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7985 index 8196e9c..d83a9f3 100644
7986 --- a/arch/powerpc/include/asm/exec.h
7987 +++ b/arch/powerpc/include/asm/exec.h
7988 @@ -4,6 +4,6 @@
7989 #ifndef _ASM_POWERPC_EXEC_H
7990 #define _ASM_POWERPC_EXEC_H
7991
7992 -extern unsigned long arch_align_stack(unsigned long sp);
7993 +#define arch_align_stack(x) ((x) & ~0xfUL)
7994
7995 #endif /* _ASM_POWERPC_EXEC_H */
7996 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7997 index 5acabbd..7ea14fa 100644
7998 --- a/arch/powerpc/include/asm/kmap_types.h
7999 +++ b/arch/powerpc/include/asm/kmap_types.h
8000 @@ -10,7 +10,7 @@
8001 * 2 of the License, or (at your option) any later version.
8002 */
8003
8004 -#define KM_TYPE_NR 16
8005 +#define KM_TYPE_NR 17
8006
8007 #endif /* __KERNEL__ */
8008 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8009 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8010 index b8da913..60b608a 100644
8011 --- a/arch/powerpc/include/asm/local.h
8012 +++ b/arch/powerpc/include/asm/local.h
8013 @@ -9,15 +9,26 @@ typedef struct
8014 atomic_long_t a;
8015 } local_t;
8016
8017 +typedef struct
8018 +{
8019 + atomic_long_unchecked_t a;
8020 +} local_unchecked_t;
8021 +
8022 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8023
8024 #define local_read(l) atomic_long_read(&(l)->a)
8025 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8026 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8027 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8028
8029 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8030 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8031 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8032 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8033 #define local_inc(l) atomic_long_inc(&(l)->a)
8034 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8035 #define local_dec(l) atomic_long_dec(&(l)->a)
8036 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8037
8038 static __inline__ long local_add_return(long a, local_t *l)
8039 {
8040 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8041
8042 return t;
8043 }
8044 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8045
8046 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8047
8048 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8049
8050 return t;
8051 }
8052 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8053
8054 static __inline__ long local_inc_return(local_t *l)
8055 {
8056 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8057
8058 #define local_cmpxchg(l, o, n) \
8059 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8060 +#define local_cmpxchg_unchecked(l, o, n) \
8061 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8062 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8063
8064 /**
8065 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8066 index 8565c25..2865190 100644
8067 --- a/arch/powerpc/include/asm/mman.h
8068 +++ b/arch/powerpc/include/asm/mman.h
8069 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8070 }
8071 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8072
8073 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8074 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8075 {
8076 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8077 }
8078 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8079 index 32e4e21..62afb12 100644
8080 --- a/arch/powerpc/include/asm/page.h
8081 +++ b/arch/powerpc/include/asm/page.h
8082 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8083 * and needs to be executable. This means the whole heap ends
8084 * up being executable.
8085 */
8086 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8087 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8088 +#define VM_DATA_DEFAULT_FLAGS32 \
8089 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8090 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8091
8092 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8093 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8094 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8095 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8096 #endif
8097
8098 +#define ktla_ktva(addr) (addr)
8099 +#define ktva_ktla(addr) (addr)
8100 +
8101 #ifndef CONFIG_PPC_BOOK3S_64
8102 /*
8103 * Use the top bit of the higher-level page table entries to indicate whether
8104 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8105 index 88693ce..ac6f9ab 100644
8106 --- a/arch/powerpc/include/asm/page_64.h
8107 +++ b/arch/powerpc/include/asm/page_64.h
8108 @@ -153,15 +153,18 @@ do { \
8109 * stack by default, so in the absence of a PT_GNU_STACK program header
8110 * we turn execute permission off.
8111 */
8112 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8113 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8114 +#define VM_STACK_DEFAULT_FLAGS32 \
8115 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8116 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8117
8118 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8119 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8120
8121 +#ifndef CONFIG_PAX_PAGEEXEC
8122 #define VM_STACK_DEFAULT_FLAGS \
8123 (is_32bit_task() ? \
8124 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8125 +#endif
8126
8127 #include <asm-generic/getorder.h>
8128
8129 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8130 index 4b0be20..c15a27d 100644
8131 --- a/arch/powerpc/include/asm/pgalloc-64.h
8132 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8133 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8134 #ifndef CONFIG_PPC_64K_PAGES
8135
8136 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8137 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8138
8139 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8140 {
8141 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8142 pud_set(pud, (unsigned long)pmd);
8143 }
8144
8145 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8146 +{
8147 + pud_populate(mm, pud, pmd);
8148 +}
8149 +
8150 #define pmd_populate(mm, pmd, pte_page) \
8151 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8152 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8153 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8154 #endif
8155
8156 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8157 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8158
8159 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8160 pte_t *pte)
8161 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8162 index 7d6eacf..14c0240 100644
8163 --- a/arch/powerpc/include/asm/pgtable.h
8164 +++ b/arch/powerpc/include/asm/pgtable.h
8165 @@ -2,6 +2,7 @@
8166 #define _ASM_POWERPC_PGTABLE_H
8167 #ifdef __KERNEL__
8168
8169 +#include <linux/const.h>
8170 #ifndef __ASSEMBLY__
8171 #include <asm/processor.h> /* For TASK_SIZE */
8172 #include <asm/mmu.h>
8173 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8174 index 4aad413..85d86bf 100644
8175 --- a/arch/powerpc/include/asm/pte-hash32.h
8176 +++ b/arch/powerpc/include/asm/pte-hash32.h
8177 @@ -21,6 +21,7 @@
8178 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8179 #define _PAGE_USER 0x004 /* usermode access allowed */
8180 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8181 +#define _PAGE_EXEC _PAGE_GUARDED
8182 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8183 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8184 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8185 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8186 index fa8388e..f985549 100644
8187 --- a/arch/powerpc/include/asm/reg.h
8188 +++ b/arch/powerpc/include/asm/reg.h
8189 @@ -239,6 +239,7 @@
8190 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8191 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8192 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8193 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8194 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8195 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8196 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8197 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8198 index 084e080..9415a3d 100644
8199 --- a/arch/powerpc/include/asm/smp.h
8200 +++ b/arch/powerpc/include/asm/smp.h
8201 @@ -51,7 +51,7 @@ struct smp_ops_t {
8202 int (*cpu_disable)(void);
8203 void (*cpu_die)(unsigned int nr);
8204 int (*cpu_bootable)(unsigned int nr);
8205 -};
8206 +} __no_const;
8207
8208 extern void smp_send_debugger_break(void);
8209 extern void start_secondary_resume(void);
8210 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8211 index 9854c56..7517190 100644
8212 --- a/arch/powerpc/include/asm/thread_info.h
8213 +++ b/arch/powerpc/include/asm/thread_info.h
8214 @@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
8215 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
8216 TIF_NEED_RESCHED */
8217 #define TIF_32BIT 4 /* 32 bit binary */
8218 -#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
8219 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
8220 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
8221 #define TIF_SINGLESTEP 8 /* singlestepping active */
8222 @@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
8223 #if defined(CONFIG_PPC64)
8224 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8225 #endif
8226 +#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
8227 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8228 +#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
8229
8230 /* as above, but as bit values */
8231 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8232 @@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
8233 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8234 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8235 #define _TIF_NOHZ (1<<TIF_NOHZ)
8236 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8237 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8238 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8239 - _TIF_NOHZ)
8240 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8241
8242 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8243 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
8244 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8245 index 9485b43..3bd3c16 100644
8246 --- a/arch/powerpc/include/asm/uaccess.h
8247 +++ b/arch/powerpc/include/asm/uaccess.h
8248 @@ -58,6 +58,7 @@
8249
8250 #endif
8251
8252 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8253 #define access_ok(type, addr, size) \
8254 (__chk_user_ptr(addr), \
8255 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8256 @@ -318,52 +319,6 @@ do { \
8257 extern unsigned long __copy_tofrom_user(void __user *to,
8258 const void __user *from, unsigned long size);
8259
8260 -#ifndef __powerpc64__
8261 -
8262 -static inline unsigned long copy_from_user(void *to,
8263 - const void __user *from, unsigned long n)
8264 -{
8265 - unsigned long over;
8266 -
8267 - if (access_ok(VERIFY_READ, from, n))
8268 - return __copy_tofrom_user((__force void __user *)to, from, n);
8269 - if ((unsigned long)from < TASK_SIZE) {
8270 - over = (unsigned long)from + n - TASK_SIZE;
8271 - return __copy_tofrom_user((__force void __user *)to, from,
8272 - n - over) + over;
8273 - }
8274 - return n;
8275 -}
8276 -
8277 -static inline unsigned long copy_to_user(void __user *to,
8278 - const void *from, unsigned long n)
8279 -{
8280 - unsigned long over;
8281 -
8282 - if (access_ok(VERIFY_WRITE, to, n))
8283 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8284 - if ((unsigned long)to < TASK_SIZE) {
8285 - over = (unsigned long)to + n - TASK_SIZE;
8286 - return __copy_tofrom_user(to, (__force void __user *)from,
8287 - n - over) + over;
8288 - }
8289 - return n;
8290 -}
8291 -
8292 -#else /* __powerpc64__ */
8293 -
8294 -#define __copy_in_user(to, from, size) \
8295 - __copy_tofrom_user((to), (from), (size))
8296 -
8297 -extern unsigned long copy_from_user(void *to, const void __user *from,
8298 - unsigned long n);
8299 -extern unsigned long copy_to_user(void __user *to, const void *from,
8300 - unsigned long n);
8301 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8302 - unsigned long n);
8303 -
8304 -#endif /* __powerpc64__ */
8305 -
8306 static inline unsigned long __copy_from_user_inatomic(void *to,
8307 const void __user *from, unsigned long n)
8308 {
8309 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8310 if (ret == 0)
8311 return 0;
8312 }
8313 +
8314 + if (!__builtin_constant_p(n))
8315 + check_object_size(to, n, false);
8316 +
8317 return __copy_tofrom_user((__force void __user *)to, from, n);
8318 }
8319
8320 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8321 if (ret == 0)
8322 return 0;
8323 }
8324 +
8325 + if (!__builtin_constant_p(n))
8326 + check_object_size(from, n, true);
8327 +
8328 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8329 }
8330
8331 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8332 return __copy_to_user_inatomic(to, from, size);
8333 }
8334
8335 +#ifndef __powerpc64__
8336 +
8337 +static inline unsigned long __must_check copy_from_user(void *to,
8338 + const void __user *from, unsigned long n)
8339 +{
8340 + unsigned long over;
8341 +
8342 + if ((long)n < 0)
8343 + return n;
8344 +
8345 + if (access_ok(VERIFY_READ, from, n)) {
8346 + if (!__builtin_constant_p(n))
8347 + check_object_size(to, n, false);
8348 + return __copy_tofrom_user((__force void __user *)to, from, n);
8349 + }
8350 + if ((unsigned long)from < TASK_SIZE) {
8351 + over = (unsigned long)from + n - TASK_SIZE;
8352 + if (!__builtin_constant_p(n - over))
8353 + check_object_size(to, n - over, false);
8354 + return __copy_tofrom_user((__force void __user *)to, from,
8355 + n - over) + over;
8356 + }
8357 + return n;
8358 +}
8359 +
8360 +static inline unsigned long __must_check copy_to_user(void __user *to,
8361 + const void *from, unsigned long n)
8362 +{
8363 + unsigned long over;
8364 +
8365 + if ((long)n < 0)
8366 + return n;
8367 +
8368 + if (access_ok(VERIFY_WRITE, to, n)) {
8369 + if (!__builtin_constant_p(n))
8370 + check_object_size(from, n, true);
8371 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8372 + }
8373 + if ((unsigned long)to < TASK_SIZE) {
8374 + over = (unsigned long)to + n - TASK_SIZE;
8375 + if (!__builtin_constant_p(n))
8376 + check_object_size(from, n - over, true);
8377 + return __copy_tofrom_user(to, (__force void __user *)from,
8378 + n - over) + over;
8379 + }
8380 + return n;
8381 +}
8382 +
8383 +#else /* __powerpc64__ */
8384 +
8385 +#define __copy_in_user(to, from, size) \
8386 + __copy_tofrom_user((to), (from), (size))
8387 +
8388 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8389 +{
8390 + if ((long)n < 0 || n > INT_MAX)
8391 + return n;
8392 +
8393 + if (!__builtin_constant_p(n))
8394 + check_object_size(to, n, false);
8395 +
8396 + if (likely(access_ok(VERIFY_READ, from, n)))
8397 + n = __copy_from_user(to, from, n);
8398 + else
8399 + memset(to, 0, n);
8400 + return n;
8401 +}
8402 +
8403 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8404 +{
8405 + if ((long)n < 0 || n > INT_MAX)
8406 + return n;
8407 +
8408 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8409 + if (!__builtin_constant_p(n))
8410 + check_object_size(from, n, true);
8411 + n = __copy_to_user(to, from, n);
8412 + }
8413 + return n;
8414 +}
8415 +
8416 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8417 + unsigned long n);
8418 +
8419 +#endif /* __powerpc64__ */
8420 +
8421 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8422
8423 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8424 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8425 index 445cb6e..4f80c5d 100644
8426 --- a/arch/powerpc/kernel/Makefile
8427 +++ b/arch/powerpc/kernel/Makefile
8428 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8429 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8430 endif
8431
8432 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8433 +
8434 obj-y := cputable.o ptrace.o syscalls.o \
8435 irq.o align.o signal_32.o pmc.o vdso.o \
8436 process.o systbl.o idle.o \
8437 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8438 index e775156..af2d1c0 100644
8439 --- a/arch/powerpc/kernel/exceptions-64e.S
8440 +++ b/arch/powerpc/kernel/exceptions-64e.S
8441 @@ -759,6 +759,7 @@ storage_fault_common:
8442 std r14,_DAR(r1)
8443 std r15,_DSISR(r1)
8444 addi r3,r1,STACK_FRAME_OVERHEAD
8445 + bl .save_nvgprs
8446 mr r4,r14
8447 mr r5,r15
8448 ld r14,PACA_EXGEN+EX_R14(r13)
8449 @@ -767,8 +768,7 @@ storage_fault_common:
8450 cmpdi r3,0
8451 bne- 1f
8452 b .ret_from_except_lite
8453 -1: bl .save_nvgprs
8454 - mr r5,r3
8455 +1: mr r5,r3
8456 addi r3,r1,STACK_FRAME_OVERHEAD
8457 ld r4,_DAR(r1)
8458 bl .bad_page_fault
8459 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8460 index 9f905e4..1d6b3d2 100644
8461 --- a/arch/powerpc/kernel/exceptions-64s.S
8462 +++ b/arch/powerpc/kernel/exceptions-64s.S
8463 @@ -1390,10 +1390,10 @@ handle_page_fault:
8464 11: ld r4,_DAR(r1)
8465 ld r5,_DSISR(r1)
8466 addi r3,r1,STACK_FRAME_OVERHEAD
8467 + bl .save_nvgprs
8468 bl .do_page_fault
8469 cmpdi r3,0
8470 beq+ 12f
8471 - bl .save_nvgprs
8472 mr r5,r3
8473 addi r3,r1,STACK_FRAME_OVERHEAD
8474 lwz r4,_DAR(r1)
8475 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8476 index 6cff040..74ac5d1 100644
8477 --- a/arch/powerpc/kernel/module_32.c
8478 +++ b/arch/powerpc/kernel/module_32.c
8479 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8480 me->arch.core_plt_section = i;
8481 }
8482 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8483 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8484 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8485 return -ENOEXEC;
8486 }
8487
8488 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8489
8490 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8491 /* Init, or core PLT? */
8492 - if (location >= mod->module_core
8493 - && location < mod->module_core + mod->core_size)
8494 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8495 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8496 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8497 - else
8498 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8499 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8500 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8501 + else {
8502 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8503 + return ~0UL;
8504 + }
8505
8506 /* Find this entry, or if that fails, the next avail. entry */
8507 while (entry->jump[0]) {
8508 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8509 }
8510 #ifdef CONFIG_DYNAMIC_FTRACE
8511 module->arch.tramp =
8512 - do_plt_call(module->module_core,
8513 + do_plt_call(module->module_core_rx,
8514 (unsigned long)ftrace_caller,
8515 sechdrs, module);
8516 #endif
8517 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8518 index ea2f6a3..dbb2be3 100644
8519 --- a/arch/powerpc/kernel/process.c
8520 +++ b/arch/powerpc/kernel/process.c
8521 @@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8522 * Lookup NIP late so we have the best change of getting the
8523 * above info out without failing
8524 */
8525 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8526 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8527 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8528 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8529 #endif
8530 show_stack(current, (unsigned long *) regs->gpr[1]);
8531 if (!user_mode(regs))
8532 @@ -1385,10 +1385,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8533 newsp = stack[0];
8534 ip = stack[STACK_FRAME_LR_SAVE];
8535 if (!firstframe || ip != lr) {
8536 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8537 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8538 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8539 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8540 - printk(" (%pS)",
8541 + printk(" (%pA)",
8542 (void *)current->ret_stack[curr_frame].ret);
8543 curr_frame--;
8544 }
8545 @@ -1408,7 +1408,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8546 struct pt_regs *regs = (struct pt_regs *)
8547 (sp + STACK_FRAME_OVERHEAD);
8548 lr = regs->link;
8549 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8550 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8551 regs->trap, (void *)regs->nip, (void *)lr);
8552 firstframe = 1;
8553 }
8554 @@ -1444,58 +1444,3 @@ void notrace __ppc64_runlatch_off(void)
8555 mtspr(SPRN_CTRLT, ctrl);
8556 }
8557 #endif /* CONFIG_PPC64 */
8558 -
8559 -unsigned long arch_align_stack(unsigned long sp)
8560 -{
8561 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8562 - sp -= get_random_int() & ~PAGE_MASK;
8563 - return sp & ~0xf;
8564 -}
8565 -
8566 -static inline unsigned long brk_rnd(void)
8567 -{
8568 - unsigned long rnd = 0;
8569 -
8570 - /* 8MB for 32bit, 1GB for 64bit */
8571 - if (is_32bit_task())
8572 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8573 - else
8574 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8575 -
8576 - return rnd << PAGE_SHIFT;
8577 -}
8578 -
8579 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8580 -{
8581 - unsigned long base = mm->brk;
8582 - unsigned long ret;
8583 -
8584 -#ifdef CONFIG_PPC_STD_MMU_64
8585 - /*
8586 - * If we are using 1TB segments and we are allowed to randomise
8587 - * the heap, we can put it above 1TB so it is backed by a 1TB
8588 - * segment. Otherwise the heap will be in the bottom 1TB
8589 - * which always uses 256MB segments and this may result in a
8590 - * performance penalty.
8591 - */
8592 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8593 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8594 -#endif
8595 -
8596 - ret = PAGE_ALIGN(base + brk_rnd());
8597 -
8598 - if (ret < mm->brk)
8599 - return mm->brk;
8600 -
8601 - return ret;
8602 -}
8603 -
8604 -unsigned long randomize_et_dyn(unsigned long base)
8605 -{
8606 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8607 -
8608 - if (ret < base)
8609 - return base;
8610 -
8611 - return ret;
8612 -}
8613 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8614 index 2e3d2bf..35df241 100644
8615 --- a/arch/powerpc/kernel/ptrace.c
8616 +++ b/arch/powerpc/kernel/ptrace.c
8617 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8618 return ret;
8619 }
8620
8621 +#ifdef CONFIG_GRKERNSEC_SETXID
8622 +extern void gr_delayed_cred_worker(void);
8623 +#endif
8624 +
8625 /*
8626 * We must return the syscall number to actually look up in the table.
8627 * This can be -1L to skip running any syscall at all.
8628 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8629
8630 secure_computing_strict(regs->gpr[0]);
8631
8632 +#ifdef CONFIG_GRKERNSEC_SETXID
8633 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8634 + gr_delayed_cred_worker();
8635 +#endif
8636 +
8637 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8638 tracehook_report_syscall_entry(regs))
8639 /*
8640 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8641 {
8642 int step;
8643
8644 +#ifdef CONFIG_GRKERNSEC_SETXID
8645 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8646 + gr_delayed_cred_worker();
8647 +#endif
8648 +
8649 audit_syscall_exit(regs);
8650
8651 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8652 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8653 index 68027bf..b26fd31 100644
8654 --- a/arch/powerpc/kernel/signal_32.c
8655 +++ b/arch/powerpc/kernel/signal_32.c
8656 @@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8657 /* Save user registers on the stack */
8658 frame = &rt_sf->uc.uc_mcontext;
8659 addr = frame;
8660 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8661 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8662 sigret = 0;
8663 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8664 } else {
8665 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8666 index 448245f..b9bae83 100644
8667 --- a/arch/powerpc/kernel/signal_64.c
8668 +++ b/arch/powerpc/kernel/signal_64.c
8669 @@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8670 #endif
8671
8672 /* Set up to return from userspace. */
8673 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8674 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8675 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8676 } else {
8677 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8678 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8679 index 907a472..4ba206f 100644
8680 --- a/arch/powerpc/kernel/traps.c
8681 +++ b/arch/powerpc/kernel/traps.c
8682 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8683 return flags;
8684 }
8685
8686 +extern void gr_handle_kernel_exploit(void);
8687 +
8688 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8689 int signr)
8690 {
8691 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8692 panic("Fatal exception in interrupt");
8693 if (panic_on_oops)
8694 panic("Fatal exception");
8695 +
8696 + gr_handle_kernel_exploit();
8697 +
8698 do_exit(signr);
8699 }
8700
8701 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8702 index 094e45c..d82b848 100644
8703 --- a/arch/powerpc/kernel/vdso.c
8704 +++ b/arch/powerpc/kernel/vdso.c
8705 @@ -35,6 +35,7 @@
8706 #include <asm/vdso.h>
8707 #include <asm/vdso_datapage.h>
8708 #include <asm/setup.h>
8709 +#include <asm/mman.h>
8710
8711 #undef DEBUG
8712
8713 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8714 vdso_base = VDSO32_MBASE;
8715 #endif
8716
8717 - current->mm->context.vdso_base = 0;
8718 + current->mm->context.vdso_base = ~0UL;
8719
8720 /* vDSO has a problem and was disabled, just don't "enable" it for the
8721 * process
8722 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8723 vdso_base = get_unmapped_area(NULL, vdso_base,
8724 (vdso_pages << PAGE_SHIFT) +
8725 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8726 - 0, 0);
8727 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8728 if (IS_ERR_VALUE(vdso_base)) {
8729 rc = vdso_base;
8730 goto fail_mmapsem;
8731 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8732 index 9ae9768..87c3448 100644
8733 --- a/arch/powerpc/kvm/powerpc.c
8734 +++ b/arch/powerpc/kvm/powerpc.c
8735 @@ -1141,7 +1141,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8736 }
8737 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8738
8739 -int kvm_arch_init(void *opaque)
8740 +int kvm_arch_init(const void *opaque)
8741 {
8742 return 0;
8743 }
8744 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8745 index 5eea6f3..5d10396 100644
8746 --- a/arch/powerpc/lib/usercopy_64.c
8747 +++ b/arch/powerpc/lib/usercopy_64.c
8748 @@ -9,22 +9,6 @@
8749 #include <linux/module.h>
8750 #include <asm/uaccess.h>
8751
8752 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8753 -{
8754 - if (likely(access_ok(VERIFY_READ, from, n)))
8755 - n = __copy_from_user(to, from, n);
8756 - else
8757 - memset(to, 0, n);
8758 - return n;
8759 -}
8760 -
8761 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8762 -{
8763 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8764 - n = __copy_to_user(to, from, n);
8765 - return n;
8766 -}
8767 -
8768 unsigned long copy_in_user(void __user *to, const void __user *from,
8769 unsigned long n)
8770 {
8771 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8772 return n;
8773 }
8774
8775 -EXPORT_SYMBOL(copy_from_user);
8776 -EXPORT_SYMBOL(copy_to_user);
8777 EXPORT_SYMBOL(copy_in_user);
8778
8779 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8780 index 51ab9e7..7d3c78b 100644
8781 --- a/arch/powerpc/mm/fault.c
8782 +++ b/arch/powerpc/mm/fault.c
8783 @@ -33,6 +33,10 @@
8784 #include <linux/magic.h>
8785 #include <linux/ratelimit.h>
8786 #include <linux/context_tracking.h>
8787 +#include <linux/slab.h>
8788 +#include <linux/pagemap.h>
8789 +#include <linux/compiler.h>
8790 +#include <linux/unistd.h>
8791
8792 #include <asm/firmware.h>
8793 #include <asm/page.h>
8794 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8795 }
8796 #endif
8797
8798 +#ifdef CONFIG_PAX_PAGEEXEC
8799 +/*
8800 + * PaX: decide what to do with offenders (regs->nip = fault address)
8801 + *
8802 + * returns 1 when task should be killed
8803 + */
8804 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8805 +{
8806 + return 1;
8807 +}
8808 +
8809 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8810 +{
8811 + unsigned long i;
8812 +
8813 + printk(KERN_ERR "PAX: bytes at PC: ");
8814 + for (i = 0; i < 5; i++) {
8815 + unsigned int c;
8816 + if (get_user(c, (unsigned int __user *)pc+i))
8817 + printk(KERN_CONT "???????? ");
8818 + else
8819 + printk(KERN_CONT "%08x ", c);
8820 + }
8821 + printk("\n");
8822 +}
8823 +#endif
8824 +
8825 /*
8826 * Check whether the instruction at regs->nip is a store using
8827 * an update addressing form which will update r1.
8828 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8829 * indicate errors in DSISR but can validly be set in SRR1.
8830 */
8831 if (trap == 0x400)
8832 - error_code &= 0x48200000;
8833 + error_code &= 0x58200000;
8834 else
8835 is_write = error_code & DSISR_ISSTORE;
8836 #else
8837 @@ -378,7 +409,7 @@ good_area:
8838 * "undefined". Of those that can be set, this is the only
8839 * one which seems bad.
8840 */
8841 - if (error_code & 0x10000000)
8842 + if (error_code & DSISR_GUARDED)
8843 /* Guarded storage error. */
8844 goto bad_area;
8845 #endif /* CONFIG_8xx */
8846 @@ -393,7 +424,7 @@ good_area:
8847 * processors use the same I/D cache coherency mechanism
8848 * as embedded.
8849 */
8850 - if (error_code & DSISR_PROTFAULT)
8851 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8852 goto bad_area;
8853 #endif /* CONFIG_PPC_STD_MMU */
8854
8855 @@ -483,6 +514,23 @@ bad_area:
8856 bad_area_nosemaphore:
8857 /* User mode accesses cause a SIGSEGV */
8858 if (user_mode(regs)) {
8859 +
8860 +#ifdef CONFIG_PAX_PAGEEXEC
8861 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8862 +#ifdef CONFIG_PPC_STD_MMU
8863 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8864 +#else
8865 + if (is_exec && regs->nip == address) {
8866 +#endif
8867 + switch (pax_handle_fetch_fault(regs)) {
8868 + }
8869 +
8870 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8871 + do_group_exit(SIGKILL);
8872 + }
8873 + }
8874 +#endif
8875 +
8876 _exception(SIGSEGV, regs, code, address);
8877 goto bail;
8878 }
8879 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8880 index cb8bdbe..cde4bc7 100644
8881 --- a/arch/powerpc/mm/mmap.c
8882 +++ b/arch/powerpc/mm/mmap.c
8883 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8884 return sysctl_legacy_va_layout;
8885 }
8886
8887 -static unsigned long mmap_rnd(void)
8888 +static unsigned long mmap_rnd(struct mm_struct *mm)
8889 {
8890 unsigned long rnd = 0;
8891
8892 +#ifdef CONFIG_PAX_RANDMMAP
8893 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8894 +#endif
8895 +
8896 if (current->flags & PF_RANDOMIZE) {
8897 /* 8MB for 32bit, 1GB for 64bit */
8898 if (is_32bit_task())
8899 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8900 return rnd << PAGE_SHIFT;
8901 }
8902
8903 -static inline unsigned long mmap_base(void)
8904 +static inline unsigned long mmap_base(struct mm_struct *mm)
8905 {
8906 unsigned long gap = rlimit(RLIMIT_STACK);
8907
8908 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8909 else if (gap > MAX_GAP)
8910 gap = MAX_GAP;
8911
8912 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8913 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8914 }
8915
8916 /*
8917 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8918 */
8919 if (mmap_is_legacy()) {
8920 mm->mmap_base = TASK_UNMAPPED_BASE;
8921 +
8922 +#ifdef CONFIG_PAX_RANDMMAP
8923 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8924 + mm->mmap_base += mm->delta_mmap;
8925 +#endif
8926 +
8927 mm->get_unmapped_area = arch_get_unmapped_area;
8928 } else {
8929 - mm->mmap_base = mmap_base();
8930 + mm->mmap_base = mmap_base(mm);
8931 +
8932 +#ifdef CONFIG_PAX_RANDMMAP
8933 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8934 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8935 +#endif
8936 +
8937 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8938 }
8939 }
8940 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8941 index 7ce9cf3..a964087 100644
8942 --- a/arch/powerpc/mm/slice.c
8943 +++ b/arch/powerpc/mm/slice.c
8944 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8945 if ((mm->task_size - len) < addr)
8946 return 0;
8947 vma = find_vma(mm, addr);
8948 - return (!vma || (addr + len) <= vma->vm_start);
8949 + return check_heap_stack_gap(vma, addr, len, 0);
8950 }
8951
8952 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8953 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8954 info.align_offset = 0;
8955
8956 addr = TASK_UNMAPPED_BASE;
8957 +
8958 +#ifdef CONFIG_PAX_RANDMMAP
8959 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8960 + addr += mm->delta_mmap;
8961 +#endif
8962 +
8963 while (addr < TASK_SIZE) {
8964 info.low_limit = addr;
8965 if (!slice_scan_available(addr, available, 1, &addr))
8966 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8967 if (fixed && addr > (mm->task_size - len))
8968 return -EINVAL;
8969
8970 +#ifdef CONFIG_PAX_RANDMMAP
8971 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8972 + addr = 0;
8973 +#endif
8974 +
8975 /* If hint, make sure it matches our alignment restrictions */
8976 if (!fixed && addr) {
8977 addr = _ALIGN_UP(addr, 1ul << pshift);
8978 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8979 index 4278acf..67fd0e6 100644
8980 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8981 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8982 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8983 }
8984
8985 static struct pci_ops scc_pciex_pci_ops = {
8986 - scc_pciex_read_config,
8987 - scc_pciex_write_config,
8988 + .read = scc_pciex_read_config,
8989 + .write = scc_pciex_write_config,
8990 };
8991
8992 static void pciex_clear_intr_all(unsigned int __iomem *base)
8993 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8994 index 9098692..3d54cd1 100644
8995 --- a/arch/powerpc/platforms/cell/spufs/file.c
8996 +++ b/arch/powerpc/platforms/cell/spufs/file.c
8997 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8998 return VM_FAULT_NOPAGE;
8999 }
9000
9001 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9002 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9003 unsigned long address,
9004 - void *buf, int len, int write)
9005 + void *buf, size_t len, int write)
9006 {
9007 struct spu_context *ctx = vma->vm_file->private_data;
9008 unsigned long offset = address - vma->vm_start;
9009 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9010 index fa9aaf7..3f5d836 100644
9011 --- a/arch/s390/include/asm/atomic.h
9012 +++ b/arch/s390/include/asm/atomic.h
9013 @@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9014 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9015 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9016
9017 +#define atomic64_read_unchecked(v) atomic64_read(v)
9018 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9019 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9020 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9021 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9022 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9023 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9024 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9025 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9026 +
9027 #define smp_mb__before_atomic_dec() smp_mb()
9028 #define smp_mb__after_atomic_dec() smp_mb()
9029 #define smp_mb__before_atomic_inc() smp_mb()
9030 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9031 index 4d7ccac..d03d0ad 100644
9032 --- a/arch/s390/include/asm/cache.h
9033 +++ b/arch/s390/include/asm/cache.h
9034 @@ -9,8 +9,10 @@
9035 #ifndef __ARCH_S390_CACHE_H
9036 #define __ARCH_S390_CACHE_H
9037
9038 -#define L1_CACHE_BYTES 256
9039 +#include <linux/const.h>
9040 +
9041 #define L1_CACHE_SHIFT 8
9042 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9043 #define NET_SKB_PAD 32
9044
9045 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9046 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9047 index 78f4f87..598ce39 100644
9048 --- a/arch/s390/include/asm/elf.h
9049 +++ b/arch/s390/include/asm/elf.h
9050 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9051 the loader. We need to make sure that it is out of the way of the program
9052 that it will "exec", and that there is sufficient room for the brk. */
9053
9054 -extern unsigned long randomize_et_dyn(unsigned long base);
9055 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9056 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9057 +
9058 +#ifdef CONFIG_PAX_ASLR
9059 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9060 +
9061 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9062 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9063 +#endif
9064
9065 /* This yields a mask that user programs can use to figure out what
9066 instruction set this CPU supports. */
9067 @@ -222,9 +228,6 @@ struct linux_binprm;
9068 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9069 int arch_setup_additional_pages(struct linux_binprm *, int);
9070
9071 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9072 -#define arch_randomize_brk arch_randomize_brk
9073 -
9074 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9075
9076 #endif
9077 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9078 index c4a93d6..4d2a9b4 100644
9079 --- a/arch/s390/include/asm/exec.h
9080 +++ b/arch/s390/include/asm/exec.h
9081 @@ -7,6 +7,6 @@
9082 #ifndef __ASM_EXEC_H
9083 #define __ASM_EXEC_H
9084
9085 -extern unsigned long arch_align_stack(unsigned long sp);
9086 +#define arch_align_stack(x) ((x) & ~0xfUL)
9087
9088 #endif /* __ASM_EXEC_H */
9089 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9090 index 79330af..254cf37 100644
9091 --- a/arch/s390/include/asm/uaccess.h
9092 +++ b/arch/s390/include/asm/uaccess.h
9093 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9094 __range_ok((unsigned long)(addr), (size)); \
9095 })
9096
9097 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9098 #define access_ok(type, addr, size) __access_ok(addr, size)
9099
9100 /*
9101 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9102 copy_to_user(void __user *to, const void *from, unsigned long n)
9103 {
9104 might_fault();
9105 +
9106 + if ((long)n < 0)
9107 + return n;
9108 +
9109 return __copy_to_user(to, from, n);
9110 }
9111
9112 @@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9113 static inline unsigned long __must_check
9114 __copy_from_user(void *to, const void __user *from, unsigned long n)
9115 {
9116 + if ((long)n < 0)
9117 + return n;
9118 +
9119 return uaccess.copy_from_user(n, from, to);
9120 }
9121
9122 @@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9123 static inline unsigned long __must_check
9124 copy_from_user(void *to, const void __user *from, unsigned long n)
9125 {
9126 - unsigned int sz = __compiletime_object_size(to);
9127 + size_t sz = __compiletime_object_size(to);
9128
9129 might_fault();
9130 - if (unlikely(sz != -1 && sz < n)) {
9131 +
9132 + if ((long)n < 0)
9133 + return n;
9134 +
9135 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9136 copy_from_user_overflow();
9137 return n;
9138 }
9139 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9140 index b89b591..fd9609d 100644
9141 --- a/arch/s390/kernel/module.c
9142 +++ b/arch/s390/kernel/module.c
9143 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9144
9145 /* Increase core size by size of got & plt and set start
9146 offsets for got and plt. */
9147 - me->core_size = ALIGN(me->core_size, 4);
9148 - me->arch.got_offset = me->core_size;
9149 - me->core_size += me->arch.got_size;
9150 - me->arch.plt_offset = me->core_size;
9151 - me->core_size += me->arch.plt_size;
9152 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9153 + me->arch.got_offset = me->core_size_rw;
9154 + me->core_size_rw += me->arch.got_size;
9155 + me->arch.plt_offset = me->core_size_rx;
9156 + me->core_size_rx += me->arch.plt_size;
9157 return 0;
9158 }
9159
9160 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9161 if (info->got_initialized == 0) {
9162 Elf_Addr *gotent;
9163
9164 - gotent = me->module_core + me->arch.got_offset +
9165 + gotent = me->module_core_rw + me->arch.got_offset +
9166 info->got_offset;
9167 *gotent = val;
9168 info->got_initialized = 1;
9169 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9170 rc = apply_rela_bits(loc, val, 0, 64, 0);
9171 else if (r_type == R_390_GOTENT ||
9172 r_type == R_390_GOTPLTENT) {
9173 - val += (Elf_Addr) me->module_core - loc;
9174 + val += (Elf_Addr) me->module_core_rw - loc;
9175 rc = apply_rela_bits(loc, val, 1, 32, 1);
9176 }
9177 break;
9178 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9179 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9180 if (info->plt_initialized == 0) {
9181 unsigned int *ip;
9182 - ip = me->module_core + me->arch.plt_offset +
9183 + ip = me->module_core_rx + me->arch.plt_offset +
9184 info->plt_offset;
9185 #ifndef CONFIG_64BIT
9186 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9187 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9188 val - loc + 0xffffUL < 0x1ffffeUL) ||
9189 (r_type == R_390_PLT32DBL &&
9190 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9191 - val = (Elf_Addr) me->module_core +
9192 + val = (Elf_Addr) me->module_core_rx +
9193 me->arch.plt_offset +
9194 info->plt_offset;
9195 val += rela->r_addend - loc;
9196 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9197 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9198 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9199 val = val + rela->r_addend -
9200 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9201 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9202 if (r_type == R_390_GOTOFF16)
9203 rc = apply_rela_bits(loc, val, 0, 16, 0);
9204 else if (r_type == R_390_GOTOFF32)
9205 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9206 break;
9207 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9208 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9209 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9210 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9211 rela->r_addend - loc;
9212 if (r_type == R_390_GOTPC)
9213 rc = apply_rela_bits(loc, val, 1, 32, 0);
9214 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9215 index 7ed0d4e..1dfc145 100644
9216 --- a/arch/s390/kernel/process.c
9217 +++ b/arch/s390/kernel/process.c
9218 @@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9219 }
9220 return 0;
9221 }
9222 -
9223 -unsigned long arch_align_stack(unsigned long sp)
9224 -{
9225 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9226 - sp -= get_random_int() & ~PAGE_MASK;
9227 - return sp & ~0xf;
9228 -}
9229 -
9230 -static inline unsigned long brk_rnd(void)
9231 -{
9232 - /* 8MB for 32bit, 1GB for 64bit */
9233 - if (is_32bit_task())
9234 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9235 - else
9236 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9237 -}
9238 -
9239 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9240 -{
9241 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
9242 -
9243 - if (ret < mm->brk)
9244 - return mm->brk;
9245 - return ret;
9246 -}
9247 -
9248 -unsigned long randomize_et_dyn(unsigned long base)
9249 -{
9250 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9251 -
9252 - if (!(current->flags & PF_RANDOMIZE))
9253 - return base;
9254 - if (ret < base)
9255 - return base;
9256 - return ret;
9257 -}
9258 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9259 index 9b436c2..54fbf0a 100644
9260 --- a/arch/s390/mm/mmap.c
9261 +++ b/arch/s390/mm/mmap.c
9262 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9263 */
9264 if (mmap_is_legacy()) {
9265 mm->mmap_base = mmap_base_legacy();
9266 +
9267 +#ifdef CONFIG_PAX_RANDMMAP
9268 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9269 + mm->mmap_base += mm->delta_mmap;
9270 +#endif
9271 +
9272 mm->get_unmapped_area = arch_get_unmapped_area;
9273 } else {
9274 mm->mmap_base = mmap_base();
9275 +
9276 +#ifdef CONFIG_PAX_RANDMMAP
9277 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9278 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9279 +#endif
9280 +
9281 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9282 }
9283 }
9284 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9285 */
9286 if (mmap_is_legacy()) {
9287 mm->mmap_base = mmap_base_legacy();
9288 +
9289 +#ifdef CONFIG_PAX_RANDMMAP
9290 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9291 + mm->mmap_base += mm->delta_mmap;
9292 +#endif
9293 +
9294 mm->get_unmapped_area = s390_get_unmapped_area;
9295 } else {
9296 mm->mmap_base = mmap_base();
9297 +
9298 +#ifdef CONFIG_PAX_RANDMMAP
9299 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9300 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9301 +#endif
9302 +
9303 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9304 }
9305 }
9306 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9307 index ae3d59f..f65f075 100644
9308 --- a/arch/score/include/asm/cache.h
9309 +++ b/arch/score/include/asm/cache.h
9310 @@ -1,7 +1,9 @@
9311 #ifndef _ASM_SCORE_CACHE_H
9312 #define _ASM_SCORE_CACHE_H
9313
9314 +#include <linux/const.h>
9315 +
9316 #define L1_CACHE_SHIFT 4
9317 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9318 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9319
9320 #endif /* _ASM_SCORE_CACHE_H */
9321 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9322 index f9f3cd5..58ff438 100644
9323 --- a/arch/score/include/asm/exec.h
9324 +++ b/arch/score/include/asm/exec.h
9325 @@ -1,6 +1,6 @@
9326 #ifndef _ASM_SCORE_EXEC_H
9327 #define _ASM_SCORE_EXEC_H
9328
9329 -extern unsigned long arch_align_stack(unsigned long sp);
9330 +#define arch_align_stack(x) (x)
9331
9332 #endif /* _ASM_SCORE_EXEC_H */
9333 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9334 index a1519ad3..e8ac1ff 100644
9335 --- a/arch/score/kernel/process.c
9336 +++ b/arch/score/kernel/process.c
9337 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9338
9339 return task_pt_regs(task)->cp0_epc;
9340 }
9341 -
9342 -unsigned long arch_align_stack(unsigned long sp)
9343 -{
9344 - return sp;
9345 -}
9346 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9347 index ef9e555..331bd29 100644
9348 --- a/arch/sh/include/asm/cache.h
9349 +++ b/arch/sh/include/asm/cache.h
9350 @@ -9,10 +9,11 @@
9351 #define __ASM_SH_CACHE_H
9352 #ifdef __KERNEL__
9353
9354 +#include <linux/const.h>
9355 #include <linux/init.h>
9356 #include <cpu/cache.h>
9357
9358 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9359 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9360
9361 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9362
9363 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9364 index 6777177..cb5e44f 100644
9365 --- a/arch/sh/mm/mmap.c
9366 +++ b/arch/sh/mm/mmap.c
9367 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9368 struct mm_struct *mm = current->mm;
9369 struct vm_area_struct *vma;
9370 int do_colour_align;
9371 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9372 struct vm_unmapped_area_info info;
9373
9374 if (flags & MAP_FIXED) {
9375 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9376 if (filp || (flags & MAP_SHARED))
9377 do_colour_align = 1;
9378
9379 +#ifdef CONFIG_PAX_RANDMMAP
9380 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9381 +#endif
9382 +
9383 if (addr) {
9384 if (do_colour_align)
9385 addr = COLOUR_ALIGN(addr, pgoff);
9386 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9387 addr = PAGE_ALIGN(addr);
9388
9389 vma = find_vma(mm, addr);
9390 - if (TASK_SIZE - len >= addr &&
9391 - (!vma || addr + len <= vma->vm_start))
9392 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9393 return addr;
9394 }
9395
9396 info.flags = 0;
9397 info.length = len;
9398 - info.low_limit = TASK_UNMAPPED_BASE;
9399 + info.low_limit = mm->mmap_base;
9400 info.high_limit = TASK_SIZE;
9401 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9402 info.align_offset = pgoff << PAGE_SHIFT;
9403 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9404 struct mm_struct *mm = current->mm;
9405 unsigned long addr = addr0;
9406 int do_colour_align;
9407 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9408 struct vm_unmapped_area_info info;
9409
9410 if (flags & MAP_FIXED) {
9411 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9412 if (filp || (flags & MAP_SHARED))
9413 do_colour_align = 1;
9414
9415 +#ifdef CONFIG_PAX_RANDMMAP
9416 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9417 +#endif
9418 +
9419 /* requesting a specific address */
9420 if (addr) {
9421 if (do_colour_align)
9422 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9423 addr = PAGE_ALIGN(addr);
9424
9425 vma = find_vma(mm, addr);
9426 - if (TASK_SIZE - len >= addr &&
9427 - (!vma || addr + len <= vma->vm_start))
9428 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9429 return addr;
9430 }
9431
9432 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9433 VM_BUG_ON(addr != -ENOMEM);
9434 info.flags = 0;
9435 info.low_limit = TASK_UNMAPPED_BASE;
9436 +
9437 +#ifdef CONFIG_PAX_RANDMMAP
9438 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9439 + info.low_limit += mm->delta_mmap;
9440 +#endif
9441 +
9442 info.high_limit = TASK_SIZE;
9443 addr = vm_unmapped_area(&info);
9444 }
9445 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9446 index be56a24..443328f 100644
9447 --- a/arch/sparc/include/asm/atomic_64.h
9448 +++ b/arch/sparc/include/asm/atomic_64.h
9449 @@ -14,18 +14,40 @@
9450 #define ATOMIC64_INIT(i) { (i) }
9451
9452 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9453 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9454 +{
9455 + return v->counter;
9456 +}
9457 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9458 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9459 +{
9460 + return v->counter;
9461 +}
9462
9463 #define atomic_set(v, i) (((v)->counter) = i)
9464 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9465 +{
9466 + v->counter = i;
9467 +}
9468 #define atomic64_set(v, i) (((v)->counter) = i)
9469 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9470 +{
9471 + v->counter = i;
9472 +}
9473
9474 extern void atomic_add(int, atomic_t *);
9475 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9476 extern void atomic64_add(long, atomic64_t *);
9477 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9478 extern void atomic_sub(int, atomic_t *);
9479 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9480 extern void atomic64_sub(long, atomic64_t *);
9481 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9482
9483 extern int atomic_add_ret(int, atomic_t *);
9484 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9485 extern long atomic64_add_ret(long, atomic64_t *);
9486 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9487 extern int atomic_sub_ret(int, atomic_t *);
9488 extern long atomic64_sub_ret(long, atomic64_t *);
9489
9490 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9491 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9492
9493 #define atomic_inc_return(v) atomic_add_ret(1, v)
9494 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9495 +{
9496 + return atomic_add_ret_unchecked(1, v);
9497 +}
9498 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9499 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9500 +{
9501 + return atomic64_add_ret_unchecked(1, v);
9502 +}
9503
9504 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9505 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9506
9507 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9508 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9509 +{
9510 + return atomic_add_ret_unchecked(i, v);
9511 +}
9512 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9513 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9514 +{
9515 + return atomic64_add_ret_unchecked(i, v);
9516 +}
9517
9518 /*
9519 * atomic_inc_and_test - increment and test
9520 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9521 * other cases.
9522 */
9523 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9524 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9525 +{
9526 + return atomic_inc_return_unchecked(v) == 0;
9527 +}
9528 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9529
9530 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9531 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9532 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9533
9534 #define atomic_inc(v) atomic_add(1, v)
9535 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9536 +{
9537 + atomic_add_unchecked(1, v);
9538 +}
9539 #define atomic64_inc(v) atomic64_add(1, v)
9540 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9541 +{
9542 + atomic64_add_unchecked(1, v);
9543 +}
9544
9545 #define atomic_dec(v) atomic_sub(1, v)
9546 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9547 +{
9548 + atomic_sub_unchecked(1, v);
9549 +}
9550 #define atomic64_dec(v) atomic64_sub(1, v)
9551 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9552 +{
9553 + atomic64_sub_unchecked(1, v);
9554 +}
9555
9556 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9557 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9558
9559 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9560 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9561 +{
9562 + return cmpxchg(&v->counter, old, new);
9563 +}
9564 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9565 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9566 +{
9567 + return xchg(&v->counter, new);
9568 +}
9569
9570 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9571 {
9572 - int c, old;
9573 + int c, old, new;
9574 c = atomic_read(v);
9575 for (;;) {
9576 - if (unlikely(c == (u)))
9577 + if (unlikely(c == u))
9578 break;
9579 - old = atomic_cmpxchg((v), c, c + (a));
9580 +
9581 + asm volatile("addcc %2, %0, %0\n"
9582 +
9583 +#ifdef CONFIG_PAX_REFCOUNT
9584 + "tvs %%icc, 6\n"
9585 +#endif
9586 +
9587 + : "=r" (new)
9588 + : "0" (c), "ir" (a)
9589 + : "cc");
9590 +
9591 + old = atomic_cmpxchg(v, c, new);
9592 if (likely(old == c))
9593 break;
9594 c = old;
9595 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9596 #define atomic64_cmpxchg(v, o, n) \
9597 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9598 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9599 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9600 +{
9601 + return xchg(&v->counter, new);
9602 +}
9603
9604 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9605 {
9606 - long c, old;
9607 + long c, old, new;
9608 c = atomic64_read(v);
9609 for (;;) {
9610 - if (unlikely(c == (u)))
9611 + if (unlikely(c == u))
9612 break;
9613 - old = atomic64_cmpxchg((v), c, c + (a));
9614 +
9615 + asm volatile("addcc %2, %0, %0\n"
9616 +
9617 +#ifdef CONFIG_PAX_REFCOUNT
9618 + "tvs %%xcc, 6\n"
9619 +#endif
9620 +
9621 + : "=r" (new)
9622 + : "0" (c), "ir" (a)
9623 + : "cc");
9624 +
9625 + old = atomic64_cmpxchg(v, c, new);
9626 if (likely(old == c))
9627 break;
9628 c = old;
9629 }
9630 - return c != (u);
9631 + return c != u;
9632 }
9633
9634 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9635 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9636 index 5bb6991..5c2132e 100644
9637 --- a/arch/sparc/include/asm/cache.h
9638 +++ b/arch/sparc/include/asm/cache.h
9639 @@ -7,10 +7,12 @@
9640 #ifndef _SPARC_CACHE_H
9641 #define _SPARC_CACHE_H
9642
9643 +#include <linux/const.h>
9644 +
9645 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9646
9647 #define L1_CACHE_SHIFT 5
9648 -#define L1_CACHE_BYTES 32
9649 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9650
9651 #ifdef CONFIG_SPARC32
9652 #define SMP_CACHE_BYTES_SHIFT 5
9653 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9654 index a24e41f..47677ff 100644
9655 --- a/arch/sparc/include/asm/elf_32.h
9656 +++ b/arch/sparc/include/asm/elf_32.h
9657 @@ -114,6 +114,13 @@ typedef struct {
9658
9659 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9660
9661 +#ifdef CONFIG_PAX_ASLR
9662 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9663 +
9664 +#define PAX_DELTA_MMAP_LEN 16
9665 +#define PAX_DELTA_STACK_LEN 16
9666 +#endif
9667 +
9668 /* This yields a mask that user programs can use to figure out what
9669 instruction set this cpu supports. This can NOT be done in userspace
9670 on Sparc. */
9671 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9672 index 370ca1e..d4f4a98 100644
9673 --- a/arch/sparc/include/asm/elf_64.h
9674 +++ b/arch/sparc/include/asm/elf_64.h
9675 @@ -189,6 +189,13 @@ typedef struct {
9676 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9677 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9678
9679 +#ifdef CONFIG_PAX_ASLR
9680 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9681 +
9682 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9683 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9684 +#endif
9685 +
9686 extern unsigned long sparc64_elf_hwcap;
9687 #define ELF_HWCAP sparc64_elf_hwcap
9688
9689 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9690 index 9b1c36d..209298b 100644
9691 --- a/arch/sparc/include/asm/pgalloc_32.h
9692 +++ b/arch/sparc/include/asm/pgalloc_32.h
9693 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9694 }
9695
9696 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9697 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9698
9699 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9700 unsigned long address)
9701 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9702 index bcfe063..b333142 100644
9703 --- a/arch/sparc/include/asm/pgalloc_64.h
9704 +++ b/arch/sparc/include/asm/pgalloc_64.h
9705 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9706 }
9707
9708 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9709 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9710
9711 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9712 {
9713 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9714 index 59ba6f6..4518128 100644
9715 --- a/arch/sparc/include/asm/pgtable.h
9716 +++ b/arch/sparc/include/asm/pgtable.h
9717 @@ -5,4 +5,8 @@
9718 #else
9719 #include <asm/pgtable_32.h>
9720 #endif
9721 +
9722 +#define ktla_ktva(addr) (addr)
9723 +#define ktva_ktla(addr) (addr)
9724 +
9725 #endif
9726 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9727 index 502f632..da1917f 100644
9728 --- a/arch/sparc/include/asm/pgtable_32.h
9729 +++ b/arch/sparc/include/asm/pgtable_32.h
9730 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9731 #define PAGE_SHARED SRMMU_PAGE_SHARED
9732 #define PAGE_COPY SRMMU_PAGE_COPY
9733 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9734 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9735 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9736 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9737 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9738
9739 /* Top-level page directory - dummy used by init-mm.
9740 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9741
9742 /* xwr */
9743 #define __P000 PAGE_NONE
9744 -#define __P001 PAGE_READONLY
9745 -#define __P010 PAGE_COPY
9746 -#define __P011 PAGE_COPY
9747 +#define __P001 PAGE_READONLY_NOEXEC
9748 +#define __P010 PAGE_COPY_NOEXEC
9749 +#define __P011 PAGE_COPY_NOEXEC
9750 #define __P100 PAGE_READONLY
9751 #define __P101 PAGE_READONLY
9752 #define __P110 PAGE_COPY
9753 #define __P111 PAGE_COPY
9754
9755 #define __S000 PAGE_NONE
9756 -#define __S001 PAGE_READONLY
9757 -#define __S010 PAGE_SHARED
9758 -#define __S011 PAGE_SHARED
9759 +#define __S001 PAGE_READONLY_NOEXEC
9760 +#define __S010 PAGE_SHARED_NOEXEC
9761 +#define __S011 PAGE_SHARED_NOEXEC
9762 #define __S100 PAGE_READONLY
9763 #define __S101 PAGE_READONLY
9764 #define __S110 PAGE_SHARED
9765 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9766 index 79da178..c2eede8 100644
9767 --- a/arch/sparc/include/asm/pgtsrmmu.h
9768 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9769 @@ -115,6 +115,11 @@
9770 SRMMU_EXEC | SRMMU_REF)
9771 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9772 SRMMU_EXEC | SRMMU_REF)
9773 +
9774 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9775 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9776 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9777 +
9778 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9779 SRMMU_DIRTY | SRMMU_REF)
9780
9781 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9782 index 9689176..63c18ea 100644
9783 --- a/arch/sparc/include/asm/spinlock_64.h
9784 +++ b/arch/sparc/include/asm/spinlock_64.h
9785 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9786
9787 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9788
9789 -static void inline arch_read_lock(arch_rwlock_t *lock)
9790 +static inline void arch_read_lock(arch_rwlock_t *lock)
9791 {
9792 unsigned long tmp1, tmp2;
9793
9794 __asm__ __volatile__ (
9795 "1: ldsw [%2], %0\n"
9796 " brlz,pn %0, 2f\n"
9797 -"4: add %0, 1, %1\n"
9798 +"4: addcc %0, 1, %1\n"
9799 +
9800 +#ifdef CONFIG_PAX_REFCOUNT
9801 +" tvs %%icc, 6\n"
9802 +#endif
9803 +
9804 " cas [%2], %0, %1\n"
9805 " cmp %0, %1\n"
9806 " bne,pn %%icc, 1b\n"
9807 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9808 " .previous"
9809 : "=&r" (tmp1), "=&r" (tmp2)
9810 : "r" (lock)
9811 - : "memory");
9812 + : "memory", "cc");
9813 }
9814
9815 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9816 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9817 {
9818 int tmp1, tmp2;
9819
9820 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9821 "1: ldsw [%2], %0\n"
9822 " brlz,a,pn %0, 2f\n"
9823 " mov 0, %0\n"
9824 -" add %0, 1, %1\n"
9825 +" addcc %0, 1, %1\n"
9826 +
9827 +#ifdef CONFIG_PAX_REFCOUNT
9828 +" tvs %%icc, 6\n"
9829 +#endif
9830 +
9831 " cas [%2], %0, %1\n"
9832 " cmp %0, %1\n"
9833 " bne,pn %%icc, 1b\n"
9834 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9835 return tmp1;
9836 }
9837
9838 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9839 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9840 {
9841 unsigned long tmp1, tmp2;
9842
9843 __asm__ __volatile__(
9844 "1: lduw [%2], %0\n"
9845 -" sub %0, 1, %1\n"
9846 +" subcc %0, 1, %1\n"
9847 +
9848 +#ifdef CONFIG_PAX_REFCOUNT
9849 +" tvs %%icc, 6\n"
9850 +#endif
9851 +
9852 " cas [%2], %0, %1\n"
9853 " cmp %0, %1\n"
9854 " bne,pn %%xcc, 1b\n"
9855 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9856 : "memory");
9857 }
9858
9859 -static void inline arch_write_lock(arch_rwlock_t *lock)
9860 +static inline void arch_write_lock(arch_rwlock_t *lock)
9861 {
9862 unsigned long mask, tmp1, tmp2;
9863
9864 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9865 : "memory");
9866 }
9867
9868 -static void inline arch_write_unlock(arch_rwlock_t *lock)
9869 +static inline void arch_write_unlock(arch_rwlock_t *lock)
9870 {
9871 __asm__ __volatile__(
9872 " stw %%g0, [%0]"
9873 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9874 : "memory");
9875 }
9876
9877 -static int inline arch_write_trylock(arch_rwlock_t *lock)
9878 +static inline int arch_write_trylock(arch_rwlock_t *lock)
9879 {
9880 unsigned long mask, tmp1, tmp2, result;
9881
9882 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9883 index 96efa7a..16858bf 100644
9884 --- a/arch/sparc/include/asm/thread_info_32.h
9885 +++ b/arch/sparc/include/asm/thread_info_32.h
9886 @@ -49,6 +49,8 @@ struct thread_info {
9887 unsigned long w_saved;
9888
9889 struct restart_block restart_block;
9890 +
9891 + unsigned long lowest_stack;
9892 };
9893
9894 /*
9895 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9896 index a5f01ac..703b554 100644
9897 --- a/arch/sparc/include/asm/thread_info_64.h
9898 +++ b/arch/sparc/include/asm/thread_info_64.h
9899 @@ -63,6 +63,8 @@ struct thread_info {
9900 struct pt_regs *kern_una_regs;
9901 unsigned int kern_una_insn;
9902
9903 + unsigned long lowest_stack;
9904 +
9905 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9906 };
9907
9908 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9909 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9910 /* flag bit 4 is available */
9911 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9912 -/* flag bit 6 is available */
9913 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9914 #define TIF_32BIT 7 /* 32-bit binary */
9915 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9916 #define TIF_SECCOMP 9 /* secure computing */
9917 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9918 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9919 +
9920 /* NOTE: Thread flags >= 12 should be ones we have no interest
9921 * in using in assembly, else we can't use the mask as
9922 * an immediate value in instructions such as andcc.
9923 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9924 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9925 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9926 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9927 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9928
9929 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9930 _TIF_DO_NOTIFY_RESUME_MASK | \
9931 _TIF_NEED_RESCHED)
9932 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9933
9934 +#define _TIF_WORK_SYSCALL \
9935 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9936 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9937 +
9938 +
9939 /*
9940 * Thread-synchronous status.
9941 *
9942 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9943 index 0167d26..767bb0c 100644
9944 --- a/arch/sparc/include/asm/uaccess.h
9945 +++ b/arch/sparc/include/asm/uaccess.h
9946 @@ -1,5 +1,6 @@
9947 #ifndef ___ASM_SPARC_UACCESS_H
9948 #define ___ASM_SPARC_UACCESS_H
9949 +
9950 #if defined(__sparc__) && defined(__arch64__)
9951 #include <asm/uaccess_64.h>
9952 #else
9953 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9954 index 53a28dd..50c38c3 100644
9955 --- a/arch/sparc/include/asm/uaccess_32.h
9956 +++ b/arch/sparc/include/asm/uaccess_32.h
9957 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9958
9959 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9960 {
9961 - if (n && __access_ok((unsigned long) to, n))
9962 + if ((long)n < 0)
9963 + return n;
9964 +
9965 + if (n && __access_ok((unsigned long) to, n)) {
9966 + if (!__builtin_constant_p(n))
9967 + check_object_size(from, n, true);
9968 return __copy_user(to, (__force void __user *) from, n);
9969 - else
9970 + } else
9971 return n;
9972 }
9973
9974 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9975 {
9976 + if ((long)n < 0)
9977 + return n;
9978 +
9979 + if (!__builtin_constant_p(n))
9980 + check_object_size(from, n, true);
9981 +
9982 return __copy_user(to, (__force void __user *) from, n);
9983 }
9984
9985 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9986 {
9987 - if (n && __access_ok((unsigned long) from, n))
9988 + if ((long)n < 0)
9989 + return n;
9990 +
9991 + if (n && __access_ok((unsigned long) from, n)) {
9992 + if (!__builtin_constant_p(n))
9993 + check_object_size(to, n, false);
9994 return __copy_user((__force void __user *) to, from, n);
9995 - else
9996 + } else
9997 return n;
9998 }
9999
10000 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10001 {
10002 + if ((long)n < 0)
10003 + return n;
10004 +
10005 return __copy_user((__force void __user *) to, from, n);
10006 }
10007
10008 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10009 index ad7e178..c9e7423 100644
10010 --- a/arch/sparc/include/asm/uaccess_64.h
10011 +++ b/arch/sparc/include/asm/uaccess_64.h
10012 @@ -10,6 +10,7 @@
10013 #include <linux/compiler.h>
10014 #include <linux/string.h>
10015 #include <linux/thread_info.h>
10016 +#include <linux/kernel.h>
10017 #include <asm/asi.h>
10018 #include <asm/spitfire.h>
10019 #include <asm-generic/uaccess-unaligned.h>
10020 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10021 static inline unsigned long __must_check
10022 copy_from_user(void *to, const void __user *from, unsigned long size)
10023 {
10024 - unsigned long ret = ___copy_from_user(to, from, size);
10025 + unsigned long ret;
10026
10027 + if ((long)size < 0 || size > INT_MAX)
10028 + return size;
10029 +
10030 + if (!__builtin_constant_p(size))
10031 + check_object_size(to, size, false);
10032 +
10033 + ret = ___copy_from_user(to, from, size);
10034 if (unlikely(ret))
10035 ret = copy_from_user_fixup(to, from, size);
10036
10037 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10038 static inline unsigned long __must_check
10039 copy_to_user(void __user *to, const void *from, unsigned long size)
10040 {
10041 - unsigned long ret = ___copy_to_user(to, from, size);
10042 + unsigned long ret;
10043
10044 + if ((long)size < 0 || size > INT_MAX)
10045 + return size;
10046 +
10047 + if (!__builtin_constant_p(size))
10048 + check_object_size(from, size, true);
10049 +
10050 + ret = ___copy_to_user(to, from, size);
10051 if (unlikely(ret))
10052 ret = copy_to_user_fixup(to, from, size);
10053 return ret;
10054 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10055 index d15cc17..d0ae796 100644
10056 --- a/arch/sparc/kernel/Makefile
10057 +++ b/arch/sparc/kernel/Makefile
10058 @@ -4,7 +4,7 @@
10059 #
10060
10061 asflags-y := -ansi
10062 -ccflags-y := -Werror
10063 +#ccflags-y := -Werror
10064
10065 extra-y := head_$(BITS).o
10066
10067 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10068 index fdd819d..5af08c8 100644
10069 --- a/arch/sparc/kernel/process_32.c
10070 +++ b/arch/sparc/kernel/process_32.c
10071 @@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
10072
10073 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10074 r->psr, r->pc, r->npc, r->y, print_tainted());
10075 - printk("PC: <%pS>\n", (void *) r->pc);
10076 + printk("PC: <%pA>\n", (void *) r->pc);
10077 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10078 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10079 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10080 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10081 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10082 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10083 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10084 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10085
10086 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10087 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10088 @@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10089 rw = (struct reg_window32 *) fp;
10090 pc = rw->ins[7];
10091 printk("[%08lx : ", pc);
10092 - printk("%pS ] ", (void *) pc);
10093 + printk("%pA ] ", (void *) pc);
10094 fp = rw->ins[6];
10095 } while (++count < 16);
10096 printk("\n");
10097 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10098 index 32a280e..84fc6a9 100644
10099 --- a/arch/sparc/kernel/process_64.c
10100 +++ b/arch/sparc/kernel/process_64.c
10101 @@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
10102 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10103 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10104 if (regs->tstate & TSTATE_PRIV)
10105 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10106 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10107 }
10108
10109 void show_regs(struct pt_regs *regs)
10110 @@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
10111
10112 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10113 regs->tpc, regs->tnpc, regs->y, print_tainted());
10114 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10115 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10116 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10117 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10118 regs->u_regs[3]);
10119 @@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
10120 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10121 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10122 regs->u_regs[15]);
10123 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10124 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10125 show_regwindow(regs);
10126 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10127 }
10128 @@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
10129 ((tp && tp->task) ? tp->task->pid : -1));
10130
10131 if (gp->tstate & TSTATE_PRIV) {
10132 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10133 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10134 (void *) gp->tpc,
10135 (void *) gp->o7,
10136 (void *) gp->i7,
10137 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10138 index 79cc0d1..ec62734 100644
10139 --- a/arch/sparc/kernel/prom_common.c
10140 +++ b/arch/sparc/kernel/prom_common.c
10141 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10142
10143 unsigned int prom_early_allocated __initdata;
10144
10145 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10146 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10147 .nextprop = prom_common_nextprop,
10148 .getproplen = prom_getproplen,
10149 .getproperty = prom_getproperty,
10150 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10151 index c13c9f2..d572c34 100644
10152 --- a/arch/sparc/kernel/ptrace_64.c
10153 +++ b/arch/sparc/kernel/ptrace_64.c
10154 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10155 return ret;
10156 }
10157
10158 +#ifdef CONFIG_GRKERNSEC_SETXID
10159 +extern void gr_delayed_cred_worker(void);
10160 +#endif
10161 +
10162 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10163 {
10164 int ret = 0;
10165 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10166 if (test_thread_flag(TIF_NOHZ))
10167 user_exit();
10168
10169 +#ifdef CONFIG_GRKERNSEC_SETXID
10170 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10171 + gr_delayed_cred_worker();
10172 +#endif
10173 +
10174 if (test_thread_flag(TIF_SYSCALL_TRACE))
10175 ret = tracehook_report_syscall_entry(regs);
10176
10177 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10178 if (test_thread_flag(TIF_NOHZ))
10179 user_exit();
10180
10181 +#ifdef CONFIG_GRKERNSEC_SETXID
10182 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10183 + gr_delayed_cred_worker();
10184 +#endif
10185 +
10186 audit_syscall_exit(regs);
10187
10188 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10189 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10190 index b085311..6f885f7 100644
10191 --- a/arch/sparc/kernel/smp_64.c
10192 +++ b/arch/sparc/kernel/smp_64.c
10193 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10194 extern unsigned long xcall_flush_dcache_page_spitfire;
10195
10196 #ifdef CONFIG_DEBUG_DCFLUSH
10197 -extern atomic_t dcpage_flushes;
10198 -extern atomic_t dcpage_flushes_xcall;
10199 +extern atomic_unchecked_t dcpage_flushes;
10200 +extern atomic_unchecked_t dcpage_flushes_xcall;
10201 #endif
10202
10203 static inline void __local_flush_dcache_page(struct page *page)
10204 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10205 return;
10206
10207 #ifdef CONFIG_DEBUG_DCFLUSH
10208 - atomic_inc(&dcpage_flushes);
10209 + atomic_inc_unchecked(&dcpage_flushes);
10210 #endif
10211
10212 this_cpu = get_cpu();
10213 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10214 xcall_deliver(data0, __pa(pg_addr),
10215 (u64) pg_addr, cpumask_of(cpu));
10216 #ifdef CONFIG_DEBUG_DCFLUSH
10217 - atomic_inc(&dcpage_flushes_xcall);
10218 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10219 #endif
10220 }
10221 }
10222 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10223 preempt_disable();
10224
10225 #ifdef CONFIG_DEBUG_DCFLUSH
10226 - atomic_inc(&dcpage_flushes);
10227 + atomic_inc_unchecked(&dcpage_flushes);
10228 #endif
10229 data0 = 0;
10230 pg_addr = page_address(page);
10231 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10232 xcall_deliver(data0, __pa(pg_addr),
10233 (u64) pg_addr, cpu_online_mask);
10234 #ifdef CONFIG_DEBUG_DCFLUSH
10235 - atomic_inc(&dcpage_flushes_xcall);
10236 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10237 #endif
10238 }
10239 __local_flush_dcache_page(page);
10240 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10241 index 3a8d184..49498a8 100644
10242 --- a/arch/sparc/kernel/sys_sparc_32.c
10243 +++ b/arch/sparc/kernel/sys_sparc_32.c
10244 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10245 if (len > TASK_SIZE - PAGE_SIZE)
10246 return -ENOMEM;
10247 if (!addr)
10248 - addr = TASK_UNMAPPED_BASE;
10249 + addr = current->mm->mmap_base;
10250
10251 info.flags = 0;
10252 info.length = len;
10253 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10254 index beb0b5a..5a153f7 100644
10255 --- a/arch/sparc/kernel/sys_sparc_64.c
10256 +++ b/arch/sparc/kernel/sys_sparc_64.c
10257 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10258 struct vm_area_struct * vma;
10259 unsigned long task_size = TASK_SIZE;
10260 int do_color_align;
10261 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10262 struct vm_unmapped_area_info info;
10263
10264 if (flags & MAP_FIXED) {
10265 /* We do not accept a shared mapping if it would violate
10266 * cache aliasing constraints.
10267 */
10268 - if ((flags & MAP_SHARED) &&
10269 + if ((filp || (flags & MAP_SHARED)) &&
10270 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10271 return -EINVAL;
10272 return addr;
10273 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10274 if (filp || (flags & MAP_SHARED))
10275 do_color_align = 1;
10276
10277 +#ifdef CONFIG_PAX_RANDMMAP
10278 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10279 +#endif
10280 +
10281 if (addr) {
10282 if (do_color_align)
10283 addr = COLOR_ALIGN(addr, pgoff);
10284 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10285 addr = PAGE_ALIGN(addr);
10286
10287 vma = find_vma(mm, addr);
10288 - if (task_size - len >= addr &&
10289 - (!vma || addr + len <= vma->vm_start))
10290 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10291 return addr;
10292 }
10293
10294 info.flags = 0;
10295 info.length = len;
10296 - info.low_limit = TASK_UNMAPPED_BASE;
10297 + info.low_limit = mm->mmap_base;
10298 info.high_limit = min(task_size, VA_EXCLUDE_START);
10299 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10300 info.align_offset = pgoff << PAGE_SHIFT;
10301 + info.threadstack_offset = offset;
10302 addr = vm_unmapped_area(&info);
10303
10304 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10305 VM_BUG_ON(addr != -ENOMEM);
10306 info.low_limit = VA_EXCLUDE_END;
10307 +
10308 +#ifdef CONFIG_PAX_RANDMMAP
10309 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10310 + info.low_limit += mm->delta_mmap;
10311 +#endif
10312 +
10313 info.high_limit = task_size;
10314 addr = vm_unmapped_area(&info);
10315 }
10316 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10317 unsigned long task_size = STACK_TOP32;
10318 unsigned long addr = addr0;
10319 int do_color_align;
10320 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10321 struct vm_unmapped_area_info info;
10322
10323 /* This should only ever run for 32-bit processes. */
10324 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10325 /* We do not accept a shared mapping if it would violate
10326 * cache aliasing constraints.
10327 */
10328 - if ((flags & MAP_SHARED) &&
10329 + if ((filp || (flags & MAP_SHARED)) &&
10330 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10331 return -EINVAL;
10332 return addr;
10333 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10334 if (filp || (flags & MAP_SHARED))
10335 do_color_align = 1;
10336
10337 +#ifdef CONFIG_PAX_RANDMMAP
10338 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10339 +#endif
10340 +
10341 /* requesting a specific address */
10342 if (addr) {
10343 if (do_color_align)
10344 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10345 addr = PAGE_ALIGN(addr);
10346
10347 vma = find_vma(mm, addr);
10348 - if (task_size - len >= addr &&
10349 - (!vma || addr + len <= vma->vm_start))
10350 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10351 return addr;
10352 }
10353
10354 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10355 info.high_limit = mm->mmap_base;
10356 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10357 info.align_offset = pgoff << PAGE_SHIFT;
10358 + info.threadstack_offset = offset;
10359 addr = vm_unmapped_area(&info);
10360
10361 /*
10362 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10363 VM_BUG_ON(addr != -ENOMEM);
10364 info.flags = 0;
10365 info.low_limit = TASK_UNMAPPED_BASE;
10366 +
10367 +#ifdef CONFIG_PAX_RANDMMAP
10368 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10369 + info.low_limit += mm->delta_mmap;
10370 +#endif
10371 +
10372 info.high_limit = STACK_TOP32;
10373 addr = vm_unmapped_area(&info);
10374 }
10375 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10376 EXPORT_SYMBOL(get_fb_unmapped_area);
10377
10378 /* Essentially the same as PowerPC. */
10379 -static unsigned long mmap_rnd(void)
10380 +static unsigned long mmap_rnd(struct mm_struct *mm)
10381 {
10382 unsigned long rnd = 0UL;
10383
10384 +#ifdef CONFIG_PAX_RANDMMAP
10385 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10386 +#endif
10387 +
10388 if (current->flags & PF_RANDOMIZE) {
10389 unsigned long val = get_random_int();
10390 if (test_thread_flag(TIF_32BIT))
10391 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10392
10393 void arch_pick_mmap_layout(struct mm_struct *mm)
10394 {
10395 - unsigned long random_factor = mmap_rnd();
10396 + unsigned long random_factor = mmap_rnd(mm);
10397 unsigned long gap;
10398
10399 /*
10400 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10401 gap == RLIM_INFINITY ||
10402 sysctl_legacy_va_layout) {
10403 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10404 +
10405 +#ifdef CONFIG_PAX_RANDMMAP
10406 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10407 + mm->mmap_base += mm->delta_mmap;
10408 +#endif
10409 +
10410 mm->get_unmapped_area = arch_get_unmapped_area;
10411 } else {
10412 /* We know it's 32-bit */
10413 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10414 gap = (task_size / 6 * 5);
10415
10416 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10417 +
10418 +#ifdef CONFIG_PAX_RANDMMAP
10419 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10420 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10421 +#endif
10422 +
10423 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10424 }
10425 }
10426 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10427 index 87729ff..d87fb1f 100644
10428 --- a/arch/sparc/kernel/syscalls.S
10429 +++ b/arch/sparc/kernel/syscalls.S
10430 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10431 #endif
10432 .align 32
10433 1: ldx [%g6 + TI_FLAGS], %l5
10434 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10435 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10436 be,pt %icc, rtrap
10437 nop
10438 call syscall_trace_leave
10439 @@ -184,12 +184,13 @@ linux_sparc_syscall32:
10440
10441 srl %i3, 0, %o3 ! IEU0
10442 srl %i2, 0, %o2 ! IEU0 Group
10443 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10444 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10445 bne,pn %icc, linux_syscall_trace32 ! CTI
10446 mov %i0, %l5 ! IEU1
10447 5: call %l7 ! CTI Group brk forced
10448 srl %i5, 0, %o5 ! IEU1
10449 - ba,a,pt %xcc, 3f
10450 + ba,pt %xcc, 3f
10451 + sra %o0, 0, %o0
10452
10453 /* Linux native system calls enter here... */
10454 .align 32
10455 @@ -207,7 +208,7 @@ linux_sparc_syscall:
10456
10457 mov %i3, %o3 ! IEU1
10458 mov %i4, %o4 ! IEU0 Group
10459 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10460 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10461 bne,pn %icc, linux_syscall_trace ! CTI Group
10462 mov %i0, %l5 ! IEU0
10463 2: call %l7 ! CTI Group brk forced
10464 @@ -217,13 +218,12 @@ linux_sparc_syscall:
10465 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
10466 ret_sys_call:
10467 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
10468 - sra %o0, 0, %o0
10469 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
10470 sllx %g2, 32, %g2
10471
10472 cmp %o0, -ERESTART_RESTARTBLOCK
10473 bgeu,pn %xcc, 1f
10474 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10475 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10476 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10477
10478 2:
10479 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10480 index 6629829..036032d 100644
10481 --- a/arch/sparc/kernel/traps_32.c
10482 +++ b/arch/sparc/kernel/traps_32.c
10483 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10484 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10485 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10486
10487 +extern void gr_handle_kernel_exploit(void);
10488 +
10489 void die_if_kernel(char *str, struct pt_regs *regs)
10490 {
10491 static int die_counter;
10492 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10493 count++ < 30 &&
10494 (((unsigned long) rw) >= PAGE_OFFSET) &&
10495 !(((unsigned long) rw) & 0x7)) {
10496 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10497 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10498 (void *) rw->ins[7]);
10499 rw = (struct reg_window32 *)rw->ins[6];
10500 }
10501 }
10502 printk("Instruction DUMP:");
10503 instruction_dump ((unsigned long *) regs->pc);
10504 - if(regs->psr & PSR_PS)
10505 + if(regs->psr & PSR_PS) {
10506 + gr_handle_kernel_exploit();
10507 do_exit(SIGKILL);
10508 + }
10509 do_exit(SIGSEGV);
10510 }
10511
10512 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10513 index 4ced92f..965eeed 100644
10514 --- a/arch/sparc/kernel/traps_64.c
10515 +++ b/arch/sparc/kernel/traps_64.c
10516 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10517 i + 1,
10518 p->trapstack[i].tstate, p->trapstack[i].tpc,
10519 p->trapstack[i].tnpc, p->trapstack[i].tt);
10520 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10521 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10522 }
10523 }
10524
10525 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10526
10527 lvl -= 0x100;
10528 if (regs->tstate & TSTATE_PRIV) {
10529 +
10530 +#ifdef CONFIG_PAX_REFCOUNT
10531 + if (lvl == 6)
10532 + pax_report_refcount_overflow(regs);
10533 +#endif
10534 +
10535 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10536 die_if_kernel(buffer, regs);
10537 }
10538 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10539 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10540 {
10541 char buffer[32];
10542 -
10543 +
10544 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10545 0, lvl, SIGTRAP) == NOTIFY_STOP)
10546 return;
10547
10548 +#ifdef CONFIG_PAX_REFCOUNT
10549 + if (lvl == 6)
10550 + pax_report_refcount_overflow(regs);
10551 +#endif
10552 +
10553 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10554
10555 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10556 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10557 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10558 printk("%s" "ERROR(%d): ",
10559 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10560 - printk("TPC<%pS>\n", (void *) regs->tpc);
10561 + printk("TPC<%pA>\n", (void *) regs->tpc);
10562 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10563 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10564 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10565 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10566 smp_processor_id(),
10567 (type & 0x1) ? 'I' : 'D',
10568 regs->tpc);
10569 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10570 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10571 panic("Irrecoverable Cheetah+ parity error.");
10572 }
10573
10574 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10575 smp_processor_id(),
10576 (type & 0x1) ? 'I' : 'D',
10577 regs->tpc);
10578 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10579 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10580 }
10581
10582 struct sun4v_error_entry {
10583 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10584 /*0x38*/u64 reserved_5;
10585 };
10586
10587 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10588 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10589 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10590 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10591
10592 static const char *sun4v_err_type_to_str(u8 type)
10593 {
10594 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10595 }
10596
10597 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10598 - int cpu, const char *pfx, atomic_t *ocnt)
10599 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10600 {
10601 u64 *raw_ptr = (u64 *) ent;
10602 u32 attrs;
10603 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10604
10605 show_regs(regs);
10606
10607 - if ((cnt = atomic_read(ocnt)) != 0) {
10608 - atomic_set(ocnt, 0);
10609 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10610 + atomic_set_unchecked(ocnt, 0);
10611 wmb();
10612 printk("%s: Queue overflowed %d times.\n",
10613 pfx, cnt);
10614 @@ -2046,7 +2057,7 @@ out:
10615 */
10616 void sun4v_resum_overflow(struct pt_regs *regs)
10617 {
10618 - atomic_inc(&sun4v_resum_oflow_cnt);
10619 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10620 }
10621
10622 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10623 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10624 /* XXX Actually even this can make not that much sense. Perhaps
10625 * XXX we should just pull the plug and panic directly from here?
10626 */
10627 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10628 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10629 }
10630
10631 unsigned long sun4v_err_itlb_vaddr;
10632 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10633
10634 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10635 regs->tpc, tl);
10636 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10637 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10638 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10639 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10640 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10641 (void *) regs->u_regs[UREG_I7]);
10642 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10643 "pte[%lx] error[%lx]\n",
10644 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10645
10646 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10647 regs->tpc, tl);
10648 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10649 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10650 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10651 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10652 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10653 (void *) regs->u_regs[UREG_I7]);
10654 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10655 "pte[%lx] error[%lx]\n",
10656 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10657 fp = (unsigned long)sf->fp + STACK_BIAS;
10658 }
10659
10660 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10661 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10662 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10663 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10664 int index = tsk->curr_ret_stack;
10665 if (tsk->ret_stack && index >= graph) {
10666 pc = tsk->ret_stack[index - graph].ret;
10667 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10668 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10669 graph++;
10670 }
10671 }
10672 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10673 return (struct reg_window *) (fp + STACK_BIAS);
10674 }
10675
10676 +extern void gr_handle_kernel_exploit(void);
10677 +
10678 void die_if_kernel(char *str, struct pt_regs *regs)
10679 {
10680 static int die_counter;
10681 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10682 while (rw &&
10683 count++ < 30 &&
10684 kstack_valid(tp, (unsigned long) rw)) {
10685 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10686 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10687 (void *) rw->ins[7]);
10688
10689 rw = kernel_stack_up(rw);
10690 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10691 }
10692 user_instruction_dump ((unsigned int __user *) regs->tpc);
10693 }
10694 - if (regs->tstate & TSTATE_PRIV)
10695 + if (regs->tstate & TSTATE_PRIV) {
10696 + gr_handle_kernel_exploit();
10697 do_exit(SIGKILL);
10698 + }
10699 do_exit(SIGSEGV);
10700 }
10701 EXPORT_SYMBOL(die_if_kernel);
10702 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10703 index 3c1a7cb..73e1923 100644
10704 --- a/arch/sparc/kernel/unaligned_64.c
10705 +++ b/arch/sparc/kernel/unaligned_64.c
10706 @@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10707 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10708
10709 if (__ratelimit(&ratelimit)) {
10710 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10711 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10712 regs->tpc, (void *) regs->tpc);
10713 }
10714 }
10715 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10716 index dbe119b..089c7c1 100644
10717 --- a/arch/sparc/lib/Makefile
10718 +++ b/arch/sparc/lib/Makefile
10719 @@ -2,7 +2,7 @@
10720 #
10721
10722 asflags-y := -ansi -DST_DIV0=0x02
10723 -ccflags-y := -Werror
10724 +#ccflags-y := -Werror
10725
10726 lib-$(CONFIG_SPARC32) += ashrdi3.o
10727 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10728 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10729 index 85c233d..68500e0 100644
10730 --- a/arch/sparc/lib/atomic_64.S
10731 +++ b/arch/sparc/lib/atomic_64.S
10732 @@ -17,7 +17,12 @@
10733 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10734 BACKOFF_SETUP(%o2)
10735 1: lduw [%o1], %g1
10736 - add %g1, %o0, %g7
10737 + addcc %g1, %o0, %g7
10738 +
10739 +#ifdef CONFIG_PAX_REFCOUNT
10740 + tvs %icc, 6
10741 +#endif
10742 +
10743 cas [%o1], %g1, %g7
10744 cmp %g1, %g7
10745 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10746 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10747 2: BACKOFF_SPIN(%o2, %o3, 1b)
10748 ENDPROC(atomic_add)
10749
10750 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10751 + BACKOFF_SETUP(%o2)
10752 +1: lduw [%o1], %g1
10753 + add %g1, %o0, %g7
10754 + cas [%o1], %g1, %g7
10755 + cmp %g1, %g7
10756 + bne,pn %icc, 2f
10757 + nop
10758 + retl
10759 + nop
10760 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10761 +ENDPROC(atomic_add_unchecked)
10762 +
10763 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10764 BACKOFF_SETUP(%o2)
10765 1: lduw [%o1], %g1
10766 - sub %g1, %o0, %g7
10767 + subcc %g1, %o0, %g7
10768 +
10769 +#ifdef CONFIG_PAX_REFCOUNT
10770 + tvs %icc, 6
10771 +#endif
10772 +
10773 cas [%o1], %g1, %g7
10774 cmp %g1, %g7
10775 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10776 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10777 2: BACKOFF_SPIN(%o2, %o3, 1b)
10778 ENDPROC(atomic_sub)
10779
10780 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10781 + BACKOFF_SETUP(%o2)
10782 +1: lduw [%o1], %g1
10783 + sub %g1, %o0, %g7
10784 + cas [%o1], %g1, %g7
10785 + cmp %g1, %g7
10786 + bne,pn %icc, 2f
10787 + nop
10788 + retl
10789 + nop
10790 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10791 +ENDPROC(atomic_sub_unchecked)
10792 +
10793 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10794 BACKOFF_SETUP(%o2)
10795 1: lduw [%o1], %g1
10796 - add %g1, %o0, %g7
10797 + addcc %g1, %o0, %g7
10798 +
10799 +#ifdef CONFIG_PAX_REFCOUNT
10800 + tvs %icc, 6
10801 +#endif
10802 +
10803 cas [%o1], %g1, %g7
10804 cmp %g1, %g7
10805 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10806 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10807 2: BACKOFF_SPIN(%o2, %o3, 1b)
10808 ENDPROC(atomic_add_ret)
10809
10810 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10811 + BACKOFF_SETUP(%o2)
10812 +1: lduw [%o1], %g1
10813 + addcc %g1, %o0, %g7
10814 + cas [%o1], %g1, %g7
10815 + cmp %g1, %g7
10816 + bne,pn %icc, 2f
10817 + add %g7, %o0, %g7
10818 + sra %g7, 0, %o0
10819 + retl
10820 + nop
10821 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10822 +ENDPROC(atomic_add_ret_unchecked)
10823 +
10824 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10825 BACKOFF_SETUP(%o2)
10826 1: lduw [%o1], %g1
10827 - sub %g1, %o0, %g7
10828 + subcc %g1, %o0, %g7
10829 +
10830 +#ifdef CONFIG_PAX_REFCOUNT
10831 + tvs %icc, 6
10832 +#endif
10833 +
10834 cas [%o1], %g1, %g7
10835 cmp %g1, %g7
10836 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10837 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10838 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10839 BACKOFF_SETUP(%o2)
10840 1: ldx [%o1], %g1
10841 - add %g1, %o0, %g7
10842 + addcc %g1, %o0, %g7
10843 +
10844 +#ifdef CONFIG_PAX_REFCOUNT
10845 + tvs %xcc, 6
10846 +#endif
10847 +
10848 casx [%o1], %g1, %g7
10849 cmp %g1, %g7
10850 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10851 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10852 2: BACKOFF_SPIN(%o2, %o3, 1b)
10853 ENDPROC(atomic64_add)
10854
10855 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10856 + BACKOFF_SETUP(%o2)
10857 +1: ldx [%o1], %g1
10858 + addcc %g1, %o0, %g7
10859 + casx [%o1], %g1, %g7
10860 + cmp %g1, %g7
10861 + bne,pn %xcc, 2f
10862 + nop
10863 + retl
10864 + nop
10865 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10866 +ENDPROC(atomic64_add_unchecked)
10867 +
10868 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10869 BACKOFF_SETUP(%o2)
10870 1: ldx [%o1], %g1
10871 - sub %g1, %o0, %g7
10872 + subcc %g1, %o0, %g7
10873 +
10874 +#ifdef CONFIG_PAX_REFCOUNT
10875 + tvs %xcc, 6
10876 +#endif
10877 +
10878 casx [%o1], %g1, %g7
10879 cmp %g1, %g7
10880 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10881 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10882 2: BACKOFF_SPIN(%o2, %o3, 1b)
10883 ENDPROC(atomic64_sub)
10884
10885 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10886 + BACKOFF_SETUP(%o2)
10887 +1: ldx [%o1], %g1
10888 + subcc %g1, %o0, %g7
10889 + casx [%o1], %g1, %g7
10890 + cmp %g1, %g7
10891 + bne,pn %xcc, 2f
10892 + nop
10893 + retl
10894 + nop
10895 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10896 +ENDPROC(atomic64_sub_unchecked)
10897 +
10898 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10899 BACKOFF_SETUP(%o2)
10900 1: ldx [%o1], %g1
10901 - add %g1, %o0, %g7
10902 + addcc %g1, %o0, %g7
10903 +
10904 +#ifdef CONFIG_PAX_REFCOUNT
10905 + tvs %xcc, 6
10906 +#endif
10907 +
10908 casx [%o1], %g1, %g7
10909 cmp %g1, %g7
10910 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10911 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10912 2: BACKOFF_SPIN(%o2, %o3, 1b)
10913 ENDPROC(atomic64_add_ret)
10914
10915 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10916 + BACKOFF_SETUP(%o2)
10917 +1: ldx [%o1], %g1
10918 + addcc %g1, %o0, %g7
10919 + casx [%o1], %g1, %g7
10920 + cmp %g1, %g7
10921 + bne,pn %xcc, 2f
10922 + add %g7, %o0, %g7
10923 + mov %g7, %o0
10924 + retl
10925 + nop
10926 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10927 +ENDPROC(atomic64_add_ret_unchecked)
10928 +
10929 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10930 BACKOFF_SETUP(%o2)
10931 1: ldx [%o1], %g1
10932 - sub %g1, %o0, %g7
10933 + subcc %g1, %o0, %g7
10934 +
10935 +#ifdef CONFIG_PAX_REFCOUNT
10936 + tvs %xcc, 6
10937 +#endif
10938 +
10939 casx [%o1], %g1, %g7
10940 cmp %g1, %g7
10941 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10942 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10943 index 323335b..ed85ea2 100644
10944 --- a/arch/sparc/lib/ksyms.c
10945 +++ b/arch/sparc/lib/ksyms.c
10946 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10947
10948 /* Atomic counter implementation. */
10949 EXPORT_SYMBOL(atomic_add);
10950 +EXPORT_SYMBOL(atomic_add_unchecked);
10951 EXPORT_SYMBOL(atomic_add_ret);
10952 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
10953 EXPORT_SYMBOL(atomic_sub);
10954 +EXPORT_SYMBOL(atomic_sub_unchecked);
10955 EXPORT_SYMBOL(atomic_sub_ret);
10956 EXPORT_SYMBOL(atomic64_add);
10957 +EXPORT_SYMBOL(atomic64_add_unchecked);
10958 EXPORT_SYMBOL(atomic64_add_ret);
10959 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10960 EXPORT_SYMBOL(atomic64_sub);
10961 +EXPORT_SYMBOL(atomic64_sub_unchecked);
10962 EXPORT_SYMBOL(atomic64_sub_ret);
10963 EXPORT_SYMBOL(atomic64_dec_if_positive);
10964
10965 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10966 index 30c3ecc..736f015 100644
10967 --- a/arch/sparc/mm/Makefile
10968 +++ b/arch/sparc/mm/Makefile
10969 @@ -2,7 +2,7 @@
10970 #
10971
10972 asflags-y := -ansi
10973 -ccflags-y := -Werror
10974 +#ccflags-y := -Werror
10975
10976 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10977 obj-y += fault_$(BITS).o
10978 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10979 index 59dbd46..1dd7f5e 100644
10980 --- a/arch/sparc/mm/fault_32.c
10981 +++ b/arch/sparc/mm/fault_32.c
10982 @@ -21,6 +21,9 @@
10983 #include <linux/perf_event.h>
10984 #include <linux/interrupt.h>
10985 #include <linux/kdebug.h>
10986 +#include <linux/slab.h>
10987 +#include <linux/pagemap.h>
10988 +#include <linux/compiler.h>
10989
10990 #include <asm/page.h>
10991 #include <asm/pgtable.h>
10992 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10993 return safe_compute_effective_address(regs, insn);
10994 }
10995
10996 +#ifdef CONFIG_PAX_PAGEEXEC
10997 +#ifdef CONFIG_PAX_DLRESOLVE
10998 +static void pax_emuplt_close(struct vm_area_struct *vma)
10999 +{
11000 + vma->vm_mm->call_dl_resolve = 0UL;
11001 +}
11002 +
11003 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11004 +{
11005 + unsigned int *kaddr;
11006 +
11007 + vmf->page = alloc_page(GFP_HIGHUSER);
11008 + if (!vmf->page)
11009 + return VM_FAULT_OOM;
11010 +
11011 + kaddr = kmap(vmf->page);
11012 + memset(kaddr, 0, PAGE_SIZE);
11013 + kaddr[0] = 0x9DE3BFA8U; /* save */
11014 + flush_dcache_page(vmf->page);
11015 + kunmap(vmf->page);
11016 + return VM_FAULT_MAJOR;
11017 +}
11018 +
11019 +static const struct vm_operations_struct pax_vm_ops = {
11020 + .close = pax_emuplt_close,
11021 + .fault = pax_emuplt_fault
11022 +};
11023 +
11024 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11025 +{
11026 + int ret;
11027 +
11028 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11029 + vma->vm_mm = current->mm;
11030 + vma->vm_start = addr;
11031 + vma->vm_end = addr + PAGE_SIZE;
11032 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11033 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11034 + vma->vm_ops = &pax_vm_ops;
11035 +
11036 + ret = insert_vm_struct(current->mm, vma);
11037 + if (ret)
11038 + return ret;
11039 +
11040 + ++current->mm->total_vm;
11041 + return 0;
11042 +}
11043 +#endif
11044 +
11045 +/*
11046 + * PaX: decide what to do with offenders (regs->pc = fault address)
11047 + *
11048 + * returns 1 when task should be killed
11049 + * 2 when patched PLT trampoline was detected
11050 + * 3 when unpatched PLT trampoline was detected
11051 + */
11052 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11053 +{
11054 +
11055 +#ifdef CONFIG_PAX_EMUPLT
11056 + int err;
11057 +
11058 + do { /* PaX: patched PLT emulation #1 */
11059 + unsigned int sethi1, sethi2, jmpl;
11060 +
11061 + err = get_user(sethi1, (unsigned int *)regs->pc);
11062 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11063 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11064 +
11065 + if (err)
11066 + break;
11067 +
11068 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11069 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11070 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11071 + {
11072 + unsigned int addr;
11073 +
11074 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11075 + addr = regs->u_regs[UREG_G1];
11076 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11077 + regs->pc = addr;
11078 + regs->npc = addr+4;
11079 + return 2;
11080 + }
11081 + } while (0);
11082 +
11083 + do { /* PaX: patched PLT emulation #2 */
11084 + unsigned int ba;
11085 +
11086 + err = get_user(ba, (unsigned int *)regs->pc);
11087 +
11088 + if (err)
11089 + break;
11090 +
11091 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11092 + unsigned int addr;
11093 +
11094 + if ((ba & 0xFFC00000U) == 0x30800000U)
11095 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11096 + else
11097 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11098 + regs->pc = addr;
11099 + regs->npc = addr+4;
11100 + return 2;
11101 + }
11102 + } while (0);
11103 +
11104 + do { /* PaX: patched PLT emulation #3 */
11105 + unsigned int sethi, bajmpl, nop;
11106 +
11107 + err = get_user(sethi, (unsigned int *)regs->pc);
11108 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11109 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11110 +
11111 + if (err)
11112 + break;
11113 +
11114 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11115 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11116 + nop == 0x01000000U)
11117 + {
11118 + unsigned int addr;
11119 +
11120 + addr = (sethi & 0x003FFFFFU) << 10;
11121 + regs->u_regs[UREG_G1] = addr;
11122 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11123 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11124 + else
11125 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11126 + regs->pc = addr;
11127 + regs->npc = addr+4;
11128 + return 2;
11129 + }
11130 + } while (0);
11131 +
11132 + do { /* PaX: unpatched PLT emulation step 1 */
11133 + unsigned int sethi, ba, nop;
11134 +
11135 + err = get_user(sethi, (unsigned int *)regs->pc);
11136 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11137 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11138 +
11139 + if (err)
11140 + break;
11141 +
11142 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11143 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11144 + nop == 0x01000000U)
11145 + {
11146 + unsigned int addr, save, call;
11147 +
11148 + if ((ba & 0xFFC00000U) == 0x30800000U)
11149 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11150 + else
11151 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11152 +
11153 + err = get_user(save, (unsigned int *)addr);
11154 + err |= get_user(call, (unsigned int *)(addr+4));
11155 + err |= get_user(nop, (unsigned int *)(addr+8));
11156 + if (err)
11157 + break;
11158 +
11159 +#ifdef CONFIG_PAX_DLRESOLVE
11160 + if (save == 0x9DE3BFA8U &&
11161 + (call & 0xC0000000U) == 0x40000000U &&
11162 + nop == 0x01000000U)
11163 + {
11164 + struct vm_area_struct *vma;
11165 + unsigned long call_dl_resolve;
11166 +
11167 + down_read(&current->mm->mmap_sem);
11168 + call_dl_resolve = current->mm->call_dl_resolve;
11169 + up_read(&current->mm->mmap_sem);
11170 + if (likely(call_dl_resolve))
11171 + goto emulate;
11172 +
11173 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11174 +
11175 + down_write(&current->mm->mmap_sem);
11176 + if (current->mm->call_dl_resolve) {
11177 + call_dl_resolve = current->mm->call_dl_resolve;
11178 + up_write(&current->mm->mmap_sem);
11179 + if (vma)
11180 + kmem_cache_free(vm_area_cachep, vma);
11181 + goto emulate;
11182 + }
11183 +
11184 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11185 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11186 + up_write(&current->mm->mmap_sem);
11187 + if (vma)
11188 + kmem_cache_free(vm_area_cachep, vma);
11189 + return 1;
11190 + }
11191 +
11192 + if (pax_insert_vma(vma, call_dl_resolve)) {
11193 + up_write(&current->mm->mmap_sem);
11194 + kmem_cache_free(vm_area_cachep, vma);
11195 + return 1;
11196 + }
11197 +
11198 + current->mm->call_dl_resolve = call_dl_resolve;
11199 + up_write(&current->mm->mmap_sem);
11200 +
11201 +emulate:
11202 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11203 + regs->pc = call_dl_resolve;
11204 + regs->npc = addr+4;
11205 + return 3;
11206 + }
11207 +#endif
11208 +
11209 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11210 + if ((save & 0xFFC00000U) == 0x05000000U &&
11211 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11212 + nop == 0x01000000U)
11213 + {
11214 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11215 + regs->u_regs[UREG_G2] = addr + 4;
11216 + addr = (save & 0x003FFFFFU) << 10;
11217 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11218 + regs->pc = addr;
11219 + regs->npc = addr+4;
11220 + return 3;
11221 + }
11222 + }
11223 + } while (0);
11224 +
11225 + do { /* PaX: unpatched PLT emulation step 2 */
11226 + unsigned int save, call, nop;
11227 +
11228 + err = get_user(save, (unsigned int *)(regs->pc-4));
11229 + err |= get_user(call, (unsigned int *)regs->pc);
11230 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11231 + if (err)
11232 + break;
11233 +
11234 + if (save == 0x9DE3BFA8U &&
11235 + (call & 0xC0000000U) == 0x40000000U &&
11236 + nop == 0x01000000U)
11237 + {
11238 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11239 +
11240 + regs->u_regs[UREG_RETPC] = regs->pc;
11241 + regs->pc = dl_resolve;
11242 + regs->npc = dl_resolve+4;
11243 + return 3;
11244 + }
11245 + } while (0);
11246 +#endif
11247 +
11248 + return 1;
11249 +}
11250 +
11251 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11252 +{
11253 + unsigned long i;
11254 +
11255 + printk(KERN_ERR "PAX: bytes at PC: ");
11256 + for (i = 0; i < 8; i++) {
11257 + unsigned int c;
11258 + if (get_user(c, (unsigned int *)pc+i))
11259 + printk(KERN_CONT "???????? ");
11260 + else
11261 + printk(KERN_CONT "%08x ", c);
11262 + }
11263 + printk("\n");
11264 +}
11265 +#endif
11266 +
11267 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11268 int text_fault)
11269 {
11270 @@ -229,6 +503,24 @@ good_area:
11271 if (!(vma->vm_flags & VM_WRITE))
11272 goto bad_area;
11273 } else {
11274 +
11275 +#ifdef CONFIG_PAX_PAGEEXEC
11276 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11277 + up_read(&mm->mmap_sem);
11278 + switch (pax_handle_fetch_fault(regs)) {
11279 +
11280 +#ifdef CONFIG_PAX_EMUPLT
11281 + case 2:
11282 + case 3:
11283 + return;
11284 +#endif
11285 +
11286 + }
11287 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11288 + do_group_exit(SIGKILL);
11289 + }
11290 +#endif
11291 +
11292 /* Allow reads even for write-only mappings */
11293 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11294 goto bad_area;
11295 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11296 index 69bb818..6ca35c8 100644
11297 --- a/arch/sparc/mm/fault_64.c
11298 +++ b/arch/sparc/mm/fault_64.c
11299 @@ -22,6 +22,9 @@
11300 #include <linux/kdebug.h>
11301 #include <linux/percpu.h>
11302 #include <linux/context_tracking.h>
11303 +#include <linux/slab.h>
11304 +#include <linux/pagemap.h>
11305 +#include <linux/compiler.h>
11306
11307 #include <asm/page.h>
11308 #include <asm/pgtable.h>
11309 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11310 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11311 regs->tpc);
11312 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11313 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11314 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11315 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11316 dump_stack();
11317 unhandled_fault(regs->tpc, current, regs);
11318 @@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11319 show_regs(regs);
11320 }
11321
11322 +#ifdef CONFIG_PAX_PAGEEXEC
11323 +#ifdef CONFIG_PAX_DLRESOLVE
11324 +static void pax_emuplt_close(struct vm_area_struct *vma)
11325 +{
11326 + vma->vm_mm->call_dl_resolve = 0UL;
11327 +}
11328 +
11329 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11330 +{
11331 + unsigned int *kaddr;
11332 +
11333 + vmf->page = alloc_page(GFP_HIGHUSER);
11334 + if (!vmf->page)
11335 + return VM_FAULT_OOM;
11336 +
11337 + kaddr = kmap(vmf->page);
11338 + memset(kaddr, 0, PAGE_SIZE);
11339 + kaddr[0] = 0x9DE3BFA8U; /* save */
11340 + flush_dcache_page(vmf->page);
11341 + kunmap(vmf->page);
11342 + return VM_FAULT_MAJOR;
11343 +}
11344 +
11345 +static const struct vm_operations_struct pax_vm_ops = {
11346 + .close = pax_emuplt_close,
11347 + .fault = pax_emuplt_fault
11348 +};
11349 +
11350 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11351 +{
11352 + int ret;
11353 +
11354 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11355 + vma->vm_mm = current->mm;
11356 + vma->vm_start = addr;
11357 + vma->vm_end = addr + PAGE_SIZE;
11358 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11359 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11360 + vma->vm_ops = &pax_vm_ops;
11361 +
11362 + ret = insert_vm_struct(current->mm, vma);
11363 + if (ret)
11364 + return ret;
11365 +
11366 + ++current->mm->total_vm;
11367 + return 0;
11368 +}
11369 +#endif
11370 +
11371 +/*
11372 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11373 + *
11374 + * returns 1 when task should be killed
11375 + * 2 when patched PLT trampoline was detected
11376 + * 3 when unpatched PLT trampoline was detected
11377 + */
11378 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11379 +{
11380 +
11381 +#ifdef CONFIG_PAX_EMUPLT
11382 + int err;
11383 +
11384 + do { /* PaX: patched PLT emulation #1 */
11385 + unsigned int sethi1, sethi2, jmpl;
11386 +
11387 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11388 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11389 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11390 +
11391 + if (err)
11392 + break;
11393 +
11394 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11395 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11396 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11397 + {
11398 + unsigned long addr;
11399 +
11400 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11401 + addr = regs->u_regs[UREG_G1];
11402 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11403 +
11404 + if (test_thread_flag(TIF_32BIT))
11405 + addr &= 0xFFFFFFFFUL;
11406 +
11407 + regs->tpc = addr;
11408 + regs->tnpc = addr+4;
11409 + return 2;
11410 + }
11411 + } while (0);
11412 +
11413 + do { /* PaX: patched PLT emulation #2 */
11414 + unsigned int ba;
11415 +
11416 + err = get_user(ba, (unsigned int *)regs->tpc);
11417 +
11418 + if (err)
11419 + break;
11420 +
11421 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11422 + unsigned long addr;
11423 +
11424 + if ((ba & 0xFFC00000U) == 0x30800000U)
11425 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11426 + else
11427 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11428 +
11429 + if (test_thread_flag(TIF_32BIT))
11430 + addr &= 0xFFFFFFFFUL;
11431 +
11432 + regs->tpc = addr;
11433 + regs->tnpc = addr+4;
11434 + return 2;
11435 + }
11436 + } while (0);
11437 +
11438 + do { /* PaX: patched PLT emulation #3 */
11439 + unsigned int sethi, bajmpl, nop;
11440 +
11441 + err = get_user(sethi, (unsigned int *)regs->tpc);
11442 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11443 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11444 +
11445 + if (err)
11446 + break;
11447 +
11448 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11449 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11450 + nop == 0x01000000U)
11451 + {
11452 + unsigned long addr;
11453 +
11454 + addr = (sethi & 0x003FFFFFU) << 10;
11455 + regs->u_regs[UREG_G1] = addr;
11456 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11457 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11458 + else
11459 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11460 +
11461 + if (test_thread_flag(TIF_32BIT))
11462 + addr &= 0xFFFFFFFFUL;
11463 +
11464 + regs->tpc = addr;
11465 + regs->tnpc = addr+4;
11466 + return 2;
11467 + }
11468 + } while (0);
11469 +
11470 + do { /* PaX: patched PLT emulation #4 */
11471 + unsigned int sethi, mov1, call, mov2;
11472 +
11473 + err = get_user(sethi, (unsigned int *)regs->tpc);
11474 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11475 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11476 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11477 +
11478 + if (err)
11479 + break;
11480 +
11481 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11482 + mov1 == 0x8210000FU &&
11483 + (call & 0xC0000000U) == 0x40000000U &&
11484 + mov2 == 0x9E100001U)
11485 + {
11486 + unsigned long addr;
11487 +
11488 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11489 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11490 +
11491 + if (test_thread_flag(TIF_32BIT))
11492 + addr &= 0xFFFFFFFFUL;
11493 +
11494 + regs->tpc = addr;
11495 + regs->tnpc = addr+4;
11496 + return 2;
11497 + }
11498 + } while (0);
11499 +
11500 + do { /* PaX: patched PLT emulation #5 */
11501 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11502 +
11503 + err = get_user(sethi, (unsigned int *)regs->tpc);
11504 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11505 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11506 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11507 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11508 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11509 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11510 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11511 +
11512 + if (err)
11513 + break;
11514 +
11515 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11516 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11517 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11518 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11519 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11520 + sllx == 0x83287020U &&
11521 + jmpl == 0x81C04005U &&
11522 + nop == 0x01000000U)
11523 + {
11524 + unsigned long addr;
11525 +
11526 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11527 + regs->u_regs[UREG_G1] <<= 32;
11528 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11529 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11530 + regs->tpc = addr;
11531 + regs->tnpc = addr+4;
11532 + return 2;
11533 + }
11534 + } while (0);
11535 +
11536 + do { /* PaX: patched PLT emulation #6 */
11537 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11538 +
11539 + err = get_user(sethi, (unsigned int *)regs->tpc);
11540 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11541 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11542 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11543 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11544 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11545 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11546 +
11547 + if (err)
11548 + break;
11549 +
11550 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11551 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11552 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11553 + sllx == 0x83287020U &&
11554 + (or & 0xFFFFE000U) == 0x8A116000U &&
11555 + jmpl == 0x81C04005U &&
11556 + nop == 0x01000000U)
11557 + {
11558 + unsigned long addr;
11559 +
11560 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11561 + regs->u_regs[UREG_G1] <<= 32;
11562 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11563 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11564 + regs->tpc = addr;
11565 + regs->tnpc = addr+4;
11566 + return 2;
11567 + }
11568 + } while (0);
11569 +
11570 + do { /* PaX: unpatched PLT emulation step 1 */
11571 + unsigned int sethi, ba, nop;
11572 +
11573 + err = get_user(sethi, (unsigned int *)regs->tpc);
11574 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11575 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11576 +
11577 + if (err)
11578 + break;
11579 +
11580 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11581 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11582 + nop == 0x01000000U)
11583 + {
11584 + unsigned long addr;
11585 + unsigned int save, call;
11586 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11587 +
11588 + if ((ba & 0xFFC00000U) == 0x30800000U)
11589 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11590 + else
11591 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11592 +
11593 + if (test_thread_flag(TIF_32BIT))
11594 + addr &= 0xFFFFFFFFUL;
11595 +
11596 + err = get_user(save, (unsigned int *)addr);
11597 + err |= get_user(call, (unsigned int *)(addr+4));
11598 + err |= get_user(nop, (unsigned int *)(addr+8));
11599 + if (err)
11600 + break;
11601 +
11602 +#ifdef CONFIG_PAX_DLRESOLVE
11603 + if (save == 0x9DE3BFA8U &&
11604 + (call & 0xC0000000U) == 0x40000000U &&
11605 + nop == 0x01000000U)
11606 + {
11607 + struct vm_area_struct *vma;
11608 + unsigned long call_dl_resolve;
11609 +
11610 + down_read(&current->mm->mmap_sem);
11611 + call_dl_resolve = current->mm->call_dl_resolve;
11612 + up_read(&current->mm->mmap_sem);
11613 + if (likely(call_dl_resolve))
11614 + goto emulate;
11615 +
11616 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11617 +
11618 + down_write(&current->mm->mmap_sem);
11619 + if (current->mm->call_dl_resolve) {
11620 + call_dl_resolve = current->mm->call_dl_resolve;
11621 + up_write(&current->mm->mmap_sem);
11622 + if (vma)
11623 + kmem_cache_free(vm_area_cachep, vma);
11624 + goto emulate;
11625 + }
11626 +
11627 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11628 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11629 + up_write(&current->mm->mmap_sem);
11630 + if (vma)
11631 + kmem_cache_free(vm_area_cachep, vma);
11632 + return 1;
11633 + }
11634 +
11635 + if (pax_insert_vma(vma, call_dl_resolve)) {
11636 + up_write(&current->mm->mmap_sem);
11637 + kmem_cache_free(vm_area_cachep, vma);
11638 + return 1;
11639 + }
11640 +
11641 + current->mm->call_dl_resolve = call_dl_resolve;
11642 + up_write(&current->mm->mmap_sem);
11643 +
11644 +emulate:
11645 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11646 + regs->tpc = call_dl_resolve;
11647 + regs->tnpc = addr+4;
11648 + return 3;
11649 + }
11650 +#endif
11651 +
11652 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11653 + if ((save & 0xFFC00000U) == 0x05000000U &&
11654 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11655 + nop == 0x01000000U)
11656 + {
11657 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11658 + regs->u_regs[UREG_G2] = addr + 4;
11659 + addr = (save & 0x003FFFFFU) << 10;
11660 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11661 +
11662 + if (test_thread_flag(TIF_32BIT))
11663 + addr &= 0xFFFFFFFFUL;
11664 +
11665 + regs->tpc = addr;
11666 + regs->tnpc = addr+4;
11667 + return 3;
11668 + }
11669 +
11670 + /* PaX: 64-bit PLT stub */
11671 + err = get_user(sethi1, (unsigned int *)addr);
11672 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11673 + err |= get_user(or1, (unsigned int *)(addr+8));
11674 + err |= get_user(or2, (unsigned int *)(addr+12));
11675 + err |= get_user(sllx, (unsigned int *)(addr+16));
11676 + err |= get_user(add, (unsigned int *)(addr+20));
11677 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11678 + err |= get_user(nop, (unsigned int *)(addr+28));
11679 + if (err)
11680 + break;
11681 +
11682 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11683 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11684 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11685 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11686 + sllx == 0x89293020U &&
11687 + add == 0x8A010005U &&
11688 + jmpl == 0x89C14000U &&
11689 + nop == 0x01000000U)
11690 + {
11691 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11692 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11693 + regs->u_regs[UREG_G4] <<= 32;
11694 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11695 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11696 + regs->u_regs[UREG_G4] = addr + 24;
11697 + addr = regs->u_regs[UREG_G5];
11698 + regs->tpc = addr;
11699 + regs->tnpc = addr+4;
11700 + return 3;
11701 + }
11702 + }
11703 + } while (0);
11704 +
11705 +#ifdef CONFIG_PAX_DLRESOLVE
11706 + do { /* PaX: unpatched PLT emulation step 2 */
11707 + unsigned int save, call, nop;
11708 +
11709 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11710 + err |= get_user(call, (unsigned int *)regs->tpc);
11711 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11712 + if (err)
11713 + break;
11714 +
11715 + if (save == 0x9DE3BFA8U &&
11716 + (call & 0xC0000000U) == 0x40000000U &&
11717 + nop == 0x01000000U)
11718 + {
11719 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11720 +
11721 + if (test_thread_flag(TIF_32BIT))
11722 + dl_resolve &= 0xFFFFFFFFUL;
11723 +
11724 + regs->u_regs[UREG_RETPC] = regs->tpc;
11725 + regs->tpc = dl_resolve;
11726 + regs->tnpc = dl_resolve+4;
11727 + return 3;
11728 + }
11729 + } while (0);
11730 +#endif
11731 +
11732 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11733 + unsigned int sethi, ba, nop;
11734 +
11735 + err = get_user(sethi, (unsigned int *)regs->tpc);
11736 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11737 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11738 +
11739 + if (err)
11740 + break;
11741 +
11742 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11743 + (ba & 0xFFF00000U) == 0x30600000U &&
11744 + nop == 0x01000000U)
11745 + {
11746 + unsigned long addr;
11747 +
11748 + addr = (sethi & 0x003FFFFFU) << 10;
11749 + regs->u_regs[UREG_G1] = addr;
11750 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11751 +
11752 + if (test_thread_flag(TIF_32BIT))
11753 + addr &= 0xFFFFFFFFUL;
11754 +
11755 + regs->tpc = addr;
11756 + regs->tnpc = addr+4;
11757 + return 2;
11758 + }
11759 + } while (0);
11760 +
11761 +#endif
11762 +
11763 + return 1;
11764 +}
11765 +
11766 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11767 +{
11768 + unsigned long i;
11769 +
11770 + printk(KERN_ERR "PAX: bytes at PC: ");
11771 + for (i = 0; i < 8; i++) {
11772 + unsigned int c;
11773 + if (get_user(c, (unsigned int *)pc+i))
11774 + printk(KERN_CONT "???????? ");
11775 + else
11776 + printk(KERN_CONT "%08x ", c);
11777 + }
11778 + printk("\n");
11779 +}
11780 +#endif
11781 +
11782 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11783 {
11784 enum ctx_state prev_state = exception_enter();
11785 @@ -344,6 +807,29 @@ retry:
11786 if (!vma)
11787 goto bad_area;
11788
11789 +#ifdef CONFIG_PAX_PAGEEXEC
11790 + /* PaX: detect ITLB misses on non-exec pages */
11791 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11792 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11793 + {
11794 + if (address != regs->tpc)
11795 + goto good_area;
11796 +
11797 + up_read(&mm->mmap_sem);
11798 + switch (pax_handle_fetch_fault(regs)) {
11799 +
11800 +#ifdef CONFIG_PAX_EMUPLT
11801 + case 2:
11802 + case 3:
11803 + return;
11804 +#endif
11805 +
11806 + }
11807 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11808 + do_group_exit(SIGKILL);
11809 + }
11810 +#endif
11811 +
11812 /* Pure DTLB misses do not tell us whether the fault causing
11813 * load/store/atomic was a write or not, it only says that there
11814 * was no match. So in such a case we (carefully) read the
11815 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11816 index 3096317..a7b7654 100644
11817 --- a/arch/sparc/mm/hugetlbpage.c
11818 +++ b/arch/sparc/mm/hugetlbpage.c
11819 @@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11820 unsigned long addr,
11821 unsigned long len,
11822 unsigned long pgoff,
11823 - unsigned long flags)
11824 + unsigned long flags,
11825 + unsigned long offset)
11826 {
11827 unsigned long task_size = TASK_SIZE;
11828 struct vm_unmapped_area_info info;
11829 @@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11830
11831 info.flags = 0;
11832 info.length = len;
11833 - info.low_limit = TASK_UNMAPPED_BASE;
11834 + info.low_limit = mm->mmap_base;
11835 info.high_limit = min(task_size, VA_EXCLUDE_START);
11836 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11837 info.align_offset = 0;
11838 + info.threadstack_offset = offset;
11839 addr = vm_unmapped_area(&info);
11840
11841 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11842 VM_BUG_ON(addr != -ENOMEM);
11843 info.low_limit = VA_EXCLUDE_END;
11844 +
11845 +#ifdef CONFIG_PAX_RANDMMAP
11846 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11847 + info.low_limit += mm->delta_mmap;
11848 +#endif
11849 +
11850 info.high_limit = task_size;
11851 addr = vm_unmapped_area(&info);
11852 }
11853 @@ -56,7 +64,8 @@ static unsigned long
11854 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11855 const unsigned long len,
11856 const unsigned long pgoff,
11857 - const unsigned long flags)
11858 + const unsigned long flags,
11859 + const unsigned long offset)
11860 {
11861 struct mm_struct *mm = current->mm;
11862 unsigned long addr = addr0;
11863 @@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11864 info.high_limit = mm->mmap_base;
11865 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11866 info.align_offset = 0;
11867 + info.threadstack_offset = offset;
11868 addr = vm_unmapped_area(&info);
11869
11870 /*
11871 @@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11872 VM_BUG_ON(addr != -ENOMEM);
11873 info.flags = 0;
11874 info.low_limit = TASK_UNMAPPED_BASE;
11875 +
11876 +#ifdef CONFIG_PAX_RANDMMAP
11877 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11878 + info.low_limit += mm->delta_mmap;
11879 +#endif
11880 +
11881 info.high_limit = STACK_TOP32;
11882 addr = vm_unmapped_area(&info);
11883 }
11884 @@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11885 struct mm_struct *mm = current->mm;
11886 struct vm_area_struct *vma;
11887 unsigned long task_size = TASK_SIZE;
11888 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11889
11890 if (test_thread_flag(TIF_32BIT))
11891 task_size = STACK_TOP32;
11892 @@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11893 return addr;
11894 }
11895
11896 +#ifdef CONFIG_PAX_RANDMMAP
11897 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11898 +#endif
11899 +
11900 if (addr) {
11901 addr = ALIGN(addr, HPAGE_SIZE);
11902 vma = find_vma(mm, addr);
11903 - if (task_size - len >= addr &&
11904 - (!vma || addr + len <= vma->vm_start))
11905 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11906 return addr;
11907 }
11908 if (mm->get_unmapped_area == arch_get_unmapped_area)
11909 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11910 - pgoff, flags);
11911 + pgoff, flags, offset);
11912 else
11913 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11914 - pgoff, flags);
11915 + pgoff, flags, offset);
11916 }
11917
11918 pte_t *huge_pte_alloc(struct mm_struct *mm,
11919 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11920 index 5322e53..f820c5e 100644
11921 --- a/arch/sparc/mm/init_64.c
11922 +++ b/arch/sparc/mm/init_64.c
11923 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11924 int num_kernel_image_mappings;
11925
11926 #ifdef CONFIG_DEBUG_DCFLUSH
11927 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
11928 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11929 #ifdef CONFIG_SMP
11930 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11931 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11932 #endif
11933 #endif
11934
11935 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11936 {
11937 BUG_ON(tlb_type == hypervisor);
11938 #ifdef CONFIG_DEBUG_DCFLUSH
11939 - atomic_inc(&dcpage_flushes);
11940 + atomic_inc_unchecked(&dcpage_flushes);
11941 #endif
11942
11943 #ifdef DCACHE_ALIASING_POSSIBLE
11944 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11945
11946 #ifdef CONFIG_DEBUG_DCFLUSH
11947 seq_printf(m, "DCPageFlushes\t: %d\n",
11948 - atomic_read(&dcpage_flushes));
11949 + atomic_read_unchecked(&dcpage_flushes));
11950 #ifdef CONFIG_SMP
11951 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11952 - atomic_read(&dcpage_flushes_xcall));
11953 + atomic_read_unchecked(&dcpage_flushes_xcall));
11954 #endif /* CONFIG_SMP */
11955 #endif /* CONFIG_DEBUG_DCFLUSH */
11956 }
11957 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11958 index b3692ce..e4517c9 100644
11959 --- a/arch/tile/Kconfig
11960 +++ b/arch/tile/Kconfig
11961 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11962
11963 config KEXEC
11964 bool "kexec system call"
11965 + depends on !GRKERNSEC_KMEM
11966 ---help---
11967 kexec is a system call that implements the ability to shutdown your
11968 current kernel, and to start another kernel. It is like a reboot
11969 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11970 index ad220ee..2f537b3 100644
11971 --- a/arch/tile/include/asm/atomic_64.h
11972 +++ b/arch/tile/include/asm/atomic_64.h
11973 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11974
11975 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11976
11977 +#define atomic64_read_unchecked(v) atomic64_read(v)
11978 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11979 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11980 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11981 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11982 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
11983 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11984 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
11985 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11986 +
11987 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11988 #define smp_mb__before_atomic_dec() smp_mb()
11989 #define smp_mb__after_atomic_dec() smp_mb()
11990 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11991 index 6160761..00cac88 100644
11992 --- a/arch/tile/include/asm/cache.h
11993 +++ b/arch/tile/include/asm/cache.h
11994 @@ -15,11 +15,12 @@
11995 #ifndef _ASM_TILE_CACHE_H
11996 #define _ASM_TILE_CACHE_H
11997
11998 +#include <linux/const.h>
11999 #include <arch/chip.h>
12000
12001 /* bytes per L1 data cache line */
12002 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12003 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12004 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12005
12006 /* bytes per L2 cache line */
12007 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12008 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12009 index b6cde32..c0cb736 100644
12010 --- a/arch/tile/include/asm/uaccess.h
12011 +++ b/arch/tile/include/asm/uaccess.h
12012 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12013 const void __user *from,
12014 unsigned long n)
12015 {
12016 - int sz = __compiletime_object_size(to);
12017 + size_t sz = __compiletime_object_size(to);
12018
12019 - if (likely(sz == -1 || sz >= n))
12020 + if (likely(sz == (size_t)-1 || sz >= n))
12021 n = _copy_from_user(to, from, n);
12022 else
12023 copy_from_user_overflow();
12024 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12025 index 0cb3bba..7338b2d 100644
12026 --- a/arch/tile/mm/hugetlbpage.c
12027 +++ b/arch/tile/mm/hugetlbpage.c
12028 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12029 info.high_limit = TASK_SIZE;
12030 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12031 info.align_offset = 0;
12032 + info.threadstack_offset = 0;
12033 return vm_unmapped_area(&info);
12034 }
12035
12036 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12037 info.high_limit = current->mm->mmap_base;
12038 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12039 info.align_offset = 0;
12040 + info.threadstack_offset = 0;
12041 addr = vm_unmapped_area(&info);
12042
12043 /*
12044 diff --git a/arch/um/Makefile b/arch/um/Makefile
12045 index 36e658a..71a5c5a 100644
12046 --- a/arch/um/Makefile
12047 +++ b/arch/um/Makefile
12048 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12049 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12050 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12051
12052 +ifdef CONSTIFY_PLUGIN
12053 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12054 +endif
12055 +
12056 #This will adjust *FLAGS accordingly to the platform.
12057 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12058
12059 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12060 index 19e1bdd..3665b77 100644
12061 --- a/arch/um/include/asm/cache.h
12062 +++ b/arch/um/include/asm/cache.h
12063 @@ -1,6 +1,7 @@
12064 #ifndef __UM_CACHE_H
12065 #define __UM_CACHE_H
12066
12067 +#include <linux/const.h>
12068
12069 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12070 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12071 @@ -12,6 +13,6 @@
12072 # define L1_CACHE_SHIFT 5
12073 #endif
12074
12075 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12076 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12077
12078 #endif
12079 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12080 index 2e0a6b1..a64d0f5 100644
12081 --- a/arch/um/include/asm/kmap_types.h
12082 +++ b/arch/um/include/asm/kmap_types.h
12083 @@ -8,6 +8,6 @@
12084
12085 /* No more #include "asm/arch/kmap_types.h" ! */
12086
12087 -#define KM_TYPE_NR 14
12088 +#define KM_TYPE_NR 15
12089
12090 #endif
12091 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12092 index 5ff53d9..5850cdf 100644
12093 --- a/arch/um/include/asm/page.h
12094 +++ b/arch/um/include/asm/page.h
12095 @@ -14,6 +14,9 @@
12096 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12097 #define PAGE_MASK (~(PAGE_SIZE-1))
12098
12099 +#define ktla_ktva(addr) (addr)
12100 +#define ktva_ktla(addr) (addr)
12101 +
12102 #ifndef __ASSEMBLY__
12103
12104 struct page;
12105 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12106 index 0032f92..cd151e0 100644
12107 --- a/arch/um/include/asm/pgtable-3level.h
12108 +++ b/arch/um/include/asm/pgtable-3level.h
12109 @@ -58,6 +58,7 @@
12110 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12111 #define pud_populate(mm, pud, pmd) \
12112 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12113 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12114
12115 #ifdef CONFIG_64BIT
12116 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12117 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12118 index eecc414..48adb87 100644
12119 --- a/arch/um/kernel/process.c
12120 +++ b/arch/um/kernel/process.c
12121 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12122 return 2;
12123 }
12124
12125 -/*
12126 - * Only x86 and x86_64 have an arch_align_stack().
12127 - * All other arches have "#define arch_align_stack(x) (x)"
12128 - * in their asm/system.h
12129 - * As this is included in UML from asm-um/system-generic.h,
12130 - * we can use it to behave as the subarch does.
12131 - */
12132 -#ifndef arch_align_stack
12133 -unsigned long arch_align_stack(unsigned long sp)
12134 -{
12135 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12136 - sp -= get_random_int() % 8192;
12137 - return sp & ~0xf;
12138 -}
12139 -#endif
12140 -
12141 unsigned long get_wchan(struct task_struct *p)
12142 {
12143 unsigned long stack_page, sp, ip;
12144 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12145 index ad8f795..2c7eec6 100644
12146 --- a/arch/unicore32/include/asm/cache.h
12147 +++ b/arch/unicore32/include/asm/cache.h
12148 @@ -12,8 +12,10 @@
12149 #ifndef __UNICORE_CACHE_H__
12150 #define __UNICORE_CACHE_H__
12151
12152 -#define L1_CACHE_SHIFT (5)
12153 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12154 +#include <linux/const.h>
12155 +
12156 +#define L1_CACHE_SHIFT 5
12157 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12158
12159 /*
12160 * Memory returned by kmalloc() may be used for DMA, so we must make
12161 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12162 index 0952ecd..9cf578c 100644
12163 --- a/arch/x86/Kconfig
12164 +++ b/arch/x86/Kconfig
12165 @@ -249,7 +249,7 @@ config X86_HT
12166
12167 config X86_32_LAZY_GS
12168 def_bool y
12169 - depends on X86_32 && !CC_STACKPROTECTOR
12170 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12171
12172 config ARCH_HWEIGHT_CFLAGS
12173 string
12174 @@ -602,6 +602,7 @@ config SCHED_OMIT_FRAME_POINTER
12175
12176 menuconfig HYPERVISOR_GUEST
12177 bool "Linux guest support"
12178 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12179 ---help---
12180 Say Y here to enable options for running Linux under various hyper-
12181 visors. This option enables basic hypervisor detection and platform
12182 @@ -1127,7 +1128,7 @@ choice
12183
12184 config NOHIGHMEM
12185 bool "off"
12186 - depends on !X86_NUMAQ
12187 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12188 ---help---
12189 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12190 However, the address space of 32-bit x86 processors is only 4
12191 @@ -1164,7 +1165,7 @@ config NOHIGHMEM
12192
12193 config HIGHMEM4G
12194 bool "4GB"
12195 - depends on !X86_NUMAQ
12196 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12197 ---help---
12198 Select this if you have a 32-bit processor and between 1 and 4
12199 gigabytes of physical RAM.
12200 @@ -1217,7 +1218,7 @@ config PAGE_OFFSET
12201 hex
12202 default 0xB0000000 if VMSPLIT_3G_OPT
12203 default 0x80000000 if VMSPLIT_2G
12204 - default 0x78000000 if VMSPLIT_2G_OPT
12205 + default 0x70000000 if VMSPLIT_2G_OPT
12206 default 0x40000000 if VMSPLIT_1G
12207 default 0xC0000000
12208 depends on X86_32
12209 @@ -1619,6 +1620,7 @@ config SECCOMP
12210
12211 config CC_STACKPROTECTOR
12212 bool "Enable -fstack-protector buffer overflow detection"
12213 + depends on X86_64 || !PAX_MEMORY_UDEREF
12214 ---help---
12215 This option turns on the -fstack-protector GCC feature. This
12216 feature puts, at the beginning of functions, a canary value on
12217 @@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
12218
12219 config KEXEC
12220 bool "kexec system call"
12221 + depends on !GRKERNSEC_KMEM
12222 ---help---
12223 kexec is a system call that implements the ability to shutdown your
12224 current kernel, and to start another kernel. It is like a reboot
12225 @@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
12226 config PHYSICAL_ALIGN
12227 hex "Alignment value to which kernel should be aligned"
12228 default "0x1000000"
12229 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12230 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12231 range 0x2000 0x1000000 if X86_32
12232 range 0x200000 0x1000000 if X86_64
12233 ---help---
12234 @@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
12235 If unsure, say N.
12236
12237 config COMPAT_VDSO
12238 - def_bool y
12239 + def_bool n
12240 prompt "Compat VDSO support"
12241 depends on X86_32 || IA32_EMULATION
12242 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12243 ---help---
12244 Map the 32-bit VDSO to the predictable old-style address too.
12245
12246 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12247 index c026cca..14657ae 100644
12248 --- a/arch/x86/Kconfig.cpu
12249 +++ b/arch/x86/Kconfig.cpu
12250 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12251
12252 config X86_F00F_BUG
12253 def_bool y
12254 - depends on M586MMX || M586TSC || M586 || M486
12255 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12256
12257 config X86_INVD_BUG
12258 def_bool y
12259 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12260
12261 config X86_ALIGNMENT_16
12262 def_bool y
12263 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12264 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12265
12266 config X86_INTEL_USERCOPY
12267 def_bool y
12268 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
12269 # generates cmov.
12270 config X86_CMOV
12271 def_bool y
12272 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12273 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12274
12275 config X86_MINIMUM_CPU_FAMILY
12276 int
12277 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12278 index 0f3621e..282f24b 100644
12279 --- a/arch/x86/Kconfig.debug
12280 +++ b/arch/x86/Kconfig.debug
12281 @@ -84,7 +84,7 @@ config X86_PTDUMP
12282 config DEBUG_RODATA
12283 bool "Write protect kernel read-only data structures"
12284 default y
12285 - depends on DEBUG_KERNEL
12286 + depends on DEBUG_KERNEL && BROKEN
12287 ---help---
12288 Mark the kernel read-only data as write-protected in the pagetables,
12289 in order to catch accidental (and incorrect) writes to such const
12290 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12291
12292 config DEBUG_SET_MODULE_RONX
12293 bool "Set loadable kernel module data as NX and text as RO"
12294 - depends on MODULES
12295 + depends on MODULES && BROKEN
12296 ---help---
12297 This option helps catch unintended modifications to loadable
12298 kernel module's text and read-only data. It also prevents execution
12299 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12300 index 57d0215..b4373fb 100644
12301 --- a/arch/x86/Makefile
12302 +++ b/arch/x86/Makefile
12303 @@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
12304 # CPU-specific tuning. Anything which can be shared with UML should go here.
12305 include $(srctree)/arch/x86/Makefile_32.cpu
12306 KBUILD_CFLAGS += $(cflags-y)
12307 -
12308 - # temporary until string.h is fixed
12309 - KBUILD_CFLAGS += -ffreestanding
12310 else
12311 BITS := 64
12312 UTS_MACHINE := x86_64
12313 CHECKFLAGS += -D__x86_64__ -m64
12314
12315 + biarch := $(call cc-option,-m64)
12316 KBUILD_AFLAGS += -m64
12317 KBUILD_CFLAGS += -m64
12318
12319 @@ -89,6 +87,9 @@ else
12320 KBUILD_CFLAGS += -maccumulate-outgoing-args
12321 endif
12322
12323 +# temporary until string.h is fixed
12324 +KBUILD_CFLAGS += -ffreestanding
12325 +
12326 ifdef CONFIG_CC_STACKPROTECTOR
12327 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12328 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
12329 @@ -247,3 +248,12 @@ define archhelp
12330 echo ' FDINITRD=file initrd for the booted kernel'
12331 echo ' kvmconfig - Enable additional options for guest kernel support'
12332 endef
12333 +
12334 +define OLD_LD
12335 +
12336 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12337 +*** Please upgrade your binutils to 2.18 or newer
12338 +endef
12339 +
12340 +archprepare:
12341 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12342 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12343 index d9c1195..a26ca0d 100644
12344 --- a/arch/x86/boot/Makefile
12345 +++ b/arch/x86/boot/Makefile
12346 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
12347 $(call cc-option, -fno-unit-at-a-time)) \
12348 $(call cc-option, -fno-stack-protector) \
12349 $(call cc-option, -mpreferred-stack-boundary=2)
12350 +ifdef CONSTIFY_PLUGIN
12351 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12352 +endif
12353 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12354 GCOV_PROFILE := n
12355
12356 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12357 index 878e4b9..20537ab 100644
12358 --- a/arch/x86/boot/bitops.h
12359 +++ b/arch/x86/boot/bitops.h
12360 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12361 u8 v;
12362 const u32 *p = (const u32 *)addr;
12363
12364 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12365 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12366 return v;
12367 }
12368
12369 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12370
12371 static inline void set_bit(int nr, void *addr)
12372 {
12373 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12374 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12375 }
12376
12377 #endif /* BOOT_BITOPS_H */
12378 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12379 index ef72bae..353a184 100644
12380 --- a/arch/x86/boot/boot.h
12381 +++ b/arch/x86/boot/boot.h
12382 @@ -85,7 +85,7 @@ static inline void io_delay(void)
12383 static inline u16 ds(void)
12384 {
12385 u16 seg;
12386 - asm("movw %%ds,%0" : "=rm" (seg));
12387 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12388 return seg;
12389 }
12390
12391 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12392 static inline int memcmp(const void *s1, const void *s2, size_t len)
12393 {
12394 u8 diff;
12395 - asm("repe; cmpsb; setnz %0"
12396 + asm volatile("repe; cmpsb; setnz %0"
12397 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12398 return diff;
12399 }
12400 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12401 index c8a6792..2402765 100644
12402 --- a/arch/x86/boot/compressed/Makefile
12403 +++ b/arch/x86/boot/compressed/Makefile
12404 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12405 KBUILD_CFLAGS += -mno-mmx -mno-sse
12406 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12407 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12408 +ifdef CONSTIFY_PLUGIN
12409 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12410 +endif
12411
12412 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12413 GCOV_PROFILE := n
12414 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12415 index a53440e..c3dbf1e 100644
12416 --- a/arch/x86/boot/compressed/efi_stub_32.S
12417 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12418 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12419 * parameter 2, ..., param n. To make things easy, we save the return
12420 * address of efi_call_phys in a global variable.
12421 */
12422 - popl %ecx
12423 - movl %ecx, saved_return_addr(%edx)
12424 - /* get the function pointer into ECX*/
12425 - popl %ecx
12426 - movl %ecx, efi_rt_function_ptr(%edx)
12427 + popl saved_return_addr(%edx)
12428 + popl efi_rt_function_ptr(%edx)
12429
12430 /*
12431 * 3. Call the physical function.
12432 */
12433 - call *%ecx
12434 + call *efi_rt_function_ptr(%edx)
12435
12436 /*
12437 * 4. Balance the stack. And because EAX contain the return value,
12438 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12439 1: popl %edx
12440 subl $1b, %edx
12441
12442 - movl efi_rt_function_ptr(%edx), %ecx
12443 - pushl %ecx
12444 + pushl efi_rt_function_ptr(%edx)
12445
12446 /*
12447 * 10. Push the saved return address onto the stack and return.
12448 */
12449 - movl saved_return_addr(%edx), %ecx
12450 - pushl %ecx
12451 - ret
12452 + jmpl *saved_return_addr(%edx)
12453 ENDPROC(efi_call_phys)
12454 .previous
12455
12456 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12457 index 5d6f689..9d06730 100644
12458 --- a/arch/x86/boot/compressed/head_32.S
12459 +++ b/arch/x86/boot/compressed/head_32.S
12460 @@ -118,7 +118,7 @@ preferred_addr:
12461 notl %eax
12462 andl %eax, %ebx
12463 #else
12464 - movl $LOAD_PHYSICAL_ADDR, %ebx
12465 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12466 #endif
12467
12468 /* Target address to relocate to for decompression */
12469 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12470 index c337422..2c5be72 100644
12471 --- a/arch/x86/boot/compressed/head_64.S
12472 +++ b/arch/x86/boot/compressed/head_64.S
12473 @@ -95,7 +95,7 @@ ENTRY(startup_32)
12474 notl %eax
12475 andl %eax, %ebx
12476 #else
12477 - movl $LOAD_PHYSICAL_ADDR, %ebx
12478 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12479 #endif
12480
12481 /* Target address to relocate to for decompression */
12482 @@ -270,7 +270,7 @@ preferred_addr:
12483 notq %rax
12484 andq %rax, %rbp
12485 #else
12486 - movq $LOAD_PHYSICAL_ADDR, %rbp
12487 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12488 #endif
12489
12490 /* Target address to relocate to for decompression */
12491 @@ -362,8 +362,8 @@ gdt:
12492 .long gdt
12493 .word 0
12494 .quad 0x0000000000000000 /* NULL descriptor */
12495 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12496 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12497 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12498 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12499 .quad 0x0080890000000000 /* TS descriptor */
12500 .quad 0x0000000000000000 /* TS continued */
12501 gdt_end:
12502 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12503 index 434f077..f20f3ff 100644
12504 --- a/arch/x86/boot/compressed/misc.c
12505 +++ b/arch/x86/boot/compressed/misc.c
12506 @@ -224,7 +224,7 @@ void __putstr(const char *s)
12507
12508 void *memset(void *s, int c, size_t n)
12509 {
12510 - int i;
12511 + size_t i;
12512 char *ss = s;
12513
12514 for (i = 0; i < n; i++)
12515 @@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12516 * Calculate the delta between where vmlinux was linked to load
12517 * and where it was actually loaded.
12518 */
12519 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12520 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12521 if (!delta) {
12522 debug_putstr("No relocation needed... ");
12523 return;
12524 @@ -353,7 +353,7 @@ static void parse_elf(void *output)
12525 Elf32_Ehdr ehdr;
12526 Elf32_Phdr *phdrs, *phdr;
12527 #endif
12528 - void *dest;
12529 + void *dest, *prev;
12530 int i;
12531
12532 memcpy(&ehdr, output, sizeof(ehdr));
12533 @@ -380,13 +380,16 @@ static void parse_elf(void *output)
12534 case PT_LOAD:
12535 #ifdef CONFIG_RELOCATABLE
12536 dest = output;
12537 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12538 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12539 #else
12540 dest = (void *)(phdr->p_paddr);
12541 #endif
12542 memcpy(dest,
12543 output + phdr->p_offset,
12544 phdr->p_filesz);
12545 + if (i)
12546 + memset(prev, 0xff, dest - prev);
12547 + prev = dest + phdr->p_filesz;
12548 break;
12549 default: /* Ignore other PT_* */ break;
12550 }
12551 @@ -432,7 +435,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12552 error("Destination address too large");
12553 #endif
12554 #ifndef CONFIG_RELOCATABLE
12555 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12556 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12557 error("Wrong destination address");
12558 #endif
12559
12560 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12561 index 4d3ff03..e4972ff 100644
12562 --- a/arch/x86/boot/cpucheck.c
12563 +++ b/arch/x86/boot/cpucheck.c
12564 @@ -74,7 +74,7 @@ static int has_fpu(void)
12565 u16 fcw = -1, fsw = -1;
12566 u32 cr0;
12567
12568 - asm("movl %%cr0,%0" : "=r" (cr0));
12569 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
12570 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12571 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12572 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12573 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12574 {
12575 u32 f0, f1;
12576
12577 - asm("pushfl ; "
12578 + asm volatile("pushfl ; "
12579 "pushfl ; "
12580 "popl %0 ; "
12581 "movl %0,%1 ; "
12582 @@ -115,7 +115,7 @@ static void get_flags(void)
12583 set_bit(X86_FEATURE_FPU, cpu.flags);
12584
12585 if (has_eflag(X86_EFLAGS_ID)) {
12586 - asm("cpuid"
12587 + asm volatile("cpuid"
12588 : "=a" (max_intel_level),
12589 "=b" (cpu_vendor[0]),
12590 "=d" (cpu_vendor[1]),
12591 @@ -124,7 +124,7 @@ static void get_flags(void)
12592
12593 if (max_intel_level >= 0x00000001 &&
12594 max_intel_level <= 0x0000ffff) {
12595 - asm("cpuid"
12596 + asm volatile("cpuid"
12597 : "=a" (tfms),
12598 "=c" (cpu.flags[4]),
12599 "=d" (cpu.flags[0])
12600 @@ -136,7 +136,7 @@ static void get_flags(void)
12601 cpu.model += ((tfms >> 16) & 0xf) << 4;
12602 }
12603
12604 - asm("cpuid"
12605 + asm volatile("cpuid"
12606 : "=a" (max_amd_level)
12607 : "a" (0x80000000)
12608 : "ebx", "ecx", "edx");
12609 @@ -144,7 +144,7 @@ static void get_flags(void)
12610 if (max_amd_level >= 0x80000001 &&
12611 max_amd_level <= 0x8000ffff) {
12612 u32 eax = 0x80000001;
12613 - asm("cpuid"
12614 + asm volatile("cpuid"
12615 : "+a" (eax),
12616 "=c" (cpu.flags[6]),
12617 "=d" (cpu.flags[1])
12618 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12619 u32 ecx = MSR_K7_HWCR;
12620 u32 eax, edx;
12621
12622 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12623 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12624 eax &= ~(1 << 15);
12625 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12626 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12627
12628 get_flags(); /* Make sure it really did something */
12629 err = check_flags();
12630 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12631 u32 ecx = MSR_VIA_FCR;
12632 u32 eax, edx;
12633
12634 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12635 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12636 eax |= (1<<1)|(1<<7);
12637 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12638 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12639
12640 set_bit(X86_FEATURE_CX8, cpu.flags);
12641 err = check_flags();
12642 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12643 u32 eax, edx;
12644 u32 level = 1;
12645
12646 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12647 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12648 - asm("cpuid"
12649 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12650 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12651 + asm volatile("cpuid"
12652 : "+a" (level), "=d" (cpu.flags[0])
12653 : : "ecx", "ebx");
12654 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12655 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12656
12657 err = check_flags();
12658 }
12659 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12660 index 9ec06a1..2c25e79 100644
12661 --- a/arch/x86/boot/header.S
12662 +++ b/arch/x86/boot/header.S
12663 @@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12664 # single linked list of
12665 # struct setup_data
12666
12667 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12668 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12669
12670 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12671 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12672 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12673 +#else
12674 #define VO_INIT_SIZE (VO__end - VO__text)
12675 +#endif
12676 #if ZO_INIT_SIZE > VO_INIT_SIZE
12677 #define INIT_SIZE ZO_INIT_SIZE
12678 #else
12679 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12680 index db75d07..8e6d0af 100644
12681 --- a/arch/x86/boot/memory.c
12682 +++ b/arch/x86/boot/memory.c
12683 @@ -19,7 +19,7 @@
12684
12685 static int detect_memory_e820(void)
12686 {
12687 - int count = 0;
12688 + unsigned int count = 0;
12689 struct biosregs ireg, oreg;
12690 struct e820entry *desc = boot_params.e820_map;
12691 static struct e820entry buf; /* static so it is zeroed */
12692 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12693 index 11e8c6e..fdbb1ed 100644
12694 --- a/arch/x86/boot/video-vesa.c
12695 +++ b/arch/x86/boot/video-vesa.c
12696 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12697
12698 boot_params.screen_info.vesapm_seg = oreg.es;
12699 boot_params.screen_info.vesapm_off = oreg.di;
12700 + boot_params.screen_info.vesapm_size = oreg.cx;
12701 }
12702
12703 /*
12704 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12705 index 43eda28..5ab5fdb 100644
12706 --- a/arch/x86/boot/video.c
12707 +++ b/arch/x86/boot/video.c
12708 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12709 static unsigned int get_entry(void)
12710 {
12711 char entry_buf[4];
12712 - int i, len = 0;
12713 + unsigned int i, len = 0;
12714 int key;
12715 unsigned int v;
12716
12717 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12718 index 9105655..41779c1 100644
12719 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12720 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12721 @@ -8,6 +8,8 @@
12722 * including this sentence is retained in full.
12723 */
12724
12725 +#include <asm/alternative-asm.h>
12726 +
12727 .extern crypto_ft_tab
12728 .extern crypto_it_tab
12729 .extern crypto_fl_tab
12730 @@ -70,6 +72,8 @@
12731 je B192; \
12732 leaq 32(r9),r9;
12733
12734 +#define ret pax_force_retaddr; ret
12735 +
12736 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12737 movq r1,r2; \
12738 movq r3,r4; \
12739 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12740 index 477e9d7..c92c7d8 100644
12741 --- a/arch/x86/crypto/aesni-intel_asm.S
12742 +++ b/arch/x86/crypto/aesni-intel_asm.S
12743 @@ -31,6 +31,7 @@
12744
12745 #include <linux/linkage.h>
12746 #include <asm/inst.h>
12747 +#include <asm/alternative-asm.h>
12748
12749 #ifdef __x86_64__
12750 .data
12751 @@ -205,7 +206,7 @@ enc: .octa 0x2
12752 * num_initial_blocks = b mod 4
12753 * encrypt the initial num_initial_blocks blocks and apply ghash on
12754 * the ciphertext
12755 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12756 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12757 * are clobbered
12758 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12759 */
12760 @@ -214,8 +215,8 @@ enc: .octa 0x2
12761 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12762 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12763 mov arg7, %r10 # %r10 = AAD
12764 - mov arg8, %r12 # %r12 = aadLen
12765 - mov %r12, %r11
12766 + mov arg8, %r15 # %r15 = aadLen
12767 + mov %r15, %r11
12768 pxor %xmm\i, %xmm\i
12769 _get_AAD_loop\num_initial_blocks\operation:
12770 movd (%r10), \TMP1
12771 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12772 psrldq $4, %xmm\i
12773 pxor \TMP1, %xmm\i
12774 add $4, %r10
12775 - sub $4, %r12
12776 + sub $4, %r15
12777 jne _get_AAD_loop\num_initial_blocks\operation
12778 cmp $16, %r11
12779 je _get_AAD_loop2_done\num_initial_blocks\operation
12780 - mov $16, %r12
12781 + mov $16, %r15
12782 _get_AAD_loop2\num_initial_blocks\operation:
12783 psrldq $4, %xmm\i
12784 - sub $4, %r12
12785 - cmp %r11, %r12
12786 + sub $4, %r15
12787 + cmp %r11, %r15
12788 jne _get_AAD_loop2\num_initial_blocks\operation
12789 _get_AAD_loop2_done\num_initial_blocks\operation:
12790 movdqa SHUF_MASK(%rip), %xmm14
12791 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12792 * num_initial_blocks = b mod 4
12793 * encrypt the initial num_initial_blocks blocks and apply ghash on
12794 * the ciphertext
12795 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12796 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12797 * are clobbered
12798 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12799 */
12800 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12801 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12802 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12803 mov arg7, %r10 # %r10 = AAD
12804 - mov arg8, %r12 # %r12 = aadLen
12805 - mov %r12, %r11
12806 + mov arg8, %r15 # %r15 = aadLen
12807 + mov %r15, %r11
12808 pxor %xmm\i, %xmm\i
12809 _get_AAD_loop\num_initial_blocks\operation:
12810 movd (%r10), \TMP1
12811 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12812 psrldq $4, %xmm\i
12813 pxor \TMP1, %xmm\i
12814 add $4, %r10
12815 - sub $4, %r12
12816 + sub $4, %r15
12817 jne _get_AAD_loop\num_initial_blocks\operation
12818 cmp $16, %r11
12819 je _get_AAD_loop2_done\num_initial_blocks\operation
12820 - mov $16, %r12
12821 + mov $16, %r15
12822 _get_AAD_loop2\num_initial_blocks\operation:
12823 psrldq $4, %xmm\i
12824 - sub $4, %r12
12825 - cmp %r11, %r12
12826 + sub $4, %r15
12827 + cmp %r11, %r15
12828 jne _get_AAD_loop2\num_initial_blocks\operation
12829 _get_AAD_loop2_done\num_initial_blocks\operation:
12830 movdqa SHUF_MASK(%rip), %xmm14
12831 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12832 *
12833 *****************************************************************************/
12834 ENTRY(aesni_gcm_dec)
12835 - push %r12
12836 + push %r15
12837 push %r13
12838 push %r14
12839 mov %rsp, %r14
12840 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12841 */
12842 sub $VARIABLE_OFFSET, %rsp
12843 and $~63, %rsp # align rsp to 64 bytes
12844 - mov %arg6, %r12
12845 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12846 + mov %arg6, %r15
12847 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12848 movdqa SHUF_MASK(%rip), %xmm2
12849 PSHUFB_XMM %xmm2, %xmm13
12850
12851 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12852 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12853 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12854 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12855 - mov %r13, %r12
12856 - and $(3<<4), %r12
12857 + mov %r13, %r15
12858 + and $(3<<4), %r15
12859 jz _initial_num_blocks_is_0_decrypt
12860 - cmp $(2<<4), %r12
12861 + cmp $(2<<4), %r15
12862 jb _initial_num_blocks_is_1_decrypt
12863 je _initial_num_blocks_is_2_decrypt
12864 _initial_num_blocks_is_3_decrypt:
12865 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12866 sub $16, %r11
12867 add %r13, %r11
12868 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12869 - lea SHIFT_MASK+16(%rip), %r12
12870 - sub %r13, %r12
12871 + lea SHIFT_MASK+16(%rip), %r15
12872 + sub %r13, %r15
12873 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12874 # (%r13 is the number of bytes in plaintext mod 16)
12875 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12876 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12877 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12878
12879 movdqa %xmm1, %xmm2
12880 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12881 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12882 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12883 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12884 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12885 pand %xmm1, %xmm2
12886 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12887 sub $1, %r13
12888 jne _less_than_8_bytes_left_decrypt
12889 _multiple_of_16_bytes_decrypt:
12890 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12891 - shl $3, %r12 # convert into number of bits
12892 - movd %r12d, %xmm15 # len(A) in %xmm15
12893 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12894 + shl $3, %r15 # convert into number of bits
12895 + movd %r15d, %xmm15 # len(A) in %xmm15
12896 shl $3, %arg4 # len(C) in bits (*128)
12897 MOVQ_R64_XMM %arg4, %xmm1
12898 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12899 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12900 mov %r14, %rsp
12901 pop %r14
12902 pop %r13
12903 - pop %r12
12904 + pop %r15
12905 + pax_force_retaddr
12906 ret
12907 ENDPROC(aesni_gcm_dec)
12908
12909 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12910 * poly = x^128 + x^127 + x^126 + x^121 + 1
12911 ***************************************************************************/
12912 ENTRY(aesni_gcm_enc)
12913 - push %r12
12914 + push %r15
12915 push %r13
12916 push %r14
12917 mov %rsp, %r14
12918 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12919 #
12920 sub $VARIABLE_OFFSET, %rsp
12921 and $~63, %rsp
12922 - mov %arg6, %r12
12923 - movdqu (%r12), %xmm13
12924 + mov %arg6, %r15
12925 + movdqu (%r15), %xmm13
12926 movdqa SHUF_MASK(%rip), %xmm2
12927 PSHUFB_XMM %xmm2, %xmm13
12928
12929 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12930 movdqa %xmm13, HashKey(%rsp)
12931 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12932 and $-16, %r13
12933 - mov %r13, %r12
12934 + mov %r13, %r15
12935
12936 # Encrypt first few blocks
12937
12938 - and $(3<<4), %r12
12939 + and $(3<<4), %r15
12940 jz _initial_num_blocks_is_0_encrypt
12941 - cmp $(2<<4), %r12
12942 + cmp $(2<<4), %r15
12943 jb _initial_num_blocks_is_1_encrypt
12944 je _initial_num_blocks_is_2_encrypt
12945 _initial_num_blocks_is_3_encrypt:
12946 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12947 sub $16, %r11
12948 add %r13, %r11
12949 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12950 - lea SHIFT_MASK+16(%rip), %r12
12951 - sub %r13, %r12
12952 + lea SHIFT_MASK+16(%rip), %r15
12953 + sub %r13, %r15
12954 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12955 # (%r13 is the number of bytes in plaintext mod 16)
12956 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12957 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12958 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12959 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12960 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12961 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12962 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12963 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12964 movdqa SHUF_MASK(%rip), %xmm10
12965 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12966 sub $1, %r13
12967 jne _less_than_8_bytes_left_encrypt
12968 _multiple_of_16_bytes_encrypt:
12969 - mov arg8, %r12 # %r12 = addLen (number of bytes)
12970 - shl $3, %r12
12971 - movd %r12d, %xmm15 # len(A) in %xmm15
12972 + mov arg8, %r15 # %r15 = addLen (number of bytes)
12973 + shl $3, %r15
12974 + movd %r15d, %xmm15 # len(A) in %xmm15
12975 shl $3, %arg4 # len(C) in bits (*128)
12976 MOVQ_R64_XMM %arg4, %xmm1
12977 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12978 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12979 mov %r14, %rsp
12980 pop %r14
12981 pop %r13
12982 - pop %r12
12983 + pop %r15
12984 + pax_force_retaddr
12985 ret
12986 ENDPROC(aesni_gcm_enc)
12987
12988 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
12989 pxor %xmm1, %xmm0
12990 movaps %xmm0, (TKEYP)
12991 add $0x10, TKEYP
12992 + pax_force_retaddr
12993 ret
12994 ENDPROC(_key_expansion_128)
12995 ENDPROC(_key_expansion_256a)
12996 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
12997 shufps $0b01001110, %xmm2, %xmm1
12998 movaps %xmm1, 0x10(TKEYP)
12999 add $0x20, TKEYP
13000 + pax_force_retaddr
13001 ret
13002 ENDPROC(_key_expansion_192a)
13003
13004 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13005
13006 movaps %xmm0, (TKEYP)
13007 add $0x10, TKEYP
13008 + pax_force_retaddr
13009 ret
13010 ENDPROC(_key_expansion_192b)
13011
13012 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13013 pxor %xmm1, %xmm2
13014 movaps %xmm2, (TKEYP)
13015 add $0x10, TKEYP
13016 + pax_force_retaddr
13017 ret
13018 ENDPROC(_key_expansion_256b)
13019
13020 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13021 #ifndef __x86_64__
13022 popl KEYP
13023 #endif
13024 + pax_force_retaddr
13025 ret
13026 ENDPROC(aesni_set_key)
13027
13028 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13029 popl KLEN
13030 popl KEYP
13031 #endif
13032 + pax_force_retaddr
13033 ret
13034 ENDPROC(aesni_enc)
13035
13036 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13037 AESENC KEY STATE
13038 movaps 0x70(TKEYP), KEY
13039 AESENCLAST KEY STATE
13040 + pax_force_retaddr
13041 ret
13042 ENDPROC(_aesni_enc1)
13043
13044 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13045 AESENCLAST KEY STATE2
13046 AESENCLAST KEY STATE3
13047 AESENCLAST KEY STATE4
13048 + pax_force_retaddr
13049 ret
13050 ENDPROC(_aesni_enc4)
13051
13052 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13053 popl KLEN
13054 popl KEYP
13055 #endif
13056 + pax_force_retaddr
13057 ret
13058 ENDPROC(aesni_dec)
13059
13060 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13061 AESDEC KEY STATE
13062 movaps 0x70(TKEYP), KEY
13063 AESDECLAST KEY STATE
13064 + pax_force_retaddr
13065 ret
13066 ENDPROC(_aesni_dec1)
13067
13068 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13069 AESDECLAST KEY STATE2
13070 AESDECLAST KEY STATE3
13071 AESDECLAST KEY STATE4
13072 + pax_force_retaddr
13073 ret
13074 ENDPROC(_aesni_dec4)
13075
13076 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13077 popl KEYP
13078 popl LEN
13079 #endif
13080 + pax_force_retaddr
13081 ret
13082 ENDPROC(aesni_ecb_enc)
13083
13084 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13085 popl KEYP
13086 popl LEN
13087 #endif
13088 + pax_force_retaddr
13089 ret
13090 ENDPROC(aesni_ecb_dec)
13091
13092 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13093 popl LEN
13094 popl IVP
13095 #endif
13096 + pax_force_retaddr
13097 ret
13098 ENDPROC(aesni_cbc_enc)
13099
13100 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13101 popl LEN
13102 popl IVP
13103 #endif
13104 + pax_force_retaddr
13105 ret
13106 ENDPROC(aesni_cbc_dec)
13107
13108 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13109 mov $1, TCTR_LOW
13110 MOVQ_R64_XMM TCTR_LOW INC
13111 MOVQ_R64_XMM CTR TCTR_LOW
13112 + pax_force_retaddr
13113 ret
13114 ENDPROC(_aesni_inc_init)
13115
13116 @@ -2579,6 +2598,7 @@ _aesni_inc:
13117 .Linc_low:
13118 movaps CTR, IV
13119 PSHUFB_XMM BSWAP_MASK IV
13120 + pax_force_retaddr
13121 ret
13122 ENDPROC(_aesni_inc)
13123
13124 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13125 .Lctr_enc_ret:
13126 movups IV, (IVP)
13127 .Lctr_enc_just_ret:
13128 + pax_force_retaddr
13129 ret
13130 ENDPROC(aesni_ctr_enc)
13131
13132 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13133 pxor INC, STATE4
13134 movdqu STATE4, 0x70(OUTP)
13135
13136 + pax_force_retaddr
13137 ret
13138 ENDPROC(aesni_xts_crypt8)
13139
13140 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13141 index 246c670..466e2d6 100644
13142 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13143 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13144 @@ -21,6 +21,7 @@
13145 */
13146
13147 #include <linux/linkage.h>
13148 +#include <asm/alternative-asm.h>
13149
13150 .file "blowfish-x86_64-asm.S"
13151 .text
13152 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13153 jnz .L__enc_xor;
13154
13155 write_block();
13156 + pax_force_retaddr
13157 ret;
13158 .L__enc_xor:
13159 xor_block();
13160 + pax_force_retaddr
13161 ret;
13162 ENDPROC(__blowfish_enc_blk)
13163
13164 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13165
13166 movq %r11, %rbp;
13167
13168 + pax_force_retaddr
13169 ret;
13170 ENDPROC(blowfish_dec_blk)
13171
13172 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13173
13174 popq %rbx;
13175 popq %rbp;
13176 + pax_force_retaddr
13177 ret;
13178
13179 .L__enc_xor4:
13180 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13181
13182 popq %rbx;
13183 popq %rbp;
13184 + pax_force_retaddr
13185 ret;
13186 ENDPROC(__blowfish_enc_blk_4way)
13187
13188 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13189 popq %rbx;
13190 popq %rbp;
13191
13192 + pax_force_retaddr
13193 ret;
13194 ENDPROC(blowfish_dec_blk_4way)
13195 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13196 index ce71f92..1dce7ec 100644
13197 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13198 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13199 @@ -16,6 +16,7 @@
13200 */
13201
13202 #include <linux/linkage.h>
13203 +#include <asm/alternative-asm.h>
13204
13205 #define CAMELLIA_TABLE_BYTE_LEN 272
13206
13207 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13208 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13209 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13210 %rcx, (%r9));
13211 + pax_force_retaddr
13212 ret;
13213 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13214
13215 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13216 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13217 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13218 %rax, (%r9));
13219 + pax_force_retaddr
13220 ret;
13221 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13222
13223 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13224 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13225 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13226
13227 + pax_force_retaddr
13228 ret;
13229
13230 .align 8
13231 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13232 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13233 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13234
13235 + pax_force_retaddr
13236 ret;
13237
13238 .align 8
13239 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13240 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13241 %xmm8, %rsi);
13242
13243 + pax_force_retaddr
13244 ret;
13245 ENDPROC(camellia_ecb_enc_16way)
13246
13247 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13248 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13249 %xmm8, %rsi);
13250
13251 + pax_force_retaddr
13252 ret;
13253 ENDPROC(camellia_ecb_dec_16way)
13254
13255 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13256 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13257 %xmm8, %rsi);
13258
13259 + pax_force_retaddr
13260 ret;
13261 ENDPROC(camellia_cbc_dec_16way)
13262
13263 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13264 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13265 %xmm8, %rsi);
13266
13267 + pax_force_retaddr
13268 ret;
13269 ENDPROC(camellia_ctr_16way)
13270
13271 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13272 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13273 %xmm8, %rsi);
13274
13275 + pax_force_retaddr
13276 ret;
13277 ENDPROC(camellia_xts_crypt_16way)
13278
13279 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13280 index 0e0b886..5a3123c 100644
13281 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13282 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13283 @@ -11,6 +11,7 @@
13284 */
13285
13286 #include <linux/linkage.h>
13287 +#include <asm/alternative-asm.h>
13288
13289 #define CAMELLIA_TABLE_BYTE_LEN 272
13290
13291 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13292 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13293 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13294 %rcx, (%r9));
13295 + pax_force_retaddr
13296 ret;
13297 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13298
13299 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13300 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13301 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13302 %rax, (%r9));
13303 + pax_force_retaddr
13304 ret;
13305 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13306
13307 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13308 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13309 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13310
13311 + pax_force_retaddr
13312 ret;
13313
13314 .align 8
13315 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13316 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13317 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13318
13319 + pax_force_retaddr
13320 ret;
13321
13322 .align 8
13323 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13324
13325 vzeroupper;
13326
13327 + pax_force_retaddr
13328 ret;
13329 ENDPROC(camellia_ecb_enc_32way)
13330
13331 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13332
13333 vzeroupper;
13334
13335 + pax_force_retaddr
13336 ret;
13337 ENDPROC(camellia_ecb_dec_32way)
13338
13339 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13340
13341 vzeroupper;
13342
13343 + pax_force_retaddr
13344 ret;
13345 ENDPROC(camellia_cbc_dec_32way)
13346
13347 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13348
13349 vzeroupper;
13350
13351 + pax_force_retaddr
13352 ret;
13353 ENDPROC(camellia_ctr_32way)
13354
13355 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13356
13357 vzeroupper;
13358
13359 + pax_force_retaddr
13360 ret;
13361 ENDPROC(camellia_xts_crypt_32way)
13362
13363 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13364 index 310319c..db3d7b5 100644
13365 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13366 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13367 @@ -21,6 +21,7 @@
13368 */
13369
13370 #include <linux/linkage.h>
13371 +#include <asm/alternative-asm.h>
13372
13373 .file "camellia-x86_64-asm_64.S"
13374 .text
13375 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13376 enc_outunpack(mov, RT1);
13377
13378 movq RRBP, %rbp;
13379 + pax_force_retaddr
13380 ret;
13381
13382 .L__enc_xor:
13383 enc_outunpack(xor, RT1);
13384
13385 movq RRBP, %rbp;
13386 + pax_force_retaddr
13387 ret;
13388 ENDPROC(__camellia_enc_blk)
13389
13390 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13391 dec_outunpack();
13392
13393 movq RRBP, %rbp;
13394 + pax_force_retaddr
13395 ret;
13396 ENDPROC(camellia_dec_blk)
13397
13398 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13399
13400 movq RRBP, %rbp;
13401 popq %rbx;
13402 + pax_force_retaddr
13403 ret;
13404
13405 .L__enc2_xor:
13406 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13407
13408 movq RRBP, %rbp;
13409 popq %rbx;
13410 + pax_force_retaddr
13411 ret;
13412 ENDPROC(__camellia_enc_blk_2way)
13413
13414 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13415
13416 movq RRBP, %rbp;
13417 movq RXOR, %rbx;
13418 + pax_force_retaddr
13419 ret;
13420 ENDPROC(camellia_dec_blk_2way)
13421 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13422 index c35fd5d..2d8c7db 100644
13423 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13424 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13425 @@ -24,6 +24,7 @@
13426 */
13427
13428 #include <linux/linkage.h>
13429 +#include <asm/alternative-asm.h>
13430
13431 .file "cast5-avx-x86_64-asm_64.S"
13432
13433 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13434 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13435 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13436
13437 + pax_force_retaddr
13438 ret;
13439 ENDPROC(__cast5_enc_blk16)
13440
13441 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13442 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13443 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13444
13445 + pax_force_retaddr
13446 ret;
13447
13448 .L__skip_dec:
13449 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13450 vmovdqu RR4, (6*4*4)(%r11);
13451 vmovdqu RL4, (7*4*4)(%r11);
13452
13453 + pax_force_retaddr
13454 ret;
13455 ENDPROC(cast5_ecb_enc_16way)
13456
13457 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13458 vmovdqu RR4, (6*4*4)(%r11);
13459 vmovdqu RL4, (7*4*4)(%r11);
13460
13461 + pax_force_retaddr
13462 ret;
13463 ENDPROC(cast5_ecb_dec_16way)
13464
13465 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13466 * %rdx: src
13467 */
13468
13469 - pushq %r12;
13470 + pushq %r14;
13471
13472 movq %rsi, %r11;
13473 - movq %rdx, %r12;
13474 + movq %rdx, %r14;
13475
13476 vmovdqu (0*16)(%rdx), RL1;
13477 vmovdqu (1*16)(%rdx), RR1;
13478 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13479 call __cast5_dec_blk16;
13480
13481 /* xor with src */
13482 - vmovq (%r12), RX;
13483 + vmovq (%r14), RX;
13484 vpshufd $0x4f, RX, RX;
13485 vpxor RX, RR1, RR1;
13486 - vpxor 0*16+8(%r12), RL1, RL1;
13487 - vpxor 1*16+8(%r12), RR2, RR2;
13488 - vpxor 2*16+8(%r12), RL2, RL2;
13489 - vpxor 3*16+8(%r12), RR3, RR3;
13490 - vpxor 4*16+8(%r12), RL3, RL3;
13491 - vpxor 5*16+8(%r12), RR4, RR4;
13492 - vpxor 6*16+8(%r12), RL4, RL4;
13493 + vpxor 0*16+8(%r14), RL1, RL1;
13494 + vpxor 1*16+8(%r14), RR2, RR2;
13495 + vpxor 2*16+8(%r14), RL2, RL2;
13496 + vpxor 3*16+8(%r14), RR3, RR3;
13497 + vpxor 4*16+8(%r14), RL3, RL3;
13498 + vpxor 5*16+8(%r14), RR4, RR4;
13499 + vpxor 6*16+8(%r14), RL4, RL4;
13500
13501 vmovdqu RR1, (0*16)(%r11);
13502 vmovdqu RL1, (1*16)(%r11);
13503 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13504 vmovdqu RR4, (6*16)(%r11);
13505 vmovdqu RL4, (7*16)(%r11);
13506
13507 - popq %r12;
13508 + popq %r14;
13509
13510 + pax_force_retaddr
13511 ret;
13512 ENDPROC(cast5_cbc_dec_16way)
13513
13514 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13515 * %rcx: iv (big endian, 64bit)
13516 */
13517
13518 - pushq %r12;
13519 + pushq %r14;
13520
13521 movq %rsi, %r11;
13522 - movq %rdx, %r12;
13523 + movq %rdx, %r14;
13524
13525 vpcmpeqd RTMP, RTMP, RTMP;
13526 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13527 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13528 call __cast5_enc_blk16;
13529
13530 /* dst = src ^ iv */
13531 - vpxor (0*16)(%r12), RR1, RR1;
13532 - vpxor (1*16)(%r12), RL1, RL1;
13533 - vpxor (2*16)(%r12), RR2, RR2;
13534 - vpxor (3*16)(%r12), RL2, RL2;
13535 - vpxor (4*16)(%r12), RR3, RR3;
13536 - vpxor (5*16)(%r12), RL3, RL3;
13537 - vpxor (6*16)(%r12), RR4, RR4;
13538 - vpxor (7*16)(%r12), RL4, RL4;
13539 + vpxor (0*16)(%r14), RR1, RR1;
13540 + vpxor (1*16)(%r14), RL1, RL1;
13541 + vpxor (2*16)(%r14), RR2, RR2;
13542 + vpxor (3*16)(%r14), RL2, RL2;
13543 + vpxor (4*16)(%r14), RR3, RR3;
13544 + vpxor (5*16)(%r14), RL3, RL3;
13545 + vpxor (6*16)(%r14), RR4, RR4;
13546 + vpxor (7*16)(%r14), RL4, RL4;
13547 vmovdqu RR1, (0*16)(%r11);
13548 vmovdqu RL1, (1*16)(%r11);
13549 vmovdqu RR2, (2*16)(%r11);
13550 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13551 vmovdqu RR4, (6*16)(%r11);
13552 vmovdqu RL4, (7*16)(%r11);
13553
13554 - popq %r12;
13555 + popq %r14;
13556
13557 + pax_force_retaddr
13558 ret;
13559 ENDPROC(cast5_ctr_16way)
13560 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13561 index e3531f8..e123f35 100644
13562 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13563 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13564 @@ -24,6 +24,7 @@
13565 */
13566
13567 #include <linux/linkage.h>
13568 +#include <asm/alternative-asm.h>
13569 #include "glue_helper-asm-avx.S"
13570
13571 .file "cast6-avx-x86_64-asm_64.S"
13572 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13573 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13574 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13575
13576 + pax_force_retaddr
13577 ret;
13578 ENDPROC(__cast6_enc_blk8)
13579
13580 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13581 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13582 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13583
13584 + pax_force_retaddr
13585 ret;
13586 ENDPROC(__cast6_dec_blk8)
13587
13588 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13589
13590 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13591
13592 + pax_force_retaddr
13593 ret;
13594 ENDPROC(cast6_ecb_enc_8way)
13595
13596 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13597
13598 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13599
13600 + pax_force_retaddr
13601 ret;
13602 ENDPROC(cast6_ecb_dec_8way)
13603
13604 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13605 * %rdx: src
13606 */
13607
13608 - pushq %r12;
13609 + pushq %r14;
13610
13611 movq %rsi, %r11;
13612 - movq %rdx, %r12;
13613 + movq %rdx, %r14;
13614
13615 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13616
13617 call __cast6_dec_blk8;
13618
13619 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13620 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13621
13622 - popq %r12;
13623 + popq %r14;
13624
13625 + pax_force_retaddr
13626 ret;
13627 ENDPROC(cast6_cbc_dec_8way)
13628
13629 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13630 * %rcx: iv (little endian, 128bit)
13631 */
13632
13633 - pushq %r12;
13634 + pushq %r14;
13635
13636 movq %rsi, %r11;
13637 - movq %rdx, %r12;
13638 + movq %rdx, %r14;
13639
13640 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13641 RD2, RX, RKR, RKM);
13642
13643 call __cast6_enc_blk8;
13644
13645 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13646 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13647
13648 - popq %r12;
13649 + popq %r14;
13650
13651 + pax_force_retaddr
13652 ret;
13653 ENDPROC(cast6_ctr_8way)
13654
13655 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13656 /* dst <= regs xor IVs(in dst) */
13657 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13658
13659 + pax_force_retaddr
13660 ret;
13661 ENDPROC(cast6_xts_enc_8way)
13662
13663 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13664 /* dst <= regs xor IVs(in dst) */
13665 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13666
13667 + pax_force_retaddr
13668 ret;
13669 ENDPROC(cast6_xts_dec_8way)
13670 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13671 index dbc4339..de6e120 100644
13672 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13673 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13674 @@ -45,6 +45,7 @@
13675
13676 #include <asm/inst.h>
13677 #include <linux/linkage.h>
13678 +#include <asm/alternative-asm.h>
13679
13680 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13681
13682 @@ -312,6 +313,7 @@ do_return:
13683 popq %rsi
13684 popq %rdi
13685 popq %rbx
13686 + pax_force_retaddr
13687 ret
13688
13689 ################################################################
13690 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13691 index 586f41a..d02851e 100644
13692 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13693 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13694 @@ -18,6 +18,7 @@
13695
13696 #include <linux/linkage.h>
13697 #include <asm/inst.h>
13698 +#include <asm/alternative-asm.h>
13699
13700 .data
13701
13702 @@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13703 psrlq $1, T2
13704 pxor T2, T1
13705 pxor T1, DATA
13706 + pax_force_retaddr
13707 ret
13708 ENDPROC(__clmul_gf128mul_ble)
13709
13710 @@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13711 call __clmul_gf128mul_ble
13712 PSHUFB_XMM BSWAP DATA
13713 movups DATA, (%rdi)
13714 + pax_force_retaddr
13715 ret
13716 ENDPROC(clmul_ghash_mul)
13717
13718 @@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13719 PSHUFB_XMM BSWAP DATA
13720 movups DATA, (%rdi)
13721 .Lupdate_just_ret:
13722 + pax_force_retaddr
13723 ret
13724 ENDPROC(clmul_ghash_update)
13725
13726 @@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13727 pand .Lpoly, %xmm1
13728 pxor %xmm1, %xmm0
13729 movups %xmm0, (%rdi)
13730 + pax_force_retaddr
13731 ret
13732 ENDPROC(clmul_ghash_setkey)
13733 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13734 index 9279e0b..c4b3d2c 100644
13735 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13736 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13737 @@ -1,4 +1,5 @@
13738 #include <linux/linkage.h>
13739 +#include <asm/alternative-asm.h>
13740
13741 # enter salsa20_encrypt_bytes
13742 ENTRY(salsa20_encrypt_bytes)
13743 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13744 add %r11,%rsp
13745 mov %rdi,%rax
13746 mov %rsi,%rdx
13747 + pax_force_retaddr
13748 ret
13749 # bytesatleast65:
13750 ._bytesatleast65:
13751 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13752 add %r11,%rsp
13753 mov %rdi,%rax
13754 mov %rsi,%rdx
13755 + pax_force_retaddr
13756 ret
13757 ENDPROC(salsa20_keysetup)
13758
13759 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13760 add %r11,%rsp
13761 mov %rdi,%rax
13762 mov %rsi,%rdx
13763 + pax_force_retaddr
13764 ret
13765 ENDPROC(salsa20_ivsetup)
13766 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13767 index 2f202f4..d9164d6 100644
13768 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13769 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13770 @@ -24,6 +24,7 @@
13771 */
13772
13773 #include <linux/linkage.h>
13774 +#include <asm/alternative-asm.h>
13775 #include "glue_helper-asm-avx.S"
13776
13777 .file "serpent-avx-x86_64-asm_64.S"
13778 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13779 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13780 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13781
13782 + pax_force_retaddr
13783 ret;
13784 ENDPROC(__serpent_enc_blk8_avx)
13785
13786 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13787 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13788 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13789
13790 + pax_force_retaddr
13791 ret;
13792 ENDPROC(__serpent_dec_blk8_avx)
13793
13794 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13795
13796 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13797
13798 + pax_force_retaddr
13799 ret;
13800 ENDPROC(serpent_ecb_enc_8way_avx)
13801
13802 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13803
13804 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13805
13806 + pax_force_retaddr
13807 ret;
13808 ENDPROC(serpent_ecb_dec_8way_avx)
13809
13810 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13811
13812 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13813
13814 + pax_force_retaddr
13815 ret;
13816 ENDPROC(serpent_cbc_dec_8way_avx)
13817
13818 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13819
13820 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13821
13822 + pax_force_retaddr
13823 ret;
13824 ENDPROC(serpent_ctr_8way_avx)
13825
13826 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13827 /* dst <= regs xor IVs(in dst) */
13828 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13829
13830 + pax_force_retaddr
13831 ret;
13832 ENDPROC(serpent_xts_enc_8way_avx)
13833
13834 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13835 /* dst <= regs xor IVs(in dst) */
13836 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13837
13838 + pax_force_retaddr
13839 ret;
13840 ENDPROC(serpent_xts_dec_8way_avx)
13841 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13842 index b222085..abd483c 100644
13843 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13844 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13845 @@ -15,6 +15,7 @@
13846 */
13847
13848 #include <linux/linkage.h>
13849 +#include <asm/alternative-asm.h>
13850 #include "glue_helper-asm-avx2.S"
13851
13852 .file "serpent-avx2-asm_64.S"
13853 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13854 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13855 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13856
13857 + pax_force_retaddr
13858 ret;
13859 ENDPROC(__serpent_enc_blk16)
13860
13861 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13862 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13863 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13864
13865 + pax_force_retaddr
13866 ret;
13867 ENDPROC(__serpent_dec_blk16)
13868
13869 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13870
13871 vzeroupper;
13872
13873 + pax_force_retaddr
13874 ret;
13875 ENDPROC(serpent_ecb_enc_16way)
13876
13877 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13878
13879 vzeroupper;
13880
13881 + pax_force_retaddr
13882 ret;
13883 ENDPROC(serpent_ecb_dec_16way)
13884
13885 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13886
13887 vzeroupper;
13888
13889 + pax_force_retaddr
13890 ret;
13891 ENDPROC(serpent_cbc_dec_16way)
13892
13893 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13894
13895 vzeroupper;
13896
13897 + pax_force_retaddr
13898 ret;
13899 ENDPROC(serpent_ctr_16way)
13900
13901 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13902
13903 vzeroupper;
13904
13905 + pax_force_retaddr
13906 ret;
13907 ENDPROC(serpent_xts_enc_16way)
13908
13909 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13910
13911 vzeroupper;
13912
13913 + pax_force_retaddr
13914 ret;
13915 ENDPROC(serpent_xts_dec_16way)
13916 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13917 index acc066c..1559cc4 100644
13918 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13919 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13920 @@ -25,6 +25,7 @@
13921 */
13922
13923 #include <linux/linkage.h>
13924 +#include <asm/alternative-asm.h>
13925
13926 .file "serpent-sse2-x86_64-asm_64.S"
13927 .text
13928 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13929 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13930 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13931
13932 + pax_force_retaddr
13933 ret;
13934
13935 .L__enc_xor8:
13936 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13937 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13938
13939 + pax_force_retaddr
13940 ret;
13941 ENDPROC(__serpent_enc_blk_8way)
13942
13943 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13944 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13945 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13946
13947 + pax_force_retaddr
13948 ret;
13949 ENDPROC(serpent_dec_blk_8way)
13950 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13951 index a410950..9dfe7ad 100644
13952 --- a/arch/x86/crypto/sha1_ssse3_asm.S
13953 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
13954 @@ -29,6 +29,7 @@
13955 */
13956
13957 #include <linux/linkage.h>
13958 +#include <asm/alternative-asm.h>
13959
13960 #define CTX %rdi // arg1
13961 #define BUF %rsi // arg2
13962 @@ -75,9 +76,9 @@
13963
13964 push %rbx
13965 push %rbp
13966 - push %r12
13967 + push %r14
13968
13969 - mov %rsp, %r12
13970 + mov %rsp, %r14
13971 sub $64, %rsp # allocate workspace
13972 and $~15, %rsp # align stack
13973
13974 @@ -99,11 +100,12 @@
13975 xor %rax, %rax
13976 rep stosq
13977
13978 - mov %r12, %rsp # deallocate workspace
13979 + mov %r14, %rsp # deallocate workspace
13980
13981 - pop %r12
13982 + pop %r14
13983 pop %rbp
13984 pop %rbx
13985 + pax_force_retaddr
13986 ret
13987
13988 ENDPROC(\name)
13989 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13990 index 642f156..51a513c 100644
13991 --- a/arch/x86/crypto/sha256-avx-asm.S
13992 +++ b/arch/x86/crypto/sha256-avx-asm.S
13993 @@ -49,6 +49,7 @@
13994
13995 #ifdef CONFIG_AS_AVX
13996 #include <linux/linkage.h>
13997 +#include <asm/alternative-asm.h>
13998
13999 ## assume buffers not aligned
14000 #define VMOVDQ vmovdqu
14001 @@ -460,6 +461,7 @@ done_hash:
14002 popq %r13
14003 popq %rbp
14004 popq %rbx
14005 + pax_force_retaddr
14006 ret
14007 ENDPROC(sha256_transform_avx)
14008
14009 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14010 index 9e86944..3795e6a 100644
14011 --- a/arch/x86/crypto/sha256-avx2-asm.S
14012 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14013 @@ -50,6 +50,7 @@
14014
14015 #ifdef CONFIG_AS_AVX2
14016 #include <linux/linkage.h>
14017 +#include <asm/alternative-asm.h>
14018
14019 ## assume buffers not aligned
14020 #define VMOVDQ vmovdqu
14021 @@ -720,6 +721,7 @@ done_hash:
14022 popq %r12
14023 popq %rbp
14024 popq %rbx
14025 + pax_force_retaddr
14026 ret
14027 ENDPROC(sha256_transform_rorx)
14028
14029 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14030 index f833b74..8c62a9e 100644
14031 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14032 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14033 @@ -47,6 +47,7 @@
14034 ########################################################################
14035
14036 #include <linux/linkage.h>
14037 +#include <asm/alternative-asm.h>
14038
14039 ## assume buffers not aligned
14040 #define MOVDQ movdqu
14041 @@ -471,6 +472,7 @@ done_hash:
14042 popq %rbp
14043 popq %rbx
14044
14045 + pax_force_retaddr
14046 ret
14047 ENDPROC(sha256_transform_ssse3)
14048
14049 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14050 index 974dde9..a823ff9 100644
14051 --- a/arch/x86/crypto/sha512-avx-asm.S
14052 +++ b/arch/x86/crypto/sha512-avx-asm.S
14053 @@ -49,6 +49,7 @@
14054
14055 #ifdef CONFIG_AS_AVX
14056 #include <linux/linkage.h>
14057 +#include <asm/alternative-asm.h>
14058
14059 .text
14060
14061 @@ -364,6 +365,7 @@ updateblock:
14062 mov frame_RSPSAVE(%rsp), %rsp
14063
14064 nowork:
14065 + pax_force_retaddr
14066 ret
14067 ENDPROC(sha512_transform_avx)
14068
14069 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14070 index 568b961..ed20c37 100644
14071 --- a/arch/x86/crypto/sha512-avx2-asm.S
14072 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14073 @@ -51,6 +51,7 @@
14074
14075 #ifdef CONFIG_AS_AVX2
14076 #include <linux/linkage.h>
14077 +#include <asm/alternative-asm.h>
14078
14079 .text
14080
14081 @@ -678,6 +679,7 @@ done_hash:
14082
14083 # Restore Stack Pointer
14084 mov frame_RSPSAVE(%rsp), %rsp
14085 + pax_force_retaddr
14086 ret
14087 ENDPROC(sha512_transform_rorx)
14088
14089 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14090 index fb56855..6edd768 100644
14091 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14092 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14093 @@ -48,6 +48,7 @@
14094 ########################################################################
14095
14096 #include <linux/linkage.h>
14097 +#include <asm/alternative-asm.h>
14098
14099 .text
14100
14101 @@ -363,6 +364,7 @@ updateblock:
14102 mov frame_RSPSAVE(%rsp), %rsp
14103
14104 nowork:
14105 + pax_force_retaddr
14106 ret
14107 ENDPROC(sha512_transform_ssse3)
14108
14109 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14110 index 0505813..b067311 100644
14111 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14112 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14113 @@ -24,6 +24,7 @@
14114 */
14115
14116 #include <linux/linkage.h>
14117 +#include <asm/alternative-asm.h>
14118 #include "glue_helper-asm-avx.S"
14119
14120 .file "twofish-avx-x86_64-asm_64.S"
14121 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14122 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14123 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14124
14125 + pax_force_retaddr
14126 ret;
14127 ENDPROC(__twofish_enc_blk8)
14128
14129 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14130 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14131 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14132
14133 + pax_force_retaddr
14134 ret;
14135 ENDPROC(__twofish_dec_blk8)
14136
14137 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14138
14139 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14140
14141 + pax_force_retaddr
14142 ret;
14143 ENDPROC(twofish_ecb_enc_8way)
14144
14145 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14146
14147 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14148
14149 + pax_force_retaddr
14150 ret;
14151 ENDPROC(twofish_ecb_dec_8way)
14152
14153 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14154 * %rdx: src
14155 */
14156
14157 - pushq %r12;
14158 + pushq %r14;
14159
14160 movq %rsi, %r11;
14161 - movq %rdx, %r12;
14162 + movq %rdx, %r14;
14163
14164 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14165
14166 call __twofish_dec_blk8;
14167
14168 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14169 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14170
14171 - popq %r12;
14172 + popq %r14;
14173
14174 + pax_force_retaddr
14175 ret;
14176 ENDPROC(twofish_cbc_dec_8way)
14177
14178 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14179 * %rcx: iv (little endian, 128bit)
14180 */
14181
14182 - pushq %r12;
14183 + pushq %r14;
14184
14185 movq %rsi, %r11;
14186 - movq %rdx, %r12;
14187 + movq %rdx, %r14;
14188
14189 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14190 RD2, RX0, RX1, RY0);
14191
14192 call __twofish_enc_blk8;
14193
14194 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14195 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14196
14197 - popq %r12;
14198 + popq %r14;
14199
14200 + pax_force_retaddr
14201 ret;
14202 ENDPROC(twofish_ctr_8way)
14203
14204 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14205 /* dst <= regs xor IVs(in dst) */
14206 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14207
14208 + pax_force_retaddr
14209 ret;
14210 ENDPROC(twofish_xts_enc_8way)
14211
14212 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14213 /* dst <= regs xor IVs(in dst) */
14214 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14215
14216 + pax_force_retaddr
14217 ret;
14218 ENDPROC(twofish_xts_dec_8way)
14219 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14220 index 1c3b7ce..02f578d 100644
14221 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14222 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14223 @@ -21,6 +21,7 @@
14224 */
14225
14226 #include <linux/linkage.h>
14227 +#include <asm/alternative-asm.h>
14228
14229 .file "twofish-x86_64-asm-3way.S"
14230 .text
14231 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14232 popq %r13;
14233 popq %r14;
14234 popq %r15;
14235 + pax_force_retaddr
14236 ret;
14237
14238 .L__enc_xor3:
14239 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14240 popq %r13;
14241 popq %r14;
14242 popq %r15;
14243 + pax_force_retaddr
14244 ret;
14245 ENDPROC(__twofish_enc_blk_3way)
14246
14247 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14248 popq %r13;
14249 popq %r14;
14250 popq %r15;
14251 + pax_force_retaddr
14252 ret;
14253 ENDPROC(twofish_dec_blk_3way)
14254 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14255 index a039d21..524b8b2 100644
14256 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14257 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14258 @@ -22,6 +22,7 @@
14259
14260 #include <linux/linkage.h>
14261 #include <asm/asm-offsets.h>
14262 +#include <asm/alternative-asm.h>
14263
14264 #define a_offset 0
14265 #define b_offset 4
14266 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14267
14268 popq R1
14269 movq $1,%rax
14270 + pax_force_retaddr
14271 ret
14272 ENDPROC(twofish_enc_blk)
14273
14274 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14275
14276 popq R1
14277 movq $1,%rax
14278 + pax_force_retaddr
14279 ret
14280 ENDPROC(twofish_dec_blk)
14281 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14282 index d21ff89..6da8e6e 100644
14283 --- a/arch/x86/ia32/ia32_aout.c
14284 +++ b/arch/x86/ia32/ia32_aout.c
14285 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14286 unsigned long dump_start, dump_size;
14287 struct user32 dump;
14288
14289 + memset(&dump, 0, sizeof(dump));
14290 +
14291 fs = get_fs();
14292 set_fs(KERNEL_DS);
14293 has_dumped = 1;
14294 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14295 index 2206757..85cbcfa 100644
14296 --- a/arch/x86/ia32/ia32_signal.c
14297 +++ b/arch/x86/ia32/ia32_signal.c
14298 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14299 if (__get_user(set.sig[0], &frame->sc.oldmask)
14300 || (_COMPAT_NSIG_WORDS > 1
14301 && __copy_from_user((((char *) &set.sig) + 4),
14302 - &frame->extramask,
14303 + frame->extramask,
14304 sizeof(frame->extramask))))
14305 goto badframe;
14306
14307 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14308 sp -= frame_size;
14309 /* Align the stack pointer according to the i386 ABI,
14310 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14311 - sp = ((sp + 4) & -16ul) - 4;
14312 + sp = ((sp - 12) & -16ul) - 4;
14313 return (void __user *) sp;
14314 }
14315
14316 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14317 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14318 sigreturn);
14319 else
14320 - restorer = &frame->retcode;
14321 + restorer = frame->retcode;
14322 }
14323
14324 put_user_try {
14325 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14326 * These are actually not used anymore, but left because some
14327 * gdb versions depend on them as a marker.
14328 */
14329 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14330 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14331 } put_user_catch(err);
14332
14333 if (err)
14334 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14335 0xb8,
14336 __NR_ia32_rt_sigreturn,
14337 0x80cd,
14338 - 0,
14339 + 0
14340 };
14341
14342 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14343 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14344
14345 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14346 restorer = ksig->ka.sa.sa_restorer;
14347 + else if (current->mm->context.vdso)
14348 + /* Return stub is in 32bit vsyscall page */
14349 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14350 else
14351 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14352 - rt_sigreturn);
14353 + restorer = frame->retcode;
14354 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14355
14356 /*
14357 * Not actually used anymore, but left because some gdb
14358 * versions need it.
14359 */
14360 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14361 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14362 } put_user_catch(err);
14363
14364 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14365 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14366 index 4299eb0..c0687a7 100644
14367 --- a/arch/x86/ia32/ia32entry.S
14368 +++ b/arch/x86/ia32/ia32entry.S
14369 @@ -15,8 +15,10 @@
14370 #include <asm/irqflags.h>
14371 #include <asm/asm.h>
14372 #include <asm/smap.h>
14373 +#include <asm/pgtable.h>
14374 #include <linux/linkage.h>
14375 #include <linux/err.h>
14376 +#include <asm/alternative-asm.h>
14377
14378 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14379 #include <linux/elf-em.h>
14380 @@ -62,12 +64,12 @@
14381 */
14382 .macro LOAD_ARGS32 offset, _r9=0
14383 .if \_r9
14384 - movl \offset+16(%rsp),%r9d
14385 + movl \offset+R9(%rsp),%r9d
14386 .endif
14387 - movl \offset+40(%rsp),%ecx
14388 - movl \offset+48(%rsp),%edx
14389 - movl \offset+56(%rsp),%esi
14390 - movl \offset+64(%rsp),%edi
14391 + movl \offset+RCX(%rsp),%ecx
14392 + movl \offset+RDX(%rsp),%edx
14393 + movl \offset+RSI(%rsp),%esi
14394 + movl \offset+RDI(%rsp),%edi
14395 movl %eax,%eax /* zero extension */
14396 .endm
14397
14398 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14399 ENDPROC(native_irq_enable_sysexit)
14400 #endif
14401
14402 + .macro pax_enter_kernel_user
14403 + pax_set_fptr_mask
14404 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14405 + call pax_enter_kernel_user
14406 +#endif
14407 + .endm
14408 +
14409 + .macro pax_exit_kernel_user
14410 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14411 + call pax_exit_kernel_user
14412 +#endif
14413 +#ifdef CONFIG_PAX_RANDKSTACK
14414 + pushq %rax
14415 + pushq %r11
14416 + call pax_randomize_kstack
14417 + popq %r11
14418 + popq %rax
14419 +#endif
14420 + .endm
14421 +
14422 + .macro pax_erase_kstack
14423 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14424 + call pax_erase_kstack
14425 +#endif
14426 + .endm
14427 +
14428 /*
14429 * 32bit SYSENTER instruction entry.
14430 *
14431 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14432 CFI_REGISTER rsp,rbp
14433 SWAPGS_UNSAFE_STACK
14434 movq PER_CPU_VAR(kernel_stack), %rsp
14435 - addq $(KERNEL_STACK_OFFSET),%rsp
14436 - /*
14437 - * No need to follow this irqs on/off section: the syscall
14438 - * disabled irqs, here we enable it straight after entry:
14439 - */
14440 - ENABLE_INTERRUPTS(CLBR_NONE)
14441 movl %ebp,%ebp /* zero extension */
14442 pushq_cfi $__USER32_DS
14443 /*CFI_REL_OFFSET ss,0*/
14444 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14445 CFI_REL_OFFSET rsp,0
14446 pushfq_cfi
14447 /*CFI_REL_OFFSET rflags,0*/
14448 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14449 - CFI_REGISTER rip,r10
14450 + orl $X86_EFLAGS_IF,(%rsp)
14451 + GET_THREAD_INFO(%r11)
14452 + movl TI_sysenter_return(%r11), %r11d
14453 + CFI_REGISTER rip,r11
14454 pushq_cfi $__USER32_CS
14455 /*CFI_REL_OFFSET cs,0*/
14456 movl %eax, %eax
14457 - pushq_cfi %r10
14458 + pushq_cfi %r11
14459 CFI_REL_OFFSET rip,0
14460 pushq_cfi %rax
14461 cld
14462 SAVE_ARGS 0,1,0
14463 + pax_enter_kernel_user
14464 +
14465 +#ifdef CONFIG_PAX_RANDKSTACK
14466 + pax_erase_kstack
14467 +#endif
14468 +
14469 + /*
14470 + * No need to follow this irqs on/off section: the syscall
14471 + * disabled irqs, here we enable it straight after entry:
14472 + */
14473 + ENABLE_INTERRUPTS(CLBR_NONE)
14474 /* no need to do an access_ok check here because rbp has been
14475 32bit zero extended */
14476 +
14477 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14478 + addq pax_user_shadow_base,%rbp
14479 + ASM_PAX_OPEN_USERLAND
14480 +#endif
14481 +
14482 ASM_STAC
14483 1: movl (%rbp),%ebp
14484 _ASM_EXTABLE(1b,ia32_badarg)
14485 ASM_CLAC
14486 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14487 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14488 +
14489 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14490 + ASM_PAX_CLOSE_USERLAND
14491 +#endif
14492 +
14493 + GET_THREAD_INFO(%r11)
14494 + orl $TS_COMPAT,TI_status(%r11)
14495 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14496 CFI_REMEMBER_STATE
14497 jnz sysenter_tracesys
14498 cmpq $(IA32_NR_syscalls-1),%rax
14499 @@ -162,15 +209,18 @@ sysenter_do_call:
14500 sysenter_dispatch:
14501 call *ia32_sys_call_table(,%rax,8)
14502 movq %rax,RAX-ARGOFFSET(%rsp)
14503 + GET_THREAD_INFO(%r11)
14504 DISABLE_INTERRUPTS(CLBR_NONE)
14505 TRACE_IRQS_OFF
14506 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14507 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14508 jnz sysexit_audit
14509 sysexit_from_sys_call:
14510 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14511 + pax_exit_kernel_user
14512 + pax_erase_kstack
14513 + andl $~TS_COMPAT,TI_status(%r11)
14514 /* clear IF, that popfq doesn't enable interrupts early */
14515 - andl $~0x200,EFLAGS-R11(%rsp)
14516 - movl RIP-R11(%rsp),%edx /* User %eip */
14517 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14518 + movl RIP(%rsp),%edx /* User %eip */
14519 CFI_REGISTER rip,rdx
14520 RESTORE_ARGS 0,24,0,0,0,0
14521 xorq %r8,%r8
14522 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14523 movl %eax,%esi /* 2nd arg: syscall number */
14524 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14525 call __audit_syscall_entry
14526 +
14527 + pax_erase_kstack
14528 +
14529 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14530 cmpq $(IA32_NR_syscalls-1),%rax
14531 ja ia32_badsys
14532 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14533 .endm
14534
14535 .macro auditsys_exit exit
14536 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14537 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14538 jnz ia32_ret_from_sys_call
14539 TRACE_IRQS_ON
14540 ENABLE_INTERRUPTS(CLBR_NONE)
14541 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14542 1: setbe %al /* 1 if error, 0 if not */
14543 movzbl %al,%edi /* zero-extend that into %edi */
14544 call __audit_syscall_exit
14545 + GET_THREAD_INFO(%r11)
14546 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14547 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14548 DISABLE_INTERRUPTS(CLBR_NONE)
14549 TRACE_IRQS_OFF
14550 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14551 + testl %edi,TI_flags(%r11)
14552 jz \exit
14553 CLEAR_RREGS -ARGOFFSET
14554 jmp int_with_check
14555 @@ -237,7 +291,7 @@ sysexit_audit:
14556
14557 sysenter_tracesys:
14558 #ifdef CONFIG_AUDITSYSCALL
14559 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14560 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14561 jz sysenter_auditsys
14562 #endif
14563 SAVE_REST
14564 @@ -249,6 +303,9 @@ sysenter_tracesys:
14565 RESTORE_REST
14566 cmpq $(IA32_NR_syscalls-1),%rax
14567 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14568 +
14569 + pax_erase_kstack
14570 +
14571 jmp sysenter_do_call
14572 CFI_ENDPROC
14573 ENDPROC(ia32_sysenter_target)
14574 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14575 ENTRY(ia32_cstar_target)
14576 CFI_STARTPROC32 simple
14577 CFI_SIGNAL_FRAME
14578 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14579 + CFI_DEF_CFA rsp,0
14580 CFI_REGISTER rip,rcx
14581 /*CFI_REGISTER rflags,r11*/
14582 SWAPGS_UNSAFE_STACK
14583 movl %esp,%r8d
14584 CFI_REGISTER rsp,r8
14585 movq PER_CPU_VAR(kernel_stack),%rsp
14586 + SAVE_ARGS 8*6,0,0
14587 + pax_enter_kernel_user
14588 +
14589 +#ifdef CONFIG_PAX_RANDKSTACK
14590 + pax_erase_kstack
14591 +#endif
14592 +
14593 /*
14594 * No need to follow this irqs on/off section: the syscall
14595 * disabled irqs and here we enable it straight after entry:
14596 */
14597 ENABLE_INTERRUPTS(CLBR_NONE)
14598 - SAVE_ARGS 8,0,0
14599 movl %eax,%eax /* zero extension */
14600 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14601 movq %rcx,RIP-ARGOFFSET(%rsp)
14602 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14603 /* no need to do an access_ok check here because r8 has been
14604 32bit zero extended */
14605 /* hardware stack frame is complete now */
14606 +
14607 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14608 + ASM_PAX_OPEN_USERLAND
14609 + movq pax_user_shadow_base,%r8
14610 + addq RSP-ARGOFFSET(%rsp),%r8
14611 +#endif
14612 +
14613 ASM_STAC
14614 1: movl (%r8),%r9d
14615 _ASM_EXTABLE(1b,ia32_badarg)
14616 ASM_CLAC
14617 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14618 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14619 +
14620 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14621 + ASM_PAX_CLOSE_USERLAND
14622 +#endif
14623 +
14624 + GET_THREAD_INFO(%r11)
14625 + orl $TS_COMPAT,TI_status(%r11)
14626 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14627 CFI_REMEMBER_STATE
14628 jnz cstar_tracesys
14629 cmpq $IA32_NR_syscalls-1,%rax
14630 @@ -319,13 +395,16 @@ cstar_do_call:
14631 cstar_dispatch:
14632 call *ia32_sys_call_table(,%rax,8)
14633 movq %rax,RAX-ARGOFFSET(%rsp)
14634 + GET_THREAD_INFO(%r11)
14635 DISABLE_INTERRUPTS(CLBR_NONE)
14636 TRACE_IRQS_OFF
14637 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14638 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14639 jnz sysretl_audit
14640 sysretl_from_sys_call:
14641 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14642 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14643 + pax_exit_kernel_user
14644 + pax_erase_kstack
14645 + andl $~TS_COMPAT,TI_status(%r11)
14646 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14647 movl RIP-ARGOFFSET(%rsp),%ecx
14648 CFI_REGISTER rip,rcx
14649 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14650 @@ -352,7 +431,7 @@ sysretl_audit:
14651
14652 cstar_tracesys:
14653 #ifdef CONFIG_AUDITSYSCALL
14654 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14655 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14656 jz cstar_auditsys
14657 #endif
14658 xchgl %r9d,%ebp
14659 @@ -366,11 +445,19 @@ cstar_tracesys:
14660 xchgl %ebp,%r9d
14661 cmpq $(IA32_NR_syscalls-1),%rax
14662 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14663 +
14664 + pax_erase_kstack
14665 +
14666 jmp cstar_do_call
14667 END(ia32_cstar_target)
14668
14669 ia32_badarg:
14670 ASM_CLAC
14671 +
14672 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14673 + ASM_PAX_CLOSE_USERLAND
14674 +#endif
14675 +
14676 movq $-EFAULT,%rax
14677 jmp ia32_sysret
14678 CFI_ENDPROC
14679 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14680 CFI_REL_OFFSET rip,RIP-RIP
14681 PARAVIRT_ADJUST_EXCEPTION_FRAME
14682 SWAPGS
14683 - /*
14684 - * No need to follow this irqs on/off section: the syscall
14685 - * disabled irqs and here we enable it straight after entry:
14686 - */
14687 - ENABLE_INTERRUPTS(CLBR_NONE)
14688 movl %eax,%eax
14689 pushq_cfi %rax
14690 cld
14691 /* note the registers are not zero extended to the sf.
14692 this could be a problem. */
14693 SAVE_ARGS 0,1,0
14694 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14695 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14696 + pax_enter_kernel_user
14697 +
14698 +#ifdef CONFIG_PAX_RANDKSTACK
14699 + pax_erase_kstack
14700 +#endif
14701 +
14702 + /*
14703 + * No need to follow this irqs on/off section: the syscall
14704 + * disabled irqs and here we enable it straight after entry:
14705 + */
14706 + ENABLE_INTERRUPTS(CLBR_NONE)
14707 + GET_THREAD_INFO(%r11)
14708 + orl $TS_COMPAT,TI_status(%r11)
14709 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14710 jnz ia32_tracesys
14711 cmpq $(IA32_NR_syscalls-1),%rax
14712 ja ia32_badsys
14713 @@ -442,6 +536,9 @@ ia32_tracesys:
14714 RESTORE_REST
14715 cmpq $(IA32_NR_syscalls-1),%rax
14716 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14717 +
14718 + pax_erase_kstack
14719 +
14720 jmp ia32_do_call
14721 END(ia32_syscall)
14722
14723 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14724 index 8e0ceec..af13504 100644
14725 --- a/arch/x86/ia32/sys_ia32.c
14726 +++ b/arch/x86/ia32/sys_ia32.c
14727 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14728 */
14729 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14730 {
14731 - typeof(ubuf->st_uid) uid = 0;
14732 - typeof(ubuf->st_gid) gid = 0;
14733 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14734 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14735 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14736 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14737 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14738 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14739 index 372231c..51b537d 100644
14740 --- a/arch/x86/include/asm/alternative-asm.h
14741 +++ b/arch/x86/include/asm/alternative-asm.h
14742 @@ -18,6 +18,45 @@
14743 .endm
14744 #endif
14745
14746 +#ifdef KERNEXEC_PLUGIN
14747 + .macro pax_force_retaddr_bts rip=0
14748 + btsq $63,\rip(%rsp)
14749 + .endm
14750 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14751 + .macro pax_force_retaddr rip=0, reload=0
14752 + btsq $63,\rip(%rsp)
14753 + .endm
14754 + .macro pax_force_fptr ptr
14755 + btsq $63,\ptr
14756 + .endm
14757 + .macro pax_set_fptr_mask
14758 + .endm
14759 +#endif
14760 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14761 + .macro pax_force_retaddr rip=0, reload=0
14762 + .if \reload
14763 + pax_set_fptr_mask
14764 + .endif
14765 + orq %r12,\rip(%rsp)
14766 + .endm
14767 + .macro pax_force_fptr ptr
14768 + orq %r12,\ptr
14769 + .endm
14770 + .macro pax_set_fptr_mask
14771 + movabs $0x8000000000000000,%r12
14772 + .endm
14773 +#endif
14774 +#else
14775 + .macro pax_force_retaddr rip=0, reload=0
14776 + .endm
14777 + .macro pax_force_fptr ptr
14778 + .endm
14779 + .macro pax_force_retaddr_bts rip=0
14780 + .endm
14781 + .macro pax_set_fptr_mask
14782 + .endm
14783 +#endif
14784 +
14785 .macro altinstruction_entry orig alt feature orig_len alt_len
14786 .long \orig - .
14787 .long \alt - .
14788 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14789 index 0a3f9c9..c9d081d 100644
14790 --- a/arch/x86/include/asm/alternative.h
14791 +++ b/arch/x86/include/asm/alternative.h
14792 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14793 ".pushsection .discard,\"aw\",@progbits\n" \
14794 DISCARD_ENTRY(1) \
14795 ".popsection\n" \
14796 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14797 + ".pushsection .altinstr_replacement, \"a\"\n" \
14798 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14799 ".popsection"
14800
14801 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14802 DISCARD_ENTRY(1) \
14803 DISCARD_ENTRY(2) \
14804 ".popsection\n" \
14805 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14806 + ".pushsection .altinstr_replacement, \"a\"\n" \
14807 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14808 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14809 ".popsection"
14810 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14811 index 1d2091a..f5074c1 100644
14812 --- a/arch/x86/include/asm/apic.h
14813 +++ b/arch/x86/include/asm/apic.h
14814 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14815
14816 #ifdef CONFIG_X86_LOCAL_APIC
14817
14818 -extern unsigned int apic_verbosity;
14819 +extern int apic_verbosity;
14820 extern int local_apic_timer_c2_ok;
14821
14822 extern int disable_apic;
14823 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14824 index 20370c6..a2eb9b0 100644
14825 --- a/arch/x86/include/asm/apm.h
14826 +++ b/arch/x86/include/asm/apm.h
14827 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14828 __asm__ __volatile__(APM_DO_ZERO_SEGS
14829 "pushl %%edi\n\t"
14830 "pushl %%ebp\n\t"
14831 - "lcall *%%cs:apm_bios_entry\n\t"
14832 + "lcall *%%ss:apm_bios_entry\n\t"
14833 "setc %%al\n\t"
14834 "popl %%ebp\n\t"
14835 "popl %%edi\n\t"
14836 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14837 __asm__ __volatile__(APM_DO_ZERO_SEGS
14838 "pushl %%edi\n\t"
14839 "pushl %%ebp\n\t"
14840 - "lcall *%%cs:apm_bios_entry\n\t"
14841 + "lcall *%%ss:apm_bios_entry\n\t"
14842 "setc %%bl\n\t"
14843 "popl %%ebp\n\t"
14844 "popl %%edi\n\t"
14845 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14846 index b17f4f4..9620151 100644
14847 --- a/arch/x86/include/asm/atomic.h
14848 +++ b/arch/x86/include/asm/atomic.h
14849 @@ -23,7 +23,18 @@
14850 */
14851 static inline int atomic_read(const atomic_t *v)
14852 {
14853 - return (*(volatile int *)&(v)->counter);
14854 + return (*(volatile const int *)&(v)->counter);
14855 +}
14856 +
14857 +/**
14858 + * atomic_read_unchecked - read atomic variable
14859 + * @v: pointer of type atomic_unchecked_t
14860 + *
14861 + * Atomically reads the value of @v.
14862 + */
14863 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14864 +{
14865 + return (*(volatile const int *)&(v)->counter);
14866 }
14867
14868 /**
14869 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14870 }
14871
14872 /**
14873 + * atomic_set_unchecked - set atomic variable
14874 + * @v: pointer of type atomic_unchecked_t
14875 + * @i: required value
14876 + *
14877 + * Atomically sets the value of @v to @i.
14878 + */
14879 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14880 +{
14881 + v->counter = i;
14882 +}
14883 +
14884 +/**
14885 * atomic_add - add integer to atomic variable
14886 * @i: integer value to add
14887 * @v: pointer of type atomic_t
14888 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14889 */
14890 static inline void atomic_add(int i, atomic_t *v)
14891 {
14892 - asm volatile(LOCK_PREFIX "addl %1,%0"
14893 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14894 +
14895 +#ifdef CONFIG_PAX_REFCOUNT
14896 + "jno 0f\n"
14897 + LOCK_PREFIX "subl %1,%0\n"
14898 + "int $4\n0:\n"
14899 + _ASM_EXTABLE(0b, 0b)
14900 +#endif
14901 +
14902 + : "+m" (v->counter)
14903 + : "ir" (i));
14904 +}
14905 +
14906 +/**
14907 + * atomic_add_unchecked - add integer to atomic variable
14908 + * @i: integer value to add
14909 + * @v: pointer of type atomic_unchecked_t
14910 + *
14911 + * Atomically adds @i to @v.
14912 + */
14913 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14914 +{
14915 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14916 : "+m" (v->counter)
14917 : "ir" (i));
14918 }
14919 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14920 */
14921 static inline void atomic_sub(int i, atomic_t *v)
14922 {
14923 - asm volatile(LOCK_PREFIX "subl %1,%0"
14924 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14925 +
14926 +#ifdef CONFIG_PAX_REFCOUNT
14927 + "jno 0f\n"
14928 + LOCK_PREFIX "addl %1,%0\n"
14929 + "int $4\n0:\n"
14930 + _ASM_EXTABLE(0b, 0b)
14931 +#endif
14932 +
14933 + : "+m" (v->counter)
14934 + : "ir" (i));
14935 +}
14936 +
14937 +/**
14938 + * atomic_sub_unchecked - subtract integer from atomic variable
14939 + * @i: integer value to subtract
14940 + * @v: pointer of type atomic_unchecked_t
14941 + *
14942 + * Atomically subtracts @i from @v.
14943 + */
14944 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14945 +{
14946 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14947 : "+m" (v->counter)
14948 : "ir" (i));
14949 }
14950 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14951 */
14952 static inline int atomic_sub_and_test(int i, atomic_t *v)
14953 {
14954 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14955 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14956 }
14957
14958 /**
14959 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14960 */
14961 static inline void atomic_inc(atomic_t *v)
14962 {
14963 - asm volatile(LOCK_PREFIX "incl %0"
14964 + asm volatile(LOCK_PREFIX "incl %0\n"
14965 +
14966 +#ifdef CONFIG_PAX_REFCOUNT
14967 + "jno 0f\n"
14968 + LOCK_PREFIX "decl %0\n"
14969 + "int $4\n0:\n"
14970 + _ASM_EXTABLE(0b, 0b)
14971 +#endif
14972 +
14973 + : "+m" (v->counter));
14974 +}
14975 +
14976 +/**
14977 + * atomic_inc_unchecked - increment atomic variable
14978 + * @v: pointer of type atomic_unchecked_t
14979 + *
14980 + * Atomically increments @v by 1.
14981 + */
14982 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14983 +{
14984 + asm volatile(LOCK_PREFIX "incl %0\n"
14985 : "+m" (v->counter));
14986 }
14987
14988 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14989 */
14990 static inline void atomic_dec(atomic_t *v)
14991 {
14992 - asm volatile(LOCK_PREFIX "decl %0"
14993 + asm volatile(LOCK_PREFIX "decl %0\n"
14994 +
14995 +#ifdef CONFIG_PAX_REFCOUNT
14996 + "jno 0f\n"
14997 + LOCK_PREFIX "incl %0\n"
14998 + "int $4\n0:\n"
14999 + _ASM_EXTABLE(0b, 0b)
15000 +#endif
15001 +
15002 + : "+m" (v->counter));
15003 +}
15004 +
15005 +/**
15006 + * atomic_dec_unchecked - decrement atomic variable
15007 + * @v: pointer of type atomic_unchecked_t
15008 + *
15009 + * Atomically decrements @v by 1.
15010 + */
15011 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15012 +{
15013 + asm volatile(LOCK_PREFIX "decl %0\n"
15014 : "+m" (v->counter));
15015 }
15016
15017 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15018 */
15019 static inline int atomic_dec_and_test(atomic_t *v)
15020 {
15021 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15022 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15023 }
15024
15025 /**
15026 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15027 */
15028 static inline int atomic_inc_and_test(atomic_t *v)
15029 {
15030 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15031 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15032 +}
15033 +
15034 +/**
15035 + * atomic_inc_and_test_unchecked - increment and test
15036 + * @v: pointer of type atomic_unchecked_t
15037 + *
15038 + * Atomically increments @v by 1
15039 + * and returns true if the result is zero, or false for all
15040 + * other cases.
15041 + */
15042 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15043 +{
15044 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15045 }
15046
15047 /**
15048 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15049 */
15050 static inline int atomic_add_negative(int i, atomic_t *v)
15051 {
15052 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15053 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15054 }
15055
15056 /**
15057 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15058 */
15059 static inline int atomic_add_return(int i, atomic_t *v)
15060 {
15061 + return i + xadd_check_overflow(&v->counter, i);
15062 +}
15063 +
15064 +/**
15065 + * atomic_add_return_unchecked - add integer and return
15066 + * @i: integer value to add
15067 + * @v: pointer of type atomic_unchecked_t
15068 + *
15069 + * Atomically adds @i to @v and returns @i + @v
15070 + */
15071 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15072 +{
15073 return i + xadd(&v->counter, i);
15074 }
15075
15076 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15077 }
15078
15079 #define atomic_inc_return(v) (atomic_add_return(1, v))
15080 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15081 +{
15082 + return atomic_add_return_unchecked(1, v);
15083 +}
15084 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15085
15086 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15087 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15088 +{
15089 + return cmpxchg(&v->counter, old, new);
15090 +}
15091 +
15092 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15093 {
15094 return cmpxchg(&v->counter, old, new);
15095 }
15096 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15097 return xchg(&v->counter, new);
15098 }
15099
15100 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15101 +{
15102 + return xchg(&v->counter, new);
15103 +}
15104 +
15105 /**
15106 * __atomic_add_unless - add unless the number is already a given value
15107 * @v: pointer of type atomic_t
15108 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15109 * Atomically adds @a to @v, so long as @v was not already @u.
15110 * Returns the old value of @v.
15111 */
15112 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15113 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15114 {
15115 - int c, old;
15116 + int c, old, new;
15117 c = atomic_read(v);
15118 for (;;) {
15119 - if (unlikely(c == (u)))
15120 + if (unlikely(c == u))
15121 break;
15122 - old = atomic_cmpxchg((v), c, c + (a));
15123 +
15124 + asm volatile("addl %2,%0\n"
15125 +
15126 +#ifdef CONFIG_PAX_REFCOUNT
15127 + "jno 0f\n"
15128 + "subl %2,%0\n"
15129 + "int $4\n0:\n"
15130 + _ASM_EXTABLE(0b, 0b)
15131 +#endif
15132 +
15133 + : "=r" (new)
15134 + : "0" (c), "ir" (a));
15135 +
15136 + old = atomic_cmpxchg(v, c, new);
15137 if (likely(old == c))
15138 break;
15139 c = old;
15140 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15141 }
15142
15143 /**
15144 + * atomic_inc_not_zero_hint - increment if not null
15145 + * @v: pointer of type atomic_t
15146 + * @hint: probable value of the atomic before the increment
15147 + *
15148 + * This version of atomic_inc_not_zero() gives a hint of probable
15149 + * value of the atomic. This helps processor to not read the memory
15150 + * before doing the atomic read/modify/write cycle, lowering
15151 + * number of bus transactions on some arches.
15152 + *
15153 + * Returns: 0 if increment was not done, 1 otherwise.
15154 + */
15155 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15156 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15157 +{
15158 + int val, c = hint, new;
15159 +
15160 + /* sanity test, should be removed by compiler if hint is a constant */
15161 + if (!hint)
15162 + return __atomic_add_unless(v, 1, 0);
15163 +
15164 + do {
15165 + asm volatile("incl %0\n"
15166 +
15167 +#ifdef CONFIG_PAX_REFCOUNT
15168 + "jno 0f\n"
15169 + "decl %0\n"
15170 + "int $4\n0:\n"
15171 + _ASM_EXTABLE(0b, 0b)
15172 +#endif
15173 +
15174 + : "=r" (new)
15175 + : "0" (c));
15176 +
15177 + val = atomic_cmpxchg(v, c, new);
15178 + if (val == c)
15179 + return 1;
15180 + c = val;
15181 + } while (c);
15182 +
15183 + return 0;
15184 +}
15185 +
15186 +/**
15187 * atomic_inc_short - increment of a short integer
15188 * @v: pointer to type int
15189 *
15190 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15191 #endif
15192
15193 /* These are x86-specific, used by some header files */
15194 -#define atomic_clear_mask(mask, addr) \
15195 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15196 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15197 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15198 +{
15199 + asm volatile(LOCK_PREFIX "andl %1,%0"
15200 + : "+m" (v->counter)
15201 + : "r" (~(mask))
15202 + : "memory");
15203 +}
15204
15205 -#define atomic_set_mask(mask, addr) \
15206 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15207 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15208 - : "memory")
15209 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15210 +{
15211 + asm volatile(LOCK_PREFIX "andl %1,%0"
15212 + : "+m" (v->counter)
15213 + : "r" (~(mask))
15214 + : "memory");
15215 +}
15216 +
15217 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15218 +{
15219 + asm volatile(LOCK_PREFIX "orl %1,%0"
15220 + : "+m" (v->counter)
15221 + : "r" (mask)
15222 + : "memory");
15223 +}
15224 +
15225 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15226 +{
15227 + asm volatile(LOCK_PREFIX "orl %1,%0"
15228 + : "+m" (v->counter)
15229 + : "r" (mask)
15230 + : "memory");
15231 +}
15232
15233 /* Atomic operations are already serializing on x86 */
15234 #define smp_mb__before_atomic_dec() barrier()
15235 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15236 index b154de7..bf18a5a 100644
15237 --- a/arch/x86/include/asm/atomic64_32.h
15238 +++ b/arch/x86/include/asm/atomic64_32.h
15239 @@ -12,6 +12,14 @@ typedef struct {
15240 u64 __aligned(8) counter;
15241 } atomic64_t;
15242
15243 +#ifdef CONFIG_PAX_REFCOUNT
15244 +typedef struct {
15245 + u64 __aligned(8) counter;
15246 +} atomic64_unchecked_t;
15247 +#else
15248 +typedef atomic64_t atomic64_unchecked_t;
15249 +#endif
15250 +
15251 #define ATOMIC64_INIT(val) { (val) }
15252
15253 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15254 @@ -37,21 +45,31 @@ typedef struct {
15255 ATOMIC64_DECL_ONE(sym##_386)
15256
15257 ATOMIC64_DECL_ONE(add_386);
15258 +ATOMIC64_DECL_ONE(add_unchecked_386);
15259 ATOMIC64_DECL_ONE(sub_386);
15260 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15261 ATOMIC64_DECL_ONE(inc_386);
15262 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15263 ATOMIC64_DECL_ONE(dec_386);
15264 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15265 #endif
15266
15267 #define alternative_atomic64(f, out, in...) \
15268 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15269
15270 ATOMIC64_DECL(read);
15271 +ATOMIC64_DECL(read_unchecked);
15272 ATOMIC64_DECL(set);
15273 +ATOMIC64_DECL(set_unchecked);
15274 ATOMIC64_DECL(xchg);
15275 ATOMIC64_DECL(add_return);
15276 +ATOMIC64_DECL(add_return_unchecked);
15277 ATOMIC64_DECL(sub_return);
15278 +ATOMIC64_DECL(sub_return_unchecked);
15279 ATOMIC64_DECL(inc_return);
15280 +ATOMIC64_DECL(inc_return_unchecked);
15281 ATOMIC64_DECL(dec_return);
15282 +ATOMIC64_DECL(dec_return_unchecked);
15283 ATOMIC64_DECL(dec_if_positive);
15284 ATOMIC64_DECL(inc_not_zero);
15285 ATOMIC64_DECL(add_unless);
15286 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15287 }
15288
15289 /**
15290 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15291 + * @p: pointer to type atomic64_unchecked_t
15292 + * @o: expected value
15293 + * @n: new value
15294 + *
15295 + * Atomically sets @v to @n if it was equal to @o and returns
15296 + * the old value.
15297 + */
15298 +
15299 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15300 +{
15301 + return cmpxchg64(&v->counter, o, n);
15302 +}
15303 +
15304 +/**
15305 * atomic64_xchg - xchg atomic64 variable
15306 * @v: pointer to type atomic64_t
15307 * @n: value to assign
15308 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15309 }
15310
15311 /**
15312 + * atomic64_set_unchecked - set atomic64 variable
15313 + * @v: pointer to type atomic64_unchecked_t
15314 + * @n: value to assign
15315 + *
15316 + * Atomically sets the value of @v to @n.
15317 + */
15318 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15319 +{
15320 + unsigned high = (unsigned)(i >> 32);
15321 + unsigned low = (unsigned)i;
15322 + alternative_atomic64(set, /* no output */,
15323 + "S" (v), "b" (low), "c" (high)
15324 + : "eax", "edx", "memory");
15325 +}
15326 +
15327 +/**
15328 * atomic64_read - read atomic64 variable
15329 * @v: pointer to type atomic64_t
15330 *
15331 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15332 }
15333
15334 /**
15335 + * atomic64_read_unchecked - read atomic64 variable
15336 + * @v: pointer to type atomic64_unchecked_t
15337 + *
15338 + * Atomically reads the value of @v and returns it.
15339 + */
15340 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15341 +{
15342 + long long r;
15343 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15344 + return r;
15345 + }
15346 +
15347 +/**
15348 * atomic64_add_return - add and return
15349 * @i: integer value to add
15350 * @v: pointer to type atomic64_t
15351 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15352 return i;
15353 }
15354
15355 +/**
15356 + * atomic64_add_return_unchecked - add and return
15357 + * @i: integer value to add
15358 + * @v: pointer to type atomic64_unchecked_t
15359 + *
15360 + * Atomically adds @i to @v and returns @i + *@v
15361 + */
15362 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15363 +{
15364 + alternative_atomic64(add_return_unchecked,
15365 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15366 + ASM_NO_INPUT_CLOBBER("memory"));
15367 + return i;
15368 +}
15369 +
15370 /*
15371 * Other variants with different arithmetic operators:
15372 */
15373 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15374 return a;
15375 }
15376
15377 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15378 +{
15379 + long long a;
15380 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15381 + "S" (v) : "memory", "ecx");
15382 + return a;
15383 +}
15384 +
15385 static inline long long atomic64_dec_return(atomic64_t *v)
15386 {
15387 long long a;
15388 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15389 }
15390
15391 /**
15392 + * atomic64_add_unchecked - add integer to atomic64 variable
15393 + * @i: integer value to add
15394 + * @v: pointer to type atomic64_unchecked_t
15395 + *
15396 + * Atomically adds @i to @v.
15397 + */
15398 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15399 +{
15400 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15401 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15402 + ASM_NO_INPUT_CLOBBER("memory"));
15403 + return i;
15404 +}
15405 +
15406 +/**
15407 * atomic64_sub - subtract the atomic64 variable
15408 * @i: integer value to subtract
15409 * @v: pointer to type atomic64_t
15410 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15411 index 46e9052..ae45136 100644
15412 --- a/arch/x86/include/asm/atomic64_64.h
15413 +++ b/arch/x86/include/asm/atomic64_64.h
15414 @@ -18,7 +18,19 @@
15415 */
15416 static inline long atomic64_read(const atomic64_t *v)
15417 {
15418 - return (*(volatile long *)&(v)->counter);
15419 + return (*(volatile const long *)&(v)->counter);
15420 +}
15421 +
15422 +/**
15423 + * atomic64_read_unchecked - read atomic64 variable
15424 + * @v: pointer of type atomic64_unchecked_t
15425 + *
15426 + * Atomically reads the value of @v.
15427 + * Doesn't imply a read memory barrier.
15428 + */
15429 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15430 +{
15431 + return (*(volatile const long *)&(v)->counter);
15432 }
15433
15434 /**
15435 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15436 }
15437
15438 /**
15439 + * atomic64_set_unchecked - set atomic64 variable
15440 + * @v: pointer to type atomic64_unchecked_t
15441 + * @i: required value
15442 + *
15443 + * Atomically sets the value of @v to @i.
15444 + */
15445 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15446 +{
15447 + v->counter = i;
15448 +}
15449 +
15450 +/**
15451 * atomic64_add - add integer to atomic64 variable
15452 * @i: integer value to add
15453 * @v: pointer to type atomic64_t
15454 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15455 */
15456 static inline void atomic64_add(long i, atomic64_t *v)
15457 {
15458 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15459 +
15460 +#ifdef CONFIG_PAX_REFCOUNT
15461 + "jno 0f\n"
15462 + LOCK_PREFIX "subq %1,%0\n"
15463 + "int $4\n0:\n"
15464 + _ASM_EXTABLE(0b, 0b)
15465 +#endif
15466 +
15467 + : "=m" (v->counter)
15468 + : "er" (i), "m" (v->counter));
15469 +}
15470 +
15471 +/**
15472 + * atomic64_add_unchecked - add integer to atomic64 variable
15473 + * @i: integer value to add
15474 + * @v: pointer to type atomic64_unchecked_t
15475 + *
15476 + * Atomically adds @i to @v.
15477 + */
15478 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15479 +{
15480 asm volatile(LOCK_PREFIX "addq %1,%0"
15481 : "=m" (v->counter)
15482 : "er" (i), "m" (v->counter));
15483 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15484 */
15485 static inline void atomic64_sub(long i, atomic64_t *v)
15486 {
15487 - asm volatile(LOCK_PREFIX "subq %1,%0"
15488 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15489 +
15490 +#ifdef CONFIG_PAX_REFCOUNT
15491 + "jno 0f\n"
15492 + LOCK_PREFIX "addq %1,%0\n"
15493 + "int $4\n0:\n"
15494 + _ASM_EXTABLE(0b, 0b)
15495 +#endif
15496 +
15497 + : "=m" (v->counter)
15498 + : "er" (i), "m" (v->counter));
15499 +}
15500 +
15501 +/**
15502 + * atomic64_sub_unchecked - subtract the atomic64 variable
15503 + * @i: integer value to subtract
15504 + * @v: pointer to type atomic64_unchecked_t
15505 + *
15506 + * Atomically subtracts @i from @v.
15507 + */
15508 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15509 +{
15510 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15511 : "=m" (v->counter)
15512 : "er" (i), "m" (v->counter));
15513 }
15514 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15515 */
15516 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15517 {
15518 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15519 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15520 }
15521
15522 /**
15523 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15524 */
15525 static inline void atomic64_inc(atomic64_t *v)
15526 {
15527 + asm volatile(LOCK_PREFIX "incq %0\n"
15528 +
15529 +#ifdef CONFIG_PAX_REFCOUNT
15530 + "jno 0f\n"
15531 + LOCK_PREFIX "decq %0\n"
15532 + "int $4\n0:\n"
15533 + _ASM_EXTABLE(0b, 0b)
15534 +#endif
15535 +
15536 + : "=m" (v->counter)
15537 + : "m" (v->counter));
15538 +}
15539 +
15540 +/**
15541 + * atomic64_inc_unchecked - increment atomic64 variable
15542 + * @v: pointer to type atomic64_unchecked_t
15543 + *
15544 + * Atomically increments @v by 1.
15545 + */
15546 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15547 +{
15548 asm volatile(LOCK_PREFIX "incq %0"
15549 : "=m" (v->counter)
15550 : "m" (v->counter));
15551 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15552 */
15553 static inline void atomic64_dec(atomic64_t *v)
15554 {
15555 - asm volatile(LOCK_PREFIX "decq %0"
15556 + asm volatile(LOCK_PREFIX "decq %0\n"
15557 +
15558 +#ifdef CONFIG_PAX_REFCOUNT
15559 + "jno 0f\n"
15560 + LOCK_PREFIX "incq %0\n"
15561 + "int $4\n0:\n"
15562 + _ASM_EXTABLE(0b, 0b)
15563 +#endif
15564 +
15565 + : "=m" (v->counter)
15566 + : "m" (v->counter));
15567 +}
15568 +
15569 +/**
15570 + * atomic64_dec_unchecked - decrement atomic64 variable
15571 + * @v: pointer to type atomic64_t
15572 + *
15573 + * Atomically decrements @v by 1.
15574 + */
15575 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15576 +{
15577 + asm volatile(LOCK_PREFIX "decq %0\n"
15578 : "=m" (v->counter)
15579 : "m" (v->counter));
15580 }
15581 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15582 */
15583 static inline int atomic64_dec_and_test(atomic64_t *v)
15584 {
15585 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15586 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15587 }
15588
15589 /**
15590 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15591 */
15592 static inline int atomic64_inc_and_test(atomic64_t *v)
15593 {
15594 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15595 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15596 }
15597
15598 /**
15599 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15600 */
15601 static inline int atomic64_add_negative(long i, atomic64_t *v)
15602 {
15603 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15604 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15605 }
15606
15607 /**
15608 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15609 */
15610 static inline long atomic64_add_return(long i, atomic64_t *v)
15611 {
15612 + return i + xadd_check_overflow(&v->counter, i);
15613 +}
15614 +
15615 +/**
15616 + * atomic64_add_return_unchecked - add and return
15617 + * @i: integer value to add
15618 + * @v: pointer to type atomic64_unchecked_t
15619 + *
15620 + * Atomically adds @i to @v and returns @i + @v
15621 + */
15622 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15623 +{
15624 return i + xadd(&v->counter, i);
15625 }
15626
15627 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15628 }
15629
15630 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15631 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15632 +{
15633 + return atomic64_add_return_unchecked(1, v);
15634 +}
15635 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15636
15637 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15638 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15639 return cmpxchg(&v->counter, old, new);
15640 }
15641
15642 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15643 +{
15644 + return cmpxchg(&v->counter, old, new);
15645 +}
15646 +
15647 static inline long atomic64_xchg(atomic64_t *v, long new)
15648 {
15649 return xchg(&v->counter, new);
15650 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15651 */
15652 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15653 {
15654 - long c, old;
15655 + long c, old, new;
15656 c = atomic64_read(v);
15657 for (;;) {
15658 - if (unlikely(c == (u)))
15659 + if (unlikely(c == u))
15660 break;
15661 - old = atomic64_cmpxchg((v), c, c + (a));
15662 +
15663 + asm volatile("add %2,%0\n"
15664 +
15665 +#ifdef CONFIG_PAX_REFCOUNT
15666 + "jno 0f\n"
15667 + "sub %2,%0\n"
15668 + "int $4\n0:\n"
15669 + _ASM_EXTABLE(0b, 0b)
15670 +#endif
15671 +
15672 + : "=r" (new)
15673 + : "0" (c), "ir" (a));
15674 +
15675 + old = atomic64_cmpxchg(v, c, new);
15676 if (likely(old == c))
15677 break;
15678 c = old;
15679 }
15680 - return c != (u);
15681 + return c != u;
15682 }
15683
15684 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15685 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15686 index 9fc1af7..fc71228 100644
15687 --- a/arch/x86/include/asm/bitops.h
15688 +++ b/arch/x86/include/asm/bitops.h
15689 @@ -49,7 +49,7 @@
15690 * a mask operation on a byte.
15691 */
15692 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15693 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15694 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15695 #define CONST_MASK(nr) (1 << ((nr) & 7))
15696
15697 /**
15698 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15699 */
15700 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15701 {
15702 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15703 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15704 }
15705
15706 /**
15707 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15708 */
15709 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15710 {
15711 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15712 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15713 }
15714
15715 /**
15716 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15717 */
15718 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15719 {
15720 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15721 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15722 }
15723
15724 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15725 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15726 *
15727 * Undefined if no bit exists, so code should check against 0 first.
15728 */
15729 -static inline unsigned long __ffs(unsigned long word)
15730 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15731 {
15732 asm("rep; bsf %1,%0"
15733 : "=r" (word)
15734 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15735 *
15736 * Undefined if no zero exists, so code should check against ~0UL first.
15737 */
15738 -static inline unsigned long ffz(unsigned long word)
15739 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15740 {
15741 asm("rep; bsf %1,%0"
15742 : "=r" (word)
15743 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15744 *
15745 * Undefined if no set bit exists, so code should check against 0 first.
15746 */
15747 -static inline unsigned long __fls(unsigned long word)
15748 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15749 {
15750 asm("bsr %1,%0"
15751 : "=r" (word)
15752 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15753 * set bit if value is nonzero. The last (most significant) bit is
15754 * at position 32.
15755 */
15756 -static inline int fls(int x)
15757 +static inline int __intentional_overflow(-1) fls(int x)
15758 {
15759 int r;
15760
15761 @@ -478,7 +478,7 @@ static inline int fls(int x)
15762 * at position 64.
15763 */
15764 #ifdef CONFIG_X86_64
15765 -static __always_inline int fls64(__u64 x)
15766 +static __always_inline long fls64(__u64 x)
15767 {
15768 int bitpos = -1;
15769 /*
15770 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15771 index 4fa687a..60f2d39 100644
15772 --- a/arch/x86/include/asm/boot.h
15773 +++ b/arch/x86/include/asm/boot.h
15774 @@ -6,10 +6,15 @@
15775 #include <uapi/asm/boot.h>
15776
15777 /* Physical address where kernel should be loaded. */
15778 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15779 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15780 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15781 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15782
15783 +#ifndef __ASSEMBLY__
15784 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15785 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15786 +#endif
15787 +
15788 /* Minimum kernel alignment, as a power of two */
15789 #ifdef CONFIG_X86_64
15790 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15791 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15792 index 48f99f1..d78ebf9 100644
15793 --- a/arch/x86/include/asm/cache.h
15794 +++ b/arch/x86/include/asm/cache.h
15795 @@ -5,12 +5,13 @@
15796
15797 /* L1 cache line size */
15798 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15799 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15800 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15801
15802 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15803 +#define __read_only __attribute__((__section__(".data..read_only")))
15804
15805 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15806 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15807 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15808
15809 #ifdef CONFIG_X86_VSMP
15810 #ifdef CONFIG_SMP
15811 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15812 index 9863ee3..4a1f8e1 100644
15813 --- a/arch/x86/include/asm/cacheflush.h
15814 +++ b/arch/x86/include/asm/cacheflush.h
15815 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15816 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15817
15818 if (pg_flags == _PGMT_DEFAULT)
15819 - return -1;
15820 + return ~0UL;
15821 else if (pg_flags == _PGMT_WC)
15822 return _PAGE_CACHE_WC;
15823 else if (pg_flags == _PGMT_UC_MINUS)
15824 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15825 index cb4c73b..c473c29 100644
15826 --- a/arch/x86/include/asm/calling.h
15827 +++ b/arch/x86/include/asm/calling.h
15828 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15829 #define RSP 152
15830 #define SS 160
15831
15832 -#define ARGOFFSET R11
15833 -#define SWFRAME ORIG_RAX
15834 +#define ARGOFFSET R15
15835
15836 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15837 - subq $9*8+\addskip, %rsp
15838 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15839 - movq_cfi rdi, 8*8
15840 - movq_cfi rsi, 7*8
15841 - movq_cfi rdx, 6*8
15842 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15843 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15844 + movq_cfi rdi, RDI
15845 + movq_cfi rsi, RSI
15846 + movq_cfi rdx, RDX
15847
15848 .if \save_rcx
15849 - movq_cfi rcx, 5*8
15850 + movq_cfi rcx, RCX
15851 .endif
15852
15853 - movq_cfi rax, 4*8
15854 + movq_cfi rax, RAX
15855
15856 .if \save_r891011
15857 - movq_cfi r8, 3*8
15858 - movq_cfi r9, 2*8
15859 - movq_cfi r10, 1*8
15860 - movq_cfi r11, 0*8
15861 + movq_cfi r8, R8
15862 + movq_cfi r9, R9
15863 + movq_cfi r10, R10
15864 + movq_cfi r11, R11
15865 .endif
15866
15867 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15868 + movq_cfi r12, R12
15869 +#endif
15870 +
15871 .endm
15872
15873 -#define ARG_SKIP (9*8)
15874 +#define ARG_SKIP ORIG_RAX
15875
15876 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15877 rstor_r8910=1, rstor_rdx=1
15878 +
15879 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15880 + movq_cfi_restore R12, r12
15881 +#endif
15882 +
15883 .if \rstor_r11
15884 - movq_cfi_restore 0*8, r11
15885 + movq_cfi_restore R11, r11
15886 .endif
15887
15888 .if \rstor_r8910
15889 - movq_cfi_restore 1*8, r10
15890 - movq_cfi_restore 2*8, r9
15891 - movq_cfi_restore 3*8, r8
15892 + movq_cfi_restore R10, r10
15893 + movq_cfi_restore R9, r9
15894 + movq_cfi_restore R8, r8
15895 .endif
15896
15897 .if \rstor_rax
15898 - movq_cfi_restore 4*8, rax
15899 + movq_cfi_restore RAX, rax
15900 .endif
15901
15902 .if \rstor_rcx
15903 - movq_cfi_restore 5*8, rcx
15904 + movq_cfi_restore RCX, rcx
15905 .endif
15906
15907 .if \rstor_rdx
15908 - movq_cfi_restore 6*8, rdx
15909 + movq_cfi_restore RDX, rdx
15910 .endif
15911
15912 - movq_cfi_restore 7*8, rsi
15913 - movq_cfi_restore 8*8, rdi
15914 + movq_cfi_restore RSI, rsi
15915 + movq_cfi_restore RDI, rdi
15916
15917 - .if ARG_SKIP+\addskip > 0
15918 - addq $ARG_SKIP+\addskip, %rsp
15919 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15920 + .if ORIG_RAX+\addskip > 0
15921 + addq $ORIG_RAX+\addskip, %rsp
15922 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15923 .endif
15924 .endm
15925
15926 - .macro LOAD_ARGS offset, skiprax=0
15927 - movq \offset(%rsp), %r11
15928 - movq \offset+8(%rsp), %r10
15929 - movq \offset+16(%rsp), %r9
15930 - movq \offset+24(%rsp), %r8
15931 - movq \offset+40(%rsp), %rcx
15932 - movq \offset+48(%rsp), %rdx
15933 - movq \offset+56(%rsp), %rsi
15934 - movq \offset+64(%rsp), %rdi
15935 + .macro LOAD_ARGS skiprax=0
15936 + movq R11(%rsp), %r11
15937 + movq R10(%rsp), %r10
15938 + movq R9(%rsp), %r9
15939 + movq R8(%rsp), %r8
15940 + movq RCX(%rsp), %rcx
15941 + movq RDX(%rsp), %rdx
15942 + movq RSI(%rsp), %rsi
15943 + movq RDI(%rsp), %rdi
15944 .if \skiprax
15945 .else
15946 - movq \offset+72(%rsp), %rax
15947 + movq RAX(%rsp), %rax
15948 .endif
15949 .endm
15950
15951 -#define REST_SKIP (6*8)
15952 -
15953 .macro SAVE_REST
15954 - subq $REST_SKIP, %rsp
15955 - CFI_ADJUST_CFA_OFFSET REST_SKIP
15956 - movq_cfi rbx, 5*8
15957 - movq_cfi rbp, 4*8
15958 - movq_cfi r12, 3*8
15959 - movq_cfi r13, 2*8
15960 - movq_cfi r14, 1*8
15961 - movq_cfi r15, 0*8
15962 + movq_cfi rbx, RBX
15963 + movq_cfi rbp, RBP
15964 +
15965 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15966 + movq_cfi r12, R12
15967 +#endif
15968 +
15969 + movq_cfi r13, R13
15970 + movq_cfi r14, R14
15971 + movq_cfi r15, R15
15972 .endm
15973
15974 .macro RESTORE_REST
15975 - movq_cfi_restore 0*8, r15
15976 - movq_cfi_restore 1*8, r14
15977 - movq_cfi_restore 2*8, r13
15978 - movq_cfi_restore 3*8, r12
15979 - movq_cfi_restore 4*8, rbp
15980 - movq_cfi_restore 5*8, rbx
15981 - addq $REST_SKIP, %rsp
15982 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15983 + movq_cfi_restore R15, r15
15984 + movq_cfi_restore R14, r14
15985 + movq_cfi_restore R13, r13
15986 +
15987 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15988 + movq_cfi_restore R12, r12
15989 +#endif
15990 +
15991 + movq_cfi_restore RBP, rbp
15992 + movq_cfi_restore RBX, rbx
15993 .endm
15994
15995 .macro SAVE_ALL
15996 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15997 index f50de69..2b0a458 100644
15998 --- a/arch/x86/include/asm/checksum_32.h
15999 +++ b/arch/x86/include/asm/checksum_32.h
16000 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16001 int len, __wsum sum,
16002 int *src_err_ptr, int *dst_err_ptr);
16003
16004 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16005 + int len, __wsum sum,
16006 + int *src_err_ptr, int *dst_err_ptr);
16007 +
16008 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16009 + int len, __wsum sum,
16010 + int *src_err_ptr, int *dst_err_ptr);
16011 +
16012 /*
16013 * Note: when you get a NULL pointer exception here this means someone
16014 * passed in an incorrect kernel address to one of these functions.
16015 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16016
16017 might_sleep();
16018 stac();
16019 - ret = csum_partial_copy_generic((__force void *)src, dst,
16020 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16021 len, sum, err_ptr, NULL);
16022 clac();
16023
16024 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16025 might_sleep();
16026 if (access_ok(VERIFY_WRITE, dst, len)) {
16027 stac();
16028 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16029 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16030 len, sum, NULL, err_ptr);
16031 clac();
16032 return ret;
16033 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16034 index d47786a..ce1b05d 100644
16035 --- a/arch/x86/include/asm/cmpxchg.h
16036 +++ b/arch/x86/include/asm/cmpxchg.h
16037 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16038 __compiletime_error("Bad argument size for cmpxchg");
16039 extern void __xadd_wrong_size(void)
16040 __compiletime_error("Bad argument size for xadd");
16041 +extern void __xadd_check_overflow_wrong_size(void)
16042 + __compiletime_error("Bad argument size for xadd_check_overflow");
16043 extern void __add_wrong_size(void)
16044 __compiletime_error("Bad argument size for add");
16045 +extern void __add_check_overflow_wrong_size(void)
16046 + __compiletime_error("Bad argument size for add_check_overflow");
16047
16048 /*
16049 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16050 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
16051 __ret; \
16052 })
16053
16054 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16055 + ({ \
16056 + __typeof__ (*(ptr)) __ret = (arg); \
16057 + switch (sizeof(*(ptr))) { \
16058 + case __X86_CASE_L: \
16059 + asm volatile (lock #op "l %0, %1\n" \
16060 + "jno 0f\n" \
16061 + "mov %0,%1\n" \
16062 + "int $4\n0:\n" \
16063 + _ASM_EXTABLE(0b, 0b) \
16064 + : "+r" (__ret), "+m" (*(ptr)) \
16065 + : : "memory", "cc"); \
16066 + break; \
16067 + case __X86_CASE_Q: \
16068 + asm volatile (lock #op "q %q0, %1\n" \
16069 + "jno 0f\n" \
16070 + "mov %0,%1\n" \
16071 + "int $4\n0:\n" \
16072 + _ASM_EXTABLE(0b, 0b) \
16073 + : "+r" (__ret), "+m" (*(ptr)) \
16074 + : : "memory", "cc"); \
16075 + break; \
16076 + default: \
16077 + __ ## op ## _check_overflow_wrong_size(); \
16078 + } \
16079 + __ret; \
16080 + })
16081 +
16082 /*
16083 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16084 * Since this is generally used to protect other memory information, we
16085 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
16086 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16087 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16088
16089 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16090 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16091 +
16092 #define __add(ptr, inc, lock) \
16093 ({ \
16094 __typeof__ (*(ptr)) __ret = (inc); \
16095 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16096 index 59c6c40..5e0b22c 100644
16097 --- a/arch/x86/include/asm/compat.h
16098 +++ b/arch/x86/include/asm/compat.h
16099 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16100 typedef u32 compat_uint_t;
16101 typedef u32 compat_ulong_t;
16102 typedef u64 __attribute__((aligned(4))) compat_u64;
16103 -typedef u32 compat_uptr_t;
16104 +typedef u32 __user compat_uptr_t;
16105
16106 struct compat_timespec {
16107 compat_time_t tv_sec;
16108 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16109 index 89270b4..f0abf8e 100644
16110 --- a/arch/x86/include/asm/cpufeature.h
16111 +++ b/arch/x86/include/asm/cpufeature.h
16112 @@ -203,7 +203,7 @@
16113 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16114 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16115 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16116 -
16117 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16118
16119 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16120 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16121 @@ -211,7 +211,7 @@
16122 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16123 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16124 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16125 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16126 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16127 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16128 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16129 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16130 @@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
16131 #undef cpu_has_centaur_mcr
16132 #define cpu_has_centaur_mcr 0
16133
16134 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16135 #endif /* CONFIG_X86_64 */
16136
16137 #if __GNUC__ >= 4
16138 @@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16139
16140 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16141 t_warn:
16142 - warn_pre_alternatives();
16143 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16144 + warn_pre_alternatives();
16145 return false;
16146 #endif
16147
16148 @@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16149 ".section .discard,\"aw\",@progbits\n"
16150 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16151 ".previous\n"
16152 - ".section .altinstr_replacement,\"ax\"\n"
16153 + ".section .altinstr_replacement,\"a\"\n"
16154 "3: movb $1,%0\n"
16155 "4:\n"
16156 ".previous\n"
16157 @@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16158 " .byte 2b - 1b\n" /* src len */
16159 " .byte 4f - 3f\n" /* repl len */
16160 ".previous\n"
16161 - ".section .altinstr_replacement,\"ax\"\n"
16162 + ".section .altinstr_replacement,\"a\"\n"
16163 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16164 "4:\n"
16165 ".previous\n"
16166 @@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16167 ".section .discard,\"aw\",@progbits\n"
16168 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16169 ".previous\n"
16170 - ".section .altinstr_replacement,\"ax\"\n"
16171 + ".section .altinstr_replacement,\"a\"\n"
16172 "3: movb $0,%0\n"
16173 "4:\n"
16174 ".previous\n"
16175 @@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16176 ".section .discard,\"aw\",@progbits\n"
16177 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16178 ".previous\n"
16179 - ".section .altinstr_replacement,\"ax\"\n"
16180 + ".section .altinstr_replacement,\"a\"\n"
16181 "5: movb $1,%0\n"
16182 "6:\n"
16183 ".previous\n"
16184 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16185 index 50d033a..37deb26 100644
16186 --- a/arch/x86/include/asm/desc.h
16187 +++ b/arch/x86/include/asm/desc.h
16188 @@ -4,6 +4,7 @@
16189 #include <asm/desc_defs.h>
16190 #include <asm/ldt.h>
16191 #include <asm/mmu.h>
16192 +#include <asm/pgtable.h>
16193
16194 #include <linux/smp.h>
16195 #include <linux/percpu.h>
16196 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16197
16198 desc->type = (info->read_exec_only ^ 1) << 1;
16199 desc->type |= info->contents << 2;
16200 + desc->type |= info->seg_not_present ^ 1;
16201
16202 desc->s = 1;
16203 desc->dpl = 0x3;
16204 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16205 }
16206
16207 extern struct desc_ptr idt_descr;
16208 -extern gate_desc idt_table[];
16209 -extern struct desc_ptr debug_idt_descr;
16210 -extern gate_desc debug_idt_table[];
16211 -
16212 -struct gdt_page {
16213 - struct desc_struct gdt[GDT_ENTRIES];
16214 -} __attribute__((aligned(PAGE_SIZE)));
16215 -
16216 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16217 +extern gate_desc idt_table[IDT_ENTRIES];
16218 +extern const struct desc_ptr debug_idt_descr;
16219 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16220
16221 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16222 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16223 {
16224 - return per_cpu(gdt_page, cpu).gdt;
16225 + return cpu_gdt_table[cpu];
16226 }
16227
16228 #ifdef CONFIG_X86_64
16229 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16230 unsigned long base, unsigned dpl, unsigned flags,
16231 unsigned short seg)
16232 {
16233 - gate->a = (seg << 16) | (base & 0xffff);
16234 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16235 + gate->gate.offset_low = base;
16236 + gate->gate.seg = seg;
16237 + gate->gate.reserved = 0;
16238 + gate->gate.type = type;
16239 + gate->gate.s = 0;
16240 + gate->gate.dpl = dpl;
16241 + gate->gate.p = 1;
16242 + gate->gate.offset_high = base >> 16;
16243 }
16244
16245 #endif
16246 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16247
16248 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16249 {
16250 + pax_open_kernel();
16251 memcpy(&idt[entry], gate, sizeof(*gate));
16252 + pax_close_kernel();
16253 }
16254
16255 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16256 {
16257 + pax_open_kernel();
16258 memcpy(&ldt[entry], desc, 8);
16259 + pax_close_kernel();
16260 }
16261
16262 static inline void
16263 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16264 default: size = sizeof(*gdt); break;
16265 }
16266
16267 + pax_open_kernel();
16268 memcpy(&gdt[entry], desc, size);
16269 + pax_close_kernel();
16270 }
16271
16272 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16273 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16274
16275 static inline void native_load_tr_desc(void)
16276 {
16277 + pax_open_kernel();
16278 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16279 + pax_close_kernel();
16280 }
16281
16282 static inline void native_load_gdt(const struct desc_ptr *dtr)
16283 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16284 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16285 unsigned int i;
16286
16287 + pax_open_kernel();
16288 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16289 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16290 + pax_close_kernel();
16291 }
16292
16293 #define _LDT_empty(info) \
16294 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16295 preempt_enable();
16296 }
16297
16298 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16299 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16300 {
16301 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16302 }
16303 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16304 }
16305
16306 #ifdef CONFIG_X86_64
16307 -static inline void set_nmi_gate(int gate, void *addr)
16308 +static inline void set_nmi_gate(int gate, const void *addr)
16309 {
16310 gate_desc s;
16311
16312 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16313 #endif
16314
16315 #ifdef CONFIG_TRACING
16316 -extern struct desc_ptr trace_idt_descr;
16317 -extern gate_desc trace_idt_table[];
16318 +extern const struct desc_ptr trace_idt_descr;
16319 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16320 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16321 {
16322 write_idt_entry(trace_idt_table, entry, gate);
16323 }
16324
16325 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16326 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16327 unsigned dpl, unsigned ist, unsigned seg)
16328 {
16329 gate_desc s;
16330 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16331 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16332 #endif
16333
16334 -static inline void _set_gate(int gate, unsigned type, void *addr,
16335 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16336 unsigned dpl, unsigned ist, unsigned seg)
16337 {
16338 gate_desc s;
16339 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16340 #define set_intr_gate(n, addr) \
16341 do { \
16342 BUG_ON((unsigned)n > 0xFF); \
16343 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16344 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16345 __KERNEL_CS); \
16346 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16347 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16348 0, 0, __KERNEL_CS); \
16349 } while (0)
16350
16351 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16352 /*
16353 * This routine sets up an interrupt gate at directory privilege level 3.
16354 */
16355 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16356 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16357 {
16358 BUG_ON((unsigned)n > 0xFF);
16359 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16360 }
16361
16362 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16363 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16364 {
16365 BUG_ON((unsigned)n > 0xFF);
16366 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16367 }
16368
16369 -static inline void set_trap_gate(unsigned int n, void *addr)
16370 +static inline void set_trap_gate(unsigned int n, const void *addr)
16371 {
16372 BUG_ON((unsigned)n > 0xFF);
16373 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16374 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16375 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16376 {
16377 BUG_ON((unsigned)n > 0xFF);
16378 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16379 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16380 }
16381
16382 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16383 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16384 {
16385 BUG_ON((unsigned)n > 0xFF);
16386 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16387 }
16388
16389 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16390 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16391 {
16392 BUG_ON((unsigned)n > 0xFF);
16393 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16394 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16395 else
16396 load_idt((const struct desc_ptr *)&idt_descr);
16397 }
16398 +
16399 +#ifdef CONFIG_X86_32
16400 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16401 +{
16402 + struct desc_struct d;
16403 +
16404 + if (likely(limit))
16405 + limit = (limit - 1UL) >> PAGE_SHIFT;
16406 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16407 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16408 +}
16409 +#endif
16410 +
16411 #endif /* _ASM_X86_DESC_H */
16412 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16413 index 278441f..b95a174 100644
16414 --- a/arch/x86/include/asm/desc_defs.h
16415 +++ b/arch/x86/include/asm/desc_defs.h
16416 @@ -31,6 +31,12 @@ struct desc_struct {
16417 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16418 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16419 };
16420 + struct {
16421 + u16 offset_low;
16422 + u16 seg;
16423 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16424 + unsigned offset_high: 16;
16425 + } gate;
16426 };
16427 } __attribute__((packed));
16428
16429 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16430 index ced283a..ffe04cc 100644
16431 --- a/arch/x86/include/asm/div64.h
16432 +++ b/arch/x86/include/asm/div64.h
16433 @@ -39,7 +39,7 @@
16434 __mod; \
16435 })
16436
16437 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16438 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16439 {
16440 union {
16441 u64 v64;
16442 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16443 index 9c999c1..3860cb8 100644
16444 --- a/arch/x86/include/asm/elf.h
16445 +++ b/arch/x86/include/asm/elf.h
16446 @@ -243,7 +243,25 @@ extern int force_personality32;
16447 the loader. We need to make sure that it is out of the way of the program
16448 that it will "exec", and that there is sufficient room for the brk. */
16449
16450 +#ifdef CONFIG_PAX_SEGMEXEC
16451 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16452 +#else
16453 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16454 +#endif
16455 +
16456 +#ifdef CONFIG_PAX_ASLR
16457 +#ifdef CONFIG_X86_32
16458 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16459 +
16460 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16461 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16462 +#else
16463 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16464 +
16465 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16466 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16467 +#endif
16468 +#endif
16469
16470 /* This yields a mask that user programs can use to figure out what
16471 instruction set this CPU supports. This could be done in user space,
16472 @@ -296,16 +314,12 @@ do { \
16473
16474 #define ARCH_DLINFO \
16475 do { \
16476 - if (vdso_enabled) \
16477 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16478 - (unsigned long)current->mm->context.vdso); \
16479 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16480 } while (0)
16481
16482 #define ARCH_DLINFO_X32 \
16483 do { \
16484 - if (vdso_enabled) \
16485 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16486 - (unsigned long)current->mm->context.vdso); \
16487 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16488 } while (0)
16489
16490 #define AT_SYSINFO 32
16491 @@ -320,7 +334,7 @@ else \
16492
16493 #endif /* !CONFIG_X86_32 */
16494
16495 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16496 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16497
16498 #define VDSO_ENTRY \
16499 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16500 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16501 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16502 #define compat_arch_setup_additional_pages syscall32_setup_pages
16503
16504 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16505 -#define arch_randomize_brk arch_randomize_brk
16506 -
16507 /*
16508 * True on X86_32 or when emulating IA32 on X86_64
16509 */
16510 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16511 index 77a99ac..39ff7f5 100644
16512 --- a/arch/x86/include/asm/emergency-restart.h
16513 +++ b/arch/x86/include/asm/emergency-restart.h
16514 @@ -1,6 +1,6 @@
16515 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16516 #define _ASM_X86_EMERGENCY_RESTART_H
16517
16518 -extern void machine_emergency_restart(void);
16519 +extern void machine_emergency_restart(void) __noreturn;
16520
16521 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16522 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16523 index d3d7469..677ef72 100644
16524 --- a/arch/x86/include/asm/floppy.h
16525 +++ b/arch/x86/include/asm/floppy.h
16526 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16527 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16528 } fd_routine[] = {
16529 {
16530 - request_dma,
16531 - free_dma,
16532 - get_dma_residue,
16533 - dma_mem_alloc,
16534 - hard_dma_setup
16535 + ._request_dma = request_dma,
16536 + ._free_dma = free_dma,
16537 + ._get_dma_residue = get_dma_residue,
16538 + ._dma_mem_alloc = dma_mem_alloc,
16539 + ._dma_setup = hard_dma_setup
16540 },
16541 {
16542 - vdma_request_dma,
16543 - vdma_nop,
16544 - vdma_get_dma_residue,
16545 - vdma_mem_alloc,
16546 - vdma_dma_setup
16547 + ._request_dma = vdma_request_dma,
16548 + ._free_dma = vdma_nop,
16549 + ._get_dma_residue = vdma_get_dma_residue,
16550 + ._dma_mem_alloc = vdma_mem_alloc,
16551 + ._dma_setup = vdma_dma_setup
16552 }
16553 };
16554
16555 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16556 index cea1c76..6c0d79b 100644
16557 --- a/arch/x86/include/asm/fpu-internal.h
16558 +++ b/arch/x86/include/asm/fpu-internal.h
16559 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16560 #define user_insn(insn, output, input...) \
16561 ({ \
16562 int err; \
16563 + pax_open_userland(); \
16564 asm volatile(ASM_STAC "\n" \
16565 - "1:" #insn "\n\t" \
16566 + "1:" \
16567 + __copyuser_seg \
16568 + #insn "\n\t" \
16569 "2: " ASM_CLAC "\n" \
16570 ".section .fixup,\"ax\"\n" \
16571 "3: movl $-1,%[err]\n" \
16572 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16573 _ASM_EXTABLE(1b, 3b) \
16574 : [err] "=r" (err), output \
16575 : "0"(0), input); \
16576 + pax_close_userland(); \
16577 err; \
16578 })
16579
16580 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16581 "fnclex\n\t"
16582 "emms\n\t"
16583 "fildl %P[addr]" /* set F?P to defined value */
16584 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16585 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16586 }
16587
16588 return fpu_restore_checking(&tsk->thread.fpu);
16589 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16590 index be27ba1..04a8801 100644
16591 --- a/arch/x86/include/asm/futex.h
16592 +++ b/arch/x86/include/asm/futex.h
16593 @@ -12,6 +12,7 @@
16594 #include <asm/smap.h>
16595
16596 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16597 + typecheck(u32 __user *, uaddr); \
16598 asm volatile("\t" ASM_STAC "\n" \
16599 "1:\t" insn "\n" \
16600 "2:\t" ASM_CLAC "\n" \
16601 @@ -20,15 +21,16 @@
16602 "\tjmp\t2b\n" \
16603 "\t.previous\n" \
16604 _ASM_EXTABLE(1b, 3b) \
16605 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16606 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16607 : "i" (-EFAULT), "0" (oparg), "1" (0))
16608
16609 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16610 + typecheck(u32 __user *, uaddr); \
16611 asm volatile("\t" ASM_STAC "\n" \
16612 "1:\tmovl %2, %0\n" \
16613 "\tmovl\t%0, %3\n" \
16614 "\t" insn "\n" \
16615 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16616 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16617 "\tjnz\t1b\n" \
16618 "3:\t" ASM_CLAC "\n" \
16619 "\t.section .fixup,\"ax\"\n" \
16620 @@ -38,7 +40,7 @@
16621 _ASM_EXTABLE(1b, 4b) \
16622 _ASM_EXTABLE(2b, 4b) \
16623 : "=&a" (oldval), "=&r" (ret), \
16624 - "+m" (*uaddr), "=&r" (tem) \
16625 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16626 : "r" (oparg), "i" (-EFAULT), "1" (0))
16627
16628 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16629 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16630
16631 pagefault_disable();
16632
16633 + pax_open_userland();
16634 switch (op) {
16635 case FUTEX_OP_SET:
16636 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16637 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16638 break;
16639 case FUTEX_OP_ADD:
16640 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16641 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16642 uaddr, oparg);
16643 break;
16644 case FUTEX_OP_OR:
16645 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16646 default:
16647 ret = -ENOSYS;
16648 }
16649 + pax_close_userland();
16650
16651 pagefault_enable();
16652
16653 @@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16654 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16655 return -EFAULT;
16656
16657 + pax_open_userland();
16658 asm volatile("\t" ASM_STAC "\n"
16659 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16660 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16661 "2:\t" ASM_CLAC "\n"
16662 "\t.section .fixup, \"ax\"\n"
16663 "3:\tmov %3, %0\n"
16664 "\tjmp 2b\n"
16665 "\t.previous\n"
16666 _ASM_EXTABLE(1b, 3b)
16667 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16668 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16669 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16670 : "memory"
16671 );
16672 + pax_close_userland();
16673
16674 *uval = oldval;
16675 return ret;
16676 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16677 index cba45d9..86344ba 100644
16678 --- a/arch/x86/include/asm/hw_irq.h
16679 +++ b/arch/x86/include/asm/hw_irq.h
16680 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16681 extern void enable_IO_APIC(void);
16682
16683 /* Statistics */
16684 -extern atomic_t irq_err_count;
16685 -extern atomic_t irq_mis_count;
16686 +extern atomic_unchecked_t irq_err_count;
16687 +extern atomic_unchecked_t irq_mis_count;
16688
16689 /* EISA */
16690 extern void eisa_set_level_irq(unsigned int irq);
16691 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16692 index a203659..9889f1c 100644
16693 --- a/arch/x86/include/asm/i8259.h
16694 +++ b/arch/x86/include/asm/i8259.h
16695 @@ -62,7 +62,7 @@ struct legacy_pic {
16696 void (*init)(int auto_eoi);
16697 int (*irq_pending)(unsigned int irq);
16698 void (*make_irq)(unsigned int irq);
16699 -};
16700 +} __do_const;
16701
16702 extern struct legacy_pic *legacy_pic;
16703 extern struct legacy_pic null_legacy_pic;
16704 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16705 index 34f69cb..6d95446 100644
16706 --- a/arch/x86/include/asm/io.h
16707 +++ b/arch/x86/include/asm/io.h
16708 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16709 "m" (*(volatile type __force *)addr) barrier); }
16710
16711 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16712 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16713 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16714 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16715 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16716
16717 build_mmio_read(__readb, "b", unsigned char, "=q", )
16718 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16719 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16720 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16721 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16722
16723 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16724 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16725 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16726 return ioremap_nocache(offset, size);
16727 }
16728
16729 -extern void iounmap(volatile void __iomem *addr);
16730 +extern void iounmap(const volatile void __iomem *addr);
16731
16732 extern void set_iounmap_nonlazy(void);
16733
16734 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16735
16736 #include <linux/vmalloc.h>
16737
16738 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16739 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16740 +{
16741 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16742 +}
16743 +
16744 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16745 +{
16746 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16747 +}
16748 +
16749 /*
16750 * Convert a virtual cached pointer to an uncached pointer
16751 */
16752 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16753 index bba3cf8..06bc8da 100644
16754 --- a/arch/x86/include/asm/irqflags.h
16755 +++ b/arch/x86/include/asm/irqflags.h
16756 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16757 sti; \
16758 sysexit
16759
16760 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16761 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16762 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16763 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16764 +
16765 #else
16766 #define INTERRUPT_RETURN iret
16767 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16768 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16769 index 9454c16..e4100e3 100644
16770 --- a/arch/x86/include/asm/kprobes.h
16771 +++ b/arch/x86/include/asm/kprobes.h
16772 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16773 #define RELATIVEJUMP_SIZE 5
16774 #define RELATIVECALL_OPCODE 0xe8
16775 #define RELATIVE_ADDR_SIZE 4
16776 -#define MAX_STACK_SIZE 64
16777 -#define MIN_STACK_SIZE(ADDR) \
16778 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16779 - THREAD_SIZE - (unsigned long)(ADDR))) \
16780 - ? (MAX_STACK_SIZE) \
16781 - : (((unsigned long)current_thread_info()) + \
16782 - THREAD_SIZE - (unsigned long)(ADDR)))
16783 +#define MAX_STACK_SIZE 64UL
16784 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16785
16786 #define flush_insn_slot(p) do { } while (0)
16787
16788 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16789 index 4ad6560..75c7bdd 100644
16790 --- a/arch/x86/include/asm/local.h
16791 +++ b/arch/x86/include/asm/local.h
16792 @@ -10,33 +10,97 @@ typedef struct {
16793 atomic_long_t a;
16794 } local_t;
16795
16796 +typedef struct {
16797 + atomic_long_unchecked_t a;
16798 +} local_unchecked_t;
16799 +
16800 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16801
16802 #define local_read(l) atomic_long_read(&(l)->a)
16803 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16804 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16805 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16806
16807 static inline void local_inc(local_t *l)
16808 {
16809 - asm volatile(_ASM_INC "%0"
16810 + asm volatile(_ASM_INC "%0\n"
16811 +
16812 +#ifdef CONFIG_PAX_REFCOUNT
16813 + "jno 0f\n"
16814 + _ASM_DEC "%0\n"
16815 + "int $4\n0:\n"
16816 + _ASM_EXTABLE(0b, 0b)
16817 +#endif
16818 +
16819 + : "+m" (l->a.counter));
16820 +}
16821 +
16822 +static inline void local_inc_unchecked(local_unchecked_t *l)
16823 +{
16824 + asm volatile(_ASM_INC "%0\n"
16825 : "+m" (l->a.counter));
16826 }
16827
16828 static inline void local_dec(local_t *l)
16829 {
16830 - asm volatile(_ASM_DEC "%0"
16831 + asm volatile(_ASM_DEC "%0\n"
16832 +
16833 +#ifdef CONFIG_PAX_REFCOUNT
16834 + "jno 0f\n"
16835 + _ASM_INC "%0\n"
16836 + "int $4\n0:\n"
16837 + _ASM_EXTABLE(0b, 0b)
16838 +#endif
16839 +
16840 + : "+m" (l->a.counter));
16841 +}
16842 +
16843 +static inline void local_dec_unchecked(local_unchecked_t *l)
16844 +{
16845 + asm volatile(_ASM_DEC "%0\n"
16846 : "+m" (l->a.counter));
16847 }
16848
16849 static inline void local_add(long i, local_t *l)
16850 {
16851 - asm volatile(_ASM_ADD "%1,%0"
16852 + asm volatile(_ASM_ADD "%1,%0\n"
16853 +
16854 +#ifdef CONFIG_PAX_REFCOUNT
16855 + "jno 0f\n"
16856 + _ASM_SUB "%1,%0\n"
16857 + "int $4\n0:\n"
16858 + _ASM_EXTABLE(0b, 0b)
16859 +#endif
16860 +
16861 + : "+m" (l->a.counter)
16862 + : "ir" (i));
16863 +}
16864 +
16865 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16866 +{
16867 + asm volatile(_ASM_ADD "%1,%0\n"
16868 : "+m" (l->a.counter)
16869 : "ir" (i));
16870 }
16871
16872 static inline void local_sub(long i, local_t *l)
16873 {
16874 - asm volatile(_ASM_SUB "%1,%0"
16875 + asm volatile(_ASM_SUB "%1,%0\n"
16876 +
16877 +#ifdef CONFIG_PAX_REFCOUNT
16878 + "jno 0f\n"
16879 + _ASM_ADD "%1,%0\n"
16880 + "int $4\n0:\n"
16881 + _ASM_EXTABLE(0b, 0b)
16882 +#endif
16883 +
16884 + : "+m" (l->a.counter)
16885 + : "ir" (i));
16886 +}
16887 +
16888 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16889 +{
16890 + asm volatile(_ASM_SUB "%1,%0\n"
16891 : "+m" (l->a.counter)
16892 : "ir" (i));
16893 }
16894 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16895 */
16896 static inline int local_sub_and_test(long i, local_t *l)
16897 {
16898 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16899 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16900 }
16901
16902 /**
16903 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16904 */
16905 static inline int local_dec_and_test(local_t *l)
16906 {
16907 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16908 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16909 }
16910
16911 /**
16912 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16913 */
16914 static inline int local_inc_and_test(local_t *l)
16915 {
16916 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16917 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16918 }
16919
16920 /**
16921 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16922 */
16923 static inline int local_add_negative(long i, local_t *l)
16924 {
16925 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16926 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16927 }
16928
16929 /**
16930 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16931 static inline long local_add_return(long i, local_t *l)
16932 {
16933 long __i = i;
16934 + asm volatile(_ASM_XADD "%0, %1\n"
16935 +
16936 +#ifdef CONFIG_PAX_REFCOUNT
16937 + "jno 0f\n"
16938 + _ASM_MOV "%0,%1\n"
16939 + "int $4\n0:\n"
16940 + _ASM_EXTABLE(0b, 0b)
16941 +#endif
16942 +
16943 + : "+r" (i), "+m" (l->a.counter)
16944 + : : "memory");
16945 + return i + __i;
16946 +}
16947 +
16948 +/**
16949 + * local_add_return_unchecked - add and return
16950 + * @i: integer value to add
16951 + * @l: pointer to type local_unchecked_t
16952 + *
16953 + * Atomically adds @i to @l and returns @i + @l
16954 + */
16955 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16956 +{
16957 + long __i = i;
16958 asm volatile(_ASM_XADD "%0, %1;"
16959 : "+r" (i), "+m" (l->a.counter)
16960 : : "memory");
16961 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16962
16963 #define local_cmpxchg(l, o, n) \
16964 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16965 +#define local_cmpxchg_unchecked(l, o, n) \
16966 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
16967 /* Always has a lock prefix */
16968 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16969
16970 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16971 new file mode 100644
16972 index 0000000..2bfd3ba
16973 --- /dev/null
16974 +++ b/arch/x86/include/asm/mman.h
16975 @@ -0,0 +1,15 @@
16976 +#ifndef _X86_MMAN_H
16977 +#define _X86_MMAN_H
16978 +
16979 +#include <uapi/asm/mman.h>
16980 +
16981 +#ifdef __KERNEL__
16982 +#ifndef __ASSEMBLY__
16983 +#ifdef CONFIG_X86_32
16984 +#define arch_mmap_check i386_mmap_check
16985 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16986 +#endif
16987 +#endif
16988 +#endif
16989 +
16990 +#endif /* X86_MMAN_H */
16991 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16992 index 5f55e69..e20bfb1 100644
16993 --- a/arch/x86/include/asm/mmu.h
16994 +++ b/arch/x86/include/asm/mmu.h
16995 @@ -9,7 +9,7 @@
16996 * we put the segment information here.
16997 */
16998 typedef struct {
16999 - void *ldt;
17000 + struct desc_struct *ldt;
17001 int size;
17002
17003 #ifdef CONFIG_X86_64
17004 @@ -18,7 +18,19 @@ typedef struct {
17005 #endif
17006
17007 struct mutex lock;
17008 - void *vdso;
17009 + unsigned long vdso;
17010 +
17011 +#ifdef CONFIG_X86_32
17012 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17013 + unsigned long user_cs_base;
17014 + unsigned long user_cs_limit;
17015 +
17016 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17017 + cpumask_t cpu_user_cs_mask;
17018 +#endif
17019 +
17020 +#endif
17021 +#endif
17022 } mm_context_t;
17023
17024 #ifdef CONFIG_SMP
17025 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17026 index be12c53..4d24039 100644
17027 --- a/arch/x86/include/asm/mmu_context.h
17028 +++ b/arch/x86/include/asm/mmu_context.h
17029 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17030
17031 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17032 {
17033 +
17034 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17035 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17036 + unsigned int i;
17037 + pgd_t *pgd;
17038 +
17039 + pax_open_kernel();
17040 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17041 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17042 + set_pgd_batched(pgd+i, native_make_pgd(0));
17043 + pax_close_kernel();
17044 + }
17045 +#endif
17046 +
17047 #ifdef CONFIG_SMP
17048 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17049 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17050 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17051 struct task_struct *tsk)
17052 {
17053 unsigned cpu = smp_processor_id();
17054 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17055 + int tlbstate = TLBSTATE_OK;
17056 +#endif
17057
17058 if (likely(prev != next)) {
17059 #ifdef CONFIG_SMP
17060 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17061 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17062 +#endif
17063 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17064 this_cpu_write(cpu_tlbstate.active_mm, next);
17065 #endif
17066 cpumask_set_cpu(cpu, mm_cpumask(next));
17067
17068 /* Re-load page tables */
17069 +#ifdef CONFIG_PAX_PER_CPU_PGD
17070 + pax_open_kernel();
17071 +
17072 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17073 + if (static_cpu_has(X86_FEATURE_PCID))
17074 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17075 + else
17076 +#endif
17077 +
17078 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17079 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17080 + pax_close_kernel();
17081 + 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));
17082 +
17083 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17084 + if (static_cpu_has(X86_FEATURE_PCID)) {
17085 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17086 + u64 descriptor[2];
17087 + descriptor[0] = PCID_USER;
17088 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17089 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17090 + descriptor[0] = PCID_KERNEL;
17091 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17092 + }
17093 + } else {
17094 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17095 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17096 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17097 + else
17098 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17099 + }
17100 + } else
17101 +#endif
17102 +
17103 + load_cr3(get_cpu_pgd(cpu, kernel));
17104 +#else
17105 load_cr3(next->pgd);
17106 +#endif
17107
17108 /* Stop flush ipis for the previous mm */
17109 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17110 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17111 /* Load the LDT, if the LDT is different: */
17112 if (unlikely(prev->context.ldt != next->context.ldt))
17113 load_LDT_nolock(&next->context);
17114 +
17115 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17116 + if (!(__supported_pte_mask & _PAGE_NX)) {
17117 + smp_mb__before_clear_bit();
17118 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17119 + smp_mb__after_clear_bit();
17120 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17121 + }
17122 +#endif
17123 +
17124 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17125 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17126 + prev->context.user_cs_limit != next->context.user_cs_limit))
17127 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17128 +#ifdef CONFIG_SMP
17129 + else if (unlikely(tlbstate != TLBSTATE_OK))
17130 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17131 +#endif
17132 +#endif
17133 +
17134 }
17135 + else {
17136 +
17137 +#ifdef CONFIG_PAX_PER_CPU_PGD
17138 + pax_open_kernel();
17139 +
17140 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17141 + if (static_cpu_has(X86_FEATURE_PCID))
17142 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17143 + else
17144 +#endif
17145 +
17146 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17147 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17148 + pax_close_kernel();
17149 + 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));
17150 +
17151 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17152 + if (static_cpu_has(X86_FEATURE_PCID)) {
17153 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17154 + u64 descriptor[2];
17155 + descriptor[0] = PCID_USER;
17156 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17157 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17158 + descriptor[0] = PCID_KERNEL;
17159 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17160 + }
17161 + } else {
17162 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17163 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17164 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17165 + else
17166 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17167 + }
17168 + } else
17169 +#endif
17170 +
17171 + load_cr3(get_cpu_pgd(cpu, kernel));
17172 +#endif
17173 +
17174 #ifdef CONFIG_SMP
17175 - else {
17176 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17177 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17178
17179 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17180 * tlb flush IPI delivery. We must reload CR3
17181 * to make sure to use no freed page tables.
17182 */
17183 +
17184 +#ifndef CONFIG_PAX_PER_CPU_PGD
17185 load_cr3(next->pgd);
17186 +#endif
17187 +
17188 load_LDT_nolock(&next->context);
17189 +
17190 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17191 + if (!(__supported_pte_mask & _PAGE_NX))
17192 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17193 +#endif
17194 +
17195 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17196 +#ifdef CONFIG_PAX_PAGEEXEC
17197 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17198 +#endif
17199 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17200 +#endif
17201 +
17202 }
17203 +#endif
17204 }
17205 -#endif
17206 }
17207
17208 #define activate_mm(prev, next) \
17209 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17210 index e3b7819..b257c64 100644
17211 --- a/arch/x86/include/asm/module.h
17212 +++ b/arch/x86/include/asm/module.h
17213 @@ -5,6 +5,7 @@
17214
17215 #ifdef CONFIG_X86_64
17216 /* X86_64 does not define MODULE_PROC_FAMILY */
17217 +#define MODULE_PROC_FAMILY ""
17218 #elif defined CONFIG_M486
17219 #define MODULE_PROC_FAMILY "486 "
17220 #elif defined CONFIG_M586
17221 @@ -57,8 +58,20 @@
17222 #error unknown processor family
17223 #endif
17224
17225 -#ifdef CONFIG_X86_32
17226 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17227 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17228 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17229 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17230 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17231 +#else
17232 +#define MODULE_PAX_KERNEXEC ""
17233 #endif
17234
17235 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17236 +#define MODULE_PAX_UDEREF "UDEREF "
17237 +#else
17238 +#define MODULE_PAX_UDEREF ""
17239 +#endif
17240 +
17241 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17242 +
17243 #endif /* _ASM_X86_MODULE_H */
17244 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17245 index 86f9301..b365cda 100644
17246 --- a/arch/x86/include/asm/nmi.h
17247 +++ b/arch/x86/include/asm/nmi.h
17248 @@ -40,11 +40,11 @@ struct nmiaction {
17249 nmi_handler_t handler;
17250 unsigned long flags;
17251 const char *name;
17252 -};
17253 +} __do_const;
17254
17255 #define register_nmi_handler(t, fn, fg, n, init...) \
17256 ({ \
17257 - static struct nmiaction init fn##_na = { \
17258 + static const struct nmiaction init fn##_na = { \
17259 .handler = (fn), \
17260 .name = (n), \
17261 .flags = (fg), \
17262 @@ -52,7 +52,7 @@ struct nmiaction {
17263 __register_nmi_handler((t), &fn##_na); \
17264 })
17265
17266 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17267 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17268
17269 void unregister_nmi_handler(unsigned int, const char *);
17270
17271 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17272 index c878924..21f4889 100644
17273 --- a/arch/x86/include/asm/page.h
17274 +++ b/arch/x86/include/asm/page.h
17275 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17276 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17277
17278 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17279 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17280
17281 #define __boot_va(x) __va(x)
17282 #define __boot_pa(x) __pa(x)
17283 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17284 index 0f1ddee..e2fc3d1 100644
17285 --- a/arch/x86/include/asm/page_64.h
17286 +++ b/arch/x86/include/asm/page_64.h
17287 @@ -7,9 +7,9 @@
17288
17289 /* duplicated to the one in bootmem.h */
17290 extern unsigned long max_pfn;
17291 -extern unsigned long phys_base;
17292 +extern const unsigned long phys_base;
17293
17294 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17295 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17296 {
17297 unsigned long y = x - __START_KERNEL_map;
17298
17299 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17300 index 401f350..dee5d13 100644
17301 --- a/arch/x86/include/asm/paravirt.h
17302 +++ b/arch/x86/include/asm/paravirt.h
17303 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17304 return (pmd_t) { ret };
17305 }
17306
17307 -static inline pmdval_t pmd_val(pmd_t pmd)
17308 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17309 {
17310 pmdval_t ret;
17311
17312 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17313 val);
17314 }
17315
17316 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17317 +{
17318 + pgdval_t val = native_pgd_val(pgd);
17319 +
17320 + if (sizeof(pgdval_t) > sizeof(long))
17321 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17322 + val, (u64)val >> 32);
17323 + else
17324 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17325 + val);
17326 +}
17327 +
17328 static inline void pgd_clear(pgd_t *pgdp)
17329 {
17330 set_pgd(pgdp, __pgd(0));
17331 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17332 pv_mmu_ops.set_fixmap(idx, phys, flags);
17333 }
17334
17335 +#ifdef CONFIG_PAX_KERNEXEC
17336 +static inline unsigned long pax_open_kernel(void)
17337 +{
17338 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17339 +}
17340 +
17341 +static inline unsigned long pax_close_kernel(void)
17342 +{
17343 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17344 +}
17345 +#else
17346 +static inline unsigned long pax_open_kernel(void) { return 0; }
17347 +static inline unsigned long pax_close_kernel(void) { return 0; }
17348 +#endif
17349 +
17350 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17351
17352 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17353 @@ -906,7 +933,7 @@ extern void default_banner(void);
17354
17355 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17356 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17357 -#define PARA_INDIRECT(addr) *%cs:addr
17358 +#define PARA_INDIRECT(addr) *%ss:addr
17359 #endif
17360
17361 #define INTERRUPT_RETURN \
17362 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17363 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17364 CLBR_NONE, \
17365 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17366 +
17367 +#define GET_CR0_INTO_RDI \
17368 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17369 + mov %rax,%rdi
17370 +
17371 +#define SET_RDI_INTO_CR0 \
17372 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17373 +
17374 +#define GET_CR3_INTO_RDI \
17375 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17376 + mov %rax,%rdi
17377 +
17378 +#define SET_RDI_INTO_CR3 \
17379 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17380 +
17381 #endif /* CONFIG_X86_32 */
17382
17383 #endif /* __ASSEMBLY__ */
17384 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17385 index aab8f67..0fb0ee4 100644
17386 --- a/arch/x86/include/asm/paravirt_types.h
17387 +++ b/arch/x86/include/asm/paravirt_types.h
17388 @@ -84,7 +84,7 @@ struct pv_init_ops {
17389 */
17390 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17391 unsigned long addr, unsigned len);
17392 -};
17393 +} __no_const __no_randomize_layout;
17394
17395
17396 struct pv_lazy_ops {
17397 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17398 void (*enter)(void);
17399 void (*leave)(void);
17400 void (*flush)(void);
17401 -};
17402 +} __no_randomize_layout;
17403
17404 struct pv_time_ops {
17405 unsigned long long (*sched_clock)(void);
17406 unsigned long long (*steal_clock)(int cpu);
17407 unsigned long (*get_tsc_khz)(void);
17408 -};
17409 +} __no_const __no_randomize_layout;
17410
17411 struct pv_cpu_ops {
17412 /* hooks for various privileged instructions */
17413 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17414
17415 void (*start_context_switch)(struct task_struct *prev);
17416 void (*end_context_switch)(struct task_struct *next);
17417 -};
17418 +} __no_const __no_randomize_layout;
17419
17420 struct pv_irq_ops {
17421 /*
17422 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17423 #ifdef CONFIG_X86_64
17424 void (*adjust_exception_frame)(void);
17425 #endif
17426 -};
17427 +} __no_randomize_layout;
17428
17429 struct pv_apic_ops {
17430 #ifdef CONFIG_X86_LOCAL_APIC
17431 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17432 unsigned long start_eip,
17433 unsigned long start_esp);
17434 #endif
17435 -};
17436 +} __no_const __no_randomize_layout;
17437
17438 struct pv_mmu_ops {
17439 unsigned long (*read_cr2)(void);
17440 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17441 struct paravirt_callee_save make_pud;
17442
17443 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17444 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17445 #endif /* PAGETABLE_LEVELS == 4 */
17446 #endif /* PAGETABLE_LEVELS >= 3 */
17447
17448 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17449 an mfn. We can tell which is which from the index. */
17450 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17451 phys_addr_t phys, pgprot_t flags);
17452 -};
17453 +
17454 +#ifdef CONFIG_PAX_KERNEXEC
17455 + unsigned long (*pax_open_kernel)(void);
17456 + unsigned long (*pax_close_kernel)(void);
17457 +#endif
17458 +
17459 +} __no_randomize_layout;
17460
17461 struct arch_spinlock;
17462 #ifdef CONFIG_SMP
17463 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17464 struct pv_lock_ops {
17465 struct paravirt_callee_save lock_spinning;
17466 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17467 -};
17468 +} __no_randomize_layout;
17469
17470 /* This contains all the paravirt structures: we get a convenient
17471 * number for each function using the offset which we use to indicate
17472 - * what to patch. */
17473 + * what to patch.
17474 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17475 + */
17476 +
17477 struct paravirt_patch_template {
17478 struct pv_init_ops pv_init_ops;
17479 struct pv_time_ops pv_time_ops;
17480 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17481 struct pv_apic_ops pv_apic_ops;
17482 struct pv_mmu_ops pv_mmu_ops;
17483 struct pv_lock_ops pv_lock_ops;
17484 -};
17485 +} __no_randomize_layout;
17486
17487 extern struct pv_info pv_info;
17488 extern struct pv_init_ops pv_init_ops;
17489 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17490 index c4412e9..90e88c5 100644
17491 --- a/arch/x86/include/asm/pgalloc.h
17492 +++ b/arch/x86/include/asm/pgalloc.h
17493 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17494 pmd_t *pmd, pte_t *pte)
17495 {
17496 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17497 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17498 +}
17499 +
17500 +static inline void pmd_populate_user(struct mm_struct *mm,
17501 + pmd_t *pmd, pte_t *pte)
17502 +{
17503 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17504 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17505 }
17506
17507 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17508
17509 #ifdef CONFIG_X86_PAE
17510 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17511 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17512 +{
17513 + pud_populate(mm, pudp, pmd);
17514 +}
17515 #else /* !CONFIG_X86_PAE */
17516 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17517 {
17518 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17519 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17520 }
17521 +
17522 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17523 +{
17524 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17525 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17526 +}
17527 #endif /* CONFIG_X86_PAE */
17528
17529 #if PAGETABLE_LEVELS > 3
17530 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17531 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17532 }
17533
17534 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17535 +{
17536 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17537 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17538 +}
17539 +
17540 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17541 {
17542 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17543 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17544 index 3bf2dd0..23d2a9f 100644
17545 --- a/arch/x86/include/asm/pgtable-2level.h
17546 +++ b/arch/x86/include/asm/pgtable-2level.h
17547 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17548
17549 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17550 {
17551 + pax_open_kernel();
17552 *pmdp = pmd;
17553 + pax_close_kernel();
17554 }
17555
17556 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17557 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17558 index 81bb91b..9392125 100644
17559 --- a/arch/x86/include/asm/pgtable-3level.h
17560 +++ b/arch/x86/include/asm/pgtable-3level.h
17561 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17562
17563 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17564 {
17565 + pax_open_kernel();
17566 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17567 + pax_close_kernel();
17568 }
17569
17570 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17571 {
17572 + pax_open_kernel();
17573 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17574 + pax_close_kernel();
17575 }
17576
17577 /*
17578 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17579 index bbc8b12..f228861 100644
17580 --- a/arch/x86/include/asm/pgtable.h
17581 +++ b/arch/x86/include/asm/pgtable.h
17582 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17583
17584 #ifndef __PAGETABLE_PUD_FOLDED
17585 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17586 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17587 #define pgd_clear(pgd) native_pgd_clear(pgd)
17588 #endif
17589
17590 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17591
17592 #define arch_end_context_switch(prev) do {} while(0)
17593
17594 +#define pax_open_kernel() native_pax_open_kernel()
17595 +#define pax_close_kernel() native_pax_close_kernel()
17596 #endif /* CONFIG_PARAVIRT */
17597
17598 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17599 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17600 +
17601 +#ifdef CONFIG_PAX_KERNEXEC
17602 +static inline unsigned long native_pax_open_kernel(void)
17603 +{
17604 + unsigned long cr0;
17605 +
17606 + preempt_disable();
17607 + barrier();
17608 + cr0 = read_cr0() ^ X86_CR0_WP;
17609 + BUG_ON(cr0 & X86_CR0_WP);
17610 + write_cr0(cr0);
17611 + return cr0 ^ X86_CR0_WP;
17612 +}
17613 +
17614 +static inline unsigned long native_pax_close_kernel(void)
17615 +{
17616 + unsigned long cr0;
17617 +
17618 + cr0 = read_cr0() ^ X86_CR0_WP;
17619 + BUG_ON(!(cr0 & X86_CR0_WP));
17620 + write_cr0(cr0);
17621 + barrier();
17622 + preempt_enable_no_resched();
17623 + return cr0 ^ X86_CR0_WP;
17624 +}
17625 +#else
17626 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17627 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17628 +#endif
17629 +
17630 /*
17631 * The following only work if pte_present() is true.
17632 * Undefined behaviour if not..
17633 */
17634 +static inline int pte_user(pte_t pte)
17635 +{
17636 + return pte_val(pte) & _PAGE_USER;
17637 +}
17638 +
17639 static inline int pte_dirty(pte_t pte)
17640 {
17641 return pte_flags(pte) & _PAGE_DIRTY;
17642 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17643 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17644 }
17645
17646 +static inline unsigned long pgd_pfn(pgd_t pgd)
17647 +{
17648 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17649 +}
17650 +
17651 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17652
17653 static inline int pmd_large(pmd_t pte)
17654 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17655 return pte_clear_flags(pte, _PAGE_RW);
17656 }
17657
17658 +static inline pte_t pte_mkread(pte_t pte)
17659 +{
17660 + return __pte(pte_val(pte) | _PAGE_USER);
17661 +}
17662 +
17663 static inline pte_t pte_mkexec(pte_t pte)
17664 {
17665 - return pte_clear_flags(pte, _PAGE_NX);
17666 +#ifdef CONFIG_X86_PAE
17667 + if (__supported_pte_mask & _PAGE_NX)
17668 + return pte_clear_flags(pte, _PAGE_NX);
17669 + else
17670 +#endif
17671 + return pte_set_flags(pte, _PAGE_USER);
17672 +}
17673 +
17674 +static inline pte_t pte_exprotect(pte_t pte)
17675 +{
17676 +#ifdef CONFIG_X86_PAE
17677 + if (__supported_pte_mask & _PAGE_NX)
17678 + return pte_set_flags(pte, _PAGE_NX);
17679 + else
17680 +#endif
17681 + return pte_clear_flags(pte, _PAGE_USER);
17682 }
17683
17684 static inline pte_t pte_mkdirty(pte_t pte)
17685 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17686 #endif
17687
17688 #ifndef __ASSEMBLY__
17689 +
17690 +#ifdef CONFIG_PAX_PER_CPU_PGD
17691 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17692 +enum cpu_pgd_type {kernel = 0, user = 1};
17693 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17694 +{
17695 + return cpu_pgd[cpu][type];
17696 +}
17697 +#endif
17698 +
17699 #include <linux/mm_types.h>
17700 #include <linux/mmdebug.h>
17701 #include <linux/log2.h>
17702 @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17703 * Currently stuck as a macro due to indirect forward reference to
17704 * linux/mmzone.h's __section_mem_map_addr() definition:
17705 */
17706 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17707 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17708
17709 /* Find an entry in the second-level page table.. */
17710 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17711 @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17712 * Currently stuck as a macro due to indirect forward reference to
17713 * linux/mmzone.h's __section_mem_map_addr() definition:
17714 */
17715 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17716 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17717
17718 /* to find an entry in a page-table-directory. */
17719 static inline unsigned long pud_index(unsigned long address)
17720 @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17721
17722 static inline int pgd_bad(pgd_t pgd)
17723 {
17724 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17725 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17726 }
17727
17728 static inline int pgd_none(pgd_t pgd)
17729 @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17730 * pgd_offset() returns a (pgd_t *)
17731 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17732 */
17733 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17734 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17735 +
17736 +#ifdef CONFIG_PAX_PER_CPU_PGD
17737 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17738 +#endif
17739 +
17740 /*
17741 * a shortcut which implies the use of the kernel's pgd, instead
17742 * of a process's
17743 @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17744 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17745 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17746
17747 +#ifdef CONFIG_X86_32
17748 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17749 +#else
17750 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17751 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17752 +
17753 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17754 +#ifdef __ASSEMBLY__
17755 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17756 +#else
17757 +extern unsigned long pax_user_shadow_base;
17758 +extern pgdval_t clone_pgd_mask;
17759 +#endif
17760 +#endif
17761 +
17762 +#endif
17763 +
17764 #ifndef __ASSEMBLY__
17765
17766 extern int direct_gbpages;
17767 @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17768 * dst and src can be on the same page, but the range must not overlap,
17769 * and must not cross a page boundary.
17770 */
17771 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17772 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17773 {
17774 - memcpy(dst, src, count * sizeof(pgd_t));
17775 + pax_open_kernel();
17776 + while (count--)
17777 + *dst++ = *src++;
17778 + pax_close_kernel();
17779 }
17780
17781 +#ifdef CONFIG_PAX_PER_CPU_PGD
17782 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17783 +#endif
17784 +
17785 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17786 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17787 +#else
17788 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17789 +#endif
17790 +
17791 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17792 static inline int page_level_shift(enum pg_level level)
17793 {
17794 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17795 index 9ee3221..b979c6b 100644
17796 --- a/arch/x86/include/asm/pgtable_32.h
17797 +++ b/arch/x86/include/asm/pgtable_32.h
17798 @@ -25,9 +25,6 @@
17799 struct mm_struct;
17800 struct vm_area_struct;
17801
17802 -extern pgd_t swapper_pg_dir[1024];
17803 -extern pgd_t initial_page_table[1024];
17804 -
17805 static inline void pgtable_cache_init(void) { }
17806 static inline void check_pgt_cache(void) { }
17807 void paging_init(void);
17808 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17809 # include <asm/pgtable-2level.h>
17810 #endif
17811
17812 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17813 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17814 +#ifdef CONFIG_X86_PAE
17815 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17816 +#endif
17817 +
17818 #if defined(CONFIG_HIGHPTE)
17819 #define pte_offset_map(dir, address) \
17820 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17821 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17822 /* Clear a kernel PTE and flush it from the TLB */
17823 #define kpte_clear_flush(ptep, vaddr) \
17824 do { \
17825 + pax_open_kernel(); \
17826 pte_clear(&init_mm, (vaddr), (ptep)); \
17827 + pax_close_kernel(); \
17828 __flush_tlb_one((vaddr)); \
17829 } while (0)
17830
17831 #endif /* !__ASSEMBLY__ */
17832
17833 +#define HAVE_ARCH_UNMAPPED_AREA
17834 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17835 +
17836 /*
17837 * kern_addr_valid() is (1) for FLATMEM and (0) for
17838 * SPARSEMEM and DISCONTIGMEM
17839 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17840 index ed5903b..c7fe163 100644
17841 --- a/arch/x86/include/asm/pgtable_32_types.h
17842 +++ b/arch/x86/include/asm/pgtable_32_types.h
17843 @@ -8,7 +8,7 @@
17844 */
17845 #ifdef CONFIG_X86_PAE
17846 # include <asm/pgtable-3level_types.h>
17847 -# define PMD_SIZE (1UL << PMD_SHIFT)
17848 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17849 # define PMD_MASK (~(PMD_SIZE - 1))
17850 #else
17851 # include <asm/pgtable-2level_types.h>
17852 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17853 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17854 #endif
17855
17856 +#ifdef CONFIG_PAX_KERNEXEC
17857 +#ifndef __ASSEMBLY__
17858 +extern unsigned char MODULES_EXEC_VADDR[];
17859 +extern unsigned char MODULES_EXEC_END[];
17860 +#endif
17861 +#include <asm/boot.h>
17862 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17863 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17864 +#else
17865 +#define ktla_ktva(addr) (addr)
17866 +#define ktva_ktla(addr) (addr)
17867 +#endif
17868 +
17869 #define MODULES_VADDR VMALLOC_START
17870 #define MODULES_END VMALLOC_END
17871 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17872 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17873 index e22c1db..23a625a 100644
17874 --- a/arch/x86/include/asm/pgtable_64.h
17875 +++ b/arch/x86/include/asm/pgtable_64.h
17876 @@ -16,10 +16,14 @@
17877
17878 extern pud_t level3_kernel_pgt[512];
17879 extern pud_t level3_ident_pgt[512];
17880 +extern pud_t level3_vmalloc_start_pgt[512];
17881 +extern pud_t level3_vmalloc_end_pgt[512];
17882 +extern pud_t level3_vmemmap_pgt[512];
17883 +extern pud_t level2_vmemmap_pgt[512];
17884 extern pmd_t level2_kernel_pgt[512];
17885 extern pmd_t level2_fixmap_pgt[512];
17886 -extern pmd_t level2_ident_pgt[512];
17887 -extern pgd_t init_level4_pgt[];
17888 +extern pmd_t level2_ident_pgt[512*2];
17889 +extern pgd_t init_level4_pgt[512];
17890
17891 #define swapper_pg_dir init_level4_pgt
17892
17893 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17894
17895 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17896 {
17897 + pax_open_kernel();
17898 *pmdp = pmd;
17899 + pax_close_kernel();
17900 }
17901
17902 static inline void native_pmd_clear(pmd_t *pmd)
17903 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17904
17905 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17906 {
17907 + pax_open_kernel();
17908 *pudp = pud;
17909 + pax_close_kernel();
17910 }
17911
17912 static inline void native_pud_clear(pud_t *pud)
17913 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17914
17915 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17916 {
17917 + pax_open_kernel();
17918 + *pgdp = pgd;
17919 + pax_close_kernel();
17920 +}
17921 +
17922 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17923 +{
17924 *pgdp = pgd;
17925 }
17926
17927 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17928 index 2d88344..4679fc3 100644
17929 --- a/arch/x86/include/asm/pgtable_64_types.h
17930 +++ b/arch/x86/include/asm/pgtable_64_types.h
17931 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17932 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17933 #define MODULES_END _AC(0xffffffffff000000, UL)
17934 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17935 +#define MODULES_EXEC_VADDR MODULES_VADDR
17936 +#define MODULES_EXEC_END MODULES_END
17937 +
17938 +#define ktla_ktva(addr) (addr)
17939 +#define ktva_ktla(addr) (addr)
17940
17941 #define EARLY_DYNAMIC_PAGE_TABLES 64
17942
17943 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17944 index 840c127..a8f297b 100644
17945 --- a/arch/x86/include/asm/pgtable_types.h
17946 +++ b/arch/x86/include/asm/pgtable_types.h
17947 @@ -16,13 +16,12 @@
17948 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17949 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17950 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17951 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17952 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17953 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17954 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17955 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17956 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17957 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17958 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17959 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17960 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17961 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17962
17963 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17964 @@ -40,7 +39,6 @@
17965 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17966 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17967 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17968 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17969 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17970 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17971 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17972 @@ -87,8 +85,10 @@
17973
17974 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17975 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17976 -#else
17977 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17978 #define _PAGE_NX (_AT(pteval_t, 0))
17979 +#else
17980 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17981 #endif
17982
17983 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17984 @@ -147,6 +147,9 @@
17985 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17986 _PAGE_ACCESSED)
17987
17988 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
17989 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
17990 +
17991 #define __PAGE_KERNEL_EXEC \
17992 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17993 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17994 @@ -157,7 +160,7 @@
17995 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17996 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17997 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17998 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17999 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18000 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18001 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18002 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18003 @@ -219,8 +222,8 @@
18004 * bits are combined, this will alow user to access the high address mapped
18005 * VDSO in the presence of CONFIG_COMPAT_VDSO
18006 */
18007 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18008 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18009 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18010 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18011 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18012 #endif
18013
18014 @@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18015 {
18016 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18017 }
18018 +#endif
18019
18020 +#if PAGETABLE_LEVELS == 3
18021 +#include <asm-generic/pgtable-nopud.h>
18022 +#endif
18023 +
18024 +#if PAGETABLE_LEVELS == 2
18025 +#include <asm-generic/pgtable-nopmd.h>
18026 +#endif
18027 +
18028 +#ifndef __ASSEMBLY__
18029 #if PAGETABLE_LEVELS > 3
18030 typedef struct { pudval_t pud; } pud_t;
18031
18032 @@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18033 return pud.pud;
18034 }
18035 #else
18036 -#include <asm-generic/pgtable-nopud.h>
18037 -
18038 static inline pudval_t native_pud_val(pud_t pud)
18039 {
18040 return native_pgd_val(pud.pgd);
18041 @@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18042 return pmd.pmd;
18043 }
18044 #else
18045 -#include <asm-generic/pgtable-nopmd.h>
18046 -
18047 static inline pmdval_t native_pmd_val(pmd_t pmd)
18048 {
18049 return native_pgd_val(pmd.pud.pgd);
18050 @@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18051
18052 extern pteval_t __supported_pte_mask;
18053 extern void set_nx(void);
18054 -extern int nx_enabled;
18055
18056 #define pgprot_writecombine pgprot_writecombine
18057 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18058 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18059 index c8b0519..fd29e73 100644
18060 --- a/arch/x86/include/asm/preempt.h
18061 +++ b/arch/x86/include/asm/preempt.h
18062 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18063 */
18064 static __always_inline bool __preempt_count_dec_and_test(void)
18065 {
18066 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18067 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18068 }
18069
18070 /*
18071 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18072 index 7b034a4..4fe3e3f 100644
18073 --- a/arch/x86/include/asm/processor.h
18074 +++ b/arch/x86/include/asm/processor.h
18075 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18076 /* Index into per_cpu list: */
18077 u16 cpu_index;
18078 u32 microcode;
18079 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18080 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18081
18082 #define X86_VENDOR_INTEL 0
18083 #define X86_VENDOR_CYRIX 1
18084 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18085 : "memory");
18086 }
18087
18088 +/* invpcid (%rdx),%rax */
18089 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18090 +
18091 +#define INVPCID_SINGLE_ADDRESS 0UL
18092 +#define INVPCID_SINGLE_CONTEXT 1UL
18093 +#define INVPCID_ALL_GLOBAL 2UL
18094 +#define INVPCID_ALL_MONGLOBAL 3UL
18095 +
18096 +#define PCID_KERNEL 0UL
18097 +#define PCID_USER 1UL
18098 +#define PCID_NOFLUSH (1UL << 63)
18099 +
18100 static inline void load_cr3(pgd_t *pgdir)
18101 {
18102 - write_cr3(__pa(pgdir));
18103 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18104 }
18105
18106 #ifdef CONFIG_X86_32
18107 @@ -283,7 +295,7 @@ struct tss_struct {
18108
18109 } ____cacheline_aligned;
18110
18111 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18112 +extern struct tss_struct init_tss[NR_CPUS];
18113
18114 /*
18115 * Save the original ist values for checking stack pointers during debugging
18116 @@ -453,6 +465,7 @@ struct thread_struct {
18117 unsigned short ds;
18118 unsigned short fsindex;
18119 unsigned short gsindex;
18120 + unsigned short ss;
18121 #endif
18122 #ifdef CONFIG_X86_32
18123 unsigned long ip;
18124 @@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
18125 extern unsigned long mmu_cr4_features;
18126 extern u32 *trampoline_cr4_features;
18127
18128 -static inline void set_in_cr4(unsigned long mask)
18129 -{
18130 - unsigned long cr4;
18131 -
18132 - mmu_cr4_features |= mask;
18133 - if (trampoline_cr4_features)
18134 - *trampoline_cr4_features = mmu_cr4_features;
18135 - cr4 = read_cr4();
18136 - cr4 |= mask;
18137 - write_cr4(cr4);
18138 -}
18139 -
18140 -static inline void clear_in_cr4(unsigned long mask)
18141 -{
18142 - unsigned long cr4;
18143 -
18144 - mmu_cr4_features &= ~mask;
18145 - if (trampoline_cr4_features)
18146 - *trampoline_cr4_features = mmu_cr4_features;
18147 - cr4 = read_cr4();
18148 - cr4 &= ~mask;
18149 - write_cr4(cr4);
18150 -}
18151 +extern void set_in_cr4(unsigned long mask);
18152 +extern void clear_in_cr4(unsigned long mask);
18153
18154 typedef struct {
18155 unsigned long seg;
18156 @@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
18157 */
18158 #define TASK_SIZE PAGE_OFFSET
18159 #define TASK_SIZE_MAX TASK_SIZE
18160 +
18161 +#ifdef CONFIG_PAX_SEGMEXEC
18162 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18163 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18164 +#else
18165 #define STACK_TOP TASK_SIZE
18166 -#define STACK_TOP_MAX STACK_TOP
18167 +#endif
18168 +
18169 +#define STACK_TOP_MAX TASK_SIZE
18170
18171 #define INIT_THREAD { \
18172 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18173 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18174 .vm86_info = NULL, \
18175 .sysenter_cs = __KERNEL_CS, \
18176 .io_bitmap_ptr = NULL, \
18177 @@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
18178 */
18179 #define INIT_TSS { \
18180 .x86_tss = { \
18181 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18182 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18183 .ss0 = __KERNEL_DS, \
18184 .ss1 = __KERNEL_CS, \
18185 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18186 @@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
18187 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18188
18189 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18190 -#define KSTK_TOP(info) \
18191 -({ \
18192 - unsigned long *__ptr = (unsigned long *)(info); \
18193 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18194 -})
18195 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18196
18197 /*
18198 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18199 @@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18200 #define task_pt_regs(task) \
18201 ({ \
18202 struct pt_regs *__regs__; \
18203 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18204 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18205 __regs__ - 1; \
18206 })
18207
18208 @@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18209 /*
18210 * User space process size. 47bits minus one guard page.
18211 */
18212 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18213 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18214
18215 /* This decides where the kernel will search for a free chunk of vm
18216 * space during mmap's.
18217 */
18218 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18219 - 0xc0000000 : 0xFFFFe000)
18220 + 0xc0000000 : 0xFFFFf000)
18221
18222 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18223 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18224 @@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18225 #define STACK_TOP_MAX TASK_SIZE_MAX
18226
18227 #define INIT_THREAD { \
18228 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18229 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18230 }
18231
18232 #define INIT_TSS { \
18233 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18234 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18235 }
18236
18237 /*
18238 @@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18239 */
18240 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18241
18242 +#ifdef CONFIG_PAX_SEGMEXEC
18243 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18244 +#endif
18245 +
18246 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18247
18248 /* Get/set a process' ability to use the timestamp counter instruction */
18249 @@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18250 return 0;
18251 }
18252
18253 -extern unsigned long arch_align_stack(unsigned long sp);
18254 +#define arch_align_stack(x) ((x) & ~0xfUL)
18255 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18256
18257 void default_idle(void);
18258 @@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
18259 #define xen_set_default_idle 0
18260 #endif
18261
18262 -void stop_this_cpu(void *dummy);
18263 +void stop_this_cpu(void *dummy) __noreturn;
18264 void df_debug(struct pt_regs *regs, long error_code);
18265 #endif /* _ASM_X86_PROCESSOR_H */
18266 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18267 index 942a086..6c26446 100644
18268 --- a/arch/x86/include/asm/ptrace.h
18269 +++ b/arch/x86/include/asm/ptrace.h
18270 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18271 }
18272
18273 /*
18274 - * user_mode_vm(regs) determines whether a register set came from user mode.
18275 + * user_mode(regs) determines whether a register set came from user mode.
18276 * This is true if V8086 mode was enabled OR if the register set was from
18277 * protected mode with RPL-3 CS value. This tricky test checks that with
18278 * one comparison. Many places in the kernel can bypass this full check
18279 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18280 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18281 + * be used.
18282 */
18283 -static inline int user_mode(struct pt_regs *regs)
18284 +static inline int user_mode_novm(struct pt_regs *regs)
18285 {
18286 #ifdef CONFIG_X86_32
18287 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18288 #else
18289 - return !!(regs->cs & 3);
18290 + return !!(regs->cs & SEGMENT_RPL_MASK);
18291 #endif
18292 }
18293
18294 -static inline int user_mode_vm(struct pt_regs *regs)
18295 +static inline int user_mode(struct pt_regs *regs)
18296 {
18297 #ifdef CONFIG_X86_32
18298 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18299 USER_RPL;
18300 #else
18301 - return user_mode(regs);
18302 + return user_mode_novm(regs);
18303 #endif
18304 }
18305
18306 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18307 #ifdef CONFIG_X86_64
18308 static inline bool user_64bit_mode(struct pt_regs *regs)
18309 {
18310 + unsigned long cs = regs->cs & 0xffff;
18311 #ifndef CONFIG_PARAVIRT
18312 /*
18313 * On non-paravirt systems, this is the only long mode CPL 3
18314 * selector. We do not allow long mode selectors in the LDT.
18315 */
18316 - return regs->cs == __USER_CS;
18317 + return cs == __USER_CS;
18318 #else
18319 /* Headers are too twisted for this to go in paravirt.h. */
18320 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18321 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18322 #endif
18323 }
18324
18325 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18326 * Traps from the kernel do not save sp and ss.
18327 * Use the helper function to retrieve sp.
18328 */
18329 - if (offset == offsetof(struct pt_regs, sp) &&
18330 - regs->cs == __KERNEL_CS)
18331 - return kernel_stack_pointer(regs);
18332 + if (offset == offsetof(struct pt_regs, sp)) {
18333 + unsigned long cs = regs->cs & 0xffff;
18334 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18335 + return kernel_stack_pointer(regs);
18336 + }
18337 #endif
18338 return *(unsigned long *)((unsigned long)regs + offset);
18339 }
18340 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18341 index 9c6b890..5305f53 100644
18342 --- a/arch/x86/include/asm/realmode.h
18343 +++ b/arch/x86/include/asm/realmode.h
18344 @@ -22,16 +22,14 @@ struct real_mode_header {
18345 #endif
18346 /* APM/BIOS reboot */
18347 u32 machine_real_restart_asm;
18348 -#ifdef CONFIG_X86_64
18349 u32 machine_real_restart_seg;
18350 -#endif
18351 };
18352
18353 /* This must match data at trampoline_32/64.S */
18354 struct trampoline_header {
18355 #ifdef CONFIG_X86_32
18356 u32 start;
18357 - u16 gdt_pad;
18358 + u16 boot_cs;
18359 u16 gdt_limit;
18360 u32 gdt_base;
18361 #else
18362 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18363 index a82c4f1..ac45053 100644
18364 --- a/arch/x86/include/asm/reboot.h
18365 +++ b/arch/x86/include/asm/reboot.h
18366 @@ -6,13 +6,13 @@
18367 struct pt_regs;
18368
18369 struct machine_ops {
18370 - void (*restart)(char *cmd);
18371 - void (*halt)(void);
18372 - void (*power_off)(void);
18373 + void (* __noreturn restart)(char *cmd);
18374 + void (* __noreturn halt)(void);
18375 + void (* __noreturn power_off)(void);
18376 void (*shutdown)(void);
18377 void (*crash_shutdown)(struct pt_regs *);
18378 - void (*emergency_restart)(void);
18379 -};
18380 + void (* __noreturn emergency_restart)(void);
18381 +} __no_const;
18382
18383 extern struct machine_ops machine_ops;
18384
18385 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18386 index 8f7866a..e442f20 100644
18387 --- a/arch/x86/include/asm/rmwcc.h
18388 +++ b/arch/x86/include/asm/rmwcc.h
18389 @@ -3,7 +3,34 @@
18390
18391 #ifdef CC_HAVE_ASM_GOTO
18392
18393 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18394 +#ifdef CONFIG_PAX_REFCOUNT
18395 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18396 +do { \
18397 + asm_volatile_goto (fullop \
18398 + ";jno 0f\n" \
18399 + fullantiop \
18400 + ";int $4\n0:\n" \
18401 + _ASM_EXTABLE(0b, 0b) \
18402 + ";j" cc " %l[cc_label]" \
18403 + : : "m" (var), ## __VA_ARGS__ \
18404 + : "memory" : cc_label); \
18405 + return 0; \
18406 +cc_label: \
18407 + return 1; \
18408 +} while (0)
18409 +#else
18410 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18411 +do { \
18412 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18413 + : : "m" (var), ## __VA_ARGS__ \
18414 + : "memory" : cc_label); \
18415 + return 0; \
18416 +cc_label: \
18417 + return 1; \
18418 +} while (0)
18419 +#endif
18420 +
18421 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18422 do { \
18423 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18424 : : "m" (var), ## __VA_ARGS__ \
18425 @@ -13,15 +40,46 @@ cc_label: \
18426 return 1; \
18427 } while (0)
18428
18429 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18430 - __GEN_RMWcc(op " " arg0, var, cc)
18431 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18432 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18433
18434 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18435 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18436 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18437 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18438 +
18439 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18440 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18441 +
18442 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18443 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18444
18445 #else /* !CC_HAVE_ASM_GOTO */
18446
18447 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18448 +#ifdef CONFIG_PAX_REFCOUNT
18449 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18450 +do { \
18451 + char c; \
18452 + asm volatile (fullop \
18453 + ";jno 0f\n" \
18454 + fullantiop \
18455 + ";int $4\n0:\n" \
18456 + _ASM_EXTABLE(0b, 0b) \
18457 + "; set" cc " %1" \
18458 + : "+m" (var), "=qm" (c) \
18459 + : __VA_ARGS__ : "memory"); \
18460 + return c != 0; \
18461 +} while (0)
18462 +#else
18463 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18464 +do { \
18465 + char c; \
18466 + asm volatile (fullop "; set" cc " %1" \
18467 + : "+m" (var), "=qm" (c) \
18468 + : __VA_ARGS__ : "memory"); \
18469 + return c != 0; \
18470 +} while (0)
18471 +#endif
18472 +
18473 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18474 do { \
18475 char c; \
18476 asm volatile (fullop "; set" cc " %1" \
18477 @@ -30,11 +88,17 @@ do { \
18478 return c != 0; \
18479 } while (0)
18480
18481 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18482 - __GEN_RMWcc(op " " arg0, var, cc)
18483 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18484 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18485 +
18486 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18487 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18488 +
18489 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18490 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18491
18492 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18493 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18494 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18495 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18496
18497 #endif /* CC_HAVE_ASM_GOTO */
18498
18499 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18500 index cad82c9..2e5c5c1 100644
18501 --- a/arch/x86/include/asm/rwsem.h
18502 +++ b/arch/x86/include/asm/rwsem.h
18503 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18504 {
18505 asm volatile("# beginning down_read\n\t"
18506 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18507 +
18508 +#ifdef CONFIG_PAX_REFCOUNT
18509 + "jno 0f\n"
18510 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18511 + "int $4\n0:\n"
18512 + _ASM_EXTABLE(0b, 0b)
18513 +#endif
18514 +
18515 /* adds 0x00000001 */
18516 " jns 1f\n"
18517 " call call_rwsem_down_read_failed\n"
18518 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18519 "1:\n\t"
18520 " mov %1,%2\n\t"
18521 " add %3,%2\n\t"
18522 +
18523 +#ifdef CONFIG_PAX_REFCOUNT
18524 + "jno 0f\n"
18525 + "sub %3,%2\n"
18526 + "int $4\n0:\n"
18527 + _ASM_EXTABLE(0b, 0b)
18528 +#endif
18529 +
18530 " jle 2f\n\t"
18531 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18532 " jnz 1b\n\t"
18533 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18534 long tmp;
18535 asm volatile("# beginning down_write\n\t"
18536 LOCK_PREFIX " xadd %1,(%2)\n\t"
18537 +
18538 +#ifdef CONFIG_PAX_REFCOUNT
18539 + "jno 0f\n"
18540 + "mov %1,(%2)\n"
18541 + "int $4\n0:\n"
18542 + _ASM_EXTABLE(0b, 0b)
18543 +#endif
18544 +
18545 /* adds 0xffff0001, returns the old value */
18546 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18547 /* was the active mask 0 before? */
18548 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18549 long tmp;
18550 asm volatile("# beginning __up_read\n\t"
18551 LOCK_PREFIX " xadd %1,(%2)\n\t"
18552 +
18553 +#ifdef CONFIG_PAX_REFCOUNT
18554 + "jno 0f\n"
18555 + "mov %1,(%2)\n"
18556 + "int $4\n0:\n"
18557 + _ASM_EXTABLE(0b, 0b)
18558 +#endif
18559 +
18560 /* subtracts 1, returns the old value */
18561 " jns 1f\n\t"
18562 " call call_rwsem_wake\n" /* expects old value in %edx */
18563 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18564 long tmp;
18565 asm volatile("# beginning __up_write\n\t"
18566 LOCK_PREFIX " xadd %1,(%2)\n\t"
18567 +
18568 +#ifdef CONFIG_PAX_REFCOUNT
18569 + "jno 0f\n"
18570 + "mov %1,(%2)\n"
18571 + "int $4\n0:\n"
18572 + _ASM_EXTABLE(0b, 0b)
18573 +#endif
18574 +
18575 /* subtracts 0xffff0001, returns the old value */
18576 " jns 1f\n\t"
18577 " call call_rwsem_wake\n" /* expects old value in %edx */
18578 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18579 {
18580 asm volatile("# beginning __downgrade_write\n\t"
18581 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18582 +
18583 +#ifdef CONFIG_PAX_REFCOUNT
18584 + "jno 0f\n"
18585 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18586 + "int $4\n0:\n"
18587 + _ASM_EXTABLE(0b, 0b)
18588 +#endif
18589 +
18590 /*
18591 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18592 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18593 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18594 */
18595 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18596 {
18597 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18598 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18599 +
18600 +#ifdef CONFIG_PAX_REFCOUNT
18601 + "jno 0f\n"
18602 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18603 + "int $4\n0:\n"
18604 + _ASM_EXTABLE(0b, 0b)
18605 +#endif
18606 +
18607 : "+m" (sem->count)
18608 : "er" (delta));
18609 }
18610 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18611 */
18612 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18613 {
18614 - return delta + xadd(&sem->count, delta);
18615 + return delta + xadd_check_overflow(&sem->count, delta);
18616 }
18617
18618 #endif /* __KERNEL__ */
18619 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18620 index 6f1c3a8..7744f19 100644
18621 --- a/arch/x86/include/asm/segment.h
18622 +++ b/arch/x86/include/asm/segment.h
18623 @@ -64,10 +64,15 @@
18624 * 26 - ESPFIX small SS
18625 * 27 - per-cpu [ offset to per-cpu data area ]
18626 * 28 - stack_canary-20 [ for stack protector ]
18627 - * 29 - unused
18628 - * 30 - unused
18629 + * 29 - PCI BIOS CS
18630 + * 30 - PCI BIOS DS
18631 * 31 - TSS for double fault handler
18632 */
18633 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18634 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18635 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18636 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18637 +
18638 #define GDT_ENTRY_TLS_MIN 6
18639 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18640
18641 @@ -79,6 +84,8 @@
18642
18643 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18644
18645 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18646 +
18647 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18648
18649 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18650 @@ -104,6 +111,12 @@
18651 #define __KERNEL_STACK_CANARY 0
18652 #endif
18653
18654 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18655 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18656 +
18657 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18658 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18659 +
18660 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18661
18662 /*
18663 @@ -141,7 +154,7 @@
18664 */
18665
18666 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18667 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18668 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18669
18670
18671 #else
18672 @@ -165,6 +178,8 @@
18673 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18674 #define __USER32_DS __USER_DS
18675
18676 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18677 +
18678 #define GDT_ENTRY_TSS 8 /* needs two entries */
18679 #define GDT_ENTRY_LDT 10 /* needs two entries */
18680 #define GDT_ENTRY_TLS_MIN 12
18681 @@ -173,6 +188,8 @@
18682 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18683 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18684
18685 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18686 +
18687 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18688 #define FS_TLS 0
18689 #define GS_TLS 1
18690 @@ -180,12 +197,14 @@
18691 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18692 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18693
18694 -#define GDT_ENTRIES 16
18695 +#define GDT_ENTRIES 17
18696
18697 #endif
18698
18699 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18700 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18701 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18702 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18703 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18704 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18705 #ifndef CONFIG_PARAVIRT
18706 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18707 {
18708 unsigned long __limit;
18709 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18710 - return __limit + 1;
18711 + return __limit;
18712 }
18713
18714 #endif /* !__ASSEMBLY__ */
18715 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18716 index 8d3120f..352b440 100644
18717 --- a/arch/x86/include/asm/smap.h
18718 +++ b/arch/x86/include/asm/smap.h
18719 @@ -25,11 +25,40 @@
18720
18721 #include <asm/alternative-asm.h>
18722
18723 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18724 +#define ASM_PAX_OPEN_USERLAND \
18725 + 661: jmp 663f; \
18726 + .pushsection .altinstr_replacement, "a" ; \
18727 + 662: pushq %rax; nop; \
18728 + .popsection ; \
18729 + .pushsection .altinstructions, "a" ; \
18730 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18731 + .popsection ; \
18732 + call __pax_open_userland; \
18733 + popq %rax; \
18734 + 663:
18735 +
18736 +#define ASM_PAX_CLOSE_USERLAND \
18737 + 661: jmp 663f; \
18738 + .pushsection .altinstr_replacement, "a" ; \
18739 + 662: pushq %rax; nop; \
18740 + .popsection; \
18741 + .pushsection .altinstructions, "a" ; \
18742 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18743 + .popsection; \
18744 + call __pax_close_userland; \
18745 + popq %rax; \
18746 + 663:
18747 +#else
18748 +#define ASM_PAX_OPEN_USERLAND
18749 +#define ASM_PAX_CLOSE_USERLAND
18750 +#endif
18751 +
18752 #ifdef CONFIG_X86_SMAP
18753
18754 #define ASM_CLAC \
18755 661: ASM_NOP3 ; \
18756 - .pushsection .altinstr_replacement, "ax" ; \
18757 + .pushsection .altinstr_replacement, "a" ; \
18758 662: __ASM_CLAC ; \
18759 .popsection ; \
18760 .pushsection .altinstructions, "a" ; \
18761 @@ -38,7 +67,7 @@
18762
18763 #define ASM_STAC \
18764 661: ASM_NOP3 ; \
18765 - .pushsection .altinstr_replacement, "ax" ; \
18766 + .pushsection .altinstr_replacement, "a" ; \
18767 662: __ASM_STAC ; \
18768 .popsection ; \
18769 .pushsection .altinstructions, "a" ; \
18770 @@ -56,6 +85,37 @@
18771
18772 #include <asm/alternative.h>
18773
18774 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18775 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18776 +
18777 +extern void __pax_open_userland(void);
18778 +static __always_inline unsigned long pax_open_userland(void)
18779 +{
18780 +
18781 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18782 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18783 + :
18784 + : [open] "i" (__pax_open_userland)
18785 + : "memory", "rax");
18786 +#endif
18787 +
18788 + return 0;
18789 +}
18790 +
18791 +extern void __pax_close_userland(void);
18792 +static __always_inline unsigned long pax_close_userland(void)
18793 +{
18794 +
18795 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18796 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18797 + :
18798 + : [close] "i" (__pax_close_userland)
18799 + : "memory", "rax");
18800 +#endif
18801 +
18802 + return 0;
18803 +}
18804 +
18805 #ifdef CONFIG_X86_SMAP
18806
18807 static __always_inline void clac(void)
18808 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18809 index 4137890..03fa172 100644
18810 --- a/arch/x86/include/asm/smp.h
18811 +++ b/arch/x86/include/asm/smp.h
18812 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18813 /* cpus sharing the last level cache: */
18814 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18815 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18816 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18817 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18818
18819 static inline struct cpumask *cpu_sibling_mask(int cpu)
18820 {
18821 @@ -79,7 +79,7 @@ struct smp_ops {
18822
18823 void (*send_call_func_ipi)(const struct cpumask *mask);
18824 void (*send_call_func_single_ipi)(int cpu);
18825 -};
18826 +} __no_const;
18827
18828 /* Globals due to paravirt */
18829 extern void set_cpu_sibling_map(int cpu);
18830 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18831 extern int safe_smp_processor_id(void);
18832
18833 #elif defined(CONFIG_X86_64_SMP)
18834 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18835 -
18836 -#define stack_smp_processor_id() \
18837 -({ \
18838 - struct thread_info *ti; \
18839 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18840 - ti->cpu; \
18841 -})
18842 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18843 +#define stack_smp_processor_id() raw_smp_processor_id()
18844 #define safe_smp_processor_id() smp_processor_id()
18845
18846 #endif
18847 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18848 index bf156de..1a782ab 100644
18849 --- a/arch/x86/include/asm/spinlock.h
18850 +++ b/arch/x86/include/asm/spinlock.h
18851 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18852 static inline void arch_read_lock(arch_rwlock_t *rw)
18853 {
18854 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18855 +
18856 +#ifdef CONFIG_PAX_REFCOUNT
18857 + "jno 0f\n"
18858 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18859 + "int $4\n0:\n"
18860 + _ASM_EXTABLE(0b, 0b)
18861 +#endif
18862 +
18863 "jns 1f\n"
18864 "call __read_lock_failed\n\t"
18865 "1:\n"
18866 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18867 static inline void arch_write_lock(arch_rwlock_t *rw)
18868 {
18869 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18870 +
18871 +#ifdef CONFIG_PAX_REFCOUNT
18872 + "jno 0f\n"
18873 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18874 + "int $4\n0:\n"
18875 + _ASM_EXTABLE(0b, 0b)
18876 +#endif
18877 +
18878 "jz 1f\n"
18879 "call __write_lock_failed\n\t"
18880 "1:\n"
18881 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18882
18883 static inline void arch_read_unlock(arch_rwlock_t *rw)
18884 {
18885 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18886 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18887 +
18888 +#ifdef CONFIG_PAX_REFCOUNT
18889 + "jno 0f\n"
18890 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18891 + "int $4\n0:\n"
18892 + _ASM_EXTABLE(0b, 0b)
18893 +#endif
18894 +
18895 :"+m" (rw->lock) : : "memory");
18896 }
18897
18898 static inline void arch_write_unlock(arch_rwlock_t *rw)
18899 {
18900 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18901 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18902 +
18903 +#ifdef CONFIG_PAX_REFCOUNT
18904 + "jno 0f\n"
18905 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18906 + "int $4\n0:\n"
18907 + _ASM_EXTABLE(0b, 0b)
18908 +#endif
18909 +
18910 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18911 }
18912
18913 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18914 index 6a99859..03cb807 100644
18915 --- a/arch/x86/include/asm/stackprotector.h
18916 +++ b/arch/x86/include/asm/stackprotector.h
18917 @@ -47,7 +47,7 @@
18918 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18919 */
18920 #define GDT_STACK_CANARY_INIT \
18921 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18922 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18923
18924 /*
18925 * Initialize the stackprotector canary value.
18926 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18927
18928 static inline void load_stack_canary_segment(void)
18929 {
18930 -#ifdef CONFIG_X86_32
18931 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18932 asm volatile ("mov %0, %%gs" : : "r" (0));
18933 #endif
18934 }
18935 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18936 index 70bbe39..4ae2bd4 100644
18937 --- a/arch/x86/include/asm/stacktrace.h
18938 +++ b/arch/x86/include/asm/stacktrace.h
18939 @@ -11,28 +11,20 @@
18940
18941 extern int kstack_depth_to_print;
18942
18943 -struct thread_info;
18944 +struct task_struct;
18945 struct stacktrace_ops;
18946
18947 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18948 - unsigned long *stack,
18949 - unsigned long bp,
18950 - const struct stacktrace_ops *ops,
18951 - void *data,
18952 - unsigned long *end,
18953 - int *graph);
18954 +typedef unsigned long walk_stack_t(struct task_struct *task,
18955 + void *stack_start,
18956 + unsigned long *stack,
18957 + unsigned long bp,
18958 + const struct stacktrace_ops *ops,
18959 + void *data,
18960 + unsigned long *end,
18961 + int *graph);
18962
18963 -extern unsigned long
18964 -print_context_stack(struct thread_info *tinfo,
18965 - unsigned long *stack, unsigned long bp,
18966 - const struct stacktrace_ops *ops, void *data,
18967 - unsigned long *end, int *graph);
18968 -
18969 -extern unsigned long
18970 -print_context_stack_bp(struct thread_info *tinfo,
18971 - unsigned long *stack, unsigned long bp,
18972 - const struct stacktrace_ops *ops, void *data,
18973 - unsigned long *end, int *graph);
18974 +extern walk_stack_t print_context_stack;
18975 +extern walk_stack_t print_context_stack_bp;
18976
18977 /* Generic stack tracer with callbacks */
18978
18979 @@ -40,7 +32,7 @@ struct stacktrace_ops {
18980 void (*address)(void *data, unsigned long address, int reliable);
18981 /* On negative return stop dumping */
18982 int (*stack)(void *data, char *name);
18983 - walk_stack_t walk_stack;
18984 + walk_stack_t *walk_stack;
18985 };
18986
18987 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18988 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18989 index d7f3b3b..3cc39f1 100644
18990 --- a/arch/x86/include/asm/switch_to.h
18991 +++ b/arch/x86/include/asm/switch_to.h
18992 @@ -108,7 +108,7 @@ do { \
18993 "call __switch_to\n\t" \
18994 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18995 __switch_canary \
18996 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
18997 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18998 "movq %%rax,%%rdi\n\t" \
18999 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19000 "jnz ret_from_fork\n\t" \
19001 @@ -119,7 +119,7 @@ do { \
19002 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19003 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19004 [_tif_fork] "i" (_TIF_FORK), \
19005 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19006 + [thread_info] "m" (current_tinfo), \
19007 [current_task] "m" (current_task) \
19008 __switch_canary_iparam \
19009 : "memory", "cc" __EXTRA_CLOBBER)
19010 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19011 index 3ba3de4..6c113b2 100644
19012 --- a/arch/x86/include/asm/thread_info.h
19013 +++ b/arch/x86/include/asm/thread_info.h
19014 @@ -10,6 +10,7 @@
19015 #include <linux/compiler.h>
19016 #include <asm/page.h>
19017 #include <asm/types.h>
19018 +#include <asm/percpu.h>
19019
19020 /*
19021 * low level task data that entry.S needs immediate access to
19022 @@ -23,7 +24,6 @@ struct exec_domain;
19023 #include <linux/atomic.h>
19024
19025 struct thread_info {
19026 - struct task_struct *task; /* main task structure */
19027 struct exec_domain *exec_domain; /* execution domain */
19028 __u32 flags; /* low level flags */
19029 __u32 status; /* thread synchronous flags */
19030 @@ -32,19 +32,13 @@ struct thread_info {
19031 mm_segment_t addr_limit;
19032 struct restart_block restart_block;
19033 void __user *sysenter_return;
19034 -#ifdef CONFIG_X86_32
19035 - unsigned long previous_esp; /* ESP of the previous stack in
19036 - case of nested (IRQ) stacks
19037 - */
19038 - __u8 supervisor_stack[0];
19039 -#endif
19040 + unsigned long lowest_stack;
19041 unsigned int sig_on_uaccess_error:1;
19042 unsigned int uaccess_err:1; /* uaccess failed */
19043 };
19044
19045 -#define INIT_THREAD_INFO(tsk) \
19046 +#define INIT_THREAD_INFO \
19047 { \
19048 - .task = &tsk, \
19049 .exec_domain = &default_exec_domain, \
19050 .flags = 0, \
19051 .cpu = 0, \
19052 @@ -55,7 +49,7 @@ struct thread_info {
19053 }, \
19054 }
19055
19056 -#define init_thread_info (init_thread_union.thread_info)
19057 +#define init_thread_info (init_thread_union.stack)
19058 #define init_stack (init_thread_union.stack)
19059
19060 #else /* !__ASSEMBLY__ */
19061 @@ -95,6 +89,7 @@ struct thread_info {
19062 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19063 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19064 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19065 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19066
19067 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19068 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19069 @@ -118,17 +113,18 @@ struct thread_info {
19070 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19071 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19072 #define _TIF_X32 (1 << TIF_X32)
19073 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19074
19075 /* work to do in syscall_trace_enter() */
19076 #define _TIF_WORK_SYSCALL_ENTRY \
19077 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19078 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19079 - _TIF_NOHZ)
19080 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19081
19082 /* work to do in syscall_trace_leave() */
19083 #define _TIF_WORK_SYSCALL_EXIT \
19084 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19085 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19086 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19087
19088 /* work to do on interrupt/exception return */
19089 #define _TIF_WORK_MASK \
19090 @@ -139,7 +135,7 @@ struct thread_info {
19091 /* work to do on any return to user space */
19092 #define _TIF_ALLWORK_MASK \
19093 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19094 - _TIF_NOHZ)
19095 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19096
19097 /* Only used for 64 bit */
19098 #define _TIF_DO_NOTIFY_MASK \
19099 @@ -153,45 +149,40 @@ struct thread_info {
19100 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19101 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19102
19103 -#ifdef CONFIG_X86_32
19104 -
19105 -#define STACK_WARN (THREAD_SIZE/8)
19106 -/*
19107 - * macros/functions for gaining access to the thread information structure
19108 - *
19109 - * preempt_count needs to be 1 initially, until the scheduler is functional.
19110 - */
19111 -#ifndef __ASSEMBLY__
19112 -
19113 -
19114 -/* how to get the current stack pointer from C */
19115 -register unsigned long current_stack_pointer asm("esp") __used;
19116 -
19117 -/* how to get the thread information struct from C */
19118 -static inline struct thread_info *current_thread_info(void)
19119 -{
19120 - return (struct thread_info *)
19121 - (current_stack_pointer & ~(THREAD_SIZE - 1));
19122 -}
19123 -
19124 -#else /* !__ASSEMBLY__ */
19125 -
19126 +#ifdef __ASSEMBLY__
19127 /* how to get the thread information struct from ASM */
19128 #define GET_THREAD_INFO(reg) \
19129 - movl $-THREAD_SIZE, reg; \
19130 - andl %esp, reg
19131 + mov PER_CPU_VAR(current_tinfo), reg
19132
19133 /* use this one if reg already contains %esp */
19134 -#define GET_THREAD_INFO_WITH_ESP(reg) \
19135 - andl $-THREAD_SIZE, reg
19136 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19137 +#else
19138 +/* how to get the thread information struct from C */
19139 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19140 +
19141 +static __always_inline struct thread_info *current_thread_info(void)
19142 +{
19143 + return this_cpu_read_stable(current_tinfo);
19144 +}
19145 +#endif
19146 +
19147 +#ifdef CONFIG_X86_32
19148 +
19149 +#define STACK_WARN (THREAD_SIZE/8)
19150 +/*
19151 + * macros/functions for gaining access to the thread information structure
19152 + *
19153 + * preempt_count needs to be 1 initially, until the scheduler is functional.
19154 + */
19155 +#ifndef __ASSEMBLY__
19156 +
19157 +/* how to get the current stack pointer from C */
19158 +register unsigned long current_stack_pointer asm("esp") __used;
19159
19160 #endif
19161
19162 #else /* X86_32 */
19163
19164 -#include <asm/percpu.h>
19165 -#define KERNEL_STACK_OFFSET (5*8)
19166 -
19167 /*
19168 * macros/functions for gaining access to the thread information structure
19169 * preempt_count needs to be 1 initially, until the scheduler is functional.
19170 @@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
19171 #ifndef __ASSEMBLY__
19172 DECLARE_PER_CPU(unsigned long, kernel_stack);
19173
19174 -static inline struct thread_info *current_thread_info(void)
19175 -{
19176 - struct thread_info *ti;
19177 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19178 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19179 - return ti;
19180 -}
19181 -
19182 -#else /* !__ASSEMBLY__ */
19183 -
19184 -/* how to get the thread information struct from ASM */
19185 -#define GET_THREAD_INFO(reg) \
19186 - movq PER_CPU_VAR(kernel_stack),reg ; \
19187 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19188 -
19189 -/*
19190 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19191 - * a certain register (to be used in assembler memory operands).
19192 - */
19193 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19194 -
19195 +/* how to get the current stack pointer from C */
19196 +register unsigned long current_stack_pointer asm("rsp") __used;
19197 #endif
19198
19199 #endif /* !X86_32 */
19200 @@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
19201 extern void arch_task_cache_init(void);
19202 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19203 extern void arch_release_task_struct(struct task_struct *tsk);
19204 +
19205 +#define __HAVE_THREAD_FUNCTIONS
19206 +#define task_thread_info(task) (&(task)->tinfo)
19207 +#define task_stack_page(task) ((task)->stack)
19208 +#define setup_thread_stack(p, org) do {} while (0)
19209 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19210 +
19211 #endif
19212 #endif /* _ASM_X86_THREAD_INFO_H */
19213 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19214 index e6d90ba..f81f114 100644
19215 --- a/arch/x86/include/asm/tlbflush.h
19216 +++ b/arch/x86/include/asm/tlbflush.h
19217 @@ -17,18 +17,44 @@
19218
19219 static inline void __native_flush_tlb(void)
19220 {
19221 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19222 + u64 descriptor[2];
19223 +
19224 + descriptor[0] = PCID_KERNEL;
19225 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19226 + return;
19227 + }
19228 +
19229 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19230 + if (static_cpu_has(X86_FEATURE_PCID)) {
19231 + unsigned int cpu = raw_get_cpu();
19232 +
19233 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19234 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19235 + raw_put_cpu_no_resched();
19236 + return;
19237 + }
19238 +#endif
19239 +
19240 native_write_cr3(native_read_cr3());
19241 }
19242
19243 static inline void __native_flush_tlb_global_irq_disabled(void)
19244 {
19245 - unsigned long cr4;
19246 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19247 + u64 descriptor[2];
19248
19249 - cr4 = native_read_cr4();
19250 - /* clear PGE */
19251 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19252 - /* write old PGE again and flush TLBs */
19253 - native_write_cr4(cr4);
19254 + descriptor[0] = PCID_KERNEL;
19255 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19256 + } else {
19257 + unsigned long cr4;
19258 +
19259 + cr4 = native_read_cr4();
19260 + /* clear PGE */
19261 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19262 + /* write old PGE again and flush TLBs */
19263 + native_write_cr4(cr4);
19264 + }
19265 }
19266
19267 static inline void __native_flush_tlb_global(void)
19268 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19269
19270 static inline void __native_flush_tlb_single(unsigned long addr)
19271 {
19272 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19273 + u64 descriptor[2];
19274 +
19275 + descriptor[0] = PCID_KERNEL;
19276 + descriptor[1] = addr;
19277 +
19278 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19279 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19280 + if (addr < TASK_SIZE_MAX)
19281 + descriptor[1] += pax_user_shadow_base;
19282 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19283 + }
19284 +
19285 + descriptor[0] = PCID_USER;
19286 + descriptor[1] = addr;
19287 +#endif
19288 +
19289 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19290 + return;
19291 + }
19292 +
19293 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19294 + if (static_cpu_has(X86_FEATURE_PCID)) {
19295 + unsigned int cpu = raw_get_cpu();
19296 +
19297 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19298 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19299 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19300 + raw_put_cpu_no_resched();
19301 +
19302 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19303 + addr += pax_user_shadow_base;
19304 + }
19305 +#endif
19306 +
19307 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19308 }
19309
19310 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19311 index 8ec57c0..451bcfc 100644
19312 --- a/arch/x86/include/asm/uaccess.h
19313 +++ b/arch/x86/include/asm/uaccess.h
19314 @@ -7,6 +7,7 @@
19315 #include <linux/compiler.h>
19316 #include <linux/thread_info.h>
19317 #include <linux/string.h>
19318 +#include <linux/spinlock.h>
19319 #include <asm/asm.h>
19320 #include <asm/page.h>
19321 #include <asm/smap.h>
19322 @@ -29,7 +30,12 @@
19323
19324 #define get_ds() (KERNEL_DS)
19325 #define get_fs() (current_thread_info()->addr_limit)
19326 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19327 +void __set_fs(mm_segment_t x);
19328 +void set_fs(mm_segment_t x);
19329 +#else
19330 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19331 +#endif
19332
19333 #define segment_eq(a, b) ((a).seg == (b).seg)
19334
19335 @@ -77,8 +83,34 @@
19336 * checks that the pointer is in the user space range - after calling
19337 * this function, memory access functions may still return -EFAULT.
19338 */
19339 -#define access_ok(type, addr, size) \
19340 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19341 +extern int _cond_resched(void);
19342 +#define access_ok_noprefault(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19343 +#define access_ok(type, addr, size) \
19344 +({ \
19345 + long __size = size; \
19346 + unsigned long __addr = (unsigned long)addr; \
19347 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19348 + unsigned long __end_ao = __addr + __size - 1; \
19349 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19350 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19351 + while(__addr_ao <= __end_ao) { \
19352 + char __c_ao; \
19353 + __addr_ao += PAGE_SIZE; \
19354 + if (__size > PAGE_SIZE) \
19355 + _cond_resched(); \
19356 + if (__get_user(__c_ao, (char __user *)__addr)) \
19357 + break; \
19358 + if (type != VERIFY_WRITE) { \
19359 + __addr = __addr_ao; \
19360 + continue; \
19361 + } \
19362 + if (__put_user(__c_ao, (char __user *)__addr)) \
19363 + break; \
19364 + __addr = __addr_ao; \
19365 + } \
19366 + } \
19367 + __ret_ao; \
19368 +})
19369
19370 /*
19371 * The exception table consists of pairs of addresses relative to the
19372 @@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19373 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19374 __chk_user_ptr(ptr); \
19375 might_fault(); \
19376 + pax_open_userland(); \
19377 asm volatile("call __get_user_%P3" \
19378 : "=a" (__ret_gu), "=r" (__val_gu) \
19379 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19380 (x) = (__typeof__(*(ptr))) __val_gu; \
19381 + pax_close_userland(); \
19382 __ret_gu; \
19383 })
19384
19385 @@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19386 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19387 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19388
19389 -
19390 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19391 +#define __copyuser_seg "gs;"
19392 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19393 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19394 +#else
19395 +#define __copyuser_seg
19396 +#define __COPYUSER_SET_ES
19397 +#define __COPYUSER_RESTORE_ES
19398 +#endif
19399
19400 #ifdef CONFIG_X86_32
19401 #define __put_user_asm_u64(x, addr, err, errret) \
19402 asm volatile(ASM_STAC "\n" \
19403 - "1: movl %%eax,0(%2)\n" \
19404 - "2: movl %%edx,4(%2)\n" \
19405 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19406 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19407 "3: " ASM_CLAC "\n" \
19408 ".section .fixup,\"ax\"\n" \
19409 "4: movl %3,%0\n" \
19410 @@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19411
19412 #define __put_user_asm_ex_u64(x, addr) \
19413 asm volatile(ASM_STAC "\n" \
19414 - "1: movl %%eax,0(%1)\n" \
19415 - "2: movl %%edx,4(%1)\n" \
19416 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19417 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19418 "3: " ASM_CLAC "\n" \
19419 _ASM_EXTABLE_EX(1b, 2b) \
19420 _ASM_EXTABLE_EX(2b, 3b) \
19421 @@ -249,7 +291,8 @@ extern void __put_user_8(void);
19422 __typeof__(*(ptr)) __pu_val; \
19423 __chk_user_ptr(ptr); \
19424 might_fault(); \
19425 - __pu_val = x; \
19426 + __pu_val = (x); \
19427 + pax_open_userland(); \
19428 switch (sizeof(*(ptr))) { \
19429 case 1: \
19430 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19431 @@ -267,6 +310,7 @@ extern void __put_user_8(void);
19432 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19433 break; \
19434 } \
19435 + pax_close_userland(); \
19436 __ret_pu; \
19437 })
19438
19439 @@ -347,8 +391,10 @@ do { \
19440 } while (0)
19441
19442 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19443 +do { \
19444 + pax_open_userland(); \
19445 asm volatile(ASM_STAC "\n" \
19446 - "1: mov"itype" %2,%"rtype"1\n" \
19447 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19448 "2: " ASM_CLAC "\n" \
19449 ".section .fixup,\"ax\"\n" \
19450 "3: mov %3,%0\n" \
19451 @@ -356,8 +402,10 @@ do { \
19452 " jmp 2b\n" \
19453 ".previous\n" \
19454 _ASM_EXTABLE(1b, 3b) \
19455 - : "=r" (err), ltype(x) \
19456 - : "m" (__m(addr)), "i" (errret), "0" (err))
19457 + : "=r" (err), ltype (x) \
19458 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19459 + pax_close_userland(); \
19460 +} while (0)
19461
19462 #define __get_user_size_ex(x, ptr, size) \
19463 do { \
19464 @@ -381,7 +429,7 @@ do { \
19465 } while (0)
19466
19467 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19468 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19469 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19470 "2:\n" \
19471 _ASM_EXTABLE_EX(1b, 2b) \
19472 : ltype(x) : "m" (__m(addr)))
19473 @@ -398,13 +446,24 @@ do { \
19474 int __gu_err; \
19475 unsigned long __gu_val; \
19476 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19477 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19478 + (x) = (__typeof__(*(ptr)))__gu_val; \
19479 __gu_err; \
19480 })
19481
19482 /* FIXME: this hack is definitely wrong -AK */
19483 struct __large_struct { unsigned long buf[100]; };
19484 -#define __m(x) (*(struct __large_struct __user *)(x))
19485 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19486 +#define ____m(x) \
19487 +({ \
19488 + unsigned long ____x = (unsigned long)(x); \
19489 + if (____x < pax_user_shadow_base) \
19490 + ____x += pax_user_shadow_base; \
19491 + (typeof(x))____x; \
19492 +})
19493 +#else
19494 +#define ____m(x) (x)
19495 +#endif
19496 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19497
19498 /*
19499 * Tell gcc we read from memory instead of writing: this is because
19500 @@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
19501 * aliasing issues.
19502 */
19503 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19504 +do { \
19505 + pax_open_userland(); \
19506 asm volatile(ASM_STAC "\n" \
19507 - "1: mov"itype" %"rtype"1,%2\n" \
19508 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19509 "2: " ASM_CLAC "\n" \
19510 ".section .fixup,\"ax\"\n" \
19511 "3: mov %3,%0\n" \
19512 @@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
19513 ".previous\n" \
19514 _ASM_EXTABLE(1b, 3b) \
19515 : "=r"(err) \
19516 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19517 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19518 + pax_close_userland(); \
19519 +} while (0)
19520
19521 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19522 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19523 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19524 "2:\n" \
19525 _ASM_EXTABLE_EX(1b, 2b) \
19526 : : ltype(x), "m" (__m(addr)))
19527 @@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
19528 */
19529 #define uaccess_try do { \
19530 current_thread_info()->uaccess_err = 0; \
19531 + pax_open_userland(); \
19532 stac(); \
19533 barrier();
19534
19535 #define uaccess_catch(err) \
19536 clac(); \
19537 + pax_close_userland(); \
19538 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19539 } while (0)
19540
19541 @@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
19542 * On error, the variable @x is set to zero.
19543 */
19544
19545 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19546 +#define __get_user(x, ptr) get_user((x), (ptr))
19547 +#else
19548 #define __get_user(x, ptr) \
19549 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19550 +#endif
19551
19552 /**
19553 * __put_user: - Write a simple value into user space, with less checking.
19554 @@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
19555 * Returns zero on success, or -EFAULT on error.
19556 */
19557
19558 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19559 +#define __put_user(x, ptr) put_user((x), (ptr))
19560 +#else
19561 #define __put_user(x, ptr) \
19562 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19563 +#endif
19564
19565 #define __get_user_unaligned __get_user
19566 #define __put_user_unaligned __put_user
19567 @@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19568 #define get_user_ex(x, ptr) do { \
19569 unsigned long __gue_val; \
19570 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19571 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19572 + (x) = (__typeof__(*(ptr)))__gue_val; \
19573 } while (0)
19574
19575 #define put_user_try uaccess_try
19576 @@ -536,17 +609,6 @@ extern struct movsl_mask {
19577
19578 #define ARCH_HAS_NOCACHE_UACCESS 1
19579
19580 -#ifdef CONFIG_X86_32
19581 -# include <asm/uaccess_32.h>
19582 -#else
19583 -# include <asm/uaccess_64.h>
19584 -#endif
19585 -
19586 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19587 - unsigned n);
19588 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19589 - unsigned n);
19590 -
19591 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19592 # define copy_user_diag __compiletime_error
19593 #else
19594 @@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19595 extern void copy_user_diag("copy_from_user() buffer size is too small")
19596 copy_from_user_overflow(void);
19597 extern void copy_user_diag("copy_to_user() buffer size is too small")
19598 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19599 +copy_to_user_overflow(void);
19600
19601 #undef copy_user_diag
19602
19603 @@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19604
19605 extern void
19606 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19607 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19608 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19609 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19610
19611 #else
19612 @@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19613
19614 #endif
19615
19616 +#ifdef CONFIG_X86_32
19617 +# include <asm/uaccess_32.h>
19618 +#else
19619 +# include <asm/uaccess_64.h>
19620 +#endif
19621 +
19622 static inline unsigned long __must_check
19623 copy_from_user(void *to, const void __user *from, unsigned long n)
19624 {
19625 - int sz = __compiletime_object_size(to);
19626 + size_t sz = __compiletime_object_size(to);
19627
19628 might_fault();
19629
19630 @@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19631 * case, and do only runtime checking for non-constant sizes.
19632 */
19633
19634 - if (likely(sz < 0 || sz >= n))
19635 - n = _copy_from_user(to, from, n);
19636 - else if(__builtin_constant_p(n))
19637 - copy_from_user_overflow();
19638 - else
19639 - __copy_from_user_overflow(sz, n);
19640 + if (likely(sz != (size_t)-1 && sz < n)) {
19641 + if(__builtin_constant_p(n))
19642 + copy_from_user_overflow();
19643 + else
19644 + __copy_from_user_overflow(sz, n);
19645 + } if (access_ok(VERIFY_READ, from, n))
19646 + n = __copy_from_user(to, from, n);
19647 + else if ((long)n > 0)
19648 + memset(to, 0, n);
19649
19650 return n;
19651 }
19652 @@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19653 static inline unsigned long __must_check
19654 copy_to_user(void __user *to, const void *from, unsigned long n)
19655 {
19656 - int sz = __compiletime_object_size(from);
19657 + size_t sz = __compiletime_object_size(from);
19658
19659 might_fault();
19660
19661 /* See the comment in copy_from_user() above. */
19662 - if (likely(sz < 0 || sz >= n))
19663 - n = _copy_to_user(to, from, n);
19664 - else if(__builtin_constant_p(n))
19665 - copy_to_user_overflow();
19666 - else
19667 - __copy_to_user_overflow(sz, n);
19668 + if (likely(sz != (size_t)-1 && sz < n)) {
19669 + if(__builtin_constant_p(n))
19670 + copy_to_user_overflow();
19671 + else
19672 + __copy_to_user_overflow(sz, n);
19673 + } else if (access_ok(VERIFY_WRITE, to, n))
19674 + n = __copy_to_user(to, from, n);
19675
19676 return n;
19677 }
19678 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19679 index 3c03a5d..1071638 100644
19680 --- a/arch/x86/include/asm/uaccess_32.h
19681 +++ b/arch/x86/include/asm/uaccess_32.h
19682 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19683 static __always_inline unsigned long __must_check
19684 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19685 {
19686 + if ((long)n < 0)
19687 + return n;
19688 +
19689 + check_object_size(from, n, true);
19690 +
19691 if (__builtin_constant_p(n)) {
19692 unsigned long ret;
19693
19694 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19695 __copy_to_user(void __user *to, const void *from, unsigned long n)
19696 {
19697 might_fault();
19698 +
19699 return __copy_to_user_inatomic(to, from, n);
19700 }
19701
19702 static __always_inline unsigned long
19703 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19704 {
19705 + if ((long)n < 0)
19706 + return n;
19707 +
19708 /* Avoid zeroing the tail if the copy fails..
19709 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19710 * but as the zeroing behaviour is only significant when n is not
19711 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19712 __copy_from_user(void *to, const void __user *from, unsigned long n)
19713 {
19714 might_fault();
19715 +
19716 + if ((long)n < 0)
19717 + return n;
19718 +
19719 + check_object_size(to, n, false);
19720 +
19721 if (__builtin_constant_p(n)) {
19722 unsigned long ret;
19723
19724 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19725 const void __user *from, unsigned long n)
19726 {
19727 might_fault();
19728 +
19729 + if ((long)n < 0)
19730 + return n;
19731 +
19732 if (__builtin_constant_p(n)) {
19733 unsigned long ret;
19734
19735 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19736 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19737 unsigned long n)
19738 {
19739 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19740 + if ((long)n < 0)
19741 + return n;
19742 +
19743 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19744 }
19745
19746 #endif /* _ASM_X86_UACCESS_32_H */
19747 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19748 index 190413d..206c200 100644
19749 --- a/arch/x86/include/asm/uaccess_64.h
19750 +++ b/arch/x86/include/asm/uaccess_64.h
19751 @@ -10,6 +10,9 @@
19752 #include <asm/alternative.h>
19753 #include <asm/cpufeature.h>
19754 #include <asm/page.h>
19755 +#include <asm/pgtable.h>
19756 +
19757 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19758
19759 /*
19760 * Copy To/From Userspace
19761 @@ -17,14 +20,14 @@
19762
19763 /* Handles exceptions in both to and from, but doesn't do access_ok */
19764 __must_check unsigned long
19765 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19766 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19767 __must_check unsigned long
19768 -copy_user_generic_string(void *to, const void *from, unsigned len);
19769 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19770 __must_check unsigned long
19771 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19772 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19773
19774 static __always_inline __must_check unsigned long
19775 -copy_user_generic(void *to, const void *from, unsigned len)
19776 +copy_user_generic(void *to, const void *from, unsigned long len)
19777 {
19778 unsigned ret;
19779
19780 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19781 }
19782
19783 __must_check unsigned long
19784 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19785 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19786
19787 static __always_inline __must_check
19788 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19789 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19790 {
19791 - int ret = 0;
19792 + size_t sz = __compiletime_object_size(dst);
19793 + unsigned ret = 0;
19794 +
19795 + if (size > INT_MAX)
19796 + return size;
19797 +
19798 + check_object_size(dst, size, false);
19799 +
19800 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19801 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19802 + return size;
19803 +#endif
19804 +
19805 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19806 + if(__builtin_constant_p(size))
19807 + copy_from_user_overflow();
19808 + else
19809 + __copy_from_user_overflow(sz, size);
19810 + return size;
19811 + }
19812
19813 if (!__builtin_constant_p(size))
19814 - return copy_user_generic(dst, (__force void *)src, size);
19815 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19816 switch (size) {
19817 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19818 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19819 ret, "b", "b", "=q", 1);
19820 return ret;
19821 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19822 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19823 ret, "w", "w", "=r", 2);
19824 return ret;
19825 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19826 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19827 ret, "l", "k", "=r", 4);
19828 return ret;
19829 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19830 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19831 ret, "q", "", "=r", 8);
19832 return ret;
19833 case 10:
19834 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19835 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19836 ret, "q", "", "=r", 10);
19837 if (unlikely(ret))
19838 return ret;
19839 __get_user_asm(*(u16 *)(8 + (char *)dst),
19840 - (u16 __user *)(8 + (char __user *)src),
19841 + (const u16 __user *)(8 + (const char __user *)src),
19842 ret, "w", "w", "=r", 2);
19843 return ret;
19844 case 16:
19845 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19846 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19847 ret, "q", "", "=r", 16);
19848 if (unlikely(ret))
19849 return ret;
19850 __get_user_asm(*(u64 *)(8 + (char *)dst),
19851 - (u64 __user *)(8 + (char __user *)src),
19852 + (const u64 __user *)(8 + (const char __user *)src),
19853 ret, "q", "", "=r", 8);
19854 return ret;
19855 default:
19856 - return copy_user_generic(dst, (__force void *)src, size);
19857 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19858 }
19859 }
19860
19861 static __always_inline __must_check
19862 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19863 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19864 {
19865 might_fault();
19866 return __copy_from_user_nocheck(dst, src, size);
19867 }
19868
19869 static __always_inline __must_check
19870 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19871 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19872 {
19873 - int ret = 0;
19874 + size_t sz = __compiletime_object_size(src);
19875 + unsigned ret = 0;
19876 +
19877 + if (size > INT_MAX)
19878 + return size;
19879 +
19880 + check_object_size(src, size, true);
19881 +
19882 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19883 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19884 + return size;
19885 +#endif
19886 +
19887 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19888 + if(__builtin_constant_p(size))
19889 + copy_to_user_overflow();
19890 + else
19891 + __copy_to_user_overflow(sz, size);
19892 + return size;
19893 + }
19894
19895 if (!__builtin_constant_p(size))
19896 - return copy_user_generic((__force void *)dst, src, size);
19897 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19898 switch (size) {
19899 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19900 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19901 ret, "b", "b", "iq", 1);
19902 return ret;
19903 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19904 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19905 ret, "w", "w", "ir", 2);
19906 return ret;
19907 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19908 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19909 ret, "l", "k", "ir", 4);
19910 return ret;
19911 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19912 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19913 ret, "q", "", "er", 8);
19914 return ret;
19915 case 10:
19916 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19917 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19918 ret, "q", "", "er", 10);
19919 if (unlikely(ret))
19920 return ret;
19921 asm("":::"memory");
19922 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19923 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19924 ret, "w", "w", "ir", 2);
19925 return ret;
19926 case 16:
19927 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19928 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19929 ret, "q", "", "er", 16);
19930 if (unlikely(ret))
19931 return ret;
19932 asm("":::"memory");
19933 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19934 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19935 ret, "q", "", "er", 8);
19936 return ret;
19937 default:
19938 - return copy_user_generic((__force void *)dst, src, size);
19939 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19940 }
19941 }
19942
19943 static __always_inline __must_check
19944 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
19945 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19946 {
19947 might_fault();
19948 return __copy_to_user_nocheck(dst, src, size);
19949 }
19950
19951 static __always_inline __must_check
19952 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19953 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19954 {
19955 - int ret = 0;
19956 + unsigned ret = 0;
19957
19958 might_fault();
19959 +
19960 + if (size > INT_MAX)
19961 + return size;
19962 +
19963 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19964 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19965 + return size;
19966 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19967 + return size;
19968 +#endif
19969 +
19970 if (!__builtin_constant_p(size))
19971 - return copy_user_generic((__force void *)dst,
19972 - (__force void *)src, size);
19973 + return copy_user_generic((__force_kernel void *)____m(dst),
19974 + (__force_kernel const void *)____m(src), size);
19975 switch (size) {
19976 case 1: {
19977 u8 tmp;
19978 - __get_user_asm(tmp, (u8 __user *)src,
19979 + __get_user_asm(tmp, (const u8 __user *)src,
19980 ret, "b", "b", "=q", 1);
19981 if (likely(!ret))
19982 __put_user_asm(tmp, (u8 __user *)dst,
19983 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19984 }
19985 case 2: {
19986 u16 tmp;
19987 - __get_user_asm(tmp, (u16 __user *)src,
19988 + __get_user_asm(tmp, (const u16 __user *)src,
19989 ret, "w", "w", "=r", 2);
19990 if (likely(!ret))
19991 __put_user_asm(tmp, (u16 __user *)dst,
19992 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19993
19994 case 4: {
19995 u32 tmp;
19996 - __get_user_asm(tmp, (u32 __user *)src,
19997 + __get_user_asm(tmp, (const u32 __user *)src,
19998 ret, "l", "k", "=r", 4);
19999 if (likely(!ret))
20000 __put_user_asm(tmp, (u32 __user *)dst,
20001 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20002 }
20003 case 8: {
20004 u64 tmp;
20005 - __get_user_asm(tmp, (u64 __user *)src,
20006 + __get_user_asm(tmp, (const u64 __user *)src,
20007 ret, "q", "", "=r", 8);
20008 if (likely(!ret))
20009 __put_user_asm(tmp, (u64 __user *)dst,
20010 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20011 return ret;
20012 }
20013 default:
20014 - return copy_user_generic((__force void *)dst,
20015 - (__force void *)src, size);
20016 + return copy_user_generic((__force_kernel void *)____m(dst),
20017 + (__force_kernel const void *)____m(src), size);
20018 }
20019 }
20020
20021 -static __must_check __always_inline int
20022 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20023 +static __must_check __always_inline unsigned long
20024 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20025 {
20026 - return __copy_from_user_nocheck(dst, (__force const void *)src, size);
20027 + return __copy_from_user_nocheck(dst, src, size);
20028 }
20029
20030 -static __must_check __always_inline int
20031 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20032 +static __must_check __always_inline unsigned long
20033 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20034 {
20035 - return __copy_to_user_nocheck((__force void *)dst, src, size);
20036 + return __copy_to_user_nocheck(dst, src, size);
20037 }
20038
20039 -extern long __copy_user_nocache(void *dst, const void __user *src,
20040 - unsigned size, int zerorest);
20041 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20042 + unsigned long size, int zerorest);
20043
20044 -static inline int
20045 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20046 +static inline unsigned long
20047 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20048 {
20049 might_fault();
20050 +
20051 + if (size > INT_MAX)
20052 + return size;
20053 +
20054 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20055 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20056 + return size;
20057 +#endif
20058 +
20059 return __copy_user_nocache(dst, src, size, 1);
20060 }
20061
20062 -static inline int
20063 +static inline unsigned long
20064 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20065 - unsigned size)
20066 + unsigned long size)
20067 {
20068 + if (size > INT_MAX)
20069 + return size;
20070 +
20071 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20072 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20073 + return size;
20074 +#endif
20075 +
20076 return __copy_user_nocache(dst, src, size, 0);
20077 }
20078
20079 unsigned long
20080 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20081 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20082
20083 #endif /* _ASM_X86_UACCESS_64_H */
20084 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20085 index 5b238981..77fdd78 100644
20086 --- a/arch/x86/include/asm/word-at-a-time.h
20087 +++ b/arch/x86/include/asm/word-at-a-time.h
20088 @@ -11,7 +11,7 @@
20089 * and shift, for example.
20090 */
20091 struct word_at_a_time {
20092 - const unsigned long one_bits, high_bits;
20093 + unsigned long one_bits, high_bits;
20094 };
20095
20096 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20097 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20098 index 0f1be11..f7542bf 100644
20099 --- a/arch/x86/include/asm/x86_init.h
20100 +++ b/arch/x86/include/asm/x86_init.h
20101 @@ -129,7 +129,7 @@ struct x86_init_ops {
20102 struct x86_init_timers timers;
20103 struct x86_init_iommu iommu;
20104 struct x86_init_pci pci;
20105 -};
20106 +} __no_const;
20107
20108 /**
20109 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20110 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20111 void (*setup_percpu_clockev)(void);
20112 void (*early_percpu_clock_init)(void);
20113 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20114 -};
20115 +} __no_const;
20116
20117 struct timespec;
20118
20119 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20120 void (*save_sched_clock_state)(void);
20121 void (*restore_sched_clock_state)(void);
20122 void (*apic_post_init)(void);
20123 -};
20124 +} __no_const;
20125
20126 struct pci_dev;
20127 struct msi_msg;
20128 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20129 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20130 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20131 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20132 -};
20133 +} __no_const;
20134
20135 struct IO_APIC_route_entry;
20136 struct io_apic_irq_attr;
20137 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20138 unsigned int destination, int vector,
20139 struct io_apic_irq_attr *attr);
20140 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20141 -};
20142 +} __no_const;
20143
20144 extern struct x86_init_ops x86_init;
20145 extern struct x86_cpuinit_ops x86_cpuinit;
20146 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20147 index b913915..4f5a581 100644
20148 --- a/arch/x86/include/asm/xen/page.h
20149 +++ b/arch/x86/include/asm/xen/page.h
20150 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20151 extern struct page *m2p_find_override(unsigned long mfn);
20152 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20153
20154 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20155 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20156 {
20157 unsigned long mfn;
20158
20159 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20160 index 0415cda..3b22adc 100644
20161 --- a/arch/x86/include/asm/xsave.h
20162 +++ b/arch/x86/include/asm/xsave.h
20163 @@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20164 if (unlikely(err))
20165 return -EFAULT;
20166
20167 + pax_open_userland();
20168 __asm__ __volatile__(ASM_STAC "\n"
20169 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20170 + "1:"
20171 + __copyuser_seg
20172 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20173 "2: " ASM_CLAC "\n"
20174 ".section .fixup,\"ax\"\n"
20175 "3: movl $-1,%[err]\n"
20176 @@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20177 : [err] "=r" (err)
20178 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20179 : "memory");
20180 + pax_close_userland();
20181 return err;
20182 }
20183
20184 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20185 {
20186 int err;
20187 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20188 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20189 u32 lmask = mask;
20190 u32 hmask = mask >> 32;
20191
20192 + pax_open_userland();
20193 __asm__ __volatile__(ASM_STAC "\n"
20194 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20195 + "1:"
20196 + __copyuser_seg
20197 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20198 "2: " ASM_CLAC "\n"
20199 ".section .fixup,\"ax\"\n"
20200 "3: movl $-1,%[err]\n"
20201 @@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20202 : [err] "=r" (err)
20203 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20204 : "memory"); /* memory required? */
20205 + pax_close_userland();
20206 return err;
20207 }
20208
20209 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20210 index bbae024..e1528f9 100644
20211 --- a/arch/x86/include/uapi/asm/e820.h
20212 +++ b/arch/x86/include/uapi/asm/e820.h
20213 @@ -63,7 +63,7 @@ struct e820map {
20214 #define ISA_START_ADDRESS 0xa0000
20215 #define ISA_END_ADDRESS 0x100000
20216
20217 -#define BIOS_BEGIN 0x000a0000
20218 +#define BIOS_BEGIN 0x000c0000
20219 #define BIOS_END 0x00100000
20220
20221 #define BIOS_ROM_BASE 0xffe00000
20222 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20223 index 7b0a55a..ad115bf 100644
20224 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20225 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20226 @@ -49,7 +49,6 @@
20227 #define EFLAGS 144
20228 #define RSP 152
20229 #define SS 160
20230 -#define ARGOFFSET R11
20231 #endif /* __ASSEMBLY__ */
20232
20233 /* top of stack page */
20234 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20235 index 9b0a34e..fc7e553 100644
20236 --- a/arch/x86/kernel/Makefile
20237 +++ b/arch/x86/kernel/Makefile
20238 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20239 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20240 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20241 obj-y += probe_roms.o
20242 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20243 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20244 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20245 obj-y += syscall_$(BITS).o
20246 obj-$(CONFIG_X86_64) += vsyscall_64.o
20247 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20248 index 6c0b43b..e67bb31 100644
20249 --- a/arch/x86/kernel/acpi/boot.c
20250 +++ b/arch/x86/kernel/acpi/boot.c
20251 @@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20252 * If your system is blacklisted here, but you find that acpi=force
20253 * works for you, please contact linux-acpi@vger.kernel.org
20254 */
20255 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20256 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20257 /*
20258 * Boxes that need ACPI disabled
20259 */
20260 @@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20261 };
20262
20263 /* second table for DMI checks that should run after early-quirks */
20264 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20265 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20266 /*
20267 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20268 * which includes some code which overrides all temperature
20269 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20270 index 3a2ae4c..9db31d6 100644
20271 --- a/arch/x86/kernel/acpi/sleep.c
20272 +++ b/arch/x86/kernel/acpi/sleep.c
20273 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20274 #else /* CONFIG_64BIT */
20275 #ifdef CONFIG_SMP
20276 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20277 +
20278 + pax_open_kernel();
20279 early_gdt_descr.address =
20280 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20281 + pax_close_kernel();
20282 +
20283 initial_gs = per_cpu_offset(smp_processor_id());
20284 #endif
20285 initial_code = (unsigned long)wakeup_long64;
20286 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20287 index 665c6b7..eae4d56 100644
20288 --- a/arch/x86/kernel/acpi/wakeup_32.S
20289 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20290 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20291 # and restore the stack ... but you need gdt for this to work
20292 movl saved_context_esp, %esp
20293
20294 - movl %cs:saved_magic, %eax
20295 - cmpl $0x12345678, %eax
20296 + cmpl $0x12345678, saved_magic
20297 jne bogus_magic
20298
20299 # jump to place where we left off
20300 - movl saved_eip, %eax
20301 - jmp *%eax
20302 + jmp *(saved_eip)
20303
20304 bogus_magic:
20305 jmp bogus_magic
20306 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20307 index df94598..f3b29bf 100644
20308 --- a/arch/x86/kernel/alternative.c
20309 +++ b/arch/x86/kernel/alternative.c
20310 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20311 */
20312 for (a = start; a < end; a++) {
20313 instr = (u8 *)&a->instr_offset + a->instr_offset;
20314 +
20315 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20316 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20317 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20318 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20319 +#endif
20320 +
20321 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20322 BUG_ON(a->replacementlen > a->instrlen);
20323 BUG_ON(a->instrlen > sizeof(insnbuf));
20324 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20325 for (poff = start; poff < end; poff++) {
20326 u8 *ptr = (u8 *)poff + *poff;
20327
20328 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20329 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20330 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20331 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20332 +#endif
20333 +
20334 if (!*poff || ptr < text || ptr >= text_end)
20335 continue;
20336 /* turn DS segment override prefix into lock prefix */
20337 - if (*ptr == 0x3e)
20338 + if (*ktla_ktva(ptr) == 0x3e)
20339 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20340 }
20341 mutex_unlock(&text_mutex);
20342 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20343 for (poff = start; poff < end; poff++) {
20344 u8 *ptr = (u8 *)poff + *poff;
20345
20346 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20347 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20348 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20349 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20350 +#endif
20351 +
20352 if (!*poff || ptr < text || ptr >= text_end)
20353 continue;
20354 /* turn lock prefix into DS segment override prefix */
20355 - if (*ptr == 0xf0)
20356 + if (*ktla_ktva(ptr) == 0xf0)
20357 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20358 }
20359 mutex_unlock(&text_mutex);
20360 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20361
20362 BUG_ON(p->len > MAX_PATCH_LEN);
20363 /* prep the buffer with the original instructions */
20364 - memcpy(insnbuf, p->instr, p->len);
20365 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20366 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20367 (unsigned long)p->instr, p->len);
20368
20369 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20370 if (!uniproc_patched || num_possible_cpus() == 1)
20371 free_init_pages("SMP alternatives",
20372 (unsigned long)__smp_locks,
20373 - (unsigned long)__smp_locks_end);
20374 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20375 #endif
20376
20377 apply_paravirt(__parainstructions, __parainstructions_end);
20378 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20379 * instructions. And on the local CPU you need to be protected again NMI or MCE
20380 * handlers seeing an inconsistent instruction while you patch.
20381 */
20382 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20383 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20384 size_t len)
20385 {
20386 unsigned long flags;
20387 local_irq_save(flags);
20388 - memcpy(addr, opcode, len);
20389 +
20390 + pax_open_kernel();
20391 + memcpy(ktla_ktva(addr), opcode, len);
20392 sync_core();
20393 + pax_close_kernel();
20394 +
20395 local_irq_restore(flags);
20396 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20397 that causes hangs on some VIA CPUs. */
20398 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20399 */
20400 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20401 {
20402 - unsigned long flags;
20403 - char *vaddr;
20404 + unsigned char *vaddr = ktla_ktva(addr);
20405 struct page *pages[2];
20406 - int i;
20407 + size_t i;
20408
20409 if (!core_kernel_text((unsigned long)addr)) {
20410 - pages[0] = vmalloc_to_page(addr);
20411 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20412 + pages[0] = vmalloc_to_page(vaddr);
20413 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20414 } else {
20415 - pages[0] = virt_to_page(addr);
20416 + pages[0] = virt_to_page(vaddr);
20417 WARN_ON(!PageReserved(pages[0]));
20418 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20419 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20420 }
20421 BUG_ON(!pages[0]);
20422 - local_irq_save(flags);
20423 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20424 - if (pages[1])
20425 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20426 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20427 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20428 - clear_fixmap(FIX_TEXT_POKE0);
20429 - if (pages[1])
20430 - clear_fixmap(FIX_TEXT_POKE1);
20431 - local_flush_tlb();
20432 - sync_core();
20433 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20434 - that causes hangs on some VIA CPUs. */
20435 + text_poke_early(addr, opcode, len);
20436 for (i = 0; i < len; i++)
20437 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20438 - local_irq_restore(flags);
20439 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20440 return addr;
20441 }
20442
20443 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20444 if (likely(!bp_patching_in_progress))
20445 return 0;
20446
20447 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20448 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20449 return 0;
20450
20451 /* set up the specified breakpoint handler */
20452 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20453 */
20454 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20455 {
20456 - unsigned char int3 = 0xcc;
20457 + const unsigned char int3 = 0xcc;
20458
20459 bp_int3_handler = handler;
20460 bp_int3_addr = (u8 *)addr + sizeof(int3);
20461 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20462 index d278736..0b4af9a8 100644
20463 --- a/arch/x86/kernel/apic/apic.c
20464 +++ b/arch/x86/kernel/apic/apic.c
20465 @@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
20466 /*
20467 * Debug level, exported for io_apic.c
20468 */
20469 -unsigned int apic_verbosity;
20470 +int apic_verbosity;
20471
20472 int pic_mode;
20473
20474 @@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20475 apic_write(APIC_ESR, 0);
20476 v1 = apic_read(APIC_ESR);
20477 ack_APIC_irq();
20478 - atomic_inc(&irq_err_count);
20479 + atomic_inc_unchecked(&irq_err_count);
20480
20481 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
20482 smp_processor_id(), v0 , v1);
20483 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20484 index 00c77cf..2dc6a2d 100644
20485 --- a/arch/x86/kernel/apic/apic_flat_64.c
20486 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20487 @@ -157,7 +157,7 @@ static int flat_probe(void)
20488 return 1;
20489 }
20490
20491 -static struct apic apic_flat = {
20492 +static struct apic apic_flat __read_only = {
20493 .name = "flat",
20494 .probe = flat_probe,
20495 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20496 @@ -271,7 +271,7 @@ static int physflat_probe(void)
20497 return 0;
20498 }
20499
20500 -static struct apic apic_physflat = {
20501 +static struct apic apic_physflat __read_only = {
20502
20503 .name = "physical flat",
20504 .probe = physflat_probe,
20505 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20506 index e145f28..2752888 100644
20507 --- a/arch/x86/kernel/apic/apic_noop.c
20508 +++ b/arch/x86/kernel/apic/apic_noop.c
20509 @@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
20510 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20511 }
20512
20513 -struct apic apic_noop = {
20514 +struct apic apic_noop __read_only = {
20515 .name = "noop",
20516 .probe = noop_probe,
20517 .acpi_madt_oem_check = NULL,
20518 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20519 index d50e364..543bee3 100644
20520 --- a/arch/x86/kernel/apic/bigsmp_32.c
20521 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20522 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20523 return dmi_bigsmp;
20524 }
20525
20526 -static struct apic apic_bigsmp = {
20527 +static struct apic apic_bigsmp __read_only = {
20528
20529 .name = "bigsmp",
20530 .probe = probe_bigsmp,
20531 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20532 index c552247..587a316 100644
20533 --- a/arch/x86/kernel/apic/es7000_32.c
20534 +++ b/arch/x86/kernel/apic/es7000_32.c
20535 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20536 return ret && es7000_apic_is_cluster();
20537 }
20538
20539 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20540 -static struct apic __refdata apic_es7000_cluster = {
20541 +static struct apic apic_es7000_cluster __read_only = {
20542
20543 .name = "es7000",
20544 .probe = probe_es7000,
20545 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20546 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20547 };
20548
20549 -static struct apic __refdata apic_es7000 = {
20550 +static struct apic apic_es7000 __read_only = {
20551
20552 .name = "es7000",
20553 .probe = probe_es7000,
20554 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20555 index e63a5bd..c0babf8 100644
20556 --- a/arch/x86/kernel/apic/io_apic.c
20557 +++ b/arch/x86/kernel/apic/io_apic.c
20558 @@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20559 }
20560 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20561
20562 -void lock_vector_lock(void)
20563 +void lock_vector_lock(void) __acquires(vector_lock)
20564 {
20565 /* Used to the online set of cpus does not change
20566 * during assign_irq_vector.
20567 @@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20568 raw_spin_lock(&vector_lock);
20569 }
20570
20571 -void unlock_vector_lock(void)
20572 +void unlock_vector_lock(void) __releases(vector_lock)
20573 {
20574 raw_spin_unlock(&vector_lock);
20575 }
20576 @@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20577 ack_APIC_irq();
20578 }
20579
20580 -atomic_t irq_mis_count;
20581 +atomic_unchecked_t irq_mis_count;
20582
20583 #ifdef CONFIG_GENERIC_PENDING_IRQ
20584 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20585 @@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20586 * at the cpu.
20587 */
20588 if (!(v & (1 << (i & 0x1f)))) {
20589 - atomic_inc(&irq_mis_count);
20590 + atomic_inc_unchecked(&irq_mis_count);
20591
20592 eoi_ioapic_irq(irq, cfg);
20593 }
20594 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20595 index 1e42e8f..daacf44 100644
20596 --- a/arch/x86/kernel/apic/numaq_32.c
20597 +++ b/arch/x86/kernel/apic/numaq_32.c
20598 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20599 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20600 }
20601
20602 -/* Use __refdata to keep false positive warning calm. */
20603 -static struct apic __refdata apic_numaq = {
20604 +static struct apic apic_numaq __read_only = {
20605
20606 .name = "NUMAQ",
20607 .probe = probe_numaq,
20608 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20609 index eb35ef9..f184a21 100644
20610 --- a/arch/x86/kernel/apic/probe_32.c
20611 +++ b/arch/x86/kernel/apic/probe_32.c
20612 @@ -72,7 +72,7 @@ static int probe_default(void)
20613 return 1;
20614 }
20615
20616 -static struct apic apic_default = {
20617 +static struct apic apic_default __read_only = {
20618
20619 .name = "default",
20620 .probe = probe_default,
20621 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20622 index 77c95c0..434f8a4 100644
20623 --- a/arch/x86/kernel/apic/summit_32.c
20624 +++ b/arch/x86/kernel/apic/summit_32.c
20625 @@ -486,7 +486,7 @@ void setup_summit(void)
20626 }
20627 #endif
20628
20629 -static struct apic apic_summit = {
20630 +static struct apic apic_summit __read_only = {
20631
20632 .name = "summit",
20633 .probe = probe_summit,
20634 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20635 index 140e29d..d88bc95 100644
20636 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20637 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20638 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20639 return notifier_from_errno(err);
20640 }
20641
20642 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20643 +static struct notifier_block x2apic_cpu_notifier = {
20644 .notifier_call = update_clusterinfo,
20645 };
20646
20647 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20648 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20649 }
20650
20651 -static struct apic apic_x2apic_cluster = {
20652 +static struct apic apic_x2apic_cluster __read_only = {
20653
20654 .name = "cluster x2apic",
20655 .probe = x2apic_cluster_probe,
20656 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20657 index 562a76d..a003c0f 100644
20658 --- a/arch/x86/kernel/apic/x2apic_phys.c
20659 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20660 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20661 return apic == &apic_x2apic_phys;
20662 }
20663
20664 -static struct apic apic_x2apic_phys = {
20665 +static struct apic apic_x2apic_phys __read_only = {
20666
20667 .name = "physical x2apic",
20668 .probe = x2apic_phys_probe,
20669 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20670 index ad0dc04..0d9cc56 100644
20671 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20672 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20673 @@ -350,7 +350,7 @@ static int uv_probe(void)
20674 return apic == &apic_x2apic_uv_x;
20675 }
20676
20677 -static struct apic __refdata apic_x2apic_uv_x = {
20678 +static struct apic apic_x2apic_uv_x __read_only = {
20679
20680 .name = "UV large system",
20681 .probe = uv_probe,
20682 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20683 index 3ab0343..814c4787 100644
20684 --- a/arch/x86/kernel/apm_32.c
20685 +++ b/arch/x86/kernel/apm_32.c
20686 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20687 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20688 * even though they are called in protected mode.
20689 */
20690 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20691 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20692 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20693
20694 static const char driver_version[] = "1.16ac"; /* no spaces */
20695 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20696 BUG_ON(cpu != 0);
20697 gdt = get_cpu_gdt_table(cpu);
20698 save_desc_40 = gdt[0x40 / 8];
20699 +
20700 + pax_open_kernel();
20701 gdt[0x40 / 8] = bad_bios_desc;
20702 + pax_close_kernel();
20703
20704 apm_irq_save(flags);
20705 APM_DO_SAVE_SEGS;
20706 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20707 &call->esi);
20708 APM_DO_RESTORE_SEGS;
20709 apm_irq_restore(flags);
20710 +
20711 + pax_open_kernel();
20712 gdt[0x40 / 8] = save_desc_40;
20713 + pax_close_kernel();
20714 +
20715 put_cpu();
20716
20717 return call->eax & 0xff;
20718 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20719 BUG_ON(cpu != 0);
20720 gdt = get_cpu_gdt_table(cpu);
20721 save_desc_40 = gdt[0x40 / 8];
20722 +
20723 + pax_open_kernel();
20724 gdt[0x40 / 8] = bad_bios_desc;
20725 + pax_close_kernel();
20726
20727 apm_irq_save(flags);
20728 APM_DO_SAVE_SEGS;
20729 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20730 &call->eax);
20731 APM_DO_RESTORE_SEGS;
20732 apm_irq_restore(flags);
20733 +
20734 + pax_open_kernel();
20735 gdt[0x40 / 8] = save_desc_40;
20736 + pax_close_kernel();
20737 +
20738 put_cpu();
20739 return error;
20740 }
20741 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20742 * code to that CPU.
20743 */
20744 gdt = get_cpu_gdt_table(0);
20745 +
20746 + pax_open_kernel();
20747 set_desc_base(&gdt[APM_CS >> 3],
20748 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20749 set_desc_base(&gdt[APM_CS_16 >> 3],
20750 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20751 set_desc_base(&gdt[APM_DS >> 3],
20752 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20753 + pax_close_kernel();
20754
20755 proc_create("apm", 0, NULL, &apm_file_ops);
20756
20757 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20758 index 9f6b934..cf5ffb3 100644
20759 --- a/arch/x86/kernel/asm-offsets.c
20760 +++ b/arch/x86/kernel/asm-offsets.c
20761 @@ -32,6 +32,8 @@ void common(void) {
20762 OFFSET(TI_flags, thread_info, flags);
20763 OFFSET(TI_status, thread_info, status);
20764 OFFSET(TI_addr_limit, thread_info, addr_limit);
20765 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20766 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20767
20768 BLANK();
20769 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20770 @@ -52,8 +54,26 @@ void common(void) {
20771 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20772 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20773 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20774 +
20775 +#ifdef CONFIG_PAX_KERNEXEC
20776 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20777 #endif
20778
20779 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20780 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20781 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20782 +#ifdef CONFIG_X86_64
20783 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20784 +#endif
20785 +#endif
20786 +
20787 +#endif
20788 +
20789 + BLANK();
20790 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20791 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20792 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20793 +
20794 #ifdef CONFIG_XEN
20795 BLANK();
20796 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20797 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20798 index e7c798b..2b2019b 100644
20799 --- a/arch/x86/kernel/asm-offsets_64.c
20800 +++ b/arch/x86/kernel/asm-offsets_64.c
20801 @@ -77,6 +77,7 @@ int main(void)
20802 BLANK();
20803 #undef ENTRY
20804
20805 + DEFINE(TSS_size, sizeof(struct tss_struct));
20806 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20807 BLANK();
20808
20809 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20810 index 47b56a7..efc2bc6 100644
20811 --- a/arch/x86/kernel/cpu/Makefile
20812 +++ b/arch/x86/kernel/cpu/Makefile
20813 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20814 CFLAGS_REMOVE_perf_event.o = -pg
20815 endif
20816
20817 -# Make sure load_percpu_segment has no stackprotector
20818 -nostackp := $(call cc-option, -fno-stack-protector)
20819 -CFLAGS_common.o := $(nostackp)
20820 -
20821 obj-y := intel_cacheinfo.o scattered.o topology.o
20822 obj-y += proc.o capflags.o powerflags.o common.o
20823 obj-y += rdrand.o
20824 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20825 index 59bfebc..d8f27bd 100644
20826 --- a/arch/x86/kernel/cpu/amd.c
20827 +++ b/arch/x86/kernel/cpu/amd.c
20828 @@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20829 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20830 {
20831 /* AMD errata T13 (order #21922) */
20832 - if ((c->x86 == 6)) {
20833 + if (c->x86 == 6) {
20834 /* Duron Rev A0 */
20835 if (c->x86_model == 3 && c->x86_mask == 0)
20836 size = 64;
20837 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20838 index fe2bdd0..77b0d1b 100644
20839 --- a/arch/x86/kernel/cpu/common.c
20840 +++ b/arch/x86/kernel/cpu/common.c
20841 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20842
20843 static const struct cpu_dev *this_cpu = &default_cpu;
20844
20845 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20846 -#ifdef CONFIG_X86_64
20847 - /*
20848 - * We need valid kernel segments for data and code in long mode too
20849 - * IRET will check the segment types kkeil 2000/10/28
20850 - * Also sysret mandates a special GDT layout
20851 - *
20852 - * TLS descriptors are currently at a different place compared to i386.
20853 - * Hopefully nobody expects them at a fixed place (Wine?)
20854 - */
20855 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20856 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20857 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20858 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20859 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20860 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20861 -#else
20862 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20863 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20864 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20865 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20866 - /*
20867 - * Segments used for calling PnP BIOS have byte granularity.
20868 - * They code segments and data segments have fixed 64k limits,
20869 - * the transfer segment sizes are set at run time.
20870 - */
20871 - /* 32-bit code */
20872 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20873 - /* 16-bit code */
20874 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20875 - /* 16-bit data */
20876 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20877 - /* 16-bit data */
20878 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20879 - /* 16-bit data */
20880 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20881 - /*
20882 - * The APM segments have byte granularity and their bases
20883 - * are set at run time. All have 64k limits.
20884 - */
20885 - /* 32-bit code */
20886 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20887 - /* 16-bit code */
20888 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20889 - /* data */
20890 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20891 -
20892 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20893 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20894 - GDT_STACK_CANARY_INIT
20895 -#endif
20896 -} };
20897 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20898 -
20899 static int __init x86_xsave_setup(char *s)
20900 {
20901 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20902 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20903 }
20904 }
20905
20906 +#ifdef CONFIG_X86_64
20907 +static __init int setup_disable_pcid(char *arg)
20908 +{
20909 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20910 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20911 +
20912 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20913 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20914 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20915 +#endif
20916 +
20917 + return 1;
20918 +}
20919 +__setup("nopcid", setup_disable_pcid);
20920 +
20921 +static void setup_pcid(struct cpuinfo_x86 *c)
20922 +{
20923 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20924 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20925 +
20926 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20927 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20928 + pax_open_kernel();
20929 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20930 + pax_close_kernel();
20931 + printk("PAX: slow and weak UDEREF enabled\n");
20932 + } else
20933 + printk("PAX: UDEREF disabled\n");
20934 +#endif
20935 +
20936 + return;
20937 + }
20938 +
20939 + printk("PAX: PCID detected\n");
20940 + set_in_cr4(X86_CR4_PCIDE);
20941 +
20942 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20943 + pax_open_kernel();
20944 + clone_pgd_mask = ~(pgdval_t)0UL;
20945 + pax_close_kernel();
20946 + if (pax_user_shadow_base)
20947 + printk("PAX: weak UDEREF enabled\n");
20948 + else {
20949 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20950 + printk("PAX: strong UDEREF enabled\n");
20951 + }
20952 +#endif
20953 +
20954 + if (cpu_has(c, X86_FEATURE_INVPCID))
20955 + printk("PAX: INVPCID detected\n");
20956 +}
20957 +#endif
20958 +
20959 /*
20960 * Some CPU features depend on higher CPUID levels, which may not always
20961 * be available due to CPUID level capping or broken virtualization
20962 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20963 {
20964 struct desc_ptr gdt_descr;
20965
20966 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20967 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20968 gdt_descr.size = GDT_SIZE - 1;
20969 load_gdt(&gdt_descr);
20970 /* Reload the per-cpu base */
20971 @@ -882,6 +881,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20972 setup_smep(c);
20973 setup_smap(c);
20974
20975 +#ifdef CONFIG_X86_64
20976 + setup_pcid(c);
20977 +#endif
20978 +
20979 /*
20980 * The vendor-specific functions might have changed features.
20981 * Now we do "generic changes."
20982 @@ -890,6 +893,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20983 /* Filter out anything that depends on CPUID levels we don't have */
20984 filter_cpuid_features(c, true);
20985
20986 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20987 + setup_clear_cpu_cap(X86_FEATURE_SEP);
20988 +#endif
20989 +
20990 /* If the model name is still unset, do table lookup. */
20991 if (!c->x86_model_id[0]) {
20992 const char *p;
20993 @@ -1077,10 +1084,12 @@ static __init int setup_disablecpuid(char *arg)
20994 }
20995 __setup("clearcpuid=", setup_disablecpuid);
20996
20997 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20998 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
20999 +
21000 #ifdef CONFIG_X86_64
21001 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21002 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21003 - (unsigned long) debug_idt_table };
21004 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21005 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21006
21007 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21008 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21009 @@ -1094,7 +1103,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21010 EXPORT_PER_CPU_SYMBOL(current_task);
21011
21012 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21013 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21014 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21015 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21016
21017 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21018 @@ -1244,7 +1253,7 @@ void cpu_init(void)
21019 load_ucode_ap();
21020
21021 cpu = stack_smp_processor_id();
21022 - t = &per_cpu(init_tss, cpu);
21023 + t = init_tss + cpu;
21024 oist = &per_cpu(orig_ist, cpu);
21025
21026 #ifdef CONFIG_NUMA
21027 @@ -1279,7 +1288,6 @@ void cpu_init(void)
21028 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21029 barrier();
21030
21031 - x86_configure_nx();
21032 enable_x2apic();
21033
21034 /*
21035 @@ -1331,7 +1339,7 @@ void cpu_init(void)
21036 {
21037 int cpu = smp_processor_id();
21038 struct task_struct *curr = current;
21039 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21040 + struct tss_struct *t = init_tss + cpu;
21041 struct thread_struct *thread = &curr->thread;
21042
21043 show_ucode_info_early();
21044 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21045 index 0641113..06f5ba4 100644
21046 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21047 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21048 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21049 };
21050
21051 #ifdef CONFIG_AMD_NB
21052 +static struct attribute *default_attrs_amd_nb[] = {
21053 + &type.attr,
21054 + &level.attr,
21055 + &coherency_line_size.attr,
21056 + &physical_line_partition.attr,
21057 + &ways_of_associativity.attr,
21058 + &number_of_sets.attr,
21059 + &size.attr,
21060 + &shared_cpu_map.attr,
21061 + &shared_cpu_list.attr,
21062 + NULL,
21063 + NULL,
21064 + NULL,
21065 + NULL
21066 +};
21067 +
21068 static struct attribute **amd_l3_attrs(void)
21069 {
21070 static struct attribute **attrs;
21071 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21072
21073 n = ARRAY_SIZE(default_attrs);
21074
21075 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21076 - n += 2;
21077 -
21078 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21079 - n += 1;
21080 -
21081 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21082 - if (attrs == NULL)
21083 - return attrs = default_attrs;
21084 -
21085 - for (n = 0; default_attrs[n]; n++)
21086 - attrs[n] = default_attrs[n];
21087 + attrs = default_attrs_amd_nb;
21088
21089 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21090 attrs[n++] = &cache_disable_0.attr;
21091 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21092 .default_attrs = default_attrs,
21093 };
21094
21095 +#ifdef CONFIG_AMD_NB
21096 +static struct kobj_type ktype_cache_amd_nb = {
21097 + .sysfs_ops = &sysfs_ops,
21098 + .default_attrs = default_attrs_amd_nb,
21099 +};
21100 +#endif
21101 +
21102 static struct kobj_type ktype_percpu_entry = {
21103 .sysfs_ops = &sysfs_ops,
21104 };
21105 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21106 return retval;
21107 }
21108
21109 +#ifdef CONFIG_AMD_NB
21110 + amd_l3_attrs();
21111 +#endif
21112 +
21113 for (i = 0; i < num_cache_leaves; i++) {
21114 + struct kobj_type *ktype;
21115 +
21116 this_object = INDEX_KOBJECT_PTR(cpu, i);
21117 this_object->cpu = cpu;
21118 this_object->index = i;
21119
21120 this_leaf = CPUID4_INFO_IDX(cpu, i);
21121
21122 - ktype_cache.default_attrs = default_attrs;
21123 + ktype = &ktype_cache;
21124 #ifdef CONFIG_AMD_NB
21125 if (this_leaf->base.nb)
21126 - ktype_cache.default_attrs = amd_l3_attrs();
21127 + ktype = &ktype_cache_amd_nb;
21128 #endif
21129 retval = kobject_init_and_add(&(this_object->kobj),
21130 - &ktype_cache,
21131 + ktype,
21132 per_cpu(ici_cache_kobject, cpu),
21133 "index%1lu", i);
21134 if (unlikely(retval)) {
21135 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21136 index b3218cd..99a75de 100644
21137 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21138 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21139 @@ -45,6 +45,7 @@
21140 #include <asm/processor.h>
21141 #include <asm/mce.h>
21142 #include <asm/msr.h>
21143 +#include <asm/local.h>
21144
21145 #include "mce-internal.h"
21146
21147 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21148 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21149 m->cs, m->ip);
21150
21151 - if (m->cs == __KERNEL_CS)
21152 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21153 print_symbol("{%s}", m->ip);
21154 pr_cont("\n");
21155 }
21156 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21157
21158 #define PANIC_TIMEOUT 5 /* 5 seconds */
21159
21160 -static atomic_t mce_paniced;
21161 +static atomic_unchecked_t mce_paniced;
21162
21163 static int fake_panic;
21164 -static atomic_t mce_fake_paniced;
21165 +static atomic_unchecked_t mce_fake_paniced;
21166
21167 /* Panic in progress. Enable interrupts and wait for final IPI */
21168 static void wait_for_panic(void)
21169 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21170 /*
21171 * Make sure only one CPU runs in machine check panic
21172 */
21173 - if (atomic_inc_return(&mce_paniced) > 1)
21174 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21175 wait_for_panic();
21176 barrier();
21177
21178 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21179 console_verbose();
21180 } else {
21181 /* Don't log too much for fake panic */
21182 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21183 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21184 return;
21185 }
21186 /* First print corrected ones that are still unlogged */
21187 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21188 if (!fake_panic) {
21189 if (panic_timeout == 0)
21190 panic_timeout = mca_cfg.panic_timeout;
21191 - panic(msg);
21192 + panic("%s", msg);
21193 } else
21194 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21195 }
21196 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21197 * might have been modified by someone else.
21198 */
21199 rmb();
21200 - if (atomic_read(&mce_paniced))
21201 + if (atomic_read_unchecked(&mce_paniced))
21202 wait_for_panic();
21203 if (!mca_cfg.monarch_timeout)
21204 goto out;
21205 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21206 }
21207
21208 /* Call the installed machine check handler for this CPU setup. */
21209 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21210 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21211 unexpected_machine_check;
21212
21213 /*
21214 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21215 return;
21216 }
21217
21218 + pax_open_kernel();
21219 machine_check_vector = do_machine_check;
21220 + pax_close_kernel();
21221
21222 __mcheck_cpu_init_generic();
21223 __mcheck_cpu_init_vendor(c);
21224 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21225 */
21226
21227 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21228 -static int mce_chrdev_open_count; /* #times opened */
21229 +static local_t mce_chrdev_open_count; /* #times opened */
21230 static int mce_chrdev_open_exclu; /* already open exclusive? */
21231
21232 static int mce_chrdev_open(struct inode *inode, struct file *file)
21233 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21234 spin_lock(&mce_chrdev_state_lock);
21235
21236 if (mce_chrdev_open_exclu ||
21237 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21238 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21239 spin_unlock(&mce_chrdev_state_lock);
21240
21241 return -EBUSY;
21242 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21243
21244 if (file->f_flags & O_EXCL)
21245 mce_chrdev_open_exclu = 1;
21246 - mce_chrdev_open_count++;
21247 + local_inc(&mce_chrdev_open_count);
21248
21249 spin_unlock(&mce_chrdev_state_lock);
21250
21251 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21252 {
21253 spin_lock(&mce_chrdev_state_lock);
21254
21255 - mce_chrdev_open_count--;
21256 + local_dec(&mce_chrdev_open_count);
21257 mce_chrdev_open_exclu = 0;
21258
21259 spin_unlock(&mce_chrdev_state_lock);
21260 @@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
21261
21262 for (i = 0; i < mca_cfg.banks; i++) {
21263 struct mce_bank *b = &mce_banks[i];
21264 - struct device_attribute *a = &b->attr;
21265 + device_attribute_no_const *a = &b->attr;
21266
21267 sysfs_attr_init(&a->attr);
21268 a->attr.name = b->attrname;
21269 @@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
21270 static void mce_reset(void)
21271 {
21272 cpu_missing = 0;
21273 - atomic_set(&mce_fake_paniced, 0);
21274 + atomic_set_unchecked(&mce_fake_paniced, 0);
21275 atomic_set(&mce_executing, 0);
21276 atomic_set(&mce_callin, 0);
21277 atomic_set(&global_nwo, 0);
21278 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21279 index 1c044b1..37a2a43 100644
21280 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21281 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21282 @@ -11,6 +11,7 @@
21283 #include <asm/processor.h>
21284 #include <asm/mce.h>
21285 #include <asm/msr.h>
21286 +#include <asm/pgtable.h>
21287
21288 /* By default disabled */
21289 int mce_p5_enabled __read_mostly;
21290 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21291 if (!cpu_has(c, X86_FEATURE_MCE))
21292 return;
21293
21294 + pax_open_kernel();
21295 machine_check_vector = pentium_machine_check;
21296 + pax_close_kernel();
21297 /* Make sure the vector pointer is visible before we enable MCEs: */
21298 wmb();
21299
21300 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21301 index e9a701a..35317d6 100644
21302 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21303 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21304 @@ -10,6 +10,7 @@
21305 #include <asm/processor.h>
21306 #include <asm/mce.h>
21307 #include <asm/msr.h>
21308 +#include <asm/pgtable.h>
21309
21310 /* Machine check handler for WinChip C6: */
21311 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21312 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21313 {
21314 u32 lo, hi;
21315
21316 + pax_open_kernel();
21317 machine_check_vector = winchip_machine_check;
21318 + pax_close_kernel();
21319 /* Make sure the vector pointer is visible before we enable MCEs: */
21320 wmb();
21321
21322 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21323 index f961de9..8a9d332 100644
21324 --- a/arch/x86/kernel/cpu/mtrr/main.c
21325 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21326 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21327 u64 size_or_mask, size_and_mask;
21328 static bool mtrr_aps_delayed_init;
21329
21330 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21331 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21332
21333 const struct mtrr_ops *mtrr_if;
21334
21335 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21336 index df5e41f..816c719 100644
21337 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21338 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21339 @@ -25,7 +25,7 @@ struct mtrr_ops {
21340 int (*validate_add_page)(unsigned long base, unsigned long size,
21341 unsigned int type);
21342 int (*have_wrcomb)(void);
21343 -};
21344 +} __do_const;
21345
21346 extern int generic_get_free_region(unsigned long base, unsigned long size,
21347 int replace_reg);
21348 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21349 index db6cdbe..faaf834 100644
21350 --- a/arch/x86/kernel/cpu/perf_event.c
21351 +++ b/arch/x86/kernel/cpu/perf_event.c
21352 @@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21353 pr_info("no hardware sampling interrupt available.\n");
21354 }
21355
21356 -static struct attribute_group x86_pmu_format_group = {
21357 +static attribute_group_no_const x86_pmu_format_group = {
21358 .name = "format",
21359 .attrs = NULL,
21360 };
21361 @@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21362 NULL,
21363 };
21364
21365 -static struct attribute_group x86_pmu_events_group = {
21366 +static attribute_group_no_const x86_pmu_events_group = {
21367 .name = "events",
21368 .attrs = events_attr,
21369 };
21370 @@ -1961,7 +1961,7 @@ static unsigned long get_segment_base(unsigned int segment)
21371 if (idx > GDT_ENTRIES)
21372 return 0;
21373
21374 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21375 + desc = get_cpu_gdt_table(smp_processor_id());
21376 }
21377
21378 return get_desc_base(desc + idx);
21379 @@ -2051,7 +2051,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21380 break;
21381
21382 perf_callchain_store(entry, frame.return_address);
21383 - fp = frame.next_frame;
21384 + fp = (const void __force_user *)frame.next_frame;
21385 }
21386 }
21387
21388 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21389 index 639d128..e92d7e5 100644
21390 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21391 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21392 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21393 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21394 {
21395 struct attribute **attrs;
21396 - struct attribute_group *attr_group;
21397 + attribute_group_no_const *attr_group;
21398 int i = 0, j;
21399
21400 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21401 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21402 index 0fa4f24..17990ed 100644
21403 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21404 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21405 @@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
21406 * v2 and above have a perf capabilities MSR
21407 */
21408 if (version > 1) {
21409 - u64 capabilities;
21410 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21411
21412 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21413 - x86_pmu.intel_cap.capabilities = capabilities;
21414 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21415 + x86_pmu.intel_cap.capabilities = capabilities;
21416 }
21417
21418 intel_ds_init();
21419 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21420 index 29c2487..a5606fa 100644
21421 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21422 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21423 @@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21424 static int __init uncore_type_init(struct intel_uncore_type *type)
21425 {
21426 struct intel_uncore_pmu *pmus;
21427 - struct attribute_group *attr_group;
21428 + attribute_group_no_const *attr_group;
21429 struct attribute **attrs;
21430 int i, j;
21431
21432 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21433 index a80ab71..4089da5 100644
21434 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21435 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21436 @@ -498,7 +498,7 @@ struct intel_uncore_box {
21437 struct uncore_event_desc {
21438 struct kobj_attribute attr;
21439 const char *config;
21440 -};
21441 +} __do_const;
21442
21443 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21444 { \
21445 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21446 index 7d9481c..99c7e4b 100644
21447 --- a/arch/x86/kernel/cpuid.c
21448 +++ b/arch/x86/kernel/cpuid.c
21449 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21450 return notifier_from_errno(err);
21451 }
21452
21453 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21454 +static struct notifier_block cpuid_class_cpu_notifier =
21455 {
21456 .notifier_call = cpuid_class_cpu_callback,
21457 };
21458 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21459 index 18677a9..f67c45b 100644
21460 --- a/arch/x86/kernel/crash.c
21461 +++ b/arch/x86/kernel/crash.c
21462 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21463 {
21464 #ifdef CONFIG_X86_32
21465 struct pt_regs fixed_regs;
21466 -#endif
21467
21468 -#ifdef CONFIG_X86_32
21469 - if (!user_mode_vm(regs)) {
21470 + if (!user_mode(regs)) {
21471 crash_fixup_ss_esp(&fixed_regs, regs);
21472 regs = &fixed_regs;
21473 }
21474 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21475 index afa64ad..dce67dd 100644
21476 --- a/arch/x86/kernel/crash_dump_64.c
21477 +++ b/arch/x86/kernel/crash_dump_64.c
21478 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21479 return -ENOMEM;
21480
21481 if (userbuf) {
21482 - if (copy_to_user(buf, vaddr + offset, csize)) {
21483 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21484 iounmap(vaddr);
21485 return -EFAULT;
21486 }
21487 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21488 index 5d3fe8d..02e1429 100644
21489 --- a/arch/x86/kernel/doublefault.c
21490 +++ b/arch/x86/kernel/doublefault.c
21491 @@ -13,7 +13,7 @@
21492
21493 #define DOUBLEFAULT_STACKSIZE (1024)
21494 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21495 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21496 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21497
21498 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21499
21500 @@ -23,7 +23,7 @@ static void doublefault_fn(void)
21501 unsigned long gdt, tss;
21502
21503 native_store_gdt(&gdt_desc);
21504 - gdt = gdt_desc.address;
21505 + gdt = (unsigned long)gdt_desc.address;
21506
21507 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21508
21509 @@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21510 /* 0x2 bit is always set */
21511 .flags = X86_EFLAGS_SF | 0x2,
21512 .sp = STACK_START,
21513 - .es = __USER_DS,
21514 + .es = __KERNEL_DS,
21515 .cs = __KERNEL_CS,
21516 .ss = __KERNEL_DS,
21517 - .ds = __USER_DS,
21518 + .ds = __KERNEL_DS,
21519 .fs = __KERNEL_PERCPU,
21520
21521 .__cr3 = __pa_nodebug(swapper_pg_dir),
21522 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21523 index d9c12d3..7858b62 100644
21524 --- a/arch/x86/kernel/dumpstack.c
21525 +++ b/arch/x86/kernel/dumpstack.c
21526 @@ -2,6 +2,9 @@
21527 * Copyright (C) 1991, 1992 Linus Torvalds
21528 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21529 */
21530 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21531 +#define __INCLUDED_BY_HIDESYM 1
21532 +#endif
21533 #include <linux/kallsyms.h>
21534 #include <linux/kprobes.h>
21535 #include <linux/uaccess.h>
21536 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21537 static void
21538 print_ftrace_graph_addr(unsigned long addr, void *data,
21539 const struct stacktrace_ops *ops,
21540 - struct thread_info *tinfo, int *graph)
21541 + struct task_struct *task, int *graph)
21542 {
21543 - struct task_struct *task;
21544 unsigned long ret_addr;
21545 int index;
21546
21547 if (addr != (unsigned long)return_to_handler)
21548 return;
21549
21550 - task = tinfo->task;
21551 index = task->curr_ret_stack;
21552
21553 if (!task->ret_stack || index < *graph)
21554 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21555 static inline void
21556 print_ftrace_graph_addr(unsigned long addr, void *data,
21557 const struct stacktrace_ops *ops,
21558 - struct thread_info *tinfo, int *graph)
21559 + struct task_struct *task, int *graph)
21560 { }
21561 #endif
21562
21563 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21564 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21565 */
21566
21567 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21568 - void *p, unsigned int size, void *end)
21569 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21570 {
21571 - void *t = tinfo;
21572 if (end) {
21573 if (p < end && p >= (end-THREAD_SIZE))
21574 return 1;
21575 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21576 }
21577
21578 unsigned long
21579 -print_context_stack(struct thread_info *tinfo,
21580 +print_context_stack(struct task_struct *task, void *stack_start,
21581 unsigned long *stack, unsigned long bp,
21582 const struct stacktrace_ops *ops, void *data,
21583 unsigned long *end, int *graph)
21584 {
21585 struct stack_frame *frame = (struct stack_frame *)bp;
21586
21587 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21588 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21589 unsigned long addr;
21590
21591 addr = *stack;
21592 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21593 } else {
21594 ops->address(data, addr, 0);
21595 }
21596 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21597 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21598 }
21599 stack++;
21600 }
21601 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21602 EXPORT_SYMBOL_GPL(print_context_stack);
21603
21604 unsigned long
21605 -print_context_stack_bp(struct thread_info *tinfo,
21606 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21607 unsigned long *stack, unsigned long bp,
21608 const struct stacktrace_ops *ops, void *data,
21609 unsigned long *end, int *graph)
21610 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21611 struct stack_frame *frame = (struct stack_frame *)bp;
21612 unsigned long *ret_addr = &frame->return_address;
21613
21614 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21615 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21616 unsigned long addr = *ret_addr;
21617
21618 if (!__kernel_text_address(addr))
21619 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21620 ops->address(data, addr, 1);
21621 frame = frame->next_frame;
21622 ret_addr = &frame->return_address;
21623 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21624 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21625 }
21626
21627 return (unsigned long)frame;
21628 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21629 static void print_trace_address(void *data, unsigned long addr, int reliable)
21630 {
21631 touch_nmi_watchdog();
21632 - printk(data);
21633 + printk("%s", (char *)data);
21634 printk_stack_address(addr, reliable);
21635 }
21636
21637 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21638 }
21639 EXPORT_SYMBOL_GPL(oops_begin);
21640
21641 +extern void gr_handle_kernel_exploit(void);
21642 +
21643 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21644 {
21645 if (regs && kexec_should_crash(current))
21646 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21647 panic("Fatal exception in interrupt");
21648 if (panic_on_oops)
21649 panic("Fatal exception");
21650 - do_exit(signr);
21651 +
21652 + gr_handle_kernel_exploit();
21653 +
21654 + do_group_exit(signr);
21655 }
21656
21657 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21658 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21659 print_modules();
21660 show_regs(regs);
21661 #ifdef CONFIG_X86_32
21662 - if (user_mode_vm(regs)) {
21663 + if (user_mode(regs)) {
21664 sp = regs->sp;
21665 ss = regs->ss & 0xffff;
21666 } else {
21667 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21668 unsigned long flags = oops_begin();
21669 int sig = SIGSEGV;
21670
21671 - if (!user_mode_vm(regs))
21672 + if (!user_mode(regs))
21673 report_bug(regs->ip, regs);
21674
21675 if (__die(str, regs, err))
21676 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21677 index f2a1770..540657f 100644
21678 --- a/arch/x86/kernel/dumpstack_32.c
21679 +++ b/arch/x86/kernel/dumpstack_32.c
21680 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21681 bp = stack_frame(task, regs);
21682
21683 for (;;) {
21684 - struct thread_info *context;
21685 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21686
21687 - context = (struct thread_info *)
21688 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21689 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21690 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21691
21692 - stack = (unsigned long *)context->previous_esp;
21693 - if (!stack)
21694 + if (stack_start == task_stack_page(task))
21695 break;
21696 + stack = *(unsigned long **)stack_start;
21697 if (ops->stack(data, "IRQ") < 0)
21698 break;
21699 touch_nmi_watchdog();
21700 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21701 int i;
21702
21703 show_regs_print_info(KERN_EMERG);
21704 - __show_regs(regs, !user_mode_vm(regs));
21705 + __show_regs(regs, !user_mode(regs));
21706
21707 /*
21708 * When in-kernel, we also print out the stack and code at the
21709 * time of the fault..
21710 */
21711 - if (!user_mode_vm(regs)) {
21712 + if (!user_mode(regs)) {
21713 unsigned int code_prologue = code_bytes * 43 / 64;
21714 unsigned int code_len = code_bytes;
21715 unsigned char c;
21716 u8 *ip;
21717 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21718
21719 pr_emerg("Stack:\n");
21720 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21721
21722 pr_emerg("Code:");
21723
21724 - ip = (u8 *)regs->ip - code_prologue;
21725 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21726 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21727 /* try starting at IP */
21728 - ip = (u8 *)regs->ip;
21729 + ip = (u8 *)regs->ip + cs_base;
21730 code_len = code_len - code_prologue + 1;
21731 }
21732 for (i = 0; i < code_len; i++, ip++) {
21733 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21734 pr_cont(" Bad EIP value.");
21735 break;
21736 }
21737 - if (ip == (u8 *)regs->ip)
21738 + if (ip == (u8 *)regs->ip + cs_base)
21739 pr_cont(" <%02x>", c);
21740 else
21741 pr_cont(" %02x", c);
21742 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21743 {
21744 unsigned short ud2;
21745
21746 + ip = ktla_ktva(ip);
21747 if (ip < PAGE_OFFSET)
21748 return 0;
21749 if (probe_kernel_address((unsigned short *)ip, ud2))
21750 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21751
21752 return ud2 == 0x0b0f;
21753 }
21754 +
21755 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21756 +void pax_check_alloca(unsigned long size)
21757 +{
21758 + unsigned long sp = (unsigned long)&sp, stack_left;
21759 +
21760 + /* all kernel stacks are of the same size */
21761 + stack_left = sp & (THREAD_SIZE - 1);
21762 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21763 +}
21764 +EXPORT_SYMBOL(pax_check_alloca);
21765 +#endif
21766 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21767 index addb207..99635fa 100644
21768 --- a/arch/x86/kernel/dumpstack_64.c
21769 +++ b/arch/x86/kernel/dumpstack_64.c
21770 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21771 unsigned long *irq_stack_end =
21772 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21773 unsigned used = 0;
21774 - struct thread_info *tinfo;
21775 int graph = 0;
21776 unsigned long dummy;
21777 + void *stack_start;
21778
21779 if (!task)
21780 task = current;
21781 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21782 * current stack address. If the stacks consist of nested
21783 * exceptions
21784 */
21785 - tinfo = task_thread_info(task);
21786 for (;;) {
21787 char *id;
21788 unsigned long *estack_end;
21789 +
21790 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21791 &used, &id);
21792
21793 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21794 if (ops->stack(data, id) < 0)
21795 break;
21796
21797 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21798 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21799 data, estack_end, &graph);
21800 ops->stack(data, "<EOE>");
21801 /*
21802 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21803 * second-to-last pointer (index -2 to end) in the
21804 * exception stack:
21805 */
21806 + if ((u16)estack_end[-1] != __KERNEL_DS)
21807 + goto out;
21808 stack = (unsigned long *) estack_end[-2];
21809 continue;
21810 }
21811 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21812 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21813 if (ops->stack(data, "IRQ") < 0)
21814 break;
21815 - bp = ops->walk_stack(tinfo, stack, bp,
21816 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21817 ops, data, irq_stack_end, &graph);
21818 /*
21819 * We link to the next stack (which would be
21820 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21821 /*
21822 * This handles the process stack:
21823 */
21824 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21825 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21826 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21827 +out:
21828 put_cpu();
21829 }
21830 EXPORT_SYMBOL(dump_trace);
21831 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21832
21833 return ud2 == 0x0b0f;
21834 }
21835 +
21836 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21837 +void pax_check_alloca(unsigned long size)
21838 +{
21839 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21840 + unsigned cpu, used;
21841 + char *id;
21842 +
21843 + /* check the process stack first */
21844 + stack_start = (unsigned long)task_stack_page(current);
21845 + stack_end = stack_start + THREAD_SIZE;
21846 + if (likely(stack_start <= sp && sp < stack_end)) {
21847 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21848 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21849 + return;
21850 + }
21851 +
21852 + cpu = get_cpu();
21853 +
21854 + /* check the irq stacks */
21855 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21856 + stack_start = stack_end - IRQ_STACK_SIZE;
21857 + if (stack_start <= sp && sp < stack_end) {
21858 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21859 + put_cpu();
21860 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21861 + return;
21862 + }
21863 +
21864 + /* check the exception stacks */
21865 + used = 0;
21866 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21867 + stack_start = stack_end - EXCEPTION_STKSZ;
21868 + if (stack_end && stack_start <= sp && sp < stack_end) {
21869 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21870 + put_cpu();
21871 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21872 + return;
21873 + }
21874 +
21875 + put_cpu();
21876 +
21877 + /* unknown stack */
21878 + BUG();
21879 +}
21880 +EXPORT_SYMBOL(pax_check_alloca);
21881 +#endif
21882 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21883 index 174da5f..5e55606 100644
21884 --- a/arch/x86/kernel/e820.c
21885 +++ b/arch/x86/kernel/e820.c
21886 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21887
21888 static void early_panic(char *msg)
21889 {
21890 - early_printk(msg);
21891 - panic(msg);
21892 + early_printk("%s", msg);
21893 + panic("%s", msg);
21894 }
21895
21896 static int userdef __initdata;
21897 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21898 index 01d1c18..8073693 100644
21899 --- a/arch/x86/kernel/early_printk.c
21900 +++ b/arch/x86/kernel/early_printk.c
21901 @@ -7,6 +7,7 @@
21902 #include <linux/pci_regs.h>
21903 #include <linux/pci_ids.h>
21904 #include <linux/errno.h>
21905 +#include <linux/sched.h>
21906 #include <asm/io.h>
21907 #include <asm/processor.h>
21908 #include <asm/fcntl.h>
21909 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21910 index a2a4f46..6cab058 100644
21911 --- a/arch/x86/kernel/entry_32.S
21912 +++ b/arch/x86/kernel/entry_32.S
21913 @@ -177,13 +177,153 @@
21914 /*CFI_REL_OFFSET gs, PT_GS*/
21915 .endm
21916 .macro SET_KERNEL_GS reg
21917 +
21918 +#ifdef CONFIG_CC_STACKPROTECTOR
21919 movl $(__KERNEL_STACK_CANARY), \reg
21920 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21921 + movl $(__USER_DS), \reg
21922 +#else
21923 + xorl \reg, \reg
21924 +#endif
21925 +
21926 movl \reg, %gs
21927 .endm
21928
21929 #endif /* CONFIG_X86_32_LAZY_GS */
21930
21931 -.macro SAVE_ALL
21932 +.macro pax_enter_kernel
21933 +#ifdef CONFIG_PAX_KERNEXEC
21934 + call pax_enter_kernel
21935 +#endif
21936 +.endm
21937 +
21938 +.macro pax_exit_kernel
21939 +#ifdef CONFIG_PAX_KERNEXEC
21940 + call pax_exit_kernel
21941 +#endif
21942 +.endm
21943 +
21944 +#ifdef CONFIG_PAX_KERNEXEC
21945 +ENTRY(pax_enter_kernel)
21946 +#ifdef CONFIG_PARAVIRT
21947 + pushl %eax
21948 + pushl %ecx
21949 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21950 + mov %eax, %esi
21951 +#else
21952 + mov %cr0, %esi
21953 +#endif
21954 + bts $16, %esi
21955 + jnc 1f
21956 + mov %cs, %esi
21957 + cmp $__KERNEL_CS, %esi
21958 + jz 3f
21959 + ljmp $__KERNEL_CS, $3f
21960 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21961 +2:
21962 +#ifdef CONFIG_PARAVIRT
21963 + mov %esi, %eax
21964 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21965 +#else
21966 + mov %esi, %cr0
21967 +#endif
21968 +3:
21969 +#ifdef CONFIG_PARAVIRT
21970 + popl %ecx
21971 + popl %eax
21972 +#endif
21973 + ret
21974 +ENDPROC(pax_enter_kernel)
21975 +
21976 +ENTRY(pax_exit_kernel)
21977 +#ifdef CONFIG_PARAVIRT
21978 + pushl %eax
21979 + pushl %ecx
21980 +#endif
21981 + mov %cs, %esi
21982 + cmp $__KERNEXEC_KERNEL_CS, %esi
21983 + jnz 2f
21984 +#ifdef CONFIG_PARAVIRT
21985 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21986 + mov %eax, %esi
21987 +#else
21988 + mov %cr0, %esi
21989 +#endif
21990 + btr $16, %esi
21991 + ljmp $__KERNEL_CS, $1f
21992 +1:
21993 +#ifdef CONFIG_PARAVIRT
21994 + mov %esi, %eax
21995 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21996 +#else
21997 + mov %esi, %cr0
21998 +#endif
21999 +2:
22000 +#ifdef CONFIG_PARAVIRT
22001 + popl %ecx
22002 + popl %eax
22003 +#endif
22004 + ret
22005 +ENDPROC(pax_exit_kernel)
22006 +#endif
22007 +
22008 + .macro pax_erase_kstack
22009 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22010 + call pax_erase_kstack
22011 +#endif
22012 + .endm
22013 +
22014 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22015 +/*
22016 + * ebp: thread_info
22017 + */
22018 +ENTRY(pax_erase_kstack)
22019 + pushl %edi
22020 + pushl %ecx
22021 + pushl %eax
22022 +
22023 + mov TI_lowest_stack(%ebp), %edi
22024 + mov $-0xBEEF, %eax
22025 + std
22026 +
22027 +1: mov %edi, %ecx
22028 + and $THREAD_SIZE_asm - 1, %ecx
22029 + shr $2, %ecx
22030 + repne scasl
22031 + jecxz 2f
22032 +
22033 + cmp $2*16, %ecx
22034 + jc 2f
22035 +
22036 + mov $2*16, %ecx
22037 + repe scasl
22038 + jecxz 2f
22039 + jne 1b
22040 +
22041 +2: cld
22042 + mov %esp, %ecx
22043 + sub %edi, %ecx
22044 +
22045 + cmp $THREAD_SIZE_asm, %ecx
22046 + jb 3f
22047 + ud2
22048 +3:
22049 +
22050 + shr $2, %ecx
22051 + rep stosl
22052 +
22053 + mov TI_task_thread_sp0(%ebp), %edi
22054 + sub $128, %edi
22055 + mov %edi, TI_lowest_stack(%ebp)
22056 +
22057 + popl %eax
22058 + popl %ecx
22059 + popl %edi
22060 + ret
22061 +ENDPROC(pax_erase_kstack)
22062 +#endif
22063 +
22064 +.macro __SAVE_ALL _DS
22065 cld
22066 PUSH_GS
22067 pushl_cfi %fs
22068 @@ -206,7 +346,7 @@
22069 CFI_REL_OFFSET ecx, 0
22070 pushl_cfi %ebx
22071 CFI_REL_OFFSET ebx, 0
22072 - movl $(__USER_DS), %edx
22073 + movl $\_DS, %edx
22074 movl %edx, %ds
22075 movl %edx, %es
22076 movl $(__KERNEL_PERCPU), %edx
22077 @@ -214,6 +354,15 @@
22078 SET_KERNEL_GS %edx
22079 .endm
22080
22081 +.macro SAVE_ALL
22082 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22083 + __SAVE_ALL __KERNEL_DS
22084 + pax_enter_kernel
22085 +#else
22086 + __SAVE_ALL __USER_DS
22087 +#endif
22088 +.endm
22089 +
22090 .macro RESTORE_INT_REGS
22091 popl_cfi %ebx
22092 CFI_RESTORE ebx
22093 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22094 popfl_cfi
22095 jmp syscall_exit
22096 CFI_ENDPROC
22097 -END(ret_from_fork)
22098 +ENDPROC(ret_from_fork)
22099
22100 ENTRY(ret_from_kernel_thread)
22101 CFI_STARTPROC
22102 @@ -344,7 +493,15 @@ ret_from_intr:
22103 andl $SEGMENT_RPL_MASK, %eax
22104 #endif
22105 cmpl $USER_RPL, %eax
22106 +
22107 +#ifdef CONFIG_PAX_KERNEXEC
22108 + jae resume_userspace
22109 +
22110 + pax_exit_kernel
22111 + jmp resume_kernel
22112 +#else
22113 jb resume_kernel # not returning to v8086 or userspace
22114 +#endif
22115
22116 ENTRY(resume_userspace)
22117 LOCKDEP_SYS_EXIT
22118 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22119 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22120 # int/exception return?
22121 jne work_pending
22122 - jmp restore_all
22123 -END(ret_from_exception)
22124 + jmp restore_all_pax
22125 +ENDPROC(ret_from_exception)
22126
22127 #ifdef CONFIG_PREEMPT
22128 ENTRY(resume_kernel)
22129 @@ -369,7 +526,7 @@ need_resched:
22130 jz restore_all
22131 call preempt_schedule_irq
22132 jmp need_resched
22133 -END(resume_kernel)
22134 +ENDPROC(resume_kernel)
22135 #endif
22136 CFI_ENDPROC
22137 /*
22138 @@ -403,30 +560,45 @@ sysenter_past_esp:
22139 /*CFI_REL_OFFSET cs, 0*/
22140 /*
22141 * Push current_thread_info()->sysenter_return to the stack.
22142 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22143 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22144 */
22145 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22146 + pushl_cfi $0
22147 CFI_REL_OFFSET eip, 0
22148
22149 pushl_cfi %eax
22150 SAVE_ALL
22151 + GET_THREAD_INFO(%ebp)
22152 + movl TI_sysenter_return(%ebp),%ebp
22153 + movl %ebp,PT_EIP(%esp)
22154 ENABLE_INTERRUPTS(CLBR_NONE)
22155
22156 /*
22157 * Load the potential sixth argument from user stack.
22158 * Careful about security.
22159 */
22160 + movl PT_OLDESP(%esp),%ebp
22161 +
22162 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22163 + mov PT_OLDSS(%esp),%ds
22164 +1: movl %ds:(%ebp),%ebp
22165 + push %ss
22166 + pop %ds
22167 +#else
22168 cmpl $__PAGE_OFFSET-3,%ebp
22169 jae syscall_fault
22170 ASM_STAC
22171 1: movl (%ebp),%ebp
22172 ASM_CLAC
22173 +#endif
22174 +
22175 movl %ebp,PT_EBP(%esp)
22176 _ASM_EXTABLE(1b,syscall_fault)
22177
22178 GET_THREAD_INFO(%ebp)
22179
22180 +#ifdef CONFIG_PAX_RANDKSTACK
22181 + pax_erase_kstack
22182 +#endif
22183 +
22184 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22185 jnz sysenter_audit
22186 sysenter_do_call:
22187 @@ -441,12 +613,24 @@ sysenter_do_call:
22188 testl $_TIF_ALLWORK_MASK, %ecx
22189 jne sysexit_audit
22190 sysenter_exit:
22191 +
22192 +#ifdef CONFIG_PAX_RANDKSTACK
22193 + pushl_cfi %eax
22194 + movl %esp, %eax
22195 + call pax_randomize_kstack
22196 + popl_cfi %eax
22197 +#endif
22198 +
22199 + pax_erase_kstack
22200 +
22201 /* if something modifies registers it must also disable sysexit */
22202 movl PT_EIP(%esp), %edx
22203 movl PT_OLDESP(%esp), %ecx
22204 xorl %ebp,%ebp
22205 TRACE_IRQS_ON
22206 1: mov PT_FS(%esp), %fs
22207 +2: mov PT_DS(%esp), %ds
22208 +3: mov PT_ES(%esp), %es
22209 PTGS_TO_GS
22210 ENABLE_INTERRUPTS_SYSEXIT
22211
22212 @@ -463,6 +647,9 @@ sysenter_audit:
22213 movl %eax,%edx /* 2nd arg: syscall number */
22214 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22215 call __audit_syscall_entry
22216 +
22217 + pax_erase_kstack
22218 +
22219 pushl_cfi %ebx
22220 movl PT_EAX(%esp),%eax /* reload syscall number */
22221 jmp sysenter_do_call
22222 @@ -488,10 +675,16 @@ sysexit_audit:
22223
22224 CFI_ENDPROC
22225 .pushsection .fixup,"ax"
22226 -2: movl $0,PT_FS(%esp)
22227 +4: movl $0,PT_FS(%esp)
22228 + jmp 1b
22229 +5: movl $0,PT_DS(%esp)
22230 + jmp 1b
22231 +6: movl $0,PT_ES(%esp)
22232 jmp 1b
22233 .popsection
22234 - _ASM_EXTABLE(1b,2b)
22235 + _ASM_EXTABLE(1b,4b)
22236 + _ASM_EXTABLE(2b,5b)
22237 + _ASM_EXTABLE(3b,6b)
22238 PTGS_TO_GS_EX
22239 ENDPROC(ia32_sysenter_target)
22240
22241 @@ -506,6 +699,11 @@ ENTRY(system_call)
22242 pushl_cfi %eax # save orig_eax
22243 SAVE_ALL
22244 GET_THREAD_INFO(%ebp)
22245 +
22246 +#ifdef CONFIG_PAX_RANDKSTACK
22247 + pax_erase_kstack
22248 +#endif
22249 +
22250 # system call tracing in operation / emulation
22251 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22252 jnz syscall_trace_entry
22253 @@ -524,6 +722,15 @@ syscall_exit:
22254 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22255 jne syscall_exit_work
22256
22257 +restore_all_pax:
22258 +
22259 +#ifdef CONFIG_PAX_RANDKSTACK
22260 + movl %esp, %eax
22261 + call pax_randomize_kstack
22262 +#endif
22263 +
22264 + pax_erase_kstack
22265 +
22266 restore_all:
22267 TRACE_IRQS_IRET
22268 restore_all_notrace:
22269 @@ -580,14 +787,34 @@ ldt_ss:
22270 * compensating for the offset by changing to the ESPFIX segment with
22271 * a base address that matches for the difference.
22272 */
22273 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22274 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22275 mov %esp, %edx /* load kernel esp */
22276 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22277 mov %dx, %ax /* eax: new kernel esp */
22278 sub %eax, %edx /* offset (low word is 0) */
22279 +#ifdef CONFIG_SMP
22280 + movl PER_CPU_VAR(cpu_number), %ebx
22281 + shll $PAGE_SHIFT_asm, %ebx
22282 + addl $cpu_gdt_table, %ebx
22283 +#else
22284 + movl $cpu_gdt_table, %ebx
22285 +#endif
22286 shr $16, %edx
22287 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22288 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22289 +
22290 +#ifdef CONFIG_PAX_KERNEXEC
22291 + mov %cr0, %esi
22292 + btr $16, %esi
22293 + mov %esi, %cr0
22294 +#endif
22295 +
22296 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22297 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22298 +
22299 +#ifdef CONFIG_PAX_KERNEXEC
22300 + bts $16, %esi
22301 + mov %esi, %cr0
22302 +#endif
22303 +
22304 pushl_cfi $__ESPFIX_SS
22305 pushl_cfi %eax /* new kernel esp */
22306 /* Disable interrupts, but do not irqtrace this section: we
22307 @@ -616,20 +843,18 @@ work_resched:
22308 movl TI_flags(%ebp), %ecx
22309 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22310 # than syscall tracing?
22311 - jz restore_all
22312 + jz restore_all_pax
22313 testb $_TIF_NEED_RESCHED, %cl
22314 jnz work_resched
22315
22316 work_notifysig: # deal with pending signals and
22317 # notify-resume requests
22318 + movl %esp, %eax
22319 #ifdef CONFIG_VM86
22320 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22321 - movl %esp, %eax
22322 jne work_notifysig_v86 # returning to kernel-space or
22323 # vm86-space
22324 1:
22325 -#else
22326 - movl %esp, %eax
22327 #endif
22328 TRACE_IRQS_ON
22329 ENABLE_INTERRUPTS(CLBR_NONE)
22330 @@ -650,7 +875,7 @@ work_notifysig_v86:
22331 movl %eax, %esp
22332 jmp 1b
22333 #endif
22334 -END(work_pending)
22335 +ENDPROC(work_pending)
22336
22337 # perform syscall exit tracing
22338 ALIGN
22339 @@ -658,11 +883,14 @@ syscall_trace_entry:
22340 movl $-ENOSYS,PT_EAX(%esp)
22341 movl %esp, %eax
22342 call syscall_trace_enter
22343 +
22344 + pax_erase_kstack
22345 +
22346 /* What it returned is what we'll actually use. */
22347 cmpl $(NR_syscalls), %eax
22348 jnae syscall_call
22349 jmp syscall_exit
22350 -END(syscall_trace_entry)
22351 +ENDPROC(syscall_trace_entry)
22352
22353 # perform syscall exit tracing
22354 ALIGN
22355 @@ -675,21 +903,25 @@ syscall_exit_work:
22356 movl %esp, %eax
22357 call syscall_trace_leave
22358 jmp resume_userspace
22359 -END(syscall_exit_work)
22360 +ENDPROC(syscall_exit_work)
22361 CFI_ENDPROC
22362
22363 RING0_INT_FRAME # can't unwind into user space anyway
22364 syscall_fault:
22365 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22366 + push %ss
22367 + pop %ds
22368 +#endif
22369 ASM_CLAC
22370 GET_THREAD_INFO(%ebp)
22371 movl $-EFAULT,PT_EAX(%esp)
22372 jmp resume_userspace
22373 -END(syscall_fault)
22374 +ENDPROC(syscall_fault)
22375
22376 syscall_badsys:
22377 movl $-ENOSYS,PT_EAX(%esp)
22378 jmp resume_userspace
22379 -END(syscall_badsys)
22380 +ENDPROC(syscall_badsys)
22381 CFI_ENDPROC
22382 /*
22383 * End of kprobes section
22384 @@ -705,8 +937,15 @@ END(syscall_badsys)
22385 * normal stack and adjusts ESP with the matching offset.
22386 */
22387 /* fixup the stack */
22388 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22389 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22390 +#ifdef CONFIG_SMP
22391 + movl PER_CPU_VAR(cpu_number), %ebx
22392 + shll $PAGE_SHIFT_asm, %ebx
22393 + addl $cpu_gdt_table, %ebx
22394 +#else
22395 + movl $cpu_gdt_table, %ebx
22396 +#endif
22397 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22398 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22399 shl $16, %eax
22400 addl %esp, %eax /* the adjusted stack pointer */
22401 pushl_cfi $__KERNEL_DS
22402 @@ -759,7 +998,7 @@ vector=vector+1
22403 .endr
22404 2: jmp common_interrupt
22405 .endr
22406 -END(irq_entries_start)
22407 +ENDPROC(irq_entries_start)
22408
22409 .previous
22410 END(interrupt)
22411 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22412 pushl_cfi $do_coprocessor_error
22413 jmp error_code
22414 CFI_ENDPROC
22415 -END(coprocessor_error)
22416 +ENDPROC(coprocessor_error)
22417
22418 ENTRY(simd_coprocessor_error)
22419 RING0_INT_FRAME
22420 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22421 .section .altinstructions,"a"
22422 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22423 .previous
22424 -.section .altinstr_replacement,"ax"
22425 +.section .altinstr_replacement,"a"
22426 663: pushl $do_simd_coprocessor_error
22427 664:
22428 .previous
22429 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22430 #endif
22431 jmp error_code
22432 CFI_ENDPROC
22433 -END(simd_coprocessor_error)
22434 +ENDPROC(simd_coprocessor_error)
22435
22436 ENTRY(device_not_available)
22437 RING0_INT_FRAME
22438 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22439 pushl_cfi $do_device_not_available
22440 jmp error_code
22441 CFI_ENDPROC
22442 -END(device_not_available)
22443 +ENDPROC(device_not_available)
22444
22445 #ifdef CONFIG_PARAVIRT
22446 ENTRY(native_iret)
22447 iret
22448 _ASM_EXTABLE(native_iret, iret_exc)
22449 -END(native_iret)
22450 +ENDPROC(native_iret)
22451
22452 ENTRY(native_irq_enable_sysexit)
22453 sti
22454 sysexit
22455 -END(native_irq_enable_sysexit)
22456 +ENDPROC(native_irq_enable_sysexit)
22457 #endif
22458
22459 ENTRY(overflow)
22460 @@ -872,7 +1111,7 @@ ENTRY(overflow)
22461 pushl_cfi $do_overflow
22462 jmp error_code
22463 CFI_ENDPROC
22464 -END(overflow)
22465 +ENDPROC(overflow)
22466
22467 ENTRY(bounds)
22468 RING0_INT_FRAME
22469 @@ -881,7 +1120,7 @@ ENTRY(bounds)
22470 pushl_cfi $do_bounds
22471 jmp error_code
22472 CFI_ENDPROC
22473 -END(bounds)
22474 +ENDPROC(bounds)
22475
22476 ENTRY(invalid_op)
22477 RING0_INT_FRAME
22478 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22479 pushl_cfi $do_invalid_op
22480 jmp error_code
22481 CFI_ENDPROC
22482 -END(invalid_op)
22483 +ENDPROC(invalid_op)
22484
22485 ENTRY(coprocessor_segment_overrun)
22486 RING0_INT_FRAME
22487 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22488 pushl_cfi $do_coprocessor_segment_overrun
22489 jmp error_code
22490 CFI_ENDPROC
22491 -END(coprocessor_segment_overrun)
22492 +ENDPROC(coprocessor_segment_overrun)
22493
22494 ENTRY(invalid_TSS)
22495 RING0_EC_FRAME
22496 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22497 pushl_cfi $do_invalid_TSS
22498 jmp error_code
22499 CFI_ENDPROC
22500 -END(invalid_TSS)
22501 +ENDPROC(invalid_TSS)
22502
22503 ENTRY(segment_not_present)
22504 RING0_EC_FRAME
22505 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22506 pushl_cfi $do_segment_not_present
22507 jmp error_code
22508 CFI_ENDPROC
22509 -END(segment_not_present)
22510 +ENDPROC(segment_not_present)
22511
22512 ENTRY(stack_segment)
22513 RING0_EC_FRAME
22514 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22515 pushl_cfi $do_stack_segment
22516 jmp error_code
22517 CFI_ENDPROC
22518 -END(stack_segment)
22519 +ENDPROC(stack_segment)
22520
22521 ENTRY(alignment_check)
22522 RING0_EC_FRAME
22523 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22524 pushl_cfi $do_alignment_check
22525 jmp error_code
22526 CFI_ENDPROC
22527 -END(alignment_check)
22528 +ENDPROC(alignment_check)
22529
22530 ENTRY(divide_error)
22531 RING0_INT_FRAME
22532 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
22533 pushl_cfi $do_divide_error
22534 jmp error_code
22535 CFI_ENDPROC
22536 -END(divide_error)
22537 +ENDPROC(divide_error)
22538
22539 #ifdef CONFIG_X86_MCE
22540 ENTRY(machine_check)
22541 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
22542 pushl_cfi machine_check_vector
22543 jmp error_code
22544 CFI_ENDPROC
22545 -END(machine_check)
22546 +ENDPROC(machine_check)
22547 #endif
22548
22549 ENTRY(spurious_interrupt_bug)
22550 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22551 pushl_cfi $do_spurious_interrupt_bug
22552 jmp error_code
22553 CFI_ENDPROC
22554 -END(spurious_interrupt_bug)
22555 +ENDPROC(spurious_interrupt_bug)
22556 /*
22557 * End of kprobes section
22558 */
22559 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22560
22561 ENTRY(mcount)
22562 ret
22563 -END(mcount)
22564 +ENDPROC(mcount)
22565
22566 ENTRY(ftrace_caller)
22567 cmpl $0, function_trace_stop
22568 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22569 .globl ftrace_stub
22570 ftrace_stub:
22571 ret
22572 -END(ftrace_caller)
22573 +ENDPROC(ftrace_caller)
22574
22575 ENTRY(ftrace_regs_caller)
22576 pushf /* push flags before compare (in cs location) */
22577 @@ -1207,7 +1446,7 @@ trace:
22578 popl %ecx
22579 popl %eax
22580 jmp ftrace_stub
22581 -END(mcount)
22582 +ENDPROC(mcount)
22583 #endif /* CONFIG_DYNAMIC_FTRACE */
22584 #endif /* CONFIG_FUNCTION_TRACER */
22585
22586 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22587 popl %ecx
22588 popl %eax
22589 ret
22590 -END(ftrace_graph_caller)
22591 +ENDPROC(ftrace_graph_caller)
22592
22593 .globl return_to_handler
22594 return_to_handler:
22595 @@ -1291,15 +1530,18 @@ error_code:
22596 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22597 REG_TO_PTGS %ecx
22598 SET_KERNEL_GS %ecx
22599 - movl $(__USER_DS), %ecx
22600 + movl $(__KERNEL_DS), %ecx
22601 movl %ecx, %ds
22602 movl %ecx, %es
22603 +
22604 + pax_enter_kernel
22605 +
22606 TRACE_IRQS_OFF
22607 movl %esp,%eax # pt_regs pointer
22608 call *%edi
22609 jmp ret_from_exception
22610 CFI_ENDPROC
22611 -END(page_fault)
22612 +ENDPROC(page_fault)
22613
22614 /*
22615 * Debug traps and NMI can happen at the one SYSENTER instruction
22616 @@ -1342,7 +1584,7 @@ debug_stack_correct:
22617 call do_debug
22618 jmp ret_from_exception
22619 CFI_ENDPROC
22620 -END(debug)
22621 +ENDPROC(debug)
22622
22623 /*
22624 * NMI is doubly nasty. It can happen _while_ we're handling
22625 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
22626 xorl %edx,%edx # zero error code
22627 movl %esp,%eax # pt_regs pointer
22628 call do_nmi
22629 +
22630 + pax_exit_kernel
22631 +
22632 jmp restore_all_notrace
22633 CFI_ENDPROC
22634
22635 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22636 FIXUP_ESPFIX_STACK # %eax == %esp
22637 xorl %edx,%edx # zero error code
22638 call do_nmi
22639 +
22640 + pax_exit_kernel
22641 +
22642 RESTORE_REGS
22643 lss 12+4(%esp), %esp # back to espfix stack
22644 CFI_ADJUST_CFA_OFFSET -24
22645 jmp irq_return
22646 CFI_ENDPROC
22647 -END(nmi)
22648 +ENDPROC(nmi)
22649
22650 ENTRY(int3)
22651 RING0_INT_FRAME
22652 @@ -1434,14 +1682,14 @@ ENTRY(int3)
22653 call do_int3
22654 jmp ret_from_exception
22655 CFI_ENDPROC
22656 -END(int3)
22657 +ENDPROC(int3)
22658
22659 ENTRY(general_protection)
22660 RING0_EC_FRAME
22661 pushl_cfi $do_general_protection
22662 jmp error_code
22663 CFI_ENDPROC
22664 -END(general_protection)
22665 +ENDPROC(general_protection)
22666
22667 #ifdef CONFIG_KVM_GUEST
22668 ENTRY(async_page_fault)
22669 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22670 pushl_cfi $do_async_page_fault
22671 jmp error_code
22672 CFI_ENDPROC
22673 -END(async_page_fault)
22674 +ENDPROC(async_page_fault)
22675 #endif
22676
22677 /*
22678 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22679 index 1e96c36..3ff710a 100644
22680 --- a/arch/x86/kernel/entry_64.S
22681 +++ b/arch/x86/kernel/entry_64.S
22682 @@ -59,6 +59,8 @@
22683 #include <asm/context_tracking.h>
22684 #include <asm/smap.h>
22685 #include <linux/err.h>
22686 +#include <asm/pgtable.h>
22687 +#include <asm/alternative-asm.h>
22688
22689 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22690 #include <linux/elf-em.h>
22691 @@ -80,8 +82,9 @@
22692 #ifdef CONFIG_DYNAMIC_FTRACE
22693
22694 ENTRY(function_hook)
22695 + pax_force_retaddr
22696 retq
22697 -END(function_hook)
22698 +ENDPROC(function_hook)
22699
22700 /* skip is set if stack has been adjusted */
22701 .macro ftrace_caller_setup skip=0
22702 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22703 #endif
22704
22705 GLOBAL(ftrace_stub)
22706 + pax_force_retaddr
22707 retq
22708 -END(ftrace_caller)
22709 +ENDPROC(ftrace_caller)
22710
22711 ENTRY(ftrace_regs_caller)
22712 /* Save the current flags before compare (in SS location)*/
22713 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22714 popfq
22715 jmp ftrace_stub
22716
22717 -END(ftrace_regs_caller)
22718 +ENDPROC(ftrace_regs_caller)
22719
22720
22721 #else /* ! CONFIG_DYNAMIC_FTRACE */
22722 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22723 #endif
22724
22725 GLOBAL(ftrace_stub)
22726 + pax_force_retaddr
22727 retq
22728
22729 trace:
22730 @@ -225,12 +230,13 @@ trace:
22731 #endif
22732 subq $MCOUNT_INSN_SIZE, %rdi
22733
22734 + pax_force_fptr ftrace_trace_function
22735 call *ftrace_trace_function
22736
22737 MCOUNT_RESTORE_FRAME
22738
22739 jmp ftrace_stub
22740 -END(function_hook)
22741 +ENDPROC(function_hook)
22742 #endif /* CONFIG_DYNAMIC_FTRACE */
22743 #endif /* CONFIG_FUNCTION_TRACER */
22744
22745 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22746
22747 MCOUNT_RESTORE_FRAME
22748
22749 + pax_force_retaddr
22750 retq
22751 -END(ftrace_graph_caller)
22752 +ENDPROC(ftrace_graph_caller)
22753
22754 GLOBAL(return_to_handler)
22755 subq $24, %rsp
22756 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22757 movq 8(%rsp), %rdx
22758 movq (%rsp), %rax
22759 addq $24, %rsp
22760 + pax_force_fptr %rdi
22761 jmp *%rdi
22762 +ENDPROC(return_to_handler)
22763 #endif
22764
22765
22766 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22767 ENDPROC(native_usergs_sysret64)
22768 #endif /* CONFIG_PARAVIRT */
22769
22770 + .macro ljmpq sel, off
22771 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22772 + .byte 0x48; ljmp *1234f(%rip)
22773 + .pushsection .rodata
22774 + .align 16
22775 + 1234: .quad \off; .word \sel
22776 + .popsection
22777 +#else
22778 + pushq $\sel
22779 + pushq $\off
22780 + lretq
22781 +#endif
22782 + .endm
22783 +
22784 + .macro pax_enter_kernel
22785 + pax_set_fptr_mask
22786 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22787 + call pax_enter_kernel
22788 +#endif
22789 + .endm
22790 +
22791 + .macro pax_exit_kernel
22792 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22793 + call pax_exit_kernel
22794 +#endif
22795 +
22796 + .endm
22797 +
22798 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22799 +ENTRY(pax_enter_kernel)
22800 + pushq %rdi
22801 +
22802 +#ifdef CONFIG_PARAVIRT
22803 + PV_SAVE_REGS(CLBR_RDI)
22804 +#endif
22805 +
22806 +#ifdef CONFIG_PAX_KERNEXEC
22807 + GET_CR0_INTO_RDI
22808 + bts $16,%rdi
22809 + jnc 3f
22810 + mov %cs,%edi
22811 + cmp $__KERNEL_CS,%edi
22812 + jnz 2f
22813 +1:
22814 +#endif
22815 +
22816 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22817 + 661: jmp 111f
22818 + .pushsection .altinstr_replacement, "a"
22819 + 662: ASM_NOP2
22820 + .popsection
22821 + .pushsection .altinstructions, "a"
22822 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22823 + .popsection
22824 + GET_CR3_INTO_RDI
22825 + cmp $0,%dil
22826 + jnz 112f
22827 + mov $__KERNEL_DS,%edi
22828 + mov %edi,%ss
22829 + jmp 111f
22830 +112: cmp $1,%dil
22831 + jz 113f
22832 + ud2
22833 +113: sub $4097,%rdi
22834 + bts $63,%rdi
22835 + SET_RDI_INTO_CR3
22836 + mov $__UDEREF_KERNEL_DS,%edi
22837 + mov %edi,%ss
22838 +111:
22839 +#endif
22840 +
22841 +#ifdef CONFIG_PARAVIRT
22842 + PV_RESTORE_REGS(CLBR_RDI)
22843 +#endif
22844 +
22845 + popq %rdi
22846 + pax_force_retaddr
22847 + retq
22848 +
22849 +#ifdef CONFIG_PAX_KERNEXEC
22850 +2: ljmpq __KERNEL_CS,1b
22851 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22852 +4: SET_RDI_INTO_CR0
22853 + jmp 1b
22854 +#endif
22855 +ENDPROC(pax_enter_kernel)
22856 +
22857 +ENTRY(pax_exit_kernel)
22858 + pushq %rdi
22859 +
22860 +#ifdef CONFIG_PARAVIRT
22861 + PV_SAVE_REGS(CLBR_RDI)
22862 +#endif
22863 +
22864 +#ifdef CONFIG_PAX_KERNEXEC
22865 + mov %cs,%rdi
22866 + cmp $__KERNEXEC_KERNEL_CS,%edi
22867 + jz 2f
22868 + GET_CR0_INTO_RDI
22869 + bts $16,%rdi
22870 + jnc 4f
22871 +1:
22872 +#endif
22873 +
22874 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22875 + 661: jmp 111f
22876 + .pushsection .altinstr_replacement, "a"
22877 + 662: ASM_NOP2
22878 + .popsection
22879 + .pushsection .altinstructions, "a"
22880 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22881 + .popsection
22882 + mov %ss,%edi
22883 + cmp $__UDEREF_KERNEL_DS,%edi
22884 + jnz 111f
22885 + GET_CR3_INTO_RDI
22886 + cmp $0,%dil
22887 + jz 112f
22888 + ud2
22889 +112: add $4097,%rdi
22890 + bts $63,%rdi
22891 + SET_RDI_INTO_CR3
22892 + mov $__KERNEL_DS,%edi
22893 + mov %edi,%ss
22894 +111:
22895 +#endif
22896 +
22897 +#ifdef CONFIG_PARAVIRT
22898 + PV_RESTORE_REGS(CLBR_RDI);
22899 +#endif
22900 +
22901 + popq %rdi
22902 + pax_force_retaddr
22903 + retq
22904 +
22905 +#ifdef CONFIG_PAX_KERNEXEC
22906 +2: GET_CR0_INTO_RDI
22907 + btr $16,%rdi
22908 + jnc 4f
22909 + ljmpq __KERNEL_CS,3f
22910 +3: SET_RDI_INTO_CR0
22911 + jmp 1b
22912 +4: ud2
22913 + jmp 4b
22914 +#endif
22915 +ENDPROC(pax_exit_kernel)
22916 +#endif
22917 +
22918 + .macro pax_enter_kernel_user
22919 + pax_set_fptr_mask
22920 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22921 + call pax_enter_kernel_user
22922 +#endif
22923 + .endm
22924 +
22925 + .macro pax_exit_kernel_user
22926 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22927 + call pax_exit_kernel_user
22928 +#endif
22929 +#ifdef CONFIG_PAX_RANDKSTACK
22930 + pushq %rax
22931 + pushq %r11
22932 + call pax_randomize_kstack
22933 + popq %r11
22934 + popq %rax
22935 +#endif
22936 + .endm
22937 +
22938 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22939 +ENTRY(pax_enter_kernel_user)
22940 + pushq %rdi
22941 + pushq %rbx
22942 +
22943 +#ifdef CONFIG_PARAVIRT
22944 + PV_SAVE_REGS(CLBR_RDI)
22945 +#endif
22946 +
22947 + 661: jmp 111f
22948 + .pushsection .altinstr_replacement, "a"
22949 + 662: ASM_NOP2
22950 + .popsection
22951 + .pushsection .altinstructions, "a"
22952 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22953 + .popsection
22954 + GET_CR3_INTO_RDI
22955 + cmp $1,%dil
22956 + jnz 4f
22957 + sub $4097,%rdi
22958 + bts $63,%rdi
22959 + SET_RDI_INTO_CR3
22960 + jmp 3f
22961 +111:
22962 +
22963 + GET_CR3_INTO_RDI
22964 + mov %rdi,%rbx
22965 + add $__START_KERNEL_map,%rbx
22966 + sub phys_base(%rip),%rbx
22967 +
22968 +#ifdef CONFIG_PARAVIRT
22969 + cmpl $0, pv_info+PARAVIRT_enabled
22970 + jz 1f
22971 + pushq %rdi
22972 + i = 0
22973 + .rept USER_PGD_PTRS
22974 + mov i*8(%rbx),%rsi
22975 + mov $0,%sil
22976 + lea i*8(%rbx),%rdi
22977 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22978 + i = i + 1
22979 + .endr
22980 + popq %rdi
22981 + jmp 2f
22982 +1:
22983 +#endif
22984 +
22985 + i = 0
22986 + .rept USER_PGD_PTRS
22987 + movb $0,i*8(%rbx)
22988 + i = i + 1
22989 + .endr
22990 +
22991 +2: SET_RDI_INTO_CR3
22992 +
22993 +#ifdef CONFIG_PAX_KERNEXEC
22994 + GET_CR0_INTO_RDI
22995 + bts $16,%rdi
22996 + SET_RDI_INTO_CR0
22997 +#endif
22998 +
22999 +3:
23000 +
23001 +#ifdef CONFIG_PARAVIRT
23002 + PV_RESTORE_REGS(CLBR_RDI)
23003 +#endif
23004 +
23005 + popq %rbx
23006 + popq %rdi
23007 + pax_force_retaddr
23008 + retq
23009 +4: ud2
23010 +ENDPROC(pax_enter_kernel_user)
23011 +
23012 +ENTRY(pax_exit_kernel_user)
23013 + pushq %rdi
23014 + pushq %rbx
23015 +
23016 +#ifdef CONFIG_PARAVIRT
23017 + PV_SAVE_REGS(CLBR_RDI)
23018 +#endif
23019 +
23020 + GET_CR3_INTO_RDI
23021 + 661: jmp 1f
23022 + .pushsection .altinstr_replacement, "a"
23023 + 662: ASM_NOP2
23024 + .popsection
23025 + .pushsection .altinstructions, "a"
23026 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23027 + .popsection
23028 + cmp $0,%dil
23029 + jnz 3f
23030 + add $4097,%rdi
23031 + bts $63,%rdi
23032 + SET_RDI_INTO_CR3
23033 + jmp 2f
23034 +1:
23035 +
23036 + mov %rdi,%rbx
23037 +
23038 +#ifdef CONFIG_PAX_KERNEXEC
23039 + GET_CR0_INTO_RDI
23040 + btr $16,%rdi
23041 + jnc 3f
23042 + SET_RDI_INTO_CR0
23043 +#endif
23044 +
23045 + add $__START_KERNEL_map,%rbx
23046 + sub phys_base(%rip),%rbx
23047 +
23048 +#ifdef CONFIG_PARAVIRT
23049 + cmpl $0, pv_info+PARAVIRT_enabled
23050 + jz 1f
23051 + i = 0
23052 + .rept USER_PGD_PTRS
23053 + mov i*8(%rbx),%rsi
23054 + mov $0x67,%sil
23055 + lea i*8(%rbx),%rdi
23056 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23057 + i = i + 1
23058 + .endr
23059 + jmp 2f
23060 +1:
23061 +#endif
23062 +
23063 + i = 0
23064 + .rept USER_PGD_PTRS
23065 + movb $0x67,i*8(%rbx)
23066 + i = i + 1
23067 + .endr
23068 +2:
23069 +
23070 +#ifdef CONFIG_PARAVIRT
23071 + PV_RESTORE_REGS(CLBR_RDI)
23072 +#endif
23073 +
23074 + popq %rbx
23075 + popq %rdi
23076 + pax_force_retaddr
23077 + retq
23078 +3: ud2
23079 +ENDPROC(pax_exit_kernel_user)
23080 +#endif
23081 +
23082 + .macro pax_enter_kernel_nmi
23083 + pax_set_fptr_mask
23084 +
23085 +#ifdef CONFIG_PAX_KERNEXEC
23086 + GET_CR0_INTO_RDI
23087 + bts $16,%rdi
23088 + jc 110f
23089 + SET_RDI_INTO_CR0
23090 + or $2,%ebx
23091 +110:
23092 +#endif
23093 +
23094 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23095 + 661: jmp 111f
23096 + .pushsection .altinstr_replacement, "a"
23097 + 662: ASM_NOP2
23098 + .popsection
23099 + .pushsection .altinstructions, "a"
23100 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23101 + .popsection
23102 + GET_CR3_INTO_RDI
23103 + cmp $0,%dil
23104 + jz 111f
23105 + sub $4097,%rdi
23106 + or $4,%ebx
23107 + bts $63,%rdi
23108 + SET_RDI_INTO_CR3
23109 + mov $__UDEREF_KERNEL_DS,%edi
23110 + mov %edi,%ss
23111 +111:
23112 +#endif
23113 + .endm
23114 +
23115 + .macro pax_exit_kernel_nmi
23116 +#ifdef CONFIG_PAX_KERNEXEC
23117 + btr $1,%ebx
23118 + jnc 110f
23119 + GET_CR0_INTO_RDI
23120 + btr $16,%rdi
23121 + SET_RDI_INTO_CR0
23122 +110:
23123 +#endif
23124 +
23125 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23126 + btr $2,%ebx
23127 + jnc 111f
23128 + GET_CR3_INTO_RDI
23129 + add $4097,%rdi
23130 + bts $63,%rdi
23131 + SET_RDI_INTO_CR3
23132 + mov $__KERNEL_DS,%edi
23133 + mov %edi,%ss
23134 +111:
23135 +#endif
23136 + .endm
23137 +
23138 + .macro pax_erase_kstack
23139 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23140 + call pax_erase_kstack
23141 +#endif
23142 + .endm
23143 +
23144 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23145 +ENTRY(pax_erase_kstack)
23146 + pushq %rdi
23147 + pushq %rcx
23148 + pushq %rax
23149 + pushq %r11
23150 +
23151 + GET_THREAD_INFO(%r11)
23152 + mov TI_lowest_stack(%r11), %rdi
23153 + mov $-0xBEEF, %rax
23154 + std
23155 +
23156 +1: mov %edi, %ecx
23157 + and $THREAD_SIZE_asm - 1, %ecx
23158 + shr $3, %ecx
23159 + repne scasq
23160 + jecxz 2f
23161 +
23162 + cmp $2*8, %ecx
23163 + jc 2f
23164 +
23165 + mov $2*8, %ecx
23166 + repe scasq
23167 + jecxz 2f
23168 + jne 1b
23169 +
23170 +2: cld
23171 + mov %esp, %ecx
23172 + sub %edi, %ecx
23173 +
23174 + cmp $THREAD_SIZE_asm, %rcx
23175 + jb 3f
23176 + ud2
23177 +3:
23178 +
23179 + shr $3, %ecx
23180 + rep stosq
23181 +
23182 + mov TI_task_thread_sp0(%r11), %rdi
23183 + sub $256, %rdi
23184 + mov %rdi, TI_lowest_stack(%r11)
23185 +
23186 + popq %r11
23187 + popq %rax
23188 + popq %rcx
23189 + popq %rdi
23190 + pax_force_retaddr
23191 + ret
23192 +ENDPROC(pax_erase_kstack)
23193 +#endif
23194
23195 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23196 #ifdef CONFIG_TRACE_IRQFLAGS
23197 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23198 .endm
23199
23200 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23201 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23202 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23203 jnc 1f
23204 TRACE_IRQS_ON_DEBUG
23205 1:
23206 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23207 movq \tmp,R11+\offset(%rsp)
23208 .endm
23209
23210 - .macro FAKE_STACK_FRAME child_rip
23211 - /* push in order ss, rsp, eflags, cs, rip */
23212 - xorl %eax, %eax
23213 - pushq_cfi $__KERNEL_DS /* ss */
23214 - /*CFI_REL_OFFSET ss,0*/
23215 - pushq_cfi %rax /* rsp */
23216 - CFI_REL_OFFSET rsp,0
23217 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23218 - /*CFI_REL_OFFSET rflags,0*/
23219 - pushq_cfi $__KERNEL_CS /* cs */
23220 - /*CFI_REL_OFFSET cs,0*/
23221 - pushq_cfi \child_rip /* rip */
23222 - CFI_REL_OFFSET rip,0
23223 - pushq_cfi %rax /* orig rax */
23224 - .endm
23225 -
23226 - .macro UNFAKE_STACK_FRAME
23227 - addq $8*6, %rsp
23228 - CFI_ADJUST_CFA_OFFSET -(6*8)
23229 - .endm
23230 -
23231 /*
23232 * initial frame state for interrupts (and exceptions without error code)
23233 */
23234 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23235 /* save partial stack frame */
23236 .macro SAVE_ARGS_IRQ
23237 cld
23238 - /* start from rbp in pt_regs and jump over */
23239 - movq_cfi rdi, (RDI-RBP)
23240 - movq_cfi rsi, (RSI-RBP)
23241 - movq_cfi rdx, (RDX-RBP)
23242 - movq_cfi rcx, (RCX-RBP)
23243 - movq_cfi rax, (RAX-RBP)
23244 - movq_cfi r8, (R8-RBP)
23245 - movq_cfi r9, (R9-RBP)
23246 - movq_cfi r10, (R10-RBP)
23247 - movq_cfi r11, (R11-RBP)
23248 + /* start from r15 in pt_regs and jump over */
23249 + movq_cfi rdi, RDI
23250 + movq_cfi rsi, RSI
23251 + movq_cfi rdx, RDX
23252 + movq_cfi rcx, RCX
23253 + movq_cfi rax, RAX
23254 + movq_cfi r8, R8
23255 + movq_cfi r9, R9
23256 + movq_cfi r10, R10
23257 + movq_cfi r11, R11
23258 + movq_cfi r12, R12
23259
23260 /* Save rbp so that we can unwind from get_irq_regs() */
23261 - movq_cfi rbp, 0
23262 + movq_cfi rbp, RBP
23263
23264 /* Save previous stack value */
23265 movq %rsp, %rsi
23266
23267 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23268 - testl $3, CS-RBP(%rsi)
23269 + movq %rsp,%rdi /* arg1 for handler */
23270 + testb $3, CS(%rsi)
23271 je 1f
23272 SWAPGS
23273 /*
23274 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23275 0x06 /* DW_OP_deref */, \
23276 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23277 0x22 /* DW_OP_plus */
23278 +
23279 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23280 + testb $3, CS(%rdi)
23281 + jnz 1f
23282 + pax_enter_kernel
23283 + jmp 2f
23284 +1: pax_enter_kernel_user
23285 +2:
23286 +#else
23287 + pax_enter_kernel
23288 +#endif
23289 +
23290 /* We entered an interrupt context - irqs are off: */
23291 TRACE_IRQS_OFF
23292 .endm
23293 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23294 js 1f /* negative -> in kernel */
23295 SWAPGS
23296 xorl %ebx,%ebx
23297 -1: ret
23298 +1:
23299 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23300 + testb $3, CS+8(%rsp)
23301 + jnz 1f
23302 + pax_enter_kernel
23303 + jmp 2f
23304 +1: pax_enter_kernel_user
23305 +2:
23306 +#else
23307 + pax_enter_kernel
23308 +#endif
23309 + pax_force_retaddr
23310 + ret
23311 CFI_ENDPROC
23312 -END(save_paranoid)
23313 +ENDPROC(save_paranoid)
23314 +
23315 +ENTRY(save_paranoid_nmi)
23316 + XCPT_FRAME 1 RDI+8
23317 + cld
23318 + movq_cfi rdi, RDI+8
23319 + movq_cfi rsi, RSI+8
23320 + movq_cfi rdx, RDX+8
23321 + movq_cfi rcx, RCX+8
23322 + movq_cfi rax, RAX+8
23323 + movq_cfi r8, R8+8
23324 + movq_cfi r9, R9+8
23325 + movq_cfi r10, R10+8
23326 + movq_cfi r11, R11+8
23327 + movq_cfi rbx, RBX+8
23328 + movq_cfi rbp, RBP+8
23329 + movq_cfi r12, R12+8
23330 + movq_cfi r13, R13+8
23331 + movq_cfi r14, R14+8
23332 + movq_cfi r15, R15+8
23333 + movl $1,%ebx
23334 + movl $MSR_GS_BASE,%ecx
23335 + rdmsr
23336 + testl %edx,%edx
23337 + js 1f /* negative -> in kernel */
23338 + SWAPGS
23339 + xorl %ebx,%ebx
23340 +1: pax_enter_kernel_nmi
23341 + pax_force_retaddr
23342 + ret
23343 + CFI_ENDPROC
23344 +ENDPROC(save_paranoid_nmi)
23345 .popsection
23346
23347 /*
23348 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23349
23350 RESTORE_REST
23351
23352 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23353 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23354 jz 1f
23355
23356 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23357 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23358 jmp ret_from_sys_call # go to the SYSRET fastpath
23359
23360 1:
23361 - subq $REST_SKIP, %rsp # leave space for volatiles
23362 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23363 movq %rbp, %rdi
23364 call *%rbx
23365 movl $0, RAX(%rsp)
23366 RESTORE_REST
23367 jmp int_ret_from_sys_call
23368 CFI_ENDPROC
23369 -END(ret_from_fork)
23370 +ENDPROC(ret_from_fork)
23371
23372 /*
23373 * System call entry. Up to 6 arguments in registers are supported.
23374 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23375 ENTRY(system_call)
23376 CFI_STARTPROC simple
23377 CFI_SIGNAL_FRAME
23378 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23379 + CFI_DEF_CFA rsp,0
23380 CFI_REGISTER rip,rcx
23381 /*CFI_REGISTER rflags,r11*/
23382 SWAPGS_UNSAFE_STACK
23383 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23384
23385 movq %rsp,PER_CPU_VAR(old_rsp)
23386 movq PER_CPU_VAR(kernel_stack),%rsp
23387 + SAVE_ARGS 8*6,0
23388 + pax_enter_kernel_user
23389 +
23390 +#ifdef CONFIG_PAX_RANDKSTACK
23391 + pax_erase_kstack
23392 +#endif
23393 +
23394 /*
23395 * No need to follow this irqs off/on section - it's straight
23396 * and short:
23397 */
23398 ENABLE_INTERRUPTS(CLBR_NONE)
23399 - SAVE_ARGS 8,0
23400 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23401 movq %rcx,RIP-ARGOFFSET(%rsp)
23402 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23403 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23404 + GET_THREAD_INFO(%rcx)
23405 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23406 jnz tracesys
23407 system_call_fastpath:
23408 #if __SYSCALL_MASK == ~0
23409 @@ -639,10 +1112,13 @@ sysret_check:
23410 LOCKDEP_SYS_EXIT
23411 DISABLE_INTERRUPTS(CLBR_NONE)
23412 TRACE_IRQS_OFF
23413 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23414 + GET_THREAD_INFO(%rcx)
23415 + movl TI_flags(%rcx),%edx
23416 andl %edi,%edx
23417 jnz sysret_careful
23418 CFI_REMEMBER_STATE
23419 + pax_exit_kernel_user
23420 + pax_erase_kstack
23421 /*
23422 * sysretq will re-enable interrupts:
23423 */
23424 @@ -701,6 +1177,9 @@ auditsys:
23425 movq %rax,%rsi /* 2nd arg: syscall number */
23426 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23427 call __audit_syscall_entry
23428 +
23429 + pax_erase_kstack
23430 +
23431 LOAD_ARGS 0 /* reload call-clobbered registers */
23432 jmp system_call_fastpath
23433
23434 @@ -722,7 +1201,7 @@ sysret_audit:
23435 /* Do syscall tracing */
23436 tracesys:
23437 #ifdef CONFIG_AUDITSYSCALL
23438 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23439 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23440 jz auditsys
23441 #endif
23442 SAVE_REST
23443 @@ -730,12 +1209,15 @@ tracesys:
23444 FIXUP_TOP_OF_STACK %rdi
23445 movq %rsp,%rdi
23446 call syscall_trace_enter
23447 +
23448 + pax_erase_kstack
23449 +
23450 /*
23451 * Reload arg registers from stack in case ptrace changed them.
23452 * We don't reload %rax because syscall_trace_enter() returned
23453 * the value it wants us to use in the table lookup.
23454 */
23455 - LOAD_ARGS ARGOFFSET, 1
23456 + LOAD_ARGS 1
23457 RESTORE_REST
23458 #if __SYSCALL_MASK == ~0
23459 cmpq $__NR_syscall_max,%rax
23460 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23461 andl %edi,%edx
23462 jnz int_careful
23463 andl $~TS_COMPAT,TI_status(%rcx)
23464 - jmp retint_swapgs
23465 + pax_exit_kernel_user
23466 + pax_erase_kstack
23467 + jmp retint_swapgs_pax
23468
23469 /* Either reschedule or signal or syscall exit tracking needed. */
23470 /* First do a reschedule test. */
23471 @@ -811,7 +1295,7 @@ int_restore_rest:
23472 TRACE_IRQS_OFF
23473 jmp int_with_check
23474 CFI_ENDPROC
23475 -END(system_call)
23476 +ENDPROC(system_call)
23477
23478 .macro FORK_LIKE func
23479 ENTRY(stub_\func)
23480 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23481 DEFAULT_FRAME 0 8 /* offset 8: return address */
23482 call sys_\func
23483 RESTORE_TOP_OF_STACK %r11, 8
23484 - ret $REST_SKIP /* pop extended registers */
23485 + pax_force_retaddr
23486 + ret
23487 CFI_ENDPROC
23488 -END(stub_\func)
23489 +ENDPROC(stub_\func)
23490 .endm
23491
23492 .macro FIXED_FRAME label,func
23493 @@ -836,9 +1321,10 @@ ENTRY(\label)
23494 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23495 call \func
23496 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23497 + pax_force_retaddr
23498 ret
23499 CFI_ENDPROC
23500 -END(\label)
23501 +ENDPROC(\label)
23502 .endm
23503
23504 FORK_LIKE clone
23505 @@ -846,19 +1332,6 @@ END(\label)
23506 FORK_LIKE vfork
23507 FIXED_FRAME stub_iopl, sys_iopl
23508
23509 -ENTRY(ptregscall_common)
23510 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23511 - RESTORE_TOP_OF_STACK %r11, 8
23512 - movq_cfi_restore R15+8, r15
23513 - movq_cfi_restore R14+8, r14
23514 - movq_cfi_restore R13+8, r13
23515 - movq_cfi_restore R12+8, r12
23516 - movq_cfi_restore RBP+8, rbp
23517 - movq_cfi_restore RBX+8, rbx
23518 - ret $REST_SKIP /* pop extended registers */
23519 - CFI_ENDPROC
23520 -END(ptregscall_common)
23521 -
23522 ENTRY(stub_execve)
23523 CFI_STARTPROC
23524 addq $8, %rsp
23525 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23526 RESTORE_REST
23527 jmp int_ret_from_sys_call
23528 CFI_ENDPROC
23529 -END(stub_execve)
23530 +ENDPROC(stub_execve)
23531
23532 /*
23533 * sigreturn is special because it needs to restore all registers on return.
23534 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23535 RESTORE_REST
23536 jmp int_ret_from_sys_call
23537 CFI_ENDPROC
23538 -END(stub_rt_sigreturn)
23539 +ENDPROC(stub_rt_sigreturn)
23540
23541 #ifdef CONFIG_X86_X32_ABI
23542 ENTRY(stub_x32_rt_sigreturn)
23543 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23544 RESTORE_REST
23545 jmp int_ret_from_sys_call
23546 CFI_ENDPROC
23547 -END(stub_x32_rt_sigreturn)
23548 +ENDPROC(stub_x32_rt_sigreturn)
23549
23550 ENTRY(stub_x32_execve)
23551 CFI_STARTPROC
23552 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23553 RESTORE_REST
23554 jmp int_ret_from_sys_call
23555 CFI_ENDPROC
23556 -END(stub_x32_execve)
23557 +ENDPROC(stub_x32_execve)
23558
23559 #endif
23560
23561 @@ -952,7 +1425,7 @@ vector=vector+1
23562 2: jmp common_interrupt
23563 .endr
23564 CFI_ENDPROC
23565 -END(irq_entries_start)
23566 +ENDPROC(irq_entries_start)
23567
23568 .previous
23569 END(interrupt)
23570 @@ -969,8 +1442,8 @@ END(interrupt)
23571 /* 0(%rsp): ~(interrupt number) */
23572 .macro interrupt func
23573 /* reserve pt_regs for scratch regs and rbp */
23574 - subq $ORIG_RAX-RBP, %rsp
23575 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23576 + subq $ORIG_RAX, %rsp
23577 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23578 SAVE_ARGS_IRQ
23579 call \func
23580 .endm
23581 @@ -997,14 +1470,14 @@ ret_from_intr:
23582
23583 /* Restore saved previous stack */
23584 popq %rsi
23585 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23586 - leaq ARGOFFSET-RBP(%rsi), %rsp
23587 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23588 + movq %rsi, %rsp
23589 CFI_DEF_CFA_REGISTER rsp
23590 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23591 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23592
23593 exit_intr:
23594 GET_THREAD_INFO(%rcx)
23595 - testl $3,CS-ARGOFFSET(%rsp)
23596 + testb $3,CS-ARGOFFSET(%rsp)
23597 je retint_kernel
23598
23599 /* Interrupt came from user space */
23600 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23601 * The iretq could re-enable interrupts:
23602 */
23603 DISABLE_INTERRUPTS(CLBR_ANY)
23604 + pax_exit_kernel_user
23605 +retint_swapgs_pax:
23606 TRACE_IRQS_IRETQ
23607 SWAPGS
23608 jmp restore_args
23609
23610 retint_restore_args: /* return to kernel space */
23611 DISABLE_INTERRUPTS(CLBR_ANY)
23612 + pax_exit_kernel
23613 + pax_force_retaddr (RIP-ARGOFFSET)
23614 /*
23615 * The iretq could re-enable interrupts:
23616 */
23617 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23618 #endif
23619
23620 CFI_ENDPROC
23621 -END(common_interrupt)
23622 +ENDPROC(common_interrupt)
23623 /*
23624 * End of kprobes section
23625 */
23626 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23627 interrupt \do_sym
23628 jmp ret_from_intr
23629 CFI_ENDPROC
23630 -END(\sym)
23631 +ENDPROC(\sym)
23632 .endm
23633
23634 #ifdef CONFIG_TRACING
23635 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23636 call \do_sym
23637 jmp error_exit /* %ebx: no swapgs flag */
23638 CFI_ENDPROC
23639 -END(\sym)
23640 +ENDPROC(\sym)
23641 .endm
23642
23643 .macro paranoidzeroentry sym do_sym
23644 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23645 call \do_sym
23646 jmp paranoid_exit /* %ebx: no swapgs flag */
23647 CFI_ENDPROC
23648 -END(\sym)
23649 +ENDPROC(\sym)
23650 .endm
23651
23652 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23653 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23654 .macro paranoidzeroentry_ist sym do_sym ist
23655 ENTRY(\sym)
23656 INTR_FRAME
23657 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23658 TRACE_IRQS_OFF_DEBUG
23659 movq %rsp,%rdi /* pt_regs pointer */
23660 xorl %esi,%esi /* no error code */
23661 +#ifdef CONFIG_SMP
23662 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23663 + lea init_tss(%r13), %r13
23664 +#else
23665 + lea init_tss(%rip), %r13
23666 +#endif
23667 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23668 call \do_sym
23669 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23670 jmp paranoid_exit /* %ebx: no swapgs flag */
23671 CFI_ENDPROC
23672 -END(\sym)
23673 +ENDPROC(\sym)
23674 .endm
23675
23676 .macro errorentry sym do_sym
23677 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23678 call \do_sym
23679 jmp error_exit /* %ebx: no swapgs flag */
23680 CFI_ENDPROC
23681 -END(\sym)
23682 +ENDPROC(\sym)
23683 .endm
23684
23685 #ifdef CONFIG_TRACING
23686 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23687 call \do_sym
23688 jmp paranoid_exit /* %ebx: no swapgs flag */
23689 CFI_ENDPROC
23690 -END(\sym)
23691 +ENDPROC(\sym)
23692 .endm
23693
23694 zeroentry divide_error do_divide_error
23695 @@ -1336,9 +1819,10 @@ gs_change:
23696 2: mfence /* workaround */
23697 SWAPGS
23698 popfq_cfi
23699 + pax_force_retaddr
23700 ret
23701 CFI_ENDPROC
23702 -END(native_load_gs_index)
23703 +ENDPROC(native_load_gs_index)
23704
23705 _ASM_EXTABLE(gs_change,bad_gs)
23706 .section .fixup,"ax"
23707 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23708 CFI_DEF_CFA_REGISTER rsp
23709 CFI_ADJUST_CFA_OFFSET -8
23710 decl PER_CPU_VAR(irq_count)
23711 + pax_force_retaddr
23712 ret
23713 CFI_ENDPROC
23714 -END(do_softirq_own_stack)
23715 +ENDPROC(do_softirq_own_stack)
23716
23717 #ifdef CONFIG_XEN
23718 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23719 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23720 decl PER_CPU_VAR(irq_count)
23721 jmp error_exit
23722 CFI_ENDPROC
23723 -END(xen_do_hypervisor_callback)
23724 +ENDPROC(xen_do_hypervisor_callback)
23725
23726 /*
23727 * Hypervisor uses this for application faults while it executes.
23728 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23729 SAVE_ALL
23730 jmp error_exit
23731 CFI_ENDPROC
23732 -END(xen_failsafe_callback)
23733 +ENDPROC(xen_failsafe_callback)
23734
23735 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23736 xen_hvm_callback_vector xen_evtchn_do_upcall
23737 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23738 DEFAULT_FRAME
23739 DISABLE_INTERRUPTS(CLBR_NONE)
23740 TRACE_IRQS_OFF_DEBUG
23741 - testl %ebx,%ebx /* swapgs needed? */
23742 + testl $1,%ebx /* swapgs needed? */
23743 jnz paranoid_restore
23744 - testl $3,CS(%rsp)
23745 + testb $3,CS(%rsp)
23746 jnz paranoid_userspace
23747 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23748 + pax_exit_kernel
23749 + TRACE_IRQS_IRETQ 0
23750 + SWAPGS_UNSAFE_STACK
23751 + RESTORE_ALL 8
23752 + pax_force_retaddr_bts
23753 + jmp irq_return
23754 +#endif
23755 paranoid_swapgs:
23756 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23757 + pax_exit_kernel_user
23758 +#else
23759 + pax_exit_kernel
23760 +#endif
23761 TRACE_IRQS_IRETQ 0
23762 SWAPGS_UNSAFE_STACK
23763 RESTORE_ALL 8
23764 jmp irq_return
23765 paranoid_restore:
23766 + pax_exit_kernel
23767 TRACE_IRQS_IRETQ_DEBUG 0
23768 RESTORE_ALL 8
23769 + pax_force_retaddr_bts
23770 jmp irq_return
23771 paranoid_userspace:
23772 GET_THREAD_INFO(%rcx)
23773 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23774 TRACE_IRQS_OFF
23775 jmp paranoid_userspace
23776 CFI_ENDPROC
23777 -END(paranoid_exit)
23778 +ENDPROC(paranoid_exit)
23779
23780 /*
23781 * Exception entry point. This expects an error code/orig_rax on the stack.
23782 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23783 movq_cfi r14, R14+8
23784 movq_cfi r15, R15+8
23785 xorl %ebx,%ebx
23786 - testl $3,CS+8(%rsp)
23787 + testb $3,CS+8(%rsp)
23788 je error_kernelspace
23789 error_swapgs:
23790 SWAPGS
23791 error_sti:
23792 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23793 + testb $3, CS+8(%rsp)
23794 + jnz 1f
23795 + pax_enter_kernel
23796 + jmp 2f
23797 +1: pax_enter_kernel_user
23798 +2:
23799 +#else
23800 + pax_enter_kernel
23801 +#endif
23802 TRACE_IRQS_OFF
23803 + pax_force_retaddr
23804 ret
23805
23806 /*
23807 @@ -1616,7 +2127,7 @@ bstep_iret:
23808 movq %rcx,RIP+8(%rsp)
23809 jmp error_swapgs
23810 CFI_ENDPROC
23811 -END(error_entry)
23812 +ENDPROC(error_entry)
23813
23814
23815 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23816 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23817 DISABLE_INTERRUPTS(CLBR_NONE)
23818 TRACE_IRQS_OFF
23819 GET_THREAD_INFO(%rcx)
23820 - testl %eax,%eax
23821 + testl $1,%eax
23822 jne retint_kernel
23823 LOCKDEP_SYS_EXIT_IRQ
23824 movl TI_flags(%rcx),%edx
23825 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23826 jnz retint_careful
23827 jmp retint_swapgs
23828 CFI_ENDPROC
23829 -END(error_exit)
23830 +ENDPROC(error_exit)
23831
23832 /*
23833 * Test if a given stack is an NMI stack or not.
23834 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23835 * If %cs was not the kernel segment, then the NMI triggered in user
23836 * space, which means it is definitely not nested.
23837 */
23838 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23839 + je 1f
23840 cmpl $__KERNEL_CS, 16(%rsp)
23841 jne first_nmi
23842 -
23843 +1:
23844 /*
23845 * Check the special variable on the stack to see if NMIs are
23846 * executing.
23847 @@ -1730,8 +2243,7 @@ nested_nmi:
23848
23849 1:
23850 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23851 - leaq -1*8(%rsp), %rdx
23852 - movq %rdx, %rsp
23853 + subq $8, %rsp
23854 CFI_ADJUST_CFA_OFFSET 1*8
23855 leaq -10*8(%rsp), %rdx
23856 pushq_cfi $__KERNEL_DS
23857 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23858 CFI_RESTORE rdx
23859
23860 /* No need to check faults here */
23861 +# pax_force_retaddr_bts
23862 INTERRUPT_RETURN
23863
23864 CFI_RESTORE_STATE
23865 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23866 subq $ORIG_RAX-R15, %rsp
23867 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23868 /*
23869 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23870 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23871 * as we should not be calling schedule in NMI context.
23872 * Even with normal interrupts enabled. An NMI should not be
23873 * setting NEED_RESCHED or anything that normal interrupts and
23874 * exceptions might do.
23875 */
23876 - call save_paranoid
23877 + call save_paranoid_nmi
23878 DEFAULT_FRAME 0
23879
23880 /*
23881 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23882 * NMI itself takes a page fault, the page fault that was preempted
23883 * will read the information from the NMI page fault and not the
23884 * origin fault. Save it off and restore it if it changes.
23885 - * Use the r12 callee-saved register.
23886 + * Use the r13 callee-saved register.
23887 */
23888 - movq %cr2, %r12
23889 + movq %cr2, %r13
23890
23891 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23892 movq %rsp,%rdi
23893 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
23894
23895 /* Did the NMI take a page fault? Restore cr2 if it did */
23896 movq %cr2, %rcx
23897 - cmpq %rcx, %r12
23898 + cmpq %rcx, %r13
23899 je 1f
23900 - movq %r12, %cr2
23901 + movq %r13, %cr2
23902 1:
23903
23904 - testl %ebx,%ebx /* swapgs needed? */
23905 + testl $1,%ebx /* swapgs needed? */
23906 jnz nmi_restore
23907 nmi_swapgs:
23908 SWAPGS_UNSAFE_STACK
23909 nmi_restore:
23910 + pax_exit_kernel_nmi
23911 /* Pop the extra iret frame at once */
23912 RESTORE_ALL 6*8
23913 + testb $3, 8(%rsp)
23914 + jnz 1f
23915 + pax_force_retaddr_bts
23916 +1:
23917
23918 /* Clear the NMI executing stack variable */
23919 movq $0, 5*8(%rsp)
23920 jmp irq_return
23921 CFI_ENDPROC
23922 -END(nmi)
23923 +ENDPROC(nmi)
23924
23925 ENTRY(ignore_sysret)
23926 CFI_STARTPROC
23927 mov $-ENOSYS,%eax
23928 sysret
23929 CFI_ENDPROC
23930 -END(ignore_sysret)
23931 +ENDPROC(ignore_sysret)
23932
23933 /*
23934 * End of kprobes section
23935 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23936 index e625319..b9abb9d 100644
23937 --- a/arch/x86/kernel/ftrace.c
23938 +++ b/arch/x86/kernel/ftrace.c
23939 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23940 {
23941 unsigned char replaced[MCOUNT_INSN_SIZE];
23942
23943 + ip = ktla_ktva(ip);
23944 +
23945 /*
23946 * Note: Due to modules and __init, code can
23947 * disappear and change, we need to protect against faulting
23948 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23949 unsigned char old[MCOUNT_INSN_SIZE];
23950 int ret;
23951
23952 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23953 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23954
23955 ftrace_update_func = ip;
23956 /* Make sure the breakpoints see the ftrace_update_func update */
23957 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23958 * kernel identity mapping to modify code.
23959 */
23960 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23961 - ip = (unsigned long)__va(__pa_symbol(ip));
23962 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23963
23964 return probe_kernel_write((void *)ip, val, size);
23965 }
23966 @@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23967 unsigned char replaced[MCOUNT_INSN_SIZE];
23968 unsigned char brk = BREAKPOINT_INSTRUCTION;
23969
23970 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23971 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23972 return -EFAULT;
23973
23974 /* Make sure it is what we expect it to be */
23975 @@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23976 return ret;
23977
23978 fail_update:
23979 - probe_kernel_write((void *)ip, &old_code[0], 1);
23980 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23981 goto out;
23982 }
23983
23984 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23985 index 85126cc..1bbce17 100644
23986 --- a/arch/x86/kernel/head64.c
23987 +++ b/arch/x86/kernel/head64.c
23988 @@ -67,12 +67,12 @@ again:
23989 pgd = *pgd_p;
23990
23991 /*
23992 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23993 - * critical -- __PAGE_OFFSET would point us back into the dynamic
23994 + * The use of __early_va rather than __va here is critical:
23995 + * __va would point us back into the dynamic
23996 * range and we might end up looping forever...
23997 */
23998 if (pgd)
23999 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24000 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24001 else {
24002 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24003 reset_early_page_tables();
24004 @@ -82,13 +82,13 @@ again:
24005 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24006 for (i = 0; i < PTRS_PER_PUD; i++)
24007 pud_p[i] = 0;
24008 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24009 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24010 }
24011 pud_p += pud_index(address);
24012 pud = *pud_p;
24013
24014 if (pud)
24015 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24016 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24017 else {
24018 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24019 reset_early_page_tables();
24020 @@ -98,7 +98,7 @@ again:
24021 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24022 for (i = 0; i < PTRS_PER_PMD; i++)
24023 pmd_p[i] = 0;
24024 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24025 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24026 }
24027 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24028 pmd_p[pmd_index(address)] = pmd;
24029 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24030 if (console_loglevel == 10)
24031 early_printk("Kernel alive\n");
24032
24033 - clear_page(init_level4_pgt);
24034 /* set init_level4_pgt kernel high mapping*/
24035 init_level4_pgt[511] = early_level4_pgt[511];
24036
24037 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24038 index f36bd42..56ee1534 100644
24039 --- a/arch/x86/kernel/head_32.S
24040 +++ b/arch/x86/kernel/head_32.S
24041 @@ -26,6 +26,12 @@
24042 /* Physical address */
24043 #define pa(X) ((X) - __PAGE_OFFSET)
24044
24045 +#ifdef CONFIG_PAX_KERNEXEC
24046 +#define ta(X) (X)
24047 +#else
24048 +#define ta(X) ((X) - __PAGE_OFFSET)
24049 +#endif
24050 +
24051 /*
24052 * References to members of the new_cpu_data structure.
24053 */
24054 @@ -55,11 +61,7 @@
24055 * and small than max_low_pfn, otherwise will waste some page table entries
24056 */
24057
24058 -#if PTRS_PER_PMD > 1
24059 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24060 -#else
24061 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24062 -#endif
24063 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24064
24065 /* Number of possible pages in the lowmem region */
24066 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24067 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24068 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24069
24070 /*
24071 + * Real beginning of normal "text" segment
24072 + */
24073 +ENTRY(stext)
24074 +ENTRY(_stext)
24075 +
24076 +/*
24077 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24078 * %esi points to the real-mode code as a 32-bit pointer.
24079 * CS and DS must be 4 GB flat segments, but we don't depend on
24080 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24081 * can.
24082 */
24083 __HEAD
24084 +
24085 +#ifdef CONFIG_PAX_KERNEXEC
24086 + jmp startup_32
24087 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24088 +.fill PAGE_SIZE-5,1,0xcc
24089 +#endif
24090 +
24091 ENTRY(startup_32)
24092 movl pa(stack_start),%ecx
24093
24094 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24095 2:
24096 leal -__PAGE_OFFSET(%ecx),%esp
24097
24098 +#ifdef CONFIG_SMP
24099 + movl $pa(cpu_gdt_table),%edi
24100 + movl $__per_cpu_load,%eax
24101 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24102 + rorl $16,%eax
24103 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24104 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24105 + movl $__per_cpu_end - 1,%eax
24106 + subl $__per_cpu_start,%eax
24107 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24108 +#endif
24109 +
24110 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24111 + movl $NR_CPUS,%ecx
24112 + movl $pa(cpu_gdt_table),%edi
24113 +1:
24114 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24115 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24116 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24117 + addl $PAGE_SIZE_asm,%edi
24118 + loop 1b
24119 +#endif
24120 +
24121 +#ifdef CONFIG_PAX_KERNEXEC
24122 + movl $pa(boot_gdt),%edi
24123 + movl $__LOAD_PHYSICAL_ADDR,%eax
24124 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24125 + rorl $16,%eax
24126 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24127 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24128 + rorl $16,%eax
24129 +
24130 + ljmp $(__BOOT_CS),$1f
24131 +1:
24132 +
24133 + movl $NR_CPUS,%ecx
24134 + movl $pa(cpu_gdt_table),%edi
24135 + addl $__PAGE_OFFSET,%eax
24136 +1:
24137 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24138 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24139 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24140 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24141 + rorl $16,%eax
24142 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24143 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24144 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24145 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24146 + rorl $16,%eax
24147 + addl $PAGE_SIZE_asm,%edi
24148 + loop 1b
24149 +#endif
24150 +
24151 /*
24152 * Clear BSS first so that there are no surprises...
24153 */
24154 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24155 movl %eax, pa(max_pfn_mapped)
24156
24157 /* Do early initialization of the fixmap area */
24158 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24159 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24160 +#ifdef CONFIG_COMPAT_VDSO
24161 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24162 +#else
24163 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24164 +#endif
24165 #else /* Not PAE */
24166
24167 page_pde_offset = (__PAGE_OFFSET >> 20);
24168 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24169 movl %eax, pa(max_pfn_mapped)
24170
24171 /* Do early initialization of the fixmap area */
24172 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24173 - movl %eax,pa(initial_page_table+0xffc)
24174 +#ifdef CONFIG_COMPAT_VDSO
24175 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24176 +#else
24177 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24178 +#endif
24179 #endif
24180
24181 #ifdef CONFIG_PARAVIRT
24182 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24183 cmpl $num_subarch_entries, %eax
24184 jae bad_subarch
24185
24186 - movl pa(subarch_entries)(,%eax,4), %eax
24187 - subl $__PAGE_OFFSET, %eax
24188 - jmp *%eax
24189 + jmp *pa(subarch_entries)(,%eax,4)
24190
24191 bad_subarch:
24192 WEAK(lguest_entry)
24193 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24194 __INITDATA
24195
24196 subarch_entries:
24197 - .long default_entry /* normal x86/PC */
24198 - .long lguest_entry /* lguest hypervisor */
24199 - .long xen_entry /* Xen hypervisor */
24200 - .long default_entry /* Moorestown MID */
24201 + .long ta(default_entry) /* normal x86/PC */
24202 + .long ta(lguest_entry) /* lguest hypervisor */
24203 + .long ta(xen_entry) /* Xen hypervisor */
24204 + .long ta(default_entry) /* Moorestown MID */
24205 num_subarch_entries = (. - subarch_entries) / 4
24206 .previous
24207 #else
24208 @@ -354,6 +426,7 @@ default_entry:
24209 movl pa(mmu_cr4_features),%eax
24210 movl %eax,%cr4
24211
24212 +#ifdef CONFIG_X86_PAE
24213 testb $X86_CR4_PAE, %al # check if PAE is enabled
24214 jz enable_paging
24215
24216 @@ -382,6 +455,9 @@ default_entry:
24217 /* Make changes effective */
24218 wrmsr
24219
24220 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24221 +#endif
24222 +
24223 enable_paging:
24224
24225 /*
24226 @@ -449,14 +525,20 @@ is486:
24227 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24228 movl %eax,%ss # after changing gdt.
24229
24230 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24231 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24232 movl %eax,%ds
24233 movl %eax,%es
24234
24235 movl $(__KERNEL_PERCPU), %eax
24236 movl %eax,%fs # set this cpu's percpu
24237
24238 +#ifdef CONFIG_CC_STACKPROTECTOR
24239 movl $(__KERNEL_STACK_CANARY),%eax
24240 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24241 + movl $(__USER_DS),%eax
24242 +#else
24243 + xorl %eax,%eax
24244 +#endif
24245 movl %eax,%gs
24246
24247 xorl %eax,%eax # Clear LDT
24248 @@ -512,8 +594,11 @@ setup_once:
24249 * relocation. Manually set base address in stack canary
24250 * segment descriptor.
24251 */
24252 - movl $gdt_page,%eax
24253 + movl $cpu_gdt_table,%eax
24254 movl $stack_canary,%ecx
24255 +#ifdef CONFIG_SMP
24256 + addl $__per_cpu_load,%ecx
24257 +#endif
24258 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24259 shrl $16, %ecx
24260 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24261 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24262 cmpl $2,(%esp) # X86_TRAP_NMI
24263 je is_nmi # Ignore NMI
24264
24265 - cmpl $2,%ss:early_recursion_flag
24266 + cmpl $1,%ss:early_recursion_flag
24267 je hlt_loop
24268 incl %ss:early_recursion_flag
24269
24270 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24271 pushl (20+6*4)(%esp) /* trapno */
24272 pushl $fault_msg
24273 call printk
24274 -#endif
24275 call dump_stack
24276 +#endif
24277 hlt_loop:
24278 hlt
24279 jmp hlt_loop
24280 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24281 /* This is the default interrupt "handler" :-) */
24282 ALIGN
24283 ignore_int:
24284 - cld
24285 #ifdef CONFIG_PRINTK
24286 + cmpl $2,%ss:early_recursion_flag
24287 + je hlt_loop
24288 + incl %ss:early_recursion_flag
24289 + cld
24290 pushl %eax
24291 pushl %ecx
24292 pushl %edx
24293 @@ -617,9 +705,6 @@ ignore_int:
24294 movl $(__KERNEL_DS),%eax
24295 movl %eax,%ds
24296 movl %eax,%es
24297 - cmpl $2,early_recursion_flag
24298 - je hlt_loop
24299 - incl early_recursion_flag
24300 pushl 16(%esp)
24301 pushl 24(%esp)
24302 pushl 32(%esp)
24303 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24304 /*
24305 * BSS section
24306 */
24307 -__PAGE_ALIGNED_BSS
24308 - .align PAGE_SIZE
24309 #ifdef CONFIG_X86_PAE
24310 +.section .initial_pg_pmd,"a",@progbits
24311 initial_pg_pmd:
24312 .fill 1024*KPMDS,4,0
24313 #else
24314 +.section .initial_page_table,"a",@progbits
24315 ENTRY(initial_page_table)
24316 .fill 1024,4,0
24317 #endif
24318 +.section .initial_pg_fixmap,"a",@progbits
24319 initial_pg_fixmap:
24320 .fill 1024,4,0
24321 +.section .empty_zero_page,"a",@progbits
24322 ENTRY(empty_zero_page)
24323 .fill 4096,1,0
24324 +.section .swapper_pg_dir,"a",@progbits
24325 ENTRY(swapper_pg_dir)
24326 +#ifdef CONFIG_X86_PAE
24327 + .fill 4,8,0
24328 +#else
24329 .fill 1024,4,0
24330 +#endif
24331
24332 /*
24333 * This starts the data section.
24334 */
24335 #ifdef CONFIG_X86_PAE
24336 -__PAGE_ALIGNED_DATA
24337 - /* Page-aligned for the benefit of paravirt? */
24338 - .align PAGE_SIZE
24339 +.section .initial_page_table,"a",@progbits
24340 ENTRY(initial_page_table)
24341 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24342 # if KPMDS == 3
24343 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24344 # error "Kernel PMDs should be 1, 2 or 3"
24345 # endif
24346 .align PAGE_SIZE /* needs to be page-sized too */
24347 +
24348 +#ifdef CONFIG_PAX_PER_CPU_PGD
24349 +ENTRY(cpu_pgd)
24350 + .rept 2*NR_CPUS
24351 + .fill 4,8,0
24352 + .endr
24353 +#endif
24354 +
24355 #endif
24356
24357 .data
24358 .balign 4
24359 ENTRY(stack_start)
24360 - .long init_thread_union+THREAD_SIZE
24361 + .long init_thread_union+THREAD_SIZE-8
24362
24363 __INITRODATA
24364 int_msg:
24365 @@ -727,7 +825,7 @@ fault_msg:
24366 * segment size, and 32-bit linear address value:
24367 */
24368
24369 - .data
24370 +.section .rodata,"a",@progbits
24371 .globl boot_gdt_descr
24372 .globl idt_descr
24373
24374 @@ -736,7 +834,7 @@ fault_msg:
24375 .word 0 # 32 bit align gdt_desc.address
24376 boot_gdt_descr:
24377 .word __BOOT_DS+7
24378 - .long boot_gdt - __PAGE_OFFSET
24379 + .long pa(boot_gdt)
24380
24381 .word 0 # 32-bit align idt_desc.address
24382 idt_descr:
24383 @@ -747,7 +845,7 @@ idt_descr:
24384 .word 0 # 32 bit align gdt_desc.address
24385 ENTRY(early_gdt_descr)
24386 .word GDT_ENTRIES*8-1
24387 - .long gdt_page /* Overwritten for secondary CPUs */
24388 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24389
24390 /*
24391 * The boot_gdt must mirror the equivalent in setup.S and is
24392 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24393 .align L1_CACHE_BYTES
24394 ENTRY(boot_gdt)
24395 .fill GDT_ENTRY_BOOT_CS,8,0
24396 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24397 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24398 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24399 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24400 +
24401 + .align PAGE_SIZE_asm
24402 +ENTRY(cpu_gdt_table)
24403 + .rept NR_CPUS
24404 + .quad 0x0000000000000000 /* NULL descriptor */
24405 + .quad 0x0000000000000000 /* 0x0b reserved */
24406 + .quad 0x0000000000000000 /* 0x13 reserved */
24407 + .quad 0x0000000000000000 /* 0x1b reserved */
24408 +
24409 +#ifdef CONFIG_PAX_KERNEXEC
24410 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24411 +#else
24412 + .quad 0x0000000000000000 /* 0x20 unused */
24413 +#endif
24414 +
24415 + .quad 0x0000000000000000 /* 0x28 unused */
24416 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24417 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24418 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24419 + .quad 0x0000000000000000 /* 0x4b reserved */
24420 + .quad 0x0000000000000000 /* 0x53 reserved */
24421 + .quad 0x0000000000000000 /* 0x5b reserved */
24422 +
24423 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24424 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24425 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24426 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24427 +
24428 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24429 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24430 +
24431 + /*
24432 + * Segments used for calling PnP BIOS have byte granularity.
24433 + * The code segments and data segments have fixed 64k limits,
24434 + * the transfer segment sizes are set at run time.
24435 + */
24436 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24437 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24438 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24439 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24440 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24441 +
24442 + /*
24443 + * The APM segments have byte granularity and their bases
24444 + * are set at run time. All have 64k limits.
24445 + */
24446 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24447 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24448 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24449 +
24450 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24451 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24452 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24453 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24454 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24455 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24456 +
24457 + /* Be sure this is zeroed to avoid false validations in Xen */
24458 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24459 + .endr
24460 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24461 index a468c0a..c7dec74 100644
24462 --- a/arch/x86/kernel/head_64.S
24463 +++ b/arch/x86/kernel/head_64.S
24464 @@ -20,6 +20,8 @@
24465 #include <asm/processor-flags.h>
24466 #include <asm/percpu.h>
24467 #include <asm/nops.h>
24468 +#include <asm/cpufeature.h>
24469 +#include <asm/alternative-asm.h>
24470
24471 #ifdef CONFIG_PARAVIRT
24472 #include <asm/asm-offsets.h>
24473 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24474 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24475 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24476 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24477 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24478 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24479 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24480 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24481 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24482 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24483
24484 .text
24485 __HEAD
24486 @@ -89,11 +97,24 @@ startup_64:
24487 * Fixup the physical addresses in the page table
24488 */
24489 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24490 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24491 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24492 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24493 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24494 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24495
24496 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24497 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24498 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24499 +#ifndef CONFIG_XEN
24500 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24501 +#endif
24502 +
24503 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24504 +
24505 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24506 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24507
24508 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24509 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24510
24511 /*
24512 * Set up the identity mapping for the switchover. These
24513 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24514 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24515 1:
24516
24517 - /* Enable PAE mode and PGE */
24518 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24519 + /* Enable PAE mode and PSE/PGE */
24520 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24521 movq %rcx, %cr4
24522
24523 /* Setup early boot stage 4 level pagetables. */
24524 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24525 movl $MSR_EFER, %ecx
24526 rdmsr
24527 btsl $_EFER_SCE, %eax /* Enable System Call */
24528 - btl $20,%edi /* No Execute supported? */
24529 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24530 jnc 1f
24531 btsl $_EFER_NX, %eax
24532 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24533 +#ifndef CONFIG_EFI
24534 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24535 +#endif
24536 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24537 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24538 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24539 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24540 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24541 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24542 1: wrmsr /* Make changes effective */
24543
24544 /* Setup cr0 */
24545 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24546 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24547 * address given in m16:64.
24548 */
24549 + pax_set_fptr_mask
24550 movq initial_code(%rip),%rax
24551 pushq $0 # fake return address to stop unwinder
24552 pushq $__KERNEL_CS # set correct cs
24553 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24554 .quad INIT_PER_CPU_VAR(irq_stack_union)
24555
24556 GLOBAL(stack_start)
24557 - .quad init_thread_union+THREAD_SIZE-8
24558 + .quad init_thread_union+THREAD_SIZE-16
24559 .word 0
24560 __FINITDATA
24561
24562 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24563 call dump_stack
24564 #ifdef CONFIG_KALLSYMS
24565 leaq early_idt_ripmsg(%rip),%rdi
24566 - movq 40(%rsp),%rsi # %rip again
24567 + movq 88(%rsp),%rsi # %rip again
24568 call __print_symbol
24569 #endif
24570 #endif /* EARLY_PRINTK */
24571 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24572 early_recursion_flag:
24573 .long 0
24574
24575 + .section .rodata,"a",@progbits
24576 #ifdef CONFIG_EARLY_PRINTK
24577 early_idt_msg:
24578 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24579 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24580 NEXT_PAGE(early_dynamic_pgts)
24581 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24582
24583 - .data
24584 + .section .rodata,"a",@progbits
24585
24586 -#ifndef CONFIG_XEN
24587 NEXT_PAGE(init_level4_pgt)
24588 - .fill 512,8,0
24589 -#else
24590 -NEXT_PAGE(init_level4_pgt)
24591 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24592 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24593 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24594 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24595 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24596 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24597 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24598 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24599 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24600 .org init_level4_pgt + L4_START_KERNEL*8, 0
24601 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24602 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24603
24604 +#ifdef CONFIG_PAX_PER_CPU_PGD
24605 +NEXT_PAGE(cpu_pgd)
24606 + .rept 2*NR_CPUS
24607 + .fill 512,8,0
24608 + .endr
24609 +#endif
24610 +
24611 NEXT_PAGE(level3_ident_pgt)
24612 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24613 +#ifdef CONFIG_XEN
24614 .fill 511, 8, 0
24615 +#else
24616 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24617 + .fill 510,8,0
24618 +#endif
24619 +
24620 +NEXT_PAGE(level3_vmalloc_start_pgt)
24621 + .fill 512,8,0
24622 +
24623 +NEXT_PAGE(level3_vmalloc_end_pgt)
24624 + .fill 512,8,0
24625 +
24626 +NEXT_PAGE(level3_vmemmap_pgt)
24627 + .fill L3_VMEMMAP_START,8,0
24628 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24629 +
24630 NEXT_PAGE(level2_ident_pgt)
24631 - /* Since I easily can, map the first 1G.
24632 + /* Since I easily can, map the first 2G.
24633 * Don't set NX because code runs from these pages.
24634 */
24635 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24636 -#endif
24637 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24638
24639 NEXT_PAGE(level3_kernel_pgt)
24640 .fill L3_START_KERNEL,8,0
24641 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24642 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24643 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24644
24645 +NEXT_PAGE(level2_vmemmap_pgt)
24646 + .fill 512,8,0
24647 +
24648 NEXT_PAGE(level2_kernel_pgt)
24649 /*
24650 * 512 MB kernel mapping. We spend a full page on this pagetable
24651 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24652 NEXT_PAGE(level2_fixmap_pgt)
24653 .fill 506,8,0
24654 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24655 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24656 - .fill 5,8,0
24657 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24658 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24659 + .fill 4,8,0
24660
24661 NEXT_PAGE(level1_fixmap_pgt)
24662 .fill 512,8,0
24663
24664 +NEXT_PAGE(level1_vsyscall_pgt)
24665 + .fill 512,8,0
24666 +
24667 #undef PMDS
24668
24669 - .data
24670 + .align PAGE_SIZE
24671 +ENTRY(cpu_gdt_table)
24672 + .rept NR_CPUS
24673 + .quad 0x0000000000000000 /* NULL descriptor */
24674 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24675 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24676 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24677 + .quad 0x00cffb000000ffff /* __USER32_CS */
24678 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24679 + .quad 0x00affb000000ffff /* __USER_CS */
24680 +
24681 +#ifdef CONFIG_PAX_KERNEXEC
24682 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24683 +#else
24684 + .quad 0x0 /* unused */
24685 +#endif
24686 +
24687 + .quad 0,0 /* TSS */
24688 + .quad 0,0 /* LDT */
24689 + .quad 0,0,0 /* three TLS descriptors */
24690 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24691 + /* asm/segment.h:GDT_ENTRIES must match this */
24692 +
24693 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24694 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24695 +#else
24696 + .quad 0x0 /* unused */
24697 +#endif
24698 +
24699 + /* zero the remaining page */
24700 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24701 + .endr
24702 +
24703 .align 16
24704 .globl early_gdt_descr
24705 early_gdt_descr:
24706 .word GDT_ENTRIES*8-1
24707 early_gdt_descr_base:
24708 - .quad INIT_PER_CPU_VAR(gdt_page)
24709 + .quad cpu_gdt_table
24710
24711 ENTRY(phys_base)
24712 /* This must match the first entry in level2_kernel_pgt */
24713 .quad 0x0000000000000000
24714
24715 #include "../../x86/xen/xen-head.S"
24716 -
24717 - __PAGE_ALIGNED_BSS
24718 +
24719 + .section .rodata,"a",@progbits
24720 NEXT_PAGE(empty_zero_page)
24721 .skip PAGE_SIZE
24722 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24723 index 05fd74f..c3548b1 100644
24724 --- a/arch/x86/kernel/i386_ksyms_32.c
24725 +++ b/arch/x86/kernel/i386_ksyms_32.c
24726 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24727 EXPORT_SYMBOL(cmpxchg8b_emu);
24728 #endif
24729
24730 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24731 +
24732 /* Networking helper routines. */
24733 EXPORT_SYMBOL(csum_partial_copy_generic);
24734 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24735 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24736
24737 EXPORT_SYMBOL(__get_user_1);
24738 EXPORT_SYMBOL(__get_user_2);
24739 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24740 EXPORT_SYMBOL(___preempt_schedule_context);
24741 #endif
24742 #endif
24743 +
24744 +#ifdef CONFIG_PAX_KERNEXEC
24745 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24746 +#endif
24747 +
24748 +#ifdef CONFIG_PAX_PER_CPU_PGD
24749 +EXPORT_SYMBOL(cpu_pgd);
24750 +#endif
24751 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24752 index d5dd808..b6432cf 100644
24753 --- a/arch/x86/kernel/i387.c
24754 +++ b/arch/x86/kernel/i387.c
24755 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24756 static inline bool interrupted_user_mode(void)
24757 {
24758 struct pt_regs *regs = get_irq_regs();
24759 - return regs && user_mode_vm(regs);
24760 + return regs && user_mode(regs);
24761 }
24762
24763 /*
24764 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24765 index 2e977b5..5f2c273 100644
24766 --- a/arch/x86/kernel/i8259.c
24767 +++ b/arch/x86/kernel/i8259.c
24768 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24769 static void make_8259A_irq(unsigned int irq)
24770 {
24771 disable_irq_nosync(irq);
24772 - io_apic_irqs &= ~(1<<irq);
24773 + io_apic_irqs &= ~(1UL<<irq);
24774 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24775 i8259A_chip.name);
24776 enable_irq(irq);
24777 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24778 "spurious 8259A interrupt: IRQ%d.\n", irq);
24779 spurious_irq_mask |= irqmask;
24780 }
24781 - atomic_inc(&irq_err_count);
24782 + atomic_inc_unchecked(&irq_err_count);
24783 /*
24784 * Theoretically we do not have to handle this IRQ,
24785 * but in Linux this does not cause problems and is
24786 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24787 /* (slave's support for AEOI in flat mode is to be investigated) */
24788 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24789
24790 + pax_open_kernel();
24791 if (auto_eoi)
24792 /*
24793 * In AEOI mode we just have to mask the interrupt
24794 * when acking.
24795 */
24796 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24797 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24798 else
24799 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24800 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24801 + pax_close_kernel();
24802
24803 udelay(100); /* wait for 8259A to initialize */
24804
24805 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24806 index a979b5b..1d6db75 100644
24807 --- a/arch/x86/kernel/io_delay.c
24808 +++ b/arch/x86/kernel/io_delay.c
24809 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24810 * Quirk table for systems that misbehave (lock up, etc.) if port
24811 * 0x80 is used:
24812 */
24813 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24814 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24815 {
24816 .callback = dmi_io_delay_0xed_port,
24817 .ident = "Compaq Presario V6000",
24818 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24819 index 4ddaf66..49d5c18 100644
24820 --- a/arch/x86/kernel/ioport.c
24821 +++ b/arch/x86/kernel/ioport.c
24822 @@ -6,6 +6,7 @@
24823 #include <linux/sched.h>
24824 #include <linux/kernel.h>
24825 #include <linux/capability.h>
24826 +#include <linux/security.h>
24827 #include <linux/errno.h>
24828 #include <linux/types.h>
24829 #include <linux/ioport.h>
24830 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24831 return -EINVAL;
24832 if (turn_on && !capable(CAP_SYS_RAWIO))
24833 return -EPERM;
24834 +#ifdef CONFIG_GRKERNSEC_IO
24835 + if (turn_on && grsec_disable_privio) {
24836 + gr_handle_ioperm();
24837 + return -ENODEV;
24838 + }
24839 +#endif
24840
24841 /*
24842 * If it's the first ioperm() call in this thread's lifetime, set the
24843 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24844 * because the ->io_bitmap_max value must match the bitmap
24845 * contents:
24846 */
24847 - tss = &per_cpu(init_tss, get_cpu());
24848 + tss = init_tss + get_cpu();
24849
24850 if (turn_on)
24851 bitmap_clear(t->io_bitmap_ptr, from, num);
24852 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24853 if (level > old) {
24854 if (!capable(CAP_SYS_RAWIO))
24855 return -EPERM;
24856 +#ifdef CONFIG_GRKERNSEC_IO
24857 + if (grsec_disable_privio) {
24858 + gr_handle_iopl();
24859 + return -ENODEV;
24860 + }
24861 +#endif
24862 }
24863 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24864 t->iopl = level << 12;
24865 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24866 index 22d0687..e07b2a5 100644
24867 --- a/arch/x86/kernel/irq.c
24868 +++ b/arch/x86/kernel/irq.c
24869 @@ -21,7 +21,7 @@
24870 #define CREATE_TRACE_POINTS
24871 #include <asm/trace/irq_vectors.h>
24872
24873 -atomic_t irq_err_count;
24874 +atomic_unchecked_t irq_err_count;
24875
24876 /* Function pointer for generic interrupt vector handling */
24877 void (*x86_platform_ipi_callback)(void) = NULL;
24878 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24879 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24880 seq_printf(p, " Machine check polls\n");
24881 #endif
24882 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24883 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24884 #if defined(CONFIG_X86_IO_APIC)
24885 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24886 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24887 #endif
24888 return 0;
24889 }
24890 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24891
24892 u64 arch_irq_stat(void)
24893 {
24894 - u64 sum = atomic_read(&irq_err_count);
24895 + u64 sum = atomic_read_unchecked(&irq_err_count);
24896 return sum;
24897 }
24898
24899 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24900 index d7fcbed..1f747f7 100644
24901 --- a/arch/x86/kernel/irq_32.c
24902 +++ b/arch/x86/kernel/irq_32.c
24903 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24904 __asm__ __volatile__("andl %%esp,%0" :
24905 "=r" (sp) : "0" (THREAD_SIZE - 1));
24906
24907 - return sp < (sizeof(struct thread_info) + STACK_WARN);
24908 + return sp < STACK_WARN;
24909 }
24910
24911 static void print_stack_overflow(void)
24912 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24913 * per-CPU IRQ handling contexts (thread information and stack)
24914 */
24915 union irq_ctx {
24916 - struct thread_info tinfo;
24917 - u32 stack[THREAD_SIZE/sizeof(u32)];
24918 + unsigned long previous_esp;
24919 + u32 stack[THREAD_SIZE/sizeof(u32)];
24920 } __attribute__((aligned(THREAD_SIZE)));
24921
24922 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24923 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24924 static inline int
24925 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24926 {
24927 - union irq_ctx *curctx, *irqctx;
24928 + union irq_ctx *irqctx;
24929 u32 *isp, arg1, arg2;
24930
24931 - curctx = (union irq_ctx *) current_thread_info();
24932 irqctx = __this_cpu_read(hardirq_ctx);
24933
24934 /*
24935 @@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24936 * handler) we can't do that and just have to keep using the
24937 * current stack (which is the irq stack already after all)
24938 */
24939 - if (unlikely(curctx == irqctx))
24940 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24941 return 0;
24942
24943 /* build the stack frame on the IRQ stack */
24944 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24945 - irqctx->tinfo.task = curctx->tinfo.task;
24946 - irqctx->tinfo.previous_esp = current_stack_pointer;
24947 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24948 + irqctx->previous_esp = current_stack_pointer;
24949 +
24950 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24951 + __set_fs(MAKE_MM_SEG(0));
24952 +#endif
24953
24954 if (unlikely(overflow))
24955 call_on_stack(print_stack_overflow, isp);
24956 @@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24957 : "0" (irq), "1" (desc), "2" (isp),
24958 "D" (desc->handle_irq)
24959 : "memory", "cc", "ecx");
24960 +
24961 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24962 + __set_fs(current_thread_info()->addr_limit);
24963 +#endif
24964 +
24965 return 1;
24966 }
24967
24968 @@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24969 */
24970 void irq_ctx_init(int cpu)
24971 {
24972 - union irq_ctx *irqctx;
24973 -
24974 if (per_cpu(hardirq_ctx, cpu))
24975 return;
24976
24977 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24978 - THREADINFO_GFP,
24979 - THREAD_SIZE_ORDER));
24980 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24981 - irqctx->tinfo.cpu = cpu;
24982 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24983 -
24984 - per_cpu(hardirq_ctx, cpu) = irqctx;
24985 -
24986 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24987 - THREADINFO_GFP,
24988 - THREAD_SIZE_ORDER));
24989 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24990 - irqctx->tinfo.cpu = cpu;
24991 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24992 -
24993 - per_cpu(softirq_ctx, cpu) = irqctx;
24994 -
24995 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24996 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24997 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24998 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24999 }
25000
25001 void do_softirq_own_stack(void)
25002 {
25003 - struct thread_info *curctx;
25004 union irq_ctx *irqctx;
25005 u32 *isp;
25006
25007 - curctx = current_thread_info();
25008 irqctx = __this_cpu_read(softirq_ctx);
25009 - irqctx->tinfo.task = curctx->task;
25010 - irqctx->tinfo.previous_esp = current_stack_pointer;
25011 + irqctx->previous_esp = current_stack_pointer;
25012
25013 /* build the stack frame on the softirq stack */
25014 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25015 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25016 +
25017 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25018 + __set_fs(MAKE_MM_SEG(0));
25019 +#endif
25020
25021 call_on_stack(__do_softirq, isp);
25022 +
25023 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25024 + __set_fs(current_thread_info()->addr_limit);
25025 +#endif
25026 +
25027 }
25028
25029 bool handle_irq(unsigned irq, struct pt_regs *regs)
25030 @@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25031 if (unlikely(!desc))
25032 return false;
25033
25034 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25035 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25036 if (unlikely(overflow))
25037 print_stack_overflow();
25038 desc->handle_irq(irq, desc);
25039 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25040 index 4d1c746..232961d 100644
25041 --- a/arch/x86/kernel/irq_64.c
25042 +++ b/arch/x86/kernel/irq_64.c
25043 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25044 u64 estack_top, estack_bottom;
25045 u64 curbase = (u64)task_stack_page(current);
25046
25047 - if (user_mode_vm(regs))
25048 + if (user_mode(regs))
25049 return;
25050
25051 if (regs->sp >= curbase + sizeof(struct thread_info) +
25052 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25053 index 26d5a55..a01160a 100644
25054 --- a/arch/x86/kernel/jump_label.c
25055 +++ b/arch/x86/kernel/jump_label.c
25056 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25057 * Jump label is enabled for the first time.
25058 * So we expect a default_nop...
25059 */
25060 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25061 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25062 != 0))
25063 bug_at((void *)entry->code, __LINE__);
25064 } else {
25065 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25066 * ...otherwise expect an ideal_nop. Otherwise
25067 * something went horribly wrong.
25068 */
25069 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25070 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25071 != 0))
25072 bug_at((void *)entry->code, __LINE__);
25073 }
25074 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25075 * are converting the default nop to the ideal nop.
25076 */
25077 if (init) {
25078 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25079 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25080 bug_at((void *)entry->code, __LINE__);
25081 } else {
25082 code.jump = 0xe9;
25083 code.offset = entry->target -
25084 (entry->code + JUMP_LABEL_NOP_SIZE);
25085 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25086 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25087 bug_at((void *)entry->code, __LINE__);
25088 }
25089 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25090 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25091 index 836f832..a8bda67 100644
25092 --- a/arch/x86/kernel/kgdb.c
25093 +++ b/arch/x86/kernel/kgdb.c
25094 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25095 #ifdef CONFIG_X86_32
25096 switch (regno) {
25097 case GDB_SS:
25098 - if (!user_mode_vm(regs))
25099 + if (!user_mode(regs))
25100 *(unsigned long *)mem = __KERNEL_DS;
25101 break;
25102 case GDB_SP:
25103 - if (!user_mode_vm(regs))
25104 + if (!user_mode(regs))
25105 *(unsigned long *)mem = kernel_stack_pointer(regs);
25106 break;
25107 case GDB_GS:
25108 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
25109 bp->attr.bp_addr = breakinfo[breakno].addr;
25110 bp->attr.bp_len = breakinfo[breakno].len;
25111 bp->attr.bp_type = breakinfo[breakno].type;
25112 - info->address = breakinfo[breakno].addr;
25113 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25114 + info->address = ktla_ktva(breakinfo[breakno].addr);
25115 + else
25116 + info->address = breakinfo[breakno].addr;
25117 info->len = breakinfo[breakno].len;
25118 info->type = breakinfo[breakno].type;
25119 val = arch_install_hw_breakpoint(bp);
25120 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25121 case 'k':
25122 /* clear the trace bit */
25123 linux_regs->flags &= ~X86_EFLAGS_TF;
25124 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25125 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25126
25127 /* set the trace bit if we're stepping */
25128 if (remcomInBuffer[0] == 's') {
25129 linux_regs->flags |= X86_EFLAGS_TF;
25130 - atomic_set(&kgdb_cpu_doing_single_step,
25131 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25132 raw_smp_processor_id());
25133 }
25134
25135 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25136
25137 switch (cmd) {
25138 case DIE_DEBUG:
25139 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25140 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25141 if (user_mode(regs))
25142 return single_step_cont(regs, args);
25143 break;
25144 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25145 #endif /* CONFIG_DEBUG_RODATA */
25146
25147 bpt->type = BP_BREAKPOINT;
25148 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25149 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25150 BREAK_INSTR_SIZE);
25151 if (err)
25152 return err;
25153 - err = probe_kernel_write((char *)bpt->bpt_addr,
25154 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25155 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25156 #ifdef CONFIG_DEBUG_RODATA
25157 if (!err)
25158 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25159 return -EBUSY;
25160 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25161 BREAK_INSTR_SIZE);
25162 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25163 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25164 if (err)
25165 return err;
25166 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25167 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25168 if (mutex_is_locked(&text_mutex))
25169 goto knl_write;
25170 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25171 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25172 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25173 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25174 goto knl_write;
25175 return err;
25176 knl_write:
25177 #endif /* CONFIG_DEBUG_RODATA */
25178 - return probe_kernel_write((char *)bpt->bpt_addr,
25179 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25180 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25181 }
25182
25183 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25184 index 79a3f96..6ba030a 100644
25185 --- a/arch/x86/kernel/kprobes/core.c
25186 +++ b/arch/x86/kernel/kprobes/core.c
25187 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25188 s32 raddr;
25189 } __packed *insn;
25190
25191 - insn = (struct __arch_relative_insn *)from;
25192 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25193 +
25194 + pax_open_kernel();
25195 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25196 insn->op = op;
25197 + pax_close_kernel();
25198 }
25199
25200 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25201 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25202 kprobe_opcode_t opcode;
25203 kprobe_opcode_t *orig_opcodes = opcodes;
25204
25205 - if (search_exception_tables((unsigned long)opcodes))
25206 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25207 return 0; /* Page fault may occur on this address. */
25208
25209 retry:
25210 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25211 * for the first byte, we can recover the original instruction
25212 * from it and kp->opcode.
25213 */
25214 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25215 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25216 buf[0] = kp->opcode;
25217 - return (unsigned long)buf;
25218 + return ktva_ktla((unsigned long)buf);
25219 }
25220
25221 /*
25222 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25223 /* Another subsystem puts a breakpoint, failed to recover */
25224 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25225 return 0;
25226 + pax_open_kernel();
25227 memcpy(dest, insn.kaddr, insn.length);
25228 + pax_close_kernel();
25229
25230 #ifdef CONFIG_X86_64
25231 if (insn_rip_relative(&insn)) {
25232 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25233 return 0;
25234 }
25235 disp = (u8 *) dest + insn_offset_displacement(&insn);
25236 + pax_open_kernel();
25237 *(s32 *) disp = (s32) newdisp;
25238 + pax_close_kernel();
25239 }
25240 #endif
25241 return insn.length;
25242 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25243 * nor set current_kprobe, because it doesn't use single
25244 * stepping.
25245 */
25246 - regs->ip = (unsigned long)p->ainsn.insn;
25247 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25248 preempt_enable_no_resched();
25249 return;
25250 }
25251 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25252 regs->flags &= ~X86_EFLAGS_IF;
25253 /* single step inline if the instruction is an int3 */
25254 if (p->opcode == BREAKPOINT_INSTRUCTION)
25255 - regs->ip = (unsigned long)p->addr;
25256 + regs->ip = ktla_ktva((unsigned long)p->addr);
25257 else
25258 - regs->ip = (unsigned long)p->ainsn.insn;
25259 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25260 }
25261
25262 /*
25263 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25264 setup_singlestep(p, regs, kcb, 0);
25265 return 1;
25266 }
25267 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25268 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25269 /*
25270 * The breakpoint instruction was removed right
25271 * after we hit it. Another cpu has removed
25272 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25273 " movq %rax, 152(%rsp)\n"
25274 RESTORE_REGS_STRING
25275 " popfq\n"
25276 +#ifdef KERNEXEC_PLUGIN
25277 + " btsq $63,(%rsp)\n"
25278 +#endif
25279 #else
25280 " pushf\n"
25281 SAVE_REGS_STRING
25282 @@ -779,7 +789,7 @@ static void __kprobes
25283 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25284 {
25285 unsigned long *tos = stack_addr(regs);
25286 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25287 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25288 unsigned long orig_ip = (unsigned long)p->addr;
25289 kprobe_opcode_t *insn = p->ainsn.insn;
25290
25291 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25292 struct die_args *args = data;
25293 int ret = NOTIFY_DONE;
25294
25295 - if (args->regs && user_mode_vm(args->regs))
25296 + if (args->regs && user_mode(args->regs))
25297 return ret;
25298
25299 switch (val) {
25300 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25301 index 898160b..758cde8 100644
25302 --- a/arch/x86/kernel/kprobes/opt.c
25303 +++ b/arch/x86/kernel/kprobes/opt.c
25304 @@ -79,6 +79,7 @@ found:
25305 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25306 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25307 {
25308 + pax_open_kernel();
25309 #ifdef CONFIG_X86_64
25310 *addr++ = 0x48;
25311 *addr++ = 0xbf;
25312 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25313 *addr++ = 0xb8;
25314 #endif
25315 *(unsigned long *)addr = val;
25316 + pax_close_kernel();
25317 }
25318
25319 asm (
25320 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25321 * Verify if the address gap is in 2GB range, because this uses
25322 * a relative jump.
25323 */
25324 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25325 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25326 if (abs(rel) > 0x7fffffff)
25327 return -ERANGE;
25328
25329 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25330 op->optinsn.size = ret;
25331
25332 /* Copy arch-dep-instance from template */
25333 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25334 + pax_open_kernel();
25335 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25336 + pax_close_kernel();
25337
25338 /* Set probe information */
25339 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25340
25341 /* Set probe function call */
25342 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25343 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25344
25345 /* Set returning jmp instruction at the tail of out-of-line buffer */
25346 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25347 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25348 (u8 *)op->kp.addr + op->optinsn.size);
25349
25350 flush_icache_range((unsigned long) buf,
25351 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25352 WARN_ON(kprobe_disabled(&op->kp));
25353
25354 /* Backup instructions which will be replaced by jump address */
25355 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25356 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25357 RELATIVE_ADDR_SIZE);
25358
25359 insn_buf[0] = RELATIVEJUMP_OPCODE;
25360 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25361 /* This kprobe is really able to run optimized path. */
25362 op = container_of(p, struct optimized_kprobe, kp);
25363 /* Detour through copied instructions */
25364 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25365 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25366 if (!reenter)
25367 reset_current_kprobe();
25368 preempt_enable_no_resched();
25369 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25370 index ebc9873..37b8776 100644
25371 --- a/arch/x86/kernel/ldt.c
25372 +++ b/arch/x86/kernel/ldt.c
25373 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25374 if (reload) {
25375 #ifdef CONFIG_SMP
25376 preempt_disable();
25377 - load_LDT(pc);
25378 + load_LDT_nolock(pc);
25379 if (!cpumask_equal(mm_cpumask(current->mm),
25380 cpumask_of(smp_processor_id())))
25381 smp_call_function(flush_ldt, current->mm, 1);
25382 preempt_enable();
25383 #else
25384 - load_LDT(pc);
25385 + load_LDT_nolock(pc);
25386 #endif
25387 }
25388 if (oldsize) {
25389 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25390 return err;
25391
25392 for (i = 0; i < old->size; i++)
25393 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25394 + write_ldt_entry(new->ldt, i, old->ldt + i);
25395 return 0;
25396 }
25397
25398 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25399 retval = copy_ldt(&mm->context, &old_mm->context);
25400 mutex_unlock(&old_mm->context.lock);
25401 }
25402 +
25403 + if (tsk == current) {
25404 + mm->context.vdso = 0;
25405 +
25406 +#ifdef CONFIG_X86_32
25407 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25408 + mm->context.user_cs_base = 0UL;
25409 + mm->context.user_cs_limit = ~0UL;
25410 +
25411 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25412 + cpus_clear(mm->context.cpu_user_cs_mask);
25413 +#endif
25414 +
25415 +#endif
25416 +#endif
25417 +
25418 + }
25419 +
25420 return retval;
25421 }
25422
25423 @@ -229,6 +247,24 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25424 }
25425 }
25426
25427 +#ifdef CONFIG_PAX_SEGMEXEC
25428 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25429 + error = -EINVAL;
25430 + goto out_unlock;
25431 + }
25432 +#endif
25433 +
25434 + /*
25435 + * On x86-64 we do not support 16-bit segments due to
25436 + * IRET leaking the high bits of the kernel stack address.
25437 + */
25438 +#ifdef CONFIG_X86_64
25439 + if (!ldt_info.seg_32bit) {
25440 + error = -EINVAL;
25441 + goto out_unlock;
25442 + }
25443 +#endif
25444 +
25445 fill_ldt(&ldt, &ldt_info);
25446 if (oldmode)
25447 ldt.avl = 0;
25448 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25449 index 5b19e4d..6476a76 100644
25450 --- a/arch/x86/kernel/machine_kexec_32.c
25451 +++ b/arch/x86/kernel/machine_kexec_32.c
25452 @@ -26,7 +26,7 @@
25453 #include <asm/cacheflush.h>
25454 #include <asm/debugreg.h>
25455
25456 -static void set_idt(void *newidt, __u16 limit)
25457 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25458 {
25459 struct desc_ptr curidt;
25460
25461 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
25462 }
25463
25464
25465 -static void set_gdt(void *newgdt, __u16 limit)
25466 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25467 {
25468 struct desc_ptr curgdt;
25469
25470 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
25471 }
25472
25473 control_page = page_address(image->control_code_page);
25474 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25475 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25476
25477 relocate_kernel_ptr = control_page;
25478 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25479 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
25480 index 15c9876..0a43909 100644
25481 --- a/arch/x86/kernel/microcode_core.c
25482 +++ b/arch/x86/kernel/microcode_core.c
25483 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
25484 return NOTIFY_OK;
25485 }
25486
25487 -static struct notifier_block __refdata mc_cpu_notifier = {
25488 +static struct notifier_block mc_cpu_notifier = {
25489 .notifier_call = mc_cpu_callback,
25490 };
25491
25492 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
25493 index 5fb2ceb..3ae90bb 100644
25494 --- a/arch/x86/kernel/microcode_intel.c
25495 +++ b/arch/x86/kernel/microcode_intel.c
25496 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
25497
25498 static int get_ucode_user(void *to, const void *from, size_t n)
25499 {
25500 - return copy_from_user(to, from, n);
25501 + return copy_from_user(to, (const void __force_user *)from, n);
25502 }
25503
25504 static enum ucode_state
25505 request_microcode_user(int cpu, const void __user *buf, size_t size)
25506 {
25507 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
25508 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
25509 }
25510
25511 static void microcode_fini_cpu(int cpu)
25512 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25513 index 18be189..4a9fe40 100644
25514 --- a/arch/x86/kernel/module.c
25515 +++ b/arch/x86/kernel/module.c
25516 @@ -43,15 +43,60 @@ do { \
25517 } while (0)
25518 #endif
25519
25520 -void *module_alloc(unsigned long size)
25521 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25522 {
25523 - if (PAGE_ALIGN(size) > MODULES_LEN)
25524 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25525 return NULL;
25526 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25527 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25528 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25529 NUMA_NO_NODE, __builtin_return_address(0));
25530 }
25531
25532 +void *module_alloc(unsigned long size)
25533 +{
25534 +
25535 +#ifdef CONFIG_PAX_KERNEXEC
25536 + return __module_alloc(size, PAGE_KERNEL);
25537 +#else
25538 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25539 +#endif
25540 +
25541 +}
25542 +
25543 +#ifdef CONFIG_PAX_KERNEXEC
25544 +#ifdef CONFIG_X86_32
25545 +void *module_alloc_exec(unsigned long size)
25546 +{
25547 + struct vm_struct *area;
25548 +
25549 + if (size == 0)
25550 + return NULL;
25551 +
25552 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25553 + return area ? area->addr : NULL;
25554 +}
25555 +EXPORT_SYMBOL(module_alloc_exec);
25556 +
25557 +void module_free_exec(struct module *mod, void *module_region)
25558 +{
25559 + vunmap(module_region);
25560 +}
25561 +EXPORT_SYMBOL(module_free_exec);
25562 +#else
25563 +void module_free_exec(struct module *mod, void *module_region)
25564 +{
25565 + module_free(mod, module_region);
25566 +}
25567 +EXPORT_SYMBOL(module_free_exec);
25568 +
25569 +void *module_alloc_exec(unsigned long size)
25570 +{
25571 + return __module_alloc(size, PAGE_KERNEL_RX);
25572 +}
25573 +EXPORT_SYMBOL(module_alloc_exec);
25574 +#endif
25575 +#endif
25576 +
25577 #ifdef CONFIG_X86_32
25578 int apply_relocate(Elf32_Shdr *sechdrs,
25579 const char *strtab,
25580 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25581 unsigned int i;
25582 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25583 Elf32_Sym *sym;
25584 - uint32_t *location;
25585 + uint32_t *plocation, location;
25586
25587 DEBUGP("Applying relocate section %u to %u\n",
25588 relsec, sechdrs[relsec].sh_info);
25589 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25590 /* This is where to make the change */
25591 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25592 - + rel[i].r_offset;
25593 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25594 + location = (uint32_t)plocation;
25595 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25596 + plocation = ktla_ktva((void *)plocation);
25597 /* This is the symbol it is referring to. Note that all
25598 undefined symbols have been resolved. */
25599 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25600 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25601 switch (ELF32_R_TYPE(rel[i].r_info)) {
25602 case R_386_32:
25603 /* We add the value into the location given */
25604 - *location += sym->st_value;
25605 + pax_open_kernel();
25606 + *plocation += sym->st_value;
25607 + pax_close_kernel();
25608 break;
25609 case R_386_PC32:
25610 /* Add the value, subtract its position */
25611 - *location += sym->st_value - (uint32_t)location;
25612 + pax_open_kernel();
25613 + *plocation += sym->st_value - location;
25614 + pax_close_kernel();
25615 break;
25616 default:
25617 pr_err("%s: Unknown relocation: %u\n",
25618 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25619 case R_X86_64_NONE:
25620 break;
25621 case R_X86_64_64:
25622 + pax_open_kernel();
25623 *(u64 *)loc = val;
25624 + pax_close_kernel();
25625 break;
25626 case R_X86_64_32:
25627 + pax_open_kernel();
25628 *(u32 *)loc = val;
25629 + pax_close_kernel();
25630 if (val != *(u32 *)loc)
25631 goto overflow;
25632 break;
25633 case R_X86_64_32S:
25634 + pax_open_kernel();
25635 *(s32 *)loc = val;
25636 + pax_close_kernel();
25637 if ((s64)val != *(s32 *)loc)
25638 goto overflow;
25639 break;
25640 case R_X86_64_PC32:
25641 val -= (u64)loc;
25642 + pax_open_kernel();
25643 *(u32 *)loc = val;
25644 + pax_close_kernel();
25645 +
25646 #if 0
25647 if ((s64)val != *(s32 *)loc)
25648 goto overflow;
25649 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25650 index 05266b5..3432443 100644
25651 --- a/arch/x86/kernel/msr.c
25652 +++ b/arch/x86/kernel/msr.c
25653 @@ -37,6 +37,7 @@
25654 #include <linux/notifier.h>
25655 #include <linux/uaccess.h>
25656 #include <linux/gfp.h>
25657 +#include <linux/grsecurity.h>
25658
25659 #include <asm/processor.h>
25660 #include <asm/msr.h>
25661 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25662 int err = 0;
25663 ssize_t bytes = 0;
25664
25665 +#ifdef CONFIG_GRKERNSEC_KMEM
25666 + gr_handle_msr_write();
25667 + return -EPERM;
25668 +#endif
25669 +
25670 if (count % 8)
25671 return -EINVAL; /* Invalid chunk size */
25672
25673 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25674 err = -EBADF;
25675 break;
25676 }
25677 +#ifdef CONFIG_GRKERNSEC_KMEM
25678 + gr_handle_msr_write();
25679 + return -EPERM;
25680 +#endif
25681 if (copy_from_user(&regs, uregs, sizeof regs)) {
25682 err = -EFAULT;
25683 break;
25684 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25685 return notifier_from_errno(err);
25686 }
25687
25688 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25689 +static struct notifier_block msr_class_cpu_notifier = {
25690 .notifier_call = msr_class_cpu_callback,
25691 };
25692
25693 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25694 index 6fcb49c..5b3f4ff 100644
25695 --- a/arch/x86/kernel/nmi.c
25696 +++ b/arch/x86/kernel/nmi.c
25697 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25698 return handled;
25699 }
25700
25701 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25702 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25703 {
25704 struct nmi_desc *desc = nmi_to_desc(type);
25705 unsigned long flags;
25706 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25707 * event confuses some handlers (kdump uses this flag)
25708 */
25709 if (action->flags & NMI_FLAG_FIRST)
25710 - list_add_rcu(&action->list, &desc->head);
25711 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25712 else
25713 - list_add_tail_rcu(&action->list, &desc->head);
25714 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25715
25716 spin_unlock_irqrestore(&desc->lock, flags);
25717 return 0;
25718 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25719 if (!strcmp(n->name, name)) {
25720 WARN(in_nmi(),
25721 "Trying to free NMI (%s) from NMI context!\n", n->name);
25722 - list_del_rcu(&n->list);
25723 + pax_list_del_rcu((struct list_head *)&n->list);
25724 break;
25725 }
25726 }
25727 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25728 dotraplinkage notrace __kprobes void
25729 do_nmi(struct pt_regs *regs, long error_code)
25730 {
25731 +
25732 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25733 + if (!user_mode(regs)) {
25734 + unsigned long cs = regs->cs & 0xFFFF;
25735 + unsigned long ip = ktva_ktla(regs->ip);
25736 +
25737 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25738 + regs->ip = ip;
25739 + }
25740 +#endif
25741 +
25742 nmi_nesting_preprocess(regs);
25743
25744 nmi_enter();
25745 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25746 index 6d9582e..f746287 100644
25747 --- a/arch/x86/kernel/nmi_selftest.c
25748 +++ b/arch/x86/kernel/nmi_selftest.c
25749 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25750 {
25751 /* trap all the unknown NMIs we may generate */
25752 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25753 - __initdata);
25754 + __initconst);
25755 }
25756
25757 static void __init cleanup_nmi_testsuite(void)
25758 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25759 unsigned long timeout;
25760
25761 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25762 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25763 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25764 nmi_fail = FAILURE;
25765 return;
25766 }
25767 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25768 index bbb6c73..24a58ef 100644
25769 --- a/arch/x86/kernel/paravirt-spinlocks.c
25770 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25771 @@ -8,7 +8,7 @@
25772
25773 #include <asm/paravirt.h>
25774
25775 -struct pv_lock_ops pv_lock_ops = {
25776 +struct pv_lock_ops pv_lock_ops __read_only = {
25777 #ifdef CONFIG_SMP
25778 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25779 .unlock_kick = paravirt_nop,
25780 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25781 index 1b10af8..0b58cbc 100644
25782 --- a/arch/x86/kernel/paravirt.c
25783 +++ b/arch/x86/kernel/paravirt.c
25784 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25785 {
25786 return x;
25787 }
25788 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25789 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25790 +#endif
25791
25792 void __init default_banner(void)
25793 {
25794 @@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25795 if (opfunc == NULL)
25796 /* If there's no function, patch it with a ud2a (BUG) */
25797 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25798 - else if (opfunc == _paravirt_nop)
25799 + else if (opfunc == (void *)_paravirt_nop)
25800 /* If the operation is a nop, then nop the callsite */
25801 ret = paravirt_patch_nop();
25802
25803 /* identity functions just return their single argument */
25804 - else if (opfunc == _paravirt_ident_32)
25805 + else if (opfunc == (void *)_paravirt_ident_32)
25806 ret = paravirt_patch_ident_32(insnbuf, len);
25807 - else if (opfunc == _paravirt_ident_64)
25808 + else if (opfunc == (void *)_paravirt_ident_64)
25809 ret = paravirt_patch_ident_64(insnbuf, len);
25810 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25811 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25812 + ret = paravirt_patch_ident_64(insnbuf, len);
25813 +#endif
25814
25815 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25816 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25817 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25818 if (insn_len > len || start == NULL)
25819 insn_len = len;
25820 else
25821 - memcpy(insnbuf, start, insn_len);
25822 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25823
25824 return insn_len;
25825 }
25826 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25827 return this_cpu_read(paravirt_lazy_mode);
25828 }
25829
25830 -struct pv_info pv_info = {
25831 +struct pv_info pv_info __read_only = {
25832 .name = "bare hardware",
25833 .paravirt_enabled = 0,
25834 .kernel_rpl = 0,
25835 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25836 #endif
25837 };
25838
25839 -struct pv_init_ops pv_init_ops = {
25840 +struct pv_init_ops pv_init_ops __read_only = {
25841 .patch = native_patch,
25842 };
25843
25844 -struct pv_time_ops pv_time_ops = {
25845 +struct pv_time_ops pv_time_ops __read_only = {
25846 .sched_clock = native_sched_clock,
25847 .steal_clock = native_steal_clock,
25848 };
25849
25850 -__visible struct pv_irq_ops pv_irq_ops = {
25851 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25852 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25853 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25854 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25855 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25856 #endif
25857 };
25858
25859 -__visible struct pv_cpu_ops pv_cpu_ops = {
25860 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25861 .cpuid = native_cpuid,
25862 .get_debugreg = native_get_debugreg,
25863 .set_debugreg = native_set_debugreg,
25864 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25865 .end_context_switch = paravirt_nop,
25866 };
25867
25868 -struct pv_apic_ops pv_apic_ops = {
25869 +struct pv_apic_ops pv_apic_ops __read_only= {
25870 #ifdef CONFIG_X86_LOCAL_APIC
25871 .startup_ipi_hook = paravirt_nop,
25872 #endif
25873 };
25874
25875 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25876 +#ifdef CONFIG_X86_32
25877 +#ifdef CONFIG_X86_PAE
25878 +/* 64-bit pagetable entries */
25879 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25880 +#else
25881 /* 32-bit pagetable entries */
25882 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25883 +#endif
25884 #else
25885 /* 64-bit pagetable entries */
25886 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25887 #endif
25888
25889 -struct pv_mmu_ops pv_mmu_ops = {
25890 +struct pv_mmu_ops pv_mmu_ops __read_only = {
25891
25892 .read_cr2 = native_read_cr2,
25893 .write_cr2 = native_write_cr2,
25894 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25895 .make_pud = PTE_IDENT,
25896
25897 .set_pgd = native_set_pgd,
25898 + .set_pgd_batched = native_set_pgd_batched,
25899 #endif
25900 #endif /* PAGETABLE_LEVELS >= 3 */
25901
25902 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25903 },
25904
25905 .set_fixmap = native_set_fixmap,
25906 +
25907 +#ifdef CONFIG_PAX_KERNEXEC
25908 + .pax_open_kernel = native_pax_open_kernel,
25909 + .pax_close_kernel = native_pax_close_kernel,
25910 +#endif
25911 +
25912 };
25913
25914 EXPORT_SYMBOL_GPL(pv_time_ops);
25915 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25916 index 299d493..2ccb0ee 100644
25917 --- a/arch/x86/kernel/pci-calgary_64.c
25918 +++ b/arch/x86/kernel/pci-calgary_64.c
25919 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25920 tce_space = be64_to_cpu(readq(target));
25921 tce_space = tce_space & TAR_SW_BITS;
25922
25923 - tce_space = tce_space & (~specified_table_size);
25924 + tce_space = tce_space & (~(unsigned long)specified_table_size);
25925 info->tce_space = (u64 *)__va(tce_space);
25926 }
25927 }
25928 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25929 index 35ccf75..7a15747 100644
25930 --- a/arch/x86/kernel/pci-iommu_table.c
25931 +++ b/arch/x86/kernel/pci-iommu_table.c
25932 @@ -2,7 +2,7 @@
25933 #include <asm/iommu_table.h>
25934 #include <linux/string.h>
25935 #include <linux/kallsyms.h>
25936 -
25937 +#include <linux/sched.h>
25938
25939 #define DEBUG 1
25940
25941 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25942 index 6c483ba..d10ce2f 100644
25943 --- a/arch/x86/kernel/pci-swiotlb.c
25944 +++ b/arch/x86/kernel/pci-swiotlb.c
25945 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25946 void *vaddr, dma_addr_t dma_addr,
25947 struct dma_attrs *attrs)
25948 {
25949 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25950 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25951 }
25952
25953 static struct dma_map_ops swiotlb_dma_ops = {
25954 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25955 index ca7f0d5..8996469 100644
25956 --- a/arch/x86/kernel/preempt.S
25957 +++ b/arch/x86/kernel/preempt.S
25958 @@ -3,12 +3,14 @@
25959 #include <asm/dwarf2.h>
25960 #include <asm/asm.h>
25961 #include <asm/calling.h>
25962 +#include <asm/alternative-asm.h>
25963
25964 ENTRY(___preempt_schedule)
25965 CFI_STARTPROC
25966 SAVE_ALL
25967 call preempt_schedule
25968 RESTORE_ALL
25969 + pax_force_retaddr
25970 ret
25971 CFI_ENDPROC
25972
25973 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25974 SAVE_ALL
25975 call preempt_schedule_context
25976 RESTORE_ALL
25977 + pax_force_retaddr
25978 ret
25979 CFI_ENDPROC
25980
25981 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25982 index 3fb8d95..254dc51 100644
25983 --- a/arch/x86/kernel/process.c
25984 +++ b/arch/x86/kernel/process.c
25985 @@ -36,7 +36,8 @@
25986 * section. Since TSS's are completely CPU-local, we want them
25987 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25988 */
25989 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25990 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25991 +EXPORT_SYMBOL(init_tss);
25992
25993 #ifdef CONFIG_X86_64
25994 static DEFINE_PER_CPU(unsigned char, is_idle);
25995 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25996 task_xstate_cachep =
25997 kmem_cache_create("task_xstate", xstate_size,
25998 __alignof__(union thread_xstate),
25999 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26000 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26001 }
26002
26003 /*
26004 @@ -105,7 +106,7 @@ void exit_thread(void)
26005 unsigned long *bp = t->io_bitmap_ptr;
26006
26007 if (bp) {
26008 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26009 + struct tss_struct *tss = init_tss + get_cpu();
26010
26011 t->io_bitmap_ptr = NULL;
26012 clear_thread_flag(TIF_IO_BITMAP);
26013 @@ -125,6 +126,9 @@ void flush_thread(void)
26014 {
26015 struct task_struct *tsk = current;
26016
26017 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26018 + loadsegment(gs, 0);
26019 +#endif
26020 flush_ptrace_hw_breakpoint(tsk);
26021 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26022 drop_init_fpu(tsk);
26023 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26024 void exit_idle(void)
26025 {
26026 /* idle loop has pid 0 */
26027 - if (current->pid)
26028 + if (task_pid_nr(current))
26029 return;
26030 __exit_idle();
26031 }
26032 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26033 return ret;
26034 }
26035 #endif
26036 -void stop_this_cpu(void *dummy)
26037 +__noreturn void stop_this_cpu(void *dummy)
26038 {
26039 local_irq_disable();
26040 /*
26041 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26042 }
26043 early_param("idle", idle_setup);
26044
26045 -unsigned long arch_align_stack(unsigned long sp)
26046 +#ifdef CONFIG_PAX_RANDKSTACK
26047 +void pax_randomize_kstack(struct pt_regs *regs)
26048 {
26049 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26050 - sp -= get_random_int() % 8192;
26051 - return sp & ~0xf;
26052 -}
26053 + struct thread_struct *thread = &current->thread;
26054 + unsigned long time;
26055
26056 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26057 -{
26058 - unsigned long range_end = mm->brk + 0x02000000;
26059 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26060 -}
26061 + if (!randomize_va_space)
26062 + return;
26063 +
26064 + if (v8086_mode(regs))
26065 + return;
26066
26067 + rdtscl(time);
26068 +
26069 + /* P4 seems to return a 0 LSB, ignore it */
26070 +#ifdef CONFIG_MPENTIUM4
26071 + time &= 0x3EUL;
26072 + time <<= 2;
26073 +#elif defined(CONFIG_X86_64)
26074 + time &= 0xFUL;
26075 + time <<= 4;
26076 +#else
26077 + time &= 0x1FUL;
26078 + time <<= 3;
26079 +#endif
26080 +
26081 + thread->sp0 ^= time;
26082 + load_sp0(init_tss + smp_processor_id(), thread);
26083 +
26084 +#ifdef CONFIG_X86_64
26085 + this_cpu_write(kernel_stack, thread->sp0);
26086 +#endif
26087 +}
26088 +#endif
26089 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26090 index 6f1236c..fd448d4 100644
26091 --- a/arch/x86/kernel/process_32.c
26092 +++ b/arch/x86/kernel/process_32.c
26093 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26094 unsigned long thread_saved_pc(struct task_struct *tsk)
26095 {
26096 return ((unsigned long *)tsk->thread.sp)[3];
26097 +//XXX return tsk->thread.eip;
26098 }
26099
26100 void __show_regs(struct pt_regs *regs, int all)
26101 @@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
26102 unsigned long sp;
26103 unsigned short ss, gs;
26104
26105 - if (user_mode_vm(regs)) {
26106 + if (user_mode(regs)) {
26107 sp = regs->sp;
26108 ss = regs->ss & 0xffff;
26109 - gs = get_user_gs(regs);
26110 } else {
26111 sp = kernel_stack_pointer(regs);
26112 savesegment(ss, ss);
26113 - savesegment(gs, gs);
26114 }
26115 + gs = get_user_gs(regs);
26116
26117 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26118 (u16)regs->cs, regs->ip, regs->flags,
26119 - smp_processor_id());
26120 + raw_smp_processor_id());
26121 print_symbol("EIP is at %s\n", regs->ip);
26122
26123 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26124 @@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
26125 int copy_thread(unsigned long clone_flags, unsigned long sp,
26126 unsigned long arg, struct task_struct *p)
26127 {
26128 - struct pt_regs *childregs = task_pt_regs(p);
26129 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26130 struct task_struct *tsk;
26131 int err;
26132
26133 p->thread.sp = (unsigned long) childregs;
26134 p->thread.sp0 = (unsigned long) (childregs+1);
26135 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26136
26137 if (unlikely(p->flags & PF_KTHREAD)) {
26138 /* kernel thread */
26139 memset(childregs, 0, sizeof(struct pt_regs));
26140 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26141 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26142 - childregs->ds = __USER_DS;
26143 - childregs->es = __USER_DS;
26144 + savesegment(gs, childregs->gs);
26145 + childregs->ds = __KERNEL_DS;
26146 + childregs->es = __KERNEL_DS;
26147 childregs->fs = __KERNEL_PERCPU;
26148 childregs->bx = sp; /* function */
26149 childregs->bp = arg;
26150 @@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26151 struct thread_struct *prev = &prev_p->thread,
26152 *next = &next_p->thread;
26153 int cpu = smp_processor_id();
26154 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26155 + struct tss_struct *tss = init_tss + cpu;
26156 fpu_switch_t fpu;
26157
26158 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26159 @@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26160 */
26161 lazy_save_gs(prev->gs);
26162
26163 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26164 + __set_fs(task_thread_info(next_p)->addr_limit);
26165 +#endif
26166 +
26167 /*
26168 * Load the per-thread Thread-Local Storage descriptor.
26169 */
26170 @@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26171 */
26172 arch_end_context_switch(next_p);
26173
26174 + this_cpu_write(current_task, next_p);
26175 + this_cpu_write(current_tinfo, &next_p->tinfo);
26176 +
26177 /*
26178 * Restore %gs if needed (which is common)
26179 */
26180 @@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26181
26182 switch_fpu_finish(next_p, fpu);
26183
26184 - this_cpu_write(current_task, next_p);
26185 -
26186 return prev_p;
26187 }
26188
26189 @@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26190 } while (count++ < 16);
26191 return 0;
26192 }
26193 -
26194 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26195 index 9c0280f..5bbb1c0 100644
26196 --- a/arch/x86/kernel/process_64.c
26197 +++ b/arch/x86/kernel/process_64.c
26198 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26199 struct pt_regs *childregs;
26200 struct task_struct *me = current;
26201
26202 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26203 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26204 childregs = task_pt_regs(p);
26205 p->thread.sp = (unsigned long) childregs;
26206 p->thread.usersp = me->thread.usersp;
26207 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26208 set_tsk_thread_flag(p, TIF_FORK);
26209 p->thread.fpu_counter = 0;
26210 p->thread.io_bitmap_ptr = NULL;
26211 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26212 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26213 savesegment(es, p->thread.es);
26214 savesegment(ds, p->thread.ds);
26215 + savesegment(ss, p->thread.ss);
26216 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26217 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26218
26219 if (unlikely(p->flags & PF_KTHREAD)) {
26220 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26221 struct thread_struct *prev = &prev_p->thread;
26222 struct thread_struct *next = &next_p->thread;
26223 int cpu = smp_processor_id();
26224 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26225 + struct tss_struct *tss = init_tss + cpu;
26226 unsigned fsindex, gsindex;
26227 fpu_switch_t fpu;
26228
26229 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26230 if (unlikely(next->ds | prev->ds))
26231 loadsegment(ds, next->ds);
26232
26233 + savesegment(ss, prev->ss);
26234 + if (unlikely(next->ss != prev->ss))
26235 + loadsegment(ss, next->ss);
26236
26237 /* We must save %fs and %gs before load_TLS() because
26238 * %fs and %gs may be cleared by load_TLS().
26239 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26240 prev->usersp = this_cpu_read(old_rsp);
26241 this_cpu_write(old_rsp, next->usersp);
26242 this_cpu_write(current_task, next_p);
26243 + this_cpu_write(current_tinfo, &next_p->tinfo);
26244
26245 /*
26246 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26247 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26248 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26249 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26250
26251 - this_cpu_write(kernel_stack,
26252 - (unsigned long)task_stack_page(next_p) +
26253 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26254 + this_cpu_write(kernel_stack, next->sp0);
26255
26256 /*
26257 * Now maybe reload the debug registers and handle I/O bitmaps
26258 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26259 if (!p || p == current || p->state == TASK_RUNNING)
26260 return 0;
26261 stack = (unsigned long)task_stack_page(p);
26262 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26263 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26264 return 0;
26265 fp = *(u64 *)(p->thread.sp);
26266 do {
26267 - if (fp < (unsigned long)stack ||
26268 - fp >= (unsigned long)stack+THREAD_SIZE)
26269 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26270 return 0;
26271 ip = *(u64 *)(fp+8);
26272 if (!in_sched_functions(ip))
26273 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26274 index 7461f50..1334029 100644
26275 --- a/arch/x86/kernel/ptrace.c
26276 +++ b/arch/x86/kernel/ptrace.c
26277 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26278 {
26279 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26280 unsigned long sp = (unsigned long)&regs->sp;
26281 - struct thread_info *tinfo;
26282
26283 - if (context == (sp & ~(THREAD_SIZE - 1)))
26284 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26285 return sp;
26286
26287 - tinfo = (struct thread_info *)context;
26288 - if (tinfo->previous_esp)
26289 - return tinfo->previous_esp;
26290 + sp = *(unsigned long *)context;
26291 + if (sp)
26292 + return sp;
26293
26294 return (unsigned long)regs;
26295 }
26296 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26297 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26298 {
26299 int i;
26300 - int dr7 = 0;
26301 + unsigned long dr7 = 0;
26302 struct arch_hw_breakpoint *info;
26303
26304 for (i = 0; i < HBP_NUM; i++) {
26305 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26306 unsigned long addr, unsigned long data)
26307 {
26308 int ret;
26309 - unsigned long __user *datap = (unsigned long __user *)data;
26310 + unsigned long __user *datap = (__force unsigned long __user *)data;
26311
26312 switch (request) {
26313 /* read the word at location addr in the USER area. */
26314 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26315 if ((int) addr < 0)
26316 return -EIO;
26317 ret = do_get_thread_area(child, addr,
26318 - (struct user_desc __user *)data);
26319 + (__force struct user_desc __user *) data);
26320 break;
26321
26322 case PTRACE_SET_THREAD_AREA:
26323 if ((int) addr < 0)
26324 return -EIO;
26325 ret = do_set_thread_area(child, addr,
26326 - (struct user_desc __user *)data, 0);
26327 + (__force struct user_desc __user *) data, 0);
26328 break;
26329 #endif
26330
26331 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26332
26333 #ifdef CONFIG_X86_64
26334
26335 -static struct user_regset x86_64_regsets[] __read_mostly = {
26336 +static user_regset_no_const x86_64_regsets[] __read_only = {
26337 [REGSET_GENERAL] = {
26338 .core_note_type = NT_PRSTATUS,
26339 .n = sizeof(struct user_regs_struct) / sizeof(long),
26340 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26341 #endif /* CONFIG_X86_64 */
26342
26343 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26344 -static struct user_regset x86_32_regsets[] __read_mostly = {
26345 +static user_regset_no_const x86_32_regsets[] __read_only = {
26346 [REGSET_GENERAL] = {
26347 .core_note_type = NT_PRSTATUS,
26348 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26349 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26350 */
26351 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26352
26353 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26354 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26355 {
26356 #ifdef CONFIG_X86_64
26357 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26358 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26359 memset(info, 0, sizeof(*info));
26360 info->si_signo = SIGTRAP;
26361 info->si_code = si_code;
26362 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26363 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26364 }
26365
26366 void user_single_step_siginfo(struct task_struct *tsk,
26367 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26368 # define IS_IA32 0
26369 #endif
26370
26371 +#ifdef CONFIG_GRKERNSEC_SETXID
26372 +extern void gr_delayed_cred_worker(void);
26373 +#endif
26374 +
26375 /*
26376 * We must return the syscall number to actually look up in the table.
26377 * This can be -1L to skip running any syscall at all.
26378 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26379
26380 user_exit();
26381
26382 +#ifdef CONFIG_GRKERNSEC_SETXID
26383 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26384 + gr_delayed_cred_worker();
26385 +#endif
26386 +
26387 /*
26388 * If we stepped into a sysenter/syscall insn, it trapped in
26389 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26390 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26391 */
26392 user_exit();
26393
26394 +#ifdef CONFIG_GRKERNSEC_SETXID
26395 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26396 + gr_delayed_cred_worker();
26397 +#endif
26398 +
26399 audit_syscall_exit(regs);
26400
26401 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26402 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26403 index 2f355d2..e75ed0a 100644
26404 --- a/arch/x86/kernel/pvclock.c
26405 +++ b/arch/x86/kernel/pvclock.c
26406 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26407 reset_hung_task_detector();
26408 }
26409
26410 -static atomic64_t last_value = ATOMIC64_INIT(0);
26411 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26412
26413 void pvclock_resume(void)
26414 {
26415 - atomic64_set(&last_value, 0);
26416 + atomic64_set_unchecked(&last_value, 0);
26417 }
26418
26419 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26420 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26421 * updating at the same time, and one of them could be slightly behind,
26422 * making the assumption that last_value always go forward fail to hold.
26423 */
26424 - last = atomic64_read(&last_value);
26425 + last = atomic64_read_unchecked(&last_value);
26426 do {
26427 if (ret < last)
26428 return last;
26429 - last = atomic64_cmpxchg(&last_value, last, ret);
26430 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26431 } while (unlikely(last != ret));
26432
26433 return ret;
26434 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26435 index c752cb4..866c432 100644
26436 --- a/arch/x86/kernel/reboot.c
26437 +++ b/arch/x86/kernel/reboot.c
26438 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26439
26440 void __noreturn machine_real_restart(unsigned int type)
26441 {
26442 +
26443 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26444 + struct desc_struct *gdt;
26445 +#endif
26446 +
26447 local_irq_disable();
26448
26449 /*
26450 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26451
26452 /* Jump to the identity-mapped low memory code */
26453 #ifdef CONFIG_X86_32
26454 - asm volatile("jmpl *%0" : :
26455 +
26456 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26457 + gdt = get_cpu_gdt_table(smp_processor_id());
26458 + pax_open_kernel();
26459 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26460 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26461 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26462 + loadsegment(ds, __KERNEL_DS);
26463 + loadsegment(es, __KERNEL_DS);
26464 + loadsegment(ss, __KERNEL_DS);
26465 +#endif
26466 +#ifdef CONFIG_PAX_KERNEXEC
26467 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26468 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26469 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26470 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26471 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26472 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26473 +#endif
26474 + pax_close_kernel();
26475 +#endif
26476 +
26477 + asm volatile("ljmpl *%0" : :
26478 "rm" (real_mode_header->machine_real_restart_asm),
26479 "a" (type));
26480 #else
26481 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26482 * try to force a triple fault and then cycle between hitting the keyboard
26483 * controller and doing that
26484 */
26485 -static void native_machine_emergency_restart(void)
26486 +static void __noreturn native_machine_emergency_restart(void)
26487 {
26488 int i;
26489 int attempt = 0;
26490 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26491 #endif
26492 }
26493
26494 -static void __machine_emergency_restart(int emergency)
26495 +static void __noreturn __machine_emergency_restart(int emergency)
26496 {
26497 reboot_emergency = emergency;
26498 machine_ops.emergency_restart();
26499 }
26500
26501 -static void native_machine_restart(char *__unused)
26502 +static void __noreturn native_machine_restart(char *__unused)
26503 {
26504 pr_notice("machine restart\n");
26505
26506 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26507 __machine_emergency_restart(0);
26508 }
26509
26510 -static void native_machine_halt(void)
26511 +static void __noreturn native_machine_halt(void)
26512 {
26513 /* Stop other cpus and apics */
26514 machine_shutdown();
26515 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
26516 stop_this_cpu(NULL);
26517 }
26518
26519 -static void native_machine_power_off(void)
26520 +static void __noreturn native_machine_power_off(void)
26521 {
26522 if (pm_power_off) {
26523 if (!reboot_force)
26524 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26525 }
26526 /* A fallback in case there is no PM info available */
26527 tboot_shutdown(TB_SHUTDOWN_HALT);
26528 + unreachable();
26529 }
26530
26531 -struct machine_ops machine_ops = {
26532 +struct machine_ops machine_ops __read_only = {
26533 .power_off = native_machine_power_off,
26534 .shutdown = native_machine_shutdown,
26535 .emergency_restart = native_machine_emergency_restart,
26536 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26537 index c8e41e9..64049ef 100644
26538 --- a/arch/x86/kernel/reboot_fixups_32.c
26539 +++ b/arch/x86/kernel/reboot_fixups_32.c
26540 @@ -57,7 +57,7 @@ struct device_fixup {
26541 unsigned int vendor;
26542 unsigned int device;
26543 void (*reboot_fixup)(struct pci_dev *);
26544 -};
26545 +} __do_const;
26546
26547 /*
26548 * PCI ids solely used for fixups_table go here
26549 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26550 index 3fd2c69..a444264 100644
26551 --- a/arch/x86/kernel/relocate_kernel_64.S
26552 +++ b/arch/x86/kernel/relocate_kernel_64.S
26553 @@ -96,8 +96,7 @@ relocate_kernel:
26554
26555 /* jump to identity mapped page */
26556 addq $(identity_mapped - relocate_kernel), %r8
26557 - pushq %r8
26558 - ret
26559 + jmp *%r8
26560
26561 identity_mapped:
26562 /* set return address to 0 if not preserving context */
26563 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26564 index cb233bc..23b4879 100644
26565 --- a/arch/x86/kernel/setup.c
26566 +++ b/arch/x86/kernel/setup.c
26567 @@ -110,6 +110,7 @@
26568 #include <asm/mce.h>
26569 #include <asm/alternative.h>
26570 #include <asm/prom.h>
26571 +#include <asm/boot.h>
26572
26573 /*
26574 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26575 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26576 #endif
26577
26578
26579 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26580 -__visible unsigned long mmu_cr4_features;
26581 +#ifdef CONFIG_X86_64
26582 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26583 +#elif defined(CONFIG_X86_PAE)
26584 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26585 #else
26586 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26587 +__visible unsigned long mmu_cr4_features __read_only;
26588 #endif
26589
26590 +void set_in_cr4(unsigned long mask)
26591 +{
26592 + unsigned long cr4 = read_cr4();
26593 +
26594 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26595 + return;
26596 +
26597 + pax_open_kernel();
26598 + mmu_cr4_features |= mask;
26599 + pax_close_kernel();
26600 +
26601 + if (trampoline_cr4_features)
26602 + *trampoline_cr4_features = mmu_cr4_features;
26603 + cr4 |= mask;
26604 + write_cr4(cr4);
26605 +}
26606 +EXPORT_SYMBOL(set_in_cr4);
26607 +
26608 +void clear_in_cr4(unsigned long mask)
26609 +{
26610 + unsigned long cr4 = read_cr4();
26611 +
26612 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26613 + return;
26614 +
26615 + pax_open_kernel();
26616 + mmu_cr4_features &= ~mask;
26617 + pax_close_kernel();
26618 +
26619 + if (trampoline_cr4_features)
26620 + *trampoline_cr4_features = mmu_cr4_features;
26621 + cr4 &= ~mask;
26622 + write_cr4(cr4);
26623 +}
26624 +EXPORT_SYMBOL(clear_in_cr4);
26625 +
26626 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26627 int bootloader_type, bootloader_version;
26628
26629 @@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26630 * area (640->1Mb) as ram even though it is not.
26631 * take them out.
26632 */
26633 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26634 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26635
26636 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26637 }
26638 @@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26639 /* called before trim_bios_range() to spare extra sanitize */
26640 static void __init e820_add_kernel_range(void)
26641 {
26642 - u64 start = __pa_symbol(_text);
26643 + u64 start = __pa_symbol(ktla_ktva(_text));
26644 u64 size = __pa_symbol(_end) - start;
26645
26646 /*
26647 @@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26648
26649 void __init setup_arch(char **cmdline_p)
26650 {
26651 +#ifdef CONFIG_X86_32
26652 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26653 +#else
26654 memblock_reserve(__pa_symbol(_text),
26655 (unsigned long)__bss_stop - (unsigned long)_text);
26656 +#endif
26657
26658 early_reserve_initrd();
26659
26660 @@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26661
26662 if (!boot_params.hdr.root_flags)
26663 root_mountflags &= ~MS_RDONLY;
26664 - init_mm.start_code = (unsigned long) _text;
26665 - init_mm.end_code = (unsigned long) _etext;
26666 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26667 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26668 init_mm.end_data = (unsigned long) _edata;
26669 init_mm.brk = _brk_end;
26670
26671 - code_resource.start = __pa_symbol(_text);
26672 - code_resource.end = __pa_symbol(_etext)-1;
26673 - data_resource.start = __pa_symbol(_etext);
26674 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26675 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26676 + data_resource.start = __pa_symbol(_sdata);
26677 data_resource.end = __pa_symbol(_edata)-1;
26678 bss_resource.start = __pa_symbol(__bss_start);
26679 bss_resource.end = __pa_symbol(__bss_stop)-1;
26680 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26681 index 5cdff03..80fa283 100644
26682 --- a/arch/x86/kernel/setup_percpu.c
26683 +++ b/arch/x86/kernel/setup_percpu.c
26684 @@ -21,19 +21,17 @@
26685 #include <asm/cpu.h>
26686 #include <asm/stackprotector.h>
26687
26688 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26689 +#ifdef CONFIG_SMP
26690 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26691 EXPORT_PER_CPU_SYMBOL(cpu_number);
26692 +#endif
26693
26694 -#ifdef CONFIG_X86_64
26695 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26696 -#else
26697 -#define BOOT_PERCPU_OFFSET 0
26698 -#endif
26699
26700 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26701 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26702
26703 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26704 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26705 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26706 };
26707 EXPORT_SYMBOL(__per_cpu_offset);
26708 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26709 {
26710 #ifdef CONFIG_NEED_MULTIPLE_NODES
26711 pg_data_t *last = NULL;
26712 - unsigned int cpu;
26713 + int cpu;
26714
26715 for_each_possible_cpu(cpu) {
26716 int node = early_cpu_to_node(cpu);
26717 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26718 {
26719 #ifdef CONFIG_X86_32
26720 struct desc_struct gdt;
26721 + unsigned long base = per_cpu_offset(cpu);
26722
26723 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26724 - 0x2 | DESCTYPE_S, 0x8);
26725 - gdt.s = 1;
26726 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26727 + 0x83 | DESCTYPE_S, 0xC);
26728 write_gdt_entry(get_cpu_gdt_table(cpu),
26729 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26730 #endif
26731 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26732 /* alrighty, percpu areas up and running */
26733 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26734 for_each_possible_cpu(cpu) {
26735 +#ifdef CONFIG_CC_STACKPROTECTOR
26736 +#ifdef CONFIG_X86_32
26737 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26738 +#endif
26739 +#endif
26740 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26741 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26742 per_cpu(cpu_number, cpu) = cpu;
26743 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26744 */
26745 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26746 #endif
26747 +#ifdef CONFIG_CC_STACKPROTECTOR
26748 +#ifdef CONFIG_X86_32
26749 + if (!cpu)
26750 + per_cpu(stack_canary.canary, cpu) = canary;
26751 +#endif
26752 +#endif
26753 /*
26754 * Up to this point, the boot CPU has been using .init.data
26755 * area. Reload any changed state for the boot CPU.
26756 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26757 index 9e5de68..16c53cb 100644
26758 --- a/arch/x86/kernel/signal.c
26759 +++ b/arch/x86/kernel/signal.c
26760 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26761 * Align the stack pointer according to the i386 ABI,
26762 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26763 */
26764 - sp = ((sp + 4) & -16ul) - 4;
26765 + sp = ((sp - 12) & -16ul) - 4;
26766 #else /* !CONFIG_X86_32 */
26767 sp = round_down(sp, 16) - 8;
26768 #endif
26769 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26770 }
26771
26772 if (current->mm->context.vdso)
26773 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26774 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26775 else
26776 - restorer = &frame->retcode;
26777 + restorer = (void __user *)&frame->retcode;
26778 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26779 restorer = ksig->ka.sa.sa_restorer;
26780
26781 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26782 * reasons and because gdb uses it as a signature to notice
26783 * signal handler stack frames.
26784 */
26785 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26786 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26787
26788 if (err)
26789 return -EFAULT;
26790 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26791 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26792
26793 /* Set up to return from userspace. */
26794 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26795 + if (current->mm->context.vdso)
26796 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26797 + else
26798 + restorer = (void __user *)&frame->retcode;
26799 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26800 restorer = ksig->ka.sa.sa_restorer;
26801 put_user_ex(restorer, &frame->pretcode);
26802 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26803 * reasons and because gdb uses it as a signature to notice
26804 * signal handler stack frames.
26805 */
26806 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26807 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26808 } put_user_catch(err);
26809
26810 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26811 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26812 {
26813 int usig = signr_convert(ksig->sig);
26814 sigset_t *set = sigmask_to_save();
26815 - compat_sigset_t *cset = (compat_sigset_t *) set;
26816 + sigset_t sigcopy;
26817 + compat_sigset_t *cset;
26818 +
26819 + sigcopy = *set;
26820 +
26821 + cset = (compat_sigset_t *) &sigcopy;
26822
26823 /* Set up the stack frame */
26824 if (is_ia32_frame()) {
26825 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26826 } else if (is_x32_frame()) {
26827 return x32_setup_rt_frame(ksig, cset, regs);
26828 } else {
26829 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26830 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26831 }
26832 }
26833
26834 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26835 index 7c3a5a6..f0a8961 100644
26836 --- a/arch/x86/kernel/smp.c
26837 +++ b/arch/x86/kernel/smp.c
26838 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26839
26840 __setup("nonmi_ipi", nonmi_ipi_setup);
26841
26842 -struct smp_ops smp_ops = {
26843 +struct smp_ops smp_ops __read_only = {
26844 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26845 .smp_prepare_cpus = native_smp_prepare_cpus,
26846 .smp_cpus_done = native_smp_cpus_done,
26847 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26848 index 85dc05a..f8c96f6 100644
26849 --- a/arch/x86/kernel/smpboot.c
26850 +++ b/arch/x86/kernel/smpboot.c
26851 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26852
26853 enable_start_cpu0 = 0;
26854
26855 -#ifdef CONFIG_X86_32
26856 - /* switch away from the initial page table */
26857 - load_cr3(swapper_pg_dir);
26858 - __flush_tlb_all();
26859 -#endif
26860 -
26861 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26862 barrier();
26863 +
26864 + /* switch away from the initial page table */
26865 +#ifdef CONFIG_PAX_PER_CPU_PGD
26866 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26867 + __flush_tlb_all();
26868 +#elif defined(CONFIG_X86_32)
26869 + load_cr3(swapper_pg_dir);
26870 + __flush_tlb_all();
26871 +#endif
26872 +
26873 /*
26874 * Check TSC synchronization with the BP:
26875 */
26876 @@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26877 alternatives_enable_smp();
26878
26879 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26880 - (THREAD_SIZE + task_stack_page(idle))) - 1);
26881 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26882 per_cpu(current_task, cpu) = idle;
26883 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26884
26885 #ifdef CONFIG_X86_32
26886 /* Stack for startup_32 can be just as for start_secondary onwards */
26887 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26888 #else
26889 clear_tsk_thread_flag(idle, TIF_FORK);
26890 initial_gs = per_cpu_offset(cpu);
26891 - per_cpu(kernel_stack, cpu) =
26892 - (unsigned long)task_stack_page(idle) -
26893 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26894 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26895 #endif
26896 +
26897 + pax_open_kernel();
26898 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26899 + pax_close_kernel();
26900 +
26901 initial_code = (unsigned long)start_secondary;
26902 stack_start = idle->thread.sp;
26903
26904 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26905 /* the FPU context is blank, nobody can own it */
26906 __cpu_disable_lazy_restore(cpu);
26907
26908 +#ifdef CONFIG_PAX_PER_CPU_PGD
26909 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26910 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26911 + KERNEL_PGD_PTRS);
26912 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26913 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26914 + KERNEL_PGD_PTRS);
26915 +#endif
26916 +
26917 err = do_boot_cpu(apicid, cpu, tidle);
26918 if (err) {
26919 pr_debug("do_boot_cpu failed %d\n", err);
26920 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26921 index 9b4d51d..5d28b58 100644
26922 --- a/arch/x86/kernel/step.c
26923 +++ b/arch/x86/kernel/step.c
26924 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26925 struct desc_struct *desc;
26926 unsigned long base;
26927
26928 - seg &= ~7UL;
26929 + seg >>= 3;
26930
26931 mutex_lock(&child->mm->context.lock);
26932 - if (unlikely((seg >> 3) >= child->mm->context.size))
26933 + if (unlikely(seg >= child->mm->context.size))
26934 addr = -1L; /* bogus selector, access would fault */
26935 else {
26936 desc = child->mm->context.ldt + seg;
26937 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26938 addr += base;
26939 }
26940 mutex_unlock(&child->mm->context.lock);
26941 - }
26942 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26943 + addr = ktla_ktva(addr);
26944
26945 return addr;
26946 }
26947 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26948 unsigned char opcode[15];
26949 unsigned long addr = convert_ip_to_linear(child, regs);
26950
26951 + if (addr == -EINVAL)
26952 + return 0;
26953 +
26954 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26955 for (i = 0; i < copied; i++) {
26956 switch (opcode[i]) {
26957 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26958 new file mode 100644
26959 index 0000000..5877189
26960 --- /dev/null
26961 +++ b/arch/x86/kernel/sys_i386_32.c
26962 @@ -0,0 +1,189 @@
26963 +/*
26964 + * This file contains various random system calls that
26965 + * have a non-standard calling sequence on the Linux/i386
26966 + * platform.
26967 + */
26968 +
26969 +#include <linux/errno.h>
26970 +#include <linux/sched.h>
26971 +#include <linux/mm.h>
26972 +#include <linux/fs.h>
26973 +#include <linux/smp.h>
26974 +#include <linux/sem.h>
26975 +#include <linux/msg.h>
26976 +#include <linux/shm.h>
26977 +#include <linux/stat.h>
26978 +#include <linux/syscalls.h>
26979 +#include <linux/mman.h>
26980 +#include <linux/file.h>
26981 +#include <linux/utsname.h>
26982 +#include <linux/ipc.h>
26983 +#include <linux/elf.h>
26984 +
26985 +#include <linux/uaccess.h>
26986 +#include <linux/unistd.h>
26987 +
26988 +#include <asm/syscalls.h>
26989 +
26990 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26991 +{
26992 + unsigned long pax_task_size = TASK_SIZE;
26993 +
26994 +#ifdef CONFIG_PAX_SEGMEXEC
26995 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26996 + pax_task_size = SEGMEXEC_TASK_SIZE;
26997 +#endif
26998 +
26999 + if (flags & MAP_FIXED)
27000 + if (len > pax_task_size || addr > pax_task_size - len)
27001 + return -EINVAL;
27002 +
27003 + return 0;
27004 +}
27005 +
27006 +/*
27007 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27008 + */
27009 +static unsigned long get_align_mask(void)
27010 +{
27011 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27012 + return 0;
27013 +
27014 + if (!(current->flags & PF_RANDOMIZE))
27015 + return 0;
27016 +
27017 + return va_align.mask;
27018 +}
27019 +
27020 +unsigned long
27021 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27022 + unsigned long len, unsigned long pgoff, unsigned long flags)
27023 +{
27024 + struct mm_struct *mm = current->mm;
27025 + struct vm_area_struct *vma;
27026 + unsigned long pax_task_size = TASK_SIZE;
27027 + struct vm_unmapped_area_info info;
27028 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27029 +
27030 +#ifdef CONFIG_PAX_SEGMEXEC
27031 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27032 + pax_task_size = SEGMEXEC_TASK_SIZE;
27033 +#endif
27034 +
27035 + pax_task_size -= PAGE_SIZE;
27036 +
27037 + if (len > pax_task_size)
27038 + return -ENOMEM;
27039 +
27040 + if (flags & MAP_FIXED)
27041 + return addr;
27042 +
27043 +#ifdef CONFIG_PAX_RANDMMAP
27044 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27045 +#endif
27046 +
27047 + if (addr) {
27048 + addr = PAGE_ALIGN(addr);
27049 + if (pax_task_size - len >= addr) {
27050 + vma = find_vma(mm, addr);
27051 + if (check_heap_stack_gap(vma, addr, len, offset))
27052 + return addr;
27053 + }
27054 + }
27055 +
27056 + info.flags = 0;
27057 + info.length = len;
27058 + info.align_mask = filp ? get_align_mask() : 0;
27059 + info.align_offset = pgoff << PAGE_SHIFT;
27060 + info.threadstack_offset = offset;
27061 +
27062 +#ifdef CONFIG_PAX_PAGEEXEC
27063 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27064 + info.low_limit = 0x00110000UL;
27065 + info.high_limit = mm->start_code;
27066 +
27067 +#ifdef CONFIG_PAX_RANDMMAP
27068 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27069 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27070 +#endif
27071 +
27072 + if (info.low_limit < info.high_limit) {
27073 + addr = vm_unmapped_area(&info);
27074 + if (!IS_ERR_VALUE(addr))
27075 + return addr;
27076 + }
27077 + } else
27078 +#endif
27079 +
27080 + info.low_limit = mm->mmap_base;
27081 + info.high_limit = pax_task_size;
27082 +
27083 + return vm_unmapped_area(&info);
27084 +}
27085 +
27086 +unsigned long
27087 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27088 + const unsigned long len, const unsigned long pgoff,
27089 + const unsigned long flags)
27090 +{
27091 + struct vm_area_struct *vma;
27092 + struct mm_struct *mm = current->mm;
27093 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27094 + struct vm_unmapped_area_info info;
27095 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27096 +
27097 +#ifdef CONFIG_PAX_SEGMEXEC
27098 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27099 + pax_task_size = SEGMEXEC_TASK_SIZE;
27100 +#endif
27101 +
27102 + pax_task_size -= PAGE_SIZE;
27103 +
27104 + /* requested length too big for entire address space */
27105 + if (len > pax_task_size)
27106 + return -ENOMEM;
27107 +
27108 + if (flags & MAP_FIXED)
27109 + return addr;
27110 +
27111 +#ifdef CONFIG_PAX_PAGEEXEC
27112 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27113 + goto bottomup;
27114 +#endif
27115 +
27116 +#ifdef CONFIG_PAX_RANDMMAP
27117 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27118 +#endif
27119 +
27120 + /* requesting a specific address */
27121 + if (addr) {
27122 + addr = PAGE_ALIGN(addr);
27123 + if (pax_task_size - len >= addr) {
27124 + vma = find_vma(mm, addr);
27125 + if (check_heap_stack_gap(vma, addr, len, offset))
27126 + return addr;
27127 + }
27128 + }
27129 +
27130 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27131 + info.length = len;
27132 + info.low_limit = PAGE_SIZE;
27133 + info.high_limit = mm->mmap_base;
27134 + info.align_mask = filp ? get_align_mask() : 0;
27135 + info.align_offset = pgoff << PAGE_SHIFT;
27136 + info.threadstack_offset = offset;
27137 +
27138 + addr = vm_unmapped_area(&info);
27139 + if (!(addr & ~PAGE_MASK))
27140 + return addr;
27141 + VM_BUG_ON(addr != -ENOMEM);
27142 +
27143 +bottomup:
27144 + /*
27145 + * A failed mmap() very likely causes application failure,
27146 + * so fall back to the bottom-up function here. This scenario
27147 + * can happen with large stack limits and large mmap()
27148 + * allocations.
27149 + */
27150 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27151 +}
27152 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27153 index 30277e2..5664a29 100644
27154 --- a/arch/x86/kernel/sys_x86_64.c
27155 +++ b/arch/x86/kernel/sys_x86_64.c
27156 @@ -81,8 +81,8 @@ out:
27157 return error;
27158 }
27159
27160 -static void find_start_end(unsigned long flags, unsigned long *begin,
27161 - unsigned long *end)
27162 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27163 + unsigned long *begin, unsigned long *end)
27164 {
27165 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27166 unsigned long new_begin;
27167 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27168 *begin = new_begin;
27169 }
27170 } else {
27171 - *begin = current->mm->mmap_legacy_base;
27172 + *begin = mm->mmap_legacy_base;
27173 *end = TASK_SIZE;
27174 }
27175 }
27176 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27177 struct vm_area_struct *vma;
27178 struct vm_unmapped_area_info info;
27179 unsigned long begin, end;
27180 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27181
27182 if (flags & MAP_FIXED)
27183 return addr;
27184
27185 - find_start_end(flags, &begin, &end);
27186 + find_start_end(mm, flags, &begin, &end);
27187
27188 if (len > end)
27189 return -ENOMEM;
27190
27191 +#ifdef CONFIG_PAX_RANDMMAP
27192 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27193 +#endif
27194 +
27195 if (addr) {
27196 addr = PAGE_ALIGN(addr);
27197 vma = find_vma(mm, addr);
27198 - if (end - len >= addr &&
27199 - (!vma || addr + len <= vma->vm_start))
27200 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27201 return addr;
27202 }
27203
27204 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27205 info.high_limit = end;
27206 info.align_mask = filp ? get_align_mask() : 0;
27207 info.align_offset = pgoff << PAGE_SHIFT;
27208 + info.threadstack_offset = offset;
27209 return vm_unmapped_area(&info);
27210 }
27211
27212 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27213 struct mm_struct *mm = current->mm;
27214 unsigned long addr = addr0;
27215 struct vm_unmapped_area_info info;
27216 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27217
27218 /* requested length too big for entire address space */
27219 if (len > TASK_SIZE)
27220 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27221 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27222 goto bottomup;
27223
27224 +#ifdef CONFIG_PAX_RANDMMAP
27225 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27226 +#endif
27227 +
27228 /* requesting a specific address */
27229 if (addr) {
27230 addr = PAGE_ALIGN(addr);
27231 vma = find_vma(mm, addr);
27232 - if (TASK_SIZE - len >= addr &&
27233 - (!vma || addr + len <= vma->vm_start))
27234 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27235 return addr;
27236 }
27237
27238 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27239 info.high_limit = mm->mmap_base;
27240 info.align_mask = filp ? get_align_mask() : 0;
27241 info.align_offset = pgoff << PAGE_SHIFT;
27242 + info.threadstack_offset = offset;
27243 addr = vm_unmapped_area(&info);
27244 if (!(addr & ~PAGE_MASK))
27245 return addr;
27246 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27247 index 91a4496..bb87552 100644
27248 --- a/arch/x86/kernel/tboot.c
27249 +++ b/arch/x86/kernel/tboot.c
27250 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27251
27252 void tboot_shutdown(u32 shutdown_type)
27253 {
27254 - void (*shutdown)(void);
27255 + void (* __noreturn shutdown)(void);
27256
27257 if (!tboot_enabled())
27258 return;
27259 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27260
27261 switch_to_tboot_pt();
27262
27263 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27264 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27265 shutdown();
27266
27267 /* should not reach here */
27268 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27269 return -ENODEV;
27270 }
27271
27272 -static atomic_t ap_wfs_count;
27273 +static atomic_unchecked_t ap_wfs_count;
27274
27275 static int tboot_wait_for_aps(int num_aps)
27276 {
27277 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27278 {
27279 switch (action) {
27280 case CPU_DYING:
27281 - atomic_inc(&ap_wfs_count);
27282 + atomic_inc_unchecked(&ap_wfs_count);
27283 if (num_online_cpus() == 1)
27284 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27285 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27286 return NOTIFY_BAD;
27287 break;
27288 }
27289 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27290
27291 tboot_create_trampoline();
27292
27293 - atomic_set(&ap_wfs_count, 0);
27294 + atomic_set_unchecked(&ap_wfs_count, 0);
27295 register_hotcpu_notifier(&tboot_cpu_notifier);
27296
27297 #ifdef CONFIG_DEBUG_FS
27298 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27299 index 24d3c91..d06b473 100644
27300 --- a/arch/x86/kernel/time.c
27301 +++ b/arch/x86/kernel/time.c
27302 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27303 {
27304 unsigned long pc = instruction_pointer(regs);
27305
27306 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27307 + if (!user_mode(regs) && in_lock_functions(pc)) {
27308 #ifdef CONFIG_FRAME_POINTER
27309 - return *(unsigned long *)(regs->bp + sizeof(long));
27310 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27311 #else
27312 unsigned long *sp =
27313 (unsigned long *)kernel_stack_pointer(regs);
27314 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27315 * or above a saved flags. Eflags has bits 22-31 zero,
27316 * kernel addresses don't.
27317 */
27318 +
27319 +#ifdef CONFIG_PAX_KERNEXEC
27320 + return ktla_ktva(sp[0]);
27321 +#else
27322 if (sp[0] >> 22)
27323 return sp[0];
27324 if (sp[1] >> 22)
27325 return sp[1];
27326 #endif
27327 +
27328 +#endif
27329 }
27330 return pc;
27331 }
27332 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27333 index f7fec09..9991981 100644
27334 --- a/arch/x86/kernel/tls.c
27335 +++ b/arch/x86/kernel/tls.c
27336 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27337 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27338 return -EINVAL;
27339
27340 +#ifdef CONFIG_PAX_SEGMEXEC
27341 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27342 + return -EINVAL;
27343 +#endif
27344 +
27345 set_tls_desc(p, idx, &info, 1);
27346
27347 return 0;
27348 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27349
27350 if (kbuf)
27351 info = kbuf;
27352 - else if (__copy_from_user(infobuf, ubuf, count))
27353 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27354 return -EFAULT;
27355 else
27356 info = infobuf;
27357 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27358 index 1c113db..287b42e 100644
27359 --- a/arch/x86/kernel/tracepoint.c
27360 +++ b/arch/x86/kernel/tracepoint.c
27361 @@ -9,11 +9,11 @@
27362 #include <linux/atomic.h>
27363
27364 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27365 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27366 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27367 (unsigned long) trace_idt_table };
27368
27369 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27370 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27371 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27372
27373 static int trace_irq_vector_refcount;
27374 static DEFINE_MUTEX(irq_vector_mutex);
27375 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27376 index b857ed8..51ae4cb 100644
27377 --- a/arch/x86/kernel/traps.c
27378 +++ b/arch/x86/kernel/traps.c
27379 @@ -66,7 +66,7 @@
27380 #include <asm/proto.h>
27381
27382 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27383 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27384 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27385 #else
27386 #include <asm/processor-flags.h>
27387 #include <asm/setup.h>
27388 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27389 #endif
27390
27391 /* Must be page-aligned because the real IDT is used in a fixmap. */
27392 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27393 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27394
27395 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27396 EXPORT_SYMBOL_GPL(used_vectors);
27397 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27398 }
27399
27400 static int __kprobes
27401 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27402 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27403 struct pt_regs *regs, long error_code)
27404 {
27405 #ifdef CONFIG_X86_32
27406 - if (regs->flags & X86_VM_MASK) {
27407 + if (v8086_mode(regs)) {
27408 /*
27409 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27410 * On nmi (interrupt 2), do_trap should not be called.
27411 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27412 return -1;
27413 }
27414 #endif
27415 - if (!user_mode(regs)) {
27416 + if (!user_mode_novm(regs)) {
27417 if (!fixup_exception(regs)) {
27418 tsk->thread.error_code = error_code;
27419 tsk->thread.trap_nr = trapnr;
27420 +
27421 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27422 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27423 + str = "PAX: suspicious stack segment fault";
27424 +#endif
27425 +
27426 die(str, regs, error_code);
27427 }
27428 +
27429 +#ifdef CONFIG_PAX_REFCOUNT
27430 + if (trapnr == 4)
27431 + pax_report_refcount_overflow(regs);
27432 +#endif
27433 +
27434 return 0;
27435 }
27436
27437 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27438 }
27439
27440 static void __kprobes
27441 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27442 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27443 long error_code, siginfo_t *info)
27444 {
27445 struct task_struct *tsk = current;
27446 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27447 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27448 printk_ratelimit()) {
27449 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27450 - tsk->comm, tsk->pid, str,
27451 + tsk->comm, task_pid_nr(tsk), str,
27452 regs->ip, regs->sp, error_code);
27453 print_vma_addr(" in ", regs->ip);
27454 pr_cont("\n");
27455 @@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27456 conditional_sti(regs);
27457
27458 #ifdef CONFIG_X86_32
27459 - if (regs->flags & X86_VM_MASK) {
27460 + if (v8086_mode(regs)) {
27461 local_irq_enable();
27462 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27463 goto exit;
27464 @@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27465 #endif
27466
27467 tsk = current;
27468 - if (!user_mode(regs)) {
27469 + if (!user_mode_novm(regs)) {
27470 if (fixup_exception(regs))
27471 goto exit;
27472
27473 tsk->thread.error_code = error_code;
27474 tsk->thread.trap_nr = X86_TRAP_GP;
27475 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27476 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27477 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27478 +
27479 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27480 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27481 + die("PAX: suspicious general protection fault", regs, error_code);
27482 + else
27483 +#endif
27484 +
27485 die("general protection fault", regs, error_code);
27486 + }
27487 goto exit;
27488 }
27489
27490 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27491 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27492 + struct mm_struct *mm = tsk->mm;
27493 + unsigned long limit;
27494 +
27495 + down_write(&mm->mmap_sem);
27496 + limit = mm->context.user_cs_limit;
27497 + if (limit < TASK_SIZE) {
27498 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27499 + up_write(&mm->mmap_sem);
27500 + return;
27501 + }
27502 + up_write(&mm->mmap_sem);
27503 + }
27504 +#endif
27505 +
27506 tsk->thread.error_code = error_code;
27507 tsk->thread.trap_nr = X86_TRAP_GP;
27508
27509 @@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27510 /* It's safe to allow irq's after DR6 has been saved */
27511 preempt_conditional_sti(regs);
27512
27513 - if (regs->flags & X86_VM_MASK) {
27514 + if (v8086_mode(regs)) {
27515 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27516 X86_TRAP_DB);
27517 preempt_conditional_cli(regs);
27518 @@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27519 * We already checked v86 mode above, so we can check for kernel mode
27520 * by just checking the CPL of CS.
27521 */
27522 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27523 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27524 tsk->thread.debugreg6 &= ~DR_STEP;
27525 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27526 regs->flags &= ~X86_EFLAGS_TF;
27527 @@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27528 return;
27529 conditional_sti(regs);
27530
27531 - if (!user_mode_vm(regs))
27532 + if (!user_mode(regs))
27533 {
27534 if (!fixup_exception(regs)) {
27535 task->thread.error_code = error_code;
27536 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27537 index 2ed8459..7cf329f 100644
27538 --- a/arch/x86/kernel/uprobes.c
27539 +++ b/arch/x86/kernel/uprobes.c
27540 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27541 int ret = NOTIFY_DONE;
27542
27543 /* We are only interested in userspace traps */
27544 - if (regs && !user_mode_vm(regs))
27545 + if (regs && !user_mode(regs))
27546 return NOTIFY_DONE;
27547
27548 switch (val) {
27549 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27550
27551 if (ncopied != rasize) {
27552 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27553 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27554 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27555
27556 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27557 }
27558 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27559 index b9242ba..50c5edd 100644
27560 --- a/arch/x86/kernel/verify_cpu.S
27561 +++ b/arch/x86/kernel/verify_cpu.S
27562 @@ -20,6 +20,7 @@
27563 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27564 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27565 * arch/x86/kernel/head_32.S: processor startup
27566 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27567 *
27568 * verify_cpu, returns the status of longmode and SSE in register %eax.
27569 * 0: Success 1: Failure
27570 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27571 index e8edcf5..27f9344 100644
27572 --- a/arch/x86/kernel/vm86_32.c
27573 +++ b/arch/x86/kernel/vm86_32.c
27574 @@ -44,6 +44,7 @@
27575 #include <linux/ptrace.h>
27576 #include <linux/audit.h>
27577 #include <linux/stddef.h>
27578 +#include <linux/grsecurity.h>
27579
27580 #include <asm/uaccess.h>
27581 #include <asm/io.h>
27582 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27583 do_exit(SIGSEGV);
27584 }
27585
27586 - tss = &per_cpu(init_tss, get_cpu());
27587 + tss = init_tss + get_cpu();
27588 current->thread.sp0 = current->thread.saved_sp0;
27589 current->thread.sysenter_cs = __KERNEL_CS;
27590 load_sp0(tss, &current->thread);
27591 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27592
27593 if (tsk->thread.saved_sp0)
27594 return -EPERM;
27595 +
27596 +#ifdef CONFIG_GRKERNSEC_VM86
27597 + if (!capable(CAP_SYS_RAWIO)) {
27598 + gr_handle_vm86();
27599 + return -EPERM;
27600 + }
27601 +#endif
27602 +
27603 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27604 offsetof(struct kernel_vm86_struct, vm86plus) -
27605 sizeof(info.regs));
27606 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27607 int tmp;
27608 struct vm86plus_struct __user *v86;
27609
27610 +#ifdef CONFIG_GRKERNSEC_VM86
27611 + if (!capable(CAP_SYS_RAWIO)) {
27612 + gr_handle_vm86();
27613 + return -EPERM;
27614 + }
27615 +#endif
27616 +
27617 tsk = current;
27618 switch (cmd) {
27619 case VM86_REQUEST_IRQ:
27620 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27621 tsk->thread.saved_fs = info->regs32->fs;
27622 tsk->thread.saved_gs = get_user_gs(info->regs32);
27623
27624 - tss = &per_cpu(init_tss, get_cpu());
27625 + tss = init_tss + get_cpu();
27626 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27627 if (cpu_has_sep)
27628 tsk->thread.sysenter_cs = 0;
27629 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27630 goto cannot_handle;
27631 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27632 goto cannot_handle;
27633 - intr_ptr = (unsigned long __user *) (i << 2);
27634 + intr_ptr = (__force unsigned long __user *) (i << 2);
27635 if (get_user(segoffs, intr_ptr))
27636 goto cannot_handle;
27637 if ((segoffs >> 16) == BIOSSEG)
27638 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27639 index da6b35a..977e9cf 100644
27640 --- a/arch/x86/kernel/vmlinux.lds.S
27641 +++ b/arch/x86/kernel/vmlinux.lds.S
27642 @@ -26,6 +26,13 @@
27643 #include <asm/page_types.h>
27644 #include <asm/cache.h>
27645 #include <asm/boot.h>
27646 +#include <asm/segment.h>
27647 +
27648 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27649 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27650 +#else
27651 +#define __KERNEL_TEXT_OFFSET 0
27652 +#endif
27653
27654 #undef i386 /* in case the preprocessor is a 32bit one */
27655
27656 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27657
27658 PHDRS {
27659 text PT_LOAD FLAGS(5); /* R_E */
27660 +#ifdef CONFIG_X86_32
27661 + module PT_LOAD FLAGS(5); /* R_E */
27662 +#endif
27663 +#ifdef CONFIG_XEN
27664 + rodata PT_LOAD FLAGS(5); /* R_E */
27665 +#else
27666 + rodata PT_LOAD FLAGS(4); /* R__ */
27667 +#endif
27668 data PT_LOAD FLAGS(6); /* RW_ */
27669 -#ifdef CONFIG_X86_64
27670 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27671 #ifdef CONFIG_SMP
27672 percpu PT_LOAD FLAGS(6); /* RW_ */
27673 #endif
27674 + text.init PT_LOAD FLAGS(5); /* R_E */
27675 + text.exit PT_LOAD FLAGS(5); /* R_E */
27676 init PT_LOAD FLAGS(7); /* RWE */
27677 -#endif
27678 note PT_NOTE FLAGS(0); /* ___ */
27679 }
27680
27681 SECTIONS
27682 {
27683 #ifdef CONFIG_X86_32
27684 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27685 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27686 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27687 #else
27688 - . = __START_KERNEL;
27689 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27690 + . = __START_KERNEL;
27691 #endif
27692
27693 /* Text and read-only data */
27694 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27695 - _text = .;
27696 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27697 /* bootstrapping code */
27698 +#ifdef CONFIG_X86_32
27699 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27700 +#else
27701 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27702 +#endif
27703 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27704 + _text = .;
27705 HEAD_TEXT
27706 . = ALIGN(8);
27707 _stext = .;
27708 @@ -104,13 +124,47 @@ SECTIONS
27709 IRQENTRY_TEXT
27710 *(.fixup)
27711 *(.gnu.warning)
27712 - /* End of text section */
27713 - _etext = .;
27714 } :text = 0x9090
27715
27716 - NOTES :text :note
27717 + . += __KERNEL_TEXT_OFFSET;
27718
27719 - EXCEPTION_TABLE(16) :text = 0x9090
27720 +#ifdef CONFIG_X86_32
27721 + . = ALIGN(PAGE_SIZE);
27722 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27723 +
27724 +#ifdef CONFIG_PAX_KERNEXEC
27725 + MODULES_EXEC_VADDR = .;
27726 + BYTE(0)
27727 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27728 + . = ALIGN(HPAGE_SIZE) - 1;
27729 + MODULES_EXEC_END = .;
27730 +#endif
27731 +
27732 + } :module
27733 +#endif
27734 +
27735 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27736 + /* End of text section */
27737 + BYTE(0)
27738 + _etext = . - __KERNEL_TEXT_OFFSET;
27739 + }
27740 +
27741 +#ifdef CONFIG_X86_32
27742 + . = ALIGN(PAGE_SIZE);
27743 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27744 + . = ALIGN(PAGE_SIZE);
27745 + *(.empty_zero_page)
27746 + *(.initial_pg_fixmap)
27747 + *(.initial_pg_pmd)
27748 + *(.initial_page_table)
27749 + *(.swapper_pg_dir)
27750 + } :rodata
27751 +#endif
27752 +
27753 + . = ALIGN(PAGE_SIZE);
27754 + NOTES :rodata :note
27755 +
27756 + EXCEPTION_TABLE(16) :rodata
27757
27758 #if defined(CONFIG_DEBUG_RODATA)
27759 /* .text should occupy whole number of pages */
27760 @@ -122,16 +176,20 @@ SECTIONS
27761
27762 /* Data */
27763 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27764 +
27765 +#ifdef CONFIG_PAX_KERNEXEC
27766 + . = ALIGN(HPAGE_SIZE);
27767 +#else
27768 + . = ALIGN(PAGE_SIZE);
27769 +#endif
27770 +
27771 /* Start of data section */
27772 _sdata = .;
27773
27774 /* init_task */
27775 INIT_TASK_DATA(THREAD_SIZE)
27776
27777 -#ifdef CONFIG_X86_32
27778 - /* 32 bit has nosave before _edata */
27779 NOSAVE_DATA
27780 -#endif
27781
27782 PAGE_ALIGNED_DATA(PAGE_SIZE)
27783
27784 @@ -172,12 +230,19 @@ SECTIONS
27785 #endif /* CONFIG_X86_64 */
27786
27787 /* Init code and data - will be freed after init */
27788 - . = ALIGN(PAGE_SIZE);
27789 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27790 + BYTE(0)
27791 +
27792 +#ifdef CONFIG_PAX_KERNEXEC
27793 + . = ALIGN(HPAGE_SIZE);
27794 +#else
27795 + . = ALIGN(PAGE_SIZE);
27796 +#endif
27797 +
27798 __init_begin = .; /* paired with __init_end */
27799 - }
27800 + } :init.begin
27801
27802 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27803 +#ifdef CONFIG_SMP
27804 /*
27805 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27806 * output PHDR, so the next output section - .init.text - should
27807 @@ -186,12 +251,27 @@ SECTIONS
27808 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27809 #endif
27810
27811 - INIT_TEXT_SECTION(PAGE_SIZE)
27812 -#ifdef CONFIG_X86_64
27813 - :init
27814 -#endif
27815 + . = ALIGN(PAGE_SIZE);
27816 + init_begin = .;
27817 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27818 + VMLINUX_SYMBOL(_sinittext) = .;
27819 + INIT_TEXT
27820 + VMLINUX_SYMBOL(_einittext) = .;
27821 + . = ALIGN(PAGE_SIZE);
27822 + } :text.init
27823
27824 - INIT_DATA_SECTION(16)
27825 + /*
27826 + * .exit.text is discard at runtime, not link time, to deal with
27827 + * references from .altinstructions and .eh_frame
27828 + */
27829 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27830 + EXIT_TEXT
27831 + . = ALIGN(16);
27832 + } :text.exit
27833 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27834 +
27835 + . = ALIGN(PAGE_SIZE);
27836 + INIT_DATA_SECTION(16) :init
27837
27838 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27839 __x86_cpu_dev_start = .;
27840 @@ -262,19 +342,12 @@ SECTIONS
27841 }
27842
27843 . = ALIGN(8);
27844 - /*
27845 - * .exit.text is discard at runtime, not link time, to deal with
27846 - * references from .altinstructions and .eh_frame
27847 - */
27848 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27849 - EXIT_TEXT
27850 - }
27851
27852 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27853 EXIT_DATA
27854 }
27855
27856 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27857 +#ifndef CONFIG_SMP
27858 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27859 #endif
27860
27861 @@ -293,16 +366,10 @@ SECTIONS
27862 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27863 __smp_locks = .;
27864 *(.smp_locks)
27865 - . = ALIGN(PAGE_SIZE);
27866 __smp_locks_end = .;
27867 + . = ALIGN(PAGE_SIZE);
27868 }
27869
27870 -#ifdef CONFIG_X86_64
27871 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27872 - NOSAVE_DATA
27873 - }
27874 -#endif
27875 -
27876 /* BSS */
27877 . = ALIGN(PAGE_SIZE);
27878 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27879 @@ -318,6 +385,7 @@ SECTIONS
27880 __brk_base = .;
27881 . += 64 * 1024; /* 64k alignment slop space */
27882 *(.brk_reservation) /* areas brk users have reserved */
27883 + . = ALIGN(HPAGE_SIZE);
27884 __brk_limit = .;
27885 }
27886
27887 @@ -344,13 +412,12 @@ SECTIONS
27888 * for the boot processor.
27889 */
27890 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27891 -INIT_PER_CPU(gdt_page);
27892 INIT_PER_CPU(irq_stack_union);
27893
27894 /*
27895 * Build-time check on the image size:
27896 */
27897 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27898 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27899 "kernel image bigger than KERNEL_IMAGE_SIZE");
27900
27901 #ifdef CONFIG_SMP
27902 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27903 index 1f96f93..d5c8f7a 100644
27904 --- a/arch/x86/kernel/vsyscall_64.c
27905 +++ b/arch/x86/kernel/vsyscall_64.c
27906 @@ -56,15 +56,13 @@
27907 DEFINE_VVAR(int, vgetcpu_mode);
27908 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27909
27910 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27911 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27912
27913 static int __init vsyscall_setup(char *str)
27914 {
27915 if (str) {
27916 if (!strcmp("emulate", str))
27917 vsyscall_mode = EMULATE;
27918 - else if (!strcmp("native", str))
27919 - vsyscall_mode = NATIVE;
27920 else if (!strcmp("none", str))
27921 vsyscall_mode = NONE;
27922 else
27923 @@ -323,8 +321,7 @@ do_ret:
27924 return true;
27925
27926 sigsegv:
27927 - force_sig(SIGSEGV, current);
27928 - return true;
27929 + do_group_exit(SIGKILL);
27930 }
27931
27932 /*
27933 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27934 extern char __vvar_page;
27935 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27936
27937 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27938 - vsyscall_mode == NATIVE
27939 - ? PAGE_KERNEL_VSYSCALL
27940 - : PAGE_KERNEL_VVAR);
27941 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27942 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27943 (unsigned long)VSYSCALL_START);
27944
27945 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27946 index 04068192..4d75aa6 100644
27947 --- a/arch/x86/kernel/x8664_ksyms_64.c
27948 +++ b/arch/x86/kernel/x8664_ksyms_64.c
27949 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27950 EXPORT_SYMBOL(copy_user_generic_unrolled);
27951 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27952 EXPORT_SYMBOL(__copy_user_nocache);
27953 -EXPORT_SYMBOL(_copy_from_user);
27954 -EXPORT_SYMBOL(_copy_to_user);
27955
27956 EXPORT_SYMBOL(copy_page);
27957 EXPORT_SYMBOL(clear_page);
27958 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27959 EXPORT_SYMBOL(___preempt_schedule_context);
27960 #endif
27961 #endif
27962 +
27963 +#ifdef CONFIG_PAX_PER_CPU_PGD
27964 +EXPORT_SYMBOL(cpu_pgd);
27965 +#endif
27966 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27967 index 021783b..6511282 100644
27968 --- a/arch/x86/kernel/x86_init.c
27969 +++ b/arch/x86/kernel/x86_init.c
27970 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27971 static void default_nmi_init(void) { };
27972 static int default_i8042_detect(void) { return 1; };
27973
27974 -struct x86_platform_ops x86_platform = {
27975 +struct x86_platform_ops x86_platform __read_only = {
27976 .calibrate_tsc = native_calibrate_tsc,
27977 .get_wallclock = mach_get_cmos_time,
27978 .set_wallclock = mach_set_rtc_mmss,
27979 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27980 EXPORT_SYMBOL_GPL(x86_platform);
27981
27982 #if defined(CONFIG_PCI_MSI)
27983 -struct x86_msi_ops x86_msi = {
27984 +struct x86_msi_ops x86_msi __read_only = {
27985 .setup_msi_irqs = native_setup_msi_irqs,
27986 .compose_msi_msg = native_compose_msi_msg,
27987 .teardown_msi_irq = native_teardown_msi_irq,
27988 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27989 }
27990 #endif
27991
27992 -struct x86_io_apic_ops x86_io_apic_ops = {
27993 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27994 .init = native_io_apic_init_mappings,
27995 .read = native_io_apic_read,
27996 .write = native_io_apic_write,
27997 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27998 index 422fd82..b2d262e 100644
27999 --- a/arch/x86/kernel/xsave.c
28000 +++ b/arch/x86/kernel/xsave.c
28001 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28002
28003 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28004 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28005 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28006 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28007
28008 if (!use_xsave())
28009 return err;
28010
28011 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28012 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28013
28014 /*
28015 * Read the xstate_bv which we copied (directly from the cpu or
28016 * from the state in task struct) to the user buffers.
28017 */
28018 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28019 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28020
28021 /*
28022 * For legacy compatible, we always set FP/SSE bits in the bit
28023 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28024 */
28025 xstate_bv |= XSTATE_FPSSE;
28026
28027 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28028 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28029
28030 return err;
28031 }
28032 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28033 {
28034 int err;
28035
28036 + buf = (struct xsave_struct __user *)____m(buf);
28037 if (use_xsave())
28038 err = xsave_user(buf);
28039 else if (use_fxsr())
28040 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28041 */
28042 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28043 {
28044 + buf = (void __user *)____m(buf);
28045 if (use_xsave()) {
28046 if ((unsigned long)buf % 64 || fx_only) {
28047 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28048 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28049 index c697625..a032162 100644
28050 --- a/arch/x86/kvm/cpuid.c
28051 +++ b/arch/x86/kvm/cpuid.c
28052 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28053 struct kvm_cpuid2 *cpuid,
28054 struct kvm_cpuid_entry2 __user *entries)
28055 {
28056 - int r;
28057 + int r, i;
28058
28059 r = -E2BIG;
28060 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28061 goto out;
28062 r = -EFAULT;
28063 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28064 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28065 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28066 goto out;
28067 + for (i = 0; i < cpuid->nent; ++i) {
28068 + struct kvm_cpuid_entry2 cpuid_entry;
28069 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28070 + goto out;
28071 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28072 + }
28073 vcpu->arch.cpuid_nent = cpuid->nent;
28074 kvm_apic_set_version(vcpu);
28075 kvm_x86_ops->cpuid_update(vcpu);
28076 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28077 struct kvm_cpuid2 *cpuid,
28078 struct kvm_cpuid_entry2 __user *entries)
28079 {
28080 - int r;
28081 + int r, i;
28082
28083 r = -E2BIG;
28084 if (cpuid->nent < vcpu->arch.cpuid_nent)
28085 goto out;
28086 r = -EFAULT;
28087 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28088 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28089 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28090 goto out;
28091 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28092 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28093 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28094 + goto out;
28095 + }
28096 return 0;
28097
28098 out:
28099 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28100 index d86ff15..e77b023 100644
28101 --- a/arch/x86/kvm/lapic.c
28102 +++ b/arch/x86/kvm/lapic.c
28103 @@ -55,7 +55,7 @@
28104 #define APIC_BUS_CYCLE_NS 1
28105
28106 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28107 -#define apic_debug(fmt, arg...)
28108 +#define apic_debug(fmt, arg...) do {} while (0)
28109
28110 #define APIC_LVT_NUM 6
28111 /* 14 is the version for Xeon and Pentium 8.4.8*/
28112 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28113 index cba218a..1cc1bed 100644
28114 --- a/arch/x86/kvm/paging_tmpl.h
28115 +++ b/arch/x86/kvm/paging_tmpl.h
28116 @@ -331,7 +331,7 @@ retry_walk:
28117 if (unlikely(kvm_is_error_hva(host_addr)))
28118 goto error;
28119
28120 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28121 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28122 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28123 goto error;
28124 walker->ptep_user[walker->level - 1] = ptep_user;
28125 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28126 index 532add1..59eb241 100644
28127 --- a/arch/x86/kvm/svm.c
28128 +++ b/arch/x86/kvm/svm.c
28129 @@ -3495,7 +3495,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28130 int cpu = raw_smp_processor_id();
28131
28132 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28133 +
28134 + pax_open_kernel();
28135 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28136 + pax_close_kernel();
28137 +
28138 load_TR_desc();
28139 }
28140
28141 @@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28142 #endif
28143 #endif
28144
28145 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28146 + __set_fs(current_thread_info()->addr_limit);
28147 +#endif
28148 +
28149 reload_tss(vcpu);
28150
28151 local_irq_disable();
28152 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28153 index 31c3e8b..ca3acc6 100644
28154 --- a/arch/x86/kvm/vmx.c
28155 +++ b/arch/x86/kvm/vmx.c
28156 @@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28157 #endif
28158 }
28159
28160 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28161 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28162 {
28163 vmcs_writel(field, vmcs_readl(field) & ~mask);
28164 }
28165
28166 -static void vmcs_set_bits(unsigned long field, u32 mask)
28167 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28168 {
28169 vmcs_writel(field, vmcs_readl(field) | mask);
28170 }
28171 @@ -1522,7 +1522,11 @@ static void reload_tss(void)
28172 struct desc_struct *descs;
28173
28174 descs = (void *)gdt->address;
28175 +
28176 + pax_open_kernel();
28177 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28178 + pax_close_kernel();
28179 +
28180 load_TR_desc();
28181 }
28182
28183 @@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28184 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28185 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28186
28187 +#ifdef CONFIG_PAX_PER_CPU_PGD
28188 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28189 +#endif
28190 +
28191 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28192 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28193 vmx->loaded_vmcs->cpu = cpu;
28194 @@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28195 * reads and returns guest's timestamp counter "register"
28196 * guest_tsc = host_tsc + tsc_offset -- 21.3
28197 */
28198 -static u64 guest_read_tsc(void)
28199 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28200 {
28201 u64 host_tsc, tsc_offset;
28202
28203 @@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
28204 if (!cpu_has_vmx_flexpriority())
28205 flexpriority_enabled = 0;
28206
28207 - if (!cpu_has_vmx_tpr_shadow())
28208 - kvm_x86_ops->update_cr8_intercept = NULL;
28209 + if (!cpu_has_vmx_tpr_shadow()) {
28210 + pax_open_kernel();
28211 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28212 + pax_close_kernel();
28213 + }
28214
28215 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28216 kvm_disable_largepages();
28217 @@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
28218 if (!cpu_has_vmx_apicv())
28219 enable_apicv = 0;
28220
28221 + pax_open_kernel();
28222 if (enable_apicv)
28223 - kvm_x86_ops->update_cr8_intercept = NULL;
28224 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28225 else {
28226 - kvm_x86_ops->hwapic_irr_update = NULL;
28227 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28228 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28229 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28230 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28231 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28232 }
28233 + pax_close_kernel();
28234
28235 if (nested)
28236 nested_vmx_setup_ctls_msrs();
28237 @@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28238
28239 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28240 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28241 +
28242 +#ifndef CONFIG_PAX_PER_CPU_PGD
28243 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28244 +#endif
28245
28246 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28247 #ifdef CONFIG_X86_64
28248 @@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28249 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28250 vmx->host_idt_base = dt.address;
28251
28252 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28253 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28254
28255 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28256 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28257 @@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28258 "jmp 2f \n\t"
28259 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28260 "2: "
28261 +
28262 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28263 + "ljmp %[cs],$3f\n\t"
28264 + "3: "
28265 +#endif
28266 +
28267 /* Save guest registers, load host registers, keep flags */
28268 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28269 "pop %0 \n\t"
28270 @@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28271 #endif
28272 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28273 [wordsize]"i"(sizeof(ulong))
28274 +
28275 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28276 + ,[cs]"i"(__KERNEL_CS)
28277 +#endif
28278 +
28279 : "cc", "memory"
28280 #ifdef CONFIG_X86_64
28281 , "rax", "rbx", "rdi", "rsi"
28282 @@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28283 if (debugctlmsr)
28284 update_debugctlmsr(debugctlmsr);
28285
28286 -#ifndef CONFIG_X86_64
28287 +#ifdef CONFIG_X86_32
28288 /*
28289 * The sysexit path does not restore ds/es, so we must set them to
28290 * a reasonable value ourselves.
28291 @@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28292 * may be executed in interrupt context, which saves and restore segments
28293 * around it, nullifying its effect.
28294 */
28295 - loadsegment(ds, __USER_DS);
28296 - loadsegment(es, __USER_DS);
28297 + loadsegment(ds, __KERNEL_DS);
28298 + loadsegment(es, __KERNEL_DS);
28299 + loadsegment(ss, __KERNEL_DS);
28300 +
28301 +#ifdef CONFIG_PAX_KERNEXEC
28302 + loadsegment(fs, __KERNEL_PERCPU);
28303 +#endif
28304 +
28305 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28306 + __set_fs(current_thread_info()->addr_limit);
28307 +#endif
28308 +
28309 #endif
28310
28311 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28312 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28313 index 4e33b85..fa94855 100644
28314 --- a/arch/x86/kvm/x86.c
28315 +++ b/arch/x86/kvm/x86.c
28316 @@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28317 {
28318 struct kvm *kvm = vcpu->kvm;
28319 int lm = is_long_mode(vcpu);
28320 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28321 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28322 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28323 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28324 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28325 : kvm->arch.xen_hvm_config.blob_size_32;
28326 u32 page_num = data & ~PAGE_MASK;
28327 @@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28328 if (n < msr_list.nmsrs)
28329 goto out;
28330 r = -EFAULT;
28331 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28332 + goto out;
28333 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28334 num_msrs_to_save * sizeof(u32)))
28335 goto out;
28336 @@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28337 };
28338 #endif
28339
28340 -int kvm_arch_init(void *opaque)
28341 +int kvm_arch_init(const void *opaque)
28342 {
28343 int r;
28344 struct kvm_x86_ops *ops = opaque;
28345 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28346 index bdf8532..f63c587 100644
28347 --- a/arch/x86/lguest/boot.c
28348 +++ b/arch/x86/lguest/boot.c
28349 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28350 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28351 * Launcher to reboot us.
28352 */
28353 -static void lguest_restart(char *reason)
28354 +static __noreturn void lguest_restart(char *reason)
28355 {
28356 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28357 + BUG();
28358 }
28359
28360 /*G:050
28361 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28362 index 00933d5..3a64af9 100644
28363 --- a/arch/x86/lib/atomic64_386_32.S
28364 +++ b/arch/x86/lib/atomic64_386_32.S
28365 @@ -48,6 +48,10 @@ BEGIN(read)
28366 movl (v), %eax
28367 movl 4(v), %edx
28368 RET_ENDP
28369 +BEGIN(read_unchecked)
28370 + movl (v), %eax
28371 + movl 4(v), %edx
28372 +RET_ENDP
28373 #undef v
28374
28375 #define v %esi
28376 @@ -55,6 +59,10 @@ BEGIN(set)
28377 movl %ebx, (v)
28378 movl %ecx, 4(v)
28379 RET_ENDP
28380 +BEGIN(set_unchecked)
28381 + movl %ebx, (v)
28382 + movl %ecx, 4(v)
28383 +RET_ENDP
28384 #undef v
28385
28386 #define v %esi
28387 @@ -70,6 +78,20 @@ RET_ENDP
28388 BEGIN(add)
28389 addl %eax, (v)
28390 adcl %edx, 4(v)
28391 +
28392 +#ifdef CONFIG_PAX_REFCOUNT
28393 + jno 0f
28394 + subl %eax, (v)
28395 + sbbl %edx, 4(v)
28396 + int $4
28397 +0:
28398 + _ASM_EXTABLE(0b, 0b)
28399 +#endif
28400 +
28401 +RET_ENDP
28402 +BEGIN(add_unchecked)
28403 + addl %eax, (v)
28404 + adcl %edx, 4(v)
28405 RET_ENDP
28406 #undef v
28407
28408 @@ -77,6 +99,24 @@ RET_ENDP
28409 BEGIN(add_return)
28410 addl (v), %eax
28411 adcl 4(v), %edx
28412 +
28413 +#ifdef CONFIG_PAX_REFCOUNT
28414 + into
28415 +1234:
28416 + _ASM_EXTABLE(1234b, 2f)
28417 +#endif
28418 +
28419 + movl %eax, (v)
28420 + movl %edx, 4(v)
28421 +
28422 +#ifdef CONFIG_PAX_REFCOUNT
28423 +2:
28424 +#endif
28425 +
28426 +RET_ENDP
28427 +BEGIN(add_return_unchecked)
28428 + addl (v), %eax
28429 + adcl 4(v), %edx
28430 movl %eax, (v)
28431 movl %edx, 4(v)
28432 RET_ENDP
28433 @@ -86,6 +126,20 @@ RET_ENDP
28434 BEGIN(sub)
28435 subl %eax, (v)
28436 sbbl %edx, 4(v)
28437 +
28438 +#ifdef CONFIG_PAX_REFCOUNT
28439 + jno 0f
28440 + addl %eax, (v)
28441 + adcl %edx, 4(v)
28442 + int $4
28443 +0:
28444 + _ASM_EXTABLE(0b, 0b)
28445 +#endif
28446 +
28447 +RET_ENDP
28448 +BEGIN(sub_unchecked)
28449 + subl %eax, (v)
28450 + sbbl %edx, 4(v)
28451 RET_ENDP
28452 #undef v
28453
28454 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28455 sbbl $0, %edx
28456 addl (v), %eax
28457 adcl 4(v), %edx
28458 +
28459 +#ifdef CONFIG_PAX_REFCOUNT
28460 + into
28461 +1234:
28462 + _ASM_EXTABLE(1234b, 2f)
28463 +#endif
28464 +
28465 + movl %eax, (v)
28466 + movl %edx, 4(v)
28467 +
28468 +#ifdef CONFIG_PAX_REFCOUNT
28469 +2:
28470 +#endif
28471 +
28472 +RET_ENDP
28473 +BEGIN(sub_return_unchecked)
28474 + negl %edx
28475 + negl %eax
28476 + sbbl $0, %edx
28477 + addl (v), %eax
28478 + adcl 4(v), %edx
28479 movl %eax, (v)
28480 movl %edx, 4(v)
28481 RET_ENDP
28482 @@ -105,6 +180,20 @@ RET_ENDP
28483 BEGIN(inc)
28484 addl $1, (v)
28485 adcl $0, 4(v)
28486 +
28487 +#ifdef CONFIG_PAX_REFCOUNT
28488 + jno 0f
28489 + subl $1, (v)
28490 + sbbl $0, 4(v)
28491 + int $4
28492 +0:
28493 + _ASM_EXTABLE(0b, 0b)
28494 +#endif
28495 +
28496 +RET_ENDP
28497 +BEGIN(inc_unchecked)
28498 + addl $1, (v)
28499 + adcl $0, 4(v)
28500 RET_ENDP
28501 #undef v
28502
28503 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28504 movl 4(v), %edx
28505 addl $1, %eax
28506 adcl $0, %edx
28507 +
28508 +#ifdef CONFIG_PAX_REFCOUNT
28509 + into
28510 +1234:
28511 + _ASM_EXTABLE(1234b, 2f)
28512 +#endif
28513 +
28514 + movl %eax, (v)
28515 + movl %edx, 4(v)
28516 +
28517 +#ifdef CONFIG_PAX_REFCOUNT
28518 +2:
28519 +#endif
28520 +
28521 +RET_ENDP
28522 +BEGIN(inc_return_unchecked)
28523 + movl (v), %eax
28524 + movl 4(v), %edx
28525 + addl $1, %eax
28526 + adcl $0, %edx
28527 movl %eax, (v)
28528 movl %edx, 4(v)
28529 RET_ENDP
28530 @@ -123,6 +232,20 @@ RET_ENDP
28531 BEGIN(dec)
28532 subl $1, (v)
28533 sbbl $0, 4(v)
28534 +
28535 +#ifdef CONFIG_PAX_REFCOUNT
28536 + jno 0f
28537 + addl $1, (v)
28538 + adcl $0, 4(v)
28539 + int $4
28540 +0:
28541 + _ASM_EXTABLE(0b, 0b)
28542 +#endif
28543 +
28544 +RET_ENDP
28545 +BEGIN(dec_unchecked)
28546 + subl $1, (v)
28547 + sbbl $0, 4(v)
28548 RET_ENDP
28549 #undef v
28550
28551 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28552 movl 4(v), %edx
28553 subl $1, %eax
28554 sbbl $0, %edx
28555 +
28556 +#ifdef CONFIG_PAX_REFCOUNT
28557 + into
28558 +1234:
28559 + _ASM_EXTABLE(1234b, 2f)
28560 +#endif
28561 +
28562 + movl %eax, (v)
28563 + movl %edx, 4(v)
28564 +
28565 +#ifdef CONFIG_PAX_REFCOUNT
28566 +2:
28567 +#endif
28568 +
28569 +RET_ENDP
28570 +BEGIN(dec_return_unchecked)
28571 + movl (v), %eax
28572 + movl 4(v), %edx
28573 + subl $1, %eax
28574 + sbbl $0, %edx
28575 movl %eax, (v)
28576 movl %edx, 4(v)
28577 RET_ENDP
28578 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28579 adcl %edx, %edi
28580 addl (v), %eax
28581 adcl 4(v), %edx
28582 +
28583 +#ifdef CONFIG_PAX_REFCOUNT
28584 + into
28585 +1234:
28586 + _ASM_EXTABLE(1234b, 2f)
28587 +#endif
28588 +
28589 cmpl %eax, %ecx
28590 je 3f
28591 1:
28592 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28593 1:
28594 addl $1, %eax
28595 adcl $0, %edx
28596 +
28597 +#ifdef CONFIG_PAX_REFCOUNT
28598 + into
28599 +1234:
28600 + _ASM_EXTABLE(1234b, 2f)
28601 +#endif
28602 +
28603 movl %eax, (v)
28604 movl %edx, 4(v)
28605 movl $1, %eax
28606 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28607 movl 4(v), %edx
28608 subl $1, %eax
28609 sbbl $0, %edx
28610 +
28611 +#ifdef CONFIG_PAX_REFCOUNT
28612 + into
28613 +1234:
28614 + _ASM_EXTABLE(1234b, 1f)
28615 +#endif
28616 +
28617 js 1f
28618 movl %eax, (v)
28619 movl %edx, 4(v)
28620 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28621 index f5cc9eb..51fa319 100644
28622 --- a/arch/x86/lib/atomic64_cx8_32.S
28623 +++ b/arch/x86/lib/atomic64_cx8_32.S
28624 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28625 CFI_STARTPROC
28626
28627 read64 %ecx
28628 + pax_force_retaddr
28629 ret
28630 CFI_ENDPROC
28631 ENDPROC(atomic64_read_cx8)
28632
28633 +ENTRY(atomic64_read_unchecked_cx8)
28634 + CFI_STARTPROC
28635 +
28636 + read64 %ecx
28637 + pax_force_retaddr
28638 + ret
28639 + CFI_ENDPROC
28640 +ENDPROC(atomic64_read_unchecked_cx8)
28641 +
28642 ENTRY(atomic64_set_cx8)
28643 CFI_STARTPROC
28644
28645 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28646 cmpxchg8b (%esi)
28647 jne 1b
28648
28649 + pax_force_retaddr
28650 ret
28651 CFI_ENDPROC
28652 ENDPROC(atomic64_set_cx8)
28653
28654 +ENTRY(atomic64_set_unchecked_cx8)
28655 + CFI_STARTPROC
28656 +
28657 +1:
28658 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28659 + * are atomic on 586 and newer */
28660 + cmpxchg8b (%esi)
28661 + jne 1b
28662 +
28663 + pax_force_retaddr
28664 + ret
28665 + CFI_ENDPROC
28666 +ENDPROC(atomic64_set_unchecked_cx8)
28667 +
28668 ENTRY(atomic64_xchg_cx8)
28669 CFI_STARTPROC
28670
28671 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28672 cmpxchg8b (%esi)
28673 jne 1b
28674
28675 + pax_force_retaddr
28676 ret
28677 CFI_ENDPROC
28678 ENDPROC(atomic64_xchg_cx8)
28679
28680 -.macro addsub_return func ins insc
28681 -ENTRY(atomic64_\func\()_return_cx8)
28682 +.macro addsub_return func ins insc unchecked=""
28683 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28684 CFI_STARTPROC
28685 SAVE ebp
28686 SAVE ebx
28687 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28688 movl %edx, %ecx
28689 \ins\()l %esi, %ebx
28690 \insc\()l %edi, %ecx
28691 +
28692 +.ifb \unchecked
28693 +#ifdef CONFIG_PAX_REFCOUNT
28694 + into
28695 +2:
28696 + _ASM_EXTABLE(2b, 3f)
28697 +#endif
28698 +.endif
28699 +
28700 LOCK_PREFIX
28701 cmpxchg8b (%ebp)
28702 jne 1b
28703 -
28704 -10:
28705 movl %ebx, %eax
28706 movl %ecx, %edx
28707 +
28708 +.ifb \unchecked
28709 +#ifdef CONFIG_PAX_REFCOUNT
28710 +3:
28711 +#endif
28712 +.endif
28713 +
28714 RESTORE edi
28715 RESTORE esi
28716 RESTORE ebx
28717 RESTORE ebp
28718 + pax_force_retaddr
28719 ret
28720 CFI_ENDPROC
28721 -ENDPROC(atomic64_\func\()_return_cx8)
28722 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28723 .endm
28724
28725 addsub_return add add adc
28726 addsub_return sub sub sbb
28727 +addsub_return add add adc _unchecked
28728 +addsub_return sub sub sbb _unchecked
28729
28730 -.macro incdec_return func ins insc
28731 -ENTRY(atomic64_\func\()_return_cx8)
28732 +.macro incdec_return func ins insc unchecked=""
28733 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28734 CFI_STARTPROC
28735 SAVE ebx
28736
28737 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28738 movl %edx, %ecx
28739 \ins\()l $1, %ebx
28740 \insc\()l $0, %ecx
28741 +
28742 +.ifb \unchecked
28743 +#ifdef CONFIG_PAX_REFCOUNT
28744 + into
28745 +2:
28746 + _ASM_EXTABLE(2b, 3f)
28747 +#endif
28748 +.endif
28749 +
28750 LOCK_PREFIX
28751 cmpxchg8b (%esi)
28752 jne 1b
28753
28754 -10:
28755 movl %ebx, %eax
28756 movl %ecx, %edx
28757 +
28758 +.ifb \unchecked
28759 +#ifdef CONFIG_PAX_REFCOUNT
28760 +3:
28761 +#endif
28762 +.endif
28763 +
28764 RESTORE ebx
28765 + pax_force_retaddr
28766 ret
28767 CFI_ENDPROC
28768 -ENDPROC(atomic64_\func\()_return_cx8)
28769 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28770 .endm
28771
28772 incdec_return inc add adc
28773 incdec_return dec sub sbb
28774 +incdec_return inc add adc _unchecked
28775 +incdec_return dec sub sbb _unchecked
28776
28777 ENTRY(atomic64_dec_if_positive_cx8)
28778 CFI_STARTPROC
28779 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28780 movl %edx, %ecx
28781 subl $1, %ebx
28782 sbb $0, %ecx
28783 +
28784 +#ifdef CONFIG_PAX_REFCOUNT
28785 + into
28786 +1234:
28787 + _ASM_EXTABLE(1234b, 2f)
28788 +#endif
28789 +
28790 js 2f
28791 LOCK_PREFIX
28792 cmpxchg8b (%esi)
28793 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28794 movl %ebx, %eax
28795 movl %ecx, %edx
28796 RESTORE ebx
28797 + pax_force_retaddr
28798 ret
28799 CFI_ENDPROC
28800 ENDPROC(atomic64_dec_if_positive_cx8)
28801 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28802 movl %edx, %ecx
28803 addl %ebp, %ebx
28804 adcl %edi, %ecx
28805 +
28806 +#ifdef CONFIG_PAX_REFCOUNT
28807 + into
28808 +1234:
28809 + _ASM_EXTABLE(1234b, 3f)
28810 +#endif
28811 +
28812 LOCK_PREFIX
28813 cmpxchg8b (%esi)
28814 jne 1b
28815 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28816 CFI_ADJUST_CFA_OFFSET -8
28817 RESTORE ebx
28818 RESTORE ebp
28819 + pax_force_retaddr
28820 ret
28821 4:
28822 cmpl %edx, 4(%esp)
28823 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28824 xorl %ecx, %ecx
28825 addl $1, %ebx
28826 adcl %edx, %ecx
28827 +
28828 +#ifdef CONFIG_PAX_REFCOUNT
28829 + into
28830 +1234:
28831 + _ASM_EXTABLE(1234b, 3f)
28832 +#endif
28833 +
28834 LOCK_PREFIX
28835 cmpxchg8b (%esi)
28836 jne 1b
28837 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28838 movl $1, %eax
28839 3:
28840 RESTORE ebx
28841 + pax_force_retaddr
28842 ret
28843 CFI_ENDPROC
28844 ENDPROC(atomic64_inc_not_zero_cx8)
28845 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28846 index e78b8ee..7e173a8 100644
28847 --- a/arch/x86/lib/checksum_32.S
28848 +++ b/arch/x86/lib/checksum_32.S
28849 @@ -29,7 +29,8 @@
28850 #include <asm/dwarf2.h>
28851 #include <asm/errno.h>
28852 #include <asm/asm.h>
28853 -
28854 +#include <asm/segment.h>
28855 +
28856 /*
28857 * computes a partial checksum, e.g. for TCP/UDP fragments
28858 */
28859 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28860
28861 #define ARGBASE 16
28862 #define FP 12
28863 -
28864 -ENTRY(csum_partial_copy_generic)
28865 +
28866 +ENTRY(csum_partial_copy_generic_to_user)
28867 CFI_STARTPROC
28868 +
28869 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28870 + pushl_cfi %gs
28871 + popl_cfi %es
28872 + jmp csum_partial_copy_generic
28873 +#endif
28874 +
28875 +ENTRY(csum_partial_copy_generic_from_user)
28876 +
28877 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28878 + pushl_cfi %gs
28879 + popl_cfi %ds
28880 +#endif
28881 +
28882 +ENTRY(csum_partial_copy_generic)
28883 subl $4,%esp
28884 CFI_ADJUST_CFA_OFFSET 4
28885 pushl_cfi %edi
28886 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28887 jmp 4f
28888 SRC(1: movw (%esi), %bx )
28889 addl $2, %esi
28890 -DST( movw %bx, (%edi) )
28891 +DST( movw %bx, %es:(%edi) )
28892 addl $2, %edi
28893 addw %bx, %ax
28894 adcl $0, %eax
28895 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28896 SRC(1: movl (%esi), %ebx )
28897 SRC( movl 4(%esi), %edx )
28898 adcl %ebx, %eax
28899 -DST( movl %ebx, (%edi) )
28900 +DST( movl %ebx, %es:(%edi) )
28901 adcl %edx, %eax
28902 -DST( movl %edx, 4(%edi) )
28903 +DST( movl %edx, %es:4(%edi) )
28904
28905 SRC( movl 8(%esi), %ebx )
28906 SRC( movl 12(%esi), %edx )
28907 adcl %ebx, %eax
28908 -DST( movl %ebx, 8(%edi) )
28909 +DST( movl %ebx, %es:8(%edi) )
28910 adcl %edx, %eax
28911 -DST( movl %edx, 12(%edi) )
28912 +DST( movl %edx, %es:12(%edi) )
28913
28914 SRC( movl 16(%esi), %ebx )
28915 SRC( movl 20(%esi), %edx )
28916 adcl %ebx, %eax
28917 -DST( movl %ebx, 16(%edi) )
28918 +DST( movl %ebx, %es:16(%edi) )
28919 adcl %edx, %eax
28920 -DST( movl %edx, 20(%edi) )
28921 +DST( movl %edx, %es:20(%edi) )
28922
28923 SRC( movl 24(%esi), %ebx )
28924 SRC( movl 28(%esi), %edx )
28925 adcl %ebx, %eax
28926 -DST( movl %ebx, 24(%edi) )
28927 +DST( movl %ebx, %es:24(%edi) )
28928 adcl %edx, %eax
28929 -DST( movl %edx, 28(%edi) )
28930 +DST( movl %edx, %es:28(%edi) )
28931
28932 lea 32(%esi), %esi
28933 lea 32(%edi), %edi
28934 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28935 shrl $2, %edx # This clears CF
28936 SRC(3: movl (%esi), %ebx )
28937 adcl %ebx, %eax
28938 -DST( movl %ebx, (%edi) )
28939 +DST( movl %ebx, %es:(%edi) )
28940 lea 4(%esi), %esi
28941 lea 4(%edi), %edi
28942 dec %edx
28943 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28944 jb 5f
28945 SRC( movw (%esi), %cx )
28946 leal 2(%esi), %esi
28947 -DST( movw %cx, (%edi) )
28948 +DST( movw %cx, %es:(%edi) )
28949 leal 2(%edi), %edi
28950 je 6f
28951 shll $16,%ecx
28952 SRC(5: movb (%esi), %cl )
28953 -DST( movb %cl, (%edi) )
28954 +DST( movb %cl, %es:(%edi) )
28955 6: addl %ecx, %eax
28956 adcl $0, %eax
28957 7:
28958 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28959
28960 6001:
28961 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28962 - movl $-EFAULT, (%ebx)
28963 + movl $-EFAULT, %ss:(%ebx)
28964
28965 # zero the complete destination - computing the rest
28966 # is too much work
28967 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28968
28969 6002:
28970 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28971 - movl $-EFAULT,(%ebx)
28972 + movl $-EFAULT,%ss:(%ebx)
28973 jmp 5000b
28974
28975 .previous
28976
28977 + pushl_cfi %ss
28978 + popl_cfi %ds
28979 + pushl_cfi %ss
28980 + popl_cfi %es
28981 popl_cfi %ebx
28982 CFI_RESTORE ebx
28983 popl_cfi %esi
28984 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28985 popl_cfi %ecx # equivalent to addl $4,%esp
28986 ret
28987 CFI_ENDPROC
28988 -ENDPROC(csum_partial_copy_generic)
28989 +ENDPROC(csum_partial_copy_generic_to_user)
28990
28991 #else
28992
28993 /* Version for PentiumII/PPro */
28994
28995 #define ROUND1(x) \
28996 + nop; nop; nop; \
28997 SRC(movl x(%esi), %ebx ) ; \
28998 addl %ebx, %eax ; \
28999 - DST(movl %ebx, x(%edi) ) ;
29000 + DST(movl %ebx, %es:x(%edi)) ;
29001
29002 #define ROUND(x) \
29003 + nop; nop; nop; \
29004 SRC(movl x(%esi), %ebx ) ; \
29005 adcl %ebx, %eax ; \
29006 - DST(movl %ebx, x(%edi) ) ;
29007 + DST(movl %ebx, %es:x(%edi)) ;
29008
29009 #define ARGBASE 12
29010 -
29011 -ENTRY(csum_partial_copy_generic)
29012 +
29013 +ENTRY(csum_partial_copy_generic_to_user)
29014 CFI_STARTPROC
29015 +
29016 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29017 + pushl_cfi %gs
29018 + popl_cfi %es
29019 + jmp csum_partial_copy_generic
29020 +#endif
29021 +
29022 +ENTRY(csum_partial_copy_generic_from_user)
29023 +
29024 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29025 + pushl_cfi %gs
29026 + popl_cfi %ds
29027 +#endif
29028 +
29029 +ENTRY(csum_partial_copy_generic)
29030 pushl_cfi %ebx
29031 CFI_REL_OFFSET ebx, 0
29032 pushl_cfi %edi
29033 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29034 subl %ebx, %edi
29035 lea -1(%esi),%edx
29036 andl $-32,%edx
29037 - lea 3f(%ebx,%ebx), %ebx
29038 + lea 3f(%ebx,%ebx,2), %ebx
29039 testl %esi, %esi
29040 jmp *%ebx
29041 1: addl $64,%esi
29042 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29043 jb 5f
29044 SRC( movw (%esi), %dx )
29045 leal 2(%esi), %esi
29046 -DST( movw %dx, (%edi) )
29047 +DST( movw %dx, %es:(%edi) )
29048 leal 2(%edi), %edi
29049 je 6f
29050 shll $16,%edx
29051 5:
29052 SRC( movb (%esi), %dl )
29053 -DST( movb %dl, (%edi) )
29054 +DST( movb %dl, %es:(%edi) )
29055 6: addl %edx, %eax
29056 adcl $0, %eax
29057 7:
29058 .section .fixup, "ax"
29059 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29060 - movl $-EFAULT, (%ebx)
29061 + movl $-EFAULT, %ss:(%ebx)
29062 # zero the complete destination (computing the rest is too much work)
29063 movl ARGBASE+8(%esp),%edi # dst
29064 movl ARGBASE+12(%esp),%ecx # len
29065 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29066 rep; stosb
29067 jmp 7b
29068 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29069 - movl $-EFAULT, (%ebx)
29070 + movl $-EFAULT, %ss:(%ebx)
29071 jmp 7b
29072 .previous
29073
29074 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29075 + pushl_cfi %ss
29076 + popl_cfi %ds
29077 + pushl_cfi %ss
29078 + popl_cfi %es
29079 +#endif
29080 +
29081 popl_cfi %esi
29082 CFI_RESTORE esi
29083 popl_cfi %edi
29084 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29085 CFI_RESTORE ebx
29086 ret
29087 CFI_ENDPROC
29088 -ENDPROC(csum_partial_copy_generic)
29089 +ENDPROC(csum_partial_copy_generic_to_user)
29090
29091 #undef ROUND
29092 #undef ROUND1
29093 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29094 index f2145cf..cea889d 100644
29095 --- a/arch/x86/lib/clear_page_64.S
29096 +++ b/arch/x86/lib/clear_page_64.S
29097 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29098 movl $4096/8,%ecx
29099 xorl %eax,%eax
29100 rep stosq
29101 + pax_force_retaddr
29102 ret
29103 CFI_ENDPROC
29104 ENDPROC(clear_page_c)
29105 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29106 movl $4096,%ecx
29107 xorl %eax,%eax
29108 rep stosb
29109 + pax_force_retaddr
29110 ret
29111 CFI_ENDPROC
29112 ENDPROC(clear_page_c_e)
29113 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29114 leaq 64(%rdi),%rdi
29115 jnz .Lloop
29116 nop
29117 + pax_force_retaddr
29118 ret
29119 CFI_ENDPROC
29120 .Lclear_page_end:
29121 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29122
29123 #include <asm/cpufeature.h>
29124
29125 - .section .altinstr_replacement,"ax"
29126 + .section .altinstr_replacement,"a"
29127 1: .byte 0xeb /* jmp <disp8> */
29128 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29129 2: .byte 0xeb /* jmp <disp8> */
29130 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29131 index 1e572c5..2a162cd 100644
29132 --- a/arch/x86/lib/cmpxchg16b_emu.S
29133 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29134 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29135
29136 popf
29137 mov $1, %al
29138 + pax_force_retaddr
29139 ret
29140
29141 not_same:
29142 popf
29143 xor %al,%al
29144 + pax_force_retaddr
29145 ret
29146
29147 CFI_ENDPROC
29148 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29149 index 176cca6..e0d658e 100644
29150 --- a/arch/x86/lib/copy_page_64.S
29151 +++ b/arch/x86/lib/copy_page_64.S
29152 @@ -9,6 +9,7 @@ copy_page_rep:
29153 CFI_STARTPROC
29154 movl $4096/8, %ecx
29155 rep movsq
29156 + pax_force_retaddr
29157 ret
29158 CFI_ENDPROC
29159 ENDPROC(copy_page_rep)
29160 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29161 CFI_ADJUST_CFA_OFFSET 2*8
29162 movq %rbx, (%rsp)
29163 CFI_REL_OFFSET rbx, 0
29164 - movq %r12, 1*8(%rsp)
29165 - CFI_REL_OFFSET r12, 1*8
29166 + movq %r13, 1*8(%rsp)
29167 + CFI_REL_OFFSET r13, 1*8
29168
29169 movl $(4096/64)-5, %ecx
29170 .p2align 4
29171 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29172 movq 0x8*4(%rsi), %r9
29173 movq 0x8*5(%rsi), %r10
29174 movq 0x8*6(%rsi), %r11
29175 - movq 0x8*7(%rsi), %r12
29176 + movq 0x8*7(%rsi), %r13
29177
29178 prefetcht0 5*64(%rsi)
29179
29180 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29181 movq %r9, 0x8*4(%rdi)
29182 movq %r10, 0x8*5(%rdi)
29183 movq %r11, 0x8*6(%rdi)
29184 - movq %r12, 0x8*7(%rdi)
29185 + movq %r13, 0x8*7(%rdi)
29186
29187 leaq 64 (%rsi), %rsi
29188 leaq 64 (%rdi), %rdi
29189 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29190 movq 0x8*4(%rsi), %r9
29191 movq 0x8*5(%rsi), %r10
29192 movq 0x8*6(%rsi), %r11
29193 - movq 0x8*7(%rsi), %r12
29194 + movq 0x8*7(%rsi), %r13
29195
29196 movq %rax, 0x8*0(%rdi)
29197 movq %rbx, 0x8*1(%rdi)
29198 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29199 movq %r9, 0x8*4(%rdi)
29200 movq %r10, 0x8*5(%rdi)
29201 movq %r11, 0x8*6(%rdi)
29202 - movq %r12, 0x8*7(%rdi)
29203 + movq %r13, 0x8*7(%rdi)
29204
29205 leaq 64(%rdi), %rdi
29206 leaq 64(%rsi), %rsi
29207 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29208
29209 movq (%rsp), %rbx
29210 CFI_RESTORE rbx
29211 - movq 1*8(%rsp), %r12
29212 - CFI_RESTORE r12
29213 + movq 1*8(%rsp), %r13
29214 + CFI_RESTORE r13
29215 addq $2*8, %rsp
29216 CFI_ADJUST_CFA_OFFSET -2*8
29217 + pax_force_retaddr
29218 ret
29219 .Lcopy_page_end:
29220 CFI_ENDPROC
29221 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29222
29223 #include <asm/cpufeature.h>
29224
29225 - .section .altinstr_replacement,"ax"
29226 + .section .altinstr_replacement,"a"
29227 1: .byte 0xeb /* jmp <disp8> */
29228 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29229 2:
29230 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29231 index a30ca15..407412b 100644
29232 --- a/arch/x86/lib/copy_user_64.S
29233 +++ b/arch/x86/lib/copy_user_64.S
29234 @@ -18,31 +18,7 @@
29235 #include <asm/alternative-asm.h>
29236 #include <asm/asm.h>
29237 #include <asm/smap.h>
29238 -
29239 -/*
29240 - * By placing feature2 after feature1 in altinstructions section, we logically
29241 - * implement:
29242 - * If CPU has feature2, jmp to alt2 is used
29243 - * else if CPU has feature1, jmp to alt1 is used
29244 - * else jmp to orig is used.
29245 - */
29246 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29247 -0:
29248 - .byte 0xe9 /* 32bit jump */
29249 - .long \orig-1f /* by default jump to orig */
29250 -1:
29251 - .section .altinstr_replacement,"ax"
29252 -2: .byte 0xe9 /* near jump with 32bit immediate */
29253 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29254 -3: .byte 0xe9 /* near jump with 32bit immediate */
29255 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29256 - .previous
29257 -
29258 - .section .altinstructions,"a"
29259 - altinstruction_entry 0b,2b,\feature1,5,5
29260 - altinstruction_entry 0b,3b,\feature2,5,5
29261 - .previous
29262 - .endm
29263 +#include <asm/pgtable.h>
29264
29265 .macro ALIGN_DESTINATION
29266 #ifdef FIX_ALIGNMENT
29267 @@ -70,52 +46,6 @@
29268 #endif
29269 .endm
29270
29271 -/* Standard copy_to_user with segment limit checking */
29272 -ENTRY(_copy_to_user)
29273 - CFI_STARTPROC
29274 - GET_THREAD_INFO(%rax)
29275 - movq %rdi,%rcx
29276 - addq %rdx,%rcx
29277 - jc bad_to_user
29278 - cmpq TI_addr_limit(%rax),%rcx
29279 - ja bad_to_user
29280 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29281 - copy_user_generic_unrolled,copy_user_generic_string, \
29282 - copy_user_enhanced_fast_string
29283 - CFI_ENDPROC
29284 -ENDPROC(_copy_to_user)
29285 -
29286 -/* Standard copy_from_user with segment limit checking */
29287 -ENTRY(_copy_from_user)
29288 - CFI_STARTPROC
29289 - GET_THREAD_INFO(%rax)
29290 - movq %rsi,%rcx
29291 - addq %rdx,%rcx
29292 - jc bad_from_user
29293 - cmpq TI_addr_limit(%rax),%rcx
29294 - ja bad_from_user
29295 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29296 - copy_user_generic_unrolled,copy_user_generic_string, \
29297 - copy_user_enhanced_fast_string
29298 - CFI_ENDPROC
29299 -ENDPROC(_copy_from_user)
29300 -
29301 - .section .fixup,"ax"
29302 - /* must zero dest */
29303 -ENTRY(bad_from_user)
29304 -bad_from_user:
29305 - CFI_STARTPROC
29306 - movl %edx,%ecx
29307 - xorl %eax,%eax
29308 - rep
29309 - stosb
29310 -bad_to_user:
29311 - movl %edx,%eax
29312 - ret
29313 - CFI_ENDPROC
29314 -ENDPROC(bad_from_user)
29315 - .previous
29316 -
29317 /*
29318 * copy_user_generic_unrolled - memory copy with exception handling.
29319 * This version is for CPUs like P4 that don't have efficient micro
29320 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29321 */
29322 ENTRY(copy_user_generic_unrolled)
29323 CFI_STARTPROC
29324 + ASM_PAX_OPEN_USERLAND
29325 ASM_STAC
29326 cmpl $8,%edx
29327 jb 20f /* less then 8 bytes, go to byte copy loop */
29328 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29329 jnz 21b
29330 23: xor %eax,%eax
29331 ASM_CLAC
29332 + ASM_PAX_CLOSE_USERLAND
29333 + pax_force_retaddr
29334 ret
29335
29336 .section .fixup,"ax"
29337 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29338 */
29339 ENTRY(copy_user_generic_string)
29340 CFI_STARTPROC
29341 + ASM_PAX_OPEN_USERLAND
29342 ASM_STAC
29343 andl %edx,%edx
29344 jz 4f
29345 @@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
29346 movsb
29347 4: xorl %eax,%eax
29348 ASM_CLAC
29349 + ASM_PAX_CLOSE_USERLAND
29350 + pax_force_retaddr
29351 ret
29352
29353 .section .fixup,"ax"
29354 @@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
29355 */
29356 ENTRY(copy_user_enhanced_fast_string)
29357 CFI_STARTPROC
29358 + ASM_PAX_OPEN_USERLAND
29359 ASM_STAC
29360 andl %edx,%edx
29361 jz 2f
29362 @@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
29363 movsb
29364 2: xorl %eax,%eax
29365 ASM_CLAC
29366 + ASM_PAX_CLOSE_USERLAND
29367 + pax_force_retaddr
29368 ret
29369
29370 .section .fixup,"ax"
29371 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29372 index 6a4f43c..c70fb52 100644
29373 --- a/arch/x86/lib/copy_user_nocache_64.S
29374 +++ b/arch/x86/lib/copy_user_nocache_64.S
29375 @@ -8,6 +8,7 @@
29376
29377 #include <linux/linkage.h>
29378 #include <asm/dwarf2.h>
29379 +#include <asm/alternative-asm.h>
29380
29381 #define FIX_ALIGNMENT 1
29382
29383 @@ -16,6 +17,7 @@
29384 #include <asm/thread_info.h>
29385 #include <asm/asm.h>
29386 #include <asm/smap.h>
29387 +#include <asm/pgtable.h>
29388
29389 .macro ALIGN_DESTINATION
29390 #ifdef FIX_ALIGNMENT
29391 @@ -49,6 +51,16 @@
29392 */
29393 ENTRY(__copy_user_nocache)
29394 CFI_STARTPROC
29395 +
29396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29397 + mov pax_user_shadow_base,%rcx
29398 + cmp %rcx,%rsi
29399 + jae 1f
29400 + add %rcx,%rsi
29401 +1:
29402 +#endif
29403 +
29404 + ASM_PAX_OPEN_USERLAND
29405 ASM_STAC
29406 cmpl $8,%edx
29407 jb 20f /* less then 8 bytes, go to byte copy loop */
29408 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29409 jnz 21b
29410 23: xorl %eax,%eax
29411 ASM_CLAC
29412 + ASM_PAX_CLOSE_USERLAND
29413 sfence
29414 + pax_force_retaddr
29415 ret
29416
29417 .section .fixup,"ax"
29418 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29419 index 2419d5f..fe52d0e 100644
29420 --- a/arch/x86/lib/csum-copy_64.S
29421 +++ b/arch/x86/lib/csum-copy_64.S
29422 @@ -9,6 +9,7 @@
29423 #include <asm/dwarf2.h>
29424 #include <asm/errno.h>
29425 #include <asm/asm.h>
29426 +#include <asm/alternative-asm.h>
29427
29428 /*
29429 * Checksum copy with exception handling.
29430 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29431 CFI_ADJUST_CFA_OFFSET 7*8
29432 movq %rbx, 2*8(%rsp)
29433 CFI_REL_OFFSET rbx, 2*8
29434 - movq %r12, 3*8(%rsp)
29435 - CFI_REL_OFFSET r12, 3*8
29436 + movq %r15, 3*8(%rsp)
29437 + CFI_REL_OFFSET r15, 3*8
29438 movq %r14, 4*8(%rsp)
29439 CFI_REL_OFFSET r14, 4*8
29440 movq %r13, 5*8(%rsp)
29441 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29442 movl %edx, %ecx
29443
29444 xorl %r9d, %r9d
29445 - movq %rcx, %r12
29446 + movq %rcx, %r15
29447
29448 - shrq $6, %r12
29449 + shrq $6, %r15
29450 jz .Lhandle_tail /* < 64 */
29451
29452 clc
29453
29454 /* main loop. clear in 64 byte blocks */
29455 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29456 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29457 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29458 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29459 .p2align 4
29460 .Lloop:
29461 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29462 adcq %r14, %rax
29463 adcq %r13, %rax
29464
29465 - decl %r12d
29466 + decl %r15d
29467
29468 dest
29469 movq %rbx, (%rsi)
29470 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29471 .Lende:
29472 movq 2*8(%rsp), %rbx
29473 CFI_RESTORE rbx
29474 - movq 3*8(%rsp), %r12
29475 - CFI_RESTORE r12
29476 + movq 3*8(%rsp), %r15
29477 + CFI_RESTORE r15
29478 movq 4*8(%rsp), %r14
29479 CFI_RESTORE r14
29480 movq 5*8(%rsp), %r13
29481 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29482 CFI_RESTORE rbp
29483 addq $7*8, %rsp
29484 CFI_ADJUST_CFA_OFFSET -7*8
29485 + pax_force_retaddr
29486 ret
29487 CFI_RESTORE_STATE
29488
29489 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29490 index 7609e0e..b449b98 100644
29491 --- a/arch/x86/lib/csum-wrappers_64.c
29492 +++ b/arch/x86/lib/csum-wrappers_64.c
29493 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29494 len -= 2;
29495 }
29496 }
29497 + pax_open_userland();
29498 stac();
29499 - isum = csum_partial_copy_generic((__force const void *)src,
29500 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29501 dst, len, isum, errp, NULL);
29502 clac();
29503 + pax_close_userland();
29504 if (unlikely(*errp))
29505 goto out_err;
29506
29507 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29508 }
29509
29510 *errp = 0;
29511 + pax_open_userland();
29512 stac();
29513 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29514 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29515 len, isum, NULL, errp);
29516 clac();
29517 + pax_close_userland();
29518 return ret;
29519 }
29520 EXPORT_SYMBOL(csum_partial_copy_to_user);
29521 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29522 index a451235..1daa956 100644
29523 --- a/arch/x86/lib/getuser.S
29524 +++ b/arch/x86/lib/getuser.S
29525 @@ -33,17 +33,40 @@
29526 #include <asm/thread_info.h>
29527 #include <asm/asm.h>
29528 #include <asm/smap.h>
29529 +#include <asm/segment.h>
29530 +#include <asm/pgtable.h>
29531 +#include <asm/alternative-asm.h>
29532 +
29533 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29534 +#define __copyuser_seg gs;
29535 +#else
29536 +#define __copyuser_seg
29537 +#endif
29538
29539 .text
29540 ENTRY(__get_user_1)
29541 CFI_STARTPROC
29542 +
29543 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29544 GET_THREAD_INFO(%_ASM_DX)
29545 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29546 jae bad_get_user
29547 ASM_STAC
29548 -1: movzbl (%_ASM_AX),%edx
29549 +
29550 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29551 + mov pax_user_shadow_base,%_ASM_DX
29552 + cmp %_ASM_DX,%_ASM_AX
29553 + jae 1234f
29554 + add %_ASM_DX,%_ASM_AX
29555 +1234:
29556 +#endif
29557 +
29558 +#endif
29559 +
29560 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29561 xor %eax,%eax
29562 ASM_CLAC
29563 + pax_force_retaddr
29564 ret
29565 CFI_ENDPROC
29566 ENDPROC(__get_user_1)
29567 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29568 ENTRY(__get_user_2)
29569 CFI_STARTPROC
29570 add $1,%_ASM_AX
29571 +
29572 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29573 jc bad_get_user
29574 GET_THREAD_INFO(%_ASM_DX)
29575 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29576 jae bad_get_user
29577 ASM_STAC
29578 -2: movzwl -1(%_ASM_AX),%edx
29579 +
29580 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29581 + mov pax_user_shadow_base,%_ASM_DX
29582 + cmp %_ASM_DX,%_ASM_AX
29583 + jae 1234f
29584 + add %_ASM_DX,%_ASM_AX
29585 +1234:
29586 +#endif
29587 +
29588 +#endif
29589 +
29590 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29591 xor %eax,%eax
29592 ASM_CLAC
29593 + pax_force_retaddr
29594 ret
29595 CFI_ENDPROC
29596 ENDPROC(__get_user_2)
29597 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29598 ENTRY(__get_user_4)
29599 CFI_STARTPROC
29600 add $3,%_ASM_AX
29601 +
29602 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29603 jc bad_get_user
29604 GET_THREAD_INFO(%_ASM_DX)
29605 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29606 jae bad_get_user
29607 ASM_STAC
29608 -3: movl -3(%_ASM_AX),%edx
29609 +
29610 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29611 + mov pax_user_shadow_base,%_ASM_DX
29612 + cmp %_ASM_DX,%_ASM_AX
29613 + jae 1234f
29614 + add %_ASM_DX,%_ASM_AX
29615 +1234:
29616 +#endif
29617 +
29618 +#endif
29619 +
29620 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29621 xor %eax,%eax
29622 ASM_CLAC
29623 + pax_force_retaddr
29624 ret
29625 CFI_ENDPROC
29626 ENDPROC(__get_user_4)
29627 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29628 GET_THREAD_INFO(%_ASM_DX)
29629 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29630 jae bad_get_user
29631 +
29632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29633 + mov pax_user_shadow_base,%_ASM_DX
29634 + cmp %_ASM_DX,%_ASM_AX
29635 + jae 1234f
29636 + add %_ASM_DX,%_ASM_AX
29637 +1234:
29638 +#endif
29639 +
29640 ASM_STAC
29641 4: movq -7(%_ASM_AX),%rdx
29642 xor %eax,%eax
29643 ASM_CLAC
29644 + pax_force_retaddr
29645 ret
29646 #else
29647 add $7,%_ASM_AX
29648 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29649 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29650 jae bad_get_user_8
29651 ASM_STAC
29652 -4: movl -7(%_ASM_AX),%edx
29653 -5: movl -3(%_ASM_AX),%ecx
29654 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29655 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29656 xor %eax,%eax
29657 ASM_CLAC
29658 + pax_force_retaddr
29659 ret
29660 #endif
29661 CFI_ENDPROC
29662 @@ -113,6 +175,7 @@ bad_get_user:
29663 xor %edx,%edx
29664 mov $(-EFAULT),%_ASM_AX
29665 ASM_CLAC
29666 + pax_force_retaddr
29667 ret
29668 CFI_ENDPROC
29669 END(bad_get_user)
29670 @@ -124,6 +187,7 @@ bad_get_user_8:
29671 xor %ecx,%ecx
29672 mov $(-EFAULT),%_ASM_AX
29673 ASM_CLAC
29674 + pax_force_retaddr
29675 ret
29676 CFI_ENDPROC
29677 END(bad_get_user_8)
29678 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29679 index 54fcffe..7be149e 100644
29680 --- a/arch/x86/lib/insn.c
29681 +++ b/arch/x86/lib/insn.c
29682 @@ -20,8 +20,10 @@
29683
29684 #ifdef __KERNEL__
29685 #include <linux/string.h>
29686 +#include <asm/pgtable_types.h>
29687 #else
29688 #include <string.h>
29689 +#define ktla_ktva(addr) addr
29690 #endif
29691 #include <asm/inat.h>
29692 #include <asm/insn.h>
29693 @@ -53,8 +55,8 @@
29694 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29695 {
29696 memset(insn, 0, sizeof(*insn));
29697 - insn->kaddr = kaddr;
29698 - insn->next_byte = kaddr;
29699 + insn->kaddr = ktla_ktva(kaddr);
29700 + insn->next_byte = ktla_ktva(kaddr);
29701 insn->x86_64 = x86_64 ? 1 : 0;
29702 insn->opnd_bytes = 4;
29703 if (x86_64)
29704 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29705 index 05a95e7..326f2fa 100644
29706 --- a/arch/x86/lib/iomap_copy_64.S
29707 +++ b/arch/x86/lib/iomap_copy_64.S
29708 @@ -17,6 +17,7 @@
29709
29710 #include <linux/linkage.h>
29711 #include <asm/dwarf2.h>
29712 +#include <asm/alternative-asm.h>
29713
29714 /*
29715 * override generic version in lib/iomap_copy.c
29716 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29717 CFI_STARTPROC
29718 movl %edx,%ecx
29719 rep movsd
29720 + pax_force_retaddr
29721 ret
29722 CFI_ENDPROC
29723 ENDPROC(__iowrite32_copy)
29724 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29725 index 56313a3..0db417e 100644
29726 --- a/arch/x86/lib/memcpy_64.S
29727 +++ b/arch/x86/lib/memcpy_64.S
29728 @@ -24,7 +24,7 @@
29729 * This gets patched over the unrolled variant (below) via the
29730 * alternative instructions framework:
29731 */
29732 - .section .altinstr_replacement, "ax", @progbits
29733 + .section .altinstr_replacement, "a", @progbits
29734 .Lmemcpy_c:
29735 movq %rdi, %rax
29736 movq %rdx, %rcx
29737 @@ -33,6 +33,7 @@
29738 rep movsq
29739 movl %edx, %ecx
29740 rep movsb
29741 + pax_force_retaddr
29742 ret
29743 .Lmemcpy_e:
29744 .previous
29745 @@ -44,11 +45,12 @@
29746 * This gets patched over the unrolled variant (below) via the
29747 * alternative instructions framework:
29748 */
29749 - .section .altinstr_replacement, "ax", @progbits
29750 + .section .altinstr_replacement, "a", @progbits
29751 .Lmemcpy_c_e:
29752 movq %rdi, %rax
29753 movq %rdx, %rcx
29754 rep movsb
29755 + pax_force_retaddr
29756 ret
29757 .Lmemcpy_e_e:
29758 .previous
29759 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29760 movq %r9, 1*8(%rdi)
29761 movq %r10, -2*8(%rdi, %rdx)
29762 movq %r11, -1*8(%rdi, %rdx)
29763 + pax_force_retaddr
29764 retq
29765 .p2align 4
29766 .Lless_16bytes:
29767 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29768 movq -1*8(%rsi, %rdx), %r9
29769 movq %r8, 0*8(%rdi)
29770 movq %r9, -1*8(%rdi, %rdx)
29771 + pax_force_retaddr
29772 retq
29773 .p2align 4
29774 .Lless_8bytes:
29775 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29776 movl -4(%rsi, %rdx), %r8d
29777 movl %ecx, (%rdi)
29778 movl %r8d, -4(%rdi, %rdx)
29779 + pax_force_retaddr
29780 retq
29781 .p2align 4
29782 .Lless_3bytes:
29783 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29784 movb %cl, (%rdi)
29785
29786 .Lend:
29787 + pax_force_retaddr
29788 retq
29789 CFI_ENDPROC
29790 ENDPROC(memcpy)
29791 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29792 index 65268a6..dd1de11 100644
29793 --- a/arch/x86/lib/memmove_64.S
29794 +++ b/arch/x86/lib/memmove_64.S
29795 @@ -202,14 +202,16 @@ ENTRY(memmove)
29796 movb (%rsi), %r11b
29797 movb %r11b, (%rdi)
29798 13:
29799 + pax_force_retaddr
29800 retq
29801 CFI_ENDPROC
29802
29803 - .section .altinstr_replacement,"ax"
29804 + .section .altinstr_replacement,"a"
29805 .Lmemmove_begin_forward_efs:
29806 /* Forward moving data. */
29807 movq %rdx, %rcx
29808 rep movsb
29809 + pax_force_retaddr
29810 retq
29811 .Lmemmove_end_forward_efs:
29812 .previous
29813 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29814 index 2dcb380..2eb79fe 100644
29815 --- a/arch/x86/lib/memset_64.S
29816 +++ b/arch/x86/lib/memset_64.S
29817 @@ -16,7 +16,7 @@
29818 *
29819 * rax original destination
29820 */
29821 - .section .altinstr_replacement, "ax", @progbits
29822 + .section .altinstr_replacement, "a", @progbits
29823 .Lmemset_c:
29824 movq %rdi,%r9
29825 movq %rdx,%rcx
29826 @@ -30,6 +30,7 @@
29827 movl %edx,%ecx
29828 rep stosb
29829 movq %r9,%rax
29830 + pax_force_retaddr
29831 ret
29832 .Lmemset_e:
29833 .previous
29834 @@ -45,13 +46,14 @@
29835 *
29836 * rax original destination
29837 */
29838 - .section .altinstr_replacement, "ax", @progbits
29839 + .section .altinstr_replacement, "a", @progbits
29840 .Lmemset_c_e:
29841 movq %rdi,%r9
29842 movb %sil,%al
29843 movq %rdx,%rcx
29844 rep stosb
29845 movq %r9,%rax
29846 + pax_force_retaddr
29847 ret
29848 .Lmemset_e_e:
29849 .previous
29850 @@ -118,6 +120,7 @@ ENTRY(__memset)
29851
29852 .Lende:
29853 movq %r10,%rax
29854 + pax_force_retaddr
29855 ret
29856
29857 CFI_RESTORE_STATE
29858 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29859 index c9f2d9b..e7fd2c0 100644
29860 --- a/arch/x86/lib/mmx_32.c
29861 +++ b/arch/x86/lib/mmx_32.c
29862 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29863 {
29864 void *p;
29865 int i;
29866 + unsigned long cr0;
29867
29868 if (unlikely(in_interrupt()))
29869 return __memcpy(to, from, len);
29870 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29871 kernel_fpu_begin();
29872
29873 __asm__ __volatile__ (
29874 - "1: prefetch (%0)\n" /* This set is 28 bytes */
29875 - " prefetch 64(%0)\n"
29876 - " prefetch 128(%0)\n"
29877 - " prefetch 192(%0)\n"
29878 - " prefetch 256(%0)\n"
29879 + "1: prefetch (%1)\n" /* This set is 28 bytes */
29880 + " prefetch 64(%1)\n"
29881 + " prefetch 128(%1)\n"
29882 + " prefetch 192(%1)\n"
29883 + " prefetch 256(%1)\n"
29884 "2: \n"
29885 ".section .fixup, \"ax\"\n"
29886 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29887 + "3: \n"
29888 +
29889 +#ifdef CONFIG_PAX_KERNEXEC
29890 + " movl %%cr0, %0\n"
29891 + " movl %0, %%eax\n"
29892 + " andl $0xFFFEFFFF, %%eax\n"
29893 + " movl %%eax, %%cr0\n"
29894 +#endif
29895 +
29896 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29897 +
29898 +#ifdef CONFIG_PAX_KERNEXEC
29899 + " movl %0, %%cr0\n"
29900 +#endif
29901 +
29902 " jmp 2b\n"
29903 ".previous\n"
29904 _ASM_EXTABLE(1b, 3b)
29905 - : : "r" (from));
29906 + : "=&r" (cr0) : "r" (from) : "ax");
29907
29908 for ( ; i > 5; i--) {
29909 __asm__ __volatile__ (
29910 - "1: prefetch 320(%0)\n"
29911 - "2: movq (%0), %%mm0\n"
29912 - " movq 8(%0), %%mm1\n"
29913 - " movq 16(%0), %%mm2\n"
29914 - " movq 24(%0), %%mm3\n"
29915 - " movq %%mm0, (%1)\n"
29916 - " movq %%mm1, 8(%1)\n"
29917 - " movq %%mm2, 16(%1)\n"
29918 - " movq %%mm3, 24(%1)\n"
29919 - " movq 32(%0), %%mm0\n"
29920 - " movq 40(%0), %%mm1\n"
29921 - " movq 48(%0), %%mm2\n"
29922 - " movq 56(%0), %%mm3\n"
29923 - " movq %%mm0, 32(%1)\n"
29924 - " movq %%mm1, 40(%1)\n"
29925 - " movq %%mm2, 48(%1)\n"
29926 - " movq %%mm3, 56(%1)\n"
29927 + "1: prefetch 320(%1)\n"
29928 + "2: movq (%1), %%mm0\n"
29929 + " movq 8(%1), %%mm1\n"
29930 + " movq 16(%1), %%mm2\n"
29931 + " movq 24(%1), %%mm3\n"
29932 + " movq %%mm0, (%2)\n"
29933 + " movq %%mm1, 8(%2)\n"
29934 + " movq %%mm2, 16(%2)\n"
29935 + " movq %%mm3, 24(%2)\n"
29936 + " movq 32(%1), %%mm0\n"
29937 + " movq 40(%1), %%mm1\n"
29938 + " movq 48(%1), %%mm2\n"
29939 + " movq 56(%1), %%mm3\n"
29940 + " movq %%mm0, 32(%2)\n"
29941 + " movq %%mm1, 40(%2)\n"
29942 + " movq %%mm2, 48(%2)\n"
29943 + " movq %%mm3, 56(%2)\n"
29944 ".section .fixup, \"ax\"\n"
29945 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29946 + "3:\n"
29947 +
29948 +#ifdef CONFIG_PAX_KERNEXEC
29949 + " movl %%cr0, %0\n"
29950 + " movl %0, %%eax\n"
29951 + " andl $0xFFFEFFFF, %%eax\n"
29952 + " movl %%eax, %%cr0\n"
29953 +#endif
29954 +
29955 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29956 +
29957 +#ifdef CONFIG_PAX_KERNEXEC
29958 + " movl %0, %%cr0\n"
29959 +#endif
29960 +
29961 " jmp 2b\n"
29962 ".previous\n"
29963 _ASM_EXTABLE(1b, 3b)
29964 - : : "r" (from), "r" (to) : "memory");
29965 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29966
29967 from += 64;
29968 to += 64;
29969 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29970 static void fast_copy_page(void *to, void *from)
29971 {
29972 int i;
29973 + unsigned long cr0;
29974
29975 kernel_fpu_begin();
29976
29977 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29978 * but that is for later. -AV
29979 */
29980 __asm__ __volatile__(
29981 - "1: prefetch (%0)\n"
29982 - " prefetch 64(%0)\n"
29983 - " prefetch 128(%0)\n"
29984 - " prefetch 192(%0)\n"
29985 - " prefetch 256(%0)\n"
29986 + "1: prefetch (%1)\n"
29987 + " prefetch 64(%1)\n"
29988 + " prefetch 128(%1)\n"
29989 + " prefetch 192(%1)\n"
29990 + " prefetch 256(%1)\n"
29991 "2: \n"
29992 ".section .fixup, \"ax\"\n"
29993 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29994 + "3: \n"
29995 +
29996 +#ifdef CONFIG_PAX_KERNEXEC
29997 + " movl %%cr0, %0\n"
29998 + " movl %0, %%eax\n"
29999 + " andl $0xFFFEFFFF, %%eax\n"
30000 + " movl %%eax, %%cr0\n"
30001 +#endif
30002 +
30003 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30004 +
30005 +#ifdef CONFIG_PAX_KERNEXEC
30006 + " movl %0, %%cr0\n"
30007 +#endif
30008 +
30009 " jmp 2b\n"
30010 ".previous\n"
30011 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30012 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30013
30014 for (i = 0; i < (4096-320)/64; i++) {
30015 __asm__ __volatile__ (
30016 - "1: prefetch 320(%0)\n"
30017 - "2: movq (%0), %%mm0\n"
30018 - " movntq %%mm0, (%1)\n"
30019 - " movq 8(%0), %%mm1\n"
30020 - " movntq %%mm1, 8(%1)\n"
30021 - " movq 16(%0), %%mm2\n"
30022 - " movntq %%mm2, 16(%1)\n"
30023 - " movq 24(%0), %%mm3\n"
30024 - " movntq %%mm3, 24(%1)\n"
30025 - " movq 32(%0), %%mm4\n"
30026 - " movntq %%mm4, 32(%1)\n"
30027 - " movq 40(%0), %%mm5\n"
30028 - " movntq %%mm5, 40(%1)\n"
30029 - " movq 48(%0), %%mm6\n"
30030 - " movntq %%mm6, 48(%1)\n"
30031 - " movq 56(%0), %%mm7\n"
30032 - " movntq %%mm7, 56(%1)\n"
30033 + "1: prefetch 320(%1)\n"
30034 + "2: movq (%1), %%mm0\n"
30035 + " movntq %%mm0, (%2)\n"
30036 + " movq 8(%1), %%mm1\n"
30037 + " movntq %%mm1, 8(%2)\n"
30038 + " movq 16(%1), %%mm2\n"
30039 + " movntq %%mm2, 16(%2)\n"
30040 + " movq 24(%1), %%mm3\n"
30041 + " movntq %%mm3, 24(%2)\n"
30042 + " movq 32(%1), %%mm4\n"
30043 + " movntq %%mm4, 32(%2)\n"
30044 + " movq 40(%1), %%mm5\n"
30045 + " movntq %%mm5, 40(%2)\n"
30046 + " movq 48(%1), %%mm6\n"
30047 + " movntq %%mm6, 48(%2)\n"
30048 + " movq 56(%1), %%mm7\n"
30049 + " movntq %%mm7, 56(%2)\n"
30050 ".section .fixup, \"ax\"\n"
30051 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30052 + "3:\n"
30053 +
30054 +#ifdef CONFIG_PAX_KERNEXEC
30055 + " movl %%cr0, %0\n"
30056 + " movl %0, %%eax\n"
30057 + " andl $0xFFFEFFFF, %%eax\n"
30058 + " movl %%eax, %%cr0\n"
30059 +#endif
30060 +
30061 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30062 +
30063 +#ifdef CONFIG_PAX_KERNEXEC
30064 + " movl %0, %%cr0\n"
30065 +#endif
30066 +
30067 " jmp 2b\n"
30068 ".previous\n"
30069 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30070 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30071
30072 from += 64;
30073 to += 64;
30074 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30075 static void fast_copy_page(void *to, void *from)
30076 {
30077 int i;
30078 + unsigned long cr0;
30079
30080 kernel_fpu_begin();
30081
30082 __asm__ __volatile__ (
30083 - "1: prefetch (%0)\n"
30084 - " prefetch 64(%0)\n"
30085 - " prefetch 128(%0)\n"
30086 - " prefetch 192(%0)\n"
30087 - " prefetch 256(%0)\n"
30088 + "1: prefetch (%1)\n"
30089 + " prefetch 64(%1)\n"
30090 + " prefetch 128(%1)\n"
30091 + " prefetch 192(%1)\n"
30092 + " prefetch 256(%1)\n"
30093 "2: \n"
30094 ".section .fixup, \"ax\"\n"
30095 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30096 + "3: \n"
30097 +
30098 +#ifdef CONFIG_PAX_KERNEXEC
30099 + " movl %%cr0, %0\n"
30100 + " movl %0, %%eax\n"
30101 + " andl $0xFFFEFFFF, %%eax\n"
30102 + " movl %%eax, %%cr0\n"
30103 +#endif
30104 +
30105 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30106 +
30107 +#ifdef CONFIG_PAX_KERNEXEC
30108 + " movl %0, %%cr0\n"
30109 +#endif
30110 +
30111 " jmp 2b\n"
30112 ".previous\n"
30113 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30114 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30115
30116 for (i = 0; i < 4096/64; i++) {
30117 __asm__ __volatile__ (
30118 - "1: prefetch 320(%0)\n"
30119 - "2: movq (%0), %%mm0\n"
30120 - " movq 8(%0), %%mm1\n"
30121 - " movq 16(%0), %%mm2\n"
30122 - " movq 24(%0), %%mm3\n"
30123 - " movq %%mm0, (%1)\n"
30124 - " movq %%mm1, 8(%1)\n"
30125 - " movq %%mm2, 16(%1)\n"
30126 - " movq %%mm3, 24(%1)\n"
30127 - " movq 32(%0), %%mm0\n"
30128 - " movq 40(%0), %%mm1\n"
30129 - " movq 48(%0), %%mm2\n"
30130 - " movq 56(%0), %%mm3\n"
30131 - " movq %%mm0, 32(%1)\n"
30132 - " movq %%mm1, 40(%1)\n"
30133 - " movq %%mm2, 48(%1)\n"
30134 - " movq %%mm3, 56(%1)\n"
30135 + "1: prefetch 320(%1)\n"
30136 + "2: movq (%1), %%mm0\n"
30137 + " movq 8(%1), %%mm1\n"
30138 + " movq 16(%1), %%mm2\n"
30139 + " movq 24(%1), %%mm3\n"
30140 + " movq %%mm0, (%2)\n"
30141 + " movq %%mm1, 8(%2)\n"
30142 + " movq %%mm2, 16(%2)\n"
30143 + " movq %%mm3, 24(%2)\n"
30144 + " movq 32(%1), %%mm0\n"
30145 + " movq 40(%1), %%mm1\n"
30146 + " movq 48(%1), %%mm2\n"
30147 + " movq 56(%1), %%mm3\n"
30148 + " movq %%mm0, 32(%2)\n"
30149 + " movq %%mm1, 40(%2)\n"
30150 + " movq %%mm2, 48(%2)\n"
30151 + " movq %%mm3, 56(%2)\n"
30152 ".section .fixup, \"ax\"\n"
30153 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30154 + "3:\n"
30155 +
30156 +#ifdef CONFIG_PAX_KERNEXEC
30157 + " movl %%cr0, %0\n"
30158 + " movl %0, %%eax\n"
30159 + " andl $0xFFFEFFFF, %%eax\n"
30160 + " movl %%eax, %%cr0\n"
30161 +#endif
30162 +
30163 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30164 +
30165 +#ifdef CONFIG_PAX_KERNEXEC
30166 + " movl %0, %%cr0\n"
30167 +#endif
30168 +
30169 " jmp 2b\n"
30170 ".previous\n"
30171 _ASM_EXTABLE(1b, 3b)
30172 - : : "r" (from), "r" (to) : "memory");
30173 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30174
30175 from += 64;
30176 to += 64;
30177 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30178 index f6d13ee..d789440 100644
30179 --- a/arch/x86/lib/msr-reg.S
30180 +++ b/arch/x86/lib/msr-reg.S
30181 @@ -3,6 +3,7 @@
30182 #include <asm/dwarf2.h>
30183 #include <asm/asm.h>
30184 #include <asm/msr.h>
30185 +#include <asm/alternative-asm.h>
30186
30187 #ifdef CONFIG_X86_64
30188 /*
30189 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30190 movl %edi, 28(%r10)
30191 popq_cfi %rbp
30192 popq_cfi %rbx
30193 + pax_force_retaddr
30194 ret
30195 3:
30196 CFI_RESTORE_STATE
30197 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30198 index fc6ba17..d4d989d 100644
30199 --- a/arch/x86/lib/putuser.S
30200 +++ b/arch/x86/lib/putuser.S
30201 @@ -16,7 +16,9 @@
30202 #include <asm/errno.h>
30203 #include <asm/asm.h>
30204 #include <asm/smap.h>
30205 -
30206 +#include <asm/segment.h>
30207 +#include <asm/pgtable.h>
30208 +#include <asm/alternative-asm.h>
30209
30210 /*
30211 * __put_user_X
30212 @@ -30,57 +32,125 @@
30213 * as they get called from within inline assembly.
30214 */
30215
30216 -#define ENTER CFI_STARTPROC ; \
30217 - GET_THREAD_INFO(%_ASM_BX)
30218 -#define EXIT ASM_CLAC ; \
30219 - ret ; \
30220 +#define ENTER CFI_STARTPROC
30221 +#define EXIT ASM_CLAC ; \
30222 + pax_force_retaddr ; \
30223 + ret ; \
30224 CFI_ENDPROC
30225
30226 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30227 +#define _DEST %_ASM_CX,%_ASM_BX
30228 +#else
30229 +#define _DEST %_ASM_CX
30230 +#endif
30231 +
30232 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30233 +#define __copyuser_seg gs;
30234 +#else
30235 +#define __copyuser_seg
30236 +#endif
30237 +
30238 .text
30239 ENTRY(__put_user_1)
30240 ENTER
30241 +
30242 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30243 + GET_THREAD_INFO(%_ASM_BX)
30244 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30245 jae bad_put_user
30246 ASM_STAC
30247 -1: movb %al,(%_ASM_CX)
30248 +
30249 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30250 + mov pax_user_shadow_base,%_ASM_BX
30251 + cmp %_ASM_BX,%_ASM_CX
30252 + jb 1234f
30253 + xor %ebx,%ebx
30254 +1234:
30255 +#endif
30256 +
30257 +#endif
30258 +
30259 +1: __copyuser_seg movb %al,(_DEST)
30260 xor %eax,%eax
30261 EXIT
30262 ENDPROC(__put_user_1)
30263
30264 ENTRY(__put_user_2)
30265 ENTER
30266 +
30267 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30268 + GET_THREAD_INFO(%_ASM_BX)
30269 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30270 sub $1,%_ASM_BX
30271 cmp %_ASM_BX,%_ASM_CX
30272 jae bad_put_user
30273 ASM_STAC
30274 -2: movw %ax,(%_ASM_CX)
30275 +
30276 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30277 + mov pax_user_shadow_base,%_ASM_BX
30278 + cmp %_ASM_BX,%_ASM_CX
30279 + jb 1234f
30280 + xor %ebx,%ebx
30281 +1234:
30282 +#endif
30283 +
30284 +#endif
30285 +
30286 +2: __copyuser_seg movw %ax,(_DEST)
30287 xor %eax,%eax
30288 EXIT
30289 ENDPROC(__put_user_2)
30290
30291 ENTRY(__put_user_4)
30292 ENTER
30293 +
30294 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30295 + GET_THREAD_INFO(%_ASM_BX)
30296 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30297 sub $3,%_ASM_BX
30298 cmp %_ASM_BX,%_ASM_CX
30299 jae bad_put_user
30300 ASM_STAC
30301 -3: movl %eax,(%_ASM_CX)
30302 +
30303 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30304 + mov pax_user_shadow_base,%_ASM_BX
30305 + cmp %_ASM_BX,%_ASM_CX
30306 + jb 1234f
30307 + xor %ebx,%ebx
30308 +1234:
30309 +#endif
30310 +
30311 +#endif
30312 +
30313 +3: __copyuser_seg movl %eax,(_DEST)
30314 xor %eax,%eax
30315 EXIT
30316 ENDPROC(__put_user_4)
30317
30318 ENTRY(__put_user_8)
30319 ENTER
30320 +
30321 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30322 + GET_THREAD_INFO(%_ASM_BX)
30323 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30324 sub $7,%_ASM_BX
30325 cmp %_ASM_BX,%_ASM_CX
30326 jae bad_put_user
30327 ASM_STAC
30328 -4: mov %_ASM_AX,(%_ASM_CX)
30329 +
30330 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30331 + mov pax_user_shadow_base,%_ASM_BX
30332 + cmp %_ASM_BX,%_ASM_CX
30333 + jb 1234f
30334 + xor %ebx,%ebx
30335 +1234:
30336 +#endif
30337 +
30338 +#endif
30339 +
30340 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30341 #ifdef CONFIG_X86_32
30342 -5: movl %edx,4(%_ASM_CX)
30343 +5: __copyuser_seg movl %edx,4(_DEST)
30344 #endif
30345 xor %eax,%eax
30346 EXIT
30347 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30348 index 1cad221..de671ee 100644
30349 --- a/arch/x86/lib/rwlock.S
30350 +++ b/arch/x86/lib/rwlock.S
30351 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30352 FRAME
30353 0: LOCK_PREFIX
30354 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30355 +
30356 +#ifdef CONFIG_PAX_REFCOUNT
30357 + jno 1234f
30358 + LOCK_PREFIX
30359 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30360 + int $4
30361 +1234:
30362 + _ASM_EXTABLE(1234b, 1234b)
30363 +#endif
30364 +
30365 1: rep; nop
30366 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30367 jne 1b
30368 LOCK_PREFIX
30369 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30370 +
30371 +#ifdef CONFIG_PAX_REFCOUNT
30372 + jno 1234f
30373 + LOCK_PREFIX
30374 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30375 + int $4
30376 +1234:
30377 + _ASM_EXTABLE(1234b, 1234b)
30378 +#endif
30379 +
30380 jnz 0b
30381 ENDFRAME
30382 + pax_force_retaddr
30383 ret
30384 CFI_ENDPROC
30385 END(__write_lock_failed)
30386 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30387 FRAME
30388 0: LOCK_PREFIX
30389 READ_LOCK_SIZE(inc) (%__lock_ptr)
30390 +
30391 +#ifdef CONFIG_PAX_REFCOUNT
30392 + jno 1234f
30393 + LOCK_PREFIX
30394 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30395 + int $4
30396 +1234:
30397 + _ASM_EXTABLE(1234b, 1234b)
30398 +#endif
30399 +
30400 1: rep; nop
30401 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30402 js 1b
30403 LOCK_PREFIX
30404 READ_LOCK_SIZE(dec) (%__lock_ptr)
30405 +
30406 +#ifdef CONFIG_PAX_REFCOUNT
30407 + jno 1234f
30408 + LOCK_PREFIX
30409 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30410 + int $4
30411 +1234:
30412 + _ASM_EXTABLE(1234b, 1234b)
30413 +#endif
30414 +
30415 js 0b
30416 ENDFRAME
30417 + pax_force_retaddr
30418 ret
30419 CFI_ENDPROC
30420 END(__read_lock_failed)
30421 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30422 index 5dff5f0..cadebf4 100644
30423 --- a/arch/x86/lib/rwsem.S
30424 +++ b/arch/x86/lib/rwsem.S
30425 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30426 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30427 CFI_RESTORE __ASM_REG(dx)
30428 restore_common_regs
30429 + pax_force_retaddr
30430 ret
30431 CFI_ENDPROC
30432 ENDPROC(call_rwsem_down_read_failed)
30433 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30434 movq %rax,%rdi
30435 call rwsem_down_write_failed
30436 restore_common_regs
30437 + pax_force_retaddr
30438 ret
30439 CFI_ENDPROC
30440 ENDPROC(call_rwsem_down_write_failed)
30441 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30442 movq %rax,%rdi
30443 call rwsem_wake
30444 restore_common_regs
30445 -1: ret
30446 +1: pax_force_retaddr
30447 + ret
30448 CFI_ENDPROC
30449 ENDPROC(call_rwsem_wake)
30450
30451 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30452 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30453 CFI_RESTORE __ASM_REG(dx)
30454 restore_common_regs
30455 + pax_force_retaddr
30456 ret
30457 CFI_ENDPROC
30458 ENDPROC(call_rwsem_downgrade_wake)
30459 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30460 index a63efd6..8149fbe 100644
30461 --- a/arch/x86/lib/thunk_64.S
30462 +++ b/arch/x86/lib/thunk_64.S
30463 @@ -8,6 +8,7 @@
30464 #include <linux/linkage.h>
30465 #include <asm/dwarf2.h>
30466 #include <asm/calling.h>
30467 +#include <asm/alternative-asm.h>
30468
30469 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30470 .macro THUNK name, func, put_ret_addr_in_rdi=0
30471 @@ -15,11 +16,11 @@
30472 \name:
30473 CFI_STARTPROC
30474
30475 - /* this one pushes 9 elems, the next one would be %rIP */
30476 - SAVE_ARGS
30477 + /* this one pushes 15+1 elems, the next one would be %rIP */
30478 + SAVE_ARGS 8
30479
30480 .if \put_ret_addr_in_rdi
30481 - movq_cfi_restore 9*8, rdi
30482 + movq_cfi_restore RIP, rdi
30483 .endif
30484
30485 call \func
30486 @@ -38,8 +39,9 @@
30487
30488 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30489 CFI_STARTPROC
30490 - SAVE_ARGS
30491 + SAVE_ARGS 8
30492 restore:
30493 - RESTORE_ARGS
30494 + RESTORE_ARGS 1,8
30495 + pax_force_retaddr
30496 ret
30497 CFI_ENDPROC
30498 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30499 index e2f5e21..4b22130 100644
30500 --- a/arch/x86/lib/usercopy_32.c
30501 +++ b/arch/x86/lib/usercopy_32.c
30502 @@ -42,11 +42,13 @@ do { \
30503 int __d0; \
30504 might_fault(); \
30505 __asm__ __volatile__( \
30506 + __COPYUSER_SET_ES \
30507 ASM_STAC "\n" \
30508 "0: rep; stosl\n" \
30509 " movl %2,%0\n" \
30510 "1: rep; stosb\n" \
30511 "2: " ASM_CLAC "\n" \
30512 + __COPYUSER_RESTORE_ES \
30513 ".section .fixup,\"ax\"\n" \
30514 "3: lea 0(%2,%0,4),%0\n" \
30515 " jmp 2b\n" \
30516 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30517
30518 #ifdef CONFIG_X86_INTEL_USERCOPY
30519 static unsigned long
30520 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30521 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30522 {
30523 int d0, d1;
30524 __asm__ __volatile__(
30525 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30526 " .align 2,0x90\n"
30527 "3: movl 0(%4), %%eax\n"
30528 "4: movl 4(%4), %%edx\n"
30529 - "5: movl %%eax, 0(%3)\n"
30530 - "6: movl %%edx, 4(%3)\n"
30531 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30532 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30533 "7: movl 8(%4), %%eax\n"
30534 "8: movl 12(%4),%%edx\n"
30535 - "9: movl %%eax, 8(%3)\n"
30536 - "10: movl %%edx, 12(%3)\n"
30537 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30538 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30539 "11: movl 16(%4), %%eax\n"
30540 "12: movl 20(%4), %%edx\n"
30541 - "13: movl %%eax, 16(%3)\n"
30542 - "14: movl %%edx, 20(%3)\n"
30543 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30544 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30545 "15: movl 24(%4), %%eax\n"
30546 "16: movl 28(%4), %%edx\n"
30547 - "17: movl %%eax, 24(%3)\n"
30548 - "18: movl %%edx, 28(%3)\n"
30549 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30550 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30551 "19: movl 32(%4), %%eax\n"
30552 "20: movl 36(%4), %%edx\n"
30553 - "21: movl %%eax, 32(%3)\n"
30554 - "22: movl %%edx, 36(%3)\n"
30555 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30556 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30557 "23: movl 40(%4), %%eax\n"
30558 "24: movl 44(%4), %%edx\n"
30559 - "25: movl %%eax, 40(%3)\n"
30560 - "26: movl %%edx, 44(%3)\n"
30561 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30562 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30563 "27: movl 48(%4), %%eax\n"
30564 "28: movl 52(%4), %%edx\n"
30565 - "29: movl %%eax, 48(%3)\n"
30566 - "30: movl %%edx, 52(%3)\n"
30567 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30568 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30569 "31: movl 56(%4), %%eax\n"
30570 "32: movl 60(%4), %%edx\n"
30571 - "33: movl %%eax, 56(%3)\n"
30572 - "34: movl %%edx, 60(%3)\n"
30573 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30574 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30575 " addl $-64, %0\n"
30576 " addl $64, %4\n"
30577 " addl $64, %3\n"
30578 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30579 " shrl $2, %0\n"
30580 " andl $3, %%eax\n"
30581 " cld\n"
30582 + __COPYUSER_SET_ES
30583 "99: rep; movsl\n"
30584 "36: movl %%eax, %0\n"
30585 "37: rep; movsb\n"
30586 "100:\n"
30587 + __COPYUSER_RESTORE_ES
30588 + ".section .fixup,\"ax\"\n"
30589 + "101: lea 0(%%eax,%0,4),%0\n"
30590 + " jmp 100b\n"
30591 + ".previous\n"
30592 + _ASM_EXTABLE(1b,100b)
30593 + _ASM_EXTABLE(2b,100b)
30594 + _ASM_EXTABLE(3b,100b)
30595 + _ASM_EXTABLE(4b,100b)
30596 + _ASM_EXTABLE(5b,100b)
30597 + _ASM_EXTABLE(6b,100b)
30598 + _ASM_EXTABLE(7b,100b)
30599 + _ASM_EXTABLE(8b,100b)
30600 + _ASM_EXTABLE(9b,100b)
30601 + _ASM_EXTABLE(10b,100b)
30602 + _ASM_EXTABLE(11b,100b)
30603 + _ASM_EXTABLE(12b,100b)
30604 + _ASM_EXTABLE(13b,100b)
30605 + _ASM_EXTABLE(14b,100b)
30606 + _ASM_EXTABLE(15b,100b)
30607 + _ASM_EXTABLE(16b,100b)
30608 + _ASM_EXTABLE(17b,100b)
30609 + _ASM_EXTABLE(18b,100b)
30610 + _ASM_EXTABLE(19b,100b)
30611 + _ASM_EXTABLE(20b,100b)
30612 + _ASM_EXTABLE(21b,100b)
30613 + _ASM_EXTABLE(22b,100b)
30614 + _ASM_EXTABLE(23b,100b)
30615 + _ASM_EXTABLE(24b,100b)
30616 + _ASM_EXTABLE(25b,100b)
30617 + _ASM_EXTABLE(26b,100b)
30618 + _ASM_EXTABLE(27b,100b)
30619 + _ASM_EXTABLE(28b,100b)
30620 + _ASM_EXTABLE(29b,100b)
30621 + _ASM_EXTABLE(30b,100b)
30622 + _ASM_EXTABLE(31b,100b)
30623 + _ASM_EXTABLE(32b,100b)
30624 + _ASM_EXTABLE(33b,100b)
30625 + _ASM_EXTABLE(34b,100b)
30626 + _ASM_EXTABLE(35b,100b)
30627 + _ASM_EXTABLE(36b,100b)
30628 + _ASM_EXTABLE(37b,100b)
30629 + _ASM_EXTABLE(99b,101b)
30630 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30631 + : "1"(to), "2"(from), "0"(size)
30632 + : "eax", "edx", "memory");
30633 + return size;
30634 +}
30635 +
30636 +static unsigned long
30637 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30638 +{
30639 + int d0, d1;
30640 + __asm__ __volatile__(
30641 + " .align 2,0x90\n"
30642 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30643 + " cmpl $67, %0\n"
30644 + " jbe 3f\n"
30645 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30646 + " .align 2,0x90\n"
30647 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30648 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30649 + "5: movl %%eax, 0(%3)\n"
30650 + "6: movl %%edx, 4(%3)\n"
30651 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30652 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30653 + "9: movl %%eax, 8(%3)\n"
30654 + "10: movl %%edx, 12(%3)\n"
30655 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30656 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30657 + "13: movl %%eax, 16(%3)\n"
30658 + "14: movl %%edx, 20(%3)\n"
30659 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30660 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30661 + "17: movl %%eax, 24(%3)\n"
30662 + "18: movl %%edx, 28(%3)\n"
30663 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30664 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30665 + "21: movl %%eax, 32(%3)\n"
30666 + "22: movl %%edx, 36(%3)\n"
30667 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30668 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30669 + "25: movl %%eax, 40(%3)\n"
30670 + "26: movl %%edx, 44(%3)\n"
30671 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30672 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30673 + "29: movl %%eax, 48(%3)\n"
30674 + "30: movl %%edx, 52(%3)\n"
30675 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30676 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30677 + "33: movl %%eax, 56(%3)\n"
30678 + "34: movl %%edx, 60(%3)\n"
30679 + " addl $-64, %0\n"
30680 + " addl $64, %4\n"
30681 + " addl $64, %3\n"
30682 + " cmpl $63, %0\n"
30683 + " ja 1b\n"
30684 + "35: movl %0, %%eax\n"
30685 + " shrl $2, %0\n"
30686 + " andl $3, %%eax\n"
30687 + " cld\n"
30688 + "99: rep; "__copyuser_seg" movsl\n"
30689 + "36: movl %%eax, %0\n"
30690 + "37: rep; "__copyuser_seg" movsb\n"
30691 + "100:\n"
30692 ".section .fixup,\"ax\"\n"
30693 "101: lea 0(%%eax,%0,4),%0\n"
30694 " jmp 100b\n"
30695 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30696 int d0, d1;
30697 __asm__ __volatile__(
30698 " .align 2,0x90\n"
30699 - "0: movl 32(%4), %%eax\n"
30700 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30701 " cmpl $67, %0\n"
30702 " jbe 2f\n"
30703 - "1: movl 64(%4), %%eax\n"
30704 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30705 " .align 2,0x90\n"
30706 - "2: movl 0(%4), %%eax\n"
30707 - "21: movl 4(%4), %%edx\n"
30708 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30709 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30710 " movl %%eax, 0(%3)\n"
30711 " movl %%edx, 4(%3)\n"
30712 - "3: movl 8(%4), %%eax\n"
30713 - "31: movl 12(%4),%%edx\n"
30714 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30715 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30716 " movl %%eax, 8(%3)\n"
30717 " movl %%edx, 12(%3)\n"
30718 - "4: movl 16(%4), %%eax\n"
30719 - "41: movl 20(%4), %%edx\n"
30720 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30721 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30722 " movl %%eax, 16(%3)\n"
30723 " movl %%edx, 20(%3)\n"
30724 - "10: movl 24(%4), %%eax\n"
30725 - "51: movl 28(%4), %%edx\n"
30726 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30727 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30728 " movl %%eax, 24(%3)\n"
30729 " movl %%edx, 28(%3)\n"
30730 - "11: movl 32(%4), %%eax\n"
30731 - "61: movl 36(%4), %%edx\n"
30732 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30733 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30734 " movl %%eax, 32(%3)\n"
30735 " movl %%edx, 36(%3)\n"
30736 - "12: movl 40(%4), %%eax\n"
30737 - "71: movl 44(%4), %%edx\n"
30738 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30739 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30740 " movl %%eax, 40(%3)\n"
30741 " movl %%edx, 44(%3)\n"
30742 - "13: movl 48(%4), %%eax\n"
30743 - "81: movl 52(%4), %%edx\n"
30744 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30745 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30746 " movl %%eax, 48(%3)\n"
30747 " movl %%edx, 52(%3)\n"
30748 - "14: movl 56(%4), %%eax\n"
30749 - "91: movl 60(%4), %%edx\n"
30750 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30751 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30752 " movl %%eax, 56(%3)\n"
30753 " movl %%edx, 60(%3)\n"
30754 " addl $-64, %0\n"
30755 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30756 " shrl $2, %0\n"
30757 " andl $3, %%eax\n"
30758 " cld\n"
30759 - "6: rep; movsl\n"
30760 + "6: rep; "__copyuser_seg" movsl\n"
30761 " movl %%eax,%0\n"
30762 - "7: rep; movsb\n"
30763 + "7: rep; "__copyuser_seg" movsb\n"
30764 "8:\n"
30765 ".section .fixup,\"ax\"\n"
30766 "9: lea 0(%%eax,%0,4),%0\n"
30767 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30768
30769 __asm__ __volatile__(
30770 " .align 2,0x90\n"
30771 - "0: movl 32(%4), %%eax\n"
30772 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30773 " cmpl $67, %0\n"
30774 " jbe 2f\n"
30775 - "1: movl 64(%4), %%eax\n"
30776 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30777 " .align 2,0x90\n"
30778 - "2: movl 0(%4), %%eax\n"
30779 - "21: movl 4(%4), %%edx\n"
30780 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30781 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30782 " movnti %%eax, 0(%3)\n"
30783 " movnti %%edx, 4(%3)\n"
30784 - "3: movl 8(%4), %%eax\n"
30785 - "31: movl 12(%4),%%edx\n"
30786 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30787 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30788 " movnti %%eax, 8(%3)\n"
30789 " movnti %%edx, 12(%3)\n"
30790 - "4: movl 16(%4), %%eax\n"
30791 - "41: movl 20(%4), %%edx\n"
30792 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30793 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30794 " movnti %%eax, 16(%3)\n"
30795 " movnti %%edx, 20(%3)\n"
30796 - "10: movl 24(%4), %%eax\n"
30797 - "51: movl 28(%4), %%edx\n"
30798 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30799 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30800 " movnti %%eax, 24(%3)\n"
30801 " movnti %%edx, 28(%3)\n"
30802 - "11: movl 32(%4), %%eax\n"
30803 - "61: movl 36(%4), %%edx\n"
30804 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30805 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30806 " movnti %%eax, 32(%3)\n"
30807 " movnti %%edx, 36(%3)\n"
30808 - "12: movl 40(%4), %%eax\n"
30809 - "71: movl 44(%4), %%edx\n"
30810 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30811 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30812 " movnti %%eax, 40(%3)\n"
30813 " movnti %%edx, 44(%3)\n"
30814 - "13: movl 48(%4), %%eax\n"
30815 - "81: movl 52(%4), %%edx\n"
30816 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30817 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30818 " movnti %%eax, 48(%3)\n"
30819 " movnti %%edx, 52(%3)\n"
30820 - "14: movl 56(%4), %%eax\n"
30821 - "91: movl 60(%4), %%edx\n"
30822 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30823 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30824 " movnti %%eax, 56(%3)\n"
30825 " movnti %%edx, 60(%3)\n"
30826 " addl $-64, %0\n"
30827 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30828 " shrl $2, %0\n"
30829 " andl $3, %%eax\n"
30830 " cld\n"
30831 - "6: rep; movsl\n"
30832 + "6: rep; "__copyuser_seg" movsl\n"
30833 " movl %%eax,%0\n"
30834 - "7: rep; movsb\n"
30835 + "7: rep; "__copyuser_seg" movsb\n"
30836 "8:\n"
30837 ".section .fixup,\"ax\"\n"
30838 "9: lea 0(%%eax,%0,4),%0\n"
30839 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30840
30841 __asm__ __volatile__(
30842 " .align 2,0x90\n"
30843 - "0: movl 32(%4), %%eax\n"
30844 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30845 " cmpl $67, %0\n"
30846 " jbe 2f\n"
30847 - "1: movl 64(%4), %%eax\n"
30848 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30849 " .align 2,0x90\n"
30850 - "2: movl 0(%4), %%eax\n"
30851 - "21: movl 4(%4), %%edx\n"
30852 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30853 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30854 " movnti %%eax, 0(%3)\n"
30855 " movnti %%edx, 4(%3)\n"
30856 - "3: movl 8(%4), %%eax\n"
30857 - "31: movl 12(%4),%%edx\n"
30858 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30859 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30860 " movnti %%eax, 8(%3)\n"
30861 " movnti %%edx, 12(%3)\n"
30862 - "4: movl 16(%4), %%eax\n"
30863 - "41: movl 20(%4), %%edx\n"
30864 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30865 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30866 " movnti %%eax, 16(%3)\n"
30867 " movnti %%edx, 20(%3)\n"
30868 - "10: movl 24(%4), %%eax\n"
30869 - "51: movl 28(%4), %%edx\n"
30870 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30871 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30872 " movnti %%eax, 24(%3)\n"
30873 " movnti %%edx, 28(%3)\n"
30874 - "11: movl 32(%4), %%eax\n"
30875 - "61: movl 36(%4), %%edx\n"
30876 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30877 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30878 " movnti %%eax, 32(%3)\n"
30879 " movnti %%edx, 36(%3)\n"
30880 - "12: movl 40(%4), %%eax\n"
30881 - "71: movl 44(%4), %%edx\n"
30882 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30883 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30884 " movnti %%eax, 40(%3)\n"
30885 " movnti %%edx, 44(%3)\n"
30886 - "13: movl 48(%4), %%eax\n"
30887 - "81: movl 52(%4), %%edx\n"
30888 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30889 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30890 " movnti %%eax, 48(%3)\n"
30891 " movnti %%edx, 52(%3)\n"
30892 - "14: movl 56(%4), %%eax\n"
30893 - "91: movl 60(%4), %%edx\n"
30894 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30895 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30896 " movnti %%eax, 56(%3)\n"
30897 " movnti %%edx, 60(%3)\n"
30898 " addl $-64, %0\n"
30899 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30900 " shrl $2, %0\n"
30901 " andl $3, %%eax\n"
30902 " cld\n"
30903 - "6: rep; movsl\n"
30904 + "6: rep; "__copyuser_seg" movsl\n"
30905 " movl %%eax,%0\n"
30906 - "7: rep; movsb\n"
30907 + "7: rep; "__copyuser_seg" movsb\n"
30908 "8:\n"
30909 ".section .fixup,\"ax\"\n"
30910 "9: lea 0(%%eax,%0,4),%0\n"
30911 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30912 */
30913 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30914 unsigned long size);
30915 -unsigned long __copy_user_intel(void __user *to, const void *from,
30916 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30917 + unsigned long size);
30918 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30919 unsigned long size);
30920 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30921 const void __user *from, unsigned long size);
30922 #endif /* CONFIG_X86_INTEL_USERCOPY */
30923
30924 /* Generic arbitrary sized copy. */
30925 -#define __copy_user(to, from, size) \
30926 +#define __copy_user(to, from, size, prefix, set, restore) \
30927 do { \
30928 int __d0, __d1, __d2; \
30929 __asm__ __volatile__( \
30930 + set \
30931 " cmp $7,%0\n" \
30932 " jbe 1f\n" \
30933 " movl %1,%0\n" \
30934 " negl %0\n" \
30935 " andl $7,%0\n" \
30936 " subl %0,%3\n" \
30937 - "4: rep; movsb\n" \
30938 + "4: rep; "prefix"movsb\n" \
30939 " movl %3,%0\n" \
30940 " shrl $2,%0\n" \
30941 " andl $3,%3\n" \
30942 " .align 2,0x90\n" \
30943 - "0: rep; movsl\n" \
30944 + "0: rep; "prefix"movsl\n" \
30945 " movl %3,%0\n" \
30946 - "1: rep; movsb\n" \
30947 + "1: rep; "prefix"movsb\n" \
30948 "2:\n" \
30949 + restore \
30950 ".section .fixup,\"ax\"\n" \
30951 "5: addl %3,%0\n" \
30952 " jmp 2b\n" \
30953 @@ -538,14 +650,14 @@ do { \
30954 " negl %0\n" \
30955 " andl $7,%0\n" \
30956 " subl %0,%3\n" \
30957 - "4: rep; movsb\n" \
30958 + "4: rep; "__copyuser_seg"movsb\n" \
30959 " movl %3,%0\n" \
30960 " shrl $2,%0\n" \
30961 " andl $3,%3\n" \
30962 " .align 2,0x90\n" \
30963 - "0: rep; movsl\n" \
30964 + "0: rep; "__copyuser_seg"movsl\n" \
30965 " movl %3,%0\n" \
30966 - "1: rep; movsb\n" \
30967 + "1: rep; "__copyuser_seg"movsb\n" \
30968 "2:\n" \
30969 ".section .fixup,\"ax\"\n" \
30970 "5: addl %3,%0\n" \
30971 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30972 {
30973 stac();
30974 if (movsl_is_ok(to, from, n))
30975 - __copy_user(to, from, n);
30976 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30977 else
30978 - n = __copy_user_intel(to, from, n);
30979 + n = __generic_copy_to_user_intel(to, from, n);
30980 clac();
30981 return n;
30982 }
30983 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30984 {
30985 stac();
30986 if (movsl_is_ok(to, from, n))
30987 - __copy_user(to, from, n);
30988 + __copy_user(to, from, n, __copyuser_seg, "", "");
30989 else
30990 - n = __copy_user_intel((void __user *)to,
30991 - (const void *)from, n);
30992 + n = __generic_copy_from_user_intel(to, from, n);
30993 clac();
30994 return n;
30995 }
30996 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30997 if (n > 64 && cpu_has_xmm2)
30998 n = __copy_user_intel_nocache(to, from, n);
30999 else
31000 - __copy_user(to, from, n);
31001 + __copy_user(to, from, n, __copyuser_seg, "", "");
31002 #else
31003 - __copy_user(to, from, n);
31004 + __copy_user(to, from, n, __copyuser_seg, "", "");
31005 #endif
31006 clac();
31007 return n;
31008 }
31009 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31010
31011 -/**
31012 - * copy_to_user: - Copy a block of data into user space.
31013 - * @to: Destination address, in user space.
31014 - * @from: Source address, in kernel space.
31015 - * @n: Number of bytes to copy.
31016 - *
31017 - * Context: User context only. This function may sleep.
31018 - *
31019 - * Copy data from kernel space to user space.
31020 - *
31021 - * Returns number of bytes that could not be copied.
31022 - * On success, this will be zero.
31023 - */
31024 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31025 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31026 +void __set_fs(mm_segment_t x)
31027 {
31028 - if (access_ok(VERIFY_WRITE, to, n))
31029 - n = __copy_to_user(to, from, n);
31030 - return n;
31031 + switch (x.seg) {
31032 + case 0:
31033 + loadsegment(gs, 0);
31034 + break;
31035 + case TASK_SIZE_MAX:
31036 + loadsegment(gs, __USER_DS);
31037 + break;
31038 + case -1UL:
31039 + loadsegment(gs, __KERNEL_DS);
31040 + break;
31041 + default:
31042 + BUG();
31043 + }
31044 }
31045 -EXPORT_SYMBOL(_copy_to_user);
31046 +EXPORT_SYMBOL(__set_fs);
31047
31048 -/**
31049 - * copy_from_user: - Copy a block of data from user space.
31050 - * @to: Destination address, in kernel space.
31051 - * @from: Source address, in user space.
31052 - * @n: Number of bytes to copy.
31053 - *
31054 - * Context: User context only. This function may sleep.
31055 - *
31056 - * Copy data from user space to kernel space.
31057 - *
31058 - * Returns number of bytes that could not be copied.
31059 - * On success, this will be zero.
31060 - *
31061 - * If some data could not be copied, this function will pad the copied
31062 - * data to the requested size using zero bytes.
31063 - */
31064 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31065 +void set_fs(mm_segment_t x)
31066 {
31067 - if (access_ok(VERIFY_READ, from, n))
31068 - n = __copy_from_user(to, from, n);
31069 - else
31070 - memset(to, 0, n);
31071 - return n;
31072 + current_thread_info()->addr_limit = x;
31073 + __set_fs(x);
31074 }
31075 -EXPORT_SYMBOL(_copy_from_user);
31076 +EXPORT_SYMBOL(set_fs);
31077 +#endif
31078 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31079 index c905e89..01ab928 100644
31080 --- a/arch/x86/lib/usercopy_64.c
31081 +++ b/arch/x86/lib/usercopy_64.c
31082 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31083 might_fault();
31084 /* no memory constraint because it doesn't change any memory gcc knows
31085 about */
31086 + pax_open_userland();
31087 stac();
31088 asm volatile(
31089 " testq %[size8],%[size8]\n"
31090 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31091 _ASM_EXTABLE(0b,3b)
31092 _ASM_EXTABLE(1b,2b)
31093 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31094 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31095 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31096 [zero] "r" (0UL), [eight] "r" (8UL));
31097 clac();
31098 + pax_close_userland();
31099 return size;
31100 }
31101 EXPORT_SYMBOL(__clear_user);
31102 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31103 }
31104 EXPORT_SYMBOL(clear_user);
31105
31106 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31107 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31108 {
31109 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31110 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31111 - }
31112 - return len;
31113 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31114 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31115 + return len;
31116 }
31117 EXPORT_SYMBOL(copy_in_user);
31118
31119 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31120 * it is not necessary to optimize tail handling.
31121 */
31122 __visible unsigned long
31123 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31124 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31125 {
31126 char c;
31127 unsigned zero_len;
31128
31129 + clac();
31130 + pax_close_userland();
31131 for (; len; --len, to++) {
31132 if (__get_user_nocheck(c, from++, sizeof(char)))
31133 break;
31134 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31135 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31136 if (__put_user_nocheck(c, to++, sizeof(char)))
31137 break;
31138 - clac();
31139 return len;
31140 }
31141 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31142 index 6a19ad9..1c48f9a 100644
31143 --- a/arch/x86/mm/Makefile
31144 +++ b/arch/x86/mm/Makefile
31145 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31146 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31147
31148 obj-$(CONFIG_MEMTEST) += memtest.o
31149 +
31150 +quote:="
31151 +obj-$(CONFIG_X86_64) += uderef_64.o
31152 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31153 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31154 index 903ec1e..c4166b2 100644
31155 --- a/arch/x86/mm/extable.c
31156 +++ b/arch/x86/mm/extable.c
31157 @@ -6,12 +6,24 @@
31158 static inline unsigned long
31159 ex_insn_addr(const struct exception_table_entry *x)
31160 {
31161 - return (unsigned long)&x->insn + x->insn;
31162 + unsigned long reloc = 0;
31163 +
31164 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31165 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31166 +#endif
31167 +
31168 + return (unsigned long)&x->insn + x->insn + reloc;
31169 }
31170 static inline unsigned long
31171 ex_fixup_addr(const struct exception_table_entry *x)
31172 {
31173 - return (unsigned long)&x->fixup + x->fixup;
31174 + unsigned long reloc = 0;
31175 +
31176 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31177 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31178 +#endif
31179 +
31180 + return (unsigned long)&x->fixup + x->fixup + reloc;
31181 }
31182
31183 int fixup_exception(struct pt_regs *regs)
31184 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31185 unsigned long new_ip;
31186
31187 #ifdef CONFIG_PNPBIOS
31188 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31189 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31190 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31191 extern u32 pnp_bios_is_utter_crap;
31192 pnp_bios_is_utter_crap = 1;
31193 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31194 i += 4;
31195 p->fixup -= i;
31196 i += 4;
31197 +
31198 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31199 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31200 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31201 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31202 +#endif
31203 +
31204 }
31205 }
31206
31207 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31208 index 6dea040..31e52ff 100644
31209 --- a/arch/x86/mm/fault.c
31210 +++ b/arch/x86/mm/fault.c
31211 @@ -14,11 +14,18 @@
31212 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31213 #include <linux/prefetch.h> /* prefetchw */
31214 #include <linux/context_tracking.h> /* exception_enter(), ... */
31215 +#include <linux/unistd.h>
31216 +#include <linux/compiler.h>
31217
31218 #include <asm/traps.h> /* dotraplinkage, ... */
31219 #include <asm/pgalloc.h> /* pgd_*(), ... */
31220 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31221 #include <asm/fixmap.h> /* VSYSCALL_START */
31222 +#include <asm/tlbflush.h>
31223 +
31224 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31225 +#include <asm/stacktrace.h>
31226 +#endif
31227
31228 #define CREATE_TRACE_POINTS
31229 #include <asm/trace/exceptions.h>
31230 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31231 int ret = 0;
31232
31233 /* kprobe_running() needs smp_processor_id() */
31234 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31235 + if (kprobes_built_in() && !user_mode(regs)) {
31236 preempt_disable();
31237 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31238 ret = 1;
31239 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31240 return !instr_lo || (instr_lo>>1) == 1;
31241 case 0x00:
31242 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31243 - if (probe_kernel_address(instr, opcode))
31244 + if (user_mode(regs)) {
31245 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31246 + return 0;
31247 + } else if (probe_kernel_address(instr, opcode))
31248 return 0;
31249
31250 *prefetch = (instr_lo == 0xF) &&
31251 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31252 while (instr < max_instr) {
31253 unsigned char opcode;
31254
31255 - if (probe_kernel_address(instr, opcode))
31256 + if (user_mode(regs)) {
31257 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31258 + break;
31259 + } else if (probe_kernel_address(instr, opcode))
31260 break;
31261
31262 instr++;
31263 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31264 force_sig_info(si_signo, &info, tsk);
31265 }
31266
31267 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31268 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31269 +#endif
31270 +
31271 +#ifdef CONFIG_PAX_EMUTRAMP
31272 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31273 +#endif
31274 +
31275 +#ifdef CONFIG_PAX_PAGEEXEC
31276 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31277 +{
31278 + pgd_t *pgd;
31279 + pud_t *pud;
31280 + pmd_t *pmd;
31281 +
31282 + pgd = pgd_offset(mm, address);
31283 + if (!pgd_present(*pgd))
31284 + return NULL;
31285 + pud = pud_offset(pgd, address);
31286 + if (!pud_present(*pud))
31287 + return NULL;
31288 + pmd = pmd_offset(pud, address);
31289 + if (!pmd_present(*pmd))
31290 + return NULL;
31291 + return pmd;
31292 +}
31293 +#endif
31294 +
31295 DEFINE_SPINLOCK(pgd_lock);
31296 LIST_HEAD(pgd_list);
31297
31298 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31299 for (address = VMALLOC_START & PMD_MASK;
31300 address >= TASK_SIZE && address < FIXADDR_TOP;
31301 address += PMD_SIZE) {
31302 +
31303 +#ifdef CONFIG_PAX_PER_CPU_PGD
31304 + unsigned long cpu;
31305 +#else
31306 struct page *page;
31307 +#endif
31308
31309 spin_lock(&pgd_lock);
31310 +
31311 +#ifdef CONFIG_PAX_PER_CPU_PGD
31312 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31313 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31314 + pmd_t *ret;
31315 +
31316 + ret = vmalloc_sync_one(pgd, address);
31317 + if (!ret)
31318 + break;
31319 + pgd = get_cpu_pgd(cpu, kernel);
31320 +#else
31321 list_for_each_entry(page, &pgd_list, lru) {
31322 + pgd_t *pgd;
31323 spinlock_t *pgt_lock;
31324 pmd_t *ret;
31325
31326 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31327 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31328
31329 spin_lock(pgt_lock);
31330 - ret = vmalloc_sync_one(page_address(page), address);
31331 + pgd = page_address(page);
31332 +#endif
31333 +
31334 + ret = vmalloc_sync_one(pgd, address);
31335 +
31336 +#ifndef CONFIG_PAX_PER_CPU_PGD
31337 spin_unlock(pgt_lock);
31338 +#endif
31339
31340 if (!ret)
31341 break;
31342 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31343 * an interrupt in the middle of a task switch..
31344 */
31345 pgd_paddr = read_cr3();
31346 +
31347 +#ifdef CONFIG_PAX_PER_CPU_PGD
31348 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31349 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31350 +#endif
31351 +
31352 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31353 if (!pmd_k)
31354 return -1;
31355 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31356 * happen within a race in page table update. In the later
31357 * case just flush:
31358 */
31359 - pgd = pgd_offset(current->active_mm, address);
31360 +
31361 pgd_ref = pgd_offset_k(address);
31362 if (pgd_none(*pgd_ref))
31363 return -1;
31364
31365 +#ifdef CONFIG_PAX_PER_CPU_PGD
31366 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31367 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31368 + if (pgd_none(*pgd)) {
31369 + set_pgd(pgd, *pgd_ref);
31370 + arch_flush_lazy_mmu_mode();
31371 + } else {
31372 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31373 + }
31374 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31375 +#else
31376 + pgd = pgd_offset(current->active_mm, address);
31377 +#endif
31378 +
31379 if (pgd_none(*pgd)) {
31380 set_pgd(pgd, *pgd_ref);
31381 arch_flush_lazy_mmu_mode();
31382 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31383 static int is_errata100(struct pt_regs *regs, unsigned long address)
31384 {
31385 #ifdef CONFIG_X86_64
31386 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31387 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31388 return 1;
31389 #endif
31390 return 0;
31391 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31392 }
31393
31394 static const char nx_warning[] = KERN_CRIT
31395 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31396 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31397
31398 static void
31399 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31400 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31401 if (!oops_may_print())
31402 return;
31403
31404 - if (error_code & PF_INSTR) {
31405 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31406 unsigned int level;
31407
31408 pte_t *pte = lookup_address(address, &level);
31409
31410 if (pte && pte_present(*pte) && !pte_exec(*pte))
31411 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31412 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31413 }
31414
31415 +#ifdef CONFIG_PAX_KERNEXEC
31416 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31417 + if (current->signal->curr_ip)
31418 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31419 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31420 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31421 + else
31422 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31423 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31424 + }
31425 +#endif
31426 +
31427 printk(KERN_ALERT "BUG: unable to handle kernel ");
31428 if (address < PAGE_SIZE)
31429 printk(KERN_CONT "NULL pointer dereference");
31430 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31431 return;
31432 }
31433 #endif
31434 +
31435 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31436 + if (pax_is_fetch_fault(regs, error_code, address)) {
31437 +
31438 +#ifdef CONFIG_PAX_EMUTRAMP
31439 + switch (pax_handle_fetch_fault(regs)) {
31440 + case 2:
31441 + return;
31442 + }
31443 +#endif
31444 +
31445 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31446 + do_group_exit(SIGKILL);
31447 + }
31448 +#endif
31449 +
31450 /* Kernel addresses are always protection faults: */
31451 if (address >= TASK_SIZE)
31452 error_code |= PF_PROT;
31453 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31454 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31455 printk(KERN_ERR
31456 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31457 - tsk->comm, tsk->pid, address);
31458 + tsk->comm, task_pid_nr(tsk), address);
31459 code = BUS_MCEERR_AR;
31460 }
31461 #endif
31462 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31463 return 1;
31464 }
31465
31466 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31467 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31468 +{
31469 + pte_t *pte;
31470 + pmd_t *pmd;
31471 + spinlock_t *ptl;
31472 + unsigned char pte_mask;
31473 +
31474 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31475 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31476 + return 0;
31477 +
31478 + /* PaX: it's our fault, let's handle it if we can */
31479 +
31480 + /* PaX: take a look at read faults before acquiring any locks */
31481 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31482 + /* instruction fetch attempt from a protected page in user mode */
31483 + up_read(&mm->mmap_sem);
31484 +
31485 +#ifdef CONFIG_PAX_EMUTRAMP
31486 + switch (pax_handle_fetch_fault(regs)) {
31487 + case 2:
31488 + return 1;
31489 + }
31490 +#endif
31491 +
31492 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31493 + do_group_exit(SIGKILL);
31494 + }
31495 +
31496 + pmd = pax_get_pmd(mm, address);
31497 + if (unlikely(!pmd))
31498 + return 0;
31499 +
31500 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31501 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31502 + pte_unmap_unlock(pte, ptl);
31503 + return 0;
31504 + }
31505 +
31506 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31507 + /* write attempt to a protected page in user mode */
31508 + pte_unmap_unlock(pte, ptl);
31509 + return 0;
31510 + }
31511 +
31512 +#ifdef CONFIG_SMP
31513 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31514 +#else
31515 + if (likely(address > get_limit(regs->cs)))
31516 +#endif
31517 + {
31518 + set_pte(pte, pte_mkread(*pte));
31519 + __flush_tlb_one(address);
31520 + pte_unmap_unlock(pte, ptl);
31521 + up_read(&mm->mmap_sem);
31522 + return 1;
31523 + }
31524 +
31525 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31526 +
31527 + /*
31528 + * PaX: fill DTLB with user rights and retry
31529 + */
31530 + __asm__ __volatile__ (
31531 + "orb %2,(%1)\n"
31532 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31533 +/*
31534 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31535 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31536 + * page fault when examined during a TLB load attempt. this is true not only
31537 + * for PTEs holding a non-present entry but also present entries that will
31538 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31539 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31540 + * for our target pages since their PTEs are simply not in the TLBs at all.
31541 +
31542 + * the best thing in omitting it is that we gain around 15-20% speed in the
31543 + * fast path of the page fault handler and can get rid of tracing since we
31544 + * can no longer flush unintended entries.
31545 + */
31546 + "invlpg (%0)\n"
31547 +#endif
31548 + __copyuser_seg"testb $0,(%0)\n"
31549 + "xorb %3,(%1)\n"
31550 + :
31551 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31552 + : "memory", "cc");
31553 + pte_unmap_unlock(pte, ptl);
31554 + up_read(&mm->mmap_sem);
31555 + return 1;
31556 +}
31557 +#endif
31558 +
31559 /*
31560 * Handle a spurious fault caused by a stale TLB entry.
31561 *
31562 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31563 static inline int
31564 access_error(unsigned long error_code, struct vm_area_struct *vma)
31565 {
31566 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31567 + return 1;
31568 +
31569 if (error_code & PF_WRITE) {
31570 /* write, present and write, not present: */
31571 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31572 @@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31573 if (error_code & PF_USER)
31574 return false;
31575
31576 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31577 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31578 return false;
31579
31580 return true;
31581 @@ -1037,6 +1245,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31582 /* Get the faulting address: */
31583 address = read_cr2();
31584
31585 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31586 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31587 + if (!search_exception_tables(regs->ip)) {
31588 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31589 + bad_area_nosemaphore(regs, error_code, address);
31590 + return;
31591 + }
31592 + if (address < pax_user_shadow_base) {
31593 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31594 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31595 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31596 + } else
31597 + address -= pax_user_shadow_base;
31598 + }
31599 +#endif
31600 +
31601 /*
31602 * Detect and handle instructions that would cause a page fault for
31603 * both a tracked kernel page and a userspace page.
31604 @@ -1114,7 +1338,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31605 * User-mode registers count as a user access even for any
31606 * potential system fault or CPU buglet:
31607 */
31608 - if (user_mode_vm(regs)) {
31609 + if (user_mode(regs)) {
31610 local_irq_enable();
31611 error_code |= PF_USER;
31612 flags |= FAULT_FLAG_USER;
31613 @@ -1161,6 +1385,11 @@ retry:
31614 might_sleep();
31615 }
31616
31617 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31618 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31619 + return;
31620 +#endif
31621 +
31622 vma = find_vma(mm, address);
31623 if (unlikely(!vma)) {
31624 bad_area(regs, error_code, address);
31625 @@ -1172,18 +1401,24 @@ retry:
31626 bad_area(regs, error_code, address);
31627 return;
31628 }
31629 - if (error_code & PF_USER) {
31630 - /*
31631 - * Accessing the stack below %sp is always a bug.
31632 - * The large cushion allows instructions like enter
31633 - * and pusha to work. ("enter $65535, $31" pushes
31634 - * 32 pointers and then decrements %sp by 65535.)
31635 - */
31636 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31637 - bad_area(regs, error_code, address);
31638 - return;
31639 - }
31640 + /*
31641 + * Accessing the stack below %sp is always a bug.
31642 + * The large cushion allows instructions like enter
31643 + * and pusha to work. ("enter $65535, $31" pushes
31644 + * 32 pointers and then decrements %sp by 65535.)
31645 + */
31646 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31647 + bad_area(regs, error_code, address);
31648 + return;
31649 }
31650 +
31651 +#ifdef CONFIG_PAX_SEGMEXEC
31652 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31653 + bad_area(regs, error_code, address);
31654 + return;
31655 + }
31656 +#endif
31657 +
31658 if (unlikely(expand_stack(vma, address))) {
31659 bad_area(regs, error_code, address);
31660 return;
31661 @@ -1277,3 +1512,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31662 __do_page_fault(regs, error_code);
31663 exception_exit(prev_state);
31664 }
31665 +
31666 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31667 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31668 +{
31669 + struct mm_struct *mm = current->mm;
31670 + unsigned long ip = regs->ip;
31671 +
31672 + if (v8086_mode(regs))
31673 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31674 +
31675 +#ifdef CONFIG_PAX_PAGEEXEC
31676 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31677 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31678 + return true;
31679 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31680 + return true;
31681 + return false;
31682 + }
31683 +#endif
31684 +
31685 +#ifdef CONFIG_PAX_SEGMEXEC
31686 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31687 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31688 + return true;
31689 + return false;
31690 + }
31691 +#endif
31692 +
31693 + return false;
31694 +}
31695 +#endif
31696 +
31697 +#ifdef CONFIG_PAX_EMUTRAMP
31698 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31699 +{
31700 + int err;
31701 +
31702 + do { /* PaX: libffi trampoline emulation */
31703 + unsigned char mov, jmp;
31704 + unsigned int addr1, addr2;
31705 +
31706 +#ifdef CONFIG_X86_64
31707 + if ((regs->ip + 9) >> 32)
31708 + break;
31709 +#endif
31710 +
31711 + err = get_user(mov, (unsigned char __user *)regs->ip);
31712 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31713 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31714 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31715 +
31716 + if (err)
31717 + break;
31718 +
31719 + if (mov == 0xB8 && jmp == 0xE9) {
31720 + regs->ax = addr1;
31721 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31722 + return 2;
31723 + }
31724 + } while (0);
31725 +
31726 + do { /* PaX: gcc trampoline emulation #1 */
31727 + unsigned char mov1, mov2;
31728 + unsigned short jmp;
31729 + unsigned int addr1, addr2;
31730 +
31731 +#ifdef CONFIG_X86_64
31732 + if ((regs->ip + 11) >> 32)
31733 + break;
31734 +#endif
31735 +
31736 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31737 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31738 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31739 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31740 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31741 +
31742 + if (err)
31743 + break;
31744 +
31745 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31746 + regs->cx = addr1;
31747 + regs->ax = addr2;
31748 + regs->ip = addr2;
31749 + return 2;
31750 + }
31751 + } while (0);
31752 +
31753 + do { /* PaX: gcc trampoline emulation #2 */
31754 + unsigned char mov, jmp;
31755 + unsigned int addr1, addr2;
31756 +
31757 +#ifdef CONFIG_X86_64
31758 + if ((regs->ip + 9) >> 32)
31759 + break;
31760 +#endif
31761 +
31762 + err = get_user(mov, (unsigned char __user *)regs->ip);
31763 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31764 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31765 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31766 +
31767 + if (err)
31768 + break;
31769 +
31770 + if (mov == 0xB9 && jmp == 0xE9) {
31771 + regs->cx = addr1;
31772 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31773 + return 2;
31774 + }
31775 + } while (0);
31776 +
31777 + return 1; /* PaX in action */
31778 +}
31779 +
31780 +#ifdef CONFIG_X86_64
31781 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31782 +{
31783 + int err;
31784 +
31785 + do { /* PaX: libffi trampoline emulation */
31786 + unsigned short mov1, mov2, jmp1;
31787 + unsigned char stcclc, jmp2;
31788 + unsigned long addr1, addr2;
31789 +
31790 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31791 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31792 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31793 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31794 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31795 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31796 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31797 +
31798 + if (err)
31799 + break;
31800 +
31801 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31802 + regs->r11 = addr1;
31803 + regs->r10 = addr2;
31804 + if (stcclc == 0xF8)
31805 + regs->flags &= ~X86_EFLAGS_CF;
31806 + else
31807 + regs->flags |= X86_EFLAGS_CF;
31808 + regs->ip = addr1;
31809 + return 2;
31810 + }
31811 + } while (0);
31812 +
31813 + do { /* PaX: gcc trampoline emulation #1 */
31814 + unsigned short mov1, mov2, jmp1;
31815 + unsigned char jmp2;
31816 + unsigned int addr1;
31817 + unsigned long addr2;
31818 +
31819 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31820 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31821 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31822 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31823 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31824 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31825 +
31826 + if (err)
31827 + break;
31828 +
31829 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31830 + regs->r11 = addr1;
31831 + regs->r10 = addr2;
31832 + regs->ip = addr1;
31833 + return 2;
31834 + }
31835 + } while (0);
31836 +
31837 + do { /* PaX: gcc trampoline emulation #2 */
31838 + unsigned short mov1, mov2, jmp1;
31839 + unsigned char jmp2;
31840 + unsigned long addr1, addr2;
31841 +
31842 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31843 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31844 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31845 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31846 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31847 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31848 +
31849 + if (err)
31850 + break;
31851 +
31852 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31853 + regs->r11 = addr1;
31854 + regs->r10 = addr2;
31855 + regs->ip = addr1;
31856 + return 2;
31857 + }
31858 + } while (0);
31859 +
31860 + return 1; /* PaX in action */
31861 +}
31862 +#endif
31863 +
31864 +/*
31865 + * PaX: decide what to do with offenders (regs->ip = fault address)
31866 + *
31867 + * returns 1 when task should be killed
31868 + * 2 when gcc trampoline was detected
31869 + */
31870 +static int pax_handle_fetch_fault(struct pt_regs *regs)
31871 +{
31872 + if (v8086_mode(regs))
31873 + return 1;
31874 +
31875 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31876 + return 1;
31877 +
31878 +#ifdef CONFIG_X86_32
31879 + return pax_handle_fetch_fault_32(regs);
31880 +#else
31881 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31882 + return pax_handle_fetch_fault_32(regs);
31883 + else
31884 + return pax_handle_fetch_fault_64(regs);
31885 +#endif
31886 +}
31887 +#endif
31888 +
31889 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31890 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31891 +{
31892 + long i;
31893 +
31894 + printk(KERN_ERR "PAX: bytes at PC: ");
31895 + for (i = 0; i < 20; i++) {
31896 + unsigned char c;
31897 + if (get_user(c, (unsigned char __force_user *)pc+i))
31898 + printk(KERN_CONT "?? ");
31899 + else
31900 + printk(KERN_CONT "%02x ", c);
31901 + }
31902 + printk("\n");
31903 +
31904 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31905 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
31906 + unsigned long c;
31907 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
31908 +#ifdef CONFIG_X86_32
31909 + printk(KERN_CONT "???????? ");
31910 +#else
31911 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31912 + printk(KERN_CONT "???????? ???????? ");
31913 + else
31914 + printk(KERN_CONT "???????????????? ");
31915 +#endif
31916 + } else {
31917 +#ifdef CONFIG_X86_64
31918 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31919 + printk(KERN_CONT "%08x ", (unsigned int)c);
31920 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31921 + } else
31922 +#endif
31923 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31924 + }
31925 + }
31926 + printk("\n");
31927 +}
31928 +#endif
31929 +
31930 +/**
31931 + * probe_kernel_write(): safely attempt to write to a location
31932 + * @dst: address to write to
31933 + * @src: pointer to the data that shall be written
31934 + * @size: size of the data chunk
31935 + *
31936 + * Safely write to address @dst from the buffer at @src. If a kernel fault
31937 + * happens, handle that and return -EFAULT.
31938 + */
31939 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31940 +{
31941 + long ret;
31942 + mm_segment_t old_fs = get_fs();
31943 +
31944 + set_fs(KERNEL_DS);
31945 + pagefault_disable();
31946 + pax_open_kernel();
31947 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31948 + pax_close_kernel();
31949 + pagefault_enable();
31950 + set_fs(old_fs);
31951 +
31952 + return ret ? -EFAULT : 0;
31953 +}
31954 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31955 index 0596e8e..5626789 100644
31956 --- a/arch/x86/mm/gup.c
31957 +++ b/arch/x86/mm/gup.c
31958 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31959 addr = start;
31960 len = (unsigned long) nr_pages << PAGE_SHIFT;
31961 end = start + len;
31962 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31963 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31964 (void __user *)start, len)))
31965 return 0;
31966
31967 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31968 goto slow_irqon;
31969 #endif
31970
31971 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31972 + (void __user *)start, len)))
31973 + return 0;
31974 +
31975 /*
31976 * XXX: batch / limit 'nr', to avoid large irq off latency
31977 * needs some instrumenting to determine the common sizes used by
31978 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31979 index 4500142..53a363c 100644
31980 --- a/arch/x86/mm/highmem_32.c
31981 +++ b/arch/x86/mm/highmem_32.c
31982 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31983 idx = type + KM_TYPE_NR*smp_processor_id();
31984 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31985 BUG_ON(!pte_none(*(kmap_pte-idx)));
31986 +
31987 + pax_open_kernel();
31988 set_pte(kmap_pte-idx, mk_pte(page, prot));
31989 + pax_close_kernel();
31990 +
31991 arch_flush_lazy_mmu_mode();
31992
31993 return (void *)vaddr;
31994 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31995 index 9d980d8..6bbfacb 100644
31996 --- a/arch/x86/mm/hugetlbpage.c
31997 +++ b/arch/x86/mm/hugetlbpage.c
31998 @@ -92,23 +92,30 @@ int pmd_huge_support(void)
31999 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
32000 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32001 unsigned long addr, unsigned long len,
32002 - unsigned long pgoff, unsigned long flags)
32003 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32004 {
32005 struct hstate *h = hstate_file(file);
32006 struct vm_unmapped_area_info info;
32007 -
32008 +
32009 info.flags = 0;
32010 info.length = len;
32011 info.low_limit = TASK_UNMAPPED_BASE;
32012 +
32013 +#ifdef CONFIG_PAX_RANDMMAP
32014 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32015 + info.low_limit += current->mm->delta_mmap;
32016 +#endif
32017 +
32018 info.high_limit = TASK_SIZE;
32019 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32020 info.align_offset = 0;
32021 + info.threadstack_offset = offset;
32022 return vm_unmapped_area(&info);
32023 }
32024
32025 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32026 unsigned long addr0, unsigned long len,
32027 - unsigned long pgoff, unsigned long flags)
32028 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32029 {
32030 struct hstate *h = hstate_file(file);
32031 struct vm_unmapped_area_info info;
32032 @@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32033 info.high_limit = current->mm->mmap_base;
32034 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32035 info.align_offset = 0;
32036 + info.threadstack_offset = offset;
32037 addr = vm_unmapped_area(&info);
32038
32039 /*
32040 @@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32041 VM_BUG_ON(addr != -ENOMEM);
32042 info.flags = 0;
32043 info.low_limit = TASK_UNMAPPED_BASE;
32044 +
32045 +#ifdef CONFIG_PAX_RANDMMAP
32046 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32047 + info.low_limit += current->mm->delta_mmap;
32048 +#endif
32049 +
32050 info.high_limit = TASK_SIZE;
32051 addr = vm_unmapped_area(&info);
32052 }
32053 @@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32054 struct hstate *h = hstate_file(file);
32055 struct mm_struct *mm = current->mm;
32056 struct vm_area_struct *vma;
32057 + unsigned long pax_task_size = TASK_SIZE;
32058 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32059
32060 if (len & ~huge_page_mask(h))
32061 return -EINVAL;
32062 - if (len > TASK_SIZE)
32063 +
32064 +#ifdef CONFIG_PAX_SEGMEXEC
32065 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32066 + pax_task_size = SEGMEXEC_TASK_SIZE;
32067 +#endif
32068 +
32069 + pax_task_size -= PAGE_SIZE;
32070 +
32071 + if (len > pax_task_size)
32072 return -ENOMEM;
32073
32074 if (flags & MAP_FIXED) {
32075 @@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32076 return addr;
32077 }
32078
32079 +#ifdef CONFIG_PAX_RANDMMAP
32080 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32081 +#endif
32082 +
32083 if (addr) {
32084 addr = ALIGN(addr, huge_page_size(h));
32085 vma = find_vma(mm, addr);
32086 - if (TASK_SIZE - len >= addr &&
32087 - (!vma || addr + len <= vma->vm_start))
32088 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32089 return addr;
32090 }
32091 if (mm->get_unmapped_area == arch_get_unmapped_area)
32092 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32093 - pgoff, flags);
32094 + pgoff, flags, offset);
32095 else
32096 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32097 - pgoff, flags);
32098 + pgoff, flags, offset);
32099 }
32100
32101 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
32102 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32103 index f971306..e83e0f6 100644
32104 --- a/arch/x86/mm/init.c
32105 +++ b/arch/x86/mm/init.c
32106 @@ -4,6 +4,7 @@
32107 #include <linux/swap.h>
32108 #include <linux/memblock.h>
32109 #include <linux/bootmem.h> /* for max_low_pfn */
32110 +#include <linux/tboot.h>
32111
32112 #include <asm/cacheflush.h>
32113 #include <asm/e820.h>
32114 @@ -17,6 +18,8 @@
32115 #include <asm/proto.h>
32116 #include <asm/dma.h> /* for MAX_DMA_PFN */
32117 #include <asm/microcode.h>
32118 +#include <asm/desc.h>
32119 +#include <asm/bios_ebda.h>
32120
32121 #include "mm_internal.h"
32122
32123 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32124 early_ioremap_page_table_range_init();
32125 #endif
32126
32127 +#ifdef CONFIG_PAX_PER_CPU_PGD
32128 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32129 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32130 + KERNEL_PGD_PTRS);
32131 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32132 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32133 + KERNEL_PGD_PTRS);
32134 + load_cr3(get_cpu_pgd(0, kernel));
32135 +#else
32136 load_cr3(swapper_pg_dir);
32137 +#endif
32138 +
32139 __flush_tlb_all();
32140
32141 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32142 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32143 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32144 * mmio resources as well as potential bios/acpi data regions.
32145 */
32146 +
32147 +#ifdef CONFIG_GRKERNSEC_KMEM
32148 +static unsigned int ebda_start __read_only;
32149 +static unsigned int ebda_end __read_only;
32150 +#endif
32151 +
32152 int devmem_is_allowed(unsigned long pagenr)
32153 {
32154 - if (pagenr < 256)
32155 +#ifdef CONFIG_GRKERNSEC_KMEM
32156 + /* allow BDA */
32157 + if (!pagenr)
32158 return 1;
32159 + /* allow EBDA */
32160 + if (pagenr >= ebda_start && pagenr < ebda_end)
32161 + return 1;
32162 + /* if tboot is in use, allow access to its hardcoded serial log range */
32163 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32164 + return 1;
32165 +#else
32166 + if (!pagenr)
32167 + return 1;
32168 +#ifdef CONFIG_VM86
32169 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32170 + return 1;
32171 +#endif
32172 +#endif
32173 +
32174 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32175 + return 1;
32176 +#ifdef CONFIG_GRKERNSEC_KMEM
32177 + /* throw out everything else below 1MB */
32178 + if (pagenr <= 256)
32179 + return 0;
32180 +#endif
32181 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32182 return 0;
32183 if (!page_is_ram(pagenr))
32184 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32185 #endif
32186 }
32187
32188 +#ifdef CONFIG_GRKERNSEC_KMEM
32189 +static inline void gr_init_ebda(void)
32190 +{
32191 + unsigned int ebda_addr;
32192 + unsigned int ebda_size = 0;
32193 +
32194 + ebda_addr = get_bios_ebda();
32195 + if (ebda_addr) {
32196 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32197 + ebda_size <<= 10;
32198 + }
32199 + if (ebda_addr && ebda_size) {
32200 + ebda_start = ebda_addr >> PAGE_SHIFT;
32201 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32202 + } else {
32203 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32204 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32205 + }
32206 +}
32207 +#else
32208 +static inline void gr_init_ebda(void) { }
32209 +#endif
32210 +
32211 void free_initmem(void)
32212 {
32213 +#ifdef CONFIG_PAX_KERNEXEC
32214 +#ifdef CONFIG_X86_32
32215 + /* PaX: limit KERNEL_CS to actual size */
32216 + unsigned long addr, limit;
32217 + struct desc_struct d;
32218 + int cpu;
32219 +#else
32220 + pgd_t *pgd;
32221 + pud_t *pud;
32222 + pmd_t *pmd;
32223 + unsigned long addr, end;
32224 +#endif
32225 +#endif
32226 +
32227 + gr_init_ebda();
32228 +
32229 +#ifdef CONFIG_PAX_KERNEXEC
32230 +#ifdef CONFIG_X86_32
32231 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32232 + limit = (limit - 1UL) >> PAGE_SHIFT;
32233 +
32234 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32235 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32236 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32237 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32238 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32239 + }
32240 +
32241 + /* PaX: make KERNEL_CS read-only */
32242 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32243 + if (!paravirt_enabled())
32244 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32245 +/*
32246 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32247 + pgd = pgd_offset_k(addr);
32248 + pud = pud_offset(pgd, addr);
32249 + pmd = pmd_offset(pud, addr);
32250 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32251 + }
32252 +*/
32253 +#ifdef CONFIG_X86_PAE
32254 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32255 +/*
32256 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32257 + pgd = pgd_offset_k(addr);
32258 + pud = pud_offset(pgd, addr);
32259 + pmd = pmd_offset(pud, addr);
32260 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32261 + }
32262 +*/
32263 +#endif
32264 +
32265 +#ifdef CONFIG_MODULES
32266 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32267 +#endif
32268 +
32269 +#else
32270 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32271 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32272 + pgd = pgd_offset_k(addr);
32273 + pud = pud_offset(pgd, addr);
32274 + pmd = pmd_offset(pud, addr);
32275 + if (!pmd_present(*pmd))
32276 + continue;
32277 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32278 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32279 + else
32280 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32281 + }
32282 +
32283 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32284 + end = addr + KERNEL_IMAGE_SIZE;
32285 + for (; addr < end; addr += PMD_SIZE) {
32286 + pgd = pgd_offset_k(addr);
32287 + pud = pud_offset(pgd, addr);
32288 + pmd = pmd_offset(pud, addr);
32289 + if (!pmd_present(*pmd))
32290 + continue;
32291 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32292 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32293 + }
32294 +#endif
32295 +
32296 + flush_tlb_all();
32297 +#endif
32298 +
32299 free_init_pages("unused kernel",
32300 (unsigned long)(&__init_begin),
32301 (unsigned long)(&__init_end));
32302 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32303 index 4287f1f..3b99c71 100644
32304 --- a/arch/x86/mm/init_32.c
32305 +++ b/arch/x86/mm/init_32.c
32306 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32307 bool __read_mostly __vmalloc_start_set = false;
32308
32309 /*
32310 - * Creates a middle page table and puts a pointer to it in the
32311 - * given global directory entry. This only returns the gd entry
32312 - * in non-PAE compilation mode, since the middle layer is folded.
32313 - */
32314 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32315 -{
32316 - pud_t *pud;
32317 - pmd_t *pmd_table;
32318 -
32319 -#ifdef CONFIG_X86_PAE
32320 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32321 - pmd_table = (pmd_t *)alloc_low_page();
32322 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32323 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32324 - pud = pud_offset(pgd, 0);
32325 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32326 -
32327 - return pmd_table;
32328 - }
32329 -#endif
32330 - pud = pud_offset(pgd, 0);
32331 - pmd_table = pmd_offset(pud, 0);
32332 -
32333 - return pmd_table;
32334 -}
32335 -
32336 -/*
32337 * Create a page table and place a pointer to it in a middle page
32338 * directory entry:
32339 */
32340 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32341 pte_t *page_table = (pte_t *)alloc_low_page();
32342
32343 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32344 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32345 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32346 +#else
32347 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32348 +#endif
32349 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32350 }
32351
32352 return pte_offset_kernel(pmd, 0);
32353 }
32354
32355 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32356 +{
32357 + pud_t *pud;
32358 + pmd_t *pmd_table;
32359 +
32360 + pud = pud_offset(pgd, 0);
32361 + pmd_table = pmd_offset(pud, 0);
32362 +
32363 + return pmd_table;
32364 +}
32365 +
32366 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32367 {
32368 int pgd_idx = pgd_index(vaddr);
32369 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32370 int pgd_idx, pmd_idx;
32371 unsigned long vaddr;
32372 pgd_t *pgd;
32373 + pud_t *pud;
32374 pmd_t *pmd;
32375 pte_t *pte = NULL;
32376 unsigned long count = page_table_range_init_count(start, end);
32377 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32378 pgd = pgd_base + pgd_idx;
32379
32380 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32381 - pmd = one_md_table_init(pgd);
32382 - pmd = pmd + pmd_index(vaddr);
32383 + pud = pud_offset(pgd, vaddr);
32384 + pmd = pmd_offset(pud, vaddr);
32385 +
32386 +#ifdef CONFIG_X86_PAE
32387 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32388 +#endif
32389 +
32390 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32391 pmd++, pmd_idx++) {
32392 pte = page_table_kmap_check(one_page_table_init(pmd),
32393 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32394 }
32395 }
32396
32397 -static inline int is_kernel_text(unsigned long addr)
32398 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32399 {
32400 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32401 - return 1;
32402 - return 0;
32403 + if ((start > ktla_ktva((unsigned long)_etext) ||
32404 + end <= ktla_ktva((unsigned long)_stext)) &&
32405 + (start > ktla_ktva((unsigned long)_einittext) ||
32406 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32407 +
32408 +#ifdef CONFIG_ACPI_SLEEP
32409 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32410 +#endif
32411 +
32412 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32413 + return 0;
32414 + return 1;
32415 }
32416
32417 /*
32418 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32419 unsigned long last_map_addr = end;
32420 unsigned long start_pfn, end_pfn;
32421 pgd_t *pgd_base = swapper_pg_dir;
32422 - int pgd_idx, pmd_idx, pte_ofs;
32423 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32424 unsigned long pfn;
32425 pgd_t *pgd;
32426 + pud_t *pud;
32427 pmd_t *pmd;
32428 pte_t *pte;
32429 unsigned pages_2m, pages_4k;
32430 @@ -291,8 +295,13 @@ repeat:
32431 pfn = start_pfn;
32432 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32433 pgd = pgd_base + pgd_idx;
32434 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32435 - pmd = one_md_table_init(pgd);
32436 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32437 + pud = pud_offset(pgd, 0);
32438 + pmd = pmd_offset(pud, 0);
32439 +
32440 +#ifdef CONFIG_X86_PAE
32441 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32442 +#endif
32443
32444 if (pfn >= end_pfn)
32445 continue;
32446 @@ -304,14 +313,13 @@ repeat:
32447 #endif
32448 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32449 pmd++, pmd_idx++) {
32450 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32451 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32452
32453 /*
32454 * Map with big pages if possible, otherwise
32455 * create normal page tables:
32456 */
32457 if (use_pse) {
32458 - unsigned int addr2;
32459 pgprot_t prot = PAGE_KERNEL_LARGE;
32460 /*
32461 * first pass will use the same initial
32462 @@ -322,11 +330,7 @@ repeat:
32463 _PAGE_PSE);
32464
32465 pfn &= PMD_MASK >> PAGE_SHIFT;
32466 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32467 - PAGE_OFFSET + PAGE_SIZE-1;
32468 -
32469 - if (is_kernel_text(addr) ||
32470 - is_kernel_text(addr2))
32471 + if (is_kernel_text(address, address + PMD_SIZE))
32472 prot = PAGE_KERNEL_LARGE_EXEC;
32473
32474 pages_2m++;
32475 @@ -343,7 +347,7 @@ repeat:
32476 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32477 pte += pte_ofs;
32478 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32479 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32480 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32481 pgprot_t prot = PAGE_KERNEL;
32482 /*
32483 * first pass will use the same initial
32484 @@ -351,7 +355,7 @@ repeat:
32485 */
32486 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32487
32488 - if (is_kernel_text(addr))
32489 + if (is_kernel_text(address, address + PAGE_SIZE))
32490 prot = PAGE_KERNEL_EXEC;
32491
32492 pages_4k++;
32493 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32494
32495 pud = pud_offset(pgd, va);
32496 pmd = pmd_offset(pud, va);
32497 - if (!pmd_present(*pmd))
32498 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32499 break;
32500
32501 /* should not be large page here */
32502 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32503
32504 static void __init pagetable_init(void)
32505 {
32506 - pgd_t *pgd_base = swapper_pg_dir;
32507 -
32508 - permanent_kmaps_init(pgd_base);
32509 + permanent_kmaps_init(swapper_pg_dir);
32510 }
32511
32512 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32513 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32514 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32515
32516 /* user-defined highmem size */
32517 @@ -787,10 +789,10 @@ void __init mem_init(void)
32518 ((unsigned long)&__init_end -
32519 (unsigned long)&__init_begin) >> 10,
32520
32521 - (unsigned long)&_etext, (unsigned long)&_edata,
32522 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32523 + (unsigned long)&_sdata, (unsigned long)&_edata,
32524 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32525
32526 - (unsigned long)&_text, (unsigned long)&_etext,
32527 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32528 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32529
32530 /*
32531 @@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
32532 if (!kernel_set_to_readonly)
32533 return;
32534
32535 + start = ktla_ktva(start);
32536 pr_debug("Set kernel text: %lx - %lx for read write\n",
32537 start, start+size);
32538
32539 @@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
32540 if (!kernel_set_to_readonly)
32541 return;
32542
32543 + start = ktla_ktva(start);
32544 pr_debug("Set kernel text: %lx - %lx for read only\n",
32545 start, start+size);
32546
32547 @@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32548 unsigned long start = PFN_ALIGN(_text);
32549 unsigned long size = PFN_ALIGN(_etext) - start;
32550
32551 + start = ktla_ktva(start);
32552 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32553 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32554 size >> 10);
32555 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32556 index 104d56a..62ba13f1 100644
32557 --- a/arch/x86/mm/init_64.c
32558 +++ b/arch/x86/mm/init_64.c
32559 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32560 * around without checking the pgd every time.
32561 */
32562
32563 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32564 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32565 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32566
32567 int force_personality32;
32568 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32569
32570 for (address = start; address <= end; address += PGDIR_SIZE) {
32571 const pgd_t *pgd_ref = pgd_offset_k(address);
32572 +
32573 +#ifdef CONFIG_PAX_PER_CPU_PGD
32574 + unsigned long cpu;
32575 +#else
32576 struct page *page;
32577 +#endif
32578
32579 if (pgd_none(*pgd_ref))
32580 continue;
32581
32582 spin_lock(&pgd_lock);
32583 +
32584 +#ifdef CONFIG_PAX_PER_CPU_PGD
32585 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32586 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32587 +
32588 + if (pgd_none(*pgd))
32589 + set_pgd(pgd, *pgd_ref);
32590 + else
32591 + BUG_ON(pgd_page_vaddr(*pgd)
32592 + != pgd_page_vaddr(*pgd_ref));
32593 + pgd = pgd_offset_cpu(cpu, kernel, address);
32594 +#else
32595 list_for_each_entry(page, &pgd_list, lru) {
32596 pgd_t *pgd;
32597 spinlock_t *pgt_lock;
32598 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32599 /* the pgt_lock only for Xen */
32600 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32601 spin_lock(pgt_lock);
32602 +#endif
32603
32604 if (pgd_none(*pgd))
32605 set_pgd(pgd, *pgd_ref);
32606 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32607 BUG_ON(pgd_page_vaddr(*pgd)
32608 != pgd_page_vaddr(*pgd_ref));
32609
32610 +#ifndef CONFIG_PAX_PER_CPU_PGD
32611 spin_unlock(pgt_lock);
32612 +#endif
32613 +
32614 }
32615 spin_unlock(&pgd_lock);
32616 }
32617 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32618 {
32619 if (pgd_none(*pgd)) {
32620 pud_t *pud = (pud_t *)spp_getpage();
32621 - pgd_populate(&init_mm, pgd, pud);
32622 + pgd_populate_kernel(&init_mm, pgd, pud);
32623 if (pud != pud_offset(pgd, 0))
32624 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32625 pud, pud_offset(pgd, 0));
32626 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32627 {
32628 if (pud_none(*pud)) {
32629 pmd_t *pmd = (pmd_t *) spp_getpage();
32630 - pud_populate(&init_mm, pud, pmd);
32631 + pud_populate_kernel(&init_mm, pud, pmd);
32632 if (pmd != pmd_offset(pud, 0))
32633 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32634 pmd, pmd_offset(pud, 0));
32635 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32636 pmd = fill_pmd(pud, vaddr);
32637 pte = fill_pte(pmd, vaddr);
32638
32639 + pax_open_kernel();
32640 set_pte(pte, new_pte);
32641 + pax_close_kernel();
32642
32643 /*
32644 * It's enough to flush this one mapping.
32645 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32646 pgd = pgd_offset_k((unsigned long)__va(phys));
32647 if (pgd_none(*pgd)) {
32648 pud = (pud_t *) spp_getpage();
32649 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32650 - _PAGE_USER));
32651 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32652 }
32653 pud = pud_offset(pgd, (unsigned long)__va(phys));
32654 if (pud_none(*pud)) {
32655 pmd = (pmd_t *) spp_getpage();
32656 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32657 - _PAGE_USER));
32658 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32659 }
32660 pmd = pmd_offset(pud, phys);
32661 BUG_ON(!pmd_none(*pmd));
32662 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32663 prot);
32664
32665 spin_lock(&init_mm.page_table_lock);
32666 - pud_populate(&init_mm, pud, pmd);
32667 + pud_populate_kernel(&init_mm, pud, pmd);
32668 spin_unlock(&init_mm.page_table_lock);
32669 }
32670 __flush_tlb_all();
32671 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32672 page_size_mask);
32673
32674 spin_lock(&init_mm.page_table_lock);
32675 - pgd_populate(&init_mm, pgd, pud);
32676 + pgd_populate_kernel(&init_mm, pgd, pud);
32677 spin_unlock(&init_mm.page_table_lock);
32678 pgd_changed = true;
32679 }
32680 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32681 static struct vm_area_struct gate_vma = {
32682 .vm_start = VSYSCALL_START,
32683 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32684 - .vm_page_prot = PAGE_READONLY_EXEC,
32685 - .vm_flags = VM_READ | VM_EXEC
32686 + .vm_page_prot = PAGE_READONLY,
32687 + .vm_flags = VM_READ
32688 };
32689
32690 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32691 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32692
32693 const char *arch_vma_name(struct vm_area_struct *vma)
32694 {
32695 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32696 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32697 return "[vdso]";
32698 if (vma == &gate_vma)
32699 return "[vsyscall]";
32700 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32701 index 7b179b4..6bd17777 100644
32702 --- a/arch/x86/mm/iomap_32.c
32703 +++ b/arch/x86/mm/iomap_32.c
32704 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32705 type = kmap_atomic_idx_push();
32706 idx = type + KM_TYPE_NR * smp_processor_id();
32707 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32708 +
32709 + pax_open_kernel();
32710 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32711 + pax_close_kernel();
32712 +
32713 arch_flush_lazy_mmu_mode();
32714
32715 return (void *)vaddr;
32716 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32717 index 799580c..72f9fe0 100644
32718 --- a/arch/x86/mm/ioremap.c
32719 +++ b/arch/x86/mm/ioremap.c
32720 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32721 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32722 int is_ram = page_is_ram(pfn);
32723
32724 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32725 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32726 return NULL;
32727 WARN_ON_ONCE(is_ram);
32728 }
32729 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32730 *
32731 * Caller must ensure there is only one unmapping for the same pointer.
32732 */
32733 -void iounmap(volatile void __iomem *addr)
32734 +void iounmap(const volatile void __iomem *addr)
32735 {
32736 struct vm_struct *p, *o;
32737
32738 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32739
32740 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32741 if (page_is_ram(start >> PAGE_SHIFT))
32742 +#ifdef CONFIG_HIGHMEM
32743 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32744 +#endif
32745 return __va(phys);
32746
32747 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32748 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32749 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32750 {
32751 if (page_is_ram(phys >> PAGE_SHIFT))
32752 +#ifdef CONFIG_HIGHMEM
32753 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32754 +#endif
32755 return;
32756
32757 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32758 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32759 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32760
32761 static __initdata int after_paging_init;
32762 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32763 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32764
32765 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32766 {
32767 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32768 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32769
32770 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32771 - memset(bm_pte, 0, sizeof(bm_pte));
32772 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32773 + pmd_populate_user(&init_mm, pmd, bm_pte);
32774
32775 /*
32776 * The boot-ioremap range spans multiple pmds, for which
32777 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32778 index d87dd6d..bf3fa66 100644
32779 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32780 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32781 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32782 * memory (e.g. tracked pages)? For now, we need this to avoid
32783 * invoking kmemcheck for PnP BIOS calls.
32784 */
32785 - if (regs->flags & X86_VM_MASK)
32786 + if (v8086_mode(regs))
32787 return false;
32788 - if (regs->cs != __KERNEL_CS)
32789 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32790 return false;
32791
32792 pte = kmemcheck_pte_lookup(address);
32793 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32794 index 25e7e13..1964579 100644
32795 --- a/arch/x86/mm/mmap.c
32796 +++ b/arch/x86/mm/mmap.c
32797 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32798 * Leave an at least ~128 MB hole with possible stack randomization.
32799 */
32800 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32801 -#define MAX_GAP (TASK_SIZE/6*5)
32802 +#define MAX_GAP (pax_task_size/6*5)
32803
32804 static int mmap_is_legacy(void)
32805 {
32806 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32807 return rnd << PAGE_SHIFT;
32808 }
32809
32810 -static unsigned long mmap_base(void)
32811 +static unsigned long mmap_base(struct mm_struct *mm)
32812 {
32813 unsigned long gap = rlimit(RLIMIT_STACK);
32814 + unsigned long pax_task_size = TASK_SIZE;
32815 +
32816 +#ifdef CONFIG_PAX_SEGMEXEC
32817 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32818 + pax_task_size = SEGMEXEC_TASK_SIZE;
32819 +#endif
32820
32821 if (gap < MIN_GAP)
32822 gap = MIN_GAP;
32823 else if (gap > MAX_GAP)
32824 gap = MAX_GAP;
32825
32826 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32827 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32828 }
32829
32830 /*
32831 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32832 * does, but not when emulating X86_32
32833 */
32834 -static unsigned long mmap_legacy_base(void)
32835 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32836 {
32837 - if (mmap_is_ia32())
32838 + if (mmap_is_ia32()) {
32839 +
32840 +#ifdef CONFIG_PAX_SEGMEXEC
32841 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32842 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32843 + else
32844 +#endif
32845 +
32846 return TASK_UNMAPPED_BASE;
32847 - else
32848 + } else
32849 return TASK_UNMAPPED_BASE + mmap_rnd();
32850 }
32851
32852 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32853 */
32854 void arch_pick_mmap_layout(struct mm_struct *mm)
32855 {
32856 - mm->mmap_legacy_base = mmap_legacy_base();
32857 - mm->mmap_base = mmap_base();
32858 + mm->mmap_legacy_base = mmap_legacy_base(mm);
32859 + mm->mmap_base = mmap_base(mm);
32860 +
32861 +#ifdef CONFIG_PAX_RANDMMAP
32862 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
32863 + mm->mmap_legacy_base += mm->delta_mmap;
32864 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32865 + }
32866 +#endif
32867
32868 if (mmap_is_legacy()) {
32869 mm->mmap_base = mm->mmap_legacy_base;
32870 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32871 index 0057a7a..95c7edd 100644
32872 --- a/arch/x86/mm/mmio-mod.c
32873 +++ b/arch/x86/mm/mmio-mod.c
32874 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32875 break;
32876 default:
32877 {
32878 - unsigned char *ip = (unsigned char *)instptr;
32879 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32880 my_trace->opcode = MMIO_UNKNOWN_OP;
32881 my_trace->width = 0;
32882 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32883 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32884 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32885 void __iomem *addr)
32886 {
32887 - static atomic_t next_id;
32888 + static atomic_unchecked_t next_id;
32889 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32890 /* These are page-unaligned. */
32891 struct mmiotrace_map map = {
32892 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32893 .private = trace
32894 },
32895 .phys = offset,
32896 - .id = atomic_inc_return(&next_id)
32897 + .id = atomic_inc_return_unchecked(&next_id)
32898 };
32899 map.map_id = trace->id;
32900
32901 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32902 ioremap_trace_core(offset, size, addr);
32903 }
32904
32905 -static void iounmap_trace_core(volatile void __iomem *addr)
32906 +static void iounmap_trace_core(const volatile void __iomem *addr)
32907 {
32908 struct mmiotrace_map map = {
32909 .phys = 0,
32910 @@ -328,7 +328,7 @@ not_enabled:
32911 }
32912 }
32913
32914 -void mmiotrace_iounmap(volatile void __iomem *addr)
32915 +void mmiotrace_iounmap(const volatile void __iomem *addr)
32916 {
32917 might_sleep();
32918 if (is_enabled()) /* recheck and proper locking in *_core() */
32919 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32920 index 24aec58..c39fe8b 100644
32921 --- a/arch/x86/mm/numa.c
32922 +++ b/arch/x86/mm/numa.c
32923 @@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32924 return true;
32925 }
32926
32927 -static int __init numa_register_memblks(struct numa_meminfo *mi)
32928 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32929 {
32930 unsigned long uninitialized_var(pfn_align);
32931 int i, nid;
32932 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32933 index d0b1773..4c3327c 100644
32934 --- a/arch/x86/mm/pageattr-test.c
32935 +++ b/arch/x86/mm/pageattr-test.c
32936 @@ -36,7 +36,7 @@ enum {
32937
32938 static int pte_testbit(pte_t pte)
32939 {
32940 - return pte_flags(pte) & _PAGE_UNUSED1;
32941 + return pte_flags(pte) & _PAGE_CPA_TEST;
32942 }
32943
32944 struct split_state {
32945 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32946 index bb32480..75f2f5e 100644
32947 --- a/arch/x86/mm/pageattr.c
32948 +++ b/arch/x86/mm/pageattr.c
32949 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32950 */
32951 #ifdef CONFIG_PCI_BIOS
32952 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32953 - pgprot_val(forbidden) |= _PAGE_NX;
32954 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32955 #endif
32956
32957 /*
32958 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32959 * Does not cover __inittext since that is gone later on. On
32960 * 64bit we do not enforce !NX on the low mapping
32961 */
32962 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
32963 - pgprot_val(forbidden) |= _PAGE_NX;
32964 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32965 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32966
32967 +#ifdef CONFIG_DEBUG_RODATA
32968 /*
32969 * The .rodata section needs to be read-only. Using the pfn
32970 * catches all aliases.
32971 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32972 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32973 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32974 pgprot_val(forbidden) |= _PAGE_RW;
32975 +#endif
32976
32977 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32978 /*
32979 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32980 }
32981 #endif
32982
32983 +#ifdef CONFIG_PAX_KERNEXEC
32984 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32985 + pgprot_val(forbidden) |= _PAGE_RW;
32986 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32987 + }
32988 +#endif
32989 +
32990 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32991
32992 return prot;
32993 @@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32994 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32995 {
32996 /* change init_mm */
32997 + pax_open_kernel();
32998 set_pte_atomic(kpte, pte);
32999 +
33000 #ifdef CONFIG_X86_32
33001 if (!SHARED_KERNEL_PMD) {
33002 +
33003 +#ifdef CONFIG_PAX_PER_CPU_PGD
33004 + unsigned long cpu;
33005 +#else
33006 struct page *page;
33007 +#endif
33008
33009 +#ifdef CONFIG_PAX_PER_CPU_PGD
33010 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33011 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33012 +#else
33013 list_for_each_entry(page, &pgd_list, lru) {
33014 - pgd_t *pgd;
33015 + pgd_t *pgd = (pgd_t *)page_address(page);
33016 +#endif
33017 +
33018 pud_t *pud;
33019 pmd_t *pmd;
33020
33021 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33022 + pgd += pgd_index(address);
33023 pud = pud_offset(pgd, address);
33024 pmd = pmd_offset(pud, address);
33025 set_pte_atomic((pte_t *)pmd, pte);
33026 }
33027 }
33028 #endif
33029 + pax_close_kernel();
33030 }
33031
33032 static int
33033 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33034 index 6574388..87e9bef 100644
33035 --- a/arch/x86/mm/pat.c
33036 +++ b/arch/x86/mm/pat.c
33037 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33038
33039 if (!entry) {
33040 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33041 - current->comm, current->pid, start, end - 1);
33042 + current->comm, task_pid_nr(current), start, end - 1);
33043 return -EINVAL;
33044 }
33045
33046 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33047
33048 while (cursor < to) {
33049 if (!devmem_is_allowed(pfn)) {
33050 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33051 - current->comm, from, to - 1);
33052 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33053 + current->comm, from, to - 1, cursor);
33054 return 0;
33055 }
33056 cursor += PAGE_SIZE;
33057 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33058 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33059 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33060 "for [mem %#010Lx-%#010Lx]\n",
33061 - current->comm, current->pid,
33062 + current->comm, task_pid_nr(current),
33063 cattr_name(flags),
33064 base, (unsigned long long)(base + size-1));
33065 return -EINVAL;
33066 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33067 flags = lookup_memtype(paddr);
33068 if (want_flags != flags) {
33069 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33070 - current->comm, current->pid,
33071 + current->comm, task_pid_nr(current),
33072 cattr_name(want_flags),
33073 (unsigned long long)paddr,
33074 (unsigned long long)(paddr + size - 1),
33075 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33076 free_memtype(paddr, paddr + size);
33077 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33078 " for [mem %#010Lx-%#010Lx], got %s\n",
33079 - current->comm, current->pid,
33080 + current->comm, task_pid_nr(current),
33081 cattr_name(want_flags),
33082 (unsigned long long)paddr,
33083 (unsigned long long)(paddr + size - 1),
33084 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33085 index 415f6c4..d319983 100644
33086 --- a/arch/x86/mm/pat_rbtree.c
33087 +++ b/arch/x86/mm/pat_rbtree.c
33088 @@ -160,7 +160,7 @@ success:
33089
33090 failure:
33091 printk(KERN_INFO "%s:%d conflicting memory types "
33092 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33093 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33094 end, cattr_name(found_type), cattr_name(match->type));
33095 return -EBUSY;
33096 }
33097 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33098 index 9f0614d..92ae64a 100644
33099 --- a/arch/x86/mm/pf_in.c
33100 +++ b/arch/x86/mm/pf_in.c
33101 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33102 int i;
33103 enum reason_type rv = OTHERS;
33104
33105 - p = (unsigned char *)ins_addr;
33106 + p = (unsigned char *)ktla_ktva(ins_addr);
33107 p += skip_prefix(p, &prf);
33108 p += get_opcode(p, &opcode);
33109
33110 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33111 struct prefix_bits prf;
33112 int i;
33113
33114 - p = (unsigned char *)ins_addr;
33115 + p = (unsigned char *)ktla_ktva(ins_addr);
33116 p += skip_prefix(p, &prf);
33117 p += get_opcode(p, &opcode);
33118
33119 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33120 struct prefix_bits prf;
33121 int i;
33122
33123 - p = (unsigned char *)ins_addr;
33124 + p = (unsigned char *)ktla_ktva(ins_addr);
33125 p += skip_prefix(p, &prf);
33126 p += get_opcode(p, &opcode);
33127
33128 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33129 struct prefix_bits prf;
33130 int i;
33131
33132 - p = (unsigned char *)ins_addr;
33133 + p = (unsigned char *)ktla_ktva(ins_addr);
33134 p += skip_prefix(p, &prf);
33135 p += get_opcode(p, &opcode);
33136 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33137 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33138 struct prefix_bits prf;
33139 int i;
33140
33141 - p = (unsigned char *)ins_addr;
33142 + p = (unsigned char *)ktla_ktva(ins_addr);
33143 p += skip_prefix(p, &prf);
33144 p += get_opcode(p, &opcode);
33145 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33146 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33147 index c96314a..433b127 100644
33148 --- a/arch/x86/mm/pgtable.c
33149 +++ b/arch/x86/mm/pgtable.c
33150 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33151 list_del(&page->lru);
33152 }
33153
33154 -#define UNSHARED_PTRS_PER_PGD \
33155 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33156 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33157 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33158
33159 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33160 +{
33161 + unsigned int count = USER_PGD_PTRS;
33162
33163 + if (!pax_user_shadow_base)
33164 + return;
33165 +
33166 + while (count--)
33167 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33168 +}
33169 +#endif
33170 +
33171 +#ifdef CONFIG_PAX_PER_CPU_PGD
33172 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33173 +{
33174 + unsigned int count = USER_PGD_PTRS;
33175 +
33176 + while (count--) {
33177 + pgd_t pgd;
33178 +
33179 +#ifdef CONFIG_X86_64
33180 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33181 +#else
33182 + pgd = *src++;
33183 +#endif
33184 +
33185 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33186 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33187 +#endif
33188 +
33189 + *dst++ = pgd;
33190 + }
33191 +
33192 +}
33193 +#endif
33194 +
33195 +#ifdef CONFIG_X86_64
33196 +#define pxd_t pud_t
33197 +#define pyd_t pgd_t
33198 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33199 +#define pgtable_pxd_page_ctor(page) true
33200 +#define pgtable_pxd_page_dtor(page)
33201 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33202 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33203 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33204 +#define PYD_SIZE PGDIR_SIZE
33205 +#else
33206 +#define pxd_t pmd_t
33207 +#define pyd_t pud_t
33208 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33209 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33210 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33211 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33212 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33213 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33214 +#define PYD_SIZE PUD_SIZE
33215 +#endif
33216 +
33217 +#ifdef CONFIG_PAX_PER_CPU_PGD
33218 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33219 +static inline void pgd_dtor(pgd_t *pgd) {}
33220 +#else
33221 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33222 {
33223 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33224 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33225 pgd_list_del(pgd);
33226 spin_unlock(&pgd_lock);
33227 }
33228 +#endif
33229
33230 /*
33231 * List of all pgd's needed for non-PAE so it can invalidate entries
33232 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33233 * -- nyc
33234 */
33235
33236 -#ifdef CONFIG_X86_PAE
33237 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33238 /*
33239 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33240 * updating the top-level pagetable entries to guarantee the
33241 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33242 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33243 * and initialize the kernel pmds here.
33244 */
33245 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33246 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33247
33248 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33249 {
33250 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33251 */
33252 flush_tlb_mm(mm);
33253 }
33254 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33255 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33256 #else /* !CONFIG_X86_PAE */
33257
33258 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33259 -#define PREALLOCATED_PMDS 0
33260 +#define PREALLOCATED_PXDS 0
33261
33262 #endif /* CONFIG_X86_PAE */
33263
33264 -static void free_pmds(pmd_t *pmds[])
33265 +static void free_pxds(pxd_t *pxds[])
33266 {
33267 int i;
33268
33269 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33270 - if (pmds[i]) {
33271 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33272 - free_page((unsigned long)pmds[i]);
33273 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33274 + if (pxds[i]) {
33275 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33276 + free_page((unsigned long)pxds[i]);
33277 }
33278 }
33279
33280 -static int preallocate_pmds(pmd_t *pmds[])
33281 +static int preallocate_pxds(pxd_t *pxds[])
33282 {
33283 int i;
33284 bool failed = false;
33285
33286 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33287 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33288 - if (!pmd)
33289 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33290 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33291 + if (!pxd)
33292 failed = true;
33293 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33294 - free_page((unsigned long)pmd);
33295 - pmd = NULL;
33296 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33297 + free_page((unsigned long)pxd);
33298 + pxd = NULL;
33299 failed = true;
33300 }
33301 - pmds[i] = pmd;
33302 + pxds[i] = pxd;
33303 }
33304
33305 if (failed) {
33306 - free_pmds(pmds);
33307 + free_pxds(pxds);
33308 return -ENOMEM;
33309 }
33310
33311 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33312 * preallocate which never got a corresponding vma will need to be
33313 * freed manually.
33314 */
33315 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33316 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33317 {
33318 int i;
33319
33320 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33321 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33322 pgd_t pgd = pgdp[i];
33323
33324 if (pgd_val(pgd) != 0) {
33325 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33326 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33327
33328 - pgdp[i] = native_make_pgd(0);
33329 + set_pgd(pgdp + i, native_make_pgd(0));
33330
33331 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33332 - pmd_free(mm, pmd);
33333 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33334 + pxd_free(mm, pxd);
33335 }
33336 }
33337 }
33338
33339 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33340 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33341 {
33342 - pud_t *pud;
33343 + pyd_t *pyd;
33344 int i;
33345
33346 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33347 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33348 return;
33349
33350 - pud = pud_offset(pgd, 0);
33351 -
33352 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33353 - pmd_t *pmd = pmds[i];
33354 +#ifdef CONFIG_X86_64
33355 + pyd = pyd_offset(mm, 0L);
33356 +#else
33357 + pyd = pyd_offset(pgd, 0L);
33358 +#endif
33359
33360 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33361 + pxd_t *pxd = pxds[i];
33362 if (i >= KERNEL_PGD_BOUNDARY)
33363 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33364 - sizeof(pmd_t) * PTRS_PER_PMD);
33365 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33366 + sizeof(pxd_t) * PTRS_PER_PMD);
33367
33368 - pud_populate(mm, pud, pmd);
33369 + pyd_populate(mm, pyd, pxd);
33370 }
33371 }
33372
33373 pgd_t *pgd_alloc(struct mm_struct *mm)
33374 {
33375 pgd_t *pgd;
33376 - pmd_t *pmds[PREALLOCATED_PMDS];
33377 + pxd_t *pxds[PREALLOCATED_PXDS];
33378
33379 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33380
33381 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33382
33383 mm->pgd = pgd;
33384
33385 - if (preallocate_pmds(pmds) != 0)
33386 + if (preallocate_pxds(pxds) != 0)
33387 goto out_free_pgd;
33388
33389 if (paravirt_pgd_alloc(mm) != 0)
33390 - goto out_free_pmds;
33391 + goto out_free_pxds;
33392
33393 /*
33394 * Make sure that pre-populating the pmds is atomic with
33395 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33396 spin_lock(&pgd_lock);
33397
33398 pgd_ctor(mm, pgd);
33399 - pgd_prepopulate_pmd(mm, pgd, pmds);
33400 + pgd_prepopulate_pxd(mm, pgd, pxds);
33401
33402 spin_unlock(&pgd_lock);
33403
33404 return pgd;
33405
33406 -out_free_pmds:
33407 - free_pmds(pmds);
33408 +out_free_pxds:
33409 + free_pxds(pxds);
33410 out_free_pgd:
33411 free_page((unsigned long)pgd);
33412 out:
33413 @@ -313,7 +380,7 @@ out:
33414
33415 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33416 {
33417 - pgd_mop_up_pmds(mm, pgd);
33418 + pgd_mop_up_pxds(mm, pgd);
33419 pgd_dtor(pgd);
33420 paravirt_pgd_free(mm, pgd);
33421 free_page((unsigned long)pgd);
33422 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33423 index a69bcb8..19068ab 100644
33424 --- a/arch/x86/mm/pgtable_32.c
33425 +++ b/arch/x86/mm/pgtable_32.c
33426 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33427 return;
33428 }
33429 pte = pte_offset_kernel(pmd, vaddr);
33430 +
33431 + pax_open_kernel();
33432 if (pte_val(pteval))
33433 set_pte_at(&init_mm, vaddr, pte, pteval);
33434 else
33435 pte_clear(&init_mm, vaddr, pte);
33436 + pax_close_kernel();
33437
33438 /*
33439 * It's enough to flush this one mapping.
33440 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33441 index e666cbb..61788c45 100644
33442 --- a/arch/x86/mm/physaddr.c
33443 +++ b/arch/x86/mm/physaddr.c
33444 @@ -10,7 +10,7 @@
33445 #ifdef CONFIG_X86_64
33446
33447 #ifdef CONFIG_DEBUG_VIRTUAL
33448 -unsigned long __phys_addr(unsigned long x)
33449 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33450 {
33451 unsigned long y = x - __START_KERNEL_map;
33452
33453 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33454 #else
33455
33456 #ifdef CONFIG_DEBUG_VIRTUAL
33457 -unsigned long __phys_addr(unsigned long x)
33458 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33459 {
33460 unsigned long phys_addr = x - PAGE_OFFSET;
33461 /* VMALLOC_* aren't constants */
33462 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33463 index 90555bf..f5f1828 100644
33464 --- a/arch/x86/mm/setup_nx.c
33465 +++ b/arch/x86/mm/setup_nx.c
33466 @@ -5,8 +5,10 @@
33467 #include <asm/pgtable.h>
33468 #include <asm/proto.h>
33469
33470 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33471 static int disable_nx;
33472
33473 +#ifndef CONFIG_PAX_PAGEEXEC
33474 /*
33475 * noexec = on|off
33476 *
33477 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33478 return 0;
33479 }
33480 early_param("noexec", noexec_setup);
33481 +#endif
33482 +
33483 +#endif
33484
33485 void x86_configure_nx(void)
33486 {
33487 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33488 if (cpu_has_nx && !disable_nx)
33489 __supported_pte_mask |= _PAGE_NX;
33490 else
33491 +#endif
33492 __supported_pte_mask &= ~_PAGE_NX;
33493 }
33494
33495 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33496 index ae699b3..f1b2ad2 100644
33497 --- a/arch/x86/mm/tlb.c
33498 +++ b/arch/x86/mm/tlb.c
33499 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33500 BUG();
33501 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33502 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33503 +
33504 +#ifndef CONFIG_PAX_PER_CPU_PGD
33505 load_cr3(swapper_pg_dir);
33506 +#endif
33507 +
33508 }
33509 }
33510 EXPORT_SYMBOL_GPL(leave_mm);
33511 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33512 new file mode 100644
33513 index 0000000..dace51c
33514 --- /dev/null
33515 +++ b/arch/x86/mm/uderef_64.c
33516 @@ -0,0 +1,37 @@
33517 +#include <linux/mm.h>
33518 +#include <asm/pgtable.h>
33519 +#include <asm/uaccess.h>
33520 +
33521 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33522 +/* PaX: due to the special call convention these functions must
33523 + * - remain leaf functions under all configurations,
33524 + * - never be called directly, only dereferenced from the wrappers.
33525 + */
33526 +void __pax_open_userland(void)
33527 +{
33528 + unsigned int cpu;
33529 +
33530 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33531 + return;
33532 +
33533 + cpu = raw_get_cpu();
33534 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33535 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33536 + raw_put_cpu_no_resched();
33537 +}
33538 +EXPORT_SYMBOL(__pax_open_userland);
33539 +
33540 +void __pax_close_userland(void)
33541 +{
33542 + unsigned int cpu;
33543 +
33544 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33545 + return;
33546 +
33547 + cpu = raw_get_cpu();
33548 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33549 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33550 + raw_put_cpu_no_resched();
33551 +}
33552 +EXPORT_SYMBOL(__pax_close_userland);
33553 +#endif
33554 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33555 index 0149575..f746de8 100644
33556 --- a/arch/x86/net/bpf_jit.S
33557 +++ b/arch/x86/net/bpf_jit.S
33558 @@ -9,6 +9,7 @@
33559 */
33560 #include <linux/linkage.h>
33561 #include <asm/dwarf2.h>
33562 +#include <asm/alternative-asm.h>
33563
33564 /*
33565 * Calling convention :
33566 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33567 jle bpf_slow_path_word
33568 mov (SKBDATA,%rsi),%eax
33569 bswap %eax /* ntohl() */
33570 + pax_force_retaddr
33571 ret
33572
33573 sk_load_half:
33574 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33575 jle bpf_slow_path_half
33576 movzwl (SKBDATA,%rsi),%eax
33577 rol $8,%ax # ntohs()
33578 + pax_force_retaddr
33579 ret
33580
33581 sk_load_byte:
33582 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33583 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33584 jle bpf_slow_path_byte
33585 movzbl (SKBDATA,%rsi),%eax
33586 + pax_force_retaddr
33587 ret
33588
33589 /**
33590 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33591 movzbl (SKBDATA,%rsi),%ebx
33592 and $15,%bl
33593 shl $2,%bl
33594 + pax_force_retaddr
33595 ret
33596
33597 /* rsi contains offset and can be scratched */
33598 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33599 js bpf_error
33600 mov -12(%rbp),%eax
33601 bswap %eax
33602 + pax_force_retaddr
33603 ret
33604
33605 bpf_slow_path_half:
33606 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33607 mov -12(%rbp),%ax
33608 rol $8,%ax
33609 movzwl %ax,%eax
33610 + pax_force_retaddr
33611 ret
33612
33613 bpf_slow_path_byte:
33614 bpf_slow_path_common(1)
33615 js bpf_error
33616 movzbl -12(%rbp),%eax
33617 + pax_force_retaddr
33618 ret
33619
33620 bpf_slow_path_byte_msh:
33621 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33622 and $15,%al
33623 shl $2,%al
33624 xchg %eax,%ebx
33625 + pax_force_retaddr
33626 ret
33627
33628 #define sk_negative_common(SIZE) \
33629 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33630 sk_negative_common(4)
33631 mov (%rax), %eax
33632 bswap %eax
33633 + pax_force_retaddr
33634 ret
33635
33636 bpf_slow_path_half_neg:
33637 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33638 mov (%rax),%ax
33639 rol $8,%ax
33640 movzwl %ax,%eax
33641 + pax_force_retaddr
33642 ret
33643
33644 bpf_slow_path_byte_neg:
33645 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33646 .globl sk_load_byte_negative_offset
33647 sk_negative_common(1)
33648 movzbl (%rax), %eax
33649 + pax_force_retaddr
33650 ret
33651
33652 bpf_slow_path_byte_msh_neg:
33653 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33654 and $15,%al
33655 shl $2,%al
33656 xchg %eax,%ebx
33657 + pax_force_retaddr
33658 ret
33659
33660 bpf_error:
33661 @@ -197,4 +210,5 @@ bpf_error:
33662 xor %eax,%eax
33663 mov -8(%rbp),%rbx
33664 leaveq
33665 + pax_force_retaddr
33666 ret
33667 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33668 index 4ed75dd..3cf24f0b 100644
33669 --- a/arch/x86/net/bpf_jit_comp.c
33670 +++ b/arch/x86/net/bpf_jit_comp.c
33671 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33672 return ptr + len;
33673 }
33674
33675 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33676 +#define MAX_INSTR_CODE_SIZE 96
33677 +#else
33678 +#define MAX_INSTR_CODE_SIZE 64
33679 +#endif
33680 +
33681 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33682
33683 #define EMIT1(b1) EMIT(b1, 1)
33684 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33685 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33686 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33687 +
33688 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33689 +/* original constant will appear in ecx */
33690 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33691 +do { \
33692 + /* mov ecx, randkey */ \
33693 + EMIT1(0xb9); \
33694 + EMIT(_key, 4); \
33695 + /* xor ecx, randkey ^ off */ \
33696 + EMIT2(0x81, 0xf1); \
33697 + EMIT((_key) ^ (_off), 4); \
33698 +} while (0)
33699 +
33700 +#define EMIT1_off32(b1, _off) \
33701 +do { \
33702 + switch (b1) { \
33703 + case 0x05: /* add eax, imm32 */ \
33704 + case 0x2d: /* sub eax, imm32 */ \
33705 + case 0x25: /* and eax, imm32 */ \
33706 + case 0x0d: /* or eax, imm32 */ \
33707 + case 0xb8: /* mov eax, imm32 */ \
33708 + case 0x35: /* xor eax, imm32 */ \
33709 + case 0x3d: /* cmp eax, imm32 */ \
33710 + case 0xa9: /* test eax, imm32 */ \
33711 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33712 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33713 + break; \
33714 + case 0xbb: /* mov ebx, imm32 */ \
33715 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33716 + /* mov ebx, ecx */ \
33717 + EMIT2(0x89, 0xcb); \
33718 + break; \
33719 + case 0xbe: /* mov esi, imm32 */ \
33720 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33721 + /* mov esi, ecx */ \
33722 + EMIT2(0x89, 0xce); \
33723 + break; \
33724 + case 0xe8: /* call rel imm32, always to known funcs */ \
33725 + EMIT1(b1); \
33726 + EMIT(_off, 4); \
33727 + break; \
33728 + case 0xe9: /* jmp rel imm32 */ \
33729 + EMIT1(b1); \
33730 + EMIT(_off, 4); \
33731 + /* prevent fall-through, we're not called if off = 0 */ \
33732 + EMIT(0xcccccccc, 4); \
33733 + EMIT(0xcccccccc, 4); \
33734 + break; \
33735 + default: \
33736 + BUILD_BUG(); \
33737 + } \
33738 +} while (0)
33739 +
33740 +#define EMIT2_off32(b1, b2, _off) \
33741 +do { \
33742 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33743 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33744 + EMIT(randkey, 4); \
33745 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33746 + EMIT((_off) - randkey, 4); \
33747 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33748 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33749 + /* imul eax, ecx */ \
33750 + EMIT3(0x0f, 0xaf, 0xc1); \
33751 + } else { \
33752 + BUILD_BUG(); \
33753 + } \
33754 +} while (0)
33755 +#else
33756 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33757 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33758 +#endif
33759
33760 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33761 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33762 @@ -91,6 +168,24 @@ do { \
33763 #define X86_JBE 0x76
33764 #define X86_JA 0x77
33765
33766 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33767 +#define APPEND_FLOW_VERIFY() \
33768 +do { \
33769 + /* mov ecx, randkey */ \
33770 + EMIT1(0xb9); \
33771 + EMIT(randkey, 4); \
33772 + /* cmp ecx, randkey */ \
33773 + EMIT2(0x81, 0xf9); \
33774 + EMIT(randkey, 4); \
33775 + /* jz after 8 int 3s */ \
33776 + EMIT2(0x74, 0x08); \
33777 + EMIT(0xcccccccc, 4); \
33778 + EMIT(0xcccccccc, 4); \
33779 +} while (0)
33780 +#else
33781 +#define APPEND_FLOW_VERIFY() do { } while (0)
33782 +#endif
33783 +
33784 #define EMIT_COND_JMP(op, offset) \
33785 do { \
33786 if (is_near(offset)) \
33787 @@ -98,6 +193,7 @@ do { \
33788 else { \
33789 EMIT2(0x0f, op + 0x10); \
33790 EMIT(offset, 4); /* jxx .+off32 */ \
33791 + APPEND_FLOW_VERIFY(); \
33792 } \
33793 } while (0)
33794
33795 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33796 return -1;
33797 }
33798
33799 -struct bpf_binary_header {
33800 - unsigned int pages;
33801 - /* Note : for security reasons, bpf code will follow a randomly
33802 - * sized amount of int3 instructions
33803 - */
33804 - u8 image[];
33805 -};
33806 -
33807 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33808 +/* Note : for security reasons, bpf code will follow a randomly
33809 + * sized amount of int3 instructions
33810 + */
33811 +static u8 *bpf_alloc_binary(unsigned int proglen,
33812 u8 **image_ptr)
33813 {
33814 unsigned int sz, hole;
33815 - struct bpf_binary_header *header;
33816 + u8 *header;
33817
33818 /* Most of BPF filters are really small,
33819 * but if some of them fill a page, allow at least
33820 * 128 extra bytes to insert a random section of int3
33821 */
33822 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33823 - header = module_alloc(sz);
33824 + sz = round_up(proglen + 128, PAGE_SIZE);
33825 + header = module_alloc_exec(sz);
33826 if (!header)
33827 return NULL;
33828
33829 + pax_open_kernel();
33830 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33831 + pax_close_kernel();
33832
33833 - header->pages = sz / PAGE_SIZE;
33834 - hole = sz - (proglen + sizeof(*header));
33835 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33836
33837 /* insert a random number of int3 instructions before BPF code */
33838 - *image_ptr = &header->image[prandom_u32() % hole];
33839 + *image_ptr = &header[prandom_u32() % hole];
33840 return header;
33841 }
33842
33843 void bpf_jit_compile(struct sk_filter *fp)
33844 {
33845 - u8 temp[64];
33846 + u8 temp[MAX_INSTR_CODE_SIZE];
33847 u8 *prog;
33848 unsigned int proglen, oldproglen = 0;
33849 int ilen, i;
33850 int t_offset, f_offset;
33851 u8 t_op, f_op, seen = 0, pass;
33852 u8 *image = NULL;
33853 - struct bpf_binary_header *header = NULL;
33854 + u8 *header = NULL;
33855 u8 *func;
33856 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33857 unsigned int cleanup_addr; /* epilogue code offset */
33858 unsigned int *addrs;
33859 const struct sock_filter *filter = fp->insns;
33860 int flen = fp->len;
33861 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33862 + unsigned int randkey;
33863 +#endif
33864
33865 if (!bpf_jit_enable)
33866 return;
33867 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33868 return;
33869
33870 /* Before first pass, make a rough estimation of addrs[]
33871 - * each bpf instruction is translated to less than 64 bytes
33872 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33873 */
33874 for (proglen = 0, i = 0; i < flen; i++) {
33875 - proglen += 64;
33876 + proglen += MAX_INSTR_CODE_SIZE;
33877 addrs[i] = proglen;
33878 }
33879 cleanup_addr = proglen; /* epilogue address */
33880 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33881 for (i = 0; i < flen; i++) {
33882 unsigned int K = filter[i].k;
33883
33884 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33885 + randkey = prandom_u32();
33886 +#endif
33887 +
33888 switch (filter[i].code) {
33889 case BPF_S_ALU_ADD_X: /* A += X; */
33890 seen |= SEEN_XREG;
33891 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33892 case BPF_S_ALU_MUL_K: /* A *= K */
33893 if (is_imm8(K))
33894 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33895 - else {
33896 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33897 - EMIT(K, 4);
33898 - }
33899 + else
33900 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33901 break;
33902 case BPF_S_ALU_DIV_X: /* A /= X; */
33903 seen |= SEEN_XREG;
33904 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33905 break;
33906 }
33907 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33908 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33909 + DILUTE_CONST_SEQUENCE(K, randkey);
33910 +#else
33911 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33912 +#endif
33913 EMIT2(0xf7, 0xf1); /* div %ecx */
33914 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33915 break;
33916 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33917 if (K == 1)
33918 break;
33919 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33920 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33921 + DILUTE_CONST_SEQUENCE(K, randkey);
33922 +#else
33923 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33924 +#endif
33925 EMIT2(0xf7, 0xf1); /* div %ecx */
33926 break;
33927 case BPF_S_ALU_AND_X:
33928 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33929 if (is_imm8(K)) {
33930 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33931 } else {
33932 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33933 - EMIT(K, 4);
33934 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33935 }
33936 } else {
33937 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33938 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33939 if (unlikely(proglen + ilen > oldproglen)) {
33940 pr_err("bpb_jit_compile fatal error\n");
33941 kfree(addrs);
33942 - module_free(NULL, header);
33943 + module_free_exec(NULL, image);
33944 return;
33945 }
33946 + pax_open_kernel();
33947 memcpy(image + proglen, temp, ilen);
33948 + pax_close_kernel();
33949 }
33950 proglen += ilen;
33951 addrs[i] = proglen;
33952 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33953
33954 if (image) {
33955 bpf_flush_icache(header, image + proglen);
33956 - set_memory_ro((unsigned long)header, header->pages);
33957 fp->bpf_func = (void *)image;
33958 }
33959 out:
33960 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33961 {
33962 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33963 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33964 - struct bpf_binary_header *header = (void *)addr;
33965
33966 - set_memory_rw(addr, header->pages);
33967 - module_free(NULL, header);
33968 + set_memory_rw(addr, 1);
33969 + module_free_exec(NULL, (void *)addr);
33970 kfree(fp);
33971 }
33972
33973 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33974 index 5d04be5..2beeaa2 100644
33975 --- a/arch/x86/oprofile/backtrace.c
33976 +++ b/arch/x86/oprofile/backtrace.c
33977 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33978 struct stack_frame_ia32 *fp;
33979 unsigned long bytes;
33980
33981 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33982 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33983 if (bytes != 0)
33984 return NULL;
33985
33986 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33987 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33988
33989 oprofile_add_trace(bufhead[0].return_address);
33990
33991 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33992 struct stack_frame bufhead[2];
33993 unsigned long bytes;
33994
33995 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33996 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33997 if (bytes != 0)
33998 return NULL;
33999
34000 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34001 {
34002 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34003
34004 - if (!user_mode_vm(regs)) {
34005 + if (!user_mode(regs)) {
34006 unsigned long stack = kernel_stack_pointer(regs);
34007 if (depth)
34008 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34009 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34010 index 6890d84..1dad1f1 100644
34011 --- a/arch/x86/oprofile/nmi_int.c
34012 +++ b/arch/x86/oprofile/nmi_int.c
34013 @@ -23,6 +23,7 @@
34014 #include <asm/nmi.h>
34015 #include <asm/msr.h>
34016 #include <asm/apic.h>
34017 +#include <asm/pgtable.h>
34018
34019 #include "op_counter.h"
34020 #include "op_x86_model.h"
34021 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34022 if (ret)
34023 return ret;
34024
34025 - if (!model->num_virt_counters)
34026 - model->num_virt_counters = model->num_counters;
34027 + if (!model->num_virt_counters) {
34028 + pax_open_kernel();
34029 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34030 + pax_close_kernel();
34031 + }
34032
34033 mux_init(ops);
34034
34035 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34036 index 50d86c0..7985318 100644
34037 --- a/arch/x86/oprofile/op_model_amd.c
34038 +++ b/arch/x86/oprofile/op_model_amd.c
34039 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34040 num_counters = AMD64_NUM_COUNTERS;
34041 }
34042
34043 - op_amd_spec.num_counters = num_counters;
34044 - op_amd_spec.num_controls = num_counters;
34045 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34046 + pax_open_kernel();
34047 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34048 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34049 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34050 + pax_close_kernel();
34051
34052 return 0;
34053 }
34054 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34055 index d90528e..0127e2b 100644
34056 --- a/arch/x86/oprofile/op_model_ppro.c
34057 +++ b/arch/x86/oprofile/op_model_ppro.c
34058 @@ -19,6 +19,7 @@
34059 #include <asm/msr.h>
34060 #include <asm/apic.h>
34061 #include <asm/nmi.h>
34062 +#include <asm/pgtable.h>
34063
34064 #include "op_x86_model.h"
34065 #include "op_counter.h"
34066 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34067
34068 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34069
34070 - op_arch_perfmon_spec.num_counters = num_counters;
34071 - op_arch_perfmon_spec.num_controls = num_counters;
34072 + pax_open_kernel();
34073 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34074 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34075 + pax_close_kernel();
34076 }
34077
34078 static int arch_perfmon_init(struct oprofile_operations *ignore)
34079 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34080 index 71e8a67..6a313bb 100644
34081 --- a/arch/x86/oprofile/op_x86_model.h
34082 +++ b/arch/x86/oprofile/op_x86_model.h
34083 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34084 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34085 struct op_msrs const * const msrs);
34086 #endif
34087 -};
34088 +} __do_const;
34089
34090 struct op_counter_config;
34091
34092 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34093 index 51384ca..a25f51e 100644
34094 --- a/arch/x86/pci/intel_mid_pci.c
34095 +++ b/arch/x86/pci/intel_mid_pci.c
34096 @@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
34097 pr_info("Intel MID platform detected, using MID PCI ops\n");
34098 pci_mmcfg_late_init();
34099 pcibios_enable_irq = intel_mid_pci_irq_enable;
34100 - pci_root_ops = intel_mid_pci_ops;
34101 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34102 pci_soc_mode = 1;
34103 /* Continue with standard init */
34104 return 1;
34105 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34106 index 372e9b8..e775a6c 100644
34107 --- a/arch/x86/pci/irq.c
34108 +++ b/arch/x86/pci/irq.c
34109 @@ -50,7 +50,7 @@ struct irq_router {
34110 struct irq_router_handler {
34111 u16 vendor;
34112 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34113 -};
34114 +} __do_const;
34115
34116 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34117 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34118 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34119 return 0;
34120 }
34121
34122 -static __initdata struct irq_router_handler pirq_routers[] = {
34123 +static __initconst const struct irq_router_handler pirq_routers[] = {
34124 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34125 { PCI_VENDOR_ID_AL, ali_router_probe },
34126 { PCI_VENDOR_ID_ITE, ite_router_probe },
34127 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34128 static void __init pirq_find_router(struct irq_router *r)
34129 {
34130 struct irq_routing_table *rt = pirq_table;
34131 - struct irq_router_handler *h;
34132 + const struct irq_router_handler *h;
34133
34134 #ifdef CONFIG_PCI_BIOS
34135 if (!rt->signature) {
34136 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34137 return 0;
34138 }
34139
34140 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34141 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34142 {
34143 .callback = fix_broken_hp_bios_irq9,
34144 .ident = "HP Pavilion N5400 Series Laptop",
34145 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34146 index c77b24a..c979855 100644
34147 --- a/arch/x86/pci/pcbios.c
34148 +++ b/arch/x86/pci/pcbios.c
34149 @@ -79,7 +79,7 @@ union bios32 {
34150 static struct {
34151 unsigned long address;
34152 unsigned short segment;
34153 -} bios32_indirect = { 0, __KERNEL_CS };
34154 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34155
34156 /*
34157 * Returns the entry point for the given service, NULL on error
34158 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34159 unsigned long length; /* %ecx */
34160 unsigned long entry; /* %edx */
34161 unsigned long flags;
34162 + struct desc_struct d, *gdt;
34163
34164 local_irq_save(flags);
34165 - __asm__("lcall *(%%edi); cld"
34166 +
34167 + gdt = get_cpu_gdt_table(smp_processor_id());
34168 +
34169 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34170 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34171 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34172 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34173 +
34174 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34175 : "=a" (return_code),
34176 "=b" (address),
34177 "=c" (length),
34178 "=d" (entry)
34179 : "0" (service),
34180 "1" (0),
34181 - "D" (&bios32_indirect));
34182 + "D" (&bios32_indirect),
34183 + "r"(__PCIBIOS_DS)
34184 + : "memory");
34185 +
34186 + pax_open_kernel();
34187 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34188 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34189 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34190 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34191 + pax_close_kernel();
34192 +
34193 local_irq_restore(flags);
34194
34195 switch (return_code) {
34196 - case 0:
34197 - return address + entry;
34198 - case 0x80: /* Not present */
34199 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34200 - return 0;
34201 - default: /* Shouldn't happen */
34202 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34203 - service, return_code);
34204 + case 0: {
34205 + int cpu;
34206 + unsigned char flags;
34207 +
34208 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34209 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34210 + printk(KERN_WARNING "bios32_service: not valid\n");
34211 return 0;
34212 + }
34213 + address = address + PAGE_OFFSET;
34214 + length += 16UL; /* some BIOSs underreport this... */
34215 + flags = 4;
34216 + if (length >= 64*1024*1024) {
34217 + length >>= PAGE_SHIFT;
34218 + flags |= 8;
34219 + }
34220 +
34221 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34222 + gdt = get_cpu_gdt_table(cpu);
34223 + pack_descriptor(&d, address, length, 0x9b, flags);
34224 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34225 + pack_descriptor(&d, address, length, 0x93, flags);
34226 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34227 + }
34228 + return entry;
34229 + }
34230 + case 0x80: /* Not present */
34231 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34232 + return 0;
34233 + default: /* Shouldn't happen */
34234 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34235 + service, return_code);
34236 + return 0;
34237 }
34238 }
34239
34240 static struct {
34241 unsigned long address;
34242 unsigned short segment;
34243 -} pci_indirect = { 0, __KERNEL_CS };
34244 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34245
34246 -static int pci_bios_present;
34247 +static int pci_bios_present __read_only;
34248
34249 static int check_pcibios(void)
34250 {
34251 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34252 unsigned long flags, pcibios_entry;
34253
34254 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34255 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34256 + pci_indirect.address = pcibios_entry;
34257
34258 local_irq_save(flags);
34259 - __asm__(
34260 - "lcall *(%%edi); cld\n\t"
34261 + __asm__("movw %w6, %%ds\n\t"
34262 + "lcall *%%ss:(%%edi); cld\n\t"
34263 + "push %%ss\n\t"
34264 + "pop %%ds\n\t"
34265 "jc 1f\n\t"
34266 "xor %%ah, %%ah\n"
34267 "1:"
34268 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34269 "=b" (ebx),
34270 "=c" (ecx)
34271 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34272 - "D" (&pci_indirect)
34273 + "D" (&pci_indirect),
34274 + "r" (__PCIBIOS_DS)
34275 : "memory");
34276 local_irq_restore(flags);
34277
34278 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34279
34280 switch (len) {
34281 case 1:
34282 - __asm__("lcall *(%%esi); cld\n\t"
34283 + __asm__("movw %w6, %%ds\n\t"
34284 + "lcall *%%ss:(%%esi); cld\n\t"
34285 + "push %%ss\n\t"
34286 + "pop %%ds\n\t"
34287 "jc 1f\n\t"
34288 "xor %%ah, %%ah\n"
34289 "1:"
34290 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34291 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34292 "b" (bx),
34293 "D" ((long)reg),
34294 - "S" (&pci_indirect));
34295 + "S" (&pci_indirect),
34296 + "r" (__PCIBIOS_DS));
34297 /*
34298 * Zero-extend the result beyond 8 bits, do not trust the
34299 * BIOS having done it:
34300 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34301 *value &= 0xff;
34302 break;
34303 case 2:
34304 - __asm__("lcall *(%%esi); cld\n\t"
34305 + __asm__("movw %w6, %%ds\n\t"
34306 + "lcall *%%ss:(%%esi); cld\n\t"
34307 + "push %%ss\n\t"
34308 + "pop %%ds\n\t"
34309 "jc 1f\n\t"
34310 "xor %%ah, %%ah\n"
34311 "1:"
34312 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34313 : "1" (PCIBIOS_READ_CONFIG_WORD),
34314 "b" (bx),
34315 "D" ((long)reg),
34316 - "S" (&pci_indirect));
34317 + "S" (&pci_indirect),
34318 + "r" (__PCIBIOS_DS));
34319 /*
34320 * Zero-extend the result beyond 16 bits, do not trust the
34321 * BIOS having done it:
34322 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34323 *value &= 0xffff;
34324 break;
34325 case 4:
34326 - __asm__("lcall *(%%esi); cld\n\t"
34327 + __asm__("movw %w6, %%ds\n\t"
34328 + "lcall *%%ss:(%%esi); cld\n\t"
34329 + "push %%ss\n\t"
34330 + "pop %%ds\n\t"
34331 "jc 1f\n\t"
34332 "xor %%ah, %%ah\n"
34333 "1:"
34334 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34335 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34336 "b" (bx),
34337 "D" ((long)reg),
34338 - "S" (&pci_indirect));
34339 + "S" (&pci_indirect),
34340 + "r" (__PCIBIOS_DS));
34341 break;
34342 }
34343
34344 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34345
34346 switch (len) {
34347 case 1:
34348 - __asm__("lcall *(%%esi); cld\n\t"
34349 + __asm__("movw %w6, %%ds\n\t"
34350 + "lcall *%%ss:(%%esi); cld\n\t"
34351 + "push %%ss\n\t"
34352 + "pop %%ds\n\t"
34353 "jc 1f\n\t"
34354 "xor %%ah, %%ah\n"
34355 "1:"
34356 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34357 "c" (value),
34358 "b" (bx),
34359 "D" ((long)reg),
34360 - "S" (&pci_indirect));
34361 + "S" (&pci_indirect),
34362 + "r" (__PCIBIOS_DS));
34363 break;
34364 case 2:
34365 - __asm__("lcall *(%%esi); cld\n\t"
34366 + __asm__("movw %w6, %%ds\n\t"
34367 + "lcall *%%ss:(%%esi); cld\n\t"
34368 + "push %%ss\n\t"
34369 + "pop %%ds\n\t"
34370 "jc 1f\n\t"
34371 "xor %%ah, %%ah\n"
34372 "1:"
34373 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34374 "c" (value),
34375 "b" (bx),
34376 "D" ((long)reg),
34377 - "S" (&pci_indirect));
34378 + "S" (&pci_indirect),
34379 + "r" (__PCIBIOS_DS));
34380 break;
34381 case 4:
34382 - __asm__("lcall *(%%esi); cld\n\t"
34383 + __asm__("movw %w6, %%ds\n\t"
34384 + "lcall *%%ss:(%%esi); cld\n\t"
34385 + "push %%ss\n\t"
34386 + "pop %%ds\n\t"
34387 "jc 1f\n\t"
34388 "xor %%ah, %%ah\n"
34389 "1:"
34390 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34391 "c" (value),
34392 "b" (bx),
34393 "D" ((long)reg),
34394 - "S" (&pci_indirect));
34395 + "S" (&pci_indirect),
34396 + "r" (__PCIBIOS_DS));
34397 break;
34398 }
34399
34400 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34401
34402 DBG("PCI: Fetching IRQ routing table... ");
34403 __asm__("push %%es\n\t"
34404 + "movw %w8, %%ds\n\t"
34405 "push %%ds\n\t"
34406 "pop %%es\n\t"
34407 - "lcall *(%%esi); cld\n\t"
34408 + "lcall *%%ss:(%%esi); cld\n\t"
34409 "pop %%es\n\t"
34410 + "push %%ss\n\t"
34411 + "pop %%ds\n"
34412 "jc 1f\n\t"
34413 "xor %%ah, %%ah\n"
34414 "1:"
34415 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34416 "1" (0),
34417 "D" ((long) &opt),
34418 "S" (&pci_indirect),
34419 - "m" (opt)
34420 + "m" (opt),
34421 + "r" (__PCIBIOS_DS)
34422 : "memory");
34423 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34424 if (ret & 0xff00)
34425 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34426 {
34427 int ret;
34428
34429 - __asm__("lcall *(%%esi); cld\n\t"
34430 + __asm__("movw %w5, %%ds\n\t"
34431 + "lcall *%%ss:(%%esi); cld\n\t"
34432 + "push %%ss\n\t"
34433 + "pop %%ds\n"
34434 "jc 1f\n\t"
34435 "xor %%ah, %%ah\n"
34436 "1:"
34437 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34438 : "0" (PCIBIOS_SET_PCI_HW_INT),
34439 "b" ((dev->bus->number << 8) | dev->devfn),
34440 "c" ((irq << 8) | (pin + 10)),
34441 - "S" (&pci_indirect));
34442 + "S" (&pci_indirect),
34443 + "r" (__PCIBIOS_DS));
34444 return !(ret & 0xff00);
34445 }
34446 EXPORT_SYMBOL(pcibios_set_irq_routing);
34447 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34448 index 40e4469..d915bf9 100644
34449 --- a/arch/x86/platform/efi/efi_32.c
34450 +++ b/arch/x86/platform/efi/efi_32.c
34451 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
34452 {
34453 struct desc_ptr gdt_descr;
34454
34455 +#ifdef CONFIG_PAX_KERNEXEC
34456 + struct desc_struct d;
34457 +#endif
34458 +
34459 local_irq_save(efi_rt_eflags);
34460
34461 load_cr3(initial_page_table);
34462 __flush_tlb_all();
34463
34464 +#ifdef CONFIG_PAX_KERNEXEC
34465 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34466 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34467 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34468 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34469 +#endif
34470 +
34471 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34472 gdt_descr.size = GDT_SIZE - 1;
34473 load_gdt(&gdt_descr);
34474 @@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
34475 {
34476 struct desc_ptr gdt_descr;
34477
34478 +#ifdef CONFIG_PAX_KERNEXEC
34479 + struct desc_struct d;
34480 +
34481 + memset(&d, 0, sizeof d);
34482 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34483 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34484 +#endif
34485 +
34486 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34487 gdt_descr.size = GDT_SIZE - 1;
34488 load_gdt(&gdt_descr);
34489
34490 +#ifdef CONFIG_PAX_PER_CPU_PGD
34491 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34492 +#else
34493 load_cr3(swapper_pg_dir);
34494 +#endif
34495 +
34496 __flush_tlb_all();
34497
34498 local_irq_restore(efi_rt_eflags);
34499 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34500 index 39a0e7f1..872396e 100644
34501 --- a/arch/x86/platform/efi/efi_64.c
34502 +++ b/arch/x86/platform/efi/efi_64.c
34503 @@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
34504 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34505 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34506 }
34507 +
34508 +#ifdef CONFIG_PAX_PER_CPU_PGD
34509 + load_cr3(swapper_pg_dir);
34510 +#endif
34511 +
34512 __flush_tlb_all();
34513 }
34514
34515 @@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
34516 for (pgd = 0; pgd < n_pgds; pgd++)
34517 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34518 kfree(save_pgd);
34519 +
34520 +#ifdef CONFIG_PAX_PER_CPU_PGD
34521 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34522 +#endif
34523 +
34524 __flush_tlb_all();
34525 local_irq_restore(efi_flags);
34526 early_code_mapping_set_exec(0);
34527 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34528 index fbe66e6..eae5e38 100644
34529 --- a/arch/x86/platform/efi/efi_stub_32.S
34530 +++ b/arch/x86/platform/efi/efi_stub_32.S
34531 @@ -6,7 +6,9 @@
34532 */
34533
34534 #include <linux/linkage.h>
34535 +#include <linux/init.h>
34536 #include <asm/page_types.h>
34537 +#include <asm/segment.h>
34538
34539 /*
34540 * efi_call_phys(void *, ...) is a function with variable parameters.
34541 @@ -20,7 +22,7 @@
34542 * service functions will comply with gcc calling convention, too.
34543 */
34544
34545 -.text
34546 +__INIT
34547 ENTRY(efi_call_phys)
34548 /*
34549 * 0. The function can only be called in Linux kernel. So CS has been
34550 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34551 * The mapping of lower virtual memory has been created in prelog and
34552 * epilog.
34553 */
34554 - movl $1f, %edx
34555 - subl $__PAGE_OFFSET, %edx
34556 - jmp *%edx
34557 +#ifdef CONFIG_PAX_KERNEXEC
34558 + movl $(__KERNEXEC_EFI_DS), %edx
34559 + mov %edx, %ds
34560 + mov %edx, %es
34561 + mov %edx, %ss
34562 + addl $2f,(1f)
34563 + ljmp *(1f)
34564 +
34565 +__INITDATA
34566 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34567 +.previous
34568 +
34569 +2:
34570 + subl $2b,(1b)
34571 +#else
34572 + jmp 1f-__PAGE_OFFSET
34573 1:
34574 +#endif
34575
34576 /*
34577 * 2. Now on the top of stack is the return
34578 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34579 * parameter 2, ..., param n. To make things easy, we save the return
34580 * address of efi_call_phys in a global variable.
34581 */
34582 - popl %edx
34583 - movl %edx, saved_return_addr
34584 - /* get the function pointer into ECX*/
34585 - popl %ecx
34586 - movl %ecx, efi_rt_function_ptr
34587 - movl $2f, %edx
34588 - subl $__PAGE_OFFSET, %edx
34589 - pushl %edx
34590 + popl (saved_return_addr)
34591 + popl (efi_rt_function_ptr)
34592
34593 /*
34594 * 3. Clear PG bit in %CR0.
34595 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34596 /*
34597 * 5. Call the physical function.
34598 */
34599 - jmp *%ecx
34600 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34601
34602 -2:
34603 /*
34604 * 6. After EFI runtime service returns, control will return to
34605 * following instruction. We'd better readjust stack pointer first.
34606 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34607 movl %cr0, %edx
34608 orl $0x80000000, %edx
34609 movl %edx, %cr0
34610 - jmp 1f
34611 -1:
34612 +
34613 /*
34614 * 8. Now restore the virtual mode from flat mode by
34615 * adding EIP with PAGE_OFFSET.
34616 */
34617 - movl $1f, %edx
34618 - jmp *%edx
34619 +#ifdef CONFIG_PAX_KERNEXEC
34620 + movl $(__KERNEL_DS), %edx
34621 + mov %edx, %ds
34622 + mov %edx, %es
34623 + mov %edx, %ss
34624 + ljmp $(__KERNEL_CS),$1f
34625 +#else
34626 + jmp 1f+__PAGE_OFFSET
34627 +#endif
34628 1:
34629
34630 /*
34631 * 9. Balance the stack. And because EAX contain the return value,
34632 * we'd better not clobber it.
34633 */
34634 - leal efi_rt_function_ptr, %edx
34635 - movl (%edx), %ecx
34636 - pushl %ecx
34637 + pushl (efi_rt_function_ptr)
34638
34639 /*
34640 - * 10. Push the saved return address onto the stack and return.
34641 + * 10. Return to the saved return address.
34642 */
34643 - leal saved_return_addr, %edx
34644 - movl (%edx), %ecx
34645 - pushl %ecx
34646 - ret
34647 + jmpl *(saved_return_addr)
34648 ENDPROC(efi_call_phys)
34649 .previous
34650
34651 -.data
34652 +__INITDATA
34653 saved_return_addr:
34654 .long 0
34655 efi_rt_function_ptr:
34656 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34657 index 4c07cca..2c8427d 100644
34658 --- a/arch/x86/platform/efi/efi_stub_64.S
34659 +++ b/arch/x86/platform/efi/efi_stub_64.S
34660 @@ -7,6 +7,7 @@
34661 */
34662
34663 #include <linux/linkage.h>
34664 +#include <asm/alternative-asm.h>
34665
34666 #define SAVE_XMM \
34667 mov %rsp, %rax; \
34668 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
34669 call *%rdi
34670 addq $32, %rsp
34671 RESTORE_XMM
34672 + pax_force_retaddr 0, 1
34673 ret
34674 ENDPROC(efi_call0)
34675
34676 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
34677 call *%rdi
34678 addq $32, %rsp
34679 RESTORE_XMM
34680 + pax_force_retaddr 0, 1
34681 ret
34682 ENDPROC(efi_call1)
34683
34684 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
34685 call *%rdi
34686 addq $32, %rsp
34687 RESTORE_XMM
34688 + pax_force_retaddr 0, 1
34689 ret
34690 ENDPROC(efi_call2)
34691
34692 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
34693 call *%rdi
34694 addq $32, %rsp
34695 RESTORE_XMM
34696 + pax_force_retaddr 0, 1
34697 ret
34698 ENDPROC(efi_call3)
34699
34700 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
34701 call *%rdi
34702 addq $32, %rsp
34703 RESTORE_XMM
34704 + pax_force_retaddr 0, 1
34705 ret
34706 ENDPROC(efi_call4)
34707
34708 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
34709 call *%rdi
34710 addq $48, %rsp
34711 RESTORE_XMM
34712 + pax_force_retaddr 0, 1
34713 ret
34714 ENDPROC(efi_call5)
34715
34716 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
34717 call *%rdi
34718 addq $48, %rsp
34719 RESTORE_XMM
34720 + pax_force_retaddr 0, 1
34721 ret
34722 ENDPROC(efi_call6)
34723 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34724 index f90e290..435f0dd 100644
34725 --- a/arch/x86/platform/intel-mid/intel-mid.c
34726 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34727 @@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34728 {
34729 }
34730
34731 -static void intel_mid_reboot(void)
34732 +static void __noreturn intel_mid_reboot(void)
34733 {
34734 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34735 + BUG();
34736 }
34737
34738 static unsigned long __init intel_mid_calibrate_tsc(void)
34739 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34740 index d6ee929..3637cb5 100644
34741 --- a/arch/x86/platform/olpc/olpc_dt.c
34742 +++ b/arch/x86/platform/olpc/olpc_dt.c
34743 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34744 return res;
34745 }
34746
34747 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34748 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34749 .nextprop = olpc_dt_nextprop,
34750 .getproplen = olpc_dt_getproplen,
34751 .getproperty = olpc_dt_getproperty,
34752 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34753 index 424f4c9..f2a2988 100644
34754 --- a/arch/x86/power/cpu.c
34755 +++ b/arch/x86/power/cpu.c
34756 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34757 static void fix_processor_context(void)
34758 {
34759 int cpu = smp_processor_id();
34760 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34761 -#ifdef CONFIG_X86_64
34762 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34763 - tss_desc tss;
34764 -#endif
34765 + struct tss_struct *t = init_tss + cpu;
34766 +
34767 set_tss_desc(cpu, t); /*
34768 * This just modifies memory; should not be
34769 * necessary. But... This is necessary, because
34770 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34771 */
34772
34773 #ifdef CONFIG_X86_64
34774 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34775 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34776 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34777 -
34778 syscall_init(); /* This sets MSR_*STAR and related */
34779 #endif
34780 load_TR_desc(); /* This does ltr */
34781 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34782 index a44f457..9140171 100644
34783 --- a/arch/x86/realmode/init.c
34784 +++ b/arch/x86/realmode/init.c
34785 @@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34786 __va(real_mode_header->trampoline_header);
34787
34788 #ifdef CONFIG_X86_32
34789 - trampoline_header->start = __pa_symbol(startup_32_smp);
34790 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34791 +
34792 +#ifdef CONFIG_PAX_KERNEXEC
34793 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34794 +#endif
34795 +
34796 + trampoline_header->boot_cs = __BOOT_CS;
34797 trampoline_header->gdt_limit = __BOOT_DS + 7;
34798 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34799 #else
34800 @@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34801 *trampoline_cr4_features = read_cr4();
34802
34803 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34804 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34805 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34806 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34807 #endif
34808 }
34809 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34810 index 9cac825..4890b25 100644
34811 --- a/arch/x86/realmode/rm/Makefile
34812 +++ b/arch/x86/realmode/rm/Makefile
34813 @@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34814 $(call cc-option, -fno-unit-at-a-time)) \
34815 $(call cc-option, -fno-stack-protector) \
34816 $(call cc-option, -mpreferred-stack-boundary=2)
34817 +ifdef CONSTIFY_PLUGIN
34818 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34819 +endif
34820 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34821 GCOV_PROFILE := n
34822 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34823 index a28221d..93c40f1 100644
34824 --- a/arch/x86/realmode/rm/header.S
34825 +++ b/arch/x86/realmode/rm/header.S
34826 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34827 #endif
34828 /* APM/BIOS reboot */
34829 .long pa_machine_real_restart_asm
34830 -#ifdef CONFIG_X86_64
34831 +#ifdef CONFIG_X86_32
34832 + .long __KERNEL_CS
34833 +#else
34834 .long __KERNEL32_CS
34835 #endif
34836 END(real_mode_header)
34837 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34838 index c1b2791..f9e31c7 100644
34839 --- a/arch/x86/realmode/rm/trampoline_32.S
34840 +++ b/arch/x86/realmode/rm/trampoline_32.S
34841 @@ -25,6 +25,12 @@
34842 #include <asm/page_types.h>
34843 #include "realmode.h"
34844
34845 +#ifdef CONFIG_PAX_KERNEXEC
34846 +#define ta(X) (X)
34847 +#else
34848 +#define ta(X) (pa_ ## X)
34849 +#endif
34850 +
34851 .text
34852 .code16
34853
34854 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34855
34856 cli # We should be safe anyway
34857
34858 - movl tr_start, %eax # where we need to go
34859 -
34860 movl $0xA5A5A5A5, trampoline_status
34861 # write marker for master knows we're running
34862
34863 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34864 movw $1, %dx # protected mode (PE) bit
34865 lmsw %dx # into protected mode
34866
34867 - ljmpl $__BOOT_CS, $pa_startup_32
34868 + ljmpl *(trampoline_header)
34869
34870 .section ".text32","ax"
34871 .code32
34872 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34873 .balign 8
34874 GLOBAL(trampoline_header)
34875 tr_start: .space 4
34876 - tr_gdt_pad: .space 2
34877 + tr_boot_cs: .space 2
34878 tr_gdt: .space 6
34879 END(trampoline_header)
34880
34881 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34882 index bb360dc..d0fd8f8 100644
34883 --- a/arch/x86/realmode/rm/trampoline_64.S
34884 +++ b/arch/x86/realmode/rm/trampoline_64.S
34885 @@ -94,6 +94,7 @@ ENTRY(startup_32)
34886 movl %edx, %gs
34887
34888 movl pa_tr_cr4, %eax
34889 + andl $~X86_CR4_PCIDE, %eax
34890 movl %eax, %cr4 # Enable PAE mode
34891
34892 # Setup trampoline 4 level pagetables
34893 @@ -107,7 +108,7 @@ ENTRY(startup_32)
34894 wrmsr
34895
34896 # Enable paging and in turn activate Long Mode
34897 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34898 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
34899 movl %eax, %cr0
34900
34901 /*
34902 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34903 index e812034..c747134 100644
34904 --- a/arch/x86/tools/Makefile
34905 +++ b/arch/x86/tools/Makefile
34906 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34907
34908 $(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
34909
34910 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34911 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34912 hostprogs-y += relocs
34913 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34914 relocs: $(obj)/relocs
34915 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34916 index f7bab68..b6d9886 100644
34917 --- a/arch/x86/tools/relocs.c
34918 +++ b/arch/x86/tools/relocs.c
34919 @@ -1,5 +1,7 @@
34920 /* This is included from relocs_32/64.c */
34921
34922 +#include "../../../include/generated/autoconf.h"
34923 +
34924 #define ElfW(type) _ElfW(ELF_BITS, type)
34925 #define _ElfW(bits, type) __ElfW(bits, type)
34926 #define __ElfW(bits, type) Elf##bits##_##type
34927 @@ -11,6 +13,7 @@
34928 #define Elf_Sym ElfW(Sym)
34929
34930 static Elf_Ehdr ehdr;
34931 +static Elf_Phdr *phdr;
34932
34933 struct relocs {
34934 uint32_t *offset;
34935 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34936 }
34937 }
34938
34939 +static void read_phdrs(FILE *fp)
34940 +{
34941 + unsigned int i;
34942 +
34943 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34944 + if (!phdr) {
34945 + die("Unable to allocate %d program headers\n",
34946 + ehdr.e_phnum);
34947 + }
34948 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34949 + die("Seek to %d failed: %s\n",
34950 + ehdr.e_phoff, strerror(errno));
34951 + }
34952 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34953 + die("Cannot read ELF program headers: %s\n",
34954 + strerror(errno));
34955 + }
34956 + for(i = 0; i < ehdr.e_phnum; i++) {
34957 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34958 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34959 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34960 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34961 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34962 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34963 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34964 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34965 + }
34966 +
34967 +}
34968 +
34969 static void read_shdrs(FILE *fp)
34970 {
34971 - int i;
34972 + unsigned int i;
34973 Elf_Shdr shdr;
34974
34975 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34976 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34977
34978 static void read_strtabs(FILE *fp)
34979 {
34980 - int i;
34981 + unsigned int i;
34982 for (i = 0; i < ehdr.e_shnum; i++) {
34983 struct section *sec = &secs[i];
34984 if (sec->shdr.sh_type != SHT_STRTAB) {
34985 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34986
34987 static void read_symtabs(FILE *fp)
34988 {
34989 - int i,j;
34990 + unsigned int i,j;
34991 for (i = 0; i < ehdr.e_shnum; i++) {
34992 struct section *sec = &secs[i];
34993 if (sec->shdr.sh_type != SHT_SYMTAB) {
34994 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34995 }
34996
34997
34998 -static void read_relocs(FILE *fp)
34999 +static void read_relocs(FILE *fp, int use_real_mode)
35000 {
35001 - int i,j;
35002 + unsigned int i,j;
35003 + uint32_t base;
35004 +
35005 for (i = 0; i < ehdr.e_shnum; i++) {
35006 struct section *sec = &secs[i];
35007 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35008 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35009 die("Cannot read symbol table: %s\n",
35010 strerror(errno));
35011 }
35012 + base = 0;
35013 +
35014 +#ifdef CONFIG_X86_32
35015 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35016 + if (phdr[j].p_type != PT_LOAD )
35017 + continue;
35018 + 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)
35019 + continue;
35020 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35021 + break;
35022 + }
35023 +#endif
35024 +
35025 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35026 Elf_Rel *rel = &sec->reltab[j];
35027 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35028 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35029 rel->r_info = elf_xword_to_cpu(rel->r_info);
35030 #if (SHT_REL_TYPE == SHT_RELA)
35031 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35032 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35033
35034 static void print_absolute_symbols(void)
35035 {
35036 - int i;
35037 + unsigned int i;
35038 const char *format;
35039
35040 if (ELF_BITS == 64)
35041 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35042 for (i = 0; i < ehdr.e_shnum; i++) {
35043 struct section *sec = &secs[i];
35044 char *sym_strtab;
35045 - int j;
35046 + unsigned int j;
35047
35048 if (sec->shdr.sh_type != SHT_SYMTAB) {
35049 continue;
35050 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35051
35052 static void print_absolute_relocs(void)
35053 {
35054 - int i, printed = 0;
35055 + unsigned int i, printed = 0;
35056 const char *format;
35057
35058 if (ELF_BITS == 64)
35059 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35060 struct section *sec_applies, *sec_symtab;
35061 char *sym_strtab;
35062 Elf_Sym *sh_symtab;
35063 - int j;
35064 + unsigned int j;
35065 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35066 continue;
35067 }
35068 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35069 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35070 Elf_Sym *sym, const char *symname))
35071 {
35072 - int i;
35073 + unsigned int i;
35074 /* Walk through the relocations */
35075 for (i = 0; i < ehdr.e_shnum; i++) {
35076 char *sym_strtab;
35077 Elf_Sym *sh_symtab;
35078 struct section *sec_applies, *sec_symtab;
35079 - int j;
35080 + unsigned int j;
35081 struct section *sec = &secs[i];
35082
35083 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35084 @@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35085 {
35086 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35087 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35088 + char *sym_strtab = sec->link->link->strtab;
35089 +
35090 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35091 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35092 + return 0;
35093 +
35094 +#ifdef CONFIG_PAX_KERNEXEC
35095 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35096 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35097 + return 0;
35098 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35099 + return 0;
35100 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35101 + return 0;
35102 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35103 + return 0;
35104 +#endif
35105
35106 switch (r_type) {
35107 case R_386_NONE:
35108 @@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35109
35110 static void emit_relocs(int as_text, int use_real_mode)
35111 {
35112 - int i;
35113 + unsigned int i;
35114 int (*write_reloc)(uint32_t, FILE *) = write32;
35115 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35116 const char *symname);
35117 @@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35118 {
35119 regex_init(use_real_mode);
35120 read_ehdr(fp);
35121 + read_phdrs(fp);
35122 read_shdrs(fp);
35123 read_strtabs(fp);
35124 read_symtabs(fp);
35125 - read_relocs(fp);
35126 + read_relocs(fp, use_real_mode);
35127 if (ELF_BITS == 64)
35128 percpu_init();
35129 if (show_absolute_syms) {
35130 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35131 index 80ffa5b..a33bd15 100644
35132 --- a/arch/x86/um/tls_32.c
35133 +++ b/arch/x86/um/tls_32.c
35134 @@ -260,7 +260,7 @@ out:
35135 if (unlikely(task == current &&
35136 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35137 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35138 - "without flushed TLS.", current->pid);
35139 + "without flushed TLS.", task_pid_nr(current));
35140 }
35141
35142 return 0;
35143 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35144 index fd14be1..e3c79c0 100644
35145 --- a/arch/x86/vdso/Makefile
35146 +++ b/arch/x86/vdso/Makefile
35147 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35148 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35149 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35150
35151 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35152 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35153 GCOV_PROFILE := n
35154
35155 #
35156 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35157 index d6bfb87..876ee18 100644
35158 --- a/arch/x86/vdso/vdso32-setup.c
35159 +++ b/arch/x86/vdso/vdso32-setup.c
35160 @@ -25,6 +25,7 @@
35161 #include <asm/tlbflush.h>
35162 #include <asm/vdso.h>
35163 #include <asm/proto.h>
35164 +#include <asm/mman.h>
35165
35166 enum {
35167 VDSO_DISABLED = 0,
35168 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35169 void enable_sep_cpu(void)
35170 {
35171 int cpu = get_cpu();
35172 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35173 + struct tss_struct *tss = init_tss + cpu;
35174
35175 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35176 put_cpu();
35177 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35178 gate_vma.vm_start = FIXADDR_USER_START;
35179 gate_vma.vm_end = FIXADDR_USER_END;
35180 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35181 - gate_vma.vm_page_prot = __P101;
35182 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35183
35184 return 0;
35185 }
35186 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35187 if (compat)
35188 addr = VDSO_HIGH_BASE;
35189 else {
35190 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35191 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35192 if (IS_ERR_VALUE(addr)) {
35193 ret = addr;
35194 goto up_fail;
35195 }
35196 }
35197
35198 - current->mm->context.vdso = (void *)addr;
35199 + current->mm->context.vdso = addr;
35200
35201 if (compat_uses_vma || !compat) {
35202 /*
35203 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35204 }
35205
35206 current_thread_info()->sysenter_return =
35207 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35208 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35209
35210 up_fail:
35211 if (ret)
35212 - current->mm->context.vdso = NULL;
35213 + current->mm->context.vdso = 0;
35214
35215 up_write(&mm->mmap_sem);
35216
35217 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35218
35219 const char *arch_vma_name(struct vm_area_struct *vma)
35220 {
35221 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35222 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35223 return "[vdso]";
35224 +
35225 +#ifdef CONFIG_PAX_SEGMEXEC
35226 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35227 + return "[vdso]";
35228 +#endif
35229 +
35230 return NULL;
35231 }
35232
35233 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35234 * Check to see if the corresponding task was created in compat vdso
35235 * mode.
35236 */
35237 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35238 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35239 return &gate_vma;
35240 return NULL;
35241 }
35242 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35243 index 431e875..cbb23f3 100644
35244 --- a/arch/x86/vdso/vma.c
35245 +++ b/arch/x86/vdso/vma.c
35246 @@ -16,8 +16,6 @@
35247 #include <asm/vdso.h>
35248 #include <asm/page.h>
35249
35250 -unsigned int __read_mostly vdso_enabled = 1;
35251 -
35252 extern char vdso_start[], vdso_end[];
35253 extern unsigned short vdso_sync_cpuid;
35254
35255 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35256 * unaligned here as a result of stack start randomization.
35257 */
35258 addr = PAGE_ALIGN(addr);
35259 - addr = align_vdso_addr(addr);
35260
35261 return addr;
35262 }
35263 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35264 unsigned size)
35265 {
35266 struct mm_struct *mm = current->mm;
35267 - unsigned long addr;
35268 + unsigned long addr = 0;
35269 int ret;
35270
35271 - if (!vdso_enabled)
35272 - return 0;
35273 -
35274 down_write(&mm->mmap_sem);
35275 +
35276 +#ifdef CONFIG_PAX_RANDMMAP
35277 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35278 +#endif
35279 +
35280 addr = vdso_addr(mm->start_stack, size);
35281 + addr = align_vdso_addr(addr);
35282 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35283 if (IS_ERR_VALUE(addr)) {
35284 ret = addr;
35285 goto up_fail;
35286 }
35287
35288 - current->mm->context.vdso = (void *)addr;
35289 + mm->context.vdso = addr;
35290
35291 ret = install_special_mapping(mm, addr, size,
35292 VM_READ|VM_EXEC|
35293 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35294 pages);
35295 - if (ret) {
35296 - current->mm->context.vdso = NULL;
35297 - goto up_fail;
35298 - }
35299 + if (ret)
35300 + mm->context.vdso = 0;
35301
35302 up_fail:
35303 up_write(&mm->mmap_sem);
35304 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35305 vdsox32_size);
35306 }
35307 #endif
35308 -
35309 -static __init int vdso_setup(char *s)
35310 -{
35311 - vdso_enabled = simple_strtoul(s, NULL, 0);
35312 - return 0;
35313 -}
35314 -__setup("vdso=", vdso_setup);
35315 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35316 index 1a3c765..3d2e8d1 100644
35317 --- a/arch/x86/xen/Kconfig
35318 +++ b/arch/x86/xen/Kconfig
35319 @@ -9,6 +9,7 @@ config XEN
35320 select XEN_HAVE_PVMMU
35321 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35322 depends on X86_TSC
35323 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35324 help
35325 This is the Linux Xen port. Enabling this will allow the
35326 kernel to boot in a paravirtualized environment under the
35327 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35328 index fa6ade7..73da73a5 100644
35329 --- a/arch/x86/xen/enlighten.c
35330 +++ b/arch/x86/xen/enlighten.c
35331 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35332
35333 struct shared_info xen_dummy_shared_info;
35334
35335 -void *xen_initial_gdt;
35336 -
35337 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35338 __read_mostly int xen_have_vector_callback;
35339 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35340 @@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35341 {
35342 unsigned long va = dtr->address;
35343 unsigned int size = dtr->size + 1;
35344 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35345 - unsigned long frames[pages];
35346 + unsigned long frames[65536 / PAGE_SIZE];
35347 int f;
35348
35349 /*
35350 @@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35351 {
35352 unsigned long va = dtr->address;
35353 unsigned int size = dtr->size + 1;
35354 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35355 - unsigned long frames[pages];
35356 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35357 int f;
35358
35359 /*
35360 @@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35361 * 8-byte entries, or 16 4k pages..
35362 */
35363
35364 - BUG_ON(size > 65536);
35365 + BUG_ON(size > GDT_SIZE);
35366 BUG_ON(va & ~PAGE_MASK);
35367
35368 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35369 @@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35370 return 0;
35371 }
35372
35373 -static void set_xen_basic_apic_ops(void)
35374 +static void __init set_xen_basic_apic_ops(void)
35375 {
35376 apic->read = xen_apic_read;
35377 apic->write = xen_apic_write;
35378 @@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35379 #endif
35380 };
35381
35382 -static void xen_reboot(int reason)
35383 +static __noreturn void xen_reboot(int reason)
35384 {
35385 struct sched_shutdown r = { .reason = reason };
35386
35387 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35388 - BUG();
35389 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35390 + BUG();
35391 }
35392
35393 -static void xen_restart(char *msg)
35394 +static __noreturn void xen_restart(char *msg)
35395 {
35396 xen_reboot(SHUTDOWN_reboot);
35397 }
35398
35399 -static void xen_emergency_restart(void)
35400 +static __noreturn void xen_emergency_restart(void)
35401 {
35402 xen_reboot(SHUTDOWN_reboot);
35403 }
35404
35405 -static void xen_machine_halt(void)
35406 +static __noreturn void xen_machine_halt(void)
35407 {
35408 xen_reboot(SHUTDOWN_poweroff);
35409 }
35410
35411 -static void xen_machine_power_off(void)
35412 +static __noreturn void xen_machine_power_off(void)
35413 {
35414 if (pm_power_off)
35415 pm_power_off();
35416 @@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
35417 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35418
35419 /* Work out if we support NX */
35420 - x86_configure_nx();
35421 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35422 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35423 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35424 + unsigned l, h;
35425 +
35426 + __supported_pte_mask |= _PAGE_NX;
35427 + rdmsr(MSR_EFER, l, h);
35428 + l |= EFER_NX;
35429 + wrmsr(MSR_EFER, l, h);
35430 + }
35431 +#endif
35432
35433 xen_setup_features();
35434
35435 @@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
35436
35437 machine_ops = xen_machine_ops;
35438
35439 - /*
35440 - * The only reliable way to retain the initial address of the
35441 - * percpu gdt_page is to remember it here, so we can go and
35442 - * mark it RW later, when the initial percpu area is freed.
35443 - */
35444 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35445 -
35446 xen_smp_init();
35447
35448 #ifdef CONFIG_ACPI_NUMA
35449 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35450 index ce563be..7327d91 100644
35451 --- a/arch/x86/xen/mmu.c
35452 +++ b/arch/x86/xen/mmu.c
35453 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35454 return val;
35455 }
35456
35457 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35458 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35459 {
35460 if (val & _PAGE_PRESENT) {
35461 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35462 @@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35463 /* L3_k[510] -> level2_kernel_pgt
35464 * L3_i[511] -> level2_fixmap_pgt */
35465 convert_pfn_mfn(level3_kernel_pgt);
35466 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35467 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35468 + convert_pfn_mfn(level3_vmemmap_pgt);
35469
35470 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35471 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35472 @@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35473 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35474 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35475 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35476 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35477 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35478 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35479 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35480 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35481 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35482 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35483 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35484
35485 @@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
35486 pv_mmu_ops.set_pud = xen_set_pud;
35487 #if PAGETABLE_LEVELS == 4
35488 pv_mmu_ops.set_pgd = xen_set_pgd;
35489 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35490 #endif
35491
35492 /* This will work as long as patching hasn't happened yet
35493 @@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35494 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35495 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35496 .set_pgd = xen_set_pgd_hyper,
35497 + .set_pgd_batched = xen_set_pgd_hyper,
35498
35499 .alloc_pud = xen_alloc_pmd_init,
35500 .release_pud = xen_release_pmd_init,
35501 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35502 index c36b325..b0f1518 100644
35503 --- a/arch/x86/xen/smp.c
35504 +++ b/arch/x86/xen/smp.c
35505 @@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35506 native_smp_prepare_boot_cpu();
35507
35508 if (xen_pv_domain()) {
35509 - /* We've switched to the "real" per-cpu gdt, so make sure the
35510 - old memory can be recycled */
35511 - make_lowmem_page_readwrite(xen_initial_gdt);
35512 -
35513 #ifdef CONFIG_X86_32
35514 /*
35515 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35516 * expects __USER_DS
35517 */
35518 - loadsegment(ds, __USER_DS);
35519 - loadsegment(es, __USER_DS);
35520 + loadsegment(ds, __KERNEL_DS);
35521 + loadsegment(es, __KERNEL_DS);
35522 #endif
35523
35524 xen_filter_cpu_maps();
35525 @@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35526 ctxt->user_regs.ss = __KERNEL_DS;
35527 #ifdef CONFIG_X86_32
35528 ctxt->user_regs.fs = __KERNEL_PERCPU;
35529 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35530 + savesegment(gs, ctxt->user_regs.gs);
35531 #else
35532 ctxt->gs_base_kernel = per_cpu_offset(cpu);
35533 #endif
35534 @@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35535
35536 {
35537 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35538 - ctxt->user_regs.ds = __USER_DS;
35539 - ctxt->user_regs.es = __USER_DS;
35540 + ctxt->user_regs.ds = __KERNEL_DS;
35541 + ctxt->user_regs.es = __KERNEL_DS;
35542
35543 xen_copy_trap_info(ctxt->trap_ctxt);
35544
35545 @@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35546 int rc;
35547
35548 per_cpu(current_task, cpu) = idle;
35549 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35550 #ifdef CONFIG_X86_32
35551 irq_ctx_init(cpu);
35552 #else
35553 clear_tsk_thread_flag(idle, TIF_FORK);
35554 - per_cpu(kernel_stack, cpu) =
35555 - (unsigned long)task_stack_page(idle) -
35556 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35557 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35558 #endif
35559 xen_setup_runstate_info(cpu);
35560 xen_setup_timer(cpu);
35561 @@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35562
35563 void __init xen_smp_init(void)
35564 {
35565 - smp_ops = xen_smp_ops;
35566 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35567 xen_fill_possible_map();
35568 }
35569
35570 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35571 index 33ca6e4..0ded929 100644
35572 --- a/arch/x86/xen/xen-asm_32.S
35573 +++ b/arch/x86/xen/xen-asm_32.S
35574 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
35575 ESP_OFFSET=4 # bytes pushed onto stack
35576
35577 /*
35578 - * Store vcpu_info pointer for easy access. Do it this way to
35579 - * avoid having to reload %fs
35580 + * Store vcpu_info pointer for easy access.
35581 */
35582 #ifdef CONFIG_SMP
35583 - GET_THREAD_INFO(%eax)
35584 - movl %ss:TI_cpu(%eax), %eax
35585 - movl %ss:__per_cpu_offset(,%eax,4), %eax
35586 - mov %ss:xen_vcpu(%eax), %eax
35587 + push %fs
35588 + mov $(__KERNEL_PERCPU), %eax
35589 + mov %eax, %fs
35590 + mov PER_CPU_VAR(xen_vcpu), %eax
35591 + pop %fs
35592 #else
35593 movl %ss:xen_vcpu, %eax
35594 #endif
35595 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35596 index 7faed58..ba4427c 100644
35597 --- a/arch/x86/xen/xen-head.S
35598 +++ b/arch/x86/xen/xen-head.S
35599 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
35600 #ifdef CONFIG_X86_32
35601 mov %esi,xen_start_info
35602 mov $init_thread_union+THREAD_SIZE,%esp
35603 +#ifdef CONFIG_SMP
35604 + movl $cpu_gdt_table,%edi
35605 + movl $__per_cpu_load,%eax
35606 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35607 + rorl $16,%eax
35608 + movb %al,__KERNEL_PERCPU + 4(%edi)
35609 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35610 + movl $__per_cpu_end - 1,%eax
35611 + subl $__per_cpu_start,%eax
35612 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35613 +#endif
35614 #else
35615 mov %rsi,xen_start_info
35616 mov $init_thread_union+THREAD_SIZE,%rsp
35617 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35618 index 95f8c61..611d6e8 100644
35619 --- a/arch/x86/xen/xen-ops.h
35620 +++ b/arch/x86/xen/xen-ops.h
35621 @@ -10,8 +10,6 @@
35622 extern const char xen_hypervisor_callback[];
35623 extern const char xen_failsafe_callback[];
35624
35625 -extern void *xen_initial_gdt;
35626 -
35627 struct trap_info;
35628 void xen_copy_trap_info(struct trap_info *traps);
35629
35630 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35631 index 525bd3d..ef888b1 100644
35632 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35633 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35634 @@ -119,9 +119,9 @@
35635 ----------------------------------------------------------------------*/
35636
35637 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35638 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35639 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35640 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35641 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35642
35643 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35644 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35645 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35646 index 2f33760..835e50a 100644
35647 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35648 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35649 @@ -11,6 +11,7 @@
35650 #ifndef _XTENSA_CORE_H
35651 #define _XTENSA_CORE_H
35652
35653 +#include <linux/const.h>
35654
35655 /****************************************************************************
35656 Parameters Useful for Any Code, USER or PRIVILEGED
35657 @@ -112,9 +113,9 @@
35658 ----------------------------------------------------------------------*/
35659
35660 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35661 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35662 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35663 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35664 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35665
35666 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35667 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35668 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35669 index af00795..2bb8105 100644
35670 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35671 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35672 @@ -11,6 +11,7 @@
35673 #ifndef _XTENSA_CORE_CONFIGURATION_H
35674 #define _XTENSA_CORE_CONFIGURATION_H
35675
35676 +#include <linux/const.h>
35677
35678 /****************************************************************************
35679 Parameters Useful for Any Code, USER or PRIVILEGED
35680 @@ -118,9 +119,9 @@
35681 ----------------------------------------------------------------------*/
35682
35683 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35684 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35685 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35686 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35687 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35688
35689 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35690 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35691 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35692 index 4e491d9..c8e18e4 100644
35693 --- a/block/blk-cgroup.c
35694 +++ b/block/blk-cgroup.c
35695 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35696 static struct cgroup_subsys_state *
35697 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35698 {
35699 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35700 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35701 struct blkcg *blkcg;
35702
35703 if (!parent_css) {
35704 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35705
35706 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35707 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35708 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35709 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35710 done:
35711 spin_lock_init(&blkcg->lock);
35712 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35713 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35714 index 1855bf5..af12b06 100644
35715 --- a/block/blk-iopoll.c
35716 +++ b/block/blk-iopoll.c
35717 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35718 }
35719 EXPORT_SYMBOL(blk_iopoll_complete);
35720
35721 -static void blk_iopoll_softirq(struct softirq_action *h)
35722 +static __latent_entropy void blk_iopoll_softirq(void)
35723 {
35724 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35725 int rearm = 0, budget = blk_iopoll_budget;
35726 diff --git a/block/blk-map.c b/block/blk-map.c
35727 index 623e1cd..ca1e109 100644
35728 --- a/block/blk-map.c
35729 +++ b/block/blk-map.c
35730 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35731 if (!len || !kbuf)
35732 return -EINVAL;
35733
35734 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35735 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35736 if (do_copy)
35737 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35738 else
35739 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35740 index 57790c1..5e988dd 100644
35741 --- a/block/blk-softirq.c
35742 +++ b/block/blk-softirq.c
35743 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35744 * Softirq action handler - move entries to local list and loop over them
35745 * while passing them to the queue registered handler.
35746 */
35747 -static void blk_done_softirq(struct softirq_action *h)
35748 +static __latent_entropy void blk_done_softirq(void)
35749 {
35750 struct list_head *cpu_list, local_list;
35751
35752 diff --git a/block/bsg.c b/block/bsg.c
35753 index 420a5a9..23834aa 100644
35754 --- a/block/bsg.c
35755 +++ b/block/bsg.c
35756 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35757 struct sg_io_v4 *hdr, struct bsg_device *bd,
35758 fmode_t has_write_perm)
35759 {
35760 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35761 + unsigned char *cmdptr;
35762 +
35763 if (hdr->request_len > BLK_MAX_CDB) {
35764 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35765 if (!rq->cmd)
35766 return -ENOMEM;
35767 - }
35768 + cmdptr = rq->cmd;
35769 + } else
35770 + cmdptr = tmpcmd;
35771
35772 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35773 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35774 hdr->request_len))
35775 return -EFAULT;
35776
35777 + if (cmdptr != rq->cmd)
35778 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35779 +
35780 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35781 if (blk_verify_command(rq->cmd, has_write_perm))
35782 return -EPERM;
35783 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35784 index fbd5a67..f24fd95 100644
35785 --- a/block/compat_ioctl.c
35786 +++ b/block/compat_ioctl.c
35787 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35788 cgc = compat_alloc_user_space(sizeof(*cgc));
35789 cgc32 = compat_ptr(arg);
35790
35791 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35792 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35793 get_user(data, &cgc32->buffer) ||
35794 put_user(compat_ptr(data), &cgc->buffer) ||
35795 copy_in_user(&cgc->buflen, &cgc32->buflen,
35796 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35797 err |= __get_user(f->spec1, &uf->spec1);
35798 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35799 err |= __get_user(name, &uf->name);
35800 - f->name = compat_ptr(name);
35801 + f->name = (void __force_kernel *)compat_ptr(name);
35802 if (err) {
35803 err = -EFAULT;
35804 goto out;
35805 diff --git a/block/genhd.c b/block/genhd.c
35806 index 791f419..89f21c4 100644
35807 --- a/block/genhd.c
35808 +++ b/block/genhd.c
35809 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35810
35811 /*
35812 * Register device numbers dev..(dev+range-1)
35813 - * range must be nonzero
35814 + * Noop if @range is zero.
35815 * The hash chain is sorted on range, so that subranges can override.
35816 */
35817 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35818 struct kobject *(*probe)(dev_t, int *, void *),
35819 int (*lock)(dev_t, void *), void *data)
35820 {
35821 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35822 + if (range)
35823 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35824 }
35825
35826 EXPORT_SYMBOL(blk_register_region);
35827
35828 +/* undo blk_register_region(), noop if @range is zero */
35829 void blk_unregister_region(dev_t devt, unsigned long range)
35830 {
35831 - kobj_unmap(bdev_map, devt, range);
35832 + if (range)
35833 + kobj_unmap(bdev_map, devt, range);
35834 }
35835
35836 EXPORT_SYMBOL(blk_unregister_region);
35837 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35838 index dc51f46..d5446a8 100644
35839 --- a/block/partitions/efi.c
35840 +++ b/block/partitions/efi.c
35841 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35842 if (!gpt)
35843 return NULL;
35844
35845 + if (!le32_to_cpu(gpt->num_partition_entries))
35846 + return NULL;
35847 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35848 + if (!pte)
35849 + return NULL;
35850 +
35851 count = le32_to_cpu(gpt->num_partition_entries) *
35852 le32_to_cpu(gpt->sizeof_partition_entry);
35853 - if (!count)
35854 - return NULL;
35855 - pte = kmalloc(count, GFP_KERNEL);
35856 - if (!pte)
35857 - return NULL;
35858 -
35859 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35860 (u8 *) pte, count) < count) {
35861 kfree(pte);
35862 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35863 index 625e3e4..b5339f9 100644
35864 --- a/block/scsi_ioctl.c
35865 +++ b/block/scsi_ioctl.c
35866 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35867 return put_user(0, p);
35868 }
35869
35870 -static int sg_get_timeout(struct request_queue *q)
35871 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35872 {
35873 return jiffies_to_clock_t(q->sg_timeout);
35874 }
35875 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35876 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35877 struct sg_io_hdr *hdr, fmode_t mode)
35878 {
35879 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35880 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35881 + unsigned char *cmdptr;
35882 +
35883 + if (rq->cmd != rq->__cmd)
35884 + cmdptr = rq->cmd;
35885 + else
35886 + cmdptr = tmpcmd;
35887 +
35888 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35889 return -EFAULT;
35890 +
35891 + if (cmdptr != rq->cmd)
35892 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35893 +
35894 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35895 return -EPERM;
35896
35897 @@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35898 int err;
35899 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35900 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35901 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35902 + unsigned char *cmdptr;
35903
35904 if (!sic)
35905 return -EINVAL;
35906 @@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35907 */
35908 err = -EFAULT;
35909 rq->cmd_len = cmdlen;
35910 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
35911 +
35912 + if (rq->cmd != rq->__cmd)
35913 + cmdptr = rq->cmd;
35914 + else
35915 + cmdptr = tmpcmd;
35916 +
35917 + if (copy_from_user(cmdptr, sic->data, cmdlen))
35918 goto error;
35919
35920 + if (rq->cmd != cmdptr)
35921 + memcpy(rq->cmd, cmdptr, cmdlen);
35922 +
35923 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35924 goto error;
35925
35926 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35927 index 7bdd61b..afec999 100644
35928 --- a/crypto/cryptd.c
35929 +++ b/crypto/cryptd.c
35930 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35931
35932 struct cryptd_blkcipher_request_ctx {
35933 crypto_completion_t complete;
35934 -};
35935 +} __no_const;
35936
35937 struct cryptd_hash_ctx {
35938 struct crypto_shash *child;
35939 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35940
35941 struct cryptd_aead_request_ctx {
35942 crypto_completion_t complete;
35943 -};
35944 +} __no_const;
35945
35946 static void cryptd_queue_worker(struct work_struct *work);
35947
35948 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35949 index f8c920c..ab2cb5a 100644
35950 --- a/crypto/pcrypt.c
35951 +++ b/crypto/pcrypt.c
35952 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35953 int ret;
35954
35955 pinst->kobj.kset = pcrypt_kset;
35956 - ret = kobject_add(&pinst->kobj, NULL, name);
35957 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35958 if (!ret)
35959 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35960
35961 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35962 index 15dddc1..b61cf0c 100644
35963 --- a/drivers/acpi/acpica/hwxfsleep.c
35964 +++ b/drivers/acpi/acpica/hwxfsleep.c
35965 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35966 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35967
35968 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35969 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35970 - acpi_hw_extended_sleep},
35971 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35972 - acpi_hw_extended_wake_prep},
35973 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35974 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35975 + .extended_function = acpi_hw_extended_sleep},
35976 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35977 + .extended_function = acpi_hw_extended_wake_prep},
35978 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35979 + .extended_function = acpi_hw_extended_wake}
35980 };
35981
35982 /*
35983 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35984 index 21ba34a..cb05966 100644
35985 --- a/drivers/acpi/apei/apei-internal.h
35986 +++ b/drivers/acpi/apei/apei-internal.h
35987 @@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35988 struct apei_exec_ins_type {
35989 u32 flags;
35990 apei_exec_ins_func_t run;
35991 -};
35992 +} __do_const;
35993
35994 struct apei_exec_context {
35995 u32 ip;
35996 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35997 index a30bc31..b91c4d5 100644
35998 --- a/drivers/acpi/apei/ghes.c
35999 +++ b/drivers/acpi/apei/ghes.c
36000 @@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
36001 const struct acpi_hest_generic *generic,
36002 const struct acpi_generic_status *estatus)
36003 {
36004 - static atomic_t seqno;
36005 + static atomic_unchecked_t seqno;
36006 unsigned int curr_seqno;
36007 char pfx_seq[64];
36008
36009 @@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
36010 else
36011 pfx = KERN_ERR;
36012 }
36013 - curr_seqno = atomic_inc_return(&seqno);
36014 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36015 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36016 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36017 pfx_seq, generic->header.source_id);
36018 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36019 index a83e3c6..c3d617f 100644
36020 --- a/drivers/acpi/bgrt.c
36021 +++ b/drivers/acpi/bgrt.c
36022 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36023 if (!bgrt_image)
36024 return -ENODEV;
36025
36026 - bin_attr_image.private = bgrt_image;
36027 - bin_attr_image.size = bgrt_image_size;
36028 + pax_open_kernel();
36029 + *(void **)&bin_attr_image.private = bgrt_image;
36030 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36031 + pax_close_kernel();
36032
36033 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36034 if (!bgrt_kobj)
36035 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36036 index 078c4f7..410e272 100644
36037 --- a/drivers/acpi/blacklist.c
36038 +++ b/drivers/acpi/blacklist.c
36039 @@ -52,7 +52,7 @@ struct acpi_blacklist_item {
36040 u32 is_critical_error;
36041 };
36042
36043 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36044 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36045
36046 /*
36047 * POLICY: If *anything* doesn't work, put it on the blacklist.
36048 @@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36049 return 0;
36050 }
36051
36052 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36053 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36054 {
36055 .callback = dmi_disable_osi_vista,
36056 .ident = "Fujitsu Siemens",
36057 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36058 index 12b62f2..dc2aac8 100644
36059 --- a/drivers/acpi/custom_method.c
36060 +++ b/drivers/acpi/custom_method.c
36061 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36062 struct acpi_table_header table;
36063 acpi_status status;
36064
36065 +#ifdef CONFIG_GRKERNSEC_KMEM
36066 + return -EPERM;
36067 +#endif
36068 +
36069 if (!(*ppos)) {
36070 /* parse the table header to get the table length */
36071 if (count <= sizeof(struct acpi_table_header))
36072 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36073 index 644516d..643937e 100644
36074 --- a/drivers/acpi/processor_idle.c
36075 +++ b/drivers/acpi/processor_idle.c
36076 @@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36077 {
36078 int i, count = CPUIDLE_DRIVER_STATE_START;
36079 struct acpi_processor_cx *cx;
36080 - struct cpuidle_state *state;
36081 + cpuidle_state_no_const *state;
36082 struct cpuidle_driver *drv = &acpi_idle_driver;
36083
36084 if (!pr->flags.power_setup_done)
36085 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36086 index 6dbc3ca..b8b59a0 100644
36087 --- a/drivers/acpi/sysfs.c
36088 +++ b/drivers/acpi/sysfs.c
36089 @@ -425,11 +425,11 @@ static u32 num_counters;
36090 static struct attribute **all_attrs;
36091 static u32 acpi_gpe_count;
36092
36093 -static struct attribute_group interrupt_stats_attr_group = {
36094 +static attribute_group_no_const interrupt_stats_attr_group = {
36095 .name = "interrupts",
36096 };
36097
36098 -static struct kobj_attribute *counter_attrs;
36099 +static kobj_attribute_no_const *counter_attrs;
36100
36101 static void delete_gpe_attr_array(void)
36102 {
36103 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36104 index c482f8c..c832240 100644
36105 --- a/drivers/ata/libahci.c
36106 +++ b/drivers/ata/libahci.c
36107 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36108 }
36109 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36110
36111 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36112 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36113 struct ata_taskfile *tf, int is_cmd, u16 flags,
36114 unsigned long timeout_msec)
36115 {
36116 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36117 index 8cb2522..a815e54 100644
36118 --- a/drivers/ata/libata-core.c
36119 +++ b/drivers/ata/libata-core.c
36120 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36121 static void ata_dev_xfermask(struct ata_device *dev);
36122 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36123
36124 -atomic_t ata_print_id = ATOMIC_INIT(0);
36125 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36126
36127 struct ata_force_param {
36128 const char *name;
36129 @@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36130 struct ata_port *ap;
36131 unsigned int tag;
36132
36133 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36134 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36135 ap = qc->ap;
36136
36137 qc->flags = 0;
36138 @@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36139 struct ata_port *ap;
36140 struct ata_link *link;
36141
36142 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36143 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36144 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36145 ap = qc->ap;
36146 link = qc->dev->link;
36147 @@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36148 return;
36149
36150 spin_lock(&lock);
36151 + pax_open_kernel();
36152
36153 for (cur = ops->inherits; cur; cur = cur->inherits) {
36154 void **inherit = (void **)cur;
36155 @@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36156 if (IS_ERR(*pp))
36157 *pp = NULL;
36158
36159 - ops->inherits = NULL;
36160 + *(struct ata_port_operations **)&ops->inherits = NULL;
36161
36162 + pax_close_kernel();
36163 spin_unlock(&lock);
36164 }
36165
36166 @@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36167
36168 /* give ports names and add SCSI hosts */
36169 for (i = 0; i < host->n_ports; i++) {
36170 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36171 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36172 host->ports[i]->local_port_no = i + 1;
36173 }
36174
36175 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36176 index ef8567d..8bdbd03 100644
36177 --- a/drivers/ata/libata-scsi.c
36178 +++ b/drivers/ata/libata-scsi.c
36179 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36180
36181 if (rc)
36182 return rc;
36183 - ap->print_id = atomic_inc_return(&ata_print_id);
36184 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36185 return 0;
36186 }
36187 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36188 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36189 index 45b5ab3..98446b8 100644
36190 --- a/drivers/ata/libata.h
36191 +++ b/drivers/ata/libata.h
36192 @@ -53,7 +53,7 @@ enum {
36193 ATA_DNXFER_QUIET = (1 << 31),
36194 };
36195
36196 -extern atomic_t ata_print_id;
36197 +extern atomic_unchecked_t ata_print_id;
36198 extern int atapi_passthru16;
36199 extern int libata_fua;
36200 extern int libata_noacpi;
36201 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36202 index 73492dd..ca2bff5 100644
36203 --- a/drivers/ata/pata_arasan_cf.c
36204 +++ b/drivers/ata/pata_arasan_cf.c
36205 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36206 /* Handle platform specific quirks */
36207 if (quirk) {
36208 if (quirk & CF_BROKEN_PIO) {
36209 - ap->ops->set_piomode = NULL;
36210 + pax_open_kernel();
36211 + *(void **)&ap->ops->set_piomode = NULL;
36212 + pax_close_kernel();
36213 ap->pio_mask = 0;
36214 }
36215 if (quirk & CF_BROKEN_MWDMA)
36216 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36217 index f9b983a..887b9d8 100644
36218 --- a/drivers/atm/adummy.c
36219 +++ b/drivers/atm/adummy.c
36220 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36221 vcc->pop(vcc, skb);
36222 else
36223 dev_kfree_skb_any(skb);
36224 - atomic_inc(&vcc->stats->tx);
36225 + atomic_inc_unchecked(&vcc->stats->tx);
36226
36227 return 0;
36228 }
36229 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36230 index 62a7607..cc4be104 100644
36231 --- a/drivers/atm/ambassador.c
36232 +++ b/drivers/atm/ambassador.c
36233 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36234 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36235
36236 // VC layer stats
36237 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36238 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36239
36240 // free the descriptor
36241 kfree (tx_descr);
36242 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36243 dump_skb ("<<<", vc, skb);
36244
36245 // VC layer stats
36246 - atomic_inc(&atm_vcc->stats->rx);
36247 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36248 __net_timestamp(skb);
36249 // end of our responsibility
36250 atm_vcc->push (atm_vcc, skb);
36251 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36252 } else {
36253 PRINTK (KERN_INFO, "dropped over-size frame");
36254 // should we count this?
36255 - atomic_inc(&atm_vcc->stats->rx_drop);
36256 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36257 }
36258
36259 } else {
36260 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36261 }
36262
36263 if (check_area (skb->data, skb->len)) {
36264 - atomic_inc(&atm_vcc->stats->tx_err);
36265 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36266 return -ENOMEM; // ?
36267 }
36268
36269 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36270 index 0e3f8f9..765a7a5 100644
36271 --- a/drivers/atm/atmtcp.c
36272 +++ b/drivers/atm/atmtcp.c
36273 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36274 if (vcc->pop) vcc->pop(vcc,skb);
36275 else dev_kfree_skb(skb);
36276 if (dev_data) return 0;
36277 - atomic_inc(&vcc->stats->tx_err);
36278 + atomic_inc_unchecked(&vcc->stats->tx_err);
36279 return -ENOLINK;
36280 }
36281 size = skb->len+sizeof(struct atmtcp_hdr);
36282 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36283 if (!new_skb) {
36284 if (vcc->pop) vcc->pop(vcc,skb);
36285 else dev_kfree_skb(skb);
36286 - atomic_inc(&vcc->stats->tx_err);
36287 + atomic_inc_unchecked(&vcc->stats->tx_err);
36288 return -ENOBUFS;
36289 }
36290 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36291 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36292 if (vcc->pop) vcc->pop(vcc,skb);
36293 else dev_kfree_skb(skb);
36294 out_vcc->push(out_vcc,new_skb);
36295 - atomic_inc(&vcc->stats->tx);
36296 - atomic_inc(&out_vcc->stats->rx);
36297 + atomic_inc_unchecked(&vcc->stats->tx);
36298 + atomic_inc_unchecked(&out_vcc->stats->rx);
36299 return 0;
36300 }
36301
36302 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36303 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36304 read_unlock(&vcc_sklist_lock);
36305 if (!out_vcc) {
36306 - atomic_inc(&vcc->stats->tx_err);
36307 + atomic_inc_unchecked(&vcc->stats->tx_err);
36308 goto done;
36309 }
36310 skb_pull(skb,sizeof(struct atmtcp_hdr));
36311 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36312 __net_timestamp(new_skb);
36313 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36314 out_vcc->push(out_vcc,new_skb);
36315 - atomic_inc(&vcc->stats->tx);
36316 - atomic_inc(&out_vcc->stats->rx);
36317 + atomic_inc_unchecked(&vcc->stats->tx);
36318 + atomic_inc_unchecked(&out_vcc->stats->rx);
36319 done:
36320 if (vcc->pop) vcc->pop(vcc,skb);
36321 else dev_kfree_skb(skb);
36322 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36323 index b1955ba..b179940 100644
36324 --- a/drivers/atm/eni.c
36325 +++ b/drivers/atm/eni.c
36326 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36327 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36328 vcc->dev->number);
36329 length = 0;
36330 - atomic_inc(&vcc->stats->rx_err);
36331 + atomic_inc_unchecked(&vcc->stats->rx_err);
36332 }
36333 else {
36334 length = ATM_CELL_SIZE-1; /* no HEC */
36335 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36336 size);
36337 }
36338 eff = length = 0;
36339 - atomic_inc(&vcc->stats->rx_err);
36340 + atomic_inc_unchecked(&vcc->stats->rx_err);
36341 }
36342 else {
36343 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36344 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36345 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36346 vcc->dev->number,vcc->vci,length,size << 2,descr);
36347 length = eff = 0;
36348 - atomic_inc(&vcc->stats->rx_err);
36349 + atomic_inc_unchecked(&vcc->stats->rx_err);
36350 }
36351 }
36352 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36353 @@ -767,7 +767,7 @@ rx_dequeued++;
36354 vcc->push(vcc,skb);
36355 pushed++;
36356 }
36357 - atomic_inc(&vcc->stats->rx);
36358 + atomic_inc_unchecked(&vcc->stats->rx);
36359 }
36360 wake_up(&eni_dev->rx_wait);
36361 }
36362 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36363 PCI_DMA_TODEVICE);
36364 if (vcc->pop) vcc->pop(vcc,skb);
36365 else dev_kfree_skb_irq(skb);
36366 - atomic_inc(&vcc->stats->tx);
36367 + atomic_inc_unchecked(&vcc->stats->tx);
36368 wake_up(&eni_dev->tx_wait);
36369 dma_complete++;
36370 }
36371 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36372 index b41c948..a002b17 100644
36373 --- a/drivers/atm/firestream.c
36374 +++ b/drivers/atm/firestream.c
36375 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36376 }
36377 }
36378
36379 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36380 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36381
36382 fs_dprintk (FS_DEBUG_TXMEM, "i");
36383 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36384 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36385 #endif
36386 skb_put (skb, qe->p1 & 0xffff);
36387 ATM_SKB(skb)->vcc = atm_vcc;
36388 - atomic_inc(&atm_vcc->stats->rx);
36389 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36390 __net_timestamp(skb);
36391 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36392 atm_vcc->push (atm_vcc, skb);
36393 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36394 kfree (pe);
36395 }
36396 if (atm_vcc)
36397 - atomic_inc(&atm_vcc->stats->rx_drop);
36398 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36399 break;
36400 case 0x1f: /* Reassembly abort: no buffers. */
36401 /* Silently increment error counter. */
36402 if (atm_vcc)
36403 - atomic_inc(&atm_vcc->stats->rx_drop);
36404 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36405 break;
36406 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36407 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36408 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36409 index 204814e..cede831 100644
36410 --- a/drivers/atm/fore200e.c
36411 +++ b/drivers/atm/fore200e.c
36412 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36413 #endif
36414 /* check error condition */
36415 if (*entry->status & STATUS_ERROR)
36416 - atomic_inc(&vcc->stats->tx_err);
36417 + atomic_inc_unchecked(&vcc->stats->tx_err);
36418 else
36419 - atomic_inc(&vcc->stats->tx);
36420 + atomic_inc_unchecked(&vcc->stats->tx);
36421 }
36422 }
36423
36424 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36425 if (skb == NULL) {
36426 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36427
36428 - atomic_inc(&vcc->stats->rx_drop);
36429 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36430 return -ENOMEM;
36431 }
36432
36433 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36434
36435 dev_kfree_skb_any(skb);
36436
36437 - atomic_inc(&vcc->stats->rx_drop);
36438 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36439 return -ENOMEM;
36440 }
36441
36442 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36443
36444 vcc->push(vcc, skb);
36445 - atomic_inc(&vcc->stats->rx);
36446 + atomic_inc_unchecked(&vcc->stats->rx);
36447
36448 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36449
36450 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36451 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36452 fore200e->atm_dev->number,
36453 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36454 - atomic_inc(&vcc->stats->rx_err);
36455 + atomic_inc_unchecked(&vcc->stats->rx_err);
36456 }
36457 }
36458
36459 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36460 goto retry_here;
36461 }
36462
36463 - atomic_inc(&vcc->stats->tx_err);
36464 + atomic_inc_unchecked(&vcc->stats->tx_err);
36465
36466 fore200e->tx_sat++;
36467 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36468 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36469 index 8557adc..3fb5d55 100644
36470 --- a/drivers/atm/he.c
36471 +++ b/drivers/atm/he.c
36472 @@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36473
36474 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36475 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36476 - atomic_inc(&vcc->stats->rx_drop);
36477 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36478 goto return_host_buffers;
36479 }
36480
36481 @@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36482 RBRQ_LEN_ERR(he_dev->rbrq_head)
36483 ? "LEN_ERR" : "",
36484 vcc->vpi, vcc->vci);
36485 - atomic_inc(&vcc->stats->rx_err);
36486 + atomic_inc_unchecked(&vcc->stats->rx_err);
36487 goto return_host_buffers;
36488 }
36489
36490 @@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36491 vcc->push(vcc, skb);
36492 spin_lock(&he_dev->global_lock);
36493
36494 - atomic_inc(&vcc->stats->rx);
36495 + atomic_inc_unchecked(&vcc->stats->rx);
36496
36497 return_host_buffers:
36498 ++pdus_assembled;
36499 @@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36500 tpd->vcc->pop(tpd->vcc, tpd->skb);
36501 else
36502 dev_kfree_skb_any(tpd->skb);
36503 - atomic_inc(&tpd->vcc->stats->tx_err);
36504 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36505 }
36506 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36507 return;
36508 @@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36509 vcc->pop(vcc, skb);
36510 else
36511 dev_kfree_skb_any(skb);
36512 - atomic_inc(&vcc->stats->tx_err);
36513 + atomic_inc_unchecked(&vcc->stats->tx_err);
36514 return -EINVAL;
36515 }
36516
36517 @@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36518 vcc->pop(vcc, skb);
36519 else
36520 dev_kfree_skb_any(skb);
36521 - atomic_inc(&vcc->stats->tx_err);
36522 + atomic_inc_unchecked(&vcc->stats->tx_err);
36523 return -EINVAL;
36524 }
36525 #endif
36526 @@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36527 vcc->pop(vcc, skb);
36528 else
36529 dev_kfree_skb_any(skb);
36530 - atomic_inc(&vcc->stats->tx_err);
36531 + atomic_inc_unchecked(&vcc->stats->tx_err);
36532 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36533 return -ENOMEM;
36534 }
36535 @@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36536 vcc->pop(vcc, skb);
36537 else
36538 dev_kfree_skb_any(skb);
36539 - atomic_inc(&vcc->stats->tx_err);
36540 + atomic_inc_unchecked(&vcc->stats->tx_err);
36541 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36542 return -ENOMEM;
36543 }
36544 @@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36545 __enqueue_tpd(he_dev, tpd, cid);
36546 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36547
36548 - atomic_inc(&vcc->stats->tx);
36549 + atomic_inc_unchecked(&vcc->stats->tx);
36550
36551 return 0;
36552 }
36553 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36554 index 1dc0519..1aadaf7 100644
36555 --- a/drivers/atm/horizon.c
36556 +++ b/drivers/atm/horizon.c
36557 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36558 {
36559 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36560 // VC layer stats
36561 - atomic_inc(&vcc->stats->rx);
36562 + atomic_inc_unchecked(&vcc->stats->rx);
36563 __net_timestamp(skb);
36564 // end of our responsibility
36565 vcc->push (vcc, skb);
36566 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36567 dev->tx_iovec = NULL;
36568
36569 // VC layer stats
36570 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36571 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36572
36573 // free the skb
36574 hrz_kfree_skb (skb);
36575 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36576 index 1bdf104..9dc44b1 100644
36577 --- a/drivers/atm/idt77252.c
36578 +++ b/drivers/atm/idt77252.c
36579 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36580 else
36581 dev_kfree_skb(skb);
36582
36583 - atomic_inc(&vcc->stats->tx);
36584 + atomic_inc_unchecked(&vcc->stats->tx);
36585 }
36586
36587 atomic_dec(&scq->used);
36588 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36589 if ((sb = dev_alloc_skb(64)) == NULL) {
36590 printk("%s: Can't allocate buffers for aal0.\n",
36591 card->name);
36592 - atomic_add(i, &vcc->stats->rx_drop);
36593 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36594 break;
36595 }
36596 if (!atm_charge(vcc, sb->truesize)) {
36597 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36598 card->name);
36599 - atomic_add(i - 1, &vcc->stats->rx_drop);
36600 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36601 dev_kfree_skb(sb);
36602 break;
36603 }
36604 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36605 ATM_SKB(sb)->vcc = vcc;
36606 __net_timestamp(sb);
36607 vcc->push(vcc, sb);
36608 - atomic_inc(&vcc->stats->rx);
36609 + atomic_inc_unchecked(&vcc->stats->rx);
36610
36611 cell += ATM_CELL_PAYLOAD;
36612 }
36613 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36614 "(CDC: %08x)\n",
36615 card->name, len, rpp->len, readl(SAR_REG_CDC));
36616 recycle_rx_pool_skb(card, rpp);
36617 - atomic_inc(&vcc->stats->rx_err);
36618 + atomic_inc_unchecked(&vcc->stats->rx_err);
36619 return;
36620 }
36621 if (stat & SAR_RSQE_CRC) {
36622 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36623 recycle_rx_pool_skb(card, rpp);
36624 - atomic_inc(&vcc->stats->rx_err);
36625 + atomic_inc_unchecked(&vcc->stats->rx_err);
36626 return;
36627 }
36628 if (skb_queue_len(&rpp->queue) > 1) {
36629 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36630 RXPRINTK("%s: Can't alloc RX skb.\n",
36631 card->name);
36632 recycle_rx_pool_skb(card, rpp);
36633 - atomic_inc(&vcc->stats->rx_err);
36634 + atomic_inc_unchecked(&vcc->stats->rx_err);
36635 return;
36636 }
36637 if (!atm_charge(vcc, skb->truesize)) {
36638 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36639 __net_timestamp(skb);
36640
36641 vcc->push(vcc, skb);
36642 - atomic_inc(&vcc->stats->rx);
36643 + atomic_inc_unchecked(&vcc->stats->rx);
36644
36645 return;
36646 }
36647 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36648 __net_timestamp(skb);
36649
36650 vcc->push(vcc, skb);
36651 - atomic_inc(&vcc->stats->rx);
36652 + atomic_inc_unchecked(&vcc->stats->rx);
36653
36654 if (skb->truesize > SAR_FB_SIZE_3)
36655 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36656 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36657 if (vcc->qos.aal != ATM_AAL0) {
36658 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36659 card->name, vpi, vci);
36660 - atomic_inc(&vcc->stats->rx_drop);
36661 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36662 goto drop;
36663 }
36664
36665 if ((sb = dev_alloc_skb(64)) == NULL) {
36666 printk("%s: Can't allocate buffers for AAL0.\n",
36667 card->name);
36668 - atomic_inc(&vcc->stats->rx_err);
36669 + atomic_inc_unchecked(&vcc->stats->rx_err);
36670 goto drop;
36671 }
36672
36673 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36674 ATM_SKB(sb)->vcc = vcc;
36675 __net_timestamp(sb);
36676 vcc->push(vcc, sb);
36677 - atomic_inc(&vcc->stats->rx);
36678 + atomic_inc_unchecked(&vcc->stats->rx);
36679
36680 drop:
36681 skb_pull(queue, 64);
36682 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36683
36684 if (vc == NULL) {
36685 printk("%s: NULL connection in send().\n", card->name);
36686 - atomic_inc(&vcc->stats->tx_err);
36687 + atomic_inc_unchecked(&vcc->stats->tx_err);
36688 dev_kfree_skb(skb);
36689 return -EINVAL;
36690 }
36691 if (!test_bit(VCF_TX, &vc->flags)) {
36692 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36693 - atomic_inc(&vcc->stats->tx_err);
36694 + atomic_inc_unchecked(&vcc->stats->tx_err);
36695 dev_kfree_skb(skb);
36696 return -EINVAL;
36697 }
36698 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36699 break;
36700 default:
36701 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36702 - atomic_inc(&vcc->stats->tx_err);
36703 + atomic_inc_unchecked(&vcc->stats->tx_err);
36704 dev_kfree_skb(skb);
36705 return -EINVAL;
36706 }
36707
36708 if (skb_shinfo(skb)->nr_frags != 0) {
36709 printk("%s: No scatter-gather yet.\n", card->name);
36710 - atomic_inc(&vcc->stats->tx_err);
36711 + atomic_inc_unchecked(&vcc->stats->tx_err);
36712 dev_kfree_skb(skb);
36713 return -EINVAL;
36714 }
36715 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36716
36717 err = queue_skb(card, vc, skb, oam);
36718 if (err) {
36719 - atomic_inc(&vcc->stats->tx_err);
36720 + atomic_inc_unchecked(&vcc->stats->tx_err);
36721 dev_kfree_skb(skb);
36722 return err;
36723 }
36724 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36725 skb = dev_alloc_skb(64);
36726 if (!skb) {
36727 printk("%s: Out of memory in send_oam().\n", card->name);
36728 - atomic_inc(&vcc->stats->tx_err);
36729 + atomic_inc_unchecked(&vcc->stats->tx_err);
36730 return -ENOMEM;
36731 }
36732 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36733 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36734 index 4217f29..88f547a 100644
36735 --- a/drivers/atm/iphase.c
36736 +++ b/drivers/atm/iphase.c
36737 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36738 status = (u_short) (buf_desc_ptr->desc_mode);
36739 if (status & (RX_CER | RX_PTE | RX_OFL))
36740 {
36741 - atomic_inc(&vcc->stats->rx_err);
36742 + atomic_inc_unchecked(&vcc->stats->rx_err);
36743 IF_ERR(printk("IA: bad packet, dropping it");)
36744 if (status & RX_CER) {
36745 IF_ERR(printk(" cause: packet CRC error\n");)
36746 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36747 len = dma_addr - buf_addr;
36748 if (len > iadev->rx_buf_sz) {
36749 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36750 - atomic_inc(&vcc->stats->rx_err);
36751 + atomic_inc_unchecked(&vcc->stats->rx_err);
36752 goto out_free_desc;
36753 }
36754
36755 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36756 ia_vcc = INPH_IA_VCC(vcc);
36757 if (ia_vcc == NULL)
36758 {
36759 - atomic_inc(&vcc->stats->rx_err);
36760 + atomic_inc_unchecked(&vcc->stats->rx_err);
36761 atm_return(vcc, skb->truesize);
36762 dev_kfree_skb_any(skb);
36763 goto INCR_DLE;
36764 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36765 if ((length > iadev->rx_buf_sz) || (length >
36766 (skb->len - sizeof(struct cpcs_trailer))))
36767 {
36768 - atomic_inc(&vcc->stats->rx_err);
36769 + atomic_inc_unchecked(&vcc->stats->rx_err);
36770 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36771 length, skb->len);)
36772 atm_return(vcc, skb->truesize);
36773 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36774
36775 IF_RX(printk("rx_dle_intr: skb push");)
36776 vcc->push(vcc,skb);
36777 - atomic_inc(&vcc->stats->rx);
36778 + atomic_inc_unchecked(&vcc->stats->rx);
36779 iadev->rx_pkt_cnt++;
36780 }
36781 INCR_DLE:
36782 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36783 {
36784 struct k_sonet_stats *stats;
36785 stats = &PRIV(_ia_dev[board])->sonet_stats;
36786 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36787 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36788 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36789 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36790 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36791 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36792 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36793 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36794 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36795 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36796 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36797 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36798 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36799 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36800 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36801 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36802 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36803 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36804 }
36805 ia_cmds.status = 0;
36806 break;
36807 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36808 if ((desc == 0) || (desc > iadev->num_tx_desc))
36809 {
36810 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36811 - atomic_inc(&vcc->stats->tx);
36812 + atomic_inc_unchecked(&vcc->stats->tx);
36813 if (vcc->pop)
36814 vcc->pop(vcc, skb);
36815 else
36816 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36817 ATM_DESC(skb) = vcc->vci;
36818 skb_queue_tail(&iadev->tx_dma_q, skb);
36819
36820 - atomic_inc(&vcc->stats->tx);
36821 + atomic_inc_unchecked(&vcc->stats->tx);
36822 iadev->tx_pkt_cnt++;
36823 /* Increment transaction counter */
36824 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36825
36826 #if 0
36827 /* add flow control logic */
36828 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36829 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36830 if (iavcc->vc_desc_cnt > 10) {
36831 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36832 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36833 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36834 index fa7d701..1e404c7 100644
36835 --- a/drivers/atm/lanai.c
36836 +++ b/drivers/atm/lanai.c
36837 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36838 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36839 lanai_endtx(lanai, lvcc);
36840 lanai_free_skb(lvcc->tx.atmvcc, skb);
36841 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36842 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36843 }
36844
36845 /* Try to fill the buffer - don't call unless there is backlog */
36846 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36847 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36848 __net_timestamp(skb);
36849 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36850 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36851 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36852 out:
36853 lvcc->rx.buf.ptr = end;
36854 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36855 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36856 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36857 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36858 lanai->stats.service_rxnotaal5++;
36859 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36860 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36861 return 0;
36862 }
36863 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36864 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36865 int bytes;
36866 read_unlock(&vcc_sklist_lock);
36867 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36868 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36869 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36870 lvcc->stats.x.aal5.service_trash++;
36871 bytes = (SERVICE_GET_END(s) * 16) -
36872 (((unsigned long) lvcc->rx.buf.ptr) -
36873 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36874 }
36875 if (s & SERVICE_STREAM) {
36876 read_unlock(&vcc_sklist_lock);
36877 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36878 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36879 lvcc->stats.x.aal5.service_stream++;
36880 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36881 "PDU on VCI %d!\n", lanai->number, vci);
36882 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36883 return 0;
36884 }
36885 DPRINTK("got rx crc error on vci %d\n", vci);
36886 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36887 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36888 lvcc->stats.x.aal5.service_rxcrc++;
36889 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36890 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36891 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36892 index 5aca5f4..ce3a6b0 100644
36893 --- a/drivers/atm/nicstar.c
36894 +++ b/drivers/atm/nicstar.c
36895 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36896 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36897 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36898 card->index);
36899 - atomic_inc(&vcc->stats->tx_err);
36900 + atomic_inc_unchecked(&vcc->stats->tx_err);
36901 dev_kfree_skb_any(skb);
36902 return -EINVAL;
36903 }
36904 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36905 if (!vc->tx) {
36906 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36907 card->index);
36908 - atomic_inc(&vcc->stats->tx_err);
36909 + atomic_inc_unchecked(&vcc->stats->tx_err);
36910 dev_kfree_skb_any(skb);
36911 return -EINVAL;
36912 }
36913 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36914 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36915 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36916 card->index);
36917 - atomic_inc(&vcc->stats->tx_err);
36918 + atomic_inc_unchecked(&vcc->stats->tx_err);
36919 dev_kfree_skb_any(skb);
36920 return -EINVAL;
36921 }
36922
36923 if (skb_shinfo(skb)->nr_frags != 0) {
36924 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36925 - atomic_inc(&vcc->stats->tx_err);
36926 + atomic_inc_unchecked(&vcc->stats->tx_err);
36927 dev_kfree_skb_any(skb);
36928 return -EINVAL;
36929 }
36930 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36931 }
36932
36933 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36934 - atomic_inc(&vcc->stats->tx_err);
36935 + atomic_inc_unchecked(&vcc->stats->tx_err);
36936 dev_kfree_skb_any(skb);
36937 return -EIO;
36938 }
36939 - atomic_inc(&vcc->stats->tx);
36940 + atomic_inc_unchecked(&vcc->stats->tx);
36941
36942 return 0;
36943 }
36944 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36945 printk
36946 ("nicstar%d: Can't allocate buffers for aal0.\n",
36947 card->index);
36948 - atomic_add(i, &vcc->stats->rx_drop);
36949 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36950 break;
36951 }
36952 if (!atm_charge(vcc, sb->truesize)) {
36953 RXPRINTK
36954 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36955 card->index);
36956 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36957 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36958 dev_kfree_skb_any(sb);
36959 break;
36960 }
36961 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36962 ATM_SKB(sb)->vcc = vcc;
36963 __net_timestamp(sb);
36964 vcc->push(vcc, sb);
36965 - atomic_inc(&vcc->stats->rx);
36966 + atomic_inc_unchecked(&vcc->stats->rx);
36967 cell += ATM_CELL_PAYLOAD;
36968 }
36969
36970 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36971 if (iovb == NULL) {
36972 printk("nicstar%d: Out of iovec buffers.\n",
36973 card->index);
36974 - atomic_inc(&vcc->stats->rx_drop);
36975 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36976 recycle_rx_buf(card, skb);
36977 return;
36978 }
36979 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36980 small or large buffer itself. */
36981 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36982 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36983 - atomic_inc(&vcc->stats->rx_err);
36984 + atomic_inc_unchecked(&vcc->stats->rx_err);
36985 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36986 NS_MAX_IOVECS);
36987 NS_PRV_IOVCNT(iovb) = 0;
36988 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36989 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36990 card->index);
36991 which_list(card, skb);
36992 - atomic_inc(&vcc->stats->rx_err);
36993 + atomic_inc_unchecked(&vcc->stats->rx_err);
36994 recycle_rx_buf(card, skb);
36995 vc->rx_iov = NULL;
36996 recycle_iov_buf(card, iovb);
36997 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36998 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36999 card->index);
37000 which_list(card, skb);
37001 - atomic_inc(&vcc->stats->rx_err);
37002 + atomic_inc_unchecked(&vcc->stats->rx_err);
37003 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37004 NS_PRV_IOVCNT(iovb));
37005 vc->rx_iov = NULL;
37006 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37007 printk(" - PDU size mismatch.\n");
37008 else
37009 printk(".\n");
37010 - atomic_inc(&vcc->stats->rx_err);
37011 + atomic_inc_unchecked(&vcc->stats->rx_err);
37012 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37013 NS_PRV_IOVCNT(iovb));
37014 vc->rx_iov = NULL;
37015 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37016 /* skb points to a small buffer */
37017 if (!atm_charge(vcc, skb->truesize)) {
37018 push_rxbufs(card, skb);
37019 - atomic_inc(&vcc->stats->rx_drop);
37020 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37021 } else {
37022 skb_put(skb, len);
37023 dequeue_sm_buf(card, skb);
37024 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37025 ATM_SKB(skb)->vcc = vcc;
37026 __net_timestamp(skb);
37027 vcc->push(vcc, skb);
37028 - atomic_inc(&vcc->stats->rx);
37029 + atomic_inc_unchecked(&vcc->stats->rx);
37030 }
37031 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37032 struct sk_buff *sb;
37033 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37034 if (len <= NS_SMBUFSIZE) {
37035 if (!atm_charge(vcc, sb->truesize)) {
37036 push_rxbufs(card, sb);
37037 - atomic_inc(&vcc->stats->rx_drop);
37038 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37039 } else {
37040 skb_put(sb, len);
37041 dequeue_sm_buf(card, sb);
37042 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37043 ATM_SKB(sb)->vcc = vcc;
37044 __net_timestamp(sb);
37045 vcc->push(vcc, sb);
37046 - atomic_inc(&vcc->stats->rx);
37047 + atomic_inc_unchecked(&vcc->stats->rx);
37048 }
37049
37050 push_rxbufs(card, skb);
37051 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37052
37053 if (!atm_charge(vcc, skb->truesize)) {
37054 push_rxbufs(card, skb);
37055 - atomic_inc(&vcc->stats->rx_drop);
37056 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37057 } else {
37058 dequeue_lg_buf(card, skb);
37059 #ifdef NS_USE_DESTRUCTORS
37060 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37061 ATM_SKB(skb)->vcc = vcc;
37062 __net_timestamp(skb);
37063 vcc->push(vcc, skb);
37064 - atomic_inc(&vcc->stats->rx);
37065 + atomic_inc_unchecked(&vcc->stats->rx);
37066 }
37067
37068 push_rxbufs(card, sb);
37069 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37070 printk
37071 ("nicstar%d: Out of huge buffers.\n",
37072 card->index);
37073 - atomic_inc(&vcc->stats->rx_drop);
37074 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37075 recycle_iovec_rx_bufs(card,
37076 (struct iovec *)
37077 iovb->data,
37078 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37079 card->hbpool.count++;
37080 } else
37081 dev_kfree_skb_any(hb);
37082 - atomic_inc(&vcc->stats->rx_drop);
37083 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37084 } else {
37085 /* Copy the small buffer to the huge buffer */
37086 sb = (struct sk_buff *)iov->iov_base;
37087 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37088 #endif /* NS_USE_DESTRUCTORS */
37089 __net_timestamp(hb);
37090 vcc->push(vcc, hb);
37091 - atomic_inc(&vcc->stats->rx);
37092 + atomic_inc_unchecked(&vcc->stats->rx);
37093 }
37094 }
37095
37096 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37097 index 32784d1..4a8434a 100644
37098 --- a/drivers/atm/solos-pci.c
37099 +++ b/drivers/atm/solos-pci.c
37100 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37101 }
37102 atm_charge(vcc, skb->truesize);
37103 vcc->push(vcc, skb);
37104 - atomic_inc(&vcc->stats->rx);
37105 + atomic_inc_unchecked(&vcc->stats->rx);
37106 break;
37107
37108 case PKT_STATUS:
37109 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37110 vcc = SKB_CB(oldskb)->vcc;
37111
37112 if (vcc) {
37113 - atomic_inc(&vcc->stats->tx);
37114 + atomic_inc_unchecked(&vcc->stats->tx);
37115 solos_pop(vcc, oldskb);
37116 } else {
37117 dev_kfree_skb_irq(oldskb);
37118 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37119 index 0215934..ce9f5b1 100644
37120 --- a/drivers/atm/suni.c
37121 +++ b/drivers/atm/suni.c
37122 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37123
37124
37125 #define ADD_LIMITED(s,v) \
37126 - atomic_add((v),&stats->s); \
37127 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37128 + atomic_add_unchecked((v),&stats->s); \
37129 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37130
37131
37132 static void suni_hz(unsigned long from_timer)
37133 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37134 index 5120a96..e2572bd 100644
37135 --- a/drivers/atm/uPD98402.c
37136 +++ b/drivers/atm/uPD98402.c
37137 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37138 struct sonet_stats tmp;
37139 int error = 0;
37140
37141 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37142 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37143 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37144 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37145 if (zero && !error) {
37146 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37147
37148
37149 #define ADD_LIMITED(s,v) \
37150 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37151 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37152 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37153 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37154 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37155 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37156
37157
37158 static void stat_event(struct atm_dev *dev)
37159 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37160 if (reason & uPD98402_INT_PFM) stat_event(dev);
37161 if (reason & uPD98402_INT_PCO) {
37162 (void) GET(PCOCR); /* clear interrupt cause */
37163 - atomic_add(GET(HECCT),
37164 + atomic_add_unchecked(GET(HECCT),
37165 &PRIV(dev)->sonet_stats.uncorr_hcs);
37166 }
37167 if ((reason & uPD98402_INT_RFO) &&
37168 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37169 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37170 uPD98402_INT_LOS),PIMR); /* enable them */
37171 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37172 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37173 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37174 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37175 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37176 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37177 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37178 return 0;
37179 }
37180
37181 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37182 index 969c3c2..9b72956 100644
37183 --- a/drivers/atm/zatm.c
37184 +++ b/drivers/atm/zatm.c
37185 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37186 }
37187 if (!size) {
37188 dev_kfree_skb_irq(skb);
37189 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37190 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37191 continue;
37192 }
37193 if (!atm_charge(vcc,skb->truesize)) {
37194 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37195 skb->len = size;
37196 ATM_SKB(skb)->vcc = vcc;
37197 vcc->push(vcc,skb);
37198 - atomic_inc(&vcc->stats->rx);
37199 + atomic_inc_unchecked(&vcc->stats->rx);
37200 }
37201 zout(pos & 0xffff,MTA(mbx));
37202 #if 0 /* probably a stupid idea */
37203 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37204 skb_queue_head(&zatm_vcc->backlog,skb);
37205 break;
37206 }
37207 - atomic_inc(&vcc->stats->tx);
37208 + atomic_inc_unchecked(&vcc->stats->tx);
37209 wake_up(&zatm_vcc->tx_wait);
37210 }
37211
37212 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37213 index 73f6c29..b0c0e13 100644
37214 --- a/drivers/base/bus.c
37215 +++ b/drivers/base/bus.c
37216 @@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37217 return -EINVAL;
37218
37219 mutex_lock(&subsys->p->mutex);
37220 - list_add_tail(&sif->node, &subsys->p->interfaces);
37221 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37222 if (sif->add_dev) {
37223 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37224 while ((dev = subsys_dev_iter_next(&iter)))
37225 @@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37226 subsys = sif->subsys;
37227
37228 mutex_lock(&subsys->p->mutex);
37229 - list_del_init(&sif->node);
37230 + pax_list_del_init((struct list_head *)&sif->node);
37231 if (sif->remove_dev) {
37232 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37233 while ((dev = subsys_dev_iter_next(&iter)))
37234 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37235 index 0f38201..6c2b444 100644
37236 --- a/drivers/base/devtmpfs.c
37237 +++ b/drivers/base/devtmpfs.c
37238 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37239 if (!thread)
37240 return 0;
37241
37242 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37243 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37244 if (err)
37245 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37246 else
37247 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37248 *err = sys_unshare(CLONE_NEWNS);
37249 if (*err)
37250 goto out;
37251 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37252 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37253 if (*err)
37254 goto out;
37255 - sys_chdir("/.."); /* will traverse into overmounted root */
37256 - sys_chroot(".");
37257 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37258 + sys_chroot((char __force_user *)".");
37259 complete(&setup_done);
37260 while (1) {
37261 spin_lock(&req_lock);
37262 diff --git a/drivers/base/node.c b/drivers/base/node.c
37263 index bc9f43b..29703b8 100644
37264 --- a/drivers/base/node.c
37265 +++ b/drivers/base/node.c
37266 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37267 struct node_attr {
37268 struct device_attribute attr;
37269 enum node_states state;
37270 -};
37271 +} __do_const;
37272
37273 static ssize_t show_node_state(struct device *dev,
37274 struct device_attribute *attr, char *buf)
37275 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37276 index bfb8955..4ebff34 100644
37277 --- a/drivers/base/power/domain.c
37278 +++ b/drivers/base/power/domain.c
37279 @@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37280
37281 if (dev->power.subsys_data->domain_data) {
37282 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37283 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37284 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37285 if (clear_td)
37286 - gpd_data->td = (struct gpd_timing_data){ 0 };
37287 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37288
37289 if (--gpd_data->refcount == 0) {
37290 dev->power.subsys_data->domain_data = NULL;
37291 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37292 {
37293 struct cpuidle_driver *cpuidle_drv;
37294 struct gpd_cpu_data *cpu_data;
37295 - struct cpuidle_state *idle_state;
37296 + cpuidle_state_no_const *idle_state;
37297 int ret = 0;
37298
37299 if (IS_ERR_OR_NULL(genpd) || state < 0)
37300 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37301 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37302 {
37303 struct gpd_cpu_data *cpu_data;
37304 - struct cpuidle_state *idle_state;
37305 + cpuidle_state_no_const *idle_state;
37306 int ret = 0;
37307
37308 if (IS_ERR_OR_NULL(genpd))
37309 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37310 index 03e089a..0e9560c 100644
37311 --- a/drivers/base/power/sysfs.c
37312 +++ b/drivers/base/power/sysfs.c
37313 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37314 return -EIO;
37315 }
37316 }
37317 - return sprintf(buf, p);
37318 + return sprintf(buf, "%s", p);
37319 }
37320
37321 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37322 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37323 index 2d56f41..8830f19 100644
37324 --- a/drivers/base/power/wakeup.c
37325 +++ b/drivers/base/power/wakeup.c
37326 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37327 * They need to be modified together atomically, so it's better to use one
37328 * atomic variable to hold them both.
37329 */
37330 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37331 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37332
37333 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37334 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37335
37336 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37337 {
37338 - unsigned int comb = atomic_read(&combined_event_count);
37339 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37340
37341 *cnt = (comb >> IN_PROGRESS_BITS);
37342 *inpr = comb & MAX_IN_PROGRESS;
37343 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37344 ws->start_prevent_time = ws->last_time;
37345
37346 /* Increment the counter of events in progress. */
37347 - cec = atomic_inc_return(&combined_event_count);
37348 + cec = atomic_inc_return_unchecked(&combined_event_count);
37349
37350 trace_wakeup_source_activate(ws->name, cec);
37351 }
37352 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37353 * Increment the counter of registered wakeup events and decrement the
37354 * couter of wakeup events in progress simultaneously.
37355 */
37356 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37357 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37358 trace_wakeup_source_deactivate(ws->name, cec);
37359
37360 split_counters(&cnt, &inpr);
37361 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37362 index e8d11b6..7b1b36f 100644
37363 --- a/drivers/base/syscore.c
37364 +++ b/drivers/base/syscore.c
37365 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37366 void register_syscore_ops(struct syscore_ops *ops)
37367 {
37368 mutex_lock(&syscore_ops_lock);
37369 - list_add_tail(&ops->node, &syscore_ops_list);
37370 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37371 mutex_unlock(&syscore_ops_lock);
37372 }
37373 EXPORT_SYMBOL_GPL(register_syscore_ops);
37374 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37375 void unregister_syscore_ops(struct syscore_ops *ops)
37376 {
37377 mutex_lock(&syscore_ops_lock);
37378 - list_del(&ops->node);
37379 + pax_list_del((struct list_head *)&ops->node);
37380 mutex_unlock(&syscore_ops_lock);
37381 }
37382 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37383 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37384 index b35fc4f..c902870 100644
37385 --- a/drivers/block/cciss.c
37386 +++ b/drivers/block/cciss.c
37387 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37388 while (!list_empty(&h->reqQ)) {
37389 c = list_entry(h->reqQ.next, CommandList_struct, list);
37390 /* can't do anything if fifo is full */
37391 - if ((h->access.fifo_full(h))) {
37392 + if ((h->access->fifo_full(h))) {
37393 dev_warn(&h->pdev->dev, "fifo full\n");
37394 break;
37395 }
37396 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37397 h->Qdepth--;
37398
37399 /* Tell the controller execute command */
37400 - h->access.submit_command(h, c);
37401 + h->access->submit_command(h, c);
37402
37403 /* Put job onto the completed Q */
37404 addQ(&h->cmpQ, c);
37405 @@ -3447,17 +3447,17 @@ startio:
37406
37407 static inline unsigned long get_next_completion(ctlr_info_t *h)
37408 {
37409 - return h->access.command_completed(h);
37410 + return h->access->command_completed(h);
37411 }
37412
37413 static inline int interrupt_pending(ctlr_info_t *h)
37414 {
37415 - return h->access.intr_pending(h);
37416 + return h->access->intr_pending(h);
37417 }
37418
37419 static inline long interrupt_not_for_us(ctlr_info_t *h)
37420 {
37421 - return ((h->access.intr_pending(h) == 0) ||
37422 + return ((h->access->intr_pending(h) == 0) ||
37423 (h->interrupts_enabled == 0));
37424 }
37425
37426 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37427 u32 a;
37428
37429 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37430 - return h->access.command_completed(h);
37431 + return h->access->command_completed(h);
37432
37433 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37434 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37435 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37436 trans_support & CFGTBL_Trans_use_short_tags);
37437
37438 /* Change the access methods to the performant access methods */
37439 - h->access = SA5_performant_access;
37440 + h->access = &SA5_performant_access;
37441 h->transMethod = CFGTBL_Trans_Performant;
37442
37443 return;
37444 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37445 if (prod_index < 0)
37446 return -ENODEV;
37447 h->product_name = products[prod_index].product_name;
37448 - h->access = *(products[prod_index].access);
37449 + h->access = products[prod_index].access;
37450
37451 if (cciss_board_disabled(h)) {
37452 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37453 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37454 }
37455
37456 /* make sure the board interrupts are off */
37457 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37458 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37459 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37460 if (rc)
37461 goto clean2;
37462 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37463 * fake ones to scoop up any residual completions.
37464 */
37465 spin_lock_irqsave(&h->lock, flags);
37466 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37467 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37468 spin_unlock_irqrestore(&h->lock, flags);
37469 free_irq(h->intr[h->intr_mode], h);
37470 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37471 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37472 dev_info(&h->pdev->dev, "Board READY.\n");
37473 dev_info(&h->pdev->dev,
37474 "Waiting for stale completions to drain.\n");
37475 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37476 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37477 msleep(10000);
37478 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37479 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37480
37481 rc = controller_reset_failed(h->cfgtable);
37482 if (rc)
37483 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37484 cciss_scsi_setup(h);
37485
37486 /* Turn the interrupts on so we can service requests */
37487 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37488 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37489
37490 /* Get the firmware version */
37491 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37492 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37493 kfree(flush_buf);
37494 if (return_code != IO_OK)
37495 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37496 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37497 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37498 free_irq(h->intr[h->intr_mode], h);
37499 }
37500
37501 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37502 index 7fda30e..2f27946 100644
37503 --- a/drivers/block/cciss.h
37504 +++ b/drivers/block/cciss.h
37505 @@ -101,7 +101,7 @@ struct ctlr_info
37506 /* information about each logical volume */
37507 drive_info_struct *drv[CISS_MAX_LUN];
37508
37509 - struct access_method access;
37510 + struct access_method *access;
37511
37512 /* queue and queue Info */
37513 struct list_head reqQ;
37514 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37515 }
37516
37517 static struct access_method SA5_access = {
37518 - SA5_submit_command,
37519 - SA5_intr_mask,
37520 - SA5_fifo_full,
37521 - SA5_intr_pending,
37522 - SA5_completed,
37523 + .submit_command = SA5_submit_command,
37524 + .set_intr_mask = SA5_intr_mask,
37525 + .fifo_full = SA5_fifo_full,
37526 + .intr_pending = SA5_intr_pending,
37527 + .command_completed = SA5_completed,
37528 };
37529
37530 static struct access_method SA5B_access = {
37531 - SA5_submit_command,
37532 - SA5B_intr_mask,
37533 - SA5_fifo_full,
37534 - SA5B_intr_pending,
37535 - SA5_completed,
37536 + .submit_command = SA5_submit_command,
37537 + .set_intr_mask = SA5B_intr_mask,
37538 + .fifo_full = SA5_fifo_full,
37539 + .intr_pending = SA5B_intr_pending,
37540 + .command_completed = SA5_completed,
37541 };
37542
37543 static struct access_method SA5_performant_access = {
37544 - SA5_submit_command,
37545 - SA5_performant_intr_mask,
37546 - SA5_fifo_full,
37547 - SA5_performant_intr_pending,
37548 - SA5_performant_completed,
37549 + .submit_command = SA5_submit_command,
37550 + .set_intr_mask = SA5_performant_intr_mask,
37551 + .fifo_full = SA5_fifo_full,
37552 + .intr_pending = SA5_performant_intr_pending,
37553 + .command_completed = SA5_performant_completed,
37554 };
37555
37556 struct board_type {
37557 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37558 index 2b94403..fd6ad1f 100644
37559 --- a/drivers/block/cpqarray.c
37560 +++ b/drivers/block/cpqarray.c
37561 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37562 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37563 goto Enomem4;
37564 }
37565 - hba[i]->access.set_intr_mask(hba[i], 0);
37566 + hba[i]->access->set_intr_mask(hba[i], 0);
37567 if (request_irq(hba[i]->intr, do_ida_intr,
37568 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37569 {
37570 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37571 add_timer(&hba[i]->timer);
37572
37573 /* Enable IRQ now that spinlock and rate limit timer are set up */
37574 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37575 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37576
37577 for(j=0; j<NWD; j++) {
37578 struct gendisk *disk = ida_gendisk[i][j];
37579 @@ -694,7 +694,7 @@ DBGINFO(
37580 for(i=0; i<NR_PRODUCTS; i++) {
37581 if (board_id == products[i].board_id) {
37582 c->product_name = products[i].product_name;
37583 - c->access = *(products[i].access);
37584 + c->access = products[i].access;
37585 break;
37586 }
37587 }
37588 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37589 hba[ctlr]->intr = intr;
37590 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37591 hba[ctlr]->product_name = products[j].product_name;
37592 - hba[ctlr]->access = *(products[j].access);
37593 + hba[ctlr]->access = products[j].access;
37594 hba[ctlr]->ctlr = ctlr;
37595 hba[ctlr]->board_id = board_id;
37596 hba[ctlr]->pci_dev = NULL; /* not PCI */
37597 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37598
37599 while((c = h->reqQ) != NULL) {
37600 /* Can't do anything if we're busy */
37601 - if (h->access.fifo_full(h) == 0)
37602 + if (h->access->fifo_full(h) == 0)
37603 return;
37604
37605 /* Get the first entry from the request Q */
37606 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37607 h->Qdepth--;
37608
37609 /* Tell the controller to do our bidding */
37610 - h->access.submit_command(h, c);
37611 + h->access->submit_command(h, c);
37612
37613 /* Get onto the completion Q */
37614 addQ(&h->cmpQ, c);
37615 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37616 unsigned long flags;
37617 __u32 a,a1;
37618
37619 - istat = h->access.intr_pending(h);
37620 + istat = h->access->intr_pending(h);
37621 /* Is this interrupt for us? */
37622 if (istat == 0)
37623 return IRQ_NONE;
37624 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37625 */
37626 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37627 if (istat & FIFO_NOT_EMPTY) {
37628 - while((a = h->access.command_completed(h))) {
37629 + while((a = h->access->command_completed(h))) {
37630 a1 = a; a &= ~3;
37631 if ((c = h->cmpQ) == NULL)
37632 {
37633 @@ -1448,11 +1448,11 @@ static int sendcmd(
37634 /*
37635 * Disable interrupt
37636 */
37637 - info_p->access.set_intr_mask(info_p, 0);
37638 + info_p->access->set_intr_mask(info_p, 0);
37639 /* Make sure there is room in the command FIFO */
37640 /* Actually it should be completely empty at this time. */
37641 for (i = 200000; i > 0; i--) {
37642 - temp = info_p->access.fifo_full(info_p);
37643 + temp = info_p->access->fifo_full(info_p);
37644 if (temp != 0) {
37645 break;
37646 }
37647 @@ -1465,7 +1465,7 @@ DBG(
37648 /*
37649 * Send the cmd
37650 */
37651 - info_p->access.submit_command(info_p, c);
37652 + info_p->access->submit_command(info_p, c);
37653 complete = pollcomplete(ctlr);
37654
37655 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37656 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37657 * we check the new geometry. Then turn interrupts back on when
37658 * we're done.
37659 */
37660 - host->access.set_intr_mask(host, 0);
37661 + host->access->set_intr_mask(host, 0);
37662 getgeometry(ctlr);
37663 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37664 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37665
37666 for(i=0; i<NWD; i++) {
37667 struct gendisk *disk = ida_gendisk[ctlr][i];
37668 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37669 /* Wait (up to 2 seconds) for a command to complete */
37670
37671 for (i = 200000; i > 0; i--) {
37672 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37673 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37674 if (done == 0) {
37675 udelay(10); /* a short fixed delay */
37676 } else
37677 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37678 index be73e9d..7fbf140 100644
37679 --- a/drivers/block/cpqarray.h
37680 +++ b/drivers/block/cpqarray.h
37681 @@ -99,7 +99,7 @@ struct ctlr_info {
37682 drv_info_t drv[NWD];
37683 struct proc_dir_entry *proc;
37684
37685 - struct access_method access;
37686 + struct access_method *access;
37687
37688 cmdlist_t *reqQ;
37689 cmdlist_t *cmpQ;
37690 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37691 index 0e06f0c..c47b81d 100644
37692 --- a/drivers/block/drbd/drbd_int.h
37693 +++ b/drivers/block/drbd/drbd_int.h
37694 @@ -582,7 +582,7 @@ struct drbd_epoch {
37695 struct drbd_tconn *tconn;
37696 struct list_head list;
37697 unsigned int barrier_nr;
37698 - atomic_t epoch_size; /* increased on every request added. */
37699 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37700 atomic_t active; /* increased on every req. added, and dec on every finished. */
37701 unsigned long flags;
37702 };
37703 @@ -1022,7 +1022,7 @@ struct drbd_conf {
37704 unsigned int al_tr_number;
37705 int al_tr_cycle;
37706 wait_queue_head_t seq_wait;
37707 - atomic_t packet_seq;
37708 + atomic_unchecked_t packet_seq;
37709 unsigned int peer_seq;
37710 spinlock_t peer_seq_lock;
37711 unsigned int minor;
37712 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37713 char __user *uoptval;
37714 int err;
37715
37716 - uoptval = (char __user __force *)optval;
37717 + uoptval = (char __force_user *)optval;
37718
37719 set_fs(KERNEL_DS);
37720 if (level == SOL_SOCKET)
37721 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37722 index 89c497c..9c736ae 100644
37723 --- a/drivers/block/drbd/drbd_interval.c
37724 +++ b/drivers/block/drbd/drbd_interval.c
37725 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37726 }
37727
37728 static const struct rb_augment_callbacks augment_callbacks = {
37729 - augment_propagate,
37730 - augment_copy,
37731 - augment_rotate,
37732 + .propagate = augment_propagate,
37733 + .copy = augment_copy,
37734 + .rotate = augment_rotate,
37735 };
37736
37737 /**
37738 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37739 index 9e3818b..7b64c92 100644
37740 --- a/drivers/block/drbd/drbd_main.c
37741 +++ b/drivers/block/drbd/drbd_main.c
37742 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37743 p->sector = sector;
37744 p->block_id = block_id;
37745 p->blksize = blksize;
37746 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37747 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37748 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37749 }
37750
37751 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37752 return -EIO;
37753 p->sector = cpu_to_be64(req->i.sector);
37754 p->block_id = (unsigned long)req;
37755 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37756 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37757 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37758 if (mdev->state.conn >= C_SYNC_SOURCE &&
37759 mdev->state.conn <= C_PAUSED_SYNC_T)
37760 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37761 {
37762 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37763
37764 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37765 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37766 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37767 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37768 kfree(tconn->current_epoch);
37769
37770 idr_destroy(&tconn->volumes);
37771 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37772 index c706d50..5e1b472 100644
37773 --- a/drivers/block/drbd/drbd_nl.c
37774 +++ b/drivers/block/drbd/drbd_nl.c
37775 @@ -3440,7 +3440,7 @@ out:
37776
37777 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37778 {
37779 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37780 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37781 struct sk_buff *msg;
37782 struct drbd_genlmsghdr *d_out;
37783 unsigned seq;
37784 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37785 return;
37786 }
37787
37788 - seq = atomic_inc_return(&drbd_genl_seq);
37789 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37790 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37791 if (!msg)
37792 goto failed;
37793 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37794 index 6fa6673..b7f97e9 100644
37795 --- a/drivers/block/drbd/drbd_receiver.c
37796 +++ b/drivers/block/drbd/drbd_receiver.c
37797 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37798 {
37799 int err;
37800
37801 - atomic_set(&mdev->packet_seq, 0);
37802 + atomic_set_unchecked(&mdev->packet_seq, 0);
37803 mdev->peer_seq = 0;
37804
37805 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37806 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37807 do {
37808 next_epoch = NULL;
37809
37810 - epoch_size = atomic_read(&epoch->epoch_size);
37811 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37812
37813 switch (ev & ~EV_CLEANUP) {
37814 case EV_PUT:
37815 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37816 rv = FE_DESTROYED;
37817 } else {
37818 epoch->flags = 0;
37819 - atomic_set(&epoch->epoch_size, 0);
37820 + atomic_set_unchecked(&epoch->epoch_size, 0);
37821 /* atomic_set(&epoch->active, 0); is already zero */
37822 if (rv == FE_STILL_LIVE)
37823 rv = FE_RECYCLED;
37824 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37825 conn_wait_active_ee_empty(tconn);
37826 drbd_flush(tconn);
37827
37828 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37829 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37830 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37831 if (epoch)
37832 break;
37833 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37834 }
37835
37836 epoch->flags = 0;
37837 - atomic_set(&epoch->epoch_size, 0);
37838 + atomic_set_unchecked(&epoch->epoch_size, 0);
37839 atomic_set(&epoch->active, 0);
37840
37841 spin_lock(&tconn->epoch_lock);
37842 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37843 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37844 list_add(&epoch->list, &tconn->current_epoch->list);
37845 tconn->current_epoch = epoch;
37846 tconn->epochs++;
37847 @@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37848
37849 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37850 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37851 - atomic_inc(&tconn->current_epoch->epoch_size);
37852 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37853 err2 = drbd_drain_block(mdev, pi->size);
37854 if (!err)
37855 err = err2;
37856 @@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37857
37858 spin_lock(&tconn->epoch_lock);
37859 peer_req->epoch = tconn->current_epoch;
37860 - atomic_inc(&peer_req->epoch->epoch_size);
37861 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37862 atomic_inc(&peer_req->epoch->active);
37863 spin_unlock(&tconn->epoch_lock);
37864
37865 @@ -4344,7 +4344,7 @@ struct data_cmd {
37866 int expect_payload;
37867 size_t pkt_size;
37868 int (*fn)(struct drbd_tconn *, struct packet_info *);
37869 -};
37870 +} __do_const;
37871
37872 static struct data_cmd drbd_cmd_handler[] = {
37873 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37874 @@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37875 if (!list_empty(&tconn->current_epoch->list))
37876 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37877 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37878 - atomic_set(&tconn->current_epoch->epoch_size, 0);
37879 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37880 tconn->send.seen_any_write_yet = false;
37881
37882 conn_info(tconn, "Connection closed\n");
37883 @@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37884 struct asender_cmd {
37885 size_t pkt_size;
37886 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37887 -};
37888 +} __do_const;
37889
37890 static struct asender_cmd asender_tbl[] = {
37891 [P_PING] = { 0, got_Ping },
37892 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37893 index c8dac73..1800093 100644
37894 --- a/drivers/block/loop.c
37895 +++ b/drivers/block/loop.c
37896 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37897
37898 file_start_write(file);
37899 set_fs(get_ds());
37900 - bw = file->f_op->write(file, buf, len, &pos);
37901 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37902 set_fs(old_fs);
37903 file_end_write(file);
37904 if (likely(bw == len))
37905 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37906 index 83a598e..2de5ce3 100644
37907 --- a/drivers/block/null_blk.c
37908 +++ b/drivers/block/null_blk.c
37909 @@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37910 return 0;
37911 }
37912
37913 -static struct blk_mq_ops null_mq_ops = {
37914 - .queue_rq = null_queue_rq,
37915 - .map_queue = blk_mq_map_queue,
37916 +static struct blk_mq_ops null_mq_single_ops = {
37917 + .queue_rq = null_queue_rq,
37918 + .map_queue = blk_mq_map_queue,
37919 .init_hctx = null_init_hctx,
37920 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
37921 + .free_hctx = blk_mq_free_single_hw_queue,
37922 +};
37923 +
37924 +static struct blk_mq_ops null_mq_per_node_ops = {
37925 + .queue_rq = null_queue_rq,
37926 + .map_queue = blk_mq_map_queue,
37927 + .init_hctx = null_init_hctx,
37928 + .alloc_hctx = null_alloc_hctx,
37929 + .free_hctx = null_free_hctx,
37930 };
37931
37932 static struct blk_mq_reg null_mq_reg = {
37933 - .ops = &null_mq_ops,
37934 + .ops = &null_mq_single_ops,
37935 .queue_depth = 64,
37936 .cmd_size = sizeof(struct nullb_cmd),
37937 .flags = BLK_MQ_F_SHOULD_MERGE,
37938 @@ -545,13 +555,8 @@ static int null_add_dev(void)
37939 null_mq_reg.queue_depth = hw_queue_depth;
37940 null_mq_reg.nr_hw_queues = submit_queues;
37941
37942 - if (use_per_node_hctx) {
37943 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37944 - null_mq_reg.ops->free_hctx = null_free_hctx;
37945 - } else {
37946 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37947 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37948 - }
37949 + if (use_per_node_hctx)
37950 + null_mq_reg.ops = &null_mq_per_node_ops;
37951
37952 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37953 } else if (queue_mode == NULL_Q_BIO) {
37954 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37955 index ff8668c..f62167a 100644
37956 --- a/drivers/block/pktcdvd.c
37957 +++ b/drivers/block/pktcdvd.c
37958 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37959
37960 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37961 {
37962 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37963 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37964 }
37965
37966 /*
37967 @@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37968 return -EROFS;
37969 }
37970 pd->settings.fp = ti.fp;
37971 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37972 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37973
37974 if (ti.nwa_v) {
37975 pd->nwa = be32_to_cpu(ti.next_writable);
37976 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37977 index e5565fb..71be10b4 100644
37978 --- a/drivers/block/smart1,2.h
37979 +++ b/drivers/block/smart1,2.h
37980 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37981 }
37982
37983 static struct access_method smart4_access = {
37984 - smart4_submit_command,
37985 - smart4_intr_mask,
37986 - smart4_fifo_full,
37987 - smart4_intr_pending,
37988 - smart4_completed,
37989 + .submit_command = smart4_submit_command,
37990 + .set_intr_mask = smart4_intr_mask,
37991 + .fifo_full = smart4_fifo_full,
37992 + .intr_pending = smart4_intr_pending,
37993 + .command_completed = smart4_completed,
37994 };
37995
37996 /*
37997 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37998 }
37999
38000 static struct access_method smart2_access = {
38001 - smart2_submit_command,
38002 - smart2_intr_mask,
38003 - smart2_fifo_full,
38004 - smart2_intr_pending,
38005 - smart2_completed,
38006 + .submit_command = smart2_submit_command,
38007 + .set_intr_mask = smart2_intr_mask,
38008 + .fifo_full = smart2_fifo_full,
38009 + .intr_pending = smart2_intr_pending,
38010 + .command_completed = smart2_completed,
38011 };
38012
38013 /*
38014 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38015 }
38016
38017 static struct access_method smart2e_access = {
38018 - smart2e_submit_command,
38019 - smart2e_intr_mask,
38020 - smart2e_fifo_full,
38021 - smart2e_intr_pending,
38022 - smart2e_completed,
38023 + .submit_command = smart2e_submit_command,
38024 + .set_intr_mask = smart2e_intr_mask,
38025 + .fifo_full = smart2e_fifo_full,
38026 + .intr_pending = smart2e_intr_pending,
38027 + .command_completed = smart2e_completed,
38028 };
38029
38030 /*
38031 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38032 }
38033
38034 static struct access_method smart1_access = {
38035 - smart1_submit_command,
38036 - smart1_intr_mask,
38037 - smart1_fifo_full,
38038 - smart1_intr_pending,
38039 - smart1_completed,
38040 + .submit_command = smart1_submit_command,
38041 + .set_intr_mask = smart1_intr_mask,
38042 + .fifo_full = smart1_fifo_full,
38043 + .intr_pending = smart1_intr_pending,
38044 + .command_completed = smart1_completed,
38045 };
38046 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38047 index f038dba..bb74c08 100644
38048 --- a/drivers/bluetooth/btwilink.c
38049 +++ b/drivers/bluetooth/btwilink.c
38050 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38051
38052 static int bt_ti_probe(struct platform_device *pdev)
38053 {
38054 - static struct ti_st *hst;
38055 + struct ti_st *hst;
38056 struct hci_dev *hdev;
38057 int err;
38058
38059 diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
38060 index b6739cb..962fd35 100644
38061 --- a/drivers/bus/arm-cci.c
38062 +++ b/drivers/bus/arm-cci.c
38063 @@ -979,7 +979,7 @@ static int cci_probe(void)
38064
38065 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
38066
38067 - ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
38068 + ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
38069 if (!ports)
38070 return -ENOMEM;
38071
38072 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38073 index 8a3aff7..d7538c2 100644
38074 --- a/drivers/cdrom/cdrom.c
38075 +++ b/drivers/cdrom/cdrom.c
38076 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38077 ENSURE(reset, CDC_RESET);
38078 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38079 cdi->mc_flags = 0;
38080 - cdo->n_minors = 0;
38081 cdi->options = CDO_USE_FFLAGS;
38082
38083 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38084 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38085 else
38086 cdi->cdda_method = CDDA_OLD;
38087
38088 - if (!cdo->generic_packet)
38089 - cdo->generic_packet = cdrom_dummy_generic_packet;
38090 + if (!cdo->generic_packet) {
38091 + pax_open_kernel();
38092 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38093 + pax_close_kernel();
38094 + }
38095
38096 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38097 mutex_lock(&cdrom_mutex);
38098 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38099 if (cdi->exit)
38100 cdi->exit(cdi);
38101
38102 - cdi->ops->n_minors--;
38103 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38104 }
38105
38106 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38107 */
38108 nr = nframes;
38109 do {
38110 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38111 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38112 if (cgc.buffer)
38113 break;
38114
38115 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38116 struct cdrom_device_info *cdi;
38117 int ret;
38118
38119 - ret = scnprintf(info + *pos, max_size - *pos, header);
38120 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38121 if (!ret)
38122 return 1;
38123
38124 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38125 index 5980cb9..6d7bd7e 100644
38126 --- a/drivers/cdrom/gdrom.c
38127 +++ b/drivers/cdrom/gdrom.c
38128 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38129 .audio_ioctl = gdrom_audio_ioctl,
38130 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38131 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38132 - .n_minors = 1,
38133 };
38134
38135 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38136 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38137 index fa3243d..8c98297 100644
38138 --- a/drivers/char/Kconfig
38139 +++ b/drivers/char/Kconfig
38140 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38141
38142 config DEVKMEM
38143 bool "/dev/kmem virtual device support"
38144 - default y
38145 + default n
38146 + depends on !GRKERNSEC_KMEM
38147 help
38148 Say Y here if you want to support the /dev/kmem device. The
38149 /dev/kmem device is rarely used, but can be used for certain
38150 @@ -576,6 +577,7 @@ config DEVPORT
38151 bool
38152 depends on !M68K
38153 depends on ISA || PCI
38154 + depends on !GRKERNSEC_KMEM
38155 default y
38156
38157 source "drivers/s390/char/Kconfig"
38158 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38159 index a48e05b..6bac831 100644
38160 --- a/drivers/char/agp/compat_ioctl.c
38161 +++ b/drivers/char/agp/compat_ioctl.c
38162 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38163 return -ENOMEM;
38164 }
38165
38166 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38167 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38168 sizeof(*usegment) * ureserve.seg_count)) {
38169 kfree(usegment);
38170 kfree(ksegment);
38171 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38172 index 1b19239..b87b143 100644
38173 --- a/drivers/char/agp/frontend.c
38174 +++ b/drivers/char/agp/frontend.c
38175 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38176 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38177 return -EFAULT;
38178
38179 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38180 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38181 return -EFAULT;
38182
38183 client = agp_find_client_by_pid(reserve.pid);
38184 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38185 if (segment == NULL)
38186 return -ENOMEM;
38187
38188 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38189 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38190 sizeof(struct agp_segment) * reserve.seg_count)) {
38191 kfree(segment);
38192 return -EFAULT;
38193 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38194 index 4f94375..413694e 100644
38195 --- a/drivers/char/genrtc.c
38196 +++ b/drivers/char/genrtc.c
38197 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38198 switch (cmd) {
38199
38200 case RTC_PLL_GET:
38201 + memset(&pll, 0, sizeof(pll));
38202 if (get_rtc_pll(&pll))
38203 return -EINVAL;
38204 else
38205 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38206 index 5d9c31d..c94ccb5 100644
38207 --- a/drivers/char/hpet.c
38208 +++ b/drivers/char/hpet.c
38209 @@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38210 }
38211
38212 static int
38213 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38214 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38215 struct hpet_info *info)
38216 {
38217 struct hpet_timer __iomem *timer;
38218 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38219 index 86fe45c..c0ea948 100644
38220 --- a/drivers/char/hw_random/intel-rng.c
38221 +++ b/drivers/char/hw_random/intel-rng.c
38222 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38223
38224 if (no_fwh_detect)
38225 return -ENODEV;
38226 - printk(warning);
38227 + printk("%s", warning);
38228 return -EBUSY;
38229 }
38230
38231 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38232 index ec4e10f..f2a763b 100644
38233 --- a/drivers/char/ipmi/ipmi_msghandler.c
38234 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38235 @@ -420,7 +420,7 @@ struct ipmi_smi {
38236 struct proc_dir_entry *proc_dir;
38237 char proc_dir_name[10];
38238
38239 - atomic_t stats[IPMI_NUM_STATS];
38240 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38241
38242 /*
38243 * run_to_completion duplicate of smb_info, smi_info
38244 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38245
38246
38247 #define ipmi_inc_stat(intf, stat) \
38248 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38249 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38250 #define ipmi_get_stat(intf, stat) \
38251 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38252 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38253
38254 static int is_lan_addr(struct ipmi_addr *addr)
38255 {
38256 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38257 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38258 init_waitqueue_head(&intf->waitq);
38259 for (i = 0; i < IPMI_NUM_STATS; i++)
38260 - atomic_set(&intf->stats[i], 0);
38261 + atomic_set_unchecked(&intf->stats[i], 0);
38262
38263 intf->proc_dir = NULL;
38264
38265 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38266 index 15e4a60..b046093 100644
38267 --- a/drivers/char/ipmi/ipmi_si_intf.c
38268 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38269 @@ -280,7 +280,7 @@ struct smi_info {
38270 unsigned char slave_addr;
38271
38272 /* Counters and things for the proc filesystem. */
38273 - atomic_t stats[SI_NUM_STATS];
38274 + atomic_unchecked_t stats[SI_NUM_STATS];
38275
38276 struct task_struct *thread;
38277
38278 @@ -289,9 +289,9 @@ struct smi_info {
38279 };
38280
38281 #define smi_inc_stat(smi, stat) \
38282 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38283 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38284 #define smi_get_stat(smi, stat) \
38285 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38286 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38287
38288 #define SI_MAX_PARMS 4
38289
38290 @@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
38291 atomic_set(&new_smi->req_events, 0);
38292 new_smi->run_to_completion = 0;
38293 for (i = 0; i < SI_NUM_STATS; i++)
38294 - atomic_set(&new_smi->stats[i], 0);
38295 + atomic_set_unchecked(&new_smi->stats[i], 0);
38296
38297 new_smi->interrupt_disabled = 1;
38298 atomic_set(&new_smi->stop_operation, 0);
38299 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38300 index f895a8c..2bc9147 100644
38301 --- a/drivers/char/mem.c
38302 +++ b/drivers/char/mem.c
38303 @@ -18,6 +18,7 @@
38304 #include <linux/raw.h>
38305 #include <linux/tty.h>
38306 #include <linux/capability.h>
38307 +#include <linux/security.h>
38308 #include <linux/ptrace.h>
38309 #include <linux/device.h>
38310 #include <linux/highmem.h>
38311 @@ -37,6 +38,10 @@
38312
38313 #define DEVPORT_MINOR 4
38314
38315 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38316 +extern const struct file_operations grsec_fops;
38317 +#endif
38318 +
38319 static inline unsigned long size_inside_page(unsigned long start,
38320 unsigned long size)
38321 {
38322 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38323
38324 while (cursor < to) {
38325 if (!devmem_is_allowed(pfn)) {
38326 +#ifdef CONFIG_GRKERNSEC_KMEM
38327 + gr_handle_mem_readwrite(from, to);
38328 +#else
38329 printk(KERN_INFO
38330 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38331 current->comm, from, to);
38332 +#endif
38333 return 0;
38334 }
38335 cursor += PAGE_SIZE;
38336 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38337 }
38338 return 1;
38339 }
38340 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38341 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38342 +{
38343 + return 0;
38344 +}
38345 #else
38346 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38347 {
38348 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38349
38350 while (count > 0) {
38351 unsigned long remaining;
38352 + char *temp;
38353
38354 sz = size_inside_page(p, count);
38355
38356 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38357 if (!ptr)
38358 return -EFAULT;
38359
38360 - remaining = copy_to_user(buf, ptr, sz);
38361 +#ifdef CONFIG_PAX_USERCOPY
38362 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38363 + if (!temp) {
38364 + unxlate_dev_mem_ptr(p, ptr);
38365 + return -ENOMEM;
38366 + }
38367 + memcpy(temp, ptr, sz);
38368 +#else
38369 + temp = ptr;
38370 +#endif
38371 +
38372 + remaining = copy_to_user(buf, temp, sz);
38373 +
38374 +#ifdef CONFIG_PAX_USERCOPY
38375 + kfree(temp);
38376 +#endif
38377 +
38378 unxlate_dev_mem_ptr(p, ptr);
38379 if (remaining)
38380 return -EFAULT;
38381 @@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38382 size_t count, loff_t *ppos)
38383 {
38384 unsigned long p = *ppos;
38385 - ssize_t low_count, read, sz;
38386 + ssize_t low_count, read, sz, err = 0;
38387 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38388 - int err = 0;
38389
38390 read = 0;
38391 if (p < (unsigned long) high_memory) {
38392 @@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38393 }
38394 #endif
38395 while (low_count > 0) {
38396 + char *temp;
38397 +
38398 sz = size_inside_page(p, low_count);
38399
38400 /*
38401 @@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38402 */
38403 kbuf = xlate_dev_kmem_ptr((char *)p);
38404
38405 - if (copy_to_user(buf, kbuf, sz))
38406 +#ifdef CONFIG_PAX_USERCOPY
38407 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38408 + if (!temp)
38409 + return -ENOMEM;
38410 + memcpy(temp, kbuf, sz);
38411 +#else
38412 + temp = kbuf;
38413 +#endif
38414 +
38415 + err = copy_to_user(buf, temp, sz);
38416 +
38417 +#ifdef CONFIG_PAX_USERCOPY
38418 + kfree(temp);
38419 +#endif
38420 +
38421 + if (err)
38422 return -EFAULT;
38423 buf += sz;
38424 p += sz;
38425 @@ -822,6 +869,9 @@ static const struct memdev {
38426 #ifdef CONFIG_PRINTK
38427 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38428 #endif
38429 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38430 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38431 +#endif
38432 };
38433
38434 static int memory_open(struct inode *inode, struct file *filp)
38435 @@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
38436 continue;
38437
38438 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38439 - NULL, devlist[minor].name);
38440 + NULL, "%s", devlist[minor].name);
38441 }
38442
38443 return tty_init();
38444 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38445 index 9df78e2..01ba9ae 100644
38446 --- a/drivers/char/nvram.c
38447 +++ b/drivers/char/nvram.c
38448 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38449
38450 spin_unlock_irq(&rtc_lock);
38451
38452 - if (copy_to_user(buf, contents, tmp - contents))
38453 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38454 return -EFAULT;
38455
38456 *ppos = i;
38457 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38458 index d39cca6..8c1e269 100644
38459 --- a/drivers/char/pcmcia/synclink_cs.c
38460 +++ b/drivers/char/pcmcia/synclink_cs.c
38461 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38462
38463 if (debug_level >= DEBUG_LEVEL_INFO)
38464 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38465 - __FILE__, __LINE__, info->device_name, port->count);
38466 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38467
38468 - WARN_ON(!port->count);
38469 + WARN_ON(!atomic_read(&port->count));
38470
38471 if (tty_port_close_start(port, tty, filp) == 0)
38472 goto cleanup;
38473 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38474 cleanup:
38475 if (debug_level >= DEBUG_LEVEL_INFO)
38476 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38477 - tty->driver->name, port->count);
38478 + tty->driver->name, atomic_read(&port->count));
38479 }
38480
38481 /* Wait until the transmitter is empty.
38482 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38483
38484 if (debug_level >= DEBUG_LEVEL_INFO)
38485 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38486 - __FILE__, __LINE__, tty->driver->name, port->count);
38487 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38488
38489 /* If port is closing, signal caller to try again */
38490 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38491 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38492 goto cleanup;
38493 }
38494 spin_lock(&port->lock);
38495 - port->count++;
38496 + atomic_inc(&port->count);
38497 spin_unlock(&port->lock);
38498 spin_unlock_irqrestore(&info->netlock, flags);
38499
38500 - if (port->count == 1) {
38501 + if (atomic_read(&port->count) == 1) {
38502 /* 1st open on this device, init hardware */
38503 retval = startup(info, tty);
38504 if (retval < 0)
38505 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38506 unsigned short new_crctype;
38507
38508 /* return error if TTY interface open */
38509 - if (info->port.count)
38510 + if (atomic_read(&info->port.count))
38511 return -EBUSY;
38512
38513 switch (encoding)
38514 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38515
38516 /* arbitrate between network and tty opens */
38517 spin_lock_irqsave(&info->netlock, flags);
38518 - if (info->port.count != 0 || info->netcount != 0) {
38519 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38520 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38521 spin_unlock_irqrestore(&info->netlock, flags);
38522 return -EBUSY;
38523 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38524 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38525
38526 /* return error if TTY interface open */
38527 - if (info->port.count)
38528 + if (atomic_read(&info->port.count))
38529 return -EBUSY;
38530
38531 if (cmd != SIOCWANDEV)
38532 diff --git a/drivers/char/random.c b/drivers/char/random.c
38533 index 429b75b..a7f4145 100644
38534 --- a/drivers/char/random.c
38535 +++ b/drivers/char/random.c
38536 @@ -270,10 +270,17 @@
38537 /*
38538 * Configuration information
38539 */
38540 +#ifdef CONFIG_GRKERNSEC_RANDNET
38541 +#define INPUT_POOL_SHIFT 14
38542 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38543 +#define OUTPUT_POOL_SHIFT 12
38544 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38545 +#else
38546 #define INPUT_POOL_SHIFT 12
38547 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38548 #define OUTPUT_POOL_SHIFT 10
38549 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38550 +#endif
38551 #define SEC_XFER_SIZE 512
38552 #define EXTRACT_SIZE 10
38553
38554 @@ -284,9 +291,6 @@
38555 /*
38556 * To allow fractional bits to be tracked, the entropy_count field is
38557 * denominated in units of 1/8th bits.
38558 - *
38559 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38560 - * credit_entropy_bits() needs to be 64 bits wide.
38561 */
38562 #define ENTROPY_SHIFT 3
38563 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38564 @@ -361,12 +365,19 @@ static struct poolinfo {
38565 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38566 int tap1, tap2, tap3, tap4, tap5;
38567 } poolinfo_table[] = {
38568 +#ifdef CONFIG_GRKERNSEC_RANDNET
38569 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38570 + { S(512), 411, 308, 208, 104, 1 },
38571 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38572 + { S(128), 104, 76, 51, 25, 1 },
38573 +#else
38574 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38575 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38576 { S(128), 104, 76, 51, 25, 1 },
38577 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38578 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38579 { S(32), 26, 19, 14, 7, 1 },
38580 +#endif
38581 #if 0
38582 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38583 { S(2048), 1638, 1231, 819, 411, 1 },
38584 @@ -433,9 +444,9 @@ struct entropy_store {
38585 };
38586
38587 static void push_to_pool(struct work_struct *work);
38588 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38589 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38590 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38591 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38592 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38593 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38594
38595 static struct entropy_store input_pool = {
38596 .poolinfo = &poolinfo_table[0],
38597 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38598 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38599 }
38600
38601 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38602 - ACCESS_ONCE(r->add_ptr) = i;
38603 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38604 + ACCESS_ONCE_RW(r->add_ptr) = i;
38605 smp_wmb();
38606
38607 if (out)
38608 @@ -632,7 +643,7 @@ retry:
38609 /* The +2 corresponds to the /4 in the denominator */
38610
38611 do {
38612 - unsigned int anfrac = min(pnfrac, pool_size/2);
38613 + u64 anfrac = min(pnfrac, pool_size/2);
38614 unsigned int add =
38615 ((pool_size - entropy_count)*anfrac*3) >> s;
38616
38617 @@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38618
38619 extract_buf(r, tmp);
38620 i = min_t(int, nbytes, EXTRACT_SIZE);
38621 - if (copy_to_user(buf, tmp, i)) {
38622 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38623 ret = -EFAULT;
38624 break;
38625 }
38626 @@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38627 #include <linux/sysctl.h>
38628
38629 static int min_read_thresh = 8, min_write_thresh;
38630 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
38631 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38632 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38633 static char sysctl_bootid[16];
38634
38635 @@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38636 static int proc_do_uuid(struct ctl_table *table, int write,
38637 void __user *buffer, size_t *lenp, loff_t *ppos)
38638 {
38639 - struct ctl_table fake_table;
38640 + ctl_table_no_const fake_table;
38641 unsigned char buf[64], tmp_uuid[16], *uuid;
38642
38643 uuid = table->data;
38644 @@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38645 static int proc_do_entropy(ctl_table *table, int write,
38646 void __user *buffer, size_t *lenp, loff_t *ppos)
38647 {
38648 - ctl_table fake_table;
38649 + ctl_table_no_const fake_table;
38650 int entropy_count;
38651
38652 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38653 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38654 index 7cc1fe22..b602d6b 100644
38655 --- a/drivers/char/sonypi.c
38656 +++ b/drivers/char/sonypi.c
38657 @@ -54,6 +54,7 @@
38658
38659 #include <asm/uaccess.h>
38660 #include <asm/io.h>
38661 +#include <asm/local.h>
38662
38663 #include <linux/sonypi.h>
38664
38665 @@ -490,7 +491,7 @@ static struct sonypi_device {
38666 spinlock_t fifo_lock;
38667 wait_queue_head_t fifo_proc_list;
38668 struct fasync_struct *fifo_async;
38669 - int open_count;
38670 + local_t open_count;
38671 int model;
38672 struct input_dev *input_jog_dev;
38673 struct input_dev *input_key_dev;
38674 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38675 static int sonypi_misc_release(struct inode *inode, struct file *file)
38676 {
38677 mutex_lock(&sonypi_device.lock);
38678 - sonypi_device.open_count--;
38679 + local_dec(&sonypi_device.open_count);
38680 mutex_unlock(&sonypi_device.lock);
38681 return 0;
38682 }
38683 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38684 {
38685 mutex_lock(&sonypi_device.lock);
38686 /* Flush input queue on first open */
38687 - if (!sonypi_device.open_count)
38688 + if (!local_read(&sonypi_device.open_count))
38689 kfifo_reset(&sonypi_device.fifo);
38690 - sonypi_device.open_count++;
38691 + local_inc(&sonypi_device.open_count);
38692 mutex_unlock(&sonypi_device.lock);
38693
38694 return 0;
38695 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38696 index 64420b3..5c40b56 100644
38697 --- a/drivers/char/tpm/tpm_acpi.c
38698 +++ b/drivers/char/tpm/tpm_acpi.c
38699 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38700 virt = acpi_os_map_memory(start, len);
38701 if (!virt) {
38702 kfree(log->bios_event_log);
38703 + log->bios_event_log = NULL;
38704 printk("%s: ERROR - Unable to map memory\n", __func__);
38705 return -EIO;
38706 }
38707
38708 - memcpy_fromio(log->bios_event_log, virt, len);
38709 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38710
38711 acpi_os_unmap_memory(virt, len);
38712 return 0;
38713 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38714 index 59f7cb2..bac8b6d 100644
38715 --- a/drivers/char/tpm/tpm_eventlog.c
38716 +++ b/drivers/char/tpm/tpm_eventlog.c
38717 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38718 event = addr;
38719
38720 if ((event->event_type == 0 && event->event_size == 0) ||
38721 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38722 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38723 return NULL;
38724
38725 return addr;
38726 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38727 return NULL;
38728
38729 if ((event->event_type == 0 && event->event_size == 0) ||
38730 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38731 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38732 return NULL;
38733
38734 (*pos)++;
38735 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38736 int i;
38737
38738 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38739 - seq_putc(m, data[i]);
38740 + if (!seq_putc(m, data[i]))
38741 + return -EFAULT;
38742
38743 return 0;
38744 }
38745 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38746 index feea87c..18aefff 100644
38747 --- a/drivers/char/virtio_console.c
38748 +++ b/drivers/char/virtio_console.c
38749 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38750 if (to_user) {
38751 ssize_t ret;
38752
38753 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38754 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38755 if (ret)
38756 return -EFAULT;
38757 } else {
38758 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38759 if (!port_has_data(port) && !port->host_connected)
38760 return 0;
38761
38762 - return fill_readbuf(port, ubuf, count, true);
38763 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38764 }
38765
38766 static int wait_port_writable(struct port *port, bool nonblock)
38767 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38768 index a33f46f..a720eed 100644
38769 --- a/drivers/clk/clk-composite.c
38770 +++ b/drivers/clk/clk-composite.c
38771 @@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38772 struct clk *clk;
38773 struct clk_init_data init;
38774 struct clk_composite *composite;
38775 - struct clk_ops *clk_composite_ops;
38776 + clk_ops_no_const *clk_composite_ops;
38777
38778 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38779 if (!composite) {
38780 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38781 index 81dd31a..ef5c542 100644
38782 --- a/drivers/clk/socfpga/clk.c
38783 +++ b/drivers/clk/socfpga/clk.c
38784 @@ -22,6 +22,7 @@
38785 #include <linux/clk-provider.h>
38786 #include <linux/io.h>
38787 #include <linux/of.h>
38788 +#include <asm/pgtable.h>
38789
38790 /* Clock Manager offsets */
38791 #define CLKMGR_CTRL 0x0
38792 @@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38793 streq(clk_name, "periph_pll") ||
38794 streq(clk_name, "sdram_pll")) {
38795 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38796 - clk_pll_ops.enable = clk_gate_ops.enable;
38797 - clk_pll_ops.disable = clk_gate_ops.disable;
38798 + pax_open_kernel();
38799 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38800 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38801 + pax_close_kernel();
38802 }
38803
38804 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38805 @@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38806 return parent_rate / div;
38807 }
38808
38809 -static struct clk_ops gateclk_ops = {
38810 +static clk_ops_no_const gateclk_ops __read_only = {
38811 .recalc_rate = socfpga_clk_recalc_rate,
38812 .get_parent = socfpga_clk_get_parent,
38813 .set_parent = socfpga_clk_set_parent,
38814 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38815 index caf41eb..223d27a 100644
38816 --- a/drivers/cpufreq/acpi-cpufreq.c
38817 +++ b/drivers/cpufreq/acpi-cpufreq.c
38818 @@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38819 return sprintf(buf, "%u\n", boost_enabled);
38820 }
38821
38822 -static struct global_attr global_boost = __ATTR(boost, 0644,
38823 +static global_attr_no_const global_boost = __ATTR(boost, 0644,
38824 show_global_boost,
38825 store_global_boost);
38826
38827 @@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38828 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38829 per_cpu(acfreq_data, cpu) = data;
38830
38831 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38832 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38833 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38834 + pax_open_kernel();
38835 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38836 + pax_close_kernel();
38837 + }
38838
38839 result = acpi_processor_register_performance(data->acpi_data, cpu);
38840 if (result)
38841 @@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38842 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38843 break;
38844 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38845 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38846 + pax_open_kernel();
38847 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38848 + pax_close_kernel();
38849 break;
38850 default:
38851 break;
38852 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38853 index 99a443e..8cb6f02 100644
38854 --- a/drivers/cpufreq/cpufreq.c
38855 +++ b/drivers/cpufreq/cpufreq.c
38856 @@ -1878,7 +1878,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38857 #endif
38858
38859 mutex_lock(&cpufreq_governor_mutex);
38860 - list_del(&governor->governor_list);
38861 + pax_list_del(&governor->governor_list);
38862 mutex_unlock(&cpufreq_governor_mutex);
38863 return;
38864 }
38865 @@ -2108,7 +2108,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38866 return NOTIFY_OK;
38867 }
38868
38869 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
38870 +static struct notifier_block cpufreq_cpu_notifier = {
38871 .notifier_call = cpufreq_cpu_callback,
38872 };
38873
38874 @@ -2141,8 +2141,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38875
38876 pr_debug("trying to register driver %s\n", driver_data->name);
38877
38878 - if (driver_data->setpolicy)
38879 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
38880 + if (driver_data->setpolicy) {
38881 + pax_open_kernel();
38882 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38883 + pax_close_kernel();
38884 + }
38885
38886 write_lock_irqsave(&cpufreq_driver_lock, flags);
38887 if (cpufreq_driver) {
38888 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38889 index e6be635..f8a90dc 100644
38890 --- a/drivers/cpufreq/cpufreq_governor.c
38891 +++ b/drivers/cpufreq/cpufreq_governor.c
38892 @@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38893 struct dbs_data *dbs_data;
38894 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38895 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38896 - struct od_ops *od_ops = NULL;
38897 + const struct od_ops *od_ops = NULL;
38898 struct od_dbs_tuners *od_tuners = NULL;
38899 struct cs_dbs_tuners *cs_tuners = NULL;
38900 struct cpu_dbs_common_info *cpu_cdbs;
38901 @@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38902
38903 if ((cdata->governor == GOV_CONSERVATIVE) &&
38904 (!policy->governor->initialized)) {
38905 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38906 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38907
38908 cpufreq_register_notifier(cs_ops->notifier_block,
38909 CPUFREQ_TRANSITION_NOTIFIER);
38910 @@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38911
38912 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38913 (policy->governor->initialized == 1)) {
38914 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38915 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38916
38917 cpufreq_unregister_notifier(cs_ops->notifier_block,
38918 CPUFREQ_TRANSITION_NOTIFIER);
38919 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38920 index b5f2b86..daa801b 100644
38921 --- a/drivers/cpufreq/cpufreq_governor.h
38922 +++ b/drivers/cpufreq/cpufreq_governor.h
38923 @@ -205,7 +205,7 @@ struct common_dbs_data {
38924 void (*exit)(struct dbs_data *dbs_data);
38925
38926 /* Governor specific ops, see below */
38927 - void *gov_ops;
38928 + const void *gov_ops;
38929 };
38930
38931 /* Governor Per policy data */
38932 @@ -225,7 +225,7 @@ struct od_ops {
38933 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38934 unsigned int freq_next, unsigned int relation);
38935 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38936 -};
38937 +} __no_const;
38938
38939 struct cs_ops {
38940 struct notifier_block *notifier_block;
38941 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38942 index 18d4091..434be15 100644
38943 --- a/drivers/cpufreq/cpufreq_ondemand.c
38944 +++ b/drivers/cpufreq/cpufreq_ondemand.c
38945 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38946
38947 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38948
38949 -static struct od_ops od_ops = {
38950 +static struct od_ops od_ops __read_only = {
38951 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38952 .powersave_bias_target = generic_powersave_bias_target,
38953 .freq_increase = dbs_freq_increase,
38954 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38955 (struct cpufreq_policy *, unsigned int, unsigned int),
38956 unsigned int powersave_bias)
38957 {
38958 - od_ops.powersave_bias_target = f;
38959 + pax_open_kernel();
38960 + *(void **)&od_ops.powersave_bias_target = f;
38961 + pax_close_kernel();
38962 od_set_powersave_bias(powersave_bias);
38963 }
38964 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38965
38966 void od_unregister_powersave_bias_handler(void)
38967 {
38968 - od_ops.powersave_bias_target = generic_powersave_bias_target;
38969 + pax_open_kernel();
38970 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38971 + pax_close_kernel();
38972 od_set_powersave_bias(0);
38973 }
38974 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38975 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38976 index 4cf0d28..5830372 100644
38977 --- a/drivers/cpufreq/cpufreq_stats.c
38978 +++ b/drivers/cpufreq/cpufreq_stats.c
38979 @@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38980 }
38981
38982 /* priority=1 so this will get called before cpufreq_remove_dev */
38983 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38984 +static struct notifier_block cpufreq_stat_cpu_notifier = {
38985 .notifier_call = cpufreq_stat_cpu_callback,
38986 .priority = 1,
38987 };
38988 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38989 index b687df8..ae733fc 100644
38990 --- a/drivers/cpufreq/intel_pstate.c
38991 +++ b/drivers/cpufreq/intel_pstate.c
38992 @@ -123,10 +123,10 @@ struct pstate_funcs {
38993 struct cpu_defaults {
38994 struct pstate_adjust_policy pid_policy;
38995 struct pstate_funcs funcs;
38996 -};
38997 +} __do_const;
38998
38999 static struct pstate_adjust_policy pid_params;
39000 -static struct pstate_funcs pstate_funcs;
39001 +static struct pstate_funcs *pstate_funcs;
39002
39003 struct perf_limits {
39004 int no_turbo;
39005 @@ -517,7 +517,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39006
39007 cpu->pstate.current_pstate = pstate;
39008
39009 - pstate_funcs.set(cpu, pstate);
39010 + pstate_funcs->set(cpu, pstate);
39011 }
39012
39013 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39014 @@ -539,12 +539,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39015 {
39016 sprintf(cpu->name, "Intel 2nd generation core");
39017
39018 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39019 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39020 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39021 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39022 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39023 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39024
39025 - if (pstate_funcs.get_vid)
39026 - pstate_funcs.get_vid(cpu);
39027 + if (pstate_funcs->get_vid)
39028 + pstate_funcs->get_vid(cpu);
39029
39030 /*
39031 * goto max pstate so we don't slow up boot if we are built-in if we are
39032 @@ -808,9 +808,9 @@ static int intel_pstate_msrs_not_valid(void)
39033 rdmsrl(MSR_IA32_APERF, aperf);
39034 rdmsrl(MSR_IA32_MPERF, mperf);
39035
39036 - if (!pstate_funcs.get_max() ||
39037 - !pstate_funcs.get_min() ||
39038 - !pstate_funcs.get_turbo())
39039 + if (!pstate_funcs->get_max() ||
39040 + !pstate_funcs->get_min() ||
39041 + !pstate_funcs->get_turbo())
39042 return -ENODEV;
39043
39044 rdmsrl(MSR_IA32_APERF, tmp);
39045 @@ -824,7 +824,7 @@ static int intel_pstate_msrs_not_valid(void)
39046 return 0;
39047 }
39048
39049 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39050 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39051 {
39052 pid_params.sample_rate_ms = policy->sample_rate_ms;
39053 pid_params.p_gain_pct = policy->p_gain_pct;
39054 @@ -836,11 +836,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39055
39056 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39057 {
39058 - pstate_funcs.get_max = funcs->get_max;
39059 - pstate_funcs.get_min = funcs->get_min;
39060 - pstate_funcs.get_turbo = funcs->get_turbo;
39061 - pstate_funcs.set = funcs->set;
39062 - pstate_funcs.get_vid = funcs->get_vid;
39063 + pstate_funcs = funcs;
39064 }
39065
39066 #if IS_ENABLED(CONFIG_ACPI)
39067 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39068 index 3d1cba9..0ab21d2 100644
39069 --- a/drivers/cpufreq/p4-clockmod.c
39070 +++ b/drivers/cpufreq/p4-clockmod.c
39071 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39072 case 0x0F: /* Core Duo */
39073 case 0x16: /* Celeron Core */
39074 case 0x1C: /* Atom */
39075 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39076 + pax_open_kernel();
39077 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39078 + pax_close_kernel();
39079 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39080 case 0x0D: /* Pentium M (Dothan) */
39081 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39082 + pax_open_kernel();
39083 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39084 + pax_close_kernel();
39085 /* fall through */
39086 case 0x09: /* Pentium M (Banias) */
39087 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39088 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39089
39090 /* on P-4s, the TSC runs with constant frequency independent whether
39091 * throttling is active or not. */
39092 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39093 + pax_open_kernel();
39094 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39095 + pax_close_kernel();
39096
39097 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39098 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39099 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39100 index 724ffbd..ad83692 100644
39101 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39102 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39103 @@ -18,14 +18,12 @@
39104 #include <asm/head.h>
39105 #include <asm/timer.h>
39106
39107 -static struct cpufreq_driver *cpufreq_us3_driver;
39108 -
39109 struct us3_freq_percpu_info {
39110 struct cpufreq_frequency_table table[4];
39111 };
39112
39113 /* Indexed by cpu number. */
39114 -static struct us3_freq_percpu_info *us3_freq_table;
39115 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39116
39117 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39118 * in the Safari config register.
39119 @@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39120
39121 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39122 {
39123 - if (cpufreq_us3_driver) {
39124 - cpufreq_frequency_table_put_attr(policy->cpu);
39125 - us3_freq_target(policy, 0);
39126 - }
39127 + cpufreq_frequency_table_put_attr(policy->cpu);
39128 + us3_freq_target(policy, 0);
39129
39130 return 0;
39131 }
39132
39133 +static int __init us3_freq_init(void);
39134 +static void __exit us3_freq_exit(void);
39135 +
39136 +static struct cpufreq_driver cpufreq_us3_driver = {
39137 + .init = us3_freq_cpu_init,
39138 + .verify = cpufreq_generic_frequency_table_verify,
39139 + .target_index = us3_freq_target,
39140 + .get = us3_freq_get,
39141 + .exit = us3_freq_cpu_exit,
39142 + .owner = THIS_MODULE,
39143 + .name = "UltraSPARC-III",
39144 +
39145 +};
39146 +
39147 static int __init us3_freq_init(void)
39148 {
39149 unsigned long manuf, impl, ver;
39150 @@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39151 (impl == CHEETAH_IMPL ||
39152 impl == CHEETAH_PLUS_IMPL ||
39153 impl == JAGUAR_IMPL ||
39154 - impl == PANTHER_IMPL)) {
39155 - struct cpufreq_driver *driver;
39156 -
39157 - ret = -ENOMEM;
39158 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39159 - if (!driver)
39160 - goto err_out;
39161 -
39162 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39163 - GFP_KERNEL);
39164 - if (!us3_freq_table)
39165 - goto err_out;
39166 -
39167 - driver->init = us3_freq_cpu_init;
39168 - driver->verify = cpufreq_generic_frequency_table_verify;
39169 - driver->target_index = us3_freq_target;
39170 - driver->get = us3_freq_get;
39171 - driver->exit = us3_freq_cpu_exit;
39172 - strcpy(driver->name, "UltraSPARC-III");
39173 -
39174 - cpufreq_us3_driver = driver;
39175 - ret = cpufreq_register_driver(driver);
39176 - if (ret)
39177 - goto err_out;
39178 -
39179 - return 0;
39180 -
39181 -err_out:
39182 - if (driver) {
39183 - kfree(driver);
39184 - cpufreq_us3_driver = NULL;
39185 - }
39186 - kfree(us3_freq_table);
39187 - us3_freq_table = NULL;
39188 - return ret;
39189 - }
39190 + impl == PANTHER_IMPL))
39191 + return cpufreq_register_driver(&cpufreq_us3_driver);
39192
39193 return -ENODEV;
39194 }
39195
39196 static void __exit us3_freq_exit(void)
39197 {
39198 - if (cpufreq_us3_driver) {
39199 - cpufreq_unregister_driver(cpufreq_us3_driver);
39200 - kfree(cpufreq_us3_driver);
39201 - cpufreq_us3_driver = NULL;
39202 - kfree(us3_freq_table);
39203 - us3_freq_table = NULL;
39204 - }
39205 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39206 }
39207
39208 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39209 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39210 index 4e1daca..e707b61 100644
39211 --- a/drivers/cpufreq/speedstep-centrino.c
39212 +++ b/drivers/cpufreq/speedstep-centrino.c
39213 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39214 !cpu_has(cpu, X86_FEATURE_EST))
39215 return -ENODEV;
39216
39217 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39218 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39219 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39220 + pax_open_kernel();
39221 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39222 + pax_close_kernel();
39223 + }
39224
39225 if (policy->cpu != 0)
39226 return -ENODEV;
39227 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39228 index 06dbe7c..c2c8671 100644
39229 --- a/drivers/cpuidle/driver.c
39230 +++ b/drivers/cpuidle/driver.c
39231 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39232
39233 static void poll_idle_init(struct cpuidle_driver *drv)
39234 {
39235 - struct cpuidle_state *state = &drv->states[0];
39236 + cpuidle_state_no_const *state = &drv->states[0];
39237
39238 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39239 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39240 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39241 index ca89412..a7b9c49 100644
39242 --- a/drivers/cpuidle/governor.c
39243 +++ b/drivers/cpuidle/governor.c
39244 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39245 mutex_lock(&cpuidle_lock);
39246 if (__cpuidle_find_governor(gov->name) == NULL) {
39247 ret = 0;
39248 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39249 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39250 if (!cpuidle_curr_governor ||
39251 cpuidle_curr_governor->rating < gov->rating)
39252 cpuidle_switch_governor(gov);
39253 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39254 index e918b6d..f87ea80 100644
39255 --- a/drivers/cpuidle/sysfs.c
39256 +++ b/drivers/cpuidle/sysfs.c
39257 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39258 NULL
39259 };
39260
39261 -static struct attribute_group cpuidle_attr_group = {
39262 +static attribute_group_no_const cpuidle_attr_group = {
39263 .attrs = cpuidle_default_attrs,
39264 .name = "cpuidle",
39265 };
39266 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39267 index 12fea3e..1e28f47 100644
39268 --- a/drivers/crypto/hifn_795x.c
39269 +++ b/drivers/crypto/hifn_795x.c
39270 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39271 MODULE_PARM_DESC(hifn_pll_ref,
39272 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39273
39274 -static atomic_t hifn_dev_number;
39275 +static atomic_unchecked_t hifn_dev_number;
39276
39277 #define ACRYPTO_OP_DECRYPT 0
39278 #define ACRYPTO_OP_ENCRYPT 1
39279 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39280 goto err_out_disable_pci_device;
39281
39282 snprintf(name, sizeof(name), "hifn%d",
39283 - atomic_inc_return(&hifn_dev_number)-1);
39284 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39285
39286 err = pci_request_regions(pdev, name);
39287 if (err)
39288 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39289 index a0b2f7e..1b6f028 100644
39290 --- a/drivers/devfreq/devfreq.c
39291 +++ b/drivers/devfreq/devfreq.c
39292 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39293 goto err_out;
39294 }
39295
39296 - list_add(&governor->node, &devfreq_governor_list);
39297 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39298
39299 list_for_each_entry(devfreq, &devfreq_list, node) {
39300 int ret = 0;
39301 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39302 }
39303 }
39304
39305 - list_del(&governor->node);
39306 + pax_list_del((struct list_head *)&governor->node);
39307 err_out:
39308 mutex_unlock(&devfreq_list_lock);
39309
39310 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39311 index 0d765c0..60b7480 100644
39312 --- a/drivers/dma/sh/shdmac.c
39313 +++ b/drivers/dma/sh/shdmac.c
39314 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39315 return ret;
39316 }
39317
39318 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39319 +static struct notifier_block sh_dmae_nmi_notifier = {
39320 .notifier_call = sh_dmae_nmi_handler,
39321
39322 /* Run before NMI debug handler and KGDB */
39323 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39324 index 1026743..80b081c 100644
39325 --- a/drivers/edac/edac_device.c
39326 +++ b/drivers/edac/edac_device.c
39327 @@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39328 */
39329 int edac_device_alloc_index(void)
39330 {
39331 - static atomic_t device_indexes = ATOMIC_INIT(0);
39332 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39333
39334 - return atomic_inc_return(&device_indexes) - 1;
39335 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39336 }
39337 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39338
39339 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39340 index e5bdf21..b8f9055 100644
39341 --- a/drivers/edac/edac_mc_sysfs.c
39342 +++ b/drivers/edac/edac_mc_sysfs.c
39343 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39344 struct dev_ch_attribute {
39345 struct device_attribute attr;
39346 int channel;
39347 -};
39348 +} __do_const;
39349
39350 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39351 struct dev_ch_attribute dev_attr_legacy_##_name = \
39352 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39353 }
39354
39355 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39356 + pax_open_kernel();
39357 if (mci->get_sdram_scrub_rate) {
39358 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39359 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39360 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39361 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39362 }
39363 if (mci->set_sdram_scrub_rate) {
39364 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39365 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39366 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39367 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39368 }
39369 + pax_close_kernel();
39370 err = device_create_file(&mci->dev,
39371 &dev_attr_sdram_scrub_rate);
39372 if (err) {
39373 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39374 index 2cf44b4d..6dd2dc7 100644
39375 --- a/drivers/edac/edac_pci.c
39376 +++ b/drivers/edac/edac_pci.c
39377 @@ -29,7 +29,7 @@
39378
39379 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39380 static LIST_HEAD(edac_pci_list);
39381 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39382 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39383
39384 /*
39385 * edac_pci_alloc_ctl_info
39386 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39387 */
39388 int edac_pci_alloc_index(void)
39389 {
39390 - return atomic_inc_return(&pci_indexes) - 1;
39391 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39392 }
39393 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39394
39395 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39396 index e8658e4..22746d6 100644
39397 --- a/drivers/edac/edac_pci_sysfs.c
39398 +++ b/drivers/edac/edac_pci_sysfs.c
39399 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39400 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39401 static int edac_pci_poll_msec = 1000; /* one second workq period */
39402
39403 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39404 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39405 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39406 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39407
39408 static struct kobject *edac_pci_top_main_kobj;
39409 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39410 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39411 void *value;
39412 ssize_t(*show) (void *, char *);
39413 ssize_t(*store) (void *, const char *, size_t);
39414 -};
39415 +} __do_const;
39416
39417 /* Set of show/store abstract level functions for PCI Parity object */
39418 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39419 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39420 edac_printk(KERN_CRIT, EDAC_PCI,
39421 "Signaled System Error on %s\n",
39422 pci_name(dev));
39423 - atomic_inc(&pci_nonparity_count);
39424 + atomic_inc_unchecked(&pci_nonparity_count);
39425 }
39426
39427 if (status & (PCI_STATUS_PARITY)) {
39428 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39429 "Master Data Parity Error on %s\n",
39430 pci_name(dev));
39431
39432 - atomic_inc(&pci_parity_count);
39433 + atomic_inc_unchecked(&pci_parity_count);
39434 }
39435
39436 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39437 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39438 "Detected Parity Error on %s\n",
39439 pci_name(dev));
39440
39441 - atomic_inc(&pci_parity_count);
39442 + atomic_inc_unchecked(&pci_parity_count);
39443 }
39444 }
39445
39446 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39447 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39448 "Signaled System Error on %s\n",
39449 pci_name(dev));
39450 - atomic_inc(&pci_nonparity_count);
39451 + atomic_inc_unchecked(&pci_nonparity_count);
39452 }
39453
39454 if (status & (PCI_STATUS_PARITY)) {
39455 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39456 "Master Data Parity Error on "
39457 "%s\n", pci_name(dev));
39458
39459 - atomic_inc(&pci_parity_count);
39460 + atomic_inc_unchecked(&pci_parity_count);
39461 }
39462
39463 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39464 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39465 "Detected Parity Error on %s\n",
39466 pci_name(dev));
39467
39468 - atomic_inc(&pci_parity_count);
39469 + atomic_inc_unchecked(&pci_parity_count);
39470 }
39471 }
39472 }
39473 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39474 if (!check_pci_errors)
39475 return;
39476
39477 - before_count = atomic_read(&pci_parity_count);
39478 + before_count = atomic_read_unchecked(&pci_parity_count);
39479
39480 /* scan all PCI devices looking for a Parity Error on devices and
39481 * bridges.
39482 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39483 /* Only if operator has selected panic on PCI Error */
39484 if (edac_pci_get_panic_on_pe()) {
39485 /* If the count is different 'after' from 'before' */
39486 - if (before_count != atomic_read(&pci_parity_count))
39487 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39488 panic("EDAC: PCI Parity Error");
39489 }
39490 }
39491 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39492 index 51b7e3a..aa8a3e8 100644
39493 --- a/drivers/edac/mce_amd.h
39494 +++ b/drivers/edac/mce_amd.h
39495 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39496 bool (*mc0_mce)(u16, u8);
39497 bool (*mc1_mce)(u16, u8);
39498 bool (*mc2_mce)(u16, u8);
39499 -};
39500 +} __no_const;
39501
39502 void amd_report_gart_errors(bool);
39503 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39504 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39505 index 57ea7f4..af06b76 100644
39506 --- a/drivers/firewire/core-card.c
39507 +++ b/drivers/firewire/core-card.c
39508 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39509 const struct fw_card_driver *driver,
39510 struct device *device)
39511 {
39512 - static atomic_t index = ATOMIC_INIT(-1);
39513 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39514
39515 - card->index = atomic_inc_return(&index);
39516 + card->index = atomic_inc_return_unchecked(&index);
39517 card->driver = driver;
39518 card->device = device;
39519 card->current_tlabel = 0;
39520 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39521
39522 void fw_core_remove_card(struct fw_card *card)
39523 {
39524 - struct fw_card_driver dummy_driver = dummy_driver_template;
39525 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39526
39527 card->driver->update_phy_reg(card, 4,
39528 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39529 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39530 index 2c6d5e1..a2cca6b 100644
39531 --- a/drivers/firewire/core-device.c
39532 +++ b/drivers/firewire/core-device.c
39533 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39534 struct config_rom_attribute {
39535 struct device_attribute attr;
39536 u32 key;
39537 -};
39538 +} __do_const;
39539
39540 static ssize_t show_immediate(struct device *dev,
39541 struct device_attribute *dattr, char *buf)
39542 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39543 index 0e79951..b180217 100644
39544 --- a/drivers/firewire/core-transaction.c
39545 +++ b/drivers/firewire/core-transaction.c
39546 @@ -38,6 +38,7 @@
39547 #include <linux/timer.h>
39548 #include <linux/types.h>
39549 #include <linux/workqueue.h>
39550 +#include <linux/sched.h>
39551
39552 #include <asm/byteorder.h>
39553
39554 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39555 index 515a42c..5ecf3ba 100644
39556 --- a/drivers/firewire/core.h
39557 +++ b/drivers/firewire/core.h
39558 @@ -111,6 +111,7 @@ struct fw_card_driver {
39559
39560 int (*stop_iso)(struct fw_iso_context *ctx);
39561 };
39562 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39563
39564 void fw_card_initialize(struct fw_card *card,
39565 const struct fw_card_driver *driver, struct device *device);
39566 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39567 index 94a58a0..f5eba42 100644
39568 --- a/drivers/firmware/dmi-id.c
39569 +++ b/drivers/firmware/dmi-id.c
39570 @@ -16,7 +16,7 @@
39571 struct dmi_device_attribute{
39572 struct device_attribute dev_attr;
39573 int field;
39574 -};
39575 +} __do_const;
39576 #define to_dmi_dev_attr(_dev_attr) \
39577 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39578
39579 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39580 index c7e81ff..94a7401 100644
39581 --- a/drivers/firmware/dmi_scan.c
39582 +++ b/drivers/firmware/dmi_scan.c
39583 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39584 if (buf == NULL)
39585 return -1;
39586
39587 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39588 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39589
39590 iounmap(buf);
39591 return 0;
39592 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39593 index 1491dd4..aa910db 100644
39594 --- a/drivers/firmware/efi/cper.c
39595 +++ b/drivers/firmware/efi/cper.c
39596 @@ -41,12 +41,12 @@
39597 */
39598 u64 cper_next_record_id(void)
39599 {
39600 - static atomic64_t seq;
39601 + static atomic64_unchecked_t seq;
39602
39603 - if (!atomic64_read(&seq))
39604 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39605 + if (!atomic64_read_unchecked(&seq))
39606 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39607
39608 - return atomic64_inc_return(&seq);
39609 + return atomic64_inc_return_unchecked(&seq);
39610 }
39611 EXPORT_SYMBOL_GPL(cper_next_record_id);
39612
39613 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39614 index 2e2fbde..7676c8b 100644
39615 --- a/drivers/firmware/efi/efi.c
39616 +++ b/drivers/firmware/efi/efi.c
39617 @@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
39618 };
39619
39620 static struct efivars generic_efivars;
39621 -static struct efivar_operations generic_ops;
39622 +static efivar_operations_no_const generic_ops __read_only;
39623
39624 static int generic_ops_register(void)
39625 {
39626 - generic_ops.get_variable = efi.get_variable;
39627 - generic_ops.set_variable = efi.set_variable;
39628 - generic_ops.get_next_variable = efi.get_next_variable;
39629 - generic_ops.query_variable_store = efi_query_variable_store;
39630 + pax_open_kernel();
39631 + *(void **)&generic_ops.get_variable = efi.get_variable;
39632 + *(void **)&generic_ops.set_variable = efi.set_variable;
39633 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39634 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39635 + pax_close_kernel();
39636
39637 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39638 }
39639 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39640 index 3dc2482..7bd2f61 100644
39641 --- a/drivers/firmware/efi/efivars.c
39642 +++ b/drivers/firmware/efi/efivars.c
39643 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39644 static int
39645 create_efivars_bin_attributes(void)
39646 {
39647 - struct bin_attribute *attr;
39648 + bin_attribute_no_const *attr;
39649 int error;
39650
39651 /* new_var */
39652 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39653 index 2a90ba6..07f3733 100644
39654 --- a/drivers/firmware/google/memconsole.c
39655 +++ b/drivers/firmware/google/memconsole.c
39656 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39657 if (!found_memconsole())
39658 return -ENODEV;
39659
39660 - memconsole_bin_attr.size = memconsole_length;
39661 + pax_open_kernel();
39662 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39663 + pax_close_kernel();
39664
39665 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39666
39667 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39668 index ec19036..8ffafc2 100644
39669 --- a/drivers/gpio/gpio-em.c
39670 +++ b/drivers/gpio/gpio-em.c
39671 @@ -257,7 +257,7 @@ static int em_gio_probe(struct platform_device *pdev)
39672 struct em_gio_priv *p;
39673 struct resource *io[2], *irq[2];
39674 struct gpio_chip *gpio_chip;
39675 - struct irq_chip *irq_chip;
39676 + irq_chip_no_const *irq_chip;
39677 const char *name = dev_name(&pdev->dev);
39678 int ret;
39679
39680 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39681 index 814addb..0937d7f 100644
39682 --- a/drivers/gpio/gpio-ich.c
39683 +++ b/drivers/gpio/gpio-ich.c
39684 @@ -71,7 +71,7 @@ struct ichx_desc {
39685 /* Some chipsets have quirks, let these use their own request/get */
39686 int (*request)(struct gpio_chip *chip, unsigned offset);
39687 int (*get)(struct gpio_chip *chip, unsigned offset);
39688 -};
39689 +} __do_const;
39690
39691 static struct {
39692 spinlock_t lock;
39693 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39694 index 8b7e719..dc089dc 100644
39695 --- a/drivers/gpio/gpio-rcar.c
39696 +++ b/drivers/gpio/gpio-rcar.c
39697 @@ -316,7 +316,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39698 struct gpio_rcar_priv *p;
39699 struct resource *io, *irq;
39700 struct gpio_chip *gpio_chip;
39701 - struct irq_chip *irq_chip;
39702 + irq_chip_no_const *irq_chip;
39703 const char *name = dev_name(&pdev->dev);
39704 int ret;
39705
39706 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39707 index 9902732..64b62dd 100644
39708 --- a/drivers/gpio/gpio-vr41xx.c
39709 +++ b/drivers/gpio/gpio-vr41xx.c
39710 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39711 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39712 maskl, pendl, maskh, pendh);
39713
39714 - atomic_inc(&irq_err_count);
39715 + atomic_inc_unchecked(&irq_err_count);
39716
39717 return -EINVAL;
39718 }
39719 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39720 index d6cf77c..2842146 100644
39721 --- a/drivers/gpu/drm/drm_crtc.c
39722 +++ b/drivers/gpu/drm/drm_crtc.c
39723 @@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39724 goto done;
39725 }
39726
39727 - if (copy_to_user(&enum_ptr[copied].name,
39728 + if (copy_to_user(enum_ptr[copied].name,
39729 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39730 ret = -EFAULT;
39731 goto done;
39732 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39733 index 01361ab..891e821 100644
39734 --- a/drivers/gpu/drm/drm_crtc_helper.c
39735 +++ b/drivers/gpu/drm/drm_crtc_helper.c
39736 @@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39737 struct drm_crtc *tmp;
39738 int crtc_mask = 1;
39739
39740 - WARN(!crtc, "checking null crtc?\n");
39741 + BUG_ON(!crtc);
39742
39743 dev = crtc->dev;
39744
39745 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39746 index d9137e4..69b73a0 100644
39747 --- a/drivers/gpu/drm/drm_drv.c
39748 +++ b/drivers/gpu/drm/drm_drv.c
39749 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39750 /**
39751 * Copy and IOCTL return string to user space
39752 */
39753 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39754 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39755 {
39756 int len;
39757
39758 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39759 struct drm_file *file_priv = filp->private_data;
39760 struct drm_device *dev;
39761 const struct drm_ioctl_desc *ioctl = NULL;
39762 - drm_ioctl_t *func;
39763 + drm_ioctl_no_const_t func;
39764 unsigned int nr = DRM_IOCTL_NR(cmd);
39765 int retcode = -EINVAL;
39766 char stack_kdata[128];
39767 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39768 index c5b929c..8a3b8be 100644
39769 --- a/drivers/gpu/drm/drm_fops.c
39770 +++ b/drivers/gpu/drm/drm_fops.c
39771 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39772 if (drm_device_is_unplugged(dev))
39773 return -ENODEV;
39774
39775 - if (!dev->open_count++)
39776 + if (local_inc_return(&dev->open_count) == 1)
39777 need_setup = 1;
39778 mutex_lock(&dev->struct_mutex);
39779 old_imapping = inode->i_mapping;
39780 @@ -127,7 +127,7 @@ err_undo:
39781 iput(container_of(dev->dev_mapping, struct inode, i_data));
39782 dev->dev_mapping = old_mapping;
39783 mutex_unlock(&dev->struct_mutex);
39784 - dev->open_count--;
39785 + local_dec(&dev->open_count);
39786 return retcode;
39787 }
39788 EXPORT_SYMBOL(drm_open);
39789 @@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39790
39791 mutex_lock(&drm_global_mutex);
39792
39793 - DRM_DEBUG("open_count = %d\n", dev->open_count);
39794 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39795
39796 if (dev->driver->preclose)
39797 dev->driver->preclose(dev, file_priv);
39798 @@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39799 * Begin inline drm_release
39800 */
39801
39802 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39803 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39804 task_pid_nr(current),
39805 (long)old_encode_dev(file_priv->minor->device),
39806 - dev->open_count);
39807 + local_read(&dev->open_count));
39808
39809 /* Release any auth tokens that might point to this file_priv,
39810 (do that under the drm_global_mutex) */
39811 @@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39812 * End inline drm_release
39813 */
39814
39815 - if (!--dev->open_count) {
39816 + if (local_dec_and_test(&dev->open_count)) {
39817 if (atomic_read(&dev->ioctl_count)) {
39818 DRM_ERROR("Device busy: %d\n",
39819 atomic_read(&dev->ioctl_count));
39820 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39821 index 3d2e91c..d31c4c9 100644
39822 --- a/drivers/gpu/drm/drm_global.c
39823 +++ b/drivers/gpu/drm/drm_global.c
39824 @@ -36,7 +36,7 @@
39825 struct drm_global_item {
39826 struct mutex mutex;
39827 void *object;
39828 - int refcount;
39829 + atomic_t refcount;
39830 };
39831
39832 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39833 @@ -49,7 +49,7 @@ void drm_global_init(void)
39834 struct drm_global_item *item = &glob[i];
39835 mutex_init(&item->mutex);
39836 item->object = NULL;
39837 - item->refcount = 0;
39838 + atomic_set(&item->refcount, 0);
39839 }
39840 }
39841
39842 @@ -59,7 +59,7 @@ void drm_global_release(void)
39843 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39844 struct drm_global_item *item = &glob[i];
39845 BUG_ON(item->object != NULL);
39846 - BUG_ON(item->refcount != 0);
39847 + BUG_ON(atomic_read(&item->refcount) != 0);
39848 }
39849 }
39850
39851 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39852 struct drm_global_item *item = &glob[ref->global_type];
39853
39854 mutex_lock(&item->mutex);
39855 - if (item->refcount == 0) {
39856 + if (atomic_read(&item->refcount) == 0) {
39857 item->object = kzalloc(ref->size, GFP_KERNEL);
39858 if (unlikely(item->object == NULL)) {
39859 ret = -ENOMEM;
39860 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39861 goto out_err;
39862
39863 }
39864 - ++item->refcount;
39865 + atomic_inc(&item->refcount);
39866 ref->object = item->object;
39867 mutex_unlock(&item->mutex);
39868 return 0;
39869 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39870 struct drm_global_item *item = &glob[ref->global_type];
39871
39872 mutex_lock(&item->mutex);
39873 - BUG_ON(item->refcount == 0);
39874 + BUG_ON(atomic_read(&item->refcount) == 0);
39875 BUG_ON(ref->object != item->object);
39876 - if (--item->refcount == 0) {
39877 + if (atomic_dec_and_test(&item->refcount)) {
39878 ref->release(ref);
39879 item->object = NULL;
39880 }
39881 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39882 index 7d5a152..d7186da 100644
39883 --- a/drivers/gpu/drm/drm_info.c
39884 +++ b/drivers/gpu/drm/drm_info.c
39885 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39886 struct drm_local_map *map;
39887 struct drm_map_list *r_list;
39888
39889 - /* Hardcoded from _DRM_FRAME_BUFFER,
39890 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39891 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39892 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39893 + static const char * const types[] = {
39894 + [_DRM_FRAME_BUFFER] = "FB",
39895 + [_DRM_REGISTERS] = "REG",
39896 + [_DRM_SHM] = "SHM",
39897 + [_DRM_AGP] = "AGP",
39898 + [_DRM_SCATTER_GATHER] = "SG",
39899 + [_DRM_CONSISTENT] = "PCI",
39900 + [_DRM_GEM] = "GEM" };
39901 const char *type;
39902 int i;
39903
39904 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39905 map = r_list->map;
39906 if (!map)
39907 continue;
39908 - if (map->type < 0 || map->type > 5)
39909 + if (map->type >= ARRAY_SIZE(types))
39910 type = "??";
39911 else
39912 type = types[map->type];
39913 @@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39914 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39915 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39916 vma->vm_flags & VM_IO ? 'i' : '-',
39917 +#ifdef CONFIG_GRKERNSEC_HIDESYM
39918 + 0);
39919 +#else
39920 vma->vm_pgoff);
39921 +#endif
39922
39923 #if defined(__i386__)
39924 pgprot = pgprot_val(vma->vm_page_prot);
39925 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39926 index 2f4c4343..dd12cd2 100644
39927 --- a/drivers/gpu/drm/drm_ioc32.c
39928 +++ b/drivers/gpu/drm/drm_ioc32.c
39929 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39930 request = compat_alloc_user_space(nbytes);
39931 if (!access_ok(VERIFY_WRITE, request, nbytes))
39932 return -EFAULT;
39933 - list = (struct drm_buf_desc *) (request + 1);
39934 + list = (struct drm_buf_desc __user *) (request + 1);
39935
39936 if (__put_user(count, &request->count)
39937 || __put_user(list, &request->list))
39938 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39939 request = compat_alloc_user_space(nbytes);
39940 if (!access_ok(VERIFY_WRITE, request, nbytes))
39941 return -EFAULT;
39942 - list = (struct drm_buf_pub *) (request + 1);
39943 + list = (struct drm_buf_pub __user *) (request + 1);
39944
39945 if (__put_user(count, &request->count)
39946 || __put_user(list, &request->list))
39947 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39948 return 0;
39949 }
39950
39951 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
39952 +drm_ioctl_compat_t drm_compat_ioctls[] = {
39953 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39954 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39955 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39956 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39957 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39958 {
39959 unsigned int nr = DRM_IOCTL_NR(cmd);
39960 - drm_ioctl_compat_t *fn;
39961 int ret;
39962
39963 /* Assume that ioctls without an explicit compat routine will just
39964 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39965 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39966 return drm_ioctl(filp, cmd, arg);
39967
39968 - fn = drm_compat_ioctls[nr];
39969 -
39970 - if (fn != NULL)
39971 - ret = (*fn) (filp, cmd, arg);
39972 + if (drm_compat_ioctls[nr] != NULL)
39973 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39974 else
39975 ret = drm_ioctl(filp, cmd, arg);
39976
39977 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39978 index 66dd3a0..3bed6c4 100644
39979 --- a/drivers/gpu/drm/drm_stub.c
39980 +++ b/drivers/gpu/drm/drm_stub.c
39981 @@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39982
39983 drm_device_set_unplugged(dev);
39984
39985 - if (dev->open_count == 0) {
39986 + if (local_read(&dev->open_count) == 0) {
39987 drm_put_dev(dev);
39988 }
39989 mutex_unlock(&drm_global_mutex);
39990 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39991 index c22c309..ae758c3 100644
39992 --- a/drivers/gpu/drm/drm_sysfs.c
39993 +++ b/drivers/gpu/drm/drm_sysfs.c
39994 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39995 */
39996 int drm_sysfs_device_add(struct drm_minor *minor)
39997 {
39998 - char *minor_str;
39999 + const char *minor_str;
40000 int r;
40001
40002 if (minor->type == DRM_MINOR_CONTROL)
40003 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40004 index d4d16ed..8fb0b51 100644
40005 --- a/drivers/gpu/drm/i810/i810_drv.h
40006 +++ b/drivers/gpu/drm/i810/i810_drv.h
40007 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40008 int page_flipping;
40009
40010 wait_queue_head_t irq_queue;
40011 - atomic_t irq_received;
40012 - atomic_t irq_emitted;
40013 + atomic_unchecked_t irq_received;
40014 + atomic_unchecked_t irq_emitted;
40015
40016 int front_offset;
40017 } drm_i810_private_t;
40018 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40019 index 6ed45a9..eb6dc41 100644
40020 --- a/drivers/gpu/drm/i915/i915_debugfs.c
40021 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
40022 @@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40023 I915_READ(GTIMR));
40024 }
40025 seq_printf(m, "Interrupts received: %d\n",
40026 - atomic_read(&dev_priv->irq_received));
40027 + atomic_read_unchecked(&dev_priv->irq_received));
40028 for_each_ring(ring, dev_priv, i) {
40029 if (INTEL_INFO(dev)->gen >= 6) {
40030 seq_printf(m,
40031 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40032 index e02266a..e3411aa 100644
40033 --- a/drivers/gpu/drm/i915/i915_dma.c
40034 +++ b/drivers/gpu/drm/i915/i915_dma.c
40035 @@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40036 bool can_switch;
40037
40038 spin_lock(&dev->count_lock);
40039 - can_switch = (dev->open_count == 0);
40040 + can_switch = (local_read(&dev->open_count) == 0);
40041 spin_unlock(&dev->count_lock);
40042 return can_switch;
40043 }
40044 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40045 index 221ac62..f56acc8 100644
40046 --- a/drivers/gpu/drm/i915/i915_drv.h
40047 +++ b/drivers/gpu/drm/i915/i915_drv.h
40048 @@ -1326,7 +1326,7 @@ typedef struct drm_i915_private {
40049 drm_dma_handle_t *status_page_dmah;
40050 struct resource mch_res;
40051
40052 - atomic_t irq_received;
40053 + atomic_unchecked_t irq_received;
40054
40055 /* protects the irq masks */
40056 spinlock_t irq_lock;
40057 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40058 index a3ba9a8..ee52ddd 100644
40059 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40060 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40061 @@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40062
40063 static int
40064 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40065 - int count)
40066 + unsigned int count)
40067 {
40068 - int i;
40069 + unsigned int i;
40070 unsigned relocs_total = 0;
40071 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40072
40073 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40074 index 3c59584..500f2e9 100644
40075 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40076 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40077 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40078 (unsigned long)request);
40079 }
40080
40081 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40082 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40083 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40084 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40085 [DRM_I915_GETPARAM] = compat_i915_getparam,
40086 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40087 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40088 {
40089 unsigned int nr = DRM_IOCTL_NR(cmd);
40090 - drm_ioctl_compat_t *fn = NULL;
40091 int ret;
40092
40093 if (nr < DRM_COMMAND_BASE)
40094 return drm_compat_ioctl(filp, cmd, arg);
40095
40096 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40097 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40098 -
40099 - if (fn != NULL)
40100 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40101 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40102 ret = (*fn) (filp, cmd, arg);
40103 - else
40104 + } else
40105 ret = drm_ioctl(filp, cmd, arg);
40106
40107 return ret;
40108 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40109 index 9702704..3fb9e40 100644
40110 --- a/drivers/gpu/drm/i915/i915_irq.c
40111 +++ b/drivers/gpu/drm/i915/i915_irq.c
40112 @@ -1419,7 +1419,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40113 int pipe;
40114 u32 pipe_stats[I915_MAX_PIPES];
40115
40116 - atomic_inc(&dev_priv->irq_received);
40117 + atomic_inc_unchecked(&dev_priv->irq_received);
40118
40119 while (true) {
40120 iir = I915_READ(VLV_IIR);
40121 @@ -1729,7 +1729,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40122 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40123 irqreturn_t ret = IRQ_NONE;
40124
40125 - atomic_inc(&dev_priv->irq_received);
40126 + atomic_inc_unchecked(&dev_priv->irq_received);
40127
40128 /* We get interrupts on unclaimed registers, so check for this before we
40129 * do any I915_{READ,WRITE}. */
40130 @@ -1799,7 +1799,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40131 uint32_t tmp = 0;
40132 enum pipe pipe;
40133
40134 - atomic_inc(&dev_priv->irq_received);
40135 + atomic_inc_unchecked(&dev_priv->irq_received);
40136
40137 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40138 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40139 @@ -2623,7 +2623,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40140 {
40141 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40142
40143 - atomic_set(&dev_priv->irq_received, 0);
40144 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40145
40146 I915_WRITE(HWSTAM, 0xeffe);
40147
40148 @@ -2641,7 +2641,7 @@ static void valleyview_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 /* VLV magic */
40156 I915_WRITE(VLV_IMR, 0);
40157 @@ -2672,7 +2672,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40158 struct drm_i915_private *dev_priv = dev->dev_private;
40159 int pipe;
40160
40161 - atomic_set(&dev_priv->irq_received, 0);
40162 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40163
40164 I915_WRITE(GEN8_MASTER_IRQ, 0);
40165 POSTING_READ(GEN8_MASTER_IRQ);
40166 @@ -2996,7 +2996,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40167 if (!dev_priv)
40168 return;
40169
40170 - atomic_set(&dev_priv->irq_received, 0);
40171 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40172
40173 I915_WRITE(GEN8_MASTER_IRQ, 0);
40174
40175 @@ -3090,7 +3090,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40176 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40177 int pipe;
40178
40179 - atomic_set(&dev_priv->irq_received, 0);
40180 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40181
40182 for_each_pipe(pipe)
40183 I915_WRITE(PIPESTAT(pipe), 0);
40184 @@ -3176,7 +3176,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40185 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40186 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40187
40188 - atomic_inc(&dev_priv->irq_received);
40189 + atomic_inc_unchecked(&dev_priv->irq_received);
40190
40191 iir = I915_READ16(IIR);
40192 if (iir == 0)
40193 @@ -3251,7 +3251,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40194 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40195 int pipe;
40196
40197 - atomic_set(&dev_priv->irq_received, 0);
40198 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40199
40200 if (I915_HAS_HOTPLUG(dev)) {
40201 I915_WRITE(PORT_HOTPLUG_EN, 0);
40202 @@ -3358,7 +3358,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40203 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40204 int pipe, ret = IRQ_NONE;
40205
40206 - atomic_inc(&dev_priv->irq_received);
40207 + atomic_inc_unchecked(&dev_priv->irq_received);
40208
40209 iir = I915_READ(IIR);
40210 do {
40211 @@ -3485,7 +3485,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40212 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40213 int pipe;
40214
40215 - atomic_set(&dev_priv->irq_received, 0);
40216 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40217
40218 I915_WRITE(PORT_HOTPLUG_EN, 0);
40219 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40220 @@ -3601,7 +3601,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40221 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40222 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40223
40224 - atomic_inc(&dev_priv->irq_received);
40225 + atomic_inc_unchecked(&dev_priv->irq_received);
40226
40227 iir = I915_READ(IIR);
40228
40229 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40230 index 3c5ff7a..ae759ca 100644
40231 --- a/drivers/gpu/drm/i915/intel_display.c
40232 +++ b/drivers/gpu/drm/i915/intel_display.c
40233 @@ -10506,13 +10506,13 @@ struct intel_quirk {
40234 int subsystem_vendor;
40235 int subsystem_device;
40236 void (*hook)(struct drm_device *dev);
40237 -};
40238 +} __do_const;
40239
40240 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40241 struct intel_dmi_quirk {
40242 void (*hook)(struct drm_device *dev);
40243 const struct dmi_system_id (*dmi_id_list)[];
40244 -};
40245 +} __do_const;
40246
40247 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40248 {
40249 @@ -10520,18 +10520,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40250 return 1;
40251 }
40252
40253 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40254 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40255 {
40256 - .dmi_id_list = &(const struct dmi_system_id[]) {
40257 - {
40258 - .callback = intel_dmi_reverse_brightness,
40259 - .ident = "NCR Corporation",
40260 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40261 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40262 - },
40263 - },
40264 - { } /* terminating entry */
40265 + .callback = intel_dmi_reverse_brightness,
40266 + .ident = "NCR Corporation",
40267 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40268 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40269 },
40270 + },
40271 + { } /* terminating entry */
40272 +};
40273 +
40274 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40275 + {
40276 + .dmi_id_list = &intel_dmi_quirks_table,
40277 .hook = quirk_invert_brightness,
40278 },
40279 };
40280 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40281 index ca4bc54..ee598a2 100644
40282 --- a/drivers/gpu/drm/mga/mga_drv.h
40283 +++ b/drivers/gpu/drm/mga/mga_drv.h
40284 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40285 u32 clear_cmd;
40286 u32 maccess;
40287
40288 - atomic_t vbl_received; /**< Number of vblanks received. */
40289 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40290 wait_queue_head_t fence_queue;
40291 - atomic_t last_fence_retired;
40292 + atomic_unchecked_t last_fence_retired;
40293 u32 next_fence_to_post;
40294
40295 unsigned int fb_cpp;
40296 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40297 index 709e90d..89a1c0d 100644
40298 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40299 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40300 @@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40301 return 0;
40302 }
40303
40304 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40305 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40306 [DRM_MGA_INIT] = compat_mga_init,
40307 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40308 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40309 @@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40310 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40311 {
40312 unsigned int nr = DRM_IOCTL_NR(cmd);
40313 - drm_ioctl_compat_t *fn = NULL;
40314 int ret;
40315
40316 if (nr < DRM_COMMAND_BASE)
40317 return drm_compat_ioctl(filp, cmd, arg);
40318
40319 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40320 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40321 -
40322 - if (fn != NULL)
40323 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40324 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40325 ret = (*fn) (filp, cmd, arg);
40326 - else
40327 + } else
40328 ret = drm_ioctl(filp, cmd, arg);
40329
40330 return ret;
40331 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40332 index 2b0ceb8..517e99e 100644
40333 --- a/drivers/gpu/drm/mga/mga_irq.c
40334 +++ b/drivers/gpu/drm/mga/mga_irq.c
40335 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40336 if (crtc != 0)
40337 return 0;
40338
40339 - return atomic_read(&dev_priv->vbl_received);
40340 + return atomic_read_unchecked(&dev_priv->vbl_received);
40341 }
40342
40343
40344 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40345 /* VBLANK interrupt */
40346 if (status & MGA_VLINEPEN) {
40347 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40348 - atomic_inc(&dev_priv->vbl_received);
40349 + atomic_inc_unchecked(&dev_priv->vbl_received);
40350 drm_handle_vblank(dev, 0);
40351 handled = 1;
40352 }
40353 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40354 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40355 MGA_WRITE(MGA_PRIMEND, prim_end);
40356
40357 - atomic_inc(&dev_priv->last_fence_retired);
40358 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40359 DRM_WAKEUP(&dev_priv->fence_queue);
40360 handled = 1;
40361 }
40362 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40363 * using fences.
40364 */
40365 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
40366 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40367 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40368 - *sequence) <= (1 << 23)));
40369
40370 *sequence = cur_fence;
40371 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40372 index 4c3feaa..26391ce 100644
40373 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40374 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40375 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40376 struct bit_table {
40377 const char id;
40378 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40379 -};
40380 +} __no_const;
40381
40382 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40383
40384 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40385 index 4b0fb6c..67667a9 100644
40386 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40387 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40388 @@ -96,7 +96,6 @@ struct nouveau_drm {
40389 struct drm_global_reference mem_global_ref;
40390 struct ttm_bo_global_ref bo_global_ref;
40391 struct ttm_bo_device bdev;
40392 - atomic_t validate_sequence;
40393 int (*move)(struct nouveau_channel *,
40394 struct ttm_buffer_object *,
40395 struct ttm_mem_reg *, struct ttm_mem_reg *);
40396 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40397 index c1a7e5a..38b8539 100644
40398 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40399 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40400 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40401 unsigned long arg)
40402 {
40403 unsigned int nr = DRM_IOCTL_NR(cmd);
40404 - drm_ioctl_compat_t *fn = NULL;
40405 + drm_ioctl_compat_t fn = NULL;
40406 int ret;
40407
40408 if (nr < DRM_COMMAND_BASE)
40409 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40410 index 19e3757..ad16478 100644
40411 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40412 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40413 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40414 }
40415
40416 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40417 - nouveau_vram_manager_init,
40418 - nouveau_vram_manager_fini,
40419 - nouveau_vram_manager_new,
40420 - nouveau_vram_manager_del,
40421 - nouveau_vram_manager_debug
40422 + .init = nouveau_vram_manager_init,
40423 + .takedown = nouveau_vram_manager_fini,
40424 + .get_node = nouveau_vram_manager_new,
40425 + .put_node = nouveau_vram_manager_del,
40426 + .debug = nouveau_vram_manager_debug
40427 };
40428
40429 static int
40430 @@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40431 }
40432
40433 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40434 - nouveau_gart_manager_init,
40435 - nouveau_gart_manager_fini,
40436 - nouveau_gart_manager_new,
40437 - nouveau_gart_manager_del,
40438 - nouveau_gart_manager_debug
40439 + .init = nouveau_gart_manager_init,
40440 + .takedown = nouveau_gart_manager_fini,
40441 + .get_node = nouveau_gart_manager_new,
40442 + .put_node = nouveau_gart_manager_del,
40443 + .debug = nouveau_gart_manager_debug
40444 };
40445
40446 #include <core/subdev/vm/nv04.h>
40447 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40448 }
40449
40450 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40451 - nv04_gart_manager_init,
40452 - nv04_gart_manager_fini,
40453 - nv04_gart_manager_new,
40454 - nv04_gart_manager_del,
40455 - nv04_gart_manager_debug
40456 + .init = nv04_gart_manager_init,
40457 + .takedown = nv04_gart_manager_fini,
40458 + .get_node = nv04_gart_manager_new,
40459 + .put_node = nv04_gart_manager_del,
40460 + .debug = nv04_gart_manager_debug
40461 };
40462
40463 int
40464 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40465 index 81638d7..2e45854 100644
40466 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40467 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40468 @@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40469 bool can_switch;
40470
40471 spin_lock(&dev->count_lock);
40472 - can_switch = (dev->open_count == 0);
40473 + can_switch = (local_read(&dev->open_count) == 0);
40474 spin_unlock(&dev->count_lock);
40475 return can_switch;
40476 }
40477 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40478 index eb89653..613cf71 100644
40479 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40480 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40481 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40482 int ret;
40483
40484 mutex_lock(&qdev->async_io_mutex);
40485 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40486 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40487 if (qdev->last_sent_io_cmd > irq_num) {
40488 if (intr)
40489 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40490 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40491 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40492 else
40493 ret = wait_event_timeout(qdev->io_cmd_event,
40494 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40495 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40496 /* 0 is timeout, just bail the "hw" has gone away */
40497 if (ret <= 0)
40498 goto out;
40499 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40500 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40501 }
40502 outb(val, addr);
40503 qdev->last_sent_io_cmd = irq_num + 1;
40504 if (intr)
40505 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40506 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40507 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40508 else
40509 ret = wait_event_timeout(qdev->io_cmd_event,
40510 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40511 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40512 out:
40513 if (ret > 0)
40514 ret = 0;
40515 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40516 index c3c2bbd..bc3c0fb 100644
40517 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40518 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40519 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40520 struct drm_info_node *node = (struct drm_info_node *) m->private;
40521 struct qxl_device *qdev = node->minor->dev->dev_private;
40522
40523 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40524 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40525 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40526 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40527 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40528 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40529 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40530 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40531 seq_printf(m, "%d\n", qdev->irq_received_error);
40532 return 0;
40533 }
40534 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40535 index 7bda32f..dd98fc5 100644
40536 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40537 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40538 @@ -290,10 +290,10 @@ struct qxl_device {
40539 unsigned int last_sent_io_cmd;
40540
40541 /* interrupt handling */
40542 - atomic_t irq_received;
40543 - atomic_t irq_received_display;
40544 - atomic_t irq_received_cursor;
40545 - atomic_t irq_received_io_cmd;
40546 + atomic_unchecked_t irq_received;
40547 + atomic_unchecked_t irq_received_display;
40548 + atomic_unchecked_t irq_received_cursor;
40549 + atomic_unchecked_t irq_received_io_cmd;
40550 unsigned irq_received_error;
40551 wait_queue_head_t display_event;
40552 wait_queue_head_t cursor_event;
40553 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40554 index 7b95c75..9cffb4f 100644
40555 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40556 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40557 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40558
40559 /* TODO copy slow path code from i915 */
40560 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40561 - 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);
40562 + 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);
40563
40564 {
40565 struct qxl_drawable *draw = fb_cmd;
40566 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40567 struct drm_qxl_reloc reloc;
40568
40569 if (DRM_COPY_FROM_USER(&reloc,
40570 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40571 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40572 sizeof(reloc))) {
40573 ret = -EFAULT;
40574 goto out_free_bos;
40575 @@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40576 struct drm_qxl_command *commands =
40577 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40578
40579 - if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
40580 + if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40581 sizeof(user_cmd)))
40582 return -EFAULT;
40583
40584 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40585 index 21393dc..329f3a9 100644
40586 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40587 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40588 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
40589
40590 pending = xchg(&qdev->ram_header->int_pending, 0);
40591
40592 - atomic_inc(&qdev->irq_received);
40593 + atomic_inc_unchecked(&qdev->irq_received);
40594
40595 if (pending & QXL_INTERRUPT_DISPLAY) {
40596 - atomic_inc(&qdev->irq_received_display);
40597 + atomic_inc_unchecked(&qdev->irq_received_display);
40598 wake_up_all(&qdev->display_event);
40599 qxl_queue_garbage_collect(qdev, false);
40600 }
40601 if (pending & QXL_INTERRUPT_CURSOR) {
40602 - atomic_inc(&qdev->irq_received_cursor);
40603 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40604 wake_up_all(&qdev->cursor_event);
40605 }
40606 if (pending & QXL_INTERRUPT_IO_CMD) {
40607 - atomic_inc(&qdev->irq_received_io_cmd);
40608 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40609 wake_up_all(&qdev->io_cmd_event);
40610 }
40611 if (pending & QXL_INTERRUPT_ERROR) {
40612 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40613 init_waitqueue_head(&qdev->io_cmd_event);
40614 INIT_WORK(&qdev->client_monitors_config_work,
40615 qxl_client_monitors_config_work_func);
40616 - atomic_set(&qdev->irq_received, 0);
40617 - atomic_set(&qdev->irq_received_display, 0);
40618 - atomic_set(&qdev->irq_received_cursor, 0);
40619 - atomic_set(&qdev->irq_received_io_cmd, 0);
40620 + atomic_set_unchecked(&qdev->irq_received, 0);
40621 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40622 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40623 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40624 qdev->irq_received_error = 0;
40625 ret = drm_irq_install(qdev->ddev);
40626 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40627 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40628 index c7e7e65..7dddd4d 100644
40629 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40630 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40631 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40632 }
40633 }
40634
40635 -static struct vm_operations_struct qxl_ttm_vm_ops;
40636 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40637 static const struct vm_operations_struct *ttm_vm_ops;
40638
40639 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40640 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40641 return r;
40642 if (unlikely(ttm_vm_ops == NULL)) {
40643 ttm_vm_ops = vma->vm_ops;
40644 + pax_open_kernel();
40645 qxl_ttm_vm_ops = *ttm_vm_ops;
40646 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40647 + pax_close_kernel();
40648 }
40649 vma->vm_ops = &qxl_ttm_vm_ops;
40650 return 0;
40651 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40652 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40653 {
40654 #if defined(CONFIG_DEBUG_FS)
40655 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40656 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40657 - unsigned i;
40658 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40659 + {
40660 + .name = "qxl_mem_mm",
40661 + .show = &qxl_mm_dump_table,
40662 + },
40663 + {
40664 + .name = "qxl_surf_mm",
40665 + .show = &qxl_mm_dump_table,
40666 + }
40667 + };
40668
40669 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40670 - if (i == 0)
40671 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40672 - else
40673 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40674 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40675 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40676 - qxl_mem_types_list[i].driver_features = 0;
40677 - if (i == 0)
40678 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40679 - else
40680 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40681 + pax_open_kernel();
40682 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40683 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40684 + pax_close_kernel();
40685
40686 - }
40687 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40688 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40689 #else
40690 return 0;
40691 #endif
40692 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40693 index c451257..0ad2134 100644
40694 --- a/drivers/gpu/drm/r128/r128_cce.c
40695 +++ b/drivers/gpu/drm/r128/r128_cce.c
40696 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40697
40698 /* GH: Simple idle check.
40699 */
40700 - atomic_set(&dev_priv->idle_count, 0);
40701 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40702
40703 /* We don't support anything other than bus-mastering ring mode,
40704 * but the ring can be in either AGP or PCI space for the ring
40705 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40706 index 56eb5e3..c4ec43d 100644
40707 --- a/drivers/gpu/drm/r128/r128_drv.h
40708 +++ b/drivers/gpu/drm/r128/r128_drv.h
40709 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40710 int is_pci;
40711 unsigned long cce_buffers_offset;
40712
40713 - atomic_t idle_count;
40714 + atomic_unchecked_t idle_count;
40715
40716 int page_flipping;
40717 int current_page;
40718 u32 crtc_offset;
40719 u32 crtc_offset_cntl;
40720
40721 - atomic_t vbl_received;
40722 + atomic_unchecked_t vbl_received;
40723
40724 u32 color_fmt;
40725 unsigned int front_offset;
40726 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40727 index a954c54..9cc595c 100644
40728 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40729 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40730 @@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40731 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40732 }
40733
40734 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40735 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40736 [DRM_R128_INIT] = compat_r128_init,
40737 [DRM_R128_DEPTH] = compat_r128_depth,
40738 [DRM_R128_STIPPLE] = compat_r128_stipple,
40739 @@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40740 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40741 {
40742 unsigned int nr = DRM_IOCTL_NR(cmd);
40743 - drm_ioctl_compat_t *fn = NULL;
40744 int ret;
40745
40746 if (nr < DRM_COMMAND_BASE)
40747 return drm_compat_ioctl(filp, cmd, arg);
40748
40749 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40750 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40751 -
40752 - if (fn != NULL)
40753 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40754 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40755 ret = (*fn) (filp, cmd, arg);
40756 - else
40757 + } else
40758 ret = drm_ioctl(filp, cmd, arg);
40759
40760 return ret;
40761 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40762 index 2ea4f09..d391371 100644
40763 --- a/drivers/gpu/drm/r128/r128_irq.c
40764 +++ b/drivers/gpu/drm/r128/r128_irq.c
40765 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40766 if (crtc != 0)
40767 return 0;
40768
40769 - return atomic_read(&dev_priv->vbl_received);
40770 + return atomic_read_unchecked(&dev_priv->vbl_received);
40771 }
40772
40773 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40774 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40775 /* VBLANK interrupt */
40776 if (status & R128_CRTC_VBLANK_INT) {
40777 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40778 - atomic_inc(&dev_priv->vbl_received);
40779 + atomic_inc_unchecked(&dev_priv->vbl_received);
40780 drm_handle_vblank(dev, 0);
40781 return IRQ_HANDLED;
40782 }
40783 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40784 index 01dd9ae..6352f04 100644
40785 --- a/drivers/gpu/drm/r128/r128_state.c
40786 +++ b/drivers/gpu/drm/r128/r128_state.c
40787 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40788
40789 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40790 {
40791 - if (atomic_read(&dev_priv->idle_count) == 0)
40792 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40793 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40794 else
40795 - atomic_set(&dev_priv->idle_count, 0);
40796 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40797 }
40798
40799 #endif
40800 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40801 index af85299..ed9ac8d 100644
40802 --- a/drivers/gpu/drm/radeon/mkregtable.c
40803 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40804 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40805 regex_t mask_rex;
40806 regmatch_t match[4];
40807 char buf[1024];
40808 - size_t end;
40809 + long end;
40810 int len;
40811 int done = 0;
40812 int r;
40813 unsigned o;
40814 struct offset *offset;
40815 char last_reg_s[10];
40816 - int last_reg;
40817 + unsigned long last_reg;
40818
40819 if (regcomp
40820 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40821 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40822 index 39b033b..6efc056 100644
40823 --- a/drivers/gpu/drm/radeon/radeon_device.c
40824 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40825 @@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40826 bool can_switch;
40827
40828 spin_lock(&dev->count_lock);
40829 - can_switch = (dev->open_count == 0);
40830 + can_switch = (local_read(&dev->open_count) == 0);
40831 spin_unlock(&dev->count_lock);
40832 return can_switch;
40833 }
40834 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40835 index 00e0d44..08381a4 100644
40836 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40837 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40838 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40839
40840 /* SW interrupt */
40841 wait_queue_head_t swi_queue;
40842 - atomic_t swi_emitted;
40843 + atomic_unchecked_t swi_emitted;
40844 int vblank_crtc;
40845 uint32_t irq_enable_reg;
40846 uint32_t r500_disp_irq_reg;
40847 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40848 index bdb0f93..5ff558f 100644
40849 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40850 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40851 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40852 request = compat_alloc_user_space(sizeof(*request));
40853 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40854 || __put_user(req32.param, &request->param)
40855 - || __put_user((void __user *)(unsigned long)req32.value,
40856 + || __put_user((unsigned long)req32.value,
40857 &request->value))
40858 return -EFAULT;
40859
40860 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40861 #define compat_radeon_cp_setparam NULL
40862 #endif /* X86_64 || IA64 */
40863
40864 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40865 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40866 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40867 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40868 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40869 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40870 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40871 {
40872 unsigned int nr = DRM_IOCTL_NR(cmd);
40873 - drm_ioctl_compat_t *fn = NULL;
40874 int ret;
40875
40876 if (nr < DRM_COMMAND_BASE)
40877 return drm_compat_ioctl(filp, cmd, arg);
40878
40879 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40880 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40881 -
40882 - if (fn != NULL)
40883 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40884 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40885 ret = (*fn) (filp, cmd, arg);
40886 - else
40887 + } else
40888 ret = drm_ioctl(filp, cmd, arg);
40889
40890 return ret;
40891 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40892 index 8d68e97..9dcfed8 100644
40893 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40894 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40895 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40896 unsigned int ret;
40897 RING_LOCALS;
40898
40899 - atomic_inc(&dev_priv->swi_emitted);
40900 - ret = atomic_read(&dev_priv->swi_emitted);
40901 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40902 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40903
40904 BEGIN_RING(4);
40905 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40906 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40907 drm_radeon_private_t *dev_priv =
40908 (drm_radeon_private_t *) dev->dev_private;
40909
40910 - atomic_set(&dev_priv->swi_emitted, 0);
40911 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40912 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40913
40914 dev->max_vblank_count = 0x001fffff;
40915 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40916 index 4d20910..6726b6d 100644
40917 --- a/drivers/gpu/drm/radeon/radeon_state.c
40918 +++ b/drivers/gpu/drm/radeon/radeon_state.c
40919 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40920 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40921 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40922
40923 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40924 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40925 sarea_priv->nbox * sizeof(depth_boxes[0])))
40926 return -EFAULT;
40927
40928 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40929 {
40930 drm_radeon_private_t *dev_priv = dev->dev_private;
40931 drm_radeon_getparam_t *param = data;
40932 - int value;
40933 + int value = 0;
40934
40935 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40936
40937 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40938 index 84323c9..cf07baf 100644
40939 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
40940 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40941 @@ -787,7 +787,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40942 man->size = size >> PAGE_SHIFT;
40943 }
40944
40945 -static struct vm_operations_struct radeon_ttm_vm_ops;
40946 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40947 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40948
40949 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40950 @@ -828,8 +828,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40951 }
40952 if (unlikely(ttm_vm_ops == NULL)) {
40953 ttm_vm_ops = vma->vm_ops;
40954 + pax_open_kernel();
40955 radeon_ttm_vm_ops = *ttm_vm_ops;
40956 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40957 + pax_close_kernel();
40958 }
40959 vma->vm_ops = &radeon_ttm_vm_ops;
40960 return 0;
40961 @@ -858,38 +860,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40962 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40963 {
40964 #if defined(CONFIG_DEBUG_FS)
40965 - static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40966 - static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40967 - unsigned i;
40968 + static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40969 + {
40970 + .name = "radeon_vram_mm",
40971 + .show = &radeon_mm_dump_table,
40972 + },
40973 + {
40974 + .name = "radeon_gtt_mm",
40975 + .show = &radeon_mm_dump_table,
40976 + },
40977 + {
40978 + .name = "ttm_page_pool",
40979 + .show = &ttm_page_alloc_debugfs,
40980 + },
40981 + {
40982 + .name = "ttm_dma_page_pool",
40983 + .show = &ttm_dma_page_alloc_debugfs,
40984 + },
40985 + };
40986 + unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40987
40988 - for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40989 - if (i == 0)
40990 - sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40991 - else
40992 - sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40993 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40994 - radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40995 - radeon_mem_types_list[i].driver_features = 0;
40996 - if (i == 0)
40997 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40998 - else
40999 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
41000 -
41001 - }
41002 - /* Add ttm page pool to debugfs */
41003 - sprintf(radeon_mem_types_names[i], "ttm_page_pool");
41004 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
41005 - radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
41006 - radeon_mem_types_list[i].driver_features = 0;
41007 - radeon_mem_types_list[i++].data = NULL;
41008 + pax_open_kernel();
41009 + *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
41010 + *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
41011 + pax_close_kernel();
41012 #ifdef CONFIG_SWIOTLB
41013 - if (swiotlb_nr_tbl()) {
41014 - sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
41015 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
41016 - radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
41017 - radeon_mem_types_list[i].driver_features = 0;
41018 - radeon_mem_types_list[i++].data = NULL;
41019 - }
41020 + if (swiotlb_nr_tbl())
41021 + i++;
41022 #endif
41023 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
41024
41025 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41026 index ae1cb31..5b5b6b7c 100644
41027 --- a/drivers/gpu/drm/tegra/dc.c
41028 +++ b/drivers/gpu/drm/tegra/dc.c
41029 @@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41030 }
41031
41032 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41033 - dc->debugfs_files[i].data = dc;
41034 + *(void **)&dc->debugfs_files[i].data = dc;
41035
41036 err = drm_debugfs_create_files(dc->debugfs_files,
41037 ARRAY_SIZE(debugfs_files),
41038 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41039 index 0cd9bc2..9759be4 100644
41040 --- a/drivers/gpu/drm/tegra/hdmi.c
41041 +++ b/drivers/gpu/drm/tegra/hdmi.c
41042 @@ -57,7 +57,7 @@ struct tegra_hdmi {
41043 bool stereo;
41044 bool dvi;
41045
41046 - struct drm_info_list *debugfs_files;
41047 + drm_info_list_no_const *debugfs_files;
41048 struct drm_minor *minor;
41049 struct dentry *debugfs;
41050 };
41051 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41052 index c58eba33..83c2728 100644
41053 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41054 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41055 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41056 }
41057
41058 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41059 - ttm_bo_man_init,
41060 - ttm_bo_man_takedown,
41061 - ttm_bo_man_get_node,
41062 - ttm_bo_man_put_node,
41063 - ttm_bo_man_debug
41064 + .init = ttm_bo_man_init,
41065 + .takedown = ttm_bo_man_takedown,
41066 + .get_node = ttm_bo_man_get_node,
41067 + .put_node = ttm_bo_man_put_node,
41068 + .debug = ttm_bo_man_debug
41069 };
41070 EXPORT_SYMBOL(ttm_bo_manager_func);
41071 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41072 index dbc2def..0a9f710 100644
41073 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41074 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41075 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41076 zone->glob = glob;
41077 glob->zone_kernel = zone;
41078 ret = kobject_init_and_add(
41079 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41080 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41081 if (unlikely(ret != 0)) {
41082 kobject_put(&zone->kobj);
41083 return ret;
41084 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41085 zone->glob = glob;
41086 glob->zone_dma32 = zone;
41087 ret = kobject_init_and_add(
41088 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41089 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41090 if (unlikely(ret != 0)) {
41091 kobject_put(&zone->kobj);
41092 return ret;
41093 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41094 index 863bef9..cba15cf 100644
41095 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41096 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41097 @@ -391,9 +391,9 @@ out:
41098 static unsigned long
41099 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41100 {
41101 - static atomic_t start_pool = ATOMIC_INIT(0);
41102 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41103 unsigned i;
41104 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41105 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41106 struct ttm_page_pool *pool;
41107 int shrink_pages = sc->nr_to_scan;
41108 unsigned long freed = 0;
41109 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41110 index 97e9d61..bf23c461 100644
41111 --- a/drivers/gpu/drm/udl/udl_fb.c
41112 +++ b/drivers/gpu/drm/udl/udl_fb.c
41113 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41114 fb_deferred_io_cleanup(info);
41115 kfree(info->fbdefio);
41116 info->fbdefio = NULL;
41117 - info->fbops->fb_mmap = udl_fb_mmap;
41118 }
41119
41120 pr_warn("released /dev/fb%d user=%d count=%d\n",
41121 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41122 index a811ef2..ff99b05 100644
41123 --- a/drivers/gpu/drm/via/via_drv.h
41124 +++ b/drivers/gpu/drm/via/via_drv.h
41125 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41126 typedef uint32_t maskarray_t[5];
41127
41128 typedef struct drm_via_irq {
41129 - atomic_t irq_received;
41130 + atomic_unchecked_t irq_received;
41131 uint32_t pending_mask;
41132 uint32_t enable_mask;
41133 wait_queue_head_t irq_queue;
41134 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41135 struct timeval last_vblank;
41136 int last_vblank_valid;
41137 unsigned usec_per_vblank;
41138 - atomic_t vbl_received;
41139 + atomic_unchecked_t vbl_received;
41140 drm_via_state_t hc_state;
41141 char pci_buf[VIA_PCI_BUF_SIZE];
41142 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41143 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41144 index ac98964..5dbf512 100644
41145 --- a/drivers/gpu/drm/via/via_irq.c
41146 +++ b/drivers/gpu/drm/via/via_irq.c
41147 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41148 if (crtc != 0)
41149 return 0;
41150
41151 - return atomic_read(&dev_priv->vbl_received);
41152 + return atomic_read_unchecked(&dev_priv->vbl_received);
41153 }
41154
41155 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41156 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41157
41158 status = VIA_READ(VIA_REG_INTERRUPT);
41159 if (status & VIA_IRQ_VBLANK_PENDING) {
41160 - atomic_inc(&dev_priv->vbl_received);
41161 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41162 + atomic_inc_unchecked(&dev_priv->vbl_received);
41163 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41164 do_gettimeofday(&cur_vblank);
41165 if (dev_priv->last_vblank_valid) {
41166 dev_priv->usec_per_vblank =
41167 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41168 dev_priv->last_vblank = cur_vblank;
41169 dev_priv->last_vblank_valid = 1;
41170 }
41171 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41172 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41173 DRM_DEBUG("US per vblank is: %u\n",
41174 dev_priv->usec_per_vblank);
41175 }
41176 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41177
41178 for (i = 0; i < dev_priv->num_irqs; ++i) {
41179 if (status & cur_irq->pending_mask) {
41180 - atomic_inc(&cur_irq->irq_received);
41181 + atomic_inc_unchecked(&cur_irq->irq_received);
41182 DRM_WAKEUP(&cur_irq->irq_queue);
41183 handled = 1;
41184 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41185 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41186 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41187 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41188 masks[irq][4]));
41189 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41190 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41191 } else {
41192 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41193 (((cur_irq_sequence =
41194 - atomic_read(&cur_irq->irq_received)) -
41195 + atomic_read_unchecked(&cur_irq->irq_received)) -
41196 *sequence) <= (1 << 23)));
41197 }
41198 *sequence = cur_irq_sequence;
41199 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41200 }
41201
41202 for (i = 0; i < dev_priv->num_irqs; ++i) {
41203 - atomic_set(&cur_irq->irq_received, 0);
41204 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41205 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41206 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41207 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
41208 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41209 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41210 case VIA_IRQ_RELATIVE:
41211 irqwait->request.sequence +=
41212 - atomic_read(&cur_irq->irq_received);
41213 + atomic_read_unchecked(&cur_irq->irq_received);
41214 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41215 case VIA_IRQ_ABSOLUTE:
41216 break;
41217 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41218 index c0b73b9..f6f7f34 100644
41219 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41220 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41221 @@ -341,7 +341,7 @@ struct vmw_private {
41222 * Fencing and IRQs.
41223 */
41224
41225 - atomic_t marker_seq;
41226 + atomic_unchecked_t marker_seq;
41227 wait_queue_head_t fence_queue;
41228 wait_queue_head_t fifo_queue;
41229 int fence_queue_waiters; /* Protected by hw_mutex */
41230 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41231 index 3eb1486..0a47ee9 100644
41232 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41233 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41234 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41235 (unsigned int) min,
41236 (unsigned int) fifo->capabilities);
41237
41238 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41239 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41240 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41241 vmw_marker_queue_init(&fifo->marker_queue);
41242 return vmw_fifo_send_fence(dev_priv, &dummy);
41243 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41244 if (reserveable)
41245 iowrite32(bytes, fifo_mem +
41246 SVGA_FIFO_RESERVED);
41247 - return fifo_mem + (next_cmd >> 2);
41248 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41249 } else {
41250 need_bounce = true;
41251 }
41252 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41253
41254 fm = vmw_fifo_reserve(dev_priv, bytes);
41255 if (unlikely(fm == NULL)) {
41256 - *seqno = atomic_read(&dev_priv->marker_seq);
41257 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41258 ret = -ENOMEM;
41259 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41260 false, 3*HZ);
41261 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41262 }
41263
41264 do {
41265 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41266 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41267 } while (*seqno == 0);
41268
41269 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41270 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41271 index c5c054a..46f0548 100644
41272 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41273 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41274 @@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41275 }
41276
41277 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41278 - vmw_gmrid_man_init,
41279 - vmw_gmrid_man_takedown,
41280 - vmw_gmrid_man_get_node,
41281 - vmw_gmrid_man_put_node,
41282 - vmw_gmrid_man_debug
41283 + .init = vmw_gmrid_man_init,
41284 + .takedown = vmw_gmrid_man_takedown,
41285 + .get_node = vmw_gmrid_man_get_node,
41286 + .put_node = vmw_gmrid_man_put_node,
41287 + .debug = vmw_gmrid_man_debug
41288 };
41289 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41290 index 45d5b5a..f3f5e4e 100644
41291 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41292 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41293 @@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41294 int ret;
41295
41296 num_clips = arg->num_clips;
41297 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41298 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41299
41300 if (unlikely(num_clips == 0))
41301 return 0;
41302 @@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41303 int ret;
41304
41305 num_clips = arg->num_clips;
41306 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41307 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41308
41309 if (unlikely(num_clips == 0))
41310 return 0;
41311 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41312 index 4640adb..e1384ed 100644
41313 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41314 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41315 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41316 * emitted. Then the fence is stale and signaled.
41317 */
41318
41319 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41320 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41321 > VMW_FENCE_WRAP);
41322
41323 return ret;
41324 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41325
41326 if (fifo_idle)
41327 down_read(&fifo_state->rwsem);
41328 - signal_seq = atomic_read(&dev_priv->marker_seq);
41329 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41330 ret = 0;
41331
41332 for (;;) {
41333 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41334 index 8a8725c2..afed796 100644
41335 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41336 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41337 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41338 while (!vmw_lag_lt(queue, us)) {
41339 spin_lock(&queue->lock);
41340 if (list_empty(&queue->head))
41341 - seqno = atomic_read(&dev_priv->marker_seq);
41342 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41343 else {
41344 marker = list_first_entry(&queue->head,
41345 struct vmw_marker, head);
41346 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41347 index ec0ae2d..dc0780b 100644
41348 --- a/drivers/gpu/vga/vga_switcheroo.c
41349 +++ b/drivers/gpu/vga/vga_switcheroo.c
41350 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41351
41352 /* this version is for the case where the power switch is separate
41353 to the device being powered down. */
41354 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41355 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41356 {
41357 /* copy over all the bus versions */
41358 if (dev->bus && dev->bus->pm) {
41359 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41360 return ret;
41361 }
41362
41363 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41364 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41365 {
41366 /* copy over all the bus versions */
41367 if (dev->bus && dev->bus->pm) {
41368 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41369 index 253fe23..0dfec5f 100644
41370 --- a/drivers/hid/hid-core.c
41371 +++ b/drivers/hid/hid-core.c
41372 @@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41373
41374 int hid_add_device(struct hid_device *hdev)
41375 {
41376 - static atomic_t id = ATOMIC_INIT(0);
41377 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41378 int ret;
41379
41380 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41381 @@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
41382 /* XXX hack, any other cleaner solution after the driver core
41383 * is converted to allow more than 20 bytes as the device name? */
41384 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41385 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41386 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41387
41388 hid_debug_register(hdev, dev_name(&hdev->dev));
41389 ret = device_add(&hdev->dev);
41390 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41391 index c13fb5b..55a3802 100644
41392 --- a/drivers/hid/hid-wiimote-debug.c
41393 +++ b/drivers/hid/hid-wiimote-debug.c
41394 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41395 else if (size == 0)
41396 return -EIO;
41397
41398 - if (copy_to_user(u, buf, size))
41399 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41400 return -EFAULT;
41401
41402 *off += size;
41403 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41404 index cedc6da..2c3da2a 100644
41405 --- a/drivers/hid/uhid.c
41406 +++ b/drivers/hid/uhid.c
41407 @@ -47,7 +47,7 @@ struct uhid_device {
41408 struct mutex report_lock;
41409 wait_queue_head_t report_wait;
41410 atomic_t report_done;
41411 - atomic_t report_id;
41412 + atomic_unchecked_t report_id;
41413 struct uhid_event report_buf;
41414 };
41415
41416 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41417
41418 spin_lock_irqsave(&uhid->qlock, flags);
41419 ev->type = UHID_FEATURE;
41420 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41421 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41422 ev->u.feature.rnum = rnum;
41423 ev->u.feature.rtype = report_type;
41424
41425 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41426 spin_lock_irqsave(&uhid->qlock, flags);
41427
41428 /* id for old report; drop it silently */
41429 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41430 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41431 goto unlock;
41432 if (atomic_read(&uhid->report_done))
41433 goto unlock;
41434 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41435 index cea623c..73011b0 100644
41436 --- a/drivers/hv/channel.c
41437 +++ b/drivers/hv/channel.c
41438 @@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41439 int ret = 0;
41440 int t;
41441
41442 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41443 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41444 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41445 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41446
41447 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41448 if (ret)
41449 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41450 index f0c5e07..49a4d4a 100644
41451 --- a/drivers/hv/hv.c
41452 +++ b/drivers/hv/hv.c
41453 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41454 u64 output_address = (output) ? virt_to_phys(output) : 0;
41455 u32 output_address_hi = output_address >> 32;
41456 u32 output_address_lo = output_address & 0xFFFFFFFF;
41457 - void *hypercall_page = hv_context.hypercall_page;
41458 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41459
41460 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41461 "=a"(hv_status_lo) : "d" (control_hi),
41462 @@ -154,7 +154,7 @@ int hv_init(void)
41463 /* See if the hypercall page is already set */
41464 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41465
41466 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41467 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41468
41469 if (!virtaddr)
41470 goto cleanup;
41471 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41472 index 7e17a54..a50a33d 100644
41473 --- a/drivers/hv/hv_balloon.c
41474 +++ b/drivers/hv/hv_balloon.c
41475 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41476
41477 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41478 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41479 -static atomic_t trans_id = ATOMIC_INIT(0);
41480 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41481
41482 static int dm_ring_size = (5 * PAGE_SIZE);
41483
41484 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41485 pr_info("Memory hot add failed\n");
41486
41487 dm->state = DM_INITIALIZED;
41488 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41489 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41490 vmbus_sendpacket(dm->dev->channel, &resp,
41491 sizeof(struct dm_hot_add_response),
41492 (unsigned long)NULL,
41493 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41494 memset(&status, 0, sizeof(struct dm_status));
41495 status.hdr.type = DM_STATUS_REPORT;
41496 status.hdr.size = sizeof(struct dm_status);
41497 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41498 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41499
41500 /*
41501 * The host expects the guest to report free memory.
41502 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41503 * send the status. This can happen if we were interrupted
41504 * after we picked our transaction ID.
41505 */
41506 - if (status.hdr.trans_id != atomic_read(&trans_id))
41507 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41508 return;
41509
41510 vmbus_sendpacket(dm->dev->channel, &status,
41511 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41512 */
41513
41514 do {
41515 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41516 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41517 ret = vmbus_sendpacket(dm_device.dev->channel,
41518 bl_resp,
41519 bl_resp->hdr.size,
41520 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41521
41522 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41523 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41524 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41525 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41526 resp.hdr.size = sizeof(struct dm_unballoon_response);
41527
41528 vmbus_sendpacket(dm_device.dev->channel, &resp,
41529 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41530 memset(&version_req, 0, sizeof(struct dm_version_request));
41531 version_req.hdr.type = DM_VERSION_REQUEST;
41532 version_req.hdr.size = sizeof(struct dm_version_request);
41533 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41534 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41535 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41536 version_req.is_last_attempt = 1;
41537
41538 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41539 memset(&version_req, 0, sizeof(struct dm_version_request));
41540 version_req.hdr.type = DM_VERSION_REQUEST;
41541 version_req.hdr.size = sizeof(struct dm_version_request);
41542 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41543 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41544 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41545 version_req.is_last_attempt = 0;
41546
41547 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41548 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41549 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41550 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41551 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41552 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41553
41554 cap_msg.caps.cap_bits.balloon = 1;
41555 cap_msg.caps.cap_bits.hot_add = 1;
41556 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41557 index e055176..c22ff1f 100644
41558 --- a/drivers/hv/hyperv_vmbus.h
41559 +++ b/drivers/hv/hyperv_vmbus.h
41560 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41561 struct vmbus_connection {
41562 enum vmbus_connect_state conn_state;
41563
41564 - atomic_t next_gpadl_handle;
41565 + atomic_unchecked_t next_gpadl_handle;
41566
41567 /*
41568 * Represents channel interrupts. Each bit position represents a
41569 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41570 index 48aad4f..c768fb2 100644
41571 --- a/drivers/hv/vmbus_drv.c
41572 +++ b/drivers/hv/vmbus_drv.c
41573 @@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41574 {
41575 int ret = 0;
41576
41577 - static atomic_t device_num = ATOMIC_INIT(0);
41578 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41579
41580 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41581 - atomic_inc_return(&device_num));
41582 + atomic_inc_return_unchecked(&device_num));
41583
41584 child_device_obj->device.bus = &hv_bus;
41585 child_device_obj->device.parent = &hv_acpi_dev->dev;
41586 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41587 index 6a34f7f..aa4c3a6 100644
41588 --- a/drivers/hwmon/acpi_power_meter.c
41589 +++ b/drivers/hwmon/acpi_power_meter.c
41590 @@ -117,7 +117,7 @@ struct sensor_template {
41591 struct device_attribute *devattr,
41592 const char *buf, size_t count);
41593 int index;
41594 -};
41595 +} __do_const;
41596
41597 /* Averaging interval */
41598 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41599 @@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41600 struct sensor_template *attrs)
41601 {
41602 struct device *dev = &resource->acpi_dev->dev;
41603 - struct sensor_device_attribute *sensors =
41604 + sensor_device_attribute_no_const *sensors =
41605 &resource->sensors[resource->num_sensors];
41606 int res = 0;
41607
41608 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41609 index 3288f13..71cfb4e 100644
41610 --- a/drivers/hwmon/applesmc.c
41611 +++ b/drivers/hwmon/applesmc.c
41612 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41613 {
41614 struct applesmc_node_group *grp;
41615 struct applesmc_dev_attr *node;
41616 - struct attribute *attr;
41617 + attribute_no_const *attr;
41618 int ret, i;
41619
41620 for (grp = groups; grp->format; grp++) {
41621 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41622 index dafc63c..4abb96c 100644
41623 --- a/drivers/hwmon/asus_atk0110.c
41624 +++ b/drivers/hwmon/asus_atk0110.c
41625 @@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41626 struct atk_sensor_data {
41627 struct list_head list;
41628 struct atk_data *data;
41629 - struct device_attribute label_attr;
41630 - struct device_attribute input_attr;
41631 - struct device_attribute limit1_attr;
41632 - struct device_attribute limit2_attr;
41633 + device_attribute_no_const label_attr;
41634 + device_attribute_no_const input_attr;
41635 + device_attribute_no_const limit1_attr;
41636 + device_attribute_no_const limit2_attr;
41637 char label_attr_name[ATTR_NAME_SIZE];
41638 char input_attr_name[ATTR_NAME_SIZE];
41639 char limit1_attr_name[ATTR_NAME_SIZE];
41640 @@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
41641 static struct device_attribute atk_name_attr =
41642 __ATTR(name, 0444, atk_name_show, NULL);
41643
41644 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41645 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41646 sysfs_show_func show)
41647 {
41648 sysfs_attr_init(&attr->attr);
41649 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41650 index 9425098..7646cc5 100644
41651 --- a/drivers/hwmon/coretemp.c
41652 +++ b/drivers/hwmon/coretemp.c
41653 @@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41654 return NOTIFY_OK;
41655 }
41656
41657 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41658 +static struct notifier_block coretemp_cpu_notifier = {
41659 .notifier_call = coretemp_cpu_callback,
41660 };
41661
41662 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41663 index 632f1dc..57e6a58 100644
41664 --- a/drivers/hwmon/ibmaem.c
41665 +++ b/drivers/hwmon/ibmaem.c
41666 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41667 struct aem_rw_sensor_template *rw)
41668 {
41669 struct device *dev = &data->pdev->dev;
41670 - struct sensor_device_attribute *sensors = data->sensors;
41671 + sensor_device_attribute_no_const *sensors = data->sensors;
41672 int err;
41673
41674 /* Set up read-only sensors */
41675 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41676 index 708081b..fe2d4ab 100644
41677 --- a/drivers/hwmon/iio_hwmon.c
41678 +++ b/drivers/hwmon/iio_hwmon.c
41679 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41680 {
41681 struct device *dev = &pdev->dev;
41682 struct iio_hwmon_state *st;
41683 - struct sensor_device_attribute *a;
41684 + sensor_device_attribute_no_const *a;
41685 int ret, i;
41686 int in_i = 1, temp_i = 1, curr_i = 1;
41687 enum iio_chan_type type;
41688 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41689 index cf811c1..4c17110 100644
41690 --- a/drivers/hwmon/nct6775.c
41691 +++ b/drivers/hwmon/nct6775.c
41692 @@ -944,10 +944,10 @@ static struct attribute_group *
41693 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41694 int repeat)
41695 {
41696 - struct attribute_group *group;
41697 + attribute_group_no_const *group;
41698 struct sensor_device_attr_u *su;
41699 - struct sensor_device_attribute *a;
41700 - struct sensor_device_attribute_2 *a2;
41701 + sensor_device_attribute_no_const *a;
41702 + sensor_device_attribute_2_no_const *a2;
41703 struct attribute **attrs;
41704 struct sensor_device_template **t;
41705 int i, count;
41706 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41707 index 3cbf66e..8c5cc2a 100644
41708 --- a/drivers/hwmon/pmbus/pmbus_core.c
41709 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41710 @@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41711 return 0;
41712 }
41713
41714 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41715 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41716 const char *name,
41717 umode_t mode,
41718 ssize_t (*show)(struct device *dev,
41719 @@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41720 dev_attr->store = store;
41721 }
41722
41723 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41724 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41725 const char *name,
41726 umode_t mode,
41727 ssize_t (*show)(struct device *dev,
41728 @@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41729 u16 reg, u8 mask)
41730 {
41731 struct pmbus_boolean *boolean;
41732 - struct sensor_device_attribute *a;
41733 + sensor_device_attribute_no_const *a;
41734
41735 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41736 if (!boolean)
41737 @@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41738 bool update, bool readonly)
41739 {
41740 struct pmbus_sensor *sensor;
41741 - struct device_attribute *a;
41742 + device_attribute_no_const *a;
41743
41744 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41745 if (!sensor)
41746 @@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41747 const char *lstring, int index)
41748 {
41749 struct pmbus_label *label;
41750 - struct device_attribute *a;
41751 + device_attribute_no_const *a;
41752
41753 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41754 if (!label)
41755 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41756 index 97cd45a..ac54d8b 100644
41757 --- a/drivers/hwmon/sht15.c
41758 +++ b/drivers/hwmon/sht15.c
41759 @@ -169,7 +169,7 @@ struct sht15_data {
41760 int supply_uv;
41761 bool supply_uv_valid;
41762 struct work_struct update_supply_work;
41763 - atomic_t interrupt_handled;
41764 + atomic_unchecked_t interrupt_handled;
41765 };
41766
41767 /**
41768 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41769 ret = gpio_direction_input(data->pdata->gpio_data);
41770 if (ret)
41771 return ret;
41772 - atomic_set(&data->interrupt_handled, 0);
41773 + atomic_set_unchecked(&data->interrupt_handled, 0);
41774
41775 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41776 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41777 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41778 /* Only relevant if the interrupt hasn't occurred. */
41779 - if (!atomic_read(&data->interrupt_handled))
41780 + if (!atomic_read_unchecked(&data->interrupt_handled))
41781 schedule_work(&data->read_work);
41782 }
41783 ret = wait_event_timeout(data->wait_queue,
41784 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41785
41786 /* First disable the interrupt */
41787 disable_irq_nosync(irq);
41788 - atomic_inc(&data->interrupt_handled);
41789 + atomic_inc_unchecked(&data->interrupt_handled);
41790 /* Then schedule a reading work struct */
41791 if (data->state != SHT15_READING_NOTHING)
41792 schedule_work(&data->read_work);
41793 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41794 * If not, then start the interrupt again - care here as could
41795 * have gone low in meantime so verify it hasn't!
41796 */
41797 - atomic_set(&data->interrupt_handled, 0);
41798 + atomic_set_unchecked(&data->interrupt_handled, 0);
41799 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41800 /* If still not occurred or another handler was scheduled */
41801 if (gpio_get_value(data->pdata->gpio_data)
41802 - || atomic_read(&data->interrupt_handled))
41803 + || atomic_read_unchecked(&data->interrupt_handled))
41804 return;
41805 }
41806
41807 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41808 index 38944e9..ae9e5ed 100644
41809 --- a/drivers/hwmon/via-cputemp.c
41810 +++ b/drivers/hwmon/via-cputemp.c
41811 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41812 return NOTIFY_OK;
41813 }
41814
41815 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41816 +static struct notifier_block via_cputemp_cpu_notifier = {
41817 .notifier_call = via_cputemp_cpu_callback,
41818 };
41819
41820 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41821 index 07f01ac..d79ad3d 100644
41822 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41823 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41824 @@ -43,7 +43,7 @@
41825 extern struct i2c_adapter amd756_smbus;
41826
41827 static struct i2c_adapter *s4882_adapter;
41828 -static struct i2c_algorithm *s4882_algo;
41829 +static i2c_algorithm_no_const *s4882_algo;
41830
41831 /* Wrapper access functions for multiplexed SMBus */
41832 static DEFINE_MUTEX(amd756_lock);
41833 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41834 index 721f7eb..0fd2a09 100644
41835 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41836 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41837 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41838 /* usb layer */
41839
41840 /* Send command to device, and get response. */
41841 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41842 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41843 {
41844 int ret = 0;
41845 int actual;
41846 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41847 index 2ca268d..c6acbdf 100644
41848 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41849 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41850 @@ -41,7 +41,7 @@
41851 extern struct i2c_adapter *nforce2_smbus;
41852
41853 static struct i2c_adapter *s4985_adapter;
41854 -static struct i2c_algorithm *s4985_algo;
41855 +static i2c_algorithm_no_const *s4985_algo;
41856
41857 /* Wrapper access functions for multiplexed SMBus */
41858 static DEFINE_MUTEX(nforce2_lock);
41859 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41860 index 80b47e8..1a6040d9 100644
41861 --- a/drivers/i2c/i2c-dev.c
41862 +++ b/drivers/i2c/i2c-dev.c
41863 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41864 break;
41865 }
41866
41867 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41868 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41869 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41870 if (IS_ERR(rdwr_pa[i].buf)) {
41871 res = PTR_ERR(rdwr_pa[i].buf);
41872 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41873 index 0b510ba..4fbb5085 100644
41874 --- a/drivers/ide/ide-cd.c
41875 +++ b/drivers/ide/ide-cd.c
41876 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41877 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41878 if ((unsigned long)buf & alignment
41879 || blk_rq_bytes(rq) & q->dma_pad_mask
41880 - || object_is_on_stack(buf))
41881 + || object_starts_on_stack(buf))
41882 drive->dma = 0;
41883 }
41884 }
41885 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41886 index 18f72e3..3722327 100644
41887 --- a/drivers/iio/industrialio-core.c
41888 +++ b/drivers/iio/industrialio-core.c
41889 @@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41890 }
41891
41892 static
41893 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41894 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41895 const char *postfix,
41896 struct iio_chan_spec const *chan,
41897 ssize_t (*readfunc)(struct device *dev,
41898 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41899 index f2ef7ef..743d02f 100644
41900 --- a/drivers/infiniband/core/cm.c
41901 +++ b/drivers/infiniband/core/cm.c
41902 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41903
41904 struct cm_counter_group {
41905 struct kobject obj;
41906 - atomic_long_t counter[CM_ATTR_COUNT];
41907 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41908 };
41909
41910 struct cm_counter_attribute {
41911 @@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41912 struct ib_mad_send_buf *msg = NULL;
41913 int ret;
41914
41915 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41916 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41917 counter[CM_REQ_COUNTER]);
41918
41919 /* Quick state check to discard duplicate REQs. */
41920 @@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41921 if (!cm_id_priv)
41922 return;
41923
41924 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41925 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41926 counter[CM_REP_COUNTER]);
41927 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41928 if (ret)
41929 @@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41930 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41931 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41932 spin_unlock_irq(&cm_id_priv->lock);
41933 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41934 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41935 counter[CM_RTU_COUNTER]);
41936 goto out;
41937 }
41938 @@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41939 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41940 dreq_msg->local_comm_id);
41941 if (!cm_id_priv) {
41942 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41943 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41944 counter[CM_DREQ_COUNTER]);
41945 cm_issue_drep(work->port, work->mad_recv_wc);
41946 return -EINVAL;
41947 @@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41948 case IB_CM_MRA_REP_RCVD:
41949 break;
41950 case IB_CM_TIMEWAIT:
41951 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41952 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41953 counter[CM_DREQ_COUNTER]);
41954 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41955 goto unlock;
41956 @@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41957 cm_free_msg(msg);
41958 goto deref;
41959 case IB_CM_DREQ_RCVD:
41960 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41961 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41962 counter[CM_DREQ_COUNTER]);
41963 goto unlock;
41964 default:
41965 @@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41966 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41967 cm_id_priv->msg, timeout)) {
41968 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41969 - atomic_long_inc(&work->port->
41970 + atomic_long_inc_unchecked(&work->port->
41971 counter_group[CM_RECV_DUPLICATES].
41972 counter[CM_MRA_COUNTER]);
41973 goto out;
41974 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41975 break;
41976 case IB_CM_MRA_REQ_RCVD:
41977 case IB_CM_MRA_REP_RCVD:
41978 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41979 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41980 counter[CM_MRA_COUNTER]);
41981 /* fall through */
41982 default:
41983 @@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41984 case IB_CM_LAP_IDLE:
41985 break;
41986 case IB_CM_MRA_LAP_SENT:
41987 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41988 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41989 counter[CM_LAP_COUNTER]);
41990 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41991 goto unlock;
41992 @@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41993 cm_free_msg(msg);
41994 goto deref;
41995 case IB_CM_LAP_RCVD:
41996 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41997 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41998 counter[CM_LAP_COUNTER]);
41999 goto unlock;
42000 default:
42001 @@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42002 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42003 if (cur_cm_id_priv) {
42004 spin_unlock_irq(&cm.lock);
42005 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42006 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42007 counter[CM_SIDR_REQ_COUNTER]);
42008 goto out; /* Duplicate message. */
42009 }
42010 @@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42011 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42012 msg->retries = 1;
42013
42014 - atomic_long_add(1 + msg->retries,
42015 + atomic_long_add_unchecked(1 + msg->retries,
42016 &port->counter_group[CM_XMIT].counter[attr_index]);
42017 if (msg->retries)
42018 - atomic_long_add(msg->retries,
42019 + atomic_long_add_unchecked(msg->retries,
42020 &port->counter_group[CM_XMIT_RETRIES].
42021 counter[attr_index]);
42022
42023 @@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42024 }
42025
42026 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42027 - atomic_long_inc(&port->counter_group[CM_RECV].
42028 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42029 counter[attr_id - CM_ATTR_ID_OFFSET]);
42030
42031 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42032 @@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42033 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42034
42035 return sprintf(buf, "%ld\n",
42036 - atomic_long_read(&group->counter[cm_attr->index]));
42037 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42038 }
42039
42040 static const struct sysfs_ops cm_counter_ops = {
42041 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42042 index 9f5ad7c..588cd84 100644
42043 --- a/drivers/infiniband/core/fmr_pool.c
42044 +++ b/drivers/infiniband/core/fmr_pool.c
42045 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42046
42047 struct task_struct *thread;
42048
42049 - atomic_t req_ser;
42050 - atomic_t flush_ser;
42051 + atomic_unchecked_t req_ser;
42052 + atomic_unchecked_t flush_ser;
42053
42054 wait_queue_head_t force_wait;
42055 };
42056 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42057 struct ib_fmr_pool *pool = pool_ptr;
42058
42059 do {
42060 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42061 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42062 ib_fmr_batch_release(pool);
42063
42064 - atomic_inc(&pool->flush_ser);
42065 + atomic_inc_unchecked(&pool->flush_ser);
42066 wake_up_interruptible(&pool->force_wait);
42067
42068 if (pool->flush_function)
42069 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42070 }
42071
42072 set_current_state(TASK_INTERRUPTIBLE);
42073 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42074 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42075 !kthread_should_stop())
42076 schedule();
42077 __set_current_state(TASK_RUNNING);
42078 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42079 pool->dirty_watermark = params->dirty_watermark;
42080 pool->dirty_len = 0;
42081 spin_lock_init(&pool->pool_lock);
42082 - atomic_set(&pool->req_ser, 0);
42083 - atomic_set(&pool->flush_ser, 0);
42084 + atomic_set_unchecked(&pool->req_ser, 0);
42085 + atomic_set_unchecked(&pool->flush_ser, 0);
42086 init_waitqueue_head(&pool->force_wait);
42087
42088 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42089 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42090 }
42091 spin_unlock_irq(&pool->pool_lock);
42092
42093 - serial = atomic_inc_return(&pool->req_ser);
42094 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42095 wake_up_process(pool->thread);
42096
42097 if (wait_event_interruptible(pool->force_wait,
42098 - atomic_read(&pool->flush_ser) - serial >= 0))
42099 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42100 return -EINTR;
42101
42102 return 0;
42103 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42104 } else {
42105 list_add_tail(&fmr->list, &pool->dirty_list);
42106 if (++pool->dirty_len >= pool->dirty_watermark) {
42107 - atomic_inc(&pool->req_ser);
42108 + atomic_inc_unchecked(&pool->req_ser);
42109 wake_up_process(pool->thread);
42110 }
42111 }
42112 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42113 index 84e4500..2c9beeb 100644
42114 --- a/drivers/infiniband/hw/cxgb4/mem.c
42115 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42116 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42117 int err;
42118 struct fw_ri_tpte tpt;
42119 u32 stag_idx;
42120 - static atomic_t key;
42121 + static atomic_unchecked_t key;
42122
42123 if (c4iw_fatal_error(rdev))
42124 return -EIO;
42125 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42126 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42127 rdev->stats.stag.max = rdev->stats.stag.cur;
42128 mutex_unlock(&rdev->stats.lock);
42129 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42130 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42131 }
42132 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42133 __func__, stag_state, type, pdid, stag_idx);
42134 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42135 index 644c2c7..ecf0879 100644
42136 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
42137 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42138 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42139 }
42140
42141 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42142 - ipath_mapping_error,
42143 - ipath_dma_map_single,
42144 - ipath_dma_unmap_single,
42145 - ipath_dma_map_page,
42146 - ipath_dma_unmap_page,
42147 - ipath_map_sg,
42148 - ipath_unmap_sg,
42149 - ipath_sg_dma_address,
42150 - ipath_sg_dma_len,
42151 - ipath_sync_single_for_cpu,
42152 - ipath_sync_single_for_device,
42153 - ipath_dma_alloc_coherent,
42154 - ipath_dma_free_coherent
42155 + .mapping_error = ipath_mapping_error,
42156 + .map_single = ipath_dma_map_single,
42157 + .unmap_single = ipath_dma_unmap_single,
42158 + .map_page = ipath_dma_map_page,
42159 + .unmap_page = ipath_dma_unmap_page,
42160 + .map_sg = ipath_map_sg,
42161 + .unmap_sg = ipath_unmap_sg,
42162 + .dma_address = ipath_sg_dma_address,
42163 + .dma_len = ipath_sg_dma_len,
42164 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
42165 + .sync_single_for_device = ipath_sync_single_for_device,
42166 + .alloc_coherent = ipath_dma_alloc_coherent,
42167 + .free_coherent = ipath_dma_free_coherent
42168 };
42169 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42170 index 79b3dbc..96e5fcc 100644
42171 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42172 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42173 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42174 struct ib_atomic_eth *ateth;
42175 struct ipath_ack_entry *e;
42176 u64 vaddr;
42177 - atomic64_t *maddr;
42178 + atomic64_unchecked_t *maddr;
42179 u64 sdata;
42180 u32 rkey;
42181 u8 next;
42182 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42183 IB_ACCESS_REMOTE_ATOMIC)))
42184 goto nack_acc_unlck;
42185 /* Perform atomic OP and save result. */
42186 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42187 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42188 sdata = be64_to_cpu(ateth->swap_data);
42189 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42190 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42191 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42192 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42193 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42194 be64_to_cpu(ateth->compare_data),
42195 sdata);
42196 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42197 index 1f95bba..9530f87 100644
42198 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42199 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42200 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42201 unsigned long flags;
42202 struct ib_wc wc;
42203 u64 sdata;
42204 - atomic64_t *maddr;
42205 + atomic64_unchecked_t *maddr;
42206 enum ib_wc_status send_status;
42207
42208 /*
42209 @@ -382,11 +382,11 @@ again:
42210 IB_ACCESS_REMOTE_ATOMIC)))
42211 goto acc_err;
42212 /* Perform atomic OP and save result. */
42213 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42214 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42215 sdata = wqe->wr.wr.atomic.compare_add;
42216 *(u64 *) sqp->s_sge.sge.vaddr =
42217 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42218 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42219 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42220 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42221 sdata, wqe->wr.wr.atomic.swap);
42222 goto send_comp;
42223 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42224 index f2a3f48..673ec79 100644
42225 --- a/drivers/infiniband/hw/mlx4/mad.c
42226 +++ b/drivers/infiniband/hw/mlx4/mad.c
42227 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42228
42229 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42230 {
42231 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42232 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42233 cpu_to_be64(0xff00000000000000LL);
42234 }
42235
42236 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42237 index 25b2cdf..099ff97 100644
42238 --- a/drivers/infiniband/hw/mlx4/mcg.c
42239 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42240 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42241 {
42242 char name[20];
42243
42244 - atomic_set(&ctx->tid, 0);
42245 + atomic_set_unchecked(&ctx->tid, 0);
42246 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42247 ctx->mcg_wq = create_singlethread_workqueue(name);
42248 if (!ctx->mcg_wq)
42249 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42250 index 036b663..c9a8c73 100644
42251 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42252 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42253 @@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
42254 struct list_head mcg_mgid0_list;
42255 struct workqueue_struct *mcg_wq;
42256 struct mlx4_ib_demux_pv_ctx **tun;
42257 - atomic_t tid;
42258 + atomic_unchecked_t tid;
42259 int flushing; /* flushing the work queue */
42260 };
42261
42262 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42263 index 9d3e5c1..6f166df 100644
42264 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42265 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42266 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42267 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42268 }
42269
42270 -int mthca_QUERY_FW(struct mthca_dev *dev)
42271 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42272 {
42273 struct mthca_mailbox *mailbox;
42274 u32 *outbox;
42275 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42276 CMD_TIME_CLASS_B);
42277 }
42278
42279 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42280 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42281 int num_mtt)
42282 {
42283 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42284 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42285 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42286 }
42287
42288 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42289 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42290 int eq_num)
42291 {
42292 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42293 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42294 CMD_TIME_CLASS_B);
42295 }
42296
42297 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42298 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42299 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42300 void *in_mad, void *response_mad)
42301 {
42302 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42303 index 87897b9..7e79542 100644
42304 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42305 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42306 @@ -692,7 +692,7 @@ err_close:
42307 return err;
42308 }
42309
42310 -static int mthca_setup_hca(struct mthca_dev *dev)
42311 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42312 {
42313 int err;
42314
42315 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42316 index ed9a989..6aa5dc2 100644
42317 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42318 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42319 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42320 * through the bitmaps)
42321 */
42322
42323 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42324 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42325 {
42326 int o;
42327 int m;
42328 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42329 return key;
42330 }
42331
42332 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42333 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42334 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42335 {
42336 struct mthca_mailbox *mailbox;
42337 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42338 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42339 }
42340
42341 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42342 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42343 u64 *buffer_list, int buffer_size_shift,
42344 int list_len, u64 iova, u64 total_size,
42345 u32 access, struct mthca_mr *mr)
42346 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42347 index 5b71d43..35a9e14 100644
42348 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42349 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42350 @@ -763,7 +763,7 @@ unlock:
42351 return 0;
42352 }
42353
42354 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42355 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42356 {
42357 struct mthca_dev *dev = to_mdev(ibcq->device);
42358 struct mthca_cq *cq = to_mcq(ibcq);
42359 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42360 index 4291410..d2ab1fb 100644
42361 --- a/drivers/infiniband/hw/nes/nes.c
42362 +++ b/drivers/infiniband/hw/nes/nes.c
42363 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42364 LIST_HEAD(nes_adapter_list);
42365 static LIST_HEAD(nes_dev_list);
42366
42367 -atomic_t qps_destroyed;
42368 +atomic_unchecked_t qps_destroyed;
42369
42370 static unsigned int ee_flsh_adapter;
42371 static unsigned int sysfs_nonidx_addr;
42372 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42373 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42374 struct nes_adapter *nesadapter = nesdev->nesadapter;
42375
42376 - atomic_inc(&qps_destroyed);
42377 + atomic_inc_unchecked(&qps_destroyed);
42378
42379 /* Free the control structures */
42380
42381 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42382 index 33cc589..3bd6538 100644
42383 --- a/drivers/infiniband/hw/nes/nes.h
42384 +++ b/drivers/infiniband/hw/nes/nes.h
42385 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42386 extern unsigned int wqm_quanta;
42387 extern struct list_head nes_adapter_list;
42388
42389 -extern atomic_t cm_connects;
42390 -extern atomic_t cm_accepts;
42391 -extern atomic_t cm_disconnects;
42392 -extern atomic_t cm_closes;
42393 -extern atomic_t cm_connecteds;
42394 -extern atomic_t cm_connect_reqs;
42395 -extern atomic_t cm_rejects;
42396 -extern atomic_t mod_qp_timouts;
42397 -extern atomic_t qps_created;
42398 -extern atomic_t qps_destroyed;
42399 -extern atomic_t sw_qps_destroyed;
42400 +extern atomic_unchecked_t cm_connects;
42401 +extern atomic_unchecked_t cm_accepts;
42402 +extern atomic_unchecked_t cm_disconnects;
42403 +extern atomic_unchecked_t cm_closes;
42404 +extern atomic_unchecked_t cm_connecteds;
42405 +extern atomic_unchecked_t cm_connect_reqs;
42406 +extern atomic_unchecked_t cm_rejects;
42407 +extern atomic_unchecked_t mod_qp_timouts;
42408 +extern atomic_unchecked_t qps_created;
42409 +extern atomic_unchecked_t qps_destroyed;
42410 +extern atomic_unchecked_t sw_qps_destroyed;
42411 extern u32 mh_detected;
42412 extern u32 mh_pauses_sent;
42413 extern u32 cm_packets_sent;
42414 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42415 extern u32 cm_packets_received;
42416 extern u32 cm_packets_dropped;
42417 extern u32 cm_packets_retrans;
42418 -extern atomic_t cm_listens_created;
42419 -extern atomic_t cm_listens_destroyed;
42420 +extern atomic_unchecked_t cm_listens_created;
42421 +extern atomic_unchecked_t cm_listens_destroyed;
42422 extern u32 cm_backlog_drops;
42423 -extern atomic_t cm_loopbacks;
42424 -extern atomic_t cm_nodes_created;
42425 -extern atomic_t cm_nodes_destroyed;
42426 -extern atomic_t cm_accel_dropped_pkts;
42427 -extern atomic_t cm_resets_recvd;
42428 -extern atomic_t pau_qps_created;
42429 -extern atomic_t pau_qps_destroyed;
42430 +extern atomic_unchecked_t cm_loopbacks;
42431 +extern atomic_unchecked_t cm_nodes_created;
42432 +extern atomic_unchecked_t cm_nodes_destroyed;
42433 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42434 +extern atomic_unchecked_t cm_resets_recvd;
42435 +extern atomic_unchecked_t pau_qps_created;
42436 +extern atomic_unchecked_t pau_qps_destroyed;
42437
42438 extern u32 int_mod_timer_init;
42439 extern u32 int_mod_cq_depth_256;
42440 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42441 index 6b29249..461d143 100644
42442 --- a/drivers/infiniband/hw/nes/nes_cm.c
42443 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42444 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42445 u32 cm_packets_retrans;
42446 u32 cm_packets_created;
42447 u32 cm_packets_received;
42448 -atomic_t cm_listens_created;
42449 -atomic_t cm_listens_destroyed;
42450 +atomic_unchecked_t cm_listens_created;
42451 +atomic_unchecked_t cm_listens_destroyed;
42452 u32 cm_backlog_drops;
42453 -atomic_t cm_loopbacks;
42454 -atomic_t cm_nodes_created;
42455 -atomic_t cm_nodes_destroyed;
42456 -atomic_t cm_accel_dropped_pkts;
42457 -atomic_t cm_resets_recvd;
42458 +atomic_unchecked_t cm_loopbacks;
42459 +atomic_unchecked_t cm_nodes_created;
42460 +atomic_unchecked_t cm_nodes_destroyed;
42461 +atomic_unchecked_t cm_accel_dropped_pkts;
42462 +atomic_unchecked_t cm_resets_recvd;
42463
42464 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42465 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42466 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42467 /* instance of function pointers for client API */
42468 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42469 static struct nes_cm_ops nes_cm_api = {
42470 - mini_cm_accelerated,
42471 - mini_cm_listen,
42472 - mini_cm_del_listen,
42473 - mini_cm_connect,
42474 - mini_cm_close,
42475 - mini_cm_accept,
42476 - mini_cm_reject,
42477 - mini_cm_recv_pkt,
42478 - mini_cm_dealloc_core,
42479 - mini_cm_get,
42480 - mini_cm_set
42481 + .accelerated = mini_cm_accelerated,
42482 + .listen = mini_cm_listen,
42483 + .stop_listener = mini_cm_del_listen,
42484 + .connect = mini_cm_connect,
42485 + .close = mini_cm_close,
42486 + .accept = mini_cm_accept,
42487 + .reject = mini_cm_reject,
42488 + .recv_pkt = mini_cm_recv_pkt,
42489 + .destroy_cm_core = mini_cm_dealloc_core,
42490 + .get = mini_cm_get,
42491 + .set = mini_cm_set
42492 };
42493
42494 static struct nes_cm_core *g_cm_core;
42495
42496 -atomic_t cm_connects;
42497 -atomic_t cm_accepts;
42498 -atomic_t cm_disconnects;
42499 -atomic_t cm_closes;
42500 -atomic_t cm_connecteds;
42501 -atomic_t cm_connect_reqs;
42502 -atomic_t cm_rejects;
42503 +atomic_unchecked_t cm_connects;
42504 +atomic_unchecked_t cm_accepts;
42505 +atomic_unchecked_t cm_disconnects;
42506 +atomic_unchecked_t cm_closes;
42507 +atomic_unchecked_t cm_connecteds;
42508 +atomic_unchecked_t cm_connect_reqs;
42509 +atomic_unchecked_t cm_rejects;
42510
42511 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42512 {
42513 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42514 kfree(listener);
42515 listener = NULL;
42516 ret = 0;
42517 - atomic_inc(&cm_listens_destroyed);
42518 + atomic_inc_unchecked(&cm_listens_destroyed);
42519 } else {
42520 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42521 }
42522 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42523 cm_node->rem_mac);
42524
42525 add_hte_node(cm_core, cm_node);
42526 - atomic_inc(&cm_nodes_created);
42527 + atomic_inc_unchecked(&cm_nodes_created);
42528
42529 return cm_node;
42530 }
42531 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42532 }
42533
42534 atomic_dec(&cm_core->node_cnt);
42535 - atomic_inc(&cm_nodes_destroyed);
42536 + atomic_inc_unchecked(&cm_nodes_destroyed);
42537 nesqp = cm_node->nesqp;
42538 if (nesqp) {
42539 nesqp->cm_node = NULL;
42540 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42541
42542 static void drop_packet(struct sk_buff *skb)
42543 {
42544 - atomic_inc(&cm_accel_dropped_pkts);
42545 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42546 dev_kfree_skb_any(skb);
42547 }
42548
42549 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42550 {
42551
42552 int reset = 0; /* whether to send reset in case of err.. */
42553 - atomic_inc(&cm_resets_recvd);
42554 + atomic_inc_unchecked(&cm_resets_recvd);
42555 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42556 " refcnt=%d\n", cm_node, cm_node->state,
42557 atomic_read(&cm_node->ref_count));
42558 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42559 rem_ref_cm_node(cm_node->cm_core, cm_node);
42560 return NULL;
42561 }
42562 - atomic_inc(&cm_loopbacks);
42563 + atomic_inc_unchecked(&cm_loopbacks);
42564 loopbackremotenode->loopbackpartner = cm_node;
42565 loopbackremotenode->tcp_cntxt.rcv_wscale =
42566 NES_CM_DEFAULT_RCV_WND_SCALE;
42567 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42568 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42569 else {
42570 rem_ref_cm_node(cm_core, cm_node);
42571 - atomic_inc(&cm_accel_dropped_pkts);
42572 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42573 dev_kfree_skb_any(skb);
42574 }
42575 break;
42576 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42577
42578 if ((cm_id) && (cm_id->event_handler)) {
42579 if (issue_disconn) {
42580 - atomic_inc(&cm_disconnects);
42581 + atomic_inc_unchecked(&cm_disconnects);
42582 cm_event.event = IW_CM_EVENT_DISCONNECT;
42583 cm_event.status = disconn_status;
42584 cm_event.local_addr = cm_id->local_addr;
42585 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42586 }
42587
42588 if (issue_close) {
42589 - atomic_inc(&cm_closes);
42590 + atomic_inc_unchecked(&cm_closes);
42591 nes_disconnect(nesqp, 1);
42592
42593 cm_id->provider_data = nesqp;
42594 @@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42595
42596 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42597 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42598 - atomic_inc(&cm_accepts);
42599 + atomic_inc_unchecked(&cm_accepts);
42600
42601 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42602 netdev_refcnt_read(nesvnic->netdev));
42603 @@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42604 struct nes_cm_core *cm_core;
42605 u8 *start_buff;
42606
42607 - atomic_inc(&cm_rejects);
42608 + atomic_inc_unchecked(&cm_rejects);
42609 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42610 loopback = cm_node->loopbackpartner;
42611 cm_core = cm_node->cm_core;
42612 @@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42613 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42614 ntohs(laddr->sin_port));
42615
42616 - atomic_inc(&cm_connects);
42617 + atomic_inc_unchecked(&cm_connects);
42618 nesqp->active_conn = 1;
42619
42620 /* cache the cm_id in the qp */
42621 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42622 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42623 return err;
42624 }
42625 - atomic_inc(&cm_listens_created);
42626 + atomic_inc_unchecked(&cm_listens_created);
42627 }
42628
42629 cm_id->add_ref(cm_id);
42630 @@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42631
42632 if (nesqp->destroyed)
42633 return;
42634 - atomic_inc(&cm_connecteds);
42635 + atomic_inc_unchecked(&cm_connecteds);
42636 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42637 " local port 0x%04X. jiffies = %lu.\n",
42638 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42639 @@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42640
42641 cm_id->add_ref(cm_id);
42642 ret = cm_id->event_handler(cm_id, &cm_event);
42643 - atomic_inc(&cm_closes);
42644 + atomic_inc_unchecked(&cm_closes);
42645 cm_event.event = IW_CM_EVENT_CLOSE;
42646 cm_event.status = 0;
42647 cm_event.provider_data = cm_id->provider_data;
42648 @@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42649 return;
42650 cm_id = cm_node->cm_id;
42651
42652 - atomic_inc(&cm_connect_reqs);
42653 + atomic_inc_unchecked(&cm_connect_reqs);
42654 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42655 cm_node, cm_id, jiffies);
42656
42657 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42658 return;
42659 cm_id = cm_node->cm_id;
42660
42661 - atomic_inc(&cm_connect_reqs);
42662 + atomic_inc_unchecked(&cm_connect_reqs);
42663 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42664 cm_node, cm_id, jiffies);
42665
42666 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42667 index 4166452..fc952c3 100644
42668 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42669 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42670 @@ -40,8 +40,8 @@
42671 #include "nes.h"
42672 #include "nes_mgt.h"
42673
42674 -atomic_t pau_qps_created;
42675 -atomic_t pau_qps_destroyed;
42676 +atomic_unchecked_t pau_qps_created;
42677 +atomic_unchecked_t pau_qps_destroyed;
42678
42679 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42680 {
42681 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42682 {
42683 struct sk_buff *skb;
42684 unsigned long flags;
42685 - atomic_inc(&pau_qps_destroyed);
42686 + atomic_inc_unchecked(&pau_qps_destroyed);
42687
42688 /* Free packets that have not yet been forwarded */
42689 /* Lock is acquired by skb_dequeue when removing the skb */
42690 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42691 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42692 skb_queue_head_init(&nesqp->pau_list);
42693 spin_lock_init(&nesqp->pau_lock);
42694 - atomic_inc(&pau_qps_created);
42695 + atomic_inc_unchecked(&pau_qps_created);
42696 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42697 }
42698
42699 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42700 index 49eb511..a774366 100644
42701 --- a/drivers/infiniband/hw/nes/nes_nic.c
42702 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42703 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42704 target_stat_values[++index] = mh_detected;
42705 target_stat_values[++index] = mh_pauses_sent;
42706 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42707 - target_stat_values[++index] = atomic_read(&cm_connects);
42708 - target_stat_values[++index] = atomic_read(&cm_accepts);
42709 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42710 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42711 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42712 - target_stat_values[++index] = atomic_read(&cm_rejects);
42713 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42714 - target_stat_values[++index] = atomic_read(&qps_created);
42715 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42716 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42717 - target_stat_values[++index] = atomic_read(&cm_closes);
42718 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42719 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42720 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42721 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42722 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42723 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42724 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42725 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42726 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42727 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42728 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42729 target_stat_values[++index] = cm_packets_sent;
42730 target_stat_values[++index] = cm_packets_bounced;
42731 target_stat_values[++index] = cm_packets_created;
42732 target_stat_values[++index] = cm_packets_received;
42733 target_stat_values[++index] = cm_packets_dropped;
42734 target_stat_values[++index] = cm_packets_retrans;
42735 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42736 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42737 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42738 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42739 target_stat_values[++index] = cm_backlog_drops;
42740 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42741 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42742 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42743 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42744 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42745 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42746 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42747 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42748 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42749 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42750 target_stat_values[++index] = nesadapter->free_4kpbl;
42751 target_stat_values[++index] = nesadapter->free_256pbl;
42752 target_stat_values[++index] = int_mod_timer_init;
42753 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42754 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42755 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42756 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42757 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42758 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42759 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42760 }
42761
42762 /**
42763 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42764 index 8308e36..ae0d3b5 100644
42765 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42766 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42767 @@ -46,9 +46,9 @@
42768
42769 #include <rdma/ib_umem.h>
42770
42771 -atomic_t mod_qp_timouts;
42772 -atomic_t qps_created;
42773 -atomic_t sw_qps_destroyed;
42774 +atomic_unchecked_t mod_qp_timouts;
42775 +atomic_unchecked_t qps_created;
42776 +atomic_unchecked_t sw_qps_destroyed;
42777
42778 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42779
42780 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42781 if (init_attr->create_flags)
42782 return ERR_PTR(-EINVAL);
42783
42784 - atomic_inc(&qps_created);
42785 + atomic_inc_unchecked(&qps_created);
42786 switch (init_attr->qp_type) {
42787 case IB_QPT_RC:
42788 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42789 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42790 struct iw_cm_event cm_event;
42791 int ret = 0;
42792
42793 - atomic_inc(&sw_qps_destroyed);
42794 + atomic_inc_unchecked(&sw_qps_destroyed);
42795 nesqp->destroyed = 1;
42796
42797 /* Blow away the connection if it exists. */
42798 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42799 index 1946101..09766d2 100644
42800 --- a/drivers/infiniband/hw/qib/qib.h
42801 +++ b/drivers/infiniband/hw/qib/qib.h
42802 @@ -52,6 +52,7 @@
42803 #include <linux/kref.h>
42804 #include <linux/sched.h>
42805 #include <linux/kthread.h>
42806 +#include <linux/slab.h>
42807
42808 #include "qib_common.h"
42809 #include "qib_verbs.h"
42810 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42811 index 24c41ba..102d71f 100644
42812 --- a/drivers/input/gameport/gameport.c
42813 +++ b/drivers/input/gameport/gameport.c
42814 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42815 */
42816 static void gameport_init_port(struct gameport *gameport)
42817 {
42818 - static atomic_t gameport_no = ATOMIC_INIT(0);
42819 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42820
42821 __module_get(THIS_MODULE);
42822
42823 mutex_init(&gameport->drv_mutex);
42824 device_initialize(&gameport->dev);
42825 dev_set_name(&gameport->dev, "gameport%lu",
42826 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42827 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42828 gameport->dev.bus = &gameport_bus;
42829 gameport->dev.release = gameport_release_port;
42830 if (gameport->parent)
42831 diff --git a/drivers/input/input.c b/drivers/input/input.c
42832 index d2965e4..f52b7d7 100644
42833 --- a/drivers/input/input.c
42834 +++ b/drivers/input/input.c
42835 @@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42836 */
42837 struct input_dev *input_allocate_device(void)
42838 {
42839 - static atomic_t input_no = ATOMIC_INIT(0);
42840 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42841 struct input_dev *dev;
42842
42843 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42844 @@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42845 INIT_LIST_HEAD(&dev->node);
42846
42847 dev_set_name(&dev->dev, "input%ld",
42848 - (unsigned long) atomic_inc_return(&input_no) - 1);
42849 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42850
42851 __module_get(THIS_MODULE);
42852 }
42853 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42854 index 04c69af..5f92d00 100644
42855 --- a/drivers/input/joystick/sidewinder.c
42856 +++ b/drivers/input/joystick/sidewinder.c
42857 @@ -30,6 +30,7 @@
42858 #include <linux/kernel.h>
42859 #include <linux/module.h>
42860 #include <linux/slab.h>
42861 +#include <linux/sched.h>
42862 #include <linux/init.h>
42863 #include <linux/input.h>
42864 #include <linux/gameport.h>
42865 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42866 index 75e3b10..fb390fd 100644
42867 --- a/drivers/input/joystick/xpad.c
42868 +++ b/drivers/input/joystick/xpad.c
42869 @@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42870
42871 static int xpad_led_probe(struct usb_xpad *xpad)
42872 {
42873 - static atomic_t led_seq = ATOMIC_INIT(0);
42874 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42875 long led_no;
42876 struct xpad_led *led;
42877 struct led_classdev *led_cdev;
42878 @@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42879 if (!led)
42880 return -ENOMEM;
42881
42882 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42883 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42884
42885 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42886 led->xpad = xpad;
42887 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42888 index e204f26..8459f15 100644
42889 --- a/drivers/input/misc/ims-pcu.c
42890 +++ b/drivers/input/misc/ims-pcu.c
42891 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42892
42893 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42894 {
42895 - static atomic_t device_no = ATOMIC_INIT(0);
42896 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42897
42898 const struct ims_pcu_device_info *info;
42899 u8 device_id;
42900 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42901 }
42902
42903 /* Device appears to be operable, complete initialization */
42904 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42905 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42906
42907 error = ims_pcu_setup_backlight(pcu);
42908 if (error)
42909 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42910 index 2f0b39d..7370f13 100644
42911 --- a/drivers/input/mouse/psmouse.h
42912 +++ b/drivers/input/mouse/psmouse.h
42913 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42914 ssize_t (*set)(struct psmouse *psmouse, void *data,
42915 const char *buf, size_t count);
42916 bool protect;
42917 -};
42918 +} __do_const;
42919 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42920
42921 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42922 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42923 index b604564..3f14ae4 100644
42924 --- a/drivers/input/mousedev.c
42925 +++ b/drivers/input/mousedev.c
42926 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42927
42928 spin_unlock_irq(&client->packet_lock);
42929
42930 - if (copy_to_user(buffer, data, count))
42931 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42932 return -EFAULT;
42933
42934 return count;
42935 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42936 index 8f4c4ab..5fc8a45 100644
42937 --- a/drivers/input/serio/serio.c
42938 +++ b/drivers/input/serio/serio.c
42939 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42940 */
42941 static void serio_init_port(struct serio *serio)
42942 {
42943 - static atomic_t serio_no = ATOMIC_INIT(0);
42944 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42945
42946 __module_get(THIS_MODULE);
42947
42948 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42949 mutex_init(&serio->drv_mutex);
42950 device_initialize(&serio->dev);
42951 dev_set_name(&serio->dev, "serio%ld",
42952 - (long)atomic_inc_return(&serio_no) - 1);
42953 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42954 serio->dev.bus = &serio_bus;
42955 serio->dev.release = serio_release_port;
42956 serio->dev.groups = serio_device_attr_groups;
42957 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42958 index 59df2e7..8f1cafb 100644
42959 --- a/drivers/input/serio/serio_raw.c
42960 +++ b/drivers/input/serio/serio_raw.c
42961 @@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42962
42963 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42964 {
42965 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42966 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42967 struct serio_raw *serio_raw;
42968 int err;
42969
42970 @@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42971 }
42972
42973 snprintf(serio_raw->name, sizeof(serio_raw->name),
42974 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42975 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42976 kref_init(&serio_raw->kref);
42977 INIT_LIST_HEAD(&serio_raw->client_list);
42978 init_waitqueue_head(&serio_raw->wait);
42979 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42980 index e5555fc..937986d 100644
42981 --- a/drivers/iommu/iommu.c
42982 +++ b/drivers/iommu/iommu.c
42983 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42984 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42985 {
42986 bus_register_notifier(bus, &iommu_bus_nb);
42987 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42988 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42989 }
42990
42991 /**
42992 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42993 index 39f81ae..2660096 100644
42994 --- a/drivers/iommu/irq_remapping.c
42995 +++ b/drivers/iommu/irq_remapping.c
42996 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42997 void panic_if_irq_remap(const char *msg)
42998 {
42999 if (irq_remapping_enabled)
43000 - panic(msg);
43001 + panic("%s", msg);
43002 }
43003
43004 static void ir_ack_apic_edge(struct irq_data *data)
43005 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43006
43007 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43008 {
43009 - chip->irq_print_chip = ir_print_prefix;
43010 - chip->irq_ack = ir_ack_apic_edge;
43011 - chip->irq_eoi = ir_ack_apic_level;
43012 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43013 + pax_open_kernel();
43014 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43015 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43016 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43017 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43018 + pax_close_kernel();
43019 }
43020
43021 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43022 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43023 index 341c601..e5f407e 100644
43024 --- a/drivers/irqchip/irq-gic.c
43025 +++ b/drivers/irqchip/irq-gic.c
43026 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43027 * Supported arch specific GIC irq extension.
43028 * Default make them NULL.
43029 */
43030 -struct irq_chip gic_arch_extn = {
43031 +irq_chip_no_const gic_arch_extn = {
43032 .irq_eoi = NULL,
43033 .irq_mask = NULL,
43034 .irq_unmask = NULL,
43035 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43036 chained_irq_exit(chip, desc);
43037 }
43038
43039 -static struct irq_chip gic_chip = {
43040 +static irq_chip_no_const gic_chip __read_only = {
43041 .name = "GIC",
43042 .irq_mask = gic_mask_irq,
43043 .irq_unmask = gic_unmask_irq,
43044 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43045 index ac6f72b..81150f2 100644
43046 --- a/drivers/isdn/capi/capi.c
43047 +++ b/drivers/isdn/capi/capi.c
43048 @@ -81,8 +81,8 @@ struct capiminor {
43049
43050 struct capi20_appl *ap;
43051 u32 ncci;
43052 - atomic_t datahandle;
43053 - atomic_t msgid;
43054 + atomic_unchecked_t datahandle;
43055 + atomic_unchecked_t msgid;
43056
43057 struct tty_port port;
43058 int ttyinstop;
43059 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43060 capimsg_setu16(s, 2, mp->ap->applid);
43061 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43062 capimsg_setu8 (s, 5, CAPI_RESP);
43063 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43064 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43065 capimsg_setu32(s, 8, mp->ncci);
43066 capimsg_setu16(s, 12, datahandle);
43067 }
43068 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43069 mp->outbytes -= len;
43070 spin_unlock_bh(&mp->outlock);
43071
43072 - datahandle = atomic_inc_return(&mp->datahandle);
43073 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43074 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43075 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43076 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43077 capimsg_setu16(skb->data, 2, mp->ap->applid);
43078 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43079 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43080 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43081 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43082 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43083 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43084 capimsg_setu16(skb->data, 16, len); /* Data length */
43085 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43086 index c44950d..10ac276 100644
43087 --- a/drivers/isdn/gigaset/bas-gigaset.c
43088 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43089 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43090
43091
43092 static const struct gigaset_ops gigops = {
43093 - gigaset_write_cmd,
43094 - gigaset_write_room,
43095 - gigaset_chars_in_buffer,
43096 - gigaset_brkchars,
43097 - gigaset_init_bchannel,
43098 - gigaset_close_bchannel,
43099 - gigaset_initbcshw,
43100 - gigaset_freebcshw,
43101 - gigaset_reinitbcshw,
43102 - gigaset_initcshw,
43103 - gigaset_freecshw,
43104 - gigaset_set_modem_ctrl,
43105 - gigaset_baud_rate,
43106 - gigaset_set_line_ctrl,
43107 - gigaset_isoc_send_skb,
43108 - gigaset_isoc_input,
43109 + .write_cmd = gigaset_write_cmd,
43110 + .write_room = gigaset_write_room,
43111 + .chars_in_buffer = gigaset_chars_in_buffer,
43112 + .brkchars = gigaset_brkchars,
43113 + .init_bchannel = gigaset_init_bchannel,
43114 + .close_bchannel = gigaset_close_bchannel,
43115 + .initbcshw = gigaset_initbcshw,
43116 + .freebcshw = gigaset_freebcshw,
43117 + .reinitbcshw = gigaset_reinitbcshw,
43118 + .initcshw = gigaset_initcshw,
43119 + .freecshw = gigaset_freecshw,
43120 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43121 + .baud_rate = gigaset_baud_rate,
43122 + .set_line_ctrl = gigaset_set_line_ctrl,
43123 + .send_skb = gigaset_isoc_send_skb,
43124 + .handle_input = gigaset_isoc_input,
43125 };
43126
43127 /* bas_gigaset_init
43128 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43129 index 600c79b..3752bab 100644
43130 --- a/drivers/isdn/gigaset/interface.c
43131 +++ b/drivers/isdn/gigaset/interface.c
43132 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43133 }
43134 tty->driver_data = cs;
43135
43136 - ++cs->port.count;
43137 + atomic_inc(&cs->port.count);
43138
43139 - if (cs->port.count == 1) {
43140 + if (atomic_read(&cs->port.count) == 1) {
43141 tty_port_tty_set(&cs->port, tty);
43142 cs->port.low_latency = 1;
43143 }
43144 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43145
43146 if (!cs->connected)
43147 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43148 - else if (!cs->port.count)
43149 + else if (!atomic_read(&cs->port.count))
43150 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43151 - else if (!--cs->port.count)
43152 + else if (!atomic_dec_return(&cs->port.count))
43153 tty_port_tty_set(&cs->port, NULL);
43154
43155 mutex_unlock(&cs->mutex);
43156 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43157 index 8c91fd5..14f13ce 100644
43158 --- a/drivers/isdn/gigaset/ser-gigaset.c
43159 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43160 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43161 }
43162
43163 static const struct gigaset_ops ops = {
43164 - gigaset_write_cmd,
43165 - gigaset_write_room,
43166 - gigaset_chars_in_buffer,
43167 - gigaset_brkchars,
43168 - gigaset_init_bchannel,
43169 - gigaset_close_bchannel,
43170 - gigaset_initbcshw,
43171 - gigaset_freebcshw,
43172 - gigaset_reinitbcshw,
43173 - gigaset_initcshw,
43174 - gigaset_freecshw,
43175 - gigaset_set_modem_ctrl,
43176 - gigaset_baud_rate,
43177 - gigaset_set_line_ctrl,
43178 - gigaset_m10x_send_skb, /* asyncdata.c */
43179 - gigaset_m10x_input, /* asyncdata.c */
43180 + .write_cmd = gigaset_write_cmd,
43181 + .write_room = gigaset_write_room,
43182 + .chars_in_buffer = gigaset_chars_in_buffer,
43183 + .brkchars = gigaset_brkchars,
43184 + .init_bchannel = gigaset_init_bchannel,
43185 + .close_bchannel = gigaset_close_bchannel,
43186 + .initbcshw = gigaset_initbcshw,
43187 + .freebcshw = gigaset_freebcshw,
43188 + .reinitbcshw = gigaset_reinitbcshw,
43189 + .initcshw = gigaset_initcshw,
43190 + .freecshw = gigaset_freecshw,
43191 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43192 + .baud_rate = gigaset_baud_rate,
43193 + .set_line_ctrl = gigaset_set_line_ctrl,
43194 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43195 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43196 };
43197
43198
43199 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43200 index d0a41cb..b953e50 100644
43201 --- a/drivers/isdn/gigaset/usb-gigaset.c
43202 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43203 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43204 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43205 memcpy(cs->hw.usb->bchars, buf, 6);
43206 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43207 - 0, 0, &buf, 6, 2000);
43208 + 0, 0, buf, 6, 2000);
43209 }
43210
43211 static void gigaset_freebcshw(struct bc_state *bcs)
43212 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43213 }
43214
43215 static const struct gigaset_ops ops = {
43216 - gigaset_write_cmd,
43217 - gigaset_write_room,
43218 - gigaset_chars_in_buffer,
43219 - gigaset_brkchars,
43220 - gigaset_init_bchannel,
43221 - gigaset_close_bchannel,
43222 - gigaset_initbcshw,
43223 - gigaset_freebcshw,
43224 - gigaset_reinitbcshw,
43225 - gigaset_initcshw,
43226 - gigaset_freecshw,
43227 - gigaset_set_modem_ctrl,
43228 - gigaset_baud_rate,
43229 - gigaset_set_line_ctrl,
43230 - gigaset_m10x_send_skb,
43231 - gigaset_m10x_input,
43232 + .write_cmd = gigaset_write_cmd,
43233 + .write_room = gigaset_write_room,
43234 + .chars_in_buffer = gigaset_chars_in_buffer,
43235 + .brkchars = gigaset_brkchars,
43236 + .init_bchannel = gigaset_init_bchannel,
43237 + .close_bchannel = gigaset_close_bchannel,
43238 + .initbcshw = gigaset_initbcshw,
43239 + .freebcshw = gigaset_freebcshw,
43240 + .reinitbcshw = gigaset_reinitbcshw,
43241 + .initcshw = gigaset_initcshw,
43242 + .freecshw = gigaset_freecshw,
43243 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43244 + .baud_rate = gigaset_baud_rate,
43245 + .set_line_ctrl = gigaset_set_line_ctrl,
43246 + .send_skb = gigaset_m10x_send_skb,
43247 + .handle_input = gigaset_m10x_input,
43248 };
43249
43250 /*
43251 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43252 index 4d9b195..455075c 100644
43253 --- a/drivers/isdn/hardware/avm/b1.c
43254 +++ b/drivers/isdn/hardware/avm/b1.c
43255 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43256 }
43257 if (left) {
43258 if (t4file->user) {
43259 - if (copy_from_user(buf, dp, left))
43260 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43261 return -EFAULT;
43262 } else {
43263 memcpy(buf, dp, left);
43264 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43265 }
43266 if (left) {
43267 if (config->user) {
43268 - if (copy_from_user(buf, dp, left))
43269 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43270 return -EFAULT;
43271 } else {
43272 memcpy(buf, dp, left);
43273 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43274 index 9bb12ba..d4262f7 100644
43275 --- a/drivers/isdn/i4l/isdn_common.c
43276 +++ b/drivers/isdn/i4l/isdn_common.c
43277 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43278 } else
43279 return -EINVAL;
43280 case IIOCDBGVAR:
43281 + if (!capable(CAP_SYS_RAWIO))
43282 + return -EPERM;
43283 if (arg) {
43284 if (copy_to_user(argp, &dev, sizeof(ulong)))
43285 return -EFAULT;
43286 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43287 index 91d5730..336523e 100644
43288 --- a/drivers/isdn/i4l/isdn_concap.c
43289 +++ b/drivers/isdn/i4l/isdn_concap.c
43290 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43291 }
43292
43293 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43294 - &isdn_concap_dl_data_req,
43295 - &isdn_concap_dl_connect_req,
43296 - &isdn_concap_dl_disconn_req
43297 + .data_req = &isdn_concap_dl_data_req,
43298 + .connect_req = &isdn_concap_dl_connect_req,
43299 + .disconn_req = &isdn_concap_dl_disconn_req
43300 };
43301
43302 /* The following should better go into a dedicated source file such that
43303 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43304 index 3c5f249..5fac4d0 100644
43305 --- a/drivers/isdn/i4l/isdn_tty.c
43306 +++ b/drivers/isdn/i4l/isdn_tty.c
43307 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43308
43309 #ifdef ISDN_DEBUG_MODEM_OPEN
43310 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43311 - port->count);
43312 + atomic_read(&port->count));
43313 #endif
43314 - port->count++;
43315 + atomic_inc(&port->count);
43316 port->tty = tty;
43317 /*
43318 * Start up serial port
43319 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43320 #endif
43321 return;
43322 }
43323 - if ((tty->count == 1) && (port->count != 1)) {
43324 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43325 /*
43326 * Uh, oh. tty->count is 1, which means that the tty
43327 * structure will be freed. Info->count should always
43328 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43329 * serial port won't be shutdown.
43330 */
43331 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43332 - "info->count is %d\n", port->count);
43333 - port->count = 1;
43334 + "info->count is %d\n", atomic_read(&port->count));
43335 + atomic_set(&port->count, 1);
43336 }
43337 - if (--port->count < 0) {
43338 + if (atomic_dec_return(&port->count) < 0) {
43339 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43340 - info->line, port->count);
43341 - port->count = 0;
43342 + info->line, atomic_read(&port->count));
43343 + atomic_set(&port->count, 0);
43344 }
43345 - if (port->count) {
43346 + if (atomic_read(&port->count)) {
43347 #ifdef ISDN_DEBUG_MODEM_OPEN
43348 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43349 #endif
43350 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43351 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43352 return;
43353 isdn_tty_shutdown(info);
43354 - port->count = 0;
43355 + atomic_set(&port->count, 0);
43356 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43357 port->tty = NULL;
43358 wake_up_interruptible(&port->open_wait);
43359 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43360 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43361 modem_info *info = &dev->mdm.info[i];
43362
43363 - if (info->port.count == 0)
43364 + if (atomic_read(&info->port.count) == 0)
43365 continue;
43366 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43367 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43368 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43369 index e2d4e58..40cd045 100644
43370 --- a/drivers/isdn/i4l/isdn_x25iface.c
43371 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43372 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43373
43374
43375 static struct concap_proto_ops ix25_pops = {
43376 - &isdn_x25iface_proto_new,
43377 - &isdn_x25iface_proto_del,
43378 - &isdn_x25iface_proto_restart,
43379 - &isdn_x25iface_proto_close,
43380 - &isdn_x25iface_xmit,
43381 - &isdn_x25iface_receive,
43382 - &isdn_x25iface_connect_ind,
43383 - &isdn_x25iface_disconn_ind
43384 + .proto_new = &isdn_x25iface_proto_new,
43385 + .proto_del = &isdn_x25iface_proto_del,
43386 + .restart = &isdn_x25iface_proto_restart,
43387 + .close = &isdn_x25iface_proto_close,
43388 + .encap_and_xmit = &isdn_x25iface_xmit,
43389 + .data_ind = &isdn_x25iface_receive,
43390 + .connect_ind = &isdn_x25iface_connect_ind,
43391 + .disconn_ind = &isdn_x25iface_disconn_ind
43392 };
43393
43394 /* error message helper function */
43395 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43396 index 53d487f..f020f41 100644
43397 --- a/drivers/isdn/icn/icn.c
43398 +++ b/drivers/isdn/icn/icn.c
43399 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43400 if (count > len)
43401 count = len;
43402 if (user) {
43403 - if (copy_from_user(msg, buf, count))
43404 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43405 return -EFAULT;
43406 } else
43407 memcpy(msg, buf, count);
43408 diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
43409 index 02125e6..5a4da94 100644
43410 --- a/drivers/isdn/isdnloop/isdnloop.c
43411 +++ b/drivers/isdn/isdnloop/isdnloop.c
43412 @@ -518,9 +518,9 @@ static isdnloop_stat isdnloop_cmd_table[] =
43413 static void
43414 isdnloop_fake_err(isdnloop_card *card)
43415 {
43416 - char buf[60];
43417 + char buf[64];
43418
43419 - sprintf(buf, "E%s", card->omsg);
43420 + snprintf(buf, sizeof(buf), "E%s", card->omsg);
43421 isdnloop_fake(card, buf, -1);
43422 isdnloop_fake(card, "NAK", -1);
43423 }
43424 @@ -903,6 +903,8 @@ isdnloop_parse_cmd(isdnloop_card *card)
43425 case 7:
43426 /* 0x;EAZ */
43427 p += 3;
43428 + if (strlen(p) >= sizeof(card->eazlist[0]))
43429 + break;
43430 strcpy(card->eazlist[ch - 1], p);
43431 break;
43432 case 8:
43433 @@ -1070,6 +1072,12 @@ isdnloop_start(isdnloop_card *card, isdnloop_sdef *sdefp)
43434 return -EBUSY;
43435 if (copy_from_user((char *) &sdef, (char *) sdefp, sizeof(sdef)))
43436 return -EFAULT;
43437 +
43438 + for (i = 0; i < 3; i++) {
43439 + if (!memchr(sdef.num[i], 0, sizeof(sdef.num[i])))
43440 + return -EINVAL;
43441 + }
43442 +
43443 spin_lock_irqsave(&card->isdnloop_lock, flags);
43444 switch (sdef.ptype) {
43445 case ISDN_PTYPE_EURO:
43446 @@ -1127,7 +1135,7 @@ isdnloop_command(isdn_ctrl *c, isdnloop_card *card)
43447 {
43448 ulong a;
43449 int i;
43450 - char cbuf[60];
43451 + char cbuf[80];
43452 isdn_ctrl cmd;
43453 isdnloop_cdef cdef;
43454
43455 @@ -1192,7 +1200,6 @@ isdnloop_command(isdn_ctrl *c, isdnloop_card *card)
43456 break;
43457 if ((c->arg & 255) < ISDNLOOP_BCH) {
43458 char *p;
43459 - char dial[50];
43460 char dcode[4];
43461
43462 a = c->arg;
43463 @@ -1204,10 +1211,10 @@ isdnloop_command(isdn_ctrl *c, isdnloop_card *card)
43464 } else
43465 /* Normal Dial */
43466 strcpy(dcode, "CAL");
43467 - strcpy(dial, p);
43468 - sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43469 - dcode, dial, c->parm.setup.si1,
43470 - c->parm.setup.si2, c->parm.setup.eazmsn);
43471 + snprintf(cbuf, sizeof(cbuf),
43472 + "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43473 + dcode, p, c->parm.setup.si1,
43474 + c->parm.setup.si2, c->parm.setup.eazmsn);
43475 i = isdnloop_writecmd(cbuf, strlen(cbuf), 0, card);
43476 }
43477 break;
43478 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43479 index a4f05c5..1433bc5 100644
43480 --- a/drivers/isdn/mISDN/dsp_cmx.c
43481 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43482 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43483 static u16 dsp_count; /* last sample count */
43484 static int dsp_count_valid; /* if we have last sample count */
43485
43486 -void
43487 +void __intentional_overflow(-1)
43488 dsp_cmx_send(void *arg)
43489 {
43490 struct dsp_conf *conf;
43491 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43492 index d93e245..e7ece6b 100644
43493 --- a/drivers/leds/leds-clevo-mail.c
43494 +++ b/drivers/leds/leds-clevo-mail.c
43495 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43496 * detected as working, but in reality it is not) as low as
43497 * possible.
43498 */
43499 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43500 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43501 {
43502 .callback = clevo_mail_led_dmi_callback,
43503 .ident = "Clevo D410J",
43504 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43505 index 5b8f938..b73d657 100644
43506 --- a/drivers/leds/leds-ss4200.c
43507 +++ b/drivers/leds/leds-ss4200.c
43508 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43509 * detected as working, but in reality it is not) as low as
43510 * possible.
43511 */
43512 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43513 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43514 {
43515 .callback = ss4200_led_dmi_callback,
43516 .ident = "Intel SS4200-E",
43517 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43518 index 0bf1e4e..b4bf44e 100644
43519 --- a/drivers/lguest/core.c
43520 +++ b/drivers/lguest/core.c
43521 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43522 * The end address needs +1 because __get_vm_area allocates an
43523 * extra guard page, so we need space for that.
43524 */
43525 +
43526 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43527 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43528 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43529 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43530 +#else
43531 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43532 VM_ALLOC, switcher_addr, switcher_addr
43533 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43534 +#endif
43535 +
43536 if (!switcher_vma) {
43537 err = -ENOMEM;
43538 printk("lguest: could not map switcher pages high\n");
43539 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43540 * Now the Switcher is mapped at the right address, we can't fail!
43541 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43542 */
43543 - memcpy(switcher_vma->addr, start_switcher_text,
43544 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43545 end_switcher_text - start_switcher_text);
43546
43547 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43548 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43549 index bfb39bb..08a603b 100644
43550 --- a/drivers/lguest/page_tables.c
43551 +++ b/drivers/lguest/page_tables.c
43552 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43553 /*:*/
43554
43555 #ifdef CONFIG_X86_PAE
43556 -static void release_pmd(pmd_t *spmd)
43557 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43558 {
43559 /* If the entry's not present, there's nothing to release. */
43560 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43561 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43562 index 922a1ac..9dd0c2a 100644
43563 --- a/drivers/lguest/x86/core.c
43564 +++ b/drivers/lguest/x86/core.c
43565 @@ -59,7 +59,7 @@ static struct {
43566 /* Offset from where switcher.S was compiled to where we've copied it */
43567 static unsigned long switcher_offset(void)
43568 {
43569 - return switcher_addr - (unsigned long)start_switcher_text;
43570 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43571 }
43572
43573 /* This cpu's struct lguest_pages (after the Switcher text page) */
43574 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43575 * These copies are pretty cheap, so we do them unconditionally: */
43576 /* Save the current Host top-level page directory.
43577 */
43578 +
43579 +#ifdef CONFIG_PAX_PER_CPU_PGD
43580 + pages->state.host_cr3 = read_cr3();
43581 +#else
43582 pages->state.host_cr3 = __pa(current->mm->pgd);
43583 +#endif
43584 +
43585 /*
43586 * Set up the Guest's page tables to see this CPU's pages (and no
43587 * other CPU's pages).
43588 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43589 * compiled-in switcher code and the high-mapped copy we just made.
43590 */
43591 for (i = 0; i < IDT_ENTRIES; i++)
43592 - default_idt_entries[i] += switcher_offset();
43593 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43594
43595 /*
43596 * Set up the Switcher's per-cpu areas.
43597 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43598 * it will be undisturbed when we switch. To change %cs and jump we
43599 * need this structure to feed to Intel's "lcall" instruction.
43600 */
43601 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43602 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43603 lguest_entry.segment = LGUEST_CS;
43604
43605 /*
43606 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43607 index 40634b0..4f5855e 100644
43608 --- a/drivers/lguest/x86/switcher_32.S
43609 +++ b/drivers/lguest/x86/switcher_32.S
43610 @@ -87,6 +87,7 @@
43611 #include <asm/page.h>
43612 #include <asm/segment.h>
43613 #include <asm/lguest.h>
43614 +#include <asm/processor-flags.h>
43615
43616 // We mark the start of the code to copy
43617 // It's placed in .text tho it's never run here
43618 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43619 // Changes type when we load it: damn Intel!
43620 // For after we switch over our page tables
43621 // That entry will be read-only: we'd crash.
43622 +
43623 +#ifdef CONFIG_PAX_KERNEXEC
43624 + mov %cr0, %edx
43625 + xor $X86_CR0_WP, %edx
43626 + mov %edx, %cr0
43627 +#endif
43628 +
43629 movl $(GDT_ENTRY_TSS*8), %edx
43630 ltr %dx
43631
43632 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43633 // Let's clear it again for our return.
43634 // The GDT descriptor of the Host
43635 // Points to the table after two "size" bytes
43636 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43637 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43638 // Clear "used" from type field (byte 5, bit 2)
43639 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43640 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43641 +
43642 +#ifdef CONFIG_PAX_KERNEXEC
43643 + mov %cr0, %eax
43644 + xor $X86_CR0_WP, %eax
43645 + mov %eax, %cr0
43646 +#endif
43647
43648 // Once our page table's switched, the Guest is live!
43649 // The Host fades as we run this final step.
43650 @@ -295,13 +309,12 @@ deliver_to_host:
43651 // I consulted gcc, and it gave
43652 // These instructions, which I gladly credit:
43653 leal (%edx,%ebx,8), %eax
43654 - movzwl (%eax),%edx
43655 - movl 4(%eax), %eax
43656 - xorw %ax, %ax
43657 - orl %eax, %edx
43658 + movl 4(%eax), %edx
43659 + movw (%eax), %dx
43660 // Now the address of the handler's in %edx
43661 // We call it now: its "iret" drops us home.
43662 - jmp *%edx
43663 + ljmp $__KERNEL_CS, $1f
43664 +1: jmp *%edx
43665
43666 // Every interrupt can come to us here
43667 // But we must truly tell each apart.
43668 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43669 index 9762f1b..3e79734 100644
43670 --- a/drivers/md/bcache/closure.h
43671 +++ b/drivers/md/bcache/closure.h
43672 @@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
43673 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43674 struct workqueue_struct *wq)
43675 {
43676 - BUG_ON(object_is_on_stack(cl));
43677 + BUG_ON(object_starts_on_stack(cl));
43678 closure_set_ip(cl);
43679 cl->fn = fn;
43680 cl->wq = wq;
43681 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43682 index 12dc29b..1596277 100644
43683 --- a/drivers/md/bitmap.c
43684 +++ b/drivers/md/bitmap.c
43685 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43686 chunk_kb ? "KB" : "B");
43687 if (bitmap->storage.file) {
43688 seq_printf(seq, ", file: ");
43689 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43690 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43691 }
43692
43693 seq_printf(seq, "\n");
43694 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43695 index 5152142..623d141 100644
43696 --- a/drivers/md/dm-ioctl.c
43697 +++ b/drivers/md/dm-ioctl.c
43698 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43699 cmd == DM_LIST_VERSIONS_CMD)
43700 return 0;
43701
43702 - if ((cmd == DM_DEV_CREATE_CMD)) {
43703 + if (cmd == DM_DEV_CREATE_CMD) {
43704 if (!*param->name) {
43705 DMWARN("name not supplied when creating device");
43706 return -EINVAL;
43707 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43708 index 9584443..9fc9ac9 100644
43709 --- a/drivers/md/dm-raid1.c
43710 +++ b/drivers/md/dm-raid1.c
43711 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43712
43713 struct mirror {
43714 struct mirror_set *ms;
43715 - atomic_t error_count;
43716 + atomic_unchecked_t error_count;
43717 unsigned long error_type;
43718 struct dm_dev *dev;
43719 sector_t offset;
43720 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43721 struct mirror *m;
43722
43723 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43724 - if (!atomic_read(&m->error_count))
43725 + if (!atomic_read_unchecked(&m->error_count))
43726 return m;
43727
43728 return NULL;
43729 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43730 * simple way to tell if a device has encountered
43731 * errors.
43732 */
43733 - atomic_inc(&m->error_count);
43734 + atomic_inc_unchecked(&m->error_count);
43735
43736 if (test_and_set_bit(error_type, &m->error_type))
43737 return;
43738 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43739 struct mirror *m = get_default_mirror(ms);
43740
43741 do {
43742 - if (likely(!atomic_read(&m->error_count)))
43743 + if (likely(!atomic_read_unchecked(&m->error_count)))
43744 return m;
43745
43746 if (m-- == ms->mirror)
43747 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43748 {
43749 struct mirror *default_mirror = get_default_mirror(m->ms);
43750
43751 - return !atomic_read(&default_mirror->error_count);
43752 + return !atomic_read_unchecked(&default_mirror->error_count);
43753 }
43754
43755 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43756 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43757 */
43758 if (likely(region_in_sync(ms, region, 1)))
43759 m = choose_mirror(ms, bio->bi_sector);
43760 - else if (m && atomic_read(&m->error_count))
43761 + else if (m && atomic_read_unchecked(&m->error_count))
43762 m = NULL;
43763
43764 if (likely(m))
43765 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43766 }
43767
43768 ms->mirror[mirror].ms = ms;
43769 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43770 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43771 ms->mirror[mirror].error_type = 0;
43772 ms->mirror[mirror].offset = offset;
43773
43774 @@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43775 */
43776 static char device_status_char(struct mirror *m)
43777 {
43778 - if (!atomic_read(&(m->error_count)))
43779 + if (!atomic_read_unchecked(&(m->error_count)))
43780 return 'A';
43781
43782 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43783 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43784 index 28a9012..9c0f6a5 100644
43785 --- a/drivers/md/dm-stats.c
43786 +++ b/drivers/md/dm-stats.c
43787 @@ -382,7 +382,7 @@ do_sync_free:
43788 synchronize_rcu_expedited();
43789 dm_stat_free(&s->rcu_head);
43790 } else {
43791 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43792 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43793 call_rcu(&s->rcu_head, dm_stat_free);
43794 }
43795 return 0;
43796 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43797 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43798 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43799 ));
43800 - ACCESS_ONCE(last->last_sector) = end_sector;
43801 - ACCESS_ONCE(last->last_rw) = bi_rw;
43802 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43803 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43804 }
43805
43806 rcu_read_lock();
43807 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43808 index 73c1712..7347292 100644
43809 --- a/drivers/md/dm-stripe.c
43810 +++ b/drivers/md/dm-stripe.c
43811 @@ -21,7 +21,7 @@ struct stripe {
43812 struct dm_dev *dev;
43813 sector_t physical_start;
43814
43815 - atomic_t error_count;
43816 + atomic_unchecked_t error_count;
43817 };
43818
43819 struct stripe_c {
43820 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43821 kfree(sc);
43822 return r;
43823 }
43824 - atomic_set(&(sc->stripe[i].error_count), 0);
43825 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43826 }
43827
43828 ti->private = sc;
43829 @@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43830 DMEMIT("%d ", sc->stripes);
43831 for (i = 0; i < sc->stripes; i++) {
43832 DMEMIT("%s ", sc->stripe[i].dev->name);
43833 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43834 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43835 'D' : 'A';
43836 }
43837 buffer[i] = '\0';
43838 @@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43839 */
43840 for (i = 0; i < sc->stripes; i++)
43841 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43842 - atomic_inc(&(sc->stripe[i].error_count));
43843 - if (atomic_read(&(sc->stripe[i].error_count)) <
43844 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43845 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43846 DM_IO_ERROR_THRESHOLD)
43847 schedule_work(&sc->trigger_event);
43848 }
43849 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43850 index 3ba6a38..b0fa9b0 100644
43851 --- a/drivers/md/dm-table.c
43852 +++ b/drivers/md/dm-table.c
43853 @@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43854 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43855 struct mapped_device *md)
43856 {
43857 - static char *_claim_ptr = "I belong to device-mapper";
43858 + static char _claim_ptr[] = "I belong to device-mapper";
43859 struct block_device *bdev;
43860
43861 int r;
43862 @@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43863 if (!dev_size)
43864 return 0;
43865
43866 - if ((start >= dev_size) || (start + len > dev_size)) {
43867 + if ((start >= dev_size) || (len > dev_size - start)) {
43868 DMWARN("%s: %s too small for target: "
43869 "start=%llu, len=%llu, dev_size=%llu",
43870 dm_device_name(ti->table->md), bdevname(bdev, b),
43871 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43872 index 3bb4506..56e20cc 100644
43873 --- a/drivers/md/dm-thin-metadata.c
43874 +++ b/drivers/md/dm-thin-metadata.c
43875 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43876 {
43877 pmd->info.tm = pmd->tm;
43878 pmd->info.levels = 2;
43879 - pmd->info.value_type.context = pmd->data_sm;
43880 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43881 pmd->info.value_type.size = sizeof(__le64);
43882 pmd->info.value_type.inc = data_block_inc;
43883 pmd->info.value_type.dec = data_block_dec;
43884 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43885
43886 pmd->bl_info.tm = pmd->tm;
43887 pmd->bl_info.levels = 1;
43888 - pmd->bl_info.value_type.context = pmd->data_sm;
43889 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43890 pmd->bl_info.value_type.size = sizeof(__le64);
43891 pmd->bl_info.value_type.inc = data_block_inc;
43892 pmd->bl_info.value_type.dec = data_block_dec;
43893 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43894 index b49c762..c9503cf 100644
43895 --- a/drivers/md/dm.c
43896 +++ b/drivers/md/dm.c
43897 @@ -185,9 +185,9 @@ struct mapped_device {
43898 /*
43899 * Event handling.
43900 */
43901 - atomic_t event_nr;
43902 + atomic_unchecked_t event_nr;
43903 wait_queue_head_t eventq;
43904 - atomic_t uevent_seq;
43905 + atomic_unchecked_t uevent_seq;
43906 struct list_head uevent_list;
43907 spinlock_t uevent_lock; /* Protect access to uevent_list */
43908
43909 @@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43910 spin_lock_init(&md->deferred_lock);
43911 atomic_set(&md->holders, 1);
43912 atomic_set(&md->open_count, 0);
43913 - atomic_set(&md->event_nr, 0);
43914 - atomic_set(&md->uevent_seq, 0);
43915 + atomic_set_unchecked(&md->event_nr, 0);
43916 + atomic_set_unchecked(&md->uevent_seq, 0);
43917 INIT_LIST_HEAD(&md->uevent_list);
43918 spin_lock_init(&md->uevent_lock);
43919
43920 @@ -2176,7 +2176,7 @@ static void event_callback(void *context)
43921
43922 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43923
43924 - atomic_inc(&md->event_nr);
43925 + atomic_inc_unchecked(&md->event_nr);
43926 wake_up(&md->eventq);
43927 }
43928
43929 @@ -2869,18 +2869,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43930
43931 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43932 {
43933 - return atomic_add_return(1, &md->uevent_seq);
43934 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43935 }
43936
43937 uint32_t dm_get_event_nr(struct mapped_device *md)
43938 {
43939 - return atomic_read(&md->event_nr);
43940 + return atomic_read_unchecked(&md->event_nr);
43941 }
43942
43943 int dm_wait_event(struct mapped_device *md, int event_nr)
43944 {
43945 return wait_event_interruptible(md->eventq,
43946 - (event_nr != atomic_read(&md->event_nr)));
43947 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43948 }
43949
43950 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43951 diff --git a/drivers/md/md.c b/drivers/md/md.c
43952 index 369d919..ba7049c 100644
43953 --- a/drivers/md/md.c
43954 +++ b/drivers/md/md.c
43955 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43956 * start build, activate spare
43957 */
43958 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43959 -static atomic_t md_event_count;
43960 +static atomic_unchecked_t md_event_count;
43961 void md_new_event(struct mddev *mddev)
43962 {
43963 - atomic_inc(&md_event_count);
43964 + atomic_inc_unchecked(&md_event_count);
43965 wake_up(&md_event_waiters);
43966 }
43967 EXPORT_SYMBOL_GPL(md_new_event);
43968 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43969 */
43970 static void md_new_event_inintr(struct mddev *mddev)
43971 {
43972 - atomic_inc(&md_event_count);
43973 + atomic_inc_unchecked(&md_event_count);
43974 wake_up(&md_event_waiters);
43975 }
43976
43977 @@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43978 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43979 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43980 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43981 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43982 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43983
43984 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43985 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43986 @@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43987 else
43988 sb->resync_offset = cpu_to_le64(0);
43989
43990 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43991 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43992
43993 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43994 sb->size = cpu_to_le64(mddev->dev_sectors);
43995 @@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43996 static ssize_t
43997 errors_show(struct md_rdev *rdev, char *page)
43998 {
43999 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44000 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44001 }
44002
44003 static ssize_t
44004 @@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44005 char *e;
44006 unsigned long n = simple_strtoul(buf, &e, 10);
44007 if (*buf && (*e == 0 || *e == '\n')) {
44008 - atomic_set(&rdev->corrected_errors, n);
44009 + atomic_set_unchecked(&rdev->corrected_errors, n);
44010 return len;
44011 }
44012 return -EINVAL;
44013 @@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
44014 rdev->sb_loaded = 0;
44015 rdev->bb_page = NULL;
44016 atomic_set(&rdev->nr_pending, 0);
44017 - atomic_set(&rdev->read_errors, 0);
44018 - atomic_set(&rdev->corrected_errors, 0);
44019 + atomic_set_unchecked(&rdev->read_errors, 0);
44020 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44021
44022 INIT_LIST_HEAD(&rdev->same_set);
44023 init_waitqueue_head(&rdev->blocked_wait);
44024 @@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44025
44026 spin_unlock(&pers_lock);
44027 seq_printf(seq, "\n");
44028 - seq->poll_event = atomic_read(&md_event_count);
44029 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44030 return 0;
44031 }
44032 if (v == (void*)2) {
44033 @@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44034 return error;
44035
44036 seq = file->private_data;
44037 - seq->poll_event = atomic_read(&md_event_count);
44038 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44039 return error;
44040 }
44041
44042 @@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44043 /* always allow read */
44044 mask = POLLIN | POLLRDNORM;
44045
44046 - if (seq->poll_event != atomic_read(&md_event_count))
44047 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44048 mask |= POLLERR | POLLPRI;
44049 return mask;
44050 }
44051 @@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44052 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44053 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44054 (int)part_stat_read(&disk->part0, sectors[1]) -
44055 - atomic_read(&disk->sync_io);
44056 + atomic_read_unchecked(&disk->sync_io);
44057 /* sync IO will cause sync_io to increase before the disk_stats
44058 * as sync_io is counted when a request starts, and
44059 * disk_stats is counted when it completes.
44060 diff --git a/drivers/md/md.h b/drivers/md/md.h
44061 index 0095ec8..c89277a 100644
44062 --- a/drivers/md/md.h
44063 +++ b/drivers/md/md.h
44064 @@ -94,13 +94,13 @@ struct md_rdev {
44065 * only maintained for arrays that
44066 * support hot removal
44067 */
44068 - atomic_t read_errors; /* number of consecutive read errors that
44069 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44070 * we have tried to ignore.
44071 */
44072 struct timespec last_read_error; /* monotonic time since our
44073 * last read error
44074 */
44075 - atomic_t corrected_errors; /* number of corrected read errors,
44076 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44077 * for reporting to userspace and storing
44078 * in superblock.
44079 */
44080 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44081
44082 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44083 {
44084 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44085 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44086 }
44087
44088 struct md_personality
44089 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44090 index 579b582..9fb6185 100644
44091 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44092 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44093 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44094 * Flick into a mode where all blocks get allocated in the new area.
44095 */
44096 smm->begin = old_len;
44097 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44098 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44099
44100 /*
44101 * Extend.
44102 @@ -710,7 +710,7 @@ out:
44103 /*
44104 * Switch back to normal behaviour.
44105 */
44106 - memcpy(sm, &ops, sizeof(*sm));
44107 + memcpy((void *)sm, &ops, sizeof(*sm));
44108 return r;
44109 }
44110
44111 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44112 index 3e6d115..ffecdeb 100644
44113 --- a/drivers/md/persistent-data/dm-space-map.h
44114 +++ b/drivers/md/persistent-data/dm-space-map.h
44115 @@ -71,6 +71,7 @@ struct dm_space_map {
44116 dm_sm_threshold_fn fn,
44117 void *context);
44118 };
44119 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44120
44121 /*----------------------------------------------------------------*/
44122
44123 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44124 index 63b2e8d..225f16b 100644
44125 --- a/drivers/md/raid1.c
44126 +++ b/drivers/md/raid1.c
44127 @@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44128 if (r1_sync_page_io(rdev, sect, s,
44129 bio->bi_io_vec[idx].bv_page,
44130 READ) != 0)
44131 - atomic_add(s, &rdev->corrected_errors);
44132 + atomic_add_unchecked(s, &rdev->corrected_errors);
44133 }
44134 sectors -= s;
44135 sect += s;
44136 @@ -2155,7 +2155,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44137 test_bit(In_sync, &rdev->flags)) {
44138 if (r1_sync_page_io(rdev, sect, s,
44139 conf->tmppage, READ)) {
44140 - atomic_add(s, &rdev->corrected_errors);
44141 + atomic_add_unchecked(s, &rdev->corrected_errors);
44142 printk(KERN_INFO
44143 "md/raid1:%s: read error corrected "
44144 "(%d sectors at %llu on %s)\n",
44145 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44146 index 06eeb99..770613e 100644
44147 --- a/drivers/md/raid10.c
44148 +++ b/drivers/md/raid10.c
44149 @@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
44150 /* The write handler will notice the lack of
44151 * R10BIO_Uptodate and record any errors etc
44152 */
44153 - atomic_add(r10_bio->sectors,
44154 + atomic_add_unchecked(r10_bio->sectors,
44155 &conf->mirrors[d].rdev->corrected_errors);
44156
44157 /* for reconstruct, we always reschedule after a read.
44158 @@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44159 {
44160 struct timespec cur_time_mon;
44161 unsigned long hours_since_last;
44162 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44163 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44164
44165 ktime_get_ts(&cur_time_mon);
44166
44167 @@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44168 * overflowing the shift of read_errors by hours_since_last.
44169 */
44170 if (hours_since_last >= 8 * sizeof(read_errors))
44171 - atomic_set(&rdev->read_errors, 0);
44172 + atomic_set_unchecked(&rdev->read_errors, 0);
44173 else
44174 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44175 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44176 }
44177
44178 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44179 @@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44180 return;
44181
44182 check_decay_read_errors(mddev, rdev);
44183 - atomic_inc(&rdev->read_errors);
44184 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44185 + atomic_inc_unchecked(&rdev->read_errors);
44186 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44187 char b[BDEVNAME_SIZE];
44188 bdevname(rdev->bdev, b);
44189
44190 @@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44191 "md/raid10:%s: %s: Raid device exceeded "
44192 "read_error threshold [cur %d:max %d]\n",
44193 mdname(mddev), b,
44194 - atomic_read(&rdev->read_errors), max_read_errors);
44195 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44196 printk(KERN_NOTICE
44197 "md/raid10:%s: %s: Failing raid device\n",
44198 mdname(mddev), b);
44199 @@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44200 sect +
44201 choose_data_offset(r10_bio, rdev)),
44202 bdevname(rdev->bdev, b));
44203 - atomic_add(s, &rdev->corrected_errors);
44204 + atomic_add_unchecked(s, &rdev->corrected_errors);
44205 }
44206
44207 rdev_dec_pending(rdev, mddev);
44208 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44209 index 48cdec8..c7726b1 100644
44210 --- a/drivers/md/raid5.c
44211 +++ b/drivers/md/raid5.c
44212 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44213 mdname(conf->mddev), STRIPE_SECTORS,
44214 (unsigned long long)s,
44215 bdevname(rdev->bdev, b));
44216 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44217 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44218 clear_bit(R5_ReadError, &sh->dev[i].flags);
44219 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44220 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44221 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44222
44223 - if (atomic_read(&rdev->read_errors))
44224 - atomic_set(&rdev->read_errors, 0);
44225 + if (atomic_read_unchecked(&rdev->read_errors))
44226 + atomic_set_unchecked(&rdev->read_errors, 0);
44227 } else {
44228 const char *bdn = bdevname(rdev->bdev, b);
44229 int retry = 0;
44230 int set_bad = 0;
44231
44232 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44233 - atomic_inc(&rdev->read_errors);
44234 + atomic_inc_unchecked(&rdev->read_errors);
44235 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44236 printk_ratelimited(
44237 KERN_WARNING
44238 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44239 mdname(conf->mddev),
44240 (unsigned long long)s,
44241 bdn);
44242 - } else if (atomic_read(&rdev->read_errors)
44243 + } else if (atomic_read_unchecked(&rdev->read_errors)
44244 > conf->max_nr_stripes)
44245 printk(KERN_WARNING
44246 "md/raid:%s: Too many read errors, failing device %s.\n",
44247 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44248 index 983db75..ef9248c 100644
44249 --- a/drivers/media/dvb-core/dvbdev.c
44250 +++ b/drivers/media/dvb-core/dvbdev.c
44251 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44252 const struct dvb_device *template, void *priv, int type)
44253 {
44254 struct dvb_device *dvbdev;
44255 - struct file_operations *dvbdevfops;
44256 + file_operations_no_const *dvbdevfops;
44257 struct device *clsdev;
44258 int minor;
44259 int id;
44260 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44261 index 9b6c3bb..baeb5c7 100644
44262 --- a/drivers/media/dvb-frontends/dib3000.h
44263 +++ b/drivers/media/dvb-frontends/dib3000.h
44264 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44265 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44266 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44267 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44268 -};
44269 +} __no_const;
44270
44271 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44272 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44273 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44274 index ed8cb90..5ef7f79 100644
44275 --- a/drivers/media/pci/cx88/cx88-video.c
44276 +++ b/drivers/media/pci/cx88/cx88-video.c
44277 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44278
44279 /* ------------------------------------------------------------------ */
44280
44281 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44282 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44283 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44284 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44285 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44286 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44287
44288 module_param_array(video_nr, int, NULL, 0444);
44289 module_param_array(vbi_nr, int, NULL, 0444);
44290 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44291 index 802642d..5534900 100644
44292 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44293 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44294 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44295 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44296
44297 /* ivtv instance counter */
44298 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44299 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44300
44301 /* Parameter declarations */
44302 static int cardtype[IVTV_MAX_CARDS];
44303 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44304 index dfd0a21..6bbb465 100644
44305 --- a/drivers/media/platform/omap/omap_vout.c
44306 +++ b/drivers/media/platform/omap/omap_vout.c
44307 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44308 OMAP_VIDEO2,
44309 };
44310
44311 -static struct videobuf_queue_ops video_vbq_ops;
44312 /* Variables configurable through module params*/
44313 static u32 video1_numbuffers = 3;
44314 static u32 video2_numbuffers = 3;
44315 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44316 {
44317 struct videobuf_queue *q;
44318 struct omap_vout_device *vout = NULL;
44319 + static struct videobuf_queue_ops video_vbq_ops = {
44320 + .buf_setup = omap_vout_buffer_setup,
44321 + .buf_prepare = omap_vout_buffer_prepare,
44322 + .buf_release = omap_vout_buffer_release,
44323 + .buf_queue = omap_vout_buffer_queue,
44324 + };
44325
44326 vout = video_drvdata(file);
44327 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44328 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44329 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44330
44331 q = &vout->vbq;
44332 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44333 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44334 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44335 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44336 spin_lock_init(&vout->vbq_lock);
44337
44338 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44339 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44340 index fb2acc5..a2fcbdc4 100644
44341 --- a/drivers/media/platform/s5p-tv/mixer.h
44342 +++ b/drivers/media/platform/s5p-tv/mixer.h
44343 @@ -156,7 +156,7 @@ struct mxr_layer {
44344 /** layer index (unique identifier) */
44345 int idx;
44346 /** callbacks for layer methods */
44347 - struct mxr_layer_ops ops;
44348 + struct mxr_layer_ops *ops;
44349 /** format array */
44350 const struct mxr_format **fmt_array;
44351 /** size of format array */
44352 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44353 index 74344c7..a39e70e 100644
44354 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44355 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44356 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44357 {
44358 struct mxr_layer *layer;
44359 int ret;
44360 - struct mxr_layer_ops ops = {
44361 + static struct mxr_layer_ops ops = {
44362 .release = mxr_graph_layer_release,
44363 .buffer_set = mxr_graph_buffer_set,
44364 .stream_set = mxr_graph_stream_set,
44365 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44366 index b713403..53cb5ad 100644
44367 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44368 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44369 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44370 layer->update_buf = next;
44371 }
44372
44373 - layer->ops.buffer_set(layer, layer->update_buf);
44374 + layer->ops->buffer_set(layer, layer->update_buf);
44375
44376 if (done && done != layer->shadow_buf)
44377 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44378 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44379 index 81b97db..b089ccd 100644
44380 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44381 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44382 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44383 layer->geo.src.height = layer->geo.src.full_height;
44384
44385 mxr_geometry_dump(mdev, &layer->geo);
44386 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44387 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44388 mxr_geometry_dump(mdev, &layer->geo);
44389 }
44390
44391 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44392 layer->geo.dst.full_width = mbus_fmt.width;
44393 layer->geo.dst.full_height = mbus_fmt.height;
44394 layer->geo.dst.field = mbus_fmt.field;
44395 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44396 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44397
44398 mxr_geometry_dump(mdev, &layer->geo);
44399 }
44400 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44401 /* set source size to highest accepted value */
44402 geo->src.full_width = max(geo->dst.full_width, pix->width);
44403 geo->src.full_height = max(geo->dst.full_height, pix->height);
44404 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44405 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44406 mxr_geometry_dump(mdev, &layer->geo);
44407 /* set cropping to total visible screen */
44408 geo->src.width = pix->width;
44409 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44410 geo->src.x_offset = 0;
44411 geo->src.y_offset = 0;
44412 /* assure consistency of geometry */
44413 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44414 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44415 mxr_geometry_dump(mdev, &layer->geo);
44416 /* set full size to lowest possible value */
44417 geo->src.full_width = 0;
44418 geo->src.full_height = 0;
44419 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44420 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44421 mxr_geometry_dump(mdev, &layer->geo);
44422
44423 /* returning results */
44424 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44425 target->width = s->r.width;
44426 target->height = s->r.height;
44427
44428 - layer->ops.fix_geometry(layer, stage, s->flags);
44429 + layer->ops->fix_geometry(layer, stage, s->flags);
44430
44431 /* retrieve update selection rectangle */
44432 res.left = target->x_offset;
44433 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44434 mxr_output_get(mdev);
44435
44436 mxr_layer_update_output(layer);
44437 - layer->ops.format_set(layer);
44438 + layer->ops->format_set(layer);
44439 /* enabling layer in hardware */
44440 spin_lock_irqsave(&layer->enq_slock, flags);
44441 layer->state = MXR_LAYER_STREAMING;
44442 spin_unlock_irqrestore(&layer->enq_slock, flags);
44443
44444 - layer->ops.stream_set(layer, MXR_ENABLE);
44445 + layer->ops->stream_set(layer, MXR_ENABLE);
44446 mxr_streamer_get(mdev);
44447
44448 return 0;
44449 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44450 spin_unlock_irqrestore(&layer->enq_slock, flags);
44451
44452 /* disabling layer in hardware */
44453 - layer->ops.stream_set(layer, MXR_DISABLE);
44454 + layer->ops->stream_set(layer, MXR_DISABLE);
44455 /* remove one streamer */
44456 mxr_streamer_put(mdev);
44457 /* allow changes in output configuration */
44458 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44459
44460 void mxr_layer_release(struct mxr_layer *layer)
44461 {
44462 - if (layer->ops.release)
44463 - layer->ops.release(layer);
44464 + if (layer->ops->release)
44465 + layer->ops->release(layer);
44466 }
44467
44468 void mxr_base_layer_release(struct mxr_layer *layer)
44469 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44470
44471 layer->mdev = mdev;
44472 layer->idx = idx;
44473 - layer->ops = *ops;
44474 + layer->ops = ops;
44475
44476 spin_lock_init(&layer->enq_slock);
44477 INIT_LIST_HEAD(&layer->enq_list);
44478 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44479 index c9388c4..ce71ece 100644
44480 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44481 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44482 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44483 {
44484 struct mxr_layer *layer;
44485 int ret;
44486 - struct mxr_layer_ops ops = {
44487 + static struct mxr_layer_ops ops = {
44488 .release = mxr_vp_layer_release,
44489 .buffer_set = mxr_vp_buffer_set,
44490 .stream_set = mxr_vp_stream_set,
44491 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44492 index 2d4e73b..8b4d5b6 100644
44493 --- a/drivers/media/platform/vivi.c
44494 +++ b/drivers/media/platform/vivi.c
44495 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44496 MODULE_LICENSE("Dual BSD/GPL");
44497 MODULE_VERSION(VIVI_VERSION);
44498
44499 -static unsigned video_nr = -1;
44500 -module_param(video_nr, uint, 0644);
44501 +static int video_nr = -1;
44502 +module_param(video_nr, int, 0644);
44503 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44504
44505 static unsigned n_devs = 1;
44506 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44507 index 545c04c..a14bded 100644
44508 --- a/drivers/media/radio/radio-cadet.c
44509 +++ b/drivers/media/radio/radio-cadet.c
44510 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44511 unsigned char readbuf[RDS_BUFFER];
44512 int i = 0;
44513
44514 + if (count > RDS_BUFFER)
44515 + return -EFAULT;
44516 mutex_lock(&dev->lock);
44517 if (dev->rdsstat == 0)
44518 cadet_start_rds(dev);
44519 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44520 while (i < count && dev->rdsin != dev->rdsout)
44521 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44522
44523 - if (i && copy_to_user(data, readbuf, i))
44524 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44525 i = -EFAULT;
44526 unlock:
44527 mutex_unlock(&dev->lock);
44528 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44529 index 5236035..c622c74 100644
44530 --- a/drivers/media/radio/radio-maxiradio.c
44531 +++ b/drivers/media/radio/radio-maxiradio.c
44532 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44533 /* TEA5757 pin mappings */
44534 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44535
44536 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44537 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44538
44539 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44540 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44541 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44542 index 050b3bb..79f62b9 100644
44543 --- a/drivers/media/radio/radio-shark.c
44544 +++ b/drivers/media/radio/radio-shark.c
44545 @@ -79,7 +79,7 @@ struct shark_device {
44546 u32 last_val;
44547 };
44548
44549 -static atomic_t shark_instance = ATOMIC_INIT(0);
44550 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44551
44552 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44553 {
44554 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44555 index 8654e0d..0608a64 100644
44556 --- a/drivers/media/radio/radio-shark2.c
44557 +++ b/drivers/media/radio/radio-shark2.c
44558 @@ -74,7 +74,7 @@ struct shark_device {
44559 u8 *transfer_buffer;
44560 };
44561
44562 -static atomic_t shark_instance = ATOMIC_INIT(0);
44563 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44564
44565 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44566 {
44567 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44568 index 2fd9009..278cc1e 100644
44569 --- a/drivers/media/radio/radio-si476x.c
44570 +++ b/drivers/media/radio/radio-si476x.c
44571 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44572 struct si476x_radio *radio;
44573 struct v4l2_ctrl *ctrl;
44574
44575 - static atomic_t instance = ATOMIC_INIT(0);
44576 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44577
44578 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44579 if (!radio)
44580 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
44581 index 46da365..3ba4206 100644
44582 --- a/drivers/media/rc/rc-main.c
44583 +++ b/drivers/media/rc/rc-main.c
44584 @@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
44585 int rc_register_device(struct rc_dev *dev)
44586 {
44587 static bool raw_init = false; /* raw decoders loaded? */
44588 - static atomic_t devno = ATOMIC_INIT(0);
44589 + static atomic_unchecked_t devno = ATOMIC_INIT(0);
44590 struct rc_map *rc_map;
44591 const char *path;
44592 int rc;
44593 @@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
44594 */
44595 mutex_lock(&dev->lock);
44596
44597 - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
44598 + dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
44599 dev_set_name(&dev->dev, "rc%ld", dev->devno);
44600 dev_set_drvdata(&dev->dev, dev);
44601 rc = device_add(&dev->dev);
44602 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44603 index a1c641e..3007da9 100644
44604 --- a/drivers/media/usb/dvb-usb/cxusb.c
44605 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44606 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44607
44608 struct dib0700_adapter_state {
44609 int (*set_param_save) (struct dvb_frontend *);
44610 -};
44611 +} __no_const;
44612
44613 static int dib7070_set_param_override(struct dvb_frontend *fe)
44614 {
44615 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44616 index f272ed8..6289f9c 100644
44617 --- a/drivers/media/usb/dvb-usb/dw2102.c
44618 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44619 @@ -121,7 +121,7 @@ struct su3000_state {
44620
44621 struct s6x0_state {
44622 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44623 -};
44624 +} __no_const;
44625
44626 /* debug */
44627 static int dvb_usb_dw2102_debug;
44628 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44629 index 8f7a6a4..eb0e1d4 100644
44630 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44631 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44632 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44633 __u32 reserved;
44634 };
44635
44636 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44637 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44638 enum v4l2_memory memory)
44639 {
44640 void __user *up_pln;
44641 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44642 return 0;
44643 }
44644
44645 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44646 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44647 enum v4l2_memory memory)
44648 {
44649 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44650 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44651 * by passing a very big num_planes value */
44652 uplane = compat_alloc_user_space(num_planes *
44653 sizeof(struct v4l2_plane));
44654 - kp->m.planes = uplane;
44655 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44656
44657 while (--num_planes >= 0) {
44658 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44659 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44660 if (num_planes == 0)
44661 return 0;
44662
44663 - uplane = kp->m.planes;
44664 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44665 if (get_user(p, &up->m.planes))
44666 return -EFAULT;
44667 uplane32 = compat_ptr(p);
44668 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44669 get_user(kp->capability, &up->capability) ||
44670 get_user(kp->flags, &up->flags))
44671 return -EFAULT;
44672 - kp->base = compat_ptr(tmp);
44673 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44674 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44675 return 0;
44676 }
44677 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44678 n * sizeof(struct v4l2_ext_control32)))
44679 return -EFAULT;
44680 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44681 - kp->controls = kcontrols;
44682 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44683 while (--n >= 0) {
44684 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44685 return -EFAULT;
44686 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44687 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44688 {
44689 struct v4l2_ext_control32 __user *ucontrols;
44690 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44691 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44692 int n = kp->count;
44693 compat_caddr_t p;
44694
44695 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44696 put_user(kp->start_block, &up->start_block) ||
44697 put_user(kp->blocks, &up->blocks) ||
44698 put_user(tmp, &up->edid) ||
44699 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44700 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44701 return -EFAULT;
44702 return 0;
44703 }
44704 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44705 index fb46790..ae1f8fa 100644
44706 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
44707 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44708 @@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44709 return 0;
44710
44711 case V4L2_CTRL_TYPE_STRING:
44712 - len = strlen(c->string);
44713 - if (len < ctrl->minimum)
44714 + len = strlen_user(c->string);
44715 + if (!len || len < ctrl->minimum)
44716 return -ERANGE;
44717 if ((len - ctrl->minimum) % ctrl->step)
44718 return -ERANGE;
44719 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44720 index 02d1b63..5fd6b16 100644
44721 --- a/drivers/media/v4l2-core/v4l2-device.c
44722 +++ b/drivers/media/v4l2-core/v4l2-device.c
44723 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44724 EXPORT_SYMBOL_GPL(v4l2_device_put);
44725
44726 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44727 - atomic_t *instance)
44728 + atomic_unchecked_t *instance)
44729 {
44730 - int num = atomic_inc_return(instance) - 1;
44731 + int num = atomic_inc_return_unchecked(instance) - 1;
44732 int len = strlen(basename);
44733
44734 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44735 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44736 index 68e6b5e..8eb2aec 100644
44737 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44738 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44739 @@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
44740 struct file *file, void *fh, void *p);
44741 } u;
44742 void (*debug)(const void *arg, bool write_only);
44743 -};
44744 +} __do_const;
44745 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44746
44747 /* This control needs a priority check */
44748 #define INFO_FL_PRIO (1 << 0)
44749 @@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
44750 struct video_device *vfd = video_devdata(file);
44751 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44752 bool write_only = false;
44753 - struct v4l2_ioctl_info default_info;
44754 + v4l2_ioctl_info_no_const default_info;
44755 const struct v4l2_ioctl_info *info;
44756 void *fh = file->private_data;
44757 struct v4l2_fh *vfh = NULL;
44758 @@ -2194,7 +2195,7 @@ done:
44759 }
44760
44761 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44762 - void * __user *user_ptr, void ***kernel_ptr)
44763 + void __user **user_ptr, void ***kernel_ptr)
44764 {
44765 int ret = 0;
44766
44767 @@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44768 ret = -EINVAL;
44769 break;
44770 }
44771 - *user_ptr = (void __user *)buf->m.planes;
44772 + *user_ptr = (void __force_user *)buf->m.planes;
44773 *kernel_ptr = (void *)&buf->m.planes;
44774 *array_size = sizeof(struct v4l2_plane) * buf->length;
44775 ret = 1;
44776 @@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44777 ret = -EINVAL;
44778 break;
44779 }
44780 - *user_ptr = (void __user *)ctrls->controls;
44781 + *user_ptr = (void __force_user *)ctrls->controls;
44782 *kernel_ptr = (void *)&ctrls->controls;
44783 *array_size = sizeof(struct v4l2_ext_control)
44784 * ctrls->count;
44785 @@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44786 err = -ENOTTY;
44787
44788 if (has_array_args) {
44789 - *kernel_ptr = user_ptr;
44790 + *kernel_ptr = (void __force_kernel *)user_ptr;
44791 if (copy_to_user(user_ptr, mbuf, array_size))
44792 err = -EFAULT;
44793 goto out_array_args;
44794 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44795 index 767ff4d..c69d259 100644
44796 --- a/drivers/message/fusion/mptbase.c
44797 +++ b/drivers/message/fusion/mptbase.c
44798 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44799 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44800 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44801
44802 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44803 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44804 +#else
44805 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44806 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44807 +#endif
44808 +
44809 /*
44810 * Rounding UP to nearest 4-kB boundary here...
44811 */
44812 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44813 ioc->facts.GlobalCredits);
44814
44815 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44816 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44817 + NULL, NULL);
44818 +#else
44819 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44820 +#endif
44821 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44822 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44823 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44824 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44825 index dd239bd..689c4f7 100644
44826 --- a/drivers/message/fusion/mptsas.c
44827 +++ b/drivers/message/fusion/mptsas.c
44828 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44829 return 0;
44830 }
44831
44832 +static inline void
44833 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44834 +{
44835 + if (phy_info->port_details) {
44836 + phy_info->port_details->rphy = rphy;
44837 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44838 + ioc->name, rphy));
44839 + }
44840 +
44841 + if (rphy) {
44842 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44843 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44844 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44845 + ioc->name, rphy, rphy->dev.release));
44846 + }
44847 +}
44848 +
44849 /* no mutex */
44850 static void
44851 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44852 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44853 return NULL;
44854 }
44855
44856 -static inline void
44857 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44858 -{
44859 - if (phy_info->port_details) {
44860 - phy_info->port_details->rphy = rphy;
44861 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44862 - ioc->name, rphy));
44863 - }
44864 -
44865 - if (rphy) {
44866 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44867 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44868 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44869 - ioc->name, rphy, rphy->dev.release));
44870 - }
44871 -}
44872 -
44873 static inline struct sas_port *
44874 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44875 {
44876 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44877 index 727819c..ad74694 100644
44878 --- a/drivers/message/fusion/mptscsih.c
44879 +++ b/drivers/message/fusion/mptscsih.c
44880 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44881
44882 h = shost_priv(SChost);
44883
44884 - if (h) {
44885 - if (h->info_kbuf == NULL)
44886 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44887 - return h->info_kbuf;
44888 - h->info_kbuf[0] = '\0';
44889 + if (!h)
44890 + return NULL;
44891
44892 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44893 - h->info_kbuf[size-1] = '\0';
44894 - }
44895 + if (h->info_kbuf == NULL)
44896 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44897 + return h->info_kbuf;
44898 + h->info_kbuf[0] = '\0';
44899 +
44900 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44901 + h->info_kbuf[size-1] = '\0';
44902
44903 return h->info_kbuf;
44904 }
44905 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44906 index b7d87cd..3fb36da 100644
44907 --- a/drivers/message/i2o/i2o_proc.c
44908 +++ b/drivers/message/i2o/i2o_proc.c
44909 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44910 "Array Controller Device"
44911 };
44912
44913 -static char *chtostr(char *tmp, u8 *chars, int n)
44914 -{
44915 - tmp[0] = 0;
44916 - return strncat(tmp, (char *)chars, n);
44917 -}
44918 -
44919 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44920 char *group)
44921 {
44922 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44923 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44924 {
44925 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44926 - static u32 work32[5];
44927 - static u8 *work8 = (u8 *) work32;
44928 - static u16 *work16 = (u16 *) work32;
44929 + u32 work32[5];
44930 + u8 *work8 = (u8 *) work32;
44931 + u16 *work16 = (u16 *) work32;
44932 int token;
44933 u32 hwcap;
44934
44935 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44936 } *result;
44937
44938 i2o_exec_execute_ddm_table ddm_table;
44939 - char tmp[28 + 1];
44940
44941 result = kmalloc(sizeof(*result), GFP_KERNEL);
44942 if (!result)
44943 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44944
44945 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44946 seq_printf(seq, "%-#8x", ddm_table.module_id);
44947 - seq_printf(seq, "%-29s",
44948 - chtostr(tmp, ddm_table.module_name_version, 28));
44949 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44950 seq_printf(seq, "%9d ", ddm_table.data_size);
44951 seq_printf(seq, "%8d", ddm_table.code_size);
44952
44953 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44954
44955 i2o_driver_result_table *result;
44956 i2o_driver_store_table *dst;
44957 - char tmp[28 + 1];
44958
44959 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44960 if (result == NULL)
44961 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44962
44963 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44964 seq_printf(seq, "%-#8x", dst->module_id);
44965 - seq_printf(seq, "%-29s",
44966 - chtostr(tmp, dst->module_name_version, 28));
44967 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44968 + seq_printf(seq, "%-.28s", dst->module_name_version);
44969 + seq_printf(seq, "%-.8s", dst->date);
44970 seq_printf(seq, "%8d ", dst->module_size);
44971 seq_printf(seq, "%8d ", dst->mpb_size);
44972 seq_printf(seq, "0x%04x", dst->module_flags);
44973 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44974 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44975 {
44976 struct i2o_device *d = (struct i2o_device *)seq->private;
44977 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44978 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44979 // == (allow) 512d bytes (max)
44980 - static u16 *work16 = (u16 *) work32;
44981 + u16 *work16 = (u16 *) work32;
44982 int token;
44983 - char tmp[16 + 1];
44984
44985 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44986
44987 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44988 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44989 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44990 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44991 - seq_printf(seq, "Vendor info : %s\n",
44992 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44993 - seq_printf(seq, "Product info : %s\n",
44994 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44995 - seq_printf(seq, "Description : %s\n",
44996 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44997 - seq_printf(seq, "Product rev. : %s\n",
44998 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44999 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45000 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45001 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45002 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45003
45004 seq_printf(seq, "Serial number : ");
45005 print_serial_number(seq, (u8 *) (work32 + 16),
45006 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45007 u8 pad[256]; // allow up to 256 byte (max) serial number
45008 } result;
45009
45010 - char tmp[24 + 1];
45011 -
45012 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45013
45014 if (token < 0) {
45015 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45016 }
45017
45018 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45019 - seq_printf(seq, "Module name : %s\n",
45020 - chtostr(tmp, result.module_name, 24));
45021 - seq_printf(seq, "Module revision : %s\n",
45022 - chtostr(tmp, result.module_rev, 8));
45023 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
45024 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45025
45026 seq_printf(seq, "Serial number : ");
45027 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45028 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45029 u8 instance_number[4];
45030 } result;
45031
45032 - char tmp[64 + 1];
45033 -
45034 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45035
45036 if (token < 0) {
45037 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45038 return 0;
45039 }
45040
45041 - seq_printf(seq, "Device name : %s\n",
45042 - chtostr(tmp, result.device_name, 64));
45043 - seq_printf(seq, "Service name : %s\n",
45044 - chtostr(tmp, result.service_name, 64));
45045 - seq_printf(seq, "Physical name : %s\n",
45046 - chtostr(tmp, result.physical_location, 64));
45047 - seq_printf(seq, "Instance number : %s\n",
45048 - chtostr(tmp, result.instance_number, 4));
45049 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
45050 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
45051 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45052 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45053
45054 return 0;
45055 }
45056 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45057 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45058 {
45059 struct i2o_device *d = (struct i2o_device *)seq->private;
45060 - static u32 work32[12];
45061 - static u16 *work16 = (u16 *) work32;
45062 - static u8 *work8 = (u8 *) work32;
45063 + u32 work32[12];
45064 + u16 *work16 = (u16 *) work32;
45065 + u8 *work8 = (u8 *) work32;
45066 int token;
45067
45068 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45069 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45070 index a8c08f3..155fe3d 100644
45071 --- a/drivers/message/i2o/iop.c
45072 +++ b/drivers/message/i2o/iop.c
45073 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45074
45075 spin_lock_irqsave(&c->context_list_lock, flags);
45076
45077 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45078 - atomic_inc(&c->context_list_counter);
45079 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45080 + atomic_inc_unchecked(&c->context_list_counter);
45081
45082 - entry->context = atomic_read(&c->context_list_counter);
45083 + entry->context = atomic_read_unchecked(&c->context_list_counter);
45084
45085 list_add(&entry->list, &c->context_list);
45086
45087 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45088
45089 #if BITS_PER_LONG == 64
45090 spin_lock_init(&c->context_list_lock);
45091 - atomic_set(&c->context_list_counter, 0);
45092 + atomic_set_unchecked(&c->context_list_counter, 0);
45093 INIT_LIST_HEAD(&c->context_list);
45094 #endif
45095
45096 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45097 index e33e385..28dfd23 100644
45098 --- a/drivers/mfd/ab8500-debugfs.c
45099 +++ b/drivers/mfd/ab8500-debugfs.c
45100 @@ -100,7 +100,7 @@ static int irq_last;
45101 static u32 *irq_count;
45102 static int num_irqs;
45103
45104 -static struct device_attribute **dev_attr;
45105 +static device_attribute_no_const **dev_attr;
45106 static char **event_name;
45107
45108 static u8 avg_sample = SAMPLE_16;
45109 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45110 index fcbb2e9..2635e11 100644
45111 --- a/drivers/mfd/janz-cmodio.c
45112 +++ b/drivers/mfd/janz-cmodio.c
45113 @@ -13,6 +13,7 @@
45114
45115 #include <linux/kernel.h>
45116 #include <linux/module.h>
45117 +#include <linux/slab.h>
45118 #include <linux/init.h>
45119 #include <linux/pci.h>
45120 #include <linux/interrupt.h>
45121 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45122 index 176aa26..27811b2 100644
45123 --- a/drivers/mfd/max8925-i2c.c
45124 +++ b/drivers/mfd/max8925-i2c.c
45125 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45126 const struct i2c_device_id *id)
45127 {
45128 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45129 - static struct max8925_chip *chip;
45130 + struct max8925_chip *chip;
45131 struct device_node *node = client->dev.of_node;
45132
45133 if (node && !pdata) {
45134 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45135 index c0f608e..286f8ec 100644
45136 --- a/drivers/mfd/tps65910.c
45137 +++ b/drivers/mfd/tps65910.c
45138 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45139 struct tps65910_platform_data *pdata)
45140 {
45141 int ret = 0;
45142 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45143 + struct regmap_irq_chip *tps6591x_irqs_chip;
45144
45145 if (!irq) {
45146 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45147 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45148 index 9aa6d1e..1631bfc 100644
45149 --- a/drivers/mfd/twl4030-irq.c
45150 +++ b/drivers/mfd/twl4030-irq.c
45151 @@ -35,6 +35,7 @@
45152 #include <linux/of.h>
45153 #include <linux/irqdomain.h>
45154 #include <linux/i2c/twl.h>
45155 +#include <asm/pgtable.h>
45156
45157 #include "twl-core.h"
45158
45159 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45160 * Install an irq handler for each of the SIH modules;
45161 * clone dummy irq_chip since PIH can't *do* anything
45162 */
45163 - twl4030_irq_chip = dummy_irq_chip;
45164 - twl4030_irq_chip.name = "twl4030";
45165 + pax_open_kernel();
45166 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45167 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45168
45169 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45170 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45171 + pax_close_kernel();
45172
45173 for (i = irq_base; i < irq_end; i++) {
45174 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45175 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45176 index 464419b..64bae8d 100644
45177 --- a/drivers/misc/c2port/core.c
45178 +++ b/drivers/misc/c2port/core.c
45179 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45180 goto error_idr_alloc;
45181 c2dev->id = ret;
45182
45183 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45184 + pax_open_kernel();
45185 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45186 + pax_close_kernel();
45187
45188 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45189 "c2port%d", c2dev->id);
45190 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45191 index 9c34e57..b981cda 100644
45192 --- a/drivers/misc/eeprom/sunxi_sid.c
45193 +++ b/drivers/misc/eeprom/sunxi_sid.c
45194 @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45195
45196 platform_set_drvdata(pdev, sid_data);
45197
45198 - sid_bin_attr.size = sid_data->keysize;
45199 + pax_open_kernel();
45200 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45201 + pax_close_kernel();
45202 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45203 return -ENODEV;
45204
45205 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45206 index 36f5d52..32311c3 100644
45207 --- a/drivers/misc/kgdbts.c
45208 +++ b/drivers/misc/kgdbts.c
45209 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45210 char before[BREAK_INSTR_SIZE];
45211 char after[BREAK_INSTR_SIZE];
45212
45213 - probe_kernel_read(before, (char *)kgdbts_break_test,
45214 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45215 BREAK_INSTR_SIZE);
45216 init_simple_test();
45217 ts.tst = plant_and_detach_test;
45218 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45219 /* Activate test with initial breakpoint */
45220 if (!is_early)
45221 kgdb_breakpoint();
45222 - probe_kernel_read(after, (char *)kgdbts_break_test,
45223 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45224 BREAK_INSTR_SIZE);
45225 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45226 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45227 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45228 index 036effe..b3a6336 100644
45229 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45230 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45231 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45232 * the lid is closed. This leads to interrupts as soon as a little move
45233 * is done.
45234 */
45235 - atomic_inc(&lis3->count);
45236 + atomic_inc_unchecked(&lis3->count);
45237
45238 wake_up_interruptible(&lis3->misc_wait);
45239 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45240 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45241 if (lis3->pm_dev)
45242 pm_runtime_get_sync(lis3->pm_dev);
45243
45244 - atomic_set(&lis3->count, 0);
45245 + atomic_set_unchecked(&lis3->count, 0);
45246 return 0;
45247 }
45248
45249 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45250 add_wait_queue(&lis3->misc_wait, &wait);
45251 while (true) {
45252 set_current_state(TASK_INTERRUPTIBLE);
45253 - data = atomic_xchg(&lis3->count, 0);
45254 + data = atomic_xchg_unchecked(&lis3->count, 0);
45255 if (data)
45256 break;
45257
45258 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45259 struct lis3lv02d, miscdev);
45260
45261 poll_wait(file, &lis3->misc_wait, wait);
45262 - if (atomic_read(&lis3->count))
45263 + if (atomic_read_unchecked(&lis3->count))
45264 return POLLIN | POLLRDNORM;
45265 return 0;
45266 }
45267 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45268 index c439c82..1f20f57 100644
45269 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45270 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45271 @@ -297,7 +297,7 @@ struct lis3lv02d {
45272 struct input_polled_dev *idev; /* input device */
45273 struct platform_device *pdev; /* platform device */
45274 struct regulator_bulk_data regulators[2];
45275 - atomic_t count; /* interrupt count after last read */
45276 + atomic_unchecked_t count; /* interrupt count after last read */
45277 union axis_conversion ac; /* hw -> logical axis */
45278 int mapped_btns[3];
45279
45280 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45281 index 2f30bad..c4c13d0 100644
45282 --- a/drivers/misc/sgi-gru/gruhandles.c
45283 +++ b/drivers/misc/sgi-gru/gruhandles.c
45284 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45285 unsigned long nsec;
45286
45287 nsec = CLKS2NSEC(clks);
45288 - atomic_long_inc(&mcs_op_statistics[op].count);
45289 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45290 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45291 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45292 if (mcs_op_statistics[op].max < nsec)
45293 mcs_op_statistics[op].max = nsec;
45294 }
45295 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45296 index 4f76359..cdfcb2e 100644
45297 --- a/drivers/misc/sgi-gru/gruprocfs.c
45298 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45299 @@ -32,9 +32,9 @@
45300
45301 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45302
45303 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45304 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45305 {
45306 - unsigned long val = atomic_long_read(v);
45307 + unsigned long val = atomic_long_read_unchecked(v);
45308
45309 seq_printf(s, "%16lu %s\n", val, id);
45310 }
45311 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45312
45313 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45314 for (op = 0; op < mcsop_last; op++) {
45315 - count = atomic_long_read(&mcs_op_statistics[op].count);
45316 - total = atomic_long_read(&mcs_op_statistics[op].total);
45317 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45318 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45319 max = mcs_op_statistics[op].max;
45320 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45321 count ? total / count : 0, max);
45322 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45323 index 5c3ce24..4915ccb 100644
45324 --- a/drivers/misc/sgi-gru/grutables.h
45325 +++ b/drivers/misc/sgi-gru/grutables.h
45326 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45327 * GRU statistics.
45328 */
45329 struct gru_stats_s {
45330 - atomic_long_t vdata_alloc;
45331 - atomic_long_t vdata_free;
45332 - atomic_long_t gts_alloc;
45333 - atomic_long_t gts_free;
45334 - atomic_long_t gms_alloc;
45335 - atomic_long_t gms_free;
45336 - atomic_long_t gts_double_allocate;
45337 - atomic_long_t assign_context;
45338 - atomic_long_t assign_context_failed;
45339 - atomic_long_t free_context;
45340 - atomic_long_t load_user_context;
45341 - atomic_long_t load_kernel_context;
45342 - atomic_long_t lock_kernel_context;
45343 - atomic_long_t unlock_kernel_context;
45344 - atomic_long_t steal_user_context;
45345 - atomic_long_t steal_kernel_context;
45346 - atomic_long_t steal_context_failed;
45347 - atomic_long_t nopfn;
45348 - atomic_long_t asid_new;
45349 - atomic_long_t asid_next;
45350 - atomic_long_t asid_wrap;
45351 - atomic_long_t asid_reuse;
45352 - atomic_long_t intr;
45353 - atomic_long_t intr_cbr;
45354 - atomic_long_t intr_tfh;
45355 - atomic_long_t intr_spurious;
45356 - atomic_long_t intr_mm_lock_failed;
45357 - atomic_long_t call_os;
45358 - atomic_long_t call_os_wait_queue;
45359 - atomic_long_t user_flush_tlb;
45360 - atomic_long_t user_unload_context;
45361 - atomic_long_t user_exception;
45362 - atomic_long_t set_context_option;
45363 - atomic_long_t check_context_retarget_intr;
45364 - atomic_long_t check_context_unload;
45365 - atomic_long_t tlb_dropin;
45366 - atomic_long_t tlb_preload_page;
45367 - atomic_long_t tlb_dropin_fail_no_asid;
45368 - atomic_long_t tlb_dropin_fail_upm;
45369 - atomic_long_t tlb_dropin_fail_invalid;
45370 - atomic_long_t tlb_dropin_fail_range_active;
45371 - atomic_long_t tlb_dropin_fail_idle;
45372 - atomic_long_t tlb_dropin_fail_fmm;
45373 - atomic_long_t tlb_dropin_fail_no_exception;
45374 - atomic_long_t tfh_stale_on_fault;
45375 - atomic_long_t mmu_invalidate_range;
45376 - atomic_long_t mmu_invalidate_page;
45377 - atomic_long_t flush_tlb;
45378 - atomic_long_t flush_tlb_gru;
45379 - atomic_long_t flush_tlb_gru_tgh;
45380 - atomic_long_t flush_tlb_gru_zero_asid;
45381 + atomic_long_unchecked_t vdata_alloc;
45382 + atomic_long_unchecked_t vdata_free;
45383 + atomic_long_unchecked_t gts_alloc;
45384 + atomic_long_unchecked_t gts_free;
45385 + atomic_long_unchecked_t gms_alloc;
45386 + atomic_long_unchecked_t gms_free;
45387 + atomic_long_unchecked_t gts_double_allocate;
45388 + atomic_long_unchecked_t assign_context;
45389 + atomic_long_unchecked_t assign_context_failed;
45390 + atomic_long_unchecked_t free_context;
45391 + atomic_long_unchecked_t load_user_context;
45392 + atomic_long_unchecked_t load_kernel_context;
45393 + atomic_long_unchecked_t lock_kernel_context;
45394 + atomic_long_unchecked_t unlock_kernel_context;
45395 + atomic_long_unchecked_t steal_user_context;
45396 + atomic_long_unchecked_t steal_kernel_context;
45397 + atomic_long_unchecked_t steal_context_failed;
45398 + atomic_long_unchecked_t nopfn;
45399 + atomic_long_unchecked_t asid_new;
45400 + atomic_long_unchecked_t asid_next;
45401 + atomic_long_unchecked_t asid_wrap;
45402 + atomic_long_unchecked_t asid_reuse;
45403 + atomic_long_unchecked_t intr;
45404 + atomic_long_unchecked_t intr_cbr;
45405 + atomic_long_unchecked_t intr_tfh;
45406 + atomic_long_unchecked_t intr_spurious;
45407 + atomic_long_unchecked_t intr_mm_lock_failed;
45408 + atomic_long_unchecked_t call_os;
45409 + atomic_long_unchecked_t call_os_wait_queue;
45410 + atomic_long_unchecked_t user_flush_tlb;
45411 + atomic_long_unchecked_t user_unload_context;
45412 + atomic_long_unchecked_t user_exception;
45413 + atomic_long_unchecked_t set_context_option;
45414 + atomic_long_unchecked_t check_context_retarget_intr;
45415 + atomic_long_unchecked_t check_context_unload;
45416 + atomic_long_unchecked_t tlb_dropin;
45417 + atomic_long_unchecked_t tlb_preload_page;
45418 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45419 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45420 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45421 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45422 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45423 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45424 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45425 + atomic_long_unchecked_t tfh_stale_on_fault;
45426 + atomic_long_unchecked_t mmu_invalidate_range;
45427 + atomic_long_unchecked_t mmu_invalidate_page;
45428 + atomic_long_unchecked_t flush_tlb;
45429 + atomic_long_unchecked_t flush_tlb_gru;
45430 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45431 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45432
45433 - atomic_long_t copy_gpa;
45434 - atomic_long_t read_gpa;
45435 + atomic_long_unchecked_t copy_gpa;
45436 + atomic_long_unchecked_t read_gpa;
45437
45438 - atomic_long_t mesq_receive;
45439 - atomic_long_t mesq_receive_none;
45440 - atomic_long_t mesq_send;
45441 - atomic_long_t mesq_send_failed;
45442 - atomic_long_t mesq_noop;
45443 - atomic_long_t mesq_send_unexpected_error;
45444 - atomic_long_t mesq_send_lb_overflow;
45445 - atomic_long_t mesq_send_qlimit_reached;
45446 - atomic_long_t mesq_send_amo_nacked;
45447 - atomic_long_t mesq_send_put_nacked;
45448 - atomic_long_t mesq_page_overflow;
45449 - atomic_long_t mesq_qf_locked;
45450 - atomic_long_t mesq_qf_noop_not_full;
45451 - atomic_long_t mesq_qf_switch_head_failed;
45452 - atomic_long_t mesq_qf_unexpected_error;
45453 - atomic_long_t mesq_noop_unexpected_error;
45454 - atomic_long_t mesq_noop_lb_overflow;
45455 - atomic_long_t mesq_noop_qlimit_reached;
45456 - atomic_long_t mesq_noop_amo_nacked;
45457 - atomic_long_t mesq_noop_put_nacked;
45458 - atomic_long_t mesq_noop_page_overflow;
45459 + atomic_long_unchecked_t mesq_receive;
45460 + atomic_long_unchecked_t mesq_receive_none;
45461 + atomic_long_unchecked_t mesq_send;
45462 + atomic_long_unchecked_t mesq_send_failed;
45463 + atomic_long_unchecked_t mesq_noop;
45464 + atomic_long_unchecked_t mesq_send_unexpected_error;
45465 + atomic_long_unchecked_t mesq_send_lb_overflow;
45466 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45467 + atomic_long_unchecked_t mesq_send_amo_nacked;
45468 + atomic_long_unchecked_t mesq_send_put_nacked;
45469 + atomic_long_unchecked_t mesq_page_overflow;
45470 + atomic_long_unchecked_t mesq_qf_locked;
45471 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45472 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45473 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45474 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45475 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45476 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45477 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45478 + atomic_long_unchecked_t mesq_noop_put_nacked;
45479 + atomic_long_unchecked_t mesq_noop_page_overflow;
45480
45481 };
45482
45483 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45484 tghop_invalidate, mcsop_last};
45485
45486 struct mcs_op_statistic {
45487 - atomic_long_t count;
45488 - atomic_long_t total;
45489 + atomic_long_unchecked_t count;
45490 + atomic_long_unchecked_t total;
45491 unsigned long max;
45492 };
45493
45494 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45495
45496 #define STAT(id) do { \
45497 if (gru_options & OPT_STATS) \
45498 - atomic_long_inc(&gru_stats.id); \
45499 + atomic_long_inc_unchecked(&gru_stats.id); \
45500 } while (0)
45501
45502 #ifdef CONFIG_SGI_GRU_DEBUG
45503 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45504 index c862cd4..0d176fe 100644
45505 --- a/drivers/misc/sgi-xp/xp.h
45506 +++ b/drivers/misc/sgi-xp/xp.h
45507 @@ -288,7 +288,7 @@ struct xpc_interface {
45508 xpc_notify_func, void *);
45509 void (*received) (short, int, void *);
45510 enum xp_retval (*partid_to_nasids) (short, void *);
45511 -};
45512 +} __no_const;
45513
45514 extern struct xpc_interface xpc_interface;
45515
45516 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45517 index 01be66d..e3a0c7e 100644
45518 --- a/drivers/misc/sgi-xp/xp_main.c
45519 +++ b/drivers/misc/sgi-xp/xp_main.c
45520 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45521 }
45522
45523 struct xpc_interface xpc_interface = {
45524 - (void (*)(int))xpc_notloaded,
45525 - (void (*)(int))xpc_notloaded,
45526 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45527 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45528 + .connect = (void (*)(int))xpc_notloaded,
45529 + .disconnect = (void (*)(int))xpc_notloaded,
45530 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45531 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45532 void *))xpc_notloaded,
45533 - (void (*)(short, int, void *))xpc_notloaded,
45534 - (enum xp_retval(*)(short, void *))xpc_notloaded
45535 + .received = (void (*)(short, int, void *))xpc_notloaded,
45536 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45537 };
45538 EXPORT_SYMBOL_GPL(xpc_interface);
45539
45540 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45541 index b94d5f7..7f494c5 100644
45542 --- a/drivers/misc/sgi-xp/xpc.h
45543 +++ b/drivers/misc/sgi-xp/xpc.h
45544 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45545 void (*received_payload) (struct xpc_channel *, void *);
45546 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45547 };
45548 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45549
45550 /* struct xpc_partition act_state values (for XPC HB) */
45551
45552 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45553 /* found in xpc_main.c */
45554 extern struct device *xpc_part;
45555 extern struct device *xpc_chan;
45556 -extern struct xpc_arch_operations xpc_arch_ops;
45557 +extern xpc_arch_operations_no_const xpc_arch_ops;
45558 extern int xpc_disengage_timelimit;
45559 extern int xpc_disengage_timedout;
45560 extern int xpc_activate_IRQ_rcvd;
45561 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45562 index 82dc574..8539ab2 100644
45563 --- a/drivers/misc/sgi-xp/xpc_main.c
45564 +++ b/drivers/misc/sgi-xp/xpc_main.c
45565 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45566 .notifier_call = xpc_system_die,
45567 };
45568
45569 -struct xpc_arch_operations xpc_arch_ops;
45570 +xpc_arch_operations_no_const xpc_arch_ops;
45571
45572 /*
45573 * Timer function to enforce the timelimit on the partition disengage.
45574 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45575
45576 if (((die_args->trapnr == X86_TRAP_MF) ||
45577 (die_args->trapnr == X86_TRAP_XF)) &&
45578 - !user_mode_vm(die_args->regs))
45579 + !user_mode(die_args->regs))
45580 xpc_die_deactivate();
45581
45582 break;
45583 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45584 index 7b5424f..ed1d6ac 100644
45585 --- a/drivers/mmc/card/block.c
45586 +++ b/drivers/mmc/card/block.c
45587 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45588 if (idata->ic.postsleep_min_us)
45589 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45590
45591 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45592 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45593 err = -EFAULT;
45594 goto cmd_rel_host;
45595 }
45596 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45597 index e5b5eeb..7bf2212 100644
45598 --- a/drivers/mmc/core/mmc_ops.c
45599 +++ b/drivers/mmc/core/mmc_ops.c
45600 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45601 void *data_buf;
45602 int is_on_stack;
45603
45604 - is_on_stack = object_is_on_stack(buf);
45605 + is_on_stack = object_starts_on_stack(buf);
45606 if (is_on_stack) {
45607 /*
45608 * dma onto stack is unsafe/nonportable, but callers to this
45609 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45610 index 6bf24ab..13d0293b 100644
45611 --- a/drivers/mmc/host/dw_mmc.h
45612 +++ b/drivers/mmc/host/dw_mmc.h
45613 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45614 int (*parse_dt)(struct dw_mci *host);
45615 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45616 struct dw_mci_tuning_data *tuning_data);
45617 -};
45618 +} __do_const;
45619 #endif /* _DW_MMC_H_ */
45620 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45621 index f320579..7b7ebac 100644
45622 --- a/drivers/mmc/host/mmci.c
45623 +++ b/drivers/mmc/host/mmci.c
45624 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45625 }
45626
45627 if (variant->busy_detect) {
45628 - mmci_ops.card_busy = mmci_card_busy;
45629 + pax_open_kernel();
45630 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45631 + pax_close_kernel();
45632 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45633 }
45634
45635 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45636 index 1dcaf8a..025af25 100644
45637 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45638 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45639 @@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45640 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
45641 }
45642
45643 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45644 - sdhci_esdhc_ops.platform_execute_tuning =
45645 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45646 + pax_open_kernel();
45647 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45648 esdhc_executing_tuning;
45649 + pax_close_kernel();
45650 + }
45651 boarddata = &imx_data->boarddata;
45652 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
45653 if (!host->mmc->parent->platform_data) {
45654 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45655 index 6debda9..2ba7427 100644
45656 --- a/drivers/mmc/host/sdhci-s3c.c
45657 +++ b/drivers/mmc/host/sdhci-s3c.c
45658 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45659 * we can use overriding functions instead of default.
45660 */
45661 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45662 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45663 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45664 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45665 + pax_open_kernel();
45666 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45667 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45668 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45669 + pax_close_kernel();
45670 }
45671
45672 /* It supports additional host capabilities if needed */
45673 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45674 index 096993f..f02c23b 100644
45675 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45676 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45677 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45678 size_t totlen = 0, thislen;
45679 int ret = 0;
45680 size_t buflen = 0;
45681 - static char *buffer;
45682 + char *buffer;
45683
45684 if (!ECCBUF_SIZE) {
45685 /* We should fall back to a general writev implementation.
45686 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45687 index 370b9dd..1a1176b 100644
45688 --- a/drivers/mtd/nand/denali.c
45689 +++ b/drivers/mtd/nand/denali.c
45690 @@ -24,6 +24,7 @@
45691 #include <linux/slab.h>
45692 #include <linux/mtd/mtd.h>
45693 #include <linux/module.h>
45694 +#include <linux/slab.h>
45695
45696 #include "denali.h"
45697
45698 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45699 index 51b9d6a..52af9a7 100644
45700 --- a/drivers/mtd/nftlmount.c
45701 +++ b/drivers/mtd/nftlmount.c
45702 @@ -24,6 +24,7 @@
45703 #include <asm/errno.h>
45704 #include <linux/delay.h>
45705 #include <linux/slab.h>
45706 +#include <linux/sched.h>
45707 #include <linux/mtd/mtd.h>
45708 #include <linux/mtd/nand.h>
45709 #include <linux/mtd/nftl.h>
45710 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45711 index 4b8e895..6b3c498 100644
45712 --- a/drivers/mtd/sm_ftl.c
45713 +++ b/drivers/mtd/sm_ftl.c
45714 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45715 #define SM_CIS_VENDOR_OFFSET 0x59
45716 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45717 {
45718 - struct attribute_group *attr_group;
45719 + attribute_group_no_const *attr_group;
45720 struct attribute **attributes;
45721 struct sm_sysfs_attribute *vendor_attribute;
45722
45723 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45724 index 4b8c58b..a200546 100644
45725 --- a/drivers/net/bonding/bond_main.c
45726 +++ b/drivers/net/bonding/bond_main.c
45727 @@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
45728
45729 bond_netlink_fini();
45730 unregister_pernet_subsys(&bond_net_ops);
45731 + rtnl_link_unregister(&bond_link_ops);
45732
45733 #ifdef CONFIG_NET_POLL_CONTROLLER
45734 /*
45735 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45736 index 40e7b1c..6a70fff 100644
45737 --- a/drivers/net/bonding/bond_netlink.c
45738 +++ b/drivers/net/bonding/bond_netlink.c
45739 @@ -102,7 +102,7 @@ nla_put_failure:
45740 return -EMSGSIZE;
45741 }
45742
45743 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45744 +struct rtnl_link_ops bond_link_ops = {
45745 .kind = "bond",
45746 .priv_size = sizeof(struct bonding),
45747 .setup = bond_setup,
45748 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45749 index 3c06947..fd0e5de 100644
45750 --- a/drivers/net/can/Kconfig
45751 +++ b/drivers/net/can/Kconfig
45752 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45753
45754 config CAN_FLEXCAN
45755 tristate "Support for Freescale FLEXCAN based chips"
45756 - depends on ARM || PPC
45757 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45758 ---help---
45759 Say Y here if you want to support for Freescale FlexCAN.
45760
45761 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45762 index 36fa577..a158806 100644
45763 --- a/drivers/net/ethernet/8390/ax88796.c
45764 +++ b/drivers/net/ethernet/8390/ax88796.c
45765 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
45766 if (ax->plat->reg_offsets)
45767 ei_local->reg_offset = ax->plat->reg_offsets;
45768 else {
45769 + resource_size_t _mem_size = mem_size;
45770 + do_div(_mem_size, 0x18);
45771 ei_local->reg_offset = ax->reg_offsets;
45772 for (ret = 0; ret < 0x18; ret++)
45773 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45774 + ax->reg_offsets[ret] = _mem_size * ret;
45775 }
45776
45777 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45778 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45779 index 41f3ca5a..1ee5364 100644
45780 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45781 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45782 @@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45783 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45784 {
45785 /* RX_MODE controlling object */
45786 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45787 + bnx2x_init_rx_mode_obj(bp);
45788
45789 /* multicast configuration controlling object */
45790 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45791 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45792 index 18438a5..c923b8e 100644
45793 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45794 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45795 @@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45796 return rc;
45797 }
45798
45799 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45800 - struct bnx2x_rx_mode_obj *o)
45801 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45802 {
45803 if (CHIP_IS_E1x(bp)) {
45804 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45805 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45806 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45807 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45808 } else {
45809 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45810 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45811 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45812 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45813 }
45814 }
45815
45816 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45817 index 6a53c15..6e7d1e7 100644
45818 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45819 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45820 @@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45821
45822 /********************* RX MODE ****************/
45823
45824 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45825 - struct bnx2x_rx_mode_obj *o);
45826 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45827
45828 /**
45829 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45830 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45831 index cf9917b..c658558 100644
45832 --- a/drivers/net/ethernet/broadcom/tg3.h
45833 +++ b/drivers/net/ethernet/broadcom/tg3.h
45834 @@ -150,6 +150,7 @@
45835 #define CHIPREV_ID_5750_A0 0x4000
45836 #define CHIPREV_ID_5750_A1 0x4001
45837 #define CHIPREV_ID_5750_A3 0x4003
45838 +#define CHIPREV_ID_5750_C1 0x4201
45839 #define CHIPREV_ID_5750_C2 0x4202
45840 #define CHIPREV_ID_5752_A0_HW 0x5000
45841 #define CHIPREV_ID_5752_A0 0x6000
45842 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45843 index 3ca77fa..fcc015f 100644
45844 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45845 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45846 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45847 }
45848
45849 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45850 - bna_cb_ioceth_enable,
45851 - bna_cb_ioceth_disable,
45852 - bna_cb_ioceth_hbfail,
45853 - bna_cb_ioceth_reset
45854 + .enable_cbfn = bna_cb_ioceth_enable,
45855 + .disable_cbfn = bna_cb_ioceth_disable,
45856 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45857 + .reset_cbfn = bna_cb_ioceth_reset
45858 };
45859
45860 static void bna_attr_init(struct bna_ioceth *ioceth)
45861 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45862 index 8cffcdf..aadf043 100644
45863 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45864 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45865 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45866 */
45867 struct l2t_skb_cb {
45868 arp_failure_handler_func arp_failure_handler;
45869 -};
45870 +} __no_const;
45871
45872 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45873
45874 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45875 index fff02ed..d421412 100644
45876 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45877 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45878 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45879
45880 int i;
45881 struct adapter *ap = netdev2adap(dev);
45882 - static const unsigned int *reg_ranges;
45883 + const unsigned int *reg_ranges;
45884 int arr_size = 0, buf_size = 0;
45885
45886 if (is_t4(ap->params.chip)) {
45887 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45888 index c05b66d..ed69872 100644
45889 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45890 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45891 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45892 for (i=0; i<ETH_ALEN; i++) {
45893 tmp.addr[i] = dev->dev_addr[i];
45894 }
45895 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45896 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45897 break;
45898
45899 case DE4X5_SET_HWADDR: /* Set the hardware address */
45900 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45901 spin_lock_irqsave(&lp->lock, flags);
45902 memcpy(&statbuf, &lp->pktStats, ioc->len);
45903 spin_unlock_irqrestore(&lp->lock, flags);
45904 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45905 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45906 return -EFAULT;
45907 break;
45908 }
45909 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45910 index a37039d..a51d7e8 100644
45911 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45912 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45913 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45914
45915 if (wrapped)
45916 newacc += 65536;
45917 - ACCESS_ONCE(*acc) = newacc;
45918 + ACCESS_ONCE_RW(*acc) = newacc;
45919 }
45920
45921 static void populate_erx_stats(struct be_adapter *adapter,
45922 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45923 index 212f44b..fb69959 100644
45924 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45925 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45926 @@ -31,6 +31,8 @@
45927 #include <linux/netdevice.h>
45928 #include <linux/phy.h>
45929 #include <linux/platform_device.h>
45930 +#include <linux/interrupt.h>
45931 +#include <linux/irqreturn.h>
45932 #include <net/ip.h>
45933
45934 #include "ftgmac100.h"
45935 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45936 index 8be5b40..081bc1b 100644
45937 --- a/drivers/net/ethernet/faraday/ftmac100.c
45938 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45939 @@ -31,6 +31,8 @@
45940 #include <linux/module.h>
45941 #include <linux/netdevice.h>
45942 #include <linux/platform_device.h>
45943 +#include <linux/interrupt.h>
45944 +#include <linux/irqreturn.h>
45945
45946 #include "ftmac100.h"
45947
45948 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45949 index 5184e2a..acb28c3 100644
45950 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45951 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45952 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45953 }
45954
45955 /* update the base incval used to calculate frequency adjustment */
45956 - ACCESS_ONCE(adapter->base_incval) = incval;
45957 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45958 smp_mb();
45959
45960 /* need lock to prevent incorrect read while modifying cyclecounter */
45961 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45962 index fbe5363..266b4e3 100644
45963 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45964 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45965 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45966 struct __vxge_hw_fifo *fifo;
45967 struct vxge_hw_fifo_config *config;
45968 u32 txdl_size, txdl_per_memblock;
45969 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45970 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45971 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45972 + };
45973 +
45974 struct __vxge_hw_virtualpath *vpath;
45975
45976 if ((vp == NULL) || (attr == NULL)) {
45977 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45978 goto exit;
45979 }
45980
45981 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45982 -
45983 fifo->mempool =
45984 __vxge_hw_mempool_create(vpath->hldev,
45985 fifo->config->memblock_size,
45986 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45987 index 918e18d..4ca3650 100644
45988 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45989 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45990 @@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45991 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45992 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45993 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45994 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45995 + pax_open_kernel();
45996 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45997 + pax_close_kernel();
45998 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45999 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46000 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
46001 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46002 index 734d286..b017bf5 100644
46003 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46004 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46005 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46006 case QLCNIC_NON_PRIV_FUNC:
46007 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46008 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46009 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46010 + pax_open_kernel();
46011 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46012 + pax_close_kernel();
46013 break;
46014 case QLCNIC_PRIV_FUNC:
46015 ahw->op_mode = QLCNIC_PRIV_FUNC;
46016 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46017 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46018 + pax_open_kernel();
46019 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46020 + pax_close_kernel();
46021 break;
46022 case QLCNIC_MGMT_FUNC:
46023 ahw->op_mode = QLCNIC_MGMT_FUNC;
46024 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46025 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46026 + pax_open_kernel();
46027 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46028 + pax_close_kernel();
46029 break;
46030 default:
46031 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46032 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46033 index 7763962..c3499a7 100644
46034 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46035 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46036 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46037 struct qlcnic_dump_entry *entry;
46038 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46039 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
46040 - static const struct qlcnic_dump_operations *fw_dump_ops;
46041 + const struct qlcnic_dump_operations *fw_dump_ops;
46042 struct device *dev = &adapter->pdev->dev;
46043 struct qlcnic_hardware_context *ahw;
46044 void *temp_buffer;
46045 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46046 index c737f0e..32b8682 100644
46047 --- a/drivers/net/ethernet/realtek/r8169.c
46048 +++ b/drivers/net/ethernet/realtek/r8169.c
46049 @@ -759,22 +759,22 @@ struct rtl8169_private {
46050 struct mdio_ops {
46051 void (*write)(struct rtl8169_private *, int, int);
46052 int (*read)(struct rtl8169_private *, int);
46053 - } mdio_ops;
46054 + } __no_const mdio_ops;
46055
46056 struct pll_power_ops {
46057 void (*down)(struct rtl8169_private *);
46058 void (*up)(struct rtl8169_private *);
46059 - } pll_power_ops;
46060 + } __no_const pll_power_ops;
46061
46062 struct jumbo_ops {
46063 void (*enable)(struct rtl8169_private *);
46064 void (*disable)(struct rtl8169_private *);
46065 - } jumbo_ops;
46066 + } __no_const jumbo_ops;
46067
46068 struct csi_ops {
46069 void (*write)(struct rtl8169_private *, int, int);
46070 u32 (*read)(struct rtl8169_private *, int);
46071 - } csi_ops;
46072 + } __no_const csi_ops;
46073
46074 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46075 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46076 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46077 index a124103..59c74f8 100644
46078 --- a/drivers/net/ethernet/sfc/ptp.c
46079 +++ b/drivers/net/ethernet/sfc/ptp.c
46080 @@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46081 ptp->start.dma_addr);
46082
46083 /* Clear flag that signals MC ready */
46084 - ACCESS_ONCE(*start) = 0;
46085 + ACCESS_ONCE_RW(*start) = 0;
46086 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46087 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46088 EFX_BUG_ON_PARANOID(rc);
46089 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46090 index 50617c5..b13724c 100644
46091 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46092 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46093 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46094
46095 writel(value, ioaddr + MMC_CNTRL);
46096
46097 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46098 - MMC_CNTRL, value);
46099 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46100 +// MMC_CNTRL, value);
46101 }
46102
46103 /* To mask all all interrupts.*/
46104 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46105 index e6fe0d8..2b7d752 100644
46106 --- a/drivers/net/hyperv/hyperv_net.h
46107 +++ b/drivers/net/hyperv/hyperv_net.h
46108 @@ -101,7 +101,7 @@ struct rndis_device {
46109
46110 enum rndis_device_state state;
46111 bool link_state;
46112 - atomic_t new_req_id;
46113 + atomic_unchecked_t new_req_id;
46114
46115 spinlock_t request_lock;
46116 struct list_head req_list;
46117 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46118 index 0775f0a..d4fb316 100644
46119 --- a/drivers/net/hyperv/rndis_filter.c
46120 +++ b/drivers/net/hyperv/rndis_filter.c
46121 @@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46122 * template
46123 */
46124 set = &rndis_msg->msg.set_req;
46125 - set->req_id = atomic_inc_return(&dev->new_req_id);
46126 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46127
46128 /* Add to the request list */
46129 spin_lock_irqsave(&dev->request_lock, flags);
46130 @@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46131
46132 /* Setup the rndis set */
46133 halt = &request->request_msg.msg.halt_req;
46134 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46135 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46136
46137 /* Ignore return since this msg is optional. */
46138 rndis_filter_send_request(dev, request);
46139 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46140 index bf0d55e..82bcfbd1 100644
46141 --- a/drivers/net/ieee802154/fakehard.c
46142 +++ b/drivers/net/ieee802154/fakehard.c
46143 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46144 phy->transmit_power = 0xbf;
46145
46146 dev->netdev_ops = &fake_ops;
46147 - dev->ml_priv = &fake_mlme;
46148 + dev->ml_priv = (void *)&fake_mlme;
46149
46150 priv = netdev_priv(dev);
46151 priv->phy = phy;
46152 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46153 index d7e2907..1f8bfee 100644
46154 --- a/drivers/net/macvlan.c
46155 +++ b/drivers/net/macvlan.c
46156 @@ -993,13 +993,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46157 int macvlan_link_register(struct rtnl_link_ops *ops)
46158 {
46159 /* common fields */
46160 - ops->priv_size = sizeof(struct macvlan_dev);
46161 - ops->validate = macvlan_validate;
46162 - ops->maxtype = IFLA_MACVLAN_MAX;
46163 - ops->policy = macvlan_policy;
46164 - ops->changelink = macvlan_changelink;
46165 - ops->get_size = macvlan_get_size;
46166 - ops->fill_info = macvlan_fill_info;
46167 + pax_open_kernel();
46168 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46169 + *(void **)&ops->validate = macvlan_validate;
46170 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46171 + *(const void **)&ops->policy = macvlan_policy;
46172 + *(void **)&ops->changelink = macvlan_changelink;
46173 + *(void **)&ops->get_size = macvlan_get_size;
46174 + *(void **)&ops->fill_info = macvlan_fill_info;
46175 + pax_close_kernel();
46176
46177 return rtnl_link_register(ops);
46178 };
46179 @@ -1054,7 +1056,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46180 return NOTIFY_DONE;
46181 }
46182
46183 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46184 +static struct notifier_block macvlan_notifier_block = {
46185 .notifier_call = macvlan_device_event,
46186 };
46187
46188 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46189 index 2a89da0..c17fe1d 100644
46190 --- a/drivers/net/macvtap.c
46191 +++ b/drivers/net/macvtap.c
46192 @@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46193 }
46194
46195 ret = 0;
46196 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46197 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46198 put_user(q->flags, &ifr->ifr_flags))
46199 ret = -EFAULT;
46200 macvtap_put_vlan(vlan);
46201 @@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46202 return NOTIFY_DONE;
46203 }
46204
46205 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46206 +static struct notifier_block macvtap_notifier_block = {
46207 .notifier_call = macvtap_device_event,
46208 };
46209
46210 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46211 index daec9b0..6428fcb 100644
46212 --- a/drivers/net/phy/mdio-bitbang.c
46213 +++ b/drivers/net/phy/mdio-bitbang.c
46214 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46215 struct mdiobb_ctrl *ctrl = bus->priv;
46216
46217 module_put(ctrl->ops->owner);
46218 + mdiobus_unregister(bus);
46219 mdiobus_free(bus);
46220 }
46221 EXPORT_SYMBOL(free_mdio_bitbang);
46222 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46223 index 72ff14b..11d442d 100644
46224 --- a/drivers/net/ppp/ppp_generic.c
46225 +++ b/drivers/net/ppp/ppp_generic.c
46226 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46227 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46228 struct ppp_stats stats;
46229 struct ppp_comp_stats cstats;
46230 - char *vers;
46231
46232 switch (cmd) {
46233 case SIOCGPPPSTATS:
46234 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46235 break;
46236
46237 case SIOCGPPPVER:
46238 - vers = PPP_VERSION;
46239 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46240 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46241 break;
46242 err = 0;
46243 break;
46244 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46245 index 1252d9c..80e660b 100644
46246 --- a/drivers/net/slip/slhc.c
46247 +++ b/drivers/net/slip/slhc.c
46248 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46249 register struct tcphdr *thp;
46250 register struct iphdr *ip;
46251 register struct cstate *cs;
46252 - int len, hdrlen;
46253 + long len, hdrlen;
46254 unsigned char *cp = icp;
46255
46256 /* We've got a compressed packet; read the change byte */
46257 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46258 index b75ae5b..953c157 100644
46259 --- a/drivers/net/team/team.c
46260 +++ b/drivers/net/team/team.c
46261 @@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
46262 return NOTIFY_DONE;
46263 }
46264
46265 -static struct notifier_block team_notifier_block __read_mostly = {
46266 +static struct notifier_block team_notifier_block = {
46267 .notifier_call = team_device_event,
46268 };
46269
46270 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46271 index 55c9238..ebb6ee5 100644
46272 --- a/drivers/net/tun.c
46273 +++ b/drivers/net/tun.c
46274 @@ -1841,7 +1841,7 @@ unlock:
46275 }
46276
46277 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46278 - unsigned long arg, int ifreq_len)
46279 + unsigned long arg, size_t ifreq_len)
46280 {
46281 struct tun_file *tfile = file->private_data;
46282 struct tun_struct *tun;
46283 @@ -1854,6 +1854,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46284 unsigned int ifindex;
46285 int ret;
46286
46287 + if (ifreq_len > sizeof ifr)
46288 + return -EFAULT;
46289 +
46290 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46291 if (copy_from_user(&ifr, argp, ifreq_len))
46292 return -EFAULT;
46293 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46294 index 1a48234..a555339 100644
46295 --- a/drivers/net/usb/hso.c
46296 +++ b/drivers/net/usb/hso.c
46297 @@ -71,7 +71,7 @@
46298 #include <asm/byteorder.h>
46299 #include <linux/serial_core.h>
46300 #include <linux/serial.h>
46301 -
46302 +#include <asm/local.h>
46303
46304 #define MOD_AUTHOR "Option Wireless"
46305 #define MOD_DESCRIPTION "USB High Speed Option driver"
46306 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46307 struct urb *urb;
46308
46309 urb = serial->rx_urb[0];
46310 - if (serial->port.count > 0) {
46311 + if (atomic_read(&serial->port.count) > 0) {
46312 count = put_rxbuf_data(urb, serial);
46313 if (count == -1)
46314 return;
46315 @@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46316 DUMP1(urb->transfer_buffer, urb->actual_length);
46317
46318 /* Anyone listening? */
46319 - if (serial->port.count == 0)
46320 + if (atomic_read(&serial->port.count) == 0)
46321 return;
46322
46323 if (status == 0) {
46324 @@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46325 tty_port_tty_set(&serial->port, tty);
46326
46327 /* check for port already opened, if not set the termios */
46328 - serial->port.count++;
46329 - if (serial->port.count == 1) {
46330 + if (atomic_inc_return(&serial->port.count) == 1) {
46331 serial->rx_state = RX_IDLE;
46332 /* Force default termio settings */
46333 _hso_serial_set_termios(tty, NULL);
46334 @@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46335 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46336 if (result) {
46337 hso_stop_serial_device(serial->parent);
46338 - serial->port.count--;
46339 + atomic_dec(&serial->port.count);
46340 kref_put(&serial->parent->ref, hso_serial_ref_free);
46341 }
46342 } else {
46343 @@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46344
46345 /* reset the rts and dtr */
46346 /* do the actual close */
46347 - serial->port.count--;
46348 + atomic_dec(&serial->port.count);
46349
46350 - if (serial->port.count <= 0) {
46351 - serial->port.count = 0;
46352 + if (atomic_read(&serial->port.count) <= 0) {
46353 + atomic_set(&serial->port.count, 0);
46354 tty_port_tty_set(&serial->port, NULL);
46355 if (!usb_gone)
46356 hso_stop_serial_device(serial->parent);
46357 @@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46358
46359 /* the actual setup */
46360 spin_lock_irqsave(&serial->serial_lock, flags);
46361 - if (serial->port.count)
46362 + if (atomic_read(&serial->port.count))
46363 _hso_serial_set_termios(tty, old);
46364 else
46365 tty->termios = *old;
46366 @@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
46367 D1("Pending read interrupt on port %d\n", i);
46368 spin_lock(&serial->serial_lock);
46369 if (serial->rx_state == RX_IDLE &&
46370 - serial->port.count > 0) {
46371 + atomic_read(&serial->port.count) > 0) {
46372 /* Setup and send a ctrl req read on
46373 * port i */
46374 if (!serial->rx_urb_filled[0]) {
46375 @@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
46376 /* Start all serial ports */
46377 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46378 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46379 - if (dev2ser(serial_table[i])->port.count) {
46380 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46381 result =
46382 hso_start_serial_device(serial_table[i], GFP_NOIO);
46383 hso_kick_transmit(dev2ser(serial_table[i]));
46384 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46385 index a79e9d3..78cd4fa 100644
46386 --- a/drivers/net/usb/sierra_net.c
46387 +++ b/drivers/net/usb/sierra_net.c
46388 @@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
46389 /* atomic counter partially included in MAC address to make sure 2 devices
46390 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46391 */
46392 -static atomic_t iface_counter = ATOMIC_INIT(0);
46393 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46394
46395 /*
46396 * SYNC Timer Delay definition used to set the expiry time
46397 @@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46398 dev->net->netdev_ops = &sierra_net_device_ops;
46399
46400 /* change MAC addr to include, ifacenum, and to be unique */
46401 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46402 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46403 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46404
46405 /* we will have to manufacture ethernet headers, prepare template */
46406 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46407 index 0247973..088193a 100644
46408 --- a/drivers/net/vxlan.c
46409 +++ b/drivers/net/vxlan.c
46410 @@ -2615,7 +2615,7 @@ nla_put_failure:
46411 return -EMSGSIZE;
46412 }
46413
46414 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46415 +static struct rtnl_link_ops vxlan_link_ops = {
46416 .kind = "vxlan",
46417 .maxtype = IFLA_VXLAN_MAX,
46418 .policy = vxlan_policy,
46419 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46420 index 5920c99..ff2e4a5 100644
46421 --- a/drivers/net/wan/lmc/lmc_media.c
46422 +++ b/drivers/net/wan/lmc/lmc_media.c
46423 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46424 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46425
46426 lmc_media_t lmc_ds3_media = {
46427 - lmc_ds3_init, /* special media init stuff */
46428 - lmc_ds3_default, /* reset to default state */
46429 - lmc_ds3_set_status, /* reset status to state provided */
46430 - lmc_dummy_set_1, /* set clock source */
46431 - lmc_dummy_set2_1, /* set line speed */
46432 - lmc_ds3_set_100ft, /* set cable length */
46433 - lmc_ds3_set_scram, /* set scrambler */
46434 - lmc_ds3_get_link_status, /* get link status */
46435 - lmc_dummy_set_1, /* set link status */
46436 - lmc_ds3_set_crc_length, /* set CRC length */
46437 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46438 - lmc_ds3_watchdog
46439 + .init = lmc_ds3_init, /* special media init stuff */
46440 + .defaults = lmc_ds3_default, /* reset to default state */
46441 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46442 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46443 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46444 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46445 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46446 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46447 + .set_link_status = lmc_dummy_set_1, /* set link status */
46448 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46449 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46450 + .watchdog = lmc_ds3_watchdog
46451 };
46452
46453 lmc_media_t lmc_hssi_media = {
46454 - lmc_hssi_init, /* special media init stuff */
46455 - lmc_hssi_default, /* reset to default state */
46456 - lmc_hssi_set_status, /* reset status to state provided */
46457 - lmc_hssi_set_clock, /* set clock source */
46458 - lmc_dummy_set2_1, /* set line speed */
46459 - lmc_dummy_set_1, /* set cable length */
46460 - lmc_dummy_set_1, /* set scrambler */
46461 - lmc_hssi_get_link_status, /* get link status */
46462 - lmc_hssi_set_link_status, /* set link status */
46463 - lmc_hssi_set_crc_length, /* set CRC length */
46464 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46465 - lmc_hssi_watchdog
46466 + .init = lmc_hssi_init, /* special media init stuff */
46467 + .defaults = lmc_hssi_default, /* reset to default state */
46468 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46469 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46470 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46471 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46472 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46473 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46474 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46475 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46476 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46477 + .watchdog = lmc_hssi_watchdog
46478 };
46479
46480 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46481 - lmc_ssi_default, /* reset to default state */
46482 - lmc_ssi_set_status, /* reset status to state provided */
46483 - lmc_ssi_set_clock, /* set clock source */
46484 - lmc_ssi_set_speed, /* set line speed */
46485 - lmc_dummy_set_1, /* set cable length */
46486 - lmc_dummy_set_1, /* set scrambler */
46487 - lmc_ssi_get_link_status, /* get link status */
46488 - lmc_ssi_set_link_status, /* set link status */
46489 - lmc_ssi_set_crc_length, /* set CRC length */
46490 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46491 - lmc_ssi_watchdog
46492 +lmc_media_t lmc_ssi_media = {
46493 + .init = lmc_ssi_init, /* special media init stuff */
46494 + .defaults = lmc_ssi_default, /* reset to default state */
46495 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46496 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46497 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46498 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46499 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46500 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46501 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46502 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46503 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46504 + .watchdog = lmc_ssi_watchdog
46505 };
46506
46507 lmc_media_t lmc_t1_media = {
46508 - lmc_t1_init, /* special media init stuff */
46509 - lmc_t1_default, /* reset to default state */
46510 - lmc_t1_set_status, /* reset status to state provided */
46511 - lmc_t1_set_clock, /* set clock source */
46512 - lmc_dummy_set2_1, /* set line speed */
46513 - lmc_dummy_set_1, /* set cable length */
46514 - lmc_dummy_set_1, /* set scrambler */
46515 - lmc_t1_get_link_status, /* get link status */
46516 - lmc_dummy_set_1, /* set link status */
46517 - lmc_t1_set_crc_length, /* set CRC length */
46518 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46519 - lmc_t1_watchdog
46520 + .init = lmc_t1_init, /* special media init stuff */
46521 + .defaults = lmc_t1_default, /* reset to default state */
46522 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46523 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46524 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46525 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46526 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46527 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46528 + .set_link_status = lmc_dummy_set_1, /* set link status */
46529 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46530 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46531 + .watchdog = lmc_t1_watchdog
46532 };
46533
46534 static void
46535 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46536 index feacc3b..5bac0de 100644
46537 --- a/drivers/net/wan/z85230.c
46538 +++ b/drivers/net/wan/z85230.c
46539 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46540
46541 struct z8530_irqhandler z8530_sync =
46542 {
46543 - z8530_rx,
46544 - z8530_tx,
46545 - z8530_status
46546 + .rx = z8530_rx,
46547 + .tx = z8530_tx,
46548 + .status = z8530_status
46549 };
46550
46551 EXPORT_SYMBOL(z8530_sync);
46552 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46553 }
46554
46555 static struct z8530_irqhandler z8530_dma_sync = {
46556 - z8530_dma_rx,
46557 - z8530_dma_tx,
46558 - z8530_dma_status
46559 + .rx = z8530_dma_rx,
46560 + .tx = z8530_dma_tx,
46561 + .status = z8530_dma_status
46562 };
46563
46564 static struct z8530_irqhandler z8530_txdma_sync = {
46565 - z8530_rx,
46566 - z8530_dma_tx,
46567 - z8530_dma_status
46568 + .rx = z8530_rx,
46569 + .tx = z8530_dma_tx,
46570 + .status = z8530_dma_status
46571 };
46572
46573 /**
46574 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46575
46576 struct z8530_irqhandler z8530_nop=
46577 {
46578 - z8530_rx_clear,
46579 - z8530_tx_clear,
46580 - z8530_status_clear
46581 + .rx = z8530_rx_clear,
46582 + .tx = z8530_tx_clear,
46583 + .status = z8530_status_clear
46584 };
46585
46586
46587 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46588 index 0b60295..b8bfa5b 100644
46589 --- a/drivers/net/wimax/i2400m/rx.c
46590 +++ b/drivers/net/wimax/i2400m/rx.c
46591 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46592 if (i2400m->rx_roq == NULL)
46593 goto error_roq_alloc;
46594
46595 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46596 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46597 GFP_KERNEL);
46598 if (rd == NULL) {
46599 result = -ENOMEM;
46600 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46601 index edf4b57..68b51c0 100644
46602 --- a/drivers/net/wireless/airo.c
46603 +++ b/drivers/net/wireless/airo.c
46604 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46605 struct airo_info *ai = dev->ml_priv;
46606 int ridcode;
46607 int enabled;
46608 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46609 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46610 unsigned char *iobuf;
46611
46612 /* Only super-user can write RIDs */
46613 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46614 index 34c8a33..3261fdc 100644
46615 --- a/drivers/net/wireless/at76c50x-usb.c
46616 +++ b/drivers/net/wireless/at76c50x-usb.c
46617 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46618 }
46619
46620 /* Convert timeout from the DFU status to jiffies */
46621 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
46622 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46623 {
46624 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46625 | (s->poll_timeout[1] << 8)
46626 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46627 index edae50b..b24278c 100644
46628 --- a/drivers/net/wireless/ath/ath10k/htc.c
46629 +++ b/drivers/net/wireless/ath/ath10k/htc.c
46630 @@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46631 /* registered target arrival callback from the HIF layer */
46632 int ath10k_htc_init(struct ath10k *ar)
46633 {
46634 - struct ath10k_hif_cb htc_callbacks;
46635 + static struct ath10k_hif_cb htc_callbacks = {
46636 + .rx_completion = ath10k_htc_rx_completion_handler,
46637 + .tx_completion = ath10k_htc_tx_completion_handler,
46638 + };
46639 struct ath10k_htc_ep *ep = NULL;
46640 struct ath10k_htc *htc = &ar->htc;
46641
46642 @@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
46643 ath10k_htc_reset_endpoint_states(htc);
46644
46645 /* setup HIF layer callbacks */
46646 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46647 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46648 htc->ar = ar;
46649
46650 /* Get HIF default pipe for HTC message exchange */
46651 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46652 index 4716d33..a688310 100644
46653 --- a/drivers/net/wireless/ath/ath10k/htc.h
46654 +++ b/drivers/net/wireless/ath/ath10k/htc.h
46655 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46656
46657 struct ath10k_htc_ops {
46658 void (*target_send_suspend_complete)(struct ath10k *ar);
46659 -};
46660 +} __no_const;
46661
46662 struct ath10k_htc_ep_ops {
46663 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46664 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46665 void (*ep_tx_credits)(struct ath10k *);
46666 -};
46667 +} __no_const;
46668
46669 /* service connection information */
46670 struct ath10k_htc_svc_conn_req {
46671 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46672 index a366d6b..b6f28f8 100644
46673 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46674 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46675 @@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46676 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46677 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46678
46679 - ACCESS_ONCE(ads->ds_link) = i->link;
46680 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46681 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
46682 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46683
46684 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46685 ctl6 = SM(i->keytype, AR_EncrType);
46686 @@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46687
46688 if ((i->is_first || i->is_last) &&
46689 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46690 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46691 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46692 | set11nTries(i->rates, 1)
46693 | set11nTries(i->rates, 2)
46694 | set11nTries(i->rates, 3)
46695 | (i->dur_update ? AR_DurUpdateEna : 0)
46696 | SM(0, AR_BurstDur);
46697
46698 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46699 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46700 | set11nRate(i->rates, 1)
46701 | set11nRate(i->rates, 2)
46702 | set11nRate(i->rates, 3);
46703 } else {
46704 - ACCESS_ONCE(ads->ds_ctl2) = 0;
46705 - ACCESS_ONCE(ads->ds_ctl3) = 0;
46706 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46707 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46708 }
46709
46710 if (!i->is_first) {
46711 - ACCESS_ONCE(ads->ds_ctl0) = 0;
46712 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46713 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46714 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46715 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46716 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46717 return;
46718 }
46719
46720 @@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46721 break;
46722 }
46723
46724 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46725 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46726 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46727 | SM(i->txpower, AR_XmitPower)
46728 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46729 @@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46730 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46731 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46732
46733 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46734 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46735 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46736 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46737
46738 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46739 return;
46740
46741 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46742 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46743 | set11nPktDurRTSCTS(i->rates, 1);
46744
46745 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46746 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46747 | set11nPktDurRTSCTS(i->rates, 3);
46748
46749 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46750 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46751 | set11nRateFlags(i->rates, 1)
46752 | set11nRateFlags(i->rates, 2)
46753 | set11nRateFlags(i->rates, 3)
46754 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46755 index f6c5c1b..6058354 100644
46756 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46757 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46758 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46759 (i->qcu << AR_TxQcuNum_S) | desc_len;
46760
46761 checksum += val;
46762 - ACCESS_ONCE(ads->info) = val;
46763 + ACCESS_ONCE_RW(ads->info) = val;
46764
46765 checksum += i->link;
46766 - ACCESS_ONCE(ads->link) = i->link;
46767 + ACCESS_ONCE_RW(ads->link) = i->link;
46768
46769 checksum += i->buf_addr[0];
46770 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46771 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46772 checksum += i->buf_addr[1];
46773 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46774 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46775 checksum += i->buf_addr[2];
46776 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46777 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46778 checksum += i->buf_addr[3];
46779 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46780 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46781
46782 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46783 - ACCESS_ONCE(ads->ctl3) = val;
46784 + ACCESS_ONCE_RW(ads->ctl3) = val;
46785 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46786 - ACCESS_ONCE(ads->ctl5) = val;
46787 + ACCESS_ONCE_RW(ads->ctl5) = val;
46788 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46789 - ACCESS_ONCE(ads->ctl7) = val;
46790 + ACCESS_ONCE_RW(ads->ctl7) = val;
46791 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46792 - ACCESS_ONCE(ads->ctl9) = val;
46793 + ACCESS_ONCE_RW(ads->ctl9) = val;
46794
46795 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46796 - ACCESS_ONCE(ads->ctl10) = checksum;
46797 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46798
46799 if (i->is_first || i->is_last) {
46800 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46801 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46802 | set11nTries(i->rates, 1)
46803 | set11nTries(i->rates, 2)
46804 | set11nTries(i->rates, 3)
46805 | (i->dur_update ? AR_DurUpdateEna : 0)
46806 | SM(0, AR_BurstDur);
46807
46808 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46809 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46810 | set11nRate(i->rates, 1)
46811 | set11nRate(i->rates, 2)
46812 | set11nRate(i->rates, 3);
46813 } else {
46814 - ACCESS_ONCE(ads->ctl13) = 0;
46815 - ACCESS_ONCE(ads->ctl14) = 0;
46816 + ACCESS_ONCE_RW(ads->ctl13) = 0;
46817 + ACCESS_ONCE_RW(ads->ctl14) = 0;
46818 }
46819
46820 ads->ctl20 = 0;
46821 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46822
46823 ctl17 = SM(i->keytype, AR_EncrType);
46824 if (!i->is_first) {
46825 - ACCESS_ONCE(ads->ctl11) = 0;
46826 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46827 - ACCESS_ONCE(ads->ctl15) = 0;
46828 - ACCESS_ONCE(ads->ctl16) = 0;
46829 - ACCESS_ONCE(ads->ctl17) = ctl17;
46830 - ACCESS_ONCE(ads->ctl18) = 0;
46831 - ACCESS_ONCE(ads->ctl19) = 0;
46832 + ACCESS_ONCE_RW(ads->ctl11) = 0;
46833 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46834 + ACCESS_ONCE_RW(ads->ctl15) = 0;
46835 + ACCESS_ONCE_RW(ads->ctl16) = 0;
46836 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46837 + ACCESS_ONCE_RW(ads->ctl18) = 0;
46838 + ACCESS_ONCE_RW(ads->ctl19) = 0;
46839 return;
46840 }
46841
46842 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46843 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46844 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46845 | SM(i->txpower, AR_XmitPower)
46846 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46847 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46848 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46849 ctl12 |= SM(val, AR_PAPRDChainMask);
46850
46851 - ACCESS_ONCE(ads->ctl12) = ctl12;
46852 - ACCESS_ONCE(ads->ctl17) = ctl17;
46853 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46854 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46855
46856 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46857 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46858 | set11nPktDurRTSCTS(i->rates, 1);
46859
46860 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46861 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46862 | set11nPktDurRTSCTS(i->rates, 3);
46863
46864 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46865 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46866 | set11nRateFlags(i->rates, 1)
46867 | set11nRateFlags(i->rates, 2)
46868 | set11nRateFlags(i->rates, 3)
46869 | SM(i->rtscts_rate, AR_RTSCTSRate);
46870
46871 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46872 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46873 }
46874
46875 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46876 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46877 index a2c9a5d..b52273e 100644
46878 --- a/drivers/net/wireless/ath/ath9k/hw.h
46879 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46880 @@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46881
46882 /* ANI */
46883 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46884 -};
46885 +} __no_const;
46886
46887 /**
46888 * struct ath_spec_scan - parameters for Atheros spectral scan
46889 @@ -711,7 +711,7 @@ struct ath_hw_ops {
46890 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46891 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46892 #endif
46893 -};
46894 +} __no_const;
46895
46896 struct ath_nf_limits {
46897 s16 max;
46898 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46899 index 92190da..f3a4c4c 100644
46900 --- a/drivers/net/wireless/b43/phy_lp.c
46901 +++ b/drivers/net/wireless/b43/phy_lp.c
46902 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46903 {
46904 struct ssb_bus *bus = dev->dev->sdev->bus;
46905
46906 - static const struct b206x_channel *chandata = NULL;
46907 + const struct b206x_channel *chandata = NULL;
46908 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46909 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46910 u16 old_comm15, scale;
46911 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46912 index dea3b50..543db99 100644
46913 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46914 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46915 @@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46916 */
46917 if (il3945_mod_params.disable_hw_scan) {
46918 D_INFO("Disabling hw_scan\n");
46919 - il3945_mac_ops.hw_scan = NULL;
46920 + pax_open_kernel();
46921 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46922 + pax_close_kernel();
46923 }
46924
46925 D_INFO("*** LOAD DRIVER ***\n");
46926 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46927 index d94f8ab..5b568c8 100644
46928 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46929 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46930 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46931 {
46932 struct iwl_priv *priv = file->private_data;
46933 char buf[64];
46934 - int buf_size;
46935 + size_t buf_size;
46936 u32 offset, len;
46937
46938 memset(buf, 0, sizeof(buf));
46939 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46940 struct iwl_priv *priv = file->private_data;
46941
46942 char buf[8];
46943 - int buf_size;
46944 + size_t buf_size;
46945 u32 reset_flag;
46946
46947 memset(buf, 0, sizeof(buf));
46948 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46949 {
46950 struct iwl_priv *priv = file->private_data;
46951 char buf[8];
46952 - int buf_size;
46953 + size_t buf_size;
46954 int ht40;
46955
46956 memset(buf, 0, sizeof(buf));
46957 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46958 {
46959 struct iwl_priv *priv = file->private_data;
46960 char buf[8];
46961 - int buf_size;
46962 + size_t buf_size;
46963 int value;
46964
46965 memset(buf, 0, sizeof(buf));
46966 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46967 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46968 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46969
46970 -static const char *fmt_value = " %-30s %10u\n";
46971 -static const char *fmt_hex = " %-30s 0x%02X\n";
46972 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46973 -static const char *fmt_header =
46974 +static const char fmt_value[] = " %-30s %10u\n";
46975 +static const char fmt_hex[] = " %-30s 0x%02X\n";
46976 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46977 +static const char fmt_header[] =
46978 "%-32s current cumulative delta max\n";
46979
46980 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46981 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46982 {
46983 struct iwl_priv *priv = file->private_data;
46984 char buf[8];
46985 - int buf_size;
46986 + size_t buf_size;
46987 int clear;
46988
46989 memset(buf, 0, sizeof(buf));
46990 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46991 {
46992 struct iwl_priv *priv = file->private_data;
46993 char buf[8];
46994 - int buf_size;
46995 + size_t buf_size;
46996 int trace;
46997
46998 memset(buf, 0, sizeof(buf));
46999 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47000 {
47001 struct iwl_priv *priv = file->private_data;
47002 char buf[8];
47003 - int buf_size;
47004 + size_t buf_size;
47005 int missed;
47006
47007 memset(buf, 0, sizeof(buf));
47008 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47009
47010 struct iwl_priv *priv = file->private_data;
47011 char buf[8];
47012 - int buf_size;
47013 + size_t buf_size;
47014 int plcp;
47015
47016 memset(buf, 0, sizeof(buf));
47017 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47018
47019 struct iwl_priv *priv = file->private_data;
47020 char buf[8];
47021 - int buf_size;
47022 + size_t buf_size;
47023 int flush;
47024
47025 memset(buf, 0, sizeof(buf));
47026 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47027
47028 struct iwl_priv *priv = file->private_data;
47029 char buf[8];
47030 - int buf_size;
47031 + size_t buf_size;
47032 int rts;
47033
47034 if (!priv->cfg->ht_params)
47035 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47036 {
47037 struct iwl_priv *priv = file->private_data;
47038 char buf[8];
47039 - int buf_size;
47040 + size_t buf_size;
47041
47042 memset(buf, 0, sizeof(buf));
47043 buf_size = min(count, sizeof(buf) - 1);
47044 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47045 struct iwl_priv *priv = file->private_data;
47046 u32 event_log_flag;
47047 char buf[8];
47048 - int buf_size;
47049 + size_t buf_size;
47050
47051 /* check that the interface is up */
47052 if (!iwl_is_ready(priv))
47053 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47054 struct iwl_priv *priv = file->private_data;
47055 char buf[8];
47056 u32 calib_disabled;
47057 - int buf_size;
47058 + size_t buf_size;
47059
47060 memset(buf, 0, sizeof(buf));
47061 buf_size = min(count, sizeof(buf) - 1);
47062 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47063 index 7aad766..06addb4 100644
47064 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
47065 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47066 @@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47067 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47068 {
47069 struct iwl_nvm_data *data = priv->nvm_data;
47070 - char *debug_msg;
47071 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47072
47073 if (data->sku_cap_11n_enable &&
47074 !priv->cfg->ht_params) {
47075 @@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47076 return -EINVAL;
47077 }
47078
47079 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47080 IWL_DEBUG_INFO(priv, debug_msg,
47081 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47082 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47083 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47084 index f53ef83..5e34bcb 100644
47085 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47086 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47087 @@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47088 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47089
47090 char buf[8];
47091 - int buf_size;
47092 + size_t buf_size;
47093 u32 reset_flag;
47094
47095 memset(buf, 0, sizeof(buf));
47096 @@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47097 {
47098 struct iwl_trans *trans = file->private_data;
47099 char buf[8];
47100 - int buf_size;
47101 + size_t buf_size;
47102 int csr;
47103
47104 memset(buf, 0, sizeof(buf));
47105 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47106 index a1b32ee..94b3c3d 100644
47107 --- a/drivers/net/wireless/mac80211_hwsim.c
47108 +++ b/drivers/net/wireless/mac80211_hwsim.c
47109 @@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
47110
47111 if (channels > 1) {
47112 hwsim_if_comb.num_different_channels = channels;
47113 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47114 - mac80211_hwsim_ops.cancel_hw_scan =
47115 - mac80211_hwsim_cancel_hw_scan;
47116 - mac80211_hwsim_ops.sw_scan_start = NULL;
47117 - mac80211_hwsim_ops.sw_scan_complete = NULL;
47118 - mac80211_hwsim_ops.remain_on_channel =
47119 - mac80211_hwsim_roc;
47120 - mac80211_hwsim_ops.cancel_remain_on_channel =
47121 - mac80211_hwsim_croc;
47122 - mac80211_hwsim_ops.add_chanctx =
47123 - mac80211_hwsim_add_chanctx;
47124 - mac80211_hwsim_ops.remove_chanctx =
47125 - mac80211_hwsim_remove_chanctx;
47126 - mac80211_hwsim_ops.change_chanctx =
47127 - mac80211_hwsim_change_chanctx;
47128 - mac80211_hwsim_ops.assign_vif_chanctx =
47129 - mac80211_hwsim_assign_vif_chanctx;
47130 - mac80211_hwsim_ops.unassign_vif_chanctx =
47131 - mac80211_hwsim_unassign_vif_chanctx;
47132 + pax_open_kernel();
47133 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47134 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47135 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
47136 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
47137 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
47138 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47139 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47140 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47141 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47142 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47143 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47144 + pax_close_kernel();
47145 }
47146
47147 spin_lock_init(&hwsim_radio_lock);
47148 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47149 index 8169a85..7fa3b47 100644
47150 --- a/drivers/net/wireless/rndis_wlan.c
47151 +++ b/drivers/net/wireless/rndis_wlan.c
47152 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47153
47154 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47155
47156 - if (rts_threshold < 0 || rts_threshold > 2347)
47157 + if (rts_threshold > 2347)
47158 rts_threshold = 2347;
47159
47160 tmp = cpu_to_le32(rts_threshold);
47161 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47162 index e4ba2ce..63d7417 100644
47163 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47164 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47165 @@ -377,7 +377,7 @@ struct rt2x00_intf {
47166 * for hardware which doesn't support hardware
47167 * sequence counting.
47168 */
47169 - atomic_t seqno;
47170 + atomic_unchecked_t seqno;
47171 };
47172
47173 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47174 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47175 index a5d38e8..d3c24ea 100644
47176 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47177 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47178 @@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47179 * sequence counter given by mac80211.
47180 */
47181 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47182 - seqno = atomic_add_return(0x10, &intf->seqno);
47183 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47184 else
47185 - seqno = atomic_read(&intf->seqno);
47186 + seqno = atomic_read_unchecked(&intf->seqno);
47187
47188 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47189 hdr->seq_ctrl |= cpu_to_le16(seqno);
47190 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47191 index e2b3d9c..67a5184 100644
47192 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47193 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47194 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47195
47196 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47197
47198 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47199 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47200 + pax_open_kernel();
47201 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47202 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47203 + pax_close_kernel();
47204
47205 wl1251_info("using dedicated interrupt line");
47206 } else {
47207 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47208 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47209 + pax_open_kernel();
47210 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47211 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47212 + pax_close_kernel();
47213
47214 wl1251_info("using SDIO interrupt");
47215 }
47216 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47217 index be7129b..4161356 100644
47218 --- a/drivers/net/wireless/ti/wl12xx/main.c
47219 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47220 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47221 sizeof(wl->conf.mem));
47222
47223 /* read data preparation is only needed by wl127x */
47224 - wl->ops->prepare_read = wl127x_prepare_read;
47225 + pax_open_kernel();
47226 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47227 + pax_close_kernel();
47228
47229 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47230 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47231 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47232 sizeof(wl->conf.mem));
47233
47234 /* read data preparation is only needed by wl127x */
47235 - wl->ops->prepare_read = wl127x_prepare_read;
47236 + pax_open_kernel();
47237 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47238 + pax_close_kernel();
47239
47240 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47241 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47242 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47243 index ec37b16..7e34d66 100644
47244 --- a/drivers/net/wireless/ti/wl18xx/main.c
47245 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47246 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47247 }
47248
47249 if (!checksum_param) {
47250 - wl18xx_ops.set_rx_csum = NULL;
47251 - wl18xx_ops.init_vif = NULL;
47252 + pax_open_kernel();
47253 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47254 + *(void **)&wl18xx_ops.init_vif = NULL;
47255 + pax_close_kernel();
47256 }
47257
47258 /* Enable 11a Band only if we have 5G antennas */
47259 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47260 index 84d94f5..bd6c61c 100644
47261 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47262 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47263 @@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
47264 {
47265 struct zd_usb *usb = urb->context;
47266 struct zd_usb_interrupt *intr = &usb->intr;
47267 - int len;
47268 + unsigned int len;
47269 u16 int_num;
47270
47271 ZD_ASSERT(in_interrupt());
47272 diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
47273 index c47794b..6668d03 100644
47274 --- a/drivers/net/xen-netback/common.h
47275 +++ b/drivers/net/xen-netback/common.h
47276 @@ -113,6 +113,11 @@ struct xenvif {
47277 domid_t domid;
47278 unsigned int handle;
47279
47280 + /* Is this interface disabled? True when backend discovers
47281 + * frontend is rogue.
47282 + */
47283 + bool disabled;
47284 +
47285 /* Use NAPI for guest TX */
47286 struct napi_struct napi;
47287 /* When feature-split-event-channels = 0, tx_irq = rx_irq. */
47288 diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
47289 index fff8cddf..a2ef2e6 100644
47290 --- a/drivers/net/xen-netback/interface.c
47291 +++ b/drivers/net/xen-netback/interface.c
47292 @@ -67,6 +67,15 @@ static int xenvif_poll(struct napi_struct *napi, int budget)
47293 struct xenvif *vif = container_of(napi, struct xenvif, napi);
47294 int work_done;
47295
47296 + /* This vif is rogue, we pretend we've there is nothing to do
47297 + * for this vif to deschedule it from NAPI. But this interface
47298 + * will be turned off in thread context later.
47299 + */
47300 + if (unlikely(vif->disabled)) {
47301 + napi_complete(napi);
47302 + return 0;
47303 + }
47304 +
47305 work_done = xenvif_tx_action(vif, budget);
47306
47307 if (work_done < budget) {
47308 @@ -323,6 +332,8 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
47309 vif->ip_csum = 1;
47310 vif->dev = dev;
47311
47312 + vif->disabled = false;
47313 +
47314 vif->credit_bytes = vif->remaining_credit = ~0UL;
47315 vif->credit_usec = 0UL;
47316 init_timer(&vif->credit_timeout);
47317 diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
47318 index 7842555..c69d1ad 100644
47319 --- a/drivers/net/xen-netback/netback.c
47320 +++ b/drivers/net/xen-netback/netback.c
47321 @@ -756,7 +756,8 @@ static void xenvif_tx_err(struct xenvif *vif,
47322 static void xenvif_fatal_tx_err(struct xenvif *vif)
47323 {
47324 netdev_err(vif->dev, "fatal error; disabling device\n");
47325 - xenvif_carrier_off(vif);
47326 + vif->disabled = true;
47327 + xenvif_kick_thread(vif);
47328 }
47329
47330 static int xenvif_count_requests(struct xenvif *vif,
47331 @@ -1483,7 +1484,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
47332 vif->tx.sring->req_prod, vif->tx.req_cons,
47333 XEN_NETIF_TX_RING_SIZE);
47334 xenvif_fatal_tx_err(vif);
47335 - continue;
47336 + break;
47337 }
47338
47339 work_to_do = RING_HAS_UNCONSUMED_REQUESTS(&vif->tx);
47340 @@ -1877,7 +1878,18 @@ int xenvif_kthread(void *data)
47341 while (!kthread_should_stop()) {
47342 wait_event_interruptible(vif->wq,
47343 rx_work_todo(vif) ||
47344 + vif->disabled ||
47345 kthread_should_stop());
47346 +
47347 + /* This frontend is found to be rogue, disable it in
47348 + * kthread context. Currently this is only set when
47349 + * netback finds out frontend sends malformed packet,
47350 + * but we cannot disable the interface in softirq
47351 + * context so we defer it here.
47352 + */
47353 + if (unlikely(vif->disabled && netif_carrier_ok(vif->dev)))
47354 + xenvif_carrier_off(vif);
47355 +
47356 if (kthread_should_stop())
47357 break;
47358
47359 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47360 index 7130864..00e64de 100644
47361 --- a/drivers/nfc/nfcwilink.c
47362 +++ b/drivers/nfc/nfcwilink.c
47363 @@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
47364
47365 static int nfcwilink_probe(struct platform_device *pdev)
47366 {
47367 - static struct nfcwilink *drv;
47368 + struct nfcwilink *drv;
47369 int rc;
47370 __u32 protocols;
47371
47372 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47373 index d93b2b6..ae50401 100644
47374 --- a/drivers/oprofile/buffer_sync.c
47375 +++ b/drivers/oprofile/buffer_sync.c
47376 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47377 if (cookie == NO_COOKIE)
47378 offset = pc;
47379 if (cookie == INVALID_COOKIE) {
47380 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47381 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47382 offset = pc;
47383 }
47384 if (cookie != last_cookie) {
47385 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47386 /* add userspace sample */
47387
47388 if (!mm) {
47389 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47390 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47391 return 0;
47392 }
47393
47394 cookie = lookup_dcookie(mm, s->eip, &offset);
47395
47396 if (cookie == INVALID_COOKIE) {
47397 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47398 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47399 return 0;
47400 }
47401
47402 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47403 /* ignore backtraces if failed to add a sample */
47404 if (state == sb_bt_start) {
47405 state = sb_bt_ignore;
47406 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47407 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47408 }
47409 }
47410 release_mm(mm);
47411 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47412 index c0cc4e7..44d4e54 100644
47413 --- a/drivers/oprofile/event_buffer.c
47414 +++ b/drivers/oprofile/event_buffer.c
47415 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47416 }
47417
47418 if (buffer_pos == buffer_size) {
47419 - atomic_inc(&oprofile_stats.event_lost_overflow);
47420 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47421 return;
47422 }
47423
47424 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47425 index ed2c3ec..deda85a 100644
47426 --- a/drivers/oprofile/oprof.c
47427 +++ b/drivers/oprofile/oprof.c
47428 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47429 if (oprofile_ops.switch_events())
47430 return;
47431
47432 - atomic_inc(&oprofile_stats.multiplex_counter);
47433 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47434 start_switch_worker();
47435 }
47436
47437 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47438 index ee2cfce..7f8f699 100644
47439 --- a/drivers/oprofile/oprofile_files.c
47440 +++ b/drivers/oprofile/oprofile_files.c
47441 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47442
47443 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47444
47445 -static ssize_t timeout_read(struct file *file, char __user *buf,
47446 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47447 size_t count, loff_t *offset)
47448 {
47449 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47450 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47451 index 59659ce..6c860a0 100644
47452 --- a/drivers/oprofile/oprofile_stats.c
47453 +++ b/drivers/oprofile/oprofile_stats.c
47454 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47455 cpu_buf->sample_invalid_eip = 0;
47456 }
47457
47458 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47459 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47460 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47461 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47462 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47463 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47464 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47465 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47466 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47467 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47468 }
47469
47470
47471 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47472 index 1fc622b..8c48fc3 100644
47473 --- a/drivers/oprofile/oprofile_stats.h
47474 +++ b/drivers/oprofile/oprofile_stats.h
47475 @@ -13,11 +13,11 @@
47476 #include <linux/atomic.h>
47477
47478 struct oprofile_stat_struct {
47479 - atomic_t sample_lost_no_mm;
47480 - atomic_t sample_lost_no_mapping;
47481 - atomic_t bt_lost_no_mapping;
47482 - atomic_t event_lost_overflow;
47483 - atomic_t multiplex_counter;
47484 + atomic_unchecked_t sample_lost_no_mm;
47485 + atomic_unchecked_t sample_lost_no_mapping;
47486 + atomic_unchecked_t bt_lost_no_mapping;
47487 + atomic_unchecked_t event_lost_overflow;
47488 + atomic_unchecked_t multiplex_counter;
47489 };
47490
47491 extern struct oprofile_stat_struct oprofile_stats;
47492 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47493 index 3f49345..c750d0b 100644
47494 --- a/drivers/oprofile/oprofilefs.c
47495 +++ b/drivers/oprofile/oprofilefs.c
47496 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47497
47498 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47499 {
47500 - atomic_t *val = file->private_data;
47501 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47502 + atomic_unchecked_t *val = file->private_data;
47503 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47504 }
47505
47506
47507 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47508
47509
47510 int oprofilefs_create_ro_atomic(struct dentry *root,
47511 - char const *name, atomic_t *val)
47512 + char const *name, atomic_unchecked_t *val)
47513 {
47514 return __oprofilefs_create_file(root, name,
47515 &atomic_ro_fops, 0444, val);
47516 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47517 index 61be1d9..dec05d7 100644
47518 --- a/drivers/oprofile/timer_int.c
47519 +++ b/drivers/oprofile/timer_int.c
47520 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47521 return NOTIFY_OK;
47522 }
47523
47524 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47525 +static struct notifier_block oprofile_cpu_notifier = {
47526 .notifier_call = oprofile_cpu_notify,
47527 };
47528
47529 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47530 index 92ed045..62d39bd7 100644
47531 --- a/drivers/parport/procfs.c
47532 +++ b/drivers/parport/procfs.c
47533 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47534
47535 *ppos += len;
47536
47537 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47538 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47539 }
47540
47541 #ifdef CONFIG_PARPORT_1284
47542 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47543
47544 *ppos += len;
47545
47546 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47547 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47548 }
47549 #endif /* IEEE1284.3 support. */
47550
47551 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47552 index ecfac7e..41be7028 100644
47553 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47554 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47555 @@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
47556 goto init_cleanup;
47557 }
47558
47559 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47560 + pax_open_kernel();
47561 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47562 + pax_close_kernel();
47563 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47564
47565 return retval;
47566 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47567 index 7536eef..52dc8fa 100644
47568 --- a/drivers/pci/hotplug/cpcihp_generic.c
47569 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47570 @@ -73,7 +73,6 @@ static u16 port;
47571 static unsigned int enum_bit;
47572 static u8 enum_mask;
47573
47574 -static struct cpci_hp_controller_ops generic_hpc_ops;
47575 static struct cpci_hp_controller generic_hpc;
47576
47577 static int __init validate_parameters(void)
47578 @@ -139,6 +138,10 @@ static int query_enum(void)
47579 return ((value & enum_mask) == enum_mask);
47580 }
47581
47582 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47583 + .query_enum = query_enum,
47584 +};
47585 +
47586 static int __init cpcihp_generic_init(void)
47587 {
47588 int status;
47589 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47590 pci_dev_put(dev);
47591
47592 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47593 - generic_hpc_ops.query_enum = query_enum;
47594 generic_hpc.ops = &generic_hpc_ops;
47595
47596 status = cpci_hp_register_controller(&generic_hpc);
47597 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47598 index e8c4a7c..7046f5c 100644
47599 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47600 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47601 @@ -59,7 +59,6 @@
47602 /* local variables */
47603 static bool debug;
47604 static bool poll;
47605 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47606 static struct cpci_hp_controller zt5550_hpc;
47607
47608 /* Primary cPCI bus bridge device */
47609 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47610 return 0;
47611 }
47612
47613 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47614 + .query_enum = zt5550_hc_query_enum,
47615 +};
47616 +
47617 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47618 {
47619 int status;
47620 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47621 dbg("returned from zt5550_hc_config");
47622
47623 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47624 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47625 zt5550_hpc.ops = &zt5550_hpc_ops;
47626 if(!poll) {
47627 zt5550_hpc.irq = hc_dev->irq;
47628 zt5550_hpc.irq_flags = IRQF_SHARED;
47629 zt5550_hpc.dev_id = hc_dev;
47630
47631 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47632 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47633 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47634 + pax_open_kernel();
47635 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47636 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47637 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47638 + pax_open_kernel();
47639 } else {
47640 info("using ENUM# polling mode");
47641 }
47642 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47643 index 76ba8a1..20ca857 100644
47644 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47645 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47646 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47647
47648 void compaq_nvram_init (void __iomem *rom_start)
47649 {
47650 +
47651 +#ifndef CONFIG_PAX_KERNEXEC
47652 if (rom_start) {
47653 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47654 }
47655 +#endif
47656 +
47657 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47658
47659 /* initialize our int15 lock */
47660 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47661 index cfa92a9..29539c5 100644
47662 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47663 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47664 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47665 return -EINVAL;
47666 }
47667
47668 - slot->ops->owner = owner;
47669 - slot->ops->mod_name = mod_name;
47670 + pax_open_kernel();
47671 + *(struct module **)&slot->ops->owner = owner;
47672 + *(const char **)&slot->ops->mod_name = mod_name;
47673 + pax_close_kernel();
47674
47675 mutex_lock(&pci_hp_mutex);
47676 /*
47677 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47678 index bbd48bb..6907ef4 100644
47679 --- a/drivers/pci/hotplug/pciehp_core.c
47680 +++ b/drivers/pci/hotplug/pciehp_core.c
47681 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47682 struct slot *slot = ctrl->slot;
47683 struct hotplug_slot *hotplug = NULL;
47684 struct hotplug_slot_info *info = NULL;
47685 - struct hotplug_slot_ops *ops = NULL;
47686 + hotplug_slot_ops_no_const *ops = NULL;
47687 char name[SLOT_NAME_SIZE];
47688 int retval = -ENOMEM;
47689
47690 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47691 index c91e6c1..5c723ef 100644
47692 --- a/drivers/pci/pci-sysfs.c
47693 +++ b/drivers/pci/pci-sysfs.c
47694 @@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47695 {
47696 /* allocate attribute structure, piggyback attribute name */
47697 int name_len = write_combine ? 13 : 10;
47698 - struct bin_attribute *res_attr;
47699 + bin_attribute_no_const *res_attr;
47700 int retval;
47701
47702 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47703 @@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47704 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47705 {
47706 int retval;
47707 - struct bin_attribute *attr;
47708 + bin_attribute_no_const *attr;
47709
47710 /* If the device has VPD, try to expose it in sysfs. */
47711 if (dev->vpd) {
47712 @@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47713 {
47714 int retval;
47715 int rom_size = 0;
47716 - struct bin_attribute *attr;
47717 + bin_attribute_no_const *attr;
47718
47719 if (!sysfs_initialized)
47720 return -EACCES;
47721 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47722 index 9c91ecc..bda4796 100644
47723 --- a/drivers/pci/pci.h
47724 +++ b/drivers/pci/pci.h
47725 @@ -95,7 +95,7 @@ struct pci_vpd_ops {
47726 struct pci_vpd {
47727 unsigned int len;
47728 const struct pci_vpd_ops *ops;
47729 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47730 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47731 };
47732
47733 int pci_vpd_pci22_init(struct pci_dev *dev);
47734 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47735 index f1272dc..e92a1ac 100644
47736 --- a/drivers/pci/pcie/aspm.c
47737 +++ b/drivers/pci/pcie/aspm.c
47738 @@ -27,9 +27,9 @@
47739 #define MODULE_PARAM_PREFIX "pcie_aspm."
47740
47741 /* Note: those are not register definitions */
47742 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47743 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47744 -#define ASPM_STATE_L1 (4) /* L1 state */
47745 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47746 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47747 +#define ASPM_STATE_L1 (4U) /* L1 state */
47748 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47749 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47750
47751 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47752 index 38e403d..a2ce55a 100644
47753 --- a/drivers/pci/probe.c
47754 +++ b/drivers/pci/probe.c
47755 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47756 struct pci_bus_region region, inverted_region;
47757 bool bar_too_big = false, bar_disabled = false;
47758
47759 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47760 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47761
47762 /* No printks while decoding is disabled! */
47763 if (!dev->mmio_always_on) {
47764 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47765 index 46d1378..30e452b 100644
47766 --- a/drivers/pci/proc.c
47767 +++ b/drivers/pci/proc.c
47768 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47769 static int __init pci_proc_init(void)
47770 {
47771 struct pci_dev *dev = NULL;
47772 +
47773 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47774 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47775 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47776 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47777 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47778 +#endif
47779 +#else
47780 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47781 +#endif
47782 proc_create("devices", 0, proc_bus_pci_dir,
47783 &proc_bus_pci_dev_operations);
47784 proc_initialized = 1;
47785 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47786 index 3e5b4497..dcdfb70 100644
47787 --- a/drivers/platform/chrome/chromeos_laptop.c
47788 +++ b/drivers/platform/chrome/chromeos_laptop.c
47789 @@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
47790 return 0;
47791 }
47792
47793 -static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
47794 +static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
47795 {
47796 .ident = "Samsung Series 5 550 - Touchpad",
47797 .matches = {
47798 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47799 index 19c313b..ed28b38 100644
47800 --- a/drivers/platform/x86/asus-wmi.c
47801 +++ b/drivers/platform/x86/asus-wmi.c
47802 @@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
47803 int err;
47804 u32 retval = -1;
47805
47806 +#ifdef CONFIG_GRKERNSEC_KMEM
47807 + return -EPERM;
47808 +#endif
47809 +
47810 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47811
47812 if (err < 0)
47813 @@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
47814 int err;
47815 u32 retval = -1;
47816
47817 +#ifdef CONFIG_GRKERNSEC_KMEM
47818 + return -EPERM;
47819 +#endif
47820 +
47821 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47822 &retval);
47823
47824 @@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
47825 union acpi_object *obj;
47826 acpi_status status;
47827
47828 +#ifdef CONFIG_GRKERNSEC_KMEM
47829 + return -EPERM;
47830 +#endif
47831 +
47832 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47833 1, asus->debug.method_id,
47834 &input, &output);
47835 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47836 index 62f8030..c7f2a45 100644
47837 --- a/drivers/platform/x86/msi-laptop.c
47838 +++ b/drivers/platform/x86/msi-laptop.c
47839 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47840
47841 if (!quirks->ec_read_only) {
47842 /* allow userland write sysfs file */
47843 - dev_attr_bluetooth.store = store_bluetooth;
47844 - dev_attr_wlan.store = store_wlan;
47845 - dev_attr_threeg.store = store_threeg;
47846 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47847 - dev_attr_wlan.attr.mode |= S_IWUSR;
47848 - dev_attr_threeg.attr.mode |= S_IWUSR;
47849 + pax_open_kernel();
47850 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47851 + *(void **)&dev_attr_wlan.store = store_wlan;
47852 + *(void **)&dev_attr_threeg.store = store_threeg;
47853 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47854 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47855 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47856 + pax_close_kernel();
47857 }
47858
47859 /* disable hardware control by fn key */
47860 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47861 index 70222f2..8c8ce66 100644
47862 --- a/drivers/platform/x86/msi-wmi.c
47863 +++ b/drivers/platform/x86/msi-wmi.c
47864 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47865 static void msi_wmi_notify(u32 value, void *context)
47866 {
47867 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47868 - static struct key_entry *key;
47869 + struct key_entry *key;
47870 union acpi_object *obj;
47871 acpi_status status;
47872
47873 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47874 index fb233ae..23a325c 100644
47875 --- a/drivers/platform/x86/sony-laptop.c
47876 +++ b/drivers/platform/x86/sony-laptop.c
47877 @@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47878 }
47879
47880 /* High speed charging function */
47881 -static struct device_attribute *hsc_handle;
47882 +static device_attribute_no_const *hsc_handle;
47883
47884 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47885 struct device_attribute *attr,
47886 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47887 index 58b0274..6704626 100644
47888 --- a/drivers/platform/x86/thinkpad_acpi.c
47889 +++ b/drivers/platform/x86/thinkpad_acpi.c
47890 @@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
47891 return 0;
47892 }
47893
47894 -void static hotkey_mask_warn_incomplete_mask(void)
47895 +static void hotkey_mask_warn_incomplete_mask(void)
47896 {
47897 /* log only what the user can fix... */
47898 const u32 wantedmask = hotkey_driver_mask &
47899 @@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47900 }
47901 }
47902
47903 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47904 - struct tp_nvram_state *newn,
47905 - const u32 event_mask)
47906 -{
47907 -
47908 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47909 do { \
47910 if ((event_mask & (1 << __scancode)) && \
47911 @@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47912 tpacpi_hotkey_send_key(__scancode); \
47913 } while (0)
47914
47915 - void issue_volchange(const unsigned int oldvol,
47916 - const unsigned int newvol)
47917 - {
47918 - unsigned int i = oldvol;
47919 +static void issue_volchange(const unsigned int oldvol,
47920 + const unsigned int newvol,
47921 + const u32 event_mask)
47922 +{
47923 + unsigned int i = oldvol;
47924
47925 - while (i > newvol) {
47926 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47927 - i--;
47928 - }
47929 - while (i < newvol) {
47930 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47931 - i++;
47932 - }
47933 + while (i > newvol) {
47934 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47935 + i--;
47936 }
47937 + while (i < newvol) {
47938 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47939 + i++;
47940 + }
47941 +}
47942
47943 - void issue_brightnesschange(const unsigned int oldbrt,
47944 - const unsigned int newbrt)
47945 - {
47946 - unsigned int i = oldbrt;
47947 +static void issue_brightnesschange(const unsigned int oldbrt,
47948 + const unsigned int newbrt,
47949 + const u32 event_mask)
47950 +{
47951 + unsigned int i = oldbrt;
47952
47953 - while (i > newbrt) {
47954 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47955 - i--;
47956 - }
47957 - while (i < newbrt) {
47958 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47959 - i++;
47960 - }
47961 + while (i > newbrt) {
47962 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47963 + i--;
47964 + }
47965 + while (i < newbrt) {
47966 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47967 + i++;
47968 }
47969 +}
47970
47971 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47972 + struct tp_nvram_state *newn,
47973 + const u32 event_mask)
47974 +{
47975 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47976 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47977 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47978 @@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47979 oldn->volume_level != newn->volume_level) {
47980 /* recently muted, or repeated mute keypress, or
47981 * multiple presses ending in mute */
47982 - issue_volchange(oldn->volume_level, newn->volume_level);
47983 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47984 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47985 }
47986 } else {
47987 @@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47988 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47989 }
47990 if (oldn->volume_level != newn->volume_level) {
47991 - issue_volchange(oldn->volume_level, newn->volume_level);
47992 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47993 } else if (oldn->volume_toggle != newn->volume_toggle) {
47994 /* repeated vol up/down keypress at end of scale ? */
47995 if (newn->volume_level == 0)
47996 @@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47997 /* handle brightness */
47998 if (oldn->brightness_level != newn->brightness_level) {
47999 issue_brightnesschange(oldn->brightness_level,
48000 - newn->brightness_level);
48001 + newn->brightness_level,
48002 + event_mask);
48003 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
48004 /* repeated key presses that didn't change state */
48005 if (newn->brightness_level == 0)
48006 @@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48007 && !tp_features.bright_unkfw)
48008 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48009 }
48010 +}
48011
48012 #undef TPACPI_COMPARE_KEY
48013 #undef TPACPI_MAY_SEND_KEY
48014 -}
48015
48016 /*
48017 * Polling driver
48018 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48019 index 769d265..a3a05ca 100644
48020 --- a/drivers/pnp/pnpbios/bioscalls.c
48021 +++ b/drivers/pnp/pnpbios/bioscalls.c
48022 @@ -58,7 +58,7 @@ do { \
48023 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48024 } while(0)
48025
48026 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48027 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48028 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48029
48030 /*
48031 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48032
48033 cpu = get_cpu();
48034 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48035 +
48036 + pax_open_kernel();
48037 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48038 + pax_close_kernel();
48039
48040 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48041 spin_lock_irqsave(&pnp_bios_lock, flags);
48042 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48043 :"memory");
48044 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48045
48046 + pax_open_kernel();
48047 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48048 + pax_close_kernel();
48049 +
48050 put_cpu();
48051
48052 /* If we get here and this is set then the PnP BIOS faulted on us. */
48053 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48054 return status;
48055 }
48056
48057 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
48058 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48059 {
48060 int i;
48061
48062 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48063 pnp_bios_callpoint.offset = header->fields.pm16offset;
48064 pnp_bios_callpoint.segment = PNP_CS16;
48065
48066 + pax_open_kernel();
48067 +
48068 for_each_possible_cpu(i) {
48069 struct desc_struct *gdt = get_cpu_gdt_table(i);
48070 if (!gdt)
48071 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48072 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48073 (unsigned long)__va(header->fields.pm16dseg));
48074 }
48075 +
48076 + pax_close_kernel();
48077 }
48078 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48079 index d95e101..67f0c3f 100644
48080 --- a/drivers/pnp/resource.c
48081 +++ b/drivers/pnp/resource.c
48082 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48083 return 1;
48084
48085 /* check if the resource is valid */
48086 - if (*irq < 0 || *irq > 15)
48087 + if (*irq > 15)
48088 return 0;
48089
48090 /* check if the resource is reserved */
48091 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48092 return 1;
48093
48094 /* check if the resource is valid */
48095 - if (*dma < 0 || *dma == 4 || *dma > 7)
48096 + if (*dma == 4 || *dma > 7)
48097 return 0;
48098
48099 /* check if the resource is reserved */
48100 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48101 index 0c52e2a..3421ab7 100644
48102 --- a/drivers/power/pda_power.c
48103 +++ b/drivers/power/pda_power.c
48104 @@ -37,7 +37,11 @@ static int polling;
48105
48106 #if IS_ENABLED(CONFIG_USB_PHY)
48107 static struct usb_phy *transceiver;
48108 -static struct notifier_block otg_nb;
48109 +static int otg_handle_notification(struct notifier_block *nb,
48110 + unsigned long event, void *unused);
48111 +static struct notifier_block otg_nb = {
48112 + .notifier_call = otg_handle_notification
48113 +};
48114 #endif
48115
48116 static struct regulator *ac_draw;
48117 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48118
48119 #if IS_ENABLED(CONFIG_USB_PHY)
48120 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48121 - otg_nb.notifier_call = otg_handle_notification;
48122 ret = usb_register_notifier(transceiver, &otg_nb);
48123 if (ret) {
48124 dev_err(dev, "failure to register otg notifier\n");
48125 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48126 index cc439fd..8fa30df 100644
48127 --- a/drivers/power/power_supply.h
48128 +++ b/drivers/power/power_supply.h
48129 @@ -16,12 +16,12 @@ struct power_supply;
48130
48131 #ifdef CONFIG_SYSFS
48132
48133 -extern void power_supply_init_attrs(struct device_type *dev_type);
48134 +extern void power_supply_init_attrs(void);
48135 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48136
48137 #else
48138
48139 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48140 +static inline void power_supply_init_attrs(void) {}
48141 #define power_supply_uevent NULL
48142
48143 #endif /* CONFIG_SYSFS */
48144 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48145 index 557af94..84dc1fe 100644
48146 --- a/drivers/power/power_supply_core.c
48147 +++ b/drivers/power/power_supply_core.c
48148 @@ -24,7 +24,10 @@
48149 struct class *power_supply_class;
48150 EXPORT_SYMBOL_GPL(power_supply_class);
48151
48152 -static struct device_type power_supply_dev_type;
48153 +extern const struct attribute_group *power_supply_attr_groups[];
48154 +static struct device_type power_supply_dev_type = {
48155 + .groups = power_supply_attr_groups,
48156 +};
48157
48158 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48159 struct power_supply *supply)
48160 @@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
48161 return PTR_ERR(power_supply_class);
48162
48163 power_supply_class->dev_uevent = power_supply_uevent;
48164 - power_supply_init_attrs(&power_supply_dev_type);
48165 + power_supply_init_attrs();
48166
48167 return 0;
48168 }
48169 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48170 index 44420d1..967126e 100644
48171 --- a/drivers/power/power_supply_sysfs.c
48172 +++ b/drivers/power/power_supply_sysfs.c
48173 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48174 .is_visible = power_supply_attr_is_visible,
48175 };
48176
48177 -static const struct attribute_group *power_supply_attr_groups[] = {
48178 +const struct attribute_group *power_supply_attr_groups[] = {
48179 &power_supply_attr_group,
48180 NULL,
48181 };
48182
48183 -void power_supply_init_attrs(struct device_type *dev_type)
48184 +void power_supply_init_attrs(void)
48185 {
48186 int i;
48187
48188 - dev_type->groups = power_supply_attr_groups;
48189 -
48190 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48191 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48192 }
48193 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48194 index 84419af..268ede8 100644
48195 --- a/drivers/powercap/powercap_sys.c
48196 +++ b/drivers/powercap/powercap_sys.c
48197 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48198 struct device_attribute name_attr;
48199 };
48200
48201 +static ssize_t show_constraint_name(struct device *dev,
48202 + struct device_attribute *dev_attr,
48203 + char *buf);
48204 +
48205 static struct powercap_constraint_attr
48206 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48207 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48208 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48209 + .power_limit_attr = {
48210 + .attr = {
48211 + .name = NULL,
48212 + .mode = S_IWUSR | S_IRUGO
48213 + },
48214 + .show = show_constraint_power_limit_uw,
48215 + .store = store_constraint_power_limit_uw
48216 + },
48217 +
48218 + .time_window_attr = {
48219 + .attr = {
48220 + .name = NULL,
48221 + .mode = S_IWUSR | S_IRUGO
48222 + },
48223 + .show = show_constraint_time_window_us,
48224 + .store = store_constraint_time_window_us
48225 + },
48226 +
48227 + .max_power_attr = {
48228 + .attr = {
48229 + .name = NULL,
48230 + .mode = S_IRUGO
48231 + },
48232 + .show = show_constraint_max_power_uw,
48233 + .store = NULL
48234 + },
48235 +
48236 + .min_power_attr = {
48237 + .attr = {
48238 + .name = NULL,
48239 + .mode = S_IRUGO
48240 + },
48241 + .show = show_constraint_min_power_uw,
48242 + .store = NULL
48243 + },
48244 +
48245 + .max_time_window_attr = {
48246 + .attr = {
48247 + .name = NULL,
48248 + .mode = S_IRUGO
48249 + },
48250 + .show = show_constraint_max_time_window_us,
48251 + .store = NULL
48252 + },
48253 +
48254 + .min_time_window_attr = {
48255 + .attr = {
48256 + .name = NULL,
48257 + .mode = S_IRUGO
48258 + },
48259 + .show = show_constraint_min_time_window_us,
48260 + .store = NULL
48261 + },
48262 +
48263 + .name_attr = {
48264 + .attr = {
48265 + .name = NULL,
48266 + .mode = S_IRUGO
48267 + },
48268 + .show = show_constraint_name,
48269 + .store = NULL
48270 + }
48271 + }
48272 +};
48273
48274 /* A list of powercap control_types */
48275 static LIST_HEAD(powercap_cntrl_list);
48276 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48277 }
48278
48279 static int create_constraint_attribute(int id, const char *name,
48280 - int mode,
48281 - struct device_attribute *dev_attr,
48282 - ssize_t (*show)(struct device *,
48283 - struct device_attribute *, char *),
48284 - ssize_t (*store)(struct device *,
48285 - struct device_attribute *,
48286 - const char *, size_t)
48287 - )
48288 + struct device_attribute *dev_attr)
48289 {
48290 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48291
48292 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48293 - id, name);
48294 - if (!dev_attr->attr.name)
48295 + if (!name)
48296 return -ENOMEM;
48297 - dev_attr->attr.mode = mode;
48298 - dev_attr->show = show;
48299 - dev_attr->store = store;
48300 +
48301 + pax_open_kernel();
48302 + *(const char **)&dev_attr->attr.name = name;
48303 + pax_close_kernel();
48304
48305 return 0;
48306 }
48307 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48308
48309 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48310 ret = create_constraint_attribute(i, "power_limit_uw",
48311 - S_IWUSR | S_IRUGO,
48312 - &constraint_attrs[i].power_limit_attr,
48313 - show_constraint_power_limit_uw,
48314 - store_constraint_power_limit_uw);
48315 + &constraint_attrs[i].power_limit_attr);
48316 if (ret)
48317 goto err_alloc;
48318 ret = create_constraint_attribute(i, "time_window_us",
48319 - S_IWUSR | S_IRUGO,
48320 - &constraint_attrs[i].time_window_attr,
48321 - show_constraint_time_window_us,
48322 - store_constraint_time_window_us);
48323 + &constraint_attrs[i].time_window_attr);
48324 if (ret)
48325 goto err_alloc;
48326 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48327 - &constraint_attrs[i].name_attr,
48328 - show_constraint_name,
48329 - NULL);
48330 + ret = create_constraint_attribute(i, "name",
48331 + &constraint_attrs[i].name_attr);
48332 if (ret)
48333 goto err_alloc;
48334 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48335 - &constraint_attrs[i].max_power_attr,
48336 - show_constraint_max_power_uw,
48337 - NULL);
48338 + ret = create_constraint_attribute(i, "max_power_uw",
48339 + &constraint_attrs[i].max_power_attr);
48340 if (ret)
48341 goto err_alloc;
48342 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48343 - &constraint_attrs[i].min_power_attr,
48344 - show_constraint_min_power_uw,
48345 - NULL);
48346 + ret = create_constraint_attribute(i, "min_power_uw",
48347 + &constraint_attrs[i].min_power_attr);
48348 if (ret)
48349 goto err_alloc;
48350 ret = create_constraint_attribute(i, "max_time_window_us",
48351 - S_IRUGO,
48352 - &constraint_attrs[i].max_time_window_attr,
48353 - show_constraint_max_time_window_us,
48354 - NULL);
48355 + &constraint_attrs[i].max_time_window_attr);
48356 if (ret)
48357 goto err_alloc;
48358 ret = create_constraint_attribute(i, "min_time_window_us",
48359 - S_IRUGO,
48360 - &constraint_attrs[i].min_time_window_attr,
48361 - show_constraint_min_time_window_us,
48362 - NULL);
48363 + &constraint_attrs[i].min_time_window_attr);
48364 if (ret)
48365 goto err_alloc;
48366
48367 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48368 power_zone->zone_dev_attrs[count++] =
48369 &dev_attr_max_energy_range_uj.attr;
48370 if (power_zone->ops->get_energy_uj) {
48371 + pax_open_kernel();
48372 if (power_zone->ops->reset_energy_uj)
48373 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48374 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48375 else
48376 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48377 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48378 + pax_close_kernel();
48379 power_zone->zone_dev_attrs[count++] =
48380 &dev_attr_energy_uj.attr;
48381 }
48382 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48383 index 7271299..20217a5 100644
48384 --- a/drivers/regulator/core.c
48385 +++ b/drivers/regulator/core.c
48386 @@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48387 {
48388 const struct regulation_constraints *constraints = NULL;
48389 const struct regulator_init_data *init_data;
48390 - static atomic_t regulator_no = ATOMIC_INIT(0);
48391 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48392 struct regulator_dev *rdev;
48393 struct device *dev;
48394 int ret, i;
48395 @@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48396 rdev->dev.of_node = config->of_node;
48397 rdev->dev.parent = dev;
48398 dev_set_name(&rdev->dev, "regulator.%d",
48399 - atomic_inc_return(&regulator_no) - 1);
48400 + atomic_inc_return_unchecked(&regulator_no) - 1);
48401 ret = device_register(&rdev->dev);
48402 if (ret != 0) {
48403 put_device(&rdev->dev);
48404 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48405 index 8d94d3d..653b623 100644
48406 --- a/drivers/regulator/max8660.c
48407 +++ b/drivers/regulator/max8660.c
48408 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48409 max8660->shadow_regs[MAX8660_OVER1] = 5;
48410 } else {
48411 /* Otherwise devices can be toggled via software */
48412 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48413 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48414 + pax_open_kernel();
48415 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48416 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48417 + pax_close_kernel();
48418 }
48419
48420 /*
48421 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48422 index 892aa1e..ebd1b9c 100644
48423 --- a/drivers/regulator/max8973-regulator.c
48424 +++ b/drivers/regulator/max8973-regulator.c
48425 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48426 if (!pdata || !pdata->enable_ext_control) {
48427 max->desc.enable_reg = MAX8973_VOUT;
48428 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48429 - max->ops.enable = regulator_enable_regmap;
48430 - max->ops.disable = regulator_disable_regmap;
48431 - max->ops.is_enabled = regulator_is_enabled_regmap;
48432 + pax_open_kernel();
48433 + *(void **)&max->ops.enable = regulator_enable_regmap;
48434 + *(void **)&max->ops.disable = regulator_disable_regmap;
48435 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48436 + pax_close_kernel();
48437 }
48438
48439 if (pdata) {
48440 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48441 index 96c9f80..90974ca 100644
48442 --- a/drivers/regulator/mc13892-regulator.c
48443 +++ b/drivers/regulator/mc13892-regulator.c
48444 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48445 }
48446 mc13xxx_unlock(mc13892);
48447
48448 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48449 + pax_open_kernel();
48450 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48451 = mc13892_vcam_set_mode;
48452 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48453 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48454 = mc13892_vcam_get_mode;
48455 + pax_close_kernel();
48456
48457 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48458 ARRAY_SIZE(mc13892_regulators));
48459 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48460 index a2325bc..04c549f 100644
48461 --- a/drivers/rtc/rtc-cmos.c
48462 +++ b/drivers/rtc/rtc-cmos.c
48463 @@ -779,7 +779,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48464 hpet_rtc_timer_init();
48465
48466 /* export at least the first block of NVRAM */
48467 - nvram.size = address_space - NVRAM_OFFSET;
48468 + pax_open_kernel();
48469 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48470 + pax_close_kernel();
48471 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48472 if (retval < 0) {
48473 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48474 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48475 index d049393..bb20be0 100644
48476 --- a/drivers/rtc/rtc-dev.c
48477 +++ b/drivers/rtc/rtc-dev.c
48478 @@ -16,6 +16,7 @@
48479 #include <linux/module.h>
48480 #include <linux/rtc.h>
48481 #include <linux/sched.h>
48482 +#include <linux/grsecurity.h>
48483 #include "rtc-core.h"
48484
48485 static dev_t rtc_devt;
48486 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48487 if (copy_from_user(&tm, uarg, sizeof(tm)))
48488 return -EFAULT;
48489
48490 + gr_log_timechange();
48491 +
48492 return rtc_set_time(rtc, &tm);
48493
48494 case RTC_PIE_ON:
48495 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48496 index 4e75345..09f8663 100644
48497 --- a/drivers/rtc/rtc-ds1307.c
48498 +++ b/drivers/rtc/rtc-ds1307.c
48499 @@ -107,7 +107,7 @@ struct ds1307 {
48500 u8 offset; /* register's offset */
48501 u8 regs[11];
48502 u16 nvram_offset;
48503 - struct bin_attribute *nvram;
48504 + bin_attribute_no_const *nvram;
48505 enum ds_type type;
48506 unsigned long flags;
48507 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48508 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48509 index 11880c1..b823aa4 100644
48510 --- a/drivers/rtc/rtc-m48t59.c
48511 +++ b/drivers/rtc/rtc-m48t59.c
48512 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48513 if (IS_ERR(m48t59->rtc))
48514 return PTR_ERR(m48t59->rtc);
48515
48516 - m48t59_nvram_attr.size = pdata->offset;
48517 + pax_open_kernel();
48518 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48519 + pax_close_kernel();
48520
48521 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48522 if (ret)
48523 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48524 index 14b5f8d..cc9bd26 100644
48525 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48526 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48527 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48528 for (bit = 0; bit < 8; bit++) {
48529
48530 if ((pci_status[i] & (0x1 << bit)) != 0) {
48531 - static const char *s;
48532 + const char *s;
48533
48534 s = pci_status_strings[bit];
48535 if (i == 7/*TARG*/ && bit == 3)
48536 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48537
48538 for (bit = 0; bit < 8; bit++) {
48539
48540 - if ((split_status[i] & (0x1 << bit)) != 0) {
48541 - static const char *s;
48542 -
48543 - s = split_status_strings[bit];
48544 - printk(s, ahd_name(ahd),
48545 + if ((split_status[i] & (0x1 << bit)) != 0)
48546 + printk(split_status_strings[bit], ahd_name(ahd),
48547 split_status_source[i]);
48548 - }
48549
48550 if (i > 1)
48551 continue;
48552
48553 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48554 - static const char *s;
48555 -
48556 - s = split_status_strings[bit];
48557 - printk(s, ahd_name(ahd), "SG");
48558 - }
48559 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48560 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48561 }
48562 }
48563 /*
48564 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48565 index e693af6..2e525b6 100644
48566 --- a/drivers/scsi/bfa/bfa_fcpim.h
48567 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48568 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48569
48570 struct bfa_itn_s {
48571 bfa_isr_func_t isr;
48572 -};
48573 +} __no_const;
48574
48575 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48576 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48577 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48578 index a3ab5cc..8143622 100644
48579 --- a/drivers/scsi/bfa/bfa_fcs.c
48580 +++ b/drivers/scsi/bfa/bfa_fcs.c
48581 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48582 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48583
48584 static struct bfa_fcs_mod_s fcs_modules[] = {
48585 - { bfa_fcs_port_attach, NULL, NULL },
48586 - { bfa_fcs_uf_attach, NULL, NULL },
48587 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48588 - bfa_fcs_fabric_modexit },
48589 + {
48590 + .attach = bfa_fcs_port_attach,
48591 + .modinit = NULL,
48592 + .modexit = NULL
48593 + },
48594 + {
48595 + .attach = bfa_fcs_uf_attach,
48596 + .modinit = NULL,
48597 + .modexit = NULL
48598 + },
48599 + {
48600 + .attach = bfa_fcs_fabric_attach,
48601 + .modinit = bfa_fcs_fabric_modinit,
48602 + .modexit = bfa_fcs_fabric_modexit
48603 + },
48604 };
48605
48606 /*
48607 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48608 index f5e4e61..a0acaf6 100644
48609 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48610 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48611 @@ -89,15 +89,26 @@ static struct {
48612 void (*offline) (struct bfa_fcs_lport_s *port);
48613 } __port_action[] = {
48614 {
48615 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48616 - bfa_fcs_lport_unknown_offline}, {
48617 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48618 - bfa_fcs_lport_fab_offline}, {
48619 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48620 - bfa_fcs_lport_n2n_offline}, {
48621 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48622 - bfa_fcs_lport_loop_offline},
48623 - };
48624 + .init = bfa_fcs_lport_unknown_init,
48625 + .online = bfa_fcs_lport_unknown_online,
48626 + .offline = bfa_fcs_lport_unknown_offline
48627 + },
48628 + {
48629 + .init = bfa_fcs_lport_fab_init,
48630 + .online = bfa_fcs_lport_fab_online,
48631 + .offline = bfa_fcs_lport_fab_offline
48632 + },
48633 + {
48634 + .init = bfa_fcs_lport_n2n_init,
48635 + .online = bfa_fcs_lport_n2n_online,
48636 + .offline = bfa_fcs_lport_n2n_offline
48637 + },
48638 + {
48639 + .init = bfa_fcs_lport_loop_init,
48640 + .online = bfa_fcs_lport_loop_online,
48641 + .offline = bfa_fcs_lport_loop_offline
48642 + },
48643 +};
48644
48645 /*
48646 * fcs_port_sm FCS logical port state machine
48647 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48648 index 90814fe..4384138 100644
48649 --- a/drivers/scsi/bfa/bfa_ioc.h
48650 +++ b/drivers/scsi/bfa/bfa_ioc.h
48651 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48652 bfa_ioc_disable_cbfn_t disable_cbfn;
48653 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48654 bfa_ioc_reset_cbfn_t reset_cbfn;
48655 -};
48656 +} __no_const;
48657
48658 /*
48659 * IOC event notification mechanism.
48660 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48661 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48662 enum bfi_ioc_state fwstate);
48663 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48664 -};
48665 +} __no_const;
48666
48667 /*
48668 * Queue element to wait for room in request queue. FIFO order is
48669 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48670 index a14c784..6de6790 100644
48671 --- a/drivers/scsi/bfa/bfa_modules.h
48672 +++ b/drivers/scsi/bfa/bfa_modules.h
48673 @@ -78,12 +78,12 @@ enum {
48674 \
48675 extern struct bfa_module_s hal_mod_ ## __mod; \
48676 struct bfa_module_s hal_mod_ ## __mod = { \
48677 - bfa_ ## __mod ## _meminfo, \
48678 - bfa_ ## __mod ## _attach, \
48679 - bfa_ ## __mod ## _detach, \
48680 - bfa_ ## __mod ## _start, \
48681 - bfa_ ## __mod ## _stop, \
48682 - bfa_ ## __mod ## _iocdisable, \
48683 + .meminfo = bfa_ ## __mod ## _meminfo, \
48684 + .attach = bfa_ ## __mod ## _attach, \
48685 + .detach = bfa_ ## __mod ## _detach, \
48686 + .start = bfa_ ## __mod ## _start, \
48687 + .stop = bfa_ ## __mod ## _stop, \
48688 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
48689 }
48690
48691 #define BFA_CACHELINE_SZ (256)
48692 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48693 index 045c4e1..13de803 100644
48694 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
48695 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48696 @@ -33,8 +33,8 @@
48697 */
48698 #include "libfcoe.h"
48699
48700 -static atomic_t ctlr_num;
48701 -static atomic_t fcf_num;
48702 +static atomic_unchecked_t ctlr_num;
48703 +static atomic_unchecked_t fcf_num;
48704
48705 /*
48706 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48707 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48708 if (!ctlr)
48709 goto out;
48710
48711 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48712 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48713 ctlr->f = f;
48714 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48715 INIT_LIST_HEAD(&ctlr->fcfs);
48716 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48717 fcf->dev.parent = &ctlr->dev;
48718 fcf->dev.bus = &fcoe_bus_type;
48719 fcf->dev.type = &fcoe_fcf_device_type;
48720 - fcf->id = atomic_inc_return(&fcf_num) - 1;
48721 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48722 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48723
48724 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48725 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48726 {
48727 int error;
48728
48729 - atomic_set(&ctlr_num, 0);
48730 - atomic_set(&fcf_num, 0);
48731 + atomic_set_unchecked(&ctlr_num, 0);
48732 + atomic_set_unchecked(&fcf_num, 0);
48733
48734 error = bus_register(&fcoe_bus_type);
48735 if (error)
48736 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48737 index f2c5005..db36c02 100644
48738 --- a/drivers/scsi/hosts.c
48739 +++ b/drivers/scsi/hosts.c
48740 @@ -42,7 +42,7 @@
48741 #include "scsi_logging.h"
48742
48743
48744 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48745 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48746
48747
48748 static void scsi_host_cls_release(struct device *dev)
48749 @@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48750 * subtract one because we increment first then return, but we need to
48751 * know what the next host number was before increment
48752 */
48753 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48754 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48755 shost->dma_channel = 0xff;
48756
48757 /* These three are default values which can be overridden */
48758 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48759 index 20a5e6e..8b23cea 100644
48760 --- a/drivers/scsi/hpsa.c
48761 +++ b/drivers/scsi/hpsa.c
48762 @@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48763 unsigned long flags;
48764
48765 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48766 - return h->access.command_completed(h, q);
48767 + return h->access->command_completed(h, q);
48768
48769 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48770 a = rq->head[rq->current_entry];
48771 @@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
48772 while (!list_empty(&h->reqQ)) {
48773 c = list_entry(h->reqQ.next, struct CommandList, list);
48774 /* can't do anything if fifo is full */
48775 - if ((h->access.fifo_full(h))) {
48776 + if ((h->access->fifo_full(h))) {
48777 dev_warn(&h->pdev->dev, "fifo full\n");
48778 break;
48779 }
48780 @@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
48781
48782 /* Tell the controller execute command */
48783 spin_unlock_irqrestore(&h->lock, flags);
48784 - h->access.submit_command(h, c);
48785 + h->access->submit_command(h, c);
48786 spin_lock_irqsave(&h->lock, flags);
48787 }
48788 spin_unlock_irqrestore(&h->lock, flags);
48789 @@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
48790
48791 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48792 {
48793 - return h->access.command_completed(h, q);
48794 + return h->access->command_completed(h, q);
48795 }
48796
48797 static inline bool interrupt_pending(struct ctlr_info *h)
48798 {
48799 - return h->access.intr_pending(h);
48800 + return h->access->intr_pending(h);
48801 }
48802
48803 static inline long interrupt_not_for_us(struct ctlr_info *h)
48804 {
48805 - return (h->access.intr_pending(h) == 0) ||
48806 + return (h->access->intr_pending(h) == 0) ||
48807 (h->interrupts_enabled == 0);
48808 }
48809
48810 @@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48811 if (prod_index < 0)
48812 return -ENODEV;
48813 h->product_name = products[prod_index].product_name;
48814 - h->access = *(products[prod_index].access);
48815 + h->access = products[prod_index].access;
48816
48817 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48818 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48819 @@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48820
48821 assert_spin_locked(&lockup_detector_lock);
48822 remove_ctlr_from_lockup_detector_list(h);
48823 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48824 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48825 spin_lock_irqsave(&h->lock, flags);
48826 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48827 spin_unlock_irqrestore(&h->lock, flags);
48828 @@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
48829 }
48830
48831 /* make sure the board interrupts are off */
48832 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48833 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48834
48835 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48836 goto clean2;
48837 @@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
48838 * fake ones to scoop up any residual completions.
48839 */
48840 spin_lock_irqsave(&h->lock, flags);
48841 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48842 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48843 spin_unlock_irqrestore(&h->lock, flags);
48844 free_irqs(h);
48845 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48846 @@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
48847 dev_info(&h->pdev->dev, "Board READY.\n");
48848 dev_info(&h->pdev->dev,
48849 "Waiting for stale completions to drain.\n");
48850 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48851 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48852 msleep(10000);
48853 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48854 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48855
48856 rc = controller_reset_failed(h->cfgtable);
48857 if (rc)
48858 @@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
48859 }
48860
48861 /* Turn the interrupts on so we can service requests */
48862 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48863 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48864
48865 hpsa_hba_inquiry(h);
48866 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48867 @@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48868 * To write all data in the battery backed cache to disks
48869 */
48870 hpsa_flush_cache(h);
48871 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48872 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48873 hpsa_free_irqs_and_disable_msix(h);
48874 }
48875
48876 @@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48877 return;
48878 }
48879 /* Change the access methods to the performant access methods */
48880 - h->access = SA5_performant_access;
48881 + h->access = &SA5_performant_access;
48882 h->transMethod = CFGTBL_Trans_Performant;
48883 }
48884
48885 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48886 index bc85e72..d463049 100644
48887 --- a/drivers/scsi/hpsa.h
48888 +++ b/drivers/scsi/hpsa.h
48889 @@ -79,7 +79,7 @@ struct ctlr_info {
48890 unsigned int msix_vector;
48891 unsigned int msi_vector;
48892 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48893 - struct access_method access;
48894 + struct access_method *access;
48895
48896 /* queue and queue Info */
48897 struct list_head reqQ;
48898 @@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48899 }
48900
48901 static struct access_method SA5_access = {
48902 - SA5_submit_command,
48903 - SA5_intr_mask,
48904 - SA5_fifo_full,
48905 - SA5_intr_pending,
48906 - SA5_completed,
48907 + .submit_command = SA5_submit_command,
48908 + .set_intr_mask = SA5_intr_mask,
48909 + .fifo_full = SA5_fifo_full,
48910 + .intr_pending = SA5_intr_pending,
48911 + .command_completed = SA5_completed,
48912 };
48913
48914 static struct access_method SA5_performant_access = {
48915 - SA5_submit_command,
48916 - SA5_performant_intr_mask,
48917 - SA5_fifo_full,
48918 - SA5_performant_intr_pending,
48919 - SA5_performant_completed,
48920 + .submit_command = SA5_submit_command,
48921 + .set_intr_mask = SA5_performant_intr_mask,
48922 + .fifo_full = SA5_fifo_full,
48923 + .intr_pending = SA5_performant_intr_pending,
48924 + .command_completed = SA5_performant_completed,
48925 };
48926
48927 struct board_type {
48928 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48929 index 1b3a094..068e683 100644
48930 --- a/drivers/scsi/libfc/fc_exch.c
48931 +++ b/drivers/scsi/libfc/fc_exch.c
48932 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
48933 u16 pool_max_index;
48934
48935 struct {
48936 - atomic_t no_free_exch;
48937 - atomic_t no_free_exch_xid;
48938 - atomic_t xid_not_found;
48939 - atomic_t xid_busy;
48940 - atomic_t seq_not_found;
48941 - atomic_t non_bls_resp;
48942 + atomic_unchecked_t no_free_exch;
48943 + atomic_unchecked_t no_free_exch_xid;
48944 + atomic_unchecked_t xid_not_found;
48945 + atomic_unchecked_t xid_busy;
48946 + atomic_unchecked_t seq_not_found;
48947 + atomic_unchecked_t non_bls_resp;
48948 } stats;
48949 };
48950
48951 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48952 /* allocate memory for exchange */
48953 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48954 if (!ep) {
48955 - atomic_inc(&mp->stats.no_free_exch);
48956 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48957 goto out;
48958 }
48959 memset(ep, 0, sizeof(*ep));
48960 @@ -874,7 +874,7 @@ out:
48961 return ep;
48962 err:
48963 spin_unlock_bh(&pool->lock);
48964 - atomic_inc(&mp->stats.no_free_exch_xid);
48965 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48966 mempool_free(ep, mp->ep_pool);
48967 return NULL;
48968 }
48969 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48970 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48971 ep = fc_exch_find(mp, xid);
48972 if (!ep) {
48973 - atomic_inc(&mp->stats.xid_not_found);
48974 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48975 reject = FC_RJT_OX_ID;
48976 goto out;
48977 }
48978 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48979 ep = fc_exch_find(mp, xid);
48980 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48981 if (ep) {
48982 - atomic_inc(&mp->stats.xid_busy);
48983 + atomic_inc_unchecked(&mp->stats.xid_busy);
48984 reject = FC_RJT_RX_ID;
48985 goto rel;
48986 }
48987 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48988 }
48989 xid = ep->xid; /* get our XID */
48990 } else if (!ep) {
48991 - atomic_inc(&mp->stats.xid_not_found);
48992 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48993 reject = FC_RJT_RX_ID; /* XID not found */
48994 goto out;
48995 }
48996 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48997 } else {
48998 sp = &ep->seq;
48999 if (sp->id != fh->fh_seq_id) {
49000 - atomic_inc(&mp->stats.seq_not_found);
49001 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49002 if (f_ctl & FC_FC_END_SEQ) {
49003 /*
49004 * Update sequence_id based on incoming last
49005 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49006
49007 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49008 if (!ep) {
49009 - atomic_inc(&mp->stats.xid_not_found);
49010 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49011 goto out;
49012 }
49013 if (ep->esb_stat & ESB_ST_COMPLETE) {
49014 - atomic_inc(&mp->stats.xid_not_found);
49015 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49016 goto rel;
49017 }
49018 if (ep->rxid == FC_XID_UNKNOWN)
49019 ep->rxid = ntohs(fh->fh_rx_id);
49020 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49021 - atomic_inc(&mp->stats.xid_not_found);
49022 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49023 goto rel;
49024 }
49025 if (ep->did != ntoh24(fh->fh_s_id) &&
49026 ep->did != FC_FID_FLOGI) {
49027 - atomic_inc(&mp->stats.xid_not_found);
49028 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49029 goto rel;
49030 }
49031 sof = fr_sof(fp);
49032 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49033 sp->ssb_stat |= SSB_ST_RESP;
49034 sp->id = fh->fh_seq_id;
49035 } else if (sp->id != fh->fh_seq_id) {
49036 - atomic_inc(&mp->stats.seq_not_found);
49037 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49038 goto rel;
49039 }
49040
49041 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49042 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49043
49044 if (!sp)
49045 - atomic_inc(&mp->stats.xid_not_found);
49046 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49047 else
49048 - atomic_inc(&mp->stats.non_bls_resp);
49049 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
49050
49051 fc_frame_free(fp);
49052 }
49053 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49054
49055 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49056 mp = ema->mp;
49057 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49058 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49059 st->fc_no_free_exch_xid +=
49060 - atomic_read(&mp->stats.no_free_exch_xid);
49061 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49062 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49063 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49064 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49065 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49066 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49067 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49068 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49069 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49070 }
49071 }
49072 EXPORT_SYMBOL(fc_exch_update_stats);
49073 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49074 index d289583..b745eec 100644
49075 --- a/drivers/scsi/libsas/sas_ata.c
49076 +++ b/drivers/scsi/libsas/sas_ata.c
49077 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49078 .postreset = ata_std_postreset,
49079 .error_handler = ata_std_error_handler,
49080 .post_internal_cmd = sas_ata_post_internal,
49081 - .qc_defer = ata_std_qc_defer,
49082 + .qc_defer = ata_std_qc_defer,
49083 .qc_prep = ata_noop_qc_prep,
49084 .qc_issue = sas_ata_qc_issue,
49085 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49086 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49087 index 4e1b75c..0bbdfa9 100644
49088 --- a/drivers/scsi/lpfc/lpfc.h
49089 +++ b/drivers/scsi/lpfc/lpfc.h
49090 @@ -432,7 +432,7 @@ struct lpfc_vport {
49091 struct dentry *debug_nodelist;
49092 struct dentry *vport_debugfs_root;
49093 struct lpfc_debugfs_trc *disc_trc;
49094 - atomic_t disc_trc_cnt;
49095 + atomic_unchecked_t disc_trc_cnt;
49096 #endif
49097 uint8_t stat_data_enabled;
49098 uint8_t stat_data_blocked;
49099 @@ -865,8 +865,8 @@ struct lpfc_hba {
49100 struct timer_list fabric_block_timer;
49101 unsigned long bit_flags;
49102 #define FABRIC_COMANDS_BLOCKED 0
49103 - atomic_t num_rsrc_err;
49104 - atomic_t num_cmd_success;
49105 + atomic_unchecked_t num_rsrc_err;
49106 + atomic_unchecked_t num_cmd_success;
49107 unsigned long last_rsrc_error_time;
49108 unsigned long last_ramp_down_time;
49109 unsigned long last_ramp_up_time;
49110 @@ -902,7 +902,7 @@ struct lpfc_hba {
49111
49112 struct dentry *debug_slow_ring_trc;
49113 struct lpfc_debugfs_trc *slow_ring_trc;
49114 - atomic_t slow_ring_trc_cnt;
49115 + atomic_unchecked_t slow_ring_trc_cnt;
49116 /* iDiag debugfs sub-directory */
49117 struct dentry *idiag_root;
49118 struct dentry *idiag_pci_cfg;
49119 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49120 index 60084e6..0e2e700 100644
49121 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
49122 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49123 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49124
49125 #include <linux/debugfs.h>
49126
49127 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49128 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49129 static unsigned long lpfc_debugfs_start_time = 0L;
49130
49131 /* iDiag */
49132 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49133 lpfc_debugfs_enable = 0;
49134
49135 len = 0;
49136 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49137 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49138 (lpfc_debugfs_max_disc_trc - 1);
49139 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49140 dtp = vport->disc_trc + i;
49141 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49142 lpfc_debugfs_enable = 0;
49143
49144 len = 0;
49145 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49146 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49147 (lpfc_debugfs_max_slow_ring_trc - 1);
49148 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49149 dtp = phba->slow_ring_trc + i;
49150 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49151 !vport || !vport->disc_trc)
49152 return;
49153
49154 - index = atomic_inc_return(&vport->disc_trc_cnt) &
49155 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49156 (lpfc_debugfs_max_disc_trc - 1);
49157 dtp = vport->disc_trc + index;
49158 dtp->fmt = fmt;
49159 dtp->data1 = data1;
49160 dtp->data2 = data2;
49161 dtp->data3 = data3;
49162 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49163 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49164 dtp->jif = jiffies;
49165 #endif
49166 return;
49167 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49168 !phba || !phba->slow_ring_trc)
49169 return;
49170
49171 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49172 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49173 (lpfc_debugfs_max_slow_ring_trc - 1);
49174 dtp = phba->slow_ring_trc + index;
49175 dtp->fmt = fmt;
49176 dtp->data1 = data1;
49177 dtp->data2 = data2;
49178 dtp->data3 = data3;
49179 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49180 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49181 dtp->jif = jiffies;
49182 #endif
49183 return;
49184 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49185 "slow_ring buffer\n");
49186 goto debug_failed;
49187 }
49188 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49189 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49190 memset(phba->slow_ring_trc, 0,
49191 (sizeof(struct lpfc_debugfs_trc) *
49192 lpfc_debugfs_max_slow_ring_trc));
49193 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49194 "buffer\n");
49195 goto debug_failed;
49196 }
49197 - atomic_set(&vport->disc_trc_cnt, 0);
49198 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49199
49200 snprintf(name, sizeof(name), "discovery_trace");
49201 vport->debug_disc_trc =
49202 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49203 index 68c94cc..8c27be5 100644
49204 --- a/drivers/scsi/lpfc/lpfc_init.c
49205 +++ b/drivers/scsi/lpfc/lpfc_init.c
49206 @@ -10949,8 +10949,10 @@ lpfc_init(void)
49207 "misc_register returned with status %d", error);
49208
49209 if (lpfc_enable_npiv) {
49210 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49211 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49212 + pax_open_kernel();
49213 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49214 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49215 + pax_close_kernel();
49216 }
49217 lpfc_transport_template =
49218 fc_attach_transport(&lpfc_transport_functions);
49219 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49220 index b2ede05..aaf482ca 100644
49221 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49222 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49223 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49224 uint32_t evt_posted;
49225
49226 spin_lock_irqsave(&phba->hbalock, flags);
49227 - atomic_inc(&phba->num_rsrc_err);
49228 + atomic_inc_unchecked(&phba->num_rsrc_err);
49229 phba->last_rsrc_error_time = jiffies;
49230
49231 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49232 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49233 unsigned long flags;
49234 struct lpfc_hba *phba = vport->phba;
49235 uint32_t evt_posted;
49236 - atomic_inc(&phba->num_cmd_success);
49237 + atomic_inc_unchecked(&phba->num_cmd_success);
49238
49239 if (vport->cfg_lun_queue_depth <= queue_depth)
49240 return;
49241 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49242 unsigned long num_rsrc_err, num_cmd_success;
49243 int i;
49244
49245 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49246 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49247 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49248 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49249
49250 /*
49251 * The error and success command counters are global per
49252 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49253 }
49254 }
49255 lpfc_destroy_vport_work_array(phba, vports);
49256 - atomic_set(&phba->num_rsrc_err, 0);
49257 - atomic_set(&phba->num_cmd_success, 0);
49258 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49259 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49260 }
49261
49262 /**
49263 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49264 }
49265 }
49266 lpfc_destroy_vport_work_array(phba, vports);
49267 - atomic_set(&phba->num_rsrc_err, 0);
49268 - atomic_set(&phba->num_cmd_success, 0);
49269 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49270 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49271 }
49272
49273 /**
49274 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49275 index 7f0af4f..193ac3e 100644
49276 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49277 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49278 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49279 {
49280 struct scsi_device *sdev = to_scsi_device(dev);
49281 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49282 - static struct _raid_device *raid_device;
49283 + struct _raid_device *raid_device;
49284 unsigned long flags;
49285 Mpi2RaidVolPage0_t vol_pg0;
49286 Mpi2ConfigReply_t mpi_reply;
49287 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49288 {
49289 struct scsi_device *sdev = to_scsi_device(dev);
49290 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49291 - static struct _raid_device *raid_device;
49292 + struct _raid_device *raid_device;
49293 unsigned long flags;
49294 Mpi2RaidVolPage0_t vol_pg0;
49295 Mpi2ConfigReply_t mpi_reply;
49296 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49297 struct fw_event_work *fw_event)
49298 {
49299 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49300 - static struct _raid_device *raid_device;
49301 + struct _raid_device *raid_device;
49302 unsigned long flags;
49303 u16 handle;
49304
49305 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49306 u64 sas_address;
49307 struct _sas_device *sas_device;
49308 struct _sas_node *expander_device;
49309 - static struct _raid_device *raid_device;
49310 + struct _raid_device *raid_device;
49311 u8 retry_count;
49312 unsigned long flags;
49313
49314 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49315 index be8ce54..94ed33a 100644
49316 --- a/drivers/scsi/pmcraid.c
49317 +++ b/drivers/scsi/pmcraid.c
49318 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49319 res->scsi_dev = scsi_dev;
49320 scsi_dev->hostdata = res;
49321 res->change_detected = 0;
49322 - atomic_set(&res->read_failures, 0);
49323 - atomic_set(&res->write_failures, 0);
49324 + atomic_set_unchecked(&res->read_failures, 0);
49325 + atomic_set_unchecked(&res->write_failures, 0);
49326 rc = 0;
49327 }
49328 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49329 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49330
49331 /* If this was a SCSI read/write command keep count of errors */
49332 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49333 - atomic_inc(&res->read_failures);
49334 + atomic_inc_unchecked(&res->read_failures);
49335 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49336 - atomic_inc(&res->write_failures);
49337 + atomic_inc_unchecked(&res->write_failures);
49338
49339 if (!RES_IS_GSCSI(res->cfg_entry) &&
49340 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49341 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49342 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49343 * hrrq_id assigned here in queuecommand
49344 */
49345 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49346 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49347 pinstance->num_hrrq;
49348 cmd->cmd_done = pmcraid_io_done;
49349
49350 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49351 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49352 * hrrq_id assigned here in queuecommand
49353 */
49354 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49355 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49356 pinstance->num_hrrq;
49357
49358 if (request_size) {
49359 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49360
49361 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49362 /* add resources only after host is added into system */
49363 - if (!atomic_read(&pinstance->expose_resources))
49364 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49365 return;
49366
49367 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49368 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49369 init_waitqueue_head(&pinstance->reset_wait_q);
49370
49371 atomic_set(&pinstance->outstanding_cmds, 0);
49372 - atomic_set(&pinstance->last_message_id, 0);
49373 - atomic_set(&pinstance->expose_resources, 0);
49374 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49375 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49376
49377 INIT_LIST_HEAD(&pinstance->free_res_q);
49378 INIT_LIST_HEAD(&pinstance->used_res_q);
49379 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49380 /* Schedule worker thread to handle CCN and take care of adding and
49381 * removing devices to OS
49382 */
49383 - atomic_set(&pinstance->expose_resources, 1);
49384 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49385 schedule_work(&pinstance->worker_q);
49386 return rc;
49387
49388 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49389 index e1d150f..6c6df44 100644
49390 --- a/drivers/scsi/pmcraid.h
49391 +++ b/drivers/scsi/pmcraid.h
49392 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49393 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49394
49395 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49396 - atomic_t last_message_id;
49397 + atomic_unchecked_t last_message_id;
49398
49399 /* configuration table */
49400 struct pmcraid_config_table *cfg_table;
49401 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49402 atomic_t outstanding_cmds;
49403
49404 /* should add/delete resources to mid-layer now ?*/
49405 - atomic_t expose_resources;
49406 + atomic_unchecked_t expose_resources;
49407
49408
49409
49410 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49411 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49412 };
49413 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49414 - atomic_t read_failures; /* count of failed READ commands */
49415 - atomic_t write_failures; /* count of failed WRITE commands */
49416 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49417 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49418
49419 /* To indicate add/delete/modify during CCN */
49420 u8 change_detected;
49421 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49422 index 5f174b8..98d32b0 100644
49423 --- a/drivers/scsi/qla2xxx/qla_attr.c
49424 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49425 @@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49426 return 0;
49427 }
49428
49429 -struct fc_function_template qla2xxx_transport_functions = {
49430 +fc_function_template_no_const qla2xxx_transport_functions = {
49431
49432 .show_host_node_name = 1,
49433 .show_host_port_name = 1,
49434 @@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49435 .bsg_timeout = qla24xx_bsg_timeout,
49436 };
49437
49438 -struct fc_function_template qla2xxx_transport_vport_functions = {
49439 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49440
49441 .show_host_node_name = 1,
49442 .show_host_port_name = 1,
49443 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49444 index 4446bf5..9a3574d 100644
49445 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49446 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49447 @@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49448 struct device_attribute;
49449 extern struct device_attribute *qla2x00_host_attrs[];
49450 struct fc_function_template;
49451 -extern struct fc_function_template qla2xxx_transport_functions;
49452 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49453 +extern fc_function_template_no_const qla2xxx_transport_functions;
49454 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49455 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49456 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
49457 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49458 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49459 index 52be35e..b933907 100644
49460 --- a/drivers/scsi/qla2xxx/qla_os.c
49461 +++ b/drivers/scsi/qla2xxx/qla_os.c
49462 @@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49463 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49464 /* Ok, a 64bit DMA mask is applicable. */
49465 ha->flags.enable_64bit_addressing = 1;
49466 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49467 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49468 + pax_open_kernel();
49469 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49470 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49471 + pax_close_kernel();
49472 return;
49473 }
49474 }
49475 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49476 index 084d1fd..9f939eb 100644
49477 --- a/drivers/scsi/qla4xxx/ql4_def.h
49478 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49479 @@ -296,7 +296,7 @@ struct ddb_entry {
49480 * (4000 only) */
49481 atomic_t relogin_timer; /* Max Time to wait for
49482 * relogin to complete */
49483 - atomic_t relogin_retry_count; /* Num of times relogin has been
49484 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49485 * retried */
49486 uint32_t default_time2wait; /* Default Min time between
49487 * relogins (+aens) */
49488 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49489 index cf174a4..128a420 100644
49490 --- a/drivers/scsi/qla4xxx/ql4_os.c
49491 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49492 @@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49493 */
49494 if (!iscsi_is_session_online(cls_sess)) {
49495 /* Reset retry relogin timer */
49496 - atomic_inc(&ddb_entry->relogin_retry_count);
49497 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49498 DEBUG2(ql4_printk(KERN_INFO, ha,
49499 "%s: index[%d] relogin timed out-retrying"
49500 " relogin (%d), retry (%d)\n", __func__,
49501 ddb_entry->fw_ddb_index,
49502 - atomic_read(&ddb_entry->relogin_retry_count),
49503 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49504 ddb_entry->default_time2wait + 4));
49505 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49506 atomic_set(&ddb_entry->retry_relogin_timer,
49507 @@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49508
49509 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49510 atomic_set(&ddb_entry->relogin_timer, 0);
49511 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49512 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49513 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49514 ddb_entry->default_relogin_timeout =
49515 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49516 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49517 index fe0bcb1..c9255be 100644
49518 --- a/drivers/scsi/scsi.c
49519 +++ b/drivers/scsi/scsi.c
49520 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49521 struct Scsi_Host *host = cmd->device->host;
49522 int rtn = 0;
49523
49524 - atomic_inc(&cmd->device->iorequest_cnt);
49525 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49526
49527 /* check if the device is still usable */
49528 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49529 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49530 index 62ec84b..93159d8 100644
49531 --- a/drivers/scsi/scsi_lib.c
49532 +++ b/drivers/scsi/scsi_lib.c
49533 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49534 shost = sdev->host;
49535 scsi_init_cmd_errh(cmd);
49536 cmd->result = DID_NO_CONNECT << 16;
49537 - atomic_inc(&cmd->device->iorequest_cnt);
49538 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49539
49540 /*
49541 * SCSI request completion path will do scsi_device_unbusy(),
49542 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49543
49544 INIT_LIST_HEAD(&cmd->eh_entry);
49545
49546 - atomic_inc(&cmd->device->iodone_cnt);
49547 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49548 if (cmd->result)
49549 - atomic_inc(&cmd->device->ioerr_cnt);
49550 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49551
49552 disposition = scsi_decide_disposition(cmd);
49553 if (disposition != SUCCESS &&
49554 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49555 index 8ff62c2..693b6f7 100644
49556 --- a/drivers/scsi/scsi_sysfs.c
49557 +++ b/drivers/scsi/scsi_sysfs.c
49558 @@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49559 char *buf) \
49560 { \
49561 struct scsi_device *sdev = to_scsi_device(dev); \
49562 - unsigned long long count = atomic_read(&sdev->field); \
49563 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49564 return snprintf(buf, 20, "0x%llx\n", count); \
49565 } \
49566 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49567 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49568 index 84a1fdf..693b0d6 100644
49569 --- a/drivers/scsi/scsi_tgt_lib.c
49570 +++ b/drivers/scsi/scsi_tgt_lib.c
49571 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49572 int err;
49573
49574 dprintk("%lx %u\n", uaddr, len);
49575 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49576 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49577 if (err) {
49578 /*
49579 * TODO: need to fixup sg_tablesize, max_segment_size,
49580 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49581 index 4628fd5..a94a1c2 100644
49582 --- a/drivers/scsi/scsi_transport_fc.c
49583 +++ b/drivers/scsi/scsi_transport_fc.c
49584 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49585 * Netlink Infrastructure
49586 */
49587
49588 -static atomic_t fc_event_seq;
49589 +static atomic_unchecked_t fc_event_seq;
49590
49591 /**
49592 * fc_get_event_number - Obtain the next sequential FC event number
49593 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49594 u32
49595 fc_get_event_number(void)
49596 {
49597 - return atomic_add_return(1, &fc_event_seq);
49598 + return atomic_add_return_unchecked(1, &fc_event_seq);
49599 }
49600 EXPORT_SYMBOL(fc_get_event_number);
49601
49602 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49603 {
49604 int error;
49605
49606 - atomic_set(&fc_event_seq, 0);
49607 + atomic_set_unchecked(&fc_event_seq, 0);
49608
49609 error = transport_class_register(&fc_host_class);
49610 if (error)
49611 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49612 char *cp;
49613
49614 *val = simple_strtoul(buf, &cp, 0);
49615 - if ((*cp && (*cp != '\n')) || (*val < 0))
49616 + if (*cp && (*cp != '\n'))
49617 return -EINVAL;
49618 /*
49619 * Check for overflow; dev_loss_tmo is u32
49620 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49621 index 63a6ca4..5d5cadd 100644
49622 --- a/drivers/scsi/scsi_transport_iscsi.c
49623 +++ b/drivers/scsi/scsi_transport_iscsi.c
49624 @@ -79,7 +79,7 @@ struct iscsi_internal {
49625 struct transport_container session_cont;
49626 };
49627
49628 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49629 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49630 static struct workqueue_struct *iscsi_eh_timer_workq;
49631
49632 static DEFINE_IDA(iscsi_sess_ida);
49633 @@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49634 int err;
49635
49636 ihost = shost->shost_data;
49637 - session->sid = atomic_add_return(1, &iscsi_session_nr);
49638 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49639
49640 if (target_id == ISCSI_MAX_TARGET) {
49641 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49642 @@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
49643 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49644 ISCSI_TRANSPORT_VERSION);
49645
49646 - atomic_set(&iscsi_session_nr, 0);
49647 + atomic_set_unchecked(&iscsi_session_nr, 0);
49648
49649 err = class_register(&iscsi_transport_class);
49650 if (err)
49651 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49652 index 2700a5a..752ec38 100644
49653 --- a/drivers/scsi/scsi_transport_srp.c
49654 +++ b/drivers/scsi/scsi_transport_srp.c
49655 @@ -36,7 +36,7 @@
49656 #include "scsi_transport_srp_internal.h"
49657
49658 struct srp_host_attrs {
49659 - atomic_t next_port_id;
49660 + atomic_unchecked_t next_port_id;
49661 };
49662 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49663
49664 @@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49665 struct Scsi_Host *shost = dev_to_shost(dev);
49666 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49667
49668 - atomic_set(&srp_host->next_port_id, 0);
49669 + atomic_set_unchecked(&srp_host->next_port_id, 0);
49670 return 0;
49671 }
49672
49673 @@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49674 rport_fast_io_fail_timedout);
49675 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49676
49677 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49678 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49679 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49680
49681 transport_setup_device(&rport->dev);
49682 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49683 index 69725f7..03aaee1 100644
49684 --- a/drivers/scsi/sd.c
49685 +++ b/drivers/scsi/sd.c
49686 @@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
49687 sdkp->disk = gd;
49688 sdkp->index = index;
49689 atomic_set(&sdkp->openers, 0);
49690 - atomic_set(&sdkp->device->ioerr_cnt, 0);
49691 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49692
49693 if (!sdp->request_queue->rq_timeout) {
49694 if (sdp->type != TYPE_MOD)
49695 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49696 index df5e961..df6b97f 100644
49697 --- a/drivers/scsi/sg.c
49698 +++ b/drivers/scsi/sg.c
49699 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49700 sdp->disk->disk_name,
49701 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49702 NULL,
49703 - (char *)arg);
49704 + (char __user *)arg);
49705 case BLKTRACESTART:
49706 return blk_trace_startstop(sdp->device->request_queue, 1);
49707 case BLKTRACESTOP:
49708 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49709 index 349ebba..ff2a249 100644
49710 --- a/drivers/spi/spi.c
49711 +++ b/drivers/spi/spi.c
49712 @@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
49713 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49714
49715 /* portable code must never pass more than 32 bytes */
49716 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49717 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49718
49719 static u8 *buf;
49720
49721 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49722 index 2c61783..4d49e4e 100644
49723 --- a/drivers/staging/android/timed_output.c
49724 +++ b/drivers/staging/android/timed_output.c
49725 @@ -25,7 +25,7 @@
49726 #include "timed_output.h"
49727
49728 static struct class *timed_output_class;
49729 -static atomic_t device_count;
49730 +static atomic_unchecked_t device_count;
49731
49732 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49733 char *buf)
49734 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49735 timed_output_class = class_create(THIS_MODULE, "timed_output");
49736 if (IS_ERR(timed_output_class))
49737 return PTR_ERR(timed_output_class);
49738 - atomic_set(&device_count, 0);
49739 + atomic_set_unchecked(&device_count, 0);
49740 timed_output_class->dev_groups = timed_output_groups;
49741 }
49742
49743 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49744 if (ret < 0)
49745 return ret;
49746
49747 - tdev->index = atomic_inc_return(&device_count);
49748 + tdev->index = atomic_inc_return_unchecked(&device_count);
49749 tdev->dev = device_create(timed_output_class, NULL,
49750 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49751 if (IS_ERR(tdev->dev))
49752 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49753 index c0f7cd7..5424212 100644
49754 --- a/drivers/staging/gdm724x/gdm_tty.c
49755 +++ b/drivers/staging/gdm724x/gdm_tty.c
49756 @@ -45,7 +45,7 @@
49757 #define gdm_tty_send_control(n, r, v, d, l) (\
49758 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49759
49760 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49761 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49762
49763 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49764 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49765 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49766 index 96e4eee..6d7c37e 100644
49767 --- a/drivers/staging/imx-drm/imx-drm-core.c
49768 +++ b/drivers/staging/imx-drm/imx-drm-core.c
49769 @@ -510,7 +510,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49770 goto err_busy;
49771 }
49772
49773 - if (imxdrm->drm->open_count) {
49774 + if (local_read(&imxdrm->drm->open_count)) {
49775 ret = -EBUSY;
49776 goto err_busy;
49777 }
49778 @@ -590,7 +590,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49779
49780 mutex_lock(&imxdrm->mutex);
49781
49782 - if (imxdrm->drm->open_count) {
49783 + if (local_read(&imxdrm->drm->open_count)) {
49784 ret = -EBUSY;
49785 goto err_busy;
49786 }
49787 @@ -729,7 +729,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49788
49789 mutex_lock(&imxdrm->mutex);
49790
49791 - if (imxdrm->drm->open_count) {
49792 + if (local_read(&imxdrm->drm->open_count)) {
49793 ret = -EBUSY;
49794 goto err_busy;
49795 }
49796 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49797 index b7613c8..c302392 100644
49798 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49799 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49800 @@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49801 return 0;
49802 }
49803
49804 -sfw_test_client_ops_t brw_test_client;
49805 -void brw_init_test_client(void)
49806 -{
49807 - brw_test_client.tso_init = brw_client_init;
49808 - brw_test_client.tso_fini = brw_client_fini;
49809 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49810 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
49811 +sfw_test_client_ops_t brw_test_client = {
49812 + .tso_init = brw_client_init,
49813 + .tso_fini = brw_client_fini,
49814 + .tso_prep_rpc = brw_client_prep_rpc,
49815 + .tso_done_rpc = brw_client_done_rpc,
49816 };
49817
49818 srpc_service_t brw_test_service;
49819 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49820 index 483c785..e1a2a7b 100644
49821 --- a/drivers/staging/lustre/lnet/selftest/framework.c
49822 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
49823 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49824
49825 extern sfw_test_client_ops_t ping_test_client;
49826 extern srpc_service_t ping_test_service;
49827 -extern void ping_init_test_client(void);
49828 extern void ping_init_test_service(void);
49829
49830 extern sfw_test_client_ops_t brw_test_client;
49831 extern srpc_service_t brw_test_service;
49832 -extern void brw_init_test_client(void);
49833 extern void brw_init_test_service(void);
49834
49835
49836 @@ -1684,12 +1682,10 @@ sfw_startup (void)
49837 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49838 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49839
49840 - brw_init_test_client();
49841 brw_init_test_service();
49842 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49843 LASSERT (rc == 0);
49844
49845 - ping_init_test_client();
49846 ping_init_test_service();
49847 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49848 LASSERT (rc == 0);
49849 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49850 index f0f9194..b589047 100644
49851 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49852 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49853 @@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49854 return 0;
49855 }
49856
49857 -sfw_test_client_ops_t ping_test_client;
49858 -void ping_init_test_client(void)
49859 -{
49860 - ping_test_client.tso_init = ping_client_init;
49861 - ping_test_client.tso_fini = ping_client_fini;
49862 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49863 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49864 -}
49865 +sfw_test_client_ops_t ping_test_client = {
49866 + .tso_init = ping_client_init,
49867 + .tso_fini = ping_client_fini,
49868 + .tso_prep_rpc = ping_client_prep_rpc,
49869 + .tso_done_rpc = ping_client_done_rpc,
49870 +};
49871
49872 srpc_service_t ping_test_service;
49873 void ping_init_test_service(void)
49874 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49875 index bc2b82f..67fd598 100644
49876 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49877 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49878 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49879 ldlm_completion_callback lcs_completion;
49880 ldlm_blocking_callback lcs_blocking;
49881 ldlm_glimpse_callback lcs_glimpse;
49882 -};
49883 +} __no_const;
49884
49885 /* ldlm_lockd.c */
49886 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49887 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49888 index d0aea15..7af68e1 100644
49889 --- a/drivers/staging/lustre/lustre/include/obd.h
49890 +++ b/drivers/staging/lustre/lustre/include/obd.h
49891 @@ -1417,7 +1417,7 @@ struct md_ops {
49892 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49893 * wrapper function in include/linux/obd_class.h.
49894 */
49895 -};
49896 +} __no_const;
49897
49898 struct lsm_operations {
49899 void (*lsm_free)(struct lov_stripe_md *);
49900 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49901 index 39fcdac..222780f 100644
49902 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49903 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49904 @@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49905 int added = (mode == LCK_NL);
49906 int overlaps = 0;
49907 int splitted = 0;
49908 - const struct ldlm_callback_suite null_cbs = { NULL };
49909 + const struct ldlm_callback_suite null_cbs = { };
49910 int rc;
49911
49912 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49913 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49914 index fc6c977..df1f956 100644
49915 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49916 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49917 @@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49918 int LL_PROC_PROTO(proc_console_max_delay_cs)
49919 {
49920 int rc, max_delay_cs;
49921 - ctl_table_t dummy = *table;
49922 + ctl_table_no_const dummy = *table;
49923 cfs_duration_t d;
49924
49925 dummy.data = &max_delay_cs;
49926 @@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49927 int LL_PROC_PROTO(proc_console_min_delay_cs)
49928 {
49929 int rc, min_delay_cs;
49930 - ctl_table_t dummy = *table;
49931 + ctl_table_no_const dummy = *table;
49932 cfs_duration_t d;
49933
49934 dummy.data = &min_delay_cs;
49935 @@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49936 int LL_PROC_PROTO(proc_console_backoff)
49937 {
49938 int rc, backoff;
49939 - ctl_table_t dummy = *table;
49940 + ctl_table_no_const dummy = *table;
49941
49942 dummy.data = &backoff;
49943 dummy.proc_handler = &proc_dointvec;
49944 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49945 index f3108c7..cd4f9da 100644
49946 --- a/drivers/staging/lustre/lustre/libcfs/module.c
49947 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
49948 @@ -348,11 +348,11 @@ out:
49949
49950
49951 struct cfs_psdev_ops libcfs_psdev_ops = {
49952 - libcfs_psdev_open,
49953 - libcfs_psdev_release,
49954 - NULL,
49955 - NULL,
49956 - libcfs_ioctl
49957 + .p_open = libcfs_psdev_open,
49958 + .p_close = libcfs_psdev_release,
49959 + .p_read = NULL,
49960 + .p_write = NULL,
49961 + .p_ioctl = libcfs_ioctl
49962 };
49963
49964 extern int insert_proc(void);
49965 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49966 index a4e0472..05d854c 100644
49967 --- a/drivers/staging/lustre/lustre/llite/dir.c
49968 +++ b/drivers/staging/lustre/lustre/llite/dir.c
49969 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49970 int mode;
49971 int err;
49972
49973 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49974 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49975 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49976 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49977 lump);
49978 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49979 index 3675020..e80d92c 100644
49980 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
49981 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49982 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49983
49984 static int solo_sysfs_init(struct solo_dev *solo_dev)
49985 {
49986 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49987 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49988 struct device *dev = &solo_dev->dev;
49989 const char *driver;
49990 int i;
49991 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49992 index 1db18c7..35e6afc 100644
49993 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49994 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49995 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49996
49997 int solo_g723_init(struct solo_dev *solo_dev)
49998 {
49999 - static struct snd_device_ops ops = { NULL };
50000 + static struct snd_device_ops ops = { };
50001 struct snd_card *card;
50002 struct snd_kcontrol_new kctl;
50003 char name[32];
50004 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50005 index 7f2f247..d999137 100644
50006 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50007 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50008 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50009
50010 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50011 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50012 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50013 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50014 if (p2m_id < 0)
50015 p2m_id = -p2m_id;
50016 }
50017 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50018 index f1bbb8c..a73eaba 100644
50019 --- a/drivers/staging/media/solo6x10/solo6x10.h
50020 +++ b/drivers/staging/media/solo6x10/solo6x10.h
50021 @@ -237,7 +237,7 @@ struct solo_dev {
50022
50023 /* P2M DMA Engine */
50024 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50025 - atomic_t p2m_count;
50026 + atomic_unchecked_t p2m_count;
50027 int p2m_jiffies;
50028 unsigned int p2m_timeouts;
50029
50030 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50031 index 0315f60..ce93f406 100644
50032 --- a/drivers/staging/octeon/ethernet-rx.c
50033 +++ b/drivers/staging/octeon/ethernet-rx.c
50034 @@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50035 /* Increment RX stats for virtual ports */
50036 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50037 #ifdef CONFIG_64BIT
50038 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50039 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50040 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50041 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50042 #else
50043 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50044 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50045 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50046 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50047 #endif
50048 }
50049 netif_receive_skb(skb);
50050 @@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50051 dev->name);
50052 */
50053 #ifdef CONFIG_64BIT
50054 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50055 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50056 #else
50057 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50058 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50059 #endif
50060 dev_kfree_skb_irq(skb);
50061 }
50062 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50063 index bd6ca71..8f0961e 100644
50064 --- a/drivers/staging/octeon/ethernet.c
50065 +++ b/drivers/staging/octeon/ethernet.c
50066 @@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50067 * since the RX tasklet also increments it.
50068 */
50069 #ifdef CONFIG_64BIT
50070 - atomic64_add(rx_status.dropped_packets,
50071 - (atomic64_t *)&priv->stats.rx_dropped);
50072 + atomic64_add_unchecked(rx_status.dropped_packets,
50073 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50074 #else
50075 - atomic_add(rx_status.dropped_packets,
50076 - (atomic_t *)&priv->stats.rx_dropped);
50077 + atomic_add_unchecked(rx_status.dropped_packets,
50078 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
50079 #endif
50080 }
50081
50082 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50083 index 439c3c9..2d74293 100644
50084 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
50085 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50086 @@ -271,7 +271,7 @@ struct hal_ops {
50087 s32 (*c2h_handler)(struct adapter *padapter,
50088 struct c2h_evt_hdr *c2h_evt);
50089 c2h_id_filter c2h_id_filter_ccx;
50090 -};
50091 +} __no_const;
50092
50093 enum rt_eeprom_type {
50094 EEPROM_93C46,
50095 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50096 index eb6f0e5..e6a0958 100644
50097 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
50098 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50099 @@ -126,7 +126,7 @@ struct _io_ops {
50100 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
50101 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50102 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50103 -};
50104 +} __no_const;
50105
50106 struct io_req {
50107 struct list_head list;
50108 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50109 index dc23395..cf7e9b1 100644
50110 --- a/drivers/staging/rtl8712/rtl871x_io.h
50111 +++ b/drivers/staging/rtl8712/rtl871x_io.h
50112 @@ -108,7 +108,7 @@ struct _io_ops {
50113 u8 *pmem);
50114 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50115 u8 *pmem);
50116 -};
50117 +} __no_const;
50118
50119 struct io_req {
50120 struct list_head list;
50121 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50122 index 1f5088b..0e59820 100644
50123 --- a/drivers/staging/sbe-2t3e3/netdev.c
50124 +++ b/drivers/staging/sbe-2t3e3/netdev.c
50125 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50126 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50127
50128 if (rlen)
50129 - if (copy_to_user(data, &resp, rlen))
50130 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50131 return -EFAULT;
50132
50133 return 0;
50134 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50135 index a863a98..d272795 100644
50136 --- a/drivers/staging/usbip/vhci.h
50137 +++ b/drivers/staging/usbip/vhci.h
50138 @@ -83,7 +83,7 @@ struct vhci_hcd {
50139 unsigned resuming:1;
50140 unsigned long re_timeout;
50141
50142 - atomic_t seqnum;
50143 + atomic_unchecked_t seqnum;
50144
50145 /*
50146 * NOTE:
50147 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50148 index e810ad5..931336f 100644
50149 --- a/drivers/staging/usbip/vhci_hcd.c
50150 +++ b/drivers/staging/usbip/vhci_hcd.c
50151 @@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
50152
50153 spin_lock(&vdev->priv_lock);
50154
50155 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50156 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50157 if (priv->seqnum == 0xffff)
50158 dev_info(&urb->dev->dev, "seqnum max\n");
50159
50160 @@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50161 return -ENOMEM;
50162 }
50163
50164 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50165 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50166 if (unlink->seqnum == 0xffff)
50167 pr_info("seqnum max\n");
50168
50169 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
50170 vdev->rhport = rhport;
50171 }
50172
50173 - atomic_set(&vhci->seqnum, 0);
50174 + atomic_set_unchecked(&vhci->seqnum, 0);
50175 spin_lock_init(&vhci->lock);
50176
50177 hcd->power_budget = 0; /* no limit */
50178 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50179 index d07fcb5..358e1e1 100644
50180 --- a/drivers/staging/usbip/vhci_rx.c
50181 +++ b/drivers/staging/usbip/vhci_rx.c
50182 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50183 if (!urb) {
50184 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50185 pr_info("max seqnum %d\n",
50186 - atomic_read(&the_controller->seqnum));
50187 + atomic_read_unchecked(&the_controller->seqnum));
50188 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50189 return;
50190 }
50191 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50192 index ab8b2ba..99184aa 100644
50193 --- a/drivers/staging/vt6655/hostap.c
50194 +++ b/drivers/staging/vt6655/hostap.c
50195 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50196 *
50197 */
50198
50199 +static net_device_ops_no_const apdev_netdev_ops;
50200 +
50201 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50202 {
50203 PSDevice apdev_priv;
50204 struct net_device *dev = pDevice->dev;
50205 int ret;
50206 - const struct net_device_ops apdev_netdev_ops = {
50207 - .ndo_start_xmit = pDevice->tx_80211,
50208 - };
50209
50210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50211
50212 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50213 *apdev_priv = *pDevice;
50214 eth_hw_addr_inherit(pDevice->apdev, dev);
50215
50216 + /* only half broken now */
50217 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50218 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50219
50220 pDevice->apdev->type = ARPHRD_IEEE80211;
50221 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50222 index 67ba48b..24e602f 100644
50223 --- a/drivers/staging/vt6656/hostap.c
50224 +++ b/drivers/staging/vt6656/hostap.c
50225 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50226 *
50227 */
50228
50229 +static net_device_ops_no_const apdev_netdev_ops;
50230 +
50231 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50232 {
50233 struct vnt_private *apdev_priv;
50234 struct net_device *dev = pDevice->dev;
50235 int ret;
50236 - const struct net_device_ops apdev_netdev_ops = {
50237 - .ndo_start_xmit = pDevice->tx_80211,
50238 - };
50239
50240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50241
50242 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50243 *apdev_priv = *pDevice;
50244 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50245
50246 + /* only half broken now */
50247 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50248 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50249
50250 pDevice->apdev->type = ARPHRD_IEEE80211;
50251 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50252 index 24884ca..26c8220 100644
50253 --- a/drivers/target/sbp/sbp_target.c
50254 +++ b/drivers/target/sbp/sbp_target.c
50255 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50256
50257 #define SESSION_MAINTENANCE_INTERVAL HZ
50258
50259 -static atomic_t login_id = ATOMIC_INIT(0);
50260 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50261
50262 static void session_maintenance_work(struct work_struct *);
50263 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50264 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50265 login->lun = se_lun;
50266 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50267 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50268 - login->login_id = atomic_inc_return(&login_id);
50269 + login->login_id = atomic_inc_return_unchecked(&login_id);
50270
50271 login->tgt_agt = sbp_target_agent_register(login);
50272 if (IS_ERR(login->tgt_agt)) {
50273 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50274 index d06de84..fd38c9b 100644
50275 --- a/drivers/target/target_core_device.c
50276 +++ b/drivers/target/target_core_device.c
50277 @@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50278 spin_lock_init(&dev->se_tmr_lock);
50279 spin_lock_init(&dev->qf_cmd_lock);
50280 sema_init(&dev->caw_sem, 1);
50281 - atomic_set(&dev->dev_ordered_id, 0);
50282 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50283 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50284 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50285 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50286 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50287 index dee2be1..f5fd8ca 100644
50288 --- a/drivers/target/target_core_transport.c
50289 +++ b/drivers/target/target_core_transport.c
50290 @@ -1113,7 +1113,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50291 * Used to determine when ORDERED commands should go from
50292 * Dormant to Active status.
50293 */
50294 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50295 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50296 smp_mb__after_atomic_inc();
50297 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50298 cmd->se_ordered_id, cmd->sam_task_attr,
50299 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50300 index 33f83fe..d80f8e1 100644
50301 --- a/drivers/tty/cyclades.c
50302 +++ b/drivers/tty/cyclades.c
50303 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50304 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50305 info->port.count);
50306 #endif
50307 - info->port.count++;
50308 + atomic_inc(&info->port.count);
50309 #ifdef CY_DEBUG_COUNT
50310 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50311 - current->pid, info->port.count);
50312 + current->pid, atomic_read(&info->port.count));
50313 #endif
50314
50315 /*
50316 @@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50317 for (j = 0; j < cy_card[i].nports; j++) {
50318 info = &cy_card[i].ports[j];
50319
50320 - if (info->port.count) {
50321 + if (atomic_read(&info->port.count)) {
50322 /* XXX is the ldisc num worth this? */
50323 struct tty_struct *tty;
50324 struct tty_ldisc *ld;
50325 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50326 index 9eba119..5070303 100644
50327 --- a/drivers/tty/hvc/hvc_console.c
50328 +++ b/drivers/tty/hvc/hvc_console.c
50329 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50330
50331 spin_lock_irqsave(&hp->port.lock, flags);
50332 /* Check and then increment for fast path open. */
50333 - if (hp->port.count++ > 0) {
50334 + if (atomic_inc_return(&hp->port.count) > 1) {
50335 spin_unlock_irqrestore(&hp->port.lock, flags);
50336 hvc_kick();
50337 return 0;
50338 @@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50339
50340 spin_lock_irqsave(&hp->port.lock, flags);
50341
50342 - if (--hp->port.count == 0) {
50343 + if (atomic_dec_return(&hp->port.count) == 0) {
50344 spin_unlock_irqrestore(&hp->port.lock, flags);
50345 /* We are done with the tty pointer now. */
50346 tty_port_tty_set(&hp->port, NULL);
50347 @@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50348 */
50349 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50350 } else {
50351 - if (hp->port.count < 0)
50352 + if (atomic_read(&hp->port.count) < 0)
50353 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50354 - hp->vtermno, hp->port.count);
50355 + hp->vtermno, atomic_read(&hp->port.count));
50356 spin_unlock_irqrestore(&hp->port.lock, flags);
50357 }
50358 }
50359 @@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
50360 * open->hangup case this can be called after the final close so prevent
50361 * that from happening for now.
50362 */
50363 - if (hp->port.count <= 0) {
50364 + if (atomic_read(&hp->port.count) <= 0) {
50365 spin_unlock_irqrestore(&hp->port.lock, flags);
50366 return;
50367 }
50368
50369 - hp->port.count = 0;
50370 + atomic_set(&hp->port.count, 0);
50371 spin_unlock_irqrestore(&hp->port.lock, flags);
50372 tty_port_tty_set(&hp->port, NULL);
50373
50374 @@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50375 return -EPIPE;
50376
50377 /* FIXME what's this (unprotected) check for? */
50378 - if (hp->port.count <= 0)
50379 + if (atomic_read(&hp->port.count) <= 0)
50380 return -EIO;
50381
50382 spin_lock_irqsave(&hp->lock, flags);
50383 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50384 index 81e939e..95ead10 100644
50385 --- a/drivers/tty/hvc/hvcs.c
50386 +++ b/drivers/tty/hvc/hvcs.c
50387 @@ -83,6 +83,7 @@
50388 #include <asm/hvcserver.h>
50389 #include <asm/uaccess.h>
50390 #include <asm/vio.h>
50391 +#include <asm/local.h>
50392
50393 /*
50394 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50395 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50396
50397 spin_lock_irqsave(&hvcsd->lock, flags);
50398
50399 - if (hvcsd->port.count > 0) {
50400 + if (atomic_read(&hvcsd->port.count) > 0) {
50401 spin_unlock_irqrestore(&hvcsd->lock, flags);
50402 printk(KERN_INFO "HVCS: vterm state unchanged. "
50403 "The hvcs device node is still in use.\n");
50404 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50405 }
50406 }
50407
50408 - hvcsd->port.count = 0;
50409 + atomic_set(&hvcsd->port.count, 0);
50410 hvcsd->port.tty = tty;
50411 tty->driver_data = hvcsd;
50412
50413 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50414 unsigned long flags;
50415
50416 spin_lock_irqsave(&hvcsd->lock, flags);
50417 - hvcsd->port.count++;
50418 + atomic_inc(&hvcsd->port.count);
50419 hvcsd->todo_mask |= HVCS_SCHED_READ;
50420 spin_unlock_irqrestore(&hvcsd->lock, flags);
50421
50422 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50423 hvcsd = tty->driver_data;
50424
50425 spin_lock_irqsave(&hvcsd->lock, flags);
50426 - if (--hvcsd->port.count == 0) {
50427 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50428
50429 vio_disable_interrupts(hvcsd->vdev);
50430
50431 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50432
50433 free_irq(irq, hvcsd);
50434 return;
50435 - } else if (hvcsd->port.count < 0) {
50436 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50437 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50438 " is missmanaged.\n",
50439 - hvcsd->vdev->unit_address, hvcsd->port.count);
50440 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50441 }
50442
50443 spin_unlock_irqrestore(&hvcsd->lock, flags);
50444 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50445
50446 spin_lock_irqsave(&hvcsd->lock, flags);
50447 /* Preserve this so that we know how many kref refs to put */
50448 - temp_open_count = hvcsd->port.count;
50449 + temp_open_count = atomic_read(&hvcsd->port.count);
50450
50451 /*
50452 * Don't kref put inside the spinlock because the destruction
50453 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50454 tty->driver_data = NULL;
50455 hvcsd->port.tty = NULL;
50456
50457 - hvcsd->port.count = 0;
50458 + atomic_set(&hvcsd->port.count, 0);
50459
50460 /* This will drop any buffered data on the floor which is OK in a hangup
50461 * scenario. */
50462 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50463 * the middle of a write operation? This is a crummy place to do this
50464 * but we want to keep it all in the spinlock.
50465 */
50466 - if (hvcsd->port.count <= 0) {
50467 + if (atomic_read(&hvcsd->port.count) <= 0) {
50468 spin_unlock_irqrestore(&hvcsd->lock, flags);
50469 return -ENODEV;
50470 }
50471 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50472 {
50473 struct hvcs_struct *hvcsd = tty->driver_data;
50474
50475 - if (!hvcsd || hvcsd->port.count <= 0)
50476 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50477 return 0;
50478
50479 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50480 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50481 index 4190199..06d5bfa 100644
50482 --- a/drivers/tty/hvc/hvsi.c
50483 +++ b/drivers/tty/hvc/hvsi.c
50484 @@ -85,7 +85,7 @@ struct hvsi_struct {
50485 int n_outbuf;
50486 uint32_t vtermno;
50487 uint32_t virq;
50488 - atomic_t seqno; /* HVSI packet sequence number */
50489 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50490 uint16_t mctrl;
50491 uint8_t state; /* HVSI protocol state */
50492 uint8_t flags;
50493 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50494
50495 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50496 packet.hdr.len = sizeof(struct hvsi_query_response);
50497 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50498 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50499 packet.verb = VSV_SEND_VERSION_NUMBER;
50500 packet.u.version = HVSI_VERSION;
50501 packet.query_seqno = query_seqno+1;
50502 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50503
50504 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50505 packet.hdr.len = sizeof(struct hvsi_query);
50506 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50507 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50508 packet.verb = verb;
50509
50510 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50511 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50512 int wrote;
50513
50514 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50515 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50516 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50517 packet.hdr.len = sizeof(struct hvsi_control);
50518 packet.verb = VSV_SET_MODEM_CTL;
50519 packet.mask = HVSI_TSDTR;
50520 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50521 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50522
50523 packet.hdr.type = VS_DATA_PACKET_HEADER;
50524 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50525 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50526 packet.hdr.len = count + sizeof(struct hvsi_header);
50527 memcpy(&packet.data, buf, count);
50528
50529 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50530 struct hvsi_control packet __ALIGNED__;
50531
50532 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50533 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50534 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50535 packet.hdr.len = 6;
50536 packet.verb = VSV_CLOSE_PROTOCOL;
50537
50538 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50539
50540 tty_port_tty_set(&hp->port, tty);
50541 spin_lock_irqsave(&hp->lock, flags);
50542 - hp->port.count++;
50543 + atomic_inc(&hp->port.count);
50544 atomic_set(&hp->seqno, 0);
50545 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50546 spin_unlock_irqrestore(&hp->lock, flags);
50547 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50548
50549 spin_lock_irqsave(&hp->lock, flags);
50550
50551 - if (--hp->port.count == 0) {
50552 + if (atomic_dec_return(&hp->port.count) == 0) {
50553 tty_port_tty_set(&hp->port, NULL);
50554 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50555
50556 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50557
50558 spin_lock_irqsave(&hp->lock, flags);
50559 }
50560 - } else if (hp->port.count < 0)
50561 + } else if (atomic_read(&hp->port.count) < 0)
50562 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50563 - hp - hvsi_ports, hp->port.count);
50564 + hp - hvsi_ports, atomic_read(&hp->port.count));
50565
50566 spin_unlock_irqrestore(&hp->lock, flags);
50567 }
50568 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50569 tty_port_tty_set(&hp->port, NULL);
50570
50571 spin_lock_irqsave(&hp->lock, flags);
50572 - hp->port.count = 0;
50573 + atomic_set(&hp->port.count, 0);
50574 hp->n_outbuf = 0;
50575 spin_unlock_irqrestore(&hp->lock, flags);
50576 }
50577 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50578 index 347050e..14f8fbf 100644
50579 --- a/drivers/tty/hvc/hvsi_lib.c
50580 +++ b/drivers/tty/hvc/hvsi_lib.c
50581 @@ -9,7 +9,7 @@
50582
50583 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50584 {
50585 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50586 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50587
50588 /* Assumes that always succeeds, works in practice */
50589 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50590 @@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50591
50592 /* Reset state */
50593 pv->established = 0;
50594 - atomic_set(&pv->seqno, 0);
50595 + atomic_set_unchecked(&pv->seqno, 0);
50596
50597 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50598
50599 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50600 index 8fd72ff..34a0bed 100644
50601 --- a/drivers/tty/ipwireless/tty.c
50602 +++ b/drivers/tty/ipwireless/tty.c
50603 @@ -29,6 +29,7 @@
50604 #include <linux/tty_driver.h>
50605 #include <linux/tty_flip.h>
50606 #include <linux/uaccess.h>
50607 +#include <asm/local.h>
50608
50609 #include "tty.h"
50610 #include "network.h"
50611 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50612 mutex_unlock(&tty->ipw_tty_mutex);
50613 return -ENODEV;
50614 }
50615 - if (tty->port.count == 0)
50616 + if (atomic_read(&tty->port.count) == 0)
50617 tty->tx_bytes_queued = 0;
50618
50619 - tty->port.count++;
50620 + atomic_inc(&tty->port.count);
50621
50622 tty->port.tty = linux_tty;
50623 linux_tty->driver_data = tty;
50624 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50625
50626 static void do_ipw_close(struct ipw_tty *tty)
50627 {
50628 - tty->port.count--;
50629 -
50630 - if (tty->port.count == 0) {
50631 + if (atomic_dec_return(&tty->port.count) == 0) {
50632 struct tty_struct *linux_tty = tty->port.tty;
50633
50634 if (linux_tty != NULL) {
50635 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50636 return;
50637
50638 mutex_lock(&tty->ipw_tty_mutex);
50639 - if (tty->port.count == 0) {
50640 + if (atomic_read(&tty->port.count) == 0) {
50641 mutex_unlock(&tty->ipw_tty_mutex);
50642 return;
50643 }
50644 @@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50645
50646 mutex_lock(&tty->ipw_tty_mutex);
50647
50648 - if (!tty->port.count) {
50649 + if (!atomic_read(&tty->port.count)) {
50650 mutex_unlock(&tty->ipw_tty_mutex);
50651 return;
50652 }
50653 @@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50654 return -ENODEV;
50655
50656 mutex_lock(&tty->ipw_tty_mutex);
50657 - if (!tty->port.count) {
50658 + if (!atomic_read(&tty->port.count)) {
50659 mutex_unlock(&tty->ipw_tty_mutex);
50660 return -EINVAL;
50661 }
50662 @@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50663 if (!tty)
50664 return -ENODEV;
50665
50666 - if (!tty->port.count)
50667 + if (!atomic_read(&tty->port.count))
50668 return -EINVAL;
50669
50670 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50671 @@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50672 if (!tty)
50673 return 0;
50674
50675 - if (!tty->port.count)
50676 + if (!atomic_read(&tty->port.count))
50677 return 0;
50678
50679 return tty->tx_bytes_queued;
50680 @@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50681 if (!tty)
50682 return -ENODEV;
50683
50684 - if (!tty->port.count)
50685 + if (!atomic_read(&tty->port.count))
50686 return -EINVAL;
50687
50688 return get_control_lines(tty);
50689 @@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50690 if (!tty)
50691 return -ENODEV;
50692
50693 - if (!tty->port.count)
50694 + if (!atomic_read(&tty->port.count))
50695 return -EINVAL;
50696
50697 return set_control_lines(tty, set, clear);
50698 @@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50699 if (!tty)
50700 return -ENODEV;
50701
50702 - if (!tty->port.count)
50703 + if (!atomic_read(&tty->port.count))
50704 return -EINVAL;
50705
50706 /* FIXME: Exactly how is the tty object locked here .. */
50707 @@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50708 * are gone */
50709 mutex_lock(&ttyj->ipw_tty_mutex);
50710 }
50711 - while (ttyj->port.count)
50712 + while (atomic_read(&ttyj->port.count))
50713 do_ipw_close(ttyj);
50714 ipwireless_disassociate_network_ttys(network,
50715 ttyj->channel_idx);
50716 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50717 index 1deaca4..c8582d4 100644
50718 --- a/drivers/tty/moxa.c
50719 +++ b/drivers/tty/moxa.c
50720 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50721 }
50722
50723 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50724 - ch->port.count++;
50725 + atomic_inc(&ch->port.count);
50726 tty->driver_data = ch;
50727 tty_port_tty_set(&ch->port, tty);
50728 mutex_lock(&ch->port.mutex);
50729 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50730 index 5056090..c80ca04 100644
50731 --- a/drivers/tty/n_gsm.c
50732 +++ b/drivers/tty/n_gsm.c
50733 @@ -1643,7 +1643,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50734 spin_lock_init(&dlci->lock);
50735 mutex_init(&dlci->mutex);
50736 dlci->fifo = &dlci->_fifo;
50737 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50738 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50739 kfree(dlci);
50740 return NULL;
50741 }
50742 @@ -2946,7 +2946,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50743 struct gsm_dlci *dlci = tty->driver_data;
50744 struct tty_port *port = &dlci->port;
50745
50746 - port->count++;
50747 + atomic_inc(&port->count);
50748 dlci_get(dlci);
50749 dlci_get(dlci->gsm->dlci[0]);
50750 mux_get(dlci->gsm);
50751 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50752 index 4c10837..a40ec45 100644
50753 --- a/drivers/tty/n_tty.c
50754 +++ b/drivers/tty/n_tty.c
50755 @@ -114,7 +114,7 @@ struct n_tty_data {
50756 int minimum_to_wake;
50757
50758 /* consumer-published */
50759 - size_t read_tail;
50760 + size_t read_tail __intentional_overflow(-1);
50761 size_t line_start;
50762
50763 /* protected by output lock */
50764 @@ -2504,6 +2504,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50765 {
50766 *ops = tty_ldisc_N_TTY;
50767 ops->owner = NULL;
50768 - ops->refcount = ops->flags = 0;
50769 + atomic_set(&ops->refcount, 0);
50770 + ops->flags = 0;
50771 }
50772 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50773 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50774 index 25c9bc7..24077b7 100644
50775 --- a/drivers/tty/pty.c
50776 +++ b/drivers/tty/pty.c
50777 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50778 panic("Couldn't register Unix98 pts driver");
50779
50780 /* Now create the /dev/ptmx special device */
50781 + pax_open_kernel();
50782 tty_default_fops(&ptmx_fops);
50783 - ptmx_fops.open = ptmx_open;
50784 + *(void **)&ptmx_fops.open = ptmx_open;
50785 + pax_close_kernel();
50786
50787 cdev_init(&ptmx_cdev, &ptmx_fops);
50788 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50789 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50790 index 354564e..fe50d9a 100644
50791 --- a/drivers/tty/rocket.c
50792 +++ b/drivers/tty/rocket.c
50793 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50794 tty->driver_data = info;
50795 tty_port_tty_set(port, tty);
50796
50797 - if (port->count++ == 0) {
50798 + if (atomic_inc_return(&port->count) == 1) {
50799 atomic_inc(&rp_num_ports_open);
50800
50801 #ifdef ROCKET_DEBUG_OPEN
50802 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50803 #endif
50804 }
50805 #ifdef ROCKET_DEBUG_OPEN
50806 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50807 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50808 #endif
50809
50810 /*
50811 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50812 spin_unlock_irqrestore(&info->port.lock, flags);
50813 return;
50814 }
50815 - if (info->port.count)
50816 + if (atomic_read(&info->port.count))
50817 atomic_dec(&rp_num_ports_open);
50818 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50819 spin_unlock_irqrestore(&info->port.lock, flags);
50820 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50821 index 1274499..f541382 100644
50822 --- a/drivers/tty/serial/ioc4_serial.c
50823 +++ b/drivers/tty/serial/ioc4_serial.c
50824 @@ -437,7 +437,7 @@ struct ioc4_soft {
50825 } is_intr_info[MAX_IOC4_INTR_ENTS];
50826
50827 /* Number of entries active in the above array */
50828 - atomic_t is_num_intrs;
50829 + atomic_unchecked_t is_num_intrs;
50830 } is_intr_type[IOC4_NUM_INTR_TYPES];
50831
50832 /* is_ir_lock must be held while
50833 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50834 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50835 || (type == IOC4_OTHER_INTR_TYPE)));
50836
50837 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50838 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50839 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50840
50841 /* Save off the lower level interrupt handler */
50842 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50843
50844 soft = arg;
50845 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50846 - num_intrs = (int)atomic_read(
50847 + num_intrs = (int)atomic_read_unchecked(
50848 &soft->is_intr_type[intr_type].is_num_intrs);
50849
50850 this_mir = this_ir = pending_intrs(soft, intr_type);
50851 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50852 index a260cde..6b2b5ce 100644
50853 --- a/drivers/tty/serial/kgdboc.c
50854 +++ b/drivers/tty/serial/kgdboc.c
50855 @@ -24,8 +24,9 @@
50856 #define MAX_CONFIG_LEN 40
50857
50858 static struct kgdb_io kgdboc_io_ops;
50859 +static struct kgdb_io kgdboc_io_ops_console;
50860
50861 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50862 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50863 static int configured = -1;
50864
50865 static char config[MAX_CONFIG_LEN];
50866 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50867 kgdboc_unregister_kbd();
50868 if (configured == 1)
50869 kgdb_unregister_io_module(&kgdboc_io_ops);
50870 + else if (configured == 2)
50871 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
50872 }
50873
50874 static int configure_kgdboc(void)
50875 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50876 int err;
50877 char *cptr = config;
50878 struct console *cons;
50879 + int is_console = 0;
50880
50881 err = kgdboc_option_setup(config);
50882 if (err || !strlen(config) || isspace(config[0]))
50883 goto noconfig;
50884
50885 err = -ENODEV;
50886 - kgdboc_io_ops.is_console = 0;
50887 kgdb_tty_driver = NULL;
50888
50889 kgdboc_use_kms = 0;
50890 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50891 int idx;
50892 if (cons->device && cons->device(cons, &idx) == p &&
50893 idx == tty_line) {
50894 - kgdboc_io_ops.is_console = 1;
50895 + is_console = 1;
50896 break;
50897 }
50898 cons = cons->next;
50899 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50900 kgdb_tty_line = tty_line;
50901
50902 do_register:
50903 - err = kgdb_register_io_module(&kgdboc_io_ops);
50904 + if (is_console) {
50905 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
50906 + configured = 2;
50907 + } else {
50908 + err = kgdb_register_io_module(&kgdboc_io_ops);
50909 + configured = 1;
50910 + }
50911 if (err)
50912 goto noconfig;
50913
50914 @@ -205,8 +214,6 @@ do_register:
50915 if (err)
50916 goto nmi_con_failed;
50917
50918 - configured = 1;
50919 -
50920 return 0;
50921
50922 nmi_con_failed:
50923 @@ -223,7 +230,7 @@ noconfig:
50924 static int __init init_kgdboc(void)
50925 {
50926 /* Already configured? */
50927 - if (configured == 1)
50928 + if (configured >= 1)
50929 return 0;
50930
50931 return configure_kgdboc();
50932 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50933 if (config[len - 1] == '\n')
50934 config[len - 1] = '\0';
50935
50936 - if (configured == 1)
50937 + if (configured >= 1)
50938 cleanup_kgdboc();
50939
50940 /* Go and configure with the new params. */
50941 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50942 .post_exception = kgdboc_post_exp_handler,
50943 };
50944
50945 +static struct kgdb_io kgdboc_io_ops_console = {
50946 + .name = "kgdboc",
50947 + .read_char = kgdboc_get_char,
50948 + .write_char = kgdboc_put_char,
50949 + .pre_exception = kgdboc_pre_exp_handler,
50950 + .post_exception = kgdboc_post_exp_handler,
50951 + .is_console = 1
50952 +};
50953 +
50954 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50955 /* This is only available if kgdboc is a built in for early debugging */
50956 static int __init kgdboc_early_init(char *opt)
50957 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50958 index b5d779c..3622cfe 100644
50959 --- a/drivers/tty/serial/msm_serial.c
50960 +++ b/drivers/tty/serial/msm_serial.c
50961 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50962 .cons = MSM_CONSOLE,
50963 };
50964
50965 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50966 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50967
50968 static const struct of_device_id msm_uartdm_table[] = {
50969 { .compatible = "qcom,msm-uartdm" },
50970 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50971 int irq;
50972
50973 if (pdev->id == -1)
50974 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50975 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50976
50977 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50978 return -ENXIO;
50979 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50980 index c1af04d..0815c8a 100644
50981 --- a/drivers/tty/serial/samsung.c
50982 +++ b/drivers/tty/serial/samsung.c
50983 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50984 }
50985 }
50986
50987 +static int s3c64xx_serial_startup(struct uart_port *port);
50988 static int s3c24xx_serial_startup(struct uart_port *port)
50989 {
50990 struct s3c24xx_uart_port *ourport = to_ourport(port);
50991 int ret;
50992
50993 + /* Startup sequence is different for s3c64xx and higher SoC's */
50994 + if (s3c24xx_serial_has_interrupt_mask(port))
50995 + return s3c64xx_serial_startup(port);
50996 +
50997 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50998 port->mapbase, port->membase);
50999
51000 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51001 /* setup info for port */
51002 port->dev = &platdev->dev;
51003
51004 - /* Startup sequence is different for s3c64xx and higher SoC's */
51005 - if (s3c24xx_serial_has_interrupt_mask(port))
51006 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51007 -
51008 port->uartclk = 1;
51009
51010 if (cfg->uart_flags & UPF_CONS_FLOW) {
51011 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51012 index 0f02351..07c59c5 100644
51013 --- a/drivers/tty/serial/serial_core.c
51014 +++ b/drivers/tty/serial/serial_core.c
51015 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
51016 uart_flush_buffer(tty);
51017 uart_shutdown(tty, state);
51018 spin_lock_irqsave(&port->lock, flags);
51019 - port->count = 0;
51020 + atomic_set(&port->count, 0);
51021 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51022 spin_unlock_irqrestore(&port->lock, flags);
51023 tty_port_tty_set(port, NULL);
51024 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51025 goto end;
51026 }
51027
51028 - port->count++;
51029 + atomic_inc(&port->count);
51030 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51031 retval = -ENXIO;
51032 goto err_dec_count;
51033 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51034 /*
51035 * Make sure the device is in D0 state.
51036 */
51037 - if (port->count == 1)
51038 + if (atomic_read(&port->count) == 1)
51039 uart_change_pm(state, UART_PM_STATE_ON);
51040
51041 /*
51042 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51043 end:
51044 return retval;
51045 err_dec_count:
51046 - port->count--;
51047 + atomic_inc(&port->count);
51048 mutex_unlock(&port->mutex);
51049 goto end;
51050 }
51051 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51052 index e1ce141..6d4ed80 100644
51053 --- a/drivers/tty/synclink.c
51054 +++ b/drivers/tty/synclink.c
51055 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51056
51057 if (debug_level >= DEBUG_LEVEL_INFO)
51058 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51059 - __FILE__,__LINE__, info->device_name, info->port.count);
51060 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51061
51062 if (tty_port_close_start(&info->port, tty, filp) == 0)
51063 goto cleanup;
51064 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51065 cleanup:
51066 if (debug_level >= DEBUG_LEVEL_INFO)
51067 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51068 - tty->driver->name, info->port.count);
51069 + tty->driver->name, atomic_read(&info->port.count));
51070
51071 } /* end of mgsl_close() */
51072
51073 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51074
51075 mgsl_flush_buffer(tty);
51076 shutdown(info);
51077 -
51078 - info->port.count = 0;
51079 +
51080 + atomic_set(&info->port.count, 0);
51081 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51082 info->port.tty = NULL;
51083
51084 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51085
51086 if (debug_level >= DEBUG_LEVEL_INFO)
51087 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51088 - __FILE__,__LINE__, tty->driver->name, port->count );
51089 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51090
51091 spin_lock_irqsave(&info->irq_spinlock, flags);
51092 if (!tty_hung_up_p(filp)) {
51093 extra_count = true;
51094 - port->count--;
51095 + atomic_dec(&port->count);
51096 }
51097 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51098 port->blocked_open++;
51099 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51100
51101 if (debug_level >= DEBUG_LEVEL_INFO)
51102 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51103 - __FILE__,__LINE__, tty->driver->name, port->count );
51104 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51105
51106 tty_unlock(tty);
51107 schedule();
51108 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51109
51110 /* FIXME: Racy on hangup during close wait */
51111 if (extra_count)
51112 - port->count++;
51113 + atomic_inc(&port->count);
51114 port->blocked_open--;
51115
51116 if (debug_level >= DEBUG_LEVEL_INFO)
51117 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51118 - __FILE__,__LINE__, tty->driver->name, port->count );
51119 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51120
51121 if (!retval)
51122 port->flags |= ASYNC_NORMAL_ACTIVE;
51123 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51124
51125 if (debug_level >= DEBUG_LEVEL_INFO)
51126 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51127 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51128 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51129
51130 /* If port is closing, signal caller to try again */
51131 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51132 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51133 spin_unlock_irqrestore(&info->netlock, flags);
51134 goto cleanup;
51135 }
51136 - info->port.count++;
51137 + atomic_inc(&info->port.count);
51138 spin_unlock_irqrestore(&info->netlock, flags);
51139
51140 - if (info->port.count == 1) {
51141 + if (atomic_read(&info->port.count) == 1) {
51142 /* 1st open on this device, init hardware */
51143 retval = startup(info);
51144 if (retval < 0)
51145 @@ -3446,8 +3446,8 @@ cleanup:
51146 if (retval) {
51147 if (tty->count == 1)
51148 info->port.tty = NULL; /* tty layer will release tty struct */
51149 - if(info->port.count)
51150 - info->port.count--;
51151 + if (atomic_read(&info->port.count))
51152 + atomic_dec(&info->port.count);
51153 }
51154
51155 return retval;
51156 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51157 unsigned short new_crctype;
51158
51159 /* return error if TTY interface open */
51160 - if (info->port.count)
51161 + if (atomic_read(&info->port.count))
51162 return -EBUSY;
51163
51164 switch (encoding)
51165 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51166
51167 /* arbitrate between network and tty opens */
51168 spin_lock_irqsave(&info->netlock, flags);
51169 - if (info->port.count != 0 || info->netcount != 0) {
51170 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51171 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51172 spin_unlock_irqrestore(&info->netlock, flags);
51173 return -EBUSY;
51174 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51175 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51176
51177 /* return error if TTY interface open */
51178 - if (info->port.count)
51179 + if (atomic_read(&info->port.count))
51180 return -EBUSY;
51181
51182 if (cmd != SIOCWANDEV)
51183 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51184 index 1abf946..1ee34fc 100644
51185 --- a/drivers/tty/synclink_gt.c
51186 +++ b/drivers/tty/synclink_gt.c
51187 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51188 tty->driver_data = info;
51189 info->port.tty = tty;
51190
51191 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51192 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51193
51194 /* If port is closing, signal caller to try again */
51195 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51196 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51197 mutex_unlock(&info->port.mutex);
51198 goto cleanup;
51199 }
51200 - info->port.count++;
51201 + atomic_inc(&info->port.count);
51202 spin_unlock_irqrestore(&info->netlock, flags);
51203
51204 - if (info->port.count == 1) {
51205 + if (atomic_read(&info->port.count) == 1) {
51206 /* 1st open on this device, init hardware */
51207 retval = startup(info);
51208 if (retval < 0) {
51209 @@ -715,8 +715,8 @@ cleanup:
51210 if (retval) {
51211 if (tty->count == 1)
51212 info->port.tty = NULL; /* tty layer will release tty struct */
51213 - if(info->port.count)
51214 - info->port.count--;
51215 + if(atomic_read(&info->port.count))
51216 + atomic_dec(&info->port.count);
51217 }
51218
51219 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51220 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51221
51222 if (sanity_check(info, tty->name, "close"))
51223 return;
51224 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51225 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51226
51227 if (tty_port_close_start(&info->port, tty, filp) == 0)
51228 goto cleanup;
51229 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51230 tty_port_close_end(&info->port, tty);
51231 info->port.tty = NULL;
51232 cleanup:
51233 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51234 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51235 }
51236
51237 static void hangup(struct tty_struct *tty)
51238 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51239 shutdown(info);
51240
51241 spin_lock_irqsave(&info->port.lock, flags);
51242 - info->port.count = 0;
51243 + atomic_set(&info->port.count, 0);
51244 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51245 info->port.tty = NULL;
51246 spin_unlock_irqrestore(&info->port.lock, flags);
51247 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51248 unsigned short new_crctype;
51249
51250 /* return error if TTY interface open */
51251 - if (info->port.count)
51252 + if (atomic_read(&info->port.count))
51253 return -EBUSY;
51254
51255 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51256 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51257
51258 /* arbitrate between network and tty opens */
51259 spin_lock_irqsave(&info->netlock, flags);
51260 - if (info->port.count != 0 || info->netcount != 0) {
51261 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51262 DBGINFO(("%s hdlc_open busy\n", dev->name));
51263 spin_unlock_irqrestore(&info->netlock, flags);
51264 return -EBUSY;
51265 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51266 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51267
51268 /* return error if TTY interface open */
51269 - if (info->port.count)
51270 + if (atomic_read(&info->port.count))
51271 return -EBUSY;
51272
51273 if (cmd != SIOCWANDEV)
51274 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51275 if (port == NULL)
51276 continue;
51277 spin_lock(&port->lock);
51278 - if ((port->port.count || port->netcount) &&
51279 + if ((atomic_read(&port->port.count) || port->netcount) &&
51280 port->pending_bh && !port->bh_running &&
51281 !port->bh_requested) {
51282 DBGISR(("%s bh queued\n", port->device_name));
51283 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51284 spin_lock_irqsave(&info->lock, flags);
51285 if (!tty_hung_up_p(filp)) {
51286 extra_count = true;
51287 - port->count--;
51288 + atomic_dec(&port->count);
51289 }
51290 spin_unlock_irqrestore(&info->lock, flags);
51291 port->blocked_open++;
51292 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51293 remove_wait_queue(&port->open_wait, &wait);
51294
51295 if (extra_count)
51296 - port->count++;
51297 + atomic_inc(&port->count);
51298 port->blocked_open--;
51299
51300 if (!retval)
51301 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51302 index dc6e969..5dc8786 100644
51303 --- a/drivers/tty/synclinkmp.c
51304 +++ b/drivers/tty/synclinkmp.c
51305 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51306
51307 if (debug_level >= DEBUG_LEVEL_INFO)
51308 printk("%s(%d):%s open(), old ref count = %d\n",
51309 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51310 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51311
51312 /* If port is closing, signal caller to try again */
51313 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51314 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51315 spin_unlock_irqrestore(&info->netlock, flags);
51316 goto cleanup;
51317 }
51318 - info->port.count++;
51319 + atomic_inc(&info->port.count);
51320 spin_unlock_irqrestore(&info->netlock, flags);
51321
51322 - if (info->port.count == 1) {
51323 + if (atomic_read(&info->port.count) == 1) {
51324 /* 1st open on this device, init hardware */
51325 retval = startup(info);
51326 if (retval < 0)
51327 @@ -796,8 +796,8 @@ cleanup:
51328 if (retval) {
51329 if (tty->count == 1)
51330 info->port.tty = NULL; /* tty layer will release tty struct */
51331 - if(info->port.count)
51332 - info->port.count--;
51333 + if(atomic_read(&info->port.count))
51334 + atomic_dec(&info->port.count);
51335 }
51336
51337 return retval;
51338 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51339
51340 if (debug_level >= DEBUG_LEVEL_INFO)
51341 printk("%s(%d):%s close() entry, count=%d\n",
51342 - __FILE__,__LINE__, info->device_name, info->port.count);
51343 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51344
51345 if (tty_port_close_start(&info->port, tty, filp) == 0)
51346 goto cleanup;
51347 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51348 cleanup:
51349 if (debug_level >= DEBUG_LEVEL_INFO)
51350 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51351 - tty->driver->name, info->port.count);
51352 + tty->driver->name, atomic_read(&info->port.count));
51353 }
51354
51355 /* Called by tty_hangup() when a hangup is signaled.
51356 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51357 shutdown(info);
51358
51359 spin_lock_irqsave(&info->port.lock, flags);
51360 - info->port.count = 0;
51361 + atomic_set(&info->port.count, 0);
51362 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51363 info->port.tty = NULL;
51364 spin_unlock_irqrestore(&info->port.lock, flags);
51365 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51366 unsigned short new_crctype;
51367
51368 /* return error if TTY interface open */
51369 - if (info->port.count)
51370 + if (atomic_read(&info->port.count))
51371 return -EBUSY;
51372
51373 switch (encoding)
51374 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51375
51376 /* arbitrate between network and tty opens */
51377 spin_lock_irqsave(&info->netlock, flags);
51378 - if (info->port.count != 0 || info->netcount != 0) {
51379 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51380 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51381 spin_unlock_irqrestore(&info->netlock, flags);
51382 return -EBUSY;
51383 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51384 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51385
51386 /* return error if TTY interface open */
51387 - if (info->port.count)
51388 + if (atomic_read(&info->port.count))
51389 return -EBUSY;
51390
51391 if (cmd != SIOCWANDEV)
51392 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51393 * do not request bottom half processing if the
51394 * device is not open in a normal mode.
51395 */
51396 - if ( port && (port->port.count || port->netcount) &&
51397 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51398 port->pending_bh && !port->bh_running &&
51399 !port->bh_requested ) {
51400 if ( debug_level >= DEBUG_LEVEL_ISR )
51401 @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51402
51403 if (debug_level >= DEBUG_LEVEL_INFO)
51404 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51405 - __FILE__,__LINE__, tty->driver->name, port->count );
51406 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51407
51408 spin_lock_irqsave(&info->lock, flags);
51409 if (!tty_hung_up_p(filp)) {
51410 extra_count = true;
51411 - port->count--;
51412 + atomic_dec(&port->count);
51413 }
51414 spin_unlock_irqrestore(&info->lock, flags);
51415 port->blocked_open++;
51416 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51417
51418 if (debug_level >= DEBUG_LEVEL_INFO)
51419 printk("%s(%d):%s block_til_ready() count=%d\n",
51420 - __FILE__,__LINE__, tty->driver->name, port->count );
51421 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51422
51423 tty_unlock(tty);
51424 schedule();
51425 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51426 remove_wait_queue(&port->open_wait, &wait);
51427
51428 if (extra_count)
51429 - port->count++;
51430 + atomic_inc(&port->count);
51431 port->blocked_open--;
51432
51433 if (debug_level >= DEBUG_LEVEL_INFO)
51434 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51435 - __FILE__,__LINE__, tty->driver->name, port->count );
51436 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51437
51438 if (!retval)
51439 port->flags |= ASYNC_NORMAL_ACTIVE;
51440 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51441 index ce396ec..04a37be 100644
51442 --- a/drivers/tty/sysrq.c
51443 +++ b/drivers/tty/sysrq.c
51444 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51445 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51446 size_t count, loff_t *ppos)
51447 {
51448 - if (count) {
51449 + if (count && capable(CAP_SYS_ADMIN)) {
51450 char c;
51451
51452 if (get_user(c, buf))
51453 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51454 index c74a00a..02cf211a 100644
51455 --- a/drivers/tty/tty_io.c
51456 +++ b/drivers/tty/tty_io.c
51457 @@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51458
51459 void tty_default_fops(struct file_operations *fops)
51460 {
51461 - *fops = tty_fops;
51462 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51463 }
51464
51465 /*
51466 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51467 index 6458e11..6cfc218 100644
51468 --- a/drivers/tty/tty_ldisc.c
51469 +++ b/drivers/tty/tty_ldisc.c
51470 @@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51471 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51472 tty_ldiscs[disc] = new_ldisc;
51473 new_ldisc->num = disc;
51474 - new_ldisc->refcount = 0;
51475 + atomic_set(&new_ldisc->refcount, 0);
51476 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51477
51478 return ret;
51479 @@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
51480 return -EINVAL;
51481
51482 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51483 - if (tty_ldiscs[disc]->refcount)
51484 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51485 ret = -EBUSY;
51486 else
51487 tty_ldiscs[disc] = NULL;
51488 @@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51489 if (ldops) {
51490 ret = ERR_PTR(-EAGAIN);
51491 if (try_module_get(ldops->owner)) {
51492 - ldops->refcount++;
51493 + atomic_inc(&ldops->refcount);
51494 ret = ldops;
51495 }
51496 }
51497 @@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51498 unsigned long flags;
51499
51500 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51501 - ldops->refcount--;
51502 + atomic_dec(&ldops->refcount);
51503 module_put(ldops->owner);
51504 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51505 }
51506 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51507 index c94d234..8210f2d 100644
51508 --- a/drivers/tty/tty_port.c
51509 +++ b/drivers/tty/tty_port.c
51510 @@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
51511 unsigned long flags;
51512
51513 spin_lock_irqsave(&port->lock, flags);
51514 - port->count = 0;
51515 + atomic_set(&port->count, 0);
51516 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51517 tty = port->tty;
51518 if (tty)
51519 @@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51520 /* The port lock protects the port counts */
51521 spin_lock_irqsave(&port->lock, flags);
51522 if (!tty_hung_up_p(filp))
51523 - port->count--;
51524 + atomic_dec(&port->count);
51525 port->blocked_open++;
51526 spin_unlock_irqrestore(&port->lock, flags);
51527
51528 @@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51529 we must not mess that up further */
51530 spin_lock_irqsave(&port->lock, flags);
51531 if (!tty_hung_up_p(filp))
51532 - port->count++;
51533 + atomic_inc(&port->count);
51534 port->blocked_open--;
51535 if (retval == 0)
51536 port->flags |= ASYNC_NORMAL_ACTIVE;
51537 @@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
51538 return 0;
51539 }
51540
51541 - if (tty->count == 1 && port->count != 1) {
51542 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51543 printk(KERN_WARNING
51544 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51545 - port->count);
51546 - port->count = 1;
51547 + atomic_read(&port->count));
51548 + atomic_set(&port->count, 1);
51549 }
51550 - if (--port->count < 0) {
51551 + if (atomic_dec_return(&port->count) < 0) {
51552 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51553 - port->count);
51554 - port->count = 0;
51555 + atomic_read(&port->count));
51556 + atomic_set(&port->count, 0);
51557 }
51558
51559 - if (port->count) {
51560 + if (atomic_read(&port->count)) {
51561 spin_unlock_irqrestore(&port->lock, flags);
51562 return 0;
51563 }
51564 @@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51565 {
51566 spin_lock_irq(&port->lock);
51567 if (!tty_hung_up_p(filp))
51568 - ++port->count;
51569 + atomic_inc(&port->count);
51570 spin_unlock_irq(&port->lock);
51571 tty_port_tty_set(port, tty);
51572
51573 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51574 index d0e3a44..5f8b754 100644
51575 --- a/drivers/tty/vt/keyboard.c
51576 +++ b/drivers/tty/vt/keyboard.c
51577 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51578 kbd->kbdmode == VC_OFF) &&
51579 value != KVAL(K_SAK))
51580 return; /* SAK is allowed even in raw mode */
51581 +
51582 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51583 + {
51584 + void *func = fn_handler[value];
51585 + if (func == fn_show_state || func == fn_show_ptregs ||
51586 + func == fn_show_mem)
51587 + return;
51588 + }
51589 +#endif
51590 +
51591 fn_handler[value](vc);
51592 }
51593
51594 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51595 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51596 return -EFAULT;
51597
51598 - if (!capable(CAP_SYS_TTY_CONFIG))
51599 - perm = 0;
51600 -
51601 switch (cmd) {
51602 case KDGKBENT:
51603 /* Ensure another thread doesn't free it under us */
51604 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51605 spin_unlock_irqrestore(&kbd_event_lock, flags);
51606 return put_user(val, &user_kbe->kb_value);
51607 case KDSKBENT:
51608 + if (!capable(CAP_SYS_TTY_CONFIG))
51609 + perm = 0;
51610 +
51611 if (!perm)
51612 return -EPERM;
51613 if (!i && v == K_NOSUCHMAP) {
51614 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51615 int i, j, k;
51616 int ret;
51617
51618 - if (!capable(CAP_SYS_TTY_CONFIG))
51619 - perm = 0;
51620 -
51621 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51622 if (!kbs) {
51623 ret = -ENOMEM;
51624 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51625 kfree(kbs);
51626 return ((p && *p) ? -EOVERFLOW : 0);
51627 case KDSKBSENT:
51628 + if (!capable(CAP_SYS_TTY_CONFIG))
51629 + perm = 0;
51630 +
51631 if (!perm) {
51632 ret = -EPERM;
51633 goto reterr;
51634 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51635 index a673e5b..36e5d32 100644
51636 --- a/drivers/uio/uio.c
51637 +++ b/drivers/uio/uio.c
51638 @@ -25,6 +25,7 @@
51639 #include <linux/kobject.h>
51640 #include <linux/cdev.h>
51641 #include <linux/uio_driver.h>
51642 +#include <asm/local.h>
51643
51644 #define UIO_MAX_DEVICES (1U << MINORBITS)
51645
51646 @@ -32,7 +33,7 @@ struct uio_device {
51647 struct module *owner;
51648 struct device *dev;
51649 int minor;
51650 - atomic_t event;
51651 + atomic_unchecked_t event;
51652 struct fasync_struct *async_queue;
51653 wait_queue_head_t wait;
51654 struct uio_info *info;
51655 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51656 struct device_attribute *attr, char *buf)
51657 {
51658 struct uio_device *idev = dev_get_drvdata(dev);
51659 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51660 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51661 }
51662 static DEVICE_ATTR_RO(event);
51663
51664 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51665 {
51666 struct uio_device *idev = info->uio_dev;
51667
51668 - atomic_inc(&idev->event);
51669 + atomic_inc_unchecked(&idev->event);
51670 wake_up_interruptible(&idev->wait);
51671 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51672 }
51673 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51674 }
51675
51676 listener->dev = idev;
51677 - listener->event_count = atomic_read(&idev->event);
51678 + listener->event_count = atomic_read_unchecked(&idev->event);
51679 filep->private_data = listener;
51680
51681 if (idev->info->open) {
51682 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51683 return -EIO;
51684
51685 poll_wait(filep, &idev->wait, wait);
51686 - if (listener->event_count != atomic_read(&idev->event))
51687 + if (listener->event_count != atomic_read_unchecked(&idev->event))
51688 return POLLIN | POLLRDNORM;
51689 return 0;
51690 }
51691 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51692 do {
51693 set_current_state(TASK_INTERRUPTIBLE);
51694
51695 - event_count = atomic_read(&idev->event);
51696 + event_count = atomic_read_unchecked(&idev->event);
51697 if (event_count != listener->event_count) {
51698 if (copy_to_user(buf, &event_count, count))
51699 retval = -EFAULT;
51700 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51701 static int uio_find_mem_index(struct vm_area_struct *vma)
51702 {
51703 struct uio_device *idev = vma->vm_private_data;
51704 + unsigned long size;
51705
51706 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51707 - if (idev->info->mem[vma->vm_pgoff].size == 0)
51708 + size = idev->info->mem[vma->vm_pgoff].size;
51709 + if (size == 0)
51710 + return -1;
51711 + if (vma->vm_end - vma->vm_start > size)
51712 return -1;
51713 return (int)vma->vm_pgoff;
51714 }
51715 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51716 idev->owner = owner;
51717 idev->info = info;
51718 init_waitqueue_head(&idev->wait);
51719 - atomic_set(&idev->event, 0);
51720 + atomic_set_unchecked(&idev->event, 0);
51721
51722 ret = uio_get_minor(idev);
51723 if (ret)
51724 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51725 index 8a7eb77..c00402f 100644
51726 --- a/drivers/usb/atm/cxacru.c
51727 +++ b/drivers/usb/atm/cxacru.c
51728 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51729 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51730 if (ret < 2)
51731 return -EINVAL;
51732 - if (index < 0 || index > 0x7f)
51733 + if (index > 0x7f)
51734 return -EINVAL;
51735 pos += tmp;
51736
51737 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51738 index 25a7bfc..57f3cf5 100644
51739 --- a/drivers/usb/atm/usbatm.c
51740 +++ b/drivers/usb/atm/usbatm.c
51741 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51742 if (printk_ratelimit())
51743 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51744 __func__, vpi, vci);
51745 - atomic_inc(&vcc->stats->rx_err);
51746 + atomic_inc_unchecked(&vcc->stats->rx_err);
51747 return;
51748 }
51749
51750 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51751 if (length > ATM_MAX_AAL5_PDU) {
51752 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51753 __func__, length, vcc);
51754 - atomic_inc(&vcc->stats->rx_err);
51755 + atomic_inc_unchecked(&vcc->stats->rx_err);
51756 goto out;
51757 }
51758
51759 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51760 if (sarb->len < pdu_length) {
51761 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51762 __func__, pdu_length, sarb->len, vcc);
51763 - atomic_inc(&vcc->stats->rx_err);
51764 + atomic_inc_unchecked(&vcc->stats->rx_err);
51765 goto out;
51766 }
51767
51768 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51769 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51770 __func__, vcc);
51771 - atomic_inc(&vcc->stats->rx_err);
51772 + atomic_inc_unchecked(&vcc->stats->rx_err);
51773 goto out;
51774 }
51775
51776 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51777 if (printk_ratelimit())
51778 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51779 __func__, length);
51780 - atomic_inc(&vcc->stats->rx_drop);
51781 + atomic_inc_unchecked(&vcc->stats->rx_drop);
51782 goto out;
51783 }
51784
51785 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51786
51787 vcc->push(vcc, skb);
51788
51789 - atomic_inc(&vcc->stats->rx);
51790 + atomic_inc_unchecked(&vcc->stats->rx);
51791 out:
51792 skb_trim(sarb, 0);
51793 }
51794 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51795 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51796
51797 usbatm_pop(vcc, skb);
51798 - atomic_inc(&vcc->stats->tx);
51799 + atomic_inc_unchecked(&vcc->stats->tx);
51800
51801 skb = skb_dequeue(&instance->sndqueue);
51802 }
51803 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
51804 if (!left--)
51805 return sprintf(page,
51806 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51807 - atomic_read(&atm_dev->stats.aal5.tx),
51808 - atomic_read(&atm_dev->stats.aal5.tx_err),
51809 - atomic_read(&atm_dev->stats.aal5.rx),
51810 - atomic_read(&atm_dev->stats.aal5.rx_err),
51811 - atomic_read(&atm_dev->stats.aal5.rx_drop));
51812 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51813 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51814 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51815 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51816 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51817
51818 if (!left--) {
51819 if (instance->disconnected)
51820 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51821 index 2a3bbdf..91d72cf 100644
51822 --- a/drivers/usb/core/devices.c
51823 +++ b/drivers/usb/core/devices.c
51824 @@ -126,7 +126,7 @@ static const char format_endpt[] =
51825 * time it gets called.
51826 */
51827 static struct device_connect_event {
51828 - atomic_t count;
51829 + atomic_unchecked_t count;
51830 wait_queue_head_t wait;
51831 } device_event = {
51832 .count = ATOMIC_INIT(1),
51833 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51834
51835 void usbfs_conn_disc_event(void)
51836 {
51837 - atomic_add(2, &device_event.count);
51838 + atomic_add_unchecked(2, &device_event.count);
51839 wake_up(&device_event.wait);
51840 }
51841
51842 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51843
51844 poll_wait(file, &device_event.wait, wait);
51845
51846 - event_count = atomic_read(&device_event.count);
51847 + event_count = atomic_read_unchecked(&device_event.count);
51848 if (file->f_version != event_count) {
51849 file->f_version = event_count;
51850 return POLLIN | POLLRDNORM;
51851 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51852 index 967152a..16fa2e5 100644
51853 --- a/drivers/usb/core/devio.c
51854 +++ b/drivers/usb/core/devio.c
51855 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51856 struct dev_state *ps = file->private_data;
51857 struct usb_device *dev = ps->dev;
51858 ssize_t ret = 0;
51859 - unsigned len;
51860 + size_t len;
51861 loff_t pos;
51862 int i;
51863
51864 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51865 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51866 struct usb_config_descriptor *config =
51867 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51868 - unsigned int length = le16_to_cpu(config->wTotalLength);
51869 + size_t length = le16_to_cpu(config->wTotalLength);
51870
51871 if (*ppos < pos + length) {
51872
51873 /* The descriptor may claim to be longer than it
51874 * really is. Here is the actual allocated length. */
51875 - unsigned alloclen =
51876 + size_t alloclen =
51877 le16_to_cpu(dev->config[i].desc.wTotalLength);
51878
51879 - len = length - (*ppos - pos);
51880 + len = length + pos - *ppos;
51881 if (len > nbytes)
51882 len = nbytes;
51883
51884 /* Simply don't write (skip over) unallocated parts */
51885 if (alloclen > (*ppos - pos)) {
51886 - alloclen -= (*ppos - pos);
51887 + alloclen = alloclen + pos - *ppos;
51888 if (copy_to_user(buf,
51889 dev->rawdescriptors[i] + (*ppos - pos),
51890 min(len, alloclen))) {
51891 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51892 index d39106c..bfe13a4 100644
51893 --- a/drivers/usb/core/hcd.c
51894 +++ b/drivers/usb/core/hcd.c
51895 @@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51896 */
51897 usb_get_urb(urb);
51898 atomic_inc(&urb->use_count);
51899 - atomic_inc(&urb->dev->urbnum);
51900 + atomic_inc_unchecked(&urb->dev->urbnum);
51901 usbmon_urb_submit(&hcd->self, urb);
51902
51903 /* NOTE requirements on root-hub callers (usbfs and the hub
51904 @@ -1576,7 +1576,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51905 urb->hcpriv = NULL;
51906 INIT_LIST_HEAD(&urb->urb_list);
51907 atomic_dec(&urb->use_count);
51908 - atomic_dec(&urb->dev->urbnum);
51909 + atomic_dec_unchecked(&urb->dev->urbnum);
51910 if (atomic_read(&urb->reject))
51911 wake_up(&usb_kill_urb_queue);
51912 usb_put_urb(urb);
51913 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51914 index ebcd3bf..be93a64 100644
51915 --- a/drivers/usb/core/hub.c
51916 +++ b/drivers/usb/core/hub.c
51917 @@ -27,6 +27,7 @@
51918 #include <linux/freezer.h>
51919 #include <linux/random.h>
51920 #include <linux/pm_qos.h>
51921 +#include <linux/grsecurity.h>
51922
51923 #include <asm/uaccess.h>
51924 #include <asm/byteorder.h>
51925 @@ -4437,6 +4438,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51926 goto done;
51927 return;
51928 }
51929 +
51930 + if (gr_handle_new_usb())
51931 + goto done;
51932 +
51933 if (hub_is_superspeed(hub->hdev))
51934 unit_load = 150;
51935 else
51936 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51937 index bb31597..6c5ef8b 100644
51938 --- a/drivers/usb/core/message.c
51939 +++ b/drivers/usb/core/message.c
51940 @@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51941 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51942 * error number.
51943 */
51944 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51945 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51946 __u8 requesttype, __u16 value, __u16 index, void *data,
51947 __u16 size, int timeout)
51948 {
51949 @@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51950 * If successful, 0. Otherwise a negative error number. The number of actual
51951 * bytes transferred will be stored in the @actual_length paramater.
51952 */
51953 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51954 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51955 void *data, int len, int *actual_length, int timeout)
51956 {
51957 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51958 @@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51959 * bytes transferred will be stored in the @actual_length paramater.
51960 *
51961 */
51962 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51963 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51964 void *data, int len, int *actual_length, int timeout)
51965 {
51966 struct urb *urb;
51967 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51968 index 52a97ad..e73330f 100644
51969 --- a/drivers/usb/core/sysfs.c
51970 +++ b/drivers/usb/core/sysfs.c
51971 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51972 struct usb_device *udev;
51973
51974 udev = to_usb_device(dev);
51975 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51976 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51977 }
51978 static DEVICE_ATTR_RO(urbnum);
51979
51980 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51981 index 4d11449..f4ccabf 100644
51982 --- a/drivers/usb/core/usb.c
51983 +++ b/drivers/usb/core/usb.c
51984 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51985 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51986 dev->state = USB_STATE_ATTACHED;
51987 dev->lpm_disable_count = 1;
51988 - atomic_set(&dev->urbnum, 0);
51989 + atomic_set_unchecked(&dev->urbnum, 0);
51990
51991 INIT_LIST_HEAD(&dev->ep0.urb_list);
51992 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51993 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51994 index 02e44fc..3c4fe64 100644
51995 --- a/drivers/usb/dwc3/gadget.c
51996 +++ b/drivers/usb/dwc3/gadget.c
51997 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51998 if (!usb_endpoint_xfer_isoc(desc))
51999 return 0;
52000
52001 - memset(&trb_link, 0, sizeof(trb_link));
52002 -
52003 /* Link TRB for ISOC. The HWO bit is never reset */
52004 trb_st_hw = &dep->trb_pool[0];
52005
52006 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52007 index 8cfc319..4868255 100644
52008 --- a/drivers/usb/early/ehci-dbgp.c
52009 +++ b/drivers/usb/early/ehci-dbgp.c
52010 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52011
52012 #ifdef CONFIG_KGDB
52013 static struct kgdb_io kgdbdbgp_io_ops;
52014 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52015 +static struct kgdb_io kgdbdbgp_io_ops_console;
52016 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52017 #else
52018 #define dbgp_kgdb_mode (0)
52019 #endif
52020 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52021 .write_char = kgdbdbgp_write_char,
52022 };
52023
52024 +static struct kgdb_io kgdbdbgp_io_ops_console = {
52025 + .name = "kgdbdbgp",
52026 + .read_char = kgdbdbgp_read_char,
52027 + .write_char = kgdbdbgp_write_char,
52028 + .is_console = 1
52029 +};
52030 +
52031 static int kgdbdbgp_wait_time;
52032
52033 static int __init kgdbdbgp_parse_config(char *str)
52034 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52035 ptr++;
52036 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52037 }
52038 - kgdb_register_io_module(&kgdbdbgp_io_ops);
52039 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52040 + if (early_dbgp_console.index != -1)
52041 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52042 + else
52043 + kgdb_register_io_module(&kgdbdbgp_io_ops);
52044
52045 return 0;
52046 }
52047 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52048 index b369292..9f3ba40 100644
52049 --- a/drivers/usb/gadget/u_serial.c
52050 +++ b/drivers/usb/gadget/u_serial.c
52051 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52052 spin_lock_irq(&port->port_lock);
52053
52054 /* already open? Great. */
52055 - if (port->port.count) {
52056 + if (atomic_read(&port->port.count)) {
52057 status = 0;
52058 - port->port.count++;
52059 + atomic_inc(&port->port.count);
52060
52061 /* currently opening/closing? wait ... */
52062 } else if (port->openclose) {
52063 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52064 tty->driver_data = port;
52065 port->port.tty = tty;
52066
52067 - port->port.count = 1;
52068 + atomic_set(&port->port.count, 1);
52069 port->openclose = false;
52070
52071 /* if connected, start the I/O stream */
52072 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52073
52074 spin_lock_irq(&port->port_lock);
52075
52076 - if (port->port.count != 1) {
52077 - if (port->port.count == 0)
52078 + if (atomic_read(&port->port.count) != 1) {
52079 + if (atomic_read(&port->port.count) == 0)
52080 WARN_ON(1);
52081 else
52082 - --port->port.count;
52083 + atomic_dec(&port->port.count);
52084 goto exit;
52085 }
52086
52087 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52088 * and sleep if necessary
52089 */
52090 port->openclose = true;
52091 - port->port.count = 0;
52092 + atomic_set(&port->port.count, 0);
52093
52094 gser = port->port_usb;
52095 if (gser && gser->disconnect)
52096 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52097 int cond;
52098
52099 spin_lock_irq(&port->port_lock);
52100 - cond = (port->port.count == 0) && !port->openclose;
52101 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52102 spin_unlock_irq(&port->port_lock);
52103 return cond;
52104 }
52105 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52106 /* if it's already open, start I/O ... and notify the serial
52107 * protocol about open/close status (connect/disconnect).
52108 */
52109 - if (port->port.count) {
52110 + if (atomic_read(&port->port.count)) {
52111 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52112 gs_start_io(port);
52113 if (gser->connect)
52114 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52115
52116 port->port_usb = NULL;
52117 gser->ioport = NULL;
52118 - if (port->port.count > 0 || port->openclose) {
52119 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
52120 wake_up_interruptible(&port->drain_wait);
52121 if (port->port.tty)
52122 tty_hangup(port->port.tty);
52123 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52124
52125 /* finally, free any unused/unusable I/O buffers */
52126 spin_lock_irqsave(&port->port_lock, flags);
52127 - if (port->port.count == 0 && !port->openclose)
52128 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
52129 gs_buf_free(&port->port_write_buf);
52130 gs_free_requests(gser->out, &port->read_pool, NULL);
52131 gs_free_requests(gser->out, &port->read_queue, NULL);
52132 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52133 index 1bb85be..29e28d9 100644
52134 --- a/drivers/usb/host/ehci-hub.c
52135 +++ b/drivers/usb/host/ehci-hub.c
52136 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52137 urb->transfer_flags = URB_DIR_IN;
52138 usb_get_urb(urb);
52139 atomic_inc(&urb->use_count);
52140 - atomic_inc(&urb->dev->urbnum);
52141 + atomic_inc_unchecked(&urb->dev->urbnum);
52142 urb->setup_dma = dma_map_single(
52143 hcd->self.controller,
52144 urb->setup_packet,
52145 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52146 urb->status = -EINPROGRESS;
52147 usb_get_urb(urb);
52148 atomic_inc(&urb->use_count);
52149 - atomic_inc(&urb->dev->urbnum);
52150 + atomic_inc_unchecked(&urb->dev->urbnum);
52151 retval = submit_single_step_set_feature(hcd, urb, 0);
52152 if (!retval && !wait_for_completion_timeout(&done,
52153 msecs_to_jiffies(2000))) {
52154 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52155 index ba6a5d6..f88f7f3 100644
52156 --- a/drivers/usb/misc/appledisplay.c
52157 +++ b/drivers/usb/misc/appledisplay.c
52158 @@ -83,7 +83,7 @@ struct appledisplay {
52159 spinlock_t lock;
52160 };
52161
52162 -static atomic_t count_displays = ATOMIC_INIT(0);
52163 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52164 static struct workqueue_struct *wq;
52165
52166 static void appledisplay_complete(struct urb *urb)
52167 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52168
52169 /* Register backlight device */
52170 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52171 - atomic_inc_return(&count_displays) - 1);
52172 + atomic_inc_return_unchecked(&count_displays) - 1);
52173 memset(&props, 0, sizeof(struct backlight_properties));
52174 props.type = BACKLIGHT_RAW;
52175 props.max_brightness = 0xff;
52176 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52177 index c69bb50..215ef37 100644
52178 --- a/drivers/usb/serial/console.c
52179 +++ b/drivers/usb/serial/console.c
52180 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
52181
52182 info->port = port;
52183
52184 - ++port->port.count;
52185 + atomic_inc(&port->port.count);
52186 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52187 if (serial->type->set_termios) {
52188 /*
52189 @@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
52190 }
52191 /* Now that any required fake tty operations are completed restore
52192 * the tty port count */
52193 - --port->port.count;
52194 + atomic_dec(&port->port.count);
52195 /* The console is special in terms of closing the device so
52196 * indicate this port is now acting as a system console. */
52197 port->port.console = 1;
52198 @@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
52199 free_tty:
52200 kfree(tty);
52201 reset_open_count:
52202 - port->port.count = 0;
52203 + atomic_set(&port->port.count, 0);
52204 usb_autopm_put_interface(serial->interface);
52205 error_get_interface:
52206 usb_serial_put(serial);
52207 @@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
52208 static void usb_console_write(struct console *co,
52209 const char *buf, unsigned count)
52210 {
52211 - static struct usbcons_info *info = &usbcons_info;
52212 + struct usbcons_info *info = &usbcons_info;
52213 struct usb_serial_port *port = info->port;
52214 struct usb_serial *serial;
52215 int retval = -ENODEV;
52216 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52217 index 75f70f0..d467e1a 100644
52218 --- a/drivers/usb/storage/usb.h
52219 +++ b/drivers/usb/storage/usb.h
52220 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52221 __u8 useProtocol;
52222 __u8 useTransport;
52223 int (*initFunction)(struct us_data *);
52224 -};
52225 +} __do_const;
52226
52227
52228 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52229 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52230 index e614f02..3fd60e2 100644
52231 --- a/drivers/usb/wusbcore/wa-hc.h
52232 +++ b/drivers/usb/wusbcore/wa-hc.h
52233 @@ -225,7 +225,7 @@ struct wahc {
52234 spinlock_t xfer_list_lock;
52235 struct work_struct xfer_enqueue_work;
52236 struct work_struct xfer_error_work;
52237 - atomic_t xfer_id_count;
52238 + atomic_unchecked_t xfer_id_count;
52239
52240 kernel_ulong_t quirks;
52241 };
52242 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52243 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52244 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52245 wa->dto_in_use = 0;
52246 - atomic_set(&wa->xfer_id_count, 1);
52247 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52248 }
52249
52250 /**
52251 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52252 index ed5abe8..7036400 100644
52253 --- a/drivers/usb/wusbcore/wa-xfer.c
52254 +++ b/drivers/usb/wusbcore/wa-xfer.c
52255 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52256 */
52257 static void wa_xfer_id_init(struct wa_xfer *xfer)
52258 {
52259 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52260 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52261 }
52262
52263 /* Return the xfer's ID. */
52264 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52265 index 1eab4ac..e21efc9 100644
52266 --- a/drivers/vfio/vfio.c
52267 +++ b/drivers/vfio/vfio.c
52268 @@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52269 return 0;
52270
52271 /* TODO Prevent device auto probing */
52272 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52273 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52274 iommu_group_id(group->iommu_group));
52275
52276 return 0;
52277 diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
52278 index b12176f..e5522d9 100644
52279 --- a/drivers/vhost/net.c
52280 +++ b/drivers/vhost/net.c
52281 @@ -528,6 +528,12 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
52282 *iovcount = seg;
52283 if (unlikely(log))
52284 *log_num = nlogs;
52285 +
52286 + /* Detect overrun */
52287 + if (unlikely(datalen > 0)) {
52288 + r = UIO_MAXIOV + 1;
52289 + goto err;
52290 + }
52291 return headcount;
52292 err:
52293 vhost_discard_vq_desc(vq, headcount);
52294 @@ -583,6 +589,14 @@ static void handle_rx(struct vhost_net *net)
52295 /* On error, stop handling until the next kick. */
52296 if (unlikely(headcount < 0))
52297 break;
52298 + /* On overrun, truncate and discard */
52299 + if (unlikely(headcount > UIO_MAXIOV)) {
52300 + msg.msg_iovlen = 1;
52301 + err = sock->ops->recvmsg(NULL, sock, &msg,
52302 + 1, MSG_DONTWAIT | MSG_TRUNC);
52303 + pr_debug("Discarded rx packet: len %zd\n", sock_len);
52304 + continue;
52305 + }
52306 /* OK, now we need to know about added descriptors. */
52307 if (!headcount) {
52308 if (unlikely(vhost_enable_notify(&net->dev, vq))) {
52309 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52310 index 5174eba..451e6bc 100644
52311 --- a/drivers/vhost/vringh.c
52312 +++ b/drivers/vhost/vringh.c
52313 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52314 /* Userspace access helpers: in this case, addresses are really userspace. */
52315 static inline int getu16_user(u16 *val, const u16 *p)
52316 {
52317 - return get_user(*val, (__force u16 __user *)p);
52318 + return get_user(*val, (u16 __force_user *)p);
52319 }
52320
52321 static inline int putu16_user(u16 *p, u16 val)
52322 {
52323 - return put_user(val, (__force u16 __user *)p);
52324 + return put_user(val, (u16 __force_user *)p);
52325 }
52326
52327 static inline int copydesc_user(void *dst, const void *src, size_t len)
52328 {
52329 - return copy_from_user(dst, (__force void __user *)src, len) ?
52330 + return copy_from_user(dst, (void __force_user *)src, len) ?
52331 -EFAULT : 0;
52332 }
52333
52334 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52335 const struct vring_used_elem *src,
52336 unsigned int num)
52337 {
52338 - return copy_to_user((__force void __user *)dst, src,
52339 + return copy_to_user((void __force_user *)dst, src,
52340 sizeof(*dst) * num) ? -EFAULT : 0;
52341 }
52342
52343 static inline int xfer_from_user(void *src, void *dst, size_t len)
52344 {
52345 - return copy_from_user(dst, (__force void __user *)src, len) ?
52346 + return copy_from_user(dst, (void __force_user *)src, len) ?
52347 -EFAULT : 0;
52348 }
52349
52350 static inline int xfer_to_user(void *dst, void *src, size_t len)
52351 {
52352 - return copy_to_user((__force void __user *)dst, src, len) ?
52353 + return copy_to_user((void __force_user *)dst, src, len) ?
52354 -EFAULT : 0;
52355 }
52356
52357 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52358 vrh->last_used_idx = 0;
52359 vrh->vring.num = num;
52360 /* vring expects kernel addresses, but only used via accessors. */
52361 - vrh->vring.desc = (__force struct vring_desc *)desc;
52362 - vrh->vring.avail = (__force struct vring_avail *)avail;
52363 - vrh->vring.used = (__force struct vring_used *)used;
52364 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52365 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52366 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52367 return 0;
52368 }
52369 EXPORT_SYMBOL(vringh_init_user);
52370 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52371
52372 static inline int putu16_kern(u16 *p, u16 val)
52373 {
52374 - ACCESS_ONCE(*p) = val;
52375 + ACCESS_ONCE_RW(*p) = val;
52376 return 0;
52377 }
52378
52379 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52380 index 1b0b233..6f34c2c 100644
52381 --- a/drivers/video/arcfb.c
52382 +++ b/drivers/video/arcfb.c
52383 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52384 return -ENOSPC;
52385
52386 err = 0;
52387 - if ((count + p) > fbmemlength) {
52388 + if (count > (fbmemlength - p)) {
52389 count = fbmemlength - p;
52390 err = -ENOSPC;
52391 }
52392 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52393 index 12ca031..84a8a74 100644
52394 --- a/drivers/video/aty/aty128fb.c
52395 +++ b/drivers/video/aty/aty128fb.c
52396 @@ -149,7 +149,7 @@ enum {
52397 };
52398
52399 /* Must match above enum */
52400 -static char * const r128_family[] = {
52401 +static const char * const r128_family[] = {
52402 "AGP",
52403 "PCI",
52404 "PRO AGP",
52405 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52406 index 28fafbf..ae91651 100644
52407 --- a/drivers/video/aty/atyfb_base.c
52408 +++ b/drivers/video/aty/atyfb_base.c
52409 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52410 par->accel_flags = var->accel_flags; /* hack */
52411
52412 if (var->accel_flags) {
52413 - info->fbops->fb_sync = atyfb_sync;
52414 + pax_open_kernel();
52415 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52416 + pax_close_kernel();
52417 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52418 } else {
52419 - info->fbops->fb_sync = NULL;
52420 + pax_open_kernel();
52421 + *(void **)&info->fbops->fb_sync = NULL;
52422 + pax_close_kernel();
52423 info->flags |= FBINFO_HWACCEL_DISABLED;
52424 }
52425
52426 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52427 index 95ec042..e6affdd 100644
52428 --- a/drivers/video/aty/mach64_cursor.c
52429 +++ b/drivers/video/aty/mach64_cursor.c
52430 @@ -7,6 +7,7 @@
52431 #include <linux/string.h>
52432
52433 #include <asm/io.h>
52434 +#include <asm/pgtable.h>
52435
52436 #ifdef __sparc__
52437 #include <asm/fbio.h>
52438 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52439 info->sprite.buf_align = 16; /* and 64 lines tall. */
52440 info->sprite.flags = FB_PIXMAP_IO;
52441
52442 - info->fbops->fb_cursor = atyfb_cursor;
52443 + pax_open_kernel();
52444 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52445 + pax_close_kernel();
52446
52447 return 0;
52448 }
52449 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52450 index 7592cc2..92feb56 100644
52451 --- a/drivers/video/backlight/kb3886_bl.c
52452 +++ b/drivers/video/backlight/kb3886_bl.c
52453 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52454 static unsigned long kb3886bl_flags;
52455 #define KB3886BL_SUSPENDED 0x01
52456
52457 -static struct dmi_system_id __initdata kb3886bl_device_table[] = {
52458 +static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
52459 {
52460 .ident = "Sahara Touch-iT",
52461 .matches = {
52462 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52463 index 900aa4e..6d49418 100644
52464 --- a/drivers/video/fb_defio.c
52465 +++ b/drivers/video/fb_defio.c
52466 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52467
52468 BUG_ON(!fbdefio);
52469 mutex_init(&fbdefio->lock);
52470 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52471 + pax_open_kernel();
52472 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52473 + pax_close_kernel();
52474 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52475 INIT_LIST_HEAD(&fbdefio->pagelist);
52476 if (fbdefio->delay == 0) /* set a default of 1 s */
52477 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52478 page->mapping = NULL;
52479 }
52480
52481 - info->fbops->fb_mmap = NULL;
52482 + *(void **)&info->fbops->fb_mmap = NULL;
52483 mutex_destroy(&fbdefio->lock);
52484 }
52485 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52486 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52487 index 010d191..7b8235a 100644
52488 --- a/drivers/video/fbmem.c
52489 +++ b/drivers/video/fbmem.c
52490 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52491 image->dx += image->width + 8;
52492 }
52493 } else if (rotate == FB_ROTATE_UD) {
52494 - for (x = 0; x < num && image->dx >= 0; x++) {
52495 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52496 info->fbops->fb_imageblit(info, image);
52497 image->dx -= image->width + 8;
52498 }
52499 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52500 image->dy += image->height + 8;
52501 }
52502 } else if (rotate == FB_ROTATE_CCW) {
52503 - for (x = 0; x < num && image->dy >= 0; x++) {
52504 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52505 info->fbops->fb_imageblit(info, image);
52506 image->dy -= image->height + 8;
52507 }
52508 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52509 return -EFAULT;
52510 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52511 return -EINVAL;
52512 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52513 + if (con2fb.framebuffer >= FB_MAX)
52514 return -EINVAL;
52515 if (!registered_fb[con2fb.framebuffer])
52516 request_module("fb%d", con2fb.framebuffer);
52517 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52518 __u32 data;
52519 int err;
52520
52521 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52522 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52523
52524 data = (__u32) (unsigned long) fix->smem_start;
52525 err |= put_user(data, &fix32->smem_start);
52526 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52527 index 130708f..cdac1a9 100644
52528 --- a/drivers/video/hyperv_fb.c
52529 +++ b/drivers/video/hyperv_fb.c
52530 @@ -233,7 +233,7 @@ static uint screen_fb_size;
52531 static inline int synthvid_send(struct hv_device *hdev,
52532 struct synthvid_msg *msg)
52533 {
52534 - static atomic64_t request_id = ATOMIC64_INIT(0);
52535 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52536 int ret;
52537
52538 msg->pipe_hdr.type = PIPE_MSG_DATA;
52539 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52540
52541 ret = vmbus_sendpacket(hdev->channel, msg,
52542 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52543 - atomic64_inc_return(&request_id),
52544 + atomic64_inc_return_unchecked(&request_id),
52545 VM_PKT_DATA_INBAND, 0);
52546
52547 if (ret)
52548 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52549 index 7672d2e..b56437f 100644
52550 --- a/drivers/video/i810/i810_accel.c
52551 +++ b/drivers/video/i810/i810_accel.c
52552 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52553 }
52554 }
52555 printk("ringbuffer lockup!!!\n");
52556 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52557 i810_report_error(mmio);
52558 par->dev_flags |= LOCKUP;
52559 info->pixmap.scan_align = 1;
52560 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52561 index 3c14e43..2630570 100644
52562 --- a/drivers/video/logo/logo_linux_clut224.ppm
52563 +++ b/drivers/video/logo/logo_linux_clut224.ppm
52564 @@ -2,1603 +2,1123 @@ P3
52565 # Standard 224-color Linux logo
52566 80 80
52567 255
52568 - 0 0 0 0 0 0 0 0 0 0 0 0
52569 - 0 0 0 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 0 0 0
52575 - 0 0 0 0 0 0 0 0 0 0 0 0
52576 - 0 0 0 0 0 0 0 0 0 0 0 0
52577 - 6 6 6 6 6 6 10 10 10 10 10 10
52578 - 10 10 10 6 6 6 6 6 6 6 6 6
52579 - 0 0 0 0 0 0 0 0 0 0 0 0
52580 - 0 0 0 0 0 0 0 0 0 0 0 0
52581 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 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 0 0 0
52595 - 0 0 0 0 0 0 0 0 0 0 0 0
52596 - 0 0 0 6 6 6 10 10 10 14 14 14
52597 - 22 22 22 26 26 26 30 30 30 34 34 34
52598 - 30 30 30 30 30 30 26 26 26 18 18 18
52599 - 14 14 14 10 10 10 6 6 6 0 0 0
52600 - 0 0 0 0 0 0 0 0 0 0 0 0
52601 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 0 0 0
52615 - 0 0 0 0 0 0 0 0 0 0 0 0
52616 - 6 6 6 14 14 14 26 26 26 42 42 42
52617 - 54 54 54 66 66 66 78 78 78 78 78 78
52618 - 78 78 78 74 74 74 66 66 66 54 54 54
52619 - 42 42 42 26 26 26 18 18 18 10 10 10
52620 - 6 6 6 0 0 0 0 0 0 0 0 0
52621 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
52629 - 0 0 1 0 0 0 0 0 0 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 0 0 0
52635 - 0 0 0 0 0 0 0 0 0 10 10 10
52636 - 22 22 22 42 42 42 66 66 66 86 86 86
52637 - 66 66 66 38 38 38 38 38 38 22 22 22
52638 - 26 26 26 34 34 34 54 54 54 66 66 66
52639 - 86 86 86 70 70 70 46 46 46 26 26 26
52640 - 14 14 14 6 6 6 0 0 0 0 0 0
52641 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 0 0 0
52655 - 0 0 0 0 0 0 10 10 10 26 26 26
52656 - 50 50 50 82 82 82 58 58 58 6 6 6
52657 - 2 2 6 2 2 6 2 2 6 2 2 6
52658 - 2 2 6 2 2 6 2 2 6 2 2 6
52659 - 6 6 6 54 54 54 86 86 86 66 66 66
52660 - 38 38 38 18 18 18 6 6 6 0 0 0
52661 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
52669 - 0 0 0 0 0 0 0 0 0 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 0 0 0
52675 - 0 0 0 6 6 6 22 22 22 50 50 50
52676 - 78 78 78 34 34 34 2 2 6 2 2 6
52677 - 2 2 6 2 2 6 2 2 6 2 2 6
52678 - 2 2 6 2 2 6 2 2 6 2 2 6
52679 - 2 2 6 2 2 6 6 6 6 70 70 70
52680 - 78 78 78 46 46 46 22 22 22 6 6 6
52681 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
52689 - 0 0 1 0 0 1 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 0 0 0
52695 - 6 6 6 18 18 18 42 42 42 82 82 82
52696 - 26 26 26 2 2 6 2 2 6 2 2 6
52697 - 2 2 6 2 2 6 2 2 6 2 2 6
52698 - 2 2 6 2 2 6 2 2 6 14 14 14
52699 - 46 46 46 34 34 34 6 6 6 2 2 6
52700 - 42 42 42 78 78 78 42 42 42 18 18 18
52701 - 6 6 6 0 0 0 0 0 0 0 0 0
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 0 0 0 0
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 0 0 0
52715 - 10 10 10 30 30 30 66 66 66 58 58 58
52716 - 2 2 6 2 2 6 2 2 6 2 2 6
52717 - 2 2 6 2 2 6 2 2 6 2 2 6
52718 - 2 2 6 2 2 6 2 2 6 26 26 26
52719 - 86 86 86 101 101 101 46 46 46 10 10 10
52720 - 2 2 6 58 58 58 70 70 70 34 34 34
52721 - 10 10 10 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 0 0 0
52735 - 14 14 14 42 42 42 86 86 86 10 10 10
52736 - 2 2 6 2 2 6 2 2 6 2 2 6
52737 - 2 2 6 2 2 6 2 2 6 2 2 6
52738 - 2 2 6 2 2 6 2 2 6 30 30 30
52739 - 94 94 94 94 94 94 58 58 58 26 26 26
52740 - 2 2 6 6 6 6 78 78 78 54 54 54
52741 - 22 22 22 6 6 6 0 0 0 0 0 0
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 6 6 6
52755 - 22 22 22 62 62 62 62 62 62 2 2 6
52756 - 2 2 6 2 2 6 2 2 6 2 2 6
52757 - 2 2 6 2 2 6 2 2 6 2 2 6
52758 - 2 2 6 2 2 6 2 2 6 26 26 26
52759 - 54 54 54 38 38 38 18 18 18 10 10 10
52760 - 2 2 6 2 2 6 34 34 34 82 82 82
52761 - 38 38 38 14 14 14 0 0 0 0 0 0
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 1 0 0 1 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 6 6 6
52775 - 30 30 30 78 78 78 30 30 30 2 2 6
52776 - 2 2 6 2 2 6 2 2 6 2 2 6
52777 - 2 2 6 2 2 6 2 2 6 2 2 6
52778 - 2 2 6 2 2 6 2 2 6 10 10 10
52779 - 10 10 10 2 2 6 2 2 6 2 2 6
52780 - 2 2 6 2 2 6 2 2 6 78 78 78
52781 - 50 50 50 18 18 18 6 6 6 0 0 0
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 1 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 - 38 38 38 86 86 86 14 14 14 2 2 6
52796 - 2 2 6 2 2 6 2 2 6 2 2 6
52797 - 2 2 6 2 2 6 2 2 6 2 2 6
52798 - 2 2 6 2 2 6 2 2 6 2 2 6
52799 - 2 2 6 2 2 6 2 2 6 2 2 6
52800 - 2 2 6 2 2 6 2 2 6 54 54 54
52801 - 66 66 66 26 26 26 6 6 6 0 0 0
52802 - 0 0 0 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 1 0 0 1 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 14 14 14
52815 - 42 42 42 82 82 82 2 2 6 2 2 6
52816 - 2 2 6 6 6 6 10 10 10 2 2 6
52817 - 2 2 6 2 2 6 2 2 6 2 2 6
52818 - 2 2 6 2 2 6 2 2 6 6 6 6
52819 - 14 14 14 10 10 10 2 2 6 2 2 6
52820 - 2 2 6 2 2 6 2 2 6 18 18 18
52821 - 82 82 82 34 34 34 10 10 10 0 0 0
52822 - 0 0 0 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 1 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 14 14 14
52835 - 46 46 46 86 86 86 2 2 6 2 2 6
52836 - 6 6 6 6 6 6 22 22 22 34 34 34
52837 - 6 6 6 2 2 6 2 2 6 2 2 6
52838 - 2 2 6 2 2 6 18 18 18 34 34 34
52839 - 10 10 10 50 50 50 22 22 22 2 2 6
52840 - 2 2 6 2 2 6 2 2 6 10 10 10
52841 - 86 86 86 42 42 42 14 14 14 0 0 0
52842 - 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 14 14 14
52855 - 46 46 46 86 86 86 2 2 6 2 2 6
52856 - 38 38 38 116 116 116 94 94 94 22 22 22
52857 - 22 22 22 2 2 6 2 2 6 2 2 6
52858 - 14 14 14 86 86 86 138 138 138 162 162 162
52859 -154 154 154 38 38 38 26 26 26 6 6 6
52860 - 2 2 6 2 2 6 2 2 6 2 2 6
52861 - 86 86 86 46 46 46 14 14 14 0 0 0
52862 - 0 0 0 0 0 0 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 0 0 0 14 14 14
52875 - 46 46 46 86 86 86 2 2 6 14 14 14
52876 -134 134 134 198 198 198 195 195 195 116 116 116
52877 - 10 10 10 2 2 6 2 2 6 6 6 6
52878 -101 98 89 187 187 187 210 210 210 218 218 218
52879 -214 214 214 134 134 134 14 14 14 6 6 6
52880 - 2 2 6 2 2 6 2 2 6 2 2 6
52881 - 86 86 86 50 50 50 18 18 18 6 6 6
52882 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
52889 - 0 0 1 0 0 1 0 0 1 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 0 0 0 14 14 14
52895 - 46 46 46 86 86 86 2 2 6 54 54 54
52896 -218 218 218 195 195 195 226 226 226 246 246 246
52897 - 58 58 58 2 2 6 2 2 6 30 30 30
52898 -210 210 210 253 253 253 174 174 174 123 123 123
52899 -221 221 221 234 234 234 74 74 74 2 2 6
52900 - 2 2 6 2 2 6 2 2 6 2 2 6
52901 - 70 70 70 58 58 58 22 22 22 6 6 6
52902 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 14 14 14
52915 - 46 46 46 82 82 82 2 2 6 106 106 106
52916 -170 170 170 26 26 26 86 86 86 226 226 226
52917 -123 123 123 10 10 10 14 14 14 46 46 46
52918 -231 231 231 190 190 190 6 6 6 70 70 70
52919 - 90 90 90 238 238 238 158 158 158 2 2 6
52920 - 2 2 6 2 2 6 2 2 6 2 2 6
52921 - 70 70 70 58 58 58 22 22 22 6 6 6
52922 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
52929 - 0 0 1 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 14 14 14
52935 - 42 42 42 86 86 86 6 6 6 116 116 116
52936 -106 106 106 6 6 6 70 70 70 149 149 149
52937 -128 128 128 18 18 18 38 38 38 54 54 54
52938 -221 221 221 106 106 106 2 2 6 14 14 14
52939 - 46 46 46 190 190 190 198 198 198 2 2 6
52940 - 2 2 6 2 2 6 2 2 6 2 2 6
52941 - 74 74 74 62 62 62 22 22 22 6 6 6
52942 - 0 0 0 0 0 0 0 0 0 0 0 0
52943 - 0 0 0 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 1 0 0 0
52949 - 0 0 1 0 0 0 0 0 1 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 0 0 0
52954 - 0 0 0 0 0 0 0 0 0 14 14 14
52955 - 42 42 42 94 94 94 14 14 14 101 101 101
52956 -128 128 128 2 2 6 18 18 18 116 116 116
52957 -118 98 46 121 92 8 121 92 8 98 78 10
52958 -162 162 162 106 106 106 2 2 6 2 2 6
52959 - 2 2 6 195 195 195 195 195 195 6 6 6
52960 - 2 2 6 2 2 6 2 2 6 2 2 6
52961 - 74 74 74 62 62 62 22 22 22 6 6 6
52962 - 0 0 0 0 0 0 0 0 0 0 0 0
52963 - 0 0 0 0 0 0 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 1 0 0 1
52969 - 0 0 1 0 0 0 0 0 1 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 0 0 0
52974 - 0 0 0 0 0 0 0 0 0 10 10 10
52975 - 38 38 38 90 90 90 14 14 14 58 58 58
52976 -210 210 210 26 26 26 54 38 6 154 114 10
52977 -226 170 11 236 186 11 225 175 15 184 144 12
52978 -215 174 15 175 146 61 37 26 9 2 2 6
52979 - 70 70 70 246 246 246 138 138 138 2 2 6
52980 - 2 2 6 2 2 6 2 2 6 2 2 6
52981 - 70 70 70 66 66 66 26 26 26 6 6 6
52982 - 0 0 0 0 0 0 0 0 0 0 0 0
52983 - 0 0 0 0 0 0 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 0 0 0 0 0 0
52994 - 0 0 0 0 0 0 0 0 0 10 10 10
52995 - 38 38 38 86 86 86 14 14 14 10 10 10
52996 -195 195 195 188 164 115 192 133 9 225 175 15
52997 -239 182 13 234 190 10 232 195 16 232 200 30
52998 -245 207 45 241 208 19 232 195 16 184 144 12
52999 -218 194 134 211 206 186 42 42 42 2 2 6
53000 - 2 2 6 2 2 6 2 2 6 2 2 6
53001 - 50 50 50 74 74 74 30 30 30 6 6 6
53002 - 0 0 0 0 0 0 0 0 0 0 0 0
53003 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0
53014 - 0 0 0 0 0 0 0 0 0 10 10 10
53015 - 34 34 34 86 86 86 14 14 14 2 2 6
53016 -121 87 25 192 133 9 219 162 10 239 182 13
53017 -236 186 11 232 195 16 241 208 19 244 214 54
53018 -246 218 60 246 218 38 246 215 20 241 208 19
53019 -241 208 19 226 184 13 121 87 25 2 2 6
53020 - 2 2 6 2 2 6 2 2 6 2 2 6
53021 - 50 50 50 82 82 82 34 34 34 10 10 10
53022 - 0 0 0 0 0 0 0 0 0 0 0 0
53023 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 0 0 0 0 0 0 0 0 0 0 0 0
53034 - 0 0 0 0 0 0 0 0 0 10 10 10
53035 - 34 34 34 82 82 82 30 30 30 61 42 6
53036 -180 123 7 206 145 10 230 174 11 239 182 13
53037 -234 190 10 238 202 15 241 208 19 246 218 74
53038 -246 218 38 246 215 20 246 215 20 246 215 20
53039 -226 184 13 215 174 15 184 144 12 6 6 6
53040 - 2 2 6 2 2 6 2 2 6 2 2 6
53041 - 26 26 26 94 94 94 42 42 42 14 14 14
53042 - 0 0 0 0 0 0 0 0 0 0 0 0
53043 - 0 0 0 0 0 0 0 0 0 0 0 0
53044 - 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
53054 - 0 0 0 0 0 0 0 0 0 10 10 10
53055 - 30 30 30 78 78 78 50 50 50 104 69 6
53056 -192 133 9 216 158 10 236 178 12 236 186 11
53057 -232 195 16 241 208 19 244 214 54 245 215 43
53058 -246 215 20 246 215 20 241 208 19 198 155 10
53059 -200 144 11 216 158 10 156 118 10 2 2 6
53060 - 2 2 6 2 2 6 2 2 6 2 2 6
53061 - 6 6 6 90 90 90 54 54 54 18 18 18
53062 - 6 6 6 0 0 0 0 0 0 0 0 0
53063 - 0 0 0 0 0 0 0 0 0 0 0 0
53064 - 0 0 0 0 0 0 0 0 0 0 0 0
53065 - 0 0 0 0 0 0 0 0 0 0 0 0
53066 - 0 0 0 0 0 0 0 0 0 0 0 0
53067 - 0 0 0 0 0 0 0 0 0 0 0 0
53068 - 0 0 0 0 0 0 0 0 0 0 0 0
53069 - 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 - 0 0 0 0 0 0 0 0 0 0 0 0
53074 - 0 0 0 0 0 0 0 0 0 10 10 10
53075 - 30 30 30 78 78 78 46 46 46 22 22 22
53076 -137 92 6 210 162 10 239 182 13 238 190 10
53077 -238 202 15 241 208 19 246 215 20 246 215 20
53078 -241 208 19 203 166 17 185 133 11 210 150 10
53079 -216 158 10 210 150 10 102 78 10 2 2 6
53080 - 6 6 6 54 54 54 14 14 14 2 2 6
53081 - 2 2 6 62 62 62 74 74 74 30 30 30
53082 - 10 10 10 0 0 0 0 0 0 0 0 0
53083 - 0 0 0 0 0 0 0 0 0 0 0 0
53084 - 0 0 0 0 0 0 0 0 0 0 0 0
53085 - 0 0 0 0 0 0 0 0 0 0 0 0
53086 - 0 0 0 0 0 0 0 0 0 0 0 0
53087 - 0 0 0 0 0 0 0 0 0 0 0 0
53088 - 0 0 0 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 0 0 0
53093 - 0 0 0 0 0 0 0 0 0 0 0 0
53094 - 0 0 0 0 0 0 0 0 0 10 10 10
53095 - 34 34 34 78 78 78 50 50 50 6 6 6
53096 - 94 70 30 139 102 15 190 146 13 226 184 13
53097 -232 200 30 232 195 16 215 174 15 190 146 13
53098 -168 122 10 192 133 9 210 150 10 213 154 11
53099 -202 150 34 182 157 106 101 98 89 2 2 6
53100 - 2 2 6 78 78 78 116 116 116 58 58 58
53101 - 2 2 6 22 22 22 90 90 90 46 46 46
53102 - 18 18 18 6 6 6 0 0 0 0 0 0
53103 - 0 0 0 0 0 0 0 0 0 0 0 0
53104 - 0 0 0 0 0 0 0 0 0 0 0 0
53105 - 0 0 0 0 0 0 0 0 0 0 0 0
53106 - 0 0 0 0 0 0 0 0 0 0 0 0
53107 - 0 0 0 0 0 0 0 0 0 0 0 0
53108 - 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 0 0 0
53113 - 0 0 0 0 0 0 0 0 0 0 0 0
53114 - 0 0 0 0 0 0 0 0 0 10 10 10
53115 - 38 38 38 86 86 86 50 50 50 6 6 6
53116 -128 128 128 174 154 114 156 107 11 168 122 10
53117 -198 155 10 184 144 12 197 138 11 200 144 11
53118 -206 145 10 206 145 10 197 138 11 188 164 115
53119 -195 195 195 198 198 198 174 174 174 14 14 14
53120 - 2 2 6 22 22 22 116 116 116 116 116 116
53121 - 22 22 22 2 2 6 74 74 74 70 70 70
53122 - 30 30 30 10 10 10 0 0 0 0 0 0
53123 - 0 0 0 0 0 0 0 0 0 0 0 0
53124 - 0 0 0 0 0 0 0 0 0 0 0 0
53125 - 0 0 0 0 0 0 0 0 0 0 0 0
53126 - 0 0 0 0 0 0 0 0 0 0 0 0
53127 - 0 0 0 0 0 0 0 0 0 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 0 0 0
53133 - 0 0 0 0 0 0 0 0 0 0 0 0
53134 - 0 0 0 0 0 0 6 6 6 18 18 18
53135 - 50 50 50 101 101 101 26 26 26 10 10 10
53136 -138 138 138 190 190 190 174 154 114 156 107 11
53137 -197 138 11 200 144 11 197 138 11 192 133 9
53138 -180 123 7 190 142 34 190 178 144 187 187 187
53139 -202 202 202 221 221 221 214 214 214 66 66 66
53140 - 2 2 6 2 2 6 50 50 50 62 62 62
53141 - 6 6 6 2 2 6 10 10 10 90 90 90
53142 - 50 50 50 18 18 18 6 6 6 0 0 0
53143 - 0 0 0 0 0 0 0 0 0 0 0 0
53144 - 0 0 0 0 0 0 0 0 0 0 0 0
53145 - 0 0 0 0 0 0 0 0 0 0 0 0
53146 - 0 0 0 0 0 0 0 0 0 0 0 0
53147 - 0 0 0 0 0 0 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 0 0 0 0 0 0
53153 - 0 0 0 0 0 0 0 0 0 0 0 0
53154 - 0 0 0 0 0 0 10 10 10 34 34 34
53155 - 74 74 74 74 74 74 2 2 6 6 6 6
53156 -144 144 144 198 198 198 190 190 190 178 166 146
53157 -154 121 60 156 107 11 156 107 11 168 124 44
53158 -174 154 114 187 187 187 190 190 190 210 210 210
53159 -246 246 246 253 253 253 253 253 253 182 182 182
53160 - 6 6 6 2 2 6 2 2 6 2 2 6
53161 - 2 2 6 2 2 6 2 2 6 62 62 62
53162 - 74 74 74 34 34 34 14 14 14 0 0 0
53163 - 0 0 0 0 0 0 0 0 0 0 0 0
53164 - 0 0 0 0 0 0 0 0 0 0 0 0
53165 - 0 0 0 0 0 0 0 0 0 0 0 0
53166 - 0 0 0 0 0 0 0 0 0 0 0 0
53167 - 0 0 0 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 0 0 0 0 0 0
53173 - 0 0 0 0 0 0 0 0 0 0 0 0
53174 - 0 0 0 10 10 10 22 22 22 54 54 54
53175 - 94 94 94 18 18 18 2 2 6 46 46 46
53176 -234 234 234 221 221 221 190 190 190 190 190 190
53177 -190 190 190 187 187 187 187 187 187 190 190 190
53178 -190 190 190 195 195 195 214 214 214 242 242 242
53179 -253 253 253 253 253 253 253 253 253 253 253 253
53180 - 82 82 82 2 2 6 2 2 6 2 2 6
53181 - 2 2 6 2 2 6 2 2 6 14 14 14
53182 - 86 86 86 54 54 54 22 22 22 6 6 6
53183 - 0 0 0 0 0 0 0 0 0 0 0 0
53184 - 0 0 0 0 0 0 0 0 0 0 0 0
53185 - 0 0 0 0 0 0 0 0 0 0 0 0
53186 - 0 0 0 0 0 0 0 0 0 0 0 0
53187 - 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 0 0 0 0 0 0 0 0 0
53193 - 0 0 0 0 0 0 0 0 0 0 0 0
53194 - 6 6 6 18 18 18 46 46 46 90 90 90
53195 - 46 46 46 18 18 18 6 6 6 182 182 182
53196 -253 253 253 246 246 246 206 206 206 190 190 190
53197 -190 190 190 190 190 190 190 190 190 190 190 190
53198 -206 206 206 231 231 231 250 250 250 253 253 253
53199 -253 253 253 253 253 253 253 253 253 253 253 253
53200 -202 202 202 14 14 14 2 2 6 2 2 6
53201 - 2 2 6 2 2 6 2 2 6 2 2 6
53202 - 42 42 42 86 86 86 42 42 42 18 18 18
53203 - 6 6 6 0 0 0 0 0 0 0 0 0
53204 - 0 0 0 0 0 0 0 0 0 0 0 0
53205 - 0 0 0 0 0 0 0 0 0 0 0 0
53206 - 0 0 0 0 0 0 0 0 0 0 0 0
53207 - 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 0 0 0 0 0 0 0 0 0
53213 - 0 0 0 0 0 0 0 0 0 6 6 6
53214 - 14 14 14 38 38 38 74 74 74 66 66 66
53215 - 2 2 6 6 6 6 90 90 90 250 250 250
53216 -253 253 253 253 253 253 238 238 238 198 198 198
53217 -190 190 190 190 190 190 195 195 195 221 221 221
53218 -246 246 246 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 82 82 82 2 2 6 2 2 6
53221 - 2 2 6 2 2 6 2 2 6 2 2 6
53222 - 2 2 6 78 78 78 70 70 70 34 34 34
53223 - 14 14 14 6 6 6 0 0 0 0 0 0
53224 - 0 0 0 0 0 0 0 0 0 0 0 0
53225 - 0 0 0 0 0 0 0 0 0 0 0 0
53226 - 0 0 0 0 0 0 0 0 0 0 0 0
53227 - 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 - 0 0 0 0 0 0 0 0 0 0 0 0
53233 - 0 0 0 0 0 0 0 0 0 14 14 14
53234 - 34 34 34 66 66 66 78 78 78 6 6 6
53235 - 2 2 6 18 18 18 218 218 218 253 253 253
53236 -253 253 253 253 253 253 253 253 253 246 246 246
53237 -226 226 226 231 231 231 246 246 246 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 178 178 178 2 2 6 2 2 6
53241 - 2 2 6 2 2 6 2 2 6 2 2 6
53242 - 2 2 6 18 18 18 90 90 90 62 62 62
53243 - 30 30 30 10 10 10 0 0 0 0 0 0
53244 - 0 0 0 0 0 0 0 0 0 0 0 0
53245 - 0 0 0 0 0 0 0 0 0 0 0 0
53246 - 0 0 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
53253 - 0 0 0 0 0 0 10 10 10 26 26 26
53254 - 58 58 58 90 90 90 18 18 18 2 2 6
53255 - 2 2 6 110 110 110 253 253 253 253 253 253
53256 -253 253 253 253 253 253 253 253 253 253 253 253
53257 -250 250 250 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 231 231 231 18 18 18 2 2 6
53261 - 2 2 6 2 2 6 2 2 6 2 2 6
53262 - 2 2 6 2 2 6 18 18 18 94 94 94
53263 - 54 54 54 26 26 26 10 10 10 0 0 0
53264 - 0 0 0 0 0 0 0 0 0 0 0 0
53265 - 0 0 0 0 0 0 0 0 0 0 0 0
53266 - 0 0 0 0 0 0 0 0 0 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 0 0 0
53272 - 0 0 0 0 0 0 0 0 0 0 0 0
53273 - 0 0 0 6 6 6 22 22 22 50 50 50
53274 - 90 90 90 26 26 26 2 2 6 2 2 6
53275 - 14 14 14 195 195 195 250 250 250 253 253 253
53276 -253 253 253 253 253 253 253 253 253 253 253 253
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 -250 250 250 242 242 242 54 54 54 2 2 6
53281 - 2 2 6 2 2 6 2 2 6 2 2 6
53282 - 2 2 6 2 2 6 2 2 6 38 38 38
53283 - 86 86 86 50 50 50 22 22 22 6 6 6
53284 - 0 0 0 0 0 0 0 0 0 0 0 0
53285 - 0 0 0 0 0 0 0 0 0 0 0 0
53286 - 0 0 0 0 0 0 0 0 0 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 0 0 0
53292 - 0 0 0 0 0 0 0 0 0 0 0 0
53293 - 6 6 6 14 14 14 38 38 38 82 82 82
53294 - 34 34 34 2 2 6 2 2 6 2 2 6
53295 - 42 42 42 195 195 195 246 246 246 253 253 253
53296 -253 253 253 253 253 253 253 253 253 250 250 250
53297 -242 242 242 242 242 242 250 250 250 253 253 253
53298 -253 253 253 253 253 253 253 253 253 253 253 253
53299 -253 253 253 250 250 250 246 246 246 238 238 238
53300 -226 226 226 231 231 231 101 101 101 6 6 6
53301 - 2 2 6 2 2 6 2 2 6 2 2 6
53302 - 2 2 6 2 2 6 2 2 6 2 2 6
53303 - 38 38 38 82 82 82 42 42 42 14 14 14
53304 - 6 6 6 0 0 0 0 0 0 0 0 0
53305 - 0 0 0 0 0 0 0 0 0 0 0 0
53306 - 0 0 0 0 0 0 0 0 0 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 0 0 0
53312 - 0 0 0 0 0 0 0 0 0 0 0 0
53313 - 10 10 10 26 26 26 62 62 62 66 66 66
53314 - 2 2 6 2 2 6 2 2 6 6 6 6
53315 - 70 70 70 170 170 170 206 206 206 234 234 234
53316 -246 246 246 250 250 250 250 250 250 238 238 238
53317 -226 226 226 231 231 231 238 238 238 250 250 250
53318 -250 250 250 250 250 250 246 246 246 231 231 231
53319 -214 214 214 206 206 206 202 202 202 202 202 202
53320 -198 198 198 202 202 202 182 182 182 18 18 18
53321 - 2 2 6 2 2 6 2 2 6 2 2 6
53322 - 2 2 6 2 2 6 2 2 6 2 2 6
53323 - 2 2 6 62 62 62 66 66 66 30 30 30
53324 - 10 10 10 0 0 0 0 0 0 0 0 0
53325 - 0 0 0 0 0 0 0 0 0 0 0 0
53326 - 0 0 0 0 0 0 0 0 0 0 0 0
53327 - 0 0 0 0 0 0 0 0 0 0 0 0
53328 - 0 0 0 0 0 0 0 0 0 0 0 0
53329 - 0 0 0 0 0 0 0 0 0 0 0 0
53330 - 0 0 0 0 0 0 0 0 0 0 0 0
53331 - 0 0 0 0 0 0 0 0 0 0 0 0
53332 - 0 0 0 0 0 0 0 0 0 0 0 0
53333 - 14 14 14 42 42 42 82 82 82 18 18 18
53334 - 2 2 6 2 2 6 2 2 6 10 10 10
53335 - 94 94 94 182 182 182 218 218 218 242 242 242
53336 -250 250 250 253 253 253 253 253 253 250 250 250
53337 -234 234 234 253 253 253 253 253 253 253 253 253
53338 -253 253 253 253 253 253 253 253 253 246 246 246
53339 -238 238 238 226 226 226 210 210 210 202 202 202
53340 -195 195 195 195 195 195 210 210 210 158 158 158
53341 - 6 6 6 14 14 14 50 50 50 14 14 14
53342 - 2 2 6 2 2 6 2 2 6 2 2 6
53343 - 2 2 6 6 6 6 86 86 86 46 46 46
53344 - 18 18 18 6 6 6 0 0 0 0 0 0
53345 - 0 0 0 0 0 0 0 0 0 0 0 0
53346 - 0 0 0 0 0 0 0 0 0 0 0 0
53347 - 0 0 0 0 0 0 0 0 0 0 0 0
53348 - 0 0 0 0 0 0 0 0 0 0 0 0
53349 - 0 0 0 0 0 0 0 0 0 0 0 0
53350 - 0 0 0 0 0 0 0 0 0 0 0 0
53351 - 0 0 0 0 0 0 0 0 0 0 0 0
53352 - 0 0 0 0 0 0 0 0 0 6 6 6
53353 - 22 22 22 54 54 54 70 70 70 2 2 6
53354 - 2 2 6 10 10 10 2 2 6 22 22 22
53355 -166 166 166 231 231 231 250 250 250 253 253 253
53356 -253 253 253 253 253 253 253 253 253 250 250 250
53357 -242 242 242 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 246 246 246
53360 -231 231 231 206 206 206 198 198 198 226 226 226
53361 - 94 94 94 2 2 6 6 6 6 38 38 38
53362 - 30 30 30 2 2 6 2 2 6 2 2 6
53363 - 2 2 6 2 2 6 62 62 62 66 66 66
53364 - 26 26 26 10 10 10 0 0 0 0 0 0
53365 - 0 0 0 0 0 0 0 0 0 0 0 0
53366 - 0 0 0 0 0 0 0 0 0 0 0 0
53367 - 0 0 0 0 0 0 0 0 0 0 0 0
53368 - 0 0 0 0 0 0 0 0 0 0 0 0
53369 - 0 0 0 0 0 0 0 0 0 0 0 0
53370 - 0 0 0 0 0 0 0 0 0 0 0 0
53371 - 0 0 0 0 0 0 0 0 0 0 0 0
53372 - 0 0 0 0 0 0 0 0 0 10 10 10
53373 - 30 30 30 74 74 74 50 50 50 2 2 6
53374 - 26 26 26 26 26 26 2 2 6 106 106 106
53375 -238 238 238 253 253 253 253 253 253 253 253 253
53376 -253 253 253 253 253 253 253 253 253 253 253 253
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 246 246 246 218 218 218 202 202 202
53381 -210 210 210 14 14 14 2 2 6 2 2 6
53382 - 30 30 30 22 22 22 2 2 6 2 2 6
53383 - 2 2 6 2 2 6 18 18 18 86 86 86
53384 - 42 42 42 14 14 14 0 0 0 0 0 0
53385 - 0 0 0 0 0 0 0 0 0 0 0 0
53386 - 0 0 0 0 0 0 0 0 0 0 0 0
53387 - 0 0 0 0 0 0 0 0 0 0 0 0
53388 - 0 0 0 0 0 0 0 0 0 0 0 0
53389 - 0 0 0 0 0 0 0 0 0 0 0 0
53390 - 0 0 0 0 0 0 0 0 0 0 0 0
53391 - 0 0 0 0 0 0 0 0 0 0 0 0
53392 - 0 0 0 0 0 0 0 0 0 14 14 14
53393 - 42 42 42 90 90 90 22 22 22 2 2 6
53394 - 42 42 42 2 2 6 18 18 18 218 218 218
53395 -253 253 253 253 253 253 253 253 253 253 253 253
53396 -253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 221 221 221
53401 -218 218 218 101 101 101 2 2 6 14 14 14
53402 - 18 18 18 38 38 38 10 10 10 2 2 6
53403 - 2 2 6 2 2 6 2 2 6 78 78 78
53404 - 58 58 58 22 22 22 6 6 6 0 0 0
53405 - 0 0 0 0 0 0 0 0 0 0 0 0
53406 - 0 0 0 0 0 0 0 0 0 0 0 0
53407 - 0 0 0 0 0 0 0 0 0 0 0 0
53408 - 0 0 0 0 0 0 0 0 0 0 0 0
53409 - 0 0 0 0 0 0 0 0 0 0 0 0
53410 - 0 0 0 0 0 0 0 0 0 0 0 0
53411 - 0 0 0 0 0 0 0 0 0 0 0 0
53412 - 0 0 0 0 0 0 6 6 6 18 18 18
53413 - 54 54 54 82 82 82 2 2 6 26 26 26
53414 - 22 22 22 2 2 6 123 123 123 253 253 253
53415 -253 253 253 253 253 253 253 253 253 253 253 253
53416 -253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250
53421 -238 238 238 198 198 198 6 6 6 38 38 38
53422 - 58 58 58 26 26 26 38 38 38 2 2 6
53423 - 2 2 6 2 2 6 2 2 6 46 46 46
53424 - 78 78 78 30 30 30 10 10 10 0 0 0
53425 - 0 0 0 0 0 0 0 0 0 0 0 0
53426 - 0 0 0 0 0 0 0 0 0 0 0 0
53427 - 0 0 0 0 0 0 0 0 0 0 0 0
53428 - 0 0 0 0 0 0 0 0 0 0 0 0
53429 - 0 0 0 0 0 0 0 0 0 0 0 0
53430 - 0 0 0 0 0 0 0 0 0 0 0 0
53431 - 0 0 0 0 0 0 0 0 0 0 0 0
53432 - 0 0 0 0 0 0 10 10 10 30 30 30
53433 - 74 74 74 58 58 58 2 2 6 42 42 42
53434 - 2 2 6 22 22 22 231 231 231 253 253 253
53435 -253 253 253 253 253 253 253 253 253 253 253 253
53436 -253 253 253 253 253 253 253 253 253 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 253 253 253
53441 -253 253 253 246 246 246 46 46 46 38 38 38
53442 - 42 42 42 14 14 14 38 38 38 14 14 14
53443 - 2 2 6 2 2 6 2 2 6 6 6 6
53444 - 86 86 86 46 46 46 14 14 14 0 0 0
53445 - 0 0 0 0 0 0 0 0 0 0 0 0
53446 - 0 0 0 0 0 0 0 0 0 0 0 0
53447 - 0 0 0 0 0 0 0 0 0 0 0 0
53448 - 0 0 0 0 0 0 0 0 0 0 0 0
53449 - 0 0 0 0 0 0 0 0 0 0 0 0
53450 - 0 0 0 0 0 0 0 0 0 0 0 0
53451 - 0 0 0 0 0 0 0 0 0 0 0 0
53452 - 0 0 0 6 6 6 14 14 14 42 42 42
53453 - 90 90 90 18 18 18 18 18 18 26 26 26
53454 - 2 2 6 116 116 116 253 253 253 253 253 253
53455 -253 253 253 253 253 253 253 253 253 253 253 253
53456 -253 253 253 253 253 253 250 250 250 238 238 238
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 253 253 253
53461 -253 253 253 253 253 253 94 94 94 6 6 6
53462 - 2 2 6 2 2 6 10 10 10 34 34 34
53463 - 2 2 6 2 2 6 2 2 6 2 2 6
53464 - 74 74 74 58 58 58 22 22 22 6 6 6
53465 - 0 0 0 0 0 0 0 0 0 0 0 0
53466 - 0 0 0 0 0 0 0 0 0 0 0 0
53467 - 0 0 0 0 0 0 0 0 0 0 0 0
53468 - 0 0 0 0 0 0 0 0 0 0 0 0
53469 - 0 0 0 0 0 0 0 0 0 0 0 0
53470 - 0 0 0 0 0 0 0 0 0 0 0 0
53471 - 0 0 0 0 0 0 0 0 0 0 0 0
53472 - 0 0 0 10 10 10 26 26 26 66 66 66
53473 - 82 82 82 2 2 6 38 38 38 6 6 6
53474 - 14 14 14 210 210 210 253 253 253 253 253 253
53475 -253 253 253 253 253 253 253 253 253 253 253 253
53476 -253 253 253 253 253 253 246 246 246 242 242 242
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 253 253 253 253 253 253 253 253 253
53481 -253 253 253 253 253 253 144 144 144 2 2 6
53482 - 2 2 6 2 2 6 2 2 6 46 46 46
53483 - 2 2 6 2 2 6 2 2 6 2 2 6
53484 - 42 42 42 74 74 74 30 30 30 10 10 10
53485 - 0 0 0 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 0 0 0
53490 - 0 0 0 0 0 0 0 0 0 0 0 0
53491 - 0 0 0 0 0 0 0 0 0 0 0 0
53492 - 6 6 6 14 14 14 42 42 42 90 90 90
53493 - 26 26 26 6 6 6 42 42 42 2 2 6
53494 - 74 74 74 250 250 250 253 253 253 253 253 253
53495 -253 253 253 253 253 253 253 253 253 253 253 253
53496 -253 253 253 253 253 253 242 242 242 242 242 242
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 253 253 253 253 253 253 253 253 253
53501 -253 253 253 253 253 253 182 182 182 2 2 6
53502 - 2 2 6 2 2 6 2 2 6 46 46 46
53503 - 2 2 6 2 2 6 2 2 6 2 2 6
53504 - 10 10 10 86 86 86 38 38 38 10 10 10
53505 - 0 0 0 0 0 0 0 0 0 0 0 0
53506 - 0 0 0 0 0 0 0 0 0 0 0 0
53507 - 0 0 0 0 0 0 0 0 0 0 0 0
53508 - 0 0 0 0 0 0 0 0 0 0 0 0
53509 - 0 0 0 0 0 0 0 0 0 0 0 0
53510 - 0 0 0 0 0 0 0 0 0 0 0 0
53511 - 0 0 0 0 0 0 0 0 0 0 0 0
53512 - 10 10 10 26 26 26 66 66 66 82 82 82
53513 - 2 2 6 22 22 22 18 18 18 2 2 6
53514 -149 149 149 253 253 253 253 253 253 253 253 253
53515 -253 253 253 253 253 253 253 253 253 253 253 253
53516 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253 253 253 253
53521 -253 253 253 253 253 253 206 206 206 2 2 6
53522 - 2 2 6 2 2 6 2 2 6 38 38 38
53523 - 2 2 6 2 2 6 2 2 6 2 2 6
53524 - 6 6 6 86 86 86 46 46 46 14 14 14
53525 - 0 0 0 0 0 0 0 0 0 0 0 0
53526 - 0 0 0 0 0 0 0 0 0 0 0 0
53527 - 0 0 0 0 0 0 0 0 0 0 0 0
53528 - 0 0 0 0 0 0 0 0 0 0 0 0
53529 - 0 0 0 0 0 0 0 0 0 0 0 0
53530 - 0 0 0 0 0 0 0 0 0 0 0 0
53531 - 0 0 0 0 0 0 0 0 0 6 6 6
53532 - 18 18 18 46 46 46 86 86 86 18 18 18
53533 - 2 2 6 34 34 34 10 10 10 6 6 6
53534 -210 210 210 253 253 253 253 253 253 253 253 253
53535 -253 253 253 253 253 253 253 253 253 253 253 253
53536 -253 253 253 253 253 253 234 234 234 242 242 242
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 -253 253 253 253 253 253 253 253 253 253 253 253
53541 -253 253 253 253 253 253 221 221 221 6 6 6
53542 - 2 2 6 2 2 6 6 6 6 30 30 30
53543 - 2 2 6 2 2 6 2 2 6 2 2 6
53544 - 2 2 6 82 82 82 54 54 54 18 18 18
53545 - 6 6 6 0 0 0 0 0 0 0 0 0
53546 - 0 0 0 0 0 0 0 0 0 0 0 0
53547 - 0 0 0 0 0 0 0 0 0 0 0 0
53548 - 0 0 0 0 0 0 0 0 0 0 0 0
53549 - 0 0 0 0 0 0 0 0 0 0 0 0
53550 - 0 0 0 0 0 0 0 0 0 0 0 0
53551 - 0 0 0 0 0 0 0 0 0 10 10 10
53552 - 26 26 26 66 66 66 62 62 62 2 2 6
53553 - 2 2 6 38 38 38 10 10 10 26 26 26
53554 -238 238 238 253 253 253 253 253 253 253 253 253
53555 -253 253 253 253 253 253 253 253 253 253 253 253
53556 -253 253 253 253 253 253 231 231 231 238 238 238
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 -253 253 253 253 253 253 253 253 253 253 253 253
53561 -253 253 253 253 253 253 231 231 231 6 6 6
53562 - 2 2 6 2 2 6 10 10 10 30 30 30
53563 - 2 2 6 2 2 6 2 2 6 2 2 6
53564 - 2 2 6 66 66 66 58 58 58 22 22 22
53565 - 6 6 6 0 0 0 0 0 0 0 0 0
53566 - 0 0 0 0 0 0 0 0 0 0 0 0
53567 - 0 0 0 0 0 0 0 0 0 0 0 0
53568 - 0 0 0 0 0 0 0 0 0 0 0 0
53569 - 0 0 0 0 0 0 0 0 0 0 0 0
53570 - 0 0 0 0 0 0 0 0 0 0 0 0
53571 - 0 0 0 0 0 0 0 0 0 10 10 10
53572 - 38 38 38 78 78 78 6 6 6 2 2 6
53573 - 2 2 6 46 46 46 14 14 14 42 42 42
53574 -246 246 246 253 253 253 253 253 253 253 253 253
53575 -253 253 253 253 253 253 253 253 253 253 253 253
53576 -253 253 253 253 253 253 231 231 231 242 242 242
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 253 253 253 253 253 253 253 253 253
53581 -253 253 253 253 253 253 234 234 234 10 10 10
53582 - 2 2 6 2 2 6 22 22 22 14 14 14
53583 - 2 2 6 2 2 6 2 2 6 2 2 6
53584 - 2 2 6 66 66 66 62 62 62 22 22 22
53585 - 6 6 6 0 0 0 0 0 0 0 0 0
53586 - 0 0 0 0 0 0 0 0 0 0 0 0
53587 - 0 0 0 0 0 0 0 0 0 0 0 0
53588 - 0 0 0 0 0 0 0 0 0 0 0 0
53589 - 0 0 0 0 0 0 0 0 0 0 0 0
53590 - 0 0 0 0 0 0 0 0 0 0 0 0
53591 - 0 0 0 0 0 0 6 6 6 18 18 18
53592 - 50 50 50 74 74 74 2 2 6 2 2 6
53593 - 14 14 14 70 70 70 34 34 34 62 62 62
53594 -250 250 250 253 253 253 253 253 253 253 253 253
53595 -253 253 253 253 253 253 253 253 253 253 253 253
53596 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253 253 253 253
53601 -253 253 253 253 253 253 234 234 234 14 14 14
53602 - 2 2 6 2 2 6 30 30 30 2 2 6
53603 - 2 2 6 2 2 6 2 2 6 2 2 6
53604 - 2 2 6 66 66 66 62 62 62 22 22 22
53605 - 6 6 6 0 0 0 0 0 0 0 0 0
53606 - 0 0 0 0 0 0 0 0 0 0 0 0
53607 - 0 0 0 0 0 0 0 0 0 0 0 0
53608 - 0 0 0 0 0 0 0 0 0 0 0 0
53609 - 0 0 0 0 0 0 0 0 0 0 0 0
53610 - 0 0 0 0 0 0 0 0 0 0 0 0
53611 - 0 0 0 0 0 0 6 6 6 18 18 18
53612 - 54 54 54 62 62 62 2 2 6 2 2 6
53613 - 2 2 6 30 30 30 46 46 46 70 70 70
53614 -250 250 250 253 253 253 253 253 253 253 253 253
53615 -253 253 253 253 253 253 253 253 253 253 253 253
53616 -253 253 253 253 253 253 231 231 231 246 246 246
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 -253 253 253 253 253 253 253 253 253 253 253 253
53621 -253 253 253 253 253 253 226 226 226 10 10 10
53622 - 2 2 6 6 6 6 30 30 30 2 2 6
53623 - 2 2 6 2 2 6 2 2 6 2 2 6
53624 - 2 2 6 66 66 66 58 58 58 22 22 22
53625 - 6 6 6 0 0 0 0 0 0 0 0 0
53626 - 0 0 0 0 0 0 0 0 0 0 0 0
53627 - 0 0 0 0 0 0 0 0 0 0 0 0
53628 - 0 0 0 0 0 0 0 0 0 0 0 0
53629 - 0 0 0 0 0 0 0 0 0 0 0 0
53630 - 0 0 0 0 0 0 0 0 0 0 0 0
53631 - 0 0 0 0 0 0 6 6 6 22 22 22
53632 - 58 58 58 62 62 62 2 2 6 2 2 6
53633 - 2 2 6 2 2 6 30 30 30 78 78 78
53634 -250 250 250 253 253 253 253 253 253 253 253 253
53635 -253 253 253 253 253 253 253 253 253 253 253 253
53636 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
53640 -253 253 253 253 253 253 253 253 253 253 253 253
53641 -253 253 253 253 253 253 206 206 206 2 2 6
53642 - 22 22 22 34 34 34 18 14 6 22 22 22
53643 - 26 26 26 18 18 18 6 6 6 2 2 6
53644 - 2 2 6 82 82 82 54 54 54 18 18 18
53645 - 6 6 6 0 0 0 0 0 0 0 0 0
53646 - 0 0 0 0 0 0 0 0 0 0 0 0
53647 - 0 0 0 0 0 0 0 0 0 0 0 0
53648 - 0 0 0 0 0 0 0 0 0 0 0 0
53649 - 0 0 0 0 0 0 0 0 0 0 0 0
53650 - 0 0 0 0 0 0 0 0 0 0 0 0
53651 - 0 0 0 0 0 0 6 6 6 26 26 26
53652 - 62 62 62 106 106 106 74 54 14 185 133 11
53653 -210 162 10 121 92 8 6 6 6 62 62 62
53654 -238 238 238 253 253 253 253 253 253 253 253 253
53655 -253 253 253 253 253 253 253 253 253 253 253 253
53656 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253 253 253 253
53660 -253 253 253 253 253 253 253 253 253 253 253 253
53661 -253 253 253 253 253 253 158 158 158 18 18 18
53662 - 14 14 14 2 2 6 2 2 6 2 2 6
53663 - 6 6 6 18 18 18 66 66 66 38 38 38
53664 - 6 6 6 94 94 94 50 50 50 18 18 18
53665 - 6 6 6 0 0 0 0 0 0 0 0 0
53666 - 0 0 0 0 0 0 0 0 0 0 0 0
53667 - 0 0 0 0 0 0 0 0 0 0 0 0
53668 - 0 0 0 0 0 0 0 0 0 0 0 0
53669 - 0 0 0 0 0 0 0 0 0 0 0 0
53670 - 0 0 0 0 0 0 0 0 0 6 6 6
53671 - 10 10 10 10 10 10 18 18 18 38 38 38
53672 - 78 78 78 142 134 106 216 158 10 242 186 14
53673 -246 190 14 246 190 14 156 118 10 10 10 10
53674 - 90 90 90 238 238 238 253 253 253 253 253 253
53675 -253 253 253 253 253 253 253 253 253 253 253 253
53676 -253 253 253 253 253 253 231 231 231 250 250 250
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 -253 253 253 253 253 253 253 253 253 253 253 253
53680 -253 253 253 253 253 253 253 253 253 246 230 190
53681 -238 204 91 238 204 91 181 142 44 37 26 9
53682 - 2 2 6 2 2 6 2 2 6 2 2 6
53683 - 2 2 6 2 2 6 38 38 38 46 46 46
53684 - 26 26 26 106 106 106 54 54 54 18 18 18
53685 - 6 6 6 0 0 0 0 0 0 0 0 0
53686 - 0 0 0 0 0 0 0 0 0 0 0 0
53687 - 0 0 0 0 0 0 0 0 0 0 0 0
53688 - 0 0 0 0 0 0 0 0 0 0 0 0
53689 - 0 0 0 0 0 0 0 0 0 0 0 0
53690 - 0 0 0 6 6 6 14 14 14 22 22 22
53691 - 30 30 30 38 38 38 50 50 50 70 70 70
53692 -106 106 106 190 142 34 226 170 11 242 186 14
53693 -246 190 14 246 190 14 246 190 14 154 114 10
53694 - 6 6 6 74 74 74 226 226 226 253 253 253
53695 -253 253 253 253 253 253 253 253 253 253 253 253
53696 -253 253 253 253 253 253 231 231 231 250 250 250
53697 -253 253 253 253 253 253 253 253 253 253 253 253
53698 -253 253 253 253 253 253 253 253 253 253 253 253
53699 -253 253 253 253 253 253 253 253 253 253 253 253
53700 -253 253 253 253 253 253 253 253 253 228 184 62
53701 -241 196 14 241 208 19 232 195 16 38 30 10
53702 - 2 2 6 2 2 6 2 2 6 2 2 6
53703 - 2 2 6 6 6 6 30 30 30 26 26 26
53704 -203 166 17 154 142 90 66 66 66 26 26 26
53705 - 6 6 6 0 0 0 0 0 0 0 0 0
53706 - 0 0 0 0 0 0 0 0 0 0 0 0
53707 - 0 0 0 0 0 0 0 0 0 0 0 0
53708 - 0 0 0 0 0 0 0 0 0 0 0 0
53709 - 0 0 0 0 0 0 0 0 0 0 0 0
53710 - 6 6 6 18 18 18 38 38 38 58 58 58
53711 - 78 78 78 86 86 86 101 101 101 123 123 123
53712 -175 146 61 210 150 10 234 174 13 246 186 14
53713 -246 190 14 246 190 14 246 190 14 238 190 10
53714 -102 78 10 2 2 6 46 46 46 198 198 198
53715 -253 253 253 253 253 253 253 253 253 253 253 253
53716 -253 253 253 253 253 253 234 234 234 242 242 242
53717 -253 253 253 253 253 253 253 253 253 253 253 253
53718 -253 253 253 253 253 253 253 253 253 253 253 253
53719 -253 253 253 253 253 253 253 253 253 253 253 253
53720 -253 253 253 253 253 253 253 253 253 224 178 62
53721 -242 186 14 241 196 14 210 166 10 22 18 6
53722 - 2 2 6 2 2 6 2 2 6 2 2 6
53723 - 2 2 6 2 2 6 6 6 6 121 92 8
53724 -238 202 15 232 195 16 82 82 82 34 34 34
53725 - 10 10 10 0 0 0 0 0 0 0 0 0
53726 - 0 0 0 0 0 0 0 0 0 0 0 0
53727 - 0 0 0 0 0 0 0 0 0 0 0 0
53728 - 0 0 0 0 0 0 0 0 0 0 0 0
53729 - 0 0 0 0 0 0 0 0 0 0 0 0
53730 - 14 14 14 38 38 38 70 70 70 154 122 46
53731 -190 142 34 200 144 11 197 138 11 197 138 11
53732 -213 154 11 226 170 11 242 186 14 246 190 14
53733 -246 190 14 246 190 14 246 190 14 246 190 14
53734 -225 175 15 46 32 6 2 2 6 22 22 22
53735 -158 158 158 250 250 250 253 253 253 253 253 253
53736 -253 253 253 253 253 253 253 253 253 253 253 253
53737 -253 253 253 253 253 253 253 253 253 253 253 253
53738 -253 253 253 253 253 253 253 253 253 253 253 253
53739 -253 253 253 253 253 253 253 253 253 253 253 253
53740 -253 253 253 250 250 250 242 242 242 224 178 62
53741 -239 182 13 236 186 11 213 154 11 46 32 6
53742 - 2 2 6 2 2 6 2 2 6 2 2 6
53743 - 2 2 6 2 2 6 61 42 6 225 175 15
53744 -238 190 10 236 186 11 112 100 78 42 42 42
53745 - 14 14 14 0 0 0 0 0 0 0 0 0
53746 - 0 0 0 0 0 0 0 0 0 0 0 0
53747 - 0 0 0 0 0 0 0 0 0 0 0 0
53748 - 0 0 0 0 0 0 0 0 0 0 0 0
53749 - 0 0 0 0 0 0 0 0 0 6 6 6
53750 - 22 22 22 54 54 54 154 122 46 213 154 11
53751 -226 170 11 230 174 11 226 170 11 226 170 11
53752 -236 178 12 242 186 14 246 190 14 246 190 14
53753 -246 190 14 246 190 14 246 190 14 246 190 14
53754 -241 196 14 184 144 12 10 10 10 2 2 6
53755 - 6 6 6 116 116 116 242 242 242 253 253 253
53756 -253 253 253 253 253 253 253 253 253 253 253 253
53757 -253 253 253 253 253 253 253 253 253 253 253 253
53758 -253 253 253 253 253 253 253 253 253 253 253 253
53759 -253 253 253 253 253 253 253 253 253 253 253 253
53760 -253 253 253 231 231 231 198 198 198 214 170 54
53761 -236 178 12 236 178 12 210 150 10 137 92 6
53762 - 18 14 6 2 2 6 2 2 6 2 2 6
53763 - 6 6 6 70 47 6 200 144 11 236 178 12
53764 -239 182 13 239 182 13 124 112 88 58 58 58
53765 - 22 22 22 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 10 10 10
53770 - 30 30 30 70 70 70 180 133 36 226 170 11
53771 -239 182 13 242 186 14 242 186 14 246 186 14
53772 -246 190 14 246 190 14 246 190 14 246 190 14
53773 -246 190 14 246 190 14 246 190 14 246 190 14
53774 -246 190 14 232 195 16 98 70 6 2 2 6
53775 - 2 2 6 2 2 6 66 66 66 221 221 221
53776 -253 253 253 253 253 253 253 253 253 253 253 253
53777 -253 253 253 253 253 253 253 253 253 253 253 253
53778 -253 253 253 253 253 253 253 253 253 253 253 253
53779 -253 253 253 253 253 253 253 253 253 253 253 253
53780 -253 253 253 206 206 206 198 198 198 214 166 58
53781 -230 174 11 230 174 11 216 158 10 192 133 9
53782 -163 110 8 116 81 8 102 78 10 116 81 8
53783 -167 114 7 197 138 11 226 170 11 239 182 13
53784 -242 186 14 242 186 14 162 146 94 78 78 78
53785 - 34 34 34 14 14 14 6 6 6 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 6 6 6
53790 - 30 30 30 78 78 78 190 142 34 226 170 11
53791 -239 182 13 246 190 14 246 190 14 246 190 14
53792 -246 190 14 246 190 14 246 190 14 246 190 14
53793 -246 190 14 246 190 14 246 190 14 246 190 14
53794 -246 190 14 241 196 14 203 166 17 22 18 6
53795 - 2 2 6 2 2 6 2 2 6 38 38 38
53796 -218 218 218 253 253 253 253 253 253 253 253 253
53797 -253 253 253 253 253 253 253 253 253 253 253 253
53798 -253 253 253 253 253 253 253 253 253 253 253 253
53799 -253 253 253 253 253 253 253 253 253 253 253 253
53800 -250 250 250 206 206 206 198 198 198 202 162 69
53801 -226 170 11 236 178 12 224 166 10 210 150 10
53802 -200 144 11 197 138 11 192 133 9 197 138 11
53803 -210 150 10 226 170 11 242 186 14 246 190 14
53804 -246 190 14 246 186 14 225 175 15 124 112 88
53805 - 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
53810 - 30 30 30 78 78 78 174 135 50 224 166 10
53811 -239 182 13 246 190 14 246 190 14 246 190 14
53812 -246 190 14 246 190 14 246 190 14 246 190 14
53813 -246 190 14 246 190 14 246 190 14 246 190 14
53814 -246 190 14 246 190 14 241 196 14 139 102 15
53815 - 2 2 6 2 2 6 2 2 6 2 2 6
53816 - 78 78 78 250 250 250 253 253 253 253 253 253
53817 -253 253 253 253 253 253 253 253 253 253 253 253
53818 -253 253 253 253 253 253 253 253 253 253 253 253
53819 -253 253 253 253 253 253 253 253 253 253 253 253
53820 -250 250 250 214 214 214 198 198 198 190 150 46
53821 -219 162 10 236 178 12 234 174 13 224 166 10
53822 -216 158 10 213 154 11 213 154 11 216 158 10
53823 -226 170 11 239 182 13 246 190 14 246 190 14
53824 -246 190 14 246 190 14 242 186 14 206 162 42
53825 -101 101 101 58 58 58 30 30 30 14 14 14
53826 - 6 6 6 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 10 10 10
53830 - 30 30 30 74 74 74 174 135 50 216 158 10
53831 -236 178 12 246 190 14 246 190 14 246 190 14
53832 -246 190 14 246 190 14 246 190 14 246 190 14
53833 -246 190 14 246 190 14 246 190 14 246 190 14
53834 -246 190 14 246 190 14 241 196 14 226 184 13
53835 - 61 42 6 2 2 6 2 2 6 2 2 6
53836 - 22 22 22 238 238 238 253 253 253 253 253 253
53837 -253 253 253 253 253 253 253 253 253 253 253 253
53838 -253 253 253 253 253 253 253 253 253 253 253 253
53839 -253 253 253 253 253 253 253 253 253 253 253 253
53840 -253 253 253 226 226 226 187 187 187 180 133 36
53841 -216 158 10 236 178 12 239 182 13 236 178 12
53842 -230 174 11 226 170 11 226 170 11 230 174 11
53843 -236 178 12 242 186 14 246 190 14 246 190 14
53844 -246 190 14 246 190 14 246 186 14 239 182 13
53845 -206 162 42 106 106 106 66 66 66 34 34 34
53846 - 14 14 14 6 6 6 0 0 0 0 0 0
53847 - 0 0 0 0 0 0 0 0 0 0 0 0
53848 - 0 0 0 0 0 0 0 0 0 0 0 0
53849 - 0 0 0 0 0 0 0 0 0 6 6 6
53850 - 26 26 26 70 70 70 163 133 67 213 154 11
53851 -236 178 12 246 190 14 246 190 14 246 190 14
53852 -246 190 14 246 190 14 246 190 14 246 190 14
53853 -246 190 14 246 190 14 246 190 14 246 190 14
53854 -246 190 14 246 190 14 246 190 14 241 196 14
53855 -190 146 13 18 14 6 2 2 6 2 2 6
53856 - 46 46 46 246 246 246 253 253 253 253 253 253
53857 -253 253 253 253 253 253 253 253 253 253 253 253
53858 -253 253 253 253 253 253 253 253 253 253 253 253
53859 -253 253 253 253 253 253 253 253 253 253 253 253
53860 -253 253 253 221 221 221 86 86 86 156 107 11
53861 -216 158 10 236 178 12 242 186 14 246 186 14
53862 -242 186 14 239 182 13 239 182 13 242 186 14
53863 -242 186 14 246 186 14 246 190 14 246 190 14
53864 -246 190 14 246 190 14 246 190 14 246 190 14
53865 -242 186 14 225 175 15 142 122 72 66 66 66
53866 - 30 30 30 10 10 10 0 0 0 0 0 0
53867 - 0 0 0 0 0 0 0 0 0 0 0 0
53868 - 0 0 0 0 0 0 0 0 0 0 0 0
53869 - 0 0 0 0 0 0 0 0 0 6 6 6
53870 - 26 26 26 70 70 70 163 133 67 210 150 10
53871 -236 178 12 246 190 14 246 190 14 246 190 14
53872 -246 190 14 246 190 14 246 190 14 246 190 14
53873 -246 190 14 246 190 14 246 190 14 246 190 14
53874 -246 190 14 246 190 14 246 190 14 246 190 14
53875 -232 195 16 121 92 8 34 34 34 106 106 106
53876 -221 221 221 253 253 253 253 253 253 253 253 253
53877 -253 253 253 253 253 253 253 253 253 253 253 253
53878 -253 253 253 253 253 253 253 253 253 253 253 253
53879 -253 253 253 253 253 253 253 253 253 253 253 253
53880 -242 242 242 82 82 82 18 14 6 163 110 8
53881 -216 158 10 236 178 12 242 186 14 246 190 14
53882 -246 190 14 246 190 14 246 190 14 246 190 14
53883 -246 190 14 246 190 14 246 190 14 246 190 14
53884 -246 190 14 246 190 14 246 190 14 246 190 14
53885 -246 190 14 246 190 14 242 186 14 163 133 67
53886 - 46 46 46 18 18 18 6 6 6 0 0 0
53887 - 0 0 0 0 0 0 0 0 0 0 0 0
53888 - 0 0 0 0 0 0 0 0 0 0 0 0
53889 - 0 0 0 0 0 0 0 0 0 10 10 10
53890 - 30 30 30 78 78 78 163 133 67 210 150 10
53891 -236 178 12 246 186 14 246 190 14 246 190 14
53892 -246 190 14 246 190 14 246 190 14 246 190 14
53893 -246 190 14 246 190 14 246 190 14 246 190 14
53894 -246 190 14 246 190 14 246 190 14 246 190 14
53895 -241 196 14 215 174 15 190 178 144 253 253 253
53896 -253 253 253 253 253 253 253 253 253 253 253 253
53897 -253 253 253 253 253 253 253 253 253 253 253 253
53898 -253 253 253 253 253 253 253 253 253 253 253 253
53899 -253 253 253 253 253 253 253 253 253 218 218 218
53900 - 58 58 58 2 2 6 22 18 6 167 114 7
53901 -216 158 10 236 178 12 246 186 14 246 190 14
53902 -246 190 14 246 190 14 246 190 14 246 190 14
53903 -246 190 14 246 190 14 246 190 14 246 190 14
53904 -246 190 14 246 190 14 246 190 14 246 190 14
53905 -246 190 14 246 186 14 242 186 14 190 150 46
53906 - 54 54 54 22 22 22 6 6 6 0 0 0
53907 - 0 0 0 0 0 0 0 0 0 0 0 0
53908 - 0 0 0 0 0 0 0 0 0 0 0 0
53909 - 0 0 0 0 0 0 0 0 0 14 14 14
53910 - 38 38 38 86 86 86 180 133 36 213 154 11
53911 -236 178 12 246 186 14 246 190 14 246 190 14
53912 -246 190 14 246 190 14 246 190 14 246 190 14
53913 -246 190 14 246 190 14 246 190 14 246 190 14
53914 -246 190 14 246 190 14 246 190 14 246 190 14
53915 -246 190 14 232 195 16 190 146 13 214 214 214
53916 -253 253 253 253 253 253 253 253 253 253 253 253
53917 -253 253 253 253 253 253 253 253 253 253 253 253
53918 -253 253 253 253 253 253 253 253 253 253 253 253
53919 -253 253 253 250 250 250 170 170 170 26 26 26
53920 - 2 2 6 2 2 6 37 26 9 163 110 8
53921 -219 162 10 239 182 13 246 186 14 246 190 14
53922 -246 190 14 246 190 14 246 190 14 246 190 14
53923 -246 190 14 246 190 14 246 190 14 246 190 14
53924 -246 190 14 246 190 14 246 190 14 246 190 14
53925 -246 186 14 236 178 12 224 166 10 142 122 72
53926 - 46 46 46 18 18 18 6 6 6 0 0 0
53927 - 0 0 0 0 0 0 0 0 0 0 0 0
53928 - 0 0 0 0 0 0 0 0 0 0 0 0
53929 - 0 0 0 0 0 0 6 6 6 18 18 18
53930 - 50 50 50 109 106 95 192 133 9 224 166 10
53931 -242 186 14 246 190 14 246 190 14 246 190 14
53932 -246 190 14 246 190 14 246 190 14 246 190 14
53933 -246 190 14 246 190 14 246 190 14 246 190 14
53934 -246 190 14 246 190 14 246 190 14 246 190 14
53935 -242 186 14 226 184 13 210 162 10 142 110 46
53936 -226 226 226 253 253 253 253 253 253 253 253 253
53937 -253 253 253 253 253 253 253 253 253 253 253 253
53938 -253 253 253 253 253 253 253 253 253 253 253 253
53939 -198 198 198 66 66 66 2 2 6 2 2 6
53940 - 2 2 6 2 2 6 50 34 6 156 107 11
53941 -219 162 10 239 182 13 246 186 14 246 190 14
53942 -246 190 14 246 190 14 246 190 14 246 190 14
53943 -246 190 14 246 190 14 246 190 14 246 190 14
53944 -246 190 14 246 190 14 246 190 14 242 186 14
53945 -234 174 13 213 154 11 154 122 46 66 66 66
53946 - 30 30 30 10 10 10 0 0 0 0 0 0
53947 - 0 0 0 0 0 0 0 0 0 0 0 0
53948 - 0 0 0 0 0 0 0 0 0 0 0 0
53949 - 0 0 0 0 0 0 6 6 6 22 22 22
53950 - 58 58 58 154 121 60 206 145 10 234 174 13
53951 -242 186 14 246 186 14 246 190 14 246 190 14
53952 -246 190 14 246 190 14 246 190 14 246 190 14
53953 -246 190 14 246 190 14 246 190 14 246 190 14
53954 -246 190 14 246 190 14 246 190 14 246 190 14
53955 -246 186 14 236 178 12 210 162 10 163 110 8
53956 - 61 42 6 138 138 138 218 218 218 250 250 250
53957 -253 253 253 253 253 253 253 253 253 250 250 250
53958 -242 242 242 210 210 210 144 144 144 66 66 66
53959 - 6 6 6 2 2 6 2 2 6 2 2 6
53960 - 2 2 6 2 2 6 61 42 6 163 110 8
53961 -216 158 10 236 178 12 246 190 14 246 190 14
53962 -246 190 14 246 190 14 246 190 14 246 190 14
53963 -246 190 14 246 190 14 246 190 14 246 190 14
53964 -246 190 14 239 182 13 230 174 11 216 158 10
53965 -190 142 34 124 112 88 70 70 70 38 38 38
53966 - 18 18 18 6 6 6 0 0 0 0 0 0
53967 - 0 0 0 0 0 0 0 0 0 0 0 0
53968 - 0 0 0 0 0 0 0 0 0 0 0 0
53969 - 0 0 0 0 0 0 6 6 6 22 22 22
53970 - 62 62 62 168 124 44 206 145 10 224 166 10
53971 -236 178 12 239 182 13 242 186 14 242 186 14
53972 -246 186 14 246 190 14 246 190 14 246 190 14
53973 -246 190 14 246 190 14 246 190 14 246 190 14
53974 -246 190 14 246 190 14 246 190 14 246 190 14
53975 -246 190 14 236 178 12 216 158 10 175 118 6
53976 - 80 54 7 2 2 6 6 6 6 30 30 30
53977 - 54 54 54 62 62 62 50 50 50 38 38 38
53978 - 14 14 14 2 2 6 2 2 6 2 2 6
53979 - 2 2 6 2 2 6 2 2 6 2 2 6
53980 - 2 2 6 6 6 6 80 54 7 167 114 7
53981 -213 154 11 236 178 12 246 190 14 246 190 14
53982 -246 190 14 246 190 14 246 190 14 246 190 14
53983 -246 190 14 242 186 14 239 182 13 239 182 13
53984 -230 174 11 210 150 10 174 135 50 124 112 88
53985 - 82 82 82 54 54 54 34 34 34 18 18 18
53986 - 6 6 6 0 0 0 0 0 0 0 0 0
53987 - 0 0 0 0 0 0 0 0 0 0 0 0
53988 - 0 0 0 0 0 0 0 0 0 0 0 0
53989 - 0 0 0 0 0 0 6 6 6 18 18 18
53990 - 50 50 50 158 118 36 192 133 9 200 144 11
53991 -216 158 10 219 162 10 224 166 10 226 170 11
53992 -230 174 11 236 178 12 239 182 13 239 182 13
53993 -242 186 14 246 186 14 246 190 14 246 190 14
53994 -246 190 14 246 190 14 246 190 14 246 190 14
53995 -246 186 14 230 174 11 210 150 10 163 110 8
53996 -104 69 6 10 10 10 2 2 6 2 2 6
53997 - 2 2 6 2 2 6 2 2 6 2 2 6
53998 - 2 2 6 2 2 6 2 2 6 2 2 6
53999 - 2 2 6 2 2 6 2 2 6 2 2 6
54000 - 2 2 6 6 6 6 91 60 6 167 114 7
54001 -206 145 10 230 174 11 242 186 14 246 190 14
54002 -246 190 14 246 190 14 246 186 14 242 186 14
54003 -239 182 13 230 174 11 224 166 10 213 154 11
54004 -180 133 36 124 112 88 86 86 86 58 58 58
54005 - 38 38 38 22 22 22 10 10 10 6 6 6
54006 - 0 0 0 0 0 0 0 0 0 0 0 0
54007 - 0 0 0 0 0 0 0 0 0 0 0 0
54008 - 0 0 0 0 0 0 0 0 0 0 0 0
54009 - 0 0 0 0 0 0 0 0 0 14 14 14
54010 - 34 34 34 70 70 70 138 110 50 158 118 36
54011 -167 114 7 180 123 7 192 133 9 197 138 11
54012 -200 144 11 206 145 10 213 154 11 219 162 10
54013 -224 166 10 230 174 11 239 182 13 242 186 14
54014 -246 186 14 246 186 14 246 186 14 246 186 14
54015 -239 182 13 216 158 10 185 133 11 152 99 6
54016 -104 69 6 18 14 6 2 2 6 2 2 6
54017 - 2 2 6 2 2 6 2 2 6 2 2 6
54018 - 2 2 6 2 2 6 2 2 6 2 2 6
54019 - 2 2 6 2 2 6 2 2 6 2 2 6
54020 - 2 2 6 6 6 6 80 54 7 152 99 6
54021 -192 133 9 219 162 10 236 178 12 239 182 13
54022 -246 186 14 242 186 14 239 182 13 236 178 12
54023 -224 166 10 206 145 10 192 133 9 154 121 60
54024 - 94 94 94 62 62 62 42 42 42 22 22 22
54025 - 14 14 14 6 6 6 0 0 0 0 0 0
54026 - 0 0 0 0 0 0 0 0 0 0 0 0
54027 - 0 0 0 0 0 0 0 0 0 0 0 0
54028 - 0 0 0 0 0 0 0 0 0 0 0 0
54029 - 0 0 0 0 0 0 0 0 0 6 6 6
54030 - 18 18 18 34 34 34 58 58 58 78 78 78
54031 -101 98 89 124 112 88 142 110 46 156 107 11
54032 -163 110 8 167 114 7 175 118 6 180 123 7
54033 -185 133 11 197 138 11 210 150 10 219 162 10
54034 -226 170 11 236 178 12 236 178 12 234 174 13
54035 -219 162 10 197 138 11 163 110 8 130 83 6
54036 - 91 60 6 10 10 10 2 2 6 2 2 6
54037 - 18 18 18 38 38 38 38 38 38 38 38 38
54038 - 38 38 38 38 38 38 38 38 38 38 38 38
54039 - 38 38 38 38 38 38 26 26 26 2 2 6
54040 - 2 2 6 6 6 6 70 47 6 137 92 6
54041 -175 118 6 200 144 11 219 162 10 230 174 11
54042 -234 174 13 230 174 11 219 162 10 210 150 10
54043 -192 133 9 163 110 8 124 112 88 82 82 82
54044 - 50 50 50 30 30 30 14 14 14 6 6 6
54045 - 0 0 0 0 0 0 0 0 0 0 0 0
54046 - 0 0 0 0 0 0 0 0 0 0 0 0
54047 - 0 0 0 0 0 0 0 0 0 0 0 0
54048 - 0 0 0 0 0 0 0 0 0 0 0 0
54049 - 0 0 0 0 0 0 0 0 0 0 0 0
54050 - 6 6 6 14 14 14 22 22 22 34 34 34
54051 - 42 42 42 58 58 58 74 74 74 86 86 86
54052 -101 98 89 122 102 70 130 98 46 121 87 25
54053 -137 92 6 152 99 6 163 110 8 180 123 7
54054 -185 133 11 197 138 11 206 145 10 200 144 11
54055 -180 123 7 156 107 11 130 83 6 104 69 6
54056 - 50 34 6 54 54 54 110 110 110 101 98 89
54057 - 86 86 86 82 82 82 78 78 78 78 78 78
54058 - 78 78 78 78 78 78 78 78 78 78 78 78
54059 - 78 78 78 82 82 82 86 86 86 94 94 94
54060 -106 106 106 101 101 101 86 66 34 124 80 6
54061 -156 107 11 180 123 7 192 133 9 200 144 11
54062 -206 145 10 200 144 11 192 133 9 175 118 6
54063 -139 102 15 109 106 95 70 70 70 42 42 42
54064 - 22 22 22 10 10 10 0 0 0 0 0 0
54065 - 0 0 0 0 0 0 0 0 0 0 0 0
54066 - 0 0 0 0 0 0 0 0 0 0 0 0
54067 - 0 0 0 0 0 0 0 0 0 0 0 0
54068 - 0 0 0 0 0 0 0 0 0 0 0 0
54069 - 0 0 0 0 0 0 0 0 0 0 0 0
54070 - 0 0 0 0 0 0 6 6 6 10 10 10
54071 - 14 14 14 22 22 22 30 30 30 38 38 38
54072 - 50 50 50 62 62 62 74 74 74 90 90 90
54073 -101 98 89 112 100 78 121 87 25 124 80 6
54074 -137 92 6 152 99 6 152 99 6 152 99 6
54075 -138 86 6 124 80 6 98 70 6 86 66 30
54076 -101 98 89 82 82 82 58 58 58 46 46 46
54077 - 38 38 38 34 34 34 34 34 34 34 34 34
54078 - 34 34 34 34 34 34 34 34 34 34 34 34
54079 - 34 34 34 34 34 34 38 38 38 42 42 42
54080 - 54 54 54 82 82 82 94 86 76 91 60 6
54081 -134 86 6 156 107 11 167 114 7 175 118 6
54082 -175 118 6 167 114 7 152 99 6 121 87 25
54083 -101 98 89 62 62 62 34 34 34 18 18 18
54084 - 6 6 6 0 0 0 0 0 0 0 0 0
54085 - 0 0 0 0 0 0 0 0 0 0 0 0
54086 - 0 0 0 0 0 0 0 0 0 0 0 0
54087 - 0 0 0 0 0 0 0 0 0 0 0 0
54088 - 0 0 0 0 0 0 0 0 0 0 0 0
54089 - 0 0 0 0 0 0 0 0 0 0 0 0
54090 - 0 0 0 0 0 0 0 0 0 0 0 0
54091 - 0 0 0 6 6 6 6 6 6 10 10 10
54092 - 18 18 18 22 22 22 30 30 30 42 42 42
54093 - 50 50 50 66 66 66 86 86 86 101 98 89
54094 -106 86 58 98 70 6 104 69 6 104 69 6
54095 -104 69 6 91 60 6 82 62 34 90 90 90
54096 - 62 62 62 38 38 38 22 22 22 14 14 14
54097 - 10 10 10 10 10 10 10 10 10 10 10 10
54098 - 10 10 10 10 10 10 6 6 6 10 10 10
54099 - 10 10 10 10 10 10 10 10 10 14 14 14
54100 - 22 22 22 42 42 42 70 70 70 89 81 66
54101 - 80 54 7 104 69 6 124 80 6 137 92 6
54102 -134 86 6 116 81 8 100 82 52 86 86 86
54103 - 58 58 58 30 30 30 14 14 14 6 6 6
54104 - 0 0 0 0 0 0 0 0 0 0 0 0
54105 - 0 0 0 0 0 0 0 0 0 0 0 0
54106 - 0 0 0 0 0 0 0 0 0 0 0 0
54107 - 0 0 0 0 0 0 0 0 0 0 0 0
54108 - 0 0 0 0 0 0 0 0 0 0 0 0
54109 - 0 0 0 0 0 0 0 0 0 0 0 0
54110 - 0 0 0 0 0 0 0 0 0 0 0 0
54111 - 0 0 0 0 0 0 0 0 0 0 0 0
54112 - 0 0 0 6 6 6 10 10 10 14 14 14
54113 - 18 18 18 26 26 26 38 38 38 54 54 54
54114 - 70 70 70 86 86 86 94 86 76 89 81 66
54115 - 89 81 66 86 86 86 74 74 74 50 50 50
54116 - 30 30 30 14 14 14 6 6 6 0 0 0
54117 - 0 0 0 0 0 0 0 0 0 0 0 0
54118 - 0 0 0 0 0 0 0 0 0 0 0 0
54119 - 0 0 0 0 0 0 0 0 0 0 0 0
54120 - 6 6 6 18 18 18 34 34 34 58 58 58
54121 - 82 82 82 89 81 66 89 81 66 89 81 66
54122 - 94 86 66 94 86 76 74 74 74 50 50 50
54123 - 26 26 26 14 14 14 6 6 6 0 0 0
54124 - 0 0 0 0 0 0 0 0 0 0 0 0
54125 - 0 0 0 0 0 0 0 0 0 0 0 0
54126 - 0 0 0 0 0 0 0 0 0 0 0 0
54127 - 0 0 0 0 0 0 0 0 0 0 0 0
54128 - 0 0 0 0 0 0 0 0 0 0 0 0
54129 - 0 0 0 0 0 0 0 0 0 0 0 0
54130 - 0 0 0 0 0 0 0 0 0 0 0 0
54131 - 0 0 0 0 0 0 0 0 0 0 0 0
54132 - 0 0 0 0 0 0 0 0 0 0 0 0
54133 - 6 6 6 6 6 6 14 14 14 18 18 18
54134 - 30 30 30 38 38 38 46 46 46 54 54 54
54135 - 50 50 50 42 42 42 30 30 30 18 18 18
54136 - 10 10 10 0 0 0 0 0 0 0 0 0
54137 - 0 0 0 0 0 0 0 0 0 0 0 0
54138 - 0 0 0 0 0 0 0 0 0 0 0 0
54139 - 0 0 0 0 0 0 0 0 0 0 0 0
54140 - 0 0 0 6 6 6 14 14 14 26 26 26
54141 - 38 38 38 50 50 50 58 58 58 58 58 58
54142 - 54 54 54 42 42 42 30 30 30 18 18 18
54143 - 10 10 10 0 0 0 0 0 0 0 0 0
54144 - 0 0 0 0 0 0 0 0 0 0 0 0
54145 - 0 0 0 0 0 0 0 0 0 0 0 0
54146 - 0 0 0 0 0 0 0 0 0 0 0 0
54147 - 0 0 0 0 0 0 0 0 0 0 0 0
54148 - 0 0 0 0 0 0 0 0 0 0 0 0
54149 - 0 0 0 0 0 0 0 0 0 0 0 0
54150 - 0 0 0 0 0 0 0 0 0 0 0 0
54151 - 0 0 0 0 0 0 0 0 0 0 0 0
54152 - 0 0 0 0 0 0 0 0 0 0 0 0
54153 - 0 0 0 0 0 0 0 0 0 6 6 6
54154 - 6 6 6 10 10 10 14 14 14 18 18 18
54155 - 18 18 18 14 14 14 10 10 10 6 6 6
54156 - 0 0 0 0 0 0 0 0 0 0 0 0
54157 - 0 0 0 0 0 0 0 0 0 0 0 0
54158 - 0 0 0 0 0 0 0 0 0 0 0 0
54159 - 0 0 0 0 0 0 0 0 0 0 0 0
54160 - 0 0 0 0 0 0 0 0 0 6 6 6
54161 - 14 14 14 18 18 18 22 22 22 22 22 22
54162 - 18 18 18 14 14 14 10 10 10 6 6 6
54163 - 0 0 0 0 0 0 0 0 0 0 0 0
54164 - 0 0 0 0 0 0 0 0 0 0 0 0
54165 - 0 0 0 0 0 0 0 0 0 0 0 0
54166 - 0 0 0 0 0 0 0 0 0 0 0 0
54167 - 0 0 0 0 0 0 0 0 0 0 0 0
54168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54181 +4 4 4 4 4 4
54182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54195 +4 4 4 4 4 4
54196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54209 +4 4 4 4 4 4
54210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54223 +4 4 4 4 4 4
54224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54237 +4 4 4 4 4 4
54238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54251 +4 4 4 4 4 4
54252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54256 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54257 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54261 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54262 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54263 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54265 +4 4 4 4 4 4
54266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54270 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54271 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54272 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54275 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54276 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54277 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54278 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54279 +4 4 4 4 4 4
54280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54284 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54285 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54286 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54289 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54290 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54291 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54292 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54293 +4 4 4 4 4 4
54294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54297 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54298 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54299 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54300 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54302 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54303 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54304 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54305 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54306 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54307 +4 4 4 4 4 4
54308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54311 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54312 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54313 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54314 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54315 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54316 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54317 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54318 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54319 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54320 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54321 +4 4 4 4 4 4
54322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54325 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54326 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54327 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54328 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54329 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54330 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54331 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54332 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54333 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54334 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54335 +4 4 4 4 4 4
54336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54338 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54339 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54340 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54341 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54342 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54343 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54344 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54345 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54346 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54347 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54348 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54349 +4 4 4 4 4 4
54350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54352 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54353 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54354 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54355 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54356 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54357 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54358 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54359 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54360 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54361 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54362 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54363 +4 4 4 4 4 4
54364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54366 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54367 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54368 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54369 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54370 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54371 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54372 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54373 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54374 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54375 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54376 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54377 +4 4 4 4 4 4
54378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54380 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54381 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54382 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54383 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54384 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54385 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54386 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54387 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54388 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54389 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54390 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54391 +4 4 4 4 4 4
54392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54393 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54394 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54395 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54396 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54397 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54398 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54399 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54400 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54401 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54402 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54403 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54404 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54405 +4 4 4 4 4 4
54406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54407 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54408 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54409 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54410 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54411 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54412 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54413 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54414 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54415 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54416 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54417 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54418 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54419 +0 0 0 4 4 4
54420 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54421 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54422 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54423 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54424 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54425 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54426 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54427 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54428 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54429 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54430 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54431 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54432 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54433 +2 0 0 0 0 0
54434 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54435 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54436 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54437 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54438 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54439 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54440 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54441 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54442 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54443 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54444 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54445 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54446 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54447 +37 38 37 0 0 0
54448 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54449 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54450 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54451 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54452 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54453 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54454 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54455 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54456 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54457 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54458 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54459 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54460 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54461 +85 115 134 4 0 0
54462 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54463 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54464 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54465 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54466 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54467 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54468 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54469 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54470 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54471 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54472 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54473 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54474 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54475 +60 73 81 4 0 0
54476 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54477 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54478 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54479 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54480 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54481 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54482 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54483 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54484 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54485 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54486 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54487 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54488 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54489 +16 19 21 4 0 0
54490 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54491 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54492 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54493 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54494 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54495 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54496 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54497 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54498 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54499 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54500 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54501 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54502 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54503 +4 0 0 4 3 3
54504 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54505 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54506 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54508 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54509 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54510 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54511 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54512 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54513 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54514 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54515 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54516 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54517 +3 2 2 4 4 4
54518 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54519 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54520 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54521 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54522 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54523 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54524 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54525 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54526 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54527 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54528 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54529 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54530 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54531 +4 4 4 4 4 4
54532 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54533 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54534 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54535 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54536 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54537 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54538 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54539 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54540 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54541 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54542 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54543 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54544 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54545 +4 4 4 4 4 4
54546 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54547 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54548 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54549 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54550 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54551 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54552 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54553 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54554 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54555 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54556 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54557 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54558 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54559 +5 5 5 5 5 5
54560 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54561 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54562 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54563 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54564 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54565 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54566 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54567 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54568 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54569 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54570 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54571 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54572 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54573 +5 5 5 4 4 4
54574 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54575 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54576 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54577 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54578 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54579 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54580 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54581 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54582 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54583 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54584 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54585 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54587 +4 4 4 4 4 4
54588 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54589 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54590 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54591 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54592 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54593 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54594 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54595 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54596 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54597 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54598 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54599 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54601 +4 4 4 4 4 4
54602 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54603 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54604 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54605 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54606 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54607 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54608 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54609 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54610 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54611 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54612 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54615 +4 4 4 4 4 4
54616 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54617 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54618 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54619 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54620 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54621 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54622 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54623 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54624 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54625 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54626 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54629 +4 4 4 4 4 4
54630 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54631 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54632 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54633 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54634 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54635 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54636 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54637 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54638 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54639 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54640 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54643 +4 4 4 4 4 4
54644 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54645 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54646 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54647 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54648 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54649 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54650 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54651 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54652 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54653 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54654 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
54655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54657 +4 4 4 4 4 4
54658 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54659 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54660 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54661 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54662 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54663 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54664 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54665 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54666 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54667 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54668 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
54669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54671 +4 4 4 4 4 4
54672 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54673 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54674 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54675 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54676 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54677 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54678 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54679 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54680 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54681 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54682 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54685 +4 4 4 4 4 4
54686 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54687 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54688 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54689 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54690 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54691 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54692 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54693 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54694 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54695 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54696 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54699 +4 4 4 4 4 4
54700 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54701 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54702 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54703 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54704 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54705 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54706 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54707 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54708 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54709 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54710 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54713 +4 4 4 4 4 4
54714 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54715 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54716 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54717 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54718 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54719 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54720 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54721 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54722 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54723 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54724 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54727 +4 4 4 4 4 4
54728 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54729 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54730 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54731 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54732 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54733 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54734 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54735 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54736 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54737 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54738 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54741 +4 4 4 4 4 4
54742 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54743 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54744 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54745 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54746 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54747 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54748 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54749 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54750 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54751 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54752 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54755 +4 4 4 4 4 4
54756 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54757 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54758 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54759 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54760 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54761 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54762 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54763 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54764 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54765 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54766 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54769 +4 4 4 4 4 4
54770 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54771 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54772 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54773 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54774 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54775 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54776 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54777 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54778 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54779 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54780 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54783 +4 4 4 4 4 4
54784 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54785 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54786 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54787 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54788 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54789 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54790 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54791 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54792 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54793 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54794 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54797 +4 4 4 4 4 4
54798 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54799 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54800 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54801 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54802 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54803 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54804 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54805 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54806 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54807 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54808 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54811 +4 4 4 4 4 4
54812 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54813 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54814 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54815 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54816 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54817 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54818 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54819 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54820 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54821 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54822 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54825 +4 4 4 4 4 4
54826 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54827 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54828 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54829 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54830 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54831 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54832 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54833 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54834 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54835 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54836 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54839 +4 4 4 4 4 4
54840 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54841 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54842 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54843 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54844 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54845 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54846 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54847 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54848 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54849 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54850 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54853 +4 4 4 4 4 4
54854 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54855 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54856 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54857 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54858 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54859 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54860 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54861 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54862 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54863 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54864 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54867 +4 4 4 4 4 4
54868 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54869 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54870 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54871 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54872 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54873 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54874 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54875 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54876 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54877 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54878 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54881 +4 4 4 4 4 4
54882 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54883 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54884 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54885 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54886 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54887 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54888 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54889 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54890 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54891 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54892 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54895 +4 4 4 4 4 4
54896 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54897 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54898 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54899 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54900 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54901 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54902 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54903 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54904 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54905 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54906 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54909 +4 4 4 4 4 4
54910 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54911 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54912 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54913 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54914 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54915 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54916 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54917 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54918 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54919 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54920 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54923 +4 4 4 4 4 4
54924 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54925 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54926 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54927 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54928 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54929 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54930 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54931 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54932 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54933 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54934 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54937 +4 4 4 4 4 4
54938 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54939 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54940 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54941 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54942 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54943 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54944 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54945 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54946 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54947 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54948 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54951 +4 4 4 4 4 4
54952 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54953 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54954 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54955 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54956 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54957 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54958 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54959 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54960 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54961 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54962 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54965 +4 4 4 4 4 4
54966 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54967 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54968 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54969 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54970 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54971 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54972 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54973 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54974 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54975 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54976 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54979 +4 4 4 4 4 4
54980 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54981 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54982 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54983 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54984 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54985 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54986 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54987 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54988 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54989 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54993 +4 4 4 4 4 4
54994 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54995 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54996 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54997 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54998 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54999 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55000 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55001 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55002 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55003 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
55008 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55009 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55010 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55011 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55012 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55013 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55014 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55015 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55016 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55017 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55019 +4 4 4 4 4 4 4 4 4 4 4 4 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
55022 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55023 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55024 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55025 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55026 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55027 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55028 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55029 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55030 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55031 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55035 +4 4 4 4 4 4
55036 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55037 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55038 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55039 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55040 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55041 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55042 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55043 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55044 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55049 +4 4 4 4 4 4
55050 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55051 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55052 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55053 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55054 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55055 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55056 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55057 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55058 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55063 +4 4 4 4 4 4
55064 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55065 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55066 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55067 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55068 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55069 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55070 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55071 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55072 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55077 +4 4 4 4 4 4
55078 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55079 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55080 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55081 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55082 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55083 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55084 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55085 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55091 +4 4 4 4 4 4
55092 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55093 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55094 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55095 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55096 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55097 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55098 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55099 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55105 +4 4 4 4 4 4
55106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55107 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55108 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55109 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55110 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55111 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55112 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55113 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55119 +4 4 4 4 4 4
55120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55121 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55122 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55123 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55124 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55125 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55126 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55127 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55133 +4 4 4 4 4 4
55134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55135 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55136 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55137 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55138 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55139 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55140 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55141 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55147 +4 4 4 4 4 4
55148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55150 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55151 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55152 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55153 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55154 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55155 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55161 +4 4 4 4 4 4
55162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55165 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55166 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55167 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55168 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55175 +4 4 4 4 4 4
55176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55179 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55180 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55181 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55182 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55189 +4 4 4 4 4 4
55190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55193 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55194 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55195 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55196 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55203 +4 4 4 4 4 4
55204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55207 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55208 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55209 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55210 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55217 +4 4 4 4 4 4
55218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55222 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55223 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55224 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55231 +4 4 4 4 4 4
55232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55236 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55237 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55238 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55245 +4 4 4 4 4 4
55246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55250 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55251 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55252 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55259 +4 4 4 4 4 4
55260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55264 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55265 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55273 +4 4 4 4 4 4
55274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55278 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55279 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55287 +4 4 4 4 4 4
55288 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55289 index a01147f..5d896f8 100644
55290 --- a/drivers/video/matrox/matroxfb_DAC1064.c
55291 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
55292 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55293
55294 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55295 struct matrox_switch matrox_mystique = {
55296 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55297 + .preinit = MGA1064_preinit,
55298 + .reset = MGA1064_reset,
55299 + .init = MGA1064_init,
55300 + .restore = MGA1064_restore,
55301 };
55302 EXPORT_SYMBOL(matrox_mystique);
55303 #endif
55304
55305 #ifdef CONFIG_FB_MATROX_G
55306 struct matrox_switch matrox_G100 = {
55307 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55308 + .preinit = MGAG100_preinit,
55309 + .reset = MGAG100_reset,
55310 + .init = MGAG100_init,
55311 + .restore = MGAG100_restore,
55312 };
55313 EXPORT_SYMBOL(matrox_G100);
55314 #endif
55315 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55316 index 195ad7c..09743fc 100644
55317 --- a/drivers/video/matrox/matroxfb_Ti3026.c
55318 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
55319 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55320 }
55321
55322 struct matrox_switch matrox_millennium = {
55323 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55324 + .preinit = Ti3026_preinit,
55325 + .reset = Ti3026_reset,
55326 + .init = Ti3026_init,
55327 + .restore = Ti3026_restore
55328 };
55329 EXPORT_SYMBOL(matrox_millennium);
55330 #endif
55331 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55332 index fe92eed..106e085 100644
55333 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
55334 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55335 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55336 struct mb862xxfb_par *par = info->par;
55337
55338 if (info->var.bits_per_pixel == 32) {
55339 - info->fbops->fb_fillrect = cfb_fillrect;
55340 - info->fbops->fb_copyarea = cfb_copyarea;
55341 - info->fbops->fb_imageblit = cfb_imageblit;
55342 + pax_open_kernel();
55343 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55344 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55345 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55346 + pax_close_kernel();
55347 } else {
55348 outreg(disp, GC_L0EM, 3);
55349 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55350 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55351 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55352 + pax_open_kernel();
55353 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55354 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55355 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55356 + pax_close_kernel();
55357 }
55358 outreg(draw, GDC_REG_DRAW_BASE, 0);
55359 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55360 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55361 index ff22871..b129bed 100644
55362 --- a/drivers/video/nvidia/nvidia.c
55363 +++ b/drivers/video/nvidia/nvidia.c
55364 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55365 info->fix.line_length = (info->var.xres_virtual *
55366 info->var.bits_per_pixel) >> 3;
55367 if (info->var.accel_flags) {
55368 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55369 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55370 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55371 - info->fbops->fb_sync = nvidiafb_sync;
55372 + pax_open_kernel();
55373 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55374 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55375 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55376 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55377 + pax_close_kernel();
55378 info->pixmap.scan_align = 4;
55379 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55380 info->flags |= FBINFO_READS_FAST;
55381 NVResetGraphics(info);
55382 } else {
55383 - info->fbops->fb_imageblit = cfb_imageblit;
55384 - info->fbops->fb_fillrect = cfb_fillrect;
55385 - info->fbops->fb_copyarea = cfb_copyarea;
55386 - info->fbops->fb_sync = NULL;
55387 + pax_open_kernel();
55388 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55389 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55390 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55391 + *(void **)&info->fbops->fb_sync = NULL;
55392 + pax_close_kernel();
55393 info->pixmap.scan_align = 1;
55394 info->flags |= FBINFO_HWACCEL_DISABLED;
55395 info->flags &= ~FBINFO_READS_FAST;
55396 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55397 info->pixmap.size = 8 * 1024;
55398 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55399
55400 - if (!hwcur)
55401 - info->fbops->fb_cursor = NULL;
55402 + if (!hwcur) {
55403 + pax_open_kernel();
55404 + *(void **)&info->fbops->fb_cursor = NULL;
55405 + pax_close_kernel();
55406 + }
55407
55408 info->var.accel_flags = (!noaccel);
55409
55410 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55411 index 669a81f..e216d76 100644
55412 --- a/drivers/video/omap2/dss/display.c
55413 +++ b/drivers/video/omap2/dss/display.c
55414 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55415 snprintf(dssdev->alias, sizeof(dssdev->alias),
55416 "display%d", disp_num_counter++);
55417
55418 + pax_open_kernel();
55419 if (drv && drv->get_resolution == NULL)
55420 - drv->get_resolution = omapdss_default_get_resolution;
55421 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55422 if (drv && drv->get_recommended_bpp == NULL)
55423 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55424 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55425 if (drv && drv->get_timings == NULL)
55426 - drv->get_timings = omapdss_default_get_timings;
55427 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55428 + pax_close_kernel();
55429
55430 mutex_lock(&panel_list_mutex);
55431 list_add_tail(&dssdev->panel_list, &panel_list);
55432 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55433 index 83433cb..71e9b98 100644
55434 --- a/drivers/video/s1d13xxxfb.c
55435 +++ b/drivers/video/s1d13xxxfb.c
55436 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55437
55438 switch(prod_id) {
55439 case S1D13506_PROD_ID: /* activate acceleration */
55440 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55441 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55442 + pax_open_kernel();
55443 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55444 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55445 + pax_close_kernel();
55446 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55447 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55448 break;
55449 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55450 index d513ed6..90b0de9 100644
55451 --- a/drivers/video/smscufx.c
55452 +++ b/drivers/video/smscufx.c
55453 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55454 fb_deferred_io_cleanup(info);
55455 kfree(info->fbdefio);
55456 info->fbdefio = NULL;
55457 - info->fbops->fb_mmap = ufx_ops_mmap;
55458 + pax_open_kernel();
55459 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55460 + pax_close_kernel();
55461 }
55462
55463 pr_debug("released /dev/fb%d user=%d count=%d",
55464 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55465 index 025f14e..20eb4db 100644
55466 --- a/drivers/video/udlfb.c
55467 +++ b/drivers/video/udlfb.c
55468 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55469 dlfb_urb_completion(urb);
55470
55471 error:
55472 - atomic_add(bytes_sent, &dev->bytes_sent);
55473 - atomic_add(bytes_identical, &dev->bytes_identical);
55474 - atomic_add(width*height*2, &dev->bytes_rendered);
55475 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55476 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55477 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55478 end_cycles = get_cycles();
55479 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55480 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55481 >> 10)), /* Kcycles */
55482 &dev->cpu_kcycles_used);
55483
55484 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55485 dlfb_urb_completion(urb);
55486
55487 error:
55488 - atomic_add(bytes_sent, &dev->bytes_sent);
55489 - atomic_add(bytes_identical, &dev->bytes_identical);
55490 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55491 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55492 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55493 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55494 end_cycles = get_cycles();
55495 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55496 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55497 >> 10)), /* Kcycles */
55498 &dev->cpu_kcycles_used);
55499 }
55500 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55501 fb_deferred_io_cleanup(info);
55502 kfree(info->fbdefio);
55503 info->fbdefio = NULL;
55504 - info->fbops->fb_mmap = dlfb_ops_mmap;
55505 + pax_open_kernel();
55506 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55507 + pax_close_kernel();
55508 }
55509
55510 pr_warn("released /dev/fb%d user=%d count=%d\n",
55511 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55512 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55513 struct dlfb_data *dev = fb_info->par;
55514 return snprintf(buf, PAGE_SIZE, "%u\n",
55515 - atomic_read(&dev->bytes_rendered));
55516 + atomic_read_unchecked(&dev->bytes_rendered));
55517 }
55518
55519 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55520 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55521 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55522 struct dlfb_data *dev = fb_info->par;
55523 return snprintf(buf, PAGE_SIZE, "%u\n",
55524 - atomic_read(&dev->bytes_identical));
55525 + atomic_read_unchecked(&dev->bytes_identical));
55526 }
55527
55528 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55529 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55530 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55531 struct dlfb_data *dev = fb_info->par;
55532 return snprintf(buf, PAGE_SIZE, "%u\n",
55533 - atomic_read(&dev->bytes_sent));
55534 + atomic_read_unchecked(&dev->bytes_sent));
55535 }
55536
55537 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55538 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55539 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55540 struct dlfb_data *dev = fb_info->par;
55541 return snprintf(buf, PAGE_SIZE, "%u\n",
55542 - atomic_read(&dev->cpu_kcycles_used));
55543 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55544 }
55545
55546 static ssize_t edid_show(
55547 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55548 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55549 struct dlfb_data *dev = fb_info->par;
55550
55551 - atomic_set(&dev->bytes_rendered, 0);
55552 - atomic_set(&dev->bytes_identical, 0);
55553 - atomic_set(&dev->bytes_sent, 0);
55554 - atomic_set(&dev->cpu_kcycles_used, 0);
55555 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55556 + atomic_set_unchecked(&dev->bytes_identical, 0);
55557 + atomic_set_unchecked(&dev->bytes_sent, 0);
55558 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55559
55560 return count;
55561 }
55562 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55563 index 256fba7..6e75516 100644
55564 --- a/drivers/video/uvesafb.c
55565 +++ b/drivers/video/uvesafb.c
55566 @@ -19,6 +19,7 @@
55567 #include <linux/io.h>
55568 #include <linux/mutex.h>
55569 #include <linux/slab.h>
55570 +#include <linux/moduleloader.h>
55571 #include <video/edid.h>
55572 #include <video/uvesafb.h>
55573 #ifdef CONFIG_X86
55574 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55575 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55576 par->pmi_setpal = par->ypan = 0;
55577 } else {
55578 +
55579 +#ifdef CONFIG_PAX_KERNEXEC
55580 +#ifdef CONFIG_MODULES
55581 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55582 +#endif
55583 + if (!par->pmi_code) {
55584 + par->pmi_setpal = par->ypan = 0;
55585 + return 0;
55586 + }
55587 +#endif
55588 +
55589 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55590 + task->t.regs.edi);
55591 +
55592 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55593 + pax_open_kernel();
55594 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55595 + pax_close_kernel();
55596 +
55597 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55598 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55599 +#else
55600 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55601 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55602 +#endif
55603 +
55604 printk(KERN_INFO "uvesafb: protected mode interface info at "
55605 "%04x:%04x\n",
55606 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55607 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55608 par->ypan = ypan;
55609
55610 if (par->pmi_setpal || par->ypan) {
55611 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55612 if (__supported_pte_mask & _PAGE_NX) {
55613 par->pmi_setpal = par->ypan = 0;
55614 printk(KERN_WARNING "uvesafb: NX protection is active, "
55615 "better not use the PMI.\n");
55616 - } else {
55617 + } else
55618 +#endif
55619 uvesafb_vbe_getpmi(task, par);
55620 - }
55621 }
55622 #else
55623 /* The protected mode interface is not available on non-x86. */
55624 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55625 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55626
55627 /* Disable blanking if the user requested so. */
55628 - if (!blank)
55629 - info->fbops->fb_blank = NULL;
55630 + if (!blank) {
55631 + pax_open_kernel();
55632 + *(void **)&info->fbops->fb_blank = NULL;
55633 + pax_close_kernel();
55634 + }
55635
55636 /*
55637 * Find out how much IO memory is required for the mode with
55638 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55639 info->flags = FBINFO_FLAG_DEFAULT |
55640 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55641
55642 - if (!par->ypan)
55643 - info->fbops->fb_pan_display = NULL;
55644 + if (!par->ypan) {
55645 + pax_open_kernel();
55646 + *(void **)&info->fbops->fb_pan_display = NULL;
55647 + pax_close_kernel();
55648 + }
55649 }
55650
55651 static void uvesafb_init_mtrr(struct fb_info *info)
55652 @@ -1792,6 +1822,11 @@ out_mode:
55653 out:
55654 kfree(par->vbe_modes);
55655
55656 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55657 + if (par->pmi_code)
55658 + module_free_exec(NULL, par->pmi_code);
55659 +#endif
55660 +
55661 framebuffer_release(info);
55662 return err;
55663 }
55664 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55665 kfree(par->vbe_modes);
55666 kfree(par->vbe_state_orig);
55667 kfree(par->vbe_state_saved);
55668 +
55669 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55670 + if (par->pmi_code)
55671 + module_free_exec(NULL, par->pmi_code);
55672 +#endif
55673 +
55674 }
55675
55676 framebuffer_release(info);
55677 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55678 index 1c7da3b..56ea0bd 100644
55679 --- a/drivers/video/vesafb.c
55680 +++ b/drivers/video/vesafb.c
55681 @@ -9,6 +9,7 @@
55682 */
55683
55684 #include <linux/module.h>
55685 +#include <linux/moduleloader.h>
55686 #include <linux/kernel.h>
55687 #include <linux/errno.h>
55688 #include <linux/string.h>
55689 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55690 static int vram_total; /* Set total amount of memory */
55691 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55692 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55693 -static void (*pmi_start)(void) __read_mostly;
55694 -static void (*pmi_pal) (void) __read_mostly;
55695 +static void (*pmi_start)(void) __read_only;
55696 +static void (*pmi_pal) (void) __read_only;
55697 static int depth __read_mostly;
55698 static int vga_compat __read_mostly;
55699 /* --------------------------------------------------------------------- */
55700 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55701 unsigned int size_remap;
55702 unsigned int size_total;
55703 char *option = NULL;
55704 + void *pmi_code = NULL;
55705
55706 /* ignore error return of fb_get_options */
55707 fb_get_options("vesafb", &option);
55708 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55709 size_remap = size_total;
55710 vesafb_fix.smem_len = size_remap;
55711
55712 -#ifndef __i386__
55713 - screen_info.vesapm_seg = 0;
55714 -#endif
55715 -
55716 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55717 printk(KERN_WARNING
55718 "vesafb: cannot reserve video memory at 0x%lx\n",
55719 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55720 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55721 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55722
55723 +#ifdef __i386__
55724 +
55725 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55726 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55727 + if (!pmi_code)
55728 +#elif !defined(CONFIG_PAX_KERNEXEC)
55729 + if (0)
55730 +#endif
55731 +
55732 +#endif
55733 + screen_info.vesapm_seg = 0;
55734 +
55735 if (screen_info.vesapm_seg) {
55736 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55737 - screen_info.vesapm_seg,screen_info.vesapm_off);
55738 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55739 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55740 }
55741
55742 if (screen_info.vesapm_seg < 0xc000)
55743 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55744
55745 if (ypan || pmi_setpal) {
55746 unsigned short *pmi_base;
55747 +
55748 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55749 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55750 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55751 +
55752 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55753 + pax_open_kernel();
55754 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55755 +#else
55756 + pmi_code = pmi_base;
55757 +#endif
55758 +
55759 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55760 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55761 +
55762 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55763 + pmi_start = ktva_ktla(pmi_start);
55764 + pmi_pal = ktva_ktla(pmi_pal);
55765 + pax_close_kernel();
55766 +#endif
55767 +
55768 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55769 if (pmi_base[3]) {
55770 printk(KERN_INFO "vesafb: pmi: ports = ");
55771 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55772 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55773 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55774
55775 - if (!ypan)
55776 - info->fbops->fb_pan_display = NULL;
55777 + if (!ypan) {
55778 + pax_open_kernel();
55779 + *(void **)&info->fbops->fb_pan_display = NULL;
55780 + pax_close_kernel();
55781 + }
55782
55783 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55784 err = -ENOMEM;
55785 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55786 fb_info(info, "%s frame buffer device\n", info->fix.id);
55787 return 0;
55788 err:
55789 +
55790 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55791 + module_free_exec(NULL, pmi_code);
55792 +#endif
55793 +
55794 if (info->screen_base)
55795 iounmap(info->screen_base);
55796 framebuffer_release(info);
55797 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55798 index 88714ae..16c2e11 100644
55799 --- a/drivers/video/via/via_clock.h
55800 +++ b/drivers/video/via/via_clock.h
55801 @@ -56,7 +56,7 @@ struct via_clock {
55802
55803 void (*set_engine_pll_state)(u8 state);
55804 void (*set_engine_pll)(struct via_pll_config config);
55805 -};
55806 +} __no_const;
55807
55808
55809 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55810 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55811 index fef20db..d28b1ab 100644
55812 --- a/drivers/xen/xenfs/xenstored.c
55813 +++ b/drivers/xen/xenfs/xenstored.c
55814 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55815 static int xsd_kva_open(struct inode *inode, struct file *file)
55816 {
55817 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55818 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55819 + NULL);
55820 +#else
55821 xen_store_interface);
55822 +#endif
55823 +
55824 if (!file->private_data)
55825 return -ENOMEM;
55826 return 0;
55827 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55828 index 9ff073f..05cef23 100644
55829 --- a/fs/9p/vfs_addr.c
55830 +++ b/fs/9p/vfs_addr.c
55831 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55832
55833 retval = v9fs_file_write_internal(inode,
55834 v9inode->writeback_fid,
55835 - (__force const char __user *)buffer,
55836 + (const char __force_user *)buffer,
55837 len, &offset, 0);
55838 if (retval > 0)
55839 retval = 0;
55840 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55841 index 4e65aa9..043dc9a 100644
55842 --- a/fs/9p/vfs_inode.c
55843 +++ b/fs/9p/vfs_inode.c
55844 @@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55845 void
55846 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55847 {
55848 - char *s = nd_get_link(nd);
55849 + const char *s = nd_get_link(nd);
55850
55851 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55852 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55853 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55854 index 370b24c..ff0be7b 100644
55855 --- a/fs/Kconfig.binfmt
55856 +++ b/fs/Kconfig.binfmt
55857 @@ -103,7 +103,7 @@ config HAVE_AOUT
55858
55859 config BINFMT_AOUT
55860 tristate "Kernel support for a.out and ECOFF binaries"
55861 - depends on HAVE_AOUT
55862 + depends on HAVE_AOUT && BROKEN
55863 ---help---
55864 A.out (Assembler.OUTput) is a set of formats for libraries and
55865 executables used in the earliest versions of UNIX. Linux used
55866 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55867 index ce25d75..dc09eeb 100644
55868 --- a/fs/afs/inode.c
55869 +++ b/fs/afs/inode.c
55870 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55871 struct afs_vnode *vnode;
55872 struct super_block *sb;
55873 struct inode *inode;
55874 - static atomic_t afs_autocell_ino;
55875 + static atomic_unchecked_t afs_autocell_ino;
55876
55877 _enter("{%x:%u},%*.*s,",
55878 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55879 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55880 data.fid.unique = 0;
55881 data.fid.vnode = 0;
55882
55883 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55884 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55885 afs_iget5_autocell_test, afs_iget5_set,
55886 &data);
55887 if (!inode) {
55888 diff --git a/fs/aio.c b/fs/aio.c
55889 index 062a5f6..e5618e0 100644
55890 --- a/fs/aio.c
55891 +++ b/fs/aio.c
55892 @@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55893 size += sizeof(struct io_event) * nr_events;
55894
55895 nr_pages = PFN_UP(size);
55896 - if (nr_pages < 0)
55897 + if (nr_pages <= 0)
55898 return -EINVAL;
55899
55900 file = aio_private_file(ctx, nr_pages);
55901 diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
55902 index 2408473..80ef38c 100644
55903 --- a/fs/anon_inodes.c
55904 +++ b/fs/anon_inodes.c
55905 @@ -41,19 +41,8 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {
55906 static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
55907 int flags, const char *dev_name, void *data)
55908 {
55909 - struct dentry *root;
55910 - root = mount_pseudo(fs_type, "anon_inode:", NULL,
55911 + return mount_pseudo(fs_type, "anon_inode:", NULL,
55912 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
55913 - if (!IS_ERR(root)) {
55914 - struct super_block *s = root->d_sb;
55915 - anon_inode_inode = alloc_anon_inode(s);
55916 - if (IS_ERR(anon_inode_inode)) {
55917 - dput(root);
55918 - deactivate_locked_super(s);
55919 - root = ERR_CAST(anon_inode_inode);
55920 - }
55921 - }
55922 - return root;
55923 }
55924
55925 static struct file_system_type anon_inode_fs_type = {
55926 @@ -175,22 +164,15 @@ EXPORT_SYMBOL_GPL(anon_inode_getfd);
55927
55928 static int __init anon_inode_init(void)
55929 {
55930 - int error;
55931 -
55932 - error = register_filesystem(&anon_inode_fs_type);
55933 - if (error)
55934 - goto err_exit;
55935 anon_inode_mnt = kern_mount(&anon_inode_fs_type);
55936 - if (IS_ERR(anon_inode_mnt)) {
55937 - error = PTR_ERR(anon_inode_mnt);
55938 - goto err_unregister_filesystem;
55939 - }
55940 + if (IS_ERR(anon_inode_mnt))
55941 + panic("anon_inode_init() kernel mount failed (%ld)\n", PTR_ERR(anon_inode_mnt));
55942 +
55943 + anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
55944 + if (IS_ERR(anon_inode_inode))
55945 + panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode));
55946 +
55947 return 0;
55948 -
55949 -err_unregister_filesystem:
55950 - unregister_filesystem(&anon_inode_fs_type);
55951 -err_exit:
55952 - panic(KERN_ERR "anon_inode_init() failed (%d)\n", error);
55953 }
55954
55955 fs_initcall(anon_inode_init);
55956 diff --git a/fs/attr.c b/fs/attr.c
55957 index 5d4e59d..fd02418 100644
55958 --- a/fs/attr.c
55959 +++ b/fs/attr.c
55960 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55961 unsigned long limit;
55962
55963 limit = rlimit(RLIMIT_FSIZE);
55964 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55965 if (limit != RLIM_INFINITY && offset > limit)
55966 goto out_sig;
55967 if (offset > inode->i_sb->s_maxbytes)
55968 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55969 index 689e40d..515cac5 100644
55970 --- a/fs/autofs4/waitq.c
55971 +++ b/fs/autofs4/waitq.c
55972 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55973 {
55974 unsigned long sigpipe, flags;
55975 mm_segment_t fs;
55976 - const char *data = (const char *)addr;
55977 + const char __user *data = (const char __force_user *)addr;
55978 ssize_t wr = 0;
55979
55980 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55981 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55982 return 1;
55983 }
55984
55985 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55986 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55987 +#endif
55988 +
55989 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55990 enum autofs_notify notify)
55991 {
55992 @@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55993
55994 /* If this is a direct mount request create a dummy name */
55995 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55996 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55997 + /* this name does get written to userland via autofs4_write() */
55998 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55999 +#else
56000 qstr.len = sprintf(name, "%p", dentry);
56001 +#endif
56002 else {
56003 qstr.len = autofs4_getpath(sbi, dentry, &name);
56004 if (!qstr.len) {
56005 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56006 index 2722387..56059b5 100644
56007 --- a/fs/befs/endian.h
56008 +++ b/fs/befs/endian.h
56009 @@ -11,7 +11,7 @@
56010
56011 #include <asm/byteorder.h>
56012
56013 -static inline u64
56014 +static inline u64 __intentional_overflow(-1)
56015 fs64_to_cpu(const struct super_block *sb, fs64 n)
56016 {
56017 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56018 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56019 return (__force fs64)cpu_to_be64(n);
56020 }
56021
56022 -static inline u32
56023 +static inline u32 __intentional_overflow(-1)
56024 fs32_to_cpu(const struct super_block *sb, fs32 n)
56025 {
56026 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56027 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56028 return (__force fs32)cpu_to_be32(n);
56029 }
56030
56031 -static inline u16
56032 +static inline u16 __intentional_overflow(-1)
56033 fs16_to_cpu(const struct super_block *sb, fs16 n)
56034 {
56035 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56036 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56037 index ca0ba15..0fa3257 100644
56038 --- a/fs/binfmt_aout.c
56039 +++ b/fs/binfmt_aout.c
56040 @@ -16,6 +16,7 @@
56041 #include <linux/string.h>
56042 #include <linux/fs.h>
56043 #include <linux/file.h>
56044 +#include <linux/security.h>
56045 #include <linux/stat.h>
56046 #include <linux/fcntl.h>
56047 #include <linux/ptrace.h>
56048 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56049 #endif
56050 # define START_STACK(u) ((void __user *)u.start_stack)
56051
56052 + memset(&dump, 0, sizeof(dump));
56053 +
56054 fs = get_fs();
56055 set_fs(KERNEL_DS);
56056 has_dumped = 1;
56057 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56058
56059 /* If the size of the dump file exceeds the rlimit, then see what would happen
56060 if we wrote the stack, but not the data area. */
56061 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56062 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56063 dump.u_dsize = 0;
56064
56065 /* Make sure we have enough room to write the stack and data areas. */
56066 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56067 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56068 dump.u_ssize = 0;
56069
56070 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56071 rlim = rlimit(RLIMIT_DATA);
56072 if (rlim >= RLIM_INFINITY)
56073 rlim = ~0;
56074 +
56075 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56076 if (ex.a_data + ex.a_bss > rlim)
56077 return -ENOMEM;
56078
56079 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56080
56081 install_exec_creds(bprm);
56082
56083 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56084 + current->mm->pax_flags = 0UL;
56085 +#endif
56086 +
56087 +#ifdef CONFIG_PAX_PAGEEXEC
56088 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56089 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56090 +
56091 +#ifdef CONFIG_PAX_EMUTRAMP
56092 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56093 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56094 +#endif
56095 +
56096 +#ifdef CONFIG_PAX_MPROTECT
56097 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56098 + current->mm->pax_flags |= MF_PAX_MPROTECT;
56099 +#endif
56100 +
56101 + }
56102 +#endif
56103 +
56104 if (N_MAGIC(ex) == OMAGIC) {
56105 unsigned long text_addr, map_size;
56106 loff_t pos;
56107 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56108 }
56109
56110 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56111 - PROT_READ | PROT_WRITE | PROT_EXEC,
56112 + PROT_READ | PROT_WRITE,
56113 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56114 fd_offset + ex.a_text);
56115 if (error != N_DATADDR(ex)) {
56116 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56117 index 571a423..eed5754 100644
56118 --- a/fs/binfmt_elf.c
56119 +++ b/fs/binfmt_elf.c
56120 @@ -34,6 +34,7 @@
56121 #include <linux/utsname.h>
56122 #include <linux/coredump.h>
56123 #include <linux/sched.h>
56124 +#include <linux/xattr.h>
56125 #include <asm/uaccess.h>
56126 #include <asm/param.h>
56127 #include <asm/page.h>
56128 @@ -48,7 +49,7 @@
56129 static int load_elf_binary(struct linux_binprm *bprm);
56130 static int load_elf_library(struct file *);
56131 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56132 - int, int, unsigned long);
56133 + int, int, unsigned long) __intentional_overflow(-1);
56134
56135 /*
56136 * If we don't support core dumping, then supply a NULL so we
56137 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56138 #define elf_core_dump NULL
56139 #endif
56140
56141 +#ifdef CONFIG_PAX_MPROTECT
56142 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56143 +#endif
56144 +
56145 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56146 +static void elf_handle_mmap(struct file *file);
56147 +#endif
56148 +
56149 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56150 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56151 #else
56152 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56153 .load_binary = load_elf_binary,
56154 .load_shlib = load_elf_library,
56155 .core_dump = elf_core_dump,
56156 +
56157 +#ifdef CONFIG_PAX_MPROTECT
56158 + .handle_mprotect= elf_handle_mprotect,
56159 +#endif
56160 +
56161 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56162 + .handle_mmap = elf_handle_mmap,
56163 +#endif
56164 +
56165 .min_coredump = ELF_EXEC_PAGESIZE,
56166 };
56167
56168 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56169
56170 static int set_brk(unsigned long start, unsigned long end)
56171 {
56172 + unsigned long e = end;
56173 +
56174 start = ELF_PAGEALIGN(start);
56175 end = ELF_PAGEALIGN(end);
56176 if (end > start) {
56177 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56178 if (BAD_ADDR(addr))
56179 return addr;
56180 }
56181 - current->mm->start_brk = current->mm->brk = end;
56182 + current->mm->start_brk = current->mm->brk = e;
56183 return 0;
56184 }
56185
56186 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56187 elf_addr_t __user *u_rand_bytes;
56188 const char *k_platform = ELF_PLATFORM;
56189 const char *k_base_platform = ELF_BASE_PLATFORM;
56190 - unsigned char k_rand_bytes[16];
56191 + u32 k_rand_bytes[4];
56192 int items;
56193 elf_addr_t *elf_info;
56194 int ei_index = 0;
56195 const struct cred *cred = current_cred();
56196 struct vm_area_struct *vma;
56197 + unsigned long saved_auxv[AT_VECTOR_SIZE];
56198
56199 /*
56200 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56201 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56202 * Generate 16 random bytes for userspace PRNG seeding.
56203 */
56204 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56205 - u_rand_bytes = (elf_addr_t __user *)
56206 - STACK_ALLOC(p, sizeof(k_rand_bytes));
56207 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56208 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56209 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56210 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56211 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
56212 + u_rand_bytes = (elf_addr_t __user *) p;
56213 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56214 return -EFAULT;
56215
56216 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56217 return -EFAULT;
56218 current->mm->env_end = p;
56219
56220 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56221 +
56222 /* Put the elf_info on the stack in the right place. */
56223 sp = (elf_addr_t __user *)envp + 1;
56224 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56225 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56226 return -EFAULT;
56227 return 0;
56228 }
56229 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56230 an ELF header */
56231
56232 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56233 - struct file *interpreter, unsigned long *interp_map_addr,
56234 - unsigned long no_base)
56235 + struct file *interpreter, unsigned long no_base)
56236 {
56237 struct elf_phdr *elf_phdata;
56238 struct elf_phdr *eppnt;
56239 - unsigned long load_addr = 0;
56240 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56241 int load_addr_set = 0;
56242 unsigned long last_bss = 0, elf_bss = 0;
56243 - unsigned long error = ~0UL;
56244 + unsigned long error = -EINVAL;
56245 unsigned long total_size;
56246 int retval, i, size;
56247
56248 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56249 goto out_close;
56250 }
56251
56252 +#ifdef CONFIG_PAX_SEGMEXEC
56253 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56254 + pax_task_size = SEGMEXEC_TASK_SIZE;
56255 +#endif
56256 +
56257 eppnt = elf_phdata;
56258 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56259 if (eppnt->p_type == PT_LOAD) {
56260 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56261 map_addr = elf_map(interpreter, load_addr + vaddr,
56262 eppnt, elf_prot, elf_type, total_size);
56263 total_size = 0;
56264 - if (!*interp_map_addr)
56265 - *interp_map_addr = map_addr;
56266 error = map_addr;
56267 if (BAD_ADDR(map_addr))
56268 goto out_close;
56269 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56270 k = load_addr + eppnt->p_vaddr;
56271 if (BAD_ADDR(k) ||
56272 eppnt->p_filesz > eppnt->p_memsz ||
56273 - eppnt->p_memsz > TASK_SIZE ||
56274 - TASK_SIZE - eppnt->p_memsz < k) {
56275 + eppnt->p_memsz > pax_task_size ||
56276 + pax_task_size - eppnt->p_memsz < k) {
56277 error = -ENOMEM;
56278 goto out_close;
56279 }
56280 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56281 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56282
56283 /* Map the last of the bss segment */
56284 - error = vm_brk(elf_bss, last_bss - elf_bss);
56285 - if (BAD_ADDR(error))
56286 - goto out_close;
56287 + if (last_bss > elf_bss) {
56288 + error = vm_brk(elf_bss, last_bss - elf_bss);
56289 + if (BAD_ADDR(error))
56290 + goto out_close;
56291 + }
56292 }
56293
56294 error = load_addr;
56295 @@ -538,6 +569,336 @@ out:
56296 return error;
56297 }
56298
56299 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56300 +#ifdef CONFIG_PAX_SOFTMODE
56301 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56302 +{
56303 + unsigned long pax_flags = 0UL;
56304 +
56305 +#ifdef CONFIG_PAX_PAGEEXEC
56306 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56307 + pax_flags |= MF_PAX_PAGEEXEC;
56308 +#endif
56309 +
56310 +#ifdef CONFIG_PAX_SEGMEXEC
56311 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56312 + pax_flags |= MF_PAX_SEGMEXEC;
56313 +#endif
56314 +
56315 +#ifdef CONFIG_PAX_EMUTRAMP
56316 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56317 + pax_flags |= MF_PAX_EMUTRAMP;
56318 +#endif
56319 +
56320 +#ifdef CONFIG_PAX_MPROTECT
56321 + if (elf_phdata->p_flags & PF_MPROTECT)
56322 + pax_flags |= MF_PAX_MPROTECT;
56323 +#endif
56324 +
56325 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56326 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56327 + pax_flags |= MF_PAX_RANDMMAP;
56328 +#endif
56329 +
56330 + return pax_flags;
56331 +}
56332 +#endif
56333 +
56334 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56335 +{
56336 + unsigned long pax_flags = 0UL;
56337 +
56338 +#ifdef CONFIG_PAX_PAGEEXEC
56339 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56340 + pax_flags |= MF_PAX_PAGEEXEC;
56341 +#endif
56342 +
56343 +#ifdef CONFIG_PAX_SEGMEXEC
56344 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56345 + pax_flags |= MF_PAX_SEGMEXEC;
56346 +#endif
56347 +
56348 +#ifdef CONFIG_PAX_EMUTRAMP
56349 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56350 + pax_flags |= MF_PAX_EMUTRAMP;
56351 +#endif
56352 +
56353 +#ifdef CONFIG_PAX_MPROTECT
56354 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56355 + pax_flags |= MF_PAX_MPROTECT;
56356 +#endif
56357 +
56358 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56359 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56360 + pax_flags |= MF_PAX_RANDMMAP;
56361 +#endif
56362 +
56363 + return pax_flags;
56364 +}
56365 +#endif
56366 +
56367 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56368 +#ifdef CONFIG_PAX_SOFTMODE
56369 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56370 +{
56371 + unsigned long pax_flags = 0UL;
56372 +
56373 +#ifdef CONFIG_PAX_PAGEEXEC
56374 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56375 + pax_flags |= MF_PAX_PAGEEXEC;
56376 +#endif
56377 +
56378 +#ifdef CONFIG_PAX_SEGMEXEC
56379 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56380 + pax_flags |= MF_PAX_SEGMEXEC;
56381 +#endif
56382 +
56383 +#ifdef CONFIG_PAX_EMUTRAMP
56384 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56385 + pax_flags |= MF_PAX_EMUTRAMP;
56386 +#endif
56387 +
56388 +#ifdef CONFIG_PAX_MPROTECT
56389 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56390 + pax_flags |= MF_PAX_MPROTECT;
56391 +#endif
56392 +
56393 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56394 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56395 + pax_flags |= MF_PAX_RANDMMAP;
56396 +#endif
56397 +
56398 + return pax_flags;
56399 +}
56400 +#endif
56401 +
56402 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56403 +{
56404 + unsigned long pax_flags = 0UL;
56405 +
56406 +#ifdef CONFIG_PAX_PAGEEXEC
56407 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56408 + pax_flags |= MF_PAX_PAGEEXEC;
56409 +#endif
56410 +
56411 +#ifdef CONFIG_PAX_SEGMEXEC
56412 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56413 + pax_flags |= MF_PAX_SEGMEXEC;
56414 +#endif
56415 +
56416 +#ifdef CONFIG_PAX_EMUTRAMP
56417 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56418 + pax_flags |= MF_PAX_EMUTRAMP;
56419 +#endif
56420 +
56421 +#ifdef CONFIG_PAX_MPROTECT
56422 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56423 + pax_flags |= MF_PAX_MPROTECT;
56424 +#endif
56425 +
56426 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56427 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56428 + pax_flags |= MF_PAX_RANDMMAP;
56429 +#endif
56430 +
56431 + return pax_flags;
56432 +}
56433 +#endif
56434 +
56435 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56436 +static unsigned long pax_parse_defaults(void)
56437 +{
56438 + unsigned long pax_flags = 0UL;
56439 +
56440 +#ifdef CONFIG_PAX_SOFTMODE
56441 + if (pax_softmode)
56442 + return pax_flags;
56443 +#endif
56444 +
56445 +#ifdef CONFIG_PAX_PAGEEXEC
56446 + pax_flags |= MF_PAX_PAGEEXEC;
56447 +#endif
56448 +
56449 +#ifdef CONFIG_PAX_SEGMEXEC
56450 + pax_flags |= MF_PAX_SEGMEXEC;
56451 +#endif
56452 +
56453 +#ifdef CONFIG_PAX_MPROTECT
56454 + pax_flags |= MF_PAX_MPROTECT;
56455 +#endif
56456 +
56457 +#ifdef CONFIG_PAX_RANDMMAP
56458 + if (randomize_va_space)
56459 + pax_flags |= MF_PAX_RANDMMAP;
56460 +#endif
56461 +
56462 + return pax_flags;
56463 +}
56464 +
56465 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56466 +{
56467 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56468 +
56469 +#ifdef CONFIG_PAX_EI_PAX
56470 +
56471 +#ifdef CONFIG_PAX_SOFTMODE
56472 + if (pax_softmode)
56473 + return pax_flags;
56474 +#endif
56475 +
56476 + pax_flags = 0UL;
56477 +
56478 +#ifdef CONFIG_PAX_PAGEEXEC
56479 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56480 + pax_flags |= MF_PAX_PAGEEXEC;
56481 +#endif
56482 +
56483 +#ifdef CONFIG_PAX_SEGMEXEC
56484 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56485 + pax_flags |= MF_PAX_SEGMEXEC;
56486 +#endif
56487 +
56488 +#ifdef CONFIG_PAX_EMUTRAMP
56489 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56490 + pax_flags |= MF_PAX_EMUTRAMP;
56491 +#endif
56492 +
56493 +#ifdef CONFIG_PAX_MPROTECT
56494 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56495 + pax_flags |= MF_PAX_MPROTECT;
56496 +#endif
56497 +
56498 +#ifdef CONFIG_PAX_ASLR
56499 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56500 + pax_flags |= MF_PAX_RANDMMAP;
56501 +#endif
56502 +
56503 +#endif
56504 +
56505 + return pax_flags;
56506 +
56507 +}
56508 +
56509 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56510 +{
56511 +
56512 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56513 + unsigned long i;
56514 +
56515 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56516 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56517 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56518 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56519 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56520 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56521 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56522 + return PAX_PARSE_FLAGS_FALLBACK;
56523 +
56524 +#ifdef CONFIG_PAX_SOFTMODE
56525 + if (pax_softmode)
56526 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56527 + else
56528 +#endif
56529 +
56530 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56531 + break;
56532 + }
56533 +#endif
56534 +
56535 + return PAX_PARSE_FLAGS_FALLBACK;
56536 +}
56537 +
56538 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56539 +{
56540 +
56541 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56542 + ssize_t xattr_size, i;
56543 + unsigned char xattr_value[sizeof("pemrs") - 1];
56544 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56545 +
56546 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56547 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56548 + return PAX_PARSE_FLAGS_FALLBACK;
56549 +
56550 + for (i = 0; i < xattr_size; i++)
56551 + switch (xattr_value[i]) {
56552 + default:
56553 + return PAX_PARSE_FLAGS_FALLBACK;
56554 +
56555 +#define parse_flag(option1, option2, flag) \
56556 + case option1: \
56557 + if (pax_flags_hardmode & MF_PAX_##flag) \
56558 + return PAX_PARSE_FLAGS_FALLBACK;\
56559 + pax_flags_hardmode |= MF_PAX_##flag; \
56560 + break; \
56561 + case option2: \
56562 + if (pax_flags_softmode & MF_PAX_##flag) \
56563 + return PAX_PARSE_FLAGS_FALLBACK;\
56564 + pax_flags_softmode |= MF_PAX_##flag; \
56565 + break;
56566 +
56567 + parse_flag('p', 'P', PAGEEXEC);
56568 + parse_flag('e', 'E', EMUTRAMP);
56569 + parse_flag('m', 'M', MPROTECT);
56570 + parse_flag('r', 'R', RANDMMAP);
56571 + parse_flag('s', 'S', SEGMEXEC);
56572 +
56573 +#undef parse_flag
56574 + }
56575 +
56576 + if (pax_flags_hardmode & pax_flags_softmode)
56577 + return PAX_PARSE_FLAGS_FALLBACK;
56578 +
56579 +#ifdef CONFIG_PAX_SOFTMODE
56580 + if (pax_softmode)
56581 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56582 + else
56583 +#endif
56584 +
56585 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56586 +#else
56587 + return PAX_PARSE_FLAGS_FALLBACK;
56588 +#endif
56589 +
56590 +}
56591 +
56592 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56593 +{
56594 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56595 +
56596 + pax_flags = pax_parse_defaults();
56597 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56598 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56599 + xattr_pax_flags = pax_parse_xattr_pax(file);
56600 +
56601 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56602 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56603 + pt_pax_flags != xattr_pax_flags)
56604 + return -EINVAL;
56605 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56606 + pax_flags = xattr_pax_flags;
56607 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56608 + pax_flags = pt_pax_flags;
56609 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56610 + pax_flags = ei_pax_flags;
56611 +
56612 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56613 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56614 + if ((__supported_pte_mask & _PAGE_NX))
56615 + pax_flags &= ~MF_PAX_SEGMEXEC;
56616 + else
56617 + pax_flags &= ~MF_PAX_PAGEEXEC;
56618 + }
56619 +#endif
56620 +
56621 + if (0 > pax_check_flags(&pax_flags))
56622 + return -EINVAL;
56623 +
56624 + current->mm->pax_flags = pax_flags;
56625 + return 0;
56626 +}
56627 +#endif
56628 +
56629 /*
56630 * These are the functions used to load ELF style executables and shared
56631 * libraries. There is no binary dependent code anywhere else.
56632 @@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56633 {
56634 unsigned int random_variable = 0;
56635
56636 +#ifdef CONFIG_PAX_RANDUSTACK
56637 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56638 + return stack_top - current->mm->delta_stack;
56639 +#endif
56640 +
56641 if ((current->flags & PF_RANDOMIZE) &&
56642 !(current->personality & ADDR_NO_RANDOMIZE)) {
56643 random_variable = get_random_int() & STACK_RND_MASK;
56644 @@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56645 unsigned long load_addr = 0, load_bias = 0;
56646 int load_addr_set = 0;
56647 char * elf_interpreter = NULL;
56648 - unsigned long error;
56649 + unsigned long error = 0;
56650 struct elf_phdr *elf_ppnt, *elf_phdata;
56651 unsigned long elf_bss, elf_brk;
56652 int retval, i;
56653 @@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56654 unsigned long start_code, end_code, start_data, end_data;
56655 unsigned long reloc_func_desc __maybe_unused = 0;
56656 int executable_stack = EXSTACK_DEFAULT;
56657 - unsigned long def_flags = 0;
56658 struct pt_regs *regs = current_pt_regs();
56659 struct {
56660 struct elfhdr elf_ex;
56661 struct elfhdr interp_elf_ex;
56662 } *loc;
56663 + unsigned long pax_task_size;
56664
56665 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56666 if (!loc) {
56667 @@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56668 goto out_free_dentry;
56669
56670 /* OK, This is the point of no return */
56671 - current->mm->def_flags = def_flags;
56672 + current->mm->def_flags = 0;
56673
56674 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56675 may depend on the personality. */
56676 SET_PERSONALITY(loc->elf_ex);
56677 +
56678 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56679 + current->mm->pax_flags = 0UL;
56680 +#endif
56681 +
56682 +#ifdef CONFIG_PAX_DLRESOLVE
56683 + current->mm->call_dl_resolve = 0UL;
56684 +#endif
56685 +
56686 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56687 + current->mm->call_syscall = 0UL;
56688 +#endif
56689 +
56690 +#ifdef CONFIG_PAX_ASLR
56691 + current->mm->delta_mmap = 0UL;
56692 + current->mm->delta_stack = 0UL;
56693 +#endif
56694 +
56695 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56696 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56697 + send_sig(SIGKILL, current, 0);
56698 + goto out_free_dentry;
56699 + }
56700 +#endif
56701 +
56702 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56703 + pax_set_initial_flags(bprm);
56704 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56705 + if (pax_set_initial_flags_func)
56706 + (pax_set_initial_flags_func)(bprm);
56707 +#endif
56708 +
56709 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56710 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56711 + current->mm->context.user_cs_limit = PAGE_SIZE;
56712 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56713 + }
56714 +#endif
56715 +
56716 +#ifdef CONFIG_PAX_SEGMEXEC
56717 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56718 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56719 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56720 + pax_task_size = SEGMEXEC_TASK_SIZE;
56721 + current->mm->def_flags |= VM_NOHUGEPAGE;
56722 + } else
56723 +#endif
56724 +
56725 + pax_task_size = TASK_SIZE;
56726 +
56727 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56728 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56729 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56730 + put_cpu();
56731 + }
56732 +#endif
56733 +
56734 +#ifdef CONFIG_PAX_ASLR
56735 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56736 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56737 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56738 + }
56739 +#endif
56740 +
56741 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56742 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56743 + executable_stack = EXSTACK_DISABLE_X;
56744 + current->personality &= ~READ_IMPLIES_EXEC;
56745 + } else
56746 +#endif
56747 +
56748 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56749 current->personality |= READ_IMPLIES_EXEC;
56750
56751 @@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56752 #else
56753 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56754 #endif
56755 +
56756 +#ifdef CONFIG_PAX_RANDMMAP
56757 + /* PaX: randomize base address at the default exe base if requested */
56758 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56759 +#ifdef CONFIG_SPARC64
56760 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56761 +#else
56762 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56763 +#endif
56764 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56765 + elf_flags |= MAP_FIXED;
56766 + }
56767 +#endif
56768 +
56769 }
56770
56771 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56772 @@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56773 * allowed task size. Note that p_filesz must always be
56774 * <= p_memsz so it is only necessary to check p_memsz.
56775 */
56776 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56777 - elf_ppnt->p_memsz > TASK_SIZE ||
56778 - TASK_SIZE - elf_ppnt->p_memsz < k) {
56779 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56780 + elf_ppnt->p_memsz > pax_task_size ||
56781 + pax_task_size - elf_ppnt->p_memsz < k) {
56782 /* set_brk can never work. Avoid overflows. */
56783 send_sig(SIGKILL, current, 0);
56784 retval = -EINVAL;
56785 @@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56786 goto out_free_dentry;
56787 }
56788 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56789 - send_sig(SIGSEGV, current, 0);
56790 - retval = -EFAULT; /* Nobody gets to see this, but.. */
56791 - goto out_free_dentry;
56792 + /*
56793 + * This bss-zeroing can fail if the ELF
56794 + * file specifies odd protections. So
56795 + * we don't check the return value
56796 + */
56797 }
56798
56799 +#ifdef CONFIG_PAX_RANDMMAP
56800 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56801 + unsigned long start, size, flags;
56802 + vm_flags_t vm_flags;
56803 +
56804 + start = ELF_PAGEALIGN(elf_brk);
56805 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56806 + flags = MAP_FIXED | MAP_PRIVATE;
56807 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56808 +
56809 + down_write(&current->mm->mmap_sem);
56810 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56811 + retval = -ENOMEM;
56812 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56813 +// if (current->personality & ADDR_NO_RANDOMIZE)
56814 +// vm_flags |= VM_READ | VM_MAYREAD;
56815 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56816 + retval = IS_ERR_VALUE(start) ? start : 0;
56817 + }
56818 + up_write(&current->mm->mmap_sem);
56819 + if (retval == 0)
56820 + retval = set_brk(start + size, start + size + PAGE_SIZE);
56821 + if (retval < 0) {
56822 + send_sig(SIGKILL, current, 0);
56823 + goto out_free_dentry;
56824 + }
56825 + }
56826 +#endif
56827 +
56828 if (elf_interpreter) {
56829 - unsigned long interp_map_addr = 0;
56830 -
56831 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56832 interpreter,
56833 - &interp_map_addr,
56834 load_bias);
56835 if (!IS_ERR((void *)elf_entry)) {
56836 /*
56837 @@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56838 * Decide what to dump of a segment, part, all or none.
56839 */
56840 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56841 - unsigned long mm_flags)
56842 + unsigned long mm_flags, long signr)
56843 {
56844 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56845
56846 @@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56847 if (vma->vm_file == NULL)
56848 return 0;
56849
56850 - if (FILTER(MAPPED_PRIVATE))
56851 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56852 goto whole;
56853
56854 /*
56855 @@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56856 {
56857 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56858 int i = 0;
56859 - do
56860 + do {
56861 i += 2;
56862 - while (auxv[i - 2] != AT_NULL);
56863 + } while (auxv[i - 2] != AT_NULL);
56864 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56865 }
56866
56867 @@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56868 {
56869 mm_segment_t old_fs = get_fs();
56870 set_fs(KERNEL_DS);
56871 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56872 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56873 set_fs(old_fs);
56874 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56875 }
56876 @@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56877 }
56878
56879 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56880 - unsigned long mm_flags)
56881 + struct coredump_params *cprm)
56882 {
56883 struct vm_area_struct *vma;
56884 size_t size = 0;
56885
56886 for (vma = first_vma(current, gate_vma); vma != NULL;
56887 vma = next_vma(vma, gate_vma))
56888 - size += vma_dump_size(vma, mm_flags);
56889 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56890 return size;
56891 }
56892
56893 @@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56894
56895 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56896
56897 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56898 + offset += elf_core_vma_data_size(gate_vma, cprm);
56899 offset += elf_core_extra_data_size();
56900 e_shoff = offset;
56901
56902 @@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56903 phdr.p_offset = offset;
56904 phdr.p_vaddr = vma->vm_start;
56905 phdr.p_paddr = 0;
56906 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56907 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56908 phdr.p_memsz = vma->vm_end - vma->vm_start;
56909 offset += phdr.p_filesz;
56910 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56911 @@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56912 unsigned long addr;
56913 unsigned long end;
56914
56915 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56916 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56917
56918 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56919 struct page *page;
56920 @@ -2202,6 +2681,167 @@ out:
56921
56922 #endif /* CONFIG_ELF_CORE */
56923
56924 +#ifdef CONFIG_PAX_MPROTECT
56925 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
56926 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56927 + * we'll remove VM_MAYWRITE for good on RELRO segments.
56928 + *
56929 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56930 + * basis because we want to allow the common case and not the special ones.
56931 + */
56932 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56933 +{
56934 + struct elfhdr elf_h;
56935 + struct elf_phdr elf_p;
56936 + unsigned long i;
56937 + unsigned long oldflags;
56938 + bool is_textrel_rw, is_textrel_rx, is_relro;
56939 +
56940 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56941 + return;
56942 +
56943 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56944 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56945 +
56946 +#ifdef CONFIG_PAX_ELFRELOCS
56947 + /* possible TEXTREL */
56948 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56949 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56950 +#else
56951 + is_textrel_rw = false;
56952 + is_textrel_rx = false;
56953 +#endif
56954 +
56955 + /* possible RELRO */
56956 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56957 +
56958 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56959 + return;
56960 +
56961 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56962 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56963 +
56964 +#ifdef CONFIG_PAX_ETEXECRELOCS
56965 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56966 +#else
56967 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56968 +#endif
56969 +
56970 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56971 + !elf_check_arch(&elf_h) ||
56972 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56973 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56974 + return;
56975 +
56976 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56977 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56978 + return;
56979 + switch (elf_p.p_type) {
56980 + case PT_DYNAMIC:
56981 + if (!is_textrel_rw && !is_textrel_rx)
56982 + continue;
56983 + i = 0UL;
56984 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56985 + elf_dyn dyn;
56986 +
56987 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56988 + break;
56989 + if (dyn.d_tag == DT_NULL)
56990 + break;
56991 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56992 + gr_log_textrel(vma);
56993 + if (is_textrel_rw)
56994 + vma->vm_flags |= VM_MAYWRITE;
56995 + else
56996 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56997 + vma->vm_flags &= ~VM_MAYWRITE;
56998 + break;
56999 + }
57000 + i++;
57001 + }
57002 + is_textrel_rw = false;
57003 + is_textrel_rx = false;
57004 + continue;
57005 +
57006 + case PT_GNU_RELRO:
57007 + if (!is_relro)
57008 + continue;
57009 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57010 + vma->vm_flags &= ~VM_MAYWRITE;
57011 + is_relro = false;
57012 + continue;
57013 +
57014 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
57015 + case PT_PAX_FLAGS: {
57016 + const char *msg_mprotect = "", *msg_emutramp = "";
57017 + char *buffer_lib, *buffer_exe;
57018 +
57019 + if (elf_p.p_flags & PF_NOMPROTECT)
57020 + msg_mprotect = "MPROTECT disabled";
57021 +
57022 +#ifdef CONFIG_PAX_EMUTRAMP
57023 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57024 + msg_emutramp = "EMUTRAMP enabled";
57025 +#endif
57026 +
57027 + if (!msg_mprotect[0] && !msg_emutramp[0])
57028 + continue;
57029 +
57030 + if (!printk_ratelimit())
57031 + continue;
57032 +
57033 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57034 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57035 + if (buffer_lib && buffer_exe) {
57036 + char *path_lib, *path_exe;
57037 +
57038 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57039 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57040 +
57041 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57042 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57043 +
57044 + }
57045 + free_page((unsigned long)buffer_exe);
57046 + free_page((unsigned long)buffer_lib);
57047 + continue;
57048 + }
57049 +#endif
57050 +
57051 + }
57052 + }
57053 +}
57054 +#endif
57055 +
57056 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57057 +
57058 +extern int grsec_enable_log_rwxmaps;
57059 +
57060 +static void elf_handle_mmap(struct file *file)
57061 +{
57062 + struct elfhdr elf_h;
57063 + struct elf_phdr elf_p;
57064 + unsigned long i;
57065 +
57066 + if (!grsec_enable_log_rwxmaps)
57067 + return;
57068 +
57069 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57070 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57071 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57072 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57073 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57074 + return;
57075 +
57076 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57077 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57078 + return;
57079 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57080 + gr_log_ptgnustack(file);
57081 + }
57082 +}
57083 +#endif
57084 +
57085 static int __init init_elf_binfmt(void)
57086 {
57087 register_binfmt(&elf_format);
57088 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
57089 index d50bbe5..af3b649 100644
57090 --- a/fs/binfmt_flat.c
57091 +++ b/fs/binfmt_flat.c
57092 @@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
57093 realdatastart = (unsigned long) -ENOMEM;
57094 printk("Unable to allocate RAM for process data, errno %d\n",
57095 (int)-realdatastart);
57096 + down_write(&current->mm->mmap_sem);
57097 vm_munmap(textpos, text_len);
57098 + up_write(&current->mm->mmap_sem);
57099 ret = realdatastart;
57100 goto err;
57101 }
57102 @@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57103 }
57104 if (IS_ERR_VALUE(result)) {
57105 printk("Unable to read data+bss, errno %d\n", (int)-result);
57106 + down_write(&current->mm->mmap_sem);
57107 vm_munmap(textpos, text_len);
57108 vm_munmap(realdatastart, len);
57109 + up_write(&current->mm->mmap_sem);
57110 ret = result;
57111 goto err;
57112 }
57113 @@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57114 }
57115 if (IS_ERR_VALUE(result)) {
57116 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
57117 + down_write(&current->mm->mmap_sem);
57118 vm_munmap(textpos, text_len + data_len + extra +
57119 MAX_SHARED_LIBS * sizeof(unsigned long));
57120 + up_write(&current->mm->mmap_sem);
57121 ret = result;
57122 goto err;
57123 }
57124 diff --git a/fs/bio.c b/fs/bio.c
57125 index 33d79a4..c3c9893 100644
57126 --- a/fs/bio.c
57127 +++ b/fs/bio.c
57128 @@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57129 /*
57130 * Overflow, abort
57131 */
57132 - if (end < start)
57133 + if (end < start || end - start > INT_MAX - nr_pages)
57134 return ERR_PTR(-EINVAL);
57135
57136 nr_pages += end - start;
57137 @@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57138 /*
57139 * Overflow, abort
57140 */
57141 - if (end < start)
57142 + if (end < start || end - start > INT_MAX - nr_pages)
57143 return ERR_PTR(-EINVAL);
57144
57145 nr_pages += end - start;
57146 @@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57147 const int read = bio_data_dir(bio) == READ;
57148 struct bio_map_data *bmd = bio->bi_private;
57149 int i;
57150 - char *p = bmd->sgvecs[0].iov_base;
57151 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57152
57153 bio_for_each_segment_all(bvec, bio, i) {
57154 char *addr = page_address(bvec->bv_page);
57155 diff --git a/fs/block_dev.c b/fs/block_dev.c
57156 index 1e86823..8e34695 100644
57157 --- a/fs/block_dev.c
57158 +++ b/fs/block_dev.c
57159 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57160 else if (bdev->bd_contains == bdev)
57161 return true; /* is a whole device which isn't held */
57162
57163 - else if (whole->bd_holder == bd_may_claim)
57164 + else if (whole->bd_holder == (void *)bd_may_claim)
57165 return true; /* is a partition of a device that is being partitioned */
57166 else if (whole->bd_holder != NULL)
57167 return false; /* is a partition of a held device */
57168 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57169 index 3de01b4..6547c39 100644
57170 --- a/fs/btrfs/ctree.c
57171 +++ b/fs/btrfs/ctree.c
57172 @@ -1217,9 +1217,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57173 free_extent_buffer(buf);
57174 add_root_to_dirty_list(root);
57175 } else {
57176 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57177 - parent_start = parent->start;
57178 - else
57179 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57180 + if (parent)
57181 + parent_start = parent->start;
57182 + else
57183 + parent_start = 0;
57184 + } else
57185 parent_start = 0;
57186
57187 WARN_ON(trans->transid != btrfs_header_generation(parent));
57188 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57189 index 8d292fb..bc205c2 100644
57190 --- a/fs/btrfs/delayed-inode.c
57191 +++ b/fs/btrfs/delayed-inode.c
57192 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57193
57194 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57195 {
57196 - int seq = atomic_inc_return(&delayed_root->items_seq);
57197 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57198 if ((atomic_dec_return(&delayed_root->items) <
57199 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57200 waitqueue_active(&delayed_root->wait))
57201 @@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57202 static int refs_newer(struct btrfs_delayed_root *delayed_root,
57203 int seq, int count)
57204 {
57205 - int val = atomic_read(&delayed_root->items_seq);
57206 + int val = atomic_read_unchecked(&delayed_root->items_seq);
57207
57208 if (val < seq || val >= seq + count)
57209 return 1;
57210 @@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57211 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
57212 return;
57213
57214 - seq = atomic_read(&delayed_root->items_seq);
57215 + seq = atomic_read_unchecked(&delayed_root->items_seq);
57216
57217 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
57218 int ret;
57219 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57220 index a4b38f9..f86a509 100644
57221 --- a/fs/btrfs/delayed-inode.h
57222 +++ b/fs/btrfs/delayed-inode.h
57223 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57224 */
57225 struct list_head prepare_list;
57226 atomic_t items; /* for delayed items */
57227 - atomic_t items_seq; /* for delayed items */
57228 + atomic_unchecked_t items_seq; /* for delayed items */
57229 int nodes; /* for delayed nodes */
57230 wait_queue_head_t wait;
57231 };
57232 @@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
57233 struct btrfs_delayed_root *delayed_root)
57234 {
57235 atomic_set(&delayed_root->items, 0);
57236 - atomic_set(&delayed_root->items_seq, 0);
57237 + atomic_set_unchecked(&delayed_root->items_seq, 0);
57238 delayed_root->nodes = 0;
57239 spin_lock_init(&delayed_root->lock);
57240 init_waitqueue_head(&delayed_root->wait);
57241 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57242 index 9f831bb..14afde5 100644
57243 --- a/fs/btrfs/ioctl.c
57244 +++ b/fs/btrfs/ioctl.c
57245 @@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57246 for (i = 0; i < num_types; i++) {
57247 struct btrfs_space_info *tmp;
57248
57249 + /* Don't copy in more than we allocated */
57250 if (!slot_count)
57251 break;
57252
57253 + slot_count--;
57254 +
57255 info = NULL;
57256 rcu_read_lock();
57257 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57258 @@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57259 memcpy(dest, &space, sizeof(space));
57260 dest++;
57261 space_args.total_spaces++;
57262 - slot_count--;
57263 }
57264 - if (!slot_count)
57265 - break;
57266 }
57267 up_read(&info->groups_sem);
57268 }
57269 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57270 index d71a11d..384e2c4 100644
57271 --- a/fs/btrfs/super.c
57272 +++ b/fs/btrfs/super.c
57273 @@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57274 function, line, errstr);
57275 return;
57276 }
57277 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57278 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57279 /* Wake up anybody who may be waiting on this transaction */
57280 wake_up(&root->fs_info->transaction_wait);
57281 wake_up(&root->fs_info->transaction_blocked_wait);
57282 diff --git a/fs/buffer.c b/fs/buffer.c
57283 index aeeea65..7651d590 100644
57284 --- a/fs/buffer.c
57285 +++ b/fs/buffer.c
57286 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57287 bh_cachep = kmem_cache_create("buffer_head",
57288 sizeof(struct buffer_head), 0,
57289 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57290 - SLAB_MEM_SPREAD),
57291 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57292 NULL);
57293
57294 /*
57295 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57296 index 622f469..e8d2d55 100644
57297 --- a/fs/cachefiles/bind.c
57298 +++ b/fs/cachefiles/bind.c
57299 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57300 args);
57301
57302 /* start by checking things over */
57303 - ASSERT(cache->fstop_percent >= 0 &&
57304 - cache->fstop_percent < cache->fcull_percent &&
57305 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57306 cache->fcull_percent < cache->frun_percent &&
57307 cache->frun_percent < 100);
57308
57309 - ASSERT(cache->bstop_percent >= 0 &&
57310 - cache->bstop_percent < cache->bcull_percent &&
57311 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57312 cache->bcull_percent < cache->brun_percent &&
57313 cache->brun_percent < 100);
57314
57315 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57316 index 0a1467b..6a53245 100644
57317 --- a/fs/cachefiles/daemon.c
57318 +++ b/fs/cachefiles/daemon.c
57319 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57320 if (n > buflen)
57321 return -EMSGSIZE;
57322
57323 - if (copy_to_user(_buffer, buffer, n) != 0)
57324 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57325 return -EFAULT;
57326
57327 return n;
57328 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57329 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57330 return -EIO;
57331
57332 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57333 + if (datalen > PAGE_SIZE - 1)
57334 return -EOPNOTSUPP;
57335
57336 /* drag the command string into the kernel so we can parse it */
57337 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57338 if (args[0] != '%' || args[1] != '\0')
57339 return -EINVAL;
57340
57341 - if (fstop < 0 || fstop >= cache->fcull_percent)
57342 + if (fstop >= cache->fcull_percent)
57343 return cachefiles_daemon_range_error(cache, args);
57344
57345 cache->fstop_percent = fstop;
57346 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57347 if (args[0] != '%' || args[1] != '\0')
57348 return -EINVAL;
57349
57350 - if (bstop < 0 || bstop >= cache->bcull_percent)
57351 + if (bstop >= cache->bcull_percent)
57352 return cachefiles_daemon_range_error(cache, args);
57353
57354 cache->bstop_percent = bstop;
57355 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57356 index 5349473..d6c0b93 100644
57357 --- a/fs/cachefiles/internal.h
57358 +++ b/fs/cachefiles/internal.h
57359 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57360 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57361 struct rb_root active_nodes; /* active nodes (can't be culled) */
57362 rwlock_t active_lock; /* lock for active_nodes */
57363 - atomic_t gravecounter; /* graveyard uniquifier */
57364 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57365 unsigned frun_percent; /* when to stop culling (% files) */
57366 unsigned fcull_percent; /* when to start culling (% files) */
57367 unsigned fstop_percent; /* when to stop allocating (% files) */
57368 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57369 * proc.c
57370 */
57371 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57372 -extern atomic_t cachefiles_lookup_histogram[HZ];
57373 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57374 -extern atomic_t cachefiles_create_histogram[HZ];
57375 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57376 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57377 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57378
57379 extern int __init cachefiles_proc_init(void);
57380 extern void cachefiles_proc_cleanup(void);
57381 static inline
57382 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57383 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57384 {
57385 unsigned long jif = jiffies - start_jif;
57386 if (jif >= HZ)
57387 jif = HZ - 1;
57388 - atomic_inc(&histogram[jif]);
57389 + atomic_inc_unchecked(&histogram[jif]);
57390 }
57391
57392 #else
57393 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57394 index ca65f39..48921e3 100644
57395 --- a/fs/cachefiles/namei.c
57396 +++ b/fs/cachefiles/namei.c
57397 @@ -317,7 +317,7 @@ try_again:
57398 /* first step is to make up a grave dentry in the graveyard */
57399 sprintf(nbuffer, "%08x%08x",
57400 (uint32_t) get_seconds(),
57401 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57402 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57403
57404 /* do the multiway lock magic */
57405 trap = lock_rename(cache->graveyard, dir);
57406 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57407 index eccd339..4c1d995 100644
57408 --- a/fs/cachefiles/proc.c
57409 +++ b/fs/cachefiles/proc.c
57410 @@ -14,9 +14,9 @@
57411 #include <linux/seq_file.h>
57412 #include "internal.h"
57413
57414 -atomic_t cachefiles_lookup_histogram[HZ];
57415 -atomic_t cachefiles_mkdir_histogram[HZ];
57416 -atomic_t cachefiles_create_histogram[HZ];
57417 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57418 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57419 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57420
57421 /*
57422 * display the latency histogram
57423 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57424 return 0;
57425 default:
57426 index = (unsigned long) v - 3;
57427 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57428 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57429 - z = atomic_read(&cachefiles_create_histogram[index]);
57430 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57431 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57432 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57433 if (x == 0 && y == 0 && z == 0)
57434 return 0;
57435
57436 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57437 index ebaff36..7e3ea26 100644
57438 --- a/fs/cachefiles/rdwr.c
57439 +++ b/fs/cachefiles/rdwr.c
57440 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57441 old_fs = get_fs();
57442 set_fs(KERNEL_DS);
57443 ret = file->f_op->write(
57444 - file, (const void __user *) data, len, &pos);
57445 + file, (const void __force_user *) data, len, &pos);
57446 set_fs(old_fs);
57447 kunmap(page);
57448 file_end_write(file);
57449 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57450 index 2a0bcae..34ec24e 100644
57451 --- a/fs/ceph/dir.c
57452 +++ b/fs/ceph/dir.c
57453 @@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57454 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57455 struct ceph_mds_client *mdsc = fsc->mdsc;
57456 unsigned frag = fpos_frag(ctx->pos);
57457 - int off = fpos_off(ctx->pos);
57458 + unsigned int off = fpos_off(ctx->pos);
57459 int err;
57460 u32 ftype;
57461 struct ceph_mds_reply_info_parsed *rinfo;
57462 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57463 index 6a0951e..03fac6d 100644
57464 --- a/fs/ceph/super.c
57465 +++ b/fs/ceph/super.c
57466 @@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57467 /*
57468 * construct our own bdi so we can control readahead, etc.
57469 */
57470 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57471 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57472
57473 static int ceph_register_bdi(struct super_block *sb,
57474 struct ceph_fs_client *fsc)
57475 @@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
57476 default_backing_dev_info.ra_pages;
57477
57478 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57479 - atomic_long_inc_return(&bdi_seq));
57480 + atomic_long_inc_return_unchecked(&bdi_seq));
57481 if (!err)
57482 sb->s_bdi = &fsc->backing_dev_info;
57483 return err;
57484 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57485 index f3ac415..3d2420c 100644
57486 --- a/fs/cifs/cifs_debug.c
57487 +++ b/fs/cifs/cifs_debug.c
57488 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57489
57490 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57491 #ifdef CONFIG_CIFS_STATS2
57492 - atomic_set(&totBufAllocCount, 0);
57493 - atomic_set(&totSmBufAllocCount, 0);
57494 + atomic_set_unchecked(&totBufAllocCount, 0);
57495 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57496 #endif /* CONFIG_CIFS_STATS2 */
57497 spin_lock(&cifs_tcp_ses_lock);
57498 list_for_each(tmp1, &cifs_tcp_ses_list) {
57499 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57500 tcon = list_entry(tmp3,
57501 struct cifs_tcon,
57502 tcon_list);
57503 - atomic_set(&tcon->num_smbs_sent, 0);
57504 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57505 if (server->ops->clear_stats)
57506 server->ops->clear_stats(tcon);
57507 }
57508 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57509 smBufAllocCount.counter, cifs_min_small);
57510 #ifdef CONFIG_CIFS_STATS2
57511 seq_printf(m, "Total Large %d Small %d Allocations\n",
57512 - atomic_read(&totBufAllocCount),
57513 - atomic_read(&totSmBufAllocCount));
57514 + atomic_read_unchecked(&totBufAllocCount),
57515 + atomic_read_unchecked(&totSmBufAllocCount));
57516 #endif /* CONFIG_CIFS_STATS2 */
57517
57518 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57519 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57520 if (tcon->need_reconnect)
57521 seq_puts(m, "\tDISCONNECTED ");
57522 seq_printf(m, "\nSMBs: %d",
57523 - atomic_read(&tcon->num_smbs_sent));
57524 + atomic_read_unchecked(&tcon->num_smbs_sent));
57525 if (server->ops->print_stats)
57526 server->ops->print_stats(m, tcon);
57527 }
57528 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57529 index 849f613..eae6dec 100644
57530 --- a/fs/cifs/cifsfs.c
57531 +++ b/fs/cifs/cifsfs.c
57532 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57533 */
57534 cifs_req_cachep = kmem_cache_create("cifs_request",
57535 CIFSMaxBufSize + max_hdr_size, 0,
57536 - SLAB_HWCACHE_ALIGN, NULL);
57537 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57538 if (cifs_req_cachep == NULL)
57539 return -ENOMEM;
57540
57541 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57542 efficient to alloc 1 per page off the slab compared to 17K (5page)
57543 alloc of large cifs buffers even when page debugging is on */
57544 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57545 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57546 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57547 NULL);
57548 if (cifs_sm_req_cachep == NULL) {
57549 mempool_destroy(cifs_req_poolp);
57550 @@ -1168,8 +1168,8 @@ init_cifs(void)
57551 atomic_set(&bufAllocCount, 0);
57552 atomic_set(&smBufAllocCount, 0);
57553 #ifdef CONFIG_CIFS_STATS2
57554 - atomic_set(&totBufAllocCount, 0);
57555 - atomic_set(&totSmBufAllocCount, 0);
57556 + atomic_set_unchecked(&totBufAllocCount, 0);
57557 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57558 #endif /* CONFIG_CIFS_STATS2 */
57559
57560 atomic_set(&midCount, 0);
57561 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57562 index 579c6d5..95b6d03353 100644
57563 --- a/fs/cifs/cifsglob.h
57564 +++ b/fs/cifs/cifsglob.h
57565 @@ -797,35 +797,35 @@ struct cifs_tcon {
57566 __u16 Flags; /* optional support bits */
57567 enum statusEnum tidStatus;
57568 #ifdef CONFIG_CIFS_STATS
57569 - atomic_t num_smbs_sent;
57570 + atomic_unchecked_t num_smbs_sent;
57571 union {
57572 struct {
57573 - atomic_t num_writes;
57574 - atomic_t num_reads;
57575 - atomic_t num_flushes;
57576 - atomic_t num_oplock_brks;
57577 - atomic_t num_opens;
57578 - atomic_t num_closes;
57579 - atomic_t num_deletes;
57580 - atomic_t num_mkdirs;
57581 - atomic_t num_posixopens;
57582 - atomic_t num_posixmkdirs;
57583 - atomic_t num_rmdirs;
57584 - atomic_t num_renames;
57585 - atomic_t num_t2renames;
57586 - atomic_t num_ffirst;
57587 - atomic_t num_fnext;
57588 - atomic_t num_fclose;
57589 - atomic_t num_hardlinks;
57590 - atomic_t num_symlinks;
57591 - atomic_t num_locks;
57592 - atomic_t num_acl_get;
57593 - atomic_t num_acl_set;
57594 + atomic_unchecked_t num_writes;
57595 + atomic_unchecked_t num_reads;
57596 + atomic_unchecked_t num_flushes;
57597 + atomic_unchecked_t num_oplock_brks;
57598 + atomic_unchecked_t num_opens;
57599 + atomic_unchecked_t num_closes;
57600 + atomic_unchecked_t num_deletes;
57601 + atomic_unchecked_t num_mkdirs;
57602 + atomic_unchecked_t num_posixopens;
57603 + atomic_unchecked_t num_posixmkdirs;
57604 + atomic_unchecked_t num_rmdirs;
57605 + atomic_unchecked_t num_renames;
57606 + atomic_unchecked_t num_t2renames;
57607 + atomic_unchecked_t num_ffirst;
57608 + atomic_unchecked_t num_fnext;
57609 + atomic_unchecked_t num_fclose;
57610 + atomic_unchecked_t num_hardlinks;
57611 + atomic_unchecked_t num_symlinks;
57612 + atomic_unchecked_t num_locks;
57613 + atomic_unchecked_t num_acl_get;
57614 + atomic_unchecked_t num_acl_set;
57615 } cifs_stats;
57616 #ifdef CONFIG_CIFS_SMB2
57617 struct {
57618 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57619 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57620 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57621 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57622 } smb2_stats;
57623 #endif /* CONFIG_CIFS_SMB2 */
57624 } stats;
57625 @@ -1155,7 +1155,7 @@ convert_delimiter(char *path, char delim)
57626 }
57627
57628 #ifdef CONFIG_CIFS_STATS
57629 -#define cifs_stats_inc atomic_inc
57630 +#define cifs_stats_inc atomic_inc_unchecked
57631
57632 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57633 unsigned int bytes)
57634 @@ -1521,8 +1521,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57635 /* Various Debug counters */
57636 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57637 #ifdef CONFIG_CIFS_STATS2
57638 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57639 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57640 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57641 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57642 #endif
57643 GLOBAL_EXTERN atomic_t smBufAllocCount;
57644 GLOBAL_EXTERN atomic_t midCount;
57645 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57646 index a1c9ead..63e4c62 100644
57647 --- a/fs/cifs/file.c
57648 +++ b/fs/cifs/file.c
57649 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57650 index = mapping->writeback_index; /* Start from prev offset */
57651 end = -1;
57652 } else {
57653 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
57654 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
57655 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57656 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57657 range_whole = true;
57658 + index = 0;
57659 + end = ULONG_MAX;
57660 + } else {
57661 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
57662 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
57663 + }
57664 scanned = true;
57665 }
57666 retry:
57667 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57668 index 2f9f379..43f8025 100644
57669 --- a/fs/cifs/misc.c
57670 +++ b/fs/cifs/misc.c
57671 @@ -170,7 +170,7 @@ cifs_buf_get(void)
57672 memset(ret_buf, 0, buf_size + 3);
57673 atomic_inc(&bufAllocCount);
57674 #ifdef CONFIG_CIFS_STATS2
57675 - atomic_inc(&totBufAllocCount);
57676 + atomic_inc_unchecked(&totBufAllocCount);
57677 #endif /* CONFIG_CIFS_STATS2 */
57678 }
57679
57680 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57681 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57682 atomic_inc(&smBufAllocCount);
57683 #ifdef CONFIG_CIFS_STATS2
57684 - atomic_inc(&totSmBufAllocCount);
57685 + atomic_inc_unchecked(&totSmBufAllocCount);
57686 #endif /* CONFIG_CIFS_STATS2 */
57687
57688 }
57689 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57690 index ffc9ef9..b3c992b 100644
57691 --- a/fs/cifs/smb1ops.c
57692 +++ b/fs/cifs/smb1ops.c
57693 @@ -609,27 +609,27 @@ static void
57694 cifs_clear_stats(struct cifs_tcon *tcon)
57695 {
57696 #ifdef CONFIG_CIFS_STATS
57697 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57698 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57699 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57700 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57701 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57702 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57703 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57704 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57705 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57706 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57707 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57708 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57709 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57710 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57711 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57712 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57713 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57714 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57715 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57716 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57717 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57718 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57719 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57720 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57721 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57722 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57723 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57724 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57725 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57726 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57727 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57728 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57729 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57730 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57731 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57732 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57733 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57734 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57735 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57736 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57737 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57738 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57739 #endif
57740 }
57741
57742 @@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57743 {
57744 #ifdef CONFIG_CIFS_STATS
57745 seq_printf(m, " Oplocks breaks: %d",
57746 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57747 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57748 seq_printf(m, "\nReads: %d Bytes: %llu",
57749 - atomic_read(&tcon->stats.cifs_stats.num_reads),
57750 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57751 (long long)(tcon->bytes_read));
57752 seq_printf(m, "\nWrites: %d Bytes: %llu",
57753 - atomic_read(&tcon->stats.cifs_stats.num_writes),
57754 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57755 (long long)(tcon->bytes_written));
57756 seq_printf(m, "\nFlushes: %d",
57757 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
57758 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57759 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57760 - atomic_read(&tcon->stats.cifs_stats.num_locks),
57761 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57762 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57763 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57764 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57765 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57766 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57767 - atomic_read(&tcon->stats.cifs_stats.num_opens),
57768 - atomic_read(&tcon->stats.cifs_stats.num_closes),
57769 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
57770 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57771 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57772 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57773 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57774 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57775 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57776 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57777 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57778 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57779 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57780 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57781 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57782 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57783 seq_printf(m, "\nRenames: %d T2 Renames %d",
57784 - atomic_read(&tcon->stats.cifs_stats.num_renames),
57785 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57786 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57787 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57788 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57789 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57790 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
57791 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
57792 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57793 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57794 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57795 #endif
57796 }
57797
57798 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57799 index 192f51a..539307e 100644
57800 --- a/fs/cifs/smb2ops.c
57801 +++ b/fs/cifs/smb2ops.c
57802 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57803 #ifdef CONFIG_CIFS_STATS
57804 int i;
57805 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57806 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57807 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57808 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57809 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57810 }
57811 #endif
57812 }
57813 @@ -405,65 +405,65 @@ static void
57814 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57815 {
57816 #ifdef CONFIG_CIFS_STATS
57817 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57818 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57819 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57820 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57821 seq_printf(m, "\nNegotiates: %d sent %d failed",
57822 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57823 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57824 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57825 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57826 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57827 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57828 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57829 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57830 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57831 seq_printf(m, "\nLogoffs: %d sent %d failed",
57832 - atomic_read(&sent[SMB2_LOGOFF_HE]),
57833 - atomic_read(&failed[SMB2_LOGOFF_HE]));
57834 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57835 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57836 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57837 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57838 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57839 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57840 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57841 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57842 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57843 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57844 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57845 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57846 seq_printf(m, "\nCreates: %d sent %d failed",
57847 - atomic_read(&sent[SMB2_CREATE_HE]),
57848 - atomic_read(&failed[SMB2_CREATE_HE]));
57849 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57850 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57851 seq_printf(m, "\nCloses: %d sent %d failed",
57852 - atomic_read(&sent[SMB2_CLOSE_HE]),
57853 - atomic_read(&failed[SMB2_CLOSE_HE]));
57854 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57855 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57856 seq_printf(m, "\nFlushes: %d sent %d failed",
57857 - atomic_read(&sent[SMB2_FLUSH_HE]),
57858 - atomic_read(&failed[SMB2_FLUSH_HE]));
57859 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57860 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57861 seq_printf(m, "\nReads: %d sent %d failed",
57862 - atomic_read(&sent[SMB2_READ_HE]),
57863 - atomic_read(&failed[SMB2_READ_HE]));
57864 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
57865 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
57866 seq_printf(m, "\nWrites: %d sent %d failed",
57867 - atomic_read(&sent[SMB2_WRITE_HE]),
57868 - atomic_read(&failed[SMB2_WRITE_HE]));
57869 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57870 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57871 seq_printf(m, "\nLocks: %d sent %d failed",
57872 - atomic_read(&sent[SMB2_LOCK_HE]),
57873 - atomic_read(&failed[SMB2_LOCK_HE]));
57874 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57875 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57876 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57877 - atomic_read(&sent[SMB2_IOCTL_HE]),
57878 - atomic_read(&failed[SMB2_IOCTL_HE]));
57879 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57880 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57881 seq_printf(m, "\nCancels: %d sent %d failed",
57882 - atomic_read(&sent[SMB2_CANCEL_HE]),
57883 - atomic_read(&failed[SMB2_CANCEL_HE]));
57884 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57885 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57886 seq_printf(m, "\nEchos: %d sent %d failed",
57887 - atomic_read(&sent[SMB2_ECHO_HE]),
57888 - atomic_read(&failed[SMB2_ECHO_HE]));
57889 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57890 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57891 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57892 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57893 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57894 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57895 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57896 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57897 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57898 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57899 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57900 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57901 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57902 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57903 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57904 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57905 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57906 seq_printf(m, "\nSetInfos: %d sent %d failed",
57907 - atomic_read(&sent[SMB2_SET_INFO_HE]),
57908 - atomic_read(&failed[SMB2_SET_INFO_HE]));
57909 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57910 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57911 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57912 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57913 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57914 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57915 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57916 #endif
57917 }
57918
57919 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57920 index 787e171..31dcd0a 100644
57921 --- a/fs/cifs/smb2pdu.c
57922 +++ b/fs/cifs/smb2pdu.c
57923 @@ -2093,8 +2093,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57924 default:
57925 cifs_dbg(VFS, "info level %u isn't supported\n",
57926 srch_inf->info_level);
57927 - rc = -EINVAL;
57928 - goto qdir_exit;
57929 + return -EINVAL;
57930 }
57931
57932 req->FileIndex = cpu_to_le32(index);
57933 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57934 index 1da168c..8bc7ff6 100644
57935 --- a/fs/coda/cache.c
57936 +++ b/fs/coda/cache.c
57937 @@ -24,7 +24,7 @@
57938 #include "coda_linux.h"
57939 #include "coda_cache.h"
57940
57941 -static atomic_t permission_epoch = ATOMIC_INIT(0);
57942 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57943
57944 /* replace or extend an acl cache hit */
57945 void coda_cache_enter(struct inode *inode, int mask)
57946 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57947 struct coda_inode_info *cii = ITOC(inode);
57948
57949 spin_lock(&cii->c_lock);
57950 - cii->c_cached_epoch = atomic_read(&permission_epoch);
57951 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57952 if (!uid_eq(cii->c_uid, current_fsuid())) {
57953 cii->c_uid = current_fsuid();
57954 cii->c_cached_perm = mask;
57955 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57956 {
57957 struct coda_inode_info *cii = ITOC(inode);
57958 spin_lock(&cii->c_lock);
57959 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57960 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57961 spin_unlock(&cii->c_lock);
57962 }
57963
57964 /* remove all acl caches */
57965 void coda_cache_clear_all(struct super_block *sb)
57966 {
57967 - atomic_inc(&permission_epoch);
57968 + atomic_inc_unchecked(&permission_epoch);
57969 }
57970
57971
57972 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57973 spin_lock(&cii->c_lock);
57974 hit = (mask & cii->c_cached_perm) == mask &&
57975 uid_eq(cii->c_uid, current_fsuid()) &&
57976 - cii->c_cached_epoch == atomic_read(&permission_epoch);
57977 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57978 spin_unlock(&cii->c_lock);
57979
57980 return hit;
57981 diff --git a/fs/compat.c b/fs/compat.c
57982 index 6af20de..fec3fbb 100644
57983 --- a/fs/compat.c
57984 +++ b/fs/compat.c
57985 @@ -54,7 +54,7 @@
57986 #include <asm/ioctls.h>
57987 #include "internal.h"
57988
57989 -int compat_log = 1;
57990 +int compat_log = 0;
57991
57992 int compat_printk(const char *fmt, ...)
57993 {
57994 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57995
57996 set_fs(KERNEL_DS);
57997 /* The __user pointer cast is valid because of the set_fs() */
57998 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57999 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58000 set_fs(oldfs);
58001 /* truncating is ok because it's a user address */
58002 if (!ret)
58003 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58004 goto out;
58005
58006 ret = -EINVAL;
58007 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58008 + if (nr_segs > UIO_MAXIOV)
58009 goto out;
58010 if (nr_segs > fast_segs) {
58011 ret = -ENOMEM;
58012 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
58013 struct compat_readdir_callback {
58014 struct dir_context ctx;
58015 struct compat_old_linux_dirent __user *dirent;
58016 + struct file * file;
58017 int result;
58018 };
58019
58020 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58021 buf->result = -EOVERFLOW;
58022 return -EOVERFLOW;
58023 }
58024 +
58025 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58026 + return 0;
58027 +
58028 buf->result++;
58029 dirent = buf->dirent;
58030 if (!access_ok(VERIFY_WRITE, dirent,
58031 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
58032 if (!f.file)
58033 return -EBADF;
58034
58035 + buf.file = f.file;
58036 error = iterate_dir(f.file, &buf.ctx);
58037 if (buf.result)
58038 error = buf.result;
58039 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
58040 struct dir_context ctx;
58041 struct compat_linux_dirent __user *current_dir;
58042 struct compat_linux_dirent __user *previous;
58043 + struct file * file;
58044 int count;
58045 int error;
58046 };
58047 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58048 buf->error = -EOVERFLOW;
58049 return -EOVERFLOW;
58050 }
58051 +
58052 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58053 + return 0;
58054 +
58055 dirent = buf->previous;
58056 if (dirent) {
58057 if (__put_user(offset, &dirent->d_off))
58058 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
58059 if (!f.file)
58060 return -EBADF;
58061
58062 + buf.file = f.file;
58063 error = iterate_dir(f.file, &buf.ctx);
58064 if (error >= 0)
58065 error = buf.error;
58066 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58067 struct dir_context ctx;
58068 struct linux_dirent64 __user *current_dir;
58069 struct linux_dirent64 __user *previous;
58070 + struct file * file;
58071 int count;
58072 int error;
58073 };
58074 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58075 buf->error = -EINVAL; /* only used if we fail.. */
58076 if (reclen > buf->count)
58077 return -EINVAL;
58078 +
58079 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58080 + return 0;
58081 +
58082 dirent = buf->previous;
58083
58084 if (dirent) {
58085 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58086 if (!f.file)
58087 return -EBADF;
58088
58089 + buf.file = f.file;
58090 error = iterate_dir(f.file, &buf.ctx);
58091 if (error >= 0)
58092 error = buf.error;
58093 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58094 index a81147e..20bf2b5 100644
58095 --- a/fs/compat_binfmt_elf.c
58096 +++ b/fs/compat_binfmt_elf.c
58097 @@ -30,11 +30,13 @@
58098 #undef elf_phdr
58099 #undef elf_shdr
58100 #undef elf_note
58101 +#undef elf_dyn
58102 #undef elf_addr_t
58103 #define elfhdr elf32_hdr
58104 #define elf_phdr elf32_phdr
58105 #define elf_shdr elf32_shdr
58106 #define elf_note elf32_note
58107 +#define elf_dyn Elf32_Dyn
58108 #define elf_addr_t Elf32_Addr
58109
58110 /*
58111 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58112 index dc52e13..ec61057 100644
58113 --- a/fs/compat_ioctl.c
58114 +++ b/fs/compat_ioctl.c
58115 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58116 return -EFAULT;
58117 if (__get_user(udata, &ss32->iomem_base))
58118 return -EFAULT;
58119 - ss.iomem_base = compat_ptr(udata);
58120 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58121 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58122 __get_user(ss.port_high, &ss32->port_high))
58123 return -EFAULT;
58124 @@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58125 for (i = 0; i < nmsgs; i++) {
58126 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58127 return -EFAULT;
58128 - if (get_user(datap, &umsgs[i].buf) ||
58129 - put_user(compat_ptr(datap), &tmsgs[i].buf))
58130 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58131 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58132 return -EFAULT;
58133 }
58134 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58135 @@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
58136 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58137 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58138 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58139 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58140 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58141 return -EFAULT;
58142
58143 return ioctl_preallocate(file, p);
58144 @@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58145 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58146 {
58147 unsigned int a, b;
58148 - a = *(unsigned int *)p;
58149 - b = *(unsigned int *)q;
58150 + a = *(const unsigned int *)p;
58151 + b = *(const unsigned int *)q;
58152 if (a > b)
58153 return 1;
58154 if (a < b)
58155 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58156 index e081acb..911df21 100644
58157 --- a/fs/configfs/dir.c
58158 +++ b/fs/configfs/dir.c
58159 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58160 }
58161 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58162 struct configfs_dirent *next;
58163 - const char *name;
58164 + const unsigned char * name;
58165 + char d_name[sizeof(next->s_dentry->d_iname)];
58166 int len;
58167 struct inode *inode = NULL;
58168
58169 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58170 continue;
58171
58172 name = configfs_get_name(next);
58173 - len = strlen(name);
58174 + if (next->s_dentry && name == next->s_dentry->d_iname) {
58175 + len = next->s_dentry->d_name.len;
58176 + memcpy(d_name, name, len);
58177 + name = d_name;
58178 + } else
58179 + len = strlen(name);
58180
58181 /*
58182 * We'll have a dentry and an inode for
58183 diff --git a/fs/coredump.c b/fs/coredump.c
58184 index bc3fbcd..6031650 100644
58185 --- a/fs/coredump.c
58186 +++ b/fs/coredump.c
58187 @@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
58188 struct pipe_inode_info *pipe = file->private_data;
58189
58190 pipe_lock(pipe);
58191 - pipe->readers++;
58192 - pipe->writers--;
58193 + atomic_inc(&pipe->readers);
58194 + atomic_dec(&pipe->writers);
58195 wake_up_interruptible_sync(&pipe->wait);
58196 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58197 pipe_unlock(pipe);
58198 @@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
58199 * We actually want wait_event_freezable() but then we need
58200 * to clear TIF_SIGPENDING and improve dump_interrupted().
58201 */
58202 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
58203 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58204
58205 pipe_lock(pipe);
58206 - pipe->readers--;
58207 - pipe->writers++;
58208 + atomic_dec(&pipe->readers);
58209 + atomic_inc(&pipe->writers);
58210 pipe_unlock(pipe);
58211 }
58212
58213 @@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
58214 struct files_struct *displaced;
58215 bool need_nonrelative = false;
58216 bool core_dumped = false;
58217 - static atomic_t core_dump_count = ATOMIC_INIT(0);
58218 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58219 + long signr = siginfo->si_signo;
58220 + int dumpable;
58221 struct coredump_params cprm = {
58222 .siginfo = siginfo,
58223 .regs = signal_pt_regs(),
58224 @@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
58225 .mm_flags = mm->flags,
58226 };
58227
58228 - audit_core_dumps(siginfo->si_signo);
58229 + audit_core_dumps(signr);
58230 +
58231 + dumpable = __get_dumpable(cprm.mm_flags);
58232 +
58233 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58234 + gr_handle_brute_attach(dumpable);
58235
58236 binfmt = mm->binfmt;
58237 if (!binfmt || !binfmt->core_dump)
58238 goto fail;
58239 - if (!__get_dumpable(cprm.mm_flags))
58240 + if (!dumpable)
58241 goto fail;
58242
58243 cred = prepare_creds();
58244 @@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
58245 need_nonrelative = true;
58246 }
58247
58248 - retval = coredump_wait(siginfo->si_signo, &core_state);
58249 + retval = coredump_wait(signr, &core_state);
58250 if (retval < 0)
58251 goto fail_creds;
58252
58253 @@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
58254 }
58255 cprm.limit = RLIM_INFINITY;
58256
58257 - dump_count = atomic_inc_return(&core_dump_count);
58258 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
58259 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58260 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58261 task_tgid_vnr(current), current->comm);
58262 @@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
58263 } else {
58264 struct inode *inode;
58265
58266 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58267 +
58268 if (cprm.limit < binfmt->min_coredump)
58269 goto fail_unlock;
58270
58271 @@ -669,7 +678,7 @@ close_fail:
58272 filp_close(cprm.file, NULL);
58273 fail_dropcount:
58274 if (ispipe)
58275 - atomic_dec(&core_dump_count);
58276 + atomic_dec_unchecked(&core_dump_count);
58277 fail_unlock:
58278 kfree(cn.corename);
58279 coredump_finish(mm, core_dumped);
58280 @@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58281 struct file *file = cprm->file;
58282 loff_t pos = file->f_pos;
58283 ssize_t n;
58284 +
58285 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58286 if (cprm->written + nr > cprm->limit)
58287 return 0;
58288 while (nr) {
58289 diff --git a/fs/dcache.c b/fs/dcache.c
58290 index f7ad6d7..d852932 100644
58291 --- a/fs/dcache.c
58292 +++ b/fs/dcache.c
58293 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58294 */
58295 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58296 if (name->len > DNAME_INLINE_LEN-1) {
58297 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58298 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58299 if (!dname) {
58300 kmem_cache_free(dentry_cache, dentry);
58301 return NULL;
58302 @@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
58303 mempages -= reserve;
58304
58305 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58306 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58307 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58308 + SLAB_NO_SANITIZE, NULL);
58309
58310 dcache_init();
58311 inode_init();
58312 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58313 index 9c0444c..628490c 100644
58314 --- a/fs/debugfs/inode.c
58315 +++ b/fs/debugfs/inode.c
58316 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58317 */
58318 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58319 {
58320 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58321 + return __create_file(name, S_IFDIR | S_IRWXU,
58322 +#else
58323 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58324 +#endif
58325 parent, NULL, NULL);
58326 }
58327 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58328 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58329 index c36c448..fc96710 100644
58330 --- a/fs/ecryptfs/inode.c
58331 +++ b/fs/ecryptfs/inode.c
58332 @@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
58333 old_fs = get_fs();
58334 set_fs(get_ds());
58335 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58336 - (char __user *)lower_buf,
58337 + (char __force_user *)lower_buf,
58338 PATH_MAX);
58339 set_fs(old_fs);
58340 if (rc < 0)
58341 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58342 index e4141f2..d8263e8 100644
58343 --- a/fs/ecryptfs/miscdev.c
58344 +++ b/fs/ecryptfs/miscdev.c
58345 @@ -304,7 +304,7 @@ check_list:
58346 goto out_unlock_msg_ctx;
58347 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58348 if (msg_ctx->msg) {
58349 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58350 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58351 goto out_unlock_msg_ctx;
58352 i += packet_length_size;
58353 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58354 diff --git a/fs/exec.c b/fs/exec.c
58355 index 7ea097f..0158d8a 100644
58356 --- a/fs/exec.c
58357 +++ b/fs/exec.c
58358 @@ -55,8 +55,20 @@
58359 #include <linux/pipe_fs_i.h>
58360 #include <linux/oom.h>
58361 #include <linux/compat.h>
58362 +#include <linux/random.h>
58363 +#include <linux/seq_file.h>
58364 +#include <linux/coredump.h>
58365 +#include <linux/mman.h>
58366 +
58367 +#ifdef CONFIG_PAX_REFCOUNT
58368 +#include <linux/kallsyms.h>
58369 +#include <linux/kdebug.h>
58370 +#endif
58371 +
58372 +#include <trace/events/fs.h>
58373
58374 #include <asm/uaccess.h>
58375 +#include <asm/sections.h>
58376 #include <asm/mmu_context.h>
58377 #include <asm/tlb.h>
58378
58379 @@ -66,19 +78,34 @@
58380
58381 #include <trace/events/sched.h>
58382
58383 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58384 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58385 +{
58386 + 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");
58387 +}
58388 +#endif
58389 +
58390 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58391 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58392 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58393 +#endif
58394 +
58395 int suid_dumpable = 0;
58396
58397 static LIST_HEAD(formats);
58398 static DEFINE_RWLOCK(binfmt_lock);
58399
58400 +extern int gr_process_kernel_exec_ban(void);
58401 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58402 +
58403 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58404 {
58405 BUG_ON(!fmt);
58406 if (WARN_ON(!fmt->load_binary))
58407 return;
58408 write_lock(&binfmt_lock);
58409 - insert ? list_add(&fmt->lh, &formats) :
58410 - list_add_tail(&fmt->lh, &formats);
58411 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58412 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58413 write_unlock(&binfmt_lock);
58414 }
58415
58416 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58417 void unregister_binfmt(struct linux_binfmt * fmt)
58418 {
58419 write_lock(&binfmt_lock);
58420 - list_del(&fmt->lh);
58421 + pax_list_del((struct list_head *)&fmt->lh);
58422 write_unlock(&binfmt_lock);
58423 }
58424
58425 @@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58426 int write)
58427 {
58428 struct page *page;
58429 - int ret;
58430
58431 -#ifdef CONFIG_STACK_GROWSUP
58432 - if (write) {
58433 - ret = expand_downwards(bprm->vma, pos);
58434 - if (ret < 0)
58435 - return NULL;
58436 - }
58437 -#endif
58438 - ret = get_user_pages(current, bprm->mm, pos,
58439 - 1, write, 1, &page, NULL);
58440 - if (ret <= 0)
58441 + if (0 > expand_downwards(bprm->vma, pos))
58442 + return NULL;
58443 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58444 return NULL;
58445
58446 if (write) {
58447 @@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58448 if (size <= ARG_MAX)
58449 return page;
58450
58451 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58452 + // only allow 512KB for argv+env on suid/sgid binaries
58453 + // to prevent easy ASLR exhaustion
58454 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58455 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58456 + (size > (512 * 1024))) {
58457 + put_page(page);
58458 + return NULL;
58459 + }
58460 +#endif
58461 +
58462 /*
58463 * Limit to 1/4-th the stack size for the argv+env strings.
58464 * This ensures that:
58465 @@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58466 vma->vm_end = STACK_TOP_MAX;
58467 vma->vm_start = vma->vm_end - PAGE_SIZE;
58468 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58469 +
58470 +#ifdef CONFIG_PAX_SEGMEXEC
58471 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58472 +#endif
58473 +
58474 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58475 INIT_LIST_HEAD(&vma->anon_vma_chain);
58476
58477 @@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58478 mm->stack_vm = mm->total_vm = 1;
58479 up_write(&mm->mmap_sem);
58480 bprm->p = vma->vm_end - sizeof(void *);
58481 +
58482 +#ifdef CONFIG_PAX_RANDUSTACK
58483 + if (randomize_va_space)
58484 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58485 +#endif
58486 +
58487 return 0;
58488 err:
58489 up_write(&mm->mmap_sem);
58490 @@ -397,7 +438,7 @@ struct user_arg_ptr {
58491 } ptr;
58492 };
58493
58494 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58495 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58496 {
58497 const char __user *native;
58498
58499 @@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58500 compat_uptr_t compat;
58501
58502 if (get_user(compat, argv.ptr.compat + nr))
58503 - return ERR_PTR(-EFAULT);
58504 + return (const char __force_user *)ERR_PTR(-EFAULT);
58505
58506 return compat_ptr(compat);
58507 }
58508 #endif
58509
58510 if (get_user(native, argv.ptr.native + nr))
58511 - return ERR_PTR(-EFAULT);
58512 + return (const char __force_user *)ERR_PTR(-EFAULT);
58513
58514 return native;
58515 }
58516 @@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
58517 if (!p)
58518 break;
58519
58520 - if (IS_ERR(p))
58521 + if (IS_ERR((const char __force_kernel *)p))
58522 return -EFAULT;
58523
58524 if (i >= max)
58525 @@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58526
58527 ret = -EFAULT;
58528 str = get_user_arg_ptr(argv, argc);
58529 - if (IS_ERR(str))
58530 + if (IS_ERR((const char __force_kernel *)str))
58531 goto out;
58532
58533 len = strnlen_user(str, MAX_ARG_STRLEN);
58534 @@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58535 int r;
58536 mm_segment_t oldfs = get_fs();
58537 struct user_arg_ptr argv = {
58538 - .ptr.native = (const char __user *const __user *)__argv,
58539 + .ptr.native = (const char __user * const __force_user *)__argv,
58540 };
58541
58542 set_fs(KERNEL_DS);
58543 @@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58544 unsigned long new_end = old_end - shift;
58545 struct mmu_gather tlb;
58546
58547 - BUG_ON(new_start > new_end);
58548 + if (new_start >= new_end || new_start < mmap_min_addr)
58549 + return -ENOMEM;
58550
58551 /*
58552 * ensure there are no vmas between where we want to go
58553 @@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58554 if (vma != find_vma(mm, new_start))
58555 return -EFAULT;
58556
58557 +#ifdef CONFIG_PAX_SEGMEXEC
58558 + BUG_ON(pax_find_mirror_vma(vma));
58559 +#endif
58560 +
58561 /*
58562 * cover the whole range: [new_start, old_end)
58563 */
58564 @@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58565 stack_top = arch_align_stack(stack_top);
58566 stack_top = PAGE_ALIGN(stack_top);
58567
58568 - if (unlikely(stack_top < mmap_min_addr) ||
58569 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58570 - return -ENOMEM;
58571 -
58572 stack_shift = vma->vm_end - stack_top;
58573
58574 bprm->p -= stack_shift;
58575 @@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58576 bprm->exec -= stack_shift;
58577
58578 down_write(&mm->mmap_sem);
58579 +
58580 + /* Move stack pages down in memory. */
58581 + if (stack_shift) {
58582 + ret = shift_arg_pages(vma, stack_shift);
58583 + if (ret)
58584 + goto out_unlock;
58585 + }
58586 +
58587 vm_flags = VM_STACK_FLAGS;
58588
58589 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58590 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58591 + vm_flags &= ~VM_EXEC;
58592 +
58593 +#ifdef CONFIG_PAX_MPROTECT
58594 + if (mm->pax_flags & MF_PAX_MPROTECT)
58595 + vm_flags &= ~VM_MAYEXEC;
58596 +#endif
58597 +
58598 + }
58599 +#endif
58600 +
58601 /*
58602 * Adjust stack execute permissions; explicitly enable for
58603 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58604 @@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58605 goto out_unlock;
58606 BUG_ON(prev != vma);
58607
58608 - /* Move stack pages down in memory. */
58609 - if (stack_shift) {
58610 - ret = shift_arg_pages(vma, stack_shift);
58611 - if (ret)
58612 - goto out_unlock;
58613 - }
58614 -
58615 /* mprotect_fixup is overkill to remove the temporary stack flags */
58616 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58617
58618 @@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58619 #endif
58620 current->mm->start_stack = bprm->p;
58621 ret = expand_stack(vma, stack_base);
58622 +
58623 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58624 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58625 + unsigned long size;
58626 + vm_flags_t vm_flags;
58627 +
58628 + size = STACK_TOP - vma->vm_end;
58629 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58630 +
58631 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58632 +
58633 +#ifdef CONFIG_X86
58634 + if (!ret) {
58635 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58636 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58637 + }
58638 +#endif
58639 +
58640 + }
58641 +#endif
58642 +
58643 if (ret)
58644 ret = -EFAULT;
58645
58646 @@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
58647
58648 fsnotify_open(file);
58649
58650 + trace_open_exec(name);
58651 +
58652 err = deny_write_access(file);
58653 if (err)
58654 goto exit;
58655 @@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
58656 old_fs = get_fs();
58657 set_fs(get_ds());
58658 /* The cast to a user pointer is valid due to the set_fs() */
58659 - result = vfs_read(file, (void __user *)addr, count, &pos);
58660 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
58661 set_fs(old_fs);
58662 return result;
58663 }
58664 @@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
58665 }
58666 rcu_read_unlock();
58667
58668 - if (p->fs->users > n_fs) {
58669 + if (atomic_read(&p->fs->users) > n_fs) {
58670 bprm->unsafe |= LSM_UNSAFE_SHARE;
58671 } else {
58672 res = -EAGAIN;
58673 @@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58674 return ret;
58675 }
58676
58677 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58678 +static DEFINE_PER_CPU(u64, exec_counter);
58679 +static int __init init_exec_counters(void)
58680 +{
58681 + unsigned int cpu;
58682 +
58683 + for_each_possible_cpu(cpu) {
58684 + per_cpu(exec_counter, cpu) = (u64)cpu;
58685 + }
58686 +
58687 + return 0;
58688 +}
58689 +early_initcall(init_exec_counters);
58690 +static inline void increment_exec_counter(void)
58691 +{
58692 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
58693 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58694 +}
58695 +#else
58696 +static inline void increment_exec_counter(void) {}
58697 +#endif
58698 +
58699 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
58700 + struct user_arg_ptr argv);
58701 +
58702 /*
58703 * sys_execve() executes a new program.
58704 */
58705 @@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
58706 struct user_arg_ptr argv,
58707 struct user_arg_ptr envp)
58708 {
58709 +#ifdef CONFIG_GRKERNSEC
58710 + struct file *old_exec_file;
58711 + struct acl_subject_label *old_acl;
58712 + struct rlimit old_rlim[RLIM_NLIMITS];
58713 +#endif
58714 struct linux_binprm *bprm;
58715 struct file *file;
58716 struct files_struct *displaced;
58717 bool clear_in_exec;
58718 int retval;
58719
58720 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58721 +
58722 /*
58723 * We move the actual failure in case of RLIMIT_NPROC excess from
58724 * set*uid() to execve() because too many poorly written programs
58725 @@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
58726 if (IS_ERR(file))
58727 goto out_unmark;
58728
58729 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
58730 + retval = -EPERM;
58731 + goto out_file;
58732 + }
58733 +
58734 sched_exec();
58735
58736 bprm->file = file;
58737 bprm->filename = filename;
58738 bprm->interp = filename;
58739
58740 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58741 + retval = -EACCES;
58742 + goto out_file;
58743 + }
58744 +
58745 retval = bprm_mm_init(bprm);
58746 if (retval)
58747 goto out_file;
58748 @@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
58749 if (retval < 0)
58750 goto out;
58751
58752 +#ifdef CONFIG_GRKERNSEC
58753 + old_acl = current->acl;
58754 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58755 + old_exec_file = current->exec_file;
58756 + get_file(file);
58757 + current->exec_file = file;
58758 +#endif
58759 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58760 + /* limit suid stack to 8MB
58761 + * we saved the old limits above and will restore them if this exec fails
58762 + */
58763 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58764 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58765 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58766 +#endif
58767 +
58768 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58769 + retval = -EPERM;
58770 + goto out_fail;
58771 + }
58772 +
58773 + if (!gr_tpe_allow(file)) {
58774 + retval = -EACCES;
58775 + goto out_fail;
58776 + }
58777 +
58778 + if (gr_check_crash_exec(file)) {
58779 + retval = -EACCES;
58780 + goto out_fail;
58781 + }
58782 +
58783 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58784 + bprm->unsafe);
58785 + if (retval < 0)
58786 + goto out_fail;
58787 +
58788 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58789 if (retval < 0)
58790 - goto out;
58791 + goto out_fail;
58792
58793 bprm->exec = bprm->p;
58794 retval = copy_strings(bprm->envc, envp, bprm);
58795 if (retval < 0)
58796 - goto out;
58797 + goto out_fail;
58798
58799 retval = copy_strings(bprm->argc, argv, bprm);
58800 if (retval < 0)
58801 - goto out;
58802 + goto out_fail;
58803 +
58804 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58805 +
58806 + gr_handle_exec_args(bprm, argv);
58807
58808 retval = exec_binprm(bprm);
58809 if (retval < 0)
58810 - goto out;
58811 + goto out_fail;
58812 +#ifdef CONFIG_GRKERNSEC
58813 + if (old_exec_file)
58814 + fput(old_exec_file);
58815 +#endif
58816
58817 /* execve succeeded */
58818 +
58819 + increment_exec_counter();
58820 current->fs->in_exec = 0;
58821 current->in_execve = 0;
58822 acct_update_integrals(current);
58823 @@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
58824 put_files_struct(displaced);
58825 return retval;
58826
58827 +out_fail:
58828 +#ifdef CONFIG_GRKERNSEC
58829 + current->acl = old_acl;
58830 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58831 + fput(current->exec_file);
58832 + current->exec_file = old_exec_file;
58833 +#endif
58834 +
58835 out:
58836 if (bprm->mm) {
58837 acct_arg_size(bprm, 0);
58838 @@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58839 return error;
58840 }
58841 #endif
58842 +
58843 +int pax_check_flags(unsigned long *flags)
58844 +{
58845 + int retval = 0;
58846 +
58847 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58848 + if (*flags & MF_PAX_SEGMEXEC)
58849 + {
58850 + *flags &= ~MF_PAX_SEGMEXEC;
58851 + retval = -EINVAL;
58852 + }
58853 +#endif
58854 +
58855 + if ((*flags & MF_PAX_PAGEEXEC)
58856 +
58857 +#ifdef CONFIG_PAX_PAGEEXEC
58858 + && (*flags & MF_PAX_SEGMEXEC)
58859 +#endif
58860 +
58861 + )
58862 + {
58863 + *flags &= ~MF_PAX_PAGEEXEC;
58864 + retval = -EINVAL;
58865 + }
58866 +
58867 + if ((*flags & MF_PAX_MPROTECT)
58868 +
58869 +#ifdef CONFIG_PAX_MPROTECT
58870 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58871 +#endif
58872 +
58873 + )
58874 + {
58875 + *flags &= ~MF_PAX_MPROTECT;
58876 + retval = -EINVAL;
58877 + }
58878 +
58879 + if ((*flags & MF_PAX_EMUTRAMP)
58880 +
58881 +#ifdef CONFIG_PAX_EMUTRAMP
58882 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58883 +#endif
58884 +
58885 + )
58886 + {
58887 + *flags &= ~MF_PAX_EMUTRAMP;
58888 + retval = -EINVAL;
58889 + }
58890 +
58891 + return retval;
58892 +}
58893 +
58894 +EXPORT_SYMBOL(pax_check_flags);
58895 +
58896 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58897 +char *pax_get_path(const struct path *path, char *buf, int buflen)
58898 +{
58899 + char *pathname = d_path(path, buf, buflen);
58900 +
58901 + if (IS_ERR(pathname))
58902 + goto toolong;
58903 +
58904 + pathname = mangle_path(buf, pathname, "\t\n\\");
58905 + if (!pathname)
58906 + goto toolong;
58907 +
58908 + *pathname = 0;
58909 + return buf;
58910 +
58911 +toolong:
58912 + return "<path too long>";
58913 +}
58914 +EXPORT_SYMBOL(pax_get_path);
58915 +
58916 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58917 +{
58918 + struct task_struct *tsk = current;
58919 + struct mm_struct *mm = current->mm;
58920 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58921 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58922 + char *path_exec = NULL;
58923 + char *path_fault = NULL;
58924 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
58925 + siginfo_t info = { };
58926 +
58927 + if (buffer_exec && buffer_fault) {
58928 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58929 +
58930 + down_read(&mm->mmap_sem);
58931 + vma = mm->mmap;
58932 + while (vma && (!vma_exec || !vma_fault)) {
58933 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58934 + vma_exec = vma;
58935 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58936 + vma_fault = vma;
58937 + vma = vma->vm_next;
58938 + }
58939 + if (vma_exec)
58940 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58941 + if (vma_fault) {
58942 + start = vma_fault->vm_start;
58943 + end = vma_fault->vm_end;
58944 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58945 + if (vma_fault->vm_file)
58946 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58947 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58948 + path_fault = "<heap>";
58949 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58950 + path_fault = "<stack>";
58951 + else
58952 + path_fault = "<anonymous mapping>";
58953 + }
58954 + up_read(&mm->mmap_sem);
58955 + }
58956 + if (tsk->signal->curr_ip)
58957 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58958 + else
58959 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58960 + 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),
58961 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58962 + free_page((unsigned long)buffer_exec);
58963 + free_page((unsigned long)buffer_fault);
58964 + pax_report_insns(regs, pc, sp);
58965 + info.si_signo = SIGKILL;
58966 + info.si_errno = 0;
58967 + info.si_code = SI_KERNEL;
58968 + info.si_pid = 0;
58969 + info.si_uid = 0;
58970 + do_coredump(&info);
58971 +}
58972 +#endif
58973 +
58974 +#ifdef CONFIG_PAX_REFCOUNT
58975 +void pax_report_refcount_overflow(struct pt_regs *regs)
58976 +{
58977 + if (current->signal->curr_ip)
58978 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58979 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
58980 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58981 + else
58982 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58983 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58984 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58985 + preempt_disable();
58986 + show_regs(regs);
58987 + preempt_enable();
58988 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58989 +}
58990 +#endif
58991 +
58992 +#ifdef CONFIG_PAX_USERCOPY
58993 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58994 +static noinline int check_stack_object(const void *obj, unsigned long len)
58995 +{
58996 + const void * const stack = task_stack_page(current);
58997 + const void * const stackend = stack + THREAD_SIZE;
58998 +
58999 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59000 + const void *frame = NULL;
59001 + const void *oldframe;
59002 +#endif
59003 +
59004 + if (obj + len < obj)
59005 + return -1;
59006 +
59007 + if (obj + len <= stack || stackend <= obj)
59008 + return 0;
59009 +
59010 + if (obj < stack || stackend < obj + len)
59011 + return -1;
59012 +
59013 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59014 + oldframe = __builtin_frame_address(1);
59015 + if (oldframe)
59016 + frame = __builtin_frame_address(2);
59017 + /*
59018 + low ----------------------------------------------> high
59019 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
59020 + ^----------------^
59021 + allow copies only within here
59022 + */
59023 + while (stack <= frame && frame < stackend) {
59024 + /* if obj + len extends past the last frame, this
59025 + check won't pass and the next frame will be 0,
59026 + causing us to bail out and correctly report
59027 + the copy as invalid
59028 + */
59029 + if (obj + len <= frame)
59030 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59031 + oldframe = frame;
59032 + frame = *(const void * const *)frame;
59033 + }
59034 + return -1;
59035 +#else
59036 + return 1;
59037 +#endif
59038 +}
59039 +
59040 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59041 +{
59042 + if (current->signal->curr_ip)
59043 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59044 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59045 + else
59046 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59047 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59048 + dump_stack();
59049 + gr_handle_kernel_exploit();
59050 + do_group_exit(SIGKILL);
59051 +}
59052 +#endif
59053 +
59054 +#ifdef CONFIG_PAX_USERCOPY
59055 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59056 +{
59057 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59058 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
59059 +#ifdef CONFIG_MODULES
59060 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59061 +#else
59062 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59063 +#endif
59064 +
59065 +#else
59066 + unsigned long textlow = (unsigned long)_stext;
59067 + unsigned long texthigh = (unsigned long)_etext;
59068 +
59069 +#ifdef CONFIG_X86_64
59070 + /* check against linear mapping as well */
59071 + if (high > (unsigned long)__va(__pa(textlow)) &&
59072 + low <= (unsigned long)__va(__pa(texthigh)))
59073 + return true;
59074 +#endif
59075 +
59076 +#endif
59077 +
59078 + if (high <= textlow || low > texthigh)
59079 + return false;
59080 + else
59081 + return true;
59082 +}
59083 +#endif
59084 +
59085 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59086 +{
59087 +
59088 +#ifdef CONFIG_PAX_USERCOPY
59089 + const char *type;
59090 +
59091 + if (!n)
59092 + return;
59093 +
59094 + type = check_heap_object(ptr, n);
59095 + if (!type) {
59096 + int ret = check_stack_object(ptr, n);
59097 + if (ret == 1 || ret == 2)
59098 + return;
59099 + if (ret == 0) {
59100 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59101 + type = "<kernel text>";
59102 + else
59103 + return;
59104 + } else
59105 + type = "<process stack>";
59106 + }
59107 +
59108 + pax_report_usercopy(ptr, n, to_user, type);
59109 +#endif
59110 +
59111 +}
59112 +EXPORT_SYMBOL(__check_object_size);
59113 +
59114 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59115 +void pax_track_stack(void)
59116 +{
59117 + unsigned long sp = (unsigned long)&sp;
59118 + if (sp < current_thread_info()->lowest_stack &&
59119 + sp > (unsigned long)task_stack_page(current))
59120 + current_thread_info()->lowest_stack = sp;
59121 +}
59122 +EXPORT_SYMBOL(pax_track_stack);
59123 +#endif
59124 +
59125 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
59126 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59127 +{
59128 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59129 + dump_stack();
59130 + do_group_exit(SIGKILL);
59131 +}
59132 +EXPORT_SYMBOL(report_size_overflow);
59133 +#endif
59134 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59135 index 9f9992b..8b59411 100644
59136 --- a/fs/ext2/balloc.c
59137 +++ b/fs/ext2/balloc.c
59138 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59139
59140 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59141 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59142 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59143 + if (free_blocks < root_blocks + 1 &&
59144 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59145 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59146 - !in_group_p (sbi->s_resgid))) {
59147 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59148 return 0;
59149 }
59150 return 1;
59151 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59152 index 2d7557d..14e38f94 100644
59153 --- a/fs/ext2/xattr.c
59154 +++ b/fs/ext2/xattr.c
59155 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59156 struct buffer_head *bh = NULL;
59157 struct ext2_xattr_entry *entry;
59158 char *end;
59159 - size_t rest = buffer_size;
59160 + size_t rest = buffer_size, total_size = 0;
59161 int error;
59162
59163 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59164 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59165 buffer += size;
59166 }
59167 rest -= size;
59168 + total_size += size;
59169 }
59170 }
59171 - error = buffer_size - rest; /* total size */
59172 + error = total_size;
59173
59174 cleanup:
59175 brelse(bh);
59176 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59177 index 22548f5..41521d8 100644
59178 --- a/fs/ext3/balloc.c
59179 +++ b/fs/ext3/balloc.c
59180 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59181
59182 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59183 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59184 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59185 + if (free_blocks < root_blocks + 1 &&
59186 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59187 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59188 - !in_group_p (sbi->s_resgid))) {
59189 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59190 return 0;
59191 }
59192 return 1;
59193 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59194 index b1fc963..881228c 100644
59195 --- a/fs/ext3/xattr.c
59196 +++ b/fs/ext3/xattr.c
59197 @@ -330,7 +330,7 @@ static int
59198 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59199 char *buffer, size_t buffer_size)
59200 {
59201 - size_t rest = buffer_size;
59202 + size_t rest = buffer_size, total_size = 0;
59203
59204 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59205 const struct xattr_handler *handler =
59206 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59207 buffer += size;
59208 }
59209 rest -= size;
59210 + total_size += size;
59211 }
59212 }
59213 - return buffer_size - rest;
59214 + return total_size;
59215 }
59216
59217 static int
59218 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59219 index 6ea7b14..8fa16d9 100644
59220 --- a/fs/ext4/balloc.c
59221 +++ b/fs/ext4/balloc.c
59222 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59223 /* Hm, nope. Are (enough) root reserved clusters available? */
59224 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59225 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59226 - capable(CAP_SYS_RESOURCE) ||
59227 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59228 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59229 + capable_nolog(CAP_SYS_RESOURCE)) {
59230
59231 if (free_clusters >= (nclusters + dirty_clusters +
59232 resv_clusters))
59233 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59234 index d3a534f..242c50a 100644
59235 --- a/fs/ext4/ext4.h
59236 +++ b/fs/ext4/ext4.h
59237 @@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59238 unsigned long s_mb_last_start;
59239
59240 /* stats for buddy allocator */
59241 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59242 - atomic_t s_bal_success; /* we found long enough chunks */
59243 - atomic_t s_bal_allocated; /* in blocks */
59244 - atomic_t s_bal_ex_scanned; /* total extents scanned */
59245 - atomic_t s_bal_goals; /* goal hits */
59246 - atomic_t s_bal_breaks; /* too long searches */
59247 - atomic_t s_bal_2orders; /* 2^order hits */
59248 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59249 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59250 + atomic_unchecked_t s_bal_allocated; /* in blocks */
59251 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59252 + atomic_unchecked_t s_bal_goals; /* goal hits */
59253 + atomic_unchecked_t s_bal_breaks; /* too long searches */
59254 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59255 spinlock_t s_bal_lock;
59256 unsigned long s_mb_buddies_generated;
59257 unsigned long long s_mb_generation_time;
59258 - atomic_t s_mb_lost_chunks;
59259 - atomic_t s_mb_preallocated;
59260 - atomic_t s_mb_discarded;
59261 + atomic_unchecked_t s_mb_lost_chunks;
59262 + atomic_unchecked_t s_mb_preallocated;
59263 + atomic_unchecked_t s_mb_discarded;
59264 atomic_t s_lock_busy;
59265
59266 /* locality groups */
59267 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59268 index 04a5c75..09894fa 100644
59269 --- a/fs/ext4/mballoc.c
59270 +++ b/fs/ext4/mballoc.c
59271 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59272 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59273
59274 if (EXT4_SB(sb)->s_mb_stats)
59275 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59276 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59277
59278 break;
59279 }
59280 @@ -2189,7 +2189,7 @@ repeat:
59281 ac->ac_status = AC_STATUS_CONTINUE;
59282 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59283 cr = 3;
59284 - atomic_inc(&sbi->s_mb_lost_chunks);
59285 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59286 goto repeat;
59287 }
59288 }
59289 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59290 if (sbi->s_mb_stats) {
59291 ext4_msg(sb, KERN_INFO,
59292 "mballoc: %u blocks %u reqs (%u success)",
59293 - atomic_read(&sbi->s_bal_allocated),
59294 - atomic_read(&sbi->s_bal_reqs),
59295 - atomic_read(&sbi->s_bal_success));
59296 + atomic_read_unchecked(&sbi->s_bal_allocated),
59297 + atomic_read_unchecked(&sbi->s_bal_reqs),
59298 + atomic_read_unchecked(&sbi->s_bal_success));
59299 ext4_msg(sb, KERN_INFO,
59300 "mballoc: %u extents scanned, %u goal hits, "
59301 "%u 2^N hits, %u breaks, %u lost",
59302 - atomic_read(&sbi->s_bal_ex_scanned),
59303 - atomic_read(&sbi->s_bal_goals),
59304 - atomic_read(&sbi->s_bal_2orders),
59305 - atomic_read(&sbi->s_bal_breaks),
59306 - atomic_read(&sbi->s_mb_lost_chunks));
59307 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59308 + atomic_read_unchecked(&sbi->s_bal_goals),
59309 + atomic_read_unchecked(&sbi->s_bal_2orders),
59310 + atomic_read_unchecked(&sbi->s_bal_breaks),
59311 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59312 ext4_msg(sb, KERN_INFO,
59313 "mballoc: %lu generated and it took %Lu",
59314 sbi->s_mb_buddies_generated,
59315 sbi->s_mb_generation_time);
59316 ext4_msg(sb, KERN_INFO,
59317 "mballoc: %u preallocated, %u discarded",
59318 - atomic_read(&sbi->s_mb_preallocated),
59319 - atomic_read(&sbi->s_mb_discarded));
59320 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59321 + atomic_read_unchecked(&sbi->s_mb_discarded));
59322 }
59323
59324 free_percpu(sbi->s_locality_groups);
59325 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59326 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59327
59328 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59329 - atomic_inc(&sbi->s_bal_reqs);
59330 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59331 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59332 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59333 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59334 - atomic_inc(&sbi->s_bal_success);
59335 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59336 + atomic_inc_unchecked(&sbi->s_bal_success);
59337 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59338 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59339 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59340 - atomic_inc(&sbi->s_bal_goals);
59341 + atomic_inc_unchecked(&sbi->s_bal_goals);
59342 if (ac->ac_found > sbi->s_mb_max_to_scan)
59343 - atomic_inc(&sbi->s_bal_breaks);
59344 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59345 }
59346
59347 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59348 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59349 trace_ext4_mb_new_inode_pa(ac, pa);
59350
59351 ext4_mb_use_inode_pa(ac, pa);
59352 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59353 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59354
59355 ei = EXT4_I(ac->ac_inode);
59356 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59357 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59358 trace_ext4_mb_new_group_pa(ac, pa);
59359
59360 ext4_mb_use_group_pa(ac, pa);
59361 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59362 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59363
59364 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59365 lg = ac->ac_lg;
59366 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59367 * from the bitmap and continue.
59368 */
59369 }
59370 - atomic_add(free, &sbi->s_mb_discarded);
59371 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59372
59373 return err;
59374 }
59375 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59376 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59377 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59378 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59379 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59380 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59381 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59382
59383 return 0;
59384 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59385 index 04434ad..6404663 100644
59386 --- a/fs/ext4/mmp.c
59387 +++ b/fs/ext4/mmp.c
59388 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59389 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59390 const char *function, unsigned int line, const char *msg)
59391 {
59392 - __ext4_warning(sb, function, line, msg);
59393 + __ext4_warning(sb, function, line, "%s", msg);
59394 __ext4_warning(sb, function, line,
59395 "MMP failure info: last update time: %llu, last update "
59396 "node: %s, last update device: %s\n",
59397 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59398 index 710fed2..a82e4e8 100644
59399 --- a/fs/ext4/super.c
59400 +++ b/fs/ext4/super.c
59401 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59402 }
59403
59404 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59405 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59406 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59407 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59408
59409 #ifdef CONFIG_QUOTA
59410 @@ -2450,7 +2450,7 @@ struct ext4_attr {
59411 int offset;
59412 int deprecated_val;
59413 } u;
59414 -};
59415 +} __do_const;
59416
59417 static int parse_strtoull(const char *buf,
59418 unsigned long long max, unsigned long long *value)
59419 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59420 index 1423c48..9c0c6dc 100644
59421 --- a/fs/ext4/xattr.c
59422 +++ b/fs/ext4/xattr.c
59423 @@ -381,7 +381,7 @@ static int
59424 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59425 char *buffer, size_t buffer_size)
59426 {
59427 - size_t rest = buffer_size;
59428 + size_t rest = buffer_size, total_size = 0;
59429
59430 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59431 const struct xattr_handler *handler =
59432 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59433 buffer += size;
59434 }
59435 rest -= size;
59436 + total_size += size;
59437 }
59438 }
59439 - return buffer_size - rest;
59440 + return total_size;
59441 }
59442
59443 static int
59444 diff --git a/fs/fcntl.c b/fs/fcntl.c
59445 index ef68665..5deacdc 100644
59446 --- a/fs/fcntl.c
59447 +++ b/fs/fcntl.c
59448 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59449 if (err)
59450 return err;
59451
59452 + if (gr_handle_chroot_fowner(pid, type))
59453 + return -ENOENT;
59454 + if (gr_check_protected_task_fowner(pid, type))
59455 + return -EACCES;
59456 +
59457 f_modown(filp, pid, type, force);
59458 return 0;
59459 }
59460 diff --git a/fs/fhandle.c b/fs/fhandle.c
59461 index 999ff5c..41f4109 100644
59462 --- a/fs/fhandle.c
59463 +++ b/fs/fhandle.c
59464 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59465 } else
59466 retval = 0;
59467 /* copy the mount id */
59468 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59469 - sizeof(*mnt_id)) ||
59470 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59471 copy_to_user(ufh, handle,
59472 sizeof(struct file_handle) + handle_bytes))
59473 retval = -EFAULT;
59474 diff --git a/fs/file.c b/fs/file.c
59475 index 9de2026..8e334ca 100644
59476 --- a/fs/file.c
59477 +++ b/fs/file.c
59478 @@ -16,6 +16,7 @@
59479 #include <linux/slab.h>
59480 #include <linux/vmalloc.h>
59481 #include <linux/file.h>
59482 +#include <linux/security.h>
59483 #include <linux/fdtable.h>
59484 #include <linux/bitops.h>
59485 #include <linux/interrupt.h>
59486 @@ -141,7 +142,7 @@ out:
59487 * Return <0 error code on error; 1 on successful completion.
59488 * The files->file_lock should be held on entry, and will be held on exit.
59489 */
59490 -static int expand_fdtable(struct files_struct *files, int nr)
59491 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59492 __releases(files->file_lock)
59493 __acquires(files->file_lock)
59494 {
59495 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59496 * expanded and execution may have blocked.
59497 * The files->file_lock should be held on entry, and will be held on exit.
59498 */
59499 -static int expand_files(struct files_struct *files, int nr)
59500 +static int expand_files(struct files_struct *files, unsigned int nr)
59501 {
59502 struct fdtable *fdt;
59503
59504 @@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59505 if (!file)
59506 return __close_fd(files, fd);
59507
59508 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59509 if (fd >= rlimit(RLIMIT_NOFILE))
59510 return -EBADF;
59511
59512 @@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59513 if (unlikely(oldfd == newfd))
59514 return -EINVAL;
59515
59516 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59517 if (newfd >= rlimit(RLIMIT_NOFILE))
59518 return -EBADF;
59519
59520 @@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59521 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59522 {
59523 int err;
59524 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59525 if (from >= rlimit(RLIMIT_NOFILE))
59526 return -EINVAL;
59527 err = alloc_fd(from, flags);
59528 diff --git a/fs/filesystems.c b/fs/filesystems.c
59529 index 92567d9..fcd8cbf 100644
59530 --- a/fs/filesystems.c
59531 +++ b/fs/filesystems.c
59532 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59533 int len = dot ? dot - name : strlen(name);
59534
59535 fs = __get_fs_type(name, len);
59536 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
59537 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59538 +#else
59539 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59540 +#endif
59541 fs = __get_fs_type(name, len);
59542
59543 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59544 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59545 index 7dca743..543d620 100644
59546 --- a/fs/fs_struct.c
59547 +++ b/fs/fs_struct.c
59548 @@ -4,6 +4,7 @@
59549 #include <linux/path.h>
59550 #include <linux/slab.h>
59551 #include <linux/fs_struct.h>
59552 +#include <linux/grsecurity.h>
59553 #include "internal.h"
59554
59555 /*
59556 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59557 write_seqcount_begin(&fs->seq);
59558 old_root = fs->root;
59559 fs->root = *path;
59560 + gr_set_chroot_entries(current, path);
59561 write_seqcount_end(&fs->seq);
59562 spin_unlock(&fs->lock);
59563 if (old_root.dentry)
59564 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59565 int hits = 0;
59566 spin_lock(&fs->lock);
59567 write_seqcount_begin(&fs->seq);
59568 + /* this root replacement is only done by pivot_root,
59569 + leave grsec's chroot tagging alone for this task
59570 + so that a pivoted root isn't treated as a chroot
59571 + */
59572 hits += replace_path(&fs->root, old_root, new_root);
59573 hits += replace_path(&fs->pwd, old_root, new_root);
59574 write_seqcount_end(&fs->seq);
59575 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59576 task_lock(tsk);
59577 spin_lock(&fs->lock);
59578 tsk->fs = NULL;
59579 - kill = !--fs->users;
59580 + gr_clear_chroot_entries(tsk);
59581 + kill = !atomic_dec_return(&fs->users);
59582 spin_unlock(&fs->lock);
59583 task_unlock(tsk);
59584 if (kill)
59585 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59586 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59587 /* We don't need to lock fs - think why ;-) */
59588 if (fs) {
59589 - fs->users = 1;
59590 + atomic_set(&fs->users, 1);
59591 fs->in_exec = 0;
59592 spin_lock_init(&fs->lock);
59593 seqcount_init(&fs->seq);
59594 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59595 spin_lock(&old->lock);
59596 fs->root = old->root;
59597 path_get(&fs->root);
59598 + /* instead of calling gr_set_chroot_entries here,
59599 + we call it from every caller of this function
59600 + */
59601 fs->pwd = old->pwd;
59602 path_get(&fs->pwd);
59603 spin_unlock(&old->lock);
59604 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59605
59606 task_lock(current);
59607 spin_lock(&fs->lock);
59608 - kill = !--fs->users;
59609 + kill = !atomic_dec_return(&fs->users);
59610 current->fs = new_fs;
59611 + gr_set_chroot_entries(current, &new_fs->root);
59612 spin_unlock(&fs->lock);
59613 task_unlock(current);
59614
59615 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59616
59617 int current_umask(void)
59618 {
59619 - return current->fs->umask;
59620 + return current->fs->umask | gr_acl_umask();
59621 }
59622 EXPORT_SYMBOL(current_umask);
59623
59624 /* to be mentioned only in INIT_TASK */
59625 struct fs_struct init_fs = {
59626 - .users = 1,
59627 + .users = ATOMIC_INIT(1),
59628 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59629 .seq = SEQCNT_ZERO(init_fs.seq),
59630 .umask = 0022,
59631 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59632 index 29d7feb..303644d 100644
59633 --- a/fs/fscache/cookie.c
59634 +++ b/fs/fscache/cookie.c
59635 @@ -19,7 +19,7 @@
59636
59637 struct kmem_cache *fscache_cookie_jar;
59638
59639 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59640 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59641
59642 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59643 static int fscache_alloc_object(struct fscache_cache *cache,
59644 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59645 parent ? (char *) parent->def->name : "<no-parent>",
59646 def->name, netfs_data, enable);
59647
59648 - fscache_stat(&fscache_n_acquires);
59649 + fscache_stat_unchecked(&fscache_n_acquires);
59650
59651 /* if there's no parent cookie, then we don't create one here either */
59652 if (!parent) {
59653 - fscache_stat(&fscache_n_acquires_null);
59654 + fscache_stat_unchecked(&fscache_n_acquires_null);
59655 _leave(" [no parent]");
59656 return NULL;
59657 }
59658 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59659 /* allocate and initialise a cookie */
59660 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59661 if (!cookie) {
59662 - fscache_stat(&fscache_n_acquires_oom);
59663 + fscache_stat_unchecked(&fscache_n_acquires_oom);
59664 _leave(" [ENOMEM]");
59665 return NULL;
59666 }
59667 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59668
59669 switch (cookie->def->type) {
59670 case FSCACHE_COOKIE_TYPE_INDEX:
59671 - fscache_stat(&fscache_n_cookie_index);
59672 + fscache_stat_unchecked(&fscache_n_cookie_index);
59673 break;
59674 case FSCACHE_COOKIE_TYPE_DATAFILE:
59675 - fscache_stat(&fscache_n_cookie_data);
59676 + fscache_stat_unchecked(&fscache_n_cookie_data);
59677 break;
59678 default:
59679 - fscache_stat(&fscache_n_cookie_special);
59680 + fscache_stat_unchecked(&fscache_n_cookie_special);
59681 break;
59682 }
59683
59684 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59685 } else {
59686 atomic_dec(&parent->n_children);
59687 __fscache_cookie_put(cookie);
59688 - fscache_stat(&fscache_n_acquires_nobufs);
59689 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59690 _leave(" = NULL");
59691 return NULL;
59692 }
59693 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59694 }
59695 }
59696
59697 - fscache_stat(&fscache_n_acquires_ok);
59698 + fscache_stat_unchecked(&fscache_n_acquires_ok);
59699 _leave(" = %p", cookie);
59700 return cookie;
59701 }
59702 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59703 cache = fscache_select_cache_for_object(cookie->parent);
59704 if (!cache) {
59705 up_read(&fscache_addremove_sem);
59706 - fscache_stat(&fscache_n_acquires_no_cache);
59707 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59708 _leave(" = -ENOMEDIUM [no cache]");
59709 return -ENOMEDIUM;
59710 }
59711 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59712 object = cache->ops->alloc_object(cache, cookie);
59713 fscache_stat_d(&fscache_n_cop_alloc_object);
59714 if (IS_ERR(object)) {
59715 - fscache_stat(&fscache_n_object_no_alloc);
59716 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
59717 ret = PTR_ERR(object);
59718 goto error;
59719 }
59720
59721 - fscache_stat(&fscache_n_object_alloc);
59722 + fscache_stat_unchecked(&fscache_n_object_alloc);
59723
59724 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59725 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59726
59727 _debug("ALLOC OBJ%x: %s {%lx}",
59728 object->debug_id, cookie->def->name, object->events);
59729 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59730
59731 _enter("{%s}", cookie->def->name);
59732
59733 - fscache_stat(&fscache_n_invalidates);
59734 + fscache_stat_unchecked(&fscache_n_invalidates);
59735
59736 /* Only permit invalidation of data files. Invalidating an index will
59737 * require the caller to release all its attachments to the tree rooted
59738 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59739 {
59740 struct fscache_object *object;
59741
59742 - fscache_stat(&fscache_n_updates);
59743 + fscache_stat_unchecked(&fscache_n_updates);
59744
59745 if (!cookie) {
59746 - fscache_stat(&fscache_n_updates_null);
59747 + fscache_stat_unchecked(&fscache_n_updates_null);
59748 _leave(" [no cookie]");
59749 return;
59750 }
59751 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59752 */
59753 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59754 {
59755 - fscache_stat(&fscache_n_relinquishes);
59756 + fscache_stat_unchecked(&fscache_n_relinquishes);
59757 if (retire)
59758 - fscache_stat(&fscache_n_relinquishes_retire);
59759 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59760
59761 if (!cookie) {
59762 - fscache_stat(&fscache_n_relinquishes_null);
59763 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
59764 _leave(" [no cookie]");
59765 return;
59766 }
59767 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59768 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59769 goto inconsistent;
59770
59771 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59772 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59773
59774 __fscache_use_cookie(cookie);
59775 if (fscache_submit_op(object, op) < 0)
59776 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59777 index 4226f66..0fb3f45 100644
59778 --- a/fs/fscache/internal.h
59779 +++ b/fs/fscache/internal.h
59780 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59781 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59782 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59783 struct fscache_operation *,
59784 - atomic_t *,
59785 - atomic_t *,
59786 + atomic_unchecked_t *,
59787 + atomic_unchecked_t *,
59788 void (*)(struct fscache_operation *));
59789 extern void fscache_invalidate_writes(struct fscache_cookie *);
59790
59791 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59792 * stats.c
59793 */
59794 #ifdef CONFIG_FSCACHE_STATS
59795 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59796 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59797 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59798 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59799
59800 -extern atomic_t fscache_n_op_pend;
59801 -extern atomic_t fscache_n_op_run;
59802 -extern atomic_t fscache_n_op_enqueue;
59803 -extern atomic_t fscache_n_op_deferred_release;
59804 -extern atomic_t fscache_n_op_release;
59805 -extern atomic_t fscache_n_op_gc;
59806 -extern atomic_t fscache_n_op_cancelled;
59807 -extern atomic_t fscache_n_op_rejected;
59808 +extern atomic_unchecked_t fscache_n_op_pend;
59809 +extern atomic_unchecked_t fscache_n_op_run;
59810 +extern atomic_unchecked_t fscache_n_op_enqueue;
59811 +extern atomic_unchecked_t fscache_n_op_deferred_release;
59812 +extern atomic_unchecked_t fscache_n_op_release;
59813 +extern atomic_unchecked_t fscache_n_op_gc;
59814 +extern atomic_unchecked_t fscache_n_op_cancelled;
59815 +extern atomic_unchecked_t fscache_n_op_rejected;
59816
59817 -extern atomic_t fscache_n_attr_changed;
59818 -extern atomic_t fscache_n_attr_changed_ok;
59819 -extern atomic_t fscache_n_attr_changed_nobufs;
59820 -extern atomic_t fscache_n_attr_changed_nomem;
59821 -extern atomic_t fscache_n_attr_changed_calls;
59822 +extern atomic_unchecked_t fscache_n_attr_changed;
59823 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
59824 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59825 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59826 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
59827
59828 -extern atomic_t fscache_n_allocs;
59829 -extern atomic_t fscache_n_allocs_ok;
59830 -extern atomic_t fscache_n_allocs_wait;
59831 -extern atomic_t fscache_n_allocs_nobufs;
59832 -extern atomic_t fscache_n_allocs_intr;
59833 -extern atomic_t fscache_n_allocs_object_dead;
59834 -extern atomic_t fscache_n_alloc_ops;
59835 -extern atomic_t fscache_n_alloc_op_waits;
59836 +extern atomic_unchecked_t fscache_n_allocs;
59837 +extern atomic_unchecked_t fscache_n_allocs_ok;
59838 +extern atomic_unchecked_t fscache_n_allocs_wait;
59839 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
59840 +extern atomic_unchecked_t fscache_n_allocs_intr;
59841 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
59842 +extern atomic_unchecked_t fscache_n_alloc_ops;
59843 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
59844
59845 -extern atomic_t fscache_n_retrievals;
59846 -extern atomic_t fscache_n_retrievals_ok;
59847 -extern atomic_t fscache_n_retrievals_wait;
59848 -extern atomic_t fscache_n_retrievals_nodata;
59849 -extern atomic_t fscache_n_retrievals_nobufs;
59850 -extern atomic_t fscache_n_retrievals_intr;
59851 -extern atomic_t fscache_n_retrievals_nomem;
59852 -extern atomic_t fscache_n_retrievals_object_dead;
59853 -extern atomic_t fscache_n_retrieval_ops;
59854 -extern atomic_t fscache_n_retrieval_op_waits;
59855 +extern atomic_unchecked_t fscache_n_retrievals;
59856 +extern atomic_unchecked_t fscache_n_retrievals_ok;
59857 +extern atomic_unchecked_t fscache_n_retrievals_wait;
59858 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
59859 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59860 +extern atomic_unchecked_t fscache_n_retrievals_intr;
59861 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
59862 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59863 +extern atomic_unchecked_t fscache_n_retrieval_ops;
59864 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59865
59866 -extern atomic_t fscache_n_stores;
59867 -extern atomic_t fscache_n_stores_ok;
59868 -extern atomic_t fscache_n_stores_again;
59869 -extern atomic_t fscache_n_stores_nobufs;
59870 -extern atomic_t fscache_n_stores_oom;
59871 -extern atomic_t fscache_n_store_ops;
59872 -extern atomic_t fscache_n_store_calls;
59873 -extern atomic_t fscache_n_store_pages;
59874 -extern atomic_t fscache_n_store_radix_deletes;
59875 -extern atomic_t fscache_n_store_pages_over_limit;
59876 +extern atomic_unchecked_t fscache_n_stores;
59877 +extern atomic_unchecked_t fscache_n_stores_ok;
59878 +extern atomic_unchecked_t fscache_n_stores_again;
59879 +extern atomic_unchecked_t fscache_n_stores_nobufs;
59880 +extern atomic_unchecked_t fscache_n_stores_oom;
59881 +extern atomic_unchecked_t fscache_n_store_ops;
59882 +extern atomic_unchecked_t fscache_n_store_calls;
59883 +extern atomic_unchecked_t fscache_n_store_pages;
59884 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
59885 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59886
59887 -extern atomic_t fscache_n_store_vmscan_not_storing;
59888 -extern atomic_t fscache_n_store_vmscan_gone;
59889 -extern atomic_t fscache_n_store_vmscan_busy;
59890 -extern atomic_t fscache_n_store_vmscan_cancelled;
59891 -extern atomic_t fscache_n_store_vmscan_wait;
59892 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59893 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59894 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59895 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59896 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59897
59898 -extern atomic_t fscache_n_marks;
59899 -extern atomic_t fscache_n_uncaches;
59900 +extern atomic_unchecked_t fscache_n_marks;
59901 +extern atomic_unchecked_t fscache_n_uncaches;
59902
59903 -extern atomic_t fscache_n_acquires;
59904 -extern atomic_t fscache_n_acquires_null;
59905 -extern atomic_t fscache_n_acquires_no_cache;
59906 -extern atomic_t fscache_n_acquires_ok;
59907 -extern atomic_t fscache_n_acquires_nobufs;
59908 -extern atomic_t fscache_n_acquires_oom;
59909 +extern atomic_unchecked_t fscache_n_acquires;
59910 +extern atomic_unchecked_t fscache_n_acquires_null;
59911 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
59912 +extern atomic_unchecked_t fscache_n_acquires_ok;
59913 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
59914 +extern atomic_unchecked_t fscache_n_acquires_oom;
59915
59916 -extern atomic_t fscache_n_invalidates;
59917 -extern atomic_t fscache_n_invalidates_run;
59918 +extern atomic_unchecked_t fscache_n_invalidates;
59919 +extern atomic_unchecked_t fscache_n_invalidates_run;
59920
59921 -extern atomic_t fscache_n_updates;
59922 -extern atomic_t fscache_n_updates_null;
59923 -extern atomic_t fscache_n_updates_run;
59924 +extern atomic_unchecked_t fscache_n_updates;
59925 +extern atomic_unchecked_t fscache_n_updates_null;
59926 +extern atomic_unchecked_t fscache_n_updates_run;
59927
59928 -extern atomic_t fscache_n_relinquishes;
59929 -extern atomic_t fscache_n_relinquishes_null;
59930 -extern atomic_t fscache_n_relinquishes_waitcrt;
59931 -extern atomic_t fscache_n_relinquishes_retire;
59932 +extern atomic_unchecked_t fscache_n_relinquishes;
59933 +extern atomic_unchecked_t fscache_n_relinquishes_null;
59934 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59935 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
59936
59937 -extern atomic_t fscache_n_cookie_index;
59938 -extern atomic_t fscache_n_cookie_data;
59939 -extern atomic_t fscache_n_cookie_special;
59940 +extern atomic_unchecked_t fscache_n_cookie_index;
59941 +extern atomic_unchecked_t fscache_n_cookie_data;
59942 +extern atomic_unchecked_t fscache_n_cookie_special;
59943
59944 -extern atomic_t fscache_n_object_alloc;
59945 -extern atomic_t fscache_n_object_no_alloc;
59946 -extern atomic_t fscache_n_object_lookups;
59947 -extern atomic_t fscache_n_object_lookups_negative;
59948 -extern atomic_t fscache_n_object_lookups_positive;
59949 -extern atomic_t fscache_n_object_lookups_timed_out;
59950 -extern atomic_t fscache_n_object_created;
59951 -extern atomic_t fscache_n_object_avail;
59952 -extern atomic_t fscache_n_object_dead;
59953 +extern atomic_unchecked_t fscache_n_object_alloc;
59954 +extern atomic_unchecked_t fscache_n_object_no_alloc;
59955 +extern atomic_unchecked_t fscache_n_object_lookups;
59956 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
59957 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
59958 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59959 +extern atomic_unchecked_t fscache_n_object_created;
59960 +extern atomic_unchecked_t fscache_n_object_avail;
59961 +extern atomic_unchecked_t fscache_n_object_dead;
59962
59963 -extern atomic_t fscache_n_checkaux_none;
59964 -extern atomic_t fscache_n_checkaux_okay;
59965 -extern atomic_t fscache_n_checkaux_update;
59966 -extern atomic_t fscache_n_checkaux_obsolete;
59967 +extern atomic_unchecked_t fscache_n_checkaux_none;
59968 +extern atomic_unchecked_t fscache_n_checkaux_okay;
59969 +extern atomic_unchecked_t fscache_n_checkaux_update;
59970 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59971
59972 extern atomic_t fscache_n_cop_alloc_object;
59973 extern atomic_t fscache_n_cop_lookup_object;
59974 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59975 atomic_inc(stat);
59976 }
59977
59978 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59979 +{
59980 + atomic_inc_unchecked(stat);
59981 +}
59982 +
59983 static inline void fscache_stat_d(atomic_t *stat)
59984 {
59985 atomic_dec(stat);
59986 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59987
59988 #define __fscache_stat(stat) (NULL)
59989 #define fscache_stat(stat) do {} while (0)
59990 +#define fscache_stat_unchecked(stat) do {} while (0)
59991 #define fscache_stat_d(stat) do {} while (0)
59992 #endif
59993
59994 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59995 index 53d35c5..5d68ed4 100644
59996 --- a/fs/fscache/object.c
59997 +++ b/fs/fscache/object.c
59998 @@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59999 _debug("LOOKUP \"%s\" in \"%s\"",
60000 cookie->def->name, object->cache->tag->name);
60001
60002 - fscache_stat(&fscache_n_object_lookups);
60003 + fscache_stat_unchecked(&fscache_n_object_lookups);
60004 fscache_stat(&fscache_n_cop_lookup_object);
60005 ret = object->cache->ops->lookup_object(object);
60006 fscache_stat_d(&fscache_n_cop_lookup_object);
60007 @@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60008 if (ret == -ETIMEDOUT) {
60009 /* probably stuck behind another object, so move this one to
60010 * the back of the queue */
60011 - fscache_stat(&fscache_n_object_lookups_timed_out);
60012 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60013 _leave(" [timeout]");
60014 return NO_TRANSIT;
60015 }
60016 @@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60017 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60018
60019 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60020 - fscache_stat(&fscache_n_object_lookups_negative);
60021 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60022
60023 /* Allow write requests to begin stacking up and read requests to begin
60024 * returning ENODATA.
60025 @@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
60026 /* if we were still looking up, then we must have a positive lookup
60027 * result, in which case there may be data available */
60028 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60029 - fscache_stat(&fscache_n_object_lookups_positive);
60030 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60031
60032 /* We do (presumably) have data */
60033 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60034 @@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
60035 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60036 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60037 } else {
60038 - fscache_stat(&fscache_n_object_created);
60039 + fscache_stat_unchecked(&fscache_n_object_created);
60040 }
60041
60042 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60043 @@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60044 fscache_stat_d(&fscache_n_cop_lookup_complete);
60045
60046 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60047 - fscache_stat(&fscache_n_object_avail);
60048 + fscache_stat_unchecked(&fscache_n_object_avail);
60049
60050 _leave("");
60051 return transit_to(JUMPSTART_DEPS);
60052 @@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60053
60054 /* this just shifts the object release to the work processor */
60055 fscache_put_object(object);
60056 - fscache_stat(&fscache_n_object_dead);
60057 + fscache_stat_unchecked(&fscache_n_object_dead);
60058
60059 _leave("");
60060 return transit_to(OBJECT_DEAD);
60061 @@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60062 enum fscache_checkaux result;
60063
60064 if (!object->cookie->def->check_aux) {
60065 - fscache_stat(&fscache_n_checkaux_none);
60066 + fscache_stat_unchecked(&fscache_n_checkaux_none);
60067 return FSCACHE_CHECKAUX_OKAY;
60068 }
60069
60070 @@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60071 switch (result) {
60072 /* entry okay as is */
60073 case FSCACHE_CHECKAUX_OKAY:
60074 - fscache_stat(&fscache_n_checkaux_okay);
60075 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
60076 break;
60077
60078 /* entry requires update */
60079 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60080 - fscache_stat(&fscache_n_checkaux_update);
60081 + fscache_stat_unchecked(&fscache_n_checkaux_update);
60082 break;
60083
60084 /* entry requires deletion */
60085 case FSCACHE_CHECKAUX_OBSOLETE:
60086 - fscache_stat(&fscache_n_checkaux_obsolete);
60087 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60088 break;
60089
60090 default:
60091 @@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60092 {
60093 const struct fscache_state *s;
60094
60095 - fscache_stat(&fscache_n_invalidates_run);
60096 + fscache_stat_unchecked(&fscache_n_invalidates_run);
60097 fscache_stat(&fscache_n_cop_invalidate_object);
60098 s = _fscache_invalidate_object(object, event);
60099 fscache_stat_d(&fscache_n_cop_invalidate_object);
60100 @@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60101 {
60102 _enter("{OBJ%x},%d", object->debug_id, event);
60103
60104 - fscache_stat(&fscache_n_updates_run);
60105 + fscache_stat_unchecked(&fscache_n_updates_run);
60106 fscache_stat(&fscache_n_cop_update_object);
60107 object->cache->ops->update_object(object);
60108 fscache_stat_d(&fscache_n_cop_update_object);
60109 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60110 index 318071a..379938b 100644
60111 --- a/fs/fscache/operation.c
60112 +++ b/fs/fscache/operation.c
60113 @@ -17,7 +17,7 @@
60114 #include <linux/slab.h>
60115 #include "internal.h"
60116
60117 -atomic_t fscache_op_debug_id;
60118 +atomic_unchecked_t fscache_op_debug_id;
60119 EXPORT_SYMBOL(fscache_op_debug_id);
60120
60121 /**
60122 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60123 ASSERTCMP(atomic_read(&op->usage), >, 0);
60124 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60125
60126 - fscache_stat(&fscache_n_op_enqueue);
60127 + fscache_stat_unchecked(&fscache_n_op_enqueue);
60128 switch (op->flags & FSCACHE_OP_TYPE) {
60129 case FSCACHE_OP_ASYNC:
60130 _debug("queue async");
60131 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60132 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60133 if (op->processor)
60134 fscache_enqueue_operation(op);
60135 - fscache_stat(&fscache_n_op_run);
60136 + fscache_stat_unchecked(&fscache_n_op_run);
60137 }
60138
60139 /*
60140 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60141 if (object->n_in_progress > 0) {
60142 atomic_inc(&op->usage);
60143 list_add_tail(&op->pend_link, &object->pending_ops);
60144 - fscache_stat(&fscache_n_op_pend);
60145 + fscache_stat_unchecked(&fscache_n_op_pend);
60146 } else if (!list_empty(&object->pending_ops)) {
60147 atomic_inc(&op->usage);
60148 list_add_tail(&op->pend_link, &object->pending_ops);
60149 - fscache_stat(&fscache_n_op_pend);
60150 + fscache_stat_unchecked(&fscache_n_op_pend);
60151 fscache_start_operations(object);
60152 } else {
60153 ASSERTCMP(object->n_in_progress, ==, 0);
60154 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60155 object->n_exclusive++; /* reads and writes must wait */
60156 atomic_inc(&op->usage);
60157 list_add_tail(&op->pend_link, &object->pending_ops);
60158 - fscache_stat(&fscache_n_op_pend);
60159 + fscache_stat_unchecked(&fscache_n_op_pend);
60160 ret = 0;
60161 } else {
60162 /* If we're in any other state, there must have been an I/O
60163 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60164 if (object->n_exclusive > 0) {
60165 atomic_inc(&op->usage);
60166 list_add_tail(&op->pend_link, &object->pending_ops);
60167 - fscache_stat(&fscache_n_op_pend);
60168 + fscache_stat_unchecked(&fscache_n_op_pend);
60169 } else if (!list_empty(&object->pending_ops)) {
60170 atomic_inc(&op->usage);
60171 list_add_tail(&op->pend_link, &object->pending_ops);
60172 - fscache_stat(&fscache_n_op_pend);
60173 + fscache_stat_unchecked(&fscache_n_op_pend);
60174 fscache_start_operations(object);
60175 } else {
60176 ASSERTCMP(object->n_exclusive, ==, 0);
60177 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60178 object->n_ops++;
60179 atomic_inc(&op->usage);
60180 list_add_tail(&op->pend_link, &object->pending_ops);
60181 - fscache_stat(&fscache_n_op_pend);
60182 + fscache_stat_unchecked(&fscache_n_op_pend);
60183 ret = 0;
60184 } else if (fscache_object_is_dying(object)) {
60185 - fscache_stat(&fscache_n_op_rejected);
60186 + fscache_stat_unchecked(&fscache_n_op_rejected);
60187 op->state = FSCACHE_OP_ST_CANCELLED;
60188 ret = -ENOBUFS;
60189 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60190 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60191 ret = -EBUSY;
60192 if (op->state == FSCACHE_OP_ST_PENDING) {
60193 ASSERT(!list_empty(&op->pend_link));
60194 - fscache_stat(&fscache_n_op_cancelled);
60195 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60196 list_del_init(&op->pend_link);
60197 if (do_cancel)
60198 do_cancel(op);
60199 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60200 while (!list_empty(&object->pending_ops)) {
60201 op = list_entry(object->pending_ops.next,
60202 struct fscache_operation, pend_link);
60203 - fscache_stat(&fscache_n_op_cancelled);
60204 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60205 list_del_init(&op->pend_link);
60206
60207 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60208 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60209 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60210 op->state = FSCACHE_OP_ST_DEAD;
60211
60212 - fscache_stat(&fscache_n_op_release);
60213 + fscache_stat_unchecked(&fscache_n_op_release);
60214
60215 if (op->release) {
60216 op->release(op);
60217 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60218 * lock, and defer it otherwise */
60219 if (!spin_trylock(&object->lock)) {
60220 _debug("defer put");
60221 - fscache_stat(&fscache_n_op_deferred_release);
60222 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
60223
60224 cache = object->cache;
60225 spin_lock(&cache->op_gc_list_lock);
60226 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60227
60228 _debug("GC DEFERRED REL OBJ%x OP%x",
60229 object->debug_id, op->debug_id);
60230 - fscache_stat(&fscache_n_op_gc);
60231 + fscache_stat_unchecked(&fscache_n_op_gc);
60232
60233 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60234 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60235 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60236 index 7f5c658..6c1e164 100644
60237 --- a/fs/fscache/page.c
60238 +++ b/fs/fscache/page.c
60239 @@ -61,7 +61,7 @@ try_again:
60240 val = radix_tree_lookup(&cookie->stores, page->index);
60241 if (!val) {
60242 rcu_read_unlock();
60243 - fscache_stat(&fscache_n_store_vmscan_not_storing);
60244 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60245 __fscache_uncache_page(cookie, page);
60246 return true;
60247 }
60248 @@ -91,11 +91,11 @@ try_again:
60249 spin_unlock(&cookie->stores_lock);
60250
60251 if (xpage) {
60252 - fscache_stat(&fscache_n_store_vmscan_cancelled);
60253 - fscache_stat(&fscache_n_store_radix_deletes);
60254 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60255 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60256 ASSERTCMP(xpage, ==, page);
60257 } else {
60258 - fscache_stat(&fscache_n_store_vmscan_gone);
60259 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60260 }
60261
60262 wake_up_bit(&cookie->flags, 0);
60263 @@ -110,11 +110,11 @@ page_busy:
60264 * sleeping on memory allocation, so we may need to impose a timeout
60265 * too. */
60266 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60267 - fscache_stat(&fscache_n_store_vmscan_busy);
60268 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60269 return false;
60270 }
60271
60272 - fscache_stat(&fscache_n_store_vmscan_wait);
60273 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60274 __fscache_wait_on_page_write(cookie, page);
60275 gfp &= ~__GFP_WAIT;
60276 goto try_again;
60277 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60278 FSCACHE_COOKIE_STORING_TAG);
60279 if (!radix_tree_tag_get(&cookie->stores, page->index,
60280 FSCACHE_COOKIE_PENDING_TAG)) {
60281 - fscache_stat(&fscache_n_store_radix_deletes);
60282 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60283 xpage = radix_tree_delete(&cookie->stores, page->index);
60284 }
60285 spin_unlock(&cookie->stores_lock);
60286 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60287
60288 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60289
60290 - fscache_stat(&fscache_n_attr_changed_calls);
60291 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60292
60293 if (fscache_object_is_active(object)) {
60294 fscache_stat(&fscache_n_cop_attr_changed);
60295 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60296
60297 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60298
60299 - fscache_stat(&fscache_n_attr_changed);
60300 + fscache_stat_unchecked(&fscache_n_attr_changed);
60301
60302 op = kzalloc(sizeof(*op), GFP_KERNEL);
60303 if (!op) {
60304 - fscache_stat(&fscache_n_attr_changed_nomem);
60305 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60306 _leave(" = -ENOMEM");
60307 return -ENOMEM;
60308 }
60309 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60310 if (fscache_submit_exclusive_op(object, op) < 0)
60311 goto nobufs;
60312 spin_unlock(&cookie->lock);
60313 - fscache_stat(&fscache_n_attr_changed_ok);
60314 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60315 fscache_put_operation(op);
60316 _leave(" = 0");
60317 return 0;
60318 @@ -225,7 +225,7 @@ nobufs:
60319 kfree(op);
60320 if (wake_cookie)
60321 __fscache_wake_unused_cookie(cookie);
60322 - fscache_stat(&fscache_n_attr_changed_nobufs);
60323 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60324 _leave(" = %d", -ENOBUFS);
60325 return -ENOBUFS;
60326 }
60327 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60328 /* allocate a retrieval operation and attempt to submit it */
60329 op = kzalloc(sizeof(*op), GFP_NOIO);
60330 if (!op) {
60331 - fscache_stat(&fscache_n_retrievals_nomem);
60332 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60333 return NULL;
60334 }
60335
60336 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60337 return 0;
60338 }
60339
60340 - fscache_stat(&fscache_n_retrievals_wait);
60341 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60342
60343 jif = jiffies;
60344 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60345 fscache_wait_bit_interruptible,
60346 TASK_INTERRUPTIBLE) != 0) {
60347 - fscache_stat(&fscache_n_retrievals_intr);
60348 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60349 _leave(" = -ERESTARTSYS");
60350 return -ERESTARTSYS;
60351 }
60352 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60353 */
60354 int fscache_wait_for_operation_activation(struct fscache_object *object,
60355 struct fscache_operation *op,
60356 - atomic_t *stat_op_waits,
60357 - atomic_t *stat_object_dead,
60358 + atomic_unchecked_t *stat_op_waits,
60359 + atomic_unchecked_t *stat_object_dead,
60360 void (*do_cancel)(struct fscache_operation *))
60361 {
60362 int ret;
60363 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60364
60365 _debug(">>> WT");
60366 if (stat_op_waits)
60367 - fscache_stat(stat_op_waits);
60368 + fscache_stat_unchecked(stat_op_waits);
60369 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60370 fscache_wait_bit_interruptible,
60371 TASK_INTERRUPTIBLE) != 0) {
60372 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60373 check_if_dead:
60374 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60375 if (stat_object_dead)
60376 - fscache_stat(stat_object_dead);
60377 + fscache_stat_unchecked(stat_object_dead);
60378 _leave(" = -ENOBUFS [cancelled]");
60379 return -ENOBUFS;
60380 }
60381 @@ -366,7 +366,7 @@ check_if_dead:
60382 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60383 fscache_cancel_op(op, do_cancel);
60384 if (stat_object_dead)
60385 - fscache_stat(stat_object_dead);
60386 + fscache_stat_unchecked(stat_object_dead);
60387 return -ENOBUFS;
60388 }
60389 return 0;
60390 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60391
60392 _enter("%p,%p,,,", cookie, page);
60393
60394 - fscache_stat(&fscache_n_retrievals);
60395 + fscache_stat_unchecked(&fscache_n_retrievals);
60396
60397 if (hlist_empty(&cookie->backing_objects))
60398 goto nobufs;
60399 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60400 goto nobufs_unlock_dec;
60401 spin_unlock(&cookie->lock);
60402
60403 - fscache_stat(&fscache_n_retrieval_ops);
60404 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60405
60406 /* pin the netfs read context in case we need to do the actual netfs
60407 * read because we've encountered a cache read failure */
60408 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60409
60410 error:
60411 if (ret == -ENOMEM)
60412 - fscache_stat(&fscache_n_retrievals_nomem);
60413 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60414 else if (ret == -ERESTARTSYS)
60415 - fscache_stat(&fscache_n_retrievals_intr);
60416 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60417 else if (ret == -ENODATA)
60418 - fscache_stat(&fscache_n_retrievals_nodata);
60419 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60420 else if (ret < 0)
60421 - fscache_stat(&fscache_n_retrievals_nobufs);
60422 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60423 else
60424 - fscache_stat(&fscache_n_retrievals_ok);
60425 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60426
60427 fscache_put_retrieval(op);
60428 _leave(" = %d", ret);
60429 @@ -490,7 +490,7 @@ nobufs_unlock:
60430 __fscache_wake_unused_cookie(cookie);
60431 kfree(op);
60432 nobufs:
60433 - fscache_stat(&fscache_n_retrievals_nobufs);
60434 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60435 _leave(" = -ENOBUFS");
60436 return -ENOBUFS;
60437 }
60438 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60439
60440 _enter("%p,,%d,,,", cookie, *nr_pages);
60441
60442 - fscache_stat(&fscache_n_retrievals);
60443 + fscache_stat_unchecked(&fscache_n_retrievals);
60444
60445 if (hlist_empty(&cookie->backing_objects))
60446 goto nobufs;
60447 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60448 goto nobufs_unlock_dec;
60449 spin_unlock(&cookie->lock);
60450
60451 - fscache_stat(&fscache_n_retrieval_ops);
60452 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60453
60454 /* pin the netfs read context in case we need to do the actual netfs
60455 * read because we've encountered a cache read failure */
60456 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60457
60458 error:
60459 if (ret == -ENOMEM)
60460 - fscache_stat(&fscache_n_retrievals_nomem);
60461 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60462 else if (ret == -ERESTARTSYS)
60463 - fscache_stat(&fscache_n_retrievals_intr);
60464 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60465 else if (ret == -ENODATA)
60466 - fscache_stat(&fscache_n_retrievals_nodata);
60467 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60468 else if (ret < 0)
60469 - fscache_stat(&fscache_n_retrievals_nobufs);
60470 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60471 else
60472 - fscache_stat(&fscache_n_retrievals_ok);
60473 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60474
60475 fscache_put_retrieval(op);
60476 _leave(" = %d", ret);
60477 @@ -621,7 +621,7 @@ nobufs_unlock:
60478 if (wake_cookie)
60479 __fscache_wake_unused_cookie(cookie);
60480 nobufs:
60481 - fscache_stat(&fscache_n_retrievals_nobufs);
60482 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60483 _leave(" = -ENOBUFS");
60484 return -ENOBUFS;
60485 }
60486 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60487
60488 _enter("%p,%p,,,", cookie, page);
60489
60490 - fscache_stat(&fscache_n_allocs);
60491 + fscache_stat_unchecked(&fscache_n_allocs);
60492
60493 if (hlist_empty(&cookie->backing_objects))
60494 goto nobufs;
60495 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60496 goto nobufs_unlock_dec;
60497 spin_unlock(&cookie->lock);
60498
60499 - fscache_stat(&fscache_n_alloc_ops);
60500 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60501
60502 ret = fscache_wait_for_operation_activation(
60503 object, &op->op,
60504 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60505
60506 error:
60507 if (ret == -ERESTARTSYS)
60508 - fscache_stat(&fscache_n_allocs_intr);
60509 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60510 else if (ret < 0)
60511 - fscache_stat(&fscache_n_allocs_nobufs);
60512 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60513 else
60514 - fscache_stat(&fscache_n_allocs_ok);
60515 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60516
60517 fscache_put_retrieval(op);
60518 _leave(" = %d", ret);
60519 @@ -715,7 +715,7 @@ nobufs_unlock:
60520 if (wake_cookie)
60521 __fscache_wake_unused_cookie(cookie);
60522 nobufs:
60523 - fscache_stat(&fscache_n_allocs_nobufs);
60524 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60525 _leave(" = -ENOBUFS");
60526 return -ENOBUFS;
60527 }
60528 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60529
60530 spin_lock(&cookie->stores_lock);
60531
60532 - fscache_stat(&fscache_n_store_calls);
60533 + fscache_stat_unchecked(&fscache_n_store_calls);
60534
60535 /* find a page to store */
60536 page = NULL;
60537 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60538 page = results[0];
60539 _debug("gang %d [%lx]", n, page->index);
60540 if (page->index > op->store_limit) {
60541 - fscache_stat(&fscache_n_store_pages_over_limit);
60542 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60543 goto superseded;
60544 }
60545
60546 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60547 spin_unlock(&cookie->stores_lock);
60548 spin_unlock(&object->lock);
60549
60550 - fscache_stat(&fscache_n_store_pages);
60551 + fscache_stat_unchecked(&fscache_n_store_pages);
60552 fscache_stat(&fscache_n_cop_write_page);
60553 ret = object->cache->ops->write_page(op, page);
60554 fscache_stat_d(&fscache_n_cop_write_page);
60555 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60556 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60557 ASSERT(PageFsCache(page));
60558
60559 - fscache_stat(&fscache_n_stores);
60560 + fscache_stat_unchecked(&fscache_n_stores);
60561
60562 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60563 _leave(" = -ENOBUFS [invalidating]");
60564 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60565 spin_unlock(&cookie->stores_lock);
60566 spin_unlock(&object->lock);
60567
60568 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60569 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60570 op->store_limit = object->store_limit;
60571
60572 __fscache_use_cookie(cookie);
60573 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60574
60575 spin_unlock(&cookie->lock);
60576 radix_tree_preload_end();
60577 - fscache_stat(&fscache_n_store_ops);
60578 - fscache_stat(&fscache_n_stores_ok);
60579 + fscache_stat_unchecked(&fscache_n_store_ops);
60580 + fscache_stat_unchecked(&fscache_n_stores_ok);
60581
60582 /* the work queue now carries its own ref on the object */
60583 fscache_put_operation(&op->op);
60584 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60585 return 0;
60586
60587 already_queued:
60588 - fscache_stat(&fscache_n_stores_again);
60589 + fscache_stat_unchecked(&fscache_n_stores_again);
60590 already_pending:
60591 spin_unlock(&cookie->stores_lock);
60592 spin_unlock(&object->lock);
60593 spin_unlock(&cookie->lock);
60594 radix_tree_preload_end();
60595 kfree(op);
60596 - fscache_stat(&fscache_n_stores_ok);
60597 + fscache_stat_unchecked(&fscache_n_stores_ok);
60598 _leave(" = 0");
60599 return 0;
60600
60601 @@ -1024,14 +1024,14 @@ nobufs:
60602 kfree(op);
60603 if (wake_cookie)
60604 __fscache_wake_unused_cookie(cookie);
60605 - fscache_stat(&fscache_n_stores_nobufs);
60606 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
60607 _leave(" = -ENOBUFS");
60608 return -ENOBUFS;
60609
60610 nomem_free:
60611 kfree(op);
60612 nomem:
60613 - fscache_stat(&fscache_n_stores_oom);
60614 + fscache_stat_unchecked(&fscache_n_stores_oom);
60615 _leave(" = -ENOMEM");
60616 return -ENOMEM;
60617 }
60618 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60619 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60620 ASSERTCMP(page, !=, NULL);
60621
60622 - fscache_stat(&fscache_n_uncaches);
60623 + fscache_stat_unchecked(&fscache_n_uncaches);
60624
60625 /* cache withdrawal may beat us to it */
60626 if (!PageFsCache(page))
60627 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60628 struct fscache_cookie *cookie = op->op.object->cookie;
60629
60630 #ifdef CONFIG_FSCACHE_STATS
60631 - atomic_inc(&fscache_n_marks);
60632 + atomic_inc_unchecked(&fscache_n_marks);
60633 #endif
60634
60635 _debug("- mark %p{%lx}", page, page->index);
60636 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60637 index 40d13c7..ddf52b9 100644
60638 --- a/fs/fscache/stats.c
60639 +++ b/fs/fscache/stats.c
60640 @@ -18,99 +18,99 @@
60641 /*
60642 * operation counters
60643 */
60644 -atomic_t fscache_n_op_pend;
60645 -atomic_t fscache_n_op_run;
60646 -atomic_t fscache_n_op_enqueue;
60647 -atomic_t fscache_n_op_requeue;
60648 -atomic_t fscache_n_op_deferred_release;
60649 -atomic_t fscache_n_op_release;
60650 -atomic_t fscache_n_op_gc;
60651 -atomic_t fscache_n_op_cancelled;
60652 -atomic_t fscache_n_op_rejected;
60653 +atomic_unchecked_t fscache_n_op_pend;
60654 +atomic_unchecked_t fscache_n_op_run;
60655 +atomic_unchecked_t fscache_n_op_enqueue;
60656 +atomic_unchecked_t fscache_n_op_requeue;
60657 +atomic_unchecked_t fscache_n_op_deferred_release;
60658 +atomic_unchecked_t fscache_n_op_release;
60659 +atomic_unchecked_t fscache_n_op_gc;
60660 +atomic_unchecked_t fscache_n_op_cancelled;
60661 +atomic_unchecked_t fscache_n_op_rejected;
60662
60663 -atomic_t fscache_n_attr_changed;
60664 -atomic_t fscache_n_attr_changed_ok;
60665 -atomic_t fscache_n_attr_changed_nobufs;
60666 -atomic_t fscache_n_attr_changed_nomem;
60667 -atomic_t fscache_n_attr_changed_calls;
60668 +atomic_unchecked_t fscache_n_attr_changed;
60669 +atomic_unchecked_t fscache_n_attr_changed_ok;
60670 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
60671 +atomic_unchecked_t fscache_n_attr_changed_nomem;
60672 +atomic_unchecked_t fscache_n_attr_changed_calls;
60673
60674 -atomic_t fscache_n_allocs;
60675 -atomic_t fscache_n_allocs_ok;
60676 -atomic_t fscache_n_allocs_wait;
60677 -atomic_t fscache_n_allocs_nobufs;
60678 -atomic_t fscache_n_allocs_intr;
60679 -atomic_t fscache_n_allocs_object_dead;
60680 -atomic_t fscache_n_alloc_ops;
60681 -atomic_t fscache_n_alloc_op_waits;
60682 +atomic_unchecked_t fscache_n_allocs;
60683 +atomic_unchecked_t fscache_n_allocs_ok;
60684 +atomic_unchecked_t fscache_n_allocs_wait;
60685 +atomic_unchecked_t fscache_n_allocs_nobufs;
60686 +atomic_unchecked_t fscache_n_allocs_intr;
60687 +atomic_unchecked_t fscache_n_allocs_object_dead;
60688 +atomic_unchecked_t fscache_n_alloc_ops;
60689 +atomic_unchecked_t fscache_n_alloc_op_waits;
60690
60691 -atomic_t fscache_n_retrievals;
60692 -atomic_t fscache_n_retrievals_ok;
60693 -atomic_t fscache_n_retrievals_wait;
60694 -atomic_t fscache_n_retrievals_nodata;
60695 -atomic_t fscache_n_retrievals_nobufs;
60696 -atomic_t fscache_n_retrievals_intr;
60697 -atomic_t fscache_n_retrievals_nomem;
60698 -atomic_t fscache_n_retrievals_object_dead;
60699 -atomic_t fscache_n_retrieval_ops;
60700 -atomic_t fscache_n_retrieval_op_waits;
60701 +atomic_unchecked_t fscache_n_retrievals;
60702 +atomic_unchecked_t fscache_n_retrievals_ok;
60703 +atomic_unchecked_t fscache_n_retrievals_wait;
60704 +atomic_unchecked_t fscache_n_retrievals_nodata;
60705 +atomic_unchecked_t fscache_n_retrievals_nobufs;
60706 +atomic_unchecked_t fscache_n_retrievals_intr;
60707 +atomic_unchecked_t fscache_n_retrievals_nomem;
60708 +atomic_unchecked_t fscache_n_retrievals_object_dead;
60709 +atomic_unchecked_t fscache_n_retrieval_ops;
60710 +atomic_unchecked_t fscache_n_retrieval_op_waits;
60711
60712 -atomic_t fscache_n_stores;
60713 -atomic_t fscache_n_stores_ok;
60714 -atomic_t fscache_n_stores_again;
60715 -atomic_t fscache_n_stores_nobufs;
60716 -atomic_t fscache_n_stores_oom;
60717 -atomic_t fscache_n_store_ops;
60718 -atomic_t fscache_n_store_calls;
60719 -atomic_t fscache_n_store_pages;
60720 -atomic_t fscache_n_store_radix_deletes;
60721 -atomic_t fscache_n_store_pages_over_limit;
60722 +atomic_unchecked_t fscache_n_stores;
60723 +atomic_unchecked_t fscache_n_stores_ok;
60724 +atomic_unchecked_t fscache_n_stores_again;
60725 +atomic_unchecked_t fscache_n_stores_nobufs;
60726 +atomic_unchecked_t fscache_n_stores_oom;
60727 +atomic_unchecked_t fscache_n_store_ops;
60728 +atomic_unchecked_t fscache_n_store_calls;
60729 +atomic_unchecked_t fscache_n_store_pages;
60730 +atomic_unchecked_t fscache_n_store_radix_deletes;
60731 +atomic_unchecked_t fscache_n_store_pages_over_limit;
60732
60733 -atomic_t fscache_n_store_vmscan_not_storing;
60734 -atomic_t fscache_n_store_vmscan_gone;
60735 -atomic_t fscache_n_store_vmscan_busy;
60736 -atomic_t fscache_n_store_vmscan_cancelled;
60737 -atomic_t fscache_n_store_vmscan_wait;
60738 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60739 +atomic_unchecked_t fscache_n_store_vmscan_gone;
60740 +atomic_unchecked_t fscache_n_store_vmscan_busy;
60741 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60742 +atomic_unchecked_t fscache_n_store_vmscan_wait;
60743
60744 -atomic_t fscache_n_marks;
60745 -atomic_t fscache_n_uncaches;
60746 +atomic_unchecked_t fscache_n_marks;
60747 +atomic_unchecked_t fscache_n_uncaches;
60748
60749 -atomic_t fscache_n_acquires;
60750 -atomic_t fscache_n_acquires_null;
60751 -atomic_t fscache_n_acquires_no_cache;
60752 -atomic_t fscache_n_acquires_ok;
60753 -atomic_t fscache_n_acquires_nobufs;
60754 -atomic_t fscache_n_acquires_oom;
60755 +atomic_unchecked_t fscache_n_acquires;
60756 +atomic_unchecked_t fscache_n_acquires_null;
60757 +atomic_unchecked_t fscache_n_acquires_no_cache;
60758 +atomic_unchecked_t fscache_n_acquires_ok;
60759 +atomic_unchecked_t fscache_n_acquires_nobufs;
60760 +atomic_unchecked_t fscache_n_acquires_oom;
60761
60762 -atomic_t fscache_n_invalidates;
60763 -atomic_t fscache_n_invalidates_run;
60764 +atomic_unchecked_t fscache_n_invalidates;
60765 +atomic_unchecked_t fscache_n_invalidates_run;
60766
60767 -atomic_t fscache_n_updates;
60768 -atomic_t fscache_n_updates_null;
60769 -atomic_t fscache_n_updates_run;
60770 +atomic_unchecked_t fscache_n_updates;
60771 +atomic_unchecked_t fscache_n_updates_null;
60772 +atomic_unchecked_t fscache_n_updates_run;
60773
60774 -atomic_t fscache_n_relinquishes;
60775 -atomic_t fscache_n_relinquishes_null;
60776 -atomic_t fscache_n_relinquishes_waitcrt;
60777 -atomic_t fscache_n_relinquishes_retire;
60778 +atomic_unchecked_t fscache_n_relinquishes;
60779 +atomic_unchecked_t fscache_n_relinquishes_null;
60780 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60781 +atomic_unchecked_t fscache_n_relinquishes_retire;
60782
60783 -atomic_t fscache_n_cookie_index;
60784 -atomic_t fscache_n_cookie_data;
60785 -atomic_t fscache_n_cookie_special;
60786 +atomic_unchecked_t fscache_n_cookie_index;
60787 +atomic_unchecked_t fscache_n_cookie_data;
60788 +atomic_unchecked_t fscache_n_cookie_special;
60789
60790 -atomic_t fscache_n_object_alloc;
60791 -atomic_t fscache_n_object_no_alloc;
60792 -atomic_t fscache_n_object_lookups;
60793 -atomic_t fscache_n_object_lookups_negative;
60794 -atomic_t fscache_n_object_lookups_positive;
60795 -atomic_t fscache_n_object_lookups_timed_out;
60796 -atomic_t fscache_n_object_created;
60797 -atomic_t fscache_n_object_avail;
60798 -atomic_t fscache_n_object_dead;
60799 +atomic_unchecked_t fscache_n_object_alloc;
60800 +atomic_unchecked_t fscache_n_object_no_alloc;
60801 +atomic_unchecked_t fscache_n_object_lookups;
60802 +atomic_unchecked_t fscache_n_object_lookups_negative;
60803 +atomic_unchecked_t fscache_n_object_lookups_positive;
60804 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
60805 +atomic_unchecked_t fscache_n_object_created;
60806 +atomic_unchecked_t fscache_n_object_avail;
60807 +atomic_unchecked_t fscache_n_object_dead;
60808
60809 -atomic_t fscache_n_checkaux_none;
60810 -atomic_t fscache_n_checkaux_okay;
60811 -atomic_t fscache_n_checkaux_update;
60812 -atomic_t fscache_n_checkaux_obsolete;
60813 +atomic_unchecked_t fscache_n_checkaux_none;
60814 +atomic_unchecked_t fscache_n_checkaux_okay;
60815 +atomic_unchecked_t fscache_n_checkaux_update;
60816 +atomic_unchecked_t fscache_n_checkaux_obsolete;
60817
60818 atomic_t fscache_n_cop_alloc_object;
60819 atomic_t fscache_n_cop_lookup_object;
60820 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60821 seq_puts(m, "FS-Cache statistics\n");
60822
60823 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60824 - atomic_read(&fscache_n_cookie_index),
60825 - atomic_read(&fscache_n_cookie_data),
60826 - atomic_read(&fscache_n_cookie_special));
60827 + atomic_read_unchecked(&fscache_n_cookie_index),
60828 + atomic_read_unchecked(&fscache_n_cookie_data),
60829 + atomic_read_unchecked(&fscache_n_cookie_special));
60830
60831 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60832 - atomic_read(&fscache_n_object_alloc),
60833 - atomic_read(&fscache_n_object_no_alloc),
60834 - atomic_read(&fscache_n_object_avail),
60835 - atomic_read(&fscache_n_object_dead));
60836 + atomic_read_unchecked(&fscache_n_object_alloc),
60837 + atomic_read_unchecked(&fscache_n_object_no_alloc),
60838 + atomic_read_unchecked(&fscache_n_object_avail),
60839 + atomic_read_unchecked(&fscache_n_object_dead));
60840 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60841 - atomic_read(&fscache_n_checkaux_none),
60842 - atomic_read(&fscache_n_checkaux_okay),
60843 - atomic_read(&fscache_n_checkaux_update),
60844 - atomic_read(&fscache_n_checkaux_obsolete));
60845 + atomic_read_unchecked(&fscache_n_checkaux_none),
60846 + atomic_read_unchecked(&fscache_n_checkaux_okay),
60847 + atomic_read_unchecked(&fscache_n_checkaux_update),
60848 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60849
60850 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60851 - atomic_read(&fscache_n_marks),
60852 - atomic_read(&fscache_n_uncaches));
60853 + atomic_read_unchecked(&fscache_n_marks),
60854 + atomic_read_unchecked(&fscache_n_uncaches));
60855
60856 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60857 " oom=%u\n",
60858 - atomic_read(&fscache_n_acquires),
60859 - atomic_read(&fscache_n_acquires_null),
60860 - atomic_read(&fscache_n_acquires_no_cache),
60861 - atomic_read(&fscache_n_acquires_ok),
60862 - atomic_read(&fscache_n_acquires_nobufs),
60863 - atomic_read(&fscache_n_acquires_oom));
60864 + atomic_read_unchecked(&fscache_n_acquires),
60865 + atomic_read_unchecked(&fscache_n_acquires_null),
60866 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
60867 + atomic_read_unchecked(&fscache_n_acquires_ok),
60868 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
60869 + atomic_read_unchecked(&fscache_n_acquires_oom));
60870
60871 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60872 - atomic_read(&fscache_n_object_lookups),
60873 - atomic_read(&fscache_n_object_lookups_negative),
60874 - atomic_read(&fscache_n_object_lookups_positive),
60875 - atomic_read(&fscache_n_object_created),
60876 - atomic_read(&fscache_n_object_lookups_timed_out));
60877 + atomic_read_unchecked(&fscache_n_object_lookups),
60878 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
60879 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
60880 + atomic_read_unchecked(&fscache_n_object_created),
60881 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60882
60883 seq_printf(m, "Invals : n=%u run=%u\n",
60884 - atomic_read(&fscache_n_invalidates),
60885 - atomic_read(&fscache_n_invalidates_run));
60886 + atomic_read_unchecked(&fscache_n_invalidates),
60887 + atomic_read_unchecked(&fscache_n_invalidates_run));
60888
60889 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60890 - atomic_read(&fscache_n_updates),
60891 - atomic_read(&fscache_n_updates_null),
60892 - atomic_read(&fscache_n_updates_run));
60893 + atomic_read_unchecked(&fscache_n_updates),
60894 + atomic_read_unchecked(&fscache_n_updates_null),
60895 + atomic_read_unchecked(&fscache_n_updates_run));
60896
60897 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60898 - atomic_read(&fscache_n_relinquishes),
60899 - atomic_read(&fscache_n_relinquishes_null),
60900 - atomic_read(&fscache_n_relinquishes_waitcrt),
60901 - atomic_read(&fscache_n_relinquishes_retire));
60902 + atomic_read_unchecked(&fscache_n_relinquishes),
60903 + atomic_read_unchecked(&fscache_n_relinquishes_null),
60904 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60905 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
60906
60907 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60908 - atomic_read(&fscache_n_attr_changed),
60909 - atomic_read(&fscache_n_attr_changed_ok),
60910 - atomic_read(&fscache_n_attr_changed_nobufs),
60911 - atomic_read(&fscache_n_attr_changed_nomem),
60912 - atomic_read(&fscache_n_attr_changed_calls));
60913 + atomic_read_unchecked(&fscache_n_attr_changed),
60914 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
60915 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60916 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60917 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
60918
60919 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60920 - atomic_read(&fscache_n_allocs),
60921 - atomic_read(&fscache_n_allocs_ok),
60922 - atomic_read(&fscache_n_allocs_wait),
60923 - atomic_read(&fscache_n_allocs_nobufs),
60924 - atomic_read(&fscache_n_allocs_intr));
60925 + atomic_read_unchecked(&fscache_n_allocs),
60926 + atomic_read_unchecked(&fscache_n_allocs_ok),
60927 + atomic_read_unchecked(&fscache_n_allocs_wait),
60928 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
60929 + atomic_read_unchecked(&fscache_n_allocs_intr));
60930 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60931 - atomic_read(&fscache_n_alloc_ops),
60932 - atomic_read(&fscache_n_alloc_op_waits),
60933 - atomic_read(&fscache_n_allocs_object_dead));
60934 + atomic_read_unchecked(&fscache_n_alloc_ops),
60935 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
60936 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
60937
60938 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60939 " int=%u oom=%u\n",
60940 - atomic_read(&fscache_n_retrievals),
60941 - atomic_read(&fscache_n_retrievals_ok),
60942 - atomic_read(&fscache_n_retrievals_wait),
60943 - atomic_read(&fscache_n_retrievals_nodata),
60944 - atomic_read(&fscache_n_retrievals_nobufs),
60945 - atomic_read(&fscache_n_retrievals_intr),
60946 - atomic_read(&fscache_n_retrievals_nomem));
60947 + atomic_read_unchecked(&fscache_n_retrievals),
60948 + atomic_read_unchecked(&fscache_n_retrievals_ok),
60949 + atomic_read_unchecked(&fscache_n_retrievals_wait),
60950 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
60951 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60952 + atomic_read_unchecked(&fscache_n_retrievals_intr),
60953 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
60954 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60955 - atomic_read(&fscache_n_retrieval_ops),
60956 - atomic_read(&fscache_n_retrieval_op_waits),
60957 - atomic_read(&fscache_n_retrievals_object_dead));
60958 + atomic_read_unchecked(&fscache_n_retrieval_ops),
60959 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60960 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60961
60962 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60963 - atomic_read(&fscache_n_stores),
60964 - atomic_read(&fscache_n_stores_ok),
60965 - atomic_read(&fscache_n_stores_again),
60966 - atomic_read(&fscache_n_stores_nobufs),
60967 - atomic_read(&fscache_n_stores_oom));
60968 + atomic_read_unchecked(&fscache_n_stores),
60969 + atomic_read_unchecked(&fscache_n_stores_ok),
60970 + atomic_read_unchecked(&fscache_n_stores_again),
60971 + atomic_read_unchecked(&fscache_n_stores_nobufs),
60972 + atomic_read_unchecked(&fscache_n_stores_oom));
60973 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60974 - atomic_read(&fscache_n_store_ops),
60975 - atomic_read(&fscache_n_store_calls),
60976 - atomic_read(&fscache_n_store_pages),
60977 - atomic_read(&fscache_n_store_radix_deletes),
60978 - atomic_read(&fscache_n_store_pages_over_limit));
60979 + atomic_read_unchecked(&fscache_n_store_ops),
60980 + atomic_read_unchecked(&fscache_n_store_calls),
60981 + atomic_read_unchecked(&fscache_n_store_pages),
60982 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
60983 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60984
60985 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60986 - atomic_read(&fscache_n_store_vmscan_not_storing),
60987 - atomic_read(&fscache_n_store_vmscan_gone),
60988 - atomic_read(&fscache_n_store_vmscan_busy),
60989 - atomic_read(&fscache_n_store_vmscan_cancelled),
60990 - atomic_read(&fscache_n_store_vmscan_wait));
60991 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60992 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60993 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60994 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60995 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60996
60997 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60998 - atomic_read(&fscache_n_op_pend),
60999 - atomic_read(&fscache_n_op_run),
61000 - atomic_read(&fscache_n_op_enqueue),
61001 - atomic_read(&fscache_n_op_cancelled),
61002 - atomic_read(&fscache_n_op_rejected));
61003 + atomic_read_unchecked(&fscache_n_op_pend),
61004 + atomic_read_unchecked(&fscache_n_op_run),
61005 + atomic_read_unchecked(&fscache_n_op_enqueue),
61006 + atomic_read_unchecked(&fscache_n_op_cancelled),
61007 + atomic_read_unchecked(&fscache_n_op_rejected));
61008 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61009 - atomic_read(&fscache_n_op_deferred_release),
61010 - atomic_read(&fscache_n_op_release),
61011 - atomic_read(&fscache_n_op_gc));
61012 + atomic_read_unchecked(&fscache_n_op_deferred_release),
61013 + atomic_read_unchecked(&fscache_n_op_release),
61014 + atomic_read_unchecked(&fscache_n_op_gc));
61015
61016 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61017 atomic_read(&fscache_n_cop_alloc_object),
61018 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61019 index b96a49b..9bfdc47 100644
61020 --- a/fs/fuse/cuse.c
61021 +++ b/fs/fuse/cuse.c
61022 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
61023 INIT_LIST_HEAD(&cuse_conntbl[i]);
61024
61025 /* inherit and extend fuse_dev_operations */
61026 - cuse_channel_fops = fuse_dev_operations;
61027 - cuse_channel_fops.owner = THIS_MODULE;
61028 - cuse_channel_fops.open = cuse_channel_open;
61029 - cuse_channel_fops.release = cuse_channel_release;
61030 + pax_open_kernel();
61031 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61032 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61033 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
61034 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
61035 + pax_close_kernel();
61036
61037 cuse_class = class_create(THIS_MODULE, "cuse");
61038 if (IS_ERR(cuse_class))
61039 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61040 index fa8cb4b..4acb935 100644
61041 --- a/fs/fuse/dev.c
61042 +++ b/fs/fuse/dev.c
61043 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61044 ret = 0;
61045 pipe_lock(pipe);
61046
61047 - if (!pipe->readers) {
61048 + if (!atomic_read(&pipe->readers)) {
61049 send_sig(SIGPIPE, current, 0);
61050 if (!ret)
61051 ret = -EPIPE;
61052 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61053 page_nr++;
61054 ret += buf->len;
61055
61056 - if (pipe->files)
61057 + if (atomic_read(&pipe->files))
61058 do_wakeup = 1;
61059 }
61060
61061 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61062 index c3eb2c4..98007d4 100644
61063 --- a/fs/fuse/dir.c
61064 +++ b/fs/fuse/dir.c
61065 @@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
61066 return link;
61067 }
61068
61069 -static void free_link(char *link)
61070 +static void free_link(const char *link)
61071 {
61072 if (!IS_ERR(link))
61073 free_page((unsigned long) link);
61074 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61075 index db23ce1..9e6cd9d 100644
61076 --- a/fs/hostfs/hostfs_kern.c
61077 +++ b/fs/hostfs/hostfs_kern.c
61078 @@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61079
61080 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61081 {
61082 - char *s = nd_get_link(nd);
61083 + const char *s = nd_get_link(nd);
61084 if (!IS_ERR(s))
61085 __putname(s);
61086 }
61087 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61088 index d19b30a..ef89c36 100644
61089 --- a/fs/hugetlbfs/inode.c
61090 +++ b/fs/hugetlbfs/inode.c
61091 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61092 struct mm_struct *mm = current->mm;
61093 struct vm_area_struct *vma;
61094 struct hstate *h = hstate_file(file);
61095 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61096 struct vm_unmapped_area_info info;
61097
61098 if (len & ~huge_page_mask(h))
61099 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61100 return addr;
61101 }
61102
61103 +#ifdef CONFIG_PAX_RANDMMAP
61104 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61105 +#endif
61106 +
61107 if (addr) {
61108 addr = ALIGN(addr, huge_page_size(h));
61109 vma = find_vma(mm, addr);
61110 - if (TASK_SIZE - len >= addr &&
61111 - (!vma || addr + len <= vma->vm_start))
61112 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61113 return addr;
61114 }
61115
61116 info.flags = 0;
61117 info.length = len;
61118 info.low_limit = TASK_UNMAPPED_BASE;
61119 +
61120 +#ifdef CONFIG_PAX_RANDMMAP
61121 + if (mm->pax_flags & MF_PAX_RANDMMAP)
61122 + info.low_limit += mm->delta_mmap;
61123 +#endif
61124 +
61125 info.high_limit = TASK_SIZE;
61126 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61127 info.align_offset = 0;
61128 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61129 };
61130 MODULE_ALIAS_FS("hugetlbfs");
61131
61132 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61133 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61134
61135 static int can_do_hugetlb_shm(void)
61136 {
61137 diff --git a/fs/inode.c b/fs/inode.c
61138 index 4bcdad3..1883822 100644
61139 --- a/fs/inode.c
61140 +++ b/fs/inode.c
61141 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61142
61143 #ifdef CONFIG_SMP
61144 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61145 - static atomic_t shared_last_ino;
61146 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61147 + static atomic_unchecked_t shared_last_ino;
61148 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61149
61150 res = next - LAST_INO_BATCH;
61151 }
61152 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61153 index 4a6cf28..d3a29d3 100644
61154 --- a/fs/jffs2/erase.c
61155 +++ b/fs/jffs2/erase.c
61156 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61157 struct jffs2_unknown_node marker = {
61158 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61159 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61160 - .totlen = cpu_to_je32(c->cleanmarker_size)
61161 + .totlen = cpu_to_je32(c->cleanmarker_size),
61162 + .hdr_crc = cpu_to_je32(0)
61163 };
61164
61165 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61166 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61167 index a6597d6..41b30ec 100644
61168 --- a/fs/jffs2/wbuf.c
61169 +++ b/fs/jffs2/wbuf.c
61170 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61171 {
61172 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61173 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61174 - .totlen = constant_cpu_to_je32(8)
61175 + .totlen = constant_cpu_to_je32(8),
61176 + .hdr_crc = constant_cpu_to_je32(0)
61177 };
61178
61179 /*
61180 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61181 index 6669aa2..36b033d 100644
61182 --- a/fs/jfs/super.c
61183 +++ b/fs/jfs/super.c
61184 @@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
61185
61186 jfs_inode_cachep =
61187 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61188 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61189 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61190 init_once);
61191 if (jfs_inode_cachep == NULL)
61192 return -ENOMEM;
61193 diff --git a/fs/libfs.c b/fs/libfs.c
61194 index a184424..944ddce 100644
61195 --- a/fs/libfs.c
61196 +++ b/fs/libfs.c
61197 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61198
61199 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61200 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61201 + char d_name[sizeof(next->d_iname)];
61202 + const unsigned char *name;
61203 +
61204 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61205 if (!simple_positive(next)) {
61206 spin_unlock(&next->d_lock);
61207 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61208
61209 spin_unlock(&next->d_lock);
61210 spin_unlock(&dentry->d_lock);
61211 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61212 + name = next->d_name.name;
61213 + if (name == next->d_iname) {
61214 + memcpy(d_name, name, next->d_name.len);
61215 + name = d_name;
61216 + }
61217 + if (!dir_emit(ctx, name, next->d_name.len,
61218 next->d_inode->i_ino, dt_type(next->d_inode)))
61219 return 0;
61220 spin_lock(&dentry->d_lock);
61221 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61222 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61223 void *cookie)
61224 {
61225 - char *s = nd_get_link(nd);
61226 + const char *s = nd_get_link(nd);
61227 if (!IS_ERR(s))
61228 kfree(s);
61229 }
61230 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61231 index acd3947..1f896e2 100644
61232 --- a/fs/lockd/clntproc.c
61233 +++ b/fs/lockd/clntproc.c
61234 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61235 /*
61236 * Cookie counter for NLM requests
61237 */
61238 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61239 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61240
61241 void nlmclnt_next_cookie(struct nlm_cookie *c)
61242 {
61243 - u32 cookie = atomic_inc_return(&nlm_cookie);
61244 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61245
61246 memcpy(c->data, &cookie, 4);
61247 c->len=4;
61248 diff --git a/fs/locks.c b/fs/locks.c
61249 index 92a0f0a..45a48f0 100644
61250 --- a/fs/locks.c
61251 +++ b/fs/locks.c
61252 @@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61253 return;
61254
61255 if (filp->f_op->flock) {
61256 - struct file_lock fl = {
61257 + struct file_lock flock = {
61258 .fl_pid = current->tgid,
61259 .fl_file = filp,
61260 .fl_flags = FL_FLOCK,
61261 .fl_type = F_UNLCK,
61262 .fl_end = OFFSET_MAX,
61263 };
61264 - filp->f_op->flock(filp, F_SETLKW, &fl);
61265 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61266 - fl.fl_ops->fl_release_private(&fl);
61267 + filp->f_op->flock(filp, F_SETLKW, &flock);
61268 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61269 + flock.fl_ops->fl_release_private(&flock);
61270 }
61271
61272 spin_lock(&inode->i_lock);
61273 diff --git a/fs/mount.h b/fs/mount.h
61274 index b29e42f..5ea7fdf 100644
61275 --- a/fs/mount.h
61276 +++ b/fs/mount.h
61277 @@ -11,7 +11,7 @@ struct mnt_namespace {
61278 u64 seq; /* Sequence number to prevent loops */
61279 wait_queue_head_t poll;
61280 int event;
61281 -};
61282 +} __randomize_layout;
61283
61284 struct mnt_pcp {
61285 int mnt_count;
61286 @@ -57,7 +57,7 @@ struct mount {
61287 int mnt_expiry_mark; /* true if marked for expiry */
61288 int mnt_pinned;
61289 struct path mnt_ex_mountpoint;
61290 -};
61291 +} __randomize_layout;
61292
61293 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61294
61295 diff --git a/fs/namei.c b/fs/namei.c
61296 index 399f637..a24748c 100644
61297 --- a/fs/namei.c
61298 +++ b/fs/namei.c
61299 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
61300 if (ret != -EACCES)
61301 return ret;
61302
61303 +#ifdef CONFIG_GRKERNSEC
61304 + /* we'll block if we have to log due to a denied capability use */
61305 + if (mask & MAY_NOT_BLOCK)
61306 + return -ECHILD;
61307 +#endif
61308 +
61309 if (S_ISDIR(inode->i_mode)) {
61310 /* DACs are overridable for directories */
61311 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
61312 - return 0;
61313 if (!(mask & MAY_WRITE))
61314 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61315 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61316 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61317 return 0;
61318 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
61319 + return 0;
61320 return -EACCES;
61321 }
61322 /*
61323 + * Searching includes executable on directories, else just read.
61324 + */
61325 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61326 + if (mask == MAY_READ)
61327 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61328 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61329 + return 0;
61330 +
61331 + /*
61332 * Read/write DACs are always overridable.
61333 * Executable DACs are overridable when there is
61334 * at least one exec bit set.
61335 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
61336 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61337 return 0;
61338
61339 - /*
61340 - * Searching includes executable on directories, else just read.
61341 - */
61342 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61343 - if (mask == MAY_READ)
61344 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61345 - return 0;
61346 -
61347 return -EACCES;
61348 }
61349
61350 @@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61351 {
61352 struct dentry *dentry = link->dentry;
61353 int error;
61354 - char *s;
61355 + const char *s;
61356
61357 BUG_ON(nd->flags & LOOKUP_RCU);
61358
61359 @@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61360 if (error)
61361 goto out_put_nd_path;
61362
61363 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61364 + dentry->d_inode, dentry, nd->path.mnt)) {
61365 + error = -EACCES;
61366 + goto out_put_nd_path;
61367 + }
61368 +
61369 nd->last_type = LAST_BIND;
61370 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61371 error = PTR_ERR(*p);
61372 @@ -1579,6 +1593,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61373 if (res)
61374 break;
61375 res = walk_component(nd, path, LOOKUP_FOLLOW);
61376 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61377 + res = -EACCES;
61378 put_link(nd, &link, cookie);
61379 } while (res > 0);
61380
61381 @@ -1652,7 +1668,7 @@ EXPORT_SYMBOL(full_name_hash);
61382 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61383 {
61384 unsigned long a, b, adata, bdata, mask, hash, len;
61385 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61386 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61387
61388 hash = a = 0;
61389 len = -sizeof(unsigned long);
61390 @@ -1936,6 +1952,8 @@ static int path_lookupat(int dfd, const char *name,
61391 if (err)
61392 break;
61393 err = lookup_last(nd, &path);
61394 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61395 + err = -EACCES;
61396 put_link(nd, &link, cookie);
61397 }
61398 }
61399 @@ -1943,6 +1961,13 @@ static int path_lookupat(int dfd, const char *name,
61400 if (!err)
61401 err = complete_walk(nd);
61402
61403 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61404 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61405 + path_put(&nd->path);
61406 + err = -ENOENT;
61407 + }
61408 + }
61409 +
61410 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61411 if (!d_is_directory(nd->path.dentry)) {
61412 path_put(&nd->path);
61413 @@ -1970,8 +1995,15 @@ static int filename_lookup(int dfd, struct filename *name,
61414 retval = path_lookupat(dfd, name->name,
61415 flags | LOOKUP_REVAL, nd);
61416
61417 - if (likely(!retval))
61418 + if (likely(!retval)) {
61419 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61420 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61421 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61422 + path_put(&nd->path);
61423 + return -ENOENT;
61424 + }
61425 + }
61426 + }
61427 return retval;
61428 }
61429
61430 @@ -2545,6 +2577,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61431 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61432 return -EPERM;
61433
61434 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61435 + return -EPERM;
61436 + if (gr_handle_rawio(inode))
61437 + return -EPERM;
61438 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61439 + return -EACCES;
61440 +
61441 return 0;
61442 }
61443
61444 @@ -2776,7 +2815,7 @@ looked_up:
61445 * cleared otherwise prior to returning.
61446 */
61447 static int lookup_open(struct nameidata *nd, struct path *path,
61448 - struct file *file,
61449 + struct path *link, struct file *file,
61450 const struct open_flags *op,
61451 bool got_write, int *opened)
61452 {
61453 @@ -2811,6 +2850,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61454 /* Negative dentry, just create the file */
61455 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61456 umode_t mode = op->mode;
61457 +
61458 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61459 + error = -EACCES;
61460 + goto out_dput;
61461 + }
61462 +
61463 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61464 + error = -EACCES;
61465 + goto out_dput;
61466 + }
61467 +
61468 if (!IS_POSIXACL(dir->d_inode))
61469 mode &= ~current_umask();
61470 /*
61471 @@ -2832,6 +2882,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61472 nd->flags & LOOKUP_EXCL);
61473 if (error)
61474 goto out_dput;
61475 + else
61476 + gr_handle_create(dentry, nd->path.mnt);
61477 }
61478 out_no_open:
61479 path->dentry = dentry;
61480 @@ -2846,7 +2898,7 @@ out_dput:
61481 /*
61482 * Handle the last step of open()
61483 */
61484 -static int do_last(struct nameidata *nd, struct path *path,
61485 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61486 struct file *file, const struct open_flags *op,
61487 int *opened, struct filename *name)
61488 {
61489 @@ -2896,6 +2948,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61490 if (error)
61491 return error;
61492
61493 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61494 + error = -ENOENT;
61495 + goto out;
61496 + }
61497 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61498 + error = -EACCES;
61499 + goto out;
61500 + }
61501 +
61502 audit_inode(name, dir, LOOKUP_PARENT);
61503 error = -EISDIR;
61504 /* trailing slashes? */
61505 @@ -2915,7 +2976,7 @@ retry_lookup:
61506 */
61507 }
61508 mutex_lock(&dir->d_inode->i_mutex);
61509 - error = lookup_open(nd, path, file, op, got_write, opened);
61510 + error = lookup_open(nd, path, link, file, op, got_write, opened);
61511 mutex_unlock(&dir->d_inode->i_mutex);
61512
61513 if (error <= 0) {
61514 @@ -2939,11 +3000,28 @@ retry_lookup:
61515 goto finish_open_created;
61516 }
61517
61518 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61519 + error = -ENOENT;
61520 + goto exit_dput;
61521 + }
61522 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61523 + error = -EACCES;
61524 + goto exit_dput;
61525 + }
61526 +
61527 /*
61528 * create/update audit record if it already exists.
61529 */
61530 - if (d_is_positive(path->dentry))
61531 + if (d_is_positive(path->dentry)) {
61532 + /* only check if O_CREAT is specified, all other checks need to go
61533 + into may_open */
61534 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61535 + error = -EACCES;
61536 + goto exit_dput;
61537 + }
61538 +
61539 audit_inode(name, path->dentry, 0);
61540 + }
61541
61542 /*
61543 * If atomic_open() acquired write access it is dropped now due to
61544 @@ -2984,6 +3062,11 @@ finish_lookup:
61545 }
61546 }
61547 BUG_ON(inode != path->dentry->d_inode);
61548 + /* if we're resolving a symlink to another symlink */
61549 + if (link && gr_handle_symlink_owner(link, inode)) {
61550 + error = -EACCES;
61551 + goto out;
61552 + }
61553 return 1;
61554 }
61555
61556 @@ -2993,7 +3076,6 @@ finish_lookup:
61557 save_parent.dentry = nd->path.dentry;
61558 save_parent.mnt = mntget(path->mnt);
61559 nd->path.dentry = path->dentry;
61560 -
61561 }
61562 nd->inode = inode;
61563 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61564 @@ -3003,7 +3085,18 @@ finish_open:
61565 path_put(&save_parent);
61566 return error;
61567 }
61568 +
61569 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61570 + error = -ENOENT;
61571 + goto out;
61572 + }
61573 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61574 + error = -EACCES;
61575 + goto out;
61576 + }
61577 +
61578 audit_inode(name, nd->path.dentry, 0);
61579 +
61580 error = -EISDIR;
61581 if ((open_flag & O_CREAT) &&
61582 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61583 @@ -3167,7 +3260,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61584 if (unlikely(error))
61585 goto out;
61586
61587 - error = do_last(nd, &path, file, op, &opened, pathname);
61588 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61589 while (unlikely(error > 0)) { /* trailing symlink */
61590 struct path link = path;
61591 void *cookie;
61592 @@ -3185,7 +3278,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61593 error = follow_link(&link, nd, &cookie);
61594 if (unlikely(error))
61595 break;
61596 - error = do_last(nd, &path, file, op, &opened, pathname);
61597 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
61598 put_link(nd, &link, cookie);
61599 }
61600 out:
61601 @@ -3285,9 +3378,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61602 goto unlock;
61603
61604 error = -EEXIST;
61605 - if (d_is_positive(dentry))
61606 + if (d_is_positive(dentry)) {
61607 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61608 + error = -ENOENT;
61609 goto fail;
61610 -
61611 + }
61612 /*
61613 * Special case - lookup gave negative, but... we had foo/bar/
61614 * From the vfs_mknod() POV we just have a negative dentry -
61615 @@ -3339,6 +3434,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61616 }
61617 EXPORT_SYMBOL(user_path_create);
61618
61619 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61620 +{
61621 + struct filename *tmp = getname(pathname);
61622 + struct dentry *res;
61623 + if (IS_ERR(tmp))
61624 + return ERR_CAST(tmp);
61625 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61626 + if (IS_ERR(res))
61627 + putname(tmp);
61628 + else
61629 + *to = tmp;
61630 + return res;
61631 +}
61632 +
61633 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61634 {
61635 int error = may_create(dir, dentry);
61636 @@ -3401,6 +3510,17 @@ retry:
61637
61638 if (!IS_POSIXACL(path.dentry->d_inode))
61639 mode &= ~current_umask();
61640 +
61641 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61642 + error = -EPERM;
61643 + goto out;
61644 + }
61645 +
61646 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61647 + error = -EACCES;
61648 + goto out;
61649 + }
61650 +
61651 error = security_path_mknod(&path, dentry, mode, dev);
61652 if (error)
61653 goto out;
61654 @@ -3417,6 +3537,8 @@ retry:
61655 break;
61656 }
61657 out:
61658 + if (!error)
61659 + gr_handle_create(dentry, path.mnt);
61660 done_path_create(&path, dentry);
61661 if (retry_estale(error, lookup_flags)) {
61662 lookup_flags |= LOOKUP_REVAL;
61663 @@ -3469,9 +3591,16 @@ retry:
61664
61665 if (!IS_POSIXACL(path.dentry->d_inode))
61666 mode &= ~current_umask();
61667 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61668 + error = -EACCES;
61669 + goto out;
61670 + }
61671 error = security_path_mkdir(&path, dentry, mode);
61672 if (!error)
61673 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61674 + if (!error)
61675 + gr_handle_create(dentry, path.mnt);
61676 +out:
61677 done_path_create(&path, dentry);
61678 if (retry_estale(error, lookup_flags)) {
61679 lookup_flags |= LOOKUP_REVAL;
61680 @@ -3552,6 +3681,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61681 struct filename *name;
61682 struct dentry *dentry;
61683 struct nameidata nd;
61684 + ino_t saved_ino = 0;
61685 + dev_t saved_dev = 0;
61686 unsigned int lookup_flags = 0;
61687 retry:
61688 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61689 @@ -3584,10 +3715,21 @@ retry:
61690 error = -ENOENT;
61691 goto exit3;
61692 }
61693 +
61694 + saved_ino = dentry->d_inode->i_ino;
61695 + saved_dev = gr_get_dev_from_dentry(dentry);
61696 +
61697 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61698 + error = -EACCES;
61699 + goto exit3;
61700 + }
61701 +
61702 error = security_path_rmdir(&nd.path, dentry);
61703 if (error)
61704 goto exit3;
61705 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61706 + if (!error && (saved_dev || saved_ino))
61707 + gr_handle_delete(saved_ino, saved_dev);
61708 exit3:
61709 dput(dentry);
61710 exit2:
61711 @@ -3677,6 +3819,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61712 struct nameidata nd;
61713 struct inode *inode = NULL;
61714 struct inode *delegated_inode = NULL;
61715 + ino_t saved_ino = 0;
61716 + dev_t saved_dev = 0;
61717 unsigned int lookup_flags = 0;
61718 retry:
61719 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61720 @@ -3703,10 +3847,22 @@ retry_deleg:
61721 if (d_is_negative(dentry))
61722 goto slashes;
61723 ihold(inode);
61724 +
61725 + if (inode->i_nlink <= 1) {
61726 + saved_ino = inode->i_ino;
61727 + saved_dev = gr_get_dev_from_dentry(dentry);
61728 + }
61729 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61730 + error = -EACCES;
61731 + goto exit2;
61732 + }
61733 +
61734 error = security_path_unlink(&nd.path, dentry);
61735 if (error)
61736 goto exit2;
61737 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61738 + if (!error && (saved_ino || saved_dev))
61739 + gr_handle_delete(saved_ino, saved_dev);
61740 exit2:
61741 dput(dentry);
61742 }
61743 @@ -3794,9 +3950,17 @@ retry:
61744 if (IS_ERR(dentry))
61745 goto out_putname;
61746
61747 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61748 + error = -EACCES;
61749 + goto out;
61750 + }
61751 +
61752 error = security_path_symlink(&path, dentry, from->name);
61753 if (!error)
61754 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61755 + if (!error)
61756 + gr_handle_create(dentry, path.mnt);
61757 +out:
61758 done_path_create(&path, dentry);
61759 if (retry_estale(error, lookup_flags)) {
61760 lookup_flags |= LOOKUP_REVAL;
61761 @@ -3899,6 +4063,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61762 struct dentry *new_dentry;
61763 struct path old_path, new_path;
61764 struct inode *delegated_inode = NULL;
61765 + struct filename *to = NULL;
61766 int how = 0;
61767 int error;
61768
61769 @@ -3922,7 +4087,7 @@ retry:
61770 if (error)
61771 return error;
61772
61773 - new_dentry = user_path_create(newdfd, newname, &new_path,
61774 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61775 (how & LOOKUP_REVAL));
61776 error = PTR_ERR(new_dentry);
61777 if (IS_ERR(new_dentry))
61778 @@ -3934,11 +4099,28 @@ retry:
61779 error = may_linkat(&old_path);
61780 if (unlikely(error))
61781 goto out_dput;
61782 +
61783 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61784 + old_path.dentry->d_inode,
61785 + old_path.dentry->d_inode->i_mode, to)) {
61786 + error = -EACCES;
61787 + goto out_dput;
61788 + }
61789 +
61790 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61791 + old_path.dentry, old_path.mnt, to)) {
61792 + error = -EACCES;
61793 + goto out_dput;
61794 + }
61795 +
61796 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61797 if (error)
61798 goto out_dput;
61799 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61800 + if (!error)
61801 + gr_handle_create(new_dentry, new_path.mnt);
61802 out_dput:
61803 + putname(to);
61804 done_path_create(&new_path, new_dentry);
61805 if (delegated_inode) {
61806 error = break_deleg_wait(&delegated_inode);
61807 @@ -4225,6 +4407,12 @@ retry_deleg:
61808 if (new_dentry == trap)
61809 goto exit5;
61810
61811 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61812 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
61813 + to);
61814 + if (error)
61815 + goto exit5;
61816 +
61817 error = security_path_rename(&oldnd.path, old_dentry,
61818 &newnd.path, new_dentry);
61819 if (error)
61820 @@ -4232,6 +4420,9 @@ retry_deleg:
61821 error = vfs_rename(old_dir->d_inode, old_dentry,
61822 new_dir->d_inode, new_dentry,
61823 &delegated_inode);
61824 + if (!error)
61825 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61826 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61827 exit5:
61828 dput(new_dentry);
61829 exit4:
61830 @@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61831
61832 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61833 {
61834 + char tmpbuf[64];
61835 + const char *newlink;
61836 int len;
61837
61838 len = PTR_ERR(link);
61839 @@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61840 len = strlen(link);
61841 if (len > (unsigned) buflen)
61842 len = buflen;
61843 - if (copy_to_user(buffer, link, len))
61844 +
61845 + if (len < sizeof(tmpbuf)) {
61846 + memcpy(tmpbuf, link, len);
61847 + newlink = tmpbuf;
61848 + } else
61849 + newlink = link;
61850 +
61851 + if (copy_to_user(buffer, newlink, len))
61852 len = -EFAULT;
61853 out:
61854 return len;
61855 diff --git a/fs/namespace.c b/fs/namespace.c
61856 index 6d0e54e..4c1f85e 100644
61857 --- a/fs/namespace.c
61858 +++ b/fs/namespace.c
61859 @@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
61860 if (!(sb->s_flags & MS_RDONLY))
61861 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61862 up_write(&sb->s_umount);
61863 +
61864 + gr_log_remount(mnt->mnt_devname, retval);
61865 +
61866 return retval;
61867 }
61868
61869 @@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
61870 }
61871 unlock_mount_hash();
61872 namespace_unlock();
61873 +
61874 + gr_log_unmount(mnt->mnt_devname, retval);
61875 +
61876 return retval;
61877 }
61878
61879 @@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
61880 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61881 */
61882
61883 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61884 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61885 {
61886 struct path path;
61887 struct mount *mnt;
61888 @@ -1422,7 +1428,7 @@ out:
61889 /*
61890 * The 2.0 compatible umount. No flags.
61891 */
61892 -SYSCALL_DEFINE1(oldumount, char __user *, name)
61893 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
61894 {
61895 return sys_umount(name, 0);
61896 }
61897 @@ -2426,6 +2432,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61898 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61899 MS_STRICTATIME);
61900
61901 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61902 + retval = -EPERM;
61903 + goto dput_out;
61904 + }
61905 +
61906 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61907 + retval = -EPERM;
61908 + goto dput_out;
61909 + }
61910 +
61911 if (flags & MS_REMOUNT)
61912 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61913 data_page);
61914 @@ -2440,6 +2456,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61915 dev_name, data_page);
61916 dput_out:
61917 path_put(&path);
61918 +
61919 + gr_log_mount(dev_name, dir_name, retval);
61920 +
61921 return retval;
61922 }
61923
61924 @@ -2457,7 +2476,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61925 * number incrementing at 10Ghz will take 12,427 years to wrap which
61926 * is effectively never, so we can ignore the possibility.
61927 */
61928 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61929 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61930
61931 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61932 {
61933 @@ -2472,7 +2491,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61934 kfree(new_ns);
61935 return ERR_PTR(ret);
61936 }
61937 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61938 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61939 atomic_set(&new_ns->count, 1);
61940 new_ns->root = NULL;
61941 INIT_LIST_HEAD(&new_ns->list);
61942 @@ -2482,7 +2501,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61943 return new_ns;
61944 }
61945
61946 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61947 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61948 struct user_namespace *user_ns, struct fs_struct *new_fs)
61949 {
61950 struct mnt_namespace *new_ns;
61951 @@ -2603,8 +2622,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61952 }
61953 EXPORT_SYMBOL(mount_subtree);
61954
61955 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61956 - char __user *, type, unsigned long, flags, void __user *, data)
61957 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61958 + const char __user *, type, unsigned long, flags, void __user *, data)
61959 {
61960 int ret;
61961 char *kernel_type;
61962 @@ -2717,6 +2736,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61963 if (error)
61964 goto out2;
61965
61966 + if (gr_handle_chroot_pivot()) {
61967 + error = -EPERM;
61968 + goto out2;
61969 + }
61970 +
61971 get_fs_root(current->fs, &root);
61972 old_mp = lock_mount(&old);
61973 error = PTR_ERR(old_mp);
61974 @@ -2983,7 +3007,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61975 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61976 return -EPERM;
61977
61978 - if (fs->users != 1)
61979 + if (atomic_read(&fs->users) != 1)
61980 return -EINVAL;
61981
61982 get_mnt_ns(mnt_ns);
61983 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61984 index f4ccfe6..a5cf064 100644
61985 --- a/fs/nfs/callback_xdr.c
61986 +++ b/fs/nfs/callback_xdr.c
61987 @@ -51,7 +51,7 @@ struct callback_op {
61988 callback_decode_arg_t decode_args;
61989 callback_encode_res_t encode_res;
61990 long res_maxsize;
61991 -};
61992 +} __do_const;
61993
61994 static struct callback_op callback_ops[];
61995
61996 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61997 index 5d94c02..630214f 100644
61998 --- a/fs/nfs/inode.c
61999 +++ b/fs/nfs/inode.c
62000 @@ -1153,16 +1153,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62001 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62002 }
62003
62004 -static atomic_long_t nfs_attr_generation_counter;
62005 +static atomic_long_unchecked_t nfs_attr_generation_counter;
62006
62007 static unsigned long nfs_read_attr_generation_counter(void)
62008 {
62009 - return atomic_long_read(&nfs_attr_generation_counter);
62010 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62011 }
62012
62013 unsigned long nfs_inc_attr_generation_counter(void)
62014 {
62015 - return atomic_long_inc_return(&nfs_attr_generation_counter);
62016 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62017 }
62018
62019 void nfs_fattr_init(struct nfs_fattr *fattr)
62020 diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
62021 index 0e90bf0..134691e 100644
62022 --- a/fs/nfs/nfs4proc.c
62023 +++ b/fs/nfs/nfs4proc.c
62024 @@ -1070,6 +1070,7 @@ static void nfs4_opendata_free(struct kref *kref)
62025 dput(p->dentry);
62026 nfs_sb_deactive(sb);
62027 nfs_fattr_free_names(&p->f_attr);
62028 + kfree(p->f_attr.mdsthreshold);
62029 kfree(p);
62030 }
62031
62032 @@ -2246,10 +2247,12 @@ static int _nfs4_do_open(struct inode *dir,
62033 }
62034 }
62035
62036 - if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
62037 - opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
62038 - if (!opendata->f_attr.mdsthreshold)
62039 - goto err_free_label;
62040 + if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
62041 + if (!opendata->f_attr.mdsthreshold) {
62042 + opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
62043 + if (!opendata->f_attr.mdsthreshold)
62044 + goto err_free_label;
62045 + }
62046 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
62047 }
62048 if (dentry->d_inode != NULL)
62049 @@ -2277,11 +2280,10 @@ static int _nfs4_do_open(struct inode *dir,
62050 if (opendata->file_created)
62051 *opened |= FILE_CREATED;
62052
62053 - if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
62054 + if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) {
62055 *ctx_th = opendata->f_attr.mdsthreshold;
62056 - else
62057 - kfree(opendata->f_attr.mdsthreshold);
62058 - opendata->f_attr.mdsthreshold = NULL;
62059 + opendata->f_attr.mdsthreshold = NULL;
62060 + }
62061
62062 nfs4_label_free(olabel);
62063
62064 @@ -2291,7 +2293,6 @@ static int _nfs4_do_open(struct inode *dir,
62065 err_free_label:
62066 nfs4_label_free(olabel);
62067 err_opendata_put:
62068 - kfree(opendata->f_attr.mdsthreshold);
62069 nfs4_opendata_put(opendata);
62070 err_put_state_owner:
62071 nfs4_put_state_owner(sp);
62072 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62073 index 419572f..5414a23 100644
62074 --- a/fs/nfsd/nfs4proc.c
62075 +++ b/fs/nfsd/nfs4proc.c
62076 @@ -1168,7 +1168,7 @@ struct nfsd4_operation {
62077 nfsd4op_rsize op_rsize_bop;
62078 stateid_getter op_get_currentstateid;
62079 stateid_setter op_set_currentstateid;
62080 -};
62081 +} __do_const;
62082
62083 static struct nfsd4_operation nfsd4_ops[];
62084
62085 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62086 index ee7237f..e3ae60a 100644
62087 --- a/fs/nfsd/nfs4xdr.c
62088 +++ b/fs/nfsd/nfs4xdr.c
62089 @@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62090
62091 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62092
62093 -static nfsd4_dec nfsd4_dec_ops[] = {
62094 +static const nfsd4_dec nfsd4_dec_ops[] = {
62095 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62096 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62097 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62098 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62099 index b6af150..f6ec5e3 100644
62100 --- a/fs/nfsd/nfscache.c
62101 +++ b/fs/nfsd/nfscache.c
62102 @@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62103 {
62104 struct svc_cacherep *rp = rqstp->rq_cacherep;
62105 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62106 - int len;
62107 + long len;
62108 size_t bufsize = 0;
62109
62110 if (!rp)
62111 return;
62112
62113 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62114 - len >>= 2;
62115 + if (statp) {
62116 + len = (char*)statp - (char*)resv->iov_base;
62117 + len = resv->iov_len - len;
62118 + len >>= 2;
62119 + }
62120
62121 /* Don't cache excessive amounts of data and XDR failures */
62122 if (!statp || len > (256 >> 2)) {
62123 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62124 index 7eea63c..a35f4fb 100644
62125 --- a/fs/nfsd/vfs.c
62126 +++ b/fs/nfsd/vfs.c
62127 @@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62128 } else {
62129 oldfs = get_fs();
62130 set_fs(KERNEL_DS);
62131 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62132 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62133 set_fs(oldfs);
62134 }
62135
62136 @@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62137
62138 /* Write the data. */
62139 oldfs = get_fs(); set_fs(KERNEL_DS);
62140 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62141 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62142 set_fs(oldfs);
62143 if (host_err < 0)
62144 goto out_nfserr;
62145 @@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62146 */
62147
62148 oldfs = get_fs(); set_fs(KERNEL_DS);
62149 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62150 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62151 set_fs(oldfs);
62152
62153 if (host_err < 0)
62154 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62155 index fea6bd5..8ee9d81 100644
62156 --- a/fs/nls/nls_base.c
62157 +++ b/fs/nls/nls_base.c
62158 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62159
62160 int register_nls(struct nls_table * nls)
62161 {
62162 - struct nls_table ** tmp = &tables;
62163 + struct nls_table *tmp = tables;
62164
62165 if (nls->next)
62166 return -EBUSY;
62167
62168 spin_lock(&nls_lock);
62169 - while (*tmp) {
62170 - if (nls == *tmp) {
62171 + while (tmp) {
62172 + if (nls == tmp) {
62173 spin_unlock(&nls_lock);
62174 return -EBUSY;
62175 }
62176 - tmp = &(*tmp)->next;
62177 + tmp = tmp->next;
62178 }
62179 - nls->next = tables;
62180 + pax_open_kernel();
62181 + *(struct nls_table **)&nls->next = tables;
62182 + pax_close_kernel();
62183 tables = nls;
62184 spin_unlock(&nls_lock);
62185 return 0;
62186 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
62187
62188 int unregister_nls(struct nls_table * nls)
62189 {
62190 - struct nls_table ** tmp = &tables;
62191 + struct nls_table * const * tmp = &tables;
62192
62193 spin_lock(&nls_lock);
62194 while (*tmp) {
62195 if (nls == *tmp) {
62196 - *tmp = nls->next;
62197 + pax_open_kernel();
62198 + *(struct nls_table **)tmp = nls->next;
62199 + pax_close_kernel();
62200 spin_unlock(&nls_lock);
62201 return 0;
62202 }
62203 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62204 index 7424929..35f6be5 100644
62205 --- a/fs/nls/nls_euc-jp.c
62206 +++ b/fs/nls/nls_euc-jp.c
62207 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
62208 p_nls = load_nls("cp932");
62209
62210 if (p_nls) {
62211 - table.charset2upper = p_nls->charset2upper;
62212 - table.charset2lower = p_nls->charset2lower;
62213 + pax_open_kernel();
62214 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62215 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62216 + pax_close_kernel();
62217 return register_nls(&table);
62218 }
62219
62220 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62221 index e7bc1d7..06bd4bb 100644
62222 --- a/fs/nls/nls_koi8-ru.c
62223 +++ b/fs/nls/nls_koi8-ru.c
62224 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
62225 p_nls = load_nls("koi8-u");
62226
62227 if (p_nls) {
62228 - table.charset2upper = p_nls->charset2upper;
62229 - table.charset2lower = p_nls->charset2lower;
62230 + pax_open_kernel();
62231 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62232 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62233 + pax_close_kernel();
62234 return register_nls(&table);
62235 }
62236
62237 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62238 index 6663511..7668ca4 100644
62239 --- a/fs/notify/fanotify/fanotify_user.c
62240 +++ b/fs/notify/fanotify/fanotify_user.c
62241 @@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62242
62243 fd = fanotify_event_metadata.fd;
62244 ret = -EFAULT;
62245 - if (copy_to_user(buf, &fanotify_event_metadata,
62246 - fanotify_event_metadata.event_len))
62247 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62248 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62249 goto out_close_fd;
62250
62251 ret = prepare_for_access_response(group, event, fd);
62252 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62253 index 7b51b05..5ea5ef6 100644
62254 --- a/fs/notify/notification.c
62255 +++ b/fs/notify/notification.c
62256 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
62257 * get set to 0 so it will never get 'freed'
62258 */
62259 static struct fsnotify_event *q_overflow_event;
62260 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62261 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62262
62263 /**
62264 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62265 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62266 */
62267 u32 fsnotify_get_cookie(void)
62268 {
62269 - return atomic_inc_return(&fsnotify_sync_cookie);
62270 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62271 }
62272 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62273
62274 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62275 index 9e38daf..5727cae 100644
62276 --- a/fs/ntfs/dir.c
62277 +++ b/fs/ntfs/dir.c
62278 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62279 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62280 ~(s64)(ndir->itype.index.block_size - 1)));
62281 /* Bounds checks. */
62282 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62283 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62284 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62285 "inode 0x%lx or driver bug.", vdir->i_ino);
62286 goto err_out;
62287 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62288 index ea4ba9d..1e13d34 100644
62289 --- a/fs/ntfs/file.c
62290 +++ b/fs/ntfs/file.c
62291 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62292 char *addr;
62293 size_t total = 0;
62294 unsigned len;
62295 - int left;
62296 + unsigned left;
62297
62298 do {
62299 len = PAGE_CACHE_SIZE - ofs;
62300 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62301 index 82650d5..db37dcf 100644
62302 --- a/fs/ntfs/super.c
62303 +++ b/fs/ntfs/super.c
62304 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62305 if (!silent)
62306 ntfs_error(sb, "Primary boot sector is invalid.");
62307 } else if (!silent)
62308 - ntfs_error(sb, read_err_str, "primary");
62309 + ntfs_error(sb, read_err_str, "%s", "primary");
62310 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62311 if (bh_primary)
62312 brelse(bh_primary);
62313 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62314 goto hotfix_primary_boot_sector;
62315 brelse(bh_backup);
62316 } else if (!silent)
62317 - ntfs_error(sb, read_err_str, "backup");
62318 + ntfs_error(sb, read_err_str, "%s", "backup");
62319 /* Try to read NT3.51- backup boot sector. */
62320 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62321 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62322 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62323 "sector.");
62324 brelse(bh_backup);
62325 } else if (!silent)
62326 - ntfs_error(sb, read_err_str, "backup");
62327 + ntfs_error(sb, read_err_str, "%s", "backup");
62328 /* We failed. Cleanup and return. */
62329 if (bh_primary)
62330 brelse(bh_primary);
62331 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62332 index cd5496b..26a1055 100644
62333 --- a/fs/ocfs2/localalloc.c
62334 +++ b/fs/ocfs2/localalloc.c
62335 @@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62336 goto bail;
62337 }
62338
62339 - atomic_inc(&osb->alloc_stats.moves);
62340 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62341
62342 bail:
62343 if (handle)
62344 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62345 index 3a90347..c40bef8 100644
62346 --- a/fs/ocfs2/ocfs2.h
62347 +++ b/fs/ocfs2/ocfs2.h
62348 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
62349
62350 struct ocfs2_alloc_stats
62351 {
62352 - atomic_t moves;
62353 - atomic_t local_data;
62354 - atomic_t bitmap_data;
62355 - atomic_t bg_allocs;
62356 - atomic_t bg_extends;
62357 + atomic_unchecked_t moves;
62358 + atomic_unchecked_t local_data;
62359 + atomic_unchecked_t bitmap_data;
62360 + atomic_unchecked_t bg_allocs;
62361 + atomic_unchecked_t bg_extends;
62362 };
62363
62364 enum ocfs2_local_alloc_state
62365 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62366 index 2c91452..77a3cd2 100644
62367 --- a/fs/ocfs2/suballoc.c
62368 +++ b/fs/ocfs2/suballoc.c
62369 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62370 mlog_errno(status);
62371 goto bail;
62372 }
62373 - atomic_inc(&osb->alloc_stats.bg_extends);
62374 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62375
62376 /* You should never ask for this much metadata */
62377 BUG_ON(bits_wanted >
62378 @@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62379 mlog_errno(status);
62380 goto bail;
62381 }
62382 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62383 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62384
62385 *suballoc_loc = res.sr_bg_blkno;
62386 *suballoc_bit_start = res.sr_bit_offset;
62387 @@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62388 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62389 res->sr_bits);
62390
62391 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62392 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62393
62394 BUG_ON(res->sr_bits != 1);
62395
62396 @@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62397 mlog_errno(status);
62398 goto bail;
62399 }
62400 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62401 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62402
62403 BUG_ON(res.sr_bits != 1);
62404
62405 @@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62406 cluster_start,
62407 num_clusters);
62408 if (!status)
62409 - atomic_inc(&osb->alloc_stats.local_data);
62410 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62411 } else {
62412 if (min_clusters > (osb->bitmap_cpg - 1)) {
62413 /* The only paths asking for contiguousness
62414 @@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62415 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62416 res.sr_bg_blkno,
62417 res.sr_bit_offset);
62418 - atomic_inc(&osb->alloc_stats.bitmap_data);
62419 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62420 *num_clusters = res.sr_bits;
62421 }
62422 }
62423 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62424 index c414929..5c9ee542 100644
62425 --- a/fs/ocfs2/super.c
62426 +++ b/fs/ocfs2/super.c
62427 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62428 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62429 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62430 "Stats",
62431 - atomic_read(&osb->alloc_stats.bitmap_data),
62432 - atomic_read(&osb->alloc_stats.local_data),
62433 - atomic_read(&osb->alloc_stats.bg_allocs),
62434 - atomic_read(&osb->alloc_stats.moves),
62435 - atomic_read(&osb->alloc_stats.bg_extends));
62436 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62437 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62438 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62439 + atomic_read_unchecked(&osb->alloc_stats.moves),
62440 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62441
62442 out += snprintf(buf + out, len - out,
62443 "%10s => State: %u Descriptor: %llu Size: %u bits "
62444 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62445 spin_lock_init(&osb->osb_xattr_lock);
62446 ocfs2_init_steal_slots(osb);
62447
62448 - atomic_set(&osb->alloc_stats.moves, 0);
62449 - atomic_set(&osb->alloc_stats.local_data, 0);
62450 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62451 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62452 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62453 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62454 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62455 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62456 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62457 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62458
62459 /* Copy the blockcheck stats from the superblock probe */
62460 osb->osb_ecc_stats = *stats;
62461 diff --git a/fs/open.c b/fs/open.c
62462 index 4b3e1ed..1c84599 100644
62463 --- a/fs/open.c
62464 +++ b/fs/open.c
62465 @@ -32,6 +32,8 @@
62466 #include <linux/dnotify.h>
62467 #include <linux/compat.h>
62468
62469 +#define CREATE_TRACE_POINTS
62470 +#include <trace/events/fs.h>
62471 #include "internal.h"
62472
62473 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62474 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62475 error = locks_verify_truncate(inode, NULL, length);
62476 if (!error)
62477 error = security_path_truncate(path);
62478 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62479 + error = -EACCES;
62480 if (!error)
62481 error = do_truncate(path->dentry, length, 0, NULL);
62482
62483 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62484 error = locks_verify_truncate(inode, f.file, length);
62485 if (!error)
62486 error = security_path_truncate(&f.file->f_path);
62487 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62488 + error = -EACCES;
62489 if (!error)
62490 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62491 sb_end_write(inode->i_sb);
62492 @@ -361,6 +367,9 @@ retry:
62493 if (__mnt_is_readonly(path.mnt))
62494 res = -EROFS;
62495
62496 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62497 + res = -EACCES;
62498 +
62499 out_path_release:
62500 path_put(&path);
62501 if (retry_estale(res, lookup_flags)) {
62502 @@ -392,6 +401,8 @@ retry:
62503 if (error)
62504 goto dput_and_out;
62505
62506 + gr_log_chdir(path.dentry, path.mnt);
62507 +
62508 set_fs_pwd(current->fs, &path);
62509
62510 dput_and_out:
62511 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62512 goto out_putf;
62513
62514 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62515 +
62516 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62517 + error = -EPERM;
62518 +
62519 + if (!error)
62520 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62521 +
62522 if (!error)
62523 set_fs_pwd(current->fs, &f.file->f_path);
62524 out_putf:
62525 @@ -450,7 +468,13 @@ retry:
62526 if (error)
62527 goto dput_and_out;
62528
62529 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62530 + goto dput_and_out;
62531 +
62532 set_fs_root(current->fs, &path);
62533 +
62534 + gr_handle_chroot_chdir(&path);
62535 +
62536 error = 0;
62537 dput_and_out:
62538 path_put(&path);
62539 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62540 return error;
62541 retry_deleg:
62542 mutex_lock(&inode->i_mutex);
62543 +
62544 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62545 + error = -EACCES;
62546 + goto out_unlock;
62547 + }
62548 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62549 + error = -EACCES;
62550 + goto out_unlock;
62551 + }
62552 +
62553 error = security_path_chmod(path, mode);
62554 if (error)
62555 goto out_unlock;
62556 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62557 uid = make_kuid(current_user_ns(), user);
62558 gid = make_kgid(current_user_ns(), group);
62559
62560 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
62561 + return -EACCES;
62562 +
62563 newattrs.ia_valid = ATTR_CTIME;
62564 if (user != (uid_t) -1) {
62565 if (!uid_valid(uid))
62566 @@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62567 } else {
62568 fsnotify_open(f);
62569 fd_install(fd, f);
62570 + trace_do_sys_open(tmp->name, flags, mode);
62571 }
62572 }
62573 putname(tmp);
62574 diff --git a/fs/pipe.c b/fs/pipe.c
62575 index 0e0752e..7cfdd50 100644
62576 --- a/fs/pipe.c
62577 +++ b/fs/pipe.c
62578 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62579
62580 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62581 {
62582 - if (pipe->files)
62583 + if (atomic_read(&pipe->files))
62584 mutex_lock_nested(&pipe->mutex, subclass);
62585 }
62586
62587 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62588
62589 void pipe_unlock(struct pipe_inode_info *pipe)
62590 {
62591 - if (pipe->files)
62592 + if (atomic_read(&pipe->files))
62593 mutex_unlock(&pipe->mutex);
62594 }
62595 EXPORT_SYMBOL(pipe_unlock);
62596 @@ -449,9 +449,9 @@ redo:
62597 }
62598 if (bufs) /* More to do? */
62599 continue;
62600 - if (!pipe->writers)
62601 + if (!atomic_read(&pipe->writers))
62602 break;
62603 - if (!pipe->waiting_writers) {
62604 + if (!atomic_read(&pipe->waiting_writers)) {
62605 /* syscall merging: Usually we must not sleep
62606 * if O_NONBLOCK is set, or if we got some data.
62607 * But if a writer sleeps in kernel space, then
62608 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62609 ret = 0;
62610 __pipe_lock(pipe);
62611
62612 - if (!pipe->readers) {
62613 + if (!atomic_read(&pipe->readers)) {
62614 send_sig(SIGPIPE, current, 0);
62615 ret = -EPIPE;
62616 goto out;
62617 @@ -562,7 +562,7 @@ redo1:
62618 for (;;) {
62619 int bufs;
62620
62621 - if (!pipe->readers) {
62622 + if (!atomic_read(&pipe->readers)) {
62623 send_sig(SIGPIPE, current, 0);
62624 if (!ret)
62625 ret = -EPIPE;
62626 @@ -653,9 +653,9 @@ redo2:
62627 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62628 do_wakeup = 0;
62629 }
62630 - pipe->waiting_writers++;
62631 + atomic_inc(&pipe->waiting_writers);
62632 pipe_wait(pipe);
62633 - pipe->waiting_writers--;
62634 + atomic_dec(&pipe->waiting_writers);
62635 }
62636 out:
62637 __pipe_unlock(pipe);
62638 @@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62639 mask = 0;
62640 if (filp->f_mode & FMODE_READ) {
62641 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62642 - if (!pipe->writers && filp->f_version != pipe->w_counter)
62643 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62644 mask |= POLLHUP;
62645 }
62646
62647 @@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62648 * Most Unices do not set POLLERR for FIFOs but on Linux they
62649 * behave exactly like pipes for poll().
62650 */
62651 - if (!pipe->readers)
62652 + if (!atomic_read(&pipe->readers))
62653 mask |= POLLERR;
62654 }
62655
62656 @@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62657 int kill = 0;
62658
62659 spin_lock(&inode->i_lock);
62660 - if (!--pipe->files) {
62661 + if (atomic_dec_and_test(&pipe->files)) {
62662 inode->i_pipe = NULL;
62663 kill = 1;
62664 }
62665 @@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
62666
62667 __pipe_lock(pipe);
62668 if (file->f_mode & FMODE_READ)
62669 - pipe->readers--;
62670 + atomic_dec(&pipe->readers);
62671 if (file->f_mode & FMODE_WRITE)
62672 - pipe->writers--;
62673 + atomic_dec(&pipe->writers);
62674
62675 - if (pipe->readers || pipe->writers) {
62676 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62677 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62678 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62679 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62680 @@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62681 kfree(pipe);
62682 }
62683
62684 -static struct vfsmount *pipe_mnt __read_mostly;
62685 +struct vfsmount *pipe_mnt __read_mostly;
62686
62687 /*
62688 * pipefs_dname() is called from d_path().
62689 @@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
62690 goto fail_iput;
62691
62692 inode->i_pipe = pipe;
62693 - pipe->files = 2;
62694 - pipe->readers = pipe->writers = 1;
62695 + atomic_set(&pipe->files, 2);
62696 + atomic_set(&pipe->readers, 1);
62697 + atomic_set(&pipe->writers, 1);
62698 inode->i_fop = &pipefifo_fops;
62699
62700 /*
62701 @@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62702 spin_lock(&inode->i_lock);
62703 if (inode->i_pipe) {
62704 pipe = inode->i_pipe;
62705 - pipe->files++;
62706 + atomic_inc(&pipe->files);
62707 spin_unlock(&inode->i_lock);
62708 } else {
62709 spin_unlock(&inode->i_lock);
62710 pipe = alloc_pipe_info();
62711 if (!pipe)
62712 return -ENOMEM;
62713 - pipe->files = 1;
62714 + atomic_set(&pipe->files, 1);
62715 spin_lock(&inode->i_lock);
62716 if (unlikely(inode->i_pipe)) {
62717 - inode->i_pipe->files++;
62718 + atomic_inc(&inode->i_pipe->files);
62719 spin_unlock(&inode->i_lock);
62720 free_pipe_info(pipe);
62721 pipe = inode->i_pipe;
62722 @@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62723 * opened, even when there is no process writing the FIFO.
62724 */
62725 pipe->r_counter++;
62726 - if (pipe->readers++ == 0)
62727 + if (atomic_inc_return(&pipe->readers) == 1)
62728 wake_up_partner(pipe);
62729
62730 - if (!is_pipe && !pipe->writers) {
62731 + if (!is_pipe && !atomic_read(&pipe->writers)) {
62732 if ((filp->f_flags & O_NONBLOCK)) {
62733 /* suppress POLLHUP until we have
62734 * seen a writer */
62735 @@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62736 * errno=ENXIO when there is no process reading the FIFO.
62737 */
62738 ret = -ENXIO;
62739 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62740 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62741 goto err;
62742
62743 pipe->w_counter++;
62744 - if (!pipe->writers++)
62745 + if (atomic_inc_return(&pipe->writers) == 1)
62746 wake_up_partner(pipe);
62747
62748 - if (!is_pipe && !pipe->readers) {
62749 + if (!is_pipe && !atomic_read(&pipe->readers)) {
62750 if (wait_for_partner(pipe, &pipe->r_counter))
62751 goto err_wr;
62752 }
62753 @@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62754 * the process can at least talk to itself.
62755 */
62756
62757 - pipe->readers++;
62758 - pipe->writers++;
62759 + atomic_inc(&pipe->readers);
62760 + atomic_inc(&pipe->writers);
62761 pipe->r_counter++;
62762 pipe->w_counter++;
62763 - if (pipe->readers == 1 || pipe->writers == 1)
62764 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62765 wake_up_partner(pipe);
62766 break;
62767
62768 @@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62769 return 0;
62770
62771 err_rd:
62772 - if (!--pipe->readers)
62773 + if (atomic_dec_and_test(&pipe->readers))
62774 wake_up_interruptible(&pipe->wait);
62775 ret = -ERESTARTSYS;
62776 goto err;
62777
62778 err_wr:
62779 - if (!--pipe->writers)
62780 + if (atomic_dec_and_test(&pipe->writers))
62781 wake_up_interruptible(&pipe->wait);
62782 ret = -ERESTARTSYS;
62783 goto err;
62784 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62785 index 8bd2135..eab9adb 100644
62786 --- a/fs/posix_acl.c
62787 +++ b/fs/posix_acl.c
62788 @@ -19,6 +19,7 @@
62789 #include <linux/sched.h>
62790 #include <linux/posix_acl.h>
62791 #include <linux/export.h>
62792 +#include <linux/grsecurity.h>
62793
62794 #include <linux/errno.h>
62795
62796 @@ -183,7 +184,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62797 }
62798 }
62799 if (mode_p)
62800 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62801 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62802 return not_equiv;
62803 }
62804
62805 @@ -331,7 +332,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62806 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62807 }
62808
62809 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62810 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62811 return not_equiv;
62812 }
62813
62814 @@ -389,6 +390,8 @@ posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62815 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62816 int err = -ENOMEM;
62817 if (clone) {
62818 + *mode_p &= ~gr_acl_umask();
62819 +
62820 err = posix_acl_create_masq(clone, mode_p);
62821 if (err < 0) {
62822 posix_acl_release(clone);
62823 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62824 index 2183fcf..3c32a98 100644
62825 --- a/fs/proc/Kconfig
62826 +++ b/fs/proc/Kconfig
62827 @@ -30,7 +30,7 @@ config PROC_FS
62828
62829 config PROC_KCORE
62830 bool "/proc/kcore support" if !ARM
62831 - depends on PROC_FS && MMU
62832 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62833 help
62834 Provides a virtual ELF core file of the live kernel. This can
62835 be read with gdb and other ELF tools. No modifications can be
62836 @@ -38,8 +38,8 @@ config PROC_KCORE
62837
62838 config PROC_VMCORE
62839 bool "/proc/vmcore support"
62840 - depends on PROC_FS && CRASH_DUMP
62841 - default y
62842 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62843 + default n
62844 help
62845 Exports the dump image of crashed kernel in ELF format.
62846
62847 @@ -63,8 +63,8 @@ config PROC_SYSCTL
62848 limited in memory.
62849
62850 config PROC_PAGE_MONITOR
62851 - default y
62852 - depends on PROC_FS && MMU
62853 + default n
62854 + depends on PROC_FS && MMU && !GRKERNSEC
62855 bool "Enable /proc page monitoring" if EXPERT
62856 help
62857 Various /proc files exist to monitor process memory utilization:
62858 diff --git a/fs/proc/array.c b/fs/proc/array.c
62859 index 1bd2077..2f7cfd5 100644
62860 --- a/fs/proc/array.c
62861 +++ b/fs/proc/array.c
62862 @@ -60,6 +60,7 @@
62863 #include <linux/tty.h>
62864 #include <linux/string.h>
62865 #include <linux/mman.h>
62866 +#include <linux/grsecurity.h>
62867 #include <linux/proc_fs.h>
62868 #include <linux/ioport.h>
62869 #include <linux/uaccess.h>
62870 @@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62871 seq_putc(m, '\n');
62872 }
62873
62874 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62875 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
62876 +{
62877 + if (p->mm)
62878 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62879 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62880 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62881 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62882 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62883 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62884 + else
62885 + seq_printf(m, "PaX:\t-----\n");
62886 +}
62887 +#endif
62888 +
62889 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62890 struct pid *pid, struct task_struct *task)
62891 {
62892 @@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62893 task_cpus_allowed(m, task);
62894 cpuset_task_status_allowed(m, task);
62895 task_context_switch_counts(m, task);
62896 +
62897 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62898 + task_pax(m, task);
62899 +#endif
62900 +
62901 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62902 + task_grsec_rbac(m, task);
62903 +#endif
62904 +
62905 return 0;
62906 }
62907
62908 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62909 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62910 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62911 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62912 +#endif
62913 +
62914 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62915 struct pid *pid, struct task_struct *task, int whole)
62916 {
62917 @@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62918 char tcomm[sizeof(task->comm)];
62919 unsigned long flags;
62920
62921 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62922 + if (current->exec_id != m->exec_id) {
62923 + gr_log_badprocpid("stat");
62924 + return 0;
62925 + }
62926 +#endif
62927 +
62928 state = *get_task_state(task);
62929 vsize = eip = esp = 0;
62930 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62931 @@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62932 gtime = task_gtime(task);
62933 }
62934
62935 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62936 + if (PAX_RAND_FLAGS(mm)) {
62937 + eip = 0;
62938 + esp = 0;
62939 + wchan = 0;
62940 + }
62941 +#endif
62942 +#ifdef CONFIG_GRKERNSEC_HIDESYM
62943 + wchan = 0;
62944 + eip =0;
62945 + esp =0;
62946 +#endif
62947 +
62948 /* scale priority and nice values from timeslices to -20..20 */
62949 /* to make it look like a "normal" Unix priority/nice value */
62950 priority = task_prio(task);
62951 @@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62952 seq_put_decimal_ull(m, ' ', vsize);
62953 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
62954 seq_put_decimal_ull(m, ' ', rsslim);
62955 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62956 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
62957 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
62958 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
62959 +#else
62960 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
62961 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
62962 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
62963 +#endif
62964 seq_put_decimal_ull(m, ' ', esp);
62965 seq_put_decimal_ull(m, ' ', eip);
62966 /* The signal information here is obsolete.
62967 @@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62968 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
62969 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
62970
62971 - if (mm && permitted) {
62972 + if (mm && permitted
62973 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62974 + && !PAX_RAND_FLAGS(mm)
62975 +#endif
62976 + ) {
62977 seq_put_decimal_ull(m, ' ', mm->start_data);
62978 seq_put_decimal_ull(m, ' ', mm->end_data);
62979 seq_put_decimal_ull(m, ' ', mm->start_brk);
62980 @@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62981 struct pid *pid, struct task_struct *task)
62982 {
62983 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
62984 - struct mm_struct *mm = get_task_mm(task);
62985 + struct mm_struct *mm;
62986
62987 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62988 + if (current->exec_id != m->exec_id) {
62989 + gr_log_badprocpid("statm");
62990 + return 0;
62991 + }
62992 +#endif
62993 + mm = get_task_mm(task);
62994 if (mm) {
62995 size = task_statm(mm, &shared, &text, &data, &resident);
62996 mmput(mm);
62997 @@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62998 return 0;
62999 }
63000
63001 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63002 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63003 +{
63004 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63005 +}
63006 +#endif
63007 +
63008 #ifdef CONFIG_CHECKPOINT_RESTORE
63009 static struct pid *
63010 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63011 diff --git a/fs/proc/base.c b/fs/proc/base.c
63012 index b59a34b..68a79e8 100644
63013 --- a/fs/proc/base.c
63014 +++ b/fs/proc/base.c
63015 @@ -113,6 +113,14 @@ struct pid_entry {
63016 union proc_op op;
63017 };
63018
63019 +struct getdents_callback {
63020 + struct linux_dirent __user * current_dir;
63021 + struct linux_dirent __user * previous;
63022 + struct file * file;
63023 + int count;
63024 + int error;
63025 +};
63026 +
63027 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63028 .name = (NAME), \
63029 .len = sizeof(NAME) - 1, \
63030 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63031 if (!mm->arg_end)
63032 goto out_mm; /* Shh! No looking before we're done */
63033
63034 + if (gr_acl_handle_procpidmem(task))
63035 + goto out_mm;
63036 +
63037 len = mm->arg_end - mm->arg_start;
63038
63039 if (len > PAGE_SIZE)
63040 @@ -237,12 +248,28 @@ out:
63041 return res;
63042 }
63043
63044 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63045 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63046 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63047 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63048 +#endif
63049 +
63050 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63051 {
63052 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63053 int res = PTR_ERR(mm);
63054 if (mm && !IS_ERR(mm)) {
63055 unsigned int nwords = 0;
63056 +
63057 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63058 + /* allow if we're currently ptracing this task */
63059 + if (PAX_RAND_FLAGS(mm) &&
63060 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63061 + mmput(mm);
63062 + return 0;
63063 + }
63064 +#endif
63065 +
63066 do {
63067 nwords += 2;
63068 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63069 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63070 }
63071
63072
63073 -#ifdef CONFIG_KALLSYMS
63074 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63075 /*
63076 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63077 * Returns the resolved symbol. If that fails, simply return the address.
63078 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63079 mutex_unlock(&task->signal->cred_guard_mutex);
63080 }
63081
63082 -#ifdef CONFIG_STACKTRACE
63083 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63084
63085 #define MAX_STACK_TRACE_DEPTH 64
63086
63087 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63088 return count;
63089 }
63090
63091 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63092 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63093 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63094 {
63095 long nr;
63096 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63097 /************************************************************************/
63098
63099 /* permission checks */
63100 -static int proc_fd_access_allowed(struct inode *inode)
63101 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63102 {
63103 struct task_struct *task;
63104 int allowed = 0;
63105 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63106 */
63107 task = get_proc_task(inode);
63108 if (task) {
63109 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63110 + if (log)
63111 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63112 + else
63113 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63114 put_task_struct(task);
63115 }
63116 return allowed;
63117 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63118 struct task_struct *task,
63119 int hide_pid_min)
63120 {
63121 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63122 + return false;
63123 +
63124 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63125 + rcu_read_lock();
63126 + {
63127 + const struct cred *tmpcred = current_cred();
63128 + const struct cred *cred = __task_cred(task);
63129 +
63130 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63131 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63132 + || in_group_p(grsec_proc_gid)
63133 +#endif
63134 + ) {
63135 + rcu_read_unlock();
63136 + return true;
63137 + }
63138 + }
63139 + rcu_read_unlock();
63140 +
63141 + if (!pid->hide_pid)
63142 + return false;
63143 +#endif
63144 +
63145 if (pid->hide_pid < hide_pid_min)
63146 return true;
63147 if (in_group_p(pid->pid_gid))
63148 return true;
63149 +
63150 return ptrace_may_access(task, PTRACE_MODE_READ);
63151 }
63152
63153 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63154 put_task_struct(task);
63155
63156 if (!has_perms) {
63157 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63158 + {
63159 +#else
63160 if (pid->hide_pid == 2) {
63161 +#endif
63162 /*
63163 * Let's make getdents(), stat(), and open()
63164 * consistent with each other. If a process
63165 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63166 if (!task)
63167 return -ESRCH;
63168
63169 + if (gr_acl_handle_procpidmem(task)) {
63170 + put_task_struct(task);
63171 + return -EPERM;
63172 + }
63173 +
63174 mm = mm_access(task, mode);
63175 put_task_struct(task);
63176
63177 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63178
63179 file->private_data = mm;
63180
63181 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63182 + file->f_version = current->exec_id;
63183 +#endif
63184 +
63185 return 0;
63186 }
63187
63188 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63189 ssize_t copied;
63190 char *page;
63191
63192 +#ifdef CONFIG_GRKERNSEC
63193 + if (write)
63194 + return -EPERM;
63195 +#endif
63196 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63197 + if (file->f_version != current->exec_id) {
63198 + gr_log_badprocpid("mem");
63199 + return 0;
63200 + }
63201 +#endif
63202 +
63203 if (!mm)
63204 return 0;
63205
63206 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63207 goto free;
63208
63209 while (count > 0) {
63210 - int this_len = min_t(int, count, PAGE_SIZE);
63211 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63212
63213 if (write && copy_from_user(page, buf, this_len)) {
63214 copied = -EFAULT;
63215 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63216 if (!mm)
63217 return 0;
63218
63219 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63220 + if (file->f_version != current->exec_id) {
63221 + gr_log_badprocpid("environ");
63222 + return 0;
63223 + }
63224 +#endif
63225 +
63226 page = (char *)__get_free_page(GFP_TEMPORARY);
63227 if (!page)
63228 return -ENOMEM;
63229 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63230 goto free;
63231 while (count > 0) {
63232 size_t this_len, max_len;
63233 - int retval;
63234 + ssize_t retval;
63235
63236 if (src >= (mm->env_end - mm->env_start))
63237 break;
63238 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63239 int error = -EACCES;
63240
63241 /* Are we allowed to snoop on the tasks file descriptors? */
63242 - if (!proc_fd_access_allowed(inode))
63243 + if (!proc_fd_access_allowed(inode, 0))
63244 goto out;
63245
63246 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63247 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63248 struct path path;
63249
63250 /* Are we allowed to snoop on the tasks file descriptors? */
63251 - if (!proc_fd_access_allowed(inode))
63252 - goto out;
63253 + /* logging this is needed for learning on chromium to work properly,
63254 + but we don't want to flood the logs from 'ps' which does a readlink
63255 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63256 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63257 + */
63258 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63259 + if (!proc_fd_access_allowed(inode,0))
63260 + goto out;
63261 + } else {
63262 + if (!proc_fd_access_allowed(inode,1))
63263 + goto out;
63264 + }
63265
63266 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63267 if (error)
63268 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63269 rcu_read_lock();
63270 cred = __task_cred(task);
63271 inode->i_uid = cred->euid;
63272 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63273 + inode->i_gid = grsec_proc_gid;
63274 +#else
63275 inode->i_gid = cred->egid;
63276 +#endif
63277 rcu_read_unlock();
63278 }
63279 security_task_to_inode(task, inode);
63280 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63281 return -ENOENT;
63282 }
63283 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63284 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63285 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63286 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63287 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63288 +#endif
63289 task_dumpable(task)) {
63290 cred = __task_cred(task);
63291 stat->uid = cred->euid;
63292 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63293 + stat->gid = grsec_proc_gid;
63294 +#else
63295 stat->gid = cred->egid;
63296 +#endif
63297 }
63298 }
63299 rcu_read_unlock();
63300 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63301
63302 if (task) {
63303 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63304 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63305 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63306 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63307 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63308 +#endif
63309 task_dumpable(task)) {
63310 rcu_read_lock();
63311 cred = __task_cred(task);
63312 inode->i_uid = cred->euid;
63313 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63314 + inode->i_gid = grsec_proc_gid;
63315 +#else
63316 inode->i_gid = cred->egid;
63317 +#endif
63318 rcu_read_unlock();
63319 } else {
63320 inode->i_uid = GLOBAL_ROOT_UID;
63321 @@ -2173,6 +2291,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63322 if (!task)
63323 goto out_no_task;
63324
63325 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63326 + goto out;
63327 +
63328 /*
63329 * Yes, it does not scale. And it should not. Don't add
63330 * new entries into /proc/<tgid>/ without very good reasons.
63331 @@ -2203,6 +2324,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63332 if (!task)
63333 return -ENOENT;
63334
63335 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63336 + goto out;
63337 +
63338 if (!dir_emit_dots(file, ctx))
63339 goto out;
63340
63341 @@ -2592,7 +2716,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63342 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63343 #endif
63344 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63345 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63346 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63347 INF("syscall", S_IRUGO, proc_pid_syscall),
63348 #endif
63349 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63350 @@ -2617,10 +2741,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63351 #ifdef CONFIG_SECURITY
63352 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63353 #endif
63354 -#ifdef CONFIG_KALLSYMS
63355 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63356 INF("wchan", S_IRUGO, proc_pid_wchan),
63357 #endif
63358 -#ifdef CONFIG_STACKTRACE
63359 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63360 ONE("stack", S_IRUGO, proc_pid_stack),
63361 #endif
63362 #ifdef CONFIG_SCHEDSTATS
63363 @@ -2654,6 +2778,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63364 #ifdef CONFIG_HARDWALL
63365 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63366 #endif
63367 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63368 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63369 +#endif
63370 #ifdef CONFIG_USER_NS
63371 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63372 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63373 @@ -2784,7 +2911,14 @@ static int proc_pid_instantiate(struct inode *dir,
63374 if (!inode)
63375 goto out;
63376
63377 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63378 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63379 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63380 + inode->i_gid = grsec_proc_gid;
63381 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63382 +#else
63383 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63384 +#endif
63385 inode->i_op = &proc_tgid_base_inode_operations;
63386 inode->i_fop = &proc_tgid_base_operations;
63387 inode->i_flags|=S_IMMUTABLE;
63388 @@ -2822,7 +2956,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63389 if (!task)
63390 goto out;
63391
63392 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63393 + goto out_put_task;
63394 +
63395 result = proc_pid_instantiate(dir, dentry, task, NULL);
63396 +out_put_task:
63397 put_task_struct(task);
63398 out:
63399 return ERR_PTR(result);
63400 @@ -2928,7 +3066,7 @@ static const struct pid_entry tid_base_stuff[] = {
63401 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63402 #endif
63403 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63404 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63405 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63406 INF("syscall", S_IRUGO, proc_pid_syscall),
63407 #endif
63408 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63409 @@ -2955,10 +3093,10 @@ static const struct pid_entry tid_base_stuff[] = {
63410 #ifdef CONFIG_SECURITY
63411 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63412 #endif
63413 -#ifdef CONFIG_KALLSYMS
63414 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63415 INF("wchan", S_IRUGO, proc_pid_wchan),
63416 #endif
63417 -#ifdef CONFIG_STACKTRACE
63418 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63419 ONE("stack", S_IRUGO, proc_pid_stack),
63420 #endif
63421 #ifdef CONFIG_SCHEDSTATS
63422 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63423 index 82676e3..5f8518a 100644
63424 --- a/fs/proc/cmdline.c
63425 +++ b/fs/proc/cmdline.c
63426 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63427
63428 static int __init proc_cmdline_init(void)
63429 {
63430 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63431 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63432 +#else
63433 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63434 +#endif
63435 return 0;
63436 }
63437 module_init(proc_cmdline_init);
63438 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63439 index b143471..bb105e5 100644
63440 --- a/fs/proc/devices.c
63441 +++ b/fs/proc/devices.c
63442 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63443
63444 static int __init proc_devices_init(void)
63445 {
63446 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63447 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63448 +#else
63449 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63450 +#endif
63451 return 0;
63452 }
63453 module_init(proc_devices_init);
63454 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63455 index 985ea88..d118a0a 100644
63456 --- a/fs/proc/fd.c
63457 +++ b/fs/proc/fd.c
63458 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63459 if (!task)
63460 return -ENOENT;
63461
63462 - files = get_files_struct(task);
63463 + if (!gr_acl_handle_procpidmem(task))
63464 + files = get_files_struct(task);
63465 put_task_struct(task);
63466
63467 if (files) {
63468 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63469 */
63470 int proc_fd_permission(struct inode *inode, int mask)
63471 {
63472 + struct task_struct *task;
63473 int rv = generic_permission(inode, mask);
63474 - if (rv == 0)
63475 - return 0;
63476 +
63477 if (task_tgid(current) == proc_pid(inode))
63478 rv = 0;
63479 +
63480 + task = get_proc_task(inode);
63481 + if (task == NULL)
63482 + return rv;
63483 +
63484 + if (gr_acl_handle_procpidmem(task))
63485 + rv = -EACCES;
63486 +
63487 + put_task_struct(task);
63488 +
63489 return rv;
63490 }
63491
63492 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63493 index 124fc43..8afbb02 100644
63494 --- a/fs/proc/inode.c
63495 +++ b/fs/proc/inode.c
63496 @@ -23,11 +23,17 @@
63497 #include <linux/slab.h>
63498 #include <linux/mount.h>
63499 #include <linux/magic.h>
63500 +#include <linux/grsecurity.h>
63501
63502 #include <asm/uaccess.h>
63503
63504 #include "internal.h"
63505
63506 +#ifdef CONFIG_PROC_SYSCTL
63507 +extern const struct inode_operations proc_sys_inode_operations;
63508 +extern const struct inode_operations proc_sys_dir_operations;
63509 +#endif
63510 +
63511 static void proc_evict_inode(struct inode *inode)
63512 {
63513 struct proc_dir_entry *de;
63514 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63515 ns = PROC_I(inode)->ns.ns;
63516 if (ns_ops && ns)
63517 ns_ops->put(ns);
63518 +
63519 +#ifdef CONFIG_PROC_SYSCTL
63520 + if (inode->i_op == &proc_sys_inode_operations ||
63521 + inode->i_op == &proc_sys_dir_operations)
63522 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63523 +#endif
63524 +
63525 }
63526
63527 static struct kmem_cache * proc_inode_cachep;
63528 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63529 if (de->mode) {
63530 inode->i_mode = de->mode;
63531 inode->i_uid = de->uid;
63532 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63533 + inode->i_gid = grsec_proc_gid;
63534 +#else
63535 inode->i_gid = de->gid;
63536 +#endif
63537 }
63538 if (de->size)
63539 inode->i_size = de->size;
63540 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63541 index 651d09a..3d7f0bf 100644
63542 --- a/fs/proc/internal.h
63543 +++ b/fs/proc/internal.h
63544 @@ -48,7 +48,7 @@ struct proc_dir_entry {
63545 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63546 u8 namelen;
63547 char name[];
63548 -};
63549 +} __randomize_layout;
63550
63551 union proc_op {
63552 int (*proc_get_link)(struct dentry *, struct path *);
63553 @@ -67,7 +67,7 @@ struct proc_inode {
63554 struct ctl_table *sysctl_entry;
63555 struct proc_ns ns;
63556 struct inode vfs_inode;
63557 -};
63558 +} __randomize_layout;
63559
63560 /*
63561 * General functions
63562 @@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63563 struct pid *, struct task_struct *);
63564 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63565 struct pid *, struct task_struct *);
63566 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63567 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63568 +#endif
63569
63570 /*
63571 * base.c
63572 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63573 index 05029c0..7ea1987 100644
63574 --- a/fs/proc/interrupts.c
63575 +++ b/fs/proc/interrupts.c
63576 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63577
63578 static int __init proc_interrupts_init(void)
63579 {
63580 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63581 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63582 +#else
63583 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63584 +#endif
63585 return 0;
63586 }
63587 module_init(proc_interrupts_init);
63588 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63589 index 5ed0e52..a1c1f2e 100644
63590 --- a/fs/proc/kcore.c
63591 +++ b/fs/proc/kcore.c
63592 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63593 * the addresses in the elf_phdr on our list.
63594 */
63595 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63596 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63597 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63598 + if (tsz > buflen)
63599 tsz = buflen;
63600 -
63601 +
63602 while (buflen) {
63603 struct kcore_list *m;
63604
63605 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63606 kfree(elf_buf);
63607 } else {
63608 if (kern_addr_valid(start)) {
63609 - unsigned long n;
63610 + char *elf_buf;
63611 + mm_segment_t oldfs;
63612
63613 - n = copy_to_user(buffer, (char *)start, tsz);
63614 - /*
63615 - * We cannot distinguish between fault on source
63616 - * and fault on destination. When this happens
63617 - * we clear too and hope it will trigger the
63618 - * EFAULT again.
63619 - */
63620 - if (n) {
63621 - if (clear_user(buffer + tsz - n,
63622 - n))
63623 + elf_buf = kmalloc(tsz, GFP_KERNEL);
63624 + if (!elf_buf)
63625 + return -ENOMEM;
63626 + oldfs = get_fs();
63627 + set_fs(KERNEL_DS);
63628 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63629 + set_fs(oldfs);
63630 + if (copy_to_user(buffer, elf_buf, tsz)) {
63631 + kfree(elf_buf);
63632 return -EFAULT;
63633 + }
63634 }
63635 + set_fs(oldfs);
63636 + kfree(elf_buf);
63637 } else {
63638 if (clear_user(buffer, tsz))
63639 return -EFAULT;
63640 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63641
63642 static int open_kcore(struct inode *inode, struct file *filp)
63643 {
63644 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63645 + return -EPERM;
63646 +#endif
63647 if (!capable(CAP_SYS_RAWIO))
63648 return -EPERM;
63649 if (kcore_need_update)
63650 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63651 index a77d2b2..a9153f0 100644
63652 --- a/fs/proc/meminfo.c
63653 +++ b/fs/proc/meminfo.c
63654 @@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63655 vmi.used >> 10,
63656 vmi.largest_chunk >> 10
63657 #ifdef CONFIG_MEMORY_FAILURE
63658 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63659 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63660 #endif
63661 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63662 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63663 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63664 index 5f9bc8a..5c35f08 100644
63665 --- a/fs/proc/nommu.c
63666 +++ b/fs/proc/nommu.c
63667 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63668
63669 if (file) {
63670 seq_pad(m, ' ');
63671 - seq_path(m, &file->f_path, "");
63672 + seq_path(m, &file->f_path, "\n\\");
63673 }
63674
63675 seq_putc(m, '\n');
63676 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63677 index 4677bb7..408e936 100644
63678 --- a/fs/proc/proc_net.c
63679 +++ b/fs/proc/proc_net.c
63680 @@ -23,6 +23,7 @@
63681 #include <linux/nsproxy.h>
63682 #include <net/net_namespace.h>
63683 #include <linux/seq_file.h>
63684 +#include <linux/grsecurity.h>
63685
63686 #include "internal.h"
63687
63688 @@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
63689 struct task_struct *task;
63690 struct nsproxy *ns;
63691 struct net *net = NULL;
63692 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63693 + const struct cred *cred = current_cred();
63694 +#endif
63695 +
63696 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63697 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
63698 + return net;
63699 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63700 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
63701 + return net;
63702 +#endif
63703
63704 rcu_read_lock();
63705 task = pid_task(proc_pid(dir), PIDTYPE_PID);
63706 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63707 index 7129046..6914844 100644
63708 --- a/fs/proc/proc_sysctl.c
63709 +++ b/fs/proc/proc_sysctl.c
63710 @@ -11,13 +11,21 @@
63711 #include <linux/namei.h>
63712 #include <linux/mm.h>
63713 #include <linux/module.h>
63714 +#include <linux/nsproxy.h>
63715 +#ifdef CONFIG_GRKERNSEC
63716 +#include <net/net_namespace.h>
63717 +#endif
63718 #include "internal.h"
63719
63720 +extern int gr_handle_chroot_sysctl(const int op);
63721 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63722 + const int op);
63723 +
63724 static const struct dentry_operations proc_sys_dentry_operations;
63725 static const struct file_operations proc_sys_file_operations;
63726 -static const struct inode_operations proc_sys_inode_operations;
63727 +const struct inode_operations proc_sys_inode_operations;
63728 static const struct file_operations proc_sys_dir_file_operations;
63729 -static const struct inode_operations proc_sys_dir_operations;
63730 +const struct inode_operations proc_sys_dir_operations;
63731
63732 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63733 {
63734 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63735
63736 err = NULL;
63737 d_set_d_op(dentry, &proc_sys_dentry_operations);
63738 +
63739 + gr_handle_proc_create(dentry, inode);
63740 +
63741 d_add(dentry, inode);
63742
63743 out:
63744 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63745 struct inode *inode = file_inode(filp);
63746 struct ctl_table_header *head = grab_header(inode);
63747 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63748 + int op = write ? MAY_WRITE : MAY_READ;
63749 ssize_t error;
63750 size_t res;
63751
63752 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63753 * and won't be until we finish.
63754 */
63755 error = -EPERM;
63756 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63757 + if (sysctl_perm(head, table, op))
63758 goto out;
63759
63760 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63761 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63762 if (!table->proc_handler)
63763 goto out;
63764
63765 +#ifdef CONFIG_GRKERNSEC
63766 + error = -EPERM;
63767 + if (gr_handle_chroot_sysctl(op))
63768 + goto out;
63769 + dget(filp->f_path.dentry);
63770 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63771 + dput(filp->f_path.dentry);
63772 + goto out;
63773 + }
63774 + dput(filp->f_path.dentry);
63775 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63776 + goto out;
63777 + if (write) {
63778 + if (current->nsproxy->net_ns != table->extra2) {
63779 + if (!capable(CAP_SYS_ADMIN))
63780 + goto out;
63781 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63782 + goto out;
63783 + }
63784 +#endif
63785 +
63786 /* careful: calling conventions are nasty here */
63787 res = count;
63788 error = table->proc_handler(table, write, buf, &res, ppos);
63789 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63790 return false;
63791 } else {
63792 d_set_d_op(child, &proc_sys_dentry_operations);
63793 +
63794 + gr_handle_proc_create(child, inode);
63795 +
63796 d_add(child, inode);
63797 }
63798 } else {
63799 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63800 if ((*pos)++ < ctx->pos)
63801 return true;
63802
63803 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63804 + return 0;
63805 +
63806 if (unlikely(S_ISLNK(table->mode)))
63807 res = proc_sys_link_fill_cache(file, ctx, head, table);
63808 else
63809 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
63810 if (IS_ERR(head))
63811 return PTR_ERR(head);
63812
63813 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
63814 + return -ENOENT;
63815 +
63816 generic_fillattr(inode, stat);
63817 if (table)
63818 stat->mode = (stat->mode & S_IFMT) | table->mode;
63819 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
63820 .llseek = generic_file_llseek,
63821 };
63822
63823 -static const struct inode_operations proc_sys_inode_operations = {
63824 +const struct inode_operations proc_sys_inode_operations = {
63825 .permission = proc_sys_permission,
63826 .setattr = proc_sys_setattr,
63827 .getattr = proc_sys_getattr,
63828 };
63829
63830 -static const struct inode_operations proc_sys_dir_operations = {
63831 +const struct inode_operations proc_sys_dir_operations = {
63832 .lookup = proc_sys_lookup,
63833 .permission = proc_sys_permission,
63834 .setattr = proc_sys_setattr,
63835 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
63836 static struct ctl_dir *new_dir(struct ctl_table_set *set,
63837 const char *name, int namelen)
63838 {
63839 - struct ctl_table *table;
63840 + ctl_table_no_const *table;
63841 struct ctl_dir *new;
63842 struct ctl_node *node;
63843 char *new_name;
63844 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
63845 return NULL;
63846
63847 node = (struct ctl_node *)(new + 1);
63848 - table = (struct ctl_table *)(node + 1);
63849 + table = (ctl_table_no_const *)(node + 1);
63850 new_name = (char *)(table + 2);
63851 memcpy(new_name, name, namelen);
63852 new_name[namelen] = '\0';
63853 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
63854 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
63855 struct ctl_table_root *link_root)
63856 {
63857 - struct ctl_table *link_table, *entry, *link;
63858 + ctl_table_no_const *link_table, *link;
63859 + struct ctl_table *entry;
63860 struct ctl_table_header *links;
63861 struct ctl_node *node;
63862 char *link_name;
63863 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
63864 return NULL;
63865
63866 node = (struct ctl_node *)(links + 1);
63867 - link_table = (struct ctl_table *)(node + nr_entries);
63868 + link_table = (ctl_table_no_const *)(node + nr_entries);
63869 link_name = (char *)&link_table[nr_entries + 1];
63870
63871 for (link = link_table, entry = table; entry->procname; link++, entry++) {
63872 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63873 struct ctl_table_header ***subheader, struct ctl_table_set *set,
63874 struct ctl_table *table)
63875 {
63876 - struct ctl_table *ctl_table_arg = NULL;
63877 - struct ctl_table *entry, *files;
63878 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
63879 + struct ctl_table *entry;
63880 int nr_files = 0;
63881 int nr_dirs = 0;
63882 int err = -ENOMEM;
63883 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63884 nr_files++;
63885 }
63886
63887 - files = table;
63888 /* If there are mixed files and directories we need a new table */
63889 if (nr_dirs && nr_files) {
63890 - struct ctl_table *new;
63891 + ctl_table_no_const *new;
63892 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
63893 GFP_KERNEL);
63894 if (!files)
63895 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63896 /* Register everything except a directory full of subdirectories */
63897 if (nr_files || !nr_dirs) {
63898 struct ctl_table_header *header;
63899 - header = __register_sysctl_table(set, path, files);
63900 + header = __register_sysctl_table(set, path, files ? files : table);
63901 if (!header) {
63902 kfree(ctl_table_arg);
63903 goto out;
63904 diff --git a/fs/proc/root.c b/fs/proc/root.c
63905 index 87dbcbe..55e1b4d 100644
63906 --- a/fs/proc/root.c
63907 +++ b/fs/proc/root.c
63908 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
63909 #ifdef CONFIG_PROC_DEVICETREE
63910 proc_device_tree_init();
63911 #endif
63912 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63913 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63914 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
63915 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63916 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
63917 +#endif
63918 +#else
63919 proc_mkdir("bus", NULL);
63920 +#endif
63921 proc_sys_init();
63922 }
63923
63924 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
63925 index 1cf86c0..0ee1ca5 100644
63926 --- a/fs/proc/stat.c
63927 +++ b/fs/proc/stat.c
63928 @@ -11,6 +11,7 @@
63929 #include <linux/irqnr.h>
63930 #include <asm/cputime.h>
63931 #include <linux/tick.h>
63932 +#include <linux/grsecurity.h>
63933
63934 #ifndef arch_irq_stat_cpu
63935 #define arch_irq_stat_cpu(cpu) 0
63936 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
63937 u64 sum_softirq = 0;
63938 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
63939 struct timespec boottime;
63940 + int unrestricted = 1;
63941 +
63942 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63943 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63944 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
63945 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63946 + && !in_group_p(grsec_proc_gid)
63947 +#endif
63948 + )
63949 + unrestricted = 0;
63950 +#endif
63951 +#endif
63952
63953 user = nice = system = idle = iowait =
63954 irq = softirq = steal = 0;
63955 @@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
63956 getboottime(&boottime);
63957 jif = boottime.tv_sec;
63958
63959 + if (unrestricted) {
63960 for_each_possible_cpu(i) {
63961 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
63962 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63963 @@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
63964 }
63965 }
63966 sum += arch_irq_stat();
63967 + }
63968
63969 seq_puts(p, "cpu ");
63970 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63971 @@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
63972 seq_putc(p, '\n');
63973
63974 for_each_online_cpu(i) {
63975 + if (unrestricted) {
63976 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
63977 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
63978 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63979 @@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
63980 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
63981 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
63982 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
63983 + }
63984 seq_printf(p, "cpu%d", i);
63985 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63986 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
63987 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
63988
63989 /* sum again ? it could be updated? */
63990 for_each_irq_nr(j)
63991 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
63992 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
63993
63994 seq_printf(p,
63995 "\nctxt %llu\n"
63996 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
63997 "processes %lu\n"
63998 "procs_running %lu\n"
63999 "procs_blocked %lu\n",
64000 - nr_context_switches(),
64001 + unrestricted ? nr_context_switches() : 0ULL,
64002 (unsigned long)jif,
64003 - total_forks,
64004 - nr_running(),
64005 - nr_iowait());
64006 + unrestricted ? total_forks : 0UL,
64007 + unrestricted ? nr_running() : 0UL,
64008 + unrestricted ? nr_iowait() : 0UL);
64009
64010 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64011
64012 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64013 index fb52b54..5fc7c14 100644
64014 --- a/fs/proc/task_mmu.c
64015 +++ b/fs/proc/task_mmu.c
64016 @@ -12,12 +12,19 @@
64017 #include <linux/swap.h>
64018 #include <linux/swapops.h>
64019 #include <linux/mmu_notifier.h>
64020 +#include <linux/grsecurity.h>
64021
64022 #include <asm/elf.h>
64023 #include <asm/uaccess.h>
64024 #include <asm/tlbflush.h>
64025 #include "internal.h"
64026
64027 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64028 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64029 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
64030 + _mm->pax_flags & MF_PAX_SEGMEXEC))
64031 +#endif
64032 +
64033 void task_mem(struct seq_file *m, struct mm_struct *mm)
64034 {
64035 unsigned long data, text, lib, swap;
64036 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64037 "VmExe:\t%8lu kB\n"
64038 "VmLib:\t%8lu kB\n"
64039 "VmPTE:\t%8lu kB\n"
64040 - "VmSwap:\t%8lu kB\n",
64041 - hiwater_vm << (PAGE_SHIFT-10),
64042 + "VmSwap:\t%8lu kB\n"
64043 +
64044 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64045 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64046 +#endif
64047 +
64048 + ,hiwater_vm << (PAGE_SHIFT-10),
64049 total_vm << (PAGE_SHIFT-10),
64050 mm->locked_vm << (PAGE_SHIFT-10),
64051 mm->pinned_vm << (PAGE_SHIFT-10),
64052 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64053 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64054 (PTRS_PER_PTE * sizeof(pte_t) *
64055 atomic_long_read(&mm->nr_ptes)) >> 10,
64056 - swap << (PAGE_SHIFT-10));
64057 + swap << (PAGE_SHIFT-10)
64058 +
64059 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64060 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64061 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64062 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64063 +#else
64064 + , mm->context.user_cs_base
64065 + , mm->context.user_cs_limit
64066 +#endif
64067 +#endif
64068 +
64069 + );
64070 }
64071
64072 unsigned long task_vsize(struct mm_struct *mm)
64073 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64074 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64075 }
64076
64077 - /* We don't show the stack guard page in /proc/maps */
64078 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64079 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64080 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64081 +#else
64082 start = vma->vm_start;
64083 - if (stack_guard_page_start(vma, start))
64084 - start += PAGE_SIZE;
64085 end = vma->vm_end;
64086 - if (stack_guard_page_end(vma, end))
64087 - end -= PAGE_SIZE;
64088 +#endif
64089
64090 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64091 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64092 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64093 flags & VM_WRITE ? 'w' : '-',
64094 flags & VM_EXEC ? 'x' : '-',
64095 flags & VM_MAYSHARE ? 's' : 'p',
64096 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64097 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64098 +#else
64099 pgoff,
64100 +#endif
64101 MAJOR(dev), MINOR(dev), ino);
64102
64103 /*
64104 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64105 */
64106 if (file) {
64107 seq_pad(m, ' ');
64108 - seq_path(m, &file->f_path, "\n");
64109 + seq_path(m, &file->f_path, "\n\\");
64110 goto done;
64111 }
64112
64113 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64114 * Thread stack in /proc/PID/task/TID/maps or
64115 * the main process stack.
64116 */
64117 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
64118 - vma->vm_end >= mm->start_stack)) {
64119 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64120 + (vma->vm_start <= mm->start_stack &&
64121 + vma->vm_end >= mm->start_stack)) {
64122 name = "[stack]";
64123 } else {
64124 /* Thread stack in /proc/PID/maps */
64125 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64126 struct proc_maps_private *priv = m->private;
64127 struct task_struct *task = priv->task;
64128
64129 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64130 + if (current->exec_id != m->exec_id) {
64131 + gr_log_badprocpid("maps");
64132 + return 0;
64133 + }
64134 +#endif
64135 +
64136 show_map_vma(m, vma, is_pid);
64137
64138 if (m->count < m->size) /* vma is copied successfully */
64139 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64140 .private = &mss,
64141 };
64142
64143 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64144 + if (current->exec_id != m->exec_id) {
64145 + gr_log_badprocpid("smaps");
64146 + return 0;
64147 + }
64148 +#endif
64149 memset(&mss, 0, sizeof mss);
64150 - mss.vma = vma;
64151 - /* mmap_sem is held in m_start */
64152 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64153 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64154 -
64155 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64156 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64157 +#endif
64158 + mss.vma = vma;
64159 + /* mmap_sem is held in m_start */
64160 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64161 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64162 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64163 + }
64164 +#endif
64165 show_map_vma(m, vma, is_pid);
64166
64167 seq_printf(m,
64168 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64169 "KernelPageSize: %8lu kB\n"
64170 "MMUPageSize: %8lu kB\n"
64171 "Locked: %8lu kB\n",
64172 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64173 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64174 +#else
64175 (vma->vm_end - vma->vm_start) >> 10,
64176 +#endif
64177 mss.resident >> 10,
64178 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64179 mss.shared_clean >> 10,
64180 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64181 char buffer[64];
64182 int nid;
64183
64184 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64185 + if (current->exec_id != m->exec_id) {
64186 + gr_log_badprocpid("numa_maps");
64187 + return 0;
64188 + }
64189 +#endif
64190 +
64191 if (!mm)
64192 return 0;
64193
64194 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64195 mpol_to_str(buffer, sizeof(buffer), pol);
64196 mpol_cond_put(pol);
64197
64198 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64199 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64200 +#else
64201 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64202 +#endif
64203
64204 if (file) {
64205 seq_printf(m, " file=");
64206 - seq_path(m, &file->f_path, "\n\t= ");
64207 + seq_path(m, &file->f_path, "\n\t\\= ");
64208 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64209 seq_printf(m, " heap");
64210 } else {
64211 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64212 index 678455d..ebd3245 100644
64213 --- a/fs/proc/task_nommu.c
64214 +++ b/fs/proc/task_nommu.c
64215 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64216 else
64217 bytes += kobjsize(mm);
64218
64219 - if (current->fs && current->fs->users > 1)
64220 + if (current->fs && atomic_read(&current->fs->users) > 1)
64221 sbytes += kobjsize(current->fs);
64222 else
64223 bytes += kobjsize(current->fs);
64224 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64225
64226 if (file) {
64227 seq_pad(m, ' ');
64228 - seq_path(m, &file->f_path, "");
64229 + seq_path(m, &file->f_path, "\n\\");
64230 } else if (mm) {
64231 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64232
64233 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64234 index 9100d69..51cd925 100644
64235 --- a/fs/proc/vmcore.c
64236 +++ b/fs/proc/vmcore.c
64237 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64238 nr_bytes = count;
64239
64240 /* If pfn is not ram, return zeros for sparse dump files */
64241 - if (pfn_is_ram(pfn) == 0)
64242 - memset(buf, 0, nr_bytes);
64243 - else {
64244 + if (pfn_is_ram(pfn) == 0) {
64245 + if (userbuf) {
64246 + if (clear_user((char __force_user *)buf, nr_bytes))
64247 + return -EFAULT;
64248 + } else
64249 + memset(buf, 0, nr_bytes);
64250 + } else {
64251 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64252 offset, userbuf);
64253 if (tmp < 0)
64254 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64255 static int copy_to(void *target, void *src, size_t size, int userbuf)
64256 {
64257 if (userbuf) {
64258 - if (copy_to_user((char __user *) target, src, size))
64259 + if (copy_to_user((char __force_user *) target, src, size))
64260 return -EFAULT;
64261 } else {
64262 memcpy(target, src, size);
64263 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64264 if (*fpos < m->offset + m->size) {
64265 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64266 start = m->paddr + *fpos - m->offset;
64267 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64268 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64269 if (tmp < 0)
64270 return tmp;
64271 buflen -= tsz;
64272 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64273 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64274 size_t buflen, loff_t *fpos)
64275 {
64276 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64277 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64278 }
64279
64280 /*
64281 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64282 index b00fcc9..e0c6381 100644
64283 --- a/fs/qnx6/qnx6.h
64284 +++ b/fs/qnx6/qnx6.h
64285 @@ -74,7 +74,7 @@ enum {
64286 BYTESEX_BE,
64287 };
64288
64289 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64290 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64291 {
64292 if (sbi->s_bytesex == BYTESEX_LE)
64293 return le64_to_cpu((__force __le64)n);
64294 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64295 return (__force __fs64)cpu_to_be64(n);
64296 }
64297
64298 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64299 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64300 {
64301 if (sbi->s_bytesex == BYTESEX_LE)
64302 return le32_to_cpu((__force __le32)n);
64303 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64304 index 72d2917..c917c12 100644
64305 --- a/fs/quota/netlink.c
64306 +++ b/fs/quota/netlink.c
64307 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64308 void quota_send_warning(struct kqid qid, dev_t dev,
64309 const char warntype)
64310 {
64311 - static atomic_t seq;
64312 + static atomic_unchecked_t seq;
64313 struct sk_buff *skb;
64314 void *msg_head;
64315 int ret;
64316 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64317 "VFS: Not enough memory to send quota warning.\n");
64318 return;
64319 }
64320 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64321 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64322 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64323 if (!msg_head) {
64324 printk(KERN_ERR
64325 diff --git a/fs/read_write.c b/fs/read_write.c
64326 index cfa18df..c110979 100644
64327 --- a/fs/read_write.c
64328 +++ b/fs/read_write.c
64329 @@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64330
64331 old_fs = get_fs();
64332 set_fs(get_ds());
64333 - p = (__force const char __user *)buf;
64334 + p = (const char __force_user *)buf;
64335 if (count > MAX_RW_COUNT)
64336 count = MAX_RW_COUNT;
64337 if (file->f_op->write)
64338 diff --git a/fs/readdir.c b/fs/readdir.c
64339 index 5b53d99..a6c3049 100644
64340 --- a/fs/readdir.c
64341 +++ b/fs/readdir.c
64342 @@ -17,6 +17,7 @@
64343 #include <linux/security.h>
64344 #include <linux/syscalls.h>
64345 #include <linux/unistd.h>
64346 +#include <linux/namei.h>
64347
64348 #include <asm/uaccess.h>
64349
64350 @@ -69,6 +70,7 @@ struct old_linux_dirent {
64351 struct readdir_callback {
64352 struct dir_context ctx;
64353 struct old_linux_dirent __user * dirent;
64354 + struct file * file;
64355 int result;
64356 };
64357
64358 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64359 buf->result = -EOVERFLOW;
64360 return -EOVERFLOW;
64361 }
64362 +
64363 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64364 + return 0;
64365 +
64366 buf->result++;
64367 dirent = buf->dirent;
64368 if (!access_ok(VERIFY_WRITE, dirent,
64369 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64370 if (!f.file)
64371 return -EBADF;
64372
64373 + buf.file = f.file;
64374 error = iterate_dir(f.file, &buf.ctx);
64375 if (buf.result)
64376 error = buf.result;
64377 @@ -142,6 +149,7 @@ struct getdents_callback {
64378 struct dir_context ctx;
64379 struct linux_dirent __user * current_dir;
64380 struct linux_dirent __user * previous;
64381 + struct file * file;
64382 int count;
64383 int error;
64384 };
64385 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64386 buf->error = -EOVERFLOW;
64387 return -EOVERFLOW;
64388 }
64389 +
64390 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64391 + return 0;
64392 +
64393 dirent = buf->previous;
64394 if (dirent) {
64395 if (__put_user(offset, &dirent->d_off))
64396 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64397 if (!f.file)
64398 return -EBADF;
64399
64400 + buf.file = f.file;
64401 error = iterate_dir(f.file, &buf.ctx);
64402 if (error >= 0)
64403 error = buf.error;
64404 @@ -226,6 +239,7 @@ struct getdents_callback64 {
64405 struct dir_context ctx;
64406 struct linux_dirent64 __user * current_dir;
64407 struct linux_dirent64 __user * previous;
64408 + struct file *file;
64409 int count;
64410 int error;
64411 };
64412 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64413 buf->error = -EINVAL; /* only used if we fail.. */
64414 if (reclen > buf->count)
64415 return -EINVAL;
64416 +
64417 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64418 + return 0;
64419 +
64420 dirent = buf->previous;
64421 if (dirent) {
64422 if (__put_user(offset, &dirent->d_off))
64423 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64424 if (!f.file)
64425 return -EBADF;
64426
64427 + buf.file = f.file;
64428 error = iterate_dir(f.file, &buf.ctx);
64429 if (error >= 0)
64430 error = buf.error;
64431 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64432 index 2b7882b..1c5ef48 100644
64433 --- a/fs/reiserfs/do_balan.c
64434 +++ b/fs/reiserfs/do_balan.c
64435 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64436 return;
64437 }
64438
64439 - atomic_inc(&(fs_generation(tb->tb_sb)));
64440 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64441 do_balance_starts(tb);
64442
64443 /* balance leaf returns 0 except if combining L R and S into
64444 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64445 index ee382ef..f4eb6eb5 100644
64446 --- a/fs/reiserfs/item_ops.c
64447 +++ b/fs/reiserfs/item_ops.c
64448 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64449 }
64450
64451 static struct item_operations errcatch_ops = {
64452 - errcatch_bytes_number,
64453 - errcatch_decrement_key,
64454 - errcatch_is_left_mergeable,
64455 - errcatch_print_item,
64456 - errcatch_check_item,
64457 + .bytes_number = errcatch_bytes_number,
64458 + .decrement_key = errcatch_decrement_key,
64459 + .is_left_mergeable = errcatch_is_left_mergeable,
64460 + .print_item = errcatch_print_item,
64461 + .check_item = errcatch_check_item,
64462
64463 - errcatch_create_vi,
64464 - errcatch_check_left,
64465 - errcatch_check_right,
64466 - errcatch_part_size,
64467 - errcatch_unit_num,
64468 - errcatch_print_vi
64469 + .create_vi = errcatch_create_vi,
64470 + .check_left = errcatch_check_left,
64471 + .check_right = errcatch_check_right,
64472 + .part_size = errcatch_part_size,
64473 + .unit_num = errcatch_unit_num,
64474 + .print_vi = errcatch_print_vi
64475 };
64476
64477 //////////////////////////////////////////////////////////////////////////////
64478 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64479 index a958444..42b2323 100644
64480 --- a/fs/reiserfs/procfs.c
64481 +++ b/fs/reiserfs/procfs.c
64482 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64483 "SMALL_TAILS " : "NO_TAILS ",
64484 replay_only(sb) ? "REPLAY_ONLY " : "",
64485 convert_reiserfs(sb) ? "CONV " : "",
64486 - atomic_read(&r->s_generation_counter),
64487 + atomic_read_unchecked(&r->s_generation_counter),
64488 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64489 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64490 SF(s_good_search_by_key_reada), SF(s_bmaps),
64491 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64492 index f8adaee..0eeeeca 100644
64493 --- a/fs/reiserfs/reiserfs.h
64494 +++ b/fs/reiserfs/reiserfs.h
64495 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64496 /* Comment? -Hans */
64497 wait_queue_head_t s_wait;
64498 /* To be obsoleted soon by per buffer seals.. -Hans */
64499 - atomic_t s_generation_counter; // increased by one every time the
64500 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64501 // tree gets re-balanced
64502 unsigned long s_properties; /* File system properties. Currently holds
64503 on-disk FS format */
64504 @@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64505 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64506
64507 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64508 -#define get_generation(s) atomic_read (&fs_generation(s))
64509 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64510 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64511 #define __fs_changed(gen,s) (gen != get_generation (s))
64512 #define fs_changed(gen,s) \
64513 diff --git a/fs/select.c b/fs/select.c
64514 index 467bb1c..cf9d65a 100644
64515 --- a/fs/select.c
64516 +++ b/fs/select.c
64517 @@ -20,6 +20,7 @@
64518 #include <linux/export.h>
64519 #include <linux/slab.h>
64520 #include <linux/poll.h>
64521 +#include <linux/security.h>
64522 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64523 #include <linux/file.h>
64524 #include <linux/fdtable.h>
64525 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64526 struct poll_list *walk = head;
64527 unsigned long todo = nfds;
64528
64529 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64530 if (nfds > rlimit(RLIMIT_NOFILE))
64531 return -EINVAL;
64532
64533 diff --git a/fs/seq_file.c b/fs/seq_file.c
64534 index 1d641bb..e600623 100644
64535 --- a/fs/seq_file.c
64536 +++ b/fs/seq_file.c
64537 @@ -10,6 +10,7 @@
64538 #include <linux/seq_file.h>
64539 #include <linux/slab.h>
64540 #include <linux/cred.h>
64541 +#include <linux/sched.h>
64542
64543 #include <asm/uaccess.h>
64544 #include <asm/page.h>
64545 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64546 #ifdef CONFIG_USER_NS
64547 p->user_ns = file->f_cred->user_ns;
64548 #endif
64549 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64550 + p->exec_id = current->exec_id;
64551 +#endif
64552
64553 /*
64554 * Wrappers around seq_open(e.g. swaps_open) need to be
64555 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64556 return 0;
64557 }
64558 if (!m->buf) {
64559 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64560 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64561 if (!m->buf)
64562 return -ENOMEM;
64563 }
64564 @@ -137,7 +141,7 @@ Eoverflow:
64565 m->op->stop(m, p);
64566 kfree(m->buf);
64567 m->count = 0;
64568 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64569 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64570 return !m->buf ? -ENOMEM : -EAGAIN;
64571 }
64572
64573 @@ -153,7 +157,7 @@ Eoverflow:
64574 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64575 {
64576 struct seq_file *m = file->private_data;
64577 - size_t copied = 0;
64578 + ssize_t copied = 0;
64579 loff_t pos;
64580 size_t n;
64581 void *p;
64582 @@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64583
64584 /* grab buffer if we didn't have one */
64585 if (!m->buf) {
64586 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64587 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64588 if (!m->buf)
64589 goto Enomem;
64590 }
64591 @@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64592 m->op->stop(m, p);
64593 kfree(m->buf);
64594 m->count = 0;
64595 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64596 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64597 if (!m->buf)
64598 goto Enomem;
64599 m->version = 0;
64600 @@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
64601 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64602 void *data)
64603 {
64604 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64605 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64606 int res = -ENOMEM;
64607
64608 if (op) {
64609 diff --git a/fs/splice.c b/fs/splice.c
64610 index 12028fa..a6f2619 100644
64611 --- a/fs/splice.c
64612 +++ b/fs/splice.c
64613 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64614 pipe_lock(pipe);
64615
64616 for (;;) {
64617 - if (!pipe->readers) {
64618 + if (!atomic_read(&pipe->readers)) {
64619 send_sig(SIGPIPE, current, 0);
64620 if (!ret)
64621 ret = -EPIPE;
64622 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64623 page_nr++;
64624 ret += buf->len;
64625
64626 - if (pipe->files)
64627 + if (atomic_read(&pipe->files))
64628 do_wakeup = 1;
64629
64630 if (!--spd->nr_pages)
64631 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64632 do_wakeup = 0;
64633 }
64634
64635 - pipe->waiting_writers++;
64636 + atomic_inc(&pipe->waiting_writers);
64637 pipe_wait(pipe);
64638 - pipe->waiting_writers--;
64639 + atomic_dec(&pipe->waiting_writers);
64640 }
64641
64642 pipe_unlock(pipe);
64643 @@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64644 old_fs = get_fs();
64645 set_fs(get_ds());
64646 /* The cast to a user pointer is valid due to the set_fs() */
64647 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64648 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64649 set_fs(old_fs);
64650
64651 return res;
64652 @@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64653 old_fs = get_fs();
64654 set_fs(get_ds());
64655 /* The cast to a user pointer is valid due to the set_fs() */
64656 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64657 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64658 set_fs(old_fs);
64659
64660 return res;
64661 @@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64662 goto err;
64663
64664 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64665 - vec[i].iov_base = (void __user *) page_address(page);
64666 + vec[i].iov_base = (void __force_user *) page_address(page);
64667 vec[i].iov_len = this_len;
64668 spd.pages[i] = page;
64669 spd.nr_pages++;
64670 @@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64671 ops->release(pipe, buf);
64672 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64673 pipe->nrbufs--;
64674 - if (pipe->files)
64675 + if (atomic_read(&pipe->files))
64676 sd->need_wakeup = true;
64677 }
64678
64679 @@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64680 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64681 {
64682 while (!pipe->nrbufs) {
64683 - if (!pipe->writers)
64684 + if (!atomic_read(&pipe->writers))
64685 return 0;
64686
64687 - if (!pipe->waiting_writers && sd->num_spliced)
64688 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64689 return 0;
64690
64691 if (sd->flags & SPLICE_F_NONBLOCK)
64692 @@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64693 * out of the pipe right after the splice_to_pipe(). So set
64694 * PIPE_READERS appropriately.
64695 */
64696 - pipe->readers = 1;
64697 + atomic_set(&pipe->readers, 1);
64698
64699 current->splice_pipe = pipe;
64700 }
64701 @@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64702
64703 partial[buffers].offset = off;
64704 partial[buffers].len = plen;
64705 + partial[buffers].private = 0;
64706
64707 off = 0;
64708 len -= plen;
64709 @@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64710 ret = -ERESTARTSYS;
64711 break;
64712 }
64713 - if (!pipe->writers)
64714 + if (!atomic_read(&pipe->writers))
64715 break;
64716 - if (!pipe->waiting_writers) {
64717 + if (!atomic_read(&pipe->waiting_writers)) {
64718 if (flags & SPLICE_F_NONBLOCK) {
64719 ret = -EAGAIN;
64720 break;
64721 @@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64722 pipe_lock(pipe);
64723
64724 while (pipe->nrbufs >= pipe->buffers) {
64725 - if (!pipe->readers) {
64726 + if (!atomic_read(&pipe->readers)) {
64727 send_sig(SIGPIPE, current, 0);
64728 ret = -EPIPE;
64729 break;
64730 @@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64731 ret = -ERESTARTSYS;
64732 break;
64733 }
64734 - pipe->waiting_writers++;
64735 + atomic_inc(&pipe->waiting_writers);
64736 pipe_wait(pipe);
64737 - pipe->waiting_writers--;
64738 + atomic_dec(&pipe->waiting_writers);
64739 }
64740
64741 pipe_unlock(pipe);
64742 @@ -1880,14 +1881,14 @@ retry:
64743 pipe_double_lock(ipipe, opipe);
64744
64745 do {
64746 - if (!opipe->readers) {
64747 + if (!atomic_read(&opipe->readers)) {
64748 send_sig(SIGPIPE, current, 0);
64749 if (!ret)
64750 ret = -EPIPE;
64751 break;
64752 }
64753
64754 - if (!ipipe->nrbufs && !ipipe->writers)
64755 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64756 break;
64757
64758 /*
64759 @@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64760 pipe_double_lock(ipipe, opipe);
64761
64762 do {
64763 - if (!opipe->readers) {
64764 + if (!atomic_read(&opipe->readers)) {
64765 send_sig(SIGPIPE, current, 0);
64766 if (!ret)
64767 ret = -EPIPE;
64768 @@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64769 * return EAGAIN if we have the potential of some data in the
64770 * future, otherwise just return 0
64771 */
64772 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
64773 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
64774 ret = -EAGAIN;
64775
64776 pipe_unlock(ipipe);
64777 diff --git a/fs/stat.c b/fs/stat.c
64778 index ae0c3ce..9ee641c 100644
64779 --- a/fs/stat.c
64780 +++ b/fs/stat.c
64781 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
64782 stat->gid = inode->i_gid;
64783 stat->rdev = inode->i_rdev;
64784 stat->size = i_size_read(inode);
64785 - stat->atime = inode->i_atime;
64786 - stat->mtime = inode->i_mtime;
64787 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64788 + stat->atime = inode->i_ctime;
64789 + stat->mtime = inode->i_ctime;
64790 + } else {
64791 + stat->atime = inode->i_atime;
64792 + stat->mtime = inode->i_mtime;
64793 + }
64794 stat->ctime = inode->i_ctime;
64795 stat->blksize = (1 << inode->i_blkbits);
64796 stat->blocks = inode->i_blocks;
64797 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
64798 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
64799 {
64800 struct inode *inode = path->dentry->d_inode;
64801 + int retval;
64802
64803 - if (inode->i_op->getattr)
64804 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
64805 + if (inode->i_op->getattr) {
64806 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
64807 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64808 + stat->atime = stat->ctime;
64809 + stat->mtime = stat->ctime;
64810 + }
64811 + return retval;
64812 + }
64813
64814 generic_fillattr(inode, stat);
64815 return 0;
64816 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
64817 index 5e73d66..4f165fd 100644
64818 --- a/fs/sysfs/dir.c
64819 +++ b/fs/sysfs/dir.c
64820 @@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
64821 *
64822 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64823 */
64824 -static unsigned int sysfs_name_hash(const char *name, const void *ns)
64825 +static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
64826 {
64827 unsigned long hash = init_name_hash();
64828 unsigned int len = strlen(name);
64829 @@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
64830 struct sysfs_dirent *sd;
64831 int rc;
64832
64833 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64834 + const char *parent_name = parent_sd->s_name;
64835 +
64836 + mode = S_IFDIR | S_IRWXU;
64837 +
64838 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
64839 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
64840 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
64841 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
64842 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
64843 +#endif
64844 +
64845 /* allocate */
64846 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
64847 if (!sd)
64848 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
64849 index 35e7d08..4d6e676 100644
64850 --- a/fs/sysfs/file.c
64851 +++ b/fs/sysfs/file.c
64852 @@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
64853
64854 struct sysfs_open_dirent {
64855 atomic_t refcnt;
64856 - atomic_t event;
64857 + atomic_unchecked_t event;
64858 wait_queue_head_t poll;
64859 struct list_head files; /* goes through sysfs_open_file.list */
64860 };
64861 @@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
64862 return -ENODEV;
64863 }
64864
64865 - of->event = atomic_read(&of->sd->s_attr.open->event);
64866 + of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
64867
64868 /*
64869 * Lookup @ops and invoke show(). Control may reach here via seq
64870 @@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
64871 return ret;
64872 }
64873
64874 -static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64875 - void *buf, int len, int write)
64876 +static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64877 + void *buf, size_t len, int write)
64878 {
64879 struct file *file = vma->vm_file;
64880 struct sysfs_open_file *of = sysfs_of(file);
64881 - int ret;
64882 + ssize_t ret;
64883
64884 if (!of->vm_ops)
64885 return -EINVAL;
64886 @@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
64887 return -ENOMEM;
64888
64889 atomic_set(&new_od->refcnt, 0);
64890 - atomic_set(&new_od->event, 1);
64891 + atomic_set_unchecked(&new_od->event, 1);
64892 init_waitqueue_head(&new_od->poll);
64893 INIT_LIST_HEAD(&new_od->files);
64894 goto retry;
64895 @@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
64896
64897 sysfs_put_active(attr_sd);
64898
64899 - if (of->event != atomic_read(&od->event))
64900 + if (of->event != atomic_read_unchecked(&od->event))
64901 goto trigger;
64902
64903 return DEFAULT_POLLMASK;
64904 @@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
64905 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
64906 od = sd->s_attr.open;
64907 if (od) {
64908 - atomic_inc(&od->event);
64909 + atomic_inc_unchecked(&od->event);
64910 wake_up_interruptible(&od->poll);
64911 }
64912 }
64913 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
64914 index 3ae3f1b..081a26c 100644
64915 --- a/fs/sysfs/symlink.c
64916 +++ b/fs/sysfs/symlink.c
64917 @@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64918 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
64919 void *cookie)
64920 {
64921 - char *page = nd_get_link(nd);
64922 + const char *page = nd_get_link(nd);
64923 if (!IS_ERR(page))
64924 free_page((unsigned long)page);
64925 }
64926 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
64927 index 69d4889..a810bd4 100644
64928 --- a/fs/sysv/sysv.h
64929 +++ b/fs/sysv/sysv.h
64930 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
64931 #endif
64932 }
64933
64934 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64935 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64936 {
64937 if (sbi->s_bytesex == BYTESEX_PDP)
64938 return PDP_swab((__force __u32)n);
64939 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
64940 index e18b988..f1d4ad0f 100644
64941 --- a/fs/ubifs/io.c
64942 +++ b/fs/ubifs/io.c
64943 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
64944 return err;
64945 }
64946
64947 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64948 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64949 {
64950 int err;
64951
64952 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
64953 index c175b4d..8f36a16 100644
64954 --- a/fs/udf/misc.c
64955 +++ b/fs/udf/misc.c
64956 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
64957
64958 u8 udf_tag_checksum(const struct tag *t)
64959 {
64960 - u8 *data = (u8 *)t;
64961 + const u8 *data = (const u8 *)t;
64962 u8 checksum = 0;
64963 int i;
64964 for (i = 0; i < sizeof(struct tag); ++i)
64965 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
64966 index 8d974c4..b82f6ec 100644
64967 --- a/fs/ufs/swab.h
64968 +++ b/fs/ufs/swab.h
64969 @@ -22,7 +22,7 @@ enum {
64970 BYTESEX_BE
64971 };
64972
64973 -static inline u64
64974 +static inline u64 __intentional_overflow(-1)
64975 fs64_to_cpu(struct super_block *sbp, __fs64 n)
64976 {
64977 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64978 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
64979 return (__force __fs64)cpu_to_be64(n);
64980 }
64981
64982 -static inline u32
64983 +static inline u32 __intentional_overflow(-1)
64984 fs32_to_cpu(struct super_block *sbp, __fs32 n)
64985 {
64986 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64987 diff --git a/fs/utimes.c b/fs/utimes.c
64988 index aa138d6..5f3a811 100644
64989 --- a/fs/utimes.c
64990 +++ b/fs/utimes.c
64991 @@ -1,6 +1,7 @@
64992 #include <linux/compiler.h>
64993 #include <linux/file.h>
64994 #include <linux/fs.h>
64995 +#include <linux/security.h>
64996 #include <linux/linkage.h>
64997 #include <linux/mount.h>
64998 #include <linux/namei.h>
64999 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65000 }
65001 }
65002 retry_deleg:
65003 +
65004 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65005 + error = -EACCES;
65006 + goto mnt_drop_write_and_out;
65007 + }
65008 +
65009 mutex_lock(&inode->i_mutex);
65010 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65011 mutex_unlock(&inode->i_mutex);
65012 diff --git a/fs/xattr.c b/fs/xattr.c
65013 index 3377dff..f394815 100644
65014 --- a/fs/xattr.c
65015 +++ b/fs/xattr.c
65016 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65017 return rc;
65018 }
65019
65020 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65021 +ssize_t
65022 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
65023 +{
65024 + struct inode *inode = dentry->d_inode;
65025 + ssize_t error;
65026 +
65027 + error = inode_permission(inode, MAY_EXEC);
65028 + if (error)
65029 + return error;
65030 +
65031 + if (inode->i_op->getxattr)
65032 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65033 + else
65034 + error = -EOPNOTSUPP;
65035 +
65036 + return error;
65037 +}
65038 +EXPORT_SYMBOL(pax_getxattr);
65039 +#endif
65040 +
65041 ssize_t
65042 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65043 {
65044 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65045 * Extended attribute SET operations
65046 */
65047 static long
65048 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
65049 +setxattr(struct path *path, const char __user *name, const void __user *value,
65050 size_t size, int flags)
65051 {
65052 int error;
65053 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65054 posix_acl_fix_xattr_from_user(kvalue, size);
65055 }
65056
65057 - error = vfs_setxattr(d, kname, kvalue, size, flags);
65058 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65059 + error = -EACCES;
65060 + goto out;
65061 + }
65062 +
65063 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65064 out:
65065 if (vvalue)
65066 vfree(vvalue);
65067 @@ -377,7 +403,7 @@ retry:
65068 return error;
65069 error = mnt_want_write(path.mnt);
65070 if (!error) {
65071 - error = setxattr(path.dentry, name, value, size, flags);
65072 + error = setxattr(&path, name, value, size, flags);
65073 mnt_drop_write(path.mnt);
65074 }
65075 path_put(&path);
65076 @@ -401,7 +427,7 @@ retry:
65077 return error;
65078 error = mnt_want_write(path.mnt);
65079 if (!error) {
65080 - error = setxattr(path.dentry, name, value, size, flags);
65081 + error = setxattr(&path, name, value, size, flags);
65082 mnt_drop_write(path.mnt);
65083 }
65084 path_put(&path);
65085 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65086 const void __user *,value, size_t, size, int, flags)
65087 {
65088 struct fd f = fdget(fd);
65089 - struct dentry *dentry;
65090 int error = -EBADF;
65091
65092 if (!f.file)
65093 return error;
65094 - dentry = f.file->f_path.dentry;
65095 - audit_inode(NULL, dentry, 0);
65096 + audit_inode(NULL, f.file->f_path.dentry, 0);
65097 error = mnt_want_write_file(f.file);
65098 if (!error) {
65099 - error = setxattr(dentry, name, value, size, flags);
65100 + error = setxattr(&f.file->f_path, name, value, size, flags);
65101 mnt_drop_write_file(f.file);
65102 }
65103 fdput(f);
65104 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65105 * Extended attribute REMOVE operations
65106 */
65107 static long
65108 -removexattr(struct dentry *d, const char __user *name)
65109 +removexattr(struct path *path, const char __user *name)
65110 {
65111 int error;
65112 char kname[XATTR_NAME_MAX + 1];
65113 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65114 if (error < 0)
65115 return error;
65116
65117 - return vfs_removexattr(d, kname);
65118 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65119 + return -EACCES;
65120 +
65121 + return vfs_removexattr(path->dentry, kname);
65122 }
65123
65124 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65125 @@ -652,7 +679,7 @@ retry:
65126 return error;
65127 error = mnt_want_write(path.mnt);
65128 if (!error) {
65129 - error = removexattr(path.dentry, name);
65130 + error = removexattr(&path, name);
65131 mnt_drop_write(path.mnt);
65132 }
65133 path_put(&path);
65134 @@ -675,7 +702,7 @@ retry:
65135 return error;
65136 error = mnt_want_write(path.mnt);
65137 if (!error) {
65138 - error = removexattr(path.dentry, name);
65139 + error = removexattr(&path, name);
65140 mnt_drop_write(path.mnt);
65141 }
65142 path_put(&path);
65143 @@ -689,16 +716,16 @@ retry:
65144 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65145 {
65146 struct fd f = fdget(fd);
65147 - struct dentry *dentry;
65148 + struct path *path;
65149 int error = -EBADF;
65150
65151 if (!f.file)
65152 return error;
65153 - dentry = f.file->f_path.dentry;
65154 - audit_inode(NULL, dentry, 0);
65155 + path = &f.file->f_path;
65156 + audit_inode(NULL, path->dentry, 0);
65157 error = mnt_want_write_file(f.file);
65158 if (!error) {
65159 - error = removexattr(dentry, name);
65160 + error = removexattr(path, name);
65161 mnt_drop_write_file(f.file);
65162 }
65163 fdput(f);
65164 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
65165 index 9fbea87..417b3c2 100644
65166 --- a/fs/xattr_acl.c
65167 +++ b/fs/xattr_acl.c
65168 @@ -10,6 +10,7 @@
65169 #include <linux/posix_acl_xattr.h>
65170 #include <linux/gfp.h>
65171 #include <linux/user_namespace.h>
65172 +#include <linux/grsecurity.h>
65173
65174 /*
65175 * Fix up the uids and gids in posix acl extended attributes in place.
65176 @@ -76,11 +77,12 @@ struct posix_acl *
65177 posix_acl_from_xattr(struct user_namespace *user_ns,
65178 const void *value, size_t size)
65179 {
65180 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65181 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65182 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65183 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65184 int count;
65185 struct posix_acl *acl;
65186 struct posix_acl_entry *acl_e;
65187 + umode_t umask = gr_acl_umask();
65188
65189 if (!value)
65190 return NULL;
65191 @@ -106,12 +108,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65192
65193 switch(acl_e->e_tag) {
65194 case ACL_USER_OBJ:
65195 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65196 + break;
65197 case ACL_GROUP_OBJ:
65198 case ACL_MASK:
65199 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65200 + break;
65201 case ACL_OTHER:
65202 + acl_e->e_perm &= ~(umask & S_IRWXO);
65203 break;
65204
65205 case ACL_USER:
65206 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65207 acl_e->e_uid =
65208 make_kuid(user_ns,
65209 le32_to_cpu(entry->e_id));
65210 @@ -119,6 +127,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65211 goto fail;
65212 break;
65213 case ACL_GROUP:
65214 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65215 acl_e->e_gid =
65216 make_kgid(user_ns,
65217 le32_to_cpu(entry->e_id));
65218 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65219 index 3b2c14b..de031fe 100644
65220 --- a/fs/xfs/xfs_bmap.c
65221 +++ b/fs/xfs/xfs_bmap.c
65222 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65223
65224 #else
65225 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65226 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65227 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65228 #endif /* DEBUG */
65229
65230 /*
65231 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65232 index c4e50c6..8ba93e3 100644
65233 --- a/fs/xfs/xfs_dir2_readdir.c
65234 +++ b/fs/xfs/xfs_dir2_readdir.c
65235 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65236 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65237 filetype = dp->d_ops->sf_get_ftype(sfep);
65238 ctx->pos = off & 0x7fffffff;
65239 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65240 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65241 + char name[sfep->namelen];
65242 + memcpy(name, sfep->name, sfep->namelen);
65243 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65244 + return 0;
65245 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65246 xfs_dir3_get_dtype(mp, filetype)))
65247 return 0;
65248 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65249 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65250 index 33ad9a7..82c18ba 100644
65251 --- a/fs/xfs/xfs_ioctl.c
65252 +++ b/fs/xfs/xfs_ioctl.c
65253 @@ -126,7 +126,7 @@ xfs_find_handle(
65254 }
65255
65256 error = -EFAULT;
65257 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65258 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65259 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65260 goto out_put;
65261
65262 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
65263 index 104455b..764c512 100644
65264 --- a/fs/xfs/xfs_iops.c
65265 +++ b/fs/xfs/xfs_iops.c
65266 @@ -397,7 +397,7 @@ xfs_vn_put_link(
65267 struct nameidata *nd,
65268 void *p)
65269 {
65270 - char *s = nd_get_link(nd);
65271 + const char *s = nd_get_link(nd);
65272
65273 if (!IS_ERR(s))
65274 kfree(s);
65275 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65276 new file mode 100644
65277 index 0000000..3abaf02
65278 --- /dev/null
65279 +++ b/grsecurity/Kconfig
65280 @@ -0,0 +1,1161 @@
65281 +#
65282 +# grecurity configuration
65283 +#
65284 +menu "Memory Protections"
65285 +depends on GRKERNSEC
65286 +
65287 +config GRKERNSEC_KMEM
65288 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65289 + default y if GRKERNSEC_CONFIG_AUTO
65290 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65291 + help
65292 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65293 + be written to or read from to modify or leak the contents of the running
65294 + kernel. /dev/port will also not be allowed to be opened, writing to
65295 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65296 + If you have module support disabled, enabling this will close up several
65297 + ways that are currently used to insert malicious code into the running
65298 + kernel.
65299 +
65300 + Even with this feature enabled, we still highly recommend that
65301 + you use the RBAC system, as it is still possible for an attacker to
65302 + modify the running kernel through other more obscure methods.
65303 +
65304 + It is highly recommended that you say Y here if you meet all the
65305 + conditions above.
65306 +
65307 +config GRKERNSEC_VM86
65308 + bool "Restrict VM86 mode"
65309 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65310 + depends on X86_32
65311 +
65312 + help
65313 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65314 + make use of a special execution mode on 32bit x86 processors called
65315 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65316 + video cards and will still work with this option enabled. The purpose
65317 + of the option is to prevent exploitation of emulation errors in
65318 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65319 + Nearly all users should be able to enable this option.
65320 +
65321 +config GRKERNSEC_IO
65322 + bool "Disable privileged I/O"
65323 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65324 + depends on X86
65325 + select RTC_CLASS
65326 + select RTC_INTF_DEV
65327 + select RTC_DRV_CMOS
65328 +
65329 + help
65330 + If you say Y here, all ioperm and iopl calls will return an error.
65331 + Ioperm and iopl can be used to modify the running kernel.
65332 + Unfortunately, some programs need this access to operate properly,
65333 + the most notable of which are XFree86 and hwclock. hwclock can be
65334 + remedied by having RTC support in the kernel, so real-time
65335 + clock support is enabled if this option is enabled, to ensure
65336 + that hwclock operates correctly. If hwclock still does not work,
65337 + either update udev or symlink /dev/rtc to /dev/rtc0.
65338 +
65339 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
65340 + you may not be able to boot into a graphical environment with this
65341 + option enabled. In this case, you should use the RBAC system instead.
65342 +
65343 +config GRKERNSEC_JIT_HARDEN
65344 + bool "Harden BPF JIT against spray attacks"
65345 + default y if GRKERNSEC_CONFIG_AUTO
65346 + depends on BPF_JIT && X86
65347 + help
65348 + If you say Y here, the native code generated by the kernel's Berkeley
65349 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65350 + attacks that attempt to fit attacker-beneficial instructions in
65351 + 32bit immediate fields of JIT-generated native instructions. The
65352 + attacker will generally aim to cause an unintended instruction sequence
65353 + of JIT-generated native code to execute by jumping into the middle of
65354 + a generated instruction. This feature effectively randomizes the 32bit
65355 + immediate constants present in the generated code to thwart such attacks.
65356 +
65357 + If you're using KERNEXEC, it's recommended that you enable this option
65358 + to supplement the hardening of the kernel.
65359 +
65360 +config GRKERNSEC_PERF_HARDEN
65361 + bool "Disable unprivileged PERF_EVENTS usage by default"
65362 + default y if GRKERNSEC_CONFIG_AUTO
65363 + depends on PERF_EVENTS
65364 + help
65365 + If you say Y here, the range of acceptable values for the
65366 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65367 + default to a new value: 3. When the sysctl is set to this value, no
65368 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65369 +
65370 + Though PERF_EVENTS can be used legitimately for performance monitoring
65371 + and low-level application profiling, it is forced on regardless of
65372 + configuration, has been at fault for several vulnerabilities, and
65373 + creates new opportunities for side channels and other information leaks.
65374 +
65375 + This feature puts PERF_EVENTS into a secure default state and permits
65376 + the administrator to change out of it temporarily if unprivileged
65377 + application profiling is needed.
65378 +
65379 +config GRKERNSEC_RAND_THREADSTACK
65380 + bool "Insert random gaps between thread stacks"
65381 + default y if GRKERNSEC_CONFIG_AUTO
65382 + depends on PAX_RANDMMAP && !PPC
65383 + help
65384 + If you say Y here, a random-sized gap will be enforced between allocated
65385 + thread stacks. Glibc's NPTL and other threading libraries that
65386 + pass MAP_STACK to the kernel for thread stack allocation are supported.
65387 + The implementation currently provides 8 bits of entropy for the gap.
65388 +
65389 + Many distributions do not compile threaded remote services with the
65390 + -fstack-check argument to GCC, causing the variable-sized stack-based
65391 + allocator, alloca(), to not probe the stack on allocation. This
65392 + permits an unbounded alloca() to skip over any guard page and potentially
65393 + modify another thread's stack reliably. An enforced random gap
65394 + reduces the reliability of such an attack and increases the chance
65395 + that such a read/write to another thread's stack instead lands in
65396 + an unmapped area, causing a crash and triggering grsecurity's
65397 + anti-bruteforcing logic.
65398 +
65399 +config GRKERNSEC_PROC_MEMMAP
65400 + bool "Harden ASLR against information leaks and entropy reduction"
65401 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65402 + depends on PAX_NOEXEC || PAX_ASLR
65403 + help
65404 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65405 + give no information about the addresses of its mappings if
65406 + PaX features that rely on random addresses are enabled on the task.
65407 + In addition to sanitizing this information and disabling other
65408 + dangerous sources of information, this option causes reads of sensitive
65409 + /proc/<pid> entries where the file descriptor was opened in a different
65410 + task than the one performing the read. Such attempts are logged.
65411 + This option also limits argv/env strings for suid/sgid binaries
65412 + to 512KB to prevent a complete exhaustion of the stack entropy provided
65413 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65414 + binaries to prevent alternative mmap layouts from being abused.
65415 +
65416 + If you use PaX it is essential that you say Y here as it closes up
65417 + several holes that make full ASLR useless locally.
65418 +
65419 +config GRKERNSEC_BRUTE
65420 + bool "Deter exploit bruteforcing"
65421 + default y if GRKERNSEC_CONFIG_AUTO
65422 + help
65423 + If you say Y here, attempts to bruteforce exploits against forking
65424 + daemons such as apache or sshd, as well as against suid/sgid binaries
65425 + will be deterred. When a child of a forking daemon is killed by PaX
65426 + or crashes due to an illegal instruction or other suspicious signal,
65427 + the parent process will be delayed 30 seconds upon every subsequent
65428 + fork until the administrator is able to assess the situation and
65429 + restart the daemon.
65430 + In the suid/sgid case, the attempt is logged, the user has all their
65431 + existing instances of the suid/sgid binary terminated and will
65432 + be unable to execute any suid/sgid binaries for 15 minutes.
65433 +
65434 + It is recommended that you also enable signal logging in the auditing
65435 + section so that logs are generated when a process triggers a suspicious
65436 + signal.
65437 + If the sysctl option is enabled, a sysctl option with name
65438 + "deter_bruteforce" is created.
65439 +
65440 +config GRKERNSEC_MODHARDEN
65441 + bool "Harden module auto-loading"
65442 + default y if GRKERNSEC_CONFIG_AUTO
65443 + depends on MODULES
65444 + help
65445 + If you say Y here, module auto-loading in response to use of some
65446 + feature implemented by an unloaded module will be restricted to
65447 + root users. Enabling this option helps defend against attacks
65448 + by unprivileged users who abuse the auto-loading behavior to
65449 + cause a vulnerable module to load that is then exploited.
65450 +
65451 + If this option prevents a legitimate use of auto-loading for a
65452 + non-root user, the administrator can execute modprobe manually
65453 + with the exact name of the module mentioned in the alert log.
65454 + Alternatively, the administrator can add the module to the list
65455 + of modules loaded at boot by modifying init scripts.
65456 +
65457 + Modification of init scripts will most likely be needed on
65458 + Ubuntu servers with encrypted home directory support enabled,
65459 + as the first non-root user logging in will cause the ecb(aes),
65460 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65461 +
65462 +config GRKERNSEC_HIDESYM
65463 + bool "Hide kernel symbols"
65464 + default y if GRKERNSEC_CONFIG_AUTO
65465 + select PAX_USERCOPY_SLABS
65466 + help
65467 + If you say Y here, getting information on loaded modules, and
65468 + displaying all kernel symbols through a syscall will be restricted
65469 + to users with CAP_SYS_MODULE. For software compatibility reasons,
65470 + /proc/kallsyms will be restricted to the root user. The RBAC
65471 + system can hide that entry even from root.
65472 +
65473 + This option also prevents leaking of kernel addresses through
65474 + several /proc entries.
65475 +
65476 + Note that this option is only effective provided the following
65477 + conditions are met:
65478 + 1) The kernel using grsecurity is not precompiled by some distribution
65479 + 2) You have also enabled GRKERNSEC_DMESG
65480 + 3) You are using the RBAC system and hiding other files such as your
65481 + kernel image and System.map. Alternatively, enabling this option
65482 + causes the permissions on /boot, /lib/modules, and the kernel
65483 + source directory to change at compile time to prevent
65484 + reading by non-root users.
65485 + If the above conditions are met, this option will aid in providing a
65486 + useful protection against local kernel exploitation of overflows
65487 + and arbitrary read/write vulnerabilities.
65488 +
65489 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65490 + in addition to this feature.
65491 +
65492 +config GRKERNSEC_RANDSTRUCT
65493 + bool "Randomize layout of sensitive kernel structures"
65494 + default y if GRKERNSEC_CONFIG_AUTO
65495 + select GRKERNSEC_HIDESYM
65496 + select MODVERSIONS if MODULES
65497 + help
65498 + If you say Y here, the layouts of a number of sensitive kernel
65499 + structures (task, fs, cred, etc) and all structures composed entirely
65500 + of function pointers (aka "ops" structs) will be randomized at compile-time.
65501 + This can introduce the requirement of an additional infoleak
65502 + vulnerability for exploits targeting these structure types.
65503 +
65504 + Enabling this feature will introduce some performance impact, slightly
65505 + increase memory usage, and prevent the use of forensic tools like
65506 + Volatility against the system (unless the kernel source tree isn't
65507 + cleaned after kernel installation).
65508 +
65509 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65510 + It remains after a make clean to allow for external modules to be compiled
65511 + with the existing seed and will be removed by a make mrproper or
65512 + make distclean.
65513 +
65514 + Note that the implementation requires gcc 4.6.4. or newer. You may need
65515 + to install the supporting headers explicitly in addition to the normal
65516 + gcc package.
65517 +
65518 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65519 + bool "Use cacheline-aware structure randomization"
65520 + depends on GRKERNSEC_RANDSTRUCT
65521 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65522 + help
65523 + If you say Y here, the RANDSTRUCT randomization will make a best effort
65524 + at restricting randomization to cacheline-sized groups of elements. It
65525 + will further not randomize bitfields in structures. This reduces the
65526 + performance hit of RANDSTRUCT at the cost of weakened randomization.
65527 +
65528 +config GRKERNSEC_KERN_LOCKOUT
65529 + bool "Active kernel exploit response"
65530 + default y if GRKERNSEC_CONFIG_AUTO
65531 + depends on X86 || ARM || PPC || SPARC
65532 + help
65533 + If you say Y here, when a PaX alert is triggered due to suspicious
65534 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65535 + or an OOPS occurs due to bad memory accesses, instead of just
65536 + terminating the offending process (and potentially allowing
65537 + a subsequent exploit from the same user), we will take one of two
65538 + actions:
65539 + If the user was root, we will panic the system
65540 + If the user was non-root, we will log the attempt, terminate
65541 + all processes owned by the user, then prevent them from creating
65542 + any new processes until the system is restarted
65543 + This deters repeated kernel exploitation/bruteforcing attempts
65544 + and is useful for later forensics.
65545 +
65546 +config GRKERNSEC_OLD_ARM_USERLAND
65547 + bool "Old ARM userland compatibility"
65548 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65549 + help
65550 + If you say Y here, stubs of executable code to perform such operations
65551 + as "compare-exchange" will be placed at fixed locations in the ARM vector
65552 + table. This is unfortunately needed for old ARM userland meant to run
65553 + across a wide range of processors. Without this option enabled,
65554 + the get_tls and data memory barrier stubs will be emulated by the kernel,
65555 + which is enough for Linaro userlands or other userlands designed for v6
65556 + and newer ARM CPUs. It's recommended that you try without this option enabled
65557 + first, and only enable it if your userland does not boot (it will likely fail
65558 + at init time).
65559 +
65560 +endmenu
65561 +menu "Role Based Access Control Options"
65562 +depends on GRKERNSEC
65563 +
65564 +config GRKERNSEC_RBAC_DEBUG
65565 + bool
65566 +
65567 +config GRKERNSEC_NO_RBAC
65568 + bool "Disable RBAC system"
65569 + help
65570 + If you say Y here, the /dev/grsec device will be removed from the kernel,
65571 + preventing the RBAC system from being enabled. You should only say Y
65572 + here if you have no intention of using the RBAC system, so as to prevent
65573 + an attacker with root access from misusing the RBAC system to hide files
65574 + and processes when loadable module support and /dev/[k]mem have been
65575 + locked down.
65576 +
65577 +config GRKERNSEC_ACL_HIDEKERN
65578 + bool "Hide kernel processes"
65579 + help
65580 + If you say Y here, all kernel threads will be hidden to all
65581 + processes but those whose subject has the "view hidden processes"
65582 + flag.
65583 +
65584 +config GRKERNSEC_ACL_MAXTRIES
65585 + int "Maximum tries before password lockout"
65586 + default 3
65587 + help
65588 + This option enforces the maximum number of times a user can attempt
65589 + to authorize themselves with the grsecurity RBAC system before being
65590 + denied the ability to attempt authorization again for a specified time.
65591 + The lower the number, the harder it will be to brute-force a password.
65592 +
65593 +config GRKERNSEC_ACL_TIMEOUT
65594 + int "Time to wait after max password tries, in seconds"
65595 + default 30
65596 + help
65597 + This option specifies the time the user must wait after attempting to
65598 + authorize to the RBAC system with the maximum number of invalid
65599 + passwords. The higher the number, the harder it will be to brute-force
65600 + a password.
65601 +
65602 +endmenu
65603 +menu "Filesystem Protections"
65604 +depends on GRKERNSEC
65605 +
65606 +config GRKERNSEC_PROC
65607 + bool "Proc restrictions"
65608 + default y if GRKERNSEC_CONFIG_AUTO
65609 + help
65610 + If you say Y here, the permissions of the /proc filesystem
65611 + will be altered to enhance system security and privacy. You MUST
65612 + choose either a user only restriction or a user and group restriction.
65613 + Depending upon the option you choose, you can either restrict users to
65614 + see only the processes they themselves run, or choose a group that can
65615 + view all processes and files normally restricted to root if you choose
65616 + the "restrict to user only" option. NOTE: If you're running identd or
65617 + ntpd as a non-root user, you will have to run it as the group you
65618 + specify here.
65619 +
65620 +config GRKERNSEC_PROC_USER
65621 + bool "Restrict /proc to user only"
65622 + depends on GRKERNSEC_PROC
65623 + help
65624 + If you say Y here, non-root users will only be able to view their own
65625 + processes, and restricts them from viewing network-related information,
65626 + and viewing kernel symbol and module information.
65627 +
65628 +config GRKERNSEC_PROC_USERGROUP
65629 + bool "Allow special group"
65630 + default y if GRKERNSEC_CONFIG_AUTO
65631 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65632 + help
65633 + If you say Y here, you will be able to select a group that will be
65634 + able to view all processes and network-related information. If you've
65635 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65636 + remain hidden. This option is useful if you want to run identd as
65637 + a non-root user. The group you select may also be chosen at boot time
65638 + via "grsec_proc_gid=" on the kernel commandline.
65639 +
65640 +config GRKERNSEC_PROC_GID
65641 + int "GID for special group"
65642 + depends on GRKERNSEC_PROC_USERGROUP
65643 + default 1001
65644 +
65645 +config GRKERNSEC_PROC_ADD
65646 + bool "Additional restrictions"
65647 + default y if GRKERNSEC_CONFIG_AUTO
65648 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65649 + help
65650 + If you say Y here, additional restrictions will be placed on
65651 + /proc that keep normal users from viewing device information and
65652 + slabinfo information that could be useful for exploits.
65653 +
65654 +config GRKERNSEC_LINK
65655 + bool "Linking restrictions"
65656 + default y if GRKERNSEC_CONFIG_AUTO
65657 + help
65658 + If you say Y here, /tmp race exploits will be prevented, since users
65659 + will no longer be able to follow symlinks owned by other users in
65660 + world-writable +t directories (e.g. /tmp), unless the owner of the
65661 + symlink is the owner of the directory. users will also not be
65662 + able to hardlink to files they do not own. If the sysctl option is
65663 + enabled, a sysctl option with name "linking_restrictions" is created.
65664 +
65665 +config GRKERNSEC_SYMLINKOWN
65666 + bool "Kernel-enforced SymlinksIfOwnerMatch"
65667 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65668 + help
65669 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
65670 + that prevents it from being used as a security feature. As Apache
65671 + verifies the symlink by performing a stat() against the target of
65672 + the symlink before it is followed, an attacker can setup a symlink
65673 + to point to a same-owned file, then replace the symlink with one
65674 + that targets another user's file just after Apache "validates" the
65675 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
65676 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65677 + will be in place for the group you specify. If the sysctl option
65678 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
65679 + created.
65680 +
65681 +config GRKERNSEC_SYMLINKOWN_GID
65682 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65683 + depends on GRKERNSEC_SYMLINKOWN
65684 + default 1006
65685 + help
65686 + Setting this GID determines what group kernel-enforced
65687 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65688 + is enabled, a sysctl option with name "symlinkown_gid" is created.
65689 +
65690 +config GRKERNSEC_FIFO
65691 + bool "FIFO restrictions"
65692 + default y if GRKERNSEC_CONFIG_AUTO
65693 + help
65694 + If you say Y here, users will not be able to write to FIFOs they don't
65695 + own in world-writable +t directories (e.g. /tmp), unless the owner of
65696 + the FIFO is the same owner of the directory it's held in. If the sysctl
65697 + option is enabled, a sysctl option with name "fifo_restrictions" is
65698 + created.
65699 +
65700 +config GRKERNSEC_SYSFS_RESTRICT
65701 + bool "Sysfs/debugfs restriction"
65702 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65703 + depends on SYSFS
65704 + help
65705 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65706 + any filesystem normally mounted under it (e.g. debugfs) will be
65707 + mostly accessible only by root. These filesystems generally provide access
65708 + to hardware and debug information that isn't appropriate for unprivileged
65709 + users of the system. Sysfs and debugfs have also become a large source
65710 + of new vulnerabilities, ranging from infoleaks to local compromise.
65711 + There has been very little oversight with an eye toward security involved
65712 + in adding new exporters of information to these filesystems, so their
65713 + use is discouraged.
65714 + For reasons of compatibility, a few directories have been whitelisted
65715 + for access by non-root users:
65716 + /sys/fs/selinux
65717 + /sys/fs/fuse
65718 + /sys/devices/system/cpu
65719 +
65720 +config GRKERNSEC_ROFS
65721 + bool "Runtime read-only mount protection"
65722 + depends on SYSCTL
65723 + help
65724 + If you say Y here, a sysctl option with name "romount_protect" will
65725 + be created. By setting this option to 1 at runtime, filesystems
65726 + will be protected in the following ways:
65727 + * No new writable mounts will be allowed
65728 + * Existing read-only mounts won't be able to be remounted read/write
65729 + * Write operations will be denied on all block devices
65730 + This option acts independently of grsec_lock: once it is set to 1,
65731 + it cannot be turned off. Therefore, please be mindful of the resulting
65732 + behavior if this option is enabled in an init script on a read-only
65733 + filesystem.
65734 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65735 + and GRKERNSEC_IO should be enabled and module loading disabled via
65736 + config or at runtime.
65737 + This feature is mainly intended for secure embedded systems.
65738 +
65739 +
65740 +config GRKERNSEC_DEVICE_SIDECHANNEL
65741 + bool "Eliminate stat/notify-based device sidechannels"
65742 + default y if GRKERNSEC_CONFIG_AUTO
65743 + help
65744 + If you say Y here, timing analyses on block or character
65745 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65746 + will be thwarted for unprivileged users. If a process without
65747 + CAP_MKNOD stats such a device, the last access and last modify times
65748 + will match the device's create time. No access or modify events
65749 + will be triggered through inotify/dnotify/fanotify for such devices.
65750 + This feature will prevent attacks that may at a minimum
65751 + allow an attacker to determine the administrator's password length.
65752 +
65753 +config GRKERNSEC_CHROOT
65754 + bool "Chroot jail restrictions"
65755 + default y if GRKERNSEC_CONFIG_AUTO
65756 + help
65757 + If you say Y here, you will be able to choose several options that will
65758 + make breaking out of a chrooted jail much more difficult. If you
65759 + encounter no software incompatibilities with the following options, it
65760 + is recommended that you enable each one.
65761 +
65762 + Note that the chroot restrictions are not intended to apply to "chroots"
65763 + to directories that are simple bind mounts of the global root filesystem.
65764 + For several other reasons, a user shouldn't expect any significant
65765 + security by performing such a chroot.
65766 +
65767 +config GRKERNSEC_CHROOT_MOUNT
65768 + bool "Deny mounts"
65769 + default y if GRKERNSEC_CONFIG_AUTO
65770 + depends on GRKERNSEC_CHROOT
65771 + help
65772 + If you say Y here, processes inside a chroot will not be able to
65773 + mount or remount filesystems. If the sysctl option is enabled, a
65774 + sysctl option with name "chroot_deny_mount" is created.
65775 +
65776 +config GRKERNSEC_CHROOT_DOUBLE
65777 + bool "Deny double-chroots"
65778 + default y if GRKERNSEC_CONFIG_AUTO
65779 + depends on GRKERNSEC_CHROOT
65780 + help
65781 + If you say Y here, processes inside a chroot will not be able to chroot
65782 + again outside the chroot. This is a widely used method of breaking
65783 + out of a chroot jail and should not be allowed. If the sysctl
65784 + option is enabled, a sysctl option with name
65785 + "chroot_deny_chroot" is created.
65786 +
65787 +config GRKERNSEC_CHROOT_PIVOT
65788 + bool "Deny pivot_root in chroot"
65789 + default y if GRKERNSEC_CONFIG_AUTO
65790 + depends on GRKERNSEC_CHROOT
65791 + help
65792 + If you say Y here, processes inside a chroot will not be able to use
65793 + a function called pivot_root() that was introduced in Linux 2.3.41. It
65794 + works similar to chroot in that it changes the root filesystem. This
65795 + function could be misused in a chrooted process to attempt to break out
65796 + of the chroot, and therefore should not be allowed. If the sysctl
65797 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
65798 + created.
65799 +
65800 +config GRKERNSEC_CHROOT_CHDIR
65801 + bool "Enforce chdir(\"/\") on all chroots"
65802 + default y if GRKERNSEC_CONFIG_AUTO
65803 + depends on GRKERNSEC_CHROOT
65804 + help
65805 + If you say Y here, the current working directory of all newly-chrooted
65806 + applications will be set to the the root directory of the chroot.
65807 + The man page on chroot(2) states:
65808 + Note that this call does not change the current working
65809 + directory, so that `.' can be outside the tree rooted at
65810 + `/'. In particular, the super-user can escape from a
65811 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65812 +
65813 + It is recommended that you say Y here, since it's not known to break
65814 + any software. If the sysctl option is enabled, a sysctl option with
65815 + name "chroot_enforce_chdir" is created.
65816 +
65817 +config GRKERNSEC_CHROOT_CHMOD
65818 + bool "Deny (f)chmod +s"
65819 + default y if GRKERNSEC_CONFIG_AUTO
65820 + depends on GRKERNSEC_CHROOT
65821 + help
65822 + If you say Y here, processes inside a chroot will not be able to chmod
65823 + or fchmod files to make them have suid or sgid bits. This protects
65824 + against another published method of breaking a chroot. If the sysctl
65825 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
65826 + created.
65827 +
65828 +config GRKERNSEC_CHROOT_FCHDIR
65829 + bool "Deny fchdir out of chroot"
65830 + default y if GRKERNSEC_CONFIG_AUTO
65831 + depends on GRKERNSEC_CHROOT
65832 + help
65833 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
65834 + to a file descriptor of the chrooting process that points to a directory
65835 + outside the filesystem will be stopped. If the sysctl option
65836 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65837 +
65838 +config GRKERNSEC_CHROOT_MKNOD
65839 + bool "Deny mknod"
65840 + default y if GRKERNSEC_CONFIG_AUTO
65841 + depends on GRKERNSEC_CHROOT
65842 + help
65843 + If you say Y here, processes inside a chroot will not be allowed to
65844 + mknod. The problem with using mknod inside a chroot is that it
65845 + would allow an attacker to create a device entry that is the same
65846 + as one on the physical root of your system, which could range from
65847 + anything from the console device to a device for your harddrive (which
65848 + they could then use to wipe the drive or steal data). It is recommended
65849 + that you say Y here, unless you run into software incompatibilities.
65850 + If the sysctl option is enabled, a sysctl option with name
65851 + "chroot_deny_mknod" is created.
65852 +
65853 +config GRKERNSEC_CHROOT_SHMAT
65854 + bool "Deny shmat() out of chroot"
65855 + default y if GRKERNSEC_CONFIG_AUTO
65856 + depends on GRKERNSEC_CHROOT
65857 + help
65858 + If you say Y here, processes inside a chroot will not be able to attach
65859 + to shared memory segments that were created outside of the chroot jail.
65860 + It is recommended that you say Y here. If the sysctl option is enabled,
65861 + a sysctl option with name "chroot_deny_shmat" is created.
65862 +
65863 +config GRKERNSEC_CHROOT_UNIX
65864 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
65865 + default y if GRKERNSEC_CONFIG_AUTO
65866 + depends on GRKERNSEC_CHROOT
65867 + help
65868 + If you say Y here, processes inside a chroot will not be able to
65869 + connect to abstract (meaning not belonging to a filesystem) Unix
65870 + domain sockets that were bound outside of a chroot. It is recommended
65871 + that you say Y here. If the sysctl option is enabled, a sysctl option
65872 + with name "chroot_deny_unix" is created.
65873 +
65874 +config GRKERNSEC_CHROOT_FINDTASK
65875 + bool "Protect outside processes"
65876 + default y if GRKERNSEC_CONFIG_AUTO
65877 + depends on GRKERNSEC_CHROOT
65878 + help
65879 + If you say Y here, processes inside a chroot will not be able to
65880 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65881 + getsid, or view any process outside of the chroot. If the sysctl
65882 + option is enabled, a sysctl option with name "chroot_findtask" is
65883 + created.
65884 +
65885 +config GRKERNSEC_CHROOT_NICE
65886 + bool "Restrict priority changes"
65887 + default y if GRKERNSEC_CONFIG_AUTO
65888 + depends on GRKERNSEC_CHROOT
65889 + help
65890 + If you say Y here, processes inside a chroot will not be able to raise
65891 + the priority of processes in the chroot, or alter the priority of
65892 + processes outside the chroot. This provides more security than simply
65893 + removing CAP_SYS_NICE from the process' capability set. If the
65894 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65895 + is created.
65896 +
65897 +config GRKERNSEC_CHROOT_SYSCTL
65898 + bool "Deny sysctl writes"
65899 + default y if GRKERNSEC_CONFIG_AUTO
65900 + depends on GRKERNSEC_CHROOT
65901 + help
65902 + If you say Y here, an attacker in a chroot will not be able to
65903 + write to sysctl entries, either by sysctl(2) or through a /proc
65904 + interface. It is strongly recommended that you say Y here. If the
65905 + sysctl option is enabled, a sysctl option with name
65906 + "chroot_deny_sysctl" is created.
65907 +
65908 +config GRKERNSEC_CHROOT_CAPS
65909 + bool "Capability restrictions"
65910 + default y if GRKERNSEC_CONFIG_AUTO
65911 + depends on GRKERNSEC_CHROOT
65912 + help
65913 + If you say Y here, the capabilities on all processes within a
65914 + chroot jail will be lowered to stop module insertion, raw i/o,
65915 + system and net admin tasks, rebooting the system, modifying immutable
65916 + files, modifying IPC owned by another, and changing the system time.
65917 + This is left an option because it can break some apps. Disable this
65918 + if your chrooted apps are having problems performing those kinds of
65919 + tasks. If the sysctl option is enabled, a sysctl option with
65920 + name "chroot_caps" is created.
65921 +
65922 +config GRKERNSEC_CHROOT_INITRD
65923 + bool "Exempt initrd tasks from restrictions"
65924 + default y if GRKERNSEC_CONFIG_AUTO
65925 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
65926 + help
65927 + If you say Y here, tasks started prior to init will be exempted from
65928 + grsecurity's chroot restrictions. This option is mainly meant to
65929 + resolve Plymouth's performing privileged operations unnecessarily
65930 + in a chroot.
65931 +
65932 +endmenu
65933 +menu "Kernel Auditing"
65934 +depends on GRKERNSEC
65935 +
65936 +config GRKERNSEC_AUDIT_GROUP
65937 + bool "Single group for auditing"
65938 + help
65939 + If you say Y here, the exec and chdir logging features will only operate
65940 + on a group you specify. This option is recommended if you only want to
65941 + watch certain users instead of having a large amount of logs from the
65942 + entire system. If the sysctl option is enabled, a sysctl option with
65943 + name "audit_group" is created.
65944 +
65945 +config GRKERNSEC_AUDIT_GID
65946 + int "GID for auditing"
65947 + depends on GRKERNSEC_AUDIT_GROUP
65948 + default 1007
65949 +
65950 +config GRKERNSEC_EXECLOG
65951 + bool "Exec logging"
65952 + help
65953 + If you say Y here, all execve() calls will be logged (since the
65954 + other exec*() calls are frontends to execve(), all execution
65955 + will be logged). Useful for shell-servers that like to keep track
65956 + of their users. If the sysctl option is enabled, a sysctl option with
65957 + name "exec_logging" is created.
65958 + WARNING: This option when enabled will produce a LOT of logs, especially
65959 + on an active system.
65960 +
65961 +config GRKERNSEC_RESLOG
65962 + bool "Resource logging"
65963 + default y if GRKERNSEC_CONFIG_AUTO
65964 + help
65965 + If you say Y here, all attempts to overstep resource limits will
65966 + be logged with the resource name, the requested size, and the current
65967 + limit. It is highly recommended that you say Y here. If the sysctl
65968 + option is enabled, a sysctl option with name "resource_logging" is
65969 + created. If the RBAC system is enabled, the sysctl value is ignored.
65970 +
65971 +config GRKERNSEC_CHROOT_EXECLOG
65972 + bool "Log execs within chroot"
65973 + help
65974 + If you say Y here, all executions inside a chroot jail will be logged
65975 + to syslog. This can cause a large amount of logs if certain
65976 + applications (eg. djb's daemontools) are installed on the system, and
65977 + is therefore left as an option. If the sysctl option is enabled, a
65978 + sysctl option with name "chroot_execlog" is created.
65979 +
65980 +config GRKERNSEC_AUDIT_PTRACE
65981 + bool "Ptrace logging"
65982 + help
65983 + If you say Y here, all attempts to attach to a process via ptrace
65984 + will be logged. If the sysctl option is enabled, a sysctl option
65985 + with name "audit_ptrace" is created.
65986 +
65987 +config GRKERNSEC_AUDIT_CHDIR
65988 + bool "Chdir logging"
65989 + help
65990 + If you say Y here, all chdir() calls will be logged. If the sysctl
65991 + option is enabled, a sysctl option with name "audit_chdir" is created.
65992 +
65993 +config GRKERNSEC_AUDIT_MOUNT
65994 + bool "(Un)Mount logging"
65995 + help
65996 + If you say Y here, all mounts and unmounts will be logged. If the
65997 + sysctl option is enabled, a sysctl option with name "audit_mount" is
65998 + created.
65999 +
66000 +config GRKERNSEC_SIGNAL
66001 + bool "Signal logging"
66002 + default y if GRKERNSEC_CONFIG_AUTO
66003 + help
66004 + If you say Y here, certain important signals will be logged, such as
66005 + SIGSEGV, which will as a result inform you of when a error in a program
66006 + occurred, which in some cases could mean a possible exploit attempt.
66007 + If the sysctl option is enabled, a sysctl option with name
66008 + "signal_logging" is created.
66009 +
66010 +config GRKERNSEC_FORKFAIL
66011 + bool "Fork failure logging"
66012 + help
66013 + If you say Y here, all failed fork() attempts will be logged.
66014 + This could suggest a fork bomb, or someone attempting to overstep
66015 + their process limit. If the sysctl option is enabled, a sysctl option
66016 + with name "forkfail_logging" is created.
66017 +
66018 +config GRKERNSEC_TIME
66019 + bool "Time change logging"
66020 + default y if GRKERNSEC_CONFIG_AUTO
66021 + help
66022 + If you say Y here, any changes of the system clock will be logged.
66023 + If the sysctl option is enabled, a sysctl option with name
66024 + "timechange_logging" is created.
66025 +
66026 +config GRKERNSEC_PROC_IPADDR
66027 + bool "/proc/<pid>/ipaddr support"
66028 + default y if GRKERNSEC_CONFIG_AUTO
66029 + help
66030 + If you say Y here, a new entry will be added to each /proc/<pid>
66031 + directory that contains the IP address of the person using the task.
66032 + The IP is carried across local TCP and AF_UNIX stream sockets.
66033 + This information can be useful for IDS/IPSes to perform remote response
66034 + to a local attack. The entry is readable by only the owner of the
66035 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66036 + the RBAC system), and thus does not create privacy concerns.
66037 +
66038 +config GRKERNSEC_RWXMAP_LOG
66039 + bool 'Denied RWX mmap/mprotect logging'
66040 + default y if GRKERNSEC_CONFIG_AUTO
66041 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66042 + help
66043 + If you say Y here, calls to mmap() and mprotect() with explicit
66044 + usage of PROT_WRITE and PROT_EXEC together will be logged when
66045 + denied by the PAX_MPROTECT feature. This feature will also
66046 + log other problematic scenarios that can occur when PAX_MPROTECT
66047 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
66048 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66049 + is created.
66050 +
66051 +endmenu
66052 +
66053 +menu "Executable Protections"
66054 +depends on GRKERNSEC
66055 +
66056 +config GRKERNSEC_DMESG
66057 + bool "Dmesg(8) restriction"
66058 + default y if GRKERNSEC_CONFIG_AUTO
66059 + help
66060 + If you say Y here, non-root users will not be able to use dmesg(8)
66061 + to view the contents of the kernel's circular log buffer.
66062 + The kernel's log buffer often contains kernel addresses and other
66063 + identifying information useful to an attacker in fingerprinting a
66064 + system for a targeted exploit.
66065 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
66066 + created.
66067 +
66068 +config GRKERNSEC_HARDEN_PTRACE
66069 + bool "Deter ptrace-based process snooping"
66070 + default y if GRKERNSEC_CONFIG_AUTO
66071 + help
66072 + If you say Y here, TTY sniffers and other malicious monitoring
66073 + programs implemented through ptrace will be defeated. If you
66074 + have been using the RBAC system, this option has already been
66075 + enabled for several years for all users, with the ability to make
66076 + fine-grained exceptions.
66077 +
66078 + This option only affects the ability of non-root users to ptrace
66079 + processes that are not a descendent of the ptracing process.
66080 + This means that strace ./binary and gdb ./binary will still work,
66081 + but attaching to arbitrary processes will not. If the sysctl
66082 + option is enabled, a sysctl option with name "harden_ptrace" is
66083 + created.
66084 +
66085 +config GRKERNSEC_PTRACE_READEXEC
66086 + bool "Require read access to ptrace sensitive binaries"
66087 + default y if GRKERNSEC_CONFIG_AUTO
66088 + help
66089 + If you say Y here, unprivileged users will not be able to ptrace unreadable
66090 + binaries. This option is useful in environments that
66091 + remove the read bits (e.g. file mode 4711) from suid binaries to
66092 + prevent infoleaking of their contents. This option adds
66093 + consistency to the use of that file mode, as the binary could normally
66094 + be read out when run without privileges while ptracing.
66095 +
66096 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66097 + is created.
66098 +
66099 +config GRKERNSEC_SETXID
66100 + bool "Enforce consistent multithreaded privileges"
66101 + default y if GRKERNSEC_CONFIG_AUTO
66102 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66103 + help
66104 + If you say Y here, a change from a root uid to a non-root uid
66105 + in a multithreaded application will cause the resulting uids,
66106 + gids, supplementary groups, and capabilities in that thread
66107 + to be propagated to the other threads of the process. In most
66108 + cases this is unnecessary, as glibc will emulate this behavior
66109 + on behalf of the application. Other libcs do not act in the
66110 + same way, allowing the other threads of the process to continue
66111 + running with root privileges. If the sysctl option is enabled,
66112 + a sysctl option with name "consistent_setxid" is created.
66113 +
66114 +config GRKERNSEC_HARDEN_IPC
66115 + bool "Disallow access to overly-permissive IPC objects"
66116 + default y if GRKERNSEC_CONFIG_AUTO
66117 + depends on SYSVIPC
66118 + help
66119 + If you say Y here, access to overly-permissive IPC objects (shared
66120 + memory, message queues, and semaphores) will be denied for processes
66121 + given the following criteria beyond normal permission checks:
66122 + 1) If the IPC object is world-accessible and the euid doesn't match
66123 + that of the creator or current uid for the IPC object
66124 + 2) If the IPC object is group-accessible and the egid doesn't
66125 + match that of the creator or current gid for the IPC object
66126 + It's a common error to grant too much permission to these objects,
66127 + with impact ranging from denial of service and information leaking to
66128 + privilege escalation. This feature was developed in response to
66129 + research by Tim Brown:
66130 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66131 + who found hundreds of such insecure usages. Processes with
66132 + CAP_IPC_OWNER are still permitted to access these IPC objects.
66133 + If the sysctl option is enabled, a sysctl option with name
66134 + "harden_ipc" is created.
66135 +
66136 +config GRKERNSEC_TPE
66137 + bool "Trusted Path Execution (TPE)"
66138 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66139 + help
66140 + If you say Y here, you will be able to choose a gid to add to the
66141 + supplementary groups of users you want to mark as "untrusted."
66142 + These users will not be able to execute any files that are not in
66143 + root-owned directories writable only by root. If the sysctl option
66144 + is enabled, a sysctl option with name "tpe" is created.
66145 +
66146 +config GRKERNSEC_TPE_ALL
66147 + bool "Partially restrict all non-root users"
66148 + depends on GRKERNSEC_TPE
66149 + help
66150 + If you say Y here, all non-root users will be covered under
66151 + a weaker TPE restriction. This is separate from, and in addition to,
66152 + the main TPE options that you have selected elsewhere. Thus, if a
66153 + "trusted" GID is chosen, this restriction applies to even that GID.
66154 + Under this restriction, all non-root users will only be allowed to
66155 + execute files in directories they own that are not group or
66156 + world-writable, or in directories owned by root and writable only by
66157 + root. If the sysctl option is enabled, a sysctl option with name
66158 + "tpe_restrict_all" is created.
66159 +
66160 +config GRKERNSEC_TPE_INVERT
66161 + bool "Invert GID option"
66162 + depends on GRKERNSEC_TPE
66163 + help
66164 + If you say Y here, the group you specify in the TPE configuration will
66165 + decide what group TPE restrictions will be *disabled* for. This
66166 + option is useful if you want TPE restrictions to be applied to most
66167 + users on the system. If the sysctl option is enabled, a sysctl option
66168 + with name "tpe_invert" is created. Unlike other sysctl options, this
66169 + entry will default to on for backward-compatibility.
66170 +
66171 +config GRKERNSEC_TPE_GID
66172 + int
66173 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66174 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66175 +
66176 +config GRKERNSEC_TPE_UNTRUSTED_GID
66177 + int "GID for TPE-untrusted users"
66178 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66179 + default 1005
66180 + help
66181 + Setting this GID determines what group TPE restrictions will be
66182 + *enabled* for. If the sysctl option is enabled, a sysctl option
66183 + with name "tpe_gid" is created.
66184 +
66185 +config GRKERNSEC_TPE_TRUSTED_GID
66186 + int "GID for TPE-trusted users"
66187 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66188 + default 1005
66189 + help
66190 + Setting this GID determines what group TPE restrictions will be
66191 + *disabled* for. If the sysctl option is enabled, a sysctl option
66192 + with name "tpe_gid" is created.
66193 +
66194 +endmenu
66195 +menu "Network Protections"
66196 +depends on GRKERNSEC
66197 +
66198 +config GRKERNSEC_RANDNET
66199 + bool "Larger entropy pools"
66200 + default y if GRKERNSEC_CONFIG_AUTO
66201 + help
66202 + If you say Y here, the entropy pools used for many features of Linux
66203 + and grsecurity will be doubled in size. Since several grsecurity
66204 + features use additional randomness, it is recommended that you say Y
66205 + here. Saying Y here has a similar effect as modifying
66206 + /proc/sys/kernel/random/poolsize.
66207 +
66208 +config GRKERNSEC_BLACKHOLE
66209 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66210 + default y if GRKERNSEC_CONFIG_AUTO
66211 + depends on NET
66212 + help
66213 + If you say Y here, neither TCP resets nor ICMP
66214 + destination-unreachable packets will be sent in response to packets
66215 + sent to ports for which no associated listening process exists.
66216 + This feature supports both IPV4 and IPV6 and exempts the
66217 + loopback interface from blackholing. Enabling this feature
66218 + makes a host more resilient to DoS attacks and reduces network
66219 + visibility against scanners.
66220 +
66221 + The blackhole feature as-implemented is equivalent to the FreeBSD
66222 + blackhole feature, as it prevents RST responses to all packets, not
66223 + just SYNs. Under most application behavior this causes no
66224 + problems, but applications (like haproxy) may not close certain
66225 + connections in a way that cleanly terminates them on the remote
66226 + end, leaving the remote host in LAST_ACK state. Because of this
66227 + side-effect and to prevent intentional LAST_ACK DoSes, this
66228 + feature also adds automatic mitigation against such attacks.
66229 + The mitigation drastically reduces the amount of time a socket
66230 + can spend in LAST_ACK state. If you're using haproxy and not
66231 + all servers it connects to have this option enabled, consider
66232 + disabling this feature on the haproxy host.
66233 +
66234 + If the sysctl option is enabled, two sysctl options with names
66235 + "ip_blackhole" and "lastack_retries" will be created.
66236 + While "ip_blackhole" takes the standard zero/non-zero on/off
66237 + toggle, "lastack_retries" uses the same kinds of values as
66238 + "tcp_retries1" and "tcp_retries2". The default value of 4
66239 + prevents a socket from lasting more than 45 seconds in LAST_ACK
66240 + state.
66241 +
66242 +config GRKERNSEC_NO_SIMULT_CONNECT
66243 + bool "Disable TCP Simultaneous Connect"
66244 + default y if GRKERNSEC_CONFIG_AUTO
66245 + depends on NET
66246 + help
66247 + If you say Y here, a feature by Willy Tarreau will be enabled that
66248 + removes a weakness in Linux's strict implementation of TCP that
66249 + allows two clients to connect to each other without either entering
66250 + a listening state. The weakness allows an attacker to easily prevent
66251 + a client from connecting to a known server provided the source port
66252 + for the connection is guessed correctly.
66253 +
66254 + As the weakness could be used to prevent an antivirus or IPS from
66255 + fetching updates, or prevent an SSL gateway from fetching a CRL,
66256 + it should be eliminated by enabling this option. Though Linux is
66257 + one of few operating systems supporting simultaneous connect, it
66258 + has no legitimate use in practice and is rarely supported by firewalls.
66259 +
66260 +config GRKERNSEC_SOCKET
66261 + bool "Socket restrictions"
66262 + depends on NET
66263 + help
66264 + If you say Y here, you will be able to choose from several options.
66265 + If you assign a GID on your system and add it to the supplementary
66266 + groups of users you want to restrict socket access to, this patch
66267 + will perform up to three things, based on the option(s) you choose.
66268 +
66269 +config GRKERNSEC_SOCKET_ALL
66270 + bool "Deny any sockets to group"
66271 + depends on GRKERNSEC_SOCKET
66272 + help
66273 + If you say Y here, you will be able to choose a GID of whose users will
66274 + be unable to connect to other hosts from your machine or run server
66275 + applications from your machine. If the sysctl option is enabled, a
66276 + sysctl option with name "socket_all" is created.
66277 +
66278 +config GRKERNSEC_SOCKET_ALL_GID
66279 + int "GID to deny all sockets for"
66280 + depends on GRKERNSEC_SOCKET_ALL
66281 + default 1004
66282 + help
66283 + Here you can choose the GID to disable socket access for. Remember to
66284 + add the users you want socket access disabled for to the GID
66285 + specified here. If the sysctl option is enabled, a sysctl option
66286 + with name "socket_all_gid" is created.
66287 +
66288 +config GRKERNSEC_SOCKET_CLIENT
66289 + bool "Deny client sockets to group"
66290 + depends on GRKERNSEC_SOCKET
66291 + help
66292 + If you say Y here, you will be able to choose a GID of whose users will
66293 + be unable to connect to other hosts from your machine, but will be
66294 + able to run servers. If this option is enabled, all users in the group
66295 + you specify will have to use passive mode when initiating ftp transfers
66296 + from the shell on your machine. If the sysctl option is enabled, a
66297 + sysctl option with name "socket_client" is created.
66298 +
66299 +config GRKERNSEC_SOCKET_CLIENT_GID
66300 + int "GID to deny client sockets for"
66301 + depends on GRKERNSEC_SOCKET_CLIENT
66302 + default 1003
66303 + help
66304 + Here you can choose the GID to disable client socket access for.
66305 + Remember to add the users you want client socket access disabled for to
66306 + the GID specified here. If the sysctl option is enabled, a sysctl
66307 + option with name "socket_client_gid" is created.
66308 +
66309 +config GRKERNSEC_SOCKET_SERVER
66310 + bool "Deny server sockets to group"
66311 + depends on GRKERNSEC_SOCKET
66312 + help
66313 + If you say Y here, you will be able to choose a GID of whose users will
66314 + be unable to run server applications from your machine. If the sysctl
66315 + option is enabled, a sysctl option with name "socket_server" is created.
66316 +
66317 +config GRKERNSEC_SOCKET_SERVER_GID
66318 + int "GID to deny server sockets for"
66319 + depends on GRKERNSEC_SOCKET_SERVER
66320 + default 1002
66321 + help
66322 + Here you can choose the GID to disable server socket access for.
66323 + Remember to add the users you want server socket access disabled for to
66324 + the GID specified here. If the sysctl option is enabled, a sysctl
66325 + option with name "socket_server_gid" is created.
66326 +
66327 +endmenu
66328 +
66329 +menu "Physical Protections"
66330 +depends on GRKERNSEC
66331 +
66332 +config GRKERNSEC_DENYUSB
66333 + bool "Deny new USB connections after toggle"
66334 + default y if GRKERNSEC_CONFIG_AUTO
66335 + depends on SYSCTL && USB_SUPPORT
66336 + help
66337 + If you say Y here, a new sysctl option with name "deny_new_usb"
66338 + will be created. Setting its value to 1 will prevent any new
66339 + USB devices from being recognized by the OS. Any attempted USB
66340 + device insertion will be logged. This option is intended to be
66341 + used against custom USB devices designed to exploit vulnerabilities
66342 + in various USB device drivers.
66343 +
66344 + For greatest effectiveness, this sysctl should be set after any
66345 + relevant init scripts. This option is safe to enable in distros
66346 + as each user can choose whether or not to toggle the sysctl.
66347 +
66348 +config GRKERNSEC_DENYUSB_FORCE
66349 + bool "Reject all USB devices not connected at boot"
66350 + select USB
66351 + depends on GRKERNSEC_DENYUSB
66352 + help
66353 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66354 + that doesn't involve a sysctl entry. This option should only be
66355 + enabled if you're sure you want to deny all new USB connections
66356 + at runtime and don't want to modify init scripts. This should not
66357 + be enabled by distros. It forces the core USB code to be built
66358 + into the kernel image so that all devices connected at boot time
66359 + can be recognized and new USB device connections can be prevented
66360 + prior to init running.
66361 +
66362 +endmenu
66363 +
66364 +menu "Sysctl Support"
66365 +depends on GRKERNSEC && SYSCTL
66366 +
66367 +config GRKERNSEC_SYSCTL
66368 + bool "Sysctl support"
66369 + default y if GRKERNSEC_CONFIG_AUTO
66370 + help
66371 + If you say Y here, you will be able to change the options that
66372 + grsecurity runs with at bootup, without having to recompile your
66373 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66374 + to enable (1) or disable (0) various features. All the sysctl entries
66375 + are mutable until the "grsec_lock" entry is set to a non-zero value.
66376 + All features enabled in the kernel configuration are disabled at boot
66377 + if you do not say Y to the "Turn on features by default" option.
66378 + All options should be set at startup, and the grsec_lock entry should
66379 + be set to a non-zero value after all the options are set.
66380 + *THIS IS EXTREMELY IMPORTANT*
66381 +
66382 +config GRKERNSEC_SYSCTL_DISTRO
66383 + bool "Extra sysctl support for distro makers (READ HELP)"
66384 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66385 + help
66386 + If you say Y here, additional sysctl options will be created
66387 + for features that affect processes running as root. Therefore,
66388 + it is critical when using this option that the grsec_lock entry be
66389 + enabled after boot. Only distros with prebuilt kernel packages
66390 + with this option enabled that can ensure grsec_lock is enabled
66391 + after boot should use this option.
66392 + *Failure to set grsec_lock after boot makes all grsec features
66393 + this option covers useless*
66394 +
66395 + Currently this option creates the following sysctl entries:
66396 + "Disable Privileged I/O": "disable_priv_io"
66397 +
66398 +config GRKERNSEC_SYSCTL_ON
66399 + bool "Turn on features by default"
66400 + default y if GRKERNSEC_CONFIG_AUTO
66401 + depends on GRKERNSEC_SYSCTL
66402 + help
66403 + If you say Y here, instead of having all features enabled in the
66404 + kernel configuration disabled at boot time, the features will be
66405 + enabled at boot time. It is recommended you say Y here unless
66406 + there is some reason you would want all sysctl-tunable features to
66407 + be disabled by default. As mentioned elsewhere, it is important
66408 + to enable the grsec_lock entry once you have finished modifying
66409 + the sysctl entries.
66410 +
66411 +endmenu
66412 +menu "Logging Options"
66413 +depends on GRKERNSEC
66414 +
66415 +config GRKERNSEC_FLOODTIME
66416 + int "Seconds in between log messages (minimum)"
66417 + default 10
66418 + help
66419 + This option allows you to enforce the number of seconds between
66420 + grsecurity log messages. The default should be suitable for most
66421 + people, however, if you choose to change it, choose a value small enough
66422 + to allow informative logs to be produced, but large enough to
66423 + prevent flooding.
66424 +
66425 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66426 + any rate limiting on grsecurity log messages.
66427 +
66428 +config GRKERNSEC_FLOODBURST
66429 + int "Number of messages in a burst (maximum)"
66430 + default 6
66431 + help
66432 + This option allows you to choose the maximum number of messages allowed
66433 + within the flood time interval you chose in a separate option. The
66434 + default should be suitable for most people, however if you find that
66435 + many of your logs are being interpreted as flooding, you may want to
66436 + raise this value.
66437 +
66438 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66439 + any rate limiting on grsecurity log messages.
66440 +
66441 +endmenu
66442 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66443 new file mode 100644
66444 index 0000000..5307c8a
66445 --- /dev/null
66446 +++ b/grsecurity/Makefile
66447 @@ -0,0 +1,54 @@
66448 +# grsecurity – access control and security hardening for Linux
66449 +# All code in this directory and various hooks located throughout the Linux kernel are
66450 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66451 +# http://www.grsecurity.net spender@grsecurity.net
66452 +#
66453 +# This program is free software; you can redistribute it and/or
66454 +# modify it under the terms of the GNU General Public License version 2
66455 +# as published by the Free Software Foundation.
66456 +#
66457 +# This program is distributed in the hope that it will be useful,
66458 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
66459 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66460 +# GNU General Public License for more details.
66461 +#
66462 +# You should have received a copy of the GNU General Public License
66463 +# along with this program; if not, write to the Free Software
66464 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66465 +
66466 +KBUILD_CFLAGS += -Werror
66467 +
66468 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66469 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
66470 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66471 + grsec_usb.o grsec_ipc.o
66472 +
66473 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66474 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66475 + gracl_learn.o grsec_log.o gracl_policy.o
66476 +ifdef CONFIG_COMPAT
66477 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66478 +endif
66479 +
66480 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66481 +
66482 +ifdef CONFIG_NET
66483 +obj-y += grsec_sock.o
66484 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66485 +endif
66486 +
66487 +ifndef CONFIG_GRKERNSEC
66488 +obj-y += grsec_disabled.o
66489 +endif
66490 +
66491 +ifdef CONFIG_GRKERNSEC_HIDESYM
66492 +extra-y := grsec_hidesym.o
66493 +$(obj)/grsec_hidesym.o:
66494 + @-chmod -f 500 /boot
66495 + @-chmod -f 500 /lib/modules
66496 + @-chmod -f 500 /lib64/modules
66497 + @-chmod -f 500 /lib32/modules
66498 + @-chmod -f 700 .
66499 + @-chmod -f 700 $(objtree)
66500 + @echo ' grsec: protected kernel image paths'
66501 +endif
66502 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66503 new file mode 100644
66504 index 0000000..e56396f
66505 --- /dev/null
66506 +++ b/grsecurity/gracl.c
66507 @@ -0,0 +1,2679 @@
66508 +#include <linux/kernel.h>
66509 +#include <linux/module.h>
66510 +#include <linux/sched.h>
66511 +#include <linux/mm.h>
66512 +#include <linux/file.h>
66513 +#include <linux/fs.h>
66514 +#include <linux/namei.h>
66515 +#include <linux/mount.h>
66516 +#include <linux/tty.h>
66517 +#include <linux/proc_fs.h>
66518 +#include <linux/lglock.h>
66519 +#include <linux/slab.h>
66520 +#include <linux/vmalloc.h>
66521 +#include <linux/types.h>
66522 +#include <linux/sysctl.h>
66523 +#include <linux/netdevice.h>
66524 +#include <linux/ptrace.h>
66525 +#include <linux/gracl.h>
66526 +#include <linux/gralloc.h>
66527 +#include <linux/security.h>
66528 +#include <linux/grinternal.h>
66529 +#include <linux/pid_namespace.h>
66530 +#include <linux/stop_machine.h>
66531 +#include <linux/fdtable.h>
66532 +#include <linux/percpu.h>
66533 +#include <linux/lglock.h>
66534 +#include <linux/hugetlb.h>
66535 +#include <linux/posix-timers.h>
66536 +#include <linux/prefetch.h>
66537 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66538 +#include <linux/magic.h>
66539 +#include <linux/pagemap.h>
66540 +#include "../fs/btrfs/async-thread.h"
66541 +#include "../fs/btrfs/ctree.h"
66542 +#include "../fs/btrfs/btrfs_inode.h"
66543 +#endif
66544 +#include "../fs/mount.h"
66545 +
66546 +#include <asm/uaccess.h>
66547 +#include <asm/errno.h>
66548 +#include <asm/mman.h>
66549 +
66550 +#define FOR_EACH_ROLE_START(role) \
66551 + role = running_polstate.role_list; \
66552 + while (role) {
66553 +
66554 +#define FOR_EACH_ROLE_END(role) \
66555 + role = role->prev; \
66556 + }
66557 +
66558 +extern struct path gr_real_root;
66559 +
66560 +static struct gr_policy_state running_polstate;
66561 +struct gr_policy_state *polstate = &running_polstate;
66562 +extern struct gr_alloc_state *current_alloc_state;
66563 +
66564 +extern char *gr_shared_page[4];
66565 +DEFINE_RWLOCK(gr_inode_lock);
66566 +
66567 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
66568 +
66569 +#ifdef CONFIG_NET
66570 +extern struct vfsmount *sock_mnt;
66571 +#endif
66572 +
66573 +extern struct vfsmount *pipe_mnt;
66574 +extern struct vfsmount *shm_mnt;
66575 +
66576 +#ifdef CONFIG_HUGETLBFS
66577 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66578 +#endif
66579 +
66580 +extern u16 acl_sp_role_value;
66581 +extern struct acl_object_label *fakefs_obj_rw;
66582 +extern struct acl_object_label *fakefs_obj_rwx;
66583 +
66584 +int gr_acl_is_enabled(void)
66585 +{
66586 + return (gr_status & GR_READY);
66587 +}
66588 +
66589 +void gr_enable_rbac_system(void)
66590 +{
66591 + pax_open_kernel();
66592 + gr_status |= GR_READY;
66593 + pax_close_kernel();
66594 +}
66595 +
66596 +int gr_rbac_disable(void *unused)
66597 +{
66598 + pax_open_kernel();
66599 + gr_status &= ~GR_READY;
66600 + pax_close_kernel();
66601 +
66602 + return 0;
66603 +}
66604 +
66605 +static inline dev_t __get_dev(const struct dentry *dentry)
66606 +{
66607 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66608 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66609 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
66610 + else
66611 +#endif
66612 + return dentry->d_sb->s_dev;
66613 +}
66614 +
66615 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66616 +{
66617 + return __get_dev(dentry);
66618 +}
66619 +
66620 +static char gr_task_roletype_to_char(struct task_struct *task)
66621 +{
66622 + switch (task->role->roletype &
66623 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66624 + GR_ROLE_SPECIAL)) {
66625 + case GR_ROLE_DEFAULT:
66626 + return 'D';
66627 + case GR_ROLE_USER:
66628 + return 'U';
66629 + case GR_ROLE_GROUP:
66630 + return 'G';
66631 + case GR_ROLE_SPECIAL:
66632 + return 'S';
66633 + }
66634 +
66635 + return 'X';
66636 +}
66637 +
66638 +char gr_roletype_to_char(void)
66639 +{
66640 + return gr_task_roletype_to_char(current);
66641 +}
66642 +
66643 +__inline__ int
66644 +gr_acl_tpe_check(void)
66645 +{
66646 + if (unlikely(!(gr_status & GR_READY)))
66647 + return 0;
66648 + if (current->role->roletype & GR_ROLE_TPE)
66649 + return 1;
66650 + else
66651 + return 0;
66652 +}
66653 +
66654 +int
66655 +gr_handle_rawio(const struct inode *inode)
66656 +{
66657 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66658 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66659 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66660 + !capable(CAP_SYS_RAWIO))
66661 + return 1;
66662 +#endif
66663 + return 0;
66664 +}
66665 +
66666 +int
66667 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66668 +{
66669 + if (likely(lena != lenb))
66670 + return 0;
66671 +
66672 + return !memcmp(a, b, lena);
66673 +}
66674 +
66675 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66676 +{
66677 + *buflen -= namelen;
66678 + if (*buflen < 0)
66679 + return -ENAMETOOLONG;
66680 + *buffer -= namelen;
66681 + memcpy(*buffer, str, namelen);
66682 + return 0;
66683 +}
66684 +
66685 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66686 +{
66687 + return prepend(buffer, buflen, name->name, name->len);
66688 +}
66689 +
66690 +static int prepend_path(const struct path *path, struct path *root,
66691 + char **buffer, int *buflen)
66692 +{
66693 + struct dentry *dentry = path->dentry;
66694 + struct vfsmount *vfsmnt = path->mnt;
66695 + struct mount *mnt = real_mount(vfsmnt);
66696 + bool slash = false;
66697 + int error = 0;
66698 +
66699 + while (dentry != root->dentry || vfsmnt != root->mnt) {
66700 + struct dentry * parent;
66701 +
66702 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66703 + /* Global root? */
66704 + if (!mnt_has_parent(mnt)) {
66705 + goto out;
66706 + }
66707 + dentry = mnt->mnt_mountpoint;
66708 + mnt = mnt->mnt_parent;
66709 + vfsmnt = &mnt->mnt;
66710 + continue;
66711 + }
66712 + parent = dentry->d_parent;
66713 + prefetch(parent);
66714 + spin_lock(&dentry->d_lock);
66715 + error = prepend_name(buffer, buflen, &dentry->d_name);
66716 + spin_unlock(&dentry->d_lock);
66717 + if (!error)
66718 + error = prepend(buffer, buflen, "/", 1);
66719 + if (error)
66720 + break;
66721 +
66722 + slash = true;
66723 + dentry = parent;
66724 + }
66725 +
66726 +out:
66727 + if (!error && !slash)
66728 + error = prepend(buffer, buflen, "/", 1);
66729 +
66730 + return error;
66731 +}
66732 +
66733 +/* this must be called with mount_lock and rename_lock held */
66734 +
66735 +static char *__our_d_path(const struct path *path, struct path *root,
66736 + char *buf, int buflen)
66737 +{
66738 + char *res = buf + buflen;
66739 + int error;
66740 +
66741 + prepend(&res, &buflen, "\0", 1);
66742 + error = prepend_path(path, root, &res, &buflen);
66743 + if (error)
66744 + return ERR_PTR(error);
66745 +
66746 + return res;
66747 +}
66748 +
66749 +static char *
66750 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66751 +{
66752 + char *retval;
66753 +
66754 + retval = __our_d_path(path, root, buf, buflen);
66755 + if (unlikely(IS_ERR(retval)))
66756 + retval = strcpy(buf, "<path too long>");
66757 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66758 + retval[1] = '\0';
66759 +
66760 + return retval;
66761 +}
66762 +
66763 +static char *
66764 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66765 + char *buf, int buflen)
66766 +{
66767 + struct path path;
66768 + char *res;
66769 +
66770 + path.dentry = (struct dentry *)dentry;
66771 + path.mnt = (struct vfsmount *)vfsmnt;
66772 +
66773 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66774 + by the RBAC system */
66775 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
66776 +
66777 + return res;
66778 +}
66779 +
66780 +static char *
66781 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66782 + char *buf, int buflen)
66783 +{
66784 + char *res;
66785 + struct path path;
66786 + struct path root;
66787 + struct task_struct *reaper = init_pid_ns.child_reaper;
66788 +
66789 + path.dentry = (struct dentry *)dentry;
66790 + path.mnt = (struct vfsmount *)vfsmnt;
66791 +
66792 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66793 + get_fs_root(reaper->fs, &root);
66794 +
66795 + read_seqlock_excl(&mount_lock);
66796 + write_seqlock(&rename_lock);
66797 + res = gen_full_path(&path, &root, buf, buflen);
66798 + write_sequnlock(&rename_lock);
66799 + read_sequnlock_excl(&mount_lock);
66800 +
66801 + path_put(&root);
66802 + return res;
66803 +}
66804 +
66805 +char *
66806 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66807 +{
66808 + char *ret;
66809 + read_seqlock_excl(&mount_lock);
66810 + write_seqlock(&rename_lock);
66811 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66812 + PAGE_SIZE);
66813 + write_sequnlock(&rename_lock);
66814 + read_sequnlock_excl(&mount_lock);
66815 + return ret;
66816 +}
66817 +
66818 +static char *
66819 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66820 +{
66821 + char *ret;
66822 + char *buf;
66823 + int buflen;
66824 +
66825 + read_seqlock_excl(&mount_lock);
66826 + write_seqlock(&rename_lock);
66827 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66828 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66829 + buflen = (int)(ret - buf);
66830 + if (buflen >= 5)
66831 + prepend(&ret, &buflen, "/proc", 5);
66832 + else
66833 + ret = strcpy(buf, "<path too long>");
66834 + write_sequnlock(&rename_lock);
66835 + read_sequnlock_excl(&mount_lock);
66836 + return ret;
66837 +}
66838 +
66839 +char *
66840 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66841 +{
66842 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66843 + PAGE_SIZE);
66844 +}
66845 +
66846 +char *
66847 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66848 +{
66849 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66850 + PAGE_SIZE);
66851 +}
66852 +
66853 +char *
66854 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66855 +{
66856 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66857 + PAGE_SIZE);
66858 +}
66859 +
66860 +char *
66861 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66862 +{
66863 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66864 + PAGE_SIZE);
66865 +}
66866 +
66867 +char *
66868 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66869 +{
66870 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66871 + PAGE_SIZE);
66872 +}
66873 +
66874 +__inline__ __u32
66875 +to_gr_audit(const __u32 reqmode)
66876 +{
66877 + /* masks off auditable permission flags, then shifts them to create
66878 + auditing flags, and adds the special case of append auditing if
66879 + we're requesting write */
66880 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66881 +}
66882 +
66883 +struct acl_role_label *
66884 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66885 + const gid_t gid)
66886 +{
66887 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66888 + struct acl_role_label *match;
66889 + struct role_allowed_ip *ipp;
66890 + unsigned int x;
66891 + u32 curr_ip = task->signal->saved_ip;
66892 +
66893 + match = state->acl_role_set.r_hash[index];
66894 +
66895 + while (match) {
66896 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66897 + for (x = 0; x < match->domain_child_num; x++) {
66898 + if (match->domain_children[x] == uid)
66899 + goto found;
66900 + }
66901 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66902 + break;
66903 + match = match->next;
66904 + }
66905 +found:
66906 + if (match == NULL) {
66907 + try_group:
66908 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
66909 + match = state->acl_role_set.r_hash[index];
66910 +
66911 + while (match) {
66912 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
66913 + for (x = 0; x < match->domain_child_num; x++) {
66914 + if (match->domain_children[x] == gid)
66915 + goto found2;
66916 + }
66917 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
66918 + break;
66919 + match = match->next;
66920 + }
66921 +found2:
66922 + if (match == NULL)
66923 + match = state->default_role;
66924 + if (match->allowed_ips == NULL)
66925 + return match;
66926 + else {
66927 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66928 + if (likely
66929 + ((ntohl(curr_ip) & ipp->netmask) ==
66930 + (ntohl(ipp->addr) & ipp->netmask)))
66931 + return match;
66932 + }
66933 + match = state->default_role;
66934 + }
66935 + } else if (match->allowed_ips == NULL) {
66936 + return match;
66937 + } else {
66938 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66939 + if (likely
66940 + ((ntohl(curr_ip) & ipp->netmask) ==
66941 + (ntohl(ipp->addr) & ipp->netmask)))
66942 + return match;
66943 + }
66944 + goto try_group;
66945 + }
66946 +
66947 + return match;
66948 +}
66949 +
66950 +static struct acl_role_label *
66951 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
66952 + const gid_t gid)
66953 +{
66954 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
66955 +}
66956 +
66957 +struct acl_subject_label *
66958 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
66959 + const struct acl_role_label *role)
66960 +{
66961 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66962 + struct acl_subject_label *match;
66963 +
66964 + match = role->subj_hash[index];
66965 +
66966 + while (match && (match->inode != ino || match->device != dev ||
66967 + (match->mode & GR_DELETED))) {
66968 + match = match->next;
66969 + }
66970 +
66971 + if (match && !(match->mode & GR_DELETED))
66972 + return match;
66973 + else
66974 + return NULL;
66975 +}
66976 +
66977 +struct acl_subject_label *
66978 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
66979 + const struct acl_role_label *role)
66980 +{
66981 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66982 + struct acl_subject_label *match;
66983 +
66984 + match = role->subj_hash[index];
66985 +
66986 + while (match && (match->inode != ino || match->device != dev ||
66987 + !(match->mode & GR_DELETED))) {
66988 + match = match->next;
66989 + }
66990 +
66991 + if (match && (match->mode & GR_DELETED))
66992 + return match;
66993 + else
66994 + return NULL;
66995 +}
66996 +
66997 +static struct acl_object_label *
66998 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
66999 + const struct acl_subject_label *subj)
67000 +{
67001 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67002 + struct acl_object_label *match;
67003 +
67004 + match = subj->obj_hash[index];
67005 +
67006 + while (match && (match->inode != ino || match->device != dev ||
67007 + (match->mode & GR_DELETED))) {
67008 + match = match->next;
67009 + }
67010 +
67011 + if (match && !(match->mode & GR_DELETED))
67012 + return match;
67013 + else
67014 + return NULL;
67015 +}
67016 +
67017 +static struct acl_object_label *
67018 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67019 + const struct acl_subject_label *subj)
67020 +{
67021 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67022 + struct acl_object_label *match;
67023 +
67024 + match = subj->obj_hash[index];
67025 +
67026 + while (match && (match->inode != ino || match->device != dev ||
67027 + !(match->mode & GR_DELETED))) {
67028 + match = match->next;
67029 + }
67030 +
67031 + if (match && (match->mode & GR_DELETED))
67032 + return match;
67033 +
67034 + match = subj->obj_hash[index];
67035 +
67036 + while (match && (match->inode != ino || match->device != dev ||
67037 + (match->mode & GR_DELETED))) {
67038 + match = match->next;
67039 + }
67040 +
67041 + if (match && !(match->mode & GR_DELETED))
67042 + return match;
67043 + else
67044 + return NULL;
67045 +}
67046 +
67047 +struct name_entry *
67048 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67049 +{
67050 + unsigned int len = strlen(name);
67051 + unsigned int key = full_name_hash(name, len);
67052 + unsigned int index = key % state->name_set.n_size;
67053 + struct name_entry *match;
67054 +
67055 + match = state->name_set.n_hash[index];
67056 +
67057 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67058 + match = match->next;
67059 +
67060 + return match;
67061 +}
67062 +
67063 +static struct name_entry *
67064 +lookup_name_entry(const char *name)
67065 +{
67066 + return __lookup_name_entry(&running_polstate, name);
67067 +}
67068 +
67069 +static struct name_entry *
67070 +lookup_name_entry_create(const char *name)
67071 +{
67072 + unsigned int len = strlen(name);
67073 + unsigned int key = full_name_hash(name, len);
67074 + unsigned int index = key % running_polstate.name_set.n_size;
67075 + struct name_entry *match;
67076 +
67077 + match = running_polstate.name_set.n_hash[index];
67078 +
67079 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67080 + !match->deleted))
67081 + match = match->next;
67082 +
67083 + if (match && match->deleted)
67084 + return match;
67085 +
67086 + match = running_polstate.name_set.n_hash[index];
67087 +
67088 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67089 + match->deleted))
67090 + match = match->next;
67091 +
67092 + if (match && !match->deleted)
67093 + return match;
67094 + else
67095 + return NULL;
67096 +}
67097 +
67098 +static struct inodev_entry *
67099 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
67100 +{
67101 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67102 + struct inodev_entry *match;
67103 +
67104 + match = running_polstate.inodev_set.i_hash[index];
67105 +
67106 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67107 + match = match->next;
67108 +
67109 + return match;
67110 +}
67111 +
67112 +void
67113 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67114 +{
67115 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67116 + state->inodev_set.i_size);
67117 + struct inodev_entry **curr;
67118 +
67119 + entry->prev = NULL;
67120 +
67121 + curr = &state->inodev_set.i_hash[index];
67122 + if (*curr != NULL)
67123 + (*curr)->prev = entry;
67124 +
67125 + entry->next = *curr;
67126 + *curr = entry;
67127 +
67128 + return;
67129 +}
67130 +
67131 +static void
67132 +insert_inodev_entry(struct inodev_entry *entry)
67133 +{
67134 + __insert_inodev_entry(&running_polstate, entry);
67135 +}
67136 +
67137 +void
67138 +insert_acl_obj_label(struct acl_object_label *obj,
67139 + struct acl_subject_label *subj)
67140 +{
67141 + unsigned int index =
67142 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67143 + struct acl_object_label **curr;
67144 +
67145 + obj->prev = NULL;
67146 +
67147 + curr = &subj->obj_hash[index];
67148 + if (*curr != NULL)
67149 + (*curr)->prev = obj;
67150 +
67151 + obj->next = *curr;
67152 + *curr = obj;
67153 +
67154 + return;
67155 +}
67156 +
67157 +void
67158 +insert_acl_subj_label(struct acl_subject_label *obj,
67159 + struct acl_role_label *role)
67160 +{
67161 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67162 + struct acl_subject_label **curr;
67163 +
67164 + obj->prev = NULL;
67165 +
67166 + curr = &role->subj_hash[index];
67167 + if (*curr != NULL)
67168 + (*curr)->prev = obj;
67169 +
67170 + obj->next = *curr;
67171 + *curr = obj;
67172 +
67173 + return;
67174 +}
67175 +
67176 +/* derived from glibc fnmatch() 0: match, 1: no match*/
67177 +
67178 +static int
67179 +glob_match(const char *p, const char *n)
67180 +{
67181 + char c;
67182 +
67183 + while ((c = *p++) != '\0') {
67184 + switch (c) {
67185 + case '?':
67186 + if (*n == '\0')
67187 + return 1;
67188 + else if (*n == '/')
67189 + return 1;
67190 + break;
67191 + case '\\':
67192 + if (*n != c)
67193 + return 1;
67194 + break;
67195 + case '*':
67196 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
67197 + if (*n == '/')
67198 + return 1;
67199 + else if (c == '?') {
67200 + if (*n == '\0')
67201 + return 1;
67202 + else
67203 + ++n;
67204 + }
67205 + }
67206 + if (c == '\0') {
67207 + return 0;
67208 + } else {
67209 + const char *endp;
67210 +
67211 + if ((endp = strchr(n, '/')) == NULL)
67212 + endp = n + strlen(n);
67213 +
67214 + if (c == '[') {
67215 + for (--p; n < endp; ++n)
67216 + if (!glob_match(p, n))
67217 + return 0;
67218 + } else if (c == '/') {
67219 + while (*n != '\0' && *n != '/')
67220 + ++n;
67221 + if (*n == '/' && !glob_match(p, n + 1))
67222 + return 0;
67223 + } else {
67224 + for (--p; n < endp; ++n)
67225 + if (*n == c && !glob_match(p, n))
67226 + return 0;
67227 + }
67228 +
67229 + return 1;
67230 + }
67231 + case '[':
67232 + {
67233 + int not;
67234 + char cold;
67235 +
67236 + if (*n == '\0' || *n == '/')
67237 + return 1;
67238 +
67239 + not = (*p == '!' || *p == '^');
67240 + if (not)
67241 + ++p;
67242 +
67243 + c = *p++;
67244 + for (;;) {
67245 + unsigned char fn = (unsigned char)*n;
67246 +
67247 + if (c == '\0')
67248 + return 1;
67249 + else {
67250 + if (c == fn)
67251 + goto matched;
67252 + cold = c;
67253 + c = *p++;
67254 +
67255 + if (c == '-' && *p != ']') {
67256 + unsigned char cend = *p++;
67257 +
67258 + if (cend == '\0')
67259 + return 1;
67260 +
67261 + if (cold <= fn && fn <= cend)
67262 + goto matched;
67263 +
67264 + c = *p++;
67265 + }
67266 + }
67267 +
67268 + if (c == ']')
67269 + break;
67270 + }
67271 + if (!not)
67272 + return 1;
67273 + break;
67274 + matched:
67275 + while (c != ']') {
67276 + if (c == '\0')
67277 + return 1;
67278 +
67279 + c = *p++;
67280 + }
67281 + if (not)
67282 + return 1;
67283 + }
67284 + break;
67285 + default:
67286 + if (c != *n)
67287 + return 1;
67288 + }
67289 +
67290 + ++n;
67291 + }
67292 +
67293 + if (*n == '\0')
67294 + return 0;
67295 +
67296 + if (*n == '/')
67297 + return 0;
67298 +
67299 + return 1;
67300 +}
67301 +
67302 +static struct acl_object_label *
67303 +chk_glob_label(struct acl_object_label *globbed,
67304 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67305 +{
67306 + struct acl_object_label *tmp;
67307 +
67308 + if (*path == NULL)
67309 + *path = gr_to_filename_nolock(dentry, mnt);
67310 +
67311 + tmp = globbed;
67312 +
67313 + while (tmp) {
67314 + if (!glob_match(tmp->filename, *path))
67315 + return tmp;
67316 + tmp = tmp->next;
67317 + }
67318 +
67319 + return NULL;
67320 +}
67321 +
67322 +static struct acl_object_label *
67323 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67324 + const ino_t curr_ino, const dev_t curr_dev,
67325 + const struct acl_subject_label *subj, char **path, const int checkglob)
67326 +{
67327 + struct acl_subject_label *tmpsubj;
67328 + struct acl_object_label *retval;
67329 + struct acl_object_label *retval2;
67330 +
67331 + tmpsubj = (struct acl_subject_label *) subj;
67332 + read_lock(&gr_inode_lock);
67333 + do {
67334 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67335 + if (retval) {
67336 + if (checkglob && retval->globbed) {
67337 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67338 + if (retval2)
67339 + retval = retval2;
67340 + }
67341 + break;
67342 + }
67343 + } while ((tmpsubj = tmpsubj->parent_subject));
67344 + read_unlock(&gr_inode_lock);
67345 +
67346 + return retval;
67347 +}
67348 +
67349 +static __inline__ struct acl_object_label *
67350 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67351 + struct dentry *curr_dentry,
67352 + const struct acl_subject_label *subj, char **path, const int checkglob)
67353 +{
67354 + int newglob = checkglob;
67355 + ino_t inode;
67356 + dev_t device;
67357 +
67358 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67359 + as we don't want a / * rule to match instead of the / object
67360 + don't do this for create lookups that call this function though, since they're looking up
67361 + on the parent and thus need globbing checks on all paths
67362 + */
67363 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67364 + newglob = GR_NO_GLOB;
67365 +
67366 + spin_lock(&curr_dentry->d_lock);
67367 + inode = curr_dentry->d_inode->i_ino;
67368 + device = __get_dev(curr_dentry);
67369 + spin_unlock(&curr_dentry->d_lock);
67370 +
67371 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67372 +}
67373 +
67374 +#ifdef CONFIG_HUGETLBFS
67375 +static inline bool
67376 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
67377 +{
67378 + int i;
67379 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67380 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67381 + return true;
67382 + }
67383 +
67384 + return false;
67385 +}
67386 +#endif
67387 +
67388 +static struct acl_object_label *
67389 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67390 + const struct acl_subject_label *subj, char *path, const int checkglob)
67391 +{
67392 + struct dentry *dentry = (struct dentry *) l_dentry;
67393 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67394 + struct mount *real_mnt = real_mount(mnt);
67395 + struct acl_object_label *retval;
67396 + struct dentry *parent;
67397 +
67398 + read_seqlock_excl(&mount_lock);
67399 + write_seqlock(&rename_lock);
67400 +
67401 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67402 +#ifdef CONFIG_NET
67403 + mnt == sock_mnt ||
67404 +#endif
67405 +#ifdef CONFIG_HUGETLBFS
67406 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67407 +#endif
67408 + /* ignore Eric Biederman */
67409 + IS_PRIVATE(l_dentry->d_inode))) {
67410 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67411 + goto out;
67412 + }
67413 +
67414 + for (;;) {
67415 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67416 + break;
67417 +
67418 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67419 + if (!mnt_has_parent(real_mnt))
67420 + break;
67421 +
67422 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67423 + if (retval != NULL)
67424 + goto out;
67425 +
67426 + dentry = real_mnt->mnt_mountpoint;
67427 + real_mnt = real_mnt->mnt_parent;
67428 + mnt = &real_mnt->mnt;
67429 + continue;
67430 + }
67431 +
67432 + parent = dentry->d_parent;
67433 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67434 + if (retval != NULL)
67435 + goto out;
67436 +
67437 + dentry = parent;
67438 + }
67439 +
67440 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67441 +
67442 + /* gr_real_root is pinned so we don't have to hold a reference */
67443 + if (retval == NULL)
67444 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67445 +out:
67446 + write_sequnlock(&rename_lock);
67447 + read_sequnlock_excl(&mount_lock);
67448 +
67449 + BUG_ON(retval == NULL);
67450 +
67451 + return retval;
67452 +}
67453 +
67454 +static __inline__ struct acl_object_label *
67455 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67456 + const struct acl_subject_label *subj)
67457 +{
67458 + char *path = NULL;
67459 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67460 +}
67461 +
67462 +static __inline__ struct acl_object_label *
67463 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67464 + const struct acl_subject_label *subj)
67465 +{
67466 + char *path = NULL;
67467 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67468 +}
67469 +
67470 +static __inline__ struct acl_object_label *
67471 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67472 + const struct acl_subject_label *subj, char *path)
67473 +{
67474 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67475 +}
67476 +
67477 +struct acl_subject_label *
67478 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67479 + const struct acl_role_label *role)
67480 +{
67481 + struct dentry *dentry = (struct dentry *) l_dentry;
67482 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67483 + struct mount *real_mnt = real_mount(mnt);
67484 + struct acl_subject_label *retval;
67485 + struct dentry *parent;
67486 +
67487 + read_seqlock_excl(&mount_lock);
67488 + write_seqlock(&rename_lock);
67489 +
67490 + for (;;) {
67491 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67492 + break;
67493 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67494 + if (!mnt_has_parent(real_mnt))
67495 + break;
67496 +
67497 + spin_lock(&dentry->d_lock);
67498 + read_lock(&gr_inode_lock);
67499 + retval =
67500 + lookup_acl_subj_label(dentry->d_inode->i_ino,
67501 + __get_dev(dentry), role);
67502 + read_unlock(&gr_inode_lock);
67503 + spin_unlock(&dentry->d_lock);
67504 + if (retval != NULL)
67505 + goto out;
67506 +
67507 + dentry = real_mnt->mnt_mountpoint;
67508 + real_mnt = real_mnt->mnt_parent;
67509 + mnt = &real_mnt->mnt;
67510 + continue;
67511 + }
67512 +
67513 + spin_lock(&dentry->d_lock);
67514 + read_lock(&gr_inode_lock);
67515 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67516 + __get_dev(dentry), role);
67517 + read_unlock(&gr_inode_lock);
67518 + parent = dentry->d_parent;
67519 + spin_unlock(&dentry->d_lock);
67520 +
67521 + if (retval != NULL)
67522 + goto out;
67523 +
67524 + dentry = parent;
67525 + }
67526 +
67527 + spin_lock(&dentry->d_lock);
67528 + read_lock(&gr_inode_lock);
67529 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67530 + __get_dev(dentry), role);
67531 + read_unlock(&gr_inode_lock);
67532 + spin_unlock(&dentry->d_lock);
67533 +
67534 + if (unlikely(retval == NULL)) {
67535 + /* gr_real_root is pinned, we don't need to hold a reference */
67536 + read_lock(&gr_inode_lock);
67537 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67538 + __get_dev(gr_real_root.dentry), role);
67539 + read_unlock(&gr_inode_lock);
67540 + }
67541 +out:
67542 + write_sequnlock(&rename_lock);
67543 + read_sequnlock_excl(&mount_lock);
67544 +
67545 + BUG_ON(retval == NULL);
67546 +
67547 + return retval;
67548 +}
67549 +
67550 +void
67551 +assign_special_role(const char *rolename)
67552 +{
67553 + struct acl_object_label *obj;
67554 + struct acl_role_label *r;
67555 + struct acl_role_label *assigned = NULL;
67556 + struct task_struct *tsk;
67557 + struct file *filp;
67558 +
67559 + FOR_EACH_ROLE_START(r)
67560 + if (!strcmp(rolename, r->rolename) &&
67561 + (r->roletype & GR_ROLE_SPECIAL)) {
67562 + assigned = r;
67563 + break;
67564 + }
67565 + FOR_EACH_ROLE_END(r)
67566 +
67567 + if (!assigned)
67568 + return;
67569 +
67570 + read_lock(&tasklist_lock);
67571 + read_lock(&grsec_exec_file_lock);
67572 +
67573 + tsk = current->real_parent;
67574 + if (tsk == NULL)
67575 + goto out_unlock;
67576 +
67577 + filp = tsk->exec_file;
67578 + if (filp == NULL)
67579 + goto out_unlock;
67580 +
67581 + tsk->is_writable = 0;
67582 + tsk->inherited = 0;
67583 +
67584 + tsk->acl_sp_role = 1;
67585 + tsk->acl_role_id = ++acl_sp_role_value;
67586 + tsk->role = assigned;
67587 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67588 +
67589 + /* ignore additional mmap checks for processes that are writable
67590 + by the default ACL */
67591 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67592 + if (unlikely(obj->mode & GR_WRITE))
67593 + tsk->is_writable = 1;
67594 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67595 + if (unlikely(obj->mode & GR_WRITE))
67596 + tsk->is_writable = 1;
67597 +
67598 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67599 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67600 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67601 +#endif
67602 +
67603 +out_unlock:
67604 + read_unlock(&grsec_exec_file_lock);
67605 + read_unlock(&tasklist_lock);
67606 + return;
67607 +}
67608 +
67609 +
67610 +static void
67611 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67612 +{
67613 + struct task_struct *task = current;
67614 + const struct cred *cred = current_cred();
67615 +
67616 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67617 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67618 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67619 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67620 +
67621 + return;
67622 +}
67623 +
67624 +static void
67625 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67626 +{
67627 + struct task_struct *task = current;
67628 + const struct cred *cred = current_cred();
67629 +
67630 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67631 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67632 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67633 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67634 +
67635 + return;
67636 +}
67637 +
67638 +static void
67639 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67640 +{
67641 + struct task_struct *task = current;
67642 + const struct cred *cred = current_cred();
67643 +
67644 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67645 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67646 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67647 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67648 +
67649 + return;
67650 +}
67651 +
67652 +static void
67653 +gr_set_proc_res(struct task_struct *task)
67654 +{
67655 + struct acl_subject_label *proc;
67656 + unsigned short i;
67657 +
67658 + proc = task->acl;
67659 +
67660 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67661 + return;
67662 +
67663 + for (i = 0; i < RLIM_NLIMITS; i++) {
67664 + if (!(proc->resmask & (1U << i)))
67665 + continue;
67666 +
67667 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67668 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67669 +
67670 + if (i == RLIMIT_CPU)
67671 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
67672 + }
67673 +
67674 + return;
67675 +}
67676 +
67677 +/* both of the below must be called with
67678 + rcu_read_lock();
67679 + read_lock(&tasklist_lock);
67680 + read_lock(&grsec_exec_file_lock);
67681 +*/
67682 +
67683 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67684 +{
67685 + char *tmpname;
67686 + struct acl_subject_label *tmpsubj;
67687 + struct file *filp;
67688 + struct name_entry *nmatch;
67689 +
67690 + filp = task->exec_file;
67691 + if (filp == NULL)
67692 + return NULL;
67693 +
67694 + /* the following is to apply the correct subject
67695 + on binaries running when the RBAC system
67696 + is enabled, when the binaries have been
67697 + replaced or deleted since their execution
67698 + -----
67699 + when the RBAC system starts, the inode/dev
67700 + from exec_file will be one the RBAC system
67701 + is unaware of. It only knows the inode/dev
67702 + of the present file on disk, or the absence
67703 + of it.
67704 + */
67705 +
67706 + if (filename)
67707 + nmatch = __lookup_name_entry(state, filename);
67708 + else {
67709 + preempt_disable();
67710 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67711 +
67712 + nmatch = __lookup_name_entry(state, tmpname);
67713 + preempt_enable();
67714 + }
67715 + tmpsubj = NULL;
67716 + if (nmatch) {
67717 + if (nmatch->deleted)
67718 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67719 + else
67720 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67721 + }
67722 + /* this also works for the reload case -- if we don't match a potentially inherited subject
67723 + then we fall back to a normal lookup based on the binary's ino/dev
67724 + */
67725 + if (tmpsubj == NULL)
67726 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67727 +
67728 + return tmpsubj;
67729 +}
67730 +
67731 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67732 +{
67733 + return __gr_get_subject_for_task(&running_polstate, task, filename);
67734 +}
67735 +
67736 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67737 +{
67738 + struct acl_object_label *obj;
67739 + struct file *filp;
67740 +
67741 + filp = task->exec_file;
67742 +
67743 + task->acl = subj;
67744 + task->is_writable = 0;
67745 + /* ignore additional mmap checks for processes that are writable
67746 + by the default ACL */
67747 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67748 + if (unlikely(obj->mode & GR_WRITE))
67749 + task->is_writable = 1;
67750 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67751 + if (unlikely(obj->mode & GR_WRITE))
67752 + task->is_writable = 1;
67753 +
67754 + gr_set_proc_res(task);
67755 +
67756 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67757 + 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);
67758 +#endif
67759 +}
67760 +
67761 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67762 +{
67763 + __gr_apply_subject_to_task(&running_polstate, task, subj);
67764 +}
67765 +
67766 +__u32
67767 +gr_search_file(const struct dentry * dentry, const __u32 mode,
67768 + const struct vfsmount * mnt)
67769 +{
67770 + __u32 retval = mode;
67771 + struct acl_subject_label *curracl;
67772 + struct acl_object_label *currobj;
67773 +
67774 + if (unlikely(!(gr_status & GR_READY)))
67775 + return (mode & ~GR_AUDITS);
67776 +
67777 + curracl = current->acl;
67778 +
67779 + currobj = chk_obj_label(dentry, mnt, curracl);
67780 + retval = currobj->mode & mode;
67781 +
67782 + /* if we're opening a specified transfer file for writing
67783 + (e.g. /dev/initctl), then transfer our role to init
67784 + */
67785 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67786 + current->role->roletype & GR_ROLE_PERSIST)) {
67787 + struct task_struct *task = init_pid_ns.child_reaper;
67788 +
67789 + if (task->role != current->role) {
67790 + struct acl_subject_label *subj;
67791 +
67792 + task->acl_sp_role = 0;
67793 + task->acl_role_id = current->acl_role_id;
67794 + task->role = current->role;
67795 + rcu_read_lock();
67796 + read_lock(&grsec_exec_file_lock);
67797 + subj = gr_get_subject_for_task(task, NULL);
67798 + gr_apply_subject_to_task(task, subj);
67799 + read_unlock(&grsec_exec_file_lock);
67800 + rcu_read_unlock();
67801 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67802 + }
67803 + }
67804 +
67805 + if (unlikely
67806 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67807 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67808 + __u32 new_mode = mode;
67809 +
67810 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67811 +
67812 + retval = new_mode;
67813 +
67814 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67815 + new_mode |= GR_INHERIT;
67816 +
67817 + if (!(mode & GR_NOLEARN))
67818 + gr_log_learn(dentry, mnt, new_mode);
67819 + }
67820 +
67821 + return retval;
67822 +}
67823 +
67824 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67825 + const struct dentry *parent,
67826 + const struct vfsmount *mnt)
67827 +{
67828 + struct name_entry *match;
67829 + struct acl_object_label *matchpo;
67830 + struct acl_subject_label *curracl;
67831 + char *path;
67832 +
67833 + if (unlikely(!(gr_status & GR_READY)))
67834 + return NULL;
67835 +
67836 + preempt_disable();
67837 + path = gr_to_filename_rbac(new_dentry, mnt);
67838 + match = lookup_name_entry_create(path);
67839 +
67840 + curracl = current->acl;
67841 +
67842 + if (match) {
67843 + read_lock(&gr_inode_lock);
67844 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67845 + read_unlock(&gr_inode_lock);
67846 +
67847 + if (matchpo) {
67848 + preempt_enable();
67849 + return matchpo;
67850 + }
67851 + }
67852 +
67853 + // lookup parent
67854 +
67855 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67856 +
67857 + preempt_enable();
67858 + return matchpo;
67859 +}
67860 +
67861 +__u32
67862 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67863 + const struct vfsmount * mnt, const __u32 mode)
67864 +{
67865 + struct acl_object_label *matchpo;
67866 + __u32 retval;
67867 +
67868 + if (unlikely(!(gr_status & GR_READY)))
67869 + return (mode & ~GR_AUDITS);
67870 +
67871 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
67872 +
67873 + retval = matchpo->mode & mode;
67874 +
67875 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67876 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67877 + __u32 new_mode = mode;
67878 +
67879 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67880 +
67881 + gr_log_learn(new_dentry, mnt, new_mode);
67882 + return new_mode;
67883 + }
67884 +
67885 + return retval;
67886 +}
67887 +
67888 +__u32
67889 +gr_check_link(const struct dentry * new_dentry,
67890 + const struct dentry * parent_dentry,
67891 + const struct vfsmount * parent_mnt,
67892 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67893 +{
67894 + struct acl_object_label *obj;
67895 + __u32 oldmode, newmode;
67896 + __u32 needmode;
67897 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67898 + GR_DELETE | GR_INHERIT;
67899 +
67900 + if (unlikely(!(gr_status & GR_READY)))
67901 + return (GR_CREATE | GR_LINK);
67902 +
67903 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
67904 + oldmode = obj->mode;
67905 +
67906 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
67907 + newmode = obj->mode;
67908 +
67909 + needmode = newmode & checkmodes;
67910 +
67911 + // old name for hardlink must have at least the permissions of the new name
67912 + if ((oldmode & needmode) != needmode)
67913 + goto bad;
67914 +
67915 + // if old name had restrictions/auditing, make sure the new name does as well
67916 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
67917 +
67918 + // don't allow hardlinking of suid/sgid/fcapped files without permission
67919 + if (is_privileged_binary(old_dentry))
67920 + needmode |= GR_SETID;
67921 +
67922 + if ((newmode & needmode) != needmode)
67923 + goto bad;
67924 +
67925 + // enforce minimum permissions
67926 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
67927 + return newmode;
67928 +bad:
67929 + needmode = oldmode;
67930 + if (is_privileged_binary(old_dentry))
67931 + needmode |= GR_SETID;
67932 +
67933 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
67934 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
67935 + return (GR_CREATE | GR_LINK);
67936 + } else if (newmode & GR_SUPPRESS)
67937 + return GR_SUPPRESS;
67938 + else
67939 + return 0;
67940 +}
67941 +
67942 +int
67943 +gr_check_hidden_task(const struct task_struct *task)
67944 +{
67945 + if (unlikely(!(gr_status & GR_READY)))
67946 + return 0;
67947 +
67948 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
67949 + return 1;
67950 +
67951 + return 0;
67952 +}
67953 +
67954 +int
67955 +gr_check_protected_task(const struct task_struct *task)
67956 +{
67957 + if (unlikely(!(gr_status & GR_READY) || !task))
67958 + return 0;
67959 +
67960 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67961 + task->acl != current->acl)
67962 + return 1;
67963 +
67964 + return 0;
67965 +}
67966 +
67967 +int
67968 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67969 +{
67970 + struct task_struct *p;
67971 + int ret = 0;
67972 +
67973 + if (unlikely(!(gr_status & GR_READY) || !pid))
67974 + return ret;
67975 +
67976 + read_lock(&tasklist_lock);
67977 + do_each_pid_task(pid, type, p) {
67978 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67979 + p->acl != current->acl) {
67980 + ret = 1;
67981 + goto out;
67982 + }
67983 + } while_each_pid_task(pid, type, p);
67984 +out:
67985 + read_unlock(&tasklist_lock);
67986 +
67987 + return ret;
67988 +}
67989 +
67990 +void
67991 +gr_copy_label(struct task_struct *tsk)
67992 +{
67993 + struct task_struct *p = current;
67994 +
67995 + tsk->inherited = p->inherited;
67996 + tsk->acl_sp_role = 0;
67997 + tsk->acl_role_id = p->acl_role_id;
67998 + tsk->acl = p->acl;
67999 + tsk->role = p->role;
68000 + tsk->signal->used_accept = 0;
68001 + tsk->signal->curr_ip = p->signal->curr_ip;
68002 + tsk->signal->saved_ip = p->signal->saved_ip;
68003 + if (p->exec_file)
68004 + get_file(p->exec_file);
68005 + tsk->exec_file = p->exec_file;
68006 + tsk->is_writable = p->is_writable;
68007 + if (unlikely(p->signal->used_accept)) {
68008 + p->signal->curr_ip = 0;
68009 + p->signal->saved_ip = 0;
68010 + }
68011 +
68012 + return;
68013 +}
68014 +
68015 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68016 +
68017 +int
68018 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68019 +{
68020 + unsigned int i;
68021 + __u16 num;
68022 + uid_t *uidlist;
68023 + uid_t curuid;
68024 + int realok = 0;
68025 + int effectiveok = 0;
68026 + int fsok = 0;
68027 + uid_t globalreal, globaleffective, globalfs;
68028 +
68029 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68030 + struct user_struct *user;
68031 +
68032 + if (!uid_valid(real))
68033 + goto skipit;
68034 +
68035 + /* find user based on global namespace */
68036 +
68037 + globalreal = GR_GLOBAL_UID(real);
68038 +
68039 + user = find_user(make_kuid(&init_user_ns, globalreal));
68040 + if (user == NULL)
68041 + goto skipit;
68042 +
68043 + if (gr_process_kernel_setuid_ban(user)) {
68044 + /* for find_user */
68045 + free_uid(user);
68046 + return 1;
68047 + }
68048 +
68049 + /* for find_user */
68050 + free_uid(user);
68051 +
68052 +skipit:
68053 +#endif
68054 +
68055 + if (unlikely(!(gr_status & GR_READY)))
68056 + return 0;
68057 +
68058 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68059 + gr_log_learn_uid_change(real, effective, fs);
68060 +
68061 + num = current->acl->user_trans_num;
68062 + uidlist = current->acl->user_transitions;
68063 +
68064 + if (uidlist == NULL)
68065 + return 0;
68066 +
68067 + if (!uid_valid(real)) {
68068 + realok = 1;
68069 + globalreal = (uid_t)-1;
68070 + } else {
68071 + globalreal = GR_GLOBAL_UID(real);
68072 + }
68073 + if (!uid_valid(effective)) {
68074 + effectiveok = 1;
68075 + globaleffective = (uid_t)-1;
68076 + } else {
68077 + globaleffective = GR_GLOBAL_UID(effective);
68078 + }
68079 + if (!uid_valid(fs)) {
68080 + fsok = 1;
68081 + globalfs = (uid_t)-1;
68082 + } else {
68083 + globalfs = GR_GLOBAL_UID(fs);
68084 + }
68085 +
68086 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
68087 + for (i = 0; i < num; i++) {
68088 + curuid = uidlist[i];
68089 + if (globalreal == curuid)
68090 + realok = 1;
68091 + if (globaleffective == curuid)
68092 + effectiveok = 1;
68093 + if (globalfs == curuid)
68094 + fsok = 1;
68095 + }
68096 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
68097 + for (i = 0; i < num; i++) {
68098 + curuid = uidlist[i];
68099 + if (globalreal == curuid)
68100 + break;
68101 + if (globaleffective == curuid)
68102 + break;
68103 + if (globalfs == curuid)
68104 + break;
68105 + }
68106 + /* not in deny list */
68107 + if (i == num) {
68108 + realok = 1;
68109 + effectiveok = 1;
68110 + fsok = 1;
68111 + }
68112 + }
68113 +
68114 + if (realok && effectiveok && fsok)
68115 + return 0;
68116 + else {
68117 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68118 + return 1;
68119 + }
68120 +}
68121 +
68122 +int
68123 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68124 +{
68125 + unsigned int i;
68126 + __u16 num;
68127 + gid_t *gidlist;
68128 + gid_t curgid;
68129 + int realok = 0;
68130 + int effectiveok = 0;
68131 + int fsok = 0;
68132 + gid_t globalreal, globaleffective, globalfs;
68133 +
68134 + if (unlikely(!(gr_status & GR_READY)))
68135 + return 0;
68136 +
68137 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68138 + gr_log_learn_gid_change(real, effective, fs);
68139 +
68140 + num = current->acl->group_trans_num;
68141 + gidlist = current->acl->group_transitions;
68142 +
68143 + if (gidlist == NULL)
68144 + return 0;
68145 +
68146 + if (!gid_valid(real)) {
68147 + realok = 1;
68148 + globalreal = (gid_t)-1;
68149 + } else {
68150 + globalreal = GR_GLOBAL_GID(real);
68151 + }
68152 + if (!gid_valid(effective)) {
68153 + effectiveok = 1;
68154 + globaleffective = (gid_t)-1;
68155 + } else {
68156 + globaleffective = GR_GLOBAL_GID(effective);
68157 + }
68158 + if (!gid_valid(fs)) {
68159 + fsok = 1;
68160 + globalfs = (gid_t)-1;
68161 + } else {
68162 + globalfs = GR_GLOBAL_GID(fs);
68163 + }
68164 +
68165 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
68166 + for (i = 0; i < num; i++) {
68167 + curgid = gidlist[i];
68168 + if (globalreal == curgid)
68169 + realok = 1;
68170 + if (globaleffective == curgid)
68171 + effectiveok = 1;
68172 + if (globalfs == curgid)
68173 + fsok = 1;
68174 + }
68175 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
68176 + for (i = 0; i < num; i++) {
68177 + curgid = gidlist[i];
68178 + if (globalreal == curgid)
68179 + break;
68180 + if (globaleffective == curgid)
68181 + break;
68182 + if (globalfs == curgid)
68183 + break;
68184 + }
68185 + /* not in deny list */
68186 + if (i == num) {
68187 + realok = 1;
68188 + effectiveok = 1;
68189 + fsok = 1;
68190 + }
68191 + }
68192 +
68193 + if (realok && effectiveok && fsok)
68194 + return 0;
68195 + else {
68196 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68197 + return 1;
68198 + }
68199 +}
68200 +
68201 +extern int gr_acl_is_capable(const int cap);
68202 +
68203 +void
68204 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68205 +{
68206 + struct acl_role_label *role = task->role;
68207 + struct acl_subject_label *subj = NULL;
68208 + struct acl_object_label *obj;
68209 + struct file *filp;
68210 + uid_t uid;
68211 + gid_t gid;
68212 +
68213 + if (unlikely(!(gr_status & GR_READY)))
68214 + return;
68215 +
68216 + uid = GR_GLOBAL_UID(kuid);
68217 + gid = GR_GLOBAL_GID(kgid);
68218 +
68219 + filp = task->exec_file;
68220 +
68221 + /* kernel process, we'll give them the kernel role */
68222 + if (unlikely(!filp)) {
68223 + task->role = running_polstate.kernel_role;
68224 + task->acl = running_polstate.kernel_role->root_label;
68225 + return;
68226 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68227 + /* save the current ip at time of role lookup so that the proper
68228 + IP will be learned for role_allowed_ip */
68229 + task->signal->saved_ip = task->signal->curr_ip;
68230 + role = lookup_acl_role_label(task, uid, gid);
68231 + }
68232 +
68233 + /* don't change the role if we're not a privileged process */
68234 + if (role && task->role != role &&
68235 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68236 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68237 + return;
68238 +
68239 + /* perform subject lookup in possibly new role
68240 + we can use this result below in the case where role == task->role
68241 + */
68242 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68243 +
68244 + /* if we changed uid/gid, but result in the same role
68245 + and are using inheritance, don't lose the inherited subject
68246 + if current subject is other than what normal lookup
68247 + would result in, we arrived via inheritance, don't
68248 + lose subject
68249 + */
68250 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68251 + (subj == task->acl)))
68252 + task->acl = subj;
68253 +
68254 + /* leave task->inherited unaffected */
68255 +
68256 + task->role = role;
68257 +
68258 + task->is_writable = 0;
68259 +
68260 + /* ignore additional mmap checks for processes that are writable
68261 + by the default ACL */
68262 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68263 + if (unlikely(obj->mode & GR_WRITE))
68264 + task->is_writable = 1;
68265 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68266 + if (unlikely(obj->mode & GR_WRITE))
68267 + task->is_writable = 1;
68268 +
68269 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68270 + 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);
68271 +#endif
68272 +
68273 + gr_set_proc_res(task);
68274 +
68275 + return;
68276 +}
68277 +
68278 +int
68279 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68280 + const int unsafe_flags)
68281 +{
68282 + struct task_struct *task = current;
68283 + struct acl_subject_label *newacl;
68284 + struct acl_object_label *obj;
68285 + __u32 retmode;
68286 +
68287 + if (unlikely(!(gr_status & GR_READY)))
68288 + return 0;
68289 +
68290 + newacl = chk_subj_label(dentry, mnt, task->role);
68291 +
68292 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68293 + did an exec
68294 + */
68295 + rcu_read_lock();
68296 + read_lock(&tasklist_lock);
68297 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68298 + (task->parent->acl->mode & GR_POVERRIDE))) {
68299 + read_unlock(&tasklist_lock);
68300 + rcu_read_unlock();
68301 + goto skip_check;
68302 + }
68303 + read_unlock(&tasklist_lock);
68304 + rcu_read_unlock();
68305 +
68306 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68307 + !(task->role->roletype & GR_ROLE_GOD) &&
68308 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68309 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68310 + if (unsafe_flags & LSM_UNSAFE_SHARE)
68311 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68312 + else
68313 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68314 + return -EACCES;
68315 + }
68316 +
68317 +skip_check:
68318 +
68319 + obj = chk_obj_label(dentry, mnt, task->acl);
68320 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68321 +
68322 + if (!(task->acl->mode & GR_INHERITLEARN) &&
68323 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68324 + if (obj->nested)
68325 + task->acl = obj->nested;
68326 + else
68327 + task->acl = newacl;
68328 + task->inherited = 0;
68329 + } else {
68330 + task->inherited = 1;
68331 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68332 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68333 + }
68334 +
68335 + task->is_writable = 0;
68336 +
68337 + /* ignore additional mmap checks for processes that are writable
68338 + by the default ACL */
68339 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68340 + if (unlikely(obj->mode & GR_WRITE))
68341 + task->is_writable = 1;
68342 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
68343 + if (unlikely(obj->mode & GR_WRITE))
68344 + task->is_writable = 1;
68345 +
68346 + gr_set_proc_res(task);
68347 +
68348 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68349 + 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);
68350 +#endif
68351 + return 0;
68352 +}
68353 +
68354 +/* always called with valid inodev ptr */
68355 +static void
68356 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68357 +{
68358 + struct acl_object_label *matchpo;
68359 + struct acl_subject_label *matchps;
68360 + struct acl_subject_label *subj;
68361 + struct acl_role_label *role;
68362 + unsigned int x;
68363 +
68364 + FOR_EACH_ROLE_START(role)
68365 + FOR_EACH_SUBJECT_START(role, subj, x)
68366 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68367 + matchpo->mode |= GR_DELETED;
68368 + FOR_EACH_SUBJECT_END(subj,x)
68369 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68370 + /* nested subjects aren't in the role's subj_hash table */
68371 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68372 + matchpo->mode |= GR_DELETED;
68373 + FOR_EACH_NESTED_SUBJECT_END(subj)
68374 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68375 + matchps->mode |= GR_DELETED;
68376 + FOR_EACH_ROLE_END(role)
68377 +
68378 + inodev->nentry->deleted = 1;
68379 +
68380 + return;
68381 +}
68382 +
68383 +void
68384 +gr_handle_delete(const ino_t ino, const dev_t dev)
68385 +{
68386 + struct inodev_entry *inodev;
68387 +
68388 + if (unlikely(!(gr_status & GR_READY)))
68389 + return;
68390 +
68391 + write_lock(&gr_inode_lock);
68392 + inodev = lookup_inodev_entry(ino, dev);
68393 + if (inodev != NULL)
68394 + do_handle_delete(inodev, ino, dev);
68395 + write_unlock(&gr_inode_lock);
68396 +
68397 + return;
68398 +}
68399 +
68400 +static void
68401 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68402 + const ino_t newinode, const dev_t newdevice,
68403 + struct acl_subject_label *subj)
68404 +{
68405 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68406 + struct acl_object_label *match;
68407 +
68408 + match = subj->obj_hash[index];
68409 +
68410 + while (match && (match->inode != oldinode ||
68411 + match->device != olddevice ||
68412 + !(match->mode & GR_DELETED)))
68413 + match = match->next;
68414 +
68415 + if (match && (match->inode == oldinode)
68416 + && (match->device == olddevice)
68417 + && (match->mode & GR_DELETED)) {
68418 + if (match->prev == NULL) {
68419 + subj->obj_hash[index] = match->next;
68420 + if (match->next != NULL)
68421 + match->next->prev = NULL;
68422 + } else {
68423 + match->prev->next = match->next;
68424 + if (match->next != NULL)
68425 + match->next->prev = match->prev;
68426 + }
68427 + match->prev = NULL;
68428 + match->next = NULL;
68429 + match->inode = newinode;
68430 + match->device = newdevice;
68431 + match->mode &= ~GR_DELETED;
68432 +
68433 + insert_acl_obj_label(match, subj);
68434 + }
68435 +
68436 + return;
68437 +}
68438 +
68439 +static void
68440 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68441 + const ino_t newinode, const dev_t newdevice,
68442 + struct acl_role_label *role)
68443 +{
68444 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68445 + struct acl_subject_label *match;
68446 +
68447 + match = role->subj_hash[index];
68448 +
68449 + while (match && (match->inode != oldinode ||
68450 + match->device != olddevice ||
68451 + !(match->mode & GR_DELETED)))
68452 + match = match->next;
68453 +
68454 + if (match && (match->inode == oldinode)
68455 + && (match->device == olddevice)
68456 + && (match->mode & GR_DELETED)) {
68457 + if (match->prev == NULL) {
68458 + role->subj_hash[index] = match->next;
68459 + if (match->next != NULL)
68460 + match->next->prev = NULL;
68461 + } else {
68462 + match->prev->next = match->next;
68463 + if (match->next != NULL)
68464 + match->next->prev = match->prev;
68465 + }
68466 + match->prev = NULL;
68467 + match->next = NULL;
68468 + match->inode = newinode;
68469 + match->device = newdevice;
68470 + match->mode &= ~GR_DELETED;
68471 +
68472 + insert_acl_subj_label(match, role);
68473 + }
68474 +
68475 + return;
68476 +}
68477 +
68478 +static void
68479 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68480 + const ino_t newinode, const dev_t newdevice)
68481 +{
68482 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68483 + struct inodev_entry *match;
68484 +
68485 + match = running_polstate.inodev_set.i_hash[index];
68486 +
68487 + while (match && (match->nentry->inode != oldinode ||
68488 + match->nentry->device != olddevice || !match->nentry->deleted))
68489 + match = match->next;
68490 +
68491 + if (match && (match->nentry->inode == oldinode)
68492 + && (match->nentry->device == olddevice) &&
68493 + match->nentry->deleted) {
68494 + if (match->prev == NULL) {
68495 + running_polstate.inodev_set.i_hash[index] = match->next;
68496 + if (match->next != NULL)
68497 + match->next->prev = NULL;
68498 + } else {
68499 + match->prev->next = match->next;
68500 + if (match->next != NULL)
68501 + match->next->prev = match->prev;
68502 + }
68503 + match->prev = NULL;
68504 + match->next = NULL;
68505 + match->nentry->inode = newinode;
68506 + match->nentry->device = newdevice;
68507 + match->nentry->deleted = 0;
68508 +
68509 + insert_inodev_entry(match);
68510 + }
68511 +
68512 + return;
68513 +}
68514 +
68515 +static void
68516 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68517 +{
68518 + struct acl_subject_label *subj;
68519 + struct acl_role_label *role;
68520 + unsigned int x;
68521 +
68522 + FOR_EACH_ROLE_START(role)
68523 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68524 +
68525 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68526 + if ((subj->inode == ino) && (subj->device == dev)) {
68527 + subj->inode = ino;
68528 + subj->device = dev;
68529 + }
68530 + /* nested subjects aren't in the role's subj_hash table */
68531 + update_acl_obj_label(matchn->inode, matchn->device,
68532 + ino, dev, subj);
68533 + FOR_EACH_NESTED_SUBJECT_END(subj)
68534 + FOR_EACH_SUBJECT_START(role, subj, x)
68535 + update_acl_obj_label(matchn->inode, matchn->device,
68536 + ino, dev, subj);
68537 + FOR_EACH_SUBJECT_END(subj,x)
68538 + FOR_EACH_ROLE_END(role)
68539 +
68540 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68541 +
68542 + return;
68543 +}
68544 +
68545 +static void
68546 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68547 + const struct vfsmount *mnt)
68548 +{
68549 + ino_t ino = dentry->d_inode->i_ino;
68550 + dev_t dev = __get_dev(dentry);
68551 +
68552 + __do_handle_create(matchn, ino, dev);
68553 +
68554 + return;
68555 +}
68556 +
68557 +void
68558 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68559 +{
68560 + struct name_entry *matchn;
68561 +
68562 + if (unlikely(!(gr_status & GR_READY)))
68563 + return;
68564 +
68565 + preempt_disable();
68566 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68567 +
68568 + if (unlikely((unsigned long)matchn)) {
68569 + write_lock(&gr_inode_lock);
68570 + do_handle_create(matchn, dentry, mnt);
68571 + write_unlock(&gr_inode_lock);
68572 + }
68573 + preempt_enable();
68574 +
68575 + return;
68576 +}
68577 +
68578 +void
68579 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68580 +{
68581 + struct name_entry *matchn;
68582 +
68583 + if (unlikely(!(gr_status & GR_READY)))
68584 + return;
68585 +
68586 + preempt_disable();
68587 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68588 +
68589 + if (unlikely((unsigned long)matchn)) {
68590 + write_lock(&gr_inode_lock);
68591 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68592 + write_unlock(&gr_inode_lock);
68593 + }
68594 + preempt_enable();
68595 +
68596 + return;
68597 +}
68598 +
68599 +void
68600 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68601 + struct dentry *old_dentry,
68602 + struct dentry *new_dentry,
68603 + struct vfsmount *mnt, const __u8 replace)
68604 +{
68605 + struct name_entry *matchn;
68606 + struct inodev_entry *inodev;
68607 + struct inode *inode = new_dentry->d_inode;
68608 + ino_t old_ino = old_dentry->d_inode->i_ino;
68609 + dev_t old_dev = __get_dev(old_dentry);
68610 +
68611 + /* vfs_rename swaps the name and parent link for old_dentry and
68612 + new_dentry
68613 + at this point, old_dentry has the new name, parent link, and inode
68614 + for the renamed file
68615 + if a file is being replaced by a rename, new_dentry has the inode
68616 + and name for the replaced file
68617 + */
68618 +
68619 + if (unlikely(!(gr_status & GR_READY)))
68620 + return;
68621 +
68622 + preempt_disable();
68623 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68624 +
68625 + /* we wouldn't have to check d_inode if it weren't for
68626 + NFS silly-renaming
68627 + */
68628 +
68629 + write_lock(&gr_inode_lock);
68630 + if (unlikely(replace && inode)) {
68631 + ino_t new_ino = inode->i_ino;
68632 + dev_t new_dev = __get_dev(new_dentry);
68633 +
68634 + inodev = lookup_inodev_entry(new_ino, new_dev);
68635 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68636 + do_handle_delete(inodev, new_ino, new_dev);
68637 + }
68638 +
68639 + inodev = lookup_inodev_entry(old_ino, old_dev);
68640 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68641 + do_handle_delete(inodev, old_ino, old_dev);
68642 +
68643 + if (unlikely((unsigned long)matchn))
68644 + do_handle_create(matchn, old_dentry, mnt);
68645 +
68646 + write_unlock(&gr_inode_lock);
68647 + preempt_enable();
68648 +
68649 + return;
68650 +}
68651 +
68652 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68653 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68654 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68655 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68656 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68657 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68658 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68659 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68660 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68661 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68662 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68663 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68664 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68665 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68666 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68667 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68668 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68669 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68670 +};
68671 +
68672 +void
68673 +gr_learn_resource(const struct task_struct *task,
68674 + const int res, const unsigned long wanted, const int gt)
68675 +{
68676 + struct acl_subject_label *acl;
68677 + const struct cred *cred;
68678 +
68679 + if (unlikely((gr_status & GR_READY) &&
68680 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68681 + goto skip_reslog;
68682 +
68683 + gr_log_resource(task, res, wanted, gt);
68684 +skip_reslog:
68685 +
68686 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68687 + return;
68688 +
68689 + acl = task->acl;
68690 +
68691 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68692 + !(acl->resmask & (1U << (unsigned short) res))))
68693 + return;
68694 +
68695 + if (wanted >= acl->res[res].rlim_cur) {
68696 + unsigned long res_add;
68697 +
68698 + res_add = wanted + res_learn_bumps[res];
68699 +
68700 + acl->res[res].rlim_cur = res_add;
68701 +
68702 + if (wanted > acl->res[res].rlim_max)
68703 + acl->res[res].rlim_max = res_add;
68704 +
68705 + /* only log the subject filename, since resource logging is supported for
68706 + single-subject learning only */
68707 + rcu_read_lock();
68708 + cred = __task_cred(task);
68709 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68710 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68711 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68712 + "", (unsigned long) res, &task->signal->saved_ip);
68713 + rcu_read_unlock();
68714 + }
68715 +
68716 + return;
68717 +}
68718 +EXPORT_SYMBOL_GPL(gr_learn_resource);
68719 +#endif
68720 +
68721 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68722 +void
68723 +pax_set_initial_flags(struct linux_binprm *bprm)
68724 +{
68725 + struct task_struct *task = current;
68726 + struct acl_subject_label *proc;
68727 + unsigned long flags;
68728 +
68729 + if (unlikely(!(gr_status & GR_READY)))
68730 + return;
68731 +
68732 + flags = pax_get_flags(task);
68733 +
68734 + proc = task->acl;
68735 +
68736 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68737 + flags &= ~MF_PAX_PAGEEXEC;
68738 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68739 + flags &= ~MF_PAX_SEGMEXEC;
68740 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68741 + flags &= ~MF_PAX_RANDMMAP;
68742 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68743 + flags &= ~MF_PAX_EMUTRAMP;
68744 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68745 + flags &= ~MF_PAX_MPROTECT;
68746 +
68747 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68748 + flags |= MF_PAX_PAGEEXEC;
68749 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68750 + flags |= MF_PAX_SEGMEXEC;
68751 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68752 + flags |= MF_PAX_RANDMMAP;
68753 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68754 + flags |= MF_PAX_EMUTRAMP;
68755 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68756 + flags |= MF_PAX_MPROTECT;
68757 +
68758 + pax_set_flags(task, flags);
68759 +
68760 + return;
68761 +}
68762 +#endif
68763 +
68764 +int
68765 +gr_handle_proc_ptrace(struct task_struct *task)
68766 +{
68767 + struct file *filp;
68768 + struct task_struct *tmp = task;
68769 + struct task_struct *curtemp = current;
68770 + __u32 retmode;
68771 +
68772 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68773 + if (unlikely(!(gr_status & GR_READY)))
68774 + return 0;
68775 +#endif
68776 +
68777 + read_lock(&tasklist_lock);
68778 + read_lock(&grsec_exec_file_lock);
68779 + filp = task->exec_file;
68780 +
68781 + while (task_pid_nr(tmp) > 0) {
68782 + if (tmp == curtemp)
68783 + break;
68784 + tmp = tmp->real_parent;
68785 + }
68786 +
68787 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68788 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68789 + read_unlock(&grsec_exec_file_lock);
68790 + read_unlock(&tasklist_lock);
68791 + return 1;
68792 + }
68793 +
68794 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68795 + if (!(gr_status & GR_READY)) {
68796 + read_unlock(&grsec_exec_file_lock);
68797 + read_unlock(&tasklist_lock);
68798 + return 0;
68799 + }
68800 +#endif
68801 +
68802 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68803 + read_unlock(&grsec_exec_file_lock);
68804 + read_unlock(&tasklist_lock);
68805 +
68806 + if (retmode & GR_NOPTRACE)
68807 + return 1;
68808 +
68809 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68810 + && (current->acl != task->acl || (current->acl != current->role->root_label
68811 + && task_pid_nr(current) != task_pid_nr(task))))
68812 + return 1;
68813 +
68814 + return 0;
68815 +}
68816 +
68817 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68818 +{
68819 + if (unlikely(!(gr_status & GR_READY)))
68820 + return;
68821 +
68822 + if (!(current->role->roletype & GR_ROLE_GOD))
68823 + return;
68824 +
68825 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68826 + p->role->rolename, gr_task_roletype_to_char(p),
68827 + p->acl->filename);
68828 +}
68829 +
68830 +int
68831 +gr_handle_ptrace(struct task_struct *task, const long request)
68832 +{
68833 + struct task_struct *tmp = task;
68834 + struct task_struct *curtemp = current;
68835 + __u32 retmode;
68836 +
68837 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68838 + if (unlikely(!(gr_status & GR_READY)))
68839 + return 0;
68840 +#endif
68841 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68842 + read_lock(&tasklist_lock);
68843 + while (task_pid_nr(tmp) > 0) {
68844 + if (tmp == curtemp)
68845 + break;
68846 + tmp = tmp->real_parent;
68847 + }
68848 +
68849 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68850 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68851 + read_unlock(&tasklist_lock);
68852 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68853 + return 1;
68854 + }
68855 + read_unlock(&tasklist_lock);
68856 + }
68857 +
68858 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68859 + if (!(gr_status & GR_READY))
68860 + return 0;
68861 +#endif
68862 +
68863 + read_lock(&grsec_exec_file_lock);
68864 + if (unlikely(!task->exec_file)) {
68865 + read_unlock(&grsec_exec_file_lock);
68866 + return 0;
68867 + }
68868 +
68869 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68870 + read_unlock(&grsec_exec_file_lock);
68871 +
68872 + if (retmode & GR_NOPTRACE) {
68873 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68874 + return 1;
68875 + }
68876 +
68877 + if (retmode & GR_PTRACERD) {
68878 + switch (request) {
68879 + case PTRACE_SEIZE:
68880 + case PTRACE_POKETEXT:
68881 + case PTRACE_POKEDATA:
68882 + case PTRACE_POKEUSR:
68883 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68884 + case PTRACE_SETREGS:
68885 + case PTRACE_SETFPREGS:
68886 +#endif
68887 +#ifdef CONFIG_X86
68888 + case PTRACE_SETFPXREGS:
68889 +#endif
68890 +#ifdef CONFIG_ALTIVEC
68891 + case PTRACE_SETVRREGS:
68892 +#endif
68893 + return 1;
68894 + default:
68895 + return 0;
68896 + }
68897 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
68898 + !(current->role->roletype & GR_ROLE_GOD) &&
68899 + (current->acl != task->acl)) {
68900 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68901 + return 1;
68902 + }
68903 +
68904 + return 0;
68905 +}
68906 +
68907 +static int is_writable_mmap(const struct file *filp)
68908 +{
68909 + struct task_struct *task = current;
68910 + struct acl_object_label *obj, *obj2;
68911 +
68912 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
68913 + !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))) {
68914 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68915 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
68916 + task->role->root_label);
68917 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
68918 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
68919 + return 1;
68920 + }
68921 + }
68922 + return 0;
68923 +}
68924 +
68925 +int
68926 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
68927 +{
68928 + __u32 mode;
68929 +
68930 + if (unlikely(!file || !(prot & PROT_EXEC)))
68931 + return 1;
68932 +
68933 + if (is_writable_mmap(file))
68934 + return 0;
68935 +
68936 + mode =
68937 + gr_search_file(file->f_path.dentry,
68938 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68939 + file->f_path.mnt);
68940 +
68941 + if (!gr_tpe_allow(file))
68942 + return 0;
68943 +
68944 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68945 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68946 + return 0;
68947 + } else if (unlikely(!(mode & GR_EXEC))) {
68948 + return 0;
68949 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68950 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68951 + return 1;
68952 + }
68953 +
68954 + return 1;
68955 +}
68956 +
68957 +int
68958 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68959 +{
68960 + __u32 mode;
68961 +
68962 + if (unlikely(!file || !(prot & PROT_EXEC)))
68963 + return 1;
68964 +
68965 + if (is_writable_mmap(file))
68966 + return 0;
68967 +
68968 + mode =
68969 + gr_search_file(file->f_path.dentry,
68970 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68971 + file->f_path.mnt);
68972 +
68973 + if (!gr_tpe_allow(file))
68974 + return 0;
68975 +
68976 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68977 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68978 + return 0;
68979 + } else if (unlikely(!(mode & GR_EXEC))) {
68980 + return 0;
68981 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68982 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68983 + return 1;
68984 + }
68985 +
68986 + return 1;
68987 +}
68988 +
68989 +void
68990 +gr_acl_handle_psacct(struct task_struct *task, const long code)
68991 +{
68992 + unsigned long runtime, cputime;
68993 + cputime_t utime, stime;
68994 + unsigned int wday, cday;
68995 + __u8 whr, chr;
68996 + __u8 wmin, cmin;
68997 + __u8 wsec, csec;
68998 + struct timespec timeval;
68999 +
69000 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69001 + !(task->acl->mode & GR_PROCACCT)))
69002 + return;
69003 +
69004 + do_posix_clock_monotonic_gettime(&timeval);
69005 + runtime = timeval.tv_sec - task->start_time.tv_sec;
69006 + wday = runtime / (60 * 60 * 24);
69007 + runtime -= wday * (60 * 60 * 24);
69008 + whr = runtime / (60 * 60);
69009 + runtime -= whr * (60 * 60);
69010 + wmin = runtime / 60;
69011 + runtime -= wmin * 60;
69012 + wsec = runtime;
69013 +
69014 + task_cputime(task, &utime, &stime);
69015 + cputime = cputime_to_secs(utime + stime);
69016 + cday = cputime / (60 * 60 * 24);
69017 + cputime -= cday * (60 * 60 * 24);
69018 + chr = cputime / (60 * 60);
69019 + cputime -= chr * (60 * 60);
69020 + cmin = cputime / 60;
69021 + cputime -= cmin * 60;
69022 + csec = cputime;
69023 +
69024 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69025 +
69026 + return;
69027 +}
69028 +
69029 +#ifdef CONFIG_TASKSTATS
69030 +int gr_is_taskstats_denied(int pid)
69031 +{
69032 + struct task_struct *task;
69033 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69034 + const struct cred *cred;
69035 +#endif
69036 + int ret = 0;
69037 +
69038 + /* restrict taskstats viewing to un-chrooted root users
69039 + who have the 'view' subject flag if the RBAC system is enabled
69040 + */
69041 +
69042 + rcu_read_lock();
69043 + read_lock(&tasklist_lock);
69044 + task = find_task_by_vpid(pid);
69045 + if (task) {
69046 +#ifdef CONFIG_GRKERNSEC_CHROOT
69047 + if (proc_is_chrooted(task))
69048 + ret = -EACCES;
69049 +#endif
69050 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69051 + cred = __task_cred(task);
69052 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69053 + if (gr_is_global_nonroot(cred->uid))
69054 + ret = -EACCES;
69055 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69056 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69057 + ret = -EACCES;
69058 +#endif
69059 +#endif
69060 + if (gr_status & GR_READY) {
69061 + if (!(task->acl->mode & GR_VIEW))
69062 + ret = -EACCES;
69063 + }
69064 + } else
69065 + ret = -ENOENT;
69066 +
69067 + read_unlock(&tasklist_lock);
69068 + rcu_read_unlock();
69069 +
69070 + return ret;
69071 +}
69072 +#endif
69073 +
69074 +/* AUXV entries are filled via a descendant of search_binary_handler
69075 + after we've already applied the subject for the target
69076 +*/
69077 +int gr_acl_enable_at_secure(void)
69078 +{
69079 + if (unlikely(!(gr_status & GR_READY)))
69080 + return 0;
69081 +
69082 + if (current->acl->mode & GR_ATSECURE)
69083 + return 1;
69084 +
69085 + return 0;
69086 +}
69087 +
69088 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69089 +{
69090 + struct task_struct *task = current;
69091 + struct dentry *dentry = file->f_path.dentry;
69092 + struct vfsmount *mnt = file->f_path.mnt;
69093 + struct acl_object_label *obj, *tmp;
69094 + struct acl_subject_label *subj;
69095 + unsigned int bufsize;
69096 + int is_not_root;
69097 + char *path;
69098 + dev_t dev = __get_dev(dentry);
69099 +
69100 + if (unlikely(!(gr_status & GR_READY)))
69101 + return 1;
69102 +
69103 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69104 + return 1;
69105 +
69106 + /* ignore Eric Biederman */
69107 + if (IS_PRIVATE(dentry->d_inode))
69108 + return 1;
69109 +
69110 + subj = task->acl;
69111 + read_lock(&gr_inode_lock);
69112 + do {
69113 + obj = lookup_acl_obj_label(ino, dev, subj);
69114 + if (obj != NULL) {
69115 + read_unlock(&gr_inode_lock);
69116 + return (obj->mode & GR_FIND) ? 1 : 0;
69117 + }
69118 + } while ((subj = subj->parent_subject));
69119 + read_unlock(&gr_inode_lock);
69120 +
69121 + /* this is purely an optimization since we're looking for an object
69122 + for the directory we're doing a readdir on
69123 + if it's possible for any globbed object to match the entry we're
69124 + filling into the directory, then the object we find here will be
69125 + an anchor point with attached globbed objects
69126 + */
69127 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69128 + if (obj->globbed == NULL)
69129 + return (obj->mode & GR_FIND) ? 1 : 0;
69130 +
69131 + is_not_root = ((obj->filename[0] == '/') &&
69132 + (obj->filename[1] == '\0')) ? 0 : 1;
69133 + bufsize = PAGE_SIZE - namelen - is_not_root;
69134 +
69135 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
69136 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69137 + return 1;
69138 +
69139 + preempt_disable();
69140 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69141 + bufsize);
69142 +
69143 + bufsize = strlen(path);
69144 +
69145 + /* if base is "/", don't append an additional slash */
69146 + if (is_not_root)
69147 + *(path + bufsize) = '/';
69148 + memcpy(path + bufsize + is_not_root, name, namelen);
69149 + *(path + bufsize + namelen + is_not_root) = '\0';
69150 +
69151 + tmp = obj->globbed;
69152 + while (tmp) {
69153 + if (!glob_match(tmp->filename, path)) {
69154 + preempt_enable();
69155 + return (tmp->mode & GR_FIND) ? 1 : 0;
69156 + }
69157 + tmp = tmp->next;
69158 + }
69159 + preempt_enable();
69160 + return (obj->mode & GR_FIND) ? 1 : 0;
69161 +}
69162 +
69163 +void gr_put_exec_file(struct task_struct *task)
69164 +{
69165 + struct file *filp;
69166 +
69167 + write_lock(&grsec_exec_file_lock);
69168 + filp = task->exec_file;
69169 + task->exec_file = NULL;
69170 + write_unlock(&grsec_exec_file_lock);
69171 +
69172 + if (filp)
69173 + fput(filp);
69174 +
69175 + return;
69176 +}
69177 +
69178 +
69179 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69180 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69181 +#endif
69182 +#ifdef CONFIG_SECURITY
69183 +EXPORT_SYMBOL_GPL(gr_check_user_change);
69184 +EXPORT_SYMBOL_GPL(gr_check_group_change);
69185 +#endif
69186 +
69187 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69188 new file mode 100644
69189 index 0000000..18ffbbd
69190 --- /dev/null
69191 +++ b/grsecurity/gracl_alloc.c
69192 @@ -0,0 +1,105 @@
69193 +#include <linux/kernel.h>
69194 +#include <linux/mm.h>
69195 +#include <linux/slab.h>
69196 +#include <linux/vmalloc.h>
69197 +#include <linux/gracl.h>
69198 +#include <linux/grsecurity.h>
69199 +
69200 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69201 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69202 +
69203 +static __inline__ int
69204 +alloc_pop(void)
69205 +{
69206 + if (current_alloc_state->alloc_stack_next == 1)
69207 + return 0;
69208 +
69209 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69210 +
69211 + current_alloc_state->alloc_stack_next--;
69212 +
69213 + return 1;
69214 +}
69215 +
69216 +static __inline__ int
69217 +alloc_push(void *buf)
69218 +{
69219 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69220 + return 1;
69221 +
69222 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69223 +
69224 + current_alloc_state->alloc_stack_next++;
69225 +
69226 + return 0;
69227 +}
69228 +
69229 +void *
69230 +acl_alloc(unsigned long len)
69231 +{
69232 + void *ret = NULL;
69233 +
69234 + if (!len || len > PAGE_SIZE)
69235 + goto out;
69236 +
69237 + ret = kmalloc(len, GFP_KERNEL);
69238 +
69239 + if (ret) {
69240 + if (alloc_push(ret)) {
69241 + kfree(ret);
69242 + ret = NULL;
69243 + }
69244 + }
69245 +
69246 +out:
69247 + return ret;
69248 +}
69249 +
69250 +void *
69251 +acl_alloc_num(unsigned long num, unsigned long len)
69252 +{
69253 + if (!len || (num > (PAGE_SIZE / len)))
69254 + return NULL;
69255 +
69256 + return acl_alloc(num * len);
69257 +}
69258 +
69259 +void
69260 +acl_free_all(void)
69261 +{
69262 + if (!current_alloc_state->alloc_stack)
69263 + return;
69264 +
69265 + while (alloc_pop()) ;
69266 +
69267 + if (current_alloc_state->alloc_stack) {
69268 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69269 + kfree(current_alloc_state->alloc_stack);
69270 + else
69271 + vfree(current_alloc_state->alloc_stack);
69272 + }
69273 +
69274 + current_alloc_state->alloc_stack = NULL;
69275 + current_alloc_state->alloc_stack_size = 1;
69276 + current_alloc_state->alloc_stack_next = 1;
69277 +
69278 + return;
69279 +}
69280 +
69281 +int
69282 +acl_alloc_stack_init(unsigned long size)
69283 +{
69284 + if ((size * sizeof (void *)) <= PAGE_SIZE)
69285 + current_alloc_state->alloc_stack =
69286 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69287 + else
69288 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69289 +
69290 + current_alloc_state->alloc_stack_size = size;
69291 + current_alloc_state->alloc_stack_next = 1;
69292 +
69293 + if (!current_alloc_state->alloc_stack)
69294 + return 0;
69295 + else
69296 + return 1;
69297 +}
69298 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69299 new file mode 100644
69300 index 0000000..bdd51ea
69301 --- /dev/null
69302 +++ b/grsecurity/gracl_cap.c
69303 @@ -0,0 +1,110 @@
69304 +#include <linux/kernel.h>
69305 +#include <linux/module.h>
69306 +#include <linux/sched.h>
69307 +#include <linux/gracl.h>
69308 +#include <linux/grsecurity.h>
69309 +#include <linux/grinternal.h>
69310 +
69311 +extern const char *captab_log[];
69312 +extern int captab_log_entries;
69313 +
69314 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69315 +{
69316 + struct acl_subject_label *curracl;
69317 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69318 + kernel_cap_t cap_audit = __cap_empty_set;
69319 +
69320 + if (!gr_acl_is_enabled())
69321 + return 1;
69322 +
69323 + curracl = task->acl;
69324 +
69325 + cap_drop = curracl->cap_lower;
69326 + cap_mask = curracl->cap_mask;
69327 + cap_audit = curracl->cap_invert_audit;
69328 +
69329 + while ((curracl = curracl->parent_subject)) {
69330 + /* if the cap isn't specified in the current computed mask but is specified in the
69331 + current level subject, and is lowered in the current level subject, then add
69332 + it to the set of dropped capabilities
69333 + otherwise, add the current level subject's mask to the current computed mask
69334 + */
69335 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69336 + cap_raise(cap_mask, cap);
69337 + if (cap_raised(curracl->cap_lower, cap))
69338 + cap_raise(cap_drop, cap);
69339 + if (cap_raised(curracl->cap_invert_audit, cap))
69340 + cap_raise(cap_audit, cap);
69341 + }
69342 + }
69343 +
69344 + if (!cap_raised(cap_drop, cap)) {
69345 + if (cap_raised(cap_audit, cap))
69346 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69347 + return 1;
69348 + }
69349 +
69350 + curracl = task->acl;
69351 +
69352 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69353 + && cap_raised(cred->cap_effective, cap)) {
69354 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69355 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
69356 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
69357 + gr_to_filename(task->exec_file->f_path.dentry,
69358 + task->exec_file->f_path.mnt) : curracl->filename,
69359 + curracl->filename, 0UL,
69360 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69361 + return 1;
69362 + }
69363 +
69364 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69365 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69366 +
69367 + return 0;
69368 +}
69369 +
69370 +int
69371 +gr_acl_is_capable(const int cap)
69372 +{
69373 + return gr_task_acl_is_capable(current, current_cred(), cap);
69374 +}
69375 +
69376 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69377 +{
69378 + struct acl_subject_label *curracl;
69379 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69380 +
69381 + if (!gr_acl_is_enabled())
69382 + return 1;
69383 +
69384 + curracl = task->acl;
69385 +
69386 + cap_drop = curracl->cap_lower;
69387 + cap_mask = curracl->cap_mask;
69388 +
69389 + while ((curracl = curracl->parent_subject)) {
69390 + /* if the cap isn't specified in the current computed mask but is specified in the
69391 + current level subject, and is lowered in the current level subject, then add
69392 + it to the set of dropped capabilities
69393 + otherwise, add the current level subject's mask to the current computed mask
69394 + */
69395 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69396 + cap_raise(cap_mask, cap);
69397 + if (cap_raised(curracl->cap_lower, cap))
69398 + cap_raise(cap_drop, cap);
69399 + }
69400 + }
69401 +
69402 + if (!cap_raised(cap_drop, cap))
69403 + return 1;
69404 +
69405 + return 0;
69406 +}
69407 +
69408 +int
69409 +gr_acl_is_capable_nolog(const int cap)
69410 +{
69411 + return gr_task_acl_is_capable_nolog(current, cap);
69412 +}
69413 +
69414 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69415 new file mode 100644
69416 index 0000000..ca25605
69417 --- /dev/null
69418 +++ b/grsecurity/gracl_compat.c
69419 @@ -0,0 +1,270 @@
69420 +#include <linux/kernel.h>
69421 +#include <linux/gracl.h>
69422 +#include <linux/compat.h>
69423 +#include <linux/gracl_compat.h>
69424 +
69425 +#include <asm/uaccess.h>
69426 +
69427 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69428 +{
69429 + struct gr_arg_wrapper_compat uwrapcompat;
69430 +
69431 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69432 + return -EFAULT;
69433 +
69434 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69435 + (uwrapcompat.version != 0x2901)) ||
69436 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69437 + return -EINVAL;
69438 +
69439 + uwrap->arg = compat_ptr(uwrapcompat.arg);
69440 + uwrap->version = uwrapcompat.version;
69441 + uwrap->size = sizeof(struct gr_arg);
69442 +
69443 + return 0;
69444 +}
69445 +
69446 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69447 +{
69448 + struct gr_arg_compat argcompat;
69449 +
69450 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69451 + return -EFAULT;
69452 +
69453 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69454 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69455 + arg->role_db.num_roles = argcompat.role_db.num_roles;
69456 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69457 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69458 + arg->role_db.num_objects = argcompat.role_db.num_objects;
69459 +
69460 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69461 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69462 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69463 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69464 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69465 + arg->segv_device = argcompat.segv_device;
69466 + arg->segv_inode = argcompat.segv_inode;
69467 + arg->segv_uid = argcompat.segv_uid;
69468 + arg->num_sprole_pws = argcompat.num_sprole_pws;
69469 + arg->mode = argcompat.mode;
69470 +
69471 + return 0;
69472 +}
69473 +
69474 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69475 +{
69476 + struct acl_object_label_compat objcompat;
69477 +
69478 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69479 + return -EFAULT;
69480 +
69481 + obj->filename = compat_ptr(objcompat.filename);
69482 + obj->inode = objcompat.inode;
69483 + obj->device = objcompat.device;
69484 + obj->mode = objcompat.mode;
69485 +
69486 + obj->nested = compat_ptr(objcompat.nested);
69487 + obj->globbed = compat_ptr(objcompat.globbed);
69488 +
69489 + obj->prev = compat_ptr(objcompat.prev);
69490 + obj->next = compat_ptr(objcompat.next);
69491 +
69492 + return 0;
69493 +}
69494 +
69495 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69496 +{
69497 + unsigned int i;
69498 + struct acl_subject_label_compat subjcompat;
69499 +
69500 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69501 + return -EFAULT;
69502 +
69503 + subj->filename = compat_ptr(subjcompat.filename);
69504 + subj->inode = subjcompat.inode;
69505 + subj->device = subjcompat.device;
69506 + subj->mode = subjcompat.mode;
69507 + subj->cap_mask = subjcompat.cap_mask;
69508 + subj->cap_lower = subjcompat.cap_lower;
69509 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
69510 +
69511 + for (i = 0; i < GR_NLIMITS; i++) {
69512 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69513 + subj->res[i].rlim_cur = RLIM_INFINITY;
69514 + else
69515 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69516 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69517 + subj->res[i].rlim_max = RLIM_INFINITY;
69518 + else
69519 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69520 + }
69521 + subj->resmask = subjcompat.resmask;
69522 +
69523 + subj->user_trans_type = subjcompat.user_trans_type;
69524 + subj->group_trans_type = subjcompat.group_trans_type;
69525 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69526 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69527 + subj->user_trans_num = subjcompat.user_trans_num;
69528 + subj->group_trans_num = subjcompat.group_trans_num;
69529 +
69530 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69531 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69532 + subj->ip_type = subjcompat.ip_type;
69533 + subj->ips = compat_ptr(subjcompat.ips);
69534 + subj->ip_num = subjcompat.ip_num;
69535 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
69536 +
69537 + subj->crashes = subjcompat.crashes;
69538 + subj->expires = subjcompat.expires;
69539 +
69540 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69541 + subj->hash = compat_ptr(subjcompat.hash);
69542 + subj->prev = compat_ptr(subjcompat.prev);
69543 + subj->next = compat_ptr(subjcompat.next);
69544 +
69545 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69546 + subj->obj_hash_size = subjcompat.obj_hash_size;
69547 + subj->pax_flags = subjcompat.pax_flags;
69548 +
69549 + return 0;
69550 +}
69551 +
69552 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69553 +{
69554 + struct acl_role_label_compat rolecompat;
69555 +
69556 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69557 + return -EFAULT;
69558 +
69559 + role->rolename = compat_ptr(rolecompat.rolename);
69560 + role->uidgid = rolecompat.uidgid;
69561 + role->roletype = rolecompat.roletype;
69562 +
69563 + role->auth_attempts = rolecompat.auth_attempts;
69564 + role->expires = rolecompat.expires;
69565 +
69566 + role->root_label = compat_ptr(rolecompat.root_label);
69567 + role->hash = compat_ptr(rolecompat.hash);
69568 +
69569 + role->prev = compat_ptr(rolecompat.prev);
69570 + role->next = compat_ptr(rolecompat.next);
69571 +
69572 + role->transitions = compat_ptr(rolecompat.transitions);
69573 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69574 + role->domain_children = compat_ptr(rolecompat.domain_children);
69575 + role->domain_child_num = rolecompat.domain_child_num;
69576 +
69577 + role->umask = rolecompat.umask;
69578 +
69579 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
69580 + role->subj_hash_size = rolecompat.subj_hash_size;
69581 +
69582 + return 0;
69583 +}
69584 +
69585 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69586 +{
69587 + struct role_allowed_ip_compat roleip_compat;
69588 +
69589 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69590 + return -EFAULT;
69591 +
69592 + roleip->addr = roleip_compat.addr;
69593 + roleip->netmask = roleip_compat.netmask;
69594 +
69595 + roleip->prev = compat_ptr(roleip_compat.prev);
69596 + roleip->next = compat_ptr(roleip_compat.next);
69597 +
69598 + return 0;
69599 +}
69600 +
69601 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69602 +{
69603 + struct role_transition_compat trans_compat;
69604 +
69605 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69606 + return -EFAULT;
69607 +
69608 + trans->rolename = compat_ptr(trans_compat.rolename);
69609 +
69610 + trans->prev = compat_ptr(trans_compat.prev);
69611 + trans->next = compat_ptr(trans_compat.next);
69612 +
69613 + return 0;
69614 +
69615 +}
69616 +
69617 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69618 +{
69619 + struct gr_hash_struct_compat hash_compat;
69620 +
69621 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69622 + return -EFAULT;
69623 +
69624 + hash->table = compat_ptr(hash_compat.table);
69625 + hash->nametable = compat_ptr(hash_compat.nametable);
69626 + hash->first = compat_ptr(hash_compat.first);
69627 +
69628 + hash->table_size = hash_compat.table_size;
69629 + hash->used_size = hash_compat.used_size;
69630 +
69631 + hash->type = hash_compat.type;
69632 +
69633 + return 0;
69634 +}
69635 +
69636 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69637 +{
69638 + compat_uptr_t ptrcompat;
69639 +
69640 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69641 + return -EFAULT;
69642 +
69643 + *(void **)ptr = compat_ptr(ptrcompat);
69644 +
69645 + return 0;
69646 +}
69647 +
69648 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69649 +{
69650 + struct acl_ip_label_compat ip_compat;
69651 +
69652 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69653 + return -EFAULT;
69654 +
69655 + ip->iface = compat_ptr(ip_compat.iface);
69656 + ip->addr = ip_compat.addr;
69657 + ip->netmask = ip_compat.netmask;
69658 + ip->low = ip_compat.low;
69659 + ip->high = ip_compat.high;
69660 + ip->mode = ip_compat.mode;
69661 + ip->type = ip_compat.type;
69662 +
69663 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69664 +
69665 + ip->prev = compat_ptr(ip_compat.prev);
69666 + ip->next = compat_ptr(ip_compat.next);
69667 +
69668 + return 0;
69669 +}
69670 +
69671 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69672 +{
69673 + struct sprole_pw_compat pw_compat;
69674 +
69675 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69676 + return -EFAULT;
69677 +
69678 + pw->rolename = compat_ptr(pw_compat.rolename);
69679 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69680 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69681 +
69682 + return 0;
69683 +}
69684 +
69685 +size_t get_gr_arg_wrapper_size_compat(void)
69686 +{
69687 + return sizeof(struct gr_arg_wrapper_compat);
69688 +}
69689 +
69690 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69691 new file mode 100644
69692 index 0000000..a89b1f4
69693 --- /dev/null
69694 +++ b/grsecurity/gracl_fs.c
69695 @@ -0,0 +1,437 @@
69696 +#include <linux/kernel.h>
69697 +#include <linux/sched.h>
69698 +#include <linux/types.h>
69699 +#include <linux/fs.h>
69700 +#include <linux/file.h>
69701 +#include <linux/stat.h>
69702 +#include <linux/grsecurity.h>
69703 +#include <linux/grinternal.h>
69704 +#include <linux/gracl.h>
69705 +
69706 +umode_t
69707 +gr_acl_umask(void)
69708 +{
69709 + if (unlikely(!gr_acl_is_enabled()))
69710 + return 0;
69711 +
69712 + return current->role->umask;
69713 +}
69714 +
69715 +__u32
69716 +gr_acl_handle_hidden_file(const struct dentry * dentry,
69717 + const struct vfsmount * mnt)
69718 +{
69719 + __u32 mode;
69720 +
69721 + if (unlikely(d_is_negative(dentry)))
69722 + return GR_FIND;
69723 +
69724 + mode =
69725 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69726 +
69727 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69728 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69729 + return mode;
69730 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69731 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69732 + return 0;
69733 + } else if (unlikely(!(mode & GR_FIND)))
69734 + return 0;
69735 +
69736 + return GR_FIND;
69737 +}
69738 +
69739 +__u32
69740 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69741 + int acc_mode)
69742 +{
69743 + __u32 reqmode = GR_FIND;
69744 + __u32 mode;
69745 +
69746 + if (unlikely(d_is_negative(dentry)))
69747 + return reqmode;
69748 +
69749 + if (acc_mode & MAY_APPEND)
69750 + reqmode |= GR_APPEND;
69751 + else if (acc_mode & MAY_WRITE)
69752 + reqmode |= GR_WRITE;
69753 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69754 + reqmode |= GR_READ;
69755 +
69756 + mode =
69757 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69758 + mnt);
69759 +
69760 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69761 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69762 + reqmode & GR_READ ? " reading" : "",
69763 + reqmode & GR_WRITE ? " writing" : reqmode &
69764 + GR_APPEND ? " appending" : "");
69765 + return reqmode;
69766 + } else
69767 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69768 + {
69769 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69770 + reqmode & GR_READ ? " reading" : "",
69771 + reqmode & GR_WRITE ? " writing" : reqmode &
69772 + GR_APPEND ? " appending" : "");
69773 + return 0;
69774 + } else if (unlikely((mode & reqmode) != reqmode))
69775 + return 0;
69776 +
69777 + return reqmode;
69778 +}
69779 +
69780 +__u32
69781 +gr_acl_handle_creat(const struct dentry * dentry,
69782 + const struct dentry * p_dentry,
69783 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69784 + const int imode)
69785 +{
69786 + __u32 reqmode = GR_WRITE | GR_CREATE;
69787 + __u32 mode;
69788 +
69789 + if (acc_mode & MAY_APPEND)
69790 + reqmode |= GR_APPEND;
69791 + // if a directory was required or the directory already exists, then
69792 + // don't count this open as a read
69793 + if ((acc_mode & MAY_READ) &&
69794 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69795 + reqmode |= GR_READ;
69796 + if ((open_flags & O_CREAT) &&
69797 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69798 + reqmode |= GR_SETID;
69799 +
69800 + mode =
69801 + gr_check_create(dentry, p_dentry, p_mnt,
69802 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69803 +
69804 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69805 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69806 + reqmode & GR_READ ? " reading" : "",
69807 + reqmode & GR_WRITE ? " writing" : reqmode &
69808 + GR_APPEND ? " appending" : "");
69809 + return reqmode;
69810 + } else
69811 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69812 + {
69813 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69814 + reqmode & GR_READ ? " reading" : "",
69815 + reqmode & GR_WRITE ? " writing" : reqmode &
69816 + GR_APPEND ? " appending" : "");
69817 + return 0;
69818 + } else if (unlikely((mode & reqmode) != reqmode))
69819 + return 0;
69820 +
69821 + return reqmode;
69822 +}
69823 +
69824 +__u32
69825 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69826 + const int fmode)
69827 +{
69828 + __u32 mode, reqmode = GR_FIND;
69829 +
69830 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69831 + reqmode |= GR_EXEC;
69832 + if (fmode & S_IWOTH)
69833 + reqmode |= GR_WRITE;
69834 + if (fmode & S_IROTH)
69835 + reqmode |= GR_READ;
69836 +
69837 + mode =
69838 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69839 + mnt);
69840 +
69841 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69842 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69843 + reqmode & GR_READ ? " reading" : "",
69844 + reqmode & GR_WRITE ? " writing" : "",
69845 + reqmode & GR_EXEC ? " executing" : "");
69846 + return reqmode;
69847 + } else
69848 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69849 + {
69850 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69851 + reqmode & GR_READ ? " reading" : "",
69852 + reqmode & GR_WRITE ? " writing" : "",
69853 + reqmode & GR_EXEC ? " executing" : "");
69854 + return 0;
69855 + } else if (unlikely((mode & reqmode) != reqmode))
69856 + return 0;
69857 +
69858 + return reqmode;
69859 +}
69860 +
69861 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69862 +{
69863 + __u32 mode;
69864 +
69865 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69866 +
69867 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69868 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69869 + return mode;
69870 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69871 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69872 + return 0;
69873 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69874 + return 0;
69875 +
69876 + return (reqmode);
69877 +}
69878 +
69879 +__u32
69880 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69881 +{
69882 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69883 +}
69884 +
69885 +__u32
69886 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69887 +{
69888 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69889 +}
69890 +
69891 +__u32
69892 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69893 +{
69894 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69895 +}
69896 +
69897 +__u32
69898 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69899 +{
69900 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69901 +}
69902 +
69903 +__u32
69904 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
69905 + umode_t *modeptr)
69906 +{
69907 + umode_t mode;
69908 +
69909 + *modeptr &= ~gr_acl_umask();
69910 + mode = *modeptr;
69911 +
69912 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
69913 + return 1;
69914 +
69915 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
69916 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
69917 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
69918 + GR_CHMOD_ACL_MSG);
69919 + } else {
69920 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
69921 + }
69922 +}
69923 +
69924 +__u32
69925 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
69926 +{
69927 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
69928 +}
69929 +
69930 +__u32
69931 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
69932 +{
69933 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
69934 +}
69935 +
69936 +__u32
69937 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
69938 +{
69939 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
69940 +}
69941 +
69942 +__u32
69943 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
69944 +{
69945 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
69946 +}
69947 +
69948 +__u32
69949 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
69950 +{
69951 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
69952 + GR_UNIXCONNECT_ACL_MSG);
69953 +}
69954 +
69955 +/* hardlinks require at minimum create and link permission,
69956 + any additional privilege required is based on the
69957 + privilege of the file being linked to
69958 +*/
69959 +__u32
69960 +gr_acl_handle_link(const struct dentry * new_dentry,
69961 + const struct dentry * parent_dentry,
69962 + const struct vfsmount * parent_mnt,
69963 + const struct dentry * old_dentry,
69964 + const struct vfsmount * old_mnt, const struct filename *to)
69965 +{
69966 + __u32 mode;
69967 + __u32 needmode = GR_CREATE | GR_LINK;
69968 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
69969 +
69970 + mode =
69971 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
69972 + old_mnt);
69973 +
69974 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
69975 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69976 + return mode;
69977 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69978 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69979 + return 0;
69980 + } else if (unlikely((mode & needmode) != needmode))
69981 + return 0;
69982 +
69983 + return 1;
69984 +}
69985 +
69986 +__u32
69987 +gr_acl_handle_symlink(const struct dentry * new_dentry,
69988 + const struct dentry * parent_dentry,
69989 + const struct vfsmount * parent_mnt, const struct filename *from)
69990 +{
69991 + __u32 needmode = GR_WRITE | GR_CREATE;
69992 + __u32 mode;
69993 +
69994 + mode =
69995 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
69996 + GR_CREATE | GR_AUDIT_CREATE |
69997 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
69998 +
69999 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70000 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70001 + return mode;
70002 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70003 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70004 + return 0;
70005 + } else if (unlikely((mode & needmode) != needmode))
70006 + return 0;
70007 +
70008 + return (GR_WRITE | GR_CREATE);
70009 +}
70010 +
70011 +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)
70012 +{
70013 + __u32 mode;
70014 +
70015 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70016 +
70017 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70018 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70019 + return mode;
70020 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70021 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70022 + return 0;
70023 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70024 + return 0;
70025 +
70026 + return (reqmode);
70027 +}
70028 +
70029 +__u32
70030 +gr_acl_handle_mknod(const struct dentry * new_dentry,
70031 + const struct dentry * parent_dentry,
70032 + const struct vfsmount * parent_mnt,
70033 + const int mode)
70034 +{
70035 + __u32 reqmode = GR_WRITE | GR_CREATE;
70036 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70037 + reqmode |= GR_SETID;
70038 +
70039 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70040 + reqmode, GR_MKNOD_ACL_MSG);
70041 +}
70042 +
70043 +__u32
70044 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
70045 + const struct dentry *parent_dentry,
70046 + const struct vfsmount *parent_mnt)
70047 +{
70048 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70049 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70050 +}
70051 +
70052 +#define RENAME_CHECK_SUCCESS(old, new) \
70053 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70054 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70055 +
70056 +int
70057 +gr_acl_handle_rename(struct dentry *new_dentry,
70058 + struct dentry *parent_dentry,
70059 + const struct vfsmount *parent_mnt,
70060 + struct dentry *old_dentry,
70061 + struct inode *old_parent_inode,
70062 + struct vfsmount *old_mnt, const struct filename *newname)
70063 +{
70064 + __u32 comp1, comp2;
70065 + int error = 0;
70066 +
70067 + if (unlikely(!gr_acl_is_enabled()))
70068 + return 0;
70069 +
70070 + if (d_is_negative(new_dentry)) {
70071 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70072 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70073 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70074 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70075 + GR_DELETE | GR_AUDIT_DELETE |
70076 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70077 + GR_SUPPRESS, old_mnt);
70078 + } else {
70079 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70080 + GR_CREATE | GR_DELETE |
70081 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70082 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70083 + GR_SUPPRESS, parent_mnt);
70084 + comp2 =
70085 + gr_search_file(old_dentry,
70086 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70087 + GR_DELETE | GR_AUDIT_DELETE |
70088 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70089 + }
70090 +
70091 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70092 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70093 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70094 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70095 + && !(comp2 & GR_SUPPRESS)) {
70096 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70097 + error = -EACCES;
70098 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70099 + error = -EACCES;
70100 +
70101 + return error;
70102 +}
70103 +
70104 +void
70105 +gr_acl_handle_exit(void)
70106 +{
70107 + u16 id;
70108 + char *rolename;
70109 +
70110 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70111 + !(current->role->roletype & GR_ROLE_PERSIST))) {
70112 + id = current->acl_role_id;
70113 + rolename = current->role->rolename;
70114 + gr_set_acls(1);
70115 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70116 + }
70117 +
70118 + gr_put_exec_file(current);
70119 + return;
70120 +}
70121 +
70122 +int
70123 +gr_acl_handle_procpidmem(const struct task_struct *task)
70124 +{
70125 + if (unlikely(!gr_acl_is_enabled()))
70126 + return 0;
70127 +
70128 + if (task != current && task->acl->mode & GR_PROTPROCFD)
70129 + return -EACCES;
70130 +
70131 + return 0;
70132 +}
70133 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70134 new file mode 100644
70135 index 0000000..f056b81
70136 --- /dev/null
70137 +++ b/grsecurity/gracl_ip.c
70138 @@ -0,0 +1,386 @@
70139 +#include <linux/kernel.h>
70140 +#include <asm/uaccess.h>
70141 +#include <asm/errno.h>
70142 +#include <net/sock.h>
70143 +#include <linux/file.h>
70144 +#include <linux/fs.h>
70145 +#include <linux/net.h>
70146 +#include <linux/in.h>
70147 +#include <linux/skbuff.h>
70148 +#include <linux/ip.h>
70149 +#include <linux/udp.h>
70150 +#include <linux/types.h>
70151 +#include <linux/sched.h>
70152 +#include <linux/netdevice.h>
70153 +#include <linux/inetdevice.h>
70154 +#include <linux/gracl.h>
70155 +#include <linux/grsecurity.h>
70156 +#include <linux/grinternal.h>
70157 +
70158 +#define GR_BIND 0x01
70159 +#define GR_CONNECT 0x02
70160 +#define GR_INVERT 0x04
70161 +#define GR_BINDOVERRIDE 0x08
70162 +#define GR_CONNECTOVERRIDE 0x10
70163 +#define GR_SOCK_FAMILY 0x20
70164 +
70165 +static const char * gr_protocols[IPPROTO_MAX] = {
70166 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70167 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70168 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70169 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70170 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70171 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70172 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70173 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70174 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70175 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70176 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70177 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70178 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70179 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70180 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70181 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70182 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70183 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70184 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70185 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70186 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70187 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70188 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70189 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70190 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70191 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70192 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70193 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70194 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70195 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70196 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70197 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70198 + };
70199 +
70200 +static const char * gr_socktypes[SOCK_MAX] = {
70201 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70202 + "unknown:7", "unknown:8", "unknown:9", "packet"
70203 + };
70204 +
70205 +static const char * gr_sockfamilies[AF_MAX+1] = {
70206 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70207 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70208 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70209 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70210 + };
70211 +
70212 +const char *
70213 +gr_proto_to_name(unsigned char proto)
70214 +{
70215 + return gr_protocols[proto];
70216 +}
70217 +
70218 +const char *
70219 +gr_socktype_to_name(unsigned char type)
70220 +{
70221 + return gr_socktypes[type];
70222 +}
70223 +
70224 +const char *
70225 +gr_sockfamily_to_name(unsigned char family)
70226 +{
70227 + return gr_sockfamilies[family];
70228 +}
70229 +
70230 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70231 +
70232 +int
70233 +gr_search_socket(const int domain, const int type, const int protocol)
70234 +{
70235 + struct acl_subject_label *curr;
70236 + const struct cred *cred = current_cred();
70237 +
70238 + if (unlikely(!gr_acl_is_enabled()))
70239 + goto exit;
70240 +
70241 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
70242 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70243 + goto exit; // let the kernel handle it
70244 +
70245 + curr = current->acl;
70246 +
70247 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70248 + /* the family is allowed, if this is PF_INET allow it only if
70249 + the extra sock type/protocol checks pass */
70250 + if (domain == PF_INET)
70251 + goto inet_check;
70252 + goto exit;
70253 + } else {
70254 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70255 + __u32 fakeip = 0;
70256 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70257 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70258 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70259 + gr_to_filename(current->exec_file->f_path.dentry,
70260 + current->exec_file->f_path.mnt) :
70261 + curr->filename, curr->filename,
70262 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70263 + &current->signal->saved_ip);
70264 + goto exit;
70265 + }
70266 + goto exit_fail;
70267 + }
70268 +
70269 +inet_check:
70270 + /* the rest of this checking is for IPv4 only */
70271 + if (!curr->ips)
70272 + goto exit;
70273 +
70274 + if ((curr->ip_type & (1U << type)) &&
70275 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70276 + goto exit;
70277 +
70278 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70279 + /* we don't place acls on raw sockets , and sometimes
70280 + dgram/ip sockets are opened for ioctl and not
70281 + bind/connect, so we'll fake a bind learn log */
70282 + if (type == SOCK_RAW || type == SOCK_PACKET) {
70283 + __u32 fakeip = 0;
70284 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70285 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70286 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70287 + gr_to_filename(current->exec_file->f_path.dentry,
70288 + current->exec_file->f_path.mnt) :
70289 + curr->filename, curr->filename,
70290 + &fakeip, 0, type,
70291 + protocol, GR_CONNECT, &current->signal->saved_ip);
70292 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70293 + __u32 fakeip = 0;
70294 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70295 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70296 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70297 + gr_to_filename(current->exec_file->f_path.dentry,
70298 + current->exec_file->f_path.mnt) :
70299 + curr->filename, curr->filename,
70300 + &fakeip, 0, type,
70301 + protocol, GR_BIND, &current->signal->saved_ip);
70302 + }
70303 + /* we'll log when they use connect or bind */
70304 + goto exit;
70305 + }
70306 +
70307 +exit_fail:
70308 + if (domain == PF_INET)
70309 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70310 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
70311 + else if (rcu_access_pointer(net_families[domain]) != NULL)
70312 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70313 + gr_socktype_to_name(type), protocol);
70314 +
70315 + return 0;
70316 +exit:
70317 + return 1;
70318 +}
70319 +
70320 +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)
70321 +{
70322 + if ((ip->mode & mode) &&
70323 + (ip_port >= ip->low) &&
70324 + (ip_port <= ip->high) &&
70325 + ((ntohl(ip_addr) & our_netmask) ==
70326 + (ntohl(our_addr) & our_netmask))
70327 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70328 + && (ip->type & (1U << type))) {
70329 + if (ip->mode & GR_INVERT)
70330 + return 2; // specifically denied
70331 + else
70332 + return 1; // allowed
70333 + }
70334 +
70335 + return 0; // not specifically allowed, may continue parsing
70336 +}
70337 +
70338 +static int
70339 +gr_search_connectbind(const int full_mode, struct sock *sk,
70340 + struct sockaddr_in *addr, const int type)
70341 +{
70342 + char iface[IFNAMSIZ] = {0};
70343 + struct acl_subject_label *curr;
70344 + struct acl_ip_label *ip;
70345 + struct inet_sock *isk;
70346 + struct net_device *dev;
70347 + struct in_device *idev;
70348 + unsigned long i;
70349 + int ret;
70350 + int mode = full_mode & (GR_BIND | GR_CONNECT);
70351 + __u32 ip_addr = 0;
70352 + __u32 our_addr;
70353 + __u32 our_netmask;
70354 + char *p;
70355 + __u16 ip_port = 0;
70356 + const struct cred *cred = current_cred();
70357 +
70358 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70359 + return 0;
70360 +
70361 + curr = current->acl;
70362 + isk = inet_sk(sk);
70363 +
70364 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70365 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70366 + addr->sin_addr.s_addr = curr->inaddr_any_override;
70367 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70368 + struct sockaddr_in saddr;
70369 + int err;
70370 +
70371 + saddr.sin_family = AF_INET;
70372 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
70373 + saddr.sin_port = isk->inet_sport;
70374 +
70375 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70376 + if (err)
70377 + return err;
70378 +
70379 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70380 + if (err)
70381 + return err;
70382 + }
70383 +
70384 + if (!curr->ips)
70385 + return 0;
70386 +
70387 + ip_addr = addr->sin_addr.s_addr;
70388 + ip_port = ntohs(addr->sin_port);
70389 +
70390 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70391 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70392 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70393 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70394 + gr_to_filename(current->exec_file->f_path.dentry,
70395 + current->exec_file->f_path.mnt) :
70396 + curr->filename, curr->filename,
70397 + &ip_addr, ip_port, type,
70398 + sk->sk_protocol, mode, &current->signal->saved_ip);
70399 + return 0;
70400 + }
70401 +
70402 + for (i = 0; i < curr->ip_num; i++) {
70403 + ip = *(curr->ips + i);
70404 + if (ip->iface != NULL) {
70405 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
70406 + p = strchr(iface, ':');
70407 + if (p != NULL)
70408 + *p = '\0';
70409 + dev = dev_get_by_name(sock_net(sk), iface);
70410 + if (dev == NULL)
70411 + continue;
70412 + idev = in_dev_get(dev);
70413 + if (idev == NULL) {
70414 + dev_put(dev);
70415 + continue;
70416 + }
70417 + rcu_read_lock();
70418 + for_ifa(idev) {
70419 + if (!strcmp(ip->iface, ifa->ifa_label)) {
70420 + our_addr = ifa->ifa_address;
70421 + our_netmask = 0xffffffff;
70422 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70423 + if (ret == 1) {
70424 + rcu_read_unlock();
70425 + in_dev_put(idev);
70426 + dev_put(dev);
70427 + return 0;
70428 + } else if (ret == 2) {
70429 + rcu_read_unlock();
70430 + in_dev_put(idev);
70431 + dev_put(dev);
70432 + goto denied;
70433 + }
70434 + }
70435 + } endfor_ifa(idev);
70436 + rcu_read_unlock();
70437 + in_dev_put(idev);
70438 + dev_put(dev);
70439 + } else {
70440 + our_addr = ip->addr;
70441 + our_netmask = ip->netmask;
70442 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70443 + if (ret == 1)
70444 + return 0;
70445 + else if (ret == 2)
70446 + goto denied;
70447 + }
70448 + }
70449 +
70450 +denied:
70451 + if (mode == GR_BIND)
70452 + 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));
70453 + else if (mode == GR_CONNECT)
70454 + 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));
70455 +
70456 + return -EACCES;
70457 +}
70458 +
70459 +int
70460 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70461 +{
70462 + /* always allow disconnection of dgram sockets with connect */
70463 + if (addr->sin_family == AF_UNSPEC)
70464 + return 0;
70465 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70466 +}
70467 +
70468 +int
70469 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70470 +{
70471 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70472 +}
70473 +
70474 +int gr_search_listen(struct socket *sock)
70475 +{
70476 + struct sock *sk = sock->sk;
70477 + struct sockaddr_in addr;
70478 +
70479 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70480 + addr.sin_port = inet_sk(sk)->inet_sport;
70481 +
70482 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70483 +}
70484 +
70485 +int gr_search_accept(struct socket *sock)
70486 +{
70487 + struct sock *sk = sock->sk;
70488 + struct sockaddr_in addr;
70489 +
70490 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70491 + addr.sin_port = inet_sk(sk)->inet_sport;
70492 +
70493 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70494 +}
70495 +
70496 +int
70497 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70498 +{
70499 + if (addr)
70500 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70501 + else {
70502 + struct sockaddr_in sin;
70503 + const struct inet_sock *inet = inet_sk(sk);
70504 +
70505 + sin.sin_addr.s_addr = inet->inet_daddr;
70506 + sin.sin_port = inet->inet_dport;
70507 +
70508 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70509 + }
70510 +}
70511 +
70512 +int
70513 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70514 +{
70515 + struct sockaddr_in sin;
70516 +
70517 + if (unlikely(skb->len < sizeof (struct udphdr)))
70518 + return 0; // skip this packet
70519 +
70520 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70521 + sin.sin_port = udp_hdr(skb)->source;
70522 +
70523 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70524 +}
70525 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70526 new file mode 100644
70527 index 0000000..25f54ef
70528 --- /dev/null
70529 +++ b/grsecurity/gracl_learn.c
70530 @@ -0,0 +1,207 @@
70531 +#include <linux/kernel.h>
70532 +#include <linux/mm.h>
70533 +#include <linux/sched.h>
70534 +#include <linux/poll.h>
70535 +#include <linux/string.h>
70536 +#include <linux/file.h>
70537 +#include <linux/types.h>
70538 +#include <linux/vmalloc.h>
70539 +#include <linux/grinternal.h>
70540 +
70541 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70542 + size_t count, loff_t *ppos);
70543 +extern int gr_acl_is_enabled(void);
70544 +
70545 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70546 +static int gr_learn_attached;
70547 +
70548 +/* use a 512k buffer */
70549 +#define LEARN_BUFFER_SIZE (512 * 1024)
70550 +
70551 +static DEFINE_SPINLOCK(gr_learn_lock);
70552 +static DEFINE_MUTEX(gr_learn_user_mutex);
70553 +
70554 +/* we need to maintain two buffers, so that the kernel context of grlearn
70555 + uses a semaphore around the userspace copying, and the other kernel contexts
70556 + use a spinlock when copying into the buffer, since they cannot sleep
70557 +*/
70558 +static char *learn_buffer;
70559 +static char *learn_buffer_user;
70560 +static int learn_buffer_len;
70561 +static int learn_buffer_user_len;
70562 +
70563 +static ssize_t
70564 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70565 +{
70566 + DECLARE_WAITQUEUE(wait, current);
70567 + ssize_t retval = 0;
70568 +
70569 + add_wait_queue(&learn_wait, &wait);
70570 + set_current_state(TASK_INTERRUPTIBLE);
70571 + do {
70572 + mutex_lock(&gr_learn_user_mutex);
70573 + spin_lock(&gr_learn_lock);
70574 + if (learn_buffer_len)
70575 + break;
70576 + spin_unlock(&gr_learn_lock);
70577 + mutex_unlock(&gr_learn_user_mutex);
70578 + if (file->f_flags & O_NONBLOCK) {
70579 + retval = -EAGAIN;
70580 + goto out;
70581 + }
70582 + if (signal_pending(current)) {
70583 + retval = -ERESTARTSYS;
70584 + goto out;
70585 + }
70586 +
70587 + schedule();
70588 + } while (1);
70589 +
70590 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70591 + learn_buffer_user_len = learn_buffer_len;
70592 + retval = learn_buffer_len;
70593 + learn_buffer_len = 0;
70594 +
70595 + spin_unlock(&gr_learn_lock);
70596 +
70597 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70598 + retval = -EFAULT;
70599 +
70600 + mutex_unlock(&gr_learn_user_mutex);
70601 +out:
70602 + set_current_state(TASK_RUNNING);
70603 + remove_wait_queue(&learn_wait, &wait);
70604 + return retval;
70605 +}
70606 +
70607 +static unsigned int
70608 +poll_learn(struct file * file, poll_table * wait)
70609 +{
70610 + poll_wait(file, &learn_wait, wait);
70611 +
70612 + if (learn_buffer_len)
70613 + return (POLLIN | POLLRDNORM);
70614 +
70615 + return 0;
70616 +}
70617 +
70618 +void
70619 +gr_clear_learn_entries(void)
70620 +{
70621 + char *tmp;
70622 +
70623 + mutex_lock(&gr_learn_user_mutex);
70624 + spin_lock(&gr_learn_lock);
70625 + tmp = learn_buffer;
70626 + learn_buffer = NULL;
70627 + spin_unlock(&gr_learn_lock);
70628 + if (tmp)
70629 + vfree(tmp);
70630 + if (learn_buffer_user != NULL) {
70631 + vfree(learn_buffer_user);
70632 + learn_buffer_user = NULL;
70633 + }
70634 + learn_buffer_len = 0;
70635 + mutex_unlock(&gr_learn_user_mutex);
70636 +
70637 + return;
70638 +}
70639 +
70640 +void
70641 +gr_add_learn_entry(const char *fmt, ...)
70642 +{
70643 + va_list args;
70644 + unsigned int len;
70645 +
70646 + if (!gr_learn_attached)
70647 + return;
70648 +
70649 + spin_lock(&gr_learn_lock);
70650 +
70651 + /* leave a gap at the end so we know when it's "full" but don't have to
70652 + compute the exact length of the string we're trying to append
70653 + */
70654 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70655 + spin_unlock(&gr_learn_lock);
70656 + wake_up_interruptible(&learn_wait);
70657 + return;
70658 + }
70659 + if (learn_buffer == NULL) {
70660 + spin_unlock(&gr_learn_lock);
70661 + return;
70662 + }
70663 +
70664 + va_start(args, fmt);
70665 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70666 + va_end(args);
70667 +
70668 + learn_buffer_len += len + 1;
70669 +
70670 + spin_unlock(&gr_learn_lock);
70671 + wake_up_interruptible(&learn_wait);
70672 +
70673 + return;
70674 +}
70675 +
70676 +static int
70677 +open_learn(struct inode *inode, struct file *file)
70678 +{
70679 + if (file->f_mode & FMODE_READ && gr_learn_attached)
70680 + return -EBUSY;
70681 + if (file->f_mode & FMODE_READ) {
70682 + int retval = 0;
70683 + mutex_lock(&gr_learn_user_mutex);
70684 + if (learn_buffer == NULL)
70685 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70686 + if (learn_buffer_user == NULL)
70687 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70688 + if (learn_buffer == NULL) {
70689 + retval = -ENOMEM;
70690 + goto out_error;
70691 + }
70692 + if (learn_buffer_user == NULL) {
70693 + retval = -ENOMEM;
70694 + goto out_error;
70695 + }
70696 + learn_buffer_len = 0;
70697 + learn_buffer_user_len = 0;
70698 + gr_learn_attached = 1;
70699 +out_error:
70700 + mutex_unlock(&gr_learn_user_mutex);
70701 + return retval;
70702 + }
70703 + return 0;
70704 +}
70705 +
70706 +static int
70707 +close_learn(struct inode *inode, struct file *file)
70708 +{
70709 + if (file->f_mode & FMODE_READ) {
70710 + char *tmp = NULL;
70711 + mutex_lock(&gr_learn_user_mutex);
70712 + spin_lock(&gr_learn_lock);
70713 + tmp = learn_buffer;
70714 + learn_buffer = NULL;
70715 + spin_unlock(&gr_learn_lock);
70716 + if (tmp)
70717 + vfree(tmp);
70718 + if (learn_buffer_user != NULL) {
70719 + vfree(learn_buffer_user);
70720 + learn_buffer_user = NULL;
70721 + }
70722 + learn_buffer_len = 0;
70723 + learn_buffer_user_len = 0;
70724 + gr_learn_attached = 0;
70725 + mutex_unlock(&gr_learn_user_mutex);
70726 + }
70727 +
70728 + return 0;
70729 +}
70730 +
70731 +const struct file_operations grsec_fops = {
70732 + .read = read_learn,
70733 + .write = write_grsec_handler,
70734 + .open = open_learn,
70735 + .release = close_learn,
70736 + .poll = poll_learn,
70737 +};
70738 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70739 new file mode 100644
70740 index 0000000..361a099
70741 --- /dev/null
70742 +++ b/grsecurity/gracl_policy.c
70743 @@ -0,0 +1,1782 @@
70744 +#include <linux/kernel.h>
70745 +#include <linux/module.h>
70746 +#include <linux/sched.h>
70747 +#include <linux/mm.h>
70748 +#include <linux/file.h>
70749 +#include <linux/fs.h>
70750 +#include <linux/namei.h>
70751 +#include <linux/mount.h>
70752 +#include <linux/tty.h>
70753 +#include <linux/proc_fs.h>
70754 +#include <linux/lglock.h>
70755 +#include <linux/slab.h>
70756 +#include <linux/vmalloc.h>
70757 +#include <linux/types.h>
70758 +#include <linux/sysctl.h>
70759 +#include <linux/netdevice.h>
70760 +#include <linux/ptrace.h>
70761 +#include <linux/gracl.h>
70762 +#include <linux/gralloc.h>
70763 +#include <linux/security.h>
70764 +#include <linux/grinternal.h>
70765 +#include <linux/pid_namespace.h>
70766 +#include <linux/stop_machine.h>
70767 +#include <linux/fdtable.h>
70768 +#include <linux/percpu.h>
70769 +#include <linux/lglock.h>
70770 +#include <linux/hugetlb.h>
70771 +#include <linux/posix-timers.h>
70772 +#include "../fs/mount.h"
70773 +
70774 +#include <asm/uaccess.h>
70775 +#include <asm/errno.h>
70776 +#include <asm/mman.h>
70777 +
70778 +extern struct gr_policy_state *polstate;
70779 +
70780 +#define FOR_EACH_ROLE_START(role) \
70781 + role = polstate->role_list; \
70782 + while (role) {
70783 +
70784 +#define FOR_EACH_ROLE_END(role) \
70785 + role = role->prev; \
70786 + }
70787 +
70788 +struct path gr_real_root;
70789 +
70790 +extern struct gr_alloc_state *current_alloc_state;
70791 +
70792 +u16 acl_sp_role_value;
70793 +
70794 +static DEFINE_MUTEX(gr_dev_mutex);
70795 +
70796 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70797 +extern void gr_clear_learn_entries(void);
70798 +
70799 +static struct gr_arg gr_usermode;
70800 +static unsigned char gr_system_salt[GR_SALT_LEN];
70801 +static unsigned char gr_system_sum[GR_SHA_LEN];
70802 +
70803 +static unsigned int gr_auth_attempts = 0;
70804 +static unsigned long gr_auth_expires = 0UL;
70805 +
70806 +struct acl_object_label *fakefs_obj_rw;
70807 +struct acl_object_label *fakefs_obj_rwx;
70808 +
70809 +extern int gr_init_uidset(void);
70810 +extern void gr_free_uidset(void);
70811 +extern void gr_remove_uid(uid_t uid);
70812 +extern int gr_find_uid(uid_t uid);
70813 +
70814 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70815 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70816 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70817 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70818 +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);
70819 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70820 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70821 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70822 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70823 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70824 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70825 +extern void assign_special_role(const char *rolename);
70826 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70827 +extern int gr_rbac_disable(void *unused);
70828 +extern void gr_enable_rbac_system(void);
70829 +
70830 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70831 +{
70832 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70833 + return -EFAULT;
70834 +
70835 + return 0;
70836 +}
70837 +
70838 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70839 +{
70840 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70841 + return -EFAULT;
70842 +
70843 + return 0;
70844 +}
70845 +
70846 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70847 +{
70848 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70849 + return -EFAULT;
70850 +
70851 + return 0;
70852 +}
70853 +
70854 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70855 +{
70856 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70857 + return -EFAULT;
70858 +
70859 + return 0;
70860 +}
70861 +
70862 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70863 +{
70864 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70865 + return -EFAULT;
70866 +
70867 + return 0;
70868 +}
70869 +
70870 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70871 +{
70872 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70873 + return -EFAULT;
70874 +
70875 + return 0;
70876 +}
70877 +
70878 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70879 +{
70880 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70881 + return -EFAULT;
70882 +
70883 + return 0;
70884 +}
70885 +
70886 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70887 +{
70888 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70889 + return -EFAULT;
70890 +
70891 + return 0;
70892 +}
70893 +
70894 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70895 +{
70896 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70897 + return -EFAULT;
70898 +
70899 + return 0;
70900 +}
70901 +
70902 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
70903 +{
70904 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
70905 + return -EFAULT;
70906 +
70907 + if (((uwrap->version != GRSECURITY_VERSION) &&
70908 + (uwrap->version != 0x2901)) ||
70909 + (uwrap->size != sizeof(struct gr_arg)))
70910 + return -EINVAL;
70911 +
70912 + return 0;
70913 +}
70914 +
70915 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
70916 +{
70917 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
70918 + return -EFAULT;
70919 +
70920 + return 0;
70921 +}
70922 +
70923 +static size_t get_gr_arg_wrapper_size_normal(void)
70924 +{
70925 + return sizeof(struct gr_arg_wrapper);
70926 +}
70927 +
70928 +#ifdef CONFIG_COMPAT
70929 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
70930 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
70931 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
70932 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
70933 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
70934 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
70935 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
70936 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
70937 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
70938 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
70939 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
70940 +extern size_t get_gr_arg_wrapper_size_compat(void);
70941 +
70942 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
70943 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
70944 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
70945 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
70946 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
70947 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
70948 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
70949 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
70950 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
70951 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
70952 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
70953 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
70954 +
70955 +#else
70956 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
70957 +#define copy_gr_arg copy_gr_arg_normal
70958 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
70959 +#define copy_acl_object_label copy_acl_object_label_normal
70960 +#define copy_acl_subject_label copy_acl_subject_label_normal
70961 +#define copy_acl_role_label copy_acl_role_label_normal
70962 +#define copy_acl_ip_label copy_acl_ip_label_normal
70963 +#define copy_pointer_from_array copy_pointer_from_array_normal
70964 +#define copy_sprole_pw copy_sprole_pw_normal
70965 +#define copy_role_transition copy_role_transition_normal
70966 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
70967 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
70968 +#endif
70969 +
70970 +static struct acl_subject_label *
70971 +lookup_subject_map(const struct acl_subject_label *userp)
70972 +{
70973 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
70974 + struct subject_map *match;
70975 +
70976 + match = polstate->subj_map_set.s_hash[index];
70977 +
70978 + while (match && match->user != userp)
70979 + match = match->next;
70980 +
70981 + if (match != NULL)
70982 + return match->kernel;
70983 + else
70984 + return NULL;
70985 +}
70986 +
70987 +static void
70988 +insert_subj_map_entry(struct subject_map *subjmap)
70989 +{
70990 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
70991 + struct subject_map **curr;
70992 +
70993 + subjmap->prev = NULL;
70994 +
70995 + curr = &polstate->subj_map_set.s_hash[index];
70996 + if (*curr != NULL)
70997 + (*curr)->prev = subjmap;
70998 +
70999 + subjmap->next = *curr;
71000 + *curr = subjmap;
71001 +
71002 + return;
71003 +}
71004 +
71005 +static void
71006 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71007 +{
71008 + unsigned int index =
71009 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71010 + struct acl_role_label **curr;
71011 + struct acl_role_label *tmp, *tmp2;
71012 +
71013 + curr = &polstate->acl_role_set.r_hash[index];
71014 +
71015 + /* simple case, slot is empty, just set it to our role */
71016 + if (*curr == NULL) {
71017 + *curr = role;
71018 + } else {
71019 + /* example:
71020 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
71021 + 2 -> 3
71022 + */
71023 + /* first check to see if we can already be reached via this slot */
71024 + tmp = *curr;
71025 + while (tmp && tmp != role)
71026 + tmp = tmp->next;
71027 + if (tmp == role) {
71028 + /* we don't need to add ourselves to this slot's chain */
71029 + return;
71030 + }
71031 + /* we need to add ourselves to this chain, two cases */
71032 + if (role->next == NULL) {
71033 + /* simple case, append the current chain to our role */
71034 + role->next = *curr;
71035 + *curr = role;
71036 + } else {
71037 + /* 1 -> 2 -> 3 -> 4
71038 + 2 -> 3 -> 4
71039 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71040 + */
71041 + /* trickier case: walk our role's chain until we find
71042 + the role for the start of the current slot's chain */
71043 + tmp = role;
71044 + tmp2 = *curr;
71045 + while (tmp->next && tmp->next != tmp2)
71046 + tmp = tmp->next;
71047 + if (tmp->next == tmp2) {
71048 + /* from example above, we found 3, so just
71049 + replace this slot's chain with ours */
71050 + *curr = role;
71051 + } else {
71052 + /* we didn't find a subset of our role's chain
71053 + in the current slot's chain, so append their
71054 + chain to ours, and set us as the first role in
71055 + the slot's chain
71056 +
71057 + we could fold this case with the case above,
71058 + but making it explicit for clarity
71059 + */
71060 + tmp->next = tmp2;
71061 + *curr = role;
71062 + }
71063 + }
71064 + }
71065 +
71066 + return;
71067 +}
71068 +
71069 +static void
71070 +insert_acl_role_label(struct acl_role_label *role)
71071 +{
71072 + int i;
71073 +
71074 + if (polstate->role_list == NULL) {
71075 + polstate->role_list = role;
71076 + role->prev = NULL;
71077 + } else {
71078 + role->prev = polstate->role_list;
71079 + polstate->role_list = role;
71080 + }
71081 +
71082 + /* used for hash chains */
71083 + role->next = NULL;
71084 +
71085 + if (role->roletype & GR_ROLE_DOMAIN) {
71086 + for (i = 0; i < role->domain_child_num; i++)
71087 + __insert_acl_role_label(role, role->domain_children[i]);
71088 + } else
71089 + __insert_acl_role_label(role, role->uidgid);
71090 +}
71091 +
71092 +static int
71093 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71094 +{
71095 + struct name_entry **curr, *nentry;
71096 + struct inodev_entry *ientry;
71097 + unsigned int len = strlen(name);
71098 + unsigned int key = full_name_hash(name, len);
71099 + unsigned int index = key % polstate->name_set.n_size;
71100 +
71101 + curr = &polstate->name_set.n_hash[index];
71102 +
71103 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71104 + curr = &((*curr)->next);
71105 +
71106 + if (*curr != NULL)
71107 + return 1;
71108 +
71109 + nentry = acl_alloc(sizeof (struct name_entry));
71110 + if (nentry == NULL)
71111 + return 0;
71112 + ientry = acl_alloc(sizeof (struct inodev_entry));
71113 + if (ientry == NULL)
71114 + return 0;
71115 + ientry->nentry = nentry;
71116 +
71117 + nentry->key = key;
71118 + nentry->name = name;
71119 + nentry->inode = inode;
71120 + nentry->device = device;
71121 + nentry->len = len;
71122 + nentry->deleted = deleted;
71123 +
71124 + nentry->prev = NULL;
71125 + curr = &polstate->name_set.n_hash[index];
71126 + if (*curr != NULL)
71127 + (*curr)->prev = nentry;
71128 + nentry->next = *curr;
71129 + *curr = nentry;
71130 +
71131 + /* insert us into the table searchable by inode/dev */
71132 + __insert_inodev_entry(polstate, ientry);
71133 +
71134 + return 1;
71135 +}
71136 +
71137 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71138 +
71139 +static void *
71140 +create_table(__u32 * len, int elementsize)
71141 +{
71142 + unsigned int table_sizes[] = {
71143 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71144 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71145 + 4194301, 8388593, 16777213, 33554393, 67108859
71146 + };
71147 + void *newtable = NULL;
71148 + unsigned int pwr = 0;
71149 +
71150 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71151 + table_sizes[pwr] <= *len)
71152 + pwr++;
71153 +
71154 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71155 + return newtable;
71156 +
71157 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71158 + newtable =
71159 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71160 + else
71161 + newtable = vmalloc(table_sizes[pwr] * elementsize);
71162 +
71163 + *len = table_sizes[pwr];
71164 +
71165 + return newtable;
71166 +}
71167 +
71168 +static int
71169 +init_variables(const struct gr_arg *arg, bool reload)
71170 +{
71171 + struct task_struct *reaper = init_pid_ns.child_reaper;
71172 + unsigned int stacksize;
71173 +
71174 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71175 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71176 + polstate->name_set.n_size = arg->role_db.num_objects;
71177 + polstate->inodev_set.i_size = arg->role_db.num_objects;
71178 +
71179 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71180 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71181 + return 1;
71182 +
71183 + if (!reload) {
71184 + if (!gr_init_uidset())
71185 + return 1;
71186 + }
71187 +
71188 + /* set up the stack that holds allocation info */
71189 +
71190 + stacksize = arg->role_db.num_pointers + 5;
71191 +
71192 + if (!acl_alloc_stack_init(stacksize))
71193 + return 1;
71194 +
71195 + if (!reload) {
71196 + /* grab reference for the real root dentry and vfsmount */
71197 + get_fs_root(reaper->fs, &gr_real_root);
71198 +
71199 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71200 + 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);
71201 +#endif
71202 +
71203 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71204 + if (fakefs_obj_rw == NULL)
71205 + return 1;
71206 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71207 +
71208 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71209 + if (fakefs_obj_rwx == NULL)
71210 + return 1;
71211 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71212 + }
71213 +
71214 + polstate->subj_map_set.s_hash =
71215 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71216 + polstate->acl_role_set.r_hash =
71217 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71218 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71219 + polstate->inodev_set.i_hash =
71220 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71221 +
71222 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71223 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71224 + return 1;
71225 +
71226 + memset(polstate->subj_map_set.s_hash, 0,
71227 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71228 + memset(polstate->acl_role_set.r_hash, 0,
71229 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71230 + memset(polstate->name_set.n_hash, 0,
71231 + sizeof (struct name_entry *) * polstate->name_set.n_size);
71232 + memset(polstate->inodev_set.i_hash, 0,
71233 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71234 +
71235 + return 0;
71236 +}
71237 +
71238 +/* free information not needed after startup
71239 + currently contains user->kernel pointer mappings for subjects
71240 +*/
71241 +
71242 +static void
71243 +free_init_variables(void)
71244 +{
71245 + __u32 i;
71246 +
71247 + if (polstate->subj_map_set.s_hash) {
71248 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71249 + if (polstate->subj_map_set.s_hash[i]) {
71250 + kfree(polstate->subj_map_set.s_hash[i]);
71251 + polstate->subj_map_set.s_hash[i] = NULL;
71252 + }
71253 + }
71254 +
71255 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71256 + PAGE_SIZE)
71257 + kfree(polstate->subj_map_set.s_hash);
71258 + else
71259 + vfree(polstate->subj_map_set.s_hash);
71260 + }
71261 +
71262 + return;
71263 +}
71264 +
71265 +static void
71266 +free_variables(bool reload)
71267 +{
71268 + struct acl_subject_label *s;
71269 + struct acl_role_label *r;
71270 + struct task_struct *task, *task2;
71271 + unsigned int x;
71272 +
71273 + if (!reload) {
71274 + gr_clear_learn_entries();
71275 +
71276 + read_lock(&tasklist_lock);
71277 + do_each_thread(task2, task) {
71278 + task->acl_sp_role = 0;
71279 + task->acl_role_id = 0;
71280 + task->inherited = 0;
71281 + task->acl = NULL;
71282 + task->role = NULL;
71283 + } while_each_thread(task2, task);
71284 + read_unlock(&tasklist_lock);
71285 +
71286 + kfree(fakefs_obj_rw);
71287 + fakefs_obj_rw = NULL;
71288 + kfree(fakefs_obj_rwx);
71289 + fakefs_obj_rwx = NULL;
71290 +
71291 + /* release the reference to the real root dentry and vfsmount */
71292 + path_put(&gr_real_root);
71293 + memset(&gr_real_root, 0, sizeof(gr_real_root));
71294 + }
71295 +
71296 + /* free all object hash tables */
71297 +
71298 + FOR_EACH_ROLE_START(r)
71299 + if (r->subj_hash == NULL)
71300 + goto next_role;
71301 + FOR_EACH_SUBJECT_START(r, s, x)
71302 + if (s->obj_hash == NULL)
71303 + break;
71304 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71305 + kfree(s->obj_hash);
71306 + else
71307 + vfree(s->obj_hash);
71308 + FOR_EACH_SUBJECT_END(s, x)
71309 + FOR_EACH_NESTED_SUBJECT_START(r, s)
71310 + if (s->obj_hash == NULL)
71311 + break;
71312 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71313 + kfree(s->obj_hash);
71314 + else
71315 + vfree(s->obj_hash);
71316 + FOR_EACH_NESTED_SUBJECT_END(s)
71317 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71318 + kfree(r->subj_hash);
71319 + else
71320 + vfree(r->subj_hash);
71321 + r->subj_hash = NULL;
71322 +next_role:
71323 + FOR_EACH_ROLE_END(r)
71324 +
71325 + acl_free_all();
71326 +
71327 + if (polstate->acl_role_set.r_hash) {
71328 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71329 + PAGE_SIZE)
71330 + kfree(polstate->acl_role_set.r_hash);
71331 + else
71332 + vfree(polstate->acl_role_set.r_hash);
71333 + }
71334 + if (polstate->name_set.n_hash) {
71335 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71336 + PAGE_SIZE)
71337 + kfree(polstate->name_set.n_hash);
71338 + else
71339 + vfree(polstate->name_set.n_hash);
71340 + }
71341 +
71342 + if (polstate->inodev_set.i_hash) {
71343 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71344 + PAGE_SIZE)
71345 + kfree(polstate->inodev_set.i_hash);
71346 + else
71347 + vfree(polstate->inodev_set.i_hash);
71348 + }
71349 +
71350 + if (!reload)
71351 + gr_free_uidset();
71352 +
71353 + memset(&polstate->name_set, 0, sizeof (struct name_db));
71354 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71355 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71356 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71357 +
71358 + polstate->default_role = NULL;
71359 + polstate->kernel_role = NULL;
71360 + polstate->role_list = NULL;
71361 +
71362 + return;
71363 +}
71364 +
71365 +static struct acl_subject_label *
71366 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71367 +
71368 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
71369 +{
71370 + unsigned int len = strnlen_user(*name, maxlen);
71371 + char *tmp;
71372 +
71373 + if (!len || len >= maxlen)
71374 + return -EINVAL;
71375 +
71376 + if ((tmp = (char *) acl_alloc(len)) == NULL)
71377 + return -ENOMEM;
71378 +
71379 + if (copy_from_user(tmp, *name, len))
71380 + return -EFAULT;
71381 +
71382 + tmp[len-1] = '\0';
71383 + *name = tmp;
71384 +
71385 + return 0;
71386 +}
71387 +
71388 +static int
71389 +copy_user_glob(struct acl_object_label *obj)
71390 +{
71391 + struct acl_object_label *g_tmp, **guser;
71392 + int error;
71393 +
71394 + if (obj->globbed == NULL)
71395 + return 0;
71396 +
71397 + guser = &obj->globbed;
71398 + while (*guser) {
71399 + g_tmp = (struct acl_object_label *)
71400 + acl_alloc(sizeof (struct acl_object_label));
71401 + if (g_tmp == NULL)
71402 + return -ENOMEM;
71403 +
71404 + if (copy_acl_object_label(g_tmp, *guser))
71405 + return -EFAULT;
71406 +
71407 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71408 + if (error)
71409 + return error;
71410 +
71411 + *guser = g_tmp;
71412 + guser = &(g_tmp->next);
71413 + }
71414 +
71415 + return 0;
71416 +}
71417 +
71418 +static int
71419 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71420 + struct acl_role_label *role)
71421 +{
71422 + struct acl_object_label *o_tmp;
71423 + int ret;
71424 +
71425 + while (userp) {
71426 + if ((o_tmp = (struct acl_object_label *)
71427 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
71428 + return -ENOMEM;
71429 +
71430 + if (copy_acl_object_label(o_tmp, userp))
71431 + return -EFAULT;
71432 +
71433 + userp = o_tmp->prev;
71434 +
71435 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71436 + if (ret)
71437 + return ret;
71438 +
71439 + insert_acl_obj_label(o_tmp, subj);
71440 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71441 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71442 + return -ENOMEM;
71443 +
71444 + ret = copy_user_glob(o_tmp);
71445 + if (ret)
71446 + return ret;
71447 +
71448 + if (o_tmp->nested) {
71449 + int already_copied;
71450 +
71451 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71452 + if (IS_ERR(o_tmp->nested))
71453 + return PTR_ERR(o_tmp->nested);
71454 +
71455 + /* insert into nested subject list if we haven't copied this one yet
71456 + to prevent duplicate entries */
71457 + if (!already_copied) {
71458 + o_tmp->nested->next = role->hash->first;
71459 + role->hash->first = o_tmp->nested;
71460 + }
71461 + }
71462 + }
71463 +
71464 + return 0;
71465 +}
71466 +
71467 +static __u32
71468 +count_user_subjs(struct acl_subject_label *userp)
71469 +{
71470 + struct acl_subject_label s_tmp;
71471 + __u32 num = 0;
71472 +
71473 + while (userp) {
71474 + if (copy_acl_subject_label(&s_tmp, userp))
71475 + break;
71476 +
71477 + userp = s_tmp.prev;
71478 + }
71479 +
71480 + return num;
71481 +}
71482 +
71483 +static int
71484 +copy_user_allowedips(struct acl_role_label *rolep)
71485 +{
71486 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71487 +
71488 + ruserip = rolep->allowed_ips;
71489 +
71490 + while (ruserip) {
71491 + rlast = rtmp;
71492 +
71493 + if ((rtmp = (struct role_allowed_ip *)
71494 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71495 + return -ENOMEM;
71496 +
71497 + if (copy_role_allowed_ip(rtmp, ruserip))
71498 + return -EFAULT;
71499 +
71500 + ruserip = rtmp->prev;
71501 +
71502 + if (!rlast) {
71503 + rtmp->prev = NULL;
71504 + rolep->allowed_ips = rtmp;
71505 + } else {
71506 + rlast->next = rtmp;
71507 + rtmp->prev = rlast;
71508 + }
71509 +
71510 + if (!ruserip)
71511 + rtmp->next = NULL;
71512 + }
71513 +
71514 + return 0;
71515 +}
71516 +
71517 +static int
71518 +copy_user_transitions(struct acl_role_label *rolep)
71519 +{
71520 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
71521 + int error;
71522 +
71523 + rusertp = rolep->transitions;
71524 +
71525 + while (rusertp) {
71526 + rlast = rtmp;
71527 +
71528 + if ((rtmp = (struct role_transition *)
71529 + acl_alloc(sizeof (struct role_transition))) == NULL)
71530 + return -ENOMEM;
71531 +
71532 + if (copy_role_transition(rtmp, rusertp))
71533 + return -EFAULT;
71534 +
71535 + rusertp = rtmp->prev;
71536 +
71537 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71538 + if (error)
71539 + return error;
71540 +
71541 + if (!rlast) {
71542 + rtmp->prev = NULL;
71543 + rolep->transitions = rtmp;
71544 + } else {
71545 + rlast->next = rtmp;
71546 + rtmp->prev = rlast;
71547 + }
71548 +
71549 + if (!rusertp)
71550 + rtmp->next = NULL;
71551 + }
71552 +
71553 + return 0;
71554 +}
71555 +
71556 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
71557 +{
71558 + struct acl_object_label o_tmp;
71559 + __u32 num = 0;
71560 +
71561 + while (userp) {
71562 + if (copy_acl_object_label(&o_tmp, userp))
71563 + break;
71564 +
71565 + userp = o_tmp.prev;
71566 + num++;
71567 + }
71568 +
71569 + return num;
71570 +}
71571 +
71572 +static struct acl_subject_label *
71573 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71574 +{
71575 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71576 + __u32 num_objs;
71577 + struct acl_ip_label **i_tmp, *i_utmp2;
71578 + struct gr_hash_struct ghash;
71579 + struct subject_map *subjmap;
71580 + unsigned int i_num;
71581 + int err;
71582 +
71583 + if (already_copied != NULL)
71584 + *already_copied = 0;
71585 +
71586 + s_tmp = lookup_subject_map(userp);
71587 +
71588 + /* we've already copied this subject into the kernel, just return
71589 + the reference to it, and don't copy it over again
71590 + */
71591 + if (s_tmp) {
71592 + if (already_copied != NULL)
71593 + *already_copied = 1;
71594 + return(s_tmp);
71595 + }
71596 +
71597 + if ((s_tmp = (struct acl_subject_label *)
71598 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71599 + return ERR_PTR(-ENOMEM);
71600 +
71601 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71602 + if (subjmap == NULL)
71603 + return ERR_PTR(-ENOMEM);
71604 +
71605 + subjmap->user = userp;
71606 + subjmap->kernel = s_tmp;
71607 + insert_subj_map_entry(subjmap);
71608 +
71609 + if (copy_acl_subject_label(s_tmp, userp))
71610 + return ERR_PTR(-EFAULT);
71611 +
71612 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71613 + if (err)
71614 + return ERR_PTR(err);
71615 +
71616 + if (!strcmp(s_tmp->filename, "/"))
71617 + role->root_label = s_tmp;
71618 +
71619 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71620 + return ERR_PTR(-EFAULT);
71621 +
71622 + /* copy user and group transition tables */
71623 +
71624 + if (s_tmp->user_trans_num) {
71625 + uid_t *uidlist;
71626 +
71627 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71628 + if (uidlist == NULL)
71629 + return ERR_PTR(-ENOMEM);
71630 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71631 + return ERR_PTR(-EFAULT);
71632 +
71633 + s_tmp->user_transitions = uidlist;
71634 + }
71635 +
71636 + if (s_tmp->group_trans_num) {
71637 + gid_t *gidlist;
71638 +
71639 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71640 + if (gidlist == NULL)
71641 + return ERR_PTR(-ENOMEM);
71642 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71643 + return ERR_PTR(-EFAULT);
71644 +
71645 + s_tmp->group_transitions = gidlist;
71646 + }
71647 +
71648 + /* set up object hash table */
71649 + num_objs = count_user_objs(ghash.first);
71650 +
71651 + s_tmp->obj_hash_size = num_objs;
71652 + s_tmp->obj_hash =
71653 + (struct acl_object_label **)
71654 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71655 +
71656 + if (!s_tmp->obj_hash)
71657 + return ERR_PTR(-ENOMEM);
71658 +
71659 + memset(s_tmp->obj_hash, 0,
71660 + s_tmp->obj_hash_size *
71661 + sizeof (struct acl_object_label *));
71662 +
71663 + /* add in objects */
71664 + err = copy_user_objs(ghash.first, s_tmp, role);
71665 +
71666 + if (err)
71667 + return ERR_PTR(err);
71668 +
71669 + /* set pointer for parent subject */
71670 + if (s_tmp->parent_subject) {
71671 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71672 +
71673 + if (IS_ERR(s_tmp2))
71674 + return s_tmp2;
71675 +
71676 + s_tmp->parent_subject = s_tmp2;
71677 + }
71678 +
71679 + /* add in ip acls */
71680 +
71681 + if (!s_tmp->ip_num) {
71682 + s_tmp->ips = NULL;
71683 + goto insert;
71684 + }
71685 +
71686 + i_tmp =
71687 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71688 + sizeof (struct acl_ip_label *));
71689 +
71690 + if (!i_tmp)
71691 + return ERR_PTR(-ENOMEM);
71692 +
71693 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71694 + *(i_tmp + i_num) =
71695 + (struct acl_ip_label *)
71696 + acl_alloc(sizeof (struct acl_ip_label));
71697 + if (!*(i_tmp + i_num))
71698 + return ERR_PTR(-ENOMEM);
71699 +
71700 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71701 + return ERR_PTR(-EFAULT);
71702 +
71703 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71704 + return ERR_PTR(-EFAULT);
71705 +
71706 + if ((*(i_tmp + i_num))->iface == NULL)
71707 + continue;
71708 +
71709 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71710 + if (err)
71711 + return ERR_PTR(err);
71712 + }
71713 +
71714 + s_tmp->ips = i_tmp;
71715 +
71716 +insert:
71717 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71718 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71719 + return ERR_PTR(-ENOMEM);
71720 +
71721 + return s_tmp;
71722 +}
71723 +
71724 +static int
71725 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71726 +{
71727 + struct acl_subject_label s_pre;
71728 + struct acl_subject_label * ret;
71729 + int err;
71730 +
71731 + while (userp) {
71732 + if (copy_acl_subject_label(&s_pre, userp))
71733 + return -EFAULT;
71734 +
71735 + ret = do_copy_user_subj(userp, role, NULL);
71736 +
71737 + err = PTR_ERR(ret);
71738 + if (IS_ERR(ret))
71739 + return err;
71740 +
71741 + insert_acl_subj_label(ret, role);
71742 +
71743 + userp = s_pre.prev;
71744 + }
71745 +
71746 + return 0;
71747 +}
71748 +
71749 +static int
71750 +copy_user_acl(struct gr_arg *arg)
71751 +{
71752 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71753 + struct acl_subject_label *subj_list;
71754 + struct sprole_pw *sptmp;
71755 + struct gr_hash_struct *ghash;
71756 + uid_t *domainlist;
71757 + unsigned int r_num;
71758 + int err = 0;
71759 + __u16 i;
71760 + __u32 num_subjs;
71761 +
71762 + /* we need a default and kernel role */
71763 + if (arg->role_db.num_roles < 2)
71764 + return -EINVAL;
71765 +
71766 + /* copy special role authentication info from userspace */
71767 +
71768 + polstate->num_sprole_pws = arg->num_sprole_pws;
71769 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71770 +
71771 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71772 + return -ENOMEM;
71773 +
71774 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71775 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71776 + if (!sptmp)
71777 + return -ENOMEM;
71778 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71779 + return -EFAULT;
71780 +
71781 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71782 + if (err)
71783 + return err;
71784 +
71785 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71786 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71787 +#endif
71788 +
71789 + polstate->acl_special_roles[i] = sptmp;
71790 + }
71791 +
71792 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71793 +
71794 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71795 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
71796 +
71797 + if (!r_tmp)
71798 + return -ENOMEM;
71799 +
71800 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71801 + return -EFAULT;
71802 +
71803 + if (copy_acl_role_label(r_tmp, r_utmp2))
71804 + return -EFAULT;
71805 +
71806 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71807 + if (err)
71808 + return err;
71809 +
71810 + if (!strcmp(r_tmp->rolename, "default")
71811 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71812 + polstate->default_role = r_tmp;
71813 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71814 + polstate->kernel_role = r_tmp;
71815 + }
71816 +
71817 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71818 + return -ENOMEM;
71819 +
71820 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
71821 + return -EFAULT;
71822 +
71823 + r_tmp->hash = ghash;
71824 +
71825 + num_subjs = count_user_subjs(r_tmp->hash->first);
71826 +
71827 + r_tmp->subj_hash_size = num_subjs;
71828 + r_tmp->subj_hash =
71829 + (struct acl_subject_label **)
71830 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71831 +
71832 + if (!r_tmp->subj_hash)
71833 + return -ENOMEM;
71834 +
71835 + err = copy_user_allowedips(r_tmp);
71836 + if (err)
71837 + return err;
71838 +
71839 + /* copy domain info */
71840 + if (r_tmp->domain_children != NULL) {
71841 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71842 + if (domainlist == NULL)
71843 + return -ENOMEM;
71844 +
71845 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71846 + return -EFAULT;
71847 +
71848 + r_tmp->domain_children = domainlist;
71849 + }
71850 +
71851 + err = copy_user_transitions(r_tmp);
71852 + if (err)
71853 + return err;
71854 +
71855 + memset(r_tmp->subj_hash, 0,
71856 + r_tmp->subj_hash_size *
71857 + sizeof (struct acl_subject_label *));
71858 +
71859 + /* acquire the list of subjects, then NULL out
71860 + the list prior to parsing the subjects for this role,
71861 + as during this parsing the list is replaced with a list
71862 + of *nested* subjects for the role
71863 + */
71864 + subj_list = r_tmp->hash->first;
71865 +
71866 + /* set nested subject list to null */
71867 + r_tmp->hash->first = NULL;
71868 +
71869 + err = copy_user_subjs(subj_list, r_tmp);
71870 +
71871 + if (err)
71872 + return err;
71873 +
71874 + insert_acl_role_label(r_tmp);
71875 + }
71876 +
71877 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71878 + return -EINVAL;
71879 +
71880 + return err;
71881 +}
71882 +
71883 +static int gracl_reload_apply_policies(void *reload)
71884 +{
71885 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71886 + struct task_struct *task, *task2;
71887 + struct acl_role_label *role, *rtmp;
71888 + struct acl_subject_label *subj;
71889 + const struct cred *cred;
71890 + int role_applied;
71891 + int ret = 0;
71892 +
71893 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71894 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71895 +
71896 + /* first make sure we'll be able to apply the new policy cleanly */
71897 + do_each_thread(task2, task) {
71898 + if (task->exec_file == NULL)
71899 + continue;
71900 + role_applied = 0;
71901 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71902 + /* preserve special roles */
71903 + FOR_EACH_ROLE_START(role)
71904 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71905 + rtmp = task->role;
71906 + task->role = role;
71907 + role_applied = 1;
71908 + break;
71909 + }
71910 + FOR_EACH_ROLE_END(role)
71911 + }
71912 + if (!role_applied) {
71913 + cred = __task_cred(task);
71914 + rtmp = task->role;
71915 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71916 + }
71917 + /* this handles non-nested inherited subjects, nested subjects will still
71918 + be dropped currently */
71919 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71920 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
71921 + /* change the role back so that we've made no modifications to the policy */
71922 + task->role = rtmp;
71923 +
71924 + if (subj == NULL || task->tmpacl == NULL) {
71925 + ret = -EINVAL;
71926 + goto out;
71927 + }
71928 + } while_each_thread(task2, task);
71929 +
71930 + /* now actually apply the policy */
71931 +
71932 + do_each_thread(task2, task) {
71933 + if (task->exec_file) {
71934 + role_applied = 0;
71935 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71936 + /* preserve special roles */
71937 + FOR_EACH_ROLE_START(role)
71938 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71939 + task->role = role;
71940 + role_applied = 1;
71941 + break;
71942 + }
71943 + FOR_EACH_ROLE_END(role)
71944 + }
71945 + if (!role_applied) {
71946 + cred = __task_cred(task);
71947 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71948 + }
71949 + /* this handles non-nested inherited subjects, nested subjects will still
71950 + be dropped currently */
71951 + if (!reload_state->oldmode && task->inherited)
71952 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71953 + else {
71954 + /* looked up and tagged to the task previously */
71955 + subj = task->tmpacl;
71956 + }
71957 + /* subj will be non-null */
71958 + __gr_apply_subject_to_task(polstate, task, subj);
71959 + if (reload_state->oldmode) {
71960 + task->acl_role_id = 0;
71961 + task->acl_sp_role = 0;
71962 + task->inherited = 0;
71963 + }
71964 + } else {
71965 + // it's a kernel process
71966 + task->role = polstate->kernel_role;
71967 + task->acl = polstate->kernel_role->root_label;
71968 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71969 + task->acl->mode &= ~GR_PROCFIND;
71970 +#endif
71971 + }
71972 + } while_each_thread(task2, task);
71973 +
71974 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
71975 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
71976 +
71977 +out:
71978 +
71979 + return ret;
71980 +}
71981 +
71982 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
71983 +{
71984 + struct gr_reload_state new_reload_state = { };
71985 + int err;
71986 +
71987 + new_reload_state.oldpolicy_ptr = polstate;
71988 + new_reload_state.oldalloc_ptr = current_alloc_state;
71989 + new_reload_state.oldmode = oldmode;
71990 +
71991 + current_alloc_state = &new_reload_state.newalloc;
71992 + polstate = &new_reload_state.newpolicy;
71993 +
71994 + /* everything relevant is now saved off, copy in the new policy */
71995 + if (init_variables(args, true)) {
71996 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71997 + err = -ENOMEM;
71998 + goto error;
71999 + }
72000 +
72001 + err = copy_user_acl(args);
72002 + free_init_variables();
72003 + if (err)
72004 + goto error;
72005 + /* the new policy is copied in, with the old policy available via saved_state
72006 + first go through applying roles, making sure to preserve special roles
72007 + then apply new subjects, making sure to preserve inherited and nested subjects,
72008 + though currently only inherited subjects will be preserved
72009 + */
72010 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72011 + if (err)
72012 + goto error;
72013 +
72014 + /* we've now applied the new policy, so restore the old policy state to free it */
72015 + polstate = &new_reload_state.oldpolicy;
72016 + current_alloc_state = &new_reload_state.oldalloc;
72017 + free_variables(true);
72018 +
72019 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72020 + to running_polstate/current_alloc_state inside stop_machine
72021 + */
72022 + err = 0;
72023 + goto out;
72024 +error:
72025 + /* on error of loading the new policy, we'll just keep the previous
72026 + policy set around
72027 + */
72028 + free_variables(true);
72029 +
72030 + /* doesn't affect runtime, but maintains consistent state */
72031 +out:
72032 + polstate = new_reload_state.oldpolicy_ptr;
72033 + current_alloc_state = new_reload_state.oldalloc_ptr;
72034 +
72035 + return err;
72036 +}
72037 +
72038 +static int
72039 +gracl_init(struct gr_arg *args)
72040 +{
72041 + int error = 0;
72042 +
72043 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72044 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72045 +
72046 + if (init_variables(args, false)) {
72047 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72048 + error = -ENOMEM;
72049 + goto out;
72050 + }
72051 +
72052 + error = copy_user_acl(args);
72053 + free_init_variables();
72054 + if (error)
72055 + goto out;
72056 +
72057 + error = gr_set_acls(0);
72058 + if (error)
72059 + goto out;
72060 +
72061 + gr_enable_rbac_system();
72062 +
72063 + return 0;
72064 +
72065 +out:
72066 + free_variables(false);
72067 + return error;
72068 +}
72069 +
72070 +static int
72071 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72072 + unsigned char **sum)
72073 +{
72074 + struct acl_role_label *r;
72075 + struct role_allowed_ip *ipp;
72076 + struct role_transition *trans;
72077 + unsigned int i;
72078 + int found = 0;
72079 + u32 curr_ip = current->signal->curr_ip;
72080 +
72081 + current->signal->saved_ip = curr_ip;
72082 +
72083 + /* check transition table */
72084 +
72085 + for (trans = current->role->transitions; trans; trans = trans->next) {
72086 + if (!strcmp(rolename, trans->rolename)) {
72087 + found = 1;
72088 + break;
72089 + }
72090 + }
72091 +
72092 + if (!found)
72093 + return 0;
72094 +
72095 + /* handle special roles that do not require authentication
72096 + and check ip */
72097 +
72098 + FOR_EACH_ROLE_START(r)
72099 + if (!strcmp(rolename, r->rolename) &&
72100 + (r->roletype & GR_ROLE_SPECIAL)) {
72101 + found = 0;
72102 + if (r->allowed_ips != NULL) {
72103 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72104 + if ((ntohl(curr_ip) & ipp->netmask) ==
72105 + (ntohl(ipp->addr) & ipp->netmask))
72106 + found = 1;
72107 + }
72108 + } else
72109 + found = 2;
72110 + if (!found)
72111 + return 0;
72112 +
72113 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72114 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72115 + *salt = NULL;
72116 + *sum = NULL;
72117 + return 1;
72118 + }
72119 + }
72120 + FOR_EACH_ROLE_END(r)
72121 +
72122 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72123 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72124 + *salt = polstate->acl_special_roles[i]->salt;
72125 + *sum = polstate->acl_special_roles[i]->sum;
72126 + return 1;
72127 + }
72128 + }
72129 +
72130 + return 0;
72131 +}
72132 +
72133 +int gr_check_secure_terminal(struct task_struct *task)
72134 +{
72135 + struct task_struct *p, *p2, *p3;
72136 + struct files_struct *files;
72137 + struct fdtable *fdt;
72138 + struct file *our_file = NULL, *file;
72139 + int i;
72140 +
72141 + if (task->signal->tty == NULL)
72142 + return 1;
72143 +
72144 + files = get_files_struct(task);
72145 + if (files != NULL) {
72146 + rcu_read_lock();
72147 + fdt = files_fdtable(files);
72148 + for (i=0; i < fdt->max_fds; i++) {
72149 + file = fcheck_files(files, i);
72150 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72151 + get_file(file);
72152 + our_file = file;
72153 + }
72154 + }
72155 + rcu_read_unlock();
72156 + put_files_struct(files);
72157 + }
72158 +
72159 + if (our_file == NULL)
72160 + return 1;
72161 +
72162 + read_lock(&tasklist_lock);
72163 + do_each_thread(p2, p) {
72164 + files = get_files_struct(p);
72165 + if (files == NULL ||
72166 + (p->signal && p->signal->tty == task->signal->tty)) {
72167 + if (files != NULL)
72168 + put_files_struct(files);
72169 + continue;
72170 + }
72171 + rcu_read_lock();
72172 + fdt = files_fdtable(files);
72173 + for (i=0; i < fdt->max_fds; i++) {
72174 + file = fcheck_files(files, i);
72175 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72176 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72177 + p3 = task;
72178 + while (task_pid_nr(p3) > 0) {
72179 + if (p3 == p)
72180 + break;
72181 + p3 = p3->real_parent;
72182 + }
72183 + if (p3 == p)
72184 + break;
72185 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72186 + gr_handle_alertkill(p);
72187 + rcu_read_unlock();
72188 + put_files_struct(files);
72189 + read_unlock(&tasklist_lock);
72190 + fput(our_file);
72191 + return 0;
72192 + }
72193 + }
72194 + rcu_read_unlock();
72195 + put_files_struct(files);
72196 + } while_each_thread(p2, p);
72197 + read_unlock(&tasklist_lock);
72198 +
72199 + fput(our_file);
72200 + return 1;
72201 +}
72202 +
72203 +ssize_t
72204 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72205 +{
72206 + struct gr_arg_wrapper uwrap;
72207 + unsigned char *sprole_salt = NULL;
72208 + unsigned char *sprole_sum = NULL;
72209 + int error = 0;
72210 + int error2 = 0;
72211 + size_t req_count = 0;
72212 + unsigned char oldmode = 0;
72213 +
72214 + mutex_lock(&gr_dev_mutex);
72215 +
72216 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72217 + error = -EPERM;
72218 + goto out;
72219 + }
72220 +
72221 +#ifdef CONFIG_COMPAT
72222 + pax_open_kernel();
72223 + if (is_compat_task()) {
72224 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72225 + copy_gr_arg = &copy_gr_arg_compat;
72226 + copy_acl_object_label = &copy_acl_object_label_compat;
72227 + copy_acl_subject_label = &copy_acl_subject_label_compat;
72228 + copy_acl_role_label = &copy_acl_role_label_compat;
72229 + copy_acl_ip_label = &copy_acl_ip_label_compat;
72230 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72231 + copy_role_transition = &copy_role_transition_compat;
72232 + copy_sprole_pw = &copy_sprole_pw_compat;
72233 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72234 + copy_pointer_from_array = &copy_pointer_from_array_compat;
72235 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72236 + } else {
72237 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72238 + copy_gr_arg = &copy_gr_arg_normal;
72239 + copy_acl_object_label = &copy_acl_object_label_normal;
72240 + copy_acl_subject_label = &copy_acl_subject_label_normal;
72241 + copy_acl_role_label = &copy_acl_role_label_normal;
72242 + copy_acl_ip_label = &copy_acl_ip_label_normal;
72243 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72244 + copy_role_transition = &copy_role_transition_normal;
72245 + copy_sprole_pw = &copy_sprole_pw_normal;
72246 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72247 + copy_pointer_from_array = &copy_pointer_from_array_normal;
72248 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72249 + }
72250 + pax_close_kernel();
72251 +#endif
72252 +
72253 + req_count = get_gr_arg_wrapper_size();
72254 +
72255 + if (count != req_count) {
72256 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72257 + error = -EINVAL;
72258 + goto out;
72259 + }
72260 +
72261 +
72262 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72263 + gr_auth_expires = 0;
72264 + gr_auth_attempts = 0;
72265 + }
72266 +
72267 + error = copy_gr_arg_wrapper(buf, &uwrap);
72268 + if (error)
72269 + goto out;
72270 +
72271 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
72272 + if (error)
72273 + goto out;
72274 +
72275 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72276 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72277 + time_after(gr_auth_expires, get_seconds())) {
72278 + error = -EBUSY;
72279 + goto out;
72280 + }
72281 +
72282 + /* if non-root trying to do anything other than use a special role,
72283 + do not attempt authentication, do not count towards authentication
72284 + locking
72285 + */
72286 +
72287 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72288 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72289 + gr_is_global_nonroot(current_uid())) {
72290 + error = -EPERM;
72291 + goto out;
72292 + }
72293 +
72294 + /* ensure pw and special role name are null terminated */
72295 +
72296 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72297 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72298 +
72299 + /* Okay.
72300 + * We have our enough of the argument structure..(we have yet
72301 + * to copy_from_user the tables themselves) . Copy the tables
72302 + * only if we need them, i.e. for loading operations. */
72303 +
72304 + switch (gr_usermode.mode) {
72305 + case GR_STATUS:
72306 + if (gr_acl_is_enabled()) {
72307 + error = 1;
72308 + if (!gr_check_secure_terminal(current))
72309 + error = 3;
72310 + } else
72311 + error = 2;
72312 + goto out;
72313 + case GR_SHUTDOWN:
72314 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72315 + stop_machine(gr_rbac_disable, NULL, NULL);
72316 + free_variables(false);
72317 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72318 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72319 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72320 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72321 + } else if (gr_acl_is_enabled()) {
72322 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72323 + error = -EPERM;
72324 + } else {
72325 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72326 + error = -EAGAIN;
72327 + }
72328 + break;
72329 + case GR_ENABLE:
72330 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72331 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72332 + else {
72333 + if (gr_acl_is_enabled())
72334 + error = -EAGAIN;
72335 + else
72336 + error = error2;
72337 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72338 + }
72339 + break;
72340 + case GR_OLDRELOAD:
72341 + oldmode = 1;
72342 + case GR_RELOAD:
72343 + if (!gr_acl_is_enabled()) {
72344 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72345 + error = -EAGAIN;
72346 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72347 + error2 = gracl_reload(&gr_usermode, oldmode);
72348 + if (!error2)
72349 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72350 + else {
72351 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72352 + error = error2;
72353 + }
72354 + } else {
72355 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72356 + error = -EPERM;
72357 + }
72358 + break;
72359 + case GR_SEGVMOD:
72360 + if (unlikely(!gr_acl_is_enabled())) {
72361 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72362 + error = -EAGAIN;
72363 + break;
72364 + }
72365 +
72366 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72367 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72368 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72369 + struct acl_subject_label *segvacl;
72370 + segvacl =
72371 + lookup_acl_subj_label(gr_usermode.segv_inode,
72372 + gr_usermode.segv_device,
72373 + current->role);
72374 + if (segvacl) {
72375 + segvacl->crashes = 0;
72376 + segvacl->expires = 0;
72377 + }
72378 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72379 + gr_remove_uid(gr_usermode.segv_uid);
72380 + }
72381 + } else {
72382 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72383 + error = -EPERM;
72384 + }
72385 + break;
72386 + case GR_SPROLE:
72387 + case GR_SPROLEPAM:
72388 + if (unlikely(!gr_acl_is_enabled())) {
72389 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72390 + error = -EAGAIN;
72391 + break;
72392 + }
72393 +
72394 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72395 + current->role->expires = 0;
72396 + current->role->auth_attempts = 0;
72397 + }
72398 +
72399 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72400 + time_after(current->role->expires, get_seconds())) {
72401 + error = -EBUSY;
72402 + goto out;
72403 + }
72404 +
72405 + if (lookup_special_role_auth
72406 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72407 + && ((!sprole_salt && !sprole_sum)
72408 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72409 + char *p = "";
72410 + assign_special_role(gr_usermode.sp_role);
72411 + read_lock(&tasklist_lock);
72412 + if (current->real_parent)
72413 + p = current->real_parent->role->rolename;
72414 + read_unlock(&tasklist_lock);
72415 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72416 + p, acl_sp_role_value);
72417 + } else {
72418 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72419 + error = -EPERM;
72420 + if(!(current->role->auth_attempts++))
72421 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72422 +
72423 + goto out;
72424 + }
72425 + break;
72426 + case GR_UNSPROLE:
72427 + if (unlikely(!gr_acl_is_enabled())) {
72428 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72429 + error = -EAGAIN;
72430 + break;
72431 + }
72432 +
72433 + if (current->role->roletype & GR_ROLE_SPECIAL) {
72434 + char *p = "";
72435 + int i = 0;
72436 +
72437 + read_lock(&tasklist_lock);
72438 + if (current->real_parent) {
72439 + p = current->real_parent->role->rolename;
72440 + i = current->real_parent->acl_role_id;
72441 + }
72442 + read_unlock(&tasklist_lock);
72443 +
72444 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72445 + gr_set_acls(1);
72446 + } else {
72447 + error = -EPERM;
72448 + goto out;
72449 + }
72450 + break;
72451 + default:
72452 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72453 + error = -EINVAL;
72454 + break;
72455 + }
72456 +
72457 + if (error != -EPERM)
72458 + goto out;
72459 +
72460 + if(!(gr_auth_attempts++))
72461 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72462 +
72463 + out:
72464 + mutex_unlock(&gr_dev_mutex);
72465 +
72466 + if (!error)
72467 + error = req_count;
72468 +
72469 + return error;
72470 +}
72471 +
72472 +int
72473 +gr_set_acls(const int type)
72474 +{
72475 + struct task_struct *task, *task2;
72476 + struct acl_role_label *role = current->role;
72477 + struct acl_subject_label *subj;
72478 + __u16 acl_role_id = current->acl_role_id;
72479 + const struct cred *cred;
72480 + int ret;
72481 +
72482 + rcu_read_lock();
72483 + read_lock(&tasklist_lock);
72484 + read_lock(&grsec_exec_file_lock);
72485 + do_each_thread(task2, task) {
72486 + /* check to see if we're called from the exit handler,
72487 + if so, only replace ACLs that have inherited the admin
72488 + ACL */
72489 +
72490 + if (type && (task->role != role ||
72491 + task->acl_role_id != acl_role_id))
72492 + continue;
72493 +
72494 + task->acl_role_id = 0;
72495 + task->acl_sp_role = 0;
72496 + task->inherited = 0;
72497 +
72498 + if (task->exec_file) {
72499 + cred = __task_cred(task);
72500 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72501 + subj = __gr_get_subject_for_task(polstate, task, NULL);
72502 + if (subj == NULL) {
72503 + ret = -EINVAL;
72504 + read_unlock(&grsec_exec_file_lock);
72505 + read_unlock(&tasklist_lock);
72506 + rcu_read_unlock();
72507 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72508 + return ret;
72509 + }
72510 + __gr_apply_subject_to_task(polstate, task, subj);
72511 + } else {
72512 + // it's a kernel process
72513 + task->role = polstate->kernel_role;
72514 + task->acl = polstate->kernel_role->root_label;
72515 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72516 + task->acl->mode &= ~GR_PROCFIND;
72517 +#endif
72518 + }
72519 + } while_each_thread(task2, task);
72520 + read_unlock(&grsec_exec_file_lock);
72521 + read_unlock(&tasklist_lock);
72522 + rcu_read_unlock();
72523 +
72524 + return 0;
72525 +}
72526 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72527 new file mode 100644
72528 index 0000000..39645c9
72529 --- /dev/null
72530 +++ b/grsecurity/gracl_res.c
72531 @@ -0,0 +1,68 @@
72532 +#include <linux/kernel.h>
72533 +#include <linux/sched.h>
72534 +#include <linux/gracl.h>
72535 +#include <linux/grinternal.h>
72536 +
72537 +static const char *restab_log[] = {
72538 + [RLIMIT_CPU] = "RLIMIT_CPU",
72539 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72540 + [RLIMIT_DATA] = "RLIMIT_DATA",
72541 + [RLIMIT_STACK] = "RLIMIT_STACK",
72542 + [RLIMIT_CORE] = "RLIMIT_CORE",
72543 + [RLIMIT_RSS] = "RLIMIT_RSS",
72544 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
72545 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72546 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72547 + [RLIMIT_AS] = "RLIMIT_AS",
72548 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72549 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72550 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72551 + [RLIMIT_NICE] = "RLIMIT_NICE",
72552 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72553 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72554 + [GR_CRASH_RES] = "RLIMIT_CRASH"
72555 +};
72556 +
72557 +void
72558 +gr_log_resource(const struct task_struct *task,
72559 + const int res, const unsigned long wanted, const int gt)
72560 +{
72561 + const struct cred *cred;
72562 + unsigned long rlim;
72563 +
72564 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
72565 + return;
72566 +
72567 + // not yet supported resource
72568 + if (unlikely(!restab_log[res]))
72569 + return;
72570 +
72571 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72572 + rlim = task_rlimit_max(task, res);
72573 + else
72574 + rlim = task_rlimit(task, res);
72575 +
72576 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72577 + return;
72578 +
72579 + rcu_read_lock();
72580 + cred = __task_cred(task);
72581 +
72582 + if (res == RLIMIT_NPROC &&
72583 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72584 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72585 + goto out_rcu_unlock;
72586 + else if (res == RLIMIT_MEMLOCK &&
72587 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72588 + goto out_rcu_unlock;
72589 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72590 + goto out_rcu_unlock;
72591 + rcu_read_unlock();
72592 +
72593 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72594 +
72595 + return;
72596 +out_rcu_unlock:
72597 + rcu_read_unlock();
72598 + return;
72599 +}
72600 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72601 new file mode 100644
72602 index 0000000..2040e61
72603 --- /dev/null
72604 +++ b/grsecurity/gracl_segv.c
72605 @@ -0,0 +1,313 @@
72606 +#include <linux/kernel.h>
72607 +#include <linux/mm.h>
72608 +#include <asm/uaccess.h>
72609 +#include <asm/errno.h>
72610 +#include <asm/mman.h>
72611 +#include <net/sock.h>
72612 +#include <linux/file.h>
72613 +#include <linux/fs.h>
72614 +#include <linux/net.h>
72615 +#include <linux/in.h>
72616 +#include <linux/slab.h>
72617 +#include <linux/types.h>
72618 +#include <linux/sched.h>
72619 +#include <linux/timer.h>
72620 +#include <linux/gracl.h>
72621 +#include <linux/grsecurity.h>
72622 +#include <linux/grinternal.h>
72623 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72624 +#include <linux/magic.h>
72625 +#include <linux/pagemap.h>
72626 +#include "../fs/btrfs/async-thread.h"
72627 +#include "../fs/btrfs/ctree.h"
72628 +#include "../fs/btrfs/btrfs_inode.h"
72629 +#endif
72630 +
72631 +static struct crash_uid *uid_set;
72632 +static unsigned short uid_used;
72633 +static DEFINE_SPINLOCK(gr_uid_lock);
72634 +extern rwlock_t gr_inode_lock;
72635 +extern struct acl_subject_label *
72636 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72637 + struct acl_role_label *role);
72638 +
72639 +static inline dev_t __get_dev(const struct dentry *dentry)
72640 +{
72641 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72642 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72643 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
72644 + else
72645 +#endif
72646 + return dentry->d_sb->s_dev;
72647 +}
72648 +
72649 +int
72650 +gr_init_uidset(void)
72651 +{
72652 + uid_set =
72653 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72654 + uid_used = 0;
72655 +
72656 + return uid_set ? 1 : 0;
72657 +}
72658 +
72659 +void
72660 +gr_free_uidset(void)
72661 +{
72662 + if (uid_set) {
72663 + struct crash_uid *tmpset;
72664 + spin_lock(&gr_uid_lock);
72665 + tmpset = uid_set;
72666 + uid_set = NULL;
72667 + uid_used = 0;
72668 + spin_unlock(&gr_uid_lock);
72669 + if (tmpset)
72670 + kfree(tmpset);
72671 + }
72672 +
72673 + return;
72674 +}
72675 +
72676 +int
72677 +gr_find_uid(const uid_t uid)
72678 +{
72679 + struct crash_uid *tmp = uid_set;
72680 + uid_t buid;
72681 + int low = 0, high = uid_used - 1, mid;
72682 +
72683 + while (high >= low) {
72684 + mid = (low + high) >> 1;
72685 + buid = tmp[mid].uid;
72686 + if (buid == uid)
72687 + return mid;
72688 + if (buid > uid)
72689 + high = mid - 1;
72690 + if (buid < uid)
72691 + low = mid + 1;
72692 + }
72693 +
72694 + return -1;
72695 +}
72696 +
72697 +static __inline__ void
72698 +gr_insertsort(void)
72699 +{
72700 + unsigned short i, j;
72701 + struct crash_uid index;
72702 +
72703 + for (i = 1; i < uid_used; i++) {
72704 + index = uid_set[i];
72705 + j = i;
72706 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72707 + uid_set[j] = uid_set[j - 1];
72708 + j--;
72709 + }
72710 + uid_set[j] = index;
72711 + }
72712 +
72713 + return;
72714 +}
72715 +
72716 +static __inline__ void
72717 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72718 +{
72719 + int loc;
72720 + uid_t uid = GR_GLOBAL_UID(kuid);
72721 +
72722 + if (uid_used == GR_UIDTABLE_MAX)
72723 + return;
72724 +
72725 + loc = gr_find_uid(uid);
72726 +
72727 + if (loc >= 0) {
72728 + uid_set[loc].expires = expires;
72729 + return;
72730 + }
72731 +
72732 + uid_set[uid_used].uid = uid;
72733 + uid_set[uid_used].expires = expires;
72734 + uid_used++;
72735 +
72736 + gr_insertsort();
72737 +
72738 + return;
72739 +}
72740 +
72741 +void
72742 +gr_remove_uid(const unsigned short loc)
72743 +{
72744 + unsigned short i;
72745 +
72746 + for (i = loc + 1; i < uid_used; i++)
72747 + uid_set[i - 1] = uid_set[i];
72748 +
72749 + uid_used--;
72750 +
72751 + return;
72752 +}
72753 +
72754 +int
72755 +gr_check_crash_uid(const kuid_t kuid)
72756 +{
72757 + int loc;
72758 + int ret = 0;
72759 + uid_t uid;
72760 +
72761 + if (unlikely(!gr_acl_is_enabled()))
72762 + return 0;
72763 +
72764 + uid = GR_GLOBAL_UID(kuid);
72765 +
72766 + spin_lock(&gr_uid_lock);
72767 + loc = gr_find_uid(uid);
72768 +
72769 + if (loc < 0)
72770 + goto out_unlock;
72771 +
72772 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
72773 + gr_remove_uid(loc);
72774 + else
72775 + ret = 1;
72776 +
72777 +out_unlock:
72778 + spin_unlock(&gr_uid_lock);
72779 + return ret;
72780 +}
72781 +
72782 +static __inline__ int
72783 +proc_is_setxid(const struct cred *cred)
72784 +{
72785 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72786 + !uid_eq(cred->uid, cred->fsuid))
72787 + return 1;
72788 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72789 + !gid_eq(cred->gid, cred->fsgid))
72790 + return 1;
72791 +
72792 + return 0;
72793 +}
72794 +
72795 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
72796 +
72797 +void
72798 +gr_handle_crash(struct task_struct *task, const int sig)
72799 +{
72800 + struct acl_subject_label *curr;
72801 + struct task_struct *tsk, *tsk2;
72802 + const struct cred *cred;
72803 + const struct cred *cred2;
72804 +
72805 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72806 + return;
72807 +
72808 + if (unlikely(!gr_acl_is_enabled()))
72809 + return;
72810 +
72811 + curr = task->acl;
72812 +
72813 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
72814 + return;
72815 +
72816 + if (time_before_eq(curr->expires, get_seconds())) {
72817 + curr->expires = 0;
72818 + curr->crashes = 0;
72819 + }
72820 +
72821 + curr->crashes++;
72822 +
72823 + if (!curr->expires)
72824 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72825 +
72826 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72827 + time_after(curr->expires, get_seconds())) {
72828 + rcu_read_lock();
72829 + cred = __task_cred(task);
72830 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72831 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72832 + spin_lock(&gr_uid_lock);
72833 + gr_insert_uid(cred->uid, curr->expires);
72834 + spin_unlock(&gr_uid_lock);
72835 + curr->expires = 0;
72836 + curr->crashes = 0;
72837 + read_lock(&tasklist_lock);
72838 + do_each_thread(tsk2, tsk) {
72839 + cred2 = __task_cred(tsk);
72840 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
72841 + gr_fake_force_sig(SIGKILL, tsk);
72842 + } while_each_thread(tsk2, tsk);
72843 + read_unlock(&tasklist_lock);
72844 + } else {
72845 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72846 + read_lock(&tasklist_lock);
72847 + read_lock(&grsec_exec_file_lock);
72848 + do_each_thread(tsk2, tsk) {
72849 + if (likely(tsk != task)) {
72850 + // if this thread has the same subject as the one that triggered
72851 + // RES_CRASH and it's the same binary, kill it
72852 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72853 + gr_fake_force_sig(SIGKILL, tsk);
72854 + }
72855 + } while_each_thread(tsk2, tsk);
72856 + read_unlock(&grsec_exec_file_lock);
72857 + read_unlock(&tasklist_lock);
72858 + }
72859 + rcu_read_unlock();
72860 + }
72861 +
72862 + return;
72863 +}
72864 +
72865 +int
72866 +gr_check_crash_exec(const struct file *filp)
72867 +{
72868 + struct acl_subject_label *curr;
72869 +
72870 + if (unlikely(!gr_acl_is_enabled()))
72871 + return 0;
72872 +
72873 + read_lock(&gr_inode_lock);
72874 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72875 + __get_dev(filp->f_path.dentry),
72876 + current->role);
72877 + read_unlock(&gr_inode_lock);
72878 +
72879 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72880 + (!curr->crashes && !curr->expires))
72881 + return 0;
72882 +
72883 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72884 + time_after(curr->expires, get_seconds()))
72885 + return 1;
72886 + else if (time_before_eq(curr->expires, get_seconds())) {
72887 + curr->crashes = 0;
72888 + curr->expires = 0;
72889 + }
72890 +
72891 + return 0;
72892 +}
72893 +
72894 +void
72895 +gr_handle_alertkill(struct task_struct *task)
72896 +{
72897 + struct acl_subject_label *curracl;
72898 + __u32 curr_ip;
72899 + struct task_struct *p, *p2;
72900 +
72901 + if (unlikely(!gr_acl_is_enabled()))
72902 + return;
72903 +
72904 + curracl = task->acl;
72905 + curr_ip = task->signal->curr_ip;
72906 +
72907 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
72908 + read_lock(&tasklist_lock);
72909 + do_each_thread(p2, p) {
72910 + if (p->signal->curr_ip == curr_ip)
72911 + gr_fake_force_sig(SIGKILL, p);
72912 + } while_each_thread(p2, p);
72913 + read_unlock(&tasklist_lock);
72914 + } else if (curracl->mode & GR_KILLPROC)
72915 + gr_fake_force_sig(SIGKILL, task);
72916 +
72917 + return;
72918 +}
72919 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
72920 new file mode 100644
72921 index 0000000..98011b0
72922 --- /dev/null
72923 +++ b/grsecurity/gracl_shm.c
72924 @@ -0,0 +1,40 @@
72925 +#include <linux/kernel.h>
72926 +#include <linux/mm.h>
72927 +#include <linux/sched.h>
72928 +#include <linux/file.h>
72929 +#include <linux/ipc.h>
72930 +#include <linux/gracl.h>
72931 +#include <linux/grsecurity.h>
72932 +#include <linux/grinternal.h>
72933 +
72934 +int
72935 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72936 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72937 +{
72938 + struct task_struct *task;
72939 +
72940 + if (!gr_acl_is_enabled())
72941 + return 1;
72942 +
72943 + rcu_read_lock();
72944 + read_lock(&tasklist_lock);
72945 +
72946 + task = find_task_by_vpid(shm_cprid);
72947 +
72948 + if (unlikely(!task))
72949 + task = find_task_by_vpid(shm_lapid);
72950 +
72951 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
72952 + (task_pid_nr(task) == shm_lapid)) &&
72953 + (task->acl->mode & GR_PROTSHM) &&
72954 + (task->acl != current->acl))) {
72955 + read_unlock(&tasklist_lock);
72956 + rcu_read_unlock();
72957 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
72958 + return 0;
72959 + }
72960 + read_unlock(&tasklist_lock);
72961 + rcu_read_unlock();
72962 +
72963 + return 1;
72964 +}
72965 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
72966 new file mode 100644
72967 index 0000000..bc0be01
72968 --- /dev/null
72969 +++ b/grsecurity/grsec_chdir.c
72970 @@ -0,0 +1,19 @@
72971 +#include <linux/kernel.h>
72972 +#include <linux/sched.h>
72973 +#include <linux/fs.h>
72974 +#include <linux/file.h>
72975 +#include <linux/grsecurity.h>
72976 +#include <linux/grinternal.h>
72977 +
72978 +void
72979 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
72980 +{
72981 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72982 + if ((grsec_enable_chdir && grsec_enable_group &&
72983 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
72984 + !grsec_enable_group)) {
72985 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
72986 + }
72987 +#endif
72988 + return;
72989 +}
72990 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
72991 new file mode 100644
72992 index 0000000..651d6c2
72993 --- /dev/null
72994 +++ b/grsecurity/grsec_chroot.c
72995 @@ -0,0 +1,370 @@
72996 +#include <linux/kernel.h>
72997 +#include <linux/module.h>
72998 +#include <linux/sched.h>
72999 +#include <linux/file.h>
73000 +#include <linux/fs.h>
73001 +#include <linux/mount.h>
73002 +#include <linux/types.h>
73003 +#include "../fs/mount.h"
73004 +#include <linux/grsecurity.h>
73005 +#include <linux/grinternal.h>
73006 +
73007 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73008 +int gr_init_ran;
73009 +#endif
73010 +
73011 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73012 +{
73013 +#ifdef CONFIG_GRKERNSEC
73014 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73015 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73016 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73017 + && gr_init_ran
73018 +#endif
73019 + )
73020 + task->gr_is_chrooted = 1;
73021 + else {
73022 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73023 + if (task_pid_nr(task) == 1 && !gr_init_ran)
73024 + gr_init_ran = 1;
73025 +#endif
73026 + task->gr_is_chrooted = 0;
73027 + }
73028 +
73029 + task->gr_chroot_dentry = path->dentry;
73030 +#endif
73031 + return;
73032 +}
73033 +
73034 +void gr_clear_chroot_entries(struct task_struct *task)
73035 +{
73036 +#ifdef CONFIG_GRKERNSEC
73037 + task->gr_is_chrooted = 0;
73038 + task->gr_chroot_dentry = NULL;
73039 +#endif
73040 + return;
73041 +}
73042 +
73043 +int
73044 +gr_handle_chroot_unix(const pid_t pid)
73045 +{
73046 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73047 + struct task_struct *p;
73048 +
73049 + if (unlikely(!grsec_enable_chroot_unix))
73050 + return 1;
73051 +
73052 + if (likely(!proc_is_chrooted(current)))
73053 + return 1;
73054 +
73055 + rcu_read_lock();
73056 + read_lock(&tasklist_lock);
73057 + p = find_task_by_vpid_unrestricted(pid);
73058 + if (unlikely(p && !have_same_root(current, p))) {
73059 + read_unlock(&tasklist_lock);
73060 + rcu_read_unlock();
73061 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73062 + return 0;
73063 + }
73064 + read_unlock(&tasklist_lock);
73065 + rcu_read_unlock();
73066 +#endif
73067 + return 1;
73068 +}
73069 +
73070 +int
73071 +gr_handle_chroot_nice(void)
73072 +{
73073 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73074 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73075 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73076 + return -EPERM;
73077 + }
73078 +#endif
73079 + return 0;
73080 +}
73081 +
73082 +int
73083 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73084 +{
73085 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73086 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73087 + && proc_is_chrooted(current)) {
73088 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73089 + return -EACCES;
73090 + }
73091 +#endif
73092 + return 0;
73093 +}
73094 +
73095 +int
73096 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73097 +{
73098 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73099 + struct task_struct *p;
73100 + int ret = 0;
73101 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73102 + return ret;
73103 +
73104 + read_lock(&tasklist_lock);
73105 + do_each_pid_task(pid, type, p) {
73106 + if (!have_same_root(current, p)) {
73107 + ret = 1;
73108 + goto out;
73109 + }
73110 + } while_each_pid_task(pid, type, p);
73111 +out:
73112 + read_unlock(&tasklist_lock);
73113 + return ret;
73114 +#endif
73115 + return 0;
73116 +}
73117 +
73118 +int
73119 +gr_pid_is_chrooted(struct task_struct *p)
73120 +{
73121 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73122 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73123 + return 0;
73124 +
73125 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73126 + !have_same_root(current, p)) {
73127 + return 1;
73128 + }
73129 +#endif
73130 + return 0;
73131 +}
73132 +
73133 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73134 +
73135 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73136 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73137 +{
73138 + struct path path, currentroot;
73139 + int ret = 0;
73140 +
73141 + path.dentry = (struct dentry *)u_dentry;
73142 + path.mnt = (struct vfsmount *)u_mnt;
73143 + get_fs_root(current->fs, &currentroot);
73144 + if (path_is_under(&path, &currentroot))
73145 + ret = 1;
73146 + path_put(&currentroot);
73147 +
73148 + return ret;
73149 +}
73150 +#endif
73151 +
73152 +int
73153 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73154 +{
73155 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73156 + if (!grsec_enable_chroot_fchdir)
73157 + return 1;
73158 +
73159 + if (!proc_is_chrooted(current))
73160 + return 1;
73161 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73162 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73163 + return 0;
73164 + }
73165 +#endif
73166 + return 1;
73167 +}
73168 +
73169 +int
73170 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73171 + const time_t shm_createtime)
73172 +{
73173 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73174 + struct task_struct *p;
73175 + time_t starttime;
73176 +
73177 + if (unlikely(!grsec_enable_chroot_shmat))
73178 + return 1;
73179 +
73180 + if (likely(!proc_is_chrooted(current)))
73181 + return 1;
73182 +
73183 + rcu_read_lock();
73184 + read_lock(&tasklist_lock);
73185 +
73186 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73187 + starttime = p->start_time.tv_sec;
73188 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73189 + if (have_same_root(current, p)) {
73190 + goto allow;
73191 + } else {
73192 + read_unlock(&tasklist_lock);
73193 + rcu_read_unlock();
73194 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73195 + return 0;
73196 + }
73197 + }
73198 + /* creator exited, pid reuse, fall through to next check */
73199 + }
73200 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73201 + if (unlikely(!have_same_root(current, p))) {
73202 + read_unlock(&tasklist_lock);
73203 + rcu_read_unlock();
73204 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73205 + return 0;
73206 + }
73207 + }
73208 +
73209 +allow:
73210 + read_unlock(&tasklist_lock);
73211 + rcu_read_unlock();
73212 +#endif
73213 + return 1;
73214 +}
73215 +
73216 +void
73217 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73218 +{
73219 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73220 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73221 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73222 +#endif
73223 + return;
73224 +}
73225 +
73226 +int
73227 +gr_handle_chroot_mknod(const struct dentry *dentry,
73228 + const struct vfsmount *mnt, const int mode)
73229 +{
73230 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73231 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73232 + proc_is_chrooted(current)) {
73233 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73234 + return -EPERM;
73235 + }
73236 +#endif
73237 + return 0;
73238 +}
73239 +
73240 +int
73241 +gr_handle_chroot_mount(const struct dentry *dentry,
73242 + const struct vfsmount *mnt, const char *dev_name)
73243 +{
73244 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73245 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73246 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73247 + return -EPERM;
73248 + }
73249 +#endif
73250 + return 0;
73251 +}
73252 +
73253 +int
73254 +gr_handle_chroot_pivot(void)
73255 +{
73256 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73257 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73258 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73259 + return -EPERM;
73260 + }
73261 +#endif
73262 + return 0;
73263 +}
73264 +
73265 +int
73266 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73267 +{
73268 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73269 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73270 + !gr_is_outside_chroot(dentry, mnt)) {
73271 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73272 + return -EPERM;
73273 + }
73274 +#endif
73275 + return 0;
73276 +}
73277 +
73278 +extern const char *captab_log[];
73279 +extern int captab_log_entries;
73280 +
73281 +int
73282 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73283 +{
73284 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73285 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73286 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73287 + if (cap_raised(chroot_caps, cap)) {
73288 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73289 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73290 + }
73291 + return 0;
73292 + }
73293 + }
73294 +#endif
73295 + return 1;
73296 +}
73297 +
73298 +int
73299 +gr_chroot_is_capable(const int cap)
73300 +{
73301 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73302 + return gr_task_chroot_is_capable(current, current_cred(), cap);
73303 +#endif
73304 + return 1;
73305 +}
73306 +
73307 +int
73308 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73309 +{
73310 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73311 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73312 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73313 + if (cap_raised(chroot_caps, cap)) {
73314 + return 0;
73315 + }
73316 + }
73317 +#endif
73318 + return 1;
73319 +}
73320 +
73321 +int
73322 +gr_chroot_is_capable_nolog(const int cap)
73323 +{
73324 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73325 + return gr_task_chroot_is_capable_nolog(current, cap);
73326 +#endif
73327 + return 1;
73328 +}
73329 +
73330 +int
73331 +gr_handle_chroot_sysctl(const int op)
73332 +{
73333 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73334 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73335 + proc_is_chrooted(current))
73336 + return -EACCES;
73337 +#endif
73338 + return 0;
73339 +}
73340 +
73341 +void
73342 +gr_handle_chroot_chdir(const struct path *path)
73343 +{
73344 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73345 + if (grsec_enable_chroot_chdir)
73346 + set_fs_pwd(current->fs, path);
73347 +#endif
73348 + return;
73349 +}
73350 +
73351 +int
73352 +gr_handle_chroot_chmod(const struct dentry *dentry,
73353 + const struct vfsmount *mnt, const int mode)
73354 +{
73355 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73356 + /* allow chmod +s on directories, but not files */
73357 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73358 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73359 + proc_is_chrooted(current)) {
73360 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73361 + return -EPERM;
73362 + }
73363 +#endif
73364 + return 0;
73365 +}
73366 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73367 new file mode 100644
73368 index 0000000..4d6fce8
73369 --- /dev/null
73370 +++ b/grsecurity/grsec_disabled.c
73371 @@ -0,0 +1,433 @@
73372 +#include <linux/kernel.h>
73373 +#include <linux/module.h>
73374 +#include <linux/sched.h>
73375 +#include <linux/file.h>
73376 +#include <linux/fs.h>
73377 +#include <linux/kdev_t.h>
73378 +#include <linux/net.h>
73379 +#include <linux/in.h>
73380 +#include <linux/ip.h>
73381 +#include <linux/skbuff.h>
73382 +#include <linux/sysctl.h>
73383 +
73384 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73385 +void
73386 +pax_set_initial_flags(struct linux_binprm *bprm)
73387 +{
73388 + return;
73389 +}
73390 +#endif
73391 +
73392 +#ifdef CONFIG_SYSCTL
73393 +__u32
73394 +gr_handle_sysctl(const struct ctl_table * table, const int op)
73395 +{
73396 + return 0;
73397 +}
73398 +#endif
73399 +
73400 +#ifdef CONFIG_TASKSTATS
73401 +int gr_is_taskstats_denied(int pid)
73402 +{
73403 + return 0;
73404 +}
73405 +#endif
73406 +
73407 +int
73408 +gr_acl_is_enabled(void)
73409 +{
73410 + return 0;
73411 +}
73412 +
73413 +void
73414 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73415 +{
73416 + return;
73417 +}
73418 +
73419 +int
73420 +gr_handle_rawio(const struct inode *inode)
73421 +{
73422 + return 0;
73423 +}
73424 +
73425 +void
73426 +gr_acl_handle_psacct(struct task_struct *task, const long code)
73427 +{
73428 + return;
73429 +}
73430 +
73431 +int
73432 +gr_handle_ptrace(struct task_struct *task, const long request)
73433 +{
73434 + return 0;
73435 +}
73436 +
73437 +int
73438 +gr_handle_proc_ptrace(struct task_struct *task)
73439 +{
73440 + return 0;
73441 +}
73442 +
73443 +int
73444 +gr_set_acls(const int type)
73445 +{
73446 + return 0;
73447 +}
73448 +
73449 +int
73450 +gr_check_hidden_task(const struct task_struct *tsk)
73451 +{
73452 + return 0;
73453 +}
73454 +
73455 +int
73456 +gr_check_protected_task(const struct task_struct *task)
73457 +{
73458 + return 0;
73459 +}
73460 +
73461 +int
73462 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73463 +{
73464 + return 0;
73465 +}
73466 +
73467 +void
73468 +gr_copy_label(struct task_struct *tsk)
73469 +{
73470 + return;
73471 +}
73472 +
73473 +void
73474 +gr_set_pax_flags(struct task_struct *task)
73475 +{
73476 + return;
73477 +}
73478 +
73479 +int
73480 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73481 + const int unsafe_share)
73482 +{
73483 + return 0;
73484 +}
73485 +
73486 +void
73487 +gr_handle_delete(const ino_t ino, const dev_t dev)
73488 +{
73489 + return;
73490 +}
73491 +
73492 +void
73493 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73494 +{
73495 + return;
73496 +}
73497 +
73498 +void
73499 +gr_handle_crash(struct task_struct *task, const int sig)
73500 +{
73501 + return;
73502 +}
73503 +
73504 +int
73505 +gr_check_crash_exec(const struct file *filp)
73506 +{
73507 + return 0;
73508 +}
73509 +
73510 +int
73511 +gr_check_crash_uid(const kuid_t uid)
73512 +{
73513 + return 0;
73514 +}
73515 +
73516 +void
73517 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73518 + struct dentry *old_dentry,
73519 + struct dentry *new_dentry,
73520 + struct vfsmount *mnt, const __u8 replace)
73521 +{
73522 + return;
73523 +}
73524 +
73525 +int
73526 +gr_search_socket(const int family, const int type, const int protocol)
73527 +{
73528 + return 1;
73529 +}
73530 +
73531 +int
73532 +gr_search_connectbind(const int mode, const struct socket *sock,
73533 + const struct sockaddr_in *addr)
73534 +{
73535 + return 0;
73536 +}
73537 +
73538 +void
73539 +gr_handle_alertkill(struct task_struct *task)
73540 +{
73541 + return;
73542 +}
73543 +
73544 +__u32
73545 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73546 +{
73547 + return 1;
73548 +}
73549 +
73550 +__u32
73551 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73552 + const struct vfsmount * mnt)
73553 +{
73554 + return 1;
73555 +}
73556 +
73557 +__u32
73558 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73559 + int acc_mode)
73560 +{
73561 + return 1;
73562 +}
73563 +
73564 +__u32
73565 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73566 +{
73567 + return 1;
73568 +}
73569 +
73570 +__u32
73571 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73572 +{
73573 + return 1;
73574 +}
73575 +
73576 +int
73577 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73578 + unsigned int *vm_flags)
73579 +{
73580 + return 1;
73581 +}
73582 +
73583 +__u32
73584 +gr_acl_handle_truncate(const struct dentry * dentry,
73585 + const struct vfsmount * mnt)
73586 +{
73587 + return 1;
73588 +}
73589 +
73590 +__u32
73591 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73592 +{
73593 + return 1;
73594 +}
73595 +
73596 +__u32
73597 +gr_acl_handle_access(const struct dentry * dentry,
73598 + const struct vfsmount * mnt, const int fmode)
73599 +{
73600 + return 1;
73601 +}
73602 +
73603 +__u32
73604 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73605 + umode_t *mode)
73606 +{
73607 + return 1;
73608 +}
73609 +
73610 +__u32
73611 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73612 +{
73613 + return 1;
73614 +}
73615 +
73616 +__u32
73617 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73618 +{
73619 + return 1;
73620 +}
73621 +
73622 +__u32
73623 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73624 +{
73625 + return 1;
73626 +}
73627 +
73628 +void
73629 +grsecurity_init(void)
73630 +{
73631 + return;
73632 +}
73633 +
73634 +umode_t gr_acl_umask(void)
73635 +{
73636 + return 0;
73637 +}
73638 +
73639 +__u32
73640 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73641 + const struct dentry * parent_dentry,
73642 + const struct vfsmount * parent_mnt,
73643 + const int mode)
73644 +{
73645 + return 1;
73646 +}
73647 +
73648 +__u32
73649 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
73650 + const struct dentry * parent_dentry,
73651 + const struct vfsmount * parent_mnt)
73652 +{
73653 + return 1;
73654 +}
73655 +
73656 +__u32
73657 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73658 + const struct dentry * parent_dentry,
73659 + const struct vfsmount * parent_mnt, const struct filename *from)
73660 +{
73661 + return 1;
73662 +}
73663 +
73664 +__u32
73665 +gr_acl_handle_link(const struct dentry * new_dentry,
73666 + const struct dentry * parent_dentry,
73667 + const struct vfsmount * parent_mnt,
73668 + const struct dentry * old_dentry,
73669 + const struct vfsmount * old_mnt, const struct filename *to)
73670 +{
73671 + return 1;
73672 +}
73673 +
73674 +int
73675 +gr_acl_handle_rename(const struct dentry *new_dentry,
73676 + const struct dentry *parent_dentry,
73677 + const struct vfsmount *parent_mnt,
73678 + const struct dentry *old_dentry,
73679 + const struct inode *old_parent_inode,
73680 + const struct vfsmount *old_mnt, const struct filename *newname)
73681 +{
73682 + return 0;
73683 +}
73684 +
73685 +int
73686 +gr_acl_handle_filldir(const struct file *file, const char *name,
73687 + const int namelen, const ino_t ino)
73688 +{
73689 + return 1;
73690 +}
73691 +
73692 +int
73693 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73694 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73695 +{
73696 + return 1;
73697 +}
73698 +
73699 +int
73700 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73701 +{
73702 + return 0;
73703 +}
73704 +
73705 +int
73706 +gr_search_accept(const struct socket *sock)
73707 +{
73708 + return 0;
73709 +}
73710 +
73711 +int
73712 +gr_search_listen(const struct socket *sock)
73713 +{
73714 + return 0;
73715 +}
73716 +
73717 +int
73718 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73719 +{
73720 + return 0;
73721 +}
73722 +
73723 +__u32
73724 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73725 +{
73726 + return 1;
73727 +}
73728 +
73729 +__u32
73730 +gr_acl_handle_creat(const struct dentry * dentry,
73731 + const struct dentry * p_dentry,
73732 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73733 + const int imode)
73734 +{
73735 + return 1;
73736 +}
73737 +
73738 +void
73739 +gr_acl_handle_exit(void)
73740 +{
73741 + return;
73742 +}
73743 +
73744 +int
73745 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73746 +{
73747 + return 1;
73748 +}
73749 +
73750 +void
73751 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
73752 +{
73753 + return;
73754 +}
73755 +
73756 +int
73757 +gr_acl_handle_procpidmem(const struct task_struct *task)
73758 +{
73759 + return 0;
73760 +}
73761 +
73762 +int
73763 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73764 +{
73765 + return 0;
73766 +}
73767 +
73768 +int
73769 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73770 +{
73771 + return 0;
73772 +}
73773 +
73774 +int
73775 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73776 +{
73777 + return 0;
73778 +}
73779 +
73780 +int
73781 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73782 +{
73783 + return 0;
73784 +}
73785 +
73786 +int gr_acl_enable_at_secure(void)
73787 +{
73788 + return 0;
73789 +}
73790 +
73791 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73792 +{
73793 + return dentry->d_sb->s_dev;
73794 +}
73795 +
73796 +void gr_put_exec_file(struct task_struct *task)
73797 +{
73798 + return;
73799 +}
73800 +
73801 +#ifdef CONFIG_SECURITY
73802 +EXPORT_SYMBOL_GPL(gr_check_user_change);
73803 +EXPORT_SYMBOL_GPL(gr_check_group_change);
73804 +#endif
73805 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73806 new file mode 100644
73807 index 0000000..f35f454
73808 --- /dev/null
73809 +++ b/grsecurity/grsec_exec.c
73810 @@ -0,0 +1,187 @@
73811 +#include <linux/kernel.h>
73812 +#include <linux/sched.h>
73813 +#include <linux/file.h>
73814 +#include <linux/binfmts.h>
73815 +#include <linux/fs.h>
73816 +#include <linux/types.h>
73817 +#include <linux/grdefs.h>
73818 +#include <linux/grsecurity.h>
73819 +#include <linux/grinternal.h>
73820 +#include <linux/capability.h>
73821 +#include <linux/module.h>
73822 +#include <linux/compat.h>
73823 +
73824 +#include <asm/uaccess.h>
73825 +
73826 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73827 +static char gr_exec_arg_buf[132];
73828 +static DEFINE_MUTEX(gr_exec_arg_mutex);
73829 +#endif
73830 +
73831 +struct user_arg_ptr {
73832 +#ifdef CONFIG_COMPAT
73833 + bool is_compat;
73834 +#endif
73835 + union {
73836 + const char __user *const __user *native;
73837 +#ifdef CONFIG_COMPAT
73838 + const compat_uptr_t __user *compat;
73839 +#endif
73840 + } ptr;
73841 +};
73842 +
73843 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73844 +
73845 +void
73846 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73847 +{
73848 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73849 + char *grarg = gr_exec_arg_buf;
73850 + unsigned int i, x, execlen = 0;
73851 + char c;
73852 +
73853 + if (!((grsec_enable_execlog && grsec_enable_group &&
73854 + in_group_p(grsec_audit_gid))
73855 + || (grsec_enable_execlog && !grsec_enable_group)))
73856 + return;
73857 +
73858 + mutex_lock(&gr_exec_arg_mutex);
73859 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
73860 +
73861 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
73862 + const char __user *p;
73863 + unsigned int len;
73864 +
73865 + p = get_user_arg_ptr(argv, i);
73866 + if (IS_ERR(p))
73867 + goto log;
73868 +
73869 + len = strnlen_user(p, 128 - execlen);
73870 + if (len > 128 - execlen)
73871 + len = 128 - execlen;
73872 + else if (len > 0)
73873 + len--;
73874 + if (copy_from_user(grarg + execlen, p, len))
73875 + goto log;
73876 +
73877 + /* rewrite unprintable characters */
73878 + for (x = 0; x < len; x++) {
73879 + c = *(grarg + execlen + x);
73880 + if (c < 32 || c > 126)
73881 + *(grarg + execlen + x) = ' ';
73882 + }
73883 +
73884 + execlen += len;
73885 + *(grarg + execlen) = ' ';
73886 + *(grarg + execlen + 1) = '\0';
73887 + execlen++;
73888 + }
73889 +
73890 + log:
73891 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73892 + bprm->file->f_path.mnt, grarg);
73893 + mutex_unlock(&gr_exec_arg_mutex);
73894 +#endif
73895 + return;
73896 +}
73897 +
73898 +#ifdef CONFIG_GRKERNSEC
73899 +extern int gr_acl_is_capable(const int cap);
73900 +extern int gr_acl_is_capable_nolog(const int cap);
73901 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73902 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
73903 +extern int gr_chroot_is_capable(const int cap);
73904 +extern int gr_chroot_is_capable_nolog(const int cap);
73905 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73906 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
73907 +#endif
73908 +
73909 +const char *captab_log[] = {
73910 + "CAP_CHOWN",
73911 + "CAP_DAC_OVERRIDE",
73912 + "CAP_DAC_READ_SEARCH",
73913 + "CAP_FOWNER",
73914 + "CAP_FSETID",
73915 + "CAP_KILL",
73916 + "CAP_SETGID",
73917 + "CAP_SETUID",
73918 + "CAP_SETPCAP",
73919 + "CAP_LINUX_IMMUTABLE",
73920 + "CAP_NET_BIND_SERVICE",
73921 + "CAP_NET_BROADCAST",
73922 + "CAP_NET_ADMIN",
73923 + "CAP_NET_RAW",
73924 + "CAP_IPC_LOCK",
73925 + "CAP_IPC_OWNER",
73926 + "CAP_SYS_MODULE",
73927 + "CAP_SYS_RAWIO",
73928 + "CAP_SYS_CHROOT",
73929 + "CAP_SYS_PTRACE",
73930 + "CAP_SYS_PACCT",
73931 + "CAP_SYS_ADMIN",
73932 + "CAP_SYS_BOOT",
73933 + "CAP_SYS_NICE",
73934 + "CAP_SYS_RESOURCE",
73935 + "CAP_SYS_TIME",
73936 + "CAP_SYS_TTY_CONFIG",
73937 + "CAP_MKNOD",
73938 + "CAP_LEASE",
73939 + "CAP_AUDIT_WRITE",
73940 + "CAP_AUDIT_CONTROL",
73941 + "CAP_SETFCAP",
73942 + "CAP_MAC_OVERRIDE",
73943 + "CAP_MAC_ADMIN",
73944 + "CAP_SYSLOG",
73945 + "CAP_WAKE_ALARM"
73946 +};
73947 +
73948 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
73949 +
73950 +int gr_is_capable(const int cap)
73951 +{
73952 +#ifdef CONFIG_GRKERNSEC
73953 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
73954 + return 1;
73955 + return 0;
73956 +#else
73957 + return 1;
73958 +#endif
73959 +}
73960 +
73961 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73962 +{
73963 +#ifdef CONFIG_GRKERNSEC
73964 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
73965 + return 1;
73966 + return 0;
73967 +#else
73968 + return 1;
73969 +#endif
73970 +}
73971 +
73972 +int gr_is_capable_nolog(const int cap)
73973 +{
73974 +#ifdef CONFIG_GRKERNSEC
73975 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
73976 + return 1;
73977 + return 0;
73978 +#else
73979 + return 1;
73980 +#endif
73981 +}
73982 +
73983 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
73984 +{
73985 +#ifdef CONFIG_GRKERNSEC
73986 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
73987 + return 1;
73988 + return 0;
73989 +#else
73990 + return 1;
73991 +#endif
73992 +}
73993 +
73994 +EXPORT_SYMBOL_GPL(gr_is_capable);
73995 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
73996 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
73997 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
73998 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
73999 new file mode 100644
74000 index 0000000..06cc6ea
74001 --- /dev/null
74002 +++ b/grsecurity/grsec_fifo.c
74003 @@ -0,0 +1,24 @@
74004 +#include <linux/kernel.h>
74005 +#include <linux/sched.h>
74006 +#include <linux/fs.h>
74007 +#include <linux/file.h>
74008 +#include <linux/grinternal.h>
74009 +
74010 +int
74011 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74012 + const struct dentry *dir, const int flag, const int acc_mode)
74013 +{
74014 +#ifdef CONFIG_GRKERNSEC_FIFO
74015 + const struct cred *cred = current_cred();
74016 +
74017 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74018 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74019 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74020 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74021 + if (!inode_permission(dentry->d_inode, acc_mode))
74022 + 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));
74023 + return -EACCES;
74024 + }
74025 +#endif
74026 + return 0;
74027 +}
74028 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74029 new file mode 100644
74030 index 0000000..8ca18bf
74031 --- /dev/null
74032 +++ b/grsecurity/grsec_fork.c
74033 @@ -0,0 +1,23 @@
74034 +#include <linux/kernel.h>
74035 +#include <linux/sched.h>
74036 +#include <linux/grsecurity.h>
74037 +#include <linux/grinternal.h>
74038 +#include <linux/errno.h>
74039 +
74040 +void
74041 +gr_log_forkfail(const int retval)
74042 +{
74043 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74044 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74045 + switch (retval) {
74046 + case -EAGAIN:
74047 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74048 + break;
74049 + case -ENOMEM:
74050 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74051 + break;
74052 + }
74053 + }
74054 +#endif
74055 + return;
74056 +}
74057 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74058 new file mode 100644
74059 index 0000000..ae6c028
74060 --- /dev/null
74061 +++ b/grsecurity/grsec_init.c
74062 @@ -0,0 +1,272 @@
74063 +#include <linux/kernel.h>
74064 +#include <linux/sched.h>
74065 +#include <linux/mm.h>
74066 +#include <linux/gracl.h>
74067 +#include <linux/slab.h>
74068 +#include <linux/vmalloc.h>
74069 +#include <linux/percpu.h>
74070 +#include <linux/module.h>
74071 +
74072 +int grsec_enable_ptrace_readexec;
74073 +int grsec_enable_setxid;
74074 +int grsec_enable_symlinkown;
74075 +kgid_t grsec_symlinkown_gid;
74076 +int grsec_enable_brute;
74077 +int grsec_enable_link;
74078 +int grsec_enable_dmesg;
74079 +int grsec_enable_harden_ptrace;
74080 +int grsec_enable_harden_ipc;
74081 +int grsec_enable_fifo;
74082 +int grsec_enable_execlog;
74083 +int grsec_enable_signal;
74084 +int grsec_enable_forkfail;
74085 +int grsec_enable_audit_ptrace;
74086 +int grsec_enable_time;
74087 +int grsec_enable_group;
74088 +kgid_t grsec_audit_gid;
74089 +int grsec_enable_chdir;
74090 +int grsec_enable_mount;
74091 +int grsec_enable_rofs;
74092 +int grsec_deny_new_usb;
74093 +int grsec_enable_chroot_findtask;
74094 +int grsec_enable_chroot_mount;
74095 +int grsec_enable_chroot_shmat;
74096 +int grsec_enable_chroot_fchdir;
74097 +int grsec_enable_chroot_double;
74098 +int grsec_enable_chroot_pivot;
74099 +int grsec_enable_chroot_chdir;
74100 +int grsec_enable_chroot_chmod;
74101 +int grsec_enable_chroot_mknod;
74102 +int grsec_enable_chroot_nice;
74103 +int grsec_enable_chroot_execlog;
74104 +int grsec_enable_chroot_caps;
74105 +int grsec_enable_chroot_sysctl;
74106 +int grsec_enable_chroot_unix;
74107 +int grsec_enable_tpe;
74108 +kgid_t grsec_tpe_gid;
74109 +int grsec_enable_blackhole;
74110 +#ifdef CONFIG_IPV6_MODULE
74111 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74112 +#endif
74113 +int grsec_lastack_retries;
74114 +int grsec_enable_tpe_all;
74115 +int grsec_enable_tpe_invert;
74116 +int grsec_enable_socket_all;
74117 +kgid_t grsec_socket_all_gid;
74118 +int grsec_enable_socket_client;
74119 +kgid_t grsec_socket_client_gid;
74120 +int grsec_enable_socket_server;
74121 +kgid_t grsec_socket_server_gid;
74122 +int grsec_resource_logging;
74123 +int grsec_disable_privio;
74124 +int grsec_enable_log_rwxmaps;
74125 +int grsec_lock;
74126 +
74127 +DEFINE_SPINLOCK(grsec_alert_lock);
74128 +unsigned long grsec_alert_wtime = 0;
74129 +unsigned long grsec_alert_fyet = 0;
74130 +
74131 +DEFINE_SPINLOCK(grsec_audit_lock);
74132 +
74133 +DEFINE_RWLOCK(grsec_exec_file_lock);
74134 +
74135 +char *gr_shared_page[4];
74136 +
74137 +char *gr_alert_log_fmt;
74138 +char *gr_audit_log_fmt;
74139 +char *gr_alert_log_buf;
74140 +char *gr_audit_log_buf;
74141 +
74142 +void __init
74143 +grsecurity_init(void)
74144 +{
74145 + int j;
74146 + /* create the per-cpu shared pages */
74147 +
74148 +#ifdef CONFIG_X86
74149 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74150 +#endif
74151 +
74152 + for (j = 0; j < 4; j++) {
74153 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74154 + if (gr_shared_page[j] == NULL) {
74155 + panic("Unable to allocate grsecurity shared page");
74156 + return;
74157 + }
74158 + }
74159 +
74160 + /* allocate log buffers */
74161 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74162 + if (!gr_alert_log_fmt) {
74163 + panic("Unable to allocate grsecurity alert log format buffer");
74164 + return;
74165 + }
74166 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74167 + if (!gr_audit_log_fmt) {
74168 + panic("Unable to allocate grsecurity audit log format buffer");
74169 + return;
74170 + }
74171 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74172 + if (!gr_alert_log_buf) {
74173 + panic("Unable to allocate grsecurity alert log buffer");
74174 + return;
74175 + }
74176 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74177 + if (!gr_audit_log_buf) {
74178 + panic("Unable to allocate grsecurity audit log buffer");
74179 + return;
74180 + }
74181 +
74182 +#ifdef CONFIG_GRKERNSEC_IO
74183 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74184 + grsec_disable_privio = 1;
74185 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74186 + grsec_disable_privio = 1;
74187 +#else
74188 + grsec_disable_privio = 0;
74189 +#endif
74190 +#endif
74191 +
74192 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74193 + /* for backward compatibility, tpe_invert always defaults to on if
74194 + enabled in the kernel
74195 + */
74196 + grsec_enable_tpe_invert = 1;
74197 +#endif
74198 +
74199 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74200 +#ifndef CONFIG_GRKERNSEC_SYSCTL
74201 + grsec_lock = 1;
74202 +#endif
74203 +
74204 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74205 + grsec_enable_log_rwxmaps = 1;
74206 +#endif
74207 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74208 + grsec_enable_group = 1;
74209 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74210 +#endif
74211 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74212 + grsec_enable_ptrace_readexec = 1;
74213 +#endif
74214 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74215 + grsec_enable_chdir = 1;
74216 +#endif
74217 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74218 + grsec_enable_harden_ptrace = 1;
74219 +#endif
74220 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74221 + grsec_enable_harden_ipc = 1;
74222 +#endif
74223 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74224 + grsec_enable_mount = 1;
74225 +#endif
74226 +#ifdef CONFIG_GRKERNSEC_LINK
74227 + grsec_enable_link = 1;
74228 +#endif
74229 +#ifdef CONFIG_GRKERNSEC_BRUTE
74230 + grsec_enable_brute = 1;
74231 +#endif
74232 +#ifdef CONFIG_GRKERNSEC_DMESG
74233 + grsec_enable_dmesg = 1;
74234 +#endif
74235 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74236 + grsec_enable_blackhole = 1;
74237 + grsec_lastack_retries = 4;
74238 +#endif
74239 +#ifdef CONFIG_GRKERNSEC_FIFO
74240 + grsec_enable_fifo = 1;
74241 +#endif
74242 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74243 + grsec_enable_execlog = 1;
74244 +#endif
74245 +#ifdef CONFIG_GRKERNSEC_SETXID
74246 + grsec_enable_setxid = 1;
74247 +#endif
74248 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74249 + grsec_enable_signal = 1;
74250 +#endif
74251 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74252 + grsec_enable_forkfail = 1;
74253 +#endif
74254 +#ifdef CONFIG_GRKERNSEC_TIME
74255 + grsec_enable_time = 1;
74256 +#endif
74257 +#ifdef CONFIG_GRKERNSEC_RESLOG
74258 + grsec_resource_logging = 1;
74259 +#endif
74260 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74261 + grsec_enable_chroot_findtask = 1;
74262 +#endif
74263 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74264 + grsec_enable_chroot_unix = 1;
74265 +#endif
74266 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74267 + grsec_enable_chroot_mount = 1;
74268 +#endif
74269 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74270 + grsec_enable_chroot_fchdir = 1;
74271 +#endif
74272 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74273 + grsec_enable_chroot_shmat = 1;
74274 +#endif
74275 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74276 + grsec_enable_audit_ptrace = 1;
74277 +#endif
74278 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74279 + grsec_enable_chroot_double = 1;
74280 +#endif
74281 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74282 + grsec_enable_chroot_pivot = 1;
74283 +#endif
74284 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74285 + grsec_enable_chroot_chdir = 1;
74286 +#endif
74287 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74288 + grsec_enable_chroot_chmod = 1;
74289 +#endif
74290 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74291 + grsec_enable_chroot_mknod = 1;
74292 +#endif
74293 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74294 + grsec_enable_chroot_nice = 1;
74295 +#endif
74296 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74297 + grsec_enable_chroot_execlog = 1;
74298 +#endif
74299 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74300 + grsec_enable_chroot_caps = 1;
74301 +#endif
74302 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74303 + grsec_enable_chroot_sysctl = 1;
74304 +#endif
74305 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74306 + grsec_enable_symlinkown = 1;
74307 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74308 +#endif
74309 +#ifdef CONFIG_GRKERNSEC_TPE
74310 + grsec_enable_tpe = 1;
74311 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74312 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74313 + grsec_enable_tpe_all = 1;
74314 +#endif
74315 +#endif
74316 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74317 + grsec_enable_socket_all = 1;
74318 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74319 +#endif
74320 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74321 + grsec_enable_socket_client = 1;
74322 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74323 +#endif
74324 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74325 + grsec_enable_socket_server = 1;
74326 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74327 +#endif
74328 +#endif
74329 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74330 + grsec_deny_new_usb = 1;
74331 +#endif
74332 +
74333 + return;
74334 +}
74335 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74336 new file mode 100644
74337 index 0000000..1773300
74338 --- /dev/null
74339 +++ b/grsecurity/grsec_ipc.c
74340 @@ -0,0 +1,48 @@
74341 +#include <linux/kernel.h>
74342 +#include <linux/mm.h>
74343 +#include <linux/sched.h>
74344 +#include <linux/file.h>
74345 +#include <linux/ipc.h>
74346 +#include <linux/ipc_namespace.h>
74347 +#include <linux/grsecurity.h>
74348 +#include <linux/grinternal.h>
74349 +
74350 +int
74351 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74352 +{
74353 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74354 + int write;
74355 + int orig_granted_mode;
74356 + kuid_t euid;
74357 + kgid_t egid;
74358 +
74359 + if (!grsec_enable_harden_ipc)
74360 + return 1;
74361 +
74362 + euid = current_euid();
74363 + egid = current_egid();
74364 +
74365 + write = requested_mode & 00002;
74366 + orig_granted_mode = ipcp->mode;
74367 +
74368 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74369 + orig_granted_mode >>= 6;
74370 + else {
74371 + /* if likely wrong permissions, lock to user */
74372 + if (orig_granted_mode & 0007)
74373 + orig_granted_mode = 0;
74374 + /* otherwise do a egid-only check */
74375 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74376 + orig_granted_mode >>= 3;
74377 + /* otherwise, no access */
74378 + else
74379 + orig_granted_mode = 0;
74380 + }
74381 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74382 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74383 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74384 + return 0;
74385 + }
74386 +#endif
74387 + return 1;
74388 +}
74389 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74390 new file mode 100644
74391 index 0000000..5e05e20
74392 --- /dev/null
74393 +++ b/grsecurity/grsec_link.c
74394 @@ -0,0 +1,58 @@
74395 +#include <linux/kernel.h>
74396 +#include <linux/sched.h>
74397 +#include <linux/fs.h>
74398 +#include <linux/file.h>
74399 +#include <linux/grinternal.h>
74400 +
74401 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74402 +{
74403 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74404 + const struct inode *link_inode = link->dentry->d_inode;
74405 +
74406 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74407 + /* ignore root-owned links, e.g. /proc/self */
74408 + gr_is_global_nonroot(link_inode->i_uid) && target &&
74409 + !uid_eq(link_inode->i_uid, target->i_uid)) {
74410 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74411 + return 1;
74412 + }
74413 +#endif
74414 + return 0;
74415 +}
74416 +
74417 +int
74418 +gr_handle_follow_link(const struct inode *parent,
74419 + const struct inode *inode,
74420 + const struct dentry *dentry, const struct vfsmount *mnt)
74421 +{
74422 +#ifdef CONFIG_GRKERNSEC_LINK
74423 + const struct cred *cred = current_cred();
74424 +
74425 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74426 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74427 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74428 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74429 + return -EACCES;
74430 + }
74431 +#endif
74432 + return 0;
74433 +}
74434 +
74435 +int
74436 +gr_handle_hardlink(const struct dentry *dentry,
74437 + const struct vfsmount *mnt,
74438 + struct inode *inode, const int mode, const struct filename *to)
74439 +{
74440 +#ifdef CONFIG_GRKERNSEC_LINK
74441 + const struct cred *cred = current_cred();
74442 +
74443 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74444 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74445 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74446 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74447 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74448 + return -EPERM;
74449 + }
74450 +#endif
74451 + return 0;
74452 +}
74453 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74454 new file mode 100644
74455 index 0000000..dbe0a6b
74456 --- /dev/null
74457 +++ b/grsecurity/grsec_log.c
74458 @@ -0,0 +1,341 @@
74459 +#include <linux/kernel.h>
74460 +#include <linux/sched.h>
74461 +#include <linux/file.h>
74462 +#include <linux/tty.h>
74463 +#include <linux/fs.h>
74464 +#include <linux/mm.h>
74465 +#include <linux/grinternal.h>
74466 +
74467 +#ifdef CONFIG_TREE_PREEMPT_RCU
74468 +#define DISABLE_PREEMPT() preempt_disable()
74469 +#define ENABLE_PREEMPT() preempt_enable()
74470 +#else
74471 +#define DISABLE_PREEMPT()
74472 +#define ENABLE_PREEMPT()
74473 +#endif
74474 +
74475 +#define BEGIN_LOCKS(x) \
74476 + DISABLE_PREEMPT(); \
74477 + rcu_read_lock(); \
74478 + read_lock(&tasklist_lock); \
74479 + read_lock(&grsec_exec_file_lock); \
74480 + if (x != GR_DO_AUDIT) \
74481 + spin_lock(&grsec_alert_lock); \
74482 + else \
74483 + spin_lock(&grsec_audit_lock)
74484 +
74485 +#define END_LOCKS(x) \
74486 + if (x != GR_DO_AUDIT) \
74487 + spin_unlock(&grsec_alert_lock); \
74488 + else \
74489 + spin_unlock(&grsec_audit_lock); \
74490 + read_unlock(&grsec_exec_file_lock); \
74491 + read_unlock(&tasklist_lock); \
74492 + rcu_read_unlock(); \
74493 + ENABLE_PREEMPT(); \
74494 + if (x == GR_DONT_AUDIT) \
74495 + gr_handle_alertkill(current)
74496 +
74497 +enum {
74498 + FLOODING,
74499 + NO_FLOODING
74500 +};
74501 +
74502 +extern char *gr_alert_log_fmt;
74503 +extern char *gr_audit_log_fmt;
74504 +extern char *gr_alert_log_buf;
74505 +extern char *gr_audit_log_buf;
74506 +
74507 +static int gr_log_start(int audit)
74508 +{
74509 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74510 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74511 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74512 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74513 + unsigned long curr_secs = get_seconds();
74514 +
74515 + if (audit == GR_DO_AUDIT)
74516 + goto set_fmt;
74517 +
74518 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74519 + grsec_alert_wtime = curr_secs;
74520 + grsec_alert_fyet = 0;
74521 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74522 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74523 + grsec_alert_fyet++;
74524 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74525 + grsec_alert_wtime = curr_secs;
74526 + grsec_alert_fyet++;
74527 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74528 + return FLOODING;
74529 + }
74530 + else return FLOODING;
74531 +
74532 +set_fmt:
74533 +#endif
74534 + memset(buf, 0, PAGE_SIZE);
74535 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
74536 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74537 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74538 + } else if (current->signal->curr_ip) {
74539 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74540 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74541 + } else if (gr_acl_is_enabled()) {
74542 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74543 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74544 + } else {
74545 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
74546 + strcpy(buf, fmt);
74547 + }
74548 +
74549 + return NO_FLOODING;
74550 +}
74551 +
74552 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74553 + __attribute__ ((format (printf, 2, 0)));
74554 +
74555 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74556 +{
74557 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74558 + unsigned int len = strlen(buf);
74559 +
74560 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74561 +
74562 + return;
74563 +}
74564 +
74565 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74566 + __attribute__ ((format (printf, 2, 3)));
74567 +
74568 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74569 +{
74570 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74571 + unsigned int len = strlen(buf);
74572 + va_list ap;
74573 +
74574 + va_start(ap, msg);
74575 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74576 + va_end(ap);
74577 +
74578 + return;
74579 +}
74580 +
74581 +static void gr_log_end(int audit, int append_default)
74582 +{
74583 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74584 + if (append_default) {
74585 + struct task_struct *task = current;
74586 + struct task_struct *parent = task->real_parent;
74587 + const struct cred *cred = __task_cred(task);
74588 + const struct cred *pcred = __task_cred(parent);
74589 + unsigned int len = strlen(buf);
74590 +
74591 + 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));
74592 + }
74593 +
74594 + printk("%s\n", buf);
74595 +
74596 + return;
74597 +}
74598 +
74599 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74600 +{
74601 + int logtype;
74602 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74603 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74604 + void *voidptr = NULL;
74605 + int num1 = 0, num2 = 0;
74606 + unsigned long ulong1 = 0, ulong2 = 0;
74607 + struct dentry *dentry = NULL;
74608 + struct vfsmount *mnt = NULL;
74609 + struct file *file = NULL;
74610 + struct task_struct *task = NULL;
74611 + struct vm_area_struct *vma = NULL;
74612 + const struct cred *cred, *pcred;
74613 + va_list ap;
74614 +
74615 + BEGIN_LOCKS(audit);
74616 + logtype = gr_log_start(audit);
74617 + if (logtype == FLOODING) {
74618 + END_LOCKS(audit);
74619 + return;
74620 + }
74621 + va_start(ap, argtypes);
74622 + switch (argtypes) {
74623 + case GR_TTYSNIFF:
74624 + task = va_arg(ap, struct task_struct *);
74625 + 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));
74626 + break;
74627 + case GR_SYSCTL_HIDDEN:
74628 + str1 = va_arg(ap, char *);
74629 + gr_log_middle_varargs(audit, msg, result, str1);
74630 + break;
74631 + case GR_RBAC:
74632 + dentry = va_arg(ap, struct dentry *);
74633 + mnt = va_arg(ap, struct vfsmount *);
74634 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74635 + break;
74636 + case GR_RBAC_STR:
74637 + dentry = va_arg(ap, struct dentry *);
74638 + mnt = va_arg(ap, struct vfsmount *);
74639 + str1 = va_arg(ap, char *);
74640 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74641 + break;
74642 + case GR_STR_RBAC:
74643 + str1 = va_arg(ap, char *);
74644 + dentry = va_arg(ap, struct dentry *);
74645 + mnt = va_arg(ap, struct vfsmount *);
74646 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74647 + break;
74648 + case GR_RBAC_MODE2:
74649 + dentry = va_arg(ap, struct dentry *);
74650 + mnt = va_arg(ap, struct vfsmount *);
74651 + str1 = va_arg(ap, char *);
74652 + str2 = va_arg(ap, char *);
74653 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74654 + break;
74655 + case GR_RBAC_MODE3:
74656 + dentry = va_arg(ap, struct dentry *);
74657 + mnt = va_arg(ap, struct vfsmount *);
74658 + str1 = va_arg(ap, char *);
74659 + str2 = va_arg(ap, char *);
74660 + str3 = va_arg(ap, char *);
74661 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74662 + break;
74663 + case GR_FILENAME:
74664 + dentry = va_arg(ap, struct dentry *);
74665 + mnt = va_arg(ap, struct vfsmount *);
74666 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74667 + break;
74668 + case GR_STR_FILENAME:
74669 + str1 = va_arg(ap, char *);
74670 + dentry = va_arg(ap, struct dentry *);
74671 + mnt = va_arg(ap, struct vfsmount *);
74672 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74673 + break;
74674 + case GR_FILENAME_STR:
74675 + dentry = va_arg(ap, struct dentry *);
74676 + mnt = va_arg(ap, struct vfsmount *);
74677 + str1 = va_arg(ap, char *);
74678 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74679 + break;
74680 + case GR_FILENAME_TWO_INT:
74681 + dentry = va_arg(ap, struct dentry *);
74682 + mnt = va_arg(ap, struct vfsmount *);
74683 + num1 = va_arg(ap, int);
74684 + num2 = va_arg(ap, int);
74685 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74686 + break;
74687 + case GR_FILENAME_TWO_INT_STR:
74688 + dentry = va_arg(ap, struct dentry *);
74689 + mnt = va_arg(ap, struct vfsmount *);
74690 + num1 = va_arg(ap, int);
74691 + num2 = va_arg(ap, int);
74692 + str1 = va_arg(ap, char *);
74693 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74694 + break;
74695 + case GR_TEXTREL:
74696 + file = va_arg(ap, struct file *);
74697 + ulong1 = va_arg(ap, unsigned long);
74698 + ulong2 = va_arg(ap, unsigned long);
74699 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74700 + break;
74701 + case GR_PTRACE:
74702 + task = va_arg(ap, struct task_struct *);
74703 + 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));
74704 + break;
74705 + case GR_RESOURCE:
74706 + task = va_arg(ap, struct task_struct *);
74707 + cred = __task_cred(task);
74708 + pcred = __task_cred(task->real_parent);
74709 + ulong1 = va_arg(ap, unsigned long);
74710 + str1 = va_arg(ap, char *);
74711 + ulong2 = va_arg(ap, unsigned long);
74712 + 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));
74713 + break;
74714 + case GR_CAP:
74715 + task = va_arg(ap, struct task_struct *);
74716 + cred = __task_cred(task);
74717 + pcred = __task_cred(task->real_parent);
74718 + str1 = va_arg(ap, char *);
74719 + 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));
74720 + break;
74721 + case GR_SIG:
74722 + str1 = va_arg(ap, char *);
74723 + voidptr = va_arg(ap, void *);
74724 + gr_log_middle_varargs(audit, msg, str1, voidptr);
74725 + break;
74726 + case GR_SIG2:
74727 + task = va_arg(ap, struct task_struct *);
74728 + cred = __task_cred(task);
74729 + pcred = __task_cred(task->real_parent);
74730 + num1 = va_arg(ap, int);
74731 + 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));
74732 + break;
74733 + case GR_CRASH1:
74734 + task = va_arg(ap, struct task_struct *);
74735 + cred = __task_cred(task);
74736 + pcred = __task_cred(task->real_parent);
74737 + ulong1 = va_arg(ap, unsigned long);
74738 + 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);
74739 + break;
74740 + case GR_CRASH2:
74741 + task = va_arg(ap, struct task_struct *);
74742 + cred = __task_cred(task);
74743 + pcred = __task_cred(task->real_parent);
74744 + ulong1 = va_arg(ap, unsigned long);
74745 + 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);
74746 + break;
74747 + case GR_RWXMAP:
74748 + file = va_arg(ap, struct file *);
74749 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74750 + break;
74751 + case GR_RWXMAPVMA:
74752 + vma = va_arg(ap, struct vm_area_struct *);
74753 + if (vma->vm_file)
74754 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74755 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74756 + str1 = "<stack>";
74757 + else if (vma->vm_start <= current->mm->brk &&
74758 + vma->vm_end >= current->mm->start_brk)
74759 + str1 = "<heap>";
74760 + else
74761 + str1 = "<anonymous mapping>";
74762 + gr_log_middle_varargs(audit, msg, str1);
74763 + break;
74764 + case GR_PSACCT:
74765 + {
74766 + unsigned int wday, cday;
74767 + __u8 whr, chr;
74768 + __u8 wmin, cmin;
74769 + __u8 wsec, csec;
74770 + char cur_tty[64] = { 0 };
74771 + char parent_tty[64] = { 0 };
74772 +
74773 + task = va_arg(ap, struct task_struct *);
74774 + wday = va_arg(ap, unsigned int);
74775 + cday = va_arg(ap, unsigned int);
74776 + whr = va_arg(ap, int);
74777 + chr = va_arg(ap, int);
74778 + wmin = va_arg(ap, int);
74779 + cmin = va_arg(ap, int);
74780 + wsec = va_arg(ap, int);
74781 + csec = va_arg(ap, int);
74782 + ulong1 = va_arg(ap, unsigned long);
74783 + cred = __task_cred(task);
74784 + pcred = __task_cred(task->real_parent);
74785 +
74786 + 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));
74787 + }
74788 + break;
74789 + default:
74790 + gr_log_middle(audit, msg, ap);
74791 + }
74792 + va_end(ap);
74793 + // these don't need DEFAULTSECARGS printed on the end
74794 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74795 + gr_log_end(audit, 0);
74796 + else
74797 + gr_log_end(audit, 1);
74798 + END_LOCKS(audit);
74799 +}
74800 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74801 new file mode 100644
74802 index 0000000..0e39d8c
74803 --- /dev/null
74804 +++ b/grsecurity/grsec_mem.c
74805 @@ -0,0 +1,48 @@
74806 +#include <linux/kernel.h>
74807 +#include <linux/sched.h>
74808 +#include <linux/mm.h>
74809 +#include <linux/mman.h>
74810 +#include <linux/module.h>
74811 +#include <linux/grinternal.h>
74812 +
74813 +void gr_handle_msr_write(void)
74814 +{
74815 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74816 + return;
74817 +}
74818 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74819 +
74820 +void
74821 +gr_handle_ioperm(void)
74822 +{
74823 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74824 + return;
74825 +}
74826 +
74827 +void
74828 +gr_handle_iopl(void)
74829 +{
74830 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74831 + return;
74832 +}
74833 +
74834 +void
74835 +gr_handle_mem_readwrite(u64 from, u64 to)
74836 +{
74837 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74838 + return;
74839 +}
74840 +
74841 +void
74842 +gr_handle_vm86(void)
74843 +{
74844 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74845 + return;
74846 +}
74847 +
74848 +void
74849 +gr_log_badprocpid(const char *entry)
74850 +{
74851 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74852 + return;
74853 +}
74854 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74855 new file mode 100644
74856 index 0000000..cd9e124
74857 --- /dev/null
74858 +++ b/grsecurity/grsec_mount.c
74859 @@ -0,0 +1,65 @@
74860 +#include <linux/kernel.h>
74861 +#include <linux/sched.h>
74862 +#include <linux/mount.h>
74863 +#include <linux/major.h>
74864 +#include <linux/grsecurity.h>
74865 +#include <linux/grinternal.h>
74866 +
74867 +void
74868 +gr_log_remount(const char *devname, const int retval)
74869 +{
74870 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74871 + if (grsec_enable_mount && (retval >= 0))
74872 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74873 +#endif
74874 + return;
74875 +}
74876 +
74877 +void
74878 +gr_log_unmount(const char *devname, const int retval)
74879 +{
74880 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74881 + if (grsec_enable_mount && (retval >= 0))
74882 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74883 +#endif
74884 + return;
74885 +}
74886 +
74887 +void
74888 +gr_log_mount(const char *from, const char *to, const int retval)
74889 +{
74890 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74891 + if (grsec_enable_mount && (retval >= 0))
74892 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74893 +#endif
74894 + return;
74895 +}
74896 +
74897 +int
74898 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74899 +{
74900 +#ifdef CONFIG_GRKERNSEC_ROFS
74901 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74902 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
74903 + return -EPERM;
74904 + } else
74905 + return 0;
74906 +#endif
74907 + return 0;
74908 +}
74909 +
74910 +int
74911 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
74912 +{
74913 +#ifdef CONFIG_GRKERNSEC_ROFS
74914 + struct inode *inode = dentry->d_inode;
74915 +
74916 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
74917 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
74918 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
74919 + return -EPERM;
74920 + } else
74921 + return 0;
74922 +#endif
74923 + return 0;
74924 +}
74925 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
74926 new file mode 100644
74927 index 0000000..6ee9d50
74928 --- /dev/null
74929 +++ b/grsecurity/grsec_pax.c
74930 @@ -0,0 +1,45 @@
74931 +#include <linux/kernel.h>
74932 +#include <linux/sched.h>
74933 +#include <linux/mm.h>
74934 +#include <linux/file.h>
74935 +#include <linux/grinternal.h>
74936 +#include <linux/grsecurity.h>
74937 +
74938 +void
74939 +gr_log_textrel(struct vm_area_struct * vma)
74940 +{
74941 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74942 + if (grsec_enable_log_rwxmaps)
74943 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
74944 +#endif
74945 + return;
74946 +}
74947 +
74948 +void gr_log_ptgnustack(struct file *file)
74949 +{
74950 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74951 + if (grsec_enable_log_rwxmaps)
74952 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
74953 +#endif
74954 + return;
74955 +}
74956 +
74957 +void
74958 +gr_log_rwxmmap(struct file *file)
74959 +{
74960 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74961 + if (grsec_enable_log_rwxmaps)
74962 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
74963 +#endif
74964 + return;
74965 +}
74966 +
74967 +void
74968 +gr_log_rwxmprotect(struct vm_area_struct *vma)
74969 +{
74970 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74971 + if (grsec_enable_log_rwxmaps)
74972 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
74973 +#endif
74974 + return;
74975 +}
74976 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
74977 new file mode 100644
74978 index 0000000..f7f29aa
74979 --- /dev/null
74980 +++ b/grsecurity/grsec_ptrace.c
74981 @@ -0,0 +1,30 @@
74982 +#include <linux/kernel.h>
74983 +#include <linux/sched.h>
74984 +#include <linux/grinternal.h>
74985 +#include <linux/security.h>
74986 +
74987 +void
74988 +gr_audit_ptrace(struct task_struct *task)
74989 +{
74990 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74991 + if (grsec_enable_audit_ptrace)
74992 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
74993 +#endif
74994 + return;
74995 +}
74996 +
74997 +int
74998 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
74999 +{
75000 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75001 + const struct dentry *dentry = file->f_path.dentry;
75002 + const struct vfsmount *mnt = file->f_path.mnt;
75003 +
75004 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75005 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75006 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75007 + return -EACCES;
75008 + }
75009 +#endif
75010 + return 0;
75011 +}
75012 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75013 new file mode 100644
75014 index 0000000..3860c7e
75015 --- /dev/null
75016 +++ b/grsecurity/grsec_sig.c
75017 @@ -0,0 +1,236 @@
75018 +#include <linux/kernel.h>
75019 +#include <linux/sched.h>
75020 +#include <linux/fs.h>
75021 +#include <linux/delay.h>
75022 +#include <linux/grsecurity.h>
75023 +#include <linux/grinternal.h>
75024 +#include <linux/hardirq.h>
75025 +
75026 +char *signames[] = {
75027 + [SIGSEGV] = "Segmentation fault",
75028 + [SIGILL] = "Illegal instruction",
75029 + [SIGABRT] = "Abort",
75030 + [SIGBUS] = "Invalid alignment/Bus error"
75031 +};
75032 +
75033 +void
75034 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75035 +{
75036 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75037 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75038 + (sig == SIGABRT) || (sig == SIGBUS))) {
75039 + if (task_pid_nr(t) == task_pid_nr(current)) {
75040 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75041 + } else {
75042 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75043 + }
75044 + }
75045 +#endif
75046 + return;
75047 +}
75048 +
75049 +int
75050 +gr_handle_signal(const struct task_struct *p, const int sig)
75051 +{
75052 +#ifdef CONFIG_GRKERNSEC
75053 + /* ignore the 0 signal for protected task checks */
75054 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75055 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75056 + return -EPERM;
75057 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75058 + return -EPERM;
75059 + }
75060 +#endif
75061 + return 0;
75062 +}
75063 +
75064 +#ifdef CONFIG_GRKERNSEC
75065 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75066 +
75067 +int gr_fake_force_sig(int sig, struct task_struct *t)
75068 +{
75069 + unsigned long int flags;
75070 + int ret, blocked, ignored;
75071 + struct k_sigaction *action;
75072 +
75073 + spin_lock_irqsave(&t->sighand->siglock, flags);
75074 + action = &t->sighand->action[sig-1];
75075 + ignored = action->sa.sa_handler == SIG_IGN;
75076 + blocked = sigismember(&t->blocked, sig);
75077 + if (blocked || ignored) {
75078 + action->sa.sa_handler = SIG_DFL;
75079 + if (blocked) {
75080 + sigdelset(&t->blocked, sig);
75081 + recalc_sigpending_and_wake(t);
75082 + }
75083 + }
75084 + if (action->sa.sa_handler == SIG_DFL)
75085 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
75086 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75087 +
75088 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
75089 +
75090 + return ret;
75091 +}
75092 +#endif
75093 +
75094 +#define GR_USER_BAN_TIME (15 * 60)
75095 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
75096 +
75097 +void gr_handle_brute_attach(int dumpable)
75098 +{
75099 +#ifdef CONFIG_GRKERNSEC_BRUTE
75100 + struct task_struct *p = current;
75101 + kuid_t uid = GLOBAL_ROOT_UID;
75102 + int daemon = 0;
75103 +
75104 + if (!grsec_enable_brute)
75105 + return;
75106 +
75107 + rcu_read_lock();
75108 + read_lock(&tasklist_lock);
75109 + read_lock(&grsec_exec_file_lock);
75110 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75111 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75112 + p->real_parent->brute = 1;
75113 + daemon = 1;
75114 + } else {
75115 + const struct cred *cred = __task_cred(p), *cred2;
75116 + struct task_struct *tsk, *tsk2;
75117 +
75118 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75119 + struct user_struct *user;
75120 +
75121 + uid = cred->uid;
75122 +
75123 + /* this is put upon execution past expiration */
75124 + user = find_user(uid);
75125 + if (user == NULL)
75126 + goto unlock;
75127 + user->suid_banned = 1;
75128 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75129 + if (user->suid_ban_expires == ~0UL)
75130 + user->suid_ban_expires--;
75131 +
75132 + /* only kill other threads of the same binary, from the same user */
75133 + do_each_thread(tsk2, tsk) {
75134 + cred2 = __task_cred(tsk);
75135 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75136 + gr_fake_force_sig(SIGKILL, tsk);
75137 + } while_each_thread(tsk2, tsk);
75138 + }
75139 + }
75140 +unlock:
75141 + read_unlock(&grsec_exec_file_lock);
75142 + read_unlock(&tasklist_lock);
75143 + rcu_read_unlock();
75144 +
75145 + if (gr_is_global_nonroot(uid))
75146 + 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);
75147 + else if (daemon)
75148 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75149 +
75150 +#endif
75151 + return;
75152 +}
75153 +
75154 +void gr_handle_brute_check(void)
75155 +{
75156 +#ifdef CONFIG_GRKERNSEC_BRUTE
75157 + struct task_struct *p = current;
75158 +
75159 + if (unlikely(p->brute)) {
75160 + if (!grsec_enable_brute)
75161 + p->brute = 0;
75162 + else if (time_before(get_seconds(), p->brute_expires))
75163 + msleep(30 * 1000);
75164 + }
75165 +#endif
75166 + return;
75167 +}
75168 +
75169 +void gr_handle_kernel_exploit(void)
75170 +{
75171 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75172 + const struct cred *cred;
75173 + struct task_struct *tsk, *tsk2;
75174 + struct user_struct *user;
75175 + kuid_t uid;
75176 +
75177 + if (in_irq() || in_serving_softirq() || in_nmi())
75178 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75179 +
75180 + uid = current_uid();
75181 +
75182 + if (gr_is_global_root(uid))
75183 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
75184 + else {
75185 + /* kill all the processes of this user, hold a reference
75186 + to their creds struct, and prevent them from creating
75187 + another process until system reset
75188 + */
75189 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75190 + GR_GLOBAL_UID(uid));
75191 + /* we intentionally leak this ref */
75192 + user = get_uid(current->cred->user);
75193 + if (user)
75194 + user->kernel_banned = 1;
75195 +
75196 + /* kill all processes of this user */
75197 + read_lock(&tasklist_lock);
75198 + do_each_thread(tsk2, tsk) {
75199 + cred = __task_cred(tsk);
75200 + if (uid_eq(cred->uid, uid))
75201 + gr_fake_force_sig(SIGKILL, tsk);
75202 + } while_each_thread(tsk2, tsk);
75203 + read_unlock(&tasklist_lock);
75204 + }
75205 +#endif
75206 +}
75207 +
75208 +#ifdef CONFIG_GRKERNSEC_BRUTE
75209 +static bool suid_ban_expired(struct user_struct *user)
75210 +{
75211 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75212 + user->suid_banned = 0;
75213 + user->suid_ban_expires = 0;
75214 + free_uid(user);
75215 + return true;
75216 + }
75217 +
75218 + return false;
75219 +}
75220 +#endif
75221 +
75222 +int gr_process_kernel_exec_ban(void)
75223 +{
75224 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75225 + if (unlikely(current->cred->user->kernel_banned))
75226 + return -EPERM;
75227 +#endif
75228 + return 0;
75229 +}
75230 +
75231 +int gr_process_kernel_setuid_ban(struct user_struct *user)
75232 +{
75233 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75234 + if (unlikely(user->kernel_banned))
75235 + gr_fake_force_sig(SIGKILL, current);
75236 +#endif
75237 + return 0;
75238 +}
75239 +
75240 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75241 +{
75242 +#ifdef CONFIG_GRKERNSEC_BRUTE
75243 + struct user_struct *user = current->cred->user;
75244 + if (unlikely(user->suid_banned)) {
75245 + if (suid_ban_expired(user))
75246 + return 0;
75247 + /* disallow execution of suid binaries only */
75248 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75249 + return -EPERM;
75250 + }
75251 +#endif
75252 + return 0;
75253 +}
75254 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75255 new file mode 100644
75256 index 0000000..c0aef3a
75257 --- /dev/null
75258 +++ b/grsecurity/grsec_sock.c
75259 @@ -0,0 +1,244 @@
75260 +#include <linux/kernel.h>
75261 +#include <linux/module.h>
75262 +#include <linux/sched.h>
75263 +#include <linux/file.h>
75264 +#include <linux/net.h>
75265 +#include <linux/in.h>
75266 +#include <linux/ip.h>
75267 +#include <net/sock.h>
75268 +#include <net/inet_sock.h>
75269 +#include <linux/grsecurity.h>
75270 +#include <linux/grinternal.h>
75271 +#include <linux/gracl.h>
75272 +
75273 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75274 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75275 +
75276 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75277 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75278 +
75279 +#ifdef CONFIG_UNIX_MODULE
75280 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75281 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75282 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75283 +EXPORT_SYMBOL_GPL(gr_handle_create);
75284 +#endif
75285 +
75286 +#ifdef CONFIG_GRKERNSEC
75287 +#define gr_conn_table_size 32749
75288 +struct conn_table_entry {
75289 + struct conn_table_entry *next;
75290 + struct signal_struct *sig;
75291 +};
75292 +
75293 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75294 +DEFINE_SPINLOCK(gr_conn_table_lock);
75295 +
75296 +extern const char * gr_socktype_to_name(unsigned char type);
75297 +extern const char * gr_proto_to_name(unsigned char proto);
75298 +extern const char * gr_sockfamily_to_name(unsigned char family);
75299 +
75300 +static __inline__ int
75301 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75302 +{
75303 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75304 +}
75305 +
75306 +static __inline__ int
75307 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75308 + __u16 sport, __u16 dport)
75309 +{
75310 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75311 + sig->gr_sport == sport && sig->gr_dport == dport))
75312 + return 1;
75313 + else
75314 + return 0;
75315 +}
75316 +
75317 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75318 +{
75319 + struct conn_table_entry **match;
75320 + unsigned int index;
75321 +
75322 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75323 + sig->gr_sport, sig->gr_dport,
75324 + gr_conn_table_size);
75325 +
75326 + newent->sig = sig;
75327 +
75328 + match = &gr_conn_table[index];
75329 + newent->next = *match;
75330 + *match = newent;
75331 +
75332 + return;
75333 +}
75334 +
75335 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75336 +{
75337 + struct conn_table_entry *match, *last = NULL;
75338 + unsigned int index;
75339 +
75340 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75341 + sig->gr_sport, sig->gr_dport,
75342 + gr_conn_table_size);
75343 +
75344 + match = gr_conn_table[index];
75345 + while (match && !conn_match(match->sig,
75346 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75347 + sig->gr_dport)) {
75348 + last = match;
75349 + match = match->next;
75350 + }
75351 +
75352 + if (match) {
75353 + if (last)
75354 + last->next = match->next;
75355 + else
75356 + gr_conn_table[index] = NULL;
75357 + kfree(match);
75358 + }
75359 +
75360 + return;
75361 +}
75362 +
75363 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75364 + __u16 sport, __u16 dport)
75365 +{
75366 + struct conn_table_entry *match;
75367 + unsigned int index;
75368 +
75369 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75370 +
75371 + match = gr_conn_table[index];
75372 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75373 + match = match->next;
75374 +
75375 + if (match)
75376 + return match->sig;
75377 + else
75378 + return NULL;
75379 +}
75380 +
75381 +#endif
75382 +
75383 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75384 +{
75385 +#ifdef CONFIG_GRKERNSEC
75386 + struct signal_struct *sig = task->signal;
75387 + struct conn_table_entry *newent;
75388 +
75389 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75390 + if (newent == NULL)
75391 + return;
75392 + /* no bh lock needed since we are called with bh disabled */
75393 + spin_lock(&gr_conn_table_lock);
75394 + gr_del_task_from_ip_table_nolock(sig);
75395 + sig->gr_saddr = inet->inet_rcv_saddr;
75396 + sig->gr_daddr = inet->inet_daddr;
75397 + sig->gr_sport = inet->inet_sport;
75398 + sig->gr_dport = inet->inet_dport;
75399 + gr_add_to_task_ip_table_nolock(sig, newent);
75400 + spin_unlock(&gr_conn_table_lock);
75401 +#endif
75402 + return;
75403 +}
75404 +
75405 +void gr_del_task_from_ip_table(struct task_struct *task)
75406 +{
75407 +#ifdef CONFIG_GRKERNSEC
75408 + spin_lock_bh(&gr_conn_table_lock);
75409 + gr_del_task_from_ip_table_nolock(task->signal);
75410 + spin_unlock_bh(&gr_conn_table_lock);
75411 +#endif
75412 + return;
75413 +}
75414 +
75415 +void
75416 +gr_attach_curr_ip(const struct sock *sk)
75417 +{
75418 +#ifdef CONFIG_GRKERNSEC
75419 + struct signal_struct *p, *set;
75420 + const struct inet_sock *inet = inet_sk(sk);
75421 +
75422 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75423 + return;
75424 +
75425 + set = current->signal;
75426 +
75427 + spin_lock_bh(&gr_conn_table_lock);
75428 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75429 + inet->inet_dport, inet->inet_sport);
75430 + if (unlikely(p != NULL)) {
75431 + set->curr_ip = p->curr_ip;
75432 + set->used_accept = 1;
75433 + gr_del_task_from_ip_table_nolock(p);
75434 + spin_unlock_bh(&gr_conn_table_lock);
75435 + return;
75436 + }
75437 + spin_unlock_bh(&gr_conn_table_lock);
75438 +
75439 + set->curr_ip = inet->inet_daddr;
75440 + set->used_accept = 1;
75441 +#endif
75442 + return;
75443 +}
75444 +
75445 +int
75446 +gr_handle_sock_all(const int family, const int type, const int protocol)
75447 +{
75448 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75449 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75450 + (family != AF_UNIX)) {
75451 + if (family == AF_INET)
75452 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75453 + else
75454 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75455 + return -EACCES;
75456 + }
75457 +#endif
75458 + return 0;
75459 +}
75460 +
75461 +int
75462 +gr_handle_sock_server(const struct sockaddr *sck)
75463 +{
75464 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75465 + if (grsec_enable_socket_server &&
75466 + in_group_p(grsec_socket_server_gid) &&
75467 + sck && (sck->sa_family != AF_UNIX) &&
75468 + (sck->sa_family != AF_LOCAL)) {
75469 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75470 + return -EACCES;
75471 + }
75472 +#endif
75473 + return 0;
75474 +}
75475 +
75476 +int
75477 +gr_handle_sock_server_other(const struct sock *sck)
75478 +{
75479 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75480 + if (grsec_enable_socket_server &&
75481 + in_group_p(grsec_socket_server_gid) &&
75482 + sck && (sck->sk_family != AF_UNIX) &&
75483 + (sck->sk_family != AF_LOCAL)) {
75484 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75485 + return -EACCES;
75486 + }
75487 +#endif
75488 + return 0;
75489 +}
75490 +
75491 +int
75492 +gr_handle_sock_client(const struct sockaddr *sck)
75493 +{
75494 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75495 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75496 + sck && (sck->sa_family != AF_UNIX) &&
75497 + (sck->sa_family != AF_LOCAL)) {
75498 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75499 + return -EACCES;
75500 + }
75501 +#endif
75502 + return 0;
75503 +}
75504 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75505 new file mode 100644
75506 index 0000000..8159888
75507 --- /dev/null
75508 +++ b/grsecurity/grsec_sysctl.c
75509 @@ -0,0 +1,479 @@
75510 +#include <linux/kernel.h>
75511 +#include <linux/sched.h>
75512 +#include <linux/sysctl.h>
75513 +#include <linux/grsecurity.h>
75514 +#include <linux/grinternal.h>
75515 +
75516 +int
75517 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75518 +{
75519 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75520 + if (dirname == NULL || name == NULL)
75521 + return 0;
75522 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75523 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75524 + return -EACCES;
75525 + }
75526 +#endif
75527 + return 0;
75528 +}
75529 +
75530 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75531 +static int __maybe_unused __read_only one = 1;
75532 +#endif
75533 +
75534 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75535 + defined(CONFIG_GRKERNSEC_DENYUSB)
75536 +struct ctl_table grsecurity_table[] = {
75537 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75538 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75539 +#ifdef CONFIG_GRKERNSEC_IO
75540 + {
75541 + .procname = "disable_priv_io",
75542 + .data = &grsec_disable_privio,
75543 + .maxlen = sizeof(int),
75544 + .mode = 0600,
75545 + .proc_handler = &proc_dointvec,
75546 + },
75547 +#endif
75548 +#endif
75549 +#ifdef CONFIG_GRKERNSEC_LINK
75550 + {
75551 + .procname = "linking_restrictions",
75552 + .data = &grsec_enable_link,
75553 + .maxlen = sizeof(int),
75554 + .mode = 0600,
75555 + .proc_handler = &proc_dointvec,
75556 + },
75557 +#endif
75558 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75559 + {
75560 + .procname = "enforce_symlinksifowner",
75561 + .data = &grsec_enable_symlinkown,
75562 + .maxlen = sizeof(int),
75563 + .mode = 0600,
75564 + .proc_handler = &proc_dointvec,
75565 + },
75566 + {
75567 + .procname = "symlinkown_gid",
75568 + .data = &grsec_symlinkown_gid,
75569 + .maxlen = sizeof(int),
75570 + .mode = 0600,
75571 + .proc_handler = &proc_dointvec,
75572 + },
75573 +#endif
75574 +#ifdef CONFIG_GRKERNSEC_BRUTE
75575 + {
75576 + .procname = "deter_bruteforce",
75577 + .data = &grsec_enable_brute,
75578 + .maxlen = sizeof(int),
75579 + .mode = 0600,
75580 + .proc_handler = &proc_dointvec,
75581 + },
75582 +#endif
75583 +#ifdef CONFIG_GRKERNSEC_FIFO
75584 + {
75585 + .procname = "fifo_restrictions",
75586 + .data = &grsec_enable_fifo,
75587 + .maxlen = sizeof(int),
75588 + .mode = 0600,
75589 + .proc_handler = &proc_dointvec,
75590 + },
75591 +#endif
75592 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75593 + {
75594 + .procname = "ptrace_readexec",
75595 + .data = &grsec_enable_ptrace_readexec,
75596 + .maxlen = sizeof(int),
75597 + .mode = 0600,
75598 + .proc_handler = &proc_dointvec,
75599 + },
75600 +#endif
75601 +#ifdef CONFIG_GRKERNSEC_SETXID
75602 + {
75603 + .procname = "consistent_setxid",
75604 + .data = &grsec_enable_setxid,
75605 + .maxlen = sizeof(int),
75606 + .mode = 0600,
75607 + .proc_handler = &proc_dointvec,
75608 + },
75609 +#endif
75610 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75611 + {
75612 + .procname = "ip_blackhole",
75613 + .data = &grsec_enable_blackhole,
75614 + .maxlen = sizeof(int),
75615 + .mode = 0600,
75616 + .proc_handler = &proc_dointvec,
75617 + },
75618 + {
75619 + .procname = "lastack_retries",
75620 + .data = &grsec_lastack_retries,
75621 + .maxlen = sizeof(int),
75622 + .mode = 0600,
75623 + .proc_handler = &proc_dointvec,
75624 + },
75625 +#endif
75626 +#ifdef CONFIG_GRKERNSEC_EXECLOG
75627 + {
75628 + .procname = "exec_logging",
75629 + .data = &grsec_enable_execlog,
75630 + .maxlen = sizeof(int),
75631 + .mode = 0600,
75632 + .proc_handler = &proc_dointvec,
75633 + },
75634 +#endif
75635 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75636 + {
75637 + .procname = "rwxmap_logging",
75638 + .data = &grsec_enable_log_rwxmaps,
75639 + .maxlen = sizeof(int),
75640 + .mode = 0600,
75641 + .proc_handler = &proc_dointvec,
75642 + },
75643 +#endif
75644 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75645 + {
75646 + .procname = "signal_logging",
75647 + .data = &grsec_enable_signal,
75648 + .maxlen = sizeof(int),
75649 + .mode = 0600,
75650 + .proc_handler = &proc_dointvec,
75651 + },
75652 +#endif
75653 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
75654 + {
75655 + .procname = "forkfail_logging",
75656 + .data = &grsec_enable_forkfail,
75657 + .maxlen = sizeof(int),
75658 + .mode = 0600,
75659 + .proc_handler = &proc_dointvec,
75660 + },
75661 +#endif
75662 +#ifdef CONFIG_GRKERNSEC_TIME
75663 + {
75664 + .procname = "timechange_logging",
75665 + .data = &grsec_enable_time,
75666 + .maxlen = sizeof(int),
75667 + .mode = 0600,
75668 + .proc_handler = &proc_dointvec,
75669 + },
75670 +#endif
75671 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75672 + {
75673 + .procname = "chroot_deny_shmat",
75674 + .data = &grsec_enable_chroot_shmat,
75675 + .maxlen = sizeof(int),
75676 + .mode = 0600,
75677 + .proc_handler = &proc_dointvec,
75678 + },
75679 +#endif
75680 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75681 + {
75682 + .procname = "chroot_deny_unix",
75683 + .data = &grsec_enable_chroot_unix,
75684 + .maxlen = sizeof(int),
75685 + .mode = 0600,
75686 + .proc_handler = &proc_dointvec,
75687 + },
75688 +#endif
75689 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75690 + {
75691 + .procname = "chroot_deny_mount",
75692 + .data = &grsec_enable_chroot_mount,
75693 + .maxlen = sizeof(int),
75694 + .mode = 0600,
75695 + .proc_handler = &proc_dointvec,
75696 + },
75697 +#endif
75698 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75699 + {
75700 + .procname = "chroot_deny_fchdir",
75701 + .data = &grsec_enable_chroot_fchdir,
75702 + .maxlen = sizeof(int),
75703 + .mode = 0600,
75704 + .proc_handler = &proc_dointvec,
75705 + },
75706 +#endif
75707 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75708 + {
75709 + .procname = "chroot_deny_chroot",
75710 + .data = &grsec_enable_chroot_double,
75711 + .maxlen = sizeof(int),
75712 + .mode = 0600,
75713 + .proc_handler = &proc_dointvec,
75714 + },
75715 +#endif
75716 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75717 + {
75718 + .procname = "chroot_deny_pivot",
75719 + .data = &grsec_enable_chroot_pivot,
75720 + .maxlen = sizeof(int),
75721 + .mode = 0600,
75722 + .proc_handler = &proc_dointvec,
75723 + },
75724 +#endif
75725 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75726 + {
75727 + .procname = "chroot_enforce_chdir",
75728 + .data = &grsec_enable_chroot_chdir,
75729 + .maxlen = sizeof(int),
75730 + .mode = 0600,
75731 + .proc_handler = &proc_dointvec,
75732 + },
75733 +#endif
75734 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75735 + {
75736 + .procname = "chroot_deny_chmod",
75737 + .data = &grsec_enable_chroot_chmod,
75738 + .maxlen = sizeof(int),
75739 + .mode = 0600,
75740 + .proc_handler = &proc_dointvec,
75741 + },
75742 +#endif
75743 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75744 + {
75745 + .procname = "chroot_deny_mknod",
75746 + .data = &grsec_enable_chroot_mknod,
75747 + .maxlen = sizeof(int),
75748 + .mode = 0600,
75749 + .proc_handler = &proc_dointvec,
75750 + },
75751 +#endif
75752 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75753 + {
75754 + .procname = "chroot_restrict_nice",
75755 + .data = &grsec_enable_chroot_nice,
75756 + .maxlen = sizeof(int),
75757 + .mode = 0600,
75758 + .proc_handler = &proc_dointvec,
75759 + },
75760 +#endif
75761 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75762 + {
75763 + .procname = "chroot_execlog",
75764 + .data = &grsec_enable_chroot_execlog,
75765 + .maxlen = sizeof(int),
75766 + .mode = 0600,
75767 + .proc_handler = &proc_dointvec,
75768 + },
75769 +#endif
75770 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75771 + {
75772 + .procname = "chroot_caps",
75773 + .data = &grsec_enable_chroot_caps,
75774 + .maxlen = sizeof(int),
75775 + .mode = 0600,
75776 + .proc_handler = &proc_dointvec,
75777 + },
75778 +#endif
75779 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75780 + {
75781 + .procname = "chroot_deny_sysctl",
75782 + .data = &grsec_enable_chroot_sysctl,
75783 + .maxlen = sizeof(int),
75784 + .mode = 0600,
75785 + .proc_handler = &proc_dointvec,
75786 + },
75787 +#endif
75788 +#ifdef CONFIG_GRKERNSEC_TPE
75789 + {
75790 + .procname = "tpe",
75791 + .data = &grsec_enable_tpe,
75792 + .maxlen = sizeof(int),
75793 + .mode = 0600,
75794 + .proc_handler = &proc_dointvec,
75795 + },
75796 + {
75797 + .procname = "tpe_gid",
75798 + .data = &grsec_tpe_gid,
75799 + .maxlen = sizeof(int),
75800 + .mode = 0600,
75801 + .proc_handler = &proc_dointvec,
75802 + },
75803 +#endif
75804 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75805 + {
75806 + .procname = "tpe_invert",
75807 + .data = &grsec_enable_tpe_invert,
75808 + .maxlen = sizeof(int),
75809 + .mode = 0600,
75810 + .proc_handler = &proc_dointvec,
75811 + },
75812 +#endif
75813 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75814 + {
75815 + .procname = "tpe_restrict_all",
75816 + .data = &grsec_enable_tpe_all,
75817 + .maxlen = sizeof(int),
75818 + .mode = 0600,
75819 + .proc_handler = &proc_dointvec,
75820 + },
75821 +#endif
75822 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75823 + {
75824 + .procname = "socket_all",
75825 + .data = &grsec_enable_socket_all,
75826 + .maxlen = sizeof(int),
75827 + .mode = 0600,
75828 + .proc_handler = &proc_dointvec,
75829 + },
75830 + {
75831 + .procname = "socket_all_gid",
75832 + .data = &grsec_socket_all_gid,
75833 + .maxlen = sizeof(int),
75834 + .mode = 0600,
75835 + .proc_handler = &proc_dointvec,
75836 + },
75837 +#endif
75838 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75839 + {
75840 + .procname = "socket_client",
75841 + .data = &grsec_enable_socket_client,
75842 + .maxlen = sizeof(int),
75843 + .mode = 0600,
75844 + .proc_handler = &proc_dointvec,
75845 + },
75846 + {
75847 + .procname = "socket_client_gid",
75848 + .data = &grsec_socket_client_gid,
75849 + .maxlen = sizeof(int),
75850 + .mode = 0600,
75851 + .proc_handler = &proc_dointvec,
75852 + },
75853 +#endif
75854 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75855 + {
75856 + .procname = "socket_server",
75857 + .data = &grsec_enable_socket_server,
75858 + .maxlen = sizeof(int),
75859 + .mode = 0600,
75860 + .proc_handler = &proc_dointvec,
75861 + },
75862 + {
75863 + .procname = "socket_server_gid",
75864 + .data = &grsec_socket_server_gid,
75865 + .maxlen = sizeof(int),
75866 + .mode = 0600,
75867 + .proc_handler = &proc_dointvec,
75868 + },
75869 +#endif
75870 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75871 + {
75872 + .procname = "audit_group",
75873 + .data = &grsec_enable_group,
75874 + .maxlen = sizeof(int),
75875 + .mode = 0600,
75876 + .proc_handler = &proc_dointvec,
75877 + },
75878 + {
75879 + .procname = "audit_gid",
75880 + .data = &grsec_audit_gid,
75881 + .maxlen = sizeof(int),
75882 + .mode = 0600,
75883 + .proc_handler = &proc_dointvec,
75884 + },
75885 +#endif
75886 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75887 + {
75888 + .procname = "audit_chdir",
75889 + .data = &grsec_enable_chdir,
75890 + .maxlen = sizeof(int),
75891 + .mode = 0600,
75892 + .proc_handler = &proc_dointvec,
75893 + },
75894 +#endif
75895 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75896 + {
75897 + .procname = "audit_mount",
75898 + .data = &grsec_enable_mount,
75899 + .maxlen = sizeof(int),
75900 + .mode = 0600,
75901 + .proc_handler = &proc_dointvec,
75902 + },
75903 +#endif
75904 +#ifdef CONFIG_GRKERNSEC_DMESG
75905 + {
75906 + .procname = "dmesg",
75907 + .data = &grsec_enable_dmesg,
75908 + .maxlen = sizeof(int),
75909 + .mode = 0600,
75910 + .proc_handler = &proc_dointvec,
75911 + },
75912 +#endif
75913 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75914 + {
75915 + .procname = "chroot_findtask",
75916 + .data = &grsec_enable_chroot_findtask,
75917 + .maxlen = sizeof(int),
75918 + .mode = 0600,
75919 + .proc_handler = &proc_dointvec,
75920 + },
75921 +#endif
75922 +#ifdef CONFIG_GRKERNSEC_RESLOG
75923 + {
75924 + .procname = "resource_logging",
75925 + .data = &grsec_resource_logging,
75926 + .maxlen = sizeof(int),
75927 + .mode = 0600,
75928 + .proc_handler = &proc_dointvec,
75929 + },
75930 +#endif
75931 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75932 + {
75933 + .procname = "audit_ptrace",
75934 + .data = &grsec_enable_audit_ptrace,
75935 + .maxlen = sizeof(int),
75936 + .mode = 0600,
75937 + .proc_handler = &proc_dointvec,
75938 + },
75939 +#endif
75940 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75941 + {
75942 + .procname = "harden_ptrace",
75943 + .data = &grsec_enable_harden_ptrace,
75944 + .maxlen = sizeof(int),
75945 + .mode = 0600,
75946 + .proc_handler = &proc_dointvec,
75947 + },
75948 +#endif
75949 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75950 + {
75951 + .procname = "harden_ipc",
75952 + .data = &grsec_enable_harden_ipc,
75953 + .maxlen = sizeof(int),
75954 + .mode = 0600,
75955 + .proc_handler = &proc_dointvec,
75956 + },
75957 +#endif
75958 + {
75959 + .procname = "grsec_lock",
75960 + .data = &grsec_lock,
75961 + .maxlen = sizeof(int),
75962 + .mode = 0600,
75963 + .proc_handler = &proc_dointvec,
75964 + },
75965 +#endif
75966 +#ifdef CONFIG_GRKERNSEC_ROFS
75967 + {
75968 + .procname = "romount_protect",
75969 + .data = &grsec_enable_rofs,
75970 + .maxlen = sizeof(int),
75971 + .mode = 0600,
75972 + .proc_handler = &proc_dointvec_minmax,
75973 + .extra1 = &one,
75974 + .extra2 = &one,
75975 + },
75976 +#endif
75977 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
75978 + {
75979 + .procname = "deny_new_usb",
75980 + .data = &grsec_deny_new_usb,
75981 + .maxlen = sizeof(int),
75982 + .mode = 0600,
75983 + .proc_handler = &proc_dointvec,
75984 + },
75985 +#endif
75986 + { }
75987 +};
75988 +#endif
75989 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
75990 new file mode 100644
75991 index 0000000..61b514e
75992 --- /dev/null
75993 +++ b/grsecurity/grsec_time.c
75994 @@ -0,0 +1,16 @@
75995 +#include <linux/kernel.h>
75996 +#include <linux/sched.h>
75997 +#include <linux/grinternal.h>
75998 +#include <linux/module.h>
75999 +
76000 +void
76001 +gr_log_timechange(void)
76002 +{
76003 +#ifdef CONFIG_GRKERNSEC_TIME
76004 + if (grsec_enable_time)
76005 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76006 +#endif
76007 + return;
76008 +}
76009 +
76010 +EXPORT_SYMBOL_GPL(gr_log_timechange);
76011 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76012 new file mode 100644
76013 index 0000000..ee57dcf
76014 --- /dev/null
76015 +++ b/grsecurity/grsec_tpe.c
76016 @@ -0,0 +1,73 @@
76017 +#include <linux/kernel.h>
76018 +#include <linux/sched.h>
76019 +#include <linux/file.h>
76020 +#include <linux/fs.h>
76021 +#include <linux/grinternal.h>
76022 +
76023 +extern int gr_acl_tpe_check(void);
76024 +
76025 +int
76026 +gr_tpe_allow(const struct file *file)
76027 +{
76028 +#ifdef CONFIG_GRKERNSEC
76029 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76030 + const struct cred *cred = current_cred();
76031 + char *msg = NULL;
76032 + char *msg2 = NULL;
76033 +
76034 + // never restrict root
76035 + if (gr_is_global_root(cred->uid))
76036 + return 1;
76037 +
76038 + if (grsec_enable_tpe) {
76039 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76040 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76041 + msg = "not being in trusted group";
76042 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76043 + msg = "being in untrusted group";
76044 +#else
76045 + if (in_group_p(grsec_tpe_gid))
76046 + msg = "being in untrusted group";
76047 +#endif
76048 + }
76049 + if (!msg && gr_acl_tpe_check())
76050 + msg = "being in untrusted role";
76051 +
76052 + // not in any affected group/role
76053 + if (!msg)
76054 + goto next_check;
76055 +
76056 + if (gr_is_global_nonroot(inode->i_uid))
76057 + msg2 = "file in non-root-owned directory";
76058 + else if (inode->i_mode & S_IWOTH)
76059 + msg2 = "file in world-writable directory";
76060 + else if (inode->i_mode & S_IWGRP)
76061 + msg2 = "file in group-writable directory";
76062 +
76063 + if (msg && msg2) {
76064 + char fullmsg[70] = {0};
76065 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76066 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76067 + return 0;
76068 + }
76069 + msg = NULL;
76070 +next_check:
76071 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76072 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76073 + return 1;
76074 +
76075 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76076 + msg = "directory not owned by user";
76077 + else if (inode->i_mode & S_IWOTH)
76078 + msg = "file in world-writable directory";
76079 + else if (inode->i_mode & S_IWGRP)
76080 + msg = "file in group-writable directory";
76081 +
76082 + if (msg) {
76083 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76084 + return 0;
76085 + }
76086 +#endif
76087 +#endif
76088 + return 1;
76089 +}
76090 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76091 new file mode 100644
76092 index 0000000..ae02d8e
76093 --- /dev/null
76094 +++ b/grsecurity/grsec_usb.c
76095 @@ -0,0 +1,15 @@
76096 +#include <linux/kernel.h>
76097 +#include <linux/grinternal.h>
76098 +#include <linux/module.h>
76099 +
76100 +int gr_handle_new_usb(void)
76101 +{
76102 +#ifdef CONFIG_GRKERNSEC_DENYUSB
76103 + if (grsec_deny_new_usb) {
76104 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76105 + return 1;
76106 + }
76107 +#endif
76108 + return 0;
76109 +}
76110 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76111 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76112 new file mode 100644
76113 index 0000000..9f7b1ac
76114 --- /dev/null
76115 +++ b/grsecurity/grsum.c
76116 @@ -0,0 +1,61 @@
76117 +#include <linux/err.h>
76118 +#include <linux/kernel.h>
76119 +#include <linux/sched.h>
76120 +#include <linux/mm.h>
76121 +#include <linux/scatterlist.h>
76122 +#include <linux/crypto.h>
76123 +#include <linux/gracl.h>
76124 +
76125 +
76126 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76127 +#error "crypto and sha256 must be built into the kernel"
76128 +#endif
76129 +
76130 +int
76131 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76132 +{
76133 + char *p;
76134 + struct crypto_hash *tfm;
76135 + struct hash_desc desc;
76136 + struct scatterlist sg;
76137 + unsigned char temp_sum[GR_SHA_LEN];
76138 + volatile int retval = 0;
76139 + volatile int dummy = 0;
76140 + unsigned int i;
76141 +
76142 + sg_init_table(&sg, 1);
76143 +
76144 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76145 + if (IS_ERR(tfm)) {
76146 + /* should never happen, since sha256 should be built in */
76147 + return 1;
76148 + }
76149 +
76150 + desc.tfm = tfm;
76151 + desc.flags = 0;
76152 +
76153 + crypto_hash_init(&desc);
76154 +
76155 + p = salt;
76156 + sg_set_buf(&sg, p, GR_SALT_LEN);
76157 + crypto_hash_update(&desc, &sg, sg.length);
76158 +
76159 + p = entry->pw;
76160 + sg_set_buf(&sg, p, strlen(p));
76161 +
76162 + crypto_hash_update(&desc, &sg, sg.length);
76163 +
76164 + crypto_hash_final(&desc, temp_sum);
76165 +
76166 + memset(entry->pw, 0, GR_PW_LEN);
76167 +
76168 + for (i = 0; i < GR_SHA_LEN; i++)
76169 + if (sum[i] != temp_sum[i])
76170 + retval = 1;
76171 + else
76172 + dummy = 1; // waste a cycle
76173 +
76174 + crypto_free_hash(tfm);
76175 +
76176 + return retval;
76177 +}
76178 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76179 index 77ff547..181834f 100644
76180 --- a/include/asm-generic/4level-fixup.h
76181 +++ b/include/asm-generic/4level-fixup.h
76182 @@ -13,8 +13,10 @@
76183 #define pmd_alloc(mm, pud, address) \
76184 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76185 NULL: pmd_offset(pud, address))
76186 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76187
76188 #define pud_alloc(mm, pgd, address) (pgd)
76189 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76190 #define pud_offset(pgd, start) (pgd)
76191 #define pud_none(pud) 0
76192 #define pud_bad(pud) 0
76193 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76194 index b7babf0..97f4c4f 100644
76195 --- a/include/asm-generic/atomic-long.h
76196 +++ b/include/asm-generic/atomic-long.h
76197 @@ -22,6 +22,12 @@
76198
76199 typedef atomic64_t atomic_long_t;
76200
76201 +#ifdef CONFIG_PAX_REFCOUNT
76202 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
76203 +#else
76204 +typedef atomic64_t atomic_long_unchecked_t;
76205 +#endif
76206 +
76207 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76208
76209 static inline long atomic_long_read(atomic_long_t *l)
76210 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76211 return (long)atomic64_read(v);
76212 }
76213
76214 +#ifdef CONFIG_PAX_REFCOUNT
76215 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76216 +{
76217 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76218 +
76219 + return (long)atomic64_read_unchecked(v);
76220 +}
76221 +#endif
76222 +
76223 static inline void atomic_long_set(atomic_long_t *l, long i)
76224 {
76225 atomic64_t *v = (atomic64_t *)l;
76226 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76227 atomic64_set(v, i);
76228 }
76229
76230 +#ifdef CONFIG_PAX_REFCOUNT
76231 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76232 +{
76233 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76234 +
76235 + atomic64_set_unchecked(v, i);
76236 +}
76237 +#endif
76238 +
76239 static inline void atomic_long_inc(atomic_long_t *l)
76240 {
76241 atomic64_t *v = (atomic64_t *)l;
76242 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76243 atomic64_inc(v);
76244 }
76245
76246 +#ifdef CONFIG_PAX_REFCOUNT
76247 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76248 +{
76249 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76250 +
76251 + atomic64_inc_unchecked(v);
76252 +}
76253 +#endif
76254 +
76255 static inline void atomic_long_dec(atomic_long_t *l)
76256 {
76257 atomic64_t *v = (atomic64_t *)l;
76258 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76259 atomic64_dec(v);
76260 }
76261
76262 +#ifdef CONFIG_PAX_REFCOUNT
76263 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76264 +{
76265 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76266 +
76267 + atomic64_dec_unchecked(v);
76268 +}
76269 +#endif
76270 +
76271 static inline void atomic_long_add(long i, atomic_long_t *l)
76272 {
76273 atomic64_t *v = (atomic64_t *)l;
76274 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76275 atomic64_add(i, v);
76276 }
76277
76278 +#ifdef CONFIG_PAX_REFCOUNT
76279 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76280 +{
76281 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76282 +
76283 + atomic64_add_unchecked(i, v);
76284 +}
76285 +#endif
76286 +
76287 static inline void atomic_long_sub(long i, atomic_long_t *l)
76288 {
76289 atomic64_t *v = (atomic64_t *)l;
76290 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76291 atomic64_sub(i, v);
76292 }
76293
76294 +#ifdef CONFIG_PAX_REFCOUNT
76295 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76296 +{
76297 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76298 +
76299 + atomic64_sub_unchecked(i, v);
76300 +}
76301 +#endif
76302 +
76303 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76304 {
76305 atomic64_t *v = (atomic64_t *)l;
76306 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76307 return atomic64_add_negative(i, v);
76308 }
76309
76310 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
76311 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76312 {
76313 atomic64_t *v = (atomic64_t *)l;
76314
76315 return (long)atomic64_add_return(i, v);
76316 }
76317
76318 +#ifdef CONFIG_PAX_REFCOUNT
76319 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76320 +{
76321 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76322 +
76323 + return (long)atomic64_add_return_unchecked(i, v);
76324 +}
76325 +#endif
76326 +
76327 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76328 {
76329 atomic64_t *v = (atomic64_t *)l;
76330 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76331 return (long)atomic64_inc_return(v);
76332 }
76333
76334 +#ifdef CONFIG_PAX_REFCOUNT
76335 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76336 +{
76337 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76338 +
76339 + return (long)atomic64_inc_return_unchecked(v);
76340 +}
76341 +#endif
76342 +
76343 static inline long atomic_long_dec_return(atomic_long_t *l)
76344 {
76345 atomic64_t *v = (atomic64_t *)l;
76346 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76347
76348 typedef atomic_t atomic_long_t;
76349
76350 +#ifdef CONFIG_PAX_REFCOUNT
76351 +typedef atomic_unchecked_t atomic_long_unchecked_t;
76352 +#else
76353 +typedef atomic_t atomic_long_unchecked_t;
76354 +#endif
76355 +
76356 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76357 static inline long atomic_long_read(atomic_long_t *l)
76358 {
76359 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76360 return (long)atomic_read(v);
76361 }
76362
76363 +#ifdef CONFIG_PAX_REFCOUNT
76364 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76365 +{
76366 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76367 +
76368 + return (long)atomic_read_unchecked(v);
76369 +}
76370 +#endif
76371 +
76372 static inline void atomic_long_set(atomic_long_t *l, long i)
76373 {
76374 atomic_t *v = (atomic_t *)l;
76375 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76376 atomic_set(v, i);
76377 }
76378
76379 +#ifdef CONFIG_PAX_REFCOUNT
76380 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76381 +{
76382 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76383 +
76384 + atomic_set_unchecked(v, i);
76385 +}
76386 +#endif
76387 +
76388 static inline void atomic_long_inc(atomic_long_t *l)
76389 {
76390 atomic_t *v = (atomic_t *)l;
76391 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76392 atomic_inc(v);
76393 }
76394
76395 +#ifdef CONFIG_PAX_REFCOUNT
76396 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76397 +{
76398 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76399 +
76400 + atomic_inc_unchecked(v);
76401 +}
76402 +#endif
76403 +
76404 static inline void atomic_long_dec(atomic_long_t *l)
76405 {
76406 atomic_t *v = (atomic_t *)l;
76407 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76408 atomic_dec(v);
76409 }
76410
76411 +#ifdef CONFIG_PAX_REFCOUNT
76412 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76413 +{
76414 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76415 +
76416 + atomic_dec_unchecked(v);
76417 +}
76418 +#endif
76419 +
76420 static inline void atomic_long_add(long i, atomic_long_t *l)
76421 {
76422 atomic_t *v = (atomic_t *)l;
76423 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76424 atomic_add(i, v);
76425 }
76426
76427 +#ifdef CONFIG_PAX_REFCOUNT
76428 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76429 +{
76430 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76431 +
76432 + atomic_add_unchecked(i, v);
76433 +}
76434 +#endif
76435 +
76436 static inline void atomic_long_sub(long i, atomic_long_t *l)
76437 {
76438 atomic_t *v = (atomic_t *)l;
76439 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76440 atomic_sub(i, v);
76441 }
76442
76443 +#ifdef CONFIG_PAX_REFCOUNT
76444 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76445 +{
76446 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76447 +
76448 + atomic_sub_unchecked(i, v);
76449 +}
76450 +#endif
76451 +
76452 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76453 {
76454 atomic_t *v = (atomic_t *)l;
76455 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76456 return (long)atomic_add_return(i, v);
76457 }
76458
76459 +#ifdef CONFIG_PAX_REFCOUNT
76460 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76461 +{
76462 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76463 +
76464 + return (long)atomic_add_return_unchecked(i, v);
76465 +}
76466 +
76467 +#endif
76468 +
76469 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76470 {
76471 atomic_t *v = (atomic_t *)l;
76472 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76473 return (long)atomic_inc_return(v);
76474 }
76475
76476 +#ifdef CONFIG_PAX_REFCOUNT
76477 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76478 +{
76479 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76480 +
76481 + return (long)atomic_inc_return_unchecked(v);
76482 +}
76483 +#endif
76484 +
76485 static inline long atomic_long_dec_return(atomic_long_t *l)
76486 {
76487 atomic_t *v = (atomic_t *)l;
76488 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76489
76490 #endif /* BITS_PER_LONG == 64 */
76491
76492 +#ifdef CONFIG_PAX_REFCOUNT
76493 +static inline void pax_refcount_needs_these_functions(void)
76494 +{
76495 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
76496 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76497 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76498 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76499 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76500 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76501 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76502 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76503 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76504 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76505 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76506 +#ifdef CONFIG_X86
76507 + atomic_clear_mask_unchecked(0, NULL);
76508 + atomic_set_mask_unchecked(0, NULL);
76509 +#endif
76510 +
76511 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76512 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76513 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76514 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76515 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76516 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76517 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76518 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76519 +}
76520 +#else
76521 +#define atomic_read_unchecked(v) atomic_read(v)
76522 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76523 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76524 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76525 +#define atomic_inc_unchecked(v) atomic_inc(v)
76526 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76527 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76528 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76529 +#define atomic_dec_unchecked(v) atomic_dec(v)
76530 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76531 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76532 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76533 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76534 +
76535 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
76536 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76537 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76538 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76539 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76540 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76541 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76542 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76543 +#endif
76544 +
76545 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76546 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76547 index 33bd2de..f31bff97 100644
76548 --- a/include/asm-generic/atomic.h
76549 +++ b/include/asm-generic/atomic.h
76550 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76551 * Atomically clears the bits set in @mask from @v
76552 */
76553 #ifndef atomic_clear_mask
76554 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76555 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76556 {
76557 unsigned long flags;
76558
76559 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76560 index b18ce4f..2ee2843 100644
76561 --- a/include/asm-generic/atomic64.h
76562 +++ b/include/asm-generic/atomic64.h
76563 @@ -16,6 +16,8 @@ typedef struct {
76564 long long counter;
76565 } atomic64_t;
76566
76567 +typedef atomic64_t atomic64_unchecked_t;
76568 +
76569 #define ATOMIC64_INIT(i) { (i) }
76570
76571 extern long long atomic64_read(const atomic64_t *v);
76572 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76573 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76574 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76575
76576 +#define atomic64_read_unchecked(v) atomic64_read(v)
76577 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76578 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76579 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76580 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76581 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
76582 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76583 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
76584 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76585 +
76586 #endif /* _ASM_GENERIC_ATOMIC64_H */
76587 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76588 index a60a7cc..0fe12f2 100644
76589 --- a/include/asm-generic/bitops/__fls.h
76590 +++ b/include/asm-generic/bitops/__fls.h
76591 @@ -9,7 +9,7 @@
76592 *
76593 * Undefined if no set bit exists, so code should check against 0 first.
76594 */
76595 -static __always_inline unsigned long __fls(unsigned long word)
76596 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76597 {
76598 int num = BITS_PER_LONG - 1;
76599
76600 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76601 index 0576d1f..dad6c71 100644
76602 --- a/include/asm-generic/bitops/fls.h
76603 +++ b/include/asm-generic/bitops/fls.h
76604 @@ -9,7 +9,7 @@
76605 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76606 */
76607
76608 -static __always_inline int fls(int x)
76609 +static __always_inline int __intentional_overflow(-1) fls(int x)
76610 {
76611 int r = 32;
76612
76613 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76614 index b097cf8..3d40e14 100644
76615 --- a/include/asm-generic/bitops/fls64.h
76616 +++ b/include/asm-generic/bitops/fls64.h
76617 @@ -15,7 +15,7 @@
76618 * at position 64.
76619 */
76620 #if BITS_PER_LONG == 32
76621 -static __always_inline int fls64(__u64 x)
76622 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76623 {
76624 __u32 h = x >> 32;
76625 if (h)
76626 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76627 return fls(x);
76628 }
76629 #elif BITS_PER_LONG == 64
76630 -static __always_inline int fls64(__u64 x)
76631 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76632 {
76633 if (x == 0)
76634 return 0;
76635 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76636 index 1bfcfe5..e04c5c9 100644
76637 --- a/include/asm-generic/cache.h
76638 +++ b/include/asm-generic/cache.h
76639 @@ -6,7 +6,7 @@
76640 * cache lines need to provide their own cache.h.
76641 */
76642
76643 -#define L1_CACHE_SHIFT 5
76644 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76645 +#define L1_CACHE_SHIFT 5UL
76646 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76647
76648 #endif /* __ASM_GENERIC_CACHE_H */
76649 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76650 index 0d68a1e..b74a761 100644
76651 --- a/include/asm-generic/emergency-restart.h
76652 +++ b/include/asm-generic/emergency-restart.h
76653 @@ -1,7 +1,7 @@
76654 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76655 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76656
76657 -static inline void machine_emergency_restart(void)
76658 +static inline __noreturn void machine_emergency_restart(void)
76659 {
76660 machine_restart(NULL);
76661 }
76662 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76663 index 90f99c7..00ce236 100644
76664 --- a/include/asm-generic/kmap_types.h
76665 +++ b/include/asm-generic/kmap_types.h
76666 @@ -2,9 +2,9 @@
76667 #define _ASM_GENERIC_KMAP_TYPES_H
76668
76669 #ifdef __WITH_KM_FENCE
76670 -# define KM_TYPE_NR 41
76671 +# define KM_TYPE_NR 42
76672 #else
76673 -# define KM_TYPE_NR 20
76674 +# define KM_TYPE_NR 21
76675 #endif
76676
76677 #endif
76678 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76679 index 9ceb03b..62b0b8f 100644
76680 --- a/include/asm-generic/local.h
76681 +++ b/include/asm-generic/local.h
76682 @@ -23,24 +23,37 @@ typedef struct
76683 atomic_long_t a;
76684 } local_t;
76685
76686 +typedef struct {
76687 + atomic_long_unchecked_t a;
76688 +} local_unchecked_t;
76689 +
76690 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76691
76692 #define local_read(l) atomic_long_read(&(l)->a)
76693 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76694 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76695 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76696 #define local_inc(l) atomic_long_inc(&(l)->a)
76697 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76698 #define local_dec(l) atomic_long_dec(&(l)->a)
76699 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76700 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76701 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76702 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76703 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76704
76705 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76706 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76707 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76708 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76709 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76710 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76711 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76712 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76713 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76714
76715 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76716 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76717 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76718 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76719 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76720 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76721 index 725612b..9cc513a 100644
76722 --- a/include/asm-generic/pgtable-nopmd.h
76723 +++ b/include/asm-generic/pgtable-nopmd.h
76724 @@ -1,14 +1,19 @@
76725 #ifndef _PGTABLE_NOPMD_H
76726 #define _PGTABLE_NOPMD_H
76727
76728 -#ifndef __ASSEMBLY__
76729 -
76730 #include <asm-generic/pgtable-nopud.h>
76731
76732 -struct mm_struct;
76733 -
76734 #define __PAGETABLE_PMD_FOLDED
76735
76736 +#define PMD_SHIFT PUD_SHIFT
76737 +#define PTRS_PER_PMD 1
76738 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76739 +#define PMD_MASK (~(PMD_SIZE-1))
76740 +
76741 +#ifndef __ASSEMBLY__
76742 +
76743 +struct mm_struct;
76744 +
76745 /*
76746 * Having the pmd type consist of a pud gets the size right, and allows
76747 * us to conceptually access the pud entry that this pmd is folded into
76748 @@ -16,11 +21,6 @@ struct mm_struct;
76749 */
76750 typedef struct { pud_t pud; } pmd_t;
76751
76752 -#define PMD_SHIFT PUD_SHIFT
76753 -#define PTRS_PER_PMD 1
76754 -#define PMD_SIZE (1UL << PMD_SHIFT)
76755 -#define PMD_MASK (~(PMD_SIZE-1))
76756 -
76757 /*
76758 * The "pud_xxx()" functions here are trivial for a folded two-level
76759 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76760 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76761 index 810431d..0ec4804f 100644
76762 --- a/include/asm-generic/pgtable-nopud.h
76763 +++ b/include/asm-generic/pgtable-nopud.h
76764 @@ -1,10 +1,15 @@
76765 #ifndef _PGTABLE_NOPUD_H
76766 #define _PGTABLE_NOPUD_H
76767
76768 -#ifndef __ASSEMBLY__
76769 -
76770 #define __PAGETABLE_PUD_FOLDED
76771
76772 +#define PUD_SHIFT PGDIR_SHIFT
76773 +#define PTRS_PER_PUD 1
76774 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76775 +#define PUD_MASK (~(PUD_SIZE-1))
76776 +
76777 +#ifndef __ASSEMBLY__
76778 +
76779 /*
76780 * Having the pud type consist of a pgd gets the size right, and allows
76781 * us to conceptually access the pgd entry that this pud is folded into
76782 @@ -12,11 +17,6 @@
76783 */
76784 typedef struct { pgd_t pgd; } pud_t;
76785
76786 -#define PUD_SHIFT PGDIR_SHIFT
76787 -#define PTRS_PER_PUD 1
76788 -#define PUD_SIZE (1UL << PUD_SHIFT)
76789 -#define PUD_MASK (~(PUD_SIZE-1))
76790 -
76791 /*
76792 * The "pgd_xxx()" functions here are trivial for a folded two-level
76793 * setup: the pud is never bad, and a pud always exists (as it's folded
76794 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76795 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76796
76797 #define pgd_populate(mm, pgd, pud) do { } while (0)
76798 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76799 /*
76800 * (puds are folded into pgds so this doesn't get actually called,
76801 * but the define is needed for a generic inline function.)
76802 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76803 index 8e4f41d..c5e9afd 100644
76804 --- a/include/asm-generic/pgtable.h
76805 +++ b/include/asm-generic/pgtable.h
76806 @@ -748,6 +748,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
76807 }
76808 #endif /* CONFIG_NUMA_BALANCING */
76809
76810 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76811 +#ifdef CONFIG_PAX_KERNEXEC
76812 +#error KERNEXEC requires pax_open_kernel
76813 +#else
76814 +static inline unsigned long pax_open_kernel(void) { return 0; }
76815 +#endif
76816 +#endif
76817 +
76818 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76819 +#ifdef CONFIG_PAX_KERNEXEC
76820 +#error KERNEXEC requires pax_close_kernel
76821 +#else
76822 +static inline unsigned long pax_close_kernel(void) { return 0; }
76823 +#endif
76824 +#endif
76825 +
76826 #endif /* CONFIG_MMU */
76827
76828 #endif /* !__ASSEMBLY__ */
76829 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76830 index dc1269c..48a4f51 100644
76831 --- a/include/asm-generic/uaccess.h
76832 +++ b/include/asm-generic/uaccess.h
76833 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76834 return __clear_user(to, n);
76835 }
76836
76837 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76838 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76839 +#error UDEREF requires pax_open_userland
76840 +#else
76841 +static inline unsigned long pax_open_userland(void) { return 0; }
76842 +#endif
76843 +#endif
76844 +
76845 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76846 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76847 +#error UDEREF requires pax_close_userland
76848 +#else
76849 +static inline unsigned long pax_close_userland(void) { return 0; }
76850 +#endif
76851 +#endif
76852 +
76853 #endif /* __ASM_GENERIC_UACCESS_H */
76854 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76855 index bc2121f..2f41f9a 100644
76856 --- a/include/asm-generic/vmlinux.lds.h
76857 +++ b/include/asm-generic/vmlinux.lds.h
76858 @@ -232,6 +232,7 @@
76859 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76860 VMLINUX_SYMBOL(__start_rodata) = .; \
76861 *(.rodata) *(.rodata.*) \
76862 + *(.data..read_only) \
76863 *(__vermagic) /* Kernel version magic */ \
76864 . = ALIGN(8); \
76865 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76866 @@ -716,17 +717,18 @@
76867 * section in the linker script will go there too. @phdr should have
76868 * a leading colon.
76869 *
76870 - * Note that this macros defines __per_cpu_load as an absolute symbol.
76871 + * Note that this macros defines per_cpu_load as an absolute symbol.
76872 * If there is no need to put the percpu section at a predetermined
76873 * address, use PERCPU_SECTION.
76874 */
76875 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76876 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
76877 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
76878 + per_cpu_load = .; \
76879 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
76880 - LOAD_OFFSET) { \
76881 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
76882 PERCPU_INPUT(cacheline) \
76883 } phdr \
76884 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
76885 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
76886
76887 /**
76888 * PERCPU_SECTION - define output section for percpu area, simple version
76889 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
76890 index e73c19e..5b89e00 100644
76891 --- a/include/crypto/algapi.h
76892 +++ b/include/crypto/algapi.h
76893 @@ -34,7 +34,7 @@ struct crypto_type {
76894 unsigned int maskclear;
76895 unsigned int maskset;
76896 unsigned int tfmsize;
76897 -};
76898 +} __do_const;
76899
76900 struct crypto_instance {
76901 struct crypto_alg alg;
76902 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
76903 index 1d4a920..da65658 100644
76904 --- a/include/drm/drmP.h
76905 +++ b/include/drm/drmP.h
76906 @@ -66,6 +66,7 @@
76907 #include <linux/workqueue.h>
76908 #include <linux/poll.h>
76909 #include <asm/pgalloc.h>
76910 +#include <asm/local.h>
76911 #include <drm/drm.h>
76912 #include <drm/drm_sarea.h>
76913 #include <drm/drm_vma_manager.h>
76914 @@ -278,10 +279,12 @@ do { \
76915 * \param cmd command.
76916 * \param arg argument.
76917 */
76918 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
76919 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
76920 + struct drm_file *file_priv);
76921 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
76922 struct drm_file *file_priv);
76923
76924 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76925 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
76926 unsigned long arg);
76927
76928 #define DRM_IOCTL_NR(n) _IOC_NR(n)
76929 @@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76930 struct drm_ioctl_desc {
76931 unsigned int cmd;
76932 int flags;
76933 - drm_ioctl_t *func;
76934 + drm_ioctl_t func;
76935 unsigned int cmd_drv;
76936 const char *name;
76937 -};
76938 +} __do_const;
76939
76940 /**
76941 * Creates a driver or general drm_ioctl_desc array entry for the given
76942 @@ -1013,7 +1016,8 @@ struct drm_info_list {
76943 int (*show)(struct seq_file*, void*); /** show callback */
76944 u32 driver_features; /**< Required driver features for this entry */
76945 void *data;
76946 -};
76947 +} __do_const;
76948 +typedef struct drm_info_list __no_const drm_info_list_no_const;
76949
76950 /**
76951 * debugfs node structure. This structure represents a debugfs file.
76952 @@ -1097,7 +1101,7 @@ struct drm_device {
76953
76954 /** \name Usage Counters */
76955 /*@{ */
76956 - int open_count; /**< Outstanding files open */
76957 + local_t open_count; /**< Outstanding files open */
76958 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
76959 atomic_t vma_count; /**< Outstanding vma areas open */
76960 int buf_use; /**< Buffers in use -- cannot alloc */
76961 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
76962 index ef6ad3a..be34b16 100644
76963 --- a/include/drm/drm_crtc_helper.h
76964 +++ b/include/drm/drm_crtc_helper.h
76965 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
76966 struct drm_connector *connector);
76967 /* disable encoder when not in use - more explicit than dpms off */
76968 void (*disable)(struct drm_encoder *encoder);
76969 -};
76970 +} __no_const;
76971
76972 /**
76973 * drm_connector_helper_funcs - helper operations for connectors
76974 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
76975 index 940ece4..8cb727f 100644
76976 --- a/include/drm/i915_pciids.h
76977 +++ b/include/drm/i915_pciids.h
76978 @@ -37,7 +37,7 @@
76979 */
76980 #define INTEL_VGA_DEVICE(id, info) { \
76981 0x8086, id, \
76982 - ~0, ~0, \
76983 + PCI_ANY_ID, PCI_ANY_ID, \
76984 0x030000, 0xff0000, \
76985 (unsigned long) info }
76986
76987 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
76988 index 72dcbe8..8db58d7 100644
76989 --- a/include/drm/ttm/ttm_memory.h
76990 +++ b/include/drm/ttm/ttm_memory.h
76991 @@ -48,7 +48,7 @@
76992
76993 struct ttm_mem_shrink {
76994 int (*do_shrink) (struct ttm_mem_shrink *);
76995 -};
76996 +} __no_const;
76997
76998 /**
76999 * struct ttm_mem_global - Global memory accounting structure.
77000 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77001 index d1f61bf..2239439 100644
77002 --- a/include/drm/ttm/ttm_page_alloc.h
77003 +++ b/include/drm/ttm/ttm_page_alloc.h
77004 @@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
77005 */
77006 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77007
77008 +struct device;
77009 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77010 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77011
77012 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77013 index 4b840e8..155d235 100644
77014 --- a/include/keys/asymmetric-subtype.h
77015 +++ b/include/keys/asymmetric-subtype.h
77016 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77017 /* Verify the signature on a key of this subtype (optional) */
77018 int (*verify_signature)(const struct key *key,
77019 const struct public_key_signature *sig);
77020 -};
77021 +} __do_const;
77022
77023 /**
77024 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77025 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77026 index c1da539..1dcec55 100644
77027 --- a/include/linux/atmdev.h
77028 +++ b/include/linux/atmdev.h
77029 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77030 #endif
77031
77032 struct k_atm_aal_stats {
77033 -#define __HANDLE_ITEM(i) atomic_t i
77034 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
77035 __AAL_STAT_ITEMS
77036 #undef __HANDLE_ITEM
77037 };
77038 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77039 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77040 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77041 struct module *owner;
77042 -};
77043 +} __do_const ;
77044
77045 struct atmphy_ops {
77046 int (*start)(struct atm_dev *dev);
77047 diff --git a/include/linux/audit.h b/include/linux/audit.h
77048 index bf1ef22..2a55e1b 100644
77049 --- a/include/linux/audit.h
77050 +++ b/include/linux/audit.h
77051 @@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
77052 extern unsigned int audit_serial(void);
77053 extern int auditsc_get_stamp(struct audit_context *ctx,
77054 struct timespec *t, unsigned int *serial);
77055 -extern int audit_set_loginuid(kuid_t loginuid);
77056 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77057
77058 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77059 {
77060 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77061 index fd8bf32..49a5f5c 100644
77062 --- a/include/linux/binfmts.h
77063 +++ b/include/linux/binfmts.h
77064 @@ -45,7 +45,7 @@ struct linux_binprm {
77065 unsigned interp_data;
77066 unsigned long loader, exec;
77067 char tcomm[TASK_COMM_LEN];
77068 -};
77069 +} __randomize_layout;
77070
77071 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77072 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77073 @@ -74,8 +74,10 @@ struct linux_binfmt {
77074 int (*load_binary)(struct linux_binprm *);
77075 int (*load_shlib)(struct file *);
77076 int (*core_dump)(struct coredump_params *cprm);
77077 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77078 + void (*handle_mmap)(struct file *);
77079 unsigned long min_coredump; /* minimal dump size */
77080 -};
77081 +} __do_const __randomize_layout;
77082
77083 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77084
77085 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77086 index be5fd38..d71192a 100644
77087 --- a/include/linux/bitops.h
77088 +++ b/include/linux/bitops.h
77089 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77090 * @word: value to rotate
77091 * @shift: bits to roll
77092 */
77093 -static inline __u32 rol32(__u32 word, unsigned int shift)
77094 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77095 {
77096 return (word << shift) | (word >> (32 - shift));
77097 }
77098 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77099 * @word: value to rotate
77100 * @shift: bits to roll
77101 */
77102 -static inline __u32 ror32(__u32 word, unsigned int shift)
77103 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77104 {
77105 return (word >> shift) | (word << (32 - shift));
77106 }
77107 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77108 return (__s32)(value << shift) >> shift;
77109 }
77110
77111 -static inline unsigned fls_long(unsigned long l)
77112 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77113 {
77114 if (sizeof(l) == 4)
77115 return fls(l);
77116 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77117 index 1b135d4..59fc876 100644
77118 --- a/include/linux/blkdev.h
77119 +++ b/include/linux/blkdev.h
77120 @@ -1578,7 +1578,7 @@ struct block_device_operations {
77121 /* this callback is with swap_lock and sometimes page table lock held */
77122 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77123 struct module *owner;
77124 -};
77125 +} __do_const;
77126
77127 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77128 unsigned long);
77129 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77130 index afc1343..9735539 100644
77131 --- a/include/linux/blktrace_api.h
77132 +++ b/include/linux/blktrace_api.h
77133 @@ -25,7 +25,7 @@ struct blk_trace {
77134 struct dentry *dropped_file;
77135 struct dentry *msg_file;
77136 struct list_head running_list;
77137 - atomic_t dropped;
77138 + atomic_unchecked_t dropped;
77139 };
77140
77141 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77142 diff --git a/include/linux/cache.h b/include/linux/cache.h
77143 index 4c57065..40346da 100644
77144 --- a/include/linux/cache.h
77145 +++ b/include/linux/cache.h
77146 @@ -16,6 +16,14 @@
77147 #define __read_mostly
77148 #endif
77149
77150 +#ifndef __read_only
77151 +#ifdef CONFIG_PAX_KERNEXEC
77152 +#error KERNEXEC requires __read_only
77153 +#else
77154 +#define __read_only __read_mostly
77155 +#endif
77156 +#endif
77157 +
77158 #ifndef ____cacheline_aligned
77159 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77160 #endif
77161 diff --git a/include/linux/capability.h b/include/linux/capability.h
77162 index a6ee1f9..e1ca49d 100644
77163 --- a/include/linux/capability.h
77164 +++ b/include/linux/capability.h
77165 @@ -212,8 +212,13 @@ extern bool capable(int cap);
77166 extern bool ns_capable(struct user_namespace *ns, int cap);
77167 extern bool inode_capable(const struct inode *inode, int cap);
77168 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77169 +extern bool capable_nolog(int cap);
77170 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77171 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
77172
77173 /* audit system wants to get cap info from files as well */
77174 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77175
77176 +extern int is_privileged_binary(const struct dentry *dentry);
77177 +
77178 #endif /* !_LINUX_CAPABILITY_H */
77179 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77180 index 8609d57..86e4d79 100644
77181 --- a/include/linux/cdrom.h
77182 +++ b/include/linux/cdrom.h
77183 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
77184
77185 /* driver specifications */
77186 const int capability; /* capability flags */
77187 - int n_minors; /* number of active minor devices */
77188 /* handle uniform packets for scsi type devices (scsi,atapi) */
77189 int (*generic_packet) (struct cdrom_device_info *,
77190 struct packet_command *);
77191 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77192 index 4ce9056..86caac6 100644
77193 --- a/include/linux/cleancache.h
77194 +++ b/include/linux/cleancache.h
77195 @@ -31,7 +31,7 @@ struct cleancache_ops {
77196 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77197 void (*invalidate_inode)(int, struct cleancache_filekey);
77198 void (*invalidate_fs)(int);
77199 -};
77200 +} __no_const;
77201
77202 extern struct cleancache_ops *
77203 cleancache_register_ops(struct cleancache_ops *ops);
77204 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77205 index 7e59253..d6e4cae 100644
77206 --- a/include/linux/clk-provider.h
77207 +++ b/include/linux/clk-provider.h
77208 @@ -141,6 +141,7 @@ struct clk_ops {
77209 unsigned long);
77210 void (*init)(struct clk_hw *hw);
77211 };
77212 +typedef struct clk_ops __no_const clk_ops_no_const;
77213
77214 /**
77215 * struct clk_init_data - holds init data that's common to all clocks and is
77216 diff --git a/include/linux/compat.h b/include/linux/compat.h
77217 index 19f6003..90b64f4 100644
77218 --- a/include/linux/compat.h
77219 +++ b/include/linux/compat.h
77220 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77221 compat_size_t __user *len_ptr);
77222
77223 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77224 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77225 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77226 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77227 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77228 compat_ssize_t msgsz, int msgflg);
77229 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77230 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77231 compat_ulong_t addr, compat_ulong_t data);
77232 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77233 - compat_long_t addr, compat_long_t data);
77234 + compat_ulong_t addr, compat_ulong_t data);
77235
77236 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77237 /*
77238 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77239 index 2507fd2..55203f8 100644
77240 --- a/include/linux/compiler-gcc4.h
77241 +++ b/include/linux/compiler-gcc4.h
77242 @@ -39,9 +39,34 @@
77243 # define __compiletime_warning(message) __attribute__((warning(message)))
77244 # define __compiletime_error(message) __attribute__((error(message)))
77245 #endif /* __CHECKER__ */
77246 +
77247 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77248 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77249 +#define __bos0(ptr) __bos((ptr), 0)
77250 +#define __bos1(ptr) __bos((ptr), 1)
77251 #endif /* GCC_VERSION >= 40300 */
77252
77253 #if GCC_VERSION >= 40500
77254 +
77255 +#ifdef RANDSTRUCT_PLUGIN
77256 +#define __randomize_layout __attribute__((randomize_layout))
77257 +#define __no_randomize_layout __attribute__((no_randomize_layout))
77258 +#endif
77259 +
77260 +#ifdef CONSTIFY_PLUGIN
77261 +#define __no_const __attribute__((no_const))
77262 +#define __do_const __attribute__((do_const))
77263 +#endif
77264 +
77265 +#ifdef SIZE_OVERFLOW_PLUGIN
77266 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77267 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77268 +#endif
77269 +
77270 +#ifdef LATENT_ENTROPY_PLUGIN
77271 +#define __latent_entropy __attribute__((latent_entropy))
77272 +#endif
77273 +
77274 /*
77275 * Mark a position in code as unreachable. This can be used to
77276 * suppress control flow warnings after asm blocks that transfer
77277 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77278 index 92669cd..cc564c0 100644
77279 --- a/include/linux/compiler.h
77280 +++ b/include/linux/compiler.h
77281 @@ -5,11 +5,14 @@
77282
77283 #ifdef __CHECKER__
77284 # define __user __attribute__((noderef, address_space(1)))
77285 +# define __force_user __force __user
77286 # define __kernel __attribute__((address_space(0)))
77287 +# define __force_kernel __force __kernel
77288 # define __safe __attribute__((safe))
77289 # define __force __attribute__((force))
77290 # define __nocast __attribute__((nocast))
77291 # define __iomem __attribute__((noderef, address_space(2)))
77292 +# define __force_iomem __force __iomem
77293 # define __must_hold(x) __attribute__((context(x,1,1)))
77294 # define __acquires(x) __attribute__((context(x,0,1)))
77295 # define __releases(x) __attribute__((context(x,1,0)))
77296 @@ -17,20 +20,37 @@
77297 # define __release(x) __context__(x,-1)
77298 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77299 # define __percpu __attribute__((noderef, address_space(3)))
77300 +# define __force_percpu __force __percpu
77301 #ifdef CONFIG_SPARSE_RCU_POINTER
77302 # define __rcu __attribute__((noderef, address_space(4)))
77303 +# define __force_rcu __force __rcu
77304 #else
77305 # define __rcu
77306 +# define __force_rcu
77307 #endif
77308 extern void __chk_user_ptr(const volatile void __user *);
77309 extern void __chk_io_ptr(const volatile void __iomem *);
77310 #else
77311 -# define __user
77312 -# define __kernel
77313 +# ifdef CHECKER_PLUGIN
77314 +//# define __user
77315 +//# define __force_user
77316 +//# define __kernel
77317 +//# define __force_kernel
77318 +# else
77319 +# ifdef STRUCTLEAK_PLUGIN
77320 +# define __user __attribute__((user))
77321 +# else
77322 +# define __user
77323 +# endif
77324 +# define __force_user
77325 +# define __kernel
77326 +# define __force_kernel
77327 +# endif
77328 # define __safe
77329 # define __force
77330 # define __nocast
77331 # define __iomem
77332 +# define __force_iomem
77333 # define __chk_user_ptr(x) (void)0
77334 # define __chk_io_ptr(x) (void)0
77335 # define __builtin_warning(x, y...) (1)
77336 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77337 # define __release(x) (void)0
77338 # define __cond_lock(x,c) (c)
77339 # define __percpu
77340 +# define __force_percpu
77341 # define __rcu
77342 +# define __force_rcu
77343 #endif
77344
77345 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77346 @@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77347 # define __attribute_const__ /* unimplemented */
77348 #endif
77349
77350 +#ifndef __randomize_layout
77351 +# define __randomize_layout
77352 +#endif
77353 +
77354 +#ifndef __no_randomize_layout
77355 +# define __no_randomize_layout
77356 +#endif
77357 +
77358 +#ifndef __no_const
77359 +# define __no_const
77360 +#endif
77361 +
77362 +#ifndef __do_const
77363 +# define __do_const
77364 +#endif
77365 +
77366 +#ifndef __size_overflow
77367 +# define __size_overflow(...)
77368 +#endif
77369 +
77370 +#ifndef __intentional_overflow
77371 +# define __intentional_overflow(...)
77372 +#endif
77373 +
77374 +#ifndef __latent_entropy
77375 +# define __latent_entropy
77376 +#endif
77377 +
77378 /*
77379 * Tell gcc if a function is cold. The compiler will assume any path
77380 * directly leading to the call is unlikely.
77381 @@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77382 #define __cold
77383 #endif
77384
77385 +#ifndef __alloc_size
77386 +#define __alloc_size(...)
77387 +#endif
77388 +
77389 +#ifndef __bos
77390 +#define __bos(ptr, arg)
77391 +#endif
77392 +
77393 +#ifndef __bos0
77394 +#define __bos0(ptr)
77395 +#endif
77396 +
77397 +#ifndef __bos1
77398 +#define __bos1(ptr)
77399 +#endif
77400 +
77401 /* Simple shorthand for a section definition */
77402 #ifndef __section
77403 # define __section(S) __attribute__ ((__section__(#S)))
77404 @@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77405 * use is to mediate communication between process-level code and irq/NMI
77406 * handlers, all running on the same CPU.
77407 */
77408 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77409 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77410 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77411
77412 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77413 #ifdef CONFIG_KPROBES
77414 diff --git a/include/linux/completion.h b/include/linux/completion.h
77415 index 5d5aaae..0ea9b84 100644
77416 --- a/include/linux/completion.h
77417 +++ b/include/linux/completion.h
77418 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77419
77420 extern void wait_for_completion(struct completion *);
77421 extern void wait_for_completion_io(struct completion *);
77422 -extern int wait_for_completion_interruptible(struct completion *x);
77423 -extern int wait_for_completion_killable(struct completion *x);
77424 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77425 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77426 extern unsigned long wait_for_completion_timeout(struct completion *x,
77427 - unsigned long timeout);
77428 + unsigned long timeout) __intentional_overflow(-1);
77429 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77430 - unsigned long timeout);
77431 + unsigned long timeout) __intentional_overflow(-1);
77432 extern long wait_for_completion_interruptible_timeout(
77433 - struct completion *x, unsigned long timeout);
77434 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77435 extern long wait_for_completion_killable_timeout(
77436 - struct completion *x, unsigned long timeout);
77437 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77438 extern bool try_wait_for_completion(struct completion *x);
77439 extern bool completion_done(struct completion *x);
77440
77441 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77442 index 34025df..d94bbbc 100644
77443 --- a/include/linux/configfs.h
77444 +++ b/include/linux/configfs.h
77445 @@ -125,7 +125,7 @@ struct configfs_attribute {
77446 const char *ca_name;
77447 struct module *ca_owner;
77448 umode_t ca_mode;
77449 -};
77450 +} __do_const;
77451
77452 /*
77453 * Users often need to create attribute structures for their configurable
77454 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77455 index dc196bb..c55a50f 100644
77456 --- a/include/linux/cpufreq.h
77457 +++ b/include/linux/cpufreq.h
77458 @@ -189,6 +189,7 @@ struct global_attr {
77459 ssize_t (*store)(struct kobject *a, struct attribute *b,
77460 const char *c, size_t count);
77461 };
77462 +typedef struct global_attr __no_const global_attr_no_const;
77463
77464 #define define_one_global_ro(_name) \
77465 static struct global_attr _name = \
77466 @@ -225,7 +226,7 @@ struct cpufreq_driver {
77467 int (*suspend) (struct cpufreq_policy *policy);
77468 int (*resume) (struct cpufreq_policy *policy);
77469 struct freq_attr **attr;
77470 -};
77471 +} __do_const;
77472
77473 /* flags */
77474 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77475 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77476 index 50fcbb0..9d2dbd9 100644
77477 --- a/include/linux/cpuidle.h
77478 +++ b/include/linux/cpuidle.h
77479 @@ -50,7 +50,8 @@ struct cpuidle_state {
77480 int index);
77481
77482 int (*enter_dead) (struct cpuidle_device *dev, int index);
77483 -};
77484 +} __do_const;
77485 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77486
77487 /* Idle State Flags */
77488 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77489 @@ -192,7 +193,7 @@ struct cpuidle_governor {
77490 void (*reflect) (struct cpuidle_device *dev, int index);
77491
77492 struct module *owner;
77493 -};
77494 +} __do_const;
77495
77496 #ifdef CONFIG_CPU_IDLE
77497 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77498 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77499 index d08e4d2..95fad61 100644
77500 --- a/include/linux/cpumask.h
77501 +++ b/include/linux/cpumask.h
77502 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77503 }
77504
77505 /* Valid inputs for n are -1 and 0. */
77506 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77507 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77508 {
77509 return n+1;
77510 }
77511
77512 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77513 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77514 {
77515 return n+1;
77516 }
77517
77518 -static inline unsigned int cpumask_next_and(int n,
77519 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77520 const struct cpumask *srcp,
77521 const struct cpumask *andp)
77522 {
77523 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77524 *
77525 * Returns >= nr_cpu_ids if no further cpus set.
77526 */
77527 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77528 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77529 {
77530 /* -1 is a legal arg here. */
77531 if (n != -1)
77532 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77533 *
77534 * Returns >= nr_cpu_ids if no further cpus unset.
77535 */
77536 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77537 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77538 {
77539 /* -1 is a legal arg here. */
77540 if (n != -1)
77541 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77542 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77543 }
77544
77545 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77546 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77547 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77548
77549 /**
77550 diff --git a/include/linux/cred.h b/include/linux/cred.h
77551 index 04421e8..117e17a 100644
77552 --- a/include/linux/cred.h
77553 +++ b/include/linux/cred.h
77554 @@ -35,7 +35,7 @@ struct group_info {
77555 int nblocks;
77556 kgid_t small_block[NGROUPS_SMALL];
77557 kgid_t *blocks[0];
77558 -};
77559 +} __randomize_layout;
77560
77561 /**
77562 * get_group_info - Get a reference to a group info structure
77563 @@ -136,7 +136,7 @@ struct cred {
77564 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77565 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77566 struct rcu_head rcu; /* RCU deletion hook */
77567 -};
77568 +} __randomize_layout;
77569
77570 extern void __put_cred(struct cred *);
77571 extern void exit_creds(struct task_struct *);
77572 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77573 static inline void validate_process_creds(void)
77574 {
77575 }
77576 +static inline void validate_task_creds(struct task_struct *task)
77577 +{
77578 +}
77579 #endif
77580
77581 /**
77582 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77583 index b92eadf..b4ecdc1 100644
77584 --- a/include/linux/crypto.h
77585 +++ b/include/linux/crypto.h
77586 @@ -373,7 +373,7 @@ struct cipher_tfm {
77587 const u8 *key, unsigned int keylen);
77588 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77589 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77590 -};
77591 +} __no_const;
77592
77593 struct hash_tfm {
77594 int (*init)(struct hash_desc *desc);
77595 @@ -394,13 +394,13 @@ struct compress_tfm {
77596 int (*cot_decompress)(struct crypto_tfm *tfm,
77597 const u8 *src, unsigned int slen,
77598 u8 *dst, unsigned int *dlen);
77599 -};
77600 +} __no_const;
77601
77602 struct rng_tfm {
77603 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77604 unsigned int dlen);
77605 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77606 -};
77607 +} __no_const;
77608
77609 #define crt_ablkcipher crt_u.ablkcipher
77610 #define crt_aead crt_u.aead
77611 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77612 index 653589e..4ef254a 100644
77613 --- a/include/linux/ctype.h
77614 +++ b/include/linux/ctype.h
77615 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77616 * Fast implementation of tolower() for internal usage. Do not use in your
77617 * code.
77618 */
77619 -static inline char _tolower(const char c)
77620 +static inline unsigned char _tolower(const unsigned char c)
77621 {
77622 return c | 0x20;
77623 }
77624 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77625 index bf72e9a..4ca7927 100644
77626 --- a/include/linux/dcache.h
77627 +++ b/include/linux/dcache.h
77628 @@ -133,7 +133,7 @@ struct dentry {
77629 } d_u;
77630 struct list_head d_subdirs; /* our children */
77631 struct hlist_node d_alias; /* inode alias list */
77632 -};
77633 +} __randomize_layout;
77634
77635 /*
77636 * dentry->d_lock spinlock nesting subclasses:
77637 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77638 index 7925bf0..d5143d2 100644
77639 --- a/include/linux/decompress/mm.h
77640 +++ b/include/linux/decompress/mm.h
77641 @@ -77,7 +77,7 @@ static void free(void *where)
77642 * warnings when not needed (indeed large_malloc / large_free are not
77643 * needed by inflate */
77644
77645 -#define malloc(a) kmalloc(a, GFP_KERNEL)
77646 +#define malloc(a) kmalloc((a), GFP_KERNEL)
77647 #define free(a) kfree(a)
77648
77649 #define large_malloc(a) vmalloc(a)
77650 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77651 index d48dc00..211ee54 100644
77652 --- a/include/linux/devfreq.h
77653 +++ b/include/linux/devfreq.h
77654 @@ -114,7 +114,7 @@ struct devfreq_governor {
77655 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77656 int (*event_handler)(struct devfreq *devfreq,
77657 unsigned int event, void *data);
77658 -};
77659 +} __do_const;
77660
77661 /**
77662 * struct devfreq - Device devfreq structure
77663 diff --git a/include/linux/device.h b/include/linux/device.h
77664 index 952b010..d5b7691 100644
77665 --- a/include/linux/device.h
77666 +++ b/include/linux/device.h
77667 @@ -310,7 +310,7 @@ struct subsys_interface {
77668 struct list_head node;
77669 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77670 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77671 -};
77672 +} __do_const;
77673
77674 int subsys_interface_register(struct subsys_interface *sif);
77675 void subsys_interface_unregister(struct subsys_interface *sif);
77676 @@ -506,7 +506,7 @@ struct device_type {
77677 void (*release)(struct device *dev);
77678
77679 const struct dev_pm_ops *pm;
77680 -};
77681 +} __do_const;
77682
77683 /* interface for exporting device attributes */
77684 struct device_attribute {
77685 @@ -516,11 +516,12 @@ struct device_attribute {
77686 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77687 const char *buf, size_t count);
77688 };
77689 +typedef struct device_attribute __no_const device_attribute_no_const;
77690
77691 struct dev_ext_attribute {
77692 struct device_attribute attr;
77693 void *var;
77694 -};
77695 +} __do_const;
77696
77697 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77698 char *buf);
77699 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77700 index fd4aee2..1f28db9 100644
77701 --- a/include/linux/dma-mapping.h
77702 +++ b/include/linux/dma-mapping.h
77703 @@ -54,7 +54,7 @@ struct dma_map_ops {
77704 u64 (*get_required_mask)(struct device *dev);
77705 #endif
77706 int is_phys;
77707 -};
77708 +} __do_const;
77709
77710 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77711
77712 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77713 index 41cf0c3..f3b771c 100644
77714 --- a/include/linux/dmaengine.h
77715 +++ b/include/linux/dmaengine.h
77716 @@ -1114,9 +1114,9 @@ struct dma_pinned_list {
77717 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77718 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77719
77720 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77721 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77722 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77723 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77724 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77725 struct dma_pinned_list *pinned_list, struct page *page,
77726 unsigned int offset, size_t len);
77727
77728 diff --git a/include/linux/efi.h b/include/linux/efi.h
77729 index 11ce678..7b8c69c 100644
77730 --- a/include/linux/efi.h
77731 +++ b/include/linux/efi.h
77732 @@ -764,6 +764,7 @@ struct efivar_operations {
77733 efi_set_variable_t *set_variable;
77734 efi_query_variable_store_t *query_variable_store;
77735 };
77736 +typedef struct efivar_operations __no_const efivar_operations_no_const;
77737
77738 struct efivars {
77739 /*
77740 diff --git a/include/linux/elf.h b/include/linux/elf.h
77741 index 67a5fa7..b817372 100644
77742 --- a/include/linux/elf.h
77743 +++ b/include/linux/elf.h
77744 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77745 #define elf_note elf32_note
77746 #define elf_addr_t Elf32_Off
77747 #define Elf_Half Elf32_Half
77748 +#define elf_dyn Elf32_Dyn
77749
77750 #else
77751
77752 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77753 #define elf_note elf64_note
77754 #define elf_addr_t Elf64_Off
77755 #define Elf_Half Elf64_Half
77756 +#define elf_dyn Elf64_Dyn
77757
77758 #endif
77759
77760 diff --git a/include/linux/err.h b/include/linux/err.h
77761 index 15f92e0..e825a8e 100644
77762 --- a/include/linux/err.h
77763 +++ b/include/linux/err.h
77764 @@ -19,12 +19,12 @@
77765
77766 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77767
77768 -static inline void * __must_check ERR_PTR(long error)
77769 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77770 {
77771 return (void *) error;
77772 }
77773
77774 -static inline long __must_check PTR_ERR(__force const void *ptr)
77775 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77776 {
77777 return (long) ptr;
77778 }
77779 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77780 index 21c59af..6057a03 100644
77781 --- a/include/linux/extcon.h
77782 +++ b/include/linux/extcon.h
77783 @@ -135,7 +135,7 @@ struct extcon_dev {
77784 /* /sys/class/extcon/.../mutually_exclusive/... */
77785 struct attribute_group attr_g_muex;
77786 struct attribute **attrs_muex;
77787 - struct device_attribute *d_attrs_muex;
77788 + device_attribute_no_const *d_attrs_muex;
77789 };
77790
77791 /**
77792 diff --git a/include/linux/fb.h b/include/linux/fb.h
77793 index 70c4836..ff3daec 100644
77794 --- a/include/linux/fb.h
77795 +++ b/include/linux/fb.h
77796 @@ -304,7 +304,7 @@ struct fb_ops {
77797 /* called at KDB enter and leave time to prepare the console */
77798 int (*fb_debug_enter)(struct fb_info *info);
77799 int (*fb_debug_leave)(struct fb_info *info);
77800 -};
77801 +} __do_const;
77802
77803 #ifdef CONFIG_FB_TILEBLITTING
77804 #define FB_TILE_CURSOR_NONE 0
77805 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77806 index 085197b..0fa6f0b 100644
77807 --- a/include/linux/fdtable.h
77808 +++ b/include/linux/fdtable.h
77809 @@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77810 void put_files_struct(struct files_struct *fs);
77811 void reset_files_struct(struct files_struct *);
77812 int unshare_files(struct files_struct **);
77813 -struct files_struct *dup_fd(struct files_struct *, int *);
77814 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77815 void do_close_on_exec(struct files_struct *);
77816 int iterate_fd(struct files_struct *, unsigned,
77817 int (*)(const void *, struct file *, unsigned),
77818 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77819 index 8293262..2b3b8bd 100644
77820 --- a/include/linux/frontswap.h
77821 +++ b/include/linux/frontswap.h
77822 @@ -11,7 +11,7 @@ struct frontswap_ops {
77823 int (*load)(unsigned, pgoff_t, struct page *);
77824 void (*invalidate_page)(unsigned, pgoff_t);
77825 void (*invalidate_area)(unsigned);
77826 -};
77827 +} __no_const;
77828
77829 extern bool frontswap_enabled;
77830 extern struct frontswap_ops *
77831 diff --git a/include/linux/fs.h b/include/linux/fs.h
77832 index 121f11f..0f2a863 100644
77833 --- a/include/linux/fs.h
77834 +++ b/include/linux/fs.h
77835 @@ -423,7 +423,7 @@ struct address_space {
77836 spinlock_t private_lock; /* for use by the address_space */
77837 struct list_head private_list; /* ditto */
77838 void *private_data; /* ditto */
77839 -} __attribute__((aligned(sizeof(long))));
77840 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77841 /*
77842 * On most architectures that alignment is already the case; but
77843 * must be enforced here for CRIS, to let the least significant bit
77844 @@ -466,7 +466,7 @@ struct block_device {
77845 int bd_fsfreeze_count;
77846 /* Mutex for freeze */
77847 struct mutex bd_fsfreeze_mutex;
77848 -};
77849 +} __randomize_layout;
77850
77851 /*
77852 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77853 @@ -610,7 +610,7 @@ struct inode {
77854 atomic_t i_readcount; /* struct files open RO */
77855 #endif
77856 void *i_private; /* fs or device private pointer */
77857 -};
77858 +} __randomize_layout;
77859
77860 static inline int inode_unhashed(struct inode *inode)
77861 {
77862 @@ -808,7 +808,7 @@ struct file {
77863 #ifdef CONFIG_DEBUG_WRITECOUNT
77864 unsigned long f_mnt_write_state;
77865 #endif
77866 -};
77867 +} __randomize_layout;
77868
77869 struct file_handle {
77870 __u32 handle_bytes;
77871 @@ -978,7 +978,7 @@ struct file_lock {
77872 int state; /* state of grant or error if -ve */
77873 } afs;
77874 } fl_u;
77875 -};
77876 +} __randomize_layout;
77877
77878 /* The following constant reflects the upper bound of the file/locking space */
77879 #ifndef OFFSET_MAX
77880 @@ -1325,7 +1325,7 @@ struct super_block {
77881 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
77882 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
77883 struct rcu_head rcu;
77884 -};
77885 +} __randomize_layout;
77886
77887 extern struct timespec current_fs_time(struct super_block *sb);
77888
77889 @@ -1547,7 +1547,8 @@ struct file_operations {
77890 long (*fallocate)(struct file *file, int mode, loff_t offset,
77891 loff_t len);
77892 int (*show_fdinfo)(struct seq_file *m, struct file *f);
77893 -};
77894 +} __do_const __randomize_layout;
77895 +typedef struct file_operations __no_const file_operations_no_const;
77896
77897 struct inode_operations {
77898 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
77899 @@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
77900 return !IS_DEADDIR(inode);
77901 }
77902
77903 +static inline bool is_sidechannel_device(const struct inode *inode)
77904 +{
77905 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
77906 + umode_t mode = inode->i_mode;
77907 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
77908 +#else
77909 + return false;
77910 +#endif
77911 +}
77912 +
77913 #endif /* _LINUX_FS_H */
77914 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
77915 index 0efc3e6..fd23610 100644
77916 --- a/include/linux/fs_struct.h
77917 +++ b/include/linux/fs_struct.h
77918 @@ -6,13 +6,13 @@
77919 #include <linux/seqlock.h>
77920
77921 struct fs_struct {
77922 - int users;
77923 + atomic_t users;
77924 spinlock_t lock;
77925 seqcount_t seq;
77926 int umask;
77927 int in_exec;
77928 struct path root, pwd;
77929 -};
77930 +} __randomize_layout;
77931
77932 extern struct kmem_cache *fs_cachep;
77933
77934 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
77935 index 7714849..a4a5c7a 100644
77936 --- a/include/linux/fscache-cache.h
77937 +++ b/include/linux/fscache-cache.h
77938 @@ -113,7 +113,7 @@ struct fscache_operation {
77939 fscache_operation_release_t release;
77940 };
77941
77942 -extern atomic_t fscache_op_debug_id;
77943 +extern atomic_unchecked_t fscache_op_debug_id;
77944 extern void fscache_op_work_func(struct work_struct *work);
77945
77946 extern void fscache_enqueue_operation(struct fscache_operation *);
77947 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
77948 INIT_WORK(&op->work, fscache_op_work_func);
77949 atomic_set(&op->usage, 1);
77950 op->state = FSCACHE_OP_ST_INITIALISED;
77951 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
77952 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
77953 op->processor = processor;
77954 op->release = release;
77955 INIT_LIST_HEAD(&op->pend_link);
77956 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
77957 index 115bb81..e7b812b 100644
77958 --- a/include/linux/fscache.h
77959 +++ b/include/linux/fscache.h
77960 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
77961 * - this is mandatory for any object that may have data
77962 */
77963 void (*now_uncached)(void *cookie_netfs_data);
77964 -};
77965 +} __do_const;
77966
77967 /*
77968 * fscache cached network filesystem type
77969 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
77970 index 1c804b0..1432c2b 100644
77971 --- a/include/linux/fsnotify.h
77972 +++ b/include/linux/fsnotify.h
77973 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
77974 struct inode *inode = file_inode(file);
77975 __u32 mask = FS_ACCESS;
77976
77977 + if (is_sidechannel_device(inode))
77978 + return;
77979 +
77980 if (S_ISDIR(inode->i_mode))
77981 mask |= FS_ISDIR;
77982
77983 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
77984 struct inode *inode = file_inode(file);
77985 __u32 mask = FS_MODIFY;
77986
77987 + if (is_sidechannel_device(inode))
77988 + return;
77989 +
77990 if (S_ISDIR(inode->i_mode))
77991 mask |= FS_ISDIR;
77992
77993 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
77994 */
77995 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
77996 {
77997 - return kstrdup(name, GFP_KERNEL);
77998 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
77999 }
78000
78001 /*
78002 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78003 index 9f3c275..8bdff5d 100644
78004 --- a/include/linux/genhd.h
78005 +++ b/include/linux/genhd.h
78006 @@ -194,7 +194,7 @@ struct gendisk {
78007 struct kobject *slave_dir;
78008
78009 struct timer_rand_state *random;
78010 - atomic_t sync_io; /* RAID */
78011 + atomic_unchecked_t sync_io; /* RAID */
78012 struct disk_events *ev;
78013 #ifdef CONFIG_BLK_DEV_INTEGRITY
78014 struct blk_integrity *integrity;
78015 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78016 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78017
78018 /* drivers/char/random.c */
78019 -extern void add_disk_randomness(struct gendisk *disk);
78020 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78021 extern void rand_initialize_disk(struct gendisk *disk);
78022
78023 static inline sector_t get_start_sect(struct block_device *bdev)
78024 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78025 index c0894dd..2fbf10c 100644
78026 --- a/include/linux/genl_magic_func.h
78027 +++ b/include/linux/genl_magic_func.h
78028 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78029 },
78030
78031 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78032 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78033 +static struct genl_ops ZZZ_genl_ops[] = {
78034 #include GENL_MAGIC_INCLUDE_FILE
78035 };
78036
78037 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78038 index 9b4dd49..61fd41d 100644
78039 --- a/include/linux/gfp.h
78040 +++ b/include/linux/gfp.h
78041 @@ -35,6 +35,13 @@ struct vm_area_struct;
78042 #define ___GFP_NO_KSWAPD 0x400000u
78043 #define ___GFP_OTHER_NODE 0x800000u
78044 #define ___GFP_WRITE 0x1000000u
78045 +
78046 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78047 +#define ___GFP_USERCOPY 0x2000000u
78048 +#else
78049 +#define ___GFP_USERCOPY 0
78050 +#endif
78051 +
78052 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78053
78054 /*
78055 @@ -92,6 +99,7 @@ struct vm_area_struct;
78056 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78057 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78058 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78059 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78060
78061 /*
78062 * This may seem redundant, but it's a way of annotating false positives vs.
78063 @@ -99,7 +107,7 @@ struct vm_area_struct;
78064 */
78065 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78066
78067 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78068 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78069 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78070
78071 /* This equals 0, but use constants in case they ever change */
78072 @@ -153,6 +161,8 @@ struct vm_area_struct;
78073 /* 4GB DMA on some platforms */
78074 #define GFP_DMA32 __GFP_DMA32
78075
78076 +#define GFP_USERCOPY __GFP_USERCOPY
78077 +
78078 /* Convert GFP flags to their corresponding migrate type */
78079 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78080 {
78081 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78082 new file mode 100644
78083 index 0000000..edb2cb6
78084 --- /dev/null
78085 +++ b/include/linux/gracl.h
78086 @@ -0,0 +1,340 @@
78087 +#ifndef GR_ACL_H
78088 +#define GR_ACL_H
78089 +
78090 +#include <linux/grdefs.h>
78091 +#include <linux/resource.h>
78092 +#include <linux/capability.h>
78093 +#include <linux/dcache.h>
78094 +#include <asm/resource.h>
78095 +
78096 +/* Major status information */
78097 +
78098 +#define GR_VERSION "grsecurity 3.0"
78099 +#define GRSECURITY_VERSION 0x3000
78100 +
78101 +enum {
78102 + GR_SHUTDOWN = 0,
78103 + GR_ENABLE = 1,
78104 + GR_SPROLE = 2,
78105 + GR_OLDRELOAD = 3,
78106 + GR_SEGVMOD = 4,
78107 + GR_STATUS = 5,
78108 + GR_UNSPROLE = 6,
78109 + GR_PASSSET = 7,
78110 + GR_SPROLEPAM = 8,
78111 + GR_RELOAD = 9,
78112 +};
78113 +
78114 +/* Password setup definitions
78115 + * kernel/grhash.c */
78116 +enum {
78117 + GR_PW_LEN = 128,
78118 + GR_SALT_LEN = 16,
78119 + GR_SHA_LEN = 32,
78120 +};
78121 +
78122 +enum {
78123 + GR_SPROLE_LEN = 64,
78124 +};
78125 +
78126 +enum {
78127 + GR_NO_GLOB = 0,
78128 + GR_REG_GLOB,
78129 + GR_CREATE_GLOB
78130 +};
78131 +
78132 +#define GR_NLIMITS 32
78133 +
78134 +/* Begin Data Structures */
78135 +
78136 +struct sprole_pw {
78137 + unsigned char *rolename;
78138 + unsigned char salt[GR_SALT_LEN];
78139 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78140 +};
78141 +
78142 +struct name_entry {
78143 + __u32 key;
78144 + ino_t inode;
78145 + dev_t device;
78146 + char *name;
78147 + __u16 len;
78148 + __u8 deleted;
78149 + struct name_entry *prev;
78150 + struct name_entry *next;
78151 +};
78152 +
78153 +struct inodev_entry {
78154 + struct name_entry *nentry;
78155 + struct inodev_entry *prev;
78156 + struct inodev_entry *next;
78157 +};
78158 +
78159 +struct acl_role_db {
78160 + struct acl_role_label **r_hash;
78161 + __u32 r_size;
78162 +};
78163 +
78164 +struct inodev_db {
78165 + struct inodev_entry **i_hash;
78166 + __u32 i_size;
78167 +};
78168 +
78169 +struct name_db {
78170 + struct name_entry **n_hash;
78171 + __u32 n_size;
78172 +};
78173 +
78174 +struct crash_uid {
78175 + uid_t uid;
78176 + unsigned long expires;
78177 +};
78178 +
78179 +struct gr_hash_struct {
78180 + void **table;
78181 + void **nametable;
78182 + void *first;
78183 + __u32 table_size;
78184 + __u32 used_size;
78185 + int type;
78186 +};
78187 +
78188 +/* Userspace Grsecurity ACL data structures */
78189 +
78190 +struct acl_subject_label {
78191 + char *filename;
78192 + ino_t inode;
78193 + dev_t device;
78194 + __u32 mode;
78195 + kernel_cap_t cap_mask;
78196 + kernel_cap_t cap_lower;
78197 + kernel_cap_t cap_invert_audit;
78198 +
78199 + struct rlimit res[GR_NLIMITS];
78200 + __u32 resmask;
78201 +
78202 + __u8 user_trans_type;
78203 + __u8 group_trans_type;
78204 + uid_t *user_transitions;
78205 + gid_t *group_transitions;
78206 + __u16 user_trans_num;
78207 + __u16 group_trans_num;
78208 +
78209 + __u32 sock_families[2];
78210 + __u32 ip_proto[8];
78211 + __u32 ip_type;
78212 + struct acl_ip_label **ips;
78213 + __u32 ip_num;
78214 + __u32 inaddr_any_override;
78215 +
78216 + __u32 crashes;
78217 + unsigned long expires;
78218 +
78219 + struct acl_subject_label *parent_subject;
78220 + struct gr_hash_struct *hash;
78221 + struct acl_subject_label *prev;
78222 + struct acl_subject_label *next;
78223 +
78224 + struct acl_object_label **obj_hash;
78225 + __u32 obj_hash_size;
78226 + __u16 pax_flags;
78227 +};
78228 +
78229 +struct role_allowed_ip {
78230 + __u32 addr;
78231 + __u32 netmask;
78232 +
78233 + struct role_allowed_ip *prev;
78234 + struct role_allowed_ip *next;
78235 +};
78236 +
78237 +struct role_transition {
78238 + char *rolename;
78239 +
78240 + struct role_transition *prev;
78241 + struct role_transition *next;
78242 +};
78243 +
78244 +struct acl_role_label {
78245 + char *rolename;
78246 + uid_t uidgid;
78247 + __u16 roletype;
78248 +
78249 + __u16 auth_attempts;
78250 + unsigned long expires;
78251 +
78252 + struct acl_subject_label *root_label;
78253 + struct gr_hash_struct *hash;
78254 +
78255 + struct acl_role_label *prev;
78256 + struct acl_role_label *next;
78257 +
78258 + struct role_transition *transitions;
78259 + struct role_allowed_ip *allowed_ips;
78260 + uid_t *domain_children;
78261 + __u16 domain_child_num;
78262 +
78263 + umode_t umask;
78264 +
78265 + struct acl_subject_label **subj_hash;
78266 + __u32 subj_hash_size;
78267 +};
78268 +
78269 +struct user_acl_role_db {
78270 + struct acl_role_label **r_table;
78271 + __u32 num_pointers; /* Number of allocations to track */
78272 + __u32 num_roles; /* Number of roles */
78273 + __u32 num_domain_children; /* Number of domain children */
78274 + __u32 num_subjects; /* Number of subjects */
78275 + __u32 num_objects; /* Number of objects */
78276 +};
78277 +
78278 +struct acl_object_label {
78279 + char *filename;
78280 + ino_t inode;
78281 + dev_t device;
78282 + __u32 mode;
78283 +
78284 + struct acl_subject_label *nested;
78285 + struct acl_object_label *globbed;
78286 +
78287 + /* next two structures not used */
78288 +
78289 + struct acl_object_label *prev;
78290 + struct acl_object_label *next;
78291 +};
78292 +
78293 +struct acl_ip_label {
78294 + char *iface;
78295 + __u32 addr;
78296 + __u32 netmask;
78297 + __u16 low, high;
78298 + __u8 mode;
78299 + __u32 type;
78300 + __u32 proto[8];
78301 +
78302 + /* next two structures not used */
78303 +
78304 + struct acl_ip_label *prev;
78305 + struct acl_ip_label *next;
78306 +};
78307 +
78308 +struct gr_arg {
78309 + struct user_acl_role_db role_db;
78310 + unsigned char pw[GR_PW_LEN];
78311 + unsigned char salt[GR_SALT_LEN];
78312 + unsigned char sum[GR_SHA_LEN];
78313 + unsigned char sp_role[GR_SPROLE_LEN];
78314 + struct sprole_pw *sprole_pws;
78315 + dev_t segv_device;
78316 + ino_t segv_inode;
78317 + uid_t segv_uid;
78318 + __u16 num_sprole_pws;
78319 + __u16 mode;
78320 +};
78321 +
78322 +struct gr_arg_wrapper {
78323 + struct gr_arg *arg;
78324 + __u32 version;
78325 + __u32 size;
78326 +};
78327 +
78328 +struct subject_map {
78329 + struct acl_subject_label *user;
78330 + struct acl_subject_label *kernel;
78331 + struct subject_map *prev;
78332 + struct subject_map *next;
78333 +};
78334 +
78335 +struct acl_subj_map_db {
78336 + struct subject_map **s_hash;
78337 + __u32 s_size;
78338 +};
78339 +
78340 +struct gr_policy_state {
78341 + struct sprole_pw **acl_special_roles;
78342 + __u16 num_sprole_pws;
78343 + struct acl_role_label *kernel_role;
78344 + struct acl_role_label *role_list;
78345 + struct acl_role_label *default_role;
78346 + struct acl_role_db acl_role_set;
78347 + struct acl_subj_map_db subj_map_set;
78348 + struct name_db name_set;
78349 + struct inodev_db inodev_set;
78350 +};
78351 +
78352 +struct gr_alloc_state {
78353 + unsigned long alloc_stack_next;
78354 + unsigned long alloc_stack_size;
78355 + void **alloc_stack;
78356 +};
78357 +
78358 +struct gr_reload_state {
78359 + struct gr_policy_state oldpolicy;
78360 + struct gr_alloc_state oldalloc;
78361 + struct gr_policy_state newpolicy;
78362 + struct gr_alloc_state newalloc;
78363 + struct gr_policy_state *oldpolicy_ptr;
78364 + struct gr_alloc_state *oldalloc_ptr;
78365 + unsigned char oldmode;
78366 +};
78367 +
78368 +/* End Data Structures Section */
78369 +
78370 +/* Hash functions generated by empirical testing by Brad Spengler
78371 + Makes good use of the low bits of the inode. Generally 0-1 times
78372 + in loop for successful match. 0-3 for unsuccessful match.
78373 + Shift/add algorithm with modulus of table size and an XOR*/
78374 +
78375 +static __inline__ unsigned int
78376 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78377 +{
78378 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
78379 +}
78380 +
78381 + static __inline__ unsigned int
78382 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78383 +{
78384 + return ((const unsigned long)userp % sz);
78385 +}
78386 +
78387 +static __inline__ unsigned int
78388 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78389 +{
78390 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78391 +}
78392 +
78393 +static __inline__ unsigned int
78394 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78395 +{
78396 + return full_name_hash((const unsigned char *)name, len) % sz;
78397 +}
78398 +
78399 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78400 + subj = NULL; \
78401 + iter = 0; \
78402 + while (iter < role->subj_hash_size) { \
78403 + if (subj == NULL) \
78404 + subj = role->subj_hash[iter]; \
78405 + if (subj == NULL) { \
78406 + iter++; \
78407 + continue; \
78408 + }
78409 +
78410 +#define FOR_EACH_SUBJECT_END(subj,iter) \
78411 + subj = subj->next; \
78412 + if (subj == NULL) \
78413 + iter++; \
78414 + }
78415 +
78416 +
78417 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78418 + subj = role->hash->first; \
78419 + while (subj != NULL) {
78420 +
78421 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78422 + subj = subj->next; \
78423 + }
78424 +
78425 +#endif
78426 +
78427 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78428 new file mode 100644
78429 index 0000000..33ebd1f
78430 --- /dev/null
78431 +++ b/include/linux/gracl_compat.h
78432 @@ -0,0 +1,156 @@
78433 +#ifndef GR_ACL_COMPAT_H
78434 +#define GR_ACL_COMPAT_H
78435 +
78436 +#include <linux/resource.h>
78437 +#include <asm/resource.h>
78438 +
78439 +struct sprole_pw_compat {
78440 + compat_uptr_t rolename;
78441 + unsigned char salt[GR_SALT_LEN];
78442 + unsigned char sum[GR_SHA_LEN];
78443 +};
78444 +
78445 +struct gr_hash_struct_compat {
78446 + compat_uptr_t table;
78447 + compat_uptr_t nametable;
78448 + compat_uptr_t first;
78449 + __u32 table_size;
78450 + __u32 used_size;
78451 + int type;
78452 +};
78453 +
78454 +struct acl_subject_label_compat {
78455 + compat_uptr_t filename;
78456 + compat_ino_t inode;
78457 + __u32 device;
78458 + __u32 mode;
78459 + kernel_cap_t cap_mask;
78460 + kernel_cap_t cap_lower;
78461 + kernel_cap_t cap_invert_audit;
78462 +
78463 + struct compat_rlimit res[GR_NLIMITS];
78464 + __u32 resmask;
78465 +
78466 + __u8 user_trans_type;
78467 + __u8 group_trans_type;
78468 + compat_uptr_t user_transitions;
78469 + compat_uptr_t group_transitions;
78470 + __u16 user_trans_num;
78471 + __u16 group_trans_num;
78472 +
78473 + __u32 sock_families[2];
78474 + __u32 ip_proto[8];
78475 + __u32 ip_type;
78476 + compat_uptr_t ips;
78477 + __u32 ip_num;
78478 + __u32 inaddr_any_override;
78479 +
78480 + __u32 crashes;
78481 + compat_ulong_t expires;
78482 +
78483 + compat_uptr_t parent_subject;
78484 + compat_uptr_t hash;
78485 + compat_uptr_t prev;
78486 + compat_uptr_t next;
78487 +
78488 + compat_uptr_t obj_hash;
78489 + __u32 obj_hash_size;
78490 + __u16 pax_flags;
78491 +};
78492 +
78493 +struct role_allowed_ip_compat {
78494 + __u32 addr;
78495 + __u32 netmask;
78496 +
78497 + compat_uptr_t prev;
78498 + compat_uptr_t next;
78499 +};
78500 +
78501 +struct role_transition_compat {
78502 + compat_uptr_t rolename;
78503 +
78504 + compat_uptr_t prev;
78505 + compat_uptr_t next;
78506 +};
78507 +
78508 +struct acl_role_label_compat {
78509 + compat_uptr_t rolename;
78510 + uid_t uidgid;
78511 + __u16 roletype;
78512 +
78513 + __u16 auth_attempts;
78514 + compat_ulong_t expires;
78515 +
78516 + compat_uptr_t root_label;
78517 + compat_uptr_t hash;
78518 +
78519 + compat_uptr_t prev;
78520 + compat_uptr_t next;
78521 +
78522 + compat_uptr_t transitions;
78523 + compat_uptr_t allowed_ips;
78524 + compat_uptr_t domain_children;
78525 + __u16 domain_child_num;
78526 +
78527 + umode_t umask;
78528 +
78529 + compat_uptr_t subj_hash;
78530 + __u32 subj_hash_size;
78531 +};
78532 +
78533 +struct user_acl_role_db_compat {
78534 + compat_uptr_t r_table;
78535 + __u32 num_pointers;
78536 + __u32 num_roles;
78537 + __u32 num_domain_children;
78538 + __u32 num_subjects;
78539 + __u32 num_objects;
78540 +};
78541 +
78542 +struct acl_object_label_compat {
78543 + compat_uptr_t filename;
78544 + compat_ino_t inode;
78545 + __u32 device;
78546 + __u32 mode;
78547 +
78548 + compat_uptr_t nested;
78549 + compat_uptr_t globbed;
78550 +
78551 + compat_uptr_t prev;
78552 + compat_uptr_t next;
78553 +};
78554 +
78555 +struct acl_ip_label_compat {
78556 + compat_uptr_t iface;
78557 + __u32 addr;
78558 + __u32 netmask;
78559 + __u16 low, high;
78560 + __u8 mode;
78561 + __u32 type;
78562 + __u32 proto[8];
78563 +
78564 + compat_uptr_t prev;
78565 + compat_uptr_t next;
78566 +};
78567 +
78568 +struct gr_arg_compat {
78569 + struct user_acl_role_db_compat role_db;
78570 + unsigned char pw[GR_PW_LEN];
78571 + unsigned char salt[GR_SALT_LEN];
78572 + unsigned char sum[GR_SHA_LEN];
78573 + unsigned char sp_role[GR_SPROLE_LEN];
78574 + compat_uptr_t sprole_pws;
78575 + __u32 segv_device;
78576 + compat_ino_t segv_inode;
78577 + uid_t segv_uid;
78578 + __u16 num_sprole_pws;
78579 + __u16 mode;
78580 +};
78581 +
78582 +struct gr_arg_wrapper_compat {
78583 + compat_uptr_t arg;
78584 + __u32 version;
78585 + __u32 size;
78586 +};
78587 +
78588 +#endif
78589 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78590 new file mode 100644
78591 index 0000000..323ecf2
78592 --- /dev/null
78593 +++ b/include/linux/gralloc.h
78594 @@ -0,0 +1,9 @@
78595 +#ifndef __GRALLOC_H
78596 +#define __GRALLOC_H
78597 +
78598 +void acl_free_all(void);
78599 +int acl_alloc_stack_init(unsigned long size);
78600 +void *acl_alloc(unsigned long len);
78601 +void *acl_alloc_num(unsigned long num, unsigned long len);
78602 +
78603 +#endif
78604 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78605 new file mode 100644
78606 index 0000000..be66033
78607 --- /dev/null
78608 +++ b/include/linux/grdefs.h
78609 @@ -0,0 +1,140 @@
78610 +#ifndef GRDEFS_H
78611 +#define GRDEFS_H
78612 +
78613 +/* Begin grsecurity status declarations */
78614 +
78615 +enum {
78616 + GR_READY = 0x01,
78617 + GR_STATUS_INIT = 0x00 // disabled state
78618 +};
78619 +
78620 +/* Begin ACL declarations */
78621 +
78622 +/* Role flags */
78623 +
78624 +enum {
78625 + GR_ROLE_USER = 0x0001,
78626 + GR_ROLE_GROUP = 0x0002,
78627 + GR_ROLE_DEFAULT = 0x0004,
78628 + GR_ROLE_SPECIAL = 0x0008,
78629 + GR_ROLE_AUTH = 0x0010,
78630 + GR_ROLE_NOPW = 0x0020,
78631 + GR_ROLE_GOD = 0x0040,
78632 + GR_ROLE_LEARN = 0x0080,
78633 + GR_ROLE_TPE = 0x0100,
78634 + GR_ROLE_DOMAIN = 0x0200,
78635 + GR_ROLE_PAM = 0x0400,
78636 + GR_ROLE_PERSIST = 0x0800
78637 +};
78638 +
78639 +/* ACL Subject and Object mode flags */
78640 +enum {
78641 + GR_DELETED = 0x80000000
78642 +};
78643 +
78644 +/* ACL Object-only mode flags */
78645 +enum {
78646 + GR_READ = 0x00000001,
78647 + GR_APPEND = 0x00000002,
78648 + GR_WRITE = 0x00000004,
78649 + GR_EXEC = 0x00000008,
78650 + GR_FIND = 0x00000010,
78651 + GR_INHERIT = 0x00000020,
78652 + GR_SETID = 0x00000040,
78653 + GR_CREATE = 0x00000080,
78654 + GR_DELETE = 0x00000100,
78655 + GR_LINK = 0x00000200,
78656 + GR_AUDIT_READ = 0x00000400,
78657 + GR_AUDIT_APPEND = 0x00000800,
78658 + GR_AUDIT_WRITE = 0x00001000,
78659 + GR_AUDIT_EXEC = 0x00002000,
78660 + GR_AUDIT_FIND = 0x00004000,
78661 + GR_AUDIT_INHERIT= 0x00008000,
78662 + GR_AUDIT_SETID = 0x00010000,
78663 + GR_AUDIT_CREATE = 0x00020000,
78664 + GR_AUDIT_DELETE = 0x00040000,
78665 + GR_AUDIT_LINK = 0x00080000,
78666 + GR_PTRACERD = 0x00100000,
78667 + GR_NOPTRACE = 0x00200000,
78668 + GR_SUPPRESS = 0x00400000,
78669 + GR_NOLEARN = 0x00800000,
78670 + GR_INIT_TRANSFER= 0x01000000
78671 +};
78672 +
78673 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78674 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78675 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78676 +
78677 +/* ACL subject-only mode flags */
78678 +enum {
78679 + GR_KILL = 0x00000001,
78680 + GR_VIEW = 0x00000002,
78681 + GR_PROTECTED = 0x00000004,
78682 + GR_LEARN = 0x00000008,
78683 + GR_OVERRIDE = 0x00000010,
78684 + /* just a placeholder, this mode is only used in userspace */
78685 + GR_DUMMY = 0x00000020,
78686 + GR_PROTSHM = 0x00000040,
78687 + GR_KILLPROC = 0x00000080,
78688 + GR_KILLIPPROC = 0x00000100,
78689 + /* just a placeholder, this mode is only used in userspace */
78690 + GR_NOTROJAN = 0x00000200,
78691 + GR_PROTPROCFD = 0x00000400,
78692 + GR_PROCACCT = 0x00000800,
78693 + GR_RELAXPTRACE = 0x00001000,
78694 + //GR_NESTED = 0x00002000,
78695 + GR_INHERITLEARN = 0x00004000,
78696 + GR_PROCFIND = 0x00008000,
78697 + GR_POVERRIDE = 0x00010000,
78698 + GR_KERNELAUTH = 0x00020000,
78699 + GR_ATSECURE = 0x00040000,
78700 + GR_SHMEXEC = 0x00080000
78701 +};
78702 +
78703 +enum {
78704 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78705 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78706 + GR_PAX_ENABLE_MPROTECT = 0x0004,
78707 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
78708 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78709 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78710 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78711 + GR_PAX_DISABLE_MPROTECT = 0x0400,
78712 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
78713 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78714 +};
78715 +
78716 +enum {
78717 + GR_ID_USER = 0x01,
78718 + GR_ID_GROUP = 0x02,
78719 +};
78720 +
78721 +enum {
78722 + GR_ID_ALLOW = 0x01,
78723 + GR_ID_DENY = 0x02,
78724 +};
78725 +
78726 +#define GR_CRASH_RES 31
78727 +#define GR_UIDTABLE_MAX 500
78728 +
78729 +/* begin resource learning section */
78730 +enum {
78731 + GR_RLIM_CPU_BUMP = 60,
78732 + GR_RLIM_FSIZE_BUMP = 50000,
78733 + GR_RLIM_DATA_BUMP = 10000,
78734 + GR_RLIM_STACK_BUMP = 1000,
78735 + GR_RLIM_CORE_BUMP = 10000,
78736 + GR_RLIM_RSS_BUMP = 500000,
78737 + GR_RLIM_NPROC_BUMP = 1,
78738 + GR_RLIM_NOFILE_BUMP = 5,
78739 + GR_RLIM_MEMLOCK_BUMP = 50000,
78740 + GR_RLIM_AS_BUMP = 500000,
78741 + GR_RLIM_LOCKS_BUMP = 2,
78742 + GR_RLIM_SIGPENDING_BUMP = 5,
78743 + GR_RLIM_MSGQUEUE_BUMP = 10000,
78744 + GR_RLIM_NICE_BUMP = 1,
78745 + GR_RLIM_RTPRIO_BUMP = 1,
78746 + GR_RLIM_RTTIME_BUMP = 1000000
78747 +};
78748 +
78749 +#endif
78750 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78751 new file mode 100644
78752 index 0000000..d25522e
78753 --- /dev/null
78754 +++ b/include/linux/grinternal.h
78755 @@ -0,0 +1,229 @@
78756 +#ifndef __GRINTERNAL_H
78757 +#define __GRINTERNAL_H
78758 +
78759 +#ifdef CONFIG_GRKERNSEC
78760 +
78761 +#include <linux/fs.h>
78762 +#include <linux/mnt_namespace.h>
78763 +#include <linux/nsproxy.h>
78764 +#include <linux/gracl.h>
78765 +#include <linux/grdefs.h>
78766 +#include <linux/grmsg.h>
78767 +
78768 +void gr_add_learn_entry(const char *fmt, ...)
78769 + __attribute__ ((format (printf, 1, 2)));
78770 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78771 + const struct vfsmount *mnt);
78772 +__u32 gr_check_create(const struct dentry *new_dentry,
78773 + const struct dentry *parent,
78774 + const struct vfsmount *mnt, const __u32 mode);
78775 +int gr_check_protected_task(const struct task_struct *task);
78776 +__u32 to_gr_audit(const __u32 reqmode);
78777 +int gr_set_acls(const int type);
78778 +int gr_acl_is_enabled(void);
78779 +char gr_roletype_to_char(void);
78780 +
78781 +void gr_handle_alertkill(struct task_struct *task);
78782 +char *gr_to_filename(const struct dentry *dentry,
78783 + const struct vfsmount *mnt);
78784 +char *gr_to_filename1(const struct dentry *dentry,
78785 + const struct vfsmount *mnt);
78786 +char *gr_to_filename2(const struct dentry *dentry,
78787 + const struct vfsmount *mnt);
78788 +char *gr_to_filename3(const struct dentry *dentry,
78789 + const struct vfsmount *mnt);
78790 +
78791 +extern int grsec_enable_ptrace_readexec;
78792 +extern int grsec_enable_harden_ptrace;
78793 +extern int grsec_enable_link;
78794 +extern int grsec_enable_fifo;
78795 +extern int grsec_enable_execve;
78796 +extern int grsec_enable_shm;
78797 +extern int grsec_enable_execlog;
78798 +extern int grsec_enable_signal;
78799 +extern int grsec_enable_audit_ptrace;
78800 +extern int grsec_enable_forkfail;
78801 +extern int grsec_enable_time;
78802 +extern int grsec_enable_rofs;
78803 +extern int grsec_deny_new_usb;
78804 +extern int grsec_enable_chroot_shmat;
78805 +extern int grsec_enable_chroot_mount;
78806 +extern int grsec_enable_chroot_double;
78807 +extern int grsec_enable_chroot_pivot;
78808 +extern int grsec_enable_chroot_chdir;
78809 +extern int grsec_enable_chroot_chmod;
78810 +extern int grsec_enable_chroot_mknod;
78811 +extern int grsec_enable_chroot_fchdir;
78812 +extern int grsec_enable_chroot_nice;
78813 +extern int grsec_enable_chroot_execlog;
78814 +extern int grsec_enable_chroot_caps;
78815 +extern int grsec_enable_chroot_sysctl;
78816 +extern int grsec_enable_chroot_unix;
78817 +extern int grsec_enable_symlinkown;
78818 +extern kgid_t grsec_symlinkown_gid;
78819 +extern int grsec_enable_tpe;
78820 +extern kgid_t grsec_tpe_gid;
78821 +extern int grsec_enable_tpe_all;
78822 +extern int grsec_enable_tpe_invert;
78823 +extern int grsec_enable_socket_all;
78824 +extern kgid_t grsec_socket_all_gid;
78825 +extern int grsec_enable_socket_client;
78826 +extern kgid_t grsec_socket_client_gid;
78827 +extern int grsec_enable_socket_server;
78828 +extern kgid_t grsec_socket_server_gid;
78829 +extern kgid_t grsec_audit_gid;
78830 +extern int grsec_enable_group;
78831 +extern int grsec_enable_log_rwxmaps;
78832 +extern int grsec_enable_mount;
78833 +extern int grsec_enable_chdir;
78834 +extern int grsec_resource_logging;
78835 +extern int grsec_enable_blackhole;
78836 +extern int grsec_lastack_retries;
78837 +extern int grsec_enable_brute;
78838 +extern int grsec_enable_harden_ipc;
78839 +extern int grsec_lock;
78840 +
78841 +extern spinlock_t grsec_alert_lock;
78842 +extern unsigned long grsec_alert_wtime;
78843 +extern unsigned long grsec_alert_fyet;
78844 +
78845 +extern spinlock_t grsec_audit_lock;
78846 +
78847 +extern rwlock_t grsec_exec_file_lock;
78848 +
78849 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78850 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78851 + (tsk)->exec_file->f_path.mnt) : "/")
78852 +
78853 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78854 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78855 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78856 +
78857 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78858 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
78859 + (tsk)->exec_file->f_path.mnt) : "/")
78860 +
78861 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78862 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78863 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78864 +
78865 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78866 +
78867 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78868 +
78869 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78870 +{
78871 + if (file1 && file2) {
78872 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
78873 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
78874 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78875 + return true;
78876 + }
78877 +
78878 + return false;
78879 +}
78880 +
78881 +#define GR_CHROOT_CAPS {{ \
78882 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
78883 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
78884 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
78885 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
78886 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
78887 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
78888 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
78889 +
78890 +#define security_learn(normal_msg,args...) \
78891 +({ \
78892 + read_lock(&grsec_exec_file_lock); \
78893 + gr_add_learn_entry(normal_msg "\n", ## args); \
78894 + read_unlock(&grsec_exec_file_lock); \
78895 +})
78896 +
78897 +enum {
78898 + GR_DO_AUDIT,
78899 + GR_DONT_AUDIT,
78900 + /* used for non-audit messages that we shouldn't kill the task on */
78901 + GR_DONT_AUDIT_GOOD
78902 +};
78903 +
78904 +enum {
78905 + GR_TTYSNIFF,
78906 + GR_RBAC,
78907 + GR_RBAC_STR,
78908 + GR_STR_RBAC,
78909 + GR_RBAC_MODE2,
78910 + GR_RBAC_MODE3,
78911 + GR_FILENAME,
78912 + GR_SYSCTL_HIDDEN,
78913 + GR_NOARGS,
78914 + GR_ONE_INT,
78915 + GR_ONE_INT_TWO_STR,
78916 + GR_ONE_STR,
78917 + GR_STR_INT,
78918 + GR_TWO_STR_INT,
78919 + GR_TWO_INT,
78920 + GR_TWO_U64,
78921 + GR_THREE_INT,
78922 + GR_FIVE_INT_TWO_STR,
78923 + GR_TWO_STR,
78924 + GR_THREE_STR,
78925 + GR_FOUR_STR,
78926 + GR_STR_FILENAME,
78927 + GR_FILENAME_STR,
78928 + GR_FILENAME_TWO_INT,
78929 + GR_FILENAME_TWO_INT_STR,
78930 + GR_TEXTREL,
78931 + GR_PTRACE,
78932 + GR_RESOURCE,
78933 + GR_CAP,
78934 + GR_SIG,
78935 + GR_SIG2,
78936 + GR_CRASH1,
78937 + GR_CRASH2,
78938 + GR_PSACCT,
78939 + GR_RWXMAP,
78940 + GR_RWXMAPVMA
78941 +};
78942 +
78943 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
78944 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
78945 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
78946 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
78947 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
78948 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
78949 +#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)
78950 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
78951 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
78952 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
78953 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
78954 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
78955 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
78956 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
78957 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
78958 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
78959 +#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)
78960 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
78961 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
78962 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
78963 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
78964 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
78965 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
78966 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
78967 +#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)
78968 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
78969 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
78970 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
78971 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
78972 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
78973 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
78974 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
78975 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
78976 +#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)
78977 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
78978 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
78979 +
78980 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
78981 +
78982 +#endif
78983 +
78984 +#endif
78985 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
78986 new file mode 100644
78987 index 0000000..ba93581
78988 --- /dev/null
78989 +++ b/include/linux/grmsg.h
78990 @@ -0,0 +1,116 @@
78991 +#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"
78992 +#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"
78993 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
78994 +#define GR_STOPMOD_MSG "denied modification of module state by "
78995 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
78996 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
78997 +#define GR_IOPERM_MSG "denied use of ioperm() by "
78998 +#define GR_IOPL_MSG "denied use of iopl() by "
78999 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79000 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79001 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79002 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79003 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79004 +#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"
79005 +#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"
79006 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79007 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79008 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79009 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79010 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79011 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79012 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79013 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79014 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79015 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79016 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79017 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79018 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79019 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79020 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79021 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79022 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79023 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79024 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79025 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79026 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79027 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79028 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79029 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79030 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79031 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79032 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79033 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79034 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79035 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79036 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79037 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79038 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79039 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79040 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79041 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79042 +#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"
79043 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79044 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79045 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79046 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79047 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79048 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79049 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79050 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79051 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79052 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79053 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79054 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79055 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79056 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79057 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79058 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79059 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79060 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79061 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79062 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79063 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
79064 +#define GR_NICE_CHROOT_MSG "denied priority change by "
79065 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79066 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79067 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79068 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79069 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79070 +#define GR_TIME_MSG "time set by "
79071 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79072 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79073 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79074 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79075 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79076 +#define GR_BIND_MSG "denied bind() by "
79077 +#define GR_CONNECT_MSG "denied connect() by "
79078 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79079 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79080 +#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"
79081 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79082 +#define GR_CAP_ACL_MSG "use of %s denied for "
79083 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79084 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79085 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79086 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79087 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79088 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79089 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79090 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79091 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79092 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79093 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79094 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79095 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79096 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79097 +#define GR_VM86_MSG "denied use of vm86 by "
79098 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79099 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79100 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79101 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79102 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79103 +#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 "
79104 +#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 "
79105 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79106 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79107 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79108 new file mode 100644
79109 index 0000000..8108301
79110 --- /dev/null
79111 +++ b/include/linux/grsecurity.h
79112 @@ -0,0 +1,246 @@
79113 +#ifndef GR_SECURITY_H
79114 +#define GR_SECURITY_H
79115 +#include <linux/fs.h>
79116 +#include <linux/fs_struct.h>
79117 +#include <linux/binfmts.h>
79118 +#include <linux/gracl.h>
79119 +
79120 +/* notify of brain-dead configs */
79121 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79122 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79123 +#endif
79124 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79125 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79126 +#endif
79127 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79128 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79129 +#endif
79130 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79131 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
79132 +#endif
79133 +
79134 +int gr_handle_new_usb(void);
79135 +
79136 +void gr_handle_brute_attach(int dumpable);
79137 +void gr_handle_brute_check(void);
79138 +void gr_handle_kernel_exploit(void);
79139 +
79140 +char gr_roletype_to_char(void);
79141 +
79142 +int gr_acl_enable_at_secure(void);
79143 +
79144 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79145 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79146 +
79147 +void gr_del_task_from_ip_table(struct task_struct *p);
79148 +
79149 +int gr_pid_is_chrooted(struct task_struct *p);
79150 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79151 +int gr_handle_chroot_nice(void);
79152 +int gr_handle_chroot_sysctl(const int op);
79153 +int gr_handle_chroot_setpriority(struct task_struct *p,
79154 + const int niceval);
79155 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79156 +int gr_handle_chroot_chroot(const struct dentry *dentry,
79157 + const struct vfsmount *mnt);
79158 +void gr_handle_chroot_chdir(const struct path *path);
79159 +int gr_handle_chroot_chmod(const struct dentry *dentry,
79160 + const struct vfsmount *mnt, const int mode);
79161 +int gr_handle_chroot_mknod(const struct dentry *dentry,
79162 + const struct vfsmount *mnt, const int mode);
79163 +int gr_handle_chroot_mount(const struct dentry *dentry,
79164 + const struct vfsmount *mnt,
79165 + const char *dev_name);
79166 +int gr_handle_chroot_pivot(void);
79167 +int gr_handle_chroot_unix(const pid_t pid);
79168 +
79169 +int gr_handle_rawio(const struct inode *inode);
79170 +
79171 +void gr_handle_ioperm(void);
79172 +void gr_handle_iopl(void);
79173 +void gr_handle_msr_write(void);
79174 +
79175 +umode_t gr_acl_umask(void);
79176 +
79177 +int gr_tpe_allow(const struct file *file);
79178 +
79179 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79180 +void gr_clear_chroot_entries(struct task_struct *task);
79181 +
79182 +void gr_log_forkfail(const int retval);
79183 +void gr_log_timechange(void);
79184 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79185 +void gr_log_chdir(const struct dentry *dentry,
79186 + const struct vfsmount *mnt);
79187 +void gr_log_chroot_exec(const struct dentry *dentry,
79188 + const struct vfsmount *mnt);
79189 +void gr_log_remount(const char *devname, const int retval);
79190 +void gr_log_unmount(const char *devname, const int retval);
79191 +void gr_log_mount(const char *from, const char *to, const int retval);
79192 +void gr_log_textrel(struct vm_area_struct *vma);
79193 +void gr_log_ptgnustack(struct file *file);
79194 +void gr_log_rwxmmap(struct file *file);
79195 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
79196 +
79197 +int gr_handle_follow_link(const struct inode *parent,
79198 + const struct inode *inode,
79199 + const struct dentry *dentry,
79200 + const struct vfsmount *mnt);
79201 +int gr_handle_fifo(const struct dentry *dentry,
79202 + const struct vfsmount *mnt,
79203 + const struct dentry *dir, const int flag,
79204 + const int acc_mode);
79205 +int gr_handle_hardlink(const struct dentry *dentry,
79206 + const struct vfsmount *mnt,
79207 + struct inode *inode,
79208 + const int mode, const struct filename *to);
79209 +
79210 +int gr_is_capable(const int cap);
79211 +int gr_is_capable_nolog(const int cap);
79212 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79213 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79214 +
79215 +void gr_copy_label(struct task_struct *tsk);
79216 +void gr_handle_crash(struct task_struct *task, const int sig);
79217 +int gr_handle_signal(const struct task_struct *p, const int sig);
79218 +int gr_check_crash_uid(const kuid_t uid);
79219 +int gr_check_protected_task(const struct task_struct *task);
79220 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79221 +int gr_acl_handle_mmap(const struct file *file,
79222 + const unsigned long prot);
79223 +int gr_acl_handle_mprotect(const struct file *file,
79224 + const unsigned long prot);
79225 +int gr_check_hidden_task(const struct task_struct *tsk);
79226 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79227 + const struct vfsmount *mnt);
79228 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
79229 + const struct vfsmount *mnt);
79230 +__u32 gr_acl_handle_access(const struct dentry *dentry,
79231 + const struct vfsmount *mnt, const int fmode);
79232 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79233 + const struct vfsmount *mnt, umode_t *mode);
79234 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
79235 + const struct vfsmount *mnt);
79236 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79237 + const struct vfsmount *mnt);
79238 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79239 + const struct vfsmount *mnt);
79240 +int gr_handle_ptrace(struct task_struct *task, const long request);
79241 +int gr_handle_proc_ptrace(struct task_struct *task);
79242 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
79243 + const struct vfsmount *mnt);
79244 +int gr_check_crash_exec(const struct file *filp);
79245 +int gr_acl_is_enabled(void);
79246 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79247 + const kgid_t gid);
79248 +int gr_set_proc_label(const struct dentry *dentry,
79249 + const struct vfsmount *mnt,
79250 + const int unsafe_flags);
79251 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79252 + const struct vfsmount *mnt);
79253 +__u32 gr_acl_handle_open(const struct dentry *dentry,
79254 + const struct vfsmount *mnt, int acc_mode);
79255 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
79256 + const struct dentry *p_dentry,
79257 + const struct vfsmount *p_mnt,
79258 + int open_flags, int acc_mode, const int imode);
79259 +void gr_handle_create(const struct dentry *dentry,
79260 + const struct vfsmount *mnt);
79261 +void gr_handle_proc_create(const struct dentry *dentry,
79262 + const struct inode *inode);
79263 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79264 + const struct dentry *parent_dentry,
79265 + const struct vfsmount *parent_mnt,
79266 + const int mode);
79267 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79268 + const struct dentry *parent_dentry,
79269 + const struct vfsmount *parent_mnt);
79270 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79271 + const struct vfsmount *mnt);
79272 +void gr_handle_delete(const ino_t ino, const dev_t dev);
79273 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79274 + const struct vfsmount *mnt);
79275 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79276 + const struct dentry *parent_dentry,
79277 + const struct vfsmount *parent_mnt,
79278 + const struct filename *from);
79279 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79280 + const struct dentry *parent_dentry,
79281 + const struct vfsmount *parent_mnt,
79282 + const struct dentry *old_dentry,
79283 + const struct vfsmount *old_mnt, const struct filename *to);
79284 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79285 +int gr_acl_handle_rename(struct dentry *new_dentry,
79286 + struct dentry *parent_dentry,
79287 + const struct vfsmount *parent_mnt,
79288 + struct dentry *old_dentry,
79289 + struct inode *old_parent_inode,
79290 + struct vfsmount *old_mnt, const struct filename *newname);
79291 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79292 + struct dentry *old_dentry,
79293 + struct dentry *new_dentry,
79294 + struct vfsmount *mnt, const __u8 replace);
79295 +__u32 gr_check_link(const struct dentry *new_dentry,
79296 + const struct dentry *parent_dentry,
79297 + const struct vfsmount *parent_mnt,
79298 + const struct dentry *old_dentry,
79299 + const struct vfsmount *old_mnt);
79300 +int gr_acl_handle_filldir(const struct file *file, const char *name,
79301 + const unsigned int namelen, const ino_t ino);
79302 +
79303 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
79304 + const struct vfsmount *mnt);
79305 +void gr_acl_handle_exit(void);
79306 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
79307 +int gr_acl_handle_procpidmem(const struct task_struct *task);
79308 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79309 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79310 +void gr_audit_ptrace(struct task_struct *task);
79311 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79312 +void gr_put_exec_file(struct task_struct *task);
79313 +
79314 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79315 +
79316 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79317 +extern void gr_learn_resource(const struct task_struct *task, const int res,
79318 + const unsigned long wanted, const int gt);
79319 +#else
79320 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
79321 + const unsigned long wanted, const int gt)
79322 +{
79323 +}
79324 +#endif
79325 +
79326 +#ifdef CONFIG_GRKERNSEC_RESLOG
79327 +extern void gr_log_resource(const struct task_struct *task, const int res,
79328 + const unsigned long wanted, const int gt);
79329 +#else
79330 +static inline void gr_log_resource(const struct task_struct *task, const int res,
79331 + const unsigned long wanted, const int gt)
79332 +{
79333 +}
79334 +#endif
79335 +
79336 +#ifdef CONFIG_GRKERNSEC
79337 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79338 +void gr_handle_vm86(void);
79339 +void gr_handle_mem_readwrite(u64 from, u64 to);
79340 +
79341 +void gr_log_badprocpid(const char *entry);
79342 +
79343 +extern int grsec_enable_dmesg;
79344 +extern int grsec_disable_privio;
79345 +
79346 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79347 +extern kgid_t grsec_proc_gid;
79348 +#endif
79349 +
79350 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79351 +extern int grsec_enable_chroot_findtask;
79352 +#endif
79353 +#ifdef CONFIG_GRKERNSEC_SETXID
79354 +extern int grsec_enable_setxid;
79355 +#endif
79356 +#endif
79357 +
79358 +#endif
79359 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79360 new file mode 100644
79361 index 0000000..e7ffaaf
79362 --- /dev/null
79363 +++ b/include/linux/grsock.h
79364 @@ -0,0 +1,19 @@
79365 +#ifndef __GRSOCK_H
79366 +#define __GRSOCK_H
79367 +
79368 +extern void gr_attach_curr_ip(const struct sock *sk);
79369 +extern int gr_handle_sock_all(const int family, const int type,
79370 + const int protocol);
79371 +extern int gr_handle_sock_server(const struct sockaddr *sck);
79372 +extern int gr_handle_sock_server_other(const struct sock *sck);
79373 +extern int gr_handle_sock_client(const struct sockaddr *sck);
79374 +extern int gr_search_connect(struct socket * sock,
79375 + struct sockaddr_in * addr);
79376 +extern int gr_search_bind(struct socket * sock,
79377 + struct sockaddr_in * addr);
79378 +extern int gr_search_listen(struct socket * sock);
79379 +extern int gr_search_accept(struct socket * sock);
79380 +extern int gr_search_socket(const int domain, const int type,
79381 + const int protocol);
79382 +
79383 +#endif
79384 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79385 index 7fb31da..08b5114 100644
79386 --- a/include/linux/highmem.h
79387 +++ b/include/linux/highmem.h
79388 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79389 kunmap_atomic(kaddr);
79390 }
79391
79392 +static inline void sanitize_highpage(struct page *page)
79393 +{
79394 + void *kaddr;
79395 + unsigned long flags;
79396 +
79397 + local_irq_save(flags);
79398 + kaddr = kmap_atomic(page);
79399 + clear_page(kaddr);
79400 + kunmap_atomic(kaddr);
79401 + local_irq_restore(flags);
79402 +}
79403 +
79404 static inline void zero_user_segments(struct page *page,
79405 unsigned start1, unsigned end1,
79406 unsigned start2, unsigned end2)
79407 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79408 index 1c7b89a..7dda400 100644
79409 --- a/include/linux/hwmon-sysfs.h
79410 +++ b/include/linux/hwmon-sysfs.h
79411 @@ -25,7 +25,8 @@
79412 struct sensor_device_attribute{
79413 struct device_attribute dev_attr;
79414 int index;
79415 -};
79416 +} __do_const;
79417 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79418 #define to_sensor_dev_attr(_dev_attr) \
79419 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79420
79421 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79422 struct device_attribute dev_attr;
79423 u8 index;
79424 u8 nr;
79425 -};
79426 +} __do_const;
79427 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79428 #define to_sensor_dev_attr_2(_dev_attr) \
79429 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79430
79431 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79432 index d9c8dbd3..def6e5a 100644
79433 --- a/include/linux/i2c.h
79434 +++ b/include/linux/i2c.h
79435 @@ -364,6 +364,7 @@ struct i2c_algorithm {
79436 /* To determine what the adapter supports */
79437 u32 (*functionality) (struct i2c_adapter *);
79438 };
79439 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79440
79441 /**
79442 * struct i2c_bus_recovery_info - I2C bus recovery information
79443 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79444 index d23c3c2..eb63c81 100644
79445 --- a/include/linux/i2o.h
79446 +++ b/include/linux/i2o.h
79447 @@ -565,7 +565,7 @@ struct i2o_controller {
79448 struct i2o_device *exec; /* Executive */
79449 #if BITS_PER_LONG == 64
79450 spinlock_t context_list_lock; /* lock for context_list */
79451 - atomic_t context_list_counter; /* needed for unique contexts */
79452 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79453 struct list_head context_list; /* list of context id's
79454 and pointers */
79455 #endif
79456 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79457 index aff7ad8..3942bbd 100644
79458 --- a/include/linux/if_pppox.h
79459 +++ b/include/linux/if_pppox.h
79460 @@ -76,7 +76,7 @@ struct pppox_proto {
79461 int (*ioctl)(struct socket *sock, unsigned int cmd,
79462 unsigned long arg);
79463 struct module *owner;
79464 -};
79465 +} __do_const;
79466
79467 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79468 extern void unregister_pppox_proto(int proto_num);
79469 diff --git a/include/linux/init.h b/include/linux/init.h
79470 index 8e68a64..3f977a0 100644
79471 --- a/include/linux/init.h
79472 +++ b/include/linux/init.h
79473 @@ -37,9 +37,17 @@
79474 * section.
79475 */
79476
79477 +#define add_init_latent_entropy __latent_entropy
79478 +
79479 +#ifdef CONFIG_MEMORY_HOTPLUG
79480 +#define add_meminit_latent_entropy
79481 +#else
79482 +#define add_meminit_latent_entropy __latent_entropy
79483 +#endif
79484 +
79485 /* These are for everybody (although not all archs will actually
79486 discard it in modules) */
79487 -#define __init __section(.init.text) __cold notrace
79488 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79489 #define __initdata __section(.init.data)
79490 #define __initconst __constsection(.init.rodata)
79491 #define __exitdata __section(.exit.data)
79492 @@ -100,7 +108,7 @@
79493 #define __cpuexitconst
79494
79495 /* Used for MEMORY_HOTPLUG */
79496 -#define __meminit __section(.meminit.text) __cold notrace
79497 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79498 #define __meminitdata __section(.meminit.data)
79499 #define __meminitconst __constsection(.meminit.rodata)
79500 #define __memexit __section(.memexit.text) __exitused __cold notrace
79501 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79502 index b0ed422..d79ea23 100644
79503 --- a/include/linux/init_task.h
79504 +++ b/include/linux/init_task.h
79505 @@ -154,6 +154,12 @@ extern struct task_group root_task_group;
79506
79507 #define INIT_TASK_COMM "swapper"
79508
79509 +#ifdef CONFIG_X86
79510 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79511 +#else
79512 +#define INIT_TASK_THREAD_INFO
79513 +#endif
79514 +
79515 /*
79516 * INIT_TASK is used to set up the first task table, touch at
79517 * your own risk!. Base=0, limit=0x1fffff (=2MB)
79518 @@ -193,6 +199,7 @@ extern struct task_group root_task_group;
79519 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79520 .comm = INIT_TASK_COMM, \
79521 .thread = INIT_THREAD, \
79522 + INIT_TASK_THREAD_INFO \
79523 .fs = &init_fs, \
79524 .files = &init_files, \
79525 .signal = &init_signals, \
79526 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79527 index db43b58..5d5084b 100644
79528 --- a/include/linux/interrupt.h
79529 +++ b/include/linux/interrupt.h
79530 @@ -360,7 +360,7 @@ enum
79531 /* map softirq index to softirq name. update 'softirq_to_name' in
79532 * kernel/softirq.c when adding a new softirq.
79533 */
79534 -extern char *softirq_to_name[NR_SOFTIRQS];
79535 +extern const char * const softirq_to_name[NR_SOFTIRQS];
79536
79537 /* softirq mask and active fields moved to irq_cpustat_t in
79538 * asm/hardirq.h to get better cache usage. KAO
79539 @@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
79540
79541 struct softirq_action
79542 {
79543 - void (*action)(struct softirq_action *);
79544 -};
79545 + void (*action)(void);
79546 +} __no_const;
79547
79548 asmlinkage void do_softirq(void);
79549 asmlinkage void __do_softirq(void);
79550 @@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
79551 }
79552 #endif
79553
79554 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79555 +extern void open_softirq(int nr, void (*action)(void));
79556 extern void softirq_init(void);
79557 extern void __raise_softirq_irqoff(unsigned int nr);
79558
79559 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79560 index a444c79..8c41ea9 100644
79561 --- a/include/linux/iommu.h
79562 +++ b/include/linux/iommu.h
79563 @@ -130,7 +130,7 @@ struct iommu_ops {
79564 u32 (*domain_get_windows)(struct iommu_domain *domain);
79565
79566 unsigned long pgsize_bitmap;
79567 -};
79568 +} __do_const;
79569
79570 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79571 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79572 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79573 index 89b7c24..382af74 100644
79574 --- a/include/linux/ioport.h
79575 +++ b/include/linux/ioport.h
79576 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79577 int adjust_resource(struct resource *res, resource_size_t start,
79578 resource_size_t size);
79579 resource_size_t resource_alignment(struct resource *res);
79580 -static inline resource_size_t resource_size(const struct resource *res)
79581 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79582 {
79583 return res->end - res->start + 1;
79584 }
79585 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79586 index d6ad91f..f10f279 100644
79587 --- a/include/linux/ipc_namespace.h
79588 +++ b/include/linux/ipc_namespace.h
79589 @@ -70,7 +70,7 @@ struct ipc_namespace {
79590 struct user_namespace *user_ns;
79591
79592 unsigned int proc_inum;
79593 -};
79594 +} __randomize_layout;
79595
79596 extern struct ipc_namespace init_ipc_ns;
79597 extern atomic_t nr_ipc_ns;
79598 diff --git a/include/linux/irq.h b/include/linux/irq.h
79599 index 7dc1003..407327b 100644
79600 --- a/include/linux/irq.h
79601 +++ b/include/linux/irq.h
79602 @@ -338,7 +338,8 @@ struct irq_chip {
79603 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79604
79605 unsigned long flags;
79606 -};
79607 +} __do_const;
79608 +typedef struct irq_chip __no_const irq_chip_no_const;
79609
79610 /*
79611 * irq_chip specific flags
79612 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79613 index cac496b..ffa0567 100644
79614 --- a/include/linux/irqchip/arm-gic.h
79615 +++ b/include/linux/irqchip/arm-gic.h
79616 @@ -61,9 +61,11 @@
79617
79618 #ifndef __ASSEMBLY__
79619
79620 +#include <linux/irq.h>
79621 +
79622 struct device_node;
79623
79624 -extern struct irq_chip gic_arch_extn;
79625 +extern irq_chip_no_const gic_arch_extn;
79626
79627 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79628 u32 offset, struct device_node *);
79629 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79630 index d235e88..8ccbe74 100644
79631 --- a/include/linux/jiffies.h
79632 +++ b/include/linux/jiffies.h
79633 @@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
79634 /*
79635 * Convert various time units to each other:
79636 */
79637 -extern unsigned int jiffies_to_msecs(const unsigned long j);
79638 -extern unsigned int jiffies_to_usecs(const unsigned long j);
79639 -extern unsigned long msecs_to_jiffies(const unsigned int m);
79640 -extern unsigned long usecs_to_jiffies(const unsigned int u);
79641 -extern unsigned long timespec_to_jiffies(const struct timespec *value);
79642 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79643 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79644 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79645 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79646 +extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
79647 extern void jiffies_to_timespec(const unsigned long jiffies,
79648 struct timespec *value);
79649 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
79650 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79651 extern void jiffies_to_timeval(const unsigned long jiffies,
79652 struct timeval *value);
79653
79654 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79655 index 6883e19..e854fcb 100644
79656 --- a/include/linux/kallsyms.h
79657 +++ b/include/linux/kallsyms.h
79658 @@ -15,7 +15,8 @@
79659
79660 struct module;
79661
79662 -#ifdef CONFIG_KALLSYMS
79663 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79664 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79665 /* Lookup the address for a symbol. Returns 0 if not found. */
79666 unsigned long kallsyms_lookup_name(const char *name);
79667
79668 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79669 /* Stupid that this does nothing, but I didn't create this mess. */
79670 #define __print_symbol(fmt, addr)
79671 #endif /*CONFIG_KALLSYMS*/
79672 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79673 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79674 +extern unsigned long kallsyms_lookup_name(const char *name);
79675 +extern void __print_symbol(const char *fmt, unsigned long address);
79676 +extern int sprint_backtrace(char *buffer, unsigned long address);
79677 +extern int sprint_symbol(char *buffer, unsigned long address);
79678 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79679 +const char *kallsyms_lookup(unsigned long addr,
79680 + unsigned long *symbolsize,
79681 + unsigned long *offset,
79682 + char **modname, char *namebuf);
79683 +extern int kallsyms_lookup_size_offset(unsigned long addr,
79684 + unsigned long *symbolsize,
79685 + unsigned long *offset);
79686 +#endif
79687
79688 /* This macro allows us to keep printk typechecking */
79689 static __printf(1, 2)
79690 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79691 index a74c3a8..28d3f21 100644
79692 --- a/include/linux/key-type.h
79693 +++ b/include/linux/key-type.h
79694 @@ -131,7 +131,7 @@ struct key_type {
79695 /* internal fields */
79696 struct list_head link; /* link in types list */
79697 struct lock_class_key lock_class; /* key->sem lock class */
79698 -};
79699 +} __do_const;
79700
79701 extern struct key_type key_type_keyring;
79702
79703 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79704 index dfb4f2f..7927e62 100644
79705 --- a/include/linux/kgdb.h
79706 +++ b/include/linux/kgdb.h
79707 @@ -52,7 +52,7 @@ extern int kgdb_connected;
79708 extern int kgdb_io_module_registered;
79709
79710 extern atomic_t kgdb_setting_breakpoint;
79711 -extern atomic_t kgdb_cpu_doing_single_step;
79712 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79713
79714 extern struct task_struct *kgdb_usethread;
79715 extern struct task_struct *kgdb_contthread;
79716 @@ -254,7 +254,7 @@ struct kgdb_arch {
79717 void (*correct_hw_break)(void);
79718
79719 void (*enable_nmi)(bool on);
79720 -};
79721 +} __do_const;
79722
79723 /**
79724 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79725 @@ -279,7 +279,7 @@ struct kgdb_io {
79726 void (*pre_exception) (void);
79727 void (*post_exception) (void);
79728 int is_console;
79729 -};
79730 +} __do_const;
79731
79732 extern struct kgdb_arch arch_kgdb_ops;
79733
79734 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79735 index 0555cc6..40116ce 100644
79736 --- a/include/linux/kmod.h
79737 +++ b/include/linux/kmod.h
79738 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79739 * usually useless though. */
79740 extern __printf(2, 3)
79741 int __request_module(bool wait, const char *name, ...);
79742 +extern __printf(3, 4)
79743 +int ___request_module(bool wait, char *param_name, const char *name, ...);
79744 #define request_module(mod...) __request_module(true, mod)
79745 #define request_module_nowait(mod...) __request_module(false, mod)
79746 #define try_then_request_module(x, mod...) \
79747 @@ -57,6 +59,9 @@ struct subprocess_info {
79748 struct work_struct work;
79749 struct completion *complete;
79750 char *path;
79751 +#ifdef CONFIG_GRKERNSEC
79752 + char *origpath;
79753 +#endif
79754 char **argv;
79755 char **envp;
79756 int wait;
79757 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79758 index e7ba650..0af3acb 100644
79759 --- a/include/linux/kobject.h
79760 +++ b/include/linux/kobject.h
79761 @@ -116,7 +116,7 @@ struct kobj_type {
79762 struct attribute **default_attrs;
79763 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79764 const void *(*namespace)(struct kobject *kobj);
79765 -};
79766 +} __do_const;
79767
79768 struct kobj_uevent_env {
79769 char *envp[UEVENT_NUM_ENVP];
79770 @@ -139,6 +139,7 @@ struct kobj_attribute {
79771 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79772 const char *buf, size_t count);
79773 };
79774 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79775
79776 extern const struct sysfs_ops kobj_sysfs_ops;
79777
79778 @@ -166,7 +167,7 @@ struct kset {
79779 spinlock_t list_lock;
79780 struct kobject kobj;
79781 const struct kset_uevent_ops *uevent_ops;
79782 -};
79783 +} __randomize_layout;
79784
79785 extern void kset_init(struct kset *kset);
79786 extern int __must_check kset_register(struct kset *kset);
79787 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79788 index df32d25..fb52e27 100644
79789 --- a/include/linux/kobject_ns.h
79790 +++ b/include/linux/kobject_ns.h
79791 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79792 const void *(*netlink_ns)(struct sock *sk);
79793 const void *(*initial_ns)(void);
79794 void (*drop_ns)(void *);
79795 -};
79796 +} __do_const;
79797
79798 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79799 int kobj_ns_type_registered(enum kobj_ns_type type);
79800 diff --git a/include/linux/kref.h b/include/linux/kref.h
79801 index 484604d..0f6c5b6 100644
79802 --- a/include/linux/kref.h
79803 +++ b/include/linux/kref.h
79804 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79805 static inline int kref_sub(struct kref *kref, unsigned int count,
79806 void (*release)(struct kref *kref))
79807 {
79808 - WARN_ON(release == NULL);
79809 + BUG_ON(release == NULL);
79810
79811 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79812 release(kref);
79813 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79814 index 9523d2a..16c0424 100644
79815 --- a/include/linux/kvm_host.h
79816 +++ b/include/linux/kvm_host.h
79817 @@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
79818 {
79819 }
79820 #endif
79821 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79822 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79823 struct module *module);
79824 void kvm_exit(void);
79825
79826 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79827 struct kvm_guest_debug *dbg);
79828 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79829
79830 -int kvm_arch_init(void *opaque);
79831 +int kvm_arch_init(const void *opaque);
79832 void kvm_arch_exit(void);
79833
79834 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79835 diff --git a/include/linux/libata.h b/include/linux/libata.h
79836 index bec6dbe..2873d64 100644
79837 --- a/include/linux/libata.h
79838 +++ b/include/linux/libata.h
79839 @@ -975,7 +975,7 @@ struct ata_port_operations {
79840 * fields must be pointers.
79841 */
79842 const struct ata_port_operations *inherits;
79843 -};
79844 +} __do_const;
79845
79846 struct ata_port_info {
79847 unsigned long flags;
79848 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79849 index d3e8ad2..a949f68 100644
79850 --- a/include/linux/linkage.h
79851 +++ b/include/linux/linkage.h
79852 @@ -31,6 +31,7 @@
79853 #endif
79854
79855 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79856 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79857 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79858
79859 /*
79860 diff --git a/include/linux/list.h b/include/linux/list.h
79861 index ef95941..82db65a 100644
79862 --- a/include/linux/list.h
79863 +++ b/include/linux/list.h
79864 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
79865 extern void list_del(struct list_head *entry);
79866 #endif
79867
79868 +extern void __pax_list_add(struct list_head *new,
79869 + struct list_head *prev,
79870 + struct list_head *next);
79871 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
79872 +{
79873 + __pax_list_add(new, head, head->next);
79874 +}
79875 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
79876 +{
79877 + __pax_list_add(new, head->prev, head);
79878 +}
79879 +extern void pax_list_del(struct list_head *entry);
79880 +
79881 /**
79882 * list_replace - replace old entry by new one
79883 * @old : the element to be replaced
79884 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
79885 INIT_LIST_HEAD(entry);
79886 }
79887
79888 +extern void pax_list_del_init(struct list_head *entry);
79889 +
79890 /**
79891 * list_move - delete from one list and add as another's head
79892 * @list: the entry to move
79893 diff --git a/include/linux/math64.h b/include/linux/math64.h
79894 index c45c089..298841c 100644
79895 --- a/include/linux/math64.h
79896 +++ b/include/linux/math64.h
79897 @@ -15,7 +15,7 @@
79898 * This is commonly provided by 32bit archs to provide an optimized 64bit
79899 * divide.
79900 */
79901 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79902 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79903 {
79904 *remainder = dividend % divisor;
79905 return dividend / divisor;
79906 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
79907 /**
79908 * div64_u64 - unsigned 64bit divide with 64bit divisor
79909 */
79910 -static inline u64 div64_u64(u64 dividend, u64 divisor)
79911 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79912 {
79913 return dividend / divisor;
79914 }
79915 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
79916 #define div64_ul(x, y) div_u64((x), (y))
79917
79918 #ifndef div_u64_rem
79919 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79920 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79921 {
79922 *remainder = do_div(dividend, divisor);
79923 return dividend;
79924 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
79925 #endif
79926
79927 #ifndef div64_u64
79928 -extern u64 div64_u64(u64 dividend, u64 divisor);
79929 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
79930 #endif
79931
79932 #ifndef div64_s64
79933 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
79934 * divide.
79935 */
79936 #ifndef div_u64
79937 -static inline u64 div_u64(u64 dividend, u32 divisor)
79938 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
79939 {
79940 u32 remainder;
79941 return div_u64_rem(dividend, divisor, &remainder);
79942 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
79943 index 9fe426b..8148be6 100644
79944 --- a/include/linux/mempolicy.h
79945 +++ b/include/linux/mempolicy.h
79946 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
79947 }
79948
79949 #define vma_policy(vma) ((vma)->vm_policy)
79950 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79951 +{
79952 + vma->vm_policy = pol;
79953 +}
79954
79955 static inline void mpol_get(struct mempolicy *pol)
79956 {
79957 @@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
79958 }
79959
79960 #define vma_policy(vma) NULL
79961 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79962 +{
79963 +}
79964
79965 static inline int
79966 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
79967 diff --git a/include/linux/mm.h b/include/linux/mm.h
79968 index 5360b82..4eedf45 100644
79969 --- a/include/linux/mm.h
79970 +++ b/include/linux/mm.h
79971 @@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
79972 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
79973 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
79974 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
79975 +
79976 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
79977 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
79978 +#endif
79979 +
79980 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
79981
79982 #ifdef CONFIG_MEM_SOFT_DIRTY
79983 @@ -219,8 +224,8 @@ struct vm_operations_struct {
79984 /* called by access_process_vm when get_user_pages() fails, typically
79985 * for use by special VMAs that can switch between memory and hardware
79986 */
79987 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
79988 - void *buf, int len, int write);
79989 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
79990 + void *buf, size_t len, int write);
79991 #ifdef CONFIG_NUMA
79992 /*
79993 * set_policy() op must add a reference to any non-NULL @new mempolicy
79994 @@ -250,6 +255,7 @@ struct vm_operations_struct {
79995 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
79996 unsigned long size, pgoff_t pgoff);
79997 };
79998 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
79999
80000 struct mmu_gather;
80001 struct inode;
80002 @@ -1074,8 +1080,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80003 unsigned long *pfn);
80004 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80005 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80006 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80007 - void *buf, int len, int write);
80008 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80009 + void *buf, size_t len, int write);
80010
80011 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80012 loff_t const holebegin, loff_t const holelen)
80013 @@ -1114,9 +1120,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80014 }
80015 #endif
80016
80017 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80018 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80019 - void *buf, int len, int write);
80020 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80021 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80022 + void *buf, size_t len, int write);
80023
80024 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80025 unsigned long start, unsigned long nr_pages,
80026 @@ -1148,34 +1154,6 @@ int set_page_dirty(struct page *page);
80027 int set_page_dirty_lock(struct page *page);
80028 int clear_page_dirty_for_io(struct page *page);
80029
80030 -/* Is the vma a continuation of the stack vma above it? */
80031 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80032 -{
80033 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80034 -}
80035 -
80036 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
80037 - unsigned long addr)
80038 -{
80039 - return (vma->vm_flags & VM_GROWSDOWN) &&
80040 - (vma->vm_start == addr) &&
80041 - !vma_growsdown(vma->vm_prev, addr);
80042 -}
80043 -
80044 -/* Is the vma a continuation of the stack vma below it? */
80045 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80046 -{
80047 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80048 -}
80049 -
80050 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
80051 - unsigned long addr)
80052 -{
80053 - return (vma->vm_flags & VM_GROWSUP) &&
80054 - (vma->vm_end == addr) &&
80055 - !vma_growsup(vma->vm_next, addr);
80056 -}
80057 -
80058 extern pid_t
80059 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80060
80061 @@ -1275,6 +1253,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80062 }
80063 #endif
80064
80065 +#ifdef CONFIG_MMU
80066 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80067 +#else
80068 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80069 +{
80070 + return __pgprot(0);
80071 +}
80072 +#endif
80073 +
80074 int vma_wants_writenotify(struct vm_area_struct *vma);
80075
80076 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80077 @@ -1293,8 +1280,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80078 {
80079 return 0;
80080 }
80081 +
80082 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80083 + unsigned long address)
80084 +{
80085 + return 0;
80086 +}
80087 #else
80088 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80089 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80090 #endif
80091
80092 #ifdef __PAGETABLE_PMD_FOLDED
80093 @@ -1303,8 +1297,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80094 {
80095 return 0;
80096 }
80097 +
80098 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80099 + unsigned long address)
80100 +{
80101 + return 0;
80102 +}
80103 #else
80104 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80105 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80106 #endif
80107
80108 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80109 @@ -1322,11 +1323,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80110 NULL: pud_offset(pgd, address);
80111 }
80112
80113 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80114 +{
80115 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80116 + NULL: pud_offset(pgd, address);
80117 +}
80118 +
80119 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80120 {
80121 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80122 NULL: pmd_offset(pud, address);
80123 }
80124 +
80125 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80126 +{
80127 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80128 + NULL: pmd_offset(pud, address);
80129 +}
80130 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80131
80132 #if USE_SPLIT_PTE_PTLOCKS
80133 @@ -1704,7 +1717,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80134 unsigned long addr, unsigned long len,
80135 unsigned long flags, struct page **pages);
80136
80137 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80138 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80139
80140 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80141 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80142 @@ -1712,6 +1725,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80143 unsigned long len, unsigned long prot, unsigned long flags,
80144 unsigned long pgoff, unsigned long *populate);
80145 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80146 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80147
80148 #ifdef CONFIG_MMU
80149 extern int __mm_populate(unsigned long addr, unsigned long len,
80150 @@ -1740,10 +1754,11 @@ struct vm_unmapped_area_info {
80151 unsigned long high_limit;
80152 unsigned long align_mask;
80153 unsigned long align_offset;
80154 + unsigned long threadstack_offset;
80155 };
80156
80157 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80158 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80159 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80160 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80161
80162 /*
80163 * Search for an unmapped address range.
80164 @@ -1755,7 +1770,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80165 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80166 */
80167 static inline unsigned long
80168 -vm_unmapped_area(struct vm_unmapped_area_info *info)
80169 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
80170 {
80171 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80172 return unmapped_area(info);
80173 @@ -1818,6 +1833,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80174 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80175 struct vm_area_struct **pprev);
80176
80177 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80178 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80179 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80180 +
80181 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80182 NULL if none. Assume start_addr < end_addr. */
80183 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80184 @@ -1846,15 +1865,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80185 return vma;
80186 }
80187
80188 -#ifdef CONFIG_MMU
80189 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
80190 -#else
80191 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80192 -{
80193 - return __pgprot(0);
80194 -}
80195 -#endif
80196 -
80197 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
80198 unsigned long change_prot_numa(struct vm_area_struct *vma,
80199 unsigned long start, unsigned long end);
80200 @@ -1906,6 +1916,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80201 static inline void vm_stat_account(struct mm_struct *mm,
80202 unsigned long flags, struct file *file, long pages)
80203 {
80204 +
80205 +#ifdef CONFIG_PAX_RANDMMAP
80206 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80207 +#endif
80208 +
80209 mm->total_vm += pages;
80210 }
80211 #endif /* CONFIG_PROC_FS */
80212 @@ -1987,7 +2002,7 @@ extern int unpoison_memory(unsigned long pfn);
80213 extern int sysctl_memory_failure_early_kill;
80214 extern int sysctl_memory_failure_recovery;
80215 extern void shake_page(struct page *p, int access);
80216 -extern atomic_long_t num_poisoned_pages;
80217 +extern atomic_long_unchecked_t num_poisoned_pages;
80218 extern int soft_offline_page(struct page *page, int flags);
80219
80220 extern void dump_page(struct page *page);
80221 @@ -2024,5 +2039,11 @@ void __init setup_nr_node_ids(void);
80222 static inline void setup_nr_node_ids(void) {}
80223 #endif
80224
80225 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80226 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80227 +#else
80228 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80229 +#endif
80230 +
80231 #endif /* __KERNEL__ */
80232 #endif /* _LINUX_MM_H */
80233 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80234 index 290901a..e99b01c 100644
80235 --- a/include/linux/mm_types.h
80236 +++ b/include/linux/mm_types.h
80237 @@ -307,7 +307,9 @@ struct vm_area_struct {
80238 #ifdef CONFIG_NUMA
80239 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80240 #endif
80241 -};
80242 +
80243 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80244 +} __randomize_layout;
80245
80246 struct core_thread {
80247 struct task_struct *task;
80248 @@ -453,7 +455,25 @@ struct mm_struct {
80249 bool tlb_flush_pending;
80250 #endif
80251 struct uprobes_state uprobes_state;
80252 -};
80253 +
80254 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80255 + unsigned long pax_flags;
80256 +#endif
80257 +
80258 +#ifdef CONFIG_PAX_DLRESOLVE
80259 + unsigned long call_dl_resolve;
80260 +#endif
80261 +
80262 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80263 + unsigned long call_syscall;
80264 +#endif
80265 +
80266 +#ifdef CONFIG_PAX_ASLR
80267 + unsigned long delta_mmap; /* randomized offset */
80268 + unsigned long delta_stack; /* randomized offset */
80269 +#endif
80270 +
80271 +} __randomize_layout;
80272
80273 static inline void mm_init_cpumask(struct mm_struct *mm)
80274 {
80275 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80276 index c5d5278..f0b68c8 100644
80277 --- a/include/linux/mmiotrace.h
80278 +++ b/include/linux/mmiotrace.h
80279 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80280 /* Called from ioremap.c */
80281 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80282 void __iomem *addr);
80283 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
80284 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80285
80286 /* For anyone to insert markers. Remember trailing newline. */
80287 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80288 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80289 {
80290 }
80291
80292 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80293 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80294 {
80295 }
80296
80297 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80298 index bd791e4..8617c34f 100644
80299 --- a/include/linux/mmzone.h
80300 +++ b/include/linux/mmzone.h
80301 @@ -396,7 +396,7 @@ struct zone {
80302 unsigned long flags; /* zone flags, see below */
80303
80304 /* Zone statistics */
80305 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80306 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80307
80308 /*
80309 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80310 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80311 index 45e9214..a7227d6 100644
80312 --- a/include/linux/mod_devicetable.h
80313 +++ b/include/linux/mod_devicetable.h
80314 @@ -13,7 +13,7 @@
80315 typedef unsigned long kernel_ulong_t;
80316 #endif
80317
80318 -#define PCI_ANY_ID (~0)
80319 +#define PCI_ANY_ID ((__u16)~0)
80320
80321 struct pci_device_id {
80322 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80323 @@ -139,7 +139,7 @@ struct usb_device_id {
80324 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80325 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80326
80327 -#define HID_ANY_ID (~0)
80328 +#define HID_ANY_ID (~0U)
80329 #define HID_BUS_ANY 0xffff
80330 #define HID_GROUP_ANY 0x0000
80331
80332 @@ -467,7 +467,7 @@ struct dmi_system_id {
80333 const char *ident;
80334 struct dmi_strmatch matches[4];
80335 void *driver_data;
80336 -};
80337 +} __do_const;
80338 /*
80339 * struct dmi_device_id appears during expansion of
80340 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80341 diff --git a/include/linux/module.h b/include/linux/module.h
80342 index 15cd6b1..f6e2e6a 100644
80343 --- a/include/linux/module.h
80344 +++ b/include/linux/module.h
80345 @@ -17,9 +17,11 @@
80346 #include <linux/moduleparam.h>
80347 #include <linux/tracepoint.h>
80348 #include <linux/export.h>
80349 +#include <linux/fs.h>
80350
80351 #include <linux/percpu.h>
80352 #include <asm/module.h>
80353 +#include <asm/pgtable.h>
80354
80355 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80356 #define MODULE_SIG_STRING "~Module signature appended~\n"
80357 @@ -43,7 +45,7 @@ struct module_kobject {
80358 struct kobject *drivers_dir;
80359 struct module_param_attrs *mp;
80360 struct completion *kobj_completion;
80361 -};
80362 +} __randomize_layout;
80363
80364 struct module_attribute {
80365 struct attribute attr;
80366 @@ -55,12 +57,13 @@ struct module_attribute {
80367 int (*test)(struct module *);
80368 void (*free)(struct module *);
80369 };
80370 +typedef struct module_attribute __no_const module_attribute_no_const;
80371
80372 struct module_version_attribute {
80373 struct module_attribute mattr;
80374 const char *module_name;
80375 const char *version;
80376 -} __attribute__ ((__aligned__(sizeof(void *))));
80377 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80378
80379 extern ssize_t __modver_version_show(struct module_attribute *,
80380 struct module_kobject *, char *);
80381 @@ -238,7 +241,7 @@ struct module
80382
80383 /* Sysfs stuff. */
80384 struct module_kobject mkobj;
80385 - struct module_attribute *modinfo_attrs;
80386 + module_attribute_no_const *modinfo_attrs;
80387 const char *version;
80388 const char *srcversion;
80389 struct kobject *holders_dir;
80390 @@ -287,19 +290,16 @@ struct module
80391 int (*init)(void);
80392
80393 /* If this is non-NULL, vfree after init() returns */
80394 - void *module_init;
80395 + void *module_init_rx, *module_init_rw;
80396
80397 /* Here is the actual code + data, vfree'd on unload. */
80398 - void *module_core;
80399 + void *module_core_rx, *module_core_rw;
80400
80401 /* Here are the sizes of the init and core sections */
80402 - unsigned int init_size, core_size;
80403 + unsigned int init_size_rw, core_size_rw;
80404
80405 /* The size of the executable code in each section. */
80406 - unsigned int init_text_size, core_text_size;
80407 -
80408 - /* Size of RO sections of the module (text+rodata) */
80409 - unsigned int init_ro_size, core_ro_size;
80410 + unsigned int init_size_rx, core_size_rx;
80411
80412 /* Arch-specific module values */
80413 struct mod_arch_specific arch;
80414 @@ -355,6 +355,10 @@ struct module
80415 #ifdef CONFIG_EVENT_TRACING
80416 struct ftrace_event_call **trace_events;
80417 unsigned int num_trace_events;
80418 + struct file_operations trace_id;
80419 + struct file_operations trace_enable;
80420 + struct file_operations trace_format;
80421 + struct file_operations trace_filter;
80422 #endif
80423 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80424 unsigned int num_ftrace_callsites;
80425 @@ -378,7 +382,7 @@ struct module
80426 ctor_fn_t *ctors;
80427 unsigned int num_ctors;
80428 #endif
80429 -};
80430 +} __randomize_layout;
80431 #ifndef MODULE_ARCH_INIT
80432 #define MODULE_ARCH_INIT {}
80433 #endif
80434 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80435 bool is_module_percpu_address(unsigned long addr);
80436 bool is_module_text_address(unsigned long addr);
80437
80438 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80439 +{
80440 +
80441 +#ifdef CONFIG_PAX_KERNEXEC
80442 + if (ktla_ktva(addr) >= (unsigned long)start &&
80443 + ktla_ktva(addr) < (unsigned long)start + size)
80444 + return 1;
80445 +#endif
80446 +
80447 + return ((void *)addr >= start && (void *)addr < start + size);
80448 +}
80449 +
80450 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80451 +{
80452 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80453 +}
80454 +
80455 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80456 +{
80457 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80458 +}
80459 +
80460 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80461 +{
80462 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80463 +}
80464 +
80465 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80466 +{
80467 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80468 +}
80469 +
80470 static inline int within_module_core(unsigned long addr, const struct module *mod)
80471 {
80472 - return (unsigned long)mod->module_core <= addr &&
80473 - addr < (unsigned long)mod->module_core + mod->core_size;
80474 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80475 }
80476
80477 static inline int within_module_init(unsigned long addr, const struct module *mod)
80478 {
80479 - return (unsigned long)mod->module_init <= addr &&
80480 - addr < (unsigned long)mod->module_init + mod->init_size;
80481 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80482 }
80483
80484 /* Search for module by name: must hold module_mutex. */
80485 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80486 index 560ca53..ef621ef 100644
80487 --- a/include/linux/moduleloader.h
80488 +++ b/include/linux/moduleloader.h
80489 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80490 sections. Returns NULL on failure. */
80491 void *module_alloc(unsigned long size);
80492
80493 +#ifdef CONFIG_PAX_KERNEXEC
80494 +void *module_alloc_exec(unsigned long size);
80495 +#else
80496 +#define module_alloc_exec(x) module_alloc(x)
80497 +#endif
80498 +
80499 /* Free memory returned from module_alloc. */
80500 void module_free(struct module *mod, void *module_region);
80501
80502 +#ifdef CONFIG_PAX_KERNEXEC
80503 +void module_free_exec(struct module *mod, void *module_region);
80504 +#else
80505 +#define module_free_exec(x, y) module_free((x), (y))
80506 +#endif
80507 +
80508 /*
80509 * Apply the given relocation to the (simplified) ELF. Return -error
80510 * or 0.
80511 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80512 unsigned int relsec,
80513 struct module *me)
80514 {
80515 +#ifdef CONFIG_MODULES
80516 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80517 +#endif
80518 return -ENOEXEC;
80519 }
80520 #endif
80521 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80522 unsigned int relsec,
80523 struct module *me)
80524 {
80525 +#ifdef CONFIG_MODULES
80526 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80527 +#endif
80528 return -ENOEXEC;
80529 }
80530 #endif
80531 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80532 index c3eb102..073c4a6 100644
80533 --- a/include/linux/moduleparam.h
80534 +++ b/include/linux/moduleparam.h
80535 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80536 * @len is usually just sizeof(string).
80537 */
80538 #define module_param_string(name, string, len, perm) \
80539 - static const struct kparam_string __param_string_##name \
80540 + static const struct kparam_string __param_string_##name __used \
80541 = { len, string }; \
80542 __module_param_call(MODULE_PARAM_PREFIX, name, \
80543 &param_ops_string, \
80544 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80545 */
80546 #define module_param_array_named(name, array, type, nump, perm) \
80547 param_check_##type(name, &(array)[0]); \
80548 - static const struct kparam_array __param_arr_##name \
80549 + static const struct kparam_array __param_arr_##name __used \
80550 = { .max = ARRAY_SIZE(array), .num = nump, \
80551 .ops = &param_ops_##type, \
80552 .elemsize = sizeof(array[0]), .elem = array }; \
80553 diff --git a/include/linux/mount.h b/include/linux/mount.h
80554 index 371d346..fba2819 100644
80555 --- a/include/linux/mount.h
80556 +++ b/include/linux/mount.h
80557 @@ -56,7 +56,7 @@ struct vfsmount {
80558 struct dentry *mnt_root; /* root of the mounted tree */
80559 struct super_block *mnt_sb; /* pointer to superblock */
80560 int mnt_flags;
80561 -};
80562 +} __randomize_layout;
80563
80564 struct file; /* forward dec */
80565
80566 diff --git a/include/linux/namei.h b/include/linux/namei.h
80567 index 492de72..1bddcd4 100644
80568 --- a/include/linux/namei.h
80569 +++ b/include/linux/namei.h
80570 @@ -19,7 +19,7 @@ struct nameidata {
80571 unsigned seq, m_seq;
80572 int last_type;
80573 unsigned depth;
80574 - char *saved_names[MAX_NESTED_LINKS + 1];
80575 + const char *saved_names[MAX_NESTED_LINKS + 1];
80576 };
80577
80578 /*
80579 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80580
80581 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80582
80583 -static inline void nd_set_link(struct nameidata *nd, char *path)
80584 +static inline void nd_set_link(struct nameidata *nd, const char *path)
80585 {
80586 nd->saved_names[nd->depth] = path;
80587 }
80588
80589 -static inline char *nd_get_link(struct nameidata *nd)
80590 +static inline const char *nd_get_link(const struct nameidata *nd)
80591 {
80592 return nd->saved_names[nd->depth];
80593 }
80594 diff --git a/include/linux/net.h b/include/linux/net.h
80595 index 69be3e6..0fb422d 100644
80596 --- a/include/linux/net.h
80597 +++ b/include/linux/net.h
80598 @@ -192,7 +192,7 @@ struct net_proto_family {
80599 int (*create)(struct net *net, struct socket *sock,
80600 int protocol, int kern);
80601 struct module *owner;
80602 -};
80603 +} __do_const;
80604
80605 struct iovec;
80606 struct kvec;
80607 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80608 index 2177a6b..67fc561 100644
80609 --- a/include/linux/netdevice.h
80610 +++ b/include/linux/netdevice.h
80611 @@ -1129,6 +1129,7 @@ struct net_device_ops {
80612 struct net_device *dev,
80613 void *priv);
80614 };
80615 +typedef struct net_device_ops __no_const net_device_ops_no_const;
80616
80617 /*
80618 * The DEVICE structure.
80619 @@ -1211,7 +1212,7 @@ struct net_device {
80620 int iflink;
80621
80622 struct net_device_stats stats;
80623 - atomic_long_t rx_dropped; /* dropped packets by core network
80624 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80625 * Do not use this in drivers.
80626 */
80627
80628 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80629 index 2077489..a15e561 100644
80630 --- a/include/linux/netfilter.h
80631 +++ b/include/linux/netfilter.h
80632 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80633 #endif
80634 /* Use the module struct to lock set/get code in place */
80635 struct module *owner;
80636 -};
80637 +} __do_const;
80638
80639 /* Function to register/unregister hook points. */
80640 int nf_register_hook(struct nf_hook_ops *reg);
80641 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80642 index 28c7436..2d6156a 100644
80643 --- a/include/linux/netfilter/nfnetlink.h
80644 +++ b/include/linux/netfilter/nfnetlink.h
80645 @@ -19,7 +19,7 @@ struct nfnl_callback {
80646 const struct nlattr * const cda[]);
80647 const struct nla_policy *policy; /* netlink attribute policy */
80648 const u_int16_t attr_count; /* number of nlattr's */
80649 -};
80650 +} __do_const;
80651
80652 struct nfnetlink_subsystem {
80653 const char *name;
80654 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80655 new file mode 100644
80656 index 0000000..33f4af8
80657 --- /dev/null
80658 +++ b/include/linux/netfilter/xt_gradm.h
80659 @@ -0,0 +1,9 @@
80660 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
80661 +#define _LINUX_NETFILTER_XT_GRADM_H 1
80662 +
80663 +struct xt_gradm_mtinfo {
80664 + __u16 flags;
80665 + __u16 invflags;
80666 +};
80667 +
80668 +#endif
80669 diff --git a/include/linux/nls.h b/include/linux/nls.h
80670 index 5dc635f..35f5e11 100644
80671 --- a/include/linux/nls.h
80672 +++ b/include/linux/nls.h
80673 @@ -31,7 +31,7 @@ struct nls_table {
80674 const unsigned char *charset2upper;
80675 struct module *owner;
80676 struct nls_table *next;
80677 -};
80678 +} __do_const;
80679
80680 /* this value hold the maximum octet of charset */
80681 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80682 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80683 index d14a4c3..a078786 100644
80684 --- a/include/linux/notifier.h
80685 +++ b/include/linux/notifier.h
80686 @@ -54,7 +54,8 @@ struct notifier_block {
80687 notifier_fn_t notifier_call;
80688 struct notifier_block __rcu *next;
80689 int priority;
80690 -};
80691 +} __do_const;
80692 +typedef struct notifier_block __no_const notifier_block_no_const;
80693
80694 struct atomic_notifier_head {
80695 spinlock_t lock;
80696 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80697 index b2a0f15..4d7da32 100644
80698 --- a/include/linux/oprofile.h
80699 +++ b/include/linux/oprofile.h
80700 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80701 int oprofilefs_create_ro_ulong(struct dentry * root,
80702 char const * name, ulong * val);
80703
80704 -/** Create a file for read-only access to an atomic_t. */
80705 +/** Create a file for read-only access to an atomic_unchecked_t. */
80706 int oprofilefs_create_ro_atomic(struct dentry * root,
80707 - char const * name, atomic_t * val);
80708 + char const * name, atomic_unchecked_t * val);
80709
80710 /** create a directory */
80711 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80712 diff --git a/include/linux/padata.h b/include/linux/padata.h
80713 index 4386946..f50c615 100644
80714 --- a/include/linux/padata.h
80715 +++ b/include/linux/padata.h
80716 @@ -129,7 +129,7 @@ struct parallel_data {
80717 struct padata_serial_queue __percpu *squeue;
80718 atomic_t reorder_objects;
80719 atomic_t refcnt;
80720 - atomic_t seq_nr;
80721 + atomic_unchecked_t seq_nr;
80722 struct padata_cpumask cpumask;
80723 spinlock_t lock ____cacheline_aligned;
80724 unsigned int processed;
80725 diff --git a/include/linux/path.h b/include/linux/path.h
80726 index d137218..be0c176 100644
80727 --- a/include/linux/path.h
80728 +++ b/include/linux/path.h
80729 @@ -1,13 +1,15 @@
80730 #ifndef _LINUX_PATH_H
80731 #define _LINUX_PATH_H
80732
80733 +#include <linux/compiler.h>
80734 +
80735 struct dentry;
80736 struct vfsmount;
80737
80738 struct path {
80739 struct vfsmount *mnt;
80740 struct dentry *dentry;
80741 -};
80742 +} __randomize_layout;
80743
80744 extern void path_get(const struct path *);
80745 extern void path_put(const struct path *);
80746 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80747 index a2e2f1d..8a391d2 100644
80748 --- a/include/linux/pci_hotplug.h
80749 +++ b/include/linux/pci_hotplug.h
80750 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80751 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80752 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80753 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80754 -};
80755 +} __do_const;
80756 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80757
80758 /**
80759 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80760 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80761 index 2e069d1..27054b8 100644
80762 --- a/include/linux/perf_event.h
80763 +++ b/include/linux/perf_event.h
80764 @@ -327,8 +327,8 @@ struct perf_event {
80765
80766 enum perf_event_active_state state;
80767 unsigned int attach_state;
80768 - local64_t count;
80769 - atomic64_t child_count;
80770 + local64_t count; /* PaX: fix it one day */
80771 + atomic64_unchecked_t child_count;
80772
80773 /*
80774 * These are the total time in nanoseconds that the event
80775 @@ -379,8 +379,8 @@ struct perf_event {
80776 * These accumulate total time (in nanoseconds) that children
80777 * events have been enabled and running, respectively.
80778 */
80779 - atomic64_t child_total_time_enabled;
80780 - atomic64_t child_total_time_running;
80781 + atomic64_unchecked_t child_total_time_enabled;
80782 + atomic64_unchecked_t child_total_time_running;
80783
80784 /*
80785 * Protect attach/detach and child_list:
80786 @@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80787 entry->ip[entry->nr++] = ip;
80788 }
80789
80790 -extern int sysctl_perf_event_paranoid;
80791 +extern int sysctl_perf_event_legitimately_concerned;
80792 extern int sysctl_perf_event_mlock;
80793 extern int sysctl_perf_event_sample_rate;
80794 extern int sysctl_perf_cpu_time_max_percent;
80795 @@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80796 loff_t *ppos);
80797
80798
80799 +static inline bool perf_paranoid_any(void)
80800 +{
80801 + return sysctl_perf_event_legitimately_concerned > 2;
80802 +}
80803 +
80804 static inline bool perf_paranoid_tracepoint_raw(void)
80805 {
80806 - return sysctl_perf_event_paranoid > -1;
80807 + return sysctl_perf_event_legitimately_concerned > -1;
80808 }
80809
80810 static inline bool perf_paranoid_cpu(void)
80811 {
80812 - return sysctl_perf_event_paranoid > 0;
80813 + return sysctl_perf_event_legitimately_concerned > 0;
80814 }
80815
80816 static inline bool perf_paranoid_kernel(void)
80817 {
80818 - return sysctl_perf_event_paranoid > 1;
80819 + return sysctl_perf_event_legitimately_concerned > 1;
80820 }
80821
80822 extern void perf_event_init(void);
80823 @@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
80824 struct device_attribute attr;
80825 u64 id;
80826 const char *event_str;
80827 -};
80828 +} __do_const;
80829
80830 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80831 static struct perf_pmu_events_attr _var = { \
80832 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80833 index 7246ef3..1539ea4 100644
80834 --- a/include/linux/pid_namespace.h
80835 +++ b/include/linux/pid_namespace.h
80836 @@ -43,7 +43,7 @@ struct pid_namespace {
80837 int hide_pid;
80838 int reboot; /* group exit code if this pidns was rebooted */
80839 unsigned int proc_inum;
80840 -};
80841 +} __randomize_layout;
80842
80843 extern struct pid_namespace init_pid_ns;
80844
80845 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80846 index ab57526..94598804 100644
80847 --- a/include/linux/pipe_fs_i.h
80848 +++ b/include/linux/pipe_fs_i.h
80849 @@ -47,10 +47,10 @@ struct pipe_inode_info {
80850 struct mutex mutex;
80851 wait_queue_head_t wait;
80852 unsigned int nrbufs, curbuf, buffers;
80853 - unsigned int readers;
80854 - unsigned int writers;
80855 - unsigned int files;
80856 - unsigned int waiting_writers;
80857 + atomic_t readers;
80858 + atomic_t writers;
80859 + atomic_t files;
80860 + atomic_t waiting_writers;
80861 unsigned int r_counter;
80862 unsigned int w_counter;
80863 struct page *tmp_page;
80864 diff --git a/include/linux/pm.h b/include/linux/pm.h
80865 index a224c7f..92d8a97 100644
80866 --- a/include/linux/pm.h
80867 +++ b/include/linux/pm.h
80868 @@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
80869 struct dev_pm_domain {
80870 struct dev_pm_ops ops;
80871 };
80872 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
80873
80874 /*
80875 * The PM_EVENT_ messages are also used by drivers implementing the legacy
80876 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
80877 index 7c1d252..0e7061d 100644
80878 --- a/include/linux/pm_domain.h
80879 +++ b/include/linux/pm_domain.h
80880 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
80881 int (*thaw_early)(struct device *dev);
80882 int (*thaw)(struct device *dev);
80883 bool (*active_wakeup)(struct device *dev);
80884 -};
80885 +} __no_const;
80886
80887 struct gpd_cpu_data {
80888 unsigned int saved_exit_latency;
80889 - struct cpuidle_state *idle_state;
80890 + cpuidle_state_no_const *idle_state;
80891 };
80892
80893 struct generic_pm_domain {
80894 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
80895 index 6fa7cea..7bf6415 100644
80896 --- a/include/linux/pm_runtime.h
80897 +++ b/include/linux/pm_runtime.h
80898 @@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
80899
80900 static inline void pm_runtime_mark_last_busy(struct device *dev)
80901 {
80902 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
80903 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
80904 }
80905
80906 #else /* !CONFIG_PM_RUNTIME */
80907 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
80908 index 195aafc..49a7bc2 100644
80909 --- a/include/linux/pnp.h
80910 +++ b/include/linux/pnp.h
80911 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
80912 struct pnp_fixup {
80913 char id[7];
80914 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
80915 -};
80916 +} __do_const;
80917
80918 /* config parameters */
80919 #define PNP_CONFIG_NORMAL 0x0001
80920 diff --git a/include/linux/poison.h b/include/linux/poison.h
80921 index 2110a81..13a11bb 100644
80922 --- a/include/linux/poison.h
80923 +++ b/include/linux/poison.h
80924 @@ -19,8 +19,8 @@
80925 * under normal circumstances, used to verify that nobody uses
80926 * non-initialized list entries.
80927 */
80928 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
80929 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80930 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
80931 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
80932
80933 /********** include/linux/timer.h **********/
80934 /*
80935 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
80936 index d8b187c3..9a9257a 100644
80937 --- a/include/linux/power/smartreflex.h
80938 +++ b/include/linux/power/smartreflex.h
80939 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
80940 int (*notify)(struct omap_sr *sr, u32 status);
80941 u8 notify_flags;
80942 u8 class_type;
80943 -};
80944 +} __do_const;
80945
80946 /**
80947 * struct omap_sr_nvalue_table - Smartreflex n-target value info
80948 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
80949 index 4ea1d37..80f4b33 100644
80950 --- a/include/linux/ppp-comp.h
80951 +++ b/include/linux/ppp-comp.h
80952 @@ -84,7 +84,7 @@ struct compressor {
80953 struct module *owner;
80954 /* Extra skb space needed by the compressor algorithm */
80955 unsigned int comp_extra;
80956 -};
80957 +} __do_const;
80958
80959 /*
80960 * The return value from decompress routine is the length of the
80961 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
80962 index a3d9dc8..8af9922 100644
80963 --- a/include/linux/preempt.h
80964 +++ b/include/linux/preempt.h
80965 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
80966 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
80967 #endif
80968
80969 +#define raw_preempt_count_add(val) __preempt_count_add(val)
80970 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
80971 +
80972 #define __preempt_count_inc() __preempt_count_add(1)
80973 #define __preempt_count_dec() __preempt_count_sub(1)
80974
80975 #define preempt_count_inc() preempt_count_add(1)
80976 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
80977 #define preempt_count_dec() preempt_count_sub(1)
80978 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
80979
80980 #ifdef CONFIG_PREEMPT_COUNT
80981
80982 @@ -41,6 +46,12 @@ do { \
80983 barrier(); \
80984 } while (0)
80985
80986 +#define raw_preempt_disable() \
80987 +do { \
80988 + raw_preempt_count_inc(); \
80989 + barrier(); \
80990 +} while (0)
80991 +
80992 #define sched_preempt_enable_no_resched() \
80993 do { \
80994 barrier(); \
80995 @@ -49,6 +60,12 @@ do { \
80996
80997 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
80998
80999 +#define raw_preempt_enable_no_resched() \
81000 +do { \
81001 + barrier(); \
81002 + raw_preempt_count_dec(); \
81003 +} while (0)
81004 +
81005 #ifdef CONFIG_PREEMPT
81006 #define preempt_enable() \
81007 do { \
81008 @@ -105,8 +122,10 @@ do { \
81009 * region.
81010 */
81011 #define preempt_disable() barrier()
81012 +#define raw_preempt_disable() barrier()
81013 #define sched_preempt_enable_no_resched() barrier()
81014 #define preempt_enable_no_resched() barrier()
81015 +#define raw_preempt_enable_no_resched() barrier()
81016 #define preempt_enable() barrier()
81017 #define preempt_check_resched() do { } while (0)
81018
81019 diff --git a/include/linux/printk.h b/include/linux/printk.h
81020 index 6949258..7c4730e 100644
81021 --- a/include/linux/printk.h
81022 +++ b/include/linux/printk.h
81023 @@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
81024 void early_printk(const char *s, ...) { }
81025 #endif
81026
81027 +extern int kptr_restrict;
81028 +
81029 #ifdef CONFIG_PRINTK
81030 asmlinkage __printf(5, 0)
81031 int vprintk_emit(int facility, int level,
81032 @@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81033
81034 extern int printk_delay_msec;
81035 extern int dmesg_restrict;
81036 -extern int kptr_restrict;
81037
81038 extern void wake_up_klogd(void);
81039
81040 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81041 index 608e60a..c26f864 100644
81042 --- a/include/linux/proc_fs.h
81043 +++ b/include/linux/proc_fs.h
81044 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
81045 return proc_create_data(name, mode, parent, proc_fops, NULL);
81046 }
81047
81048 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81049 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81050 +{
81051 +#ifdef CONFIG_GRKERNSEC_PROC_USER
81052 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81053 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81054 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81055 +#else
81056 + return proc_create_data(name, mode, parent, proc_fops, NULL);
81057 +#endif
81058 +}
81059 +
81060 +
81061 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81062 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81063 extern void *PDE_DATA(const struct inode *);
81064 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81065 index 34a1e10..70f6bde 100644
81066 --- a/include/linux/proc_ns.h
81067 +++ b/include/linux/proc_ns.h
81068 @@ -14,7 +14,7 @@ struct proc_ns_operations {
81069 void (*put)(void *ns);
81070 int (*install)(struct nsproxy *nsproxy, void *ns);
81071 unsigned int (*inum)(void *ns);
81072 -};
81073 +} __do_const __randomize_layout;
81074
81075 struct proc_ns {
81076 void *ns;
81077 diff --git a/include/linux/quota.h b/include/linux/quota.h
81078 index cc7494a..1e27036 100644
81079 --- a/include/linux/quota.h
81080 +++ b/include/linux/quota.h
81081 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81082
81083 extern bool qid_eq(struct kqid left, struct kqid right);
81084 extern bool qid_lt(struct kqid left, struct kqid right);
81085 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81086 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81087 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81088 extern bool qid_valid(struct kqid qid);
81089
81090 diff --git a/include/linux/random.h b/include/linux/random.h
81091 index 4002b3d..d5ad855 100644
81092 --- a/include/linux/random.h
81093 +++ b/include/linux/random.h
81094 @@ -10,9 +10,19 @@
81095
81096
81097 extern void add_device_randomness(const void *, unsigned int);
81098 +
81099 +static inline void add_latent_entropy(void)
81100 +{
81101 +
81102 +#ifdef LATENT_ENTROPY_PLUGIN
81103 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81104 +#endif
81105 +
81106 +}
81107 +
81108 extern void add_input_randomness(unsigned int type, unsigned int code,
81109 - unsigned int value);
81110 -extern void add_interrupt_randomness(int irq, int irq_flags);
81111 + unsigned int value) __latent_entropy;
81112 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81113
81114 extern void get_random_bytes(void *buf, int nbytes);
81115 extern void get_random_bytes_arch(void *buf, int nbytes);
81116 @@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
81117 extern const struct file_operations random_fops, urandom_fops;
81118 #endif
81119
81120 -unsigned int get_random_int(void);
81121 +unsigned int __intentional_overflow(-1) get_random_int(void);
81122 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81123
81124 -u32 prandom_u32(void);
81125 +u32 prandom_u32(void) __intentional_overflow(-1);
81126 void prandom_bytes(void *buf, int nbytes);
81127 void prandom_seed(u32 seed);
81128 void prandom_reseed_late(void);
81129 @@ -38,6 +48,11 @@ struct rnd_state {
81130 u32 prandom_u32_state(struct rnd_state *state);
81131 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81132
81133 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81134 +{
81135 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81136 +}
81137 +
81138 /*
81139 * Handle minimum values for seeds
81140 */
81141 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81142 index fea49b5..2ac22bb 100644
81143 --- a/include/linux/rbtree_augmented.h
81144 +++ b/include/linux/rbtree_augmented.h
81145 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81146 old->rbaugmented = rbcompute(old); \
81147 } \
81148 rbstatic const struct rb_augment_callbacks rbname = { \
81149 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81150 + .propagate = rbname ## _propagate, \
81151 + .copy = rbname ## _copy, \
81152 + .rotate = rbname ## _rotate \
81153 };
81154
81155
81156 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81157 index 45a0a9e..e83788e 100644
81158 --- a/include/linux/rculist.h
81159 +++ b/include/linux/rculist.h
81160 @@ -29,8 +29,8 @@
81161 */
81162 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81163 {
81164 - ACCESS_ONCE(list->next) = list;
81165 - ACCESS_ONCE(list->prev) = list;
81166 + ACCESS_ONCE_RW(list->next) = list;
81167 + ACCESS_ONCE_RW(list->prev) = list;
81168 }
81169
81170 /*
81171 @@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
81172 struct list_head *prev, struct list_head *next);
81173 #endif
81174
81175 +extern void __pax_list_add_rcu(struct list_head *new,
81176 + struct list_head *prev, struct list_head *next);
81177 +
81178 /**
81179 * list_add_rcu - add a new entry to rcu-protected list
81180 * @new: new entry to be added
81181 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81182 __list_add_rcu(new, head, head->next);
81183 }
81184
81185 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81186 +{
81187 + __pax_list_add_rcu(new, head, head->next);
81188 +}
81189 +
81190 /**
81191 * list_add_tail_rcu - add a new entry to rcu-protected list
81192 * @new: new entry to be added
81193 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81194 __list_add_rcu(new, head->prev, head);
81195 }
81196
81197 +static inline void pax_list_add_tail_rcu(struct list_head *new,
81198 + struct list_head *head)
81199 +{
81200 + __pax_list_add_rcu(new, head->prev, head);
81201 +}
81202 +
81203 /**
81204 * list_del_rcu - deletes entry from list without re-initialization
81205 * @entry: the element to delete from the list.
81206 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81207 entry->prev = LIST_POISON2;
81208 }
81209
81210 +extern void pax_list_del_rcu(struct list_head *entry);
81211 +
81212 /**
81213 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81214 * @n: the element to delete from the hash list.
81215 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81216 index 9e7db9e..7d4fd72 100644
81217 --- a/include/linux/reboot.h
81218 +++ b/include/linux/reboot.h
81219 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81220 */
81221
81222 extern void migrate_to_reboot_cpu(void);
81223 -extern void machine_restart(char *cmd);
81224 -extern void machine_halt(void);
81225 -extern void machine_power_off(void);
81226 +extern void machine_restart(char *cmd) __noreturn;
81227 +extern void machine_halt(void) __noreturn;
81228 +extern void machine_power_off(void) __noreturn;
81229
81230 extern void machine_shutdown(void);
81231 struct pt_regs;
81232 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81233 */
81234
81235 extern void kernel_restart_prepare(char *cmd);
81236 -extern void kernel_restart(char *cmd);
81237 -extern void kernel_halt(void);
81238 -extern void kernel_power_off(void);
81239 +extern void kernel_restart(char *cmd) __noreturn;
81240 +extern void kernel_halt(void) __noreturn;
81241 +extern void kernel_power_off(void) __noreturn;
81242
81243 extern int C_A_D; /* for sysctl */
81244 void ctrl_alt_del(void);
81245 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81246 * Emergency restart, callable from an interrupt handler.
81247 */
81248
81249 -extern void emergency_restart(void);
81250 +extern void emergency_restart(void) __noreturn;
81251 #include <asm/emergency-restart.h>
81252
81253 #endif /* _LINUX_REBOOT_H */
81254 diff --git a/include/linux/regset.h b/include/linux/regset.h
81255 index 8e0c9fe..ac4d221 100644
81256 --- a/include/linux/regset.h
81257 +++ b/include/linux/regset.h
81258 @@ -161,7 +161,8 @@ struct user_regset {
81259 unsigned int align;
81260 unsigned int bias;
81261 unsigned int core_note_type;
81262 -};
81263 +} __do_const;
81264 +typedef struct user_regset __no_const user_regset_no_const;
81265
81266 /**
81267 * struct user_regset_view - available regsets
81268 diff --git a/include/linux/relay.h b/include/linux/relay.h
81269 index d7c8359..818daf5 100644
81270 --- a/include/linux/relay.h
81271 +++ b/include/linux/relay.h
81272 @@ -157,7 +157,7 @@ struct rchan_callbacks
81273 * The callback should return 0 if successful, negative if not.
81274 */
81275 int (*remove_buf_file)(struct dentry *dentry);
81276 -};
81277 +} __no_const;
81278
81279 /*
81280 * CONFIG_RELAY kernel API, kernel/relay.c
81281 diff --git a/include/linux/rio.h b/include/linux/rio.h
81282 index b71d573..2f940bd 100644
81283 --- a/include/linux/rio.h
81284 +++ b/include/linux/rio.h
81285 @@ -355,7 +355,7 @@ struct rio_ops {
81286 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81287 u64 rstart, u32 size, u32 flags);
81288 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81289 -};
81290 +} __no_const;
81291
81292 #define RIO_RESOURCE_MEM 0x00000100
81293 #define RIO_RESOURCE_DOORBELL 0x00000200
81294 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81295 index 6dacb93..6174423 100644
81296 --- a/include/linux/rmap.h
81297 +++ b/include/linux/rmap.h
81298 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81299 void anon_vma_init(void); /* create anon_vma_cachep */
81300 int anon_vma_prepare(struct vm_area_struct *);
81301 void unlink_anon_vmas(struct vm_area_struct *);
81302 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81303 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81304 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81305 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81306
81307 static inline void anon_vma_merge(struct vm_area_struct *vma,
81308 struct vm_area_struct *next)
81309 diff --git a/include/linux/sched.h b/include/linux/sched.h
81310 index 53f97eb..1d90705 100644
81311 --- a/include/linux/sched.h
81312 +++ b/include/linux/sched.h
81313 @@ -63,6 +63,7 @@ struct bio_list;
81314 struct fs_struct;
81315 struct perf_event_context;
81316 struct blk_plug;
81317 +struct linux_binprm;
81318
81319 /*
81320 * List of flags we want to share for kernel threads,
81321 @@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
81322 extern int in_sched_functions(unsigned long addr);
81323
81324 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81325 -extern signed long schedule_timeout(signed long timeout);
81326 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81327 extern signed long schedule_timeout_interruptible(signed long timeout);
81328 extern signed long schedule_timeout_killable(signed long timeout);
81329 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81330 @@ -315,6 +316,19 @@ struct nsproxy;
81331 struct user_namespace;
81332
81333 #ifdef CONFIG_MMU
81334 +
81335 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81336 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81337 +#else
81338 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81339 +{
81340 + return 0;
81341 +}
81342 +#endif
81343 +
81344 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81345 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81346 +
81347 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81348 extern unsigned long
81349 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81350 @@ -600,6 +614,17 @@ struct signal_struct {
81351 #ifdef CONFIG_TASKSTATS
81352 struct taskstats *stats;
81353 #endif
81354 +
81355 +#ifdef CONFIG_GRKERNSEC
81356 + u32 curr_ip;
81357 + u32 saved_ip;
81358 + u32 gr_saddr;
81359 + u32 gr_daddr;
81360 + u16 gr_sport;
81361 + u16 gr_dport;
81362 + u8 used_accept:1;
81363 +#endif
81364 +
81365 #ifdef CONFIG_AUDIT
81366 unsigned audit_tty;
81367 unsigned audit_tty_log_passwd;
81368 @@ -626,7 +651,7 @@ struct signal_struct {
81369 struct mutex cred_guard_mutex; /* guard against foreign influences on
81370 * credential calculations
81371 * (notably. ptrace) */
81372 -};
81373 +} __randomize_layout;
81374
81375 /*
81376 * Bits in flags field of signal_struct.
81377 @@ -680,6 +705,14 @@ struct user_struct {
81378 struct key *session_keyring; /* UID's default session keyring */
81379 #endif
81380
81381 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81382 + unsigned char kernel_banned;
81383 +#endif
81384 +#ifdef CONFIG_GRKERNSEC_BRUTE
81385 + unsigned char suid_banned;
81386 + unsigned long suid_ban_expires;
81387 +#endif
81388 +
81389 /* Hash table maintenance information */
81390 struct hlist_node uidhash_node;
81391 kuid_t uid;
81392 @@ -687,7 +720,7 @@ struct user_struct {
81393 #ifdef CONFIG_PERF_EVENTS
81394 atomic_long_t locked_vm;
81395 #endif
81396 -};
81397 +} __randomize_layout;
81398
81399 extern int uids_sysfs_init(void);
81400
81401 @@ -1162,8 +1195,8 @@ struct task_struct {
81402 struct list_head thread_group;
81403
81404 struct completion *vfork_done; /* for vfork() */
81405 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81406 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81407 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81408 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81409
81410 cputime_t utime, stime, utimescaled, stimescaled;
81411 cputime_t gtime;
81412 @@ -1188,11 +1221,6 @@ struct task_struct {
81413 struct task_cputime cputime_expires;
81414 struct list_head cpu_timers[3];
81415
81416 -/* process credentials */
81417 - const struct cred __rcu *real_cred; /* objective and real subjective task
81418 - * credentials (COW) */
81419 - const struct cred __rcu *cred; /* effective (overridable) subjective task
81420 - * credentials (COW) */
81421 char comm[TASK_COMM_LEN]; /* executable name excluding path
81422 - access with [gs]et_task_comm (which lock
81423 it with task_lock())
81424 @@ -1209,6 +1237,10 @@ struct task_struct {
81425 #endif
81426 /* CPU-specific state of this task */
81427 struct thread_struct thread;
81428 +/* thread_info moved to task_struct */
81429 +#ifdef CONFIG_X86
81430 + struct thread_info tinfo;
81431 +#endif
81432 /* filesystem information */
81433 struct fs_struct *fs;
81434 /* open file information */
81435 @@ -1282,6 +1314,10 @@ struct task_struct {
81436 gfp_t lockdep_reclaim_gfp;
81437 #endif
81438
81439 +/* process credentials */
81440 + const struct cred __rcu *real_cred; /* objective and real subjective task
81441 + * credentials (COW) */
81442 +
81443 /* journalling filesystem info */
81444 void *journal_info;
81445
81446 @@ -1320,6 +1356,10 @@ struct task_struct {
81447 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81448 struct list_head cg_list;
81449 #endif
81450 +
81451 + const struct cred __rcu *cred; /* effective (overridable) subjective task
81452 + * credentials (COW) */
81453 +
81454 #ifdef CONFIG_FUTEX
81455 struct robust_list_head __user *robust_list;
81456 #ifdef CONFIG_COMPAT
81457 @@ -1454,7 +1494,78 @@ struct task_struct {
81458 unsigned int sequential_io;
81459 unsigned int sequential_io_avg;
81460 #endif
81461 -};
81462 +
81463 +#ifdef CONFIG_GRKERNSEC
81464 + /* grsecurity */
81465 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81466 + u64 exec_id;
81467 +#endif
81468 +#ifdef CONFIG_GRKERNSEC_SETXID
81469 + const struct cred *delayed_cred;
81470 +#endif
81471 + struct dentry *gr_chroot_dentry;
81472 + struct acl_subject_label *acl;
81473 + struct acl_subject_label *tmpacl;
81474 + struct acl_role_label *role;
81475 + struct file *exec_file;
81476 + unsigned long brute_expires;
81477 + u16 acl_role_id;
81478 + u8 inherited;
81479 + /* is this the task that authenticated to the special role */
81480 + u8 acl_sp_role;
81481 + u8 is_writable;
81482 + u8 brute;
81483 + u8 gr_is_chrooted;
81484 +#endif
81485 +
81486 +} __randomize_layout;
81487 +
81488 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81489 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81490 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81491 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81492 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81493 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81494 +
81495 +#ifdef CONFIG_PAX_SOFTMODE
81496 +extern int pax_softmode;
81497 +#endif
81498 +
81499 +extern int pax_check_flags(unsigned long *);
81500 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81501 +
81502 +/* if tsk != current then task_lock must be held on it */
81503 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81504 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
81505 +{
81506 + if (likely(tsk->mm))
81507 + return tsk->mm->pax_flags;
81508 + else
81509 + return 0UL;
81510 +}
81511 +
81512 +/* if tsk != current then task_lock must be held on it */
81513 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81514 +{
81515 + if (likely(tsk->mm)) {
81516 + tsk->mm->pax_flags = flags;
81517 + return 0;
81518 + }
81519 + return -EINVAL;
81520 +}
81521 +#endif
81522 +
81523 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81524 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
81525 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81526 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81527 +#endif
81528 +
81529 +struct path;
81530 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81531 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81532 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81533 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
81534
81535 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81536 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81537 @@ -1531,7 +1642,7 @@ struct pid_namespace;
81538 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81539 struct pid_namespace *ns);
81540
81541 -static inline pid_t task_pid_nr(struct task_struct *tsk)
81542 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
81543 {
81544 return tsk->pid;
81545 }
81546 @@ -1981,7 +2092,9 @@ void yield(void);
81547 extern struct exec_domain default_exec_domain;
81548
81549 union thread_union {
81550 +#ifndef CONFIG_X86
81551 struct thread_info thread_info;
81552 +#endif
81553 unsigned long stack[THREAD_SIZE/sizeof(long)];
81554 };
81555
81556 @@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
81557 */
81558
81559 extern struct task_struct *find_task_by_vpid(pid_t nr);
81560 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81561 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81562 struct pid_namespace *ns);
81563
81564 @@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81565 extern void exit_itimers(struct signal_struct *);
81566 extern void flush_itimer_signals(void);
81567
81568 -extern void do_group_exit(int);
81569 +extern __noreturn void do_group_exit(int);
81570
81571 extern int allow_signal(int);
81572 extern int disallow_signal(int);
81573 @@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81574
81575 #endif
81576
81577 -static inline int object_is_on_stack(void *obj)
81578 +static inline int object_starts_on_stack(void *obj)
81579 {
81580 - void *stack = task_stack_page(current);
81581 + const void *stack = task_stack_page(current);
81582
81583 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81584 }
81585 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81586 index e3347c5..f682891 100644
81587 --- a/include/linux/sched/sysctl.h
81588 +++ b/include/linux/sched/sysctl.h
81589 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81590 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81591
81592 extern int sysctl_max_map_count;
81593 +extern unsigned long sysctl_heap_stack_gap;
81594
81595 extern unsigned int sysctl_sched_latency;
81596 extern unsigned int sysctl_sched_min_granularity;
81597 diff --git a/include/linux/security.h b/include/linux/security.h
81598 index 5623a7f..7ae77be 100644
81599 --- a/include/linux/security.h
81600 +++ b/include/linux/security.h
81601 @@ -27,6 +27,7 @@
81602 #include <linux/slab.h>
81603 #include <linux/err.h>
81604 #include <linux/string.h>
81605 +#include <linux/grsecurity.h>
81606
81607 struct linux_binprm;
81608 struct cred;
81609 @@ -116,8 +117,6 @@ struct seq_file;
81610
81611 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81612
81613 -void reset_security_ops(void);
81614 -
81615 #ifdef CONFIG_MMU
81616 extern unsigned long mmap_min_addr;
81617 extern unsigned long dac_mmap_min_addr;
81618 @@ -1718,7 +1717,7 @@ struct security_operations {
81619 struct audit_context *actx);
81620 void (*audit_rule_free) (void *lsmrule);
81621 #endif /* CONFIG_AUDIT */
81622 -};
81623 +} __randomize_layout;
81624
81625 /* prototypes */
81626 extern int security_init(void);
81627 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81628 index dc368b8..e895209 100644
81629 --- a/include/linux/semaphore.h
81630 +++ b/include/linux/semaphore.h
81631 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81632 }
81633
81634 extern void down(struct semaphore *sem);
81635 -extern int __must_check down_interruptible(struct semaphore *sem);
81636 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81637 extern int __must_check down_killable(struct semaphore *sem);
81638 extern int __must_check down_trylock(struct semaphore *sem);
81639 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81640 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81641 index 52e0097..09625ef 100644
81642 --- a/include/linux/seq_file.h
81643 +++ b/include/linux/seq_file.h
81644 @@ -27,6 +27,9 @@ struct seq_file {
81645 struct mutex lock;
81646 const struct seq_operations *op;
81647 int poll_event;
81648 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81649 + u64 exec_id;
81650 +#endif
81651 #ifdef CONFIG_USER_NS
81652 struct user_namespace *user_ns;
81653 #endif
81654 @@ -39,6 +42,7 @@ struct seq_operations {
81655 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81656 int (*show) (struct seq_file *m, void *v);
81657 };
81658 +typedef struct seq_operations __no_const seq_operations_no_const;
81659
81660 #define SEQ_SKIP 1
81661
81662 diff --git a/include/linux/shm.h b/include/linux/shm.h
81663 index 429c199..4d42e38 100644
81664 --- a/include/linux/shm.h
81665 +++ b/include/linux/shm.h
81666 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81667
81668 /* The task created the shm object. NULL if the task is dead. */
81669 struct task_struct *shm_creator;
81670 +#ifdef CONFIG_GRKERNSEC
81671 + time_t shm_createtime;
81672 + pid_t shm_lapid;
81673 +#endif
81674 };
81675
81676 /* shm_mode upper byte flags */
81677 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81678 index 37cb679..dbaebc0 100644
81679 --- a/include/linux/skbuff.h
81680 +++ b/include/linux/skbuff.h
81681 @@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81682 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81683 int node);
81684 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81685 -static inline struct sk_buff *alloc_skb(unsigned int size,
81686 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81687 gfp_t priority)
81688 {
81689 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81690 @@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
81691 */
81692 static inline int skb_queue_empty(const struct sk_buff_head *list)
81693 {
81694 - return list->next == (struct sk_buff *)list;
81695 + return list->next == (const struct sk_buff *)list;
81696 }
81697
81698 /**
81699 @@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
81700 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81701 const struct sk_buff *skb)
81702 {
81703 - return skb->next == (struct sk_buff *)list;
81704 + return skb->next == (const struct sk_buff *)list;
81705 }
81706
81707 /**
81708 @@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81709 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
81710 const struct sk_buff *skb)
81711 {
81712 - return skb->prev == (struct sk_buff *)list;
81713 + return skb->prev == (const struct sk_buff *)list;
81714 }
81715
81716 /**
81717 @@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81718 return skb->inner_transport_header - skb->inner_network_header;
81719 }
81720
81721 -static inline int skb_network_offset(const struct sk_buff *skb)
81722 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81723 {
81724 return skb_network_header(skb) - skb->data;
81725 }
81726 @@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81727 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81728 */
81729 #ifndef NET_SKB_PAD
81730 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81731 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81732 #endif
81733
81734 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81735 @@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81736 int *err);
81737 unsigned int datagram_poll(struct file *file, struct socket *sock,
81738 struct poll_table_struct *wait);
81739 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81740 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81741 struct iovec *to, int size);
81742 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81743 struct iovec *iov);
81744 @@ -2618,6 +2618,9 @@ static inline void nf_reset(struct sk_buff *skb)
81745 nf_bridge_put(skb->nf_bridge);
81746 skb->nf_bridge = NULL;
81747 #endif
81748 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81749 + skb->nf_trace = 0;
81750 +#endif
81751 }
81752
81753 static inline void nf_reset_trace(struct sk_buff *skb)
81754 diff --git a/include/linux/slab.h b/include/linux/slab.h
81755 index 1e2f4fe..df49ca6 100644
81756 --- a/include/linux/slab.h
81757 +++ b/include/linux/slab.h
81758 @@ -14,15 +14,29 @@
81759 #include <linux/gfp.h>
81760 #include <linux/types.h>
81761 #include <linux/workqueue.h>
81762 -
81763 +#include <linux/err.h>
81764
81765 /*
81766 * Flags to pass to kmem_cache_create().
81767 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81768 */
81769 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81770 +
81771 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81772 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81773 +#else
81774 +#define SLAB_USERCOPY 0x00000000UL
81775 +#endif
81776 +
81777 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81778 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81779 +
81780 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81781 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81782 +#else
81783 +#define SLAB_NO_SANITIZE 0x00000000UL
81784 +#endif
81785 +
81786 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81787 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81788 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81789 @@ -98,10 +112,13 @@
81790 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81791 * Both make kfree a no-op.
81792 */
81793 -#define ZERO_SIZE_PTR ((void *)16)
81794 +#define ZERO_SIZE_PTR \
81795 +({ \
81796 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81797 + (void *)(-MAX_ERRNO-1L); \
81798 +})
81799
81800 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81801 - (unsigned long)ZERO_SIZE_PTR)
81802 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81803
81804 #include <linux/kmemleak.h>
81805
81806 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81807 void kfree(const void *);
81808 void kzfree(const void *);
81809 size_t ksize(const void *);
81810 +const char *check_heap_object(const void *ptr, unsigned long n);
81811 +bool is_usercopy_object(const void *ptr);
81812
81813 /*
81814 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81815 @@ -174,7 +193,7 @@ struct kmem_cache {
81816 unsigned int align; /* Alignment as calculated */
81817 unsigned long flags; /* Active flags on the slab */
81818 const char *name; /* Slab name for sysfs */
81819 - int refcount; /* Use counter */
81820 + atomic_t refcount; /* Use counter */
81821 void (*ctor)(void *); /* Called on object slot creation */
81822 struct list_head list; /* List of all slab caches on the system */
81823 };
81824 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81825 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81826 #endif
81827
81828 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81829 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
81830 +#endif
81831 +
81832 /*
81833 * Figure out which kmalloc slab an allocation of a certain size
81834 * belongs to.
81835 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81836 * 2 = 120 .. 192 bytes
81837 * n = 2^(n-1) .. 2^n -1
81838 */
81839 -static __always_inline int kmalloc_index(size_t size)
81840 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
81841 {
81842 if (!size)
81843 return 0;
81844 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
81845 }
81846 #endif /* !CONFIG_SLOB */
81847
81848 -void *__kmalloc(size_t size, gfp_t flags);
81849 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
81850 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
81851
81852 #ifdef CONFIG_NUMA
81853 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
81854 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
81855 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
81856 #else
81857 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
81858 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
81859 index 09bfffb..4fc80fb 100644
81860 --- a/include/linux/slab_def.h
81861 +++ b/include/linux/slab_def.h
81862 @@ -36,7 +36,7 @@ struct kmem_cache {
81863 /* 4) cache creation/removal */
81864 const char *name;
81865 struct list_head list;
81866 - int refcount;
81867 + atomic_t refcount;
81868 int object_size;
81869 int align;
81870
81871 @@ -52,10 +52,14 @@ struct kmem_cache {
81872 unsigned long node_allocs;
81873 unsigned long node_frees;
81874 unsigned long node_overflow;
81875 - atomic_t allochit;
81876 - atomic_t allocmiss;
81877 - atomic_t freehit;
81878 - atomic_t freemiss;
81879 + atomic_unchecked_t allochit;
81880 + atomic_unchecked_t allocmiss;
81881 + atomic_unchecked_t freehit;
81882 + atomic_unchecked_t freemiss;
81883 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81884 + atomic_unchecked_t sanitized;
81885 + atomic_unchecked_t not_sanitized;
81886 +#endif
81887
81888 /*
81889 * If debugging is enabled, then the allocator can add additional
81890 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
81891 index f56bfa9..8378a26 100644
81892 --- a/include/linux/slub_def.h
81893 +++ b/include/linux/slub_def.h
81894 @@ -74,7 +74,7 @@ struct kmem_cache {
81895 struct kmem_cache_order_objects max;
81896 struct kmem_cache_order_objects min;
81897 gfp_t allocflags; /* gfp flags to use on each alloc */
81898 - int refcount; /* Refcount for slab cache destroy */
81899 + atomic_t refcount; /* Refcount for slab cache destroy */
81900 void (*ctor)(void *);
81901 int inuse; /* Offset to metadata */
81902 int align; /* Alignment */
81903 diff --git a/include/linux/smp.h b/include/linux/smp.h
81904 index 5da22ee..71d8a28 100644
81905 --- a/include/linux/smp.h
81906 +++ b/include/linux/smp.h
81907 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
81908 #endif
81909
81910 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
81911 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
81912 #define put_cpu() preempt_enable()
81913 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
81914
81915 /*
81916 * Callback to arch code if there's nosmp or maxcpus=0 on the
81917 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
81918 index 54f91d3..be2c379 100644
81919 --- a/include/linux/sock_diag.h
81920 +++ b/include/linux/sock_diag.h
81921 @@ -11,7 +11,7 @@ struct sock;
81922 struct sock_diag_handler {
81923 __u8 family;
81924 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
81925 -};
81926 +} __do_const;
81927
81928 int sock_diag_register(const struct sock_diag_handler *h);
81929 void sock_diag_unregister(const struct sock_diag_handler *h);
81930 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
81931 index 680f9a3..f13aeb0 100644
81932 --- a/include/linux/sonet.h
81933 +++ b/include/linux/sonet.h
81934 @@ -7,7 +7,7 @@
81935 #include <uapi/linux/sonet.h>
81936
81937 struct k_sonet_stats {
81938 -#define __HANDLE_ITEM(i) atomic_t i
81939 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
81940 __SONET_ITEMS
81941 #undef __HANDLE_ITEM
81942 };
81943 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
81944 index 07d8e53..dc934c9 100644
81945 --- a/include/linux/sunrpc/addr.h
81946 +++ b/include/linux/sunrpc/addr.h
81947 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
81948 {
81949 switch (sap->sa_family) {
81950 case AF_INET:
81951 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
81952 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
81953 case AF_INET6:
81954 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
81955 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
81956 }
81957 return 0;
81958 }
81959 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
81960 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
81961 const struct sockaddr *src)
81962 {
81963 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
81964 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
81965 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
81966
81967 dsin->sin_family = ssin->sin_family;
81968 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
81969 if (sa->sa_family != AF_INET6)
81970 return 0;
81971
81972 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
81973 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
81974 }
81975
81976 #endif /* _LINUX_SUNRPC_ADDR_H */
81977 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
81978 index 8af2804..c7414ef 100644
81979 --- a/include/linux/sunrpc/clnt.h
81980 +++ b/include/linux/sunrpc/clnt.h
81981 @@ -97,7 +97,7 @@ struct rpc_procinfo {
81982 unsigned int p_timer; /* Which RTT timer to use */
81983 u32 p_statidx; /* Which procedure to account */
81984 const char * p_name; /* name of procedure */
81985 -};
81986 +} __do_const;
81987
81988 #ifdef __KERNEL__
81989
81990 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
81991 index 6eecfc2..7ada79d 100644
81992 --- a/include/linux/sunrpc/svc.h
81993 +++ b/include/linux/sunrpc/svc.h
81994 @@ -410,7 +410,7 @@ struct svc_procedure {
81995 unsigned int pc_count; /* call count */
81996 unsigned int pc_cachetype; /* cache info (NFS) */
81997 unsigned int pc_xdrressize; /* maximum size of XDR reply */
81998 -};
81999 +} __do_const;
82000
82001 /*
82002 * Function prototypes.
82003 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82004 index 0b8e3e6..33e0a01 100644
82005 --- a/include/linux/sunrpc/svc_rdma.h
82006 +++ b/include/linux/sunrpc/svc_rdma.h
82007 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82008 extern unsigned int svcrdma_max_requests;
82009 extern unsigned int svcrdma_max_req_size;
82010
82011 -extern atomic_t rdma_stat_recv;
82012 -extern atomic_t rdma_stat_read;
82013 -extern atomic_t rdma_stat_write;
82014 -extern atomic_t rdma_stat_sq_starve;
82015 -extern atomic_t rdma_stat_rq_starve;
82016 -extern atomic_t rdma_stat_rq_poll;
82017 -extern atomic_t rdma_stat_rq_prod;
82018 -extern atomic_t rdma_stat_sq_poll;
82019 -extern atomic_t rdma_stat_sq_prod;
82020 +extern atomic_unchecked_t rdma_stat_recv;
82021 +extern atomic_unchecked_t rdma_stat_read;
82022 +extern atomic_unchecked_t rdma_stat_write;
82023 +extern atomic_unchecked_t rdma_stat_sq_starve;
82024 +extern atomic_unchecked_t rdma_stat_rq_starve;
82025 +extern atomic_unchecked_t rdma_stat_rq_poll;
82026 +extern atomic_unchecked_t rdma_stat_rq_prod;
82027 +extern atomic_unchecked_t rdma_stat_sq_poll;
82028 +extern atomic_unchecked_t rdma_stat_sq_prod;
82029
82030 #define RPCRDMA_VERSION 1
82031
82032 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82033 index 8d71d65..f79586e 100644
82034 --- a/include/linux/sunrpc/svcauth.h
82035 +++ b/include/linux/sunrpc/svcauth.h
82036 @@ -120,7 +120,7 @@ struct auth_ops {
82037 int (*release)(struct svc_rqst *rq);
82038 void (*domain_release)(struct auth_domain *);
82039 int (*set_client)(struct svc_rqst *rq);
82040 -};
82041 +} __do_const;
82042
82043 #define SVC_GARBAGE 1
82044 #define SVC_SYSERR 2
82045 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82046 index a5ffd32..0935dea 100644
82047 --- a/include/linux/swiotlb.h
82048 +++ b/include/linux/swiotlb.h
82049 @@ -60,7 +60,8 @@ extern void
82050
82051 extern void
82052 swiotlb_free_coherent(struct device *hwdev, size_t size,
82053 - void *vaddr, dma_addr_t dma_handle);
82054 + void *vaddr, dma_addr_t dma_handle,
82055 + struct dma_attrs *attrs);
82056
82057 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82058 unsigned long offset, size_t size,
82059 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82060 index 94273bb..c2e05fc 100644
82061 --- a/include/linux/syscalls.h
82062 +++ b/include/linux/syscalls.h
82063 @@ -97,8 +97,14 @@ struct sigaltstack;
82064 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82065
82066 #define __SC_DECL(t, a) t a
82067 +#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))
82068 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82069 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82070 +#define __SC_LONG(t, a) __typeof( \
82071 + __builtin_choose_expr( \
82072 + sizeof(t) > sizeof(int), \
82073 + (t) 0, \
82074 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82075 + )) a
82076 #define __SC_CAST(t, a) (t) a
82077 #define __SC_ARGS(t, a) a
82078 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82079 @@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
82080 asmlinkage long sys_fsync(unsigned int fd);
82081 asmlinkage long sys_fdatasync(unsigned int fd);
82082 asmlinkage long sys_bdflush(int func, long data);
82083 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82084 - char __user *type, unsigned long flags,
82085 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82086 + const char __user *type, unsigned long flags,
82087 void __user *data);
82088 -asmlinkage long sys_umount(char __user *name, int flags);
82089 -asmlinkage long sys_oldumount(char __user *name);
82090 +asmlinkage long sys_umount(const char __user *name, int flags);
82091 +asmlinkage long sys_oldumount(const char __user *name);
82092 asmlinkage long sys_truncate(const char __user *path, long length);
82093 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82094 asmlinkage long sys_stat(const char __user *filename,
82095 @@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82096 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82097 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82098 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82099 - struct sockaddr __user *, int);
82100 + struct sockaddr __user *, int) __intentional_overflow(0);
82101 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82102 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82103 unsigned int vlen, unsigned flags);
82104 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82105 index 27b3b0b..e093dd9 100644
82106 --- a/include/linux/syscore_ops.h
82107 +++ b/include/linux/syscore_ops.h
82108 @@ -16,7 +16,7 @@ struct syscore_ops {
82109 int (*suspend)(void);
82110 void (*resume)(void);
82111 void (*shutdown)(void);
82112 -};
82113 +} __do_const;
82114
82115 extern void register_syscore_ops(struct syscore_ops *ops);
82116 extern void unregister_syscore_ops(struct syscore_ops *ops);
82117 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82118 index 14a8ff2..fa95f3a 100644
82119 --- a/include/linux/sysctl.h
82120 +++ b/include/linux/sysctl.h
82121 @@ -34,13 +34,13 @@ struct ctl_table_root;
82122 struct ctl_table_header;
82123 struct ctl_dir;
82124
82125 -typedef struct ctl_table ctl_table;
82126 -
82127 typedef int proc_handler (struct ctl_table *ctl, int write,
82128 void __user *buffer, size_t *lenp, loff_t *ppos);
82129
82130 extern int proc_dostring(struct ctl_table *, int,
82131 void __user *, size_t *, loff_t *);
82132 +extern int proc_dostring_modpriv(struct ctl_table *, int,
82133 + void __user *, size_t *, loff_t *);
82134 extern int proc_dointvec(struct ctl_table *, int,
82135 void __user *, size_t *, loff_t *);
82136 extern int proc_dointvec_minmax(struct ctl_table *, int,
82137 @@ -115,7 +115,9 @@ struct ctl_table
82138 struct ctl_table_poll *poll;
82139 void *extra1;
82140 void *extra2;
82141 -};
82142 +} __do_const __randomize_layout;
82143 +typedef struct ctl_table __no_const ctl_table_no_const;
82144 +typedef struct ctl_table ctl_table;
82145
82146 struct ctl_node {
82147 struct rb_node node;
82148 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82149 index 6695040..3d4192d 100644
82150 --- a/include/linux/sysfs.h
82151 +++ b/include/linux/sysfs.h
82152 @@ -33,7 +33,8 @@ struct attribute {
82153 struct lock_class_key *key;
82154 struct lock_class_key skey;
82155 #endif
82156 -};
82157 +} __do_const;
82158 +typedef struct attribute __no_const attribute_no_const;
82159
82160 /**
82161 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82162 @@ -62,7 +63,8 @@ struct attribute_group {
82163 struct attribute *, int);
82164 struct attribute **attrs;
82165 struct bin_attribute **bin_attrs;
82166 -};
82167 +} __do_const;
82168 +typedef struct attribute_group __no_const attribute_group_no_const;
82169
82170 /**
82171 * Use these macros to make defining attributes easier. See include/linux/device.h
82172 @@ -126,7 +128,8 @@ struct bin_attribute {
82173 char *, loff_t, size_t);
82174 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82175 struct vm_area_struct *vma);
82176 -};
82177 +} __do_const;
82178 +typedef struct bin_attribute __no_const bin_attribute_no_const;
82179
82180 /**
82181 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82182 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82183 index 387fa7d..3fcde6b 100644
82184 --- a/include/linux/sysrq.h
82185 +++ b/include/linux/sysrq.h
82186 @@ -16,6 +16,7 @@
82187
82188 #include <linux/errno.h>
82189 #include <linux/types.h>
82190 +#include <linux/compiler.h>
82191
82192 /* Possible values of bitmask for enabling sysrq functions */
82193 /* 0x0001 is reserved for enable everything */
82194 @@ -33,7 +34,7 @@ struct sysrq_key_op {
82195 char *help_msg;
82196 char *action_msg;
82197 int enable_mask;
82198 -};
82199 +} __do_const;
82200
82201 #ifdef CONFIG_MAGIC_SYSRQ
82202
82203 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82204 index fddbe20..0312de8 100644
82205 --- a/include/linux/thread_info.h
82206 +++ b/include/linux/thread_info.h
82207 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
82208 #error "no set_restore_sigmask() provided and default one won't work"
82209 #endif
82210
82211 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82212 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82213 +{
82214 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
82215 + if (!__builtin_constant_p(n))
82216 +#endif
82217 + __check_object_size(ptr, n, to_user);
82218 +}
82219 +
82220 #endif /* __KERNEL__ */
82221
82222 #endif /* _LINUX_THREAD_INFO_H */
82223 diff --git a/include/linux/tty.h b/include/linux/tty.h
82224 index 97d660e..6356755 100644
82225 --- a/include/linux/tty.h
82226 +++ b/include/linux/tty.h
82227 @@ -196,7 +196,7 @@ struct tty_port {
82228 const struct tty_port_operations *ops; /* Port operations */
82229 spinlock_t lock; /* Lock protecting tty field */
82230 int blocked_open; /* Waiting to open */
82231 - int count; /* Usage count */
82232 + atomic_t count; /* Usage count */
82233 wait_queue_head_t open_wait; /* Open waiters */
82234 wait_queue_head_t close_wait; /* Close waiters */
82235 wait_queue_head_t delta_msr_wait; /* Modem status change */
82236 @@ -278,7 +278,7 @@ struct tty_struct {
82237 /* If the tty has a pending do_SAK, queue it here - akpm */
82238 struct work_struct SAK_work;
82239 struct tty_port *port;
82240 -};
82241 +} __randomize_layout;
82242
82243 /* Each of a tty's open files has private_data pointing to tty_file_private */
82244 struct tty_file_private {
82245 @@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
82246 struct tty_struct *tty, struct file *filp);
82247 static inline int tty_port_users(struct tty_port *port)
82248 {
82249 - return port->count + port->blocked_open;
82250 + return atomic_read(&port->count) + port->blocked_open;
82251 }
82252
82253 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82254 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82255 index 756a609..89db85e 100644
82256 --- a/include/linux/tty_driver.h
82257 +++ b/include/linux/tty_driver.h
82258 @@ -285,7 +285,7 @@ struct tty_operations {
82259 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82260 #endif
82261 const struct file_operations *proc_fops;
82262 -};
82263 +} __do_const __randomize_layout;
82264
82265 struct tty_driver {
82266 int magic; /* magic number for this structure */
82267 @@ -319,7 +319,7 @@ struct tty_driver {
82268
82269 const struct tty_operations *ops;
82270 struct list_head tty_drivers;
82271 -};
82272 +} __randomize_layout;
82273
82274 extern struct list_head tty_drivers;
82275
82276 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82277 index f15c898..207b7d1 100644
82278 --- a/include/linux/tty_ldisc.h
82279 +++ b/include/linux/tty_ldisc.h
82280 @@ -211,7 +211,7 @@ struct tty_ldisc_ops {
82281
82282 struct module *owner;
82283
82284 - int refcount;
82285 + atomic_t refcount;
82286 };
82287
82288 struct tty_ldisc {
82289 diff --git a/include/linux/types.h b/include/linux/types.h
82290 index 4d118ba..c3ee9bf 100644
82291 --- a/include/linux/types.h
82292 +++ b/include/linux/types.h
82293 @@ -176,10 +176,26 @@ typedef struct {
82294 int counter;
82295 } atomic_t;
82296
82297 +#ifdef CONFIG_PAX_REFCOUNT
82298 +typedef struct {
82299 + int counter;
82300 +} atomic_unchecked_t;
82301 +#else
82302 +typedef atomic_t atomic_unchecked_t;
82303 +#endif
82304 +
82305 #ifdef CONFIG_64BIT
82306 typedef struct {
82307 long counter;
82308 } atomic64_t;
82309 +
82310 +#ifdef CONFIG_PAX_REFCOUNT
82311 +typedef struct {
82312 + long counter;
82313 +} atomic64_unchecked_t;
82314 +#else
82315 +typedef atomic64_t atomic64_unchecked_t;
82316 +#endif
82317 #endif
82318
82319 struct list_head {
82320 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82321 index 9d8cf05..0ed74dd 100644
82322 --- a/include/linux/uaccess.h
82323 +++ b/include/linux/uaccess.h
82324 @@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82325 long ret; \
82326 mm_segment_t old_fs = get_fs(); \
82327 \
82328 - set_fs(KERNEL_DS); \
82329 pagefault_disable(); \
82330 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82331 - pagefault_enable(); \
82332 + set_fs(KERNEL_DS); \
82333 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82334 set_fs(old_fs); \
82335 + pagefault_enable(); \
82336 ret; \
82337 })
82338
82339 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82340 index 8e522cbc..aa8572d 100644
82341 --- a/include/linux/uidgid.h
82342 +++ b/include/linux/uidgid.h
82343 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82344
82345 #endif /* CONFIG_USER_NS */
82346
82347 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82348 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82349 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82350 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82351 +
82352 #endif /* _LINUX_UIDGID_H */
82353 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82354 index 99c1b4d..562e6f3 100644
82355 --- a/include/linux/unaligned/access_ok.h
82356 +++ b/include/linux/unaligned/access_ok.h
82357 @@ -4,34 +4,34 @@
82358 #include <linux/kernel.h>
82359 #include <asm/byteorder.h>
82360
82361 -static inline u16 get_unaligned_le16(const void *p)
82362 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82363 {
82364 - return le16_to_cpup((__le16 *)p);
82365 + return le16_to_cpup((const __le16 *)p);
82366 }
82367
82368 -static inline u32 get_unaligned_le32(const void *p)
82369 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82370 {
82371 - return le32_to_cpup((__le32 *)p);
82372 + return le32_to_cpup((const __le32 *)p);
82373 }
82374
82375 -static inline u64 get_unaligned_le64(const void *p)
82376 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82377 {
82378 - return le64_to_cpup((__le64 *)p);
82379 + return le64_to_cpup((const __le64 *)p);
82380 }
82381
82382 -static inline u16 get_unaligned_be16(const void *p)
82383 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82384 {
82385 - return be16_to_cpup((__be16 *)p);
82386 + return be16_to_cpup((const __be16 *)p);
82387 }
82388
82389 -static inline u32 get_unaligned_be32(const void *p)
82390 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82391 {
82392 - return be32_to_cpup((__be32 *)p);
82393 + return be32_to_cpup((const __be32 *)p);
82394 }
82395
82396 -static inline u64 get_unaligned_be64(const void *p)
82397 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82398 {
82399 - return be64_to_cpup((__be64 *)p);
82400 + return be64_to_cpup((const __be64 *)p);
82401 }
82402
82403 static inline void put_unaligned_le16(u16 val, void *p)
82404 diff --git a/include/linux/usb.h b/include/linux/usb.h
82405 index 7454865..29f4bfa 100644
82406 --- a/include/linux/usb.h
82407 +++ b/include/linux/usb.h
82408 @@ -563,7 +563,7 @@ struct usb_device {
82409 int maxchild;
82410
82411 u32 quirks;
82412 - atomic_t urbnum;
82413 + atomic_unchecked_t urbnum;
82414
82415 unsigned long active_duration;
82416
82417 @@ -1641,7 +1641,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82418
82419 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82420 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82421 - void *data, __u16 size, int timeout);
82422 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
82423 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82424 void *data, int len, int *actual_length, int timeout);
82425 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82426 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82427 index e452ba6..78f8e80 100644
82428 --- a/include/linux/usb/renesas_usbhs.h
82429 +++ b/include/linux/usb/renesas_usbhs.h
82430 @@ -39,7 +39,7 @@ enum {
82431 */
82432 struct renesas_usbhs_driver_callback {
82433 int (*notify_hotplug)(struct platform_device *pdev);
82434 -};
82435 +} __no_const;
82436
82437 /*
82438 * callback functions for platform
82439 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82440 index 4836ba3..603f6ee 100644
82441 --- a/include/linux/user_namespace.h
82442 +++ b/include/linux/user_namespace.h
82443 @@ -33,7 +33,7 @@ struct user_namespace {
82444 struct key *persistent_keyring_register;
82445 struct rw_semaphore persistent_keyring_register_sem;
82446 #endif
82447 -};
82448 +} __randomize_layout;
82449
82450 extern struct user_namespace init_user_ns;
82451
82452 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82453 index 239e277..22a5cf5 100644
82454 --- a/include/linux/utsname.h
82455 +++ b/include/linux/utsname.h
82456 @@ -24,7 +24,7 @@ struct uts_namespace {
82457 struct new_utsname name;
82458 struct user_namespace *user_ns;
82459 unsigned int proc_inum;
82460 -};
82461 +} __randomize_layout;
82462 extern struct uts_namespace init_uts_ns;
82463
82464 #ifdef CONFIG_UTS_NS
82465 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82466 index 6f8fbcf..4efc177 100644
82467 --- a/include/linux/vermagic.h
82468 +++ b/include/linux/vermagic.h
82469 @@ -25,9 +25,42 @@
82470 #define MODULE_ARCH_VERMAGIC ""
82471 #endif
82472
82473 +#ifdef CONFIG_PAX_REFCOUNT
82474 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
82475 +#else
82476 +#define MODULE_PAX_REFCOUNT ""
82477 +#endif
82478 +
82479 +#ifdef CONSTIFY_PLUGIN
82480 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82481 +#else
82482 +#define MODULE_CONSTIFY_PLUGIN ""
82483 +#endif
82484 +
82485 +#ifdef STACKLEAK_PLUGIN
82486 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82487 +#else
82488 +#define MODULE_STACKLEAK_PLUGIN ""
82489 +#endif
82490 +
82491 +#ifdef RANDSTRUCT_PLUGIN
82492 +#include <generated/randomize_layout_hash.h>
82493 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82494 +#else
82495 +#define MODULE_RANDSTRUCT_PLUGIN
82496 +#endif
82497 +
82498 +#ifdef CONFIG_GRKERNSEC
82499 +#define MODULE_GRSEC "GRSEC "
82500 +#else
82501 +#define MODULE_GRSEC ""
82502 +#endif
82503 +
82504 #define VERMAGIC_STRING \
82505 UTS_RELEASE " " \
82506 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82507 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82508 - MODULE_ARCH_VERMAGIC
82509 + MODULE_ARCH_VERMAGIC \
82510 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82511 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82512
82513 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82514 index 502073a..a7de024 100644
82515 --- a/include/linux/vga_switcheroo.h
82516 +++ b/include/linux/vga_switcheroo.h
82517 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82518
82519 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82520
82521 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82522 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82523 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82524 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82525 #else
82526
82527 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82528 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82529
82530 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82531
82532 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82533 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82534 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82535 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82536
82537 #endif
82538 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82539 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82540 index 4b8a891..cb8df6e 100644
82541 --- a/include/linux/vmalloc.h
82542 +++ b/include/linux/vmalloc.h
82543 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82544 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82545 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82546 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82547 +
82548 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82549 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82550 +#endif
82551 +
82552 /* bits [20..32] reserved for arch specific ioremap internals */
82553
82554 /*
82555 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82556
82557 /* for /dev/kmem */
82558 extern long vread(char *buf, char *addr, unsigned long count);
82559 -extern long vwrite(char *buf, char *addr, unsigned long count);
82560 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82561
82562 /*
82563 * Internals. Dont't use..
82564 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82565 index a67b384..f52a537 100644
82566 --- a/include/linux/vmstat.h
82567 +++ b/include/linux/vmstat.h
82568 @@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
82569 /*
82570 * Zone based page accounting with per cpu differentials.
82571 */
82572 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82573 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82574
82575 static inline void zone_page_state_add(long x, struct zone *zone,
82576 enum zone_stat_item item)
82577 {
82578 - atomic_long_add(x, &zone->vm_stat[item]);
82579 - atomic_long_add(x, &vm_stat[item]);
82580 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82581 + atomic_long_add_unchecked(x, &vm_stat[item]);
82582 }
82583
82584 -static inline unsigned long global_page_state(enum zone_stat_item item)
82585 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82586 {
82587 - long x = atomic_long_read(&vm_stat[item]);
82588 + long x = atomic_long_read_unchecked(&vm_stat[item]);
82589 #ifdef CONFIG_SMP
82590 if (x < 0)
82591 x = 0;
82592 @@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82593 return x;
82594 }
82595
82596 -static inline unsigned long zone_page_state(struct zone *zone,
82597 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82598 enum zone_stat_item item)
82599 {
82600 - long x = atomic_long_read(&zone->vm_stat[item]);
82601 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82602 #ifdef CONFIG_SMP
82603 if (x < 0)
82604 x = 0;
82605 @@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82606 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82607 enum zone_stat_item item)
82608 {
82609 - long x = atomic_long_read(&zone->vm_stat[item]);
82610 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82611
82612 #ifdef CONFIG_SMP
82613 int cpu;
82614 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82615
82616 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82617 {
82618 - atomic_long_inc(&zone->vm_stat[item]);
82619 - atomic_long_inc(&vm_stat[item]);
82620 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
82621 + atomic_long_inc_unchecked(&vm_stat[item]);
82622 }
82623
82624 static inline void __inc_zone_page_state(struct page *page,
82625 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
82626
82627 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82628 {
82629 - atomic_long_dec(&zone->vm_stat[item]);
82630 - atomic_long_dec(&vm_stat[item]);
82631 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
82632 + atomic_long_dec_unchecked(&vm_stat[item]);
82633 }
82634
82635 static inline void __dec_zone_page_state(struct page *page,
82636 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82637 index 91b0a68..0e9adf6 100644
82638 --- a/include/linux/xattr.h
82639 +++ b/include/linux/xattr.h
82640 @@ -28,7 +28,7 @@ struct xattr_handler {
82641 size_t size, int handler_flags);
82642 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82643 size_t size, int flags, int handler_flags);
82644 -};
82645 +} __do_const;
82646
82647 struct xattr {
82648 const char *name;
82649 @@ -37,6 +37,9 @@ struct xattr {
82650 };
82651
82652 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82653 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82654 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
82655 +#endif
82656 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82657 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82658 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82659 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82660 index 9c5a6b4..09c9438 100644
82661 --- a/include/linux/zlib.h
82662 +++ b/include/linux/zlib.h
82663 @@ -31,6 +31,7 @@
82664 #define _ZLIB_H
82665
82666 #include <linux/zconf.h>
82667 +#include <linux/compiler.h>
82668
82669 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82670 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82671 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82672
82673 /* basic functions */
82674
82675 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82676 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82677 /*
82678 Returns the number of bytes that needs to be allocated for a per-
82679 stream workspace with the specified parameters. A pointer to this
82680 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82681 index c768c9f..bdcaa5a 100644
82682 --- a/include/media/v4l2-dev.h
82683 +++ b/include/media/v4l2-dev.h
82684 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
82685 int (*mmap) (struct file *, struct vm_area_struct *);
82686 int (*open) (struct file *);
82687 int (*release) (struct file *);
82688 -};
82689 +} __do_const;
82690
82691 /*
82692 * Newer version of video_device, handled by videodev2.c
82693 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82694 index c9b1593..a572459 100644
82695 --- a/include/media/v4l2-device.h
82696 +++ b/include/media/v4l2-device.h
82697 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82698 this function returns 0. If the name ends with a digit (e.g. cx18),
82699 then the name will be set to cx18-0 since cx180 looks really odd. */
82700 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82701 - atomic_t *instance);
82702 + atomic_unchecked_t *instance);
82703
82704 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82705 Since the parent disappears this ensures that v4l2_dev doesn't have an
82706 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82707 index 9a36d92..0aafe2a 100644
82708 --- a/include/net/9p/transport.h
82709 +++ b/include/net/9p/transport.h
82710 @@ -60,7 +60,7 @@ struct p9_trans_module {
82711 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82712 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82713 char *, char *, int , int, int, int);
82714 -};
82715 +} __do_const;
82716
82717 void v9fs_register_trans(struct p9_trans_module *m);
82718 void v9fs_unregister_trans(struct p9_trans_module *m);
82719 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
82720 index a175ba4..196eb82 100644
82721 --- a/include/net/af_unix.h
82722 +++ b/include/net/af_unix.h
82723 @@ -36,7 +36,7 @@ struct unix_skb_parms {
82724 u32 secid; /* Security ID */
82725 #endif
82726 u32 consumed;
82727 -};
82728 +} __randomize_layout;
82729
82730 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
82731 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
82732 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82733 index c853b16d..37fccb7 100644
82734 --- a/include/net/bluetooth/l2cap.h
82735 +++ b/include/net/bluetooth/l2cap.h
82736 @@ -557,7 +557,7 @@ struct l2cap_ops {
82737 long (*get_sndtimeo) (struct l2cap_chan *chan);
82738 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82739 unsigned long len, int nb);
82740 -};
82741 +} __do_const;
82742
82743 struct l2cap_conn {
82744 struct hci_conn *hcon;
82745 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82746 index f2ae33d..c457cf0 100644
82747 --- a/include/net/caif/cfctrl.h
82748 +++ b/include/net/caif/cfctrl.h
82749 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
82750 void (*radioset_rsp)(void);
82751 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82752 struct cflayer *client_layer);
82753 -};
82754 +} __no_const;
82755
82756 /* Link Setup Parameters for CAIF-Links. */
82757 struct cfctrl_link_param {
82758 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
82759 struct cfctrl {
82760 struct cfsrvl serv;
82761 struct cfctrl_rsp res;
82762 - atomic_t req_seq_no;
82763 - atomic_t rsp_seq_no;
82764 + atomic_unchecked_t req_seq_no;
82765 + atomic_unchecked_t rsp_seq_no;
82766 struct list_head list;
82767 /* Protects from simultaneous access to first_req list */
82768 spinlock_t info_list_lock;
82769 diff --git a/include/net/flow.h b/include/net/flow.h
82770 index 65ce471..b7bbe9b 100644
82771 --- a/include/net/flow.h
82772 +++ b/include/net/flow.h
82773 @@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82774
82775 void flow_cache_flush(void);
82776 void flow_cache_flush_deferred(void);
82777 -extern atomic_t flow_cache_genid;
82778 +extern atomic_unchecked_t flow_cache_genid;
82779
82780 #endif
82781 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82782 index 1b177ed..a24a138 100644
82783 --- a/include/net/genetlink.h
82784 +++ b/include/net/genetlink.h
82785 @@ -118,7 +118,7 @@ struct genl_ops {
82786 u8 cmd;
82787 u8 internal_flags;
82788 u8 flags;
82789 -};
82790 +} __do_const;
82791
82792 int __genl_register_family(struct genl_family *family);
82793
82794 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82795 index 734d9b5..48a9a4b 100644
82796 --- a/include/net/gro_cells.h
82797 +++ b/include/net/gro_cells.h
82798 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82799 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82800
82801 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82802 - atomic_long_inc(&dev->rx_dropped);
82803 + atomic_long_inc_unchecked(&dev->rx_dropped);
82804 kfree_skb(skb);
82805 return;
82806 }
82807 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82808 index c55aeed..b3393f4 100644
82809 --- a/include/net/inet_connection_sock.h
82810 +++ b/include/net/inet_connection_sock.h
82811 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82812 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82813 int (*bind_conflict)(const struct sock *sk,
82814 const struct inet_bind_bucket *tb, bool relax);
82815 -};
82816 +} __do_const;
82817
82818 /** inet_connection_sock - INET connection oriented sock
82819 *
82820 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82821 index f4e127a..c3d5e9c 100644
82822 --- a/include/net/inetpeer.h
82823 +++ b/include/net/inetpeer.h
82824 @@ -47,8 +47,8 @@ struct inet_peer {
82825 */
82826 union {
82827 struct {
82828 - atomic_t rid; /* Frag reception counter */
82829 - atomic_t ip_id_count; /* IP ID for the next packet */
82830 + atomic_unchecked_t rid; /* Frag reception counter */
82831 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
82832 };
82833 struct rcu_head rcu;
82834 struct inet_peer *gc_next;
82835 @@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
82836 /* can be called with or without local BH being disabled */
82837 static inline int inet_getid(struct inet_peer *p, int more)
82838 {
82839 - int old, new;
82840 + int id;
82841 more++;
82842 inet_peer_refcheck(p);
82843 - do {
82844 - old = atomic_read(&p->ip_id_count);
82845 - new = old + more;
82846 - if (!new)
82847 - new = 1;
82848 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
82849 - return new;
82850 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
82851 + if (!id)
82852 + id = atomic_inc_return_unchecked(&p->ip_id_count);
82853 + return id;
82854 }
82855
82856 #endif /* _NET_INETPEER_H */
82857 diff --git a/include/net/ip.h b/include/net/ip.h
82858 index 5a25f36..2e73203 100644
82859 --- a/include/net/ip.h
82860 +++ b/include/net/ip.h
82861 @@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
82862
82863 void inet_get_local_port_range(struct net *net, int *low, int *high);
82864
82865 -extern unsigned long *sysctl_local_reserved_ports;
82866 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
82867 static inline int inet_is_reserved_local_port(int port)
82868 {
82869 return test_bit(port, sysctl_local_reserved_ports);
82870 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
82871 index 9922093..a1755d6 100644
82872 --- a/include/net/ip_fib.h
82873 +++ b/include/net/ip_fib.h
82874 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
82875
82876 #define FIB_RES_SADDR(net, res) \
82877 ((FIB_RES_NH(res).nh_saddr_genid == \
82878 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
82879 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
82880 FIB_RES_NH(res).nh_saddr : \
82881 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
82882 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
82883 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
82884 index 5679d92..2e7a690 100644
82885 --- a/include/net/ip_vs.h
82886 +++ b/include/net/ip_vs.h
82887 @@ -558,7 +558,7 @@ struct ip_vs_conn {
82888 struct ip_vs_conn *control; /* Master control connection */
82889 atomic_t n_control; /* Number of controlled ones */
82890 struct ip_vs_dest *dest; /* real server */
82891 - atomic_t in_pkts; /* incoming packet counter */
82892 + atomic_unchecked_t in_pkts; /* incoming packet counter */
82893
82894 /* packet transmitter for different forwarding methods. If it
82895 mangles the packet, it must return NF_DROP or better NF_STOLEN,
82896 @@ -705,7 +705,7 @@ struct ip_vs_dest {
82897 __be16 port; /* port number of the server */
82898 union nf_inet_addr addr; /* IP address of the server */
82899 volatile unsigned int flags; /* dest status flags */
82900 - atomic_t conn_flags; /* flags to copy to conn */
82901 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
82902 atomic_t weight; /* server weight */
82903
82904 atomic_t refcnt; /* reference counter */
82905 @@ -960,11 +960,11 @@ struct netns_ipvs {
82906 /* ip_vs_lblc */
82907 int sysctl_lblc_expiration;
82908 struct ctl_table_header *lblc_ctl_header;
82909 - struct ctl_table *lblc_ctl_table;
82910 + ctl_table_no_const *lblc_ctl_table;
82911 /* ip_vs_lblcr */
82912 int sysctl_lblcr_expiration;
82913 struct ctl_table_header *lblcr_ctl_header;
82914 - struct ctl_table *lblcr_ctl_table;
82915 + ctl_table_no_const *lblcr_ctl_table;
82916 /* ip_vs_est */
82917 struct list_head est_list; /* estimator list */
82918 spinlock_t est_lock;
82919 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
82920 index 0224402..dafaf94a 100644
82921 --- a/include/net/irda/ircomm_tty.h
82922 +++ b/include/net/irda/ircomm_tty.h
82923 @@ -35,6 +35,7 @@
82924 #include <linux/termios.h>
82925 #include <linux/timer.h>
82926 #include <linux/tty.h> /* struct tty_struct */
82927 +#include <asm/local.h>
82928
82929 #include <net/irda/irias_object.h>
82930 #include <net/irda/ircomm_core.h>
82931 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
82932 index 714cc9a..ea05f3e 100644
82933 --- a/include/net/iucv/af_iucv.h
82934 +++ b/include/net/iucv/af_iucv.h
82935 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
82936 struct iucv_sock_list {
82937 struct hlist_head head;
82938 rwlock_t lock;
82939 - atomic_t autobind_name;
82940 + atomic_unchecked_t autobind_name;
82941 };
82942
82943 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
82944 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
82945 index f3be818..bf46196 100644
82946 --- a/include/net/llc_c_ac.h
82947 +++ b/include/net/llc_c_ac.h
82948 @@ -87,7 +87,7 @@
82949 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
82950 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
82951
82952 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82953 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82954
82955 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
82956 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
82957 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
82958 index 3948cf1..83b28c4 100644
82959 --- a/include/net/llc_c_ev.h
82960 +++ b/include/net/llc_c_ev.h
82961 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
82962 return (struct llc_conn_state_ev *)skb->cb;
82963 }
82964
82965 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82966 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82967 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82968 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82969
82970 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
82971 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
82972 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
82973 index 0e79cfb..f46db31 100644
82974 --- a/include/net/llc_c_st.h
82975 +++ b/include/net/llc_c_st.h
82976 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
82977 u8 next_state;
82978 llc_conn_ev_qfyr_t *ev_qualifiers;
82979 llc_conn_action_t *ev_actions;
82980 -};
82981 +} __do_const;
82982
82983 struct llc_conn_state {
82984 u8 current_state;
82985 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
82986 index a61b98c..aade1eb 100644
82987 --- a/include/net/llc_s_ac.h
82988 +++ b/include/net/llc_s_ac.h
82989 @@ -23,7 +23,7 @@
82990 #define SAP_ACT_TEST_IND 9
82991
82992 /* All action functions must look like this */
82993 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82994 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82995
82996 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
82997 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
82998 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
82999 index 567c681..cd73ac0 100644
83000 --- a/include/net/llc_s_st.h
83001 +++ b/include/net/llc_s_st.h
83002 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83003 llc_sap_ev_t ev;
83004 u8 next_state;
83005 llc_sap_action_t *ev_actions;
83006 -};
83007 +} __do_const;
83008
83009 struct llc_sap_state {
83010 u8 curr_state;
83011 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83012 index 7ceed99..d3ffaa2 100644
83013 --- a/include/net/mac80211.h
83014 +++ b/include/net/mac80211.h
83015 @@ -4407,7 +4407,7 @@ struct rate_control_ops {
83016 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83017 struct dentry *dir);
83018 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83019 -};
83020 +} __do_const;
83021
83022 static inline int rate_supported(struct ieee80211_sta *sta,
83023 enum ieee80211_band band,
83024 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83025 index 536501a..47b7982 100644
83026 --- a/include/net/neighbour.h
83027 +++ b/include/net/neighbour.h
83028 @@ -123,7 +123,7 @@ struct neigh_ops {
83029 void (*error_report)(struct neighbour *, struct sk_buff *);
83030 int (*output)(struct neighbour *, struct sk_buff *);
83031 int (*connected_output)(struct neighbour *, struct sk_buff *);
83032 -};
83033 +} __do_const;
83034
83035 struct pneigh_entry {
83036 struct pneigh_entry *next;
83037 @@ -163,7 +163,6 @@ struct neigh_table {
83038 void (*proxy_redo)(struct sk_buff *skb);
83039 char *id;
83040 struct neigh_parms parms;
83041 - /* HACK. gc_* should follow parms without a gap! */
83042 int gc_interval;
83043 int gc_thresh1;
83044 int gc_thresh2;
83045 @@ -178,7 +177,7 @@ struct neigh_table {
83046 struct neigh_statistics __percpu *stats;
83047 struct neigh_hash_table __rcu *nht;
83048 struct pneigh_entry **phash_buckets;
83049 -};
83050 +} __randomize_layout;
83051
83052 #define NEIGH_PRIV_ALIGN sizeof(long long)
83053 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
83054 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83055 index da68c9a..c4a0720 100644
83056 --- a/include/net/net_namespace.h
83057 +++ b/include/net/net_namespace.h
83058 @@ -124,8 +124,8 @@ struct net {
83059 struct netns_ipvs *ipvs;
83060 #endif
83061 struct sock *diag_nlsk;
83062 - atomic_t fnhe_genid;
83063 -};
83064 + atomic_unchecked_t fnhe_genid;
83065 +} __randomize_layout;
83066
83067 /*
83068 * ifindex generation is per-net namespace, and loopback is
83069 @@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83070 #define __net_init __init
83071 #define __net_exit __exit_refok
83072 #define __net_initdata __initdata
83073 +#ifdef CONSTIFY_PLUGIN
83074 #define __net_initconst __initconst
83075 +#else
83076 +#define __net_initconst __initdata
83077 +#endif
83078 #endif
83079
83080 struct pernet_operations {
83081 @@ -291,7 +295,7 @@ struct pernet_operations {
83082 void (*exit_batch)(struct list_head *net_exit_list);
83083 int *id;
83084 size_t size;
83085 -};
83086 +} __do_const;
83087
83088 /*
83089 * Use these carefully. If you implement a network device and it
83090 @@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83091
83092 static inline int rt_genid_ipv4(struct net *net)
83093 {
83094 - return atomic_read(&net->ipv4.rt_genid);
83095 + return atomic_read_unchecked(&net->ipv4.rt_genid);
83096 }
83097
83098 static inline void rt_genid_bump_ipv4(struct net *net)
83099 {
83100 - atomic_inc(&net->ipv4.rt_genid);
83101 + atomic_inc_unchecked(&net->ipv4.rt_genid);
83102 }
83103
83104 #if IS_ENABLED(CONFIG_IPV6)
83105 static inline int rt_genid_ipv6(struct net *net)
83106 {
83107 - return atomic_read(&net->ipv6.rt_genid);
83108 + return atomic_read_unchecked(&net->ipv6.rt_genid);
83109 }
83110
83111 static inline void rt_genid_bump_ipv6(struct net *net)
83112 {
83113 - atomic_inc(&net->ipv6.rt_genid);
83114 + atomic_inc_unchecked(&net->ipv6.rt_genid);
83115 }
83116 #else
83117 static inline int rt_genid_ipv6(struct net *net)
83118 @@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
83119
83120 static inline int fnhe_genid(struct net *net)
83121 {
83122 - return atomic_read(&net->fnhe_genid);
83123 + return atomic_read_unchecked(&net->fnhe_genid);
83124 }
83125
83126 static inline void fnhe_genid_bump(struct net *net)
83127 {
83128 - atomic_inc(&net->fnhe_genid);
83129 + atomic_inc_unchecked(&net->fnhe_genid);
83130 }
83131
83132 #endif /* __NET_NET_NAMESPACE_H */
83133 diff --git a/include/net/netdma.h b/include/net/netdma.h
83134 index 8ba8ce2..99b7fff 100644
83135 --- a/include/net/netdma.h
83136 +++ b/include/net/netdma.h
83137 @@ -24,7 +24,7 @@
83138 #include <linux/dmaengine.h>
83139 #include <linux/skbuff.h>
83140
83141 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83142 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83143 struct sk_buff *skb, int offset, struct iovec *to,
83144 size_t len, struct dma_pinned_list *pinned_list);
83145
83146 diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83147 index 956b175..55d1504 100644
83148 --- a/include/net/netfilter/nf_conntrack_extend.h
83149 +++ b/include/net/netfilter/nf_conntrack_extend.h
83150 @@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83151 /* Extensions: optional stuff which isn't permanently in struct. */
83152 struct nf_ct_ext {
83153 struct rcu_head rcu;
83154 - u8 offset[NF_CT_EXT_NUM];
83155 - u8 len;
83156 + u16 offset[NF_CT_EXT_NUM];
83157 + u16 len;
83158 char data[0];
83159 };
83160
83161 diff --git a/include/net/netlink.h b/include/net/netlink.h
83162 index 2b47eaa..6d5bcc2 100644
83163 --- a/include/net/netlink.h
83164 +++ b/include/net/netlink.h
83165 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83166 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83167 {
83168 if (mark)
83169 - skb_trim(skb, (unsigned char *) mark - skb->data);
83170 + skb_trim(skb, (const unsigned char *) mark - skb->data);
83171 }
83172
83173 /**
83174 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83175 index c9c0c53..53f24c3 100644
83176 --- a/include/net/netns/conntrack.h
83177 +++ b/include/net/netns/conntrack.h
83178 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83179 struct nf_proto_net {
83180 #ifdef CONFIG_SYSCTL
83181 struct ctl_table_header *ctl_table_header;
83182 - struct ctl_table *ctl_table;
83183 + ctl_table_no_const *ctl_table;
83184 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83185 struct ctl_table_header *ctl_compat_header;
83186 - struct ctl_table *ctl_compat_table;
83187 + ctl_table_no_const *ctl_compat_table;
83188 #endif
83189 #endif
83190 unsigned int users;
83191 @@ -58,7 +58,7 @@ struct nf_ip_net {
83192 struct nf_icmp_net icmpv6;
83193 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83194 struct ctl_table_header *ctl_table_header;
83195 - struct ctl_table *ctl_table;
83196 + ctl_table_no_const *ctl_table;
83197 #endif
83198 };
83199
83200 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83201 index ee520cb..9a0fd88 100644
83202 --- a/include/net/netns/ipv4.h
83203 +++ b/include/net/netns/ipv4.h
83204 @@ -72,7 +72,7 @@ struct netns_ipv4 {
83205
83206 kgid_t sysctl_ping_group_range[2];
83207
83208 - atomic_t dev_addr_genid;
83209 + atomic_unchecked_t dev_addr_genid;
83210
83211 #ifdef CONFIG_IP_MROUTE
83212 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83213 @@ -82,6 +82,6 @@ struct netns_ipv4 {
83214 struct fib_rules_ops *mr_rules_ops;
83215 #endif
83216 #endif
83217 - atomic_t rt_genid;
83218 + atomic_unchecked_t rt_genid;
83219 };
83220 #endif
83221 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83222 index 0fb2401..477d81c 100644
83223 --- a/include/net/netns/ipv6.h
83224 +++ b/include/net/netns/ipv6.h
83225 @@ -71,8 +71,8 @@ struct netns_ipv6 {
83226 struct fib_rules_ops *mr6_rules_ops;
83227 #endif
83228 #endif
83229 - atomic_t dev_addr_genid;
83230 - atomic_t rt_genid;
83231 + atomic_unchecked_t dev_addr_genid;
83232 + atomic_unchecked_t rt_genid;
83233 };
83234
83235 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83236 diff --git a/include/net/ping.h b/include/net/ping.h
83237 index 90f4841..74446a8 100644
83238 --- a/include/net/ping.h
83239 +++ b/include/net/ping.h
83240 @@ -56,7 +56,7 @@ struct ping_iter_state {
83241 extern struct proto ping_prot;
83242 extern struct ping_table ping_table;
83243 #if IS_ENABLED(CONFIG_IPV6)
83244 -extern struct pingv6_ops pingv6_ops;
83245 +extern struct pingv6_ops *pingv6_ops;
83246 #endif
83247
83248 struct pingfakehdr {
83249 diff --git a/include/net/protocol.h b/include/net/protocol.h
83250 index fbf7676..a5e21c3 100644
83251 --- a/include/net/protocol.h
83252 +++ b/include/net/protocol.h
83253 @@ -44,7 +44,7 @@ struct net_protocol {
83254 void (*err_handler)(struct sk_buff *skb, u32 info);
83255 unsigned int no_policy:1,
83256 netns_ok:1;
83257 -};
83258 +} __do_const;
83259
83260 #if IS_ENABLED(CONFIG_IPV6)
83261 struct inet6_protocol {
83262 @@ -57,7 +57,7 @@ struct inet6_protocol {
83263 u8 type, u8 code, int offset,
83264 __be32 info);
83265 unsigned int flags; /* INET6_PROTO_xxx */
83266 -};
83267 +} __do_const;
83268
83269 #define INET6_PROTO_NOPOLICY 0x1
83270 #define INET6_PROTO_FINAL 0x2
83271 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83272 index bb13a18..e734116 100644
83273 --- a/include/net/rtnetlink.h
83274 +++ b/include/net/rtnetlink.h
83275 @@ -79,7 +79,7 @@ struct rtnl_link_ops {
83276 const struct net_device *dev);
83277 unsigned int (*get_num_tx_queues)(void);
83278 unsigned int (*get_num_rx_queues)(void);
83279 -};
83280 +} __do_const;
83281
83282 int __rtnl_link_register(struct rtnl_link_ops *ops);
83283 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83284 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83285 index 6bd44fe..96f364e 100644
83286 --- a/include/net/sctp/checksum.h
83287 +++ b/include/net/sctp/checksum.h
83288 @@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83289 unsigned int offset)
83290 {
83291 struct sctphdr *sh = sctp_hdr(skb);
83292 - __le32 ret, old = sh->checksum;
83293 - const struct skb_checksum_ops ops = {
83294 + __le32 ret, old = sh->checksum;
83295 + static const struct skb_checksum_ops ops = {
83296 .update = sctp_csum_update,
83297 .combine = sctp_csum_combine,
83298 };
83299 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83300 index 4ef75af..5aa073a 100644
83301 --- a/include/net/sctp/sm.h
83302 +++ b/include/net/sctp/sm.h
83303 @@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83304 typedef struct {
83305 sctp_state_fn_t *fn;
83306 const char *name;
83307 -} sctp_sm_table_entry_t;
83308 +} __do_const sctp_sm_table_entry_t;
83309
83310 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83311 * currently in use.
83312 @@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83313 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83314
83315 /* Extern declarations for major data structures. */
83316 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83317 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83318
83319
83320 /* Get the size of a DATA chunk payload. */
83321 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83322 index 0a248b3..4dcbe5c 100644
83323 --- a/include/net/sctp/structs.h
83324 +++ b/include/net/sctp/structs.h
83325 @@ -508,7 +508,7 @@ struct sctp_pf {
83326 struct sctp_association *asoc);
83327 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83328 struct sctp_af *af;
83329 -};
83330 +} __do_const;
83331
83332
83333 /* Structure to track chunk fragments that have been acked, but peer
83334 diff --git a/include/net/sock.h b/include/net/sock.h
83335 index 2ef3c3e..c89ee4c 100644
83336 --- a/include/net/sock.h
83337 +++ b/include/net/sock.h
83338 @@ -348,7 +348,7 @@ struct sock {
83339 unsigned int sk_napi_id;
83340 unsigned int sk_ll_usec;
83341 #endif
83342 - atomic_t sk_drops;
83343 + atomic_unchecked_t sk_drops;
83344 int sk_rcvbuf;
83345
83346 struct sk_filter __rcu *sk_filter;
83347 @@ -1022,7 +1022,7 @@ struct proto {
83348 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83349 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83350 #endif
83351 -};
83352 +} __randomize_layout;
83353
83354 /*
83355 * Bits in struct cg_proto.flags
83356 @@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83357 return ret >> PAGE_SHIFT;
83358 }
83359
83360 -static inline long
83361 +static inline long __intentional_overflow(-1)
83362 sk_memory_allocated(const struct sock *sk)
83363 {
83364 struct proto *prot = sk->sk_prot;
83365 @@ -1354,7 +1354,7 @@ struct sock_iocb {
83366 struct scm_cookie *scm;
83367 struct msghdr *msg, async_msg;
83368 struct kiocb *kiocb;
83369 -};
83370 +} __randomize_layout;
83371
83372 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83373 {
83374 @@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83375 }
83376
83377 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83378 - char __user *from, char *to,
83379 + char __user *from, unsigned char *to,
83380 int copy, int offset)
83381 {
83382 if (skb->ip_summed == CHECKSUM_NONE) {
83383 @@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83384 }
83385 }
83386
83387 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83388 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83389
83390 /**
83391 * sk_page_frag - return an appropriate page_frag
83392 diff --git a/include/net/tcp.h b/include/net/tcp.h
83393 index 9250d62..10a7f03 100644
83394 --- a/include/net/tcp.h
83395 +++ b/include/net/tcp.h
83396 @@ -480,20 +480,21 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
83397 #ifdef CONFIG_SYN_COOKIES
83398 #include <linux/ktime.h>
83399
83400 -/* Syncookies use a monotonic timer which increments every 64 seconds.
83401 +/* Syncookies use a monotonic timer which increments every 60 seconds.
83402 * This counter is used both as a hash input and partially encoded into
83403 * the cookie value. A cookie is only validated further if the delta
83404 * between the current counter value and the encoded one is less than this,
83405 - * i.e. a sent cookie is valid only at most for 128 seconds (or less if
83406 + * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if
83407 * the counter advances immediately after a cookie is generated).
83408 */
83409 #define MAX_SYNCOOKIE_AGE 2
83410
83411 static inline u32 tcp_cookie_time(void)
83412 {
83413 - struct timespec now;
83414 - getnstimeofday(&now);
83415 - return now.tv_sec >> 6; /* 64 seconds granularity */
83416 + u64 val = get_jiffies_64();
83417 +
83418 + do_div(val, 60 * HZ);
83419 + return val;
83420 }
83421
83422 u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
83423 @@ -540,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83424 void tcp_xmit_retransmit_queue(struct sock *);
83425 void tcp_simple_retransmit(struct sock *);
83426 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83427 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83428 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83429
83430 void tcp_send_probe0(struct sock *);
83431 void tcp_send_partial(struct sock *);
83432 @@ -711,8 +712,8 @@ struct tcp_skb_cb {
83433 struct inet6_skb_parm h6;
83434 #endif
83435 } header; /* For incoming frames */
83436 - __u32 seq; /* Starting sequence number */
83437 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83438 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
83439 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83440 __u32 when; /* used to compute rtt's */
83441 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83442
83443 @@ -726,7 +727,7 @@ struct tcp_skb_cb {
83444
83445 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83446 /* 1 byte hole */
83447 - __u32 ack_seq; /* Sequence number ACK'd */
83448 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83449 };
83450
83451 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83452 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83453 index 6b82fdf..14d74d2 100644
83454 --- a/include/net/xfrm.h
83455 +++ b/include/net/xfrm.h
83456 @@ -287,7 +287,6 @@ struct xfrm_dst;
83457 struct xfrm_policy_afinfo {
83458 unsigned short family;
83459 struct dst_ops *dst_ops;
83460 - void (*garbage_collect)(struct net *net);
83461 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83462 const xfrm_address_t *saddr,
83463 const xfrm_address_t *daddr);
83464 @@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
83465 struct net_device *dev,
83466 const struct flowi *fl);
83467 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83468 -};
83469 +} __do_const;
83470
83471 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83472 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83473 @@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
83474 int (*transport_finish)(struct sk_buff *skb,
83475 int async);
83476 void (*local_error)(struct sk_buff *skb, u32 mtu);
83477 -};
83478 +} __do_const;
83479
83480 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83481 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83482 @@ -429,7 +428,7 @@ struct xfrm_mode {
83483 struct module *owner;
83484 unsigned int encap;
83485 int flags;
83486 -};
83487 +} __do_const;
83488
83489 /* Flags for xfrm_mode. */
83490 enum {
83491 @@ -526,7 +525,7 @@ struct xfrm_policy {
83492 struct timer_list timer;
83493
83494 struct flow_cache_object flo;
83495 - atomic_t genid;
83496 + atomic_unchecked_t genid;
83497 u32 priority;
83498 u32 index;
83499 struct xfrm_mark mark;
83500 @@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83501 }
83502
83503 void xfrm_garbage_collect(struct net *net);
83504 +void xfrm_garbage_collect_deferred(struct net *net);
83505
83506 #else
83507
83508 @@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83509 static inline void xfrm_garbage_collect(struct net *net)
83510 {
83511 }
83512 +static inline void xfrm_garbage_collect_deferred(struct net *net)
83513 +{
83514 +}
83515 #endif
83516
83517 static __inline__
83518 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83519 index 1017e0b..227aa4d 100644
83520 --- a/include/rdma/iw_cm.h
83521 +++ b/include/rdma/iw_cm.h
83522 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
83523 int backlog);
83524
83525 int (*destroy_listen)(struct iw_cm_id *cm_id);
83526 -};
83527 +} __no_const;
83528
83529 /**
83530 * iw_create_cm_id - Create an IW CM identifier.
83531 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83532 index 52beadf..598734c 100644
83533 --- a/include/scsi/libfc.h
83534 +++ b/include/scsi/libfc.h
83535 @@ -771,6 +771,7 @@ struct libfc_function_template {
83536 */
83537 void (*disc_stop_final) (struct fc_lport *);
83538 };
83539 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83540
83541 /**
83542 * struct fc_disc - Discovery context
83543 @@ -875,7 +876,7 @@ struct fc_lport {
83544 struct fc_vport *vport;
83545
83546 /* Operational Information */
83547 - struct libfc_function_template tt;
83548 + libfc_function_template_no_const tt;
83549 u8 link_up;
83550 u8 qfull;
83551 enum fc_lport_state state;
83552 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83553 index d65fbec..f80fef2 100644
83554 --- a/include/scsi/scsi_device.h
83555 +++ b/include/scsi/scsi_device.h
83556 @@ -180,9 +180,9 @@ struct scsi_device {
83557 unsigned int max_device_blocked; /* what device_blocked counts down from */
83558 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83559
83560 - atomic_t iorequest_cnt;
83561 - atomic_t iodone_cnt;
83562 - atomic_t ioerr_cnt;
83563 + atomic_unchecked_t iorequest_cnt;
83564 + atomic_unchecked_t iodone_cnt;
83565 + atomic_unchecked_t ioerr_cnt;
83566
83567 struct device sdev_gendev,
83568 sdev_dev;
83569 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83570 index b797e8f..8e2c3aa 100644
83571 --- a/include/scsi/scsi_transport_fc.h
83572 +++ b/include/scsi/scsi_transport_fc.h
83573 @@ -751,7 +751,8 @@ struct fc_function_template {
83574 unsigned long show_host_system_hostname:1;
83575
83576 unsigned long disable_target_scan:1;
83577 -};
83578 +} __do_const;
83579 +typedef struct fc_function_template __no_const fc_function_template_no_const;
83580
83581
83582 /**
83583 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83584 index ae6c3b8..fd748ac 100644
83585 --- a/include/sound/compress_driver.h
83586 +++ b/include/sound/compress_driver.h
83587 @@ -128,7 +128,7 @@ struct snd_compr_ops {
83588 struct snd_compr_caps *caps);
83589 int (*get_codec_caps) (struct snd_compr_stream *stream,
83590 struct snd_compr_codec_caps *codec);
83591 -};
83592 +} __no_const;
83593
83594 /**
83595 * struct snd_compr: Compressed device
83596 diff --git a/include/sound/soc.h b/include/sound/soc.h
83597 index 1f741cb..8cefc08 100644
83598 --- a/include/sound/soc.h
83599 +++ b/include/sound/soc.h
83600 @@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
83601 /* probe ordering - for components with runtime dependencies */
83602 int probe_order;
83603 int remove_order;
83604 -};
83605 +} __do_const;
83606
83607 /* SoC platform interface */
83608 struct snd_soc_platform_driver {
83609 @@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
83610 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83611 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83612 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83613 -};
83614 +} __do_const;
83615
83616 struct snd_soc_platform {
83617 const char *name;
83618 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83619 index e3569f8..6544ffd 100644
83620 --- a/include/target/target_core_base.h
83621 +++ b/include/target/target_core_base.h
83622 @@ -687,7 +687,7 @@ struct se_device {
83623 atomic_long_t write_bytes;
83624 /* Active commands on this virtual SE device */
83625 atomic_t simple_cmds;
83626 - atomic_t dev_ordered_id;
83627 + atomic_unchecked_t dev_ordered_id;
83628 atomic_t dev_ordered_sync;
83629 atomic_t dev_qf_count;
83630 int export_count;
83631 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83632 new file mode 100644
83633 index 0000000..fb634b7
83634 --- /dev/null
83635 +++ b/include/trace/events/fs.h
83636 @@ -0,0 +1,53 @@
83637 +#undef TRACE_SYSTEM
83638 +#define TRACE_SYSTEM fs
83639 +
83640 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83641 +#define _TRACE_FS_H
83642 +
83643 +#include <linux/fs.h>
83644 +#include <linux/tracepoint.h>
83645 +
83646 +TRACE_EVENT(do_sys_open,
83647 +
83648 + TP_PROTO(const char *filename, int flags, int mode),
83649 +
83650 + TP_ARGS(filename, flags, mode),
83651 +
83652 + TP_STRUCT__entry(
83653 + __string( filename, filename )
83654 + __field( int, flags )
83655 + __field( int, mode )
83656 + ),
83657 +
83658 + TP_fast_assign(
83659 + __assign_str(filename, filename);
83660 + __entry->flags = flags;
83661 + __entry->mode = mode;
83662 + ),
83663 +
83664 + TP_printk("\"%s\" %x %o",
83665 + __get_str(filename), __entry->flags, __entry->mode)
83666 +);
83667 +
83668 +TRACE_EVENT(open_exec,
83669 +
83670 + TP_PROTO(const char *filename),
83671 +
83672 + TP_ARGS(filename),
83673 +
83674 + TP_STRUCT__entry(
83675 + __string( filename, filename )
83676 + ),
83677 +
83678 + TP_fast_assign(
83679 + __assign_str(filename, filename);
83680 + ),
83681 +
83682 + TP_printk("\"%s\"",
83683 + __get_str(filename))
83684 +);
83685 +
83686 +#endif /* _TRACE_FS_H */
83687 +
83688 +/* This part must be outside protection */
83689 +#include <trace/define_trace.h>
83690 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83691 index 1c09820..7f5ec79 100644
83692 --- a/include/trace/events/irq.h
83693 +++ b/include/trace/events/irq.h
83694 @@ -36,7 +36,7 @@ struct softirq_action;
83695 */
83696 TRACE_EVENT(irq_handler_entry,
83697
83698 - TP_PROTO(int irq, struct irqaction *action),
83699 + TP_PROTO(int irq, const struct irqaction *action),
83700
83701 TP_ARGS(irq, action),
83702
83703 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83704 */
83705 TRACE_EVENT(irq_handler_exit,
83706
83707 - TP_PROTO(int irq, struct irqaction *action, int ret),
83708 + TP_PROTO(int irq, const struct irqaction *action, int ret),
83709
83710 TP_ARGS(irq, action, ret),
83711
83712 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83713 index 7caf44c..23c6f27 100644
83714 --- a/include/uapi/linux/a.out.h
83715 +++ b/include/uapi/linux/a.out.h
83716 @@ -39,6 +39,14 @@ enum machine_type {
83717 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83718 };
83719
83720 +/* Constants for the N_FLAGS field */
83721 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83722 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83723 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83724 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83725 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83726 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83727 +
83728 #if !defined (N_MAGIC)
83729 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83730 #endif
83731 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83732 index d876736..ccce5c0 100644
83733 --- a/include/uapi/linux/byteorder/little_endian.h
83734 +++ b/include/uapi/linux/byteorder/little_endian.h
83735 @@ -42,51 +42,51 @@
83736
83737 static inline __le64 __cpu_to_le64p(const __u64 *p)
83738 {
83739 - return (__force __le64)*p;
83740 + return (__force const __le64)*p;
83741 }
83742 -static inline __u64 __le64_to_cpup(const __le64 *p)
83743 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83744 {
83745 - return (__force __u64)*p;
83746 + return (__force const __u64)*p;
83747 }
83748 static inline __le32 __cpu_to_le32p(const __u32 *p)
83749 {
83750 - return (__force __le32)*p;
83751 + return (__force const __le32)*p;
83752 }
83753 static inline __u32 __le32_to_cpup(const __le32 *p)
83754 {
83755 - return (__force __u32)*p;
83756 + return (__force const __u32)*p;
83757 }
83758 static inline __le16 __cpu_to_le16p(const __u16 *p)
83759 {
83760 - return (__force __le16)*p;
83761 + return (__force const __le16)*p;
83762 }
83763 static inline __u16 __le16_to_cpup(const __le16 *p)
83764 {
83765 - return (__force __u16)*p;
83766 + return (__force const __u16)*p;
83767 }
83768 static inline __be64 __cpu_to_be64p(const __u64 *p)
83769 {
83770 - return (__force __be64)__swab64p(p);
83771 + return (__force const __be64)__swab64p(p);
83772 }
83773 static inline __u64 __be64_to_cpup(const __be64 *p)
83774 {
83775 - return __swab64p((__u64 *)p);
83776 + return __swab64p((const __u64 *)p);
83777 }
83778 static inline __be32 __cpu_to_be32p(const __u32 *p)
83779 {
83780 - return (__force __be32)__swab32p(p);
83781 + return (__force const __be32)__swab32p(p);
83782 }
83783 -static inline __u32 __be32_to_cpup(const __be32 *p)
83784 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83785 {
83786 - return __swab32p((__u32 *)p);
83787 + return __swab32p((const __u32 *)p);
83788 }
83789 static inline __be16 __cpu_to_be16p(const __u16 *p)
83790 {
83791 - return (__force __be16)__swab16p(p);
83792 + return (__force const __be16)__swab16p(p);
83793 }
83794 static inline __u16 __be16_to_cpup(const __be16 *p)
83795 {
83796 - return __swab16p((__u16 *)p);
83797 + return __swab16p((const __u16 *)p);
83798 }
83799 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83800 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83801 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83802 index ef6103b..d4e65dd 100644
83803 --- a/include/uapi/linux/elf.h
83804 +++ b/include/uapi/linux/elf.h
83805 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83806 #define PT_GNU_EH_FRAME 0x6474e550
83807
83808 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83809 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83810 +
83811 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83812 +
83813 +/* Constants for the e_flags field */
83814 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83815 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83816 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83817 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83818 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83819 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83820
83821 /*
83822 * Extended Numbering
83823 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83824 #define DT_DEBUG 21
83825 #define DT_TEXTREL 22
83826 #define DT_JMPREL 23
83827 +#define DT_FLAGS 30
83828 + #define DF_TEXTREL 0x00000004
83829 #define DT_ENCODING 32
83830 #define OLD_DT_LOOS 0x60000000
83831 #define DT_LOOS 0x6000000d
83832 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
83833 #define PF_W 0x2
83834 #define PF_X 0x1
83835
83836 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
83837 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
83838 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
83839 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
83840 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
83841 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
83842 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
83843 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
83844 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
83845 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
83846 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
83847 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
83848 +
83849 typedef struct elf32_phdr{
83850 Elf32_Word p_type;
83851 Elf32_Off p_offset;
83852 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
83853 #define EI_OSABI 7
83854 #define EI_PAD 8
83855
83856 +#define EI_PAX 14
83857 +
83858 #define ELFMAG0 0x7f /* EI_MAG */
83859 #define ELFMAG1 'E'
83860 #define ELFMAG2 'L'
83861 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
83862 index aa169c4..6a2771d 100644
83863 --- a/include/uapi/linux/personality.h
83864 +++ b/include/uapi/linux/personality.h
83865 @@ -30,6 +30,7 @@ enum {
83866 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
83867 ADDR_NO_RANDOMIZE | \
83868 ADDR_COMPAT_LAYOUT | \
83869 + ADDR_LIMIT_3GB | \
83870 MMAP_PAGE_ZERO)
83871
83872 /*
83873 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
83874 index 7530e74..e714828 100644
83875 --- a/include/uapi/linux/screen_info.h
83876 +++ b/include/uapi/linux/screen_info.h
83877 @@ -43,7 +43,8 @@ struct screen_info {
83878 __u16 pages; /* 0x32 */
83879 __u16 vesa_attributes; /* 0x34 */
83880 __u32 capabilities; /* 0x36 */
83881 - __u8 _reserved[6]; /* 0x3a */
83882 + __u16 vesapm_size; /* 0x3a */
83883 + __u8 _reserved[4]; /* 0x3c */
83884 } __attribute__((packed));
83885
83886 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
83887 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
83888 index 0e011eb..82681b1 100644
83889 --- a/include/uapi/linux/swab.h
83890 +++ b/include/uapi/linux/swab.h
83891 @@ -43,7 +43,7 @@
83892 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
83893 */
83894
83895 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
83896 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
83897 {
83898 #ifdef __HAVE_BUILTIN_BSWAP16__
83899 return __builtin_bswap16(val);
83900 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
83901 #endif
83902 }
83903
83904 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
83905 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
83906 {
83907 #ifdef __HAVE_BUILTIN_BSWAP32__
83908 return __builtin_bswap32(val);
83909 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
83910 #endif
83911 }
83912
83913 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
83914 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
83915 {
83916 #ifdef __HAVE_BUILTIN_BSWAP64__
83917 return __builtin_bswap64(val);
83918 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
83919 index 6d67213..552fdd9 100644
83920 --- a/include/uapi/linux/sysctl.h
83921 +++ b/include/uapi/linux/sysctl.h
83922 @@ -155,8 +155,6 @@ enum
83923 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
83924 };
83925
83926 -
83927 -
83928 /* CTL_VM names: */
83929 enum
83930 {
83931 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
83932 index 437f1b0..0eeb38d 100644
83933 --- a/include/uapi/linux/videodev2.h
83934 +++ b/include/uapi/linux/videodev2.h
83935 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
83936 union {
83937 __s32 value;
83938 __s64 value64;
83939 - char *string;
83940 + char __user *string;
83941 };
83942 } __attribute__ ((packed));
83943
83944 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
83945 index e4629b9..6958086 100644
83946 --- a/include/uapi/linux/xattr.h
83947 +++ b/include/uapi/linux/xattr.h
83948 @@ -63,5 +63,9 @@
83949 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
83950 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
83951
83952 +/* User namespace */
83953 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
83954 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
83955 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
83956
83957 #endif /* _UAPI_LINUX_XATTR_H */
83958 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
83959 index f9466fa..f4e2b81 100644
83960 --- a/include/video/udlfb.h
83961 +++ b/include/video/udlfb.h
83962 @@ -53,10 +53,10 @@ struct dlfb_data {
83963 u32 pseudo_palette[256];
83964 int blank_mode; /*one of FB_BLANK_ */
83965 /* blit-only rendering path metrics, exposed through sysfs */
83966 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83967 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
83968 - atomic_t bytes_sent; /* to usb, after compression including overhead */
83969 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
83970 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83971 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
83972 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
83973 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
83974 };
83975
83976 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
83977 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
83978 index 30f5362..8ed8ac9 100644
83979 --- a/include/video/uvesafb.h
83980 +++ b/include/video/uvesafb.h
83981 @@ -122,6 +122,7 @@ struct uvesafb_par {
83982 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
83983 u8 pmi_setpal; /* PMI for palette changes */
83984 u16 *pmi_base; /* protected mode interface location */
83985 + u8 *pmi_code; /* protected mode code location */
83986 void *pmi_start;
83987 void *pmi_pal;
83988 u8 *vbe_state_orig; /*
83989 diff --git a/init/Kconfig b/init/Kconfig
83990 index 4e5d96a..93cd8a1 100644
83991 --- a/init/Kconfig
83992 +++ b/init/Kconfig
83993 @@ -1079,6 +1079,7 @@ endif # CGROUPS
83994
83995 config CHECKPOINT_RESTORE
83996 bool "Checkpoint/restore support" if EXPERT
83997 + depends on !GRKERNSEC
83998 default n
83999 help
84000 Enables additional kernel features in a sake of checkpoint/restore.
84001 @@ -1550,7 +1551,7 @@ config SLUB_DEBUG
84002
84003 config COMPAT_BRK
84004 bool "Disable heap randomization"
84005 - default y
84006 + default n
84007 help
84008 Randomizing heap placement makes heap exploits harder, but it
84009 also breaks ancient binaries (including anything libc5 based).
84010 @@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
84011 config STOP_MACHINE
84012 bool
84013 default y
84014 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84015 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84016 help
84017 Need stop_machine() primitive.
84018
84019 diff --git a/init/Makefile b/init/Makefile
84020 index 7bc47ee..6da2dc7 100644
84021 --- a/init/Makefile
84022 +++ b/init/Makefile
84023 @@ -2,6 +2,9 @@
84024 # Makefile for the linux kernel.
84025 #
84026
84027 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
84028 +asflags-y := $(GCC_PLUGINS_AFLAGS)
84029 +
84030 obj-y := main.o version.o mounts.o
84031 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84032 obj-y += noinitramfs.o
84033 diff --git a/init/do_mounts.c b/init/do_mounts.c
84034 index 8e5addc..c96ea61 100644
84035 --- a/init/do_mounts.c
84036 +++ b/init/do_mounts.c
84037 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84038 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84039 {
84040 struct super_block *s;
84041 - int err = sys_mount(name, "/root", fs, flags, data);
84042 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84043 if (err)
84044 return err;
84045
84046 - sys_chdir("/root");
84047 + sys_chdir((const char __force_user *)"/root");
84048 s = current->fs->pwd.dentry->d_sb;
84049 ROOT_DEV = s->s_dev;
84050 printk(KERN_INFO
84051 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84052 va_start(args, fmt);
84053 vsprintf(buf, fmt, args);
84054 va_end(args);
84055 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84056 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84057 if (fd >= 0) {
84058 sys_ioctl(fd, FDEJECT, 0);
84059 sys_close(fd);
84060 }
84061 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84062 - fd = sys_open("/dev/console", O_RDWR, 0);
84063 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84064 if (fd >= 0) {
84065 sys_ioctl(fd, TCGETS, (long)&termios);
84066 termios.c_lflag &= ~ICANON;
84067 sys_ioctl(fd, TCSETSF, (long)&termios);
84068 - sys_read(fd, &c, 1);
84069 + sys_read(fd, (char __user *)&c, 1);
84070 termios.c_lflag |= ICANON;
84071 sys_ioctl(fd, TCSETSF, (long)&termios);
84072 sys_close(fd);
84073 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84074 mount_root();
84075 out:
84076 devtmpfs_mount("dev");
84077 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84078 - sys_chroot(".");
84079 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84080 + sys_chroot((const char __force_user *)".");
84081 }
84082
84083 static bool is_tmpfs;
84084 diff --git a/init/do_mounts.h b/init/do_mounts.h
84085 index f5b978a..69dbfe8 100644
84086 --- a/init/do_mounts.h
84087 +++ b/init/do_mounts.h
84088 @@ -15,15 +15,15 @@ extern int root_mountflags;
84089
84090 static inline int create_dev(char *name, dev_t dev)
84091 {
84092 - sys_unlink(name);
84093 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84094 + sys_unlink((char __force_user *)name);
84095 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84096 }
84097
84098 #if BITS_PER_LONG == 32
84099 static inline u32 bstat(char *name)
84100 {
84101 struct stat64 stat;
84102 - if (sys_stat64(name, &stat) != 0)
84103 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84104 return 0;
84105 if (!S_ISBLK(stat.st_mode))
84106 return 0;
84107 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84108 static inline u32 bstat(char *name)
84109 {
84110 struct stat stat;
84111 - if (sys_newstat(name, &stat) != 0)
84112 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84113 return 0;
84114 if (!S_ISBLK(stat.st_mode))
84115 return 0;
84116 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84117 index 3e0878e..8a9d7a0 100644
84118 --- a/init/do_mounts_initrd.c
84119 +++ b/init/do_mounts_initrd.c
84120 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84121 {
84122 sys_unshare(CLONE_FS | CLONE_FILES);
84123 /* stdin/stdout/stderr for /linuxrc */
84124 - sys_open("/dev/console", O_RDWR, 0);
84125 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84126 sys_dup(0);
84127 sys_dup(0);
84128 /* move initrd over / and chdir/chroot in initrd root */
84129 - sys_chdir("/root");
84130 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84131 - sys_chroot(".");
84132 + sys_chdir((const char __force_user *)"/root");
84133 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84134 + sys_chroot((const char __force_user *)".");
84135 sys_setsid();
84136 return 0;
84137 }
84138 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84139 create_dev("/dev/root.old", Root_RAM0);
84140 /* mount initrd on rootfs' /root */
84141 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84142 - sys_mkdir("/old", 0700);
84143 - sys_chdir("/old");
84144 + sys_mkdir((const char __force_user *)"/old", 0700);
84145 + sys_chdir((const char __force_user *)"/old");
84146
84147 /* try loading default modules from initrd */
84148 load_default_modules();
84149 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84150 current->flags &= ~PF_FREEZER_SKIP;
84151
84152 /* move initrd to rootfs' /old */
84153 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
84154 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84155 /* switch root and cwd back to / of rootfs */
84156 - sys_chroot("..");
84157 + sys_chroot((const char __force_user *)"..");
84158
84159 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84160 - sys_chdir("/old");
84161 + sys_chdir((const char __force_user *)"/old");
84162 return;
84163 }
84164
84165 - sys_chdir("/");
84166 + sys_chdir((const char __force_user *)"/");
84167 ROOT_DEV = new_decode_dev(real_root_dev);
84168 mount_root();
84169
84170 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84171 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84172 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84173 if (!error)
84174 printk("okay\n");
84175 else {
84176 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
84177 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84178 if (error == -ENOENT)
84179 printk("/initrd does not exist. Ignored.\n");
84180 else
84181 printk("failed\n");
84182 printk(KERN_NOTICE "Unmounting old root\n");
84183 - sys_umount("/old", MNT_DETACH);
84184 + sys_umount((char __force_user *)"/old", MNT_DETACH);
84185 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84186 if (fd < 0) {
84187 error = fd;
84188 @@ -127,11 +127,11 @@ int __init initrd_load(void)
84189 * mounted in the normal path.
84190 */
84191 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84192 - sys_unlink("/initrd.image");
84193 + sys_unlink((const char __force_user *)"/initrd.image");
84194 handle_initrd();
84195 return 1;
84196 }
84197 }
84198 - sys_unlink("/initrd.image");
84199 + sys_unlink((const char __force_user *)"/initrd.image");
84200 return 0;
84201 }
84202 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84203 index 8cb6db5..d729f50 100644
84204 --- a/init/do_mounts_md.c
84205 +++ b/init/do_mounts_md.c
84206 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84207 partitioned ? "_d" : "", minor,
84208 md_setup_args[ent].device_names);
84209
84210 - fd = sys_open(name, 0, 0);
84211 + fd = sys_open((char __force_user *)name, 0, 0);
84212 if (fd < 0) {
84213 printk(KERN_ERR "md: open failed - cannot start "
84214 "array %s\n", name);
84215 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84216 * array without it
84217 */
84218 sys_close(fd);
84219 - fd = sys_open(name, 0, 0);
84220 + fd = sys_open((char __force_user *)name, 0, 0);
84221 sys_ioctl(fd, BLKRRPART, 0);
84222 }
84223 sys_close(fd);
84224 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84225
84226 wait_for_device_probe();
84227
84228 - fd = sys_open("/dev/md0", 0, 0);
84229 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84230 if (fd >= 0) {
84231 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84232 sys_close(fd);
84233 diff --git a/init/init_task.c b/init/init_task.c
84234 index ba0a7f36..2bcf1d5 100644
84235 --- a/init/init_task.c
84236 +++ b/init/init_task.c
84237 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84238 * Initial thread structure. Alignment of this is handled by a special
84239 * linker map entry.
84240 */
84241 +#ifdef CONFIG_X86
84242 +union thread_union init_thread_union __init_task_data;
84243 +#else
84244 union thread_union init_thread_union __init_task_data =
84245 { INIT_THREAD_INFO(init_task) };
84246 +#endif
84247 diff --git a/init/initramfs.c b/init/initramfs.c
84248 index a67ef9d..2d17ed9 100644
84249 --- a/init/initramfs.c
84250 +++ b/init/initramfs.c
84251 @@ -84,7 +84,7 @@ static void __init free_hash(void)
84252 }
84253 }
84254
84255 -static long __init do_utime(char *filename, time_t mtime)
84256 +static long __init do_utime(char __force_user *filename, time_t mtime)
84257 {
84258 struct timespec t[2];
84259
84260 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
84261 struct dir_entry *de, *tmp;
84262 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84263 list_del(&de->list);
84264 - do_utime(de->name, de->mtime);
84265 + do_utime((char __force_user *)de->name, de->mtime);
84266 kfree(de->name);
84267 kfree(de);
84268 }
84269 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
84270 if (nlink >= 2) {
84271 char *old = find_link(major, minor, ino, mode, collected);
84272 if (old)
84273 - return (sys_link(old, collected) < 0) ? -1 : 1;
84274 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84275 }
84276 return 0;
84277 }
84278 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84279 {
84280 struct stat st;
84281
84282 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84283 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84284 if (S_ISDIR(st.st_mode))
84285 - sys_rmdir(path);
84286 + sys_rmdir((char __force_user *)path);
84287 else
84288 - sys_unlink(path);
84289 + sys_unlink((char __force_user *)path);
84290 }
84291 }
84292
84293 @@ -315,7 +315,7 @@ static int __init do_name(void)
84294 int openflags = O_WRONLY|O_CREAT;
84295 if (ml != 1)
84296 openflags |= O_TRUNC;
84297 - wfd = sys_open(collected, openflags, mode);
84298 + wfd = sys_open((char __force_user *)collected, openflags, mode);
84299
84300 if (wfd >= 0) {
84301 sys_fchown(wfd, uid, gid);
84302 @@ -327,17 +327,17 @@ static int __init do_name(void)
84303 }
84304 }
84305 } else if (S_ISDIR(mode)) {
84306 - sys_mkdir(collected, mode);
84307 - sys_chown(collected, uid, gid);
84308 - sys_chmod(collected, mode);
84309 + sys_mkdir((char __force_user *)collected, mode);
84310 + sys_chown((char __force_user *)collected, uid, gid);
84311 + sys_chmod((char __force_user *)collected, mode);
84312 dir_add(collected, mtime);
84313 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84314 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84315 if (maybe_link() == 0) {
84316 - sys_mknod(collected, mode, rdev);
84317 - sys_chown(collected, uid, gid);
84318 - sys_chmod(collected, mode);
84319 - do_utime(collected, mtime);
84320 + sys_mknod((char __force_user *)collected, mode, rdev);
84321 + sys_chown((char __force_user *)collected, uid, gid);
84322 + sys_chmod((char __force_user *)collected, mode);
84323 + do_utime((char __force_user *)collected, mtime);
84324 }
84325 }
84326 return 0;
84327 @@ -346,15 +346,15 @@ static int __init do_name(void)
84328 static int __init do_copy(void)
84329 {
84330 if (count >= body_len) {
84331 - sys_write(wfd, victim, body_len);
84332 + sys_write(wfd, (char __force_user *)victim, body_len);
84333 sys_close(wfd);
84334 - do_utime(vcollected, mtime);
84335 + do_utime((char __force_user *)vcollected, mtime);
84336 kfree(vcollected);
84337 eat(body_len);
84338 state = SkipIt;
84339 return 0;
84340 } else {
84341 - sys_write(wfd, victim, count);
84342 + sys_write(wfd, (char __force_user *)victim, count);
84343 body_len -= count;
84344 eat(count);
84345 return 1;
84346 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
84347 {
84348 collected[N_ALIGN(name_len) + body_len] = '\0';
84349 clean_path(collected, 0);
84350 - sys_symlink(collected + N_ALIGN(name_len), collected);
84351 - sys_lchown(collected, uid, gid);
84352 - do_utime(collected, mtime);
84353 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84354 + sys_lchown((char __force_user *)collected, uid, gid);
84355 + do_utime((char __force_user *)collected, mtime);
84356 state = SkipIt;
84357 next_state = Reset;
84358 return 0;
84359 @@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
84360 {
84361 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
84362 if (err)
84363 - panic(err); /* Failed to decompress INTERNAL initramfs */
84364 + panic("%s", err); /* Failed to decompress INTERNAL initramfs */
84365 if (initrd_start) {
84366 #ifdef CONFIG_BLK_DEV_RAM
84367 int fd;
84368 diff --git a/init/main.c b/init/main.c
84369 index febc511..f0851763 100644
84370 --- a/init/main.c
84371 +++ b/init/main.c
84372 @@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
84373 extern void tc_init(void);
84374 #endif
84375
84376 +extern void grsecurity_init(void);
84377 +
84378 /*
84379 * Debug helper: via this flag we know that we are in 'early bootup code'
84380 * where only the boot processor is running with IRQ disabled. This means
84381 @@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
84382
84383 __setup("reset_devices", set_reset_devices);
84384
84385 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84386 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84387 +static int __init setup_grsec_proc_gid(char *str)
84388 +{
84389 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84390 + return 1;
84391 +}
84392 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84393 +#endif
84394 +
84395 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84396 +unsigned long pax_user_shadow_base __read_only;
84397 +EXPORT_SYMBOL(pax_user_shadow_base);
84398 +extern char pax_enter_kernel_user[];
84399 +extern char pax_exit_kernel_user[];
84400 +#endif
84401 +
84402 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84403 +static int __init setup_pax_nouderef(char *str)
84404 +{
84405 +#ifdef CONFIG_X86_32
84406 + unsigned int cpu;
84407 + struct desc_struct *gdt;
84408 +
84409 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84410 + gdt = get_cpu_gdt_table(cpu);
84411 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84412 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84413 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84414 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84415 + }
84416 + loadsegment(ds, __KERNEL_DS);
84417 + loadsegment(es, __KERNEL_DS);
84418 + loadsegment(ss, __KERNEL_DS);
84419 +#else
84420 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84421 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84422 + clone_pgd_mask = ~(pgdval_t)0UL;
84423 + pax_user_shadow_base = 0UL;
84424 + setup_clear_cpu_cap(X86_FEATURE_PCID);
84425 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84426 +#endif
84427 +
84428 + return 0;
84429 +}
84430 +early_param("pax_nouderef", setup_pax_nouderef);
84431 +
84432 +#ifdef CONFIG_X86_64
84433 +static int __init setup_pax_weakuderef(char *str)
84434 +{
84435 + if (clone_pgd_mask != ~(pgdval_t)0UL)
84436 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84437 + return 1;
84438 +}
84439 +__setup("pax_weakuderef", setup_pax_weakuderef);
84440 +#endif
84441 +#endif
84442 +
84443 +#ifdef CONFIG_PAX_SOFTMODE
84444 +int pax_softmode;
84445 +
84446 +static int __init setup_pax_softmode(char *str)
84447 +{
84448 + get_option(&str, &pax_softmode);
84449 + return 1;
84450 +}
84451 +__setup("pax_softmode=", setup_pax_softmode);
84452 +#endif
84453 +
84454 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84455 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84456 static const char *panic_later, *panic_param;
84457 @@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84458 {
84459 int count = preempt_count();
84460 int ret;
84461 - char msgbuf[64];
84462 + const char *msg1 = "", *msg2 = "";
84463
84464 if (initcall_debug)
84465 ret = do_one_initcall_debug(fn);
84466 else
84467 ret = fn();
84468
84469 - msgbuf[0] = 0;
84470 -
84471 if (preempt_count() != count) {
84472 - sprintf(msgbuf, "preemption imbalance ");
84473 + msg1 = " preemption imbalance";
84474 preempt_count_set(count);
84475 }
84476 if (irqs_disabled()) {
84477 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84478 + msg2 = " disabled interrupts";
84479 local_irq_enable();
84480 }
84481 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84482 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84483
84484 + add_latent_entropy();
84485 return ret;
84486 }
84487
84488 @@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
84489 {
84490 argv_init[0] = init_filename;
84491 return do_execve(init_filename,
84492 - (const char __user *const __user *)argv_init,
84493 - (const char __user *const __user *)envp_init);
84494 + (const char __user *const __force_user *)argv_init,
84495 + (const char __user *const __force_user *)envp_init);
84496 }
84497
84498 static int try_to_run_init_process(const char *init_filename)
84499 @@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
84500 return ret;
84501 }
84502
84503 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84504 +extern int gr_init_ran;
84505 +#endif
84506 +
84507 static noinline void __init kernel_init_freeable(void);
84508
84509 static int __ref kernel_init(void *unused)
84510 @@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
84511 ramdisk_execute_command, ret);
84512 }
84513
84514 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84515 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
84516 + gr_init_ran = 1;
84517 +#endif
84518 +
84519 /*
84520 * We try each of these until one succeeds.
84521 *
84522 @@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
84523 do_basic_setup();
84524
84525 /* Open the /dev/console on the rootfs, this should never fail */
84526 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84527 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84528 pr_err("Warning: unable to open an initial console.\n");
84529
84530 (void) sys_dup(0);
84531 @@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
84532 if (!ramdisk_execute_command)
84533 ramdisk_execute_command = "/init";
84534
84535 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84536 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84537 ramdisk_execute_command = NULL;
84538 prepare_namespace();
84539 }
84540
84541 + grsecurity_init();
84542 +
84543 /*
84544 * Ok, we have completed the initial bootup, and
84545 * we're essentially up and running. Get rid of the
84546 diff --git a/ipc/compat.c b/ipc/compat.c
84547 index 892f658..e7c6320 100644
84548 --- a/ipc/compat.c
84549 +++ b/ipc/compat.c
84550 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84551 COMPAT_SHMLBA);
84552 if (err < 0)
84553 return err;
84554 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84555 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84556 }
84557 case SHMDT:
84558 return sys_shmdt(compat_ptr(ptr));
84559 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84560 index b0e99de..09f385c 100644
84561 --- a/ipc/ipc_sysctl.c
84562 +++ b/ipc/ipc_sysctl.c
84563 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84564 static int proc_ipc_dointvec(ctl_table *table, int write,
84565 void __user *buffer, size_t *lenp, loff_t *ppos)
84566 {
84567 - struct ctl_table ipc_table;
84568 + ctl_table_no_const ipc_table;
84569
84570 memcpy(&ipc_table, table, sizeof(ipc_table));
84571 ipc_table.data = get_ipc(table);
84572 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84573 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84574 void __user *buffer, size_t *lenp, loff_t *ppos)
84575 {
84576 - struct ctl_table ipc_table;
84577 + ctl_table_no_const ipc_table;
84578
84579 memcpy(&ipc_table, table, sizeof(ipc_table));
84580 ipc_table.data = get_ipc(table);
84581 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84582 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84583 void __user *buffer, size_t *lenp, loff_t *ppos)
84584 {
84585 - struct ctl_table ipc_table;
84586 + ctl_table_no_const ipc_table;
84587 size_t lenp_bef = *lenp;
84588 int rc;
84589
84590 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84591 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84592 void __user *buffer, size_t *lenp, loff_t *ppos)
84593 {
84594 - struct ctl_table ipc_table;
84595 + ctl_table_no_const ipc_table;
84596 memcpy(&ipc_table, table, sizeof(ipc_table));
84597 ipc_table.data = get_ipc(table);
84598
84599 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84600 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84601 void __user *buffer, size_t *lenp, loff_t *ppos)
84602 {
84603 - struct ctl_table ipc_table;
84604 + ctl_table_no_const ipc_table;
84605 size_t lenp_bef = *lenp;
84606 int oldval;
84607 int rc;
84608 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84609 index 5bb8bfe..a38ec05 100644
84610 --- a/ipc/mq_sysctl.c
84611 +++ b/ipc/mq_sysctl.c
84612 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84613 static int proc_mq_dointvec(ctl_table *table, int write,
84614 void __user *buffer, size_t *lenp, loff_t *ppos)
84615 {
84616 - struct ctl_table mq_table;
84617 + ctl_table_no_const mq_table;
84618 memcpy(&mq_table, table, sizeof(mq_table));
84619 mq_table.data = get_mq(table);
84620
84621 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84622 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84623 void __user *buffer, size_t *lenp, loff_t *ppos)
84624 {
84625 - struct ctl_table mq_table;
84626 + ctl_table_no_const mq_table;
84627 memcpy(&mq_table, table, sizeof(mq_table));
84628 mq_table.data = get_mq(table);
84629
84630 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84631 index b8d4aed..96a4fe8 100644
84632 --- a/ipc/mqueue.c
84633 +++ b/ipc/mqueue.c
84634 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84635 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84636 info->attr.mq_msgsize);
84637
84638 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84639 spin_lock(&mq_lock);
84640 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84641 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84642 diff --git a/ipc/msg.c b/ipc/msg.c
84643 index 52770bf..1c60a6f 100644
84644 --- a/ipc/msg.c
84645 +++ b/ipc/msg.c
84646 @@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84647 return security_msg_queue_associate(msq, msgflg);
84648 }
84649
84650 +static struct ipc_ops msg_ops = {
84651 + .getnew = newque,
84652 + .associate = msg_security,
84653 + .more_checks = NULL
84654 +};
84655 +
84656 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84657 {
84658 struct ipc_namespace *ns;
84659 - struct ipc_ops msg_ops;
84660 struct ipc_params msg_params;
84661
84662 ns = current->nsproxy->ipc_ns;
84663
84664 - msg_ops.getnew = newque;
84665 - msg_ops.associate = msg_security;
84666 - msg_ops.more_checks = NULL;
84667 -
84668 msg_params.key = key;
84669 msg_params.flg = msgflg;
84670
84671 diff --git a/ipc/sem.c b/ipc/sem.c
84672 index db9d241..bc8427c 100644
84673 --- a/ipc/sem.c
84674 +++ b/ipc/sem.c
84675 @@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84676 return 0;
84677 }
84678
84679 +static struct ipc_ops sem_ops = {
84680 + .getnew = newary,
84681 + .associate = sem_security,
84682 + .more_checks = sem_more_checks
84683 +};
84684 +
84685 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84686 {
84687 struct ipc_namespace *ns;
84688 - struct ipc_ops sem_ops;
84689 struct ipc_params sem_params;
84690
84691 ns = current->nsproxy->ipc_ns;
84692 @@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84693 if (nsems < 0 || nsems > ns->sc_semmsl)
84694 return -EINVAL;
84695
84696 - sem_ops.getnew = newary;
84697 - sem_ops.associate = sem_security;
84698 - sem_ops.more_checks = sem_more_checks;
84699 -
84700 sem_params.key = key;
84701 sem_params.flg = semflg;
84702 sem_params.u.nsems = nsems;
84703 diff --git a/ipc/shm.c b/ipc/shm.c
84704 index 7a51443..3a257d8 100644
84705 --- a/ipc/shm.c
84706 +++ b/ipc/shm.c
84707 @@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
84708 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84709 #endif
84710
84711 +#ifdef CONFIG_GRKERNSEC
84712 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84713 + const time_t shm_createtime, const kuid_t cuid,
84714 + const int shmid);
84715 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84716 + const time_t shm_createtime);
84717 +#endif
84718 +
84719 void shm_init_ns(struct ipc_namespace *ns)
84720 {
84721 ns->shm_ctlmax = SHMMAX;
84722 @@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84723 shp->shm_lprid = 0;
84724 shp->shm_atim = shp->shm_dtim = 0;
84725 shp->shm_ctim = get_seconds();
84726 +#ifdef CONFIG_GRKERNSEC
84727 + {
84728 + struct timespec timeval;
84729 + do_posix_clock_monotonic_gettime(&timeval);
84730 +
84731 + shp->shm_createtime = timeval.tv_sec;
84732 + }
84733 +#endif
84734 shp->shm_segsz = size;
84735 shp->shm_nattch = 0;
84736 shp->shm_file = file;
84737 @@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84738 return 0;
84739 }
84740
84741 +static struct ipc_ops shm_ops = {
84742 + .getnew = newseg,
84743 + .associate = shm_security,
84744 + .more_checks = shm_more_checks
84745 +};
84746 +
84747 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84748 {
84749 struct ipc_namespace *ns;
84750 - struct ipc_ops shm_ops;
84751 struct ipc_params shm_params;
84752
84753 ns = current->nsproxy->ipc_ns;
84754
84755 - shm_ops.getnew = newseg;
84756 - shm_ops.associate = shm_security;
84757 - shm_ops.more_checks = shm_more_checks;
84758 -
84759 shm_params.key = key;
84760 shm_params.flg = shmflg;
84761 shm_params.u.size = size;
84762 @@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84763 f_mode = FMODE_READ | FMODE_WRITE;
84764 }
84765 if (shmflg & SHM_EXEC) {
84766 +
84767 +#ifdef CONFIG_PAX_MPROTECT
84768 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
84769 + goto out;
84770 +#endif
84771 +
84772 prot |= PROT_EXEC;
84773 acc_mode |= S_IXUGO;
84774 }
84775 @@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84776 if (err)
84777 goto out_unlock;
84778
84779 +#ifdef CONFIG_GRKERNSEC
84780 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84781 + shp->shm_perm.cuid, shmid) ||
84782 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84783 + err = -EACCES;
84784 + goto out_unlock;
84785 + }
84786 +#endif
84787 +
84788 ipc_lock_object(&shp->shm_perm);
84789
84790 /* check if shm_destroy() is tearing down shp */
84791 @@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84792 path = shp->shm_file->f_path;
84793 path_get(&path);
84794 shp->shm_nattch++;
84795 +#ifdef CONFIG_GRKERNSEC
84796 + shp->shm_lapid = current->pid;
84797 +#endif
84798 size = i_size_read(path.dentry->d_inode);
84799 ipc_unlock_object(&shp->shm_perm);
84800 rcu_read_unlock();
84801 diff --git a/ipc/util.c b/ipc/util.c
84802 index 3ae17a4..d67c32f 100644
84803 --- a/ipc/util.c
84804 +++ b/ipc/util.c
84805 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
84806 int (*show)(struct seq_file *, void *);
84807 };
84808
84809 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84810 +
84811 static void ipc_memory_notifier(struct work_struct *work)
84812 {
84813 ipcns_notify(IPCNS_MEMCHANGED);
84814 @@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84815 granted_mode >>= 6;
84816 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84817 granted_mode >>= 3;
84818 +
84819 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84820 + return -1;
84821 +
84822 /* is there some bit set in requested_mode but not in granted_mode? */
84823 if ((requested_mode & ~granted_mode & 0007) &&
84824 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84825 diff --git a/kernel/acct.c b/kernel/acct.c
84826 index 8d6e145..33e0b1e 100644
84827 --- a/kernel/acct.c
84828 +++ b/kernel/acct.c
84829 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84830 */
84831 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84832 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84833 - file->f_op->write(file, (char *)&ac,
84834 + file->f_op->write(file, (char __force_user *)&ac,
84835 sizeof(acct_t), &file->f_pos);
84836 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84837 set_fs(fs);
84838 diff --git a/kernel/audit.c b/kernel/audit.c
84839 index 15ec13a..986322e 100644
84840 --- a/kernel/audit.c
84841 +++ b/kernel/audit.c
84842 @@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
84843 3) suppressed due to audit_rate_limit
84844 4) suppressed due to audit_backlog_limit
84845 */
84846 -static atomic_t audit_lost = ATOMIC_INIT(0);
84847 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
84848
84849 /* The netlink socket. */
84850 static struct sock *audit_sock;
84851 @@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
84852 unsigned long now;
84853 int print;
84854
84855 - atomic_inc(&audit_lost);
84856 + atomic_inc_unchecked(&audit_lost);
84857
84858 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
84859
84860 @@ -270,7 +270,7 @@ void audit_log_lost(const char *message)
84861 printk(KERN_WARNING
84862 "audit: audit_lost=%d audit_rate_limit=%d "
84863 "audit_backlog_limit=%d\n",
84864 - atomic_read(&audit_lost),
84865 + atomic_read_unchecked(&audit_lost),
84866 audit_rate_limit,
84867 audit_backlog_limit);
84868 audit_panic(message);
84869 @@ -766,7 +766,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84870 status_set.pid = audit_pid;
84871 status_set.rate_limit = audit_rate_limit;
84872 status_set.backlog_limit = audit_backlog_limit;
84873 - status_set.lost = atomic_read(&audit_lost);
84874 + status_set.lost = atomic_read_unchecked(&audit_lost);
84875 status_set.backlog = skb_queue_len(&audit_skb_queue);
84876 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
84877 &status_set, sizeof(status_set));
84878 @@ -1359,7 +1359,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
84879 int i, avail, new_len;
84880 unsigned char *ptr;
84881 struct sk_buff *skb;
84882 - static const unsigned char *hex = "0123456789ABCDEF";
84883 + static const unsigned char hex[] = "0123456789ABCDEF";
84884
84885 if (!ab)
84886 return;
84887 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
84888 index ff32843..27fc708 100644
84889 --- a/kernel/auditsc.c
84890 +++ b/kernel/auditsc.c
84891 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
84892 }
84893
84894 /* global counter which is incremented every time something logs in */
84895 -static atomic_t session_id = ATOMIC_INIT(0);
84896 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
84897
84898 static int audit_set_loginuid_perm(kuid_t loginuid)
84899 {
84900 @@ -2011,7 +2011,7 @@ int audit_set_loginuid(kuid_t loginuid)
84901
84902 /* are we setting or clearing? */
84903 if (uid_valid(loginuid))
84904 - sessionid = atomic_inc_return(&session_id);
84905 + sessionid = atomic_inc_return_unchecked(&session_id);
84906
84907 task->sessionid = sessionid;
84908 task->loginuid = loginuid;
84909 diff --git a/kernel/capability.c b/kernel/capability.c
84910 index 4e66bf9..cdccecf 100644
84911 --- a/kernel/capability.c
84912 +++ b/kernel/capability.c
84913 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
84914 * before modification is attempted and the application
84915 * fails.
84916 */
84917 + if (tocopy > ARRAY_SIZE(kdata))
84918 + return -EFAULT;
84919 +
84920 if (copy_to_user(dataptr, kdata, tocopy
84921 * sizeof(struct __user_cap_data_struct))) {
84922 return -EFAULT;
84923 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
84924 int ret;
84925
84926 rcu_read_lock();
84927 - ret = security_capable(__task_cred(t), ns, cap);
84928 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
84929 + gr_task_is_capable(t, __task_cred(t), cap);
84930 rcu_read_unlock();
84931
84932 - return (ret == 0);
84933 + return ret;
84934 }
84935
84936 /**
84937 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
84938 int ret;
84939
84940 rcu_read_lock();
84941 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
84942 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
84943 rcu_read_unlock();
84944
84945 - return (ret == 0);
84946 + return ret;
84947 }
84948
84949 /**
84950 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
84951 BUG();
84952 }
84953
84954 - if (security_capable(current_cred(), ns, cap) == 0) {
84955 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
84956 current->flags |= PF_SUPERPRIV;
84957 return true;
84958 }
84959 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
84960 }
84961 EXPORT_SYMBOL(ns_capable);
84962
84963 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
84964 +{
84965 + if (unlikely(!cap_valid(cap))) {
84966 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
84967 + BUG();
84968 + }
84969 +
84970 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
84971 + current->flags |= PF_SUPERPRIV;
84972 + return true;
84973 + }
84974 + return false;
84975 +}
84976 +EXPORT_SYMBOL(ns_capable_nolog);
84977 +
84978 /**
84979 * file_ns_capable - Determine if the file's opener had a capability in effect
84980 * @file: The file we want to check
84981 @@ -432,6 +451,12 @@ bool capable(int cap)
84982 }
84983 EXPORT_SYMBOL(capable);
84984
84985 +bool capable_nolog(int cap)
84986 +{
84987 + return ns_capable_nolog(&init_user_ns, cap);
84988 +}
84989 +EXPORT_SYMBOL(capable_nolog);
84990 +
84991 /**
84992 * inode_capable - Check superior capability over inode
84993 * @inode: The inode in question
84994 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
84995 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84996 }
84997 EXPORT_SYMBOL(inode_capable);
84998 +
84999 +bool inode_capable_nolog(const struct inode *inode, int cap)
85000 +{
85001 + struct user_namespace *ns = current_user_ns();
85002 +
85003 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85004 +}
85005 +EXPORT_SYMBOL(inode_capable_nolog);
85006 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85007 index b44dd49..94c2826 100644
85008 --- a/kernel/cgroup.c
85009 +++ b/kernel/cgroup.c
85010 @@ -5609,7 +5609,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
85011 struct css_set *cset = link->cset;
85012 struct task_struct *task;
85013 int count = 0;
85014 - seq_printf(seq, "css_set %p\n", cset);
85015 + seq_printf(seq, "css_set %pK\n", cset);
85016 list_for_each_entry(task, &cset->tasks, cg_list) {
85017 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85018 seq_puts(seq, " ...\n");
85019 diff --git a/kernel/compat.c b/kernel/compat.c
85020 index 0a09e48..b46b3d78 100644
85021 --- a/kernel/compat.c
85022 +++ b/kernel/compat.c
85023 @@ -13,6 +13,7 @@
85024
85025 #include <linux/linkage.h>
85026 #include <linux/compat.h>
85027 +#include <linux/module.h>
85028 #include <linux/errno.h>
85029 #include <linux/time.h>
85030 #include <linux/signal.h>
85031 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85032 mm_segment_t oldfs;
85033 long ret;
85034
85035 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85036 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85037 oldfs = get_fs();
85038 set_fs(KERNEL_DS);
85039 ret = hrtimer_nanosleep_restart(restart);
85040 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85041 oldfs = get_fs();
85042 set_fs(KERNEL_DS);
85043 ret = hrtimer_nanosleep(&tu,
85044 - rmtp ? (struct timespec __user *)&rmt : NULL,
85045 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
85046 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85047 set_fs(oldfs);
85048
85049 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85050 mm_segment_t old_fs = get_fs();
85051
85052 set_fs(KERNEL_DS);
85053 - ret = sys_sigpending((old_sigset_t __user *) &s);
85054 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
85055 set_fs(old_fs);
85056 if (ret == 0)
85057 ret = put_user(s, set);
85058 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85059 mm_segment_t old_fs = get_fs();
85060
85061 set_fs(KERNEL_DS);
85062 - ret = sys_old_getrlimit(resource, &r);
85063 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85064 set_fs(old_fs);
85065
85066 if (!ret) {
85067 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85068 set_fs (KERNEL_DS);
85069 ret = sys_wait4(pid,
85070 (stat_addr ?
85071 - (unsigned int __user *) &status : NULL),
85072 - options, (struct rusage __user *) &r);
85073 + (unsigned int __force_user *) &status : NULL),
85074 + options, (struct rusage __force_user *) &r);
85075 set_fs (old_fs);
85076
85077 if (ret > 0) {
85078 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85079 memset(&info, 0, sizeof(info));
85080
85081 set_fs(KERNEL_DS);
85082 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85083 - uru ? (struct rusage __user *)&ru : NULL);
85084 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85085 + uru ? (struct rusage __force_user *)&ru : NULL);
85086 set_fs(old_fs);
85087
85088 if ((ret < 0) || (info.si_signo == 0))
85089 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85090 oldfs = get_fs();
85091 set_fs(KERNEL_DS);
85092 err = sys_timer_settime(timer_id, flags,
85093 - (struct itimerspec __user *) &newts,
85094 - (struct itimerspec __user *) &oldts);
85095 + (struct itimerspec __force_user *) &newts,
85096 + (struct itimerspec __force_user *) &oldts);
85097 set_fs(oldfs);
85098 if (!err && old && put_compat_itimerspec(old, &oldts))
85099 return -EFAULT;
85100 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85101 oldfs = get_fs();
85102 set_fs(KERNEL_DS);
85103 err = sys_timer_gettime(timer_id,
85104 - (struct itimerspec __user *) &ts);
85105 + (struct itimerspec __force_user *) &ts);
85106 set_fs(oldfs);
85107 if (!err && put_compat_itimerspec(setting, &ts))
85108 return -EFAULT;
85109 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85110 oldfs = get_fs();
85111 set_fs(KERNEL_DS);
85112 err = sys_clock_settime(which_clock,
85113 - (struct timespec __user *) &ts);
85114 + (struct timespec __force_user *) &ts);
85115 set_fs(oldfs);
85116 return err;
85117 }
85118 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85119 oldfs = get_fs();
85120 set_fs(KERNEL_DS);
85121 err = sys_clock_gettime(which_clock,
85122 - (struct timespec __user *) &ts);
85123 + (struct timespec __force_user *) &ts);
85124 set_fs(oldfs);
85125 if (!err && put_compat_timespec(&ts, tp))
85126 return -EFAULT;
85127 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85128
85129 oldfs = get_fs();
85130 set_fs(KERNEL_DS);
85131 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85132 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85133 set_fs(oldfs);
85134
85135 err = compat_put_timex(utp, &txc);
85136 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85137 oldfs = get_fs();
85138 set_fs(KERNEL_DS);
85139 err = sys_clock_getres(which_clock,
85140 - (struct timespec __user *) &ts);
85141 + (struct timespec __force_user *) &ts);
85142 set_fs(oldfs);
85143 if (!err && tp && put_compat_timespec(&ts, tp))
85144 return -EFAULT;
85145 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85146 long err;
85147 mm_segment_t oldfs;
85148 struct timespec tu;
85149 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85150 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85151
85152 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85153 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85154 oldfs = get_fs();
85155 set_fs(KERNEL_DS);
85156 err = clock_nanosleep_restart(restart);
85157 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85158 oldfs = get_fs();
85159 set_fs(KERNEL_DS);
85160 err = sys_clock_nanosleep(which_clock, flags,
85161 - (struct timespec __user *) &in,
85162 - (struct timespec __user *) &out);
85163 + (struct timespec __force_user *) &in,
85164 + (struct timespec __force_user *) &out);
85165 set_fs(oldfs);
85166
85167 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85168 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85169 mm_segment_t old_fs = get_fs();
85170
85171 set_fs(KERNEL_DS);
85172 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85173 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85174 set_fs(old_fs);
85175 if (put_compat_timespec(&t, interval))
85176 return -EFAULT;
85177 diff --git a/kernel/configs.c b/kernel/configs.c
85178 index c18b1f1..b9a0132 100644
85179 --- a/kernel/configs.c
85180 +++ b/kernel/configs.c
85181 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85182 struct proc_dir_entry *entry;
85183
85184 /* create the current config file */
85185 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85186 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85187 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85188 + &ikconfig_file_ops);
85189 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85190 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85191 + &ikconfig_file_ops);
85192 +#endif
85193 +#else
85194 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85195 &ikconfig_file_ops);
85196 +#endif
85197 +
85198 if (!entry)
85199 return -ENOMEM;
85200
85201 diff --git a/kernel/cred.c b/kernel/cred.c
85202 index e0573a4..3874e41 100644
85203 --- a/kernel/cred.c
85204 +++ b/kernel/cred.c
85205 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85206 validate_creds(cred);
85207 alter_cred_subscribers(cred, -1);
85208 put_cred(cred);
85209 +
85210 +#ifdef CONFIG_GRKERNSEC_SETXID
85211 + cred = (struct cred *) tsk->delayed_cred;
85212 + if (cred != NULL) {
85213 + tsk->delayed_cred = NULL;
85214 + validate_creds(cred);
85215 + alter_cred_subscribers(cred, -1);
85216 + put_cred(cred);
85217 + }
85218 +#endif
85219 }
85220
85221 /**
85222 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85223 * Always returns 0 thus allowing this function to be tail-called at the end
85224 * of, say, sys_setgid().
85225 */
85226 -int commit_creds(struct cred *new)
85227 +static int __commit_creds(struct cred *new)
85228 {
85229 struct task_struct *task = current;
85230 const struct cred *old = task->real_cred;
85231 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85232
85233 get_cred(new); /* we will require a ref for the subj creds too */
85234
85235 + gr_set_role_label(task, new->uid, new->gid);
85236 +
85237 /* dumpability changes */
85238 if (!uid_eq(old->euid, new->euid) ||
85239 !gid_eq(old->egid, new->egid) ||
85240 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85241 put_cred(old);
85242 return 0;
85243 }
85244 +#ifdef CONFIG_GRKERNSEC_SETXID
85245 +extern int set_user(struct cred *new);
85246 +
85247 +void gr_delayed_cred_worker(void)
85248 +{
85249 + const struct cred *new = current->delayed_cred;
85250 + struct cred *ncred;
85251 +
85252 + current->delayed_cred = NULL;
85253 +
85254 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85255 + // from doing get_cred on it when queueing this
85256 + put_cred(new);
85257 + return;
85258 + } else if (new == NULL)
85259 + return;
85260 +
85261 + ncred = prepare_creds();
85262 + if (!ncred)
85263 + goto die;
85264 + // uids
85265 + ncred->uid = new->uid;
85266 + ncred->euid = new->euid;
85267 + ncred->suid = new->suid;
85268 + ncred->fsuid = new->fsuid;
85269 + // gids
85270 + ncred->gid = new->gid;
85271 + ncred->egid = new->egid;
85272 + ncred->sgid = new->sgid;
85273 + ncred->fsgid = new->fsgid;
85274 + // groups
85275 + if (set_groups(ncred, new->group_info) < 0) {
85276 + abort_creds(ncred);
85277 + goto die;
85278 + }
85279 + // caps
85280 + ncred->securebits = new->securebits;
85281 + ncred->cap_inheritable = new->cap_inheritable;
85282 + ncred->cap_permitted = new->cap_permitted;
85283 + ncred->cap_effective = new->cap_effective;
85284 + ncred->cap_bset = new->cap_bset;
85285 +
85286 + if (set_user(ncred)) {
85287 + abort_creds(ncred);
85288 + goto die;
85289 + }
85290 +
85291 + // from doing get_cred on it when queueing this
85292 + put_cred(new);
85293 +
85294 + __commit_creds(ncred);
85295 + return;
85296 +die:
85297 + // from doing get_cred on it when queueing this
85298 + put_cred(new);
85299 + do_group_exit(SIGKILL);
85300 +}
85301 +#endif
85302 +
85303 +int commit_creds(struct cred *new)
85304 +{
85305 +#ifdef CONFIG_GRKERNSEC_SETXID
85306 + int ret;
85307 + int schedule_it = 0;
85308 + struct task_struct *t;
85309 +
85310 + /* we won't get called with tasklist_lock held for writing
85311 + and interrupts disabled as the cred struct in that case is
85312 + init_cred
85313 + */
85314 + if (grsec_enable_setxid && !current_is_single_threaded() &&
85315 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85316 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85317 + schedule_it = 1;
85318 + }
85319 + ret = __commit_creds(new);
85320 + if (schedule_it) {
85321 + rcu_read_lock();
85322 + read_lock(&tasklist_lock);
85323 + for (t = next_thread(current); t != current;
85324 + t = next_thread(t)) {
85325 + if (t->delayed_cred == NULL) {
85326 + t->delayed_cred = get_cred(new);
85327 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85328 + set_tsk_need_resched(t);
85329 + }
85330 + }
85331 + read_unlock(&tasklist_lock);
85332 + rcu_read_unlock();
85333 + }
85334 + return ret;
85335 +#else
85336 + return __commit_creds(new);
85337 +#endif
85338 +}
85339 +
85340 EXPORT_SYMBOL(commit_creds);
85341
85342 /**
85343 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85344 index 7d2f35e..1bafcd0 100644
85345 --- a/kernel/debug/debug_core.c
85346 +++ b/kernel/debug/debug_core.c
85347 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85348 */
85349 static atomic_t masters_in_kgdb;
85350 static atomic_t slaves_in_kgdb;
85351 -static atomic_t kgdb_break_tasklet_var;
85352 +static atomic_unchecked_t kgdb_break_tasklet_var;
85353 atomic_t kgdb_setting_breakpoint;
85354
85355 struct task_struct *kgdb_usethread;
85356 @@ -133,7 +133,7 @@ int kgdb_single_step;
85357 static pid_t kgdb_sstep_pid;
85358
85359 /* to keep track of the CPU which is doing the single stepping*/
85360 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85361 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85362
85363 /*
85364 * If you are debugging a problem where roundup (the collection of
85365 @@ -541,7 +541,7 @@ return_normal:
85366 * kernel will only try for the value of sstep_tries before
85367 * giving up and continuing on.
85368 */
85369 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85370 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85371 (kgdb_info[cpu].task &&
85372 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85373 atomic_set(&kgdb_active, -1);
85374 @@ -639,8 +639,8 @@ cpu_master_loop:
85375 }
85376
85377 kgdb_restore:
85378 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85379 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85380 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85381 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85382 if (kgdb_info[sstep_cpu].task)
85383 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85384 else
85385 @@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
85386 static void kgdb_tasklet_bpt(unsigned long ing)
85387 {
85388 kgdb_breakpoint();
85389 - atomic_set(&kgdb_break_tasklet_var, 0);
85390 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85391 }
85392
85393 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85394
85395 void kgdb_schedule_breakpoint(void)
85396 {
85397 - if (atomic_read(&kgdb_break_tasklet_var) ||
85398 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85399 atomic_read(&kgdb_active) != -1 ||
85400 atomic_read(&kgdb_setting_breakpoint))
85401 return;
85402 - atomic_inc(&kgdb_break_tasklet_var);
85403 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
85404 tasklet_schedule(&kgdb_tasklet_breakpoint);
85405 }
85406 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85407 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85408 index 0b097c8..11dd5c5 100644
85409 --- a/kernel/debug/kdb/kdb_main.c
85410 +++ b/kernel/debug/kdb/kdb_main.c
85411 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85412 continue;
85413
85414 kdb_printf("%-20s%8u 0x%p ", mod->name,
85415 - mod->core_size, (void *)mod);
85416 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
85417 #ifdef CONFIG_MODULE_UNLOAD
85418 kdb_printf("%4ld ", module_refcount(mod));
85419 #endif
85420 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85421 kdb_printf(" (Loading)");
85422 else
85423 kdb_printf(" (Live)");
85424 - kdb_printf(" 0x%p", mod->module_core);
85425 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85426
85427 #ifdef CONFIG_MODULE_UNLOAD
85428 {
85429 diff --git a/kernel/events/core.c b/kernel/events/core.c
85430 index 6ed1163..f36346e 100644
85431 --- a/kernel/events/core.c
85432 +++ b/kernel/events/core.c
85433 @@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
85434 * 0 - disallow raw tracepoint access for unpriv
85435 * 1 - disallow cpu events for unpriv
85436 * 2 - disallow kernel profiling for unpriv
85437 + * 3 - disallow all unpriv perf event use
85438 */
85439 -int sysctl_perf_event_paranoid __read_mostly = 1;
85440 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85441 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85442 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85443 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85444 +#else
85445 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85446 +#endif
85447
85448 /* Minimum for 512 kiB + 1 user control page */
85449 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85450 @@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
85451
85452 tmp *= sysctl_perf_cpu_time_max_percent;
85453 do_div(tmp, 100);
85454 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85455 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85456 }
85457
85458 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85459 @@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85460 update_perf_cpu_limits();
85461 }
85462
85463 -static atomic64_t perf_event_id;
85464 +static atomic64_unchecked_t perf_event_id;
85465
85466 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85467 enum event_type_t event_type);
85468 @@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
85469
85470 static inline u64 perf_event_count(struct perf_event *event)
85471 {
85472 - return local64_read(&event->count) + atomic64_read(&event->child_count);
85473 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85474 }
85475
85476 static u64 perf_event_read(struct perf_event *event)
85477 @@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85478 mutex_lock(&event->child_mutex);
85479 total += perf_event_read(event);
85480 *enabled += event->total_time_enabled +
85481 - atomic64_read(&event->child_total_time_enabled);
85482 + atomic64_read_unchecked(&event->child_total_time_enabled);
85483 *running += event->total_time_running +
85484 - atomic64_read(&event->child_total_time_running);
85485 + atomic64_read_unchecked(&event->child_total_time_running);
85486
85487 list_for_each_entry(child, &event->child_list, child_list) {
85488 total += perf_event_read(child);
85489 @@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
85490 userpg->offset -= local64_read(&event->hw.prev_count);
85491
85492 userpg->time_enabled = enabled +
85493 - atomic64_read(&event->child_total_time_enabled);
85494 + atomic64_read_unchecked(&event->child_total_time_enabled);
85495
85496 userpg->time_running = running +
85497 - atomic64_read(&event->child_total_time_running);
85498 + atomic64_read_unchecked(&event->child_total_time_running);
85499
85500 arch_perf_update_userpage(userpg, now);
85501
85502 @@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85503
85504 /* Data. */
85505 sp = perf_user_stack_pointer(regs);
85506 - rem = __output_copy_user(handle, (void *) sp, dump_size);
85507 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85508 dyn_size = dump_size - rem;
85509
85510 perf_output_skip(handle, rem);
85511 @@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85512 values[n++] = perf_event_count(event);
85513 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85514 values[n++] = enabled +
85515 - atomic64_read(&event->child_total_time_enabled);
85516 + atomic64_read_unchecked(&event->child_total_time_enabled);
85517 }
85518 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85519 values[n++] = running +
85520 - atomic64_read(&event->child_total_time_running);
85521 + atomic64_read_unchecked(&event->child_total_time_running);
85522 }
85523 if (read_format & PERF_FORMAT_ID)
85524 values[n++] = primary_event_id(event);
85525 @@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85526 event->parent = parent_event;
85527
85528 event->ns = get_pid_ns(task_active_pid_ns(current));
85529 - event->id = atomic64_inc_return(&perf_event_id);
85530 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
85531
85532 event->state = PERF_EVENT_STATE_INACTIVE;
85533
85534 @@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
85535 if (flags & ~PERF_FLAG_ALL)
85536 return -EINVAL;
85537
85538 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85539 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85540 + return -EACCES;
85541 +#endif
85542 +
85543 err = perf_copy_attr(attr_uptr, &attr);
85544 if (err)
85545 return err;
85546 @@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
85547 /*
85548 * Add back the child's count to the parent's count:
85549 */
85550 - atomic64_add(child_val, &parent_event->child_count);
85551 - atomic64_add(child_event->total_time_enabled,
85552 + atomic64_add_unchecked(child_val, &parent_event->child_count);
85553 + atomic64_add_unchecked(child_event->total_time_enabled,
85554 &parent_event->child_total_time_enabled);
85555 - atomic64_add(child_event->total_time_running,
85556 + atomic64_add_unchecked(child_event->total_time_running,
85557 &parent_event->child_total_time_running);
85558
85559 /*
85560 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85561 index 569b2187..19940d9 100644
85562 --- a/kernel/events/internal.h
85563 +++ b/kernel/events/internal.h
85564 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85565 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85566 }
85567
85568 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85569 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85570 static inline unsigned long \
85571 func_name(struct perf_output_handle *handle, \
85572 - const void *buf, unsigned long len) \
85573 + const void user *buf, unsigned long len) \
85574 { \
85575 unsigned long size, written; \
85576 \
85577 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85578 return 0;
85579 }
85580
85581 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85582 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85583
85584 static inline unsigned long
85585 memcpy_skip(void *dst, const void *src, unsigned long n)
85586 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85587 return 0;
85588 }
85589
85590 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85591 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85592
85593 #ifndef arch_perf_out_copy_user
85594 #define arch_perf_out_copy_user arch_perf_out_copy_user
85595 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85596 }
85597 #endif
85598
85599 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85600 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85601
85602 /* Callchain handling */
85603 extern struct perf_callchain_entry *
85604 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85605 index 24b7d6c..40cf797 100644
85606 --- a/kernel/events/uprobes.c
85607 +++ b/kernel/events/uprobes.c
85608 @@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85609 {
85610 struct page *page;
85611 uprobe_opcode_t opcode;
85612 - int result;
85613 + long result;
85614
85615 pagefault_disable();
85616 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85617 diff --git a/kernel/exit.c b/kernel/exit.c
85618 index a949819..a5f127d 100644
85619 --- a/kernel/exit.c
85620 +++ b/kernel/exit.c
85621 @@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
85622 struct task_struct *leader;
85623 int zap_leader;
85624 repeat:
85625 +#ifdef CONFIG_NET
85626 + gr_del_task_from_ip_table(p);
85627 +#endif
85628 +
85629 /* don't need to get the RCU readlock here - the process is dead and
85630 * can't be modifying its own credentials. But shut RCU-lockdep up */
85631 rcu_read_lock();
85632 @@ -329,7 +333,7 @@ int allow_signal(int sig)
85633 * know it'll be handled, so that they don't get converted to
85634 * SIGKILL or just silently dropped.
85635 */
85636 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85637 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85638 recalc_sigpending();
85639 spin_unlock_irq(&current->sighand->siglock);
85640 return 0;
85641 @@ -698,6 +702,8 @@ void do_exit(long code)
85642 struct task_struct *tsk = current;
85643 int group_dead;
85644
85645 + set_fs(USER_DS);
85646 +
85647 profile_task_exit(tsk);
85648
85649 WARN_ON(blk_needs_flush_plug(tsk));
85650 @@ -714,7 +720,6 @@ void do_exit(long code)
85651 * mm_release()->clear_child_tid() from writing to a user-controlled
85652 * kernel address.
85653 */
85654 - set_fs(USER_DS);
85655
85656 ptrace_event(PTRACE_EVENT_EXIT, code);
85657
85658 @@ -773,6 +778,9 @@ void do_exit(long code)
85659 tsk->exit_code = code;
85660 taskstats_exit(tsk, group_dead);
85661
85662 + gr_acl_handle_psacct(tsk, code);
85663 + gr_acl_handle_exit();
85664 +
85665 exit_mm(tsk);
85666
85667 if (group_dead)
85668 @@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85669 * Take down every thread in the group. This is called by fatal signals
85670 * as well as by sys_exit_group (below).
85671 */
85672 -void
85673 +__noreturn void
85674 do_group_exit(int exit_code)
85675 {
85676 struct signal_struct *sig = current->signal;
85677 diff --git a/kernel/fork.c b/kernel/fork.c
85678 index dfa736c..d170f9b 100644
85679 --- a/kernel/fork.c
85680 +++ b/kernel/fork.c
85681 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85682 *stackend = STACK_END_MAGIC; /* for overflow detection */
85683
85684 #ifdef CONFIG_CC_STACKPROTECTOR
85685 - tsk->stack_canary = get_random_int();
85686 + tsk->stack_canary = pax_get_random_long();
85687 #endif
85688
85689 /*
85690 @@ -345,12 +345,80 @@ free_tsk:
85691 }
85692
85693 #ifdef CONFIG_MMU
85694 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85695 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85696 +{
85697 + struct vm_area_struct *tmp;
85698 + unsigned long charge;
85699 + struct file *file;
85700 + int retval;
85701 +
85702 + charge = 0;
85703 + if (mpnt->vm_flags & VM_ACCOUNT) {
85704 + unsigned long len = vma_pages(mpnt);
85705 +
85706 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85707 + goto fail_nomem;
85708 + charge = len;
85709 + }
85710 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85711 + if (!tmp)
85712 + goto fail_nomem;
85713 + *tmp = *mpnt;
85714 + tmp->vm_mm = mm;
85715 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
85716 + retval = vma_dup_policy(mpnt, tmp);
85717 + if (retval)
85718 + goto fail_nomem_policy;
85719 + if (anon_vma_fork(tmp, mpnt))
85720 + goto fail_nomem_anon_vma_fork;
85721 + tmp->vm_flags &= ~VM_LOCKED;
85722 + tmp->vm_next = tmp->vm_prev = NULL;
85723 + tmp->vm_mirror = NULL;
85724 + file = tmp->vm_file;
85725 + if (file) {
85726 + struct inode *inode = file_inode(file);
85727 + struct address_space *mapping = file->f_mapping;
85728 +
85729 + get_file(file);
85730 + if (tmp->vm_flags & VM_DENYWRITE)
85731 + atomic_dec(&inode->i_writecount);
85732 + mutex_lock(&mapping->i_mmap_mutex);
85733 + if (tmp->vm_flags & VM_SHARED)
85734 + mapping->i_mmap_writable++;
85735 + flush_dcache_mmap_lock(mapping);
85736 + /* insert tmp into the share list, just after mpnt */
85737 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85738 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85739 + else
85740 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85741 + flush_dcache_mmap_unlock(mapping);
85742 + mutex_unlock(&mapping->i_mmap_mutex);
85743 + }
85744 +
85745 + /*
85746 + * Clear hugetlb-related page reserves for children. This only
85747 + * affects MAP_PRIVATE mappings. Faults generated by the child
85748 + * are not guaranteed to succeed, even if read-only
85749 + */
85750 + if (is_vm_hugetlb_page(tmp))
85751 + reset_vma_resv_huge_pages(tmp);
85752 +
85753 + return tmp;
85754 +
85755 +fail_nomem_anon_vma_fork:
85756 + mpol_put(vma_policy(tmp));
85757 +fail_nomem_policy:
85758 + kmem_cache_free(vm_area_cachep, tmp);
85759 +fail_nomem:
85760 + vm_unacct_memory(charge);
85761 + return NULL;
85762 +}
85763 +
85764 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85765 {
85766 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85767 struct rb_node **rb_link, *rb_parent;
85768 int retval;
85769 - unsigned long charge;
85770
85771 uprobe_start_dup_mmap();
85772 down_write(&oldmm->mmap_sem);
85773 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85774
85775 prev = NULL;
85776 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85777 - struct file *file;
85778 -
85779 if (mpnt->vm_flags & VM_DONTCOPY) {
85780 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85781 -vma_pages(mpnt));
85782 continue;
85783 }
85784 - charge = 0;
85785 - if (mpnt->vm_flags & VM_ACCOUNT) {
85786 - unsigned long len = vma_pages(mpnt);
85787 -
85788 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85789 - goto fail_nomem;
85790 - charge = len;
85791 - }
85792 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85793 - if (!tmp)
85794 - goto fail_nomem;
85795 - *tmp = *mpnt;
85796 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
85797 - retval = vma_dup_policy(mpnt, tmp);
85798 - if (retval)
85799 - goto fail_nomem_policy;
85800 - tmp->vm_mm = mm;
85801 - if (anon_vma_fork(tmp, mpnt))
85802 - goto fail_nomem_anon_vma_fork;
85803 - tmp->vm_flags &= ~VM_LOCKED;
85804 - tmp->vm_next = tmp->vm_prev = NULL;
85805 - file = tmp->vm_file;
85806 - if (file) {
85807 - struct inode *inode = file_inode(file);
85808 - struct address_space *mapping = file->f_mapping;
85809 -
85810 - get_file(file);
85811 - if (tmp->vm_flags & VM_DENYWRITE)
85812 - atomic_dec(&inode->i_writecount);
85813 - mutex_lock(&mapping->i_mmap_mutex);
85814 - if (tmp->vm_flags & VM_SHARED)
85815 - mapping->i_mmap_writable++;
85816 - flush_dcache_mmap_lock(mapping);
85817 - /* insert tmp into the share list, just after mpnt */
85818 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85819 - vma_nonlinear_insert(tmp,
85820 - &mapping->i_mmap_nonlinear);
85821 - else
85822 - vma_interval_tree_insert_after(tmp, mpnt,
85823 - &mapping->i_mmap);
85824 - flush_dcache_mmap_unlock(mapping);
85825 - mutex_unlock(&mapping->i_mmap_mutex);
85826 + tmp = dup_vma(mm, oldmm, mpnt);
85827 + if (!tmp) {
85828 + retval = -ENOMEM;
85829 + goto out;
85830 }
85831
85832 /*
85833 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85834 if (retval)
85835 goto out;
85836 }
85837 +
85838 +#ifdef CONFIG_PAX_SEGMEXEC
85839 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85840 + struct vm_area_struct *mpnt_m;
85841 +
85842 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85843 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85844 +
85845 + if (!mpnt->vm_mirror)
85846 + continue;
85847 +
85848 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
85849 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
85850 + mpnt->vm_mirror = mpnt_m;
85851 + } else {
85852 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
85853 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
85854 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
85855 + mpnt->vm_mirror->vm_mirror = mpnt;
85856 + }
85857 + }
85858 + BUG_ON(mpnt_m);
85859 + }
85860 +#endif
85861 +
85862 /* a new mm has just been created */
85863 arch_dup_mmap(oldmm, mm);
85864 retval = 0;
85865 @@ -468,14 +521,6 @@ out:
85866 up_write(&oldmm->mmap_sem);
85867 uprobe_end_dup_mmap();
85868 return retval;
85869 -fail_nomem_anon_vma_fork:
85870 - mpol_put(vma_policy(tmp));
85871 -fail_nomem_policy:
85872 - kmem_cache_free(vm_area_cachep, tmp);
85873 -fail_nomem:
85874 - retval = -ENOMEM;
85875 - vm_unacct_memory(charge);
85876 - goto out;
85877 }
85878
85879 static inline int mm_alloc_pgd(struct mm_struct *mm)
85880 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
85881 return ERR_PTR(err);
85882
85883 mm = get_task_mm(task);
85884 - if (mm && mm != current->mm &&
85885 - !ptrace_may_access(task, mode)) {
85886 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
85887 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
85888 mmput(mm);
85889 mm = ERR_PTR(-EACCES);
85890 }
85891 @@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
85892 spin_unlock(&fs->lock);
85893 return -EAGAIN;
85894 }
85895 - fs->users++;
85896 + atomic_inc(&fs->users);
85897 spin_unlock(&fs->lock);
85898 return 0;
85899 }
85900 tsk->fs = copy_fs_struct(fs);
85901 if (!tsk->fs)
85902 return -ENOMEM;
85903 + /* Carry through gr_chroot_dentry and is_chrooted instead
85904 + of recomputing it here. Already copied when the task struct
85905 + is duplicated. This allows pivot_root to not be treated as
85906 + a chroot
85907 + */
85908 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
85909 +
85910 return 0;
85911 }
85912
85913 @@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
85914 * parts of the process environment (as per the clone
85915 * flags). The actual kick-off is left to the caller.
85916 */
85917 -static struct task_struct *copy_process(unsigned long clone_flags,
85918 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
85919 unsigned long stack_start,
85920 unsigned long stack_size,
85921 int __user *child_tidptr,
85922 @@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85923 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
85924 #endif
85925 retval = -EAGAIN;
85926 +
85927 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
85928 +
85929 if (atomic_read(&p->real_cred->user->processes) >=
85930 task_rlimit(p, RLIMIT_NPROC)) {
85931 if (p->real_cred->user != INIT_USER &&
85932 @@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85933 goto bad_fork_free_pid;
85934 }
85935
85936 + /* synchronizes with gr_set_acls()
85937 + we need to call this past the point of no return for fork()
85938 + */
85939 + gr_copy_label(p);
85940 +
85941 if (likely(p->pid)) {
85942 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
85943
85944 @@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
85945 bad_fork_free:
85946 free_task(p);
85947 fork_out:
85948 + gr_log_forkfail(retval);
85949 +
85950 return ERR_PTR(retval);
85951 }
85952
85953 @@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
85954
85955 p = copy_process(clone_flags, stack_start, stack_size,
85956 child_tidptr, NULL, trace);
85957 + add_latent_entropy();
85958 /*
85959 * Do this prior waking up the new thread - the thread pointer
85960 * might get invalid after that point, if the thread exits quickly.
85961 @@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
85962 if (clone_flags & CLONE_PARENT_SETTID)
85963 put_user(nr, parent_tidptr);
85964
85965 + gr_handle_brute_check();
85966 +
85967 if (clone_flags & CLONE_VFORK) {
85968 p->vfork_done = &vfork;
85969 init_completion(&vfork);
85970 @@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
85971 mm_cachep = kmem_cache_create("mm_struct",
85972 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
85973 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
85974 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
85975 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
85976 mmap_init();
85977 nsproxy_cache_init();
85978 }
85979 @@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
85980 return 0;
85981
85982 /* don't need lock here; in the worst case we'll do useless copy */
85983 - if (fs->users == 1)
85984 + if (atomic_read(&fs->users) == 1)
85985 return 0;
85986
85987 *new_fsp = copy_fs_struct(fs);
85988 @@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
85989 fs = current->fs;
85990 spin_lock(&fs->lock);
85991 current->fs = new_fs;
85992 - if (--fs->users)
85993 + gr_set_chroot_entries(current, &current->fs->root);
85994 + if (atomic_dec_return(&fs->users))
85995 new_fs = NULL;
85996 else
85997 new_fs = fs;
85998 diff --git a/kernel/futex.c b/kernel/futex.c
85999 index f6ff019..ac53307 100644
86000 --- a/kernel/futex.c
86001 +++ b/kernel/futex.c
86002 @@ -54,6 +54,7 @@
86003 #include <linux/mount.h>
86004 #include <linux/pagemap.h>
86005 #include <linux/syscalls.h>
86006 +#include <linux/ptrace.h>
86007 #include <linux/signal.h>
86008 #include <linux/export.h>
86009 #include <linux/magic.h>
86010 @@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86011 struct page *page, *page_head;
86012 int err, ro = 0;
86013
86014 +#ifdef CONFIG_PAX_SEGMEXEC
86015 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86016 + return -EFAULT;
86017 +#endif
86018 +
86019 /*
86020 * The futex address must be "naturally" aligned.
86021 */
86022 @@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86023
86024 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86025 {
86026 - int ret;
86027 + unsigned long ret;
86028
86029 pagefault_disable();
86030 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86031 @@ -2735,6 +2741,7 @@ static int __init futex_init(void)
86032 {
86033 u32 curval;
86034 int i;
86035 + mm_segment_t oldfs;
86036
86037 /*
86038 * This will fail and we want it. Some arch implementations do
86039 @@ -2746,8 +2753,11 @@ static int __init futex_init(void)
86040 * implementation, the non-functional ones will return
86041 * -ENOSYS.
86042 */
86043 + oldfs = get_fs();
86044 + set_fs(USER_DS);
86045 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86046 futex_cmpxchg_enabled = 1;
86047 + set_fs(oldfs);
86048
86049 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
86050 plist_head_init(&futex_queues[i].chain);
86051 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86052 index f9f44fd..29885e4 100644
86053 --- a/kernel/futex_compat.c
86054 +++ b/kernel/futex_compat.c
86055 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86056 return 0;
86057 }
86058
86059 -static void __user *futex_uaddr(struct robust_list __user *entry,
86060 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86061 compat_long_t futex_offset)
86062 {
86063 compat_uptr_t base = ptr_to_compat(entry);
86064 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86065 index f45b75b..bfac6d5 100644
86066 --- a/kernel/gcov/base.c
86067 +++ b/kernel/gcov/base.c
86068 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
86069 }
86070
86071 #ifdef CONFIG_MODULES
86072 -static inline int within(void *addr, void *start, unsigned long size)
86073 -{
86074 - return ((addr >= start) && (addr < start + size));
86075 -}
86076 -
86077 /* Update list and generate events when modules are unloaded. */
86078 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86079 void *data)
86080 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86081
86082 /* Remove entries located in module from linked list. */
86083 while ((info = gcov_info_next(info))) {
86084 - if (within(info, mod->module_core, mod->core_size)) {
86085 + if (within_module_core_rw((unsigned long)info, mod)) {
86086 gcov_info_unlink(prev, info);
86087 if (gcov_events_enabled)
86088 gcov_event(GCOV_REMOVE, info);
86089 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86090 index 383319b..56ebb13 100644
86091 --- a/kernel/hrtimer.c
86092 +++ b/kernel/hrtimer.c
86093 @@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
86094 local_irq_restore(flags);
86095 }
86096
86097 -static void run_hrtimer_softirq(struct softirq_action *h)
86098 +static __latent_entropy void run_hrtimer_softirq(void)
86099 {
86100 hrtimer_peek_ahead_timers();
86101 }
86102 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86103 index 55fcce6..0e4cf34 100644
86104 --- a/kernel/irq_work.c
86105 +++ b/kernel/irq_work.c
86106 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86107 return NOTIFY_OK;
86108 }
86109
86110 -static struct notifier_block cpu_notify;
86111 +static struct notifier_block cpu_notify = {
86112 + .notifier_call = irq_work_cpu_notify,
86113 + .priority = 0,
86114 +};
86115
86116 static __init int irq_work_init_cpu_notifier(void)
86117 {
86118 - cpu_notify.notifier_call = irq_work_cpu_notify;
86119 - cpu_notify.priority = 0;
86120 register_cpu_notifier(&cpu_notify);
86121 return 0;
86122 }
86123 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86124 index 9019f15..9a3c42e 100644
86125 --- a/kernel/jump_label.c
86126 +++ b/kernel/jump_label.c
86127 @@ -14,6 +14,7 @@
86128 #include <linux/err.h>
86129 #include <linux/static_key.h>
86130 #include <linux/jump_label_ratelimit.h>
86131 +#include <linux/mm.h>
86132
86133 #ifdef HAVE_JUMP_LABEL
86134
86135 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86136
86137 size = (((unsigned long)stop - (unsigned long)start)
86138 / sizeof(struct jump_entry));
86139 + pax_open_kernel();
86140 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86141 + pax_close_kernel();
86142 }
86143
86144 static void jump_label_update(struct static_key *key, int enable);
86145 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86146 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86147 struct jump_entry *iter;
86148
86149 + pax_open_kernel();
86150 for (iter = iter_start; iter < iter_stop; iter++) {
86151 if (within_module_init(iter->code, mod))
86152 iter->code = 0;
86153 }
86154 + pax_close_kernel();
86155 }
86156
86157 static int
86158 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86159 index 3127ad5..159d880 100644
86160 --- a/kernel/kallsyms.c
86161 +++ b/kernel/kallsyms.c
86162 @@ -11,6 +11,9 @@
86163 * Changed the compression method from stem compression to "table lookup"
86164 * compression (see scripts/kallsyms.c for a more complete description)
86165 */
86166 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86167 +#define __INCLUDED_BY_HIDESYM 1
86168 +#endif
86169 #include <linux/kallsyms.h>
86170 #include <linux/module.h>
86171 #include <linux/init.h>
86172 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86173
86174 static inline int is_kernel_inittext(unsigned long addr)
86175 {
86176 + if (system_state != SYSTEM_BOOTING)
86177 + return 0;
86178 +
86179 if (addr >= (unsigned long)_sinittext
86180 && addr <= (unsigned long)_einittext)
86181 return 1;
86182 return 0;
86183 }
86184
86185 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86186 +#ifdef CONFIG_MODULES
86187 +static inline int is_module_text(unsigned long addr)
86188 +{
86189 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86190 + return 1;
86191 +
86192 + addr = ktla_ktva(addr);
86193 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86194 +}
86195 +#else
86196 +static inline int is_module_text(unsigned long addr)
86197 +{
86198 + return 0;
86199 +}
86200 +#endif
86201 +#endif
86202 +
86203 static inline int is_kernel_text(unsigned long addr)
86204 {
86205 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86206 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86207
86208 static inline int is_kernel(unsigned long addr)
86209 {
86210 +
86211 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86212 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
86213 + return 1;
86214 +
86215 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86216 +#else
86217 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86218 +#endif
86219 +
86220 return 1;
86221 return in_gate_area_no_mm(addr);
86222 }
86223
86224 static int is_ksym_addr(unsigned long addr)
86225 {
86226 +
86227 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86228 + if (is_module_text(addr))
86229 + return 0;
86230 +#endif
86231 +
86232 if (all_var)
86233 return is_kernel(addr);
86234
86235 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86236
86237 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86238 {
86239 - iter->name[0] = '\0';
86240 iter->nameoff = get_symbol_offset(new_pos);
86241 iter->pos = new_pos;
86242 }
86243 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86244 {
86245 struct kallsym_iter *iter = m->private;
86246
86247 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86248 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86249 + return 0;
86250 +#endif
86251 +
86252 /* Some debugging symbols have no name. Ignore them. */
86253 if (!iter->name[0])
86254 return 0;
86255 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86256 */
86257 type = iter->exported ? toupper(iter->type) :
86258 tolower(iter->type);
86259 +
86260 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86261 type, iter->name, iter->module_name);
86262 } else
86263 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86264 struct kallsym_iter *iter;
86265 int ret;
86266
86267 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86268 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86269 if (!iter)
86270 return -ENOMEM;
86271 reset_iter(iter, 0);
86272 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86273 index e30ac0f..3528cac 100644
86274 --- a/kernel/kcmp.c
86275 +++ b/kernel/kcmp.c
86276 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86277 struct task_struct *task1, *task2;
86278 int ret;
86279
86280 +#ifdef CONFIG_GRKERNSEC
86281 + return -ENOSYS;
86282 +#endif
86283 +
86284 rcu_read_lock();
86285
86286 /*
86287 diff --git a/kernel/kexec.c b/kernel/kexec.c
86288 index 9c97016..df438f8 100644
86289 --- a/kernel/kexec.c
86290 +++ b/kernel/kexec.c
86291 @@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86292 unsigned long flags)
86293 {
86294 struct compat_kexec_segment in;
86295 - struct kexec_segment out, __user *ksegments;
86296 + struct kexec_segment out;
86297 + struct kexec_segment __user *ksegments;
86298 unsigned long i, result;
86299
86300 /* Don't allow clients that don't understand the native
86301 diff --git a/kernel/kmod.c b/kernel/kmod.c
86302 index b086006..b66f630 100644
86303 --- a/kernel/kmod.c
86304 +++ b/kernel/kmod.c
86305 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86306 kfree(info->argv);
86307 }
86308
86309 -static int call_modprobe(char *module_name, int wait)
86310 +static int call_modprobe(char *module_name, char *module_param, int wait)
86311 {
86312 struct subprocess_info *info;
86313 static char *envp[] = {
86314 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86315 NULL
86316 };
86317
86318 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86319 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86320 if (!argv)
86321 goto out;
86322
86323 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86324 argv[1] = "-q";
86325 argv[2] = "--";
86326 argv[3] = module_name; /* check free_modprobe_argv() */
86327 - argv[4] = NULL;
86328 + argv[4] = module_param;
86329 + argv[5] = NULL;
86330
86331 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86332 NULL, free_modprobe_argv, NULL);
86333 @@ -129,9 +130,8 @@ out:
86334 * If module auto-loading support is disabled then this function
86335 * becomes a no-operation.
86336 */
86337 -int __request_module(bool wait, const char *fmt, ...)
86338 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86339 {
86340 - va_list args;
86341 char module_name[MODULE_NAME_LEN];
86342 unsigned int max_modprobes;
86343 int ret;
86344 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86345 if (!modprobe_path[0])
86346 return 0;
86347
86348 - va_start(args, fmt);
86349 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86350 - va_end(args);
86351 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86352 if (ret >= MODULE_NAME_LEN)
86353 return -ENAMETOOLONG;
86354
86355 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86356 if (ret)
86357 return ret;
86358
86359 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86360 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86361 + /* hack to workaround consolekit/udisks stupidity */
86362 + read_lock(&tasklist_lock);
86363 + if (!strcmp(current->comm, "mount") &&
86364 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86365 + read_unlock(&tasklist_lock);
86366 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86367 + return -EPERM;
86368 + }
86369 + read_unlock(&tasklist_lock);
86370 + }
86371 +#endif
86372 +
86373 /* If modprobe needs a service that is in a module, we get a recursive
86374 * loop. Limit the number of running kmod threads to max_threads/2 or
86375 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86376 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86377
86378 trace_module_request(module_name, wait, _RET_IP_);
86379
86380 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86381 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86382
86383 atomic_dec(&kmod_concurrent);
86384 return ret;
86385 }
86386 +
86387 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86388 +{
86389 + va_list args;
86390 + int ret;
86391 +
86392 + va_start(args, fmt);
86393 + ret = ____request_module(wait, module_param, fmt, args);
86394 + va_end(args);
86395 +
86396 + return ret;
86397 +}
86398 +
86399 +int __request_module(bool wait, const char *fmt, ...)
86400 +{
86401 + va_list args;
86402 + int ret;
86403 +
86404 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86405 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86406 + char module_param[MODULE_NAME_LEN];
86407 +
86408 + memset(module_param, 0, sizeof(module_param));
86409 +
86410 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86411 +
86412 + va_start(args, fmt);
86413 + ret = ____request_module(wait, module_param, fmt, args);
86414 + va_end(args);
86415 +
86416 + return ret;
86417 + }
86418 +#endif
86419 +
86420 + va_start(args, fmt);
86421 + ret = ____request_module(wait, NULL, fmt, args);
86422 + va_end(args);
86423 +
86424 + return ret;
86425 +}
86426 +
86427 EXPORT_SYMBOL(__request_module);
86428 #endif /* CONFIG_MODULES */
86429
86430 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86431 */
86432 set_user_nice(current, 0);
86433
86434 +#ifdef CONFIG_GRKERNSEC
86435 + /* this is race-free as far as userland is concerned as we copied
86436 + out the path to be used prior to this point and are now operating
86437 + on that copy
86438 + */
86439 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86440 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86441 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86442 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86443 + retval = -EPERM;
86444 + goto fail;
86445 + }
86446 +#endif
86447 +
86448 retval = -ENOMEM;
86449 new = prepare_kernel_cred(current);
86450 if (!new)
86451 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86452 commit_creds(new);
86453
86454 retval = do_execve(sub_info->path,
86455 - (const char __user *const __user *)sub_info->argv,
86456 - (const char __user *const __user *)sub_info->envp);
86457 + (const char __user *const __force_user *)sub_info->argv,
86458 + (const char __user *const __force_user *)sub_info->envp);
86459 if (!retval)
86460 return 0;
86461
86462 @@ -260,6 +327,10 @@ static int call_helper(void *data)
86463
86464 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86465 {
86466 +#ifdef CONFIG_GRKERNSEC
86467 + kfree(info->path);
86468 + info->path = info->origpath;
86469 +#endif
86470 if (info->cleanup)
86471 (*info->cleanup)(info);
86472 kfree(info);
86473 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86474 *
86475 * Thus the __user pointer cast is valid here.
86476 */
86477 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
86478 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86479
86480 /*
86481 * If ret is 0, either ____call_usermodehelper failed and the
86482 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86483 goto out;
86484
86485 INIT_WORK(&sub_info->work, __call_usermodehelper);
86486 +#ifdef CONFIG_GRKERNSEC
86487 + sub_info->origpath = path;
86488 + sub_info->path = kstrdup(path, gfp_mask);
86489 +#else
86490 sub_info->path = path;
86491 +#endif
86492 sub_info->argv = argv;
86493 sub_info->envp = envp;
86494
86495 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86496 static int proc_cap_handler(struct ctl_table *table, int write,
86497 void __user *buffer, size_t *lenp, loff_t *ppos)
86498 {
86499 - struct ctl_table t;
86500 + ctl_table_no_const t;
86501 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86502 kernel_cap_t new_cap;
86503 int err, i;
86504 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86505 index ceeadfc..11c18b6 100644
86506 --- a/kernel/kprobes.c
86507 +++ b/kernel/kprobes.c
86508 @@ -31,6 +31,9 @@
86509 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86510 * <prasanna@in.ibm.com> added function-return probes.
86511 */
86512 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86513 +#define __INCLUDED_BY_HIDESYM 1
86514 +#endif
86515 #include <linux/kprobes.h>
86516 #include <linux/hash.h>
86517 #include <linux/init.h>
86518 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
86519
86520 static void *alloc_insn_page(void)
86521 {
86522 - return module_alloc(PAGE_SIZE);
86523 + return module_alloc_exec(PAGE_SIZE);
86524 }
86525
86526 static void free_insn_page(void *page)
86527 {
86528 - module_free(NULL, page);
86529 + module_free_exec(NULL, page);
86530 }
86531
86532 struct kprobe_insn_cache kprobe_insn_slots = {
86533 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86534 kprobe_type = "k";
86535
86536 if (sym)
86537 - seq_printf(pi, "%p %s %s+0x%x %s ",
86538 + seq_printf(pi, "%pK %s %s+0x%x %s ",
86539 p->addr, kprobe_type, sym, offset,
86540 (modname ? modname : " "));
86541 else
86542 - seq_printf(pi, "%p %s %p ",
86543 + seq_printf(pi, "%pK %s %pK ",
86544 p->addr, kprobe_type, p->addr);
86545
86546 if (!pp)
86547 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86548 index 9659d38..bffd520 100644
86549 --- a/kernel/ksysfs.c
86550 +++ b/kernel/ksysfs.c
86551 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86552 {
86553 if (count+1 > UEVENT_HELPER_PATH_LEN)
86554 return -ENOENT;
86555 + if (!capable(CAP_SYS_ADMIN))
86556 + return -EPERM;
86557 memcpy(uevent_helper, buf, count);
86558 uevent_helper[count] = '\0';
86559 if (count && uevent_helper[count-1] == '\n')
86560 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86561 return count;
86562 }
86563
86564 -static struct bin_attribute notes_attr = {
86565 +static bin_attribute_no_const notes_attr __read_only = {
86566 .attr = {
86567 .name = "notes",
86568 .mode = S_IRUGO,
86569 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86570 index 576ba75..7c256e4 100644
86571 --- a/kernel/locking/lockdep.c
86572 +++ b/kernel/locking/lockdep.c
86573 @@ -596,6 +596,10 @@ static int static_obj(void *obj)
86574 end = (unsigned long) &_end,
86575 addr = (unsigned long) obj;
86576
86577 +#ifdef CONFIG_PAX_KERNEXEC
86578 + start = ktla_ktva(start);
86579 +#endif
86580 +
86581 /*
86582 * static variable?
86583 */
86584 @@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86585 if (!static_obj(lock->key)) {
86586 debug_locks_off();
86587 printk("INFO: trying to register non-static key.\n");
86588 + printk("lock:%pS key:%pS.\n", lock, lock->key);
86589 printk("the code is fine but needs lockdep annotation.\n");
86590 printk("turning off the locking correctness validator.\n");
86591 dump_stack();
86592 @@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86593 if (!class)
86594 return 0;
86595 }
86596 - atomic_inc((atomic_t *)&class->ops);
86597 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86598 if (very_verbose(class)) {
86599 printk("\nacquire class [%p] %s", class->key, class->name);
86600 if (class->name_version > 1)
86601 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86602 index ef43ac4..2720dfa 100644
86603 --- a/kernel/locking/lockdep_proc.c
86604 +++ b/kernel/locking/lockdep_proc.c
86605 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86606 return 0;
86607 }
86608
86609 - seq_printf(m, "%p", class->key);
86610 + seq_printf(m, "%pK", class->key);
86611 #ifdef CONFIG_DEBUG_LOCKDEP
86612 seq_printf(m, " OPS:%8ld", class->ops);
86613 #endif
86614 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86615
86616 list_for_each_entry(entry, &class->locks_after, entry) {
86617 if (entry->distance == 1) {
86618 - seq_printf(m, " -> [%p] ", entry->class->key);
86619 + seq_printf(m, " -> [%pK] ", entry->class->key);
86620 print_name(m, entry->class);
86621 seq_puts(m, "\n");
86622 }
86623 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86624 if (!class->key)
86625 continue;
86626
86627 - seq_printf(m, "[%p] ", class->key);
86628 + seq_printf(m, "[%pK] ", class->key);
86629 print_name(m, class);
86630 seq_puts(m, "\n");
86631 }
86632 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86633 if (!i)
86634 seq_line(m, '-', 40-namelen, namelen);
86635
86636 - snprintf(ip, sizeof(ip), "[<%p>]",
86637 + snprintf(ip, sizeof(ip), "[<%pK>]",
86638 (void *)class->contention_point[i]);
86639 seq_printf(m, "%40s %14lu %29s %pS\n",
86640 name, stats->contention_point[i],
86641 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86642 if (!i)
86643 seq_line(m, '-', 40-namelen, namelen);
86644
86645 - snprintf(ip, sizeof(ip), "[<%p>]",
86646 + snprintf(ip, sizeof(ip), "[<%pK>]",
86647 (void *)class->contending_point[i]);
86648 seq_printf(m, "%40s %14lu %29s %pS\n",
86649 name, stats->contending_point[i],
86650 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86651 index 7e3443f..b2a1e6b 100644
86652 --- a/kernel/locking/mutex-debug.c
86653 +++ b/kernel/locking/mutex-debug.c
86654 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86655 }
86656
86657 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86658 - struct thread_info *ti)
86659 + struct task_struct *task)
86660 {
86661 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86662
86663 /* Mark the current thread as blocked on the lock: */
86664 - ti->task->blocked_on = waiter;
86665 + task->blocked_on = waiter;
86666 }
86667
86668 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86669 - struct thread_info *ti)
86670 + struct task_struct *task)
86671 {
86672 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86673 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86674 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86675 - ti->task->blocked_on = NULL;
86676 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
86677 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86678 + task->blocked_on = NULL;
86679
86680 list_del_init(&waiter->list);
86681 waiter->task = NULL;
86682 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86683 index 0799fd3..d06ae3b 100644
86684 --- a/kernel/locking/mutex-debug.h
86685 +++ b/kernel/locking/mutex-debug.h
86686 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86687 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86688 extern void debug_mutex_add_waiter(struct mutex *lock,
86689 struct mutex_waiter *waiter,
86690 - struct thread_info *ti);
86691 + struct task_struct *task);
86692 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86693 - struct thread_info *ti);
86694 + struct task_struct *task);
86695 extern void debug_mutex_unlock(struct mutex *lock);
86696 extern void debug_mutex_init(struct mutex *lock, const char *name,
86697 struct lock_class_key *key);
86698 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86699 index 4dd6e4c..df52693 100644
86700 --- a/kernel/locking/mutex.c
86701 +++ b/kernel/locking/mutex.c
86702 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86703 node->locked = 1;
86704 return;
86705 }
86706 - ACCESS_ONCE(prev->next) = node;
86707 + ACCESS_ONCE_RW(prev->next) = node;
86708 smp_wmb();
86709 /* Wait until the lock holder passes the lock down */
86710 while (!ACCESS_ONCE(node->locked))
86711 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86712 while (!(next = ACCESS_ONCE(node->next)))
86713 arch_mutex_cpu_relax();
86714 }
86715 - ACCESS_ONCE(next->locked) = 1;
86716 + ACCESS_ONCE_RW(next->locked) = 1;
86717 smp_wmb();
86718 }
86719
86720 @@ -520,7 +520,7 @@ slowpath:
86721 goto skip_wait;
86722
86723 debug_mutex_lock_common(lock, &waiter);
86724 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86725 + debug_mutex_add_waiter(lock, &waiter, task);
86726
86727 /* add waiting tasks to the end of the waitqueue (FIFO): */
86728 list_add_tail(&waiter.list, &lock->wait_list);
86729 @@ -564,7 +564,7 @@ slowpath:
86730 schedule_preempt_disabled();
86731 spin_lock_mutex(&lock->wait_lock, flags);
86732 }
86733 - mutex_remove_waiter(lock, &waiter, current_thread_info());
86734 + mutex_remove_waiter(lock, &waiter, task);
86735 /* set it to 0 if there are no waiters left: */
86736 if (likely(list_empty(&lock->wait_list)))
86737 atomic_set(&lock->count, 0);
86738 @@ -601,7 +601,7 @@ skip_wait:
86739 return 0;
86740
86741 err:
86742 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86743 + mutex_remove_waiter(lock, &waiter, task);
86744 spin_unlock_mutex(&lock->wait_lock, flags);
86745 debug_mutex_free_waiter(&waiter);
86746 mutex_release(&lock->dep_map, 1, ip);
86747 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86748 index 1d96dd0..994ff19 100644
86749 --- a/kernel/locking/rtmutex-tester.c
86750 +++ b/kernel/locking/rtmutex-tester.c
86751 @@ -22,7 +22,7 @@
86752 #define MAX_RT_TEST_MUTEXES 8
86753
86754 static spinlock_t rttest_lock;
86755 -static atomic_t rttest_event;
86756 +static atomic_unchecked_t rttest_event;
86757
86758 struct test_thread_data {
86759 int opcode;
86760 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86761
86762 case RTTEST_LOCKCONT:
86763 td->mutexes[td->opdata] = 1;
86764 - td->event = atomic_add_return(1, &rttest_event);
86765 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86766 return 0;
86767
86768 case RTTEST_RESET:
86769 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86770 return 0;
86771
86772 case RTTEST_RESETEVENT:
86773 - atomic_set(&rttest_event, 0);
86774 + atomic_set_unchecked(&rttest_event, 0);
86775 return 0;
86776
86777 default:
86778 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86779 return ret;
86780
86781 td->mutexes[id] = 1;
86782 - td->event = atomic_add_return(1, &rttest_event);
86783 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86784 rt_mutex_lock(&mutexes[id]);
86785 - td->event = atomic_add_return(1, &rttest_event);
86786 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86787 td->mutexes[id] = 4;
86788 return 0;
86789
86790 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86791 return ret;
86792
86793 td->mutexes[id] = 1;
86794 - td->event = atomic_add_return(1, &rttest_event);
86795 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86796 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86797 - td->event = atomic_add_return(1, &rttest_event);
86798 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86799 td->mutexes[id] = ret ? 0 : 4;
86800 return ret ? -EINTR : 0;
86801
86802 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86803 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86804 return ret;
86805
86806 - td->event = atomic_add_return(1, &rttest_event);
86807 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86808 rt_mutex_unlock(&mutexes[id]);
86809 - td->event = atomic_add_return(1, &rttest_event);
86810 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86811 td->mutexes[id] = 0;
86812 return 0;
86813
86814 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86815 break;
86816
86817 td->mutexes[dat] = 2;
86818 - td->event = atomic_add_return(1, &rttest_event);
86819 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86820 break;
86821
86822 default:
86823 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86824 return;
86825
86826 td->mutexes[dat] = 3;
86827 - td->event = atomic_add_return(1, &rttest_event);
86828 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86829 break;
86830
86831 case RTTEST_LOCKNOWAIT:
86832 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86833 return;
86834
86835 td->mutexes[dat] = 1;
86836 - td->event = atomic_add_return(1, &rttest_event);
86837 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86838 return;
86839
86840 default:
86841 diff --git a/kernel/module.c b/kernel/module.c
86842 index f5a3b1e..97ebb15 100644
86843 --- a/kernel/module.c
86844 +++ b/kernel/module.c
86845 @@ -61,6 +61,7 @@
86846 #include <linux/pfn.h>
86847 #include <linux/bsearch.h>
86848 #include <linux/fips.h>
86849 +#include <linux/grsecurity.h>
86850 #include <uapi/linux/module.h>
86851 #include "module-internal.h"
86852
86853 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
86854
86855 /* Bounds of module allocation, for speeding __module_address.
86856 * Protected by module_mutex. */
86857 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
86858 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
86859 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
86860
86861 int register_module_notifier(struct notifier_block * nb)
86862 {
86863 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86864 return true;
86865
86866 list_for_each_entry_rcu(mod, &modules, list) {
86867 - struct symsearch arr[] = {
86868 + struct symsearch modarr[] = {
86869 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
86870 NOT_GPL_ONLY, false },
86871 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
86872 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86873 if (mod->state == MODULE_STATE_UNFORMED)
86874 continue;
86875
86876 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
86877 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
86878 return true;
86879 }
86880 return false;
86881 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
86882 if (!pcpusec->sh_size)
86883 return 0;
86884
86885 - if (align > PAGE_SIZE) {
86886 + if (align-1 >= PAGE_SIZE) {
86887 pr_warn("%s: per-cpu alignment %li > %li\n",
86888 mod->name, align, PAGE_SIZE);
86889 align = PAGE_SIZE;
86890 @@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
86891 static ssize_t show_coresize(struct module_attribute *mattr,
86892 struct module_kobject *mk, char *buffer)
86893 {
86894 - return sprintf(buffer, "%u\n", mk->mod->core_size);
86895 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
86896 }
86897
86898 static struct module_attribute modinfo_coresize =
86899 @@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
86900 static ssize_t show_initsize(struct module_attribute *mattr,
86901 struct module_kobject *mk, char *buffer)
86902 {
86903 - return sprintf(buffer, "%u\n", mk->mod->init_size);
86904 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
86905 }
86906
86907 static struct module_attribute modinfo_initsize =
86908 @@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
86909 goto bad_version;
86910 }
86911
86912 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86913 + /*
86914 + * avoid potentially printing jibberish on attempted load
86915 + * of a module randomized with a different seed
86916 + */
86917 + pr_warn("no symbol version for %s\n", symname);
86918 +#else
86919 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
86920 +#endif
86921 return 0;
86922
86923 bad_version:
86924 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86925 + /*
86926 + * avoid potentially printing jibberish on attempted load
86927 + * of a module randomized with a different seed
86928 + */
86929 + printk("attempted module disagrees about version of symbol %s\n",
86930 + symname);
86931 +#else
86932 printk("%s: disagrees about version of symbol %s\n",
86933 mod->name, symname);
86934 +#endif
86935 return 0;
86936 }
86937
86938 @@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
86939 */
86940 #ifdef CONFIG_SYSFS
86941
86942 -#ifdef CONFIG_KALLSYMS
86943 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
86944 static inline bool sect_empty(const Elf_Shdr *sect)
86945 {
86946 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
86947 @@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
86948 {
86949 unsigned int notes, loaded, i;
86950 struct module_notes_attrs *notes_attrs;
86951 - struct bin_attribute *nattr;
86952 + bin_attribute_no_const *nattr;
86953
86954 /* failed to create section attributes, so can't create notes */
86955 if (!mod->sect_attrs)
86956 @@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
86957 static int module_add_modinfo_attrs(struct module *mod)
86958 {
86959 struct module_attribute *attr;
86960 - struct module_attribute *temp_attr;
86961 + module_attribute_no_const *temp_attr;
86962 int error = 0;
86963 int i;
86964
86965 @@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
86966
86967 static void unset_module_core_ro_nx(struct module *mod)
86968 {
86969 - set_page_attributes(mod->module_core + mod->core_text_size,
86970 - mod->module_core + mod->core_size,
86971 + set_page_attributes(mod->module_core_rw,
86972 + mod->module_core_rw + mod->core_size_rw,
86973 set_memory_x);
86974 - set_page_attributes(mod->module_core,
86975 - mod->module_core + mod->core_ro_size,
86976 + set_page_attributes(mod->module_core_rx,
86977 + mod->module_core_rx + mod->core_size_rx,
86978 set_memory_rw);
86979 }
86980
86981 static void unset_module_init_ro_nx(struct module *mod)
86982 {
86983 - set_page_attributes(mod->module_init + mod->init_text_size,
86984 - mod->module_init + mod->init_size,
86985 + set_page_attributes(mod->module_init_rw,
86986 + mod->module_init_rw + mod->init_size_rw,
86987 set_memory_x);
86988 - set_page_attributes(mod->module_init,
86989 - mod->module_init + mod->init_ro_size,
86990 + set_page_attributes(mod->module_init_rx,
86991 + mod->module_init_rx + mod->init_size_rx,
86992 set_memory_rw);
86993 }
86994
86995 @@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
86996 list_for_each_entry_rcu(mod, &modules, list) {
86997 if (mod->state == MODULE_STATE_UNFORMED)
86998 continue;
86999 - if ((mod->module_core) && (mod->core_text_size)) {
87000 - set_page_attributes(mod->module_core,
87001 - mod->module_core + mod->core_text_size,
87002 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
87003 + set_page_attributes(mod->module_core_rx,
87004 + mod->module_core_rx + mod->core_size_rx,
87005 set_memory_rw);
87006 }
87007 - if ((mod->module_init) && (mod->init_text_size)) {
87008 - set_page_attributes(mod->module_init,
87009 - mod->module_init + mod->init_text_size,
87010 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
87011 + set_page_attributes(mod->module_init_rx,
87012 + mod->module_init_rx + mod->init_size_rx,
87013 set_memory_rw);
87014 }
87015 }
87016 @@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
87017 list_for_each_entry_rcu(mod, &modules, list) {
87018 if (mod->state == MODULE_STATE_UNFORMED)
87019 continue;
87020 - if ((mod->module_core) && (mod->core_text_size)) {
87021 - set_page_attributes(mod->module_core,
87022 - mod->module_core + mod->core_text_size,
87023 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
87024 + set_page_attributes(mod->module_core_rx,
87025 + mod->module_core_rx + mod->core_size_rx,
87026 set_memory_ro);
87027 }
87028 - if ((mod->module_init) && (mod->init_text_size)) {
87029 - set_page_attributes(mod->module_init,
87030 - mod->module_init + mod->init_text_size,
87031 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
87032 + set_page_attributes(mod->module_init_rx,
87033 + mod->module_init_rx + mod->init_size_rx,
87034 set_memory_ro);
87035 }
87036 }
87037 @@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
87038
87039 /* This may be NULL, but that's OK */
87040 unset_module_init_ro_nx(mod);
87041 - module_free(mod, mod->module_init);
87042 + module_free(mod, mod->module_init_rw);
87043 + module_free_exec(mod, mod->module_init_rx);
87044 kfree(mod->args);
87045 percpu_modfree(mod);
87046
87047 /* Free lock-classes: */
87048 - lockdep_free_key_range(mod->module_core, mod->core_size);
87049 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87050 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87051
87052 /* Finally, free the core (containing the module structure) */
87053 unset_module_core_ro_nx(mod);
87054 - module_free(mod, mod->module_core);
87055 + module_free_exec(mod, mod->module_core_rx);
87056 + module_free(mod, mod->module_core_rw);
87057
87058 #ifdef CONFIG_MPU
87059 update_protections(current->mm);
87060 @@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87061 int ret = 0;
87062 const struct kernel_symbol *ksym;
87063
87064 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87065 + int is_fs_load = 0;
87066 + int register_filesystem_found = 0;
87067 + char *p;
87068 +
87069 + p = strstr(mod->args, "grsec_modharden_fs");
87070 + if (p) {
87071 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87072 + /* copy \0 as well */
87073 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87074 + is_fs_load = 1;
87075 + }
87076 +#endif
87077 +
87078 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87079 const char *name = info->strtab + sym[i].st_name;
87080
87081 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87082 + /* it's a real shame this will never get ripped and copied
87083 + upstream! ;(
87084 + */
87085 + if (is_fs_load && !strcmp(name, "register_filesystem"))
87086 + register_filesystem_found = 1;
87087 +#endif
87088 +
87089 switch (sym[i].st_shndx) {
87090 case SHN_COMMON:
87091 /* We compiled with -fno-common. These are not
87092 @@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87093 ksym = resolve_symbol_wait(mod, info, name);
87094 /* Ok if resolved. */
87095 if (ksym && !IS_ERR(ksym)) {
87096 + pax_open_kernel();
87097 sym[i].st_value = ksym->value;
87098 + pax_close_kernel();
87099 break;
87100 }
87101
87102 @@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87103 secbase = (unsigned long)mod_percpu(mod);
87104 else
87105 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87106 + pax_open_kernel();
87107 sym[i].st_value += secbase;
87108 + pax_close_kernel();
87109 break;
87110 }
87111 }
87112
87113 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87114 + if (is_fs_load && !register_filesystem_found) {
87115 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87116 + ret = -EPERM;
87117 + }
87118 +#endif
87119 +
87120 return ret;
87121 }
87122
87123 @@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87124 || s->sh_entsize != ~0UL
87125 || strstarts(sname, ".init"))
87126 continue;
87127 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87128 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87129 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87130 + else
87131 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87132 pr_debug("\t%s\n", sname);
87133 }
87134 - switch (m) {
87135 - case 0: /* executable */
87136 - mod->core_size = debug_align(mod->core_size);
87137 - mod->core_text_size = mod->core_size;
87138 - break;
87139 - case 1: /* RO: text and ro-data */
87140 - mod->core_size = debug_align(mod->core_size);
87141 - mod->core_ro_size = mod->core_size;
87142 - break;
87143 - case 3: /* whole core */
87144 - mod->core_size = debug_align(mod->core_size);
87145 - break;
87146 - }
87147 }
87148
87149 pr_debug("Init section allocation order:\n");
87150 @@ -2104,23 +2149,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87151 || s->sh_entsize != ~0UL
87152 || !strstarts(sname, ".init"))
87153 continue;
87154 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87155 - | INIT_OFFSET_MASK);
87156 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87157 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87158 + else
87159 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87160 + s->sh_entsize |= INIT_OFFSET_MASK;
87161 pr_debug("\t%s\n", sname);
87162 }
87163 - switch (m) {
87164 - case 0: /* executable */
87165 - mod->init_size = debug_align(mod->init_size);
87166 - mod->init_text_size = mod->init_size;
87167 - break;
87168 - case 1: /* RO: text and ro-data */
87169 - mod->init_size = debug_align(mod->init_size);
87170 - mod->init_ro_size = mod->init_size;
87171 - break;
87172 - case 3: /* whole init */
87173 - mod->init_size = debug_align(mod->init_size);
87174 - break;
87175 - }
87176 }
87177 }
87178
87179 @@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87180
87181 /* Put symbol section at end of init part of module. */
87182 symsect->sh_flags |= SHF_ALLOC;
87183 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87184 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87185 info->index.sym) | INIT_OFFSET_MASK;
87186 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87187
87188 @@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87189 }
87190
87191 /* Append room for core symbols at end of core part. */
87192 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87193 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87194 - mod->core_size += strtab_size;
87195 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87196 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87197 + mod->core_size_rx += strtab_size;
87198
87199 /* Put string table section at end of init part of module. */
87200 strsect->sh_flags |= SHF_ALLOC;
87201 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87202 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87203 info->index.str) | INIT_OFFSET_MASK;
87204 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87205 }
87206 @@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87207 /* Make sure we get permanent strtab: don't use info->strtab. */
87208 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87209
87210 + pax_open_kernel();
87211 +
87212 /* Set types up while we still have access to sections. */
87213 for (i = 0; i < mod->num_symtab; i++)
87214 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87215
87216 - mod->core_symtab = dst = mod->module_core + info->symoffs;
87217 - mod->core_strtab = s = mod->module_core + info->stroffs;
87218 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87219 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87220 src = mod->symtab;
87221 for (ndst = i = 0; i < mod->num_symtab; i++) {
87222 if (i == 0 ||
87223 @@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87224 }
87225 }
87226 mod->core_num_syms = ndst;
87227 +
87228 + pax_close_kernel();
87229 }
87230 #else
87231 static inline void layout_symtab(struct module *mod, struct load_info *info)
87232 @@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
87233 return vmalloc_exec(size);
87234 }
87235
87236 -static void *module_alloc_update_bounds(unsigned long size)
87237 +static void *module_alloc_update_bounds_rw(unsigned long size)
87238 {
87239 void *ret = module_alloc(size);
87240
87241 if (ret) {
87242 mutex_lock(&module_mutex);
87243 /* Update module bounds. */
87244 - if ((unsigned long)ret < module_addr_min)
87245 - module_addr_min = (unsigned long)ret;
87246 - if ((unsigned long)ret + size > module_addr_max)
87247 - module_addr_max = (unsigned long)ret + size;
87248 + if ((unsigned long)ret < module_addr_min_rw)
87249 + module_addr_min_rw = (unsigned long)ret;
87250 + if ((unsigned long)ret + size > module_addr_max_rw)
87251 + module_addr_max_rw = (unsigned long)ret + size;
87252 + mutex_unlock(&module_mutex);
87253 + }
87254 + return ret;
87255 +}
87256 +
87257 +static void *module_alloc_update_bounds_rx(unsigned long size)
87258 +{
87259 + void *ret = module_alloc_exec(size);
87260 +
87261 + if (ret) {
87262 + mutex_lock(&module_mutex);
87263 + /* Update module bounds. */
87264 + if ((unsigned long)ret < module_addr_min_rx)
87265 + module_addr_min_rx = (unsigned long)ret;
87266 + if ((unsigned long)ret + size > module_addr_max_rx)
87267 + module_addr_max_rx = (unsigned long)ret + size;
87268 mutex_unlock(&module_mutex);
87269 }
87270 return ret;
87271 @@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87272 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87273
87274 if (info->index.sym == 0) {
87275 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87276 + /*
87277 + * avoid potentially printing jibberish on attempted load
87278 + * of a module randomized with a different seed
87279 + */
87280 + pr_warn("module has no symbols (stripped?)\n");
87281 +#else
87282 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87283 +#endif
87284 return ERR_PTR(-ENOEXEC);
87285 }
87286
87287 @@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87288 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87289 {
87290 const char *modmagic = get_modinfo(info, "vermagic");
87291 + const char *license = get_modinfo(info, "license");
87292 int err;
87293
87294 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87295 + if (!license || !license_is_gpl_compatible(license))
87296 + return -ENOEXEC;
87297 +#endif
87298 +
87299 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87300 modmagic = NULL;
87301
87302 @@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87303 }
87304
87305 /* Set up license info based on the info section */
87306 - set_license(mod, get_modinfo(info, "license"));
87307 + set_license(mod, license);
87308
87309 return 0;
87310 }
87311 @@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
87312 void *ptr;
87313
87314 /* Do the allocs. */
87315 - ptr = module_alloc_update_bounds(mod->core_size);
87316 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87317 /*
87318 * The pointer to this block is stored in the module structure
87319 * which is inside the block. Just mark it as not being a
87320 @@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
87321 if (!ptr)
87322 return -ENOMEM;
87323
87324 - memset(ptr, 0, mod->core_size);
87325 - mod->module_core = ptr;
87326 + memset(ptr, 0, mod->core_size_rw);
87327 + mod->module_core_rw = ptr;
87328
87329 - if (mod->init_size) {
87330 - ptr = module_alloc_update_bounds(mod->init_size);
87331 + if (mod->init_size_rw) {
87332 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87333 /*
87334 * The pointer to this block is stored in the module structure
87335 * which is inside the block. This block doesn't need to be
87336 @@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
87337 */
87338 kmemleak_ignore(ptr);
87339 if (!ptr) {
87340 - module_free(mod, mod->module_core);
87341 + module_free(mod, mod->module_core_rw);
87342 return -ENOMEM;
87343 }
87344 - memset(ptr, 0, mod->init_size);
87345 - mod->module_init = ptr;
87346 + memset(ptr, 0, mod->init_size_rw);
87347 + mod->module_init_rw = ptr;
87348 } else
87349 - mod->module_init = NULL;
87350 + mod->module_init_rw = NULL;
87351 +
87352 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87353 + kmemleak_not_leak(ptr);
87354 + if (!ptr) {
87355 + if (mod->module_init_rw)
87356 + module_free(mod, mod->module_init_rw);
87357 + module_free(mod, mod->module_core_rw);
87358 + return -ENOMEM;
87359 + }
87360 +
87361 + pax_open_kernel();
87362 + memset(ptr, 0, mod->core_size_rx);
87363 + pax_close_kernel();
87364 + mod->module_core_rx = ptr;
87365 +
87366 + if (mod->init_size_rx) {
87367 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87368 + kmemleak_ignore(ptr);
87369 + if (!ptr && mod->init_size_rx) {
87370 + module_free_exec(mod, mod->module_core_rx);
87371 + if (mod->module_init_rw)
87372 + module_free(mod, mod->module_init_rw);
87373 + module_free(mod, mod->module_core_rw);
87374 + return -ENOMEM;
87375 + }
87376 +
87377 + pax_open_kernel();
87378 + memset(ptr, 0, mod->init_size_rx);
87379 + pax_close_kernel();
87380 + mod->module_init_rx = ptr;
87381 + } else
87382 + mod->module_init_rx = NULL;
87383
87384 /* Transfer each section which specifies SHF_ALLOC */
87385 pr_debug("final section addresses:\n");
87386 @@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
87387 if (!(shdr->sh_flags & SHF_ALLOC))
87388 continue;
87389
87390 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
87391 - dest = mod->module_init
87392 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87393 - else
87394 - dest = mod->module_core + shdr->sh_entsize;
87395 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87396 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87397 + dest = mod->module_init_rw
87398 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87399 + else
87400 + dest = mod->module_init_rx
87401 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87402 + } else {
87403 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87404 + dest = mod->module_core_rw + shdr->sh_entsize;
87405 + else
87406 + dest = mod->module_core_rx + shdr->sh_entsize;
87407 + }
87408 +
87409 + if (shdr->sh_type != SHT_NOBITS) {
87410 +
87411 +#ifdef CONFIG_PAX_KERNEXEC
87412 +#ifdef CONFIG_X86_64
87413 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87414 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87415 +#endif
87416 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87417 + pax_open_kernel();
87418 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87419 + pax_close_kernel();
87420 + } else
87421 +#endif
87422
87423 - if (shdr->sh_type != SHT_NOBITS)
87424 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87425 + }
87426 /* Update sh_addr to point to copy in image. */
87427 - shdr->sh_addr = (unsigned long)dest;
87428 +
87429 +#ifdef CONFIG_PAX_KERNEXEC
87430 + if (shdr->sh_flags & SHF_EXECINSTR)
87431 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
87432 + else
87433 +#endif
87434 +
87435 + shdr->sh_addr = (unsigned long)dest;
87436 pr_debug("\t0x%lx %s\n",
87437 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87438 }
87439 @@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
87440 * Do it before processing of module parameters, so the module
87441 * can provide parameter accessor functions of its own.
87442 */
87443 - if (mod->module_init)
87444 - flush_icache_range((unsigned long)mod->module_init,
87445 - (unsigned long)mod->module_init
87446 - + mod->init_size);
87447 - flush_icache_range((unsigned long)mod->module_core,
87448 - (unsigned long)mod->module_core + mod->core_size);
87449 + if (mod->module_init_rx)
87450 + flush_icache_range((unsigned long)mod->module_init_rx,
87451 + (unsigned long)mod->module_init_rx
87452 + + mod->init_size_rx);
87453 + flush_icache_range((unsigned long)mod->module_core_rx,
87454 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
87455
87456 set_fs(old_fs);
87457 }
87458 @@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87459 static void module_deallocate(struct module *mod, struct load_info *info)
87460 {
87461 percpu_modfree(mod);
87462 - module_free(mod, mod->module_init);
87463 - module_free(mod, mod->module_core);
87464 + module_free_exec(mod, mod->module_init_rx);
87465 + module_free_exec(mod, mod->module_core_rx);
87466 + module_free(mod, mod->module_init_rw);
87467 + module_free(mod, mod->module_core_rw);
87468 }
87469
87470 int __weak module_finalize(const Elf_Ehdr *hdr,
87471 @@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87472 static int post_relocation(struct module *mod, const struct load_info *info)
87473 {
87474 /* Sort exception table now relocations are done. */
87475 + pax_open_kernel();
87476 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87477 + pax_close_kernel();
87478
87479 /* Copy relocated percpu area over. */
87480 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87481 @@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
87482 MODULE_STATE_COMING, mod);
87483
87484 /* Set RO and NX regions for core */
87485 - set_section_ro_nx(mod->module_core,
87486 - mod->core_text_size,
87487 - mod->core_ro_size,
87488 - mod->core_size);
87489 + set_section_ro_nx(mod->module_core_rx,
87490 + mod->core_size_rx,
87491 + mod->core_size_rx,
87492 + mod->core_size_rx);
87493
87494 /* Set RO and NX regions for init */
87495 - set_section_ro_nx(mod->module_init,
87496 - mod->init_text_size,
87497 - mod->init_ro_size,
87498 - mod->init_size);
87499 + set_section_ro_nx(mod->module_init_rx,
87500 + mod->init_size_rx,
87501 + mod->init_size_rx,
87502 + mod->init_size_rx);
87503
87504 do_mod_ctors(mod);
87505 /* Start the module */
87506 @@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
87507 mod->strtab = mod->core_strtab;
87508 #endif
87509 unset_module_init_ro_nx(mod);
87510 - module_free(mod, mod->module_init);
87511 - mod->module_init = NULL;
87512 - mod->init_size = 0;
87513 - mod->init_ro_size = 0;
87514 - mod->init_text_size = 0;
87515 + module_free(mod, mod->module_init_rw);
87516 + module_free_exec(mod, mod->module_init_rx);
87517 + mod->module_init_rw = NULL;
87518 + mod->module_init_rx = NULL;
87519 + mod->init_size_rw = 0;
87520 + mod->init_size_rx = 0;
87521 mutex_unlock(&module_mutex);
87522 wake_up_all(&module_wq);
87523
87524 @@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87525 if (err)
87526 goto free_unload;
87527
87528 + /* Now copy in args */
87529 + mod->args = strndup_user(uargs, ~0UL >> 1);
87530 + if (IS_ERR(mod->args)) {
87531 + err = PTR_ERR(mod->args);
87532 + goto free_unload;
87533 + }
87534 +
87535 /* Set up MODINFO_ATTR fields */
87536 setup_modinfo(mod, info);
87537
87538 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87539 + {
87540 + char *p, *p2;
87541 +
87542 + if (strstr(mod->args, "grsec_modharden_netdev")) {
87543 + 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);
87544 + err = -EPERM;
87545 + goto free_modinfo;
87546 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87547 + p += sizeof("grsec_modharden_normal") - 1;
87548 + p2 = strstr(p, "_");
87549 + if (p2) {
87550 + *p2 = '\0';
87551 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87552 + *p2 = '_';
87553 + }
87554 + err = -EPERM;
87555 + goto free_modinfo;
87556 + }
87557 + }
87558 +#endif
87559 +
87560 /* Fix up syms, so that st_value is a pointer to location. */
87561 err = simplify_symbols(mod, info);
87562 if (err < 0)
87563 @@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87564
87565 flush_module_icache(mod);
87566
87567 - /* Now copy in args */
87568 - mod->args = strndup_user(uargs, ~0UL >> 1);
87569 - if (IS_ERR(mod->args)) {
87570 - err = PTR_ERR(mod->args);
87571 - goto free_arch_cleanup;
87572 - }
87573 -
87574 dynamic_debug_setup(info->debug, info->num_debug);
87575
87576 /* Finally it's fully formed, ready to start executing. */
87577 @@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87578 ddebug_cleanup:
87579 dynamic_debug_remove(info->debug);
87580 synchronize_sched();
87581 - kfree(mod->args);
87582 - free_arch_cleanup:
87583 module_arch_cleanup(mod);
87584 free_modinfo:
87585 free_modinfo(mod);
87586 + kfree(mod->args);
87587 free_unload:
87588 module_unload_free(mod);
87589 unlink_mod:
87590 @@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
87591 unsigned long nextval;
87592
87593 /* At worse, next value is at end of module */
87594 - if (within_module_init(addr, mod))
87595 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
87596 + if (within_module_init_rx(addr, mod))
87597 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87598 + else if (within_module_init_rw(addr, mod))
87599 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87600 + else if (within_module_core_rx(addr, mod))
87601 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87602 + else if (within_module_core_rw(addr, mod))
87603 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87604 else
87605 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
87606 + return NULL;
87607
87608 /* Scan for closest preceding symbol, and next symbol. (ELF
87609 starts real symbols at 1). */
87610 @@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
87611 return 0;
87612
87613 seq_printf(m, "%s %u",
87614 - mod->name, mod->init_size + mod->core_size);
87615 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87616 print_unload_info(m, mod);
87617
87618 /* Informative for users. */
87619 @@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
87620 mod->state == MODULE_STATE_COMING ? "Loading":
87621 "Live");
87622 /* Used by oprofile and other similar tools. */
87623 - seq_printf(m, " 0x%pK", mod->module_core);
87624 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87625
87626 /* Taints info */
87627 if (mod->taints)
87628 @@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
87629
87630 static int __init proc_modules_init(void)
87631 {
87632 +#ifndef CONFIG_GRKERNSEC_HIDESYM
87633 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87634 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87635 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87636 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87637 +#else
87638 proc_create("modules", 0, NULL, &proc_modules_operations);
87639 +#endif
87640 +#else
87641 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87642 +#endif
87643 return 0;
87644 }
87645 module_init(proc_modules_init);
87646 @@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
87647 {
87648 struct module *mod;
87649
87650 - if (addr < module_addr_min || addr > module_addr_max)
87651 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87652 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
87653 return NULL;
87654
87655 list_for_each_entry_rcu(mod, &modules, list) {
87656 if (mod->state == MODULE_STATE_UNFORMED)
87657 continue;
87658 - if (within_module_core(addr, mod)
87659 - || within_module_init(addr, mod))
87660 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
87661 return mod;
87662 }
87663 return NULL;
87664 @@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
87665 */
87666 struct module *__module_text_address(unsigned long addr)
87667 {
87668 - struct module *mod = __module_address(addr);
87669 + struct module *mod;
87670 +
87671 +#ifdef CONFIG_X86_32
87672 + addr = ktla_ktva(addr);
87673 +#endif
87674 +
87675 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87676 + return NULL;
87677 +
87678 + mod = __module_address(addr);
87679 +
87680 if (mod) {
87681 /* Make sure it's within the text section. */
87682 - if (!within(addr, mod->module_init, mod->init_text_size)
87683 - && !within(addr, mod->module_core, mod->core_text_size))
87684 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87685 mod = NULL;
87686 }
87687 return mod;
87688 diff --git a/kernel/notifier.c b/kernel/notifier.c
87689 index 2d5cc4c..d9ea600 100644
87690 --- a/kernel/notifier.c
87691 +++ b/kernel/notifier.c
87692 @@ -5,6 +5,7 @@
87693 #include <linux/rcupdate.h>
87694 #include <linux/vmalloc.h>
87695 #include <linux/reboot.h>
87696 +#include <linux/mm.h>
87697
87698 /*
87699 * Notifier list for kernel code which wants to be called
87700 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87701 while ((*nl) != NULL) {
87702 if (n->priority > (*nl)->priority)
87703 break;
87704 - nl = &((*nl)->next);
87705 + nl = (struct notifier_block **)&((*nl)->next);
87706 }
87707 - n->next = *nl;
87708 + pax_open_kernel();
87709 + *(const void **)&n->next = *nl;
87710 rcu_assign_pointer(*nl, n);
87711 + pax_close_kernel();
87712 return 0;
87713 }
87714
87715 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87716 return 0;
87717 if (n->priority > (*nl)->priority)
87718 break;
87719 - nl = &((*nl)->next);
87720 + nl = (struct notifier_block **)&((*nl)->next);
87721 }
87722 - n->next = *nl;
87723 + pax_open_kernel();
87724 + *(const void **)&n->next = *nl;
87725 rcu_assign_pointer(*nl, n);
87726 + pax_close_kernel();
87727 return 0;
87728 }
87729
87730 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87731 {
87732 while ((*nl) != NULL) {
87733 if ((*nl) == n) {
87734 + pax_open_kernel();
87735 rcu_assign_pointer(*nl, n->next);
87736 + pax_close_kernel();
87737 return 0;
87738 }
87739 - nl = &((*nl)->next);
87740 + nl = (struct notifier_block **)&((*nl)->next);
87741 }
87742 return -ENOENT;
87743 }
87744 diff --git a/kernel/padata.c b/kernel/padata.c
87745 index 2abd25d..02c4faa 100644
87746 --- a/kernel/padata.c
87747 +++ b/kernel/padata.c
87748 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87749 * seq_nr mod. number of cpus in use.
87750 */
87751
87752 - seq_nr = atomic_inc_return(&pd->seq_nr);
87753 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87754 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87755
87756 return padata_index_to_cpu(pd, cpu_index);
87757 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87758 padata_init_pqueues(pd);
87759 padata_init_squeues(pd);
87760 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87761 - atomic_set(&pd->seq_nr, -1);
87762 + atomic_set_unchecked(&pd->seq_nr, -1);
87763 atomic_set(&pd->reorder_objects, 0);
87764 atomic_set(&pd->refcnt, 0);
87765 pd->pinst = pinst;
87766 diff --git a/kernel/panic.c b/kernel/panic.c
87767 index c00b4ce..98c7d1a 100644
87768 --- a/kernel/panic.c
87769 +++ b/kernel/panic.c
87770 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87771 /*
87772 * Stop ourself in panic -- architecture code may override this
87773 */
87774 -void __weak panic_smp_self_stop(void)
87775 +void __weak __noreturn panic_smp_self_stop(void)
87776 {
87777 while (1)
87778 cpu_relax();
87779 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87780 disable_trace_on_warning();
87781
87782 pr_warn("------------[ cut here ]------------\n");
87783 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87784 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87785 raw_smp_processor_id(), current->pid, file, line, caller);
87786
87787 if (args)
87788 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87789 */
87790 void __stack_chk_fail(void)
87791 {
87792 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
87793 + dump_stack();
87794 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87795 __builtin_return_address(0));
87796 }
87797 EXPORT_SYMBOL(__stack_chk_fail);
87798 diff --git a/kernel/pid.c b/kernel/pid.c
87799 index 9b9a266..c20ef80 100644
87800 --- a/kernel/pid.c
87801 +++ b/kernel/pid.c
87802 @@ -33,6 +33,7 @@
87803 #include <linux/rculist.h>
87804 #include <linux/bootmem.h>
87805 #include <linux/hash.h>
87806 +#include <linux/security.h>
87807 #include <linux/pid_namespace.h>
87808 #include <linux/init_task.h>
87809 #include <linux/syscalls.h>
87810 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87811
87812 int pid_max = PID_MAX_DEFAULT;
87813
87814 -#define RESERVED_PIDS 300
87815 +#define RESERVED_PIDS 500
87816
87817 int pid_max_min = RESERVED_PIDS + 1;
87818 int pid_max_max = PID_MAX_LIMIT;
87819 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87820 */
87821 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87822 {
87823 + struct task_struct *task;
87824 +
87825 rcu_lockdep_assert(rcu_read_lock_held(),
87826 "find_task_by_pid_ns() needs rcu_read_lock()"
87827 " protection");
87828 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87829 +
87830 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87831 +
87832 + if (gr_pid_is_chrooted(task))
87833 + return NULL;
87834 +
87835 + return task;
87836 }
87837
87838 struct task_struct *find_task_by_vpid(pid_t vnr)
87839 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87840 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87841 }
87842
87843 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87844 +{
87845 + rcu_lockdep_assert(rcu_read_lock_held(),
87846 + "find_task_by_pid_ns() needs rcu_read_lock()"
87847 + " protection");
87848 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
87849 +}
87850 +
87851 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
87852 {
87853 struct pid *pid;
87854 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
87855 index 06c62de..a0ca23f 100644
87856 --- a/kernel/pid_namespace.c
87857 +++ b/kernel/pid_namespace.c
87858 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
87859 void __user *buffer, size_t *lenp, loff_t *ppos)
87860 {
87861 struct pid_namespace *pid_ns = task_active_pid_ns(current);
87862 - struct ctl_table tmp = *table;
87863 + ctl_table_no_const tmp = *table;
87864
87865 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
87866 return -EPERM;
87867 @@ -318,7 +318,9 @@ static void *pidns_get(struct task_struct *task)
87868 struct pid_namespace *ns;
87869
87870 rcu_read_lock();
87871 - ns = get_pid_ns(task_active_pid_ns(task));
87872 + ns = task_active_pid_ns(task);
87873 + if (ns)
87874 + get_pid_ns(ns);
87875 rcu_read_unlock();
87876
87877 return ns;
87878 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
87879 index c7f31aa..2b44977 100644
87880 --- a/kernel/posix-cpu-timers.c
87881 +++ b/kernel/posix-cpu-timers.c
87882 @@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
87883
87884 static __init int init_posix_cpu_timers(void)
87885 {
87886 - struct k_clock process = {
87887 + static struct k_clock process = {
87888 .clock_getres = process_cpu_clock_getres,
87889 .clock_get = process_cpu_clock_get,
87890 .timer_create = process_cpu_timer_create,
87891 .nsleep = process_cpu_nsleep,
87892 .nsleep_restart = process_cpu_nsleep_restart,
87893 };
87894 - struct k_clock thread = {
87895 + static struct k_clock thread = {
87896 .clock_getres = thread_cpu_clock_getres,
87897 .clock_get = thread_cpu_clock_get,
87898 .timer_create = thread_cpu_timer_create,
87899 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
87900 index 424c2d4..679242f 100644
87901 --- a/kernel/posix-timers.c
87902 +++ b/kernel/posix-timers.c
87903 @@ -43,6 +43,7 @@
87904 #include <linux/hash.h>
87905 #include <linux/posix-clock.h>
87906 #include <linux/posix-timers.h>
87907 +#include <linux/grsecurity.h>
87908 #include <linux/syscalls.h>
87909 #include <linux/wait.h>
87910 #include <linux/workqueue.h>
87911 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
87912 * which we beg off on and pass to do_sys_settimeofday().
87913 */
87914
87915 -static struct k_clock posix_clocks[MAX_CLOCKS];
87916 +static struct k_clock *posix_clocks[MAX_CLOCKS];
87917
87918 /*
87919 * These ones are defined below.
87920 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
87921 */
87922 static __init int init_posix_timers(void)
87923 {
87924 - struct k_clock clock_realtime = {
87925 + static struct k_clock clock_realtime = {
87926 .clock_getres = hrtimer_get_res,
87927 .clock_get = posix_clock_realtime_get,
87928 .clock_set = posix_clock_realtime_set,
87929 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
87930 .timer_get = common_timer_get,
87931 .timer_del = common_timer_del,
87932 };
87933 - struct k_clock clock_monotonic = {
87934 + static struct k_clock clock_monotonic = {
87935 .clock_getres = hrtimer_get_res,
87936 .clock_get = posix_ktime_get_ts,
87937 .nsleep = common_nsleep,
87938 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
87939 .timer_get = common_timer_get,
87940 .timer_del = common_timer_del,
87941 };
87942 - struct k_clock clock_monotonic_raw = {
87943 + static struct k_clock clock_monotonic_raw = {
87944 .clock_getres = hrtimer_get_res,
87945 .clock_get = posix_get_monotonic_raw,
87946 };
87947 - struct k_clock clock_realtime_coarse = {
87948 + static struct k_clock clock_realtime_coarse = {
87949 .clock_getres = posix_get_coarse_res,
87950 .clock_get = posix_get_realtime_coarse,
87951 };
87952 - struct k_clock clock_monotonic_coarse = {
87953 + static struct k_clock clock_monotonic_coarse = {
87954 .clock_getres = posix_get_coarse_res,
87955 .clock_get = posix_get_monotonic_coarse,
87956 };
87957 - struct k_clock clock_tai = {
87958 + static struct k_clock clock_tai = {
87959 .clock_getres = hrtimer_get_res,
87960 .clock_get = posix_get_tai,
87961 .nsleep = common_nsleep,
87962 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
87963 .timer_get = common_timer_get,
87964 .timer_del = common_timer_del,
87965 };
87966 - struct k_clock clock_boottime = {
87967 + static struct k_clock clock_boottime = {
87968 .clock_getres = hrtimer_get_res,
87969 .clock_get = posix_get_boottime,
87970 .nsleep = common_nsleep,
87971 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
87972 return;
87973 }
87974
87975 - posix_clocks[clock_id] = *new_clock;
87976 + posix_clocks[clock_id] = new_clock;
87977 }
87978 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
87979
87980 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
87981 return (id & CLOCKFD_MASK) == CLOCKFD ?
87982 &clock_posix_dynamic : &clock_posix_cpu;
87983
87984 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
87985 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
87986 return NULL;
87987 - return &posix_clocks[id];
87988 + return posix_clocks[id];
87989 }
87990
87991 static int common_timer_create(struct k_itimer *new_timer)
87992 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
87993 struct k_clock *kc = clockid_to_kclock(which_clock);
87994 struct k_itimer *new_timer;
87995 int error, new_timer_id;
87996 - sigevent_t event;
87997 + sigevent_t event = { };
87998 int it_id_set = IT_ID_NOT_SET;
87999
88000 if (!kc)
88001 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88002 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88003 return -EFAULT;
88004
88005 + /* only the CLOCK_REALTIME clock can be set, all other clocks
88006 + have their clock_set fptr set to a nosettime dummy function
88007 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88008 + call common_clock_set, which calls do_sys_settimeofday, which
88009 + we hook
88010 + */
88011 +
88012 return kc->clock_set(which_clock, &new_tp);
88013 }
88014
88015 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88016 index 2fac9cc..56fef29 100644
88017 --- a/kernel/power/Kconfig
88018 +++ b/kernel/power/Kconfig
88019 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88020 config HIBERNATION
88021 bool "Hibernation (aka 'suspend to disk')"
88022 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88023 + depends on !GRKERNSEC_KMEM
88024 + depends on !PAX_MEMORY_SANITIZE
88025 select HIBERNATE_CALLBACKS
88026 select LZO_COMPRESS
88027 select LZO_DECOMPRESS
88028 diff --git a/kernel/power/process.c b/kernel/power/process.c
88029 index 06ec886..9dba35e 100644
88030 --- a/kernel/power/process.c
88031 +++ b/kernel/power/process.c
88032 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88033 unsigned int elapsed_msecs;
88034 bool wakeup = false;
88035 int sleep_usecs = USEC_PER_MSEC;
88036 + bool timedout = false;
88037
88038 do_gettimeofday(&start);
88039
88040 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88041
88042 while (true) {
88043 todo = 0;
88044 + if (time_after(jiffies, end_time))
88045 + timedout = true;
88046 read_lock(&tasklist_lock);
88047 do_each_thread(g, p) {
88048 if (p == current || !freeze_task(p))
88049 continue;
88050
88051 - if (!freezer_should_skip(p))
88052 + if (!freezer_should_skip(p)) {
88053 todo++;
88054 + if (timedout) {
88055 + printk(KERN_ERR "Task refusing to freeze:\n");
88056 + sched_show_task(p);
88057 + }
88058 + }
88059 } while_each_thread(g, p);
88060 read_unlock(&tasklist_lock);
88061
88062 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88063 todo += wq_busy;
88064 }
88065
88066 - if (!todo || time_after(jiffies, end_time))
88067 + if (!todo || timedout)
88068 break;
88069
88070 if (pm_wakeup_pending()) {
88071 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88072 index 97fb834..b972b27 100644
88073 --- a/kernel/printk/printk.c
88074 +++ b/kernel/printk/printk.c
88075 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88076 if (from_file && type != SYSLOG_ACTION_OPEN)
88077 return 0;
88078
88079 +#ifdef CONFIG_GRKERNSEC_DMESG
88080 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88081 + return -EPERM;
88082 +#endif
88083 +
88084 if (syslog_action_restricted(type)) {
88085 if (capable(CAP_SYSLOG))
88086 return 0;
88087 diff --git a/kernel/profile.c b/kernel/profile.c
88088 index 6631e1e..310c266 100644
88089 --- a/kernel/profile.c
88090 +++ b/kernel/profile.c
88091 @@ -37,7 +37,7 @@ struct profile_hit {
88092 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88093 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88094
88095 -static atomic_t *prof_buffer;
88096 +static atomic_unchecked_t *prof_buffer;
88097 static unsigned long prof_len, prof_shift;
88098
88099 int prof_on __read_mostly;
88100 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88101 hits[i].pc = 0;
88102 continue;
88103 }
88104 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88105 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88106 hits[i].hits = hits[i].pc = 0;
88107 }
88108 }
88109 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88110 * Add the current hit(s) and flush the write-queue out
88111 * to the global buffer:
88112 */
88113 - atomic_add(nr_hits, &prof_buffer[pc]);
88114 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88115 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88116 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88117 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88118 hits[i].pc = hits[i].hits = 0;
88119 }
88120 out:
88121 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88122 {
88123 unsigned long pc;
88124 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88125 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88126 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88127 }
88128 #endif /* !CONFIG_SMP */
88129
88130 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88131 return -EFAULT;
88132 buf++; p++; count--; read++;
88133 }
88134 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88135 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88136 if (copy_to_user(buf, (void *)pnt, count))
88137 return -EFAULT;
88138 read += count;
88139 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88140 }
88141 #endif
88142 profile_discard_flip_buffers();
88143 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88144 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88145 return count;
88146 }
88147
88148 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88149 index 1f4bcb3..99cf7ab 100644
88150 --- a/kernel/ptrace.c
88151 +++ b/kernel/ptrace.c
88152 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88153 if (seize)
88154 flags |= PT_SEIZED;
88155 rcu_read_lock();
88156 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88157 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88158 flags |= PT_PTRACE_CAP;
88159 rcu_read_unlock();
88160 task->ptrace = flags;
88161 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88162 break;
88163 return -EIO;
88164 }
88165 - if (copy_to_user(dst, buf, retval))
88166 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88167 return -EFAULT;
88168 copied += retval;
88169 src += retval;
88170 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88171 bool seized = child->ptrace & PT_SEIZED;
88172 int ret = -EIO;
88173 siginfo_t siginfo, *si;
88174 - void __user *datavp = (void __user *) data;
88175 + void __user *datavp = (__force void __user *) data;
88176 unsigned long __user *datalp = datavp;
88177 unsigned long flags;
88178
88179 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88180 goto out;
88181 }
88182
88183 + if (gr_handle_ptrace(child, request)) {
88184 + ret = -EPERM;
88185 + goto out_put_task_struct;
88186 + }
88187 +
88188 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88189 ret = ptrace_attach(child, request, addr, data);
88190 /*
88191 * Some architectures need to do book-keeping after
88192 * a ptrace attach.
88193 */
88194 - if (!ret)
88195 + if (!ret) {
88196 arch_ptrace_attach(child);
88197 + gr_audit_ptrace(child);
88198 + }
88199 goto out_put_task_struct;
88200 }
88201
88202 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88203 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88204 if (copied != sizeof(tmp))
88205 return -EIO;
88206 - return put_user(tmp, (unsigned long __user *)data);
88207 + return put_user(tmp, (__force unsigned long __user *)data);
88208 }
88209
88210 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88211 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88212 }
88213
88214 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88215 - compat_long_t addr, compat_long_t data)
88216 + compat_ulong_t addr, compat_ulong_t data)
88217 {
88218 struct task_struct *child;
88219 long ret;
88220 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88221 goto out;
88222 }
88223
88224 + if (gr_handle_ptrace(child, request)) {
88225 + ret = -EPERM;
88226 + goto out_put_task_struct;
88227 + }
88228 +
88229 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88230 ret = ptrace_attach(child, request, addr, data);
88231 /*
88232 * Some architectures need to do book-keeping after
88233 * a ptrace attach.
88234 */
88235 - if (!ret)
88236 + if (!ret) {
88237 arch_ptrace_attach(child);
88238 + gr_audit_ptrace(child);
88239 + }
88240 goto out_put_task_struct;
88241 }
88242
88243 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88244 index 01d5ccb..cdcbee6 100644
88245 --- a/kernel/rcu/srcu.c
88246 +++ b/kernel/rcu/srcu.c
88247 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88248
88249 idx = ACCESS_ONCE(sp->completed) & 0x1;
88250 preempt_disable();
88251 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88252 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88253 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88254 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88255 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88256 preempt_enable();
88257 return idx;
88258 }
88259 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88260 index 1254f31..16258dc 100644
88261 --- a/kernel/rcu/tiny.c
88262 +++ b/kernel/rcu/tiny.c
88263 @@ -46,7 +46,7 @@
88264 /* Forward declarations for tiny_plugin.h. */
88265 struct rcu_ctrlblk;
88266 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88267 -static void rcu_process_callbacks(struct softirq_action *unused);
88268 +static void rcu_process_callbacks(void);
88269 static void __call_rcu(struct rcu_head *head,
88270 void (*func)(struct rcu_head *rcu),
88271 struct rcu_ctrlblk *rcp);
88272 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88273 false));
88274 }
88275
88276 -static void rcu_process_callbacks(struct softirq_action *unused)
88277 +static __latent_entropy void rcu_process_callbacks(void)
88278 {
88279 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88280 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88281 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88282 index 3929cd4..421624d 100644
88283 --- a/kernel/rcu/torture.c
88284 +++ b/kernel/rcu/torture.c
88285 @@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88286 { 0 };
88287 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88288 { 0 };
88289 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88290 -static atomic_t n_rcu_torture_alloc;
88291 -static atomic_t n_rcu_torture_alloc_fail;
88292 -static atomic_t n_rcu_torture_free;
88293 -static atomic_t n_rcu_torture_mberror;
88294 -static atomic_t n_rcu_torture_error;
88295 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88296 +static atomic_unchecked_t n_rcu_torture_alloc;
88297 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
88298 +static atomic_unchecked_t n_rcu_torture_free;
88299 +static atomic_unchecked_t n_rcu_torture_mberror;
88300 +static atomic_unchecked_t n_rcu_torture_error;
88301 static long n_rcu_torture_barrier_error;
88302 static long n_rcu_torture_boost_ktrerror;
88303 static long n_rcu_torture_boost_rterror;
88304 @@ -299,11 +299,11 @@ rcu_torture_alloc(void)
88305
88306 spin_lock_bh(&rcu_torture_lock);
88307 if (list_empty(&rcu_torture_freelist)) {
88308 - atomic_inc(&n_rcu_torture_alloc_fail);
88309 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88310 spin_unlock_bh(&rcu_torture_lock);
88311 return NULL;
88312 }
88313 - atomic_inc(&n_rcu_torture_alloc);
88314 + atomic_inc_unchecked(&n_rcu_torture_alloc);
88315 p = rcu_torture_freelist.next;
88316 list_del_init(p);
88317 spin_unlock_bh(&rcu_torture_lock);
88318 @@ -316,7 +316,7 @@ rcu_torture_alloc(void)
88319 static void
88320 rcu_torture_free(struct rcu_torture *p)
88321 {
88322 - atomic_inc(&n_rcu_torture_free);
88323 + atomic_inc_unchecked(&n_rcu_torture_free);
88324 spin_lock_bh(&rcu_torture_lock);
88325 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88326 spin_unlock_bh(&rcu_torture_lock);
88327 @@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
88328 i = rp->rtort_pipe_count;
88329 if (i > RCU_TORTURE_PIPE_LEN)
88330 i = RCU_TORTURE_PIPE_LEN;
88331 - atomic_inc(&rcu_torture_wcount[i]);
88332 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88333 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88334 rp->rtort_mbtest = 0;
88335 rcu_torture_free(rp);
88336 @@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
88337 i = old_rp->rtort_pipe_count;
88338 if (i > RCU_TORTURE_PIPE_LEN)
88339 i = RCU_TORTURE_PIPE_LEN;
88340 - atomic_inc(&rcu_torture_wcount[i]);
88341 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88342 old_rp->rtort_pipe_count++;
88343 if (gp_normal == gp_exp)
88344 exp = !!(rcu_random(&rand) & 0x80);
88345 @@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
88346 i = rp->rtort_pipe_count;
88347 if (i > RCU_TORTURE_PIPE_LEN)
88348 i = RCU_TORTURE_PIPE_LEN;
88349 - atomic_inc(&rcu_torture_wcount[i]);
88350 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88351 if (++rp->rtort_pipe_count >=
88352 RCU_TORTURE_PIPE_LEN) {
88353 rp->rtort_mbtest = 0;
88354 @@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
88355 return;
88356 }
88357 if (p->rtort_mbtest == 0)
88358 - atomic_inc(&n_rcu_torture_mberror);
88359 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88360 spin_lock(&rand_lock);
88361 cur_ops->read_delay(&rand);
88362 n_rcu_torture_timers++;
88363 @@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
88364 continue;
88365 }
88366 if (p->rtort_mbtest == 0)
88367 - atomic_inc(&n_rcu_torture_mberror);
88368 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88369 cur_ops->read_delay(&rand);
88370 preempt_disable();
88371 pipe_count = p->rtort_pipe_count;
88372 @@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
88373 rcu_torture_current,
88374 rcu_torture_current_version,
88375 list_empty(&rcu_torture_freelist),
88376 - atomic_read(&n_rcu_torture_alloc),
88377 - atomic_read(&n_rcu_torture_alloc_fail),
88378 - atomic_read(&n_rcu_torture_free));
88379 + atomic_read_unchecked(&n_rcu_torture_alloc),
88380 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88381 + atomic_read_unchecked(&n_rcu_torture_free));
88382 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
88383 - atomic_read(&n_rcu_torture_mberror),
88384 + atomic_read_unchecked(&n_rcu_torture_mberror),
88385 n_rcu_torture_boost_ktrerror,
88386 n_rcu_torture_boost_rterror);
88387 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
88388 @@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
88389 n_barrier_attempts,
88390 n_rcu_torture_barrier_error);
88391 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
88392 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88393 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88394 n_rcu_torture_barrier_error != 0 ||
88395 n_rcu_torture_boost_ktrerror != 0 ||
88396 n_rcu_torture_boost_rterror != 0 ||
88397 n_rcu_torture_boost_failure != 0 ||
88398 i > 1) {
88399 cnt += sprintf(&page[cnt], "!!! ");
88400 - atomic_inc(&n_rcu_torture_error);
88401 + atomic_inc_unchecked(&n_rcu_torture_error);
88402 WARN_ON_ONCE(1);
88403 }
88404 cnt += sprintf(&page[cnt], "Reader Pipe: ");
88405 @@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
88406 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
88407 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88408 cnt += sprintf(&page[cnt], " %d",
88409 - atomic_read(&rcu_torture_wcount[i]));
88410 + atomic_read_unchecked(&rcu_torture_wcount[i]));
88411 }
88412 cnt += sprintf(&page[cnt], "\n");
88413 if (cur_ops->stats)
88414 @@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
88415
88416 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88417
88418 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88419 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88420 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88421 else if (n_online_successes != n_online_attempts ||
88422 n_offline_successes != n_offline_attempts)
88423 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
88424
88425 rcu_torture_current = NULL;
88426 rcu_torture_current_version = 0;
88427 - atomic_set(&n_rcu_torture_alloc, 0);
88428 - atomic_set(&n_rcu_torture_alloc_fail, 0);
88429 - atomic_set(&n_rcu_torture_free, 0);
88430 - atomic_set(&n_rcu_torture_mberror, 0);
88431 - atomic_set(&n_rcu_torture_error, 0);
88432 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88433 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88434 + atomic_set_unchecked(&n_rcu_torture_free, 0);
88435 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88436 + atomic_set_unchecked(&n_rcu_torture_error, 0);
88437 n_rcu_torture_barrier_error = 0;
88438 n_rcu_torture_boost_ktrerror = 0;
88439 n_rcu_torture_boost_rterror = 0;
88440 n_rcu_torture_boost_failure = 0;
88441 n_rcu_torture_boosts = 0;
88442 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88443 - atomic_set(&rcu_torture_wcount[i], 0);
88444 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88445 for_each_possible_cpu(cpu) {
88446 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88447 per_cpu(rcu_torture_count, cpu)[i] = 0;
88448 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88449 index dd08198..5ccccbe 100644
88450 --- a/kernel/rcu/tree.c
88451 +++ b/kernel/rcu/tree.c
88452 @@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88453 rcu_prepare_for_idle(smp_processor_id());
88454 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88455 smp_mb__before_atomic_inc(); /* See above. */
88456 - atomic_inc(&rdtp->dynticks);
88457 + atomic_inc_unchecked(&rdtp->dynticks);
88458 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88459 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88460 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88461
88462 /*
88463 * It is illegal to enter an extended quiescent state while
88464 @@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88465 int user)
88466 {
88467 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88468 - atomic_inc(&rdtp->dynticks);
88469 + atomic_inc_unchecked(&rdtp->dynticks);
88470 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88471 smp_mb__after_atomic_inc(); /* See above. */
88472 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88473 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88474 rcu_cleanup_after_idle(smp_processor_id());
88475 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88476 if (!user && !is_idle_task(current)) {
88477 @@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
88478 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88479
88480 if (rdtp->dynticks_nmi_nesting == 0 &&
88481 - (atomic_read(&rdtp->dynticks) & 0x1))
88482 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88483 return;
88484 rdtp->dynticks_nmi_nesting++;
88485 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88486 - atomic_inc(&rdtp->dynticks);
88487 + atomic_inc_unchecked(&rdtp->dynticks);
88488 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88489 smp_mb__after_atomic_inc(); /* See above. */
88490 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88491 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88492 }
88493
88494 /**
88495 @@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
88496 return;
88497 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88498 smp_mb__before_atomic_inc(); /* See above. */
88499 - atomic_inc(&rdtp->dynticks);
88500 + atomic_inc_unchecked(&rdtp->dynticks);
88501 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88502 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88503 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88504 }
88505
88506 /**
88507 @@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
88508 */
88509 bool notrace __rcu_is_watching(void)
88510 {
88511 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88512 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88513 }
88514
88515 /**
88516 @@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88517 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88518 bool *isidle, unsigned long *maxj)
88519 {
88520 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88521 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88522 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88523 return (rdp->dynticks_snap & 0x1) == 0;
88524 }
88525 @@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88526 unsigned int curr;
88527 unsigned int snap;
88528
88529 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88530 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88531 snap = (unsigned int)rdp->dynticks_snap;
88532
88533 /*
88534 @@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88535 rdp = this_cpu_ptr(rsp->rda);
88536 rcu_preempt_check_blocked_tasks(rnp);
88537 rnp->qsmask = rnp->qsmaskinit;
88538 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88539 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88540 WARN_ON_ONCE(rnp->completed != rsp->completed);
88541 - ACCESS_ONCE(rnp->completed) = rsp->completed;
88542 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88543 if (rnp == rdp->mynode)
88544 __note_gp_changes(rsp, rnp, rdp);
88545 rcu_preempt_boost_start_gp(rnp);
88546 @@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88547 */
88548 rcu_for_each_node_breadth_first(rsp, rnp) {
88549 raw_spin_lock_irq(&rnp->lock);
88550 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88551 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88552 rdp = this_cpu_ptr(rsp->rda);
88553 if (rnp == rdp->mynode)
88554 __note_gp_changes(rsp, rnp, rdp);
88555 @@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88556 rsp->qlen += rdp->qlen;
88557 rdp->n_cbs_orphaned += rdp->qlen;
88558 rdp->qlen_lazy = 0;
88559 - ACCESS_ONCE(rdp->qlen) = 0;
88560 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88561 }
88562
88563 /*
88564 @@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88565 }
88566 smp_mb(); /* List handling before counting for rcu_barrier(). */
88567 rdp->qlen_lazy -= count_lazy;
88568 - ACCESS_ONCE(rdp->qlen) -= count;
88569 + ACCESS_ONCE_RW(rdp->qlen) -= count;
88570 rdp->n_cbs_invoked += count;
88571
88572 /* Reinstate batch limit if we have worked down the excess. */
88573 @@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88574 /*
88575 * Do RCU core processing for the current CPU.
88576 */
88577 -static void rcu_process_callbacks(struct softirq_action *unused)
88578 +static void rcu_process_callbacks(void)
88579 {
88580 struct rcu_state *rsp;
88581
88582 @@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88583 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88584 if (debug_rcu_head_queue(head)) {
88585 /* Probable double call_rcu(), so leak the callback. */
88586 - ACCESS_ONCE(head->func) = rcu_leak_callback;
88587 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88588 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88589 return;
88590 }
88591 @@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88592 local_irq_restore(flags);
88593 return;
88594 }
88595 - ACCESS_ONCE(rdp->qlen)++;
88596 + ACCESS_ONCE_RW(rdp->qlen)++;
88597 if (lazy)
88598 rdp->qlen_lazy++;
88599 else
88600 @@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
88601 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88602 * course be required on a 64-bit system.
88603 */
88604 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88605 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88606 (ulong)atomic_long_read(&rsp->expedited_done) +
88607 ULONG_MAX / 8)) {
88608 synchronize_sched();
88609 - atomic_long_inc(&rsp->expedited_wrap);
88610 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
88611 return;
88612 }
88613
88614 @@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
88615 * Take a ticket. Note that atomic_inc_return() implies a
88616 * full memory barrier.
88617 */
88618 - snap = atomic_long_inc_return(&rsp->expedited_start);
88619 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88620 firstsnap = snap;
88621 get_online_cpus();
88622 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88623 @@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
88624 synchronize_sched_expedited_cpu_stop,
88625 NULL) == -EAGAIN) {
88626 put_online_cpus();
88627 - atomic_long_inc(&rsp->expedited_tryfail);
88628 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88629
88630 /* Check to see if someone else did our work for us. */
88631 s = atomic_long_read(&rsp->expedited_done);
88632 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88633 /* ensure test happens before caller kfree */
88634 smp_mb__before_atomic_inc(); /* ^^^ */
88635 - atomic_long_inc(&rsp->expedited_workdone1);
88636 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88637 return;
88638 }
88639
88640 @@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
88641 udelay(trycount * num_online_cpus());
88642 } else {
88643 wait_rcu_gp(call_rcu_sched);
88644 - atomic_long_inc(&rsp->expedited_normal);
88645 + atomic_long_inc_unchecked(&rsp->expedited_normal);
88646 return;
88647 }
88648
88649 @@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
88650 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88651 /* ensure test happens before caller kfree */
88652 smp_mb__before_atomic_inc(); /* ^^^ */
88653 - atomic_long_inc(&rsp->expedited_workdone2);
88654 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88655 return;
88656 }
88657
88658 @@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
88659 * period works for us.
88660 */
88661 get_online_cpus();
88662 - snap = atomic_long_read(&rsp->expedited_start);
88663 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
88664 smp_mb(); /* ensure read is before try_stop_cpus(). */
88665 }
88666 - atomic_long_inc(&rsp->expedited_stoppedcpus);
88667 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88668
88669 /*
88670 * Everyone up to our most recent fetch is covered by our grace
88671 @@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
88672 * than we did already did their update.
88673 */
88674 do {
88675 - atomic_long_inc(&rsp->expedited_done_tries);
88676 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88677 s = atomic_long_read(&rsp->expedited_done);
88678 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88679 /* ensure test happens before caller kfree */
88680 smp_mb__before_atomic_inc(); /* ^^^ */
88681 - atomic_long_inc(&rsp->expedited_done_lost);
88682 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88683 break;
88684 }
88685 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88686 - atomic_long_inc(&rsp->expedited_done_exit);
88687 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88688
88689 put_online_cpus();
88690 }
88691 @@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88692 * ACCESS_ONCE() to prevent the compiler from speculating
88693 * the increment to precede the early-exit check.
88694 */
88695 - ACCESS_ONCE(rsp->n_barrier_done)++;
88696 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88697 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88698 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88699 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88700 @@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88701
88702 /* Increment ->n_barrier_done to prevent duplicate work. */
88703 smp_mb(); /* Keep increment after above mechanism. */
88704 - ACCESS_ONCE(rsp->n_barrier_done)++;
88705 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88706 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88707 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88708 smp_mb(); /* Keep increment before caller's subsequent code. */
88709 @@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88710 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88711 init_callback_list(rdp);
88712 rdp->qlen_lazy = 0;
88713 - ACCESS_ONCE(rdp->qlen) = 0;
88714 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88715 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88716 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88717 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88718 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88719 rdp->cpu = cpu;
88720 rdp->rsp = rsp;
88721 rcu_boot_init_nocb_percpu_data(rdp);
88722 @@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88723 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88724 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88725 rcu_sysidle_init_percpu_data(rdp->dynticks);
88726 - atomic_set(&rdp->dynticks->dynticks,
88727 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88728 + atomic_set_unchecked(&rdp->dynticks->dynticks,
88729 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88730 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88731
88732 /* Add CPU to rcu_node bitmasks. */
88733 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88734 index 52be957..365ded3 100644
88735 --- a/kernel/rcu/tree.h
88736 +++ b/kernel/rcu/tree.h
88737 @@ -87,11 +87,11 @@ struct rcu_dynticks {
88738 long long dynticks_nesting; /* Track irq/process nesting level. */
88739 /* Process level is worth LLONG_MAX/2. */
88740 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88741 - atomic_t dynticks; /* Even value for idle, else odd. */
88742 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88743 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88744 long long dynticks_idle_nesting;
88745 /* irq/process nesting level from idle. */
88746 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
88747 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88748 /* "Idle" excludes userspace execution. */
88749 unsigned long dynticks_idle_jiffies;
88750 /* End of last non-NMI non-idle period. */
88751 @@ -429,17 +429,17 @@ struct rcu_state {
88752 /* _rcu_barrier(). */
88753 /* End of fields guarded by barrier_mutex. */
88754
88755 - atomic_long_t expedited_start; /* Starting ticket. */
88756 - atomic_long_t expedited_done; /* Done ticket. */
88757 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88758 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
88759 - atomic_long_t expedited_workdone1; /* # done by others #1. */
88760 - atomic_long_t expedited_workdone2; /* # done by others #2. */
88761 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
88762 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88763 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
88764 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88765 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88766 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88767 + atomic_long_t expedited_done; /* Done ticket. */
88768 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88769 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88770 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88771 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88772 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88773 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88774 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88775 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88776 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88777
88778 unsigned long jiffies_force_qs; /* Time at which to invoke */
88779 /* force_quiescent_state(). */
88780 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88781 index 08a7652..3598c7e 100644
88782 --- a/kernel/rcu/tree_plugin.h
88783 +++ b/kernel/rcu/tree_plugin.h
88784 @@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88785 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88786 {
88787 return !rcu_preempted_readers_exp(rnp) &&
88788 - ACCESS_ONCE(rnp->expmask) == 0;
88789 + ACCESS_ONCE_RW(rnp->expmask) == 0;
88790 }
88791
88792 /*
88793 @@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
88794
88795 /* Clean up and exit. */
88796 smp_mb(); /* ensure expedited GP seen before counter increment. */
88797 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88798 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88799 unlock_mb_ret:
88800 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88801 mb_ret:
88802 @@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88803 free_cpumask_var(cm);
88804 }
88805
88806 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88807 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88808 .store = &rcu_cpu_kthread_task,
88809 .thread_should_run = rcu_cpu_kthread_should_run,
88810 .thread_fn = rcu_cpu_kthread,
88811 @@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88812 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88813 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88814 cpu, ticks_value, ticks_title,
88815 - atomic_read(&rdtp->dynticks) & 0xfff,
88816 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88817 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88818 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88819 fast_no_hz);
88820 @@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88821
88822 /* Enqueue the callback on the nocb list and update counts. */
88823 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88824 - ACCESS_ONCE(*old_rhpp) = rhp;
88825 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
88826 atomic_long_add(rhcount, &rdp->nocb_q_count);
88827 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88828
88829 @@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
88830 * Extract queued callbacks, update counts, and wait
88831 * for a grace period to elapse.
88832 */
88833 - ACCESS_ONCE(rdp->nocb_head) = NULL;
88834 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88835 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88836 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88837 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88838 - ACCESS_ONCE(rdp->nocb_p_count) += c;
88839 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88840 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88841 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88842 rcu_nocb_wait_gp(rdp);
88843
88844 /* Each pass through the following loop invokes a callback. */
88845 @@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
88846 list = next;
88847 }
88848 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88849 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
88850 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88851 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88852 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88853 rdp->n_nocbs_invoked += c;
88854 }
88855 return 0;
88856 @@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
88857 t = kthread_run(rcu_nocb_kthread, rdp,
88858 "rcuo%c/%d", rsp->abbr, cpu);
88859 BUG_ON(IS_ERR(t));
88860 - ACCESS_ONCE(rdp->nocb_kthread) = t;
88861 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
88862 }
88863 }
88864
88865 @@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
88866
88867 /* Record start of fully idle period. */
88868 j = jiffies;
88869 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
88870 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
88871 smp_mb__before_atomic_inc();
88872 - atomic_inc(&rdtp->dynticks_idle);
88873 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88874 smp_mb__after_atomic_inc();
88875 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
88876 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
88877 }
88878
88879 /*
88880 @@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
88881
88882 /* Record end of idle period. */
88883 smp_mb__before_atomic_inc();
88884 - atomic_inc(&rdtp->dynticks_idle);
88885 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88886 smp_mb__after_atomic_inc();
88887 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
88888 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
88889
88890 /*
88891 * If we are the timekeeping CPU, we are permitted to be non-idle
88892 @@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
88893 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
88894
88895 /* Pick up current idle and NMI-nesting counter and check. */
88896 - cur = atomic_read(&rdtp->dynticks_idle);
88897 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
88898 if (cur & 0x1) {
88899 *isidle = false; /* We are not idle! */
88900 return;
88901 @@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
88902 case RCU_SYSIDLE_NOT:
88903
88904 /* First time all are idle, so note a short idle period. */
88905 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88906 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88907 break;
88908
88909 case RCU_SYSIDLE_SHORT:
88910 @@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
88911 static void rcu_sysidle_cancel(void)
88912 {
88913 smp_mb();
88914 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
88915 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
88916 }
88917
88918 /*
88919 @@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
88920 smp_mb(); /* grace period precedes setting inuse. */
88921
88922 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
88923 - ACCESS_ONCE(rshp->inuse) = 0;
88924 + ACCESS_ONCE_RW(rshp->inuse) = 0;
88925 }
88926
88927 /*
88928 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
88929 index 3596797..f78391c 100644
88930 --- a/kernel/rcu/tree_trace.c
88931 +++ b/kernel/rcu/tree_trace.c
88932 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
88933 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
88934 rdp->passed_quiesce, rdp->qs_pending);
88935 seq_printf(m, " dt=%d/%llx/%d df=%lu",
88936 - atomic_read(&rdp->dynticks->dynticks),
88937 + atomic_read_unchecked(&rdp->dynticks->dynticks),
88938 rdp->dynticks->dynticks_nesting,
88939 rdp->dynticks->dynticks_nmi_nesting,
88940 rdp->dynticks_fqs);
88941 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
88942 struct rcu_state *rsp = (struct rcu_state *)m->private;
88943
88944 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",
88945 - atomic_long_read(&rsp->expedited_start),
88946 + atomic_long_read_unchecked(&rsp->expedited_start),
88947 atomic_long_read(&rsp->expedited_done),
88948 - atomic_long_read(&rsp->expedited_wrap),
88949 - atomic_long_read(&rsp->expedited_tryfail),
88950 - atomic_long_read(&rsp->expedited_workdone1),
88951 - atomic_long_read(&rsp->expedited_workdone2),
88952 - atomic_long_read(&rsp->expedited_normal),
88953 - atomic_long_read(&rsp->expedited_stoppedcpus),
88954 - atomic_long_read(&rsp->expedited_done_tries),
88955 - atomic_long_read(&rsp->expedited_done_lost),
88956 - atomic_long_read(&rsp->expedited_done_exit));
88957 + atomic_long_read_unchecked(&rsp->expedited_wrap),
88958 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
88959 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
88960 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
88961 + atomic_long_read_unchecked(&rsp->expedited_normal),
88962 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
88963 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
88964 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
88965 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
88966 return 0;
88967 }
88968
88969 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
88970 index 6cb3dff..dc5710f 100644
88971 --- a/kernel/rcu/update.c
88972 +++ b/kernel/rcu/update.c
88973 @@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
88974 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
88975 */
88976 if (till_stall_check < 3) {
88977 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
88978 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
88979 till_stall_check = 3;
88980 } else if (till_stall_check > 300) {
88981 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
88982 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
88983 till_stall_check = 300;
88984 }
88985 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
88986 diff --git a/kernel/resource.c b/kernel/resource.c
88987 index 3f285dc..5755f62 100644
88988 --- a/kernel/resource.c
88989 +++ b/kernel/resource.c
88990 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
88991
88992 static int __init ioresources_init(void)
88993 {
88994 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88995 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88996 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
88997 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
88998 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88999 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89000 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89001 +#endif
89002 +#else
89003 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89004 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89005 +#endif
89006 return 0;
89007 }
89008 __initcall(ioresources_init);
89009 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89010 index 4a07353..66b5291 100644
89011 --- a/kernel/sched/auto_group.c
89012 +++ b/kernel/sched/auto_group.c
89013 @@ -11,7 +11,7 @@
89014
89015 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89016 static struct autogroup autogroup_default;
89017 -static atomic_t autogroup_seq_nr;
89018 +static atomic_unchecked_t autogroup_seq_nr;
89019
89020 void __init autogroup_init(struct task_struct *init_task)
89021 {
89022 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89023
89024 kref_init(&ag->kref);
89025 init_rwsem(&ag->lock);
89026 - ag->id = atomic_inc_return(&autogroup_seq_nr);
89027 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89028 ag->tg = tg;
89029 #ifdef CONFIG_RT_GROUP_SCHED
89030 /*
89031 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89032 index a63f4dc..349bbb0 100644
89033 --- a/kernel/sched/completion.c
89034 +++ b/kernel/sched/completion.c
89035 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89036 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89037 * or number of jiffies left till timeout) if completed.
89038 */
89039 -long __sched
89040 +long __sched __intentional_overflow(-1)
89041 wait_for_completion_interruptible_timeout(struct completion *x,
89042 unsigned long timeout)
89043 {
89044 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89045 *
89046 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89047 */
89048 -int __sched wait_for_completion_killable(struct completion *x)
89049 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89050 {
89051 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89052 if (t == -ERESTARTSYS)
89053 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89054 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89055 * or number of jiffies left till timeout) if completed.
89056 */
89057 -long __sched
89058 +long __sched __intentional_overflow(-1)
89059 wait_for_completion_killable_timeout(struct completion *x,
89060 unsigned long timeout)
89061 {
89062 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89063 index c677510..132bb14 100644
89064 --- a/kernel/sched/core.c
89065 +++ b/kernel/sched/core.c
89066 @@ -1768,7 +1768,7 @@ void set_numabalancing_state(bool enabled)
89067 int sysctl_numa_balancing(struct ctl_table *table, int write,
89068 void __user *buffer, size_t *lenp, loff_t *ppos)
89069 {
89070 - struct ctl_table t;
89071 + ctl_table_no_const t;
89072 int err;
89073 int state = numabalancing_enabled;
89074
89075 @@ -2893,6 +2893,8 @@ int can_nice(const struct task_struct *p, const int nice)
89076 /* convert nice value [19,-20] to rlimit style value [1,40] */
89077 int nice_rlim = 20 - nice;
89078
89079 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89080 +
89081 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89082 capable(CAP_SYS_NICE));
89083 }
89084 @@ -2926,7 +2928,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89085 if (nice > 19)
89086 nice = 19;
89087
89088 - if (increment < 0 && !can_nice(current, nice))
89089 + if (increment < 0 && (!can_nice(current, nice) ||
89090 + gr_handle_chroot_nice()))
89091 return -EPERM;
89092
89093 retval = security_task_setnice(current, nice);
89094 @@ -3088,6 +3091,7 @@ recheck:
89095 unsigned long rlim_rtprio =
89096 task_rlimit(p, RLIMIT_RTPRIO);
89097
89098 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
89099 /* can't set/change the rt policy */
89100 if (policy != p->policy && !rlim_rtprio)
89101 return -EPERM;
89102 @@ -4254,7 +4258,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89103
89104 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89105
89106 -static struct ctl_table sd_ctl_dir[] = {
89107 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
89108 {
89109 .procname = "sched_domain",
89110 .mode = 0555,
89111 @@ -4271,17 +4275,17 @@ static struct ctl_table sd_ctl_root[] = {
89112 {}
89113 };
89114
89115 -static struct ctl_table *sd_alloc_ctl_entry(int n)
89116 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89117 {
89118 - struct ctl_table *entry =
89119 + ctl_table_no_const *entry =
89120 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89121
89122 return entry;
89123 }
89124
89125 -static void sd_free_ctl_entry(struct ctl_table **tablep)
89126 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89127 {
89128 - struct ctl_table *entry;
89129 + ctl_table_no_const *entry;
89130
89131 /*
89132 * In the intermediate directories, both the child directory and
89133 @@ -4289,22 +4293,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89134 * will always be set. In the lowest directory the names are
89135 * static strings and all have proc handlers.
89136 */
89137 - for (entry = *tablep; entry->mode; entry++) {
89138 - if (entry->child)
89139 - sd_free_ctl_entry(&entry->child);
89140 + for (entry = tablep; entry->mode; entry++) {
89141 + if (entry->child) {
89142 + sd_free_ctl_entry(entry->child);
89143 + pax_open_kernel();
89144 + entry->child = NULL;
89145 + pax_close_kernel();
89146 + }
89147 if (entry->proc_handler == NULL)
89148 kfree(entry->procname);
89149 }
89150
89151 - kfree(*tablep);
89152 - *tablep = NULL;
89153 + kfree(tablep);
89154 }
89155
89156 static int min_load_idx = 0;
89157 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89158
89159 static void
89160 -set_table_entry(struct ctl_table *entry,
89161 +set_table_entry(ctl_table_no_const *entry,
89162 const char *procname, void *data, int maxlen,
89163 umode_t mode, proc_handler *proc_handler,
89164 bool load_idx)
89165 @@ -4324,7 +4331,7 @@ set_table_entry(struct ctl_table *entry,
89166 static struct ctl_table *
89167 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89168 {
89169 - struct ctl_table *table = sd_alloc_ctl_entry(13);
89170 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89171
89172 if (table == NULL)
89173 return NULL;
89174 @@ -4359,9 +4366,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89175 return table;
89176 }
89177
89178 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89179 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89180 {
89181 - struct ctl_table *entry, *table;
89182 + ctl_table_no_const *entry, *table;
89183 struct sched_domain *sd;
89184 int domain_num = 0, i;
89185 char buf[32];
89186 @@ -4388,11 +4395,13 @@ static struct ctl_table_header *sd_sysctl_header;
89187 static void register_sched_domain_sysctl(void)
89188 {
89189 int i, cpu_num = num_possible_cpus();
89190 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89191 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89192 char buf[32];
89193
89194 WARN_ON(sd_ctl_dir[0].child);
89195 + pax_open_kernel();
89196 sd_ctl_dir[0].child = entry;
89197 + pax_close_kernel();
89198
89199 if (entry == NULL)
89200 return;
89201 @@ -4415,8 +4424,12 @@ static void unregister_sched_domain_sysctl(void)
89202 if (sd_sysctl_header)
89203 unregister_sysctl_table(sd_sysctl_header);
89204 sd_sysctl_header = NULL;
89205 - if (sd_ctl_dir[0].child)
89206 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
89207 + if (sd_ctl_dir[0].child) {
89208 + sd_free_ctl_entry(sd_ctl_dir[0].child);
89209 + pax_open_kernel();
89210 + sd_ctl_dir[0].child = NULL;
89211 + pax_close_kernel();
89212 + }
89213 }
89214 #else
89215 static void register_sched_domain_sysctl(void)
89216 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89217 index ce501de..1805320 100644
89218 --- a/kernel/sched/fair.c
89219 +++ b/kernel/sched/fair.c
89220 @@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89221
89222 static void reset_ptenuma_scan(struct task_struct *p)
89223 {
89224 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
89225 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89226 p->mm->numa_scan_offset = 0;
89227 }
89228
89229 @@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
89230 * run_rebalance_domains is triggered when needed from the scheduler tick.
89231 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89232 */
89233 -static void run_rebalance_domains(struct softirq_action *h)
89234 +static __latent_entropy void run_rebalance_domains(void)
89235 {
89236 int this_cpu = smp_processor_id();
89237 struct rq *this_rq = cpu_rq(this_cpu);
89238 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89239 index 88c85b2..a1dec86 100644
89240 --- a/kernel/sched/sched.h
89241 +++ b/kernel/sched/sched.h
89242 @@ -1035,7 +1035,7 @@ struct sched_class {
89243 #ifdef CONFIG_FAIR_GROUP_SCHED
89244 void (*task_move_group) (struct task_struct *p, int on_rq);
89245 #endif
89246 -};
89247 +} __do_const;
89248
89249 #define sched_class_highest (&stop_sched_class)
89250 #define for_each_class(class) \
89251 diff --git a/kernel/signal.c b/kernel/signal.c
89252 index 940b30e..7fd6041 100644
89253 --- a/kernel/signal.c
89254 +++ b/kernel/signal.c
89255 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89256
89257 int print_fatal_signals __read_mostly;
89258
89259 -static void __user *sig_handler(struct task_struct *t, int sig)
89260 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
89261 {
89262 return t->sighand->action[sig - 1].sa.sa_handler;
89263 }
89264
89265 -static int sig_handler_ignored(void __user *handler, int sig)
89266 +static int sig_handler_ignored(__sighandler_t handler, int sig)
89267 {
89268 /* Is it explicitly or implicitly ignored? */
89269 return handler == SIG_IGN ||
89270 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89271
89272 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89273 {
89274 - void __user *handler;
89275 + __sighandler_t handler;
89276
89277 handler = sig_handler(t, sig);
89278
89279 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89280 atomic_inc(&user->sigpending);
89281 rcu_read_unlock();
89282
89283 + if (!override_rlimit)
89284 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89285 +
89286 if (override_rlimit ||
89287 atomic_read(&user->sigpending) <=
89288 task_rlimit(t, RLIMIT_SIGPENDING)) {
89289 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89290
89291 int unhandled_signal(struct task_struct *tsk, int sig)
89292 {
89293 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89294 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89295 if (is_global_init(tsk))
89296 return 1;
89297 if (handler != SIG_IGN && handler != SIG_DFL)
89298 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89299 }
89300 }
89301
89302 + /* allow glibc communication via tgkill to other threads in our
89303 + thread group */
89304 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89305 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89306 + && gr_handle_signal(t, sig))
89307 + return -EPERM;
89308 +
89309 return security_task_kill(t, info, sig, 0);
89310 }
89311
89312 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89313 return send_signal(sig, info, p, 1);
89314 }
89315
89316 -static int
89317 +int
89318 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89319 {
89320 return send_signal(sig, info, t, 0);
89321 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89322 unsigned long int flags;
89323 int ret, blocked, ignored;
89324 struct k_sigaction *action;
89325 + int is_unhandled = 0;
89326
89327 spin_lock_irqsave(&t->sighand->siglock, flags);
89328 action = &t->sighand->action[sig-1];
89329 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89330 }
89331 if (action->sa.sa_handler == SIG_DFL)
89332 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89333 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89334 + is_unhandled = 1;
89335 ret = specific_send_sig_info(sig, info, t);
89336 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89337
89338 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
89339 + normal operation */
89340 + if (is_unhandled) {
89341 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89342 + gr_handle_crash(t, sig);
89343 + }
89344 +
89345 return ret;
89346 }
89347
89348 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89349 ret = check_kill_permission(sig, info, p);
89350 rcu_read_unlock();
89351
89352 - if (!ret && sig)
89353 + if (!ret && sig) {
89354 ret = do_send_sig_info(sig, info, p, true);
89355 + if (!ret)
89356 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89357 + }
89358
89359 return ret;
89360 }
89361 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89362 int error = -ESRCH;
89363
89364 rcu_read_lock();
89365 - p = find_task_by_vpid(pid);
89366 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89367 + /* allow glibc communication via tgkill to other threads in our
89368 + thread group */
89369 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89370 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
89371 + p = find_task_by_vpid_unrestricted(pid);
89372 + else
89373 +#endif
89374 + p = find_task_by_vpid(pid);
89375 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89376 error = check_kill_permission(sig, info, p);
89377 /*
89378 @@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89379 }
89380 seg = get_fs();
89381 set_fs(KERNEL_DS);
89382 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89383 - (stack_t __force __user *) &uoss,
89384 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89385 + (stack_t __force_user *) &uoss,
89386 compat_user_stack_pointer());
89387 set_fs(seg);
89388 if (ret >= 0 && uoss_ptr) {
89389 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89390 index eb89e18..a4e6792 100644
89391 --- a/kernel/smpboot.c
89392 +++ b/kernel/smpboot.c
89393 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89394 }
89395 smpboot_unpark_thread(plug_thread, cpu);
89396 }
89397 - list_add(&plug_thread->list, &hotplug_threads);
89398 + pax_list_add(&plug_thread->list, &hotplug_threads);
89399 out:
89400 mutex_unlock(&smpboot_threads_lock);
89401 return ret;
89402 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89403 {
89404 get_online_cpus();
89405 mutex_lock(&smpboot_threads_lock);
89406 - list_del(&plug_thread->list);
89407 + pax_list_del(&plug_thread->list);
89408 smpboot_destroy_threads(plug_thread);
89409 mutex_unlock(&smpboot_threads_lock);
89410 put_online_cpus();
89411 diff --git a/kernel/softirq.c b/kernel/softirq.c
89412 index 11025cc..bc0e4dc 100644
89413 --- a/kernel/softirq.c
89414 +++ b/kernel/softirq.c
89415 @@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89416 EXPORT_SYMBOL(irq_stat);
89417 #endif
89418
89419 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89420 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89421
89422 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89423
89424 -char *softirq_to_name[NR_SOFTIRQS] = {
89425 +const char * const softirq_to_name[NR_SOFTIRQS] = {
89426 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
89427 "TASKLET", "SCHED", "HRTIMER", "RCU"
89428 };
89429 @@ -250,7 +250,7 @@ restart:
89430 kstat_incr_softirqs_this_cpu(vec_nr);
89431
89432 trace_softirq_entry(vec_nr);
89433 - h->action(h);
89434 + h->action();
89435 trace_softirq_exit(vec_nr);
89436 if (unlikely(prev_count != preempt_count())) {
89437 printk(KERN_ERR "huh, entered softirq %u %s %p"
89438 @@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89439 or_softirq_pending(1UL << nr);
89440 }
89441
89442 -void open_softirq(int nr, void (*action)(struct softirq_action *))
89443 +void __init open_softirq(int nr, void (*action)(void))
89444 {
89445 softirq_vec[nr].action = action;
89446 }
89447 @@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89448
89449 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89450
89451 -static void tasklet_action(struct softirq_action *a)
89452 +static __latent_entropy void tasklet_action(void)
89453 {
89454 struct tasklet_struct *list;
89455
89456 @@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
89457 }
89458 }
89459
89460 -static void tasklet_hi_action(struct softirq_action *a)
89461 +static __latent_entropy void tasklet_hi_action(void)
89462 {
89463 struct tasklet_struct *list;
89464
89465 @@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
89466 .notifier_call = cpu_callback
89467 };
89468
89469 -static struct smp_hotplug_thread softirq_threads = {
89470 +static struct smp_hotplug_thread softirq_threads __read_only = {
89471 .store = &ksoftirqd,
89472 .thread_should_run = ksoftirqd_should_run,
89473 .thread_fn = run_ksoftirqd,
89474 diff --git a/kernel/sys.c b/kernel/sys.c
89475 index c723113..46bf922 100644
89476 --- a/kernel/sys.c
89477 +++ b/kernel/sys.c
89478 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89479 error = -EACCES;
89480 goto out;
89481 }
89482 +
89483 + if (gr_handle_chroot_setpriority(p, niceval)) {
89484 + error = -EACCES;
89485 + goto out;
89486 + }
89487 +
89488 no_nice = security_task_setnice(p, niceval);
89489 if (no_nice) {
89490 error = no_nice;
89491 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89492 goto error;
89493 }
89494
89495 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89496 + goto error;
89497 +
89498 if (rgid != (gid_t) -1 ||
89499 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89500 new->sgid = new->egid;
89501 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89502 old = current_cred();
89503
89504 retval = -EPERM;
89505 +
89506 + if (gr_check_group_change(kgid, kgid, kgid))
89507 + goto error;
89508 +
89509 if (ns_capable(old->user_ns, CAP_SETGID))
89510 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89511 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89512 @@ -403,7 +416,7 @@ error:
89513 /*
89514 * change the user struct in a credentials set to match the new UID
89515 */
89516 -static int set_user(struct cred *new)
89517 +int set_user(struct cred *new)
89518 {
89519 struct user_struct *new_user;
89520
89521 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89522 goto error;
89523 }
89524
89525 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89526 + goto error;
89527 +
89528 if (!uid_eq(new->uid, old->uid)) {
89529 retval = set_user(new);
89530 if (retval < 0)
89531 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89532 old = current_cred();
89533
89534 retval = -EPERM;
89535 +
89536 + if (gr_check_crash_uid(kuid))
89537 + goto error;
89538 + if (gr_check_user_change(kuid, kuid, kuid))
89539 + goto error;
89540 +
89541 if (ns_capable(old->user_ns, CAP_SETUID)) {
89542 new->suid = new->uid = kuid;
89543 if (!uid_eq(kuid, old->uid)) {
89544 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89545 goto error;
89546 }
89547
89548 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
89549 + goto error;
89550 +
89551 if (ruid != (uid_t) -1) {
89552 new->uid = kruid;
89553 if (!uid_eq(kruid, old->uid)) {
89554 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89555 goto error;
89556 }
89557
89558 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
89559 + goto error;
89560 +
89561 if (rgid != (gid_t) -1)
89562 new->gid = krgid;
89563 if (egid != (gid_t) -1)
89564 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89565 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89566 ns_capable(old->user_ns, CAP_SETUID)) {
89567 if (!uid_eq(kuid, old->fsuid)) {
89568 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89569 + goto error;
89570 +
89571 new->fsuid = kuid;
89572 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89573 goto change_okay;
89574 }
89575 }
89576
89577 +error:
89578 abort_creds(new);
89579 return old_fsuid;
89580
89581 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89582 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89583 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89584 ns_capable(old->user_ns, CAP_SETGID)) {
89585 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89586 + goto error;
89587 +
89588 if (!gid_eq(kgid, old->fsgid)) {
89589 new->fsgid = kgid;
89590 goto change_okay;
89591 }
89592 }
89593
89594 +error:
89595 abort_creds(new);
89596 return old_fsgid;
89597
89598 @@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89599 return -EFAULT;
89600
89601 down_read(&uts_sem);
89602 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
89603 + error = __copy_to_user(name->sysname, &utsname()->sysname,
89604 __OLD_UTS_LEN);
89605 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89606 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89607 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
89608 __OLD_UTS_LEN);
89609 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89610 - error |= __copy_to_user(&name->release, &utsname()->release,
89611 + error |= __copy_to_user(name->release, &utsname()->release,
89612 __OLD_UTS_LEN);
89613 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89614 - error |= __copy_to_user(&name->version, &utsname()->version,
89615 + error |= __copy_to_user(name->version, &utsname()->version,
89616 __OLD_UTS_LEN);
89617 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89618 - error |= __copy_to_user(&name->machine, &utsname()->machine,
89619 + error |= __copy_to_user(name->machine, &utsname()->machine,
89620 __OLD_UTS_LEN);
89621 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89622 up_read(&uts_sem);
89623 @@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89624 */
89625 new_rlim->rlim_cur = 1;
89626 }
89627 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89628 + is changed to a lower value. Since tasks can be created by the same
89629 + user in between this limit change and an execve by this task, force
89630 + a recheck only for this task by setting PF_NPROC_EXCEEDED
89631 + */
89632 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89633 + tsk->flags |= PF_NPROC_EXCEEDED;
89634 }
89635 if (!retval) {
89636 if (old_rlim)
89637 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89638 index 06962ba..a54d45e 100644
89639 --- a/kernel/sysctl.c
89640 +++ b/kernel/sysctl.c
89641 @@ -93,7 +93,6 @@
89642
89643
89644 #if defined(CONFIG_SYSCTL)
89645 -
89646 /* External variables not in a header file. */
89647 extern int sysctl_overcommit_memory;
89648 extern int sysctl_overcommit_ratio;
89649 @@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
89650
89651 /* Constants used for minimum and maximum */
89652 #ifdef CONFIG_LOCKUP_DETECTOR
89653 -static int sixty = 60;
89654 +static int sixty __read_only = 60;
89655 #endif
89656
89657 -static int zero;
89658 -static int __maybe_unused one = 1;
89659 -static int __maybe_unused two = 2;
89660 -static int __maybe_unused three = 3;
89661 -static unsigned long one_ul = 1;
89662 -static int one_hundred = 100;
89663 +static int neg_one __read_only = -1;
89664 +static int zero __read_only = 0;
89665 +static int __maybe_unused one __read_only = 1;
89666 +static int __maybe_unused two __read_only = 2;
89667 +static int __maybe_unused three __read_only = 3;
89668 +static unsigned long one_ul __read_only = 1;
89669 +static int one_hundred __read_only = 100;
89670 #ifdef CONFIG_PRINTK
89671 -static int ten_thousand = 10000;
89672 +static int ten_thousand __read_only = 10000;
89673 #endif
89674
89675 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89676 @@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
89677 void __user *buffer, size_t *lenp, loff_t *ppos);
89678 #endif
89679
89680 -#ifdef CONFIG_PRINTK
89681 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89682 void __user *buffer, size_t *lenp, loff_t *ppos);
89683 -#endif
89684
89685 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89686 void __user *buffer, size_t *lenp, loff_t *ppos);
89687 @@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89688
89689 #endif
89690
89691 +extern struct ctl_table grsecurity_table[];
89692 +
89693 static struct ctl_table kern_table[];
89694 static struct ctl_table vm_table[];
89695 static struct ctl_table fs_table[];
89696 @@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
89697 int sysctl_legacy_va_layout;
89698 #endif
89699
89700 +#ifdef CONFIG_PAX_SOFTMODE
89701 +static ctl_table pax_table[] = {
89702 + {
89703 + .procname = "softmode",
89704 + .data = &pax_softmode,
89705 + .maxlen = sizeof(unsigned int),
89706 + .mode = 0600,
89707 + .proc_handler = &proc_dointvec,
89708 + },
89709 +
89710 + { }
89711 +};
89712 +#endif
89713 +
89714 /* The default sysctl tables: */
89715
89716 static struct ctl_table sysctl_base_table[] = {
89717 @@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
89718 #endif
89719
89720 static struct ctl_table kern_table[] = {
89721 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89722 + {
89723 + .procname = "grsecurity",
89724 + .mode = 0500,
89725 + .child = grsecurity_table,
89726 + },
89727 +#endif
89728 +
89729 +#ifdef CONFIG_PAX_SOFTMODE
89730 + {
89731 + .procname = "pax",
89732 + .mode = 0500,
89733 + .child = pax_table,
89734 + },
89735 +#endif
89736 +
89737 {
89738 .procname = "sched_child_runs_first",
89739 .data = &sysctl_sched_child_runs_first,
89740 @@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
89741 .data = &modprobe_path,
89742 .maxlen = KMOD_PATH_LEN,
89743 .mode = 0644,
89744 - .proc_handler = proc_dostring,
89745 + .proc_handler = proc_dostring_modpriv,
89746 },
89747 {
89748 .procname = "modules_disabled",
89749 @@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
89750 .extra1 = &zero,
89751 .extra2 = &one,
89752 },
89753 +#endif
89754 {
89755 .procname = "kptr_restrict",
89756 .data = &kptr_restrict,
89757 .maxlen = sizeof(int),
89758 .mode = 0644,
89759 .proc_handler = proc_dointvec_minmax_sysadmin,
89760 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89761 + .extra1 = &two,
89762 +#else
89763 .extra1 = &zero,
89764 +#endif
89765 .extra2 = &two,
89766 },
89767 -#endif
89768 {
89769 .procname = "ngroups_max",
89770 .data = &ngroups_max,
89771 @@ -1048,10 +1082,17 @@ static struct ctl_table kern_table[] = {
89772 */
89773 {
89774 .procname = "perf_event_paranoid",
89775 - .data = &sysctl_perf_event_paranoid,
89776 - .maxlen = sizeof(sysctl_perf_event_paranoid),
89777 + .data = &sysctl_perf_event_legitimately_concerned,
89778 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89779 .mode = 0644,
89780 - .proc_handler = proc_dointvec,
89781 + /* go ahead, be a hero */
89782 + .proc_handler = proc_dointvec_minmax_sysadmin,
89783 + .extra1 = &neg_one,
89784 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89785 + .extra2 = &three,
89786 +#else
89787 + .extra2 = &two,
89788 +#endif
89789 },
89790 {
89791 .procname = "perf_event_mlock_kb",
89792 @@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
89793 .proc_handler = proc_dointvec_minmax,
89794 .extra1 = &zero,
89795 },
89796 + {
89797 + .procname = "heap_stack_gap",
89798 + .data = &sysctl_heap_stack_gap,
89799 + .maxlen = sizeof(sysctl_heap_stack_gap),
89800 + .mode = 0644,
89801 + .proc_handler = proc_doulongvec_minmax,
89802 + },
89803 #else
89804 {
89805 .procname = "nr_trim_pages",
89806 @@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
89807 buffer, lenp, ppos);
89808 }
89809
89810 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89811 + void __user *buffer, size_t *lenp, loff_t *ppos)
89812 +{
89813 + if (write && !capable(CAP_SYS_MODULE))
89814 + return -EPERM;
89815 +
89816 + return _proc_do_string(table->data, table->maxlen, write,
89817 + buffer, lenp, ppos);
89818 +}
89819 +
89820 static size_t proc_skip_spaces(char **buf)
89821 {
89822 size_t ret;
89823 @@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89824 len = strlen(tmp);
89825 if (len > *size)
89826 len = *size;
89827 + if (len > sizeof(tmp))
89828 + len = sizeof(tmp);
89829 if (copy_to_user(*buf, tmp, len))
89830 return -EFAULT;
89831 *size -= len;
89832 @@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89833 static int proc_taint(struct ctl_table *table, int write,
89834 void __user *buffer, size_t *lenp, loff_t *ppos)
89835 {
89836 - struct ctl_table t;
89837 + ctl_table_no_const t;
89838 unsigned long tmptaint = get_taint();
89839 int err;
89840
89841 @@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
89842 return err;
89843 }
89844
89845 -#ifdef CONFIG_PRINTK
89846 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89847 void __user *buffer, size_t *lenp, loff_t *ppos)
89848 {
89849 @@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89850
89851 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
89852 }
89853 -#endif
89854
89855 struct do_proc_dointvec_minmax_conv_param {
89856 int *min;
89857 @@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
89858 return -ENOSYS;
89859 }
89860
89861 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89862 + void __user *buffer, size_t *lenp, loff_t *ppos)
89863 +{
89864 + return -ENOSYS;
89865 +}
89866 +
89867 int proc_dointvec(struct ctl_table *table, int write,
89868 void __user *buffer, size_t *lenp, loff_t *ppos)
89869 {
89870 @@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
89871 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
89872 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
89873 EXPORT_SYMBOL(proc_dostring);
89874 +EXPORT_SYMBOL(proc_dostring_modpriv);
89875 EXPORT_SYMBOL(proc_doulongvec_minmax);
89876 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
89877 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
89878 index 13d2f7c..c93d0b0 100644
89879 --- a/kernel/taskstats.c
89880 +++ b/kernel/taskstats.c
89881 @@ -28,9 +28,12 @@
89882 #include <linux/fs.h>
89883 #include <linux/file.h>
89884 #include <linux/pid_namespace.h>
89885 +#include <linux/grsecurity.h>
89886 #include <net/genetlink.h>
89887 #include <linux/atomic.h>
89888
89889 +extern int gr_is_taskstats_denied(int pid);
89890 +
89891 /*
89892 * Maximum length of a cpumask that can be specified in
89893 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
89894 @@ -576,6 +579,9 @@ err:
89895
89896 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
89897 {
89898 + if (gr_is_taskstats_denied(current->pid))
89899 + return -EACCES;
89900 +
89901 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
89902 return cmd_attr_register_cpumask(info);
89903 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
89904 diff --git a/kernel/time.c b/kernel/time.c
89905 index 7c7964c..2a0d412 100644
89906 --- a/kernel/time.c
89907 +++ b/kernel/time.c
89908 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
89909 return error;
89910
89911 if (tz) {
89912 + /* we log in do_settimeofday called below, so don't log twice
89913 + */
89914 + if (!tv)
89915 + gr_log_timechange();
89916 +
89917 sys_tz = *tz;
89918 update_vsyscall_tz();
89919 if (firsttime) {
89920 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
89921 index 88c9c65..7497ebc 100644
89922 --- a/kernel/time/alarmtimer.c
89923 +++ b/kernel/time/alarmtimer.c
89924 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
89925 struct platform_device *pdev;
89926 int error = 0;
89927 int i;
89928 - struct k_clock alarm_clock = {
89929 + static struct k_clock alarm_clock = {
89930 .clock_getres = alarm_clock_getres,
89931 .clock_get = alarm_clock_get,
89932 .timer_create = alarm_timer_create,
89933 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
89934 index b415457..c26876d 100644
89935 --- a/kernel/time/timekeeping.c
89936 +++ b/kernel/time/timekeeping.c
89937 @@ -15,6 +15,7 @@
89938 #include <linux/init.h>
89939 #include <linux/mm.h>
89940 #include <linux/sched.h>
89941 +#include <linux/grsecurity.h>
89942 #include <linux/syscore_ops.h>
89943 #include <linux/clocksource.h>
89944 #include <linux/jiffies.h>
89945 @@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
89946 if (!timespec_valid_strict(tv))
89947 return -EINVAL;
89948
89949 + gr_log_timechange();
89950 +
89951 raw_spin_lock_irqsave(&timekeeper_lock, flags);
89952 write_seqcount_begin(&timekeeper_seq);
89953
89954 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
89955 index 61ed862..3b52c65 100644
89956 --- a/kernel/time/timer_list.c
89957 +++ b/kernel/time/timer_list.c
89958 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
89959
89960 static void print_name_offset(struct seq_file *m, void *sym)
89961 {
89962 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89963 + SEQ_printf(m, "<%p>", NULL);
89964 +#else
89965 char symname[KSYM_NAME_LEN];
89966
89967 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
89968 SEQ_printf(m, "<%pK>", sym);
89969 else
89970 SEQ_printf(m, "%s", symname);
89971 +#endif
89972 }
89973
89974 static void
89975 @@ -119,7 +123,11 @@ next_one:
89976 static void
89977 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
89978 {
89979 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89980 + SEQ_printf(m, " .base: %p\n", NULL);
89981 +#else
89982 SEQ_printf(m, " .base: %pK\n", base);
89983 +#endif
89984 SEQ_printf(m, " .index: %d\n",
89985 base->index);
89986 SEQ_printf(m, " .resolution: %Lu nsecs\n",
89987 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
89988 {
89989 struct proc_dir_entry *pe;
89990
89991 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89992 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
89993 +#else
89994 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
89995 +#endif
89996 if (!pe)
89997 return -ENOMEM;
89998 return 0;
89999 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90000 index 1fb08f2..ca4bb1e 100644
90001 --- a/kernel/time/timer_stats.c
90002 +++ b/kernel/time/timer_stats.c
90003 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90004 static unsigned long nr_entries;
90005 static struct entry entries[MAX_ENTRIES];
90006
90007 -static atomic_t overflow_count;
90008 +static atomic_unchecked_t overflow_count;
90009
90010 /*
90011 * The entries are in a hash-table, for fast lookup:
90012 @@ -140,7 +140,7 @@ static void reset_entries(void)
90013 nr_entries = 0;
90014 memset(entries, 0, sizeof(entries));
90015 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90016 - atomic_set(&overflow_count, 0);
90017 + atomic_set_unchecked(&overflow_count, 0);
90018 }
90019
90020 static struct entry *alloc_entry(void)
90021 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90022 if (likely(entry))
90023 entry->count++;
90024 else
90025 - atomic_inc(&overflow_count);
90026 + atomic_inc_unchecked(&overflow_count);
90027
90028 out_unlock:
90029 raw_spin_unlock_irqrestore(lock, flags);
90030 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90031
90032 static void print_name_offset(struct seq_file *m, unsigned long addr)
90033 {
90034 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90035 + seq_printf(m, "<%p>", NULL);
90036 +#else
90037 char symname[KSYM_NAME_LEN];
90038
90039 if (lookup_symbol_name(addr, symname) < 0)
90040 - seq_printf(m, "<%p>", (void *)addr);
90041 + seq_printf(m, "<%pK>", (void *)addr);
90042 else
90043 seq_printf(m, "%s", symname);
90044 +#endif
90045 }
90046
90047 static int tstats_show(struct seq_file *m, void *v)
90048 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90049
90050 seq_puts(m, "Timer Stats Version: v0.3\n");
90051 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90052 - if (atomic_read(&overflow_count))
90053 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90054 + if (atomic_read_unchecked(&overflow_count))
90055 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90056 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90057
90058 for (i = 0; i < nr_entries; i++) {
90059 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90060 {
90061 struct proc_dir_entry *pe;
90062
90063 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90064 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90065 +#else
90066 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90067 +#endif
90068 if (!pe)
90069 return -ENOMEM;
90070 return 0;
90071 diff --git a/kernel/timer.c b/kernel/timer.c
90072 index accfd24..e00f0c0 100644
90073 --- a/kernel/timer.c
90074 +++ b/kernel/timer.c
90075 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
90076 /*
90077 * This function runs timers and the timer-tq in bottom half context.
90078 */
90079 -static void run_timer_softirq(struct softirq_action *h)
90080 +static __latent_entropy void run_timer_softirq(void)
90081 {
90082 struct tvec_base *base = __this_cpu_read(tvec_bases);
90083
90084 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
90085 *
90086 * In all cases the return value is guaranteed to be non-negative.
90087 */
90088 -signed long __sched schedule_timeout(signed long timeout)
90089 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90090 {
90091 struct timer_list timer;
90092 unsigned long expire;
90093 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90094 index f785aef..59f1b18 100644
90095 --- a/kernel/trace/blktrace.c
90096 +++ b/kernel/trace/blktrace.c
90097 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90098 struct blk_trace *bt = filp->private_data;
90099 char buf[16];
90100
90101 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90102 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90103
90104 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90105 }
90106 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90107 return 1;
90108
90109 bt = buf->chan->private_data;
90110 - atomic_inc(&bt->dropped);
90111 + atomic_inc_unchecked(&bt->dropped);
90112 return 0;
90113 }
90114
90115 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90116
90117 bt->dir = dir;
90118 bt->dev = dev;
90119 - atomic_set(&bt->dropped, 0);
90120 + atomic_set_unchecked(&bt->dropped, 0);
90121 INIT_LIST_HEAD(&bt->running_list);
90122
90123 ret = -EIO;
90124 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90125 index 38463d2..68abe92 100644
90126 --- a/kernel/trace/ftrace.c
90127 +++ b/kernel/trace/ftrace.c
90128 @@ -1978,12 +1978,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90129 if (unlikely(ftrace_disabled))
90130 return 0;
90131
90132 + ret = ftrace_arch_code_modify_prepare();
90133 + FTRACE_WARN_ON(ret);
90134 + if (ret)
90135 + return 0;
90136 +
90137 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90138 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90139 if (ret) {
90140 ftrace_bug(ret, ip);
90141 - return 0;
90142 }
90143 - return 1;
90144 + return ret ? 0 : 1;
90145 }
90146
90147 /*
90148 @@ -4190,8 +4195,10 @@ static int ftrace_process_locs(struct module *mod,
90149 if (!count)
90150 return 0;
90151
90152 + pax_open_kernel();
90153 sort(start, count, sizeof(*start),
90154 ftrace_cmp_ips, ftrace_swap_ips);
90155 + pax_close_kernel();
90156
90157 start_pg = ftrace_allocate_pages(count);
90158 if (!start_pg)
90159 @@ -4922,8 +4929,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90160 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90161
90162 static int ftrace_graph_active;
90163 -static struct notifier_block ftrace_suspend_notifier;
90164 -
90165 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90166 {
90167 return 0;
90168 @@ -5099,6 +5104,10 @@ static void update_function_graph_func(void)
90169 ftrace_graph_entry = ftrace_graph_entry_test;
90170 }
90171
90172 +static struct notifier_block ftrace_suspend_notifier = {
90173 + .notifier_call = ftrace_suspend_notifier_call
90174 +};
90175 +
90176 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90177 trace_func_graph_ent_t entryfunc)
90178 {
90179 @@ -5112,7 +5121,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90180 goto out;
90181 }
90182
90183 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90184 register_pm_notifier(&ftrace_suspend_notifier);
90185
90186 ftrace_graph_active++;
90187 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90188 index 0e337ee..3370631 100644
90189 --- a/kernel/trace/ring_buffer.c
90190 +++ b/kernel/trace/ring_buffer.c
90191 @@ -352,9 +352,9 @@ struct buffer_data_page {
90192 */
90193 struct buffer_page {
90194 struct list_head list; /* list of buffer pages */
90195 - local_t write; /* index for next write */
90196 + local_unchecked_t write; /* index for next write */
90197 unsigned read; /* index for next read */
90198 - local_t entries; /* entries on this page */
90199 + local_unchecked_t entries; /* entries on this page */
90200 unsigned long real_end; /* real end of data */
90201 struct buffer_data_page *page; /* Actual data page */
90202 };
90203 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90204 unsigned long last_overrun;
90205 local_t entries_bytes;
90206 local_t entries;
90207 - local_t overrun;
90208 - local_t commit_overrun;
90209 + local_unchecked_t overrun;
90210 + local_unchecked_t commit_overrun;
90211 local_t dropped_events;
90212 local_t committing;
90213 local_t commits;
90214 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90215 *
90216 * We add a counter to the write field to denote this.
90217 */
90218 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90219 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90220 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90221 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90222
90223 /*
90224 * Just make sure we have seen our old_write and synchronize
90225 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90226 * cmpxchg to only update if an interrupt did not already
90227 * do it for us. If the cmpxchg fails, we don't care.
90228 */
90229 - (void)local_cmpxchg(&next_page->write, old_write, val);
90230 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90231 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90232 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90233
90234 /*
90235 * No need to worry about races with clearing out the commit.
90236 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90237
90238 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90239 {
90240 - return local_read(&bpage->entries) & RB_WRITE_MASK;
90241 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90242 }
90243
90244 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90245 {
90246 - return local_read(&bpage->write) & RB_WRITE_MASK;
90247 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90248 }
90249
90250 static int
90251 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90252 * bytes consumed in ring buffer from here.
90253 * Increment overrun to account for the lost events.
90254 */
90255 - local_add(page_entries, &cpu_buffer->overrun);
90256 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
90257 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90258 }
90259
90260 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90261 * it is our responsibility to update
90262 * the counters.
90263 */
90264 - local_add(entries, &cpu_buffer->overrun);
90265 + local_add_unchecked(entries, &cpu_buffer->overrun);
90266 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90267
90268 /*
90269 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90270 if (tail == BUF_PAGE_SIZE)
90271 tail_page->real_end = 0;
90272
90273 - local_sub(length, &tail_page->write);
90274 + local_sub_unchecked(length, &tail_page->write);
90275 return;
90276 }
90277
90278 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90279 rb_event_set_padding(event);
90280
90281 /* Set the write back to the previous setting */
90282 - local_sub(length, &tail_page->write);
90283 + local_sub_unchecked(length, &tail_page->write);
90284 return;
90285 }
90286
90287 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90288
90289 /* Set write to end of buffer */
90290 length = (tail + length) - BUF_PAGE_SIZE;
90291 - local_sub(length, &tail_page->write);
90292 + local_sub_unchecked(length, &tail_page->write);
90293 }
90294
90295 /*
90296 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90297 * about it.
90298 */
90299 if (unlikely(next_page == commit_page)) {
90300 - local_inc(&cpu_buffer->commit_overrun);
90301 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90302 goto out_reset;
90303 }
90304
90305 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90306 cpu_buffer->tail_page) &&
90307 (cpu_buffer->commit_page ==
90308 cpu_buffer->reader_page))) {
90309 - local_inc(&cpu_buffer->commit_overrun);
90310 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90311 goto out_reset;
90312 }
90313 }
90314 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90315 length += RB_LEN_TIME_EXTEND;
90316
90317 tail_page = cpu_buffer->tail_page;
90318 - write = local_add_return(length, &tail_page->write);
90319 + write = local_add_return_unchecked(length, &tail_page->write);
90320
90321 /* set write to only the index of the write */
90322 write &= RB_WRITE_MASK;
90323 @@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90324 kmemcheck_annotate_bitfield(event, bitfield);
90325 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90326
90327 - local_inc(&tail_page->entries);
90328 + local_inc_unchecked(&tail_page->entries);
90329
90330 /*
90331 * If this is the first commit on the page, then update
90332 @@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90333
90334 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90335 unsigned long write_mask =
90336 - local_read(&bpage->write) & ~RB_WRITE_MASK;
90337 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90338 unsigned long event_length = rb_event_length(event);
90339 /*
90340 * This is on the tail page. It is possible that
90341 @@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90342 */
90343 old_index += write_mask;
90344 new_index += write_mask;
90345 - index = local_cmpxchg(&bpage->write, old_index, new_index);
90346 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90347 if (index == old_index) {
90348 /* update counters */
90349 local_sub(event_length, &cpu_buffer->entries_bytes);
90350 @@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90351
90352 /* Do the likely case first */
90353 if (likely(bpage->page == (void *)addr)) {
90354 - local_dec(&bpage->entries);
90355 + local_dec_unchecked(&bpage->entries);
90356 return;
90357 }
90358
90359 @@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90360 start = bpage;
90361 do {
90362 if (bpage->page == (void *)addr) {
90363 - local_dec(&bpage->entries);
90364 + local_dec_unchecked(&bpage->entries);
90365 return;
90366 }
90367 rb_inc_page(cpu_buffer, &bpage);
90368 @@ -3146,7 +3146,7 @@ static inline unsigned long
90369 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90370 {
90371 return local_read(&cpu_buffer->entries) -
90372 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90373 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90374 }
90375
90376 /**
90377 @@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90378 return 0;
90379
90380 cpu_buffer = buffer->buffers[cpu];
90381 - ret = local_read(&cpu_buffer->overrun);
90382 + ret = local_read_unchecked(&cpu_buffer->overrun);
90383
90384 return ret;
90385 }
90386 @@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90387 return 0;
90388
90389 cpu_buffer = buffer->buffers[cpu];
90390 - ret = local_read(&cpu_buffer->commit_overrun);
90391 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90392
90393 return ret;
90394 }
90395 @@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90396 /* if you care about this being correct, lock the buffer */
90397 for_each_buffer_cpu(buffer, cpu) {
90398 cpu_buffer = buffer->buffers[cpu];
90399 - overruns += local_read(&cpu_buffer->overrun);
90400 + overruns += local_read_unchecked(&cpu_buffer->overrun);
90401 }
90402
90403 return overruns;
90404 @@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90405 /*
90406 * Reset the reader page to size zero.
90407 */
90408 - local_set(&cpu_buffer->reader_page->write, 0);
90409 - local_set(&cpu_buffer->reader_page->entries, 0);
90410 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90411 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90412 local_set(&cpu_buffer->reader_page->page->commit, 0);
90413 cpu_buffer->reader_page->real_end = 0;
90414
90415 @@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90416 * want to compare with the last_overrun.
90417 */
90418 smp_mb();
90419 - overwrite = local_read(&(cpu_buffer->overrun));
90420 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90421
90422 /*
90423 * Here's the tricky part.
90424 @@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90425
90426 cpu_buffer->head_page
90427 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90428 - local_set(&cpu_buffer->head_page->write, 0);
90429 - local_set(&cpu_buffer->head_page->entries, 0);
90430 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
90431 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90432 local_set(&cpu_buffer->head_page->page->commit, 0);
90433
90434 cpu_buffer->head_page->read = 0;
90435 @@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90436
90437 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90438 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90439 - local_set(&cpu_buffer->reader_page->write, 0);
90440 - local_set(&cpu_buffer->reader_page->entries, 0);
90441 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90442 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90443 local_set(&cpu_buffer->reader_page->page->commit, 0);
90444 cpu_buffer->reader_page->read = 0;
90445
90446 local_set(&cpu_buffer->entries_bytes, 0);
90447 - local_set(&cpu_buffer->overrun, 0);
90448 - local_set(&cpu_buffer->commit_overrun, 0);
90449 + local_set_unchecked(&cpu_buffer->overrun, 0);
90450 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90451 local_set(&cpu_buffer->dropped_events, 0);
90452 local_set(&cpu_buffer->entries, 0);
90453 local_set(&cpu_buffer->committing, 0);
90454 @@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90455 rb_init_page(bpage);
90456 bpage = reader->page;
90457 reader->page = *data_page;
90458 - local_set(&reader->write, 0);
90459 - local_set(&reader->entries, 0);
90460 + local_set_unchecked(&reader->write, 0);
90461 + local_set_unchecked(&reader->entries, 0);
90462 reader->read = 0;
90463 *data_page = bpage;
90464
90465 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90466 index 0a360ce..7bd800e 100644
90467 --- a/kernel/trace/trace.c
90468 +++ b/kernel/trace/trace.c
90469 @@ -3352,7 +3352,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90470 return 0;
90471 }
90472
90473 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90474 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90475 {
90476 /* do nothing if flag is already set */
90477 if (!!(trace_flags & mask) == !!enabled)
90478 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90479 index ea189e0..a5b48c4 100644
90480 --- a/kernel/trace/trace.h
90481 +++ b/kernel/trace/trace.h
90482 @@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
90483 void trace_printk_init_buffers(void);
90484 void trace_printk_start_comm(void);
90485 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90486 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90487 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90488
90489 /*
90490 * Normal trace_printk() and friends allocates special buffers
90491 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90492 index 26dc348..8708ca7 100644
90493 --- a/kernel/trace/trace_clock.c
90494 +++ b/kernel/trace/trace_clock.c
90495 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90496 return now;
90497 }
90498
90499 -static atomic64_t trace_counter;
90500 +static atomic64_unchecked_t trace_counter;
90501
90502 /*
90503 * trace_clock_counter(): simply an atomic counter.
90504 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90505 */
90506 u64 notrace trace_clock_counter(void)
90507 {
90508 - return atomic64_add_return(1, &trace_counter);
90509 + return atomic64_inc_return_unchecked(&trace_counter);
90510 }
90511 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90512 index ba983dc..911aaf9 100644
90513 --- a/kernel/trace/trace_events.c
90514 +++ b/kernel/trace/trace_events.c
90515 @@ -1675,7 +1675,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90516 return 0;
90517 }
90518
90519 -struct ftrace_module_file_ops;
90520 static void __add_event_to_tracers(struct ftrace_event_call *call);
90521
90522 /* Add an additional event_call dynamically */
90523 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90524 index 0abd9b8..6a663a2 100644
90525 --- a/kernel/trace/trace_mmiotrace.c
90526 +++ b/kernel/trace/trace_mmiotrace.c
90527 @@ -24,7 +24,7 @@ struct header_iter {
90528 static struct trace_array *mmio_trace_array;
90529 static bool overrun_detected;
90530 static unsigned long prev_overruns;
90531 -static atomic_t dropped_count;
90532 +static atomic_unchecked_t dropped_count;
90533
90534 static void mmio_reset_data(struct trace_array *tr)
90535 {
90536 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90537
90538 static unsigned long count_overruns(struct trace_iterator *iter)
90539 {
90540 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
90541 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90542 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90543
90544 if (over > prev_overruns)
90545 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90546 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90547 sizeof(*entry), 0, pc);
90548 if (!event) {
90549 - atomic_inc(&dropped_count);
90550 + atomic_inc_unchecked(&dropped_count);
90551 return;
90552 }
90553 entry = ring_buffer_event_data(event);
90554 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90555 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90556 sizeof(*entry), 0, pc);
90557 if (!event) {
90558 - atomic_inc(&dropped_count);
90559 + atomic_inc_unchecked(&dropped_count);
90560 return;
90561 }
90562 entry = ring_buffer_event_data(event);
90563 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90564 index ed32284..884d6c3 100644
90565 --- a/kernel/trace/trace_output.c
90566 +++ b/kernel/trace/trace_output.c
90567 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90568
90569 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90570 if (!IS_ERR(p)) {
90571 - p = mangle_path(s->buffer + s->len, p, "\n");
90572 + p = mangle_path(s->buffer + s->len, p, "\n\\");
90573 if (p) {
90574 s->len = p - s->buffer;
90575 return 1;
90576 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90577 goto out;
90578 }
90579
90580 + pax_open_kernel();
90581 if (event->funcs->trace == NULL)
90582 - event->funcs->trace = trace_nop_print;
90583 + *(void **)&event->funcs->trace = trace_nop_print;
90584 if (event->funcs->raw == NULL)
90585 - event->funcs->raw = trace_nop_print;
90586 + *(void **)&event->funcs->raw = trace_nop_print;
90587 if (event->funcs->hex == NULL)
90588 - event->funcs->hex = trace_nop_print;
90589 + *(void **)&event->funcs->hex = trace_nop_print;
90590 if (event->funcs->binary == NULL)
90591 - event->funcs->binary = trace_nop_print;
90592 + *(void **)&event->funcs->binary = trace_nop_print;
90593 + pax_close_kernel();
90594
90595 key = event->type & (EVENT_HASHSIZE - 1);
90596
90597 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90598 index b20428c..4845a10 100644
90599 --- a/kernel/trace/trace_stack.c
90600 +++ b/kernel/trace/trace_stack.c
90601 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90602 return;
90603
90604 /* we do not handle interrupt stacks yet */
90605 - if (!object_is_on_stack(stack))
90606 + if (!object_starts_on_stack(stack))
90607 return;
90608
90609 local_irq_save(flags);
90610 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90611 index 240fb62..583473e 100644
90612 --- a/kernel/user_namespace.c
90613 +++ b/kernel/user_namespace.c
90614 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90615 !kgid_has_mapping(parent_ns, group))
90616 return -EPERM;
90617
90618 +#ifdef CONFIG_GRKERNSEC
90619 + /*
90620 + * This doesn't really inspire confidence:
90621 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90622 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90623 + * Increases kernel attack surface in areas developers
90624 + * previously cared little about ("low importance due
90625 + * to requiring "root" capability")
90626 + * To be removed when this code receives *proper* review
90627 + */
90628 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90629 + !capable(CAP_SETGID))
90630 + return -EPERM;
90631 +#endif
90632 +
90633 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90634 if (!ns)
90635 return -ENOMEM;
90636 @@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90637 if (atomic_read(&current->mm->mm_users) > 1)
90638 return -EINVAL;
90639
90640 - if (current->fs->users != 1)
90641 + if (atomic_read(&current->fs->users) != 1)
90642 return -EINVAL;
90643
90644 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90645 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90646 index 4f69f9a..7c6f8f8 100644
90647 --- a/kernel/utsname_sysctl.c
90648 +++ b/kernel/utsname_sysctl.c
90649 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90650 static int proc_do_uts_string(ctl_table *table, int write,
90651 void __user *buffer, size_t *lenp, loff_t *ppos)
90652 {
90653 - struct ctl_table uts_table;
90654 + ctl_table_no_const uts_table;
90655 int r;
90656 memcpy(&uts_table, table, sizeof(uts_table));
90657 uts_table.data = get_uts(table, write);
90658 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90659 index 4431610..4265616 100644
90660 --- a/kernel/watchdog.c
90661 +++ b/kernel/watchdog.c
90662 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90663 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90664 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90665
90666 -static struct smp_hotplug_thread watchdog_threads = {
90667 +static struct smp_hotplug_thread watchdog_threads __read_only = {
90668 .store = &softlockup_watchdog,
90669 .thread_should_run = watchdog_should_run,
90670 .thread_fn = watchdog,
90671 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90672 index a8381cf..1ce1331 100644
90673 --- a/kernel/workqueue.c
90674 +++ b/kernel/workqueue.c
90675 @@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90676 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90677 worker_flags |= WORKER_REBOUND;
90678 worker_flags &= ~WORKER_UNBOUND;
90679 - ACCESS_ONCE(worker->flags) = worker_flags;
90680 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
90681 }
90682
90683 spin_unlock_irq(&pool->lock);
90684 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90685 index db25707..8b16430 100644
90686 --- a/lib/Kconfig.debug
90687 +++ b/lib/Kconfig.debug
90688 @@ -845,7 +845,7 @@ config DEBUG_MUTEXES
90689
90690 config DEBUG_WW_MUTEX_SLOWPATH
90691 bool "Wait/wound mutex debugging: Slowpath testing"
90692 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90693 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90694 select DEBUG_LOCK_ALLOC
90695 select DEBUG_SPINLOCK
90696 select DEBUG_MUTEXES
90697 @@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90698
90699 config DEBUG_LOCK_ALLOC
90700 bool "Lock debugging: detect incorrect freeing of live locks"
90701 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90702 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90703 select DEBUG_SPINLOCK
90704 select DEBUG_MUTEXES
90705 select LOCKDEP
90706 @@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
90707
90708 config PROVE_LOCKING
90709 bool "Lock debugging: prove locking correctness"
90710 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90711 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90712 select LOCKDEP
90713 select DEBUG_SPINLOCK
90714 select DEBUG_MUTEXES
90715 @@ -923,7 +923,7 @@ config LOCKDEP
90716
90717 config LOCK_STAT
90718 bool "Lock usage statistics"
90719 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90720 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90721 select LOCKDEP
90722 select DEBUG_SPINLOCK
90723 select DEBUG_MUTEXES
90724 @@ -1385,6 +1385,7 @@ config LATENCYTOP
90725 depends on DEBUG_KERNEL
90726 depends on STACKTRACE_SUPPORT
90727 depends on PROC_FS
90728 + depends on !GRKERNSEC_HIDESYM
90729 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90730 select KALLSYMS
90731 select KALLSYMS_ALL
90732 @@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90733 config DEBUG_STRICT_USER_COPY_CHECKS
90734 bool "Strict user copy size checks"
90735 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90736 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90737 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90738 help
90739 Enabling this option turns a certain set of sanity checks for user
90740 copy operations into compile time failures.
90741 @@ -1520,7 +1521,7 @@ endmenu # runtime tests
90742
90743 config PROVIDE_OHCI1394_DMA_INIT
90744 bool "Remote debugging over FireWire early on boot"
90745 - depends on PCI && X86
90746 + depends on PCI && X86 && !GRKERNSEC
90747 help
90748 If you want to debug problems which hang or crash the kernel early
90749 on boot and the crashing machine has a FireWire port, you can use
90750 @@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
90751
90752 config FIREWIRE_OHCI_REMOTE_DMA
90753 bool "Remote debugging over FireWire with firewire-ohci"
90754 - depends on FIREWIRE_OHCI
90755 + depends on FIREWIRE_OHCI && !GRKERNSEC
90756 help
90757 This option lets you use the FireWire bus for remote debugging
90758 with help of the firewire-ohci driver. It enables unfiltered
90759 diff --git a/lib/Makefile b/lib/Makefile
90760 index 04944e9..f43eabe 100644
90761 --- a/lib/Makefile
90762 +++ b/lib/Makefile
90763 @@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90764 obj-$(CONFIG_BTREE) += btree.o
90765 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90766 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90767 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90768 +obj-y += list_debug.o
90769 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90770
90771 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90772 diff --git a/lib/bitmap.c b/lib/bitmap.c
90773 index 06f7e4f..f3cf2b0 100644
90774 --- a/lib/bitmap.c
90775 +++ b/lib/bitmap.c
90776 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90777 {
90778 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90779 u32 chunk;
90780 - const char __user __force *ubuf = (const char __user __force *)buf;
90781 + const char __user *ubuf = (const char __force_user *)buf;
90782
90783 bitmap_zero(maskp, nmaskbits);
90784
90785 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90786 {
90787 if (!access_ok(VERIFY_READ, ubuf, ulen))
90788 return -EFAULT;
90789 - return __bitmap_parse((const char __force *)ubuf,
90790 + return __bitmap_parse((const char __force_kernel *)ubuf,
90791 ulen, 1, maskp, nmaskbits);
90792
90793 }
90794 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90795 {
90796 unsigned a, b;
90797 int c, old_c, totaldigits;
90798 - const char __user __force *ubuf = (const char __user __force *)buf;
90799 + const char __user *ubuf = (const char __force_user *)buf;
90800 int exp_digit, in_range;
90801
90802 totaldigits = c = 0;
90803 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90804 {
90805 if (!access_ok(VERIFY_READ, ubuf, ulen))
90806 return -EFAULT;
90807 - return __bitmap_parselist((const char __force *)ubuf,
90808 + return __bitmap_parselist((const char __force_kernel *)ubuf,
90809 ulen, 1, maskp, nmaskbits);
90810 }
90811 EXPORT_SYMBOL(bitmap_parselist_user);
90812 diff --git a/lib/bug.c b/lib/bug.c
90813 index 1686034..a9c00c8 100644
90814 --- a/lib/bug.c
90815 +++ b/lib/bug.c
90816 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90817 return BUG_TRAP_TYPE_NONE;
90818
90819 bug = find_bug(bugaddr);
90820 + if (!bug)
90821 + return BUG_TRAP_TYPE_NONE;
90822
90823 file = NULL;
90824 line = 0;
90825 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90826 index e0731c3..ad66444 100644
90827 --- a/lib/debugobjects.c
90828 +++ b/lib/debugobjects.c
90829 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90830 if (limit > 4)
90831 return;
90832
90833 - is_on_stack = object_is_on_stack(addr);
90834 + is_on_stack = object_starts_on_stack(addr);
90835 if (is_on_stack == onstack)
90836 return;
90837
90838 diff --git a/lib/devres.c b/lib/devres.c
90839 index 8235331..5881053 100644
90840 --- a/lib/devres.c
90841 +++ b/lib/devres.c
90842 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90843 void devm_iounmap(struct device *dev, void __iomem *addr)
90844 {
90845 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
90846 - (void *)addr));
90847 + (void __force *)addr));
90848 iounmap(addr);
90849 }
90850 EXPORT_SYMBOL(devm_iounmap);
90851 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
90852 {
90853 ioport_unmap(addr);
90854 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
90855 - devm_ioport_map_match, (void *)addr));
90856 + devm_ioport_map_match, (void __force *)addr));
90857 }
90858 EXPORT_SYMBOL(devm_ioport_unmap);
90859 #endif /* CONFIG_HAS_IOPORT */
90860 diff --git a/lib/div64.c b/lib/div64.c
90861 index 4382ad7..08aa558 100644
90862 --- a/lib/div64.c
90863 +++ b/lib/div64.c
90864 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
90865 EXPORT_SYMBOL(__div64_32);
90866
90867 #ifndef div_s64_rem
90868 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90869 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90870 {
90871 u64 quotient;
90872
90873 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
90874 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
90875 */
90876 #ifndef div64_u64
90877 -u64 div64_u64(u64 dividend, u64 divisor)
90878 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
90879 {
90880 u32 high = divisor >> 32;
90881 u64 quot;
90882 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
90883 index d87a17a..ac0d79a 100644
90884 --- a/lib/dma-debug.c
90885 +++ b/lib/dma-debug.c
90886 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
90887
90888 void dma_debug_add_bus(struct bus_type *bus)
90889 {
90890 - struct notifier_block *nb;
90891 + notifier_block_no_const *nb;
90892
90893 if (global_disable)
90894 return;
90895 @@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
90896
90897 static void check_for_stack(struct device *dev, void *addr)
90898 {
90899 - if (object_is_on_stack(addr))
90900 + if (object_starts_on_stack(addr))
90901 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
90902 "stack [addr=%p]\n", addr);
90903 }
90904 diff --git a/lib/inflate.c b/lib/inflate.c
90905 index 013a761..c28f3fc 100644
90906 --- a/lib/inflate.c
90907 +++ b/lib/inflate.c
90908 @@ -269,7 +269,7 @@ static void free(void *where)
90909 malloc_ptr = free_mem_ptr;
90910 }
90911 #else
90912 -#define malloc(a) kmalloc(a, GFP_KERNEL)
90913 +#define malloc(a) kmalloc((a), GFP_KERNEL)
90914 #define free(a) kfree(a)
90915 #endif
90916
90917 diff --git a/lib/ioremap.c b/lib/ioremap.c
90918 index 0c9216c..863bd89 100644
90919 --- a/lib/ioremap.c
90920 +++ b/lib/ioremap.c
90921 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
90922 unsigned long next;
90923
90924 phys_addr -= addr;
90925 - pmd = pmd_alloc(&init_mm, pud, addr);
90926 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90927 if (!pmd)
90928 return -ENOMEM;
90929 do {
90930 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
90931 unsigned long next;
90932
90933 phys_addr -= addr;
90934 - pud = pud_alloc(&init_mm, pgd, addr);
90935 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
90936 if (!pud)
90937 return -ENOMEM;
90938 do {
90939 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
90940 index bd2bea9..6b3c95e 100644
90941 --- a/lib/is_single_threaded.c
90942 +++ b/lib/is_single_threaded.c
90943 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
90944 struct task_struct *p, *t;
90945 bool ret;
90946
90947 + if (!mm)
90948 + return true;
90949 +
90950 if (atomic_read(&task->signal->live) != 1)
90951 return false;
90952
90953 diff --git a/lib/kobject.c b/lib/kobject.c
90954 index 5b4b888..c2950f7 100644
90955 --- a/lib/kobject.c
90956 +++ b/lib/kobject.c
90957 @@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
90958
90959
90960 static DEFINE_SPINLOCK(kobj_ns_type_lock);
90961 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
90962 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
90963
90964 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90965 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90966 {
90967 enum kobj_ns_type type = ops->type;
90968 int error;
90969 diff --git a/lib/list_debug.c b/lib/list_debug.c
90970 index c24c2f7..f0296f4 100644
90971 --- a/lib/list_debug.c
90972 +++ b/lib/list_debug.c
90973 @@ -11,7 +11,9 @@
90974 #include <linux/bug.h>
90975 #include <linux/kernel.h>
90976 #include <linux/rculist.h>
90977 +#include <linux/mm.h>
90978
90979 +#ifdef CONFIG_DEBUG_LIST
90980 /*
90981 * Insert a new entry between two known consecutive entries.
90982 *
90983 @@ -19,21 +21,40 @@
90984 * the prev/next entries already!
90985 */
90986
90987 +static bool __list_add_debug(struct list_head *new,
90988 + struct list_head *prev,
90989 + struct list_head *next)
90990 +{
90991 + if (unlikely(next->prev != prev)) {
90992 + printk(KERN_ERR "list_add corruption. next->prev should be "
90993 + "prev (%p), but was %p. (next=%p).\n",
90994 + prev, next->prev, next);
90995 + BUG();
90996 + return false;
90997 + }
90998 + if (unlikely(prev->next != next)) {
90999 + printk(KERN_ERR "list_add corruption. prev->next should be "
91000 + "next (%p), but was %p. (prev=%p).\n",
91001 + next, prev->next, prev);
91002 + BUG();
91003 + return false;
91004 + }
91005 + if (unlikely(new == prev || new == next)) {
91006 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91007 + new, prev, next);
91008 + BUG();
91009 + return false;
91010 + }
91011 + return true;
91012 +}
91013 +
91014 void __list_add(struct list_head *new,
91015 - struct list_head *prev,
91016 - struct list_head *next)
91017 + struct list_head *prev,
91018 + struct list_head *next)
91019 {
91020 - WARN(next->prev != prev,
91021 - "list_add corruption. next->prev should be "
91022 - "prev (%p), but was %p. (next=%p).\n",
91023 - prev, next->prev, next);
91024 - WARN(prev->next != next,
91025 - "list_add corruption. prev->next should be "
91026 - "next (%p), but was %p. (prev=%p).\n",
91027 - next, prev->next, prev);
91028 - WARN(new == prev || new == next,
91029 - "list_add double add: new=%p, prev=%p, next=%p.\n",
91030 - new, prev, next);
91031 + if (!__list_add_debug(new, prev, next))
91032 + return;
91033 +
91034 next->prev = new;
91035 new->next = next;
91036 new->prev = prev;
91037 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91038 }
91039 EXPORT_SYMBOL(__list_add);
91040
91041 -void __list_del_entry(struct list_head *entry)
91042 +static bool __list_del_entry_debug(struct list_head *entry)
91043 {
91044 struct list_head *prev, *next;
91045
91046 prev = entry->prev;
91047 next = entry->next;
91048
91049 - if (WARN(next == LIST_POISON1,
91050 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91051 - entry, LIST_POISON1) ||
91052 - WARN(prev == LIST_POISON2,
91053 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91054 - entry, LIST_POISON2) ||
91055 - WARN(prev->next != entry,
91056 - "list_del corruption. prev->next should be %p, "
91057 - "but was %p\n", entry, prev->next) ||
91058 - WARN(next->prev != entry,
91059 - "list_del corruption. next->prev should be %p, "
91060 - "but was %p\n", entry, next->prev))
91061 + if (unlikely(next == LIST_POISON1)) {
91062 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91063 + entry, LIST_POISON1);
91064 + BUG();
91065 + return false;
91066 + }
91067 + if (unlikely(prev == LIST_POISON2)) {
91068 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91069 + entry, LIST_POISON2);
91070 + BUG();
91071 + return false;
91072 + }
91073 + if (unlikely(entry->prev->next != entry)) {
91074 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91075 + "but was %p\n", entry, prev->next);
91076 + BUG();
91077 + return false;
91078 + }
91079 + if (unlikely(entry->next->prev != entry)) {
91080 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91081 + "but was %p\n", entry, next->prev);
91082 + BUG();
91083 + return false;
91084 + }
91085 + return true;
91086 +}
91087 +
91088 +void __list_del_entry(struct list_head *entry)
91089 +{
91090 + if (!__list_del_entry_debug(entry))
91091 return;
91092
91093 - __list_del(prev, next);
91094 + __list_del(entry->prev, entry->next);
91095 }
91096 EXPORT_SYMBOL(__list_del_entry);
91097
91098 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91099 void __list_add_rcu(struct list_head *new,
91100 struct list_head *prev, struct list_head *next)
91101 {
91102 - WARN(next->prev != prev,
91103 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91104 - prev, next->prev, next);
91105 - WARN(prev->next != next,
91106 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91107 - next, prev->next, prev);
91108 + if (!__list_add_debug(new, prev, next))
91109 + return;
91110 +
91111 new->next = next;
91112 new->prev = prev;
91113 rcu_assign_pointer(list_next_rcu(prev), new);
91114 next->prev = new;
91115 }
91116 EXPORT_SYMBOL(__list_add_rcu);
91117 +#endif
91118 +
91119 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91120 +{
91121 +#ifdef CONFIG_DEBUG_LIST
91122 + if (!__list_add_debug(new, prev, next))
91123 + return;
91124 +#endif
91125 +
91126 + pax_open_kernel();
91127 + next->prev = new;
91128 + new->next = next;
91129 + new->prev = prev;
91130 + prev->next = new;
91131 + pax_close_kernel();
91132 +}
91133 +EXPORT_SYMBOL(__pax_list_add);
91134 +
91135 +void pax_list_del(struct list_head *entry)
91136 +{
91137 +#ifdef CONFIG_DEBUG_LIST
91138 + if (!__list_del_entry_debug(entry))
91139 + return;
91140 +#endif
91141 +
91142 + pax_open_kernel();
91143 + __list_del(entry->prev, entry->next);
91144 + entry->next = LIST_POISON1;
91145 + entry->prev = LIST_POISON2;
91146 + pax_close_kernel();
91147 +}
91148 +EXPORT_SYMBOL(pax_list_del);
91149 +
91150 +void pax_list_del_init(struct list_head *entry)
91151 +{
91152 + pax_open_kernel();
91153 + __list_del(entry->prev, entry->next);
91154 + INIT_LIST_HEAD(entry);
91155 + pax_close_kernel();
91156 +}
91157 +EXPORT_SYMBOL(pax_list_del_init);
91158 +
91159 +void __pax_list_add_rcu(struct list_head *new,
91160 + struct list_head *prev, struct list_head *next)
91161 +{
91162 +#ifdef CONFIG_DEBUG_LIST
91163 + if (!__list_add_debug(new, prev, next))
91164 + return;
91165 +#endif
91166 +
91167 + pax_open_kernel();
91168 + new->next = next;
91169 + new->prev = prev;
91170 + rcu_assign_pointer(list_next_rcu(prev), new);
91171 + next->prev = new;
91172 + pax_close_kernel();
91173 +}
91174 +EXPORT_SYMBOL(__pax_list_add_rcu);
91175 +
91176 +void pax_list_del_rcu(struct list_head *entry)
91177 +{
91178 +#ifdef CONFIG_DEBUG_LIST
91179 + if (!__list_del_entry_debug(entry))
91180 + return;
91181 +#endif
91182 +
91183 + pax_open_kernel();
91184 + __list_del(entry->prev, entry->next);
91185 + entry->next = LIST_POISON1;
91186 + entry->prev = LIST_POISON2;
91187 + pax_close_kernel();
91188 +}
91189 +EXPORT_SYMBOL(pax_list_del_rcu);
91190 diff --git a/lib/nlattr.c b/lib/nlattr.c
91191 index 18eca78..fc67547 100644
91192 --- a/lib/nlattr.c
91193 +++ b/lib/nlattr.c
91194 @@ -303,9 +303,15 @@ int nla_memcmp(const struct nlattr *nla, const void *data,
91195 */
91196 int nla_strcmp(const struct nlattr *nla, const char *str)
91197 {
91198 - int len = strlen(str) + 1;
91199 - int d = nla_len(nla) - len;
91200 + int len = strlen(str);
91201 + char *buf = nla_data(nla);
91202 + int attrlen = nla_len(nla);
91203 + int d;
91204
91205 + if (attrlen > 0 && buf[attrlen - 1] == '\0')
91206 + attrlen--;
91207 +
91208 + d = attrlen - len;
91209 if (d == 0)
91210 d = memcmp(nla_data(nla), str, len);
91211
91212 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91213 index 1a53d49..ace934c 100644
91214 --- a/lib/percpu-refcount.c
91215 +++ b/lib/percpu-refcount.c
91216 @@ -29,7 +29,7 @@
91217 * can't hit 0 before we've added up all the percpu refs.
91218 */
91219
91220 -#define PCPU_COUNT_BIAS (1U << 31)
91221 +#define PCPU_COUNT_BIAS (1U << 30)
91222
91223 /**
91224 * percpu_ref_init - initialize a percpu refcount
91225 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91226 index 7811ed3..f80ca19 100644
91227 --- a/lib/radix-tree.c
91228 +++ b/lib/radix-tree.c
91229 @@ -93,7 +93,7 @@ struct radix_tree_preload {
91230 int nr;
91231 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91232 };
91233 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91234 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91235
91236 static inline void *ptr_to_indirect(void *ptr)
91237 {
91238 diff --git a/lib/random32.c b/lib/random32.c
91239 index 6148967..009bfe8 100644
91240 --- a/lib/random32.c
91241 +++ b/lib/random32.c
91242 @@ -44,7 +44,7 @@
91243 static void __init prandom_state_selftest(void);
91244 #endif
91245
91246 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91247 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91248
91249 /**
91250 * prandom_u32_state - seeded pseudo-random number generator.
91251 diff --git a/lib/rbtree.c b/lib/rbtree.c
91252 index 65f4eff..2cfa167 100644
91253 --- a/lib/rbtree.c
91254 +++ b/lib/rbtree.c
91255 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91256 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91257
91258 static const struct rb_augment_callbacks dummy_callbacks = {
91259 - dummy_propagate, dummy_copy, dummy_rotate
91260 + .propagate = dummy_propagate,
91261 + .copy = dummy_copy,
91262 + .rotate = dummy_rotate
91263 };
91264
91265 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91266 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91267 index bb2b201..46abaf9 100644
91268 --- a/lib/strncpy_from_user.c
91269 +++ b/lib/strncpy_from_user.c
91270 @@ -21,7 +21,7 @@
91271 */
91272 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91273 {
91274 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91275 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91276 long res = 0;
91277
91278 /*
91279 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91280 index a28df52..3d55877 100644
91281 --- a/lib/strnlen_user.c
91282 +++ b/lib/strnlen_user.c
91283 @@ -26,7 +26,7 @@
91284 */
91285 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91286 {
91287 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91288 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91289 long align, res = 0;
91290 unsigned long c;
91291
91292 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91293 index e4399fa..5e8b214 100644
91294 --- a/lib/swiotlb.c
91295 +++ b/lib/swiotlb.c
91296 @@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91297
91298 void
91299 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91300 - dma_addr_t dev_addr)
91301 + dma_addr_t dev_addr, struct dma_attrs *attrs)
91302 {
91303 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91304
91305 diff --git a/lib/usercopy.c b/lib/usercopy.c
91306 index 4f5b1dd..7cab418 100644
91307 --- a/lib/usercopy.c
91308 +++ b/lib/usercopy.c
91309 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91310 WARN(1, "Buffer overflow detected!\n");
91311 }
91312 EXPORT_SYMBOL(copy_from_user_overflow);
91313 +
91314 +void copy_to_user_overflow(void)
91315 +{
91316 + WARN(1, "Buffer overflow detected!\n");
91317 +}
91318 +EXPORT_SYMBOL(copy_to_user_overflow);
91319 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91320 index 10909c5..653e1b8 100644
91321 --- a/lib/vsprintf.c
91322 +++ b/lib/vsprintf.c
91323 @@ -16,6 +16,9 @@
91324 * - scnprintf and vscnprintf
91325 */
91326
91327 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91328 +#define __INCLUDED_BY_HIDESYM 1
91329 +#endif
91330 #include <stdarg.h>
91331 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91332 #include <linux/types.h>
91333 @@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
91334 return number(buf, end, *(const netdev_features_t *)addr, spec);
91335 }
91336
91337 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91338 +int kptr_restrict __read_mostly = 2;
91339 +#else
91340 int kptr_restrict __read_mostly;
91341 +#endif
91342
91343 /*
91344 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91345 @@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
91346 * - 'f' For simple symbolic function names without offset
91347 * - 'S' For symbolic direct pointers with offset
91348 * - 's' For symbolic direct pointers without offset
91349 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91350 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91351 * - 'B' For backtraced symbolic direct pointers with offset
91352 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91353 @@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91354
91355 if (!ptr && *fmt != 'K') {
91356 /*
91357 - * Print (null) with the same width as a pointer so it makes
91358 + * Print (nil) with the same width as a pointer so it makes
91359 * tabular output look nice.
91360 */
91361 if (spec.field_width == -1)
91362 spec.field_width = default_width;
91363 - return string(buf, end, "(null)", spec);
91364 + return string(buf, end, "(nil)", spec);
91365 }
91366
91367 switch (*fmt) {
91368 @@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91369 /* Fallthrough */
91370 case 'S':
91371 case 's':
91372 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91373 + break;
91374 +#else
91375 + return symbol_string(buf, end, ptr, spec, fmt);
91376 +#endif
91377 + case 'A':
91378 case 'B':
91379 return symbol_string(buf, end, ptr, spec, fmt);
91380 case 'R':
91381 @@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91382 va_end(va);
91383 return buf;
91384 }
91385 + case 'P':
91386 + break;
91387 case 'K':
91388 /*
91389 * %pK cannot be used in IRQ context because its test
91390 @@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91391 ((const struct file *)ptr)->f_path.dentry,
91392 spec, fmt);
91393 }
91394 +
91395 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91396 + /* 'P' = approved pointers to copy to userland,
91397 + as in the /proc/kallsyms case, as we make it display nothing
91398 + for non-root users, and the real contents for root users
91399 + Also ignore 'K' pointers, since we force their NULLing for non-root users
91400 + above
91401 + */
91402 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91403 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91404 + dump_stack();
91405 + ptr = NULL;
91406 + }
91407 +#endif
91408 +
91409 spec.flags |= SMALL;
91410 if (spec.field_width == -1) {
91411 spec.field_width = default_width;
91412 @@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91413 typeof(type) value; \
91414 if (sizeof(type) == 8) { \
91415 args = PTR_ALIGN(args, sizeof(u32)); \
91416 - *(u32 *)&value = *(u32 *)args; \
91417 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91418 + *(u32 *)&value = *(const u32 *)args; \
91419 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91420 } else { \
91421 args = PTR_ALIGN(args, sizeof(type)); \
91422 - value = *(typeof(type) *)args; \
91423 + value = *(const typeof(type) *)args; \
91424 } \
91425 args += sizeof(type); \
91426 value; \
91427 @@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91428 case FORMAT_TYPE_STR: {
91429 const char *str_arg = args;
91430 args += strlen(str_arg) + 1;
91431 - str = string(str, end, (char *)str_arg, spec);
91432 + str = string(str, end, str_arg, spec);
91433 break;
91434 }
91435
91436 diff --git a/localversion-grsec b/localversion-grsec
91437 new file mode 100644
91438 index 0000000..7cd6065
91439 --- /dev/null
91440 +++ b/localversion-grsec
91441 @@ -0,0 +1 @@
91442 +-grsec
91443 diff --git a/mm/Kconfig b/mm/Kconfig
91444 index 723bbe0..ea624b1 100644
91445 --- a/mm/Kconfig
91446 +++ b/mm/Kconfig
91447 @@ -326,10 +326,11 @@ config KSM
91448 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91449
91450 config DEFAULT_MMAP_MIN_ADDR
91451 - int "Low address space to protect from user allocation"
91452 + int "Low address space to protect from user allocation"
91453 depends on MMU
91454 - default 4096
91455 - help
91456 + default 32768 if ALPHA || ARM || PARISC || SPARC32
91457 + default 65536
91458 + help
91459 This is the portion of low virtual memory which should be protected
91460 from userspace allocation. Keeping a user from writing to low pages
91461 can help reduce the impact of kernel NULL pointer bugs.
91462 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
91463
91464 config HWPOISON_INJECT
91465 tristate "HWPoison pages injector"
91466 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91467 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91468 select PROC_PAGE_MONITOR
91469
91470 config NOMMU_INITIAL_TRIM_EXCESS
91471 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91472 index ce682f7..1fb54f9 100644
91473 --- a/mm/backing-dev.c
91474 +++ b/mm/backing-dev.c
91475 @@ -12,7 +12,7 @@
91476 #include <linux/device.h>
91477 #include <trace/events/writeback.h>
91478
91479 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91480 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91481
91482 struct backing_dev_info default_backing_dev_info = {
91483 .name = "default",
91484 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91485 return err;
91486
91487 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91488 - atomic_long_inc_return(&bdi_seq));
91489 + atomic_long_inc_return_unchecked(&bdi_seq));
91490 if (err) {
91491 bdi_destroy(bdi);
91492 return err;
91493 diff --git a/mm/filemap.c b/mm/filemap.c
91494 index b7749a9..50d1123 100644
91495 --- a/mm/filemap.c
91496 +++ b/mm/filemap.c
91497 @@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91498 struct address_space *mapping = file->f_mapping;
91499
91500 if (!mapping->a_ops->readpage)
91501 - return -ENOEXEC;
91502 + return -ENODEV;
91503 file_accessed(file);
91504 vma->vm_ops = &generic_file_vm_ops;
91505 return 0;
91506 @@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91507
91508 while (bytes) {
91509 char __user *buf = iov->iov_base + base;
91510 - int copy = min(bytes, iov->iov_len - base);
91511 + size_t copy = min(bytes, iov->iov_len - base);
91512
91513 base = 0;
91514 left = __copy_from_user_inatomic(vaddr, buf, copy);
91515 @@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91516 BUG_ON(!in_atomic());
91517 kaddr = kmap_atomic(page);
91518 if (likely(i->nr_segs == 1)) {
91519 - int left;
91520 + size_t left;
91521 char __user *buf = i->iov->iov_base + i->iov_offset;
91522 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91523 copied = bytes - left;
91524 @@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91525
91526 kaddr = kmap(page);
91527 if (likely(i->nr_segs == 1)) {
91528 - int left;
91529 + size_t left;
91530 char __user *buf = i->iov->iov_base + i->iov_offset;
91531 left = __copy_from_user(kaddr + offset, buf, bytes);
91532 copied = bytes - left;
91533 @@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91534 * zero-length segments (without overruning the iovec).
91535 */
91536 while (bytes || unlikely(i->count && !iov->iov_len)) {
91537 - int copy;
91538 + size_t copy;
91539
91540 copy = min(bytes, iov->iov_len - base);
91541 BUG_ON(!i->count || i->count < copy);
91542 @@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91543 *pos = i_size_read(inode);
91544
91545 if (limit != RLIM_INFINITY) {
91546 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91547 if (*pos >= limit) {
91548 send_sig(SIGXFSZ, current, 0);
91549 return -EFBIG;
91550 diff --git a/mm/fremap.c b/mm/fremap.c
91551 index bbc4d66..117b798 100644
91552 --- a/mm/fremap.c
91553 +++ b/mm/fremap.c
91554 @@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91555 retry:
91556 vma = find_vma(mm, start);
91557
91558 +#ifdef CONFIG_PAX_SEGMEXEC
91559 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91560 + goto out;
91561 +#endif
91562 +
91563 /*
91564 * Make sure the vma is shared, that it supports prefaulting,
91565 * and that the remapped range is valid and fully within
91566 diff --git a/mm/highmem.c b/mm/highmem.c
91567 index b32b70c..e512eb0 100644
91568 --- a/mm/highmem.c
91569 +++ b/mm/highmem.c
91570 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91571 * So no dangers, even with speculative execution.
91572 */
91573 page = pte_page(pkmap_page_table[i]);
91574 + pax_open_kernel();
91575 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91576 -
91577 + pax_close_kernel();
91578 set_page_address(page, NULL);
91579 need_flush = 1;
91580 }
91581 @@ -198,9 +199,11 @@ start:
91582 }
91583 }
91584 vaddr = PKMAP_ADDR(last_pkmap_nr);
91585 +
91586 + pax_open_kernel();
91587 set_pte_at(&init_mm, vaddr,
91588 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91589 -
91590 + pax_close_kernel();
91591 pkmap_count[last_pkmap_nr] = 1;
91592 set_page_address(page, (void *)vaddr);
91593
91594 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91595 index dee6cf4..52b94f7 100644
91596 --- a/mm/hugetlb.c
91597 +++ b/mm/hugetlb.c
91598 @@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91599 struct hstate *h = &default_hstate;
91600 unsigned long tmp;
91601 int ret;
91602 + ctl_table_no_const hugetlb_table;
91603
91604 tmp = h->max_huge_pages;
91605
91606 if (write && h->order >= MAX_ORDER)
91607 return -EINVAL;
91608
91609 - table->data = &tmp;
91610 - table->maxlen = sizeof(unsigned long);
91611 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91612 + hugetlb_table = *table;
91613 + hugetlb_table.data = &tmp;
91614 + hugetlb_table.maxlen = sizeof(unsigned long);
91615 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91616 if (ret)
91617 goto out;
91618
91619 @@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91620 struct hstate *h = &default_hstate;
91621 unsigned long tmp;
91622 int ret;
91623 + ctl_table_no_const hugetlb_table;
91624
91625 tmp = h->nr_overcommit_huge_pages;
91626
91627 if (write && h->order >= MAX_ORDER)
91628 return -EINVAL;
91629
91630 - table->data = &tmp;
91631 - table->maxlen = sizeof(unsigned long);
91632 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91633 + hugetlb_table = *table;
91634 + hugetlb_table.data = &tmp;
91635 + hugetlb_table.maxlen = sizeof(unsigned long);
91636 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91637 if (ret)
91638 goto out;
91639
91640 @@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91641 return 1;
91642 }
91643
91644 +#ifdef CONFIG_PAX_SEGMEXEC
91645 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91646 +{
91647 + struct mm_struct *mm = vma->vm_mm;
91648 + struct vm_area_struct *vma_m;
91649 + unsigned long address_m;
91650 + pte_t *ptep_m;
91651 +
91652 + vma_m = pax_find_mirror_vma(vma);
91653 + if (!vma_m)
91654 + return;
91655 +
91656 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91657 + address_m = address + SEGMEXEC_TASK_SIZE;
91658 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91659 + get_page(page_m);
91660 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
91661 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91662 +}
91663 +#endif
91664 +
91665 /*
91666 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91667 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91668 @@ -2712,6 +2737,11 @@ retry_avoidcopy:
91669 make_huge_pte(vma, new_page, 1));
91670 page_remove_rmap(old_page);
91671 hugepage_add_new_anon_rmap(new_page, vma, address);
91672 +
91673 +#ifdef CONFIG_PAX_SEGMEXEC
91674 + pax_mirror_huge_pte(vma, address, new_page);
91675 +#endif
91676 +
91677 /* Make the old page be freed below */
91678 new_page = old_page;
91679 }
91680 @@ -2876,6 +2906,10 @@ retry:
91681 && (vma->vm_flags & VM_SHARED)));
91682 set_huge_pte_at(mm, address, ptep, new_pte);
91683
91684 +#ifdef CONFIG_PAX_SEGMEXEC
91685 + pax_mirror_huge_pte(vma, address, page);
91686 +#endif
91687 +
91688 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91689 /* Optimization, do the COW without a second fault */
91690 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91691 @@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91692 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91693 struct hstate *h = hstate_vma(vma);
91694
91695 +#ifdef CONFIG_PAX_SEGMEXEC
91696 + struct vm_area_struct *vma_m;
91697 +#endif
91698 +
91699 address &= huge_page_mask(h);
91700
91701 ptep = huge_pte_offset(mm, address);
91702 @@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91703 VM_FAULT_SET_HINDEX(hstate_index(h));
91704 }
91705
91706 +#ifdef CONFIG_PAX_SEGMEXEC
91707 + vma_m = pax_find_mirror_vma(vma);
91708 + if (vma_m) {
91709 + unsigned long address_m;
91710 +
91711 + if (vma->vm_start > vma_m->vm_start) {
91712 + address_m = address;
91713 + address -= SEGMEXEC_TASK_SIZE;
91714 + vma = vma_m;
91715 + h = hstate_vma(vma);
91716 + } else
91717 + address_m = address + SEGMEXEC_TASK_SIZE;
91718 +
91719 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91720 + return VM_FAULT_OOM;
91721 + address_m &= HPAGE_MASK;
91722 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91723 + }
91724 +#endif
91725 +
91726 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91727 if (!ptep)
91728 return VM_FAULT_OOM;
91729 diff --git a/mm/internal.h b/mm/internal.h
91730 index 8b6cfd6..ec809a6 100644
91731 --- a/mm/internal.h
91732 +++ b/mm/internal.h
91733 @@ -96,6 +96,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91734 * in mm/page_alloc.c
91735 */
91736 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91737 +extern void free_compound_page(struct page *page);
91738 extern void prep_compound_page(struct page *page, unsigned long order);
91739 #ifdef CONFIG_MEMORY_FAILURE
91740 extern bool is_free_buddy_page(struct page *page);
91741 @@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
91742
91743 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91744 unsigned long, unsigned long,
91745 - unsigned long, unsigned long);
91746 + unsigned long, unsigned long) __intentional_overflow(-1);
91747
91748 extern void set_pageblock_order(void);
91749 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91750 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91751 index 31f01c5..7015178 100644
91752 --- a/mm/kmemleak.c
91753 +++ b/mm/kmemleak.c
91754 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91755
91756 for (i = 0; i < object->trace_len; i++) {
91757 void *ptr = (void *)object->trace[i];
91758 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91759 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91760 }
91761 }
91762
91763 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91764 return -ENOMEM;
91765 }
91766
91767 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91768 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91769 &kmemleak_fops);
91770 if (!dentry)
91771 pr_warning("Failed to create the debugfs kmemleak file\n");
91772 diff --git a/mm/maccess.c b/mm/maccess.c
91773 index d53adf9..03a24bf 100644
91774 --- a/mm/maccess.c
91775 +++ b/mm/maccess.c
91776 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91777 set_fs(KERNEL_DS);
91778 pagefault_disable();
91779 ret = __copy_from_user_inatomic(dst,
91780 - (__force const void __user *)src, size);
91781 + (const void __force_user *)src, size);
91782 pagefault_enable();
91783 set_fs(old_fs);
91784
91785 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91786
91787 set_fs(KERNEL_DS);
91788 pagefault_disable();
91789 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91790 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91791 pagefault_enable();
91792 set_fs(old_fs);
91793
91794 diff --git a/mm/madvise.c b/mm/madvise.c
91795 index 539eeb9..e24a987 100644
91796 --- a/mm/madvise.c
91797 +++ b/mm/madvise.c
91798 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91799 pgoff_t pgoff;
91800 unsigned long new_flags = vma->vm_flags;
91801
91802 +#ifdef CONFIG_PAX_SEGMEXEC
91803 + struct vm_area_struct *vma_m;
91804 +#endif
91805 +
91806 switch (behavior) {
91807 case MADV_NORMAL:
91808 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91809 @@ -126,6 +130,13 @@ success:
91810 /*
91811 * vm_flags is protected by the mmap_sem held in write mode.
91812 */
91813 +
91814 +#ifdef CONFIG_PAX_SEGMEXEC
91815 + vma_m = pax_find_mirror_vma(vma);
91816 + if (vma_m)
91817 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91818 +#endif
91819 +
91820 vma->vm_flags = new_flags;
91821
91822 out:
91823 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91824 struct vm_area_struct **prev,
91825 unsigned long start, unsigned long end)
91826 {
91827 +
91828 +#ifdef CONFIG_PAX_SEGMEXEC
91829 + struct vm_area_struct *vma_m;
91830 +#endif
91831 +
91832 *prev = vma;
91833 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91834 return -EINVAL;
91835 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91836 zap_page_range(vma, start, end - start, &details);
91837 } else
91838 zap_page_range(vma, start, end - start, NULL);
91839 +
91840 +#ifdef CONFIG_PAX_SEGMEXEC
91841 + vma_m = pax_find_mirror_vma(vma);
91842 + if (vma_m) {
91843 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
91844 + struct zap_details details = {
91845 + .nonlinear_vma = vma_m,
91846 + .last_index = ULONG_MAX,
91847 + };
91848 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
91849 + } else
91850 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
91851 + }
91852 +#endif
91853 +
91854 return 0;
91855 }
91856
91857 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
91858 if (end < start)
91859 return error;
91860
91861 +#ifdef CONFIG_PAX_SEGMEXEC
91862 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
91863 + if (end > SEGMEXEC_TASK_SIZE)
91864 + return error;
91865 + } else
91866 +#endif
91867 +
91868 + if (end > TASK_SIZE)
91869 + return error;
91870 +
91871 error = 0;
91872 if (end == start)
91873 return error;
91874 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
91875 index 4566e8f..46be98c 100644
91876 --- a/mm/memory-failure.c
91877 +++ b/mm/memory-failure.c
91878 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
91879
91880 int sysctl_memory_failure_recovery __read_mostly = 1;
91881
91882 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91883 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91884
91885 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
91886
91887 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
91888 pfn, t->comm, t->pid);
91889 si.si_signo = SIGBUS;
91890 si.si_errno = 0;
91891 - si.si_addr = (void *)addr;
91892 + si.si_addr = (void __user *)addr;
91893 #ifdef __ARCH_SI_TRAPNO
91894 si.si_trapno = trapno;
91895 #endif
91896 @@ -762,7 +762,7 @@ static struct page_state {
91897 unsigned long res;
91898 char *msg;
91899 int (*action)(struct page *p, unsigned long pfn);
91900 -} error_states[] = {
91901 +} __do_const error_states[] = {
91902 { reserved, reserved, "reserved kernel", me_kernel },
91903 /*
91904 * free pages are specially detected outside this table:
91905 @@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91906 nr_pages = 1 << compound_order(hpage);
91907 else /* normal page or thp */
91908 nr_pages = 1;
91909 - atomic_long_add(nr_pages, &num_poisoned_pages);
91910 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
91911
91912 /*
91913 * We need/can do nothing about count=0 pages.
91914 @@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91915 if (!PageHWPoison(hpage)
91916 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
91917 || (p != hpage && TestSetPageHWPoison(hpage))) {
91918 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91919 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91920 return 0;
91921 }
91922 set_page_hwpoison_huge_page(hpage);
91923 @@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91924 }
91925 if (hwpoison_filter(p)) {
91926 if (TestClearPageHWPoison(p))
91927 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91928 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91929 unlock_page(hpage);
91930 put_page(hpage);
91931 return 0;
91932 @@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
91933 return 0;
91934 }
91935 if (TestClearPageHWPoison(p))
91936 - atomic_long_dec(&num_poisoned_pages);
91937 + atomic_long_dec_unchecked(&num_poisoned_pages);
91938 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
91939 return 0;
91940 }
91941 @@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
91942 */
91943 if (TestClearPageHWPoison(page)) {
91944 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
91945 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91946 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91947 freeit = 1;
91948 if (PageHuge(page))
91949 clear_page_hwpoison_huge_page(page);
91950 @@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
91951 if (PageHuge(page)) {
91952 set_page_hwpoison_huge_page(hpage);
91953 dequeue_hwpoisoned_huge_page(hpage);
91954 - atomic_long_add(1 << compound_order(hpage),
91955 + atomic_long_add_unchecked(1 << compound_order(hpage),
91956 &num_poisoned_pages);
91957 } else {
91958 SetPageHWPoison(page);
91959 - atomic_long_inc(&num_poisoned_pages);
91960 + atomic_long_inc_unchecked(&num_poisoned_pages);
91961 }
91962 }
91963 return ret;
91964 @@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
91965 put_page(page);
91966 pr_info("soft_offline: %#lx: invalidated\n", pfn);
91967 SetPageHWPoison(page);
91968 - atomic_long_inc(&num_poisoned_pages);
91969 + atomic_long_inc_unchecked(&num_poisoned_pages);
91970 return 0;
91971 }
91972
91973 @@ -1610,7 +1610,7 @@ static int __soft_offline_page(struct page *page, int flags)
91974 if (!is_free_buddy_page(page))
91975 pr_info("soft offline: %#lx: page leaked\n",
91976 pfn);
91977 - atomic_long_inc(&num_poisoned_pages);
91978 + atomic_long_inc_unchecked(&num_poisoned_pages);
91979 }
91980 } else {
91981 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
91982 @@ -1684,11 +1684,11 @@ int soft_offline_page(struct page *page, int flags)
91983 if (PageHuge(page)) {
91984 set_page_hwpoison_huge_page(hpage);
91985 dequeue_hwpoisoned_huge_page(hpage);
91986 - atomic_long_add(1 << compound_order(hpage),
91987 + atomic_long_add_unchecked(1 << compound_order(hpage),
91988 &num_poisoned_pages);
91989 } else {
91990 SetPageHWPoison(page);
91991 - atomic_long_inc(&num_poisoned_pages);
91992 + atomic_long_inc_unchecked(&num_poisoned_pages);
91993 }
91994 }
91995 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
91996 diff --git a/mm/memory.c b/mm/memory.c
91997 index dda27b9..c56b9d6 100644
91998 --- a/mm/memory.c
91999 +++ b/mm/memory.c
92000 @@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92001 free_pte_range(tlb, pmd, addr);
92002 } while (pmd++, addr = next, addr != end);
92003
92004 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92005 start &= PUD_MASK;
92006 if (start < floor)
92007 return;
92008 @@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92009 pmd = pmd_offset(pud, start);
92010 pud_clear(pud);
92011 pmd_free_tlb(tlb, pmd, start);
92012 +#endif
92013 +
92014 }
92015
92016 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92017 @@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92018 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92019 } while (pud++, addr = next, addr != end);
92020
92021 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92022 start &= PGDIR_MASK;
92023 if (start < floor)
92024 return;
92025 @@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92026 pud = pud_offset(pgd, start);
92027 pgd_clear(pgd);
92028 pud_free_tlb(tlb, pud, start);
92029 +#endif
92030 +
92031 }
92032
92033 /*
92034 @@ -1635,12 +1641,6 @@ no_page_table:
92035 return page;
92036 }
92037
92038 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92039 -{
92040 - return stack_guard_page_start(vma, addr) ||
92041 - stack_guard_page_end(vma, addr+PAGE_SIZE);
92042 -}
92043 -
92044 /**
92045 * __get_user_pages() - pin user pages in memory
92046 * @tsk: task_struct of target task
92047 @@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92048
92049 i = 0;
92050
92051 - do {
92052 + while (nr_pages) {
92053 struct vm_area_struct *vma;
92054
92055 - vma = find_extend_vma(mm, start);
92056 + vma = find_vma(mm, start);
92057 if (!vma && in_gate_area(mm, start)) {
92058 unsigned long pg = start & PAGE_MASK;
92059 pgd_t *pgd;
92060 @@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92061 goto next_page;
92062 }
92063
92064 - if (!vma ||
92065 + if (!vma || start < vma->vm_start ||
92066 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
92067 !(vm_flags & vma->vm_flags))
92068 return i ? : -EFAULT;
92069 @@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92070 int ret;
92071 unsigned int fault_flags = 0;
92072
92073 - /* For mlock, just skip the stack guard page. */
92074 - if (foll_flags & FOLL_MLOCK) {
92075 - if (stack_guard_page(vma, start))
92076 - goto next_page;
92077 - }
92078 if (foll_flags & FOLL_WRITE)
92079 fault_flags |= FAULT_FLAG_WRITE;
92080 if (nonblocking)
92081 @@ -1892,7 +1887,7 @@ next_page:
92082 start += page_increm * PAGE_SIZE;
92083 nr_pages -= page_increm;
92084 } while (nr_pages && start < vma->vm_end);
92085 - } while (nr_pages);
92086 + }
92087 return i;
92088 }
92089 EXPORT_SYMBOL(__get_user_pages);
92090 @@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92091 page_add_file_rmap(page);
92092 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92093
92094 +#ifdef CONFIG_PAX_SEGMEXEC
92095 + pax_mirror_file_pte(vma, addr, page, ptl);
92096 +#endif
92097 +
92098 retval = 0;
92099 pte_unmap_unlock(pte, ptl);
92100 return retval;
92101 @@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92102 if (!page_count(page))
92103 return -EINVAL;
92104 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92105 +
92106 +#ifdef CONFIG_PAX_SEGMEXEC
92107 + struct vm_area_struct *vma_m;
92108 +#endif
92109 +
92110 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92111 BUG_ON(vma->vm_flags & VM_PFNMAP);
92112 vma->vm_flags |= VM_MIXEDMAP;
92113 +
92114 +#ifdef CONFIG_PAX_SEGMEXEC
92115 + vma_m = pax_find_mirror_vma(vma);
92116 + if (vma_m)
92117 + vma_m->vm_flags |= VM_MIXEDMAP;
92118 +#endif
92119 +
92120 }
92121 return insert_page(vma, addr, page, vma->vm_page_prot);
92122 }
92123 @@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92124 unsigned long pfn)
92125 {
92126 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92127 + BUG_ON(vma->vm_mirror);
92128
92129 if (addr < vma->vm_start || addr >= vma->vm_end)
92130 return -EFAULT;
92131 @@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92132
92133 BUG_ON(pud_huge(*pud));
92134
92135 - pmd = pmd_alloc(mm, pud, addr);
92136 + pmd = (mm == &init_mm) ?
92137 + pmd_alloc_kernel(mm, pud, addr) :
92138 + pmd_alloc(mm, pud, addr);
92139 if (!pmd)
92140 return -ENOMEM;
92141 do {
92142 @@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92143 unsigned long next;
92144 int err;
92145
92146 - pud = pud_alloc(mm, pgd, addr);
92147 + pud = (mm == &init_mm) ?
92148 + pud_alloc_kernel(mm, pgd, addr) :
92149 + pud_alloc(mm, pgd, addr);
92150 if (!pud)
92151 return -ENOMEM;
92152 do {
92153 @@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92154 copy_user_highpage(dst, src, va, vma);
92155 }
92156
92157 +#ifdef CONFIG_PAX_SEGMEXEC
92158 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92159 +{
92160 + struct mm_struct *mm = vma->vm_mm;
92161 + spinlock_t *ptl;
92162 + pte_t *pte, entry;
92163 +
92164 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92165 + entry = *pte;
92166 + if (!pte_present(entry)) {
92167 + if (!pte_none(entry)) {
92168 + BUG_ON(pte_file(entry));
92169 + free_swap_and_cache(pte_to_swp_entry(entry));
92170 + pte_clear_not_present_full(mm, address, pte, 0);
92171 + }
92172 + } else {
92173 + struct page *page;
92174 +
92175 + flush_cache_page(vma, address, pte_pfn(entry));
92176 + entry = ptep_clear_flush(vma, address, pte);
92177 + BUG_ON(pte_dirty(entry));
92178 + page = vm_normal_page(vma, address, entry);
92179 + if (page) {
92180 + update_hiwater_rss(mm);
92181 + if (PageAnon(page))
92182 + dec_mm_counter_fast(mm, MM_ANONPAGES);
92183 + else
92184 + dec_mm_counter_fast(mm, MM_FILEPAGES);
92185 + page_remove_rmap(page);
92186 + page_cache_release(page);
92187 + }
92188 + }
92189 + pte_unmap_unlock(pte, ptl);
92190 +}
92191 +
92192 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
92193 + *
92194 + * the ptl of the lower mapped page is held on entry and is not released on exit
92195 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92196 + */
92197 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92198 +{
92199 + struct mm_struct *mm = vma->vm_mm;
92200 + unsigned long address_m;
92201 + spinlock_t *ptl_m;
92202 + struct vm_area_struct *vma_m;
92203 + pmd_t *pmd_m;
92204 + pte_t *pte_m, entry_m;
92205 +
92206 + BUG_ON(!page_m || !PageAnon(page_m));
92207 +
92208 + vma_m = pax_find_mirror_vma(vma);
92209 + if (!vma_m)
92210 + return;
92211 +
92212 + BUG_ON(!PageLocked(page_m));
92213 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92214 + address_m = address + SEGMEXEC_TASK_SIZE;
92215 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92216 + pte_m = pte_offset_map(pmd_m, address_m);
92217 + ptl_m = pte_lockptr(mm, pmd_m);
92218 + if (ptl != ptl_m) {
92219 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92220 + if (!pte_none(*pte_m))
92221 + goto out;
92222 + }
92223 +
92224 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92225 + page_cache_get(page_m);
92226 + page_add_anon_rmap(page_m, vma_m, address_m);
92227 + inc_mm_counter_fast(mm, MM_ANONPAGES);
92228 + set_pte_at(mm, address_m, pte_m, entry_m);
92229 + update_mmu_cache(vma_m, address_m, pte_m);
92230 +out:
92231 + if (ptl != ptl_m)
92232 + spin_unlock(ptl_m);
92233 + pte_unmap(pte_m);
92234 + unlock_page(page_m);
92235 +}
92236 +
92237 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92238 +{
92239 + struct mm_struct *mm = vma->vm_mm;
92240 + unsigned long address_m;
92241 + spinlock_t *ptl_m;
92242 + struct vm_area_struct *vma_m;
92243 + pmd_t *pmd_m;
92244 + pte_t *pte_m, entry_m;
92245 +
92246 + BUG_ON(!page_m || PageAnon(page_m));
92247 +
92248 + vma_m = pax_find_mirror_vma(vma);
92249 + if (!vma_m)
92250 + return;
92251 +
92252 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92253 + address_m = address + SEGMEXEC_TASK_SIZE;
92254 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92255 + pte_m = pte_offset_map(pmd_m, address_m);
92256 + ptl_m = pte_lockptr(mm, pmd_m);
92257 + if (ptl != ptl_m) {
92258 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92259 + if (!pte_none(*pte_m))
92260 + goto out;
92261 + }
92262 +
92263 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92264 + page_cache_get(page_m);
92265 + page_add_file_rmap(page_m);
92266 + inc_mm_counter_fast(mm, MM_FILEPAGES);
92267 + set_pte_at(mm, address_m, pte_m, entry_m);
92268 + update_mmu_cache(vma_m, address_m, pte_m);
92269 +out:
92270 + if (ptl != ptl_m)
92271 + spin_unlock(ptl_m);
92272 + pte_unmap(pte_m);
92273 +}
92274 +
92275 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92276 +{
92277 + struct mm_struct *mm = vma->vm_mm;
92278 + unsigned long address_m;
92279 + spinlock_t *ptl_m;
92280 + struct vm_area_struct *vma_m;
92281 + pmd_t *pmd_m;
92282 + pte_t *pte_m, entry_m;
92283 +
92284 + vma_m = pax_find_mirror_vma(vma);
92285 + if (!vma_m)
92286 + return;
92287 +
92288 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92289 + address_m = address + SEGMEXEC_TASK_SIZE;
92290 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92291 + pte_m = pte_offset_map(pmd_m, address_m);
92292 + ptl_m = pte_lockptr(mm, pmd_m);
92293 + if (ptl != ptl_m) {
92294 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92295 + if (!pte_none(*pte_m))
92296 + goto out;
92297 + }
92298 +
92299 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92300 + set_pte_at(mm, address_m, pte_m, entry_m);
92301 +out:
92302 + if (ptl != ptl_m)
92303 + spin_unlock(ptl_m);
92304 + pte_unmap(pte_m);
92305 +}
92306 +
92307 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92308 +{
92309 + struct page *page_m;
92310 + pte_t entry;
92311 +
92312 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92313 + goto out;
92314 +
92315 + entry = *pte;
92316 + page_m = vm_normal_page(vma, address, entry);
92317 + if (!page_m)
92318 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92319 + else if (PageAnon(page_m)) {
92320 + if (pax_find_mirror_vma(vma)) {
92321 + pte_unmap_unlock(pte, ptl);
92322 + lock_page(page_m);
92323 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92324 + if (pte_same(entry, *pte))
92325 + pax_mirror_anon_pte(vma, address, page_m, ptl);
92326 + else
92327 + unlock_page(page_m);
92328 + }
92329 + } else
92330 + pax_mirror_file_pte(vma, address, page_m, ptl);
92331 +
92332 +out:
92333 + pte_unmap_unlock(pte, ptl);
92334 +}
92335 +#endif
92336 +
92337 /*
92338 * This routine handles present pages, when users try to write
92339 * to a shared page. It is done by copying the page to a new address
92340 @@ -2807,6 +3003,12 @@ gotten:
92341 */
92342 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92343 if (likely(pte_same(*page_table, orig_pte))) {
92344 +
92345 +#ifdef CONFIG_PAX_SEGMEXEC
92346 + if (pax_find_mirror_vma(vma))
92347 + BUG_ON(!trylock_page(new_page));
92348 +#endif
92349 +
92350 if (old_page) {
92351 if (!PageAnon(old_page)) {
92352 dec_mm_counter_fast(mm, MM_FILEPAGES);
92353 @@ -2858,6 +3060,10 @@ gotten:
92354 page_remove_rmap(old_page);
92355 }
92356
92357 +#ifdef CONFIG_PAX_SEGMEXEC
92358 + pax_mirror_anon_pte(vma, address, new_page, ptl);
92359 +#endif
92360 +
92361 /* Free the old page.. */
92362 new_page = old_page;
92363 ret |= VM_FAULT_WRITE;
92364 @@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92365 swap_free(entry);
92366 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92367 try_to_free_swap(page);
92368 +
92369 +#ifdef CONFIG_PAX_SEGMEXEC
92370 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92371 +#endif
92372 +
92373 unlock_page(page);
92374 if (page != swapcache) {
92375 /*
92376 @@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92377
92378 /* No need to invalidate - it was non-present before */
92379 update_mmu_cache(vma, address, page_table);
92380 +
92381 +#ifdef CONFIG_PAX_SEGMEXEC
92382 + pax_mirror_anon_pte(vma, address, page, ptl);
92383 +#endif
92384 +
92385 unlock:
92386 pte_unmap_unlock(page_table, ptl);
92387 out:
92388 @@ -3177,40 +3393,6 @@ out_release:
92389 }
92390
92391 /*
92392 - * This is like a special single-page "expand_{down|up}wards()",
92393 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
92394 - * doesn't hit another vma.
92395 - */
92396 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92397 -{
92398 - address &= PAGE_MASK;
92399 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92400 - struct vm_area_struct *prev = vma->vm_prev;
92401 -
92402 - /*
92403 - * Is there a mapping abutting this one below?
92404 - *
92405 - * That's only ok if it's the same stack mapping
92406 - * that has gotten split..
92407 - */
92408 - if (prev && prev->vm_end == address)
92409 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92410 -
92411 - expand_downwards(vma, address - PAGE_SIZE);
92412 - }
92413 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92414 - struct vm_area_struct *next = vma->vm_next;
92415 -
92416 - /* As VM_GROWSDOWN but s/below/above/ */
92417 - if (next && next->vm_start == address + PAGE_SIZE)
92418 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92419 -
92420 - expand_upwards(vma, address + PAGE_SIZE);
92421 - }
92422 - return 0;
92423 -}
92424 -
92425 -/*
92426 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92427 * but allow concurrent faults), and pte mapped but not yet locked.
92428 * We return with mmap_sem still held, but pte unmapped and unlocked.
92429 @@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92430 unsigned long address, pte_t *page_table, pmd_t *pmd,
92431 unsigned int flags)
92432 {
92433 - struct page *page;
92434 + struct page *page = NULL;
92435 spinlock_t *ptl;
92436 pte_t entry;
92437
92438 - pte_unmap(page_table);
92439 -
92440 - /* Check if we need to add a guard page to the stack */
92441 - if (check_stack_guard_page(vma, address) < 0)
92442 - return VM_FAULT_SIGBUS;
92443 -
92444 - /* Use the zero-page for reads */
92445 if (!(flags & FAULT_FLAG_WRITE)) {
92446 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92447 vma->vm_page_prot));
92448 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92449 + ptl = pte_lockptr(mm, pmd);
92450 + spin_lock(ptl);
92451 if (!pte_none(*page_table))
92452 goto unlock;
92453 goto setpte;
92454 }
92455
92456 /* Allocate our own private page. */
92457 + pte_unmap(page_table);
92458 +
92459 if (unlikely(anon_vma_prepare(vma)))
92460 goto oom;
92461 page = alloc_zeroed_user_highpage_movable(vma, address);
92462 @@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92463 if (!pte_none(*page_table))
92464 goto release;
92465
92466 +#ifdef CONFIG_PAX_SEGMEXEC
92467 + if (pax_find_mirror_vma(vma))
92468 + BUG_ON(!trylock_page(page));
92469 +#endif
92470 +
92471 inc_mm_counter_fast(mm, MM_ANONPAGES);
92472 page_add_new_anon_rmap(page, vma, address);
92473 setpte:
92474 @@ -3270,6 +3453,12 @@ setpte:
92475
92476 /* No need to invalidate - it was non-present before */
92477 update_mmu_cache(vma, address, page_table);
92478 +
92479 +#ifdef CONFIG_PAX_SEGMEXEC
92480 + if (page)
92481 + pax_mirror_anon_pte(vma, address, page, ptl);
92482 +#endif
92483 +
92484 unlock:
92485 pte_unmap_unlock(page_table, ptl);
92486 return 0;
92487 @@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92488 */
92489 /* Only go through if we didn't race with anybody else... */
92490 if (likely(pte_same(*page_table, orig_pte))) {
92491 +
92492 +#ifdef CONFIG_PAX_SEGMEXEC
92493 + if (anon && pax_find_mirror_vma(vma))
92494 + BUG_ON(!trylock_page(page));
92495 +#endif
92496 +
92497 flush_icache_page(vma, page);
92498 entry = mk_pte(page, vma->vm_page_prot);
92499 if (flags & FAULT_FLAG_WRITE)
92500 @@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92501
92502 /* no need to invalidate: a not-present page won't be cached */
92503 update_mmu_cache(vma, address, page_table);
92504 +
92505 +#ifdef CONFIG_PAX_SEGMEXEC
92506 + if (anon)
92507 + pax_mirror_anon_pte(vma, address, page, ptl);
92508 + else
92509 + pax_mirror_file_pte(vma, address, page, ptl);
92510 +#endif
92511 +
92512 } else {
92513 if (cow_page)
92514 mem_cgroup_uncharge_page(cow_page);
92515 @@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92516 if (flags & FAULT_FLAG_WRITE)
92517 flush_tlb_fix_spurious_fault(vma, address);
92518 }
92519 +
92520 +#ifdef CONFIG_PAX_SEGMEXEC
92521 + pax_mirror_pte(vma, address, pte, pmd, ptl);
92522 + return 0;
92523 +#endif
92524 +
92525 unlock:
92526 pte_unmap_unlock(pte, ptl);
92527 return 0;
92528 @@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92529 pmd_t *pmd;
92530 pte_t *pte;
92531
92532 +#ifdef CONFIG_PAX_SEGMEXEC
92533 + struct vm_area_struct *vma_m;
92534 +#endif
92535 +
92536 if (unlikely(is_vm_hugetlb_page(vma)))
92537 return hugetlb_fault(mm, vma, address, flags);
92538
92539 +#ifdef CONFIG_PAX_SEGMEXEC
92540 + vma_m = pax_find_mirror_vma(vma);
92541 + if (vma_m) {
92542 + unsigned long address_m;
92543 + pgd_t *pgd_m;
92544 + pud_t *pud_m;
92545 + pmd_t *pmd_m;
92546 +
92547 + if (vma->vm_start > vma_m->vm_start) {
92548 + address_m = address;
92549 + address -= SEGMEXEC_TASK_SIZE;
92550 + vma = vma_m;
92551 + } else
92552 + address_m = address + SEGMEXEC_TASK_SIZE;
92553 +
92554 + pgd_m = pgd_offset(mm, address_m);
92555 + pud_m = pud_alloc(mm, pgd_m, address_m);
92556 + if (!pud_m)
92557 + return VM_FAULT_OOM;
92558 + pmd_m = pmd_alloc(mm, pud_m, address_m);
92559 + if (!pmd_m)
92560 + return VM_FAULT_OOM;
92561 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92562 + return VM_FAULT_OOM;
92563 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92564 + }
92565 +#endif
92566 +
92567 pgd = pgd_offset(mm, address);
92568 pud = pud_alloc(mm, pgd, address);
92569 if (!pud)
92570 @@ -3830,6 +4071,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92571 spin_unlock(&mm->page_table_lock);
92572 return 0;
92573 }
92574 +
92575 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92576 +{
92577 + pud_t *new = pud_alloc_one(mm, address);
92578 + if (!new)
92579 + return -ENOMEM;
92580 +
92581 + smp_wmb(); /* See comment in __pte_alloc */
92582 +
92583 + spin_lock(&mm->page_table_lock);
92584 + if (pgd_present(*pgd)) /* Another has populated it */
92585 + pud_free(mm, new);
92586 + else
92587 + pgd_populate_kernel(mm, pgd, new);
92588 + spin_unlock(&mm->page_table_lock);
92589 + return 0;
92590 +}
92591 #endif /* __PAGETABLE_PUD_FOLDED */
92592
92593 #ifndef __PAGETABLE_PMD_FOLDED
92594 @@ -3860,6 +4118,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92595 spin_unlock(&mm->page_table_lock);
92596 return 0;
92597 }
92598 +
92599 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92600 +{
92601 + pmd_t *new = pmd_alloc_one(mm, address);
92602 + if (!new)
92603 + return -ENOMEM;
92604 +
92605 + smp_wmb(); /* See comment in __pte_alloc */
92606 +
92607 + spin_lock(&mm->page_table_lock);
92608 +#ifndef __ARCH_HAS_4LEVEL_HACK
92609 + if (pud_present(*pud)) /* Another has populated it */
92610 + pmd_free(mm, new);
92611 + else
92612 + pud_populate_kernel(mm, pud, new);
92613 +#else
92614 + if (pgd_present(*pud)) /* Another has populated it */
92615 + pmd_free(mm, new);
92616 + else
92617 + pgd_populate_kernel(mm, pud, new);
92618 +#endif /* __ARCH_HAS_4LEVEL_HACK */
92619 + spin_unlock(&mm->page_table_lock);
92620 + return 0;
92621 +}
92622 #endif /* __PAGETABLE_PMD_FOLDED */
92623
92624 #if !defined(__HAVE_ARCH_GATE_AREA)
92625 @@ -3873,7 +4155,7 @@ static int __init gate_vma_init(void)
92626 gate_vma.vm_start = FIXADDR_USER_START;
92627 gate_vma.vm_end = FIXADDR_USER_END;
92628 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92629 - gate_vma.vm_page_prot = __P101;
92630 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92631
92632 return 0;
92633 }
92634 @@ -4007,8 +4289,8 @@ out:
92635 return ret;
92636 }
92637
92638 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92639 - void *buf, int len, int write)
92640 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92641 + void *buf, size_t len, int write)
92642 {
92643 resource_size_t phys_addr;
92644 unsigned long prot = 0;
92645 @@ -4034,8 +4316,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92646 * Access another process' address space as given in mm. If non-NULL, use the
92647 * given task for page fault accounting.
92648 */
92649 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92650 - unsigned long addr, void *buf, int len, int write)
92651 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92652 + unsigned long addr, void *buf, size_t len, int write)
92653 {
92654 struct vm_area_struct *vma;
92655 void *old_buf = buf;
92656 @@ -4043,7 +4325,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92657 down_read(&mm->mmap_sem);
92658 /* ignore errors, just check how much was successfully transferred */
92659 while (len) {
92660 - int bytes, ret, offset;
92661 + ssize_t bytes, ret, offset;
92662 void *maddr;
92663 struct page *page = NULL;
92664
92665 @@ -4102,8 +4384,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92666 *
92667 * The caller must hold a reference on @mm.
92668 */
92669 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92670 - void *buf, int len, int write)
92671 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92672 + void *buf, size_t len, int write)
92673 {
92674 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92675 }
92676 @@ -4113,11 +4395,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92677 * Source/target buffer must be kernel space,
92678 * Do not walk the page table directly, use get_user_pages
92679 */
92680 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
92681 - void *buf, int len, int write)
92682 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92683 + void *buf, size_t len, int write)
92684 {
92685 struct mm_struct *mm;
92686 - int ret;
92687 + ssize_t ret;
92688
92689 mm = get_task_mm(tsk);
92690 if (!mm)
92691 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92692 index cb2f3dd..fb80468 100644
92693 --- a/mm/mempolicy.c
92694 +++ b/mm/mempolicy.c
92695 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92696 unsigned long vmstart;
92697 unsigned long vmend;
92698
92699 +#ifdef CONFIG_PAX_SEGMEXEC
92700 + struct vm_area_struct *vma_m;
92701 +#endif
92702 +
92703 vma = find_vma(mm, start);
92704 if (!vma || vma->vm_start > start)
92705 return -EFAULT;
92706 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92707 err = vma_replace_policy(vma, new_pol);
92708 if (err)
92709 goto out;
92710 +
92711 +#ifdef CONFIG_PAX_SEGMEXEC
92712 + vma_m = pax_find_mirror_vma(vma);
92713 + if (vma_m) {
92714 + err = vma_replace_policy(vma_m, new_pol);
92715 + if (err)
92716 + goto out;
92717 + }
92718 +#endif
92719 +
92720 }
92721
92722 out:
92723 @@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92724
92725 if (end < start)
92726 return -EINVAL;
92727 +
92728 +#ifdef CONFIG_PAX_SEGMEXEC
92729 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92730 + if (end > SEGMEXEC_TASK_SIZE)
92731 + return -EINVAL;
92732 + } else
92733 +#endif
92734 +
92735 + if (end > TASK_SIZE)
92736 + return -EINVAL;
92737 +
92738 if (end == start)
92739 return 0;
92740
92741 @@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92742 */
92743 tcred = __task_cred(task);
92744 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92745 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92746 - !capable(CAP_SYS_NICE)) {
92747 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92748 rcu_read_unlock();
92749 err = -EPERM;
92750 goto out_put;
92751 @@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92752 goto out;
92753 }
92754
92755 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92756 + if (mm != current->mm &&
92757 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92758 + mmput(mm);
92759 + err = -EPERM;
92760 + goto out;
92761 + }
92762 +#endif
92763 +
92764 err = do_migrate_pages(mm, old, new,
92765 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92766
92767 diff --git a/mm/migrate.c b/mm/migrate.c
92768 index 9194375..75c81e2 100644
92769 --- a/mm/migrate.c
92770 +++ b/mm/migrate.c
92771 @@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92772 */
92773 tcred = __task_cred(task);
92774 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92775 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92776 - !capable(CAP_SYS_NICE)) {
92777 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92778 rcu_read_unlock();
92779 err = -EPERM;
92780 goto out;
92781 diff --git a/mm/mlock.c b/mm/mlock.c
92782 index 192e6ee..b044449 100644
92783 --- a/mm/mlock.c
92784 +++ b/mm/mlock.c
92785 @@ -14,6 +14,7 @@
92786 #include <linux/pagevec.h>
92787 #include <linux/mempolicy.h>
92788 #include <linux/syscalls.h>
92789 +#include <linux/security.h>
92790 #include <linux/sched.h>
92791 #include <linux/export.h>
92792 #include <linux/rmap.h>
92793 @@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92794 {
92795 unsigned long nstart, end, tmp;
92796 struct vm_area_struct * vma, * prev;
92797 - int error;
92798 + int error = 0;
92799
92800 VM_BUG_ON(start & ~PAGE_MASK);
92801 VM_BUG_ON(len != PAGE_ALIGN(len));
92802 @@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92803 return -EINVAL;
92804 if (end == start)
92805 return 0;
92806 + if (end > TASK_SIZE)
92807 + return -EINVAL;
92808 +
92809 vma = find_vma(current->mm, start);
92810 if (!vma || vma->vm_start > start)
92811 return -ENOMEM;
92812 @@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92813 for (nstart = start ; ; ) {
92814 vm_flags_t newflags;
92815
92816 +#ifdef CONFIG_PAX_SEGMEXEC
92817 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92818 + break;
92819 +#endif
92820 +
92821 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92822
92823 newflags = vma->vm_flags & ~VM_LOCKED;
92824 @@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
92825 lock_limit >>= PAGE_SHIFT;
92826
92827 /* check against resource limits */
92828 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
92829 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
92830 error = do_mlock(start, len, 1);
92831 up_write(&current->mm->mmap_sem);
92832 @@ -754,6 +764,11 @@ static int do_mlockall(int flags)
92833 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
92834 vm_flags_t newflags;
92835
92836 +#ifdef CONFIG_PAX_SEGMEXEC
92837 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92838 + break;
92839 +#endif
92840 +
92841 newflags = vma->vm_flags & ~VM_LOCKED;
92842 if (flags & MCL_CURRENT)
92843 newflags |= VM_LOCKED;
92844 @@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
92845 lock_limit >>= PAGE_SHIFT;
92846
92847 ret = -ENOMEM;
92848 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
92849 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
92850 capable(CAP_IPC_LOCK))
92851 ret = do_mlockall(flags);
92852 diff --git a/mm/mmap.c b/mm/mmap.c
92853 index 546db74..650d1b9 100644
92854 --- a/mm/mmap.c
92855 +++ b/mm/mmap.c
92856 @@ -36,6 +36,7 @@
92857 #include <linux/sched/sysctl.h>
92858 #include <linux/notifier.h>
92859 #include <linux/memory.h>
92860 +#include <linux/random.h>
92861
92862 #include <asm/uaccess.h>
92863 #include <asm/cacheflush.h>
92864 @@ -52,6 +53,16 @@
92865 #define arch_rebalance_pgtables(addr, len) (addr)
92866 #endif
92867
92868 +static inline void verify_mm_writelocked(struct mm_struct *mm)
92869 +{
92870 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
92871 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92872 + up_read(&mm->mmap_sem);
92873 + BUG();
92874 + }
92875 +#endif
92876 +}
92877 +
92878 static void unmap_region(struct mm_struct *mm,
92879 struct vm_area_struct *vma, struct vm_area_struct *prev,
92880 unsigned long start, unsigned long end);
92881 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
92882 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
92883 *
92884 */
92885 -pgprot_t protection_map[16] = {
92886 +pgprot_t protection_map[16] __read_only = {
92887 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
92888 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
92889 };
92890
92891 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
92892 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
92893 {
92894 - return __pgprot(pgprot_val(protection_map[vm_flags &
92895 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
92896 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
92897 pgprot_val(arch_vm_get_page_prot(vm_flags)));
92898 +
92899 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92900 + if (!(__supported_pte_mask & _PAGE_NX) &&
92901 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
92902 + (vm_flags & (VM_READ | VM_WRITE)))
92903 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
92904 +#endif
92905 +
92906 + return prot;
92907 }
92908 EXPORT_SYMBOL(vm_get_page_prot);
92909
92910 @@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
92911 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
92912 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92913 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92914 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
92915 /*
92916 * Make sure vm_committed_as in one cacheline and not cacheline shared with
92917 * other variables. It can be updated by several CPUs frequently.
92918 @@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
92919 struct vm_area_struct *next = vma->vm_next;
92920
92921 might_sleep();
92922 + BUG_ON(vma->vm_mirror);
92923 if (vma->vm_ops && vma->vm_ops->close)
92924 vma->vm_ops->close(vma);
92925 if (vma->vm_file)
92926 @@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
92927 * not page aligned -Ram Gupta
92928 */
92929 rlim = rlimit(RLIMIT_DATA);
92930 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
92931 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
92932 (mm->end_data - mm->start_data) > rlim)
92933 goto out;
92934 @@ -939,6 +962,12 @@ static int
92935 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
92936 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92937 {
92938 +
92939 +#ifdef CONFIG_PAX_SEGMEXEC
92940 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
92941 + return 0;
92942 +#endif
92943 +
92944 if (is_mergeable_vma(vma, file, vm_flags) &&
92945 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92946 if (vma->vm_pgoff == vm_pgoff)
92947 @@ -958,6 +987,12 @@ static int
92948 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92949 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92950 {
92951 +
92952 +#ifdef CONFIG_PAX_SEGMEXEC
92953 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
92954 + return 0;
92955 +#endif
92956 +
92957 if (is_mergeable_vma(vma, file, vm_flags) &&
92958 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92959 pgoff_t vm_pglen;
92960 @@ -1000,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92961 struct vm_area_struct *vma_merge(struct mm_struct *mm,
92962 struct vm_area_struct *prev, unsigned long addr,
92963 unsigned long end, unsigned long vm_flags,
92964 - struct anon_vma *anon_vma, struct file *file,
92965 + struct anon_vma *anon_vma, struct file *file,
92966 pgoff_t pgoff, struct mempolicy *policy)
92967 {
92968 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
92969 struct vm_area_struct *area, *next;
92970 int err;
92971
92972 +#ifdef CONFIG_PAX_SEGMEXEC
92973 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
92974 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
92975 +
92976 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
92977 +#endif
92978 +
92979 /*
92980 * We later require that vma->vm_flags == vm_flags,
92981 * so this tests vma->vm_flags & VM_SPECIAL, too.
92982 @@ -1022,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92983 if (next && next->vm_end == end) /* cases 6, 7, 8 */
92984 next = next->vm_next;
92985
92986 +#ifdef CONFIG_PAX_SEGMEXEC
92987 + if (prev)
92988 + prev_m = pax_find_mirror_vma(prev);
92989 + if (area)
92990 + area_m = pax_find_mirror_vma(area);
92991 + if (next)
92992 + next_m = pax_find_mirror_vma(next);
92993 +#endif
92994 +
92995 /*
92996 * Can it merge with the predecessor?
92997 */
92998 @@ -1041,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92999 /* cases 1, 6 */
93000 err = vma_adjust(prev, prev->vm_start,
93001 next->vm_end, prev->vm_pgoff, NULL);
93002 - } else /* cases 2, 5, 7 */
93003 +
93004 +#ifdef CONFIG_PAX_SEGMEXEC
93005 + if (!err && prev_m)
93006 + err = vma_adjust(prev_m, prev_m->vm_start,
93007 + next_m->vm_end, prev_m->vm_pgoff, NULL);
93008 +#endif
93009 +
93010 + } else { /* cases 2, 5, 7 */
93011 err = vma_adjust(prev, prev->vm_start,
93012 end, prev->vm_pgoff, NULL);
93013 +
93014 +#ifdef CONFIG_PAX_SEGMEXEC
93015 + if (!err && prev_m)
93016 + err = vma_adjust(prev_m, prev_m->vm_start,
93017 + end_m, prev_m->vm_pgoff, NULL);
93018 +#endif
93019 +
93020 + }
93021 if (err)
93022 return NULL;
93023 khugepaged_enter_vma_merge(prev);
93024 @@ -1057,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93025 mpol_equal(policy, vma_policy(next)) &&
93026 can_vma_merge_before(next, vm_flags,
93027 anon_vma, file, pgoff+pglen)) {
93028 - if (prev && addr < prev->vm_end) /* case 4 */
93029 + if (prev && addr < prev->vm_end) { /* case 4 */
93030 err = vma_adjust(prev, prev->vm_start,
93031 addr, prev->vm_pgoff, NULL);
93032 - else /* cases 3, 8 */
93033 +
93034 +#ifdef CONFIG_PAX_SEGMEXEC
93035 + if (!err && prev_m)
93036 + err = vma_adjust(prev_m, prev_m->vm_start,
93037 + addr_m, prev_m->vm_pgoff, NULL);
93038 +#endif
93039 +
93040 + } else { /* cases 3, 8 */
93041 err = vma_adjust(area, addr, next->vm_end,
93042 next->vm_pgoff - pglen, NULL);
93043 +
93044 +#ifdef CONFIG_PAX_SEGMEXEC
93045 + if (!err && area_m)
93046 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
93047 + next_m->vm_pgoff - pglen, NULL);
93048 +#endif
93049 +
93050 + }
93051 if (err)
93052 return NULL;
93053 khugepaged_enter_vma_merge(area);
93054 @@ -1171,8 +1252,10 @@ none:
93055 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93056 struct file *file, long pages)
93057 {
93058 - const unsigned long stack_flags
93059 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93060 +
93061 +#ifdef CONFIG_PAX_RANDMMAP
93062 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93063 +#endif
93064
93065 mm->total_vm += pages;
93066
93067 @@ -1180,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93068 mm->shared_vm += pages;
93069 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93070 mm->exec_vm += pages;
93071 - } else if (flags & stack_flags)
93072 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93073 mm->stack_vm += pages;
93074 }
93075 #endif /* CONFIG_PROC_FS */
93076 @@ -1218,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93077 * (the exception is when the underlying filesystem is noexec
93078 * mounted, in which case we dont add PROT_EXEC.)
93079 */
93080 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93081 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93082 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93083 prot |= PROT_EXEC;
93084
93085 @@ -1244,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93086 /* Obtain the address to map to. we verify (or select) it and ensure
93087 * that it represents a valid section of the address space.
93088 */
93089 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
93090 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93091 if (addr & ~PAGE_MASK)
93092 return addr;
93093
93094 @@ -1255,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93095 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93096 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93097
93098 +#ifdef CONFIG_PAX_MPROTECT
93099 + if (mm->pax_flags & MF_PAX_MPROTECT) {
93100 +
93101 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93102 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93103 + mm->binfmt->handle_mmap)
93104 + mm->binfmt->handle_mmap(file);
93105 +#endif
93106 +
93107 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
93108 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93109 + gr_log_rwxmmap(file);
93110 +
93111 +#ifdef CONFIG_PAX_EMUPLT
93112 + vm_flags &= ~VM_EXEC;
93113 +#else
93114 + return -EPERM;
93115 +#endif
93116 +
93117 + }
93118 +
93119 + if (!(vm_flags & VM_EXEC))
93120 + vm_flags &= ~VM_MAYEXEC;
93121 +#else
93122 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93123 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93124 +#endif
93125 + else
93126 + vm_flags &= ~VM_MAYWRITE;
93127 + }
93128 +#endif
93129 +
93130 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93131 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93132 + vm_flags &= ~VM_PAGEEXEC;
93133 +#endif
93134 +
93135 if (flags & MAP_LOCKED)
93136 if (!can_do_mlock())
93137 return -EPERM;
93138 @@ -1266,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93139 locked += mm->locked_vm;
93140 lock_limit = rlimit(RLIMIT_MEMLOCK);
93141 lock_limit >>= PAGE_SHIFT;
93142 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93143 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93144 return -EAGAIN;
93145 }
93146 @@ -1350,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93147 vm_flags |= VM_NORESERVE;
93148 }
93149
93150 + if (!gr_acl_handle_mmap(file, prot))
93151 + return -EACCES;
93152 +
93153 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93154 if (!IS_ERR_VALUE(addr) &&
93155 ((vm_flags & VM_LOCKED) ||
93156 @@ -1443,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93157 vm_flags_t vm_flags = vma->vm_flags;
93158
93159 /* If it was private or non-writable, the write bit is already clear */
93160 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93161 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93162 return 0;
93163
93164 /* The backer wishes to know when pages are first written to? */
93165 @@ -1489,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93166 struct rb_node **rb_link, *rb_parent;
93167 unsigned long charged = 0;
93168
93169 +#ifdef CONFIG_PAX_SEGMEXEC
93170 + struct vm_area_struct *vma_m = NULL;
93171 +#endif
93172 +
93173 + /*
93174 + * mm->mmap_sem is required to protect against another thread
93175 + * changing the mappings in case we sleep.
93176 + */
93177 + verify_mm_writelocked(mm);
93178 +
93179 /* Check against address space limit. */
93180 +
93181 +#ifdef CONFIG_PAX_RANDMMAP
93182 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93183 +#endif
93184 +
93185 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93186 unsigned long nr_pages;
93187
93188 @@ -1508,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93189
93190 /* Clear old maps */
93191 error = -ENOMEM;
93192 -munmap_back:
93193 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93194 if (do_munmap(mm, addr, len))
93195 return -ENOMEM;
93196 - goto munmap_back;
93197 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93198 }
93199
93200 /*
93201 @@ -1543,6 +1681,16 @@ munmap_back:
93202 goto unacct_error;
93203 }
93204
93205 +#ifdef CONFIG_PAX_SEGMEXEC
93206 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93207 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93208 + if (!vma_m) {
93209 + error = -ENOMEM;
93210 + goto free_vma;
93211 + }
93212 + }
93213 +#endif
93214 +
93215 vma->vm_mm = mm;
93216 vma->vm_start = addr;
93217 vma->vm_end = addr + len;
93218 @@ -1562,6 +1710,13 @@ munmap_back:
93219 if (error)
93220 goto unmap_and_free_vma;
93221
93222 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93223 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93224 + vma->vm_flags |= VM_PAGEEXEC;
93225 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93226 + }
93227 +#endif
93228 +
93229 /* Can addr have changed??
93230 *
93231 * Answer: Yes, several device drivers can do it in their
93232 @@ -1595,6 +1750,12 @@ munmap_back:
93233 }
93234
93235 vma_link(mm, vma, prev, rb_link, rb_parent);
93236 +
93237 +#ifdef CONFIG_PAX_SEGMEXEC
93238 + if (vma_m)
93239 + BUG_ON(pax_mirror_vma(vma_m, vma));
93240 +#endif
93241 +
93242 /* Once vma denies write, undo our temporary denial count */
93243 if (vm_flags & VM_DENYWRITE)
93244 allow_write_access(file);
93245 @@ -1603,6 +1764,7 @@ out:
93246 perf_event_mmap(vma);
93247
93248 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93249 + track_exec_limit(mm, addr, addr + len, vm_flags);
93250 if (vm_flags & VM_LOCKED) {
93251 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93252 vma == get_gate_vma(current->mm)))
93253 @@ -1635,6 +1797,12 @@ unmap_and_free_vma:
93254 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93255 charged = 0;
93256 free_vma:
93257 +
93258 +#ifdef CONFIG_PAX_SEGMEXEC
93259 + if (vma_m)
93260 + kmem_cache_free(vm_area_cachep, vma_m);
93261 +#endif
93262 +
93263 kmem_cache_free(vm_area_cachep, vma);
93264 unacct_error:
93265 if (charged)
93266 @@ -1642,7 +1810,63 @@ unacct_error:
93267 return error;
93268 }
93269
93270 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93271 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93272 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93273 +{
93274 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93275 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93276 +
93277 + return 0;
93278 +}
93279 +#endif
93280 +
93281 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93282 +{
93283 + if (!vma) {
93284 +#ifdef CONFIG_STACK_GROWSUP
93285 + if (addr > sysctl_heap_stack_gap)
93286 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93287 + else
93288 + vma = find_vma(current->mm, 0);
93289 + if (vma && (vma->vm_flags & VM_GROWSUP))
93290 + return false;
93291 +#endif
93292 + return true;
93293 + }
93294 +
93295 + if (addr + len > vma->vm_start)
93296 + return false;
93297 +
93298 + if (vma->vm_flags & VM_GROWSDOWN)
93299 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93300 +#ifdef CONFIG_STACK_GROWSUP
93301 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93302 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93303 +#endif
93304 + else if (offset)
93305 + return offset <= vma->vm_start - addr - len;
93306 +
93307 + return true;
93308 +}
93309 +
93310 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93311 +{
93312 + if (vma->vm_start < len)
93313 + return -ENOMEM;
93314 +
93315 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
93316 + if (offset <= vma->vm_start - len)
93317 + return vma->vm_start - len - offset;
93318 + else
93319 + return -ENOMEM;
93320 + }
93321 +
93322 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
93323 + return vma->vm_start - len - sysctl_heap_stack_gap;
93324 + return -ENOMEM;
93325 +}
93326 +
93327 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93328 {
93329 /*
93330 * We implement the search by looking for an rbtree node that
93331 @@ -1690,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93332 }
93333 }
93334
93335 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93336 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93337 check_current:
93338 /* Check if current node has a suitable gap */
93339 if (gap_start > high_limit)
93340 return -ENOMEM;
93341 +
93342 + if (gap_end - gap_start > info->threadstack_offset)
93343 + gap_start += info->threadstack_offset;
93344 + else
93345 + gap_start = gap_end;
93346 +
93347 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93348 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93349 + gap_start += sysctl_heap_stack_gap;
93350 + else
93351 + gap_start = gap_end;
93352 + }
93353 + if (vma->vm_flags & VM_GROWSDOWN) {
93354 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93355 + gap_end -= sysctl_heap_stack_gap;
93356 + else
93357 + gap_end = gap_start;
93358 + }
93359 if (gap_end >= low_limit && gap_end - gap_start >= length)
93360 goto found;
93361
93362 @@ -1744,7 +1986,7 @@ found:
93363 return gap_start;
93364 }
93365
93366 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93367 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93368 {
93369 struct mm_struct *mm = current->mm;
93370 struct vm_area_struct *vma;
93371 @@ -1798,6 +2040,24 @@ check_current:
93372 gap_end = vma->vm_start;
93373 if (gap_end < low_limit)
93374 return -ENOMEM;
93375 +
93376 + if (gap_end - gap_start > info->threadstack_offset)
93377 + gap_end -= info->threadstack_offset;
93378 + else
93379 + gap_end = gap_start;
93380 +
93381 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93382 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93383 + gap_start += sysctl_heap_stack_gap;
93384 + else
93385 + gap_start = gap_end;
93386 + }
93387 + if (vma->vm_flags & VM_GROWSDOWN) {
93388 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93389 + gap_end -= sysctl_heap_stack_gap;
93390 + else
93391 + gap_end = gap_start;
93392 + }
93393 if (gap_start <= high_limit && gap_end - gap_start >= length)
93394 goto found;
93395
93396 @@ -1861,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93397 struct mm_struct *mm = current->mm;
93398 struct vm_area_struct *vma;
93399 struct vm_unmapped_area_info info;
93400 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93401
93402 if (len > TASK_SIZE - mmap_min_addr)
93403 return -ENOMEM;
93404 @@ -1868,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93405 if (flags & MAP_FIXED)
93406 return addr;
93407
93408 +#ifdef CONFIG_PAX_RANDMMAP
93409 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93410 +#endif
93411 +
93412 if (addr) {
93413 addr = PAGE_ALIGN(addr);
93414 vma = find_vma(mm, addr);
93415 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93416 - (!vma || addr + len <= vma->vm_start))
93417 + check_heap_stack_gap(vma, addr, len, offset))
93418 return addr;
93419 }
93420
93421 @@ -1881,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93422 info.low_limit = mm->mmap_base;
93423 info.high_limit = TASK_SIZE;
93424 info.align_mask = 0;
93425 + info.threadstack_offset = offset;
93426 return vm_unmapped_area(&info);
93427 }
93428 #endif
93429 @@ -1899,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93430 struct mm_struct *mm = current->mm;
93431 unsigned long addr = addr0;
93432 struct vm_unmapped_area_info info;
93433 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93434
93435 /* requested length too big for entire address space */
93436 if (len > TASK_SIZE - mmap_min_addr)
93437 @@ -1907,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93438 if (flags & MAP_FIXED)
93439 return addr;
93440
93441 +#ifdef CONFIG_PAX_RANDMMAP
93442 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93443 +#endif
93444 +
93445 /* requesting a specific address */
93446 if (addr) {
93447 addr = PAGE_ALIGN(addr);
93448 vma = find_vma(mm, addr);
93449 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93450 - (!vma || addr + len <= vma->vm_start))
93451 + check_heap_stack_gap(vma, addr, len, offset))
93452 return addr;
93453 }
93454
93455 @@ -1921,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93456 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93457 info.high_limit = mm->mmap_base;
93458 info.align_mask = 0;
93459 + info.threadstack_offset = offset;
93460 addr = vm_unmapped_area(&info);
93461
93462 /*
93463 @@ -1933,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93464 VM_BUG_ON(addr != -ENOMEM);
93465 info.flags = 0;
93466 info.low_limit = TASK_UNMAPPED_BASE;
93467 +
93468 +#ifdef CONFIG_PAX_RANDMMAP
93469 + if (mm->pax_flags & MF_PAX_RANDMMAP)
93470 + info.low_limit += mm->delta_mmap;
93471 +#endif
93472 +
93473 info.high_limit = TASK_SIZE;
93474 addr = vm_unmapped_area(&info);
93475 }
93476 @@ -2034,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93477 return vma;
93478 }
93479
93480 +#ifdef CONFIG_PAX_SEGMEXEC
93481 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93482 +{
93483 + struct vm_area_struct *vma_m;
93484 +
93485 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93486 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93487 + BUG_ON(vma->vm_mirror);
93488 + return NULL;
93489 + }
93490 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93491 + vma_m = vma->vm_mirror;
93492 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93493 + BUG_ON(vma->vm_file != vma_m->vm_file);
93494 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93495 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93496 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93497 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93498 + return vma_m;
93499 +}
93500 +#endif
93501 +
93502 /*
93503 * Verify that the stack growth is acceptable and
93504 * update accounting. This is shared with both the
93505 @@ -2050,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93506 return -ENOMEM;
93507
93508 /* Stack limit test */
93509 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
93510 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93511 return -ENOMEM;
93512
93513 @@ -2060,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93514 locked = mm->locked_vm + grow;
93515 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93516 limit >>= PAGE_SHIFT;
93517 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93518 if (locked > limit && !capable(CAP_IPC_LOCK))
93519 return -ENOMEM;
93520 }
93521 @@ -2089,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93522 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93523 * vma is the last one with address > vma->vm_end. Have to extend vma.
93524 */
93525 +#ifndef CONFIG_IA64
93526 +static
93527 +#endif
93528 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93529 {
93530 int error;
93531 + bool locknext;
93532
93533 if (!(vma->vm_flags & VM_GROWSUP))
93534 return -EFAULT;
93535
93536 + /* Also guard against wrapping around to address 0. */
93537 + if (address < PAGE_ALIGN(address+1))
93538 + address = PAGE_ALIGN(address+1);
93539 + else
93540 + return -ENOMEM;
93541 +
93542 /*
93543 * We must make sure the anon_vma is allocated
93544 * so that the anon_vma locking is not a noop.
93545 */
93546 if (unlikely(anon_vma_prepare(vma)))
93547 return -ENOMEM;
93548 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93549 + if (locknext && anon_vma_prepare(vma->vm_next))
93550 + return -ENOMEM;
93551 vma_lock_anon_vma(vma);
93552 + if (locknext)
93553 + vma_lock_anon_vma(vma->vm_next);
93554
93555 /*
93556 * vma->vm_start/vm_end cannot change under us because the caller
93557 * is required to hold the mmap_sem in read mode. We need the
93558 - * anon_vma lock to serialize against concurrent expand_stacks.
93559 - * Also guard against wrapping around to address 0.
93560 + * anon_vma locks to serialize against concurrent expand_stacks
93561 + * and expand_upwards.
93562 */
93563 - if (address < PAGE_ALIGN(address+4))
93564 - address = PAGE_ALIGN(address+4);
93565 - else {
93566 - vma_unlock_anon_vma(vma);
93567 - return -ENOMEM;
93568 - }
93569 error = 0;
93570
93571 /* Somebody else might have raced and expanded it already */
93572 - if (address > vma->vm_end) {
93573 + 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)
93574 + error = -ENOMEM;
93575 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93576 unsigned long size, grow;
93577
93578 size = address - vma->vm_start;
93579 @@ -2154,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93580 }
93581 }
93582 }
93583 + if (locknext)
93584 + vma_unlock_anon_vma(vma->vm_next);
93585 vma_unlock_anon_vma(vma);
93586 khugepaged_enter_vma_merge(vma);
93587 validate_mm(vma->vm_mm);
93588 @@ -2168,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
93589 unsigned long address)
93590 {
93591 int error;
93592 + bool lockprev = false;
93593 + struct vm_area_struct *prev;
93594
93595 /*
93596 * We must make sure the anon_vma is allocated
93597 @@ -2181,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
93598 if (error)
93599 return error;
93600
93601 + prev = vma->vm_prev;
93602 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93603 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93604 +#endif
93605 + if (lockprev && anon_vma_prepare(prev))
93606 + return -ENOMEM;
93607 + if (lockprev)
93608 + vma_lock_anon_vma(prev);
93609 +
93610 vma_lock_anon_vma(vma);
93611
93612 /*
93613 @@ -2190,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
93614 */
93615
93616 /* Somebody else might have raced and expanded it already */
93617 - if (address < vma->vm_start) {
93618 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93619 + error = -ENOMEM;
93620 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93621 unsigned long size, grow;
93622
93623 +#ifdef CONFIG_PAX_SEGMEXEC
93624 + struct vm_area_struct *vma_m;
93625 +
93626 + vma_m = pax_find_mirror_vma(vma);
93627 +#endif
93628 +
93629 size = vma->vm_end - address;
93630 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93631
93632 @@ -2217,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
93633 vma->vm_pgoff -= grow;
93634 anon_vma_interval_tree_post_update_vma(vma);
93635 vma_gap_update(vma);
93636 +
93637 +#ifdef CONFIG_PAX_SEGMEXEC
93638 + if (vma_m) {
93639 + anon_vma_interval_tree_pre_update_vma(vma_m);
93640 + vma_m->vm_start -= grow << PAGE_SHIFT;
93641 + vma_m->vm_pgoff -= grow;
93642 + anon_vma_interval_tree_post_update_vma(vma_m);
93643 + vma_gap_update(vma_m);
93644 + }
93645 +#endif
93646 +
93647 spin_unlock(&vma->vm_mm->page_table_lock);
93648
93649 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93650 perf_event_mmap(vma);
93651 }
93652 }
93653 }
93654 vma_unlock_anon_vma(vma);
93655 + if (lockprev)
93656 + vma_unlock_anon_vma(prev);
93657 khugepaged_enter_vma_merge(vma);
93658 validate_mm(vma->vm_mm);
93659 return error;
93660 @@ -2321,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93661 do {
93662 long nrpages = vma_pages(vma);
93663
93664 +#ifdef CONFIG_PAX_SEGMEXEC
93665 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93666 + vma = remove_vma(vma);
93667 + continue;
93668 + }
93669 +#endif
93670 +
93671 if (vma->vm_flags & VM_ACCOUNT)
93672 nr_accounted += nrpages;
93673 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93674 @@ -2365,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93675 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93676 vma->vm_prev = NULL;
93677 do {
93678 +
93679 +#ifdef CONFIG_PAX_SEGMEXEC
93680 + if (vma->vm_mirror) {
93681 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93682 + vma->vm_mirror->vm_mirror = NULL;
93683 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
93684 + vma->vm_mirror = NULL;
93685 + }
93686 +#endif
93687 +
93688 vma_rb_erase(vma, &mm->mm_rb);
93689 mm->map_count--;
93690 tail_vma = vma;
93691 @@ -2390,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93692 struct vm_area_struct *new;
93693 int err = -ENOMEM;
93694
93695 +#ifdef CONFIG_PAX_SEGMEXEC
93696 + struct vm_area_struct *vma_m, *new_m = NULL;
93697 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93698 +#endif
93699 +
93700 if (is_vm_hugetlb_page(vma) && (addr &
93701 ~(huge_page_mask(hstate_vma(vma)))))
93702 return -EINVAL;
93703
93704 +#ifdef CONFIG_PAX_SEGMEXEC
93705 + vma_m = pax_find_mirror_vma(vma);
93706 +#endif
93707 +
93708 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93709 if (!new)
93710 goto out_err;
93711
93712 +#ifdef CONFIG_PAX_SEGMEXEC
93713 + if (vma_m) {
93714 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93715 + if (!new_m) {
93716 + kmem_cache_free(vm_area_cachep, new);
93717 + goto out_err;
93718 + }
93719 + }
93720 +#endif
93721 +
93722 /* most fields are the same, copy all, and then fixup */
93723 *new = *vma;
93724
93725 @@ -2410,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93726 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93727 }
93728
93729 +#ifdef CONFIG_PAX_SEGMEXEC
93730 + if (vma_m) {
93731 + *new_m = *vma_m;
93732 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
93733 + new_m->vm_mirror = new;
93734 + new->vm_mirror = new_m;
93735 +
93736 + if (new_below)
93737 + new_m->vm_end = addr_m;
93738 + else {
93739 + new_m->vm_start = addr_m;
93740 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93741 + }
93742 + }
93743 +#endif
93744 +
93745 err = vma_dup_policy(vma, new);
93746 if (err)
93747 goto out_free_vma;
93748 @@ -2429,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93749 else
93750 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93751
93752 +#ifdef CONFIG_PAX_SEGMEXEC
93753 + if (!err && vma_m) {
93754 + struct mempolicy *pol = vma_policy(new);
93755 +
93756 + if (anon_vma_clone(new_m, vma_m))
93757 + goto out_free_mpol;
93758 +
93759 + mpol_get(pol);
93760 + set_vma_policy(new_m, pol);
93761 +
93762 + if (new_m->vm_file)
93763 + get_file(new_m->vm_file);
93764 +
93765 + if (new_m->vm_ops && new_m->vm_ops->open)
93766 + new_m->vm_ops->open(new_m);
93767 +
93768 + if (new_below)
93769 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93770 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93771 + else
93772 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93773 +
93774 + if (err) {
93775 + if (new_m->vm_ops && new_m->vm_ops->close)
93776 + new_m->vm_ops->close(new_m);
93777 + if (new_m->vm_file)
93778 + fput(new_m->vm_file);
93779 + mpol_put(pol);
93780 + }
93781 + }
93782 +#endif
93783 +
93784 /* Success. */
93785 if (!err)
93786 return 0;
93787 @@ -2438,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93788 new->vm_ops->close(new);
93789 if (new->vm_file)
93790 fput(new->vm_file);
93791 - unlink_anon_vmas(new);
93792 out_free_mpol:
93793 mpol_put(vma_policy(new));
93794 out_free_vma:
93795 +
93796 +#ifdef CONFIG_PAX_SEGMEXEC
93797 + if (new_m) {
93798 + unlink_anon_vmas(new_m);
93799 + kmem_cache_free(vm_area_cachep, new_m);
93800 + }
93801 +#endif
93802 +
93803 + unlink_anon_vmas(new);
93804 kmem_cache_free(vm_area_cachep, new);
93805 out_err:
93806 return err;
93807 @@ -2454,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93808 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93809 unsigned long addr, int new_below)
93810 {
93811 +
93812 +#ifdef CONFIG_PAX_SEGMEXEC
93813 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93814 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93815 + if (mm->map_count >= sysctl_max_map_count-1)
93816 + return -ENOMEM;
93817 + } else
93818 +#endif
93819 +
93820 if (mm->map_count >= sysctl_max_map_count)
93821 return -ENOMEM;
93822
93823 @@ -2465,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93824 * work. This now handles partial unmappings.
93825 * Jeremy Fitzhardinge <jeremy@goop.org>
93826 */
93827 +#ifdef CONFIG_PAX_SEGMEXEC
93828 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93829 {
93830 + int ret = __do_munmap(mm, start, len);
93831 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
93832 + return ret;
93833 +
93834 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
93835 +}
93836 +
93837 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93838 +#else
93839 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93840 +#endif
93841 +{
93842 unsigned long end;
93843 struct vm_area_struct *vma, *prev, *last;
93844
93845 + /*
93846 + * mm->mmap_sem is required to protect against another thread
93847 + * changing the mappings in case we sleep.
93848 + */
93849 + verify_mm_writelocked(mm);
93850 +
93851 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
93852 return -EINVAL;
93853
93854 @@ -2544,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93855 /* Fix up all other VM information */
93856 remove_vma_list(mm, vma);
93857
93858 + track_exec_limit(mm, start, end, 0UL);
93859 +
93860 return 0;
93861 }
93862
93863 @@ -2552,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
93864 int ret;
93865 struct mm_struct *mm = current->mm;
93866
93867 +
93868 +#ifdef CONFIG_PAX_SEGMEXEC
93869 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
93870 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
93871 + return -EINVAL;
93872 +#endif
93873 +
93874 down_write(&mm->mmap_sem);
93875 ret = do_munmap(mm, start, len);
93876 up_write(&mm->mmap_sem);
93877 @@ -2565,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
93878 return vm_munmap(addr, len);
93879 }
93880
93881 -static inline void verify_mm_writelocked(struct mm_struct *mm)
93882 -{
93883 -#ifdef CONFIG_DEBUG_VM
93884 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93885 - WARN_ON(1);
93886 - up_read(&mm->mmap_sem);
93887 - }
93888 -#endif
93889 -}
93890 -
93891 /*
93892 * this is really a simplified "do_mmap". it only handles
93893 * anonymous maps. eventually we may be able to do some
93894 @@ -2588,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93895 struct rb_node ** rb_link, * rb_parent;
93896 pgoff_t pgoff = addr >> PAGE_SHIFT;
93897 int error;
93898 + unsigned long charged;
93899
93900 len = PAGE_ALIGN(len);
93901 if (!len)
93902 @@ -2595,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93903
93904 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
93905
93906 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
93907 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
93908 + flags &= ~VM_EXEC;
93909 +
93910 +#ifdef CONFIG_PAX_MPROTECT
93911 + if (mm->pax_flags & MF_PAX_MPROTECT)
93912 + flags &= ~VM_MAYEXEC;
93913 +#endif
93914 +
93915 + }
93916 +#endif
93917 +
93918 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
93919 if (error & ~PAGE_MASK)
93920 return error;
93921
93922 + charged = len >> PAGE_SHIFT;
93923 +
93924 /*
93925 * mlock MCL_FUTURE?
93926 */
93927 if (mm->def_flags & VM_LOCKED) {
93928 unsigned long locked, lock_limit;
93929 - locked = len >> PAGE_SHIFT;
93930 + locked = charged;
93931 locked += mm->locked_vm;
93932 lock_limit = rlimit(RLIMIT_MEMLOCK);
93933 lock_limit >>= PAGE_SHIFT;
93934 @@ -2621,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93935 /*
93936 * Clear old maps. this also does some error checking for us
93937 */
93938 - munmap_back:
93939 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93940 if (do_munmap(mm, addr, len))
93941 return -ENOMEM;
93942 - goto munmap_back;
93943 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93944 }
93945
93946 /* Check against address space limits *after* clearing old maps... */
93947 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
93948 + if (!may_expand_vm(mm, charged))
93949 return -ENOMEM;
93950
93951 if (mm->map_count > sysctl_max_map_count)
93952 return -ENOMEM;
93953
93954 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
93955 + if (security_vm_enough_memory_mm(mm, charged))
93956 return -ENOMEM;
93957
93958 /* Can we just expand an old private anonymous mapping? */
93959 @@ -2649,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93960 */
93961 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93962 if (!vma) {
93963 - vm_unacct_memory(len >> PAGE_SHIFT);
93964 + vm_unacct_memory(charged);
93965 return -ENOMEM;
93966 }
93967
93968 @@ -2663,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93969 vma_link(mm, vma, prev, rb_link, rb_parent);
93970 out:
93971 perf_event_mmap(vma);
93972 - mm->total_vm += len >> PAGE_SHIFT;
93973 + mm->total_vm += charged;
93974 if (flags & VM_LOCKED)
93975 - mm->locked_vm += (len >> PAGE_SHIFT);
93976 + mm->locked_vm += charged;
93977 vma->vm_flags |= VM_SOFTDIRTY;
93978 + track_exec_limit(mm, addr, addr + len, flags);
93979 return addr;
93980 }
93981
93982 @@ -2728,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
93983 while (vma) {
93984 if (vma->vm_flags & VM_ACCOUNT)
93985 nr_accounted += vma_pages(vma);
93986 + vma->vm_mirror = NULL;
93987 vma = remove_vma(vma);
93988 }
93989 vm_unacct_memory(nr_accounted);
93990 @@ -2745,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93991 struct vm_area_struct *prev;
93992 struct rb_node **rb_link, *rb_parent;
93993
93994 +#ifdef CONFIG_PAX_SEGMEXEC
93995 + struct vm_area_struct *vma_m = NULL;
93996 +#endif
93997 +
93998 + if (security_mmap_addr(vma->vm_start))
93999 + return -EPERM;
94000 +
94001 /*
94002 * The vm_pgoff of a purely anonymous vma should be irrelevant
94003 * until its first write fault, when page's anon_vma and index
94004 @@ -2768,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94005 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94006 return -ENOMEM;
94007
94008 +#ifdef CONFIG_PAX_SEGMEXEC
94009 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94010 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94011 + if (!vma_m)
94012 + return -ENOMEM;
94013 + }
94014 +#endif
94015 +
94016 vma_link(mm, vma, prev, rb_link, rb_parent);
94017 +
94018 +#ifdef CONFIG_PAX_SEGMEXEC
94019 + if (vma_m)
94020 + BUG_ON(pax_mirror_vma(vma_m, vma));
94021 +#endif
94022 +
94023 return 0;
94024 }
94025
94026 @@ -2787,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94027 struct rb_node **rb_link, *rb_parent;
94028 bool faulted_in_anon_vma = true;
94029
94030 + BUG_ON(vma->vm_mirror);
94031 +
94032 /*
94033 * If anonymous vma has not yet been faulted, update new pgoff
94034 * to match new location, to increase its chance of merging.
94035 @@ -2851,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94036 return NULL;
94037 }
94038
94039 +#ifdef CONFIG_PAX_SEGMEXEC
94040 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94041 +{
94042 + struct vm_area_struct *prev_m;
94043 + struct rb_node **rb_link_m, *rb_parent_m;
94044 + struct mempolicy *pol_m;
94045 +
94046 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94047 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94048 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94049 + *vma_m = *vma;
94050 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94051 + if (anon_vma_clone(vma_m, vma))
94052 + return -ENOMEM;
94053 + pol_m = vma_policy(vma_m);
94054 + mpol_get(pol_m);
94055 + set_vma_policy(vma_m, pol_m);
94056 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94057 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94058 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94059 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94060 + if (vma_m->vm_file)
94061 + get_file(vma_m->vm_file);
94062 + if (vma_m->vm_ops && vma_m->vm_ops->open)
94063 + vma_m->vm_ops->open(vma_m);
94064 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94065 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94066 + vma_m->vm_mirror = vma;
94067 + vma->vm_mirror = vma_m;
94068 + return 0;
94069 +}
94070 +#endif
94071 +
94072 /*
94073 * Return true if the calling process may expand its vm space by the passed
94074 * number of pages
94075 @@ -2862,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94076
94077 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94078
94079 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94080 if (cur + npages > lim)
94081 return 0;
94082 return 1;
94083 @@ -2932,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
94084 vma->vm_start = addr;
94085 vma->vm_end = addr + len;
94086
94087 +#ifdef CONFIG_PAX_MPROTECT
94088 + if (mm->pax_flags & MF_PAX_MPROTECT) {
94089 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
94090 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94091 + return -EPERM;
94092 + if (!(vm_flags & VM_EXEC))
94093 + vm_flags &= ~VM_MAYEXEC;
94094 +#else
94095 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94096 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94097 +#endif
94098 + else
94099 + vm_flags &= ~VM_MAYWRITE;
94100 + }
94101 +#endif
94102 +
94103 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94104 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94105
94106 diff --git a/mm/mprotect.c b/mm/mprotect.c
94107 index bb53a65..249c052 100644
94108 --- a/mm/mprotect.c
94109 +++ b/mm/mprotect.c
94110 @@ -23,10 +23,18 @@
94111 #include <linux/mmu_notifier.h>
94112 #include <linux/migrate.h>
94113 #include <linux/perf_event.h>
94114 +#include <linux/sched/sysctl.h>
94115 +
94116 +#ifdef CONFIG_PAX_MPROTECT
94117 +#include <linux/elf.h>
94118 +#include <linux/binfmts.h>
94119 +#endif
94120 +
94121 #include <asm/uaccess.h>
94122 #include <asm/pgtable.h>
94123 #include <asm/cacheflush.h>
94124 #include <asm/tlbflush.h>
94125 +#include <asm/mmu_context.h>
94126
94127 #ifndef pgprot_modify
94128 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94129 @@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94130 return pages;
94131 }
94132
94133 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94134 +/* called while holding the mmap semaphor for writing except stack expansion */
94135 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94136 +{
94137 + unsigned long oldlimit, newlimit = 0UL;
94138 +
94139 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94140 + return;
94141 +
94142 + spin_lock(&mm->page_table_lock);
94143 + oldlimit = mm->context.user_cs_limit;
94144 + if ((prot & VM_EXEC) && oldlimit < end)
94145 + /* USER_CS limit moved up */
94146 + newlimit = end;
94147 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94148 + /* USER_CS limit moved down */
94149 + newlimit = start;
94150 +
94151 + if (newlimit) {
94152 + mm->context.user_cs_limit = newlimit;
94153 +
94154 +#ifdef CONFIG_SMP
94155 + wmb();
94156 + cpus_clear(mm->context.cpu_user_cs_mask);
94157 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94158 +#endif
94159 +
94160 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94161 + }
94162 + spin_unlock(&mm->page_table_lock);
94163 + if (newlimit == end) {
94164 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
94165 +
94166 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
94167 + if (is_vm_hugetlb_page(vma))
94168 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94169 + else
94170 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94171 + }
94172 +}
94173 +#endif
94174 +
94175 int
94176 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94177 unsigned long start, unsigned long end, unsigned long newflags)
94178 @@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94179 int error;
94180 int dirty_accountable = 0;
94181
94182 +#ifdef CONFIG_PAX_SEGMEXEC
94183 + struct vm_area_struct *vma_m = NULL;
94184 + unsigned long start_m, end_m;
94185 +
94186 + start_m = start + SEGMEXEC_TASK_SIZE;
94187 + end_m = end + SEGMEXEC_TASK_SIZE;
94188 +#endif
94189 +
94190 if (newflags == oldflags) {
94191 *pprev = vma;
94192 return 0;
94193 }
94194
94195 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94196 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94197 +
94198 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94199 + return -ENOMEM;
94200 +
94201 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94202 + return -ENOMEM;
94203 + }
94204 +
94205 /*
94206 * If we make a private mapping writable we increase our commit;
94207 * but (without finer accounting) cannot reduce our commit if we
94208 @@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94209 }
94210 }
94211
94212 +#ifdef CONFIG_PAX_SEGMEXEC
94213 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94214 + if (start != vma->vm_start) {
94215 + error = split_vma(mm, vma, start, 1);
94216 + if (error)
94217 + goto fail;
94218 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94219 + *pprev = (*pprev)->vm_next;
94220 + }
94221 +
94222 + if (end != vma->vm_end) {
94223 + error = split_vma(mm, vma, end, 0);
94224 + if (error)
94225 + goto fail;
94226 + }
94227 +
94228 + if (pax_find_mirror_vma(vma)) {
94229 + error = __do_munmap(mm, start_m, end_m - start_m);
94230 + if (error)
94231 + goto fail;
94232 + } else {
94233 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94234 + if (!vma_m) {
94235 + error = -ENOMEM;
94236 + goto fail;
94237 + }
94238 + vma->vm_flags = newflags;
94239 + error = pax_mirror_vma(vma_m, vma);
94240 + if (error) {
94241 + vma->vm_flags = oldflags;
94242 + goto fail;
94243 + }
94244 + }
94245 + }
94246 +#endif
94247 +
94248 /*
94249 * First try to merge with previous and/or next vma.
94250 */
94251 @@ -285,9 +389,21 @@ success:
94252 * vm_flags and vm_page_prot are protected by the mmap_sem
94253 * held in write mode.
94254 */
94255 +
94256 +#ifdef CONFIG_PAX_SEGMEXEC
94257 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94258 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94259 +#endif
94260 +
94261 vma->vm_flags = newflags;
94262 +
94263 +#ifdef CONFIG_PAX_MPROTECT
94264 + if (mm->binfmt && mm->binfmt->handle_mprotect)
94265 + mm->binfmt->handle_mprotect(vma, newflags);
94266 +#endif
94267 +
94268 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94269 - vm_get_page_prot(newflags));
94270 + vm_get_page_prot(vma->vm_flags));
94271
94272 if (vma_wants_writenotify(vma)) {
94273 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94274 @@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94275 end = start + len;
94276 if (end <= start)
94277 return -ENOMEM;
94278 +
94279 +#ifdef CONFIG_PAX_SEGMEXEC
94280 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94281 + if (end > SEGMEXEC_TASK_SIZE)
94282 + return -EINVAL;
94283 + } else
94284 +#endif
94285 +
94286 + if (end > TASK_SIZE)
94287 + return -EINVAL;
94288 +
94289 if (!arch_validate_prot(prot))
94290 return -EINVAL;
94291
94292 @@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94293 /*
94294 * Does the application expect PROT_READ to imply PROT_EXEC:
94295 */
94296 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94297 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94298 prot |= PROT_EXEC;
94299
94300 vm_flags = calc_vm_prot_bits(prot);
94301 @@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94302 if (start > vma->vm_start)
94303 prev = vma;
94304
94305 +#ifdef CONFIG_PAX_MPROTECT
94306 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94307 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
94308 +#endif
94309 +
94310 for (nstart = start ; ; ) {
94311 unsigned long newflags;
94312
94313 @@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94314
94315 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94316 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94317 + if (prot & (PROT_WRITE | PROT_EXEC))
94318 + gr_log_rwxmprotect(vma);
94319 +
94320 + error = -EACCES;
94321 + goto out;
94322 + }
94323 +
94324 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94325 error = -EACCES;
94326 goto out;
94327 }
94328 @@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94329 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94330 if (error)
94331 goto out;
94332 +
94333 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
94334 +
94335 nstart = tmp;
94336
94337 if (nstart < prev->vm_end)
94338 diff --git a/mm/mremap.c b/mm/mremap.c
94339 index 0843feb..4f5b2e6 100644
94340 --- a/mm/mremap.c
94341 +++ b/mm/mremap.c
94342 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94343 continue;
94344 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94345 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94346 +
94347 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94348 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94349 + pte = pte_exprotect(pte);
94350 +#endif
94351 +
94352 pte = move_soft_dirty_pte(pte);
94353 set_pte_at(mm, new_addr, new_pte, pte);
94354 }
94355 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94356 if (is_vm_hugetlb_page(vma))
94357 goto Einval;
94358
94359 +#ifdef CONFIG_PAX_SEGMEXEC
94360 + if (pax_find_mirror_vma(vma))
94361 + goto Einval;
94362 +#endif
94363 +
94364 /* We can't remap across vm area boundaries */
94365 if (old_len > vma->vm_end - addr)
94366 goto Efault;
94367 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94368 unsigned long ret = -EINVAL;
94369 unsigned long charged = 0;
94370 unsigned long map_flags;
94371 + unsigned long pax_task_size = TASK_SIZE;
94372
94373 if (new_addr & ~PAGE_MASK)
94374 goto out;
94375
94376 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94377 +#ifdef CONFIG_PAX_SEGMEXEC
94378 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94379 + pax_task_size = SEGMEXEC_TASK_SIZE;
94380 +#endif
94381 +
94382 + pax_task_size -= PAGE_SIZE;
94383 +
94384 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94385 goto out;
94386
94387 /* Check if the location we're moving into overlaps the
94388 * old location at all, and fail if it does.
94389 */
94390 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
94391 - goto out;
94392 -
94393 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
94394 + if (addr + old_len > new_addr && new_addr + new_len > addr)
94395 goto out;
94396
94397 ret = do_munmap(mm, new_addr, new_len);
94398 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94399 unsigned long ret = -EINVAL;
94400 unsigned long charged = 0;
94401 bool locked = false;
94402 + unsigned long pax_task_size = TASK_SIZE;
94403
94404 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94405 return ret;
94406 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94407 if (!new_len)
94408 return ret;
94409
94410 +#ifdef CONFIG_PAX_SEGMEXEC
94411 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94412 + pax_task_size = SEGMEXEC_TASK_SIZE;
94413 +#endif
94414 +
94415 + pax_task_size -= PAGE_SIZE;
94416 +
94417 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94418 + old_len > pax_task_size || addr > pax_task_size-old_len)
94419 + return ret;
94420 +
94421 down_write(&current->mm->mmap_sem);
94422
94423 if (flags & MREMAP_FIXED) {
94424 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94425 new_addr = addr;
94426 }
94427 ret = addr;
94428 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94429 goto out;
94430 }
94431 }
94432 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94433 goto out;
94434 }
94435
94436 + map_flags = vma->vm_flags;
94437 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94438 + if (!(ret & ~PAGE_MASK)) {
94439 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94440 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94441 + }
94442 }
94443 out:
94444 if (ret & ~PAGE_MASK)
94445 diff --git a/mm/nommu.c b/mm/nommu.c
94446 index fec093a..8162f74 100644
94447 --- a/mm/nommu.c
94448 +++ b/mm/nommu.c
94449 @@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94450 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94451 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94452 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94453 -int heap_stack_gap = 0;
94454
94455 atomic_long_t mmap_pages_allocated;
94456
94457 @@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94458 EXPORT_SYMBOL(find_vma);
94459
94460 /*
94461 - * find a VMA
94462 - * - we don't extend stack VMAs under NOMMU conditions
94463 - */
94464 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94465 -{
94466 - return find_vma(mm, addr);
94467 -}
94468 -
94469 -/*
94470 * expand a stack to a given address
94471 * - not supported under NOMMU conditions
94472 */
94473 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94474
94475 /* most fields are the same, copy all, and then fixup */
94476 *new = *vma;
94477 + INIT_LIST_HEAD(&new->anon_vma_chain);
94478 *region = *vma->vm_region;
94479 new->vm_region = region;
94480
94481 @@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94482 }
94483 EXPORT_SYMBOL(generic_file_remap_pages);
94484
94485 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94486 - unsigned long addr, void *buf, int len, int write)
94487 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94488 + unsigned long addr, void *buf, size_t len, int write)
94489 {
94490 struct vm_area_struct *vma;
94491
94492 @@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94493 *
94494 * The caller must hold a reference on @mm.
94495 */
94496 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94497 - void *buf, int len, int write)
94498 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94499 + void *buf, size_t len, int write)
94500 {
94501 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94502 }
94503 @@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94504 * Access another process' address space.
94505 * - source/target buffer must be kernel space
94506 */
94507 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94508 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94509 {
94510 struct mm_struct *mm;
94511
94512 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94513 index 7106cb1..0805f48 100644
94514 --- a/mm/page-writeback.c
94515 +++ b/mm/page-writeback.c
94516 @@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94517 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94518 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94519 */
94520 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94521 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94522 unsigned long thresh,
94523 unsigned long bg_thresh,
94524 unsigned long dirty,
94525 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94526 index 589521d..314053a 100644
94527 --- a/mm/page_alloc.c
94528 +++ b/mm/page_alloc.c
94529 @@ -61,6 +61,7 @@
94530 #include <linux/page-debug-flags.h>
94531 #include <linux/hugetlb.h>
94532 #include <linux/sched/rt.h>
94533 +#include <linux/random.h>
94534
94535 #include <asm/sections.h>
94536 #include <asm/tlbflush.h>
94537 @@ -354,7 +355,7 @@ out:
94538 * This usage means that zero-order pages may not be compound.
94539 */
94540
94541 -static void free_compound_page(struct page *page)
94542 +void free_compound_page(struct page *page)
94543 {
94544 __free_pages_ok(page, compound_order(page));
94545 }
94546 @@ -714,6 +715,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94547 int i;
94548 int bad = 0;
94549
94550 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94551 + unsigned long index = 1UL << order;
94552 +#endif
94553 +
94554 trace_mm_page_free(page, order);
94555 kmemcheck_free_shadow(page, order);
94556
94557 @@ -730,6 +735,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94558 debug_check_no_obj_freed(page_address(page),
94559 PAGE_SIZE << order);
94560 }
94561 +
94562 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94563 + for (; index; --index)
94564 + sanitize_highpage(page + index - 1);
94565 +#endif
94566 +
94567 arch_free_page(page, order);
94568 kernel_map_pages(page, 1 << order, 0);
94569
94570 @@ -752,6 +763,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94571 local_irq_restore(flags);
94572 }
94573
94574 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94575 +bool __meminitdata extra_latent_entropy;
94576 +
94577 +static int __init setup_pax_extra_latent_entropy(char *str)
94578 +{
94579 + extra_latent_entropy = true;
94580 + return 0;
94581 +}
94582 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94583 +
94584 +volatile u64 latent_entropy __latent_entropy;
94585 +EXPORT_SYMBOL(latent_entropy);
94586 +#endif
94587 +
94588 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94589 {
94590 unsigned int nr_pages = 1 << order;
94591 @@ -767,6 +792,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94592 __ClearPageReserved(p);
94593 set_page_count(p, 0);
94594
94595 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94596 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94597 + u64 hash = 0;
94598 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94599 + const u64 *data = lowmem_page_address(page);
94600 +
94601 + for (index = 0; index < end; index++)
94602 + hash ^= hash + data[index];
94603 + latent_entropy ^= hash;
94604 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94605 + }
94606 +#endif
94607 +
94608 page_zone(page)->managed_pages += nr_pages;
94609 set_page_refcounted(page);
94610 __free_pages(page, order);
94611 @@ -872,8 +910,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94612 arch_alloc_page(page, order);
94613 kernel_map_pages(page, 1 << order, 1);
94614
94615 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
94616 if (gfp_flags & __GFP_ZERO)
94617 prep_zero_page(page, order, gfp_flags);
94618 +#endif
94619
94620 if (order && (gfp_flags & __GFP_COMP))
94621 prep_compound_page(page, order);
94622 diff --git a/mm/page_io.c b/mm/page_io.c
94623 index 8c79a47..a689e0d 100644
94624 --- a/mm/page_io.c
94625 +++ b/mm/page_io.c
94626 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94627 struct file *swap_file = sis->swap_file;
94628 struct address_space *mapping = swap_file->f_mapping;
94629 struct iovec iov = {
94630 - .iov_base = kmap(page),
94631 + .iov_base = (void __force_user *)kmap(page),
94632 .iov_len = PAGE_SIZE,
94633 };
94634
94635 diff --git a/mm/percpu.c b/mm/percpu.c
94636 index 0d10def..6dc822d 100644
94637 --- a/mm/percpu.c
94638 +++ b/mm/percpu.c
94639 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94640 static unsigned int pcpu_high_unit_cpu __read_mostly;
94641
94642 /* the address of the first chunk which starts with the kernel static area */
94643 -void *pcpu_base_addr __read_mostly;
94644 +void *pcpu_base_addr __read_only;
94645 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94646
94647 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94648 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94649 index fd26d04..0cea1b0 100644
94650 --- a/mm/process_vm_access.c
94651 +++ b/mm/process_vm_access.c
94652 @@ -13,6 +13,7 @@
94653 #include <linux/uio.h>
94654 #include <linux/sched.h>
94655 #include <linux/highmem.h>
94656 +#include <linux/security.h>
94657 #include <linux/ptrace.h>
94658 #include <linux/slab.h>
94659 #include <linux/syscalls.h>
94660 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94661 size_t iov_l_curr_offset = 0;
94662 ssize_t iov_len;
94663
94664 + return -ENOSYS; // PaX: until properly audited
94665 +
94666 /*
94667 * Work out how many pages of struct pages we're going to need
94668 * when eventually calling get_user_pages
94669 */
94670 for (i = 0; i < riovcnt; i++) {
94671 iov_len = rvec[i].iov_len;
94672 - if (iov_len > 0) {
94673 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
94674 - + iov_len)
94675 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94676 - / PAGE_SIZE + 1;
94677 - nr_pages = max(nr_pages, nr_pages_iov);
94678 - }
94679 + if (iov_len <= 0)
94680 + continue;
94681 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94682 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94683 + nr_pages = max(nr_pages, nr_pages_iov);
94684 }
94685
94686 if (nr_pages == 0)
94687 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94688 goto free_proc_pages;
94689 }
94690
94691 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94692 + rc = -EPERM;
94693 + goto put_task_struct;
94694 + }
94695 +
94696 mm = mm_access(task, PTRACE_MODE_ATTACH);
94697 if (!mm || IS_ERR(mm)) {
94698 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94699 diff --git a/mm/rmap.c b/mm/rmap.c
94700 index 068522d..f539f21 100644
94701 --- a/mm/rmap.c
94702 +++ b/mm/rmap.c
94703 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94704 struct anon_vma *anon_vma = vma->anon_vma;
94705 struct anon_vma_chain *avc;
94706
94707 +#ifdef CONFIG_PAX_SEGMEXEC
94708 + struct anon_vma_chain *avc_m = NULL;
94709 +#endif
94710 +
94711 might_sleep();
94712 if (unlikely(!anon_vma)) {
94713 struct mm_struct *mm = vma->vm_mm;
94714 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94715 if (!avc)
94716 goto out_enomem;
94717
94718 +#ifdef CONFIG_PAX_SEGMEXEC
94719 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94720 + if (!avc_m)
94721 + goto out_enomem_free_avc;
94722 +#endif
94723 +
94724 anon_vma = find_mergeable_anon_vma(vma);
94725 allocated = NULL;
94726 if (!anon_vma) {
94727 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94728 /* page_table_lock to protect against threads */
94729 spin_lock(&mm->page_table_lock);
94730 if (likely(!vma->anon_vma)) {
94731 +
94732 +#ifdef CONFIG_PAX_SEGMEXEC
94733 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94734 +
94735 + if (vma_m) {
94736 + BUG_ON(vma_m->anon_vma);
94737 + vma_m->anon_vma = anon_vma;
94738 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
94739 + avc_m = NULL;
94740 + }
94741 +#endif
94742 +
94743 vma->anon_vma = anon_vma;
94744 anon_vma_chain_link(vma, avc, anon_vma);
94745 allocated = NULL;
94746 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94747
94748 if (unlikely(allocated))
94749 put_anon_vma(allocated);
94750 +
94751 +#ifdef CONFIG_PAX_SEGMEXEC
94752 + if (unlikely(avc_m))
94753 + anon_vma_chain_free(avc_m);
94754 +#endif
94755 +
94756 if (unlikely(avc))
94757 anon_vma_chain_free(avc);
94758 }
94759 return 0;
94760
94761 out_enomem_free_avc:
94762 +
94763 +#ifdef CONFIG_PAX_SEGMEXEC
94764 + if (avc_m)
94765 + anon_vma_chain_free(avc_m);
94766 +#endif
94767 +
94768 anon_vma_chain_free(avc);
94769 out_enomem:
94770 return -ENOMEM;
94771 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94772 * Attach the anon_vmas from src to dst.
94773 * Returns 0 on success, -ENOMEM on failure.
94774 */
94775 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94776 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94777 {
94778 struct anon_vma_chain *avc, *pavc;
94779 struct anon_vma *root = NULL;
94780 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94781 * the corresponding VMA in the parent process is attached to.
94782 * Returns 0 on success, non-zero on failure.
94783 */
94784 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94785 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94786 {
94787 struct anon_vma_chain *avc;
94788 struct anon_vma *anon_vma;
94789 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94790 void __init anon_vma_init(void)
94791 {
94792 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94793 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94794 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94795 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94796 + anon_vma_ctor);
94797 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94798 + SLAB_PANIC|SLAB_NO_SANITIZE);
94799 }
94800
94801 /*
94802 diff --git a/mm/shmem.c b/mm/shmem.c
94803 index 902a148..58f9d59 100644
94804 --- a/mm/shmem.c
94805 +++ b/mm/shmem.c
94806 @@ -33,7 +33,7 @@
94807 #include <linux/swap.h>
94808 #include <linux/aio.h>
94809
94810 -static struct vfsmount *shm_mnt;
94811 +struct vfsmount *shm_mnt;
94812
94813 #ifdef CONFIG_SHMEM
94814 /*
94815 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94816 #define BOGO_DIRENT_SIZE 20
94817
94818 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94819 -#define SHORT_SYMLINK_LEN 128
94820 +#define SHORT_SYMLINK_LEN 64
94821
94822 /*
94823 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94824 @@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94825 static int shmem_xattr_validate(const char *name)
94826 {
94827 struct { const char *prefix; size_t len; } arr[] = {
94828 +
94829 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94830 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
94831 +#endif
94832 +
94833 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
94834 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
94835 };
94836 @@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
94837 if (err)
94838 return err;
94839
94840 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94841 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
94842 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
94843 + return -EOPNOTSUPP;
94844 + if (size > 8)
94845 + return -EINVAL;
94846 + }
94847 +#endif
94848 +
94849 return simple_xattr_set(&info->xattrs, name, value, size, flags);
94850 }
94851
94852 @@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
94853 int err = -ENOMEM;
94854
94855 /* Round up to L1_CACHE_BYTES to resist false sharing */
94856 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
94857 - L1_CACHE_BYTES), GFP_KERNEL);
94858 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
94859 if (!sbinfo)
94860 return -ENOMEM;
94861
94862 diff --git a/mm/slab.c b/mm/slab.c
94863 index eb043bf..d82f5a8 100644
94864 --- a/mm/slab.c
94865 +++ b/mm/slab.c
94866 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94867 if ((x)->max_freeable < i) \
94868 (x)->max_freeable = i; \
94869 } while (0)
94870 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
94871 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
94872 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
94873 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
94874 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
94875 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
94876 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
94877 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
94878 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
94879 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
94880 #else
94881 #define STATS_INC_ACTIVE(x) do { } while (0)
94882 #define STATS_DEC_ACTIVE(x) do { } while (0)
94883 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94884 #define STATS_INC_ALLOCMISS(x) do { } while (0)
94885 #define STATS_INC_FREEHIT(x) do { } while (0)
94886 #define STATS_INC_FREEMISS(x) do { } while (0)
94887 +#define STATS_INC_SANITIZED(x) do { } while (0)
94888 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
94889 #endif
94890
94891 #if DEBUG
94892 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
94893 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
94894 */
94895 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
94896 - const struct page *page, void *obj)
94897 + const struct page *page, const void *obj)
94898 {
94899 u32 offset = (obj - page->s_mem);
94900 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
94901 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
94902 */
94903
94904 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
94905 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
94906 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94907
94908 if (INDEX_AC != INDEX_NODE)
94909 kmalloc_caches[INDEX_NODE] =
94910 create_kmalloc_cache("kmalloc-node",
94911 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
94912 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94913
94914 slab_early_init = 0;
94915
94916 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
94917 struct array_cache *ac = cpu_cache_get(cachep);
94918
94919 check_irq_off();
94920 +
94921 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94922 + if (pax_sanitize_slab) {
94923 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
94924 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
94925 +
94926 + if (cachep->ctor)
94927 + cachep->ctor(objp);
94928 +
94929 + STATS_INC_SANITIZED(cachep);
94930 + } else
94931 + STATS_INC_NOT_SANITIZED(cachep);
94932 + }
94933 +#endif
94934 +
94935 kmemleak_free_recursive(objp, cachep->flags);
94936 objp = cache_free_debugcheck(cachep, objp, caller);
94937
94938 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
94939
94940 if (unlikely(ZERO_OR_NULL_PTR(objp)))
94941 return;
94942 + VM_BUG_ON(!virt_addr_valid(objp));
94943 local_irq_save(flags);
94944 kfree_debugcheck(objp);
94945 c = virt_to_cache(objp);
94946 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
94947 }
94948 /* cpu stats */
94949 {
94950 - unsigned long allochit = atomic_read(&cachep->allochit);
94951 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
94952 - unsigned long freehit = atomic_read(&cachep->freehit);
94953 - unsigned long freemiss = atomic_read(&cachep->freemiss);
94954 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
94955 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
94956 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
94957 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
94958
94959 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
94960 allochit, allocmiss, freehit, freemiss);
94961 }
94962 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94963 + {
94964 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
94965 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
94966 +
94967 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
94968 + }
94969 +#endif
94970 #endif
94971 }
94972
94973 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
94974 static int __init slab_proc_init(void)
94975 {
94976 #ifdef CONFIG_DEBUG_SLAB_LEAK
94977 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
94978 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
94979 #endif
94980 return 0;
94981 }
94982 module_init(slab_proc_init);
94983 #endif
94984
94985 +bool is_usercopy_object(const void *ptr)
94986 +{
94987 + struct page *page;
94988 + struct kmem_cache *cachep;
94989 +
94990 + if (ZERO_OR_NULL_PTR(ptr))
94991 + return false;
94992 +
94993 + if (!slab_is_available())
94994 + return false;
94995 +
94996 + if (!virt_addr_valid(ptr))
94997 + return false;
94998 +
94999 + page = virt_to_head_page(ptr);
95000 +
95001 + if (!PageSlab(page))
95002 + return false;
95003 +
95004 + cachep = page->slab_cache;
95005 + return cachep->flags & SLAB_USERCOPY;
95006 +}
95007 +
95008 +#ifdef CONFIG_PAX_USERCOPY
95009 +const char *check_heap_object(const void *ptr, unsigned long n)
95010 +{
95011 + struct page *page;
95012 + struct kmem_cache *cachep;
95013 + unsigned int objnr;
95014 + unsigned long offset;
95015 +
95016 + if (ZERO_OR_NULL_PTR(ptr))
95017 + return "<null>";
95018 +
95019 + if (!virt_addr_valid(ptr))
95020 + return NULL;
95021 +
95022 + page = virt_to_head_page(ptr);
95023 +
95024 + if (!PageSlab(page))
95025 + return NULL;
95026 +
95027 + cachep = page->slab_cache;
95028 + if (!(cachep->flags & SLAB_USERCOPY))
95029 + return cachep->name;
95030 +
95031 + objnr = obj_to_index(cachep, page, ptr);
95032 + BUG_ON(objnr >= cachep->num);
95033 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95034 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95035 + return NULL;
95036 +
95037 + return cachep->name;
95038 +}
95039 +#endif
95040 +
95041 /**
95042 * ksize - get the actual amount of memory allocated for a given object
95043 * @objp: Pointer to the object
95044 diff --git a/mm/slab.h b/mm/slab.h
95045 index 0859c42..2f7b737 100644
95046 --- a/mm/slab.h
95047 +++ b/mm/slab.h
95048 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95049 /* The slab cache that manages slab cache information */
95050 extern struct kmem_cache *kmem_cache;
95051
95052 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95053 +#ifdef CONFIG_X86_64
95054 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95055 +#else
95056 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95057 +#endif
95058 +extern bool pax_sanitize_slab;
95059 +#endif
95060 +
95061 unsigned long calculate_alignment(unsigned long flags,
95062 unsigned long align, unsigned long size);
95063
95064 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95065
95066 /* Legal flag mask for kmem_cache_create(), for various configurations */
95067 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95068 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95069 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95070 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
95071
95072 #if defined(CONFIG_DEBUG_SLAB)
95073 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95074 @@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95075 return s;
95076
95077 page = virt_to_head_page(x);
95078 +
95079 + BUG_ON(!PageSlab(page));
95080 +
95081 cachep = page->slab_cache;
95082 if (slab_equal_or_root(cachep, s))
95083 return cachep;
95084 diff --git a/mm/slab_common.c b/mm/slab_common.c
95085 index 0b7bb39..334c328 100644
95086 --- a/mm/slab_common.c
95087 +++ b/mm/slab_common.c
95088 @@ -23,11 +23,22 @@
95089
95090 #include "slab.h"
95091
95092 -enum slab_state slab_state;
95093 +enum slab_state slab_state __read_only;
95094 LIST_HEAD(slab_caches);
95095 DEFINE_MUTEX(slab_mutex);
95096 struct kmem_cache *kmem_cache;
95097
95098 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95099 +bool pax_sanitize_slab __read_only = true;
95100 +static int __init pax_sanitize_slab_setup(char *str)
95101 +{
95102 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95103 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95104 + return 1;
95105 +}
95106 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95107 +#endif
95108 +
95109 #ifdef CONFIG_DEBUG_VM
95110 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
95111 size_t size)
95112 @@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
95113
95114 err = __kmem_cache_create(s, flags);
95115 if (!err) {
95116 - s->refcount = 1;
95117 + atomic_set(&s->refcount, 1);
95118 list_add(&s->list, &slab_caches);
95119 memcg_cache_list_add(memcg, s);
95120 } else {
95121 @@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95122
95123 get_online_cpus();
95124 mutex_lock(&slab_mutex);
95125 - s->refcount--;
95126 - if (!s->refcount) {
95127 + if (atomic_dec_and_test(&s->refcount)) {
95128 list_del(&s->list);
95129
95130 if (!__kmem_cache_shutdown(s)) {
95131 @@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95132 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95133 name, size, err);
95134
95135 - s->refcount = -1; /* Exempt from merging for now */
95136 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95137 }
95138
95139 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95140 @@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95141
95142 create_boot_cache(s, name, size, flags);
95143 list_add(&s->list, &slab_caches);
95144 - s->refcount = 1;
95145 + atomic_set(&s->refcount, 1);
95146 return s;
95147 }
95148
95149 @@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95150 EXPORT_SYMBOL(kmalloc_dma_caches);
95151 #endif
95152
95153 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95154 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95155 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
95156 +#endif
95157 +
95158 /*
95159 * Conversion table for small slabs sizes / 8 to the index in the
95160 * kmalloc array. This is necessary for slabs < 192 since we have non power
95161 @@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95162 return kmalloc_dma_caches[index];
95163
95164 #endif
95165 +
95166 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95167 + if (unlikely((flags & GFP_USERCOPY)))
95168 + return kmalloc_usercopy_caches[index];
95169 +
95170 +#endif
95171 +
95172 return kmalloc_caches[index];
95173 }
95174
95175 @@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95176 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95177 if (!kmalloc_caches[i]) {
95178 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95179 - 1 << i, flags);
95180 + 1 << i, SLAB_USERCOPY | flags);
95181 }
95182
95183 /*
95184 @@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95185 * earlier power of two caches
95186 */
95187 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95188 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95189 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95190
95191 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95192 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95193 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95194 }
95195
95196 /* Kmalloc array is now usable */
95197 @@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95198 }
95199 }
95200 #endif
95201 +
95202 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95203 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
95204 + struct kmem_cache *s = kmalloc_caches[i];
95205 +
95206 + if (s) {
95207 + int size = kmalloc_size(i);
95208 + char *n = kasprintf(GFP_NOWAIT,
95209 + "usercopy-kmalloc-%d", size);
95210 +
95211 + BUG_ON(!n);
95212 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
95213 + size, SLAB_USERCOPY | flags);
95214 + }
95215 + }
95216 +#endif
95217 +
95218 }
95219 #endif /* !CONFIG_SLOB */
95220
95221 @@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
95222 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95223 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95224 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95225 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95226 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
95227 +#endif
95228 #endif
95229 seq_putc(m, '\n');
95230 }
95231 diff --git a/mm/slob.c b/mm/slob.c
95232 index 4bf8809..98a6914 100644
95233 --- a/mm/slob.c
95234 +++ b/mm/slob.c
95235 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95236 /*
95237 * Return the size of a slob block.
95238 */
95239 -static slobidx_t slob_units(slob_t *s)
95240 +static slobidx_t slob_units(const slob_t *s)
95241 {
95242 if (s->units > 0)
95243 return s->units;
95244 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95245 /*
95246 * Return the next free slob block pointer after this one.
95247 */
95248 -static slob_t *slob_next(slob_t *s)
95249 +static slob_t *slob_next(const slob_t *s)
95250 {
95251 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95252 slobidx_t next;
95253 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95254 /*
95255 * Returns true if s is the last free block in its page.
95256 */
95257 -static int slob_last(slob_t *s)
95258 +static int slob_last(const slob_t *s)
95259 {
95260 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95261 }
95262
95263 -static void *slob_new_pages(gfp_t gfp, int order, int node)
95264 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95265 {
95266 - void *page;
95267 + struct page *page;
95268
95269 #ifdef CONFIG_NUMA
95270 if (node != NUMA_NO_NODE)
95271 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95272 if (!page)
95273 return NULL;
95274
95275 - return page_address(page);
95276 + __SetPageSlab(page);
95277 + return page;
95278 }
95279
95280 -static void slob_free_pages(void *b, int order)
95281 +static void slob_free_pages(struct page *sp, int order)
95282 {
95283 if (current->reclaim_state)
95284 current->reclaim_state->reclaimed_slab += 1 << order;
95285 - free_pages((unsigned long)b, order);
95286 + __ClearPageSlab(sp);
95287 + page_mapcount_reset(sp);
95288 + sp->private = 0;
95289 + __free_pages(sp, order);
95290 }
95291
95292 /*
95293 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95294
95295 /* Not enough space: must allocate a new page */
95296 if (!b) {
95297 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95298 - if (!b)
95299 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95300 + if (!sp)
95301 return NULL;
95302 - sp = virt_to_page(b);
95303 - __SetPageSlab(sp);
95304 + b = page_address(sp);
95305
95306 spin_lock_irqsave(&slob_lock, flags);
95307 sp->units = SLOB_UNITS(PAGE_SIZE);
95308 sp->freelist = b;
95309 + sp->private = 0;
95310 INIT_LIST_HEAD(&sp->list);
95311 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95312 set_slob_page_free(sp, slob_list);
95313 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95314 if (slob_page_free(sp))
95315 clear_slob_page_free(sp);
95316 spin_unlock_irqrestore(&slob_lock, flags);
95317 - __ClearPageSlab(sp);
95318 - page_mapcount_reset(sp);
95319 - slob_free_pages(b, 0);
95320 + slob_free_pages(sp, 0);
95321 return;
95322 }
95323
95324 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95325 + if (pax_sanitize_slab)
95326 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95327 +#endif
95328 +
95329 if (!slob_page_free(sp)) {
95330 /* This slob page is about to become partially free. Easy! */
95331 sp->units = units;
95332 @@ -424,11 +431,10 @@ out:
95333 */
95334
95335 static __always_inline void *
95336 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95337 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95338 {
95339 - unsigned int *m;
95340 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95341 - void *ret;
95342 + slob_t *m;
95343 + void *ret = NULL;
95344
95345 gfp &= gfp_allowed_mask;
95346
95347 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95348
95349 if (!m)
95350 return NULL;
95351 - *m = size;
95352 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95353 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95354 + m[0].units = size;
95355 + m[1].units = align;
95356 ret = (void *)m + align;
95357
95358 trace_kmalloc_node(caller, ret,
95359 size, size + align, gfp, node);
95360 } else {
95361 unsigned int order = get_order(size);
95362 + struct page *page;
95363
95364 if (likely(order))
95365 gfp |= __GFP_COMP;
95366 - ret = slob_new_pages(gfp, order, node);
95367 + page = slob_new_pages(gfp, order, node);
95368 + if (page) {
95369 + ret = page_address(page);
95370 + page->private = size;
95371 + }
95372
95373 trace_kmalloc_node(caller, ret,
95374 size, PAGE_SIZE << order, gfp, node);
95375 }
95376
95377 - kmemleak_alloc(ret, size, 1, gfp);
95378 + return ret;
95379 +}
95380 +
95381 +static __always_inline void *
95382 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95383 +{
95384 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95385 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95386 +
95387 + if (!ZERO_OR_NULL_PTR(ret))
95388 + kmemleak_alloc(ret, size, 1, gfp);
95389 return ret;
95390 }
95391
95392 @@ -493,34 +517,112 @@ void kfree(const void *block)
95393 return;
95394 kmemleak_free(block);
95395
95396 + VM_BUG_ON(!virt_addr_valid(block));
95397 sp = virt_to_page(block);
95398 - if (PageSlab(sp)) {
95399 + VM_BUG_ON(!PageSlab(sp));
95400 + if (!sp->private) {
95401 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95402 - unsigned int *m = (unsigned int *)(block - align);
95403 - slob_free(m, *m + align);
95404 - } else
95405 + slob_t *m = (slob_t *)(block - align);
95406 + slob_free(m, m[0].units + align);
95407 + } else {
95408 + __ClearPageSlab(sp);
95409 + page_mapcount_reset(sp);
95410 + sp->private = 0;
95411 __free_pages(sp, compound_order(sp));
95412 + }
95413 }
95414 EXPORT_SYMBOL(kfree);
95415
95416 +bool is_usercopy_object(const void *ptr)
95417 +{
95418 + if (!slab_is_available())
95419 + return false;
95420 +
95421 + // PAX: TODO
95422 +
95423 + return false;
95424 +}
95425 +
95426 +#ifdef CONFIG_PAX_USERCOPY
95427 +const char *check_heap_object(const void *ptr, unsigned long n)
95428 +{
95429 + struct page *page;
95430 + const slob_t *free;
95431 + const void *base;
95432 + unsigned long flags;
95433 +
95434 + if (ZERO_OR_NULL_PTR(ptr))
95435 + return "<null>";
95436 +
95437 + if (!virt_addr_valid(ptr))
95438 + return NULL;
95439 +
95440 + page = virt_to_head_page(ptr);
95441 + if (!PageSlab(page))
95442 + return NULL;
95443 +
95444 + if (page->private) {
95445 + base = page;
95446 + if (base <= ptr && n <= page->private - (ptr - base))
95447 + return NULL;
95448 + return "<slob>";
95449 + }
95450 +
95451 + /* some tricky double walking to find the chunk */
95452 + spin_lock_irqsave(&slob_lock, flags);
95453 + base = (void *)((unsigned long)ptr & PAGE_MASK);
95454 + free = page->freelist;
95455 +
95456 + while (!slob_last(free) && (void *)free <= ptr) {
95457 + base = free + slob_units(free);
95458 + free = slob_next(free);
95459 + }
95460 +
95461 + while (base < (void *)free) {
95462 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95463 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
95464 + int offset;
95465 +
95466 + if (ptr < base + align)
95467 + break;
95468 +
95469 + offset = ptr - base - align;
95470 + if (offset >= m) {
95471 + base += size;
95472 + continue;
95473 + }
95474 +
95475 + if (n > m - offset)
95476 + break;
95477 +
95478 + spin_unlock_irqrestore(&slob_lock, flags);
95479 + return NULL;
95480 + }
95481 +
95482 + spin_unlock_irqrestore(&slob_lock, flags);
95483 + return "<slob>";
95484 +}
95485 +#endif
95486 +
95487 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95488 size_t ksize(const void *block)
95489 {
95490 struct page *sp;
95491 int align;
95492 - unsigned int *m;
95493 + slob_t *m;
95494
95495 BUG_ON(!block);
95496 if (unlikely(block == ZERO_SIZE_PTR))
95497 return 0;
95498
95499 sp = virt_to_page(block);
95500 - if (unlikely(!PageSlab(sp)))
95501 - return PAGE_SIZE << compound_order(sp);
95502 + VM_BUG_ON(!PageSlab(sp));
95503 + if (sp->private)
95504 + return sp->private;
95505
95506 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95507 - m = (unsigned int *)(block - align);
95508 - return SLOB_UNITS(*m) * SLOB_UNIT;
95509 + m = (slob_t *)(block - align);
95510 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95511 }
95512 EXPORT_SYMBOL(ksize);
95513
95514 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95515
95516 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95517 {
95518 - void *b;
95519 + void *b = NULL;
95520
95521 flags &= gfp_allowed_mask;
95522
95523 lockdep_trace_alloc(flags);
95524
95525 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95526 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95527 +#else
95528 if (c->size < PAGE_SIZE) {
95529 b = slob_alloc(c->size, flags, c->align, node);
95530 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95531 SLOB_UNITS(c->size) * SLOB_UNIT,
95532 flags, node);
95533 } else {
95534 - b = slob_new_pages(flags, get_order(c->size), node);
95535 + struct page *sp;
95536 +
95537 + sp = slob_new_pages(flags, get_order(c->size), node);
95538 + if (sp) {
95539 + b = page_address(sp);
95540 + sp->private = c->size;
95541 + }
95542 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95543 PAGE_SIZE << get_order(c->size),
95544 flags, node);
95545 }
95546 +#endif
95547
95548 if (b && c->ctor)
95549 c->ctor(b);
95550 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95551
95552 static void __kmem_cache_free(void *b, int size)
95553 {
95554 - if (size < PAGE_SIZE)
95555 + struct page *sp;
95556 +
95557 + sp = virt_to_page(b);
95558 + BUG_ON(!PageSlab(sp));
95559 + if (!sp->private)
95560 slob_free(b, size);
95561 else
95562 - slob_free_pages(b, get_order(size));
95563 + slob_free_pages(sp, get_order(size));
95564 }
95565
95566 static void kmem_rcu_free(struct rcu_head *head)
95567 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95568
95569 void kmem_cache_free(struct kmem_cache *c, void *b)
95570 {
95571 + int size = c->size;
95572 +
95573 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95574 + if (size + c->align < PAGE_SIZE) {
95575 + size += c->align;
95576 + b -= c->align;
95577 + }
95578 +#endif
95579 +
95580 kmemleak_free_recursive(b, c->flags);
95581 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95582 struct slob_rcu *slob_rcu;
95583 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95584 - slob_rcu->size = c->size;
95585 + slob_rcu = b + (size - sizeof(struct slob_rcu));
95586 + slob_rcu->size = size;
95587 call_rcu(&slob_rcu->head, kmem_rcu_free);
95588 } else {
95589 - __kmem_cache_free(b, c->size);
95590 + __kmem_cache_free(b, size);
95591 }
95592
95593 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95594 + trace_kfree(_RET_IP_, b);
95595 +#else
95596 trace_kmem_cache_free(_RET_IP_, b);
95597 +#endif
95598 +
95599 }
95600 EXPORT_SYMBOL(kmem_cache_free);
95601
95602 diff --git a/mm/slub.c b/mm/slub.c
95603 index 89490d9..c7b226a 100644
95604 --- a/mm/slub.c
95605 +++ b/mm/slub.c
95606 @@ -207,7 +207,7 @@ struct track {
95607
95608 enum track_item { TRACK_ALLOC, TRACK_FREE };
95609
95610 -#ifdef CONFIG_SYSFS
95611 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95612 static int sysfs_slab_add(struct kmem_cache *);
95613 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95614 static void sysfs_slab_remove(struct kmem_cache *);
95615 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
95616 if (!t->addr)
95617 return;
95618
95619 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95620 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95621 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95622 #ifdef CONFIG_STACKTRACE
95623 {
95624 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95625
95626 slab_free_hook(s, x);
95627
95628 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95629 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95630 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95631 + if (s->ctor)
95632 + s->ctor(x);
95633 + }
95634 +#endif
95635 +
95636 redo:
95637 /*
95638 * Determine the currently cpus per cpu slab.
95639 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
95640 * Merge control. If this is set then no merging of slab caches will occur.
95641 * (Could be removed. This was introduced to pacify the merge skeptics.)
95642 */
95643 -static int slub_nomerge;
95644 +static int slub_nomerge = 1;
95645
95646 /*
95647 * Calculate the order of allocation given an slab object size.
95648 @@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95649 s->inuse = size;
95650
95651 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95652 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95653 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95654 +#endif
95655 s->ctor)) {
95656 /*
95657 * Relocate free pointer after the object if it is not
95658 @@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95659 EXPORT_SYMBOL(__kmalloc_node);
95660 #endif
95661
95662 +bool is_usercopy_object(const void *ptr)
95663 +{
95664 + struct page *page;
95665 + struct kmem_cache *s;
95666 +
95667 + if (ZERO_OR_NULL_PTR(ptr))
95668 + return false;
95669 +
95670 + if (!slab_is_available())
95671 + return false;
95672 +
95673 + if (!virt_addr_valid(ptr))
95674 + return false;
95675 +
95676 + page = virt_to_head_page(ptr);
95677 +
95678 + if (!PageSlab(page))
95679 + return false;
95680 +
95681 + s = page->slab_cache;
95682 + return s->flags & SLAB_USERCOPY;
95683 +}
95684 +
95685 +#ifdef CONFIG_PAX_USERCOPY
95686 +const char *check_heap_object(const void *ptr, unsigned long n)
95687 +{
95688 + struct page *page;
95689 + struct kmem_cache *s;
95690 + unsigned long offset;
95691 +
95692 + if (ZERO_OR_NULL_PTR(ptr))
95693 + return "<null>";
95694 +
95695 + if (!virt_addr_valid(ptr))
95696 + return NULL;
95697 +
95698 + page = virt_to_head_page(ptr);
95699 +
95700 + if (!PageSlab(page))
95701 + return NULL;
95702 +
95703 + s = page->slab_cache;
95704 + if (!(s->flags & SLAB_USERCOPY))
95705 + return s->name;
95706 +
95707 + offset = (ptr - page_address(page)) % s->size;
95708 + if (offset <= s->object_size && n <= s->object_size - offset)
95709 + return NULL;
95710 +
95711 + return s->name;
95712 +}
95713 +#endif
95714 +
95715 size_t ksize(const void *object)
95716 {
95717 struct page *page;
95718 @@ -3360,6 +3424,7 @@ void kfree(const void *x)
95719 if (unlikely(ZERO_OR_NULL_PTR(x)))
95720 return;
95721
95722 + VM_BUG_ON(!virt_addr_valid(x));
95723 page = virt_to_head_page(x);
95724 if (unlikely(!PageSlab(page))) {
95725 BUG_ON(!PageCompound(page));
95726 @@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95727 /*
95728 * We may have set a slab to be unmergeable during bootstrap.
95729 */
95730 - if (s->refcount < 0)
95731 + if (atomic_read(&s->refcount) < 0)
95732 return 1;
95733
95734 return 0;
95735 @@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95736
95737 s = find_mergeable(memcg, size, align, flags, name, ctor);
95738 if (s) {
95739 - s->refcount++;
95740 + atomic_inc(&s->refcount);
95741 /*
95742 * Adjust the object sizes so that we clear
95743 * the complete object on kzalloc.
95744 @@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95745 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95746
95747 if (sysfs_slab_alias(s, name)) {
95748 - s->refcount--;
95749 + atomic_dec(&s->refcount);
95750 s = NULL;
95751 }
95752 }
95753 @@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95754 }
95755 #endif
95756
95757 -#ifdef CONFIG_SYSFS
95758 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95759 static int count_inuse(struct page *page)
95760 {
95761 return page->inuse;
95762 @@ -4241,12 +4306,12 @@ static void resiliency_test(void)
95763 validate_slab_cache(kmalloc_caches[9]);
95764 }
95765 #else
95766 -#ifdef CONFIG_SYSFS
95767 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95768 static void resiliency_test(void) {};
95769 #endif
95770 #endif
95771
95772 -#ifdef CONFIG_SYSFS
95773 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95774 enum slab_stat_type {
95775 SL_ALL, /* All slabs */
95776 SL_PARTIAL, /* Only partially allocated slabs */
95777 @@ -4492,7 +4557,7 @@ SLAB_ATTR_RO(ctor);
95778
95779 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95780 {
95781 - return sprintf(buf, "%d\n", s->refcount - 1);
95782 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95783 }
95784 SLAB_ATTR_RO(aliases);
95785
95786 @@ -4580,6 +4645,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95787 SLAB_ATTR_RO(cache_dma);
95788 #endif
95789
95790 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95791 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95792 +{
95793 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95794 +}
95795 +SLAB_ATTR_RO(usercopy);
95796 +#endif
95797 +
95798 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95799 {
95800 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95801 @@ -4914,6 +4987,9 @@ static struct attribute *slab_attrs[] = {
95802 #ifdef CONFIG_ZONE_DMA
95803 &cache_dma_attr.attr,
95804 #endif
95805 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95806 + &usercopy_attr.attr,
95807 +#endif
95808 #ifdef CONFIG_NUMA
95809 &remote_node_defrag_ratio_attr.attr,
95810 #endif
95811 @@ -5146,6 +5222,7 @@ static char *create_unique_id(struct kmem_cache *s)
95812 return name;
95813 }
95814
95815 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95816 static int sysfs_slab_add(struct kmem_cache *s)
95817 {
95818 int err;
95819 @@ -5169,7 +5246,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
95820 }
95821
95822 s->kobj.kset = slab_kset;
95823 - err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
95824 + err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
95825 if (err) {
95826 kobject_put(&s->kobj);
95827 return err;
95828 @@ -5203,6 +5280,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95829 kobject_del(&s->kobj);
95830 kobject_put(&s->kobj);
95831 }
95832 +#endif
95833
95834 /*
95835 * Need to buffer aliases during bootup until sysfs becomes
95836 @@ -5216,6 +5294,7 @@ struct saved_alias {
95837
95838 static struct saved_alias *alias_list;
95839
95840 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95841 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95842 {
95843 struct saved_alias *al;
95844 @@ -5238,6 +5317,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95845 alias_list = al;
95846 return 0;
95847 }
95848 +#endif
95849
95850 static int __init slab_sysfs_init(void)
95851 {
95852 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
95853 index 27eeab3..7c3f7f2 100644
95854 --- a/mm/sparse-vmemmap.c
95855 +++ b/mm/sparse-vmemmap.c
95856 @@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
95857 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95858 if (!p)
95859 return NULL;
95860 - pud_populate(&init_mm, pud, p);
95861 + pud_populate_kernel(&init_mm, pud, p);
95862 }
95863 return pud;
95864 }
95865 @@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
95866 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95867 if (!p)
95868 return NULL;
95869 - pgd_populate(&init_mm, pgd, p);
95870 + pgd_populate_kernel(&init_mm, pgd, p);
95871 }
95872 return pgd;
95873 }
95874 diff --git a/mm/sparse.c b/mm/sparse.c
95875 index 8cc7be0..d0f7d7a 100644
95876 --- a/mm/sparse.c
95877 +++ b/mm/sparse.c
95878 @@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
95879
95880 for (i = 0; i < PAGES_PER_SECTION; i++) {
95881 if (PageHWPoison(&memmap[i])) {
95882 - atomic_long_sub(1, &num_poisoned_pages);
95883 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
95884 ClearPageHWPoison(&memmap[i]);
95885 }
95886 }
95887 diff --git a/mm/swap.c b/mm/swap.c
95888 index 7010cf4..f0a56a4 100644
95889 --- a/mm/swap.c
95890 +++ b/mm/swap.c
95891 @@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
95892
95893 __page_cache_release(page);
95894 dtor = get_compound_page_dtor(page);
95895 + if (!PageHuge(page))
95896 + BUG_ON(dtor != free_compound_page);
95897 (*dtor)(page);
95898 }
95899
95900 diff --git a/mm/swapfile.c b/mm/swapfile.c
95901 index 461fce2..363ae44 100644
95902 --- a/mm/swapfile.c
95903 +++ b/mm/swapfile.c
95904 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
95905
95906 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
95907 /* Activity counter to indicate that a swapon or swapoff has occurred */
95908 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
95909 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
95910
95911 static inline unsigned char swap_count(unsigned char ent)
95912 {
95913 @@ -1958,7 +1958,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
95914 spin_unlock(&swap_lock);
95915
95916 err = 0;
95917 - atomic_inc(&proc_poll_event);
95918 + atomic_inc_unchecked(&proc_poll_event);
95919 wake_up_interruptible(&proc_poll_wait);
95920
95921 out_dput:
95922 @@ -1975,8 +1975,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
95923
95924 poll_wait(file, &proc_poll_wait, wait);
95925
95926 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
95927 - seq->poll_event = atomic_read(&proc_poll_event);
95928 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
95929 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95930 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
95931 }
95932
95933 @@ -2074,7 +2074,7 @@ static int swaps_open(struct inode *inode, struct file *file)
95934 return ret;
95935
95936 seq = file->private_data;
95937 - seq->poll_event = atomic_read(&proc_poll_event);
95938 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95939 return 0;
95940 }
95941
95942 @@ -2533,7 +2533,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
95943 (frontswap_map) ? "FS" : "");
95944
95945 mutex_unlock(&swapon_mutex);
95946 - atomic_inc(&proc_poll_event);
95947 + atomic_inc_unchecked(&proc_poll_event);
95948 wake_up_interruptible(&proc_poll_wait);
95949
95950 if (S_ISREG(inode->i_mode))
95951 diff --git a/mm/util.c b/mm/util.c
95952 index 808f375..e4764b5 100644
95953 --- a/mm/util.c
95954 +++ b/mm/util.c
95955 @@ -297,6 +297,12 @@ done:
95956 void arch_pick_mmap_layout(struct mm_struct *mm)
95957 {
95958 mm->mmap_base = TASK_UNMAPPED_BASE;
95959 +
95960 +#ifdef CONFIG_PAX_RANDMMAP
95961 + if (mm->pax_flags & MF_PAX_RANDMMAP)
95962 + mm->mmap_base += mm->delta_mmap;
95963 +#endif
95964 +
95965 mm->get_unmapped_area = arch_get_unmapped_area;
95966 }
95967 #endif
95968 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
95969 index 0fdf968..d6686e8 100644
95970 --- a/mm/vmalloc.c
95971 +++ b/mm/vmalloc.c
95972 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
95973
95974 pte = pte_offset_kernel(pmd, addr);
95975 do {
95976 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95977 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95978 +
95979 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95980 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
95981 + BUG_ON(!pte_exec(*pte));
95982 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
95983 + continue;
95984 + }
95985 +#endif
95986 +
95987 + {
95988 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95989 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95990 + }
95991 } while (pte++, addr += PAGE_SIZE, addr != end);
95992 }
95993
95994 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
95995 pte = pte_alloc_kernel(pmd, addr);
95996 if (!pte)
95997 return -ENOMEM;
95998 +
95999 + pax_open_kernel();
96000 do {
96001 struct page *page = pages[*nr];
96002
96003 - if (WARN_ON(!pte_none(*pte)))
96004 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96005 + if (pgprot_val(prot) & _PAGE_NX)
96006 +#endif
96007 +
96008 + if (!pte_none(*pte)) {
96009 + pax_close_kernel();
96010 + WARN_ON(1);
96011 return -EBUSY;
96012 - if (WARN_ON(!page))
96013 + }
96014 + if (!page) {
96015 + pax_close_kernel();
96016 + WARN_ON(1);
96017 return -ENOMEM;
96018 + }
96019 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96020 (*nr)++;
96021 } while (pte++, addr += PAGE_SIZE, addr != end);
96022 + pax_close_kernel();
96023 return 0;
96024 }
96025
96026 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96027 pmd_t *pmd;
96028 unsigned long next;
96029
96030 - pmd = pmd_alloc(&init_mm, pud, addr);
96031 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96032 if (!pmd)
96033 return -ENOMEM;
96034 do {
96035 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96036 pud_t *pud;
96037 unsigned long next;
96038
96039 - pud = pud_alloc(&init_mm, pgd, addr);
96040 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
96041 if (!pud)
96042 return -ENOMEM;
96043 do {
96044 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
96045 if (addr >= MODULES_VADDR && addr < MODULES_END)
96046 return 1;
96047 #endif
96048 +
96049 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96050 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96051 + return 1;
96052 +#endif
96053 +
96054 return is_vmalloc_addr(x);
96055 }
96056
96057 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96058
96059 if (!pgd_none(*pgd)) {
96060 pud_t *pud = pud_offset(pgd, addr);
96061 +#ifdef CONFIG_X86
96062 + if (!pud_large(*pud))
96063 +#endif
96064 if (!pud_none(*pud)) {
96065 pmd_t *pmd = pmd_offset(pud, addr);
96066 +#ifdef CONFIG_X86
96067 + if (!pmd_large(*pmd))
96068 +#endif
96069 if (!pmd_none(*pmd)) {
96070 pte_t *ptep, pte;
96071
96072 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96073 struct vm_struct *area;
96074
96075 BUG_ON(in_interrupt());
96076 +
96077 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96078 + if (flags & VM_KERNEXEC) {
96079 + if (start != VMALLOC_START || end != VMALLOC_END)
96080 + return NULL;
96081 + start = (unsigned long)MODULES_EXEC_VADDR;
96082 + end = (unsigned long)MODULES_EXEC_END;
96083 + }
96084 +#endif
96085 +
96086 if (flags & VM_IOREMAP)
96087 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96088
96089 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
96090 if (count > totalram_pages)
96091 return NULL;
96092
96093 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96094 + if (!(pgprot_val(prot) & _PAGE_NX))
96095 + flags |= VM_KERNEXEC;
96096 +#endif
96097 +
96098 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
96099 __builtin_return_address(0));
96100 if (!area)
96101 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
96102 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
96103 goto fail;
96104
96105 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96106 + if (!(pgprot_val(prot) & _PAGE_NX))
96107 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
96108 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
96109 + else
96110 +#endif
96111 +
96112 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
96113 start, end, node, gfp_mask, caller);
96114 if (!area)
96115 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
96116 * For tight control over page level allocator and protection flags
96117 * use __vmalloc() instead.
96118 */
96119 -
96120 void *vmalloc_exec(unsigned long size)
96121 {
96122 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
96123 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
96124 NUMA_NO_NODE, __builtin_return_address(0));
96125 }
96126
96127 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
96128 {
96129 struct vm_struct *area;
96130
96131 + BUG_ON(vma->vm_mirror);
96132 +
96133 size = PAGE_ALIGN(size);
96134
96135 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96136 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96137 v->addr, v->addr + v->size, v->size);
96138
96139 if (v->caller)
96140 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96141 + seq_printf(m, " %pK", v->caller);
96142 +#else
96143 seq_printf(m, " %pS", v->caller);
96144 +#endif
96145
96146 if (v->nr_pages)
96147 seq_printf(m, " pages=%d", v->nr_pages);
96148 diff --git a/mm/vmstat.c b/mm/vmstat.c
96149 index 7249614..2639fc7 100644
96150 --- a/mm/vmstat.c
96151 +++ b/mm/vmstat.c
96152 @@ -20,6 +20,7 @@
96153 #include <linux/writeback.h>
96154 #include <linux/compaction.h>
96155 #include <linux/mm_inline.h>
96156 +#include <linux/grsecurity.h>
96157
96158 #include "internal.h"
96159
96160 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96161 *
96162 * vm_stat contains the global counters
96163 */
96164 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96165 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96166 EXPORT_SYMBOL(vm_stat);
96167
96168 #ifdef CONFIG_SMP
96169 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96170
96171 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96172 if (diff[i])
96173 - atomic_long_add(diff[i], &vm_stat[i]);
96174 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96175 }
96176
96177 /*
96178 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96179 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
96180 if (v) {
96181
96182 - atomic_long_add(v, &zone->vm_stat[i]);
96183 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96184 global_diff[i] += v;
96185 #ifdef CONFIG_NUMA
96186 /* 3 seconds idle till flush */
96187 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
96188
96189 v = p->vm_stat_diff[i];
96190 p->vm_stat_diff[i] = 0;
96191 - atomic_long_add(v, &zone->vm_stat[i]);
96192 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96193 global_diff[i] += v;
96194 }
96195 }
96196 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
96197 if (pset->vm_stat_diff[i]) {
96198 int v = pset->vm_stat_diff[i];
96199 pset->vm_stat_diff[i] = 0;
96200 - atomic_long_add(v, &zone->vm_stat[i]);
96201 - atomic_long_add(v, &vm_stat[i]);
96202 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96203 + atomic_long_add_unchecked(v, &vm_stat[i]);
96204 }
96205 }
96206 #endif
96207 @@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
96208 stat_items_size += sizeof(struct vm_event_state);
96209 #endif
96210
96211 - v = kmalloc(stat_items_size, GFP_KERNEL);
96212 + v = kzalloc(stat_items_size, GFP_KERNEL);
96213 m->private = v;
96214 if (!v)
96215 return ERR_PTR(-ENOMEM);
96216 +
96217 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
96218 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
96219 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
96220 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
96221 + && !in_group_p(grsec_proc_gid)
96222 +#endif
96223 + )
96224 + return (unsigned long *)m->private + *pos;
96225 +#endif
96226 +#endif
96227 +
96228 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96229 v[i] = global_page_state(i);
96230 v += NR_VM_ZONE_STAT_ITEMS;
96231 @@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
96232 put_online_cpus();
96233 #endif
96234 #ifdef CONFIG_PROC_FS
96235 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96236 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96237 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96238 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96239 + {
96240 + mode_t gr_mode = S_IRUGO;
96241 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
96242 + gr_mode = S_IRUSR;
96243 +#endif
96244 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96245 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96246 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96247 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96248 + }
96249 #endif
96250 return 0;
96251 }
96252 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96253 index b3d17d1..e8e4cdd 100644
96254 --- a/net/8021q/vlan.c
96255 +++ b/net/8021q/vlan.c
96256 @@ -472,7 +472,7 @@ out:
96257 return NOTIFY_DONE;
96258 }
96259
96260 -static struct notifier_block vlan_notifier_block __read_mostly = {
96261 +static struct notifier_block vlan_notifier_block = {
96262 .notifier_call = vlan_device_event,
96263 };
96264
96265 @@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96266 err = -EPERM;
96267 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96268 break;
96269 - if ((args.u.name_type >= 0) &&
96270 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96271 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96272 struct vlan_net *vn;
96273
96274 vn = net_generic(net, vlan_net_id);
96275 diff --git a/net/9p/client.c b/net/9p/client.c
96276 index ee8fd6b..0469d50 100644
96277 --- a/net/9p/client.c
96278 +++ b/net/9p/client.c
96279 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96280 len - inline_len);
96281 } else {
96282 err = copy_from_user(ename + inline_len,
96283 - uidata, len - inline_len);
96284 + (char __force_user *)uidata, len - inline_len);
96285 if (err) {
96286 err = -EFAULT;
96287 goto out_err;
96288 @@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96289 kernel_buf = 1;
96290 indata = data;
96291 } else
96292 - indata = (__force char *)udata;
96293 + indata = (__force_kernel char *)udata;
96294 /*
96295 * response header len is 11
96296 * PDU Header(7) + IO Size (4)
96297 @@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96298 kernel_buf = 1;
96299 odata = data;
96300 } else
96301 - odata = (char *)udata;
96302 + odata = (char __force_kernel *)udata;
96303 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96304 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96305 fid->fid, offset, rsize);
96306 diff --git a/net/9p/mod.c b/net/9p/mod.c
96307 index 6ab36ae..6f1841b 100644
96308 --- a/net/9p/mod.c
96309 +++ b/net/9p/mod.c
96310 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96311 void v9fs_register_trans(struct p9_trans_module *m)
96312 {
96313 spin_lock(&v9fs_trans_lock);
96314 - list_add_tail(&m->list, &v9fs_trans_list);
96315 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96316 spin_unlock(&v9fs_trans_lock);
96317 }
96318 EXPORT_SYMBOL(v9fs_register_trans);
96319 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96320 void v9fs_unregister_trans(struct p9_trans_module *m)
96321 {
96322 spin_lock(&v9fs_trans_lock);
96323 - list_del_init(&m->list);
96324 + pax_list_del_init((struct list_head *)&m->list);
96325 spin_unlock(&v9fs_trans_lock);
96326 }
96327 EXPORT_SYMBOL(v9fs_unregister_trans);
96328 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96329 index 9321a77..ed2f256 100644
96330 --- a/net/9p/trans_fd.c
96331 +++ b/net/9p/trans_fd.c
96332 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96333 oldfs = get_fs();
96334 set_fs(get_ds());
96335 /* The cast to a user pointer is valid due to the set_fs() */
96336 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96337 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96338 set_fs(oldfs);
96339
96340 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96341 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96342 index 876fbe8..8bbea9f 100644
96343 --- a/net/atm/atm_misc.c
96344 +++ b/net/atm/atm_misc.c
96345 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96346 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96347 return 1;
96348 atm_return(vcc, truesize);
96349 - atomic_inc(&vcc->stats->rx_drop);
96350 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96351 return 0;
96352 }
96353 EXPORT_SYMBOL(atm_charge);
96354 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96355 }
96356 }
96357 atm_return(vcc, guess);
96358 - atomic_inc(&vcc->stats->rx_drop);
96359 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96360 return NULL;
96361 }
96362 EXPORT_SYMBOL(atm_alloc_charge);
96363 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96364
96365 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96366 {
96367 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96368 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96369 __SONET_ITEMS
96370 #undef __HANDLE_ITEM
96371 }
96372 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96373
96374 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96375 {
96376 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96377 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96378 __SONET_ITEMS
96379 #undef __HANDLE_ITEM
96380 }
96381 diff --git a/net/atm/lec.c b/net/atm/lec.c
96382 index f23916b..dd4d26b 100644
96383 --- a/net/atm/lec.c
96384 +++ b/net/atm/lec.c
96385 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96386 }
96387
96388 static struct lane2_ops lane2_ops = {
96389 - lane2_resolve, /* resolve, spec 3.1.3 */
96390 - lane2_associate_req, /* associate_req, spec 3.1.4 */
96391 - NULL /* associate indicator, spec 3.1.5 */
96392 + .resolve = lane2_resolve,
96393 + .associate_req = lane2_associate_req,
96394 + .associate_indicator = NULL
96395 };
96396
96397 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96398 diff --git a/net/atm/lec.h b/net/atm/lec.h
96399 index 4149db1..f2ab682 100644
96400 --- a/net/atm/lec.h
96401 +++ b/net/atm/lec.h
96402 @@ -48,7 +48,7 @@ struct lane2_ops {
96403 const u8 *tlvs, u32 sizeoftlvs);
96404 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96405 const u8 *tlvs, u32 sizeoftlvs);
96406 -};
96407 +} __no_const;
96408
96409 /*
96410 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96411 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96412 index d1b2d9a..d549f7f 100644
96413 --- a/net/atm/mpoa_caches.c
96414 +++ b/net/atm/mpoa_caches.c
96415 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96416
96417
96418 static struct in_cache_ops ingress_ops = {
96419 - in_cache_add_entry, /* add_entry */
96420 - in_cache_get, /* get */
96421 - in_cache_get_with_mask, /* get_with_mask */
96422 - in_cache_get_by_vcc, /* get_by_vcc */
96423 - in_cache_put, /* put */
96424 - in_cache_remove_entry, /* remove_entry */
96425 - cache_hit, /* cache_hit */
96426 - clear_count_and_expired, /* clear_count */
96427 - check_resolving_entries, /* check_resolving */
96428 - refresh_entries, /* refresh */
96429 - in_destroy_cache /* destroy_cache */
96430 + .add_entry = in_cache_add_entry,
96431 + .get = in_cache_get,
96432 + .get_with_mask = in_cache_get_with_mask,
96433 + .get_by_vcc = in_cache_get_by_vcc,
96434 + .put = in_cache_put,
96435 + .remove_entry = in_cache_remove_entry,
96436 + .cache_hit = cache_hit,
96437 + .clear_count = clear_count_and_expired,
96438 + .check_resolving = check_resolving_entries,
96439 + .refresh = refresh_entries,
96440 + .destroy_cache = in_destroy_cache
96441 };
96442
96443 static struct eg_cache_ops egress_ops = {
96444 - eg_cache_add_entry, /* add_entry */
96445 - eg_cache_get_by_cache_id, /* get_by_cache_id */
96446 - eg_cache_get_by_tag, /* get_by_tag */
96447 - eg_cache_get_by_vcc, /* get_by_vcc */
96448 - eg_cache_get_by_src_ip, /* get_by_src_ip */
96449 - eg_cache_put, /* put */
96450 - eg_cache_remove_entry, /* remove_entry */
96451 - update_eg_cache_entry, /* update */
96452 - clear_expired, /* clear_expired */
96453 - eg_destroy_cache /* destroy_cache */
96454 + .add_entry = eg_cache_add_entry,
96455 + .get_by_cache_id = eg_cache_get_by_cache_id,
96456 + .get_by_tag = eg_cache_get_by_tag,
96457 + .get_by_vcc = eg_cache_get_by_vcc,
96458 + .get_by_src_ip = eg_cache_get_by_src_ip,
96459 + .put = eg_cache_put,
96460 + .remove_entry = eg_cache_remove_entry,
96461 + .update = update_eg_cache_entry,
96462 + .clear_expired = clear_expired,
96463 + .destroy_cache = eg_destroy_cache
96464 };
96465
96466
96467 diff --git a/net/atm/proc.c b/net/atm/proc.c
96468 index bbb6461..cf04016 100644
96469 --- a/net/atm/proc.c
96470 +++ b/net/atm/proc.c
96471 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96472 const struct k_atm_aal_stats *stats)
96473 {
96474 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96475 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96476 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96477 - atomic_read(&stats->rx_drop));
96478 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96479 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96480 + atomic_read_unchecked(&stats->rx_drop));
96481 }
96482
96483 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96484 diff --git a/net/atm/resources.c b/net/atm/resources.c
96485 index 0447d5d..3cf4728 100644
96486 --- a/net/atm/resources.c
96487 +++ b/net/atm/resources.c
96488 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96489 static void copy_aal_stats(struct k_atm_aal_stats *from,
96490 struct atm_aal_stats *to)
96491 {
96492 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96493 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96494 __AAL_STAT_ITEMS
96495 #undef __HANDLE_ITEM
96496 }
96497 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96498 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96499 struct atm_aal_stats *to)
96500 {
96501 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96502 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96503 __AAL_STAT_ITEMS
96504 #undef __HANDLE_ITEM
96505 }
96506 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96507 index 919a5ce..cc6b444 100644
96508 --- a/net/ax25/sysctl_net_ax25.c
96509 +++ b/net/ax25/sysctl_net_ax25.c
96510 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96511 {
96512 char path[sizeof("net/ax25/") + IFNAMSIZ];
96513 int k;
96514 - struct ctl_table *table;
96515 + ctl_table_no_const *table;
96516
96517 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96518 if (!table)
96519 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96520 index f7270b9..cd0d879 100644
96521 --- a/net/batman-adv/bat_iv_ogm.c
96522 +++ b/net/batman-adv/bat_iv_ogm.c
96523 @@ -307,7 +307,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96524
96525 /* randomize initial seqno to avoid collision */
96526 get_random_bytes(&random_seqno, sizeof(random_seqno));
96527 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96528 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96529
96530 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96531 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96532 @@ -894,9 +894,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96533 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96534
96535 /* change sequence number to network order */
96536 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96537 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96538 batadv_ogm_packet->seqno = htonl(seqno);
96539 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96540 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96541
96542 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96543 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
96544 @@ -1261,7 +1261,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
96545 return;
96546
96547 /* could be changed by schedule_own_packet() */
96548 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96549 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96550
96551 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
96552 has_directlink_flag = 1;
96553 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96554 index 6ddb614..ca7e886 100644
96555 --- a/net/batman-adv/fragmentation.c
96556 +++ b/net/batman-adv/fragmentation.c
96557 @@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96558 frag_header.packet_type = BATADV_UNICAST_FRAG;
96559 frag_header.version = BATADV_COMPAT_VERSION;
96560 frag_header.ttl = BATADV_TTL;
96561 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96562 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96563 frag_header.reserved = 0;
96564 frag_header.no = 0;
96565 frag_header.total_size = htons(skb->len);
96566 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96567 index a8f99d1..11797ef 100644
96568 --- a/net/batman-adv/soft-interface.c
96569 +++ b/net/batman-adv/soft-interface.c
96570 @@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
96571 primary_if->net_dev->dev_addr, ETH_ALEN);
96572
96573 /* set broadcast sequence number */
96574 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96575 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96576 bcast_packet->seqno = htonl(seqno);
96577
96578 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96579 @@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96580 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96581
96582 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96583 - atomic_set(&bat_priv->bcast_seqno, 1);
96584 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96585 atomic_set(&bat_priv->tt.vn, 0);
96586 atomic_set(&bat_priv->tt.local_changes, 0);
96587 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96588 @@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96589
96590 /* randomize initial seqno to avoid collision */
96591 get_random_bytes(&random_seqno, sizeof(random_seqno));
96592 - atomic_set(&bat_priv->frag_seqno, random_seqno);
96593 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96594
96595 bat_priv->primary_if = NULL;
96596 bat_priv->num_ifaces = 0;
96597 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96598 index 91dd369..9c25750 100644
96599 --- a/net/batman-adv/types.h
96600 +++ b/net/batman-adv/types.h
96601 @@ -56,7 +56,7 @@
96602 struct batadv_hard_iface_bat_iv {
96603 unsigned char *ogm_buff;
96604 int ogm_buff_len;
96605 - atomic_t ogm_seqno;
96606 + atomic_unchecked_t ogm_seqno;
96607 };
96608
96609 /**
96610 @@ -673,7 +673,7 @@ struct batadv_priv {
96611 atomic_t bonding;
96612 atomic_t fragmentation;
96613 atomic_t packet_size_max;
96614 - atomic_t frag_seqno;
96615 + atomic_unchecked_t frag_seqno;
96616 #ifdef CONFIG_BATMAN_ADV_BLA
96617 atomic_t bridge_loop_avoidance;
96618 #endif
96619 @@ -687,7 +687,7 @@ struct batadv_priv {
96620 #ifdef CONFIG_BATMAN_ADV_DEBUG
96621 atomic_t log_level;
96622 #endif
96623 - atomic_t bcast_seqno;
96624 + atomic_unchecked_t bcast_seqno;
96625 atomic_t bcast_queue_left;
96626 atomic_t batman_queue_left;
96627 char num_ifaces;
96628 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96629 index 7552f9e..074ce29 100644
96630 --- a/net/bluetooth/hci_sock.c
96631 +++ b/net/bluetooth/hci_sock.c
96632 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96633 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96634 }
96635
96636 - len = min_t(unsigned int, len, sizeof(uf));
96637 + len = min((size_t)len, sizeof(uf));
96638 if (copy_from_user(&uf, optval, len)) {
96639 err = -EFAULT;
96640 break;
96641 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96642 index 4af3821..f2ba46c 100644
96643 --- a/net/bluetooth/l2cap_core.c
96644 +++ b/net/bluetooth/l2cap_core.c
96645 @@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96646 break;
96647
96648 case L2CAP_CONF_RFC:
96649 - if (olen == sizeof(rfc))
96650 - memcpy(&rfc, (void *)val, olen);
96651 + if (olen != sizeof(rfc))
96652 + break;
96653 +
96654 + memcpy(&rfc, (void *)val, olen);
96655
96656 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96657 rfc.mode != chan->mode)
96658 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96659 index 7cc24d2..e83f531 100644
96660 --- a/net/bluetooth/l2cap_sock.c
96661 +++ b/net/bluetooth/l2cap_sock.c
96662 @@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96663 struct sock *sk = sock->sk;
96664 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96665 struct l2cap_options opts;
96666 - int len, err = 0;
96667 + int err = 0;
96668 + size_t len = optlen;
96669 u32 opt;
96670
96671 BT_DBG("sk %p", sk);
96672 @@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96673 opts.max_tx = chan->max_tx;
96674 opts.txwin_size = chan->tx_win;
96675
96676 - len = min_t(unsigned int, sizeof(opts), optlen);
96677 + len = min(sizeof(opts), len);
96678 if (copy_from_user((char *) &opts, optval, len)) {
96679 err = -EFAULT;
96680 break;
96681 @@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96682 struct bt_security sec;
96683 struct bt_power pwr;
96684 struct l2cap_conn *conn;
96685 - int len, err = 0;
96686 + int err = 0;
96687 + size_t len = optlen;
96688 u32 opt;
96689
96690 BT_DBG("sk %p", sk);
96691 @@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96692
96693 sec.level = BT_SECURITY_LOW;
96694
96695 - len = min_t(unsigned int, sizeof(sec), optlen);
96696 + len = min(sizeof(sec), len);
96697 if (copy_from_user((char *) &sec, optval, len)) {
96698 err = -EFAULT;
96699 break;
96700 @@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96701
96702 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96703
96704 - len = min_t(unsigned int, sizeof(pwr), optlen);
96705 + len = min(sizeof(pwr), len);
96706 if (copy_from_user((char *) &pwr, optval, len)) {
96707 err = -EFAULT;
96708 break;
96709 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96710 index 3c2d3e4..884855a 100644
96711 --- a/net/bluetooth/rfcomm/sock.c
96712 +++ b/net/bluetooth/rfcomm/sock.c
96713 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96714 struct sock *sk = sock->sk;
96715 struct bt_security sec;
96716 int err = 0;
96717 - size_t len;
96718 + size_t len = optlen;
96719 u32 opt;
96720
96721 BT_DBG("sk %p", sk);
96722 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96723
96724 sec.level = BT_SECURITY_LOW;
96725
96726 - len = min_t(unsigned int, sizeof(sec), optlen);
96727 + len = min(sizeof(sec), len);
96728 if (copy_from_user((char *) &sec, optval, len)) {
96729 err = -EFAULT;
96730 break;
96731 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96732 index 84fcf9f..e389b27 100644
96733 --- a/net/bluetooth/rfcomm/tty.c
96734 +++ b/net/bluetooth/rfcomm/tty.c
96735 @@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96736 BT_DBG("tty %p id %d", tty, tty->index);
96737
96738 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96739 - dev->channel, dev->port.count);
96740 + dev->channel, atomic_read(&dev->port.count));
96741
96742 err = tty_port_open(&dev->port, tty, filp);
96743 if (err)
96744 @@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96745 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96746
96747 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96748 - dev->port.count);
96749 + atomic_read(&dev->port.count));
96750
96751 tty_port_close(&dev->port, tty, filp);
96752 }
96753 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96754 index ac78024..161a80c 100644
96755 --- a/net/bridge/netfilter/ebtables.c
96756 +++ b/net/bridge/netfilter/ebtables.c
96757 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96758 tmp.valid_hooks = t->table->valid_hooks;
96759 }
96760 mutex_unlock(&ebt_mutex);
96761 - if (copy_to_user(user, &tmp, *len) != 0){
96762 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
96763 BUGPRINT("c2u Didn't work\n");
96764 ret = -EFAULT;
96765 break;
96766 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96767 goto out;
96768 tmp.valid_hooks = t->valid_hooks;
96769
96770 - if (copy_to_user(user, &tmp, *len) != 0) {
96771 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96772 ret = -EFAULT;
96773 break;
96774 }
96775 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96776 tmp.entries_size = t->table->entries_size;
96777 tmp.valid_hooks = t->table->valid_hooks;
96778
96779 - if (copy_to_user(user, &tmp, *len) != 0) {
96780 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96781 ret = -EFAULT;
96782 break;
96783 }
96784 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96785 index 0f45522..dab651f 100644
96786 --- a/net/caif/cfctrl.c
96787 +++ b/net/caif/cfctrl.c
96788 @@ -10,6 +10,7 @@
96789 #include <linux/spinlock.h>
96790 #include <linux/slab.h>
96791 #include <linux/pkt_sched.h>
96792 +#include <linux/sched.h>
96793 #include <net/caif/caif_layer.h>
96794 #include <net/caif/cfpkt.h>
96795 #include <net/caif/cfctrl.h>
96796 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96797 memset(&dev_info, 0, sizeof(dev_info));
96798 dev_info.id = 0xff;
96799 cfsrvl_init(&this->serv, 0, &dev_info, false);
96800 - atomic_set(&this->req_seq_no, 1);
96801 - atomic_set(&this->rsp_seq_no, 1);
96802 + atomic_set_unchecked(&this->req_seq_no, 1);
96803 + atomic_set_unchecked(&this->rsp_seq_no, 1);
96804 this->serv.layer.receive = cfctrl_recv;
96805 sprintf(this->serv.layer.name, "ctrl");
96806 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96807 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96808 struct cfctrl_request_info *req)
96809 {
96810 spin_lock_bh(&ctrl->info_list_lock);
96811 - atomic_inc(&ctrl->req_seq_no);
96812 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
96813 + atomic_inc_unchecked(&ctrl->req_seq_no);
96814 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
96815 list_add_tail(&req->list, &ctrl->list);
96816 spin_unlock_bh(&ctrl->info_list_lock);
96817 }
96818 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
96819 if (p != first)
96820 pr_warn("Requests are not received in order\n");
96821
96822 - atomic_set(&ctrl->rsp_seq_no,
96823 + atomic_set_unchecked(&ctrl->rsp_seq_no,
96824 p->sequence_no);
96825 list_del(&p->list);
96826 goto out;
96827 diff --git a/net/can/af_can.c b/net/can/af_can.c
96828 index a27f8aa..67174a3 100644
96829 --- a/net/can/af_can.c
96830 +++ b/net/can/af_can.c
96831 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
96832 };
96833
96834 /* notifier block for netdevice event */
96835 -static struct notifier_block can_netdev_notifier __read_mostly = {
96836 +static struct notifier_block can_netdev_notifier = {
96837 .notifier_call = can_notifier,
96838 };
96839
96840 diff --git a/net/can/gw.c b/net/can/gw.c
96841 index 3f9b0f3..fc6d4fa 100644
96842 --- a/net/can/gw.c
96843 +++ b/net/can/gw.c
96844 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
96845 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
96846
96847 static HLIST_HEAD(cgw_list);
96848 -static struct notifier_block notifier;
96849
96850 static struct kmem_cache *cgw_cache __read_mostly;
96851
96852 @@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
96853 return err;
96854 }
96855
96856 +static struct notifier_block notifier = {
96857 + .notifier_call = cgw_notifier
96858 +};
96859 +
96860 static __init int cgw_module_init(void)
96861 {
96862 /* sanitize given module parameter */
96863 @@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
96864 return -ENOMEM;
96865
96866 /* set notifier */
96867 - notifier.notifier_call = cgw_notifier;
96868 register_netdevice_notifier(&notifier);
96869
96870 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
96871 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
96872 index 464303f..9c30218 100644
96873 --- a/net/ceph/messenger.c
96874 +++ b/net/ceph/messenger.c
96875 @@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
96876 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
96877
96878 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
96879 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
96880 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
96881
96882 static struct page *zero_page; /* used in certain error cases */
96883
96884 @@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
96885 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
96886 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
96887
96888 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96889 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96890 s = addr_str[i];
96891
96892 switch (ss->ss_family) {
96893 diff --git a/net/compat.c b/net/compat.c
96894 index f50161f..94fa415 100644
96895 --- a/net/compat.c
96896 +++ b/net/compat.c
96897 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
96898 return -EFAULT;
96899 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
96900 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
96901 - kmsg->msg_name = compat_ptr(tmp1);
96902 - kmsg->msg_iov = compat_ptr(tmp2);
96903 - kmsg->msg_control = compat_ptr(tmp3);
96904 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
96905 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
96906 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
96907 return 0;
96908 }
96909
96910 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96911
96912 if (kern_msg->msg_namelen) {
96913 if (mode == VERIFY_READ) {
96914 - int err = move_addr_to_kernel(kern_msg->msg_name,
96915 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
96916 kern_msg->msg_namelen,
96917 kern_address);
96918 if (err < 0)
96919 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96920 kern_msg->msg_name = NULL;
96921
96922 tot_len = iov_from_user_compat_to_kern(kern_iov,
96923 - (struct compat_iovec __user *)kern_msg->msg_iov,
96924 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
96925 kern_msg->msg_iovlen);
96926 if (tot_len >= 0)
96927 kern_msg->msg_iov = kern_iov;
96928 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96929
96930 #define CMSG_COMPAT_FIRSTHDR(msg) \
96931 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96932 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
96933 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
96934 (struct compat_cmsghdr __user *)NULL)
96935
96936 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
96937 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
96938 (ucmlen) <= (unsigned long) \
96939 ((mhdr)->msg_controllen - \
96940 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
96941 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
96942
96943 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
96944 struct compat_cmsghdr __user *cmsg, int cmsg_len)
96945 {
96946 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
96947 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
96948 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
96949 msg->msg_controllen)
96950 return NULL;
96951 return (struct compat_cmsghdr __user *)ptr;
96952 @@ -222,7 +222,7 @@ Efault:
96953
96954 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
96955 {
96956 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96957 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96958 struct compat_cmsghdr cmhdr;
96959 struct compat_timeval ctv;
96960 struct compat_timespec cts[3];
96961 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
96962
96963 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
96964 {
96965 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96966 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96967 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
96968 int fdnum = scm->fp->count;
96969 struct file **fp = scm->fp->fp;
96970 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
96971 return -EFAULT;
96972 old_fs = get_fs();
96973 set_fs(KERNEL_DS);
96974 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
96975 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
96976 set_fs(old_fs);
96977
96978 return err;
96979 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
96980 len = sizeof(ktime);
96981 old_fs = get_fs();
96982 set_fs(KERNEL_DS);
96983 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
96984 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
96985 set_fs(old_fs);
96986
96987 if (!err) {
96988 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96989 case MCAST_JOIN_GROUP:
96990 case MCAST_LEAVE_GROUP:
96991 {
96992 - struct compat_group_req __user *gr32 = (void *)optval;
96993 + struct compat_group_req __user *gr32 = (void __user *)optval;
96994 struct group_req __user *kgr =
96995 compat_alloc_user_space(sizeof(struct group_req));
96996 u32 interface;
96997 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96998 case MCAST_BLOCK_SOURCE:
96999 case MCAST_UNBLOCK_SOURCE:
97000 {
97001 - struct compat_group_source_req __user *gsr32 = (void *)optval;
97002 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
97003 struct group_source_req __user *kgsr = compat_alloc_user_space(
97004 sizeof(struct group_source_req));
97005 u32 interface;
97006 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97007 }
97008 case MCAST_MSFILTER:
97009 {
97010 - struct compat_group_filter __user *gf32 = (void *)optval;
97011 + struct compat_group_filter __user *gf32 = (void __user *)optval;
97012 struct group_filter __user *kgf;
97013 u32 interface, fmode, numsrc;
97014
97015 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
97016 char __user *optval, int __user *optlen,
97017 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
97018 {
97019 - struct compat_group_filter __user *gf32 = (void *)optval;
97020 + struct compat_group_filter __user *gf32 = (void __user *)optval;
97021 struct group_filter __user *kgf;
97022 int __user *koptlen;
97023 u32 interface, fmode, numsrc;
97024 @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
97025
97026 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
97027 return -EINVAL;
97028 - if (copy_from_user(a, args, nas[call]))
97029 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
97030 return -EFAULT;
97031 a0 = a[0];
97032 a1 = a[1];
97033 diff --git a/net/core/datagram.c b/net/core/datagram.c
97034 index a16ed7b..eb44d17 100644
97035 --- a/net/core/datagram.c
97036 +++ b/net/core/datagram.c
97037 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
97038 }
97039
97040 kfree_skb(skb);
97041 - atomic_inc(&sk->sk_drops);
97042 + atomic_inc_unchecked(&sk->sk_drops);
97043 sk_mem_reclaim_partial(sk);
97044
97045 return err;
97046 diff --git a/net/core/dev.c b/net/core/dev.c
97047 index 616eccf..31832d38 100644
97048 --- a/net/core/dev.c
97049 +++ b/net/core/dev.c
97050 @@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
97051 {
97052 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
97053 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
97054 - atomic_long_inc(&dev->rx_dropped);
97055 + atomic_long_inc_unchecked(&dev->rx_dropped);
97056 kfree_skb(skb);
97057 return NET_RX_DROP;
97058 }
97059 }
97060
97061 if (unlikely(!is_skb_forwardable(dev, skb))) {
97062 - atomic_long_inc(&dev->rx_dropped);
97063 + atomic_long_inc_unchecked(&dev->rx_dropped);
97064 kfree_skb(skb);
97065 return NET_RX_DROP;
97066 }
97067 @@ -2434,7 +2434,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
97068
97069 struct dev_gso_cb {
97070 void (*destructor)(struct sk_buff *skb);
97071 -};
97072 +} __no_const;
97073
97074 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
97075
97076 @@ -3224,7 +3224,7 @@ enqueue:
97077
97078 local_irq_restore(flags);
97079
97080 - atomic_long_inc(&skb->dev->rx_dropped);
97081 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97082 kfree_skb(skb);
97083 return NET_RX_DROP;
97084 }
97085 @@ -3296,7 +3296,7 @@ int netif_rx_ni(struct sk_buff *skb)
97086 }
97087 EXPORT_SYMBOL(netif_rx_ni);
97088
97089 -static void net_tx_action(struct softirq_action *h)
97090 +static __latent_entropy void net_tx_action(void)
97091 {
97092 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97093
97094 @@ -3630,7 +3630,7 @@ ncls:
97095 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
97096 } else {
97097 drop:
97098 - atomic_long_inc(&skb->dev->rx_dropped);
97099 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97100 kfree_skb(skb);
97101 /* Jamal, now you will not able to escape explaining
97102 * me how you were going to use this. :-)
97103 @@ -4290,7 +4290,7 @@ void netif_napi_del(struct napi_struct *napi)
97104 }
97105 EXPORT_SYMBOL(netif_napi_del);
97106
97107 -static void net_rx_action(struct softirq_action *h)
97108 +static __latent_entropy void net_rx_action(void)
97109 {
97110 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97111 unsigned long time_limit = jiffies + 2;
97112 @@ -6179,7 +6179,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
97113 } else {
97114 netdev_stats_to_stats64(storage, &dev->stats);
97115 }
97116 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
97117 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
97118 return storage;
97119 }
97120 EXPORT_SYMBOL(dev_get_stats);
97121 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
97122 index 5b7d0e1..cb960fc 100644
97123 --- a/net/core/dev_ioctl.c
97124 +++ b/net/core/dev_ioctl.c
97125 @@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
97126 if (no_module && capable(CAP_NET_ADMIN))
97127 no_module = request_module("netdev-%s", name);
97128 if (no_module && capable(CAP_SYS_MODULE)) {
97129 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
97130 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
97131 +#else
97132 if (!request_module("%s", name))
97133 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97134 name);
97135 +#endif
97136 }
97137 }
97138 EXPORT_SYMBOL(dev_load);
97139 diff --git a/net/core/filter.c b/net/core/filter.c
97140 index ad30d62..821081f 100644
97141 --- a/net/core/filter.c
97142 +++ b/net/core/filter.c
97143 @@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
97144 void *ptr;
97145 u32 A = 0; /* Accumulator */
97146 u32 X = 0; /* Index Register */
97147 - u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
97148 + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
97149 u32 tmp;
97150 int k;
97151
97152 @@ -292,10 +292,10 @@ load_b:
97153 X = K;
97154 continue;
97155 case BPF_S_LD_MEM:
97156 - A = mem[K];
97157 + A = mem[K&15];
97158 continue;
97159 case BPF_S_LDX_MEM:
97160 - X = mem[K];
97161 + X = mem[K&15];
97162 continue;
97163 case BPF_S_MISC_TAX:
97164 X = A;
97165 @@ -308,10 +308,10 @@ load_b:
97166 case BPF_S_RET_A:
97167 return A;
97168 case BPF_S_ST:
97169 - mem[K] = A;
97170 + mem[K&15] = A;
97171 continue;
97172 case BPF_S_STX:
97173 - mem[K] = X;
97174 + mem[K&15] = X;
97175 continue;
97176 case BPF_S_ANC_PROTOCOL:
97177 A = ntohs(skb->protocol);
97178 @@ -391,9 +391,10 @@ load_b:
97179 continue;
97180 #endif
97181 default:
97182 - WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
97183 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
97184 fentry->code, fentry->jt,
97185 fentry->jf, fentry->k);
97186 + BUG();
97187 return 0;
97188 }
97189 }
97190 @@ -416,7 +417,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
97191 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
97192 int pc, ret = 0;
97193
97194 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
97195 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
97196 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
97197 if (!masks)
97198 return -ENOMEM;
97199 @@ -679,7 +680,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
97200 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
97201 if (!fp)
97202 return -ENOMEM;
97203 - memcpy(fp->insns, fprog->filter, fsize);
97204 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
97205
97206 atomic_set(&fp->refcnt, 1);
97207 fp->len = fprog->len;
97208 diff --git a/net/core/flow.c b/net/core/flow.c
97209 index dfa602c..3103d88 100644
97210 --- a/net/core/flow.c
97211 +++ b/net/core/flow.c
97212 @@ -61,7 +61,7 @@ struct flow_cache {
97213 struct timer_list rnd_timer;
97214 };
97215
97216 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
97217 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
97218 EXPORT_SYMBOL(flow_cache_genid);
97219 static struct flow_cache flow_cache_global;
97220 static struct kmem_cache *flow_cachep __read_mostly;
97221 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
97222
97223 static int flow_entry_valid(struct flow_cache_entry *fle)
97224 {
97225 - if (atomic_read(&flow_cache_genid) != fle->genid)
97226 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
97227 return 0;
97228 if (fle->object && !fle->object->ops->check(fle->object))
97229 return 0;
97230 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97231 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97232 fcp->hash_count++;
97233 }
97234 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97235 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97236 flo = fle->object;
97237 if (!flo)
97238 goto ret_object;
97239 @@ -279,7 +279,7 @@ nocache:
97240 }
97241 flo = resolver(net, key, family, dir, flo, ctx);
97242 if (fle) {
97243 - fle->genid = atomic_read(&flow_cache_genid);
97244 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
97245 if (!IS_ERR(flo))
97246 fle->object = flo;
97247 else
97248 diff --git a/net/core/iovec.c b/net/core/iovec.c
97249 index b618694..192bbba 100644
97250 --- a/net/core/iovec.c
97251 +++ b/net/core/iovec.c
97252 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97253 if (m->msg_namelen) {
97254 if (mode == VERIFY_READ) {
97255 void __user *namep;
97256 - namep = (void __user __force *) m->msg_name;
97257 + namep = (void __force_user *) m->msg_name;
97258 err = move_addr_to_kernel(namep, m->msg_namelen,
97259 address);
97260 if (err < 0)
97261 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97262 }
97263
97264 size = m->msg_iovlen * sizeof(struct iovec);
97265 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97266 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97267 return -EFAULT;
97268
97269 m->msg_iov = iov;
97270 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97271 index 43128dd..e4d4311 100644
97272 --- a/net/core/neighbour.c
97273 +++ b/net/core/neighbour.c
97274 @@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97275 void __user *buffer, size_t *lenp, loff_t *ppos)
97276 {
97277 int size, ret;
97278 - struct ctl_table tmp = *ctl;
97279 + ctl_table_no_const tmp = *ctl;
97280
97281 tmp.extra1 = &zero;
97282 tmp.extra2 = &unres_qlen_max;
97283 @@ -2983,11 +2983,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97284 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97285 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97286 } else {
97287 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97288 dev_name_source = "default";
97289 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97290 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97291 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97292 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97293 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97294 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97295 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97296 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97297 }
97298
97299
97300 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97301 index 2bf8329..7960607 100644
97302 --- a/net/core/net-procfs.c
97303 +++ b/net/core/net-procfs.c
97304 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97305 else
97306 seq_printf(seq, "%04x", ntohs(pt->type));
97307
97308 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97309 + seq_printf(seq, " %-8s %pf\n",
97310 + pt->dev ? pt->dev->name : "", NULL);
97311 +#else
97312 seq_printf(seq, " %-8s %pf\n",
97313 pt->dev ? pt->dev->name : "", pt->func);
97314 +#endif
97315 }
97316
97317 return 0;
97318 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
97319 index f3edf96..3cd8b40 100644
97320 --- a/net/core/net-sysfs.c
97321 +++ b/net/core/net-sysfs.c
97322 @@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
97323 }
97324 EXPORT_SYMBOL(netdev_class_remove_file_ns);
97325
97326 -int netdev_kobject_init(void)
97327 +int __init netdev_kobject_init(void)
97328 {
97329 kobj_ns_type_register(&net_ns_type_operations);
97330 return class_register(&net_class);
97331 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97332 index 81d3a9a..a0bd7a8 100644
97333 --- a/net/core/net_namespace.c
97334 +++ b/net/core/net_namespace.c
97335 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97336 int error;
97337 LIST_HEAD(net_exit_list);
97338
97339 - list_add_tail(&ops->list, list);
97340 + pax_list_add_tail((struct list_head *)&ops->list, list);
97341 if (ops->init || (ops->id && ops->size)) {
97342 for_each_net(net) {
97343 error = ops_init(ops, net);
97344 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97345
97346 out_undo:
97347 /* If I have an error cleanup all namespaces I initialized */
97348 - list_del(&ops->list);
97349 + pax_list_del((struct list_head *)&ops->list);
97350 ops_exit_list(ops, &net_exit_list);
97351 ops_free_list(ops, &net_exit_list);
97352 return error;
97353 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97354 struct net *net;
97355 LIST_HEAD(net_exit_list);
97356
97357 - list_del(&ops->list);
97358 + pax_list_del((struct list_head *)&ops->list);
97359 for_each_net(net)
97360 list_add_tail(&net->exit_list, &net_exit_list);
97361 ops_exit_list(ops, &net_exit_list);
97362 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97363 mutex_lock(&net_mutex);
97364 error = register_pernet_operations(&pernet_list, ops);
97365 if (!error && (first_device == &pernet_list))
97366 - first_device = &ops->list;
97367 + first_device = (struct list_head *)&ops->list;
97368 mutex_unlock(&net_mutex);
97369 return error;
97370 }
97371 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97372 index 81975f2..9ef3531 100644
97373 --- a/net/core/netpoll.c
97374 +++ b/net/core/netpoll.c
97375 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97376 struct udphdr *udph;
97377 struct iphdr *iph;
97378 struct ethhdr *eth;
97379 - static atomic_t ip_ident;
97380 + static atomic_unchecked_t ip_ident;
97381 struct ipv6hdr *ip6h;
97382
97383 udp_len = len + sizeof(*udph);
97384 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97385 put_unaligned(0x45, (unsigned char *)iph);
97386 iph->tos = 0;
97387 put_unaligned(htons(ip_len), &(iph->tot_len));
97388 - iph->id = htons(atomic_inc_return(&ip_ident));
97389 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97390 iph->frag_off = 0;
97391 iph->ttl = 64;
97392 iph->protocol = IPPROTO_UDP;
97393 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97394 index cf67144..12bf94c 100644
97395 --- a/net/core/rtnetlink.c
97396 +++ b/net/core/rtnetlink.c
97397 @@ -58,7 +58,7 @@ struct rtnl_link {
97398 rtnl_doit_func doit;
97399 rtnl_dumpit_func dumpit;
97400 rtnl_calcit_func calcit;
97401 -};
97402 +} __no_const;
97403
97404 static DEFINE_MUTEX(rtnl_mutex);
97405
97406 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97407 if (rtnl_link_ops_get(ops->kind))
97408 return -EEXIST;
97409
97410 - if (!ops->dellink)
97411 - ops->dellink = unregister_netdevice_queue;
97412 + if (!ops->dellink) {
97413 + pax_open_kernel();
97414 + *(void **)&ops->dellink = unregister_netdevice_queue;
97415 + pax_close_kernel();
97416 + }
97417
97418 - list_add_tail(&ops->list, &link_ops);
97419 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97420 return 0;
97421 }
97422 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97423 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97424 for_each_net(net) {
97425 __rtnl_kill_links(net, ops);
97426 }
97427 - list_del(&ops->list);
97428 + pax_list_del((struct list_head *)&ops->list);
97429 }
97430 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97431
97432 diff --git a/net/core/scm.c b/net/core/scm.c
97433 index b442e7e..6f5b5a2 100644
97434 --- a/net/core/scm.c
97435 +++ b/net/core/scm.c
97436 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97437 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97438 {
97439 struct cmsghdr __user *cm
97440 - = (__force struct cmsghdr __user *)msg->msg_control;
97441 + = (struct cmsghdr __force_user *)msg->msg_control;
97442 struct cmsghdr cmhdr;
97443 int cmlen = CMSG_LEN(len);
97444 int err;
97445 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97446 err = -EFAULT;
97447 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97448 goto out;
97449 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97450 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97451 goto out;
97452 cmlen = CMSG_SPACE(len);
97453 if (msg->msg_controllen < cmlen)
97454 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97455 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97456 {
97457 struct cmsghdr __user *cm
97458 - = (__force struct cmsghdr __user*)msg->msg_control;
97459 + = (struct cmsghdr __force_user *)msg->msg_control;
97460
97461 int fdmax = 0;
97462 int fdnum = scm->fp->count;
97463 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97464 if (fdnum < fdmax)
97465 fdmax = fdnum;
97466
97467 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97468 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97469 i++, cmfptr++)
97470 {
97471 struct socket *sock;
97472 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97473 index deffb37..213db0a 100644
97474 --- a/net/core/skbuff.c
97475 +++ b/net/core/skbuff.c
97476 @@ -2006,7 +2006,7 @@ EXPORT_SYMBOL(__skb_checksum);
97477 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97478 int len, __wsum csum)
97479 {
97480 - const struct skb_checksum_ops ops = {
97481 + static const struct skb_checksum_ops ops = {
97482 .update = csum_partial_ext,
97483 .combine = csum_block_add_ext,
97484 };
97485 @@ -3119,13 +3119,15 @@ void __init skb_init(void)
97486 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97487 sizeof(struct sk_buff),
97488 0,
97489 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97490 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97491 + SLAB_NO_SANITIZE,
97492 NULL);
97493 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97494 (2*sizeof(struct sk_buff)) +
97495 sizeof(atomic_t),
97496 0,
97497 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97498 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97499 + SLAB_NO_SANITIZE,
97500 NULL);
97501 }
97502
97503 diff --git a/net/core/sock.c b/net/core/sock.c
97504 index fbc5cfb..6d7e8c3 100644
97505 --- a/net/core/sock.c
97506 +++ b/net/core/sock.c
97507 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97508 struct sk_buff_head *list = &sk->sk_receive_queue;
97509
97510 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97511 - atomic_inc(&sk->sk_drops);
97512 + atomic_inc_unchecked(&sk->sk_drops);
97513 trace_sock_rcvqueue_full(sk, skb);
97514 return -ENOMEM;
97515 }
97516 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97517 return err;
97518
97519 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97520 - atomic_inc(&sk->sk_drops);
97521 + atomic_inc_unchecked(&sk->sk_drops);
97522 return -ENOBUFS;
97523 }
97524
97525 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97526 skb_dst_force(skb);
97527
97528 spin_lock_irqsave(&list->lock, flags);
97529 - skb->dropcount = atomic_read(&sk->sk_drops);
97530 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97531 __skb_queue_tail(list, skb);
97532 spin_unlock_irqrestore(&list->lock, flags);
97533
97534 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97535 skb->dev = NULL;
97536
97537 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97538 - atomic_inc(&sk->sk_drops);
97539 + atomic_inc_unchecked(&sk->sk_drops);
97540 goto discard_and_relse;
97541 }
97542 if (nested)
97543 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97544 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97545 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97546 bh_unlock_sock(sk);
97547 - atomic_inc(&sk->sk_drops);
97548 + atomic_inc_unchecked(&sk->sk_drops);
97549 goto discard_and_relse;
97550 }
97551
97552 @@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97553 struct timeval tm;
97554 } v;
97555
97556 - int lv = sizeof(int);
97557 - int len;
97558 + unsigned int lv = sizeof(int);
97559 + unsigned int len;
97560
97561 if (get_user(len, optlen))
97562 return -EFAULT;
97563 - if (len < 0)
97564 + if (len > INT_MAX)
97565 return -EINVAL;
97566
97567 memset(&v, 0, sizeof(v));
97568 @@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97569
97570 case SO_PEERNAME:
97571 {
97572 - char address[128];
97573 + char address[_K_SS_MAXSIZE];
97574
97575 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97576 return -ENOTCONN;
97577 - if (lv < len)
97578 + if (lv < len || sizeof address < len)
97579 return -EINVAL;
97580 if (copy_to_user(optval, address, len))
97581 return -EFAULT;
97582 @@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97583
97584 if (len > lv)
97585 len = lv;
97586 - if (copy_to_user(optval, &v, len))
97587 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
97588 return -EFAULT;
97589 lenout:
97590 if (put_user(len, optlen))
97591 @@ -2353,7 +2353,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97592 */
97593 smp_wmb();
97594 atomic_set(&sk->sk_refcnt, 1);
97595 - atomic_set(&sk->sk_drops, 0);
97596 + atomic_set_unchecked(&sk->sk_drops, 0);
97597 }
97598 EXPORT_SYMBOL(sock_init_data);
97599
97600 @@ -2478,6 +2478,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97601 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97602 int level, int type)
97603 {
97604 + struct sock_extended_err ee;
97605 struct sock_exterr_skb *serr;
97606 struct sk_buff *skb, *skb2;
97607 int copied, err;
97608 @@ -2499,7 +2500,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97609 sock_recv_timestamp(msg, sk, skb);
97610
97611 serr = SKB_EXT_ERR(skb);
97612 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97613 + ee = serr->ee;
97614 + put_cmsg(msg, level, type, sizeof ee, &ee);
97615
97616 msg->msg_flags |= MSG_ERRQUEUE;
97617 err = copied;
97618 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97619 index a0e9cf6..ef7f9ed 100644
97620 --- a/net/core/sock_diag.c
97621 +++ b/net/core/sock_diag.c
97622 @@ -9,26 +9,33 @@
97623 #include <linux/inet_diag.h>
97624 #include <linux/sock_diag.h>
97625
97626 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97627 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97628 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97629 static DEFINE_MUTEX(sock_diag_table_mutex);
97630
97631 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97632 {
97633 +#ifndef CONFIG_GRKERNSEC_HIDESYM
97634 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97635 cookie[1] != INET_DIAG_NOCOOKIE) &&
97636 ((u32)(unsigned long)sk != cookie[0] ||
97637 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97638 return -ESTALE;
97639 else
97640 +#endif
97641 return 0;
97642 }
97643 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97644
97645 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97646 {
97647 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97648 + cookie[0] = 0;
97649 + cookie[1] = 0;
97650 +#else
97651 cookie[0] = (u32)(unsigned long)sk;
97652 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97653 +#endif
97654 }
97655 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97656
97657 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97658 mutex_lock(&sock_diag_table_mutex);
97659 if (sock_diag_handlers[hndl->family])
97660 err = -EBUSY;
97661 - else
97662 + else {
97663 + pax_open_kernel();
97664 sock_diag_handlers[hndl->family] = hndl;
97665 + pax_close_kernel();
97666 + }
97667 mutex_unlock(&sock_diag_table_mutex);
97668
97669 return err;
97670 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97671
97672 mutex_lock(&sock_diag_table_mutex);
97673 BUG_ON(sock_diag_handlers[family] != hnld);
97674 + pax_open_kernel();
97675 sock_diag_handlers[family] = NULL;
97676 + pax_close_kernel();
97677 mutex_unlock(&sock_diag_table_mutex);
97678 }
97679 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97680 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97681 index cca4441..5e616de 100644
97682 --- a/net/core/sysctl_net_core.c
97683 +++ b/net/core/sysctl_net_core.c
97684 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97685 {
97686 unsigned int orig_size, size;
97687 int ret, i;
97688 - struct ctl_table tmp = {
97689 + ctl_table_no_const tmp = {
97690 .data = &size,
97691 .maxlen = sizeof(size),
97692 .mode = table->mode
97693 @@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97694 void __user *buffer, size_t *lenp, loff_t *ppos)
97695 {
97696 char id[IFNAMSIZ];
97697 - struct ctl_table tbl = {
97698 + ctl_table_no_const tbl = {
97699 .data = id,
97700 .maxlen = IFNAMSIZ,
97701 };
97702 @@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
97703
97704 static __net_init int sysctl_core_net_init(struct net *net)
97705 {
97706 - struct ctl_table *tbl;
97707 + ctl_table_no_const *tbl = NULL;
97708
97709 net->core.sysctl_somaxconn = SOMAXCONN;
97710
97711 - tbl = netns_core_table;
97712 if (!net_eq(net, &init_net)) {
97713 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97714 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97715 if (tbl == NULL)
97716 goto err_dup;
97717
97718 @@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
97719 if (net->user_ns != &init_user_ns) {
97720 tbl[0].procname = NULL;
97721 }
97722 - }
97723 -
97724 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97725 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97726 + } else
97727 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
97728 if (net->core.sysctl_hdr == NULL)
97729 goto err_reg;
97730
97731 return 0;
97732
97733 err_reg:
97734 - if (tbl != netns_core_table)
97735 - kfree(tbl);
97736 + kfree(tbl);
97737 err_dup:
97738 return -ENOMEM;
97739 }
97740 @@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
97741 kfree(tbl);
97742 }
97743
97744 -static __net_initdata struct pernet_operations sysctl_core_ops = {
97745 +static __net_initconst struct pernet_operations sysctl_core_ops = {
97746 .init = sysctl_core_net_init,
97747 .exit = sysctl_core_net_exit,
97748 };
97749 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
97750 index dd4d506..fb2fb87 100644
97751 --- a/net/decnet/af_decnet.c
97752 +++ b/net/decnet/af_decnet.c
97753 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
97754 .sysctl_rmem = sysctl_decnet_rmem,
97755 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
97756 .obj_size = sizeof(struct dn_sock),
97757 + .slab_flags = SLAB_USERCOPY,
97758 };
97759
97760 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
97761 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
97762 index dd0dfb2..fdbc764 100644
97763 --- a/net/decnet/dn_dev.c
97764 +++ b/net/decnet/dn_dev.c
97765 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
97766 .extra1 = &min_t3,
97767 .extra2 = &max_t3
97768 },
97769 - {0}
97770 + { }
97771 },
97772 };
97773
97774 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
97775 index 5325b54..a0d4d69 100644
97776 --- a/net/decnet/sysctl_net_decnet.c
97777 +++ b/net/decnet/sysctl_net_decnet.c
97778 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
97779
97780 if (len > *lenp) len = *lenp;
97781
97782 - if (copy_to_user(buffer, addr, len))
97783 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
97784 return -EFAULT;
97785
97786 *lenp = len;
97787 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
97788
97789 if (len > *lenp) len = *lenp;
97790
97791 - if (copy_to_user(buffer, devname, len))
97792 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
97793 return -EFAULT;
97794
97795 *lenp = len;
97796 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
97797 index 1865fdf..581a595 100644
97798 --- a/net/ieee802154/dgram.c
97799 +++ b/net/ieee802154/dgram.c
97800 @@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
97801 if (saddr) {
97802 saddr->family = AF_IEEE802154;
97803 saddr->addr = mac_cb(skb)->sa;
97804 + }
97805 + if (addr_len)
97806 *addr_len = sizeof(*saddr);
97807 - }
97808
97809 if (flags & MSG_TRUNC)
97810 copied = skb->len;
97811 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
97812 index e4d96d4..e1651da 100644
97813 --- a/net/ipv4/af_inet.c
97814 +++ b/net/ipv4/af_inet.c
97815 @@ -1686,13 +1686,9 @@ static int __init inet_init(void)
97816
97817 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
97818
97819 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
97820 - if (!sysctl_local_reserved_ports)
97821 - goto out;
97822 -
97823 rc = proto_register(&tcp_prot, 1);
97824 if (rc)
97825 - goto out_free_reserved_ports;
97826 + goto out;
97827
97828 rc = proto_register(&udp_prot, 1);
97829 if (rc)
97830 @@ -1799,8 +1795,6 @@ out_unregister_udp_proto:
97831 proto_unregister(&udp_prot);
97832 out_unregister_tcp_proto:
97833 proto_unregister(&tcp_prot);
97834 -out_free_reserved_ports:
97835 - kfree(sysctl_local_reserved_ports);
97836 goto out;
97837 }
97838
97839 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
97840 index f4b34d8..c54a163 100644
97841 --- a/net/ipv4/devinet.c
97842 +++ b/net/ipv4/devinet.c
97843 @@ -1534,7 +1534,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
97844 idx = 0;
97845 head = &net->dev_index_head[h];
97846 rcu_read_lock();
97847 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97848 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97849 net->dev_base_seq;
97850 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97851 if (idx < s_idx)
97852 @@ -1845,7 +1845,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
97853 idx = 0;
97854 head = &net->dev_index_head[h];
97855 rcu_read_lock();
97856 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97857 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97858 net->dev_base_seq;
97859 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97860 if (idx < s_idx)
97861 @@ -2070,7 +2070,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
97862 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
97863 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
97864
97865 -static struct devinet_sysctl_table {
97866 +static const struct devinet_sysctl_table {
97867 struct ctl_table_header *sysctl_header;
97868 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
97869 } devinet_sysctl = {
97870 @@ -2192,7 +2192,7 @@ static __net_init int devinet_init_net(struct net *net)
97871 int err;
97872 struct ipv4_devconf *all, *dflt;
97873 #ifdef CONFIG_SYSCTL
97874 - struct ctl_table *tbl = ctl_forward_entry;
97875 + ctl_table_no_const *tbl = NULL;
97876 struct ctl_table_header *forw_hdr;
97877 #endif
97878
97879 @@ -2210,7 +2210,7 @@ static __net_init int devinet_init_net(struct net *net)
97880 goto err_alloc_dflt;
97881
97882 #ifdef CONFIG_SYSCTL
97883 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
97884 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
97885 if (tbl == NULL)
97886 goto err_alloc_ctl;
97887
97888 @@ -2230,7 +2230,10 @@ static __net_init int devinet_init_net(struct net *net)
97889 goto err_reg_dflt;
97890
97891 err = -ENOMEM;
97892 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97893 + if (!net_eq(net, &init_net))
97894 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97895 + else
97896 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
97897 if (forw_hdr == NULL)
97898 goto err_reg_ctl;
97899 net->ipv4.forw_hdr = forw_hdr;
97900 @@ -2246,8 +2249,7 @@ err_reg_ctl:
97901 err_reg_dflt:
97902 __devinet_sysctl_unregister(all);
97903 err_reg_all:
97904 - if (tbl != ctl_forward_entry)
97905 - kfree(tbl);
97906 + kfree(tbl);
97907 err_alloc_ctl:
97908 #endif
97909 if (dflt != &ipv4_devconf_dflt)
97910 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
97911 index c7539e2..b455e51 100644
97912 --- a/net/ipv4/fib_frontend.c
97913 +++ b/net/ipv4/fib_frontend.c
97914 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
97915 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97916 fib_sync_up(dev);
97917 #endif
97918 - atomic_inc(&net->ipv4.dev_addr_genid);
97919 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97920 rt_cache_flush(dev_net(dev));
97921 break;
97922 case NETDEV_DOWN:
97923 fib_del_ifaddr(ifa, NULL);
97924 - atomic_inc(&net->ipv4.dev_addr_genid);
97925 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97926 if (ifa->ifa_dev->ifa_list == NULL) {
97927 /* Last address was deleted from this interface.
97928 * Disable IP.
97929 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
97930 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97931 fib_sync_up(dev);
97932 #endif
97933 - atomic_inc(&net->ipv4.dev_addr_genid);
97934 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97935 rt_cache_flush(net);
97936 break;
97937 case NETDEV_DOWN:
97938 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
97939 index e63f47a..e5c531d 100644
97940 --- a/net/ipv4/fib_semantics.c
97941 +++ b/net/ipv4/fib_semantics.c
97942 @@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
97943 nh->nh_saddr = inet_select_addr(nh->nh_dev,
97944 nh->nh_gw,
97945 nh->nh_parent->fib_scope);
97946 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
97947 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
97948
97949 return nh->nh_saddr;
97950 }
97951 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
97952 index fc0e649..febfa65 100644
97953 --- a/net/ipv4/inet_connection_sock.c
97954 +++ b/net/ipv4/inet_connection_sock.c
97955 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
97956 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
97957 #endif
97958
97959 -unsigned long *sysctl_local_reserved_ports;
97960 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
97961 EXPORT_SYMBOL(sysctl_local_reserved_ports);
97962
97963 void inet_get_local_port_range(struct net *net, int *low, int *high)
97964 diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
97965 index bb075fc..322dceb 100644
97966 --- a/net/ipv4/inet_fragment.c
97967 +++ b/net/ipv4/inet_fragment.c
97968 @@ -278,9 +278,10 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
97969
97970 atomic_inc(&qp->refcnt);
97971 hlist_add_head(&qp->list, &hb->chain);
97972 - spin_unlock(&hb->chain_lock);
97973 - read_unlock(&f->lock);
97974 inet_frag_lru_add(nf, qp);
97975 + spin_unlock(&hb->chain_lock);
97976 + read_unlock(&f->lock);
97977 +
97978 return qp;
97979 }
97980
97981 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
97982 index 8b9cf27..0d8d592 100644
97983 --- a/net/ipv4/inet_hashtables.c
97984 +++ b/net/ipv4/inet_hashtables.c
97985 @@ -18,6 +18,7 @@
97986 #include <linux/sched.h>
97987 #include <linux/slab.h>
97988 #include <linux/wait.h>
97989 +#include <linux/security.h>
97990
97991 #include <net/inet_connection_sock.h>
97992 #include <net/inet_hashtables.h>
97993 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
97994 return inet_ehashfn(net, laddr, lport, faddr, fport);
97995 }
97996
97997 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
97998 +
97999 /*
98000 * Allocate and initialize a new local port bind bucket.
98001 * The bindhash mutex for snum's hash chain must be held here.
98002 @@ -554,6 +557,8 @@ ok:
98003 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
98004 spin_unlock(&head->lock);
98005
98006 + gr_update_task_in_ip_table(current, inet_sk(sk));
98007 +
98008 if (tw) {
98009 inet_twsk_deschedule(tw, death_row);
98010 while (twrefcnt) {
98011 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
98012 index 33d5537..da337a4 100644
98013 --- a/net/ipv4/inetpeer.c
98014 +++ b/net/ipv4/inetpeer.c
98015 @@ -503,8 +503,8 @@ relookup:
98016 if (p) {
98017 p->daddr = *daddr;
98018 atomic_set(&p->refcnt, 1);
98019 - atomic_set(&p->rid, 0);
98020 - atomic_set(&p->ip_id_count,
98021 + atomic_set_unchecked(&p->rid, 0);
98022 + atomic_set_unchecked(&p->ip_id_count,
98023 (daddr->family == AF_INET) ?
98024 secure_ip_id(daddr->addr.a4) :
98025 secure_ipv6_id(daddr->addr.a6));
98026 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
98027 index 2481993..2d9a7a7 100644
98028 --- a/net/ipv4/ip_fragment.c
98029 +++ b/net/ipv4/ip_fragment.c
98030 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
98031 return 0;
98032
98033 start = qp->rid;
98034 - end = atomic_inc_return(&peer->rid);
98035 + end = atomic_inc_return_unchecked(&peer->rid);
98036 qp->rid = end;
98037
98038 rc = qp->q.fragments && (end - start) > max;
98039 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
98040
98041 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98042 {
98043 - struct ctl_table *table;
98044 + ctl_table_no_const *table = NULL;
98045 struct ctl_table_header *hdr;
98046
98047 - table = ip4_frags_ns_ctl_table;
98048 if (!net_eq(net, &init_net)) {
98049 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98050 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98051 if (table == NULL)
98052 goto err_alloc;
98053
98054 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98055 /* Don't export sysctls to unprivileged users */
98056 if (net->user_ns != &init_user_ns)
98057 table[0].procname = NULL;
98058 - }
98059 + hdr = register_net_sysctl(net, "net/ipv4", table);
98060 + } else
98061 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
98062
98063 - hdr = register_net_sysctl(net, "net/ipv4", table);
98064 if (hdr == NULL)
98065 goto err_reg;
98066
98067 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98068 return 0;
98069
98070 err_reg:
98071 - if (!net_eq(net, &init_net))
98072 - kfree(table);
98073 + kfree(table);
98074 err_alloc:
98075 return -ENOMEM;
98076 }
98077 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
98078 index d306360..1c1a1f1 100644
98079 --- a/net/ipv4/ip_gre.c
98080 +++ b/net/ipv4/ip_gre.c
98081 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
98082 module_param(log_ecn_error, bool, 0644);
98083 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98084
98085 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
98086 +static struct rtnl_link_ops ipgre_link_ops;
98087 static int ipgre_tunnel_init(struct net_device *dev);
98088
98089 static int ipgre_net_id __read_mostly;
98090 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
98091 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
98092 };
98093
98094 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98095 +static struct rtnl_link_ops ipgre_link_ops = {
98096 .kind = "gre",
98097 .maxtype = IFLA_GRE_MAX,
98098 .policy = ipgre_policy,
98099 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98100 .fill_info = ipgre_fill_info,
98101 };
98102
98103 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
98104 +static struct rtnl_link_ops ipgre_tap_ops = {
98105 .kind = "gretap",
98106 .maxtype = IFLA_GRE_MAX,
98107 .policy = ipgre_policy,
98108 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
98109 index ddf32a6..3fdeea9 100644
98110 --- a/net/ipv4/ip_sockglue.c
98111 +++ b/net/ipv4/ip_sockglue.c
98112 @@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98113 len = min_t(unsigned int, len, opt->optlen);
98114 if (put_user(len, optlen))
98115 return -EFAULT;
98116 - if (copy_to_user(optval, opt->__data, len))
98117 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
98118 + copy_to_user(optval, opt->__data, len))
98119 return -EFAULT;
98120 return 0;
98121 }
98122 @@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98123 if (sk->sk_type != SOCK_STREAM)
98124 return -ENOPROTOOPT;
98125
98126 - msg.msg_control = optval;
98127 + msg.msg_control = (void __force_kernel *)optval;
98128 msg.msg_controllen = len;
98129 msg.msg_flags = flags;
98130
98131 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
98132 index 52b802a..b725179 100644
98133 --- a/net/ipv4/ip_vti.c
98134 +++ b/net/ipv4/ip_vti.c
98135 @@ -44,7 +44,7 @@
98136 #include <net/net_namespace.h>
98137 #include <net/netns/generic.h>
98138
98139 -static struct rtnl_link_ops vti_link_ops __read_mostly;
98140 +static struct rtnl_link_ops vti_link_ops;
98141
98142 static int vti_net_id __read_mostly;
98143 static int vti_tunnel_init(struct net_device *dev);
98144 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
98145 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
98146 };
98147
98148 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
98149 +static struct rtnl_link_ops vti_link_ops = {
98150 .kind = "vti",
98151 .maxtype = IFLA_VTI_MAX,
98152 .policy = vti_policy,
98153 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
98154 index efa1138..20dbba0 100644
98155 --- a/net/ipv4/ipconfig.c
98156 +++ b/net/ipv4/ipconfig.c
98157 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
98158
98159 mm_segment_t oldfs = get_fs();
98160 set_fs(get_ds());
98161 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98162 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98163 set_fs(oldfs);
98164 return res;
98165 }
98166 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
98167
98168 mm_segment_t oldfs = get_fs();
98169 set_fs(get_ds());
98170 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98171 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98172 set_fs(oldfs);
98173 return res;
98174 }
98175 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
98176
98177 mm_segment_t oldfs = get_fs();
98178 set_fs(get_ds());
98179 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
98180 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
98181 set_fs(oldfs);
98182 return res;
98183 }
98184 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
98185 index fe3e9f7..4956990 100644
98186 --- a/net/ipv4/ipip.c
98187 +++ b/net/ipv4/ipip.c
98188 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98189 static int ipip_net_id __read_mostly;
98190
98191 static int ipip_tunnel_init(struct net_device *dev);
98192 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
98193 +static struct rtnl_link_ops ipip_link_ops;
98194
98195 static int ipip_err(struct sk_buff *skb, u32 info)
98196 {
98197 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
98198 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
98199 };
98200
98201 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
98202 +static struct rtnl_link_ops ipip_link_ops = {
98203 .kind = "ipip",
98204 .maxtype = IFLA_IPTUN_MAX,
98205 .policy = ipip_policy,
98206 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
98207 index 59da7cd..e318de1 100644
98208 --- a/net/ipv4/netfilter/arp_tables.c
98209 +++ b/net/ipv4/netfilter/arp_tables.c
98210 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
98211 #endif
98212
98213 static int get_info(struct net *net, void __user *user,
98214 - const int *len, int compat)
98215 + int len, int compat)
98216 {
98217 char name[XT_TABLE_MAXNAMELEN];
98218 struct xt_table *t;
98219 int ret;
98220
98221 - if (*len != sizeof(struct arpt_getinfo)) {
98222 - duprintf("length %u != %Zu\n", *len,
98223 + if (len != sizeof(struct arpt_getinfo)) {
98224 + duprintf("length %u != %Zu\n", len,
98225 sizeof(struct arpt_getinfo));
98226 return -EINVAL;
98227 }
98228 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
98229 info.size = private->size;
98230 strcpy(info.name, name);
98231
98232 - if (copy_to_user(user, &info, *len) != 0)
98233 + if (copy_to_user(user, &info, len) != 0)
98234 ret = -EFAULT;
98235 else
98236 ret = 0;
98237 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
98238
98239 switch (cmd) {
98240 case ARPT_SO_GET_INFO:
98241 - ret = get_info(sock_net(sk), user, len, 1);
98242 + ret = get_info(sock_net(sk), user, *len, 1);
98243 break;
98244 case ARPT_SO_GET_ENTRIES:
98245 ret = compat_get_entries(sock_net(sk), user, len);
98246 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
98247
98248 switch (cmd) {
98249 case ARPT_SO_GET_INFO:
98250 - ret = get_info(sock_net(sk), user, len, 0);
98251 + ret = get_info(sock_net(sk), user, *len, 0);
98252 break;
98253
98254 case ARPT_SO_GET_ENTRIES:
98255 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98256 index 718dfbd..cef4152 100644
98257 --- a/net/ipv4/netfilter/ip_tables.c
98258 +++ b/net/ipv4/netfilter/ip_tables.c
98259 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98260 #endif
98261
98262 static int get_info(struct net *net, void __user *user,
98263 - const int *len, int compat)
98264 + int len, int compat)
98265 {
98266 char name[XT_TABLE_MAXNAMELEN];
98267 struct xt_table *t;
98268 int ret;
98269
98270 - if (*len != sizeof(struct ipt_getinfo)) {
98271 - duprintf("length %u != %zu\n", *len,
98272 + if (len != sizeof(struct ipt_getinfo)) {
98273 + duprintf("length %u != %zu\n", len,
98274 sizeof(struct ipt_getinfo));
98275 return -EINVAL;
98276 }
98277 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98278 info.size = private->size;
98279 strcpy(info.name, name);
98280
98281 - if (copy_to_user(user, &info, *len) != 0)
98282 + if (copy_to_user(user, &info, len) != 0)
98283 ret = -EFAULT;
98284 else
98285 ret = 0;
98286 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98287
98288 switch (cmd) {
98289 case IPT_SO_GET_INFO:
98290 - ret = get_info(sock_net(sk), user, len, 1);
98291 + ret = get_info(sock_net(sk), user, *len, 1);
98292 break;
98293 case IPT_SO_GET_ENTRIES:
98294 ret = compat_get_entries(sock_net(sk), user, len);
98295 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98296
98297 switch (cmd) {
98298 case IPT_SO_GET_INFO:
98299 - ret = get_info(sock_net(sk), user, len, 0);
98300 + ret = get_info(sock_net(sk), user, *len, 0);
98301 break;
98302
98303 case IPT_SO_GET_ENTRIES:
98304 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98305 index 242e7f4..76cc7ee 100644
98306 --- a/net/ipv4/ping.c
98307 +++ b/net/ipv4/ping.c
98308 @@ -55,7 +55,7 @@
98309
98310
98311 struct ping_table ping_table;
98312 -struct pingv6_ops pingv6_ops;
98313 +struct pingv6_ops *pingv6_ops;
98314 EXPORT_SYMBOL_GPL(pingv6_ops);
98315
98316 static u16 ping_port_rover;
98317 @@ -251,23 +251,28 @@ int ping_init_sock(struct sock *sk)
98318 struct group_info *group_info = get_current_groups();
98319 int i, j, count = group_info->ngroups;
98320 kgid_t low, high;
98321 + int ret = 0;
98322
98323 inet_get_ping_group_range_net(net, &low, &high);
98324 if (gid_lte(low, group) && gid_lte(group, high))
98325 - return 0;
98326 + goto out_release_group;
98327
98328 for (i = 0; i < group_info->nblocks; i++) {
98329 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
98330 for (j = 0; j < cp_count; j++) {
98331 kgid_t gid = group_info->blocks[i][j];
98332 if (gid_lte(low, gid) && gid_lte(gid, high))
98333 - return 0;
98334 + goto out_release_group;
98335 }
98336
98337 count -= cp_count;
98338 }
98339
98340 - return -EACCES;
98341 + ret = -EACCES;
98342 +
98343 +out_release_group:
98344 + put_group_info(group_info);
98345 + return ret;
98346 }
98347 EXPORT_SYMBOL_GPL(ping_init_sock);
98348
98349 @@ -334,7 +339,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98350 return -ENODEV;
98351 }
98352 }
98353 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98354 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98355 scoped);
98356 rcu_read_unlock();
98357
98358 @@ -542,7 +547,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98359 }
98360 #if IS_ENABLED(CONFIG_IPV6)
98361 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98362 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98363 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98364 #endif
98365 }
98366
98367 @@ -560,7 +565,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98368 info, (u8 *)icmph);
98369 #if IS_ENABLED(CONFIG_IPV6)
98370 } else if (family == AF_INET6) {
98371 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98372 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98373 info, (u8 *)icmph);
98374 #endif
98375 }
98376 @@ -830,6 +835,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98377 {
98378 struct inet_sock *isk = inet_sk(sk);
98379 int family = sk->sk_family;
98380 + struct sockaddr_in *sin;
98381 + struct sockaddr_in6 *sin6;
98382 struct sk_buff *skb;
98383 int copied, err;
98384
98385 @@ -839,12 +846,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98386 if (flags & MSG_OOB)
98387 goto out;
98388
98389 + if (addr_len) {
98390 + if (family == AF_INET)
98391 + *addr_len = sizeof(*sin);
98392 + else if (family == AF_INET6 && addr_len)
98393 + *addr_len = sizeof(*sin6);
98394 + }
98395 +
98396 if (flags & MSG_ERRQUEUE) {
98397 if (family == AF_INET) {
98398 return ip_recv_error(sk, msg, len, addr_len);
98399 #if IS_ENABLED(CONFIG_IPV6)
98400 } else if (family == AF_INET6) {
98401 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
98402 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
98403 addr_len);
98404 #endif
98405 }
98406 @@ -876,7 +890,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98407 sin->sin_port = 0 /* skb->h.uh->source */;
98408 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98409 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98410 - *addr_len = sizeof(*sin);
98411 }
98412
98413 if (isk->cmsg_flags)
98414 @@ -899,11 +912,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98415 sin6->sin6_scope_id =
98416 ipv6_iface_scope_id(&sin6->sin6_addr,
98417 IP6CB(skb)->iif);
98418 - *addr_len = sizeof(*sin6);
98419 }
98420
98421 if (inet6_sk(sk)->rxopt.all)
98422 - pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
98423 + pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
98424 #endif
98425 } else {
98426 BUG();
98427 @@ -1093,7 +1105,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98428 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98429 0, sock_i_ino(sp),
98430 atomic_read(&sp->sk_refcnt), sp,
98431 - atomic_read(&sp->sk_drops));
98432 + atomic_read_unchecked(&sp->sk_drops));
98433 }
98434
98435 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98436 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98437 index 23c3e5b..cdb8b36 100644
98438 --- a/net/ipv4/raw.c
98439 +++ b/net/ipv4/raw.c
98440 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98441 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98442 {
98443 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98444 - atomic_inc(&sk->sk_drops);
98445 + atomic_inc_unchecked(&sk->sk_drops);
98446 kfree_skb(skb);
98447 return NET_RX_DROP;
98448 }
98449 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98450 if (flags & MSG_OOB)
98451 goto out;
98452
98453 + if (addr_len)
98454 + *addr_len = sizeof(*sin);
98455 +
98456 if (flags & MSG_ERRQUEUE) {
98457 err = ip_recv_error(sk, msg, len, addr_len);
98458 goto out;
98459 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98460 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98461 sin->sin_port = 0;
98462 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98463 - *addr_len = sizeof(*sin);
98464 }
98465 if (inet->cmsg_flags)
98466 ip_cmsg_recv(msg, skb);
98467 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98468
98469 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98470 {
98471 + struct icmp_filter filter;
98472 +
98473 if (optlen > sizeof(struct icmp_filter))
98474 optlen = sizeof(struct icmp_filter);
98475 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98476 + if (copy_from_user(&filter, optval, optlen))
98477 return -EFAULT;
98478 + raw_sk(sk)->filter = filter;
98479 return 0;
98480 }
98481
98482 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98483 {
98484 int len, ret = -EFAULT;
98485 + struct icmp_filter filter;
98486
98487 if (get_user(len, optlen))
98488 goto out;
98489 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98490 if (len > sizeof(struct icmp_filter))
98491 len = sizeof(struct icmp_filter);
98492 ret = -EFAULT;
98493 - if (put_user(len, optlen) ||
98494 - copy_to_user(optval, &raw_sk(sk)->filter, len))
98495 + filter = raw_sk(sk)->filter;
98496 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98497 goto out;
98498 ret = 0;
98499 out: return ret;
98500 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98501 0, 0L, 0,
98502 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98503 0, sock_i_ino(sp),
98504 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98505 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98506 }
98507
98508 static int raw_seq_show(struct seq_file *seq, void *v)
98509 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98510 index e611651f..0c17263 100644
98511 --- a/net/ipv4/route.c
98512 +++ b/net/ipv4/route.c
98513 @@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98514 .maxlen = sizeof(int),
98515 .mode = 0200,
98516 .proc_handler = ipv4_sysctl_rtcache_flush,
98517 + .extra1 = &init_net,
98518 },
98519 { },
98520 };
98521
98522 static __net_init int sysctl_route_net_init(struct net *net)
98523 {
98524 - struct ctl_table *tbl;
98525 + ctl_table_no_const *tbl = NULL;
98526
98527 - tbl = ipv4_route_flush_table;
98528 if (!net_eq(net, &init_net)) {
98529 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98530 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98531 if (tbl == NULL)
98532 goto err_dup;
98533
98534 /* Don't export sysctls to unprivileged users */
98535 if (net->user_ns != &init_user_ns)
98536 tbl[0].procname = NULL;
98537 - }
98538 - tbl[0].extra1 = net;
98539 + tbl[0].extra1 = net;
98540 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98541 + } else
98542 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98543
98544 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98545 if (net->ipv4.route_hdr == NULL)
98546 goto err_reg;
98547 return 0;
98548
98549 err_reg:
98550 - if (tbl != ipv4_route_flush_table)
98551 - kfree(tbl);
98552 + kfree(tbl);
98553 err_dup:
98554 return -ENOMEM;
98555 }
98556 @@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98557
98558 static __net_init int rt_genid_init(struct net *net)
98559 {
98560 - atomic_set(&net->ipv4.rt_genid, 0);
98561 - atomic_set(&net->fnhe_genid, 0);
98562 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98563 + atomic_set_unchecked(&net->fnhe_genid, 0);
98564 get_random_bytes(&net->ipv4.dev_addr_genid,
98565 sizeof(net->ipv4.dev_addr_genid));
98566 return 0;
98567 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98568 index 3d69ec8..57207b4 100644
98569 --- a/net/ipv4/sysctl_net_ipv4.c
98570 +++ b/net/ipv4/sysctl_net_ipv4.c
98571 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98572 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98573 int ret;
98574 int range[2];
98575 - struct ctl_table tmp = {
98576 + ctl_table_no_const tmp = {
98577 .data = &range,
98578 .maxlen = sizeof(range),
98579 .mode = table->mode,
98580 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98581 int ret;
98582 gid_t urange[2];
98583 kgid_t low, high;
98584 - struct ctl_table tmp = {
98585 + ctl_table_no_const tmp = {
98586 .data = &urange,
98587 .maxlen = sizeof(urange),
98588 .mode = table->mode,
98589 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98590 void __user *buffer, size_t *lenp, loff_t *ppos)
98591 {
98592 char val[TCP_CA_NAME_MAX];
98593 - struct ctl_table tbl = {
98594 + ctl_table_no_const tbl = {
98595 .data = val,
98596 .maxlen = TCP_CA_NAME_MAX,
98597 };
98598 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98599 void __user *buffer, size_t *lenp,
98600 loff_t *ppos)
98601 {
98602 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98603 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98604 int ret;
98605
98606 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98607 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98608 void __user *buffer, size_t *lenp,
98609 loff_t *ppos)
98610 {
98611 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98612 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98613 int ret;
98614
98615 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98616 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98617 void __user *buffer, size_t *lenp,
98618 loff_t *ppos)
98619 {
98620 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98621 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98622 struct tcp_fastopen_context *ctxt;
98623 int ret;
98624 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98625 @@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
98626 },
98627 {
98628 .procname = "ip_local_reserved_ports",
98629 - .data = NULL, /* initialized in sysctl_ipv4_init */
98630 + .data = sysctl_local_reserved_ports,
98631 .maxlen = 65536,
98632 .mode = 0644,
98633 .proc_handler = proc_do_large_bitmap,
98634 @@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
98635
98636 static __net_init int ipv4_sysctl_init_net(struct net *net)
98637 {
98638 - struct ctl_table *table;
98639 + ctl_table_no_const *table = NULL;
98640
98641 - table = ipv4_net_table;
98642 if (!net_eq(net, &init_net)) {
98643 int i;
98644
98645 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98646 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98647 if (table == NULL)
98648 goto err_alloc;
98649
98650 @@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98651 net->ipv4.sysctl_local_ports.range[0] = 32768;
98652 net->ipv4.sysctl_local_ports.range[1] = 61000;
98653
98654 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98655 + if (!net_eq(net, &init_net))
98656 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98657 + else
98658 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98659 if (net->ipv4.ipv4_hdr == NULL)
98660 goto err_reg;
98661
98662 return 0;
98663
98664 err_reg:
98665 - if (!net_eq(net, &init_net))
98666 - kfree(table);
98667 + kfree(table);
98668 err_alloc:
98669 return -ENOMEM;
98670 }
98671 @@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98672 static __init int sysctl_ipv4_init(void)
98673 {
98674 struct ctl_table_header *hdr;
98675 - struct ctl_table *i;
98676 -
98677 - for (i = ipv4_table; i->procname; i++) {
98678 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98679 - i->data = sysctl_local_reserved_ports;
98680 - break;
98681 - }
98682 - }
98683 - if (!i->procname)
98684 - return -EINVAL;
98685
98686 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98687 if (hdr == NULL)
98688 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98689 index c53b7f3..a89aadd 100644
98690 --- a/net/ipv4/tcp_input.c
98691 +++ b/net/ipv4/tcp_input.c
98692 @@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
98693 * without any lock. We want to make sure compiler wont store
98694 * intermediate values in this location.
98695 */
98696 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
98697 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
98698 sk->sk_max_pacing_rate);
98699 }
98700
98701 @@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
98702 * simplifies code)
98703 */
98704 static void
98705 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98706 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98707 struct sk_buff *head, struct sk_buff *tail,
98708 u32 start, u32 end)
98709 {
98710 @@ -5559,6 +5559,7 @@ discard:
98711 tcp_paws_reject(&tp->rx_opt, 0))
98712 goto discard_and_undo;
98713
98714 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
98715 if (th->syn) {
98716 /* We see SYN without ACK. It is attempt of
98717 * simultaneous connect with crossed SYNs.
98718 @@ -5609,6 +5610,7 @@ discard:
98719 goto discard;
98720 #endif
98721 }
98722 +#endif
98723 /* "fifth, if neither of the SYN or RST bits is set then
98724 * drop the segment and return."
98725 */
98726 @@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
98727 goto discard;
98728
98729 if (th->syn) {
98730 - if (th->fin)
98731 + if (th->fin || th->urg || th->psh)
98732 goto discard;
98733 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
98734 return 1;
98735 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
98736 index 0672139..cacc17d 100644
98737 --- a/net/ipv4/tcp_ipv4.c
98738 +++ b/net/ipv4/tcp_ipv4.c
98739 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
98740 EXPORT_SYMBOL(sysctl_tcp_low_latency);
98741
98742
98743 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98744 +extern int grsec_enable_blackhole;
98745 +#endif
98746 +
98747 #ifdef CONFIG_TCP_MD5SIG
98748 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
98749 __be32 daddr, __be32 saddr, const struct tcphdr *th);
98750 @@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
98751 return 0;
98752
98753 reset:
98754 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98755 + if (!grsec_enable_blackhole)
98756 +#endif
98757 tcp_v4_send_reset(rsk, skb);
98758 discard:
98759 kfree_skb(skb);
98760 @@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
98761 TCP_SKB_CB(skb)->sacked = 0;
98762
98763 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98764 - if (!sk)
98765 + if (!sk) {
98766 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98767 + ret = 1;
98768 +#endif
98769 goto no_tcp_socket;
98770 -
98771 + }
98772 process:
98773 - if (sk->sk_state == TCP_TIME_WAIT)
98774 + if (sk->sk_state == TCP_TIME_WAIT) {
98775 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98776 + ret = 2;
98777 +#endif
98778 goto do_time_wait;
98779 + }
98780
98781 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
98782 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98783 @@ -2034,6 +2048,10 @@ csum_error:
98784 bad_packet:
98785 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98786 } else {
98787 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98788 + if (!grsec_enable_blackhole || (ret == 1 &&
98789 + (skb->dev->flags & IFF_LOOPBACK)))
98790 +#endif
98791 tcp_v4_send_reset(NULL, skb);
98792 }
98793
98794 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
98795 index 97b6841..0893357 100644
98796 --- a/net/ipv4/tcp_minisocks.c
98797 +++ b/net/ipv4/tcp_minisocks.c
98798 @@ -27,6 +27,10 @@
98799 #include <net/inet_common.h>
98800 #include <net/xfrm.h>
98801
98802 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98803 +extern int grsec_enable_blackhole;
98804 +#endif
98805 +
98806 int sysctl_tcp_syncookies __read_mostly = 1;
98807 EXPORT_SYMBOL(sysctl_tcp_syncookies);
98808
98809 @@ -708,7 +712,10 @@ embryonic_reset:
98810 * avoid becoming vulnerable to outside attack aiming at
98811 * resetting legit local connections.
98812 */
98813 - req->rsk_ops->send_reset(sk, skb);
98814 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98815 + if (!grsec_enable_blackhole)
98816 +#endif
98817 + req->rsk_ops->send_reset(sk, skb);
98818 } else if (fastopen) { /* received a valid RST pkt */
98819 reqsk_fastopen_remove(sk, req, true);
98820 tcp_reset(sk);
98821 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
98822 index 8b97d71..9d7ccf5 100644
98823 --- a/net/ipv4/tcp_probe.c
98824 +++ b/net/ipv4/tcp_probe.c
98825 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
98826 if (cnt + width >= len)
98827 break;
98828
98829 - if (copy_to_user(buf + cnt, tbuf, width))
98830 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
98831 return -EFAULT;
98832 cnt += width;
98833 }
98834 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
98835 index 64f0354..a81b39d 100644
98836 --- a/net/ipv4/tcp_timer.c
98837 +++ b/net/ipv4/tcp_timer.c
98838 @@ -22,6 +22,10 @@
98839 #include <linux/gfp.h>
98840 #include <net/tcp.h>
98841
98842 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98843 +extern int grsec_lastack_retries;
98844 +#endif
98845 +
98846 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
98847 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
98848 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
98849 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
98850 }
98851 }
98852
98853 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98854 + if ((sk->sk_state == TCP_LAST_ACK) &&
98855 + (grsec_lastack_retries > 0) &&
98856 + (grsec_lastack_retries < retry_until))
98857 + retry_until = grsec_lastack_retries;
98858 +#endif
98859 +
98860 if (retransmits_timed_out(sk, retry_until,
98861 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
98862 /* Has it gone just too far? */
98863 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
98864 index a7e4729..2758946 100644
98865 --- a/net/ipv4/udp.c
98866 +++ b/net/ipv4/udp.c
98867 @@ -87,6 +87,7 @@
98868 #include <linux/types.h>
98869 #include <linux/fcntl.h>
98870 #include <linux/module.h>
98871 +#include <linux/security.h>
98872 #include <linux/socket.h>
98873 #include <linux/sockios.h>
98874 #include <linux/igmp.h>
98875 @@ -113,6 +114,10 @@
98876 #include <net/busy_poll.h>
98877 #include "udp_impl.h"
98878
98879 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98880 +extern int grsec_enable_blackhole;
98881 +#endif
98882 +
98883 struct udp_table udp_table __read_mostly;
98884 EXPORT_SYMBOL(udp_table);
98885
98886 @@ -615,6 +620,9 @@ found:
98887 return s;
98888 }
98889
98890 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
98891 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
98892 +
98893 /*
98894 * This routine is called by the ICMP module when it gets some
98895 * sort of error condition. If err < 0 then the socket should
98896 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98897 dport = usin->sin_port;
98898 if (dport == 0)
98899 return -EINVAL;
98900 +
98901 + err = gr_search_udp_sendmsg(sk, usin);
98902 + if (err)
98903 + return err;
98904 } else {
98905 if (sk->sk_state != TCP_ESTABLISHED)
98906 return -EDESTADDRREQ;
98907 +
98908 + err = gr_search_udp_sendmsg(sk, NULL);
98909 + if (err)
98910 + return err;
98911 +
98912 daddr = inet->inet_daddr;
98913 dport = inet->inet_dport;
98914 /* Open fast path for connected socket.
98915 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
98916 IS_UDPLITE(sk));
98917 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98918 IS_UDPLITE(sk));
98919 - atomic_inc(&sk->sk_drops);
98920 + atomic_inc_unchecked(&sk->sk_drops);
98921 __skb_unlink(skb, rcvq);
98922 __skb_queue_tail(&list_kill, skb);
98923 }
98924 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98925 int is_udplite = IS_UDPLITE(sk);
98926 bool slow;
98927
98928 + /*
98929 + * Check any passed addresses
98930 + */
98931 + if (addr_len)
98932 + *addr_len = sizeof(*sin);
98933 +
98934 if (flags & MSG_ERRQUEUE)
98935 return ip_recv_error(sk, msg, len, addr_len);
98936
98937 @@ -1243,6 +1266,10 @@ try_again:
98938 if (!skb)
98939 goto out;
98940
98941 + err = gr_search_udp_recvmsg(sk, skb);
98942 + if (err)
98943 + goto out_free;
98944 +
98945 ulen = skb->len - sizeof(struct udphdr);
98946 copied = len;
98947 if (copied > ulen)
98948 @@ -1276,7 +1303,7 @@ try_again:
98949 if (unlikely(err)) {
98950 trace_kfree_skb(skb, udp_recvmsg);
98951 if (!peeked) {
98952 - atomic_inc(&sk->sk_drops);
98953 + atomic_inc_unchecked(&sk->sk_drops);
98954 UDP_INC_STATS_USER(sock_net(sk),
98955 UDP_MIB_INERRORS, is_udplite);
98956 }
98957 @@ -1295,7 +1322,6 @@ try_again:
98958 sin->sin_port = udp_hdr(skb)->source;
98959 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98960 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98961 - *addr_len = sizeof(*sin);
98962 }
98963 if (inet->cmsg_flags)
98964 ip_cmsg_recv(msg, skb);
98965 @@ -1566,7 +1592,7 @@ csum_error:
98966 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98967 drop:
98968 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98969 - atomic_inc(&sk->sk_drops);
98970 + atomic_inc_unchecked(&sk->sk_drops);
98971 kfree_skb(skb);
98972 return -1;
98973 }
98974 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98975 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98976
98977 if (!skb1) {
98978 - atomic_inc(&sk->sk_drops);
98979 + atomic_inc_unchecked(&sk->sk_drops);
98980 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98981 IS_UDPLITE(sk));
98982 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98983 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98984 goto csum_error;
98985
98986 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98987 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98988 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98989 +#endif
98990 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
98991
98992 /*
98993 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
98994 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98995 0, sock_i_ino(sp),
98996 atomic_read(&sp->sk_refcnt), sp,
98997 - atomic_read(&sp->sk_drops));
98998 + atomic_read_unchecked(&sp->sk_drops));
98999 }
99000
99001 int udp4_seq_show(struct seq_file *seq, void *v)
99002 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
99003 index e1a6393..f634ce5 100644
99004 --- a/net/ipv4/xfrm4_policy.c
99005 +++ b/net/ipv4/xfrm4_policy.c
99006 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
99007 fl4->flowi4_tos = iph->tos;
99008 }
99009
99010 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
99011 +static int xfrm4_garbage_collect(struct dst_ops *ops)
99012 {
99013 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
99014
99015 - xfrm4_policy_afinfo.garbage_collect(net);
99016 + xfrm_garbage_collect_deferred(net);
99017 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
99018 }
99019
99020 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
99021
99022 static int __net_init xfrm4_net_init(struct net *net)
99023 {
99024 - struct ctl_table *table;
99025 + ctl_table_no_const *table = NULL;
99026 struct ctl_table_header *hdr;
99027
99028 - table = xfrm4_policy_table;
99029 if (!net_eq(net, &init_net)) {
99030 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99031 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99032 if (!table)
99033 goto err_alloc;
99034
99035 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
99036 - }
99037 -
99038 - hdr = register_net_sysctl(net, "net/ipv4", table);
99039 + hdr = register_net_sysctl(net, "net/ipv4", table);
99040 + } else
99041 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
99042 if (!hdr)
99043 goto err_reg;
99044
99045 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
99046 return 0;
99047
99048 err_reg:
99049 - if (!net_eq(net, &init_net))
99050 - kfree(table);
99051 + kfree(table);
99052 err_alloc:
99053 return -ENOMEM;
99054 }
99055 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
99056 index 9c05d77..9cfa714 100644
99057 --- a/net/ipv6/addrconf.c
99058 +++ b/net/ipv6/addrconf.c
99059 @@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
99060 idx = 0;
99061 head = &net->dev_index_head[h];
99062 rcu_read_lock();
99063 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
99064 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
99065 net->dev_base_seq;
99066 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99067 if (idx < s_idx)
99068 @@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
99069 p.iph.ihl = 5;
99070 p.iph.protocol = IPPROTO_IPV6;
99071 p.iph.ttl = 64;
99072 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
99073 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
99074
99075 if (ops->ndo_do_ioctl) {
99076 mm_segment_t oldfs = get_fs();
99077 @@ -3964,7 +3964,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
99078 s_ip_idx = ip_idx = cb->args[2];
99079
99080 rcu_read_lock();
99081 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99082 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99083 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
99084 idx = 0;
99085 head = &net->dev_index_head[h];
99086 @@ -4571,7 +4571,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
99087 dst_free(&ifp->rt->dst);
99088 break;
99089 }
99090 - atomic_inc(&net->ipv6.dev_addr_genid);
99091 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
99092 rt_genid_bump_ipv6(net);
99093 }
99094
99095 @@ -4592,7 +4592,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
99096 int *valp = ctl->data;
99097 int val = *valp;
99098 loff_t pos = *ppos;
99099 - struct ctl_table lctl;
99100 + ctl_table_no_const lctl;
99101 int ret;
99102
99103 /*
99104 @@ -4677,7 +4677,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
99105 int *valp = ctl->data;
99106 int val = *valp;
99107 loff_t pos = *ppos;
99108 - struct ctl_table lctl;
99109 + ctl_table_no_const lctl;
99110 int ret;
99111
99112 /*
99113 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
99114 index 4fbdb70..f6411f2 100644
99115 --- a/net/ipv6/af_inet6.c
99116 +++ b/net/ipv6/af_inet6.c
99117 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
99118
99119 net->ipv6.sysctl.bindv6only = 0;
99120 net->ipv6.sysctl.icmpv6_time = 1*HZ;
99121 - atomic_set(&net->ipv6.rt_genid, 0);
99122 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
99123
99124 err = ipv6_init_mibs(net);
99125 if (err)
99126 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
99127 index 93b1aa3..e902855 100644
99128 --- a/net/ipv6/datagram.c
99129 +++ b/net/ipv6/datagram.c
99130 @@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
99131 0,
99132 sock_i_ino(sp),
99133 atomic_read(&sp->sk_refcnt), sp,
99134 - atomic_read(&sp->sk_drops));
99135 + atomic_read_unchecked(&sp->sk_drops));
99136 }
99137 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
99138 index eef8d94..cfa1852 100644
99139 --- a/net/ipv6/icmp.c
99140 +++ b/net/ipv6/icmp.c
99141 @@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
99142
99143 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
99144 {
99145 - struct ctl_table *table;
99146 + ctl_table_no_const *table;
99147
99148 table = kmemdup(ipv6_icmp_table_template,
99149 sizeof(ipv6_icmp_table_template),
99150 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
99151 index 8acb286..840dd06 100644
99152 --- a/net/ipv6/ip6_gre.c
99153 +++ b/net/ipv6/ip6_gre.c
99154 @@ -74,7 +74,7 @@ struct ip6gre_net {
99155 struct net_device *fb_tunnel_dev;
99156 };
99157
99158 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
99159 +static struct rtnl_link_ops ip6gre_link_ops;
99160 static int ip6gre_tunnel_init(struct net_device *dev);
99161 static void ip6gre_tunnel_setup(struct net_device *dev);
99162 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
99163 @@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
99164 }
99165
99166
99167 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
99168 +static struct inet6_protocol ip6gre_protocol = {
99169 .handler = ip6gre_rcv,
99170 .err_handler = ip6gre_err,
99171 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
99172 @@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
99173 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
99174 };
99175
99176 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99177 +static struct rtnl_link_ops ip6gre_link_ops = {
99178 .kind = "ip6gre",
99179 .maxtype = IFLA_GRE_MAX,
99180 .policy = ip6gre_policy,
99181 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99182 .fill_info = ip6gre_fill_info,
99183 };
99184
99185 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
99186 +static struct rtnl_link_ops ip6gre_tap_ops = {
99187 .kind = "ip6gretap",
99188 .maxtype = IFLA_GRE_MAX,
99189 .policy = ip6gre_policy,
99190 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
99191 index 7881965..9cf62c4 100644
99192 --- a/net/ipv6/ip6_tunnel.c
99193 +++ b/net/ipv6/ip6_tunnel.c
99194 @@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99195
99196 static int ip6_tnl_dev_init(struct net_device *dev);
99197 static void ip6_tnl_dev_setup(struct net_device *dev);
99198 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
99199 +static struct rtnl_link_ops ip6_link_ops;
99200
99201 static int ip6_tnl_net_id __read_mostly;
99202 struct ip6_tnl_net {
99203 @@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
99204 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
99205 };
99206
99207 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
99208 +static struct rtnl_link_ops ip6_link_ops = {
99209 .kind = "ip6tnl",
99210 .maxtype = IFLA_IPTUN_MAX,
99211 .policy = ip6_tnl_policy,
99212 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
99213 index 7b42d5e..1eff693 100644
99214 --- a/net/ipv6/ip6_vti.c
99215 +++ b/net/ipv6/ip6_vti.c
99216 @@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99217
99218 static int vti6_dev_init(struct net_device *dev);
99219 static void vti6_dev_setup(struct net_device *dev);
99220 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
99221 +static struct rtnl_link_ops vti6_link_ops;
99222
99223 static int vti6_net_id __read_mostly;
99224 struct vti6_net {
99225 @@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
99226 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
99227 };
99228
99229 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
99230 +static struct rtnl_link_ops vti6_link_ops = {
99231 .kind = "vti6",
99232 .maxtype = IFLA_VTI_MAX,
99233 .policy = vti6_policy,
99234 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
99235 index 1c6ce31..299e566 100644
99236 --- a/net/ipv6/ipv6_sockglue.c
99237 +++ b/net/ipv6/ipv6_sockglue.c
99238 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
99239 if (sk->sk_type != SOCK_STREAM)
99240 return -ENOPROTOOPT;
99241
99242 - msg.msg_control = optval;
99243 + msg.msg_control = (void __force_kernel *)optval;
99244 msg.msg_controllen = len;
99245 msg.msg_flags = flags;
99246
99247 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99248 index 710238f..0fd1816 100644
99249 --- a/net/ipv6/netfilter/ip6_tables.c
99250 +++ b/net/ipv6/netfilter/ip6_tables.c
99251 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99252 #endif
99253
99254 static int get_info(struct net *net, void __user *user,
99255 - const int *len, int compat)
99256 + int len, int compat)
99257 {
99258 char name[XT_TABLE_MAXNAMELEN];
99259 struct xt_table *t;
99260 int ret;
99261
99262 - if (*len != sizeof(struct ip6t_getinfo)) {
99263 - duprintf("length %u != %zu\n", *len,
99264 + if (len != sizeof(struct ip6t_getinfo)) {
99265 + duprintf("length %u != %zu\n", len,
99266 sizeof(struct ip6t_getinfo));
99267 return -EINVAL;
99268 }
99269 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99270 info.size = private->size;
99271 strcpy(info.name, name);
99272
99273 - if (copy_to_user(user, &info, *len) != 0)
99274 + if (copy_to_user(user, &info, len) != 0)
99275 ret = -EFAULT;
99276 else
99277 ret = 0;
99278 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99279
99280 switch (cmd) {
99281 case IP6T_SO_GET_INFO:
99282 - ret = get_info(sock_net(sk), user, len, 1);
99283 + ret = get_info(sock_net(sk), user, *len, 1);
99284 break;
99285 case IP6T_SO_GET_ENTRIES:
99286 ret = compat_get_entries(sock_net(sk), user, len);
99287 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99288
99289 switch (cmd) {
99290 case IP6T_SO_GET_INFO:
99291 - ret = get_info(sock_net(sk), user, len, 0);
99292 + ret = get_info(sock_net(sk), user, *len, 0);
99293 break;
99294
99295 case IP6T_SO_GET_ENTRIES:
99296 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99297 index 767ab8d..c5ec70a 100644
99298 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99299 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99300 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99301
99302 static int nf_ct_frag6_sysctl_register(struct net *net)
99303 {
99304 - struct ctl_table *table;
99305 + ctl_table_no_const *table = NULL;
99306 struct ctl_table_header *hdr;
99307
99308 - table = nf_ct_frag6_sysctl_table;
99309 if (!net_eq(net, &init_net)) {
99310 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99311 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99312 GFP_KERNEL);
99313 if (table == NULL)
99314 goto err_alloc;
99315 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99316 table[0].data = &net->nf_frag.frags.timeout;
99317 table[1].data = &net->nf_frag.frags.low_thresh;
99318 table[2].data = &net->nf_frag.frags.high_thresh;
99319 - }
99320 -
99321 - hdr = register_net_sysctl(net, "net/netfilter", table);
99322 + hdr = register_net_sysctl(net, "net/netfilter", table);
99323 + } else
99324 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99325 if (hdr == NULL)
99326 goto err_reg;
99327
99328 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99329 return 0;
99330
99331 err_reg:
99332 - if (!net_eq(net, &init_net))
99333 - kfree(table);
99334 + kfree(table);
99335 err_alloc:
99336 return -ENOMEM;
99337 }
99338 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99339 index 827f795..7e28e82 100644
99340 --- a/net/ipv6/output_core.c
99341 +++ b/net/ipv6/output_core.c
99342 @@ -9,8 +9,8 @@
99343
99344 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99345 {
99346 - static atomic_t ipv6_fragmentation_id;
99347 - int old, new;
99348 + static atomic_unchecked_t ipv6_fragmentation_id;
99349 + int id;
99350
99351 #if IS_ENABLED(CONFIG_IPV6)
99352 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99353 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99354 }
99355 }
99356 #endif
99357 - do {
99358 - old = atomic_read(&ipv6_fragmentation_id);
99359 - new = old + 1;
99360 - if (!new)
99361 - new = 1;
99362 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99363 - fhdr->identification = htonl(new);
99364 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99365 + if (!id)
99366 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99367 + fhdr->identification = htonl(id);
99368 }
99369 EXPORT_SYMBOL(ipv6_select_ident);
99370
99371 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99372 index a83243c..a1ca589 100644
99373 --- a/net/ipv6/ping.c
99374 +++ b/net/ipv6/ping.c
99375 @@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
99376 };
99377 #endif
99378
99379 +static struct pingv6_ops real_pingv6_ops = {
99380 + .ipv6_recv_error = ipv6_recv_error,
99381 + .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
99382 + .icmpv6_err_convert = icmpv6_err_convert,
99383 + .ipv6_icmp_error = ipv6_icmp_error,
99384 + .ipv6_chk_addr = ipv6_chk_addr,
99385 +};
99386 +
99387 +static struct pingv6_ops dummy_pingv6_ops = {
99388 + .ipv6_recv_error = dummy_ipv6_recv_error,
99389 + .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
99390 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
99391 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
99392 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
99393 +};
99394 +
99395 int __init pingv6_init(void)
99396 {
99397 #ifdef CONFIG_PROC_FS
99398 @@ -253,11 +269,7 @@ int __init pingv6_init(void)
99399 if (ret)
99400 return ret;
99401 #endif
99402 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99403 - pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
99404 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99405 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99406 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99407 + pingv6_ops = &real_pingv6_ops;
99408 return inet6_register_protosw(&pingv6_protosw);
99409 }
99410
99411 @@ -266,11 +278,7 @@ int __init pingv6_init(void)
99412 */
99413 void pingv6_exit(void)
99414 {
99415 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99416 - pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
99417 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99418 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99419 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99420 + pingv6_ops = &dummy_pingv6_ops;
99421 #ifdef CONFIG_PROC_FS
99422 unregister_pernet_subsys(&ping_v6_net_ops);
99423 #endif
99424 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99425 index b6bb87e..06cc9ed 100644
99426 --- a/net/ipv6/raw.c
99427 +++ b/net/ipv6/raw.c
99428 @@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99429 {
99430 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99431 skb_checksum_complete(skb)) {
99432 - atomic_inc(&sk->sk_drops);
99433 + atomic_inc_unchecked(&sk->sk_drops);
99434 kfree_skb(skb);
99435 return NET_RX_DROP;
99436 }
99437 @@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99438 struct raw6_sock *rp = raw6_sk(sk);
99439
99440 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99441 - atomic_inc(&sk->sk_drops);
99442 + atomic_inc_unchecked(&sk->sk_drops);
99443 kfree_skb(skb);
99444 return NET_RX_DROP;
99445 }
99446 @@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99447
99448 if (inet->hdrincl) {
99449 if (skb_checksum_complete(skb)) {
99450 - atomic_inc(&sk->sk_drops);
99451 + atomic_inc_unchecked(&sk->sk_drops);
99452 kfree_skb(skb);
99453 return NET_RX_DROP;
99454 }
99455 @@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99456 if (flags & MSG_OOB)
99457 return -EOPNOTSUPP;
99458
99459 + if (addr_len)
99460 + *addr_len=sizeof(*sin6);
99461 +
99462 if (flags & MSG_ERRQUEUE)
99463 return ipv6_recv_error(sk, msg, len, addr_len);
99464
99465 @@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99466 sin6->sin6_flowinfo = 0;
99467 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99468 IP6CB(skb)->iif);
99469 - *addr_len = sizeof(*sin6);
99470 }
99471
99472 sock_recv_ts_and_drops(msg, sk, skb);
99473 @@ -606,7 +608,7 @@ out:
99474 return err;
99475 }
99476
99477 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99478 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99479 struct flowi6 *fl6, struct dst_entry **dstp,
99480 unsigned int flags)
99481 {
99482 @@ -918,12 +920,15 @@ do_confirm:
99483 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99484 char __user *optval, int optlen)
99485 {
99486 + struct icmp6_filter filter;
99487 +
99488 switch (optname) {
99489 case ICMPV6_FILTER:
99490 if (optlen > sizeof(struct icmp6_filter))
99491 optlen = sizeof(struct icmp6_filter);
99492 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99493 + if (copy_from_user(&filter, optval, optlen))
99494 return -EFAULT;
99495 + raw6_sk(sk)->filter = filter;
99496 return 0;
99497 default:
99498 return -ENOPROTOOPT;
99499 @@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99500 char __user *optval, int __user *optlen)
99501 {
99502 int len;
99503 + struct icmp6_filter filter;
99504
99505 switch (optname) {
99506 case ICMPV6_FILTER:
99507 @@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99508 len = sizeof(struct icmp6_filter);
99509 if (put_user(len, optlen))
99510 return -EFAULT;
99511 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99512 + filter = raw6_sk(sk)->filter;
99513 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
99514 return -EFAULT;
99515 return 0;
99516 default:
99517 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99518 index cc85a9b..526a133 100644
99519 --- a/net/ipv6/reassembly.c
99520 +++ b/net/ipv6/reassembly.c
99521 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99522
99523 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99524 {
99525 - struct ctl_table *table;
99526 + ctl_table_no_const *table = NULL;
99527 struct ctl_table_header *hdr;
99528
99529 - table = ip6_frags_ns_ctl_table;
99530 if (!net_eq(net, &init_net)) {
99531 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99532 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99533 if (table == NULL)
99534 goto err_alloc;
99535
99536 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99537 /* Don't export sysctls to unprivileged users */
99538 if (net->user_ns != &init_user_ns)
99539 table[0].procname = NULL;
99540 - }
99541 + hdr = register_net_sysctl(net, "net/ipv6", table);
99542 + } else
99543 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99544
99545 - hdr = register_net_sysctl(net, "net/ipv6", table);
99546 if (hdr == NULL)
99547 goto err_reg;
99548
99549 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99550 return 0;
99551
99552 err_reg:
99553 - if (!net_eq(net, &init_net))
99554 - kfree(table);
99555 + kfree(table);
99556 err_alloc:
99557 return -ENOMEM;
99558 }
99559 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99560 index 4b4944c..d346b14 100644
99561 --- a/net/ipv6/route.c
99562 +++ b/net/ipv6/route.c
99563 @@ -1495,7 +1495,7 @@ int ip6_route_add(struct fib6_config *cfg)
99564 if (!table)
99565 goto out;
99566
99567 - rt = ip6_dst_alloc(net, NULL, DST_NOCOUNT, table);
99568 + rt = ip6_dst_alloc(net, NULL, (cfg->fc_flags & RTF_ADDRCONF) ? 0 : DST_NOCOUNT, table);
99569
99570 if (!rt) {
99571 err = -ENOMEM;
99572 @@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
99573
99574 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99575 {
99576 - struct ctl_table *table;
99577 + ctl_table_no_const *table;
99578
99579 table = kmemdup(ipv6_route_table_template,
99580 sizeof(ipv6_route_table_template),
99581 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99582 index d3005b3..b36df4a 100644
99583 --- a/net/ipv6/sit.c
99584 +++ b/net/ipv6/sit.c
99585 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99586 static void ipip6_dev_free(struct net_device *dev);
99587 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99588 __be32 *v4dst);
99589 -static struct rtnl_link_ops sit_link_ops __read_mostly;
99590 +static struct rtnl_link_ops sit_link_ops;
99591
99592 static int sit_net_id __read_mostly;
99593 struct sit_net {
99594 @@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99595 unregister_netdevice_queue(dev, head);
99596 }
99597
99598 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
99599 +static struct rtnl_link_ops sit_link_ops = {
99600 .kind = "sit",
99601 .maxtype = IFLA_IPTUN_MAX,
99602 .policy = ipip6_policy,
99603 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99604 index 107b2f1..72741a9 100644
99605 --- a/net/ipv6/sysctl_net_ipv6.c
99606 +++ b/net/ipv6/sysctl_net_ipv6.c
99607 @@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
99608
99609 static int __net_init ipv6_sysctl_net_init(struct net *net)
99610 {
99611 - struct ctl_table *ipv6_table;
99612 + ctl_table_no_const *ipv6_table;
99613 struct ctl_table *ipv6_route_table;
99614 struct ctl_table *ipv6_icmp_table;
99615 int err;
99616 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99617 index f67033b..6f974fc 100644
99618 --- a/net/ipv6/tcp_ipv6.c
99619 +++ b/net/ipv6/tcp_ipv6.c
99620 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99621 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99622 }
99623
99624 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99625 +extern int grsec_enable_blackhole;
99626 +#endif
99627 +
99628 static void tcp_v6_hash(struct sock *sk)
99629 {
99630 if (sk->sk_state != TCP_CLOSE) {
99631 @@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99632 return 0;
99633
99634 reset:
99635 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99636 + if (!grsec_enable_blackhole)
99637 +#endif
99638 tcp_v6_send_reset(sk, skb);
99639 discard:
99640 if (opt_skb)
99641 @@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99642 TCP_SKB_CB(skb)->sacked = 0;
99643
99644 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99645 - if (!sk)
99646 + if (!sk) {
99647 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99648 + ret = 1;
99649 +#endif
99650 goto no_tcp_socket;
99651 + }
99652
99653 process:
99654 - if (sk->sk_state == TCP_TIME_WAIT)
99655 + if (sk->sk_state == TCP_TIME_WAIT) {
99656 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99657 + ret = 2;
99658 +#endif
99659 goto do_time_wait;
99660 + }
99661
99662 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99663 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99664 @@ -1536,6 +1551,10 @@ csum_error:
99665 bad_packet:
99666 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99667 } else {
99668 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99669 + if (!grsec_enable_blackhole || (ret == 1 &&
99670 + (skb->dev->flags & IFF_LOOPBACK)))
99671 +#endif
99672 tcp_v6_send_reset(NULL, skb);
99673 }
99674
99675 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99676 index 089c741..cfee117 100644
99677 --- a/net/ipv6/udp.c
99678 +++ b/net/ipv6/udp.c
99679 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99680 udp_ipv6_hash_secret + net_hash_mix(net));
99681 }
99682
99683 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99684 +extern int grsec_enable_blackhole;
99685 +#endif
99686 +
99687 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
99688 {
99689 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
99690 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99691 int is_udp4;
99692 bool slow;
99693
99694 + if (addr_len)
99695 + *addr_len = sizeof(struct sockaddr_in6);
99696 +
99697 if (flags & MSG_ERRQUEUE)
99698 return ipv6_recv_error(sk, msg, len, addr_len);
99699
99700 @@ -435,7 +442,7 @@ try_again:
99701 if (unlikely(err)) {
99702 trace_kfree_skb(skb, udpv6_recvmsg);
99703 if (!peeked) {
99704 - atomic_inc(&sk->sk_drops);
99705 + atomic_inc_unchecked(&sk->sk_drops);
99706 if (is_udp4)
99707 UDP_INC_STATS_USER(sock_net(sk),
99708 UDP_MIB_INERRORS,
99709 @@ -477,7 +484,7 @@ try_again:
99710 ipv6_iface_scope_id(&sin6->sin6_addr,
99711 IP6CB(skb)->iif);
99712 }
99713 - *addr_len = sizeof(*sin6);
99714 +
99715 }
99716 if (is_udp4) {
99717 if (inet->cmsg_flags)
99718 @@ -685,7 +692,7 @@ csum_error:
99719 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99720 drop:
99721 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99722 - atomic_inc(&sk->sk_drops);
99723 + atomic_inc_unchecked(&sk->sk_drops);
99724 kfree_skb(skb);
99725 return -1;
99726 }
99727 @@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99728 if (likely(skb1 == NULL))
99729 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99730 if (!skb1) {
99731 - atomic_inc(&sk->sk_drops);
99732 + atomic_inc_unchecked(&sk->sk_drops);
99733 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99734 IS_UDPLITE(sk));
99735 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99736 @@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99737 goto csum_error;
99738
99739 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99740 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99741 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99742 +#endif
99743 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
99744
99745 kfree_skb(skb);
99746 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
99747 index 5f8e128..865d38e 100644
99748 --- a/net/ipv6/xfrm6_policy.c
99749 +++ b/net/ipv6/xfrm6_policy.c
99750 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
99751 }
99752 }
99753
99754 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
99755 +static int xfrm6_garbage_collect(struct dst_ops *ops)
99756 {
99757 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
99758
99759 - xfrm6_policy_afinfo.garbage_collect(net);
99760 + xfrm_garbage_collect_deferred(net);
99761 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
99762 }
99763
99764 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
99765
99766 static int __net_init xfrm6_net_init(struct net *net)
99767 {
99768 - struct ctl_table *table;
99769 + ctl_table_no_const *table = NULL;
99770 struct ctl_table_header *hdr;
99771
99772 - table = xfrm6_policy_table;
99773 if (!net_eq(net, &init_net)) {
99774 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99775 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99776 if (!table)
99777 goto err_alloc;
99778
99779 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
99780 - }
99781 + hdr = register_net_sysctl(net, "net/ipv6", table);
99782 + } else
99783 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
99784
99785 - hdr = register_net_sysctl(net, "net/ipv6", table);
99786 if (!hdr)
99787 goto err_reg;
99788
99789 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
99790 return 0;
99791
99792 err_reg:
99793 - if (!net_eq(net, &init_net))
99794 - kfree(table);
99795 + kfree(table);
99796 err_alloc:
99797 return -ENOMEM;
99798 }
99799 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
99800 index 41ac7938..75e3bb1 100644
99801 --- a/net/irda/ircomm/ircomm_tty.c
99802 +++ b/net/irda/ircomm/ircomm_tty.c
99803 @@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99804 add_wait_queue(&port->open_wait, &wait);
99805
99806 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
99807 - __FILE__, __LINE__, tty->driver->name, port->count);
99808 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99809
99810 spin_lock_irqsave(&port->lock, flags);
99811 if (!tty_hung_up_p(filp))
99812 - port->count--;
99813 + atomic_dec(&port->count);
99814 port->blocked_open++;
99815 spin_unlock_irqrestore(&port->lock, flags);
99816
99817 @@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99818 }
99819
99820 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
99821 - __FILE__, __LINE__, tty->driver->name, port->count);
99822 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99823
99824 schedule();
99825 }
99826 @@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99827
99828 spin_lock_irqsave(&port->lock, flags);
99829 if (!tty_hung_up_p(filp))
99830 - port->count++;
99831 + atomic_inc(&port->count);
99832 port->blocked_open--;
99833 spin_unlock_irqrestore(&port->lock, flags);
99834
99835 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
99836 - __FILE__, __LINE__, tty->driver->name, port->count);
99837 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99838
99839 if (!retval)
99840 port->flags |= ASYNC_NORMAL_ACTIVE;
99841 @@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
99842
99843 /* ++ is not atomic, so this should be protected - Jean II */
99844 spin_lock_irqsave(&self->port.lock, flags);
99845 - self->port.count++;
99846 + atomic_inc(&self->port.count);
99847 spin_unlock_irqrestore(&self->port.lock, flags);
99848 tty_port_tty_set(&self->port, tty);
99849
99850 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
99851 - self->line, self->port.count);
99852 + self->line, atomic_read(&self->port.count));
99853
99854 /* Not really used by us, but lets do it anyway */
99855 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
99856 @@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
99857 tty_kref_put(port->tty);
99858 }
99859 port->tty = NULL;
99860 - port->count = 0;
99861 + atomic_set(&port->count, 0);
99862 spin_unlock_irqrestore(&port->lock, flags);
99863
99864 wake_up_interruptible(&port->open_wait);
99865 @@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
99866 seq_putc(m, '\n');
99867
99868 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
99869 - seq_printf(m, "Open count: %d\n", self->port.count);
99870 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
99871 seq_printf(m, "Max data size: %d\n", self->max_data_size);
99872 seq_printf(m, "Max header size: %d\n", self->max_header_size);
99873
99874 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
99875 index c4b7218..3e83259 100644
99876 --- a/net/iucv/af_iucv.c
99877 +++ b/net/iucv/af_iucv.c
99878 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
99879
99880 write_lock_bh(&iucv_sk_list.lock);
99881
99882 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
99883 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99884 while (__iucv_get_sock_by_name(name)) {
99885 sprintf(name, "%08x",
99886 - atomic_inc_return(&iucv_sk_list.autobind_name));
99887 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99888 }
99889
99890 write_unlock_bh(&iucv_sk_list.lock);
99891 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
99892 index cd5b8ec..f205e6b 100644
99893 --- a/net/iucv/iucv.c
99894 +++ b/net/iucv/iucv.c
99895 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
99896 return NOTIFY_OK;
99897 }
99898
99899 -static struct notifier_block __refdata iucv_cpu_notifier = {
99900 +static struct notifier_block iucv_cpu_notifier = {
99901 .notifier_call = iucv_cpu_notify,
99902 };
99903
99904 diff --git a/net/key/af_key.c b/net/key/af_key.c
99905 index 545f047..9757a9d 100644
99906 --- a/net/key/af_key.c
99907 +++ b/net/key/af_key.c
99908 @@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
99909 static u32 get_acqseq(void)
99910 {
99911 u32 res;
99912 - static atomic_t acqseq;
99913 + static atomic_unchecked_t acqseq;
99914
99915 do {
99916 - res = atomic_inc_return(&acqseq);
99917 + res = atomic_inc_return_unchecked(&acqseq);
99918 } while (!res);
99919 return res;
99920 }
99921 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
99922 index da1a1ce..571db8d 100644
99923 --- a/net/l2tp/l2tp_ip.c
99924 +++ b/net/l2tp/l2tp_ip.c
99925 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99926 if (flags & MSG_OOB)
99927 goto out;
99928
99929 + if (addr_len)
99930 + *addr_len = sizeof(*sin);
99931 +
99932 skb = skb_recv_datagram(sk, flags, noblock, &err);
99933 if (!skb)
99934 goto out;
99935 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99936 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99937 sin->sin_port = 0;
99938 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99939 - *addr_len = sizeof(*sin);
99940 }
99941 if (inet->cmsg_flags)
99942 ip_cmsg_recv(msg, skb);
99943 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
99944 index b4b61b2..ac84a257 100644
99945 --- a/net/mac80211/cfg.c
99946 +++ b/net/mac80211/cfg.c
99947 @@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
99948 ret = ieee80211_vif_use_channel(sdata, chandef,
99949 IEEE80211_CHANCTX_EXCLUSIVE);
99950 }
99951 - } else if (local->open_count == local->monitors) {
99952 + } else if (local_read(&local->open_count) == local->monitors) {
99953 local->_oper_chandef = *chandef;
99954 ieee80211_hw_config(local, 0);
99955 }
99956 @@ -3311,7 +3311,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
99957 else
99958 local->probe_req_reg--;
99959
99960 - if (!local->open_count)
99961 + if (!local_read(&local->open_count))
99962 break;
99963
99964 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
99965 @@ -3774,8 +3774,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
99966 if (chanctx_conf) {
99967 *chandef = chanctx_conf->def;
99968 ret = 0;
99969 - } else if (local->open_count > 0 &&
99970 - local->open_count == local->monitors &&
99971 + } else if (local_read(&local->open_count) > 0 &&
99972 + local_read(&local->open_count) == local->monitors &&
99973 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
99974 if (local->use_chanctx)
99975 *chandef = local->monitor_chandef;
99976 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
99977 index 4aea4e7..9e698d1 100644
99978 --- a/net/mac80211/ieee80211_i.h
99979 +++ b/net/mac80211/ieee80211_i.h
99980 @@ -28,6 +28,7 @@
99981 #include <net/ieee80211_radiotap.h>
99982 #include <net/cfg80211.h>
99983 #include <net/mac80211.h>
99984 +#include <asm/local.h>
99985 #include "key.h"
99986 #include "sta_info.h"
99987 #include "debug.h"
99988 @@ -961,7 +962,7 @@ struct ieee80211_local {
99989 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
99990 spinlock_t queue_stop_reason_lock;
99991
99992 - int open_count;
99993 + local_t open_count;
99994 int monitors, cooked_mntrs;
99995 /* number of interfaces with corresponding FIF_ flags */
99996 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
99997 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
99998 index a075791..1d0027f 100644
99999 --- a/net/mac80211/iface.c
100000 +++ b/net/mac80211/iface.c
100001 @@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100002 break;
100003 }
100004
100005 - if (local->open_count == 0) {
100006 + if (local_read(&local->open_count) == 0) {
100007 res = drv_start(local);
100008 if (res)
100009 goto err_del_bss;
100010 @@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100011 res = drv_add_interface(local, sdata);
100012 if (res)
100013 goto err_stop;
100014 - } else if (local->monitors == 0 && local->open_count == 0) {
100015 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
100016 res = ieee80211_add_virtual_monitor(local);
100017 if (res)
100018 goto err_stop;
100019 @@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100020 atomic_inc(&local->iff_promiscs);
100021
100022 if (coming_up)
100023 - local->open_count++;
100024 + local_inc(&local->open_count);
100025
100026 if (hw_reconf_flags)
100027 ieee80211_hw_config(local, hw_reconf_flags);
100028 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100029 err_del_interface:
100030 drv_remove_interface(local, sdata);
100031 err_stop:
100032 - if (!local->open_count)
100033 + if (!local_read(&local->open_count))
100034 drv_stop(local);
100035 err_del_bss:
100036 sdata->bss = NULL;
100037 @@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100038 }
100039
100040 if (going_down)
100041 - local->open_count--;
100042 + local_dec(&local->open_count);
100043
100044 switch (sdata->vif.type) {
100045 case NL80211_IFTYPE_AP_VLAN:
100046 @@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100047 }
100048 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
100049
100050 - if (local->open_count == 0)
100051 + if (local_read(&local->open_count) == 0)
100052 ieee80211_clear_tx_pending(local);
100053
100054 /*
100055 @@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100056
100057 ieee80211_recalc_ps(local, -1);
100058
100059 - if (local->open_count == 0) {
100060 + if (local_read(&local->open_count) == 0) {
100061 ieee80211_stop_device(local);
100062
100063 /* no reconfiguring after stop! */
100064 @@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100065 ieee80211_configure_filter(local);
100066 ieee80211_hw_config(local, hw_reconf_flags);
100067
100068 - if (local->monitors == local->open_count)
100069 + if (local->monitors == local_read(&local->open_count))
100070 ieee80211_add_virtual_monitor(local);
100071 }
100072
100073 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
100074 index 7d1c3ac..b62dd29 100644
100075 --- a/net/mac80211/main.c
100076 +++ b/net/mac80211/main.c
100077 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
100078 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
100079 IEEE80211_CONF_CHANGE_POWER);
100080
100081 - if (changed && local->open_count) {
100082 + if (changed && local_read(&local->open_count)) {
100083 ret = drv_config(local, changed);
100084 /*
100085 * Goal:
100086 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
100087 index 3401262..d5cd68d 100644
100088 --- a/net/mac80211/pm.c
100089 +++ b/net/mac80211/pm.c
100090 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100091 struct ieee80211_sub_if_data *sdata;
100092 struct sta_info *sta;
100093
100094 - if (!local->open_count)
100095 + if (!local_read(&local->open_count))
100096 goto suspend;
100097
100098 ieee80211_scan_cancel(local);
100099 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100100 cancel_work_sync(&local->dynamic_ps_enable_work);
100101 del_timer_sync(&local->dynamic_ps_timer);
100102
100103 - local->wowlan = wowlan && local->open_count;
100104 + local->wowlan = wowlan && local_read(&local->open_count);
100105 if (local->wowlan) {
100106 int err = drv_suspend(local, wowlan);
100107 if (err < 0) {
100108 @@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100109 WARN_ON(!list_empty(&local->chanctx_list));
100110
100111 /* stop hardware - this must stop RX */
100112 - if (local->open_count)
100113 + if (local_read(&local->open_count))
100114 ieee80211_stop_device(local);
100115
100116 suspend:
100117 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
100118 index 22b223f..ab70070 100644
100119 --- a/net/mac80211/rate.c
100120 +++ b/net/mac80211/rate.c
100121 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
100122
100123 ASSERT_RTNL();
100124
100125 - if (local->open_count)
100126 + if (local_read(&local->open_count))
100127 return -EBUSY;
100128
100129 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
100130 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
100131 index 6ff1346..936ca9a 100644
100132 --- a/net/mac80211/rc80211_pid_debugfs.c
100133 +++ b/net/mac80211/rc80211_pid_debugfs.c
100134 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
100135
100136 spin_unlock_irqrestore(&events->lock, status);
100137
100138 - if (copy_to_user(buf, pb, p))
100139 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
100140 return -EFAULT;
100141
100142 return p;
100143 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
100144 index 9f9b9bd..d6fcf59 100644
100145 --- a/net/mac80211/util.c
100146 +++ b/net/mac80211/util.c
100147 @@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100148 }
100149 #endif
100150 /* everything else happens only if HW was up & running */
100151 - if (!local->open_count)
100152 + if (!local_read(&local->open_count))
100153 goto wake_up;
100154
100155 /*
100156 @@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100157 local->in_reconfig = false;
100158 barrier();
100159
100160 - if (local->monitors == local->open_count && local->monitors > 0)
100161 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
100162 ieee80211_add_virtual_monitor(local);
100163
100164 /*
100165 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
100166 index c3398cd..98ad3b4 100644
100167 --- a/net/netfilter/Kconfig
100168 +++ b/net/netfilter/Kconfig
100169 @@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
100170
100171 To compile it as a module, choose M here. If unsure, say N.
100172
100173 +config NETFILTER_XT_MATCH_GRADM
100174 + tristate '"gradm" match support'
100175 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
100176 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
100177 + ---help---
100178 + The gradm match allows to match on grsecurity RBAC being enabled.
100179 + It is useful when iptables rules are applied early on bootup to
100180 + prevent connections to the machine (except from a trusted host)
100181 + while the RBAC system is disabled.
100182 +
100183 config NETFILTER_XT_MATCH_HASHLIMIT
100184 tristate '"hashlimit" match support'
100185 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
100186 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
100187 index 394483b..ed51f2d 100644
100188 --- a/net/netfilter/Makefile
100189 +++ b/net/netfilter/Makefile
100190 @@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
100191 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
100192 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
100193 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
100194 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
100195 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
100196 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
100197 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
100198 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
100199 index bac7e01..1d7a31a 100644
100200 --- a/net/netfilter/ipset/ip_set_core.c
100201 +++ b/net/netfilter/ipset/ip_set_core.c
100202 @@ -1950,7 +1950,7 @@ done:
100203 return ret;
100204 }
100205
100206 -static struct nf_sockopt_ops so_set __read_mostly = {
100207 +static struct nf_sockopt_ops so_set = {
100208 .pf = PF_INET,
100209 .get_optmin = SO_IP_SET,
100210 .get_optmax = SO_IP_SET + 1,
100211 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
100212 index 4c8e5c0..5a79b4d 100644
100213 --- a/net/netfilter/ipvs/ip_vs_conn.c
100214 +++ b/net/netfilter/ipvs/ip_vs_conn.c
100215 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
100216 /* Increase the refcnt counter of the dest */
100217 ip_vs_dest_hold(dest);
100218
100219 - conn_flags = atomic_read(&dest->conn_flags);
100220 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
100221 if (cp->protocol != IPPROTO_UDP)
100222 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
100223 flags = cp->flags;
100224 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
100225
100226 cp->control = NULL;
100227 atomic_set(&cp->n_control, 0);
100228 - atomic_set(&cp->in_pkts, 0);
100229 + atomic_set_unchecked(&cp->in_pkts, 0);
100230
100231 cp->packet_xmit = NULL;
100232 cp->app = NULL;
100233 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
100234
100235 /* Don't drop the entry if its number of incoming packets is not
100236 located in [0, 8] */
100237 - i = atomic_read(&cp->in_pkts);
100238 + i = atomic_read_unchecked(&cp->in_pkts);
100239 if (i > 8 || i < 0) return 0;
100240
100241 if (!todrop_rate[i]) return 0;
100242 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
100243 index 4f26ee4..6a9d7c3 100644
100244 --- a/net/netfilter/ipvs/ip_vs_core.c
100245 +++ b/net/netfilter/ipvs/ip_vs_core.c
100246 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
100247 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
100248 /* do not touch skb anymore */
100249
100250 - atomic_inc(&cp->in_pkts);
100251 + atomic_inc_unchecked(&cp->in_pkts);
100252 ip_vs_conn_put(cp);
100253 return ret;
100254 }
100255 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100256 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100257 pkts = sysctl_sync_threshold(ipvs);
100258 else
100259 - pkts = atomic_add_return(1, &cp->in_pkts);
100260 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100261
100262 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100263 ip_vs_sync_conn(net, cp, pkts);
100264 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100265 index 35be035..50f8834 100644
100266 --- a/net/netfilter/ipvs/ip_vs_ctl.c
100267 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
100268 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100269 */
100270 ip_vs_rs_hash(ipvs, dest);
100271 }
100272 - atomic_set(&dest->conn_flags, conn_flags);
100273 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
100274
100275 /* bind the service */
100276 old_svc = rcu_dereference_protected(dest->svc, 1);
100277 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100278 * align with netns init in ip_vs_control_net_init()
100279 */
100280
100281 -static struct ctl_table vs_vars[] = {
100282 +static ctl_table_no_const vs_vars[] __read_only = {
100283 {
100284 .procname = "amemthresh",
100285 .maxlen = sizeof(int),
100286 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100287 " %-7s %-6d %-10d %-10d\n",
100288 &dest->addr.in6,
100289 ntohs(dest->port),
100290 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100291 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100292 atomic_read(&dest->weight),
100293 atomic_read(&dest->activeconns),
100294 atomic_read(&dest->inactconns));
100295 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100296 "%-7s %-6d %-10d %-10d\n",
100297 ntohl(dest->addr.ip),
100298 ntohs(dest->port),
100299 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100300 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100301 atomic_read(&dest->weight),
100302 atomic_read(&dest->activeconns),
100303 atomic_read(&dest->inactconns));
100304 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100305
100306 entry.addr = dest->addr.ip;
100307 entry.port = dest->port;
100308 - entry.conn_flags = atomic_read(&dest->conn_flags);
100309 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100310 entry.weight = atomic_read(&dest->weight);
100311 entry.u_threshold = dest->u_threshold;
100312 entry.l_threshold = dest->l_threshold;
100313 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100314 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100315 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100316 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100317 - (atomic_read(&dest->conn_flags) &
100318 + (atomic_read_unchecked(&dest->conn_flags) &
100319 IP_VS_CONN_F_FWD_MASK)) ||
100320 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100321 atomic_read(&dest->weight)) ||
100322 @@ -3580,7 +3580,7 @@ out:
100323 }
100324
100325
100326 -static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100327 +static const struct genl_ops ip_vs_genl_ops[] = {
100328 {
100329 .cmd = IPVS_CMD_NEW_SERVICE,
100330 .flags = GENL_ADMIN_PERM,
100331 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100332 {
100333 int idx;
100334 struct netns_ipvs *ipvs = net_ipvs(net);
100335 - struct ctl_table *tbl;
100336 + ctl_table_no_const *tbl;
100337
100338 atomic_set(&ipvs->dropentry, 0);
100339 spin_lock_init(&ipvs->dropentry_lock);
100340 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100341 index ca056a3..9cf01ef 100644
100342 --- a/net/netfilter/ipvs/ip_vs_lblc.c
100343 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
100344 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100345 * IPVS LBLC sysctl table
100346 */
100347 #ifdef CONFIG_SYSCTL
100348 -static struct ctl_table vs_vars_table[] = {
100349 +static ctl_table_no_const vs_vars_table[] __read_only = {
100350 {
100351 .procname = "lblc_expiration",
100352 .data = NULL,
100353 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100354 index 3f21a2f..a112e85 100644
100355 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
100356 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100357 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100358 * IPVS LBLCR sysctl table
100359 */
100360
100361 -static struct ctl_table vs_vars_table[] = {
100362 +static ctl_table_no_const vs_vars_table[] __read_only = {
100363 {
100364 .procname = "lblcr_expiration",
100365 .data = NULL,
100366 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100367 index f63c238..1b87f8a 100644
100368 --- a/net/netfilter/ipvs/ip_vs_sync.c
100369 +++ b/net/netfilter/ipvs/ip_vs_sync.c
100370 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100371 cp = cp->control;
100372 if (cp) {
100373 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100374 - pkts = atomic_add_return(1, &cp->in_pkts);
100375 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100376 else
100377 pkts = sysctl_sync_threshold(ipvs);
100378 ip_vs_sync_conn(net, cp->control, pkts);
100379 @@ -771,7 +771,7 @@ control:
100380 if (!cp)
100381 return;
100382 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100383 - pkts = atomic_add_return(1, &cp->in_pkts);
100384 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100385 else
100386 pkts = sysctl_sync_threshold(ipvs);
100387 goto sloop;
100388 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100389
100390 if (opt)
100391 memcpy(&cp->in_seq, opt, sizeof(*opt));
100392 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100393 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100394 cp->state = state;
100395 cp->old_state = cp->state;
100396 /*
100397 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100398 index c47444e..b0961c6 100644
100399 --- a/net/netfilter/ipvs/ip_vs_xmit.c
100400 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
100401 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100402 else
100403 rc = NF_ACCEPT;
100404 /* do not touch skb anymore */
100405 - atomic_inc(&cp->in_pkts);
100406 + atomic_inc_unchecked(&cp->in_pkts);
100407 goto out;
100408 }
100409
100410 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100411 else
100412 rc = NF_ACCEPT;
100413 /* do not touch skb anymore */
100414 - atomic_inc(&cp->in_pkts);
100415 + atomic_inc_unchecked(&cp->in_pkts);
100416 goto out;
100417 }
100418
100419 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100420 index a4b5e2a..13b1de3 100644
100421 --- a/net/netfilter/nf_conntrack_acct.c
100422 +++ b/net/netfilter/nf_conntrack_acct.c
100423 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100424 #ifdef CONFIG_SYSCTL
100425 static int nf_conntrack_acct_init_sysctl(struct net *net)
100426 {
100427 - struct ctl_table *table;
100428 + ctl_table_no_const *table;
100429
100430 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100431 GFP_KERNEL);
100432 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100433 index 43549eb..0bbeace 100644
100434 --- a/net/netfilter/nf_conntrack_core.c
100435 +++ b/net/netfilter/nf_conntrack_core.c
100436 @@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
100437 #define DYING_NULLS_VAL ((1<<30)+1)
100438 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100439
100440 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100441 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100442 +#endif
100443 +
100444 int nf_conntrack_init_net(struct net *net)
100445 {
100446 int ret;
100447 @@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
100448 goto err_stat;
100449 }
100450
100451 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100452 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100453 +#else
100454 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100455 +#endif
100456 if (!net->ct.slabname) {
100457 ret = -ENOMEM;
100458 goto err_slabname;
100459 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100460 index 1df1761..ce8b88a 100644
100461 --- a/net/netfilter/nf_conntrack_ecache.c
100462 +++ b/net/netfilter/nf_conntrack_ecache.c
100463 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100464 #ifdef CONFIG_SYSCTL
100465 static int nf_conntrack_event_init_sysctl(struct net *net)
100466 {
100467 - struct ctl_table *table;
100468 + ctl_table_no_const *table;
100469
100470 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100471 GFP_KERNEL);
100472 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100473 index 974a2a4..52cc6ff 100644
100474 --- a/net/netfilter/nf_conntrack_helper.c
100475 +++ b/net/netfilter/nf_conntrack_helper.c
100476 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100477
100478 static int nf_conntrack_helper_init_sysctl(struct net *net)
100479 {
100480 - struct ctl_table *table;
100481 + ctl_table_no_const *table;
100482
100483 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100484 GFP_KERNEL);
100485 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100486 index ce30041..3861b5d 100644
100487 --- a/net/netfilter/nf_conntrack_proto.c
100488 +++ b/net/netfilter/nf_conntrack_proto.c
100489 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100490
100491 static void
100492 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100493 - struct ctl_table **table,
100494 + ctl_table_no_const **table,
100495 unsigned int users)
100496 {
100497 if (users > 0)
100498 diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
100499 index 59359be..cb372f9 100644
100500 --- a/net/netfilter/nf_conntrack_proto_dccp.c
100501 +++ b/net/netfilter/nf_conntrack_proto_dccp.c
100502 @@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
100503 out_invalid:
100504 if (LOG_INVALID(net, IPPROTO_DCCP))
100505 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
100506 - NULL, msg);
100507 + NULL, "%s", msg);
100508 return false;
100509 }
100510
100511 @@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
100512
100513 out_invalid:
100514 if (LOG_INVALID(net, IPPROTO_DCCP))
100515 - nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
100516 + nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
100517 return -NF_ACCEPT;
100518 }
100519
100520 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100521 index f641751..d3c5b51 100644
100522 --- a/net/netfilter/nf_conntrack_standalone.c
100523 +++ b/net/netfilter/nf_conntrack_standalone.c
100524 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100525
100526 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100527 {
100528 - struct ctl_table *table;
100529 + ctl_table_no_const *table;
100530
100531 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100532 GFP_KERNEL);
100533 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100534 index 7a394df..bd91a8a 100644
100535 --- a/net/netfilter/nf_conntrack_timestamp.c
100536 +++ b/net/netfilter/nf_conntrack_timestamp.c
100537 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100538 #ifdef CONFIG_SYSCTL
100539 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100540 {
100541 - struct ctl_table *table;
100542 + ctl_table_no_const *table;
100543
100544 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100545 GFP_KERNEL);
100546 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100547 index 85296d4..8becdec 100644
100548 --- a/net/netfilter/nf_log.c
100549 +++ b/net/netfilter/nf_log.c
100550 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100551
100552 #ifdef CONFIG_SYSCTL
100553 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100554 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100555 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100556
100557 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100558 void __user *buffer, size_t *lenp, loff_t *ppos)
100559 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100560 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100561 mutex_unlock(&nf_log_mutex);
100562 } else {
100563 + ctl_table_no_const nf_log_table = *table;
100564 +
100565 mutex_lock(&nf_log_mutex);
100566 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100567 lockdep_is_held(&nf_log_mutex));
100568 if (!logger)
100569 - table->data = "NONE";
100570 + nf_log_table.data = "NONE";
100571 else
100572 - table->data = logger->name;
100573 - r = proc_dostring(table, write, buffer, lenp, ppos);
100574 + nf_log_table.data = logger->name;
100575 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100576 mutex_unlock(&nf_log_mutex);
100577 }
100578
100579 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100580 index f042ae5..30ea486 100644
100581 --- a/net/netfilter/nf_sockopt.c
100582 +++ b/net/netfilter/nf_sockopt.c
100583 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100584 }
100585 }
100586
100587 - list_add(&reg->list, &nf_sockopts);
100588 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100589 out:
100590 mutex_unlock(&nf_sockopt_mutex);
100591 return ret;
100592 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100593 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100594 {
100595 mutex_lock(&nf_sockopt_mutex);
100596 - list_del(&reg->list);
100597 + pax_list_del((struct list_head *)&reg->list);
100598 mutex_unlock(&nf_sockopt_mutex);
100599 }
100600 EXPORT_SYMBOL(nf_unregister_sockopt);
100601 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
100602 index 71a9f49..c09b60c 100644
100603 --- a/net/netfilter/nf_tables_api.c
100604 +++ b/net/netfilter/nf_tables_api.c
100605 @@ -148,8 +148,8 @@ static int nf_tables_chain_type_lookup(const struct nft_af_info *afi,
100606 #ifdef CONFIG_MODULES
100607 if (type < 0 && autoload) {
100608 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
100609 - request_module("nft-chain-%u-%*.s", afi->family,
100610 - nla_len(nla)-1, (const char *)nla_data(nla));
100611 + request_module("nft-chain-%u-%.*s", afi->family,
100612 + nla_len(nla), (const char *)nla_data(nla));
100613 nfnl_lock(NFNL_SUBSYS_NFTABLES);
100614 type = __nf_tables_chain_type_lookup(afi->family, nla);
100615 }
100616 @@ -1916,7 +1916,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
100617
100618 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
100619 [NFTA_SET_TABLE] = { .type = NLA_STRING },
100620 - [NFTA_SET_NAME] = { .type = NLA_STRING },
100621 + [NFTA_SET_NAME] = { .type = NLA_STRING,
100622 + .len = IFNAMSIZ - 1 },
100623 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
100624 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
100625 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
100626 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100627 index a155d19..726b0f2 100644
100628 --- a/net/netfilter/nfnetlink_log.c
100629 +++ b/net/netfilter/nfnetlink_log.c
100630 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100631 struct nfnl_log_net {
100632 spinlock_t instances_lock;
100633 struct hlist_head instance_table[INSTANCE_BUCKETS];
100634 - atomic_t global_seq;
100635 + atomic_unchecked_t global_seq;
100636 };
100637
100638 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100639 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100640 /* global sequence number */
100641 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100642 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100643 - htonl(atomic_inc_return(&log->global_seq))))
100644 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
100645 goto nla_put_failure;
100646
100647 if (data_len) {
100648 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100649 index da0c1f4..f79737a 100644
100650 --- a/net/netfilter/nft_compat.c
100651 +++ b/net/netfilter/nft_compat.c
100652 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100653 /* We want to reuse existing compat_to_user */
100654 old_fs = get_fs();
100655 set_fs(KERNEL_DS);
100656 - t->compat_to_user(out, in);
100657 + t->compat_to_user((void __force_user *)out, in);
100658 set_fs(old_fs);
100659 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100660 kfree(out);
100661 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100662 /* We want to reuse existing compat_to_user */
100663 old_fs = get_fs();
100664 set_fs(KERNEL_DS);
100665 - m->compat_to_user(out, in);
100666 + m->compat_to_user((void __force_user *)out, in);
100667 set_fs(old_fs);
100668 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
100669 kfree(out);
100670 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
100671 new file mode 100644
100672 index 0000000..c566332
100673 --- /dev/null
100674 +++ b/net/netfilter/xt_gradm.c
100675 @@ -0,0 +1,51 @@
100676 +/*
100677 + * gradm match for netfilter
100678 + * Copyright © Zbigniew Krzystolik, 2010
100679 + *
100680 + * This program is free software; you can redistribute it and/or modify
100681 + * it under the terms of the GNU General Public License; either version
100682 + * 2 or 3 as published by the Free Software Foundation.
100683 + */
100684 +#include <linux/module.h>
100685 +#include <linux/moduleparam.h>
100686 +#include <linux/skbuff.h>
100687 +#include <linux/netfilter/x_tables.h>
100688 +#include <linux/grsecurity.h>
100689 +#include <linux/netfilter/xt_gradm.h>
100690 +
100691 +static bool
100692 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
100693 +{
100694 + const struct xt_gradm_mtinfo *info = par->matchinfo;
100695 + bool retval = false;
100696 + if (gr_acl_is_enabled())
100697 + retval = true;
100698 + return retval ^ info->invflags;
100699 +}
100700 +
100701 +static struct xt_match gradm_mt_reg __read_mostly = {
100702 + .name = "gradm",
100703 + .revision = 0,
100704 + .family = NFPROTO_UNSPEC,
100705 + .match = gradm_mt,
100706 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
100707 + .me = THIS_MODULE,
100708 +};
100709 +
100710 +static int __init gradm_mt_init(void)
100711 +{
100712 + return xt_register_match(&gradm_mt_reg);
100713 +}
100714 +
100715 +static void __exit gradm_mt_exit(void)
100716 +{
100717 + xt_unregister_match(&gradm_mt_reg);
100718 +}
100719 +
100720 +module_init(gradm_mt_init);
100721 +module_exit(gradm_mt_exit);
100722 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
100723 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
100724 +MODULE_LICENSE("GPL");
100725 +MODULE_ALIAS("ipt_gradm");
100726 +MODULE_ALIAS("ip6t_gradm");
100727 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
100728 index 4fe4fb4..87a89e5 100644
100729 --- a/net/netfilter/xt_statistic.c
100730 +++ b/net/netfilter/xt_statistic.c
100731 @@ -19,7 +19,7 @@
100732 #include <linux/module.h>
100733
100734 struct xt_statistic_priv {
100735 - atomic_t count;
100736 + atomic_unchecked_t count;
100737 } ____cacheline_aligned_in_smp;
100738
100739 MODULE_LICENSE("GPL");
100740 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
100741 break;
100742 case XT_STATISTIC_MODE_NTH:
100743 do {
100744 - oval = atomic_read(&info->master->count);
100745 + oval = atomic_read_unchecked(&info->master->count);
100746 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
100747 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
100748 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
100749 if (nval == 0)
100750 ret = !ret;
100751 break;
100752 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
100753 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
100754 if (info->master == NULL)
100755 return -ENOMEM;
100756 - atomic_set(&info->master->count, info->u.nth.count);
100757 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
100758
100759 return 0;
100760 }
100761 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
100762 index bca50b9..782ec12 100644
100763 --- a/net/netlink/af_netlink.c
100764 +++ b/net/netlink/af_netlink.c
100765 @@ -249,7 +249,7 @@ static void netlink_overrun(struct sock *sk)
100766 sk->sk_error_report(sk);
100767 }
100768 }
100769 - atomic_inc(&sk->sk_drops);
100770 + atomic_inc_unchecked(&sk->sk_drops);
100771 }
100772
100773 static void netlink_rcv_wake(struct sock *sk)
100774 @@ -1481,8 +1481,8 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
100775 if (addr->sa_family != AF_NETLINK)
100776 return -EINVAL;
100777
100778 - /* Only superuser is allowed to send multicasts */
100779 - if (nladdr->nl_groups && !netlink_capable(sock, NL_CFG_F_NONROOT_SEND))
100780 + if ((nladdr->nl_groups || nladdr->nl_pid) &&
100781 + !netlink_capable(sock, NL_CFG_F_NONROOT_SEND))
100782 return -EPERM;
100783
100784 if (!nlk->portid)
100785 @@ -2940,7 +2940,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
100786 sk_wmem_alloc_get(s),
100787 nlk->cb_running,
100788 atomic_read(&s->sk_refcnt),
100789 - atomic_read(&s->sk_drops),
100790 + atomic_read_unchecked(&s->sk_drops),
100791 sock_i_ino(s)
100792 );
100793
100794 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
100795 index 53c19a3..b0ac04a 100644
100796 --- a/net/netrom/af_netrom.c
100797 +++ b/net/netrom/af_netrom.c
100798 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
100799 *uaddr_len = sizeof(struct full_sockaddr_ax25);
100800 } else {
100801 sax->fsa_ax25.sax25_family = AF_NETROM;
100802 - sax->fsa_ax25.sax25_ndigis = 0;
100803 sax->fsa_ax25.sax25_call = nr->source_addr;
100804 *uaddr_len = sizeof(struct sockaddr_ax25);
100805 }
100806 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
100807 index 88cfbc1..05d73f5 100644
100808 --- a/net/packet/af_packet.c
100809 +++ b/net/packet/af_packet.c
100810 @@ -1720,7 +1720,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100811
100812 spin_lock(&sk->sk_receive_queue.lock);
100813 po->stats.stats1.tp_packets++;
100814 - skb->dropcount = atomic_read(&sk->sk_drops);
100815 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
100816 __skb_queue_tail(&sk->sk_receive_queue, skb);
100817 spin_unlock(&sk->sk_receive_queue.lock);
100818 sk->sk_data_ready(sk, skb->len);
100819 @@ -1729,7 +1729,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100820 drop_n_acct:
100821 spin_lock(&sk->sk_receive_queue.lock);
100822 po->stats.stats1.tp_drops++;
100823 - atomic_inc(&sk->sk_drops);
100824 + atomic_inc_unchecked(&sk->sk_drops);
100825 spin_unlock(&sk->sk_receive_queue.lock);
100826
100827 drop_n_restore:
100828 @@ -3275,7 +3275,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100829 case PACKET_HDRLEN:
100830 if (len > sizeof(int))
100831 len = sizeof(int);
100832 - if (copy_from_user(&val, optval, len))
100833 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
100834 return -EFAULT;
100835 switch (val) {
100836 case TPACKET_V1:
100837 @@ -3318,7 +3318,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100838 len = lv;
100839 if (put_user(len, optlen))
100840 return -EFAULT;
100841 - if (copy_to_user(optval, data, len))
100842 + if (len > sizeof(st) || copy_to_user(optval, data, len))
100843 return -EFAULT;
100844 return 0;
100845 }
100846 diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
100847 index 38946b2..12c30f3 100644
100848 --- a/net/phonet/datagram.c
100849 +++ b/net/phonet/datagram.c
100850 @@ -139,6 +139,9 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
100851 MSG_CMSG_COMPAT))
100852 goto out_nofree;
100853
100854 + if (addr_len)
100855 + *addr_len = sizeof(sa);
100856 +
100857 skb = skb_recv_datagram(sk, flags, noblock, &rval);
100858 if (skb == NULL)
100859 goto out_nofree;
100860 @@ -159,10 +162,8 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
100861
100862 rval = (flags & MSG_TRUNC) ? skb->len : copylen;
100863
100864 - if (msg->msg_name != NULL) {
100865 - memcpy(msg->msg_name, &sa, sizeof(sa));
100866 - *addr_len = sizeof(sa);
100867 - }
100868 + if (msg->msg_name != NULL)
100869 + memcpy(msg->msg_name, &sa, sizeof(struct sockaddr_pn));
100870
100871 out:
100872 skb_free_datagram(sk, skb);
100873 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
100874 index e774117..900b8b7 100644
100875 --- a/net/phonet/pep.c
100876 +++ b/net/phonet/pep.c
100877 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100878
100879 case PNS_PEP_CTRL_REQ:
100880 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
100881 - atomic_inc(&sk->sk_drops);
100882 + atomic_inc_unchecked(&sk->sk_drops);
100883 break;
100884 }
100885 __skb_pull(skb, 4);
100886 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100887 }
100888
100889 if (pn->rx_credits == 0) {
100890 - atomic_inc(&sk->sk_drops);
100891 + atomic_inc_unchecked(&sk->sk_drops);
100892 err = -ENOBUFS;
100893 break;
100894 }
100895 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
100896 }
100897
100898 if (pn->rx_credits == 0) {
100899 - atomic_inc(&sk->sk_drops);
100900 + atomic_inc_unchecked(&sk->sk_drops);
100901 err = NET_RX_DROP;
100902 break;
100903 }
100904 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
100905 index 008214a..bb68240 100644
100906 --- a/net/phonet/socket.c
100907 +++ b/net/phonet/socket.c
100908 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
100909 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
100910 sock_i_ino(sk),
100911 atomic_read(&sk->sk_refcnt), sk,
100912 - atomic_read(&sk->sk_drops));
100913 + atomic_read_unchecked(&sk->sk_drops));
100914 }
100915 seq_pad(seq, '\n');
100916 return 0;
100917 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
100918 index c02a8c4..3c5b600 100644
100919 --- a/net/phonet/sysctl.c
100920 +++ b/net/phonet/sysctl.c
100921 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
100922 {
100923 int ret;
100924 int range[2] = {local_port_range[0], local_port_range[1]};
100925 - struct ctl_table tmp = {
100926 + ctl_table_no_const tmp = {
100927 .data = &range,
100928 .maxlen = sizeof(range),
100929 .mode = table->mode,
100930 diff --git a/net/rds/cong.c b/net/rds/cong.c
100931 index e5b65ac..f3b6fb7 100644
100932 --- a/net/rds/cong.c
100933 +++ b/net/rds/cong.c
100934 @@ -78,7 +78,7 @@
100935 * finds that the saved generation number is smaller than the global generation
100936 * number, it wakes up the process.
100937 */
100938 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
100939 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
100940
100941 /*
100942 * Congestion monitoring
100943 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
100944 rdsdebug("waking map %p for %pI4\n",
100945 map, &map->m_addr);
100946 rds_stats_inc(s_cong_update_received);
100947 - atomic_inc(&rds_cong_generation);
100948 + atomic_inc_unchecked(&rds_cong_generation);
100949 if (waitqueue_active(&map->m_waitq))
100950 wake_up(&map->m_waitq);
100951 if (waitqueue_active(&rds_poll_waitq))
100952 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
100953
100954 int rds_cong_updated_since(unsigned long *recent)
100955 {
100956 - unsigned long gen = atomic_read(&rds_cong_generation);
100957 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
100958
100959 if (likely(*recent == gen))
100960 return 0;
100961 diff --git a/net/rds/ib.h b/net/rds/ib.h
100962 index 7280ab8..e04f4ea 100644
100963 --- a/net/rds/ib.h
100964 +++ b/net/rds/ib.h
100965 @@ -128,7 +128,7 @@ struct rds_ib_connection {
100966 /* sending acks */
100967 unsigned long i_ack_flags;
100968 #ifdef KERNEL_HAS_ATOMIC64
100969 - atomic64_t i_ack_next; /* next ACK to send */
100970 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100971 #else
100972 spinlock_t i_ack_lock; /* protect i_ack_next */
100973 u64 i_ack_next; /* next ACK to send */
100974 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
100975 index 31b74f5..dc1fbfa 100644
100976 --- a/net/rds/ib_cm.c
100977 +++ b/net/rds/ib_cm.c
100978 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
100979 /* Clear the ACK state */
100980 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100981 #ifdef KERNEL_HAS_ATOMIC64
100982 - atomic64_set(&ic->i_ack_next, 0);
100983 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100984 #else
100985 ic->i_ack_next = 0;
100986 #endif
100987 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
100988 index b7ebe23..b6352f6 100644
100989 --- a/net/rds/ib_recv.c
100990 +++ b/net/rds/ib_recv.c
100991 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100992 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
100993 int ack_required)
100994 {
100995 - atomic64_set(&ic->i_ack_next, seq);
100996 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100997 if (ack_required) {
100998 smp_mb__before_clear_bit();
100999 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
101000 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
101001 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
101002 smp_mb__after_clear_bit();
101003
101004 - return atomic64_read(&ic->i_ack_next);
101005 + return atomic64_read_unchecked(&ic->i_ack_next);
101006 }
101007 #endif
101008
101009 diff --git a/net/rds/iw.h b/net/rds/iw.h
101010 index 04ce3b1..48119a6 100644
101011 --- a/net/rds/iw.h
101012 +++ b/net/rds/iw.h
101013 @@ -134,7 +134,7 @@ struct rds_iw_connection {
101014 /* sending acks */
101015 unsigned long i_ack_flags;
101016 #ifdef KERNEL_HAS_ATOMIC64
101017 - atomic64_t i_ack_next; /* next ACK to send */
101018 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
101019 #else
101020 spinlock_t i_ack_lock; /* protect i_ack_next */
101021 u64 i_ack_next; /* next ACK to send */
101022 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
101023 index a91e1db..cf3053f 100644
101024 --- a/net/rds/iw_cm.c
101025 +++ b/net/rds/iw_cm.c
101026 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
101027 /* Clear the ACK state */
101028 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
101029 #ifdef KERNEL_HAS_ATOMIC64
101030 - atomic64_set(&ic->i_ack_next, 0);
101031 + atomic64_set_unchecked(&ic->i_ack_next, 0);
101032 #else
101033 ic->i_ack_next = 0;
101034 #endif
101035 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
101036 index 4503335..db566b4 100644
101037 --- a/net/rds/iw_recv.c
101038 +++ b/net/rds/iw_recv.c
101039 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
101040 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
101041 int ack_required)
101042 {
101043 - atomic64_set(&ic->i_ack_next, seq);
101044 + atomic64_set_unchecked(&ic->i_ack_next, seq);
101045 if (ack_required) {
101046 smp_mb__before_clear_bit();
101047 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
101048 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
101049 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
101050 smp_mb__after_clear_bit();
101051
101052 - return atomic64_read(&ic->i_ack_next);
101053 + return atomic64_read_unchecked(&ic->i_ack_next);
101054 }
101055 #endif
101056
101057 diff --git a/net/rds/rds.h b/net/rds/rds.h
101058 index 48f8ffc..0ef3eec 100644
101059 --- a/net/rds/rds.h
101060 +++ b/net/rds/rds.h
101061 @@ -449,7 +449,7 @@ struct rds_transport {
101062 void (*sync_mr)(void *trans_private, int direction);
101063 void (*free_mr)(void *trans_private, int invalidate);
101064 void (*flush_mrs)(void);
101065 -};
101066 +} __do_const;
101067
101068 struct rds_sock {
101069 struct sock rs_sk;
101070 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
101071 index edac9ef..16bcb98 100644
101072 --- a/net/rds/tcp.c
101073 +++ b/net/rds/tcp.c
101074 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
101075 int val = 1;
101076
101077 set_fs(KERNEL_DS);
101078 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
101079 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
101080 sizeof(val));
101081 set_fs(oldfs);
101082 }
101083 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
101084 index 81cf5a4..b5826ff 100644
101085 --- a/net/rds/tcp_send.c
101086 +++ b/net/rds/tcp_send.c
101087 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
101088
101089 oldfs = get_fs();
101090 set_fs(KERNEL_DS);
101091 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
101092 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
101093 sizeof(val));
101094 set_fs(oldfs);
101095 }
101096 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
101097 index e61aa60..f07cc89 100644
101098 --- a/net/rxrpc/af_rxrpc.c
101099 +++ b/net/rxrpc/af_rxrpc.c
101100 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
101101 __be32 rxrpc_epoch;
101102
101103 /* current debugging ID */
101104 -atomic_t rxrpc_debug_id;
101105 +atomic_unchecked_t rxrpc_debug_id;
101106
101107 /* count of skbs currently in use */
101108 atomic_t rxrpc_n_skbs;
101109 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
101110 index e4d9cbc..b229649 100644
101111 --- a/net/rxrpc/ar-ack.c
101112 +++ b/net/rxrpc/ar-ack.c
101113 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
101114
101115 _enter("{%d,%d,%d,%d},",
101116 call->acks_hard, call->acks_unacked,
101117 - atomic_read(&call->sequence),
101118 + atomic_read_unchecked(&call->sequence),
101119 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
101120
101121 stop = 0;
101122 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
101123
101124 /* each Tx packet has a new serial number */
101125 sp->hdr.serial =
101126 - htonl(atomic_inc_return(&call->conn->serial));
101127 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
101128
101129 hdr = (struct rxrpc_header *) txb->head;
101130 hdr->serial = sp->hdr.serial;
101131 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
101132 */
101133 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
101134 {
101135 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
101136 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
101137 }
101138
101139 /*
101140 @@ -629,7 +629,7 @@ process_further:
101141
101142 latest = ntohl(sp->hdr.serial);
101143 hard = ntohl(ack.firstPacket);
101144 - tx = atomic_read(&call->sequence);
101145 + tx = atomic_read_unchecked(&call->sequence);
101146
101147 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
101148 latest,
101149 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
101150 goto maybe_reschedule;
101151
101152 send_ACK_with_skew:
101153 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
101154 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
101155 ntohl(ack.serial));
101156 send_ACK:
101157 mtu = call->conn->trans->peer->if_mtu;
101158 @@ -1173,7 +1173,7 @@ send_ACK:
101159 ackinfo.rxMTU = htonl(5692);
101160 ackinfo.jumbo_max = htonl(4);
101161
101162 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
101163 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
101164 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
101165 ntohl(hdr.serial),
101166 ntohs(ack.maxSkew),
101167 @@ -1191,7 +1191,7 @@ send_ACK:
101168 send_message:
101169 _debug("send message");
101170
101171 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
101172 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
101173 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
101174 send_message_2:
101175
101176 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
101177 index a3bbb36..3341fb9 100644
101178 --- a/net/rxrpc/ar-call.c
101179 +++ b/net/rxrpc/ar-call.c
101180 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
101181 spin_lock_init(&call->lock);
101182 rwlock_init(&call->state_lock);
101183 atomic_set(&call->usage, 1);
101184 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
101185 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101186 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
101187
101188 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
101189 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
101190 index 4106ca9..a338d7a 100644
101191 --- a/net/rxrpc/ar-connection.c
101192 +++ b/net/rxrpc/ar-connection.c
101193 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
101194 rwlock_init(&conn->lock);
101195 spin_lock_init(&conn->state_lock);
101196 atomic_set(&conn->usage, 1);
101197 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
101198 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101199 conn->avail_calls = RXRPC_MAXCALLS;
101200 conn->size_align = 4;
101201 conn->header_size = sizeof(struct rxrpc_header);
101202 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
101203 index e7ed43a..6afa140 100644
101204 --- a/net/rxrpc/ar-connevent.c
101205 +++ b/net/rxrpc/ar-connevent.c
101206 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
101207
101208 len = iov[0].iov_len + iov[1].iov_len;
101209
101210 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
101211 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101212 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
101213
101214 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
101215 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
101216 index 529572f..c758ca7 100644
101217 --- a/net/rxrpc/ar-input.c
101218 +++ b/net/rxrpc/ar-input.c
101219 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
101220 /* track the latest serial number on this connection for ACK packet
101221 * information */
101222 serial = ntohl(sp->hdr.serial);
101223 - hi_serial = atomic_read(&call->conn->hi_serial);
101224 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
101225 while (serial > hi_serial)
101226 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
101227 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
101228 serial);
101229
101230 /* request ACK generation for any ACK or DATA packet that requests
101231 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
101232 index 5f43675..ca07817 100644
101233 --- a/net/rxrpc/ar-internal.h
101234 +++ b/net/rxrpc/ar-internal.h
101235 @@ -272,8 +272,8 @@ struct rxrpc_connection {
101236 int error; /* error code for local abort */
101237 int debug_id; /* debug ID for printks */
101238 unsigned int call_counter; /* call ID counter */
101239 - atomic_t serial; /* packet serial number counter */
101240 - atomic_t hi_serial; /* highest serial number received */
101241 + atomic_unchecked_t serial; /* packet serial number counter */
101242 + atomic_unchecked_t hi_serial; /* highest serial number received */
101243 u8 avail_calls; /* number of calls available */
101244 u8 size_align; /* data size alignment (for security) */
101245 u8 header_size; /* rxrpc + security header size */
101246 @@ -346,7 +346,7 @@ struct rxrpc_call {
101247 spinlock_t lock;
101248 rwlock_t state_lock; /* lock for state transition */
101249 atomic_t usage;
101250 - atomic_t sequence; /* Tx data packet sequence counter */
101251 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
101252 u32 abort_code; /* local/remote abort code */
101253 enum { /* current state of call */
101254 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
101255 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
101256 */
101257 extern atomic_t rxrpc_n_skbs;
101258 extern __be32 rxrpc_epoch;
101259 -extern atomic_t rxrpc_debug_id;
101260 +extern atomic_unchecked_t rxrpc_debug_id;
101261 extern struct workqueue_struct *rxrpc_workqueue;
101262
101263 /*
101264 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
101265 index 87f7135..74d3703 100644
101266 --- a/net/rxrpc/ar-local.c
101267 +++ b/net/rxrpc/ar-local.c
101268 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
101269 spin_lock_init(&local->lock);
101270 rwlock_init(&local->services_lock);
101271 atomic_set(&local->usage, 1);
101272 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
101273 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101274 memcpy(&local->srx, srx, sizeof(*srx));
101275 }
101276
101277 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
101278 index e1ac183..b43e10e 100644
101279 --- a/net/rxrpc/ar-output.c
101280 +++ b/net/rxrpc/ar-output.c
101281 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
101282 sp->hdr.cid = call->cid;
101283 sp->hdr.callNumber = call->call_id;
101284 sp->hdr.seq =
101285 - htonl(atomic_inc_return(&call->sequence));
101286 + htonl(atomic_inc_return_unchecked(&call->sequence));
101287 sp->hdr.serial =
101288 - htonl(atomic_inc_return(&conn->serial));
101289 + htonl(atomic_inc_return_unchecked(&conn->serial));
101290 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
101291 sp->hdr.userStatus = 0;
101292 sp->hdr.securityIndex = conn->security_ix;
101293 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
101294 index bebaa43..2644591 100644
101295 --- a/net/rxrpc/ar-peer.c
101296 +++ b/net/rxrpc/ar-peer.c
101297 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
101298 INIT_LIST_HEAD(&peer->error_targets);
101299 spin_lock_init(&peer->lock);
101300 atomic_set(&peer->usage, 1);
101301 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
101302 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101303 memcpy(&peer->srx, srx, sizeof(*srx));
101304
101305 rxrpc_assess_MTU_size(peer);
101306 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
101307 index 38047f7..9f48511 100644
101308 --- a/net/rxrpc/ar-proc.c
101309 +++ b/net/rxrpc/ar-proc.c
101310 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
101311 atomic_read(&conn->usage),
101312 rxrpc_conn_states[conn->state],
101313 key_serial(conn->key),
101314 - atomic_read(&conn->serial),
101315 - atomic_read(&conn->hi_serial));
101316 + atomic_read_unchecked(&conn->serial),
101317 + atomic_read_unchecked(&conn->hi_serial));
101318
101319 return 0;
101320 }
101321 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
101322 index 92df566..87ec1bf 100644
101323 --- a/net/rxrpc/ar-transport.c
101324 +++ b/net/rxrpc/ar-transport.c
101325 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
101326 spin_lock_init(&trans->client_lock);
101327 rwlock_init(&trans->conn_lock);
101328 atomic_set(&trans->usage, 1);
101329 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
101330 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101331
101332 if (peer->srx.transport.family == AF_INET) {
101333 switch (peer->srx.transport_type) {
101334 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
101335 index f226709..0e735a8 100644
101336 --- a/net/rxrpc/rxkad.c
101337 +++ b/net/rxrpc/rxkad.c
101338 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
101339
101340 len = iov[0].iov_len + iov[1].iov_len;
101341
101342 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
101343 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101344 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
101345
101346 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
101347 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
101348
101349 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
101350
101351 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
101352 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101353 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
101354
101355 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
101356 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
101357 index 7567e6f..299382b 100644
101358 --- a/net/sctp/ipv6.c
101359 +++ b/net/sctp/ipv6.c
101360 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
101361 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
101362 };
101363
101364 -static struct sctp_af sctp_af_inet6 = {
101365 +static struct sctp_af sctp_af_inet6 __read_only = {
101366 .sa_family = AF_INET6,
101367 .sctp_xmit = sctp_v6_xmit,
101368 .setsockopt = ipv6_setsockopt,
101369 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
101370 #endif
101371 };
101372
101373 -static struct sctp_pf sctp_pf_inet6 = {
101374 +static struct sctp_pf sctp_pf_inet6 __read_only = {
101375 .event_msgname = sctp_inet6_event_msgname,
101376 .skb_msgname = sctp_inet6_skb_msgname,
101377 .af_supported = sctp_inet6_af_supported,
101378 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
101379
101380 void sctp_v6_pf_exit(void)
101381 {
101382 - list_del(&sctp_af_inet6.list);
101383 + pax_list_del(&sctp_af_inet6.list);
101384 }
101385
101386 /* Initialize IPv6 support and register with socket layer. */
101387 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
101388 index 5e17092..19be1d4 100644
101389 --- a/net/sctp/protocol.c
101390 +++ b/net/sctp/protocol.c
101391 @@ -832,8 +832,10 @@ int sctp_register_af(struct sctp_af *af)
101392 return 0;
101393 }
101394
101395 + pax_open_kernel();
101396 INIT_LIST_HEAD(&af->list);
101397 - list_add_tail(&af->list, &sctp_address_families);
101398 + pax_close_kernel();
101399 + pax_list_add_tail(&af->list, &sctp_address_families);
101400 return 1;
101401 }
101402
101403 @@ -963,7 +965,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
101404
101405 static struct sctp_af sctp_af_inet;
101406
101407 -static struct sctp_pf sctp_pf_inet = {
101408 +static struct sctp_pf sctp_pf_inet __read_only = {
101409 .event_msgname = sctp_inet_event_msgname,
101410 .skb_msgname = sctp_inet_skb_msgname,
101411 .af_supported = sctp_inet_af_supported,
101412 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
101413 };
101414
101415 /* IPv4 address related functions. */
101416 -static struct sctp_af sctp_af_inet = {
101417 +static struct sctp_af sctp_af_inet __read_only = {
101418 .sa_family = AF_INET,
101419 .sctp_xmit = sctp_v4_xmit,
101420 .setsockopt = ip_setsockopt,
101421 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
101422
101423 static void sctp_v4_pf_exit(void)
101424 {
101425 - list_del(&sctp_af_inet.list);
101426 + pax_list_del(&sctp_af_inet.list);
101427 }
101428
101429 static int sctp_v4_protosw_init(void)
101430 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
101431 index 1a6eef3..17e898f 100644
101432 --- a/net/sctp/sm_sideeffect.c
101433 +++ b/net/sctp/sm_sideeffect.c
101434 @@ -440,7 +440,7 @@ static void sctp_generate_sack_event(unsigned long data)
101435 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
101436 }
101437
101438 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101439 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101440 NULL,
101441 sctp_generate_t1_cookie_event,
101442 sctp_generate_t1_init_event,
101443 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
101444 index 146b35d..1021a34 100644
101445 --- a/net/sctp/socket.c
101446 +++ b/net/sctp/socket.c
101447 @@ -2176,11 +2176,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
101448 {
101449 struct sctp_association *asoc;
101450 struct sctp_ulpevent *event;
101451 + struct sctp_event_subscribe subscribe;
101452
101453 if (optlen > sizeof(struct sctp_event_subscribe))
101454 return -EINVAL;
101455 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
101456 + if (copy_from_user(&subscribe, optval, optlen))
101457 return -EFAULT;
101458 + sctp_sk(sk)->subscribe = subscribe;
101459
101460 /*
101461 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
101462 @@ -4252,13 +4254,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
101463 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101464 int __user *optlen)
101465 {
101466 + struct sctp_event_subscribe subscribe;
101467 +
101468 if (len <= 0)
101469 return -EINVAL;
101470 if (len > sizeof(struct sctp_event_subscribe))
101471 len = sizeof(struct sctp_event_subscribe);
101472 if (put_user(len, optlen))
101473 return -EFAULT;
101474 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
101475 + subscribe = sctp_sk(sk)->subscribe;
101476 + if (copy_to_user(optval, &subscribe, len))
101477 return -EFAULT;
101478 return 0;
101479 }
101480 @@ -4276,6 +4281,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101481 */
101482 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
101483 {
101484 + __u32 autoclose;
101485 +
101486 /* Applicable to UDP-style socket only */
101487 if (sctp_style(sk, TCP))
101488 return -EOPNOTSUPP;
101489 @@ -4284,7 +4291,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
101490 len = sizeof(int);
101491 if (put_user(len, optlen))
101492 return -EFAULT;
101493 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
101494 + autoclose = sctp_sk(sk)->autoclose;
101495 + if (copy_to_user(optval, &autoclose, sizeof(int)))
101496 return -EFAULT;
101497 return 0;
101498 }
101499 @@ -4656,12 +4664,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
101500 */
101501 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
101502 {
101503 + struct sctp_initmsg initmsg;
101504 +
101505 if (len < sizeof(struct sctp_initmsg))
101506 return -EINVAL;
101507 len = sizeof(struct sctp_initmsg);
101508 if (put_user(len, optlen))
101509 return -EFAULT;
101510 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
101511 + initmsg = sctp_sk(sk)->initmsg;
101512 + if (copy_to_user(optval, &initmsg, len))
101513 return -EFAULT;
101514 return 0;
101515 }
101516 @@ -4702,6 +4713,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
101517 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
101518 if (space_left < addrlen)
101519 return -ENOMEM;
101520 + if (addrlen > sizeof(temp) || addrlen < 0)
101521 + return -EFAULT;
101522 if (copy_to_user(to, &temp, addrlen))
101523 return -EFAULT;
101524 to += addrlen;
101525 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
101526 index b0565af..d135e6e 100644
101527 --- a/net/sctp/sysctl.c
101528 +++ b/net/sctp/sysctl.c
101529 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
101530 {
101531 struct net *net = current->nsproxy->net_ns;
101532 char tmp[8];
101533 - struct ctl_table tbl;
101534 + ctl_table_no_const tbl;
101535 int ret;
101536 int changed = 0;
101537 char *none = "none";
101538 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
101539 {
101540 struct net *net = current->nsproxy->net_ns;
101541 int new_value;
101542 - struct ctl_table tbl;
101543 + ctl_table_no_const tbl;
101544 unsigned int min = *(unsigned int *) ctl->extra1;
101545 unsigned int max = *(unsigned int *) ctl->extra2;
101546 int ret;
101547 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101548 {
101549 struct net *net = current->nsproxy->net_ns;
101550 int new_value;
101551 - struct ctl_table tbl;
101552 + ctl_table_no_const tbl;
101553 unsigned int min = *(unsigned int *) ctl->extra1;
101554 unsigned int max = *(unsigned int *) ctl->extra2;
101555 int ret;
101556 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101557
101558 int sctp_sysctl_net_register(struct net *net)
101559 {
101560 - struct ctl_table *table;
101561 + ctl_table_no_const *table;
101562 int i;
101563
101564 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
101565 diff --git a/net/socket.c b/net/socket.c
101566 index e83c416..5b883e0 100644
101567 --- a/net/socket.c
101568 +++ b/net/socket.c
101569 @@ -88,6 +88,7 @@
101570 #include <linux/magic.h>
101571 #include <linux/slab.h>
101572 #include <linux/xattr.h>
101573 +#include <linux/in.h>
101574
101575 #include <asm/uaccess.h>
101576 #include <asm/unistd.h>
101577 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
101578 unsigned int sysctl_net_busy_poll __read_mostly;
101579 #endif
101580
101581 +#include <linux/grsock.h>
101582 +
101583 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
101584 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
101585 unsigned long nr_segs, loff_t pos);
101586 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
101587 */
101588
101589 static DEFINE_SPINLOCK(net_family_lock);
101590 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101591 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101592
101593 /*
101594 * Statistics counters of the socket lists
101595 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
101596 &sockfs_dentry_operations, SOCKFS_MAGIC);
101597 }
101598
101599 -static struct vfsmount *sock_mnt __read_mostly;
101600 +struct vfsmount *sock_mnt __read_mostly;
101601
101602 static struct file_system_type sock_fs_type = {
101603 .name = "sockfs",
101604 @@ -1255,6 +1258,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101605 return -EAFNOSUPPORT;
101606 if (type < 0 || type >= SOCK_MAX)
101607 return -EINVAL;
101608 + if (protocol < 0)
101609 + return -EINVAL;
101610
101611 /* Compatibility.
101612
101613 @@ -1275,6 +1280,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101614 if (err)
101615 return err;
101616
101617 + if(!kern && !gr_search_socket(family, type, protocol)) {
101618 + if (rcu_access_pointer(net_families[family]) == NULL)
101619 + return -EAFNOSUPPORT;
101620 + else
101621 + return -EACCES;
101622 + }
101623 +
101624 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
101625 + if (rcu_access_pointer(net_families[family]) == NULL)
101626 + return -EAFNOSUPPORT;
101627 + else
101628 + return -EACCES;
101629 + }
101630 +
101631 /*
101632 * Allocate the socket and allow the family to set things up. if
101633 * the protocol is 0, the family is instructed to select an appropriate
101634 @@ -1513,6 +1532,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101635 if (sock) {
101636 err = move_addr_to_kernel(umyaddr, addrlen, &address);
101637 if (err >= 0) {
101638 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
101639 + err = -EACCES;
101640 + goto error;
101641 + }
101642 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
101643 + if (err)
101644 + goto error;
101645 +
101646 err = security_socket_bind(sock,
101647 (struct sockaddr *)&address,
101648 addrlen);
101649 @@ -1521,6 +1548,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101650 (struct sockaddr *)
101651 &address, addrlen);
101652 }
101653 +error:
101654 fput_light(sock->file, fput_needed);
101655 }
101656 return err;
101657 @@ -1544,10 +1572,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
101658 if ((unsigned int)backlog > somaxconn)
101659 backlog = somaxconn;
101660
101661 + if (gr_handle_sock_server_other(sock->sk)) {
101662 + err = -EPERM;
101663 + goto error;
101664 + }
101665 +
101666 + err = gr_search_listen(sock);
101667 + if (err)
101668 + goto error;
101669 +
101670 err = security_socket_listen(sock, backlog);
101671 if (!err)
101672 err = sock->ops->listen(sock, backlog);
101673
101674 +error:
101675 fput_light(sock->file, fput_needed);
101676 }
101677 return err;
101678 @@ -1591,6 +1629,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101679 newsock->type = sock->type;
101680 newsock->ops = sock->ops;
101681
101682 + if (gr_handle_sock_server_other(sock->sk)) {
101683 + err = -EPERM;
101684 + sock_release(newsock);
101685 + goto out_put;
101686 + }
101687 +
101688 + err = gr_search_accept(sock);
101689 + if (err) {
101690 + sock_release(newsock);
101691 + goto out_put;
101692 + }
101693 +
101694 /*
101695 * We don't need try_module_get here, as the listening socket (sock)
101696 * has the protocol module (sock->ops->owner) held.
101697 @@ -1636,6 +1686,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101698 fd_install(newfd, newfile);
101699 err = newfd;
101700
101701 + gr_attach_curr_ip(newsock->sk);
101702 +
101703 out_put:
101704 fput_light(sock->file, fput_needed);
101705 out:
101706 @@ -1668,6 +1720,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101707 int, addrlen)
101708 {
101709 struct socket *sock;
101710 + struct sockaddr *sck;
101711 struct sockaddr_storage address;
101712 int err, fput_needed;
101713
101714 @@ -1678,6 +1731,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101715 if (err < 0)
101716 goto out_put;
101717
101718 + sck = (struct sockaddr *)&address;
101719 +
101720 + if (gr_handle_sock_client(sck)) {
101721 + err = -EACCES;
101722 + goto out_put;
101723 + }
101724 +
101725 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
101726 + if (err)
101727 + goto out_put;
101728 +
101729 err =
101730 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
101731 if (err)
101732 @@ -1759,6 +1823,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
101733 * the protocol.
101734 */
101735
101736 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
101737 +
101738 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
101739 unsigned int, flags, struct sockaddr __user *, addr,
101740 int, addr_len)
101741 @@ -1825,7 +1891,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
101742 struct socket *sock;
101743 struct iovec iov;
101744 struct msghdr msg;
101745 - struct sockaddr_storage address;
101746 + struct sockaddr_storage address = { };
101747 int err, err2;
101748 int fput_needed;
101749
101750 @@ -1972,6 +2038,10 @@ static int copy_msghdr_from_user(struct msghdr *kmsg,
101751 {
101752 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
101753 return -EFAULT;
101754 +
101755 + if (kmsg->msg_namelen < 0)
101756 + return -EINVAL;
101757 +
101758 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101759 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101760 return 0;
101761 @@ -2047,7 +2117,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
101762 * checking falls down on this.
101763 */
101764 if (copy_from_user(ctl_buf,
101765 - (void __user __force *)msg_sys->msg_control,
101766 + (void __force_user *)msg_sys->msg_control,
101767 ctl_len))
101768 goto out_freectl;
101769 msg_sys->msg_control = ctl_buf;
101770 @@ -2198,7 +2268,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101771 int err, total_len, len;
101772
101773 /* kernel mode address */
101774 - struct sockaddr_storage addr;
101775 + struct sockaddr_storage addr = { };
101776
101777 /* user mode address pointers */
101778 struct sockaddr __user *uaddr;
101779 @@ -2227,7 +2297,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101780 /* Save the user-mode address (verify_iovec will change the
101781 * kernel msghdr to use the kernel address space)
101782 */
101783 - uaddr = (__force void __user *)msg_sys->msg_name;
101784 + uaddr = (void __force_user *)msg_sys->msg_name;
101785 uaddr_len = COMPAT_NAMELEN(msg);
101786 if (MSG_CMSG_COMPAT & flags)
101787 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
101788 @@ -2871,7 +2941,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
101789 ifr = compat_alloc_user_space(buf_size);
101790 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
101791
101792 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
101793 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
101794 return -EFAULT;
101795
101796 if (put_user(convert_in ? rxnfc : compat_ptr(data),
101797 @@ -2985,14 +3055,14 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
101798 old_fs = get_fs();
101799 set_fs(KERNEL_DS);
101800 err = dev_ioctl(net, cmd,
101801 - (struct ifreq __user __force *) &kifr);
101802 + (struct ifreq __force_user *) &kifr);
101803 set_fs(old_fs);
101804
101805 return err;
101806 case SIOCBONDSLAVEINFOQUERY:
101807 case SIOCBONDINFOQUERY:
101808 uifr = compat_alloc_user_space(sizeof(*uifr));
101809 - if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
101810 + if (copy_in_user(uifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
101811 return -EFAULT;
101812
101813 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
101814 @@ -3094,7 +3164,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
101815
101816 old_fs = get_fs();
101817 set_fs(KERNEL_DS);
101818 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
101819 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
101820 set_fs(old_fs);
101821
101822 if (cmd == SIOCGIFMAP && !err) {
101823 @@ -3199,7 +3269,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
101824 ret |= get_user(rtdev, &(ur4->rt_dev));
101825 if (rtdev) {
101826 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
101827 - r4.rt_dev = (char __user __force *)devname;
101828 + r4.rt_dev = (char __force_user *)devname;
101829 devname[15] = 0;
101830 } else
101831 r4.rt_dev = NULL;
101832 @@ -3425,8 +3495,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
101833 int __user *uoptlen;
101834 int err;
101835
101836 - uoptval = (char __user __force *) optval;
101837 - uoptlen = (int __user __force *) optlen;
101838 + uoptval = (char __force_user *) optval;
101839 + uoptlen = (int __force_user *) optlen;
101840
101841 set_fs(KERNEL_DS);
101842 if (level == SOL_SOCKET)
101843 @@ -3446,7 +3516,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
101844 char __user *uoptval;
101845 int err;
101846
101847 - uoptval = (char __user __force *) optval;
101848 + uoptval = (char __force_user *) optval;
101849
101850 set_fs(KERNEL_DS);
101851 if (level == SOL_SOCKET)
101852 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
101853 index 1b94a9c..496f7f5 100644
101854 --- a/net/sunrpc/auth_gss/svcauth_gss.c
101855 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
101856 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101857 uint64_t *handle)
101858 {
101859 struct rsc rsci, *rscp = NULL;
101860 - static atomic64_t ctxhctr;
101861 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
101862 long long ctxh;
101863 struct gss_api_mech *gm = NULL;
101864 time_t expiry;
101865 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101866 status = -ENOMEM;
101867 /* the handle needs to be just a unique id,
101868 * use a static counter */
101869 - ctxh = atomic64_inc_return(&ctxhctr);
101870 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
101871
101872 /* make a copy for the caller */
101873 *handle = ctxh;
101874 diff --git a/net/sunrpc/backchannel_rqst.c b/net/sunrpc/backchannel_rqst.c
101875 index 890a299..e860d4f 100644
101876 --- a/net/sunrpc/backchannel_rqst.c
101877 +++ b/net/sunrpc/backchannel_rqst.c
101878 @@ -64,7 +64,6 @@ static void xprt_free_allocation(struct rpc_rqst *req)
101879 free_page((unsigned long)xbufp->head[0].iov_base);
101880 xbufp = &req->rq_snd_buf;
101881 free_page((unsigned long)xbufp->head[0].iov_base);
101882 - list_del(&req->rq_bc_pa_list);
101883 kfree(req);
101884 }
101885
101886 @@ -168,8 +167,10 @@ out_free:
101887 /*
101888 * Memory allocation failed, free the temporary list
101889 */
101890 - list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list)
101891 + list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list) {
101892 + list_del(&req->rq_bc_pa_list);
101893 xprt_free_allocation(req);
101894 + }
101895
101896 dprintk("RPC: setup backchannel transport failed\n");
101897 return -ENOMEM;
101898 @@ -198,6 +199,7 @@ void xprt_destroy_backchannel(struct rpc_xprt *xprt, unsigned int max_reqs)
101899 xprt_dec_alloc_count(xprt, max_reqs);
101900 list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) {
101901 dprintk("RPC: req=%p\n", req);
101902 + list_del(&req->rq_bc_pa_list);
101903 xprt_free_allocation(req);
101904 if (--max_reqs == 0)
101905 break;
101906 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
101907 index e726e16..393c39e 100644
101908 --- a/net/sunrpc/clnt.c
101909 +++ b/net/sunrpc/clnt.c
101910 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
101911 (RPC_IS_ASYNC(task) ? "async" : "sync"));
101912
101913 /* Increment call count */
101914 - task->tk_msg.rpc_proc->p_count++;
101915 + pax_open_kernel();
101916 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
101917 + pax_close_kernel();
101918 clnt->cl_stats->rpccnt++;
101919 task->tk_action = call_reserve;
101920 }
101921 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
101922 index ff3cc4b..7612a9e 100644
101923 --- a/net/sunrpc/sched.c
101924 +++ b/net/sunrpc/sched.c
101925 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
101926 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
101927 static void rpc_task_set_debuginfo(struct rpc_task *task)
101928 {
101929 - static atomic_t rpc_pid;
101930 + static atomic_unchecked_t rpc_pid;
101931
101932 - task->tk_pid = atomic_inc_return(&rpc_pid);
101933 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
101934 }
101935 #else
101936 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
101937 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
101938 index e7fbe36..8052603 100644
101939 --- a/net/sunrpc/svc.c
101940 +++ b/net/sunrpc/svc.c
101941 @@ -1158,7 +1158,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
101942 svc_putnl(resv, RPC_SUCCESS);
101943
101944 /* Bump per-procedure stats counter */
101945 - procp->pc_count++;
101946 + pax_open_kernel();
101947 + (*(unsigned int *)&procp->pc_count)++;
101948 + pax_close_kernel();
101949
101950 /* Initialize storage for argp and resp */
101951 memset(rqstp->rq_argp, 0, procp->pc_argsize);
101952 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
101953 index 621ca7b..59421dd 100644
101954 --- a/net/sunrpc/svcauth_unix.c
101955 +++ b/net/sunrpc/svcauth_unix.c
101956 @@ -414,7 +414,7 @@ struct unix_gid {
101957 struct group_info *gi;
101958 };
101959
101960 -static int unix_gid_hash(kuid_t uid)
101961 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
101962 {
101963 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
101964 }
101965 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
101966 (*bpp)[-1] = '\n';
101967 }
101968
101969 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101970 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101971
101972 static int unix_gid_parse(struct cache_detail *cd,
101973 char *mesg, int mlen)
101974 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
101975 index c1b6270..05089c1 100644
101976 --- a/net/sunrpc/xprtrdma/svc_rdma.c
101977 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
101978 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
101979 static unsigned int min_max_inline = 4096;
101980 static unsigned int max_max_inline = 65536;
101981
101982 -atomic_t rdma_stat_recv;
101983 -atomic_t rdma_stat_read;
101984 -atomic_t rdma_stat_write;
101985 -atomic_t rdma_stat_sq_starve;
101986 -atomic_t rdma_stat_rq_starve;
101987 -atomic_t rdma_stat_rq_poll;
101988 -atomic_t rdma_stat_rq_prod;
101989 -atomic_t rdma_stat_sq_poll;
101990 -atomic_t rdma_stat_sq_prod;
101991 +atomic_unchecked_t rdma_stat_recv;
101992 +atomic_unchecked_t rdma_stat_read;
101993 +atomic_unchecked_t rdma_stat_write;
101994 +atomic_unchecked_t rdma_stat_sq_starve;
101995 +atomic_unchecked_t rdma_stat_rq_starve;
101996 +atomic_unchecked_t rdma_stat_rq_poll;
101997 +atomic_unchecked_t rdma_stat_rq_prod;
101998 +atomic_unchecked_t rdma_stat_sq_poll;
101999 +atomic_unchecked_t rdma_stat_sq_prod;
102000
102001 /* Temporary NFS request map and context caches */
102002 struct kmem_cache *svc_rdma_map_cachep;
102003 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
102004 len -= *ppos;
102005 if (len > *lenp)
102006 len = *lenp;
102007 - if (len && copy_to_user(buffer, str_buf, len))
102008 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
102009 return -EFAULT;
102010 *lenp = len;
102011 *ppos += len;
102012 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
102013 {
102014 .procname = "rdma_stat_read",
102015 .data = &rdma_stat_read,
102016 - .maxlen = sizeof(atomic_t),
102017 + .maxlen = sizeof(atomic_unchecked_t),
102018 .mode = 0644,
102019 .proc_handler = read_reset_stat,
102020 },
102021 {
102022 .procname = "rdma_stat_recv",
102023 .data = &rdma_stat_recv,
102024 - .maxlen = sizeof(atomic_t),
102025 + .maxlen = sizeof(atomic_unchecked_t),
102026 .mode = 0644,
102027 .proc_handler = read_reset_stat,
102028 },
102029 {
102030 .procname = "rdma_stat_write",
102031 .data = &rdma_stat_write,
102032 - .maxlen = sizeof(atomic_t),
102033 + .maxlen = sizeof(atomic_unchecked_t),
102034 .mode = 0644,
102035 .proc_handler = read_reset_stat,
102036 },
102037 {
102038 .procname = "rdma_stat_sq_starve",
102039 .data = &rdma_stat_sq_starve,
102040 - .maxlen = sizeof(atomic_t),
102041 + .maxlen = sizeof(atomic_unchecked_t),
102042 .mode = 0644,
102043 .proc_handler = read_reset_stat,
102044 },
102045 {
102046 .procname = "rdma_stat_rq_starve",
102047 .data = &rdma_stat_rq_starve,
102048 - .maxlen = sizeof(atomic_t),
102049 + .maxlen = sizeof(atomic_unchecked_t),
102050 .mode = 0644,
102051 .proc_handler = read_reset_stat,
102052 },
102053 {
102054 .procname = "rdma_stat_rq_poll",
102055 .data = &rdma_stat_rq_poll,
102056 - .maxlen = sizeof(atomic_t),
102057 + .maxlen = sizeof(atomic_unchecked_t),
102058 .mode = 0644,
102059 .proc_handler = read_reset_stat,
102060 },
102061 {
102062 .procname = "rdma_stat_rq_prod",
102063 .data = &rdma_stat_rq_prod,
102064 - .maxlen = sizeof(atomic_t),
102065 + .maxlen = sizeof(atomic_unchecked_t),
102066 .mode = 0644,
102067 .proc_handler = read_reset_stat,
102068 },
102069 {
102070 .procname = "rdma_stat_sq_poll",
102071 .data = &rdma_stat_sq_poll,
102072 - .maxlen = sizeof(atomic_t),
102073 + .maxlen = sizeof(atomic_unchecked_t),
102074 .mode = 0644,
102075 .proc_handler = read_reset_stat,
102076 },
102077 {
102078 .procname = "rdma_stat_sq_prod",
102079 .data = &rdma_stat_sq_prod,
102080 - .maxlen = sizeof(atomic_t),
102081 + .maxlen = sizeof(atomic_unchecked_t),
102082 .mode = 0644,
102083 .proc_handler = read_reset_stat,
102084 },
102085 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
102086 index 0ce7552..d074459 100644
102087 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
102088 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
102089 @@ -501,7 +501,7 @@ next_sge:
102090 svc_rdma_put_context(ctxt, 0);
102091 goto out;
102092 }
102093 - atomic_inc(&rdma_stat_read);
102094 + atomic_inc_unchecked(&rdma_stat_read);
102095
102096 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
102097 chl_map->ch[ch_no].count -= read_wr.num_sge;
102098 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
102099 dto_q);
102100 list_del_init(&ctxt->dto_q);
102101 } else {
102102 - atomic_inc(&rdma_stat_rq_starve);
102103 + atomic_inc_unchecked(&rdma_stat_rq_starve);
102104 clear_bit(XPT_DATA, &xprt->xpt_flags);
102105 ctxt = NULL;
102106 }
102107 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
102108 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
102109 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
102110 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
102111 - atomic_inc(&rdma_stat_recv);
102112 + atomic_inc_unchecked(&rdma_stat_recv);
102113
102114 /* Build up the XDR from the receive buffers. */
102115 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
102116 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
102117 index c1d124d..acfc59e 100644
102118 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
102119 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
102120 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
102121 write_wr.wr.rdma.remote_addr = to;
102122
102123 /* Post It */
102124 - atomic_inc(&rdma_stat_write);
102125 + atomic_inc_unchecked(&rdma_stat_write);
102126 if (svc_rdma_send(xprt, &write_wr))
102127 goto err;
102128 return 0;
102129 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
102130 index 62e4f9b..dd3f2d7 100644
102131 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
102132 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
102133 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
102134 return;
102135
102136 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
102137 - atomic_inc(&rdma_stat_rq_poll);
102138 + atomic_inc_unchecked(&rdma_stat_rq_poll);
102139
102140 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
102141 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
102142 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
102143 }
102144
102145 if (ctxt)
102146 - atomic_inc(&rdma_stat_rq_prod);
102147 + atomic_inc_unchecked(&rdma_stat_rq_prod);
102148
102149 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
102150 /*
102151 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
102152 return;
102153
102154 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
102155 - atomic_inc(&rdma_stat_sq_poll);
102156 + atomic_inc_unchecked(&rdma_stat_sq_poll);
102157 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
102158 if (wc.status != IB_WC_SUCCESS)
102159 /* Close the transport */
102160 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
102161 }
102162
102163 if (ctxt)
102164 - atomic_inc(&rdma_stat_sq_prod);
102165 + atomic_inc_unchecked(&rdma_stat_sq_prod);
102166 }
102167
102168 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
102169 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
102170 spin_lock_bh(&xprt->sc_lock);
102171 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
102172 spin_unlock_bh(&xprt->sc_lock);
102173 - atomic_inc(&rdma_stat_sq_starve);
102174 + atomic_inc_unchecked(&rdma_stat_sq_starve);
102175
102176 /* See if we can opportunistically reap SQ WR to make room */
102177 sq_cq_reap(xprt);
102178 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
102179 index e7000be..e3b0ba7 100644
102180 --- a/net/sysctl_net.c
102181 +++ b/net/sysctl_net.c
102182 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
102183 kgid_t root_gid = make_kgid(net->user_ns, 0);
102184
102185 /* Allow network administrator to have same access as root. */
102186 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
102187 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
102188 uid_eq(root_uid, current_euid())) {
102189 int mode = (table->mode >> 6) & 7;
102190 return (mode << 6) | (mode << 3) | mode;
102191 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
102192 index d38bb45..38d5df5 100644
102193 --- a/net/tipc/subscr.c
102194 +++ b/net/tipc/subscr.c
102195 @@ -98,7 +98,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
102196 struct kvec msg_sect;
102197 int ret;
102198
102199 - msg_sect.iov_base = (void *)&sub->evt;
102200 + msg_sect.iov_base = &sub->evt;
102201 msg_sect.iov_len = sizeof(struct tipc_event);
102202
102203 sub->evt.event = htohl(event, sub->swap);
102204 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
102205 index d7c1ac6..b0fc322 100644
102206 --- a/net/unix/af_unix.c
102207 +++ b/net/unix/af_unix.c
102208 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
102209 err = -ECONNREFUSED;
102210 if (!S_ISSOCK(inode->i_mode))
102211 goto put_fail;
102212 +
102213 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
102214 + err = -EACCES;
102215 + goto put_fail;
102216 + }
102217 +
102218 u = unix_find_socket_byinode(inode);
102219 if (!u)
102220 goto put_fail;
102221 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
102222 if (u) {
102223 struct dentry *dentry;
102224 dentry = unix_sk(u)->path.dentry;
102225 +
102226 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
102227 + err = -EPERM;
102228 + sock_put(u);
102229 + goto fail;
102230 + }
102231 +
102232 if (dentry)
102233 touch_atime(&unix_sk(u)->path);
102234 } else
102235 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
102236 */
102237 err = security_path_mknod(&path, dentry, mode, 0);
102238 if (!err) {
102239 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
102240 + err = -EACCES;
102241 + goto out;
102242 + }
102243 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
102244 if (!err) {
102245 res->mnt = mntget(path.mnt);
102246 res->dentry = dget(dentry);
102247 + gr_handle_create(dentry, path.mnt);
102248 }
102249 }
102250 +out:
102251 done_path_create(&path, dentry);
102252 return err;
102253 }
102254 @@ -1785,8 +1804,11 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
102255 goto out;
102256
102257 err = mutex_lock_interruptible(&u->readlock);
102258 - if (err) {
102259 - err = sock_intr_errno(sock_rcvtimeo(sk, noblock));
102260 + if (unlikely(err)) {
102261 + /* recvmsg() in non blocking mode is supposed to return -EAGAIN
102262 + * sk_rcvtimeo is not honored by mutex_lock_interruptible()
102263 + */
102264 + err = noblock ? -EAGAIN : -ERESTARTSYS;
102265 goto out;
102266 }
102267
102268 @@ -1911,6 +1933,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
102269 struct unix_sock *u = unix_sk(sk);
102270 struct sockaddr_un *sunaddr = msg->msg_name;
102271 int copied = 0;
102272 + int noblock = flags & MSG_DONTWAIT;
102273 int check_creds = 0;
102274 int target;
102275 int err = 0;
102276 @@ -1926,7 +1949,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
102277 goto out;
102278
102279 target = sock_rcvlowat(sk, flags&MSG_WAITALL, size);
102280 - timeo = sock_rcvtimeo(sk, flags&MSG_DONTWAIT);
102281 + timeo = sock_rcvtimeo(sk, noblock);
102282
102283 /* Lock the socket to prevent queue disordering
102284 * while sleeps in memcpy_tomsg
102285 @@ -1938,8 +1961,11 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
102286 }
102287
102288 err = mutex_lock_interruptible(&u->readlock);
102289 - if (err) {
102290 - err = sock_intr_errno(timeo);
102291 + if (unlikely(err)) {
102292 + /* recvmsg() in non blocking mode is supposed to return -EAGAIN
102293 + * sk_rcvtimeo is not honored by mutex_lock_interruptible()
102294 + */
102295 + err = noblock ? -EAGAIN : -ERESTARTSYS;
102296 goto out;
102297 }
102298
102299 @@ -2335,9 +2361,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
102300 seq_puts(seq, "Num RefCount Protocol Flags Type St "
102301 "Inode Path\n");
102302 else {
102303 - struct sock *s = v;
102304 + struct sock *s = v, *peer;
102305 struct unix_sock *u = unix_sk(s);
102306 unix_state_lock(s);
102307 + peer = unix_peer(s);
102308 + unix_state_unlock(s);
102309 +
102310 + unix_state_double_lock(s, peer);
102311
102312 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
102313 s,
102314 @@ -2364,8 +2394,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
102315 }
102316 for ( ; i < len; i++)
102317 seq_putc(seq, u->addr->name->sun_path[i]);
102318 - }
102319 - unix_state_unlock(s);
102320 + } else if (peer)
102321 + seq_printf(seq, " P%lu", sock_i_ino(peer));
102322 +
102323 + unix_state_double_unlock(s, peer);
102324 seq_putc(seq, '\n');
102325 }
102326
102327 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
102328 index b3d5150..ff3a837 100644
102329 --- a/net/unix/sysctl_net_unix.c
102330 +++ b/net/unix/sysctl_net_unix.c
102331 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
102332
102333 int __net_init unix_sysctl_register(struct net *net)
102334 {
102335 - struct ctl_table *table;
102336 + ctl_table_no_const *table;
102337
102338 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
102339 if (table == NULL)
102340 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
102341 index 9a73074..aecba9a 100644
102342 --- a/net/vmw_vsock/vmci_transport_notify.c
102343 +++ b/net/vmw_vsock/vmci_transport_notify.c
102344 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
102345
102346 /* Socket control packet based operations. */
102347 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
102348 - vmci_transport_notify_pkt_socket_init,
102349 - vmci_transport_notify_pkt_socket_destruct,
102350 - vmci_transport_notify_pkt_poll_in,
102351 - vmci_transport_notify_pkt_poll_out,
102352 - vmci_transport_notify_pkt_handle_pkt,
102353 - vmci_transport_notify_pkt_recv_init,
102354 - vmci_transport_notify_pkt_recv_pre_block,
102355 - vmci_transport_notify_pkt_recv_pre_dequeue,
102356 - vmci_transport_notify_pkt_recv_post_dequeue,
102357 - vmci_transport_notify_pkt_send_init,
102358 - vmci_transport_notify_pkt_send_pre_block,
102359 - vmci_transport_notify_pkt_send_pre_enqueue,
102360 - vmci_transport_notify_pkt_send_post_enqueue,
102361 - vmci_transport_notify_pkt_process_request,
102362 - vmci_transport_notify_pkt_process_negotiate,
102363 + .socket_init = vmci_transport_notify_pkt_socket_init,
102364 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
102365 + .poll_in = vmci_transport_notify_pkt_poll_in,
102366 + .poll_out = vmci_transport_notify_pkt_poll_out,
102367 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
102368 + .recv_init = vmci_transport_notify_pkt_recv_init,
102369 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
102370 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
102371 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
102372 + .send_init = vmci_transport_notify_pkt_send_init,
102373 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
102374 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
102375 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
102376 + .process_request = vmci_transport_notify_pkt_process_request,
102377 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
102378 };
102379 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
102380 index 622bd7a..b92086c 100644
102381 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
102382 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
102383 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
102384
102385 /* Socket always on control packet based operations. */
102386 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
102387 - vmci_transport_notify_pkt_socket_init,
102388 - vmci_transport_notify_pkt_socket_destruct,
102389 - vmci_transport_notify_pkt_poll_in,
102390 - vmci_transport_notify_pkt_poll_out,
102391 - vmci_transport_notify_pkt_handle_pkt,
102392 - vmci_transport_notify_pkt_recv_init,
102393 - vmci_transport_notify_pkt_recv_pre_block,
102394 - vmci_transport_notify_pkt_recv_pre_dequeue,
102395 - vmci_transport_notify_pkt_recv_post_dequeue,
102396 - vmci_transport_notify_pkt_send_init,
102397 - vmci_transport_notify_pkt_send_pre_block,
102398 - vmci_transport_notify_pkt_send_pre_enqueue,
102399 - vmci_transport_notify_pkt_send_post_enqueue,
102400 - vmci_transport_notify_pkt_process_request,
102401 - vmci_transport_notify_pkt_process_negotiate,
102402 + .socket_init = vmci_transport_notify_pkt_socket_init,
102403 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
102404 + .poll_in = vmci_transport_notify_pkt_poll_in,
102405 + .poll_out = vmci_transport_notify_pkt_poll_out,
102406 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
102407 + .recv_init = vmci_transport_notify_pkt_recv_init,
102408 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
102409 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
102410 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
102411 + .send_init = vmci_transport_notify_pkt_send_init,
102412 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
102413 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
102414 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
102415 + .process_request = vmci_transport_notify_pkt_process_request,
102416 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
102417 };
102418 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
102419 index c8717c1..08539f5 100644
102420 --- a/net/wireless/wext-core.c
102421 +++ b/net/wireless/wext-core.c
102422 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
102423 */
102424
102425 /* Support for very large requests */
102426 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
102427 - (user_length > descr->max_tokens)) {
102428 + if (user_length > descr->max_tokens) {
102429 /* Allow userspace to GET more than max so
102430 * we can support any size GET requests.
102431 * There is still a limit : -ENOMEM.
102432 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
102433 }
102434 }
102435
102436 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
102437 - /*
102438 - * If this is a GET, but not NOMAX, it means that the extra
102439 - * data is not bounded by userspace, but by max_tokens. Thus
102440 - * set the length to max_tokens. This matches the extra data
102441 - * allocation.
102442 - * The driver should fill it with the number of tokens it
102443 - * provided, and it may check iwp->length rather than having
102444 - * knowledge of max_tokens. If the driver doesn't change the
102445 - * iwp->length, this ioctl just copies back max_token tokens
102446 - * filled with zeroes. Hopefully the driver isn't claiming
102447 - * them to be valid data.
102448 - */
102449 - iwp->length = descr->max_tokens;
102450 - }
102451 -
102452 err = handler(dev, info, (union iwreq_data *) iwp, extra);
102453
102454 iwp->length += essid_compat;
102455 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
102456 index 4323952..a06dfe1 100644
102457 --- a/net/x25/sysctl_net_x25.c
102458 +++ b/net/x25/sysctl_net_x25.c
102459 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
102460 .mode = 0644,
102461 .proc_handler = proc_dointvec,
102462 },
102463 - { 0, },
102464 + { },
102465 };
102466
102467 void __init x25_register_sysctl(void)
102468 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
102469 index 9a91f74..502f6605 100644
102470 --- a/net/xfrm/xfrm_policy.c
102471 +++ b/net/xfrm/xfrm_policy.c
102472 @@ -332,7 +332,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
102473 {
102474 policy->walk.dead = 1;
102475
102476 - atomic_inc(&policy->genid);
102477 + atomic_inc_unchecked(&policy->genid);
102478
102479 if (del_timer(&policy->polq.hold_timer))
102480 xfrm_pol_put(policy);
102481 @@ -660,7 +660,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
102482 hlist_add_head(&policy->bydst, chain);
102483 xfrm_pol_hold(policy);
102484 net->xfrm.policy_count[dir]++;
102485 - atomic_inc(&flow_cache_genid);
102486 + atomic_inc_unchecked(&flow_cache_genid);
102487
102488 /* After previous checking, family can either be AF_INET or AF_INET6 */
102489 if (policy->family == AF_INET)
102490 @@ -1636,7 +1636,7 @@ free_dst:
102491 goto out;
102492 }
102493
102494 -static int inline
102495 +static inline int
102496 xfrm_dst_alloc_copy(void **target, const void *src, int size)
102497 {
102498 if (!*target) {
102499 @@ -1648,7 +1648,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
102500 return 0;
102501 }
102502
102503 -static int inline
102504 +static inline int
102505 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
102506 {
102507 #ifdef CONFIG_XFRM_SUB_POLICY
102508 @@ -1660,7 +1660,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
102509 #endif
102510 }
102511
102512 -static int inline
102513 +static inline int
102514 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
102515 {
102516 #ifdef CONFIG_XFRM_SUB_POLICY
102517 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
102518
102519 xdst->num_pols = num_pols;
102520 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
102521 - xdst->policy_genid = atomic_read(&pols[0]->genid);
102522 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
102523
102524 return xdst;
102525 }
102526 @@ -2582,11 +2582,12 @@ void xfrm_garbage_collect(struct net *net)
102527 }
102528 EXPORT_SYMBOL(xfrm_garbage_collect);
102529
102530 -static void xfrm_garbage_collect_deferred(struct net *net)
102531 +void xfrm_garbage_collect_deferred(struct net *net)
102532 {
102533 flow_cache_flush_deferred();
102534 __xfrm_garbage_collect(net);
102535 }
102536 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
102537
102538 static void xfrm_init_pmtu(struct dst_entry *dst)
102539 {
102540 @@ -2636,7 +2637,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
102541 if (xdst->xfrm_genid != dst->xfrm->genid)
102542 return 0;
102543 if (xdst->num_pols > 0 &&
102544 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
102545 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
102546 return 0;
102547
102548 mtu = dst_mtu(dst->child);
102549 @@ -2724,8 +2725,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
102550 dst_ops->link_failure = xfrm_link_failure;
102551 if (likely(dst_ops->neigh_lookup == NULL))
102552 dst_ops->neigh_lookup = xfrm_neigh_lookup;
102553 - if (likely(afinfo->garbage_collect == NULL))
102554 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
102555 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
102556 }
102557 spin_unlock(&xfrm_policy_afinfo_lock);
102558 @@ -2779,7 +2778,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
102559 dst_ops->check = NULL;
102560 dst_ops->negative_advice = NULL;
102561 dst_ops->link_failure = NULL;
102562 - afinfo->garbage_collect = NULL;
102563 }
102564 return err;
102565 }
102566 @@ -3162,7 +3160,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
102567 sizeof(pol->xfrm_vec[i].saddr));
102568 pol->xfrm_vec[i].encap_family = mp->new_family;
102569 /* flush bundles */
102570 - atomic_inc(&pol->genid);
102571 + atomic_inc_unchecked(&pol->genid);
102572 }
102573 }
102574
102575 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
102576 index 68c2f35..9eb05ca 100644
102577 --- a/net/xfrm/xfrm_state.c
102578 +++ b/net/xfrm/xfrm_state.c
102579 @@ -174,12 +174,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
102580
102581 if (unlikely(afinfo == NULL))
102582 return -EAFNOSUPPORT;
102583 - typemap = afinfo->type_map;
102584 + typemap = (const struct xfrm_type **)afinfo->type_map;
102585 spin_lock_bh(&xfrm_type_lock);
102586
102587 - if (likely(typemap[type->proto] == NULL))
102588 + if (likely(typemap[type->proto] == NULL)) {
102589 + pax_open_kernel();
102590 typemap[type->proto] = type;
102591 - else
102592 + pax_close_kernel();
102593 + } else
102594 err = -EEXIST;
102595 spin_unlock_bh(&xfrm_type_lock);
102596 xfrm_state_put_afinfo(afinfo);
102597 @@ -195,13 +197,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
102598
102599 if (unlikely(afinfo == NULL))
102600 return -EAFNOSUPPORT;
102601 - typemap = afinfo->type_map;
102602 + typemap = (const struct xfrm_type **)afinfo->type_map;
102603 spin_lock_bh(&xfrm_type_lock);
102604
102605 if (unlikely(typemap[type->proto] != type))
102606 err = -ENOENT;
102607 - else
102608 + else {
102609 + pax_open_kernel();
102610 typemap[type->proto] = NULL;
102611 + pax_close_kernel();
102612 + }
102613 spin_unlock_bh(&xfrm_type_lock);
102614 xfrm_state_put_afinfo(afinfo);
102615 return err;
102616 @@ -211,7 +216,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
102617 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
102618 {
102619 struct xfrm_state_afinfo *afinfo;
102620 - const struct xfrm_type **typemap;
102621 const struct xfrm_type *type;
102622 int modload_attempted = 0;
102623
102624 @@ -219,9 +223,8 @@ retry:
102625 afinfo = xfrm_state_get_afinfo(family);
102626 if (unlikely(afinfo == NULL))
102627 return NULL;
102628 - typemap = afinfo->type_map;
102629
102630 - type = typemap[proto];
102631 + type = afinfo->type_map[proto];
102632 if (unlikely(type && !try_module_get(type->owner)))
102633 type = NULL;
102634 if (!type && !modload_attempted) {
102635 @@ -255,7 +258,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102636 return -EAFNOSUPPORT;
102637
102638 err = -EEXIST;
102639 - modemap = afinfo->mode_map;
102640 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102641 spin_lock_bh(&xfrm_mode_lock);
102642 if (modemap[mode->encap])
102643 goto out;
102644 @@ -264,8 +267,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102645 if (!try_module_get(afinfo->owner))
102646 goto out;
102647
102648 - mode->afinfo = afinfo;
102649 + pax_open_kernel();
102650 + *(const void **)&mode->afinfo = afinfo;
102651 modemap[mode->encap] = mode;
102652 + pax_close_kernel();
102653 err = 0;
102654
102655 out:
102656 @@ -289,10 +294,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
102657 return -EAFNOSUPPORT;
102658
102659 err = -ENOENT;
102660 - modemap = afinfo->mode_map;
102661 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102662 spin_lock_bh(&xfrm_mode_lock);
102663 if (likely(modemap[mode->encap] == mode)) {
102664 + pax_open_kernel();
102665 modemap[mode->encap] = NULL;
102666 + pax_close_kernel();
102667 module_put(mode->afinfo->owner);
102668 err = 0;
102669 }
102670 @@ -1486,10 +1493,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
102671 u32 xfrm_get_acqseq(void)
102672 {
102673 u32 res;
102674 - static atomic_t acqseq;
102675 + static atomic_unchecked_t acqseq;
102676
102677 do {
102678 - res = atomic_inc_return(&acqseq);
102679 + res = atomic_inc_return_unchecked(&acqseq);
102680 } while (!res);
102681
102682 return res;
102683 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
102684 index 05a6e3d..6716ec9 100644
102685 --- a/net/xfrm/xfrm_sysctl.c
102686 +++ b/net/xfrm/xfrm_sysctl.c
102687 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
102688
102689 int __net_init xfrm_sysctl_init(struct net *net)
102690 {
102691 - struct ctl_table *table;
102692 + ctl_table_no_const *table;
102693
102694 __xfrm_sysctl_init(net);
102695
102696 diff --git a/scripts/Makefile b/scripts/Makefile
102697 index 01e7adb..6176d5d 100644
102698 --- a/scripts/Makefile
102699 +++ b/scripts/Makefile
102700 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
102701
102702 # Let clean descend into subdirs
102703 subdir- += basic kconfig package selinux
102704 +
102705 +clean-files := randstruct.seed
102706 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
102707 index d5d859c..781cbcb 100644
102708 --- a/scripts/Makefile.build
102709 +++ b/scripts/Makefile.build
102710 @@ -111,7 +111,7 @@ endif
102711 endif
102712
102713 # Do not include host rules unless needed
102714 -ifneq ($(hostprogs-y)$(hostprogs-m),)
102715 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
102716 include scripts/Makefile.host
102717 endif
102718
102719 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
102720 index 686cb0d..9d653bf 100644
102721 --- a/scripts/Makefile.clean
102722 +++ b/scripts/Makefile.clean
102723 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
102724 __clean-files := $(extra-y) $(always) \
102725 $(targets) $(clean-files) \
102726 $(host-progs) \
102727 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
102728 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
102729 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
102730
102731 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
102732
102733 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
102734 index 1ac414f..38575f7 100644
102735 --- a/scripts/Makefile.host
102736 +++ b/scripts/Makefile.host
102737 @@ -31,6 +31,8 @@
102738 # Note: Shared libraries consisting of C++ files are not supported
102739
102740 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
102741 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
102742 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
102743
102744 # C code
102745 # Executables compiled from a single .c file
102746 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
102747 # Shared libaries (only .c supported)
102748 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
102749 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
102750 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
102751 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
102752 # Remove .so files from "xxx-objs"
102753 host-cobjs := $(filter-out %.so,$(host-cobjs))
102754 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
102755
102756 -#Object (.o) files used by the shared libaries
102757 +# Object (.o) files used by the shared libaries
102758 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
102759 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
102760
102761 # output directory for programs/.o files
102762 # hostprogs-y := tools/build may have been specified. Retrieve directory
102763 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
102764 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
102765 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
102766 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
102767 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
102768 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
102769 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
102770 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
102771
102772 obj-dirs += $(host-objdirs)
102773 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
102774 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
102775 $(call if_changed_dep,host-cshobjs)
102776
102777 +# Compile .c file, create position independent .o file
102778 +# host-cxxshobjs -> .o
102779 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
102780 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
102781 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
102782 + $(call if_changed_dep,host-cxxshobjs)
102783 +
102784 # Link a shared library, based on position independent .o files
102785 # *.o -> .so shared library (host-cshlib)
102786 quiet_cmd_host-cshlib = HOSTLLD -shared $@
102787 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
102788 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
102789 $(call if_changed,host-cshlib)
102790
102791 +# Link a shared library, based on position independent .o files
102792 +# *.o -> .so shared library (host-cxxshlib)
102793 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
102794 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
102795 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
102796 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
102797 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
102798 + $(call if_changed,host-cxxshlib)
102799 +
102800 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
102801 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
102802 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
102803
102804 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
102805 index 078fe1d..fbdb363 100644
102806 --- a/scripts/basic/fixdep.c
102807 +++ b/scripts/basic/fixdep.c
102808 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
102809 /*
102810 * Lookup a value in the configuration string.
102811 */
102812 -static int is_defined_config(const char *name, int len, unsigned int hash)
102813 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
102814 {
102815 struct item *aux;
102816
102817 @@ -211,10 +211,10 @@ static void clear_config(void)
102818 /*
102819 * Record the use of a CONFIG_* word.
102820 */
102821 -static void use_config(const char *m, int slen)
102822 +static void use_config(const char *m, unsigned int slen)
102823 {
102824 unsigned int hash = strhash(m, slen);
102825 - int c, i;
102826 + unsigned int c, i;
102827
102828 if (is_defined_config(m, slen, hash))
102829 return;
102830 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
102831
102832 static void parse_config_file(const char *map, size_t len)
102833 {
102834 - const int *end = (const int *) (map + len);
102835 + const unsigned int *end = (const unsigned int *) (map + len);
102836 /* start at +1, so that p can never be < map */
102837 - const int *m = (const int *) map + 1;
102838 + const unsigned int *m = (const unsigned int *) map + 1;
102839 const char *p, *q;
102840
102841 for (; m < end; m++) {
102842 @@ -435,7 +435,7 @@ static void print_deps(void)
102843 static void traps(void)
102844 {
102845 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
102846 - int *p = (int *)test;
102847 + unsigned int *p = (unsigned int *)test;
102848
102849 if (*p != INT_CONF) {
102850 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
102851 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
102852 new file mode 100644
102853 index 0000000..edcbc3a
102854 --- /dev/null
102855 +++ b/scripts/gcc-plugin.sh
102856 @@ -0,0 +1,16 @@
102857 +#!/bin/bash
102858 +srctree=$(dirname "$0")
102859 +gccplugins_dir=$($3 -print-file-name=plugin)
102860 +plugincc=$($1 -E -shared - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
102861 +#include "gcc-common.h"
102862 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
102863 +#warning $2
102864 +#else
102865 +#warning $1
102866 +#endif
102867 +EOF
102868 +)
102869 +if [ $? -eq 0 ]
102870 +then
102871 + ( [[ "$plugincc" =~ "$1" ]] && echo "$1" ) || ( [[ "$plugincc" =~ "$2" ]] && echo "$2" )
102872 +fi
102873 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
102874 index 5de5660..d3deb89 100644
102875 --- a/scripts/headers_install.sh
102876 +++ b/scripts/headers_install.sh
102877 @@ -32,6 +32,7 @@ do
102878 FILE="$(basename "$i")"
102879 sed -r \
102880 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
102881 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
102882 -e 's/__attribute_const__([ \t]|$)/\1/g' \
102883 -e 's@^#include <linux/compiler.h>@@' \
102884 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
102885 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
102886 index 2dcb377..a82c500 100644
102887 --- a/scripts/link-vmlinux.sh
102888 +++ b/scripts/link-vmlinux.sh
102889 @@ -162,7 +162,7 @@ else
102890 fi;
102891
102892 # final build of init/
102893 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
102894 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
102895
102896 kallsymso=""
102897 kallsyms_vmlinux=""
102898 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
102899 index 25e5cb0..6e85821 100644
102900 --- a/scripts/mod/file2alias.c
102901 +++ b/scripts/mod/file2alias.c
102902 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
102903 unsigned long size, unsigned long id_size,
102904 void *symval)
102905 {
102906 - int i;
102907 + unsigned int i;
102908
102909 if (size % id_size || size < id_size) {
102910 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
102911 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
102912 /* USB is special because the bcdDevice can be matched against a numeric range */
102913 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
102914 static void do_usb_entry(void *symval,
102915 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
102916 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
102917 unsigned char range_lo, unsigned char range_hi,
102918 unsigned char max, struct module *mod)
102919 {
102920 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
102921 {
102922 unsigned int devlo, devhi;
102923 unsigned char chi, clo, max;
102924 - int ndigits;
102925 + unsigned int ndigits;
102926
102927 DEF_FIELD(symval, usb_device_id, match_flags);
102928 DEF_FIELD(symval, usb_device_id, idVendor);
102929 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
102930 for (i = 0; i < count; i++) {
102931 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
102932 char acpi_id[sizeof(*id)];
102933 - int j;
102934 + unsigned int j;
102935
102936 buf_printf(&mod->dev_table_buf,
102937 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
102938 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102939
102940 for (j = 0; j < PNP_MAX_DEVICES; j++) {
102941 const char *id = (char *)(*devs)[j].id;
102942 - int i2, j2;
102943 + unsigned int i2, j2;
102944 int dup = 0;
102945
102946 if (!id[0])
102947 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102948 /* add an individual alias for every device entry */
102949 if (!dup) {
102950 char acpi_id[PNP_ID_LEN];
102951 - int k;
102952 + unsigned int k;
102953
102954 buf_printf(&mod->dev_table_buf,
102955 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
102956 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
102957 static int do_dmi_entry(const char *filename, void *symval,
102958 char *alias)
102959 {
102960 - int i, j;
102961 + unsigned int i, j;
102962 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
102963 sprintf(alias, "dmi*");
102964
102965 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
102966 index 1785576..5e8e06a 100644
102967 --- a/scripts/mod/modpost.c
102968 +++ b/scripts/mod/modpost.c
102969 @@ -941,6 +941,7 @@ enum mismatch {
102970 ANY_INIT_TO_ANY_EXIT,
102971 ANY_EXIT_TO_ANY_INIT,
102972 EXPORT_TO_INIT_EXIT,
102973 + DATA_TO_TEXT
102974 };
102975
102976 struct sectioncheck {
102977 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
102978 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
102979 .mismatch = EXPORT_TO_INIT_EXIT,
102980 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
102981 +},
102982 +/* Do not reference code from writable data */
102983 +{
102984 + .fromsec = { DATA_SECTIONS, NULL },
102985 + .tosec = { TEXT_SECTIONS, NULL },
102986 + .mismatch = DATA_TO_TEXT
102987 }
102988 };
102989
102990 @@ -1147,10 +1154,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
102991 continue;
102992 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
102993 continue;
102994 - if (sym->st_value == addr)
102995 - return sym;
102996 /* Find a symbol nearby - addr are maybe negative */
102997 d = sym->st_value - addr;
102998 + if (d == 0)
102999 + return sym;
103000 if (d < 0)
103001 d = addr - sym->st_value;
103002 if (d < distance) {
103003 @@ -1428,6 +1435,14 @@ static void report_sec_mismatch(const char *modname,
103004 tosym, prl_to, prl_to, tosym);
103005 free(prl_to);
103006 break;
103007 + case DATA_TO_TEXT:
103008 +#if 0
103009 + fprintf(stderr,
103010 + "The %s %s:%s references\n"
103011 + "the %s %s:%s%s\n",
103012 + from, fromsec, fromsym, to, tosec, tosym, to_p);
103013 +#endif
103014 + break;
103015 }
103016 fprintf(stderr, "\n");
103017 }
103018 @@ -1662,7 +1677,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
103019 static void check_sec_ref(struct module *mod, const char *modname,
103020 struct elf_info *elf)
103021 {
103022 - int i;
103023 + unsigned int i;
103024 Elf_Shdr *sechdrs = elf->sechdrs;
103025
103026 /* Walk through all sections */
103027 @@ -1781,7 +1796,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
103028 va_end(ap);
103029 }
103030
103031 -void buf_write(struct buffer *buf, const char *s, int len)
103032 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
103033 {
103034 if (buf->size - buf->pos < len) {
103035 buf->size += len + SZ;
103036 @@ -2000,7 +2015,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
103037 if (fstat(fileno(file), &st) < 0)
103038 goto close_write;
103039
103040 - if (st.st_size != b->pos)
103041 + if (st.st_size != (off_t)b->pos)
103042 goto close_write;
103043
103044 tmp = NOFAIL(malloc(b->pos));
103045 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
103046 index 51207e4..f7d603d 100644
103047 --- a/scripts/mod/modpost.h
103048 +++ b/scripts/mod/modpost.h
103049 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
103050
103051 struct buffer {
103052 char *p;
103053 - int pos;
103054 - int size;
103055 + unsigned int pos;
103056 + unsigned int size;
103057 };
103058
103059 void __attribute__((format(printf, 2, 3)))
103060 buf_printf(struct buffer *buf, const char *fmt, ...);
103061
103062 void
103063 -buf_write(struct buffer *buf, const char *s, int len);
103064 +buf_write(struct buffer *buf, const char *s, unsigned int len);
103065
103066 struct module {
103067 struct module *next;
103068 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
103069 index deb2994..af4f63e 100644
103070 --- a/scripts/mod/sumversion.c
103071 +++ b/scripts/mod/sumversion.c
103072 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
103073 goto out;
103074 }
103075
103076 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
103077 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
103078 warn("writing sum in %s failed: %s\n",
103079 filename, strerror(errno));
103080 goto out;
103081 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
103082 index 0865b3e..7235dd4 100644
103083 --- a/scripts/module-common.lds
103084 +++ b/scripts/module-common.lds
103085 @@ -6,6 +6,10 @@
103086 SECTIONS {
103087 /DISCARD/ : { *(.discard) }
103088
103089 + .rodata : {
103090 + *(.rodata) *(.rodata.*)
103091 + *(.data..read_only)
103092 + }
103093 __ksymtab : { *(SORT(___ksymtab+*)) }
103094 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
103095 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
103096 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
103097 index c1bb9be..63aed853 100644
103098 --- a/scripts/package/builddeb
103099 +++ b/scripts/package/builddeb
103100 @@ -281,6 +281,7 @@ fi
103101 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
103102 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
103103 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
103104 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
103105 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
103106 mkdir -p "$destdir"
103107 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
103108 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
103109 index 68bb4ef..2f419e1 100644
103110 --- a/scripts/pnmtologo.c
103111 +++ b/scripts/pnmtologo.c
103112 @@ -244,14 +244,14 @@ static void write_header(void)
103113 fprintf(out, " * Linux logo %s\n", logoname);
103114 fputs(" */\n\n", out);
103115 fputs("#include <linux/linux_logo.h>\n\n", out);
103116 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
103117 + fprintf(out, "static unsigned char %s_data[] = {\n",
103118 logoname);
103119 }
103120
103121 static void write_footer(void)
103122 {
103123 fputs("\n};\n\n", out);
103124 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
103125 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
103126 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
103127 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
103128 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
103129 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
103130 fputs("\n};\n\n", out);
103131
103132 /* write logo clut */
103133 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
103134 + fprintf(out, "static unsigned char %s_clut[] = {\n",
103135 logoname);
103136 write_hex_cnt = 0;
103137 for (i = 0; i < logo_clutsize; i++) {
103138 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
103139 index 8fac3fd..32ff38d 100644
103140 --- a/scripts/sortextable.h
103141 +++ b/scripts/sortextable.h
103142 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
103143 const char *secstrtab;
103144 const char *strtab;
103145 char *extab_image;
103146 - int extab_index = 0;
103147 - int i;
103148 - int idx;
103149 + unsigned int extab_index = 0;
103150 + unsigned int i;
103151 + unsigned int idx;
103152 unsigned int num_sections;
103153 unsigned int secindex_strings;
103154
103155 diff --git a/security/Kconfig b/security/Kconfig
103156 index e9c6ac7..75578c4 100644
103157 --- a/security/Kconfig
103158 +++ b/security/Kconfig
103159 @@ -4,6 +4,960 @@
103160
103161 menu "Security options"
103162
103163 +menu "Grsecurity"
103164 +
103165 + config ARCH_TRACK_EXEC_LIMIT
103166 + bool
103167 +
103168 + config PAX_KERNEXEC_PLUGIN
103169 + bool
103170 +
103171 + config PAX_PER_CPU_PGD
103172 + bool
103173 +
103174 + config TASK_SIZE_MAX_SHIFT
103175 + int
103176 + depends on X86_64
103177 + default 47 if !PAX_PER_CPU_PGD
103178 + default 42 if PAX_PER_CPU_PGD
103179 +
103180 + config PAX_ENABLE_PAE
103181 + bool
103182 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
103183 +
103184 + config PAX_USERCOPY_SLABS
103185 + bool
103186 +
103187 +config GRKERNSEC
103188 + bool "Grsecurity"
103189 + select CRYPTO
103190 + select CRYPTO_SHA256
103191 + select PROC_FS
103192 + select STOP_MACHINE
103193 + select TTY
103194 + select DEBUG_KERNEL
103195 + select DEBUG_LIST
103196 + help
103197 + If you say Y here, you will be able to configure many features
103198 + that will enhance the security of your system. It is highly
103199 + recommended that you say Y here and read through the help
103200 + for each option so that you fully understand the features and
103201 + can evaluate their usefulness for your machine.
103202 +
103203 +choice
103204 + prompt "Configuration Method"
103205 + depends on GRKERNSEC
103206 + default GRKERNSEC_CONFIG_CUSTOM
103207 + help
103208 +
103209 +config GRKERNSEC_CONFIG_AUTO
103210 + bool "Automatic"
103211 + help
103212 + If you choose this configuration method, you'll be able to answer a small
103213 + number of simple questions about how you plan to use this kernel.
103214 + The settings of grsecurity and PaX will be automatically configured for
103215 + the highest commonly-used settings within the provided constraints.
103216 +
103217 + If you require additional configuration, custom changes can still be made
103218 + from the "custom configuration" menu.
103219 +
103220 +config GRKERNSEC_CONFIG_CUSTOM
103221 + bool "Custom"
103222 + help
103223 + If you choose this configuration method, you'll be able to configure all
103224 + grsecurity and PaX settings manually. Via this method, no options are
103225 + automatically enabled.
103226 +
103227 +endchoice
103228 +
103229 +choice
103230 + prompt "Usage Type"
103231 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
103232 + default GRKERNSEC_CONFIG_SERVER
103233 + help
103234 +
103235 +config GRKERNSEC_CONFIG_SERVER
103236 + bool "Server"
103237 + help
103238 + Choose this option if you plan to use this kernel on a server.
103239 +
103240 +config GRKERNSEC_CONFIG_DESKTOP
103241 + bool "Desktop"
103242 + help
103243 + Choose this option if you plan to use this kernel on a desktop.
103244 +
103245 +endchoice
103246 +
103247 +choice
103248 + prompt "Virtualization Type"
103249 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
103250 + default GRKERNSEC_CONFIG_VIRT_NONE
103251 + help
103252 +
103253 +config GRKERNSEC_CONFIG_VIRT_NONE
103254 + bool "None"
103255 + help
103256 + Choose this option if this kernel will be run on bare metal.
103257 +
103258 +config GRKERNSEC_CONFIG_VIRT_GUEST
103259 + bool "Guest"
103260 + help
103261 + Choose this option if this kernel will be run as a VM guest.
103262 +
103263 +config GRKERNSEC_CONFIG_VIRT_HOST
103264 + bool "Host"
103265 + help
103266 + Choose this option if this kernel will be run as a VM host.
103267 +
103268 +endchoice
103269 +
103270 +choice
103271 + prompt "Virtualization Hardware"
103272 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
103273 + help
103274 +
103275 +config GRKERNSEC_CONFIG_VIRT_EPT
103276 + bool "EPT/RVI Processor Support"
103277 + depends on X86
103278 + help
103279 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
103280 + hardware virtualization. This allows for additional kernel hardening protections
103281 + to operate without additional performance impact.
103282 +
103283 + To see if your Intel processor supports EPT, see:
103284 + http://ark.intel.com/Products/VirtualizationTechnology
103285 + (Most Core i3/5/7 support EPT)
103286 +
103287 + To see if your AMD processor supports RVI, see:
103288 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
103289 +
103290 +config GRKERNSEC_CONFIG_VIRT_SOFT
103291 + bool "First-gen/No Hardware Virtualization"
103292 + help
103293 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
103294 + support hardware virtualization or doesn't support the EPT/RVI extensions.
103295 +
103296 +endchoice
103297 +
103298 +choice
103299 + prompt "Virtualization Software"
103300 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
103301 + help
103302 +
103303 +config GRKERNSEC_CONFIG_VIRT_XEN
103304 + bool "Xen"
103305 + help
103306 + Choose this option if this kernel is running as a Xen guest or host.
103307 +
103308 +config GRKERNSEC_CONFIG_VIRT_VMWARE
103309 + bool "VMWare"
103310 + help
103311 + Choose this option if this kernel is running as a VMWare guest or host.
103312 +
103313 +config GRKERNSEC_CONFIG_VIRT_KVM
103314 + bool "KVM"
103315 + help
103316 + Choose this option if this kernel is running as a KVM guest or host.
103317 +
103318 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
103319 + bool "VirtualBox"
103320 + help
103321 + Choose this option if this kernel is running as a VirtualBox guest or host.
103322 +
103323 +endchoice
103324 +
103325 +choice
103326 + prompt "Required Priorities"
103327 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
103328 + default GRKERNSEC_CONFIG_PRIORITY_PERF
103329 + help
103330 +
103331 +config GRKERNSEC_CONFIG_PRIORITY_PERF
103332 + bool "Performance"
103333 + help
103334 + Choose this option if performance is of highest priority for this deployment
103335 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
103336 + clearing of structures intended for userland, and freed memory sanitizing will
103337 + be disabled.
103338 +
103339 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
103340 + bool "Security"
103341 + help
103342 + Choose this option if security is of highest priority for this deployment of
103343 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
103344 + for userland, and freed memory sanitizing will be enabled for this kernel.
103345 + In a worst-case scenario, these features can introduce a 20% performance hit
103346 + (UDEREF on x64 contributing half of this hit).
103347 +
103348 +endchoice
103349 +
103350 +menu "Default Special Groups"
103351 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
103352 +
103353 +config GRKERNSEC_PROC_GID
103354 + int "GID exempted from /proc restrictions"
103355 + default 1001
103356 + help
103357 + Setting this GID determines which group will be exempted from
103358 + grsecurity's /proc restrictions, allowing users of the specified
103359 + group to view network statistics and the existence of other users'
103360 + processes on the system. This GID may also be chosen at boot time
103361 + via "grsec_proc_gid=" on the kernel commandline.
103362 +
103363 +config GRKERNSEC_TPE_UNTRUSTED_GID
103364 + int "GID for TPE-untrusted users"
103365 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
103366 + default 1005
103367 + help
103368 + Setting this GID determines which group untrusted users should
103369 + be added to. These users will be placed under grsecurity's Trusted Path
103370 + Execution mechanism, preventing them from executing their own binaries.
103371 + The users will only be able to execute binaries in directories owned and
103372 + writable only by the root user. If the sysctl option is enabled, a sysctl
103373 + option with name "tpe_gid" is created.
103374 +
103375 +config GRKERNSEC_TPE_TRUSTED_GID
103376 + int "GID for TPE-trusted users"
103377 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
103378 + default 1005
103379 + help
103380 + Setting this GID determines what group TPE restrictions will be
103381 + *disabled* for. If the sysctl option is enabled, a sysctl option
103382 + with name "tpe_gid" is created.
103383 +
103384 +config GRKERNSEC_SYMLINKOWN_GID
103385 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
103386 + depends on GRKERNSEC_CONFIG_SERVER
103387 + default 1006
103388 + help
103389 + Setting this GID determines what group kernel-enforced
103390 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
103391 + is enabled, a sysctl option with name "symlinkown_gid" is created.
103392 +
103393 +
103394 +endmenu
103395 +
103396 +menu "Customize Configuration"
103397 +depends on GRKERNSEC
103398 +
103399 +menu "PaX"
103400 +
103401 +config PAX
103402 + bool "Enable various PaX features"
103403 + default y if GRKERNSEC_CONFIG_AUTO
103404 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
103405 + help
103406 + This allows you to enable various PaX features. PaX adds
103407 + intrusion prevention mechanisms to the kernel that reduce
103408 + the risks posed by exploitable memory corruption bugs.
103409 +
103410 +menu "PaX Control"
103411 + depends on PAX
103412 +
103413 +config PAX_SOFTMODE
103414 + bool 'Support soft mode'
103415 + help
103416 + Enabling this option will allow you to run PaX in soft mode, that
103417 + is, PaX features will not be enforced by default, only on executables
103418 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
103419 + support as they are the only way to mark executables for soft mode use.
103420 +
103421 + Soft mode can be activated by using the "pax_softmode=1" kernel command
103422 + line option on boot. Furthermore you can control various PaX features
103423 + at runtime via the entries in /proc/sys/kernel/pax.
103424 +
103425 +config PAX_EI_PAX
103426 + bool 'Use legacy ELF header marking'
103427 + default y if GRKERNSEC_CONFIG_AUTO
103428 + help
103429 + Enabling this option will allow you to control PaX features on
103430 + a per executable basis via the 'chpax' utility available at
103431 + http://pax.grsecurity.net/. The control flags will be read from
103432 + an otherwise reserved part of the ELF header. This marking has
103433 + numerous drawbacks (no support for soft-mode, toolchain does not
103434 + know about the non-standard use of the ELF header) therefore it
103435 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
103436 + support.
103437 +
103438 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
103439 + support as well, they will override the legacy EI_PAX marks.
103440 +
103441 + If you enable none of the marking options then all applications
103442 + will run with PaX enabled on them by default.
103443 +
103444 +config PAX_PT_PAX_FLAGS
103445 + bool 'Use ELF program header marking'
103446 + default y if GRKERNSEC_CONFIG_AUTO
103447 + help
103448 + Enabling this option will allow you to control PaX features on
103449 + a per executable basis via the 'paxctl' utility available at
103450 + http://pax.grsecurity.net/. The control flags will be read from
103451 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
103452 + has the benefits of supporting both soft mode and being fully
103453 + integrated into the toolchain (the binutils patch is available
103454 + from http://pax.grsecurity.net).
103455 +
103456 + Note that if you enable the legacy EI_PAX marking support as well,
103457 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
103458 +
103459 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103460 + must make sure that the marks are the same if a binary has both marks.
103461 +
103462 + If you enable none of the marking options then all applications
103463 + will run with PaX enabled on them by default.
103464 +
103465 +config PAX_XATTR_PAX_FLAGS
103466 + bool 'Use filesystem extended attributes marking'
103467 + default y if GRKERNSEC_CONFIG_AUTO
103468 + select CIFS_XATTR if CIFS
103469 + select EXT2_FS_XATTR if EXT2_FS
103470 + select EXT3_FS_XATTR if EXT3_FS
103471 + select JFFS2_FS_XATTR if JFFS2_FS
103472 + select REISERFS_FS_XATTR if REISERFS_FS
103473 + select SQUASHFS_XATTR if SQUASHFS
103474 + select TMPFS_XATTR if TMPFS
103475 + select UBIFS_FS_XATTR if UBIFS_FS
103476 + help
103477 + Enabling this option will allow you to control PaX features on
103478 + a per executable basis via the 'setfattr' utility. The control
103479 + flags will be read from the user.pax.flags extended attribute of
103480 + the file. This marking has the benefit of supporting binary-only
103481 + applications that self-check themselves (e.g., skype) and would
103482 + not tolerate chpax/paxctl changes. The main drawback is that
103483 + extended attributes are not supported by some filesystems (e.g.,
103484 + isofs, udf, vfat) so copying files through such filesystems will
103485 + lose the extended attributes and these PaX markings.
103486 +
103487 + Note that if you enable the legacy EI_PAX marking support as well,
103488 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
103489 +
103490 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103491 + must make sure that the marks are the same if a binary has both marks.
103492 +
103493 + If you enable none of the marking options then all applications
103494 + will run with PaX enabled on them by default.
103495 +
103496 +choice
103497 + prompt 'MAC system integration'
103498 + default PAX_HAVE_ACL_FLAGS
103499 + help
103500 + Mandatory Access Control systems have the option of controlling
103501 + PaX flags on a per executable basis, choose the method supported
103502 + by your particular system.
103503 +
103504 + - "none": if your MAC system does not interact with PaX,
103505 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
103506 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
103507 +
103508 + NOTE: this option is for developers/integrators only.
103509 +
103510 + config PAX_NO_ACL_FLAGS
103511 + bool 'none'
103512 +
103513 + config PAX_HAVE_ACL_FLAGS
103514 + bool 'direct'
103515 +
103516 + config PAX_HOOK_ACL_FLAGS
103517 + bool 'hook'
103518 +endchoice
103519 +
103520 +endmenu
103521 +
103522 +menu "Non-executable pages"
103523 + depends on PAX
103524 +
103525 +config PAX_NOEXEC
103526 + bool "Enforce non-executable pages"
103527 + default y if GRKERNSEC_CONFIG_AUTO
103528 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
103529 + help
103530 + By design some architectures do not allow for protecting memory
103531 + pages against execution or even if they do, Linux does not make
103532 + use of this feature. In practice this means that if a page is
103533 + readable (such as the stack or heap) it is also executable.
103534 +
103535 + There is a well known exploit technique that makes use of this
103536 + fact and a common programming mistake where an attacker can
103537 + introduce code of his choice somewhere in the attacked program's
103538 + memory (typically the stack or the heap) and then execute it.
103539 +
103540 + If the attacked program was running with different (typically
103541 + higher) privileges than that of the attacker, then he can elevate
103542 + his own privilege level (e.g. get a root shell, write to files for
103543 + which he does not have write access to, etc).
103544 +
103545 + Enabling this option will let you choose from various features
103546 + that prevent the injection and execution of 'foreign' code in
103547 + a program.
103548 +
103549 + This will also break programs that rely on the old behaviour and
103550 + expect that dynamically allocated memory via the malloc() family
103551 + of functions is executable (which it is not). Notable examples
103552 + are the XFree86 4.x server, the java runtime and wine.
103553 +
103554 +config PAX_PAGEEXEC
103555 + bool "Paging based non-executable pages"
103556 + default y if GRKERNSEC_CONFIG_AUTO
103557 + 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)
103558 + select ARCH_TRACK_EXEC_LIMIT if X86_32
103559 + help
103560 + This implementation is based on the paging feature of the CPU.
103561 + On i386 without hardware non-executable bit support there is a
103562 + variable but usually low performance impact, however on Intel's
103563 + P4 core based CPUs it is very high so you should not enable this
103564 + for kernels meant to be used on such CPUs.
103565 +
103566 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
103567 + with hardware non-executable bit support there is no performance
103568 + impact, on ppc the impact is negligible.
103569 +
103570 + Note that several architectures require various emulations due to
103571 + badly designed userland ABIs, this will cause a performance impact
103572 + but will disappear as soon as userland is fixed. For example, ppc
103573 + userland MUST have been built with secure-plt by a recent toolchain.
103574 +
103575 +config PAX_SEGMEXEC
103576 + bool "Segmentation based non-executable pages"
103577 + default y if GRKERNSEC_CONFIG_AUTO
103578 + depends on PAX_NOEXEC && X86_32
103579 + help
103580 + This implementation is based on the segmentation feature of the
103581 + CPU and has a very small performance impact, however applications
103582 + will be limited to a 1.5 GB address space instead of the normal
103583 + 3 GB.
103584 +
103585 +config PAX_EMUTRAMP
103586 + bool "Emulate trampolines"
103587 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
103588 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
103589 + help
103590 + There are some programs and libraries that for one reason or
103591 + another attempt to execute special small code snippets from
103592 + non-executable memory pages. Most notable examples are the
103593 + signal handler return code generated by the kernel itself and
103594 + the GCC trampolines.
103595 +
103596 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
103597 + such programs will no longer work under your kernel.
103598 +
103599 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
103600 + utilities to enable trampoline emulation for the affected programs
103601 + yet still have the protection provided by the non-executable pages.
103602 +
103603 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
103604 + your system will not even boot.
103605 +
103606 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
103607 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
103608 + for the affected files.
103609 +
103610 + NOTE: enabling this feature *may* open up a loophole in the
103611 + protection provided by non-executable pages that an attacker
103612 + could abuse. Therefore the best solution is to not have any
103613 + files on your system that would require this option. This can
103614 + be achieved by not using libc5 (which relies on the kernel
103615 + signal handler return code) and not using or rewriting programs
103616 + that make use of the nested function implementation of GCC.
103617 + Skilled users can just fix GCC itself so that it implements
103618 + nested function calls in a way that does not interfere with PaX.
103619 +
103620 +config PAX_EMUSIGRT
103621 + bool "Automatically emulate sigreturn trampolines"
103622 + depends on PAX_EMUTRAMP && PARISC
103623 + default y
103624 + help
103625 + Enabling this option will have the kernel automatically detect
103626 + and emulate signal return trampolines executing on the stack
103627 + that would otherwise lead to task termination.
103628 +
103629 + This solution is intended as a temporary one for users with
103630 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
103631 + Modula-3 runtime, etc) or executables linked to such, basically
103632 + everything that does not specify its own SA_RESTORER function in
103633 + normal executable memory like glibc 2.1+ does.
103634 +
103635 + On parisc you MUST enable this option, otherwise your system will
103636 + not even boot.
103637 +
103638 + NOTE: this feature cannot be disabled on a per executable basis
103639 + and since it *does* open up a loophole in the protection provided
103640 + by non-executable pages, the best solution is to not have any
103641 + files on your system that would require this option.
103642 +
103643 +config PAX_MPROTECT
103644 + bool "Restrict mprotect()"
103645 + default y if GRKERNSEC_CONFIG_AUTO
103646 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
103647 + help
103648 + Enabling this option will prevent programs from
103649 + - changing the executable status of memory pages that were
103650 + not originally created as executable,
103651 + - making read-only executable pages writable again,
103652 + - creating executable pages from anonymous memory,
103653 + - making read-only-after-relocations (RELRO) data pages writable again.
103654 +
103655 + You should say Y here to complete the protection provided by
103656 + the enforcement of non-executable pages.
103657 +
103658 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103659 + this feature on a per file basis.
103660 +
103661 +config PAX_MPROTECT_COMPAT
103662 + bool "Use legacy/compat protection demoting (read help)"
103663 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103664 + depends on PAX_MPROTECT
103665 + help
103666 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
103667 + by sending the proper error code to the application. For some broken
103668 + userland, this can cause problems with Python or other applications. The
103669 + current implementation however allows for applications like clamav to
103670 + detect if JIT compilation/execution is allowed and to fall back gracefully
103671 + to an interpreter-based mode if it does not. While we encourage everyone
103672 + to use the current implementation as-is and push upstream to fix broken
103673 + userland (note that the RWX logging option can assist with this), in some
103674 + environments this may not be possible. Having to disable MPROTECT
103675 + completely on certain binaries reduces the security benefit of PaX,
103676 + so this option is provided for those environments to revert to the old
103677 + behavior.
103678 +
103679 +config PAX_ELFRELOCS
103680 + bool "Allow ELF text relocations (read help)"
103681 + depends on PAX_MPROTECT
103682 + default n
103683 + help
103684 + Non-executable pages and mprotect() restrictions are effective
103685 + in preventing the introduction of new executable code into an
103686 + attacked task's address space. There remain only two venues
103687 + for this kind of attack: if the attacker can execute already
103688 + existing code in the attacked task then he can either have it
103689 + create and mmap() a file containing his code or have it mmap()
103690 + an already existing ELF library that does not have position
103691 + independent code in it and use mprotect() on it to make it
103692 + writable and copy his code there. While protecting against
103693 + the former approach is beyond PaX, the latter can be prevented
103694 + by having only PIC ELF libraries on one's system (which do not
103695 + need to relocate their code). If you are sure this is your case,
103696 + as is the case with all modern Linux distributions, then leave
103697 + this option disabled. You should say 'n' here.
103698 +
103699 +config PAX_ETEXECRELOCS
103700 + bool "Allow ELF ET_EXEC text relocations"
103701 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
103702 + select PAX_ELFRELOCS
103703 + default y
103704 + help
103705 + On some architectures there are incorrectly created applications
103706 + that require text relocations and would not work without enabling
103707 + this option. If you are an alpha, ia64 or parisc user, you should
103708 + enable this option and disable it once you have made sure that
103709 + none of your applications need it.
103710 +
103711 +config PAX_EMUPLT
103712 + bool "Automatically emulate ELF PLT"
103713 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
103714 + default y
103715 + help
103716 + Enabling this option will have the kernel automatically detect
103717 + and emulate the Procedure Linkage Table entries in ELF files.
103718 + On some architectures such entries are in writable memory, and
103719 + become non-executable leading to task termination. Therefore
103720 + it is mandatory that you enable this option on alpha, parisc,
103721 + sparc and sparc64, otherwise your system would not even boot.
103722 +
103723 + NOTE: this feature *does* open up a loophole in the protection
103724 + provided by the non-executable pages, therefore the proper
103725 + solution is to modify the toolchain to produce a PLT that does
103726 + not need to be writable.
103727 +
103728 +config PAX_DLRESOLVE
103729 + bool 'Emulate old glibc resolver stub'
103730 + depends on PAX_EMUPLT && SPARC
103731 + default n
103732 + help
103733 + This option is needed if userland has an old glibc (before 2.4)
103734 + that puts a 'save' instruction into the runtime generated resolver
103735 + stub that needs special emulation.
103736 +
103737 +config PAX_KERNEXEC
103738 + bool "Enforce non-executable kernel pages"
103739 + 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))
103740 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
103741 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
103742 + select PAX_KERNEXEC_PLUGIN if X86_64
103743 + help
103744 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
103745 + that is, enabling this option will make it harder to inject
103746 + and execute 'foreign' code in kernel memory itself.
103747 +
103748 +choice
103749 + prompt "Return Address Instrumentation Method"
103750 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
103751 + depends on PAX_KERNEXEC_PLUGIN
103752 + help
103753 + Select the method used to instrument function pointer dereferences.
103754 + Note that binary modules cannot be instrumented by this approach.
103755 +
103756 + Note that the implementation requires a gcc with plugin support,
103757 + i.e., gcc 4.5 or newer. You may need to install the supporting
103758 + headers explicitly in addition to the normal gcc package.
103759 +
103760 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
103761 + bool "bts"
103762 + help
103763 + This method is compatible with binary only modules but has
103764 + a higher runtime overhead.
103765 +
103766 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
103767 + bool "or"
103768 + depends on !PARAVIRT
103769 + help
103770 + This method is incompatible with binary only modules but has
103771 + a lower runtime overhead.
103772 +endchoice
103773 +
103774 +config PAX_KERNEXEC_PLUGIN_METHOD
103775 + string
103776 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
103777 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
103778 + default ""
103779 +
103780 +config PAX_KERNEXEC_MODULE_TEXT
103781 + int "Minimum amount of memory reserved for module code"
103782 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
103783 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103784 + depends on PAX_KERNEXEC && X86_32
103785 + help
103786 + Due to implementation details the kernel must reserve a fixed
103787 + amount of memory for runtime allocated code (such as modules)
103788 + at compile time that cannot be changed at runtime. Here you
103789 + can specify the minimum amount in MB that will be reserved.
103790 + Due to the same implementation details this size will always
103791 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
103792 + the actually available memory for runtime allocated code will
103793 + usually be more than this minimum.
103794 +
103795 + The default 4 MB should be enough for most users but if you have
103796 + an excessive number of modules (e.g., most distribution configs
103797 + compile many drivers as modules) or use huge modules such as
103798 + nvidia's kernel driver, you will need to adjust this amount.
103799 + A good rule of thumb is to look at your currently loaded kernel
103800 + modules and add up their sizes.
103801 +
103802 +endmenu
103803 +
103804 +menu "Address Space Layout Randomization"
103805 + depends on PAX
103806 +
103807 +config PAX_ASLR
103808 + bool "Address Space Layout Randomization"
103809 + default y if GRKERNSEC_CONFIG_AUTO
103810 + help
103811 + Many if not most exploit techniques rely on the knowledge of
103812 + certain addresses in the attacked program. The following options
103813 + will allow the kernel to apply a certain amount of randomization
103814 + to specific parts of the program thereby forcing an attacker to
103815 + guess them in most cases. Any failed guess will most likely crash
103816 + the attacked program which allows the kernel to detect such attempts
103817 + and react on them. PaX itself provides no reaction mechanisms,
103818 + instead it is strongly encouraged that you make use of Nergal's
103819 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
103820 + (http://www.grsecurity.net/) built-in crash detection features or
103821 + develop one yourself.
103822 +
103823 + By saying Y here you can choose to randomize the following areas:
103824 + - top of the task's kernel stack
103825 + - top of the task's userland stack
103826 + - base address for mmap() requests that do not specify one
103827 + (this includes all libraries)
103828 + - base address of the main executable
103829 +
103830 + It is strongly recommended to say Y here as address space layout
103831 + randomization has negligible impact on performance yet it provides
103832 + a very effective protection.
103833 +
103834 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103835 + this feature on a per file basis.
103836 +
103837 +config PAX_RANDKSTACK
103838 + bool "Randomize kernel stack base"
103839 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
103840 + depends on X86_TSC && X86
103841 + help
103842 + By saying Y here the kernel will randomize every task's kernel
103843 + stack on every system call. This will not only force an attacker
103844 + to guess it but also prevent him from making use of possible
103845 + leaked information about it.
103846 +
103847 + Since the kernel stack is a rather scarce resource, randomization
103848 + may cause unexpected stack overflows, therefore you should very
103849 + carefully test your system. Note that once enabled in the kernel
103850 + configuration, this feature cannot be disabled on a per file basis.
103851 +
103852 +config PAX_RANDUSTACK
103853 + bool "Randomize user stack base"
103854 + default y if GRKERNSEC_CONFIG_AUTO
103855 + depends on PAX_ASLR
103856 + help
103857 + By saying Y here the kernel will randomize every task's userland
103858 + stack. The randomization is done in two steps where the second
103859 + one may apply a big amount of shift to the top of the stack and
103860 + cause problems for programs that want to use lots of memory (more
103861 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
103862 + For this reason the second step can be controlled by 'chpax' or
103863 + 'paxctl' on a per file basis.
103864 +
103865 +config PAX_RANDMMAP
103866 + bool "Randomize mmap() base"
103867 + default y if GRKERNSEC_CONFIG_AUTO
103868 + depends on PAX_ASLR
103869 + help
103870 + By saying Y here the kernel will use a randomized base address for
103871 + mmap() requests that do not specify one themselves. As a result
103872 + all dynamically loaded libraries will appear at random addresses
103873 + and therefore be harder to exploit by a technique where an attacker
103874 + attempts to execute library code for his purposes (e.g. spawn a
103875 + shell from an exploited program that is running at an elevated
103876 + privilege level).
103877 +
103878 + Furthermore, if a program is relinked as a dynamic ELF file, its
103879 + base address will be randomized as well, completing the full
103880 + randomization of the address space layout. Attacking such programs
103881 + becomes a guess game. You can find an example of doing this at
103882 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
103883 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
103884 +
103885 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
103886 + feature on a per file basis.
103887 +
103888 +endmenu
103889 +
103890 +menu "Miscellaneous hardening features"
103891 +
103892 +config PAX_MEMORY_SANITIZE
103893 + bool "Sanitize all freed memory"
103894 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103895 + help
103896 + By saying Y here the kernel will erase memory pages and slab objects
103897 + as soon as they are freed. This in turn reduces the lifetime of data
103898 + stored in them, making it less likely that sensitive information such
103899 + as passwords, cryptographic secrets, etc stay in memory for too long.
103900 +
103901 + This is especially useful for programs whose runtime is short, long
103902 + lived processes and the kernel itself benefit from this as long as
103903 + they ensure timely freeing of memory that may hold sensitive
103904 + information.
103905 +
103906 + A nice side effect of the sanitization of slab objects is the
103907 + reduction of possible info leaks caused by padding bytes within the
103908 + leaky structures. Use-after-free bugs for structures containing
103909 + pointers can also be detected as dereferencing the sanitized pointer
103910 + will generate an access violation.
103911 +
103912 + The tradeoff is performance impact, on a single CPU system kernel
103913 + compilation sees a 3% slowdown, other systems and workloads may vary
103914 + and you are advised to test this feature on your expected workload
103915 + before deploying it.
103916 +
103917 + To reduce the performance penalty by sanitizing pages only, albeit
103918 + limiting the effectiveness of this feature at the same time, slab
103919 + sanitization can be disabled with the kernel commandline parameter
103920 + "pax_sanitize_slab=0".
103921 +
103922 + Note that this feature does not protect data stored in live pages,
103923 + e.g., process memory swapped to disk may stay there for a long time.
103924 +
103925 +config PAX_MEMORY_STACKLEAK
103926 + bool "Sanitize kernel stack"
103927 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103928 + depends on X86
103929 + help
103930 + By saying Y here the kernel will erase the kernel stack before it
103931 + returns from a system call. This in turn reduces the information
103932 + that a kernel stack leak bug can reveal.
103933 +
103934 + Note that such a bug can still leak information that was put on
103935 + the stack by the current system call (the one eventually triggering
103936 + the bug) but traces of earlier system calls on the kernel stack
103937 + cannot leak anymore.
103938 +
103939 + The tradeoff is performance impact: on a single CPU system kernel
103940 + compilation sees a 1% slowdown, other systems and workloads may vary
103941 + and you are advised to test this feature on your expected workload
103942 + before deploying it.
103943 +
103944 + Note that the full feature requires a gcc with plugin support,
103945 + i.e., gcc 4.5 or newer. You may need to install the supporting
103946 + headers explicitly in addition to the normal gcc package. Using
103947 + older gcc versions means that functions with large enough stack
103948 + frames may leave uninitialized memory behind that may be exposed
103949 + to a later syscall leaking the stack.
103950 +
103951 +config PAX_MEMORY_STRUCTLEAK
103952 + bool "Forcibly initialize local variables copied to userland"
103953 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103954 + help
103955 + By saying Y here the kernel will zero initialize some local
103956 + variables that are going to be copied to userland. This in
103957 + turn prevents unintended information leakage from the kernel
103958 + stack should later code forget to explicitly set all parts of
103959 + the copied variable.
103960 +
103961 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
103962 + at a much smaller coverage.
103963 +
103964 + Note that the implementation requires a gcc with plugin support,
103965 + i.e., gcc 4.5 or newer. You may need to install the supporting
103966 + headers explicitly in addition to the normal gcc package.
103967 +
103968 +config PAX_MEMORY_UDEREF
103969 + bool "Prevent invalid userland pointer dereference"
103970 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
103971 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
103972 + select PAX_PER_CPU_PGD if X86_64
103973 + help
103974 + By saying Y here the kernel will be prevented from dereferencing
103975 + userland pointers in contexts where the kernel expects only kernel
103976 + pointers. This is both a useful runtime debugging feature and a
103977 + security measure that prevents exploiting a class of kernel bugs.
103978 +
103979 + The tradeoff is that some virtualization solutions may experience
103980 + a huge slowdown and therefore you should not enable this feature
103981 + for kernels meant to run in such environments. Whether a given VM
103982 + solution is affected or not is best determined by simply trying it
103983 + out, the performance impact will be obvious right on boot as this
103984 + mechanism engages from very early on. A good rule of thumb is that
103985 + VMs running on CPUs without hardware virtualization support (i.e.,
103986 + the majority of IA-32 CPUs) will likely experience the slowdown.
103987 +
103988 + On X86_64 the kernel will make use of PCID support when available
103989 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
103990 + or performance impact. Pass pax_weakuderef on the kernel command
103991 + line to choose the latter.
103992 +
103993 +config PAX_REFCOUNT
103994 + bool "Prevent various kernel object reference counter overflows"
103995 + default y if GRKERNSEC_CONFIG_AUTO
103996 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
103997 + help
103998 + By saying Y here the kernel will detect and prevent overflowing
103999 + various (but not all) kinds of object reference counters. Such
104000 + overflows can normally occur due to bugs only and are often, if
104001 + not always, exploitable.
104002 +
104003 + The tradeoff is that data structures protected by an overflowed
104004 + refcount will never be freed and therefore will leak memory. Note
104005 + that this leak also happens even without this protection but in
104006 + that case the overflow can eventually trigger the freeing of the
104007 + data structure while it is still being used elsewhere, resulting
104008 + in the exploitable situation that this feature prevents.
104009 +
104010 + Since this has a negligible performance impact, you should enable
104011 + this feature.
104012 +
104013 +config PAX_CONSTIFY_PLUGIN
104014 + bool "Automatically constify eligible structures"
104015 + default y
104016 + depends on !UML && PAX_KERNEXEC
104017 + help
104018 + By saying Y here the compiler will automatically constify a class
104019 + of types that contain only function pointers. This reduces the
104020 + kernel's attack surface and also produces a better memory layout.
104021 +
104022 + Note that the implementation requires a gcc with plugin support,
104023 + i.e., gcc 4.5 or newer. You may need to install the supporting
104024 + headers explicitly in addition to the normal gcc package.
104025 +
104026 + Note that if some code really has to modify constified variables
104027 + then the source code will have to be patched to allow it. Examples
104028 + can be found in PaX itself (the no_const attribute) and for some
104029 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
104030 +
104031 +config PAX_USERCOPY
104032 + bool "Harden heap object copies between kernel and userland"
104033 + default y if GRKERNSEC_CONFIG_AUTO
104034 + depends on ARM || IA64 || PPC || SPARC || X86
104035 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
104036 + select PAX_USERCOPY_SLABS
104037 + help
104038 + By saying Y here the kernel will enforce the size of heap objects
104039 + when they are copied in either direction between the kernel and
104040 + userland, even if only a part of the heap object is copied.
104041 +
104042 + Specifically, this checking prevents information leaking from the
104043 + kernel heap during kernel to userland copies (if the kernel heap
104044 + object is otherwise fully initialized) and prevents kernel heap
104045 + overflows during userland to kernel copies.
104046 +
104047 + Note that the current implementation provides the strictest bounds
104048 + checks for the SLUB allocator.
104049 +
104050 + Enabling this option also enables per-slab cache protection against
104051 + data in a given cache being copied into/out of via userland
104052 + accessors. Though the whitelist of regions will be reduced over
104053 + time, it notably protects important data structures like task structs.
104054 +
104055 + If frame pointers are enabled on x86, this option will also restrict
104056 + copies into and out of the kernel stack to local variables within a
104057 + single frame.
104058 +
104059 + Since this has a negligible performance impact, you should enable
104060 + this feature.
104061 +
104062 +config PAX_USERCOPY_DEBUG
104063 + bool
104064 + depends on X86 && PAX_USERCOPY
104065 + default n
104066 +
104067 +config PAX_SIZE_OVERFLOW
104068 + bool "Prevent various integer overflows in function size parameters"
104069 + default y if GRKERNSEC_CONFIG_AUTO
104070 + depends on X86
104071 + help
104072 + By saying Y here the kernel recomputes expressions of function
104073 + arguments marked by a size_overflow attribute with double integer
104074 + precision (DImode/TImode for 32/64 bit integer types).
104075 +
104076 + The recomputed argument is checked against TYPE_MAX and an event
104077 + is logged on overflow and the triggering process is killed.
104078 +
104079 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
104080 +
104081 + Note that the implementation requires a gcc with plugin support,
104082 + i.e., gcc 4.5 or newer. You may need to install the supporting
104083 + headers explicitly in addition to the normal gcc package.
104084 +
104085 +config PAX_LATENT_ENTROPY
104086 + bool "Generate some entropy during boot and runtime"
104087 + default y if GRKERNSEC_CONFIG_AUTO
104088 + help
104089 + By saying Y here the kernel will instrument some kernel code to
104090 + extract some entropy from both original and artificially created
104091 + program state. This will help especially embedded systems where
104092 + there is little 'natural' source of entropy normally. The cost
104093 + is some slowdown of the boot process and fork and irq processing.
104094 +
104095 + When pax_extra_latent_entropy is passed on the kernel command line,
104096 + entropy will be extracted from up to the first 4GB of RAM while the
104097 + runtime memory allocator is being initialized. This costs even more
104098 + slowdown of the boot process.
104099 +
104100 + Note that the implementation requires a gcc with plugin support,
104101 + i.e., gcc 4.5 or newer. You may need to install the supporting
104102 + headers explicitly in addition to the normal gcc package.
104103 +
104104 + Note that entropy extracted this way is not cryptographically
104105 + secure!
104106 +
104107 +endmenu
104108 +
104109 +endmenu
104110 +
104111 +source grsecurity/Kconfig
104112 +
104113 +endmenu
104114 +
104115 +endmenu
104116 +
104117 source security/keys/Kconfig
104118
104119 config SECURITY_DMESG_RESTRICT
104120 @@ -103,7 +1057,7 @@ config INTEL_TXT
104121 config LSM_MMAP_MIN_ADDR
104122 int "Low address space for LSM to protect from user allocation"
104123 depends on SECURITY && SECURITY_SELINUX
104124 - default 32768 if ARM
104125 + default 32768 if ALPHA || ARM || PARISC || SPARC32
104126 default 65536
104127 help
104128 This is the portion of low virtual memory which should be protected
104129 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
104130 index fdaa50c..2761dcb 100644
104131 --- a/security/apparmor/file.c
104132 +++ b/security/apparmor/file.c
104133 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
104134 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
104135 struct path *new_dir, struct dentry *new_dentry)
104136 {
104137 - struct path link = { new_dir->mnt, new_dentry };
104138 - struct path target = { new_dir->mnt, old_dentry };
104139 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
104140 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
104141 struct path_cond cond = {
104142 old_dentry->d_inode->i_uid,
104143 old_dentry->d_inode->i_mode
104144 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
104145 index 4257b7e..2d0732d 100644
104146 --- a/security/apparmor/lsm.c
104147 +++ b/security/apparmor/lsm.c
104148 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
104149 struct dentry *dentry, u32 mask,
104150 struct path_cond *cond)
104151 {
104152 - struct path path = { dir->mnt, dentry };
104153 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
104154
104155 return common_perm(op, &path, mask, cond);
104156 }
104157 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
104158 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
104159 struct dentry *dentry, u32 mask)
104160 {
104161 - struct path path = { mnt, dentry };
104162 + struct path path = { .mnt = mnt, .dentry = dentry };
104163 struct path_cond cond = { dentry->d_inode->i_uid,
104164 dentry->d_inode->i_mode
104165 };
104166 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
104167
104168 profile = aa_current_profile();
104169 if (!unconfined(profile)) {
104170 - struct path old_path = { old_dir->mnt, old_dentry };
104171 - struct path new_path = { new_dir->mnt, new_dentry };
104172 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
104173 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
104174 struct path_cond cond = { old_dentry->d_inode->i_uid,
104175 old_dentry->d_inode->i_mode
104176 };
104177 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
104178 return error;
104179 }
104180
104181 -static struct security_operations apparmor_ops = {
104182 +static struct security_operations apparmor_ops __read_only = {
104183 .name = "apparmor",
104184
104185 .ptrace_access_check = apparmor_ptrace_access_check,
104186 diff --git a/security/commoncap.c b/security/commoncap.c
104187 index b9d613e..f68305c 100644
104188 --- a/security/commoncap.c
104189 +++ b/security/commoncap.c
104190 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
104191 return 0;
104192 }
104193
104194 +/* returns:
104195 + 1 for suid privilege
104196 + 2 for sgid privilege
104197 + 3 for fscap privilege
104198 +*/
104199 +int is_privileged_binary(const struct dentry *dentry)
104200 +{
104201 + struct cpu_vfs_cap_data capdata;
104202 + struct inode *inode = dentry->d_inode;
104203 +
104204 + if (!inode || S_ISDIR(inode->i_mode))
104205 + return 0;
104206 +
104207 + if (inode->i_mode & S_ISUID)
104208 + return 1;
104209 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
104210 + return 2;
104211 +
104212 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
104213 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
104214 + return 3;
104215 + }
104216 +
104217 + return 0;
104218 +}
104219 +
104220 /*
104221 * Attempt to get the on-exec apply capability sets for an executable file from
104222 * its xattrs and, if present, apply them to the proposed credentials being
104223 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
104224 const struct cred *cred = current_cred();
104225 kuid_t root_uid = make_kuid(cred->user_ns, 0);
104226
104227 + if (gr_acl_enable_at_secure())
104228 + return 1;
104229 +
104230 if (!uid_eq(cred->uid, root_uid)) {
104231 if (bprm->cap_effective)
104232 return 1;
104233 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
104234 index 0356e1d..72332ab 100644
104235 --- a/security/integrity/ima/ima.h
104236 +++ b/security/integrity/ima/ima.h
104237 @@ -118,8 +118,8 @@ int ima_init_template(void);
104238 extern spinlock_t ima_queue_lock;
104239
104240 struct ima_h_table {
104241 - atomic_long_t len; /* number of stored measurements in the list */
104242 - atomic_long_t violations;
104243 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
104244 + atomic_long_unchecked_t violations;
104245 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
104246 };
104247 extern struct ima_h_table ima_htable;
104248 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
104249 index c38bbce..f45133d 100644
104250 --- a/security/integrity/ima/ima_api.c
104251 +++ b/security/integrity/ima/ima_api.c
104252 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
104253 int result;
104254
104255 /* can overflow, only indicator */
104256 - atomic_long_inc(&ima_htable.violations);
104257 + atomic_long_inc_unchecked(&ima_htable.violations);
104258
104259 result = ima_alloc_init_template(NULL, file, filename,
104260 NULL, 0, &entry);
104261 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
104262 index db01125..61f6597 100644
104263 --- a/security/integrity/ima/ima_fs.c
104264 +++ b/security/integrity/ima/ima_fs.c
104265 @@ -28,12 +28,12 @@
104266 static int valid_policy = 1;
104267 #define TMPBUFLEN 12
104268 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
104269 - loff_t *ppos, atomic_long_t *val)
104270 + loff_t *ppos, atomic_long_unchecked_t *val)
104271 {
104272 char tmpbuf[TMPBUFLEN];
104273 ssize_t len;
104274
104275 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
104276 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
104277 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
104278 }
104279
104280 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
104281 index d85e997..6992813 100644
104282 --- a/security/integrity/ima/ima_queue.c
104283 +++ b/security/integrity/ima/ima_queue.c
104284 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
104285 INIT_LIST_HEAD(&qe->later);
104286 list_add_tail_rcu(&qe->later, &ima_measurements);
104287
104288 - atomic_long_inc(&ima_htable.len);
104289 + atomic_long_inc_unchecked(&ima_htable.len);
104290 key = ima_hash_key(entry->digest);
104291 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
104292 return 0;
104293 diff --git a/security/keys/compat.c b/security/keys/compat.c
104294 index bbd32c7..c60c927 100644
104295 --- a/security/keys/compat.c
104296 +++ b/security/keys/compat.c
104297 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
104298 if (ret == 0)
104299 goto no_payload_free;
104300
104301 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
104302 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
104303 err:
104304 if (iov != iovstack)
104305 kfree(iov);
104306 diff --git a/security/keys/internal.h b/security/keys/internal.h
104307 index 80b2aac..bb7ee65 100644
104308 --- a/security/keys/internal.h
104309 +++ b/security/keys/internal.h
104310 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
104311 extern long keyctl_invalidate_key(key_serial_t);
104312
104313 extern long keyctl_instantiate_key_common(key_serial_t,
104314 - const struct iovec *,
104315 + const struct iovec __user *,
104316 unsigned, size_t, key_serial_t);
104317 #ifdef CONFIG_PERSISTENT_KEYRINGS
104318 extern long keyctl_get_persistent(uid_t, key_serial_t);
104319 diff --git a/security/keys/key.c b/security/keys/key.c
104320 index 6e21c11..9ed67ca 100644
104321 --- a/security/keys/key.c
104322 +++ b/security/keys/key.c
104323 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
104324
104325 atomic_set(&key->usage, 1);
104326 init_rwsem(&key->sem);
104327 - lockdep_set_class(&key->sem, &type->lock_class);
104328 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
104329 key->index_key.type = type;
104330 key->user = user;
104331 key->quotalen = quotalen;
104332 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
104333 struct key_type *p;
104334 int ret;
104335
104336 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
104337 + pax_open_kernel();
104338 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
104339 + pax_close_kernel();
104340
104341 ret = -EEXIST;
104342 down_write(&key_types_sem);
104343 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
104344 }
104345
104346 /* store the type */
104347 - list_add(&ktype->link, &key_types_list);
104348 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
104349
104350 pr_notice("Key type %s registered\n", ktype->name);
104351 ret = 0;
104352 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
104353 void unregister_key_type(struct key_type *ktype)
104354 {
104355 down_write(&key_types_sem);
104356 - list_del_init(&ktype->link);
104357 + pax_list_del_init((struct list_head *)&ktype->link);
104358 downgrade_write(&key_types_sem);
104359 key_gc_keytype(ktype);
104360 pr_notice("Key type %s unregistered\n", ktype->name);
104361 @@ -1088,10 +1090,10 @@ void __init key_init(void)
104362 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
104363
104364 /* add the special key types */
104365 - list_add_tail(&key_type_keyring.link, &key_types_list);
104366 - list_add_tail(&key_type_dead.link, &key_types_list);
104367 - list_add_tail(&key_type_user.link, &key_types_list);
104368 - list_add_tail(&key_type_logon.link, &key_types_list);
104369 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
104370 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
104371 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
104372 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
104373
104374 /* record the root user tracking */
104375 rb_link_node(&root_key_user.node,
104376 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
104377 index cee72ce..e46074a 100644
104378 --- a/security/keys/keyctl.c
104379 +++ b/security/keys/keyctl.c
104380 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
104381 /*
104382 * Copy the iovec data from userspace
104383 */
104384 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
104385 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
104386 unsigned ioc)
104387 {
104388 for (; ioc > 0; ioc--) {
104389 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
104390 * If successful, 0 will be returned.
104391 */
104392 long keyctl_instantiate_key_common(key_serial_t id,
104393 - const struct iovec *payload_iov,
104394 + const struct iovec __user *payload_iov,
104395 unsigned ioc,
104396 size_t plen,
104397 key_serial_t ringid)
104398 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
104399 [0].iov_len = plen
104400 };
104401
104402 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
104403 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
104404 }
104405
104406 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
104407 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
104408 if (ret == 0)
104409 goto no_payload_free;
104410
104411 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
104412 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
104413 err:
104414 if (iov != iovstack)
104415 kfree(iov);
104416 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
104417 index d46cbc5..2fb2576 100644
104418 --- a/security/keys/keyring.c
104419 +++ b/security/keys/keyring.c
104420 @@ -1000,7 +1000,11 @@ static int keyring_detect_cycle_iterator(const void *object,
104421
104422 kenter("{%d}", key->serial);
104423
104424 - BUG_ON(key != ctx->match_data);
104425 + /* We might get a keyring with matching index-key that is nonetheless a
104426 + * different keyring. */
104427 + if (key != ctx->match_data)
104428 + return 0;
104429 +
104430 ctx->result = ERR_PTR(-EDEADLK);
104431 return 1;
104432 }
104433 diff --git a/security/min_addr.c b/security/min_addr.c
104434 index f728728..6457a0c 100644
104435 --- a/security/min_addr.c
104436 +++ b/security/min_addr.c
104437 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
104438 */
104439 static void update_mmap_min_addr(void)
104440 {
104441 +#ifndef SPARC
104442 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
104443 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
104444 mmap_min_addr = dac_mmap_min_addr;
104445 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
104446 #else
104447 mmap_min_addr = dac_mmap_min_addr;
104448 #endif
104449 +#endif
104450 }
104451
104452 /*
104453 diff --git a/security/security.c b/security/security.c
104454 index 15b6928..60d03ec 100644
104455 --- a/security/security.c
104456 +++ b/security/security.c
104457 @@ -33,8 +33,8 @@
104458 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
104459 CONFIG_DEFAULT_SECURITY;
104460
104461 -static struct security_operations *security_ops;
104462 -static struct security_operations default_security_ops = {
104463 +struct security_operations *security_ops __read_only;
104464 +struct security_operations default_security_ops __read_only = {
104465 .name = "default",
104466 };
104467
104468 @@ -73,11 +73,6 @@ int __init security_init(void)
104469 return 0;
104470 }
104471
104472 -void reset_security_ops(void)
104473 -{
104474 - security_ops = &default_security_ops;
104475 -}
104476 -
104477 /* Save user chosen LSM */
104478 static int __init choose_lsm(char *str)
104479 {
104480 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
104481 index fc3e662..7844c60 100644
104482 --- a/security/selinux/avc.c
104483 +++ b/security/selinux/avc.c
104484 @@ -59,7 +59,7 @@ struct avc_node {
104485 struct avc_cache {
104486 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
104487 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
104488 - atomic_t lru_hint; /* LRU hint for reclaim scan */
104489 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
104490 atomic_t active_nodes;
104491 u32 latest_notif; /* latest revocation notification */
104492 };
104493 @@ -167,7 +167,7 @@ void __init avc_init(void)
104494 spin_lock_init(&avc_cache.slots_lock[i]);
104495 }
104496 atomic_set(&avc_cache.active_nodes, 0);
104497 - atomic_set(&avc_cache.lru_hint, 0);
104498 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
104499
104500 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
104501 0, SLAB_PANIC, NULL);
104502 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
104503 spinlock_t *lock;
104504
104505 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
104506 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104507 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104508 head = &avc_cache.slots[hvalue];
104509 lock = &avc_cache.slots_lock[hvalue];
104510
104511 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
104512 index 57b0b49..402063e 100644
104513 --- a/security/selinux/hooks.c
104514 +++ b/security/selinux/hooks.c
104515 @@ -96,8 +96,6 @@
104516 #include "audit.h"
104517 #include "avc_ss.h"
104518
104519 -extern struct security_operations *security_ops;
104520 -
104521 /* SECMARK reference count */
104522 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
104523
104524 @@ -5745,7 +5743,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
104525
104526 #endif
104527
104528 -static struct security_operations selinux_ops = {
104529 +static struct security_operations selinux_ops __read_only = {
104530 .name = "selinux",
104531
104532 .ptrace_access_check = selinux_ptrace_access_check,
104533 @@ -6098,6 +6096,9 @@ static void selinux_nf_ip_exit(void)
104534 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
104535 static int selinux_disabled;
104536
104537 +extern struct security_operations *security_ops;
104538 +extern struct security_operations default_security_ops;
104539 +
104540 int selinux_disable(void)
104541 {
104542 if (ss_initialized) {
104543 @@ -6115,7 +6116,9 @@ int selinux_disable(void)
104544 selinux_disabled = 1;
104545 selinux_enabled = 0;
104546
104547 - reset_security_ops();
104548 + pax_open_kernel();
104549 + security_ops = &default_security_ops;
104550 + pax_close_kernel();
104551
104552 /* Try to destroy the avc node cache */
104553 avc_disable();
104554 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
104555 index 48c3cc9..8022cf7 100644
104556 --- a/security/selinux/include/xfrm.h
104557 +++ b/security/selinux/include/xfrm.h
104558 @@ -45,7 +45,7 @@ static inline void selinux_xfrm_notify_policyload(void)
104559 {
104560 struct net *net;
104561
104562 - atomic_inc(&flow_cache_genid);
104563 + atomic_inc_unchecked(&flow_cache_genid);
104564 rtnl_lock();
104565 for_each_net(net)
104566 rt_genid_bump_all(net);
104567 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
104568 index b0be893..646bd94 100644
104569 --- a/security/smack/smack_lsm.c
104570 +++ b/security/smack/smack_lsm.c
104571 @@ -3731,7 +3731,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
104572 return 0;
104573 }
104574
104575 -struct security_operations smack_ops = {
104576 +struct security_operations smack_ops __read_only = {
104577 .name = "smack",
104578
104579 .ptrace_access_check = smack_ptrace_access_check,
104580 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
104581 index 4003907..13a2b55 100644
104582 --- a/security/tomoyo/file.c
104583 +++ b/security/tomoyo/file.c
104584 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
104585 {
104586 struct tomoyo_request_info r;
104587 struct tomoyo_obj_info obj = {
104588 - .path1 = *path,
104589 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104590 };
104591 int error = -ENOMEM;
104592 struct tomoyo_path_info buf;
104593 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
104594 struct tomoyo_path_info buf;
104595 struct tomoyo_request_info r;
104596 struct tomoyo_obj_info obj = {
104597 - .path1 = *path,
104598 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104599 };
104600 int idx;
104601
104602 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
104603 {
104604 struct tomoyo_request_info r;
104605 struct tomoyo_obj_info obj = {
104606 - .path1 = *path,
104607 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104608 };
104609 int error;
104610 struct tomoyo_path_info buf;
104611 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
104612 {
104613 struct tomoyo_request_info r;
104614 struct tomoyo_obj_info obj = {
104615 - .path1 = *path,
104616 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104617 };
104618 int error = -ENOMEM;
104619 struct tomoyo_path_info buf;
104620 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
104621 struct tomoyo_path_info buf2;
104622 struct tomoyo_request_info r;
104623 struct tomoyo_obj_info obj = {
104624 - .path1 = *path1,
104625 - .path2 = *path2,
104626 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
104627 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
104628 };
104629 int idx;
104630
104631 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
104632 index 390c646..f2f8db3 100644
104633 --- a/security/tomoyo/mount.c
104634 +++ b/security/tomoyo/mount.c
104635 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
104636 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
104637 need_dev = -1; /* dev_name is a directory */
104638 } else {
104639 + if (!capable(CAP_SYS_ADMIN)) {
104640 + error = -EPERM;
104641 + goto out;
104642 + }
104643 fstype = get_fs_type(type);
104644 if (!fstype) {
104645 error = -ENODEV;
104646 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
104647 index f0b756e..8aa497b 100644
104648 --- a/security/tomoyo/tomoyo.c
104649 +++ b/security/tomoyo/tomoyo.c
104650 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
104651 */
104652 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
104653 {
104654 - struct path path = { mnt, dentry };
104655 + struct path path = { .mnt = mnt, .dentry = dentry };
104656 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
104657 }
104658
104659 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
104660 */
104661 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104662 {
104663 - struct path path = { parent->mnt, dentry };
104664 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104665 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
104666 }
104667
104668 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104669 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104670 umode_t mode)
104671 {
104672 - struct path path = { parent->mnt, dentry };
104673 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104674 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
104675 mode & S_IALLUGO);
104676 }
104677 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104678 */
104679 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104680 {
104681 - struct path path = { parent->mnt, dentry };
104682 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104683 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
104684 }
104685
104686 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104687 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104688 const char *old_name)
104689 {
104690 - struct path path = { parent->mnt, dentry };
104691 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104692 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
104693 }
104694
104695 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104696 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104697 umode_t mode, unsigned int dev)
104698 {
104699 - struct path path = { parent->mnt, dentry };
104700 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104701 int type = TOMOYO_TYPE_CREATE;
104702 const unsigned int perm = mode & S_IALLUGO;
104703
104704 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104705 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
104706 struct dentry *new_dentry)
104707 {
104708 - struct path path1 = { new_dir->mnt, old_dentry };
104709 - struct path path2 = { new_dir->mnt, new_dentry };
104710 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
104711 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
104712 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
104713 }
104714
104715 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
104716 struct path *new_parent,
104717 struct dentry *new_dentry)
104718 {
104719 - struct path path1 = { old_parent->mnt, old_dentry };
104720 - struct path path2 = { new_parent->mnt, new_dentry };
104721 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
104722 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
104723 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
104724 }
104725
104726 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
104727 */
104728 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
104729 {
104730 - struct path path = { mnt, mnt->mnt_root };
104731 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
104732 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
104733 }
104734
104735 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
104736 * tomoyo_security_ops is a "struct security_operations" which is used for
104737 * registering TOMOYO.
104738 */
104739 -static struct security_operations tomoyo_security_ops = {
104740 +static struct security_operations tomoyo_security_ops __read_only = {
104741 .name = "tomoyo",
104742 .cred_alloc_blank = tomoyo_cred_alloc_blank,
104743 .cred_prepare = tomoyo_cred_prepare,
104744 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
104745 index 20ef514..4182bed 100644
104746 --- a/security/yama/Kconfig
104747 +++ b/security/yama/Kconfig
104748 @@ -1,6 +1,6 @@
104749 config SECURITY_YAMA
104750 bool "Yama support"
104751 - depends on SECURITY
104752 + depends on SECURITY && !GRKERNSEC
104753 select SECURITYFS
104754 select SECURITY_PATH
104755 default n
104756 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
104757 index 13c88fbc..f8c115e 100644
104758 --- a/security/yama/yama_lsm.c
104759 +++ b/security/yama/yama_lsm.c
104760 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
104761 }
104762
104763 #ifndef CONFIG_SECURITY_YAMA_STACKED
104764 -static struct security_operations yama_ops = {
104765 +static struct security_operations yama_ops __read_only = {
104766 .name = "yama",
104767
104768 .ptrace_access_check = yama_ptrace_access_check,
104769 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
104770 #endif
104771
104772 #ifdef CONFIG_SYSCTL
104773 +static int zero __read_only;
104774 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
104775 +
104776 static int yama_dointvec_minmax(struct ctl_table *table, int write,
104777 void __user *buffer, size_t *lenp, loff_t *ppos)
104778 {
104779 - int rc;
104780 + ctl_table_no_const yama_table;
104781
104782 if (write && !capable(CAP_SYS_PTRACE))
104783 return -EPERM;
104784
104785 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
104786 - if (rc)
104787 - return rc;
104788 -
104789 + yama_table = *table;
104790 /* Lock the max value if it ever gets set. */
104791 - if (write && *(int *)table->data == *(int *)table->extra2)
104792 - table->extra1 = table->extra2;
104793 -
104794 - return rc;
104795 + if (ptrace_scope == max_scope)
104796 + yama_table.extra1 = &max_scope;
104797 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
104798 }
104799
104800 -static int zero;
104801 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
104802 -
104803 struct ctl_path yama_sysctl_path[] = {
104804 { .procname = "kernel", },
104805 { .procname = "yama", },
104806 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
104807 index 4cedc69..e59d8a3 100644
104808 --- a/sound/aoa/codecs/onyx.c
104809 +++ b/sound/aoa/codecs/onyx.c
104810 @@ -54,7 +54,7 @@ struct onyx {
104811 spdif_locked:1,
104812 analog_locked:1,
104813 original_mute:2;
104814 - int open_count;
104815 + local_t open_count;
104816 struct codec_info *codec_info;
104817
104818 /* mutex serializes concurrent access to the device
104819 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
104820 struct onyx *onyx = cii->codec_data;
104821
104822 mutex_lock(&onyx->mutex);
104823 - onyx->open_count++;
104824 + local_inc(&onyx->open_count);
104825 mutex_unlock(&onyx->mutex);
104826
104827 return 0;
104828 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
104829 struct onyx *onyx = cii->codec_data;
104830
104831 mutex_lock(&onyx->mutex);
104832 - onyx->open_count--;
104833 - if (!onyx->open_count)
104834 + if (local_dec_and_test(&onyx->open_count))
104835 onyx->spdif_locked = onyx->analog_locked = 0;
104836 mutex_unlock(&onyx->mutex);
104837
104838 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
104839 index ffd2025..df062c9 100644
104840 --- a/sound/aoa/codecs/onyx.h
104841 +++ b/sound/aoa/codecs/onyx.h
104842 @@ -11,6 +11,7 @@
104843 #include <linux/i2c.h>
104844 #include <asm/pmac_low_i2c.h>
104845 #include <asm/prom.h>
104846 +#include <asm/local.h>
104847
104848 /* PCM3052 register definitions */
104849
104850 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
104851 index 4c1cc51..16040040 100644
104852 --- a/sound/core/oss/pcm_oss.c
104853 +++ b/sound/core/oss/pcm_oss.c
104854 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
104855 if (in_kernel) {
104856 mm_segment_t fs;
104857 fs = snd_enter_user();
104858 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104859 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104860 snd_leave_user(fs);
104861 } else {
104862 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104863 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104864 }
104865 if (ret != -EPIPE && ret != -ESTRPIPE)
104866 break;
104867 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
104868 if (in_kernel) {
104869 mm_segment_t fs;
104870 fs = snd_enter_user();
104871 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104872 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104873 snd_leave_user(fs);
104874 } else {
104875 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104876 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104877 }
104878 if (ret == -EPIPE) {
104879 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
104880 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
104881 struct snd_pcm_plugin_channel *channels;
104882 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
104883 if (!in_kernel) {
104884 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
104885 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
104886 return -EFAULT;
104887 buf = runtime->oss.buffer;
104888 }
104889 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
104890 }
104891 } else {
104892 tmp = snd_pcm_oss_write2(substream,
104893 - (const char __force *)buf,
104894 + (const char __force_kernel *)buf,
104895 runtime->oss.period_bytes, 0);
104896 if (tmp <= 0)
104897 goto err;
104898 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
104899 struct snd_pcm_runtime *runtime = substream->runtime;
104900 snd_pcm_sframes_t frames, frames1;
104901 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
104902 - char __user *final_dst = (char __force __user *)buf;
104903 + char __user *final_dst = (char __force_user *)buf;
104904 if (runtime->oss.plugin_first) {
104905 struct snd_pcm_plugin_channel *channels;
104906 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
104907 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
104908 xfer += tmp;
104909 runtime->oss.buffer_used -= tmp;
104910 } else {
104911 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
104912 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
104913 runtime->oss.period_bytes, 0);
104914 if (tmp <= 0)
104915 goto err;
104916 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
104917 size1);
104918 size1 /= runtime->channels; /* frames */
104919 fs = snd_enter_user();
104920 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
104921 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
104922 snd_leave_user(fs);
104923 }
104924 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
104925 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
104926 index af49721..e85058e 100644
104927 --- a/sound/core/pcm_compat.c
104928 +++ b/sound/core/pcm_compat.c
104929 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
104930 int err;
104931
104932 fs = snd_enter_user();
104933 - err = snd_pcm_delay(substream, &delay);
104934 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
104935 snd_leave_user(fs);
104936 if (err < 0)
104937 return err;
104938 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
104939 index 01a5e05..c6bb425 100644
104940 --- a/sound/core/pcm_native.c
104941 +++ b/sound/core/pcm_native.c
104942 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
104943 switch (substream->stream) {
104944 case SNDRV_PCM_STREAM_PLAYBACK:
104945 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
104946 - (void __user *)arg);
104947 + (void __force_user *)arg);
104948 break;
104949 case SNDRV_PCM_STREAM_CAPTURE:
104950 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
104951 - (void __user *)arg);
104952 + (void __force_user *)arg);
104953 break;
104954 default:
104955 result = -EINVAL;
104956 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
104957 index 8d4d5e8..fdd0826 100644
104958 --- a/sound/core/seq/oss/seq_oss.c
104959 +++ b/sound/core/seq/oss/seq_oss.c
104960 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
104961 {
104962 int rc;
104963 static struct snd_seq_dev_ops ops = {
104964 - snd_seq_oss_synth_register,
104965 - snd_seq_oss_synth_unregister,
104966 + .init_device = snd_seq_oss_synth_register,
104967 + .free_device = snd_seq_oss_synth_unregister,
104968 };
104969
104970 snd_seq_autoload_lock();
104971 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
104972 index 040c60e..989a19a 100644
104973 --- a/sound/core/seq/seq_device.c
104974 +++ b/sound/core/seq/seq_device.c
104975 @@ -64,7 +64,7 @@ struct ops_list {
104976 int argsize; /* argument size */
104977
104978 /* operators */
104979 - struct snd_seq_dev_ops ops;
104980 + struct snd_seq_dev_ops *ops;
104981
104982 /* registered devices */
104983 struct list_head dev_list; /* list of devices */
104984 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
104985
104986 mutex_lock(&ops->reg_mutex);
104987 /* copy driver operators */
104988 - ops->ops = *entry;
104989 + ops->ops = entry;
104990 ops->driver |= DRIVER_LOADED;
104991 ops->argsize = argsize;
104992
104993 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
104994 dev->name, ops->id, ops->argsize, dev->argsize);
104995 return -EINVAL;
104996 }
104997 - if (ops->ops.init_device(dev) >= 0) {
104998 + if (ops->ops->init_device(dev) >= 0) {
104999 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
105000 ops->num_init_devices++;
105001 } else {
105002 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
105003 dev->name, ops->id, ops->argsize, dev->argsize);
105004 return -EINVAL;
105005 }
105006 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
105007 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
105008 dev->status = SNDRV_SEQ_DEVICE_FREE;
105009 dev->driver_data = NULL;
105010 ops->num_init_devices--;
105011 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
105012 index 64069db..3c6d392 100644
105013 --- a/sound/core/seq/seq_midi.c
105014 +++ b/sound/core/seq/seq_midi.c
105015 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
105016 static int __init alsa_seq_midi_init(void)
105017 {
105018 static struct snd_seq_dev_ops ops = {
105019 - snd_seq_midisynth_register_port,
105020 - snd_seq_midisynth_unregister_port,
105021 + .init_device = snd_seq_midisynth_register_port,
105022 + .free_device = snd_seq_midisynth_unregister_port,
105023 };
105024 memset(&synths, 0, sizeof(synths));
105025 snd_seq_autoload_lock();
105026 diff --git a/sound/core/sound.c b/sound/core/sound.c
105027 index 437c25e..cd040ab 100644
105028 --- a/sound/core/sound.c
105029 +++ b/sound/core/sound.c
105030 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
105031 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
105032 default: return;
105033 }
105034 - request_module(str);
105035 + request_module("%s", str);
105036 }
105037
105038 #endif /* modular kernel */
105039 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
105040 index 4e0dd22..7a1f32c 100644
105041 --- a/sound/drivers/mts64.c
105042 +++ b/sound/drivers/mts64.c
105043 @@ -29,6 +29,7 @@
105044 #include <sound/initval.h>
105045 #include <sound/rawmidi.h>
105046 #include <sound/control.h>
105047 +#include <asm/local.h>
105048
105049 #define CARD_NAME "Miditerminal 4140"
105050 #define DRIVER_NAME "MTS64"
105051 @@ -67,7 +68,7 @@ struct mts64 {
105052 struct pardevice *pardev;
105053 int pardev_claimed;
105054
105055 - int open_count;
105056 + local_t open_count;
105057 int current_midi_output_port;
105058 int current_midi_input_port;
105059 u8 mode[MTS64_NUM_INPUT_PORTS];
105060 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
105061 {
105062 struct mts64 *mts = substream->rmidi->private_data;
105063
105064 - if (mts->open_count == 0) {
105065 + if (local_read(&mts->open_count) == 0) {
105066 /* We don't need a spinlock here, because this is just called
105067 if the device has not been opened before.
105068 So there aren't any IRQs from the device */
105069 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
105070
105071 msleep(50);
105072 }
105073 - ++(mts->open_count);
105074 + local_inc(&mts->open_count);
105075
105076 return 0;
105077 }
105078 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
105079 struct mts64 *mts = substream->rmidi->private_data;
105080 unsigned long flags;
105081
105082 - --(mts->open_count);
105083 - if (mts->open_count == 0) {
105084 + if (local_dec_return(&mts->open_count) == 0) {
105085 /* We need the spinlock_irqsave here because we can still
105086 have IRQs at this point */
105087 spin_lock_irqsave(&mts->lock, flags);
105088 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
105089
105090 msleep(500);
105091
105092 - } else if (mts->open_count < 0)
105093 - mts->open_count = 0;
105094 + } else if (local_read(&mts->open_count) < 0)
105095 + local_set(&mts->open_count, 0);
105096
105097 return 0;
105098 }
105099 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
105100 index 6839953..7a0f4b9 100644
105101 --- a/sound/drivers/opl3/opl3_seq.c
105102 +++ b/sound/drivers/opl3/opl3_seq.c
105103 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
105104 {
105105 static struct snd_seq_dev_ops ops =
105106 {
105107 - snd_opl3_seq_new_device,
105108 - snd_opl3_seq_delete_device
105109 + .init_device = snd_opl3_seq_new_device,
105110 + .free_device = snd_opl3_seq_delete_device
105111 };
105112
105113 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
105114 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
105115 index b953fb4..1999c01 100644
105116 --- a/sound/drivers/opl4/opl4_lib.c
105117 +++ b/sound/drivers/opl4/opl4_lib.c
105118 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
105119 MODULE_DESCRIPTION("OPL4 driver");
105120 MODULE_LICENSE("GPL");
105121
105122 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
105123 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
105124 {
105125 int timeout = 10;
105126 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
105127 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
105128 index 9919769..d7de36c 100644
105129 --- a/sound/drivers/opl4/opl4_seq.c
105130 +++ b/sound/drivers/opl4/opl4_seq.c
105131 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
105132 static int __init alsa_opl4_synth_init(void)
105133 {
105134 static struct snd_seq_dev_ops ops = {
105135 - snd_opl4_seq_new_device,
105136 - snd_opl4_seq_delete_device
105137 + .init_device = snd_opl4_seq_new_device,
105138 + .free_device = snd_opl4_seq_delete_device
105139 };
105140
105141 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
105142 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
105143 index 991018d..8984740 100644
105144 --- a/sound/drivers/portman2x4.c
105145 +++ b/sound/drivers/portman2x4.c
105146 @@ -48,6 +48,7 @@
105147 #include <sound/initval.h>
105148 #include <sound/rawmidi.h>
105149 #include <sound/control.h>
105150 +#include <asm/local.h>
105151
105152 #define CARD_NAME "Portman 2x4"
105153 #define DRIVER_NAME "portman"
105154 @@ -85,7 +86,7 @@ struct portman {
105155 struct pardevice *pardev;
105156 int pardev_claimed;
105157
105158 - int open_count;
105159 + local_t open_count;
105160 int mode[PORTMAN_NUM_INPUT_PORTS];
105161 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
105162 };
105163 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
105164 index 9048777..2d8b1fc 100644
105165 --- a/sound/firewire/amdtp.c
105166 +++ b/sound/firewire/amdtp.c
105167 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
105168 ptr = s->pcm_buffer_pointer + data_blocks;
105169 if (ptr >= pcm->runtime->buffer_size)
105170 ptr -= pcm->runtime->buffer_size;
105171 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
105172 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
105173
105174 s->pcm_period_pointer += data_blocks;
105175 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
105176 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
105177 */
105178 void amdtp_out_stream_update(struct amdtp_out_stream *s)
105179 {
105180 - ACCESS_ONCE(s->source_node_id_field) =
105181 + ACCESS_ONCE_RW(s->source_node_id_field) =
105182 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
105183 }
105184 EXPORT_SYMBOL(amdtp_out_stream_update);
105185 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
105186 index 2746ecd..c35dedd 100644
105187 --- a/sound/firewire/amdtp.h
105188 +++ b/sound/firewire/amdtp.h
105189 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
105190 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
105191 struct snd_pcm_substream *pcm)
105192 {
105193 - ACCESS_ONCE(s->pcm) = pcm;
105194 + ACCESS_ONCE_RW(s->pcm) = pcm;
105195 }
105196
105197 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
105198 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
105199 index fd42e6b..c041971 100644
105200 --- a/sound/firewire/isight.c
105201 +++ b/sound/firewire/isight.c
105202 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
105203 ptr += count;
105204 if (ptr >= runtime->buffer_size)
105205 ptr -= runtime->buffer_size;
105206 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
105207 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
105208
105209 isight->period_counter += count;
105210 if (isight->period_counter >= runtime->period_size) {
105211 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
105212 if (err < 0)
105213 return err;
105214
105215 - ACCESS_ONCE(isight->pcm_active) = true;
105216 + ACCESS_ONCE_RW(isight->pcm_active) = true;
105217
105218 return 0;
105219 }
105220 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
105221 {
105222 struct isight *isight = substream->private_data;
105223
105224 - ACCESS_ONCE(isight->pcm_active) = false;
105225 + ACCESS_ONCE_RW(isight->pcm_active) = false;
105226
105227 mutex_lock(&isight->mutex);
105228 isight_stop_streaming(isight);
105229 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
105230
105231 switch (cmd) {
105232 case SNDRV_PCM_TRIGGER_START:
105233 - ACCESS_ONCE(isight->pcm_running) = true;
105234 + ACCESS_ONCE_RW(isight->pcm_running) = true;
105235 break;
105236 case SNDRV_PCM_TRIGGER_STOP:
105237 - ACCESS_ONCE(isight->pcm_running) = false;
105238 + ACCESS_ONCE_RW(isight->pcm_running) = false;
105239 break;
105240 default:
105241 return -EINVAL;
105242 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
105243 index 858023c..83b3d3c 100644
105244 --- a/sound/firewire/scs1x.c
105245 +++ b/sound/firewire/scs1x.c
105246 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
105247 {
105248 struct scs *scs = stream->rmidi->private_data;
105249
105250 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
105251 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
105252 if (up) {
105253 scs->output_idle = false;
105254 tasklet_schedule(&scs->tasklet);
105255 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
105256 {
105257 struct scs *scs = stream->rmidi->private_data;
105258
105259 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
105260 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
105261 }
105262
105263 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
105264 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
105265
105266 snd_card_disconnect(scs->card);
105267
105268 - ACCESS_ONCE(scs->output) = NULL;
105269 - ACCESS_ONCE(scs->input) = NULL;
105270 + ACCESS_ONCE_RW(scs->output) = NULL;
105271 + ACCESS_ONCE_RW(scs->input) = NULL;
105272
105273 wait_event(scs->idle_wait, scs->output_idle);
105274
105275 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
105276 index 4e3fcfb..ab45a9d 100644
105277 --- a/sound/isa/sb/emu8000_synth.c
105278 +++ b/sound/isa/sb/emu8000_synth.c
105279 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
105280 {
105281
105282 static struct snd_seq_dev_ops ops = {
105283 - snd_emu8000_new_device,
105284 - snd_emu8000_delete_device,
105285 + .init_device = snd_emu8000_new_device,
105286 + .free_device = snd_emu8000_delete_device,
105287 };
105288 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
105289 sizeof(struct snd_emu8000*));
105290 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
105291 index 048439a..3be9f6f 100644
105292 --- a/sound/oss/sb_audio.c
105293 +++ b/sound/oss/sb_audio.c
105294 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
105295 buf16 = (signed short *)(localbuf + localoffs);
105296 while (c)
105297 {
105298 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
105299 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
105300 if (copy_from_user(lbuf8,
105301 userbuf+useroffs + p,
105302 locallen))
105303 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
105304 index 7d8803a..559f8d0 100644
105305 --- a/sound/oss/swarm_cs4297a.c
105306 +++ b/sound/oss/swarm_cs4297a.c
105307 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
105308 {
105309 struct cs4297a_state *s;
105310 u32 pwr, id;
105311 - mm_segment_t fs;
105312 int rval;
105313 #ifndef CONFIG_BCM_CS4297A_CSWARM
105314 u64 cfg;
105315 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
105316 if (!rval) {
105317 char *sb1250_duart_present;
105318
105319 +#if 0
105320 + mm_segment_t fs;
105321 fs = get_fs();
105322 set_fs(KERNEL_DS);
105323 -#if 0
105324 val = SOUND_MASK_LINE;
105325 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
105326 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
105327 val = initvol[i].vol;
105328 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
105329 }
105330 + set_fs(fs);
105331 // cs4297a_write_ac97(s, 0x18, 0x0808);
105332 #else
105333 // cs4297a_write_ac97(s, 0x5e, 0x180);
105334 cs4297a_write_ac97(s, 0x02, 0x0808);
105335 cs4297a_write_ac97(s, 0x18, 0x0808);
105336 #endif
105337 - set_fs(fs);
105338
105339 list_add(&s->list, &cs4297a_devs);
105340
105341 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
105342 index 4c41c90..37f3631 100644
105343 --- a/sound/pci/emu10k1/emu10k1_synth.c
105344 +++ b/sound/pci/emu10k1/emu10k1_synth.c
105345 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
105346 {
105347
105348 static struct snd_seq_dev_ops ops = {
105349 - snd_emu10k1_synth_new_device,
105350 - snd_emu10k1_synth_delete_device,
105351 + .init_device = snd_emu10k1_synth_new_device,
105352 + .free_device = snd_emu10k1_synth_delete_device,
105353 };
105354 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
105355 sizeof(struct snd_emu10k1_synth_arg));
105356 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
105357 index 69178c4..4493d52 100644
105358 --- a/sound/pci/hda/hda_codec.c
105359 +++ b/sound/pci/hda/hda_codec.c
105360 @@ -976,14 +976,10 @@ find_codec_preset(struct hda_codec *codec)
105361 mutex_unlock(&preset_mutex);
105362
105363 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
105364 - char name[32];
105365 if (!mod_requested)
105366 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
105367 - codec->vendor_id);
105368 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
105369 else
105370 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
105371 - (codec->vendor_id >> 16) & 0xffff);
105372 - request_module(name);
105373 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
105374 mod_requested++;
105375 goto again;
105376 }
105377 @@ -2668,7 +2664,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
105378 /* FIXME: set_fs() hack for obtaining user-space TLV data */
105379 mm_segment_t fs = get_fs();
105380 set_fs(get_ds());
105381 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
105382 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
105383 tlv = _tlv;
105384 set_fs(fs);
105385 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
105386 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
105387 index 4631a23..001ae57 100644
105388 --- a/sound/pci/ymfpci/ymfpci.h
105389 +++ b/sound/pci/ymfpci/ymfpci.h
105390 @@ -358,7 +358,7 @@ struct snd_ymfpci {
105391 spinlock_t reg_lock;
105392 spinlock_t voice_lock;
105393 wait_queue_head_t interrupt_sleep;
105394 - atomic_t interrupt_sleep_count;
105395 + atomic_unchecked_t interrupt_sleep_count;
105396 struct snd_info_entry *proc_entry;
105397 const struct firmware *dsp_microcode;
105398 const struct firmware *controller_microcode;
105399 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
105400 index d591c15..8cb8f94 100644
105401 --- a/sound/pci/ymfpci/ymfpci_main.c
105402 +++ b/sound/pci/ymfpci/ymfpci_main.c
105403 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
105404 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
105405 break;
105406 }
105407 - if (atomic_read(&chip->interrupt_sleep_count)) {
105408 - atomic_set(&chip->interrupt_sleep_count, 0);
105409 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
105410 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105411 wake_up(&chip->interrupt_sleep);
105412 }
105413 __end:
105414 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
105415 continue;
105416 init_waitqueue_entry(&wait, current);
105417 add_wait_queue(&chip->interrupt_sleep, &wait);
105418 - atomic_inc(&chip->interrupt_sleep_count);
105419 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
105420 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
105421 remove_wait_queue(&chip->interrupt_sleep, &wait);
105422 }
105423 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
105424 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
105425 spin_unlock(&chip->reg_lock);
105426
105427 - if (atomic_read(&chip->interrupt_sleep_count)) {
105428 - atomic_set(&chip->interrupt_sleep_count, 0);
105429 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
105430 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105431 wake_up(&chip->interrupt_sleep);
105432 }
105433 }
105434 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
105435 spin_lock_init(&chip->reg_lock);
105436 spin_lock_init(&chip->voice_lock);
105437 init_waitqueue_head(&chip->interrupt_sleep);
105438 - atomic_set(&chip->interrupt_sleep_count, 0);
105439 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105440 chip->card = card;
105441 chip->pci = pci;
105442 chip->irq = -1;
105443 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
105444 index 35e2773..6d6ceee 100644
105445 --- a/sound/soc/fsl/fsl_ssi.c
105446 +++ b/sound/soc/fsl/fsl_ssi.c
105447 @@ -857,7 +857,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
105448 {
105449 struct fsl_ssi_private *ssi_private;
105450 int ret = 0;
105451 - struct device_attribute *dev_attr = NULL;
105452 + device_attribute_no_const *dev_attr = NULL;
105453 struct device_node *np = pdev->dev.of_node;
105454 const char *p, *sprop;
105455 const uint32_t *iprop;
105456 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
105457 index a66783e..ed1d791 100644
105458 --- a/sound/soc/soc-core.c
105459 +++ b/sound/soc/soc-core.c
105460 @@ -2253,8 +2253,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
105461 if (ret)
105462 return ret;
105463
105464 - ops->warm_reset = snd_soc_ac97_warm_reset;
105465 - ops->reset = snd_soc_ac97_reset;
105466 + pax_open_kernel();
105467 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
105468 + *(void **)&ops->reset = snd_soc_ac97_reset;
105469 + pax_close_kernel();
105470
105471 snd_ac97_rst_cfg = cfg;
105472 return 0;
105473 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
105474 index 7778b8e..3d619fc 100644
105475 --- a/sound/synth/emux/emux_seq.c
105476 +++ b/sound/synth/emux/emux_seq.c
105477 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
105478 * MIDI emulation operators
105479 */
105480 static struct snd_midi_op emux_ops = {
105481 - snd_emux_note_on,
105482 - snd_emux_note_off,
105483 - snd_emux_key_press,
105484 - snd_emux_terminate_note,
105485 - snd_emux_control,
105486 - snd_emux_nrpn,
105487 - snd_emux_sysex,
105488 + .note_on = snd_emux_note_on,
105489 + .note_off = snd_emux_note_off,
105490 + .key_press = snd_emux_key_press,
105491 + .note_terminate = snd_emux_terminate_note,
105492 + .control = snd_emux_control,
105493 + .nrpn = snd_emux_nrpn,
105494 + .sysex = snd_emux_sysex,
105495 };
105496
105497
105498 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
105499 new file mode 100644
105500 index 0000000..4c2c45c
105501 --- /dev/null
105502 +++ b/tools/gcc/.gitignore
105503 @@ -0,0 +1,2 @@
105504 +randomize_layout_seed.h
105505 +size_overflow_hash.h
105506 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
105507 new file mode 100644
105508 index 0000000..d25d472
105509 --- /dev/null
105510 +++ b/tools/gcc/Makefile
105511 @@ -0,0 +1,60 @@
105512 +#CC := gcc
105513 +#PLUGIN_SOURCE_FILES := pax_plugin.c
105514 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
105515 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
105516 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
105517 +
105518 +ifeq ($(PLUGINCC),$(HOSTCC))
105519 +HOSTLIBS := hostlibs
105520 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
105521 +else
105522 +HOSTLIBS := hostcxxlibs
105523 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing
105524 +endif
105525 +
105526 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
105527 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
105528 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
105529 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
105530 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
105531 +$(HOSTLIBS)-y += colorize_plugin.so
105532 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
105533 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
105534 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
105535 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
105536 +
105537 +always := $($(HOSTLIBS)-y)
105538 +
105539 +constify_plugin-objs := constify_plugin.o
105540 +stackleak_plugin-objs := stackleak_plugin.o
105541 +kallocstat_plugin-objs := kallocstat_plugin.o
105542 +kernexec_plugin-objs := kernexec_plugin.o
105543 +checker_plugin-objs := checker_plugin.o
105544 +colorize_plugin-objs := colorize_plugin.o
105545 +size_overflow_plugin-objs := size_overflow_plugin.o
105546 +latent_entropy_plugin-objs := latent_entropy_plugin.o
105547 +structleak_plugin-objs := structleak_plugin.o
105548 +randomize_layout_plugin-objs := randomize_layout_plugin.o
105549 +
105550 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
105551 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
105552 +
105553 +quiet_cmd_build_size_overflow_hash = GENHASH $@
105554 + cmd_build_size_overflow_hash = \
105555 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
105556 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
105557 + $(call if_changed,build_size_overflow_hash)
105558 +
105559 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
105560 + cmd_build_size_overflow_hash_aux = \
105561 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
105562 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
105563 + $(call if_changed,build_size_overflow_hash_aux)
105564 +
105565 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
105566 + cmd_create_randomize_layout_seed = \
105567 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
105568 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
105569 + $(call if_changed,create_randomize_layout_seed)
105570 +
105571 +targets += size_overflow_hash.h size_overflow_hash_aux.h randomize_layout_seed.h randomize_layout_hash.h
105572 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
105573 new file mode 100644
105574 index 0000000..5452feea
105575 --- /dev/null
105576 +++ b/tools/gcc/checker_plugin.c
105577 @@ -0,0 +1,150 @@
105578 +/*
105579 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105580 + * Licensed under the GPL v2
105581 + *
105582 + * Note: the choice of the license means that the compilation process is
105583 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105584 + * but for the kernel it doesn't matter since it doesn't link against
105585 + * any of the gcc libraries
105586 + *
105587 + * gcc plugin to implement various sparse (source code checker) features
105588 + *
105589 + * TODO:
105590 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
105591 + *
105592 + * BUGS:
105593 + * - none known
105594 + */
105595 +
105596 +#include "gcc-common.h"
105597 +
105598 +extern void c_register_addr_space (const char *str, addr_space_t as);
105599 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
105600 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
105601 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
105602 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
105603 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
105604 +
105605 +int plugin_is_GPL_compatible;
105606 +
105607 +static struct plugin_info checker_plugin_info = {
105608 + .version = "201304082245",
105609 + .help = NULL,
105610 +};
105611 +
105612 +#define ADDR_SPACE_KERNEL 0
105613 +#define ADDR_SPACE_FORCE_KERNEL 1
105614 +#define ADDR_SPACE_USER 2
105615 +#define ADDR_SPACE_FORCE_USER 3
105616 +#define ADDR_SPACE_IOMEM 0
105617 +#define ADDR_SPACE_FORCE_IOMEM 0
105618 +#define ADDR_SPACE_PERCPU 0
105619 +#define ADDR_SPACE_FORCE_PERCPU 0
105620 +#define ADDR_SPACE_RCU 0
105621 +#define ADDR_SPACE_FORCE_RCU 0
105622 +
105623 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
105624 +{
105625 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
105626 +}
105627 +
105628 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
105629 +{
105630 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
105631 +}
105632 +
105633 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
105634 +{
105635 + return default_addr_space_valid_pointer_mode(mode, as);
105636 +}
105637 +
105638 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
105639 +{
105640 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
105641 +}
105642 +
105643 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
105644 +{
105645 + return default_addr_space_legitimize_address(x, oldx, mode, as);
105646 +}
105647 +
105648 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
105649 +{
105650 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
105651 + return true;
105652 +
105653 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
105654 + return true;
105655 +
105656 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
105657 + return true;
105658 +
105659 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
105660 + return true;
105661 +
105662 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
105663 + return true;
105664 +
105665 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
105666 + return true;
105667 +
105668 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
105669 + return true;
105670 +
105671 + return subset == superset;
105672 +}
105673 +
105674 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
105675 +{
105676 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
105677 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
105678 +
105679 + return op;
105680 +}
105681 +
105682 +static void register_checker_address_spaces(void *event_data, void *data)
105683 +{
105684 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
105685 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
105686 + c_register_addr_space("__user", ADDR_SPACE_USER);
105687 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
105688 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
105689 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
105690 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
105691 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
105692 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
105693 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
105694 +
105695 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
105696 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
105697 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
105698 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
105699 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
105700 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
105701 + targetm.addr_space.convert = checker_addr_space_convert;
105702 +}
105703 +
105704 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105705 +{
105706 + const char * const plugin_name = plugin_info->base_name;
105707 + const int argc = plugin_info->argc;
105708 + const struct plugin_argument * const argv = plugin_info->argv;
105709 + int i;
105710 +
105711 + if (!plugin_default_version_check(version, &gcc_version)) {
105712 + error(G_("incompatible gcc/plugin versions"));
105713 + return 1;
105714 + }
105715 +
105716 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
105717 +
105718 + for (i = 0; i < argc; ++i)
105719 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105720 +
105721 + if (TARGET_64BIT == 0)
105722 + return 0;
105723 +
105724 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
105725 +
105726 + return 0;
105727 +}
105728 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
105729 new file mode 100644
105730 index 0000000..06dcfda
105731 --- /dev/null
105732 +++ b/tools/gcc/colorize_plugin.c
105733 @@ -0,0 +1,169 @@
105734 +/*
105735 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
105736 + * Licensed under the GPL v2
105737 + *
105738 + * Note: the choice of the license means that the compilation process is
105739 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105740 + * but for the kernel it doesn't matter since it doesn't link against
105741 + * any of the gcc libraries
105742 + *
105743 + * gcc plugin to colorize diagnostic output
105744 + *
105745 + */
105746 +
105747 +#include "gcc-common.h"
105748 +
105749 +int plugin_is_GPL_compatible;
105750 +
105751 +static struct plugin_info colorize_plugin_info = {
105752 + .version = "201401260140",
105753 + .help = NULL,
105754 +};
105755 +
105756 +#define GREEN "\033[32m\033[2m"
105757 +#define LIGHTGREEN "\033[32m\033[1m"
105758 +#define YELLOW "\033[33m\033[2m"
105759 +#define LIGHTYELLOW "\033[33m\033[1m"
105760 +#define RED "\033[31m\033[2m"
105761 +#define LIGHTRED "\033[31m\033[1m"
105762 +#define BLUE "\033[34m\033[2m"
105763 +#define LIGHTBLUE "\033[34m\033[1m"
105764 +#define BRIGHT "\033[m\033[1m"
105765 +#define NORMAL "\033[m"
105766 +
105767 +static diagnostic_starter_fn old_starter;
105768 +static diagnostic_finalizer_fn old_finalizer;
105769 +
105770 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105771 +{
105772 + const char *color;
105773 + char *newprefix;
105774 +
105775 + switch (diagnostic->kind) {
105776 + case DK_NOTE:
105777 + color = LIGHTBLUE;
105778 + break;
105779 +
105780 + case DK_PEDWARN:
105781 + case DK_WARNING:
105782 + color = LIGHTYELLOW;
105783 + break;
105784 +
105785 + case DK_ERROR:
105786 + case DK_FATAL:
105787 + case DK_ICE:
105788 + case DK_PERMERROR:
105789 + case DK_SORRY:
105790 + color = LIGHTRED;
105791 + break;
105792 +
105793 + default:
105794 + color = NORMAL;
105795 + }
105796 +
105797 + old_starter(context, diagnostic);
105798 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
105799 + return;
105800 + pp_destroy_prefix(context->printer);
105801 + pp_set_prefix(context->printer, newprefix);
105802 +}
105803 +
105804 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105805 +{
105806 + old_finalizer(context, diagnostic);
105807 +}
105808 +
105809 +static void colorize_arm(void)
105810 +{
105811 + old_starter = diagnostic_starter(global_dc);
105812 + old_finalizer = diagnostic_finalizer(global_dc);
105813 +
105814 + diagnostic_starter(global_dc) = start_colorize;
105815 + diagnostic_finalizer(global_dc) = finalize_colorize;
105816 +}
105817 +
105818 +static unsigned int execute_colorize_rearm(void)
105819 +{
105820 + if (diagnostic_starter(global_dc) == start_colorize)
105821 + return 0;
105822 +
105823 + colorize_arm();
105824 + return 0;
105825 +}
105826 +
105827 +#if BUILDING_GCC_VERSION >= 4009
105828 +static const struct pass_data colorize_rearm_pass_data = {
105829 +#else
105830 +struct simple_ipa_opt_pass colorize_rearm_pass = {
105831 + .pass = {
105832 +#endif
105833 + .type = SIMPLE_IPA_PASS,
105834 + .name = "colorize_rearm",
105835 +#if BUILDING_GCC_VERSION >= 4008
105836 + .optinfo_flags = OPTGROUP_NONE,
105837 +#endif
105838 +#if BUILDING_GCC_VERSION >= 4009
105839 + .has_gate = false,
105840 + .has_execute = true,
105841 +#else
105842 + .gate = NULL,
105843 + .execute = execute_colorize_rearm,
105844 + .sub = NULL,
105845 + .next = NULL,
105846 + .static_pass_number = 0,
105847 +#endif
105848 + .tv_id = TV_NONE,
105849 + .properties_required = 0,
105850 + .properties_provided = 0,
105851 + .properties_destroyed = 0,
105852 + .todo_flags_start = 0,
105853 + .todo_flags_finish = 0
105854 +#if BUILDING_GCC_VERSION < 4009
105855 + }
105856 +#endif
105857 +};
105858 +
105859 +#if BUILDING_GCC_VERSION >= 4009
105860 +namespace {
105861 +class colorize_rearm_pass : public simple_ipa_opt_pass {
105862 +public:
105863 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
105864 + unsigned int execute() { return execute_colorize_rearm(); }
105865 +};
105866 +}
105867 +#endif
105868 +
105869 +static struct opt_pass *make_colorize_rearm_pass(void)
105870 +{
105871 +#if BUILDING_GCC_VERSION >= 4009
105872 + return new colorize_rearm_pass();
105873 +#else
105874 + return &colorize_rearm_pass.pass;
105875 +#endif
105876 +}
105877 +
105878 +static void colorize_start_unit(void *gcc_data, void *user_data)
105879 +{
105880 + colorize_arm();
105881 +}
105882 +
105883 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105884 +{
105885 + const char * const plugin_name = plugin_info->base_name;
105886 + struct register_pass_info colorize_rearm_pass_info;
105887 +
105888 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
105889 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
105890 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
105891 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105892 +
105893 + if (!plugin_default_version_check(version, &gcc_version)) {
105894 + error(G_("incompatible gcc/plugin versions"));
105895 + return 1;
105896 + }
105897 +
105898 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
105899 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
105900 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
105901 + return 0;
105902 +}
105903 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
105904 new file mode 100644
105905 index 0000000..4f67ac1
105906 --- /dev/null
105907 +++ b/tools/gcc/constify_plugin.c
105908 @@ -0,0 +1,552 @@
105909 +/*
105910 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
105911 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
105912 + * Licensed under the GPL v2, or (at your option) v3
105913 + *
105914 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
105915 + *
105916 + * Homepage:
105917 + * http://www.grsecurity.net/~ephox/const_plugin/
105918 + *
105919 + * Usage:
105920 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
105921 + * $ gcc -fplugin=constify_plugin.so test.c -O2
105922 + */
105923 +
105924 +#include "gcc-common.h"
105925 +
105926 +// unused C type flag in all versions 4.5-4.9
105927 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
105928 +
105929 +int plugin_is_GPL_compatible;
105930 +
105931 +static struct plugin_info const_plugin_info = {
105932 + .version = "201401270210",
105933 + .help = "no-constify\tturn off constification\n",
105934 +};
105935 +
105936 +typedef struct {
105937 + bool has_fptr_field;
105938 + bool has_writable_field;
105939 + bool has_do_const_field;
105940 + bool has_no_const_field;
105941 +} constify_info;
105942 +
105943 +static const_tree get_field_type(const_tree field)
105944 +{
105945 + return strip_array_types(TREE_TYPE(field));
105946 +}
105947 +
105948 +static bool is_fptr(const_tree field)
105949 +{
105950 + const_tree ptr = get_field_type(field);
105951 +
105952 + if (TREE_CODE(ptr) != POINTER_TYPE)
105953 + return false;
105954 +
105955 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
105956 +}
105957 +
105958 +/*
105959 + * determine whether the given structure type meets the requirements for automatic constification,
105960 + * including the constification attributes on nested structure types
105961 + */
105962 +static void constifiable(const_tree node, constify_info *cinfo)
105963 +{
105964 + const_tree field;
105965 +
105966 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105967 +
105968 + // e.g., pointer to structure fields while still constructing the structure type
105969 + if (TYPE_FIELDS(node) == NULL_TREE)
105970 + return;
105971 +
105972 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
105973 + const_tree type = get_field_type(field);
105974 + enum tree_code code = TREE_CODE(type);
105975 +
105976 + if (node == type)
105977 + continue;
105978 +
105979 + if (is_fptr(field))
105980 + cinfo->has_fptr_field = true;
105981 + else if (!TREE_READONLY(field))
105982 + cinfo->has_writable_field = true;
105983 +
105984 + if (code == RECORD_TYPE || code == UNION_TYPE) {
105985 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105986 + cinfo->has_do_const_field = true;
105987 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
105988 + cinfo->has_no_const_field = true;
105989 + else
105990 + constifiable(type, cinfo);
105991 + }
105992 + }
105993 +}
105994 +
105995 +static bool constified(const_tree node)
105996 +{
105997 + constify_info cinfo = {
105998 + .has_fptr_field = false,
105999 + .has_writable_field = false,
106000 + .has_do_const_field = false,
106001 + .has_no_const_field = false
106002 + };
106003 +
106004 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
106005 +
106006 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
106007 +// gcc_assert(!TYPE_READONLY(node));
106008 + return false;
106009 + }
106010 +
106011 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
106012 + gcc_assert(TYPE_READONLY(node));
106013 + return true;
106014 + }
106015 +
106016 + constifiable(node, &cinfo);
106017 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
106018 + return false;
106019 +
106020 + return TYPE_READONLY(node);
106021 +}
106022 +
106023 +static void deconstify_tree(tree node);
106024 +
106025 +static void deconstify_type(tree type)
106026 +{
106027 + tree field;
106028 +
106029 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
106030 +
106031 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
106032 + const_tree fieldtype = get_field_type(field);
106033 +
106034 + // special case handling of simple ptr-to-same-array-type members
106035 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
106036 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
106037 +
106038 + if (TREE_TYPE(TREE_TYPE(field)) == type)
106039 + continue;
106040 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
106041 + continue;
106042 + if (!constified(ptrtype))
106043 + continue;
106044 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
106045 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
106046 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
106047 + }
106048 + continue;
106049 + }
106050 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
106051 + continue;
106052 + if (!constified(fieldtype))
106053 + continue;
106054 +
106055 + deconstify_tree(field);
106056 + TREE_READONLY(field) = 0;
106057 + }
106058 + TYPE_READONLY(type) = 0;
106059 + C_TYPE_FIELDS_READONLY(type) = 0;
106060 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
106061 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
106062 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
106063 + }
106064 +}
106065 +
106066 +static void deconstify_tree(tree node)
106067 +{
106068 + tree old_type, new_type, field;
106069 +
106070 + old_type = TREE_TYPE(node);
106071 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
106072 + node = TREE_TYPE(node) = copy_node(old_type);
106073 + old_type = TREE_TYPE(old_type);
106074 + }
106075 +
106076 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
106077 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
106078 +
106079 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
106080 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
106081 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
106082 + DECL_FIELD_CONTEXT(field) = new_type;
106083 +
106084 + deconstify_type(new_type);
106085 +
106086 + TREE_TYPE(node) = new_type;
106087 +}
106088 +
106089 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106090 +{
106091 + tree type;
106092 + constify_info cinfo = {
106093 + .has_fptr_field = false,
106094 + .has_writable_field = false,
106095 + .has_do_const_field = false,
106096 + .has_no_const_field = false
106097 + };
106098 +
106099 + *no_add_attrs = true;
106100 + if (TREE_CODE(*node) == FUNCTION_DECL) {
106101 + error("%qE attribute does not apply to functions (%qF)", name, *node);
106102 + return NULL_TREE;
106103 + }
106104 +
106105 + if (TREE_CODE(*node) == PARM_DECL) {
106106 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
106107 + return NULL_TREE;
106108 + }
106109 +
106110 + if (TREE_CODE(*node) == VAR_DECL) {
106111 + error("%qE attribute does not apply to variables (%qD)", name, *node);
106112 + return NULL_TREE;
106113 + }
106114 +
106115 + if (TYPE_P(*node)) {
106116 + type = *node;
106117 + } else {
106118 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
106119 + type = TREE_TYPE(*node);
106120 + }
106121 +
106122 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
106123 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
106124 + return NULL_TREE;
106125 + }
106126 +
106127 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
106128 + error("%qE attribute is already applied to the type %qT", name, type);
106129 + return NULL_TREE;
106130 + }
106131 +
106132 + if (TYPE_P(*node)) {
106133 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
106134 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
106135 + else
106136 + *no_add_attrs = false;
106137 + return NULL_TREE;
106138 + }
106139 +
106140 + constifiable(type, &cinfo);
106141 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
106142 + deconstify_tree(*node);
106143 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
106144 + return NULL_TREE;
106145 + }
106146 +
106147 + error("%qE attribute used on type %qT that is not constified", name, type);
106148 + return NULL_TREE;
106149 +}
106150 +
106151 +static void constify_type(tree type)
106152 +{
106153 + TYPE_READONLY(type) = 1;
106154 + C_TYPE_FIELDS_READONLY(type) = 1;
106155 + TYPE_CONSTIFY_VISITED(type) = 1;
106156 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
106157 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
106158 +}
106159 +
106160 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106161 +{
106162 + *no_add_attrs = true;
106163 + if (!TYPE_P(*node)) {
106164 + error("%qE attribute applies to types only (%qD)", name, *node);
106165 + return NULL_TREE;
106166 + }
106167 +
106168 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
106169 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
106170 + return NULL_TREE;
106171 + }
106172 +
106173 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
106174 + error("%qE attribute used on %qT is already applied to the type", name, *node);
106175 + return NULL_TREE;
106176 + }
106177 +
106178 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
106179 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
106180 + return NULL_TREE;
106181 + }
106182 +
106183 + *no_add_attrs = false;
106184 + return NULL_TREE;
106185 +}
106186 +
106187 +static struct attribute_spec no_const_attr = {
106188 + .name = "no_const",
106189 + .min_length = 0,
106190 + .max_length = 0,
106191 + .decl_required = false,
106192 + .type_required = false,
106193 + .function_type_required = false,
106194 + .handler = handle_no_const_attribute,
106195 +#if BUILDING_GCC_VERSION >= 4007
106196 + .affects_type_identity = true
106197 +#endif
106198 +};
106199 +
106200 +static struct attribute_spec do_const_attr = {
106201 + .name = "do_const",
106202 + .min_length = 0,
106203 + .max_length = 0,
106204 + .decl_required = false,
106205 + .type_required = false,
106206 + .function_type_required = false,
106207 + .handler = handle_do_const_attribute,
106208 +#if BUILDING_GCC_VERSION >= 4007
106209 + .affects_type_identity = true
106210 +#endif
106211 +};
106212 +
106213 +static void register_attributes(void *event_data, void *data)
106214 +{
106215 + register_attribute(&no_const_attr);
106216 + register_attribute(&do_const_attr);
106217 +}
106218 +
106219 +static void finish_type(void *event_data, void *data)
106220 +{
106221 + tree type = (tree)event_data;
106222 + constify_info cinfo = {
106223 + .has_fptr_field = false,
106224 + .has_writable_field = false,
106225 + .has_do_const_field = false,
106226 + .has_no_const_field = false
106227 + };
106228 +
106229 + if (type == NULL_TREE || type == error_mark_node)
106230 + return;
106231 +
106232 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
106233 + return;
106234 +
106235 + constifiable(type, &cinfo);
106236 +
106237 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
106238 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
106239 + deconstify_type(type);
106240 + TYPE_CONSTIFY_VISITED(type) = 1;
106241 + } else
106242 + error("'no_const' attribute used on type %qT that is not constified", type);
106243 + return;
106244 + }
106245 +
106246 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
106247 + if (!cinfo.has_writable_field) {
106248 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
106249 + return;
106250 + }
106251 + constify_type(type);
106252 + return;
106253 + }
106254 +
106255 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
106256 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
106257 + error("'do_const' attribute used on type %qT that is constified", type);
106258 + return;
106259 + }
106260 + constify_type(type);
106261 + return;
106262 + }
106263 +
106264 + deconstify_type(type);
106265 + TYPE_CONSTIFY_VISITED(type) = 1;
106266 +}
106267 +
106268 +static void check_global_variables(void *event_data, void *data)
106269 +{
106270 + struct varpool_node *node;
106271 +
106272 + FOR_EACH_VARIABLE(node) {
106273 + tree var = NODE_DECL(node);
106274 + tree type = TREE_TYPE(var);
106275 +
106276 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
106277 + continue;
106278 +
106279 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
106280 + continue;
106281 +
106282 + if (!TYPE_CONSTIFY_VISITED(type))
106283 + continue;
106284 +
106285 + if (DECL_EXTERNAL(var))
106286 + continue;
106287 +
106288 + if (DECL_INITIAL(var))
106289 + continue;
106290 +
106291 + // this works around a gcc bug/feature where uninitialized globals
106292 + // are moved into the .bss section regardless of any constification
106293 + DECL_INITIAL(var) = build_constructor(type, NULL);
106294 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
106295 + }
106296 +}
106297 +
106298 +static unsigned int check_local_variables(void)
106299 +{
106300 + unsigned int ret = 0;
106301 + tree var;
106302 +
106303 + unsigned int i;
106304 +
106305 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
106306 + tree type = TREE_TYPE(var);
106307 +
106308 + gcc_assert(DECL_P(var));
106309 + if (is_global_var(var))
106310 + continue;
106311 +
106312 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
106313 + continue;
106314 +
106315 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
106316 + continue;
106317 +
106318 + if (!TYPE_CONSTIFY_VISITED(type))
106319 + continue;
106320 +
106321 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
106322 + ret = 1;
106323 + }
106324 + return ret;
106325 +}
106326 +
106327 +#if BUILDING_GCC_VERSION >= 4009
106328 +static const struct pass_data check_local_variables_pass_data = {
106329 +#else
106330 +static struct gimple_opt_pass check_local_variables_pass = {
106331 + .pass = {
106332 +#endif
106333 + .type = GIMPLE_PASS,
106334 + .name = "check_local_variables",
106335 +#if BUILDING_GCC_VERSION >= 4008
106336 + .optinfo_flags = OPTGROUP_NONE,
106337 +#endif
106338 +#if BUILDING_GCC_VERSION >= 4009
106339 + .has_gate = false,
106340 + .has_execute = true,
106341 +#else
106342 + .gate = NULL,
106343 + .execute = check_local_variables,
106344 + .sub = NULL,
106345 + .next = NULL,
106346 + .static_pass_number = 0,
106347 +#endif
106348 + .tv_id = TV_NONE,
106349 + .properties_required = 0,
106350 + .properties_provided = 0,
106351 + .properties_destroyed = 0,
106352 + .todo_flags_start = 0,
106353 + .todo_flags_finish = 0
106354 +#if BUILDING_GCC_VERSION < 4009
106355 + }
106356 +#endif
106357 +};
106358 +
106359 +#if BUILDING_GCC_VERSION >= 4009
106360 +namespace {
106361 +class check_local_variables_pass : public gimple_opt_pass {
106362 +public:
106363 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
106364 + unsigned int execute() { return check_local_variables(); }
106365 +};
106366 +}
106367 +#endif
106368 +
106369 +static struct opt_pass *make_check_local_variables_pass(void)
106370 +{
106371 +#if BUILDING_GCC_VERSION >= 4009
106372 + return new check_local_variables_pass();
106373 +#else
106374 + return &check_local_variables_pass.pass;
106375 +#endif
106376 +}
106377 +
106378 +static struct {
106379 + const char *name;
106380 + const char *asm_op;
106381 +} sections[] = {
106382 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
106383 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
106384 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
106385 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
106386 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
106387 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
106388 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
106389 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
106390 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
106391 +};
106392 +
106393 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
106394 +
106395 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
106396 +{
106397 + size_t i;
106398 +
106399 + for (i = 0; i < ARRAY_SIZE(sections); i++)
106400 + if (!strcmp(sections[i].name, name))
106401 + return 0;
106402 + return old_section_type_flags(decl, name, reloc);
106403 +}
106404 +
106405 +static void constify_start_unit(void *gcc_data, void *user_data)
106406 +{
106407 +// size_t i;
106408 +
106409 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
106410 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
106411 +// sections[i].section = get_section(sections[i].name, 0, NULL);
106412 +
106413 + old_section_type_flags = targetm.section_type_flags;
106414 + targetm.section_type_flags = constify_section_type_flags;
106415 +}
106416 +
106417 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106418 +{
106419 + const char * const plugin_name = plugin_info->base_name;
106420 + const int argc = plugin_info->argc;
106421 + const struct plugin_argument * const argv = plugin_info->argv;
106422 + int i;
106423 + bool constify = true;
106424 +
106425 + struct register_pass_info check_local_variables_pass_info;
106426 +
106427 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
106428 + check_local_variables_pass_info.reference_pass_name = "ssa";
106429 + check_local_variables_pass_info.ref_pass_instance_number = 1;
106430 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
106431 +
106432 + if (!plugin_default_version_check(version, &gcc_version)) {
106433 + error(G_("incompatible gcc/plugin versions"));
106434 + return 1;
106435 + }
106436 +
106437 + for (i = 0; i < argc; ++i) {
106438 + if (!(strcmp(argv[i].key, "no-constify"))) {
106439 + constify = false;
106440 + continue;
106441 + }
106442 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106443 + }
106444 +
106445 + if (strcmp(lang_hooks.name, "GNU C")) {
106446 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
106447 + constify = false;
106448 + }
106449 +
106450 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
106451 + if (constify) {
106452 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
106453 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
106454 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
106455 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
106456 + }
106457 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106458 +
106459 + return 0;
106460 +}
106461 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
106462 new file mode 100644
106463 index 0000000..8af3693
106464 --- /dev/null
106465 +++ b/tools/gcc/gcc-common.h
106466 @@ -0,0 +1,287 @@
106467 +#ifndef GCC_COMMON_H_INCLUDED
106468 +#define GCC_COMMON_H_INCLUDED
106469 +
106470 +#include "plugin.h"
106471 +#include "bversion.h"
106472 +#include "plugin-version.h"
106473 +#include "config.h"
106474 +#include "system.h"
106475 +#include "coretypes.h"
106476 +#include "tm.h"
106477 +#include "line-map.h"
106478 +#include "input.h"
106479 +#include "tree.h"
106480 +
106481 +#include "tree-inline.h"
106482 +#include "version.h"
106483 +#include "rtl.h"
106484 +#include "tm_p.h"
106485 +#include "flags.h"
106486 +//#include "insn-attr.h"
106487 +//#include "insn-config.h"
106488 +//#include "insn-flags.h"
106489 +#include "hard-reg-set.h"
106490 +//#include "recog.h"
106491 +#include "output.h"
106492 +#include "except.h"
106493 +#include "function.h"
106494 +#include "toplev.h"
106495 +//#include "expr.h"
106496 +#include "basic-block.h"
106497 +#include "intl.h"
106498 +#include "ggc.h"
106499 +//#include "regs.h"
106500 +#include "timevar.h"
106501 +
106502 +#include "params.h"
106503 +#include "pointer-set.h"
106504 +#include "emit-rtl.h"
106505 +//#include "reload.h"
106506 +//#include "ira.h"
106507 +//#include "dwarf2asm.h"
106508 +#include "debug.h"
106509 +#include "target.h"
106510 +#include "langhooks.h"
106511 +#include "cfgloop.h"
106512 +//#include "hosthooks.h"
106513 +#include "cgraph.h"
106514 +#include "opts.h"
106515 +//#include "coverage.h"
106516 +//#include "value-prof.h"
106517 +
106518 +#if BUILDING_GCC_VERSION >= 4007
106519 +#include "tree-pretty-print.h"
106520 +#include "gimple-pretty-print.h"
106521 +#include "c-tree.h"
106522 +//#include "alloc-pool.h"
106523 +#endif
106524 +
106525 +#if BUILDING_GCC_VERSION <= 4008
106526 +#include "tree-flow.h"
106527 +#else
106528 +#include "tree-cfgcleanup.h"
106529 +#endif
106530 +
106531 +#include "diagnostic.h"
106532 +//#include "tree-diagnostic.h"
106533 +#include "tree-dump.h"
106534 +#include "tree-pass.h"
106535 +//#include "df.h"
106536 +#include "predict.h"
106537 +//#include "lto-streamer.h"
106538 +#include "ipa-utils.h"
106539 +
106540 +#if BUILDING_GCC_VERSION >= 4009
106541 +#include "varasm.h"
106542 +#include "stor-layout.h"
106543 +#include "internal-fn.h"
106544 +#include "gimple-expr.h"
106545 +//#include "diagnostic-color.h"
106546 +#include "context.h"
106547 +#include "tree-ssa-alias.h"
106548 +#include "stringpool.h"
106549 +#include "tree-ssanames.h"
106550 +#include "print-tree.h"
106551 +#include "tree-eh.h"
106552 +#endif
106553 +
106554 +#include "gimple.h"
106555 +
106556 +#if BUILDING_GCC_VERSION >= 4009
106557 +#include "tree-ssa-operands.h"
106558 +#include "tree-phinodes.h"
106559 +#include "tree-cfg.h"
106560 +#include "gimple-iterator.h"
106561 +#include "gimple-ssa.h"
106562 +#include "ssa-iterators.h"
106563 +#endif
106564 +
106565 +//#include "expr.h" where are you...
106566 +extern rtx emit_move_insn(rtx x, rtx y);
106567 +
106568 +// missing from basic_block.h...
106569 +extern void debug_dominance_info(enum cdi_direction dir);
106570 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
106571 +
106572 +#define __unused __attribute__((__unused__))
106573 +
106574 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
106575 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
106576 +
106577 +#if BUILDING_GCC_VERSION == 4005
106578 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
106579 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
106580 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
106581 +#define TODO_rebuild_cgraph_edges 0
106582 +
106583 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
106584 +{
106585 + tree fndecl;
106586 +
106587 + if (!is_gimple_call(stmt))
106588 + return false;
106589 + fndecl = gimple_call_fndecl(stmt);
106590 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
106591 + return false;
106592 +// print_node(stderr, "pax", fndecl, 4);
106593 + return DECL_FUNCTION_CODE(fndecl) == code;
106594 +}
106595 +
106596 +static inline bool is_simple_builtin(tree decl)
106597 +{
106598 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
106599 + return false;
106600 +
106601 + switch (DECL_FUNCTION_CODE(decl)) {
106602 + /* Builtins that expand to constants. */
106603 + case BUILT_IN_CONSTANT_P:
106604 + case BUILT_IN_EXPECT:
106605 + case BUILT_IN_OBJECT_SIZE:
106606 + case BUILT_IN_UNREACHABLE:
106607 + /* Simple register moves or loads from stack. */
106608 + case BUILT_IN_RETURN_ADDRESS:
106609 + case BUILT_IN_EXTRACT_RETURN_ADDR:
106610 + case BUILT_IN_FROB_RETURN_ADDR:
106611 + case BUILT_IN_RETURN:
106612 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
106613 + case BUILT_IN_FRAME_ADDRESS:
106614 + case BUILT_IN_VA_END:
106615 + case BUILT_IN_STACK_SAVE:
106616 + case BUILT_IN_STACK_RESTORE:
106617 + /* Exception state returns or moves registers around. */
106618 + case BUILT_IN_EH_FILTER:
106619 + case BUILT_IN_EH_POINTER:
106620 + case BUILT_IN_EH_COPY_VALUES:
106621 + return true;
106622 +
106623 + default:
106624 + return false;
106625 + }
106626 +}
106627 +#endif
106628 +
106629 +#if BUILDING_GCC_VERSION <= 4006
106630 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
106631 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
106632 +
106633 +// should come from c-tree.h if only it were installed for gcc 4.5...
106634 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
106635 +
106636 +#define get_random_seed(noinit) ({ \
106637 + unsigned HOST_WIDE_INT seed; \
106638 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
106639 + seed * seed; })
106640 +
106641 +static inline bool gimple_clobber_p(gimple s)
106642 +{
106643 + return false;
106644 +}
106645 +
106646 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
106647 +{
106648 + return implicit_built_in_decls[fncode];
106649 +}
106650 +
106651 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
106652 +{
106653 + struct cgraph_node *node = cgraph_get_node(decl);
106654 +
106655 + return node ? node : cgraph_node(decl);
106656 +}
106657 +
106658 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
106659 +{
106660 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
106661 +}
106662 +
106663 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
106664 +{
106665 + struct cgraph_node *node;
106666 +
106667 + for (node = cgraph_nodes; node; node = node->next)
106668 + if (cgraph_function_with_gimple_body_p(node))
106669 + return node;
106670 + return NULL;
106671 +}
106672 +
106673 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
106674 +{
106675 + for (node = node->next; node; node = node->next)
106676 + if (cgraph_function_with_gimple_body_p(node))
106677 + return node;
106678 + return NULL;
106679 +}
106680 +
106681 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
106682 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
106683 + (node) = cgraph_next_function_with_gimple_body(node))
106684 +#endif
106685 +
106686 +#if BUILDING_GCC_VERSION == 4006
106687 +extern void debug_gimple_stmt(gimple);
106688 +extern void debug_gimple_seq(gimple_seq);
106689 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
106690 +extern void print_gimple_stmt(FILE *, gimple, int, int);
106691 +extern void print_gimple_expr(FILE *, gimple, int, int);
106692 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
106693 +#endif
106694 +
106695 +#if BUILDING_GCC_VERSION <= 4007
106696 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
106697 +#define PROP_loops 0
106698 +
106699 +static inline int bb_loop_depth(const_basic_block bb)
106700 +{
106701 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
106702 +}
106703 +
106704 +static inline bool gimple_store_p(gimple gs)
106705 +{
106706 + tree lhs = gimple_get_lhs(gs);
106707 + return lhs && !is_gimple_reg(lhs);
106708 +}
106709 +#endif
106710 +
106711 +#if BUILDING_GCC_VERSION >= 4007
106712 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
106713 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
106714 +#endif
106715 +
106716 +#if BUILDING_GCC_VERSION <= 4008
106717 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
106718 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
106719 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
106720 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
106721 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
106722 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
106723 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
106724 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
106725 +
106726 +static inline const char *get_tree_code_name(enum tree_code code)
106727 +{
106728 + gcc_assert(code < MAX_TREE_CODES);
106729 + return tree_code_name[code];
106730 +}
106731 +
106732 +#define ipa_remove_stmt_references(cnode, stmt)
106733 +#endif
106734 +
106735 +#if BUILDING_GCC_VERSION == 4008
106736 +#define NODE_DECL(node) node->symbol.decl
106737 +#else
106738 +#define NODE_DECL(node) node->decl
106739 +#endif
106740 +
106741 +#if BUILDING_GCC_VERSION >= 4008
106742 +#define add_referenced_var(var)
106743 +#define mark_sym_for_renaming(var)
106744 +#define varpool_mark_needed_node(node)
106745 +#define TODO_dump_func 0
106746 +#define TODO_dump_cgraph 0
106747 +#endif
106748 +
106749 +#if BUILDING_GCC_VERSION >= 4009
106750 +#define TODO_ggc_collect 0
106751 +#endif
106752 +
106753 +#endif
106754 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
106755 new file mode 100644
106756 index 0000000..7514850
106757 --- /dev/null
106758 +++ b/tools/gcc/gen-random-seed.sh
106759 @@ -0,0 +1,8 @@
106760 +#!/bin/sh
106761 +
106762 +if [ ! -f "$1" ]; then
106763 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
106764 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
106765 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
106766 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
106767 +fi
106768 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
106769 new file mode 100644
106770 index 0000000..791ca76
106771 --- /dev/null
106772 +++ b/tools/gcc/generate_size_overflow_hash.sh
106773 @@ -0,0 +1,97 @@
106774 +#!/bin/bash
106775 +
106776 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
106777 +
106778 +header1="size_overflow_hash.h"
106779 +database="size_overflow_hash.data"
106780 +n=65536
106781 +hashtable_name="size_overflow_hash"
106782 +
106783 +usage() {
106784 +cat <<EOF
106785 +usage: $0 options
106786 +OPTIONS:
106787 + -h|--help help
106788 + -o header file
106789 + -d database file
106790 + -n hash array size
106791 + -s name of the hash table
106792 +EOF
106793 + return 0
106794 +}
106795 +
106796 +while true
106797 +do
106798 + case "$1" in
106799 + -h|--help) usage && exit 0;;
106800 + -n) n=$2; shift 2;;
106801 + -o) header1="$2"; shift 2;;
106802 + -d) database="$2"; shift 2;;
106803 + -s) hashtable_name="$2"; shift 2;;
106804 + --) shift 1; break ;;
106805 + *) break ;;
106806 + esac
106807 +done
106808 +
106809 +create_defines() {
106810 + for i in `seq 0 31`
106811 + do
106812 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
106813 + done
106814 + echo >> "$header1"
106815 +}
106816 +
106817 +create_structs() {
106818 + rm -f "$header1"
106819 +
106820 + create_defines
106821 +
106822 + cat "$database" | while read data
106823 + do
106824 + data_array=($data)
106825 + struct_hash_name="${data_array[0]}"
106826 + funcn="${data_array[1]}"
106827 + params="${data_array[2]}"
106828 + next="${data_array[4]}"
106829 +
106830 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
106831 +
106832 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
106833 + echo -en "\t.param\t= " >> "$header1"
106834 + line=
106835 + for param_num in ${params//-/ };
106836 + do
106837 + line="${line}PARAM"$param_num"|"
106838 + done
106839 +
106840 + echo -e "${line%?},\n};\n" >> "$header1"
106841 + done
106842 +}
106843 +
106844 +create_headers() {
106845 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
106846 +}
106847 +
106848 +create_array_elements() {
106849 + index=0
106850 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
106851 + do
106852 + data_array=($data)
106853 + i="${data_array[3]}"
106854 + hash="${data_array[0]}"
106855 + while [[ $index -lt $i ]]
106856 + do
106857 + echo -e "\t["$index"]\t= NULL," >> "$header1"
106858 + index=$(($index + 1))
106859 + done
106860 + index=$(($index + 1))
106861 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
106862 + done
106863 + echo '};' >> $header1
106864 +}
106865 +
106866 +create_structs
106867 +create_headers
106868 +create_array_elements
106869 +
106870 +exit 0
106871 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
106872 new file mode 100644
106873 index 0000000..b559327
106874 --- /dev/null
106875 +++ b/tools/gcc/kallocstat_plugin.c
106876 @@ -0,0 +1,182 @@
106877 +/*
106878 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106879 + * Licensed under the GPL v2
106880 + *
106881 + * Note: the choice of the license means that the compilation process is
106882 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106883 + * but for the kernel it doesn't matter since it doesn't link against
106884 + * any of the gcc libraries
106885 + *
106886 + * gcc plugin to find the distribution of k*alloc sizes
106887 + *
106888 + * TODO:
106889 + *
106890 + * BUGS:
106891 + * - none known
106892 + */
106893 +
106894 +#include "gcc-common.h"
106895 +
106896 +int plugin_is_GPL_compatible;
106897 +
106898 +static struct plugin_info kallocstat_plugin_info = {
106899 + .version = "201401260140",
106900 + .help = NULL
106901 +};
106902 +
106903 +static const char * const kalloc_functions[] = {
106904 + "__kmalloc",
106905 + "kmalloc",
106906 + "kmalloc_large",
106907 + "kmalloc_node",
106908 + "kmalloc_order",
106909 + "kmalloc_order_trace",
106910 + "kmalloc_slab",
106911 + "kzalloc",
106912 + "kzalloc_node",
106913 +};
106914 +
106915 +static bool is_kalloc(const char *fnname)
106916 +{
106917 + size_t i;
106918 +
106919 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
106920 + if (!strcmp(fnname, kalloc_functions[i]))
106921 + return true;
106922 + return false;
106923 +}
106924 +
106925 +static unsigned int execute_kallocstat(void)
106926 +{
106927 + basic_block bb;
106928 +
106929 + // 1. loop through BBs and GIMPLE statements
106930 + FOR_EACH_BB_FN(bb, cfun) {
106931 + gimple_stmt_iterator gsi;
106932 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106933 + // gimple match:
106934 + tree fndecl, size;
106935 + gimple stmt;
106936 + const char *fnname;
106937 +
106938 + // is it a call
106939 + stmt = gsi_stmt(gsi);
106940 + if (!is_gimple_call(stmt))
106941 + continue;
106942 + fndecl = gimple_call_fndecl(stmt);
106943 + if (fndecl == NULL_TREE)
106944 + continue;
106945 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
106946 + continue;
106947 +
106948 + // is it a call to k*alloc
106949 + fnname = DECL_NAME_POINTER(fndecl);
106950 + if (!is_kalloc(fnname))
106951 + continue;
106952 +
106953 + // is the size arg const or the result of a simple const assignment
106954 + size = gimple_call_arg(stmt, 0);
106955 + while (true) {
106956 + expanded_location xloc;
106957 + size_t size_val;
106958 +
106959 + if (TREE_CONSTANT(size)) {
106960 + xloc = expand_location(gimple_location(stmt));
106961 + if (!xloc.file)
106962 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
106963 + size_val = TREE_INT_CST_LOW(size);
106964 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
106965 + break;
106966 + }
106967 +
106968 + if (TREE_CODE(size) != SSA_NAME)
106969 + break;
106970 + stmt = SSA_NAME_DEF_STMT(size);
106971 +//debug_gimple_stmt(stmt);
106972 +//debug_tree(size);
106973 + if (!stmt || !is_gimple_assign(stmt))
106974 + break;
106975 + if (gimple_num_ops(stmt) != 2)
106976 + break;
106977 + size = gimple_assign_rhs1(stmt);
106978 + }
106979 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
106980 +//debug_tree(gimple_call_fn(call_stmt));
106981 +//print_node(stderr, "pax", fndecl, 4);
106982 + }
106983 + }
106984 +
106985 + return 0;
106986 +}
106987 +
106988 +#if BUILDING_GCC_VERSION >= 4009
106989 +static const struct pass_data kallocstat_pass_data = {
106990 +#else
106991 +static struct gimple_opt_pass kallocstat_pass = {
106992 + .pass = {
106993 +#endif
106994 + .type = GIMPLE_PASS,
106995 + .name = "kallocstat",
106996 +#if BUILDING_GCC_VERSION >= 4008
106997 + .optinfo_flags = OPTGROUP_NONE,
106998 +#endif
106999 +#if BUILDING_GCC_VERSION >= 4009
107000 + .has_gate = false,
107001 + .has_execute = true,
107002 +#else
107003 + .gate = NULL,
107004 + .execute = execute_kallocstat,
107005 + .sub = NULL,
107006 + .next = NULL,
107007 + .static_pass_number = 0,
107008 +#endif
107009 + .tv_id = TV_NONE,
107010 + .properties_required = 0,
107011 + .properties_provided = 0,
107012 + .properties_destroyed = 0,
107013 + .todo_flags_start = 0,
107014 + .todo_flags_finish = 0
107015 +#if BUILDING_GCC_VERSION < 4009
107016 + }
107017 +#endif
107018 +};
107019 +
107020 +#if BUILDING_GCC_VERSION >= 4009
107021 +namespace {
107022 +class kallocstat_pass : public gimple_opt_pass {
107023 +public:
107024 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
107025 + unsigned int execute() { return execute_kallocstat(); }
107026 +};
107027 +}
107028 +#endif
107029 +
107030 +static struct opt_pass *make_kallocstat_pass(void)
107031 +{
107032 +#if BUILDING_GCC_VERSION >= 4009
107033 + return new kallocstat_pass();
107034 +#else
107035 + return &kallocstat_pass.pass;
107036 +#endif
107037 +}
107038 +
107039 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107040 +{
107041 + const char * const plugin_name = plugin_info->base_name;
107042 + struct register_pass_info kallocstat_pass_info;
107043 +
107044 + kallocstat_pass_info.pass = make_kallocstat_pass();
107045 + kallocstat_pass_info.reference_pass_name = "ssa";
107046 + kallocstat_pass_info.ref_pass_instance_number = 1;
107047 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107048 +
107049 + if (!plugin_default_version_check(version, &gcc_version)) {
107050 + error(G_("incompatible gcc/plugin versions"));
107051 + return 1;
107052 + }
107053 +
107054 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
107055 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
107056 +
107057 + return 0;
107058 +}
107059 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
107060 new file mode 100644
107061 index 0000000..dd73713
107062 --- /dev/null
107063 +++ b/tools/gcc/kernexec_plugin.c
107064 @@ -0,0 +1,519 @@
107065 +/*
107066 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
107067 + * Licensed under the GPL v2
107068 + *
107069 + * Note: the choice of the license means that the compilation process is
107070 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107071 + * but for the kernel it doesn't matter since it doesn't link against
107072 + * any of the gcc libraries
107073 + *
107074 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
107075 + *
107076 + * TODO:
107077 + *
107078 + * BUGS:
107079 + * - none known
107080 + */
107081 +
107082 +#include "gcc-common.h"
107083 +
107084 +int plugin_is_GPL_compatible;
107085 +
107086 +static struct plugin_info kernexec_plugin_info = {
107087 + .version = "201401260140",
107088 + .help = "method=[bts|or]\tinstrumentation method\n"
107089 +};
107090 +
107091 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
107092 +static void (*kernexec_instrument_retaddr)(rtx);
107093 +
107094 +/*
107095 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
107096 + */
107097 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
107098 +{
107099 + gimple asm_movabs_stmt;
107100 +
107101 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
107102 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
107103 + gimple_asm_set_volatile(asm_movabs_stmt, true);
107104 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
107105 + update_stmt(asm_movabs_stmt);
107106 +}
107107 +
107108 +/*
107109 + * find all asm() stmts that clobber r12 and add a reload of r12
107110 + */
107111 +static unsigned int execute_kernexec_reload(void)
107112 +{
107113 + basic_block bb;
107114 +
107115 + // 1. loop through BBs and GIMPLE statements
107116 + FOR_EACH_BB_FN(bb, cfun) {
107117 + gimple_stmt_iterator gsi;
107118 +
107119 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
107120 + // gimple match: __asm__ ("" : : : "r12");
107121 + gimple asm_stmt;
107122 + size_t nclobbers;
107123 +
107124 + // is it an asm ...
107125 + asm_stmt = gsi_stmt(gsi);
107126 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
107127 + continue;
107128 +
107129 + // ... clobbering r12
107130 + nclobbers = gimple_asm_nclobbers(asm_stmt);
107131 + while (nclobbers--) {
107132 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
107133 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
107134 + continue;
107135 + kernexec_reload_fptr_mask(&gsi);
107136 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
107137 + break;
107138 + }
107139 + }
107140 + }
107141 +
107142 + return 0;
107143 +}
107144 +
107145 +/*
107146 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
107147 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
107148 + */
107149 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
107150 +{
107151 + gimple assign_intptr, assign_new_fptr, call_stmt;
107152 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
107153 +
107154 + call_stmt = gsi_stmt(*gsi);
107155 + old_fptr = gimple_call_fn(call_stmt);
107156 +
107157 + // create temporary unsigned long variable used for bitops and cast fptr to it
107158 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
107159 + add_referenced_var(intptr);
107160 + intptr = make_ssa_name(intptr, NULL);
107161 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
107162 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
107163 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
107164 + update_stmt(assign_intptr);
107165 +
107166 + // apply logical or to temporary unsigned long and bitmask
107167 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
107168 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
107169 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
107170 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
107171 + assign_intptr = gimple_build_assign(intptr, orptr);
107172 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
107173 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
107174 + update_stmt(assign_intptr);
107175 +
107176 + // cast temporary unsigned long back to a temporary fptr variable
107177 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
107178 + add_referenced_var(new_fptr);
107179 + new_fptr = make_ssa_name(new_fptr, NULL);
107180 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
107181 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
107182 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
107183 + update_stmt(assign_new_fptr);
107184 +
107185 + // replace call stmt fn with the new fptr
107186 + gimple_call_set_fn(call_stmt, new_fptr);
107187 + update_stmt(call_stmt);
107188 +}
107189 +
107190 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
107191 +{
107192 + gimple asm_or_stmt, call_stmt;
107193 + tree old_fptr, new_fptr, input, output;
107194 +#if BUILDING_GCC_VERSION <= 4007
107195 + VEC(tree, gc) *inputs = NULL;
107196 + VEC(tree, gc) *outputs = NULL;
107197 +#else
107198 + vec<tree, va_gc> *inputs = NULL;
107199 + vec<tree, va_gc> *outputs = NULL;
107200 +#endif
107201 +
107202 + call_stmt = gsi_stmt(*gsi);
107203 + old_fptr = gimple_call_fn(call_stmt);
107204 +
107205 + // create temporary fptr variable
107206 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
107207 + add_referenced_var(new_fptr);
107208 + new_fptr = make_ssa_name(new_fptr, NULL);
107209 +
107210 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
107211 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
107212 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
107213 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
107214 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
107215 +#if BUILDING_GCC_VERSION <= 4007
107216 + VEC_safe_push(tree, gc, inputs, input);
107217 + VEC_safe_push(tree, gc, outputs, output);
107218 +#else
107219 + vec_safe_push(inputs, input);
107220 + vec_safe_push(outputs, output);
107221 +#endif
107222 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
107223 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
107224 + gimple_asm_set_volatile(asm_or_stmt, true);
107225 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
107226 + update_stmt(asm_or_stmt);
107227 +
107228 + // replace call stmt fn with the new fptr
107229 + gimple_call_set_fn(call_stmt, new_fptr);
107230 + update_stmt(call_stmt);
107231 +}
107232 +
107233 +/*
107234 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
107235 + */
107236 +static unsigned int execute_kernexec_fptr(void)
107237 +{
107238 + basic_block bb;
107239 +
107240 + // 1. loop through BBs and GIMPLE statements
107241 + FOR_EACH_BB_FN(bb, cfun) {
107242 + gimple_stmt_iterator gsi;
107243 +
107244 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
107245 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
107246 + tree fn;
107247 + gimple call_stmt;
107248 +
107249 + // is it a call ...
107250 + call_stmt = gsi_stmt(gsi);
107251 + if (!is_gimple_call(call_stmt))
107252 + continue;
107253 + fn = gimple_call_fn(call_stmt);
107254 + if (TREE_CODE(fn) == ADDR_EXPR)
107255 + continue;
107256 + if (TREE_CODE(fn) != SSA_NAME)
107257 + gcc_unreachable();
107258 +
107259 + // ... through a function pointer
107260 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
107261 + fn = SSA_NAME_VAR(fn);
107262 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
107263 + debug_tree(fn);
107264 + gcc_unreachable();
107265 + }
107266 + }
107267 + fn = TREE_TYPE(fn);
107268 + if (TREE_CODE(fn) != POINTER_TYPE)
107269 + continue;
107270 + fn = TREE_TYPE(fn);
107271 + if (TREE_CODE(fn) != FUNCTION_TYPE)
107272 + continue;
107273 +
107274 + kernexec_instrument_fptr(&gsi);
107275 +
107276 +//debug_tree(gimple_call_fn(call_stmt));
107277 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
107278 + }
107279 + }
107280 +
107281 + return 0;
107282 +}
107283 +
107284 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
107285 +static void kernexec_instrument_retaddr_bts(rtx insn)
107286 +{
107287 + rtx btsq;
107288 + rtvec argvec, constraintvec, labelvec;
107289 + int line;
107290 +
107291 + // create asm volatile("btsq $63,(%%rsp)":::)
107292 + argvec = rtvec_alloc(0);
107293 + constraintvec = rtvec_alloc(0);
107294 + labelvec = rtvec_alloc(0);
107295 + line = expand_location(RTL_LOCATION(insn)).line;
107296 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
107297 + MEM_VOLATILE_P(btsq) = 1;
107298 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
107299 + emit_insn_before(btsq, insn);
107300 +}
107301 +
107302 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
107303 +static void kernexec_instrument_retaddr_or(rtx insn)
107304 +{
107305 + rtx orq;
107306 + rtvec argvec, constraintvec, labelvec;
107307 + int line;
107308 +
107309 + // create asm volatile("orq %%r12,(%%rsp)":::)
107310 + argvec = rtvec_alloc(0);
107311 + constraintvec = rtvec_alloc(0);
107312 + labelvec = rtvec_alloc(0);
107313 + line = expand_location(RTL_LOCATION(insn)).line;
107314 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
107315 + MEM_VOLATILE_P(orq) = 1;
107316 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
107317 + emit_insn_before(orq, insn);
107318 +}
107319 +
107320 +/*
107321 + * find all asm level function returns and forcibly set the highest bit of the return address
107322 + */
107323 +static unsigned int execute_kernexec_retaddr(void)
107324 +{
107325 + rtx insn;
107326 +
107327 +// if (stack_realign_drap)
107328 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
107329 +
107330 + // 1. find function returns
107331 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
107332 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
107333 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
107334 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
107335 + rtx body;
107336 +
107337 + // is it a retn
107338 + if (!JUMP_P(insn))
107339 + continue;
107340 + body = PATTERN(insn);
107341 + if (GET_CODE(body) == PARALLEL)
107342 + body = XVECEXP(body, 0, 0);
107343 + if (!ANY_RETURN_P(body))
107344 + continue;
107345 + kernexec_instrument_retaddr(insn);
107346 + }
107347 +
107348 +// print_simple_rtl(stderr, get_insns());
107349 +// print_rtl(stderr, get_insns());
107350 +
107351 + return 0;
107352 +}
107353 +
107354 +static bool kernexec_cmodel_check(void)
107355 +{
107356 + tree section;
107357 +
107358 + if (ix86_cmodel != CM_KERNEL)
107359 + return false;
107360 +
107361 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
107362 + if (!section || !TREE_VALUE(section))
107363 + return true;
107364 +
107365 + section = TREE_VALUE(TREE_VALUE(section));
107366 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
107367 + return true;
107368 +
107369 + return false;
107370 +}
107371 +
107372 +#if BUILDING_GCC_VERSION >= 4009
107373 +static const struct pass_data kernexec_reload_pass_data = {
107374 +#else
107375 +static struct gimple_opt_pass kernexec_reload_pass = {
107376 + .pass = {
107377 +#endif
107378 + .type = GIMPLE_PASS,
107379 + .name = "kernexec_reload",
107380 +#if BUILDING_GCC_VERSION >= 4008
107381 + .optinfo_flags = OPTGROUP_NONE,
107382 +#endif
107383 +#if BUILDING_GCC_VERSION >= 4009
107384 + .has_gate = true,
107385 + .has_execute = true,
107386 +#else
107387 + .gate = kernexec_cmodel_check,
107388 + .execute = execute_kernexec_reload,
107389 + .sub = NULL,
107390 + .next = NULL,
107391 + .static_pass_number = 0,
107392 +#endif
107393 + .tv_id = TV_NONE,
107394 + .properties_required = 0,
107395 + .properties_provided = 0,
107396 + .properties_destroyed = 0,
107397 + .todo_flags_start = 0,
107398 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
107399 +#if BUILDING_GCC_VERSION < 4009
107400 + }
107401 +#endif
107402 +};
107403 +
107404 +#if BUILDING_GCC_VERSION >= 4009
107405 +static const struct pass_data kernexec_fptr_pass_data = {
107406 +#else
107407 +static struct gimple_opt_pass kernexec_fptr_pass = {
107408 + .pass = {
107409 +#endif
107410 + .type = GIMPLE_PASS,
107411 + .name = "kernexec_fptr",
107412 +#if BUILDING_GCC_VERSION >= 4008
107413 + .optinfo_flags = OPTGROUP_NONE,
107414 +#endif
107415 +#if BUILDING_GCC_VERSION >= 4009
107416 + .has_gate = true,
107417 + .has_execute = true,
107418 +#else
107419 + .gate = kernexec_cmodel_check,
107420 + .execute = execute_kernexec_fptr,
107421 + .sub = NULL,
107422 + .next = NULL,
107423 + .static_pass_number = 0,
107424 +#endif
107425 + .tv_id = TV_NONE,
107426 + .properties_required = 0,
107427 + .properties_provided = 0,
107428 + .properties_destroyed = 0,
107429 + .todo_flags_start = 0,
107430 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
107431 +#if BUILDING_GCC_VERSION < 4009
107432 + }
107433 +#endif
107434 +};
107435 +
107436 +#if BUILDING_GCC_VERSION >= 4009
107437 +static const struct pass_data kernexec_retaddr_pass_data = {
107438 +#else
107439 +static struct rtl_opt_pass kernexec_retaddr_pass = {
107440 + .pass = {
107441 +#endif
107442 + .type = RTL_PASS,
107443 + .name = "kernexec_retaddr",
107444 +#if BUILDING_GCC_VERSION >= 4008
107445 + .optinfo_flags = OPTGROUP_NONE,
107446 +#endif
107447 +#if BUILDING_GCC_VERSION >= 4009
107448 + .has_gate = true,
107449 + .has_execute = true,
107450 +#else
107451 + .gate = kernexec_cmodel_check,
107452 + .execute = execute_kernexec_retaddr,
107453 + .sub = NULL,
107454 + .next = NULL,
107455 + .static_pass_number = 0,
107456 +#endif
107457 + .tv_id = TV_NONE,
107458 + .properties_required = 0,
107459 + .properties_provided = 0,
107460 + .properties_destroyed = 0,
107461 + .todo_flags_start = 0,
107462 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
107463 +#if BUILDING_GCC_VERSION < 4009
107464 + }
107465 +#endif
107466 +};
107467 +
107468 +#if BUILDING_GCC_VERSION >= 4009
107469 +namespace {
107470 +class kernexec_reload_pass : public gimple_opt_pass {
107471 +public:
107472 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
107473 + bool gate() { return kernexec_cmodel_check(); }
107474 + unsigned int execute() { return execute_kernexec_reload(); }
107475 +};
107476 +
107477 +class kernexec_fptr_pass : public gimple_opt_pass {
107478 +public:
107479 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
107480 + bool gate() { return kernexec_cmodel_check(); }
107481 + unsigned int execute() { return execute_kernexec_fptr(); }
107482 +};
107483 +
107484 +class kernexec_retaddr_pass : public rtl_opt_pass {
107485 +public:
107486 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
107487 + bool gate() { return kernexec_cmodel_check(); }
107488 + unsigned int execute() { return execute_kernexec_retaddr(); }
107489 +};
107490 +}
107491 +#endif
107492 +
107493 +static struct opt_pass *make_kernexec_reload_pass(void)
107494 +{
107495 +#if BUILDING_GCC_VERSION >= 4009
107496 + return new kernexec_reload_pass();
107497 +#else
107498 + return &kernexec_reload_pass.pass;
107499 +#endif
107500 +}
107501 +
107502 +static struct opt_pass *make_kernexec_fptr_pass(void)
107503 +{
107504 +#if BUILDING_GCC_VERSION >= 4009
107505 + return new kernexec_fptr_pass();
107506 +#else
107507 + return &kernexec_fptr_pass.pass;
107508 +#endif
107509 +}
107510 +
107511 +static struct opt_pass *make_kernexec_retaddr_pass(void)
107512 +{
107513 +#if BUILDING_GCC_VERSION >= 4009
107514 + return new kernexec_retaddr_pass();
107515 +#else
107516 + return &kernexec_retaddr_pass.pass;
107517 +#endif
107518 +}
107519 +
107520 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107521 +{
107522 + const char * const plugin_name = plugin_info->base_name;
107523 + const int argc = plugin_info->argc;
107524 + const struct plugin_argument * const argv = plugin_info->argv;
107525 + int i;
107526 + struct register_pass_info kernexec_reload_pass_info;
107527 + struct register_pass_info kernexec_fptr_pass_info;
107528 + struct register_pass_info kernexec_retaddr_pass_info;
107529 +
107530 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
107531 + kernexec_reload_pass_info.reference_pass_name = "ssa";
107532 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
107533 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107534 +
107535 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
107536 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
107537 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
107538 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107539 +
107540 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
107541 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
107542 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
107543 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107544 +
107545 + if (!plugin_default_version_check(version, &gcc_version)) {
107546 + error(G_("incompatible gcc/plugin versions"));
107547 + return 1;
107548 + }
107549 +
107550 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
107551 +
107552 + if (TARGET_64BIT == 0)
107553 + return 0;
107554 +
107555 + for (i = 0; i < argc; ++i) {
107556 + if (!strcmp(argv[i].key, "method")) {
107557 + if (!argv[i].value) {
107558 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107559 + continue;
107560 + }
107561 + if (!strcmp(argv[i].value, "bts")) {
107562 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
107563 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
107564 + } else if (!strcmp(argv[i].value, "or")) {
107565 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
107566 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
107567 + fix_register("r12", 1, 1);
107568 + } else
107569 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107570 + continue;
107571 + }
107572 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107573 + }
107574 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
107575 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
107576 +
107577 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
107578 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
107579 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
107580 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
107581 +
107582 + return 0;
107583 +}
107584 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
107585 new file mode 100644
107586 index 0000000..319229d
107587 --- /dev/null
107588 +++ b/tools/gcc/latent_entropy_plugin.c
107589 @@ -0,0 +1,457 @@
107590 +/*
107591 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
107592 + * Licensed under the GPL v2
107593 + *
107594 + * Note: the choice of the license means that the compilation process is
107595 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107596 + * but for the kernel it doesn't matter since it doesn't link against
107597 + * any of the gcc libraries
107598 + *
107599 + * gcc plugin to help generate a little bit of entropy from program state,
107600 + * used throughout the uptime of the kernel
107601 + *
107602 + * TODO:
107603 + * - add ipa pass to identify not explicitly marked candidate functions
107604 + * - mix in more program state (function arguments/return values, loop variables, etc)
107605 + * - more instrumentation control via attribute parameters
107606 + *
107607 + * BUGS:
107608 + * - LTO needs -flto-partition=none for now
107609 + */
107610 +
107611 +#include "gcc-common.h"
107612 +
107613 +int plugin_is_GPL_compatible;
107614 +
107615 +static tree latent_entropy_decl;
107616 +
107617 +static struct plugin_info latent_entropy_plugin_info = {
107618 + .version = "201403280150",
107619 + .help = NULL
107620 +};
107621 +
107622 +static unsigned HOST_WIDE_INT seed;
107623 +static unsigned HOST_WIDE_INT get_random_const(void)
107624 +{
107625 + unsigned int i;
107626 + unsigned HOST_WIDE_INT ret = 0;
107627 +
107628 + for (i = 0; i < 8 * sizeof ret; i++) {
107629 + ret = (ret << 1) | (seed & 1);
107630 + seed >>= 1;
107631 + if (ret & 1)
107632 + seed ^= 0xD800000000000000ULL;
107633 + }
107634 +
107635 + return ret;
107636 +}
107637 +
107638 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107639 +{
107640 + tree type;
107641 + unsigned long long mask;
107642 +#if BUILDING_GCC_VERSION <= 4007
107643 + VEC(constructor_elt, gc) *vals;
107644 +#else
107645 + vec<constructor_elt, va_gc> *vals;
107646 +#endif
107647 +
107648 + switch (TREE_CODE(*node)) {
107649 + default:
107650 + *no_add_attrs = true;
107651 + error("%qE attribute only applies to functions and variables", name);
107652 + break;
107653 +
107654 + case VAR_DECL:
107655 + if (DECL_INITIAL(*node)) {
107656 + *no_add_attrs = true;
107657 + error("variable %qD with %qE attribute must not be initialized", *node, name);
107658 + break;
107659 + }
107660 +
107661 + if (!TREE_STATIC(*node)) {
107662 + *no_add_attrs = true;
107663 + error("variable %qD with %qE attribute must not be local", *node, name);
107664 + break;
107665 + }
107666 +
107667 + type = TREE_TYPE(*node);
107668 + switch (TREE_CODE(type)) {
107669 + default:
107670 + *no_add_attrs = true;
107671 + 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);
107672 + break;
107673 +
107674 + case RECORD_TYPE: {
107675 + tree field;
107676 + unsigned int nelt = 0;
107677 +
107678 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
107679 + tree fieldtype;
107680 +
107681 + fieldtype = TREE_TYPE(field);
107682 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
107683 + *no_add_attrs = true;
107684 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
107685 + break;
107686 + }
107687 + }
107688 +
107689 + if (field)
107690 + break;
107691 +
107692 +#if BUILDING_GCC_VERSION <= 4007
107693 + vals = VEC_alloc(constructor_elt, gc, nelt);
107694 +#else
107695 + vec_alloc(vals, nelt);
107696 +#endif
107697 +
107698 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107699 + tree fieldtype;
107700 +
107701 + fieldtype = TREE_TYPE(field);
107702 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
107703 + mask = 2 * (mask - 1) + 1;
107704 +
107705 + if (TYPE_UNSIGNED(fieldtype))
107706 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
107707 + else
107708 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
107709 + }
107710 +
107711 + DECL_INITIAL(*node) = build_constructor(type, vals);
107712 +//debug_tree(DECL_INITIAL(*node));
107713 + break;
107714 + }
107715 +
107716 + case INTEGER_TYPE:
107717 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
107718 + mask = 2 * (mask - 1) + 1;
107719 +
107720 + if (TYPE_UNSIGNED(type))
107721 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
107722 + else
107723 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
107724 + break;
107725 +
107726 + case ARRAY_TYPE: {
107727 + tree elt_type, array_size, elt_size;
107728 + unsigned int i, nelt;
107729 +
107730 + elt_type = TREE_TYPE(type);
107731 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
107732 + array_size = TYPE_SIZE_UNIT(type);
107733 +
107734 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
107735 + *no_add_attrs = true;
107736 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
107737 + break;
107738 + }
107739 +
107740 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
107741 +#if BUILDING_GCC_VERSION <= 4007
107742 + vals = VEC_alloc(constructor_elt, gc, nelt);
107743 +#else
107744 + vec_alloc(vals, nelt);
107745 +#endif
107746 +
107747 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
107748 + mask = 2 * (mask - 1) + 1;
107749 +
107750 + for (i = 0; i < nelt; i++)
107751 + if (TYPE_UNSIGNED(elt_type))
107752 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
107753 + else
107754 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
107755 +
107756 + DECL_INITIAL(*node) = build_constructor(type, vals);
107757 +//debug_tree(DECL_INITIAL(*node));
107758 + break;
107759 + }
107760 + }
107761 + break;
107762 +
107763 + case FUNCTION_DECL:
107764 + break;
107765 + }
107766 +
107767 + return NULL_TREE;
107768 +}
107769 +
107770 +static struct attribute_spec latent_entropy_attr = {
107771 + .name = "latent_entropy",
107772 + .min_length = 0,
107773 + .max_length = 0,
107774 + .decl_required = true,
107775 + .type_required = false,
107776 + .function_type_required = false,
107777 + .handler = handle_latent_entropy_attribute,
107778 +#if BUILDING_GCC_VERSION >= 4007
107779 + .affects_type_identity = false
107780 +#endif
107781 +};
107782 +
107783 +static void register_attributes(void *event_data, void *data)
107784 +{
107785 + register_attribute(&latent_entropy_attr);
107786 +}
107787 +
107788 +static bool gate_latent_entropy(void)
107789 +{
107790 + // don't bother with noreturn functions for now
107791 + if (TREE_THIS_VOLATILE(current_function_decl))
107792 + return false;
107793 +
107794 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
107795 +}
107796 +
107797 +static enum tree_code get_op(tree *rhs)
107798 +{
107799 + static enum tree_code op;
107800 + unsigned HOST_WIDE_INT random_const;
107801 +
107802 + random_const = get_random_const();
107803 +
107804 + switch (op) {
107805 + case BIT_XOR_EXPR:
107806 + op = PLUS_EXPR;
107807 + break;
107808 +
107809 + case PLUS_EXPR:
107810 + if (rhs) {
107811 + op = LROTATE_EXPR;
107812 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
107813 + break;
107814 + }
107815 +
107816 + case LROTATE_EXPR:
107817 + default:
107818 + op = BIT_XOR_EXPR;
107819 + break;
107820 + }
107821 + if (rhs)
107822 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
107823 + return op;
107824 +}
107825 +
107826 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
107827 +{
107828 + gimple_stmt_iterator gsi;
107829 + gimple assign;
107830 + tree addxorrol, rhs;
107831 + enum tree_code op;
107832 +
107833 + op = get_op(&rhs);
107834 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
107835 + assign = gimple_build_assign(local_entropy, addxorrol);
107836 + gsi = gsi_after_labels(bb);
107837 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
107838 + update_stmt(assign);
107839 +//debug_bb(bb);
107840 +}
107841 +
107842 +static void perturb_latent_entropy(basic_block bb, tree rhs)
107843 +{
107844 + gimple_stmt_iterator gsi;
107845 + gimple assign;
107846 + tree addxorrol, temp;
107847 +
107848 + // 1. create temporary copy of latent_entropy
107849 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
107850 + add_referenced_var(temp);
107851 +
107852 + // 2. read...
107853 + temp = make_ssa_name(temp, NULL);
107854 + assign = gimple_build_assign(temp, latent_entropy_decl);
107855 + SSA_NAME_DEF_STMT(temp) = assign;
107856 + add_referenced_var(latent_entropy_decl);
107857 + gsi = gsi_after_labels(bb);
107858 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107859 + update_stmt(assign);
107860 +
107861 + // 3. ...modify...
107862 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
107863 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
107864 + assign = gimple_build_assign(temp, addxorrol);
107865 + SSA_NAME_DEF_STMT(temp) = assign;
107866 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107867 + update_stmt(assign);
107868 +
107869 + // 4. ...write latent_entropy
107870 + assign = gimple_build_assign(latent_entropy_decl, temp);
107871 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107872 + update_stmt(assign);
107873 +}
107874 +
107875 +static unsigned int execute_latent_entropy(void)
107876 +{
107877 + basic_block bb;
107878 + gimple assign;
107879 + gimple_stmt_iterator gsi;
107880 + tree local_entropy;
107881 +
107882 + if (!latent_entropy_decl) {
107883 + struct varpool_node *node;
107884 +
107885 + FOR_EACH_VARIABLE(node) {
107886 + tree var = NODE_DECL(node);
107887 +
107888 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
107889 + continue;
107890 + latent_entropy_decl = var;
107891 +// debug_tree(var);
107892 + break;
107893 + }
107894 + if (!latent_entropy_decl) {
107895 +// debug_tree(current_function_decl);
107896 + return 0;
107897 + }
107898 + }
107899 +
107900 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
107901 +
107902 + // 1. create local entropy variable
107903 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
107904 + add_referenced_var(local_entropy);
107905 + mark_sym_for_renaming(local_entropy);
107906 +
107907 + // 2. initialize local entropy variable
107908 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
107909 + if (dom_info_available_p(CDI_DOMINATORS))
107910 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
107911 + gsi = gsi_start_bb(bb);
107912 +
107913 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
107914 +// gimple_set_location(assign, loc);
107915 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107916 + update_stmt(assign);
107917 +//debug_bb(bb);
107918 + gcc_assert(single_succ_p(bb));
107919 + bb = single_succ(bb);
107920 +
107921 + // 3. instrument each BB with an operation on the local entropy variable
107922 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
107923 + perturb_local_entropy(bb, local_entropy);
107924 +//debug_bb(bb);
107925 + bb = bb->next_bb;
107926 + };
107927 +
107928 + // 4. mix local entropy into the global entropy variable
107929 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107930 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
107931 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107932 + return 0;
107933 +}
107934 +
107935 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
107936 +{
107937 + tree latent_entropy_type;
107938 +
107939 + seed = get_random_seed(false);
107940 +
107941 + if (in_lto_p)
107942 + return;
107943 +
107944 + // extern volatile u64 latent_entropy
107945 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
107946 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
107947 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
107948 +
107949 + TREE_STATIC(latent_entropy_decl) = 1;
107950 + TREE_PUBLIC(latent_entropy_decl) = 1;
107951 + TREE_USED(latent_entropy_decl) = 1;
107952 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
107953 + DECL_EXTERNAL(latent_entropy_decl) = 1;
107954 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
107955 + lang_hooks.decls.pushdecl(latent_entropy_decl);
107956 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
107957 +// varpool_finalize_decl(latent_entropy_decl);
107958 +// varpool_mark_needed_node(latent_entropy_decl);
107959 +}
107960 +
107961 +#if BUILDING_GCC_VERSION >= 4009
107962 +static const struct pass_data latent_entropy_pass_data = {
107963 +#else
107964 +static struct gimple_opt_pass latent_entropy_pass = {
107965 + .pass = {
107966 +#endif
107967 + .type = GIMPLE_PASS,
107968 + .name = "latent_entropy",
107969 +#if BUILDING_GCC_VERSION >= 4008
107970 + .optinfo_flags = OPTGROUP_NONE,
107971 +#endif
107972 +#if BUILDING_GCC_VERSION >= 4009
107973 + .has_gate = true,
107974 + .has_execute = true,
107975 +#else
107976 + .gate = gate_latent_entropy,
107977 + .execute = execute_latent_entropy,
107978 + .sub = NULL,
107979 + .next = NULL,
107980 + .static_pass_number = 0,
107981 +#endif
107982 + .tv_id = TV_NONE,
107983 + .properties_required = PROP_gimple_leh | PROP_cfg,
107984 + .properties_provided = 0,
107985 + .properties_destroyed = 0,
107986 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
107987 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
107988 +#if BUILDING_GCC_VERSION < 4009
107989 + }
107990 +#endif
107991 +};
107992 +
107993 +#if BUILDING_GCC_VERSION >= 4009
107994 +namespace {
107995 +class latent_entropy_pass : public gimple_opt_pass {
107996 +public:
107997 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
107998 + bool gate() { return gate_latent_entropy(); }
107999 + unsigned int execute() { return execute_latent_entropy(); }
108000 +};
108001 +}
108002 +#endif
108003 +
108004 +static struct opt_pass *make_latent_entropy_pass(void)
108005 +{
108006 +#if BUILDING_GCC_VERSION >= 4009
108007 + return new latent_entropy_pass();
108008 +#else
108009 + return &latent_entropy_pass.pass;
108010 +#endif
108011 +}
108012 +
108013 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108014 +{
108015 + const char * const plugin_name = plugin_info->base_name;
108016 + struct register_pass_info latent_entropy_pass_info;
108017 +
108018 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
108019 + latent_entropy_pass_info.reference_pass_name = "optimized";
108020 + latent_entropy_pass_info.ref_pass_instance_number = 1;
108021 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
108022 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
108023 + {
108024 + .base = &latent_entropy_decl,
108025 + .nelt = 1,
108026 + .stride = sizeof(latent_entropy_decl),
108027 + .cb = &gt_ggc_mx_tree_node,
108028 + .pchw = &gt_pch_nx_tree_node
108029 + },
108030 + LAST_GGC_ROOT_TAB
108031 + };
108032 +
108033 + if (!plugin_default_version_check(version, &gcc_version)) {
108034 + error(G_("incompatible gcc/plugin versions"));
108035 + return 1;
108036 + }
108037 +
108038 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
108039 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
108040 + if (!in_lto_p)
108041 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
108042 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
108043 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108044 +
108045 + return 0;
108046 +}
108047 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
108048 new file mode 100644
108049 index 0000000..8dafb22
108050 --- /dev/null
108051 +++ b/tools/gcc/randomize_layout_plugin.c
108052 @@ -0,0 +1,910 @@
108053 +/*
108054 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
108055 + * and PaX Team <pageexec@freemail.hu>
108056 + * Licensed under the GPL v2
108057 + *
108058 + * Usage:
108059 + * $ # for 4.5/4.6/C based 4.7
108060 + * $ 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
108061 + * $ # for C++ based 4.7/4.8+
108062 + * $ 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
108063 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
108064 + */
108065 +
108066 +#include "gcc-common.h"
108067 +#include "randomize_layout_seed.h"
108068 +
108069 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
108070 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
108071 +#endif
108072 +
108073 +#define ORIG_TYPE_NAME(node) \
108074 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
108075 +
108076 +int plugin_is_GPL_compatible;
108077 +
108078 +static int performance_mode;
108079 +
108080 +static struct plugin_info randomize_layout_plugin_info = {
108081 + .version = "201402201816",
108082 + .help = "disable\t\t\tdo not activate plugin\n"
108083 + "performance-mode\tenable cacheline-aware layout randomization\n"
108084 +};
108085 +
108086 +/* from old Linux dcache.h */
108087 +static inline unsigned long
108088 +partial_name_hash(unsigned long c, unsigned long prevhash)
108089 +{
108090 + return (prevhash + (c << 4) + (c >> 4)) * 11;
108091 +}
108092 +static inline unsigned int
108093 +name_hash(const unsigned char *name)
108094 +{
108095 + unsigned long hash = 0;
108096 + unsigned int len = strlen((const char *)name);
108097 + while (len--)
108098 + hash = partial_name_hash(*name++, hash);
108099 + return (unsigned int)hash;
108100 +}
108101 +
108102 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
108103 +{
108104 + tree type;
108105 +
108106 + *no_add_attrs = true;
108107 + if (TREE_CODE(*node) == FUNCTION_DECL) {
108108 + error("%qE attribute does not apply to functions (%qF)", name, *node);
108109 + return NULL_TREE;
108110 + }
108111 +
108112 + if (TREE_CODE(*node) == PARM_DECL) {
108113 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
108114 + return NULL_TREE;
108115 + }
108116 +
108117 + if (TREE_CODE(*node) == VAR_DECL) {
108118 + error("%qE attribute does not apply to variables (%qD)", name, *node);
108119 + return NULL_TREE;
108120 + }
108121 +
108122 + if (TYPE_P(*node)) {
108123 + type = *node;
108124 + } else {
108125 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
108126 + type = TREE_TYPE(*node);
108127 + }
108128 +
108129 + if (TREE_CODE(type) != RECORD_TYPE) {
108130 + error("%qE attribute used on %qT applies to struct types only", name, type);
108131 + return NULL_TREE;
108132 + }
108133 +
108134 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
108135 + error("%qE attribute is already applied to the type %qT", name, type);
108136 + return NULL_TREE;
108137 + }
108138 +
108139 + *no_add_attrs = false;
108140 +
108141 + return NULL_TREE;
108142 +}
108143 +
108144 +/* set on complete types that we don't need to inspect further at all */
108145 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
108146 +{
108147 + *no_add_attrs = false;
108148 + return NULL_TREE;
108149 +}
108150 +
108151 +/*
108152 + * set on types that we've performed a shuffle on, to prevent re-shuffling
108153 + * this does not preclude us from inspecting its fields for potential shuffles
108154 + */
108155 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
108156 +{
108157 + *no_add_attrs = false;
108158 + return NULL_TREE;
108159 +}
108160 +
108161 +/*
108162 + * 64bit variant of Bob Jenkins' public domain PRNG
108163 + * 256 bits of internal state
108164 + */
108165 +
108166 +typedef unsigned long long u64;
108167 +
108168 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
108169 +
108170 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
108171 +static u64 ranval(ranctx *x) {
108172 + u64 e = x->a - rot(x->b, 7);
108173 + x->a = x->b ^ rot(x->c, 13);
108174 + x->b = x->c + rot(x->d, 37);
108175 + x->c = x->d + e;
108176 + x->d = e + x->a;
108177 + return x->d;
108178 +}
108179 +
108180 +static void raninit(ranctx *x, u64 *seed) {
108181 + int i;
108182 +
108183 + x->a = seed[0];
108184 + x->b = seed[1];
108185 + x->c = seed[2];
108186 + x->d = seed[3];
108187 +
108188 + for (i=0; i < 30; ++i)
108189 + (void)ranval(x);
108190 +}
108191 +
108192 +static u64 shuffle_seed[4];
108193 +
108194 +struct partition_group {
108195 + tree tree_start;
108196 + unsigned long start;
108197 + unsigned long length;
108198 +};
108199 +
108200 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
108201 +{
108202 + unsigned long i;
108203 + unsigned long accum_size = 0;
108204 + unsigned long accum_length = 0;
108205 + unsigned long group_idx = 0;
108206 +
108207 + gcc_assert(length < INT_MAX);
108208 +
108209 + memset(size_groups, 0, sizeof(struct partition_group) * length);
108210 +
108211 + for (i = 0; i < length; i++) {
108212 + if (size_groups[group_idx].tree_start == NULL_TREE) {
108213 + size_groups[group_idx].tree_start = fields[i];
108214 + size_groups[group_idx].start = i;
108215 + accum_length = 0;
108216 + accum_size = 0;
108217 + }
108218 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
108219 + accum_length++;
108220 + if (accum_size >= 64) {
108221 + size_groups[group_idx].length = accum_length;
108222 + accum_length = 0;
108223 + group_idx++;
108224 + }
108225 + }
108226 +
108227 + if (size_groups[group_idx].tree_start != NULL_TREE &&
108228 + !size_groups[group_idx].length) {
108229 + size_groups[group_idx].length = accum_length;
108230 + group_idx++;
108231 + }
108232 +
108233 + *num_groups = group_idx;
108234 +}
108235 +
108236 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
108237 +{
108238 + unsigned long i, x;
108239 + struct partition_group size_group[length];
108240 + unsigned long num_groups = 0;
108241 + unsigned long randnum;
108242 +
108243 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
108244 + for (i = num_groups - 1; i > 0; i--) {
108245 + struct partition_group tmp;
108246 + randnum = ranval(prng_state) % (i + 1);
108247 + tmp = size_group[i];
108248 + size_group[i] = size_group[randnum];
108249 + size_group[randnum] = tmp;
108250 + }
108251 +
108252 + for (x = 0; x < num_groups; x++) {
108253 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
108254 + tree tmp;
108255 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
108256 + continue;
108257 + randnum = ranval(prng_state) % (i + 1);
108258 + // we could handle this case differently if desired
108259 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
108260 + continue;
108261 + tmp = newtree[i];
108262 + newtree[i] = newtree[randnum];
108263 + newtree[randnum] = tmp;
108264 + }
108265 + }
108266 +}
108267 +
108268 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
108269 +{
108270 + unsigned long i, randnum;
108271 +
108272 + for (i = length - 1; i > 0; i--) {
108273 + tree tmp;
108274 + randnum = ranval(prng_state) % (i + 1);
108275 + tmp = newtree[i];
108276 + newtree[i] = newtree[randnum];
108277 + newtree[randnum] = tmp;
108278 + }
108279 +}
108280 +
108281 +/* modern in-place Fisher-Yates shuffle */
108282 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
108283 +{
108284 + unsigned long i;
108285 + u64 seed[4];
108286 + ranctx prng_state;
108287 + const unsigned char *structname;
108288 +
108289 + if (length == 0)
108290 + return;
108291 +
108292 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108293 +
108294 + structname = ORIG_TYPE_NAME(type);
108295 +
108296 +#ifdef __DEBUG_PLUGIN
108297 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
108298 +#ifdef __DEBUG_VERBOSE
108299 + debug_tree((tree)type);
108300 +#endif
108301 +#endif
108302 +
108303 + for (i = 0; i < 4; i++) {
108304 + seed[i] = shuffle_seed[i];
108305 + seed[i] ^= name_hash(structname);
108306 + }
108307 +
108308 + raninit(&prng_state, (u64 *)&seed);
108309 +
108310 + if (performance_mode)
108311 + performance_shuffle(newtree, length, &prng_state);
108312 + else
108313 + full_shuffle(newtree, length, &prng_state);
108314 +}
108315 +
108316 +static bool is_flexible_array(const_tree field)
108317 +{
108318 + const_tree fieldtype;
108319 + const_tree typesize;
108320 + const_tree elemtype;
108321 + const_tree elemsize;
108322 +
108323 + fieldtype = TREE_TYPE(field);
108324 + typesize = TYPE_SIZE(fieldtype);
108325 +
108326 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
108327 + return false;
108328 +
108329 + elemtype = TREE_TYPE(fieldtype);
108330 + elemsize = TYPE_SIZE(elemtype);
108331 +
108332 + /* size of type is represented in bits */
108333 +
108334 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
108335 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
108336 + return true;
108337 +
108338 + if (typesize != NULL_TREE &&
108339 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
108340 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
108341 + return true;
108342 +
108343 + return false;
108344 +}
108345 +
108346 +static int relayout_struct(tree type)
108347 +{
108348 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
108349 + unsigned long shuffle_length = num_fields;
108350 + tree field;
108351 + tree newtree[num_fields];
108352 + unsigned long i;
108353 + tree list;
108354 + tree variant;
108355 + expanded_location xloc;
108356 +
108357 + if (TYPE_FIELDS(type) == NULL_TREE)
108358 + return 0;
108359 +
108360 + if (num_fields < 2)
108361 + return 0;
108362 +
108363 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108364 +
108365 + gcc_assert(num_fields < INT_MAX);
108366 +
108367 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
108368 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
108369 + return 0;
108370 +
108371 + /* throw out any structs in uapi */
108372 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
108373 +
108374 + if (strstr(xloc.file, "/uapi/"))
108375 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
108376 +
108377 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
108378 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
108379 + newtree[i] = field;
108380 + }
108381 +
108382 + /*
108383 + * enforce that we don't randomize the layout of the last
108384 + * element of a struct if it's a 0 or 1-length array
108385 + * or a proper flexible array
108386 + */
108387 + if (is_flexible_array(newtree[num_fields - 1]))
108388 + shuffle_length--;
108389 +
108390 + shuffle(type, (tree *)newtree, shuffle_length);
108391 +
108392 + /*
108393 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
108394 + * as gcc provides no other way to detect such code
108395 + */
108396 + list = make_node(FIELD_DECL);
108397 + TREE_CHAIN(list) = newtree[0];
108398 + TREE_TYPE(list) = void_type_node;
108399 + DECL_SIZE(list) = bitsize_zero_node;
108400 + DECL_NONADDRESSABLE_P(list) = 1;
108401 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
108402 + DECL_SIZE_UNIT(list) = size_zero_node;
108403 + DECL_FIELD_OFFSET(list) = size_zero_node;
108404 + // to satisfy the constify plugin
108405 + TREE_READONLY(list) = 1;
108406 +
108407 + for (i = 0; i < num_fields - 1; i++)
108408 + TREE_CHAIN(newtree[i]) = newtree[i+1];
108409 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
108410 +
108411 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
108412 + TYPE_FIELDS(variant) = list;
108413 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
108414 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
108415 + // force a re-layout
108416 + TYPE_SIZE(variant) = NULL_TREE;
108417 + layout_type(variant);
108418 + }
108419 +
108420 + return 1;
108421 +}
108422 +
108423 +/* from constify plugin */
108424 +static const_tree get_field_type(const_tree field)
108425 +{
108426 + return strip_array_types(TREE_TYPE(field));
108427 +}
108428 +
108429 +/* from constify plugin */
108430 +static bool is_fptr(const_tree fieldtype)
108431 +{
108432 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
108433 + return false;
108434 +
108435 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
108436 +}
108437 +
108438 +/* derived from constify plugin */
108439 +static int is_pure_ops_struct(const_tree node)
108440 +{
108441 + const_tree field;
108442 +
108443 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
108444 +
108445 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
108446 + const_tree fieldtype = get_field_type(field);
108447 + enum tree_code code = TREE_CODE(fieldtype);
108448 +
108449 + if (node == fieldtype)
108450 + continue;
108451 +
108452 + if (!is_fptr(fieldtype))
108453 + return 0;
108454 +
108455 + if (code != RECORD_TYPE && code != UNION_TYPE)
108456 + continue;
108457 +
108458 + if (!is_pure_ops_struct(fieldtype))
108459 + return 0;
108460 + }
108461 +
108462 + return 1;
108463 +}
108464 +
108465 +static void randomize_type(tree type)
108466 +{
108467 + tree variant;
108468 +
108469 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108470 +
108471 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108472 + return;
108473 +
108474 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
108475 + relayout_struct(type);
108476 +
108477 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
108478 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
108479 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
108480 + }
108481 +#ifdef __DEBUG_PLUGIN
108482 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
108483 +#ifdef __DEBUG_VERBOSE
108484 + debug_tree(type);
108485 +#endif
108486 +#endif
108487 +}
108488 +
108489 +static void randomize_layout_finish_decl(void *event_data, void *data)
108490 +{
108491 + tree decl = (tree)event_data;
108492 + tree type;
108493 +
108494 + if (decl == NULL_TREE || decl == error_mark_node)
108495 + return;
108496 +
108497 + type = TREE_TYPE(decl);
108498 +
108499 + if (TREE_CODE(decl) != VAR_DECL)
108500 + return;
108501 +
108502 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
108503 + return;
108504 +
108505 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
108506 + return;
108507 +
108508 + relayout_decl(decl);
108509 +}
108510 +
108511 +static void finish_type(void *event_data, void *data)
108512 +{
108513 + tree type = (tree)event_data;
108514 +
108515 + if (type == NULL_TREE || type == error_mark_node)
108516 + return;
108517 +
108518 + if (TREE_CODE(type) != RECORD_TYPE)
108519 + return;
108520 +
108521 + if (TYPE_FIELDS(type) == NULL_TREE)
108522 + return;
108523 +
108524 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108525 + return;
108526 +
108527 +#ifdef __DEBUG_PLUGIN
108528 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
108529 +#endif
108530 +#ifdef __DEBUG_VERBOSE
108531 + debug_tree(type);
108532 +#endif
108533 + randomize_type(type);
108534 +
108535 + return;
108536 +}
108537 +
108538 +static struct attribute_spec randomize_layout_attr = {
108539 + .name = "randomize_layout",
108540 + // related to args
108541 + .min_length = 0,
108542 + .max_length = 0,
108543 + .decl_required = false,
108544 + // need type declaration
108545 + .type_required = true,
108546 + .function_type_required = false,
108547 + .handler = handle_randomize_layout_attr,
108548 +#if BUILDING_GCC_VERSION >= 4007
108549 + .affects_type_identity = true
108550 +#endif
108551 +};
108552 +
108553 +static struct attribute_spec no_randomize_layout_attr = {
108554 + .name = "no_randomize_layout",
108555 + // related to args
108556 + .min_length = 0,
108557 + .max_length = 0,
108558 + .decl_required = false,
108559 + // need type declaration
108560 + .type_required = true,
108561 + .function_type_required = false,
108562 + .handler = handle_randomize_layout_attr,
108563 +#if BUILDING_GCC_VERSION >= 4007
108564 + .affects_type_identity = true
108565 +#endif
108566 +};
108567 +
108568 +static struct attribute_spec randomize_considered_attr = {
108569 + .name = "randomize_considered",
108570 + // related to args
108571 + .min_length = 0,
108572 + .max_length = 0,
108573 + .decl_required = false,
108574 + // need type declaration
108575 + .type_required = true,
108576 + .function_type_required = false,
108577 + .handler = handle_randomize_considered_attr,
108578 +#if BUILDING_GCC_VERSION >= 4007
108579 + .affects_type_identity = false
108580 +#endif
108581 +};
108582 +
108583 +static struct attribute_spec randomize_performed_attr = {
108584 + .name = "randomize_performed",
108585 + // related to args
108586 + .min_length = 0,
108587 + .max_length = 0,
108588 + .decl_required = false,
108589 + // need type declaration
108590 + .type_required = true,
108591 + .function_type_required = false,
108592 + .handler = handle_randomize_performed_attr,
108593 +#if BUILDING_GCC_VERSION >= 4007
108594 + .affects_type_identity = false
108595 +#endif
108596 +};
108597 +
108598 +static void register_attributes(void *event_data, void *data)
108599 +{
108600 + register_attribute(&randomize_layout_attr);
108601 + register_attribute(&no_randomize_layout_attr);
108602 + register_attribute(&randomize_considered_attr);
108603 + register_attribute(&randomize_performed_attr);
108604 +}
108605 +
108606 +static void check_bad_casts_in_constructor(tree var, tree init)
108607 +{
108608 + unsigned HOST_WIDE_INT idx;
108609 + tree field, val;
108610 + tree field_type, val_type;
108611 +
108612 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
108613 + if (TREE_CODE(val) == CONSTRUCTOR) {
108614 + check_bad_casts_in_constructor(var, val);
108615 + continue;
108616 + }
108617 +
108618 + /* pipacs' plugin creates franken-arrays that differ from those produced by
108619 + normal code which all have valid 'field' trees. work around this */
108620 + if (field == NULL_TREE)
108621 + continue;
108622 + field_type = TREE_TYPE(field);
108623 + val_type = TREE_TYPE(val);
108624 +
108625 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
108626 + continue;
108627 +
108628 + if (field_type == val_type)
108629 + continue;
108630 +
108631 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
108632 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
108633 +
108634 + if (field_type == void_type_node)
108635 + continue;
108636 + if (field_type == val_type)
108637 + continue;
108638 + if (TREE_CODE(val_type) != RECORD_TYPE)
108639 + continue;
108640 +
108641 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
108642 + continue;
108643 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
108644 + }
108645 +}
108646 +
108647 +/* derived from the constify plugin */
108648 +static void check_global_variables(void *event_data, void *data)
108649 +{
108650 + struct varpool_node *node;
108651 + tree init;
108652 +
108653 + FOR_EACH_VARIABLE(node) {
108654 + tree var = NODE_DECL(node);
108655 + init = DECL_INITIAL(var);
108656 + if (init == NULL_TREE)
108657 + continue;
108658 +
108659 + if (TREE_CODE(init) != CONSTRUCTOR)
108660 + continue;
108661 +
108662 + check_bad_casts_in_constructor(var, init);
108663 + }
108664 +}
108665 +
108666 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
108667 +{
108668 + basic_block dom;
108669 + gimple dom_stmt;
108670 + gimple call_stmt;
108671 + const_tree dom_lhs;
108672 + const_tree poss_is_err_cond;
108673 + const_tree poss_is_err_func;
108674 + const_tree is_err_arg;
108675 +
108676 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
108677 + if (!dom)
108678 + return false;
108679 +
108680 + dom_stmt = last_stmt(dom);
108681 + if (!dom_stmt)
108682 + return false;
108683 +
108684 + if (gimple_code(dom_stmt) != GIMPLE_COND)
108685 + return false;
108686 +
108687 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
108688 + return false;
108689 +
108690 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
108691 + return false;
108692 +
108693 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
108694 +
108695 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
108696 + return false;
108697 +
108698 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
108699 +
108700 + if (gimple_code(call_stmt) != GIMPLE_CALL)
108701 + return false;
108702 +
108703 + dom_lhs = gimple_get_lhs(call_stmt);
108704 + poss_is_err_func = gimple_call_fndecl(call_stmt);
108705 + if (!poss_is_err_func)
108706 + return false;
108707 + if (dom_lhs != poss_is_err_cond)
108708 + return false;
108709 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
108710 + return false;
108711 +
108712 + is_err_arg = gimple_call_arg(call_stmt, 0);
108713 + if (!is_err_arg)
108714 + return false;
108715 +
108716 + if (is_err_arg != rhs)
108717 + return false;
108718 +
108719 + return true;
108720 +}
108721 +
108722 +static void handle_local_var_initializers(void)
108723 +{
108724 + tree var;
108725 + unsigned int i;
108726 +
108727 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
108728 + tree init = DECL_INITIAL(var);
108729 + if (!init)
108730 + continue;
108731 + if (TREE_CODE(init) != CONSTRUCTOR)
108732 + continue;
108733 + check_bad_casts_in_constructor(var, init);
108734 + }
108735 +}
108736 +
108737 +/*
108738 + * iterate over all statements to find "bad" casts:
108739 + * those where the address of the start of a structure is cast
108740 + * to a pointer of a structure of a different type, or a
108741 + * structure pointer type is cast to a different structure pointer type
108742 + */
108743 +static unsigned int find_bad_casts(void)
108744 +{
108745 + basic_block bb;
108746 +
108747 + handle_local_var_initializers();
108748 +
108749 + FOR_ALL_BB_FN(bb, cfun) {
108750 + gimple_stmt_iterator gsi;
108751 +
108752 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108753 + gimple stmt;
108754 + const_tree lhs;
108755 + const_tree lhs_type;
108756 + const_tree rhs1;
108757 + const_tree rhs_type;
108758 + const_tree ptr_lhs_type;
108759 + const_tree ptr_rhs_type;
108760 + const_tree op0;
108761 + const_tree op0_type;
108762 + enum tree_code rhs_code;
108763 +
108764 + stmt = gsi_stmt(gsi);
108765 +
108766 +#ifdef __DEBUG_PLUGIN
108767 +#ifdef __DEBUG_VERBOSE
108768 + debug_gimple_stmt(stmt);
108769 + debug_tree(gimple_get_lhs(stmt));
108770 +#endif
108771 +#endif
108772 +
108773 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
108774 + continue;
108775 +
108776 +#ifdef __DEBUG_PLUGIN
108777 +#ifdef __DEBUG_VERBOSE
108778 + debug_tree(gimple_assign_rhs1(stmt));
108779 +#endif
108780 +#endif
108781 +
108782 + rhs_code = gimple_assign_rhs_code(stmt);
108783 +
108784 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
108785 + continue;
108786 +
108787 + lhs = gimple_get_lhs(stmt);
108788 + lhs_type = TREE_TYPE(lhs);
108789 + rhs1 = gimple_assign_rhs1(stmt);
108790 + rhs_type = TREE_TYPE(rhs1);
108791 +
108792 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
108793 + TREE_CODE(lhs_type) != POINTER_TYPE)
108794 + continue;
108795 +
108796 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
108797 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
108798 +
108799 + if (ptr_rhs_type == void_type_node)
108800 + continue;
108801 +
108802 + if (ptr_lhs_type == void_type_node)
108803 + continue;
108804 +
108805 + if (dominated_by_is_err(rhs1, bb))
108806 + continue;
108807 +
108808 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
108809 +#ifndef __DEBUG_PLUGIN
108810 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
108811 +#endif
108812 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108813 + continue;
108814 + }
108815 +
108816 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
108817 + continue;
108818 +
108819 + if (rhs_code == ADDR_EXPR) {
108820 + op0 = TREE_OPERAND(rhs1, 0);
108821 +
108822 + if (op0 == NULL_TREE)
108823 + continue;
108824 +
108825 + if (TREE_CODE(op0) != VAR_DECL)
108826 + continue;
108827 +
108828 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
108829 + if (op0_type == ptr_lhs_type)
108830 + continue;
108831 +
108832 +#ifndef __DEBUG_PLUGIN
108833 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
108834 +#endif
108835 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
108836 + } else {
108837 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
108838 + /* skip bogus type casts introduced by container_of */
108839 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
108840 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
108841 + continue;
108842 +#ifndef __DEBUG_PLUGIN
108843 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
108844 +#endif
108845 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108846 + }
108847 +
108848 + }
108849 + }
108850 + return 0;
108851 +}
108852 +
108853 +#if BUILDING_GCC_VERSION >= 4009
108854 +static const struct pass_data randomize_layout_bad_cast_data = {
108855 +#else
108856 +static struct gimple_opt_pass randomize_layout_bad_cast = {
108857 + .pass = {
108858 +#endif
108859 + .type = GIMPLE_PASS,
108860 + .name = "randomize_layout_bad_cast",
108861 +#if BUILDING_GCC_VERSION >= 4008
108862 + .optinfo_flags = OPTGROUP_NONE,
108863 +#endif
108864 +#if BUILDING_GCC_VERSION >= 4009
108865 + .has_gate = false,
108866 + .has_execute = true,
108867 +#else
108868 + .gate = NULL,
108869 + .execute = find_bad_casts,
108870 + .sub = NULL,
108871 + .next = NULL,
108872 + .static_pass_number = 0,
108873 +#endif
108874 + .tv_id = TV_NONE,
108875 + .properties_required = PROP_cfg,
108876 + .properties_provided = 0,
108877 + .properties_destroyed = 0,
108878 + .todo_flags_start = 0,
108879 + .todo_flags_finish = TODO_dump_func
108880 +#if BUILDING_GCC_VERSION < 4009
108881 + }
108882 +#endif
108883 +};
108884 +
108885 +#if BUILDING_GCC_VERSION >= 4009
108886 +namespace {
108887 +class randomize_layout_bad_cast : public gimple_opt_pass {
108888 +public:
108889 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
108890 + unsigned int execute() { return find_bad_casts(); }
108891 +};
108892 +}
108893 +#endif
108894 +
108895 +static struct opt_pass *make_randomize_layout_bad_cast(void)
108896 +{
108897 +#if BUILDING_GCC_VERSION >= 4009
108898 + return new randomize_layout_bad_cast();
108899 +#else
108900 + return &randomize_layout_bad_cast.pass;
108901 +#endif
108902 +}
108903 +
108904 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108905 +{
108906 + int i;
108907 + const char * const plugin_name = plugin_info->base_name;
108908 + const int argc = plugin_info->argc;
108909 + const struct plugin_argument * const argv = plugin_info->argv;
108910 + bool enable = true;
108911 + int obtained_seed = 0;
108912 + struct register_pass_info randomize_layout_bad_cast_info;
108913 +
108914 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
108915 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
108916 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
108917 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
108918 +
108919 + if (!plugin_default_version_check(version, &gcc_version)) {
108920 + error(G_("incompatible gcc/plugin versions"));
108921 + return 1;
108922 + }
108923 +
108924 + if (strcmp(lang_hooks.name, "GNU C")) {
108925 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
108926 + enable = false;
108927 + }
108928 +
108929 + for (i = 0; i < argc; ++i) {
108930 + if (!strcmp(argv[i].key, "disable")) {
108931 + enable = false;
108932 + continue;
108933 + }
108934 + if (!strcmp(argv[i].key, "performance-mode")) {
108935 + performance_mode = 1;
108936 + continue;
108937 + }
108938 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108939 + }
108940 +
108941 + if (strlen(randstruct_seed) != 64) {
108942 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
108943 + return 1;
108944 + }
108945 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
108946 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
108947 + if (obtained_seed != 4) {
108948 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
108949 + return 1;
108950 + }
108951 +
108952 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
108953 + if (enable) {
108954 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
108955 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
108956 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
108957 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
108958 + }
108959 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108960 +
108961 + return 0;
108962 +}
108963 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
108964 new file mode 100644
108965 index 0000000..9529806
108966 --- /dev/null
108967 +++ b/tools/gcc/size_overflow_hash.data
108968 @@ -0,0 +1,5709 @@
108969 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
108970 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
108971 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
108972 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
108973 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
108974 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
108975 +padzero_55 padzero 1 55 &sel_read_policyvers_55
108976 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
108977 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
108978 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
108979 +load_msg_95 load_msg 2 95 NULL
108980 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
108981 +init_q_132 init_q 4 132 NULL
108982 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
108983 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
108984 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
108985 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
108986 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
108987 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
108988 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
108989 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
108990 +br_port_info_size_268 br_port_info_size 0 268 NULL
108991 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
108992 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
108993 +SYSC_connect_304 SYSC_connect 3 304 NULL
108994 +syslog_print_307 syslog_print 2 307 NULL
108995 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
108996 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
108997 +hw_device_state_409 hw_device_state 0 409 NULL
108998 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
108999 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
109000 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
109001 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
109002 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
109003 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
109004 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
109005 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
109006 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
109007 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
109008 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
109009 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
109010 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
109011 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
109012 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
109013 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
109014 +osl_pktget_590 osl_pktget 2 590 NULL
109015 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
109016 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
109017 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
109018 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
109019 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
109020 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
109021 +clone_split_bio_633 clone_split_bio 6 633 NULL
109022 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
109023 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
109024 +unlink_queued_645 unlink_queued 4 645 NULL
109025 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
109026 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
109027 +persistent_ram_vmap_709 persistent_ram_vmap 1-2 709 NULL
109028 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
109029 +dvb_video_write_754 dvb_video_write 3 754 NULL
109030 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
109031 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
109032 +if_writecmd_815 if_writecmd 2 815 NULL
109033 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
109034 +error_state_read_859 error_state_read 6 859 NULL
109035 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
109036 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
109037 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
109038 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
109039 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
109040 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
109041 +memcmp_990 memcmp 0 990 NULL
109042 +readreg_1017 readreg 0-1 1017 NULL
109043 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
109044 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
109045 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
109046 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
109047 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
109048 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
109049 +llc_mac_hdr_init_1094 llc_mac_hdr_init 0 1094 NULL
109050 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
109051 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
109052 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
109053 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
109054 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
109055 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
109056 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
109057 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
109058 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
109059 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
109060 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
109061 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
109062 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
109063 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
109064 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
109065 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
109066 +ffs_1322 ffs 0 1322 NULL
109067 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
109068 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
109069 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
109070 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
109071 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
109072 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
109073 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
109074 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
109075 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
109076 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
109077 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
109078 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
109079 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
109080 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
109081 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
109082 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
109083 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
109084 +fpregs_set_1497 fpregs_set 4 1497 NULL
109085 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
109086 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
109087 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
109088 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
109089 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
109090 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
109091 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
109092 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
109093 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
109094 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
109095 +rmap_add_1677 rmap_add 3 1677 NULL
109096 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
109097 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
109098 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
109099 +internal_create_group_1733 internal_create_group 0 1733 NULL
109100 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
109101 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
109102 +cosa_write_1774 cosa_write 3 1774 NULL
109103 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
109104 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
109105 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
109106 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
109107 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
109108 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
109109 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
109110 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
109111 +bdev_erase_1933 bdev_erase 3 1933 NULL
109112 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
109113 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
109114 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
109115 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
109116 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
109117 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
109118 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
109119 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
109120 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
109121 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
109122 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
109123 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
109124 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
109125 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
109126 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
109127 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
109128 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
109129 +audit_expand_2098 audit_expand 0 2098 NULL
109130 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
109131 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
109132 +enable_read_2117 enable_read 3 2117 NULL
109133 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
109134 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
109135 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
109136 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
109137 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
109138 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
109139 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
109140 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
109141 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
109142 +vhci_write_2224 vhci_write 3 2224 NULL
109143 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
109144 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
109145 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
109146 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
109147 +do_update_counters_2259 do_update_counters 4 2259 NULL
109148 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
109149 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
109150 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
109151 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
109152 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
109153 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
109154 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
109155 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
109156 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
109157 +sysfs_add_file_mode_ns_2362 sysfs_add_file_mode_ns 0 2362 NULL
109158 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
109159 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
109160 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
109161 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
109162 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
109163 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
109164 +raid1_size_2419 raid1_size 0-2 2419 NULL
109165 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
109166 +wiphy_new_2482 wiphy_new 2 2482 NULL
109167 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
109168 +hfsplus_user_setxattr_2485 hfsplus_user_setxattr 4 2485 NULL
109169 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
109170 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
109171 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
109172 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
109173 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
109174 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
109175 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
109176 +slot_bytes_2609 slot_bytes 0 2609 NULL
109177 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
109178 +switch_status_2629 switch_status 5 2629 NULL
109179 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
109180 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
109181 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
109182 +oti6858_write_2692 oti6858_write 4 2692 NULL
109183 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
109184 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
109185 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
109186 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
109187 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
109188 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
109189 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
109190 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
109191 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
109192 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
109193 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
109194 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
109195 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
109196 +nla_padlen_2883 nla_padlen 1 2883 NULL
109197 +cmm_write_2896 cmm_write 3 2896 NULL
109198 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
109199 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
109200 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
109201 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
109202 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
109203 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
109204 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
109205 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
109206 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
109207 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
109208 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
109209 +depth_write_3021 depth_write 3 3021 NULL
109210 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
109211 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
109212 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
109213 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
109214 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
109215 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
109216 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
109217 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
109218 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
109219 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
109220 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
109221 +clone_bio_3100 clone_bio 6 3100 NULL nohasharray
109222 +ttusb2_msg_3100 ttusb2_msg 4 3100 &clone_bio_3100
109223 +rb_alloc_3102 rb_alloc 1 3102 NULL
109224 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
109225 +print_time_3132 print_time 0 3132 NULL
109226 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
109227 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
109228 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
109229 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
109230 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
109231 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
109232 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
109233 +alloc_context_3194 alloc_context 1 3194 NULL
109234 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
109235 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
109236 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
109237 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
109238 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
109239 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
109240 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
109241 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
109242 +key_key_read_3241 key_key_read 3 3241 NULL
109243 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
109244 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
109245 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
109246 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
109247 +ocfs2_extend_xattr_bucket_3328 ocfs2_extend_xattr_bucket 4 3328 NULL
109248 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
109249 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
109250 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
109251 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
109252 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
109253 +scnprintf_3360 scnprintf 0-2 3360 NULL
109254 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
109255 +sr_read_3366 sr_read 3 3366 NULL
109256 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
109257 +send_stream_3397 send_stream 4 3397 NULL
109258 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
109259 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
109260 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
109261 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
109262 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
109263 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
109264 +s3fb_ddc_read_3451 s3fb_ddc_read 0 3451 NULL
109265 +softsynth_write_3455 softsynth_write 3 3455 NULL
109266 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL nohasharray
109267 +jffs2_acl_setxattr_3464 jffs2_acl_setxattr 4 3464 &snd_pcm_lib_readv_transfer_3464
109268 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
109269 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
109270 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
109271 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
109272 +SyS_readv_3539 SyS_readv 3 3539 NULL
109273 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
109274 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
109275 +evtchn_read_3569 evtchn_read 3 3569 NULL
109276 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
109277 +vc_resize_3585 vc_resize 3-2 3585 NULL
109278 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
109279 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
109280 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
109281 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
109282 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
109283 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
109284 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
109285 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
109286 +ci_ll_write_3740 ci_ll_write 4 3740 NULL nohasharray
109287 +ath6kl_mgmt_tx_3740 ath6kl_mgmt_tx 7 3740 &ci_ll_write_3740
109288 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
109289 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
109290 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
109291 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
109292 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
109293 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
109294 +get_fd_set_3866 get_fd_set 1 3866 NULL
109295 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
109296 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
109297 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
109298 +nvram_write_3894 nvram_write 3 3894 NULL
109299 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
109300 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
109301 +vcs_write_3910 vcs_write 3 3910 NULL
109302 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
109303 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
109304 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
109305 +ll_get_max_mdsize_3962 ll_get_max_mdsize 0 3962 NULL
109306 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
109307 +do_add_counters_3992 do_add_counters 3 3992 NULL
109308 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
109309 +userspace_status_4004 userspace_status 4 4004 NULL
109310 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
109311 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
109312 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
109313 +blk_end_request_4024 blk_end_request 3 4024 NULL
109314 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
109315 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
109316 +read_file_queues_4078 read_file_queues 3 4078 NULL
109317 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
109318 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
109319 +tm6000_read_4151 tm6000_read 3 4151 NULL
109320 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
109321 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
109322 +get_alua_req_4166 get_alua_req 3 4166 NULL
109323 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
109324 +read_file_bool_4180 read_file_bool 3 4180 NULL
109325 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
109326 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
109327 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
109328 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
109329 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
109330 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
109331 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
109332 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
109333 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 3-2-5 4303 NULL
109334 +count_strings_4315 count_strings 0 4315 NULL
109335 +__sysfs_add_one_4326 __sysfs_add_one 0 4326 NULL
109336 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
109337 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
109338 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
109339 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
109340 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
109341 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
109342 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
109343 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
109344 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
109345 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
109346 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
109347 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
109348 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
109349 +set_link_security_4502 set_link_security 4 4502 NULL
109350 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
109351 +tty_register_device_4544 tty_register_device 2 4544 NULL
109352 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
109353 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
109354 +bch_alloc_4593 bch_alloc 1 4593 NULL
109355 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
109356 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
109357 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
109358 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
109359 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
109360 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
109361 +kone_receive_4690 kone_receive 4 4690 NULL
109362 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
109363 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
109364 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
109365 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
109366 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
109367 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
109368 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
109369 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
109370 +create_subvol_4791 create_subvol 4 4791 NULL
109371 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
109372 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
109373 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
109374 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
109375 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
109376 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
109377 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
109378 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
109379 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
109380 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
109381 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
109382 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
109383 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
109384 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
109385 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
109386 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
109387 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
109388 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
109389 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
109390 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
109391 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
109392 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
109393 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
109394 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
109395 +sound_write_5102 sound_write 3 5102 NULL
109396 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
109397 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
109398 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
109399 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
109400 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
109401 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
109402 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
109403 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
109404 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
109405 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
109406 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
109407 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
109408 +cq_free_res_5355 cq_free_res 5 5355 NULL
109409 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
109410 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
109411 +__split_bvec_across_targets_5454 __split_bvec_across_targets 3 5454 NULL
109412 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
109413 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
109414 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
109415 +tty_write_5494 tty_write 3 5494 NULL
109416 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
109417 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
109418 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
109419 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
109420 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
109421 +le_readq_5557 le_readq 0 5557 NULL
109422 +inw_5558 inw 0 5558 NULL
109423 +bioset_create_5580 bioset_create 1 5580 NULL
109424 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
109425 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
109426 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
109427 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
109428 +get_arg_5694 get_arg 3 5694 NULL
109429 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
109430 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
109431 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
109432 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
109433 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
109434 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
109435 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
109436 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
109437 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
109438 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
109439 +setup_req_5848 setup_req 3-0 5848 NULL
109440 +ria_page_count_5849 ria_page_count 0 5849 NULL
109441 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
109442 +config_buf_5862 config_buf 0 5862 NULL
109443 +iwl_dbgfs_scan_ant_rxchain_write_5877 iwl_dbgfs_scan_ant_rxchain_write 3 5877 NULL
109444 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
109445 +port_show_regs_5904 port_show_regs 3 5904 NULL
109446 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
109447 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
109448 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
109449 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
109450 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
109451 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
109452 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
109453 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
109454 +SyS_semop_5980 SyS_semop 3 5980 NULL
109455 +alloc_msg_6072 alloc_msg 1 6072 NULL
109456 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
109457 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
109458 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
109459 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
109460 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
109461 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
109462 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
109463 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
109464 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
109465 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
109466 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
109467 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
109468 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
109469 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
109470 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
109471 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
109472 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
109473 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
109474 +serial_port_in_6291 serial_port_in 0 6291 NULL
109475 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
109476 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
109477 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
109478 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
109479 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
109480 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
109481 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
109482 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
109483 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
109484 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
109485 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
109486 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
109487 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
109488 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
109489 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
109490 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
109491 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
109492 +mei_read_6507 mei_read 3 6507 NULL
109493 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
109494 +wdm_read_6549 wdm_read 3 6549 NULL
109495 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
109496 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
109497 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
109498 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
109499 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
109500 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
109501 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
109502 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
109503 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
109504 +mpeg_read_6708 mpeg_read 3 6708 NULL
109505 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
109506 +video_proc_write_6724 video_proc_write 3 6724 NULL
109507 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
109508 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
109509 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
109510 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
109511 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
109512 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
109513 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
109514 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
109515 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
109516 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
109517 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
109518 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
109519 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
109520 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
109521 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
109522 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
109523 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
109524 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
109525 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
109526 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
109527 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
109528 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
109529 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
109530 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
109531 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
109532 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
109533 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
109534 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
109535 +request_key_async_6990 request_key_async 4 6990 NULL
109536 +tpl_write_6998 tpl_write 3 6998 NULL
109537 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
109538 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
109539 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
109540 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
109541 +wimax_msg_7030 wimax_msg 4 7030 NULL
109542 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
109543 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
109544 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
109545 +event_enable_read_7074 event_enable_read 3 7074 NULL
109546 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
109547 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
109548 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
109549 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
109550 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
109551 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
109552 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
109553 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
109554 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
109555 +get_string_7302 get_string 0 7302 NULL
109556 +mgmt_control_7349 mgmt_control 3 7349 NULL
109557 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
109558 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
109559 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
109560 +hweight_long_7388 hweight_long 1-0 7388 NULL
109561 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
109562 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
109563 +readb_7401 readb 0 7401 NULL
109564 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
109565 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
109566 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
109567 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
109568 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
109569 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
109570 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
109571 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
109572 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
109573 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
109574 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
109575 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
109576 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
109577 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
109578 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
109579 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
109580 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
109581 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
109582 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
109583 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
109584 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
109585 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
109586 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
109587 +dev_write_7708 dev_write 3 7708 NULL
109588 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
109589 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
109590 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
109591 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
109592 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
109593 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
109594 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
109595 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
109596 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
109597 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
109598 +config_desc_7878 config_desc 0 7878 NULL
109599 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
109600 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
109601 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
109602 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
109603 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
109604 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
109605 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
109606 +vcs_read_8017 vcs_read 3 8017 NULL
109607 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
109608 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
109609 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
109610 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
109611 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
109612 +venus_lookup_8121 venus_lookup 4 8121 NULL
109613 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
109614 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
109615 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
109616 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
109617 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
109618 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
109619 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
109620 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
109621 +play_iframe_8219 play_iframe 3 8219 NULL
109622 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
109623 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
109624 +ceph_sync_write_8233 ceph_sync_write 4 8233 NULL
109625 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
109626 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
109627 +init_cdev_8274 init_cdev 1 8274 NULL
109628 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
109629 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
109630 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
109631 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
109632 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
109633 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
109634 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
109635 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
109636 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
109637 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
109638 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
109639 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
109640 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
109641 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
109642 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
109643 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
109644 +dev_config_8506 dev_config 3 8506 NULL
109645 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
109646 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
109647 +user_on_off_8552 user_on_off 2 8552 NULL
109648 +profile_remove_8556 profile_remove 3 8556 NULL
109649 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
109650 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
109651 +tower_write_8580 tower_write 3 8580 NULL
109652 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
109653 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
109654 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
109655 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
109656 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
109657 +generic_acl_set_8658 generic_acl_set 4 8658 NULL
109658 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
109659 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
109660 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
109661 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
109662 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
109663 +arcfb_write_8702 arcfb_write 3 8702 NULL
109664 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
109665 +init_header_8703 init_header 0 8703 &i_size_read_8703
109666 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
109667 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
109668 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
109669 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
109670 +__create_irqs_8733 __create_irqs 2 8733 NULL
109671 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
109672 +compound_order_8750 compound_order 0 8750 NULL
109673 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
109674 +yurex_write_8761 yurex_write 3 8761 NULL
109675 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
109676 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
109677 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
109678 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
109679 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
109680 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
109681 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
109682 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
109683 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
109684 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
109685 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
109686 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
109687 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
109688 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
109689 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
109690 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
109691 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
109692 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
109693 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
109694 +write_file_ani_8918 write_file_ani 3 8918 NULL
109695 +layout_commit_8926 layout_commit 3 8926 NULL
109696 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
109697 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
109698 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
109699 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
109700 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
109701 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
109702 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
109703 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
109704 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
109705 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
109706 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
109707 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
109708 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
109709 +nla_put_9042 nla_put 3 9042 NULL
109710 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
109711 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
109712 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
109713 +create_queues_9088 create_queues 2-3 9088 NULL
109714 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
109715 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
109716 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
109717 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110
109718 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
109719 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
109720 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
109721 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
109722 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
109723 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
109724 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
109725 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
109726 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
109727 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
109728 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
109729 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
109730 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
109731 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
109732 +flakey_status_9274 flakey_status 5 9274 NULL
109733 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
109734 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
109735 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
109736 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
109737 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
109738 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
109739 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
109740 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
109741 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
109742 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
109743 +read_9397 read 3 9397 NULL
109744 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
109745 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
109746 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
109747 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
109748 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
109749 +ext3_xattr_set_acl_9467 ext3_xattr_set_acl 4 9467 NULL
109750 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
109751 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
109752 +crypt_status_9492 crypt_status 5 9492 NULL
109753 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
109754 +lp_write_9511 lp_write 3 9511 NULL
109755 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
109756 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
109757 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
109758 +read_file_dma_9530 read_file_dma 3 9530 NULL
109759 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
109760 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
109761 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
109762 +fw_node_create_9559 fw_node_create 2 9559 NULL
109763 +kobj_map_9566 kobj_map 2-3 9566 NULL
109764 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
109765 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
109766 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
109767 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
109768 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
109769 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
109770 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
109771 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
109772 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
109773 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
109774 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
109775 +dns_query_9676 dns_query 3 9676 NULL
109776 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
109777 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
109778 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
109779 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
109780 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
109781 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
109782 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
109783 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
109784 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
109785 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
109786 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
109787 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
109788 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
109789 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
109790 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
109791 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
109792 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
109793 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
109794 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
109795 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
109796 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
109797 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
109798 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
109799 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
109800 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
109801 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
109802 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
109803 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
109804 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
109805 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
109806 +read_file_misc_9948 read_file_misc 3 9948 NULL
109807 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
109808 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
109809 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
109810 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
109811 +gameport_read_9983 gameport_read 0 9983 NULL
109812 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
109813 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
109814 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
109815 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
109816 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
109817 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
109818 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
109819 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
109820 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
109821 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
109822 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
109823 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
109824 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
109825 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
109826 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
109827 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
109828 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
109829 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
109830 +read_emulate_10310 read_emulate 2-4 10310 NULL
109831 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
109832 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
109833 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
109834 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
109835 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
109836 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
109837 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
109838 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
109839 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
109840 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
109841 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
109842 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
109843 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
109844 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
109845 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
109846 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
109847 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
109848 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
109849 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
109850 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
109851 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
109852 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
109853 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
109854 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
109855 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
109856 +otp_read_10594 otp_read 2-4-5 10594 NULL
109857 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
109858 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
109859 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
109860 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
109861 +parport_write_10669 parport_write 0 10669 NULL
109862 +edge_write_10692 edge_write 4 10692 NULL
109863 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
109864 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
109865 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
109866 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
109867 +spi_sync_10731 spi_sync 0 10731 NULL
109868 +apu_get_register_10737 apu_get_register 0 10737 NULL nohasharray
109869 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 &apu_get_register_10737
109870 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
109871 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
109872 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
109873 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
109874 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
109875 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
109876 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
109877 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
109878 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
109879 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
109880 +get_scq_10897 get_scq 2 10897 NULL
109881 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
109882 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
109883 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
109884 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
109885 +kobject_add_10919 kobject_add 0 10919 NULL
109886 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
109887 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
109888 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
109889 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
109890 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
109891 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
109892 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
109893 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
109894 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
109895 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
109896 +count_argc_11083 count_argc 0 11083 NULL
109897 +ocfs2_blocks_per_xattr_bucket_11099 ocfs2_blocks_per_xattr_bucket 0 11099 NULL
109898 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
109899 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
109900 +page_offset_11120 page_offset 0 11120 NULL
109901 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
109902 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
109903 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
109904 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
109905 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
109906 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
109907 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
109908 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
109909 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
109910 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
109911 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
109912 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
109913 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
109914 +construct_key_11329 construct_key 3 11329 NULL nohasharray
109915 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
109916 +next_segment_11330 next_segment 0-2-1 11330 NULL
109917 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 2-1 11332 NULL
109918 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
109919 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
109920 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
109921 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
109922 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
109923 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
109924 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
109925 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
109926 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
109927 +str_to_user_11411 str_to_user 2 11411 NULL
109928 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
109929 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
109930 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL nohasharray
109931 +import_sec_validate_get_11417 import_sec_validate_get 0 11417 &adis16480_show_firmware_revision_11417
109932 +trace_options_read_11419 trace_options_read 3 11419 NULL
109933 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
109934 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
109935 +bttv_read_11432 bttv_read 3 11432 NULL
109936 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
109937 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
109938 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
109939 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
109940 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
109941 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
109942 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
109943 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
109944 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
109945 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
109946 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
109947 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
109948 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
109949 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
109950 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
109951 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
109952 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
109953 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
109954 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
109955 +slab_ksize_11664 slab_ksize 0 11664 NULL
109956 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
109957 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
109958 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
109959 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
109960 +split_11691 split 2 11691 NULL
109961 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
109962 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
109963 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
109964 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
109965 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
109966 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
109967 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
109968 +umc_device_register_11824 umc_device_register 0 11824 NULL
109969 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
109970 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
109971 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
109972 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
109973 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
109974 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
109975 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
109976 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
109977 +ti_write_11916 ti_write 4 11916 NULL
109978 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
109979 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
109980 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
109981 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
109982 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
109983 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
109984 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
109985 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
109986 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
109987 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
109988 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
109989 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
109990 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
109991 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
109992 +set_powered_12129 set_powered 4 12129 NULL
109993 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
109994 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
109995 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
109996 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
109997 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
109998 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
109999 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
110000 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
110001 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
110002 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
110003 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
110004 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
110005 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
110006 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
110007 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
110008 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
110009 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
110010 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
110011 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
110012 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
110013 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
110014 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
110015 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
110016 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
110017 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
110018 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
110019 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 NULL nohasharray
110020 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391 nohasharray
110021 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
110022 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
110023 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
110024 +ptlrpc_set_wait_12426 ptlrpc_set_wait 0 12426 NULL
110025 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
110026 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
110027 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
110028 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
110029 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
110030 +xfs_get_extsz_hint_12531 xfs_get_extsz_hint 0 12531 NULL
110031 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
110032 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
110033 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
110034 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
110035 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
110036 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
110037 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
110038 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
110039 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
110040 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
110041 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
110042 +lustre_pack_request_v2_12665 lustre_pack_request_v2 0 12665 NULL
110043 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
110044 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
110045 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
110046 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
110047 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
110048 +ivtv_write_12721 ivtv_write 3 12721 NULL
110049 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
110050 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
110051 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
110052 +listxattr_12769 listxattr 3 12769 NULL
110053 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
110054 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
110055 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
110056 +readq_12825 readq 0 12825 NULL
110057 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
110058 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
110059 +spidev_sync_12842 spidev_sync 0 12842 NULL
110060 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
110061 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
110062 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
110063 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
110064 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
110065 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
110066 +bm_status_write_12964 bm_status_write 3 12964 NULL
110067 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
110068 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
110069 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
110070 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
110071 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
110072 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
110073 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
110074 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
110075 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
110076 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
110077 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
110078 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
110079 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
110080 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
110081 +blk_update_request_13146 blk_update_request 3 13146 NULL
110082 +ocfs2_quota_trans_credits_13150 ocfs2_quota_trans_credits 0 13150 NULL
110083 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
110084 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
110085 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
110086 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
110087 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
110088 +comedi_read_13199 comedi_read 3 13199 NULL
110089 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
110090 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
110091 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
110092 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
110093 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
110094 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
110095 +bio_integrity_trim_13259 bio_integrity_trim 3 13259 NULL
110096 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
110097 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
110098 +il4965_stats_flag_13281 il4965_stats_flag 3-0 13281 NULL
110099 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
110100 +sd_major_13294 sd_major 0-1 13294 NULL
110101 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
110102 +__clone_and_map_data_bio_13334 __clone_and_map_data_bio 4-8 13334 NULL
110103 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
110104 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
110105 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
110106 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
110107 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
110108 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
110109 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
110110 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
110111 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
110112 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
110113 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
110114 +data_read_13494 data_read 3 13494 NULL
110115 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
110116 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
110117 +core_status_13515 core_status 4 13515 NULL
110118 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
110119 +bm_init_13529 bm_init 2 13529 NULL
110120 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
110121 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
110122 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
110123 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
110124 +cache_write_13589 cache_write 3 13589 NULL
110125 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
110126 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
110127 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
110128 +packet_snd_13634 packet_snd 3 13634 NULL
110129 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
110130 +cache_downcall_13666 cache_downcall 3 13666 NULL
110131 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
110132 +nv94_aux_13689 nv94_aux 2-5 13689 NULL
110133 +usb_get_string_13693 usb_get_string 0 13693 NULL
110134 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
110135 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
110136 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
110137 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
110138 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
110139 +random_read_13815 random_read 3 13815 NULL
110140 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
110141 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
110142 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
110143 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
110144 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
110145 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
110146 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
110147 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
110148 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
110149 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
110150 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
110151 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
110152 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
110153 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
110154 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
110155 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
110156 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
110157 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
110158 +qcam_read_13977 qcam_read 3 13977 NULL
110159 +dsp_read_13980 dsp_read 2 13980 NULL
110160 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
110161 +create_files_14003 create_files 0 14003 NULL
110162 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
110163 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
110164 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
110165 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
110166 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
110167 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
110168 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
110169 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
110170 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
110171 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
110172 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
110173 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
110174 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
110175 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
110176 +em_canid_change_14150 em_canid_change 3 14150 NULL
110177 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
110178 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
110179 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
110180 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
110181 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
110182 +alloc_async_14208 alloc_async 1 14208 NULL
110183 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
110184 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
110185 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
110186 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
110187 +rr_status_14293 rr_status 5 14293 NULL
110188 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
110189 +oo_objects_14319 oo_objects 0 14319 NULL
110190 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
110191 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
110192 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
110193 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
110194 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
110195 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
110196 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
110197 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
110198 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
110199 +block_size_14443 block_size 0 14443 NULL
110200 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
110201 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
110202 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
110203 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
110204 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
110205 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
110206 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
110207 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
110208 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
110209 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
110210 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
110211 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
110212 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
110213 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
110214 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
110215 +dbJoin_14644 dbJoin 0 14644 NULL
110216 +profile_replace_14652 profile_replace 3 14652 NULL
110217 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
110218 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
110219 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
110220 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
110221 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
110222 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
110223 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
110224 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
110225 +cgroup_path_14713 cgroup_path 3 14713 NULL
110226 +vfd_write_14717 vfd_write 3 14717 NULL
110227 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
110228 +raid1_resize_14740 raid1_resize 2 14740 NULL
110229 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
110230 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
110231 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
110232 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
110233 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
110234 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
110235 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
110236 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
110237 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
110238 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
110239 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
110240 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
110241 +lcd_write_14857 lcd_write 3 14857 NULL
110242 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
110243 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
110244 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
110245 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
110246 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
110247 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
110248 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
110249 +queue_cnt_14951 queue_cnt 0 14951 NULL
110250 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
110251 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
110252 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
110253 +setkey_14987 setkey 3 14987 NULL nohasharray
110254 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
110255 +xfs_dinode_size_14996 xfs_dinode_size 0 14996 NULL
110256 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
110257 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
110258 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
110259 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
110260 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
110261 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
110262 +ceph_calc_ceph_pg_15075 ceph_calc_ceph_pg 0 15075 NULL
110263 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
110264 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
110265 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
110266 +start_port_15124 start_port 0 15124 NULL
110267 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
110268 +iwl_dbgfs_sta_drain_write_15167 iwl_dbgfs_sta_drain_write 3 15167 NULL
110269 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
110270 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
110271 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
110272 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
110273 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
110274 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
110275 +simple_strtol_15273 simple_strtol 0 15273 NULL
110276 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
110277 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
110278 +xlog_ticket_alloc_15335 xlog_ticket_alloc 2 15335 NULL
110279 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
110280 +ioread16_15342 ioread16 0 15342 NULL
110281 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
110282 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
110283 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
110284 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
110285 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
110286 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
110287 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
110288 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
110289 +get_modalias_15406 get_modalias 2 15406 NULL
110290 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
110291 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
110292 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
110293 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
110294 +memweight_15450 memweight 2 15450 NULL
110295 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
110296 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
110297 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
110298 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
110299 +persistent_status_15574 persistent_status 4 15574 NULL
110300 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
110301 +vme_user_write_15587 vme_user_write 3 15587 NULL
110302 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
110303 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
110304 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
110305 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
110306 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
110307 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
110308 +fs_path_add_15648 fs_path_add 3 15648 NULL
110309 +xsd_read_15653 xsd_read 3 15653 NULL
110310 +unix_bind_15668 unix_bind 3 15668 NULL
110311 +dm_read_15674 dm_read 3 15674 NULL nohasharray
110312 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
110313 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
110314 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
110315 +bio_map_15794 bio_map 3-0 15794 NULL
110316 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
110317 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
110318 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
110319 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
110320 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
110321 +table_size_15851 table_size 0-1-2 15851 NULL
110322 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
110323 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
110324 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
110325 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
110326 +native_read_msr_15905 native_read_msr 0 15905 NULL
110327 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
110328 +power_read_15939 power_read 3 15939 NULL
110329 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
110330 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
110331 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
110332 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
110333 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
110334 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
110335 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
110336 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
110337 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
110338 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
110339 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
110340 +fsm_init_16134 fsm_init 2 16134 NULL
110341 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
110342 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
110343 +mapping_level_16188 mapping_level 2-0 16188 NULL
110344 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
110345 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
110346 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
110347 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
110348 +create_table_16213 create_table 2 16213 NULL
110349 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
110350 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
110351 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
110352 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
110353 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
110354 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
110355 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
110356 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
110357 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
110358 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
110359 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
110360 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
110361 +account_16283 account 0-4-2 16283 NULL nohasharray
110362 +mirror_status_16283 mirror_status 5 16283 &account_16283
110363 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
110364 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
110365 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
110366 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
110367 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
110368 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
110369 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
110370 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
110371 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
110372 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
110373 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
110374 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
110375 +cmdline_store_16442 cmdline_store 4 16442 NULL
110376 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
110377 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
110378 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
110379 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
110380 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
110381 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
110382 +raid10_resize_16537 raid10_resize 2 16537 NULL
110383 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
110384 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
110385 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
110386 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
110387 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
110388 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
110389 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
110390 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
110391 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
110392 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
110393 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
110394 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
110395 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
110396 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
110397 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
110398 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
110399 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
110400 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
110401 +st_write_16874 st_write 3 16874 NULL
110402 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
110403 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
110404 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
110405 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
110406 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
110407 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
110408 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
110409 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
110410 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
110411 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
110412 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
110413 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
110414 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
110415 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
110416 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
110417 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
110418 +entry_length_17093 entry_length 0 17093 NULL
110419 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
110420 +write_mem_17114 write_mem 3 17114 NULL
110421 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
110422 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
110423 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
110424 +sep_read_17161 sep_read 3 17161 NULL
110425 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
110426 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
110427 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
110428 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
110429 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
110430 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
110431 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
110432 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
110433 +sync_request_17208 sync_request 2 17208 NULL
110434 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
110435 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
110436 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
110437 +alloc_ep_17269 alloc_ep 1 17269 NULL
110438 +pg_read_17276 pg_read 3 17276 NULL
110439 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
110440 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
110441 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
110442 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
110443 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 0 17298 NULL
110444 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
110445 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
110446 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
110447 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
110448 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
110449 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
110450 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
110451 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
110452 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
110453 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
110454 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
110455 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
110456 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
110457 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
110458 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
110459 +qp_free_res_17541 qp_free_res 5 17541 NULL
110460 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
110461 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
110462 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
110463 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
110464 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
110465 +osst_execute_17607 osst_execute 7-6 17607 NULL
110466 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
110467 +dma_map_page_17628 dma_map_page 0 17628 NULL
110468 +ocfs2_rotate_subtree_left_17634 ocfs2_rotate_subtree_left 5 17634 NULL
110469 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
110470 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
110471 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
110472 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
110473 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
110474 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
110475 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
110476 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
110477 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
110478 +brcmf_sdio_chip_verifynvram_17776 brcmf_sdio_chip_verifynvram 4 17776 NULL
110479 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
110480 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
110481 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
110482 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
110483 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
110484 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
110485 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
110486 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
110487 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
110488 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
110489 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
110490 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
110491 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
110492 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
110493 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
110494 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
110495 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
110496 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
110497 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
110498 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
110499 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
110500 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
110501 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
110502 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
110503 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
110504 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
110505 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
110506 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
110507 +fpregs_get_18066 fpregs_get 4 18066 NULL
110508 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
110509 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
110510 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
110511 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
110512 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
110513 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
110514 +svc_getnl_18120 svc_getnl 0 18120 NULL
110515 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
110516 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
110517 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
110518 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
110519 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
110520 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
110521 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
110522 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
110523 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
110524 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
110525 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
110526 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
110527 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
110528 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
110529 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
110530 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
110531 +um_idi_write_18293 um_idi_write 3 18293 NULL
110532 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
110533 +vga_r_18310 vga_r 0 18310 NULL
110534 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
110535 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
110536 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
110537 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
110538 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
110539 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
110540 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
110541 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
110542 +ep_io_18367 ep_io 0 18367 NULL
110543 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
110544 +ci_role_write_18388 ci_role_write 3 18388 NULL
110545 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
110546 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
110547 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
110548 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
110549 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
110550 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
110551 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
110552 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
110553 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
110554 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
110555 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
110556 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
110557 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
110558 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
110559 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
110560 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
110561 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
110562 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
110563 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
110564 +debug_output_18575 debug_output 3 18575 NULL
110565 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
110566 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
110567 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
110568 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL nohasharray
110569 +audio_get_endpoint_req_18624 audio_get_endpoint_req 0 18624 &nvc0_ram_create__18624
110570 +from_buffer_18625 from_buffer 3 18625 NULL
110571 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
110572 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
110573 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
110574 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
110575 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
110576 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
110577 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
110578 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
110579 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
110580 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
110581 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
110582 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
110583 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
110584 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
110585 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
110586 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
110587 +prealloc_18800 prealloc 0 18800 NULL
110588 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
110589 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
110590 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
110591 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
110592 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
110593 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
110594 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
110595 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
110596 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
110597 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
110598 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
110599 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
110600 +huge_page_size_19008 huge_page_size 0 19008 NULL
110601 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
110602 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
110603 +revalidate_19043 revalidate 2 19043 NULL
110604 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
110605 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
110606 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
110607 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
110608 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
110609 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
110610 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
110611 +ATOMIC_SUB_RETURN_19115 ATOMIC_SUB_RETURN 2 19115 NULL
110612 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
110613 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
110614 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
110615 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
110616 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
110617 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
110618 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
110619 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
110620 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
110621 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
110622 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
110623 +ucma_query_19260 ucma_query 4 19260 NULL
110624 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
110625 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
110626 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
110627 +qc_capture_19298 qc_capture 3 19298 NULL
110628 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
110629 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
110630 +debug_read_19322 debug_read 3 19322 NULL
110631 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
110632 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
110633 +closure_sub_19359 closure_sub 2 19359 NULL
110634 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
110635 +read_zero_19366 read_zero 3 19366 NULL
110636 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
110637 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
110638 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
110639 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
110640 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
110641 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
110642 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
110643 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
110644 +sky2_read16_19475 sky2_read16 0 19475 NULL
110645 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
110646 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
110647 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
110648 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
110649 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
110650 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
110651 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
110652 +howmany_64_19548 howmany_64 2 19548 NULL
110653 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
110654 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
110655 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
110656 +nfsd_read_19568 nfsd_read 5 19568 NULL
110657 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
110658 +bm_status_read_19583 bm_status_read 3 19583 NULL
110659 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
110660 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
110661 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
110662 +iwl_dbgfs_pm_params_write_19660 iwl_dbgfs_pm_params_write 3 19660 NULL
110663 +read_reg_19723 read_reg 0 19723 NULL
110664 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
110665 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
110666 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
110667 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
110668 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
110669 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
110670 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
110671 +readhscx_19769 readhscx 0 19769 NULL
110672 +__set_print_fmt_19776 __set_print_fmt 0 19776 NULL
110673 +iwl_dbgfs_disable_power_off_write_19823 iwl_dbgfs_disable_power_off_write 3 19823 NULL
110674 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
110675 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
110676 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
110677 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
110678 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
110679 +__nla_put_19857 __nla_put 3 19857 NULL
110680 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
110681 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
110682 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
110683 +mangle_name_19923 mangle_name 0 19923 NULL
110684 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
110685 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
110686 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
110687 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
110688 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
110689 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
110690 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
110691 +lustre_pack_request_19992 lustre_pack_request 0 19992 NULL
110692 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
110693 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL
110694 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
110695 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
110696 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
110697 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
110698 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
110699 +target_message_20072 target_message 2 20072 NULL
110700 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
110701 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
110702 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
110703 +team_options_register_20091 team_options_register 3 20091 NULL
110704 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
110705 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
110706 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
110707 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
110708 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
110709 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
110710 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
110711 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
110712 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
110713 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
110714 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
110715 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
110716 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
110717 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
110718 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
110719 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
110720 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
110721 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
110722 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
110723 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
110724 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
110725 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
110726 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
110727 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
110728 +nfs3_setxattr_20458 nfs3_setxattr 4 20458 NULL
110729 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
110730 +read_buf_20469 read_buf 2 20469 NULL
110731 +bio_trim_20472 bio_trim 2 20472 NULL
110732 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
110733 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
110734 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
110735 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
110736 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
110737 +venus_create_20555 venus_create 4 20555 NULL
110738 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
110739 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
110740 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
110741 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
110742 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
110743 +lirc_write_20604 lirc_write 3 20604 NULL
110744 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
110745 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
110746 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
110747 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
110748 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
110749 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
110750 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
110751 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
110752 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
110753 +cpumask_size_20683 cpumask_size 0 20683 NULL
110754 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
110755 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
110756 +__maestro_read_20700 __maestro_read 0 20700 NULL
110757 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
110758 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
110759 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
110760 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
110761 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
110762 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
110763 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
110764 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
110765 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
110766 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
110767 +strndup_user_20819 strndup_user 2 20819 NULL
110768 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
110769 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
110770 +uvc_alloc_entity_20836 uvc_alloc_entity 3-4 20836 NULL
110771 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
110772 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
110773 +get_name_20855 get_name 4 20855 NULL
110774 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
110775 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
110776 +srq_free_res_20868 srq_free_res 5 20868 NULL
110777 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
110778 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
110779 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
110780 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
110781 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
110782 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
110783 +htable_bits_20933 htable_bits 0 20933 NULL
110784 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
110785 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
110786 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
110787 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
110788 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
110789 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
110790 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
110791 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
110792 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
110793 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
110794 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
110795 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
110796 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
110797 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
110798 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
110799 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
110800 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
110801 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
110802 +ocfs2_extend_meta_needed_21104 ocfs2_extend_meta_needed 0 21104 NULL
110803 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
110804 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
110805 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
110806 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
110807 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
110808 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
110809 +input_ff_create_21240 input_ff_create 2 21240 NULL
110810 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
110811 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
110812 +fru_length_21257 fru_length 0 21257 NULL
110813 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
110814 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
110815 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
110816 +add_res_range_21310 add_res_range 4 21310 NULL
110817 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
110818 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
110819 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
110820 +ocfs2_find_subtree_root_21351 ocfs2_find_subtree_root 0 21351 NULL
110821 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
110822 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
110823 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
110824 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
110825 +insert_ptr_21386 insert_ptr 6 21386 NULL
110826 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
110827 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
110828 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
110829 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
110830 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
110831 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
110832 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
110833 +ReadISAR_21453 ReadISAR 0 21453 NULL
110834 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
110835 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
110836 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
110837 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
110838 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
110839 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
110840 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
110841 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
110842 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
110843 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
110844 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
110845 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
110846 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
110847 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
110848 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
110849 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
110850 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
110851 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
110852 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
110853 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
110854 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
110855 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
110856 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
110857 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
110858 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
110859 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
110860 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
110861 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
110862 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
110863 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
110864 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
110865 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
110866 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
110867 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
110868 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
110869 +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
110870 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
110871 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
110872 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
110873 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
110874 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
110875 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
110876 +mem_rw_22085 mem_rw 3 22085 NULL
110877 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
110878 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
110879 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
110880 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
110881 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
110882 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
110883 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
110884 +mem_write_22232 mem_write 3 22232 NULL
110885 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
110886 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
110887 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
110888 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
110889 +add_res_tree_22263 add_res_tree 7 22263 NULL
110890 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
110891 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
110892 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
110893 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
110894 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
110895 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
110896 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
110897 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
110898 +atomic_read_22342 atomic_read 0 22342 NULL
110899 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
110900 +memcg_size_22360 memcg_size 0 22360 NULL
110901 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
110902 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
110903 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
110904 +zoran_write_22404 zoran_write 3 22404 NULL
110905 +ATOMIC_ADD_RETURN_22413 ATOMIC_ADD_RETURN 2 22413 NULL
110906 +queue_reply_22416 queue_reply 3 22416 NULL
110907 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
110908 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
110909 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
110910 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
110911 +source_sink_start_ep_22472 source_sink_start_ep 0 22472 NULL
110912 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
110913 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
110914 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
110915 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
110916 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
110917 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
110918 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
110919 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
110920 +snapshot_read_22601 snapshot_read 3 22601 NULL
110921 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
110922 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
110923 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
110924 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
110925 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
110926 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
110927 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
110928 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
110929 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
110930 +reg_umr_22686 reg_umr 5 22686 NULL
110931 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
110932 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
110933 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
110934 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
110935 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
110936 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
110937 +print_frame_22769 print_frame 0 22769 NULL
110938 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
110939 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
110940 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
110941 +clone_bio_integrity_22842 clone_bio_integrity 4 22842 NULL
110942 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
110943 +create_attr_set_22861 create_attr_set 1 22861 NULL
110944 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
110945 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
110946 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
110947 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
110948 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 NULL
110949 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
110950 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
110951 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
110952 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
110953 +vme_get_size_22964 vme_get_size 0 22964 NULL
110954 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
110955 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
110956 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
110957 +brcmf_sdio_chip_exit_download_23001 brcmf_sdio_chip_exit_download 4 23001 NULL
110958 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
110959 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
110960 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0-6-7 23029 NULL
110961 +st_status_23032 st_status 5 23032 NULL
110962 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
110963 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
110964 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
110965 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
110966 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
110967 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
110968 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
110969 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
110970 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
110971 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
110972 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
110973 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
110974 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
110975 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
110976 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL
110977 +__clear_user_23118 __clear_user 0-2 23118 NULL
110978 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
110979 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
110980 +read_file_ani_23161 read_file_ani 3 23161 NULL
110981 +usblp_write_23178 usblp_write 3 23178 NULL
110982 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
110983 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
110984 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
110985 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
110986 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
110987 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
110988 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
110989 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
110990 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
110991 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
110992 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
110993 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
110994 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
110995 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
110996 +page_readlink_23346 page_readlink 3 23346 NULL
110997 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
110998 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
110999 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
111000 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
111001 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
111002 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
111003 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
111004 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
111005 +linear_conf_23485 linear_conf 2 23485 NULL
111006 +event_filter_read_23494 event_filter_read 3 23494 NULL
111007 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
111008 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
111009 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
111010 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
111011 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
111012 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
111013 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
111014 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
111015 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
111016 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
111017 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
111018 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
111019 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
111020 +sInW_23663 sInW 0 23663 NULL
111021 +SyS_connect_23669 SyS_connect 3 23669 NULL
111022 +cx18_read_23699 cx18_read 3 23699 NULL
111023 +at_get_23708 at_get 0 23708 NULL
111024 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
111025 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
111026 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
111027 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
111028 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
111029 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
111030 +map_write_23795 map_write 3 23795 NULL
111031 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
111032 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
111033 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
111034 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
111035 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 3-4 23829 NULL
111036 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
111037 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
111038 +p54_init_common_23850 p54_init_common 1 23850 NULL
111039 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
111040 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
111041 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
111042 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL
111043 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
111044 +usbg_prepare_w_request_23895 usbg_prepare_w_request 0 23895 NULL
111045 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
111046 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
111047 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
111048 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
111049 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
111050 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
111051 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
111052 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
111053 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
111054 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
111055 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
111056 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
111057 +give_pages_24021 give_pages 3 24021 NULL
111058 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
111059 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
111060 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
111061 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
111062 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
111063 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
111064 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
111065 +lov_brw_24122 lov_brw 4 24122 NULL
111066 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
111067 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
111068 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
111069 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
111070 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
111071 +adu_read_24177 adu_read 3 24177 NULL
111072 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
111073 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
111074 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
111075 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
111076 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
111077 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
111078 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
111079 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
111080 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
111081 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
111082 +thin_status_24278 thin_status 5 24278 NULL
111083 +msg_size_24288 msg_size 0 24288 NULL
111084 +gserial_connect_24302 gserial_connect 0 24302 NULL
111085 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
111086 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
111087 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
111088 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
111089 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
111090 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
111091 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
111092 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
111093 +igetword_24373 igetword 0 24373 NULL
111094 +max_io_len_24384 max_io_len 0-1 24384 NULL
111095 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
111096 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
111097 +getxattr_24398 getxattr 4 24398 NULL nohasharray
111098 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
111099 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
111100 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
111101 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
111102 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
111103 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
111104 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
111105 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
111106 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
111107 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
111108 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
111109 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
111110 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
111111 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
111112 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
111113 +pd_video_read_24510 pd_video_read 3 24510 NULL
111114 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
111115 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
111116 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
111117 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
111118 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
111119 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
111120 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
111121 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
111122 +SyS_poll_24620 SyS_poll 2 24620 NULL
111123 +context_alloc_24645 context_alloc 3 24645 NULL
111124 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
111125 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
111126 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
111127 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
111128 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
111129 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
111130 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
111131 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
111132 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
111133 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
111134 +cache_read_24790 cache_read 3 24790 NULL
111135 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
111136 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
111137 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
111138 +net2272_read_24825 net2272_read 0 24825 NULL
111139 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
111140 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
111141 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
111142 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
111143 +queues_read_24877 queues_read 3 24877 NULL
111144 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
111145 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
111146 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
111147 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
111148 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
111149 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
111150 +ll_layout_fetch_24961 ll_layout_fetch 0 24961 NULL
111151 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
111152 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
111153 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
111154 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
111155 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
111156 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
111157 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
111158 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
111159 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
111160 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
111161 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
111162 +iwl_dbgfs_tx_flush_write_25091 iwl_dbgfs_tx_flush_write 3 25091 NULL
111163 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
111164 +blkg_path_25099 blkg_path 3 25099 NULL
111165 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
111166 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
111167 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
111168 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
111169 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
111170 +stripe_status_25259 stripe_status 5 25259 NULL
111171 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
111172 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
111173 +vfs_writev_25278 vfs_writev 3 25278 NULL
111174 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
111175 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
111176 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
111177 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
111178 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
111179 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
111180 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
111181 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
111182 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
111183 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
111184 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
111185 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
111186 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
111187 +sb_permission_25523 sb_permission 0 25523 NULL
111188 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
111189 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
111190 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
111191 +ht_print_chan_25556 ht_print_chan 3-4-0 25556 NULL
111192 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
111193 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
111194 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
111195 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
111196 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
111197 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
111198 +__direct_map_25647 __direct_map 6-5 25647 NULL
111199 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
111200 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
111201 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
111202 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
111203 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
111204 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
111205 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
111206 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
111207 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
111208 +sg_read_25799 sg_read 3 25799 NULL
111209 +system_enable_read_25815 system_enable_read 3 25815 NULL
111210 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
111211 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
111212 +parport_read_25855 parport_read 0 25855 NULL
111213 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
111214 +key_attr_size_25865 key_attr_size 0 25865 NULL
111215 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
111216 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
111217 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
111218 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
111219 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
111220 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
111221 +rcname_read_25919 rcname_read 3 25919 NULL
111222 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
111223 +key_flags_read_25931 key_flags_read 3 25931 NULL
111224 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
111225 +flush_25957 flush 2 25957 NULL
111226 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
111227 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
111228 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
111229 +xfs_xattr_acl_set_26028 xfs_xattr_acl_set 4 26028 NULL
111230 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
111231 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
111232 +tun_do_read_26047 tun_do_read 5 26047 NULL
111233 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
111234 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
111235 +read_sb_page_26119 read_sb_page 5 26119 NULL
111236 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
111237 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
111238 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
111239 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
111240 +disk_devt_26180 disk_devt 0 26180 NULL
111241 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
111242 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
111243 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
111244 +mce_write_26201 mce_write 3 26201 NULL
111245 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
111246 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
111247 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
111248 +bio_split_26235 bio_split 2 26235 NULL
111249 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
111250 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
111251 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
111252 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL nohasharray
111253 +pax_get_random_long_26309 pax_get_random_long 0 26309 &snd_pcm_plug_client_channels_buf_26309
111254 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
111255 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
111256 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
111257 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
111258 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
111259 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
111260 +ntty_write_26404 ntty_write 3 26404 NULL
111261 +firmware_store_26408 firmware_store 4 26408 NULL
111262 +pagemap_read_26441 pagemap_read 3 26441 NULL
111263 +tower_read_26461 tower_read 3 26461 NULL nohasharray
111264 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
111265 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
111266 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
111267 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
111268 +read_vmcore_26501 read_vmcore 3 26501 NULL
111269 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
111270 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
111271 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
111272 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
111273 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
111274 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
111275 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
111276 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
111277 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
111278 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
111279 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
111280 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
111281 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
111282 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
111283 +bos_desc_26752 bos_desc 0 26752 NULL
111284 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
111285 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
111286 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
111287 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
111288 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
111289 +smk_write_load_26829 smk_write_load 3 26829 NULL
111290 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
111291 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
111292 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
111293 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
111294 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
111295 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
111296 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
111297 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
111298 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
111299 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
111300 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
111301 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
111302 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
111303 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
111304 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
111305 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
111306 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
111307 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
111308 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
111309 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
111310 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
111311 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
111312 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
111313 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
111314 +pms_capture_27142 pms_capture 4 27142 NULL
111315 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
111316 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
111317 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
111318 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
111319 +write_kmem_27225 write_kmem 3 27225 NULL
111320 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
111321 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
111322 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
111323 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
111324 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
111325 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
111326 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
111327 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
111328 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
111329 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
111330 +seq_read_27411 seq_read 3 27411 NULL
111331 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
111332 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
111333 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0-3-4 27422 NULL
111334 +cypress_write_27423 cypress_write 4 27423 NULL
111335 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
111336 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
111337 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
111338 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
111339 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
111340 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
111341 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
111342 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
111343 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
111344 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
111345 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
111346 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
111347 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
111348 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
111349 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
111350 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642
111351 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
111352 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
111353 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
111354 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
111355 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
111356 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
111357 +evm_write_key_27715 evm_write_key 3 27715 NULL
111358 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
111359 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
111360 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
111361 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
111362 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
111363 +SyS_readv_27804 SyS_readv 3 27804 NULL
111364 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
111365 +fwtty_buffer_rx_27821 fwtty_buffer_rx 3 27821 NULL
111366 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
111367 +init_header_complete_27833 init_header_complete 0 27833 NULL
111368 +read_profile_27859 read_profile 3 27859 NULL
111369 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
111370 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
111371 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
111372 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
111373 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
111374 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
111375 +device_register_27972 device_register 0 27972 NULL nohasharray
111376 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
111377 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
111378 +f2fs_bio_alloc_27983 f2fs_bio_alloc 2 27983 NULL
111379 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
111380 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
111381 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
111382 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
111383 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
111384 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
111385 +pool_status_28055 pool_status 5 28055 NULL
111386 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
111387 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
111388 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
111389 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
111390 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
111391 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
111392 +video_read_28148 video_read 3 28148 NULL
111393 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
111394 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
111395 +vread_28173 vread 0-3 28173 NULL
111396 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
111397 +counter_free_res_28187 counter_free_res 5 28187 NULL
111398 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
111399 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
111400 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
111401 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
111402 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
111403 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
111404 +usemap_size_28281 usemap_size 0 28281 NULL
111405 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
111406 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
111407 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
111408 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
111409 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
111410 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
111411 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
111412 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
111413 +snapshot_write_28351 snapshot_write 3 28351 NULL
111414 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
111415 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
111416 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
111417 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
111418 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
111419 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
111420 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
111421 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
111422 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
111423 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
111424 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
111425 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
111426 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
111427 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
111428 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
111429 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
111430 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
111431 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
111432 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
111433 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
111434 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
111435 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
111436 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
111437 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
111438 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
111439 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
111440 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
111441 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
111442 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
111443 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
111444 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
111445 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
111446 +spi_execute_28736 spi_execute 5 28736 NULL
111447 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
111448 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
111449 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
111450 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
111451 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
111452 +sel_write_member_28800 sel_write_member 3 28800 NULL
111453 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
111454 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
111455 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
111456 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
111457 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
111458 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
111459 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
111460 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
111461 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
111462 +push_rx_28939 push_rx 3 28939 NULL
111463 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
111464 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
111465 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
111466 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
111467 +bin_uuid_28999 bin_uuid 3 28999 NULL
111468 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
111469 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
111470 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
111471 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
111472 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
111473 +roundup_64_29066 roundup_64 2-0-1 29066 NULL
111474 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
111475 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
111476 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
111477 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
111478 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
111479 +snprintf_29125 snprintf 0 29125 NULL
111480 +iov_shorten_29130 iov_shorten 0 29130 NULL
111481 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
111482 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
111483 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
111484 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
111485 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
111486 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
111487 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
111488 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
111489 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
111490 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
111491 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
111492 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
111493 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
111494 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
111495 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
111496 +tun_put_user_29337 tun_put_user 5 29337 NULL
111497 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
111498 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
111499 +mwifiex_cfg80211_mgmt_tx_29387 mwifiex_cfg80211_mgmt_tx 7 29387 NULL
111500 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
111501 +mempool_create_29437 mempool_create 1 29437 NULL
111502 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
111503 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
111504 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
111505 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
111506 +do_register_entry_29478 do_register_entry 4 29478 NULL
111507 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
111508 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
111509 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
111510 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
111511 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
111512 +ftrace_write_29551 ftrace_write 3 29551 NULL
111513 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
111514 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
111515 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
111516 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
111517 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
111518 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
111519 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
111520 +slots_per_page_29601 slots_per_page 0 29601 NULL
111521 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
111522 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
111523 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
111524 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
111525 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
111526 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
111527 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
111528 +probes_write_29711 probes_write 3 29711 NULL
111529 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
111530 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
111531 +std_nic_write_29752 std_nic_write 3 29752 NULL
111532 +dbAlloc_29794 dbAlloc 0 29794 NULL
111533 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
111534 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
111535 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
111536 +count_partial_29850 count_partial 0 29850 NULL
111537 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
111538 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
111539 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
111540 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
111541 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
111542 +write_file_queue_29922 write_file_queue 3 29922 NULL
111543 +ext4_xattr_set_acl_29930 ext4_xattr_set_acl 4 29930 NULL
111544 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
111545 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
111546 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
111547 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
111548 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
111549 +drp_wmove_30043 drp_wmove 4 30043 NULL
111550 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
111551 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
111552 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
111553 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
111554 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
111555 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
111556 +recv_stream_30138 recv_stream 4 30138 NULL
111557 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
111558 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
111559 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
111560 +expand_inode_data_30169 expand_inode_data 2-3 30169 NULL
111561 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
111562 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
111563 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
111564 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
111565 +SyS_semop_30227 SyS_semop 3 30227 NULL
111566 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
111567 +ocfs2_calc_bg_discontig_credits_30230 ocfs2_calc_bg_discontig_credits 0 30230 NULL
111568 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
111569 +hfsplus_trusted_setxattr_30270 hfsplus_trusted_setxattr 4 30270 NULL
111570 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
111571 +compat_readv_30273 compat_readv 3 30273 NULL
111572 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
111573 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
111574 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
111575 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
111576 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
111577 +i8254_read_30330 i8254_read 0 30330 NULL
111578 +resource_from_user_30341 resource_from_user 3 30341 NULL
111579 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
111580 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
111581 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
111582 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
111583 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
111584 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
111585 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
111586 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
111587 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
111588 +enable_write_30456 enable_write 3 30456 NULL
111589 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
111590 +urandom_read_30462 urandom_read 3 30462 NULL
111591 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
111592 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
111593 +adu_write_30487 adu_write 3 30487 NULL
111594 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
111595 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
111596 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
111597 +set_config_30526 set_config 0 30526 NULL nohasharray
111598 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
111599 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
111600 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
111601 +set_le_30581 set_le 4 30581 NULL
111602 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
111603 +i2c_hid_get_report_length_30598 i2c_hid_get_report_length 0 30598 NULL
111604 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL nohasharray
111605 +cpufreq_get_global_kobject_30610 cpufreq_get_global_kobject 0 30610 &sgl_map_user_pages_30610
111606 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
111607 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
111608 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
111609 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
111610 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
111611 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
111612 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
111613 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
111614 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
111615 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
111616 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
111617 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
111618 +snapshot_status_30744 snapshot_status 5 30744 NULL
111619 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
111620 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
111621 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
111622 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
111623 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
111624 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
111625 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
111626 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
111627 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
111628 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
111629 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
111630 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
111631 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
111632 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
111633 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
111634 +stride_pg_count_31053 stride_pg_count 0-2-1-4-3-5 31053 NULL
111635 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
111636 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
111637 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
111638 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
111639 +depth_read_31112 depth_read 3 31112 NULL
111640 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
111641 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
111642 +size_inside_page_31141 size_inside_page 0 31141 NULL
111643 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
111644 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
111645 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
111646 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
111647 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
111648 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
111649 +__read_reg_31216 __read_reg 0 31216 NULL
111650 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
111651 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
111652 +cyy_readb_31240 cyy_readb 0 31240 NULL
111653 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
111654 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
111655 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
111656 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
111657 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
111658 +command_file_write_31318 command_file_write 3 31318 NULL
111659 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
111660 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
111661 +outlen_write_31358 outlen_write 3 31358 NULL
111662 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
111663 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
111664 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
111665 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
111666 +inb_31388 inb 0 31388 NULL
111667 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
111668 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
111669 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
111670 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
111671 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
111672 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
111673 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
111674 +alg_setkey_31485 alg_setkey 3 31485 NULL
111675 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
111676 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
111677 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
111678 +hidraw_write_31536 hidraw_write 3 31536 NULL
111679 +usbvision_read_31555 usbvision_read 3 31555 NULL
111680 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
111681 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
111682 +osst_write_31581 osst_write 3 31581 NULL
111683 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
111684 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
111685 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
111686 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
111687 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
111688 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
111689 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
111690 +__lgread_31668 __lgread 4 31668 NULL
111691 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
111692 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
111693 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
111694 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
111695 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
111696 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
111697 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
111698 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
111699 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
111700 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
111701 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
111702 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
111703 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
111704 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
111705 +data_write_31805 data_write 3 31805 NULL
111706 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
111707 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
111708 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
111709 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
111710 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
111711 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
111712 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
111713 +xattr_permission_31907 xattr_permission 0 31907 NULL
111714 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
111715 +new_dir_31919 new_dir 3 31919 NULL
111716 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
111717 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
111718 +read_mem_31942 read_mem 3 31942 NULL nohasharray
111719 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
111720 +vb2_write_31948 vb2_write 3 31948 NULL
111721 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
111722 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
111723 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
111724 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
111725 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
111726 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
111727 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
111728 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
111729 +calc_hmac_32010 calc_hmac 3 32010 NULL
111730 +aead_len_32021 aead_len 0 32021 NULL
111731 +posix_acl_set_32037 posix_acl_set 4 32037 NULL
111732 +stk_read_32038 stk_read 3 32038 NULL
111733 +ocfs2_update_edge_lengths_32046 ocfs2_update_edge_lengths 3 32046 NULL
111734 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
111735 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
111736 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
111737 +bio_alloc_32095 bio_alloc 2 32095 NULL
111738 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
111739 +disk_status_32120 disk_status 4 32120 NULL
111740 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
111741 +venus_link_32165 venus_link 5 32165 NULL
111742 +do_writepages_32173 do_writepages 0 32173 NULL
111743 +del_ptr_32197 del_ptr 4 32197 NULL
111744 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
111745 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
111746 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
111747 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
111748 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
111749 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
111750 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
111751 +SyS_select_32319 SyS_select 1 32319 NULL
111752 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
111753 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
111754 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
111755 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
111756 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
111757 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
111758 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
111759 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
111760 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
111761 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
111762 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
111763 +cache_status_32462 cache_status 5 32462 NULL
111764 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
111765 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
111766 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
111767 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
111768 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
111769 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
111770 +disconnect_32521 disconnect 4 32521 NULL
111771 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
111772 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL nohasharray
111773 +audio_get_intf_req_32524 audio_get_intf_req 0 32524 &ocfs2_refresh_qinfo_32524
111774 +ilo_read_32531 ilo_read 3 32531 NULL
111775 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
111776 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
111777 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
111778 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
111779 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
111780 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
111781 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
111782 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
111783 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
111784 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
111785 +kvmalloc_32646 kvmalloc 1 32646 NULL
111786 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
111787 +generic_readlink_32654 generic_readlink 3 32654 NULL
111788 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
111789 +apei_res_add_32674 apei_res_add 0 32674 NULL
111790 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
111791 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
111792 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
111793 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
111794 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
111795 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
111796 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
111797 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
111798 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
111799 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
111800 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
111801 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
111802 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 6-4 32884 NULL
111803 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
111804 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
111805 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
111806 +xfs_log_reserve_32959 xfs_log_reserve 2 32959 NULL
111807 +ocfs2_check_dir_trailer_32968 ocfs2_check_dir_trailer 0 32968 NULL
111808 +compat_filldir_32999 compat_filldir 3 32999 NULL
111809 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
111810 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
111811 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
111812 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
111813 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
111814 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
111815 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
111816 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
111817 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
111818 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
111819 +alloc_tio_33077 alloc_tio 3 33077 NULL
111820 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
111821 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
111822 +__len_within_target_33132 __len_within_target 0 33132 NULL
111823 +SyS_poll_33152 SyS_poll 2 33152 NULL
111824 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
111825 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
111826 +pp_read_33210 pp_read 3 33210 NULL
111827 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
111828 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
111829 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
111830 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
111831 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
111832 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
111833 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
111834 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
111835 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
111836 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
111837 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
111838 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
111839 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
111840 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
111841 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
111842 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
111843 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
111844 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
111845 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
111846 +message_stats_list_33440 message_stats_list 5 33440 NULL
111847 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
111848 +create_entry_33479 create_entry 2 33479 NULL
111849 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL nohasharray
111850 +elf_map_33487 elf_map 0-2 33487 &ip_setsockopt_33487
111851 +res_counter_read_33499 res_counter_read 4 33499 NULL
111852 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
111853 +fb_read_33506 fb_read 3 33506 NULL
111854 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
111855 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
111856 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
111857 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
111858 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
111859 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
111860 +count_subheaders_33591 count_subheaders 0 33591 NULL
111861 +scsi_execute_33596 scsi_execute 5 33596 NULL
111862 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
111863 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
111864 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
111865 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
111866 +stride_page_count_33641 stride_page_count 2 33641 NULL
111867 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
111868 +inw_p_33668 inw_p 0 33668 NULL
111869 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
111870 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
111871 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
111872 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
111873 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
111874 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
111875 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
111876 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
111877 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
111878 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
111879 +hashtab_create_33769 hashtab_create 3 33769 NULL
111880 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
111881 +filter_write_33819 filter_write 3 33819 NULL
111882 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
111883 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
111884 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
111885 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
111886 +get_user_pages_33908 get_user_pages 0 33908 NULL
111887 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
111888 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
111889 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
111890 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
111891 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
111892 +hfsplus_osx_setxattr_33952 hfsplus_osx_setxattr 4 33952 NULL
111893 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
111894 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
111895 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
111896 +ppp_write_34034 ppp_write 3 34034 NULL
111897 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
111898 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
111899 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
111900 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
111901 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
111902 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
111903 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
111904 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
111905 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
111906 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
111907 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
111908 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
111909 +sysfs_bin_read_34228 sysfs_bin_read 3 34228 NULL
111910 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
111911 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
111912 +device_private_init_34279 device_private_init 0 34279 NULL
111913 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
111914 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
111915 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
111916 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
111917 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
111918 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
111919 +ea_read_34378 ea_read 0 34378 NULL
111920 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
111921 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
111922 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
111923 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
111924 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
111925 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
111926 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
111927 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
111928 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
111929 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
111930 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
111931 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
111932 +ocfs2_mv_xattr_buckets_34484 ocfs2_mv_xattr_buckets 6 34484 NULL
111933 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
111934 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
111935 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
111936 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
111937 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
111938 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
111939 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
111940 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
111941 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
111942 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
111943 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
111944 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
111945 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
111946 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
111947 +brcmf_cfg80211_mgmt_tx_34608 brcmf_cfg80211_mgmt_tx 7 34608 NULL
111948 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
111949 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
111950 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
111951 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
111952 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
111953 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
111954 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
111955 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
111956 +port_print_34704 port_print 3 34704 NULL
111957 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
111958 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
111959 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
111960 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
111961 +bootmode_store_34762 bootmode_store 4 34762 NULL
111962 +device_add_34766 device_add 0 34766 NULL
111963 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
111964 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
111965 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
111966 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
111967 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
111968 +file_page_index_34820 file_page_index 0-2 34820 NULL
111969 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
111970 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
111971 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
111972 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
111973 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
111974 +msg_print_text_34889 msg_print_text 0 34889 NULL
111975 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
111976 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
111977 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
111978 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
111979 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
111980 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
111981 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
111982 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
111983 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
111984 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
111985 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
111986 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
111987 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
111988 +brcmf_sdio_chip_writenvram_35042 brcmf_sdio_chip_writenvram 4 35042 NULL
111989 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
111990 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
111991 +capi_write_35104 capi_write 3 35104 NULL nohasharray
111992 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
111993 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
111994 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
111995 +message_stats_print_35158 message_stats_print 6 35158 NULL
111996 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
111997 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
111998 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
111999 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
112000 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
112001 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
112002 +set_fd_set_35249 set_fd_set 1 35249 NULL
112003 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
112004 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
112005 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
112006 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
112007 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
112008 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
112009 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
112010 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
112011 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
112012 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
112013 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
112014 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
112015 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
112016 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
112017 +read_kmem_35372 read_kmem 3 35372 NULL
112018 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
112019 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
112020 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
112021 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
112022 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
112023 +async_setkey_35521 async_setkey 3 35521 NULL
112024 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
112025 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
112026 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
112027 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
112028 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
112029 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
112030 +sysfs_create_subdir_35567 sysfs_create_subdir 0 35567 NULL
112031 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
112032 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
112033 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
112034 +kernel_readv_35617 kernel_readv 3 35617 NULL
112035 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
112036 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
112037 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
112038 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
112039 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
112040 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
112041 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
112042 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
112043 +md_super_write_35703 md_super_write 4 35703 NULL
112044 +ocfs2_extent_recs_per_gd_35710 ocfs2_extent_recs_per_gd 0 35710 NULL
112045 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
112046 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
112047 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
112048 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
112049 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
112050 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
112051 +fls64_35862 fls64 0 35862 NULL
112052 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
112053 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
112054 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
112055 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
112056 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
112057 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
112058 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
112059 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
112060 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
112061 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
112062 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
112063 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
112064 +acl_alloc_35979 acl_alloc 1 35979 NULL
112065 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
112066 +generic_file_aio_read_35987 generic_file_aio_read 0 35987 NULL
112067 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
112068 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
112069 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
112070 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
112071 +account_shadowed_36048 account_shadowed 2 36048 NULL
112072 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
112073 +write_emulate_36065 write_emulate 2-4 36065 NULL
112074 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
112075 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
112076 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
112077 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
112078 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
112079 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
112080 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
112081 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
112082 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
112083 +twl_set_36154 twl_set 2 36154 NULL
112084 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
112085 +btrfs_file_extent_inline_len_36158 btrfs_file_extent_inline_len 0 36158 NULL
112086 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
112087 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
112088 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
112089 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
112090 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
112091 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
112092 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
112093 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
112094 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
112095 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
112096 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
112097 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
112098 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
112099 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
112100 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
112101 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
112102 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
112103 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
112104 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
112105 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
112106 +lc_create_36332 lc_create 4 36332 NULL
112107 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
112108 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
112109 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
112110 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
112111 +to_sector_36361 to_sector 0-1 36361 NULL
112112 +tunables_read_36385 tunables_read 3 36385 NULL
112113 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
112114 +sierra_write_36402 sierra_write 4 36402 NULL
112115 +iwl_dbgfs_d3_sram_write_36403 iwl_dbgfs_d3_sram_write 3 36403 NULL
112116 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
112117 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
112118 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
112119 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
112120 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
112121 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
112122 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
112123 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
112124 +cmd_loop_36491 cmd_loop 0 36491 NULL
112125 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
112126 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
112127 +get_param_l_36518 get_param_l 0 36518 NULL
112128 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
112129 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
112130 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
112131 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL nohasharray
112132 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
112133 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
112134 +__erst_read_36579 __erst_read 0 36579 NULL
112135 +put_cmsg_36589 put_cmsg 4 36589 NULL
112136 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
112137 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
112138 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
112139 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
112140 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
112141 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
112142 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
112143 +xillybus_read_36678 xillybus_read 3 36678 NULL
112144 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
112145 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
112146 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
112147 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
112148 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
112149 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 2-3-4-5 36796 NULL
112150 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
112151 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
112152 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
112153 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
112154 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
112155 +cm_write_36858 cm_write 3 36858 NULL
112156 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
112157 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
112158 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
112159 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
112160 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
112161 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
112162 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
112163 +audio_set_endpoint_req_36918 audio_set_endpoint_req 0 36918 NULL
112164 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
112165 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
112166 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
112167 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
112168 +setxattr_37006 setxattr 4 37006 NULL
112169 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
112170 +command_file_read_37038 command_file_read 3 37038 NULL
112171 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
112172 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
112173 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
112174 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
112175 +parse_command_37079 parse_command 2 37079 NULL
112176 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
112177 +tun_get_user_37094 tun_get_user 5 37094 NULL
112178 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
112179 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
112180 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
112181 +msg_word_37164 msg_word 0 37164 NULL
112182 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
112183 +can_set_xattr_37182 can_set_xattr 4 37182 NULL
112184 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
112185 +sysfs_add_file_37200 sysfs_add_file 0 37200 NULL
112186 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
112187 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
112188 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
112189 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
112190 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
112191 +__do_replace_37227 __do_replace 5 37227 NULL
112192 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
112193 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
112194 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
112195 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
112196 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
112197 +ocfs2_calc_extend_credits_37310 ocfs2_calc_extend_credits 0 37310 NULL
112198 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
112199 +send_msg_37323 send_msg 4 37323 NULL
112200 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
112201 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
112202 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
112203 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
112204 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
112205 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
112206 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
112207 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
112208 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 7-9-0 37433 NULL
112209 +fru_alloc_37442 fru_alloc 1 37442 NULL
112210 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
112211 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
112212 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
112213 +get_est_timing_37484 get_est_timing 0 37484 NULL
112214 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
112215 +__hfsplus_setxattr_37499 __hfsplus_setxattr 4 37499 NULL
112216 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
112217 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
112218 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
112219 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
112220 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
112221 +hdr_size_37536 hdr_size 0 37536 NULL
112222 +extent_map_end_37550 extent_map_end 0 37550 NULL
112223 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
112224 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
112225 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
112226 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
112227 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
112228 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
112229 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
112230 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
112231 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
112232 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
112233 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
112234 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
112235 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
112236 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
112237 +page_chain_free_37697 page_chain_free 0 37697 NULL
112238 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
112239 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
112240 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
112241 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
112242 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
112243 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
112244 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
112245 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
112246 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
112247 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
112248 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
112249 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
112250 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
112251 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
112252 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
112253 +set_registers_37883 set_registers 4 37883 NULL
112254 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
112255 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
112256 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
112257 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
112258 +write_file_bool_37957 write_file_bool 3 37957 NULL
112259 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
112260 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
112261 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
112262 +vfs_readv_38011 vfs_readv 3 38011 NULL
112263 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
112264 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
112265 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
112266 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
112267 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
112268 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
112269 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
112270 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
112271 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
112272 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
112273 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
112274 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
112275 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
112276 +ep0_read_38095 ep0_read 3 38095 NULL
112277 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
112278 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
112279 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
112280 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
112281 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
112282 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
112283 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
112284 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
112285 +cdev_add_38176 cdev_add 2-3 38176 NULL
112286 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
112287 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
112288 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
112289 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
112290 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
112291 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
112292 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
112293 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
112294 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
112295 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
112296 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
112297 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
112298 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
112299 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
112300 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
112301 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
112302 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
112303 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
112304 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
112305 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
112306 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
112307 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
112308 +dev_names_read_38509 dev_names_read 3 38509 NULL
112309 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
112310 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
112311 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
112312 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
112313 +kuc_len_38557 kuc_len 0-1 38557 NULL
112314 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
112315 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
112316 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
112317 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
112318 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
112319 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
112320 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
112321 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
112322 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
112323 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
112324 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
112325 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
112326 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
112327 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
112328 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
112329 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
112330 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
112331 +udf_readpages_38761 udf_readpages 4 38761 NULL
112332 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
112333 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
112334 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
112335 +slab_order_38794 slab_order 0 38794 NULL
112336 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
112337 +err_decode_38804 err_decode 2 38804 NULL
112338 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
112339 +direct_entry_38836 direct_entry 3 38836 NULL
112340 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
112341 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
112342 +interfaces_38859 interfaces 2 38859 NULL
112343 +pci_msix_table_size_38867 pci_msix_table_size 0 38867 NULL
112344 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
112345 +f2fs_xattr_set_acl_38895 f2fs_xattr_set_acl 4 38895 NULL
112346 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
112347 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
112348 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
112349 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
112350 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
112351 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
112352 +get_nodes_39012 get_nodes 3 39012 NULL
112353 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
112354 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
112355 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
112356 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
112357 +ReadHFC_39104 ReadHFC 0 39104 NULL
112358 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
112359 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
112360 +ea_foreach_39133 ea_foreach 0 39133 NULL
112361 +generic_permission_39150 generic_permission 0 39150 NULL
112362 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
112363 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
112364 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
112365 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
112366 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
112367 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
112368 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
112369 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
112370 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
112371 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
112372 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
112373 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
112374 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
112375 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
112376 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
112377 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
112378 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
112379 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
112380 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
112381 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
112382 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
112383 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
112384 +__send_to_port_39386 __send_to_port 3 39386 NULL
112385 +user_power_read_39414 user_power_read 3 39414 NULL
112386 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
112387 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
112388 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
112389 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
112390 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
112391 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
112392 +int_proc_write_39542 int_proc_write 3 39542 NULL
112393 +mdc_unpack_capa_39553 mdc_unpack_capa 0 39553 NULL
112394 +pp_write_39554 pp_write 3 39554 NULL
112395 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
112396 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
112397 +ext_depth_39607 ext_depth 0 39607 NULL
112398 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
112399 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
112400 +sdio_readb_39618 sdio_readb 0 39618 NULL
112401 +set_dev_class_39645 set_dev_class 4 39645 NULL
112402 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
112403 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
112404 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
112405 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
112406 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
112407 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
112408 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
112409 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
112410 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
112411 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
112412 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
112413 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
112414 +pkt_add_39897 pkt_add 3 39897 NULL
112415 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
112416 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
112417 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
112418 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
112419 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
112420 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
112421 +__spi_async_39932 __spi_async 0 39932 NULL
112422 +__get_order_39935 __get_order 0 39935 NULL
112423 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
112424 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
112425 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
112426 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
112427 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
112428 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
112429 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
112430 +server_name2svname_39998 server_name2svname 4 39998 NULL
112431 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
112432 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
112433 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
112434 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
112435 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
112436 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
112437 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
112438 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
112439 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
112440 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
112441 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
112442 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
112443 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
112444 +pt_write_40159 pt_write 3 40159 NULL
112445 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
112446 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
112447 +allocate_probes_40204 allocate_probes 1 40204 NULL
112448 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
112449 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
112450 +osst_read_40237 osst_read 3 40237 NULL
112451 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
112452 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
112453 +ptlrpc_queue_wait_40252 ptlrpc_queue_wait 0 40252 NULL
112454 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
112455 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
112456 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
112457 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
112458 +SyS_bind_40303 SyS_bind 3 40303 NULL
112459 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
112460 +mmio_read_40348 mmio_read 4 40348 NULL
112461 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
112462 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
112463 +get_chars_40373 get_chars 3 40373 NULL
112464 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
112465 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
112466 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
112467 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
112468 +SyS_writev_40467 SyS_writev 3 40467 NULL
112469 +SyS_select_40473 SyS_select 1 40473 NULL
112470 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
112471 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
112472 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
112473 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
112474 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
112475 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
112476 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
112477 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
112478 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
112479 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
112480 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
112481 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
112482 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
112483 +fops_read_40672 fops_read 3 40672 NULL
112484 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
112485 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
112486 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
112487 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
112488 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
112489 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
112490 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
112491 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
112492 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
112493 +card_send_command_40757 card_send_command 3 40757 NULL
112494 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
112495 +pg_write_40766 pg_write 3 40766 NULL
112496 +show_list_40775 show_list 3-0 40775 NULL
112497 +kfifo_out_copy_r_40784 kfifo_out_copy_r 3-0 40784 NULL
112498 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
112499 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
112500 +add_action_40811 add_action 4 40811 NULL
112501 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
112502 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
112503 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
112504 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
112505 +read_file_queue_40895 read_file_queue 3 40895 NULL
112506 +waiters_read_40902 waiters_read 3 40902 NULL
112507 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
112508 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
112509 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
112510 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
112511 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
112512 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
112513 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
112514 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
112515 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
112516 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
112517 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
112518 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
112519 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
112520 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
112521 +calculate_order_41061 calculate_order 0 41061 NULL
112522 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
112523 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
112524 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
112525 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
112526 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
112527 +dma_attach_41094 dma_attach 5-6 41094 NULL
112528 +provide_user_output_41105 provide_user_output 3 41105 NULL
112529 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
112530 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
112531 +ocfs2_extend_trans_41116 ocfs2_extend_trans 2 41116 NULL
112532 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
112533 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
112534 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
112535 +dgap_driver_kzmalloc_41189 dgap_driver_kzmalloc 1 41189 NULL
112536 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
112537 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
112538 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
112539 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
112540 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
112541 +erst_read_41260 erst_read 0 41260 NULL
112542 +alloc_context_41283 alloc_context 1 41283 NULL
112543 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
112544 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
112545 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
112546 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
112547 +kmp_init_41373 kmp_init 2 41373 NULL
112548 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
112549 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
112550 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
112551 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
112552 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
112553 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
112554 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
112555 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
112556 +se_io_cb_41461 se_io_cb 3 41461 NULL
112557 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
112558 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
112559 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
112560 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
112561 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
112562 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
112563 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
112564 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
112565 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
112566 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
112567 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
112568 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
112569 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
112570 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
112571 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
112572 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
112573 +vga_io_r_41609 vga_io_r 0 41609 NULL
112574 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
112575 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
112576 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
112577 +a2mp_send_41615 a2mp_send 4 41615 NULL
112578 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
112579 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
112580 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
112581 +get_std_timing_41654 get_std_timing 0 41654 NULL
112582 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
112583 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
112584 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
112585 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
112586 +fillonedir_41746 fillonedir 3 41746 NULL
112587 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
112588 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
112589 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
112590 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
112591 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
112592 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
112593 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
112594 +pci_map_single_41869 pci_map_single 0 41869 NULL
112595 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
112596 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
112597 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
112598 +nfsd_getxattr_41934 nfsd_getxattr 0 41934 NULL
112599 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
112600 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
112601 +read_gssp_41947 read_gssp 3 41947 NULL
112602 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
112603 +portnames_read_41958 portnames_read 3 41958 NULL
112604 +dst_mtu_41969 dst_mtu 0 41969 NULL
112605 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
112606 +pool_allocate_42012 pool_allocate 3 42012 NULL
112607 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
112608 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
112609 +create_dir_42025 create_dir 0 42025 NULL
112610 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
112611 +__btrfs_drop_extents_42032 __btrfs_drop_extents 5 42032 NULL
112612 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
112613 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
112614 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
112615 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
112616 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
112617 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
112618 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
112619 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
112620 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
112621 +obd_get_info_42156 obd_get_info 0 42156 NULL
112622 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
112623 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
112624 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
112625 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
112626 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
112627 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
112628 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
112629 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
112630 +find_last_bit_42260 find_last_bit 0 42260 NULL
112631 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
112632 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
112633 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
112634 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
112635 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
112636 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
112637 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
112638 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
112639 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
112640 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
112641 +tipc_send_42374 tipc_send 3 42374 NULL
112642 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
112643 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
112644 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
112645 +krng_get_random_42420 krng_get_random 3 42420 NULL
112646 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
112647 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
112648 +alloc_request_42448 alloc_request 0 42448 NULL
112649 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
112650 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
112651 +kuc_free_42455 kuc_free 2 42455 NULL
112652 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
112653 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
112654 +bypass_write_42498 bypass_write 3 42498 NULL
112655 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
112656 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
112657 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
112658 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
112659 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
112660 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
112661 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
112662 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
112663 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
112664 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
112665 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
112666 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
112667 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
112668 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
112669 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
112670 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
112671 +vb2_read_42703 vb2_read 3 42703 NULL
112672 +read_status_42722 read_status 0 42722 NULL
112673 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
112674 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
112675 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
112676 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
112677 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
112678 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
112679 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
112680 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
112681 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
112682 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
112683 +ptlrpc_request_bufs_pack_42793 ptlrpc_request_bufs_pack 0 42793 NULL
112684 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
112685 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
112686 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
112687 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
112688 +set_arg_42824 set_arg 3 42824 NULL
112689 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
112690 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
112691 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
112692 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
112693 +hd_end_request_42904 hd_end_request 2 42904 NULL
112694 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
112695 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL nohasharray
112696 +mdc_unpack_acl_42941 mdc_unpack_acl 0 42941 &sctp_getsockopt_maxburst_42941
112697 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
112698 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
112699 +read_file_node_stat_42964 read_file_node_stat 3 42964 NULL
112700 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
112701 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
112702 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
112703 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
112704 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
112705 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
112706 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
112707 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
112708 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
112709 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
112710 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
112711 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
112712 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
112713 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
112714 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
112715 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
112716 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
112717 +uio_write_43202 uio_write 3 43202 NULL
112718 +iso_callback_43208 iso_callback 3 43208 NULL
112719 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
112720 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
112721 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
112722 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
112723 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
112724 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
112725 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
112726 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
112727 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
112728 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
112729 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
112730 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
112731 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
112732 +xenfb_write_43412 xenfb_write 3 43412 NULL
112733 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
112734 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
112735 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
112736 +usb_string_43443 usb_string 0 43443 NULL nohasharray
112737 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
112738 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
112739 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
112740 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
112741 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
112742 +do_readlink_43518 do_readlink 2 43518 NULL
112743 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
112744 +read_events_43534 read_events 3 43534 NULL
112745 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
112746 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
112747 +request_resource_43548 request_resource 0 43548 NULL
112748 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
112749 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
112750 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
112751 +proc_read_43614 proc_read 3 43614 NULL
112752 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
112753 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
112754 +random_write_43656 random_write 3 43656 NULL
112755 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
112756 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
112757 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
112758 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
112759 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
112760 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
112761 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
112762 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
112763 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
112764 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
112765 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
112766 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
112767 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
112768 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
112769 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
112770 +read_flush_43851 read_flush 3 43851 NULL
112771 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
112772 +SendString_43928 SendString 3 43928 NULL
112773 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
112774 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
112775 +nla_reserve_43984 nla_reserve 3 43984 NULL
112776 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
112777 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
112778 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
112779 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
112780 +emit_flags_44006 emit_flags 4-3 44006 NULL
112781 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
112782 +fru_strlen_44046 fru_strlen 0 44046 NULL
112783 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
112784 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
112785 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 NULL
112786 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
112787 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
112788 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
112789 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
112790 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
112791 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
112792 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
112793 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
112794 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
112795 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
112796 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
112797 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
112798 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
112799 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
112800 +device_create_file_44285 device_create_file 0 44285 NULL
112801 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
112802 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
112803 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
112804 +rs_init_44327 rs_init 1 44327 NULL
112805 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
112806 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
112807 +alloc_requests_44372 alloc_requests 0 44372 NULL
112808 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
112809 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
112810 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
112811 +strlcpy_44400 strlcpy 3 44400 NULL
112812 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
112813 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
112814 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
112815 +iwl_dbgfs_bf_params_write_44450 iwl_dbgfs_bf_params_write 3 44450 NULL
112816 +write_file_debug_44476 write_file_debug 3 44476 NULL
112817 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
112818 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
112819 +bio_advance_44496 bio_advance 2 44496 NULL
112820 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
112821 +ac_register_board_44504 ac_register_board 3 44504 NULL
112822 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
112823 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
112824 +spidev_write_44510 spidev_write 3 44510 NULL
112825 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
112826 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
112827 +comm_write_44537 comm_write 3 44537 NULL
112828 +xfs_log_calc_unit_res_44540 xfs_log_calc_unit_res 0-2 44540 NULL
112829 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
112830 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
112831 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
112832 +mpi_resize_44674 mpi_resize 2 44674 NULL
112833 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
112834 +ts_read_44687 ts_read 3 44687 NULL
112835 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
112836 +__ocfs2_rotate_tree_left_44705 __ocfs2_rotate_tree_left 3 44705 NULL
112837 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
112838 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
112839 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
112840 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
112841 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
112842 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
112843 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
112844 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
112845 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
112846 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
112847 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
112848 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
112849 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
112850 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
112851 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
112852 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
112853 +sisusb_write_44834 sisusb_write 3 44834 NULL
112854 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
112855 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
112856 +copydesc_user_44855 copydesc_user 3 44855 NULL
112857 +set_advertising_44870 set_advertising 4 44870 NULL
112858 +init_rs_44873 init_rs 1 44873 NULL
112859 +skb_availroom_44883 skb_availroom 0 44883 NULL
112860 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
112861 +do_tty_write_44896 do_tty_write 5 44896 NULL
112862 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
112863 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
112864 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
112865 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
112866 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
112867 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
112868 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
112869 +sel_write_user_45060 sel_write_user 3 45060 NULL
112870 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
112871 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
112872 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
112873 +usbdev_read_45114 usbdev_read 3 45114 NULL
112874 +send_to_tty_45141 send_to_tty 3 45141 NULL
112875 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
112876 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
112877 +device_write_45156 device_write 3 45156 NULL nohasharray
112878 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
112879 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
112880 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
112881 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
112882 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
112883 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
112884 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
112885 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
112886 +event_enable_write_45238 event_enable_write 3 45238 NULL
112887 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
112888 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
112889 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
112890 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
112891 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
112892 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
112893 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
112894 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
112895 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
112896 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
112897 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
112898 +__node_remap_45458 __node_remap 4 45458 NULL
112899 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
112900 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
112901 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
112902 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
112903 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
112904 +copy_macs_45534 copy_macs 4 45534 NULL
112905 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
112906 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
112907 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
112908 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
112909 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
112910 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
112911 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
112912 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
112913 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
112914 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
112915 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
112916 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
112917 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
112918 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
112919 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
112920 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL nohasharray
112921 +task_cgroup_path_45734 task_cgroup_path 3 45734 &snd_cs46xx_io_read_45734
112922 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
112923 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
112924 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
112925 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
112926 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
112927 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
112928 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
112929 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
112930 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
112931 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
112932 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
112933 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
112934 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
112935 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
112936 +isdn_write_45863 isdn_write 3 45863 NULL
112937 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
112938 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
112939 +ima_eventdigest_init_common_45889 ima_eventdigest_init_common 2 45889 NULL
112940 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
112941 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
112942 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
112943 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
112944 +alloc_mr_45935 alloc_mr 1 45935 NULL
112945 +copy_to_45969 copy_to 3 45969 NULL
112946 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
112947 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
112948 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
112949 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
112950 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
112951 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
112952 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
112953 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
112954 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
112955 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
112956 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
112957 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
112958 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
112959 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
112960 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
112961 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
112962 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
112963 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
112964 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
112965 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
112966 +fq_resize_46195 fq_resize 2 46195 NULL
112967 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
112968 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
112969 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
112970 +dsp_write_46218 dsp_write 2 46218 NULL
112971 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
112972 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
112973 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
112974 +ReadReg_46277 ReadReg 0 46277 NULL
112975 +sptlrpc_req_get_ctx_46303 sptlrpc_req_get_ctx 0 46303 NULL
112976 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
112977 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
112978 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
112979 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
112980 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
112981 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
112982 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
112983 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
112984 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
112985 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
112986 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
112987 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
112988 +filldir64_46469 filldir64 3 46469 NULL
112989 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
112990 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
112991 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
112992 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
112993 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
112994 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
112995 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
112996 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
112997 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
112998 +il3945_stats_flag_46606 il3945_stats_flag 3-0 46606 NULL
112999 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
113000 +__kfifo_out_r_46623 __kfifo_out_r 3-0 46623 NULL
113001 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
113002 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
113003 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
113004 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
113005 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
113006 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
113007 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
113008 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
113009 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
113010 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
113011 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
113012 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
113013 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
113014 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
113015 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
113016 +readreg_46845 readreg 0 46845 NULL
113017 +spi_async_46857 spi_async 0 46857 NULL
113018 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
113019 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
113020 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
113021 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
113022 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
113023 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
113024 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
113025 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
113026 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
113027 +fb_write_46924 fb_write 3 46924 NULL
113028 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
113029 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
113030 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
113031 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
113032 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
113033 +strlcat_46985 strlcat 3 46985 NULL
113034 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
113035 +sel_write_bool_46996 sel_write_bool 3 46996 NULL nohasharray
113036 +gfs2_xattr_system_set_46996 gfs2_xattr_system_set 4 46996 &sel_write_bool_46996
113037 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
113038 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
113039 +fs_path_len_47060 fs_path_len 0 47060 NULL
113040 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
113041 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
113042 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
113043 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
113044 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
113045 +mousedev_read_47123 mousedev_read 3 47123 NULL
113046 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
113047 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
113048 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
113049 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
113050 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
113051 +can_set_system_xattr_47182 can_set_system_xattr 4 47182 NULL
113052 +options_write_47243 options_write 3 47243 NULL
113053 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
113054 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
113055 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
113056 +vsnprintf_47291 vsnprintf 0 47291 NULL
113057 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
113058 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
113059 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
113060 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
113061 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
113062 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
113063 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
113064 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
113065 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
113066 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
113067 +nametbl_list_47391 nametbl_list 2 47391 NULL
113068 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
113069 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
113070 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
113071 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
113072 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
113073 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
113074 +posix_acl_from_disk_47445 posix_acl_from_disk 2 47445 NULL
113075 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
113076 +newpart_47485 newpart 6-4 47485 NULL
113077 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
113078 +core_sys_select_47494 core_sys_select 1 47494 NULL
113079 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
113080 +unlink_simple_47506 unlink_simple 3 47506 NULL
113081 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
113082 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
113083 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
113084 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
113085 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
113086 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
113087 +read_ldt_47570 read_ldt 2 47570 NULL
113088 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
113089 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
113090 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
113091 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
113092 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
113093 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
113094 +get_size_47644 get_size 1-2 47644 NULL
113095 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
113096 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
113097 +save_microcode_47717 save_microcode 3 47717 NULL
113098 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
113099 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
113100 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
113101 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
113102 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
113103 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
113104 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
113105 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
113106 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
113107 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
113108 +lov_packmd_47810 lov_packmd 0 47810 NULL
113109 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
113110 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
113111 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
113112 +vhci_read_47878 vhci_read 3 47878 NULL
113113 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
113114 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
113115 +comedi_write_47926 comedi_write 3 47926 NULL
113116 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
113117 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
113118 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
113119 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
113120 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
113121 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
113122 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
113123 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
113124 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
113125 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
113126 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
113127 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
113128 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
113129 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
113130 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
113131 +disc_write_48070 disc_write 3 48070 NULL
113132 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
113133 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
113134 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
113135 +set_discoverable_48141 set_discoverable 4 48141 NULL
113136 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
113137 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
113138 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
113139 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
113140 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
113141 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
113142 +brcmf_sdio_chip_cm3_exitdl_48192 brcmf_sdio_chip_cm3_exitdl 4 48192 NULL
113143 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
113144 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
113145 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
113146 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
113147 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
113148 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
113149 +read_file_recv_48232 read_file_recv 3 48232 NULL
113150 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
113151 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
113152 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
113153 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
113154 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
113155 +trace_options_write_48275 trace_options_write 3 48275 NULL
113156 +send_set_info_48288 send_set_info 7 48288 NULL
113157 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
113158 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
113159 +hash_setkey_48310 hash_setkey 3 48310 NULL
113160 +audio_set_intf_req_48319 audio_set_intf_req 0 48319 NULL
113161 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
113162 +skb_add_data_48363 skb_add_data 3 48363 NULL
113163 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
113164 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
113165 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
113166 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
113167 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
113168 +print_filtered_48442 print_filtered 2-0 48442 NULL
113169 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
113170 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
113171 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
113172 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
113173 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
113174 +send_control_msg_48498 send_control_msg 6 48498 NULL
113175 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
113176 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
113177 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
113178 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
113179 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
113180 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
113181 +llog_data_len_48607 llog_data_len 1 48607 NULL
113182 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
113183 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
113184 +mtd_read_48655 mtd_read 0 48655 NULL
113185 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
113186 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
113187 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
113188 +altera_drscan_48698 altera_drscan 2 48698 NULL
113189 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
113190 +recv_msg_48709 recv_msg 4 48709 NULL
113191 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
113192 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
113193 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
113194 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
113195 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
113196 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
113197 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
113198 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
113199 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
113200 +azx_get_position_48841 azx_get_position 0 48841 NULL
113201 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
113202 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
113203 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
113204 +sptlrpc_cli_alloc_reqbuf_48855 sptlrpc_cli_alloc_reqbuf 0 48855 NULL
113205 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
113206 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
113207 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
113208 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
113209 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
113210 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
113211 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
113212 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
113213 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
113214 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
113215 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
113216 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
113217 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
113218 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
113219 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
113220 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
113221 +aic_inb_49023 aic_inb 0 49023 NULL
113222 +transient_status_49027 transient_status 4 49027 NULL
113223 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
113224 +aic7xxx_rem_scb_from_disc_list_49041 aic7xxx_rem_scb_from_disc_list 0 49041 NULL
113225 +scsi_register_49094 scsi_register 2 49094 NULL
113226 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
113227 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
113228 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
113229 +pt_read_49136 pt_read 3 49136 NULL
113230 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
113231 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
113232 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
113233 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
113234 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
113235 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
113236 +print_queue_49191 print_queue 4-0 49191 NULL
113237 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
113238 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
113239 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
113240 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
113241 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
113242 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
113243 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
113244 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
113245 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
113246 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
113247 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
113248 +uio_read_49300 uio_read 3 49300 NULL
113249 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
113250 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
113251 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
113252 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
113253 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
113254 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
113255 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
113256 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
113257 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
113258 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
113259 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
113260 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
113261 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
113262 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
113263 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
113264 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
113265 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
113266 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
113267 +smk_write_access_49561 smk_write_access 3 49561 NULL
113268 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
113269 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
113270 +ptlrpc_request_pack_49581 ptlrpc_request_pack 0 49581 NULL
113271 +readfifo_49583 readfifo 1 49583 NULL
113272 +tap_write_49595 tap_write 3 49595 NULL
113273 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
113274 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
113275 +heap_init_49617 heap_init 2 49617 NULL
113276 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
113277 +port_fops_read_49626 port_fops_read 3 49626 NULL
113278 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
113279 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
113280 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
113281 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
113282 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
113283 +write_pool_49718 write_pool 3 49718 NULL
113284 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
113285 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
113286 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
113287 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
113288 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
113289 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
113290 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
113291 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
113292 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
113293 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
113294 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
113295 +add_uuid_49831 add_uuid 4 49831 NULL
113296 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
113297 +twl4030_write_49846 twl4030_write 2 49846 NULL
113298 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
113299 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
113300 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
113301 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
113302 +ceph_get_caps_49890 ceph_get_caps 0 49890 NULL
113303 +osc_brw_49896 osc_brw 4 49896 NULL
113304 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
113305 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
113306 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
113307 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
113308 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
113309 +isdn_read_50021 isdn_read 3 50021 NULL
113310 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
113311 +ioread8_50049 ioread8 0 50049 NULL
113312 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
113313 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
113314 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
113315 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
113316 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
113317 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
113318 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
113319 +read_file_slot_50111 read_file_slot 3 50111 NULL
113320 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
113321 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
113322 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
113323 +copy_items_50140 copy_items 6 50140 NULL
113324 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
113325 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
113326 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
113327 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
113328 +odev_update_50169 odev_update 2 50169 NULL
113329 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
113330 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
113331 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
113332 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
113333 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
113334 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
113335 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
113336 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
113337 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
113338 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
113339 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
113340 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
113341 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
113342 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
113343 +do_launder_page_50329 do_launder_page 0 50329 NULL
113344 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
113345 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
113346 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
113347 +tpm_read_50344 tpm_read 3 50344 NULL
113348 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
113349 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
113350 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
113351 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
113352 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
113353 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
113354 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
113355 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
113356 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
113357 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
113358 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
113359 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
113360 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
113361 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
113362 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
113363 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
113364 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
113365 +fat_readpages_50582 fat_readpages 4 50582 NULL
113366 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
113367 +xillybus_write_50605 xillybus_write 3 50605 NULL
113368 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
113369 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
113370 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
113371 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
113372 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
113373 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
113374 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
113375 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
113376 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
113377 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
113378 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
113379 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
113380 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
113381 +tpm_write_50798 tpm_write 3 50798 NULL
113382 +write_flush_50803 write_flush 3 50803 NULL
113383 +dvb_play_50814 dvb_play 3 50814 NULL
113384 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
113385 +SetArea_50835 SetArea 4 50835 NULL
113386 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
113387 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
113388 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
113389 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
113390 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
113391 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
113392 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
113393 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
113394 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
113395 +show_device_status_50947 show_device_status 0 50947 NULL
113396 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
113397 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
113398 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
113399 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
113400 +iwl_statistics_flag_50981 iwl_statistics_flag 3-0 50981 NULL
113401 +timeout_write_50991 timeout_write 3 50991 NULL
113402 +proc_write_51003 proc_write 3 51003 NULL
113403 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
113404 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
113405 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
113406 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
113407 +dump_midi_51040 dump_midi 3 51040 NULL
113408 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
113409 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
113410 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
113411 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
113412 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
113413 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
113414 +ti_recv_51110 ti_recv 3 51110 NULL
113415 +uasp_prepare_r_request_51124 uasp_prepare_r_request 0 51124 NULL
113416 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
113417 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
113418 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
113419 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
113420 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
113421 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
113422 +drm_property_create_51239 drm_property_create 4 51239 NULL
113423 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
113424 +st_read_51251 st_read 3 51251 NULL
113425 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
113426 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
113427 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
113428 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
113429 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
113430 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
113431 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
113432 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
113433 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
113434 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
113435 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
113436 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
113437 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
113438 +ceph_sync_read_51410 ceph_sync_read 3-0 51410 NULL
113439 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
113440 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
113441 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
113442 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
113443 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
113444 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
113445 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
113446 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
113447 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
113448 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
113449 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
113450 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
113451 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
113452 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
113453 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
113454 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
113455 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
113456 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
113457 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
113458 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
113459 +sel_write_access_51704 sel_write_access 3 51704 NULL
113460 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
113461 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
113462 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
113463 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
113464 +cm4040_read_51732 cm4040_read 3 51732 NULL
113465 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
113466 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
113467 +if_write_51756 if_write 3 51756 NULL
113468 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
113469 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
113470 +ioread32_51847 ioread32 0 51847 NULL nohasharray
113471 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
113472 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
113473 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
113474 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
113475 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
113476 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
113477 +user_read_51881 user_read 3 51881 NULL
113478 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
113479 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
113480 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
113481 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
113482 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
113483 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
113484 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
113485 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
113486 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
113487 +get_zone_51981 get_zone 0-1 51981 NULL
113488 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
113489 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
113490 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
113491 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
113492 +rdmalt_52022 rdmalt 0 52022 NULL
113493 +override_release_52032 override_release 2 52032 NULL
113494 +end_port_52042 end_port 0 52042 NULL
113495 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
113496 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
113497 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
113498 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
113499 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
113500 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
113501 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
113502 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
113503 +retry_count_read_52129 retry_count_read 3 52129 NULL
113504 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
113505 +sub_alloc_52140 sub_alloc 0 52140 NULL
113506 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
113507 +htable_size_52148 htable_size 0-1 52148 NULL
113508 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
113509 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
113510 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
113511 +print_prefix_52176 print_prefix 0 52176 NULL
113512 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
113513 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
113514 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
113515 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 3 52243 &fuse_request_alloc_52243
113516 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
113517 +shrink_slab_52261 shrink_slab 2 52261 NULL
113518 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
113519 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
113520 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
113521 +read_file_reset_52310 read_file_reset 3 52310 NULL
113522 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
113523 +hwflags_read_52318 hwflags_read 3 52318 NULL
113524 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
113525 +hur_len_52339 hur_len 0 52339 NULL
113526 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
113527 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
113528 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
113529 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
113530 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
113531 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
113532 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
113533 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
113534 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
113535 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
113536 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
113537 +delay_status_52431 delay_status 5 52431 NULL
113538 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
113539 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
113540 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
113541 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
113542 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
113543 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
113544 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
113545 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
113546 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
113547 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
113548 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
113549 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
113550 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
113551 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
113552 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
113553 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
113554 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
113555 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
113556 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
113557 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
113558 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
113559 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
113560 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
113561 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
113562 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
113563 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
113564 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
113565 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
113566 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
113567 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
113568 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
113569 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
113570 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
113571 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
113572 +ext2_xattr_set_acl_52857 ext2_xattr_set_acl 4 52857 NULL
113573 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
113574 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
113575 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
113576 +twlreg_write_52880 twlreg_write 3 52880 NULL
113577 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
113578 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
113579 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
113580 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
113581 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
113582 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
113583 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
113584 +send_packet_52960 send_packet 4 52960 NULL
113585 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
113586 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
113587 +num_node_state_52989 num_node_state 0 52989 NULL
113588 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
113589 +uasp_alloc_stream_res_53015 uasp_alloc_stream_res 0 53015 NULL
113590 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
113591 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
113592 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
113593 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
113594 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
113595 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
113596 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
113597 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
113598 +verity_status_53120 verity_status 5 53120 NULL
113599 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
113600 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
113601 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
113602 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
113603 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
113604 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
113605 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
113606 +hfsplus_xattr_set_posix_acl_53249 hfsplus_xattr_set_posix_acl 4 53249 NULL
113607 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
113608 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
113609 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
113610 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
113611 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
113612 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
113613 +vm_mmap_53339 vm_mmap 0 53339 NULL
113614 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
113615 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
113616 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
113617 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
113618 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
113619 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
113620 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
113621 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL
113622 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
113623 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
113624 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
113625 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
113626 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
113627 +ocfs2_xattr_set_acl_53508 ocfs2_xattr_set_acl 4 53508 NULL
113628 +check_acl_53512 check_acl 0 53512 NULL
113629 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
113630 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
113631 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
113632 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
113633 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
113634 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
113635 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
113636 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
113637 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
113638 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
113639 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
113640 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
113641 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
113642 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
113643 +bio_integrity_split_53714 bio_integrity_split 3 53714 NULL
113644 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
113645 +wdm_write_53735 wdm_write 3 53735 NULL
113646 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
113647 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
113648 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
113649 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
113650 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
113651 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
113652 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
113653 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
113654 +setup_data_read_53822 setup_data_read 3 53822 NULL
113655 +pms_read_53873 pms_read 3 53873 NULL
113656 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
113657 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
113658 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
113659 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
113660 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
113661 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
113662 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
113663 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
113664 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
113665 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
113666 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
113667 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
113668 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
113669 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
113670 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
113671 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
113672 +_malloc_54077 _malloc 1 54077 NULL
113673 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
113674 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
113675 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
113676 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
113677 +strn_len_54122 strn_len 0 54122 NULL
113678 +isku_receive_54130 isku_receive 4 54130 NULL
113679 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
113680 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
113681 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
113682 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
113683 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
113684 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
113685 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
113686 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
113687 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
113688 +reada_add_block_54247 reada_add_block 2 54247 NULL
113689 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
113690 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
113691 +audio_write_54261 audio_write 4 54261 NULL nohasharray
113692 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
113693 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
113694 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
113695 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
113696 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
113697 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
113698 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
113699 +sprintf_54306 sprintf 0 54306 NULL
113700 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
113701 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
113702 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
113703 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
113704 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
113705 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
113706 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
113707 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
113708 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
113709 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
113710 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
113711 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
113712 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
113713 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
113714 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
113715 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
113716 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
113717 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
113718 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
113719 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
113720 +viacam_read_54526 viacam_read 3 54526 NULL
113721 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
113722 +setsockopt_54539 setsockopt 5 54539 NULL
113723 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
113724 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
113725 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
113726 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
113727 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
113728 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
113729 +port_fops_write_54627 port_fops_write 3 54627 NULL
113730 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
113731 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
113732 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
113733 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
113734 +bus_add_device_54665 bus_add_device 0 54665 NULL
113735 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
113736 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
113737 +evm_read_key_54674 evm_read_key 3 54674 NULL
113738 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
113739 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
113740 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
113741 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
113742 +kzalloc_54740 kzalloc 1 54740 NULL
113743 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
113744 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
113745 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
113746 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
113747 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
113748 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
113749 +nfsd_write_54809 nfsd_write 6 54809 NULL
113750 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
113751 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
113752 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
113753 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
113754 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
113755 +write_rio_54837 write_rio 3 54837 NULL
113756 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
113757 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
113758 +ll_layout_conf_54841 ll_layout_conf 0 54841 NULL
113759 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
113760 +printer_read_54851 printer_read 3 54851 NULL
113761 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
113762 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
113763 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
113764 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
113765 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
113766 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
113767 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
113768 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
113769 +add_port_54941 add_port 2 54941 NULL
113770 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
113771 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
113772 +c4_add_card_54968 c4_add_card 3 54968 NULL
113773 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
113774 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
113775 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
113776 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
113777 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
113778 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
113779 +read_dma_55086 read_dma 3 55086 NULL
113780 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
113781 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
113782 +filldir_55137 filldir 3 55137 NULL
113783 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
113784 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
113785 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
113786 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
113787 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
113788 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
113789 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
113790 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
113791 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
113792 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
113793 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
113794 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
113795 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
113796 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
113797 +persistent_ram_new_55286 persistent_ram_new 2-1 55286 NULL
113798 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
113799 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
113800 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
113801 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
113802 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
113803 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
113804 +vme_user_read_55338 vme_user_read 3 55338 NULL
113805 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
113806 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
113807 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
113808 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
113809 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
113810 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
113811 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
113812 +sysfs_sd_setattr_55437 sysfs_sd_setattr 0 55437 NULL
113813 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
113814 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
113815 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
113816 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
113817 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
113818 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
113819 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
113820 +ea_get_55522 ea_get 3-0 55522 NULL
113821 +buffer_size_55534 buffer_size 0 55534 NULL
113822 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
113823 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
113824 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
113825 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
113826 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
113827 +__vdev_disk_physio_55568 __vdev_disk_physio 4 55568 NULL
113828 +add_partition_55588 add_partition 2 55588 NULL
113829 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
113830 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL nohasharray
113831 +config_buf_55602 config_buf 0 55602 &SyS_keyctl_55602
113832 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
113833 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
113834 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
113835 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
113836 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
113837 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
113838 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
113839 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
113840 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
113841 +get_info_55681 get_info 3 55681 NULL
113842 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
113843 +echo_big_lmm_get_55690 echo_big_lmm_get 0 55690 NULL
113844 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
113845 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
113846 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
113847 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
113848 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
113849 +set_local_name_55757 set_local_name 4 55757 NULL
113850 +strlen_55778 strlen 0 55778 NULL
113851 +set_spte_55783 set_spte 4-5 55783 NULL
113852 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
113853 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
113854 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
113855 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
113856 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
113857 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
113858 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
113859 +hsc_write_55875 hsc_write 3 55875 NULL
113860 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
113861 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
113862 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
113863 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
113864 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
113865 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
113866 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
113867 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
113868 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
113869 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
113870 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
113871 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
113872 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
113873 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
113874 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
113875 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
113876 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
113877 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
113878 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
113879 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
113880 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
113881 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
113882 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
113883 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
113884 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
113885 +fd_copyin_56247 fd_copyin 3 56247 NULL
113886 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
113887 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
113888 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
113889 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
113890 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
113891 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
113892 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
113893 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
113894 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
113895 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
113896 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
113897 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
113898 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
113899 +dev_read_56369 dev_read 3 56369 NULL
113900 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
113901 +write_gssp_56404 write_gssp 3 56404 NULL
113902 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
113903 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
113904 +store_msg_56417 store_msg 3 56417 NULL
113905 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
113906 +fl_create_56435 fl_create 5 56435 NULL
113907 +gnttab_map_56439 gnttab_map 2 56439 NULL
113908 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
113909 +set_connectable_56458 set_connectable 4 56458 NULL
113910 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
113911 +putused_user_56467 putused_user 3 56467 NULL
113912 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
113913 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
113914 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
113915 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
113916 +init_map_ip_56508 init_map_ip 5 56508 NULL
113917 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
113918 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
113919 +ip_options_get_56538 ip_options_get 4 56538 NULL
113920 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
113921 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
113922 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
113923 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
113924 +event_filter_write_56609 event_filter_write 3 56609 NULL
113925 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
113926 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
113927 +gather_array_56641 gather_array 3 56641 NULL
113928 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
113929 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
113930 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
113931 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
113932 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
113933 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
113934 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
113935 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
113936 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
113937 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
113938 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
113939 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
113940 +do_syslog_56807 do_syslog 3 56807 NULL
113941 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
113942 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
113943 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
113944 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
113945 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
113946 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
113947 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
113948 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
113949 +hfsplus_setxattr_56902 hfsplus_setxattr 4 56902 NULL
113950 +strcspn_56913 strcspn 0 56913 NULL
113951 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
113952 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
113953 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
113954 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
113955 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
113956 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
113957 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
113958 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
113959 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
113960 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
113961 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
113962 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
113963 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
113964 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
113965 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
113966 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
113967 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
113968 +altera_get_note_57099 altera_get_note 6 57099 NULL
113969 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
113970 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
113971 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
113972 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
113973 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
113974 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
113975 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
113976 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
113977 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
113978 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
113979 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
113980 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
113981 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
113982 +dma_fifo_alloc_57236 dma_fifo_alloc 5-3-2 57236 NULL
113983 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
113984 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
113985 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
113986 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
113987 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
113988 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
113989 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
113990 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
113991 +write_file_regval_57313 write_file_regval 3 57313 NULL
113992 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
113993 +usblp_read_57342 usblp_read 3 57342 NULL
113994 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
113995 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
113996 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
113997 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
113998 +read_file_blob_57406 read_file_blob 3 57406 NULL
113999 +enclosure_register_57412 enclosure_register 3 57412 NULL
114000 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
114001 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
114002 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
114003 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
114004 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
114005 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
114006 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
114007 +skb_headlen_57501 skb_headlen 0 57501 NULL
114008 +copy_in_user_57502 copy_in_user 3 57502 NULL
114009 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
114010 +init_tag_map_57515 init_tag_map 3 57515 NULL
114011 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
114012 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
114013 +cmm_read_57520 cmm_read 3 57520 NULL
114014 +inode_permission_57531 inode_permission 0 57531 NULL
114015 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
114016 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
114017 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
114018 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
114019 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
114020 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
114021 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
114022 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
114023 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
114024 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
114025 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
114026 +mem_read_57631 mem_read 3 57631 NULL
114027 +r3964_write_57662 r3964_write 4 57662 NULL
114028 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
114029 +__lgwrite_57669 __lgwrite 4 57669 NULL
114030 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
114031 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
114032 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
114033 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
114034 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
114035 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
114036 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
114037 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
114038 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
114039 +ld2_57794 ld2 0 57794 NULL
114040 +ivtv_read_57796 ivtv_read 3 57796 NULL
114041 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
114042 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
114043 +flash_read_57843 flash_read 3 57843 NULL
114044 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
114045 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
114046 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
114047 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
114048 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
114049 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
114050 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
114051 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
114052 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
114053 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
114054 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
114055 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
114056 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
114057 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
114058 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
114059 +mce_async_out_58056 mce_async_out 3 58056 NULL
114060 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
114061 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
114062 +cm4040_write_58079 cm4040_write 3 58079 NULL
114063 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
114064 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
114065 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
114066 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
114067 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
114068 +read_file_debug_58256 read_file_debug 3 58256 NULL
114069 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
114070 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
114071 +profile_load_58267 profile_load 3 58267 NULL
114072 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
114073 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
114074 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
114075 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
114076 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
114077 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
114078 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
114079 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
114080 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
114081 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
114082 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
114083 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
114084 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
114085 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
114086 +capabilities_read_58457 capabilities_read 3 58457 NULL
114087 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
114088 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
114089 +nv_rd08_58472 nv_rd08 0 58472 NULL
114090 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
114091 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
114092 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
114093 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
114094 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
114095 +ldlm_srv_pool_shrink_58554 ldlm_srv_pool_shrink 0 58554 NULL
114096 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
114097 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
114098 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
114099 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
114100 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
114101 +xip_file_read_58592 xip_file_read 3 58592 NULL
114102 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
114103 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
114104 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
114105 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
114106 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
114107 +find_zero_58685 find_zero 0-1 58685 NULL
114108 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
114109 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
114110 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
114111 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
114112 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
114113 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
114114 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
114115 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
114116 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
114117 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
114118 +ep_read_58813 ep_read 3 58813 NULL
114119 +command_write_58841 command_write 3 58841 NULL
114120 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
114121 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
114122 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
114123 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
114124 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
114125 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
114126 +sptlrpc_import_sec_adapt_58948 sptlrpc_import_sec_adapt 0 58948 NULL
114127 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
114128 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
114129 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
114130 +init_list_set_59005 init_list_set 3 59005 NULL
114131 +ep_write_59008 ep_write 3 59008 NULL
114132 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
114133 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
114134 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
114135 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
114136 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
114137 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
114138 +sysfs_link_sibling_59078 sysfs_link_sibling 0 59078 NULL
114139 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
114140 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL
114141 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
114142 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
114143 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
114144 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
114145 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
114146 +md_getxattr_59161 md_getxattr 0 59161 NULL
114147 +ksize_59176 ksize 0 59176 NULL
114148 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
114149 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
114150 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
114151 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
114152 +dt3155_read_59226 dt3155_read 3 59226 NULL
114153 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
114154 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
114155 +nla_len_59258 nla_len 0 59258 NULL
114156 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
114157 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
114158 +fd_copyout_59323 fd_copyout 3 59323 NULL
114159 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
114160 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
114161 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
114162 +__map_request_59350 __map_request 0 59350 NULL
114163 +f2fs_fallocate_59377 f2fs_fallocate 3-4 59377 NULL
114164 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
114165 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
114166 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
114167 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
114168 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
114169 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
114170 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
114171 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
114172 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
114173 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
114174 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
114175 +tunables_write_59563 tunables_write 3 59563 NULL
114176 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
114177 +write_pbl_59583 write_pbl 4 59583 NULL
114178 +memdup_user_59590 memdup_user 2 59590 NULL
114179 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
114180 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
114181 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
114182 +mtrr_write_59622 mtrr_write 3 59622 NULL
114183 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
114184 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
114185 +hidraw_read_59650 hidraw_read 3 59650 NULL
114186 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
114187 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
114188 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
114189 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
114190 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
114191 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
114192 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
114193 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
114194 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
114195 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
114196 +strnlen_59746 strnlen 0 59746 NULL
114197 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
114198 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
114199 +venus_remove_59781 venus_remove 4 59781 NULL
114200 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
114201 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
114202 +ipw_write_59807 ipw_write 3 59807 NULL
114203 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
114204 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
114205 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
114206 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
114207 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
114208 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
114209 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
114210 +ocfs2_extend_rotate_transaction_59894 ocfs2_extend_rotate_transaction 2-3 59894 NULL
114211 +aic7xxx_abort_waiting_scb_59932 aic7xxx_abort_waiting_scb 0 59932 NULL
114212 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
114213 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
114214 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
114215 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
114216 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
114217 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
114218 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
114219 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
114220 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
114221 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
114222 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
114223 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
114224 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
114225 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
114226 +vcs_size_60050 vcs_size 0 60050 NULL
114227 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
114228 +compat_writev_60063 compat_writev 3 60063 NULL
114229 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
114230 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
114231 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
114232 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
114233 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
114234 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
114235 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
114236 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
114237 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
114238 +init_state_60165 init_state 2 60165 NULL
114239 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
114240 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
114241 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
114242 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
114243 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
114244 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
114245 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
114246 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
114247 +printer_write_60276 printer_write 3 60276 NULL
114248 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
114249 +getDataLength_60301 getDataLength 0 60301 NULL
114250 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
114251 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
114252 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
114253 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
114254 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
114255 +driver_names_read_60399 driver_names_read 3 60399 NULL
114256 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
114257 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
114258 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
114259 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
114260 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
114261 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
114262 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
114263 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
114264 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
114265 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
114266 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
114267 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
114268 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
114269 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
114270 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
114271 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
114272 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
114273 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
114274 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
114275 +raid_status_60755 raid_status 5 60755 NULL
114276 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
114277 +opticon_write_60775 opticon_write 4 60775 NULL
114278 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
114279 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
114280 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
114281 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
114282 +generic_writepages_60871 generic_writepages 0 60871 NULL
114283 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
114284 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
114285 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
114286 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
114287 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
114288 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
114289 +pti_char_write_60960 pti_char_write 3 60960 NULL
114290 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
114291 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
114292 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
114293 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
114294 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
114295 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
114296 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
114297 +symtab_init_61050 symtab_init 2 61050 NULL
114298 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
114299 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
114300 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
114301 +get_derived_key_61100 get_derived_key 4 61100 NULL
114302 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-1-2-3-4 61104 NULL
114303 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
114304 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
114305 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
114306 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
114307 +brcmf_sdio_chip_cr4_exitdl_61143 brcmf_sdio_chip_cr4_exitdl 4 61143 NULL
114308 +osl_malloc_61156 osl_malloc 2 61156 NULL
114309 +pair_device_61175 pair_device 4 61175 NULL nohasharray
114310 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
114311 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
114312 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
114313 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
114314 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
114315 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
114316 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
114317 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
114318 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
114319 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
114320 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
114321 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
114322 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
114323 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
114324 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
114325 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
114326 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
114327 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
114328 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
114329 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
114330 +system_enable_write_61396 system_enable_write 3 61396 NULL
114331 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
114332 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
114333 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
114334 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
114335 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
114336 +erst_errno_61526 erst_errno 0 61526 NULL
114337 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
114338 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
114339 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
114340 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
114341 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
114342 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
114343 +seq_open_private_61589 seq_open_private 3 61589 NULL
114344 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
114345 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
114346 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
114347 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
114348 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
114349 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
114350 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL
114351 +resize_stripes_61650 resize_stripes 2 61650 NULL
114352 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
114353 +insert_one_name_61668 insert_one_name 7 61668 NULL
114354 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
114355 +lock_loop_61681 lock_loop 1 61681 NULL
114356 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
114357 +filter_read_61692 filter_read 3 61692 NULL
114358 +iov_length_61716 iov_length 0 61716 NULL
114359 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
114360 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
114361 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
114362 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
114363 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
114364 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
114365 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
114366 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
114367 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
114368 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
114369 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
114370 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
114371 +get_fw_name_61874 get_fw_name 3 61874 NULL
114372 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
114373 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
114374 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
114375 +clear_refs_write_61904 clear_refs_write 3 61904 NULL nohasharray
114376 +import_sec_check_expire_61904 import_sec_check_expire 0 61904 &clear_refs_write_61904
114377 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
114378 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
114379 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
114380 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
114381 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
114382 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
114383 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
114384 +fix_read_error_61965 fix_read_error 4 61965 NULL
114385 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
114386 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
114387 +cow_file_range_61979 cow_file_range 3 61979 NULL
114388 +dequeue_event_62000 dequeue_event 3 62000 NULL
114389 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
114390 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
114391 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
114392 +SYSC_select_62024 SYSC_select 1 62024 NULL
114393 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
114394 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
114395 +do_pselect_62061 do_pselect 1 62061 NULL
114396 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
114397 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
114398 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
114399 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
114400 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
114401 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
114402 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
114403 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
114404 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
114405 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
114406 +video_usercopy_62151 video_usercopy 2 62151 NULL
114407 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
114408 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
114409 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
114410 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
114411 +btrfs_xattr_acl_set_62203 btrfs_xattr_acl_set 4 62203 NULL
114412 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
114413 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
114414 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
114415 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
114416 +get_random_int_62279 get_random_int 0 62279 NULL
114417 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
114418 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
114419 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
114420 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
114421 +ocfs2_xattr_buckets_per_cluster_62330 ocfs2_xattr_buckets_per_cluster 0 62330 NULL
114422 +subseq_list_62332 subseq_list 3-0 62332 NULL
114423 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
114424 +flash_write_62354 flash_write 3 62354 NULL
114425 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
114426 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
114427 +altera_irscan_62396 altera_irscan 2 62396 NULL
114428 +set_ssp_62411 set_ssp 4 62411 NULL
114429 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
114430 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
114431 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
114432 +debugfs_read_62535 debugfs_read 3 62535 NULL
114433 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
114434 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
114435 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
114436 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
114437 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
114438 +get_subdir_62581 get_subdir 3 62581 NULL
114439 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
114440 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
114441 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
114442 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
114443 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
114444 +ocfs2_wait_for_mask_interruptible_62675 ocfs2_wait_for_mask_interruptible 0 62675 NULL
114445 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
114446 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
114447 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
114448 +rdm_62719 rdm 0 62719 NULL
114449 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
114450 +key_replays_read_62746 key_replays_read 3 62746 NULL
114451 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
114452 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
114453 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
114454 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
114455 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
114456 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
114457 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
114458 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
114459 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
114460 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
114461 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
114462 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
114463 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
114464 +aoechr_write_62883 aoechr_write 3 62883 NULL
114465 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
114466 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
114467 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
114468 +getdqbuf_62908 getdqbuf 1 62908 NULL
114469 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
114470 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
114471 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
114472 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
114473 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
114474 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
114475 +unlink1_63059 unlink1 3 63059 NULL
114476 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
114477 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
114478 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
114479 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
114480 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
114481 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
114482 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
114483 +vme_master_read_63221 vme_master_read 0 63221 NULL
114484 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
114485 +ptp_read_63251 ptp_read 4 63251 NULL
114486 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
114487 +raid5_resize_63306 raid5_resize 2 63306 NULL
114488 +proc_info_read_63344 proc_info_read 3 63344 NULL
114489 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
114490 +idmouse_read_63374 idmouse_read 3 63374 NULL
114491 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
114492 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
114493 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
114494 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
114495 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
114496 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
114497 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
114498 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
114499 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
114500 +read_kcore_63488 read_kcore 3 63488 NULL
114501 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
114502 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
114503 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
114504 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
114505 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
114506 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
114507 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
114508 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
114509 +write_debug_level_63613 write_debug_level 3 63613 NULL
114510 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
114511 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
114512 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
114513 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
114514 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
114515 +vbi_read_63673 vbi_read 3 63673 NULL
114516 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
114517 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
114518 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
114519 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
114520 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
114521 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
114522 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
114523 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
114524 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
114525 +prepare_copy_63826 prepare_copy 2 63826 NULL
114526 +sel_write_load_63830 sel_write_load 3 63830 NULL
114527 +ll_readlink_63836 ll_readlink 3 63836 NULL
114528 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
114529 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
114530 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
114531 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
114532 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
114533 +__team_options_register_63941 __team_options_register 3 63941 NULL
114534 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
114535 +sysfs_add_one_63969 sysfs_add_one 0 63969 NULL
114536 +set_bredr_63975 set_bredr 4 63975 NULL
114537 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
114538 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
114539 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
114540 +hfsplus_security_setxattr_64009 hfsplus_security_setxattr 4 64009 NULL
114541 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
114542 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
114543 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
114544 +get_u8_64076 get_u8 0 64076 NULL
114545 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
114546 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
114547 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
114548 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
114549 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
114550 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
114551 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
114552 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
114553 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
114554 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
114555 +init_bch_64130 init_bch 1-2 64130 NULL
114556 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
114557 +read_div_64147 read_div 0 64147 NULL
114558 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
114559 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
114560 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
114561 +read_pulse_64227 read_pulse 0-3 64227 NULL
114562 +ea_len_64229 ea_len 0 64229 NULL
114563 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
114564 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
114565 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
114566 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
114567 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
114568 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
114569 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
114570 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
114571 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
114572 +ts_write_64336 ts_write 3 64336 NULL
114573 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
114574 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
114575 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
114576 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
114577 +reg_create_64372 reg_create 5 64372 NULL
114578 +ilo_write_64378 ilo_write 3 64378 NULL
114579 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
114580 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
114581 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
114582 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
114583 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
114584 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
114585 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
114586 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
114587 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
114588 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
114589 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
114590 +single_open_size_64483 single_open_size 4 64483 NULL
114591 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
114592 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
114593 +remove_uuid_64505 remove_uuid 4 64505 NULL
114594 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
114595 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
114596 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
114597 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
114598 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
114599 +SyS_bind_64544 SyS_bind 3 64544 NULL
114600 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
114601 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
114602 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
114603 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
114604 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
114605 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
114606 +do_erase_64574 do_erase 4 64574 NULL
114607 +fanotify_write_64623 fanotify_write 3 64623 NULL
114608 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
114609 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
114610 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
114611 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
114612 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
114613 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
114614 +sec_bulk_write_64691 sec_bulk_write 2-3 64691 NULL
114615 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
114616 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
114617 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
114618 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
114619 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
114620 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
114621 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
114622 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
114623 +message_for_md_64777 message_for_md 5 64777 NULL
114624 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
114625 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
114626 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
114627 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
114628 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
114629 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
114630 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
114631 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
114632 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
114633 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
114634 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
114635 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
114636 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
114637 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
114638 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
114639 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
114640 +insert_dent_65034 insert_dent 7 65034 NULL
114641 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
114642 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
114643 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
114644 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
114645 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
114646 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
114647 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
114648 +uasp_alloc_cmd_65097 uasp_alloc_cmd 0 65097 NULL
114649 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
114650 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
114651 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
114652 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
114653 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
114654 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
114655 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
114656 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
114657 +get_var_len_65304 get_var_len 0 65304 NULL
114658 +unpack_array_65318 unpack_array 0 65318 NULL
114659 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
114660 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
114661 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
114662 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
114663 +SyS_writev_65372 SyS_writev 3 65372 NULL
114664 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
114665 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
114666 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
114667 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
114668 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
114669 +device_add_groups_65423 device_add_groups 0 65423 NULL
114670 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
114671 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
114672 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
114673 +clear_user_65470 clear_user 2 65470 NULL
114674 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
114675 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
114676 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
114677 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
114678 diff --git a/tools/gcc/size_overflow_hash_aux.data b/tools/gcc/size_overflow_hash_aux.data
114679 new file mode 100644
114680 index 0000000..5dd8a8f
114681 --- /dev/null
114682 +++ b/tools/gcc/size_overflow_hash_aux.data
114683 @@ -0,0 +1,83 @@
114684 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
114685 +mappedread_2627 mappedread 2 2627 NULL
114686 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
114687 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
114688 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
114689 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
114690 +dmu_write_6048 dmu_write 4-3 6048 NULL
114691 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
114692 +update_pages_6225 update_pages 2-3 6225 NULL
114693 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
114694 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
114695 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
114696 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
114697 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
114698 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
114699 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
114700 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
114701 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
114702 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
114703 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
114704 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
114705 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
114706 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
114707 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
114708 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
114709 +uiocopy_18680 uiocopy 2 18680 NULL
114710 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
114711 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
114712 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
114713 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
114714 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
114715 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
114716 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
114717 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
114718 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
114719 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
114720 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
114721 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
114722 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
114723 +splat_write_30943 splat_write 3 30943 NULL
114724 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
114725 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
114726 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
114727 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
114728 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
114729 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
114730 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
114731 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
114732 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
114733 +copyinstr_36980 copyinstr 3 36980 NULL
114734 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
114735 +splat_read_38116 splat_read 3 38116 NULL
114736 +sa_setup_38756 sa_setup 4 38756 NULL
114737 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
114738 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
114739 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
114740 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
114741 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
114742 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
114743 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
114744 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
114745 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
114746 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
114747 +uiomove_44355 uiomove 2 44355 NULL
114748 +dmu_read_44418 dmu_read 4-3 44418 NULL
114749 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
114750 +copyin_45945 copyin 3 45945 NULL
114751 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
114752 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
114753 +spa_history_write_49650 spa_history_write 3 49650 NULL
114754 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
114755 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
114756 +copyout_51409 copyout 3 51409 NULL
114757 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
114758 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
114759 +get_nvlist_56685 get_nvlist 2 56685 NULL
114760 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
114761 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
114762 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
114763 +zpios_write_61823 zpios_write 3 61823 NULL
114764 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
114765 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
114766 +zpios_read_64734 zpios_read 3 64734 NULL
114767 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
114768 new file mode 100644
114769 index 0000000..0a9dd22
114770 --- /dev/null
114771 +++ b/tools/gcc/size_overflow_plugin.c
114772 @@ -0,0 +1,4110 @@
114773 +/*
114774 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114775 + * Licensed under the GPL v2, or (at your option) v3
114776 + *
114777 + * Homepage:
114778 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114779 + *
114780 + * Documentation:
114781 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114782 + *
114783 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114784 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114785 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114786 + *
114787 + * Usage:
114788 + * $ # for 4.5/4.6/C based 4.7
114789 + * $ 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
114790 + * $ # for C++ based 4.7/4.8+
114791 + * $ 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
114792 + *
114793 + * $ gcc -fplugin=./size_overflow_plugin.so test.c -O2
114794 + */
114795 +
114796 +#include "gcc-common.h"
114797 +
114798 +int plugin_is_GPL_compatible;
114799 +
114800 +static struct plugin_info size_overflow_plugin_info = {
114801 + .version = "20140402",
114802 + .help = "no-size-overflow\tturn off size overflow checking\n",
114803 +};
114804 +
114805 +#define BEFORE_STMT true
114806 +#define AFTER_STMT false
114807 +#define CREATE_NEW_VAR NULL_TREE
114808 +#define CODES_LIMIT 32
114809 +#define MAX_PARAM 31
114810 +#define VEC_LEN 128
114811 +#define RET_CHECK NULL_TREE
114812 +#define CANNOT_FIND_ARG 32
114813 +#define WRONG_NODE 32
114814 +#define NOT_INTENTIONAL_ASM NULL
114815 +#define MIN_CHECK true
114816 +#define MAX_CHECK false
114817 +
114818 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114819 +#define YES_ASM_STR "# size_overflow MARK_YES "
114820 +#define OK_ASM_STR "# size_overflow "
114821 +
114822 +struct size_overflow_hash {
114823 + const struct size_overflow_hash * const next;
114824 + const char * const name;
114825 + const unsigned int param;
114826 +};
114827 +
114828 +#include "size_overflow_hash.h"
114829 +#include "size_overflow_hash_aux.h"
114830 +
114831 +enum mark {
114832 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114833 +};
114834 +
114835 +static unsigned int call_count;
114836 +
114837 +enum stmt_flags {
114838 + MY_STMT, NO_CAST_CHECK, VISITED_STMT, NO_FLAGS
114839 +};
114840 +
114841 +struct visited {
114842 + struct visited *next;
114843 + const_tree fndecl;
114844 + unsigned int num;
114845 +};
114846 +
114847 +struct next_cgraph_node {
114848 + struct next_cgraph_node *next;
114849 + struct cgraph_node *current_function;
114850 + tree callee_fndecl;
114851 + unsigned int num;
114852 +};
114853 +
114854 +struct interesting_node {
114855 + struct interesting_node *next;
114856 + gimple first_stmt;
114857 + const_tree fndecl;
114858 + tree node;
114859 +#if BUILDING_GCC_VERSION <= 4007
114860 + VEC(tree, gc) *last_nodes;
114861 +#else
114862 + vec<tree, va_gc> *last_nodes;
114863 +#endif
114864 + unsigned int num;
114865 + enum mark intentional_attr_decl;
114866 + enum mark intentional_attr_cur_fndecl;
114867 + gimple intentional_mark_from_gimple;
114868 +};
114869 +
114870 +static tree report_size_overflow_decl;
114871 +
114872 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
114873 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
114874 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
114875 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114876 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114877 +
114878 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114879 +static tree get_size_overflow_type(gimple stmt, const_tree node);
114880 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114881 +
114882 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114883 +{
114884 + unsigned int arg_count;
114885 + enum tree_code code = TREE_CODE(*node);
114886 +
114887 + switch (code) {
114888 + case FUNCTION_DECL:
114889 + arg_count = type_num_arguments(TREE_TYPE(*node));
114890 + break;
114891 + case FUNCTION_TYPE:
114892 + case METHOD_TYPE:
114893 + arg_count = type_num_arguments(*node);
114894 + break;
114895 + default:
114896 + *no_add_attrs = true;
114897 + error("%s: %qE attribute only applies to functions", __func__, name);
114898 + return NULL_TREE;
114899 + }
114900 +
114901 + for (; args; args = TREE_CHAIN(args)) {
114902 + tree position = TREE_VALUE(args);
114903 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114904 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114905 + *no_add_attrs = true;
114906 + }
114907 + }
114908 + return NULL_TREE;
114909 +}
114910 +
114911 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114912 +{
114913 + unsigned int arg_count;
114914 + enum tree_code code = TREE_CODE(*node);
114915 +
114916 + switch (code) {
114917 + case FUNCTION_DECL:
114918 + arg_count = type_num_arguments(TREE_TYPE(*node));
114919 + break;
114920 + case FUNCTION_TYPE:
114921 + case METHOD_TYPE:
114922 + arg_count = type_num_arguments(*node);
114923 + break;
114924 + case FIELD_DECL:
114925 + return NULL_TREE;
114926 + default:
114927 + *no_add_attrs = true;
114928 + error("%qE attribute only applies to functions", name);
114929 + return NULL_TREE;
114930 + }
114931 +
114932 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
114933 + return NULL_TREE;
114934 +
114935 + for (; args; args = TREE_CHAIN(args)) {
114936 + tree position = TREE_VALUE(args);
114937 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114938 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114939 + *no_add_attrs = true;
114940 + }
114941 + }
114942 + return NULL_TREE;
114943 +}
114944 +
114945 +static struct attribute_spec size_overflow_attr = {
114946 + .name = "size_overflow",
114947 + .min_length = 1,
114948 + .max_length = -1,
114949 + .decl_required = true,
114950 + .type_required = false,
114951 + .function_type_required = false,
114952 + .handler = handle_size_overflow_attribute,
114953 +#if BUILDING_GCC_VERSION >= 4007
114954 + .affects_type_identity = false
114955 +#endif
114956 +};
114957 +
114958 +static struct attribute_spec intentional_overflow_attr = {
114959 + .name = "intentional_overflow",
114960 + .min_length = 1,
114961 + .max_length = -1,
114962 + .decl_required = true,
114963 + .type_required = false,
114964 + .function_type_required = false,
114965 + .handler = handle_intentional_overflow_attribute,
114966 +#if BUILDING_GCC_VERSION >= 4007
114967 + .affects_type_identity = false
114968 +#endif
114969 +};
114970 +
114971 +static void register_attributes(void __unused *event_data, void __unused *data)
114972 +{
114973 + register_attribute(&size_overflow_attr);
114974 + register_attribute(&intentional_overflow_attr);
114975 +}
114976 +
114977 +static enum stmt_flags get_stmt_flag(gimple stmt)
114978 +{
114979 + bool bit_1, bit_2;
114980 +
114981 + bit_1 = gimple_plf(stmt, GF_PLF_1);
114982 + bit_2 = gimple_plf(stmt, GF_PLF_2);
114983 +
114984 + if (!bit_1 && !bit_2)
114985 + return NO_FLAGS;
114986 + if (bit_1 && bit_2)
114987 + return MY_STMT;
114988 + if (!bit_1 && bit_2)
114989 + return VISITED_STMT;
114990 + return NO_CAST_CHECK;
114991 +}
114992 +
114993 +static void set_stmt_flag(gimple stmt, enum stmt_flags new_flag)
114994 +{
114995 + bool bit_1, bit_2;
114996 +
114997 + switch (new_flag) {
114998 + case NO_FLAGS:
114999 + bit_1 = bit_2 = false;
115000 + break;
115001 + case MY_STMT:
115002 + bit_1 = bit_2 = true;
115003 + break;
115004 + case VISITED_STMT:
115005 + bit_1 = false;
115006 + bit_2 = true;
115007 + break;
115008 + case NO_CAST_CHECK:
115009 + bit_1 = true;
115010 + bit_2 = false;
115011 + break;
115012 + default:
115013 + gcc_unreachable();
115014 + }
115015 +
115016 + gimple_set_plf(stmt, GF_PLF_1, bit_1);
115017 + gimple_set_plf(stmt, GF_PLF_2, bit_2);
115018 +}
115019 +
115020 +static bool is_bool(const_tree node)
115021 +{
115022 + const_tree type;
115023 +
115024 + if (node == NULL_TREE)
115025 + return false;
115026 +
115027 + type = TREE_TYPE(node);
115028 + if (!INTEGRAL_TYPE_P(type))
115029 + return false;
115030 + if (TREE_CODE(type) == BOOLEAN_TYPE)
115031 + return true;
115032 + if (TYPE_PRECISION(type) == 1)
115033 + return true;
115034 + return false;
115035 +}
115036 +
115037 +static bool skip_types(const_tree var)
115038 +{
115039 + tree type;
115040 + enum tree_code code;
115041 +
115042 + if (is_gimple_constant(var))
115043 + return true;
115044 +
115045 + switch (TREE_CODE(var)) {
115046 + case ADDR_EXPR:
115047 +#if BUILDING_GCC_VERSION >= 4006
115048 + case MEM_REF:
115049 +#endif
115050 + case ARRAY_REF:
115051 + case BIT_FIELD_REF:
115052 + case INDIRECT_REF:
115053 + case TARGET_MEM_REF:
115054 + case COMPONENT_REF:
115055 + case VAR_DECL:
115056 + case VIEW_CONVERT_EXPR:
115057 + return true;
115058 + default:
115059 + break;
115060 + }
115061 +
115062 + code = TREE_CODE(var);
115063 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
115064 +
115065 + type = TREE_TYPE(var);
115066 + switch (TREE_CODE(type)) {
115067 + case INTEGER_TYPE:
115068 + case ENUMERAL_TYPE:
115069 + return false;
115070 + case BOOLEAN_TYPE:
115071 + return is_bool(var);
115072 + default:
115073 + return true;
115074 + }
115075 +}
115076 +
115077 +static inline gimple get_def_stmt(const_tree node)
115078 +{
115079 + gcc_assert(node != NULL_TREE);
115080 +
115081 + if (skip_types(node))
115082 + return NULL;
115083 +
115084 + if (TREE_CODE(node) != SSA_NAME)
115085 + return NULL;
115086 + return SSA_NAME_DEF_STMT(node);
115087 +}
115088 +
115089 +static unsigned char get_tree_code(const_tree type)
115090 +{
115091 + switch (TREE_CODE(type)) {
115092 + case ARRAY_TYPE:
115093 + return 0;
115094 + case BOOLEAN_TYPE:
115095 + return 1;
115096 + case ENUMERAL_TYPE:
115097 + return 2;
115098 + case FUNCTION_TYPE:
115099 + return 3;
115100 + case INTEGER_TYPE:
115101 + return 4;
115102 + case POINTER_TYPE:
115103 + return 5;
115104 + case RECORD_TYPE:
115105 + return 6;
115106 + case UNION_TYPE:
115107 + return 7;
115108 + case VOID_TYPE:
115109 + return 8;
115110 + case REAL_TYPE:
115111 + return 9;
115112 + case VECTOR_TYPE:
115113 + return 10;
115114 + case REFERENCE_TYPE:
115115 + return 11;
115116 + case OFFSET_TYPE:
115117 + return 12;
115118 + case COMPLEX_TYPE:
115119 + return 13;
115120 + default:
115121 + debug_tree((tree)type);
115122 + gcc_unreachable();
115123 + }
115124 +}
115125 +
115126 +struct function_hash {
115127 + size_t tree_codes_len;
115128 + unsigned char tree_codes[CODES_LIMIT];
115129 + const_tree fndecl;
115130 + unsigned int hash;
115131 +};
115132 +
115133 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
115134 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
115135 +{
115136 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
115137 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
115138 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
115139 +
115140 + unsigned int m = 0x57559429;
115141 + unsigned int n = 0x5052acdb;
115142 + const unsigned int *key4 = (const unsigned int *)key;
115143 + unsigned int h = len;
115144 + unsigned int k = len + seed + n;
115145 + unsigned long long p;
115146 +
115147 + while (len >= 8) {
115148 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
115149 + len -= 8;
115150 + }
115151 + if (len >= 4) {
115152 + cwmixb(key4[0]) key4 += 1;
115153 + len -= 4;
115154 + }
115155 + if (len)
115156 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
115157 + cwmixb(h ^ (k + n));
115158 + return k ^ h;
115159 +
115160 +#undef cwfold
115161 +#undef cwmixa
115162 +#undef cwmixb
115163 +}
115164 +
115165 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
115166 +{
115167 + unsigned int fn, codes, seed = 0;
115168 +
115169 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
115170 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
115171 +
115172 + fn_hash_data->hash = fn ^ codes;
115173 +}
115174 +
115175 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
115176 +{
115177 + gcc_assert(type != NULL_TREE);
115178 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
115179 +
115180 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
115181 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
115182 + fn_hash_data->tree_codes_len++;
115183 + type = TREE_TYPE(type);
115184 + }
115185 +}
115186 +
115187 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
115188 +{
115189 + const_tree result;
115190 +
115191 + gcc_assert(node != NULL_TREE);
115192 +
115193 + if (DECL_P(node)) {
115194 + result = DECL_RESULT(node);
115195 + if (result != NULL_TREE)
115196 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
115197 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
115198 + }
115199 +
115200 + gcc_assert(TYPE_P(node));
115201 +
115202 + if (TREE_CODE(node) == FUNCTION_TYPE)
115203 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
115204 +
115205 + return set_node_codes(node, fn_hash_data);
115206 +}
115207 +
115208 +static void set_function_codes(struct function_hash *fn_hash_data)
115209 +{
115210 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
115211 + enum tree_code code = TREE_CODE(type);
115212 +
115213 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
115214 +
115215 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
115216 +
115217 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
115218 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
115219 +}
115220 +
115221 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
115222 +{
115223 + while (entry) {
115224 + if (!strcmp(entry->name, func_name))
115225 + return entry;
115226 + entry = entry->next;
115227 + }
115228 + return NULL;
115229 +}
115230 +
115231 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
115232 +{
115233 + const struct size_overflow_hash *entry;
115234 + struct function_hash fn_hash_data;
115235 + const char *func_name;
115236 +
115237 + // skip builtins __builtin_constant_p
115238 + if (DECL_BUILT_IN(fndecl))
115239 + return NULL;
115240 +
115241 + fn_hash_data.fndecl = fndecl;
115242 + fn_hash_data.tree_codes_len = 0;
115243 +
115244 + set_function_codes(&fn_hash_data);
115245 + gcc_assert(fn_hash_data.tree_codes_len != 0);
115246 +
115247 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
115248 + set_hash(func_name, &fn_hash_data);
115249 +
115250 + entry = size_overflow_hash[fn_hash_data.hash];
115251 + entry = get_proper_hash_chain(entry, func_name);
115252 + if (entry)
115253 + return entry;
115254 + entry = size_overflow_hash_aux[fn_hash_data.hash];
115255 + return get_proper_hash_chain(entry, func_name);
115256 +}
115257 +
115258 +static void print_missing_msg(const_tree func, unsigned int argnum)
115259 +{
115260 + location_t loc;
115261 + const char *curfunc;
115262 + struct function_hash fn_hash_data;
115263 +
115264 + fn_hash_data.fndecl = DECL_ORIGIN(func);
115265 + fn_hash_data.tree_codes_len = 0;
115266 +
115267 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
115268 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
115269 +
115270 + set_function_codes(&fn_hash_data);
115271 + set_hash(curfunc, &fn_hash_data);
115272 +
115273 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
115274 +}
115275 +
115276 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
115277 +{
115278 + tree var;
115279 + unsigned int argnum = 1;
115280 +
115281 + if (TREE_CODE(arg) == SSA_NAME)
115282 + arg = SSA_NAME_VAR(arg);
115283 +
115284 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
115285 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
115286 + continue;
115287 + if (!skip_types(var))
115288 + return argnum;
115289 + }
115290 +
115291 + return CANNOT_FIND_ARG;
115292 +}
115293 +
115294 +static tree create_new_var(tree type)
115295 +{
115296 + tree new_var = create_tmp_var(type, "cicus");
115297 +
115298 + add_referenced_var(new_var);
115299 + return new_var;
115300 +}
115301 +
115302 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
115303 +{
115304 + gimple assign;
115305 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115306 + tree type = TREE_TYPE(rhs1);
115307 + tree lhs = create_new_var(type);
115308 +
115309 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
115310 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
115311 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115312 +
115313 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
115314 + update_stmt(assign);
115315 + set_stmt_flag(assign, MY_STMT);
115316 + return assign;
115317 +}
115318 +
115319 +static tree cast_a_tree(tree type, tree var)
115320 +{
115321 + gcc_assert(type != NULL_TREE);
115322 + gcc_assert(var != NULL_TREE);
115323 + gcc_assert(fold_convertible_p(type, var));
115324 +
115325 + return fold_convert(type, var);
115326 +}
115327 +
115328 +static tree get_lhs(const_gimple stmt)
115329 +{
115330 + switch (gimple_code(stmt)) {
115331 + case GIMPLE_ASSIGN:
115332 + case GIMPLE_CALL:
115333 + return gimple_get_lhs(stmt);
115334 + case GIMPLE_PHI:
115335 + return gimple_phi_result(stmt);
115336 + default:
115337 + return NULL_TREE;
115338 + }
115339 +}
115340 +
115341 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
115342 +{
115343 + const_gimple def_stmt = get_def_stmt(rhs);
115344 +
115345 + if (force)
115346 + return false;
115347 +
115348 + if (is_gimple_constant(rhs))
115349 + return false;
115350 +
115351 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115352 + return false;
115353 +
115354 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
115355 + return false;
115356 +
115357 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
115358 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
115359 + return false;
115360 +
115361 + return true;
115362 +}
115363 +
115364 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
115365 +{
115366 + gimple assign, def_stmt;
115367 +
115368 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
115369 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
115370 + gcc_unreachable();
115371 +
115372 + def_stmt = get_def_stmt(rhs);
115373 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && get_stmt_flag(def_stmt) == MY_STMT)
115374 + return def_stmt;
115375 +
115376 + if (lhs == CREATE_NEW_VAR)
115377 + lhs = create_new_var(dst_type);
115378 +
115379 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
115380 +
115381 + if (!gsi_end_p(*gsi)) {
115382 + location_t loc = gimple_location(gsi_stmt(*gsi));
115383 + gimple_set_location(assign, loc);
115384 + }
115385 +
115386 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115387 +
115388 + if (before)
115389 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
115390 + else
115391 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
115392 + update_stmt(assign);
115393 + return assign;
115394 +}
115395 +
115396 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
115397 +{
115398 + gimple_stmt_iterator gsi;
115399 + tree lhs;
115400 + gimple new_stmt;
115401 +
115402 + if (rhs == NULL_TREE)
115403 + return NULL_TREE;
115404 +
115405 + gsi = gsi_for_stmt(stmt);
115406 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115407 + set_stmt_flag(new_stmt, MY_STMT);
115408 +
115409 + lhs = get_lhs(new_stmt);
115410 + gcc_assert(lhs != NULL_TREE);
115411 + return lhs;
115412 +}
115413 +
115414 +static tree cast_to_TI_type(gimple stmt, tree node)
115415 +{
115416 + gimple_stmt_iterator gsi;
115417 + gimple cast_stmt;
115418 + tree type = TREE_TYPE(node);
115419 +
115420 + if (types_compatible_p(type, intTI_type_node))
115421 + return node;
115422 +
115423 + gsi = gsi_for_stmt(stmt);
115424 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115425 + set_stmt_flag(cast_stmt, MY_STMT);
115426 + return gimple_assign_lhs(cast_stmt);
115427 +}
115428 +
115429 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
115430 +{
115431 + tree lhs, new_lhs;
115432 + gimple_stmt_iterator gsi;
115433 +
115434 + if (rhs1 == NULL_TREE) {
115435 + debug_gimple_stmt(oldstmt);
115436 + error("%s: rhs1 is NULL_TREE", __func__);
115437 + gcc_unreachable();
115438 + }
115439 +
115440 + switch (gimple_code(oldstmt)) {
115441 + case GIMPLE_ASM:
115442 + lhs = rhs1;
115443 + break;
115444 + case GIMPLE_CALL:
115445 + case GIMPLE_ASSIGN:
115446 + lhs = gimple_get_lhs(oldstmt);
115447 + break;
115448 + default:
115449 + debug_gimple_stmt(oldstmt);
115450 + gcc_unreachable();
115451 + }
115452 +
115453 + gsi = gsi_for_stmt(oldstmt);
115454 + pointer_set_insert(visited, oldstmt);
115455 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115456 + basic_block next_bb, cur_bb;
115457 + const_edge e;
115458 +
115459 + gcc_assert(before == false);
115460 + gcc_assert(stmt_can_throw_internal(oldstmt));
115461 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115462 + gcc_assert(!gsi_end_p(gsi));
115463 +
115464 + cur_bb = gimple_bb(oldstmt);
115465 + next_bb = cur_bb->next_bb;
115466 + e = find_edge(cur_bb, next_bb);
115467 + gcc_assert(e != NULL);
115468 + gcc_assert(e->flags & EDGE_FALLTHRU);
115469 +
115470 + gsi = gsi_after_labels(next_bb);
115471 + gcc_assert(!gsi_end_p(gsi));
115472 +
115473 + before = true;
115474 + oldstmt = gsi_stmt(gsi);
115475 + }
115476 +
115477 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
115478 + return new_lhs;
115479 +}
115480 +
115481 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115482 +{
115483 + gimple stmt;
115484 + gimple_stmt_iterator gsi;
115485 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115486 +
115487 + if (get_stmt_flag(oldstmt) == MY_STMT)
115488 + return lhs;
115489 +
115490 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115491 + rhs1 = gimple_assign_rhs1(oldstmt);
115492 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115493 + }
115494 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115495 + rhs2 = gimple_assign_rhs2(oldstmt);
115496 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115497 + }
115498 +
115499 + stmt = gimple_copy(oldstmt);
115500 + gimple_set_location(stmt, gimple_location(oldstmt));
115501 + set_stmt_flag(stmt, MY_STMT);
115502 +
115503 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115504 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115505 +
115506 + size_overflow_type = get_size_overflow_type(oldstmt, node);
115507 +
115508 + new_var = create_new_var(size_overflow_type);
115509 + new_var = make_ssa_name(new_var, stmt);
115510 + gimple_assign_set_lhs(stmt, new_var);
115511 +
115512 + if (rhs1 != NULL_TREE)
115513 + gimple_assign_set_rhs1(stmt, rhs1);
115514 +
115515 + if (rhs2 != NULL_TREE)
115516 + gimple_assign_set_rhs2(stmt, rhs2);
115517 +#if BUILDING_GCC_VERSION >= 4006
115518 + if (rhs3 != NULL_TREE)
115519 + gimple_assign_set_rhs3(stmt, rhs3);
115520 +#endif
115521 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115522 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115523 +
115524 + gsi = gsi_for_stmt(oldstmt);
115525 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115526 + update_stmt(stmt);
115527 + pointer_set_insert(visited, oldstmt);
115528 + return gimple_assign_lhs(stmt);
115529 +}
115530 +
115531 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115532 +{
115533 + gimple assign;
115534 + gimple_stmt_iterator gsi;
115535 + basic_block first_bb;
115536 +
115537 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115538 +
115539 + if (bb->index == 0) {
115540 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115541 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115542 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115543 + bb = first_bb;
115544 + }
115545 +
115546 + gsi = gsi_after_labels(bb);
115547 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115548 + set_stmt_flag(assign, MY_STMT);
115549 +
115550 + return gimple_assign_lhs(assign);
115551 +}
115552 +
115553 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
115554 +{
115555 + gimple_stmt_iterator gsi;
115556 + gimple assign, def_stmt = get_def_stmt(new_arg);
115557 +
115558 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115559 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115560 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115561 + } else {
115562 + gsi = gsi_for_stmt(def_stmt);
115563 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115564 + }
115565 +
115566 + set_stmt_flag(assign, MY_STMT);
115567 + return gimple_assign_lhs(assign);
115568 +}
115569 +
115570 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
115571 +{
115572 + basic_block bb;
115573 + gimple_stmt_iterator gsi;
115574 + const_gimple def_stmt;
115575 + gimple assign;
115576 +
115577 + def_stmt = get_def_stmt(arg);
115578 + bb = gimple_bb(def_stmt);
115579 + gcc_assert(bb->index != 0);
115580 + gsi = gsi_after_labels(bb);
115581 +
115582 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115583 + set_stmt_flag(assign, MY_STMT);
115584 + return gimple_assign_lhs(assign);
115585 +}
115586 +
115587 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115588 +{
115589 + tree size_overflow_type;
115590 + tree arg;
115591 + const_gimple def_stmt;
115592 +
115593 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115594 + return new_arg;
115595 +
115596 + arg = gimple_phi_arg_def(oldstmt, i);
115597 + def_stmt = get_def_stmt(arg);
115598 + gcc_assert(def_stmt != NULL);
115599 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
115600 +
115601 + switch (gimple_code(def_stmt)) {
115602 + case GIMPLE_PHI:
115603 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
115604 + case GIMPLE_NOP: {
115605 + basic_block bb;
115606 +
115607 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115608 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
115609 + }
115610 + case GIMPLE_ASM: {
115611 + gimple_stmt_iterator gsi;
115612 + gimple assign, stmt = get_def_stmt(arg);
115613 +
115614 + gsi = gsi_for_stmt(stmt);
115615 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115616 + set_stmt_flag(assign, MY_STMT);
115617 + return gimple_assign_lhs(assign);
115618 + }
115619 + default:
115620 + gcc_assert(new_arg != NULL_TREE);
115621 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115622 + return use_phi_ssa_name(ssa_name_var, new_arg);
115623 + }
115624 +}
115625 +
115626 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
115627 +{
115628 + basic_block bb;
115629 + gimple phi;
115630 + gimple_seq seq;
115631 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115632 +
115633 + bb = gsi_bb(gsi);
115634 +
115635 + if (result == NULL_TREE) {
115636 + tree old_result = gimple_phi_result(oldstmt);
115637 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
115638 +
115639 + result = create_new_var(size_overflow_type);
115640 + }
115641 +
115642 + phi = create_phi_node(result, bb);
115643 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115644 + seq = phi_nodes(bb);
115645 + gsi = gsi_last(seq);
115646 + gsi_remove(&gsi, false);
115647 +
115648 + gsi = gsi_for_stmt(oldstmt);
115649 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115650 + gimple_set_bb(phi, bb);
115651 + set_stmt_flag(phi, MY_STMT);
115652 + return phi;
115653 +}
115654 +
115655 +#if BUILDING_GCC_VERSION <= 4007
115656 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115657 +#else
115658 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115659 +#endif
115660 +{
115661 + gimple new_phi;
115662 + unsigned int i;
115663 + tree arg, result;
115664 + location_t loc = gimple_location(oldstmt);
115665 +
115666 +#if BUILDING_GCC_VERSION <= 4007
115667 + gcc_assert(!VEC_empty(tree, *args));
115668 +#else
115669 + gcc_assert(!args->is_empty());
115670 +#endif
115671 +
115672 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
115673 + result = gimple_phi_result(new_phi);
115674 + ssa_name_var = SSA_NAME_VAR(result);
115675 +
115676 +#if BUILDING_GCC_VERSION <= 4007
115677 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115678 +#else
115679 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115680 +#endif
115681 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
115682 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115683 + }
115684 +
115685 +#if BUILDING_GCC_VERSION <= 4007
115686 + VEC_free(tree, heap, *args);
115687 +#else
115688 + vec_free(args);
115689 +#endif
115690 + update_stmt(new_phi);
115691 + return result;
115692 +}
115693 +
115694 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
115695 +{
115696 + tree ssa_name_var = NULL_TREE;
115697 +#if BUILDING_GCC_VERSION <= 4007
115698 + VEC(tree, heap) *args = NULL;
115699 +#else
115700 + vec<tree, va_heap, vl_embed> *args = NULL;
115701 +#endif
115702 + gimple oldstmt = get_def_stmt(orig_result);
115703 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115704 +
115705 + pointer_set_insert(visited, oldstmt);
115706 + for (i = 0; i < len; i++) {
115707 + tree arg, new_arg;
115708 +
115709 + arg = gimple_phi_arg_def(oldstmt, i);
115710 + new_arg = expand(visited, caller_node, arg);
115711 +
115712 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115713 + ssa_name_var = SSA_NAME_VAR(new_arg);
115714 +
115715 + if (is_gimple_constant(arg)) {
115716 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
115717 +
115718 + new_arg = cast_a_tree(size_overflow_type, arg);
115719 + }
115720 +
115721 +#if BUILDING_GCC_VERSION <= 4007
115722 + VEC_safe_push(tree, heap, args, new_arg);
115723 +#else
115724 + vec_safe_push(args, new_arg);
115725 +#endif
115726 + }
115727 +
115728 +#if BUILDING_GCC_VERSION <= 4007
115729 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
115730 +#else
115731 + return create_new_phi_node(args, ssa_name_var, oldstmt);
115732 +#endif
115733 +}
115734 +
115735 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
115736 +{
115737 + gimple assign;
115738 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115739 + tree origtype = TREE_TYPE(orig_rhs);
115740 +
115741 + gcc_assert(is_gimple_assign(stmt));
115742 +
115743 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115744 + set_stmt_flag(assign, MY_STMT);
115745 + return gimple_assign_lhs(assign);
115746 +}
115747 +
115748 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
115749 +{
115750 + const_tree rhs1, lhs, rhs1_type, lhs_type;
115751 + enum machine_mode lhs_mode, rhs_mode;
115752 + gimple def_stmt = get_def_stmt(no_const_rhs);
115753 +
115754 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115755 + return false;
115756 +
115757 + rhs1 = gimple_assign_rhs1(def_stmt);
115758 + lhs = gimple_assign_lhs(def_stmt);
115759 + rhs1_type = TREE_TYPE(rhs1);
115760 + lhs_type = TREE_TYPE(lhs);
115761 + rhs_mode = TYPE_MODE(rhs1_type);
115762 + lhs_mode = TYPE_MODE(lhs_type);
115763 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
115764 + return false;
115765 +
115766 + return true;
115767 +}
115768 +
115769 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
115770 +{
115771 + tree rhs1 = gimple_assign_rhs1(stmt);
115772 + tree lhs = gimple_assign_lhs(stmt);
115773 + const_tree rhs1_type = TREE_TYPE(rhs1);
115774 + const_tree lhs_type = TREE_TYPE(lhs);
115775 +
115776 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115777 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115778 +
115779 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115780 +}
115781 +
115782 +static bool no_uses(tree node)
115783 +{
115784 + imm_use_iterator imm_iter;
115785 + use_operand_p use_p;
115786 +
115787 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115788 + const_gimple use_stmt = USE_STMT(use_p);
115789 +
115790 + if (use_stmt == NULL)
115791 + return true;
115792 + if (is_gimple_debug(use_stmt))
115793 + continue;
115794 + return false;
115795 + }
115796 + return true;
115797 +}
115798 +
115799 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
115800 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
115801 +{
115802 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
115803 + gimple def_stmt = get_def_stmt(lhs);
115804 +
115805 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115806 + return false;
115807 +
115808 + rhs1 = gimple_assign_rhs1(def_stmt);
115809 + rhs_type = TREE_TYPE(rhs1);
115810 + lhs_type = TREE_TYPE(lhs);
115811 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
115812 + return false;
115813 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
115814 + return false;
115815 +
115816 + def_stmt = get_def_stmt(rhs1);
115817 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
115818 + return false;
115819 +
115820 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
115821 + return false;
115822 +
115823 + rhs1 = gimple_assign_rhs1(def_stmt);
115824 + rhs2 = gimple_assign_rhs2(def_stmt);
115825 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
115826 + return false;
115827 +
115828 + if (is_gimple_constant(rhs2))
115829 + not_const_rhs = rhs1;
115830 + else
115831 + not_const_rhs = rhs2;
115832 +
115833 + return no_uses(not_const_rhs);
115834 +}
115835 +
115836 +static bool skip_lhs_cast_check(const_gimple stmt)
115837 +{
115838 + const_tree rhs = gimple_assign_rhs1(stmt);
115839 + const_gimple def_stmt = get_def_stmt(rhs);
115840 +
115841 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115842 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115843 + return true;
115844 +
115845 + if (is_const_plus_unsigned_signed_truncation(rhs))
115846 + return true;
115847 +
115848 + return false;
115849 +}
115850 +
115851 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115852 +{
115853 + bool cast_lhs, cast_rhs;
115854 + tree lhs = gimple_assign_lhs(stmt);
115855 + tree rhs = gimple_assign_rhs1(stmt);
115856 + const_tree lhs_type = TREE_TYPE(lhs);
115857 + const_tree rhs_type = TREE_TYPE(rhs);
115858 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115859 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115860 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115861 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115862 +
115863 + static bool check_lhs[3][4] = {
115864 + // ss su us uu
115865 + { false, true, true, false }, // lhs > rhs
115866 + { false, false, false, false }, // lhs = rhs
115867 + { true, true, true, true }, // lhs < rhs
115868 + };
115869 +
115870 + static bool check_rhs[3][4] = {
115871 + // ss su us uu
115872 + { true, false, true, true }, // lhs > rhs
115873 + { true, false, true, true }, // lhs = rhs
115874 + { true, false, true, true }, // lhs < rhs
115875 + };
115876 +
115877 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115878 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115879 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115880 +
115881 + if (lhs_size > rhs_size) {
115882 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115883 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115884 + } else if (lhs_size == rhs_size) {
115885 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115886 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115887 + } else {
115888 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115889 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115890 + }
115891 +
115892 + if (!cast_lhs && !cast_rhs)
115893 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115894 +
115895 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115896 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115897 +
115898 + if (cast_rhs)
115899 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115900 +
115901 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115902 +}
115903 +
115904 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115905 +{
115906 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115907 +
115908 + if (get_stmt_flag(stmt) == MY_STMT)
115909 + return lhs;
115910 +
115911 + rhs1 = gimple_assign_rhs1(stmt);
115912 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115913 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115914 +
115915 + new_rhs1 = expand(visited, caller_node, rhs1);
115916 +
115917 + if (new_rhs1 == NULL_TREE)
115918 + return create_cast_assign(visited, stmt);
115919 +
115920 + if (get_stmt_flag(stmt) == NO_CAST_CHECK)
115921 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115922 +
115923 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
115924 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
115925 +
115926 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115927 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115928 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115929 + }
115930 +
115931 + if (!gimple_assign_cast_p(stmt))
115932 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115933 +
115934 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115935 +}
115936 +
115937 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115938 +{
115939 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115940 + gimple def_stmt = get_def_stmt(lhs);
115941 +
115942 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115943 + rhs1 = gimple_assign_rhs1(def_stmt);
115944 +
115945 + if (is_gimple_constant(rhs1))
115946 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115947 +
115948 + switch (TREE_CODE(rhs1)) {
115949 + case SSA_NAME:
115950 + return handle_unary_rhs(visited, caller_node, def_stmt);
115951 + case ARRAY_REF:
115952 + case BIT_FIELD_REF:
115953 + case ADDR_EXPR:
115954 + case COMPONENT_REF:
115955 + case INDIRECT_REF:
115956 +#if BUILDING_GCC_VERSION >= 4006
115957 + case MEM_REF:
115958 +#endif
115959 + case TARGET_MEM_REF:
115960 + case VIEW_CONVERT_EXPR:
115961 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115962 + case PARM_DECL:
115963 + case VAR_DECL:
115964 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115965 +
115966 + default:
115967 + debug_gimple_stmt(def_stmt);
115968 + debug_tree(rhs1);
115969 + gcc_unreachable();
115970 + }
115971 +}
115972 +
115973 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115974 +{
115975 + gimple cond_stmt;
115976 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115977 +
115978 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115979 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115980 + update_stmt(cond_stmt);
115981 +}
115982 +
115983 +static tree create_string_param(tree string)
115984 +{
115985 + tree i_type, a_type;
115986 + const int length = TREE_STRING_LENGTH(string);
115987 +
115988 + gcc_assert(length > 0);
115989 +
115990 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115991 + a_type = build_array_type(char_type_node, i_type);
115992 +
115993 + TREE_TYPE(string) = a_type;
115994 + TREE_CONSTANT(string) = 1;
115995 + TREE_READONLY(string) = 1;
115996 +
115997 + return build1(ADDR_EXPR, ptr_type_node, string);
115998 +}
115999 +
116000 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
116001 +{
116002 + gimple func_stmt;
116003 + const_gimple def_stmt;
116004 + const_tree loc_line;
116005 + tree loc_file, ssa_name, current_func;
116006 + expanded_location xloc;
116007 + char *ssa_name_buf;
116008 + int len;
116009 + struct cgraph_edge *edge;
116010 + struct cgraph_node *callee_node;
116011 + int frequency;
116012 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
116013 +
116014 + def_stmt = get_def_stmt(arg);
116015 + xloc = expand_location(gimple_location(def_stmt));
116016 +
116017 + if (!gimple_has_location(def_stmt)) {
116018 + xloc = expand_location(gimple_location(stmt));
116019 + if (!gimple_has_location(stmt))
116020 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
116021 + }
116022 +
116023 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
116024 +
116025 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
116026 + loc_file = create_string_param(loc_file);
116027 +
116028 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
116029 + current_func = create_string_param(current_func);
116030 +
116031 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
116032 + call_count++;
116033 + 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);
116034 + gcc_assert(len > 0);
116035 + ssa_name = build_string(len + 1, ssa_name_buf);
116036 + free(ssa_name_buf);
116037 + ssa_name = create_string_param(ssa_name);
116038 +
116039 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
116040 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
116041 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
116042 +
116043 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
116044 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
116045 +
116046 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
116047 + gcc_assert(edge != NULL);
116048 +}
116049 +
116050 +static void __unused print_the_code_insertions(const_gimple stmt)
116051 +{
116052 + location_t loc = gimple_location(stmt);
116053 +
116054 + inform(loc, "Integer size_overflow check applied here.");
116055 +}
116056 +
116057 +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)
116058 +{
116059 + basic_block cond_bb, join_bb, bb_true;
116060 + edge e;
116061 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116062 +
116063 + cond_bb = gimple_bb(stmt);
116064 + if (before)
116065 + gsi_prev(&gsi);
116066 + if (gsi_end_p(gsi))
116067 + e = split_block_after_labels(cond_bb);
116068 + else
116069 + e = split_block(cond_bb, gsi_stmt(gsi));
116070 + cond_bb = e->src;
116071 + join_bb = e->dest;
116072 + e->flags = EDGE_FALSE_VALUE;
116073 + e->probability = REG_BR_PROB_BASE;
116074 +
116075 + bb_true = create_empty_bb(cond_bb);
116076 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
116077 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
116078 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
116079 +
116080 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
116081 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
116082 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
116083 +
116084 + if (current_loops != NULL) {
116085 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
116086 + add_bb_to_loop(bb_true, cond_bb->loop_father);
116087 + }
116088 +
116089 + insert_cond(cond_bb, arg, cond_code, type_value);
116090 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
116091 +
116092 +// print_the_code_insertions(stmt);
116093 +}
116094 +
116095 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
116096 +{
116097 + const_tree rhs_type = TREE_TYPE(rhs);
116098 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
116099 +
116100 + gcc_assert(rhs_type != NULL_TREE);
116101 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
116102 + return;
116103 +
116104 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
116105 +
116106 + if (is_const_plus_unsigned_signed_truncation(rhs))
116107 + return;
116108 +
116109 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
116110 + // typemax (-1) < typemin (0)
116111 + if (TREE_OVERFLOW(type_max))
116112 + return;
116113 +
116114 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
116115 +
116116 + cast_rhs_type = TREE_TYPE(cast_rhs);
116117 + type_max_type = TREE_TYPE(type_max);
116118 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
116119 +
116120 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
116121 +
116122 + // special case: get_size_overflow_type(), 32, u64->s
116123 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
116124 + return;
116125 +
116126 + type_min_type = TREE_TYPE(type_min);
116127 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
116128 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
116129 +}
116130 +
116131 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
116132 +{
116133 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
116134 + return false;
116135 + if (!is_gimple_constant(rhs))
116136 + return false;
116137 + return true;
116138 +}
116139 +
116140 +static tree get_def_stmt_rhs(const_tree var)
116141 +{
116142 + tree rhs1, def_stmt_rhs1;
116143 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
116144 +
116145 + def_stmt = get_def_stmt(var);
116146 + if (!gimple_assign_cast_p(def_stmt))
116147 + return NULL_TREE;
116148 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && get_stmt_flag(def_stmt) == MY_STMT && gimple_assign_cast_p(def_stmt));
116149 +
116150 + rhs1 = gimple_assign_rhs1(def_stmt);
116151 + rhs1_def_stmt = get_def_stmt(rhs1);
116152 + if (!gimple_assign_cast_p(rhs1_def_stmt))
116153 + return rhs1;
116154 +
116155 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116156 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
116157 +
116158 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
116159 + case GIMPLE_CALL:
116160 + case GIMPLE_NOP:
116161 + case GIMPLE_ASM:
116162 + case GIMPLE_PHI:
116163 + return def_stmt_rhs1;
116164 + case GIMPLE_ASSIGN:
116165 + return rhs1;
116166 + default:
116167 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
116168 + gcc_unreachable();
116169 + }
116170 +}
116171 +
116172 +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)
116173 +{
116174 + tree new_rhs, orig_rhs;
116175 + void (*gimple_assign_set_rhs)(gimple, tree);
116176 + tree rhs1 = gimple_assign_rhs1(stmt);
116177 + tree rhs2 = gimple_assign_rhs2(stmt);
116178 + tree lhs = gimple_assign_lhs(stmt);
116179 +
116180 + if (!check_overflow)
116181 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116182 +
116183 + if (change_rhs == NULL_TREE)
116184 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116185 +
116186 + if (new_rhs2 == NULL_TREE) {
116187 + orig_rhs = rhs1;
116188 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
116189 + } else {
116190 + orig_rhs = rhs2;
116191 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
116192 + }
116193 +
116194 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
116195 +
116196 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
116197 + gimple_assign_set_rhs(stmt, new_rhs);
116198 + update_stmt(stmt);
116199 +
116200 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116201 +}
116202 +
116203 +static bool is_subtraction_special(const_gimple stmt)
116204 +{
116205 + gimple rhs1_def_stmt, rhs2_def_stmt;
116206 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
116207 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
116208 + const_tree rhs1 = gimple_assign_rhs1(stmt);
116209 + const_tree rhs2 = gimple_assign_rhs2(stmt);
116210 +
116211 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
116212 + return false;
116213 +
116214 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
116215 +
116216 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116217 + return false;
116218 +
116219 + rhs1_def_stmt = get_def_stmt(rhs1);
116220 + rhs2_def_stmt = get_def_stmt(rhs2);
116221 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
116222 + return false;
116223 +
116224 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116225 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
116226 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
116227 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
116228 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
116229 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
116230 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
116231 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
116232 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
116233 + return false;
116234 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
116235 + return false;
116236 +
116237 + set_stmt_flag(rhs1_def_stmt, NO_CAST_CHECK);
116238 + set_stmt_flag(rhs2_def_stmt, NO_CAST_CHECK);
116239 + return true;
116240 +}
116241 +
116242 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
116243 +{
116244 + tree new_rhs1, new_rhs2;
116245 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
116246 + gimple assign, stmt = get_def_stmt(lhs);
116247 + tree rhs1 = gimple_assign_rhs1(stmt);
116248 + tree rhs2 = gimple_assign_rhs2(stmt);
116249 +
116250 + if (!is_subtraction_special(stmt))
116251 + return NULL_TREE;
116252 +
116253 + new_rhs1 = expand(visited, caller_node, rhs1);
116254 + new_rhs2 = expand(visited, caller_node, rhs2);
116255 +
116256 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
116257 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
116258 +
116259 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
116260 + return NULL_TREE;
116261 +
116262 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
116263 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
116264 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
116265 + }
116266 +
116267 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
116268 + new_lhs = gimple_assign_lhs(assign);
116269 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
116270 +
116271 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116272 +}
116273 +
116274 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
116275 +{
116276 + const_gimple def_stmt;
116277 +
116278 + if (TREE_CODE(rhs) != SSA_NAME)
116279 + return false;
116280 +
116281 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
116282 + return false;
116283 +
116284 + def_stmt = get_def_stmt(rhs);
116285 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
116286 + return false;
116287 +
116288 + return true;
116289 +}
116290 +
116291 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116292 +{
116293 + tree rhs1, rhs2, new_lhs;
116294 + gimple def_stmt = get_def_stmt(lhs);
116295 + tree new_rhs1 = NULL_TREE;
116296 + tree new_rhs2 = NULL_TREE;
116297 +
116298 + rhs1 = gimple_assign_rhs1(def_stmt);
116299 + rhs2 = gimple_assign_rhs2(def_stmt);
116300 +
116301 + /* no DImode/TImode division in the 32/64 bit kernel */
116302 + switch (gimple_assign_rhs_code(def_stmt)) {
116303 + case RDIV_EXPR:
116304 + case TRUNC_DIV_EXPR:
116305 + case CEIL_DIV_EXPR:
116306 + case FLOOR_DIV_EXPR:
116307 + case ROUND_DIV_EXPR:
116308 + case TRUNC_MOD_EXPR:
116309 + case CEIL_MOD_EXPR:
116310 + case FLOOR_MOD_EXPR:
116311 + case ROUND_MOD_EXPR:
116312 + case EXACT_DIV_EXPR:
116313 + case POINTER_PLUS_EXPR:
116314 + case BIT_AND_EXPR:
116315 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116316 + default:
116317 + break;
116318 + }
116319 +
116320 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
116321 + if (new_lhs != NULL_TREE)
116322 + return new_lhs;
116323 +
116324 + if (TREE_CODE(rhs1) == SSA_NAME)
116325 + new_rhs1 = expand(visited, caller_node, rhs1);
116326 + if (TREE_CODE(rhs2) == SSA_NAME)
116327 + new_rhs2 = expand(visited, caller_node, rhs2);
116328 +
116329 + if (is_a_neg_overflow(def_stmt, rhs2))
116330 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
116331 + if (is_a_neg_overflow(def_stmt, rhs1))
116332 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
116333 +
116334 +
116335 + if (is_a_constant_overflow(def_stmt, rhs2))
116336 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
116337 + if (is_a_constant_overflow(def_stmt, rhs1))
116338 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
116339 +
116340 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116341 +}
116342 +
116343 +#if BUILDING_GCC_VERSION >= 4006
116344 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
116345 +{
116346 + if (is_gimple_constant(rhs))
116347 + return cast_a_tree(size_overflow_type, rhs);
116348 + if (TREE_CODE(rhs) != SSA_NAME)
116349 + return NULL_TREE;
116350 + return expand(visited, caller_node, rhs);
116351 +}
116352 +
116353 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116354 +{
116355 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
116356 + gimple def_stmt = get_def_stmt(lhs);
116357 +
116358 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
116359 +
116360 + rhs1 = gimple_assign_rhs1(def_stmt);
116361 + rhs2 = gimple_assign_rhs2(def_stmt);
116362 + rhs3 = gimple_assign_rhs3(def_stmt);
116363 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
116364 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
116365 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
116366 +
116367 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
116368 +}
116369 +#endif
116370 +
116371 +static tree get_size_overflow_type(gimple stmt, const_tree node)
116372 +{
116373 + const_tree type;
116374 + tree new_type;
116375 +
116376 + gcc_assert(node != NULL_TREE);
116377 +
116378 + type = TREE_TYPE(node);
116379 +
116380 + if (get_stmt_flag(stmt) == MY_STMT)
116381 + return TREE_TYPE(node);
116382 +
116383 + switch (TYPE_MODE(type)) {
116384 + case QImode:
116385 + new_type = intHI_type_node;
116386 + break;
116387 + case HImode:
116388 + new_type = intSI_type_node;
116389 + break;
116390 + case SImode:
116391 + new_type = intDI_type_node;
116392 + break;
116393 + case DImode:
116394 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
116395 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
116396 + else
116397 + new_type = intTI_type_node;
116398 + break;
116399 + case TImode:
116400 + gcc_assert(!TYPE_UNSIGNED(type));
116401 + new_type = intTI_type_node;
116402 + break;
116403 + default:
116404 + debug_tree((tree)node);
116405 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
116406 + gcc_unreachable();
116407 + }
116408 +
116409 + if (TYPE_QUALS(type) != 0)
116410 + return build_qualified_type(new_type, TYPE_QUALS(type));
116411 + return new_type;
116412 +}
116413 +
116414 +static tree expand_visited(gimple def_stmt)
116415 +{
116416 + const_gimple next_stmt;
116417 + gimple_stmt_iterator gsi;
116418 + enum gimple_code code = gimple_code(def_stmt);
116419 +
116420 + if (code == GIMPLE_ASM)
116421 + return NULL_TREE;
116422 +
116423 + gsi = gsi_for_stmt(def_stmt);
116424 + gsi_next(&gsi);
116425 +
116426 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
116427 + return NULL_TREE;
116428 + gcc_assert(!gsi_end_p(gsi));
116429 + next_stmt = gsi_stmt(gsi);
116430 +
116431 + if (gimple_code(def_stmt) == GIMPLE_PHI && get_stmt_flag((gimple)next_stmt) != MY_STMT)
116432 + return NULL_TREE;
116433 + gcc_assert(get_stmt_flag((gimple)next_stmt) == MY_STMT);
116434 +
116435 + return get_lhs(next_stmt);
116436 +}
116437 +
116438 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116439 +{
116440 + gimple def_stmt;
116441 +
116442 + def_stmt = get_def_stmt(lhs);
116443 +
116444 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
116445 + return NULL_TREE;
116446 +
116447 + if (get_stmt_flag(def_stmt) == MY_STMT)
116448 + return lhs;
116449 +
116450 + if (pointer_set_contains(visited, def_stmt))
116451 + return expand_visited(def_stmt);
116452 +
116453 + switch (gimple_code(def_stmt)) {
116454 + case GIMPLE_PHI:
116455 + return handle_phi(visited, caller_node, lhs);
116456 + case GIMPLE_CALL:
116457 + case GIMPLE_ASM:
116458 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116459 + case GIMPLE_ASSIGN:
116460 + switch (gimple_num_ops(def_stmt)) {
116461 + case 2:
116462 + return handle_unary_ops(visited, caller_node, def_stmt);
116463 + case 3:
116464 + return handle_binary_ops(visited, caller_node, lhs);
116465 +#if BUILDING_GCC_VERSION >= 4006
116466 + case 4:
116467 + return handle_ternary_ops(visited, caller_node, lhs);
116468 +#endif
116469 + }
116470 + default:
116471 + debug_gimple_stmt(def_stmt);
116472 + error("%s: unknown gimple code", __func__);
116473 + gcc_unreachable();
116474 + }
116475 +}
116476 +
116477 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
116478 +{
116479 + const_gimple assign;
116480 + tree orig_type = TREE_TYPE(orig_node);
116481 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116482 +
116483 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116484 + return gimple_assign_lhs(assign);
116485 +}
116486 +
116487 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
116488 +{
116489 + void (*set_rhs)(gimple, tree);
116490 + gimple stmt = cur_node->first_stmt;
116491 + const_tree orig_node = cur_node->node;
116492 +
116493 + switch (gimple_code(stmt)) {
116494 + case GIMPLE_RETURN:
116495 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116496 + break;
116497 + case GIMPLE_CALL:
116498 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
116499 + break;
116500 + case GIMPLE_ASSIGN:
116501 + switch (cur_node->num) {
116502 + case 1:
116503 + set_rhs = &gimple_assign_set_rhs1;
116504 + break;
116505 + case 2:
116506 + set_rhs = &gimple_assign_set_rhs2;
116507 + break;
116508 +#if BUILDING_GCC_VERSION >= 4006
116509 + case 3:
116510 + set_rhs = &gimple_assign_set_rhs3;
116511 + break;
116512 +#endif
116513 + default:
116514 + gcc_unreachable();
116515 + }
116516 +
116517 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116518 + break;
116519 + default:
116520 + debug_gimple_stmt(stmt);
116521 + gcc_unreachable();
116522 + }
116523 +
116524 + update_stmt(stmt);
116525 +}
116526 +
116527 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
116528 +{
116529 + const struct size_overflow_hash *hash;
116530 + unsigned int new_argnum;
116531 + tree arg;
116532 + const_tree origarg;
116533 +
116534 + if (argnum == 0)
116535 + return argnum;
116536 +
116537 + hash = get_function_hash(fndecl);
116538 + if (hash && hash->param & (1U << argnum))
116539 + return argnum;
116540 +
116541 + if (DECL_EXTERNAL(fndecl))
116542 + return argnum;
116543 +
116544 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
116545 + argnum--;
116546 + while (origarg && argnum) {
116547 + origarg = TREE_CHAIN(origarg);
116548 + argnum--;
116549 + }
116550 + gcc_assert(argnum == 0);
116551 + gcc_assert(origarg != NULL_TREE);
116552 +
116553 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
116554 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
116555 + return new_argnum;
116556 +
116557 + return CANNOT_FIND_ARG;
116558 +}
116559 +
116560 +// Don't want to duplicate entries in next_cgraph_node
116561 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
116562 +{
116563 + const_tree new_callee_fndecl;
116564 + struct next_cgraph_node *cur_node;
116565 +
116566 + if (fndecl == RET_CHECK)
116567 + new_callee_fndecl = NODE_DECL(node);
116568 + else
116569 + new_callee_fndecl = fndecl;
116570 +
116571 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116572 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
116573 + continue;
116574 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
116575 + continue;
116576 + if (num == cur_node->num)
116577 + return true;
116578 + }
116579 + return false;
116580 +}
116581 +
116582 +/* Add a next_cgraph_node into the list for handle_function().
116583 + * handle_function() iterates over all the next cgraph nodes and
116584 + * starts the overflow check insertion process.
116585 + */
116586 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
116587 +{
116588 + struct next_cgraph_node *new_node;
116589 +
116590 + if (is_in_next_cgraph_node(head, node, fndecl, num))
116591 + return head;
116592 +
116593 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
116594 + new_node->current_function = node;
116595 + new_node->next = NULL;
116596 + new_node->num = num;
116597 + if (fndecl == RET_CHECK)
116598 + new_node->callee_fndecl = NODE_DECL(node);
116599 + else
116600 + new_node->callee_fndecl = fndecl;
116601 +
116602 + if (!head)
116603 + return new_node;
116604 +
116605 + new_node->next = head;
116606 + return new_node;
116607 +}
116608 +
116609 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
116610 +{
116611 + struct cgraph_edge *e;
116612 +
116613 + if (num == 0)
116614 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
116615 +
116616 + for (e = node->callers; e; e = e->next_caller) {
116617 + tree fndecl = gimple_call_fndecl(e->call_stmt);
116618 +
116619 + gcc_assert(fndecl != NULL_TREE);
116620 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
116621 + }
116622 +
116623 + return head;
116624 +}
116625 +
116626 +static bool is_a_return_check(const_tree node)
116627 +{
116628 + if (TREE_CODE(node) == FUNCTION_DECL)
116629 + return true;
116630 +
116631 + gcc_assert(TREE_CODE(node) == PARM_DECL);
116632 + return false;
116633 +}
116634 +
116635 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
116636 +{
116637 + const struct size_overflow_hash *hash;
116638 +
116639 + hash = get_function_hash(fndecl);
116640 + if (hash && (hash->param & (1U << num)))
116641 + return true;
116642 + return false;
116643 +}
116644 +
116645 +struct missing_functions {
116646 + struct missing_functions *next;
116647 + const_tree node;
116648 + tree fndecl;
116649 +};
116650 +
116651 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
116652 +{
116653 + struct missing_functions *new_function;
116654 +
116655 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
116656 + new_function->node = node;
116657 + new_function->next = NULL;
116658 +
116659 + if (TREE_CODE(node) == FUNCTION_DECL)
116660 + new_function->fndecl = node;
116661 + else
116662 + new_function->fndecl = current_function_decl;
116663 + gcc_assert(new_function->fndecl);
116664 +
116665 + if (!missing_fn_head)
116666 + return new_function;
116667 +
116668 + new_function->next = missing_fn_head;
116669 + return new_function;
116670 +}
116671 +
116672 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
116673 + * If the function is missing everywhere then print the missing message into stderr.
116674 + */
116675 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
116676 +{
116677 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
116678 +#if BUILDING_GCC_VERSION >= 4008
116679 + case BUILT_IN_BSWAP16:
116680 +#endif
116681 + case BUILT_IN_BSWAP32:
116682 + case BUILT_IN_BSWAP64:
116683 + case BUILT_IN_EXPECT:
116684 + case BUILT_IN_MEMCMP:
116685 + return false;
116686 + default:
116687 + break;
116688 + }
116689 +
116690 + // skip test.c
116691 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
116692 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
116693 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
116694 + }
116695 +
116696 + if (is_in_hash_table(orig_fndecl, num))
116697 + return false;
116698 +
116699 + print_missing_msg(orig_fndecl, num);
116700 + return true;
116701 +}
116702 +
116703 +// Get the argnum of a function decl, if node is a return then the argnum is 0
116704 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
116705 +{
116706 + if (is_a_return_check(node))
116707 + return 0;
116708 + else
116709 + return find_arg_number_tree(node, orig_fndecl);
116710 +}
116711 +
116712 +/* If the function is missing from the hash table and it is a static function
116713 + * then create a next_cgraph_node from it for handle_function()
116714 + */
116715 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116716 +{
116717 + unsigned int num;
116718 + const_tree orig_fndecl;
116719 + struct cgraph_node *next_node = NULL;
116720 +
116721 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116722 +
116723 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116724 + if (num == CANNOT_FIND_ARG)
116725 + return cnodes;
116726 +
116727 + if (!is_missing_function(orig_fndecl, num))
116728 + return cnodes;
116729 +
116730 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116731 + if (next_node && next_node->local.local)
116732 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116733 + return cnodes;
116734 +}
116735 +
116736 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116737 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116738 + */
116739 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116740 +{
116741 + unsigned int i;
116742 + tree node;
116743 + struct missing_functions *cur, *missing_fn_head = NULL;
116744 +
116745 +#if BUILDING_GCC_VERSION <= 4007
116746 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116747 +#else
116748 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116749 +#endif
116750 + switch (TREE_CODE(node)) {
116751 + case PARM_DECL:
116752 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116753 + break;
116754 + case FUNCTION_DECL:
116755 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116756 + break;
116757 + default:
116758 + break;
116759 + }
116760 + }
116761 +
116762 + while (missing_fn_head) {
116763 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116764 +
116765 + cur = missing_fn_head->next;
116766 + free(missing_fn_head);
116767 + missing_fn_head = cur;
116768 + }
116769 +
116770 + return cnodes;
116771 +}
116772 +
116773 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116774 +{
116775 + gimple phi = get_def_stmt(result);
116776 + unsigned int i, n = gimple_phi_num_args(phi);
116777 +
116778 + pointer_set_insert(visited, phi);
116779 + for (i = 0; i < n; i++) {
116780 + const_tree arg = gimple_phi_arg_def(phi, i);
116781 +
116782 + set_conditions(visited, interesting_conditions, arg);
116783 + }
116784 +}
116785 +
116786 +enum conditions {
116787 + FROM_CONST, NOT_UNARY, CAST
116788 +};
116789 +
116790 +// Search for constants, cast assignments and binary/ternary assignments
116791 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116792 +{
116793 + gimple def_stmt = get_def_stmt(lhs);
116794 +
116795 + if (is_gimple_constant(lhs)) {
116796 + interesting_conditions[FROM_CONST] = true;
116797 + return;
116798 + }
116799 +
116800 + if (!def_stmt)
116801 + return;
116802 +
116803 + if (pointer_set_contains(visited, def_stmt))
116804 + return;
116805 +
116806 + switch (gimple_code(def_stmt)) {
116807 + case GIMPLE_NOP:
116808 + case GIMPLE_CALL:
116809 + case GIMPLE_ASM:
116810 + return;
116811 + case GIMPLE_PHI:
116812 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116813 + case GIMPLE_ASSIGN:
116814 + if (gimple_num_ops(def_stmt) == 2) {
116815 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116816 +
116817 + if (gimple_assign_cast_p(def_stmt))
116818 + interesting_conditions[CAST] = true;
116819 +
116820 + return set_conditions(visited, interesting_conditions, rhs);
116821 + } else {
116822 + interesting_conditions[NOT_UNARY] = true;
116823 + return;
116824 + }
116825 + default:
116826 + debug_gimple_stmt(def_stmt);
116827 + gcc_unreachable();
116828 + }
116829 +}
116830 +
116831 +// determine whether duplication will be necessary or not.
116832 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116833 +{
116834 + struct pointer_set_t *visited;
116835 +
116836 + if (gimple_assign_cast_p(cur_node->first_stmt))
116837 + interesting_conditions[CAST] = true;
116838 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116839 + interesting_conditions[NOT_UNARY] = true;
116840 +
116841 + visited = pointer_set_create();
116842 + set_conditions(visited, interesting_conditions, cur_node->node);
116843 + pointer_set_destroy(visited);
116844 +}
116845 +
116846 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116847 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116848 +{
116849 + gimple assign;
116850 + gimple_stmt_iterator gsi;
116851 +
116852 + // already removed
116853 + if (gimple_bb(asm_stmt) == NULL)
116854 + return;
116855 + gsi = gsi_for_stmt(asm_stmt);
116856 +
116857 + assign = gimple_build_assign(lhs, rhs);
116858 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116859 + SSA_NAME_DEF_STMT(lhs) = assign;
116860 +
116861 + gsi_remove(&gsi, true);
116862 +}
116863 +
116864 +// Get the field decl of a component ref for intentional_overflow checking
116865 +static const_tree search_field_decl(const_tree comp_ref)
116866 +{
116867 + const_tree field = NULL_TREE;
116868 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116869 +
116870 + for (i = 0; i < len; i++) {
116871 + field = TREE_OPERAND(comp_ref, i);
116872 + if (TREE_CODE(field) == FIELD_DECL)
116873 + break;
116874 + }
116875 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116876 + return field;
116877 +}
116878 +
116879 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116880 + * stmt is a return otherwise it is the callee function.
116881 + */
116882 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116883 +{
116884 + const_tree fndecl;
116885 +
116886 + if (argnum == 0)
116887 + fndecl = current_function_decl;
116888 + else
116889 + fndecl = gimple_call_fndecl(stmt);
116890 +
116891 + if (fndecl == NULL_TREE)
116892 + return NULL_TREE;
116893 +
116894 + return DECL_ORIGIN(fndecl);
116895 +}
116896 +
116897 +/* Get the param of the intentional_overflow attribute.
116898 + * * 0: MARK_NOT_INTENTIONAL
116899 + * * 1..MAX_PARAM: MARK_YES
116900 + * * -1: MARK_TURN_OFF
116901 + */
116902 +static tree get_attribute_param(const_tree decl)
116903 +{
116904 + const_tree attr;
116905 +
116906 + if (decl == NULL_TREE)
116907 + return NULL_TREE;
116908 +
116909 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116910 + if (!attr || !TREE_VALUE(attr))
116911 + return NULL_TREE;
116912 +
116913 + return TREE_VALUE(attr);
116914 +}
116915 +
116916 +// MARK_TURN_OFF
116917 +static bool is_turn_off_intentional_attr(const_tree decl)
116918 +{
116919 + const_tree param_head;
116920 +
116921 + param_head = get_attribute_param(decl);
116922 + if (param_head == NULL_TREE)
116923 + return false;
116924 +
116925 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116926 + return true;
116927 + return false;
116928 +}
116929 +
116930 +// MARK_NOT_INTENTIONAL
116931 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116932 +{
116933 + const_tree param_head;
116934 +
116935 + if (argnum == 0)
116936 + return false;
116937 +
116938 + param_head = get_attribute_param(decl);
116939 + if (param_head == NULL_TREE)
116940 + return false;
116941 +
116942 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116943 + return true;
116944 + return false;
116945 +}
116946 +
116947 +// MARK_YES
116948 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116949 +{
116950 + tree param, param_head;
116951 +
116952 + if (argnum == 0)
116953 + return false;
116954 +
116955 + param_head = get_attribute_param(decl);
116956 + for (param = param_head; param; param = TREE_CHAIN(param))
116957 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
116958 + return true;
116959 + return false;
116960 +}
116961 +
116962 +static const char *get_asm_string(const_gimple stmt)
116963 +{
116964 + if (!stmt)
116965 + return NULL;
116966 + if (gimple_code(stmt) != GIMPLE_ASM)
116967 + return NULL;
116968 +
116969 + return gimple_asm_string(stmt);
116970 +}
116971 +
116972 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
116973 +{
116974 + const char *str;
116975 +
116976 + str = get_asm_string(stmt);
116977 + if (!str)
116978 + return false;
116979 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
116980 +}
116981 +
116982 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
116983 +{
116984 + const char *str;
116985 +
116986 + str = get_asm_string(stmt);
116987 + if (!str)
116988 + return false;
116989 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
116990 +}
116991 +
116992 +static bool is_size_overflow_asm(const_gimple stmt)
116993 +{
116994 + const char *str;
116995 +
116996 + str = get_asm_string(stmt);
116997 + if (!str)
116998 + return false;
116999 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
117000 +}
117001 +
117002 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
117003 +{
117004 + location_t loc;
117005 +
117006 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
117007 + return;
117008 +
117009 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
117010 + return;
117011 +
117012 + loc = DECL_SOURCE_LOCATION(decl);
117013 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
117014 +}
117015 +
117016 +/* Get the type of the intentional_overflow attribute of a node
117017 + * * MARK_TURN_OFF
117018 + * * MARK_YES
117019 + * * MARK_NO
117020 + * * MARK_NOT_INTENTIONAL
117021 + */
117022 +static enum mark get_intentional_attr_type(const_tree node)
117023 +{
117024 + const_tree cur_decl;
117025 +
117026 + if (node == NULL_TREE)
117027 + return MARK_NO;
117028 +
117029 + switch (TREE_CODE(node)) {
117030 + case COMPONENT_REF:
117031 + cur_decl = search_field_decl(node);
117032 + if (is_turn_off_intentional_attr(cur_decl))
117033 + return MARK_TURN_OFF;
117034 + if (is_end_intentional_intentional_attr(cur_decl, 1))
117035 + return MARK_YES;
117036 + break;
117037 + case PARM_DECL: {
117038 + unsigned int argnum;
117039 +
117040 + cur_decl = DECL_ORIGIN(current_function_decl);
117041 + argnum = find_arg_number_tree(node, cur_decl);
117042 + if (argnum == CANNOT_FIND_ARG)
117043 + return MARK_NO;
117044 + if (is_yes_intentional_attr(cur_decl, argnum))
117045 + return MARK_YES;
117046 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
117047 + return MARK_NOT_INTENTIONAL;
117048 + break;
117049 + }
117050 + case FUNCTION_DECL:
117051 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
117052 + return MARK_TURN_OFF;
117053 + break;
117054 + default:
117055 + break;
117056 + }
117057 + return MARK_NO;
117058 +}
117059 +
117060 +// Search for the intentional_overflow attribute on the last nodes
117061 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
117062 +{
117063 + unsigned int i;
117064 + tree last_node;
117065 + enum mark mark = MARK_NO;
117066 +
117067 +#if BUILDING_GCC_VERSION <= 4007
117068 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
117069 +#else
117070 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
117071 +#endif
117072 + mark = get_intentional_attr_type(last_node);
117073 + if (mark != MARK_NO)
117074 + break;
117075 + }
117076 + return mark;
117077 +}
117078 +
117079 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
117080 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
117081 + */
117082 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
117083 +{
117084 + if (!cur_node->intentional_mark_from_gimple)
117085 + return false;
117086 +
117087 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
117088 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
117089 + else
117090 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117091 +
117092 + // skip param decls
117093 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
117094 + return true;
117095 + return true;
117096 +}
117097 +
117098 +/* Search intentional_overflow attribute on caller and on callee too.
117099 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
117100 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
117101 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
117102 +*/
117103 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
117104 +{
117105 + const_tree fndecl;
117106 +
117107 + if (is_intentional_attribute_from_gimple(cur_node))
117108 + return;
117109 +
117110 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117111 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117112 + return;
117113 + }
117114 +
117115 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
117116 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
117117 + return;
117118 + }
117119 +
117120 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
117121 + return;
117122 +
117123 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
117124 + if (is_turn_off_intentional_attr(fndecl)) {
117125 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
117126 + return;
117127 + }
117128 +
117129 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
117130 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
117131 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
117132 + cur_node->intentional_attr_decl = MARK_YES;
117133 +
117134 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
117135 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
117136 +}
117137 +
117138 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
117139 +static bool skip_asm(const_tree arg)
117140 +{
117141 + gimple def_stmt = get_def_stmt(arg);
117142 +
117143 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117144 + return false;
117145 +
117146 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
117147 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
117148 +}
117149 +
117150 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
117151 +{
117152 + gimple phi = get_def_stmt(result);
117153 + unsigned int i, n = gimple_phi_num_args(phi);
117154 +
117155 + pointer_set_insert(visited, phi);
117156 + for (i = 0; i < n; i++) {
117157 + tree arg = gimple_phi_arg_def(phi, i);
117158 +
117159 + walk_use_def(visited, cur_node, arg);
117160 + }
117161 +}
117162 +
117163 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
117164 +{
117165 + gimple def_stmt = get_def_stmt(lhs);
117166 + tree rhs1, rhs2;
117167 +
117168 + rhs1 = gimple_assign_rhs1(def_stmt);
117169 + rhs2 = gimple_assign_rhs2(def_stmt);
117170 +
117171 + walk_use_def(visited, cur_node, rhs1);
117172 + walk_use_def(visited, cur_node, rhs2);
117173 +}
117174 +
117175 +static void insert_last_node(struct interesting_node *cur_node, tree node)
117176 +{
117177 + unsigned int i;
117178 + tree element;
117179 + enum tree_code code;
117180 +
117181 + gcc_assert(node != NULL_TREE);
117182 +
117183 + if (is_gimple_constant(node))
117184 + return;
117185 +
117186 + code = TREE_CODE(node);
117187 + if (code == VAR_DECL) {
117188 + node = DECL_ORIGIN(node);
117189 + code = TREE_CODE(node);
117190 + }
117191 +
117192 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
117193 + return;
117194 +
117195 +#if BUILDING_GCC_VERSION <= 4007
117196 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
117197 +#else
117198 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
117199 +#endif
117200 + if (operand_equal_p(node, element, 0))
117201 + return;
117202 + }
117203 +
117204 +#if BUILDING_GCC_VERSION <= 4007
117205 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
117206 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
117207 +#else
117208 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
117209 + vec_safe_push(cur_node->last_nodes, node);
117210 +#endif
117211 +}
117212 +
117213 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
117214 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
117215 +{
117216 + if (!is_size_overflow_asm(stmt))
117217 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117218 +}
117219 +
117220 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
117221 + * and component refs (for checking the intentional_overflow attribute).
117222 + */
117223 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
117224 +{
117225 + const_gimple def_stmt;
117226 +
117227 + if (TREE_CODE(lhs) != SSA_NAME) {
117228 + insert_last_node(cur_node, lhs);
117229 + return;
117230 + }
117231 +
117232 + def_stmt = get_def_stmt(lhs);
117233 + if (!def_stmt)
117234 + return;
117235 +
117236 + if (pointer_set_insert(visited, def_stmt))
117237 + return;
117238 +
117239 + switch (gimple_code(def_stmt)) {
117240 + case GIMPLE_NOP:
117241 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117242 + case GIMPLE_ASM:
117243 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
117244 + case GIMPLE_CALL: {
117245 + tree fndecl = gimple_call_fndecl(def_stmt);
117246 +
117247 + if (fndecl == NULL_TREE)
117248 + return;
117249 + insert_last_node(cur_node, fndecl);
117250 + return;
117251 + }
117252 + case GIMPLE_PHI:
117253 + return walk_use_def_phi(visited, cur_node, lhs);
117254 + case GIMPLE_ASSIGN:
117255 + switch (gimple_num_ops(def_stmt)) {
117256 + case 2:
117257 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
117258 + case 3:
117259 + return walk_use_def_binary(visited, cur_node, lhs);
117260 + }
117261 + default:
117262 + debug_gimple_stmt((gimple)def_stmt);
117263 + error("%s: unknown gimple code", __func__);
117264 + gcc_unreachable();
117265 + }
117266 +}
117267 +
117268 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
117269 +static void set_last_nodes(struct interesting_node *cur_node)
117270 +{
117271 + struct pointer_set_t *visited;
117272 +
117273 + visited = pointer_set_create();
117274 + walk_use_def(visited, cur_node, cur_node->node);
117275 + pointer_set_destroy(visited);
117276 +}
117277 +
117278 +enum precond {
117279 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
117280 +};
117281 +
117282 +/* 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.
117283 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
117284 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
117285 + * 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.
117286 + */
117287 +static enum precond check_preconditions(struct interesting_node *cur_node)
117288 +{
117289 + bool interesting_conditions[3] = {false, false, false};
117290 +
117291 + set_last_nodes(cur_node);
117292 +
117293 + check_intentional_attribute_ipa(cur_node);
117294 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
117295 + return NO_ATTRIBUTE_SEARCH;
117296 +
117297 + search_interesting_conditions(cur_node, interesting_conditions);
117298 +
117299 + // error code
117300 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
117301 + return NO_ATTRIBUTE_SEARCH;
117302 +
117303 + // unnecessary overflow check
117304 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
117305 + return NO_CHECK_INSERT;
117306 +
117307 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
117308 + return NO_CHECK_INSERT;
117309 +
117310 + return NONE;
117311 +}
117312 +
117313 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
117314 + * 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
117315 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
117316 + */
117317 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
117318 +{
117319 + enum precond ret;
117320 + struct pointer_set_t *visited;
117321 + tree new_node, orig_node = cur_node->node;
117322 +
117323 + ret = check_preconditions(cur_node);
117324 + if (ret == NO_ATTRIBUTE_SEARCH)
117325 + return cnodes;
117326 +
117327 + cnodes = search_overflow_attribute(cnodes, cur_node);
117328 +
117329 + if (ret == NO_CHECK_INSERT)
117330 + return cnodes;
117331 +
117332 + visited = pointer_set_create();
117333 + new_node = expand(visited, caller_node, orig_node);
117334 + pointer_set_destroy(visited);
117335 +
117336 + if (new_node == NULL_TREE)
117337 + return cnodes;
117338 +
117339 + change_orig_node(cur_node, new_node);
117340 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
117341 +
117342 + return cnodes;
117343 +}
117344 +
117345 +// Check visited interesting nodes.
117346 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
117347 +{
117348 + struct interesting_node *cur;
117349 +
117350 + for (cur = head; cur; cur = cur->next) {
117351 + if (!operand_equal_p(node, cur->node, 0))
117352 + continue;
117353 + if (num != cur->num)
117354 + continue;
117355 + if (first_stmt == cur->first_stmt)
117356 + return true;
117357 + }
117358 + return false;
117359 +}
117360 +
117361 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
117362 + 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
117363 + 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
117364 + the intentional_overflow attribute check. They are collected by set_last_nodes().
117365 + num: arg count of a call stmt or 0 when it is a ret
117366 + node: the recursion starts from here, it is a call arg or a return value
117367 + 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.
117368 + intentional_attr_decl: intentional_overflow attribute of the callee function
117369 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
117370 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
117371 + */
117372 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
117373 +{
117374 + struct interesting_node *new_node;
117375 + tree fndecl;
117376 + enum gimple_code code;
117377 +
117378 + gcc_assert(node != NULL_TREE);
117379 + code = gimple_code(first_stmt);
117380 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
117381 +
117382 + if (num == CANNOT_FIND_ARG)
117383 + return head;
117384 +
117385 + if (skip_types(node))
117386 + return head;
117387 +
117388 + if (skip_asm(node))
117389 + return head;
117390 +
117391 + if (is_gimple_call(first_stmt))
117392 + fndecl = gimple_call_fndecl(first_stmt);
117393 + else
117394 + fndecl = current_function_decl;
117395 +
117396 + if (fndecl == NULL_TREE)
117397 + return head;
117398 +
117399 + if (is_in_interesting_node(head, first_stmt, node, num))
117400 + return head;
117401 +
117402 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
117403 +
117404 + new_node->next = NULL;
117405 + new_node->first_stmt = first_stmt;
117406 +#if BUILDING_GCC_VERSION <= 4007
117407 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
117408 +#else
117409 + vec_alloc(new_node->last_nodes, VEC_LEN);
117410 +#endif
117411 + new_node->num = num;
117412 + new_node->node = node;
117413 + new_node->fndecl = fndecl;
117414 + new_node->intentional_attr_decl = MARK_NO;
117415 + new_node->intentional_attr_cur_fndecl = MARK_NO;
117416 + new_node->intentional_mark_from_gimple = asm_stmt;
117417 +
117418 + if (!head)
117419 + return new_node;
117420 +
117421 + new_node->next = head;
117422 + return new_node;
117423 +}
117424 +
117425 +/* 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).
117426 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
117427 + */
117428 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117429 +{
117430 + struct next_cgraph_node *cur_node;
117431 + tree ret = gimple_return_retval(stmt);
117432 +
117433 + if (ret == NULL_TREE)
117434 + return head;
117435 +
117436 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117437 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
117438 + continue;
117439 + if (cur_node->num == 0)
117440 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
117441 + }
117442 +
117443 + return head;
117444 +}
117445 +
117446 +/* 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).
117447 + * If the call stmt is in the next cgraph node list then it's an interesting call.
117448 + */
117449 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117450 +{
117451 + unsigned int argnum;
117452 + tree arg;
117453 + const_tree fndecl;
117454 + struct next_cgraph_node *cur_node;
117455 +
117456 + fndecl = gimple_call_fndecl(stmt);
117457 + if (fndecl == NULL_TREE)
117458 + return head;
117459 +
117460 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117461 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
117462 + continue;
117463 + argnum = get_correct_arg_count(cur_node->num, fndecl);
117464 + gcc_assert(argnum != CANNOT_FIND_ARG);
117465 + if (argnum == 0)
117466 + continue;
117467 +
117468 + arg = gimple_call_arg(stmt, argnum - 1);
117469 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
117470 + }
117471 +
117472 + return head;
117473 +}
117474 +
117475 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
117476 +{
117477 + if (!operand_equal_p(orig_node, node, 0))
117478 + return WRONG_NODE;
117479 + if (skip_types(node))
117480 + return WRONG_NODE;
117481 + return ret_count;
117482 +}
117483 +
117484 +// Get the index of the rhs node in an assignment
117485 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
117486 +{
117487 + const_tree rhs1, rhs2;
117488 + unsigned int ret;
117489 +
117490 + gcc_assert(stmt);
117491 + gcc_assert(is_gimple_assign(stmt));
117492 +
117493 + rhs1 = gimple_assign_rhs1(stmt);
117494 + gcc_assert(rhs1 != NULL_TREE);
117495 +
117496 + switch (gimple_num_ops(stmt)) {
117497 + case 2:
117498 + return check_ops(node, rhs1, 1);
117499 + case 3:
117500 + ret = check_ops(node, rhs1, 1);
117501 + if (ret != WRONG_NODE)
117502 + return ret;
117503 +
117504 + rhs2 = gimple_assign_rhs2(stmt);
117505 + gcc_assert(rhs2 != NULL_TREE);
117506 + return check_ops(node, rhs2, 2);
117507 + default:
117508 + gcc_unreachable();
117509 + }
117510 +}
117511 +
117512 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
117513 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
117514 +{
117515 + unsigned int i;
117516 +
117517 + if (gimple_call_fndecl(stmt) == NULL_TREE)
117518 + return CANNOT_FIND_ARG;
117519 +
117520 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
117521 + tree node;
117522 +
117523 + node = gimple_call_arg(stmt, i);
117524 + if (!operand_equal_p(arg, node, 0))
117525 + continue;
117526 + if (!skip_types(node))
117527 + return i + 1;
117528 + }
117529 +
117530 + return CANNOT_FIND_ARG;
117531 +}
117532 +
117533 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
117534 + * any of return, call or assignment stmts (because of inlining).
117535 + */
117536 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
117537 +{
117538 + use_operand_p use_p;
117539 + imm_use_iterator imm_iter;
117540 + unsigned int argnum;
117541 +
117542 + gcc_assert(TREE_CODE(node) == SSA_NAME);
117543 +
117544 + if (pointer_set_insert(visited, node))
117545 + return head;
117546 +
117547 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117548 + gimple stmt = USE_STMT(use_p);
117549 +
117550 + if (stmt == NULL)
117551 + return head;
117552 + if (is_gimple_debug(stmt))
117553 + continue;
117554 +
117555 + switch (gimple_code(stmt)) {
117556 + case GIMPLE_CALL:
117557 + argnum = find_arg_number_gimple(node, stmt);
117558 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117559 + break;
117560 + case GIMPLE_RETURN:
117561 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
117562 + break;
117563 + case GIMPLE_ASSIGN:
117564 + argnum = get_assign_ops_count(stmt, node);
117565 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117566 + break;
117567 + case GIMPLE_PHI: {
117568 + tree result = gimple_phi_result(stmt);
117569 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
117570 + break;
117571 + }
117572 + case GIMPLE_ASM:
117573 + if (gimple_asm_noutputs(stmt) != 0)
117574 + break;
117575 + if (!is_size_overflow_asm(stmt))
117576 + break;
117577 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
117578 + break;
117579 + case GIMPLE_COND:
117580 + case GIMPLE_SWITCH:
117581 + break;
117582 + default:
117583 + debug_gimple_stmt(stmt);
117584 + gcc_unreachable();
117585 + break;
117586 + }
117587 + }
117588 + return head;
117589 +}
117590 +
117591 +static void remove_size_overflow_asm(gimple stmt)
117592 +{
117593 + gimple_stmt_iterator gsi;
117594 + tree input, output;
117595 +
117596 + if (!is_size_overflow_asm(stmt))
117597 + return;
117598 +
117599 + if (gimple_asm_noutputs(stmt) == 0) {
117600 + gsi = gsi_for_stmt(stmt);
117601 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
117602 + gsi_remove(&gsi, true);
117603 + return;
117604 + }
117605 +
117606 + input = gimple_asm_input_op(stmt, 0);
117607 + output = gimple_asm_output_op(stmt, 0);
117608 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
117609 +}
117610 +
117611 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
117612 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
117613 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
117614 + */
117615 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
117616 +{
117617 + const_tree output;
117618 + struct pointer_set_t *visited;
117619 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
117620 +
117621 + if (!is_size_overflow_asm(stmt))
117622 + return head;
117623 +
117624 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
117625 + intentional_asm = stmt;
117626 +
117627 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
117628 +
117629 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
117630 + return head;
117631 +
117632 + if (gimple_asm_noutputs(stmt) == 0) {
117633 + const_tree input;
117634 +
117635 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
117636 + return head;
117637 +
117638 + input = gimple_asm_input_op(stmt, 0);
117639 + remove_size_overflow_asm(stmt);
117640 + if (is_gimple_constant(TREE_VALUE(input)))
117641 + return head;
117642 + visited = pointer_set_create();
117643 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
117644 + pointer_set_destroy(visited);
117645 + return head;
117646 + }
117647 +
117648 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
117649 + remove_size_overflow_asm(stmt);
117650 +
117651 + visited = pointer_set_create();
117652 + output = gimple_asm_output_op(stmt, 0);
117653 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
117654 + pointer_set_destroy(visited);
117655 + return head;
117656 +}
117657 +
117658 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
117659 + * or a call stmt or a return stmt and store them in the interesting_node list
117660 + */
117661 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
117662 +{
117663 + basic_block bb;
117664 + struct interesting_node *head = NULL;
117665 +
117666 + FOR_ALL_BB_FN(bb, cfun) {
117667 + gimple_stmt_iterator gsi;
117668 +
117669 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117670 + enum gimple_code code;
117671 + gimple stmt = gsi_stmt(gsi);
117672 +
117673 + code = gimple_code(stmt);
117674 +
117675 + if (code == GIMPLE_ASM)
117676 + head = handle_stmt_by_size_overflow_asm(stmt, head);
117677 +
117678 + if (!next_node)
117679 + continue;
117680 + if (code == GIMPLE_CALL)
117681 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
117682 + if (code == GIMPLE_RETURN)
117683 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
117684 + }
117685 + }
117686 + return head;
117687 +}
117688 +
117689 +static void set_current_function_decl(tree fndecl)
117690 +{
117691 + gcc_assert(fndecl != NULL_TREE);
117692 +
117693 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117694 + calculate_dominance_info(CDI_DOMINATORS);
117695 + current_function_decl = fndecl;
117696 +}
117697 +
117698 +static void unset_current_function_decl(void)
117699 +{
117700 + free_dominance_info(CDI_DOMINATORS);
117701 + pop_cfun();
117702 + current_function_decl = NULL_TREE;
117703 +}
117704 +
117705 +static void free_interesting_node(struct interesting_node *head)
117706 +{
117707 + struct interesting_node *cur;
117708 +
117709 + while (head) {
117710 + cur = head->next;
117711 +#if BUILDING_GCC_VERSION <= 4007
117712 + VEC_free(tree, gc, head->last_nodes);
117713 +#else
117714 + vec_free(head->last_nodes);
117715 +#endif
117716 + free(head);
117717 + head = cur;
117718 + }
117719 +}
117720 +
117721 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
117722 +{
117723 + struct visited *new_visited;
117724 +
117725 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
117726 + new_visited->fndecl = cur_node->fndecl;
117727 + new_visited->num = cur_node->num;
117728 + new_visited->next = NULL;
117729 +
117730 + if (!head)
117731 + return new_visited;
117732 +
117733 + new_visited->next = head;
117734 + return new_visited;
117735 +}
117736 +
117737 +/* 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
117738 + * it is a visited function.
117739 + */
117740 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
117741 +{
117742 + struct visited *cur;
117743 +
117744 + if (!head)
117745 + return false;
117746 +
117747 + if (get_stmt_flag(cur_node->first_stmt) != VISITED_STMT)
117748 + return false;
117749 +
117750 + for (cur = head; cur; cur = cur->next) {
117751 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
117752 + continue;
117753 + if (cur_node->num == cur->num)
117754 + return true;
117755 + }
117756 + return false;
117757 +}
117758 +
117759 +static void free_next_cgraph_node(struct next_cgraph_node *head)
117760 +{
117761 + struct next_cgraph_node *cur;
117762 +
117763 + while (head) {
117764 + cur = head->next;
117765 + free(head);
117766 + head = cur;
117767 + }
117768 +}
117769 +
117770 +static void remove_all_size_overflow_asm(void)
117771 +{
117772 + basic_block bb;
117773 +
117774 + FOR_ALL_BB_FN(bb, cfun) {
117775 + gimple_stmt_iterator si;
117776 +
117777 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117778 + remove_size_overflow_asm(gsi_stmt(si));
117779 + }
117780 +}
117781 +
117782 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
117783 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
117784 + * the newly collected interesting functions (they are interesting if there is control flow between
117785 + * the interesting stmts and them).
117786 + */
117787 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
117788 +{
117789 + struct interesting_node *head, *cur_node;
117790 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
117791 +
117792 + set_current_function_decl(NODE_DECL(node));
117793 + call_count = 0;
117794 +
117795 + head = collect_interesting_stmts(next_node);
117796 +
117797 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
117798 + if (is_visited_function(visited, cur_node))
117799 + continue;
117800 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
117801 + set_stmt_flag(cur_node->first_stmt, VISITED_STMT);
117802 + visited = insert_visited_function(visited, cur_node);
117803 + }
117804 +
117805 + free_interesting_node(head);
117806 + remove_all_size_overflow_asm();
117807 + unset_current_function_decl();
117808 +
117809 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
117810 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
117811 +
117812 + free_next_cgraph_node(cnodes_head);
117813 + return visited;
117814 +}
117815 +
117816 +static void free_visited(struct visited *head)
117817 +{
117818 + struct visited *cur;
117819 +
117820 + while (head) {
117821 + cur = head->next;
117822 + free(head);
117823 + head = cur;
117824 + }
117825 +}
117826 +
117827 +// erase the local flag
117828 +static void set_plf_false(void)
117829 +{
117830 + basic_block bb;
117831 +
117832 + FOR_ALL_BB_FN(bb, cfun) {
117833 + gimple_stmt_iterator si;
117834 +
117835 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117836 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117837 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117838 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117839 + }
117840 +}
117841 +
117842 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
117843 +static unsigned int search_function(void)
117844 +{
117845 + struct cgraph_node *node;
117846 + struct visited *visited = NULL;
117847 +
117848 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117849 + set_current_function_decl(NODE_DECL(node));
117850 + set_plf_false();
117851 + unset_current_function_decl();
117852 + }
117853 +
117854 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117855 + gcc_assert(cgraph_function_flags_ready);
117856 +#if BUILDING_GCC_VERSION <= 4007
117857 + gcc_assert(node->reachable);
117858 +#endif
117859 +
117860 + visited = handle_function(node, NULL, visited);
117861 + }
117862 +
117863 + free_visited(visited);
117864 + return 0;
117865 +}
117866 +
117867 +#if BUILDING_GCC_VERSION >= 4009
117868 +static const struct pass_data ipa_pass_data = {
117869 +#else
117870 +static struct ipa_opt_pass_d ipa_pass = {
117871 + .pass = {
117872 +#endif
117873 + .type = SIMPLE_IPA_PASS,
117874 + .name = "size_overflow",
117875 +#if BUILDING_GCC_VERSION >= 4008
117876 + .optinfo_flags = OPTGROUP_NONE,
117877 +#endif
117878 +#if BUILDING_GCC_VERSION >= 4009
117879 + .has_gate = false,
117880 + .has_execute = true,
117881 +#else
117882 + .gate = NULL,
117883 + .execute = search_function,
117884 + .sub = NULL,
117885 + .next = NULL,
117886 + .static_pass_number = 0,
117887 +#endif
117888 + .tv_id = TV_NONE,
117889 + .properties_required = 0,
117890 + .properties_provided = 0,
117891 + .properties_destroyed = 0,
117892 + .todo_flags_start = 0,
117893 + .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,
117894 +#if BUILDING_GCC_VERSION < 4009
117895 + },
117896 + .generate_summary = NULL,
117897 + .write_summary = NULL,
117898 + .read_summary = NULL,
117899 +#if BUILDING_GCC_VERSION >= 4006
117900 + .write_optimization_summary = NULL,
117901 + .read_optimization_summary = NULL,
117902 +#endif
117903 + .stmt_fixup = NULL,
117904 + .function_transform_todo_flags_start = 0,
117905 + .function_transform = NULL,
117906 + .variable_transform = NULL,
117907 +#endif
117908 +};
117909 +
117910 +#if BUILDING_GCC_VERSION >= 4009
117911 +namespace {
117912 +class ipa_pass : public ipa_opt_pass_d {
117913 +public:
117914 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117915 + unsigned int execute() { return search_function(); }
117916 +};
117917 +}
117918 +#endif
117919 +
117920 +static struct opt_pass *make_ipa_pass(void)
117921 +{
117922 +#if BUILDING_GCC_VERSION >= 4009
117923 + return new ipa_pass();
117924 +#else
117925 + return &ipa_pass.pass;
117926 +#endif
117927 +}
117928 +
117929 +// data for the size_overflow asm stmt
117930 +struct asm_data {
117931 + gimple def_stmt;
117932 + tree input;
117933 + tree output;
117934 +};
117935 +
117936 +#if BUILDING_GCC_VERSION <= 4007
117937 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
117938 +#else
117939 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
117940 +#endif
117941 +{
117942 + tree list;
117943 +#if BUILDING_GCC_VERSION <= 4007
117944 + VEC(tree, gc) *vec_list = NULL;
117945 +#else
117946 + vec<tree, va_gc> *vec_list = NULL;
117947 +#endif
117948 +
117949 + list = build_tree_list(NULL_TREE, string);
117950 + list = chainon(NULL_TREE, build_tree_list(list, io));
117951 +#if BUILDING_GCC_VERSION <= 4007
117952 + VEC_safe_push(tree, gc, vec_list, list);
117953 +#else
117954 + vec_safe_push(vec_list, list);
117955 +#endif
117956 + return vec_list;
117957 +}
117958 +
117959 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
117960 +{
117961 + gimple asm_stmt;
117962 + gimple_stmt_iterator gsi;
117963 +#if BUILDING_GCC_VERSION <= 4007
117964 + VEC(tree, gc) *input, *output = NULL;
117965 +#else
117966 + vec<tree, va_gc> *input, *output = NULL;
117967 +#endif
117968 +
117969 + input = create_asm_io_list(str_input, asm_data->input);
117970 +
117971 + if (asm_data->output)
117972 + output = create_asm_io_list(str_output, asm_data->output);
117973 +
117974 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
117975 + gsi = gsi_for_stmt(asm_data->def_stmt);
117976 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
117977 +
117978 + if (asm_data->output)
117979 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
117980 +}
117981 +
117982 +static void replace_call_lhs(const struct asm_data *asm_data)
117983 +{
117984 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
117985 + update_stmt(asm_data->def_stmt);
117986 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
117987 +}
117988 +
117989 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
117990 +{
117991 + enum mark cur_fndecl_attr;
117992 + gimple phi = get_def_stmt(result);
117993 + unsigned int i, n = gimple_phi_num_args(phi);
117994 +
117995 + pointer_set_insert(visited, phi);
117996 + for (i = 0; i < n; i++) {
117997 + tree arg = gimple_phi_arg_def(phi, i);
117998 +
117999 + cur_fndecl_attr = search_intentional(visited, arg);
118000 + if (cur_fndecl_attr != MARK_NO)
118001 + return cur_fndecl_attr;
118002 + }
118003 + return MARK_NO;
118004 +}
118005 +
118006 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
118007 +{
118008 + enum mark cur_fndecl_attr;
118009 + const_tree rhs1, rhs2;
118010 + gimple def_stmt = get_def_stmt(lhs);
118011 +
118012 + rhs1 = gimple_assign_rhs1(def_stmt);
118013 + rhs2 = gimple_assign_rhs2(def_stmt);
118014 +
118015 + cur_fndecl_attr = search_intentional(visited, rhs1);
118016 + if (cur_fndecl_attr != MARK_NO)
118017 + return cur_fndecl_attr;
118018 + return search_intentional(visited, rhs2);
118019 +}
118020 +
118021 +// Look up the intentional_overflow attribute on the caller and the callee functions.
118022 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
118023 +{
118024 + const_gimple def_stmt;
118025 +
118026 + if (TREE_CODE(lhs) != SSA_NAME)
118027 + return get_intentional_attr_type(lhs);
118028 +
118029 + def_stmt = get_def_stmt(lhs);
118030 + if (!def_stmt)
118031 + return MARK_NO;
118032 +
118033 + if (pointer_set_contains(visited, def_stmt))
118034 + return MARK_NO;
118035 +
118036 + switch (gimple_code(def_stmt)) {
118037 + case GIMPLE_NOP:
118038 + return search_intentional(visited, SSA_NAME_VAR(lhs));
118039 + case GIMPLE_ASM:
118040 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
118041 + return MARK_TURN_OFF;
118042 + return MARK_NO;
118043 + case GIMPLE_CALL:
118044 + return MARK_NO;
118045 + case GIMPLE_PHI:
118046 + return search_intentional_phi(visited, lhs);
118047 + case GIMPLE_ASSIGN:
118048 + switch (gimple_num_ops(def_stmt)) {
118049 + case 2:
118050 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
118051 + case 3:
118052 + return search_intentional_binary(visited, lhs);
118053 + }
118054 + case GIMPLE_RETURN:
118055 + return MARK_NO;
118056 + default:
118057 + debug_gimple_stmt((gimple)def_stmt);
118058 + error("%s: unknown gimple code", __func__);
118059 + gcc_unreachable();
118060 + }
118061 +}
118062 +
118063 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
118064 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
118065 +{
118066 + const_tree fndecl;
118067 + struct pointer_set_t *visited;
118068 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
118069 +
118070 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
118071 + if (is_end_intentional_intentional_attr(fndecl, argnum))
118072 + decl_attr = MARK_NOT_INTENTIONAL;
118073 + else if (is_yes_intentional_attr(fndecl, argnum))
118074 + decl_attr = MARK_YES;
118075 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
118076 + return MARK_TURN_OFF;
118077 + }
118078 +
118079 + visited = pointer_set_create();
118080 + cur_fndecl_attr = search_intentional(visited, arg);
118081 + pointer_set_destroy(visited);
118082 +
118083 + switch (cur_fndecl_attr) {
118084 + case MARK_NO:
118085 + case MARK_TURN_OFF:
118086 + return cur_fndecl_attr;
118087 + default:
118088 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
118089 + return MARK_YES;
118090 + }
118091 +}
118092 +
118093 +static void check_missing_size_overflow_attribute(tree var)
118094 +{
118095 + tree orig_fndecl;
118096 + unsigned int num;
118097 +
118098 + if (is_a_return_check(var))
118099 + orig_fndecl = DECL_ORIGIN(var);
118100 + else
118101 + orig_fndecl = DECL_ORIGIN(current_function_decl);
118102 +
118103 + num = get_function_num(var, orig_fndecl);
118104 + if (num == CANNOT_FIND_ARG)
118105 + return;
118106 +
118107 + is_missing_function(orig_fndecl, num);
118108 +}
118109 +
118110 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
118111 +{
118112 + gimple phi = get_def_stmt(result);
118113 + unsigned int i, n = gimple_phi_num_args(phi);
118114 +
118115 + pointer_set_insert(visited, phi);
118116 + for (i = 0; i < n; i++) {
118117 + tree arg = gimple_phi_arg_def(phi, i);
118118 +
118119 + search_size_overflow_attribute(visited, arg);
118120 + }
118121 +}
118122 +
118123 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
118124 +{
118125 + const_gimple def_stmt = get_def_stmt(lhs);
118126 + tree rhs1, rhs2;
118127 +
118128 + rhs1 = gimple_assign_rhs1(def_stmt);
118129 + rhs2 = gimple_assign_rhs2(def_stmt);
118130 +
118131 + search_size_overflow_attribute(visited, rhs1);
118132 + search_size_overflow_attribute(visited, rhs2);
118133 +}
118134 +
118135 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
118136 +{
118137 + const_gimple def_stmt;
118138 +
118139 + if (TREE_CODE(lhs) == PARM_DECL) {
118140 + check_missing_size_overflow_attribute(lhs);
118141 + return;
118142 + }
118143 +
118144 + def_stmt = get_def_stmt(lhs);
118145 + if (!def_stmt)
118146 + return;
118147 +
118148 + if (pointer_set_insert(visited, def_stmt))
118149 + return;
118150 +
118151 + switch (gimple_code(def_stmt)) {
118152 + case GIMPLE_NOP:
118153 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
118154 + case GIMPLE_ASM:
118155 + return;
118156 + case GIMPLE_CALL: {
118157 + tree fndecl = gimple_call_fndecl(def_stmt);
118158 +
118159 + if (fndecl == NULL_TREE)
118160 + return;
118161 + check_missing_size_overflow_attribute(fndecl);
118162 + return;
118163 + }
118164 + case GIMPLE_PHI:
118165 + return search_size_overflow_attribute_phi(visited, lhs);
118166 + case GIMPLE_ASSIGN:
118167 + switch (gimple_num_ops(def_stmt)) {
118168 + case 2:
118169 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
118170 + case 3:
118171 + return search_size_overflow_attribute_binary(visited, lhs);
118172 + }
118173 + default:
118174 + debug_gimple_stmt((gimple)def_stmt);
118175 + error("%s: unknown gimple code", __func__);
118176 + gcc_unreachable();
118177 + }
118178 +}
118179 +
118180 +// Search missing entries in the hash table (invoked from the gimple pass)
118181 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
118182 +{
118183 + tree fndecl = NULL_TREE;
118184 + tree lhs;
118185 + struct pointer_set_t *visited;
118186 +
118187 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
118188 + return;
118189 +
118190 + if (num == 0) {
118191 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
118192 + lhs = gimple_return_retval(stmt);
118193 + } else {
118194 + gcc_assert(is_gimple_call(stmt));
118195 + lhs = gimple_call_arg(stmt, num - 1);
118196 + fndecl = gimple_call_fndecl(stmt);
118197 + }
118198 +
118199 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
118200 + return;
118201 +
118202 + visited = pointer_set_create();
118203 + search_size_overflow_attribute(visited, lhs);
118204 + pointer_set_destroy(visited);
118205 +}
118206 +
118207 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
118208 +{
118209 + gimple_stmt_iterator gsi;
118210 + gimple assign;
118211 +
118212 + assign = gimple_build_assign(asm_data->input, asm_data->output);
118213 + gsi = gsi_for_stmt(stmt);
118214 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
118215 + asm_data->def_stmt = assign;
118216 +
118217 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
118218 + asm_data->output = make_ssa_name(asm_data->output, stmt);
118219 + if (gimple_code(stmt) == GIMPLE_RETURN)
118220 + gimple_return_set_retval(stmt, asm_data->output);
118221 + else
118222 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
118223 + update_stmt(stmt);
118224 +}
118225 +
118226 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
118227 +{
118228 + const char *fn_name;
118229 + char *asm_comment;
118230 + unsigned int len;
118231 +
118232 + if (argnum == 0)
118233 + fn_name = DECL_NAME_POINTER(current_function_decl);
118234 + else
118235 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
118236 +
118237 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
118238 + gcc_assert(len > 0);
118239 +
118240 + return asm_comment;
118241 +}
118242 +
118243 +static const char *convert_mark_to_str(enum mark mark)
118244 +{
118245 + switch (mark) {
118246 + case MARK_NO:
118247 + return OK_ASM_STR;
118248 + case MARK_YES:
118249 + case MARK_NOT_INTENTIONAL:
118250 + return YES_ASM_STR;
118251 + case MARK_TURN_OFF:
118252 + return TURN_OFF_ASM_STR;
118253 + }
118254 +
118255 + gcc_unreachable();
118256 +}
118257 +
118258 +/* Create the input of the size_overflow asm stmt.
118259 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
118260 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118261 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
118262 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
118263 + */
118264 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
118265 +{
118266 + if (!asm_data->def_stmt) {
118267 + asm_data->input = NULL_TREE;
118268 + return;
118269 + }
118270 +
118271 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
118272 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
118273 +
118274 + switch (gimple_code(asm_data->def_stmt)) {
118275 + case GIMPLE_ASSIGN:
118276 + case GIMPLE_CALL:
118277 + replace_call_lhs(asm_data);
118278 + break;
118279 + case GIMPLE_PHI:
118280 + create_output_from_phi(stmt, argnum, asm_data);
118281 + break;
118282 + case GIMPLE_NOP: {
118283 + enum mark mark;
118284 + const char *mark_str;
118285 + char *asm_comment;
118286 +
118287 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
118288 +
118289 + asm_data->input = asm_data->output;
118290 + asm_data->output = NULL;
118291 + asm_data->def_stmt = stmt;
118292 +
118293 + mark_str = convert_mark_to_str(mark);
118294 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118295 +
118296 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
118297 + free(asm_comment);
118298 + asm_data->input = NULL_TREE;
118299 + break;
118300 + }
118301 + case GIMPLE_ASM:
118302 + if (is_size_overflow_asm(asm_data->def_stmt)) {
118303 + asm_data->input = NULL_TREE;
118304 + break;
118305 + }
118306 + default:
118307 + debug_gimple_stmt(asm_data->def_stmt);
118308 + gcc_unreachable();
118309 + }
118310 +}
118311 +
118312 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
118313 + * is of the right kind create the appropriate size_overflow asm stmts:
118314 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
118315 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118316 + */
118317 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
118318 +{
118319 + struct asm_data asm_data;
118320 + const char *mark_str;
118321 + char *asm_comment;
118322 + enum mark mark;
118323 +
118324 + if (is_gimple_constant(output_node))
118325 + return;
118326 +
118327 + asm_data.output = output_node;
118328 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
118329 + if (mark != MARK_TURN_OFF)
118330 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
118331 +
118332 + asm_data.def_stmt = get_def_stmt(asm_data.output);
118333 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
118334 + return;
118335 +
118336 + create_asm_input(stmt, argnum, &asm_data);
118337 + if (asm_data.input == NULL_TREE)
118338 + return;
118339 +
118340 + mark_str = convert_mark_to_str(mark);
118341 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118342 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118343 + free(asm_comment);
118344 +}
118345 +
118346 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
118347 +static bool create_mark_asm(gimple stmt, enum mark mark)
118348 +{
118349 + struct asm_data asm_data;
118350 + const char *asm_str;
118351 +
118352 + switch (mark) {
118353 + case MARK_TURN_OFF:
118354 + asm_str = TURN_OFF_ASM_STR;
118355 + break;
118356 + case MARK_NOT_INTENTIONAL:
118357 + case MARK_YES:
118358 + asm_str = YES_ASM_STR;
118359 + break;
118360 + default:
118361 + gcc_unreachable();
118362 + }
118363 +
118364 + asm_data.def_stmt = stmt;
118365 + asm_data.output = gimple_call_lhs(stmt);
118366 +
118367 + if (asm_data.output == NULL_TREE) {
118368 + asm_data.input = gimple_call_arg(stmt, 0);
118369 + if (is_gimple_constant(asm_data.input))
118370 + return false;
118371 + asm_data.output = NULL;
118372 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
118373 + return true;
118374 + }
118375 +
118376 + create_asm_input(stmt, 0, &asm_data);
118377 + gcc_assert(asm_data.input != NULL_TREE);
118378 +
118379 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118380 + return true;
118381 +}
118382 +
118383 +static bool is_from_cast(const_tree node)
118384 +{
118385 + gimple def_stmt = get_def_stmt(node);
118386 +
118387 + if (!def_stmt)
118388 + return false;
118389 +
118390 + if (gimple_assign_cast_p(def_stmt))
118391 + return true;
118392 +
118393 + return false;
118394 +}
118395 +
118396 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
118397 +static bool skip_ptr_minus(gimple stmt)
118398 +{
118399 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
118400 +
118401 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
118402 + return false;
118403 +
118404 + rhs1 = gimple_assign_rhs1(stmt);
118405 + if (!is_from_cast(rhs1))
118406 + return false;
118407 +
118408 + rhs2 = gimple_assign_rhs2(stmt);
118409 + if (!is_from_cast(rhs2))
118410 + return false;
118411 +
118412 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
118413 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
118414 +
118415 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
118416 + return false;
118417 +
118418 + create_mark_asm(stmt, MARK_YES);
118419 + return true;
118420 +}
118421 +
118422 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
118423 +{
118424 + gimple def_stmt;
118425 +
118426 + def_stmt = get_def_stmt(lhs);
118427 + if (!def_stmt)
118428 + return;
118429 +
118430 + if (pointer_set_insert(visited, def_stmt))
118431 + return;
118432 +
118433 + switch (gimple_code(def_stmt)) {
118434 + case GIMPLE_NOP:
118435 + case GIMPLE_ASM:
118436 + case GIMPLE_CALL:
118437 + break;
118438 + case GIMPLE_PHI: {
118439 + unsigned int i, n = gimple_phi_num_args(def_stmt);
118440 +
118441 + pointer_set_insert(visited, def_stmt);
118442 +
118443 + for (i = 0; i < n; i++) {
118444 + tree arg = gimple_phi_arg_def(def_stmt, i);
118445 +
118446 + walk_use_def_ptr(visited, arg);
118447 + }
118448 + }
118449 + case GIMPLE_ASSIGN:
118450 + switch (gimple_num_ops(def_stmt)) {
118451 + case 2:
118452 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118453 + return;
118454 + case 3:
118455 + if (skip_ptr_minus(def_stmt))
118456 + return;
118457 +
118458 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118459 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
118460 + return;
118461 + default:
118462 + return;
118463 + }
118464 + default:
118465 + debug_gimple_stmt((gimple)def_stmt);
118466 + error("%s: unknown gimple code", __func__);
118467 + gcc_unreachable();
118468 + }
118469 +}
118470 +
118471 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
118472 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
118473 +{
118474 + struct pointer_set_t *visited;
118475 +
118476 + visited = pointer_set_create();
118477 + walk_use_def_ptr(visited, arg);
118478 + pointer_set_destroy(visited);
118479 +}
118480 +
118481 +// Determine the return value and insert the asm stmt to mark the return stmt.
118482 +static void insert_asm_ret(gimple stmt)
118483 +{
118484 + tree ret;
118485 +
118486 + ret = gimple_return_retval(stmt);
118487 + create_size_overflow_asm(stmt, ret, 0);
118488 +}
118489 +
118490 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
118491 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
118492 +{
118493 + tree arg;
118494 + unsigned int argnum;
118495 +
118496 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
118497 + gcc_assert(argnum != 0);
118498 + if (argnum == CANNOT_FIND_ARG)
118499 + return;
118500 +
118501 + arg = gimple_call_arg(stmt, argnum - 1);
118502 + gcc_assert(arg != NULL_TREE);
118503 +
118504 + // skip all ptr - ptr expressions
118505 + insert_mark_not_intentional_asm_at_ptr(arg);
118506 +
118507 + create_size_overflow_asm(stmt, arg, argnum);
118508 +}
118509 +
118510 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
118511 +static void set_argnum_attribute(const_tree attr, bool *argnums)
118512 +{
118513 + unsigned int argnum;
118514 + tree attr_value;
118515 +
118516 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
118517 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
118518 + argnums[argnum] = true;
118519 + }
118520 +}
118521 +
118522 +// If a function arg or the return value is in the hash table then set its index in the array.
118523 +static void set_argnum_hash(tree fndecl, bool *argnums)
118524 +{
118525 + unsigned int num;
118526 + const struct size_overflow_hash *hash;
118527 +
118528 + hash = get_function_hash(DECL_ORIGIN(fndecl));
118529 + if (!hash)
118530 + return;
118531 +
118532 + for (num = 0; num <= MAX_PARAM; num++) {
118533 + if (!(hash->param & (1U << num)))
118534 + continue;
118535 +
118536 + argnums[num] = true;
118537 + }
118538 +}
118539 +
118540 +static bool is_all_the_argnums_empty(bool *argnums)
118541 +{
118542 + unsigned int i;
118543 +
118544 + for (i = 0; i <= MAX_PARAM; i++)
118545 + if (argnums[i])
118546 + return false;
118547 + return true;
118548 +}
118549 +
118550 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
118551 +static void search_interesting_args(tree fndecl, bool *argnums)
118552 +{
118553 + const_tree attr;
118554 +
118555 + set_argnum_hash(fndecl, argnums);
118556 + if (!is_all_the_argnums_empty(argnums))
118557 + return;
118558 +
118559 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
118560 + if (attr && TREE_VALUE(attr))
118561 + set_argnum_attribute(attr, argnums);
118562 +}
118563 +
118564 +/*
118565 + * Look up the intentional_overflow attribute that turns off ipa based duplication
118566 + * on the callee function.
118567 + */
118568 +static bool is_mark_turn_off_attribute(gimple stmt)
118569 +{
118570 + enum mark mark;
118571 + const_tree fndecl = gimple_call_fndecl(stmt);
118572 +
118573 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
118574 + if (mark == MARK_TURN_OFF)
118575 + return true;
118576 + return false;
118577 +}
118578 +
118579 +// 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
118580 +static void handle_interesting_function(gimple stmt)
118581 +{
118582 + unsigned int argnum;
118583 + tree fndecl;
118584 + bool orig_argnums[MAX_PARAM + 1] = {false};
118585 +
118586 + if (gimple_call_num_args(stmt) == 0)
118587 + return;
118588 + fndecl = gimple_call_fndecl(stmt);
118589 + if (fndecl == NULL_TREE)
118590 + return;
118591 + fndecl = DECL_ORIGIN(fndecl);
118592 +
118593 + if (is_mark_turn_off_attribute(stmt)) {
118594 + create_mark_asm(stmt, MARK_TURN_OFF);
118595 + return;
118596 + }
118597 +
118598 + search_interesting_args(fndecl, orig_argnums);
118599 +
118600 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
118601 + if (orig_argnums[argnum])
118602 + insert_asm_arg(stmt, argnum);
118603 +}
118604 +
118605 +// 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
118606 +static void handle_interesting_ret(gimple stmt)
118607 +{
118608 + bool orig_argnums[MAX_PARAM + 1] = {false};
118609 +
118610 + search_interesting_args(current_function_decl, orig_argnums);
118611 +
118612 + if (orig_argnums[0])
118613 + insert_asm_ret(stmt);
118614 +}
118615 +
118616 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
118617 +static unsigned int search_interesting_functions(void)
118618 +{
118619 + basic_block bb;
118620 +
118621 + FOR_ALL_BB_FN(bb, cfun) {
118622 + gimple_stmt_iterator gsi;
118623 +
118624 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118625 + gimple stmt = gsi_stmt(gsi);
118626 +
118627 + if (is_size_overflow_asm(stmt))
118628 + continue;
118629 +
118630 + if (is_gimple_call(stmt))
118631 + handle_interesting_function(stmt);
118632 + else if (gimple_code(stmt) == GIMPLE_RETURN)
118633 + handle_interesting_ret(stmt);
118634 + }
118635 + }
118636 + return 0;
118637 +}
118638 +
118639 +/*
118640 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
118641 + * this pass inserts asm stmts to mark the interesting args
118642 + * that the ipa pass will detect and insert the size overflow checks for.
118643 + */
118644 +#if BUILDING_GCC_VERSION >= 4009
118645 +static const struct pass_data insert_size_overflow_asm_pass_data = {
118646 +#else
118647 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
118648 + .pass = {
118649 +#endif
118650 + .type = GIMPLE_PASS,
118651 + .name = "insert_size_overflow_asm",
118652 +#if BUILDING_GCC_VERSION >= 4008
118653 + .optinfo_flags = OPTGROUP_NONE,
118654 +#endif
118655 +#if BUILDING_GCC_VERSION >= 4009
118656 + .has_gate = false,
118657 + .has_execute = true,
118658 +#else
118659 + .gate = NULL,
118660 + .execute = search_interesting_functions,
118661 + .sub = NULL,
118662 + .next = NULL,
118663 + .static_pass_number = 0,
118664 +#endif
118665 + .tv_id = TV_NONE,
118666 + .properties_required = PROP_cfg,
118667 + .properties_provided = 0,
118668 + .properties_destroyed = 0,
118669 + .todo_flags_start = 0,
118670 + .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
118671 +#if BUILDING_GCC_VERSION < 4009
118672 + }
118673 +#endif
118674 +};
118675 +
118676 +#if BUILDING_GCC_VERSION >= 4009
118677 +namespace {
118678 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
118679 +public:
118680 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
118681 + unsigned int execute() { return search_interesting_functions(); }
118682 +};
118683 +}
118684 +#endif
118685 +
118686 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
118687 +{
118688 +#if BUILDING_GCC_VERSION >= 4009
118689 + return new insert_size_overflow_asm_pass();
118690 +#else
118691 + return &insert_size_overflow_asm_pass.pass;
118692 +#endif
118693 +}
118694 +
118695 +// Create the noreturn report_size_overflow() function decl.
118696 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
118697 +{
118698 + tree const_char_ptr_type_node;
118699 + tree fntype;
118700 +
118701 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
118702 +
118703 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
118704 + fntype = build_function_type_list(void_type_node,
118705 + const_char_ptr_type_node,
118706 + unsigned_type_node,
118707 + const_char_ptr_type_node,
118708 + const_char_ptr_type_node,
118709 + NULL_TREE);
118710 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
118711 +
118712 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
118713 + TREE_PUBLIC(report_size_overflow_decl) = 1;
118714 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
118715 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
118716 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
118717 +}
118718 +
118719 +static unsigned int dump_functions(void)
118720 +{
118721 + struct cgraph_node *node;
118722 +
118723 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118724 + basic_block bb;
118725 +
118726 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118727 + current_function_decl = NODE_DECL(node);
118728 +
118729 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118730 +
118731 + FOR_ALL_BB_FN(bb, cfun) {
118732 + gimple_stmt_iterator si;
118733 +
118734 + fprintf(stderr, "<bb %u>:\n", bb->index);
118735 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118736 + debug_gimple_stmt(gsi_stmt(si));
118737 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118738 + debug_gimple_stmt(gsi_stmt(si));
118739 + fprintf(stderr, "\n");
118740 + }
118741 +
118742 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118743 +
118744 + pop_cfun();
118745 + current_function_decl = NULL_TREE;
118746 + }
118747 +
118748 + fprintf(stderr, "###############################################################################\n");
118749 +
118750 + return 0;
118751 +}
118752 +
118753 +#if BUILDING_GCC_VERSION >= 4009
118754 +static const struct pass_data dump_pass_data = {
118755 +#else
118756 +static struct ipa_opt_pass_d dump_pass = {
118757 + .pass = {
118758 +#endif
118759 + .type = SIMPLE_IPA_PASS,
118760 + .name = "dump",
118761 +#if BUILDING_GCC_VERSION >= 4008
118762 + .optinfo_flags = OPTGROUP_NONE,
118763 +#endif
118764 +#if BUILDING_GCC_VERSION >= 4009
118765 + .has_gate = false,
118766 + .has_execute = true,
118767 +#else
118768 + .gate = NULL,
118769 + .execute = dump_functions,
118770 + .sub = NULL,
118771 + .next = NULL,
118772 + .static_pass_number = 0,
118773 +#endif
118774 + .tv_id = TV_NONE,
118775 + .properties_required = 0,
118776 + .properties_provided = 0,
118777 + .properties_destroyed = 0,
118778 + .todo_flags_start = 0,
118779 + .todo_flags_finish = 0,
118780 +#if BUILDING_GCC_VERSION < 4009
118781 + },
118782 + .generate_summary = NULL,
118783 + .write_summary = NULL,
118784 + .read_summary = NULL,
118785 +#if BUILDING_GCC_VERSION >= 4006
118786 + .write_optimization_summary = NULL,
118787 + .read_optimization_summary = NULL,
118788 +#endif
118789 + .stmt_fixup = NULL,
118790 + .function_transform_todo_flags_start = 0,
118791 + .function_transform = NULL,
118792 + .variable_transform = NULL,
118793 +#endif
118794 +};
118795 +
118796 +#if BUILDING_GCC_VERSION >= 4009
118797 +namespace {
118798 +class dump_pass : public ipa_opt_pass_d {
118799 +public:
118800 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118801 + unsigned int execute() { return dump_functions(); }
118802 +};
118803 +}
118804 +#endif
118805 +
118806 +static struct opt_pass *make_dump_pass(void)
118807 +{
118808 +#if BUILDING_GCC_VERSION >= 4009
118809 + return new dump_pass();
118810 +#else
118811 + return &dump_pass.pass;
118812 +#endif
118813 +}
118814 +
118815 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118816 +{
118817 + int i;
118818 + const char * const plugin_name = plugin_info->base_name;
118819 + const int argc = plugin_info->argc;
118820 + const struct plugin_argument * const argv = plugin_info->argv;
118821 + bool enable = true;
118822 + struct register_pass_info insert_size_overflow_asm_pass_info;
118823 + struct register_pass_info __unused dump_before_pass_info;
118824 + struct register_pass_info __unused dump_after_pass_info;
118825 + struct register_pass_info ipa_pass_info;
118826 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
118827 + {
118828 + .base = &report_size_overflow_decl,
118829 + .nelt = 1,
118830 + .stride = sizeof(report_size_overflow_decl),
118831 + .cb = &gt_ggc_mx_tree_node,
118832 + .pchw = &gt_pch_nx_tree_node
118833 + },
118834 + LAST_GGC_ROOT_TAB
118835 + };
118836 +
118837 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
118838 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
118839 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
118840 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118841 +
118842 + dump_before_pass_info.pass = make_dump_pass();
118843 + dump_before_pass_info.reference_pass_name = "increase_alignment";
118844 + dump_before_pass_info.ref_pass_instance_number = 1;
118845 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118846 +
118847 + ipa_pass_info.pass = make_ipa_pass();
118848 + ipa_pass_info.reference_pass_name = "increase_alignment";
118849 + ipa_pass_info.ref_pass_instance_number = 1;
118850 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118851 +
118852 + dump_after_pass_info.pass = make_dump_pass();
118853 + dump_after_pass_info.reference_pass_name = "increase_alignment";
118854 + dump_after_pass_info.ref_pass_instance_number = 1;
118855 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118856 +
118857 + if (!plugin_default_version_check(version, &gcc_version)) {
118858 + error(G_("incompatible gcc/plugin versions"));
118859 + return 1;
118860 + }
118861 +
118862 + for (i = 0; i < argc; ++i) {
118863 + if (!strcmp(argv[i].key, "no-size-overflow")) {
118864 + enable = false;
118865 + continue;
118866 + }
118867 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118868 + }
118869 +
118870 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
118871 + if (enable) {
118872 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
118873 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
118874 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
118875 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
118876 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
118877 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
118878 + }
118879 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
118880 +
118881 + return 0;
118882 +}
118883 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
118884 new file mode 100644
118885 index 0000000..5c0b937
118886 --- /dev/null
118887 +++ b/tools/gcc/stackleak_plugin.c
118888 @@ -0,0 +1,374 @@
118889 +/*
118890 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
118891 + * Licensed under the GPL v2
118892 + *
118893 + * Note: the choice of the license means that the compilation process is
118894 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
118895 + * but for the kernel it doesn't matter since it doesn't link against
118896 + * any of the gcc libraries
118897 + *
118898 + * gcc plugin to help implement various PaX features
118899 + *
118900 + * - track lowest stack pointer
118901 + *
118902 + * TODO:
118903 + * - initialize all local variables
118904 + *
118905 + * BUGS:
118906 + * - none known
118907 + */
118908 +
118909 +#include "gcc-common.h"
118910 +
118911 +int plugin_is_GPL_compatible;
118912 +
118913 +static int track_frame_size = -1;
118914 +static const char track_function[] = "pax_track_stack";
118915 +static const char check_function[] = "pax_check_alloca";
118916 +static tree track_function_decl, check_function_decl;
118917 +static bool init_locals;
118918 +
118919 +static struct plugin_info stackleak_plugin_info = {
118920 + .version = "201402131920",
118921 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
118922 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
118923 +};
118924 +
118925 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
118926 +{
118927 + gimple check_alloca;
118928 + tree alloca_size;
118929 +
118930 + // insert call to void pax_check_alloca(unsigned long size)
118931 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
118932 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
118933 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
118934 +}
118935 +
118936 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
118937 +{
118938 + gimple track_stack;
118939 +
118940 + // insert call to void pax_track_stack(void)
118941 + track_stack = gimple_build_call(track_function_decl, 0);
118942 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
118943 +}
118944 +
118945 +static bool is_alloca(gimple stmt)
118946 +{
118947 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
118948 + return true;
118949 +
118950 +#if BUILDING_GCC_VERSION >= 4007
118951 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
118952 + return true;
118953 +#endif
118954 +
118955 + return false;
118956 +}
118957 +
118958 +static unsigned int execute_stackleak_tree_instrument(void)
118959 +{
118960 + basic_block bb, entry_bb;
118961 + bool prologue_instrumented = false, is_leaf = true;
118962 +
118963 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
118964 +
118965 + // 1. loop through BBs and GIMPLE statements
118966 + FOR_EACH_BB_FN(bb, cfun) {
118967 + gimple_stmt_iterator gsi;
118968 +
118969 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118970 + gimple stmt;
118971 +
118972 + stmt = gsi_stmt(gsi);
118973 +
118974 + if (is_gimple_call(stmt))
118975 + is_leaf = false;
118976 +
118977 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
118978 + if (!is_alloca(stmt))
118979 + continue;
118980 +
118981 + // 2. insert stack overflow check before each __builtin_alloca call
118982 + stackleak_check_alloca(&gsi);
118983 +
118984 + // 3. insert track call after each __builtin_alloca call
118985 + stackleak_add_instrumentation(&gsi);
118986 + if (bb == entry_bb)
118987 + prologue_instrumented = true;
118988 + }
118989 + }
118990 +
118991 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
118992 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
118993 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
118994 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
118995 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
118996 + return 0;
118997 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
118998 + return 0;
118999 +
119000 + // 4. insert track call at the beginning
119001 + if (!prologue_instrumented) {
119002 + gimple_stmt_iterator gsi;
119003 +
119004 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
119005 + if (dom_info_available_p(CDI_DOMINATORS))
119006 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
119007 + gsi = gsi_start_bb(bb);
119008 + stackleak_add_instrumentation(&gsi);
119009 + }
119010 +
119011 + return 0;
119012 +}
119013 +
119014 +static unsigned int execute_stackleak_final(void)
119015 +{
119016 + rtx insn, next;
119017 +
119018 + if (cfun->calls_alloca)
119019 + return 0;
119020 +
119021 + // keep calls only if function frame is big enough
119022 + if (get_frame_size() >= track_frame_size)
119023 + return 0;
119024 +
119025 + // 1. find pax_track_stack calls
119026 + for (insn = get_insns(); insn; insn = next) {
119027 + // 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))
119028 + rtx body;
119029 +
119030 + next = NEXT_INSN(insn);
119031 + if (!CALL_P(insn))
119032 + continue;
119033 + body = PATTERN(insn);
119034 + if (GET_CODE(body) != CALL)
119035 + continue;
119036 + body = XEXP(body, 0);
119037 + if (GET_CODE(body) != MEM)
119038 + continue;
119039 + body = XEXP(body, 0);
119040 + if (GET_CODE(body) != SYMBOL_REF)
119041 + continue;
119042 +// if (strcmp(XSTR(body, 0), track_function))
119043 + if (SYMBOL_REF_DECL(body) != track_function_decl)
119044 + continue;
119045 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
119046 + // 2. delete call
119047 + delete_insn_and_edges(insn);
119048 +#if BUILDING_GCC_VERSION >= 4007
119049 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
119050 + insn = next;
119051 + next = NEXT_INSN(insn);
119052 + delete_insn_and_edges(insn);
119053 + }
119054 +#endif
119055 + }
119056 +
119057 +// print_simple_rtl(stderr, get_insns());
119058 +// print_rtl(stderr, get_insns());
119059 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
119060 +
119061 + return 0;
119062 +}
119063 +
119064 +static bool gate_stackleak_track_stack(void)
119065 +{
119066 + return track_frame_size >= 0;
119067 +}
119068 +
119069 +static void stackleak_start_unit(void *gcc_data, void *user_data)
119070 +{
119071 + tree fntype;
119072 +
119073 + // void pax_track_stack(void)
119074 + fntype = build_function_type_list(void_type_node, NULL_TREE);
119075 + track_function_decl = build_fn_decl(track_function, fntype);
119076 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
119077 + TREE_PUBLIC(track_function_decl) = 1;
119078 + DECL_EXTERNAL(track_function_decl) = 1;
119079 + DECL_ARTIFICIAL(track_function_decl) = 1;
119080 +
119081 + // void pax_check_alloca(unsigned long)
119082 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
119083 + check_function_decl = build_fn_decl(check_function, fntype);
119084 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
119085 + TREE_PUBLIC(check_function_decl) = 1;
119086 + DECL_EXTERNAL(check_function_decl) = 1;
119087 + DECL_ARTIFICIAL(check_function_decl) = 1;
119088 +}
119089 +
119090 +#if BUILDING_GCC_VERSION >= 4009
119091 +static const struct pass_data stackleak_tree_instrument_pass_data = {
119092 +#else
119093 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
119094 + .pass = {
119095 +#endif
119096 + .type = GIMPLE_PASS,
119097 + .name = "stackleak_tree_instrument",
119098 +#if BUILDING_GCC_VERSION >= 4008
119099 + .optinfo_flags = OPTGROUP_NONE,
119100 +#endif
119101 +#if BUILDING_GCC_VERSION >= 4009
119102 + .has_gate = true,
119103 + .has_execute = true,
119104 +#else
119105 + .gate = gate_stackleak_track_stack,
119106 + .execute = execute_stackleak_tree_instrument,
119107 + .sub = NULL,
119108 + .next = NULL,
119109 + .static_pass_number = 0,
119110 +#endif
119111 + .tv_id = TV_NONE,
119112 + .properties_required = PROP_gimple_leh | PROP_cfg,
119113 + .properties_provided = 0,
119114 + .properties_destroyed = 0,
119115 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
119116 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
119117 +#if BUILDING_GCC_VERSION < 4009
119118 + }
119119 +#endif
119120 +};
119121 +
119122 +#if BUILDING_GCC_VERSION >= 4009
119123 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
119124 +#else
119125 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
119126 + .pass = {
119127 +#endif
119128 + .type = RTL_PASS,
119129 + .name = "stackleak_final",
119130 +#if BUILDING_GCC_VERSION >= 4008
119131 + .optinfo_flags = OPTGROUP_NONE,
119132 +#endif
119133 +#if BUILDING_GCC_VERSION >= 4009
119134 + .has_gate = true,
119135 + .has_execute = true,
119136 +#else
119137 + .gate = gate_stackleak_track_stack,
119138 + .execute = execute_stackleak_final,
119139 + .sub = NULL,
119140 + .next = NULL,
119141 + .static_pass_number = 0,
119142 +#endif
119143 + .tv_id = TV_NONE,
119144 + .properties_required = 0,
119145 + .properties_provided = 0,
119146 + .properties_destroyed = 0,
119147 + .todo_flags_start = 0,
119148 + .todo_flags_finish = TODO_dump_func
119149 +#if BUILDING_GCC_VERSION < 4009
119150 + }
119151 +#endif
119152 +};
119153 +
119154 +#if BUILDING_GCC_VERSION >= 4009
119155 +namespace {
119156 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
119157 +public:
119158 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
119159 + bool gate() { return gate_stackleak_track_stack(); }
119160 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
119161 +};
119162 +
119163 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
119164 +public:
119165 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
119166 + bool gate() { return gate_stackleak_track_stack(); }
119167 + unsigned int execute() { return execute_stackleak_final(); }
119168 +};
119169 +}
119170 +#endif
119171 +
119172 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
119173 +{
119174 +#if BUILDING_GCC_VERSION >= 4009
119175 + return new stackleak_tree_instrument_pass();
119176 +#else
119177 + return &stackleak_tree_instrument_pass.pass;
119178 +#endif
119179 +}
119180 +
119181 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
119182 +{
119183 +#if BUILDING_GCC_VERSION >= 4009
119184 + return new stackleak_final_rtl_opt_pass();
119185 +#else
119186 + return &stackleak_final_rtl_opt_pass.pass;
119187 +#endif
119188 +}
119189 +
119190 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119191 +{
119192 + const char * const plugin_name = plugin_info->base_name;
119193 + const int argc = plugin_info->argc;
119194 + const struct plugin_argument * const argv = plugin_info->argv;
119195 + int i;
119196 + struct register_pass_info stackleak_tree_instrument_pass_info;
119197 + struct register_pass_info stackleak_final_pass_info;
119198 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
119199 + {
119200 + .base = &track_function_decl,
119201 + .nelt = 1,
119202 + .stride = sizeof(track_function_decl),
119203 + .cb = &gt_ggc_mx_tree_node,
119204 + .pchw = &gt_pch_nx_tree_node
119205 + },
119206 + {
119207 + .base = &check_function_decl,
119208 + .nelt = 1,
119209 + .stride = sizeof(check_function_decl),
119210 + .cb = &gt_ggc_mx_tree_node,
119211 + .pchw = &gt_pch_nx_tree_node
119212 + },
119213 + LAST_GGC_ROOT_TAB
119214 + };
119215 +
119216 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
119217 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
119218 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
119219 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
119220 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119221 +
119222 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
119223 + stackleak_final_pass_info.reference_pass_name = "final";
119224 + stackleak_final_pass_info.ref_pass_instance_number = 1;
119225 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119226 +
119227 + if (!plugin_default_version_check(version, &gcc_version)) {
119228 + error(G_("incompatible gcc/plugin versions"));
119229 + return 1;
119230 + }
119231 +
119232 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
119233 +
119234 + for (i = 0; i < argc; ++i) {
119235 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
119236 + if (!argv[i].value) {
119237 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119238 + continue;
119239 + }
119240 + track_frame_size = atoi(argv[i].value);
119241 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
119242 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119243 + continue;
119244 + }
119245 + if (!strcmp(argv[i].key, "initialize-locals")) {
119246 + if (argv[i].value) {
119247 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119248 + continue;
119249 + }
119250 + init_locals = true;
119251 + continue;
119252 + }
119253 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119254 + }
119255 +
119256 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
119257 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
119258 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
119259 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
119260 +
119261 + return 0;
119262 +}
119263 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
119264 new file mode 100644
119265 index 0000000..796569a
119266 --- /dev/null
119267 +++ b/tools/gcc/structleak_plugin.c
119268 @@ -0,0 +1,273 @@
119269 +/*
119270 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
119271 + * Licensed under the GPL v2
119272 + *
119273 + * Note: the choice of the license means that the compilation process is
119274 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
119275 + * but for the kernel it doesn't matter since it doesn't link against
119276 + * any of the gcc libraries
119277 + *
119278 + * gcc plugin to forcibly initialize certain local variables that could
119279 + * otherwise leak kernel stack to userland if they aren't properly initialized
119280 + * by later code
119281 + *
119282 + * Homepage: http://pax.grsecurity.net/
119283 + *
119284 + * Usage:
119285 + * $ # for 4.5/4.6/C based 4.7
119286 + * $ 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
119287 + * $ # for C++ based 4.7/4.8+
119288 + * $ 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
119289 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
119290 + *
119291 + * TODO: eliminate redundant initializers
119292 + * increase type coverage
119293 + */
119294 +
119295 +#include "gcc-common.h"
119296 +
119297 +// unused C type flag in all versions 4.5-4.9
119298 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
119299 +
119300 +int plugin_is_GPL_compatible;
119301 +
119302 +static struct plugin_info structleak_plugin_info = {
119303 + .version = "201401260140",
119304 + .help = "disable\tdo not activate plugin\n",
119305 +};
119306 +
119307 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
119308 +{
119309 + *no_add_attrs = true;
119310 +
119311 + // check for types? for now accept everything linux has to offer
119312 + if (TREE_CODE(*node) != FIELD_DECL)
119313 + return NULL_TREE;
119314 +
119315 + *no_add_attrs = false;
119316 + return NULL_TREE;
119317 +}
119318 +
119319 +static struct attribute_spec user_attr = {
119320 + .name = "user",
119321 + .min_length = 0,
119322 + .max_length = 0,
119323 + .decl_required = false,
119324 + .type_required = false,
119325 + .function_type_required = false,
119326 + .handler = handle_user_attribute,
119327 +#if BUILDING_GCC_VERSION >= 4007
119328 + .affects_type_identity = true
119329 +#endif
119330 +};
119331 +
119332 +static void register_attributes(void *event_data, void *data)
119333 +{
119334 + register_attribute(&user_attr);
119335 +// register_attribute(&force_attr);
119336 +}
119337 +
119338 +static tree get_field_type(tree field)
119339 +{
119340 + return strip_array_types(TREE_TYPE(field));
119341 +}
119342 +
119343 +static bool is_userspace_type(tree type)
119344 +{
119345 + tree field;
119346 +
119347 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
119348 + tree fieldtype = get_field_type(field);
119349 + enum tree_code code = TREE_CODE(fieldtype);
119350 +
119351 + if (code == RECORD_TYPE || code == UNION_TYPE)
119352 + if (is_userspace_type(fieldtype))
119353 + return true;
119354 +
119355 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
119356 + return true;
119357 + }
119358 + return false;
119359 +}
119360 +
119361 +static void finish_type(void *event_data, void *data)
119362 +{
119363 + tree type = (tree)event_data;
119364 +
119365 + if (TYPE_USERSPACE(type))
119366 + return;
119367 +
119368 + if (is_userspace_type(type))
119369 + TYPE_USERSPACE(type) = 1;
119370 +}
119371 +
119372 +static void initialize(tree var)
119373 +{
119374 + basic_block bb;
119375 + gimple_stmt_iterator gsi;
119376 + tree initializer;
119377 + gimple init_stmt;
119378 +
119379 + // this is the original entry bb before the forced split
119380 + // TODO: check further BBs in case more splits occured before us
119381 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
119382 +
119383 + // first check if the variable is already initialized, warn otherwise
119384 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
119385 + gimple stmt = gsi_stmt(gsi);
119386 + tree rhs1;
119387 +
119388 + // we're looking for an assignment of a single rhs...
119389 + if (!gimple_assign_single_p(stmt))
119390 + continue;
119391 + rhs1 = gimple_assign_rhs1(stmt);
119392 +#if BUILDING_GCC_VERSION >= 4007
119393 + // ... of a non-clobbering expression...
119394 + if (TREE_CLOBBER_P(rhs1))
119395 + continue;
119396 +#endif
119397 + // ... to our variable...
119398 + if (gimple_get_lhs(stmt) != var)
119399 + continue;
119400 + // if it's an initializer then we're good
119401 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
119402 + return;
119403 + }
119404 +
119405 + // these aren't the 0days you're looking for
119406 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
119407 +
119408 + // build the initializer expression
119409 + initializer = build_constructor(TREE_TYPE(var), NULL);
119410 +
119411 + // build the initializer stmt
119412 + init_stmt = gimple_build_assign(var, initializer);
119413 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
119414 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
119415 + update_stmt(init_stmt);
119416 +}
119417 +
119418 +static unsigned int handle_function(void)
119419 +{
119420 + basic_block bb;
119421 + unsigned int ret = 0;
119422 + tree var;
119423 + unsigned int i;
119424 +
119425 + // split the first bb where we can put the forced initializers
119426 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
119427 + if (dom_info_available_p(CDI_DOMINATORS))
119428 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
119429 +
119430 + // enumarate all local variables and forcibly initialize our targets
119431 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
119432 + tree type = TREE_TYPE(var);
119433 +
119434 + gcc_assert(DECL_P(var));
119435 + if (!auto_var_in_fn_p(var, current_function_decl))
119436 + continue;
119437 +
119438 + // only care about structure types
119439 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
119440 + continue;
119441 +
119442 + // if the type is of interest, examine the variable
119443 + if (TYPE_USERSPACE(type))
119444 + initialize(var);
119445 + }
119446 +
119447 + return ret;
119448 +}
119449 +
119450 +#if BUILDING_GCC_VERSION >= 4009
119451 +static const struct pass_data structleak_pass_data = {
119452 +#else
119453 +static struct gimple_opt_pass structleak_pass = {
119454 + .pass = {
119455 +#endif
119456 + .type = GIMPLE_PASS,
119457 + .name = "structleak",
119458 +#if BUILDING_GCC_VERSION >= 4008
119459 + .optinfo_flags = OPTGROUP_NONE,
119460 +#endif
119461 +#if BUILDING_GCC_VERSION >= 4009
119462 + .has_gate = false,
119463 + .has_execute = true,
119464 +#else
119465 + .gate = NULL,
119466 + .execute = handle_function,
119467 + .sub = NULL,
119468 + .next = NULL,
119469 + .static_pass_number = 0,
119470 +#endif
119471 + .tv_id = TV_NONE,
119472 + .properties_required = PROP_cfg,
119473 + .properties_provided = 0,
119474 + .properties_destroyed = 0,
119475 + .todo_flags_start = 0,
119476 + .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
119477 +#if BUILDING_GCC_VERSION < 4009
119478 + }
119479 +#endif
119480 +};
119481 +
119482 +#if BUILDING_GCC_VERSION >= 4009
119483 +namespace {
119484 +class structleak_pass : public gimple_opt_pass {
119485 +public:
119486 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
119487 + unsigned int execute() { return handle_function(); }
119488 +};
119489 +}
119490 +#endif
119491 +
119492 +static struct opt_pass *make_structleak_pass(void)
119493 +{
119494 +#if BUILDING_GCC_VERSION >= 4009
119495 + return new structleak_pass();
119496 +#else
119497 + return &structleak_pass.pass;
119498 +#endif
119499 +}
119500 +
119501 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119502 +{
119503 + int i;
119504 + const char * const plugin_name = plugin_info->base_name;
119505 + const int argc = plugin_info->argc;
119506 + const struct plugin_argument * const argv = plugin_info->argv;
119507 + bool enable = true;
119508 + struct register_pass_info structleak_pass_info;
119509 +
119510 + structleak_pass_info.pass = make_structleak_pass();
119511 + structleak_pass_info.reference_pass_name = "ssa";
119512 + structleak_pass_info.ref_pass_instance_number = 1;
119513 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
119514 +
119515 + if (!plugin_default_version_check(version, &gcc_version)) {
119516 + error(G_("incompatible gcc/plugin versions"));
119517 + return 1;
119518 + }
119519 +
119520 + if (strcmp(lang_hooks.name, "GNU C")) {
119521 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
119522 + enable = false;
119523 + }
119524 +
119525 + for (i = 0; i < argc; ++i) {
119526 + if (!strcmp(argv[i].key, "disable")) {
119527 + enable = false;
119528 + continue;
119529 + }
119530 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119531 + }
119532 +
119533 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
119534 + if (enable) {
119535 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
119536 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
119537 + }
119538 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
119539 +
119540 + return 0;
119541 +}
119542 diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
119543 index 3dba0a4..97175dc 100644
119544 --- a/tools/lib/lk/Makefile
119545 +++ b/tools/lib/lk/Makefile
119546 @@ -13,7 +13,7 @@ LIB_OBJS += $(OUTPUT)debugfs.o
119547
119548 LIBFILE = liblk.a
119549
119550 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119551 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119552 EXTLIBS = -lelf -lpthread -lrt -lm
119553 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
119554 ALL_LDFLAGS = $(LDFLAGS)
119555 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
119556 index 6789d78..4afd019e 100644
119557 --- a/tools/perf/util/include/asm/alternative-asm.h
119558 +++ b/tools/perf/util/include/asm/alternative-asm.h
119559 @@ -5,4 +5,7 @@
119560
119561 #define altinstruction_entry #
119562
119563 + .macro pax_force_retaddr rip=0, reload=0
119564 + .endm
119565 +
119566 #endif
119567 diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
119568 index b003ad7..c0a02f8 100644
119569 --- a/tools/perf/util/include/linux/compiler.h
119570 +++ b/tools/perf/util/include/linux/compiler.h
119571 @@ -27,4 +27,12 @@
119572 # define __weak __attribute__((weak))
119573 #endif
119574
119575 +#ifndef __size_overflow
119576 +# define __size_overflow(...)
119577 +#endif
119578 +
119579 +#ifndef __intentional_overflow
119580 +# define __intentional_overflow(...)
119581 +#endif
119582 +
119583 #endif
119584 diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
119585 index 2d68297..39dc5bc 100644
119586 --- a/virt/kvm/ioapic.c
119587 +++ b/virt/kvm/ioapic.c
119588 @@ -306,7 +306,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq, bool line_status)
119589 BUG_ON(ioapic->rtc_status.pending_eoi != 0);
119590 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,
119591 ioapic->rtc_status.dest_map);
119592 - ioapic->rtc_status.pending_eoi = ret;
119593 + ioapic->rtc_status.pending_eoi = (ret < 0 ? 0 : ret);
119594 } else
119595 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL);
119596
119597 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
119598 index 4f588bc..a543c97 100644
119599 --- a/virt/kvm/kvm_main.c
119600 +++ b/virt/kvm/kvm_main.c
119601 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
119602
119603 static cpumask_var_t cpus_hardware_enabled;
119604 static int kvm_usage_count = 0;
119605 -static atomic_t hardware_enable_failed;
119606 +static atomic_unchecked_t hardware_enable_failed;
119607
119608 struct kmem_cache *kvm_vcpu_cache;
119609 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
119610
119611 -static __read_mostly struct preempt_ops kvm_preempt_ops;
119612 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
119613 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
119614 +static struct preempt_ops kvm_preempt_ops = {
119615 + .sched_in = kvm_sched_in,
119616 + .sched_out = kvm_sched_out,
119617 +};
119618
119619 struct dentry *kvm_debugfs_dir;
119620
119621 @@ -751,7 +756,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
119622 /* We can read the guest memory with __xxx_user() later on. */
119623 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
119624 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
119625 - !access_ok(VERIFY_WRITE,
119626 + !access_ok_noprefault(VERIFY_WRITE,
119627 (void __user *)(unsigned long)mem->userspace_addr,
119628 mem->memory_size)))
119629 goto out;
119630 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
119631
119632 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
119633 {
119634 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
119635 + int r;
119636 + unsigned long addr;
119637
119638 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
119639 + addr = gfn_to_hva(kvm, gfn);
119640 + if (kvm_is_error_hva(addr))
119641 + return -EFAULT;
119642 + r = __clear_user((void __user *)addr + offset, len);
119643 + if (r)
119644 + return -EFAULT;
119645 + mark_page_dirty(kvm, gfn);
119646 + return 0;
119647 }
119648 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
119649
119650 @@ -1872,7 +1885,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
119651 return 0;
119652 }
119653
119654 -static struct file_operations kvm_vcpu_fops = {
119655 +static file_operations_no_const kvm_vcpu_fops __read_only = {
119656 .release = kvm_vcpu_release,
119657 .unlocked_ioctl = kvm_vcpu_ioctl,
119658 #ifdef CONFIG_COMPAT
119659 @@ -2532,7 +2545,7 @@ out:
119660 }
119661 #endif
119662
119663 -static struct file_operations kvm_vm_fops = {
119664 +static file_operations_no_const kvm_vm_fops __read_only = {
119665 .release = kvm_vm_release,
119666 .unlocked_ioctl = kvm_vm_ioctl,
119667 #ifdef CONFIG_COMPAT
119668 @@ -2632,7 +2645,7 @@ out:
119669 return r;
119670 }
119671
119672 -static struct file_operations kvm_chardev_ops = {
119673 +static file_operations_no_const kvm_chardev_ops __read_only = {
119674 .unlocked_ioctl = kvm_dev_ioctl,
119675 .compat_ioctl = kvm_dev_ioctl,
119676 .llseek = noop_llseek,
119677 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
119678
119679 if (r) {
119680 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
119681 - atomic_inc(&hardware_enable_failed);
119682 + atomic_inc_unchecked(&hardware_enable_failed);
119683 printk(KERN_INFO "kvm: enabling virtualization on "
119684 "CPU%d failed\n", cpu);
119685 }
119686 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
119687
119688 kvm_usage_count++;
119689 if (kvm_usage_count == 1) {
119690 - atomic_set(&hardware_enable_failed, 0);
119691 + atomic_set_unchecked(&hardware_enable_failed, 0);
119692 on_each_cpu(hardware_enable_nolock, NULL, 1);
119693
119694 - if (atomic_read(&hardware_enable_failed)) {
119695 + if (atomic_read_unchecked(&hardware_enable_failed)) {
119696 hardware_disable_all_nolock();
119697 r = -EBUSY;
119698 }
119699 @@ -3148,7 +3161,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
119700 kvm_arch_vcpu_put(vcpu);
119701 }
119702
119703 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119704 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119705 struct module *module)
119706 {
119707 int r;
119708 @@ -3195,7 +3208,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119709 if (!vcpu_align)
119710 vcpu_align = __alignof__(struct kvm_vcpu);
119711 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
119712 - 0, NULL);
119713 + SLAB_USERCOPY, NULL);
119714 if (!kvm_vcpu_cache) {
119715 r = -ENOMEM;
119716 goto out_free_3;
119717 @@ -3205,9 +3218,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119718 if (r)
119719 goto out_free;
119720
119721 + pax_open_kernel();
119722 kvm_chardev_ops.owner = module;
119723 kvm_vm_fops.owner = module;
119724 kvm_vcpu_fops.owner = module;
119725 + pax_close_kernel();
119726
119727 r = misc_register(&kvm_dev);
119728 if (r) {
119729 @@ -3217,9 +3232,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119730
119731 register_syscore_ops(&kvm_syscore_ops);
119732
119733 - kvm_preempt_ops.sched_in = kvm_sched_in;
119734 - kvm_preempt_ops.sched_out = kvm_sched_out;
119735 -
119736 r = kvm_init_debug();
119737 if (r) {
119738 printk(KERN_ERR "kvm: create debugfs files failed\n");