]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.13.6-201403202349.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.6-201403202349.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 dfe5fec..079642c 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 c1f1a7e..554b0cd 100644
878 --- a/arch/arm/Kconfig
879 +++ b/arch/arm/Kconfig
880 @@ -1828,7 +1828,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 @@ -2100,6 +2100,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 3e8f106..a0a1fe4 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 @@ -681,7 +683,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 81c8913..81d8432 100644
6666 --- a/arch/mips/include/asm/syscall.h
6667 +++ b/arch/mips/include/asm/syscall.h
6668 @@ -29,7 +29,7 @@ static inline long syscall_get_nr(struct task_struct *task,
6669 static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
6670 struct task_struct *task, struct pt_regs *regs, unsigned int n)
6671 {
6672 - unsigned long usp = regs->regs[29];
6673 + unsigned long usp __maybe_unused = regs->regs[29];
6674
6675 switch (n) {
6676 case 0: case 1: case 2: case 3:
6677 @@ -39,14 +39,14 @@ static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
6678
6679 #ifdef CONFIG_32BIT
6680 case 4: case 5: case 6: case 7:
6681 - return get_user(*arg, (int *)usp + 4 * n);
6682 + return get_user(*arg, (int *)usp + n);
6683 #endif
6684
6685 #ifdef CONFIG_64BIT
6686 case 4: case 5: case 6: case 7:
6687 #ifdef CONFIG_MIPS32_O32
6688 if (test_thread_flag(TIF_32BIT_REGS))
6689 - return get_user(*arg, (int *)usp + 4 * n);
6690 + return get_user(*arg, (int *)usp + n);
6691 else
6692 #endif
6693 *arg = regs->regs[4 + n];
6694 @@ -83,11 +83,10 @@ static inline void syscall_get_arguments(struct task_struct *task,
6695 unsigned int i, unsigned int n,
6696 unsigned long *args)
6697 {
6698 - unsigned long arg;
6699 int ret;
6700
6701 while (n--)
6702 - ret |= mips_get_syscall_arg(&arg, task, regs, i++);
6703 + ret |= mips_get_syscall_arg(args++, task, regs, i++);
6704
6705 /*
6706 * No way to communicate an error because this is a void function.
6707 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6708 index 4f58ef6..5e7081b 100644
6709 --- a/arch/mips/include/asm/thread_info.h
6710 +++ b/arch/mips/include/asm/thread_info.h
6711 @@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6712 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6713 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6714 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6715 +/* li takes a 32bit immediate */
6716 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6717 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6718
6719 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6720 @@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6721 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6722 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6723 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6724 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6725
6726 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6727 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6728 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6729
6730 /* work to do in syscall_trace_leave() */
6731 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6732 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6733 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6734
6735 /* work to do on interrupt/exception return */
6736 #define _TIF_WORK_MASK \
6737 @@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6738 /* work to do on any return to u-space */
6739 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6740 _TIF_WORK_SYSCALL_EXIT | \
6741 - _TIF_SYSCALL_TRACEPOINT)
6742 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6743
6744 /*
6745 * We stash processor id into a COP0 register to retrieve it fast
6746 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6747 index f3fa375..3af6637 100644
6748 --- a/arch/mips/include/asm/uaccess.h
6749 +++ b/arch/mips/include/asm/uaccess.h
6750 @@ -128,6 +128,7 @@ extern u64 __ua_limit;
6751 __ok == 0; \
6752 })
6753
6754 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6755 #define access_ok(type, addr, size) \
6756 likely(__access_ok((addr), (size), __access_mask))
6757
6758 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6759 index 1188e00..41cf144 100644
6760 --- a/arch/mips/kernel/binfmt_elfn32.c
6761 +++ b/arch/mips/kernel/binfmt_elfn32.c
6762 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6763 #undef ELF_ET_DYN_BASE
6764 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6765
6766 +#ifdef CONFIG_PAX_ASLR
6767 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6768 +
6769 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6770 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6771 +#endif
6772 +
6773 #include <asm/processor.h>
6774 #include <linux/module.h>
6775 #include <linux/elfcore.h>
6776 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6777 index 202e581..689ca79 100644
6778 --- a/arch/mips/kernel/binfmt_elfo32.c
6779 +++ b/arch/mips/kernel/binfmt_elfo32.c
6780 @@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6781 #undef ELF_ET_DYN_BASE
6782 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6783
6784 +#ifdef CONFIG_PAX_ASLR
6785 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6786 +
6787 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6788 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6789 +#endif
6790 +
6791 #include <asm/processor.h>
6792
6793 /*
6794 diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c
6795 index 185ba25..374ed74 100644
6796 --- a/arch/mips/kernel/ftrace.c
6797 +++ b/arch/mips/kernel/ftrace.c
6798 @@ -111,11 +111,10 @@ static int ftrace_modify_code_2(unsigned long ip, unsigned int new_code1,
6799 safe_store_code(new_code1, ip, faulted);
6800 if (unlikely(faulted))
6801 return -EFAULT;
6802 - ip += 4;
6803 - safe_store_code(new_code2, ip, faulted);
6804 + safe_store_code(new_code2, ip + 4, faulted);
6805 if (unlikely(faulted))
6806 return -EFAULT;
6807 - flush_icache_range(ip, ip + 8); /* original ip + 12 */
6808 + flush_icache_range(ip, ip + 8);
6809 return 0;
6810 }
6811 #endif
6812 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6813 index 2b91fe8..fe4f6b4 100644
6814 --- a/arch/mips/kernel/i8259.c
6815 +++ b/arch/mips/kernel/i8259.c
6816 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6817 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6818 spurious_irq_mask |= irqmask;
6819 }
6820 - atomic_inc(&irq_err_count);
6821 + atomic_inc_unchecked(&irq_err_count);
6822 /*
6823 * Theoretically we do not have to handle this IRQ,
6824 * but in Linux this does not cause problems and is
6825 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6826 index 44a1f79..2bd6aa3 100644
6827 --- a/arch/mips/kernel/irq-gt641xx.c
6828 +++ b/arch/mips/kernel/irq-gt641xx.c
6829 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6830 }
6831 }
6832
6833 - atomic_inc(&irq_err_count);
6834 + atomic_inc_unchecked(&irq_err_count);
6835 }
6836
6837 void __init gt641xx_irq_init(void)
6838 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6839 index d1fea7a..45602ea 100644
6840 --- a/arch/mips/kernel/irq.c
6841 +++ b/arch/mips/kernel/irq.c
6842 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6843 printk("unexpected IRQ # %d\n", irq);
6844 }
6845
6846 -atomic_t irq_err_count;
6847 +atomic_unchecked_t irq_err_count;
6848
6849 int arch_show_interrupts(struct seq_file *p, int prec)
6850 {
6851 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6852 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6853 return 0;
6854 }
6855
6856 asmlinkage void spurious_interrupt(void)
6857 {
6858 - atomic_inc(&irq_err_count);
6859 + atomic_inc_unchecked(&irq_err_count);
6860 }
6861
6862 void __init init_IRQ(void)
6863 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6864 index ddc7610..8c58f17 100644
6865 --- a/arch/mips/kernel/process.c
6866 +++ b/arch/mips/kernel/process.c
6867 @@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6868 out:
6869 return pc;
6870 }
6871 -
6872 -/*
6873 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6874 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6875 - */
6876 -unsigned long arch_align_stack(unsigned long sp)
6877 -{
6878 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6879 - sp -= get_random_int() & ~PAGE_MASK;
6880 -
6881 - return sp & ALMASK;
6882 -}
6883 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6884 index b52e1d2..1a3ca09 100644
6885 --- a/arch/mips/kernel/ptrace.c
6886 +++ b/arch/mips/kernel/ptrace.c
6887 @@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6888 return ret;
6889 }
6890
6891 +#ifdef CONFIG_GRKERNSEC_SETXID
6892 +extern void gr_delayed_cred_worker(void);
6893 +#endif
6894 +
6895 /*
6896 * Notification of system call entry/exit
6897 * - triggered by current->work.syscall_trace
6898 @@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6899 tracehook_report_syscall_entry(regs))
6900 ret = -1;
6901
6902 +#ifdef CONFIG_GRKERNSEC_SETXID
6903 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6904 + gr_delayed_cred_worker();
6905 +#endif
6906 +
6907 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6908 trace_sys_enter(regs, regs->regs[2]);
6909
6910 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6911 index 07fc524..b9d7f28 100644
6912 --- a/arch/mips/kernel/reset.c
6913 +++ b/arch/mips/kernel/reset.c
6914 @@ -13,6 +13,7 @@
6915 #include <linux/reboot.h>
6916
6917 #include <asm/reboot.h>
6918 +#include <asm/bug.h>
6919
6920 /*
6921 * Urgs ... Too many MIPS machines to handle this in a generic way.
6922 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6923 {
6924 if (_machine_restart)
6925 _machine_restart(command);
6926 + BUG();
6927 }
6928
6929 void machine_halt(void)
6930 {
6931 if (_machine_halt)
6932 _machine_halt();
6933 + BUG();
6934 }
6935
6936 void machine_power_off(void)
6937 {
6938 if (pm_power_off)
6939 pm_power_off();
6940 + BUG();
6941 }
6942 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6943 index c10aa84..9ec2e60 100644
6944 --- a/arch/mips/kernel/smtc-proc.c
6945 +++ b/arch/mips/kernel/smtc-proc.c
6946 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6947
6948 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6949
6950 -atomic_t smtc_fpu_recoveries;
6951 +atomic_unchecked_t smtc_fpu_recoveries;
6952
6953 static int smtc_proc_show(struct seq_file *m, void *v)
6954 {
6955 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6956 for(i = 0; i < NR_CPUS; i++)
6957 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6958 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6959 - atomic_read(&smtc_fpu_recoveries));
6960 + atomic_read_unchecked(&smtc_fpu_recoveries));
6961 return 0;
6962 }
6963
6964 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6965 smtc_cpu_stats[i].selfipis = 0;
6966 }
6967
6968 - atomic_set(&smtc_fpu_recoveries, 0);
6969 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6970
6971 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6972 }
6973 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6974 index dfc1b91..11a2c07 100644
6975 --- a/arch/mips/kernel/smtc.c
6976 +++ b/arch/mips/kernel/smtc.c
6977 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6978 }
6979 smtc_ipi_qdump();
6980 printk("%d Recoveries of \"stolen\" FPU\n",
6981 - atomic_read(&smtc_fpu_recoveries));
6982 + atomic_read_unchecked(&smtc_fpu_recoveries));
6983 }
6984
6985
6986 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6987 index 84536bf..79caa4d 100644
6988 --- a/arch/mips/kernel/sync-r4k.c
6989 +++ b/arch/mips/kernel/sync-r4k.c
6990 @@ -21,8 +21,8 @@
6991 #include <asm/mipsregs.h>
6992
6993 static atomic_t count_start_flag = ATOMIC_INIT(0);
6994 -static atomic_t count_count_start = ATOMIC_INIT(0);
6995 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6996 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6997 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6998 static atomic_t count_reference = ATOMIC_INIT(0);
6999
7000 #define COUNTON 100
7001 @@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
7002
7003 for (i = 0; i < NR_LOOPS; i++) {
7004 /* slaves loop on '!= 2' */
7005 - while (atomic_read(&count_count_start) != 1)
7006 + while (atomic_read_unchecked(&count_count_start) != 1)
7007 mb();
7008 - atomic_set(&count_count_stop, 0);
7009 + atomic_set_unchecked(&count_count_stop, 0);
7010 smp_wmb();
7011
7012 /* this lets the slaves write their count register */
7013 - atomic_inc(&count_count_start);
7014 + atomic_inc_unchecked(&count_count_start);
7015
7016 /*
7017 * Everyone initialises count in the last loop:
7018 @@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
7019 /*
7020 * Wait for all slaves to leave the synchronization point:
7021 */
7022 - while (atomic_read(&count_count_stop) != 1)
7023 + while (atomic_read_unchecked(&count_count_stop) != 1)
7024 mb();
7025 - atomic_set(&count_count_start, 0);
7026 + atomic_set_unchecked(&count_count_start, 0);
7027 smp_wmb();
7028 - atomic_inc(&count_count_stop);
7029 + atomic_inc_unchecked(&count_count_stop);
7030 }
7031 /* Arrange for an interrupt in a short while */
7032 write_c0_compare(read_c0_count() + COUNTON);
7033 @@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
7034 initcount = atomic_read(&count_reference);
7035
7036 for (i = 0; i < NR_LOOPS; i++) {
7037 - atomic_inc(&count_count_start);
7038 - while (atomic_read(&count_count_start) != 2)
7039 + atomic_inc_unchecked(&count_count_start);
7040 + while (atomic_read_unchecked(&count_count_start) != 2)
7041 mb();
7042
7043 /*
7044 @@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
7045 if (i == NR_LOOPS-1)
7046 write_c0_count(initcount);
7047
7048 - atomic_inc(&count_count_stop);
7049 - while (atomic_read(&count_count_stop) != 2)
7050 + atomic_inc_unchecked(&count_count_stop);
7051 + while (atomic_read_unchecked(&count_count_stop) != 2)
7052 mb();
7053 }
7054 /* Arrange for an interrupt in a short while */
7055 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7056 index f9c8746..78b64e3 100644
7057 --- a/arch/mips/kernel/traps.c
7058 +++ b/arch/mips/kernel/traps.c
7059 @@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7060 siginfo_t info;
7061
7062 prev_state = exception_enter();
7063 - die_if_kernel("Integer overflow", regs);
7064 + if (unlikely(!user_mode(regs))) {
7065 +
7066 +#ifdef CONFIG_PAX_REFCOUNT
7067 + if (fixup_exception(regs)) {
7068 + pax_report_refcount_overflow(regs);
7069 + exception_exit(prev_state);
7070 + return;
7071 + }
7072 +#endif
7073 +
7074 + die("Integer overflow", regs);
7075 + }
7076
7077 info.si_code = FPE_INTOVF;
7078 info.si_signo = SIGFPE;
7079 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7080 index becc42b..9e43d4b 100644
7081 --- a/arch/mips/mm/fault.c
7082 +++ b/arch/mips/mm/fault.c
7083 @@ -28,6 +28,23 @@
7084 #include <asm/highmem.h> /* For VMALLOC_END */
7085 #include <linux/kdebug.h>
7086
7087 +#ifdef CONFIG_PAX_PAGEEXEC
7088 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7089 +{
7090 + unsigned long i;
7091 +
7092 + printk(KERN_ERR "PAX: bytes at PC: ");
7093 + for (i = 0; i < 5; i++) {
7094 + unsigned int c;
7095 + if (get_user(c, (unsigned int *)pc+i))
7096 + printk(KERN_CONT "???????? ");
7097 + else
7098 + printk(KERN_CONT "%08x ", c);
7099 + }
7100 + printk("\n");
7101 +}
7102 +#endif
7103 +
7104 /*
7105 * This routine handles page faults. It determines the address,
7106 * and the problem, and then passes it off to one of the appropriate
7107 @@ -199,6 +216,14 @@ bad_area:
7108 bad_area_nosemaphore:
7109 /* User mode accesses just cause a SIGSEGV */
7110 if (user_mode(regs)) {
7111 +
7112 +#ifdef CONFIG_PAX_PAGEEXEC
7113 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7114 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7115 + do_group_exit(SIGKILL);
7116 + }
7117 +#endif
7118 +
7119 tsk->thread.cp0_badvaddr = address;
7120 tsk->thread.error_code = write;
7121 #if 0
7122 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7123 index f1baadd..5472dca 100644
7124 --- a/arch/mips/mm/mmap.c
7125 +++ b/arch/mips/mm/mmap.c
7126 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7127 struct vm_area_struct *vma;
7128 unsigned long addr = addr0;
7129 int do_color_align;
7130 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7131 struct vm_unmapped_area_info info;
7132
7133 if (unlikely(len > TASK_SIZE))
7134 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7135 do_color_align = 1;
7136
7137 /* requesting a specific address */
7138 +
7139 +#ifdef CONFIG_PAX_RANDMMAP
7140 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7141 +#endif
7142 +
7143 if (addr) {
7144 if (do_color_align)
7145 addr = COLOUR_ALIGN(addr, pgoff);
7146 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7147 addr = PAGE_ALIGN(addr);
7148
7149 vma = find_vma(mm, addr);
7150 - if (TASK_SIZE - len >= addr &&
7151 - (!vma || addr + len <= vma->vm_start))
7152 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7153 return addr;
7154 }
7155
7156 info.length = len;
7157 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7158 info.align_offset = pgoff << PAGE_SHIFT;
7159 + info.threadstack_offset = offset;
7160
7161 if (dir == DOWN) {
7162 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7163 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7164 {
7165 unsigned long random_factor = 0UL;
7166
7167 +#ifdef CONFIG_PAX_RANDMMAP
7168 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7169 +#endif
7170 +
7171 if (current->flags & PF_RANDOMIZE) {
7172 random_factor = get_random_int();
7173 random_factor = random_factor << PAGE_SHIFT;
7174 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7175
7176 if (mmap_is_legacy()) {
7177 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7178 +
7179 +#ifdef CONFIG_PAX_RANDMMAP
7180 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7181 + mm->mmap_base += mm->delta_mmap;
7182 +#endif
7183 +
7184 mm->get_unmapped_area = arch_get_unmapped_area;
7185 } else {
7186 mm->mmap_base = mmap_base(random_factor);
7187 +
7188 +#ifdef CONFIG_PAX_RANDMMAP
7189 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7190 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7191 +#endif
7192 +
7193 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7194 }
7195 }
7196
7197 -static inline unsigned long brk_rnd(void)
7198 -{
7199 - unsigned long rnd = get_random_int();
7200 -
7201 - rnd = rnd << PAGE_SHIFT;
7202 - /* 8MB for 32bit, 256MB for 64bit */
7203 - if (TASK_IS_32BIT_ADDR)
7204 - rnd = rnd & 0x7ffffful;
7205 - else
7206 - rnd = rnd & 0xffffffful;
7207 -
7208 - return rnd;
7209 -}
7210 -
7211 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7212 -{
7213 - unsigned long base = mm->brk;
7214 - unsigned long ret;
7215 -
7216 - ret = PAGE_ALIGN(base + brk_rnd());
7217 -
7218 - if (ret < mm->brk)
7219 - return mm->brk;
7220 -
7221 - return ret;
7222 -}
7223 -
7224 int __virt_addr_valid(const volatile void *kaddr)
7225 {
7226 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7227 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7228 index 59cccd9..f39ac2f 100644
7229 --- a/arch/mips/pci/pci-octeon.c
7230 +++ b/arch/mips/pci/pci-octeon.c
7231 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7232
7233
7234 static struct pci_ops octeon_pci_ops = {
7235 - octeon_read_config,
7236 - octeon_write_config,
7237 + .read = octeon_read_config,
7238 + .write = octeon_write_config,
7239 };
7240
7241 static struct resource octeon_pci_mem_resource = {
7242 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7243 index 5e36c33..eb4a17b 100644
7244 --- a/arch/mips/pci/pcie-octeon.c
7245 +++ b/arch/mips/pci/pcie-octeon.c
7246 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7247 }
7248
7249 static struct pci_ops octeon_pcie0_ops = {
7250 - octeon_pcie0_read_config,
7251 - octeon_pcie0_write_config,
7252 + .read = octeon_pcie0_read_config,
7253 + .write = octeon_pcie0_write_config,
7254 };
7255
7256 static struct resource octeon_pcie0_mem_resource = {
7257 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7258 };
7259
7260 static struct pci_ops octeon_pcie1_ops = {
7261 - octeon_pcie1_read_config,
7262 - octeon_pcie1_write_config,
7263 + .read = octeon_pcie1_read_config,
7264 + .write = octeon_pcie1_write_config,
7265 };
7266
7267 static struct resource octeon_pcie1_mem_resource = {
7268 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7269 };
7270
7271 static struct pci_ops octeon_dummy_ops = {
7272 - octeon_dummy_read_config,
7273 - octeon_dummy_write_config,
7274 + .read = octeon_dummy_read_config,
7275 + .write = octeon_dummy_write_config,
7276 };
7277
7278 static struct resource octeon_dummy_mem_resource = {
7279 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7280 index a2358b4..7cead4f 100644
7281 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7282 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7283 @@ -187,9 +187,9 @@ void
7284 cont_nmi_dump(void)
7285 {
7286 #ifndef REAL_NMI_SIGNAL
7287 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7288 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7289
7290 - atomic_inc(&nmied_cpus);
7291 + atomic_inc_unchecked(&nmied_cpus);
7292 #endif
7293 /*
7294 * Only allow 1 cpu to proceed
7295 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7296 udelay(10000);
7297 }
7298 #else
7299 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7300 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7301 #endif
7302
7303 /*
7304 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7305 index a046b30..6799527 100644
7306 --- a/arch/mips/sni/rm200.c
7307 +++ b/arch/mips/sni/rm200.c
7308 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7309 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7310 spurious_irq_mask |= irqmask;
7311 }
7312 - atomic_inc(&irq_err_count);
7313 + atomic_inc_unchecked(&irq_err_count);
7314 /*
7315 * Theoretically we do not have to handle this IRQ,
7316 * but in Linux this does not cause problems and is
7317 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7318 index 41e873b..34d33a7 100644
7319 --- a/arch/mips/vr41xx/common/icu.c
7320 +++ b/arch/mips/vr41xx/common/icu.c
7321 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7322
7323 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7324
7325 - atomic_inc(&irq_err_count);
7326 + atomic_inc_unchecked(&irq_err_count);
7327
7328 return -1;
7329 }
7330 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7331 index ae0e4ee..e8f0692 100644
7332 --- a/arch/mips/vr41xx/common/irq.c
7333 +++ b/arch/mips/vr41xx/common/irq.c
7334 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7335 irq_cascade_t *cascade;
7336
7337 if (irq >= NR_IRQS) {
7338 - atomic_inc(&irq_err_count);
7339 + atomic_inc_unchecked(&irq_err_count);
7340 return;
7341 }
7342
7343 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7344 ret = cascade->get_irq(irq);
7345 irq = ret;
7346 if (ret < 0)
7347 - atomic_inc(&irq_err_count);
7348 + atomic_inc_unchecked(&irq_err_count);
7349 else
7350 irq_dispatch(irq);
7351 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7352 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7353 index 967d144..db12197 100644
7354 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7355 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7356 @@ -11,12 +11,14 @@
7357 #ifndef _ASM_PROC_CACHE_H
7358 #define _ASM_PROC_CACHE_H
7359
7360 +#include <linux/const.h>
7361 +
7362 /* L1 cache */
7363
7364 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7365 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7366 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7367 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7368 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7369 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7370
7371 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7372 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7373 index bcb5df2..84fabd2 100644
7374 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7375 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7376 @@ -16,13 +16,15 @@
7377 #ifndef _ASM_PROC_CACHE_H
7378 #define _ASM_PROC_CACHE_H
7379
7380 +#include <linux/const.h>
7381 +
7382 /*
7383 * L1 cache
7384 */
7385 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7386 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7387 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7388 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7389 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7390 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7391
7392 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7393 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7394 index 4ce7a01..449202a 100644
7395 --- a/arch/openrisc/include/asm/cache.h
7396 +++ b/arch/openrisc/include/asm/cache.h
7397 @@ -19,11 +19,13 @@
7398 #ifndef __ASM_OPENRISC_CACHE_H
7399 #define __ASM_OPENRISC_CACHE_H
7400
7401 +#include <linux/const.h>
7402 +
7403 /* FIXME: How can we replace these with values from the CPU...
7404 * they shouldn't be hard-coded!
7405 */
7406
7407 -#define L1_CACHE_BYTES 16
7408 #define L1_CACHE_SHIFT 4
7409 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7410
7411 #endif /* __ASM_OPENRISC_CACHE_H */
7412 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7413 index 472886c..00e7df9 100644
7414 --- a/arch/parisc/include/asm/atomic.h
7415 +++ b/arch/parisc/include/asm/atomic.h
7416 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7417 return dec;
7418 }
7419
7420 +#define atomic64_read_unchecked(v) atomic64_read(v)
7421 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7422 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7423 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7424 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7425 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7426 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7427 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7428 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7429 +
7430 #endif /* !CONFIG_64BIT */
7431
7432
7433 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7434 index 47f11c7..3420df2 100644
7435 --- a/arch/parisc/include/asm/cache.h
7436 +++ b/arch/parisc/include/asm/cache.h
7437 @@ -5,6 +5,7 @@
7438 #ifndef __ARCH_PARISC_CACHE_H
7439 #define __ARCH_PARISC_CACHE_H
7440
7441 +#include <linux/const.h>
7442
7443 /*
7444 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7445 @@ -15,13 +16,13 @@
7446 * just ruin performance.
7447 */
7448 #ifdef CONFIG_PA20
7449 -#define L1_CACHE_BYTES 64
7450 #define L1_CACHE_SHIFT 6
7451 #else
7452 -#define L1_CACHE_BYTES 32
7453 #define L1_CACHE_SHIFT 5
7454 #endif
7455
7456 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7457 +
7458 #ifndef __ASSEMBLY__
7459
7460 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7461 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7462 index ad2b503..bdf1651 100644
7463 --- a/arch/parisc/include/asm/elf.h
7464 +++ b/arch/parisc/include/asm/elf.h
7465 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7466
7467 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7468
7469 +#ifdef CONFIG_PAX_ASLR
7470 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7471 +
7472 +#define PAX_DELTA_MMAP_LEN 16
7473 +#define PAX_DELTA_STACK_LEN 16
7474 +#endif
7475 +
7476 /* This yields a mask that user programs can use to figure out what
7477 instruction set this CPU supports. This could be done in user space,
7478 but it's not easy, and we've already done it here. */
7479 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7480 index f213f5b..0af3e8e 100644
7481 --- a/arch/parisc/include/asm/pgalloc.h
7482 +++ b/arch/parisc/include/asm/pgalloc.h
7483 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7484 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7485 }
7486
7487 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7488 +{
7489 + pgd_populate(mm, pgd, pmd);
7490 +}
7491 +
7492 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7493 {
7494 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7495 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7496 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7497 #define pmd_free(mm, x) do { } while (0)
7498 #define pgd_populate(mm, pmd, pte) BUG()
7499 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7500
7501 #endif
7502
7503 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7504 index 34899b5..02dd060 100644
7505 --- a/arch/parisc/include/asm/pgtable.h
7506 +++ b/arch/parisc/include/asm/pgtable.h
7507 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7508 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7509 #define PAGE_COPY PAGE_EXECREAD
7510 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7511 +
7512 +#ifdef CONFIG_PAX_PAGEEXEC
7513 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7514 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7515 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7516 +#else
7517 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7518 +# define PAGE_COPY_NOEXEC PAGE_COPY
7519 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7520 +#endif
7521 +
7522 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7523 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7524 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7525 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7526 index 4006964..fcb3cc2 100644
7527 --- a/arch/parisc/include/asm/uaccess.h
7528 +++ b/arch/parisc/include/asm/uaccess.h
7529 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7530 const void __user *from,
7531 unsigned long n)
7532 {
7533 - int sz = __compiletime_object_size(to);
7534 + size_t sz = __compiletime_object_size(to);
7535 int ret = -EFAULT;
7536
7537 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7538 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7539 ret = __copy_from_user(to, from, n);
7540 else
7541 copy_from_user_overflow();
7542 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7543 index 50dfafc..b9fc230 100644
7544 --- a/arch/parisc/kernel/module.c
7545 +++ b/arch/parisc/kernel/module.c
7546 @@ -98,16 +98,38 @@
7547
7548 /* three functions to determine where in the module core
7549 * or init pieces the location is */
7550 +static inline int in_init_rx(struct module *me, void *loc)
7551 +{
7552 + return (loc >= me->module_init_rx &&
7553 + loc < (me->module_init_rx + me->init_size_rx));
7554 +}
7555 +
7556 +static inline int in_init_rw(struct module *me, void *loc)
7557 +{
7558 + return (loc >= me->module_init_rw &&
7559 + loc < (me->module_init_rw + me->init_size_rw));
7560 +}
7561 +
7562 static inline int in_init(struct module *me, void *loc)
7563 {
7564 - return (loc >= me->module_init &&
7565 - loc <= (me->module_init + me->init_size));
7566 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7567 +}
7568 +
7569 +static inline int in_core_rx(struct module *me, void *loc)
7570 +{
7571 + return (loc >= me->module_core_rx &&
7572 + loc < (me->module_core_rx + me->core_size_rx));
7573 +}
7574 +
7575 +static inline int in_core_rw(struct module *me, void *loc)
7576 +{
7577 + return (loc >= me->module_core_rw &&
7578 + loc < (me->module_core_rw + me->core_size_rw));
7579 }
7580
7581 static inline int in_core(struct module *me, void *loc)
7582 {
7583 - return (loc >= me->module_core &&
7584 - loc <= (me->module_core + me->core_size));
7585 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7586 }
7587
7588 static inline int in_local(struct module *me, void *loc)
7589 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7590 }
7591
7592 /* align things a bit */
7593 - me->core_size = ALIGN(me->core_size, 16);
7594 - me->arch.got_offset = me->core_size;
7595 - me->core_size += gots * sizeof(struct got_entry);
7596 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7597 + me->arch.got_offset = me->core_size_rw;
7598 + me->core_size_rw += gots * sizeof(struct got_entry);
7599
7600 - me->core_size = ALIGN(me->core_size, 16);
7601 - me->arch.fdesc_offset = me->core_size;
7602 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7603 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7604 + me->arch.fdesc_offset = me->core_size_rw;
7605 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7606
7607 me->arch.got_max = gots;
7608 me->arch.fdesc_max = fdescs;
7609 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7610
7611 BUG_ON(value == 0);
7612
7613 - got = me->module_core + me->arch.got_offset;
7614 + got = me->module_core_rw + me->arch.got_offset;
7615 for (i = 0; got[i].addr; i++)
7616 if (got[i].addr == value)
7617 goto out;
7618 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7619 #ifdef CONFIG_64BIT
7620 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7621 {
7622 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7623 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7624
7625 if (!value) {
7626 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7627 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7628
7629 /* Create new one */
7630 fdesc->addr = value;
7631 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7632 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7633 return (Elf_Addr)fdesc;
7634 }
7635 #endif /* CONFIG_64BIT */
7636 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7637
7638 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7639 end = table + sechdrs[me->arch.unwind_section].sh_size;
7640 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7641 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7642
7643 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7644 me->arch.unwind_section, table, end, gp);
7645 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7646 index 0d3a9d4..20a99b0 100644
7647 --- a/arch/parisc/kernel/sys_parisc.c
7648 +++ b/arch/parisc/kernel/sys_parisc.c
7649 @@ -33,9 +33,11 @@
7650 #include <linux/utsname.h>
7651 #include <linux/personality.h>
7652
7653 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7654 +static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7655 + unsigned long flags)
7656 {
7657 struct vm_unmapped_area_info info;
7658 + unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7659
7660 info.flags = 0;
7661 info.length = len;
7662 @@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7663 info.high_limit = TASK_SIZE;
7664 info.align_mask = 0;
7665 info.align_offset = 0;
7666 + info.threadstack_offset = offset;
7667 return vm_unmapped_area(&info);
7668 }
7669
7670 @@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7671 }
7672
7673 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7674 - unsigned long len, unsigned long pgoff)
7675 + unsigned long len, unsigned long pgoff, unsigned long flags)
7676 {
7677 struct vm_unmapped_area_info info;
7678 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7679
7680 info.flags = 0;
7681 info.length = len;
7682 @@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7683 info.high_limit = TASK_SIZE;
7684 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7685 info.align_offset = shared_align_offset(filp, pgoff);
7686 + info.threadstack_offset = offset;
7687 return vm_unmapped_area(&info);
7688 }
7689
7690 @@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7691 return -EINVAL;
7692 return addr;
7693 }
7694 - if (!addr)
7695 + if (!addr) {
7696 addr = TASK_UNMAPPED_BASE;
7697
7698 +#ifdef CONFIG_PAX_RANDMMAP
7699 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7700 + addr += current->mm->delta_mmap;
7701 +#endif
7702 +
7703 + }
7704 +
7705 if (filp || (flags & MAP_SHARED))
7706 - addr = get_shared_area(filp, addr, len, pgoff);
7707 + addr = get_shared_area(filp, addr, len, pgoff, flags);
7708 else
7709 - addr = get_unshared_area(addr, len);
7710 + addr = get_unshared_area(addr, len, flags);
7711
7712 return addr;
7713 }
7714 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7715 index 1cd1d0c..44ec918 100644
7716 --- a/arch/parisc/kernel/traps.c
7717 +++ b/arch/parisc/kernel/traps.c
7718 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7719
7720 down_read(&current->mm->mmap_sem);
7721 vma = find_vma(current->mm,regs->iaoq[0]);
7722 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7723 - && (vma->vm_flags & VM_EXEC)) {
7724 -
7725 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7726 fault_address = regs->iaoq[0];
7727 fault_space = regs->iasq[0];
7728
7729 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7730 index 9d08c71..e2b4d20 100644
7731 --- a/arch/parisc/mm/fault.c
7732 +++ b/arch/parisc/mm/fault.c
7733 @@ -15,6 +15,7 @@
7734 #include <linux/sched.h>
7735 #include <linux/interrupt.h>
7736 #include <linux/module.h>
7737 +#include <linux/unistd.h>
7738
7739 #include <asm/uaccess.h>
7740 #include <asm/traps.h>
7741 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7742 static unsigned long
7743 parisc_acctyp(unsigned long code, unsigned int inst)
7744 {
7745 - if (code == 6 || code == 16)
7746 + if (code == 6 || code == 7 || code == 16)
7747 return VM_EXEC;
7748
7749 switch (inst & 0xf0000000) {
7750 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7751 }
7752 #endif
7753
7754 +#ifdef CONFIG_PAX_PAGEEXEC
7755 +/*
7756 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7757 + *
7758 + * returns 1 when task should be killed
7759 + * 2 when rt_sigreturn trampoline was detected
7760 + * 3 when unpatched PLT trampoline was detected
7761 + */
7762 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7763 +{
7764 +
7765 +#ifdef CONFIG_PAX_EMUPLT
7766 + int err;
7767 +
7768 + do { /* PaX: unpatched PLT emulation */
7769 + unsigned int bl, depwi;
7770 +
7771 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7772 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7773 +
7774 + if (err)
7775 + break;
7776 +
7777 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7778 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7779 +
7780 + err = get_user(ldw, (unsigned int *)addr);
7781 + err |= get_user(bv, (unsigned int *)(addr+4));
7782 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7783 +
7784 + if (err)
7785 + break;
7786 +
7787 + if (ldw == 0x0E801096U &&
7788 + bv == 0xEAC0C000U &&
7789 + ldw2 == 0x0E881095U)
7790 + {
7791 + unsigned int resolver, map;
7792 +
7793 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7794 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7795 + if (err)
7796 + break;
7797 +
7798 + regs->gr[20] = instruction_pointer(regs)+8;
7799 + regs->gr[21] = map;
7800 + regs->gr[22] = resolver;
7801 + regs->iaoq[0] = resolver | 3UL;
7802 + regs->iaoq[1] = regs->iaoq[0] + 4;
7803 + return 3;
7804 + }
7805 + }
7806 + } while (0);
7807 +#endif
7808 +
7809 +#ifdef CONFIG_PAX_EMUTRAMP
7810 +
7811 +#ifndef CONFIG_PAX_EMUSIGRT
7812 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7813 + return 1;
7814 +#endif
7815 +
7816 + do { /* PaX: rt_sigreturn emulation */
7817 + unsigned int ldi1, ldi2, bel, nop;
7818 +
7819 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7820 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7821 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7822 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7823 +
7824 + if (err)
7825 + break;
7826 +
7827 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7828 + ldi2 == 0x3414015AU &&
7829 + bel == 0xE4008200U &&
7830 + nop == 0x08000240U)
7831 + {
7832 + regs->gr[25] = (ldi1 & 2) >> 1;
7833 + regs->gr[20] = __NR_rt_sigreturn;
7834 + regs->gr[31] = regs->iaoq[1] + 16;
7835 + regs->sr[0] = regs->iasq[1];
7836 + regs->iaoq[0] = 0x100UL;
7837 + regs->iaoq[1] = regs->iaoq[0] + 4;
7838 + regs->iasq[0] = regs->sr[2];
7839 + regs->iasq[1] = regs->sr[2];
7840 + return 2;
7841 + }
7842 + } while (0);
7843 +#endif
7844 +
7845 + return 1;
7846 +}
7847 +
7848 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7849 +{
7850 + unsigned long i;
7851 +
7852 + printk(KERN_ERR "PAX: bytes at PC: ");
7853 + for (i = 0; i < 5; i++) {
7854 + unsigned int c;
7855 + if (get_user(c, (unsigned int *)pc+i))
7856 + printk(KERN_CONT "???????? ");
7857 + else
7858 + printk(KERN_CONT "%08x ", c);
7859 + }
7860 + printk("\n");
7861 +}
7862 +#endif
7863 +
7864 int fixup_exception(struct pt_regs *regs)
7865 {
7866 const struct exception_table_entry *fix;
7867 @@ -210,8 +321,33 @@ retry:
7868
7869 good_area:
7870
7871 - if ((vma->vm_flags & acc_type) != acc_type)
7872 + if ((vma->vm_flags & acc_type) != acc_type) {
7873 +
7874 +#ifdef CONFIG_PAX_PAGEEXEC
7875 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7876 + (address & ~3UL) == instruction_pointer(regs))
7877 + {
7878 + up_read(&mm->mmap_sem);
7879 + switch (pax_handle_fetch_fault(regs)) {
7880 +
7881 +#ifdef CONFIG_PAX_EMUPLT
7882 + case 3:
7883 + return;
7884 +#endif
7885 +
7886 +#ifdef CONFIG_PAX_EMUTRAMP
7887 + case 2:
7888 + return;
7889 +#endif
7890 +
7891 + }
7892 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7893 + do_group_exit(SIGKILL);
7894 + }
7895 +#endif
7896 +
7897 goto bad_area;
7898 + }
7899
7900 /*
7901 * If for any reason at all we couldn't handle the fault, make
7902 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7903 index b44b52c..4cd253c 100644
7904 --- a/arch/powerpc/Kconfig
7905 +++ b/arch/powerpc/Kconfig
7906 @@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7907 config KEXEC
7908 bool "kexec system call"
7909 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7910 + depends on !GRKERNSEC_KMEM
7911 help
7912 kexec is a system call that implements the ability to shutdown your
7913 current kernel, and to start another kernel. It is like a reboot
7914 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7915 index e3b1d41..8e81edf 100644
7916 --- a/arch/powerpc/include/asm/atomic.h
7917 +++ b/arch/powerpc/include/asm/atomic.h
7918 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7919 return t1;
7920 }
7921
7922 +#define atomic64_read_unchecked(v) atomic64_read(v)
7923 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7924 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7925 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7926 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7927 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7928 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7929 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7930 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7931 +
7932 #endif /* __powerpc64__ */
7933
7934 #endif /* __KERNEL__ */
7935 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7936 index 9e495c9..b6878e5 100644
7937 --- a/arch/powerpc/include/asm/cache.h
7938 +++ b/arch/powerpc/include/asm/cache.h
7939 @@ -3,6 +3,7 @@
7940
7941 #ifdef __KERNEL__
7942
7943 +#include <linux/const.h>
7944
7945 /* bytes per L1 cache line */
7946 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7947 @@ -22,7 +23,7 @@
7948 #define L1_CACHE_SHIFT 7
7949 #endif
7950
7951 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7952 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7953
7954 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7955
7956 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7957 index 935b5e7..7001d2d 100644
7958 --- a/arch/powerpc/include/asm/elf.h
7959 +++ b/arch/powerpc/include/asm/elf.h
7960 @@ -28,8 +28,19 @@
7961 the loader. We need to make sure that it is out of the way of the program
7962 that it will "exec", and that there is sufficient room for the brk. */
7963
7964 -extern unsigned long randomize_et_dyn(unsigned long base);
7965 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7966 +#define ELF_ET_DYN_BASE (0x20000000)
7967 +
7968 +#ifdef CONFIG_PAX_ASLR
7969 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7970 +
7971 +#ifdef __powerpc64__
7972 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7973 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7974 +#else
7975 +#define PAX_DELTA_MMAP_LEN 15
7976 +#define PAX_DELTA_STACK_LEN 15
7977 +#endif
7978 +#endif
7979
7980 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7981
7982 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7983 (0x7ff >> (PAGE_SHIFT - 12)) : \
7984 (0x3ffff >> (PAGE_SHIFT - 12)))
7985
7986 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7987 -#define arch_randomize_brk arch_randomize_brk
7988 -
7989 -
7990 #ifdef CONFIG_SPU_BASE
7991 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7992 #define NT_SPU 1
7993 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7994 index 8196e9c..d83a9f3 100644
7995 --- a/arch/powerpc/include/asm/exec.h
7996 +++ b/arch/powerpc/include/asm/exec.h
7997 @@ -4,6 +4,6 @@
7998 #ifndef _ASM_POWERPC_EXEC_H
7999 #define _ASM_POWERPC_EXEC_H
8000
8001 -extern unsigned long arch_align_stack(unsigned long sp);
8002 +#define arch_align_stack(x) ((x) & ~0xfUL)
8003
8004 #endif /* _ASM_POWERPC_EXEC_H */
8005 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8006 index 5acabbd..7ea14fa 100644
8007 --- a/arch/powerpc/include/asm/kmap_types.h
8008 +++ b/arch/powerpc/include/asm/kmap_types.h
8009 @@ -10,7 +10,7 @@
8010 * 2 of the License, or (at your option) any later version.
8011 */
8012
8013 -#define KM_TYPE_NR 16
8014 +#define KM_TYPE_NR 17
8015
8016 #endif /* __KERNEL__ */
8017 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8018 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8019 index b8da913..60b608a 100644
8020 --- a/arch/powerpc/include/asm/local.h
8021 +++ b/arch/powerpc/include/asm/local.h
8022 @@ -9,15 +9,26 @@ typedef struct
8023 atomic_long_t a;
8024 } local_t;
8025
8026 +typedef struct
8027 +{
8028 + atomic_long_unchecked_t a;
8029 +} local_unchecked_t;
8030 +
8031 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8032
8033 #define local_read(l) atomic_long_read(&(l)->a)
8034 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8035 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8036 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8037
8038 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8039 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8040 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8041 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8042 #define local_inc(l) atomic_long_inc(&(l)->a)
8043 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8044 #define local_dec(l) atomic_long_dec(&(l)->a)
8045 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8046
8047 static __inline__ long local_add_return(long a, local_t *l)
8048 {
8049 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8050
8051 return t;
8052 }
8053 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8054
8055 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8056
8057 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8058
8059 return t;
8060 }
8061 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8062
8063 static __inline__ long local_inc_return(local_t *l)
8064 {
8065 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8066
8067 #define local_cmpxchg(l, o, n) \
8068 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8069 +#define local_cmpxchg_unchecked(l, o, n) \
8070 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8071 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8072
8073 /**
8074 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8075 index 8565c25..2865190 100644
8076 --- a/arch/powerpc/include/asm/mman.h
8077 +++ b/arch/powerpc/include/asm/mman.h
8078 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8079 }
8080 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8081
8082 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8083 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8084 {
8085 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8086 }
8087 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8088 index 32e4e21..62afb12 100644
8089 --- a/arch/powerpc/include/asm/page.h
8090 +++ b/arch/powerpc/include/asm/page.h
8091 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8092 * and needs to be executable. This means the whole heap ends
8093 * up being executable.
8094 */
8095 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8096 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8097 +#define VM_DATA_DEFAULT_FLAGS32 \
8098 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8099 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8100
8101 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8102 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8103 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8104 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8105 #endif
8106
8107 +#define ktla_ktva(addr) (addr)
8108 +#define ktva_ktla(addr) (addr)
8109 +
8110 #ifndef CONFIG_PPC_BOOK3S_64
8111 /*
8112 * Use the top bit of the higher-level page table entries to indicate whether
8113 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8114 index 88693ce..ac6f9ab 100644
8115 --- a/arch/powerpc/include/asm/page_64.h
8116 +++ b/arch/powerpc/include/asm/page_64.h
8117 @@ -153,15 +153,18 @@ do { \
8118 * stack by default, so in the absence of a PT_GNU_STACK program header
8119 * we turn execute permission off.
8120 */
8121 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8122 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8123 +#define VM_STACK_DEFAULT_FLAGS32 \
8124 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8125 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8126
8127 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8128 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8129
8130 +#ifndef CONFIG_PAX_PAGEEXEC
8131 #define VM_STACK_DEFAULT_FLAGS \
8132 (is_32bit_task() ? \
8133 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8134 +#endif
8135
8136 #include <asm-generic/getorder.h>
8137
8138 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8139 index 4b0be20..c15a27d 100644
8140 --- a/arch/powerpc/include/asm/pgalloc-64.h
8141 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8142 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8143 #ifndef CONFIG_PPC_64K_PAGES
8144
8145 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8146 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8147
8148 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8149 {
8150 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8151 pud_set(pud, (unsigned long)pmd);
8152 }
8153
8154 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8155 +{
8156 + pud_populate(mm, pud, pmd);
8157 +}
8158 +
8159 #define pmd_populate(mm, pmd, pte_page) \
8160 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8161 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8162 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8163 #endif
8164
8165 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8166 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8167
8168 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8169 pte_t *pte)
8170 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8171 index 7d6eacf..14c0240 100644
8172 --- a/arch/powerpc/include/asm/pgtable.h
8173 +++ b/arch/powerpc/include/asm/pgtable.h
8174 @@ -2,6 +2,7 @@
8175 #define _ASM_POWERPC_PGTABLE_H
8176 #ifdef __KERNEL__
8177
8178 +#include <linux/const.h>
8179 #ifndef __ASSEMBLY__
8180 #include <asm/processor.h> /* For TASK_SIZE */
8181 #include <asm/mmu.h>
8182 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8183 index 4aad413..85d86bf 100644
8184 --- a/arch/powerpc/include/asm/pte-hash32.h
8185 +++ b/arch/powerpc/include/asm/pte-hash32.h
8186 @@ -21,6 +21,7 @@
8187 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8188 #define _PAGE_USER 0x004 /* usermode access allowed */
8189 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8190 +#define _PAGE_EXEC _PAGE_GUARDED
8191 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8192 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8193 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8194 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8195 index fa8388e..f985549 100644
8196 --- a/arch/powerpc/include/asm/reg.h
8197 +++ b/arch/powerpc/include/asm/reg.h
8198 @@ -239,6 +239,7 @@
8199 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8200 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8201 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8202 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8203 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8204 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8205 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8206 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8207 index 084e080..9415a3d 100644
8208 --- a/arch/powerpc/include/asm/smp.h
8209 +++ b/arch/powerpc/include/asm/smp.h
8210 @@ -51,7 +51,7 @@ struct smp_ops_t {
8211 int (*cpu_disable)(void);
8212 void (*cpu_die)(unsigned int nr);
8213 int (*cpu_bootable)(unsigned int nr);
8214 -};
8215 +} __no_const;
8216
8217 extern void smp_send_debugger_break(void);
8218 extern void start_secondary_resume(void);
8219 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8220 index 9854c56..7517190 100644
8221 --- a/arch/powerpc/include/asm/thread_info.h
8222 +++ b/arch/powerpc/include/asm/thread_info.h
8223 @@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
8224 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
8225 TIF_NEED_RESCHED */
8226 #define TIF_32BIT 4 /* 32 bit binary */
8227 -#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
8228 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
8229 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
8230 #define TIF_SINGLESTEP 8 /* singlestepping active */
8231 @@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
8232 #if defined(CONFIG_PPC64)
8233 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8234 #endif
8235 +#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
8236 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8237 +#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
8238
8239 /* as above, but as bit values */
8240 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8241 @@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
8242 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8243 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8244 #define _TIF_NOHZ (1<<TIF_NOHZ)
8245 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8246 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8247 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8248 - _TIF_NOHZ)
8249 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8250
8251 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8252 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
8253 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8254 index 9485b43..3bd3c16 100644
8255 --- a/arch/powerpc/include/asm/uaccess.h
8256 +++ b/arch/powerpc/include/asm/uaccess.h
8257 @@ -58,6 +58,7 @@
8258
8259 #endif
8260
8261 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8262 #define access_ok(type, addr, size) \
8263 (__chk_user_ptr(addr), \
8264 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8265 @@ -318,52 +319,6 @@ do { \
8266 extern unsigned long __copy_tofrom_user(void __user *to,
8267 const void __user *from, unsigned long size);
8268
8269 -#ifndef __powerpc64__
8270 -
8271 -static inline unsigned long copy_from_user(void *to,
8272 - const void __user *from, unsigned long n)
8273 -{
8274 - unsigned long over;
8275 -
8276 - if (access_ok(VERIFY_READ, from, n))
8277 - return __copy_tofrom_user((__force void __user *)to, from, n);
8278 - if ((unsigned long)from < TASK_SIZE) {
8279 - over = (unsigned long)from + n - TASK_SIZE;
8280 - return __copy_tofrom_user((__force void __user *)to, from,
8281 - n - over) + over;
8282 - }
8283 - return n;
8284 -}
8285 -
8286 -static inline unsigned long copy_to_user(void __user *to,
8287 - const void *from, unsigned long n)
8288 -{
8289 - unsigned long over;
8290 -
8291 - if (access_ok(VERIFY_WRITE, to, n))
8292 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8293 - if ((unsigned long)to < TASK_SIZE) {
8294 - over = (unsigned long)to + n - TASK_SIZE;
8295 - return __copy_tofrom_user(to, (__force void __user *)from,
8296 - n - over) + over;
8297 - }
8298 - return n;
8299 -}
8300 -
8301 -#else /* __powerpc64__ */
8302 -
8303 -#define __copy_in_user(to, from, size) \
8304 - __copy_tofrom_user((to), (from), (size))
8305 -
8306 -extern unsigned long copy_from_user(void *to, const void __user *from,
8307 - unsigned long n);
8308 -extern unsigned long copy_to_user(void __user *to, const void *from,
8309 - unsigned long n);
8310 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8311 - unsigned long n);
8312 -
8313 -#endif /* __powerpc64__ */
8314 -
8315 static inline unsigned long __copy_from_user_inatomic(void *to,
8316 const void __user *from, unsigned long n)
8317 {
8318 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8319 if (ret == 0)
8320 return 0;
8321 }
8322 +
8323 + if (!__builtin_constant_p(n))
8324 + check_object_size(to, n, false);
8325 +
8326 return __copy_tofrom_user((__force void __user *)to, from, n);
8327 }
8328
8329 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8330 if (ret == 0)
8331 return 0;
8332 }
8333 +
8334 + if (!__builtin_constant_p(n))
8335 + check_object_size(from, n, true);
8336 +
8337 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8338 }
8339
8340 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8341 return __copy_to_user_inatomic(to, from, size);
8342 }
8343
8344 +#ifndef __powerpc64__
8345 +
8346 +static inline unsigned long __must_check copy_from_user(void *to,
8347 + const void __user *from, unsigned long n)
8348 +{
8349 + unsigned long over;
8350 +
8351 + if ((long)n < 0)
8352 + return n;
8353 +
8354 + if (access_ok(VERIFY_READ, from, n)) {
8355 + if (!__builtin_constant_p(n))
8356 + check_object_size(to, n, false);
8357 + return __copy_tofrom_user((__force void __user *)to, from, n);
8358 + }
8359 + if ((unsigned long)from < TASK_SIZE) {
8360 + over = (unsigned long)from + n - TASK_SIZE;
8361 + if (!__builtin_constant_p(n - over))
8362 + check_object_size(to, n - over, false);
8363 + return __copy_tofrom_user((__force void __user *)to, from,
8364 + n - over) + over;
8365 + }
8366 + return n;
8367 +}
8368 +
8369 +static inline unsigned long __must_check copy_to_user(void __user *to,
8370 + const void *from, unsigned long n)
8371 +{
8372 + unsigned long over;
8373 +
8374 + if ((long)n < 0)
8375 + return n;
8376 +
8377 + if (access_ok(VERIFY_WRITE, to, n)) {
8378 + if (!__builtin_constant_p(n))
8379 + check_object_size(from, n, true);
8380 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8381 + }
8382 + if ((unsigned long)to < TASK_SIZE) {
8383 + over = (unsigned long)to + n - TASK_SIZE;
8384 + if (!__builtin_constant_p(n))
8385 + check_object_size(from, n - over, true);
8386 + return __copy_tofrom_user(to, (__force void __user *)from,
8387 + n - over) + over;
8388 + }
8389 + return n;
8390 +}
8391 +
8392 +#else /* __powerpc64__ */
8393 +
8394 +#define __copy_in_user(to, from, size) \
8395 + __copy_tofrom_user((to), (from), (size))
8396 +
8397 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8398 +{
8399 + if ((long)n < 0 || n > INT_MAX)
8400 + return n;
8401 +
8402 + if (!__builtin_constant_p(n))
8403 + check_object_size(to, n, false);
8404 +
8405 + if (likely(access_ok(VERIFY_READ, from, n)))
8406 + n = __copy_from_user(to, from, n);
8407 + else
8408 + memset(to, 0, n);
8409 + return n;
8410 +}
8411 +
8412 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8413 +{
8414 + if ((long)n < 0 || n > INT_MAX)
8415 + return n;
8416 +
8417 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8418 + if (!__builtin_constant_p(n))
8419 + check_object_size(from, n, true);
8420 + n = __copy_to_user(to, from, n);
8421 + }
8422 + return n;
8423 +}
8424 +
8425 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8426 + unsigned long n);
8427 +
8428 +#endif /* __powerpc64__ */
8429 +
8430 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8431
8432 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8433 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8434 index 445cb6e..4f80c5d 100644
8435 --- a/arch/powerpc/kernel/Makefile
8436 +++ b/arch/powerpc/kernel/Makefile
8437 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8438 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8439 endif
8440
8441 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8442 +
8443 obj-y := cputable.o ptrace.o syscalls.o \
8444 irq.o align.o signal_32.o pmc.o vdso.o \
8445 process.o systbl.o idle.o \
8446 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8447 index e775156..af2d1c0 100644
8448 --- a/arch/powerpc/kernel/exceptions-64e.S
8449 +++ b/arch/powerpc/kernel/exceptions-64e.S
8450 @@ -759,6 +759,7 @@ storage_fault_common:
8451 std r14,_DAR(r1)
8452 std r15,_DSISR(r1)
8453 addi r3,r1,STACK_FRAME_OVERHEAD
8454 + bl .save_nvgprs
8455 mr r4,r14
8456 mr r5,r15
8457 ld r14,PACA_EXGEN+EX_R14(r13)
8458 @@ -767,8 +768,7 @@ storage_fault_common:
8459 cmpdi r3,0
8460 bne- 1f
8461 b .ret_from_except_lite
8462 -1: bl .save_nvgprs
8463 - mr r5,r3
8464 +1: mr r5,r3
8465 addi r3,r1,STACK_FRAME_OVERHEAD
8466 ld r4,_DAR(r1)
8467 bl .bad_page_fault
8468 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8469 index 9f905e4..1d6b3d2 100644
8470 --- a/arch/powerpc/kernel/exceptions-64s.S
8471 +++ b/arch/powerpc/kernel/exceptions-64s.S
8472 @@ -1390,10 +1390,10 @@ handle_page_fault:
8473 11: ld r4,_DAR(r1)
8474 ld r5,_DSISR(r1)
8475 addi r3,r1,STACK_FRAME_OVERHEAD
8476 + bl .save_nvgprs
8477 bl .do_page_fault
8478 cmpdi r3,0
8479 beq+ 12f
8480 - bl .save_nvgprs
8481 mr r5,r3
8482 addi r3,r1,STACK_FRAME_OVERHEAD
8483 lwz r4,_DAR(r1)
8484 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8485 index 6cff040..74ac5d1 100644
8486 --- a/arch/powerpc/kernel/module_32.c
8487 +++ b/arch/powerpc/kernel/module_32.c
8488 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8489 me->arch.core_plt_section = i;
8490 }
8491 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8492 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8493 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8494 return -ENOEXEC;
8495 }
8496
8497 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8498
8499 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8500 /* Init, or core PLT? */
8501 - if (location >= mod->module_core
8502 - && location < mod->module_core + mod->core_size)
8503 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8504 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8505 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8506 - else
8507 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8508 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8509 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8510 + else {
8511 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8512 + return ~0UL;
8513 + }
8514
8515 /* Find this entry, or if that fails, the next avail. entry */
8516 while (entry->jump[0]) {
8517 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8518 }
8519 #ifdef CONFIG_DYNAMIC_FTRACE
8520 module->arch.tramp =
8521 - do_plt_call(module->module_core,
8522 + do_plt_call(module->module_core_rx,
8523 (unsigned long)ftrace_caller,
8524 sechdrs, module);
8525 #endif
8526 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8527 index 4a96556..dd95f6c 100644
8528 --- a/arch/powerpc/kernel/process.c
8529 +++ b/arch/powerpc/kernel/process.c
8530 @@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8531 * Lookup NIP late so we have the best change of getting the
8532 * above info out without failing
8533 */
8534 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8535 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8536 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8537 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8538 #endif
8539 show_stack(current, (unsigned long *) regs->gpr[1]);
8540 if (!user_mode(regs))
8541 @@ -1376,10 +1376,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8542 newsp = stack[0];
8543 ip = stack[STACK_FRAME_LR_SAVE];
8544 if (!firstframe || ip != lr) {
8545 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8546 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8547 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8548 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8549 - printk(" (%pS)",
8550 + printk(" (%pA)",
8551 (void *)current->ret_stack[curr_frame].ret);
8552 curr_frame--;
8553 }
8554 @@ -1399,7 +1399,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8555 struct pt_regs *regs = (struct pt_regs *)
8556 (sp + STACK_FRAME_OVERHEAD);
8557 lr = regs->link;
8558 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8559 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8560 regs->trap, (void *)regs->nip, (void *)lr);
8561 firstframe = 1;
8562 }
8563 @@ -1435,58 +1435,3 @@ void notrace __ppc64_runlatch_off(void)
8564 mtspr(SPRN_CTRLT, ctrl);
8565 }
8566 #endif /* CONFIG_PPC64 */
8567 -
8568 -unsigned long arch_align_stack(unsigned long sp)
8569 -{
8570 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8571 - sp -= get_random_int() & ~PAGE_MASK;
8572 - return sp & ~0xf;
8573 -}
8574 -
8575 -static inline unsigned long brk_rnd(void)
8576 -{
8577 - unsigned long rnd = 0;
8578 -
8579 - /* 8MB for 32bit, 1GB for 64bit */
8580 - if (is_32bit_task())
8581 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8582 - else
8583 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8584 -
8585 - return rnd << PAGE_SHIFT;
8586 -}
8587 -
8588 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8589 -{
8590 - unsigned long base = mm->brk;
8591 - unsigned long ret;
8592 -
8593 -#ifdef CONFIG_PPC_STD_MMU_64
8594 - /*
8595 - * If we are using 1TB segments and we are allowed to randomise
8596 - * the heap, we can put it above 1TB so it is backed by a 1TB
8597 - * segment. Otherwise the heap will be in the bottom 1TB
8598 - * which always uses 256MB segments and this may result in a
8599 - * performance penalty.
8600 - */
8601 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8602 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8603 -#endif
8604 -
8605 - ret = PAGE_ALIGN(base + brk_rnd());
8606 -
8607 - if (ret < mm->brk)
8608 - return mm->brk;
8609 -
8610 - return ret;
8611 -}
8612 -
8613 -unsigned long randomize_et_dyn(unsigned long base)
8614 -{
8615 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8616 -
8617 - if (ret < base)
8618 - return base;
8619 -
8620 - return ret;
8621 -}
8622 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8623 index 2e3d2bf..35df241 100644
8624 --- a/arch/powerpc/kernel/ptrace.c
8625 +++ b/arch/powerpc/kernel/ptrace.c
8626 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8627 return ret;
8628 }
8629
8630 +#ifdef CONFIG_GRKERNSEC_SETXID
8631 +extern void gr_delayed_cred_worker(void);
8632 +#endif
8633 +
8634 /*
8635 * We must return the syscall number to actually look up in the table.
8636 * This can be -1L to skip running any syscall at all.
8637 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8638
8639 secure_computing_strict(regs->gpr[0]);
8640
8641 +#ifdef CONFIG_GRKERNSEC_SETXID
8642 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8643 + gr_delayed_cred_worker();
8644 +#endif
8645 +
8646 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8647 tracehook_report_syscall_entry(regs))
8648 /*
8649 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8650 {
8651 int step;
8652
8653 +#ifdef CONFIG_GRKERNSEC_SETXID
8654 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8655 + gr_delayed_cred_worker();
8656 +#endif
8657 +
8658 audit_syscall_exit(regs);
8659
8660 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8661 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8662 index 68027bf..b26fd31 100644
8663 --- a/arch/powerpc/kernel/signal_32.c
8664 +++ b/arch/powerpc/kernel/signal_32.c
8665 @@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8666 /* Save user registers on the stack */
8667 frame = &rt_sf->uc.uc_mcontext;
8668 addr = frame;
8669 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8670 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8671 sigret = 0;
8672 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8673 } else {
8674 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8675 index 448245f..b9bae83 100644
8676 --- a/arch/powerpc/kernel/signal_64.c
8677 +++ b/arch/powerpc/kernel/signal_64.c
8678 @@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8679 #endif
8680
8681 /* Set up to return from userspace. */
8682 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8683 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8684 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8685 } else {
8686 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8687 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8688 index 907a472..4ba206f 100644
8689 --- a/arch/powerpc/kernel/traps.c
8690 +++ b/arch/powerpc/kernel/traps.c
8691 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8692 return flags;
8693 }
8694
8695 +extern void gr_handle_kernel_exploit(void);
8696 +
8697 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8698 int signr)
8699 {
8700 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8701 panic("Fatal exception in interrupt");
8702 if (panic_on_oops)
8703 panic("Fatal exception");
8704 +
8705 + gr_handle_kernel_exploit();
8706 +
8707 do_exit(signr);
8708 }
8709
8710 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8711 index 094e45c..d82b848 100644
8712 --- a/arch/powerpc/kernel/vdso.c
8713 +++ b/arch/powerpc/kernel/vdso.c
8714 @@ -35,6 +35,7 @@
8715 #include <asm/vdso.h>
8716 #include <asm/vdso_datapage.h>
8717 #include <asm/setup.h>
8718 +#include <asm/mman.h>
8719
8720 #undef DEBUG
8721
8722 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8723 vdso_base = VDSO32_MBASE;
8724 #endif
8725
8726 - current->mm->context.vdso_base = 0;
8727 + current->mm->context.vdso_base = ~0UL;
8728
8729 /* vDSO has a problem and was disabled, just don't "enable" it for the
8730 * process
8731 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8732 vdso_base = get_unmapped_area(NULL, vdso_base,
8733 (vdso_pages << PAGE_SHIFT) +
8734 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8735 - 0, 0);
8736 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8737 if (IS_ERR_VALUE(vdso_base)) {
8738 rc = vdso_base;
8739 goto fail_mmapsem;
8740 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8741 index 9ae9768..87c3448 100644
8742 --- a/arch/powerpc/kvm/powerpc.c
8743 +++ b/arch/powerpc/kvm/powerpc.c
8744 @@ -1141,7 +1141,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8745 }
8746 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8747
8748 -int kvm_arch_init(void *opaque)
8749 +int kvm_arch_init(const void *opaque)
8750 {
8751 return 0;
8752 }
8753 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8754 index 5eea6f3..5d10396 100644
8755 --- a/arch/powerpc/lib/usercopy_64.c
8756 +++ b/arch/powerpc/lib/usercopy_64.c
8757 @@ -9,22 +9,6 @@
8758 #include <linux/module.h>
8759 #include <asm/uaccess.h>
8760
8761 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8762 -{
8763 - if (likely(access_ok(VERIFY_READ, from, n)))
8764 - n = __copy_from_user(to, from, n);
8765 - else
8766 - memset(to, 0, n);
8767 - return n;
8768 -}
8769 -
8770 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8771 -{
8772 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8773 - n = __copy_to_user(to, from, n);
8774 - return n;
8775 -}
8776 -
8777 unsigned long copy_in_user(void __user *to, const void __user *from,
8778 unsigned long n)
8779 {
8780 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8781 return n;
8782 }
8783
8784 -EXPORT_SYMBOL(copy_from_user);
8785 -EXPORT_SYMBOL(copy_to_user);
8786 EXPORT_SYMBOL(copy_in_user);
8787
8788 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8789 index 51ab9e7..7d3c78b 100644
8790 --- a/arch/powerpc/mm/fault.c
8791 +++ b/arch/powerpc/mm/fault.c
8792 @@ -33,6 +33,10 @@
8793 #include <linux/magic.h>
8794 #include <linux/ratelimit.h>
8795 #include <linux/context_tracking.h>
8796 +#include <linux/slab.h>
8797 +#include <linux/pagemap.h>
8798 +#include <linux/compiler.h>
8799 +#include <linux/unistd.h>
8800
8801 #include <asm/firmware.h>
8802 #include <asm/page.h>
8803 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8804 }
8805 #endif
8806
8807 +#ifdef CONFIG_PAX_PAGEEXEC
8808 +/*
8809 + * PaX: decide what to do with offenders (regs->nip = fault address)
8810 + *
8811 + * returns 1 when task should be killed
8812 + */
8813 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8814 +{
8815 + return 1;
8816 +}
8817 +
8818 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8819 +{
8820 + unsigned long i;
8821 +
8822 + printk(KERN_ERR "PAX: bytes at PC: ");
8823 + for (i = 0; i < 5; i++) {
8824 + unsigned int c;
8825 + if (get_user(c, (unsigned int __user *)pc+i))
8826 + printk(KERN_CONT "???????? ");
8827 + else
8828 + printk(KERN_CONT "%08x ", c);
8829 + }
8830 + printk("\n");
8831 +}
8832 +#endif
8833 +
8834 /*
8835 * Check whether the instruction at regs->nip is a store using
8836 * an update addressing form which will update r1.
8837 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8838 * indicate errors in DSISR but can validly be set in SRR1.
8839 */
8840 if (trap == 0x400)
8841 - error_code &= 0x48200000;
8842 + error_code &= 0x58200000;
8843 else
8844 is_write = error_code & DSISR_ISSTORE;
8845 #else
8846 @@ -378,7 +409,7 @@ good_area:
8847 * "undefined". Of those that can be set, this is the only
8848 * one which seems bad.
8849 */
8850 - if (error_code & 0x10000000)
8851 + if (error_code & DSISR_GUARDED)
8852 /* Guarded storage error. */
8853 goto bad_area;
8854 #endif /* CONFIG_8xx */
8855 @@ -393,7 +424,7 @@ good_area:
8856 * processors use the same I/D cache coherency mechanism
8857 * as embedded.
8858 */
8859 - if (error_code & DSISR_PROTFAULT)
8860 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8861 goto bad_area;
8862 #endif /* CONFIG_PPC_STD_MMU */
8863
8864 @@ -483,6 +514,23 @@ bad_area:
8865 bad_area_nosemaphore:
8866 /* User mode accesses cause a SIGSEGV */
8867 if (user_mode(regs)) {
8868 +
8869 +#ifdef CONFIG_PAX_PAGEEXEC
8870 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8871 +#ifdef CONFIG_PPC_STD_MMU
8872 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8873 +#else
8874 + if (is_exec && regs->nip == address) {
8875 +#endif
8876 + switch (pax_handle_fetch_fault(regs)) {
8877 + }
8878 +
8879 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8880 + do_group_exit(SIGKILL);
8881 + }
8882 + }
8883 +#endif
8884 +
8885 _exception(SIGSEGV, regs, code, address);
8886 goto bail;
8887 }
8888 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8889 index cb8bdbe..cde4bc7 100644
8890 --- a/arch/powerpc/mm/mmap.c
8891 +++ b/arch/powerpc/mm/mmap.c
8892 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8893 return sysctl_legacy_va_layout;
8894 }
8895
8896 -static unsigned long mmap_rnd(void)
8897 +static unsigned long mmap_rnd(struct mm_struct *mm)
8898 {
8899 unsigned long rnd = 0;
8900
8901 +#ifdef CONFIG_PAX_RANDMMAP
8902 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8903 +#endif
8904 +
8905 if (current->flags & PF_RANDOMIZE) {
8906 /* 8MB for 32bit, 1GB for 64bit */
8907 if (is_32bit_task())
8908 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8909 return rnd << PAGE_SHIFT;
8910 }
8911
8912 -static inline unsigned long mmap_base(void)
8913 +static inline unsigned long mmap_base(struct mm_struct *mm)
8914 {
8915 unsigned long gap = rlimit(RLIMIT_STACK);
8916
8917 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8918 else if (gap > MAX_GAP)
8919 gap = MAX_GAP;
8920
8921 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8922 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8923 }
8924
8925 /*
8926 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8927 */
8928 if (mmap_is_legacy()) {
8929 mm->mmap_base = TASK_UNMAPPED_BASE;
8930 +
8931 +#ifdef CONFIG_PAX_RANDMMAP
8932 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8933 + mm->mmap_base += mm->delta_mmap;
8934 +#endif
8935 +
8936 mm->get_unmapped_area = arch_get_unmapped_area;
8937 } else {
8938 - mm->mmap_base = mmap_base();
8939 + mm->mmap_base = mmap_base(mm);
8940 +
8941 +#ifdef CONFIG_PAX_RANDMMAP
8942 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8943 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8944 +#endif
8945 +
8946 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8947 }
8948 }
8949 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8950 index 7ce9cf3..a964087 100644
8951 --- a/arch/powerpc/mm/slice.c
8952 +++ b/arch/powerpc/mm/slice.c
8953 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8954 if ((mm->task_size - len) < addr)
8955 return 0;
8956 vma = find_vma(mm, addr);
8957 - return (!vma || (addr + len) <= vma->vm_start);
8958 + return check_heap_stack_gap(vma, addr, len, 0);
8959 }
8960
8961 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8962 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8963 info.align_offset = 0;
8964
8965 addr = TASK_UNMAPPED_BASE;
8966 +
8967 +#ifdef CONFIG_PAX_RANDMMAP
8968 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8969 + addr += mm->delta_mmap;
8970 +#endif
8971 +
8972 while (addr < TASK_SIZE) {
8973 info.low_limit = addr;
8974 if (!slice_scan_available(addr, available, 1, &addr))
8975 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8976 if (fixed && addr > (mm->task_size - len))
8977 return -EINVAL;
8978
8979 +#ifdef CONFIG_PAX_RANDMMAP
8980 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8981 + addr = 0;
8982 +#endif
8983 +
8984 /* If hint, make sure it matches our alignment restrictions */
8985 if (!fixed && addr) {
8986 addr = _ALIGN_UP(addr, 1ul << pshift);
8987 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8988 index 4278acf..67fd0e6 100644
8989 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8990 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8991 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8992 }
8993
8994 static struct pci_ops scc_pciex_pci_ops = {
8995 - scc_pciex_read_config,
8996 - scc_pciex_write_config,
8997 + .read = scc_pciex_read_config,
8998 + .write = scc_pciex_write_config,
8999 };
9000
9001 static void pciex_clear_intr_all(unsigned int __iomem *base)
9002 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9003 index 9098692..3d54cd1 100644
9004 --- a/arch/powerpc/platforms/cell/spufs/file.c
9005 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9006 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9007 return VM_FAULT_NOPAGE;
9008 }
9009
9010 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9011 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9012 unsigned long address,
9013 - void *buf, int len, int write)
9014 + void *buf, size_t len, int write)
9015 {
9016 struct spu_context *ctx = vma->vm_file->private_data;
9017 unsigned long offset = address - vma->vm_start;
9018 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9019 index fa9aaf7..3f5d836 100644
9020 --- a/arch/s390/include/asm/atomic.h
9021 +++ b/arch/s390/include/asm/atomic.h
9022 @@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9023 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9024 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9025
9026 +#define atomic64_read_unchecked(v) atomic64_read(v)
9027 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9028 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9029 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9030 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9031 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9032 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9033 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9034 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9035 +
9036 #define smp_mb__before_atomic_dec() smp_mb()
9037 #define smp_mb__after_atomic_dec() smp_mb()
9038 #define smp_mb__before_atomic_inc() smp_mb()
9039 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9040 index 4d7ccac..d03d0ad 100644
9041 --- a/arch/s390/include/asm/cache.h
9042 +++ b/arch/s390/include/asm/cache.h
9043 @@ -9,8 +9,10 @@
9044 #ifndef __ARCH_S390_CACHE_H
9045 #define __ARCH_S390_CACHE_H
9046
9047 -#define L1_CACHE_BYTES 256
9048 +#include <linux/const.h>
9049 +
9050 #define L1_CACHE_SHIFT 8
9051 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9052 #define NET_SKB_PAD 32
9053
9054 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9055 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9056 index 78f4f87..598ce39 100644
9057 --- a/arch/s390/include/asm/elf.h
9058 +++ b/arch/s390/include/asm/elf.h
9059 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9060 the loader. We need to make sure that it is out of the way of the program
9061 that it will "exec", and that there is sufficient room for the brk. */
9062
9063 -extern unsigned long randomize_et_dyn(unsigned long base);
9064 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9065 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9066 +
9067 +#ifdef CONFIG_PAX_ASLR
9068 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9069 +
9070 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9071 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9072 +#endif
9073
9074 /* This yields a mask that user programs can use to figure out what
9075 instruction set this CPU supports. */
9076 @@ -222,9 +228,6 @@ struct linux_binprm;
9077 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9078 int arch_setup_additional_pages(struct linux_binprm *, int);
9079
9080 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9081 -#define arch_randomize_brk arch_randomize_brk
9082 -
9083 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9084
9085 #endif
9086 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9087 index c4a93d6..4d2a9b4 100644
9088 --- a/arch/s390/include/asm/exec.h
9089 +++ b/arch/s390/include/asm/exec.h
9090 @@ -7,6 +7,6 @@
9091 #ifndef __ASM_EXEC_H
9092 #define __ASM_EXEC_H
9093
9094 -extern unsigned long arch_align_stack(unsigned long sp);
9095 +#define arch_align_stack(x) ((x) & ~0xfUL)
9096
9097 #endif /* __ASM_EXEC_H */
9098 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9099 index 79330af..254cf37 100644
9100 --- a/arch/s390/include/asm/uaccess.h
9101 +++ b/arch/s390/include/asm/uaccess.h
9102 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9103 __range_ok((unsigned long)(addr), (size)); \
9104 })
9105
9106 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9107 #define access_ok(type, addr, size) __access_ok(addr, size)
9108
9109 /*
9110 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9111 copy_to_user(void __user *to, const void *from, unsigned long n)
9112 {
9113 might_fault();
9114 +
9115 + if ((long)n < 0)
9116 + return n;
9117 +
9118 return __copy_to_user(to, from, n);
9119 }
9120
9121 @@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9122 static inline unsigned long __must_check
9123 __copy_from_user(void *to, const void __user *from, unsigned long n)
9124 {
9125 + if ((long)n < 0)
9126 + return n;
9127 +
9128 return uaccess.copy_from_user(n, from, to);
9129 }
9130
9131 @@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9132 static inline unsigned long __must_check
9133 copy_from_user(void *to, const void __user *from, unsigned long n)
9134 {
9135 - unsigned int sz = __compiletime_object_size(to);
9136 + size_t sz = __compiletime_object_size(to);
9137
9138 might_fault();
9139 - if (unlikely(sz != -1 && sz < n)) {
9140 +
9141 + if ((long)n < 0)
9142 + return n;
9143 +
9144 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9145 copy_from_user_overflow();
9146 return n;
9147 }
9148 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9149 index b89b591..fd9609d 100644
9150 --- a/arch/s390/kernel/module.c
9151 +++ b/arch/s390/kernel/module.c
9152 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9153
9154 /* Increase core size by size of got & plt and set start
9155 offsets for got and plt. */
9156 - me->core_size = ALIGN(me->core_size, 4);
9157 - me->arch.got_offset = me->core_size;
9158 - me->core_size += me->arch.got_size;
9159 - me->arch.plt_offset = me->core_size;
9160 - me->core_size += me->arch.plt_size;
9161 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9162 + me->arch.got_offset = me->core_size_rw;
9163 + me->core_size_rw += me->arch.got_size;
9164 + me->arch.plt_offset = me->core_size_rx;
9165 + me->core_size_rx += me->arch.plt_size;
9166 return 0;
9167 }
9168
9169 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9170 if (info->got_initialized == 0) {
9171 Elf_Addr *gotent;
9172
9173 - gotent = me->module_core + me->arch.got_offset +
9174 + gotent = me->module_core_rw + me->arch.got_offset +
9175 info->got_offset;
9176 *gotent = val;
9177 info->got_initialized = 1;
9178 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9179 rc = apply_rela_bits(loc, val, 0, 64, 0);
9180 else if (r_type == R_390_GOTENT ||
9181 r_type == R_390_GOTPLTENT) {
9182 - val += (Elf_Addr) me->module_core - loc;
9183 + val += (Elf_Addr) me->module_core_rw - loc;
9184 rc = apply_rela_bits(loc, val, 1, 32, 1);
9185 }
9186 break;
9187 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9188 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9189 if (info->plt_initialized == 0) {
9190 unsigned int *ip;
9191 - ip = me->module_core + me->arch.plt_offset +
9192 + ip = me->module_core_rx + me->arch.plt_offset +
9193 info->plt_offset;
9194 #ifndef CONFIG_64BIT
9195 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9196 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9197 val - loc + 0xffffUL < 0x1ffffeUL) ||
9198 (r_type == R_390_PLT32DBL &&
9199 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9200 - val = (Elf_Addr) me->module_core +
9201 + val = (Elf_Addr) me->module_core_rx +
9202 me->arch.plt_offset +
9203 info->plt_offset;
9204 val += rela->r_addend - loc;
9205 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9206 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9207 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9208 val = val + rela->r_addend -
9209 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9210 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9211 if (r_type == R_390_GOTOFF16)
9212 rc = apply_rela_bits(loc, val, 0, 16, 0);
9213 else if (r_type == R_390_GOTOFF32)
9214 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9215 break;
9216 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9217 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9218 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9219 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9220 rela->r_addend - loc;
9221 if (r_type == R_390_GOTPC)
9222 rc = apply_rela_bits(loc, val, 1, 32, 0);
9223 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9224 index 7ed0d4e..1dfc145 100644
9225 --- a/arch/s390/kernel/process.c
9226 +++ b/arch/s390/kernel/process.c
9227 @@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9228 }
9229 return 0;
9230 }
9231 -
9232 -unsigned long arch_align_stack(unsigned long sp)
9233 -{
9234 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9235 - sp -= get_random_int() & ~PAGE_MASK;
9236 - return sp & ~0xf;
9237 -}
9238 -
9239 -static inline unsigned long brk_rnd(void)
9240 -{
9241 - /* 8MB for 32bit, 1GB for 64bit */
9242 - if (is_32bit_task())
9243 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9244 - else
9245 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9246 -}
9247 -
9248 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9249 -{
9250 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
9251 -
9252 - if (ret < mm->brk)
9253 - return mm->brk;
9254 - return ret;
9255 -}
9256 -
9257 -unsigned long randomize_et_dyn(unsigned long base)
9258 -{
9259 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9260 -
9261 - if (!(current->flags & PF_RANDOMIZE))
9262 - return base;
9263 - if (ret < base)
9264 - return base;
9265 - return ret;
9266 -}
9267 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9268 index 9b436c2..54fbf0a 100644
9269 --- a/arch/s390/mm/mmap.c
9270 +++ b/arch/s390/mm/mmap.c
9271 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9272 */
9273 if (mmap_is_legacy()) {
9274 mm->mmap_base = mmap_base_legacy();
9275 +
9276 +#ifdef CONFIG_PAX_RANDMMAP
9277 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9278 + mm->mmap_base += mm->delta_mmap;
9279 +#endif
9280 +
9281 mm->get_unmapped_area = arch_get_unmapped_area;
9282 } else {
9283 mm->mmap_base = mmap_base();
9284 +
9285 +#ifdef CONFIG_PAX_RANDMMAP
9286 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9287 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9288 +#endif
9289 +
9290 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9291 }
9292 }
9293 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9294 */
9295 if (mmap_is_legacy()) {
9296 mm->mmap_base = mmap_base_legacy();
9297 +
9298 +#ifdef CONFIG_PAX_RANDMMAP
9299 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9300 + mm->mmap_base += mm->delta_mmap;
9301 +#endif
9302 +
9303 mm->get_unmapped_area = s390_get_unmapped_area;
9304 } else {
9305 mm->mmap_base = mmap_base();
9306 +
9307 +#ifdef CONFIG_PAX_RANDMMAP
9308 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9309 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9310 +#endif
9311 +
9312 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9313 }
9314 }
9315 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9316 index ae3d59f..f65f075 100644
9317 --- a/arch/score/include/asm/cache.h
9318 +++ b/arch/score/include/asm/cache.h
9319 @@ -1,7 +1,9 @@
9320 #ifndef _ASM_SCORE_CACHE_H
9321 #define _ASM_SCORE_CACHE_H
9322
9323 +#include <linux/const.h>
9324 +
9325 #define L1_CACHE_SHIFT 4
9326 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9327 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9328
9329 #endif /* _ASM_SCORE_CACHE_H */
9330 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9331 index f9f3cd5..58ff438 100644
9332 --- a/arch/score/include/asm/exec.h
9333 +++ b/arch/score/include/asm/exec.h
9334 @@ -1,6 +1,6 @@
9335 #ifndef _ASM_SCORE_EXEC_H
9336 #define _ASM_SCORE_EXEC_H
9337
9338 -extern unsigned long arch_align_stack(unsigned long sp);
9339 +#define arch_align_stack(x) (x)
9340
9341 #endif /* _ASM_SCORE_EXEC_H */
9342 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9343 index a1519ad3..e8ac1ff 100644
9344 --- a/arch/score/kernel/process.c
9345 +++ b/arch/score/kernel/process.c
9346 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9347
9348 return task_pt_regs(task)->cp0_epc;
9349 }
9350 -
9351 -unsigned long arch_align_stack(unsigned long sp)
9352 -{
9353 - return sp;
9354 -}
9355 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9356 index ef9e555..331bd29 100644
9357 --- a/arch/sh/include/asm/cache.h
9358 +++ b/arch/sh/include/asm/cache.h
9359 @@ -9,10 +9,11 @@
9360 #define __ASM_SH_CACHE_H
9361 #ifdef __KERNEL__
9362
9363 +#include <linux/const.h>
9364 #include <linux/init.h>
9365 #include <cpu/cache.h>
9366
9367 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9368 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9369
9370 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9371
9372 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9373 index 6777177..cb5e44f 100644
9374 --- a/arch/sh/mm/mmap.c
9375 +++ b/arch/sh/mm/mmap.c
9376 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9377 struct mm_struct *mm = current->mm;
9378 struct vm_area_struct *vma;
9379 int do_colour_align;
9380 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9381 struct vm_unmapped_area_info info;
9382
9383 if (flags & MAP_FIXED) {
9384 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9385 if (filp || (flags & MAP_SHARED))
9386 do_colour_align = 1;
9387
9388 +#ifdef CONFIG_PAX_RANDMMAP
9389 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9390 +#endif
9391 +
9392 if (addr) {
9393 if (do_colour_align)
9394 addr = COLOUR_ALIGN(addr, pgoff);
9395 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9396 addr = PAGE_ALIGN(addr);
9397
9398 vma = find_vma(mm, addr);
9399 - if (TASK_SIZE - len >= addr &&
9400 - (!vma || addr + len <= vma->vm_start))
9401 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9402 return addr;
9403 }
9404
9405 info.flags = 0;
9406 info.length = len;
9407 - info.low_limit = TASK_UNMAPPED_BASE;
9408 + info.low_limit = mm->mmap_base;
9409 info.high_limit = TASK_SIZE;
9410 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9411 info.align_offset = pgoff << PAGE_SHIFT;
9412 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9413 struct mm_struct *mm = current->mm;
9414 unsigned long addr = addr0;
9415 int do_colour_align;
9416 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9417 struct vm_unmapped_area_info info;
9418
9419 if (flags & MAP_FIXED) {
9420 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9421 if (filp || (flags & MAP_SHARED))
9422 do_colour_align = 1;
9423
9424 +#ifdef CONFIG_PAX_RANDMMAP
9425 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9426 +#endif
9427 +
9428 /* requesting a specific address */
9429 if (addr) {
9430 if (do_colour_align)
9431 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9432 addr = PAGE_ALIGN(addr);
9433
9434 vma = find_vma(mm, addr);
9435 - if (TASK_SIZE - len >= addr &&
9436 - (!vma || addr + len <= vma->vm_start))
9437 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9438 return addr;
9439 }
9440
9441 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9442 VM_BUG_ON(addr != -ENOMEM);
9443 info.flags = 0;
9444 info.low_limit = TASK_UNMAPPED_BASE;
9445 +
9446 +#ifdef CONFIG_PAX_RANDMMAP
9447 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9448 + info.low_limit += mm->delta_mmap;
9449 +#endif
9450 +
9451 info.high_limit = TASK_SIZE;
9452 addr = vm_unmapped_area(&info);
9453 }
9454 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9455 index be56a24..443328f 100644
9456 --- a/arch/sparc/include/asm/atomic_64.h
9457 +++ b/arch/sparc/include/asm/atomic_64.h
9458 @@ -14,18 +14,40 @@
9459 #define ATOMIC64_INIT(i) { (i) }
9460
9461 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9462 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9463 +{
9464 + return v->counter;
9465 +}
9466 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9467 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9468 +{
9469 + return v->counter;
9470 +}
9471
9472 #define atomic_set(v, i) (((v)->counter) = i)
9473 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9474 +{
9475 + v->counter = i;
9476 +}
9477 #define atomic64_set(v, i) (((v)->counter) = i)
9478 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9479 +{
9480 + v->counter = i;
9481 +}
9482
9483 extern void atomic_add(int, atomic_t *);
9484 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9485 extern void atomic64_add(long, atomic64_t *);
9486 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9487 extern void atomic_sub(int, atomic_t *);
9488 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9489 extern void atomic64_sub(long, atomic64_t *);
9490 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9491
9492 extern int atomic_add_ret(int, atomic_t *);
9493 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9494 extern long atomic64_add_ret(long, atomic64_t *);
9495 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9496 extern int atomic_sub_ret(int, atomic_t *);
9497 extern long atomic64_sub_ret(long, atomic64_t *);
9498
9499 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9500 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9501
9502 #define atomic_inc_return(v) atomic_add_ret(1, v)
9503 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9504 +{
9505 + return atomic_add_ret_unchecked(1, v);
9506 +}
9507 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9508 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9509 +{
9510 + return atomic64_add_ret_unchecked(1, v);
9511 +}
9512
9513 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9514 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9515
9516 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9517 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9518 +{
9519 + return atomic_add_ret_unchecked(i, v);
9520 +}
9521 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9522 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9523 +{
9524 + return atomic64_add_ret_unchecked(i, v);
9525 +}
9526
9527 /*
9528 * atomic_inc_and_test - increment and test
9529 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9530 * other cases.
9531 */
9532 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9533 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9534 +{
9535 + return atomic_inc_return_unchecked(v) == 0;
9536 +}
9537 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9538
9539 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9540 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9541 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9542
9543 #define atomic_inc(v) atomic_add(1, v)
9544 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9545 +{
9546 + atomic_add_unchecked(1, v);
9547 +}
9548 #define atomic64_inc(v) atomic64_add(1, v)
9549 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9550 +{
9551 + atomic64_add_unchecked(1, v);
9552 +}
9553
9554 #define atomic_dec(v) atomic_sub(1, v)
9555 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9556 +{
9557 + atomic_sub_unchecked(1, v);
9558 +}
9559 #define atomic64_dec(v) atomic64_sub(1, v)
9560 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9561 +{
9562 + atomic64_sub_unchecked(1, v);
9563 +}
9564
9565 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9566 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9567
9568 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9569 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9570 +{
9571 + return cmpxchg(&v->counter, old, new);
9572 +}
9573 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9574 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9575 +{
9576 + return xchg(&v->counter, new);
9577 +}
9578
9579 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9580 {
9581 - int c, old;
9582 + int c, old, new;
9583 c = atomic_read(v);
9584 for (;;) {
9585 - if (unlikely(c == (u)))
9586 + if (unlikely(c == u))
9587 break;
9588 - old = atomic_cmpxchg((v), c, c + (a));
9589 +
9590 + asm volatile("addcc %2, %0, %0\n"
9591 +
9592 +#ifdef CONFIG_PAX_REFCOUNT
9593 + "tvs %%icc, 6\n"
9594 +#endif
9595 +
9596 + : "=r" (new)
9597 + : "0" (c), "ir" (a)
9598 + : "cc");
9599 +
9600 + old = atomic_cmpxchg(v, c, new);
9601 if (likely(old == c))
9602 break;
9603 c = old;
9604 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9605 #define atomic64_cmpxchg(v, o, n) \
9606 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9607 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9608 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9609 +{
9610 + return xchg(&v->counter, new);
9611 +}
9612
9613 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9614 {
9615 - long c, old;
9616 + long c, old, new;
9617 c = atomic64_read(v);
9618 for (;;) {
9619 - if (unlikely(c == (u)))
9620 + if (unlikely(c == u))
9621 break;
9622 - old = atomic64_cmpxchg((v), c, c + (a));
9623 +
9624 + asm volatile("addcc %2, %0, %0\n"
9625 +
9626 +#ifdef CONFIG_PAX_REFCOUNT
9627 + "tvs %%xcc, 6\n"
9628 +#endif
9629 +
9630 + : "=r" (new)
9631 + : "0" (c), "ir" (a)
9632 + : "cc");
9633 +
9634 + old = atomic64_cmpxchg(v, c, new);
9635 if (likely(old == c))
9636 break;
9637 c = old;
9638 }
9639 - return c != (u);
9640 + return c != u;
9641 }
9642
9643 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9644 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9645 index 5bb6991..5c2132e 100644
9646 --- a/arch/sparc/include/asm/cache.h
9647 +++ b/arch/sparc/include/asm/cache.h
9648 @@ -7,10 +7,12 @@
9649 #ifndef _SPARC_CACHE_H
9650 #define _SPARC_CACHE_H
9651
9652 +#include <linux/const.h>
9653 +
9654 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9655
9656 #define L1_CACHE_SHIFT 5
9657 -#define L1_CACHE_BYTES 32
9658 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9659
9660 #ifdef CONFIG_SPARC32
9661 #define SMP_CACHE_BYTES_SHIFT 5
9662 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9663 index a24e41f..47677ff 100644
9664 --- a/arch/sparc/include/asm/elf_32.h
9665 +++ b/arch/sparc/include/asm/elf_32.h
9666 @@ -114,6 +114,13 @@ typedef struct {
9667
9668 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9669
9670 +#ifdef CONFIG_PAX_ASLR
9671 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9672 +
9673 +#define PAX_DELTA_MMAP_LEN 16
9674 +#define PAX_DELTA_STACK_LEN 16
9675 +#endif
9676 +
9677 /* This yields a mask that user programs can use to figure out what
9678 instruction set this cpu supports. This can NOT be done in userspace
9679 on Sparc. */
9680 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9681 index 370ca1e..d4f4a98 100644
9682 --- a/arch/sparc/include/asm/elf_64.h
9683 +++ b/arch/sparc/include/asm/elf_64.h
9684 @@ -189,6 +189,13 @@ typedef struct {
9685 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9686 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9687
9688 +#ifdef CONFIG_PAX_ASLR
9689 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9690 +
9691 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9692 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9693 +#endif
9694 +
9695 extern unsigned long sparc64_elf_hwcap;
9696 #define ELF_HWCAP sparc64_elf_hwcap
9697
9698 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9699 index 9b1c36d..209298b 100644
9700 --- a/arch/sparc/include/asm/pgalloc_32.h
9701 +++ b/arch/sparc/include/asm/pgalloc_32.h
9702 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9703 }
9704
9705 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9706 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9707
9708 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9709 unsigned long address)
9710 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9711 index bcfe063..b333142 100644
9712 --- a/arch/sparc/include/asm/pgalloc_64.h
9713 +++ b/arch/sparc/include/asm/pgalloc_64.h
9714 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9715 }
9716
9717 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9718 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9719
9720 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9721 {
9722 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9723 index 59ba6f6..4518128 100644
9724 --- a/arch/sparc/include/asm/pgtable.h
9725 +++ b/arch/sparc/include/asm/pgtable.h
9726 @@ -5,4 +5,8 @@
9727 #else
9728 #include <asm/pgtable_32.h>
9729 #endif
9730 +
9731 +#define ktla_ktva(addr) (addr)
9732 +#define ktva_ktla(addr) (addr)
9733 +
9734 #endif
9735 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9736 index 502f632..da1917f 100644
9737 --- a/arch/sparc/include/asm/pgtable_32.h
9738 +++ b/arch/sparc/include/asm/pgtable_32.h
9739 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9740 #define PAGE_SHARED SRMMU_PAGE_SHARED
9741 #define PAGE_COPY SRMMU_PAGE_COPY
9742 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9743 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9744 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9745 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9746 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9747
9748 /* Top-level page directory - dummy used by init-mm.
9749 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9750
9751 /* xwr */
9752 #define __P000 PAGE_NONE
9753 -#define __P001 PAGE_READONLY
9754 -#define __P010 PAGE_COPY
9755 -#define __P011 PAGE_COPY
9756 +#define __P001 PAGE_READONLY_NOEXEC
9757 +#define __P010 PAGE_COPY_NOEXEC
9758 +#define __P011 PAGE_COPY_NOEXEC
9759 #define __P100 PAGE_READONLY
9760 #define __P101 PAGE_READONLY
9761 #define __P110 PAGE_COPY
9762 #define __P111 PAGE_COPY
9763
9764 #define __S000 PAGE_NONE
9765 -#define __S001 PAGE_READONLY
9766 -#define __S010 PAGE_SHARED
9767 -#define __S011 PAGE_SHARED
9768 +#define __S001 PAGE_READONLY_NOEXEC
9769 +#define __S010 PAGE_SHARED_NOEXEC
9770 +#define __S011 PAGE_SHARED_NOEXEC
9771 #define __S100 PAGE_READONLY
9772 #define __S101 PAGE_READONLY
9773 #define __S110 PAGE_SHARED
9774 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9775 index 79da178..c2eede8 100644
9776 --- a/arch/sparc/include/asm/pgtsrmmu.h
9777 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9778 @@ -115,6 +115,11 @@
9779 SRMMU_EXEC | SRMMU_REF)
9780 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9781 SRMMU_EXEC | SRMMU_REF)
9782 +
9783 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9784 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9785 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9786 +
9787 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9788 SRMMU_DIRTY | SRMMU_REF)
9789
9790 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9791 index 9689176..63c18ea 100644
9792 --- a/arch/sparc/include/asm/spinlock_64.h
9793 +++ b/arch/sparc/include/asm/spinlock_64.h
9794 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9795
9796 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9797
9798 -static void inline arch_read_lock(arch_rwlock_t *lock)
9799 +static inline void arch_read_lock(arch_rwlock_t *lock)
9800 {
9801 unsigned long tmp1, tmp2;
9802
9803 __asm__ __volatile__ (
9804 "1: ldsw [%2], %0\n"
9805 " brlz,pn %0, 2f\n"
9806 -"4: add %0, 1, %1\n"
9807 +"4: addcc %0, 1, %1\n"
9808 +
9809 +#ifdef CONFIG_PAX_REFCOUNT
9810 +" tvs %%icc, 6\n"
9811 +#endif
9812 +
9813 " cas [%2], %0, %1\n"
9814 " cmp %0, %1\n"
9815 " bne,pn %%icc, 1b\n"
9816 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9817 " .previous"
9818 : "=&r" (tmp1), "=&r" (tmp2)
9819 : "r" (lock)
9820 - : "memory");
9821 + : "memory", "cc");
9822 }
9823
9824 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9825 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9826 {
9827 int tmp1, tmp2;
9828
9829 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9830 "1: ldsw [%2], %0\n"
9831 " brlz,a,pn %0, 2f\n"
9832 " mov 0, %0\n"
9833 -" add %0, 1, %1\n"
9834 +" addcc %0, 1, %1\n"
9835 +
9836 +#ifdef CONFIG_PAX_REFCOUNT
9837 +" tvs %%icc, 6\n"
9838 +#endif
9839 +
9840 " cas [%2], %0, %1\n"
9841 " cmp %0, %1\n"
9842 " bne,pn %%icc, 1b\n"
9843 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9844 return tmp1;
9845 }
9846
9847 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9848 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9849 {
9850 unsigned long tmp1, tmp2;
9851
9852 __asm__ __volatile__(
9853 "1: lduw [%2], %0\n"
9854 -" sub %0, 1, %1\n"
9855 +" subcc %0, 1, %1\n"
9856 +
9857 +#ifdef CONFIG_PAX_REFCOUNT
9858 +" tvs %%icc, 6\n"
9859 +#endif
9860 +
9861 " cas [%2], %0, %1\n"
9862 " cmp %0, %1\n"
9863 " bne,pn %%xcc, 1b\n"
9864 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9865 : "memory");
9866 }
9867
9868 -static void inline arch_write_lock(arch_rwlock_t *lock)
9869 +static inline void arch_write_lock(arch_rwlock_t *lock)
9870 {
9871 unsigned long mask, tmp1, tmp2;
9872
9873 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9874 : "memory");
9875 }
9876
9877 -static void inline arch_write_unlock(arch_rwlock_t *lock)
9878 +static inline void arch_write_unlock(arch_rwlock_t *lock)
9879 {
9880 __asm__ __volatile__(
9881 " stw %%g0, [%0]"
9882 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9883 : "memory");
9884 }
9885
9886 -static int inline arch_write_trylock(arch_rwlock_t *lock)
9887 +static inline int arch_write_trylock(arch_rwlock_t *lock)
9888 {
9889 unsigned long mask, tmp1, tmp2, result;
9890
9891 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9892 index 96efa7a..16858bf 100644
9893 --- a/arch/sparc/include/asm/thread_info_32.h
9894 +++ b/arch/sparc/include/asm/thread_info_32.h
9895 @@ -49,6 +49,8 @@ struct thread_info {
9896 unsigned long w_saved;
9897
9898 struct restart_block restart_block;
9899 +
9900 + unsigned long lowest_stack;
9901 };
9902
9903 /*
9904 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9905 index a5f01ac..703b554 100644
9906 --- a/arch/sparc/include/asm/thread_info_64.h
9907 +++ b/arch/sparc/include/asm/thread_info_64.h
9908 @@ -63,6 +63,8 @@ struct thread_info {
9909 struct pt_regs *kern_una_regs;
9910 unsigned int kern_una_insn;
9911
9912 + unsigned long lowest_stack;
9913 +
9914 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9915 };
9916
9917 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9918 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9919 /* flag bit 4 is available */
9920 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9921 -/* flag bit 6 is available */
9922 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9923 #define TIF_32BIT 7 /* 32-bit binary */
9924 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9925 #define TIF_SECCOMP 9 /* secure computing */
9926 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9927 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9928 +
9929 /* NOTE: Thread flags >= 12 should be ones we have no interest
9930 * in using in assembly, else we can't use the mask as
9931 * an immediate value in instructions such as andcc.
9932 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9933 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9934 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9935 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9936 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9937
9938 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9939 _TIF_DO_NOTIFY_RESUME_MASK | \
9940 _TIF_NEED_RESCHED)
9941 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9942
9943 +#define _TIF_WORK_SYSCALL \
9944 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9945 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9946 +
9947 +
9948 /*
9949 * Thread-synchronous status.
9950 *
9951 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9952 index 0167d26..767bb0c 100644
9953 --- a/arch/sparc/include/asm/uaccess.h
9954 +++ b/arch/sparc/include/asm/uaccess.h
9955 @@ -1,5 +1,6 @@
9956 #ifndef ___ASM_SPARC_UACCESS_H
9957 #define ___ASM_SPARC_UACCESS_H
9958 +
9959 #if defined(__sparc__) && defined(__arch64__)
9960 #include <asm/uaccess_64.h>
9961 #else
9962 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9963 index 53a28dd..50c38c3 100644
9964 --- a/arch/sparc/include/asm/uaccess_32.h
9965 +++ b/arch/sparc/include/asm/uaccess_32.h
9966 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9967
9968 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9969 {
9970 - if (n && __access_ok((unsigned long) to, n))
9971 + if ((long)n < 0)
9972 + return n;
9973 +
9974 + if (n && __access_ok((unsigned long) to, n)) {
9975 + if (!__builtin_constant_p(n))
9976 + check_object_size(from, n, true);
9977 return __copy_user(to, (__force void __user *) from, n);
9978 - else
9979 + } else
9980 return n;
9981 }
9982
9983 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9984 {
9985 + if ((long)n < 0)
9986 + return n;
9987 +
9988 + if (!__builtin_constant_p(n))
9989 + check_object_size(from, n, true);
9990 +
9991 return __copy_user(to, (__force void __user *) from, n);
9992 }
9993
9994 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9995 {
9996 - if (n && __access_ok((unsigned long) from, n))
9997 + if ((long)n < 0)
9998 + return n;
9999 +
10000 + if (n && __access_ok((unsigned long) from, n)) {
10001 + if (!__builtin_constant_p(n))
10002 + check_object_size(to, n, false);
10003 return __copy_user((__force void __user *) to, from, n);
10004 - else
10005 + } else
10006 return n;
10007 }
10008
10009 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10010 {
10011 + if ((long)n < 0)
10012 + return n;
10013 +
10014 return __copy_user((__force void __user *) to, from, n);
10015 }
10016
10017 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10018 index ad7e178..c9e7423 100644
10019 --- a/arch/sparc/include/asm/uaccess_64.h
10020 +++ b/arch/sparc/include/asm/uaccess_64.h
10021 @@ -10,6 +10,7 @@
10022 #include <linux/compiler.h>
10023 #include <linux/string.h>
10024 #include <linux/thread_info.h>
10025 +#include <linux/kernel.h>
10026 #include <asm/asi.h>
10027 #include <asm/spitfire.h>
10028 #include <asm-generic/uaccess-unaligned.h>
10029 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10030 static inline unsigned long __must_check
10031 copy_from_user(void *to, const void __user *from, unsigned long size)
10032 {
10033 - unsigned long ret = ___copy_from_user(to, from, size);
10034 + unsigned long ret;
10035
10036 + if ((long)size < 0 || size > INT_MAX)
10037 + return size;
10038 +
10039 + if (!__builtin_constant_p(size))
10040 + check_object_size(to, size, false);
10041 +
10042 + ret = ___copy_from_user(to, from, size);
10043 if (unlikely(ret))
10044 ret = copy_from_user_fixup(to, from, size);
10045
10046 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10047 static inline unsigned long __must_check
10048 copy_to_user(void __user *to, const void *from, unsigned long size)
10049 {
10050 - unsigned long ret = ___copy_to_user(to, from, size);
10051 + unsigned long ret;
10052
10053 + if ((long)size < 0 || size > INT_MAX)
10054 + return size;
10055 +
10056 + if (!__builtin_constant_p(size))
10057 + check_object_size(from, size, true);
10058 +
10059 + ret = ___copy_to_user(to, from, size);
10060 if (unlikely(ret))
10061 ret = copy_to_user_fixup(to, from, size);
10062 return ret;
10063 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10064 index d15cc17..d0ae796 100644
10065 --- a/arch/sparc/kernel/Makefile
10066 +++ b/arch/sparc/kernel/Makefile
10067 @@ -4,7 +4,7 @@
10068 #
10069
10070 asflags-y := -ansi
10071 -ccflags-y := -Werror
10072 +#ccflags-y := -Werror
10073
10074 extra-y := head_$(BITS).o
10075
10076 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10077 index fdd819d..5af08c8 100644
10078 --- a/arch/sparc/kernel/process_32.c
10079 +++ b/arch/sparc/kernel/process_32.c
10080 @@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
10081
10082 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10083 r->psr, r->pc, r->npc, r->y, print_tainted());
10084 - printk("PC: <%pS>\n", (void *) r->pc);
10085 + printk("PC: <%pA>\n", (void *) r->pc);
10086 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10087 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10088 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10089 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10090 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10091 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10092 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10093 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10094
10095 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10096 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10097 @@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10098 rw = (struct reg_window32 *) fp;
10099 pc = rw->ins[7];
10100 printk("[%08lx : ", pc);
10101 - printk("%pS ] ", (void *) pc);
10102 + printk("%pA ] ", (void *) pc);
10103 fp = rw->ins[6];
10104 } while (++count < 16);
10105 printk("\n");
10106 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10107 index 32a280e..84fc6a9 100644
10108 --- a/arch/sparc/kernel/process_64.c
10109 +++ b/arch/sparc/kernel/process_64.c
10110 @@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
10111 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10112 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10113 if (regs->tstate & TSTATE_PRIV)
10114 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10115 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10116 }
10117
10118 void show_regs(struct pt_regs *regs)
10119 @@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
10120
10121 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10122 regs->tpc, regs->tnpc, regs->y, print_tainted());
10123 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10124 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10125 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10126 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10127 regs->u_regs[3]);
10128 @@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
10129 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10130 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10131 regs->u_regs[15]);
10132 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10133 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10134 show_regwindow(regs);
10135 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10136 }
10137 @@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
10138 ((tp && tp->task) ? tp->task->pid : -1));
10139
10140 if (gp->tstate & TSTATE_PRIV) {
10141 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10142 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10143 (void *) gp->tpc,
10144 (void *) gp->o7,
10145 (void *) gp->i7,
10146 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10147 index 79cc0d1..ec62734 100644
10148 --- a/arch/sparc/kernel/prom_common.c
10149 +++ b/arch/sparc/kernel/prom_common.c
10150 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10151
10152 unsigned int prom_early_allocated __initdata;
10153
10154 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10155 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10156 .nextprop = prom_common_nextprop,
10157 .getproplen = prom_getproplen,
10158 .getproperty = prom_getproperty,
10159 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10160 index c13c9f2..d572c34 100644
10161 --- a/arch/sparc/kernel/ptrace_64.c
10162 +++ b/arch/sparc/kernel/ptrace_64.c
10163 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10164 return ret;
10165 }
10166
10167 +#ifdef CONFIG_GRKERNSEC_SETXID
10168 +extern void gr_delayed_cred_worker(void);
10169 +#endif
10170 +
10171 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10172 {
10173 int ret = 0;
10174 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10175 if (test_thread_flag(TIF_NOHZ))
10176 user_exit();
10177
10178 +#ifdef CONFIG_GRKERNSEC_SETXID
10179 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10180 + gr_delayed_cred_worker();
10181 +#endif
10182 +
10183 if (test_thread_flag(TIF_SYSCALL_TRACE))
10184 ret = tracehook_report_syscall_entry(regs);
10185
10186 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10187 if (test_thread_flag(TIF_NOHZ))
10188 user_exit();
10189
10190 +#ifdef CONFIG_GRKERNSEC_SETXID
10191 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10192 + gr_delayed_cred_worker();
10193 +#endif
10194 +
10195 audit_syscall_exit(regs);
10196
10197 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10198 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10199 index b085311..6f885f7 100644
10200 --- a/arch/sparc/kernel/smp_64.c
10201 +++ b/arch/sparc/kernel/smp_64.c
10202 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10203 extern unsigned long xcall_flush_dcache_page_spitfire;
10204
10205 #ifdef CONFIG_DEBUG_DCFLUSH
10206 -extern atomic_t dcpage_flushes;
10207 -extern atomic_t dcpage_flushes_xcall;
10208 +extern atomic_unchecked_t dcpage_flushes;
10209 +extern atomic_unchecked_t dcpage_flushes_xcall;
10210 #endif
10211
10212 static inline void __local_flush_dcache_page(struct page *page)
10213 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10214 return;
10215
10216 #ifdef CONFIG_DEBUG_DCFLUSH
10217 - atomic_inc(&dcpage_flushes);
10218 + atomic_inc_unchecked(&dcpage_flushes);
10219 #endif
10220
10221 this_cpu = get_cpu();
10222 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10223 xcall_deliver(data0, __pa(pg_addr),
10224 (u64) pg_addr, cpumask_of(cpu));
10225 #ifdef CONFIG_DEBUG_DCFLUSH
10226 - atomic_inc(&dcpage_flushes_xcall);
10227 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10228 #endif
10229 }
10230 }
10231 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10232 preempt_disable();
10233
10234 #ifdef CONFIG_DEBUG_DCFLUSH
10235 - atomic_inc(&dcpage_flushes);
10236 + atomic_inc_unchecked(&dcpage_flushes);
10237 #endif
10238 data0 = 0;
10239 pg_addr = page_address(page);
10240 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10241 xcall_deliver(data0, __pa(pg_addr),
10242 (u64) pg_addr, cpu_online_mask);
10243 #ifdef CONFIG_DEBUG_DCFLUSH
10244 - atomic_inc(&dcpage_flushes_xcall);
10245 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10246 #endif
10247 }
10248 __local_flush_dcache_page(page);
10249 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10250 index 3a8d184..49498a8 100644
10251 --- a/arch/sparc/kernel/sys_sparc_32.c
10252 +++ b/arch/sparc/kernel/sys_sparc_32.c
10253 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10254 if (len > TASK_SIZE - PAGE_SIZE)
10255 return -ENOMEM;
10256 if (!addr)
10257 - addr = TASK_UNMAPPED_BASE;
10258 + addr = current->mm->mmap_base;
10259
10260 info.flags = 0;
10261 info.length = len;
10262 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10263 index beb0b5a..5a153f7 100644
10264 --- a/arch/sparc/kernel/sys_sparc_64.c
10265 +++ b/arch/sparc/kernel/sys_sparc_64.c
10266 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10267 struct vm_area_struct * vma;
10268 unsigned long task_size = TASK_SIZE;
10269 int do_color_align;
10270 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10271 struct vm_unmapped_area_info info;
10272
10273 if (flags & MAP_FIXED) {
10274 /* We do not accept a shared mapping if it would violate
10275 * cache aliasing constraints.
10276 */
10277 - if ((flags & MAP_SHARED) &&
10278 + if ((filp || (flags & MAP_SHARED)) &&
10279 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10280 return -EINVAL;
10281 return addr;
10282 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10283 if (filp || (flags & MAP_SHARED))
10284 do_color_align = 1;
10285
10286 +#ifdef CONFIG_PAX_RANDMMAP
10287 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10288 +#endif
10289 +
10290 if (addr) {
10291 if (do_color_align)
10292 addr = COLOR_ALIGN(addr, pgoff);
10293 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10294 addr = PAGE_ALIGN(addr);
10295
10296 vma = find_vma(mm, addr);
10297 - if (task_size - len >= addr &&
10298 - (!vma || addr + len <= vma->vm_start))
10299 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10300 return addr;
10301 }
10302
10303 info.flags = 0;
10304 info.length = len;
10305 - info.low_limit = TASK_UNMAPPED_BASE;
10306 + info.low_limit = mm->mmap_base;
10307 info.high_limit = min(task_size, VA_EXCLUDE_START);
10308 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10309 info.align_offset = pgoff << PAGE_SHIFT;
10310 + info.threadstack_offset = offset;
10311 addr = vm_unmapped_area(&info);
10312
10313 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10314 VM_BUG_ON(addr != -ENOMEM);
10315 info.low_limit = VA_EXCLUDE_END;
10316 +
10317 +#ifdef CONFIG_PAX_RANDMMAP
10318 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10319 + info.low_limit += mm->delta_mmap;
10320 +#endif
10321 +
10322 info.high_limit = task_size;
10323 addr = vm_unmapped_area(&info);
10324 }
10325 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10326 unsigned long task_size = STACK_TOP32;
10327 unsigned long addr = addr0;
10328 int do_color_align;
10329 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10330 struct vm_unmapped_area_info info;
10331
10332 /* This should only ever run for 32-bit processes. */
10333 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10334 /* We do not accept a shared mapping if it would violate
10335 * cache aliasing constraints.
10336 */
10337 - if ((flags & MAP_SHARED) &&
10338 + if ((filp || (flags & MAP_SHARED)) &&
10339 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10340 return -EINVAL;
10341 return addr;
10342 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10343 if (filp || (flags & MAP_SHARED))
10344 do_color_align = 1;
10345
10346 +#ifdef CONFIG_PAX_RANDMMAP
10347 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10348 +#endif
10349 +
10350 /* requesting a specific address */
10351 if (addr) {
10352 if (do_color_align)
10353 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10354 addr = PAGE_ALIGN(addr);
10355
10356 vma = find_vma(mm, addr);
10357 - if (task_size - len >= addr &&
10358 - (!vma || addr + len <= vma->vm_start))
10359 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10360 return addr;
10361 }
10362
10363 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10364 info.high_limit = mm->mmap_base;
10365 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10366 info.align_offset = pgoff << PAGE_SHIFT;
10367 + info.threadstack_offset = offset;
10368 addr = vm_unmapped_area(&info);
10369
10370 /*
10371 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10372 VM_BUG_ON(addr != -ENOMEM);
10373 info.flags = 0;
10374 info.low_limit = TASK_UNMAPPED_BASE;
10375 +
10376 +#ifdef CONFIG_PAX_RANDMMAP
10377 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10378 + info.low_limit += mm->delta_mmap;
10379 +#endif
10380 +
10381 info.high_limit = STACK_TOP32;
10382 addr = vm_unmapped_area(&info);
10383 }
10384 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10385 EXPORT_SYMBOL(get_fb_unmapped_area);
10386
10387 /* Essentially the same as PowerPC. */
10388 -static unsigned long mmap_rnd(void)
10389 +static unsigned long mmap_rnd(struct mm_struct *mm)
10390 {
10391 unsigned long rnd = 0UL;
10392
10393 +#ifdef CONFIG_PAX_RANDMMAP
10394 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10395 +#endif
10396 +
10397 if (current->flags & PF_RANDOMIZE) {
10398 unsigned long val = get_random_int();
10399 if (test_thread_flag(TIF_32BIT))
10400 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10401
10402 void arch_pick_mmap_layout(struct mm_struct *mm)
10403 {
10404 - unsigned long random_factor = mmap_rnd();
10405 + unsigned long random_factor = mmap_rnd(mm);
10406 unsigned long gap;
10407
10408 /*
10409 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10410 gap == RLIM_INFINITY ||
10411 sysctl_legacy_va_layout) {
10412 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10413 +
10414 +#ifdef CONFIG_PAX_RANDMMAP
10415 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10416 + mm->mmap_base += mm->delta_mmap;
10417 +#endif
10418 +
10419 mm->get_unmapped_area = arch_get_unmapped_area;
10420 } else {
10421 /* We know it's 32-bit */
10422 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10423 gap = (task_size / 6 * 5);
10424
10425 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10426 +
10427 +#ifdef CONFIG_PAX_RANDMMAP
10428 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10429 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10430 +#endif
10431 +
10432 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10433 }
10434 }
10435 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10436 index 87729ff..192f9d8 100644
10437 --- a/arch/sparc/kernel/syscalls.S
10438 +++ b/arch/sparc/kernel/syscalls.S
10439 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10440 #endif
10441 .align 32
10442 1: ldx [%g6 + TI_FLAGS], %l5
10443 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10444 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10445 be,pt %icc, rtrap
10446 nop
10447 call syscall_trace_leave
10448 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10449
10450 srl %i3, 0, %o3 ! IEU0
10451 srl %i2, 0, %o2 ! IEU0 Group
10452 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10453 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10454 bne,pn %icc, linux_syscall_trace32 ! CTI
10455 mov %i0, %l5 ! IEU1
10456 5: call %l7 ! CTI Group brk forced
10457 @@ -207,7 +207,7 @@ linux_sparc_syscall:
10458
10459 mov %i3, %o3 ! IEU1
10460 mov %i4, %o4 ! IEU0 Group
10461 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10462 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10463 bne,pn %icc, linux_syscall_trace ! CTI Group
10464 mov %i0, %l5 ! IEU0
10465 2: call %l7 ! CTI Group brk forced
10466 @@ -223,7 +223,7 @@ ret_sys_call:
10467
10468 cmp %o0, -ERESTART_RESTARTBLOCK
10469 bgeu,pn %xcc, 1f
10470 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10471 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10472 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10473
10474 2:
10475 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10476 index 6629829..036032d 100644
10477 --- a/arch/sparc/kernel/traps_32.c
10478 +++ b/arch/sparc/kernel/traps_32.c
10479 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10480 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10481 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10482
10483 +extern void gr_handle_kernel_exploit(void);
10484 +
10485 void die_if_kernel(char *str, struct pt_regs *regs)
10486 {
10487 static int die_counter;
10488 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10489 count++ < 30 &&
10490 (((unsigned long) rw) >= PAGE_OFFSET) &&
10491 !(((unsigned long) rw) & 0x7)) {
10492 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10493 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10494 (void *) rw->ins[7]);
10495 rw = (struct reg_window32 *)rw->ins[6];
10496 }
10497 }
10498 printk("Instruction DUMP:");
10499 instruction_dump ((unsigned long *) regs->pc);
10500 - if(regs->psr & PSR_PS)
10501 + if(regs->psr & PSR_PS) {
10502 + gr_handle_kernel_exploit();
10503 do_exit(SIGKILL);
10504 + }
10505 do_exit(SIGSEGV);
10506 }
10507
10508 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10509 index 4ced92f..965eeed 100644
10510 --- a/arch/sparc/kernel/traps_64.c
10511 +++ b/arch/sparc/kernel/traps_64.c
10512 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10513 i + 1,
10514 p->trapstack[i].tstate, p->trapstack[i].tpc,
10515 p->trapstack[i].tnpc, p->trapstack[i].tt);
10516 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10517 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10518 }
10519 }
10520
10521 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10522
10523 lvl -= 0x100;
10524 if (regs->tstate & TSTATE_PRIV) {
10525 +
10526 +#ifdef CONFIG_PAX_REFCOUNT
10527 + if (lvl == 6)
10528 + pax_report_refcount_overflow(regs);
10529 +#endif
10530 +
10531 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10532 die_if_kernel(buffer, regs);
10533 }
10534 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10535 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10536 {
10537 char buffer[32];
10538 -
10539 +
10540 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10541 0, lvl, SIGTRAP) == NOTIFY_STOP)
10542 return;
10543
10544 +#ifdef CONFIG_PAX_REFCOUNT
10545 + if (lvl == 6)
10546 + pax_report_refcount_overflow(regs);
10547 +#endif
10548 +
10549 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10550
10551 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10552 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10553 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10554 printk("%s" "ERROR(%d): ",
10555 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10556 - printk("TPC<%pS>\n", (void *) regs->tpc);
10557 + printk("TPC<%pA>\n", (void *) regs->tpc);
10558 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10559 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10560 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10561 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10562 smp_processor_id(),
10563 (type & 0x1) ? 'I' : 'D',
10564 regs->tpc);
10565 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10566 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10567 panic("Irrecoverable Cheetah+ parity error.");
10568 }
10569
10570 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10571 smp_processor_id(),
10572 (type & 0x1) ? 'I' : 'D',
10573 regs->tpc);
10574 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10575 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10576 }
10577
10578 struct sun4v_error_entry {
10579 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10580 /*0x38*/u64 reserved_5;
10581 };
10582
10583 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10584 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10585 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10586 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10587
10588 static const char *sun4v_err_type_to_str(u8 type)
10589 {
10590 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10591 }
10592
10593 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10594 - int cpu, const char *pfx, atomic_t *ocnt)
10595 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10596 {
10597 u64 *raw_ptr = (u64 *) ent;
10598 u32 attrs;
10599 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10600
10601 show_regs(regs);
10602
10603 - if ((cnt = atomic_read(ocnt)) != 0) {
10604 - atomic_set(ocnt, 0);
10605 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10606 + atomic_set_unchecked(ocnt, 0);
10607 wmb();
10608 printk("%s: Queue overflowed %d times.\n",
10609 pfx, cnt);
10610 @@ -2046,7 +2057,7 @@ out:
10611 */
10612 void sun4v_resum_overflow(struct pt_regs *regs)
10613 {
10614 - atomic_inc(&sun4v_resum_oflow_cnt);
10615 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10616 }
10617
10618 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10619 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10620 /* XXX Actually even this can make not that much sense. Perhaps
10621 * XXX we should just pull the plug and panic directly from here?
10622 */
10623 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10624 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10625 }
10626
10627 unsigned long sun4v_err_itlb_vaddr;
10628 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10629
10630 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10631 regs->tpc, tl);
10632 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10633 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10634 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10635 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10636 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10637 (void *) regs->u_regs[UREG_I7]);
10638 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10639 "pte[%lx] error[%lx]\n",
10640 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10641
10642 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10643 regs->tpc, tl);
10644 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10645 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10646 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10647 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10648 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10649 (void *) regs->u_regs[UREG_I7]);
10650 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10651 "pte[%lx] error[%lx]\n",
10652 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10653 fp = (unsigned long)sf->fp + STACK_BIAS;
10654 }
10655
10656 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10657 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10658 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10659 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10660 int index = tsk->curr_ret_stack;
10661 if (tsk->ret_stack && index >= graph) {
10662 pc = tsk->ret_stack[index - graph].ret;
10663 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10664 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10665 graph++;
10666 }
10667 }
10668 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10669 return (struct reg_window *) (fp + STACK_BIAS);
10670 }
10671
10672 +extern void gr_handle_kernel_exploit(void);
10673 +
10674 void die_if_kernel(char *str, struct pt_regs *regs)
10675 {
10676 static int die_counter;
10677 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10678 while (rw &&
10679 count++ < 30 &&
10680 kstack_valid(tp, (unsigned long) rw)) {
10681 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10682 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10683 (void *) rw->ins[7]);
10684
10685 rw = kernel_stack_up(rw);
10686 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10687 }
10688 user_instruction_dump ((unsigned int __user *) regs->tpc);
10689 }
10690 - if (regs->tstate & TSTATE_PRIV)
10691 + if (regs->tstate & TSTATE_PRIV) {
10692 + gr_handle_kernel_exploit();
10693 do_exit(SIGKILL);
10694 + }
10695 do_exit(SIGSEGV);
10696 }
10697 EXPORT_SYMBOL(die_if_kernel);
10698 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10699 index 3c1a7cb..73e1923 100644
10700 --- a/arch/sparc/kernel/unaligned_64.c
10701 +++ b/arch/sparc/kernel/unaligned_64.c
10702 @@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10703 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10704
10705 if (__ratelimit(&ratelimit)) {
10706 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10707 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10708 regs->tpc, (void *) regs->tpc);
10709 }
10710 }
10711 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10712 index dbe119b..089c7c1 100644
10713 --- a/arch/sparc/lib/Makefile
10714 +++ b/arch/sparc/lib/Makefile
10715 @@ -2,7 +2,7 @@
10716 #
10717
10718 asflags-y := -ansi -DST_DIV0=0x02
10719 -ccflags-y := -Werror
10720 +#ccflags-y := -Werror
10721
10722 lib-$(CONFIG_SPARC32) += ashrdi3.o
10723 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10724 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10725 index 85c233d..68500e0 100644
10726 --- a/arch/sparc/lib/atomic_64.S
10727 +++ b/arch/sparc/lib/atomic_64.S
10728 @@ -17,7 +17,12 @@
10729 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10730 BACKOFF_SETUP(%o2)
10731 1: lduw [%o1], %g1
10732 - add %g1, %o0, %g7
10733 + addcc %g1, %o0, %g7
10734 +
10735 +#ifdef CONFIG_PAX_REFCOUNT
10736 + tvs %icc, 6
10737 +#endif
10738 +
10739 cas [%o1], %g1, %g7
10740 cmp %g1, %g7
10741 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10742 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10743 2: BACKOFF_SPIN(%o2, %o3, 1b)
10744 ENDPROC(atomic_add)
10745
10746 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10747 + BACKOFF_SETUP(%o2)
10748 +1: lduw [%o1], %g1
10749 + add %g1, %o0, %g7
10750 + cas [%o1], %g1, %g7
10751 + cmp %g1, %g7
10752 + bne,pn %icc, 2f
10753 + nop
10754 + retl
10755 + nop
10756 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10757 +ENDPROC(atomic_add_unchecked)
10758 +
10759 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10760 BACKOFF_SETUP(%o2)
10761 1: lduw [%o1], %g1
10762 - sub %g1, %o0, %g7
10763 + subcc %g1, %o0, %g7
10764 +
10765 +#ifdef CONFIG_PAX_REFCOUNT
10766 + tvs %icc, 6
10767 +#endif
10768 +
10769 cas [%o1], %g1, %g7
10770 cmp %g1, %g7
10771 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10772 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10773 2: BACKOFF_SPIN(%o2, %o3, 1b)
10774 ENDPROC(atomic_sub)
10775
10776 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10777 + BACKOFF_SETUP(%o2)
10778 +1: lduw [%o1], %g1
10779 + sub %g1, %o0, %g7
10780 + cas [%o1], %g1, %g7
10781 + cmp %g1, %g7
10782 + bne,pn %icc, 2f
10783 + nop
10784 + retl
10785 + nop
10786 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10787 +ENDPROC(atomic_sub_unchecked)
10788 +
10789 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10790 BACKOFF_SETUP(%o2)
10791 1: lduw [%o1], %g1
10792 - add %g1, %o0, %g7
10793 + addcc %g1, %o0, %g7
10794 +
10795 +#ifdef CONFIG_PAX_REFCOUNT
10796 + tvs %icc, 6
10797 +#endif
10798 +
10799 cas [%o1], %g1, %g7
10800 cmp %g1, %g7
10801 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10802 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10803 2: BACKOFF_SPIN(%o2, %o3, 1b)
10804 ENDPROC(atomic_add_ret)
10805
10806 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10807 + BACKOFF_SETUP(%o2)
10808 +1: lduw [%o1], %g1
10809 + addcc %g1, %o0, %g7
10810 + cas [%o1], %g1, %g7
10811 + cmp %g1, %g7
10812 + bne,pn %icc, 2f
10813 + add %g7, %o0, %g7
10814 + sra %g7, 0, %o0
10815 + retl
10816 + nop
10817 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10818 +ENDPROC(atomic_add_ret_unchecked)
10819 +
10820 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10821 BACKOFF_SETUP(%o2)
10822 1: lduw [%o1], %g1
10823 - sub %g1, %o0, %g7
10824 + subcc %g1, %o0, %g7
10825 +
10826 +#ifdef CONFIG_PAX_REFCOUNT
10827 + tvs %icc, 6
10828 +#endif
10829 +
10830 cas [%o1], %g1, %g7
10831 cmp %g1, %g7
10832 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10833 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10834 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10835 BACKOFF_SETUP(%o2)
10836 1: ldx [%o1], %g1
10837 - add %g1, %o0, %g7
10838 + addcc %g1, %o0, %g7
10839 +
10840 +#ifdef CONFIG_PAX_REFCOUNT
10841 + tvs %xcc, 6
10842 +#endif
10843 +
10844 casx [%o1], %g1, %g7
10845 cmp %g1, %g7
10846 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10847 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10848 2: BACKOFF_SPIN(%o2, %o3, 1b)
10849 ENDPROC(atomic64_add)
10850
10851 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10852 + BACKOFF_SETUP(%o2)
10853 +1: ldx [%o1], %g1
10854 + addcc %g1, %o0, %g7
10855 + casx [%o1], %g1, %g7
10856 + cmp %g1, %g7
10857 + bne,pn %xcc, 2f
10858 + nop
10859 + retl
10860 + nop
10861 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10862 +ENDPROC(atomic64_add_unchecked)
10863 +
10864 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10865 BACKOFF_SETUP(%o2)
10866 1: ldx [%o1], %g1
10867 - sub %g1, %o0, %g7
10868 + subcc %g1, %o0, %g7
10869 +
10870 +#ifdef CONFIG_PAX_REFCOUNT
10871 + tvs %xcc, 6
10872 +#endif
10873 +
10874 casx [%o1], %g1, %g7
10875 cmp %g1, %g7
10876 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10877 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10878 2: BACKOFF_SPIN(%o2, %o3, 1b)
10879 ENDPROC(atomic64_sub)
10880
10881 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10882 + BACKOFF_SETUP(%o2)
10883 +1: ldx [%o1], %g1
10884 + subcc %g1, %o0, %g7
10885 + casx [%o1], %g1, %g7
10886 + cmp %g1, %g7
10887 + bne,pn %xcc, 2f
10888 + nop
10889 + retl
10890 + nop
10891 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10892 +ENDPROC(atomic64_sub_unchecked)
10893 +
10894 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10895 BACKOFF_SETUP(%o2)
10896 1: ldx [%o1], %g1
10897 - add %g1, %o0, %g7
10898 + addcc %g1, %o0, %g7
10899 +
10900 +#ifdef CONFIG_PAX_REFCOUNT
10901 + tvs %xcc, 6
10902 +#endif
10903 +
10904 casx [%o1], %g1, %g7
10905 cmp %g1, %g7
10906 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10907 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10908 2: BACKOFF_SPIN(%o2, %o3, 1b)
10909 ENDPROC(atomic64_add_ret)
10910
10911 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10912 + BACKOFF_SETUP(%o2)
10913 +1: ldx [%o1], %g1
10914 + addcc %g1, %o0, %g7
10915 + casx [%o1], %g1, %g7
10916 + cmp %g1, %g7
10917 + bne,pn %xcc, 2f
10918 + add %g7, %o0, %g7
10919 + mov %g7, %o0
10920 + retl
10921 + nop
10922 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10923 +ENDPROC(atomic64_add_ret_unchecked)
10924 +
10925 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10926 BACKOFF_SETUP(%o2)
10927 1: ldx [%o1], %g1
10928 - sub %g1, %o0, %g7
10929 + subcc %g1, %o0, %g7
10930 +
10931 +#ifdef CONFIG_PAX_REFCOUNT
10932 + tvs %xcc, 6
10933 +#endif
10934 +
10935 casx [%o1], %g1, %g7
10936 cmp %g1, %g7
10937 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10938 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10939 index 323335b..ed85ea2 100644
10940 --- a/arch/sparc/lib/ksyms.c
10941 +++ b/arch/sparc/lib/ksyms.c
10942 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10943
10944 /* Atomic counter implementation. */
10945 EXPORT_SYMBOL(atomic_add);
10946 +EXPORT_SYMBOL(atomic_add_unchecked);
10947 EXPORT_SYMBOL(atomic_add_ret);
10948 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
10949 EXPORT_SYMBOL(atomic_sub);
10950 +EXPORT_SYMBOL(atomic_sub_unchecked);
10951 EXPORT_SYMBOL(atomic_sub_ret);
10952 EXPORT_SYMBOL(atomic64_add);
10953 +EXPORT_SYMBOL(atomic64_add_unchecked);
10954 EXPORT_SYMBOL(atomic64_add_ret);
10955 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10956 EXPORT_SYMBOL(atomic64_sub);
10957 +EXPORT_SYMBOL(atomic64_sub_unchecked);
10958 EXPORT_SYMBOL(atomic64_sub_ret);
10959 EXPORT_SYMBOL(atomic64_dec_if_positive);
10960
10961 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10962 index 30c3ecc..736f015 100644
10963 --- a/arch/sparc/mm/Makefile
10964 +++ b/arch/sparc/mm/Makefile
10965 @@ -2,7 +2,7 @@
10966 #
10967
10968 asflags-y := -ansi
10969 -ccflags-y := -Werror
10970 +#ccflags-y := -Werror
10971
10972 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10973 obj-y += fault_$(BITS).o
10974 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10975 index 59dbd46..1dd7f5e 100644
10976 --- a/arch/sparc/mm/fault_32.c
10977 +++ b/arch/sparc/mm/fault_32.c
10978 @@ -21,6 +21,9 @@
10979 #include <linux/perf_event.h>
10980 #include <linux/interrupt.h>
10981 #include <linux/kdebug.h>
10982 +#include <linux/slab.h>
10983 +#include <linux/pagemap.h>
10984 +#include <linux/compiler.h>
10985
10986 #include <asm/page.h>
10987 #include <asm/pgtable.h>
10988 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10989 return safe_compute_effective_address(regs, insn);
10990 }
10991
10992 +#ifdef CONFIG_PAX_PAGEEXEC
10993 +#ifdef CONFIG_PAX_DLRESOLVE
10994 +static void pax_emuplt_close(struct vm_area_struct *vma)
10995 +{
10996 + vma->vm_mm->call_dl_resolve = 0UL;
10997 +}
10998 +
10999 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11000 +{
11001 + unsigned int *kaddr;
11002 +
11003 + vmf->page = alloc_page(GFP_HIGHUSER);
11004 + if (!vmf->page)
11005 + return VM_FAULT_OOM;
11006 +
11007 + kaddr = kmap(vmf->page);
11008 + memset(kaddr, 0, PAGE_SIZE);
11009 + kaddr[0] = 0x9DE3BFA8U; /* save */
11010 + flush_dcache_page(vmf->page);
11011 + kunmap(vmf->page);
11012 + return VM_FAULT_MAJOR;
11013 +}
11014 +
11015 +static const struct vm_operations_struct pax_vm_ops = {
11016 + .close = pax_emuplt_close,
11017 + .fault = pax_emuplt_fault
11018 +};
11019 +
11020 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11021 +{
11022 + int ret;
11023 +
11024 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11025 + vma->vm_mm = current->mm;
11026 + vma->vm_start = addr;
11027 + vma->vm_end = addr + PAGE_SIZE;
11028 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11029 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11030 + vma->vm_ops = &pax_vm_ops;
11031 +
11032 + ret = insert_vm_struct(current->mm, vma);
11033 + if (ret)
11034 + return ret;
11035 +
11036 + ++current->mm->total_vm;
11037 + return 0;
11038 +}
11039 +#endif
11040 +
11041 +/*
11042 + * PaX: decide what to do with offenders (regs->pc = fault address)
11043 + *
11044 + * returns 1 when task should be killed
11045 + * 2 when patched PLT trampoline was detected
11046 + * 3 when unpatched PLT trampoline was detected
11047 + */
11048 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11049 +{
11050 +
11051 +#ifdef CONFIG_PAX_EMUPLT
11052 + int err;
11053 +
11054 + do { /* PaX: patched PLT emulation #1 */
11055 + unsigned int sethi1, sethi2, jmpl;
11056 +
11057 + err = get_user(sethi1, (unsigned int *)regs->pc);
11058 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11059 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11060 +
11061 + if (err)
11062 + break;
11063 +
11064 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11065 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11066 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11067 + {
11068 + unsigned int addr;
11069 +
11070 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11071 + addr = regs->u_regs[UREG_G1];
11072 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11073 + regs->pc = addr;
11074 + regs->npc = addr+4;
11075 + return 2;
11076 + }
11077 + } while (0);
11078 +
11079 + do { /* PaX: patched PLT emulation #2 */
11080 + unsigned int ba;
11081 +
11082 + err = get_user(ba, (unsigned int *)regs->pc);
11083 +
11084 + if (err)
11085 + break;
11086 +
11087 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11088 + unsigned int addr;
11089 +
11090 + if ((ba & 0xFFC00000U) == 0x30800000U)
11091 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11092 + else
11093 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11094 + regs->pc = addr;
11095 + regs->npc = addr+4;
11096 + return 2;
11097 + }
11098 + } while (0);
11099 +
11100 + do { /* PaX: patched PLT emulation #3 */
11101 + unsigned int sethi, bajmpl, nop;
11102 +
11103 + err = get_user(sethi, (unsigned int *)regs->pc);
11104 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11105 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11106 +
11107 + if (err)
11108 + break;
11109 +
11110 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11111 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11112 + nop == 0x01000000U)
11113 + {
11114 + unsigned int addr;
11115 +
11116 + addr = (sethi & 0x003FFFFFU) << 10;
11117 + regs->u_regs[UREG_G1] = addr;
11118 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11119 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11120 + else
11121 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11122 + regs->pc = addr;
11123 + regs->npc = addr+4;
11124 + return 2;
11125 + }
11126 + } while (0);
11127 +
11128 + do { /* PaX: unpatched PLT emulation step 1 */
11129 + unsigned int sethi, ba, nop;
11130 +
11131 + err = get_user(sethi, (unsigned int *)regs->pc);
11132 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11133 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11134 +
11135 + if (err)
11136 + break;
11137 +
11138 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11139 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11140 + nop == 0x01000000U)
11141 + {
11142 + unsigned int addr, save, call;
11143 +
11144 + if ((ba & 0xFFC00000U) == 0x30800000U)
11145 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11146 + else
11147 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11148 +
11149 + err = get_user(save, (unsigned int *)addr);
11150 + err |= get_user(call, (unsigned int *)(addr+4));
11151 + err |= get_user(nop, (unsigned int *)(addr+8));
11152 + if (err)
11153 + break;
11154 +
11155 +#ifdef CONFIG_PAX_DLRESOLVE
11156 + if (save == 0x9DE3BFA8U &&
11157 + (call & 0xC0000000U) == 0x40000000U &&
11158 + nop == 0x01000000U)
11159 + {
11160 + struct vm_area_struct *vma;
11161 + unsigned long call_dl_resolve;
11162 +
11163 + down_read(&current->mm->mmap_sem);
11164 + call_dl_resolve = current->mm->call_dl_resolve;
11165 + up_read(&current->mm->mmap_sem);
11166 + if (likely(call_dl_resolve))
11167 + goto emulate;
11168 +
11169 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11170 +
11171 + down_write(&current->mm->mmap_sem);
11172 + if (current->mm->call_dl_resolve) {
11173 + call_dl_resolve = current->mm->call_dl_resolve;
11174 + up_write(&current->mm->mmap_sem);
11175 + if (vma)
11176 + kmem_cache_free(vm_area_cachep, vma);
11177 + goto emulate;
11178 + }
11179 +
11180 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11181 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11182 + up_write(&current->mm->mmap_sem);
11183 + if (vma)
11184 + kmem_cache_free(vm_area_cachep, vma);
11185 + return 1;
11186 + }
11187 +
11188 + if (pax_insert_vma(vma, call_dl_resolve)) {
11189 + up_write(&current->mm->mmap_sem);
11190 + kmem_cache_free(vm_area_cachep, vma);
11191 + return 1;
11192 + }
11193 +
11194 + current->mm->call_dl_resolve = call_dl_resolve;
11195 + up_write(&current->mm->mmap_sem);
11196 +
11197 +emulate:
11198 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11199 + regs->pc = call_dl_resolve;
11200 + regs->npc = addr+4;
11201 + return 3;
11202 + }
11203 +#endif
11204 +
11205 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11206 + if ((save & 0xFFC00000U) == 0x05000000U &&
11207 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11208 + nop == 0x01000000U)
11209 + {
11210 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11211 + regs->u_regs[UREG_G2] = addr + 4;
11212 + addr = (save & 0x003FFFFFU) << 10;
11213 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11214 + regs->pc = addr;
11215 + regs->npc = addr+4;
11216 + return 3;
11217 + }
11218 + }
11219 + } while (0);
11220 +
11221 + do { /* PaX: unpatched PLT emulation step 2 */
11222 + unsigned int save, call, nop;
11223 +
11224 + err = get_user(save, (unsigned int *)(regs->pc-4));
11225 + err |= get_user(call, (unsigned int *)regs->pc);
11226 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11227 + if (err)
11228 + break;
11229 +
11230 + if (save == 0x9DE3BFA8U &&
11231 + (call & 0xC0000000U) == 0x40000000U &&
11232 + nop == 0x01000000U)
11233 + {
11234 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11235 +
11236 + regs->u_regs[UREG_RETPC] = regs->pc;
11237 + regs->pc = dl_resolve;
11238 + regs->npc = dl_resolve+4;
11239 + return 3;
11240 + }
11241 + } while (0);
11242 +#endif
11243 +
11244 + return 1;
11245 +}
11246 +
11247 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11248 +{
11249 + unsigned long i;
11250 +
11251 + printk(KERN_ERR "PAX: bytes at PC: ");
11252 + for (i = 0; i < 8; i++) {
11253 + unsigned int c;
11254 + if (get_user(c, (unsigned int *)pc+i))
11255 + printk(KERN_CONT "???????? ");
11256 + else
11257 + printk(KERN_CONT "%08x ", c);
11258 + }
11259 + printk("\n");
11260 +}
11261 +#endif
11262 +
11263 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11264 int text_fault)
11265 {
11266 @@ -229,6 +503,24 @@ good_area:
11267 if (!(vma->vm_flags & VM_WRITE))
11268 goto bad_area;
11269 } else {
11270 +
11271 +#ifdef CONFIG_PAX_PAGEEXEC
11272 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11273 + up_read(&mm->mmap_sem);
11274 + switch (pax_handle_fetch_fault(regs)) {
11275 +
11276 +#ifdef CONFIG_PAX_EMUPLT
11277 + case 2:
11278 + case 3:
11279 + return;
11280 +#endif
11281 +
11282 + }
11283 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11284 + do_group_exit(SIGKILL);
11285 + }
11286 +#endif
11287 +
11288 /* Allow reads even for write-only mappings */
11289 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11290 goto bad_area;
11291 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11292 index 69bb818..6ca35c8 100644
11293 --- a/arch/sparc/mm/fault_64.c
11294 +++ b/arch/sparc/mm/fault_64.c
11295 @@ -22,6 +22,9 @@
11296 #include <linux/kdebug.h>
11297 #include <linux/percpu.h>
11298 #include <linux/context_tracking.h>
11299 +#include <linux/slab.h>
11300 +#include <linux/pagemap.h>
11301 +#include <linux/compiler.h>
11302
11303 #include <asm/page.h>
11304 #include <asm/pgtable.h>
11305 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11306 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11307 regs->tpc);
11308 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11309 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11310 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11311 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11312 dump_stack();
11313 unhandled_fault(regs->tpc, current, regs);
11314 @@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11315 show_regs(regs);
11316 }
11317
11318 +#ifdef CONFIG_PAX_PAGEEXEC
11319 +#ifdef CONFIG_PAX_DLRESOLVE
11320 +static void pax_emuplt_close(struct vm_area_struct *vma)
11321 +{
11322 + vma->vm_mm->call_dl_resolve = 0UL;
11323 +}
11324 +
11325 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11326 +{
11327 + unsigned int *kaddr;
11328 +
11329 + vmf->page = alloc_page(GFP_HIGHUSER);
11330 + if (!vmf->page)
11331 + return VM_FAULT_OOM;
11332 +
11333 + kaddr = kmap(vmf->page);
11334 + memset(kaddr, 0, PAGE_SIZE);
11335 + kaddr[0] = 0x9DE3BFA8U; /* save */
11336 + flush_dcache_page(vmf->page);
11337 + kunmap(vmf->page);
11338 + return VM_FAULT_MAJOR;
11339 +}
11340 +
11341 +static const struct vm_operations_struct pax_vm_ops = {
11342 + .close = pax_emuplt_close,
11343 + .fault = pax_emuplt_fault
11344 +};
11345 +
11346 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11347 +{
11348 + int ret;
11349 +
11350 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11351 + vma->vm_mm = current->mm;
11352 + vma->vm_start = addr;
11353 + vma->vm_end = addr + PAGE_SIZE;
11354 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11355 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11356 + vma->vm_ops = &pax_vm_ops;
11357 +
11358 + ret = insert_vm_struct(current->mm, vma);
11359 + if (ret)
11360 + return ret;
11361 +
11362 + ++current->mm->total_vm;
11363 + return 0;
11364 +}
11365 +#endif
11366 +
11367 +/*
11368 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11369 + *
11370 + * returns 1 when task should be killed
11371 + * 2 when patched PLT trampoline was detected
11372 + * 3 when unpatched PLT trampoline was detected
11373 + */
11374 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11375 +{
11376 +
11377 +#ifdef CONFIG_PAX_EMUPLT
11378 + int err;
11379 +
11380 + do { /* PaX: patched PLT emulation #1 */
11381 + unsigned int sethi1, sethi2, jmpl;
11382 +
11383 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11384 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11385 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11386 +
11387 + if (err)
11388 + break;
11389 +
11390 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11391 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11392 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11393 + {
11394 + unsigned long addr;
11395 +
11396 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11397 + addr = regs->u_regs[UREG_G1];
11398 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11399 +
11400 + if (test_thread_flag(TIF_32BIT))
11401 + addr &= 0xFFFFFFFFUL;
11402 +
11403 + regs->tpc = addr;
11404 + regs->tnpc = addr+4;
11405 + return 2;
11406 + }
11407 + } while (0);
11408 +
11409 + do { /* PaX: patched PLT emulation #2 */
11410 + unsigned int ba;
11411 +
11412 + err = get_user(ba, (unsigned int *)regs->tpc);
11413 +
11414 + if (err)
11415 + break;
11416 +
11417 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11418 + unsigned long addr;
11419 +
11420 + if ((ba & 0xFFC00000U) == 0x30800000U)
11421 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11422 + else
11423 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11424 +
11425 + if (test_thread_flag(TIF_32BIT))
11426 + addr &= 0xFFFFFFFFUL;
11427 +
11428 + regs->tpc = addr;
11429 + regs->tnpc = addr+4;
11430 + return 2;
11431 + }
11432 + } while (0);
11433 +
11434 + do { /* PaX: patched PLT emulation #3 */
11435 + unsigned int sethi, bajmpl, nop;
11436 +
11437 + err = get_user(sethi, (unsigned int *)regs->tpc);
11438 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11439 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11440 +
11441 + if (err)
11442 + break;
11443 +
11444 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11445 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11446 + nop == 0x01000000U)
11447 + {
11448 + unsigned long addr;
11449 +
11450 + addr = (sethi & 0x003FFFFFU) << 10;
11451 + regs->u_regs[UREG_G1] = addr;
11452 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11453 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11454 + else
11455 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11456 +
11457 + if (test_thread_flag(TIF_32BIT))
11458 + addr &= 0xFFFFFFFFUL;
11459 +
11460 + regs->tpc = addr;
11461 + regs->tnpc = addr+4;
11462 + return 2;
11463 + }
11464 + } while (0);
11465 +
11466 + do { /* PaX: patched PLT emulation #4 */
11467 + unsigned int sethi, mov1, call, mov2;
11468 +
11469 + err = get_user(sethi, (unsigned int *)regs->tpc);
11470 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11471 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11472 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11473 +
11474 + if (err)
11475 + break;
11476 +
11477 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11478 + mov1 == 0x8210000FU &&
11479 + (call & 0xC0000000U) == 0x40000000U &&
11480 + mov2 == 0x9E100001U)
11481 + {
11482 + unsigned long addr;
11483 +
11484 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11485 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11486 +
11487 + if (test_thread_flag(TIF_32BIT))
11488 + addr &= 0xFFFFFFFFUL;
11489 +
11490 + regs->tpc = addr;
11491 + regs->tnpc = addr+4;
11492 + return 2;
11493 + }
11494 + } while (0);
11495 +
11496 + do { /* PaX: patched PLT emulation #5 */
11497 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11498 +
11499 + err = get_user(sethi, (unsigned int *)regs->tpc);
11500 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11501 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11502 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11503 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11504 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11505 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11506 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11507 +
11508 + if (err)
11509 + break;
11510 +
11511 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11512 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11513 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11514 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11515 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11516 + sllx == 0x83287020U &&
11517 + jmpl == 0x81C04005U &&
11518 + nop == 0x01000000U)
11519 + {
11520 + unsigned long addr;
11521 +
11522 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11523 + regs->u_regs[UREG_G1] <<= 32;
11524 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11525 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11526 + regs->tpc = addr;
11527 + regs->tnpc = addr+4;
11528 + return 2;
11529 + }
11530 + } while (0);
11531 +
11532 + do { /* PaX: patched PLT emulation #6 */
11533 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11534 +
11535 + err = get_user(sethi, (unsigned int *)regs->tpc);
11536 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11537 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11538 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11539 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11540 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11541 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11542 +
11543 + if (err)
11544 + break;
11545 +
11546 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11547 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11548 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11549 + sllx == 0x83287020U &&
11550 + (or & 0xFFFFE000U) == 0x8A116000U &&
11551 + jmpl == 0x81C04005U &&
11552 + nop == 0x01000000U)
11553 + {
11554 + unsigned long addr;
11555 +
11556 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11557 + regs->u_regs[UREG_G1] <<= 32;
11558 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11559 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11560 + regs->tpc = addr;
11561 + regs->tnpc = addr+4;
11562 + return 2;
11563 + }
11564 + } while (0);
11565 +
11566 + do { /* PaX: unpatched PLT emulation step 1 */
11567 + unsigned int sethi, ba, nop;
11568 +
11569 + err = get_user(sethi, (unsigned int *)regs->tpc);
11570 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11571 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11572 +
11573 + if (err)
11574 + break;
11575 +
11576 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11577 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11578 + nop == 0x01000000U)
11579 + {
11580 + unsigned long addr;
11581 + unsigned int save, call;
11582 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11583 +
11584 + if ((ba & 0xFFC00000U) == 0x30800000U)
11585 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11586 + else
11587 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11588 +
11589 + if (test_thread_flag(TIF_32BIT))
11590 + addr &= 0xFFFFFFFFUL;
11591 +
11592 + err = get_user(save, (unsigned int *)addr);
11593 + err |= get_user(call, (unsigned int *)(addr+4));
11594 + err |= get_user(nop, (unsigned int *)(addr+8));
11595 + if (err)
11596 + break;
11597 +
11598 +#ifdef CONFIG_PAX_DLRESOLVE
11599 + if (save == 0x9DE3BFA8U &&
11600 + (call & 0xC0000000U) == 0x40000000U &&
11601 + nop == 0x01000000U)
11602 + {
11603 + struct vm_area_struct *vma;
11604 + unsigned long call_dl_resolve;
11605 +
11606 + down_read(&current->mm->mmap_sem);
11607 + call_dl_resolve = current->mm->call_dl_resolve;
11608 + up_read(&current->mm->mmap_sem);
11609 + if (likely(call_dl_resolve))
11610 + goto emulate;
11611 +
11612 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11613 +
11614 + down_write(&current->mm->mmap_sem);
11615 + if (current->mm->call_dl_resolve) {
11616 + call_dl_resolve = current->mm->call_dl_resolve;
11617 + up_write(&current->mm->mmap_sem);
11618 + if (vma)
11619 + kmem_cache_free(vm_area_cachep, vma);
11620 + goto emulate;
11621 + }
11622 +
11623 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11624 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11625 + up_write(&current->mm->mmap_sem);
11626 + if (vma)
11627 + kmem_cache_free(vm_area_cachep, vma);
11628 + return 1;
11629 + }
11630 +
11631 + if (pax_insert_vma(vma, call_dl_resolve)) {
11632 + up_write(&current->mm->mmap_sem);
11633 + kmem_cache_free(vm_area_cachep, vma);
11634 + return 1;
11635 + }
11636 +
11637 + current->mm->call_dl_resolve = call_dl_resolve;
11638 + up_write(&current->mm->mmap_sem);
11639 +
11640 +emulate:
11641 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11642 + regs->tpc = call_dl_resolve;
11643 + regs->tnpc = addr+4;
11644 + return 3;
11645 + }
11646 +#endif
11647 +
11648 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11649 + if ((save & 0xFFC00000U) == 0x05000000U &&
11650 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11651 + nop == 0x01000000U)
11652 + {
11653 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11654 + regs->u_regs[UREG_G2] = addr + 4;
11655 + addr = (save & 0x003FFFFFU) << 10;
11656 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11657 +
11658 + if (test_thread_flag(TIF_32BIT))
11659 + addr &= 0xFFFFFFFFUL;
11660 +
11661 + regs->tpc = addr;
11662 + regs->tnpc = addr+4;
11663 + return 3;
11664 + }
11665 +
11666 + /* PaX: 64-bit PLT stub */
11667 + err = get_user(sethi1, (unsigned int *)addr);
11668 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11669 + err |= get_user(or1, (unsigned int *)(addr+8));
11670 + err |= get_user(or2, (unsigned int *)(addr+12));
11671 + err |= get_user(sllx, (unsigned int *)(addr+16));
11672 + err |= get_user(add, (unsigned int *)(addr+20));
11673 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11674 + err |= get_user(nop, (unsigned int *)(addr+28));
11675 + if (err)
11676 + break;
11677 +
11678 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11679 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11680 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11681 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11682 + sllx == 0x89293020U &&
11683 + add == 0x8A010005U &&
11684 + jmpl == 0x89C14000U &&
11685 + nop == 0x01000000U)
11686 + {
11687 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11688 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11689 + regs->u_regs[UREG_G4] <<= 32;
11690 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11691 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11692 + regs->u_regs[UREG_G4] = addr + 24;
11693 + addr = regs->u_regs[UREG_G5];
11694 + regs->tpc = addr;
11695 + regs->tnpc = addr+4;
11696 + return 3;
11697 + }
11698 + }
11699 + } while (0);
11700 +
11701 +#ifdef CONFIG_PAX_DLRESOLVE
11702 + do { /* PaX: unpatched PLT emulation step 2 */
11703 + unsigned int save, call, nop;
11704 +
11705 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11706 + err |= get_user(call, (unsigned int *)regs->tpc);
11707 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11708 + if (err)
11709 + break;
11710 +
11711 + if (save == 0x9DE3BFA8U &&
11712 + (call & 0xC0000000U) == 0x40000000U &&
11713 + nop == 0x01000000U)
11714 + {
11715 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11716 +
11717 + if (test_thread_flag(TIF_32BIT))
11718 + dl_resolve &= 0xFFFFFFFFUL;
11719 +
11720 + regs->u_regs[UREG_RETPC] = regs->tpc;
11721 + regs->tpc = dl_resolve;
11722 + regs->tnpc = dl_resolve+4;
11723 + return 3;
11724 + }
11725 + } while (0);
11726 +#endif
11727 +
11728 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11729 + unsigned int sethi, ba, nop;
11730 +
11731 + err = get_user(sethi, (unsigned int *)regs->tpc);
11732 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11733 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11734 +
11735 + if (err)
11736 + break;
11737 +
11738 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11739 + (ba & 0xFFF00000U) == 0x30600000U &&
11740 + nop == 0x01000000U)
11741 + {
11742 + unsigned long addr;
11743 +
11744 + addr = (sethi & 0x003FFFFFU) << 10;
11745 + regs->u_regs[UREG_G1] = addr;
11746 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11747 +
11748 + if (test_thread_flag(TIF_32BIT))
11749 + addr &= 0xFFFFFFFFUL;
11750 +
11751 + regs->tpc = addr;
11752 + regs->tnpc = addr+4;
11753 + return 2;
11754 + }
11755 + } while (0);
11756 +
11757 +#endif
11758 +
11759 + return 1;
11760 +}
11761 +
11762 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11763 +{
11764 + unsigned long i;
11765 +
11766 + printk(KERN_ERR "PAX: bytes at PC: ");
11767 + for (i = 0; i < 8; i++) {
11768 + unsigned int c;
11769 + if (get_user(c, (unsigned int *)pc+i))
11770 + printk(KERN_CONT "???????? ");
11771 + else
11772 + printk(KERN_CONT "%08x ", c);
11773 + }
11774 + printk("\n");
11775 +}
11776 +#endif
11777 +
11778 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11779 {
11780 enum ctx_state prev_state = exception_enter();
11781 @@ -344,6 +807,29 @@ retry:
11782 if (!vma)
11783 goto bad_area;
11784
11785 +#ifdef CONFIG_PAX_PAGEEXEC
11786 + /* PaX: detect ITLB misses on non-exec pages */
11787 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11788 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11789 + {
11790 + if (address != regs->tpc)
11791 + goto good_area;
11792 +
11793 + up_read(&mm->mmap_sem);
11794 + switch (pax_handle_fetch_fault(regs)) {
11795 +
11796 +#ifdef CONFIG_PAX_EMUPLT
11797 + case 2:
11798 + case 3:
11799 + return;
11800 +#endif
11801 +
11802 + }
11803 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11804 + do_group_exit(SIGKILL);
11805 + }
11806 +#endif
11807 +
11808 /* Pure DTLB misses do not tell us whether the fault causing
11809 * load/store/atomic was a write or not, it only says that there
11810 * was no match. So in such a case we (carefully) read the
11811 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11812 index 3096317..a7b7654 100644
11813 --- a/arch/sparc/mm/hugetlbpage.c
11814 +++ b/arch/sparc/mm/hugetlbpage.c
11815 @@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11816 unsigned long addr,
11817 unsigned long len,
11818 unsigned long pgoff,
11819 - unsigned long flags)
11820 + unsigned long flags,
11821 + unsigned long offset)
11822 {
11823 unsigned long task_size = TASK_SIZE;
11824 struct vm_unmapped_area_info info;
11825 @@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11826
11827 info.flags = 0;
11828 info.length = len;
11829 - info.low_limit = TASK_UNMAPPED_BASE;
11830 + info.low_limit = mm->mmap_base;
11831 info.high_limit = min(task_size, VA_EXCLUDE_START);
11832 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11833 info.align_offset = 0;
11834 + info.threadstack_offset = offset;
11835 addr = vm_unmapped_area(&info);
11836
11837 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11838 VM_BUG_ON(addr != -ENOMEM);
11839 info.low_limit = VA_EXCLUDE_END;
11840 +
11841 +#ifdef CONFIG_PAX_RANDMMAP
11842 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11843 + info.low_limit += mm->delta_mmap;
11844 +#endif
11845 +
11846 info.high_limit = task_size;
11847 addr = vm_unmapped_area(&info);
11848 }
11849 @@ -56,7 +64,8 @@ static unsigned long
11850 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11851 const unsigned long len,
11852 const unsigned long pgoff,
11853 - const unsigned long flags)
11854 + const unsigned long flags,
11855 + const unsigned long offset)
11856 {
11857 struct mm_struct *mm = current->mm;
11858 unsigned long addr = addr0;
11859 @@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11860 info.high_limit = mm->mmap_base;
11861 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11862 info.align_offset = 0;
11863 + info.threadstack_offset = offset;
11864 addr = vm_unmapped_area(&info);
11865
11866 /*
11867 @@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11868 VM_BUG_ON(addr != -ENOMEM);
11869 info.flags = 0;
11870 info.low_limit = TASK_UNMAPPED_BASE;
11871 +
11872 +#ifdef CONFIG_PAX_RANDMMAP
11873 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11874 + info.low_limit += mm->delta_mmap;
11875 +#endif
11876 +
11877 info.high_limit = STACK_TOP32;
11878 addr = vm_unmapped_area(&info);
11879 }
11880 @@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11881 struct mm_struct *mm = current->mm;
11882 struct vm_area_struct *vma;
11883 unsigned long task_size = TASK_SIZE;
11884 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11885
11886 if (test_thread_flag(TIF_32BIT))
11887 task_size = STACK_TOP32;
11888 @@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11889 return addr;
11890 }
11891
11892 +#ifdef CONFIG_PAX_RANDMMAP
11893 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11894 +#endif
11895 +
11896 if (addr) {
11897 addr = ALIGN(addr, HPAGE_SIZE);
11898 vma = find_vma(mm, addr);
11899 - if (task_size - len >= addr &&
11900 - (!vma || addr + len <= vma->vm_start))
11901 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11902 return addr;
11903 }
11904 if (mm->get_unmapped_area == arch_get_unmapped_area)
11905 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11906 - pgoff, flags);
11907 + pgoff, flags, offset);
11908 else
11909 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11910 - pgoff, flags);
11911 + pgoff, flags, offset);
11912 }
11913
11914 pte_t *huge_pte_alloc(struct mm_struct *mm,
11915 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11916 index 5322e53..f820c5e 100644
11917 --- a/arch/sparc/mm/init_64.c
11918 +++ b/arch/sparc/mm/init_64.c
11919 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11920 int num_kernel_image_mappings;
11921
11922 #ifdef CONFIG_DEBUG_DCFLUSH
11923 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
11924 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11925 #ifdef CONFIG_SMP
11926 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11927 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11928 #endif
11929 #endif
11930
11931 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11932 {
11933 BUG_ON(tlb_type == hypervisor);
11934 #ifdef CONFIG_DEBUG_DCFLUSH
11935 - atomic_inc(&dcpage_flushes);
11936 + atomic_inc_unchecked(&dcpage_flushes);
11937 #endif
11938
11939 #ifdef DCACHE_ALIASING_POSSIBLE
11940 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11941
11942 #ifdef CONFIG_DEBUG_DCFLUSH
11943 seq_printf(m, "DCPageFlushes\t: %d\n",
11944 - atomic_read(&dcpage_flushes));
11945 + atomic_read_unchecked(&dcpage_flushes));
11946 #ifdef CONFIG_SMP
11947 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11948 - atomic_read(&dcpage_flushes_xcall));
11949 + atomic_read_unchecked(&dcpage_flushes_xcall));
11950 #endif /* CONFIG_SMP */
11951 #endif /* CONFIG_DEBUG_DCFLUSH */
11952 }
11953 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11954 index b3692ce..e4517c9 100644
11955 --- a/arch/tile/Kconfig
11956 +++ b/arch/tile/Kconfig
11957 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11958
11959 config KEXEC
11960 bool "kexec system call"
11961 + depends on !GRKERNSEC_KMEM
11962 ---help---
11963 kexec is a system call that implements the ability to shutdown your
11964 current kernel, and to start another kernel. It is like a reboot
11965 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11966 index ad220ee..2f537b3 100644
11967 --- a/arch/tile/include/asm/atomic_64.h
11968 +++ b/arch/tile/include/asm/atomic_64.h
11969 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11970
11971 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11972
11973 +#define atomic64_read_unchecked(v) atomic64_read(v)
11974 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11975 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11976 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11977 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11978 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
11979 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11980 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
11981 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11982 +
11983 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11984 #define smp_mb__before_atomic_dec() smp_mb()
11985 #define smp_mb__after_atomic_dec() smp_mb()
11986 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11987 index 6160761..00cac88 100644
11988 --- a/arch/tile/include/asm/cache.h
11989 +++ b/arch/tile/include/asm/cache.h
11990 @@ -15,11 +15,12 @@
11991 #ifndef _ASM_TILE_CACHE_H
11992 #define _ASM_TILE_CACHE_H
11993
11994 +#include <linux/const.h>
11995 #include <arch/chip.h>
11996
11997 /* bytes per L1 data cache line */
11998 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11999 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12000 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12001
12002 /* bytes per L2 cache line */
12003 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12004 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12005 index b6cde32..c0cb736 100644
12006 --- a/arch/tile/include/asm/uaccess.h
12007 +++ b/arch/tile/include/asm/uaccess.h
12008 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12009 const void __user *from,
12010 unsigned long n)
12011 {
12012 - int sz = __compiletime_object_size(to);
12013 + size_t sz = __compiletime_object_size(to);
12014
12015 - if (likely(sz == -1 || sz >= n))
12016 + if (likely(sz == (size_t)-1 || sz >= n))
12017 n = _copy_from_user(to, from, n);
12018 else
12019 copy_from_user_overflow();
12020 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12021 index 0cb3bba..7338b2d 100644
12022 --- a/arch/tile/mm/hugetlbpage.c
12023 +++ b/arch/tile/mm/hugetlbpage.c
12024 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12025 info.high_limit = TASK_SIZE;
12026 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12027 info.align_offset = 0;
12028 + info.threadstack_offset = 0;
12029 return vm_unmapped_area(&info);
12030 }
12031
12032 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12033 info.high_limit = current->mm->mmap_base;
12034 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12035 info.align_offset = 0;
12036 + info.threadstack_offset = 0;
12037 addr = vm_unmapped_area(&info);
12038
12039 /*
12040 diff --git a/arch/um/Makefile b/arch/um/Makefile
12041 index 36e658a..71a5c5a 100644
12042 --- a/arch/um/Makefile
12043 +++ b/arch/um/Makefile
12044 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12045 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12046 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12047
12048 +ifdef CONSTIFY_PLUGIN
12049 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12050 +endif
12051 +
12052 #This will adjust *FLAGS accordingly to the platform.
12053 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12054
12055 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12056 index 19e1bdd..3665b77 100644
12057 --- a/arch/um/include/asm/cache.h
12058 +++ b/arch/um/include/asm/cache.h
12059 @@ -1,6 +1,7 @@
12060 #ifndef __UM_CACHE_H
12061 #define __UM_CACHE_H
12062
12063 +#include <linux/const.h>
12064
12065 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12066 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12067 @@ -12,6 +13,6 @@
12068 # define L1_CACHE_SHIFT 5
12069 #endif
12070
12071 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12072 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12073
12074 #endif
12075 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12076 index 2e0a6b1..a64d0f5 100644
12077 --- a/arch/um/include/asm/kmap_types.h
12078 +++ b/arch/um/include/asm/kmap_types.h
12079 @@ -8,6 +8,6 @@
12080
12081 /* No more #include "asm/arch/kmap_types.h" ! */
12082
12083 -#define KM_TYPE_NR 14
12084 +#define KM_TYPE_NR 15
12085
12086 #endif
12087 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12088 index 5ff53d9..5850cdf 100644
12089 --- a/arch/um/include/asm/page.h
12090 +++ b/arch/um/include/asm/page.h
12091 @@ -14,6 +14,9 @@
12092 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12093 #define PAGE_MASK (~(PAGE_SIZE-1))
12094
12095 +#define ktla_ktva(addr) (addr)
12096 +#define ktva_ktla(addr) (addr)
12097 +
12098 #ifndef __ASSEMBLY__
12099
12100 struct page;
12101 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12102 index 0032f92..cd151e0 100644
12103 --- a/arch/um/include/asm/pgtable-3level.h
12104 +++ b/arch/um/include/asm/pgtable-3level.h
12105 @@ -58,6 +58,7 @@
12106 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12107 #define pud_populate(mm, pud, pmd) \
12108 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12109 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12110
12111 #ifdef CONFIG_64BIT
12112 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12113 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12114 index eecc414..48adb87 100644
12115 --- a/arch/um/kernel/process.c
12116 +++ b/arch/um/kernel/process.c
12117 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12118 return 2;
12119 }
12120
12121 -/*
12122 - * Only x86 and x86_64 have an arch_align_stack().
12123 - * All other arches have "#define arch_align_stack(x) (x)"
12124 - * in their asm/system.h
12125 - * As this is included in UML from asm-um/system-generic.h,
12126 - * we can use it to behave as the subarch does.
12127 - */
12128 -#ifndef arch_align_stack
12129 -unsigned long arch_align_stack(unsigned long sp)
12130 -{
12131 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12132 - sp -= get_random_int() % 8192;
12133 - return sp & ~0xf;
12134 -}
12135 -#endif
12136 -
12137 unsigned long get_wchan(struct task_struct *p)
12138 {
12139 unsigned long stack_page, sp, ip;
12140 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12141 index ad8f795..2c7eec6 100644
12142 --- a/arch/unicore32/include/asm/cache.h
12143 +++ b/arch/unicore32/include/asm/cache.h
12144 @@ -12,8 +12,10 @@
12145 #ifndef __UNICORE_CACHE_H__
12146 #define __UNICORE_CACHE_H__
12147
12148 -#define L1_CACHE_SHIFT (5)
12149 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12150 +#include <linux/const.h>
12151 +
12152 +#define L1_CACHE_SHIFT 5
12153 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12154
12155 /*
12156 * Memory returned by kmalloc() may be used for DMA, so we must make
12157 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12158 index 0952ecd..9cf578c 100644
12159 --- a/arch/x86/Kconfig
12160 +++ b/arch/x86/Kconfig
12161 @@ -249,7 +249,7 @@ config X86_HT
12162
12163 config X86_32_LAZY_GS
12164 def_bool y
12165 - depends on X86_32 && !CC_STACKPROTECTOR
12166 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12167
12168 config ARCH_HWEIGHT_CFLAGS
12169 string
12170 @@ -602,6 +602,7 @@ config SCHED_OMIT_FRAME_POINTER
12171
12172 menuconfig HYPERVISOR_GUEST
12173 bool "Linux guest support"
12174 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12175 ---help---
12176 Say Y here to enable options for running Linux under various hyper-
12177 visors. This option enables basic hypervisor detection and platform
12178 @@ -1127,7 +1128,7 @@ choice
12179
12180 config NOHIGHMEM
12181 bool "off"
12182 - depends on !X86_NUMAQ
12183 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12184 ---help---
12185 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12186 However, the address space of 32-bit x86 processors is only 4
12187 @@ -1164,7 +1165,7 @@ config NOHIGHMEM
12188
12189 config HIGHMEM4G
12190 bool "4GB"
12191 - depends on !X86_NUMAQ
12192 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12193 ---help---
12194 Select this if you have a 32-bit processor and between 1 and 4
12195 gigabytes of physical RAM.
12196 @@ -1217,7 +1218,7 @@ config PAGE_OFFSET
12197 hex
12198 default 0xB0000000 if VMSPLIT_3G_OPT
12199 default 0x80000000 if VMSPLIT_2G
12200 - default 0x78000000 if VMSPLIT_2G_OPT
12201 + default 0x70000000 if VMSPLIT_2G_OPT
12202 default 0x40000000 if VMSPLIT_1G
12203 default 0xC0000000
12204 depends on X86_32
12205 @@ -1619,6 +1620,7 @@ config SECCOMP
12206
12207 config CC_STACKPROTECTOR
12208 bool "Enable -fstack-protector buffer overflow detection"
12209 + depends on X86_64 || !PAX_MEMORY_UDEREF
12210 ---help---
12211 This option turns on the -fstack-protector GCC feature. This
12212 feature puts, at the beginning of functions, a canary value on
12213 @@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
12214
12215 config KEXEC
12216 bool "kexec system call"
12217 + depends on !GRKERNSEC_KMEM
12218 ---help---
12219 kexec is a system call that implements the ability to shutdown your
12220 current kernel, and to start another kernel. It is like a reboot
12221 @@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
12222 config PHYSICAL_ALIGN
12223 hex "Alignment value to which kernel should be aligned"
12224 default "0x1000000"
12225 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12226 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12227 range 0x2000 0x1000000 if X86_32
12228 range 0x200000 0x1000000 if X86_64
12229 ---help---
12230 @@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
12231 If unsure, say N.
12232
12233 config COMPAT_VDSO
12234 - def_bool y
12235 + def_bool n
12236 prompt "Compat VDSO support"
12237 depends on X86_32 || IA32_EMULATION
12238 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12239 ---help---
12240 Map the 32-bit VDSO to the predictable old-style address too.
12241
12242 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12243 index c026cca..14657ae 100644
12244 --- a/arch/x86/Kconfig.cpu
12245 +++ b/arch/x86/Kconfig.cpu
12246 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12247
12248 config X86_F00F_BUG
12249 def_bool y
12250 - depends on M586MMX || M586TSC || M586 || M486
12251 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12252
12253 config X86_INVD_BUG
12254 def_bool y
12255 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12256
12257 config X86_ALIGNMENT_16
12258 def_bool y
12259 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12260 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12261
12262 config X86_INTEL_USERCOPY
12263 def_bool y
12264 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
12265 # generates cmov.
12266 config X86_CMOV
12267 def_bool y
12268 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12269 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12270
12271 config X86_MINIMUM_CPU_FAMILY
12272 int
12273 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12274 index 0f3621e..282f24b 100644
12275 --- a/arch/x86/Kconfig.debug
12276 +++ b/arch/x86/Kconfig.debug
12277 @@ -84,7 +84,7 @@ config X86_PTDUMP
12278 config DEBUG_RODATA
12279 bool "Write protect kernel read-only data structures"
12280 default y
12281 - depends on DEBUG_KERNEL
12282 + depends on DEBUG_KERNEL && BROKEN
12283 ---help---
12284 Mark the kernel read-only data as write-protected in the pagetables,
12285 in order to catch accidental (and incorrect) writes to such const
12286 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12287
12288 config DEBUG_SET_MODULE_RONX
12289 bool "Set loadable kernel module data as NX and text as RO"
12290 - depends on MODULES
12291 + depends on MODULES && BROKEN
12292 ---help---
12293 This option helps catch unintended modifications to loadable
12294 kernel module's text and read-only data. It also prevents execution
12295 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12296 index 57d0215..b4373fb 100644
12297 --- a/arch/x86/Makefile
12298 +++ b/arch/x86/Makefile
12299 @@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
12300 # CPU-specific tuning. Anything which can be shared with UML should go here.
12301 include $(srctree)/arch/x86/Makefile_32.cpu
12302 KBUILD_CFLAGS += $(cflags-y)
12303 -
12304 - # temporary until string.h is fixed
12305 - KBUILD_CFLAGS += -ffreestanding
12306 else
12307 BITS := 64
12308 UTS_MACHINE := x86_64
12309 CHECKFLAGS += -D__x86_64__ -m64
12310
12311 + biarch := $(call cc-option,-m64)
12312 KBUILD_AFLAGS += -m64
12313 KBUILD_CFLAGS += -m64
12314
12315 @@ -89,6 +87,9 @@ else
12316 KBUILD_CFLAGS += -maccumulate-outgoing-args
12317 endif
12318
12319 +# temporary until string.h is fixed
12320 +KBUILD_CFLAGS += -ffreestanding
12321 +
12322 ifdef CONFIG_CC_STACKPROTECTOR
12323 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12324 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
12325 @@ -247,3 +248,12 @@ define archhelp
12326 echo ' FDINITRD=file initrd for the booted kernel'
12327 echo ' kvmconfig - Enable additional options for guest kernel support'
12328 endef
12329 +
12330 +define OLD_LD
12331 +
12332 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12333 +*** Please upgrade your binutils to 2.18 or newer
12334 +endef
12335 +
12336 +archprepare:
12337 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12338 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12339 index d9c1195..a26ca0d 100644
12340 --- a/arch/x86/boot/Makefile
12341 +++ b/arch/x86/boot/Makefile
12342 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
12343 $(call cc-option, -fno-unit-at-a-time)) \
12344 $(call cc-option, -fno-stack-protector) \
12345 $(call cc-option, -mpreferred-stack-boundary=2)
12346 +ifdef CONSTIFY_PLUGIN
12347 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12348 +endif
12349 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12350 GCOV_PROFILE := n
12351
12352 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12353 index 878e4b9..20537ab 100644
12354 --- a/arch/x86/boot/bitops.h
12355 +++ b/arch/x86/boot/bitops.h
12356 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12357 u8 v;
12358 const u32 *p = (const u32 *)addr;
12359
12360 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12361 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12362 return v;
12363 }
12364
12365 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12366
12367 static inline void set_bit(int nr, void *addr)
12368 {
12369 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12370 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12371 }
12372
12373 #endif /* BOOT_BITOPS_H */
12374 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12375 index ef72bae..353a184 100644
12376 --- a/arch/x86/boot/boot.h
12377 +++ b/arch/x86/boot/boot.h
12378 @@ -85,7 +85,7 @@ static inline void io_delay(void)
12379 static inline u16 ds(void)
12380 {
12381 u16 seg;
12382 - asm("movw %%ds,%0" : "=rm" (seg));
12383 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12384 return seg;
12385 }
12386
12387 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12388 static inline int memcmp(const void *s1, const void *s2, size_t len)
12389 {
12390 u8 diff;
12391 - asm("repe; cmpsb; setnz %0"
12392 + asm volatile("repe; cmpsb; setnz %0"
12393 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12394 return diff;
12395 }
12396 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12397 index c8a6792..2402765 100644
12398 --- a/arch/x86/boot/compressed/Makefile
12399 +++ b/arch/x86/boot/compressed/Makefile
12400 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12401 KBUILD_CFLAGS += -mno-mmx -mno-sse
12402 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12403 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12404 +ifdef CONSTIFY_PLUGIN
12405 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12406 +endif
12407
12408 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12409 GCOV_PROFILE := n
12410 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12411 index a53440e..c3dbf1e 100644
12412 --- a/arch/x86/boot/compressed/efi_stub_32.S
12413 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12414 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12415 * parameter 2, ..., param n. To make things easy, we save the return
12416 * address of efi_call_phys in a global variable.
12417 */
12418 - popl %ecx
12419 - movl %ecx, saved_return_addr(%edx)
12420 - /* get the function pointer into ECX*/
12421 - popl %ecx
12422 - movl %ecx, efi_rt_function_ptr(%edx)
12423 + popl saved_return_addr(%edx)
12424 + popl efi_rt_function_ptr(%edx)
12425
12426 /*
12427 * 3. Call the physical function.
12428 */
12429 - call *%ecx
12430 + call *efi_rt_function_ptr(%edx)
12431
12432 /*
12433 * 4. Balance the stack. And because EAX contain the return value,
12434 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12435 1: popl %edx
12436 subl $1b, %edx
12437
12438 - movl efi_rt_function_ptr(%edx), %ecx
12439 - pushl %ecx
12440 + pushl efi_rt_function_ptr(%edx)
12441
12442 /*
12443 * 10. Push the saved return address onto the stack and return.
12444 */
12445 - movl saved_return_addr(%edx), %ecx
12446 - pushl %ecx
12447 - ret
12448 + jmpl *saved_return_addr(%edx)
12449 ENDPROC(efi_call_phys)
12450 .previous
12451
12452 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12453 index 5d6f689..9d06730 100644
12454 --- a/arch/x86/boot/compressed/head_32.S
12455 +++ b/arch/x86/boot/compressed/head_32.S
12456 @@ -118,7 +118,7 @@ preferred_addr:
12457 notl %eax
12458 andl %eax, %ebx
12459 #else
12460 - movl $LOAD_PHYSICAL_ADDR, %ebx
12461 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12462 #endif
12463
12464 /* Target address to relocate to for decompression */
12465 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12466 index c337422..2c5be72 100644
12467 --- a/arch/x86/boot/compressed/head_64.S
12468 +++ b/arch/x86/boot/compressed/head_64.S
12469 @@ -95,7 +95,7 @@ ENTRY(startup_32)
12470 notl %eax
12471 andl %eax, %ebx
12472 #else
12473 - movl $LOAD_PHYSICAL_ADDR, %ebx
12474 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12475 #endif
12476
12477 /* Target address to relocate to for decompression */
12478 @@ -270,7 +270,7 @@ preferred_addr:
12479 notq %rax
12480 andq %rax, %rbp
12481 #else
12482 - movq $LOAD_PHYSICAL_ADDR, %rbp
12483 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12484 #endif
12485
12486 /* Target address to relocate to for decompression */
12487 @@ -362,8 +362,8 @@ gdt:
12488 .long gdt
12489 .word 0
12490 .quad 0x0000000000000000 /* NULL descriptor */
12491 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12492 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12493 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12494 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12495 .quad 0x0080890000000000 /* TS descriptor */
12496 .quad 0x0000000000000000 /* TS continued */
12497 gdt_end:
12498 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12499 index 434f077..b6b4b38 100644
12500 --- a/arch/x86/boot/compressed/misc.c
12501 +++ b/arch/x86/boot/compressed/misc.c
12502 @@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12503 * Calculate the delta between where vmlinux was linked to load
12504 * and where it was actually loaded.
12505 */
12506 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12507 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12508 if (!delta) {
12509 debug_putstr("No relocation needed... ");
12510 return;
12511 @@ -380,7 +380,7 @@ static void parse_elf(void *output)
12512 case PT_LOAD:
12513 #ifdef CONFIG_RELOCATABLE
12514 dest = output;
12515 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12516 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12517 #else
12518 dest = (void *)(phdr->p_paddr);
12519 #endif
12520 @@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12521 error("Destination address too large");
12522 #endif
12523 #ifndef CONFIG_RELOCATABLE
12524 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12525 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12526 error("Wrong destination address");
12527 #endif
12528
12529 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12530 index 4d3ff03..e4972ff 100644
12531 --- a/arch/x86/boot/cpucheck.c
12532 +++ b/arch/x86/boot/cpucheck.c
12533 @@ -74,7 +74,7 @@ static int has_fpu(void)
12534 u16 fcw = -1, fsw = -1;
12535 u32 cr0;
12536
12537 - asm("movl %%cr0,%0" : "=r" (cr0));
12538 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
12539 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12540 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12541 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12542 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12543 {
12544 u32 f0, f1;
12545
12546 - asm("pushfl ; "
12547 + asm volatile("pushfl ; "
12548 "pushfl ; "
12549 "popl %0 ; "
12550 "movl %0,%1 ; "
12551 @@ -115,7 +115,7 @@ static void get_flags(void)
12552 set_bit(X86_FEATURE_FPU, cpu.flags);
12553
12554 if (has_eflag(X86_EFLAGS_ID)) {
12555 - asm("cpuid"
12556 + asm volatile("cpuid"
12557 : "=a" (max_intel_level),
12558 "=b" (cpu_vendor[0]),
12559 "=d" (cpu_vendor[1]),
12560 @@ -124,7 +124,7 @@ static void get_flags(void)
12561
12562 if (max_intel_level >= 0x00000001 &&
12563 max_intel_level <= 0x0000ffff) {
12564 - asm("cpuid"
12565 + asm volatile("cpuid"
12566 : "=a" (tfms),
12567 "=c" (cpu.flags[4]),
12568 "=d" (cpu.flags[0])
12569 @@ -136,7 +136,7 @@ static void get_flags(void)
12570 cpu.model += ((tfms >> 16) & 0xf) << 4;
12571 }
12572
12573 - asm("cpuid"
12574 + asm volatile("cpuid"
12575 : "=a" (max_amd_level)
12576 : "a" (0x80000000)
12577 : "ebx", "ecx", "edx");
12578 @@ -144,7 +144,7 @@ static void get_flags(void)
12579 if (max_amd_level >= 0x80000001 &&
12580 max_amd_level <= 0x8000ffff) {
12581 u32 eax = 0x80000001;
12582 - asm("cpuid"
12583 + asm volatile("cpuid"
12584 : "+a" (eax),
12585 "=c" (cpu.flags[6]),
12586 "=d" (cpu.flags[1])
12587 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12588 u32 ecx = MSR_K7_HWCR;
12589 u32 eax, edx;
12590
12591 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12592 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12593 eax &= ~(1 << 15);
12594 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12595 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12596
12597 get_flags(); /* Make sure it really did something */
12598 err = check_flags();
12599 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12600 u32 ecx = MSR_VIA_FCR;
12601 u32 eax, edx;
12602
12603 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12604 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12605 eax |= (1<<1)|(1<<7);
12606 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12607 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12608
12609 set_bit(X86_FEATURE_CX8, cpu.flags);
12610 err = check_flags();
12611 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12612 u32 eax, edx;
12613 u32 level = 1;
12614
12615 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12616 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12617 - asm("cpuid"
12618 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12619 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12620 + asm volatile("cpuid"
12621 : "+a" (level), "=d" (cpu.flags[0])
12622 : : "ecx", "ebx");
12623 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12624 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12625
12626 err = check_flags();
12627 }
12628 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12629 index 9ec06a1..2c25e79 100644
12630 --- a/arch/x86/boot/header.S
12631 +++ b/arch/x86/boot/header.S
12632 @@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12633 # single linked list of
12634 # struct setup_data
12635
12636 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12637 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12638
12639 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12640 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12641 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12642 +#else
12643 #define VO_INIT_SIZE (VO__end - VO__text)
12644 +#endif
12645 #if ZO_INIT_SIZE > VO_INIT_SIZE
12646 #define INIT_SIZE ZO_INIT_SIZE
12647 #else
12648 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12649 index db75d07..8e6d0af 100644
12650 --- a/arch/x86/boot/memory.c
12651 +++ b/arch/x86/boot/memory.c
12652 @@ -19,7 +19,7 @@
12653
12654 static int detect_memory_e820(void)
12655 {
12656 - int count = 0;
12657 + unsigned int count = 0;
12658 struct biosregs ireg, oreg;
12659 struct e820entry *desc = boot_params.e820_map;
12660 static struct e820entry buf; /* static so it is zeroed */
12661 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12662 index 11e8c6e..fdbb1ed 100644
12663 --- a/arch/x86/boot/video-vesa.c
12664 +++ b/arch/x86/boot/video-vesa.c
12665 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12666
12667 boot_params.screen_info.vesapm_seg = oreg.es;
12668 boot_params.screen_info.vesapm_off = oreg.di;
12669 + boot_params.screen_info.vesapm_size = oreg.cx;
12670 }
12671
12672 /*
12673 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12674 index 43eda28..5ab5fdb 100644
12675 --- a/arch/x86/boot/video.c
12676 +++ b/arch/x86/boot/video.c
12677 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12678 static unsigned int get_entry(void)
12679 {
12680 char entry_buf[4];
12681 - int i, len = 0;
12682 + unsigned int i, len = 0;
12683 int key;
12684 unsigned int v;
12685
12686 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12687 index 9105655..41779c1 100644
12688 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12689 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12690 @@ -8,6 +8,8 @@
12691 * including this sentence is retained in full.
12692 */
12693
12694 +#include <asm/alternative-asm.h>
12695 +
12696 .extern crypto_ft_tab
12697 .extern crypto_it_tab
12698 .extern crypto_fl_tab
12699 @@ -70,6 +72,8 @@
12700 je B192; \
12701 leaq 32(r9),r9;
12702
12703 +#define ret pax_force_retaddr; ret
12704 +
12705 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12706 movq r1,r2; \
12707 movq r3,r4; \
12708 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12709 index 477e9d7..c92c7d8 100644
12710 --- a/arch/x86/crypto/aesni-intel_asm.S
12711 +++ b/arch/x86/crypto/aesni-intel_asm.S
12712 @@ -31,6 +31,7 @@
12713
12714 #include <linux/linkage.h>
12715 #include <asm/inst.h>
12716 +#include <asm/alternative-asm.h>
12717
12718 #ifdef __x86_64__
12719 .data
12720 @@ -205,7 +206,7 @@ enc: .octa 0x2
12721 * num_initial_blocks = b mod 4
12722 * encrypt the initial num_initial_blocks blocks and apply ghash on
12723 * the ciphertext
12724 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12725 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12726 * are clobbered
12727 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12728 */
12729 @@ -214,8 +215,8 @@ enc: .octa 0x2
12730 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12731 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12732 mov arg7, %r10 # %r10 = AAD
12733 - mov arg8, %r12 # %r12 = aadLen
12734 - mov %r12, %r11
12735 + mov arg8, %r15 # %r15 = aadLen
12736 + mov %r15, %r11
12737 pxor %xmm\i, %xmm\i
12738 _get_AAD_loop\num_initial_blocks\operation:
12739 movd (%r10), \TMP1
12740 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12741 psrldq $4, %xmm\i
12742 pxor \TMP1, %xmm\i
12743 add $4, %r10
12744 - sub $4, %r12
12745 + sub $4, %r15
12746 jne _get_AAD_loop\num_initial_blocks\operation
12747 cmp $16, %r11
12748 je _get_AAD_loop2_done\num_initial_blocks\operation
12749 - mov $16, %r12
12750 + mov $16, %r15
12751 _get_AAD_loop2\num_initial_blocks\operation:
12752 psrldq $4, %xmm\i
12753 - sub $4, %r12
12754 - cmp %r11, %r12
12755 + sub $4, %r15
12756 + cmp %r11, %r15
12757 jne _get_AAD_loop2\num_initial_blocks\operation
12758 _get_AAD_loop2_done\num_initial_blocks\operation:
12759 movdqa SHUF_MASK(%rip), %xmm14
12760 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12761 * num_initial_blocks = b mod 4
12762 * encrypt the initial num_initial_blocks blocks and apply ghash on
12763 * the ciphertext
12764 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12765 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12766 * are clobbered
12767 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12768 */
12769 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12770 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12771 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12772 mov arg7, %r10 # %r10 = AAD
12773 - mov arg8, %r12 # %r12 = aadLen
12774 - mov %r12, %r11
12775 + mov arg8, %r15 # %r15 = aadLen
12776 + mov %r15, %r11
12777 pxor %xmm\i, %xmm\i
12778 _get_AAD_loop\num_initial_blocks\operation:
12779 movd (%r10), \TMP1
12780 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12781 psrldq $4, %xmm\i
12782 pxor \TMP1, %xmm\i
12783 add $4, %r10
12784 - sub $4, %r12
12785 + sub $4, %r15
12786 jne _get_AAD_loop\num_initial_blocks\operation
12787 cmp $16, %r11
12788 je _get_AAD_loop2_done\num_initial_blocks\operation
12789 - mov $16, %r12
12790 + mov $16, %r15
12791 _get_AAD_loop2\num_initial_blocks\operation:
12792 psrldq $4, %xmm\i
12793 - sub $4, %r12
12794 - cmp %r11, %r12
12795 + sub $4, %r15
12796 + cmp %r11, %r15
12797 jne _get_AAD_loop2\num_initial_blocks\operation
12798 _get_AAD_loop2_done\num_initial_blocks\operation:
12799 movdqa SHUF_MASK(%rip), %xmm14
12800 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12801 *
12802 *****************************************************************************/
12803 ENTRY(aesni_gcm_dec)
12804 - push %r12
12805 + push %r15
12806 push %r13
12807 push %r14
12808 mov %rsp, %r14
12809 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12810 */
12811 sub $VARIABLE_OFFSET, %rsp
12812 and $~63, %rsp # align rsp to 64 bytes
12813 - mov %arg6, %r12
12814 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12815 + mov %arg6, %r15
12816 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12817 movdqa SHUF_MASK(%rip), %xmm2
12818 PSHUFB_XMM %xmm2, %xmm13
12819
12820 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12821 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12822 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12823 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12824 - mov %r13, %r12
12825 - and $(3<<4), %r12
12826 + mov %r13, %r15
12827 + and $(3<<4), %r15
12828 jz _initial_num_blocks_is_0_decrypt
12829 - cmp $(2<<4), %r12
12830 + cmp $(2<<4), %r15
12831 jb _initial_num_blocks_is_1_decrypt
12832 je _initial_num_blocks_is_2_decrypt
12833 _initial_num_blocks_is_3_decrypt:
12834 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12835 sub $16, %r11
12836 add %r13, %r11
12837 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12838 - lea SHIFT_MASK+16(%rip), %r12
12839 - sub %r13, %r12
12840 + lea SHIFT_MASK+16(%rip), %r15
12841 + sub %r13, %r15
12842 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12843 # (%r13 is the number of bytes in plaintext mod 16)
12844 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12845 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12846 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12847
12848 movdqa %xmm1, %xmm2
12849 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12850 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12851 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12852 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12853 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12854 pand %xmm1, %xmm2
12855 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12856 sub $1, %r13
12857 jne _less_than_8_bytes_left_decrypt
12858 _multiple_of_16_bytes_decrypt:
12859 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12860 - shl $3, %r12 # convert into number of bits
12861 - movd %r12d, %xmm15 # len(A) in %xmm15
12862 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12863 + shl $3, %r15 # convert into number of bits
12864 + movd %r15d, %xmm15 # len(A) in %xmm15
12865 shl $3, %arg4 # len(C) in bits (*128)
12866 MOVQ_R64_XMM %arg4, %xmm1
12867 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12868 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12869 mov %r14, %rsp
12870 pop %r14
12871 pop %r13
12872 - pop %r12
12873 + pop %r15
12874 + pax_force_retaddr
12875 ret
12876 ENDPROC(aesni_gcm_dec)
12877
12878 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12879 * poly = x^128 + x^127 + x^126 + x^121 + 1
12880 ***************************************************************************/
12881 ENTRY(aesni_gcm_enc)
12882 - push %r12
12883 + push %r15
12884 push %r13
12885 push %r14
12886 mov %rsp, %r14
12887 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12888 #
12889 sub $VARIABLE_OFFSET, %rsp
12890 and $~63, %rsp
12891 - mov %arg6, %r12
12892 - movdqu (%r12), %xmm13
12893 + mov %arg6, %r15
12894 + movdqu (%r15), %xmm13
12895 movdqa SHUF_MASK(%rip), %xmm2
12896 PSHUFB_XMM %xmm2, %xmm13
12897
12898 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12899 movdqa %xmm13, HashKey(%rsp)
12900 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12901 and $-16, %r13
12902 - mov %r13, %r12
12903 + mov %r13, %r15
12904
12905 # Encrypt first few blocks
12906
12907 - and $(3<<4), %r12
12908 + and $(3<<4), %r15
12909 jz _initial_num_blocks_is_0_encrypt
12910 - cmp $(2<<4), %r12
12911 + cmp $(2<<4), %r15
12912 jb _initial_num_blocks_is_1_encrypt
12913 je _initial_num_blocks_is_2_encrypt
12914 _initial_num_blocks_is_3_encrypt:
12915 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12916 sub $16, %r11
12917 add %r13, %r11
12918 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12919 - lea SHIFT_MASK+16(%rip), %r12
12920 - sub %r13, %r12
12921 + lea SHIFT_MASK+16(%rip), %r15
12922 + sub %r13, %r15
12923 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12924 # (%r13 is the number of bytes in plaintext mod 16)
12925 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12926 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12927 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12928 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12929 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12930 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12931 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12932 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12933 movdqa SHUF_MASK(%rip), %xmm10
12934 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12935 sub $1, %r13
12936 jne _less_than_8_bytes_left_encrypt
12937 _multiple_of_16_bytes_encrypt:
12938 - mov arg8, %r12 # %r12 = addLen (number of bytes)
12939 - shl $3, %r12
12940 - movd %r12d, %xmm15 # len(A) in %xmm15
12941 + mov arg8, %r15 # %r15 = addLen (number of bytes)
12942 + shl $3, %r15
12943 + movd %r15d, %xmm15 # len(A) in %xmm15
12944 shl $3, %arg4 # len(C) in bits (*128)
12945 MOVQ_R64_XMM %arg4, %xmm1
12946 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12947 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12948 mov %r14, %rsp
12949 pop %r14
12950 pop %r13
12951 - pop %r12
12952 + pop %r15
12953 + pax_force_retaddr
12954 ret
12955 ENDPROC(aesni_gcm_enc)
12956
12957 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
12958 pxor %xmm1, %xmm0
12959 movaps %xmm0, (TKEYP)
12960 add $0x10, TKEYP
12961 + pax_force_retaddr
12962 ret
12963 ENDPROC(_key_expansion_128)
12964 ENDPROC(_key_expansion_256a)
12965 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
12966 shufps $0b01001110, %xmm2, %xmm1
12967 movaps %xmm1, 0x10(TKEYP)
12968 add $0x20, TKEYP
12969 + pax_force_retaddr
12970 ret
12971 ENDPROC(_key_expansion_192a)
12972
12973 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
12974
12975 movaps %xmm0, (TKEYP)
12976 add $0x10, TKEYP
12977 + pax_force_retaddr
12978 ret
12979 ENDPROC(_key_expansion_192b)
12980
12981 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
12982 pxor %xmm1, %xmm2
12983 movaps %xmm2, (TKEYP)
12984 add $0x10, TKEYP
12985 + pax_force_retaddr
12986 ret
12987 ENDPROC(_key_expansion_256b)
12988
12989 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12990 #ifndef __x86_64__
12991 popl KEYP
12992 #endif
12993 + pax_force_retaddr
12994 ret
12995 ENDPROC(aesni_set_key)
12996
12997 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12998 popl KLEN
12999 popl KEYP
13000 #endif
13001 + pax_force_retaddr
13002 ret
13003 ENDPROC(aesni_enc)
13004
13005 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13006 AESENC KEY STATE
13007 movaps 0x70(TKEYP), KEY
13008 AESENCLAST KEY STATE
13009 + pax_force_retaddr
13010 ret
13011 ENDPROC(_aesni_enc1)
13012
13013 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13014 AESENCLAST KEY STATE2
13015 AESENCLAST KEY STATE3
13016 AESENCLAST KEY STATE4
13017 + pax_force_retaddr
13018 ret
13019 ENDPROC(_aesni_enc4)
13020
13021 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13022 popl KLEN
13023 popl KEYP
13024 #endif
13025 + pax_force_retaddr
13026 ret
13027 ENDPROC(aesni_dec)
13028
13029 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13030 AESDEC KEY STATE
13031 movaps 0x70(TKEYP), KEY
13032 AESDECLAST KEY STATE
13033 + pax_force_retaddr
13034 ret
13035 ENDPROC(_aesni_dec1)
13036
13037 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13038 AESDECLAST KEY STATE2
13039 AESDECLAST KEY STATE3
13040 AESDECLAST KEY STATE4
13041 + pax_force_retaddr
13042 ret
13043 ENDPROC(_aesni_dec4)
13044
13045 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13046 popl KEYP
13047 popl LEN
13048 #endif
13049 + pax_force_retaddr
13050 ret
13051 ENDPROC(aesni_ecb_enc)
13052
13053 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13054 popl KEYP
13055 popl LEN
13056 #endif
13057 + pax_force_retaddr
13058 ret
13059 ENDPROC(aesni_ecb_dec)
13060
13061 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13062 popl LEN
13063 popl IVP
13064 #endif
13065 + pax_force_retaddr
13066 ret
13067 ENDPROC(aesni_cbc_enc)
13068
13069 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13070 popl LEN
13071 popl IVP
13072 #endif
13073 + pax_force_retaddr
13074 ret
13075 ENDPROC(aesni_cbc_dec)
13076
13077 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13078 mov $1, TCTR_LOW
13079 MOVQ_R64_XMM TCTR_LOW INC
13080 MOVQ_R64_XMM CTR TCTR_LOW
13081 + pax_force_retaddr
13082 ret
13083 ENDPROC(_aesni_inc_init)
13084
13085 @@ -2579,6 +2598,7 @@ _aesni_inc:
13086 .Linc_low:
13087 movaps CTR, IV
13088 PSHUFB_XMM BSWAP_MASK IV
13089 + pax_force_retaddr
13090 ret
13091 ENDPROC(_aesni_inc)
13092
13093 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13094 .Lctr_enc_ret:
13095 movups IV, (IVP)
13096 .Lctr_enc_just_ret:
13097 + pax_force_retaddr
13098 ret
13099 ENDPROC(aesni_ctr_enc)
13100
13101 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13102 pxor INC, STATE4
13103 movdqu STATE4, 0x70(OUTP)
13104
13105 + pax_force_retaddr
13106 ret
13107 ENDPROC(aesni_xts_crypt8)
13108
13109 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13110 index 246c670..466e2d6 100644
13111 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13112 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13113 @@ -21,6 +21,7 @@
13114 */
13115
13116 #include <linux/linkage.h>
13117 +#include <asm/alternative-asm.h>
13118
13119 .file "blowfish-x86_64-asm.S"
13120 .text
13121 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13122 jnz .L__enc_xor;
13123
13124 write_block();
13125 + pax_force_retaddr
13126 ret;
13127 .L__enc_xor:
13128 xor_block();
13129 + pax_force_retaddr
13130 ret;
13131 ENDPROC(__blowfish_enc_blk)
13132
13133 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13134
13135 movq %r11, %rbp;
13136
13137 + pax_force_retaddr
13138 ret;
13139 ENDPROC(blowfish_dec_blk)
13140
13141 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13142
13143 popq %rbx;
13144 popq %rbp;
13145 + pax_force_retaddr
13146 ret;
13147
13148 .L__enc_xor4:
13149 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13150
13151 popq %rbx;
13152 popq %rbp;
13153 + pax_force_retaddr
13154 ret;
13155 ENDPROC(__blowfish_enc_blk_4way)
13156
13157 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13158 popq %rbx;
13159 popq %rbp;
13160
13161 + pax_force_retaddr
13162 ret;
13163 ENDPROC(blowfish_dec_blk_4way)
13164 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13165 index ce71f92..1dce7ec 100644
13166 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13167 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13168 @@ -16,6 +16,7 @@
13169 */
13170
13171 #include <linux/linkage.h>
13172 +#include <asm/alternative-asm.h>
13173
13174 #define CAMELLIA_TABLE_BYTE_LEN 272
13175
13176 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13177 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13178 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13179 %rcx, (%r9));
13180 + pax_force_retaddr
13181 ret;
13182 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13183
13184 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13185 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13186 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13187 %rax, (%r9));
13188 + pax_force_retaddr
13189 ret;
13190 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13191
13192 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13193 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13194 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13195
13196 + pax_force_retaddr
13197 ret;
13198
13199 .align 8
13200 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13201 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13202 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13203
13204 + pax_force_retaddr
13205 ret;
13206
13207 .align 8
13208 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13209 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13210 %xmm8, %rsi);
13211
13212 + pax_force_retaddr
13213 ret;
13214 ENDPROC(camellia_ecb_enc_16way)
13215
13216 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13217 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13218 %xmm8, %rsi);
13219
13220 + pax_force_retaddr
13221 ret;
13222 ENDPROC(camellia_ecb_dec_16way)
13223
13224 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13225 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13226 %xmm8, %rsi);
13227
13228 + pax_force_retaddr
13229 ret;
13230 ENDPROC(camellia_cbc_dec_16way)
13231
13232 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13233 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13234 %xmm8, %rsi);
13235
13236 + pax_force_retaddr
13237 ret;
13238 ENDPROC(camellia_ctr_16way)
13239
13240 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13241 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13242 %xmm8, %rsi);
13243
13244 + pax_force_retaddr
13245 ret;
13246 ENDPROC(camellia_xts_crypt_16way)
13247
13248 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13249 index 0e0b886..5a3123c 100644
13250 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13251 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13252 @@ -11,6 +11,7 @@
13253 */
13254
13255 #include <linux/linkage.h>
13256 +#include <asm/alternative-asm.h>
13257
13258 #define CAMELLIA_TABLE_BYTE_LEN 272
13259
13260 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13261 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13262 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13263 %rcx, (%r9));
13264 + pax_force_retaddr
13265 ret;
13266 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13267
13268 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13269 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13270 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13271 %rax, (%r9));
13272 + pax_force_retaddr
13273 ret;
13274 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13275
13276 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13277 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13278 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13279
13280 + pax_force_retaddr
13281 ret;
13282
13283 .align 8
13284 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13285 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13286 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13287
13288 + pax_force_retaddr
13289 ret;
13290
13291 .align 8
13292 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13293
13294 vzeroupper;
13295
13296 + pax_force_retaddr
13297 ret;
13298 ENDPROC(camellia_ecb_enc_32way)
13299
13300 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13301
13302 vzeroupper;
13303
13304 + pax_force_retaddr
13305 ret;
13306 ENDPROC(camellia_ecb_dec_32way)
13307
13308 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13309
13310 vzeroupper;
13311
13312 + pax_force_retaddr
13313 ret;
13314 ENDPROC(camellia_cbc_dec_32way)
13315
13316 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13317
13318 vzeroupper;
13319
13320 + pax_force_retaddr
13321 ret;
13322 ENDPROC(camellia_ctr_32way)
13323
13324 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13325
13326 vzeroupper;
13327
13328 + pax_force_retaddr
13329 ret;
13330 ENDPROC(camellia_xts_crypt_32way)
13331
13332 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13333 index 310319c..db3d7b5 100644
13334 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13335 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13336 @@ -21,6 +21,7 @@
13337 */
13338
13339 #include <linux/linkage.h>
13340 +#include <asm/alternative-asm.h>
13341
13342 .file "camellia-x86_64-asm_64.S"
13343 .text
13344 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13345 enc_outunpack(mov, RT1);
13346
13347 movq RRBP, %rbp;
13348 + pax_force_retaddr
13349 ret;
13350
13351 .L__enc_xor:
13352 enc_outunpack(xor, RT1);
13353
13354 movq RRBP, %rbp;
13355 + pax_force_retaddr
13356 ret;
13357 ENDPROC(__camellia_enc_blk)
13358
13359 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13360 dec_outunpack();
13361
13362 movq RRBP, %rbp;
13363 + pax_force_retaddr
13364 ret;
13365 ENDPROC(camellia_dec_blk)
13366
13367 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13368
13369 movq RRBP, %rbp;
13370 popq %rbx;
13371 + pax_force_retaddr
13372 ret;
13373
13374 .L__enc2_xor:
13375 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13376
13377 movq RRBP, %rbp;
13378 popq %rbx;
13379 + pax_force_retaddr
13380 ret;
13381 ENDPROC(__camellia_enc_blk_2way)
13382
13383 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13384
13385 movq RRBP, %rbp;
13386 movq RXOR, %rbx;
13387 + pax_force_retaddr
13388 ret;
13389 ENDPROC(camellia_dec_blk_2way)
13390 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13391 index c35fd5d..2d8c7db 100644
13392 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13393 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13394 @@ -24,6 +24,7 @@
13395 */
13396
13397 #include <linux/linkage.h>
13398 +#include <asm/alternative-asm.h>
13399
13400 .file "cast5-avx-x86_64-asm_64.S"
13401
13402 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13403 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13404 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13405
13406 + pax_force_retaddr
13407 ret;
13408 ENDPROC(__cast5_enc_blk16)
13409
13410 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13411 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13412 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13413
13414 + pax_force_retaddr
13415 ret;
13416
13417 .L__skip_dec:
13418 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13419 vmovdqu RR4, (6*4*4)(%r11);
13420 vmovdqu RL4, (7*4*4)(%r11);
13421
13422 + pax_force_retaddr
13423 ret;
13424 ENDPROC(cast5_ecb_enc_16way)
13425
13426 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13427 vmovdqu RR4, (6*4*4)(%r11);
13428 vmovdqu RL4, (7*4*4)(%r11);
13429
13430 + pax_force_retaddr
13431 ret;
13432 ENDPROC(cast5_ecb_dec_16way)
13433
13434 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13435 * %rdx: src
13436 */
13437
13438 - pushq %r12;
13439 + pushq %r14;
13440
13441 movq %rsi, %r11;
13442 - movq %rdx, %r12;
13443 + movq %rdx, %r14;
13444
13445 vmovdqu (0*16)(%rdx), RL1;
13446 vmovdqu (1*16)(%rdx), RR1;
13447 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13448 call __cast5_dec_blk16;
13449
13450 /* xor with src */
13451 - vmovq (%r12), RX;
13452 + vmovq (%r14), RX;
13453 vpshufd $0x4f, RX, RX;
13454 vpxor RX, RR1, RR1;
13455 - vpxor 0*16+8(%r12), RL1, RL1;
13456 - vpxor 1*16+8(%r12), RR2, RR2;
13457 - vpxor 2*16+8(%r12), RL2, RL2;
13458 - vpxor 3*16+8(%r12), RR3, RR3;
13459 - vpxor 4*16+8(%r12), RL3, RL3;
13460 - vpxor 5*16+8(%r12), RR4, RR4;
13461 - vpxor 6*16+8(%r12), RL4, RL4;
13462 + vpxor 0*16+8(%r14), RL1, RL1;
13463 + vpxor 1*16+8(%r14), RR2, RR2;
13464 + vpxor 2*16+8(%r14), RL2, RL2;
13465 + vpxor 3*16+8(%r14), RR3, RR3;
13466 + vpxor 4*16+8(%r14), RL3, RL3;
13467 + vpxor 5*16+8(%r14), RR4, RR4;
13468 + vpxor 6*16+8(%r14), RL4, RL4;
13469
13470 vmovdqu RR1, (0*16)(%r11);
13471 vmovdqu RL1, (1*16)(%r11);
13472 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13473 vmovdqu RR4, (6*16)(%r11);
13474 vmovdqu RL4, (7*16)(%r11);
13475
13476 - popq %r12;
13477 + popq %r14;
13478
13479 + pax_force_retaddr
13480 ret;
13481 ENDPROC(cast5_cbc_dec_16way)
13482
13483 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13484 * %rcx: iv (big endian, 64bit)
13485 */
13486
13487 - pushq %r12;
13488 + pushq %r14;
13489
13490 movq %rsi, %r11;
13491 - movq %rdx, %r12;
13492 + movq %rdx, %r14;
13493
13494 vpcmpeqd RTMP, RTMP, RTMP;
13495 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13496 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13497 call __cast5_enc_blk16;
13498
13499 /* dst = src ^ iv */
13500 - vpxor (0*16)(%r12), RR1, RR1;
13501 - vpxor (1*16)(%r12), RL1, RL1;
13502 - vpxor (2*16)(%r12), RR2, RR2;
13503 - vpxor (3*16)(%r12), RL2, RL2;
13504 - vpxor (4*16)(%r12), RR3, RR3;
13505 - vpxor (5*16)(%r12), RL3, RL3;
13506 - vpxor (6*16)(%r12), RR4, RR4;
13507 - vpxor (7*16)(%r12), RL4, RL4;
13508 + vpxor (0*16)(%r14), RR1, RR1;
13509 + vpxor (1*16)(%r14), RL1, RL1;
13510 + vpxor (2*16)(%r14), RR2, RR2;
13511 + vpxor (3*16)(%r14), RL2, RL2;
13512 + vpxor (4*16)(%r14), RR3, RR3;
13513 + vpxor (5*16)(%r14), RL3, RL3;
13514 + vpxor (6*16)(%r14), RR4, RR4;
13515 + vpxor (7*16)(%r14), RL4, RL4;
13516 vmovdqu RR1, (0*16)(%r11);
13517 vmovdqu RL1, (1*16)(%r11);
13518 vmovdqu RR2, (2*16)(%r11);
13519 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13520 vmovdqu RR4, (6*16)(%r11);
13521 vmovdqu RL4, (7*16)(%r11);
13522
13523 - popq %r12;
13524 + popq %r14;
13525
13526 + pax_force_retaddr
13527 ret;
13528 ENDPROC(cast5_ctr_16way)
13529 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13530 index e3531f8..e123f35 100644
13531 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13532 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13533 @@ -24,6 +24,7 @@
13534 */
13535
13536 #include <linux/linkage.h>
13537 +#include <asm/alternative-asm.h>
13538 #include "glue_helper-asm-avx.S"
13539
13540 .file "cast6-avx-x86_64-asm_64.S"
13541 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13542 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13543 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13544
13545 + pax_force_retaddr
13546 ret;
13547 ENDPROC(__cast6_enc_blk8)
13548
13549 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13550 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13551 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13552
13553 + pax_force_retaddr
13554 ret;
13555 ENDPROC(__cast6_dec_blk8)
13556
13557 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13558
13559 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13560
13561 + pax_force_retaddr
13562 ret;
13563 ENDPROC(cast6_ecb_enc_8way)
13564
13565 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13566
13567 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13568
13569 + pax_force_retaddr
13570 ret;
13571 ENDPROC(cast6_ecb_dec_8way)
13572
13573 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13574 * %rdx: src
13575 */
13576
13577 - pushq %r12;
13578 + pushq %r14;
13579
13580 movq %rsi, %r11;
13581 - movq %rdx, %r12;
13582 + movq %rdx, %r14;
13583
13584 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13585
13586 call __cast6_dec_blk8;
13587
13588 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13589 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13590
13591 - popq %r12;
13592 + popq %r14;
13593
13594 + pax_force_retaddr
13595 ret;
13596 ENDPROC(cast6_cbc_dec_8way)
13597
13598 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13599 * %rcx: iv (little endian, 128bit)
13600 */
13601
13602 - pushq %r12;
13603 + pushq %r14;
13604
13605 movq %rsi, %r11;
13606 - movq %rdx, %r12;
13607 + movq %rdx, %r14;
13608
13609 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13610 RD2, RX, RKR, RKM);
13611
13612 call __cast6_enc_blk8;
13613
13614 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13615 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13616
13617 - popq %r12;
13618 + popq %r14;
13619
13620 + pax_force_retaddr
13621 ret;
13622 ENDPROC(cast6_ctr_8way)
13623
13624 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13625 /* dst <= regs xor IVs(in dst) */
13626 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13627
13628 + pax_force_retaddr
13629 ret;
13630 ENDPROC(cast6_xts_enc_8way)
13631
13632 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13633 /* dst <= regs xor IVs(in dst) */
13634 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13635
13636 + pax_force_retaddr
13637 ret;
13638 ENDPROC(cast6_xts_dec_8way)
13639 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13640 index dbc4339..de6e120 100644
13641 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13642 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13643 @@ -45,6 +45,7 @@
13644
13645 #include <asm/inst.h>
13646 #include <linux/linkage.h>
13647 +#include <asm/alternative-asm.h>
13648
13649 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13650
13651 @@ -312,6 +313,7 @@ do_return:
13652 popq %rsi
13653 popq %rdi
13654 popq %rbx
13655 + pax_force_retaddr
13656 ret
13657
13658 ################################################################
13659 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13660 index 586f41a..d02851e 100644
13661 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13662 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13663 @@ -18,6 +18,7 @@
13664
13665 #include <linux/linkage.h>
13666 #include <asm/inst.h>
13667 +#include <asm/alternative-asm.h>
13668
13669 .data
13670
13671 @@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13672 psrlq $1, T2
13673 pxor T2, T1
13674 pxor T1, DATA
13675 + pax_force_retaddr
13676 ret
13677 ENDPROC(__clmul_gf128mul_ble)
13678
13679 @@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13680 call __clmul_gf128mul_ble
13681 PSHUFB_XMM BSWAP DATA
13682 movups DATA, (%rdi)
13683 + pax_force_retaddr
13684 ret
13685 ENDPROC(clmul_ghash_mul)
13686
13687 @@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13688 PSHUFB_XMM BSWAP DATA
13689 movups DATA, (%rdi)
13690 .Lupdate_just_ret:
13691 + pax_force_retaddr
13692 ret
13693 ENDPROC(clmul_ghash_update)
13694
13695 @@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13696 pand .Lpoly, %xmm1
13697 pxor %xmm1, %xmm0
13698 movups %xmm0, (%rdi)
13699 + pax_force_retaddr
13700 ret
13701 ENDPROC(clmul_ghash_setkey)
13702 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13703 index 9279e0b..c4b3d2c 100644
13704 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13705 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13706 @@ -1,4 +1,5 @@
13707 #include <linux/linkage.h>
13708 +#include <asm/alternative-asm.h>
13709
13710 # enter salsa20_encrypt_bytes
13711 ENTRY(salsa20_encrypt_bytes)
13712 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13713 add %r11,%rsp
13714 mov %rdi,%rax
13715 mov %rsi,%rdx
13716 + pax_force_retaddr
13717 ret
13718 # bytesatleast65:
13719 ._bytesatleast65:
13720 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13721 add %r11,%rsp
13722 mov %rdi,%rax
13723 mov %rsi,%rdx
13724 + pax_force_retaddr
13725 ret
13726 ENDPROC(salsa20_keysetup)
13727
13728 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13729 add %r11,%rsp
13730 mov %rdi,%rax
13731 mov %rsi,%rdx
13732 + pax_force_retaddr
13733 ret
13734 ENDPROC(salsa20_ivsetup)
13735 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13736 index 2f202f4..d9164d6 100644
13737 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13738 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13739 @@ -24,6 +24,7 @@
13740 */
13741
13742 #include <linux/linkage.h>
13743 +#include <asm/alternative-asm.h>
13744 #include "glue_helper-asm-avx.S"
13745
13746 .file "serpent-avx-x86_64-asm_64.S"
13747 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13748 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13749 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13750
13751 + pax_force_retaddr
13752 ret;
13753 ENDPROC(__serpent_enc_blk8_avx)
13754
13755 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13756 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13757 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13758
13759 + pax_force_retaddr
13760 ret;
13761 ENDPROC(__serpent_dec_blk8_avx)
13762
13763 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13764
13765 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13766
13767 + pax_force_retaddr
13768 ret;
13769 ENDPROC(serpent_ecb_enc_8way_avx)
13770
13771 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13772
13773 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13774
13775 + pax_force_retaddr
13776 ret;
13777 ENDPROC(serpent_ecb_dec_8way_avx)
13778
13779 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13780
13781 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13782
13783 + pax_force_retaddr
13784 ret;
13785 ENDPROC(serpent_cbc_dec_8way_avx)
13786
13787 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13788
13789 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13790
13791 + pax_force_retaddr
13792 ret;
13793 ENDPROC(serpent_ctr_8way_avx)
13794
13795 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13796 /* dst <= regs xor IVs(in dst) */
13797 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13798
13799 + pax_force_retaddr
13800 ret;
13801 ENDPROC(serpent_xts_enc_8way_avx)
13802
13803 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13804 /* dst <= regs xor IVs(in dst) */
13805 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13806
13807 + pax_force_retaddr
13808 ret;
13809 ENDPROC(serpent_xts_dec_8way_avx)
13810 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13811 index b222085..abd483c 100644
13812 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13813 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13814 @@ -15,6 +15,7 @@
13815 */
13816
13817 #include <linux/linkage.h>
13818 +#include <asm/alternative-asm.h>
13819 #include "glue_helper-asm-avx2.S"
13820
13821 .file "serpent-avx2-asm_64.S"
13822 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13823 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13824 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13825
13826 + pax_force_retaddr
13827 ret;
13828 ENDPROC(__serpent_enc_blk16)
13829
13830 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13831 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13832 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13833
13834 + pax_force_retaddr
13835 ret;
13836 ENDPROC(__serpent_dec_blk16)
13837
13838 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13839
13840 vzeroupper;
13841
13842 + pax_force_retaddr
13843 ret;
13844 ENDPROC(serpent_ecb_enc_16way)
13845
13846 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13847
13848 vzeroupper;
13849
13850 + pax_force_retaddr
13851 ret;
13852 ENDPROC(serpent_ecb_dec_16way)
13853
13854 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13855
13856 vzeroupper;
13857
13858 + pax_force_retaddr
13859 ret;
13860 ENDPROC(serpent_cbc_dec_16way)
13861
13862 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13863
13864 vzeroupper;
13865
13866 + pax_force_retaddr
13867 ret;
13868 ENDPROC(serpent_ctr_16way)
13869
13870 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13871
13872 vzeroupper;
13873
13874 + pax_force_retaddr
13875 ret;
13876 ENDPROC(serpent_xts_enc_16way)
13877
13878 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13879
13880 vzeroupper;
13881
13882 + pax_force_retaddr
13883 ret;
13884 ENDPROC(serpent_xts_dec_16way)
13885 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13886 index acc066c..1559cc4 100644
13887 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13888 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13889 @@ -25,6 +25,7 @@
13890 */
13891
13892 #include <linux/linkage.h>
13893 +#include <asm/alternative-asm.h>
13894
13895 .file "serpent-sse2-x86_64-asm_64.S"
13896 .text
13897 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13898 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13899 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13900
13901 + pax_force_retaddr
13902 ret;
13903
13904 .L__enc_xor8:
13905 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13906 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13907
13908 + pax_force_retaddr
13909 ret;
13910 ENDPROC(__serpent_enc_blk_8way)
13911
13912 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13913 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13914 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13915
13916 + pax_force_retaddr
13917 ret;
13918 ENDPROC(serpent_dec_blk_8way)
13919 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13920 index a410950..9dfe7ad 100644
13921 --- a/arch/x86/crypto/sha1_ssse3_asm.S
13922 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
13923 @@ -29,6 +29,7 @@
13924 */
13925
13926 #include <linux/linkage.h>
13927 +#include <asm/alternative-asm.h>
13928
13929 #define CTX %rdi // arg1
13930 #define BUF %rsi // arg2
13931 @@ -75,9 +76,9 @@
13932
13933 push %rbx
13934 push %rbp
13935 - push %r12
13936 + push %r14
13937
13938 - mov %rsp, %r12
13939 + mov %rsp, %r14
13940 sub $64, %rsp # allocate workspace
13941 and $~15, %rsp # align stack
13942
13943 @@ -99,11 +100,12 @@
13944 xor %rax, %rax
13945 rep stosq
13946
13947 - mov %r12, %rsp # deallocate workspace
13948 + mov %r14, %rsp # deallocate workspace
13949
13950 - pop %r12
13951 + pop %r14
13952 pop %rbp
13953 pop %rbx
13954 + pax_force_retaddr
13955 ret
13956
13957 ENDPROC(\name)
13958 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13959 index 642f156..51a513c 100644
13960 --- a/arch/x86/crypto/sha256-avx-asm.S
13961 +++ b/arch/x86/crypto/sha256-avx-asm.S
13962 @@ -49,6 +49,7 @@
13963
13964 #ifdef CONFIG_AS_AVX
13965 #include <linux/linkage.h>
13966 +#include <asm/alternative-asm.h>
13967
13968 ## assume buffers not aligned
13969 #define VMOVDQ vmovdqu
13970 @@ -460,6 +461,7 @@ done_hash:
13971 popq %r13
13972 popq %rbp
13973 popq %rbx
13974 + pax_force_retaddr
13975 ret
13976 ENDPROC(sha256_transform_avx)
13977
13978 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13979 index 9e86944..3795e6a 100644
13980 --- a/arch/x86/crypto/sha256-avx2-asm.S
13981 +++ b/arch/x86/crypto/sha256-avx2-asm.S
13982 @@ -50,6 +50,7 @@
13983
13984 #ifdef CONFIG_AS_AVX2
13985 #include <linux/linkage.h>
13986 +#include <asm/alternative-asm.h>
13987
13988 ## assume buffers not aligned
13989 #define VMOVDQ vmovdqu
13990 @@ -720,6 +721,7 @@ done_hash:
13991 popq %r12
13992 popq %rbp
13993 popq %rbx
13994 + pax_force_retaddr
13995 ret
13996 ENDPROC(sha256_transform_rorx)
13997
13998 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13999 index f833b74..8c62a9e 100644
14000 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14001 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14002 @@ -47,6 +47,7 @@
14003 ########################################################################
14004
14005 #include <linux/linkage.h>
14006 +#include <asm/alternative-asm.h>
14007
14008 ## assume buffers not aligned
14009 #define MOVDQ movdqu
14010 @@ -471,6 +472,7 @@ done_hash:
14011 popq %rbp
14012 popq %rbx
14013
14014 + pax_force_retaddr
14015 ret
14016 ENDPROC(sha256_transform_ssse3)
14017
14018 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14019 index 974dde9..a823ff9 100644
14020 --- a/arch/x86/crypto/sha512-avx-asm.S
14021 +++ b/arch/x86/crypto/sha512-avx-asm.S
14022 @@ -49,6 +49,7 @@
14023
14024 #ifdef CONFIG_AS_AVX
14025 #include <linux/linkage.h>
14026 +#include <asm/alternative-asm.h>
14027
14028 .text
14029
14030 @@ -364,6 +365,7 @@ updateblock:
14031 mov frame_RSPSAVE(%rsp), %rsp
14032
14033 nowork:
14034 + pax_force_retaddr
14035 ret
14036 ENDPROC(sha512_transform_avx)
14037
14038 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14039 index 568b961..ed20c37 100644
14040 --- a/arch/x86/crypto/sha512-avx2-asm.S
14041 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14042 @@ -51,6 +51,7 @@
14043
14044 #ifdef CONFIG_AS_AVX2
14045 #include <linux/linkage.h>
14046 +#include <asm/alternative-asm.h>
14047
14048 .text
14049
14050 @@ -678,6 +679,7 @@ done_hash:
14051
14052 # Restore Stack Pointer
14053 mov frame_RSPSAVE(%rsp), %rsp
14054 + pax_force_retaddr
14055 ret
14056 ENDPROC(sha512_transform_rorx)
14057
14058 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14059 index fb56855..6edd768 100644
14060 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14061 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14062 @@ -48,6 +48,7 @@
14063 ########################################################################
14064
14065 #include <linux/linkage.h>
14066 +#include <asm/alternative-asm.h>
14067
14068 .text
14069
14070 @@ -363,6 +364,7 @@ updateblock:
14071 mov frame_RSPSAVE(%rsp), %rsp
14072
14073 nowork:
14074 + pax_force_retaddr
14075 ret
14076 ENDPROC(sha512_transform_ssse3)
14077
14078 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14079 index 0505813..b067311 100644
14080 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14081 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14082 @@ -24,6 +24,7 @@
14083 */
14084
14085 #include <linux/linkage.h>
14086 +#include <asm/alternative-asm.h>
14087 #include "glue_helper-asm-avx.S"
14088
14089 .file "twofish-avx-x86_64-asm_64.S"
14090 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14091 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14092 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14093
14094 + pax_force_retaddr
14095 ret;
14096 ENDPROC(__twofish_enc_blk8)
14097
14098 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14099 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14100 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14101
14102 + pax_force_retaddr
14103 ret;
14104 ENDPROC(__twofish_dec_blk8)
14105
14106 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14107
14108 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14109
14110 + pax_force_retaddr
14111 ret;
14112 ENDPROC(twofish_ecb_enc_8way)
14113
14114 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14115
14116 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14117
14118 + pax_force_retaddr
14119 ret;
14120 ENDPROC(twofish_ecb_dec_8way)
14121
14122 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14123 * %rdx: src
14124 */
14125
14126 - pushq %r12;
14127 + pushq %r14;
14128
14129 movq %rsi, %r11;
14130 - movq %rdx, %r12;
14131 + movq %rdx, %r14;
14132
14133 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14134
14135 call __twofish_dec_blk8;
14136
14137 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14138 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14139
14140 - popq %r12;
14141 + popq %r14;
14142
14143 + pax_force_retaddr
14144 ret;
14145 ENDPROC(twofish_cbc_dec_8way)
14146
14147 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14148 * %rcx: iv (little endian, 128bit)
14149 */
14150
14151 - pushq %r12;
14152 + pushq %r14;
14153
14154 movq %rsi, %r11;
14155 - movq %rdx, %r12;
14156 + movq %rdx, %r14;
14157
14158 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14159 RD2, RX0, RX1, RY0);
14160
14161 call __twofish_enc_blk8;
14162
14163 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14164 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14165
14166 - popq %r12;
14167 + popq %r14;
14168
14169 + pax_force_retaddr
14170 ret;
14171 ENDPROC(twofish_ctr_8way)
14172
14173 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14174 /* dst <= regs xor IVs(in dst) */
14175 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14176
14177 + pax_force_retaddr
14178 ret;
14179 ENDPROC(twofish_xts_enc_8way)
14180
14181 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14182 /* dst <= regs xor IVs(in dst) */
14183 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14184
14185 + pax_force_retaddr
14186 ret;
14187 ENDPROC(twofish_xts_dec_8way)
14188 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14189 index 1c3b7ce..02f578d 100644
14190 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14191 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14192 @@ -21,6 +21,7 @@
14193 */
14194
14195 #include <linux/linkage.h>
14196 +#include <asm/alternative-asm.h>
14197
14198 .file "twofish-x86_64-asm-3way.S"
14199 .text
14200 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14201 popq %r13;
14202 popq %r14;
14203 popq %r15;
14204 + pax_force_retaddr
14205 ret;
14206
14207 .L__enc_xor3:
14208 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14209 popq %r13;
14210 popq %r14;
14211 popq %r15;
14212 + pax_force_retaddr
14213 ret;
14214 ENDPROC(__twofish_enc_blk_3way)
14215
14216 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14217 popq %r13;
14218 popq %r14;
14219 popq %r15;
14220 + pax_force_retaddr
14221 ret;
14222 ENDPROC(twofish_dec_blk_3way)
14223 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14224 index a039d21..524b8b2 100644
14225 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14226 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14227 @@ -22,6 +22,7 @@
14228
14229 #include <linux/linkage.h>
14230 #include <asm/asm-offsets.h>
14231 +#include <asm/alternative-asm.h>
14232
14233 #define a_offset 0
14234 #define b_offset 4
14235 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14236
14237 popq R1
14238 movq $1,%rax
14239 + pax_force_retaddr
14240 ret
14241 ENDPROC(twofish_enc_blk)
14242
14243 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14244
14245 popq R1
14246 movq $1,%rax
14247 + pax_force_retaddr
14248 ret
14249 ENDPROC(twofish_dec_blk)
14250 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14251 index d21ff89..6da8e6e 100644
14252 --- a/arch/x86/ia32/ia32_aout.c
14253 +++ b/arch/x86/ia32/ia32_aout.c
14254 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14255 unsigned long dump_start, dump_size;
14256 struct user32 dump;
14257
14258 + memset(&dump, 0, sizeof(dump));
14259 +
14260 fs = get_fs();
14261 set_fs(KERNEL_DS);
14262 has_dumped = 1;
14263 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14264 index 2206757..85cbcfa 100644
14265 --- a/arch/x86/ia32/ia32_signal.c
14266 +++ b/arch/x86/ia32/ia32_signal.c
14267 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14268 if (__get_user(set.sig[0], &frame->sc.oldmask)
14269 || (_COMPAT_NSIG_WORDS > 1
14270 && __copy_from_user((((char *) &set.sig) + 4),
14271 - &frame->extramask,
14272 + frame->extramask,
14273 sizeof(frame->extramask))))
14274 goto badframe;
14275
14276 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14277 sp -= frame_size;
14278 /* Align the stack pointer according to the i386 ABI,
14279 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14280 - sp = ((sp + 4) & -16ul) - 4;
14281 + sp = ((sp - 12) & -16ul) - 4;
14282 return (void __user *) sp;
14283 }
14284
14285 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14286 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14287 sigreturn);
14288 else
14289 - restorer = &frame->retcode;
14290 + restorer = frame->retcode;
14291 }
14292
14293 put_user_try {
14294 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14295 * These are actually not used anymore, but left because some
14296 * gdb versions depend on them as a marker.
14297 */
14298 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14299 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14300 } put_user_catch(err);
14301
14302 if (err)
14303 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14304 0xb8,
14305 __NR_ia32_rt_sigreturn,
14306 0x80cd,
14307 - 0,
14308 + 0
14309 };
14310
14311 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14312 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14313
14314 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14315 restorer = ksig->ka.sa.sa_restorer;
14316 + else if (current->mm->context.vdso)
14317 + /* Return stub is in 32bit vsyscall page */
14318 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14319 else
14320 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14321 - rt_sigreturn);
14322 + restorer = frame->retcode;
14323 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14324
14325 /*
14326 * Not actually used anymore, but left because some gdb
14327 * versions need it.
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 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14334 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14335 index 4299eb0..c0687a7 100644
14336 --- a/arch/x86/ia32/ia32entry.S
14337 +++ b/arch/x86/ia32/ia32entry.S
14338 @@ -15,8 +15,10 @@
14339 #include <asm/irqflags.h>
14340 #include <asm/asm.h>
14341 #include <asm/smap.h>
14342 +#include <asm/pgtable.h>
14343 #include <linux/linkage.h>
14344 #include <linux/err.h>
14345 +#include <asm/alternative-asm.h>
14346
14347 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14348 #include <linux/elf-em.h>
14349 @@ -62,12 +64,12 @@
14350 */
14351 .macro LOAD_ARGS32 offset, _r9=0
14352 .if \_r9
14353 - movl \offset+16(%rsp),%r9d
14354 + movl \offset+R9(%rsp),%r9d
14355 .endif
14356 - movl \offset+40(%rsp),%ecx
14357 - movl \offset+48(%rsp),%edx
14358 - movl \offset+56(%rsp),%esi
14359 - movl \offset+64(%rsp),%edi
14360 + movl \offset+RCX(%rsp),%ecx
14361 + movl \offset+RDX(%rsp),%edx
14362 + movl \offset+RSI(%rsp),%esi
14363 + movl \offset+RDI(%rsp),%edi
14364 movl %eax,%eax /* zero extension */
14365 .endm
14366
14367 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14368 ENDPROC(native_irq_enable_sysexit)
14369 #endif
14370
14371 + .macro pax_enter_kernel_user
14372 + pax_set_fptr_mask
14373 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14374 + call pax_enter_kernel_user
14375 +#endif
14376 + .endm
14377 +
14378 + .macro pax_exit_kernel_user
14379 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14380 + call pax_exit_kernel_user
14381 +#endif
14382 +#ifdef CONFIG_PAX_RANDKSTACK
14383 + pushq %rax
14384 + pushq %r11
14385 + call pax_randomize_kstack
14386 + popq %r11
14387 + popq %rax
14388 +#endif
14389 + .endm
14390 +
14391 + .macro pax_erase_kstack
14392 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14393 + call pax_erase_kstack
14394 +#endif
14395 + .endm
14396 +
14397 /*
14398 * 32bit SYSENTER instruction entry.
14399 *
14400 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14401 CFI_REGISTER rsp,rbp
14402 SWAPGS_UNSAFE_STACK
14403 movq PER_CPU_VAR(kernel_stack), %rsp
14404 - addq $(KERNEL_STACK_OFFSET),%rsp
14405 - /*
14406 - * No need to follow this irqs on/off section: the syscall
14407 - * disabled irqs, here we enable it straight after entry:
14408 - */
14409 - ENABLE_INTERRUPTS(CLBR_NONE)
14410 movl %ebp,%ebp /* zero extension */
14411 pushq_cfi $__USER32_DS
14412 /*CFI_REL_OFFSET ss,0*/
14413 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14414 CFI_REL_OFFSET rsp,0
14415 pushfq_cfi
14416 /*CFI_REL_OFFSET rflags,0*/
14417 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14418 - CFI_REGISTER rip,r10
14419 + orl $X86_EFLAGS_IF,(%rsp)
14420 + GET_THREAD_INFO(%r11)
14421 + movl TI_sysenter_return(%r11), %r11d
14422 + CFI_REGISTER rip,r11
14423 pushq_cfi $__USER32_CS
14424 /*CFI_REL_OFFSET cs,0*/
14425 movl %eax, %eax
14426 - pushq_cfi %r10
14427 + pushq_cfi %r11
14428 CFI_REL_OFFSET rip,0
14429 pushq_cfi %rax
14430 cld
14431 SAVE_ARGS 0,1,0
14432 + pax_enter_kernel_user
14433 +
14434 +#ifdef CONFIG_PAX_RANDKSTACK
14435 + pax_erase_kstack
14436 +#endif
14437 +
14438 + /*
14439 + * No need to follow this irqs on/off section: the syscall
14440 + * disabled irqs, here we enable it straight after entry:
14441 + */
14442 + ENABLE_INTERRUPTS(CLBR_NONE)
14443 /* no need to do an access_ok check here because rbp has been
14444 32bit zero extended */
14445 +
14446 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14447 + addq pax_user_shadow_base,%rbp
14448 + ASM_PAX_OPEN_USERLAND
14449 +#endif
14450 +
14451 ASM_STAC
14452 1: movl (%rbp),%ebp
14453 _ASM_EXTABLE(1b,ia32_badarg)
14454 ASM_CLAC
14455 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14456 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14457 +
14458 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14459 + ASM_PAX_CLOSE_USERLAND
14460 +#endif
14461 +
14462 + GET_THREAD_INFO(%r11)
14463 + orl $TS_COMPAT,TI_status(%r11)
14464 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14465 CFI_REMEMBER_STATE
14466 jnz sysenter_tracesys
14467 cmpq $(IA32_NR_syscalls-1),%rax
14468 @@ -162,15 +209,18 @@ sysenter_do_call:
14469 sysenter_dispatch:
14470 call *ia32_sys_call_table(,%rax,8)
14471 movq %rax,RAX-ARGOFFSET(%rsp)
14472 + GET_THREAD_INFO(%r11)
14473 DISABLE_INTERRUPTS(CLBR_NONE)
14474 TRACE_IRQS_OFF
14475 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14476 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14477 jnz sysexit_audit
14478 sysexit_from_sys_call:
14479 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14480 + pax_exit_kernel_user
14481 + pax_erase_kstack
14482 + andl $~TS_COMPAT,TI_status(%r11)
14483 /* clear IF, that popfq doesn't enable interrupts early */
14484 - andl $~0x200,EFLAGS-R11(%rsp)
14485 - movl RIP-R11(%rsp),%edx /* User %eip */
14486 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14487 + movl RIP(%rsp),%edx /* User %eip */
14488 CFI_REGISTER rip,rdx
14489 RESTORE_ARGS 0,24,0,0,0,0
14490 xorq %r8,%r8
14491 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14492 movl %eax,%esi /* 2nd arg: syscall number */
14493 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14494 call __audit_syscall_entry
14495 +
14496 + pax_erase_kstack
14497 +
14498 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14499 cmpq $(IA32_NR_syscalls-1),%rax
14500 ja ia32_badsys
14501 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14502 .endm
14503
14504 .macro auditsys_exit exit
14505 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14506 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14507 jnz ia32_ret_from_sys_call
14508 TRACE_IRQS_ON
14509 ENABLE_INTERRUPTS(CLBR_NONE)
14510 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14511 1: setbe %al /* 1 if error, 0 if not */
14512 movzbl %al,%edi /* zero-extend that into %edi */
14513 call __audit_syscall_exit
14514 + GET_THREAD_INFO(%r11)
14515 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14516 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14517 DISABLE_INTERRUPTS(CLBR_NONE)
14518 TRACE_IRQS_OFF
14519 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14520 + testl %edi,TI_flags(%r11)
14521 jz \exit
14522 CLEAR_RREGS -ARGOFFSET
14523 jmp int_with_check
14524 @@ -237,7 +291,7 @@ sysexit_audit:
14525
14526 sysenter_tracesys:
14527 #ifdef CONFIG_AUDITSYSCALL
14528 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14529 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14530 jz sysenter_auditsys
14531 #endif
14532 SAVE_REST
14533 @@ -249,6 +303,9 @@ sysenter_tracesys:
14534 RESTORE_REST
14535 cmpq $(IA32_NR_syscalls-1),%rax
14536 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14537 +
14538 + pax_erase_kstack
14539 +
14540 jmp sysenter_do_call
14541 CFI_ENDPROC
14542 ENDPROC(ia32_sysenter_target)
14543 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14544 ENTRY(ia32_cstar_target)
14545 CFI_STARTPROC32 simple
14546 CFI_SIGNAL_FRAME
14547 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14548 + CFI_DEF_CFA rsp,0
14549 CFI_REGISTER rip,rcx
14550 /*CFI_REGISTER rflags,r11*/
14551 SWAPGS_UNSAFE_STACK
14552 movl %esp,%r8d
14553 CFI_REGISTER rsp,r8
14554 movq PER_CPU_VAR(kernel_stack),%rsp
14555 + SAVE_ARGS 8*6,0,0
14556 + pax_enter_kernel_user
14557 +
14558 +#ifdef CONFIG_PAX_RANDKSTACK
14559 + pax_erase_kstack
14560 +#endif
14561 +
14562 /*
14563 * No need to follow this irqs on/off section: the syscall
14564 * disabled irqs and here we enable it straight after entry:
14565 */
14566 ENABLE_INTERRUPTS(CLBR_NONE)
14567 - SAVE_ARGS 8,0,0
14568 movl %eax,%eax /* zero extension */
14569 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14570 movq %rcx,RIP-ARGOFFSET(%rsp)
14571 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14572 /* no need to do an access_ok check here because r8 has been
14573 32bit zero extended */
14574 /* hardware stack frame is complete now */
14575 +
14576 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14577 + ASM_PAX_OPEN_USERLAND
14578 + movq pax_user_shadow_base,%r8
14579 + addq RSP-ARGOFFSET(%rsp),%r8
14580 +#endif
14581 +
14582 ASM_STAC
14583 1: movl (%r8),%r9d
14584 _ASM_EXTABLE(1b,ia32_badarg)
14585 ASM_CLAC
14586 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14587 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14588 +
14589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14590 + ASM_PAX_CLOSE_USERLAND
14591 +#endif
14592 +
14593 + GET_THREAD_INFO(%r11)
14594 + orl $TS_COMPAT,TI_status(%r11)
14595 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14596 CFI_REMEMBER_STATE
14597 jnz cstar_tracesys
14598 cmpq $IA32_NR_syscalls-1,%rax
14599 @@ -319,13 +395,16 @@ cstar_do_call:
14600 cstar_dispatch:
14601 call *ia32_sys_call_table(,%rax,8)
14602 movq %rax,RAX-ARGOFFSET(%rsp)
14603 + GET_THREAD_INFO(%r11)
14604 DISABLE_INTERRUPTS(CLBR_NONE)
14605 TRACE_IRQS_OFF
14606 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14607 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14608 jnz sysretl_audit
14609 sysretl_from_sys_call:
14610 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14611 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14612 + pax_exit_kernel_user
14613 + pax_erase_kstack
14614 + andl $~TS_COMPAT,TI_status(%r11)
14615 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14616 movl RIP-ARGOFFSET(%rsp),%ecx
14617 CFI_REGISTER rip,rcx
14618 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14619 @@ -352,7 +431,7 @@ sysretl_audit:
14620
14621 cstar_tracesys:
14622 #ifdef CONFIG_AUDITSYSCALL
14623 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14624 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14625 jz cstar_auditsys
14626 #endif
14627 xchgl %r9d,%ebp
14628 @@ -366,11 +445,19 @@ cstar_tracesys:
14629 xchgl %ebp,%r9d
14630 cmpq $(IA32_NR_syscalls-1),%rax
14631 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14632 +
14633 + pax_erase_kstack
14634 +
14635 jmp cstar_do_call
14636 END(ia32_cstar_target)
14637
14638 ia32_badarg:
14639 ASM_CLAC
14640 +
14641 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14642 + ASM_PAX_CLOSE_USERLAND
14643 +#endif
14644 +
14645 movq $-EFAULT,%rax
14646 jmp ia32_sysret
14647 CFI_ENDPROC
14648 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14649 CFI_REL_OFFSET rip,RIP-RIP
14650 PARAVIRT_ADJUST_EXCEPTION_FRAME
14651 SWAPGS
14652 - /*
14653 - * No need to follow this irqs on/off section: the syscall
14654 - * disabled irqs and here we enable it straight after entry:
14655 - */
14656 - ENABLE_INTERRUPTS(CLBR_NONE)
14657 movl %eax,%eax
14658 pushq_cfi %rax
14659 cld
14660 /* note the registers are not zero extended to the sf.
14661 this could be a problem. */
14662 SAVE_ARGS 0,1,0
14663 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14664 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14665 + pax_enter_kernel_user
14666 +
14667 +#ifdef CONFIG_PAX_RANDKSTACK
14668 + pax_erase_kstack
14669 +#endif
14670 +
14671 + /*
14672 + * No need to follow this irqs on/off section: the syscall
14673 + * disabled irqs and here we enable it straight after entry:
14674 + */
14675 + ENABLE_INTERRUPTS(CLBR_NONE)
14676 + GET_THREAD_INFO(%r11)
14677 + orl $TS_COMPAT,TI_status(%r11)
14678 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14679 jnz ia32_tracesys
14680 cmpq $(IA32_NR_syscalls-1),%rax
14681 ja ia32_badsys
14682 @@ -442,6 +536,9 @@ ia32_tracesys:
14683 RESTORE_REST
14684 cmpq $(IA32_NR_syscalls-1),%rax
14685 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14686 +
14687 + pax_erase_kstack
14688 +
14689 jmp ia32_do_call
14690 END(ia32_syscall)
14691
14692 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14693 index 8e0ceec..af13504 100644
14694 --- a/arch/x86/ia32/sys_ia32.c
14695 +++ b/arch/x86/ia32/sys_ia32.c
14696 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14697 */
14698 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14699 {
14700 - typeof(ubuf->st_uid) uid = 0;
14701 - typeof(ubuf->st_gid) gid = 0;
14702 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14703 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14704 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14705 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14706 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14707 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14708 index 372231c..51b537d 100644
14709 --- a/arch/x86/include/asm/alternative-asm.h
14710 +++ b/arch/x86/include/asm/alternative-asm.h
14711 @@ -18,6 +18,45 @@
14712 .endm
14713 #endif
14714
14715 +#ifdef KERNEXEC_PLUGIN
14716 + .macro pax_force_retaddr_bts rip=0
14717 + btsq $63,\rip(%rsp)
14718 + .endm
14719 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14720 + .macro pax_force_retaddr rip=0, reload=0
14721 + btsq $63,\rip(%rsp)
14722 + .endm
14723 + .macro pax_force_fptr ptr
14724 + btsq $63,\ptr
14725 + .endm
14726 + .macro pax_set_fptr_mask
14727 + .endm
14728 +#endif
14729 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14730 + .macro pax_force_retaddr rip=0, reload=0
14731 + .if \reload
14732 + pax_set_fptr_mask
14733 + .endif
14734 + orq %r12,\rip(%rsp)
14735 + .endm
14736 + .macro pax_force_fptr ptr
14737 + orq %r12,\ptr
14738 + .endm
14739 + .macro pax_set_fptr_mask
14740 + movabs $0x8000000000000000,%r12
14741 + .endm
14742 +#endif
14743 +#else
14744 + .macro pax_force_retaddr rip=0, reload=0
14745 + .endm
14746 + .macro pax_force_fptr ptr
14747 + .endm
14748 + .macro pax_force_retaddr_bts rip=0
14749 + .endm
14750 + .macro pax_set_fptr_mask
14751 + .endm
14752 +#endif
14753 +
14754 .macro altinstruction_entry orig alt feature orig_len alt_len
14755 .long \orig - .
14756 .long \alt - .
14757 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14758 index 0a3f9c9..c9d081d 100644
14759 --- a/arch/x86/include/asm/alternative.h
14760 +++ b/arch/x86/include/asm/alternative.h
14761 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14762 ".pushsection .discard,\"aw\",@progbits\n" \
14763 DISCARD_ENTRY(1) \
14764 ".popsection\n" \
14765 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14766 + ".pushsection .altinstr_replacement, \"a\"\n" \
14767 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14768 ".popsection"
14769
14770 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14771 DISCARD_ENTRY(1) \
14772 DISCARD_ENTRY(2) \
14773 ".popsection\n" \
14774 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14775 + ".pushsection .altinstr_replacement, \"a\"\n" \
14776 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14777 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14778 ".popsection"
14779 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14780 index 1d2091a..f5074c1 100644
14781 --- a/arch/x86/include/asm/apic.h
14782 +++ b/arch/x86/include/asm/apic.h
14783 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14784
14785 #ifdef CONFIG_X86_LOCAL_APIC
14786
14787 -extern unsigned int apic_verbosity;
14788 +extern int apic_verbosity;
14789 extern int local_apic_timer_c2_ok;
14790
14791 extern int disable_apic;
14792 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14793 index 20370c6..a2eb9b0 100644
14794 --- a/arch/x86/include/asm/apm.h
14795 +++ b/arch/x86/include/asm/apm.h
14796 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14797 __asm__ __volatile__(APM_DO_ZERO_SEGS
14798 "pushl %%edi\n\t"
14799 "pushl %%ebp\n\t"
14800 - "lcall *%%cs:apm_bios_entry\n\t"
14801 + "lcall *%%ss:apm_bios_entry\n\t"
14802 "setc %%al\n\t"
14803 "popl %%ebp\n\t"
14804 "popl %%edi\n\t"
14805 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14806 __asm__ __volatile__(APM_DO_ZERO_SEGS
14807 "pushl %%edi\n\t"
14808 "pushl %%ebp\n\t"
14809 - "lcall *%%cs:apm_bios_entry\n\t"
14810 + "lcall *%%ss:apm_bios_entry\n\t"
14811 "setc %%bl\n\t"
14812 "popl %%ebp\n\t"
14813 "popl %%edi\n\t"
14814 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14815 index b17f4f4..9620151 100644
14816 --- a/arch/x86/include/asm/atomic.h
14817 +++ b/arch/x86/include/asm/atomic.h
14818 @@ -23,7 +23,18 @@
14819 */
14820 static inline int atomic_read(const atomic_t *v)
14821 {
14822 - return (*(volatile int *)&(v)->counter);
14823 + return (*(volatile const int *)&(v)->counter);
14824 +}
14825 +
14826 +/**
14827 + * atomic_read_unchecked - read atomic variable
14828 + * @v: pointer of type atomic_unchecked_t
14829 + *
14830 + * Atomically reads the value of @v.
14831 + */
14832 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14833 +{
14834 + return (*(volatile const int *)&(v)->counter);
14835 }
14836
14837 /**
14838 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14839 }
14840
14841 /**
14842 + * atomic_set_unchecked - set atomic variable
14843 + * @v: pointer of type atomic_unchecked_t
14844 + * @i: required value
14845 + *
14846 + * Atomically sets the value of @v to @i.
14847 + */
14848 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14849 +{
14850 + v->counter = i;
14851 +}
14852 +
14853 +/**
14854 * atomic_add - add integer to atomic variable
14855 * @i: integer value to add
14856 * @v: pointer of type atomic_t
14857 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14858 */
14859 static inline void atomic_add(int i, atomic_t *v)
14860 {
14861 - asm volatile(LOCK_PREFIX "addl %1,%0"
14862 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14863 +
14864 +#ifdef CONFIG_PAX_REFCOUNT
14865 + "jno 0f\n"
14866 + LOCK_PREFIX "subl %1,%0\n"
14867 + "int $4\n0:\n"
14868 + _ASM_EXTABLE(0b, 0b)
14869 +#endif
14870 +
14871 + : "+m" (v->counter)
14872 + : "ir" (i));
14873 +}
14874 +
14875 +/**
14876 + * atomic_add_unchecked - add integer to atomic variable
14877 + * @i: integer value to add
14878 + * @v: pointer of type atomic_unchecked_t
14879 + *
14880 + * Atomically adds @i to @v.
14881 + */
14882 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14883 +{
14884 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14885 : "+m" (v->counter)
14886 : "ir" (i));
14887 }
14888 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14889 */
14890 static inline void atomic_sub(int i, atomic_t *v)
14891 {
14892 - asm volatile(LOCK_PREFIX "subl %1,%0"
14893 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14894 +
14895 +#ifdef CONFIG_PAX_REFCOUNT
14896 + "jno 0f\n"
14897 + LOCK_PREFIX "addl %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_sub_unchecked - subtract integer from atomic variable
14908 + * @i: integer value to subtract
14909 + * @v: pointer of type atomic_unchecked_t
14910 + *
14911 + * Atomically subtracts @i from @v.
14912 + */
14913 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14914 +{
14915 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14916 : "+m" (v->counter)
14917 : "ir" (i));
14918 }
14919 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14920 */
14921 static inline int atomic_sub_and_test(int i, atomic_t *v)
14922 {
14923 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14924 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14925 }
14926
14927 /**
14928 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14929 */
14930 static inline void atomic_inc(atomic_t *v)
14931 {
14932 - asm volatile(LOCK_PREFIX "incl %0"
14933 + asm volatile(LOCK_PREFIX "incl %0\n"
14934 +
14935 +#ifdef CONFIG_PAX_REFCOUNT
14936 + "jno 0f\n"
14937 + LOCK_PREFIX "decl %0\n"
14938 + "int $4\n0:\n"
14939 + _ASM_EXTABLE(0b, 0b)
14940 +#endif
14941 +
14942 + : "+m" (v->counter));
14943 +}
14944 +
14945 +/**
14946 + * atomic_inc_unchecked - increment atomic variable
14947 + * @v: pointer of type atomic_unchecked_t
14948 + *
14949 + * Atomically increments @v by 1.
14950 + */
14951 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14952 +{
14953 + asm volatile(LOCK_PREFIX "incl %0\n"
14954 : "+m" (v->counter));
14955 }
14956
14957 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14958 */
14959 static inline void atomic_dec(atomic_t *v)
14960 {
14961 - asm volatile(LOCK_PREFIX "decl %0"
14962 + asm volatile(LOCK_PREFIX "decl %0\n"
14963 +
14964 +#ifdef CONFIG_PAX_REFCOUNT
14965 + "jno 0f\n"
14966 + LOCK_PREFIX "incl %0\n"
14967 + "int $4\n0:\n"
14968 + _ASM_EXTABLE(0b, 0b)
14969 +#endif
14970 +
14971 + : "+m" (v->counter));
14972 +}
14973 +
14974 +/**
14975 + * atomic_dec_unchecked - decrement atomic variable
14976 + * @v: pointer of type atomic_unchecked_t
14977 + *
14978 + * Atomically decrements @v by 1.
14979 + */
14980 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14981 +{
14982 + asm volatile(LOCK_PREFIX "decl %0\n"
14983 : "+m" (v->counter));
14984 }
14985
14986 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14987 */
14988 static inline int atomic_dec_and_test(atomic_t *v)
14989 {
14990 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14991 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14992 }
14993
14994 /**
14995 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14996 */
14997 static inline int atomic_inc_and_test(atomic_t *v)
14998 {
14999 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15000 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15001 +}
15002 +
15003 +/**
15004 + * atomic_inc_and_test_unchecked - increment and test
15005 + * @v: pointer of type atomic_unchecked_t
15006 + *
15007 + * Atomically increments @v by 1
15008 + * and returns true if the result is zero, or false for all
15009 + * other cases.
15010 + */
15011 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15012 +{
15013 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15014 }
15015
15016 /**
15017 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15018 */
15019 static inline int atomic_add_negative(int i, atomic_t *v)
15020 {
15021 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15022 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15023 }
15024
15025 /**
15026 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15027 */
15028 static inline int atomic_add_return(int i, atomic_t *v)
15029 {
15030 + return i + xadd_check_overflow(&v->counter, i);
15031 +}
15032 +
15033 +/**
15034 + * atomic_add_return_unchecked - add integer and return
15035 + * @i: integer value to add
15036 + * @v: pointer of type atomic_unchecked_t
15037 + *
15038 + * Atomically adds @i to @v and returns @i + @v
15039 + */
15040 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15041 +{
15042 return i + xadd(&v->counter, i);
15043 }
15044
15045 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15046 }
15047
15048 #define atomic_inc_return(v) (atomic_add_return(1, v))
15049 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15050 +{
15051 + return atomic_add_return_unchecked(1, v);
15052 +}
15053 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15054
15055 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15056 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15057 +{
15058 + return cmpxchg(&v->counter, old, new);
15059 +}
15060 +
15061 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15062 {
15063 return cmpxchg(&v->counter, old, new);
15064 }
15065 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15066 return xchg(&v->counter, new);
15067 }
15068
15069 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15070 +{
15071 + return xchg(&v->counter, new);
15072 +}
15073 +
15074 /**
15075 * __atomic_add_unless - add unless the number is already a given value
15076 * @v: pointer of type atomic_t
15077 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15078 * Atomically adds @a to @v, so long as @v was not already @u.
15079 * Returns the old value of @v.
15080 */
15081 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15082 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15083 {
15084 - int c, old;
15085 + int c, old, new;
15086 c = atomic_read(v);
15087 for (;;) {
15088 - if (unlikely(c == (u)))
15089 + if (unlikely(c == u))
15090 break;
15091 - old = atomic_cmpxchg((v), c, c + (a));
15092 +
15093 + asm volatile("addl %2,%0\n"
15094 +
15095 +#ifdef CONFIG_PAX_REFCOUNT
15096 + "jno 0f\n"
15097 + "subl %2,%0\n"
15098 + "int $4\n0:\n"
15099 + _ASM_EXTABLE(0b, 0b)
15100 +#endif
15101 +
15102 + : "=r" (new)
15103 + : "0" (c), "ir" (a));
15104 +
15105 + old = atomic_cmpxchg(v, c, new);
15106 if (likely(old == c))
15107 break;
15108 c = old;
15109 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15110 }
15111
15112 /**
15113 + * atomic_inc_not_zero_hint - increment if not null
15114 + * @v: pointer of type atomic_t
15115 + * @hint: probable value of the atomic before the increment
15116 + *
15117 + * This version of atomic_inc_not_zero() gives a hint of probable
15118 + * value of the atomic. This helps processor to not read the memory
15119 + * before doing the atomic read/modify/write cycle, lowering
15120 + * number of bus transactions on some arches.
15121 + *
15122 + * Returns: 0 if increment was not done, 1 otherwise.
15123 + */
15124 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15125 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15126 +{
15127 + int val, c = hint, new;
15128 +
15129 + /* sanity test, should be removed by compiler if hint is a constant */
15130 + if (!hint)
15131 + return __atomic_add_unless(v, 1, 0);
15132 +
15133 + do {
15134 + asm volatile("incl %0\n"
15135 +
15136 +#ifdef CONFIG_PAX_REFCOUNT
15137 + "jno 0f\n"
15138 + "decl %0\n"
15139 + "int $4\n0:\n"
15140 + _ASM_EXTABLE(0b, 0b)
15141 +#endif
15142 +
15143 + : "=r" (new)
15144 + : "0" (c));
15145 +
15146 + val = atomic_cmpxchg(v, c, new);
15147 + if (val == c)
15148 + return 1;
15149 + c = val;
15150 + } while (c);
15151 +
15152 + return 0;
15153 +}
15154 +
15155 +/**
15156 * atomic_inc_short - increment of a short integer
15157 * @v: pointer to type int
15158 *
15159 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15160 #endif
15161
15162 /* These are x86-specific, used by some header files */
15163 -#define atomic_clear_mask(mask, addr) \
15164 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15165 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15166 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15167 +{
15168 + asm volatile(LOCK_PREFIX "andl %1,%0"
15169 + : "+m" (v->counter)
15170 + : "r" (~(mask))
15171 + : "memory");
15172 +}
15173
15174 -#define atomic_set_mask(mask, addr) \
15175 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15176 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15177 - : "memory")
15178 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15179 +{
15180 + asm volatile(LOCK_PREFIX "andl %1,%0"
15181 + : "+m" (v->counter)
15182 + : "r" (~(mask))
15183 + : "memory");
15184 +}
15185 +
15186 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15187 +{
15188 + asm volatile(LOCK_PREFIX "orl %1,%0"
15189 + : "+m" (v->counter)
15190 + : "r" (mask)
15191 + : "memory");
15192 +}
15193 +
15194 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15195 +{
15196 + asm volatile(LOCK_PREFIX "orl %1,%0"
15197 + : "+m" (v->counter)
15198 + : "r" (mask)
15199 + : "memory");
15200 +}
15201
15202 /* Atomic operations are already serializing on x86 */
15203 #define smp_mb__before_atomic_dec() barrier()
15204 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15205 index b154de7..bf18a5a 100644
15206 --- a/arch/x86/include/asm/atomic64_32.h
15207 +++ b/arch/x86/include/asm/atomic64_32.h
15208 @@ -12,6 +12,14 @@ typedef struct {
15209 u64 __aligned(8) counter;
15210 } atomic64_t;
15211
15212 +#ifdef CONFIG_PAX_REFCOUNT
15213 +typedef struct {
15214 + u64 __aligned(8) counter;
15215 +} atomic64_unchecked_t;
15216 +#else
15217 +typedef atomic64_t atomic64_unchecked_t;
15218 +#endif
15219 +
15220 #define ATOMIC64_INIT(val) { (val) }
15221
15222 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15223 @@ -37,21 +45,31 @@ typedef struct {
15224 ATOMIC64_DECL_ONE(sym##_386)
15225
15226 ATOMIC64_DECL_ONE(add_386);
15227 +ATOMIC64_DECL_ONE(add_unchecked_386);
15228 ATOMIC64_DECL_ONE(sub_386);
15229 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15230 ATOMIC64_DECL_ONE(inc_386);
15231 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15232 ATOMIC64_DECL_ONE(dec_386);
15233 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15234 #endif
15235
15236 #define alternative_atomic64(f, out, in...) \
15237 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15238
15239 ATOMIC64_DECL(read);
15240 +ATOMIC64_DECL(read_unchecked);
15241 ATOMIC64_DECL(set);
15242 +ATOMIC64_DECL(set_unchecked);
15243 ATOMIC64_DECL(xchg);
15244 ATOMIC64_DECL(add_return);
15245 +ATOMIC64_DECL(add_return_unchecked);
15246 ATOMIC64_DECL(sub_return);
15247 +ATOMIC64_DECL(sub_return_unchecked);
15248 ATOMIC64_DECL(inc_return);
15249 +ATOMIC64_DECL(inc_return_unchecked);
15250 ATOMIC64_DECL(dec_return);
15251 +ATOMIC64_DECL(dec_return_unchecked);
15252 ATOMIC64_DECL(dec_if_positive);
15253 ATOMIC64_DECL(inc_not_zero);
15254 ATOMIC64_DECL(add_unless);
15255 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15256 }
15257
15258 /**
15259 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15260 + * @p: pointer to type atomic64_unchecked_t
15261 + * @o: expected value
15262 + * @n: new value
15263 + *
15264 + * Atomically sets @v to @n if it was equal to @o and returns
15265 + * the old value.
15266 + */
15267 +
15268 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15269 +{
15270 + return cmpxchg64(&v->counter, o, n);
15271 +}
15272 +
15273 +/**
15274 * atomic64_xchg - xchg atomic64 variable
15275 * @v: pointer to type atomic64_t
15276 * @n: value to assign
15277 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15278 }
15279
15280 /**
15281 + * atomic64_set_unchecked - set atomic64 variable
15282 + * @v: pointer to type atomic64_unchecked_t
15283 + * @n: value to assign
15284 + *
15285 + * Atomically sets the value of @v to @n.
15286 + */
15287 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15288 +{
15289 + unsigned high = (unsigned)(i >> 32);
15290 + unsigned low = (unsigned)i;
15291 + alternative_atomic64(set, /* no output */,
15292 + "S" (v), "b" (low), "c" (high)
15293 + : "eax", "edx", "memory");
15294 +}
15295 +
15296 +/**
15297 * atomic64_read - read atomic64 variable
15298 * @v: pointer to type atomic64_t
15299 *
15300 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15301 }
15302
15303 /**
15304 + * atomic64_read_unchecked - read atomic64 variable
15305 + * @v: pointer to type atomic64_unchecked_t
15306 + *
15307 + * Atomically reads the value of @v and returns it.
15308 + */
15309 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15310 +{
15311 + long long r;
15312 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15313 + return r;
15314 + }
15315 +
15316 +/**
15317 * atomic64_add_return - add and return
15318 * @i: integer value to add
15319 * @v: pointer to type atomic64_t
15320 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15321 return i;
15322 }
15323
15324 +/**
15325 + * atomic64_add_return_unchecked - add and return
15326 + * @i: integer value to add
15327 + * @v: pointer to type atomic64_unchecked_t
15328 + *
15329 + * Atomically adds @i to @v and returns @i + *@v
15330 + */
15331 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15332 +{
15333 + alternative_atomic64(add_return_unchecked,
15334 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15335 + ASM_NO_INPUT_CLOBBER("memory"));
15336 + return i;
15337 +}
15338 +
15339 /*
15340 * Other variants with different arithmetic operators:
15341 */
15342 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15343 return a;
15344 }
15345
15346 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15347 +{
15348 + long long a;
15349 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15350 + "S" (v) : "memory", "ecx");
15351 + return a;
15352 +}
15353 +
15354 static inline long long atomic64_dec_return(atomic64_t *v)
15355 {
15356 long long a;
15357 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15358 }
15359
15360 /**
15361 + * atomic64_add_unchecked - add integer to atomic64 variable
15362 + * @i: integer value to add
15363 + * @v: pointer to type atomic64_unchecked_t
15364 + *
15365 + * Atomically adds @i to @v.
15366 + */
15367 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15368 +{
15369 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15370 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15371 + ASM_NO_INPUT_CLOBBER("memory"));
15372 + return i;
15373 +}
15374 +
15375 +/**
15376 * atomic64_sub - subtract the atomic64 variable
15377 * @i: integer value to subtract
15378 * @v: pointer to type atomic64_t
15379 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15380 index 46e9052..ae45136 100644
15381 --- a/arch/x86/include/asm/atomic64_64.h
15382 +++ b/arch/x86/include/asm/atomic64_64.h
15383 @@ -18,7 +18,19 @@
15384 */
15385 static inline long atomic64_read(const atomic64_t *v)
15386 {
15387 - return (*(volatile long *)&(v)->counter);
15388 + return (*(volatile const long *)&(v)->counter);
15389 +}
15390 +
15391 +/**
15392 + * atomic64_read_unchecked - read atomic64 variable
15393 + * @v: pointer of type atomic64_unchecked_t
15394 + *
15395 + * Atomically reads the value of @v.
15396 + * Doesn't imply a read memory barrier.
15397 + */
15398 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15399 +{
15400 + return (*(volatile const long *)&(v)->counter);
15401 }
15402
15403 /**
15404 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15405 }
15406
15407 /**
15408 + * atomic64_set_unchecked - set atomic64 variable
15409 + * @v: pointer to type atomic64_unchecked_t
15410 + * @i: required value
15411 + *
15412 + * Atomically sets the value of @v to @i.
15413 + */
15414 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15415 +{
15416 + v->counter = i;
15417 +}
15418 +
15419 +/**
15420 * atomic64_add - add integer to atomic64 variable
15421 * @i: integer value to add
15422 * @v: pointer to type atomic64_t
15423 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15424 */
15425 static inline void atomic64_add(long i, atomic64_t *v)
15426 {
15427 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15428 +
15429 +#ifdef CONFIG_PAX_REFCOUNT
15430 + "jno 0f\n"
15431 + LOCK_PREFIX "subq %1,%0\n"
15432 + "int $4\n0:\n"
15433 + _ASM_EXTABLE(0b, 0b)
15434 +#endif
15435 +
15436 + : "=m" (v->counter)
15437 + : "er" (i), "m" (v->counter));
15438 +}
15439 +
15440 +/**
15441 + * atomic64_add_unchecked - add integer to atomic64 variable
15442 + * @i: integer value to add
15443 + * @v: pointer to type atomic64_unchecked_t
15444 + *
15445 + * Atomically adds @i to @v.
15446 + */
15447 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15448 +{
15449 asm volatile(LOCK_PREFIX "addq %1,%0"
15450 : "=m" (v->counter)
15451 : "er" (i), "m" (v->counter));
15452 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15453 */
15454 static inline void atomic64_sub(long i, atomic64_t *v)
15455 {
15456 - asm volatile(LOCK_PREFIX "subq %1,%0"
15457 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15458 +
15459 +#ifdef CONFIG_PAX_REFCOUNT
15460 + "jno 0f\n"
15461 + LOCK_PREFIX "addq %1,%0\n"
15462 + "int $4\n0:\n"
15463 + _ASM_EXTABLE(0b, 0b)
15464 +#endif
15465 +
15466 + : "=m" (v->counter)
15467 + : "er" (i), "m" (v->counter));
15468 +}
15469 +
15470 +/**
15471 + * atomic64_sub_unchecked - subtract the atomic64 variable
15472 + * @i: integer value to subtract
15473 + * @v: pointer to type atomic64_unchecked_t
15474 + *
15475 + * Atomically subtracts @i from @v.
15476 + */
15477 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15478 +{
15479 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15480 : "=m" (v->counter)
15481 : "er" (i), "m" (v->counter));
15482 }
15483 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15484 */
15485 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15486 {
15487 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15488 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15489 }
15490
15491 /**
15492 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15493 */
15494 static inline void atomic64_inc(atomic64_t *v)
15495 {
15496 + asm volatile(LOCK_PREFIX "incq %0\n"
15497 +
15498 +#ifdef CONFIG_PAX_REFCOUNT
15499 + "jno 0f\n"
15500 + LOCK_PREFIX "decq %0\n"
15501 + "int $4\n0:\n"
15502 + _ASM_EXTABLE(0b, 0b)
15503 +#endif
15504 +
15505 + : "=m" (v->counter)
15506 + : "m" (v->counter));
15507 +}
15508 +
15509 +/**
15510 + * atomic64_inc_unchecked - increment atomic64 variable
15511 + * @v: pointer to type atomic64_unchecked_t
15512 + *
15513 + * Atomically increments @v by 1.
15514 + */
15515 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15516 +{
15517 asm volatile(LOCK_PREFIX "incq %0"
15518 : "=m" (v->counter)
15519 : "m" (v->counter));
15520 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15521 */
15522 static inline void atomic64_dec(atomic64_t *v)
15523 {
15524 - asm volatile(LOCK_PREFIX "decq %0"
15525 + asm volatile(LOCK_PREFIX "decq %0\n"
15526 +
15527 +#ifdef CONFIG_PAX_REFCOUNT
15528 + "jno 0f\n"
15529 + LOCK_PREFIX "incq %0\n"
15530 + "int $4\n0:\n"
15531 + _ASM_EXTABLE(0b, 0b)
15532 +#endif
15533 +
15534 + : "=m" (v->counter)
15535 + : "m" (v->counter));
15536 +}
15537 +
15538 +/**
15539 + * atomic64_dec_unchecked - decrement atomic64 variable
15540 + * @v: pointer to type atomic64_t
15541 + *
15542 + * Atomically decrements @v by 1.
15543 + */
15544 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15545 +{
15546 + asm volatile(LOCK_PREFIX "decq %0\n"
15547 : "=m" (v->counter)
15548 : "m" (v->counter));
15549 }
15550 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15551 */
15552 static inline int atomic64_dec_and_test(atomic64_t *v)
15553 {
15554 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15555 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15556 }
15557
15558 /**
15559 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15560 */
15561 static inline int atomic64_inc_and_test(atomic64_t *v)
15562 {
15563 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15564 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15565 }
15566
15567 /**
15568 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15569 */
15570 static inline int atomic64_add_negative(long i, atomic64_t *v)
15571 {
15572 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15573 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15574 }
15575
15576 /**
15577 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15578 */
15579 static inline long atomic64_add_return(long i, atomic64_t *v)
15580 {
15581 + return i + xadd_check_overflow(&v->counter, i);
15582 +}
15583 +
15584 +/**
15585 + * atomic64_add_return_unchecked - add and return
15586 + * @i: integer value to add
15587 + * @v: pointer to type atomic64_unchecked_t
15588 + *
15589 + * Atomically adds @i to @v and returns @i + @v
15590 + */
15591 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15592 +{
15593 return i + xadd(&v->counter, i);
15594 }
15595
15596 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15597 }
15598
15599 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15600 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15601 +{
15602 + return atomic64_add_return_unchecked(1, v);
15603 +}
15604 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15605
15606 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15607 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15608 return cmpxchg(&v->counter, old, new);
15609 }
15610
15611 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15612 +{
15613 + return cmpxchg(&v->counter, old, new);
15614 +}
15615 +
15616 static inline long atomic64_xchg(atomic64_t *v, long new)
15617 {
15618 return xchg(&v->counter, new);
15619 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15620 */
15621 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15622 {
15623 - long c, old;
15624 + long c, old, new;
15625 c = atomic64_read(v);
15626 for (;;) {
15627 - if (unlikely(c == (u)))
15628 + if (unlikely(c == u))
15629 break;
15630 - old = atomic64_cmpxchg((v), c, c + (a));
15631 +
15632 + asm volatile("add %2,%0\n"
15633 +
15634 +#ifdef CONFIG_PAX_REFCOUNT
15635 + "jno 0f\n"
15636 + "sub %2,%0\n"
15637 + "int $4\n0:\n"
15638 + _ASM_EXTABLE(0b, 0b)
15639 +#endif
15640 +
15641 + : "=r" (new)
15642 + : "0" (c), "ir" (a));
15643 +
15644 + old = atomic64_cmpxchg(v, c, new);
15645 if (likely(old == c))
15646 break;
15647 c = old;
15648 }
15649 - return c != (u);
15650 + return c != u;
15651 }
15652
15653 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15654 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15655 index 9fc1af7..fc71228 100644
15656 --- a/arch/x86/include/asm/bitops.h
15657 +++ b/arch/x86/include/asm/bitops.h
15658 @@ -49,7 +49,7 @@
15659 * a mask operation on a byte.
15660 */
15661 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15662 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15663 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15664 #define CONST_MASK(nr) (1 << ((nr) & 7))
15665
15666 /**
15667 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15668 */
15669 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15670 {
15671 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15672 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15673 }
15674
15675 /**
15676 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15677 */
15678 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15679 {
15680 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15681 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15682 }
15683
15684 /**
15685 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15686 */
15687 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15688 {
15689 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15690 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15691 }
15692
15693 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15694 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15695 *
15696 * Undefined if no bit exists, so code should check against 0 first.
15697 */
15698 -static inline unsigned long __ffs(unsigned long word)
15699 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15700 {
15701 asm("rep; bsf %1,%0"
15702 : "=r" (word)
15703 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15704 *
15705 * Undefined if no zero exists, so code should check against ~0UL first.
15706 */
15707 -static inline unsigned long ffz(unsigned long word)
15708 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15709 {
15710 asm("rep; bsf %1,%0"
15711 : "=r" (word)
15712 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15713 *
15714 * Undefined if no set bit exists, so code should check against 0 first.
15715 */
15716 -static inline unsigned long __fls(unsigned long word)
15717 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15718 {
15719 asm("bsr %1,%0"
15720 : "=r" (word)
15721 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15722 * set bit if value is nonzero. The last (most significant) bit is
15723 * at position 32.
15724 */
15725 -static inline int fls(int x)
15726 +static inline int __intentional_overflow(-1) fls(int x)
15727 {
15728 int r;
15729
15730 @@ -478,7 +478,7 @@ static inline int fls(int x)
15731 * at position 64.
15732 */
15733 #ifdef CONFIG_X86_64
15734 -static __always_inline int fls64(__u64 x)
15735 +static __always_inline long fls64(__u64 x)
15736 {
15737 int bitpos = -1;
15738 /*
15739 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15740 index 4fa687a..60f2d39 100644
15741 --- a/arch/x86/include/asm/boot.h
15742 +++ b/arch/x86/include/asm/boot.h
15743 @@ -6,10 +6,15 @@
15744 #include <uapi/asm/boot.h>
15745
15746 /* Physical address where kernel should be loaded. */
15747 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15748 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15749 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15750 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15751
15752 +#ifndef __ASSEMBLY__
15753 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15754 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15755 +#endif
15756 +
15757 /* Minimum kernel alignment, as a power of two */
15758 #ifdef CONFIG_X86_64
15759 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15760 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15761 index 48f99f1..d78ebf9 100644
15762 --- a/arch/x86/include/asm/cache.h
15763 +++ b/arch/x86/include/asm/cache.h
15764 @@ -5,12 +5,13 @@
15765
15766 /* L1 cache line size */
15767 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15768 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15769 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15770
15771 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15772 +#define __read_only __attribute__((__section__(".data..read_only")))
15773
15774 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15775 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15776 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15777
15778 #ifdef CONFIG_X86_VSMP
15779 #ifdef CONFIG_SMP
15780 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15781 index 9863ee3..4a1f8e1 100644
15782 --- a/arch/x86/include/asm/cacheflush.h
15783 +++ b/arch/x86/include/asm/cacheflush.h
15784 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15785 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15786
15787 if (pg_flags == _PGMT_DEFAULT)
15788 - return -1;
15789 + return ~0UL;
15790 else if (pg_flags == _PGMT_WC)
15791 return _PAGE_CACHE_WC;
15792 else if (pg_flags == _PGMT_UC_MINUS)
15793 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15794 index cb4c73b..c473c29 100644
15795 --- a/arch/x86/include/asm/calling.h
15796 +++ b/arch/x86/include/asm/calling.h
15797 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15798 #define RSP 152
15799 #define SS 160
15800
15801 -#define ARGOFFSET R11
15802 -#define SWFRAME ORIG_RAX
15803 +#define ARGOFFSET R15
15804
15805 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15806 - subq $9*8+\addskip, %rsp
15807 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15808 - movq_cfi rdi, 8*8
15809 - movq_cfi rsi, 7*8
15810 - movq_cfi rdx, 6*8
15811 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15812 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15813 + movq_cfi rdi, RDI
15814 + movq_cfi rsi, RSI
15815 + movq_cfi rdx, RDX
15816
15817 .if \save_rcx
15818 - movq_cfi rcx, 5*8
15819 + movq_cfi rcx, RCX
15820 .endif
15821
15822 - movq_cfi rax, 4*8
15823 + movq_cfi rax, RAX
15824
15825 .if \save_r891011
15826 - movq_cfi r8, 3*8
15827 - movq_cfi r9, 2*8
15828 - movq_cfi r10, 1*8
15829 - movq_cfi r11, 0*8
15830 + movq_cfi r8, R8
15831 + movq_cfi r9, R9
15832 + movq_cfi r10, R10
15833 + movq_cfi r11, R11
15834 .endif
15835
15836 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15837 + movq_cfi r12, R12
15838 +#endif
15839 +
15840 .endm
15841
15842 -#define ARG_SKIP (9*8)
15843 +#define ARG_SKIP ORIG_RAX
15844
15845 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15846 rstor_r8910=1, rstor_rdx=1
15847 +
15848 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15849 + movq_cfi_restore R12, r12
15850 +#endif
15851 +
15852 .if \rstor_r11
15853 - movq_cfi_restore 0*8, r11
15854 + movq_cfi_restore R11, r11
15855 .endif
15856
15857 .if \rstor_r8910
15858 - movq_cfi_restore 1*8, r10
15859 - movq_cfi_restore 2*8, r9
15860 - movq_cfi_restore 3*8, r8
15861 + movq_cfi_restore R10, r10
15862 + movq_cfi_restore R9, r9
15863 + movq_cfi_restore R8, r8
15864 .endif
15865
15866 .if \rstor_rax
15867 - movq_cfi_restore 4*8, rax
15868 + movq_cfi_restore RAX, rax
15869 .endif
15870
15871 .if \rstor_rcx
15872 - movq_cfi_restore 5*8, rcx
15873 + movq_cfi_restore RCX, rcx
15874 .endif
15875
15876 .if \rstor_rdx
15877 - movq_cfi_restore 6*8, rdx
15878 + movq_cfi_restore RDX, rdx
15879 .endif
15880
15881 - movq_cfi_restore 7*8, rsi
15882 - movq_cfi_restore 8*8, rdi
15883 + movq_cfi_restore RSI, rsi
15884 + movq_cfi_restore RDI, rdi
15885
15886 - .if ARG_SKIP+\addskip > 0
15887 - addq $ARG_SKIP+\addskip, %rsp
15888 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15889 + .if ORIG_RAX+\addskip > 0
15890 + addq $ORIG_RAX+\addskip, %rsp
15891 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15892 .endif
15893 .endm
15894
15895 - .macro LOAD_ARGS offset, skiprax=0
15896 - movq \offset(%rsp), %r11
15897 - movq \offset+8(%rsp), %r10
15898 - movq \offset+16(%rsp), %r9
15899 - movq \offset+24(%rsp), %r8
15900 - movq \offset+40(%rsp), %rcx
15901 - movq \offset+48(%rsp), %rdx
15902 - movq \offset+56(%rsp), %rsi
15903 - movq \offset+64(%rsp), %rdi
15904 + .macro LOAD_ARGS skiprax=0
15905 + movq R11(%rsp), %r11
15906 + movq R10(%rsp), %r10
15907 + movq R9(%rsp), %r9
15908 + movq R8(%rsp), %r8
15909 + movq RCX(%rsp), %rcx
15910 + movq RDX(%rsp), %rdx
15911 + movq RSI(%rsp), %rsi
15912 + movq RDI(%rsp), %rdi
15913 .if \skiprax
15914 .else
15915 - movq \offset+72(%rsp), %rax
15916 + movq RAX(%rsp), %rax
15917 .endif
15918 .endm
15919
15920 -#define REST_SKIP (6*8)
15921 -
15922 .macro SAVE_REST
15923 - subq $REST_SKIP, %rsp
15924 - CFI_ADJUST_CFA_OFFSET REST_SKIP
15925 - movq_cfi rbx, 5*8
15926 - movq_cfi rbp, 4*8
15927 - movq_cfi r12, 3*8
15928 - movq_cfi r13, 2*8
15929 - movq_cfi r14, 1*8
15930 - movq_cfi r15, 0*8
15931 + movq_cfi rbx, RBX
15932 + movq_cfi rbp, RBP
15933 +
15934 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15935 + movq_cfi r12, R12
15936 +#endif
15937 +
15938 + movq_cfi r13, R13
15939 + movq_cfi r14, R14
15940 + movq_cfi r15, R15
15941 .endm
15942
15943 .macro RESTORE_REST
15944 - movq_cfi_restore 0*8, r15
15945 - movq_cfi_restore 1*8, r14
15946 - movq_cfi_restore 2*8, r13
15947 - movq_cfi_restore 3*8, r12
15948 - movq_cfi_restore 4*8, rbp
15949 - movq_cfi_restore 5*8, rbx
15950 - addq $REST_SKIP, %rsp
15951 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15952 + movq_cfi_restore R15, r15
15953 + movq_cfi_restore R14, r14
15954 + movq_cfi_restore R13, r13
15955 +
15956 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15957 + movq_cfi_restore R12, r12
15958 +#endif
15959 +
15960 + movq_cfi_restore RBP, rbp
15961 + movq_cfi_restore RBX, rbx
15962 .endm
15963
15964 .macro SAVE_ALL
15965 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15966 index f50de69..2b0a458 100644
15967 --- a/arch/x86/include/asm/checksum_32.h
15968 +++ b/arch/x86/include/asm/checksum_32.h
15969 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15970 int len, __wsum sum,
15971 int *src_err_ptr, int *dst_err_ptr);
15972
15973 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15974 + int len, __wsum sum,
15975 + int *src_err_ptr, int *dst_err_ptr);
15976 +
15977 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15978 + int len, __wsum sum,
15979 + int *src_err_ptr, int *dst_err_ptr);
15980 +
15981 /*
15982 * Note: when you get a NULL pointer exception here this means someone
15983 * passed in an incorrect kernel address to one of these functions.
15984 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15985
15986 might_sleep();
15987 stac();
15988 - ret = csum_partial_copy_generic((__force void *)src, dst,
15989 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15990 len, sum, err_ptr, NULL);
15991 clac();
15992
15993 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15994 might_sleep();
15995 if (access_ok(VERIFY_WRITE, dst, len)) {
15996 stac();
15997 - ret = csum_partial_copy_generic(src, (__force void *)dst,
15998 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15999 len, sum, NULL, err_ptr);
16000 clac();
16001 return ret;
16002 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16003 index d47786a..ce1b05d 100644
16004 --- a/arch/x86/include/asm/cmpxchg.h
16005 +++ b/arch/x86/include/asm/cmpxchg.h
16006 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16007 __compiletime_error("Bad argument size for cmpxchg");
16008 extern void __xadd_wrong_size(void)
16009 __compiletime_error("Bad argument size for xadd");
16010 +extern void __xadd_check_overflow_wrong_size(void)
16011 + __compiletime_error("Bad argument size for xadd_check_overflow");
16012 extern void __add_wrong_size(void)
16013 __compiletime_error("Bad argument size for add");
16014 +extern void __add_check_overflow_wrong_size(void)
16015 + __compiletime_error("Bad argument size for add_check_overflow");
16016
16017 /*
16018 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16019 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
16020 __ret; \
16021 })
16022
16023 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16024 + ({ \
16025 + __typeof__ (*(ptr)) __ret = (arg); \
16026 + switch (sizeof(*(ptr))) { \
16027 + case __X86_CASE_L: \
16028 + asm volatile (lock #op "l %0, %1\n" \
16029 + "jno 0f\n" \
16030 + "mov %0,%1\n" \
16031 + "int $4\n0:\n" \
16032 + _ASM_EXTABLE(0b, 0b) \
16033 + : "+r" (__ret), "+m" (*(ptr)) \
16034 + : : "memory", "cc"); \
16035 + break; \
16036 + case __X86_CASE_Q: \
16037 + asm volatile (lock #op "q %q0, %1\n" \
16038 + "jno 0f\n" \
16039 + "mov %0,%1\n" \
16040 + "int $4\n0:\n" \
16041 + _ASM_EXTABLE(0b, 0b) \
16042 + : "+r" (__ret), "+m" (*(ptr)) \
16043 + : : "memory", "cc"); \
16044 + break; \
16045 + default: \
16046 + __ ## op ## _check_overflow_wrong_size(); \
16047 + } \
16048 + __ret; \
16049 + })
16050 +
16051 /*
16052 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16053 * Since this is generally used to protect other memory information, we
16054 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
16055 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16056 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16057
16058 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16059 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16060 +
16061 #define __add(ptr, inc, lock) \
16062 ({ \
16063 __typeof__ (*(ptr)) __ret = (inc); \
16064 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16065 index 59c6c40..5e0b22c 100644
16066 --- a/arch/x86/include/asm/compat.h
16067 +++ b/arch/x86/include/asm/compat.h
16068 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16069 typedef u32 compat_uint_t;
16070 typedef u32 compat_ulong_t;
16071 typedef u64 __attribute__((aligned(4))) compat_u64;
16072 -typedef u32 compat_uptr_t;
16073 +typedef u32 __user compat_uptr_t;
16074
16075 struct compat_timespec {
16076 compat_time_t tv_sec;
16077 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16078 index 89270b4..f0abf8e 100644
16079 --- a/arch/x86/include/asm/cpufeature.h
16080 +++ b/arch/x86/include/asm/cpufeature.h
16081 @@ -203,7 +203,7 @@
16082 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16083 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16084 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16085 -
16086 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16087
16088 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16089 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16090 @@ -211,7 +211,7 @@
16091 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16092 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16093 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16094 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16095 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16096 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16097 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16098 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16099 @@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
16100 #undef cpu_has_centaur_mcr
16101 #define cpu_has_centaur_mcr 0
16102
16103 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16104 #endif /* CONFIG_X86_64 */
16105
16106 #if __GNUC__ >= 4
16107 @@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16108
16109 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16110 t_warn:
16111 - warn_pre_alternatives();
16112 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16113 + warn_pre_alternatives();
16114 return false;
16115 #endif
16116
16117 @@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16118 ".section .discard,\"aw\",@progbits\n"
16119 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16120 ".previous\n"
16121 - ".section .altinstr_replacement,\"ax\"\n"
16122 + ".section .altinstr_replacement,\"a\"\n"
16123 "3: movb $1,%0\n"
16124 "4:\n"
16125 ".previous\n"
16126 @@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16127 " .byte 2b - 1b\n" /* src len */
16128 " .byte 4f - 3f\n" /* repl len */
16129 ".previous\n"
16130 - ".section .altinstr_replacement,\"ax\"\n"
16131 + ".section .altinstr_replacement,\"a\"\n"
16132 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16133 "4:\n"
16134 ".previous\n"
16135 @@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16136 ".section .discard,\"aw\",@progbits\n"
16137 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16138 ".previous\n"
16139 - ".section .altinstr_replacement,\"ax\"\n"
16140 + ".section .altinstr_replacement,\"a\"\n"
16141 "3: movb $0,%0\n"
16142 "4:\n"
16143 ".previous\n"
16144 @@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16145 ".section .discard,\"aw\",@progbits\n"
16146 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16147 ".previous\n"
16148 - ".section .altinstr_replacement,\"ax\"\n"
16149 + ".section .altinstr_replacement,\"a\"\n"
16150 "5: movb $1,%0\n"
16151 "6:\n"
16152 ".previous\n"
16153 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16154 index 50d033a..37deb26 100644
16155 --- a/arch/x86/include/asm/desc.h
16156 +++ b/arch/x86/include/asm/desc.h
16157 @@ -4,6 +4,7 @@
16158 #include <asm/desc_defs.h>
16159 #include <asm/ldt.h>
16160 #include <asm/mmu.h>
16161 +#include <asm/pgtable.h>
16162
16163 #include <linux/smp.h>
16164 #include <linux/percpu.h>
16165 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16166
16167 desc->type = (info->read_exec_only ^ 1) << 1;
16168 desc->type |= info->contents << 2;
16169 + desc->type |= info->seg_not_present ^ 1;
16170
16171 desc->s = 1;
16172 desc->dpl = 0x3;
16173 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16174 }
16175
16176 extern struct desc_ptr idt_descr;
16177 -extern gate_desc idt_table[];
16178 -extern struct desc_ptr debug_idt_descr;
16179 -extern gate_desc debug_idt_table[];
16180 -
16181 -struct gdt_page {
16182 - struct desc_struct gdt[GDT_ENTRIES];
16183 -} __attribute__((aligned(PAGE_SIZE)));
16184 -
16185 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16186 +extern gate_desc idt_table[IDT_ENTRIES];
16187 +extern const struct desc_ptr debug_idt_descr;
16188 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16189
16190 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16191 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16192 {
16193 - return per_cpu(gdt_page, cpu).gdt;
16194 + return cpu_gdt_table[cpu];
16195 }
16196
16197 #ifdef CONFIG_X86_64
16198 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16199 unsigned long base, unsigned dpl, unsigned flags,
16200 unsigned short seg)
16201 {
16202 - gate->a = (seg << 16) | (base & 0xffff);
16203 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16204 + gate->gate.offset_low = base;
16205 + gate->gate.seg = seg;
16206 + gate->gate.reserved = 0;
16207 + gate->gate.type = type;
16208 + gate->gate.s = 0;
16209 + gate->gate.dpl = dpl;
16210 + gate->gate.p = 1;
16211 + gate->gate.offset_high = base >> 16;
16212 }
16213
16214 #endif
16215 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16216
16217 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16218 {
16219 + pax_open_kernel();
16220 memcpy(&idt[entry], gate, sizeof(*gate));
16221 + pax_close_kernel();
16222 }
16223
16224 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16225 {
16226 + pax_open_kernel();
16227 memcpy(&ldt[entry], desc, 8);
16228 + pax_close_kernel();
16229 }
16230
16231 static inline void
16232 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16233 default: size = sizeof(*gdt); break;
16234 }
16235
16236 + pax_open_kernel();
16237 memcpy(&gdt[entry], desc, size);
16238 + pax_close_kernel();
16239 }
16240
16241 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16242 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16243
16244 static inline void native_load_tr_desc(void)
16245 {
16246 + pax_open_kernel();
16247 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16248 + pax_close_kernel();
16249 }
16250
16251 static inline void native_load_gdt(const struct desc_ptr *dtr)
16252 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16253 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16254 unsigned int i;
16255
16256 + pax_open_kernel();
16257 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16258 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16259 + pax_close_kernel();
16260 }
16261
16262 #define _LDT_empty(info) \
16263 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16264 preempt_enable();
16265 }
16266
16267 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16268 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16269 {
16270 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16271 }
16272 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16273 }
16274
16275 #ifdef CONFIG_X86_64
16276 -static inline void set_nmi_gate(int gate, void *addr)
16277 +static inline void set_nmi_gate(int gate, const void *addr)
16278 {
16279 gate_desc s;
16280
16281 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16282 #endif
16283
16284 #ifdef CONFIG_TRACING
16285 -extern struct desc_ptr trace_idt_descr;
16286 -extern gate_desc trace_idt_table[];
16287 +extern const struct desc_ptr trace_idt_descr;
16288 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16289 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16290 {
16291 write_idt_entry(trace_idt_table, entry, gate);
16292 }
16293
16294 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16295 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16296 unsigned dpl, unsigned ist, unsigned seg)
16297 {
16298 gate_desc s;
16299 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16300 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16301 #endif
16302
16303 -static inline void _set_gate(int gate, unsigned type, void *addr,
16304 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16305 unsigned dpl, unsigned ist, unsigned seg)
16306 {
16307 gate_desc s;
16308 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16309 #define set_intr_gate(n, addr) \
16310 do { \
16311 BUG_ON((unsigned)n > 0xFF); \
16312 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16313 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16314 __KERNEL_CS); \
16315 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16316 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16317 0, 0, __KERNEL_CS); \
16318 } while (0)
16319
16320 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16321 /*
16322 * This routine sets up an interrupt gate at directory privilege level 3.
16323 */
16324 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16325 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16326 {
16327 BUG_ON((unsigned)n > 0xFF);
16328 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16329 }
16330
16331 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16332 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16333 {
16334 BUG_ON((unsigned)n > 0xFF);
16335 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16336 }
16337
16338 -static inline void set_trap_gate(unsigned int n, void *addr)
16339 +static inline void set_trap_gate(unsigned int n, const void *addr)
16340 {
16341 BUG_ON((unsigned)n > 0xFF);
16342 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16343 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16344 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16345 {
16346 BUG_ON((unsigned)n > 0xFF);
16347 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16348 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16349 }
16350
16351 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16352 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16353 {
16354 BUG_ON((unsigned)n > 0xFF);
16355 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16356 }
16357
16358 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16359 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16360 {
16361 BUG_ON((unsigned)n > 0xFF);
16362 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16363 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16364 else
16365 load_idt((const struct desc_ptr *)&idt_descr);
16366 }
16367 +
16368 +#ifdef CONFIG_X86_32
16369 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16370 +{
16371 + struct desc_struct d;
16372 +
16373 + if (likely(limit))
16374 + limit = (limit - 1UL) >> PAGE_SHIFT;
16375 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16376 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16377 +}
16378 +#endif
16379 +
16380 #endif /* _ASM_X86_DESC_H */
16381 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16382 index 278441f..b95a174 100644
16383 --- a/arch/x86/include/asm/desc_defs.h
16384 +++ b/arch/x86/include/asm/desc_defs.h
16385 @@ -31,6 +31,12 @@ struct desc_struct {
16386 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16387 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16388 };
16389 + struct {
16390 + u16 offset_low;
16391 + u16 seg;
16392 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16393 + unsigned offset_high: 16;
16394 + } gate;
16395 };
16396 } __attribute__((packed));
16397
16398 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16399 index ced283a..ffe04cc 100644
16400 --- a/arch/x86/include/asm/div64.h
16401 +++ b/arch/x86/include/asm/div64.h
16402 @@ -39,7 +39,7 @@
16403 __mod; \
16404 })
16405
16406 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16407 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16408 {
16409 union {
16410 u64 v64;
16411 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16412 index 9c999c1..3860cb8 100644
16413 --- a/arch/x86/include/asm/elf.h
16414 +++ b/arch/x86/include/asm/elf.h
16415 @@ -243,7 +243,25 @@ extern int force_personality32;
16416 the loader. We need to make sure that it is out of the way of the program
16417 that it will "exec", and that there is sufficient room for the brk. */
16418
16419 +#ifdef CONFIG_PAX_SEGMEXEC
16420 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16421 +#else
16422 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16423 +#endif
16424 +
16425 +#ifdef CONFIG_PAX_ASLR
16426 +#ifdef CONFIG_X86_32
16427 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16428 +
16429 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16430 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16431 +#else
16432 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16433 +
16434 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16435 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16436 +#endif
16437 +#endif
16438
16439 /* This yields a mask that user programs can use to figure out what
16440 instruction set this CPU supports. This could be done in user space,
16441 @@ -296,16 +314,12 @@ do { \
16442
16443 #define ARCH_DLINFO \
16444 do { \
16445 - if (vdso_enabled) \
16446 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16447 - (unsigned long)current->mm->context.vdso); \
16448 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16449 } while (0)
16450
16451 #define ARCH_DLINFO_X32 \
16452 do { \
16453 - if (vdso_enabled) \
16454 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16455 - (unsigned long)current->mm->context.vdso); \
16456 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16457 } while (0)
16458
16459 #define AT_SYSINFO 32
16460 @@ -320,7 +334,7 @@ else \
16461
16462 #endif /* !CONFIG_X86_32 */
16463
16464 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16465 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16466
16467 #define VDSO_ENTRY \
16468 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16469 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16470 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16471 #define compat_arch_setup_additional_pages syscall32_setup_pages
16472
16473 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16474 -#define arch_randomize_brk arch_randomize_brk
16475 -
16476 /*
16477 * True on X86_32 or when emulating IA32 on X86_64
16478 */
16479 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16480 index 77a99ac..39ff7f5 100644
16481 --- a/arch/x86/include/asm/emergency-restart.h
16482 +++ b/arch/x86/include/asm/emergency-restart.h
16483 @@ -1,6 +1,6 @@
16484 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16485 #define _ASM_X86_EMERGENCY_RESTART_H
16486
16487 -extern void machine_emergency_restart(void);
16488 +extern void machine_emergency_restart(void) __noreturn;
16489
16490 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16491 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16492 index d3d7469..677ef72 100644
16493 --- a/arch/x86/include/asm/floppy.h
16494 +++ b/arch/x86/include/asm/floppy.h
16495 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16496 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16497 } fd_routine[] = {
16498 {
16499 - request_dma,
16500 - free_dma,
16501 - get_dma_residue,
16502 - dma_mem_alloc,
16503 - hard_dma_setup
16504 + ._request_dma = request_dma,
16505 + ._free_dma = free_dma,
16506 + ._get_dma_residue = get_dma_residue,
16507 + ._dma_mem_alloc = dma_mem_alloc,
16508 + ._dma_setup = hard_dma_setup
16509 },
16510 {
16511 - vdma_request_dma,
16512 - vdma_nop,
16513 - vdma_get_dma_residue,
16514 - vdma_mem_alloc,
16515 - vdma_dma_setup
16516 + ._request_dma = vdma_request_dma,
16517 + ._free_dma = vdma_nop,
16518 + ._get_dma_residue = vdma_get_dma_residue,
16519 + ._dma_mem_alloc = vdma_mem_alloc,
16520 + ._dma_setup = vdma_dma_setup
16521 }
16522 };
16523
16524 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16525 index cea1c76..6c0d79b 100644
16526 --- a/arch/x86/include/asm/fpu-internal.h
16527 +++ b/arch/x86/include/asm/fpu-internal.h
16528 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16529 #define user_insn(insn, output, input...) \
16530 ({ \
16531 int err; \
16532 + pax_open_userland(); \
16533 asm volatile(ASM_STAC "\n" \
16534 - "1:" #insn "\n\t" \
16535 + "1:" \
16536 + __copyuser_seg \
16537 + #insn "\n\t" \
16538 "2: " ASM_CLAC "\n" \
16539 ".section .fixup,\"ax\"\n" \
16540 "3: movl $-1,%[err]\n" \
16541 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16542 _ASM_EXTABLE(1b, 3b) \
16543 : [err] "=r" (err), output \
16544 : "0"(0), input); \
16545 + pax_close_userland(); \
16546 err; \
16547 })
16548
16549 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16550 "fnclex\n\t"
16551 "emms\n\t"
16552 "fildl %P[addr]" /* set F?P to defined value */
16553 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16554 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16555 }
16556
16557 return fpu_restore_checking(&tsk->thread.fpu);
16558 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16559 index be27ba1..04a8801 100644
16560 --- a/arch/x86/include/asm/futex.h
16561 +++ b/arch/x86/include/asm/futex.h
16562 @@ -12,6 +12,7 @@
16563 #include <asm/smap.h>
16564
16565 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16566 + typecheck(u32 __user *, uaddr); \
16567 asm volatile("\t" ASM_STAC "\n" \
16568 "1:\t" insn "\n" \
16569 "2:\t" ASM_CLAC "\n" \
16570 @@ -20,15 +21,16 @@
16571 "\tjmp\t2b\n" \
16572 "\t.previous\n" \
16573 _ASM_EXTABLE(1b, 3b) \
16574 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16575 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16576 : "i" (-EFAULT), "0" (oparg), "1" (0))
16577
16578 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16579 + typecheck(u32 __user *, uaddr); \
16580 asm volatile("\t" ASM_STAC "\n" \
16581 "1:\tmovl %2, %0\n" \
16582 "\tmovl\t%0, %3\n" \
16583 "\t" insn "\n" \
16584 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16585 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16586 "\tjnz\t1b\n" \
16587 "3:\t" ASM_CLAC "\n" \
16588 "\t.section .fixup,\"ax\"\n" \
16589 @@ -38,7 +40,7 @@
16590 _ASM_EXTABLE(1b, 4b) \
16591 _ASM_EXTABLE(2b, 4b) \
16592 : "=&a" (oldval), "=&r" (ret), \
16593 - "+m" (*uaddr), "=&r" (tem) \
16594 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16595 : "r" (oparg), "i" (-EFAULT), "1" (0))
16596
16597 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16598 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16599
16600 pagefault_disable();
16601
16602 + pax_open_userland();
16603 switch (op) {
16604 case FUTEX_OP_SET:
16605 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16606 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16607 break;
16608 case FUTEX_OP_ADD:
16609 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16610 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16611 uaddr, oparg);
16612 break;
16613 case FUTEX_OP_OR:
16614 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16615 default:
16616 ret = -ENOSYS;
16617 }
16618 + pax_close_userland();
16619
16620 pagefault_enable();
16621
16622 @@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16623 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16624 return -EFAULT;
16625
16626 + pax_open_userland();
16627 asm volatile("\t" ASM_STAC "\n"
16628 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16629 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16630 "2:\t" ASM_CLAC "\n"
16631 "\t.section .fixup, \"ax\"\n"
16632 "3:\tmov %3, %0\n"
16633 "\tjmp 2b\n"
16634 "\t.previous\n"
16635 _ASM_EXTABLE(1b, 3b)
16636 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16637 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16638 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16639 : "memory"
16640 );
16641 + pax_close_userland();
16642
16643 *uval = oldval;
16644 return ret;
16645 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16646 index cba45d9..86344ba 100644
16647 --- a/arch/x86/include/asm/hw_irq.h
16648 +++ b/arch/x86/include/asm/hw_irq.h
16649 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16650 extern void enable_IO_APIC(void);
16651
16652 /* Statistics */
16653 -extern atomic_t irq_err_count;
16654 -extern atomic_t irq_mis_count;
16655 +extern atomic_unchecked_t irq_err_count;
16656 +extern atomic_unchecked_t irq_mis_count;
16657
16658 /* EISA */
16659 extern void eisa_set_level_irq(unsigned int irq);
16660 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16661 index a203659..9889f1c 100644
16662 --- a/arch/x86/include/asm/i8259.h
16663 +++ b/arch/x86/include/asm/i8259.h
16664 @@ -62,7 +62,7 @@ struct legacy_pic {
16665 void (*init)(int auto_eoi);
16666 int (*irq_pending)(unsigned int irq);
16667 void (*make_irq)(unsigned int irq);
16668 -};
16669 +} __do_const;
16670
16671 extern struct legacy_pic *legacy_pic;
16672 extern struct legacy_pic null_legacy_pic;
16673 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16674 index 34f69cb..6d95446 100644
16675 --- a/arch/x86/include/asm/io.h
16676 +++ b/arch/x86/include/asm/io.h
16677 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16678 "m" (*(volatile type __force *)addr) barrier); }
16679
16680 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16681 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16682 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16683 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16684 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16685
16686 build_mmio_read(__readb, "b", unsigned char, "=q", )
16687 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16688 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16689 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16690 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16691
16692 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16693 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16694 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16695 return ioremap_nocache(offset, size);
16696 }
16697
16698 -extern void iounmap(volatile void __iomem *addr);
16699 +extern void iounmap(const volatile void __iomem *addr);
16700
16701 extern void set_iounmap_nonlazy(void);
16702
16703 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16704
16705 #include <linux/vmalloc.h>
16706
16707 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16708 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16709 +{
16710 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16711 +}
16712 +
16713 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16714 +{
16715 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16716 +}
16717 +
16718 /*
16719 * Convert a virtual cached pointer to an uncached pointer
16720 */
16721 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16722 index bba3cf8..06bc8da 100644
16723 --- a/arch/x86/include/asm/irqflags.h
16724 +++ b/arch/x86/include/asm/irqflags.h
16725 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16726 sti; \
16727 sysexit
16728
16729 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16730 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16731 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16732 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16733 +
16734 #else
16735 #define INTERRUPT_RETURN iret
16736 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16737 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16738 index 9454c16..e4100e3 100644
16739 --- a/arch/x86/include/asm/kprobes.h
16740 +++ b/arch/x86/include/asm/kprobes.h
16741 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16742 #define RELATIVEJUMP_SIZE 5
16743 #define RELATIVECALL_OPCODE 0xe8
16744 #define RELATIVE_ADDR_SIZE 4
16745 -#define MAX_STACK_SIZE 64
16746 -#define MIN_STACK_SIZE(ADDR) \
16747 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16748 - THREAD_SIZE - (unsigned long)(ADDR))) \
16749 - ? (MAX_STACK_SIZE) \
16750 - : (((unsigned long)current_thread_info()) + \
16751 - THREAD_SIZE - (unsigned long)(ADDR)))
16752 +#define MAX_STACK_SIZE 64UL
16753 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16754
16755 #define flush_insn_slot(p) do { } while (0)
16756
16757 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16758 index 4ad6560..75c7bdd 100644
16759 --- a/arch/x86/include/asm/local.h
16760 +++ b/arch/x86/include/asm/local.h
16761 @@ -10,33 +10,97 @@ typedef struct {
16762 atomic_long_t a;
16763 } local_t;
16764
16765 +typedef struct {
16766 + atomic_long_unchecked_t a;
16767 +} local_unchecked_t;
16768 +
16769 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16770
16771 #define local_read(l) atomic_long_read(&(l)->a)
16772 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16773 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16774 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16775
16776 static inline void local_inc(local_t *l)
16777 {
16778 - asm volatile(_ASM_INC "%0"
16779 + asm volatile(_ASM_INC "%0\n"
16780 +
16781 +#ifdef CONFIG_PAX_REFCOUNT
16782 + "jno 0f\n"
16783 + _ASM_DEC "%0\n"
16784 + "int $4\n0:\n"
16785 + _ASM_EXTABLE(0b, 0b)
16786 +#endif
16787 +
16788 + : "+m" (l->a.counter));
16789 +}
16790 +
16791 +static inline void local_inc_unchecked(local_unchecked_t *l)
16792 +{
16793 + asm volatile(_ASM_INC "%0\n"
16794 : "+m" (l->a.counter));
16795 }
16796
16797 static inline void local_dec(local_t *l)
16798 {
16799 - asm volatile(_ASM_DEC "%0"
16800 + asm volatile(_ASM_DEC "%0\n"
16801 +
16802 +#ifdef CONFIG_PAX_REFCOUNT
16803 + "jno 0f\n"
16804 + _ASM_INC "%0\n"
16805 + "int $4\n0:\n"
16806 + _ASM_EXTABLE(0b, 0b)
16807 +#endif
16808 +
16809 + : "+m" (l->a.counter));
16810 +}
16811 +
16812 +static inline void local_dec_unchecked(local_unchecked_t *l)
16813 +{
16814 + asm volatile(_ASM_DEC "%0\n"
16815 : "+m" (l->a.counter));
16816 }
16817
16818 static inline void local_add(long i, local_t *l)
16819 {
16820 - asm volatile(_ASM_ADD "%1,%0"
16821 + asm volatile(_ASM_ADD "%1,%0\n"
16822 +
16823 +#ifdef CONFIG_PAX_REFCOUNT
16824 + "jno 0f\n"
16825 + _ASM_SUB "%1,%0\n"
16826 + "int $4\n0:\n"
16827 + _ASM_EXTABLE(0b, 0b)
16828 +#endif
16829 +
16830 + : "+m" (l->a.counter)
16831 + : "ir" (i));
16832 +}
16833 +
16834 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16835 +{
16836 + asm volatile(_ASM_ADD "%1,%0\n"
16837 : "+m" (l->a.counter)
16838 : "ir" (i));
16839 }
16840
16841 static inline void local_sub(long i, local_t *l)
16842 {
16843 - asm volatile(_ASM_SUB "%1,%0"
16844 + asm volatile(_ASM_SUB "%1,%0\n"
16845 +
16846 +#ifdef CONFIG_PAX_REFCOUNT
16847 + "jno 0f\n"
16848 + _ASM_ADD "%1,%0\n"
16849 + "int $4\n0:\n"
16850 + _ASM_EXTABLE(0b, 0b)
16851 +#endif
16852 +
16853 + : "+m" (l->a.counter)
16854 + : "ir" (i));
16855 +}
16856 +
16857 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16858 +{
16859 + asm volatile(_ASM_SUB "%1,%0\n"
16860 : "+m" (l->a.counter)
16861 : "ir" (i));
16862 }
16863 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16864 */
16865 static inline int local_sub_and_test(long i, local_t *l)
16866 {
16867 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16868 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16869 }
16870
16871 /**
16872 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16873 */
16874 static inline int local_dec_and_test(local_t *l)
16875 {
16876 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16877 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16878 }
16879
16880 /**
16881 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16882 */
16883 static inline int local_inc_and_test(local_t *l)
16884 {
16885 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16886 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16887 }
16888
16889 /**
16890 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16891 */
16892 static inline int local_add_negative(long i, local_t *l)
16893 {
16894 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16895 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16896 }
16897
16898 /**
16899 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16900 static inline long local_add_return(long i, local_t *l)
16901 {
16902 long __i = i;
16903 + asm volatile(_ASM_XADD "%0, %1\n"
16904 +
16905 +#ifdef CONFIG_PAX_REFCOUNT
16906 + "jno 0f\n"
16907 + _ASM_MOV "%0,%1\n"
16908 + "int $4\n0:\n"
16909 + _ASM_EXTABLE(0b, 0b)
16910 +#endif
16911 +
16912 + : "+r" (i), "+m" (l->a.counter)
16913 + : : "memory");
16914 + return i + __i;
16915 +}
16916 +
16917 +/**
16918 + * local_add_return_unchecked - add and return
16919 + * @i: integer value to add
16920 + * @l: pointer to type local_unchecked_t
16921 + *
16922 + * Atomically adds @i to @l and returns @i + @l
16923 + */
16924 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16925 +{
16926 + long __i = i;
16927 asm volatile(_ASM_XADD "%0, %1;"
16928 : "+r" (i), "+m" (l->a.counter)
16929 : : "memory");
16930 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16931
16932 #define local_cmpxchg(l, o, n) \
16933 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16934 +#define local_cmpxchg_unchecked(l, o, n) \
16935 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
16936 /* Always has a lock prefix */
16937 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16938
16939 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16940 new file mode 100644
16941 index 0000000..2bfd3ba
16942 --- /dev/null
16943 +++ b/arch/x86/include/asm/mman.h
16944 @@ -0,0 +1,15 @@
16945 +#ifndef _X86_MMAN_H
16946 +#define _X86_MMAN_H
16947 +
16948 +#include <uapi/asm/mman.h>
16949 +
16950 +#ifdef __KERNEL__
16951 +#ifndef __ASSEMBLY__
16952 +#ifdef CONFIG_X86_32
16953 +#define arch_mmap_check i386_mmap_check
16954 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16955 +#endif
16956 +#endif
16957 +#endif
16958 +
16959 +#endif /* X86_MMAN_H */
16960 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16961 index 5f55e69..e20bfb1 100644
16962 --- a/arch/x86/include/asm/mmu.h
16963 +++ b/arch/x86/include/asm/mmu.h
16964 @@ -9,7 +9,7 @@
16965 * we put the segment information here.
16966 */
16967 typedef struct {
16968 - void *ldt;
16969 + struct desc_struct *ldt;
16970 int size;
16971
16972 #ifdef CONFIG_X86_64
16973 @@ -18,7 +18,19 @@ typedef struct {
16974 #endif
16975
16976 struct mutex lock;
16977 - void *vdso;
16978 + unsigned long vdso;
16979 +
16980 +#ifdef CONFIG_X86_32
16981 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16982 + unsigned long user_cs_base;
16983 + unsigned long user_cs_limit;
16984 +
16985 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16986 + cpumask_t cpu_user_cs_mask;
16987 +#endif
16988 +
16989 +#endif
16990 +#endif
16991 } mm_context_t;
16992
16993 #ifdef CONFIG_SMP
16994 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16995 index be12c53..4d24039 100644
16996 --- a/arch/x86/include/asm/mmu_context.h
16997 +++ b/arch/x86/include/asm/mmu_context.h
16998 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16999
17000 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17001 {
17002 +
17003 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17004 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17005 + unsigned int i;
17006 + pgd_t *pgd;
17007 +
17008 + pax_open_kernel();
17009 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17010 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17011 + set_pgd_batched(pgd+i, native_make_pgd(0));
17012 + pax_close_kernel();
17013 + }
17014 +#endif
17015 +
17016 #ifdef CONFIG_SMP
17017 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17018 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17019 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17020 struct task_struct *tsk)
17021 {
17022 unsigned cpu = smp_processor_id();
17023 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17024 + int tlbstate = TLBSTATE_OK;
17025 +#endif
17026
17027 if (likely(prev != next)) {
17028 #ifdef CONFIG_SMP
17029 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17030 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17031 +#endif
17032 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17033 this_cpu_write(cpu_tlbstate.active_mm, next);
17034 #endif
17035 cpumask_set_cpu(cpu, mm_cpumask(next));
17036
17037 /* Re-load page tables */
17038 +#ifdef CONFIG_PAX_PER_CPU_PGD
17039 + pax_open_kernel();
17040 +
17041 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17042 + if (static_cpu_has(X86_FEATURE_PCID))
17043 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17044 + else
17045 +#endif
17046 +
17047 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17048 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17049 + pax_close_kernel();
17050 + 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));
17051 +
17052 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17053 + if (static_cpu_has(X86_FEATURE_PCID)) {
17054 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17055 + u64 descriptor[2];
17056 + descriptor[0] = PCID_USER;
17057 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17058 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17059 + descriptor[0] = PCID_KERNEL;
17060 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17061 + }
17062 + } else {
17063 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17064 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17065 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17066 + else
17067 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17068 + }
17069 + } else
17070 +#endif
17071 +
17072 + load_cr3(get_cpu_pgd(cpu, kernel));
17073 +#else
17074 load_cr3(next->pgd);
17075 +#endif
17076
17077 /* Stop flush ipis for the previous mm */
17078 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17079 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17080 /* Load the LDT, if the LDT is different: */
17081 if (unlikely(prev->context.ldt != next->context.ldt))
17082 load_LDT_nolock(&next->context);
17083 +
17084 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17085 + if (!(__supported_pte_mask & _PAGE_NX)) {
17086 + smp_mb__before_clear_bit();
17087 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17088 + smp_mb__after_clear_bit();
17089 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17090 + }
17091 +#endif
17092 +
17093 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17094 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17095 + prev->context.user_cs_limit != next->context.user_cs_limit))
17096 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17097 +#ifdef CONFIG_SMP
17098 + else if (unlikely(tlbstate != TLBSTATE_OK))
17099 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17100 +#endif
17101 +#endif
17102 +
17103 }
17104 + else {
17105 +
17106 +#ifdef CONFIG_PAX_PER_CPU_PGD
17107 + pax_open_kernel();
17108 +
17109 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17110 + if (static_cpu_has(X86_FEATURE_PCID))
17111 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17112 + else
17113 +#endif
17114 +
17115 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17116 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17117 + pax_close_kernel();
17118 + 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));
17119 +
17120 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17121 + if (static_cpu_has(X86_FEATURE_PCID)) {
17122 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17123 + u64 descriptor[2];
17124 + descriptor[0] = PCID_USER;
17125 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17126 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17127 + descriptor[0] = PCID_KERNEL;
17128 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17129 + }
17130 + } else {
17131 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17132 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17133 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17134 + else
17135 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17136 + }
17137 + } else
17138 +#endif
17139 +
17140 + load_cr3(get_cpu_pgd(cpu, kernel));
17141 +#endif
17142 +
17143 #ifdef CONFIG_SMP
17144 - else {
17145 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17146 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17147
17148 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17149 * tlb flush IPI delivery. We must reload CR3
17150 * to make sure to use no freed page tables.
17151 */
17152 +
17153 +#ifndef CONFIG_PAX_PER_CPU_PGD
17154 load_cr3(next->pgd);
17155 +#endif
17156 +
17157 load_LDT_nolock(&next->context);
17158 +
17159 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17160 + if (!(__supported_pte_mask & _PAGE_NX))
17161 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17162 +#endif
17163 +
17164 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17165 +#ifdef CONFIG_PAX_PAGEEXEC
17166 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17167 +#endif
17168 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17169 +#endif
17170 +
17171 }
17172 +#endif
17173 }
17174 -#endif
17175 }
17176
17177 #define activate_mm(prev, next) \
17178 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17179 index e3b7819..b257c64 100644
17180 --- a/arch/x86/include/asm/module.h
17181 +++ b/arch/x86/include/asm/module.h
17182 @@ -5,6 +5,7 @@
17183
17184 #ifdef CONFIG_X86_64
17185 /* X86_64 does not define MODULE_PROC_FAMILY */
17186 +#define MODULE_PROC_FAMILY ""
17187 #elif defined CONFIG_M486
17188 #define MODULE_PROC_FAMILY "486 "
17189 #elif defined CONFIG_M586
17190 @@ -57,8 +58,20 @@
17191 #error unknown processor family
17192 #endif
17193
17194 -#ifdef CONFIG_X86_32
17195 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17196 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17197 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17198 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17199 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17200 +#else
17201 +#define MODULE_PAX_KERNEXEC ""
17202 #endif
17203
17204 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17205 +#define MODULE_PAX_UDEREF "UDEREF "
17206 +#else
17207 +#define MODULE_PAX_UDEREF ""
17208 +#endif
17209 +
17210 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17211 +
17212 #endif /* _ASM_X86_MODULE_H */
17213 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17214 index 86f9301..b365cda 100644
17215 --- a/arch/x86/include/asm/nmi.h
17216 +++ b/arch/x86/include/asm/nmi.h
17217 @@ -40,11 +40,11 @@ struct nmiaction {
17218 nmi_handler_t handler;
17219 unsigned long flags;
17220 const char *name;
17221 -};
17222 +} __do_const;
17223
17224 #define register_nmi_handler(t, fn, fg, n, init...) \
17225 ({ \
17226 - static struct nmiaction init fn##_na = { \
17227 + static const struct nmiaction init fn##_na = { \
17228 .handler = (fn), \
17229 .name = (n), \
17230 .flags = (fg), \
17231 @@ -52,7 +52,7 @@ struct nmiaction {
17232 __register_nmi_handler((t), &fn##_na); \
17233 })
17234
17235 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17236 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17237
17238 void unregister_nmi_handler(unsigned int, const char *);
17239
17240 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17241 index c878924..21f4889 100644
17242 --- a/arch/x86/include/asm/page.h
17243 +++ b/arch/x86/include/asm/page.h
17244 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17245 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17246
17247 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17248 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17249
17250 #define __boot_va(x) __va(x)
17251 #define __boot_pa(x) __pa(x)
17252 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17253 index 0f1ddee..e2fc3d1 100644
17254 --- a/arch/x86/include/asm/page_64.h
17255 +++ b/arch/x86/include/asm/page_64.h
17256 @@ -7,9 +7,9 @@
17257
17258 /* duplicated to the one in bootmem.h */
17259 extern unsigned long max_pfn;
17260 -extern unsigned long phys_base;
17261 +extern const unsigned long phys_base;
17262
17263 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17264 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17265 {
17266 unsigned long y = x - __START_KERNEL_map;
17267
17268 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17269 index 401f350..dee5d13 100644
17270 --- a/arch/x86/include/asm/paravirt.h
17271 +++ b/arch/x86/include/asm/paravirt.h
17272 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17273 return (pmd_t) { ret };
17274 }
17275
17276 -static inline pmdval_t pmd_val(pmd_t pmd)
17277 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17278 {
17279 pmdval_t ret;
17280
17281 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17282 val);
17283 }
17284
17285 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17286 +{
17287 + pgdval_t val = native_pgd_val(pgd);
17288 +
17289 + if (sizeof(pgdval_t) > sizeof(long))
17290 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17291 + val, (u64)val >> 32);
17292 + else
17293 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17294 + val);
17295 +}
17296 +
17297 static inline void pgd_clear(pgd_t *pgdp)
17298 {
17299 set_pgd(pgdp, __pgd(0));
17300 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17301 pv_mmu_ops.set_fixmap(idx, phys, flags);
17302 }
17303
17304 +#ifdef CONFIG_PAX_KERNEXEC
17305 +static inline unsigned long pax_open_kernel(void)
17306 +{
17307 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17308 +}
17309 +
17310 +static inline unsigned long pax_close_kernel(void)
17311 +{
17312 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17313 +}
17314 +#else
17315 +static inline unsigned long pax_open_kernel(void) { return 0; }
17316 +static inline unsigned long pax_close_kernel(void) { return 0; }
17317 +#endif
17318 +
17319 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17320
17321 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17322 @@ -906,7 +933,7 @@ extern void default_banner(void);
17323
17324 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17325 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17326 -#define PARA_INDIRECT(addr) *%cs:addr
17327 +#define PARA_INDIRECT(addr) *%ss:addr
17328 #endif
17329
17330 #define INTERRUPT_RETURN \
17331 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17332 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17333 CLBR_NONE, \
17334 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17335 +
17336 +#define GET_CR0_INTO_RDI \
17337 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17338 + mov %rax,%rdi
17339 +
17340 +#define SET_RDI_INTO_CR0 \
17341 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17342 +
17343 +#define GET_CR3_INTO_RDI \
17344 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17345 + mov %rax,%rdi
17346 +
17347 +#define SET_RDI_INTO_CR3 \
17348 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17349 +
17350 #endif /* CONFIG_X86_32 */
17351
17352 #endif /* __ASSEMBLY__ */
17353 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17354 index aab8f67..0fb0ee4 100644
17355 --- a/arch/x86/include/asm/paravirt_types.h
17356 +++ b/arch/x86/include/asm/paravirt_types.h
17357 @@ -84,7 +84,7 @@ struct pv_init_ops {
17358 */
17359 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17360 unsigned long addr, unsigned len);
17361 -};
17362 +} __no_const __no_randomize_layout;
17363
17364
17365 struct pv_lazy_ops {
17366 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17367 void (*enter)(void);
17368 void (*leave)(void);
17369 void (*flush)(void);
17370 -};
17371 +} __no_randomize_layout;
17372
17373 struct pv_time_ops {
17374 unsigned long long (*sched_clock)(void);
17375 unsigned long long (*steal_clock)(int cpu);
17376 unsigned long (*get_tsc_khz)(void);
17377 -};
17378 +} __no_const __no_randomize_layout;
17379
17380 struct pv_cpu_ops {
17381 /* hooks for various privileged instructions */
17382 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17383
17384 void (*start_context_switch)(struct task_struct *prev);
17385 void (*end_context_switch)(struct task_struct *next);
17386 -};
17387 +} __no_const __no_randomize_layout;
17388
17389 struct pv_irq_ops {
17390 /*
17391 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17392 #ifdef CONFIG_X86_64
17393 void (*adjust_exception_frame)(void);
17394 #endif
17395 -};
17396 +} __no_randomize_layout;
17397
17398 struct pv_apic_ops {
17399 #ifdef CONFIG_X86_LOCAL_APIC
17400 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17401 unsigned long start_eip,
17402 unsigned long start_esp);
17403 #endif
17404 -};
17405 +} __no_const __no_randomize_layout;
17406
17407 struct pv_mmu_ops {
17408 unsigned long (*read_cr2)(void);
17409 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17410 struct paravirt_callee_save make_pud;
17411
17412 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17413 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17414 #endif /* PAGETABLE_LEVELS == 4 */
17415 #endif /* PAGETABLE_LEVELS >= 3 */
17416
17417 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17418 an mfn. We can tell which is which from the index. */
17419 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17420 phys_addr_t phys, pgprot_t flags);
17421 -};
17422 +
17423 +#ifdef CONFIG_PAX_KERNEXEC
17424 + unsigned long (*pax_open_kernel)(void);
17425 + unsigned long (*pax_close_kernel)(void);
17426 +#endif
17427 +
17428 +} __no_randomize_layout;
17429
17430 struct arch_spinlock;
17431 #ifdef CONFIG_SMP
17432 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17433 struct pv_lock_ops {
17434 struct paravirt_callee_save lock_spinning;
17435 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17436 -};
17437 +} __no_randomize_layout;
17438
17439 /* This contains all the paravirt structures: we get a convenient
17440 * number for each function using the offset which we use to indicate
17441 - * what to patch. */
17442 + * what to patch.
17443 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17444 + */
17445 +
17446 struct paravirt_patch_template {
17447 struct pv_init_ops pv_init_ops;
17448 struct pv_time_ops pv_time_ops;
17449 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17450 struct pv_apic_ops pv_apic_ops;
17451 struct pv_mmu_ops pv_mmu_ops;
17452 struct pv_lock_ops pv_lock_ops;
17453 -};
17454 +} __no_randomize_layout;
17455
17456 extern struct pv_info pv_info;
17457 extern struct pv_init_ops pv_init_ops;
17458 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17459 index c4412e9..90e88c5 100644
17460 --- a/arch/x86/include/asm/pgalloc.h
17461 +++ b/arch/x86/include/asm/pgalloc.h
17462 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17463 pmd_t *pmd, pte_t *pte)
17464 {
17465 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17466 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17467 +}
17468 +
17469 +static inline void pmd_populate_user(struct mm_struct *mm,
17470 + pmd_t *pmd, pte_t *pte)
17471 +{
17472 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17473 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17474 }
17475
17476 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17477
17478 #ifdef CONFIG_X86_PAE
17479 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17480 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17481 +{
17482 + pud_populate(mm, pudp, pmd);
17483 +}
17484 #else /* !CONFIG_X86_PAE */
17485 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17486 {
17487 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17488 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17489 }
17490 +
17491 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17492 +{
17493 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17494 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17495 +}
17496 #endif /* CONFIG_X86_PAE */
17497
17498 #if PAGETABLE_LEVELS > 3
17499 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17500 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17501 }
17502
17503 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17504 +{
17505 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17506 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17507 +}
17508 +
17509 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17510 {
17511 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17512 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17513 index 3bf2dd0..23d2a9f 100644
17514 --- a/arch/x86/include/asm/pgtable-2level.h
17515 +++ b/arch/x86/include/asm/pgtable-2level.h
17516 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17517
17518 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17519 {
17520 + pax_open_kernel();
17521 *pmdp = pmd;
17522 + pax_close_kernel();
17523 }
17524
17525 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17526 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17527 index 81bb91b..9392125 100644
17528 --- a/arch/x86/include/asm/pgtable-3level.h
17529 +++ b/arch/x86/include/asm/pgtable-3level.h
17530 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17531
17532 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17533 {
17534 + pax_open_kernel();
17535 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17536 + pax_close_kernel();
17537 }
17538
17539 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17540 {
17541 + pax_open_kernel();
17542 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17543 + pax_close_kernel();
17544 }
17545
17546 /*
17547 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17548 index 5ad38ad..71db3f2 100644
17549 --- a/arch/x86/include/asm/pgtable.h
17550 +++ b/arch/x86/include/asm/pgtable.h
17551 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17552
17553 #ifndef __PAGETABLE_PUD_FOLDED
17554 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17555 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17556 #define pgd_clear(pgd) native_pgd_clear(pgd)
17557 #endif
17558
17559 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17560
17561 #define arch_end_context_switch(prev) do {} while(0)
17562
17563 +#define pax_open_kernel() native_pax_open_kernel()
17564 +#define pax_close_kernel() native_pax_close_kernel()
17565 #endif /* CONFIG_PARAVIRT */
17566
17567 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17568 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17569 +
17570 +#ifdef CONFIG_PAX_KERNEXEC
17571 +static inline unsigned long native_pax_open_kernel(void)
17572 +{
17573 + unsigned long cr0;
17574 +
17575 + preempt_disable();
17576 + barrier();
17577 + cr0 = read_cr0() ^ X86_CR0_WP;
17578 + BUG_ON(cr0 & X86_CR0_WP);
17579 + write_cr0(cr0);
17580 + return cr0 ^ X86_CR0_WP;
17581 +}
17582 +
17583 +static inline unsigned long native_pax_close_kernel(void)
17584 +{
17585 + unsigned long cr0;
17586 +
17587 + cr0 = read_cr0() ^ X86_CR0_WP;
17588 + BUG_ON(!(cr0 & X86_CR0_WP));
17589 + write_cr0(cr0);
17590 + barrier();
17591 + preempt_enable_no_resched();
17592 + return cr0 ^ X86_CR0_WP;
17593 +}
17594 +#else
17595 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17596 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17597 +#endif
17598 +
17599 /*
17600 * The following only work if pte_present() is true.
17601 * Undefined behaviour if not..
17602 */
17603 +static inline int pte_user(pte_t pte)
17604 +{
17605 + return pte_val(pte) & _PAGE_USER;
17606 +}
17607 +
17608 static inline int pte_dirty(pte_t pte)
17609 {
17610 return pte_flags(pte) & _PAGE_DIRTY;
17611 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17612 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17613 }
17614
17615 +static inline unsigned long pgd_pfn(pgd_t pgd)
17616 +{
17617 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17618 +}
17619 +
17620 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17621
17622 static inline int pmd_large(pmd_t pte)
17623 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17624 return pte_clear_flags(pte, _PAGE_RW);
17625 }
17626
17627 +static inline pte_t pte_mkread(pte_t pte)
17628 +{
17629 + return __pte(pte_val(pte) | _PAGE_USER);
17630 +}
17631 +
17632 static inline pte_t pte_mkexec(pte_t pte)
17633 {
17634 - return pte_clear_flags(pte, _PAGE_NX);
17635 +#ifdef CONFIG_X86_PAE
17636 + if (__supported_pte_mask & _PAGE_NX)
17637 + return pte_clear_flags(pte, _PAGE_NX);
17638 + else
17639 +#endif
17640 + return pte_set_flags(pte, _PAGE_USER);
17641 +}
17642 +
17643 +static inline pte_t pte_exprotect(pte_t pte)
17644 +{
17645 +#ifdef CONFIG_X86_PAE
17646 + if (__supported_pte_mask & _PAGE_NX)
17647 + return pte_set_flags(pte, _PAGE_NX);
17648 + else
17649 +#endif
17650 + return pte_clear_flags(pte, _PAGE_USER);
17651 }
17652
17653 static inline pte_t pte_mkdirty(pte_t pte)
17654 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17655 #endif
17656
17657 #ifndef __ASSEMBLY__
17658 +
17659 +#ifdef CONFIG_PAX_PER_CPU_PGD
17660 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17661 +enum cpu_pgd_type {kernel = 0, user = 1};
17662 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17663 +{
17664 + return cpu_pgd[cpu][type];
17665 +}
17666 +#endif
17667 +
17668 #include <linux/mm_types.h>
17669 #include <linux/mmdebug.h>
17670 #include <linux/log2.h>
17671 @@ -580,7 +655,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17672 * Currently stuck as a macro due to indirect forward reference to
17673 * linux/mmzone.h's __section_mem_map_addr() definition:
17674 */
17675 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17676 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17677
17678 /* Find an entry in the second-level page table.. */
17679 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17680 @@ -620,7 +695,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17681 * Currently stuck as a macro due to indirect forward reference to
17682 * linux/mmzone.h's __section_mem_map_addr() definition:
17683 */
17684 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17685 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17686
17687 /* to find an entry in a page-table-directory. */
17688 static inline unsigned long pud_index(unsigned long address)
17689 @@ -635,7 +710,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17690
17691 static inline int pgd_bad(pgd_t pgd)
17692 {
17693 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17694 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17695 }
17696
17697 static inline int pgd_none(pgd_t pgd)
17698 @@ -658,7 +733,12 @@ static inline int pgd_none(pgd_t pgd)
17699 * pgd_offset() returns a (pgd_t *)
17700 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17701 */
17702 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17703 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17704 +
17705 +#ifdef CONFIG_PAX_PER_CPU_PGD
17706 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17707 +#endif
17708 +
17709 /*
17710 * a shortcut which implies the use of the kernel's pgd, instead
17711 * of a process's
17712 @@ -669,6 +749,23 @@ static inline int pgd_none(pgd_t pgd)
17713 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17714 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17715
17716 +#ifdef CONFIG_X86_32
17717 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17718 +#else
17719 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17720 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17721 +
17722 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17723 +#ifdef __ASSEMBLY__
17724 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17725 +#else
17726 +extern unsigned long pax_user_shadow_base;
17727 +extern pgdval_t clone_pgd_mask;
17728 +#endif
17729 +#endif
17730 +
17731 +#endif
17732 +
17733 #ifndef __ASSEMBLY__
17734
17735 extern int direct_gbpages;
17736 @@ -835,11 +932,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17737 * dst and src can be on the same page, but the range must not overlap,
17738 * and must not cross a page boundary.
17739 */
17740 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17741 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17742 {
17743 - memcpy(dst, src, count * sizeof(pgd_t));
17744 + pax_open_kernel();
17745 + while (count--)
17746 + *dst++ = *src++;
17747 + pax_close_kernel();
17748 }
17749
17750 +#ifdef CONFIG_PAX_PER_CPU_PGD
17751 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17752 +#endif
17753 +
17754 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17755 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17756 +#else
17757 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17758 +#endif
17759 +
17760 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17761 static inline int page_level_shift(enum pg_level level)
17762 {
17763 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17764 index 9ee3221..b979c6b 100644
17765 --- a/arch/x86/include/asm/pgtable_32.h
17766 +++ b/arch/x86/include/asm/pgtable_32.h
17767 @@ -25,9 +25,6 @@
17768 struct mm_struct;
17769 struct vm_area_struct;
17770
17771 -extern pgd_t swapper_pg_dir[1024];
17772 -extern pgd_t initial_page_table[1024];
17773 -
17774 static inline void pgtable_cache_init(void) { }
17775 static inline void check_pgt_cache(void) { }
17776 void paging_init(void);
17777 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17778 # include <asm/pgtable-2level.h>
17779 #endif
17780
17781 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17782 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17783 +#ifdef CONFIG_X86_PAE
17784 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17785 +#endif
17786 +
17787 #if defined(CONFIG_HIGHPTE)
17788 #define pte_offset_map(dir, address) \
17789 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17790 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17791 /* Clear a kernel PTE and flush it from the TLB */
17792 #define kpte_clear_flush(ptep, vaddr) \
17793 do { \
17794 + pax_open_kernel(); \
17795 pte_clear(&init_mm, (vaddr), (ptep)); \
17796 + pax_close_kernel(); \
17797 __flush_tlb_one((vaddr)); \
17798 } while (0)
17799
17800 #endif /* !__ASSEMBLY__ */
17801
17802 +#define HAVE_ARCH_UNMAPPED_AREA
17803 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17804 +
17805 /*
17806 * kern_addr_valid() is (1) for FLATMEM and (0) for
17807 * SPARSEMEM and DISCONTIGMEM
17808 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17809 index ed5903b..c7fe163 100644
17810 --- a/arch/x86/include/asm/pgtable_32_types.h
17811 +++ b/arch/x86/include/asm/pgtable_32_types.h
17812 @@ -8,7 +8,7 @@
17813 */
17814 #ifdef CONFIG_X86_PAE
17815 # include <asm/pgtable-3level_types.h>
17816 -# define PMD_SIZE (1UL << PMD_SHIFT)
17817 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17818 # define PMD_MASK (~(PMD_SIZE - 1))
17819 #else
17820 # include <asm/pgtable-2level_types.h>
17821 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17822 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17823 #endif
17824
17825 +#ifdef CONFIG_PAX_KERNEXEC
17826 +#ifndef __ASSEMBLY__
17827 +extern unsigned char MODULES_EXEC_VADDR[];
17828 +extern unsigned char MODULES_EXEC_END[];
17829 +#endif
17830 +#include <asm/boot.h>
17831 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17832 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17833 +#else
17834 +#define ktla_ktva(addr) (addr)
17835 +#define ktva_ktla(addr) (addr)
17836 +#endif
17837 +
17838 #define MODULES_VADDR VMALLOC_START
17839 #define MODULES_END VMALLOC_END
17840 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17841 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17842 index e22c1db..23a625a 100644
17843 --- a/arch/x86/include/asm/pgtable_64.h
17844 +++ b/arch/x86/include/asm/pgtable_64.h
17845 @@ -16,10 +16,14 @@
17846
17847 extern pud_t level3_kernel_pgt[512];
17848 extern pud_t level3_ident_pgt[512];
17849 +extern pud_t level3_vmalloc_start_pgt[512];
17850 +extern pud_t level3_vmalloc_end_pgt[512];
17851 +extern pud_t level3_vmemmap_pgt[512];
17852 +extern pud_t level2_vmemmap_pgt[512];
17853 extern pmd_t level2_kernel_pgt[512];
17854 extern pmd_t level2_fixmap_pgt[512];
17855 -extern pmd_t level2_ident_pgt[512];
17856 -extern pgd_t init_level4_pgt[];
17857 +extern pmd_t level2_ident_pgt[512*2];
17858 +extern pgd_t init_level4_pgt[512];
17859
17860 #define swapper_pg_dir init_level4_pgt
17861
17862 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17863
17864 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17865 {
17866 + pax_open_kernel();
17867 *pmdp = pmd;
17868 + pax_close_kernel();
17869 }
17870
17871 static inline void native_pmd_clear(pmd_t *pmd)
17872 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17873
17874 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17875 {
17876 + pax_open_kernel();
17877 *pudp = pud;
17878 + pax_close_kernel();
17879 }
17880
17881 static inline void native_pud_clear(pud_t *pud)
17882 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17883
17884 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17885 {
17886 + pax_open_kernel();
17887 + *pgdp = pgd;
17888 + pax_close_kernel();
17889 +}
17890 +
17891 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17892 +{
17893 *pgdp = pgd;
17894 }
17895
17896 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17897 index 2d88344..4679fc3 100644
17898 --- a/arch/x86/include/asm/pgtable_64_types.h
17899 +++ b/arch/x86/include/asm/pgtable_64_types.h
17900 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17901 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17902 #define MODULES_END _AC(0xffffffffff000000, UL)
17903 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17904 +#define MODULES_EXEC_VADDR MODULES_VADDR
17905 +#define MODULES_EXEC_END MODULES_END
17906 +
17907 +#define ktla_ktva(addr) (addr)
17908 +#define ktva_ktla(addr) (addr)
17909
17910 #define EARLY_DYNAMIC_PAGE_TABLES 64
17911
17912 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17913 index 840c127..a8f297b 100644
17914 --- a/arch/x86/include/asm/pgtable_types.h
17915 +++ b/arch/x86/include/asm/pgtable_types.h
17916 @@ -16,13 +16,12 @@
17917 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17918 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17919 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17920 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17921 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17922 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17923 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17924 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17925 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17926 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17927 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17928 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17929 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17930 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17931
17932 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17933 @@ -40,7 +39,6 @@
17934 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17935 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17936 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17937 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17938 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17939 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17940 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17941 @@ -87,8 +85,10 @@
17942
17943 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17944 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17945 -#else
17946 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17947 #define _PAGE_NX (_AT(pteval_t, 0))
17948 +#else
17949 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17950 #endif
17951
17952 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17953 @@ -147,6 +147,9 @@
17954 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17955 _PAGE_ACCESSED)
17956
17957 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
17958 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
17959 +
17960 #define __PAGE_KERNEL_EXEC \
17961 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17962 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17963 @@ -157,7 +160,7 @@
17964 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17965 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17966 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17967 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17968 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17969 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17970 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17971 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17972 @@ -219,8 +222,8 @@
17973 * bits are combined, this will alow user to access the high address mapped
17974 * VDSO in the presence of CONFIG_COMPAT_VDSO
17975 */
17976 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17977 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17978 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17979 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17980 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17981 #endif
17982
17983 @@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17984 {
17985 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17986 }
17987 +#endif
17988
17989 +#if PAGETABLE_LEVELS == 3
17990 +#include <asm-generic/pgtable-nopud.h>
17991 +#endif
17992 +
17993 +#if PAGETABLE_LEVELS == 2
17994 +#include <asm-generic/pgtable-nopmd.h>
17995 +#endif
17996 +
17997 +#ifndef __ASSEMBLY__
17998 #if PAGETABLE_LEVELS > 3
17999 typedef struct { pudval_t pud; } pud_t;
18000
18001 @@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18002 return pud.pud;
18003 }
18004 #else
18005 -#include <asm-generic/pgtable-nopud.h>
18006 -
18007 static inline pudval_t native_pud_val(pud_t pud)
18008 {
18009 return native_pgd_val(pud.pgd);
18010 @@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18011 return pmd.pmd;
18012 }
18013 #else
18014 -#include <asm-generic/pgtable-nopmd.h>
18015 -
18016 static inline pmdval_t native_pmd_val(pmd_t pmd)
18017 {
18018 return native_pgd_val(pmd.pud.pgd);
18019 @@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18020
18021 extern pteval_t __supported_pte_mask;
18022 extern void set_nx(void);
18023 -extern int nx_enabled;
18024
18025 #define pgprot_writecombine pgprot_writecombine
18026 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18027 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18028 index c8b0519..fd29e73 100644
18029 --- a/arch/x86/include/asm/preempt.h
18030 +++ b/arch/x86/include/asm/preempt.h
18031 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18032 */
18033 static __always_inline bool __preempt_count_dec_and_test(void)
18034 {
18035 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18036 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18037 }
18038
18039 /*
18040 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18041 index 7b034a4..4fe3e3f 100644
18042 --- a/arch/x86/include/asm/processor.h
18043 +++ b/arch/x86/include/asm/processor.h
18044 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18045 /* Index into per_cpu list: */
18046 u16 cpu_index;
18047 u32 microcode;
18048 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18049 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18050
18051 #define X86_VENDOR_INTEL 0
18052 #define X86_VENDOR_CYRIX 1
18053 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18054 : "memory");
18055 }
18056
18057 +/* invpcid (%rdx),%rax */
18058 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18059 +
18060 +#define INVPCID_SINGLE_ADDRESS 0UL
18061 +#define INVPCID_SINGLE_CONTEXT 1UL
18062 +#define INVPCID_ALL_GLOBAL 2UL
18063 +#define INVPCID_ALL_MONGLOBAL 3UL
18064 +
18065 +#define PCID_KERNEL 0UL
18066 +#define PCID_USER 1UL
18067 +#define PCID_NOFLUSH (1UL << 63)
18068 +
18069 static inline void load_cr3(pgd_t *pgdir)
18070 {
18071 - write_cr3(__pa(pgdir));
18072 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18073 }
18074
18075 #ifdef CONFIG_X86_32
18076 @@ -283,7 +295,7 @@ struct tss_struct {
18077
18078 } ____cacheline_aligned;
18079
18080 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18081 +extern struct tss_struct init_tss[NR_CPUS];
18082
18083 /*
18084 * Save the original ist values for checking stack pointers during debugging
18085 @@ -453,6 +465,7 @@ struct thread_struct {
18086 unsigned short ds;
18087 unsigned short fsindex;
18088 unsigned short gsindex;
18089 + unsigned short ss;
18090 #endif
18091 #ifdef CONFIG_X86_32
18092 unsigned long ip;
18093 @@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
18094 extern unsigned long mmu_cr4_features;
18095 extern u32 *trampoline_cr4_features;
18096
18097 -static inline void set_in_cr4(unsigned long mask)
18098 -{
18099 - unsigned long cr4;
18100 -
18101 - mmu_cr4_features |= mask;
18102 - if (trampoline_cr4_features)
18103 - *trampoline_cr4_features = mmu_cr4_features;
18104 - cr4 = read_cr4();
18105 - cr4 |= mask;
18106 - write_cr4(cr4);
18107 -}
18108 -
18109 -static inline void clear_in_cr4(unsigned long mask)
18110 -{
18111 - unsigned long cr4;
18112 -
18113 - mmu_cr4_features &= ~mask;
18114 - if (trampoline_cr4_features)
18115 - *trampoline_cr4_features = mmu_cr4_features;
18116 - cr4 = read_cr4();
18117 - cr4 &= ~mask;
18118 - write_cr4(cr4);
18119 -}
18120 +extern void set_in_cr4(unsigned long mask);
18121 +extern void clear_in_cr4(unsigned long mask);
18122
18123 typedef struct {
18124 unsigned long seg;
18125 @@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
18126 */
18127 #define TASK_SIZE PAGE_OFFSET
18128 #define TASK_SIZE_MAX TASK_SIZE
18129 +
18130 +#ifdef CONFIG_PAX_SEGMEXEC
18131 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18132 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18133 +#else
18134 #define STACK_TOP TASK_SIZE
18135 -#define STACK_TOP_MAX STACK_TOP
18136 +#endif
18137 +
18138 +#define STACK_TOP_MAX TASK_SIZE
18139
18140 #define INIT_THREAD { \
18141 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18142 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18143 .vm86_info = NULL, \
18144 .sysenter_cs = __KERNEL_CS, \
18145 .io_bitmap_ptr = NULL, \
18146 @@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
18147 */
18148 #define INIT_TSS { \
18149 .x86_tss = { \
18150 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18151 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18152 .ss0 = __KERNEL_DS, \
18153 .ss1 = __KERNEL_CS, \
18154 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18155 @@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
18156 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18157
18158 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18159 -#define KSTK_TOP(info) \
18160 -({ \
18161 - unsigned long *__ptr = (unsigned long *)(info); \
18162 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18163 -})
18164 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18165
18166 /*
18167 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18168 @@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18169 #define task_pt_regs(task) \
18170 ({ \
18171 struct pt_regs *__regs__; \
18172 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18173 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18174 __regs__ - 1; \
18175 })
18176
18177 @@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18178 /*
18179 * User space process size. 47bits minus one guard page.
18180 */
18181 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18182 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18183
18184 /* This decides where the kernel will search for a free chunk of vm
18185 * space during mmap's.
18186 */
18187 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18188 - 0xc0000000 : 0xFFFFe000)
18189 + 0xc0000000 : 0xFFFFf000)
18190
18191 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18192 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18193 @@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18194 #define STACK_TOP_MAX TASK_SIZE_MAX
18195
18196 #define INIT_THREAD { \
18197 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18198 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18199 }
18200
18201 #define INIT_TSS { \
18202 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18203 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18204 }
18205
18206 /*
18207 @@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18208 */
18209 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18210
18211 +#ifdef CONFIG_PAX_SEGMEXEC
18212 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18213 +#endif
18214 +
18215 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18216
18217 /* Get/set a process' ability to use the timestamp counter instruction */
18218 @@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18219 return 0;
18220 }
18221
18222 -extern unsigned long arch_align_stack(unsigned long sp);
18223 +#define arch_align_stack(x) ((x) & ~0xfUL)
18224 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18225
18226 void default_idle(void);
18227 @@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
18228 #define xen_set_default_idle 0
18229 #endif
18230
18231 -void stop_this_cpu(void *dummy);
18232 +void stop_this_cpu(void *dummy) __noreturn;
18233 void df_debug(struct pt_regs *regs, long error_code);
18234 #endif /* _ASM_X86_PROCESSOR_H */
18235 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18236 index 942a086..6c26446 100644
18237 --- a/arch/x86/include/asm/ptrace.h
18238 +++ b/arch/x86/include/asm/ptrace.h
18239 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18240 }
18241
18242 /*
18243 - * user_mode_vm(regs) determines whether a register set came from user mode.
18244 + * user_mode(regs) determines whether a register set came from user mode.
18245 * This is true if V8086 mode was enabled OR if the register set was from
18246 * protected mode with RPL-3 CS value. This tricky test checks that with
18247 * one comparison. Many places in the kernel can bypass this full check
18248 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18249 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18250 + * be used.
18251 */
18252 -static inline int user_mode(struct pt_regs *regs)
18253 +static inline int user_mode_novm(struct pt_regs *regs)
18254 {
18255 #ifdef CONFIG_X86_32
18256 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18257 #else
18258 - return !!(regs->cs & 3);
18259 + return !!(regs->cs & SEGMENT_RPL_MASK);
18260 #endif
18261 }
18262
18263 -static inline int user_mode_vm(struct pt_regs *regs)
18264 +static inline int user_mode(struct pt_regs *regs)
18265 {
18266 #ifdef CONFIG_X86_32
18267 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18268 USER_RPL;
18269 #else
18270 - return user_mode(regs);
18271 + return user_mode_novm(regs);
18272 #endif
18273 }
18274
18275 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18276 #ifdef CONFIG_X86_64
18277 static inline bool user_64bit_mode(struct pt_regs *regs)
18278 {
18279 + unsigned long cs = regs->cs & 0xffff;
18280 #ifndef CONFIG_PARAVIRT
18281 /*
18282 * On non-paravirt systems, this is the only long mode CPL 3
18283 * selector. We do not allow long mode selectors in the LDT.
18284 */
18285 - return regs->cs == __USER_CS;
18286 + return cs == __USER_CS;
18287 #else
18288 /* Headers are too twisted for this to go in paravirt.h. */
18289 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18290 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18291 #endif
18292 }
18293
18294 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18295 * Traps from the kernel do not save sp and ss.
18296 * Use the helper function to retrieve sp.
18297 */
18298 - if (offset == offsetof(struct pt_regs, sp) &&
18299 - regs->cs == __KERNEL_CS)
18300 - return kernel_stack_pointer(regs);
18301 + if (offset == offsetof(struct pt_regs, sp)) {
18302 + unsigned long cs = regs->cs & 0xffff;
18303 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18304 + return kernel_stack_pointer(regs);
18305 + }
18306 #endif
18307 return *(unsigned long *)((unsigned long)regs + offset);
18308 }
18309 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18310 index 9c6b890..5305f53 100644
18311 --- a/arch/x86/include/asm/realmode.h
18312 +++ b/arch/x86/include/asm/realmode.h
18313 @@ -22,16 +22,14 @@ struct real_mode_header {
18314 #endif
18315 /* APM/BIOS reboot */
18316 u32 machine_real_restart_asm;
18317 -#ifdef CONFIG_X86_64
18318 u32 machine_real_restart_seg;
18319 -#endif
18320 };
18321
18322 /* This must match data at trampoline_32/64.S */
18323 struct trampoline_header {
18324 #ifdef CONFIG_X86_32
18325 u32 start;
18326 - u16 gdt_pad;
18327 + u16 boot_cs;
18328 u16 gdt_limit;
18329 u32 gdt_base;
18330 #else
18331 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18332 index a82c4f1..ac45053 100644
18333 --- a/arch/x86/include/asm/reboot.h
18334 +++ b/arch/x86/include/asm/reboot.h
18335 @@ -6,13 +6,13 @@
18336 struct pt_regs;
18337
18338 struct machine_ops {
18339 - void (*restart)(char *cmd);
18340 - void (*halt)(void);
18341 - void (*power_off)(void);
18342 + void (* __noreturn restart)(char *cmd);
18343 + void (* __noreturn halt)(void);
18344 + void (* __noreturn power_off)(void);
18345 void (*shutdown)(void);
18346 void (*crash_shutdown)(struct pt_regs *);
18347 - void (*emergency_restart)(void);
18348 -};
18349 + void (* __noreturn emergency_restart)(void);
18350 +} __no_const;
18351
18352 extern struct machine_ops machine_ops;
18353
18354 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18355 index 8f7866a..e442f20 100644
18356 --- a/arch/x86/include/asm/rmwcc.h
18357 +++ b/arch/x86/include/asm/rmwcc.h
18358 @@ -3,7 +3,34 @@
18359
18360 #ifdef CC_HAVE_ASM_GOTO
18361
18362 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18363 +#ifdef CONFIG_PAX_REFCOUNT
18364 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18365 +do { \
18366 + asm_volatile_goto (fullop \
18367 + ";jno 0f\n" \
18368 + fullantiop \
18369 + ";int $4\n0:\n" \
18370 + _ASM_EXTABLE(0b, 0b) \
18371 + ";j" cc " %l[cc_label]" \
18372 + : : "m" (var), ## __VA_ARGS__ \
18373 + : "memory" : cc_label); \
18374 + return 0; \
18375 +cc_label: \
18376 + return 1; \
18377 +} while (0)
18378 +#else
18379 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18380 +do { \
18381 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18382 + : : "m" (var), ## __VA_ARGS__ \
18383 + : "memory" : cc_label); \
18384 + return 0; \
18385 +cc_label: \
18386 + return 1; \
18387 +} while (0)
18388 +#endif
18389 +
18390 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18391 do { \
18392 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18393 : : "m" (var), ## __VA_ARGS__ \
18394 @@ -13,15 +40,46 @@ cc_label: \
18395 return 1; \
18396 } while (0)
18397
18398 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18399 - __GEN_RMWcc(op " " arg0, var, cc)
18400 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18401 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18402
18403 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18404 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18405 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18406 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18407 +
18408 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18409 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18410 +
18411 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18412 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18413
18414 #else /* !CC_HAVE_ASM_GOTO */
18415
18416 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18417 +#ifdef CONFIG_PAX_REFCOUNT
18418 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18419 +do { \
18420 + char c; \
18421 + asm volatile (fullop \
18422 + ";jno 0f\n" \
18423 + fullantiop \
18424 + ";int $4\n0:\n" \
18425 + _ASM_EXTABLE(0b, 0b) \
18426 + "; set" cc " %1" \
18427 + : "+m" (var), "=qm" (c) \
18428 + : __VA_ARGS__ : "memory"); \
18429 + return c != 0; \
18430 +} while (0)
18431 +#else
18432 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18433 +do { \
18434 + char c; \
18435 + asm volatile (fullop "; set" cc " %1" \
18436 + : "+m" (var), "=qm" (c) \
18437 + : __VA_ARGS__ : "memory"); \
18438 + return c != 0; \
18439 +} while (0)
18440 +#endif
18441 +
18442 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18443 do { \
18444 char c; \
18445 asm volatile (fullop "; set" cc " %1" \
18446 @@ -30,11 +88,17 @@ do { \
18447 return c != 0; \
18448 } while (0)
18449
18450 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18451 - __GEN_RMWcc(op " " arg0, var, cc)
18452 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18453 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18454 +
18455 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18456 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18457 +
18458 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18459 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18460
18461 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18462 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18463 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18464 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18465
18466 #endif /* CC_HAVE_ASM_GOTO */
18467
18468 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18469 index cad82c9..2e5c5c1 100644
18470 --- a/arch/x86/include/asm/rwsem.h
18471 +++ b/arch/x86/include/asm/rwsem.h
18472 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18473 {
18474 asm volatile("# beginning down_read\n\t"
18475 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18476 +
18477 +#ifdef CONFIG_PAX_REFCOUNT
18478 + "jno 0f\n"
18479 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18480 + "int $4\n0:\n"
18481 + _ASM_EXTABLE(0b, 0b)
18482 +#endif
18483 +
18484 /* adds 0x00000001 */
18485 " jns 1f\n"
18486 " call call_rwsem_down_read_failed\n"
18487 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18488 "1:\n\t"
18489 " mov %1,%2\n\t"
18490 " add %3,%2\n\t"
18491 +
18492 +#ifdef CONFIG_PAX_REFCOUNT
18493 + "jno 0f\n"
18494 + "sub %3,%2\n"
18495 + "int $4\n0:\n"
18496 + _ASM_EXTABLE(0b, 0b)
18497 +#endif
18498 +
18499 " jle 2f\n\t"
18500 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18501 " jnz 1b\n\t"
18502 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18503 long tmp;
18504 asm volatile("# beginning down_write\n\t"
18505 LOCK_PREFIX " xadd %1,(%2)\n\t"
18506 +
18507 +#ifdef CONFIG_PAX_REFCOUNT
18508 + "jno 0f\n"
18509 + "mov %1,(%2)\n"
18510 + "int $4\n0:\n"
18511 + _ASM_EXTABLE(0b, 0b)
18512 +#endif
18513 +
18514 /* adds 0xffff0001, returns the old value */
18515 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18516 /* was the active mask 0 before? */
18517 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18518 long tmp;
18519 asm volatile("# beginning __up_read\n\t"
18520 LOCK_PREFIX " xadd %1,(%2)\n\t"
18521 +
18522 +#ifdef CONFIG_PAX_REFCOUNT
18523 + "jno 0f\n"
18524 + "mov %1,(%2)\n"
18525 + "int $4\n0:\n"
18526 + _ASM_EXTABLE(0b, 0b)
18527 +#endif
18528 +
18529 /* subtracts 1, returns the old value */
18530 " jns 1f\n\t"
18531 " call call_rwsem_wake\n" /* expects old value in %edx */
18532 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18533 long tmp;
18534 asm volatile("# beginning __up_write\n\t"
18535 LOCK_PREFIX " xadd %1,(%2)\n\t"
18536 +
18537 +#ifdef CONFIG_PAX_REFCOUNT
18538 + "jno 0f\n"
18539 + "mov %1,(%2)\n"
18540 + "int $4\n0:\n"
18541 + _ASM_EXTABLE(0b, 0b)
18542 +#endif
18543 +
18544 /* subtracts 0xffff0001, returns the old value */
18545 " jns 1f\n\t"
18546 " call call_rwsem_wake\n" /* expects old value in %edx */
18547 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18548 {
18549 asm volatile("# beginning __downgrade_write\n\t"
18550 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18551 +
18552 +#ifdef CONFIG_PAX_REFCOUNT
18553 + "jno 0f\n"
18554 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18555 + "int $4\n0:\n"
18556 + _ASM_EXTABLE(0b, 0b)
18557 +#endif
18558 +
18559 /*
18560 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18561 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18562 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18563 */
18564 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18565 {
18566 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18567 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18568 +
18569 +#ifdef CONFIG_PAX_REFCOUNT
18570 + "jno 0f\n"
18571 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18572 + "int $4\n0:\n"
18573 + _ASM_EXTABLE(0b, 0b)
18574 +#endif
18575 +
18576 : "+m" (sem->count)
18577 : "er" (delta));
18578 }
18579 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18580 */
18581 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18582 {
18583 - return delta + xadd(&sem->count, delta);
18584 + return delta + xadd_check_overflow(&sem->count, delta);
18585 }
18586
18587 #endif /* __KERNEL__ */
18588 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18589 index 6f1c3a8..7744f19 100644
18590 --- a/arch/x86/include/asm/segment.h
18591 +++ b/arch/x86/include/asm/segment.h
18592 @@ -64,10 +64,15 @@
18593 * 26 - ESPFIX small SS
18594 * 27 - per-cpu [ offset to per-cpu data area ]
18595 * 28 - stack_canary-20 [ for stack protector ]
18596 - * 29 - unused
18597 - * 30 - unused
18598 + * 29 - PCI BIOS CS
18599 + * 30 - PCI BIOS DS
18600 * 31 - TSS for double fault handler
18601 */
18602 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18603 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18604 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18605 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18606 +
18607 #define GDT_ENTRY_TLS_MIN 6
18608 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18609
18610 @@ -79,6 +84,8 @@
18611
18612 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18613
18614 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18615 +
18616 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18617
18618 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18619 @@ -104,6 +111,12 @@
18620 #define __KERNEL_STACK_CANARY 0
18621 #endif
18622
18623 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18624 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18625 +
18626 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18627 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18628 +
18629 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18630
18631 /*
18632 @@ -141,7 +154,7 @@
18633 */
18634
18635 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18636 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18637 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18638
18639
18640 #else
18641 @@ -165,6 +178,8 @@
18642 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18643 #define __USER32_DS __USER_DS
18644
18645 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18646 +
18647 #define GDT_ENTRY_TSS 8 /* needs two entries */
18648 #define GDT_ENTRY_LDT 10 /* needs two entries */
18649 #define GDT_ENTRY_TLS_MIN 12
18650 @@ -173,6 +188,8 @@
18651 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18652 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18653
18654 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18655 +
18656 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18657 #define FS_TLS 0
18658 #define GS_TLS 1
18659 @@ -180,12 +197,14 @@
18660 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18661 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18662
18663 -#define GDT_ENTRIES 16
18664 +#define GDT_ENTRIES 17
18665
18666 #endif
18667
18668 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18669 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18670 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18671 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18672 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18673 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18674 #ifndef CONFIG_PARAVIRT
18675 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18676 {
18677 unsigned long __limit;
18678 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18679 - return __limit + 1;
18680 + return __limit;
18681 }
18682
18683 #endif /* !__ASSEMBLY__ */
18684 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18685 index 8d3120f..352b440 100644
18686 --- a/arch/x86/include/asm/smap.h
18687 +++ b/arch/x86/include/asm/smap.h
18688 @@ -25,11 +25,40 @@
18689
18690 #include <asm/alternative-asm.h>
18691
18692 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18693 +#define ASM_PAX_OPEN_USERLAND \
18694 + 661: jmp 663f; \
18695 + .pushsection .altinstr_replacement, "a" ; \
18696 + 662: pushq %rax; nop; \
18697 + .popsection ; \
18698 + .pushsection .altinstructions, "a" ; \
18699 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18700 + .popsection ; \
18701 + call __pax_open_userland; \
18702 + popq %rax; \
18703 + 663:
18704 +
18705 +#define ASM_PAX_CLOSE_USERLAND \
18706 + 661: jmp 663f; \
18707 + .pushsection .altinstr_replacement, "a" ; \
18708 + 662: pushq %rax; nop; \
18709 + .popsection; \
18710 + .pushsection .altinstructions, "a" ; \
18711 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18712 + .popsection; \
18713 + call __pax_close_userland; \
18714 + popq %rax; \
18715 + 663:
18716 +#else
18717 +#define ASM_PAX_OPEN_USERLAND
18718 +#define ASM_PAX_CLOSE_USERLAND
18719 +#endif
18720 +
18721 #ifdef CONFIG_X86_SMAP
18722
18723 #define ASM_CLAC \
18724 661: ASM_NOP3 ; \
18725 - .pushsection .altinstr_replacement, "ax" ; \
18726 + .pushsection .altinstr_replacement, "a" ; \
18727 662: __ASM_CLAC ; \
18728 .popsection ; \
18729 .pushsection .altinstructions, "a" ; \
18730 @@ -38,7 +67,7 @@
18731
18732 #define ASM_STAC \
18733 661: ASM_NOP3 ; \
18734 - .pushsection .altinstr_replacement, "ax" ; \
18735 + .pushsection .altinstr_replacement, "a" ; \
18736 662: __ASM_STAC ; \
18737 .popsection ; \
18738 .pushsection .altinstructions, "a" ; \
18739 @@ -56,6 +85,37 @@
18740
18741 #include <asm/alternative.h>
18742
18743 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18744 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18745 +
18746 +extern void __pax_open_userland(void);
18747 +static __always_inline unsigned long pax_open_userland(void)
18748 +{
18749 +
18750 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18751 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18752 + :
18753 + : [open] "i" (__pax_open_userland)
18754 + : "memory", "rax");
18755 +#endif
18756 +
18757 + return 0;
18758 +}
18759 +
18760 +extern void __pax_close_userland(void);
18761 +static __always_inline unsigned long pax_close_userland(void)
18762 +{
18763 +
18764 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18765 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18766 + :
18767 + : [close] "i" (__pax_close_userland)
18768 + : "memory", "rax");
18769 +#endif
18770 +
18771 + return 0;
18772 +}
18773 +
18774 #ifdef CONFIG_X86_SMAP
18775
18776 static __always_inline void clac(void)
18777 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18778 index 4137890..03fa172 100644
18779 --- a/arch/x86/include/asm/smp.h
18780 +++ b/arch/x86/include/asm/smp.h
18781 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18782 /* cpus sharing the last level cache: */
18783 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18784 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18785 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18786 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18787
18788 static inline struct cpumask *cpu_sibling_mask(int cpu)
18789 {
18790 @@ -79,7 +79,7 @@ struct smp_ops {
18791
18792 void (*send_call_func_ipi)(const struct cpumask *mask);
18793 void (*send_call_func_single_ipi)(int cpu);
18794 -};
18795 +} __no_const;
18796
18797 /* Globals due to paravirt */
18798 extern void set_cpu_sibling_map(int cpu);
18799 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18800 extern int safe_smp_processor_id(void);
18801
18802 #elif defined(CONFIG_X86_64_SMP)
18803 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18804 -
18805 -#define stack_smp_processor_id() \
18806 -({ \
18807 - struct thread_info *ti; \
18808 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18809 - ti->cpu; \
18810 -})
18811 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18812 +#define stack_smp_processor_id() raw_smp_processor_id()
18813 #define safe_smp_processor_id() smp_processor_id()
18814
18815 #endif
18816 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18817 index bf156de..1a782ab 100644
18818 --- a/arch/x86/include/asm/spinlock.h
18819 +++ b/arch/x86/include/asm/spinlock.h
18820 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18821 static inline void arch_read_lock(arch_rwlock_t *rw)
18822 {
18823 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18824 +
18825 +#ifdef CONFIG_PAX_REFCOUNT
18826 + "jno 0f\n"
18827 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18828 + "int $4\n0:\n"
18829 + _ASM_EXTABLE(0b, 0b)
18830 +#endif
18831 +
18832 "jns 1f\n"
18833 "call __read_lock_failed\n\t"
18834 "1:\n"
18835 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18836 static inline void arch_write_lock(arch_rwlock_t *rw)
18837 {
18838 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18839 +
18840 +#ifdef CONFIG_PAX_REFCOUNT
18841 + "jno 0f\n"
18842 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18843 + "int $4\n0:\n"
18844 + _ASM_EXTABLE(0b, 0b)
18845 +#endif
18846 +
18847 "jz 1f\n"
18848 "call __write_lock_failed\n\t"
18849 "1:\n"
18850 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18851
18852 static inline void arch_read_unlock(arch_rwlock_t *rw)
18853 {
18854 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18855 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18856 +
18857 +#ifdef CONFIG_PAX_REFCOUNT
18858 + "jno 0f\n"
18859 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18860 + "int $4\n0:\n"
18861 + _ASM_EXTABLE(0b, 0b)
18862 +#endif
18863 +
18864 :"+m" (rw->lock) : : "memory");
18865 }
18866
18867 static inline void arch_write_unlock(arch_rwlock_t *rw)
18868 {
18869 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18870 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18871 +
18872 +#ifdef CONFIG_PAX_REFCOUNT
18873 + "jno 0f\n"
18874 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18875 + "int $4\n0:\n"
18876 + _ASM_EXTABLE(0b, 0b)
18877 +#endif
18878 +
18879 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18880 }
18881
18882 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18883 index 6a99859..03cb807 100644
18884 --- a/arch/x86/include/asm/stackprotector.h
18885 +++ b/arch/x86/include/asm/stackprotector.h
18886 @@ -47,7 +47,7 @@
18887 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18888 */
18889 #define GDT_STACK_CANARY_INIT \
18890 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18891 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18892
18893 /*
18894 * Initialize the stackprotector canary value.
18895 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18896
18897 static inline void load_stack_canary_segment(void)
18898 {
18899 -#ifdef CONFIG_X86_32
18900 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18901 asm volatile ("mov %0, %%gs" : : "r" (0));
18902 #endif
18903 }
18904 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18905 index 70bbe39..4ae2bd4 100644
18906 --- a/arch/x86/include/asm/stacktrace.h
18907 +++ b/arch/x86/include/asm/stacktrace.h
18908 @@ -11,28 +11,20 @@
18909
18910 extern int kstack_depth_to_print;
18911
18912 -struct thread_info;
18913 +struct task_struct;
18914 struct stacktrace_ops;
18915
18916 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18917 - unsigned long *stack,
18918 - unsigned long bp,
18919 - const struct stacktrace_ops *ops,
18920 - void *data,
18921 - unsigned long *end,
18922 - int *graph);
18923 +typedef unsigned long walk_stack_t(struct task_struct *task,
18924 + void *stack_start,
18925 + unsigned long *stack,
18926 + unsigned long bp,
18927 + const struct stacktrace_ops *ops,
18928 + void *data,
18929 + unsigned long *end,
18930 + int *graph);
18931
18932 -extern unsigned long
18933 -print_context_stack(struct thread_info *tinfo,
18934 - unsigned long *stack, unsigned long bp,
18935 - const struct stacktrace_ops *ops, void *data,
18936 - unsigned long *end, int *graph);
18937 -
18938 -extern unsigned long
18939 -print_context_stack_bp(struct thread_info *tinfo,
18940 - unsigned long *stack, unsigned long bp,
18941 - const struct stacktrace_ops *ops, void *data,
18942 - unsigned long *end, int *graph);
18943 +extern walk_stack_t print_context_stack;
18944 +extern walk_stack_t print_context_stack_bp;
18945
18946 /* Generic stack tracer with callbacks */
18947
18948 @@ -40,7 +32,7 @@ struct stacktrace_ops {
18949 void (*address)(void *data, unsigned long address, int reliable);
18950 /* On negative return stop dumping */
18951 int (*stack)(void *data, char *name);
18952 - walk_stack_t walk_stack;
18953 + walk_stack_t *walk_stack;
18954 };
18955
18956 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18957 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18958 index d7f3b3b..3cc39f1 100644
18959 --- a/arch/x86/include/asm/switch_to.h
18960 +++ b/arch/x86/include/asm/switch_to.h
18961 @@ -108,7 +108,7 @@ do { \
18962 "call __switch_to\n\t" \
18963 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18964 __switch_canary \
18965 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
18966 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18967 "movq %%rax,%%rdi\n\t" \
18968 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18969 "jnz ret_from_fork\n\t" \
18970 @@ -119,7 +119,7 @@ do { \
18971 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18972 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18973 [_tif_fork] "i" (_TIF_FORK), \
18974 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
18975 + [thread_info] "m" (current_tinfo), \
18976 [current_task] "m" (current_task) \
18977 __switch_canary_iparam \
18978 : "memory", "cc" __EXTRA_CLOBBER)
18979 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18980 index 3ba3de4..6c113b2 100644
18981 --- a/arch/x86/include/asm/thread_info.h
18982 +++ b/arch/x86/include/asm/thread_info.h
18983 @@ -10,6 +10,7 @@
18984 #include <linux/compiler.h>
18985 #include <asm/page.h>
18986 #include <asm/types.h>
18987 +#include <asm/percpu.h>
18988
18989 /*
18990 * low level task data that entry.S needs immediate access to
18991 @@ -23,7 +24,6 @@ struct exec_domain;
18992 #include <linux/atomic.h>
18993
18994 struct thread_info {
18995 - struct task_struct *task; /* main task structure */
18996 struct exec_domain *exec_domain; /* execution domain */
18997 __u32 flags; /* low level flags */
18998 __u32 status; /* thread synchronous flags */
18999 @@ -32,19 +32,13 @@ struct thread_info {
19000 mm_segment_t addr_limit;
19001 struct restart_block restart_block;
19002 void __user *sysenter_return;
19003 -#ifdef CONFIG_X86_32
19004 - unsigned long previous_esp; /* ESP of the previous stack in
19005 - case of nested (IRQ) stacks
19006 - */
19007 - __u8 supervisor_stack[0];
19008 -#endif
19009 + unsigned long lowest_stack;
19010 unsigned int sig_on_uaccess_error:1;
19011 unsigned int uaccess_err:1; /* uaccess failed */
19012 };
19013
19014 -#define INIT_THREAD_INFO(tsk) \
19015 +#define INIT_THREAD_INFO \
19016 { \
19017 - .task = &tsk, \
19018 .exec_domain = &default_exec_domain, \
19019 .flags = 0, \
19020 .cpu = 0, \
19021 @@ -55,7 +49,7 @@ struct thread_info {
19022 }, \
19023 }
19024
19025 -#define init_thread_info (init_thread_union.thread_info)
19026 +#define init_thread_info (init_thread_union.stack)
19027 #define init_stack (init_thread_union.stack)
19028
19029 #else /* !__ASSEMBLY__ */
19030 @@ -95,6 +89,7 @@ struct thread_info {
19031 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19032 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19033 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19034 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19035
19036 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19037 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19038 @@ -118,17 +113,18 @@ struct thread_info {
19039 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19040 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19041 #define _TIF_X32 (1 << TIF_X32)
19042 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19043
19044 /* work to do in syscall_trace_enter() */
19045 #define _TIF_WORK_SYSCALL_ENTRY \
19046 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19047 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19048 - _TIF_NOHZ)
19049 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19050
19051 /* work to do in syscall_trace_leave() */
19052 #define _TIF_WORK_SYSCALL_EXIT \
19053 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19054 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19055 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19056
19057 /* work to do on interrupt/exception return */
19058 #define _TIF_WORK_MASK \
19059 @@ -139,7 +135,7 @@ struct thread_info {
19060 /* work to do on any return to user space */
19061 #define _TIF_ALLWORK_MASK \
19062 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19063 - _TIF_NOHZ)
19064 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19065
19066 /* Only used for 64 bit */
19067 #define _TIF_DO_NOTIFY_MASK \
19068 @@ -153,45 +149,40 @@ struct thread_info {
19069 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19070 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19071
19072 -#ifdef CONFIG_X86_32
19073 -
19074 -#define STACK_WARN (THREAD_SIZE/8)
19075 -/*
19076 - * macros/functions for gaining access to the thread information structure
19077 - *
19078 - * preempt_count needs to be 1 initially, until the scheduler is functional.
19079 - */
19080 -#ifndef __ASSEMBLY__
19081 -
19082 -
19083 -/* how to get the current stack pointer from C */
19084 -register unsigned long current_stack_pointer asm("esp") __used;
19085 -
19086 -/* how to get the thread information struct from C */
19087 -static inline struct thread_info *current_thread_info(void)
19088 -{
19089 - return (struct thread_info *)
19090 - (current_stack_pointer & ~(THREAD_SIZE - 1));
19091 -}
19092 -
19093 -#else /* !__ASSEMBLY__ */
19094 -
19095 +#ifdef __ASSEMBLY__
19096 /* how to get the thread information struct from ASM */
19097 #define GET_THREAD_INFO(reg) \
19098 - movl $-THREAD_SIZE, reg; \
19099 - andl %esp, reg
19100 + mov PER_CPU_VAR(current_tinfo), reg
19101
19102 /* use this one if reg already contains %esp */
19103 -#define GET_THREAD_INFO_WITH_ESP(reg) \
19104 - andl $-THREAD_SIZE, reg
19105 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19106 +#else
19107 +/* how to get the thread information struct from C */
19108 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19109 +
19110 +static __always_inline struct thread_info *current_thread_info(void)
19111 +{
19112 + return this_cpu_read_stable(current_tinfo);
19113 +}
19114 +#endif
19115 +
19116 +#ifdef CONFIG_X86_32
19117 +
19118 +#define STACK_WARN (THREAD_SIZE/8)
19119 +/*
19120 + * macros/functions for gaining access to the thread information structure
19121 + *
19122 + * preempt_count needs to be 1 initially, until the scheduler is functional.
19123 + */
19124 +#ifndef __ASSEMBLY__
19125 +
19126 +/* how to get the current stack pointer from C */
19127 +register unsigned long current_stack_pointer asm("esp") __used;
19128
19129 #endif
19130
19131 #else /* X86_32 */
19132
19133 -#include <asm/percpu.h>
19134 -#define KERNEL_STACK_OFFSET (5*8)
19135 -
19136 /*
19137 * macros/functions for gaining access to the thread information structure
19138 * preempt_count needs to be 1 initially, until the scheduler is functional.
19139 @@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
19140 #ifndef __ASSEMBLY__
19141 DECLARE_PER_CPU(unsigned long, kernel_stack);
19142
19143 -static inline struct thread_info *current_thread_info(void)
19144 -{
19145 - struct thread_info *ti;
19146 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19147 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19148 - return ti;
19149 -}
19150 -
19151 -#else /* !__ASSEMBLY__ */
19152 -
19153 -/* how to get the thread information struct from ASM */
19154 -#define GET_THREAD_INFO(reg) \
19155 - movq PER_CPU_VAR(kernel_stack),reg ; \
19156 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19157 -
19158 -/*
19159 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19160 - * a certain register (to be used in assembler memory operands).
19161 - */
19162 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19163 -
19164 +/* how to get the current stack pointer from C */
19165 +register unsigned long current_stack_pointer asm("rsp") __used;
19166 #endif
19167
19168 #endif /* !X86_32 */
19169 @@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
19170 extern void arch_task_cache_init(void);
19171 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19172 extern void arch_release_task_struct(struct task_struct *tsk);
19173 +
19174 +#define __HAVE_THREAD_FUNCTIONS
19175 +#define task_thread_info(task) (&(task)->tinfo)
19176 +#define task_stack_page(task) ((task)->stack)
19177 +#define setup_thread_stack(p, org) do {} while (0)
19178 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19179 +
19180 #endif
19181 #endif /* _ASM_X86_THREAD_INFO_H */
19182 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19183 index e6d90ba..f81f114 100644
19184 --- a/arch/x86/include/asm/tlbflush.h
19185 +++ b/arch/x86/include/asm/tlbflush.h
19186 @@ -17,18 +17,44 @@
19187
19188 static inline void __native_flush_tlb(void)
19189 {
19190 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19191 + u64 descriptor[2];
19192 +
19193 + descriptor[0] = PCID_KERNEL;
19194 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19195 + return;
19196 + }
19197 +
19198 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19199 + if (static_cpu_has(X86_FEATURE_PCID)) {
19200 + unsigned int cpu = raw_get_cpu();
19201 +
19202 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19203 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19204 + raw_put_cpu_no_resched();
19205 + return;
19206 + }
19207 +#endif
19208 +
19209 native_write_cr3(native_read_cr3());
19210 }
19211
19212 static inline void __native_flush_tlb_global_irq_disabled(void)
19213 {
19214 - unsigned long cr4;
19215 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19216 + u64 descriptor[2];
19217
19218 - cr4 = native_read_cr4();
19219 - /* clear PGE */
19220 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19221 - /* write old PGE again and flush TLBs */
19222 - native_write_cr4(cr4);
19223 + descriptor[0] = PCID_KERNEL;
19224 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19225 + } else {
19226 + unsigned long cr4;
19227 +
19228 + cr4 = native_read_cr4();
19229 + /* clear PGE */
19230 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19231 + /* write old PGE again and flush TLBs */
19232 + native_write_cr4(cr4);
19233 + }
19234 }
19235
19236 static inline void __native_flush_tlb_global(void)
19237 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19238
19239 static inline void __native_flush_tlb_single(unsigned long addr)
19240 {
19241 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19242 + u64 descriptor[2];
19243 +
19244 + descriptor[0] = PCID_KERNEL;
19245 + descriptor[1] = addr;
19246 +
19247 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19248 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19249 + if (addr < TASK_SIZE_MAX)
19250 + descriptor[1] += pax_user_shadow_base;
19251 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19252 + }
19253 +
19254 + descriptor[0] = PCID_USER;
19255 + descriptor[1] = addr;
19256 +#endif
19257 +
19258 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19259 + return;
19260 + }
19261 +
19262 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19263 + if (static_cpu_has(X86_FEATURE_PCID)) {
19264 + unsigned int cpu = raw_get_cpu();
19265 +
19266 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19267 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19268 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19269 + raw_put_cpu_no_resched();
19270 +
19271 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19272 + addr += pax_user_shadow_base;
19273 + }
19274 +#endif
19275 +
19276 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19277 }
19278
19279 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19280 index 8ec57c0..451bcfc 100644
19281 --- a/arch/x86/include/asm/uaccess.h
19282 +++ b/arch/x86/include/asm/uaccess.h
19283 @@ -7,6 +7,7 @@
19284 #include <linux/compiler.h>
19285 #include <linux/thread_info.h>
19286 #include <linux/string.h>
19287 +#include <linux/spinlock.h>
19288 #include <asm/asm.h>
19289 #include <asm/page.h>
19290 #include <asm/smap.h>
19291 @@ -29,7 +30,12 @@
19292
19293 #define get_ds() (KERNEL_DS)
19294 #define get_fs() (current_thread_info()->addr_limit)
19295 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19296 +void __set_fs(mm_segment_t x);
19297 +void set_fs(mm_segment_t x);
19298 +#else
19299 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19300 +#endif
19301
19302 #define segment_eq(a, b) ((a).seg == (b).seg)
19303
19304 @@ -77,8 +83,34 @@
19305 * checks that the pointer is in the user space range - after calling
19306 * this function, memory access functions may still return -EFAULT.
19307 */
19308 -#define access_ok(type, addr, size) \
19309 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19310 +extern int _cond_resched(void);
19311 +#define access_ok_noprefault(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19312 +#define access_ok(type, addr, size) \
19313 +({ \
19314 + long __size = size; \
19315 + unsigned long __addr = (unsigned long)addr; \
19316 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19317 + unsigned long __end_ao = __addr + __size - 1; \
19318 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19319 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19320 + while(__addr_ao <= __end_ao) { \
19321 + char __c_ao; \
19322 + __addr_ao += PAGE_SIZE; \
19323 + if (__size > PAGE_SIZE) \
19324 + _cond_resched(); \
19325 + if (__get_user(__c_ao, (char __user *)__addr)) \
19326 + break; \
19327 + if (type != VERIFY_WRITE) { \
19328 + __addr = __addr_ao; \
19329 + continue; \
19330 + } \
19331 + if (__put_user(__c_ao, (char __user *)__addr)) \
19332 + break; \
19333 + __addr = __addr_ao; \
19334 + } \
19335 + } \
19336 + __ret_ao; \
19337 +})
19338
19339 /*
19340 * The exception table consists of pairs of addresses relative to the
19341 @@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19342 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19343 __chk_user_ptr(ptr); \
19344 might_fault(); \
19345 + pax_open_userland(); \
19346 asm volatile("call __get_user_%P3" \
19347 : "=a" (__ret_gu), "=r" (__val_gu) \
19348 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19349 (x) = (__typeof__(*(ptr))) __val_gu; \
19350 + pax_close_userland(); \
19351 __ret_gu; \
19352 })
19353
19354 @@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19355 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19356 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19357
19358 -
19359 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19360 +#define __copyuser_seg "gs;"
19361 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19362 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19363 +#else
19364 +#define __copyuser_seg
19365 +#define __COPYUSER_SET_ES
19366 +#define __COPYUSER_RESTORE_ES
19367 +#endif
19368
19369 #ifdef CONFIG_X86_32
19370 #define __put_user_asm_u64(x, addr, err, errret) \
19371 asm volatile(ASM_STAC "\n" \
19372 - "1: movl %%eax,0(%2)\n" \
19373 - "2: movl %%edx,4(%2)\n" \
19374 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19375 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19376 "3: " ASM_CLAC "\n" \
19377 ".section .fixup,\"ax\"\n" \
19378 "4: movl %3,%0\n" \
19379 @@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19380
19381 #define __put_user_asm_ex_u64(x, addr) \
19382 asm volatile(ASM_STAC "\n" \
19383 - "1: movl %%eax,0(%1)\n" \
19384 - "2: movl %%edx,4(%1)\n" \
19385 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19386 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19387 "3: " ASM_CLAC "\n" \
19388 _ASM_EXTABLE_EX(1b, 2b) \
19389 _ASM_EXTABLE_EX(2b, 3b) \
19390 @@ -249,7 +291,8 @@ extern void __put_user_8(void);
19391 __typeof__(*(ptr)) __pu_val; \
19392 __chk_user_ptr(ptr); \
19393 might_fault(); \
19394 - __pu_val = x; \
19395 + __pu_val = (x); \
19396 + pax_open_userland(); \
19397 switch (sizeof(*(ptr))) { \
19398 case 1: \
19399 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19400 @@ -267,6 +310,7 @@ extern void __put_user_8(void);
19401 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19402 break; \
19403 } \
19404 + pax_close_userland(); \
19405 __ret_pu; \
19406 })
19407
19408 @@ -347,8 +391,10 @@ do { \
19409 } while (0)
19410
19411 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19412 +do { \
19413 + pax_open_userland(); \
19414 asm volatile(ASM_STAC "\n" \
19415 - "1: mov"itype" %2,%"rtype"1\n" \
19416 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19417 "2: " ASM_CLAC "\n" \
19418 ".section .fixup,\"ax\"\n" \
19419 "3: mov %3,%0\n" \
19420 @@ -356,8 +402,10 @@ do { \
19421 " jmp 2b\n" \
19422 ".previous\n" \
19423 _ASM_EXTABLE(1b, 3b) \
19424 - : "=r" (err), ltype(x) \
19425 - : "m" (__m(addr)), "i" (errret), "0" (err))
19426 + : "=r" (err), ltype (x) \
19427 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19428 + pax_close_userland(); \
19429 +} while (0)
19430
19431 #define __get_user_size_ex(x, ptr, size) \
19432 do { \
19433 @@ -381,7 +429,7 @@ do { \
19434 } while (0)
19435
19436 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19437 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19438 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19439 "2:\n" \
19440 _ASM_EXTABLE_EX(1b, 2b) \
19441 : ltype(x) : "m" (__m(addr)))
19442 @@ -398,13 +446,24 @@ do { \
19443 int __gu_err; \
19444 unsigned long __gu_val; \
19445 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19446 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19447 + (x) = (__typeof__(*(ptr)))__gu_val; \
19448 __gu_err; \
19449 })
19450
19451 /* FIXME: this hack is definitely wrong -AK */
19452 struct __large_struct { unsigned long buf[100]; };
19453 -#define __m(x) (*(struct __large_struct __user *)(x))
19454 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19455 +#define ____m(x) \
19456 +({ \
19457 + unsigned long ____x = (unsigned long)(x); \
19458 + if (____x < pax_user_shadow_base) \
19459 + ____x += pax_user_shadow_base; \
19460 + (typeof(x))____x; \
19461 +})
19462 +#else
19463 +#define ____m(x) (x)
19464 +#endif
19465 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19466
19467 /*
19468 * Tell gcc we read from memory instead of writing: this is because
19469 @@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
19470 * aliasing issues.
19471 */
19472 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19473 +do { \
19474 + pax_open_userland(); \
19475 asm volatile(ASM_STAC "\n" \
19476 - "1: mov"itype" %"rtype"1,%2\n" \
19477 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19478 "2: " ASM_CLAC "\n" \
19479 ".section .fixup,\"ax\"\n" \
19480 "3: mov %3,%0\n" \
19481 @@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
19482 ".previous\n" \
19483 _ASM_EXTABLE(1b, 3b) \
19484 : "=r"(err) \
19485 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19486 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19487 + pax_close_userland(); \
19488 +} while (0)
19489
19490 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19491 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19492 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19493 "2:\n" \
19494 _ASM_EXTABLE_EX(1b, 2b) \
19495 : : ltype(x), "m" (__m(addr)))
19496 @@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
19497 */
19498 #define uaccess_try do { \
19499 current_thread_info()->uaccess_err = 0; \
19500 + pax_open_userland(); \
19501 stac(); \
19502 barrier();
19503
19504 #define uaccess_catch(err) \
19505 clac(); \
19506 + pax_close_userland(); \
19507 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19508 } while (0)
19509
19510 @@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
19511 * On error, the variable @x is set to zero.
19512 */
19513
19514 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19515 +#define __get_user(x, ptr) get_user((x), (ptr))
19516 +#else
19517 #define __get_user(x, ptr) \
19518 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19519 +#endif
19520
19521 /**
19522 * __put_user: - Write a simple value into user space, with less checking.
19523 @@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
19524 * Returns zero on success, or -EFAULT on error.
19525 */
19526
19527 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19528 +#define __put_user(x, ptr) put_user((x), (ptr))
19529 +#else
19530 #define __put_user(x, ptr) \
19531 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19532 +#endif
19533
19534 #define __get_user_unaligned __get_user
19535 #define __put_user_unaligned __put_user
19536 @@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19537 #define get_user_ex(x, ptr) do { \
19538 unsigned long __gue_val; \
19539 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19540 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19541 + (x) = (__typeof__(*(ptr)))__gue_val; \
19542 } while (0)
19543
19544 #define put_user_try uaccess_try
19545 @@ -536,17 +609,6 @@ extern struct movsl_mask {
19546
19547 #define ARCH_HAS_NOCACHE_UACCESS 1
19548
19549 -#ifdef CONFIG_X86_32
19550 -# include <asm/uaccess_32.h>
19551 -#else
19552 -# include <asm/uaccess_64.h>
19553 -#endif
19554 -
19555 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19556 - unsigned n);
19557 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19558 - unsigned n);
19559 -
19560 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19561 # define copy_user_diag __compiletime_error
19562 #else
19563 @@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19564 extern void copy_user_diag("copy_from_user() buffer size is too small")
19565 copy_from_user_overflow(void);
19566 extern void copy_user_diag("copy_to_user() buffer size is too small")
19567 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19568 +copy_to_user_overflow(void);
19569
19570 #undef copy_user_diag
19571
19572 @@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19573
19574 extern void
19575 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19576 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19577 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19578 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19579
19580 #else
19581 @@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19582
19583 #endif
19584
19585 +#ifdef CONFIG_X86_32
19586 +# include <asm/uaccess_32.h>
19587 +#else
19588 +# include <asm/uaccess_64.h>
19589 +#endif
19590 +
19591 static inline unsigned long __must_check
19592 copy_from_user(void *to, const void __user *from, unsigned long n)
19593 {
19594 - int sz = __compiletime_object_size(to);
19595 + size_t sz = __compiletime_object_size(to);
19596
19597 might_fault();
19598
19599 @@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19600 * case, and do only runtime checking for non-constant sizes.
19601 */
19602
19603 - if (likely(sz < 0 || sz >= n))
19604 - n = _copy_from_user(to, from, n);
19605 - else if(__builtin_constant_p(n))
19606 - copy_from_user_overflow();
19607 - else
19608 - __copy_from_user_overflow(sz, n);
19609 + if (likely(sz != (size_t)-1 && sz < n)) {
19610 + if(__builtin_constant_p(n))
19611 + copy_from_user_overflow();
19612 + else
19613 + __copy_from_user_overflow(sz, n);
19614 + } if (access_ok(VERIFY_READ, from, n))
19615 + n = __copy_from_user(to, from, n);
19616 + else if ((long)n > 0)
19617 + memset(to, 0, n);
19618
19619 return n;
19620 }
19621 @@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19622 static inline unsigned long __must_check
19623 copy_to_user(void __user *to, const void *from, unsigned long n)
19624 {
19625 - int sz = __compiletime_object_size(from);
19626 + size_t sz = __compiletime_object_size(from);
19627
19628 might_fault();
19629
19630 /* See the comment in copy_from_user() above. */
19631 - if (likely(sz < 0 || sz >= n))
19632 - n = _copy_to_user(to, from, n);
19633 - else if(__builtin_constant_p(n))
19634 - copy_to_user_overflow();
19635 - else
19636 - __copy_to_user_overflow(sz, n);
19637 + if (likely(sz != (size_t)-1 && sz < n)) {
19638 + if(__builtin_constant_p(n))
19639 + copy_to_user_overflow();
19640 + else
19641 + __copy_to_user_overflow(sz, n);
19642 + } else if (access_ok(VERIFY_WRITE, to, n))
19643 + n = __copy_to_user(to, from, n);
19644
19645 return n;
19646 }
19647 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19648 index 3c03a5d..1071638 100644
19649 --- a/arch/x86/include/asm/uaccess_32.h
19650 +++ b/arch/x86/include/asm/uaccess_32.h
19651 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19652 static __always_inline unsigned long __must_check
19653 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19654 {
19655 + if ((long)n < 0)
19656 + return n;
19657 +
19658 + check_object_size(from, n, true);
19659 +
19660 if (__builtin_constant_p(n)) {
19661 unsigned long ret;
19662
19663 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19664 __copy_to_user(void __user *to, const void *from, unsigned long n)
19665 {
19666 might_fault();
19667 +
19668 return __copy_to_user_inatomic(to, from, n);
19669 }
19670
19671 static __always_inline unsigned long
19672 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19673 {
19674 + if ((long)n < 0)
19675 + return n;
19676 +
19677 /* Avoid zeroing the tail if the copy fails..
19678 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19679 * but as the zeroing behaviour is only significant when n is not
19680 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19681 __copy_from_user(void *to, const void __user *from, unsigned long n)
19682 {
19683 might_fault();
19684 +
19685 + if ((long)n < 0)
19686 + return n;
19687 +
19688 + check_object_size(to, n, false);
19689 +
19690 if (__builtin_constant_p(n)) {
19691 unsigned long ret;
19692
19693 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19694 const void __user *from, unsigned long n)
19695 {
19696 might_fault();
19697 +
19698 + if ((long)n < 0)
19699 + return n;
19700 +
19701 if (__builtin_constant_p(n)) {
19702 unsigned long ret;
19703
19704 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19705 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19706 unsigned long n)
19707 {
19708 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19709 + if ((long)n < 0)
19710 + return n;
19711 +
19712 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19713 }
19714
19715 #endif /* _ASM_X86_UACCESS_32_H */
19716 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19717 index 190413d..206c200 100644
19718 --- a/arch/x86/include/asm/uaccess_64.h
19719 +++ b/arch/x86/include/asm/uaccess_64.h
19720 @@ -10,6 +10,9 @@
19721 #include <asm/alternative.h>
19722 #include <asm/cpufeature.h>
19723 #include <asm/page.h>
19724 +#include <asm/pgtable.h>
19725 +
19726 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19727
19728 /*
19729 * Copy To/From Userspace
19730 @@ -17,14 +20,14 @@
19731
19732 /* Handles exceptions in both to and from, but doesn't do access_ok */
19733 __must_check unsigned long
19734 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19735 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19736 __must_check unsigned long
19737 -copy_user_generic_string(void *to, const void *from, unsigned len);
19738 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19739 __must_check unsigned long
19740 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19741 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19742
19743 static __always_inline __must_check unsigned long
19744 -copy_user_generic(void *to, const void *from, unsigned len)
19745 +copy_user_generic(void *to, const void *from, unsigned long len)
19746 {
19747 unsigned ret;
19748
19749 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19750 }
19751
19752 __must_check unsigned long
19753 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19754 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19755
19756 static __always_inline __must_check
19757 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19758 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19759 {
19760 - int ret = 0;
19761 + size_t sz = __compiletime_object_size(dst);
19762 + unsigned ret = 0;
19763 +
19764 + if (size > INT_MAX)
19765 + return size;
19766 +
19767 + check_object_size(dst, size, false);
19768 +
19769 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19770 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19771 + return size;
19772 +#endif
19773 +
19774 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19775 + if(__builtin_constant_p(size))
19776 + copy_from_user_overflow();
19777 + else
19778 + __copy_from_user_overflow(sz, size);
19779 + return size;
19780 + }
19781
19782 if (!__builtin_constant_p(size))
19783 - return copy_user_generic(dst, (__force void *)src, size);
19784 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19785 switch (size) {
19786 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19787 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19788 ret, "b", "b", "=q", 1);
19789 return ret;
19790 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19791 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19792 ret, "w", "w", "=r", 2);
19793 return ret;
19794 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19795 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19796 ret, "l", "k", "=r", 4);
19797 return ret;
19798 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19799 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19800 ret, "q", "", "=r", 8);
19801 return ret;
19802 case 10:
19803 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19804 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19805 ret, "q", "", "=r", 10);
19806 if (unlikely(ret))
19807 return ret;
19808 __get_user_asm(*(u16 *)(8 + (char *)dst),
19809 - (u16 __user *)(8 + (char __user *)src),
19810 + (const u16 __user *)(8 + (const char __user *)src),
19811 ret, "w", "w", "=r", 2);
19812 return ret;
19813 case 16:
19814 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19815 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19816 ret, "q", "", "=r", 16);
19817 if (unlikely(ret))
19818 return ret;
19819 __get_user_asm(*(u64 *)(8 + (char *)dst),
19820 - (u64 __user *)(8 + (char __user *)src),
19821 + (const u64 __user *)(8 + (const char __user *)src),
19822 ret, "q", "", "=r", 8);
19823 return ret;
19824 default:
19825 - return copy_user_generic(dst, (__force void *)src, size);
19826 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19827 }
19828 }
19829
19830 static __always_inline __must_check
19831 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19832 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19833 {
19834 might_fault();
19835 return __copy_from_user_nocheck(dst, src, size);
19836 }
19837
19838 static __always_inline __must_check
19839 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19840 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19841 {
19842 - int ret = 0;
19843 + size_t sz = __compiletime_object_size(src);
19844 + unsigned ret = 0;
19845 +
19846 + if (size > INT_MAX)
19847 + return size;
19848 +
19849 + check_object_size(src, size, true);
19850 +
19851 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19852 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19853 + return size;
19854 +#endif
19855 +
19856 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19857 + if(__builtin_constant_p(size))
19858 + copy_to_user_overflow();
19859 + else
19860 + __copy_to_user_overflow(sz, size);
19861 + return size;
19862 + }
19863
19864 if (!__builtin_constant_p(size))
19865 - return copy_user_generic((__force void *)dst, src, size);
19866 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19867 switch (size) {
19868 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19869 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19870 ret, "b", "b", "iq", 1);
19871 return ret;
19872 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19873 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19874 ret, "w", "w", "ir", 2);
19875 return ret;
19876 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19877 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19878 ret, "l", "k", "ir", 4);
19879 return ret;
19880 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19881 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19882 ret, "q", "", "er", 8);
19883 return ret;
19884 case 10:
19885 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19886 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19887 ret, "q", "", "er", 10);
19888 if (unlikely(ret))
19889 return ret;
19890 asm("":::"memory");
19891 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19892 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19893 ret, "w", "w", "ir", 2);
19894 return ret;
19895 case 16:
19896 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19897 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19898 ret, "q", "", "er", 16);
19899 if (unlikely(ret))
19900 return ret;
19901 asm("":::"memory");
19902 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19903 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19904 ret, "q", "", "er", 8);
19905 return ret;
19906 default:
19907 - return copy_user_generic((__force void *)dst, src, size);
19908 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19909 }
19910 }
19911
19912 static __always_inline __must_check
19913 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
19914 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19915 {
19916 might_fault();
19917 return __copy_to_user_nocheck(dst, src, size);
19918 }
19919
19920 static __always_inline __must_check
19921 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19922 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19923 {
19924 - int ret = 0;
19925 + unsigned ret = 0;
19926
19927 might_fault();
19928 +
19929 + if (size > INT_MAX)
19930 + return size;
19931 +
19932 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19933 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19934 + return size;
19935 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19936 + return size;
19937 +#endif
19938 +
19939 if (!__builtin_constant_p(size))
19940 - return copy_user_generic((__force void *)dst,
19941 - (__force void *)src, size);
19942 + return copy_user_generic((__force_kernel void *)____m(dst),
19943 + (__force_kernel const void *)____m(src), size);
19944 switch (size) {
19945 case 1: {
19946 u8 tmp;
19947 - __get_user_asm(tmp, (u8 __user *)src,
19948 + __get_user_asm(tmp, (const u8 __user *)src,
19949 ret, "b", "b", "=q", 1);
19950 if (likely(!ret))
19951 __put_user_asm(tmp, (u8 __user *)dst,
19952 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19953 }
19954 case 2: {
19955 u16 tmp;
19956 - __get_user_asm(tmp, (u16 __user *)src,
19957 + __get_user_asm(tmp, (const u16 __user *)src,
19958 ret, "w", "w", "=r", 2);
19959 if (likely(!ret))
19960 __put_user_asm(tmp, (u16 __user *)dst,
19961 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19962
19963 case 4: {
19964 u32 tmp;
19965 - __get_user_asm(tmp, (u32 __user *)src,
19966 + __get_user_asm(tmp, (const u32 __user *)src,
19967 ret, "l", "k", "=r", 4);
19968 if (likely(!ret))
19969 __put_user_asm(tmp, (u32 __user *)dst,
19970 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19971 }
19972 case 8: {
19973 u64 tmp;
19974 - __get_user_asm(tmp, (u64 __user *)src,
19975 + __get_user_asm(tmp, (const u64 __user *)src,
19976 ret, "q", "", "=r", 8);
19977 if (likely(!ret))
19978 __put_user_asm(tmp, (u64 __user *)dst,
19979 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19980 return ret;
19981 }
19982 default:
19983 - return copy_user_generic((__force void *)dst,
19984 - (__force void *)src, size);
19985 + return copy_user_generic((__force_kernel void *)____m(dst),
19986 + (__force_kernel const void *)____m(src), size);
19987 }
19988 }
19989
19990 -static __must_check __always_inline int
19991 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19992 +static __must_check __always_inline unsigned long
19993 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19994 {
19995 - return __copy_from_user_nocheck(dst, (__force const void *)src, size);
19996 + return __copy_from_user_nocheck(dst, src, size);
19997 }
19998
19999 -static __must_check __always_inline int
20000 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20001 +static __must_check __always_inline unsigned long
20002 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20003 {
20004 - return __copy_to_user_nocheck((__force void *)dst, src, size);
20005 + return __copy_to_user_nocheck(dst, src, size);
20006 }
20007
20008 -extern long __copy_user_nocache(void *dst, const void __user *src,
20009 - unsigned size, int zerorest);
20010 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20011 + unsigned long size, int zerorest);
20012
20013 -static inline int
20014 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20015 +static inline unsigned long
20016 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20017 {
20018 might_fault();
20019 +
20020 + if (size > INT_MAX)
20021 + return size;
20022 +
20023 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20024 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20025 + return size;
20026 +#endif
20027 +
20028 return __copy_user_nocache(dst, src, size, 1);
20029 }
20030
20031 -static inline int
20032 +static inline unsigned long
20033 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20034 - unsigned size)
20035 + unsigned long size)
20036 {
20037 + if (size > INT_MAX)
20038 + return size;
20039 +
20040 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20041 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20042 + return size;
20043 +#endif
20044 +
20045 return __copy_user_nocache(dst, src, size, 0);
20046 }
20047
20048 unsigned long
20049 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20050 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20051
20052 #endif /* _ASM_X86_UACCESS_64_H */
20053 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20054 index 5b238981..77fdd78 100644
20055 --- a/arch/x86/include/asm/word-at-a-time.h
20056 +++ b/arch/x86/include/asm/word-at-a-time.h
20057 @@ -11,7 +11,7 @@
20058 * and shift, for example.
20059 */
20060 struct word_at_a_time {
20061 - const unsigned long one_bits, high_bits;
20062 + unsigned long one_bits, high_bits;
20063 };
20064
20065 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20066 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20067 index 0f1be11..f7542bf 100644
20068 --- a/arch/x86/include/asm/x86_init.h
20069 +++ b/arch/x86/include/asm/x86_init.h
20070 @@ -129,7 +129,7 @@ struct x86_init_ops {
20071 struct x86_init_timers timers;
20072 struct x86_init_iommu iommu;
20073 struct x86_init_pci pci;
20074 -};
20075 +} __no_const;
20076
20077 /**
20078 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20079 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20080 void (*setup_percpu_clockev)(void);
20081 void (*early_percpu_clock_init)(void);
20082 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20083 -};
20084 +} __no_const;
20085
20086 struct timespec;
20087
20088 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20089 void (*save_sched_clock_state)(void);
20090 void (*restore_sched_clock_state)(void);
20091 void (*apic_post_init)(void);
20092 -};
20093 +} __no_const;
20094
20095 struct pci_dev;
20096 struct msi_msg;
20097 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20098 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20099 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20100 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20101 -};
20102 +} __no_const;
20103
20104 struct IO_APIC_route_entry;
20105 struct io_apic_irq_attr;
20106 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20107 unsigned int destination, int vector,
20108 struct io_apic_irq_attr *attr);
20109 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20110 -};
20111 +} __no_const;
20112
20113 extern struct x86_init_ops x86_init;
20114 extern struct x86_cpuinit_ops x86_cpuinit;
20115 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20116 index b913915..4f5a581 100644
20117 --- a/arch/x86/include/asm/xen/page.h
20118 +++ b/arch/x86/include/asm/xen/page.h
20119 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20120 extern struct page *m2p_find_override(unsigned long mfn);
20121 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20122
20123 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20124 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20125 {
20126 unsigned long mfn;
20127
20128 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20129 index 0415cda..3b22adc 100644
20130 --- a/arch/x86/include/asm/xsave.h
20131 +++ b/arch/x86/include/asm/xsave.h
20132 @@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20133 if (unlikely(err))
20134 return -EFAULT;
20135
20136 + pax_open_userland();
20137 __asm__ __volatile__(ASM_STAC "\n"
20138 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20139 + "1:"
20140 + __copyuser_seg
20141 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20142 "2: " ASM_CLAC "\n"
20143 ".section .fixup,\"ax\"\n"
20144 "3: movl $-1,%[err]\n"
20145 @@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20146 : [err] "=r" (err)
20147 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20148 : "memory");
20149 + pax_close_userland();
20150 return err;
20151 }
20152
20153 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20154 {
20155 int err;
20156 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20157 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20158 u32 lmask = mask;
20159 u32 hmask = mask >> 32;
20160
20161 + pax_open_userland();
20162 __asm__ __volatile__(ASM_STAC "\n"
20163 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20164 + "1:"
20165 + __copyuser_seg
20166 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20167 "2: " ASM_CLAC "\n"
20168 ".section .fixup,\"ax\"\n"
20169 "3: movl $-1,%[err]\n"
20170 @@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20171 : [err] "=r" (err)
20172 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20173 : "memory"); /* memory required? */
20174 + pax_close_userland();
20175 return err;
20176 }
20177
20178 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20179 index bbae024..e1528f9 100644
20180 --- a/arch/x86/include/uapi/asm/e820.h
20181 +++ b/arch/x86/include/uapi/asm/e820.h
20182 @@ -63,7 +63,7 @@ struct e820map {
20183 #define ISA_START_ADDRESS 0xa0000
20184 #define ISA_END_ADDRESS 0x100000
20185
20186 -#define BIOS_BEGIN 0x000a0000
20187 +#define BIOS_BEGIN 0x000c0000
20188 #define BIOS_END 0x00100000
20189
20190 #define BIOS_ROM_BASE 0xffe00000
20191 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20192 index 7b0a55a..ad115bf 100644
20193 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20194 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20195 @@ -49,7 +49,6 @@
20196 #define EFLAGS 144
20197 #define RSP 152
20198 #define SS 160
20199 -#define ARGOFFSET R11
20200 #endif /* __ASSEMBLY__ */
20201
20202 /* top of stack page */
20203 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20204 index 9b0a34e..fc7e553 100644
20205 --- a/arch/x86/kernel/Makefile
20206 +++ b/arch/x86/kernel/Makefile
20207 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20208 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20209 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20210 obj-y += probe_roms.o
20211 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20212 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20213 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20214 obj-y += syscall_$(BITS).o
20215 obj-$(CONFIG_X86_64) += vsyscall_64.o
20216 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20217 index 6c0b43b..e67bb31 100644
20218 --- a/arch/x86/kernel/acpi/boot.c
20219 +++ b/arch/x86/kernel/acpi/boot.c
20220 @@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20221 * If your system is blacklisted here, but you find that acpi=force
20222 * works for you, please contact linux-acpi@vger.kernel.org
20223 */
20224 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20225 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20226 /*
20227 * Boxes that need ACPI disabled
20228 */
20229 @@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20230 };
20231
20232 /* second table for DMI checks that should run after early-quirks */
20233 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20234 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20235 /*
20236 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20237 * which includes some code which overrides all temperature
20238 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20239 index 3a2ae4c..9db31d6 100644
20240 --- a/arch/x86/kernel/acpi/sleep.c
20241 +++ b/arch/x86/kernel/acpi/sleep.c
20242 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20243 #else /* CONFIG_64BIT */
20244 #ifdef CONFIG_SMP
20245 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20246 +
20247 + pax_open_kernel();
20248 early_gdt_descr.address =
20249 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20250 + pax_close_kernel();
20251 +
20252 initial_gs = per_cpu_offset(smp_processor_id());
20253 #endif
20254 initial_code = (unsigned long)wakeup_long64;
20255 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20256 index 665c6b7..eae4d56 100644
20257 --- a/arch/x86/kernel/acpi/wakeup_32.S
20258 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20259 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20260 # and restore the stack ... but you need gdt for this to work
20261 movl saved_context_esp, %esp
20262
20263 - movl %cs:saved_magic, %eax
20264 - cmpl $0x12345678, %eax
20265 + cmpl $0x12345678, saved_magic
20266 jne bogus_magic
20267
20268 # jump to place where we left off
20269 - movl saved_eip, %eax
20270 - jmp *%eax
20271 + jmp *(saved_eip)
20272
20273 bogus_magic:
20274 jmp bogus_magic
20275 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20276 index df94598..f3b29bf 100644
20277 --- a/arch/x86/kernel/alternative.c
20278 +++ b/arch/x86/kernel/alternative.c
20279 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20280 */
20281 for (a = start; a < end; a++) {
20282 instr = (u8 *)&a->instr_offset + a->instr_offset;
20283 +
20284 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20285 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20286 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20287 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20288 +#endif
20289 +
20290 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20291 BUG_ON(a->replacementlen > a->instrlen);
20292 BUG_ON(a->instrlen > sizeof(insnbuf));
20293 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20294 for (poff = start; poff < end; poff++) {
20295 u8 *ptr = (u8 *)poff + *poff;
20296
20297 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20298 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20299 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20300 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20301 +#endif
20302 +
20303 if (!*poff || ptr < text || ptr >= text_end)
20304 continue;
20305 /* turn DS segment override prefix into lock prefix */
20306 - if (*ptr == 0x3e)
20307 + if (*ktla_ktva(ptr) == 0x3e)
20308 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20309 }
20310 mutex_unlock(&text_mutex);
20311 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20312 for (poff = start; poff < end; poff++) {
20313 u8 *ptr = (u8 *)poff + *poff;
20314
20315 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20316 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20317 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20318 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20319 +#endif
20320 +
20321 if (!*poff || ptr < text || ptr >= text_end)
20322 continue;
20323 /* turn lock prefix into DS segment override prefix */
20324 - if (*ptr == 0xf0)
20325 + if (*ktla_ktva(ptr) == 0xf0)
20326 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20327 }
20328 mutex_unlock(&text_mutex);
20329 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20330
20331 BUG_ON(p->len > MAX_PATCH_LEN);
20332 /* prep the buffer with the original instructions */
20333 - memcpy(insnbuf, p->instr, p->len);
20334 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20335 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20336 (unsigned long)p->instr, p->len);
20337
20338 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20339 if (!uniproc_patched || num_possible_cpus() == 1)
20340 free_init_pages("SMP alternatives",
20341 (unsigned long)__smp_locks,
20342 - (unsigned long)__smp_locks_end);
20343 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20344 #endif
20345
20346 apply_paravirt(__parainstructions, __parainstructions_end);
20347 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20348 * instructions. And on the local CPU you need to be protected again NMI or MCE
20349 * handlers seeing an inconsistent instruction while you patch.
20350 */
20351 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20352 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20353 size_t len)
20354 {
20355 unsigned long flags;
20356 local_irq_save(flags);
20357 - memcpy(addr, opcode, len);
20358 +
20359 + pax_open_kernel();
20360 + memcpy(ktla_ktva(addr), opcode, len);
20361 sync_core();
20362 + pax_close_kernel();
20363 +
20364 local_irq_restore(flags);
20365 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20366 that causes hangs on some VIA CPUs. */
20367 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20368 */
20369 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20370 {
20371 - unsigned long flags;
20372 - char *vaddr;
20373 + unsigned char *vaddr = ktla_ktva(addr);
20374 struct page *pages[2];
20375 - int i;
20376 + size_t i;
20377
20378 if (!core_kernel_text((unsigned long)addr)) {
20379 - pages[0] = vmalloc_to_page(addr);
20380 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20381 + pages[0] = vmalloc_to_page(vaddr);
20382 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20383 } else {
20384 - pages[0] = virt_to_page(addr);
20385 + pages[0] = virt_to_page(vaddr);
20386 WARN_ON(!PageReserved(pages[0]));
20387 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20388 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20389 }
20390 BUG_ON(!pages[0]);
20391 - local_irq_save(flags);
20392 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20393 - if (pages[1])
20394 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20395 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20396 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20397 - clear_fixmap(FIX_TEXT_POKE0);
20398 - if (pages[1])
20399 - clear_fixmap(FIX_TEXT_POKE1);
20400 - local_flush_tlb();
20401 - sync_core();
20402 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20403 - that causes hangs on some VIA CPUs. */
20404 + text_poke_early(addr, opcode, len);
20405 for (i = 0; i < len; i++)
20406 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20407 - local_irq_restore(flags);
20408 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20409 return addr;
20410 }
20411
20412 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20413 if (likely(!bp_patching_in_progress))
20414 return 0;
20415
20416 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20417 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20418 return 0;
20419
20420 /* set up the specified breakpoint handler */
20421 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20422 */
20423 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20424 {
20425 - unsigned char int3 = 0xcc;
20426 + const unsigned char int3 = 0xcc;
20427
20428 bp_int3_handler = handler;
20429 bp_int3_addr = (u8 *)addr + sizeof(int3);
20430 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20431 index d278736..0b4af9a8 100644
20432 --- a/arch/x86/kernel/apic/apic.c
20433 +++ b/arch/x86/kernel/apic/apic.c
20434 @@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
20435 /*
20436 * Debug level, exported for io_apic.c
20437 */
20438 -unsigned int apic_verbosity;
20439 +int apic_verbosity;
20440
20441 int pic_mode;
20442
20443 @@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20444 apic_write(APIC_ESR, 0);
20445 v1 = apic_read(APIC_ESR);
20446 ack_APIC_irq();
20447 - atomic_inc(&irq_err_count);
20448 + atomic_inc_unchecked(&irq_err_count);
20449
20450 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
20451 smp_processor_id(), v0 , v1);
20452 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20453 index 00c77cf..2dc6a2d 100644
20454 --- a/arch/x86/kernel/apic/apic_flat_64.c
20455 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20456 @@ -157,7 +157,7 @@ static int flat_probe(void)
20457 return 1;
20458 }
20459
20460 -static struct apic apic_flat = {
20461 +static struct apic apic_flat __read_only = {
20462 .name = "flat",
20463 .probe = flat_probe,
20464 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20465 @@ -271,7 +271,7 @@ static int physflat_probe(void)
20466 return 0;
20467 }
20468
20469 -static struct apic apic_physflat = {
20470 +static struct apic apic_physflat __read_only = {
20471
20472 .name = "physical flat",
20473 .probe = physflat_probe,
20474 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20475 index e145f28..2752888 100644
20476 --- a/arch/x86/kernel/apic/apic_noop.c
20477 +++ b/arch/x86/kernel/apic/apic_noop.c
20478 @@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
20479 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20480 }
20481
20482 -struct apic apic_noop = {
20483 +struct apic apic_noop __read_only = {
20484 .name = "noop",
20485 .probe = noop_probe,
20486 .acpi_madt_oem_check = NULL,
20487 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20488 index d50e364..543bee3 100644
20489 --- a/arch/x86/kernel/apic/bigsmp_32.c
20490 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20491 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20492 return dmi_bigsmp;
20493 }
20494
20495 -static struct apic apic_bigsmp = {
20496 +static struct apic apic_bigsmp __read_only = {
20497
20498 .name = "bigsmp",
20499 .probe = probe_bigsmp,
20500 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20501 index c552247..587a316 100644
20502 --- a/arch/x86/kernel/apic/es7000_32.c
20503 +++ b/arch/x86/kernel/apic/es7000_32.c
20504 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20505 return ret && es7000_apic_is_cluster();
20506 }
20507
20508 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20509 -static struct apic __refdata apic_es7000_cluster = {
20510 +static struct apic apic_es7000_cluster __read_only = {
20511
20512 .name = "es7000",
20513 .probe = probe_es7000,
20514 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20515 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20516 };
20517
20518 -static struct apic __refdata apic_es7000 = {
20519 +static struct apic apic_es7000 __read_only = {
20520
20521 .name = "es7000",
20522 .probe = probe_es7000,
20523 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20524 index e63a5bd..c0babf8 100644
20525 --- a/arch/x86/kernel/apic/io_apic.c
20526 +++ b/arch/x86/kernel/apic/io_apic.c
20527 @@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20528 }
20529 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20530
20531 -void lock_vector_lock(void)
20532 +void lock_vector_lock(void) __acquires(vector_lock)
20533 {
20534 /* Used to the online set of cpus does not change
20535 * during assign_irq_vector.
20536 @@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20537 raw_spin_lock(&vector_lock);
20538 }
20539
20540 -void unlock_vector_lock(void)
20541 +void unlock_vector_lock(void) __releases(vector_lock)
20542 {
20543 raw_spin_unlock(&vector_lock);
20544 }
20545 @@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20546 ack_APIC_irq();
20547 }
20548
20549 -atomic_t irq_mis_count;
20550 +atomic_unchecked_t irq_mis_count;
20551
20552 #ifdef CONFIG_GENERIC_PENDING_IRQ
20553 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20554 @@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20555 * at the cpu.
20556 */
20557 if (!(v & (1 << (i & 0x1f)))) {
20558 - atomic_inc(&irq_mis_count);
20559 + atomic_inc_unchecked(&irq_mis_count);
20560
20561 eoi_ioapic_irq(irq, cfg);
20562 }
20563 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20564 index 1e42e8f..daacf44 100644
20565 --- a/arch/x86/kernel/apic/numaq_32.c
20566 +++ b/arch/x86/kernel/apic/numaq_32.c
20567 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20568 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20569 }
20570
20571 -/* Use __refdata to keep false positive warning calm. */
20572 -static struct apic __refdata apic_numaq = {
20573 +static struct apic apic_numaq __read_only = {
20574
20575 .name = "NUMAQ",
20576 .probe = probe_numaq,
20577 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20578 index eb35ef9..f184a21 100644
20579 --- a/arch/x86/kernel/apic/probe_32.c
20580 +++ b/arch/x86/kernel/apic/probe_32.c
20581 @@ -72,7 +72,7 @@ static int probe_default(void)
20582 return 1;
20583 }
20584
20585 -static struct apic apic_default = {
20586 +static struct apic apic_default __read_only = {
20587
20588 .name = "default",
20589 .probe = probe_default,
20590 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20591 index 77c95c0..434f8a4 100644
20592 --- a/arch/x86/kernel/apic/summit_32.c
20593 +++ b/arch/x86/kernel/apic/summit_32.c
20594 @@ -486,7 +486,7 @@ void setup_summit(void)
20595 }
20596 #endif
20597
20598 -static struct apic apic_summit = {
20599 +static struct apic apic_summit __read_only = {
20600
20601 .name = "summit",
20602 .probe = probe_summit,
20603 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20604 index 140e29d..d88bc95 100644
20605 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20606 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20607 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20608 return notifier_from_errno(err);
20609 }
20610
20611 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20612 +static struct notifier_block x2apic_cpu_notifier = {
20613 .notifier_call = update_clusterinfo,
20614 };
20615
20616 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20617 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20618 }
20619
20620 -static struct apic apic_x2apic_cluster = {
20621 +static struct apic apic_x2apic_cluster __read_only = {
20622
20623 .name = "cluster x2apic",
20624 .probe = x2apic_cluster_probe,
20625 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20626 index 562a76d..a003c0f 100644
20627 --- a/arch/x86/kernel/apic/x2apic_phys.c
20628 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20629 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20630 return apic == &apic_x2apic_phys;
20631 }
20632
20633 -static struct apic apic_x2apic_phys = {
20634 +static struct apic apic_x2apic_phys __read_only = {
20635
20636 .name = "physical x2apic",
20637 .probe = x2apic_phys_probe,
20638 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20639 index ad0dc04..0d9cc56 100644
20640 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20641 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20642 @@ -350,7 +350,7 @@ static int uv_probe(void)
20643 return apic == &apic_x2apic_uv_x;
20644 }
20645
20646 -static struct apic __refdata apic_x2apic_uv_x = {
20647 +static struct apic apic_x2apic_uv_x __read_only = {
20648
20649 .name = "UV large system",
20650 .probe = uv_probe,
20651 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20652 index 3ab0343..814c4787 100644
20653 --- a/arch/x86/kernel/apm_32.c
20654 +++ b/arch/x86/kernel/apm_32.c
20655 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20656 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20657 * even though they are called in protected mode.
20658 */
20659 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20660 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20661 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20662
20663 static const char driver_version[] = "1.16ac"; /* no spaces */
20664 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20665 BUG_ON(cpu != 0);
20666 gdt = get_cpu_gdt_table(cpu);
20667 save_desc_40 = gdt[0x40 / 8];
20668 +
20669 + pax_open_kernel();
20670 gdt[0x40 / 8] = bad_bios_desc;
20671 + pax_close_kernel();
20672
20673 apm_irq_save(flags);
20674 APM_DO_SAVE_SEGS;
20675 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20676 &call->esi);
20677 APM_DO_RESTORE_SEGS;
20678 apm_irq_restore(flags);
20679 +
20680 + pax_open_kernel();
20681 gdt[0x40 / 8] = save_desc_40;
20682 + pax_close_kernel();
20683 +
20684 put_cpu();
20685
20686 return call->eax & 0xff;
20687 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20688 BUG_ON(cpu != 0);
20689 gdt = get_cpu_gdt_table(cpu);
20690 save_desc_40 = gdt[0x40 / 8];
20691 +
20692 + pax_open_kernel();
20693 gdt[0x40 / 8] = bad_bios_desc;
20694 + pax_close_kernel();
20695
20696 apm_irq_save(flags);
20697 APM_DO_SAVE_SEGS;
20698 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20699 &call->eax);
20700 APM_DO_RESTORE_SEGS;
20701 apm_irq_restore(flags);
20702 +
20703 + pax_open_kernel();
20704 gdt[0x40 / 8] = save_desc_40;
20705 + pax_close_kernel();
20706 +
20707 put_cpu();
20708 return error;
20709 }
20710 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20711 * code to that CPU.
20712 */
20713 gdt = get_cpu_gdt_table(0);
20714 +
20715 + pax_open_kernel();
20716 set_desc_base(&gdt[APM_CS >> 3],
20717 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20718 set_desc_base(&gdt[APM_CS_16 >> 3],
20719 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20720 set_desc_base(&gdt[APM_DS >> 3],
20721 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20722 + pax_close_kernel();
20723
20724 proc_create("apm", 0, NULL, &apm_file_ops);
20725
20726 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20727 index 9f6b934..cf5ffb3 100644
20728 --- a/arch/x86/kernel/asm-offsets.c
20729 +++ b/arch/x86/kernel/asm-offsets.c
20730 @@ -32,6 +32,8 @@ void common(void) {
20731 OFFSET(TI_flags, thread_info, flags);
20732 OFFSET(TI_status, thread_info, status);
20733 OFFSET(TI_addr_limit, thread_info, addr_limit);
20734 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20735 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20736
20737 BLANK();
20738 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20739 @@ -52,8 +54,26 @@ void common(void) {
20740 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20741 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20742 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20743 +
20744 +#ifdef CONFIG_PAX_KERNEXEC
20745 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20746 #endif
20747
20748 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20749 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20750 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20751 +#ifdef CONFIG_X86_64
20752 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20753 +#endif
20754 +#endif
20755 +
20756 +#endif
20757 +
20758 + BLANK();
20759 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20760 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20761 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20762 +
20763 #ifdef CONFIG_XEN
20764 BLANK();
20765 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20766 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20767 index e7c798b..2b2019b 100644
20768 --- a/arch/x86/kernel/asm-offsets_64.c
20769 +++ b/arch/x86/kernel/asm-offsets_64.c
20770 @@ -77,6 +77,7 @@ int main(void)
20771 BLANK();
20772 #undef ENTRY
20773
20774 + DEFINE(TSS_size, sizeof(struct tss_struct));
20775 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20776 BLANK();
20777
20778 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20779 index 47b56a7..efc2bc6 100644
20780 --- a/arch/x86/kernel/cpu/Makefile
20781 +++ b/arch/x86/kernel/cpu/Makefile
20782 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20783 CFLAGS_REMOVE_perf_event.o = -pg
20784 endif
20785
20786 -# Make sure load_percpu_segment has no stackprotector
20787 -nostackp := $(call cc-option, -fno-stack-protector)
20788 -CFLAGS_common.o := $(nostackp)
20789 -
20790 obj-y := intel_cacheinfo.o scattered.o topology.o
20791 obj-y += proc.o capflags.o powerflags.o common.o
20792 obj-y += rdrand.o
20793 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20794 index 59bfebc..d8f27bd 100644
20795 --- a/arch/x86/kernel/cpu/amd.c
20796 +++ b/arch/x86/kernel/cpu/amd.c
20797 @@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20798 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20799 {
20800 /* AMD errata T13 (order #21922) */
20801 - if ((c->x86 == 6)) {
20802 + if (c->x86 == 6) {
20803 /* Duron Rev A0 */
20804 if (c->x86_model == 3 && c->x86_mask == 0)
20805 size = 64;
20806 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20807 index fe2bdd0..77b0d1b 100644
20808 --- a/arch/x86/kernel/cpu/common.c
20809 +++ b/arch/x86/kernel/cpu/common.c
20810 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20811
20812 static const struct cpu_dev *this_cpu = &default_cpu;
20813
20814 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20815 -#ifdef CONFIG_X86_64
20816 - /*
20817 - * We need valid kernel segments for data and code in long mode too
20818 - * IRET will check the segment types kkeil 2000/10/28
20819 - * Also sysret mandates a special GDT layout
20820 - *
20821 - * TLS descriptors are currently at a different place compared to i386.
20822 - * Hopefully nobody expects them at a fixed place (Wine?)
20823 - */
20824 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20825 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20826 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20827 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20828 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20829 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20830 -#else
20831 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20832 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20833 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20834 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20835 - /*
20836 - * Segments used for calling PnP BIOS have byte granularity.
20837 - * They code segments and data segments have fixed 64k limits,
20838 - * the transfer segment sizes are set at run time.
20839 - */
20840 - /* 32-bit code */
20841 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20842 - /* 16-bit code */
20843 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20844 - /* 16-bit data */
20845 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20846 - /* 16-bit data */
20847 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20848 - /* 16-bit data */
20849 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20850 - /*
20851 - * The APM segments have byte granularity and their bases
20852 - * are set at run time. All have 64k limits.
20853 - */
20854 - /* 32-bit code */
20855 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20856 - /* 16-bit code */
20857 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20858 - /* data */
20859 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20860 -
20861 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20862 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20863 - GDT_STACK_CANARY_INIT
20864 -#endif
20865 -} };
20866 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20867 -
20868 static int __init x86_xsave_setup(char *s)
20869 {
20870 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20871 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20872 }
20873 }
20874
20875 +#ifdef CONFIG_X86_64
20876 +static __init int setup_disable_pcid(char *arg)
20877 +{
20878 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20879 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20880 +
20881 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20882 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20883 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20884 +#endif
20885 +
20886 + return 1;
20887 +}
20888 +__setup("nopcid", setup_disable_pcid);
20889 +
20890 +static void setup_pcid(struct cpuinfo_x86 *c)
20891 +{
20892 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20893 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20894 +
20895 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20896 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20897 + pax_open_kernel();
20898 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20899 + pax_close_kernel();
20900 + printk("PAX: slow and weak UDEREF enabled\n");
20901 + } else
20902 + printk("PAX: UDEREF disabled\n");
20903 +#endif
20904 +
20905 + return;
20906 + }
20907 +
20908 + printk("PAX: PCID detected\n");
20909 + set_in_cr4(X86_CR4_PCIDE);
20910 +
20911 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20912 + pax_open_kernel();
20913 + clone_pgd_mask = ~(pgdval_t)0UL;
20914 + pax_close_kernel();
20915 + if (pax_user_shadow_base)
20916 + printk("PAX: weak UDEREF enabled\n");
20917 + else {
20918 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20919 + printk("PAX: strong UDEREF enabled\n");
20920 + }
20921 +#endif
20922 +
20923 + if (cpu_has(c, X86_FEATURE_INVPCID))
20924 + printk("PAX: INVPCID detected\n");
20925 +}
20926 +#endif
20927 +
20928 /*
20929 * Some CPU features depend on higher CPUID levels, which may not always
20930 * be available due to CPUID level capping or broken virtualization
20931 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20932 {
20933 struct desc_ptr gdt_descr;
20934
20935 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20936 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20937 gdt_descr.size = GDT_SIZE - 1;
20938 load_gdt(&gdt_descr);
20939 /* Reload the per-cpu base */
20940 @@ -882,6 +881,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20941 setup_smep(c);
20942 setup_smap(c);
20943
20944 +#ifdef CONFIG_X86_64
20945 + setup_pcid(c);
20946 +#endif
20947 +
20948 /*
20949 * The vendor-specific functions might have changed features.
20950 * Now we do "generic changes."
20951 @@ -890,6 +893,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20952 /* Filter out anything that depends on CPUID levels we don't have */
20953 filter_cpuid_features(c, true);
20954
20955 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20956 + setup_clear_cpu_cap(X86_FEATURE_SEP);
20957 +#endif
20958 +
20959 /* If the model name is still unset, do table lookup. */
20960 if (!c->x86_model_id[0]) {
20961 const char *p;
20962 @@ -1077,10 +1084,12 @@ static __init int setup_disablecpuid(char *arg)
20963 }
20964 __setup("clearcpuid=", setup_disablecpuid);
20965
20966 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20967 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
20968 +
20969 #ifdef CONFIG_X86_64
20970 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20971 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20972 - (unsigned long) debug_idt_table };
20973 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20974 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20975
20976 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20977 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20978 @@ -1094,7 +1103,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20979 EXPORT_PER_CPU_SYMBOL(current_task);
20980
20981 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20982 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20983 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20984 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20985
20986 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20987 @@ -1244,7 +1253,7 @@ void cpu_init(void)
20988 load_ucode_ap();
20989
20990 cpu = stack_smp_processor_id();
20991 - t = &per_cpu(init_tss, cpu);
20992 + t = init_tss + cpu;
20993 oist = &per_cpu(orig_ist, cpu);
20994
20995 #ifdef CONFIG_NUMA
20996 @@ -1279,7 +1288,6 @@ void cpu_init(void)
20997 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20998 barrier();
20999
21000 - x86_configure_nx();
21001 enable_x2apic();
21002
21003 /*
21004 @@ -1331,7 +1339,7 @@ void cpu_init(void)
21005 {
21006 int cpu = smp_processor_id();
21007 struct task_struct *curr = current;
21008 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21009 + struct tss_struct *t = init_tss + cpu;
21010 struct thread_struct *thread = &curr->thread;
21011
21012 show_ucode_info_early();
21013 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21014 index 0641113..06f5ba4 100644
21015 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21016 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21017 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21018 };
21019
21020 #ifdef CONFIG_AMD_NB
21021 +static struct attribute *default_attrs_amd_nb[] = {
21022 + &type.attr,
21023 + &level.attr,
21024 + &coherency_line_size.attr,
21025 + &physical_line_partition.attr,
21026 + &ways_of_associativity.attr,
21027 + &number_of_sets.attr,
21028 + &size.attr,
21029 + &shared_cpu_map.attr,
21030 + &shared_cpu_list.attr,
21031 + NULL,
21032 + NULL,
21033 + NULL,
21034 + NULL
21035 +};
21036 +
21037 static struct attribute **amd_l3_attrs(void)
21038 {
21039 static struct attribute **attrs;
21040 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21041
21042 n = ARRAY_SIZE(default_attrs);
21043
21044 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21045 - n += 2;
21046 -
21047 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21048 - n += 1;
21049 -
21050 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21051 - if (attrs == NULL)
21052 - return attrs = default_attrs;
21053 -
21054 - for (n = 0; default_attrs[n]; n++)
21055 - attrs[n] = default_attrs[n];
21056 + attrs = default_attrs_amd_nb;
21057
21058 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21059 attrs[n++] = &cache_disable_0.attr;
21060 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21061 .default_attrs = default_attrs,
21062 };
21063
21064 +#ifdef CONFIG_AMD_NB
21065 +static struct kobj_type ktype_cache_amd_nb = {
21066 + .sysfs_ops = &sysfs_ops,
21067 + .default_attrs = default_attrs_amd_nb,
21068 +};
21069 +#endif
21070 +
21071 static struct kobj_type ktype_percpu_entry = {
21072 .sysfs_ops = &sysfs_ops,
21073 };
21074 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21075 return retval;
21076 }
21077
21078 +#ifdef CONFIG_AMD_NB
21079 + amd_l3_attrs();
21080 +#endif
21081 +
21082 for (i = 0; i < num_cache_leaves; i++) {
21083 + struct kobj_type *ktype;
21084 +
21085 this_object = INDEX_KOBJECT_PTR(cpu, i);
21086 this_object->cpu = cpu;
21087 this_object->index = i;
21088
21089 this_leaf = CPUID4_INFO_IDX(cpu, i);
21090
21091 - ktype_cache.default_attrs = default_attrs;
21092 + ktype = &ktype_cache;
21093 #ifdef CONFIG_AMD_NB
21094 if (this_leaf->base.nb)
21095 - ktype_cache.default_attrs = amd_l3_attrs();
21096 + ktype = &ktype_cache_amd_nb;
21097 #endif
21098 retval = kobject_init_and_add(&(this_object->kobj),
21099 - &ktype_cache,
21100 + ktype,
21101 per_cpu(ici_cache_kobject, cpu),
21102 "index%1lu", i);
21103 if (unlikely(retval)) {
21104 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21105 index b3218cd..99a75de 100644
21106 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21107 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21108 @@ -45,6 +45,7 @@
21109 #include <asm/processor.h>
21110 #include <asm/mce.h>
21111 #include <asm/msr.h>
21112 +#include <asm/local.h>
21113
21114 #include "mce-internal.h"
21115
21116 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21117 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21118 m->cs, m->ip);
21119
21120 - if (m->cs == __KERNEL_CS)
21121 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21122 print_symbol("{%s}", m->ip);
21123 pr_cont("\n");
21124 }
21125 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21126
21127 #define PANIC_TIMEOUT 5 /* 5 seconds */
21128
21129 -static atomic_t mce_paniced;
21130 +static atomic_unchecked_t mce_paniced;
21131
21132 static int fake_panic;
21133 -static atomic_t mce_fake_paniced;
21134 +static atomic_unchecked_t mce_fake_paniced;
21135
21136 /* Panic in progress. Enable interrupts and wait for final IPI */
21137 static void wait_for_panic(void)
21138 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21139 /*
21140 * Make sure only one CPU runs in machine check panic
21141 */
21142 - if (atomic_inc_return(&mce_paniced) > 1)
21143 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21144 wait_for_panic();
21145 barrier();
21146
21147 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21148 console_verbose();
21149 } else {
21150 /* Don't log too much for fake panic */
21151 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21152 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21153 return;
21154 }
21155 /* First print corrected ones that are still unlogged */
21156 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21157 if (!fake_panic) {
21158 if (panic_timeout == 0)
21159 panic_timeout = mca_cfg.panic_timeout;
21160 - panic(msg);
21161 + panic("%s", msg);
21162 } else
21163 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21164 }
21165 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21166 * might have been modified by someone else.
21167 */
21168 rmb();
21169 - if (atomic_read(&mce_paniced))
21170 + if (atomic_read_unchecked(&mce_paniced))
21171 wait_for_panic();
21172 if (!mca_cfg.monarch_timeout)
21173 goto out;
21174 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21175 }
21176
21177 /* Call the installed machine check handler for this CPU setup. */
21178 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21179 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21180 unexpected_machine_check;
21181
21182 /*
21183 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21184 return;
21185 }
21186
21187 + pax_open_kernel();
21188 machine_check_vector = do_machine_check;
21189 + pax_close_kernel();
21190
21191 __mcheck_cpu_init_generic();
21192 __mcheck_cpu_init_vendor(c);
21193 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21194 */
21195
21196 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21197 -static int mce_chrdev_open_count; /* #times opened */
21198 +static local_t mce_chrdev_open_count; /* #times opened */
21199 static int mce_chrdev_open_exclu; /* already open exclusive? */
21200
21201 static int mce_chrdev_open(struct inode *inode, struct file *file)
21202 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21203 spin_lock(&mce_chrdev_state_lock);
21204
21205 if (mce_chrdev_open_exclu ||
21206 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21207 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21208 spin_unlock(&mce_chrdev_state_lock);
21209
21210 return -EBUSY;
21211 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21212
21213 if (file->f_flags & O_EXCL)
21214 mce_chrdev_open_exclu = 1;
21215 - mce_chrdev_open_count++;
21216 + local_inc(&mce_chrdev_open_count);
21217
21218 spin_unlock(&mce_chrdev_state_lock);
21219
21220 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21221 {
21222 spin_lock(&mce_chrdev_state_lock);
21223
21224 - mce_chrdev_open_count--;
21225 + local_dec(&mce_chrdev_open_count);
21226 mce_chrdev_open_exclu = 0;
21227
21228 spin_unlock(&mce_chrdev_state_lock);
21229 @@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
21230
21231 for (i = 0; i < mca_cfg.banks; i++) {
21232 struct mce_bank *b = &mce_banks[i];
21233 - struct device_attribute *a = &b->attr;
21234 + device_attribute_no_const *a = &b->attr;
21235
21236 sysfs_attr_init(&a->attr);
21237 a->attr.name = b->attrname;
21238 @@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
21239 static void mce_reset(void)
21240 {
21241 cpu_missing = 0;
21242 - atomic_set(&mce_fake_paniced, 0);
21243 + atomic_set_unchecked(&mce_fake_paniced, 0);
21244 atomic_set(&mce_executing, 0);
21245 atomic_set(&mce_callin, 0);
21246 atomic_set(&global_nwo, 0);
21247 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21248 index 1c044b1..37a2a43 100644
21249 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21250 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21251 @@ -11,6 +11,7 @@
21252 #include <asm/processor.h>
21253 #include <asm/mce.h>
21254 #include <asm/msr.h>
21255 +#include <asm/pgtable.h>
21256
21257 /* By default disabled */
21258 int mce_p5_enabled __read_mostly;
21259 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21260 if (!cpu_has(c, X86_FEATURE_MCE))
21261 return;
21262
21263 + pax_open_kernel();
21264 machine_check_vector = pentium_machine_check;
21265 + pax_close_kernel();
21266 /* Make sure the vector pointer is visible before we enable MCEs: */
21267 wmb();
21268
21269 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21270 index e9a701a..35317d6 100644
21271 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21272 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21273 @@ -10,6 +10,7 @@
21274 #include <asm/processor.h>
21275 #include <asm/mce.h>
21276 #include <asm/msr.h>
21277 +#include <asm/pgtable.h>
21278
21279 /* Machine check handler for WinChip C6: */
21280 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21281 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21282 {
21283 u32 lo, hi;
21284
21285 + pax_open_kernel();
21286 machine_check_vector = winchip_machine_check;
21287 + pax_close_kernel();
21288 /* Make sure the vector pointer is visible before we enable MCEs: */
21289 wmb();
21290
21291 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21292 index f961de9..8a9d332 100644
21293 --- a/arch/x86/kernel/cpu/mtrr/main.c
21294 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21295 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21296 u64 size_or_mask, size_and_mask;
21297 static bool mtrr_aps_delayed_init;
21298
21299 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21300 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21301
21302 const struct mtrr_ops *mtrr_if;
21303
21304 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21305 index df5e41f..816c719 100644
21306 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21307 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21308 @@ -25,7 +25,7 @@ struct mtrr_ops {
21309 int (*validate_add_page)(unsigned long base, unsigned long size,
21310 unsigned int type);
21311 int (*have_wrcomb)(void);
21312 -};
21313 +} __do_const;
21314
21315 extern int generic_get_free_region(unsigned long base, unsigned long size,
21316 int replace_reg);
21317 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21318 index db6cdbe..faaf834 100644
21319 --- a/arch/x86/kernel/cpu/perf_event.c
21320 +++ b/arch/x86/kernel/cpu/perf_event.c
21321 @@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21322 pr_info("no hardware sampling interrupt available.\n");
21323 }
21324
21325 -static struct attribute_group x86_pmu_format_group = {
21326 +static attribute_group_no_const x86_pmu_format_group = {
21327 .name = "format",
21328 .attrs = NULL,
21329 };
21330 @@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21331 NULL,
21332 };
21333
21334 -static struct attribute_group x86_pmu_events_group = {
21335 +static attribute_group_no_const x86_pmu_events_group = {
21336 .name = "events",
21337 .attrs = events_attr,
21338 };
21339 @@ -1961,7 +1961,7 @@ static unsigned long get_segment_base(unsigned int segment)
21340 if (idx > GDT_ENTRIES)
21341 return 0;
21342
21343 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21344 + desc = get_cpu_gdt_table(smp_processor_id());
21345 }
21346
21347 return get_desc_base(desc + idx);
21348 @@ -2051,7 +2051,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21349 break;
21350
21351 perf_callchain_store(entry, frame.return_address);
21352 - fp = frame.next_frame;
21353 + fp = (const void __force_user *)frame.next_frame;
21354 }
21355 }
21356
21357 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21358 index 639d128..e92d7e5 100644
21359 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21360 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21361 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21362 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21363 {
21364 struct attribute **attrs;
21365 - struct attribute_group *attr_group;
21366 + attribute_group_no_const *attr_group;
21367 int i = 0, j;
21368
21369 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21370 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21371 index 0fa4f24..17990ed 100644
21372 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21373 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21374 @@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
21375 * v2 and above have a perf capabilities MSR
21376 */
21377 if (version > 1) {
21378 - u64 capabilities;
21379 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21380
21381 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21382 - x86_pmu.intel_cap.capabilities = capabilities;
21383 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21384 + x86_pmu.intel_cap.capabilities = capabilities;
21385 }
21386
21387 intel_ds_init();
21388 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21389 index 29c2487..a5606fa 100644
21390 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21391 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21392 @@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21393 static int __init uncore_type_init(struct intel_uncore_type *type)
21394 {
21395 struct intel_uncore_pmu *pmus;
21396 - struct attribute_group *attr_group;
21397 + attribute_group_no_const *attr_group;
21398 struct attribute **attrs;
21399 int i, j;
21400
21401 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21402 index a80ab71..4089da5 100644
21403 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21404 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21405 @@ -498,7 +498,7 @@ struct intel_uncore_box {
21406 struct uncore_event_desc {
21407 struct kobj_attribute attr;
21408 const char *config;
21409 -};
21410 +} __do_const;
21411
21412 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21413 { \
21414 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21415 index 7d9481c..99c7e4b 100644
21416 --- a/arch/x86/kernel/cpuid.c
21417 +++ b/arch/x86/kernel/cpuid.c
21418 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21419 return notifier_from_errno(err);
21420 }
21421
21422 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21423 +static struct notifier_block cpuid_class_cpu_notifier =
21424 {
21425 .notifier_call = cpuid_class_cpu_callback,
21426 };
21427 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21428 index 18677a9..f67c45b 100644
21429 --- a/arch/x86/kernel/crash.c
21430 +++ b/arch/x86/kernel/crash.c
21431 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21432 {
21433 #ifdef CONFIG_X86_32
21434 struct pt_regs fixed_regs;
21435 -#endif
21436
21437 -#ifdef CONFIG_X86_32
21438 - if (!user_mode_vm(regs)) {
21439 + if (!user_mode(regs)) {
21440 crash_fixup_ss_esp(&fixed_regs, regs);
21441 regs = &fixed_regs;
21442 }
21443 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21444 index afa64ad..dce67dd 100644
21445 --- a/arch/x86/kernel/crash_dump_64.c
21446 +++ b/arch/x86/kernel/crash_dump_64.c
21447 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21448 return -ENOMEM;
21449
21450 if (userbuf) {
21451 - if (copy_to_user(buf, vaddr + offset, csize)) {
21452 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21453 iounmap(vaddr);
21454 return -EFAULT;
21455 }
21456 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21457 index 5d3fe8d..02e1429 100644
21458 --- a/arch/x86/kernel/doublefault.c
21459 +++ b/arch/x86/kernel/doublefault.c
21460 @@ -13,7 +13,7 @@
21461
21462 #define DOUBLEFAULT_STACKSIZE (1024)
21463 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21464 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21465 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21466
21467 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21468
21469 @@ -23,7 +23,7 @@ static void doublefault_fn(void)
21470 unsigned long gdt, tss;
21471
21472 native_store_gdt(&gdt_desc);
21473 - gdt = gdt_desc.address;
21474 + gdt = (unsigned long)gdt_desc.address;
21475
21476 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21477
21478 @@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21479 /* 0x2 bit is always set */
21480 .flags = X86_EFLAGS_SF | 0x2,
21481 .sp = STACK_START,
21482 - .es = __USER_DS,
21483 + .es = __KERNEL_DS,
21484 .cs = __KERNEL_CS,
21485 .ss = __KERNEL_DS,
21486 - .ds = __USER_DS,
21487 + .ds = __KERNEL_DS,
21488 .fs = __KERNEL_PERCPU,
21489
21490 .__cr3 = __pa_nodebug(swapper_pg_dir),
21491 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21492 index d9c12d3..7858b62 100644
21493 --- a/arch/x86/kernel/dumpstack.c
21494 +++ b/arch/x86/kernel/dumpstack.c
21495 @@ -2,6 +2,9 @@
21496 * Copyright (C) 1991, 1992 Linus Torvalds
21497 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21498 */
21499 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21500 +#define __INCLUDED_BY_HIDESYM 1
21501 +#endif
21502 #include <linux/kallsyms.h>
21503 #include <linux/kprobes.h>
21504 #include <linux/uaccess.h>
21505 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21506 static void
21507 print_ftrace_graph_addr(unsigned long addr, void *data,
21508 const struct stacktrace_ops *ops,
21509 - struct thread_info *tinfo, int *graph)
21510 + struct task_struct *task, int *graph)
21511 {
21512 - struct task_struct *task;
21513 unsigned long ret_addr;
21514 int index;
21515
21516 if (addr != (unsigned long)return_to_handler)
21517 return;
21518
21519 - task = tinfo->task;
21520 index = task->curr_ret_stack;
21521
21522 if (!task->ret_stack || index < *graph)
21523 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21524 static inline void
21525 print_ftrace_graph_addr(unsigned long addr, void *data,
21526 const struct stacktrace_ops *ops,
21527 - struct thread_info *tinfo, int *graph)
21528 + struct task_struct *task, int *graph)
21529 { }
21530 #endif
21531
21532 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21533 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21534 */
21535
21536 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21537 - void *p, unsigned int size, void *end)
21538 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21539 {
21540 - void *t = tinfo;
21541 if (end) {
21542 if (p < end && p >= (end-THREAD_SIZE))
21543 return 1;
21544 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21545 }
21546
21547 unsigned long
21548 -print_context_stack(struct thread_info *tinfo,
21549 +print_context_stack(struct task_struct *task, void *stack_start,
21550 unsigned long *stack, unsigned long bp,
21551 const struct stacktrace_ops *ops, void *data,
21552 unsigned long *end, int *graph)
21553 {
21554 struct stack_frame *frame = (struct stack_frame *)bp;
21555
21556 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21557 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21558 unsigned long addr;
21559
21560 addr = *stack;
21561 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21562 } else {
21563 ops->address(data, addr, 0);
21564 }
21565 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21566 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21567 }
21568 stack++;
21569 }
21570 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21571 EXPORT_SYMBOL_GPL(print_context_stack);
21572
21573 unsigned long
21574 -print_context_stack_bp(struct thread_info *tinfo,
21575 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21576 unsigned long *stack, unsigned long bp,
21577 const struct stacktrace_ops *ops, void *data,
21578 unsigned long *end, int *graph)
21579 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21580 struct stack_frame *frame = (struct stack_frame *)bp;
21581 unsigned long *ret_addr = &frame->return_address;
21582
21583 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21584 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21585 unsigned long addr = *ret_addr;
21586
21587 if (!__kernel_text_address(addr))
21588 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21589 ops->address(data, addr, 1);
21590 frame = frame->next_frame;
21591 ret_addr = &frame->return_address;
21592 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21593 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21594 }
21595
21596 return (unsigned long)frame;
21597 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21598 static void print_trace_address(void *data, unsigned long addr, int reliable)
21599 {
21600 touch_nmi_watchdog();
21601 - printk(data);
21602 + printk("%s", (char *)data);
21603 printk_stack_address(addr, reliable);
21604 }
21605
21606 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21607 }
21608 EXPORT_SYMBOL_GPL(oops_begin);
21609
21610 +extern void gr_handle_kernel_exploit(void);
21611 +
21612 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21613 {
21614 if (regs && kexec_should_crash(current))
21615 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21616 panic("Fatal exception in interrupt");
21617 if (panic_on_oops)
21618 panic("Fatal exception");
21619 - do_exit(signr);
21620 +
21621 + gr_handle_kernel_exploit();
21622 +
21623 + do_group_exit(signr);
21624 }
21625
21626 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21627 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21628 print_modules();
21629 show_regs(regs);
21630 #ifdef CONFIG_X86_32
21631 - if (user_mode_vm(regs)) {
21632 + if (user_mode(regs)) {
21633 sp = regs->sp;
21634 ss = regs->ss & 0xffff;
21635 } else {
21636 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21637 unsigned long flags = oops_begin();
21638 int sig = SIGSEGV;
21639
21640 - if (!user_mode_vm(regs))
21641 + if (!user_mode(regs))
21642 report_bug(regs->ip, regs);
21643
21644 if (__die(str, regs, err))
21645 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21646 index f2a1770..540657f 100644
21647 --- a/arch/x86/kernel/dumpstack_32.c
21648 +++ b/arch/x86/kernel/dumpstack_32.c
21649 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21650 bp = stack_frame(task, regs);
21651
21652 for (;;) {
21653 - struct thread_info *context;
21654 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21655
21656 - context = (struct thread_info *)
21657 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21658 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21659 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21660
21661 - stack = (unsigned long *)context->previous_esp;
21662 - if (!stack)
21663 + if (stack_start == task_stack_page(task))
21664 break;
21665 + stack = *(unsigned long **)stack_start;
21666 if (ops->stack(data, "IRQ") < 0)
21667 break;
21668 touch_nmi_watchdog();
21669 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21670 int i;
21671
21672 show_regs_print_info(KERN_EMERG);
21673 - __show_regs(regs, !user_mode_vm(regs));
21674 + __show_regs(regs, !user_mode(regs));
21675
21676 /*
21677 * When in-kernel, we also print out the stack and code at the
21678 * time of the fault..
21679 */
21680 - if (!user_mode_vm(regs)) {
21681 + if (!user_mode(regs)) {
21682 unsigned int code_prologue = code_bytes * 43 / 64;
21683 unsigned int code_len = code_bytes;
21684 unsigned char c;
21685 u8 *ip;
21686 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21687
21688 pr_emerg("Stack:\n");
21689 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21690
21691 pr_emerg("Code:");
21692
21693 - ip = (u8 *)regs->ip - code_prologue;
21694 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21695 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21696 /* try starting at IP */
21697 - ip = (u8 *)regs->ip;
21698 + ip = (u8 *)regs->ip + cs_base;
21699 code_len = code_len - code_prologue + 1;
21700 }
21701 for (i = 0; i < code_len; i++, ip++) {
21702 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21703 pr_cont(" Bad EIP value.");
21704 break;
21705 }
21706 - if (ip == (u8 *)regs->ip)
21707 + if (ip == (u8 *)regs->ip + cs_base)
21708 pr_cont(" <%02x>", c);
21709 else
21710 pr_cont(" %02x", c);
21711 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21712 {
21713 unsigned short ud2;
21714
21715 + ip = ktla_ktva(ip);
21716 if (ip < PAGE_OFFSET)
21717 return 0;
21718 if (probe_kernel_address((unsigned short *)ip, ud2))
21719 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21720
21721 return ud2 == 0x0b0f;
21722 }
21723 +
21724 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21725 +void pax_check_alloca(unsigned long size)
21726 +{
21727 + unsigned long sp = (unsigned long)&sp, stack_left;
21728 +
21729 + /* all kernel stacks are of the same size */
21730 + stack_left = sp & (THREAD_SIZE - 1);
21731 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21732 +}
21733 +EXPORT_SYMBOL(pax_check_alloca);
21734 +#endif
21735 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21736 index addb207..99635fa 100644
21737 --- a/arch/x86/kernel/dumpstack_64.c
21738 +++ b/arch/x86/kernel/dumpstack_64.c
21739 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21740 unsigned long *irq_stack_end =
21741 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21742 unsigned used = 0;
21743 - struct thread_info *tinfo;
21744 int graph = 0;
21745 unsigned long dummy;
21746 + void *stack_start;
21747
21748 if (!task)
21749 task = current;
21750 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21751 * current stack address. If the stacks consist of nested
21752 * exceptions
21753 */
21754 - tinfo = task_thread_info(task);
21755 for (;;) {
21756 char *id;
21757 unsigned long *estack_end;
21758 +
21759 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21760 &used, &id);
21761
21762 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21763 if (ops->stack(data, id) < 0)
21764 break;
21765
21766 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21767 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21768 data, estack_end, &graph);
21769 ops->stack(data, "<EOE>");
21770 /*
21771 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21772 * second-to-last pointer (index -2 to end) in the
21773 * exception stack:
21774 */
21775 + if ((u16)estack_end[-1] != __KERNEL_DS)
21776 + goto out;
21777 stack = (unsigned long *) estack_end[-2];
21778 continue;
21779 }
21780 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21781 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21782 if (ops->stack(data, "IRQ") < 0)
21783 break;
21784 - bp = ops->walk_stack(tinfo, stack, bp,
21785 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21786 ops, data, irq_stack_end, &graph);
21787 /*
21788 * We link to the next stack (which would be
21789 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21790 /*
21791 * This handles the process stack:
21792 */
21793 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21794 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21795 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21796 +out:
21797 put_cpu();
21798 }
21799 EXPORT_SYMBOL(dump_trace);
21800 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21801
21802 return ud2 == 0x0b0f;
21803 }
21804 +
21805 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21806 +void pax_check_alloca(unsigned long size)
21807 +{
21808 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21809 + unsigned cpu, used;
21810 + char *id;
21811 +
21812 + /* check the process stack first */
21813 + stack_start = (unsigned long)task_stack_page(current);
21814 + stack_end = stack_start + THREAD_SIZE;
21815 + if (likely(stack_start <= sp && sp < stack_end)) {
21816 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21817 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21818 + return;
21819 + }
21820 +
21821 + cpu = get_cpu();
21822 +
21823 + /* check the irq stacks */
21824 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21825 + stack_start = stack_end - IRQ_STACK_SIZE;
21826 + if (stack_start <= sp && sp < stack_end) {
21827 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21828 + put_cpu();
21829 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21830 + return;
21831 + }
21832 +
21833 + /* check the exception stacks */
21834 + used = 0;
21835 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21836 + stack_start = stack_end - EXCEPTION_STKSZ;
21837 + if (stack_end && stack_start <= sp && sp < stack_end) {
21838 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21839 + put_cpu();
21840 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21841 + return;
21842 + }
21843 +
21844 + put_cpu();
21845 +
21846 + /* unknown stack */
21847 + BUG();
21848 +}
21849 +EXPORT_SYMBOL(pax_check_alloca);
21850 +#endif
21851 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21852 index 174da5f..5e55606 100644
21853 --- a/arch/x86/kernel/e820.c
21854 +++ b/arch/x86/kernel/e820.c
21855 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21856
21857 static void early_panic(char *msg)
21858 {
21859 - early_printk(msg);
21860 - panic(msg);
21861 + early_printk("%s", msg);
21862 + panic("%s", msg);
21863 }
21864
21865 static int userdef __initdata;
21866 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21867 index 01d1c18..8073693 100644
21868 --- a/arch/x86/kernel/early_printk.c
21869 +++ b/arch/x86/kernel/early_printk.c
21870 @@ -7,6 +7,7 @@
21871 #include <linux/pci_regs.h>
21872 #include <linux/pci_ids.h>
21873 #include <linux/errno.h>
21874 +#include <linux/sched.h>
21875 #include <asm/io.h>
21876 #include <asm/processor.h>
21877 #include <asm/fcntl.h>
21878 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21879 index a2a4f46..6cab058 100644
21880 --- a/arch/x86/kernel/entry_32.S
21881 +++ b/arch/x86/kernel/entry_32.S
21882 @@ -177,13 +177,153 @@
21883 /*CFI_REL_OFFSET gs, PT_GS*/
21884 .endm
21885 .macro SET_KERNEL_GS reg
21886 +
21887 +#ifdef CONFIG_CC_STACKPROTECTOR
21888 movl $(__KERNEL_STACK_CANARY), \reg
21889 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21890 + movl $(__USER_DS), \reg
21891 +#else
21892 + xorl \reg, \reg
21893 +#endif
21894 +
21895 movl \reg, %gs
21896 .endm
21897
21898 #endif /* CONFIG_X86_32_LAZY_GS */
21899
21900 -.macro SAVE_ALL
21901 +.macro pax_enter_kernel
21902 +#ifdef CONFIG_PAX_KERNEXEC
21903 + call pax_enter_kernel
21904 +#endif
21905 +.endm
21906 +
21907 +.macro pax_exit_kernel
21908 +#ifdef CONFIG_PAX_KERNEXEC
21909 + call pax_exit_kernel
21910 +#endif
21911 +.endm
21912 +
21913 +#ifdef CONFIG_PAX_KERNEXEC
21914 +ENTRY(pax_enter_kernel)
21915 +#ifdef CONFIG_PARAVIRT
21916 + pushl %eax
21917 + pushl %ecx
21918 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21919 + mov %eax, %esi
21920 +#else
21921 + mov %cr0, %esi
21922 +#endif
21923 + bts $16, %esi
21924 + jnc 1f
21925 + mov %cs, %esi
21926 + cmp $__KERNEL_CS, %esi
21927 + jz 3f
21928 + ljmp $__KERNEL_CS, $3f
21929 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21930 +2:
21931 +#ifdef CONFIG_PARAVIRT
21932 + mov %esi, %eax
21933 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21934 +#else
21935 + mov %esi, %cr0
21936 +#endif
21937 +3:
21938 +#ifdef CONFIG_PARAVIRT
21939 + popl %ecx
21940 + popl %eax
21941 +#endif
21942 + ret
21943 +ENDPROC(pax_enter_kernel)
21944 +
21945 +ENTRY(pax_exit_kernel)
21946 +#ifdef CONFIG_PARAVIRT
21947 + pushl %eax
21948 + pushl %ecx
21949 +#endif
21950 + mov %cs, %esi
21951 + cmp $__KERNEXEC_KERNEL_CS, %esi
21952 + jnz 2f
21953 +#ifdef CONFIG_PARAVIRT
21954 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21955 + mov %eax, %esi
21956 +#else
21957 + mov %cr0, %esi
21958 +#endif
21959 + btr $16, %esi
21960 + ljmp $__KERNEL_CS, $1f
21961 +1:
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 +2:
21969 +#ifdef CONFIG_PARAVIRT
21970 + popl %ecx
21971 + popl %eax
21972 +#endif
21973 + ret
21974 +ENDPROC(pax_exit_kernel)
21975 +#endif
21976 +
21977 + .macro pax_erase_kstack
21978 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21979 + call pax_erase_kstack
21980 +#endif
21981 + .endm
21982 +
21983 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21984 +/*
21985 + * ebp: thread_info
21986 + */
21987 +ENTRY(pax_erase_kstack)
21988 + pushl %edi
21989 + pushl %ecx
21990 + pushl %eax
21991 +
21992 + mov TI_lowest_stack(%ebp), %edi
21993 + mov $-0xBEEF, %eax
21994 + std
21995 +
21996 +1: mov %edi, %ecx
21997 + and $THREAD_SIZE_asm - 1, %ecx
21998 + shr $2, %ecx
21999 + repne scasl
22000 + jecxz 2f
22001 +
22002 + cmp $2*16, %ecx
22003 + jc 2f
22004 +
22005 + mov $2*16, %ecx
22006 + repe scasl
22007 + jecxz 2f
22008 + jne 1b
22009 +
22010 +2: cld
22011 + mov %esp, %ecx
22012 + sub %edi, %ecx
22013 +
22014 + cmp $THREAD_SIZE_asm, %ecx
22015 + jb 3f
22016 + ud2
22017 +3:
22018 +
22019 + shr $2, %ecx
22020 + rep stosl
22021 +
22022 + mov TI_task_thread_sp0(%ebp), %edi
22023 + sub $128, %edi
22024 + mov %edi, TI_lowest_stack(%ebp)
22025 +
22026 + popl %eax
22027 + popl %ecx
22028 + popl %edi
22029 + ret
22030 +ENDPROC(pax_erase_kstack)
22031 +#endif
22032 +
22033 +.macro __SAVE_ALL _DS
22034 cld
22035 PUSH_GS
22036 pushl_cfi %fs
22037 @@ -206,7 +346,7 @@
22038 CFI_REL_OFFSET ecx, 0
22039 pushl_cfi %ebx
22040 CFI_REL_OFFSET ebx, 0
22041 - movl $(__USER_DS), %edx
22042 + movl $\_DS, %edx
22043 movl %edx, %ds
22044 movl %edx, %es
22045 movl $(__KERNEL_PERCPU), %edx
22046 @@ -214,6 +354,15 @@
22047 SET_KERNEL_GS %edx
22048 .endm
22049
22050 +.macro SAVE_ALL
22051 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22052 + __SAVE_ALL __KERNEL_DS
22053 + pax_enter_kernel
22054 +#else
22055 + __SAVE_ALL __USER_DS
22056 +#endif
22057 +.endm
22058 +
22059 .macro RESTORE_INT_REGS
22060 popl_cfi %ebx
22061 CFI_RESTORE ebx
22062 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22063 popfl_cfi
22064 jmp syscall_exit
22065 CFI_ENDPROC
22066 -END(ret_from_fork)
22067 +ENDPROC(ret_from_fork)
22068
22069 ENTRY(ret_from_kernel_thread)
22070 CFI_STARTPROC
22071 @@ -344,7 +493,15 @@ ret_from_intr:
22072 andl $SEGMENT_RPL_MASK, %eax
22073 #endif
22074 cmpl $USER_RPL, %eax
22075 +
22076 +#ifdef CONFIG_PAX_KERNEXEC
22077 + jae resume_userspace
22078 +
22079 + pax_exit_kernel
22080 + jmp resume_kernel
22081 +#else
22082 jb resume_kernel # not returning to v8086 or userspace
22083 +#endif
22084
22085 ENTRY(resume_userspace)
22086 LOCKDEP_SYS_EXIT
22087 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22088 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22089 # int/exception return?
22090 jne work_pending
22091 - jmp restore_all
22092 -END(ret_from_exception)
22093 + jmp restore_all_pax
22094 +ENDPROC(ret_from_exception)
22095
22096 #ifdef CONFIG_PREEMPT
22097 ENTRY(resume_kernel)
22098 @@ -369,7 +526,7 @@ need_resched:
22099 jz restore_all
22100 call preempt_schedule_irq
22101 jmp need_resched
22102 -END(resume_kernel)
22103 +ENDPROC(resume_kernel)
22104 #endif
22105 CFI_ENDPROC
22106 /*
22107 @@ -403,30 +560,45 @@ sysenter_past_esp:
22108 /*CFI_REL_OFFSET cs, 0*/
22109 /*
22110 * Push current_thread_info()->sysenter_return to the stack.
22111 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22112 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22113 */
22114 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22115 + pushl_cfi $0
22116 CFI_REL_OFFSET eip, 0
22117
22118 pushl_cfi %eax
22119 SAVE_ALL
22120 + GET_THREAD_INFO(%ebp)
22121 + movl TI_sysenter_return(%ebp),%ebp
22122 + movl %ebp,PT_EIP(%esp)
22123 ENABLE_INTERRUPTS(CLBR_NONE)
22124
22125 /*
22126 * Load the potential sixth argument from user stack.
22127 * Careful about security.
22128 */
22129 + movl PT_OLDESP(%esp),%ebp
22130 +
22131 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22132 + mov PT_OLDSS(%esp),%ds
22133 +1: movl %ds:(%ebp),%ebp
22134 + push %ss
22135 + pop %ds
22136 +#else
22137 cmpl $__PAGE_OFFSET-3,%ebp
22138 jae syscall_fault
22139 ASM_STAC
22140 1: movl (%ebp),%ebp
22141 ASM_CLAC
22142 +#endif
22143 +
22144 movl %ebp,PT_EBP(%esp)
22145 _ASM_EXTABLE(1b,syscall_fault)
22146
22147 GET_THREAD_INFO(%ebp)
22148
22149 +#ifdef CONFIG_PAX_RANDKSTACK
22150 + pax_erase_kstack
22151 +#endif
22152 +
22153 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22154 jnz sysenter_audit
22155 sysenter_do_call:
22156 @@ -441,12 +613,24 @@ sysenter_do_call:
22157 testl $_TIF_ALLWORK_MASK, %ecx
22158 jne sysexit_audit
22159 sysenter_exit:
22160 +
22161 +#ifdef CONFIG_PAX_RANDKSTACK
22162 + pushl_cfi %eax
22163 + movl %esp, %eax
22164 + call pax_randomize_kstack
22165 + popl_cfi %eax
22166 +#endif
22167 +
22168 + pax_erase_kstack
22169 +
22170 /* if something modifies registers it must also disable sysexit */
22171 movl PT_EIP(%esp), %edx
22172 movl PT_OLDESP(%esp), %ecx
22173 xorl %ebp,%ebp
22174 TRACE_IRQS_ON
22175 1: mov PT_FS(%esp), %fs
22176 +2: mov PT_DS(%esp), %ds
22177 +3: mov PT_ES(%esp), %es
22178 PTGS_TO_GS
22179 ENABLE_INTERRUPTS_SYSEXIT
22180
22181 @@ -463,6 +647,9 @@ sysenter_audit:
22182 movl %eax,%edx /* 2nd arg: syscall number */
22183 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22184 call __audit_syscall_entry
22185 +
22186 + pax_erase_kstack
22187 +
22188 pushl_cfi %ebx
22189 movl PT_EAX(%esp),%eax /* reload syscall number */
22190 jmp sysenter_do_call
22191 @@ -488,10 +675,16 @@ sysexit_audit:
22192
22193 CFI_ENDPROC
22194 .pushsection .fixup,"ax"
22195 -2: movl $0,PT_FS(%esp)
22196 +4: movl $0,PT_FS(%esp)
22197 + jmp 1b
22198 +5: movl $0,PT_DS(%esp)
22199 + jmp 1b
22200 +6: movl $0,PT_ES(%esp)
22201 jmp 1b
22202 .popsection
22203 - _ASM_EXTABLE(1b,2b)
22204 + _ASM_EXTABLE(1b,4b)
22205 + _ASM_EXTABLE(2b,5b)
22206 + _ASM_EXTABLE(3b,6b)
22207 PTGS_TO_GS_EX
22208 ENDPROC(ia32_sysenter_target)
22209
22210 @@ -506,6 +699,11 @@ ENTRY(system_call)
22211 pushl_cfi %eax # save orig_eax
22212 SAVE_ALL
22213 GET_THREAD_INFO(%ebp)
22214 +
22215 +#ifdef CONFIG_PAX_RANDKSTACK
22216 + pax_erase_kstack
22217 +#endif
22218 +
22219 # system call tracing in operation / emulation
22220 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22221 jnz syscall_trace_entry
22222 @@ -524,6 +722,15 @@ syscall_exit:
22223 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22224 jne syscall_exit_work
22225
22226 +restore_all_pax:
22227 +
22228 +#ifdef CONFIG_PAX_RANDKSTACK
22229 + movl %esp, %eax
22230 + call pax_randomize_kstack
22231 +#endif
22232 +
22233 + pax_erase_kstack
22234 +
22235 restore_all:
22236 TRACE_IRQS_IRET
22237 restore_all_notrace:
22238 @@ -580,14 +787,34 @@ ldt_ss:
22239 * compensating for the offset by changing to the ESPFIX segment with
22240 * a base address that matches for the difference.
22241 */
22242 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22243 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22244 mov %esp, %edx /* load kernel esp */
22245 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22246 mov %dx, %ax /* eax: new kernel esp */
22247 sub %eax, %edx /* offset (low word is 0) */
22248 +#ifdef CONFIG_SMP
22249 + movl PER_CPU_VAR(cpu_number), %ebx
22250 + shll $PAGE_SHIFT_asm, %ebx
22251 + addl $cpu_gdt_table, %ebx
22252 +#else
22253 + movl $cpu_gdt_table, %ebx
22254 +#endif
22255 shr $16, %edx
22256 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22257 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22258 +
22259 +#ifdef CONFIG_PAX_KERNEXEC
22260 + mov %cr0, %esi
22261 + btr $16, %esi
22262 + mov %esi, %cr0
22263 +#endif
22264 +
22265 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22266 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22267 +
22268 +#ifdef CONFIG_PAX_KERNEXEC
22269 + bts $16, %esi
22270 + mov %esi, %cr0
22271 +#endif
22272 +
22273 pushl_cfi $__ESPFIX_SS
22274 pushl_cfi %eax /* new kernel esp */
22275 /* Disable interrupts, but do not irqtrace this section: we
22276 @@ -616,20 +843,18 @@ work_resched:
22277 movl TI_flags(%ebp), %ecx
22278 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22279 # than syscall tracing?
22280 - jz restore_all
22281 + jz restore_all_pax
22282 testb $_TIF_NEED_RESCHED, %cl
22283 jnz work_resched
22284
22285 work_notifysig: # deal with pending signals and
22286 # notify-resume requests
22287 + movl %esp, %eax
22288 #ifdef CONFIG_VM86
22289 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22290 - movl %esp, %eax
22291 jne work_notifysig_v86 # returning to kernel-space or
22292 # vm86-space
22293 1:
22294 -#else
22295 - movl %esp, %eax
22296 #endif
22297 TRACE_IRQS_ON
22298 ENABLE_INTERRUPTS(CLBR_NONE)
22299 @@ -650,7 +875,7 @@ work_notifysig_v86:
22300 movl %eax, %esp
22301 jmp 1b
22302 #endif
22303 -END(work_pending)
22304 +ENDPROC(work_pending)
22305
22306 # perform syscall exit tracing
22307 ALIGN
22308 @@ -658,11 +883,14 @@ syscall_trace_entry:
22309 movl $-ENOSYS,PT_EAX(%esp)
22310 movl %esp, %eax
22311 call syscall_trace_enter
22312 +
22313 + pax_erase_kstack
22314 +
22315 /* What it returned is what we'll actually use. */
22316 cmpl $(NR_syscalls), %eax
22317 jnae syscall_call
22318 jmp syscall_exit
22319 -END(syscall_trace_entry)
22320 +ENDPROC(syscall_trace_entry)
22321
22322 # perform syscall exit tracing
22323 ALIGN
22324 @@ -675,21 +903,25 @@ syscall_exit_work:
22325 movl %esp, %eax
22326 call syscall_trace_leave
22327 jmp resume_userspace
22328 -END(syscall_exit_work)
22329 +ENDPROC(syscall_exit_work)
22330 CFI_ENDPROC
22331
22332 RING0_INT_FRAME # can't unwind into user space anyway
22333 syscall_fault:
22334 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22335 + push %ss
22336 + pop %ds
22337 +#endif
22338 ASM_CLAC
22339 GET_THREAD_INFO(%ebp)
22340 movl $-EFAULT,PT_EAX(%esp)
22341 jmp resume_userspace
22342 -END(syscall_fault)
22343 +ENDPROC(syscall_fault)
22344
22345 syscall_badsys:
22346 movl $-ENOSYS,PT_EAX(%esp)
22347 jmp resume_userspace
22348 -END(syscall_badsys)
22349 +ENDPROC(syscall_badsys)
22350 CFI_ENDPROC
22351 /*
22352 * End of kprobes section
22353 @@ -705,8 +937,15 @@ END(syscall_badsys)
22354 * normal stack and adjusts ESP with the matching offset.
22355 */
22356 /* fixup the stack */
22357 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22358 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22359 +#ifdef CONFIG_SMP
22360 + movl PER_CPU_VAR(cpu_number), %ebx
22361 + shll $PAGE_SHIFT_asm, %ebx
22362 + addl $cpu_gdt_table, %ebx
22363 +#else
22364 + movl $cpu_gdt_table, %ebx
22365 +#endif
22366 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22367 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22368 shl $16, %eax
22369 addl %esp, %eax /* the adjusted stack pointer */
22370 pushl_cfi $__KERNEL_DS
22371 @@ -759,7 +998,7 @@ vector=vector+1
22372 .endr
22373 2: jmp common_interrupt
22374 .endr
22375 -END(irq_entries_start)
22376 +ENDPROC(irq_entries_start)
22377
22378 .previous
22379 END(interrupt)
22380 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22381 pushl_cfi $do_coprocessor_error
22382 jmp error_code
22383 CFI_ENDPROC
22384 -END(coprocessor_error)
22385 +ENDPROC(coprocessor_error)
22386
22387 ENTRY(simd_coprocessor_error)
22388 RING0_INT_FRAME
22389 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22390 .section .altinstructions,"a"
22391 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22392 .previous
22393 -.section .altinstr_replacement,"ax"
22394 +.section .altinstr_replacement,"a"
22395 663: pushl $do_simd_coprocessor_error
22396 664:
22397 .previous
22398 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22399 #endif
22400 jmp error_code
22401 CFI_ENDPROC
22402 -END(simd_coprocessor_error)
22403 +ENDPROC(simd_coprocessor_error)
22404
22405 ENTRY(device_not_available)
22406 RING0_INT_FRAME
22407 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22408 pushl_cfi $do_device_not_available
22409 jmp error_code
22410 CFI_ENDPROC
22411 -END(device_not_available)
22412 +ENDPROC(device_not_available)
22413
22414 #ifdef CONFIG_PARAVIRT
22415 ENTRY(native_iret)
22416 iret
22417 _ASM_EXTABLE(native_iret, iret_exc)
22418 -END(native_iret)
22419 +ENDPROC(native_iret)
22420
22421 ENTRY(native_irq_enable_sysexit)
22422 sti
22423 sysexit
22424 -END(native_irq_enable_sysexit)
22425 +ENDPROC(native_irq_enable_sysexit)
22426 #endif
22427
22428 ENTRY(overflow)
22429 @@ -872,7 +1111,7 @@ ENTRY(overflow)
22430 pushl_cfi $do_overflow
22431 jmp error_code
22432 CFI_ENDPROC
22433 -END(overflow)
22434 +ENDPROC(overflow)
22435
22436 ENTRY(bounds)
22437 RING0_INT_FRAME
22438 @@ -881,7 +1120,7 @@ ENTRY(bounds)
22439 pushl_cfi $do_bounds
22440 jmp error_code
22441 CFI_ENDPROC
22442 -END(bounds)
22443 +ENDPROC(bounds)
22444
22445 ENTRY(invalid_op)
22446 RING0_INT_FRAME
22447 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22448 pushl_cfi $do_invalid_op
22449 jmp error_code
22450 CFI_ENDPROC
22451 -END(invalid_op)
22452 +ENDPROC(invalid_op)
22453
22454 ENTRY(coprocessor_segment_overrun)
22455 RING0_INT_FRAME
22456 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22457 pushl_cfi $do_coprocessor_segment_overrun
22458 jmp error_code
22459 CFI_ENDPROC
22460 -END(coprocessor_segment_overrun)
22461 +ENDPROC(coprocessor_segment_overrun)
22462
22463 ENTRY(invalid_TSS)
22464 RING0_EC_FRAME
22465 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22466 pushl_cfi $do_invalid_TSS
22467 jmp error_code
22468 CFI_ENDPROC
22469 -END(invalid_TSS)
22470 +ENDPROC(invalid_TSS)
22471
22472 ENTRY(segment_not_present)
22473 RING0_EC_FRAME
22474 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22475 pushl_cfi $do_segment_not_present
22476 jmp error_code
22477 CFI_ENDPROC
22478 -END(segment_not_present)
22479 +ENDPROC(segment_not_present)
22480
22481 ENTRY(stack_segment)
22482 RING0_EC_FRAME
22483 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22484 pushl_cfi $do_stack_segment
22485 jmp error_code
22486 CFI_ENDPROC
22487 -END(stack_segment)
22488 +ENDPROC(stack_segment)
22489
22490 ENTRY(alignment_check)
22491 RING0_EC_FRAME
22492 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22493 pushl_cfi $do_alignment_check
22494 jmp error_code
22495 CFI_ENDPROC
22496 -END(alignment_check)
22497 +ENDPROC(alignment_check)
22498
22499 ENTRY(divide_error)
22500 RING0_INT_FRAME
22501 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
22502 pushl_cfi $do_divide_error
22503 jmp error_code
22504 CFI_ENDPROC
22505 -END(divide_error)
22506 +ENDPROC(divide_error)
22507
22508 #ifdef CONFIG_X86_MCE
22509 ENTRY(machine_check)
22510 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
22511 pushl_cfi machine_check_vector
22512 jmp error_code
22513 CFI_ENDPROC
22514 -END(machine_check)
22515 +ENDPROC(machine_check)
22516 #endif
22517
22518 ENTRY(spurious_interrupt_bug)
22519 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22520 pushl_cfi $do_spurious_interrupt_bug
22521 jmp error_code
22522 CFI_ENDPROC
22523 -END(spurious_interrupt_bug)
22524 +ENDPROC(spurious_interrupt_bug)
22525 /*
22526 * End of kprobes section
22527 */
22528 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22529
22530 ENTRY(mcount)
22531 ret
22532 -END(mcount)
22533 +ENDPROC(mcount)
22534
22535 ENTRY(ftrace_caller)
22536 cmpl $0, function_trace_stop
22537 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22538 .globl ftrace_stub
22539 ftrace_stub:
22540 ret
22541 -END(ftrace_caller)
22542 +ENDPROC(ftrace_caller)
22543
22544 ENTRY(ftrace_regs_caller)
22545 pushf /* push flags before compare (in cs location) */
22546 @@ -1207,7 +1446,7 @@ trace:
22547 popl %ecx
22548 popl %eax
22549 jmp ftrace_stub
22550 -END(mcount)
22551 +ENDPROC(mcount)
22552 #endif /* CONFIG_DYNAMIC_FTRACE */
22553 #endif /* CONFIG_FUNCTION_TRACER */
22554
22555 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22556 popl %ecx
22557 popl %eax
22558 ret
22559 -END(ftrace_graph_caller)
22560 +ENDPROC(ftrace_graph_caller)
22561
22562 .globl return_to_handler
22563 return_to_handler:
22564 @@ -1291,15 +1530,18 @@ error_code:
22565 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22566 REG_TO_PTGS %ecx
22567 SET_KERNEL_GS %ecx
22568 - movl $(__USER_DS), %ecx
22569 + movl $(__KERNEL_DS), %ecx
22570 movl %ecx, %ds
22571 movl %ecx, %es
22572 +
22573 + pax_enter_kernel
22574 +
22575 TRACE_IRQS_OFF
22576 movl %esp,%eax # pt_regs pointer
22577 call *%edi
22578 jmp ret_from_exception
22579 CFI_ENDPROC
22580 -END(page_fault)
22581 +ENDPROC(page_fault)
22582
22583 /*
22584 * Debug traps and NMI can happen at the one SYSENTER instruction
22585 @@ -1342,7 +1584,7 @@ debug_stack_correct:
22586 call do_debug
22587 jmp ret_from_exception
22588 CFI_ENDPROC
22589 -END(debug)
22590 +ENDPROC(debug)
22591
22592 /*
22593 * NMI is doubly nasty. It can happen _while_ we're handling
22594 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
22595 xorl %edx,%edx # zero error code
22596 movl %esp,%eax # pt_regs pointer
22597 call do_nmi
22598 +
22599 + pax_exit_kernel
22600 +
22601 jmp restore_all_notrace
22602 CFI_ENDPROC
22603
22604 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22605 FIXUP_ESPFIX_STACK # %eax == %esp
22606 xorl %edx,%edx # zero error code
22607 call do_nmi
22608 +
22609 + pax_exit_kernel
22610 +
22611 RESTORE_REGS
22612 lss 12+4(%esp), %esp # back to espfix stack
22613 CFI_ADJUST_CFA_OFFSET -24
22614 jmp irq_return
22615 CFI_ENDPROC
22616 -END(nmi)
22617 +ENDPROC(nmi)
22618
22619 ENTRY(int3)
22620 RING0_INT_FRAME
22621 @@ -1434,14 +1682,14 @@ ENTRY(int3)
22622 call do_int3
22623 jmp ret_from_exception
22624 CFI_ENDPROC
22625 -END(int3)
22626 +ENDPROC(int3)
22627
22628 ENTRY(general_protection)
22629 RING0_EC_FRAME
22630 pushl_cfi $do_general_protection
22631 jmp error_code
22632 CFI_ENDPROC
22633 -END(general_protection)
22634 +ENDPROC(general_protection)
22635
22636 #ifdef CONFIG_KVM_GUEST
22637 ENTRY(async_page_fault)
22638 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22639 pushl_cfi $do_async_page_fault
22640 jmp error_code
22641 CFI_ENDPROC
22642 -END(async_page_fault)
22643 +ENDPROC(async_page_fault)
22644 #endif
22645
22646 /*
22647 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22648 index 1e96c36..3ff710a 100644
22649 --- a/arch/x86/kernel/entry_64.S
22650 +++ b/arch/x86/kernel/entry_64.S
22651 @@ -59,6 +59,8 @@
22652 #include <asm/context_tracking.h>
22653 #include <asm/smap.h>
22654 #include <linux/err.h>
22655 +#include <asm/pgtable.h>
22656 +#include <asm/alternative-asm.h>
22657
22658 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22659 #include <linux/elf-em.h>
22660 @@ -80,8 +82,9 @@
22661 #ifdef CONFIG_DYNAMIC_FTRACE
22662
22663 ENTRY(function_hook)
22664 + pax_force_retaddr
22665 retq
22666 -END(function_hook)
22667 +ENDPROC(function_hook)
22668
22669 /* skip is set if stack has been adjusted */
22670 .macro ftrace_caller_setup skip=0
22671 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22672 #endif
22673
22674 GLOBAL(ftrace_stub)
22675 + pax_force_retaddr
22676 retq
22677 -END(ftrace_caller)
22678 +ENDPROC(ftrace_caller)
22679
22680 ENTRY(ftrace_regs_caller)
22681 /* Save the current flags before compare (in SS location)*/
22682 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22683 popfq
22684 jmp ftrace_stub
22685
22686 -END(ftrace_regs_caller)
22687 +ENDPROC(ftrace_regs_caller)
22688
22689
22690 #else /* ! CONFIG_DYNAMIC_FTRACE */
22691 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22692 #endif
22693
22694 GLOBAL(ftrace_stub)
22695 + pax_force_retaddr
22696 retq
22697
22698 trace:
22699 @@ -225,12 +230,13 @@ trace:
22700 #endif
22701 subq $MCOUNT_INSN_SIZE, %rdi
22702
22703 + pax_force_fptr ftrace_trace_function
22704 call *ftrace_trace_function
22705
22706 MCOUNT_RESTORE_FRAME
22707
22708 jmp ftrace_stub
22709 -END(function_hook)
22710 +ENDPROC(function_hook)
22711 #endif /* CONFIG_DYNAMIC_FTRACE */
22712 #endif /* CONFIG_FUNCTION_TRACER */
22713
22714 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22715
22716 MCOUNT_RESTORE_FRAME
22717
22718 + pax_force_retaddr
22719 retq
22720 -END(ftrace_graph_caller)
22721 +ENDPROC(ftrace_graph_caller)
22722
22723 GLOBAL(return_to_handler)
22724 subq $24, %rsp
22725 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22726 movq 8(%rsp), %rdx
22727 movq (%rsp), %rax
22728 addq $24, %rsp
22729 + pax_force_fptr %rdi
22730 jmp *%rdi
22731 +ENDPROC(return_to_handler)
22732 #endif
22733
22734
22735 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22736 ENDPROC(native_usergs_sysret64)
22737 #endif /* CONFIG_PARAVIRT */
22738
22739 + .macro ljmpq sel, off
22740 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22741 + .byte 0x48; ljmp *1234f(%rip)
22742 + .pushsection .rodata
22743 + .align 16
22744 + 1234: .quad \off; .word \sel
22745 + .popsection
22746 +#else
22747 + pushq $\sel
22748 + pushq $\off
22749 + lretq
22750 +#endif
22751 + .endm
22752 +
22753 + .macro pax_enter_kernel
22754 + pax_set_fptr_mask
22755 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22756 + call pax_enter_kernel
22757 +#endif
22758 + .endm
22759 +
22760 + .macro pax_exit_kernel
22761 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22762 + call pax_exit_kernel
22763 +#endif
22764 +
22765 + .endm
22766 +
22767 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22768 +ENTRY(pax_enter_kernel)
22769 + pushq %rdi
22770 +
22771 +#ifdef CONFIG_PARAVIRT
22772 + PV_SAVE_REGS(CLBR_RDI)
22773 +#endif
22774 +
22775 +#ifdef CONFIG_PAX_KERNEXEC
22776 + GET_CR0_INTO_RDI
22777 + bts $16,%rdi
22778 + jnc 3f
22779 + mov %cs,%edi
22780 + cmp $__KERNEL_CS,%edi
22781 + jnz 2f
22782 +1:
22783 +#endif
22784 +
22785 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22786 + 661: jmp 111f
22787 + .pushsection .altinstr_replacement, "a"
22788 + 662: ASM_NOP2
22789 + .popsection
22790 + .pushsection .altinstructions, "a"
22791 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22792 + .popsection
22793 + GET_CR3_INTO_RDI
22794 + cmp $0,%dil
22795 + jnz 112f
22796 + mov $__KERNEL_DS,%edi
22797 + mov %edi,%ss
22798 + jmp 111f
22799 +112: cmp $1,%dil
22800 + jz 113f
22801 + ud2
22802 +113: sub $4097,%rdi
22803 + bts $63,%rdi
22804 + SET_RDI_INTO_CR3
22805 + mov $__UDEREF_KERNEL_DS,%edi
22806 + mov %edi,%ss
22807 +111:
22808 +#endif
22809 +
22810 +#ifdef CONFIG_PARAVIRT
22811 + PV_RESTORE_REGS(CLBR_RDI)
22812 +#endif
22813 +
22814 + popq %rdi
22815 + pax_force_retaddr
22816 + retq
22817 +
22818 +#ifdef CONFIG_PAX_KERNEXEC
22819 +2: ljmpq __KERNEL_CS,1b
22820 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22821 +4: SET_RDI_INTO_CR0
22822 + jmp 1b
22823 +#endif
22824 +ENDPROC(pax_enter_kernel)
22825 +
22826 +ENTRY(pax_exit_kernel)
22827 + pushq %rdi
22828 +
22829 +#ifdef CONFIG_PARAVIRT
22830 + PV_SAVE_REGS(CLBR_RDI)
22831 +#endif
22832 +
22833 +#ifdef CONFIG_PAX_KERNEXEC
22834 + mov %cs,%rdi
22835 + cmp $__KERNEXEC_KERNEL_CS,%edi
22836 + jz 2f
22837 + GET_CR0_INTO_RDI
22838 + bts $16,%rdi
22839 + jnc 4f
22840 +1:
22841 +#endif
22842 +
22843 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22844 + 661: jmp 111f
22845 + .pushsection .altinstr_replacement, "a"
22846 + 662: ASM_NOP2
22847 + .popsection
22848 + .pushsection .altinstructions, "a"
22849 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22850 + .popsection
22851 + mov %ss,%edi
22852 + cmp $__UDEREF_KERNEL_DS,%edi
22853 + jnz 111f
22854 + GET_CR3_INTO_RDI
22855 + cmp $0,%dil
22856 + jz 112f
22857 + ud2
22858 +112: add $4097,%rdi
22859 + bts $63,%rdi
22860 + SET_RDI_INTO_CR3
22861 + mov $__KERNEL_DS,%edi
22862 + mov %edi,%ss
22863 +111:
22864 +#endif
22865 +
22866 +#ifdef CONFIG_PARAVIRT
22867 + PV_RESTORE_REGS(CLBR_RDI);
22868 +#endif
22869 +
22870 + popq %rdi
22871 + pax_force_retaddr
22872 + retq
22873 +
22874 +#ifdef CONFIG_PAX_KERNEXEC
22875 +2: GET_CR0_INTO_RDI
22876 + btr $16,%rdi
22877 + jnc 4f
22878 + ljmpq __KERNEL_CS,3f
22879 +3: SET_RDI_INTO_CR0
22880 + jmp 1b
22881 +4: ud2
22882 + jmp 4b
22883 +#endif
22884 +ENDPROC(pax_exit_kernel)
22885 +#endif
22886 +
22887 + .macro pax_enter_kernel_user
22888 + pax_set_fptr_mask
22889 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22890 + call pax_enter_kernel_user
22891 +#endif
22892 + .endm
22893 +
22894 + .macro pax_exit_kernel_user
22895 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22896 + call pax_exit_kernel_user
22897 +#endif
22898 +#ifdef CONFIG_PAX_RANDKSTACK
22899 + pushq %rax
22900 + pushq %r11
22901 + call pax_randomize_kstack
22902 + popq %r11
22903 + popq %rax
22904 +#endif
22905 + .endm
22906 +
22907 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22908 +ENTRY(pax_enter_kernel_user)
22909 + pushq %rdi
22910 + pushq %rbx
22911 +
22912 +#ifdef CONFIG_PARAVIRT
22913 + PV_SAVE_REGS(CLBR_RDI)
22914 +#endif
22915 +
22916 + 661: jmp 111f
22917 + .pushsection .altinstr_replacement, "a"
22918 + 662: ASM_NOP2
22919 + .popsection
22920 + .pushsection .altinstructions, "a"
22921 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22922 + .popsection
22923 + GET_CR3_INTO_RDI
22924 + cmp $1,%dil
22925 + jnz 4f
22926 + sub $4097,%rdi
22927 + bts $63,%rdi
22928 + SET_RDI_INTO_CR3
22929 + jmp 3f
22930 +111:
22931 +
22932 + GET_CR3_INTO_RDI
22933 + mov %rdi,%rbx
22934 + add $__START_KERNEL_map,%rbx
22935 + sub phys_base(%rip),%rbx
22936 +
22937 +#ifdef CONFIG_PARAVIRT
22938 + cmpl $0, pv_info+PARAVIRT_enabled
22939 + jz 1f
22940 + pushq %rdi
22941 + i = 0
22942 + .rept USER_PGD_PTRS
22943 + mov i*8(%rbx),%rsi
22944 + mov $0,%sil
22945 + lea i*8(%rbx),%rdi
22946 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22947 + i = i + 1
22948 + .endr
22949 + popq %rdi
22950 + jmp 2f
22951 +1:
22952 +#endif
22953 +
22954 + i = 0
22955 + .rept USER_PGD_PTRS
22956 + movb $0,i*8(%rbx)
22957 + i = i + 1
22958 + .endr
22959 +
22960 +2: SET_RDI_INTO_CR3
22961 +
22962 +#ifdef CONFIG_PAX_KERNEXEC
22963 + GET_CR0_INTO_RDI
22964 + bts $16,%rdi
22965 + SET_RDI_INTO_CR0
22966 +#endif
22967 +
22968 +3:
22969 +
22970 +#ifdef CONFIG_PARAVIRT
22971 + PV_RESTORE_REGS(CLBR_RDI)
22972 +#endif
22973 +
22974 + popq %rbx
22975 + popq %rdi
22976 + pax_force_retaddr
22977 + retq
22978 +4: ud2
22979 +ENDPROC(pax_enter_kernel_user)
22980 +
22981 +ENTRY(pax_exit_kernel_user)
22982 + pushq %rdi
22983 + pushq %rbx
22984 +
22985 +#ifdef CONFIG_PARAVIRT
22986 + PV_SAVE_REGS(CLBR_RDI)
22987 +#endif
22988 +
22989 + GET_CR3_INTO_RDI
22990 + 661: jmp 1f
22991 + .pushsection .altinstr_replacement, "a"
22992 + 662: ASM_NOP2
22993 + .popsection
22994 + .pushsection .altinstructions, "a"
22995 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22996 + .popsection
22997 + cmp $0,%dil
22998 + jnz 3f
22999 + add $4097,%rdi
23000 + bts $63,%rdi
23001 + SET_RDI_INTO_CR3
23002 + jmp 2f
23003 +1:
23004 +
23005 + mov %rdi,%rbx
23006 +
23007 +#ifdef CONFIG_PAX_KERNEXEC
23008 + GET_CR0_INTO_RDI
23009 + btr $16,%rdi
23010 + jnc 3f
23011 + SET_RDI_INTO_CR0
23012 +#endif
23013 +
23014 + add $__START_KERNEL_map,%rbx
23015 + sub phys_base(%rip),%rbx
23016 +
23017 +#ifdef CONFIG_PARAVIRT
23018 + cmpl $0, pv_info+PARAVIRT_enabled
23019 + jz 1f
23020 + i = 0
23021 + .rept USER_PGD_PTRS
23022 + mov i*8(%rbx),%rsi
23023 + mov $0x67,%sil
23024 + lea i*8(%rbx),%rdi
23025 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23026 + i = i + 1
23027 + .endr
23028 + jmp 2f
23029 +1:
23030 +#endif
23031 +
23032 + i = 0
23033 + .rept USER_PGD_PTRS
23034 + movb $0x67,i*8(%rbx)
23035 + i = i + 1
23036 + .endr
23037 +2:
23038 +
23039 +#ifdef CONFIG_PARAVIRT
23040 + PV_RESTORE_REGS(CLBR_RDI)
23041 +#endif
23042 +
23043 + popq %rbx
23044 + popq %rdi
23045 + pax_force_retaddr
23046 + retq
23047 +3: ud2
23048 +ENDPROC(pax_exit_kernel_user)
23049 +#endif
23050 +
23051 + .macro pax_enter_kernel_nmi
23052 + pax_set_fptr_mask
23053 +
23054 +#ifdef CONFIG_PAX_KERNEXEC
23055 + GET_CR0_INTO_RDI
23056 + bts $16,%rdi
23057 + jc 110f
23058 + SET_RDI_INTO_CR0
23059 + or $2,%ebx
23060 +110:
23061 +#endif
23062 +
23063 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23064 + 661: jmp 111f
23065 + .pushsection .altinstr_replacement, "a"
23066 + 662: ASM_NOP2
23067 + .popsection
23068 + .pushsection .altinstructions, "a"
23069 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23070 + .popsection
23071 + GET_CR3_INTO_RDI
23072 + cmp $0,%dil
23073 + jz 111f
23074 + sub $4097,%rdi
23075 + or $4,%ebx
23076 + bts $63,%rdi
23077 + SET_RDI_INTO_CR3
23078 + mov $__UDEREF_KERNEL_DS,%edi
23079 + mov %edi,%ss
23080 +111:
23081 +#endif
23082 + .endm
23083 +
23084 + .macro pax_exit_kernel_nmi
23085 +#ifdef CONFIG_PAX_KERNEXEC
23086 + btr $1,%ebx
23087 + jnc 110f
23088 + GET_CR0_INTO_RDI
23089 + btr $16,%rdi
23090 + SET_RDI_INTO_CR0
23091 +110:
23092 +#endif
23093 +
23094 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23095 + btr $2,%ebx
23096 + jnc 111f
23097 + GET_CR3_INTO_RDI
23098 + add $4097,%rdi
23099 + bts $63,%rdi
23100 + SET_RDI_INTO_CR3
23101 + mov $__KERNEL_DS,%edi
23102 + mov %edi,%ss
23103 +111:
23104 +#endif
23105 + .endm
23106 +
23107 + .macro pax_erase_kstack
23108 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23109 + call pax_erase_kstack
23110 +#endif
23111 + .endm
23112 +
23113 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23114 +ENTRY(pax_erase_kstack)
23115 + pushq %rdi
23116 + pushq %rcx
23117 + pushq %rax
23118 + pushq %r11
23119 +
23120 + GET_THREAD_INFO(%r11)
23121 + mov TI_lowest_stack(%r11), %rdi
23122 + mov $-0xBEEF, %rax
23123 + std
23124 +
23125 +1: mov %edi, %ecx
23126 + and $THREAD_SIZE_asm - 1, %ecx
23127 + shr $3, %ecx
23128 + repne scasq
23129 + jecxz 2f
23130 +
23131 + cmp $2*8, %ecx
23132 + jc 2f
23133 +
23134 + mov $2*8, %ecx
23135 + repe scasq
23136 + jecxz 2f
23137 + jne 1b
23138 +
23139 +2: cld
23140 + mov %esp, %ecx
23141 + sub %edi, %ecx
23142 +
23143 + cmp $THREAD_SIZE_asm, %rcx
23144 + jb 3f
23145 + ud2
23146 +3:
23147 +
23148 + shr $3, %ecx
23149 + rep stosq
23150 +
23151 + mov TI_task_thread_sp0(%r11), %rdi
23152 + sub $256, %rdi
23153 + mov %rdi, TI_lowest_stack(%r11)
23154 +
23155 + popq %r11
23156 + popq %rax
23157 + popq %rcx
23158 + popq %rdi
23159 + pax_force_retaddr
23160 + ret
23161 +ENDPROC(pax_erase_kstack)
23162 +#endif
23163
23164 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23165 #ifdef CONFIG_TRACE_IRQFLAGS
23166 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23167 .endm
23168
23169 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23170 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23171 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23172 jnc 1f
23173 TRACE_IRQS_ON_DEBUG
23174 1:
23175 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23176 movq \tmp,R11+\offset(%rsp)
23177 .endm
23178
23179 - .macro FAKE_STACK_FRAME child_rip
23180 - /* push in order ss, rsp, eflags, cs, rip */
23181 - xorl %eax, %eax
23182 - pushq_cfi $__KERNEL_DS /* ss */
23183 - /*CFI_REL_OFFSET ss,0*/
23184 - pushq_cfi %rax /* rsp */
23185 - CFI_REL_OFFSET rsp,0
23186 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23187 - /*CFI_REL_OFFSET rflags,0*/
23188 - pushq_cfi $__KERNEL_CS /* cs */
23189 - /*CFI_REL_OFFSET cs,0*/
23190 - pushq_cfi \child_rip /* rip */
23191 - CFI_REL_OFFSET rip,0
23192 - pushq_cfi %rax /* orig rax */
23193 - .endm
23194 -
23195 - .macro UNFAKE_STACK_FRAME
23196 - addq $8*6, %rsp
23197 - CFI_ADJUST_CFA_OFFSET -(6*8)
23198 - .endm
23199 -
23200 /*
23201 * initial frame state for interrupts (and exceptions without error code)
23202 */
23203 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23204 /* save partial stack frame */
23205 .macro SAVE_ARGS_IRQ
23206 cld
23207 - /* start from rbp in pt_regs and jump over */
23208 - movq_cfi rdi, (RDI-RBP)
23209 - movq_cfi rsi, (RSI-RBP)
23210 - movq_cfi rdx, (RDX-RBP)
23211 - movq_cfi rcx, (RCX-RBP)
23212 - movq_cfi rax, (RAX-RBP)
23213 - movq_cfi r8, (R8-RBP)
23214 - movq_cfi r9, (R9-RBP)
23215 - movq_cfi r10, (R10-RBP)
23216 - movq_cfi r11, (R11-RBP)
23217 + /* start from r15 in pt_regs and jump over */
23218 + movq_cfi rdi, RDI
23219 + movq_cfi rsi, RSI
23220 + movq_cfi rdx, RDX
23221 + movq_cfi rcx, RCX
23222 + movq_cfi rax, RAX
23223 + movq_cfi r8, R8
23224 + movq_cfi r9, R9
23225 + movq_cfi r10, R10
23226 + movq_cfi r11, R11
23227 + movq_cfi r12, R12
23228
23229 /* Save rbp so that we can unwind from get_irq_regs() */
23230 - movq_cfi rbp, 0
23231 + movq_cfi rbp, RBP
23232
23233 /* Save previous stack value */
23234 movq %rsp, %rsi
23235
23236 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23237 - testl $3, CS-RBP(%rsi)
23238 + movq %rsp,%rdi /* arg1 for handler */
23239 + testb $3, CS(%rsi)
23240 je 1f
23241 SWAPGS
23242 /*
23243 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23244 0x06 /* DW_OP_deref */, \
23245 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23246 0x22 /* DW_OP_plus */
23247 +
23248 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23249 + testb $3, CS(%rdi)
23250 + jnz 1f
23251 + pax_enter_kernel
23252 + jmp 2f
23253 +1: pax_enter_kernel_user
23254 +2:
23255 +#else
23256 + pax_enter_kernel
23257 +#endif
23258 +
23259 /* We entered an interrupt context - irqs are off: */
23260 TRACE_IRQS_OFF
23261 .endm
23262 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23263 js 1f /* negative -> in kernel */
23264 SWAPGS
23265 xorl %ebx,%ebx
23266 -1: ret
23267 +1:
23268 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23269 + testb $3, CS+8(%rsp)
23270 + jnz 1f
23271 + pax_enter_kernel
23272 + jmp 2f
23273 +1: pax_enter_kernel_user
23274 +2:
23275 +#else
23276 + pax_enter_kernel
23277 +#endif
23278 + pax_force_retaddr
23279 + ret
23280 CFI_ENDPROC
23281 -END(save_paranoid)
23282 +ENDPROC(save_paranoid)
23283 +
23284 +ENTRY(save_paranoid_nmi)
23285 + XCPT_FRAME 1 RDI+8
23286 + cld
23287 + movq_cfi rdi, RDI+8
23288 + movq_cfi rsi, RSI+8
23289 + movq_cfi rdx, RDX+8
23290 + movq_cfi rcx, RCX+8
23291 + movq_cfi rax, RAX+8
23292 + movq_cfi r8, R8+8
23293 + movq_cfi r9, R9+8
23294 + movq_cfi r10, R10+8
23295 + movq_cfi r11, R11+8
23296 + movq_cfi rbx, RBX+8
23297 + movq_cfi rbp, RBP+8
23298 + movq_cfi r12, R12+8
23299 + movq_cfi r13, R13+8
23300 + movq_cfi r14, R14+8
23301 + movq_cfi r15, R15+8
23302 + movl $1,%ebx
23303 + movl $MSR_GS_BASE,%ecx
23304 + rdmsr
23305 + testl %edx,%edx
23306 + js 1f /* negative -> in kernel */
23307 + SWAPGS
23308 + xorl %ebx,%ebx
23309 +1: pax_enter_kernel_nmi
23310 + pax_force_retaddr
23311 + ret
23312 + CFI_ENDPROC
23313 +ENDPROC(save_paranoid_nmi)
23314 .popsection
23315
23316 /*
23317 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23318
23319 RESTORE_REST
23320
23321 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23322 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23323 jz 1f
23324
23325 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23326 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23327 jmp ret_from_sys_call # go to the SYSRET fastpath
23328
23329 1:
23330 - subq $REST_SKIP, %rsp # leave space for volatiles
23331 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23332 movq %rbp, %rdi
23333 call *%rbx
23334 movl $0, RAX(%rsp)
23335 RESTORE_REST
23336 jmp int_ret_from_sys_call
23337 CFI_ENDPROC
23338 -END(ret_from_fork)
23339 +ENDPROC(ret_from_fork)
23340
23341 /*
23342 * System call entry. Up to 6 arguments in registers are supported.
23343 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23344 ENTRY(system_call)
23345 CFI_STARTPROC simple
23346 CFI_SIGNAL_FRAME
23347 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23348 + CFI_DEF_CFA rsp,0
23349 CFI_REGISTER rip,rcx
23350 /*CFI_REGISTER rflags,r11*/
23351 SWAPGS_UNSAFE_STACK
23352 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23353
23354 movq %rsp,PER_CPU_VAR(old_rsp)
23355 movq PER_CPU_VAR(kernel_stack),%rsp
23356 + SAVE_ARGS 8*6,0
23357 + pax_enter_kernel_user
23358 +
23359 +#ifdef CONFIG_PAX_RANDKSTACK
23360 + pax_erase_kstack
23361 +#endif
23362 +
23363 /*
23364 * No need to follow this irqs off/on section - it's straight
23365 * and short:
23366 */
23367 ENABLE_INTERRUPTS(CLBR_NONE)
23368 - SAVE_ARGS 8,0
23369 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23370 movq %rcx,RIP-ARGOFFSET(%rsp)
23371 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23372 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23373 + GET_THREAD_INFO(%rcx)
23374 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23375 jnz tracesys
23376 system_call_fastpath:
23377 #if __SYSCALL_MASK == ~0
23378 @@ -639,10 +1112,13 @@ sysret_check:
23379 LOCKDEP_SYS_EXIT
23380 DISABLE_INTERRUPTS(CLBR_NONE)
23381 TRACE_IRQS_OFF
23382 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23383 + GET_THREAD_INFO(%rcx)
23384 + movl TI_flags(%rcx),%edx
23385 andl %edi,%edx
23386 jnz sysret_careful
23387 CFI_REMEMBER_STATE
23388 + pax_exit_kernel_user
23389 + pax_erase_kstack
23390 /*
23391 * sysretq will re-enable interrupts:
23392 */
23393 @@ -701,6 +1177,9 @@ auditsys:
23394 movq %rax,%rsi /* 2nd arg: syscall number */
23395 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23396 call __audit_syscall_entry
23397 +
23398 + pax_erase_kstack
23399 +
23400 LOAD_ARGS 0 /* reload call-clobbered registers */
23401 jmp system_call_fastpath
23402
23403 @@ -722,7 +1201,7 @@ sysret_audit:
23404 /* Do syscall tracing */
23405 tracesys:
23406 #ifdef CONFIG_AUDITSYSCALL
23407 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23408 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23409 jz auditsys
23410 #endif
23411 SAVE_REST
23412 @@ -730,12 +1209,15 @@ tracesys:
23413 FIXUP_TOP_OF_STACK %rdi
23414 movq %rsp,%rdi
23415 call syscall_trace_enter
23416 +
23417 + pax_erase_kstack
23418 +
23419 /*
23420 * Reload arg registers from stack in case ptrace changed them.
23421 * We don't reload %rax because syscall_trace_enter() returned
23422 * the value it wants us to use in the table lookup.
23423 */
23424 - LOAD_ARGS ARGOFFSET, 1
23425 + LOAD_ARGS 1
23426 RESTORE_REST
23427 #if __SYSCALL_MASK == ~0
23428 cmpq $__NR_syscall_max,%rax
23429 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23430 andl %edi,%edx
23431 jnz int_careful
23432 andl $~TS_COMPAT,TI_status(%rcx)
23433 - jmp retint_swapgs
23434 + pax_exit_kernel_user
23435 + pax_erase_kstack
23436 + jmp retint_swapgs_pax
23437
23438 /* Either reschedule or signal or syscall exit tracking needed. */
23439 /* First do a reschedule test. */
23440 @@ -811,7 +1295,7 @@ int_restore_rest:
23441 TRACE_IRQS_OFF
23442 jmp int_with_check
23443 CFI_ENDPROC
23444 -END(system_call)
23445 +ENDPROC(system_call)
23446
23447 .macro FORK_LIKE func
23448 ENTRY(stub_\func)
23449 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23450 DEFAULT_FRAME 0 8 /* offset 8: return address */
23451 call sys_\func
23452 RESTORE_TOP_OF_STACK %r11, 8
23453 - ret $REST_SKIP /* pop extended registers */
23454 + pax_force_retaddr
23455 + ret
23456 CFI_ENDPROC
23457 -END(stub_\func)
23458 +ENDPROC(stub_\func)
23459 .endm
23460
23461 .macro FIXED_FRAME label,func
23462 @@ -836,9 +1321,10 @@ ENTRY(\label)
23463 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23464 call \func
23465 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23466 + pax_force_retaddr
23467 ret
23468 CFI_ENDPROC
23469 -END(\label)
23470 +ENDPROC(\label)
23471 .endm
23472
23473 FORK_LIKE clone
23474 @@ -846,19 +1332,6 @@ END(\label)
23475 FORK_LIKE vfork
23476 FIXED_FRAME stub_iopl, sys_iopl
23477
23478 -ENTRY(ptregscall_common)
23479 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23480 - RESTORE_TOP_OF_STACK %r11, 8
23481 - movq_cfi_restore R15+8, r15
23482 - movq_cfi_restore R14+8, r14
23483 - movq_cfi_restore R13+8, r13
23484 - movq_cfi_restore R12+8, r12
23485 - movq_cfi_restore RBP+8, rbp
23486 - movq_cfi_restore RBX+8, rbx
23487 - ret $REST_SKIP /* pop extended registers */
23488 - CFI_ENDPROC
23489 -END(ptregscall_common)
23490 -
23491 ENTRY(stub_execve)
23492 CFI_STARTPROC
23493 addq $8, %rsp
23494 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23495 RESTORE_REST
23496 jmp int_ret_from_sys_call
23497 CFI_ENDPROC
23498 -END(stub_execve)
23499 +ENDPROC(stub_execve)
23500
23501 /*
23502 * sigreturn is special because it needs to restore all registers on return.
23503 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23504 RESTORE_REST
23505 jmp int_ret_from_sys_call
23506 CFI_ENDPROC
23507 -END(stub_rt_sigreturn)
23508 +ENDPROC(stub_rt_sigreturn)
23509
23510 #ifdef CONFIG_X86_X32_ABI
23511 ENTRY(stub_x32_rt_sigreturn)
23512 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23513 RESTORE_REST
23514 jmp int_ret_from_sys_call
23515 CFI_ENDPROC
23516 -END(stub_x32_rt_sigreturn)
23517 +ENDPROC(stub_x32_rt_sigreturn)
23518
23519 ENTRY(stub_x32_execve)
23520 CFI_STARTPROC
23521 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23522 RESTORE_REST
23523 jmp int_ret_from_sys_call
23524 CFI_ENDPROC
23525 -END(stub_x32_execve)
23526 +ENDPROC(stub_x32_execve)
23527
23528 #endif
23529
23530 @@ -952,7 +1425,7 @@ vector=vector+1
23531 2: jmp common_interrupt
23532 .endr
23533 CFI_ENDPROC
23534 -END(irq_entries_start)
23535 +ENDPROC(irq_entries_start)
23536
23537 .previous
23538 END(interrupt)
23539 @@ -969,8 +1442,8 @@ END(interrupt)
23540 /* 0(%rsp): ~(interrupt number) */
23541 .macro interrupt func
23542 /* reserve pt_regs for scratch regs and rbp */
23543 - subq $ORIG_RAX-RBP, %rsp
23544 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23545 + subq $ORIG_RAX, %rsp
23546 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23547 SAVE_ARGS_IRQ
23548 call \func
23549 .endm
23550 @@ -997,14 +1470,14 @@ ret_from_intr:
23551
23552 /* Restore saved previous stack */
23553 popq %rsi
23554 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23555 - leaq ARGOFFSET-RBP(%rsi), %rsp
23556 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23557 + movq %rsi, %rsp
23558 CFI_DEF_CFA_REGISTER rsp
23559 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23560 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23561
23562 exit_intr:
23563 GET_THREAD_INFO(%rcx)
23564 - testl $3,CS-ARGOFFSET(%rsp)
23565 + testb $3,CS-ARGOFFSET(%rsp)
23566 je retint_kernel
23567
23568 /* Interrupt came from user space */
23569 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23570 * The iretq could re-enable interrupts:
23571 */
23572 DISABLE_INTERRUPTS(CLBR_ANY)
23573 + pax_exit_kernel_user
23574 +retint_swapgs_pax:
23575 TRACE_IRQS_IRETQ
23576 SWAPGS
23577 jmp restore_args
23578
23579 retint_restore_args: /* return to kernel space */
23580 DISABLE_INTERRUPTS(CLBR_ANY)
23581 + pax_exit_kernel
23582 + pax_force_retaddr (RIP-ARGOFFSET)
23583 /*
23584 * The iretq could re-enable interrupts:
23585 */
23586 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23587 #endif
23588
23589 CFI_ENDPROC
23590 -END(common_interrupt)
23591 +ENDPROC(common_interrupt)
23592 /*
23593 * End of kprobes section
23594 */
23595 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23596 interrupt \do_sym
23597 jmp ret_from_intr
23598 CFI_ENDPROC
23599 -END(\sym)
23600 +ENDPROC(\sym)
23601 .endm
23602
23603 #ifdef CONFIG_TRACING
23604 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23605 call \do_sym
23606 jmp error_exit /* %ebx: no swapgs flag */
23607 CFI_ENDPROC
23608 -END(\sym)
23609 +ENDPROC(\sym)
23610 .endm
23611
23612 .macro paranoidzeroentry sym do_sym
23613 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23614 call \do_sym
23615 jmp paranoid_exit /* %ebx: no swapgs flag */
23616 CFI_ENDPROC
23617 -END(\sym)
23618 +ENDPROC(\sym)
23619 .endm
23620
23621 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23622 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23623 .macro paranoidzeroentry_ist sym do_sym ist
23624 ENTRY(\sym)
23625 INTR_FRAME
23626 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23627 TRACE_IRQS_OFF_DEBUG
23628 movq %rsp,%rdi /* pt_regs pointer */
23629 xorl %esi,%esi /* no error code */
23630 +#ifdef CONFIG_SMP
23631 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23632 + lea init_tss(%r13), %r13
23633 +#else
23634 + lea init_tss(%rip), %r13
23635 +#endif
23636 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23637 call \do_sym
23638 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23639 jmp paranoid_exit /* %ebx: no swapgs flag */
23640 CFI_ENDPROC
23641 -END(\sym)
23642 +ENDPROC(\sym)
23643 .endm
23644
23645 .macro errorentry sym do_sym
23646 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23647 call \do_sym
23648 jmp error_exit /* %ebx: no swapgs flag */
23649 CFI_ENDPROC
23650 -END(\sym)
23651 +ENDPROC(\sym)
23652 .endm
23653
23654 #ifdef CONFIG_TRACING
23655 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23656 call \do_sym
23657 jmp paranoid_exit /* %ebx: no swapgs flag */
23658 CFI_ENDPROC
23659 -END(\sym)
23660 +ENDPROC(\sym)
23661 .endm
23662
23663 zeroentry divide_error do_divide_error
23664 @@ -1336,9 +1819,10 @@ gs_change:
23665 2: mfence /* workaround */
23666 SWAPGS
23667 popfq_cfi
23668 + pax_force_retaddr
23669 ret
23670 CFI_ENDPROC
23671 -END(native_load_gs_index)
23672 +ENDPROC(native_load_gs_index)
23673
23674 _ASM_EXTABLE(gs_change,bad_gs)
23675 .section .fixup,"ax"
23676 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23677 CFI_DEF_CFA_REGISTER rsp
23678 CFI_ADJUST_CFA_OFFSET -8
23679 decl PER_CPU_VAR(irq_count)
23680 + pax_force_retaddr
23681 ret
23682 CFI_ENDPROC
23683 -END(do_softirq_own_stack)
23684 +ENDPROC(do_softirq_own_stack)
23685
23686 #ifdef CONFIG_XEN
23687 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23688 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23689 decl PER_CPU_VAR(irq_count)
23690 jmp error_exit
23691 CFI_ENDPROC
23692 -END(xen_do_hypervisor_callback)
23693 +ENDPROC(xen_do_hypervisor_callback)
23694
23695 /*
23696 * Hypervisor uses this for application faults while it executes.
23697 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23698 SAVE_ALL
23699 jmp error_exit
23700 CFI_ENDPROC
23701 -END(xen_failsafe_callback)
23702 +ENDPROC(xen_failsafe_callback)
23703
23704 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23705 xen_hvm_callback_vector xen_evtchn_do_upcall
23706 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23707 DEFAULT_FRAME
23708 DISABLE_INTERRUPTS(CLBR_NONE)
23709 TRACE_IRQS_OFF_DEBUG
23710 - testl %ebx,%ebx /* swapgs needed? */
23711 + testl $1,%ebx /* swapgs needed? */
23712 jnz paranoid_restore
23713 - testl $3,CS(%rsp)
23714 + testb $3,CS(%rsp)
23715 jnz paranoid_userspace
23716 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23717 + pax_exit_kernel
23718 + TRACE_IRQS_IRETQ 0
23719 + SWAPGS_UNSAFE_STACK
23720 + RESTORE_ALL 8
23721 + pax_force_retaddr_bts
23722 + jmp irq_return
23723 +#endif
23724 paranoid_swapgs:
23725 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23726 + pax_exit_kernel_user
23727 +#else
23728 + pax_exit_kernel
23729 +#endif
23730 TRACE_IRQS_IRETQ 0
23731 SWAPGS_UNSAFE_STACK
23732 RESTORE_ALL 8
23733 jmp irq_return
23734 paranoid_restore:
23735 + pax_exit_kernel
23736 TRACE_IRQS_IRETQ_DEBUG 0
23737 RESTORE_ALL 8
23738 + pax_force_retaddr_bts
23739 jmp irq_return
23740 paranoid_userspace:
23741 GET_THREAD_INFO(%rcx)
23742 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23743 TRACE_IRQS_OFF
23744 jmp paranoid_userspace
23745 CFI_ENDPROC
23746 -END(paranoid_exit)
23747 +ENDPROC(paranoid_exit)
23748
23749 /*
23750 * Exception entry point. This expects an error code/orig_rax on the stack.
23751 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23752 movq_cfi r14, R14+8
23753 movq_cfi r15, R15+8
23754 xorl %ebx,%ebx
23755 - testl $3,CS+8(%rsp)
23756 + testb $3,CS+8(%rsp)
23757 je error_kernelspace
23758 error_swapgs:
23759 SWAPGS
23760 error_sti:
23761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23762 + testb $3, CS+8(%rsp)
23763 + jnz 1f
23764 + pax_enter_kernel
23765 + jmp 2f
23766 +1: pax_enter_kernel_user
23767 +2:
23768 +#else
23769 + pax_enter_kernel
23770 +#endif
23771 TRACE_IRQS_OFF
23772 + pax_force_retaddr
23773 ret
23774
23775 /*
23776 @@ -1616,7 +2127,7 @@ bstep_iret:
23777 movq %rcx,RIP+8(%rsp)
23778 jmp error_swapgs
23779 CFI_ENDPROC
23780 -END(error_entry)
23781 +ENDPROC(error_entry)
23782
23783
23784 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23785 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23786 DISABLE_INTERRUPTS(CLBR_NONE)
23787 TRACE_IRQS_OFF
23788 GET_THREAD_INFO(%rcx)
23789 - testl %eax,%eax
23790 + testl $1,%eax
23791 jne retint_kernel
23792 LOCKDEP_SYS_EXIT_IRQ
23793 movl TI_flags(%rcx),%edx
23794 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23795 jnz retint_careful
23796 jmp retint_swapgs
23797 CFI_ENDPROC
23798 -END(error_exit)
23799 +ENDPROC(error_exit)
23800
23801 /*
23802 * Test if a given stack is an NMI stack or not.
23803 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23804 * If %cs was not the kernel segment, then the NMI triggered in user
23805 * space, which means it is definitely not nested.
23806 */
23807 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23808 + je 1f
23809 cmpl $__KERNEL_CS, 16(%rsp)
23810 jne first_nmi
23811 -
23812 +1:
23813 /*
23814 * Check the special variable on the stack to see if NMIs are
23815 * executing.
23816 @@ -1730,8 +2243,7 @@ nested_nmi:
23817
23818 1:
23819 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23820 - leaq -1*8(%rsp), %rdx
23821 - movq %rdx, %rsp
23822 + subq $8, %rsp
23823 CFI_ADJUST_CFA_OFFSET 1*8
23824 leaq -10*8(%rsp), %rdx
23825 pushq_cfi $__KERNEL_DS
23826 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23827 CFI_RESTORE rdx
23828
23829 /* No need to check faults here */
23830 +# pax_force_retaddr_bts
23831 INTERRUPT_RETURN
23832
23833 CFI_RESTORE_STATE
23834 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23835 subq $ORIG_RAX-R15, %rsp
23836 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23837 /*
23838 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23839 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23840 * as we should not be calling schedule in NMI context.
23841 * Even with normal interrupts enabled. An NMI should not be
23842 * setting NEED_RESCHED or anything that normal interrupts and
23843 * exceptions might do.
23844 */
23845 - call save_paranoid
23846 + call save_paranoid_nmi
23847 DEFAULT_FRAME 0
23848
23849 /*
23850 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23851 * NMI itself takes a page fault, the page fault that was preempted
23852 * will read the information from the NMI page fault and not the
23853 * origin fault. Save it off and restore it if it changes.
23854 - * Use the r12 callee-saved register.
23855 + * Use the r13 callee-saved register.
23856 */
23857 - movq %cr2, %r12
23858 + movq %cr2, %r13
23859
23860 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23861 movq %rsp,%rdi
23862 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
23863
23864 /* Did the NMI take a page fault? Restore cr2 if it did */
23865 movq %cr2, %rcx
23866 - cmpq %rcx, %r12
23867 + cmpq %rcx, %r13
23868 je 1f
23869 - movq %r12, %cr2
23870 + movq %r13, %cr2
23871 1:
23872
23873 - testl %ebx,%ebx /* swapgs needed? */
23874 + testl $1,%ebx /* swapgs needed? */
23875 jnz nmi_restore
23876 nmi_swapgs:
23877 SWAPGS_UNSAFE_STACK
23878 nmi_restore:
23879 + pax_exit_kernel_nmi
23880 /* Pop the extra iret frame at once */
23881 RESTORE_ALL 6*8
23882 + testb $3, 8(%rsp)
23883 + jnz 1f
23884 + pax_force_retaddr_bts
23885 +1:
23886
23887 /* Clear the NMI executing stack variable */
23888 movq $0, 5*8(%rsp)
23889 jmp irq_return
23890 CFI_ENDPROC
23891 -END(nmi)
23892 +ENDPROC(nmi)
23893
23894 ENTRY(ignore_sysret)
23895 CFI_STARTPROC
23896 mov $-ENOSYS,%eax
23897 sysret
23898 CFI_ENDPROC
23899 -END(ignore_sysret)
23900 +ENDPROC(ignore_sysret)
23901
23902 /*
23903 * End of kprobes section
23904 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23905 index e625319..b9abb9d 100644
23906 --- a/arch/x86/kernel/ftrace.c
23907 +++ b/arch/x86/kernel/ftrace.c
23908 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23909 {
23910 unsigned char replaced[MCOUNT_INSN_SIZE];
23911
23912 + ip = ktla_ktva(ip);
23913 +
23914 /*
23915 * Note: Due to modules and __init, code can
23916 * disappear and change, we need to protect against faulting
23917 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23918 unsigned char old[MCOUNT_INSN_SIZE];
23919 int ret;
23920
23921 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23922 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23923
23924 ftrace_update_func = ip;
23925 /* Make sure the breakpoints see the ftrace_update_func update */
23926 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23927 * kernel identity mapping to modify code.
23928 */
23929 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23930 - ip = (unsigned long)__va(__pa_symbol(ip));
23931 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23932
23933 return probe_kernel_write((void *)ip, val, size);
23934 }
23935 @@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23936 unsigned char replaced[MCOUNT_INSN_SIZE];
23937 unsigned char brk = BREAKPOINT_INSTRUCTION;
23938
23939 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23940 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23941 return -EFAULT;
23942
23943 /* Make sure it is what we expect it to be */
23944 @@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23945 return ret;
23946
23947 fail_update:
23948 - probe_kernel_write((void *)ip, &old_code[0], 1);
23949 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23950 goto out;
23951 }
23952
23953 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23954 index 85126cc..1bbce17 100644
23955 --- a/arch/x86/kernel/head64.c
23956 +++ b/arch/x86/kernel/head64.c
23957 @@ -67,12 +67,12 @@ again:
23958 pgd = *pgd_p;
23959
23960 /*
23961 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23962 - * critical -- __PAGE_OFFSET would point us back into the dynamic
23963 + * The use of __early_va rather than __va here is critical:
23964 + * __va would point us back into the dynamic
23965 * range and we might end up looping forever...
23966 */
23967 if (pgd)
23968 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23969 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23970 else {
23971 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23972 reset_early_page_tables();
23973 @@ -82,13 +82,13 @@ again:
23974 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23975 for (i = 0; i < PTRS_PER_PUD; i++)
23976 pud_p[i] = 0;
23977 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23978 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23979 }
23980 pud_p += pud_index(address);
23981 pud = *pud_p;
23982
23983 if (pud)
23984 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23985 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23986 else {
23987 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23988 reset_early_page_tables();
23989 @@ -98,7 +98,7 @@ again:
23990 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23991 for (i = 0; i < PTRS_PER_PMD; i++)
23992 pmd_p[i] = 0;
23993 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23994 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23995 }
23996 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23997 pmd_p[pmd_index(address)] = pmd;
23998 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23999 if (console_loglevel == 10)
24000 early_printk("Kernel alive\n");
24001
24002 - clear_page(init_level4_pgt);
24003 /* set init_level4_pgt kernel high mapping*/
24004 init_level4_pgt[511] = early_level4_pgt[511];
24005
24006 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24007 index 81ba276..30c5411 100644
24008 --- a/arch/x86/kernel/head_32.S
24009 +++ b/arch/x86/kernel/head_32.S
24010 @@ -26,6 +26,12 @@
24011 /* Physical address */
24012 #define pa(X) ((X) - __PAGE_OFFSET)
24013
24014 +#ifdef CONFIG_PAX_KERNEXEC
24015 +#define ta(X) (X)
24016 +#else
24017 +#define ta(X) ((X) - __PAGE_OFFSET)
24018 +#endif
24019 +
24020 /*
24021 * References to members of the new_cpu_data structure.
24022 */
24023 @@ -55,11 +61,7 @@
24024 * and small than max_low_pfn, otherwise will waste some page table entries
24025 */
24026
24027 -#if PTRS_PER_PMD > 1
24028 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24029 -#else
24030 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24031 -#endif
24032 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24033
24034 /* Number of possible pages in the lowmem region */
24035 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24036 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24037 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24038
24039 /*
24040 + * Real beginning of normal "text" segment
24041 + */
24042 +ENTRY(stext)
24043 +ENTRY(_stext)
24044 +
24045 +/*
24046 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24047 * %esi points to the real-mode code as a 32-bit pointer.
24048 * CS and DS must be 4 GB flat segments, but we don't depend on
24049 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24050 * can.
24051 */
24052 __HEAD
24053 +
24054 +#ifdef CONFIG_PAX_KERNEXEC
24055 + jmp startup_32
24056 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24057 +.fill PAGE_SIZE-5,1,0xcc
24058 +#endif
24059 +
24060 ENTRY(startup_32)
24061 movl pa(stack_start),%ecx
24062
24063 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24064 2:
24065 leal -__PAGE_OFFSET(%ecx),%esp
24066
24067 +#ifdef CONFIG_SMP
24068 + movl $pa(cpu_gdt_table),%edi
24069 + movl $__per_cpu_load,%eax
24070 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24071 + rorl $16,%eax
24072 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24073 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24074 + movl $__per_cpu_end - 1,%eax
24075 + subl $__per_cpu_start,%eax
24076 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24077 +#endif
24078 +
24079 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24080 + movl $NR_CPUS,%ecx
24081 + movl $pa(cpu_gdt_table),%edi
24082 +1:
24083 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24084 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24085 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24086 + addl $PAGE_SIZE_asm,%edi
24087 + loop 1b
24088 +#endif
24089 +
24090 +#ifdef CONFIG_PAX_KERNEXEC
24091 + movl $pa(boot_gdt),%edi
24092 + movl $__LOAD_PHYSICAL_ADDR,%eax
24093 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24094 + rorl $16,%eax
24095 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24096 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24097 + rorl $16,%eax
24098 +
24099 + ljmp $(__BOOT_CS),$1f
24100 +1:
24101 +
24102 + movl $NR_CPUS,%ecx
24103 + movl $pa(cpu_gdt_table),%edi
24104 + addl $__PAGE_OFFSET,%eax
24105 +1:
24106 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24107 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24108 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24109 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24110 + rorl $16,%eax
24111 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24112 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24113 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24114 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24115 + rorl $16,%eax
24116 + addl $PAGE_SIZE_asm,%edi
24117 + loop 1b
24118 +#endif
24119 +
24120 /*
24121 * Clear BSS first so that there are no surprises...
24122 */
24123 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24124 movl %eax, pa(max_pfn_mapped)
24125
24126 /* Do early initialization of the fixmap area */
24127 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24128 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24129 +#ifdef CONFIG_COMPAT_VDSO
24130 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24131 +#else
24132 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24133 +#endif
24134 #else /* Not PAE */
24135
24136 page_pde_offset = (__PAGE_OFFSET >> 20);
24137 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24138 movl %eax, pa(max_pfn_mapped)
24139
24140 /* Do early initialization of the fixmap area */
24141 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24142 - movl %eax,pa(initial_page_table+0xffc)
24143 +#ifdef CONFIG_COMPAT_VDSO
24144 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24145 +#else
24146 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24147 +#endif
24148 #endif
24149
24150 #ifdef CONFIG_PARAVIRT
24151 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24152 cmpl $num_subarch_entries, %eax
24153 jae bad_subarch
24154
24155 - movl pa(subarch_entries)(,%eax,4), %eax
24156 - subl $__PAGE_OFFSET, %eax
24157 - jmp *%eax
24158 + jmp *pa(subarch_entries)(,%eax,4)
24159
24160 bad_subarch:
24161 WEAK(lguest_entry)
24162 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24163 __INITDATA
24164
24165 subarch_entries:
24166 - .long default_entry /* normal x86/PC */
24167 - .long lguest_entry /* lguest hypervisor */
24168 - .long xen_entry /* Xen hypervisor */
24169 - .long default_entry /* Moorestown MID */
24170 + .long ta(default_entry) /* normal x86/PC */
24171 + .long ta(lguest_entry) /* lguest hypervisor */
24172 + .long ta(xen_entry) /* Xen hypervisor */
24173 + .long ta(default_entry) /* Moorestown MID */
24174 num_subarch_entries = (. - subarch_entries) / 4
24175 .previous
24176 #else
24177 @@ -354,6 +426,7 @@ default_entry:
24178 movl pa(mmu_cr4_features),%eax
24179 movl %eax,%cr4
24180
24181 +#ifdef CONFIG_X86_PAE
24182 testb $X86_CR4_PAE, %al # check if PAE is enabled
24183 jz enable_paging
24184
24185 @@ -382,6 +455,9 @@ default_entry:
24186 /* Make changes effective */
24187 wrmsr
24188
24189 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24190 +#endif
24191 +
24192 enable_paging:
24193
24194 /*
24195 @@ -449,14 +525,20 @@ is486:
24196 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24197 movl %eax,%ss # after changing gdt.
24198
24199 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24200 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24201 movl %eax,%ds
24202 movl %eax,%es
24203
24204 movl $(__KERNEL_PERCPU), %eax
24205 movl %eax,%fs # set this cpu's percpu
24206
24207 +#ifdef CONFIG_CC_STACKPROTECTOR
24208 movl $(__KERNEL_STACK_CANARY),%eax
24209 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24210 + movl $(__USER_DS),%eax
24211 +#else
24212 + xorl %eax,%eax
24213 +#endif
24214 movl %eax,%gs
24215
24216 xorl %eax,%eax # Clear LDT
24217 @@ -512,8 +594,11 @@ setup_once:
24218 * relocation. Manually set base address in stack canary
24219 * segment descriptor.
24220 */
24221 - movl $gdt_page,%eax
24222 + movl $cpu_gdt_table,%eax
24223 movl $stack_canary,%ecx
24224 +#ifdef CONFIG_SMP
24225 + addl $__per_cpu_load,%ecx
24226 +#endif
24227 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24228 shrl $16, %ecx
24229 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24230 @@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
24231 /* This is global to keep gas from relaxing the jumps */
24232 ENTRY(early_idt_handler)
24233 cld
24234 - cmpl $2,%ss:early_recursion_flag
24235 + cmpl $1,%ss:early_recursion_flag
24236 je hlt_loop
24237 incl %ss:early_recursion_flag
24238
24239 @@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
24240 pushl (20+6*4)(%esp) /* trapno */
24241 pushl $fault_msg
24242 call printk
24243 -#endif
24244 call dump_stack
24245 +#endif
24246 hlt_loop:
24247 hlt
24248 jmp hlt_loop
24249 @@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
24250 /* This is the default interrupt "handler" :-) */
24251 ALIGN
24252 ignore_int:
24253 - cld
24254 #ifdef CONFIG_PRINTK
24255 + cmpl $2,%ss:early_recursion_flag
24256 + je hlt_loop
24257 + incl %ss:early_recursion_flag
24258 + cld
24259 pushl %eax
24260 pushl %ecx
24261 pushl %edx
24262 @@ -612,9 +700,6 @@ ignore_int:
24263 movl $(__KERNEL_DS),%eax
24264 movl %eax,%ds
24265 movl %eax,%es
24266 - cmpl $2,early_recursion_flag
24267 - je hlt_loop
24268 - incl early_recursion_flag
24269 pushl 16(%esp)
24270 pushl 24(%esp)
24271 pushl 32(%esp)
24272 @@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
24273 /*
24274 * BSS section
24275 */
24276 -__PAGE_ALIGNED_BSS
24277 - .align PAGE_SIZE
24278 #ifdef CONFIG_X86_PAE
24279 +.section .initial_pg_pmd,"a",@progbits
24280 initial_pg_pmd:
24281 .fill 1024*KPMDS,4,0
24282 #else
24283 +.section .initial_page_table,"a",@progbits
24284 ENTRY(initial_page_table)
24285 .fill 1024,4,0
24286 #endif
24287 +.section .initial_pg_fixmap,"a",@progbits
24288 initial_pg_fixmap:
24289 .fill 1024,4,0
24290 +.section .empty_zero_page,"a",@progbits
24291 ENTRY(empty_zero_page)
24292 .fill 4096,1,0
24293 +.section .swapper_pg_dir,"a",@progbits
24294 ENTRY(swapper_pg_dir)
24295 +#ifdef CONFIG_X86_PAE
24296 + .fill 4,8,0
24297 +#else
24298 .fill 1024,4,0
24299 +#endif
24300
24301 /*
24302 * This starts the data section.
24303 */
24304 #ifdef CONFIG_X86_PAE
24305 -__PAGE_ALIGNED_DATA
24306 - /* Page-aligned for the benefit of paravirt? */
24307 - .align PAGE_SIZE
24308 +.section .initial_page_table,"a",@progbits
24309 ENTRY(initial_page_table)
24310 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24311 # if KPMDS == 3
24312 @@ -689,12 +779,20 @@ ENTRY(initial_page_table)
24313 # error "Kernel PMDs should be 1, 2 or 3"
24314 # endif
24315 .align PAGE_SIZE /* needs to be page-sized too */
24316 +
24317 +#ifdef CONFIG_PAX_PER_CPU_PGD
24318 +ENTRY(cpu_pgd)
24319 + .rept 2*NR_CPUS
24320 + .fill 4,8,0
24321 + .endr
24322 +#endif
24323 +
24324 #endif
24325
24326 .data
24327 .balign 4
24328 ENTRY(stack_start)
24329 - .long init_thread_union+THREAD_SIZE
24330 + .long init_thread_union+THREAD_SIZE-8
24331
24332 __INITRODATA
24333 int_msg:
24334 @@ -722,7 +820,7 @@ fault_msg:
24335 * segment size, and 32-bit linear address value:
24336 */
24337
24338 - .data
24339 +.section .rodata,"a",@progbits
24340 .globl boot_gdt_descr
24341 .globl idt_descr
24342
24343 @@ -731,7 +829,7 @@ fault_msg:
24344 .word 0 # 32 bit align gdt_desc.address
24345 boot_gdt_descr:
24346 .word __BOOT_DS+7
24347 - .long boot_gdt - __PAGE_OFFSET
24348 + .long pa(boot_gdt)
24349
24350 .word 0 # 32-bit align idt_desc.address
24351 idt_descr:
24352 @@ -742,7 +840,7 @@ idt_descr:
24353 .word 0 # 32 bit align gdt_desc.address
24354 ENTRY(early_gdt_descr)
24355 .word GDT_ENTRIES*8-1
24356 - .long gdt_page /* Overwritten for secondary CPUs */
24357 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24358
24359 /*
24360 * The boot_gdt must mirror the equivalent in setup.S and is
24361 @@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
24362 .align L1_CACHE_BYTES
24363 ENTRY(boot_gdt)
24364 .fill GDT_ENTRY_BOOT_CS,8,0
24365 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24366 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24367 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24368 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24369 +
24370 + .align PAGE_SIZE_asm
24371 +ENTRY(cpu_gdt_table)
24372 + .rept NR_CPUS
24373 + .quad 0x0000000000000000 /* NULL descriptor */
24374 + .quad 0x0000000000000000 /* 0x0b reserved */
24375 + .quad 0x0000000000000000 /* 0x13 reserved */
24376 + .quad 0x0000000000000000 /* 0x1b reserved */
24377 +
24378 +#ifdef CONFIG_PAX_KERNEXEC
24379 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24380 +#else
24381 + .quad 0x0000000000000000 /* 0x20 unused */
24382 +#endif
24383 +
24384 + .quad 0x0000000000000000 /* 0x28 unused */
24385 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24386 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24387 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24388 + .quad 0x0000000000000000 /* 0x4b reserved */
24389 + .quad 0x0000000000000000 /* 0x53 reserved */
24390 + .quad 0x0000000000000000 /* 0x5b reserved */
24391 +
24392 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24393 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24394 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24395 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24396 +
24397 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24398 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24399 +
24400 + /*
24401 + * Segments used for calling PnP BIOS have byte granularity.
24402 + * The code segments and data segments have fixed 64k limits,
24403 + * the transfer segment sizes are set at run time.
24404 + */
24405 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24406 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24407 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24408 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24409 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24410 +
24411 + /*
24412 + * The APM segments have byte granularity and their bases
24413 + * are set at run time. All have 64k limits.
24414 + */
24415 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24416 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24417 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24418 +
24419 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24420 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24421 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24422 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24423 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24424 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24425 +
24426 + /* Be sure this is zeroed to avoid false validations in Xen */
24427 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24428 + .endr
24429 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24430 index e1aabdb..fee4fee 100644
24431 --- a/arch/x86/kernel/head_64.S
24432 +++ b/arch/x86/kernel/head_64.S
24433 @@ -20,6 +20,8 @@
24434 #include <asm/processor-flags.h>
24435 #include <asm/percpu.h>
24436 #include <asm/nops.h>
24437 +#include <asm/cpufeature.h>
24438 +#include <asm/alternative-asm.h>
24439
24440 #ifdef CONFIG_PARAVIRT
24441 #include <asm/asm-offsets.h>
24442 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24443 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24444 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24445 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24446 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24447 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24448 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24449 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24450 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24451 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24452
24453 .text
24454 __HEAD
24455 @@ -89,11 +97,24 @@ startup_64:
24456 * Fixup the physical addresses in the page table
24457 */
24458 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24459 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24460 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24461 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24462 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24463 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24464
24465 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24466 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24467 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24468 +#ifndef CONFIG_XEN
24469 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24470 +#endif
24471 +
24472 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24473 +
24474 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24475 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24476
24477 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24478 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24479
24480 /*
24481 * Set up the identity mapping for the switchover. These
24482 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24483 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24484 1:
24485
24486 - /* Enable PAE mode and PGE */
24487 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24488 + /* Enable PAE mode and PSE/PGE */
24489 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24490 movq %rcx, %cr4
24491
24492 /* Setup early boot stage 4 level pagetables. */
24493 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24494 movl $MSR_EFER, %ecx
24495 rdmsr
24496 btsl $_EFER_SCE, %eax /* Enable System Call */
24497 - btl $20,%edi /* No Execute supported? */
24498 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24499 jnc 1f
24500 btsl $_EFER_NX, %eax
24501 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24502 +#ifndef CONFIG_EFI
24503 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24504 +#endif
24505 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24506 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24507 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24508 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24509 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24510 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24511 1: wrmsr /* Make changes effective */
24512
24513 /* Setup cr0 */
24514 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24515 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24516 * address given in m16:64.
24517 */
24518 + pax_set_fptr_mask
24519 movq initial_code(%rip),%rax
24520 pushq $0 # fake return address to stop unwinder
24521 pushq $__KERNEL_CS # set correct cs
24522 @@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
24523 call dump_stack
24524 #ifdef CONFIG_KALLSYMS
24525 leaq early_idt_ripmsg(%rip),%rdi
24526 - movq 40(%rsp),%rsi # %rip again
24527 + movq 88(%rsp),%rsi # %rip again
24528 call __print_symbol
24529 #endif
24530 #endif /* EARLY_PRINTK */
24531 @@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
24532 early_recursion_flag:
24533 .long 0
24534
24535 + .section .rodata,"a",@progbits
24536 #ifdef CONFIG_EARLY_PRINTK
24537 early_idt_msg:
24538 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24539 @@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
24540 NEXT_PAGE(early_dynamic_pgts)
24541 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24542
24543 - .data
24544 + .section .rodata,"a",@progbits
24545
24546 -#ifndef CONFIG_XEN
24547 NEXT_PAGE(init_level4_pgt)
24548 - .fill 512,8,0
24549 -#else
24550 -NEXT_PAGE(init_level4_pgt)
24551 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24552 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24553 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24554 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24555 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24556 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24557 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24558 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24559 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24560 .org init_level4_pgt + L4_START_KERNEL*8, 0
24561 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24562 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24563
24564 +#ifdef CONFIG_PAX_PER_CPU_PGD
24565 +NEXT_PAGE(cpu_pgd)
24566 + .rept 2*NR_CPUS
24567 + .fill 512,8,0
24568 + .endr
24569 +#endif
24570 +
24571 NEXT_PAGE(level3_ident_pgt)
24572 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24573 +#ifdef CONFIG_XEN
24574 .fill 511, 8, 0
24575 +#else
24576 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24577 + .fill 510,8,0
24578 +#endif
24579 +
24580 +NEXT_PAGE(level3_vmalloc_start_pgt)
24581 + .fill 512,8,0
24582 +
24583 +NEXT_PAGE(level3_vmalloc_end_pgt)
24584 + .fill 512,8,0
24585 +
24586 +NEXT_PAGE(level3_vmemmap_pgt)
24587 + .fill L3_VMEMMAP_START,8,0
24588 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24589 +
24590 NEXT_PAGE(level2_ident_pgt)
24591 - /* Since I easily can, map the first 1G.
24592 + /* Since I easily can, map the first 2G.
24593 * Don't set NX because code runs from these pages.
24594 */
24595 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24596 -#endif
24597 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24598
24599 NEXT_PAGE(level3_kernel_pgt)
24600 .fill L3_START_KERNEL,8,0
24601 @@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
24602 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24603 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24604
24605 +NEXT_PAGE(level2_vmemmap_pgt)
24606 + .fill 512,8,0
24607 +
24608 NEXT_PAGE(level2_kernel_pgt)
24609 /*
24610 * 512 MB kernel mapping. We spend a full page on this pagetable
24611 @@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
24612 NEXT_PAGE(level2_fixmap_pgt)
24613 .fill 506,8,0
24614 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24615 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24616 - .fill 5,8,0
24617 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24618 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24619 + .fill 4,8,0
24620
24621 NEXT_PAGE(level1_fixmap_pgt)
24622 .fill 512,8,0
24623
24624 +NEXT_PAGE(level1_vsyscall_pgt)
24625 + .fill 512,8,0
24626 +
24627 #undef PMDS
24628
24629 - .data
24630 + .align PAGE_SIZE
24631 +ENTRY(cpu_gdt_table)
24632 + .rept NR_CPUS
24633 + .quad 0x0000000000000000 /* NULL descriptor */
24634 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24635 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24636 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24637 + .quad 0x00cffb000000ffff /* __USER32_CS */
24638 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24639 + .quad 0x00affb000000ffff /* __USER_CS */
24640 +
24641 +#ifdef CONFIG_PAX_KERNEXEC
24642 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24643 +#else
24644 + .quad 0x0 /* unused */
24645 +#endif
24646 +
24647 + .quad 0,0 /* TSS */
24648 + .quad 0,0 /* LDT */
24649 + .quad 0,0,0 /* three TLS descriptors */
24650 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24651 + /* asm/segment.h:GDT_ENTRIES must match this */
24652 +
24653 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24654 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24655 +#else
24656 + .quad 0x0 /* unused */
24657 +#endif
24658 +
24659 + /* zero the remaining page */
24660 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24661 + .endr
24662 +
24663 .align 16
24664 .globl early_gdt_descr
24665 early_gdt_descr:
24666 .word GDT_ENTRIES*8-1
24667 early_gdt_descr_base:
24668 - .quad INIT_PER_CPU_VAR(gdt_page)
24669 + .quad cpu_gdt_table
24670
24671 ENTRY(phys_base)
24672 /* This must match the first entry in level2_kernel_pgt */
24673 .quad 0x0000000000000000
24674
24675 #include "../../x86/xen/xen-head.S"
24676 -
24677 - __PAGE_ALIGNED_BSS
24678 +
24679 + .section .rodata,"a",@progbits
24680 NEXT_PAGE(empty_zero_page)
24681 .skip PAGE_SIZE
24682 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24683 index 05fd74f..c3548b1 100644
24684 --- a/arch/x86/kernel/i386_ksyms_32.c
24685 +++ b/arch/x86/kernel/i386_ksyms_32.c
24686 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24687 EXPORT_SYMBOL(cmpxchg8b_emu);
24688 #endif
24689
24690 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24691 +
24692 /* Networking helper routines. */
24693 EXPORT_SYMBOL(csum_partial_copy_generic);
24694 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24695 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24696
24697 EXPORT_SYMBOL(__get_user_1);
24698 EXPORT_SYMBOL(__get_user_2);
24699 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24700 EXPORT_SYMBOL(___preempt_schedule_context);
24701 #endif
24702 #endif
24703 +
24704 +#ifdef CONFIG_PAX_KERNEXEC
24705 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24706 +#endif
24707 +
24708 +#ifdef CONFIG_PAX_PER_CPU_PGD
24709 +EXPORT_SYMBOL(cpu_pgd);
24710 +#endif
24711 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24712 index e8368c6..9c1a712 100644
24713 --- a/arch/x86/kernel/i387.c
24714 +++ b/arch/x86/kernel/i387.c
24715 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24716 static inline bool interrupted_user_mode(void)
24717 {
24718 struct pt_regs *regs = get_irq_regs();
24719 - return regs && user_mode_vm(regs);
24720 + return regs && user_mode(regs);
24721 }
24722
24723 /*
24724 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24725 index 2e977b5..5f2c273 100644
24726 --- a/arch/x86/kernel/i8259.c
24727 +++ b/arch/x86/kernel/i8259.c
24728 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24729 static void make_8259A_irq(unsigned int irq)
24730 {
24731 disable_irq_nosync(irq);
24732 - io_apic_irqs &= ~(1<<irq);
24733 + io_apic_irqs &= ~(1UL<<irq);
24734 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24735 i8259A_chip.name);
24736 enable_irq(irq);
24737 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24738 "spurious 8259A interrupt: IRQ%d.\n", irq);
24739 spurious_irq_mask |= irqmask;
24740 }
24741 - atomic_inc(&irq_err_count);
24742 + atomic_inc_unchecked(&irq_err_count);
24743 /*
24744 * Theoretically we do not have to handle this IRQ,
24745 * but in Linux this does not cause problems and is
24746 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24747 /* (slave's support for AEOI in flat mode is to be investigated) */
24748 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24749
24750 + pax_open_kernel();
24751 if (auto_eoi)
24752 /*
24753 * In AEOI mode we just have to mask the interrupt
24754 * when acking.
24755 */
24756 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24757 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24758 else
24759 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24760 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24761 + pax_close_kernel();
24762
24763 udelay(100); /* wait for 8259A to initialize */
24764
24765 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24766 index a979b5b..1d6db75 100644
24767 --- a/arch/x86/kernel/io_delay.c
24768 +++ b/arch/x86/kernel/io_delay.c
24769 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24770 * Quirk table for systems that misbehave (lock up, etc.) if port
24771 * 0x80 is used:
24772 */
24773 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24774 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24775 {
24776 .callback = dmi_io_delay_0xed_port,
24777 .ident = "Compaq Presario V6000",
24778 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24779 index 4ddaf66..49d5c18 100644
24780 --- a/arch/x86/kernel/ioport.c
24781 +++ b/arch/x86/kernel/ioport.c
24782 @@ -6,6 +6,7 @@
24783 #include <linux/sched.h>
24784 #include <linux/kernel.h>
24785 #include <linux/capability.h>
24786 +#include <linux/security.h>
24787 #include <linux/errno.h>
24788 #include <linux/types.h>
24789 #include <linux/ioport.h>
24790 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24791 return -EINVAL;
24792 if (turn_on && !capable(CAP_SYS_RAWIO))
24793 return -EPERM;
24794 +#ifdef CONFIG_GRKERNSEC_IO
24795 + if (turn_on && grsec_disable_privio) {
24796 + gr_handle_ioperm();
24797 + return -ENODEV;
24798 + }
24799 +#endif
24800
24801 /*
24802 * If it's the first ioperm() call in this thread's lifetime, set the
24803 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24804 * because the ->io_bitmap_max value must match the bitmap
24805 * contents:
24806 */
24807 - tss = &per_cpu(init_tss, get_cpu());
24808 + tss = init_tss + get_cpu();
24809
24810 if (turn_on)
24811 bitmap_clear(t->io_bitmap_ptr, from, num);
24812 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24813 if (level > old) {
24814 if (!capable(CAP_SYS_RAWIO))
24815 return -EPERM;
24816 +#ifdef CONFIG_GRKERNSEC_IO
24817 + if (grsec_disable_privio) {
24818 + gr_handle_iopl();
24819 + return -ENODEV;
24820 + }
24821 +#endif
24822 }
24823 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24824 t->iopl = level << 12;
24825 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24826 index 22d0687..e07b2a5 100644
24827 --- a/arch/x86/kernel/irq.c
24828 +++ b/arch/x86/kernel/irq.c
24829 @@ -21,7 +21,7 @@
24830 #define CREATE_TRACE_POINTS
24831 #include <asm/trace/irq_vectors.h>
24832
24833 -atomic_t irq_err_count;
24834 +atomic_unchecked_t irq_err_count;
24835
24836 /* Function pointer for generic interrupt vector handling */
24837 void (*x86_platform_ipi_callback)(void) = NULL;
24838 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24839 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24840 seq_printf(p, " Machine check polls\n");
24841 #endif
24842 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24843 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24844 #if defined(CONFIG_X86_IO_APIC)
24845 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24846 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24847 #endif
24848 return 0;
24849 }
24850 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24851
24852 u64 arch_irq_stat(void)
24853 {
24854 - u64 sum = atomic_read(&irq_err_count);
24855 + u64 sum = atomic_read_unchecked(&irq_err_count);
24856 return sum;
24857 }
24858
24859 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24860 index d7fcbed..1f747f7 100644
24861 --- a/arch/x86/kernel/irq_32.c
24862 +++ b/arch/x86/kernel/irq_32.c
24863 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24864 __asm__ __volatile__("andl %%esp,%0" :
24865 "=r" (sp) : "0" (THREAD_SIZE - 1));
24866
24867 - return sp < (sizeof(struct thread_info) + STACK_WARN);
24868 + return sp < STACK_WARN;
24869 }
24870
24871 static void print_stack_overflow(void)
24872 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24873 * per-CPU IRQ handling contexts (thread information and stack)
24874 */
24875 union irq_ctx {
24876 - struct thread_info tinfo;
24877 - u32 stack[THREAD_SIZE/sizeof(u32)];
24878 + unsigned long previous_esp;
24879 + u32 stack[THREAD_SIZE/sizeof(u32)];
24880 } __attribute__((aligned(THREAD_SIZE)));
24881
24882 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24883 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24884 static inline int
24885 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24886 {
24887 - union irq_ctx *curctx, *irqctx;
24888 + union irq_ctx *irqctx;
24889 u32 *isp, arg1, arg2;
24890
24891 - curctx = (union irq_ctx *) current_thread_info();
24892 irqctx = __this_cpu_read(hardirq_ctx);
24893
24894 /*
24895 @@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24896 * handler) we can't do that and just have to keep using the
24897 * current stack (which is the irq stack already after all)
24898 */
24899 - if (unlikely(curctx == irqctx))
24900 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24901 return 0;
24902
24903 /* build the stack frame on the IRQ stack */
24904 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24905 - irqctx->tinfo.task = curctx->tinfo.task;
24906 - irqctx->tinfo.previous_esp = current_stack_pointer;
24907 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24908 + irqctx->previous_esp = current_stack_pointer;
24909 +
24910 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24911 + __set_fs(MAKE_MM_SEG(0));
24912 +#endif
24913
24914 if (unlikely(overflow))
24915 call_on_stack(print_stack_overflow, isp);
24916 @@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24917 : "0" (irq), "1" (desc), "2" (isp),
24918 "D" (desc->handle_irq)
24919 : "memory", "cc", "ecx");
24920 +
24921 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24922 + __set_fs(current_thread_info()->addr_limit);
24923 +#endif
24924 +
24925 return 1;
24926 }
24927
24928 @@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24929 */
24930 void irq_ctx_init(int cpu)
24931 {
24932 - union irq_ctx *irqctx;
24933 -
24934 if (per_cpu(hardirq_ctx, cpu))
24935 return;
24936
24937 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24938 - THREADINFO_GFP,
24939 - THREAD_SIZE_ORDER));
24940 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24941 - irqctx->tinfo.cpu = cpu;
24942 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24943 -
24944 - per_cpu(hardirq_ctx, cpu) = irqctx;
24945 -
24946 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24947 - THREADINFO_GFP,
24948 - THREAD_SIZE_ORDER));
24949 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24950 - irqctx->tinfo.cpu = cpu;
24951 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24952 -
24953 - per_cpu(softirq_ctx, cpu) = irqctx;
24954 -
24955 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24956 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24957 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24958 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24959 }
24960
24961 void do_softirq_own_stack(void)
24962 {
24963 - struct thread_info *curctx;
24964 union irq_ctx *irqctx;
24965 u32 *isp;
24966
24967 - curctx = current_thread_info();
24968 irqctx = __this_cpu_read(softirq_ctx);
24969 - irqctx->tinfo.task = curctx->task;
24970 - irqctx->tinfo.previous_esp = current_stack_pointer;
24971 + irqctx->previous_esp = current_stack_pointer;
24972
24973 /* build the stack frame on the softirq stack */
24974 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24975 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24976 +
24977 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24978 + __set_fs(MAKE_MM_SEG(0));
24979 +#endif
24980
24981 call_on_stack(__do_softirq, isp);
24982 +
24983 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24984 + __set_fs(current_thread_info()->addr_limit);
24985 +#endif
24986 +
24987 }
24988
24989 bool handle_irq(unsigned irq, struct pt_regs *regs)
24990 @@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24991 if (unlikely(!desc))
24992 return false;
24993
24994 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24995 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24996 if (unlikely(overflow))
24997 print_stack_overflow();
24998 desc->handle_irq(irq, desc);
24999 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25000 index 4d1c746..232961d 100644
25001 --- a/arch/x86/kernel/irq_64.c
25002 +++ b/arch/x86/kernel/irq_64.c
25003 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25004 u64 estack_top, estack_bottom;
25005 u64 curbase = (u64)task_stack_page(current);
25006
25007 - if (user_mode_vm(regs))
25008 + if (user_mode(regs))
25009 return;
25010
25011 if (regs->sp >= curbase + sizeof(struct thread_info) +
25012 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25013 index 26d5a55..a01160a 100644
25014 --- a/arch/x86/kernel/jump_label.c
25015 +++ b/arch/x86/kernel/jump_label.c
25016 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25017 * Jump label is enabled for the first time.
25018 * So we expect a default_nop...
25019 */
25020 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25021 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25022 != 0))
25023 bug_at((void *)entry->code, __LINE__);
25024 } else {
25025 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25026 * ...otherwise expect an ideal_nop. Otherwise
25027 * something went horribly wrong.
25028 */
25029 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25030 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25031 != 0))
25032 bug_at((void *)entry->code, __LINE__);
25033 }
25034 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25035 * are converting the default nop to the ideal nop.
25036 */
25037 if (init) {
25038 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25039 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25040 bug_at((void *)entry->code, __LINE__);
25041 } else {
25042 code.jump = 0xe9;
25043 code.offset = entry->target -
25044 (entry->code + JUMP_LABEL_NOP_SIZE);
25045 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25046 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25047 bug_at((void *)entry->code, __LINE__);
25048 }
25049 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25050 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25051 index 836f832..a8bda67 100644
25052 --- a/arch/x86/kernel/kgdb.c
25053 +++ b/arch/x86/kernel/kgdb.c
25054 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25055 #ifdef CONFIG_X86_32
25056 switch (regno) {
25057 case GDB_SS:
25058 - if (!user_mode_vm(regs))
25059 + if (!user_mode(regs))
25060 *(unsigned long *)mem = __KERNEL_DS;
25061 break;
25062 case GDB_SP:
25063 - if (!user_mode_vm(regs))
25064 + if (!user_mode(regs))
25065 *(unsigned long *)mem = kernel_stack_pointer(regs);
25066 break;
25067 case GDB_GS:
25068 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
25069 bp->attr.bp_addr = breakinfo[breakno].addr;
25070 bp->attr.bp_len = breakinfo[breakno].len;
25071 bp->attr.bp_type = breakinfo[breakno].type;
25072 - info->address = breakinfo[breakno].addr;
25073 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25074 + info->address = ktla_ktva(breakinfo[breakno].addr);
25075 + else
25076 + info->address = breakinfo[breakno].addr;
25077 info->len = breakinfo[breakno].len;
25078 info->type = breakinfo[breakno].type;
25079 val = arch_install_hw_breakpoint(bp);
25080 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25081 case 'k':
25082 /* clear the trace bit */
25083 linux_regs->flags &= ~X86_EFLAGS_TF;
25084 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25085 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25086
25087 /* set the trace bit if we're stepping */
25088 if (remcomInBuffer[0] == 's') {
25089 linux_regs->flags |= X86_EFLAGS_TF;
25090 - atomic_set(&kgdb_cpu_doing_single_step,
25091 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25092 raw_smp_processor_id());
25093 }
25094
25095 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25096
25097 switch (cmd) {
25098 case DIE_DEBUG:
25099 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25100 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25101 if (user_mode(regs))
25102 return single_step_cont(regs, args);
25103 break;
25104 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25105 #endif /* CONFIG_DEBUG_RODATA */
25106
25107 bpt->type = BP_BREAKPOINT;
25108 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25109 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25110 BREAK_INSTR_SIZE);
25111 if (err)
25112 return err;
25113 - err = probe_kernel_write((char *)bpt->bpt_addr,
25114 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25115 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25116 #ifdef CONFIG_DEBUG_RODATA
25117 if (!err)
25118 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25119 return -EBUSY;
25120 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25121 BREAK_INSTR_SIZE);
25122 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25123 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25124 if (err)
25125 return err;
25126 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25127 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25128 if (mutex_is_locked(&text_mutex))
25129 goto knl_write;
25130 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25131 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25132 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25133 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25134 goto knl_write;
25135 return err;
25136 knl_write:
25137 #endif /* CONFIG_DEBUG_RODATA */
25138 - return probe_kernel_write((char *)bpt->bpt_addr,
25139 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25140 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25141 }
25142
25143 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25144 index 79a3f96..6ba030a 100644
25145 --- a/arch/x86/kernel/kprobes/core.c
25146 +++ b/arch/x86/kernel/kprobes/core.c
25147 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25148 s32 raddr;
25149 } __packed *insn;
25150
25151 - insn = (struct __arch_relative_insn *)from;
25152 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25153 +
25154 + pax_open_kernel();
25155 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25156 insn->op = op;
25157 + pax_close_kernel();
25158 }
25159
25160 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25161 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25162 kprobe_opcode_t opcode;
25163 kprobe_opcode_t *orig_opcodes = opcodes;
25164
25165 - if (search_exception_tables((unsigned long)opcodes))
25166 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25167 return 0; /* Page fault may occur on this address. */
25168
25169 retry:
25170 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25171 * for the first byte, we can recover the original instruction
25172 * from it and kp->opcode.
25173 */
25174 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25175 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25176 buf[0] = kp->opcode;
25177 - return (unsigned long)buf;
25178 + return ktva_ktla((unsigned long)buf);
25179 }
25180
25181 /*
25182 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25183 /* Another subsystem puts a breakpoint, failed to recover */
25184 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25185 return 0;
25186 + pax_open_kernel();
25187 memcpy(dest, insn.kaddr, insn.length);
25188 + pax_close_kernel();
25189
25190 #ifdef CONFIG_X86_64
25191 if (insn_rip_relative(&insn)) {
25192 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25193 return 0;
25194 }
25195 disp = (u8 *) dest + insn_offset_displacement(&insn);
25196 + pax_open_kernel();
25197 *(s32 *) disp = (s32) newdisp;
25198 + pax_close_kernel();
25199 }
25200 #endif
25201 return insn.length;
25202 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25203 * nor set current_kprobe, because it doesn't use single
25204 * stepping.
25205 */
25206 - regs->ip = (unsigned long)p->ainsn.insn;
25207 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25208 preempt_enable_no_resched();
25209 return;
25210 }
25211 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25212 regs->flags &= ~X86_EFLAGS_IF;
25213 /* single step inline if the instruction is an int3 */
25214 if (p->opcode == BREAKPOINT_INSTRUCTION)
25215 - regs->ip = (unsigned long)p->addr;
25216 + regs->ip = ktla_ktva((unsigned long)p->addr);
25217 else
25218 - regs->ip = (unsigned long)p->ainsn.insn;
25219 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25220 }
25221
25222 /*
25223 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25224 setup_singlestep(p, regs, kcb, 0);
25225 return 1;
25226 }
25227 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25228 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25229 /*
25230 * The breakpoint instruction was removed right
25231 * after we hit it. Another cpu has removed
25232 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25233 " movq %rax, 152(%rsp)\n"
25234 RESTORE_REGS_STRING
25235 " popfq\n"
25236 +#ifdef KERNEXEC_PLUGIN
25237 + " btsq $63,(%rsp)\n"
25238 +#endif
25239 #else
25240 " pushf\n"
25241 SAVE_REGS_STRING
25242 @@ -779,7 +789,7 @@ static void __kprobes
25243 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25244 {
25245 unsigned long *tos = stack_addr(regs);
25246 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25247 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25248 unsigned long orig_ip = (unsigned long)p->addr;
25249 kprobe_opcode_t *insn = p->ainsn.insn;
25250
25251 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25252 struct die_args *args = data;
25253 int ret = NOTIFY_DONE;
25254
25255 - if (args->regs && user_mode_vm(args->regs))
25256 + if (args->regs && user_mode(args->regs))
25257 return ret;
25258
25259 switch (val) {
25260 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25261 index 898160b..758cde8 100644
25262 --- a/arch/x86/kernel/kprobes/opt.c
25263 +++ b/arch/x86/kernel/kprobes/opt.c
25264 @@ -79,6 +79,7 @@ found:
25265 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25266 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25267 {
25268 + pax_open_kernel();
25269 #ifdef CONFIG_X86_64
25270 *addr++ = 0x48;
25271 *addr++ = 0xbf;
25272 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25273 *addr++ = 0xb8;
25274 #endif
25275 *(unsigned long *)addr = val;
25276 + pax_close_kernel();
25277 }
25278
25279 asm (
25280 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25281 * Verify if the address gap is in 2GB range, because this uses
25282 * a relative jump.
25283 */
25284 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25285 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25286 if (abs(rel) > 0x7fffffff)
25287 return -ERANGE;
25288
25289 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25290 op->optinsn.size = ret;
25291
25292 /* Copy arch-dep-instance from template */
25293 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25294 + pax_open_kernel();
25295 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25296 + pax_close_kernel();
25297
25298 /* Set probe information */
25299 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25300
25301 /* Set probe function call */
25302 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25303 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25304
25305 /* Set returning jmp instruction at the tail of out-of-line buffer */
25306 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25307 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25308 (u8 *)op->kp.addr + op->optinsn.size);
25309
25310 flush_icache_range((unsigned long) buf,
25311 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25312 WARN_ON(kprobe_disabled(&op->kp));
25313
25314 /* Backup instructions which will be replaced by jump address */
25315 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25316 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25317 RELATIVE_ADDR_SIZE);
25318
25319 insn_buf[0] = RELATIVEJUMP_OPCODE;
25320 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25321 /* This kprobe is really able to run optimized path. */
25322 op = container_of(p, struct optimized_kprobe, kp);
25323 /* Detour through copied instructions */
25324 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25325 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25326 if (!reenter)
25327 reset_current_kprobe();
25328 preempt_enable_no_resched();
25329 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25330 index ebc9873..1b9724b 100644
25331 --- a/arch/x86/kernel/ldt.c
25332 +++ b/arch/x86/kernel/ldt.c
25333 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25334 if (reload) {
25335 #ifdef CONFIG_SMP
25336 preempt_disable();
25337 - load_LDT(pc);
25338 + load_LDT_nolock(pc);
25339 if (!cpumask_equal(mm_cpumask(current->mm),
25340 cpumask_of(smp_processor_id())))
25341 smp_call_function(flush_ldt, current->mm, 1);
25342 preempt_enable();
25343 #else
25344 - load_LDT(pc);
25345 + load_LDT_nolock(pc);
25346 #endif
25347 }
25348 if (oldsize) {
25349 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25350 return err;
25351
25352 for (i = 0; i < old->size; i++)
25353 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25354 + write_ldt_entry(new->ldt, i, old->ldt + i);
25355 return 0;
25356 }
25357
25358 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25359 retval = copy_ldt(&mm->context, &old_mm->context);
25360 mutex_unlock(&old_mm->context.lock);
25361 }
25362 +
25363 + if (tsk == current) {
25364 + mm->context.vdso = 0;
25365 +
25366 +#ifdef CONFIG_X86_32
25367 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25368 + mm->context.user_cs_base = 0UL;
25369 + mm->context.user_cs_limit = ~0UL;
25370 +
25371 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25372 + cpus_clear(mm->context.cpu_user_cs_mask);
25373 +#endif
25374 +
25375 +#endif
25376 +#endif
25377 +
25378 + }
25379 +
25380 return retval;
25381 }
25382
25383 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25384 }
25385 }
25386
25387 +#ifdef CONFIG_PAX_SEGMEXEC
25388 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25389 + error = -EINVAL;
25390 + goto out_unlock;
25391 + }
25392 +#endif
25393 +
25394 fill_ldt(&ldt, &ldt_info);
25395 if (oldmode)
25396 ldt.avl = 0;
25397 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25398 index 5b19e4d..6476a76 100644
25399 --- a/arch/x86/kernel/machine_kexec_32.c
25400 +++ b/arch/x86/kernel/machine_kexec_32.c
25401 @@ -26,7 +26,7 @@
25402 #include <asm/cacheflush.h>
25403 #include <asm/debugreg.h>
25404
25405 -static void set_idt(void *newidt, __u16 limit)
25406 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25407 {
25408 struct desc_ptr curidt;
25409
25410 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
25411 }
25412
25413
25414 -static void set_gdt(void *newgdt, __u16 limit)
25415 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25416 {
25417 struct desc_ptr curgdt;
25418
25419 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
25420 }
25421
25422 control_page = page_address(image->control_code_page);
25423 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25424 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25425
25426 relocate_kernel_ptr = control_page;
25427 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25428 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
25429 index 15c9876..0a43909 100644
25430 --- a/arch/x86/kernel/microcode_core.c
25431 +++ b/arch/x86/kernel/microcode_core.c
25432 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
25433 return NOTIFY_OK;
25434 }
25435
25436 -static struct notifier_block __refdata mc_cpu_notifier = {
25437 +static struct notifier_block mc_cpu_notifier = {
25438 .notifier_call = mc_cpu_callback,
25439 };
25440
25441 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
25442 index 5fb2ceb..3ae90bb 100644
25443 --- a/arch/x86/kernel/microcode_intel.c
25444 +++ b/arch/x86/kernel/microcode_intel.c
25445 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
25446
25447 static int get_ucode_user(void *to, const void *from, size_t n)
25448 {
25449 - return copy_from_user(to, from, n);
25450 + return copy_from_user(to, (const void __force_user *)from, n);
25451 }
25452
25453 static enum ucode_state
25454 request_microcode_user(int cpu, const void __user *buf, size_t size)
25455 {
25456 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
25457 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
25458 }
25459
25460 static void microcode_fini_cpu(int cpu)
25461 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25462 index 18be189..4a9fe40 100644
25463 --- a/arch/x86/kernel/module.c
25464 +++ b/arch/x86/kernel/module.c
25465 @@ -43,15 +43,60 @@ do { \
25466 } while (0)
25467 #endif
25468
25469 -void *module_alloc(unsigned long size)
25470 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25471 {
25472 - if (PAGE_ALIGN(size) > MODULES_LEN)
25473 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25474 return NULL;
25475 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25476 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25477 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25478 NUMA_NO_NODE, __builtin_return_address(0));
25479 }
25480
25481 +void *module_alloc(unsigned long size)
25482 +{
25483 +
25484 +#ifdef CONFIG_PAX_KERNEXEC
25485 + return __module_alloc(size, PAGE_KERNEL);
25486 +#else
25487 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25488 +#endif
25489 +
25490 +}
25491 +
25492 +#ifdef CONFIG_PAX_KERNEXEC
25493 +#ifdef CONFIG_X86_32
25494 +void *module_alloc_exec(unsigned long size)
25495 +{
25496 + struct vm_struct *area;
25497 +
25498 + if (size == 0)
25499 + return NULL;
25500 +
25501 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25502 + return area ? area->addr : NULL;
25503 +}
25504 +EXPORT_SYMBOL(module_alloc_exec);
25505 +
25506 +void module_free_exec(struct module *mod, void *module_region)
25507 +{
25508 + vunmap(module_region);
25509 +}
25510 +EXPORT_SYMBOL(module_free_exec);
25511 +#else
25512 +void module_free_exec(struct module *mod, void *module_region)
25513 +{
25514 + module_free(mod, module_region);
25515 +}
25516 +EXPORT_SYMBOL(module_free_exec);
25517 +
25518 +void *module_alloc_exec(unsigned long size)
25519 +{
25520 + return __module_alloc(size, PAGE_KERNEL_RX);
25521 +}
25522 +EXPORT_SYMBOL(module_alloc_exec);
25523 +#endif
25524 +#endif
25525 +
25526 #ifdef CONFIG_X86_32
25527 int apply_relocate(Elf32_Shdr *sechdrs,
25528 const char *strtab,
25529 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25530 unsigned int i;
25531 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25532 Elf32_Sym *sym;
25533 - uint32_t *location;
25534 + uint32_t *plocation, location;
25535
25536 DEBUGP("Applying relocate section %u to %u\n",
25537 relsec, sechdrs[relsec].sh_info);
25538 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25539 /* This is where to make the change */
25540 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25541 - + rel[i].r_offset;
25542 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25543 + location = (uint32_t)plocation;
25544 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25545 + plocation = ktla_ktva((void *)plocation);
25546 /* This is the symbol it is referring to. Note that all
25547 undefined symbols have been resolved. */
25548 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25549 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25550 switch (ELF32_R_TYPE(rel[i].r_info)) {
25551 case R_386_32:
25552 /* We add the value into the location given */
25553 - *location += sym->st_value;
25554 + pax_open_kernel();
25555 + *plocation += sym->st_value;
25556 + pax_close_kernel();
25557 break;
25558 case R_386_PC32:
25559 /* Add the value, subtract its position */
25560 - *location += sym->st_value - (uint32_t)location;
25561 + pax_open_kernel();
25562 + *plocation += sym->st_value - location;
25563 + pax_close_kernel();
25564 break;
25565 default:
25566 pr_err("%s: Unknown relocation: %u\n",
25567 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25568 case R_X86_64_NONE:
25569 break;
25570 case R_X86_64_64:
25571 + pax_open_kernel();
25572 *(u64 *)loc = val;
25573 + pax_close_kernel();
25574 break;
25575 case R_X86_64_32:
25576 + pax_open_kernel();
25577 *(u32 *)loc = val;
25578 + pax_close_kernel();
25579 if (val != *(u32 *)loc)
25580 goto overflow;
25581 break;
25582 case R_X86_64_32S:
25583 + pax_open_kernel();
25584 *(s32 *)loc = val;
25585 + pax_close_kernel();
25586 if ((s64)val != *(s32 *)loc)
25587 goto overflow;
25588 break;
25589 case R_X86_64_PC32:
25590 val -= (u64)loc;
25591 + pax_open_kernel();
25592 *(u32 *)loc = val;
25593 + pax_close_kernel();
25594 +
25595 #if 0
25596 if ((s64)val != *(s32 *)loc)
25597 goto overflow;
25598 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25599 index 05266b5..3432443 100644
25600 --- a/arch/x86/kernel/msr.c
25601 +++ b/arch/x86/kernel/msr.c
25602 @@ -37,6 +37,7 @@
25603 #include <linux/notifier.h>
25604 #include <linux/uaccess.h>
25605 #include <linux/gfp.h>
25606 +#include <linux/grsecurity.h>
25607
25608 #include <asm/processor.h>
25609 #include <asm/msr.h>
25610 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25611 int err = 0;
25612 ssize_t bytes = 0;
25613
25614 +#ifdef CONFIG_GRKERNSEC_KMEM
25615 + gr_handle_msr_write();
25616 + return -EPERM;
25617 +#endif
25618 +
25619 if (count % 8)
25620 return -EINVAL; /* Invalid chunk size */
25621
25622 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25623 err = -EBADF;
25624 break;
25625 }
25626 +#ifdef CONFIG_GRKERNSEC_KMEM
25627 + gr_handle_msr_write();
25628 + return -EPERM;
25629 +#endif
25630 if (copy_from_user(&regs, uregs, sizeof regs)) {
25631 err = -EFAULT;
25632 break;
25633 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25634 return notifier_from_errno(err);
25635 }
25636
25637 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25638 +static struct notifier_block msr_class_cpu_notifier = {
25639 .notifier_call = msr_class_cpu_callback,
25640 };
25641
25642 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25643 index 6fcb49c..5b3f4ff 100644
25644 --- a/arch/x86/kernel/nmi.c
25645 +++ b/arch/x86/kernel/nmi.c
25646 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25647 return handled;
25648 }
25649
25650 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25651 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25652 {
25653 struct nmi_desc *desc = nmi_to_desc(type);
25654 unsigned long flags;
25655 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25656 * event confuses some handlers (kdump uses this flag)
25657 */
25658 if (action->flags & NMI_FLAG_FIRST)
25659 - list_add_rcu(&action->list, &desc->head);
25660 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25661 else
25662 - list_add_tail_rcu(&action->list, &desc->head);
25663 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25664
25665 spin_unlock_irqrestore(&desc->lock, flags);
25666 return 0;
25667 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25668 if (!strcmp(n->name, name)) {
25669 WARN(in_nmi(),
25670 "Trying to free NMI (%s) from NMI context!\n", n->name);
25671 - list_del_rcu(&n->list);
25672 + pax_list_del_rcu((struct list_head *)&n->list);
25673 break;
25674 }
25675 }
25676 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25677 dotraplinkage notrace __kprobes void
25678 do_nmi(struct pt_regs *regs, long error_code)
25679 {
25680 +
25681 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25682 + if (!user_mode(regs)) {
25683 + unsigned long cs = regs->cs & 0xFFFF;
25684 + unsigned long ip = ktva_ktla(regs->ip);
25685 +
25686 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25687 + regs->ip = ip;
25688 + }
25689 +#endif
25690 +
25691 nmi_nesting_preprocess(regs);
25692
25693 nmi_enter();
25694 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25695 index 6d9582e..f746287 100644
25696 --- a/arch/x86/kernel/nmi_selftest.c
25697 +++ b/arch/x86/kernel/nmi_selftest.c
25698 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25699 {
25700 /* trap all the unknown NMIs we may generate */
25701 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25702 - __initdata);
25703 + __initconst);
25704 }
25705
25706 static void __init cleanup_nmi_testsuite(void)
25707 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25708 unsigned long timeout;
25709
25710 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25711 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25712 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25713 nmi_fail = FAILURE;
25714 return;
25715 }
25716 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25717 index bbb6c73..24a58ef 100644
25718 --- a/arch/x86/kernel/paravirt-spinlocks.c
25719 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25720 @@ -8,7 +8,7 @@
25721
25722 #include <asm/paravirt.h>
25723
25724 -struct pv_lock_ops pv_lock_ops = {
25725 +struct pv_lock_ops pv_lock_ops __read_only = {
25726 #ifdef CONFIG_SMP
25727 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25728 .unlock_kick = paravirt_nop,
25729 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25730 index 1b10af8..0b58cbc 100644
25731 --- a/arch/x86/kernel/paravirt.c
25732 +++ b/arch/x86/kernel/paravirt.c
25733 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25734 {
25735 return x;
25736 }
25737 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25738 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25739 +#endif
25740
25741 void __init default_banner(void)
25742 {
25743 @@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25744 if (opfunc == NULL)
25745 /* If there's no function, patch it with a ud2a (BUG) */
25746 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25747 - else if (opfunc == _paravirt_nop)
25748 + else if (opfunc == (void *)_paravirt_nop)
25749 /* If the operation is a nop, then nop the callsite */
25750 ret = paravirt_patch_nop();
25751
25752 /* identity functions just return their single argument */
25753 - else if (opfunc == _paravirt_ident_32)
25754 + else if (opfunc == (void *)_paravirt_ident_32)
25755 ret = paravirt_patch_ident_32(insnbuf, len);
25756 - else if (opfunc == _paravirt_ident_64)
25757 + else if (opfunc == (void *)_paravirt_ident_64)
25758 ret = paravirt_patch_ident_64(insnbuf, len);
25759 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25760 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25761 + ret = paravirt_patch_ident_64(insnbuf, len);
25762 +#endif
25763
25764 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25765 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25766 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25767 if (insn_len > len || start == NULL)
25768 insn_len = len;
25769 else
25770 - memcpy(insnbuf, start, insn_len);
25771 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25772
25773 return insn_len;
25774 }
25775 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25776 return this_cpu_read(paravirt_lazy_mode);
25777 }
25778
25779 -struct pv_info pv_info = {
25780 +struct pv_info pv_info __read_only = {
25781 .name = "bare hardware",
25782 .paravirt_enabled = 0,
25783 .kernel_rpl = 0,
25784 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25785 #endif
25786 };
25787
25788 -struct pv_init_ops pv_init_ops = {
25789 +struct pv_init_ops pv_init_ops __read_only = {
25790 .patch = native_patch,
25791 };
25792
25793 -struct pv_time_ops pv_time_ops = {
25794 +struct pv_time_ops pv_time_ops __read_only = {
25795 .sched_clock = native_sched_clock,
25796 .steal_clock = native_steal_clock,
25797 };
25798
25799 -__visible struct pv_irq_ops pv_irq_ops = {
25800 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25801 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25802 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25803 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25804 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25805 #endif
25806 };
25807
25808 -__visible struct pv_cpu_ops pv_cpu_ops = {
25809 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25810 .cpuid = native_cpuid,
25811 .get_debugreg = native_get_debugreg,
25812 .set_debugreg = native_set_debugreg,
25813 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25814 .end_context_switch = paravirt_nop,
25815 };
25816
25817 -struct pv_apic_ops pv_apic_ops = {
25818 +struct pv_apic_ops pv_apic_ops __read_only= {
25819 #ifdef CONFIG_X86_LOCAL_APIC
25820 .startup_ipi_hook = paravirt_nop,
25821 #endif
25822 };
25823
25824 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25825 +#ifdef CONFIG_X86_32
25826 +#ifdef CONFIG_X86_PAE
25827 +/* 64-bit pagetable entries */
25828 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25829 +#else
25830 /* 32-bit pagetable entries */
25831 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25832 +#endif
25833 #else
25834 /* 64-bit pagetable entries */
25835 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25836 #endif
25837
25838 -struct pv_mmu_ops pv_mmu_ops = {
25839 +struct pv_mmu_ops pv_mmu_ops __read_only = {
25840
25841 .read_cr2 = native_read_cr2,
25842 .write_cr2 = native_write_cr2,
25843 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25844 .make_pud = PTE_IDENT,
25845
25846 .set_pgd = native_set_pgd,
25847 + .set_pgd_batched = native_set_pgd_batched,
25848 #endif
25849 #endif /* PAGETABLE_LEVELS >= 3 */
25850
25851 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25852 },
25853
25854 .set_fixmap = native_set_fixmap,
25855 +
25856 +#ifdef CONFIG_PAX_KERNEXEC
25857 + .pax_open_kernel = native_pax_open_kernel,
25858 + .pax_close_kernel = native_pax_close_kernel,
25859 +#endif
25860 +
25861 };
25862
25863 EXPORT_SYMBOL_GPL(pv_time_ops);
25864 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25865 index 299d493..2ccb0ee 100644
25866 --- a/arch/x86/kernel/pci-calgary_64.c
25867 +++ b/arch/x86/kernel/pci-calgary_64.c
25868 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25869 tce_space = be64_to_cpu(readq(target));
25870 tce_space = tce_space & TAR_SW_BITS;
25871
25872 - tce_space = tce_space & (~specified_table_size);
25873 + tce_space = tce_space & (~(unsigned long)specified_table_size);
25874 info->tce_space = (u64 *)__va(tce_space);
25875 }
25876 }
25877 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25878 index 35ccf75..7a15747 100644
25879 --- a/arch/x86/kernel/pci-iommu_table.c
25880 +++ b/arch/x86/kernel/pci-iommu_table.c
25881 @@ -2,7 +2,7 @@
25882 #include <asm/iommu_table.h>
25883 #include <linux/string.h>
25884 #include <linux/kallsyms.h>
25885 -
25886 +#include <linux/sched.h>
25887
25888 #define DEBUG 1
25889
25890 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25891 index 6c483ba..d10ce2f 100644
25892 --- a/arch/x86/kernel/pci-swiotlb.c
25893 +++ b/arch/x86/kernel/pci-swiotlb.c
25894 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25895 void *vaddr, dma_addr_t dma_addr,
25896 struct dma_attrs *attrs)
25897 {
25898 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25899 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25900 }
25901
25902 static struct dma_map_ops swiotlb_dma_ops = {
25903 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25904 index ca7f0d5..8996469 100644
25905 --- a/arch/x86/kernel/preempt.S
25906 +++ b/arch/x86/kernel/preempt.S
25907 @@ -3,12 +3,14 @@
25908 #include <asm/dwarf2.h>
25909 #include <asm/asm.h>
25910 #include <asm/calling.h>
25911 +#include <asm/alternative-asm.h>
25912
25913 ENTRY(___preempt_schedule)
25914 CFI_STARTPROC
25915 SAVE_ALL
25916 call preempt_schedule
25917 RESTORE_ALL
25918 + pax_force_retaddr
25919 ret
25920 CFI_ENDPROC
25921
25922 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25923 SAVE_ALL
25924 call preempt_schedule_context
25925 RESTORE_ALL
25926 + pax_force_retaddr
25927 ret
25928 CFI_ENDPROC
25929
25930 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25931 index 3fb8d95..254dc51 100644
25932 --- a/arch/x86/kernel/process.c
25933 +++ b/arch/x86/kernel/process.c
25934 @@ -36,7 +36,8 @@
25935 * section. Since TSS's are completely CPU-local, we want them
25936 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25937 */
25938 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25939 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25940 +EXPORT_SYMBOL(init_tss);
25941
25942 #ifdef CONFIG_X86_64
25943 static DEFINE_PER_CPU(unsigned char, is_idle);
25944 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25945 task_xstate_cachep =
25946 kmem_cache_create("task_xstate", xstate_size,
25947 __alignof__(union thread_xstate),
25948 - SLAB_PANIC | SLAB_NOTRACK, NULL);
25949 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25950 }
25951
25952 /*
25953 @@ -105,7 +106,7 @@ void exit_thread(void)
25954 unsigned long *bp = t->io_bitmap_ptr;
25955
25956 if (bp) {
25957 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25958 + struct tss_struct *tss = init_tss + get_cpu();
25959
25960 t->io_bitmap_ptr = NULL;
25961 clear_thread_flag(TIF_IO_BITMAP);
25962 @@ -125,6 +126,9 @@ void flush_thread(void)
25963 {
25964 struct task_struct *tsk = current;
25965
25966 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25967 + loadsegment(gs, 0);
25968 +#endif
25969 flush_ptrace_hw_breakpoint(tsk);
25970 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25971 drop_init_fpu(tsk);
25972 @@ -271,7 +275,7 @@ static void __exit_idle(void)
25973 void exit_idle(void)
25974 {
25975 /* idle loop has pid 0 */
25976 - if (current->pid)
25977 + if (task_pid_nr(current))
25978 return;
25979 __exit_idle();
25980 }
25981 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25982 return ret;
25983 }
25984 #endif
25985 -void stop_this_cpu(void *dummy)
25986 +__noreturn void stop_this_cpu(void *dummy)
25987 {
25988 local_irq_disable();
25989 /*
25990 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25991 }
25992 early_param("idle", idle_setup);
25993
25994 -unsigned long arch_align_stack(unsigned long sp)
25995 +#ifdef CONFIG_PAX_RANDKSTACK
25996 +void pax_randomize_kstack(struct pt_regs *regs)
25997 {
25998 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25999 - sp -= get_random_int() % 8192;
26000 - return sp & ~0xf;
26001 -}
26002 + struct thread_struct *thread = &current->thread;
26003 + unsigned long time;
26004
26005 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26006 -{
26007 - unsigned long range_end = mm->brk + 0x02000000;
26008 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26009 -}
26010 + if (!randomize_va_space)
26011 + return;
26012 +
26013 + if (v8086_mode(regs))
26014 + return;
26015
26016 + rdtscl(time);
26017 +
26018 + /* P4 seems to return a 0 LSB, ignore it */
26019 +#ifdef CONFIG_MPENTIUM4
26020 + time &= 0x3EUL;
26021 + time <<= 2;
26022 +#elif defined(CONFIG_X86_64)
26023 + time &= 0xFUL;
26024 + time <<= 4;
26025 +#else
26026 + time &= 0x1FUL;
26027 + time <<= 3;
26028 +#endif
26029 +
26030 + thread->sp0 ^= time;
26031 + load_sp0(init_tss + smp_processor_id(), thread);
26032 +
26033 +#ifdef CONFIG_X86_64
26034 + this_cpu_write(kernel_stack, thread->sp0);
26035 +#endif
26036 +}
26037 +#endif
26038 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26039 index 6f1236c..fd448d4 100644
26040 --- a/arch/x86/kernel/process_32.c
26041 +++ b/arch/x86/kernel/process_32.c
26042 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26043 unsigned long thread_saved_pc(struct task_struct *tsk)
26044 {
26045 return ((unsigned long *)tsk->thread.sp)[3];
26046 +//XXX return tsk->thread.eip;
26047 }
26048
26049 void __show_regs(struct pt_regs *regs, int all)
26050 @@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
26051 unsigned long sp;
26052 unsigned short ss, gs;
26053
26054 - if (user_mode_vm(regs)) {
26055 + if (user_mode(regs)) {
26056 sp = regs->sp;
26057 ss = regs->ss & 0xffff;
26058 - gs = get_user_gs(regs);
26059 } else {
26060 sp = kernel_stack_pointer(regs);
26061 savesegment(ss, ss);
26062 - savesegment(gs, gs);
26063 }
26064 + gs = get_user_gs(regs);
26065
26066 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26067 (u16)regs->cs, regs->ip, regs->flags,
26068 - smp_processor_id());
26069 + raw_smp_processor_id());
26070 print_symbol("EIP is at %s\n", regs->ip);
26071
26072 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26073 @@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
26074 int copy_thread(unsigned long clone_flags, unsigned long sp,
26075 unsigned long arg, struct task_struct *p)
26076 {
26077 - struct pt_regs *childregs = task_pt_regs(p);
26078 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26079 struct task_struct *tsk;
26080 int err;
26081
26082 p->thread.sp = (unsigned long) childregs;
26083 p->thread.sp0 = (unsigned long) (childregs+1);
26084 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26085
26086 if (unlikely(p->flags & PF_KTHREAD)) {
26087 /* kernel thread */
26088 memset(childregs, 0, sizeof(struct pt_regs));
26089 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26090 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26091 - childregs->ds = __USER_DS;
26092 - childregs->es = __USER_DS;
26093 + savesegment(gs, childregs->gs);
26094 + childregs->ds = __KERNEL_DS;
26095 + childregs->es = __KERNEL_DS;
26096 childregs->fs = __KERNEL_PERCPU;
26097 childregs->bx = sp; /* function */
26098 childregs->bp = arg;
26099 @@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26100 struct thread_struct *prev = &prev_p->thread,
26101 *next = &next_p->thread;
26102 int cpu = smp_processor_id();
26103 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26104 + struct tss_struct *tss = init_tss + cpu;
26105 fpu_switch_t fpu;
26106
26107 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26108 @@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26109 */
26110 lazy_save_gs(prev->gs);
26111
26112 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26113 + __set_fs(task_thread_info(next_p)->addr_limit);
26114 +#endif
26115 +
26116 /*
26117 * Load the per-thread Thread-Local Storage descriptor.
26118 */
26119 @@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26120 */
26121 arch_end_context_switch(next_p);
26122
26123 + this_cpu_write(current_task, next_p);
26124 + this_cpu_write(current_tinfo, &next_p->tinfo);
26125 +
26126 /*
26127 * Restore %gs if needed (which is common)
26128 */
26129 @@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26130
26131 switch_fpu_finish(next_p, fpu);
26132
26133 - this_cpu_write(current_task, next_p);
26134 -
26135 return prev_p;
26136 }
26137
26138 @@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26139 } while (count++ < 16);
26140 return 0;
26141 }
26142 -
26143 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26144 index 9c0280f..5bbb1c0 100644
26145 --- a/arch/x86/kernel/process_64.c
26146 +++ b/arch/x86/kernel/process_64.c
26147 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26148 struct pt_regs *childregs;
26149 struct task_struct *me = current;
26150
26151 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26152 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26153 childregs = task_pt_regs(p);
26154 p->thread.sp = (unsigned long) childregs;
26155 p->thread.usersp = me->thread.usersp;
26156 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26157 set_tsk_thread_flag(p, TIF_FORK);
26158 p->thread.fpu_counter = 0;
26159 p->thread.io_bitmap_ptr = NULL;
26160 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26161 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26162 savesegment(es, p->thread.es);
26163 savesegment(ds, p->thread.ds);
26164 + savesegment(ss, p->thread.ss);
26165 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26166 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26167
26168 if (unlikely(p->flags & PF_KTHREAD)) {
26169 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26170 struct thread_struct *prev = &prev_p->thread;
26171 struct thread_struct *next = &next_p->thread;
26172 int cpu = smp_processor_id();
26173 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26174 + struct tss_struct *tss = init_tss + cpu;
26175 unsigned fsindex, gsindex;
26176 fpu_switch_t fpu;
26177
26178 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26179 if (unlikely(next->ds | prev->ds))
26180 loadsegment(ds, next->ds);
26181
26182 + savesegment(ss, prev->ss);
26183 + if (unlikely(next->ss != prev->ss))
26184 + loadsegment(ss, next->ss);
26185
26186 /* We must save %fs and %gs before load_TLS() because
26187 * %fs and %gs may be cleared by load_TLS().
26188 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26189 prev->usersp = this_cpu_read(old_rsp);
26190 this_cpu_write(old_rsp, next->usersp);
26191 this_cpu_write(current_task, next_p);
26192 + this_cpu_write(current_tinfo, &next_p->tinfo);
26193
26194 /*
26195 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26196 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26197 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26198 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26199
26200 - this_cpu_write(kernel_stack,
26201 - (unsigned long)task_stack_page(next_p) +
26202 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26203 + this_cpu_write(kernel_stack, next->sp0);
26204
26205 /*
26206 * Now maybe reload the debug registers and handle I/O bitmaps
26207 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26208 if (!p || p == current || p->state == TASK_RUNNING)
26209 return 0;
26210 stack = (unsigned long)task_stack_page(p);
26211 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26212 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26213 return 0;
26214 fp = *(u64 *)(p->thread.sp);
26215 do {
26216 - if (fp < (unsigned long)stack ||
26217 - fp >= (unsigned long)stack+THREAD_SIZE)
26218 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26219 return 0;
26220 ip = *(u64 *)(fp+8);
26221 if (!in_sched_functions(ip))
26222 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26223 index 7461f50..1334029 100644
26224 --- a/arch/x86/kernel/ptrace.c
26225 +++ b/arch/x86/kernel/ptrace.c
26226 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26227 {
26228 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26229 unsigned long sp = (unsigned long)&regs->sp;
26230 - struct thread_info *tinfo;
26231
26232 - if (context == (sp & ~(THREAD_SIZE - 1)))
26233 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26234 return sp;
26235
26236 - tinfo = (struct thread_info *)context;
26237 - if (tinfo->previous_esp)
26238 - return tinfo->previous_esp;
26239 + sp = *(unsigned long *)context;
26240 + if (sp)
26241 + return sp;
26242
26243 return (unsigned long)regs;
26244 }
26245 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26246 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26247 {
26248 int i;
26249 - int dr7 = 0;
26250 + unsigned long dr7 = 0;
26251 struct arch_hw_breakpoint *info;
26252
26253 for (i = 0; i < HBP_NUM; i++) {
26254 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26255 unsigned long addr, unsigned long data)
26256 {
26257 int ret;
26258 - unsigned long __user *datap = (unsigned long __user *)data;
26259 + unsigned long __user *datap = (__force unsigned long __user *)data;
26260
26261 switch (request) {
26262 /* read the word at location addr in the USER area. */
26263 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26264 if ((int) addr < 0)
26265 return -EIO;
26266 ret = do_get_thread_area(child, addr,
26267 - (struct user_desc __user *)data);
26268 + (__force struct user_desc __user *) data);
26269 break;
26270
26271 case PTRACE_SET_THREAD_AREA:
26272 if ((int) addr < 0)
26273 return -EIO;
26274 ret = do_set_thread_area(child, addr,
26275 - (struct user_desc __user *)data, 0);
26276 + (__force struct user_desc __user *) data, 0);
26277 break;
26278 #endif
26279
26280 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26281
26282 #ifdef CONFIG_X86_64
26283
26284 -static struct user_regset x86_64_regsets[] __read_mostly = {
26285 +static user_regset_no_const x86_64_regsets[] __read_only = {
26286 [REGSET_GENERAL] = {
26287 .core_note_type = NT_PRSTATUS,
26288 .n = sizeof(struct user_regs_struct) / sizeof(long),
26289 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26290 #endif /* CONFIG_X86_64 */
26291
26292 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26293 -static struct user_regset x86_32_regsets[] __read_mostly = {
26294 +static user_regset_no_const x86_32_regsets[] __read_only = {
26295 [REGSET_GENERAL] = {
26296 .core_note_type = NT_PRSTATUS,
26297 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26298 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26299 */
26300 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26301
26302 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26303 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26304 {
26305 #ifdef CONFIG_X86_64
26306 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26307 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26308 memset(info, 0, sizeof(*info));
26309 info->si_signo = SIGTRAP;
26310 info->si_code = si_code;
26311 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26312 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26313 }
26314
26315 void user_single_step_siginfo(struct task_struct *tsk,
26316 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26317 # define IS_IA32 0
26318 #endif
26319
26320 +#ifdef CONFIG_GRKERNSEC_SETXID
26321 +extern void gr_delayed_cred_worker(void);
26322 +#endif
26323 +
26324 /*
26325 * We must return the syscall number to actually look up in the table.
26326 * This can be -1L to skip running any syscall at all.
26327 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26328
26329 user_exit();
26330
26331 +#ifdef CONFIG_GRKERNSEC_SETXID
26332 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26333 + gr_delayed_cred_worker();
26334 +#endif
26335 +
26336 /*
26337 * If we stepped into a sysenter/syscall insn, it trapped in
26338 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26339 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26340 */
26341 user_exit();
26342
26343 +#ifdef CONFIG_GRKERNSEC_SETXID
26344 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26345 + gr_delayed_cred_worker();
26346 +#endif
26347 +
26348 audit_syscall_exit(regs);
26349
26350 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26351 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26352 index 2f355d2..e75ed0a 100644
26353 --- a/arch/x86/kernel/pvclock.c
26354 +++ b/arch/x86/kernel/pvclock.c
26355 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26356 reset_hung_task_detector();
26357 }
26358
26359 -static atomic64_t last_value = ATOMIC64_INIT(0);
26360 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26361
26362 void pvclock_resume(void)
26363 {
26364 - atomic64_set(&last_value, 0);
26365 + atomic64_set_unchecked(&last_value, 0);
26366 }
26367
26368 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26369 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26370 * updating at the same time, and one of them could be slightly behind,
26371 * making the assumption that last_value always go forward fail to hold.
26372 */
26373 - last = atomic64_read(&last_value);
26374 + last = atomic64_read_unchecked(&last_value);
26375 do {
26376 if (ret < last)
26377 return last;
26378 - last = atomic64_cmpxchg(&last_value, last, ret);
26379 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26380 } while (unlikely(last != ret));
26381
26382 return ret;
26383 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26384 index c752cb4..866c432 100644
26385 --- a/arch/x86/kernel/reboot.c
26386 +++ b/arch/x86/kernel/reboot.c
26387 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26388
26389 void __noreturn machine_real_restart(unsigned int type)
26390 {
26391 +
26392 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26393 + struct desc_struct *gdt;
26394 +#endif
26395 +
26396 local_irq_disable();
26397
26398 /*
26399 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26400
26401 /* Jump to the identity-mapped low memory code */
26402 #ifdef CONFIG_X86_32
26403 - asm volatile("jmpl *%0" : :
26404 +
26405 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26406 + gdt = get_cpu_gdt_table(smp_processor_id());
26407 + pax_open_kernel();
26408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26409 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26410 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26411 + loadsegment(ds, __KERNEL_DS);
26412 + loadsegment(es, __KERNEL_DS);
26413 + loadsegment(ss, __KERNEL_DS);
26414 +#endif
26415 +#ifdef CONFIG_PAX_KERNEXEC
26416 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26417 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26418 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26419 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26420 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26421 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26422 +#endif
26423 + pax_close_kernel();
26424 +#endif
26425 +
26426 + asm volatile("ljmpl *%0" : :
26427 "rm" (real_mode_header->machine_real_restart_asm),
26428 "a" (type));
26429 #else
26430 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26431 * try to force a triple fault and then cycle between hitting the keyboard
26432 * controller and doing that
26433 */
26434 -static void native_machine_emergency_restart(void)
26435 +static void __noreturn native_machine_emergency_restart(void)
26436 {
26437 int i;
26438 int attempt = 0;
26439 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26440 #endif
26441 }
26442
26443 -static void __machine_emergency_restart(int emergency)
26444 +static void __noreturn __machine_emergency_restart(int emergency)
26445 {
26446 reboot_emergency = emergency;
26447 machine_ops.emergency_restart();
26448 }
26449
26450 -static void native_machine_restart(char *__unused)
26451 +static void __noreturn native_machine_restart(char *__unused)
26452 {
26453 pr_notice("machine restart\n");
26454
26455 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26456 __machine_emergency_restart(0);
26457 }
26458
26459 -static void native_machine_halt(void)
26460 +static void __noreturn native_machine_halt(void)
26461 {
26462 /* Stop other cpus and apics */
26463 machine_shutdown();
26464 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
26465 stop_this_cpu(NULL);
26466 }
26467
26468 -static void native_machine_power_off(void)
26469 +static void __noreturn native_machine_power_off(void)
26470 {
26471 if (pm_power_off) {
26472 if (!reboot_force)
26473 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26474 }
26475 /* A fallback in case there is no PM info available */
26476 tboot_shutdown(TB_SHUTDOWN_HALT);
26477 + unreachable();
26478 }
26479
26480 -struct machine_ops machine_ops = {
26481 +struct machine_ops machine_ops __read_only = {
26482 .power_off = native_machine_power_off,
26483 .shutdown = native_machine_shutdown,
26484 .emergency_restart = native_machine_emergency_restart,
26485 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26486 index c8e41e9..64049ef 100644
26487 --- a/arch/x86/kernel/reboot_fixups_32.c
26488 +++ b/arch/x86/kernel/reboot_fixups_32.c
26489 @@ -57,7 +57,7 @@ struct device_fixup {
26490 unsigned int vendor;
26491 unsigned int device;
26492 void (*reboot_fixup)(struct pci_dev *);
26493 -};
26494 +} __do_const;
26495
26496 /*
26497 * PCI ids solely used for fixups_table go here
26498 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26499 index 3fd2c69..16ef367 100644
26500 --- a/arch/x86/kernel/relocate_kernel_64.S
26501 +++ b/arch/x86/kernel/relocate_kernel_64.S
26502 @@ -11,6 +11,7 @@
26503 #include <asm/kexec.h>
26504 #include <asm/processor-flags.h>
26505 #include <asm/pgtable_types.h>
26506 +#include <asm/alternative-asm.h>
26507
26508 /*
26509 * Must be relocatable PIC code callable as a C function
26510 @@ -96,8 +97,7 @@ relocate_kernel:
26511
26512 /* jump to identity mapped page */
26513 addq $(identity_mapped - relocate_kernel), %r8
26514 - pushq %r8
26515 - ret
26516 + jmp *%r8
26517
26518 identity_mapped:
26519 /* set return address to 0 if not preserving context */
26520 @@ -167,6 +167,7 @@ identity_mapped:
26521 xorl %r14d, %r14d
26522 xorl %r15d, %r15d
26523
26524 + pax_force_retaddr 0, 1
26525 ret
26526
26527 1:
26528 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26529 index cb233bc..23b4879 100644
26530 --- a/arch/x86/kernel/setup.c
26531 +++ b/arch/x86/kernel/setup.c
26532 @@ -110,6 +110,7 @@
26533 #include <asm/mce.h>
26534 #include <asm/alternative.h>
26535 #include <asm/prom.h>
26536 +#include <asm/boot.h>
26537
26538 /*
26539 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26540 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26541 #endif
26542
26543
26544 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26545 -__visible unsigned long mmu_cr4_features;
26546 +#ifdef CONFIG_X86_64
26547 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26548 +#elif defined(CONFIG_X86_PAE)
26549 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26550 #else
26551 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26552 +__visible unsigned long mmu_cr4_features __read_only;
26553 #endif
26554
26555 +void set_in_cr4(unsigned long mask)
26556 +{
26557 + unsigned long cr4 = read_cr4();
26558 +
26559 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26560 + return;
26561 +
26562 + pax_open_kernel();
26563 + mmu_cr4_features |= mask;
26564 + pax_close_kernel();
26565 +
26566 + if (trampoline_cr4_features)
26567 + *trampoline_cr4_features = mmu_cr4_features;
26568 + cr4 |= mask;
26569 + write_cr4(cr4);
26570 +}
26571 +EXPORT_SYMBOL(set_in_cr4);
26572 +
26573 +void clear_in_cr4(unsigned long mask)
26574 +{
26575 + unsigned long cr4 = read_cr4();
26576 +
26577 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26578 + return;
26579 +
26580 + pax_open_kernel();
26581 + mmu_cr4_features &= ~mask;
26582 + pax_close_kernel();
26583 +
26584 + if (trampoline_cr4_features)
26585 + *trampoline_cr4_features = mmu_cr4_features;
26586 + cr4 &= ~mask;
26587 + write_cr4(cr4);
26588 +}
26589 +EXPORT_SYMBOL(clear_in_cr4);
26590 +
26591 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26592 int bootloader_type, bootloader_version;
26593
26594 @@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26595 * area (640->1Mb) as ram even though it is not.
26596 * take them out.
26597 */
26598 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26599 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26600
26601 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26602 }
26603 @@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26604 /* called before trim_bios_range() to spare extra sanitize */
26605 static void __init e820_add_kernel_range(void)
26606 {
26607 - u64 start = __pa_symbol(_text);
26608 + u64 start = __pa_symbol(ktla_ktva(_text));
26609 u64 size = __pa_symbol(_end) - start;
26610
26611 /*
26612 @@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26613
26614 void __init setup_arch(char **cmdline_p)
26615 {
26616 +#ifdef CONFIG_X86_32
26617 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26618 +#else
26619 memblock_reserve(__pa_symbol(_text),
26620 (unsigned long)__bss_stop - (unsigned long)_text);
26621 +#endif
26622
26623 early_reserve_initrd();
26624
26625 @@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26626
26627 if (!boot_params.hdr.root_flags)
26628 root_mountflags &= ~MS_RDONLY;
26629 - init_mm.start_code = (unsigned long) _text;
26630 - init_mm.end_code = (unsigned long) _etext;
26631 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26632 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26633 init_mm.end_data = (unsigned long) _edata;
26634 init_mm.brk = _brk_end;
26635
26636 - code_resource.start = __pa_symbol(_text);
26637 - code_resource.end = __pa_symbol(_etext)-1;
26638 - data_resource.start = __pa_symbol(_etext);
26639 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26640 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26641 + data_resource.start = __pa_symbol(_sdata);
26642 data_resource.end = __pa_symbol(_edata)-1;
26643 bss_resource.start = __pa_symbol(__bss_start);
26644 bss_resource.end = __pa_symbol(__bss_stop)-1;
26645 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26646 index 5cdff03..80fa283 100644
26647 --- a/arch/x86/kernel/setup_percpu.c
26648 +++ b/arch/x86/kernel/setup_percpu.c
26649 @@ -21,19 +21,17 @@
26650 #include <asm/cpu.h>
26651 #include <asm/stackprotector.h>
26652
26653 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26654 +#ifdef CONFIG_SMP
26655 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26656 EXPORT_PER_CPU_SYMBOL(cpu_number);
26657 +#endif
26658
26659 -#ifdef CONFIG_X86_64
26660 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26661 -#else
26662 -#define BOOT_PERCPU_OFFSET 0
26663 -#endif
26664
26665 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26666 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26667
26668 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26669 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26670 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26671 };
26672 EXPORT_SYMBOL(__per_cpu_offset);
26673 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26674 {
26675 #ifdef CONFIG_NEED_MULTIPLE_NODES
26676 pg_data_t *last = NULL;
26677 - unsigned int cpu;
26678 + int cpu;
26679
26680 for_each_possible_cpu(cpu) {
26681 int node = early_cpu_to_node(cpu);
26682 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26683 {
26684 #ifdef CONFIG_X86_32
26685 struct desc_struct gdt;
26686 + unsigned long base = per_cpu_offset(cpu);
26687
26688 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26689 - 0x2 | DESCTYPE_S, 0x8);
26690 - gdt.s = 1;
26691 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26692 + 0x83 | DESCTYPE_S, 0xC);
26693 write_gdt_entry(get_cpu_gdt_table(cpu),
26694 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26695 #endif
26696 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26697 /* alrighty, percpu areas up and running */
26698 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26699 for_each_possible_cpu(cpu) {
26700 +#ifdef CONFIG_CC_STACKPROTECTOR
26701 +#ifdef CONFIG_X86_32
26702 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26703 +#endif
26704 +#endif
26705 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26706 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26707 per_cpu(cpu_number, cpu) = cpu;
26708 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26709 */
26710 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26711 #endif
26712 +#ifdef CONFIG_CC_STACKPROTECTOR
26713 +#ifdef CONFIG_X86_32
26714 + if (!cpu)
26715 + per_cpu(stack_canary.canary, cpu) = canary;
26716 +#endif
26717 +#endif
26718 /*
26719 * Up to this point, the boot CPU has been using .init.data
26720 * area. Reload any changed state for the boot CPU.
26721 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26722 index 9e5de68..16c53cb 100644
26723 --- a/arch/x86/kernel/signal.c
26724 +++ b/arch/x86/kernel/signal.c
26725 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26726 * Align the stack pointer according to the i386 ABI,
26727 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26728 */
26729 - sp = ((sp + 4) & -16ul) - 4;
26730 + sp = ((sp - 12) & -16ul) - 4;
26731 #else /* !CONFIG_X86_32 */
26732 sp = round_down(sp, 16) - 8;
26733 #endif
26734 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26735 }
26736
26737 if (current->mm->context.vdso)
26738 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26739 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26740 else
26741 - restorer = &frame->retcode;
26742 + restorer = (void __user *)&frame->retcode;
26743 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26744 restorer = ksig->ka.sa.sa_restorer;
26745
26746 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26747 * reasons and because gdb uses it as a signature to notice
26748 * signal handler stack frames.
26749 */
26750 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26751 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26752
26753 if (err)
26754 return -EFAULT;
26755 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26756 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26757
26758 /* Set up to return from userspace. */
26759 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26760 + if (current->mm->context.vdso)
26761 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26762 + else
26763 + restorer = (void __user *)&frame->retcode;
26764 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26765 restorer = ksig->ka.sa.sa_restorer;
26766 put_user_ex(restorer, &frame->pretcode);
26767 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26768 * reasons and because gdb uses it as a signature to notice
26769 * signal handler stack frames.
26770 */
26771 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26772 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26773 } put_user_catch(err);
26774
26775 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26776 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26777 {
26778 int usig = signr_convert(ksig->sig);
26779 sigset_t *set = sigmask_to_save();
26780 - compat_sigset_t *cset = (compat_sigset_t *) set;
26781 + sigset_t sigcopy;
26782 + compat_sigset_t *cset;
26783 +
26784 + sigcopy = *set;
26785 +
26786 + cset = (compat_sigset_t *) &sigcopy;
26787
26788 /* Set up the stack frame */
26789 if (is_ia32_frame()) {
26790 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26791 } else if (is_x32_frame()) {
26792 return x32_setup_rt_frame(ksig, cset, regs);
26793 } else {
26794 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26795 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26796 }
26797 }
26798
26799 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26800 index 7c3a5a6..f0a8961 100644
26801 --- a/arch/x86/kernel/smp.c
26802 +++ b/arch/x86/kernel/smp.c
26803 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26804
26805 __setup("nonmi_ipi", nonmi_ipi_setup);
26806
26807 -struct smp_ops smp_ops = {
26808 +struct smp_ops smp_ops __read_only = {
26809 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26810 .smp_prepare_cpus = native_smp_prepare_cpus,
26811 .smp_cpus_done = native_smp_cpus_done,
26812 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26813 index 85dc05a..1241266 100644
26814 --- a/arch/x86/kernel/smpboot.c
26815 +++ b/arch/x86/kernel/smpboot.c
26816 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26817
26818 enable_start_cpu0 = 0;
26819
26820 -#ifdef CONFIG_X86_32
26821 - /* switch away from the initial page table */
26822 - load_cr3(swapper_pg_dir);
26823 - __flush_tlb_all();
26824 -#endif
26825 -
26826 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26827 barrier();
26828 +
26829 + /* switch away from the initial page table */
26830 +#ifdef CONFIG_PAX_PER_CPU_PGD
26831 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26832 + __flush_tlb_all();
26833 +#elif defined(CONFIG_X86_32)
26834 + load_cr3(swapper_pg_dir);
26835 + __flush_tlb_all();
26836 +#endif
26837 +
26838 /*
26839 * Check TSC synchronization with the BP:
26840 */
26841 @@ -751,6 +755,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26842 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26843 (THREAD_SIZE + task_stack_page(idle))) - 1);
26844 per_cpu(current_task, cpu) = idle;
26845 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26846
26847 #ifdef CONFIG_X86_32
26848 /* Stack for startup_32 can be just as for start_secondary onwards */
26849 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26850 #else
26851 clear_tsk_thread_flag(idle, TIF_FORK);
26852 initial_gs = per_cpu_offset(cpu);
26853 - per_cpu(kernel_stack, cpu) =
26854 - (unsigned long)task_stack_page(idle) -
26855 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26856 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26857 #endif
26858 +
26859 + pax_open_kernel();
26860 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26861 + pax_close_kernel();
26862 +
26863 initial_code = (unsigned long)start_secondary;
26864 stack_start = idle->thread.sp;
26865
26866 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26867 /* the FPU context is blank, nobody can own it */
26868 __cpu_disable_lazy_restore(cpu);
26869
26870 +#ifdef CONFIG_PAX_PER_CPU_PGD
26871 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26872 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26873 + KERNEL_PGD_PTRS);
26874 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26875 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26876 + KERNEL_PGD_PTRS);
26877 +#endif
26878 +
26879 err = do_boot_cpu(apicid, cpu, tidle);
26880 if (err) {
26881 pr_debug("do_boot_cpu failed %d\n", err);
26882 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26883 index 9b4d51d..5d28b58 100644
26884 --- a/arch/x86/kernel/step.c
26885 +++ b/arch/x86/kernel/step.c
26886 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26887 struct desc_struct *desc;
26888 unsigned long base;
26889
26890 - seg &= ~7UL;
26891 + seg >>= 3;
26892
26893 mutex_lock(&child->mm->context.lock);
26894 - if (unlikely((seg >> 3) >= child->mm->context.size))
26895 + if (unlikely(seg >= child->mm->context.size))
26896 addr = -1L; /* bogus selector, access would fault */
26897 else {
26898 desc = child->mm->context.ldt + seg;
26899 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26900 addr += base;
26901 }
26902 mutex_unlock(&child->mm->context.lock);
26903 - }
26904 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26905 + addr = ktla_ktva(addr);
26906
26907 return addr;
26908 }
26909 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26910 unsigned char opcode[15];
26911 unsigned long addr = convert_ip_to_linear(child, regs);
26912
26913 + if (addr == -EINVAL)
26914 + return 0;
26915 +
26916 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26917 for (i = 0; i < copied; i++) {
26918 switch (opcode[i]) {
26919 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26920 new file mode 100644
26921 index 0000000..5877189
26922 --- /dev/null
26923 +++ b/arch/x86/kernel/sys_i386_32.c
26924 @@ -0,0 +1,189 @@
26925 +/*
26926 + * This file contains various random system calls that
26927 + * have a non-standard calling sequence on the Linux/i386
26928 + * platform.
26929 + */
26930 +
26931 +#include <linux/errno.h>
26932 +#include <linux/sched.h>
26933 +#include <linux/mm.h>
26934 +#include <linux/fs.h>
26935 +#include <linux/smp.h>
26936 +#include <linux/sem.h>
26937 +#include <linux/msg.h>
26938 +#include <linux/shm.h>
26939 +#include <linux/stat.h>
26940 +#include <linux/syscalls.h>
26941 +#include <linux/mman.h>
26942 +#include <linux/file.h>
26943 +#include <linux/utsname.h>
26944 +#include <linux/ipc.h>
26945 +#include <linux/elf.h>
26946 +
26947 +#include <linux/uaccess.h>
26948 +#include <linux/unistd.h>
26949 +
26950 +#include <asm/syscalls.h>
26951 +
26952 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26953 +{
26954 + unsigned long pax_task_size = TASK_SIZE;
26955 +
26956 +#ifdef CONFIG_PAX_SEGMEXEC
26957 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26958 + pax_task_size = SEGMEXEC_TASK_SIZE;
26959 +#endif
26960 +
26961 + if (flags & MAP_FIXED)
26962 + if (len > pax_task_size || addr > pax_task_size - len)
26963 + return -EINVAL;
26964 +
26965 + return 0;
26966 +}
26967 +
26968 +/*
26969 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26970 + */
26971 +static unsigned long get_align_mask(void)
26972 +{
26973 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26974 + return 0;
26975 +
26976 + if (!(current->flags & PF_RANDOMIZE))
26977 + return 0;
26978 +
26979 + return va_align.mask;
26980 +}
26981 +
26982 +unsigned long
26983 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
26984 + unsigned long len, unsigned long pgoff, unsigned long flags)
26985 +{
26986 + struct mm_struct *mm = current->mm;
26987 + struct vm_area_struct *vma;
26988 + unsigned long pax_task_size = TASK_SIZE;
26989 + struct vm_unmapped_area_info info;
26990 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26991 +
26992 +#ifdef CONFIG_PAX_SEGMEXEC
26993 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26994 + pax_task_size = SEGMEXEC_TASK_SIZE;
26995 +#endif
26996 +
26997 + pax_task_size -= PAGE_SIZE;
26998 +
26999 + if (len > pax_task_size)
27000 + return -ENOMEM;
27001 +
27002 + if (flags & MAP_FIXED)
27003 + return addr;
27004 +
27005 +#ifdef CONFIG_PAX_RANDMMAP
27006 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27007 +#endif
27008 +
27009 + if (addr) {
27010 + addr = PAGE_ALIGN(addr);
27011 + if (pax_task_size - len >= addr) {
27012 + vma = find_vma(mm, addr);
27013 + if (check_heap_stack_gap(vma, addr, len, offset))
27014 + return addr;
27015 + }
27016 + }
27017 +
27018 + info.flags = 0;
27019 + info.length = len;
27020 + info.align_mask = filp ? get_align_mask() : 0;
27021 + info.align_offset = pgoff << PAGE_SHIFT;
27022 + info.threadstack_offset = offset;
27023 +
27024 +#ifdef CONFIG_PAX_PAGEEXEC
27025 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27026 + info.low_limit = 0x00110000UL;
27027 + info.high_limit = mm->start_code;
27028 +
27029 +#ifdef CONFIG_PAX_RANDMMAP
27030 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27031 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27032 +#endif
27033 +
27034 + if (info.low_limit < info.high_limit) {
27035 + addr = vm_unmapped_area(&info);
27036 + if (!IS_ERR_VALUE(addr))
27037 + return addr;
27038 + }
27039 + } else
27040 +#endif
27041 +
27042 + info.low_limit = mm->mmap_base;
27043 + info.high_limit = pax_task_size;
27044 +
27045 + return vm_unmapped_area(&info);
27046 +}
27047 +
27048 +unsigned long
27049 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27050 + const unsigned long len, const unsigned long pgoff,
27051 + const unsigned long flags)
27052 +{
27053 + struct vm_area_struct *vma;
27054 + struct mm_struct *mm = current->mm;
27055 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27056 + struct vm_unmapped_area_info info;
27057 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27058 +
27059 +#ifdef CONFIG_PAX_SEGMEXEC
27060 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27061 + pax_task_size = SEGMEXEC_TASK_SIZE;
27062 +#endif
27063 +
27064 + pax_task_size -= PAGE_SIZE;
27065 +
27066 + /* requested length too big for entire address space */
27067 + if (len > pax_task_size)
27068 + return -ENOMEM;
27069 +
27070 + if (flags & MAP_FIXED)
27071 + return addr;
27072 +
27073 +#ifdef CONFIG_PAX_PAGEEXEC
27074 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27075 + goto bottomup;
27076 +#endif
27077 +
27078 +#ifdef CONFIG_PAX_RANDMMAP
27079 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27080 +#endif
27081 +
27082 + /* requesting a specific address */
27083 + if (addr) {
27084 + addr = PAGE_ALIGN(addr);
27085 + if (pax_task_size - len >= addr) {
27086 + vma = find_vma(mm, addr);
27087 + if (check_heap_stack_gap(vma, addr, len, offset))
27088 + return addr;
27089 + }
27090 + }
27091 +
27092 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27093 + info.length = len;
27094 + info.low_limit = PAGE_SIZE;
27095 + info.high_limit = mm->mmap_base;
27096 + info.align_mask = filp ? get_align_mask() : 0;
27097 + info.align_offset = pgoff << PAGE_SHIFT;
27098 + info.threadstack_offset = offset;
27099 +
27100 + addr = vm_unmapped_area(&info);
27101 + if (!(addr & ~PAGE_MASK))
27102 + return addr;
27103 + VM_BUG_ON(addr != -ENOMEM);
27104 +
27105 +bottomup:
27106 + /*
27107 + * A failed mmap() very likely causes application failure,
27108 + * so fall back to the bottom-up function here. This scenario
27109 + * can happen with large stack limits and large mmap()
27110 + * allocations.
27111 + */
27112 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27113 +}
27114 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27115 index 30277e2..5664a29 100644
27116 --- a/arch/x86/kernel/sys_x86_64.c
27117 +++ b/arch/x86/kernel/sys_x86_64.c
27118 @@ -81,8 +81,8 @@ out:
27119 return error;
27120 }
27121
27122 -static void find_start_end(unsigned long flags, unsigned long *begin,
27123 - unsigned long *end)
27124 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27125 + unsigned long *begin, unsigned long *end)
27126 {
27127 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27128 unsigned long new_begin;
27129 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27130 *begin = new_begin;
27131 }
27132 } else {
27133 - *begin = current->mm->mmap_legacy_base;
27134 + *begin = mm->mmap_legacy_base;
27135 *end = TASK_SIZE;
27136 }
27137 }
27138 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27139 struct vm_area_struct *vma;
27140 struct vm_unmapped_area_info info;
27141 unsigned long begin, end;
27142 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27143
27144 if (flags & MAP_FIXED)
27145 return addr;
27146
27147 - find_start_end(flags, &begin, &end);
27148 + find_start_end(mm, flags, &begin, &end);
27149
27150 if (len > end)
27151 return -ENOMEM;
27152
27153 +#ifdef CONFIG_PAX_RANDMMAP
27154 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27155 +#endif
27156 +
27157 if (addr) {
27158 addr = PAGE_ALIGN(addr);
27159 vma = find_vma(mm, addr);
27160 - if (end - len >= addr &&
27161 - (!vma || addr + len <= vma->vm_start))
27162 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27163 return addr;
27164 }
27165
27166 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27167 info.high_limit = end;
27168 info.align_mask = filp ? get_align_mask() : 0;
27169 info.align_offset = pgoff << PAGE_SHIFT;
27170 + info.threadstack_offset = offset;
27171 return vm_unmapped_area(&info);
27172 }
27173
27174 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27175 struct mm_struct *mm = current->mm;
27176 unsigned long addr = addr0;
27177 struct vm_unmapped_area_info info;
27178 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27179
27180 /* requested length too big for entire address space */
27181 if (len > TASK_SIZE)
27182 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27183 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27184 goto bottomup;
27185
27186 +#ifdef CONFIG_PAX_RANDMMAP
27187 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27188 +#endif
27189 +
27190 /* requesting a specific address */
27191 if (addr) {
27192 addr = PAGE_ALIGN(addr);
27193 vma = find_vma(mm, addr);
27194 - if (TASK_SIZE - len >= addr &&
27195 - (!vma || addr + len <= vma->vm_start))
27196 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27197 return addr;
27198 }
27199
27200 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27201 info.high_limit = mm->mmap_base;
27202 info.align_mask = filp ? get_align_mask() : 0;
27203 info.align_offset = pgoff << PAGE_SHIFT;
27204 + info.threadstack_offset = offset;
27205 addr = vm_unmapped_area(&info);
27206 if (!(addr & ~PAGE_MASK))
27207 return addr;
27208 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27209 index 91a4496..bb87552 100644
27210 --- a/arch/x86/kernel/tboot.c
27211 +++ b/arch/x86/kernel/tboot.c
27212 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27213
27214 void tboot_shutdown(u32 shutdown_type)
27215 {
27216 - void (*shutdown)(void);
27217 + void (* __noreturn shutdown)(void);
27218
27219 if (!tboot_enabled())
27220 return;
27221 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27222
27223 switch_to_tboot_pt();
27224
27225 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27226 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27227 shutdown();
27228
27229 /* should not reach here */
27230 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27231 return -ENODEV;
27232 }
27233
27234 -static atomic_t ap_wfs_count;
27235 +static atomic_unchecked_t ap_wfs_count;
27236
27237 static int tboot_wait_for_aps(int num_aps)
27238 {
27239 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27240 {
27241 switch (action) {
27242 case CPU_DYING:
27243 - atomic_inc(&ap_wfs_count);
27244 + atomic_inc_unchecked(&ap_wfs_count);
27245 if (num_online_cpus() == 1)
27246 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27247 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27248 return NOTIFY_BAD;
27249 break;
27250 }
27251 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27252
27253 tboot_create_trampoline();
27254
27255 - atomic_set(&ap_wfs_count, 0);
27256 + atomic_set_unchecked(&ap_wfs_count, 0);
27257 register_hotcpu_notifier(&tboot_cpu_notifier);
27258
27259 #ifdef CONFIG_DEBUG_FS
27260 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27261 index 24d3c91..d06b473 100644
27262 --- a/arch/x86/kernel/time.c
27263 +++ b/arch/x86/kernel/time.c
27264 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27265 {
27266 unsigned long pc = instruction_pointer(regs);
27267
27268 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27269 + if (!user_mode(regs) && in_lock_functions(pc)) {
27270 #ifdef CONFIG_FRAME_POINTER
27271 - return *(unsigned long *)(regs->bp + sizeof(long));
27272 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27273 #else
27274 unsigned long *sp =
27275 (unsigned long *)kernel_stack_pointer(regs);
27276 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27277 * or above a saved flags. Eflags has bits 22-31 zero,
27278 * kernel addresses don't.
27279 */
27280 +
27281 +#ifdef CONFIG_PAX_KERNEXEC
27282 + return ktla_ktva(sp[0]);
27283 +#else
27284 if (sp[0] >> 22)
27285 return sp[0];
27286 if (sp[1] >> 22)
27287 return sp[1];
27288 #endif
27289 +
27290 +#endif
27291 }
27292 return pc;
27293 }
27294 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27295 index f7fec09..9991981 100644
27296 --- a/arch/x86/kernel/tls.c
27297 +++ b/arch/x86/kernel/tls.c
27298 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27299 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27300 return -EINVAL;
27301
27302 +#ifdef CONFIG_PAX_SEGMEXEC
27303 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27304 + return -EINVAL;
27305 +#endif
27306 +
27307 set_tls_desc(p, idx, &info, 1);
27308
27309 return 0;
27310 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27311
27312 if (kbuf)
27313 info = kbuf;
27314 - else if (__copy_from_user(infobuf, ubuf, count))
27315 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27316 return -EFAULT;
27317 else
27318 info = infobuf;
27319 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27320 index 1c113db..287b42e 100644
27321 --- a/arch/x86/kernel/tracepoint.c
27322 +++ b/arch/x86/kernel/tracepoint.c
27323 @@ -9,11 +9,11 @@
27324 #include <linux/atomic.h>
27325
27326 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27327 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27328 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27329 (unsigned long) trace_idt_table };
27330
27331 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27332 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27333 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27334
27335 static int trace_irq_vector_refcount;
27336 static DEFINE_MUTEX(irq_vector_mutex);
27337 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27338 index b857ed8..51ae4cb 100644
27339 --- a/arch/x86/kernel/traps.c
27340 +++ b/arch/x86/kernel/traps.c
27341 @@ -66,7 +66,7 @@
27342 #include <asm/proto.h>
27343
27344 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27345 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27346 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27347 #else
27348 #include <asm/processor-flags.h>
27349 #include <asm/setup.h>
27350 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27351 #endif
27352
27353 /* Must be page-aligned because the real IDT is used in a fixmap. */
27354 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27355 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27356
27357 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27358 EXPORT_SYMBOL_GPL(used_vectors);
27359 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27360 }
27361
27362 static int __kprobes
27363 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27364 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27365 struct pt_regs *regs, long error_code)
27366 {
27367 #ifdef CONFIG_X86_32
27368 - if (regs->flags & X86_VM_MASK) {
27369 + if (v8086_mode(regs)) {
27370 /*
27371 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27372 * On nmi (interrupt 2), do_trap should not be called.
27373 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27374 return -1;
27375 }
27376 #endif
27377 - if (!user_mode(regs)) {
27378 + if (!user_mode_novm(regs)) {
27379 if (!fixup_exception(regs)) {
27380 tsk->thread.error_code = error_code;
27381 tsk->thread.trap_nr = trapnr;
27382 +
27383 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27384 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27385 + str = "PAX: suspicious stack segment fault";
27386 +#endif
27387 +
27388 die(str, regs, error_code);
27389 }
27390 +
27391 +#ifdef CONFIG_PAX_REFCOUNT
27392 + if (trapnr == 4)
27393 + pax_report_refcount_overflow(regs);
27394 +#endif
27395 +
27396 return 0;
27397 }
27398
27399 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27400 }
27401
27402 static void __kprobes
27403 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27404 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27405 long error_code, siginfo_t *info)
27406 {
27407 struct task_struct *tsk = current;
27408 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27409 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27410 printk_ratelimit()) {
27411 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27412 - tsk->comm, tsk->pid, str,
27413 + tsk->comm, task_pid_nr(tsk), str,
27414 regs->ip, regs->sp, error_code);
27415 print_vma_addr(" in ", regs->ip);
27416 pr_cont("\n");
27417 @@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27418 conditional_sti(regs);
27419
27420 #ifdef CONFIG_X86_32
27421 - if (regs->flags & X86_VM_MASK) {
27422 + if (v8086_mode(regs)) {
27423 local_irq_enable();
27424 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27425 goto exit;
27426 @@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27427 #endif
27428
27429 tsk = current;
27430 - if (!user_mode(regs)) {
27431 + if (!user_mode_novm(regs)) {
27432 if (fixup_exception(regs))
27433 goto exit;
27434
27435 tsk->thread.error_code = error_code;
27436 tsk->thread.trap_nr = X86_TRAP_GP;
27437 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27438 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27439 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27440 +
27441 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27442 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27443 + die("PAX: suspicious general protection fault", regs, error_code);
27444 + else
27445 +#endif
27446 +
27447 die("general protection fault", regs, error_code);
27448 + }
27449 goto exit;
27450 }
27451
27452 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27453 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27454 + struct mm_struct *mm = tsk->mm;
27455 + unsigned long limit;
27456 +
27457 + down_write(&mm->mmap_sem);
27458 + limit = mm->context.user_cs_limit;
27459 + if (limit < TASK_SIZE) {
27460 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27461 + up_write(&mm->mmap_sem);
27462 + return;
27463 + }
27464 + up_write(&mm->mmap_sem);
27465 + }
27466 +#endif
27467 +
27468 tsk->thread.error_code = error_code;
27469 tsk->thread.trap_nr = X86_TRAP_GP;
27470
27471 @@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27472 /* It's safe to allow irq's after DR6 has been saved */
27473 preempt_conditional_sti(regs);
27474
27475 - if (regs->flags & X86_VM_MASK) {
27476 + if (v8086_mode(regs)) {
27477 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27478 X86_TRAP_DB);
27479 preempt_conditional_cli(regs);
27480 @@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27481 * We already checked v86 mode above, so we can check for kernel mode
27482 * by just checking the CPL of CS.
27483 */
27484 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27485 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27486 tsk->thread.debugreg6 &= ~DR_STEP;
27487 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27488 regs->flags &= ~X86_EFLAGS_TF;
27489 @@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27490 return;
27491 conditional_sti(regs);
27492
27493 - if (!user_mode_vm(regs))
27494 + if (!user_mode(regs))
27495 {
27496 if (!fixup_exception(regs)) {
27497 task->thread.error_code = error_code;
27498 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27499 index 2ed8459..7cf329f 100644
27500 --- a/arch/x86/kernel/uprobes.c
27501 +++ b/arch/x86/kernel/uprobes.c
27502 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27503 int ret = NOTIFY_DONE;
27504
27505 /* We are only interested in userspace traps */
27506 - if (regs && !user_mode_vm(regs))
27507 + if (regs && !user_mode(regs))
27508 return NOTIFY_DONE;
27509
27510 switch (val) {
27511 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27512
27513 if (ncopied != rasize) {
27514 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27515 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27516 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27517
27518 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27519 }
27520 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27521 index b9242ba..50c5edd 100644
27522 --- a/arch/x86/kernel/verify_cpu.S
27523 +++ b/arch/x86/kernel/verify_cpu.S
27524 @@ -20,6 +20,7 @@
27525 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27526 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27527 * arch/x86/kernel/head_32.S: processor startup
27528 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27529 *
27530 * verify_cpu, returns the status of longmode and SSE in register %eax.
27531 * 0: Success 1: Failure
27532 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27533 index e8edcf5..27f9344 100644
27534 --- a/arch/x86/kernel/vm86_32.c
27535 +++ b/arch/x86/kernel/vm86_32.c
27536 @@ -44,6 +44,7 @@
27537 #include <linux/ptrace.h>
27538 #include <linux/audit.h>
27539 #include <linux/stddef.h>
27540 +#include <linux/grsecurity.h>
27541
27542 #include <asm/uaccess.h>
27543 #include <asm/io.h>
27544 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27545 do_exit(SIGSEGV);
27546 }
27547
27548 - tss = &per_cpu(init_tss, get_cpu());
27549 + tss = init_tss + get_cpu();
27550 current->thread.sp0 = current->thread.saved_sp0;
27551 current->thread.sysenter_cs = __KERNEL_CS;
27552 load_sp0(tss, &current->thread);
27553 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27554
27555 if (tsk->thread.saved_sp0)
27556 return -EPERM;
27557 +
27558 +#ifdef CONFIG_GRKERNSEC_VM86
27559 + if (!capable(CAP_SYS_RAWIO)) {
27560 + gr_handle_vm86();
27561 + return -EPERM;
27562 + }
27563 +#endif
27564 +
27565 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27566 offsetof(struct kernel_vm86_struct, vm86plus) -
27567 sizeof(info.regs));
27568 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27569 int tmp;
27570 struct vm86plus_struct __user *v86;
27571
27572 +#ifdef CONFIG_GRKERNSEC_VM86
27573 + if (!capable(CAP_SYS_RAWIO)) {
27574 + gr_handle_vm86();
27575 + return -EPERM;
27576 + }
27577 +#endif
27578 +
27579 tsk = current;
27580 switch (cmd) {
27581 case VM86_REQUEST_IRQ:
27582 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27583 tsk->thread.saved_fs = info->regs32->fs;
27584 tsk->thread.saved_gs = get_user_gs(info->regs32);
27585
27586 - tss = &per_cpu(init_tss, get_cpu());
27587 + tss = init_tss + get_cpu();
27588 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27589 if (cpu_has_sep)
27590 tsk->thread.sysenter_cs = 0;
27591 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27592 goto cannot_handle;
27593 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27594 goto cannot_handle;
27595 - intr_ptr = (unsigned long __user *) (i << 2);
27596 + intr_ptr = (__force unsigned long __user *) (i << 2);
27597 if (get_user(segoffs, intr_ptr))
27598 goto cannot_handle;
27599 if ((segoffs >> 16) == BIOSSEG)
27600 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27601 index da6b35a..977e9cf 100644
27602 --- a/arch/x86/kernel/vmlinux.lds.S
27603 +++ b/arch/x86/kernel/vmlinux.lds.S
27604 @@ -26,6 +26,13 @@
27605 #include <asm/page_types.h>
27606 #include <asm/cache.h>
27607 #include <asm/boot.h>
27608 +#include <asm/segment.h>
27609 +
27610 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27611 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27612 +#else
27613 +#define __KERNEL_TEXT_OFFSET 0
27614 +#endif
27615
27616 #undef i386 /* in case the preprocessor is a 32bit one */
27617
27618 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27619
27620 PHDRS {
27621 text PT_LOAD FLAGS(5); /* R_E */
27622 +#ifdef CONFIG_X86_32
27623 + module PT_LOAD FLAGS(5); /* R_E */
27624 +#endif
27625 +#ifdef CONFIG_XEN
27626 + rodata PT_LOAD FLAGS(5); /* R_E */
27627 +#else
27628 + rodata PT_LOAD FLAGS(4); /* R__ */
27629 +#endif
27630 data PT_LOAD FLAGS(6); /* RW_ */
27631 -#ifdef CONFIG_X86_64
27632 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27633 #ifdef CONFIG_SMP
27634 percpu PT_LOAD FLAGS(6); /* RW_ */
27635 #endif
27636 + text.init PT_LOAD FLAGS(5); /* R_E */
27637 + text.exit PT_LOAD FLAGS(5); /* R_E */
27638 init PT_LOAD FLAGS(7); /* RWE */
27639 -#endif
27640 note PT_NOTE FLAGS(0); /* ___ */
27641 }
27642
27643 SECTIONS
27644 {
27645 #ifdef CONFIG_X86_32
27646 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27647 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27648 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27649 #else
27650 - . = __START_KERNEL;
27651 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27652 + . = __START_KERNEL;
27653 #endif
27654
27655 /* Text and read-only data */
27656 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27657 - _text = .;
27658 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27659 /* bootstrapping code */
27660 +#ifdef CONFIG_X86_32
27661 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27662 +#else
27663 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27664 +#endif
27665 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27666 + _text = .;
27667 HEAD_TEXT
27668 . = ALIGN(8);
27669 _stext = .;
27670 @@ -104,13 +124,47 @@ SECTIONS
27671 IRQENTRY_TEXT
27672 *(.fixup)
27673 *(.gnu.warning)
27674 - /* End of text section */
27675 - _etext = .;
27676 } :text = 0x9090
27677
27678 - NOTES :text :note
27679 + . += __KERNEL_TEXT_OFFSET;
27680
27681 - EXCEPTION_TABLE(16) :text = 0x9090
27682 +#ifdef CONFIG_X86_32
27683 + . = ALIGN(PAGE_SIZE);
27684 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27685 +
27686 +#ifdef CONFIG_PAX_KERNEXEC
27687 + MODULES_EXEC_VADDR = .;
27688 + BYTE(0)
27689 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27690 + . = ALIGN(HPAGE_SIZE) - 1;
27691 + MODULES_EXEC_END = .;
27692 +#endif
27693 +
27694 + } :module
27695 +#endif
27696 +
27697 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27698 + /* End of text section */
27699 + BYTE(0)
27700 + _etext = . - __KERNEL_TEXT_OFFSET;
27701 + }
27702 +
27703 +#ifdef CONFIG_X86_32
27704 + . = ALIGN(PAGE_SIZE);
27705 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27706 + . = ALIGN(PAGE_SIZE);
27707 + *(.empty_zero_page)
27708 + *(.initial_pg_fixmap)
27709 + *(.initial_pg_pmd)
27710 + *(.initial_page_table)
27711 + *(.swapper_pg_dir)
27712 + } :rodata
27713 +#endif
27714 +
27715 + . = ALIGN(PAGE_SIZE);
27716 + NOTES :rodata :note
27717 +
27718 + EXCEPTION_TABLE(16) :rodata
27719
27720 #if defined(CONFIG_DEBUG_RODATA)
27721 /* .text should occupy whole number of pages */
27722 @@ -122,16 +176,20 @@ SECTIONS
27723
27724 /* Data */
27725 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27726 +
27727 +#ifdef CONFIG_PAX_KERNEXEC
27728 + . = ALIGN(HPAGE_SIZE);
27729 +#else
27730 + . = ALIGN(PAGE_SIZE);
27731 +#endif
27732 +
27733 /* Start of data section */
27734 _sdata = .;
27735
27736 /* init_task */
27737 INIT_TASK_DATA(THREAD_SIZE)
27738
27739 -#ifdef CONFIG_X86_32
27740 - /* 32 bit has nosave before _edata */
27741 NOSAVE_DATA
27742 -#endif
27743
27744 PAGE_ALIGNED_DATA(PAGE_SIZE)
27745
27746 @@ -172,12 +230,19 @@ SECTIONS
27747 #endif /* CONFIG_X86_64 */
27748
27749 /* Init code and data - will be freed after init */
27750 - . = ALIGN(PAGE_SIZE);
27751 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27752 + BYTE(0)
27753 +
27754 +#ifdef CONFIG_PAX_KERNEXEC
27755 + . = ALIGN(HPAGE_SIZE);
27756 +#else
27757 + . = ALIGN(PAGE_SIZE);
27758 +#endif
27759 +
27760 __init_begin = .; /* paired with __init_end */
27761 - }
27762 + } :init.begin
27763
27764 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27765 +#ifdef CONFIG_SMP
27766 /*
27767 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27768 * output PHDR, so the next output section - .init.text - should
27769 @@ -186,12 +251,27 @@ SECTIONS
27770 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27771 #endif
27772
27773 - INIT_TEXT_SECTION(PAGE_SIZE)
27774 -#ifdef CONFIG_X86_64
27775 - :init
27776 -#endif
27777 + . = ALIGN(PAGE_SIZE);
27778 + init_begin = .;
27779 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27780 + VMLINUX_SYMBOL(_sinittext) = .;
27781 + INIT_TEXT
27782 + VMLINUX_SYMBOL(_einittext) = .;
27783 + . = ALIGN(PAGE_SIZE);
27784 + } :text.init
27785
27786 - INIT_DATA_SECTION(16)
27787 + /*
27788 + * .exit.text is discard at runtime, not link time, to deal with
27789 + * references from .altinstructions and .eh_frame
27790 + */
27791 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27792 + EXIT_TEXT
27793 + . = ALIGN(16);
27794 + } :text.exit
27795 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27796 +
27797 + . = ALIGN(PAGE_SIZE);
27798 + INIT_DATA_SECTION(16) :init
27799
27800 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27801 __x86_cpu_dev_start = .;
27802 @@ -262,19 +342,12 @@ SECTIONS
27803 }
27804
27805 . = ALIGN(8);
27806 - /*
27807 - * .exit.text is discard at runtime, not link time, to deal with
27808 - * references from .altinstructions and .eh_frame
27809 - */
27810 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27811 - EXIT_TEXT
27812 - }
27813
27814 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27815 EXIT_DATA
27816 }
27817
27818 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27819 +#ifndef CONFIG_SMP
27820 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27821 #endif
27822
27823 @@ -293,16 +366,10 @@ SECTIONS
27824 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27825 __smp_locks = .;
27826 *(.smp_locks)
27827 - . = ALIGN(PAGE_SIZE);
27828 __smp_locks_end = .;
27829 + . = ALIGN(PAGE_SIZE);
27830 }
27831
27832 -#ifdef CONFIG_X86_64
27833 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27834 - NOSAVE_DATA
27835 - }
27836 -#endif
27837 -
27838 /* BSS */
27839 . = ALIGN(PAGE_SIZE);
27840 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27841 @@ -318,6 +385,7 @@ SECTIONS
27842 __brk_base = .;
27843 . += 64 * 1024; /* 64k alignment slop space */
27844 *(.brk_reservation) /* areas brk users have reserved */
27845 + . = ALIGN(HPAGE_SIZE);
27846 __brk_limit = .;
27847 }
27848
27849 @@ -344,13 +412,12 @@ SECTIONS
27850 * for the boot processor.
27851 */
27852 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27853 -INIT_PER_CPU(gdt_page);
27854 INIT_PER_CPU(irq_stack_union);
27855
27856 /*
27857 * Build-time check on the image size:
27858 */
27859 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27860 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27861 "kernel image bigger than KERNEL_IMAGE_SIZE");
27862
27863 #ifdef CONFIG_SMP
27864 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27865 index 1f96f93..d5c8f7a 100644
27866 --- a/arch/x86/kernel/vsyscall_64.c
27867 +++ b/arch/x86/kernel/vsyscall_64.c
27868 @@ -56,15 +56,13 @@
27869 DEFINE_VVAR(int, vgetcpu_mode);
27870 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27871
27872 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27873 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27874
27875 static int __init vsyscall_setup(char *str)
27876 {
27877 if (str) {
27878 if (!strcmp("emulate", str))
27879 vsyscall_mode = EMULATE;
27880 - else if (!strcmp("native", str))
27881 - vsyscall_mode = NATIVE;
27882 else if (!strcmp("none", str))
27883 vsyscall_mode = NONE;
27884 else
27885 @@ -323,8 +321,7 @@ do_ret:
27886 return true;
27887
27888 sigsegv:
27889 - force_sig(SIGSEGV, current);
27890 - return true;
27891 + do_group_exit(SIGKILL);
27892 }
27893
27894 /*
27895 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27896 extern char __vvar_page;
27897 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27898
27899 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27900 - vsyscall_mode == NATIVE
27901 - ? PAGE_KERNEL_VSYSCALL
27902 - : PAGE_KERNEL_VVAR);
27903 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27904 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27905 (unsigned long)VSYSCALL_START);
27906
27907 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27908 index 04068192..4d75aa6 100644
27909 --- a/arch/x86/kernel/x8664_ksyms_64.c
27910 +++ b/arch/x86/kernel/x8664_ksyms_64.c
27911 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27912 EXPORT_SYMBOL(copy_user_generic_unrolled);
27913 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27914 EXPORT_SYMBOL(__copy_user_nocache);
27915 -EXPORT_SYMBOL(_copy_from_user);
27916 -EXPORT_SYMBOL(_copy_to_user);
27917
27918 EXPORT_SYMBOL(copy_page);
27919 EXPORT_SYMBOL(clear_page);
27920 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27921 EXPORT_SYMBOL(___preempt_schedule_context);
27922 #endif
27923 #endif
27924 +
27925 +#ifdef CONFIG_PAX_PER_CPU_PGD
27926 +EXPORT_SYMBOL(cpu_pgd);
27927 +#endif
27928 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27929 index 021783b..6511282 100644
27930 --- a/arch/x86/kernel/x86_init.c
27931 +++ b/arch/x86/kernel/x86_init.c
27932 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27933 static void default_nmi_init(void) { };
27934 static int default_i8042_detect(void) { return 1; };
27935
27936 -struct x86_platform_ops x86_platform = {
27937 +struct x86_platform_ops x86_platform __read_only = {
27938 .calibrate_tsc = native_calibrate_tsc,
27939 .get_wallclock = mach_get_cmos_time,
27940 .set_wallclock = mach_set_rtc_mmss,
27941 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27942 EXPORT_SYMBOL_GPL(x86_platform);
27943
27944 #if defined(CONFIG_PCI_MSI)
27945 -struct x86_msi_ops x86_msi = {
27946 +struct x86_msi_ops x86_msi __read_only = {
27947 .setup_msi_irqs = native_setup_msi_irqs,
27948 .compose_msi_msg = native_compose_msi_msg,
27949 .teardown_msi_irq = native_teardown_msi_irq,
27950 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27951 }
27952 #endif
27953
27954 -struct x86_io_apic_ops x86_io_apic_ops = {
27955 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27956 .init = native_io_apic_init_mappings,
27957 .read = native_io_apic_read,
27958 .write = native_io_apic_write,
27959 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27960 index 422fd82..b2d262e 100644
27961 --- a/arch/x86/kernel/xsave.c
27962 +++ b/arch/x86/kernel/xsave.c
27963 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27964
27965 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27966 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27967 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27968 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27969
27970 if (!use_xsave())
27971 return err;
27972
27973 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27974 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27975
27976 /*
27977 * Read the xstate_bv which we copied (directly from the cpu or
27978 * from the state in task struct) to the user buffers.
27979 */
27980 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27981 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27982
27983 /*
27984 * For legacy compatible, we always set FP/SSE bits in the bit
27985 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27986 */
27987 xstate_bv |= XSTATE_FPSSE;
27988
27989 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27990 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27991
27992 return err;
27993 }
27994 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27995 {
27996 int err;
27997
27998 + buf = (struct xsave_struct __user *)____m(buf);
27999 if (use_xsave())
28000 err = xsave_user(buf);
28001 else if (use_fxsr())
28002 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28003 */
28004 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28005 {
28006 + buf = (void __user *)____m(buf);
28007 if (use_xsave()) {
28008 if ((unsigned long)buf % 64 || fx_only) {
28009 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28010 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28011 index c697625..a032162 100644
28012 --- a/arch/x86/kvm/cpuid.c
28013 +++ b/arch/x86/kvm/cpuid.c
28014 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28015 struct kvm_cpuid2 *cpuid,
28016 struct kvm_cpuid_entry2 __user *entries)
28017 {
28018 - int r;
28019 + int r, i;
28020
28021 r = -E2BIG;
28022 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28023 goto out;
28024 r = -EFAULT;
28025 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28026 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28027 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28028 goto out;
28029 + for (i = 0; i < cpuid->nent; ++i) {
28030 + struct kvm_cpuid_entry2 cpuid_entry;
28031 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28032 + goto out;
28033 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28034 + }
28035 vcpu->arch.cpuid_nent = cpuid->nent;
28036 kvm_apic_set_version(vcpu);
28037 kvm_x86_ops->cpuid_update(vcpu);
28038 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28039 struct kvm_cpuid2 *cpuid,
28040 struct kvm_cpuid_entry2 __user *entries)
28041 {
28042 - int r;
28043 + int r, i;
28044
28045 r = -E2BIG;
28046 if (cpuid->nent < vcpu->arch.cpuid_nent)
28047 goto out;
28048 r = -EFAULT;
28049 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28050 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28051 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28052 goto out;
28053 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28054 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28055 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28056 + goto out;
28057 + }
28058 return 0;
28059
28060 out:
28061 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28062 index d86ff15..e77b023 100644
28063 --- a/arch/x86/kvm/lapic.c
28064 +++ b/arch/x86/kvm/lapic.c
28065 @@ -55,7 +55,7 @@
28066 #define APIC_BUS_CYCLE_NS 1
28067
28068 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28069 -#define apic_debug(fmt, arg...)
28070 +#define apic_debug(fmt, arg...) do {} while (0)
28071
28072 #define APIC_LVT_NUM 6
28073 /* 14 is the version for Xeon and Pentium 8.4.8*/
28074 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28075 index ad75d77..a679d32 100644
28076 --- a/arch/x86/kvm/paging_tmpl.h
28077 +++ b/arch/x86/kvm/paging_tmpl.h
28078 @@ -331,7 +331,7 @@ retry_walk:
28079 if (unlikely(kvm_is_error_hva(host_addr)))
28080 goto error;
28081
28082 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28083 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28084 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28085 goto error;
28086 walker->ptep_user[walker->level - 1] = ptep_user;
28087 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28088 index c7168a5..09070fc 100644
28089 --- a/arch/x86/kvm/svm.c
28090 +++ b/arch/x86/kvm/svm.c
28091 @@ -3497,7 +3497,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28092 int cpu = raw_smp_processor_id();
28093
28094 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28095 +
28096 + pax_open_kernel();
28097 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28098 + pax_close_kernel();
28099 +
28100 load_TR_desc();
28101 }
28102
28103 @@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28104 #endif
28105 #endif
28106
28107 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28108 + __set_fs(current_thread_info()->addr_limit);
28109 +#endif
28110 +
28111 reload_tss(vcpu);
28112
28113 local_irq_disable();
28114 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28115 index dcc4de3..6bf73f4 100644
28116 --- a/arch/x86/kvm/vmx.c
28117 +++ b/arch/x86/kvm/vmx.c
28118 @@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28119 #endif
28120 }
28121
28122 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28123 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28124 {
28125 vmcs_writel(field, vmcs_readl(field) & ~mask);
28126 }
28127
28128 -static void vmcs_set_bits(unsigned long field, u32 mask)
28129 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28130 {
28131 vmcs_writel(field, vmcs_readl(field) | mask);
28132 }
28133 @@ -1522,7 +1522,11 @@ static void reload_tss(void)
28134 struct desc_struct *descs;
28135
28136 descs = (void *)gdt->address;
28137 +
28138 + pax_open_kernel();
28139 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28140 + pax_close_kernel();
28141 +
28142 load_TR_desc();
28143 }
28144
28145 @@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28146 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28147 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28148
28149 +#ifdef CONFIG_PAX_PER_CPU_PGD
28150 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28151 +#endif
28152 +
28153 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28154 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28155 vmx->loaded_vmcs->cpu = cpu;
28156 @@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28157 * reads and returns guest's timestamp counter "register"
28158 * guest_tsc = host_tsc + tsc_offset -- 21.3
28159 */
28160 -static u64 guest_read_tsc(void)
28161 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28162 {
28163 u64 host_tsc, tsc_offset;
28164
28165 @@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
28166 if (!cpu_has_vmx_flexpriority())
28167 flexpriority_enabled = 0;
28168
28169 - if (!cpu_has_vmx_tpr_shadow())
28170 - kvm_x86_ops->update_cr8_intercept = NULL;
28171 + if (!cpu_has_vmx_tpr_shadow()) {
28172 + pax_open_kernel();
28173 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28174 + pax_close_kernel();
28175 + }
28176
28177 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28178 kvm_disable_largepages();
28179 @@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
28180 if (!cpu_has_vmx_apicv())
28181 enable_apicv = 0;
28182
28183 + pax_open_kernel();
28184 if (enable_apicv)
28185 - kvm_x86_ops->update_cr8_intercept = NULL;
28186 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28187 else {
28188 - kvm_x86_ops->hwapic_irr_update = NULL;
28189 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28190 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28191 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28192 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28193 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28194 }
28195 + pax_close_kernel();
28196
28197 if (nested)
28198 nested_vmx_setup_ctls_msrs();
28199 @@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28200
28201 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28202 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28203 +
28204 +#ifndef CONFIG_PAX_PER_CPU_PGD
28205 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28206 +#endif
28207
28208 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28209 #ifdef CONFIG_X86_64
28210 @@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28211 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28212 vmx->host_idt_base = dt.address;
28213
28214 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28215 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28216
28217 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28218 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28219 @@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28220 "jmp 2f \n\t"
28221 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28222 "2: "
28223 +
28224 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28225 + "ljmp %[cs],$3f\n\t"
28226 + "3: "
28227 +#endif
28228 +
28229 /* Save guest registers, load host registers, keep flags */
28230 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28231 "pop %0 \n\t"
28232 @@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28233 #endif
28234 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28235 [wordsize]"i"(sizeof(ulong))
28236 +
28237 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28238 + ,[cs]"i"(__KERNEL_CS)
28239 +#endif
28240 +
28241 : "cc", "memory"
28242 #ifdef CONFIG_X86_64
28243 , "rax", "rbx", "rdi", "rsi"
28244 @@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28245 if (debugctlmsr)
28246 update_debugctlmsr(debugctlmsr);
28247
28248 -#ifndef CONFIG_X86_64
28249 +#ifdef CONFIG_X86_32
28250 /*
28251 * The sysexit path does not restore ds/es, so we must set them to
28252 * a reasonable value ourselves.
28253 @@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28254 * may be executed in interrupt context, which saves and restore segments
28255 * around it, nullifying its effect.
28256 */
28257 - loadsegment(ds, __USER_DS);
28258 - loadsegment(es, __USER_DS);
28259 + loadsegment(ds, __KERNEL_DS);
28260 + loadsegment(es, __KERNEL_DS);
28261 + loadsegment(ss, __KERNEL_DS);
28262 +
28263 +#ifdef CONFIG_PAX_KERNEXEC
28264 + loadsegment(fs, __KERNEL_PERCPU);
28265 +#endif
28266 +
28267 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28268 + __set_fs(current_thread_info()->addr_limit);
28269 +#endif
28270 +
28271 #endif
28272
28273 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28274 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28275 index 4e33b85..fa94855 100644
28276 --- a/arch/x86/kvm/x86.c
28277 +++ b/arch/x86/kvm/x86.c
28278 @@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28279 {
28280 struct kvm *kvm = vcpu->kvm;
28281 int lm = is_long_mode(vcpu);
28282 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28283 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28284 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28285 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28286 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28287 : kvm->arch.xen_hvm_config.blob_size_32;
28288 u32 page_num = data & ~PAGE_MASK;
28289 @@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28290 if (n < msr_list.nmsrs)
28291 goto out;
28292 r = -EFAULT;
28293 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28294 + goto out;
28295 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28296 num_msrs_to_save * sizeof(u32)))
28297 goto out;
28298 @@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28299 };
28300 #endif
28301
28302 -int kvm_arch_init(void *opaque)
28303 +int kvm_arch_init(const void *opaque)
28304 {
28305 int r;
28306 struct kvm_x86_ops *ops = opaque;
28307 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28308 index bdf8532..f63c587 100644
28309 --- a/arch/x86/lguest/boot.c
28310 +++ b/arch/x86/lguest/boot.c
28311 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28312 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28313 * Launcher to reboot us.
28314 */
28315 -static void lguest_restart(char *reason)
28316 +static __noreturn void lguest_restart(char *reason)
28317 {
28318 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28319 + BUG();
28320 }
28321
28322 /*G:050
28323 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28324 index 00933d5..3a64af9 100644
28325 --- a/arch/x86/lib/atomic64_386_32.S
28326 +++ b/arch/x86/lib/atomic64_386_32.S
28327 @@ -48,6 +48,10 @@ BEGIN(read)
28328 movl (v), %eax
28329 movl 4(v), %edx
28330 RET_ENDP
28331 +BEGIN(read_unchecked)
28332 + movl (v), %eax
28333 + movl 4(v), %edx
28334 +RET_ENDP
28335 #undef v
28336
28337 #define v %esi
28338 @@ -55,6 +59,10 @@ BEGIN(set)
28339 movl %ebx, (v)
28340 movl %ecx, 4(v)
28341 RET_ENDP
28342 +BEGIN(set_unchecked)
28343 + movl %ebx, (v)
28344 + movl %ecx, 4(v)
28345 +RET_ENDP
28346 #undef v
28347
28348 #define v %esi
28349 @@ -70,6 +78,20 @@ RET_ENDP
28350 BEGIN(add)
28351 addl %eax, (v)
28352 adcl %edx, 4(v)
28353 +
28354 +#ifdef CONFIG_PAX_REFCOUNT
28355 + jno 0f
28356 + subl %eax, (v)
28357 + sbbl %edx, 4(v)
28358 + int $4
28359 +0:
28360 + _ASM_EXTABLE(0b, 0b)
28361 +#endif
28362 +
28363 +RET_ENDP
28364 +BEGIN(add_unchecked)
28365 + addl %eax, (v)
28366 + adcl %edx, 4(v)
28367 RET_ENDP
28368 #undef v
28369
28370 @@ -77,6 +99,24 @@ RET_ENDP
28371 BEGIN(add_return)
28372 addl (v), %eax
28373 adcl 4(v), %edx
28374 +
28375 +#ifdef CONFIG_PAX_REFCOUNT
28376 + into
28377 +1234:
28378 + _ASM_EXTABLE(1234b, 2f)
28379 +#endif
28380 +
28381 + movl %eax, (v)
28382 + movl %edx, 4(v)
28383 +
28384 +#ifdef CONFIG_PAX_REFCOUNT
28385 +2:
28386 +#endif
28387 +
28388 +RET_ENDP
28389 +BEGIN(add_return_unchecked)
28390 + addl (v), %eax
28391 + adcl 4(v), %edx
28392 movl %eax, (v)
28393 movl %edx, 4(v)
28394 RET_ENDP
28395 @@ -86,6 +126,20 @@ RET_ENDP
28396 BEGIN(sub)
28397 subl %eax, (v)
28398 sbbl %edx, 4(v)
28399 +
28400 +#ifdef CONFIG_PAX_REFCOUNT
28401 + jno 0f
28402 + addl %eax, (v)
28403 + adcl %edx, 4(v)
28404 + int $4
28405 +0:
28406 + _ASM_EXTABLE(0b, 0b)
28407 +#endif
28408 +
28409 +RET_ENDP
28410 +BEGIN(sub_unchecked)
28411 + subl %eax, (v)
28412 + sbbl %edx, 4(v)
28413 RET_ENDP
28414 #undef v
28415
28416 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28417 sbbl $0, %edx
28418 addl (v), %eax
28419 adcl 4(v), %edx
28420 +
28421 +#ifdef CONFIG_PAX_REFCOUNT
28422 + into
28423 +1234:
28424 + _ASM_EXTABLE(1234b, 2f)
28425 +#endif
28426 +
28427 + movl %eax, (v)
28428 + movl %edx, 4(v)
28429 +
28430 +#ifdef CONFIG_PAX_REFCOUNT
28431 +2:
28432 +#endif
28433 +
28434 +RET_ENDP
28435 +BEGIN(sub_return_unchecked)
28436 + negl %edx
28437 + negl %eax
28438 + sbbl $0, %edx
28439 + addl (v), %eax
28440 + adcl 4(v), %edx
28441 movl %eax, (v)
28442 movl %edx, 4(v)
28443 RET_ENDP
28444 @@ -105,6 +180,20 @@ RET_ENDP
28445 BEGIN(inc)
28446 addl $1, (v)
28447 adcl $0, 4(v)
28448 +
28449 +#ifdef CONFIG_PAX_REFCOUNT
28450 + jno 0f
28451 + subl $1, (v)
28452 + sbbl $0, 4(v)
28453 + int $4
28454 +0:
28455 + _ASM_EXTABLE(0b, 0b)
28456 +#endif
28457 +
28458 +RET_ENDP
28459 +BEGIN(inc_unchecked)
28460 + addl $1, (v)
28461 + adcl $0, 4(v)
28462 RET_ENDP
28463 #undef v
28464
28465 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28466 movl 4(v), %edx
28467 addl $1, %eax
28468 adcl $0, %edx
28469 +
28470 +#ifdef CONFIG_PAX_REFCOUNT
28471 + into
28472 +1234:
28473 + _ASM_EXTABLE(1234b, 2f)
28474 +#endif
28475 +
28476 + movl %eax, (v)
28477 + movl %edx, 4(v)
28478 +
28479 +#ifdef CONFIG_PAX_REFCOUNT
28480 +2:
28481 +#endif
28482 +
28483 +RET_ENDP
28484 +BEGIN(inc_return_unchecked)
28485 + movl (v), %eax
28486 + movl 4(v), %edx
28487 + addl $1, %eax
28488 + adcl $0, %edx
28489 movl %eax, (v)
28490 movl %edx, 4(v)
28491 RET_ENDP
28492 @@ -123,6 +232,20 @@ RET_ENDP
28493 BEGIN(dec)
28494 subl $1, (v)
28495 sbbl $0, 4(v)
28496 +
28497 +#ifdef CONFIG_PAX_REFCOUNT
28498 + jno 0f
28499 + addl $1, (v)
28500 + adcl $0, 4(v)
28501 + int $4
28502 +0:
28503 + _ASM_EXTABLE(0b, 0b)
28504 +#endif
28505 +
28506 +RET_ENDP
28507 +BEGIN(dec_unchecked)
28508 + subl $1, (v)
28509 + sbbl $0, 4(v)
28510 RET_ENDP
28511 #undef v
28512
28513 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28514 movl 4(v), %edx
28515 subl $1, %eax
28516 sbbl $0, %edx
28517 +
28518 +#ifdef CONFIG_PAX_REFCOUNT
28519 + into
28520 +1234:
28521 + _ASM_EXTABLE(1234b, 2f)
28522 +#endif
28523 +
28524 + movl %eax, (v)
28525 + movl %edx, 4(v)
28526 +
28527 +#ifdef CONFIG_PAX_REFCOUNT
28528 +2:
28529 +#endif
28530 +
28531 +RET_ENDP
28532 +BEGIN(dec_return_unchecked)
28533 + movl (v), %eax
28534 + movl 4(v), %edx
28535 + subl $1, %eax
28536 + sbbl $0, %edx
28537 movl %eax, (v)
28538 movl %edx, 4(v)
28539 RET_ENDP
28540 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28541 adcl %edx, %edi
28542 addl (v), %eax
28543 adcl 4(v), %edx
28544 +
28545 +#ifdef CONFIG_PAX_REFCOUNT
28546 + into
28547 +1234:
28548 + _ASM_EXTABLE(1234b, 2f)
28549 +#endif
28550 +
28551 cmpl %eax, %ecx
28552 je 3f
28553 1:
28554 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28555 1:
28556 addl $1, %eax
28557 adcl $0, %edx
28558 +
28559 +#ifdef CONFIG_PAX_REFCOUNT
28560 + into
28561 +1234:
28562 + _ASM_EXTABLE(1234b, 2f)
28563 +#endif
28564 +
28565 movl %eax, (v)
28566 movl %edx, 4(v)
28567 movl $1, %eax
28568 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28569 movl 4(v), %edx
28570 subl $1, %eax
28571 sbbl $0, %edx
28572 +
28573 +#ifdef CONFIG_PAX_REFCOUNT
28574 + into
28575 +1234:
28576 + _ASM_EXTABLE(1234b, 1f)
28577 +#endif
28578 +
28579 js 1f
28580 movl %eax, (v)
28581 movl %edx, 4(v)
28582 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28583 index f5cc9eb..51fa319 100644
28584 --- a/arch/x86/lib/atomic64_cx8_32.S
28585 +++ b/arch/x86/lib/atomic64_cx8_32.S
28586 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28587 CFI_STARTPROC
28588
28589 read64 %ecx
28590 + pax_force_retaddr
28591 ret
28592 CFI_ENDPROC
28593 ENDPROC(atomic64_read_cx8)
28594
28595 +ENTRY(atomic64_read_unchecked_cx8)
28596 + CFI_STARTPROC
28597 +
28598 + read64 %ecx
28599 + pax_force_retaddr
28600 + ret
28601 + CFI_ENDPROC
28602 +ENDPROC(atomic64_read_unchecked_cx8)
28603 +
28604 ENTRY(atomic64_set_cx8)
28605 CFI_STARTPROC
28606
28607 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28608 cmpxchg8b (%esi)
28609 jne 1b
28610
28611 + pax_force_retaddr
28612 ret
28613 CFI_ENDPROC
28614 ENDPROC(atomic64_set_cx8)
28615
28616 +ENTRY(atomic64_set_unchecked_cx8)
28617 + CFI_STARTPROC
28618 +
28619 +1:
28620 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28621 + * are atomic on 586 and newer */
28622 + cmpxchg8b (%esi)
28623 + jne 1b
28624 +
28625 + pax_force_retaddr
28626 + ret
28627 + CFI_ENDPROC
28628 +ENDPROC(atomic64_set_unchecked_cx8)
28629 +
28630 ENTRY(atomic64_xchg_cx8)
28631 CFI_STARTPROC
28632
28633 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28634 cmpxchg8b (%esi)
28635 jne 1b
28636
28637 + pax_force_retaddr
28638 ret
28639 CFI_ENDPROC
28640 ENDPROC(atomic64_xchg_cx8)
28641
28642 -.macro addsub_return func ins insc
28643 -ENTRY(atomic64_\func\()_return_cx8)
28644 +.macro addsub_return func ins insc unchecked=""
28645 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28646 CFI_STARTPROC
28647 SAVE ebp
28648 SAVE ebx
28649 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28650 movl %edx, %ecx
28651 \ins\()l %esi, %ebx
28652 \insc\()l %edi, %ecx
28653 +
28654 +.ifb \unchecked
28655 +#ifdef CONFIG_PAX_REFCOUNT
28656 + into
28657 +2:
28658 + _ASM_EXTABLE(2b, 3f)
28659 +#endif
28660 +.endif
28661 +
28662 LOCK_PREFIX
28663 cmpxchg8b (%ebp)
28664 jne 1b
28665 -
28666 -10:
28667 movl %ebx, %eax
28668 movl %ecx, %edx
28669 +
28670 +.ifb \unchecked
28671 +#ifdef CONFIG_PAX_REFCOUNT
28672 +3:
28673 +#endif
28674 +.endif
28675 +
28676 RESTORE edi
28677 RESTORE esi
28678 RESTORE ebx
28679 RESTORE ebp
28680 + pax_force_retaddr
28681 ret
28682 CFI_ENDPROC
28683 -ENDPROC(atomic64_\func\()_return_cx8)
28684 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28685 .endm
28686
28687 addsub_return add add adc
28688 addsub_return sub sub sbb
28689 +addsub_return add add adc _unchecked
28690 +addsub_return sub sub sbb _unchecked
28691
28692 -.macro incdec_return func ins insc
28693 -ENTRY(atomic64_\func\()_return_cx8)
28694 +.macro incdec_return func ins insc unchecked=""
28695 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28696 CFI_STARTPROC
28697 SAVE ebx
28698
28699 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28700 movl %edx, %ecx
28701 \ins\()l $1, %ebx
28702 \insc\()l $0, %ecx
28703 +
28704 +.ifb \unchecked
28705 +#ifdef CONFIG_PAX_REFCOUNT
28706 + into
28707 +2:
28708 + _ASM_EXTABLE(2b, 3f)
28709 +#endif
28710 +.endif
28711 +
28712 LOCK_PREFIX
28713 cmpxchg8b (%esi)
28714 jne 1b
28715
28716 -10:
28717 movl %ebx, %eax
28718 movl %ecx, %edx
28719 +
28720 +.ifb \unchecked
28721 +#ifdef CONFIG_PAX_REFCOUNT
28722 +3:
28723 +#endif
28724 +.endif
28725 +
28726 RESTORE ebx
28727 + pax_force_retaddr
28728 ret
28729 CFI_ENDPROC
28730 -ENDPROC(atomic64_\func\()_return_cx8)
28731 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28732 .endm
28733
28734 incdec_return inc add adc
28735 incdec_return dec sub sbb
28736 +incdec_return inc add adc _unchecked
28737 +incdec_return dec sub sbb _unchecked
28738
28739 ENTRY(atomic64_dec_if_positive_cx8)
28740 CFI_STARTPROC
28741 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28742 movl %edx, %ecx
28743 subl $1, %ebx
28744 sbb $0, %ecx
28745 +
28746 +#ifdef CONFIG_PAX_REFCOUNT
28747 + into
28748 +1234:
28749 + _ASM_EXTABLE(1234b, 2f)
28750 +#endif
28751 +
28752 js 2f
28753 LOCK_PREFIX
28754 cmpxchg8b (%esi)
28755 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28756 movl %ebx, %eax
28757 movl %ecx, %edx
28758 RESTORE ebx
28759 + pax_force_retaddr
28760 ret
28761 CFI_ENDPROC
28762 ENDPROC(atomic64_dec_if_positive_cx8)
28763 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28764 movl %edx, %ecx
28765 addl %ebp, %ebx
28766 adcl %edi, %ecx
28767 +
28768 +#ifdef CONFIG_PAX_REFCOUNT
28769 + into
28770 +1234:
28771 + _ASM_EXTABLE(1234b, 3f)
28772 +#endif
28773 +
28774 LOCK_PREFIX
28775 cmpxchg8b (%esi)
28776 jne 1b
28777 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28778 CFI_ADJUST_CFA_OFFSET -8
28779 RESTORE ebx
28780 RESTORE ebp
28781 + pax_force_retaddr
28782 ret
28783 4:
28784 cmpl %edx, 4(%esp)
28785 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28786 xorl %ecx, %ecx
28787 addl $1, %ebx
28788 adcl %edx, %ecx
28789 +
28790 +#ifdef CONFIG_PAX_REFCOUNT
28791 + into
28792 +1234:
28793 + _ASM_EXTABLE(1234b, 3f)
28794 +#endif
28795 +
28796 LOCK_PREFIX
28797 cmpxchg8b (%esi)
28798 jne 1b
28799 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28800 movl $1, %eax
28801 3:
28802 RESTORE ebx
28803 + pax_force_retaddr
28804 ret
28805 CFI_ENDPROC
28806 ENDPROC(atomic64_inc_not_zero_cx8)
28807 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28808 index e78b8ee..7e173a8 100644
28809 --- a/arch/x86/lib/checksum_32.S
28810 +++ b/arch/x86/lib/checksum_32.S
28811 @@ -29,7 +29,8 @@
28812 #include <asm/dwarf2.h>
28813 #include <asm/errno.h>
28814 #include <asm/asm.h>
28815 -
28816 +#include <asm/segment.h>
28817 +
28818 /*
28819 * computes a partial checksum, e.g. for TCP/UDP fragments
28820 */
28821 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28822
28823 #define ARGBASE 16
28824 #define FP 12
28825 -
28826 -ENTRY(csum_partial_copy_generic)
28827 +
28828 +ENTRY(csum_partial_copy_generic_to_user)
28829 CFI_STARTPROC
28830 +
28831 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28832 + pushl_cfi %gs
28833 + popl_cfi %es
28834 + jmp csum_partial_copy_generic
28835 +#endif
28836 +
28837 +ENTRY(csum_partial_copy_generic_from_user)
28838 +
28839 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28840 + pushl_cfi %gs
28841 + popl_cfi %ds
28842 +#endif
28843 +
28844 +ENTRY(csum_partial_copy_generic)
28845 subl $4,%esp
28846 CFI_ADJUST_CFA_OFFSET 4
28847 pushl_cfi %edi
28848 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28849 jmp 4f
28850 SRC(1: movw (%esi), %bx )
28851 addl $2, %esi
28852 -DST( movw %bx, (%edi) )
28853 +DST( movw %bx, %es:(%edi) )
28854 addl $2, %edi
28855 addw %bx, %ax
28856 adcl $0, %eax
28857 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28858 SRC(1: movl (%esi), %ebx )
28859 SRC( movl 4(%esi), %edx )
28860 adcl %ebx, %eax
28861 -DST( movl %ebx, (%edi) )
28862 +DST( movl %ebx, %es:(%edi) )
28863 adcl %edx, %eax
28864 -DST( movl %edx, 4(%edi) )
28865 +DST( movl %edx, %es:4(%edi) )
28866
28867 SRC( movl 8(%esi), %ebx )
28868 SRC( movl 12(%esi), %edx )
28869 adcl %ebx, %eax
28870 -DST( movl %ebx, 8(%edi) )
28871 +DST( movl %ebx, %es:8(%edi) )
28872 adcl %edx, %eax
28873 -DST( movl %edx, 12(%edi) )
28874 +DST( movl %edx, %es:12(%edi) )
28875
28876 SRC( movl 16(%esi), %ebx )
28877 SRC( movl 20(%esi), %edx )
28878 adcl %ebx, %eax
28879 -DST( movl %ebx, 16(%edi) )
28880 +DST( movl %ebx, %es:16(%edi) )
28881 adcl %edx, %eax
28882 -DST( movl %edx, 20(%edi) )
28883 +DST( movl %edx, %es:20(%edi) )
28884
28885 SRC( movl 24(%esi), %ebx )
28886 SRC( movl 28(%esi), %edx )
28887 adcl %ebx, %eax
28888 -DST( movl %ebx, 24(%edi) )
28889 +DST( movl %ebx, %es:24(%edi) )
28890 adcl %edx, %eax
28891 -DST( movl %edx, 28(%edi) )
28892 +DST( movl %edx, %es:28(%edi) )
28893
28894 lea 32(%esi), %esi
28895 lea 32(%edi), %edi
28896 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28897 shrl $2, %edx # This clears CF
28898 SRC(3: movl (%esi), %ebx )
28899 adcl %ebx, %eax
28900 -DST( movl %ebx, (%edi) )
28901 +DST( movl %ebx, %es:(%edi) )
28902 lea 4(%esi), %esi
28903 lea 4(%edi), %edi
28904 dec %edx
28905 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28906 jb 5f
28907 SRC( movw (%esi), %cx )
28908 leal 2(%esi), %esi
28909 -DST( movw %cx, (%edi) )
28910 +DST( movw %cx, %es:(%edi) )
28911 leal 2(%edi), %edi
28912 je 6f
28913 shll $16,%ecx
28914 SRC(5: movb (%esi), %cl )
28915 -DST( movb %cl, (%edi) )
28916 +DST( movb %cl, %es:(%edi) )
28917 6: addl %ecx, %eax
28918 adcl $0, %eax
28919 7:
28920 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28921
28922 6001:
28923 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28924 - movl $-EFAULT, (%ebx)
28925 + movl $-EFAULT, %ss:(%ebx)
28926
28927 # zero the complete destination - computing the rest
28928 # is too much work
28929 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28930
28931 6002:
28932 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28933 - movl $-EFAULT,(%ebx)
28934 + movl $-EFAULT,%ss:(%ebx)
28935 jmp 5000b
28936
28937 .previous
28938
28939 + pushl_cfi %ss
28940 + popl_cfi %ds
28941 + pushl_cfi %ss
28942 + popl_cfi %es
28943 popl_cfi %ebx
28944 CFI_RESTORE ebx
28945 popl_cfi %esi
28946 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28947 popl_cfi %ecx # equivalent to addl $4,%esp
28948 ret
28949 CFI_ENDPROC
28950 -ENDPROC(csum_partial_copy_generic)
28951 +ENDPROC(csum_partial_copy_generic_to_user)
28952
28953 #else
28954
28955 /* Version for PentiumII/PPro */
28956
28957 #define ROUND1(x) \
28958 + nop; nop; nop; \
28959 SRC(movl x(%esi), %ebx ) ; \
28960 addl %ebx, %eax ; \
28961 - DST(movl %ebx, x(%edi) ) ;
28962 + DST(movl %ebx, %es:x(%edi)) ;
28963
28964 #define ROUND(x) \
28965 + nop; nop; nop; \
28966 SRC(movl x(%esi), %ebx ) ; \
28967 adcl %ebx, %eax ; \
28968 - DST(movl %ebx, x(%edi) ) ;
28969 + DST(movl %ebx, %es:x(%edi)) ;
28970
28971 #define ARGBASE 12
28972 -
28973 -ENTRY(csum_partial_copy_generic)
28974 +
28975 +ENTRY(csum_partial_copy_generic_to_user)
28976 CFI_STARTPROC
28977 +
28978 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28979 + pushl_cfi %gs
28980 + popl_cfi %es
28981 + jmp csum_partial_copy_generic
28982 +#endif
28983 +
28984 +ENTRY(csum_partial_copy_generic_from_user)
28985 +
28986 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28987 + pushl_cfi %gs
28988 + popl_cfi %ds
28989 +#endif
28990 +
28991 +ENTRY(csum_partial_copy_generic)
28992 pushl_cfi %ebx
28993 CFI_REL_OFFSET ebx, 0
28994 pushl_cfi %edi
28995 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28996 subl %ebx, %edi
28997 lea -1(%esi),%edx
28998 andl $-32,%edx
28999 - lea 3f(%ebx,%ebx), %ebx
29000 + lea 3f(%ebx,%ebx,2), %ebx
29001 testl %esi, %esi
29002 jmp *%ebx
29003 1: addl $64,%esi
29004 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29005 jb 5f
29006 SRC( movw (%esi), %dx )
29007 leal 2(%esi), %esi
29008 -DST( movw %dx, (%edi) )
29009 +DST( movw %dx, %es:(%edi) )
29010 leal 2(%edi), %edi
29011 je 6f
29012 shll $16,%edx
29013 5:
29014 SRC( movb (%esi), %dl )
29015 -DST( movb %dl, (%edi) )
29016 +DST( movb %dl, %es:(%edi) )
29017 6: addl %edx, %eax
29018 adcl $0, %eax
29019 7:
29020 .section .fixup, "ax"
29021 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29022 - movl $-EFAULT, (%ebx)
29023 + movl $-EFAULT, %ss:(%ebx)
29024 # zero the complete destination (computing the rest is too much work)
29025 movl ARGBASE+8(%esp),%edi # dst
29026 movl ARGBASE+12(%esp),%ecx # len
29027 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29028 rep; stosb
29029 jmp 7b
29030 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29031 - movl $-EFAULT, (%ebx)
29032 + movl $-EFAULT, %ss:(%ebx)
29033 jmp 7b
29034 .previous
29035
29036 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29037 + pushl_cfi %ss
29038 + popl_cfi %ds
29039 + pushl_cfi %ss
29040 + popl_cfi %es
29041 +#endif
29042 +
29043 popl_cfi %esi
29044 CFI_RESTORE esi
29045 popl_cfi %edi
29046 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29047 CFI_RESTORE ebx
29048 ret
29049 CFI_ENDPROC
29050 -ENDPROC(csum_partial_copy_generic)
29051 +ENDPROC(csum_partial_copy_generic_to_user)
29052
29053 #undef ROUND
29054 #undef ROUND1
29055 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29056 index f2145cf..cea889d 100644
29057 --- a/arch/x86/lib/clear_page_64.S
29058 +++ b/arch/x86/lib/clear_page_64.S
29059 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29060 movl $4096/8,%ecx
29061 xorl %eax,%eax
29062 rep stosq
29063 + pax_force_retaddr
29064 ret
29065 CFI_ENDPROC
29066 ENDPROC(clear_page_c)
29067 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29068 movl $4096,%ecx
29069 xorl %eax,%eax
29070 rep stosb
29071 + pax_force_retaddr
29072 ret
29073 CFI_ENDPROC
29074 ENDPROC(clear_page_c_e)
29075 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29076 leaq 64(%rdi),%rdi
29077 jnz .Lloop
29078 nop
29079 + pax_force_retaddr
29080 ret
29081 CFI_ENDPROC
29082 .Lclear_page_end:
29083 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29084
29085 #include <asm/cpufeature.h>
29086
29087 - .section .altinstr_replacement,"ax"
29088 + .section .altinstr_replacement,"a"
29089 1: .byte 0xeb /* jmp <disp8> */
29090 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29091 2: .byte 0xeb /* jmp <disp8> */
29092 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29093 index 1e572c5..2a162cd 100644
29094 --- a/arch/x86/lib/cmpxchg16b_emu.S
29095 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29096 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29097
29098 popf
29099 mov $1, %al
29100 + pax_force_retaddr
29101 ret
29102
29103 not_same:
29104 popf
29105 xor %al,%al
29106 + pax_force_retaddr
29107 ret
29108
29109 CFI_ENDPROC
29110 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29111 index 176cca6..e0d658e 100644
29112 --- a/arch/x86/lib/copy_page_64.S
29113 +++ b/arch/x86/lib/copy_page_64.S
29114 @@ -9,6 +9,7 @@ copy_page_rep:
29115 CFI_STARTPROC
29116 movl $4096/8, %ecx
29117 rep movsq
29118 + pax_force_retaddr
29119 ret
29120 CFI_ENDPROC
29121 ENDPROC(copy_page_rep)
29122 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29123 CFI_ADJUST_CFA_OFFSET 2*8
29124 movq %rbx, (%rsp)
29125 CFI_REL_OFFSET rbx, 0
29126 - movq %r12, 1*8(%rsp)
29127 - CFI_REL_OFFSET r12, 1*8
29128 + movq %r13, 1*8(%rsp)
29129 + CFI_REL_OFFSET r13, 1*8
29130
29131 movl $(4096/64)-5, %ecx
29132 .p2align 4
29133 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29134 movq 0x8*4(%rsi), %r9
29135 movq 0x8*5(%rsi), %r10
29136 movq 0x8*6(%rsi), %r11
29137 - movq 0x8*7(%rsi), %r12
29138 + movq 0x8*7(%rsi), %r13
29139
29140 prefetcht0 5*64(%rsi)
29141
29142 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29143 movq %r9, 0x8*4(%rdi)
29144 movq %r10, 0x8*5(%rdi)
29145 movq %r11, 0x8*6(%rdi)
29146 - movq %r12, 0x8*7(%rdi)
29147 + movq %r13, 0x8*7(%rdi)
29148
29149 leaq 64 (%rsi), %rsi
29150 leaq 64 (%rdi), %rdi
29151 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29152 movq 0x8*4(%rsi), %r9
29153 movq 0x8*5(%rsi), %r10
29154 movq 0x8*6(%rsi), %r11
29155 - movq 0x8*7(%rsi), %r12
29156 + movq 0x8*7(%rsi), %r13
29157
29158 movq %rax, 0x8*0(%rdi)
29159 movq %rbx, 0x8*1(%rdi)
29160 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29161 movq %r9, 0x8*4(%rdi)
29162 movq %r10, 0x8*5(%rdi)
29163 movq %r11, 0x8*6(%rdi)
29164 - movq %r12, 0x8*7(%rdi)
29165 + movq %r13, 0x8*7(%rdi)
29166
29167 leaq 64(%rdi), %rdi
29168 leaq 64(%rsi), %rsi
29169 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29170
29171 movq (%rsp), %rbx
29172 CFI_RESTORE rbx
29173 - movq 1*8(%rsp), %r12
29174 - CFI_RESTORE r12
29175 + movq 1*8(%rsp), %r13
29176 + CFI_RESTORE r13
29177 addq $2*8, %rsp
29178 CFI_ADJUST_CFA_OFFSET -2*8
29179 + pax_force_retaddr
29180 ret
29181 .Lcopy_page_end:
29182 CFI_ENDPROC
29183 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29184
29185 #include <asm/cpufeature.h>
29186
29187 - .section .altinstr_replacement,"ax"
29188 + .section .altinstr_replacement,"a"
29189 1: .byte 0xeb /* jmp <disp8> */
29190 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29191 2:
29192 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29193 index a30ca15..407412b 100644
29194 --- a/arch/x86/lib/copy_user_64.S
29195 +++ b/arch/x86/lib/copy_user_64.S
29196 @@ -18,31 +18,7 @@
29197 #include <asm/alternative-asm.h>
29198 #include <asm/asm.h>
29199 #include <asm/smap.h>
29200 -
29201 -/*
29202 - * By placing feature2 after feature1 in altinstructions section, we logically
29203 - * implement:
29204 - * If CPU has feature2, jmp to alt2 is used
29205 - * else if CPU has feature1, jmp to alt1 is used
29206 - * else jmp to orig is used.
29207 - */
29208 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29209 -0:
29210 - .byte 0xe9 /* 32bit jump */
29211 - .long \orig-1f /* by default jump to orig */
29212 -1:
29213 - .section .altinstr_replacement,"ax"
29214 -2: .byte 0xe9 /* near jump with 32bit immediate */
29215 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29216 -3: .byte 0xe9 /* near jump with 32bit immediate */
29217 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29218 - .previous
29219 -
29220 - .section .altinstructions,"a"
29221 - altinstruction_entry 0b,2b,\feature1,5,5
29222 - altinstruction_entry 0b,3b,\feature2,5,5
29223 - .previous
29224 - .endm
29225 +#include <asm/pgtable.h>
29226
29227 .macro ALIGN_DESTINATION
29228 #ifdef FIX_ALIGNMENT
29229 @@ -70,52 +46,6 @@
29230 #endif
29231 .endm
29232
29233 -/* Standard copy_to_user with segment limit checking */
29234 -ENTRY(_copy_to_user)
29235 - CFI_STARTPROC
29236 - GET_THREAD_INFO(%rax)
29237 - movq %rdi,%rcx
29238 - addq %rdx,%rcx
29239 - jc bad_to_user
29240 - cmpq TI_addr_limit(%rax),%rcx
29241 - ja bad_to_user
29242 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29243 - copy_user_generic_unrolled,copy_user_generic_string, \
29244 - copy_user_enhanced_fast_string
29245 - CFI_ENDPROC
29246 -ENDPROC(_copy_to_user)
29247 -
29248 -/* Standard copy_from_user with segment limit checking */
29249 -ENTRY(_copy_from_user)
29250 - CFI_STARTPROC
29251 - GET_THREAD_INFO(%rax)
29252 - movq %rsi,%rcx
29253 - addq %rdx,%rcx
29254 - jc bad_from_user
29255 - cmpq TI_addr_limit(%rax),%rcx
29256 - ja bad_from_user
29257 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29258 - copy_user_generic_unrolled,copy_user_generic_string, \
29259 - copy_user_enhanced_fast_string
29260 - CFI_ENDPROC
29261 -ENDPROC(_copy_from_user)
29262 -
29263 - .section .fixup,"ax"
29264 - /* must zero dest */
29265 -ENTRY(bad_from_user)
29266 -bad_from_user:
29267 - CFI_STARTPROC
29268 - movl %edx,%ecx
29269 - xorl %eax,%eax
29270 - rep
29271 - stosb
29272 -bad_to_user:
29273 - movl %edx,%eax
29274 - ret
29275 - CFI_ENDPROC
29276 -ENDPROC(bad_from_user)
29277 - .previous
29278 -
29279 /*
29280 * copy_user_generic_unrolled - memory copy with exception handling.
29281 * This version is for CPUs like P4 that don't have efficient micro
29282 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29283 */
29284 ENTRY(copy_user_generic_unrolled)
29285 CFI_STARTPROC
29286 + ASM_PAX_OPEN_USERLAND
29287 ASM_STAC
29288 cmpl $8,%edx
29289 jb 20f /* less then 8 bytes, go to byte copy loop */
29290 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29291 jnz 21b
29292 23: xor %eax,%eax
29293 ASM_CLAC
29294 + ASM_PAX_CLOSE_USERLAND
29295 + pax_force_retaddr
29296 ret
29297
29298 .section .fixup,"ax"
29299 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29300 */
29301 ENTRY(copy_user_generic_string)
29302 CFI_STARTPROC
29303 + ASM_PAX_OPEN_USERLAND
29304 ASM_STAC
29305 andl %edx,%edx
29306 jz 4f
29307 @@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
29308 movsb
29309 4: xorl %eax,%eax
29310 ASM_CLAC
29311 + ASM_PAX_CLOSE_USERLAND
29312 + pax_force_retaddr
29313 ret
29314
29315 .section .fixup,"ax"
29316 @@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
29317 */
29318 ENTRY(copy_user_enhanced_fast_string)
29319 CFI_STARTPROC
29320 + ASM_PAX_OPEN_USERLAND
29321 ASM_STAC
29322 andl %edx,%edx
29323 jz 2f
29324 @@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
29325 movsb
29326 2: xorl %eax,%eax
29327 ASM_CLAC
29328 + ASM_PAX_CLOSE_USERLAND
29329 + pax_force_retaddr
29330 ret
29331
29332 .section .fixup,"ax"
29333 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29334 index 6a4f43c..c70fb52 100644
29335 --- a/arch/x86/lib/copy_user_nocache_64.S
29336 +++ b/arch/x86/lib/copy_user_nocache_64.S
29337 @@ -8,6 +8,7 @@
29338
29339 #include <linux/linkage.h>
29340 #include <asm/dwarf2.h>
29341 +#include <asm/alternative-asm.h>
29342
29343 #define FIX_ALIGNMENT 1
29344
29345 @@ -16,6 +17,7 @@
29346 #include <asm/thread_info.h>
29347 #include <asm/asm.h>
29348 #include <asm/smap.h>
29349 +#include <asm/pgtable.h>
29350
29351 .macro ALIGN_DESTINATION
29352 #ifdef FIX_ALIGNMENT
29353 @@ -49,6 +51,16 @@
29354 */
29355 ENTRY(__copy_user_nocache)
29356 CFI_STARTPROC
29357 +
29358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29359 + mov pax_user_shadow_base,%rcx
29360 + cmp %rcx,%rsi
29361 + jae 1f
29362 + add %rcx,%rsi
29363 +1:
29364 +#endif
29365 +
29366 + ASM_PAX_OPEN_USERLAND
29367 ASM_STAC
29368 cmpl $8,%edx
29369 jb 20f /* less then 8 bytes, go to byte copy loop */
29370 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29371 jnz 21b
29372 23: xorl %eax,%eax
29373 ASM_CLAC
29374 + ASM_PAX_CLOSE_USERLAND
29375 sfence
29376 + pax_force_retaddr
29377 ret
29378
29379 .section .fixup,"ax"
29380 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29381 index 2419d5f..fe52d0e 100644
29382 --- a/arch/x86/lib/csum-copy_64.S
29383 +++ b/arch/x86/lib/csum-copy_64.S
29384 @@ -9,6 +9,7 @@
29385 #include <asm/dwarf2.h>
29386 #include <asm/errno.h>
29387 #include <asm/asm.h>
29388 +#include <asm/alternative-asm.h>
29389
29390 /*
29391 * Checksum copy with exception handling.
29392 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29393 CFI_ADJUST_CFA_OFFSET 7*8
29394 movq %rbx, 2*8(%rsp)
29395 CFI_REL_OFFSET rbx, 2*8
29396 - movq %r12, 3*8(%rsp)
29397 - CFI_REL_OFFSET r12, 3*8
29398 + movq %r15, 3*8(%rsp)
29399 + CFI_REL_OFFSET r15, 3*8
29400 movq %r14, 4*8(%rsp)
29401 CFI_REL_OFFSET r14, 4*8
29402 movq %r13, 5*8(%rsp)
29403 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29404 movl %edx, %ecx
29405
29406 xorl %r9d, %r9d
29407 - movq %rcx, %r12
29408 + movq %rcx, %r15
29409
29410 - shrq $6, %r12
29411 + shrq $6, %r15
29412 jz .Lhandle_tail /* < 64 */
29413
29414 clc
29415
29416 /* main loop. clear in 64 byte blocks */
29417 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29418 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29419 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29420 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29421 .p2align 4
29422 .Lloop:
29423 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29424 adcq %r14, %rax
29425 adcq %r13, %rax
29426
29427 - decl %r12d
29428 + decl %r15d
29429
29430 dest
29431 movq %rbx, (%rsi)
29432 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29433 .Lende:
29434 movq 2*8(%rsp), %rbx
29435 CFI_RESTORE rbx
29436 - movq 3*8(%rsp), %r12
29437 - CFI_RESTORE r12
29438 + movq 3*8(%rsp), %r15
29439 + CFI_RESTORE r15
29440 movq 4*8(%rsp), %r14
29441 CFI_RESTORE r14
29442 movq 5*8(%rsp), %r13
29443 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29444 CFI_RESTORE rbp
29445 addq $7*8, %rsp
29446 CFI_ADJUST_CFA_OFFSET -7*8
29447 + pax_force_retaddr
29448 ret
29449 CFI_RESTORE_STATE
29450
29451 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29452 index 7609e0e..b449b98 100644
29453 --- a/arch/x86/lib/csum-wrappers_64.c
29454 +++ b/arch/x86/lib/csum-wrappers_64.c
29455 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29456 len -= 2;
29457 }
29458 }
29459 + pax_open_userland();
29460 stac();
29461 - isum = csum_partial_copy_generic((__force const void *)src,
29462 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29463 dst, len, isum, errp, NULL);
29464 clac();
29465 + pax_close_userland();
29466 if (unlikely(*errp))
29467 goto out_err;
29468
29469 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29470 }
29471
29472 *errp = 0;
29473 + pax_open_userland();
29474 stac();
29475 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29476 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29477 len, isum, NULL, errp);
29478 clac();
29479 + pax_close_userland();
29480 return ret;
29481 }
29482 EXPORT_SYMBOL(csum_partial_copy_to_user);
29483 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29484 index a451235..1daa956 100644
29485 --- a/arch/x86/lib/getuser.S
29486 +++ b/arch/x86/lib/getuser.S
29487 @@ -33,17 +33,40 @@
29488 #include <asm/thread_info.h>
29489 #include <asm/asm.h>
29490 #include <asm/smap.h>
29491 +#include <asm/segment.h>
29492 +#include <asm/pgtable.h>
29493 +#include <asm/alternative-asm.h>
29494 +
29495 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29496 +#define __copyuser_seg gs;
29497 +#else
29498 +#define __copyuser_seg
29499 +#endif
29500
29501 .text
29502 ENTRY(__get_user_1)
29503 CFI_STARTPROC
29504 +
29505 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29506 GET_THREAD_INFO(%_ASM_DX)
29507 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29508 jae bad_get_user
29509 ASM_STAC
29510 -1: movzbl (%_ASM_AX),%edx
29511 +
29512 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29513 + mov pax_user_shadow_base,%_ASM_DX
29514 + cmp %_ASM_DX,%_ASM_AX
29515 + jae 1234f
29516 + add %_ASM_DX,%_ASM_AX
29517 +1234:
29518 +#endif
29519 +
29520 +#endif
29521 +
29522 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29523 xor %eax,%eax
29524 ASM_CLAC
29525 + pax_force_retaddr
29526 ret
29527 CFI_ENDPROC
29528 ENDPROC(__get_user_1)
29529 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29530 ENTRY(__get_user_2)
29531 CFI_STARTPROC
29532 add $1,%_ASM_AX
29533 +
29534 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29535 jc bad_get_user
29536 GET_THREAD_INFO(%_ASM_DX)
29537 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29538 jae bad_get_user
29539 ASM_STAC
29540 -2: movzwl -1(%_ASM_AX),%edx
29541 +
29542 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29543 + mov pax_user_shadow_base,%_ASM_DX
29544 + cmp %_ASM_DX,%_ASM_AX
29545 + jae 1234f
29546 + add %_ASM_DX,%_ASM_AX
29547 +1234:
29548 +#endif
29549 +
29550 +#endif
29551 +
29552 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29553 xor %eax,%eax
29554 ASM_CLAC
29555 + pax_force_retaddr
29556 ret
29557 CFI_ENDPROC
29558 ENDPROC(__get_user_2)
29559 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29560 ENTRY(__get_user_4)
29561 CFI_STARTPROC
29562 add $3,%_ASM_AX
29563 +
29564 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29565 jc bad_get_user
29566 GET_THREAD_INFO(%_ASM_DX)
29567 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29568 jae bad_get_user
29569 ASM_STAC
29570 -3: movl -3(%_ASM_AX),%edx
29571 +
29572 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29573 + mov pax_user_shadow_base,%_ASM_DX
29574 + cmp %_ASM_DX,%_ASM_AX
29575 + jae 1234f
29576 + add %_ASM_DX,%_ASM_AX
29577 +1234:
29578 +#endif
29579 +
29580 +#endif
29581 +
29582 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29583 xor %eax,%eax
29584 ASM_CLAC
29585 + pax_force_retaddr
29586 ret
29587 CFI_ENDPROC
29588 ENDPROC(__get_user_4)
29589 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29590 GET_THREAD_INFO(%_ASM_DX)
29591 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29592 jae bad_get_user
29593 +
29594 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29595 + mov pax_user_shadow_base,%_ASM_DX
29596 + cmp %_ASM_DX,%_ASM_AX
29597 + jae 1234f
29598 + add %_ASM_DX,%_ASM_AX
29599 +1234:
29600 +#endif
29601 +
29602 ASM_STAC
29603 4: movq -7(%_ASM_AX),%rdx
29604 xor %eax,%eax
29605 ASM_CLAC
29606 + pax_force_retaddr
29607 ret
29608 #else
29609 add $7,%_ASM_AX
29610 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29611 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29612 jae bad_get_user_8
29613 ASM_STAC
29614 -4: movl -7(%_ASM_AX),%edx
29615 -5: movl -3(%_ASM_AX),%ecx
29616 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29617 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29618 xor %eax,%eax
29619 ASM_CLAC
29620 + pax_force_retaddr
29621 ret
29622 #endif
29623 CFI_ENDPROC
29624 @@ -113,6 +175,7 @@ bad_get_user:
29625 xor %edx,%edx
29626 mov $(-EFAULT),%_ASM_AX
29627 ASM_CLAC
29628 + pax_force_retaddr
29629 ret
29630 CFI_ENDPROC
29631 END(bad_get_user)
29632 @@ -124,6 +187,7 @@ bad_get_user_8:
29633 xor %ecx,%ecx
29634 mov $(-EFAULT),%_ASM_AX
29635 ASM_CLAC
29636 + pax_force_retaddr
29637 ret
29638 CFI_ENDPROC
29639 END(bad_get_user_8)
29640 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29641 index 54fcffe..7be149e 100644
29642 --- a/arch/x86/lib/insn.c
29643 +++ b/arch/x86/lib/insn.c
29644 @@ -20,8 +20,10 @@
29645
29646 #ifdef __KERNEL__
29647 #include <linux/string.h>
29648 +#include <asm/pgtable_types.h>
29649 #else
29650 #include <string.h>
29651 +#define ktla_ktva(addr) addr
29652 #endif
29653 #include <asm/inat.h>
29654 #include <asm/insn.h>
29655 @@ -53,8 +55,8 @@
29656 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29657 {
29658 memset(insn, 0, sizeof(*insn));
29659 - insn->kaddr = kaddr;
29660 - insn->next_byte = kaddr;
29661 + insn->kaddr = ktla_ktva(kaddr);
29662 + insn->next_byte = ktla_ktva(kaddr);
29663 insn->x86_64 = x86_64 ? 1 : 0;
29664 insn->opnd_bytes = 4;
29665 if (x86_64)
29666 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29667 index 05a95e7..326f2fa 100644
29668 --- a/arch/x86/lib/iomap_copy_64.S
29669 +++ b/arch/x86/lib/iomap_copy_64.S
29670 @@ -17,6 +17,7 @@
29671
29672 #include <linux/linkage.h>
29673 #include <asm/dwarf2.h>
29674 +#include <asm/alternative-asm.h>
29675
29676 /*
29677 * override generic version in lib/iomap_copy.c
29678 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29679 CFI_STARTPROC
29680 movl %edx,%ecx
29681 rep movsd
29682 + pax_force_retaddr
29683 ret
29684 CFI_ENDPROC
29685 ENDPROC(__iowrite32_copy)
29686 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29687 index 56313a3..0db417e 100644
29688 --- a/arch/x86/lib/memcpy_64.S
29689 +++ b/arch/x86/lib/memcpy_64.S
29690 @@ -24,7 +24,7 @@
29691 * This gets patched over the unrolled variant (below) via the
29692 * alternative instructions framework:
29693 */
29694 - .section .altinstr_replacement, "ax", @progbits
29695 + .section .altinstr_replacement, "a", @progbits
29696 .Lmemcpy_c:
29697 movq %rdi, %rax
29698 movq %rdx, %rcx
29699 @@ -33,6 +33,7 @@
29700 rep movsq
29701 movl %edx, %ecx
29702 rep movsb
29703 + pax_force_retaddr
29704 ret
29705 .Lmemcpy_e:
29706 .previous
29707 @@ -44,11 +45,12 @@
29708 * This gets patched over the unrolled variant (below) via the
29709 * alternative instructions framework:
29710 */
29711 - .section .altinstr_replacement, "ax", @progbits
29712 + .section .altinstr_replacement, "a", @progbits
29713 .Lmemcpy_c_e:
29714 movq %rdi, %rax
29715 movq %rdx, %rcx
29716 rep movsb
29717 + pax_force_retaddr
29718 ret
29719 .Lmemcpy_e_e:
29720 .previous
29721 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29722 movq %r9, 1*8(%rdi)
29723 movq %r10, -2*8(%rdi, %rdx)
29724 movq %r11, -1*8(%rdi, %rdx)
29725 + pax_force_retaddr
29726 retq
29727 .p2align 4
29728 .Lless_16bytes:
29729 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29730 movq -1*8(%rsi, %rdx), %r9
29731 movq %r8, 0*8(%rdi)
29732 movq %r9, -1*8(%rdi, %rdx)
29733 + pax_force_retaddr
29734 retq
29735 .p2align 4
29736 .Lless_8bytes:
29737 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29738 movl -4(%rsi, %rdx), %r8d
29739 movl %ecx, (%rdi)
29740 movl %r8d, -4(%rdi, %rdx)
29741 + pax_force_retaddr
29742 retq
29743 .p2align 4
29744 .Lless_3bytes:
29745 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29746 movb %cl, (%rdi)
29747
29748 .Lend:
29749 + pax_force_retaddr
29750 retq
29751 CFI_ENDPROC
29752 ENDPROC(memcpy)
29753 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29754 index 65268a6..dd1de11 100644
29755 --- a/arch/x86/lib/memmove_64.S
29756 +++ b/arch/x86/lib/memmove_64.S
29757 @@ -202,14 +202,16 @@ ENTRY(memmove)
29758 movb (%rsi), %r11b
29759 movb %r11b, (%rdi)
29760 13:
29761 + pax_force_retaddr
29762 retq
29763 CFI_ENDPROC
29764
29765 - .section .altinstr_replacement,"ax"
29766 + .section .altinstr_replacement,"a"
29767 .Lmemmove_begin_forward_efs:
29768 /* Forward moving data. */
29769 movq %rdx, %rcx
29770 rep movsb
29771 + pax_force_retaddr
29772 retq
29773 .Lmemmove_end_forward_efs:
29774 .previous
29775 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29776 index 2dcb380..2eb79fe 100644
29777 --- a/arch/x86/lib/memset_64.S
29778 +++ b/arch/x86/lib/memset_64.S
29779 @@ -16,7 +16,7 @@
29780 *
29781 * rax original destination
29782 */
29783 - .section .altinstr_replacement, "ax", @progbits
29784 + .section .altinstr_replacement, "a", @progbits
29785 .Lmemset_c:
29786 movq %rdi,%r9
29787 movq %rdx,%rcx
29788 @@ -30,6 +30,7 @@
29789 movl %edx,%ecx
29790 rep stosb
29791 movq %r9,%rax
29792 + pax_force_retaddr
29793 ret
29794 .Lmemset_e:
29795 .previous
29796 @@ -45,13 +46,14 @@
29797 *
29798 * rax original destination
29799 */
29800 - .section .altinstr_replacement, "ax", @progbits
29801 + .section .altinstr_replacement, "a", @progbits
29802 .Lmemset_c_e:
29803 movq %rdi,%r9
29804 movb %sil,%al
29805 movq %rdx,%rcx
29806 rep stosb
29807 movq %r9,%rax
29808 + pax_force_retaddr
29809 ret
29810 .Lmemset_e_e:
29811 .previous
29812 @@ -118,6 +120,7 @@ ENTRY(__memset)
29813
29814 .Lende:
29815 movq %r10,%rax
29816 + pax_force_retaddr
29817 ret
29818
29819 CFI_RESTORE_STATE
29820 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29821 index c9f2d9b..e7fd2c0 100644
29822 --- a/arch/x86/lib/mmx_32.c
29823 +++ b/arch/x86/lib/mmx_32.c
29824 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29825 {
29826 void *p;
29827 int i;
29828 + unsigned long cr0;
29829
29830 if (unlikely(in_interrupt()))
29831 return __memcpy(to, from, len);
29832 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29833 kernel_fpu_begin();
29834
29835 __asm__ __volatile__ (
29836 - "1: prefetch (%0)\n" /* This set is 28 bytes */
29837 - " prefetch 64(%0)\n"
29838 - " prefetch 128(%0)\n"
29839 - " prefetch 192(%0)\n"
29840 - " prefetch 256(%0)\n"
29841 + "1: prefetch (%1)\n" /* This set is 28 bytes */
29842 + " prefetch 64(%1)\n"
29843 + " prefetch 128(%1)\n"
29844 + " prefetch 192(%1)\n"
29845 + " prefetch 256(%1)\n"
29846 "2: \n"
29847 ".section .fixup, \"ax\"\n"
29848 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29849 + "3: \n"
29850 +
29851 +#ifdef CONFIG_PAX_KERNEXEC
29852 + " movl %%cr0, %0\n"
29853 + " movl %0, %%eax\n"
29854 + " andl $0xFFFEFFFF, %%eax\n"
29855 + " movl %%eax, %%cr0\n"
29856 +#endif
29857 +
29858 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29859 +
29860 +#ifdef CONFIG_PAX_KERNEXEC
29861 + " movl %0, %%cr0\n"
29862 +#endif
29863 +
29864 " jmp 2b\n"
29865 ".previous\n"
29866 _ASM_EXTABLE(1b, 3b)
29867 - : : "r" (from));
29868 + : "=&r" (cr0) : "r" (from) : "ax");
29869
29870 for ( ; i > 5; i--) {
29871 __asm__ __volatile__ (
29872 - "1: prefetch 320(%0)\n"
29873 - "2: movq (%0), %%mm0\n"
29874 - " movq 8(%0), %%mm1\n"
29875 - " movq 16(%0), %%mm2\n"
29876 - " movq 24(%0), %%mm3\n"
29877 - " movq %%mm0, (%1)\n"
29878 - " movq %%mm1, 8(%1)\n"
29879 - " movq %%mm2, 16(%1)\n"
29880 - " movq %%mm3, 24(%1)\n"
29881 - " movq 32(%0), %%mm0\n"
29882 - " movq 40(%0), %%mm1\n"
29883 - " movq 48(%0), %%mm2\n"
29884 - " movq 56(%0), %%mm3\n"
29885 - " movq %%mm0, 32(%1)\n"
29886 - " movq %%mm1, 40(%1)\n"
29887 - " movq %%mm2, 48(%1)\n"
29888 - " movq %%mm3, 56(%1)\n"
29889 + "1: prefetch 320(%1)\n"
29890 + "2: movq (%1), %%mm0\n"
29891 + " movq 8(%1), %%mm1\n"
29892 + " movq 16(%1), %%mm2\n"
29893 + " movq 24(%1), %%mm3\n"
29894 + " movq %%mm0, (%2)\n"
29895 + " movq %%mm1, 8(%2)\n"
29896 + " movq %%mm2, 16(%2)\n"
29897 + " movq %%mm3, 24(%2)\n"
29898 + " movq 32(%1), %%mm0\n"
29899 + " movq 40(%1), %%mm1\n"
29900 + " movq 48(%1), %%mm2\n"
29901 + " movq 56(%1), %%mm3\n"
29902 + " movq %%mm0, 32(%2)\n"
29903 + " movq %%mm1, 40(%2)\n"
29904 + " movq %%mm2, 48(%2)\n"
29905 + " movq %%mm3, 56(%2)\n"
29906 ".section .fixup, \"ax\"\n"
29907 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29908 + "3:\n"
29909 +
29910 +#ifdef CONFIG_PAX_KERNEXEC
29911 + " movl %%cr0, %0\n"
29912 + " movl %0, %%eax\n"
29913 + " andl $0xFFFEFFFF, %%eax\n"
29914 + " movl %%eax, %%cr0\n"
29915 +#endif
29916 +
29917 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29918 +
29919 +#ifdef CONFIG_PAX_KERNEXEC
29920 + " movl %0, %%cr0\n"
29921 +#endif
29922 +
29923 " jmp 2b\n"
29924 ".previous\n"
29925 _ASM_EXTABLE(1b, 3b)
29926 - : : "r" (from), "r" (to) : "memory");
29927 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29928
29929 from += 64;
29930 to += 64;
29931 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29932 static void fast_copy_page(void *to, void *from)
29933 {
29934 int i;
29935 + unsigned long cr0;
29936
29937 kernel_fpu_begin();
29938
29939 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29940 * but that is for later. -AV
29941 */
29942 __asm__ __volatile__(
29943 - "1: prefetch (%0)\n"
29944 - " prefetch 64(%0)\n"
29945 - " prefetch 128(%0)\n"
29946 - " prefetch 192(%0)\n"
29947 - " prefetch 256(%0)\n"
29948 + "1: prefetch (%1)\n"
29949 + " prefetch 64(%1)\n"
29950 + " prefetch 128(%1)\n"
29951 + " prefetch 192(%1)\n"
29952 + " prefetch 256(%1)\n"
29953 "2: \n"
29954 ".section .fixup, \"ax\"\n"
29955 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29956 + "3: \n"
29957 +
29958 +#ifdef CONFIG_PAX_KERNEXEC
29959 + " movl %%cr0, %0\n"
29960 + " movl %0, %%eax\n"
29961 + " andl $0xFFFEFFFF, %%eax\n"
29962 + " movl %%eax, %%cr0\n"
29963 +#endif
29964 +
29965 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29966 +
29967 +#ifdef CONFIG_PAX_KERNEXEC
29968 + " movl %0, %%cr0\n"
29969 +#endif
29970 +
29971 " jmp 2b\n"
29972 ".previous\n"
29973 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29974 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29975
29976 for (i = 0; i < (4096-320)/64; i++) {
29977 __asm__ __volatile__ (
29978 - "1: prefetch 320(%0)\n"
29979 - "2: movq (%0), %%mm0\n"
29980 - " movntq %%mm0, (%1)\n"
29981 - " movq 8(%0), %%mm1\n"
29982 - " movntq %%mm1, 8(%1)\n"
29983 - " movq 16(%0), %%mm2\n"
29984 - " movntq %%mm2, 16(%1)\n"
29985 - " movq 24(%0), %%mm3\n"
29986 - " movntq %%mm3, 24(%1)\n"
29987 - " movq 32(%0), %%mm4\n"
29988 - " movntq %%mm4, 32(%1)\n"
29989 - " movq 40(%0), %%mm5\n"
29990 - " movntq %%mm5, 40(%1)\n"
29991 - " movq 48(%0), %%mm6\n"
29992 - " movntq %%mm6, 48(%1)\n"
29993 - " movq 56(%0), %%mm7\n"
29994 - " movntq %%mm7, 56(%1)\n"
29995 + "1: prefetch 320(%1)\n"
29996 + "2: movq (%1), %%mm0\n"
29997 + " movntq %%mm0, (%2)\n"
29998 + " movq 8(%1), %%mm1\n"
29999 + " movntq %%mm1, 8(%2)\n"
30000 + " movq 16(%1), %%mm2\n"
30001 + " movntq %%mm2, 16(%2)\n"
30002 + " movq 24(%1), %%mm3\n"
30003 + " movntq %%mm3, 24(%2)\n"
30004 + " movq 32(%1), %%mm4\n"
30005 + " movntq %%mm4, 32(%2)\n"
30006 + " movq 40(%1), %%mm5\n"
30007 + " movntq %%mm5, 40(%2)\n"
30008 + " movq 48(%1), %%mm6\n"
30009 + " movntq %%mm6, 48(%2)\n"
30010 + " movq 56(%1), %%mm7\n"
30011 + " movntq %%mm7, 56(%2)\n"
30012 ".section .fixup, \"ax\"\n"
30013 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30014 + "3:\n"
30015 +
30016 +#ifdef CONFIG_PAX_KERNEXEC
30017 + " movl %%cr0, %0\n"
30018 + " movl %0, %%eax\n"
30019 + " andl $0xFFFEFFFF, %%eax\n"
30020 + " movl %%eax, %%cr0\n"
30021 +#endif
30022 +
30023 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30024 +
30025 +#ifdef CONFIG_PAX_KERNEXEC
30026 + " movl %0, %%cr0\n"
30027 +#endif
30028 +
30029 " jmp 2b\n"
30030 ".previous\n"
30031 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30032 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30033
30034 from += 64;
30035 to += 64;
30036 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30037 static void fast_copy_page(void *to, void *from)
30038 {
30039 int i;
30040 + unsigned long cr0;
30041
30042 kernel_fpu_begin();
30043
30044 __asm__ __volatile__ (
30045 - "1: prefetch (%0)\n"
30046 - " prefetch 64(%0)\n"
30047 - " prefetch 128(%0)\n"
30048 - " prefetch 192(%0)\n"
30049 - " prefetch 256(%0)\n"
30050 + "1: prefetch (%1)\n"
30051 + " prefetch 64(%1)\n"
30052 + " prefetch 128(%1)\n"
30053 + " prefetch 192(%1)\n"
30054 + " prefetch 256(%1)\n"
30055 "2: \n"
30056 ".section .fixup, \"ax\"\n"
30057 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30058 + "3: \n"
30059 +
30060 +#ifdef CONFIG_PAX_KERNEXEC
30061 + " movl %%cr0, %0\n"
30062 + " movl %0, %%eax\n"
30063 + " andl $0xFFFEFFFF, %%eax\n"
30064 + " movl %%eax, %%cr0\n"
30065 +#endif
30066 +
30067 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30068 +
30069 +#ifdef CONFIG_PAX_KERNEXEC
30070 + " movl %0, %%cr0\n"
30071 +#endif
30072 +
30073 " jmp 2b\n"
30074 ".previous\n"
30075 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30076 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30077
30078 for (i = 0; i < 4096/64; i++) {
30079 __asm__ __volatile__ (
30080 - "1: prefetch 320(%0)\n"
30081 - "2: movq (%0), %%mm0\n"
30082 - " movq 8(%0), %%mm1\n"
30083 - " movq 16(%0), %%mm2\n"
30084 - " movq 24(%0), %%mm3\n"
30085 - " movq %%mm0, (%1)\n"
30086 - " movq %%mm1, 8(%1)\n"
30087 - " movq %%mm2, 16(%1)\n"
30088 - " movq %%mm3, 24(%1)\n"
30089 - " movq 32(%0), %%mm0\n"
30090 - " movq 40(%0), %%mm1\n"
30091 - " movq 48(%0), %%mm2\n"
30092 - " movq 56(%0), %%mm3\n"
30093 - " movq %%mm0, 32(%1)\n"
30094 - " movq %%mm1, 40(%1)\n"
30095 - " movq %%mm2, 48(%1)\n"
30096 - " movq %%mm3, 56(%1)\n"
30097 + "1: prefetch 320(%1)\n"
30098 + "2: movq (%1), %%mm0\n"
30099 + " movq 8(%1), %%mm1\n"
30100 + " movq 16(%1), %%mm2\n"
30101 + " movq 24(%1), %%mm3\n"
30102 + " movq %%mm0, (%2)\n"
30103 + " movq %%mm1, 8(%2)\n"
30104 + " movq %%mm2, 16(%2)\n"
30105 + " movq %%mm3, 24(%2)\n"
30106 + " movq 32(%1), %%mm0\n"
30107 + " movq 40(%1), %%mm1\n"
30108 + " movq 48(%1), %%mm2\n"
30109 + " movq 56(%1), %%mm3\n"
30110 + " movq %%mm0, 32(%2)\n"
30111 + " movq %%mm1, 40(%2)\n"
30112 + " movq %%mm2, 48(%2)\n"
30113 + " movq %%mm3, 56(%2)\n"
30114 ".section .fixup, \"ax\"\n"
30115 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30116 + "3:\n"
30117 +
30118 +#ifdef CONFIG_PAX_KERNEXEC
30119 + " movl %%cr0, %0\n"
30120 + " movl %0, %%eax\n"
30121 + " andl $0xFFFEFFFF, %%eax\n"
30122 + " movl %%eax, %%cr0\n"
30123 +#endif
30124 +
30125 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30126 +
30127 +#ifdef CONFIG_PAX_KERNEXEC
30128 + " movl %0, %%cr0\n"
30129 +#endif
30130 +
30131 " jmp 2b\n"
30132 ".previous\n"
30133 _ASM_EXTABLE(1b, 3b)
30134 - : : "r" (from), "r" (to) : "memory");
30135 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30136
30137 from += 64;
30138 to += 64;
30139 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30140 index f6d13ee..d789440 100644
30141 --- a/arch/x86/lib/msr-reg.S
30142 +++ b/arch/x86/lib/msr-reg.S
30143 @@ -3,6 +3,7 @@
30144 #include <asm/dwarf2.h>
30145 #include <asm/asm.h>
30146 #include <asm/msr.h>
30147 +#include <asm/alternative-asm.h>
30148
30149 #ifdef CONFIG_X86_64
30150 /*
30151 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30152 movl %edi, 28(%r10)
30153 popq_cfi %rbp
30154 popq_cfi %rbx
30155 + pax_force_retaddr
30156 ret
30157 3:
30158 CFI_RESTORE_STATE
30159 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30160 index fc6ba17..d4d989d 100644
30161 --- a/arch/x86/lib/putuser.S
30162 +++ b/arch/x86/lib/putuser.S
30163 @@ -16,7 +16,9 @@
30164 #include <asm/errno.h>
30165 #include <asm/asm.h>
30166 #include <asm/smap.h>
30167 -
30168 +#include <asm/segment.h>
30169 +#include <asm/pgtable.h>
30170 +#include <asm/alternative-asm.h>
30171
30172 /*
30173 * __put_user_X
30174 @@ -30,57 +32,125 @@
30175 * as they get called from within inline assembly.
30176 */
30177
30178 -#define ENTER CFI_STARTPROC ; \
30179 - GET_THREAD_INFO(%_ASM_BX)
30180 -#define EXIT ASM_CLAC ; \
30181 - ret ; \
30182 +#define ENTER CFI_STARTPROC
30183 +#define EXIT ASM_CLAC ; \
30184 + pax_force_retaddr ; \
30185 + ret ; \
30186 CFI_ENDPROC
30187
30188 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30189 +#define _DEST %_ASM_CX,%_ASM_BX
30190 +#else
30191 +#define _DEST %_ASM_CX
30192 +#endif
30193 +
30194 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30195 +#define __copyuser_seg gs;
30196 +#else
30197 +#define __copyuser_seg
30198 +#endif
30199 +
30200 .text
30201 ENTRY(__put_user_1)
30202 ENTER
30203 +
30204 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30205 + GET_THREAD_INFO(%_ASM_BX)
30206 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30207 jae bad_put_user
30208 ASM_STAC
30209 -1: movb %al,(%_ASM_CX)
30210 +
30211 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30212 + mov pax_user_shadow_base,%_ASM_BX
30213 + cmp %_ASM_BX,%_ASM_CX
30214 + jb 1234f
30215 + xor %ebx,%ebx
30216 +1234:
30217 +#endif
30218 +
30219 +#endif
30220 +
30221 +1: __copyuser_seg movb %al,(_DEST)
30222 xor %eax,%eax
30223 EXIT
30224 ENDPROC(__put_user_1)
30225
30226 ENTRY(__put_user_2)
30227 ENTER
30228 +
30229 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30230 + GET_THREAD_INFO(%_ASM_BX)
30231 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30232 sub $1,%_ASM_BX
30233 cmp %_ASM_BX,%_ASM_CX
30234 jae bad_put_user
30235 ASM_STAC
30236 -2: movw %ax,(%_ASM_CX)
30237 +
30238 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30239 + mov pax_user_shadow_base,%_ASM_BX
30240 + cmp %_ASM_BX,%_ASM_CX
30241 + jb 1234f
30242 + xor %ebx,%ebx
30243 +1234:
30244 +#endif
30245 +
30246 +#endif
30247 +
30248 +2: __copyuser_seg movw %ax,(_DEST)
30249 xor %eax,%eax
30250 EXIT
30251 ENDPROC(__put_user_2)
30252
30253 ENTRY(__put_user_4)
30254 ENTER
30255 +
30256 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30257 + GET_THREAD_INFO(%_ASM_BX)
30258 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30259 sub $3,%_ASM_BX
30260 cmp %_ASM_BX,%_ASM_CX
30261 jae bad_put_user
30262 ASM_STAC
30263 -3: movl %eax,(%_ASM_CX)
30264 +
30265 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30266 + mov pax_user_shadow_base,%_ASM_BX
30267 + cmp %_ASM_BX,%_ASM_CX
30268 + jb 1234f
30269 + xor %ebx,%ebx
30270 +1234:
30271 +#endif
30272 +
30273 +#endif
30274 +
30275 +3: __copyuser_seg movl %eax,(_DEST)
30276 xor %eax,%eax
30277 EXIT
30278 ENDPROC(__put_user_4)
30279
30280 ENTRY(__put_user_8)
30281 ENTER
30282 +
30283 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30284 + GET_THREAD_INFO(%_ASM_BX)
30285 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30286 sub $7,%_ASM_BX
30287 cmp %_ASM_BX,%_ASM_CX
30288 jae bad_put_user
30289 ASM_STAC
30290 -4: mov %_ASM_AX,(%_ASM_CX)
30291 +
30292 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30293 + mov pax_user_shadow_base,%_ASM_BX
30294 + cmp %_ASM_BX,%_ASM_CX
30295 + jb 1234f
30296 + xor %ebx,%ebx
30297 +1234:
30298 +#endif
30299 +
30300 +#endif
30301 +
30302 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30303 #ifdef CONFIG_X86_32
30304 -5: movl %edx,4(%_ASM_CX)
30305 +5: __copyuser_seg movl %edx,4(_DEST)
30306 #endif
30307 xor %eax,%eax
30308 EXIT
30309 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30310 index 1cad221..de671ee 100644
30311 --- a/arch/x86/lib/rwlock.S
30312 +++ b/arch/x86/lib/rwlock.S
30313 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30314 FRAME
30315 0: LOCK_PREFIX
30316 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30317 +
30318 +#ifdef CONFIG_PAX_REFCOUNT
30319 + jno 1234f
30320 + LOCK_PREFIX
30321 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30322 + int $4
30323 +1234:
30324 + _ASM_EXTABLE(1234b, 1234b)
30325 +#endif
30326 +
30327 1: rep; nop
30328 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30329 jne 1b
30330 LOCK_PREFIX
30331 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30332 +
30333 +#ifdef CONFIG_PAX_REFCOUNT
30334 + jno 1234f
30335 + LOCK_PREFIX
30336 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30337 + int $4
30338 +1234:
30339 + _ASM_EXTABLE(1234b, 1234b)
30340 +#endif
30341 +
30342 jnz 0b
30343 ENDFRAME
30344 + pax_force_retaddr
30345 ret
30346 CFI_ENDPROC
30347 END(__write_lock_failed)
30348 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30349 FRAME
30350 0: LOCK_PREFIX
30351 READ_LOCK_SIZE(inc) (%__lock_ptr)
30352 +
30353 +#ifdef CONFIG_PAX_REFCOUNT
30354 + jno 1234f
30355 + LOCK_PREFIX
30356 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30357 + int $4
30358 +1234:
30359 + _ASM_EXTABLE(1234b, 1234b)
30360 +#endif
30361 +
30362 1: rep; nop
30363 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30364 js 1b
30365 LOCK_PREFIX
30366 READ_LOCK_SIZE(dec) (%__lock_ptr)
30367 +
30368 +#ifdef CONFIG_PAX_REFCOUNT
30369 + jno 1234f
30370 + LOCK_PREFIX
30371 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30372 + int $4
30373 +1234:
30374 + _ASM_EXTABLE(1234b, 1234b)
30375 +#endif
30376 +
30377 js 0b
30378 ENDFRAME
30379 + pax_force_retaddr
30380 ret
30381 CFI_ENDPROC
30382 END(__read_lock_failed)
30383 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30384 index 5dff5f0..cadebf4 100644
30385 --- a/arch/x86/lib/rwsem.S
30386 +++ b/arch/x86/lib/rwsem.S
30387 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30388 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30389 CFI_RESTORE __ASM_REG(dx)
30390 restore_common_regs
30391 + pax_force_retaddr
30392 ret
30393 CFI_ENDPROC
30394 ENDPROC(call_rwsem_down_read_failed)
30395 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30396 movq %rax,%rdi
30397 call rwsem_down_write_failed
30398 restore_common_regs
30399 + pax_force_retaddr
30400 ret
30401 CFI_ENDPROC
30402 ENDPROC(call_rwsem_down_write_failed)
30403 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30404 movq %rax,%rdi
30405 call rwsem_wake
30406 restore_common_regs
30407 -1: ret
30408 +1: pax_force_retaddr
30409 + ret
30410 CFI_ENDPROC
30411 ENDPROC(call_rwsem_wake)
30412
30413 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30414 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30415 CFI_RESTORE __ASM_REG(dx)
30416 restore_common_regs
30417 + pax_force_retaddr
30418 ret
30419 CFI_ENDPROC
30420 ENDPROC(call_rwsem_downgrade_wake)
30421 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30422 index a63efd6..8149fbe 100644
30423 --- a/arch/x86/lib/thunk_64.S
30424 +++ b/arch/x86/lib/thunk_64.S
30425 @@ -8,6 +8,7 @@
30426 #include <linux/linkage.h>
30427 #include <asm/dwarf2.h>
30428 #include <asm/calling.h>
30429 +#include <asm/alternative-asm.h>
30430
30431 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30432 .macro THUNK name, func, put_ret_addr_in_rdi=0
30433 @@ -15,11 +16,11 @@
30434 \name:
30435 CFI_STARTPROC
30436
30437 - /* this one pushes 9 elems, the next one would be %rIP */
30438 - SAVE_ARGS
30439 + /* this one pushes 15+1 elems, the next one would be %rIP */
30440 + SAVE_ARGS 8
30441
30442 .if \put_ret_addr_in_rdi
30443 - movq_cfi_restore 9*8, rdi
30444 + movq_cfi_restore RIP, rdi
30445 .endif
30446
30447 call \func
30448 @@ -38,8 +39,9 @@
30449
30450 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30451 CFI_STARTPROC
30452 - SAVE_ARGS
30453 + SAVE_ARGS 8
30454 restore:
30455 - RESTORE_ARGS
30456 + RESTORE_ARGS 1,8
30457 + pax_force_retaddr
30458 ret
30459 CFI_ENDPROC
30460 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30461 index e2f5e21..4b22130 100644
30462 --- a/arch/x86/lib/usercopy_32.c
30463 +++ b/arch/x86/lib/usercopy_32.c
30464 @@ -42,11 +42,13 @@ do { \
30465 int __d0; \
30466 might_fault(); \
30467 __asm__ __volatile__( \
30468 + __COPYUSER_SET_ES \
30469 ASM_STAC "\n" \
30470 "0: rep; stosl\n" \
30471 " movl %2,%0\n" \
30472 "1: rep; stosb\n" \
30473 "2: " ASM_CLAC "\n" \
30474 + __COPYUSER_RESTORE_ES \
30475 ".section .fixup,\"ax\"\n" \
30476 "3: lea 0(%2,%0,4),%0\n" \
30477 " jmp 2b\n" \
30478 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30479
30480 #ifdef CONFIG_X86_INTEL_USERCOPY
30481 static unsigned long
30482 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30483 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30484 {
30485 int d0, d1;
30486 __asm__ __volatile__(
30487 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30488 " .align 2,0x90\n"
30489 "3: movl 0(%4), %%eax\n"
30490 "4: movl 4(%4), %%edx\n"
30491 - "5: movl %%eax, 0(%3)\n"
30492 - "6: movl %%edx, 4(%3)\n"
30493 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30494 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30495 "7: movl 8(%4), %%eax\n"
30496 "8: movl 12(%4),%%edx\n"
30497 - "9: movl %%eax, 8(%3)\n"
30498 - "10: movl %%edx, 12(%3)\n"
30499 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30500 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30501 "11: movl 16(%4), %%eax\n"
30502 "12: movl 20(%4), %%edx\n"
30503 - "13: movl %%eax, 16(%3)\n"
30504 - "14: movl %%edx, 20(%3)\n"
30505 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30506 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30507 "15: movl 24(%4), %%eax\n"
30508 "16: movl 28(%4), %%edx\n"
30509 - "17: movl %%eax, 24(%3)\n"
30510 - "18: movl %%edx, 28(%3)\n"
30511 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30512 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30513 "19: movl 32(%4), %%eax\n"
30514 "20: movl 36(%4), %%edx\n"
30515 - "21: movl %%eax, 32(%3)\n"
30516 - "22: movl %%edx, 36(%3)\n"
30517 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30518 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30519 "23: movl 40(%4), %%eax\n"
30520 "24: movl 44(%4), %%edx\n"
30521 - "25: movl %%eax, 40(%3)\n"
30522 - "26: movl %%edx, 44(%3)\n"
30523 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30524 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30525 "27: movl 48(%4), %%eax\n"
30526 "28: movl 52(%4), %%edx\n"
30527 - "29: movl %%eax, 48(%3)\n"
30528 - "30: movl %%edx, 52(%3)\n"
30529 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30530 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30531 "31: movl 56(%4), %%eax\n"
30532 "32: movl 60(%4), %%edx\n"
30533 - "33: movl %%eax, 56(%3)\n"
30534 - "34: movl %%edx, 60(%3)\n"
30535 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30536 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30537 " addl $-64, %0\n"
30538 " addl $64, %4\n"
30539 " addl $64, %3\n"
30540 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30541 " shrl $2, %0\n"
30542 " andl $3, %%eax\n"
30543 " cld\n"
30544 + __COPYUSER_SET_ES
30545 "99: rep; movsl\n"
30546 "36: movl %%eax, %0\n"
30547 "37: rep; movsb\n"
30548 "100:\n"
30549 + __COPYUSER_RESTORE_ES
30550 + ".section .fixup,\"ax\"\n"
30551 + "101: lea 0(%%eax,%0,4),%0\n"
30552 + " jmp 100b\n"
30553 + ".previous\n"
30554 + _ASM_EXTABLE(1b,100b)
30555 + _ASM_EXTABLE(2b,100b)
30556 + _ASM_EXTABLE(3b,100b)
30557 + _ASM_EXTABLE(4b,100b)
30558 + _ASM_EXTABLE(5b,100b)
30559 + _ASM_EXTABLE(6b,100b)
30560 + _ASM_EXTABLE(7b,100b)
30561 + _ASM_EXTABLE(8b,100b)
30562 + _ASM_EXTABLE(9b,100b)
30563 + _ASM_EXTABLE(10b,100b)
30564 + _ASM_EXTABLE(11b,100b)
30565 + _ASM_EXTABLE(12b,100b)
30566 + _ASM_EXTABLE(13b,100b)
30567 + _ASM_EXTABLE(14b,100b)
30568 + _ASM_EXTABLE(15b,100b)
30569 + _ASM_EXTABLE(16b,100b)
30570 + _ASM_EXTABLE(17b,100b)
30571 + _ASM_EXTABLE(18b,100b)
30572 + _ASM_EXTABLE(19b,100b)
30573 + _ASM_EXTABLE(20b,100b)
30574 + _ASM_EXTABLE(21b,100b)
30575 + _ASM_EXTABLE(22b,100b)
30576 + _ASM_EXTABLE(23b,100b)
30577 + _ASM_EXTABLE(24b,100b)
30578 + _ASM_EXTABLE(25b,100b)
30579 + _ASM_EXTABLE(26b,100b)
30580 + _ASM_EXTABLE(27b,100b)
30581 + _ASM_EXTABLE(28b,100b)
30582 + _ASM_EXTABLE(29b,100b)
30583 + _ASM_EXTABLE(30b,100b)
30584 + _ASM_EXTABLE(31b,100b)
30585 + _ASM_EXTABLE(32b,100b)
30586 + _ASM_EXTABLE(33b,100b)
30587 + _ASM_EXTABLE(34b,100b)
30588 + _ASM_EXTABLE(35b,100b)
30589 + _ASM_EXTABLE(36b,100b)
30590 + _ASM_EXTABLE(37b,100b)
30591 + _ASM_EXTABLE(99b,101b)
30592 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30593 + : "1"(to), "2"(from), "0"(size)
30594 + : "eax", "edx", "memory");
30595 + return size;
30596 +}
30597 +
30598 +static unsigned long
30599 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30600 +{
30601 + int d0, d1;
30602 + __asm__ __volatile__(
30603 + " .align 2,0x90\n"
30604 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30605 + " cmpl $67, %0\n"
30606 + " jbe 3f\n"
30607 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30608 + " .align 2,0x90\n"
30609 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30610 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30611 + "5: movl %%eax, 0(%3)\n"
30612 + "6: movl %%edx, 4(%3)\n"
30613 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30614 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30615 + "9: movl %%eax, 8(%3)\n"
30616 + "10: movl %%edx, 12(%3)\n"
30617 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30618 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30619 + "13: movl %%eax, 16(%3)\n"
30620 + "14: movl %%edx, 20(%3)\n"
30621 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30622 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30623 + "17: movl %%eax, 24(%3)\n"
30624 + "18: movl %%edx, 28(%3)\n"
30625 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30626 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30627 + "21: movl %%eax, 32(%3)\n"
30628 + "22: movl %%edx, 36(%3)\n"
30629 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30630 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30631 + "25: movl %%eax, 40(%3)\n"
30632 + "26: movl %%edx, 44(%3)\n"
30633 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30634 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30635 + "29: movl %%eax, 48(%3)\n"
30636 + "30: movl %%edx, 52(%3)\n"
30637 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30638 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30639 + "33: movl %%eax, 56(%3)\n"
30640 + "34: movl %%edx, 60(%3)\n"
30641 + " addl $-64, %0\n"
30642 + " addl $64, %4\n"
30643 + " addl $64, %3\n"
30644 + " cmpl $63, %0\n"
30645 + " ja 1b\n"
30646 + "35: movl %0, %%eax\n"
30647 + " shrl $2, %0\n"
30648 + " andl $3, %%eax\n"
30649 + " cld\n"
30650 + "99: rep; "__copyuser_seg" movsl\n"
30651 + "36: movl %%eax, %0\n"
30652 + "37: rep; "__copyuser_seg" movsb\n"
30653 + "100:\n"
30654 ".section .fixup,\"ax\"\n"
30655 "101: lea 0(%%eax,%0,4),%0\n"
30656 " jmp 100b\n"
30657 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30658 int d0, d1;
30659 __asm__ __volatile__(
30660 " .align 2,0x90\n"
30661 - "0: movl 32(%4), %%eax\n"
30662 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30663 " cmpl $67, %0\n"
30664 " jbe 2f\n"
30665 - "1: movl 64(%4), %%eax\n"
30666 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30667 " .align 2,0x90\n"
30668 - "2: movl 0(%4), %%eax\n"
30669 - "21: movl 4(%4), %%edx\n"
30670 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30671 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30672 " movl %%eax, 0(%3)\n"
30673 " movl %%edx, 4(%3)\n"
30674 - "3: movl 8(%4), %%eax\n"
30675 - "31: movl 12(%4),%%edx\n"
30676 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30677 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30678 " movl %%eax, 8(%3)\n"
30679 " movl %%edx, 12(%3)\n"
30680 - "4: movl 16(%4), %%eax\n"
30681 - "41: movl 20(%4), %%edx\n"
30682 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30683 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30684 " movl %%eax, 16(%3)\n"
30685 " movl %%edx, 20(%3)\n"
30686 - "10: movl 24(%4), %%eax\n"
30687 - "51: movl 28(%4), %%edx\n"
30688 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30689 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30690 " movl %%eax, 24(%3)\n"
30691 " movl %%edx, 28(%3)\n"
30692 - "11: movl 32(%4), %%eax\n"
30693 - "61: movl 36(%4), %%edx\n"
30694 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30695 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30696 " movl %%eax, 32(%3)\n"
30697 " movl %%edx, 36(%3)\n"
30698 - "12: movl 40(%4), %%eax\n"
30699 - "71: movl 44(%4), %%edx\n"
30700 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30701 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30702 " movl %%eax, 40(%3)\n"
30703 " movl %%edx, 44(%3)\n"
30704 - "13: movl 48(%4), %%eax\n"
30705 - "81: movl 52(%4), %%edx\n"
30706 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30707 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30708 " movl %%eax, 48(%3)\n"
30709 " movl %%edx, 52(%3)\n"
30710 - "14: movl 56(%4), %%eax\n"
30711 - "91: movl 60(%4), %%edx\n"
30712 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30713 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30714 " movl %%eax, 56(%3)\n"
30715 " movl %%edx, 60(%3)\n"
30716 " addl $-64, %0\n"
30717 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30718 " shrl $2, %0\n"
30719 " andl $3, %%eax\n"
30720 " cld\n"
30721 - "6: rep; movsl\n"
30722 + "6: rep; "__copyuser_seg" movsl\n"
30723 " movl %%eax,%0\n"
30724 - "7: rep; movsb\n"
30725 + "7: rep; "__copyuser_seg" movsb\n"
30726 "8:\n"
30727 ".section .fixup,\"ax\"\n"
30728 "9: lea 0(%%eax,%0,4),%0\n"
30729 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30730
30731 __asm__ __volatile__(
30732 " .align 2,0x90\n"
30733 - "0: movl 32(%4), %%eax\n"
30734 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30735 " cmpl $67, %0\n"
30736 " jbe 2f\n"
30737 - "1: movl 64(%4), %%eax\n"
30738 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30739 " .align 2,0x90\n"
30740 - "2: movl 0(%4), %%eax\n"
30741 - "21: movl 4(%4), %%edx\n"
30742 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30743 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30744 " movnti %%eax, 0(%3)\n"
30745 " movnti %%edx, 4(%3)\n"
30746 - "3: movl 8(%4), %%eax\n"
30747 - "31: movl 12(%4),%%edx\n"
30748 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30749 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30750 " movnti %%eax, 8(%3)\n"
30751 " movnti %%edx, 12(%3)\n"
30752 - "4: movl 16(%4), %%eax\n"
30753 - "41: movl 20(%4), %%edx\n"
30754 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30755 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30756 " movnti %%eax, 16(%3)\n"
30757 " movnti %%edx, 20(%3)\n"
30758 - "10: movl 24(%4), %%eax\n"
30759 - "51: movl 28(%4), %%edx\n"
30760 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30761 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30762 " movnti %%eax, 24(%3)\n"
30763 " movnti %%edx, 28(%3)\n"
30764 - "11: movl 32(%4), %%eax\n"
30765 - "61: movl 36(%4), %%edx\n"
30766 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30767 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30768 " movnti %%eax, 32(%3)\n"
30769 " movnti %%edx, 36(%3)\n"
30770 - "12: movl 40(%4), %%eax\n"
30771 - "71: movl 44(%4), %%edx\n"
30772 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30773 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30774 " movnti %%eax, 40(%3)\n"
30775 " movnti %%edx, 44(%3)\n"
30776 - "13: movl 48(%4), %%eax\n"
30777 - "81: movl 52(%4), %%edx\n"
30778 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30779 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30780 " movnti %%eax, 48(%3)\n"
30781 " movnti %%edx, 52(%3)\n"
30782 - "14: movl 56(%4), %%eax\n"
30783 - "91: movl 60(%4), %%edx\n"
30784 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30785 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30786 " movnti %%eax, 56(%3)\n"
30787 " movnti %%edx, 60(%3)\n"
30788 " addl $-64, %0\n"
30789 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30790 " shrl $2, %0\n"
30791 " andl $3, %%eax\n"
30792 " cld\n"
30793 - "6: rep; movsl\n"
30794 + "6: rep; "__copyuser_seg" movsl\n"
30795 " movl %%eax,%0\n"
30796 - "7: rep; movsb\n"
30797 + "7: rep; "__copyuser_seg" movsb\n"
30798 "8:\n"
30799 ".section .fixup,\"ax\"\n"
30800 "9: lea 0(%%eax,%0,4),%0\n"
30801 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30802
30803 __asm__ __volatile__(
30804 " .align 2,0x90\n"
30805 - "0: movl 32(%4), %%eax\n"
30806 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30807 " cmpl $67, %0\n"
30808 " jbe 2f\n"
30809 - "1: movl 64(%4), %%eax\n"
30810 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30811 " .align 2,0x90\n"
30812 - "2: movl 0(%4), %%eax\n"
30813 - "21: movl 4(%4), %%edx\n"
30814 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30815 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30816 " movnti %%eax, 0(%3)\n"
30817 " movnti %%edx, 4(%3)\n"
30818 - "3: movl 8(%4), %%eax\n"
30819 - "31: movl 12(%4),%%edx\n"
30820 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30821 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30822 " movnti %%eax, 8(%3)\n"
30823 " movnti %%edx, 12(%3)\n"
30824 - "4: movl 16(%4), %%eax\n"
30825 - "41: movl 20(%4), %%edx\n"
30826 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30827 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30828 " movnti %%eax, 16(%3)\n"
30829 " movnti %%edx, 20(%3)\n"
30830 - "10: movl 24(%4), %%eax\n"
30831 - "51: movl 28(%4), %%edx\n"
30832 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30833 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30834 " movnti %%eax, 24(%3)\n"
30835 " movnti %%edx, 28(%3)\n"
30836 - "11: movl 32(%4), %%eax\n"
30837 - "61: movl 36(%4), %%edx\n"
30838 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30839 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30840 " movnti %%eax, 32(%3)\n"
30841 " movnti %%edx, 36(%3)\n"
30842 - "12: movl 40(%4), %%eax\n"
30843 - "71: movl 44(%4), %%edx\n"
30844 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30845 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30846 " movnti %%eax, 40(%3)\n"
30847 " movnti %%edx, 44(%3)\n"
30848 - "13: movl 48(%4), %%eax\n"
30849 - "81: movl 52(%4), %%edx\n"
30850 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30851 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30852 " movnti %%eax, 48(%3)\n"
30853 " movnti %%edx, 52(%3)\n"
30854 - "14: movl 56(%4), %%eax\n"
30855 - "91: movl 60(%4), %%edx\n"
30856 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30857 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30858 " movnti %%eax, 56(%3)\n"
30859 " movnti %%edx, 60(%3)\n"
30860 " addl $-64, %0\n"
30861 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30862 " shrl $2, %0\n"
30863 " andl $3, %%eax\n"
30864 " cld\n"
30865 - "6: rep; movsl\n"
30866 + "6: rep; "__copyuser_seg" movsl\n"
30867 " movl %%eax,%0\n"
30868 - "7: rep; movsb\n"
30869 + "7: rep; "__copyuser_seg" movsb\n"
30870 "8:\n"
30871 ".section .fixup,\"ax\"\n"
30872 "9: lea 0(%%eax,%0,4),%0\n"
30873 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30874 */
30875 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30876 unsigned long size);
30877 -unsigned long __copy_user_intel(void __user *to, const void *from,
30878 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30879 + unsigned long size);
30880 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30881 unsigned long size);
30882 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30883 const void __user *from, unsigned long size);
30884 #endif /* CONFIG_X86_INTEL_USERCOPY */
30885
30886 /* Generic arbitrary sized copy. */
30887 -#define __copy_user(to, from, size) \
30888 +#define __copy_user(to, from, size, prefix, set, restore) \
30889 do { \
30890 int __d0, __d1, __d2; \
30891 __asm__ __volatile__( \
30892 + set \
30893 " cmp $7,%0\n" \
30894 " jbe 1f\n" \
30895 " movl %1,%0\n" \
30896 " negl %0\n" \
30897 " andl $7,%0\n" \
30898 " subl %0,%3\n" \
30899 - "4: rep; movsb\n" \
30900 + "4: rep; "prefix"movsb\n" \
30901 " movl %3,%0\n" \
30902 " shrl $2,%0\n" \
30903 " andl $3,%3\n" \
30904 " .align 2,0x90\n" \
30905 - "0: rep; movsl\n" \
30906 + "0: rep; "prefix"movsl\n" \
30907 " movl %3,%0\n" \
30908 - "1: rep; movsb\n" \
30909 + "1: rep; "prefix"movsb\n" \
30910 "2:\n" \
30911 + restore \
30912 ".section .fixup,\"ax\"\n" \
30913 "5: addl %3,%0\n" \
30914 " jmp 2b\n" \
30915 @@ -538,14 +650,14 @@ do { \
30916 " negl %0\n" \
30917 " andl $7,%0\n" \
30918 " subl %0,%3\n" \
30919 - "4: rep; movsb\n" \
30920 + "4: rep; "__copyuser_seg"movsb\n" \
30921 " movl %3,%0\n" \
30922 " shrl $2,%0\n" \
30923 " andl $3,%3\n" \
30924 " .align 2,0x90\n" \
30925 - "0: rep; movsl\n" \
30926 + "0: rep; "__copyuser_seg"movsl\n" \
30927 " movl %3,%0\n" \
30928 - "1: rep; movsb\n" \
30929 + "1: rep; "__copyuser_seg"movsb\n" \
30930 "2:\n" \
30931 ".section .fixup,\"ax\"\n" \
30932 "5: addl %3,%0\n" \
30933 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30934 {
30935 stac();
30936 if (movsl_is_ok(to, from, n))
30937 - __copy_user(to, from, n);
30938 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30939 else
30940 - n = __copy_user_intel(to, from, n);
30941 + n = __generic_copy_to_user_intel(to, from, n);
30942 clac();
30943 return n;
30944 }
30945 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30946 {
30947 stac();
30948 if (movsl_is_ok(to, from, n))
30949 - __copy_user(to, from, n);
30950 + __copy_user(to, from, n, __copyuser_seg, "", "");
30951 else
30952 - n = __copy_user_intel((void __user *)to,
30953 - (const void *)from, n);
30954 + n = __generic_copy_from_user_intel(to, from, n);
30955 clac();
30956 return n;
30957 }
30958 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30959 if (n > 64 && cpu_has_xmm2)
30960 n = __copy_user_intel_nocache(to, from, n);
30961 else
30962 - __copy_user(to, from, n);
30963 + __copy_user(to, from, n, __copyuser_seg, "", "");
30964 #else
30965 - __copy_user(to, from, n);
30966 + __copy_user(to, from, n, __copyuser_seg, "", "");
30967 #endif
30968 clac();
30969 return n;
30970 }
30971 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30972
30973 -/**
30974 - * copy_to_user: - Copy a block of data into user space.
30975 - * @to: Destination address, in user space.
30976 - * @from: Source address, in kernel space.
30977 - * @n: Number of bytes to copy.
30978 - *
30979 - * Context: User context only. This function may sleep.
30980 - *
30981 - * Copy data from kernel space to user space.
30982 - *
30983 - * Returns number of bytes that could not be copied.
30984 - * On success, this will be zero.
30985 - */
30986 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
30987 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30988 +void __set_fs(mm_segment_t x)
30989 {
30990 - if (access_ok(VERIFY_WRITE, to, n))
30991 - n = __copy_to_user(to, from, n);
30992 - return n;
30993 + switch (x.seg) {
30994 + case 0:
30995 + loadsegment(gs, 0);
30996 + break;
30997 + case TASK_SIZE_MAX:
30998 + loadsegment(gs, __USER_DS);
30999 + break;
31000 + case -1UL:
31001 + loadsegment(gs, __KERNEL_DS);
31002 + break;
31003 + default:
31004 + BUG();
31005 + }
31006 }
31007 -EXPORT_SYMBOL(_copy_to_user);
31008 +EXPORT_SYMBOL(__set_fs);
31009
31010 -/**
31011 - * copy_from_user: - Copy a block of data from user space.
31012 - * @to: Destination address, in kernel space.
31013 - * @from: Source address, in user space.
31014 - * @n: Number of bytes to copy.
31015 - *
31016 - * Context: User context only. This function may sleep.
31017 - *
31018 - * Copy data from user space to kernel space.
31019 - *
31020 - * Returns number of bytes that could not be copied.
31021 - * On success, this will be zero.
31022 - *
31023 - * If some data could not be copied, this function will pad the copied
31024 - * data to the requested size using zero bytes.
31025 - */
31026 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31027 +void set_fs(mm_segment_t x)
31028 {
31029 - if (access_ok(VERIFY_READ, from, n))
31030 - n = __copy_from_user(to, from, n);
31031 - else
31032 - memset(to, 0, n);
31033 - return n;
31034 + current_thread_info()->addr_limit = x;
31035 + __set_fs(x);
31036 }
31037 -EXPORT_SYMBOL(_copy_from_user);
31038 +EXPORT_SYMBOL(set_fs);
31039 +#endif
31040 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31041 index c905e89..01ab928 100644
31042 --- a/arch/x86/lib/usercopy_64.c
31043 +++ b/arch/x86/lib/usercopy_64.c
31044 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31045 might_fault();
31046 /* no memory constraint because it doesn't change any memory gcc knows
31047 about */
31048 + pax_open_userland();
31049 stac();
31050 asm volatile(
31051 " testq %[size8],%[size8]\n"
31052 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31053 _ASM_EXTABLE(0b,3b)
31054 _ASM_EXTABLE(1b,2b)
31055 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31056 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31057 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31058 [zero] "r" (0UL), [eight] "r" (8UL));
31059 clac();
31060 + pax_close_userland();
31061 return size;
31062 }
31063 EXPORT_SYMBOL(__clear_user);
31064 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31065 }
31066 EXPORT_SYMBOL(clear_user);
31067
31068 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31069 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31070 {
31071 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31072 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31073 - }
31074 - return len;
31075 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31076 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31077 + return len;
31078 }
31079 EXPORT_SYMBOL(copy_in_user);
31080
31081 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31082 * it is not necessary to optimize tail handling.
31083 */
31084 __visible unsigned long
31085 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31086 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31087 {
31088 char c;
31089 unsigned zero_len;
31090
31091 + clac();
31092 + pax_close_userland();
31093 for (; len; --len, to++) {
31094 if (__get_user_nocheck(c, from++, sizeof(char)))
31095 break;
31096 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31097 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31098 if (__put_user_nocheck(c, to++, sizeof(char)))
31099 break;
31100 - clac();
31101 return len;
31102 }
31103 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31104 index 6a19ad9..1c48f9a 100644
31105 --- a/arch/x86/mm/Makefile
31106 +++ b/arch/x86/mm/Makefile
31107 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31108 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31109
31110 obj-$(CONFIG_MEMTEST) += memtest.o
31111 +
31112 +quote:="
31113 +obj-$(CONFIG_X86_64) += uderef_64.o
31114 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31115 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31116 index 903ec1e..c4166b2 100644
31117 --- a/arch/x86/mm/extable.c
31118 +++ b/arch/x86/mm/extable.c
31119 @@ -6,12 +6,24 @@
31120 static inline unsigned long
31121 ex_insn_addr(const struct exception_table_entry *x)
31122 {
31123 - return (unsigned long)&x->insn + x->insn;
31124 + unsigned long reloc = 0;
31125 +
31126 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31127 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31128 +#endif
31129 +
31130 + return (unsigned long)&x->insn + x->insn + reloc;
31131 }
31132 static inline unsigned long
31133 ex_fixup_addr(const struct exception_table_entry *x)
31134 {
31135 - return (unsigned long)&x->fixup + x->fixup;
31136 + unsigned long reloc = 0;
31137 +
31138 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31139 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31140 +#endif
31141 +
31142 + return (unsigned long)&x->fixup + x->fixup + reloc;
31143 }
31144
31145 int fixup_exception(struct pt_regs *regs)
31146 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31147 unsigned long new_ip;
31148
31149 #ifdef CONFIG_PNPBIOS
31150 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31151 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31152 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31153 extern u32 pnp_bios_is_utter_crap;
31154 pnp_bios_is_utter_crap = 1;
31155 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31156 i += 4;
31157 p->fixup -= i;
31158 i += 4;
31159 +
31160 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31161 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31162 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31163 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31164 +#endif
31165 +
31166 }
31167 }
31168
31169 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31170 index 6dea040..31e52ff 100644
31171 --- a/arch/x86/mm/fault.c
31172 +++ b/arch/x86/mm/fault.c
31173 @@ -14,11 +14,18 @@
31174 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31175 #include <linux/prefetch.h> /* prefetchw */
31176 #include <linux/context_tracking.h> /* exception_enter(), ... */
31177 +#include <linux/unistd.h>
31178 +#include <linux/compiler.h>
31179
31180 #include <asm/traps.h> /* dotraplinkage, ... */
31181 #include <asm/pgalloc.h> /* pgd_*(), ... */
31182 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31183 #include <asm/fixmap.h> /* VSYSCALL_START */
31184 +#include <asm/tlbflush.h>
31185 +
31186 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31187 +#include <asm/stacktrace.h>
31188 +#endif
31189
31190 #define CREATE_TRACE_POINTS
31191 #include <asm/trace/exceptions.h>
31192 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31193 int ret = 0;
31194
31195 /* kprobe_running() needs smp_processor_id() */
31196 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31197 + if (kprobes_built_in() && !user_mode(regs)) {
31198 preempt_disable();
31199 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31200 ret = 1;
31201 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31202 return !instr_lo || (instr_lo>>1) == 1;
31203 case 0x00:
31204 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31205 - if (probe_kernel_address(instr, opcode))
31206 + if (user_mode(regs)) {
31207 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31208 + return 0;
31209 + } else if (probe_kernel_address(instr, opcode))
31210 return 0;
31211
31212 *prefetch = (instr_lo == 0xF) &&
31213 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31214 while (instr < max_instr) {
31215 unsigned char opcode;
31216
31217 - if (probe_kernel_address(instr, opcode))
31218 + if (user_mode(regs)) {
31219 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31220 + break;
31221 + } else if (probe_kernel_address(instr, opcode))
31222 break;
31223
31224 instr++;
31225 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31226 force_sig_info(si_signo, &info, tsk);
31227 }
31228
31229 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31230 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31231 +#endif
31232 +
31233 +#ifdef CONFIG_PAX_EMUTRAMP
31234 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31235 +#endif
31236 +
31237 +#ifdef CONFIG_PAX_PAGEEXEC
31238 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31239 +{
31240 + pgd_t *pgd;
31241 + pud_t *pud;
31242 + pmd_t *pmd;
31243 +
31244 + pgd = pgd_offset(mm, address);
31245 + if (!pgd_present(*pgd))
31246 + return NULL;
31247 + pud = pud_offset(pgd, address);
31248 + if (!pud_present(*pud))
31249 + return NULL;
31250 + pmd = pmd_offset(pud, address);
31251 + if (!pmd_present(*pmd))
31252 + return NULL;
31253 + return pmd;
31254 +}
31255 +#endif
31256 +
31257 DEFINE_SPINLOCK(pgd_lock);
31258 LIST_HEAD(pgd_list);
31259
31260 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31261 for (address = VMALLOC_START & PMD_MASK;
31262 address >= TASK_SIZE && address < FIXADDR_TOP;
31263 address += PMD_SIZE) {
31264 +
31265 +#ifdef CONFIG_PAX_PER_CPU_PGD
31266 + unsigned long cpu;
31267 +#else
31268 struct page *page;
31269 +#endif
31270
31271 spin_lock(&pgd_lock);
31272 +
31273 +#ifdef CONFIG_PAX_PER_CPU_PGD
31274 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31275 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31276 + pmd_t *ret;
31277 +
31278 + ret = vmalloc_sync_one(pgd, address);
31279 + if (!ret)
31280 + break;
31281 + pgd = get_cpu_pgd(cpu, kernel);
31282 +#else
31283 list_for_each_entry(page, &pgd_list, lru) {
31284 + pgd_t *pgd;
31285 spinlock_t *pgt_lock;
31286 pmd_t *ret;
31287
31288 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31289 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31290
31291 spin_lock(pgt_lock);
31292 - ret = vmalloc_sync_one(page_address(page), address);
31293 + pgd = page_address(page);
31294 +#endif
31295 +
31296 + ret = vmalloc_sync_one(pgd, address);
31297 +
31298 +#ifndef CONFIG_PAX_PER_CPU_PGD
31299 spin_unlock(pgt_lock);
31300 +#endif
31301
31302 if (!ret)
31303 break;
31304 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31305 * an interrupt in the middle of a task switch..
31306 */
31307 pgd_paddr = read_cr3();
31308 +
31309 +#ifdef CONFIG_PAX_PER_CPU_PGD
31310 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31311 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31312 +#endif
31313 +
31314 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31315 if (!pmd_k)
31316 return -1;
31317 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31318 * happen within a race in page table update. In the later
31319 * case just flush:
31320 */
31321 - pgd = pgd_offset(current->active_mm, address);
31322 +
31323 pgd_ref = pgd_offset_k(address);
31324 if (pgd_none(*pgd_ref))
31325 return -1;
31326
31327 +#ifdef CONFIG_PAX_PER_CPU_PGD
31328 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31329 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31330 + if (pgd_none(*pgd)) {
31331 + set_pgd(pgd, *pgd_ref);
31332 + arch_flush_lazy_mmu_mode();
31333 + } else {
31334 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31335 + }
31336 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31337 +#else
31338 + pgd = pgd_offset(current->active_mm, address);
31339 +#endif
31340 +
31341 if (pgd_none(*pgd)) {
31342 set_pgd(pgd, *pgd_ref);
31343 arch_flush_lazy_mmu_mode();
31344 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31345 static int is_errata100(struct pt_regs *regs, unsigned long address)
31346 {
31347 #ifdef CONFIG_X86_64
31348 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31349 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31350 return 1;
31351 #endif
31352 return 0;
31353 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31354 }
31355
31356 static const char nx_warning[] = KERN_CRIT
31357 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31358 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31359
31360 static void
31361 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31362 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31363 if (!oops_may_print())
31364 return;
31365
31366 - if (error_code & PF_INSTR) {
31367 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31368 unsigned int level;
31369
31370 pte_t *pte = lookup_address(address, &level);
31371
31372 if (pte && pte_present(*pte) && !pte_exec(*pte))
31373 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31374 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31375 }
31376
31377 +#ifdef CONFIG_PAX_KERNEXEC
31378 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31379 + if (current->signal->curr_ip)
31380 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31381 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31382 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31383 + else
31384 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31385 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31386 + }
31387 +#endif
31388 +
31389 printk(KERN_ALERT "BUG: unable to handle kernel ");
31390 if (address < PAGE_SIZE)
31391 printk(KERN_CONT "NULL pointer dereference");
31392 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31393 return;
31394 }
31395 #endif
31396 +
31397 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31398 + if (pax_is_fetch_fault(regs, error_code, address)) {
31399 +
31400 +#ifdef CONFIG_PAX_EMUTRAMP
31401 + switch (pax_handle_fetch_fault(regs)) {
31402 + case 2:
31403 + return;
31404 + }
31405 +#endif
31406 +
31407 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31408 + do_group_exit(SIGKILL);
31409 + }
31410 +#endif
31411 +
31412 /* Kernel addresses are always protection faults: */
31413 if (address >= TASK_SIZE)
31414 error_code |= PF_PROT;
31415 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31416 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31417 printk(KERN_ERR
31418 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31419 - tsk->comm, tsk->pid, address);
31420 + tsk->comm, task_pid_nr(tsk), address);
31421 code = BUS_MCEERR_AR;
31422 }
31423 #endif
31424 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31425 return 1;
31426 }
31427
31428 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31429 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31430 +{
31431 + pte_t *pte;
31432 + pmd_t *pmd;
31433 + spinlock_t *ptl;
31434 + unsigned char pte_mask;
31435 +
31436 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31437 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31438 + return 0;
31439 +
31440 + /* PaX: it's our fault, let's handle it if we can */
31441 +
31442 + /* PaX: take a look at read faults before acquiring any locks */
31443 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31444 + /* instruction fetch attempt from a protected page in user mode */
31445 + up_read(&mm->mmap_sem);
31446 +
31447 +#ifdef CONFIG_PAX_EMUTRAMP
31448 + switch (pax_handle_fetch_fault(regs)) {
31449 + case 2:
31450 + return 1;
31451 + }
31452 +#endif
31453 +
31454 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31455 + do_group_exit(SIGKILL);
31456 + }
31457 +
31458 + pmd = pax_get_pmd(mm, address);
31459 + if (unlikely(!pmd))
31460 + return 0;
31461 +
31462 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31463 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31464 + pte_unmap_unlock(pte, ptl);
31465 + return 0;
31466 + }
31467 +
31468 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31469 + /* write attempt to a protected page in user mode */
31470 + pte_unmap_unlock(pte, ptl);
31471 + return 0;
31472 + }
31473 +
31474 +#ifdef CONFIG_SMP
31475 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31476 +#else
31477 + if (likely(address > get_limit(regs->cs)))
31478 +#endif
31479 + {
31480 + set_pte(pte, pte_mkread(*pte));
31481 + __flush_tlb_one(address);
31482 + pte_unmap_unlock(pte, ptl);
31483 + up_read(&mm->mmap_sem);
31484 + return 1;
31485 + }
31486 +
31487 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31488 +
31489 + /*
31490 + * PaX: fill DTLB with user rights and retry
31491 + */
31492 + __asm__ __volatile__ (
31493 + "orb %2,(%1)\n"
31494 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31495 +/*
31496 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31497 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31498 + * page fault when examined during a TLB load attempt. this is true not only
31499 + * for PTEs holding a non-present entry but also present entries that will
31500 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31501 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31502 + * for our target pages since their PTEs are simply not in the TLBs at all.
31503 +
31504 + * the best thing in omitting it is that we gain around 15-20% speed in the
31505 + * fast path of the page fault handler and can get rid of tracing since we
31506 + * can no longer flush unintended entries.
31507 + */
31508 + "invlpg (%0)\n"
31509 +#endif
31510 + __copyuser_seg"testb $0,(%0)\n"
31511 + "xorb %3,(%1)\n"
31512 + :
31513 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31514 + : "memory", "cc");
31515 + pte_unmap_unlock(pte, ptl);
31516 + up_read(&mm->mmap_sem);
31517 + return 1;
31518 +}
31519 +#endif
31520 +
31521 /*
31522 * Handle a spurious fault caused by a stale TLB entry.
31523 *
31524 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31525 static inline int
31526 access_error(unsigned long error_code, struct vm_area_struct *vma)
31527 {
31528 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31529 + return 1;
31530 +
31531 if (error_code & PF_WRITE) {
31532 /* write, present and write, not present: */
31533 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31534 @@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31535 if (error_code & PF_USER)
31536 return false;
31537
31538 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31539 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31540 return false;
31541
31542 return true;
31543 @@ -1037,6 +1245,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31544 /* Get the faulting address: */
31545 address = read_cr2();
31546
31547 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31548 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31549 + if (!search_exception_tables(regs->ip)) {
31550 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31551 + bad_area_nosemaphore(regs, error_code, address);
31552 + return;
31553 + }
31554 + if (address < pax_user_shadow_base) {
31555 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31556 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31557 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31558 + } else
31559 + address -= pax_user_shadow_base;
31560 + }
31561 +#endif
31562 +
31563 /*
31564 * Detect and handle instructions that would cause a page fault for
31565 * both a tracked kernel page and a userspace page.
31566 @@ -1114,7 +1338,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31567 * User-mode registers count as a user access even for any
31568 * potential system fault or CPU buglet:
31569 */
31570 - if (user_mode_vm(regs)) {
31571 + if (user_mode(regs)) {
31572 local_irq_enable();
31573 error_code |= PF_USER;
31574 flags |= FAULT_FLAG_USER;
31575 @@ -1161,6 +1385,11 @@ retry:
31576 might_sleep();
31577 }
31578
31579 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31580 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31581 + return;
31582 +#endif
31583 +
31584 vma = find_vma(mm, address);
31585 if (unlikely(!vma)) {
31586 bad_area(regs, error_code, address);
31587 @@ -1172,18 +1401,24 @@ retry:
31588 bad_area(regs, error_code, address);
31589 return;
31590 }
31591 - if (error_code & PF_USER) {
31592 - /*
31593 - * Accessing the stack below %sp is always a bug.
31594 - * The large cushion allows instructions like enter
31595 - * and pusha to work. ("enter $65535, $31" pushes
31596 - * 32 pointers and then decrements %sp by 65535.)
31597 - */
31598 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31599 - bad_area(regs, error_code, address);
31600 - return;
31601 - }
31602 + /*
31603 + * Accessing the stack below %sp is always a bug.
31604 + * The large cushion allows instructions like enter
31605 + * and pusha to work. ("enter $65535, $31" pushes
31606 + * 32 pointers and then decrements %sp by 65535.)
31607 + */
31608 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31609 + bad_area(regs, error_code, address);
31610 + return;
31611 }
31612 +
31613 +#ifdef CONFIG_PAX_SEGMEXEC
31614 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31615 + bad_area(regs, error_code, address);
31616 + return;
31617 + }
31618 +#endif
31619 +
31620 if (unlikely(expand_stack(vma, address))) {
31621 bad_area(regs, error_code, address);
31622 return;
31623 @@ -1277,3 +1512,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31624 __do_page_fault(regs, error_code);
31625 exception_exit(prev_state);
31626 }
31627 +
31628 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31629 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31630 +{
31631 + struct mm_struct *mm = current->mm;
31632 + unsigned long ip = regs->ip;
31633 +
31634 + if (v8086_mode(regs))
31635 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31636 +
31637 +#ifdef CONFIG_PAX_PAGEEXEC
31638 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31639 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31640 + return true;
31641 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31642 + return true;
31643 + return false;
31644 + }
31645 +#endif
31646 +
31647 +#ifdef CONFIG_PAX_SEGMEXEC
31648 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31649 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31650 + return true;
31651 + return false;
31652 + }
31653 +#endif
31654 +
31655 + return false;
31656 +}
31657 +#endif
31658 +
31659 +#ifdef CONFIG_PAX_EMUTRAMP
31660 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31661 +{
31662 + int err;
31663 +
31664 + do { /* PaX: libffi trampoline emulation */
31665 + unsigned char mov, jmp;
31666 + unsigned int addr1, addr2;
31667 +
31668 +#ifdef CONFIG_X86_64
31669 + if ((regs->ip + 9) >> 32)
31670 + break;
31671 +#endif
31672 +
31673 + err = get_user(mov, (unsigned char __user *)regs->ip);
31674 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31675 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31676 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31677 +
31678 + if (err)
31679 + break;
31680 +
31681 + if (mov == 0xB8 && jmp == 0xE9) {
31682 + regs->ax = addr1;
31683 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31684 + return 2;
31685 + }
31686 + } while (0);
31687 +
31688 + do { /* PaX: gcc trampoline emulation #1 */
31689 + unsigned char mov1, mov2;
31690 + unsigned short jmp;
31691 + unsigned int addr1, addr2;
31692 +
31693 +#ifdef CONFIG_X86_64
31694 + if ((regs->ip + 11) >> 32)
31695 + break;
31696 +#endif
31697 +
31698 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31699 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31700 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31701 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31702 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31703 +
31704 + if (err)
31705 + break;
31706 +
31707 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31708 + regs->cx = addr1;
31709 + regs->ax = addr2;
31710 + regs->ip = addr2;
31711 + return 2;
31712 + }
31713 + } while (0);
31714 +
31715 + do { /* PaX: gcc trampoline emulation #2 */
31716 + unsigned char mov, jmp;
31717 + unsigned int addr1, addr2;
31718 +
31719 +#ifdef CONFIG_X86_64
31720 + if ((regs->ip + 9) >> 32)
31721 + break;
31722 +#endif
31723 +
31724 + err = get_user(mov, (unsigned char __user *)regs->ip);
31725 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31726 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31727 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31728 +
31729 + if (err)
31730 + break;
31731 +
31732 + if (mov == 0xB9 && jmp == 0xE9) {
31733 + regs->cx = addr1;
31734 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31735 + return 2;
31736 + }
31737 + } while (0);
31738 +
31739 + return 1; /* PaX in action */
31740 +}
31741 +
31742 +#ifdef CONFIG_X86_64
31743 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31744 +{
31745 + int err;
31746 +
31747 + do { /* PaX: libffi trampoline emulation */
31748 + unsigned short mov1, mov2, jmp1;
31749 + unsigned char stcclc, jmp2;
31750 + unsigned long addr1, addr2;
31751 +
31752 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31753 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31754 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31755 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31756 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31757 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31758 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31759 +
31760 + if (err)
31761 + break;
31762 +
31763 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31764 + regs->r11 = addr1;
31765 + regs->r10 = addr2;
31766 + if (stcclc == 0xF8)
31767 + regs->flags &= ~X86_EFLAGS_CF;
31768 + else
31769 + regs->flags |= X86_EFLAGS_CF;
31770 + regs->ip = addr1;
31771 + return 2;
31772 + }
31773 + } while (0);
31774 +
31775 + do { /* PaX: gcc trampoline emulation #1 */
31776 + unsigned short mov1, mov2, jmp1;
31777 + unsigned char jmp2;
31778 + unsigned int addr1;
31779 + unsigned long addr2;
31780 +
31781 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31782 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31783 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31784 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31785 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31786 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31787 +
31788 + if (err)
31789 + break;
31790 +
31791 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31792 + regs->r11 = addr1;
31793 + regs->r10 = addr2;
31794 + regs->ip = addr1;
31795 + return 2;
31796 + }
31797 + } while (0);
31798 +
31799 + do { /* PaX: gcc trampoline emulation #2 */
31800 + unsigned short mov1, mov2, jmp1;
31801 + unsigned char jmp2;
31802 + unsigned long addr1, addr2;
31803 +
31804 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31805 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31806 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31807 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31808 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31809 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31810 +
31811 + if (err)
31812 + break;
31813 +
31814 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31815 + regs->r11 = addr1;
31816 + regs->r10 = addr2;
31817 + regs->ip = addr1;
31818 + return 2;
31819 + }
31820 + } while (0);
31821 +
31822 + return 1; /* PaX in action */
31823 +}
31824 +#endif
31825 +
31826 +/*
31827 + * PaX: decide what to do with offenders (regs->ip = fault address)
31828 + *
31829 + * returns 1 when task should be killed
31830 + * 2 when gcc trampoline was detected
31831 + */
31832 +static int pax_handle_fetch_fault(struct pt_regs *regs)
31833 +{
31834 + if (v8086_mode(regs))
31835 + return 1;
31836 +
31837 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31838 + return 1;
31839 +
31840 +#ifdef CONFIG_X86_32
31841 + return pax_handle_fetch_fault_32(regs);
31842 +#else
31843 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31844 + return pax_handle_fetch_fault_32(regs);
31845 + else
31846 + return pax_handle_fetch_fault_64(regs);
31847 +#endif
31848 +}
31849 +#endif
31850 +
31851 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31852 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31853 +{
31854 + long i;
31855 +
31856 + printk(KERN_ERR "PAX: bytes at PC: ");
31857 + for (i = 0; i < 20; i++) {
31858 + unsigned char c;
31859 + if (get_user(c, (unsigned char __force_user *)pc+i))
31860 + printk(KERN_CONT "?? ");
31861 + else
31862 + printk(KERN_CONT "%02x ", c);
31863 + }
31864 + printk("\n");
31865 +
31866 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31867 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
31868 + unsigned long c;
31869 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
31870 +#ifdef CONFIG_X86_32
31871 + printk(KERN_CONT "???????? ");
31872 +#else
31873 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31874 + printk(KERN_CONT "???????? ???????? ");
31875 + else
31876 + printk(KERN_CONT "???????????????? ");
31877 +#endif
31878 + } else {
31879 +#ifdef CONFIG_X86_64
31880 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31881 + printk(KERN_CONT "%08x ", (unsigned int)c);
31882 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31883 + } else
31884 +#endif
31885 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31886 + }
31887 + }
31888 + printk("\n");
31889 +}
31890 +#endif
31891 +
31892 +/**
31893 + * probe_kernel_write(): safely attempt to write to a location
31894 + * @dst: address to write to
31895 + * @src: pointer to the data that shall be written
31896 + * @size: size of the data chunk
31897 + *
31898 + * Safely write to address @dst from the buffer at @src. If a kernel fault
31899 + * happens, handle that and return -EFAULT.
31900 + */
31901 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31902 +{
31903 + long ret;
31904 + mm_segment_t old_fs = get_fs();
31905 +
31906 + set_fs(KERNEL_DS);
31907 + pagefault_disable();
31908 + pax_open_kernel();
31909 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31910 + pax_close_kernel();
31911 + pagefault_enable();
31912 + set_fs(old_fs);
31913 +
31914 + return ret ? -EFAULT : 0;
31915 +}
31916 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31917 index 0596e8e..5626789 100644
31918 --- a/arch/x86/mm/gup.c
31919 +++ b/arch/x86/mm/gup.c
31920 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31921 addr = start;
31922 len = (unsigned long) nr_pages << PAGE_SHIFT;
31923 end = start + len;
31924 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31925 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31926 (void __user *)start, len)))
31927 return 0;
31928
31929 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31930 goto slow_irqon;
31931 #endif
31932
31933 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31934 + (void __user *)start, len)))
31935 + return 0;
31936 +
31937 /*
31938 * XXX: batch / limit 'nr', to avoid large irq off latency
31939 * needs some instrumenting to determine the common sizes used by
31940 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31941 index 4500142..53a363c 100644
31942 --- a/arch/x86/mm/highmem_32.c
31943 +++ b/arch/x86/mm/highmem_32.c
31944 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31945 idx = type + KM_TYPE_NR*smp_processor_id();
31946 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31947 BUG_ON(!pte_none(*(kmap_pte-idx)));
31948 +
31949 + pax_open_kernel();
31950 set_pte(kmap_pte-idx, mk_pte(page, prot));
31951 + pax_close_kernel();
31952 +
31953 arch_flush_lazy_mmu_mode();
31954
31955 return (void *)vaddr;
31956 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31957 index 9d980d8..6bbfacb 100644
31958 --- a/arch/x86/mm/hugetlbpage.c
31959 +++ b/arch/x86/mm/hugetlbpage.c
31960 @@ -92,23 +92,30 @@ int pmd_huge_support(void)
31961 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31962 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31963 unsigned long addr, unsigned long len,
31964 - unsigned long pgoff, unsigned long flags)
31965 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31966 {
31967 struct hstate *h = hstate_file(file);
31968 struct vm_unmapped_area_info info;
31969 -
31970 +
31971 info.flags = 0;
31972 info.length = len;
31973 info.low_limit = TASK_UNMAPPED_BASE;
31974 +
31975 +#ifdef CONFIG_PAX_RANDMMAP
31976 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31977 + info.low_limit += current->mm->delta_mmap;
31978 +#endif
31979 +
31980 info.high_limit = TASK_SIZE;
31981 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31982 info.align_offset = 0;
31983 + info.threadstack_offset = offset;
31984 return vm_unmapped_area(&info);
31985 }
31986
31987 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31988 unsigned long addr0, unsigned long len,
31989 - unsigned long pgoff, unsigned long flags)
31990 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31991 {
31992 struct hstate *h = hstate_file(file);
31993 struct vm_unmapped_area_info info;
31994 @@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31995 info.high_limit = current->mm->mmap_base;
31996 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31997 info.align_offset = 0;
31998 + info.threadstack_offset = offset;
31999 addr = vm_unmapped_area(&info);
32000
32001 /*
32002 @@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32003 VM_BUG_ON(addr != -ENOMEM);
32004 info.flags = 0;
32005 info.low_limit = TASK_UNMAPPED_BASE;
32006 +
32007 +#ifdef CONFIG_PAX_RANDMMAP
32008 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32009 + info.low_limit += current->mm->delta_mmap;
32010 +#endif
32011 +
32012 info.high_limit = TASK_SIZE;
32013 addr = vm_unmapped_area(&info);
32014 }
32015 @@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32016 struct hstate *h = hstate_file(file);
32017 struct mm_struct *mm = current->mm;
32018 struct vm_area_struct *vma;
32019 + unsigned long pax_task_size = TASK_SIZE;
32020 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32021
32022 if (len & ~huge_page_mask(h))
32023 return -EINVAL;
32024 - if (len > TASK_SIZE)
32025 +
32026 +#ifdef CONFIG_PAX_SEGMEXEC
32027 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32028 + pax_task_size = SEGMEXEC_TASK_SIZE;
32029 +#endif
32030 +
32031 + pax_task_size -= PAGE_SIZE;
32032 +
32033 + if (len > pax_task_size)
32034 return -ENOMEM;
32035
32036 if (flags & MAP_FIXED) {
32037 @@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32038 return addr;
32039 }
32040
32041 +#ifdef CONFIG_PAX_RANDMMAP
32042 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32043 +#endif
32044 +
32045 if (addr) {
32046 addr = ALIGN(addr, huge_page_size(h));
32047 vma = find_vma(mm, addr);
32048 - if (TASK_SIZE - len >= addr &&
32049 - (!vma || addr + len <= vma->vm_start))
32050 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32051 return addr;
32052 }
32053 if (mm->get_unmapped_area == arch_get_unmapped_area)
32054 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32055 - pgoff, flags);
32056 + pgoff, flags, offset);
32057 else
32058 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32059 - pgoff, flags);
32060 + pgoff, flags, offset);
32061 }
32062
32063 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
32064 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32065 index f971306..e83e0f6 100644
32066 --- a/arch/x86/mm/init.c
32067 +++ b/arch/x86/mm/init.c
32068 @@ -4,6 +4,7 @@
32069 #include <linux/swap.h>
32070 #include <linux/memblock.h>
32071 #include <linux/bootmem.h> /* for max_low_pfn */
32072 +#include <linux/tboot.h>
32073
32074 #include <asm/cacheflush.h>
32075 #include <asm/e820.h>
32076 @@ -17,6 +18,8 @@
32077 #include <asm/proto.h>
32078 #include <asm/dma.h> /* for MAX_DMA_PFN */
32079 #include <asm/microcode.h>
32080 +#include <asm/desc.h>
32081 +#include <asm/bios_ebda.h>
32082
32083 #include "mm_internal.h"
32084
32085 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32086 early_ioremap_page_table_range_init();
32087 #endif
32088
32089 +#ifdef CONFIG_PAX_PER_CPU_PGD
32090 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32091 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32092 + KERNEL_PGD_PTRS);
32093 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32094 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32095 + KERNEL_PGD_PTRS);
32096 + load_cr3(get_cpu_pgd(0, kernel));
32097 +#else
32098 load_cr3(swapper_pg_dir);
32099 +#endif
32100 +
32101 __flush_tlb_all();
32102
32103 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32104 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32105 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32106 * mmio resources as well as potential bios/acpi data regions.
32107 */
32108 +
32109 +#ifdef CONFIG_GRKERNSEC_KMEM
32110 +static unsigned int ebda_start __read_only;
32111 +static unsigned int ebda_end __read_only;
32112 +#endif
32113 +
32114 int devmem_is_allowed(unsigned long pagenr)
32115 {
32116 - if (pagenr < 256)
32117 +#ifdef CONFIG_GRKERNSEC_KMEM
32118 + /* allow BDA */
32119 + if (!pagenr)
32120 return 1;
32121 + /* allow EBDA */
32122 + if (pagenr >= ebda_start && pagenr < ebda_end)
32123 + return 1;
32124 + /* if tboot is in use, allow access to its hardcoded serial log range */
32125 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32126 + return 1;
32127 +#else
32128 + if (!pagenr)
32129 + return 1;
32130 +#ifdef CONFIG_VM86
32131 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32132 + return 1;
32133 +#endif
32134 +#endif
32135 +
32136 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32137 + return 1;
32138 +#ifdef CONFIG_GRKERNSEC_KMEM
32139 + /* throw out everything else below 1MB */
32140 + if (pagenr <= 256)
32141 + return 0;
32142 +#endif
32143 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32144 return 0;
32145 if (!page_is_ram(pagenr))
32146 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32147 #endif
32148 }
32149
32150 +#ifdef CONFIG_GRKERNSEC_KMEM
32151 +static inline void gr_init_ebda(void)
32152 +{
32153 + unsigned int ebda_addr;
32154 + unsigned int ebda_size = 0;
32155 +
32156 + ebda_addr = get_bios_ebda();
32157 + if (ebda_addr) {
32158 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32159 + ebda_size <<= 10;
32160 + }
32161 + if (ebda_addr && ebda_size) {
32162 + ebda_start = ebda_addr >> PAGE_SHIFT;
32163 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32164 + } else {
32165 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32166 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32167 + }
32168 +}
32169 +#else
32170 +static inline void gr_init_ebda(void) { }
32171 +#endif
32172 +
32173 void free_initmem(void)
32174 {
32175 +#ifdef CONFIG_PAX_KERNEXEC
32176 +#ifdef CONFIG_X86_32
32177 + /* PaX: limit KERNEL_CS to actual size */
32178 + unsigned long addr, limit;
32179 + struct desc_struct d;
32180 + int cpu;
32181 +#else
32182 + pgd_t *pgd;
32183 + pud_t *pud;
32184 + pmd_t *pmd;
32185 + unsigned long addr, end;
32186 +#endif
32187 +#endif
32188 +
32189 + gr_init_ebda();
32190 +
32191 +#ifdef CONFIG_PAX_KERNEXEC
32192 +#ifdef CONFIG_X86_32
32193 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32194 + limit = (limit - 1UL) >> PAGE_SHIFT;
32195 +
32196 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32197 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32198 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32199 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32200 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32201 + }
32202 +
32203 + /* PaX: make KERNEL_CS read-only */
32204 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32205 + if (!paravirt_enabled())
32206 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32207 +/*
32208 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32209 + pgd = pgd_offset_k(addr);
32210 + pud = pud_offset(pgd, addr);
32211 + pmd = pmd_offset(pud, addr);
32212 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32213 + }
32214 +*/
32215 +#ifdef CONFIG_X86_PAE
32216 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32217 +/*
32218 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32219 + pgd = pgd_offset_k(addr);
32220 + pud = pud_offset(pgd, addr);
32221 + pmd = pmd_offset(pud, addr);
32222 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32223 + }
32224 +*/
32225 +#endif
32226 +
32227 +#ifdef CONFIG_MODULES
32228 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32229 +#endif
32230 +
32231 +#else
32232 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32233 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32234 + pgd = pgd_offset_k(addr);
32235 + pud = pud_offset(pgd, addr);
32236 + pmd = pmd_offset(pud, addr);
32237 + if (!pmd_present(*pmd))
32238 + continue;
32239 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32240 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32241 + else
32242 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32243 + }
32244 +
32245 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32246 + end = addr + KERNEL_IMAGE_SIZE;
32247 + for (; addr < end; addr += PMD_SIZE) {
32248 + pgd = pgd_offset_k(addr);
32249 + pud = pud_offset(pgd, addr);
32250 + pmd = pmd_offset(pud, addr);
32251 + if (!pmd_present(*pmd))
32252 + continue;
32253 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32254 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32255 + }
32256 +#endif
32257 +
32258 + flush_tlb_all();
32259 +#endif
32260 +
32261 free_init_pages("unused kernel",
32262 (unsigned long)(&__init_begin),
32263 (unsigned long)(&__init_end));
32264 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32265 index 4287f1f..3b99c71 100644
32266 --- a/arch/x86/mm/init_32.c
32267 +++ b/arch/x86/mm/init_32.c
32268 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32269 bool __read_mostly __vmalloc_start_set = false;
32270
32271 /*
32272 - * Creates a middle page table and puts a pointer to it in the
32273 - * given global directory entry. This only returns the gd entry
32274 - * in non-PAE compilation mode, since the middle layer is folded.
32275 - */
32276 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32277 -{
32278 - pud_t *pud;
32279 - pmd_t *pmd_table;
32280 -
32281 -#ifdef CONFIG_X86_PAE
32282 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32283 - pmd_table = (pmd_t *)alloc_low_page();
32284 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32285 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32286 - pud = pud_offset(pgd, 0);
32287 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32288 -
32289 - return pmd_table;
32290 - }
32291 -#endif
32292 - pud = pud_offset(pgd, 0);
32293 - pmd_table = pmd_offset(pud, 0);
32294 -
32295 - return pmd_table;
32296 -}
32297 -
32298 -/*
32299 * Create a page table and place a pointer to it in a middle page
32300 * directory entry:
32301 */
32302 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32303 pte_t *page_table = (pte_t *)alloc_low_page();
32304
32305 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32306 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32307 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32308 +#else
32309 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32310 +#endif
32311 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32312 }
32313
32314 return pte_offset_kernel(pmd, 0);
32315 }
32316
32317 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32318 +{
32319 + pud_t *pud;
32320 + pmd_t *pmd_table;
32321 +
32322 + pud = pud_offset(pgd, 0);
32323 + pmd_table = pmd_offset(pud, 0);
32324 +
32325 + return pmd_table;
32326 +}
32327 +
32328 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32329 {
32330 int pgd_idx = pgd_index(vaddr);
32331 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32332 int pgd_idx, pmd_idx;
32333 unsigned long vaddr;
32334 pgd_t *pgd;
32335 + pud_t *pud;
32336 pmd_t *pmd;
32337 pte_t *pte = NULL;
32338 unsigned long count = page_table_range_init_count(start, end);
32339 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32340 pgd = pgd_base + pgd_idx;
32341
32342 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32343 - pmd = one_md_table_init(pgd);
32344 - pmd = pmd + pmd_index(vaddr);
32345 + pud = pud_offset(pgd, vaddr);
32346 + pmd = pmd_offset(pud, vaddr);
32347 +
32348 +#ifdef CONFIG_X86_PAE
32349 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32350 +#endif
32351 +
32352 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32353 pmd++, pmd_idx++) {
32354 pte = page_table_kmap_check(one_page_table_init(pmd),
32355 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32356 }
32357 }
32358
32359 -static inline int is_kernel_text(unsigned long addr)
32360 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32361 {
32362 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32363 - return 1;
32364 - return 0;
32365 + if ((start > ktla_ktva((unsigned long)_etext) ||
32366 + end <= ktla_ktva((unsigned long)_stext)) &&
32367 + (start > ktla_ktva((unsigned long)_einittext) ||
32368 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32369 +
32370 +#ifdef CONFIG_ACPI_SLEEP
32371 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32372 +#endif
32373 +
32374 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32375 + return 0;
32376 + return 1;
32377 }
32378
32379 /*
32380 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32381 unsigned long last_map_addr = end;
32382 unsigned long start_pfn, end_pfn;
32383 pgd_t *pgd_base = swapper_pg_dir;
32384 - int pgd_idx, pmd_idx, pte_ofs;
32385 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32386 unsigned long pfn;
32387 pgd_t *pgd;
32388 + pud_t *pud;
32389 pmd_t *pmd;
32390 pte_t *pte;
32391 unsigned pages_2m, pages_4k;
32392 @@ -291,8 +295,13 @@ repeat:
32393 pfn = start_pfn;
32394 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32395 pgd = pgd_base + pgd_idx;
32396 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32397 - pmd = one_md_table_init(pgd);
32398 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32399 + pud = pud_offset(pgd, 0);
32400 + pmd = pmd_offset(pud, 0);
32401 +
32402 +#ifdef CONFIG_X86_PAE
32403 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32404 +#endif
32405
32406 if (pfn >= end_pfn)
32407 continue;
32408 @@ -304,14 +313,13 @@ repeat:
32409 #endif
32410 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32411 pmd++, pmd_idx++) {
32412 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32413 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32414
32415 /*
32416 * Map with big pages if possible, otherwise
32417 * create normal page tables:
32418 */
32419 if (use_pse) {
32420 - unsigned int addr2;
32421 pgprot_t prot = PAGE_KERNEL_LARGE;
32422 /*
32423 * first pass will use the same initial
32424 @@ -322,11 +330,7 @@ repeat:
32425 _PAGE_PSE);
32426
32427 pfn &= PMD_MASK >> PAGE_SHIFT;
32428 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32429 - PAGE_OFFSET + PAGE_SIZE-1;
32430 -
32431 - if (is_kernel_text(addr) ||
32432 - is_kernel_text(addr2))
32433 + if (is_kernel_text(address, address + PMD_SIZE))
32434 prot = PAGE_KERNEL_LARGE_EXEC;
32435
32436 pages_2m++;
32437 @@ -343,7 +347,7 @@ repeat:
32438 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32439 pte += pte_ofs;
32440 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32441 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32442 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32443 pgprot_t prot = PAGE_KERNEL;
32444 /*
32445 * first pass will use the same initial
32446 @@ -351,7 +355,7 @@ repeat:
32447 */
32448 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32449
32450 - if (is_kernel_text(addr))
32451 + if (is_kernel_text(address, address + PAGE_SIZE))
32452 prot = PAGE_KERNEL_EXEC;
32453
32454 pages_4k++;
32455 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32456
32457 pud = pud_offset(pgd, va);
32458 pmd = pmd_offset(pud, va);
32459 - if (!pmd_present(*pmd))
32460 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32461 break;
32462
32463 /* should not be large page here */
32464 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32465
32466 static void __init pagetable_init(void)
32467 {
32468 - pgd_t *pgd_base = swapper_pg_dir;
32469 -
32470 - permanent_kmaps_init(pgd_base);
32471 + permanent_kmaps_init(swapper_pg_dir);
32472 }
32473
32474 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32475 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32476 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32477
32478 /* user-defined highmem size */
32479 @@ -787,10 +789,10 @@ void __init mem_init(void)
32480 ((unsigned long)&__init_end -
32481 (unsigned long)&__init_begin) >> 10,
32482
32483 - (unsigned long)&_etext, (unsigned long)&_edata,
32484 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32485 + (unsigned long)&_sdata, (unsigned long)&_edata,
32486 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32487
32488 - (unsigned long)&_text, (unsigned long)&_etext,
32489 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32490 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32491
32492 /*
32493 @@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
32494 if (!kernel_set_to_readonly)
32495 return;
32496
32497 + start = ktla_ktva(start);
32498 pr_debug("Set kernel text: %lx - %lx for read write\n",
32499 start, start+size);
32500
32501 @@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
32502 if (!kernel_set_to_readonly)
32503 return;
32504
32505 + start = ktla_ktva(start);
32506 pr_debug("Set kernel text: %lx - %lx for read only\n",
32507 start, start+size);
32508
32509 @@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32510 unsigned long start = PFN_ALIGN(_text);
32511 unsigned long size = PFN_ALIGN(_etext) - start;
32512
32513 + start = ktla_ktva(start);
32514 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32515 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32516 size >> 10);
32517 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32518 index 104d56a..62ba13f1 100644
32519 --- a/arch/x86/mm/init_64.c
32520 +++ b/arch/x86/mm/init_64.c
32521 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32522 * around without checking the pgd every time.
32523 */
32524
32525 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32526 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32527 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32528
32529 int force_personality32;
32530 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32531
32532 for (address = start; address <= end; address += PGDIR_SIZE) {
32533 const pgd_t *pgd_ref = pgd_offset_k(address);
32534 +
32535 +#ifdef CONFIG_PAX_PER_CPU_PGD
32536 + unsigned long cpu;
32537 +#else
32538 struct page *page;
32539 +#endif
32540
32541 if (pgd_none(*pgd_ref))
32542 continue;
32543
32544 spin_lock(&pgd_lock);
32545 +
32546 +#ifdef CONFIG_PAX_PER_CPU_PGD
32547 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32548 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32549 +
32550 + if (pgd_none(*pgd))
32551 + set_pgd(pgd, *pgd_ref);
32552 + else
32553 + BUG_ON(pgd_page_vaddr(*pgd)
32554 + != pgd_page_vaddr(*pgd_ref));
32555 + pgd = pgd_offset_cpu(cpu, kernel, address);
32556 +#else
32557 list_for_each_entry(page, &pgd_list, lru) {
32558 pgd_t *pgd;
32559 spinlock_t *pgt_lock;
32560 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32561 /* the pgt_lock only for Xen */
32562 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32563 spin_lock(pgt_lock);
32564 +#endif
32565
32566 if (pgd_none(*pgd))
32567 set_pgd(pgd, *pgd_ref);
32568 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32569 BUG_ON(pgd_page_vaddr(*pgd)
32570 != pgd_page_vaddr(*pgd_ref));
32571
32572 +#ifndef CONFIG_PAX_PER_CPU_PGD
32573 spin_unlock(pgt_lock);
32574 +#endif
32575 +
32576 }
32577 spin_unlock(&pgd_lock);
32578 }
32579 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32580 {
32581 if (pgd_none(*pgd)) {
32582 pud_t *pud = (pud_t *)spp_getpage();
32583 - pgd_populate(&init_mm, pgd, pud);
32584 + pgd_populate_kernel(&init_mm, pgd, pud);
32585 if (pud != pud_offset(pgd, 0))
32586 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32587 pud, pud_offset(pgd, 0));
32588 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32589 {
32590 if (pud_none(*pud)) {
32591 pmd_t *pmd = (pmd_t *) spp_getpage();
32592 - pud_populate(&init_mm, pud, pmd);
32593 + pud_populate_kernel(&init_mm, pud, pmd);
32594 if (pmd != pmd_offset(pud, 0))
32595 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32596 pmd, pmd_offset(pud, 0));
32597 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32598 pmd = fill_pmd(pud, vaddr);
32599 pte = fill_pte(pmd, vaddr);
32600
32601 + pax_open_kernel();
32602 set_pte(pte, new_pte);
32603 + pax_close_kernel();
32604
32605 /*
32606 * It's enough to flush this one mapping.
32607 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32608 pgd = pgd_offset_k((unsigned long)__va(phys));
32609 if (pgd_none(*pgd)) {
32610 pud = (pud_t *) spp_getpage();
32611 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32612 - _PAGE_USER));
32613 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32614 }
32615 pud = pud_offset(pgd, (unsigned long)__va(phys));
32616 if (pud_none(*pud)) {
32617 pmd = (pmd_t *) spp_getpage();
32618 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32619 - _PAGE_USER));
32620 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32621 }
32622 pmd = pmd_offset(pud, phys);
32623 BUG_ON(!pmd_none(*pmd));
32624 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32625 prot);
32626
32627 spin_lock(&init_mm.page_table_lock);
32628 - pud_populate(&init_mm, pud, pmd);
32629 + pud_populate_kernel(&init_mm, pud, pmd);
32630 spin_unlock(&init_mm.page_table_lock);
32631 }
32632 __flush_tlb_all();
32633 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32634 page_size_mask);
32635
32636 spin_lock(&init_mm.page_table_lock);
32637 - pgd_populate(&init_mm, pgd, pud);
32638 + pgd_populate_kernel(&init_mm, pgd, pud);
32639 spin_unlock(&init_mm.page_table_lock);
32640 pgd_changed = true;
32641 }
32642 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32643 static struct vm_area_struct gate_vma = {
32644 .vm_start = VSYSCALL_START,
32645 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32646 - .vm_page_prot = PAGE_READONLY_EXEC,
32647 - .vm_flags = VM_READ | VM_EXEC
32648 + .vm_page_prot = PAGE_READONLY,
32649 + .vm_flags = VM_READ
32650 };
32651
32652 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32653 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32654
32655 const char *arch_vma_name(struct vm_area_struct *vma)
32656 {
32657 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32658 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32659 return "[vdso]";
32660 if (vma == &gate_vma)
32661 return "[vsyscall]";
32662 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32663 index 7b179b4..6bd17777 100644
32664 --- a/arch/x86/mm/iomap_32.c
32665 +++ b/arch/x86/mm/iomap_32.c
32666 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32667 type = kmap_atomic_idx_push();
32668 idx = type + KM_TYPE_NR * smp_processor_id();
32669 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32670 +
32671 + pax_open_kernel();
32672 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32673 + pax_close_kernel();
32674 +
32675 arch_flush_lazy_mmu_mode();
32676
32677 return (void *)vaddr;
32678 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32679 index 799580c..72f9fe0 100644
32680 --- a/arch/x86/mm/ioremap.c
32681 +++ b/arch/x86/mm/ioremap.c
32682 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32683 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32684 int is_ram = page_is_ram(pfn);
32685
32686 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32687 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32688 return NULL;
32689 WARN_ON_ONCE(is_ram);
32690 }
32691 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32692 *
32693 * Caller must ensure there is only one unmapping for the same pointer.
32694 */
32695 -void iounmap(volatile void __iomem *addr)
32696 +void iounmap(const volatile void __iomem *addr)
32697 {
32698 struct vm_struct *p, *o;
32699
32700 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32701
32702 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32703 if (page_is_ram(start >> PAGE_SHIFT))
32704 +#ifdef CONFIG_HIGHMEM
32705 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32706 +#endif
32707 return __va(phys);
32708
32709 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32710 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32711 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32712 {
32713 if (page_is_ram(phys >> PAGE_SHIFT))
32714 +#ifdef CONFIG_HIGHMEM
32715 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32716 +#endif
32717 return;
32718
32719 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32720 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32721 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32722
32723 static __initdata int after_paging_init;
32724 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32725 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32726
32727 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32728 {
32729 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32730 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32731
32732 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32733 - memset(bm_pte, 0, sizeof(bm_pte));
32734 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32735 + pmd_populate_user(&init_mm, pmd, bm_pte);
32736
32737 /*
32738 * The boot-ioremap range spans multiple pmds, for which
32739 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32740 index d87dd6d..bf3fa66 100644
32741 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32742 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32743 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32744 * memory (e.g. tracked pages)? For now, we need this to avoid
32745 * invoking kmemcheck for PnP BIOS calls.
32746 */
32747 - if (regs->flags & X86_VM_MASK)
32748 + if (v8086_mode(regs))
32749 return false;
32750 - if (regs->cs != __KERNEL_CS)
32751 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32752 return false;
32753
32754 pte = kmemcheck_pte_lookup(address);
32755 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32756 index 25e7e13..1964579 100644
32757 --- a/arch/x86/mm/mmap.c
32758 +++ b/arch/x86/mm/mmap.c
32759 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32760 * Leave an at least ~128 MB hole with possible stack randomization.
32761 */
32762 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32763 -#define MAX_GAP (TASK_SIZE/6*5)
32764 +#define MAX_GAP (pax_task_size/6*5)
32765
32766 static int mmap_is_legacy(void)
32767 {
32768 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32769 return rnd << PAGE_SHIFT;
32770 }
32771
32772 -static unsigned long mmap_base(void)
32773 +static unsigned long mmap_base(struct mm_struct *mm)
32774 {
32775 unsigned long gap = rlimit(RLIMIT_STACK);
32776 + unsigned long pax_task_size = TASK_SIZE;
32777 +
32778 +#ifdef CONFIG_PAX_SEGMEXEC
32779 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32780 + pax_task_size = SEGMEXEC_TASK_SIZE;
32781 +#endif
32782
32783 if (gap < MIN_GAP)
32784 gap = MIN_GAP;
32785 else if (gap > MAX_GAP)
32786 gap = MAX_GAP;
32787
32788 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32789 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32790 }
32791
32792 /*
32793 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32794 * does, but not when emulating X86_32
32795 */
32796 -static unsigned long mmap_legacy_base(void)
32797 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32798 {
32799 - if (mmap_is_ia32())
32800 + if (mmap_is_ia32()) {
32801 +
32802 +#ifdef CONFIG_PAX_SEGMEXEC
32803 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32804 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32805 + else
32806 +#endif
32807 +
32808 return TASK_UNMAPPED_BASE;
32809 - else
32810 + } else
32811 return TASK_UNMAPPED_BASE + mmap_rnd();
32812 }
32813
32814 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32815 */
32816 void arch_pick_mmap_layout(struct mm_struct *mm)
32817 {
32818 - mm->mmap_legacy_base = mmap_legacy_base();
32819 - mm->mmap_base = mmap_base();
32820 + mm->mmap_legacy_base = mmap_legacy_base(mm);
32821 + mm->mmap_base = mmap_base(mm);
32822 +
32823 +#ifdef CONFIG_PAX_RANDMMAP
32824 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
32825 + mm->mmap_legacy_base += mm->delta_mmap;
32826 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32827 + }
32828 +#endif
32829
32830 if (mmap_is_legacy()) {
32831 mm->mmap_base = mm->mmap_legacy_base;
32832 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32833 index 0057a7a..95c7edd 100644
32834 --- a/arch/x86/mm/mmio-mod.c
32835 +++ b/arch/x86/mm/mmio-mod.c
32836 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32837 break;
32838 default:
32839 {
32840 - unsigned char *ip = (unsigned char *)instptr;
32841 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32842 my_trace->opcode = MMIO_UNKNOWN_OP;
32843 my_trace->width = 0;
32844 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32845 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32846 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32847 void __iomem *addr)
32848 {
32849 - static atomic_t next_id;
32850 + static atomic_unchecked_t next_id;
32851 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32852 /* These are page-unaligned. */
32853 struct mmiotrace_map map = {
32854 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32855 .private = trace
32856 },
32857 .phys = offset,
32858 - .id = atomic_inc_return(&next_id)
32859 + .id = atomic_inc_return_unchecked(&next_id)
32860 };
32861 map.map_id = trace->id;
32862
32863 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32864 ioremap_trace_core(offset, size, addr);
32865 }
32866
32867 -static void iounmap_trace_core(volatile void __iomem *addr)
32868 +static void iounmap_trace_core(const volatile void __iomem *addr)
32869 {
32870 struct mmiotrace_map map = {
32871 .phys = 0,
32872 @@ -328,7 +328,7 @@ not_enabled:
32873 }
32874 }
32875
32876 -void mmiotrace_iounmap(volatile void __iomem *addr)
32877 +void mmiotrace_iounmap(const volatile void __iomem *addr)
32878 {
32879 might_sleep();
32880 if (is_enabled()) /* recheck and proper locking in *_core() */
32881 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32882 index 24aec58..c39fe8b 100644
32883 --- a/arch/x86/mm/numa.c
32884 +++ b/arch/x86/mm/numa.c
32885 @@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32886 return true;
32887 }
32888
32889 -static int __init numa_register_memblks(struct numa_meminfo *mi)
32890 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32891 {
32892 unsigned long uninitialized_var(pfn_align);
32893 int i, nid;
32894 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32895 index d0b1773..4c3327c 100644
32896 --- a/arch/x86/mm/pageattr-test.c
32897 +++ b/arch/x86/mm/pageattr-test.c
32898 @@ -36,7 +36,7 @@ enum {
32899
32900 static int pte_testbit(pte_t pte)
32901 {
32902 - return pte_flags(pte) & _PAGE_UNUSED1;
32903 + return pte_flags(pte) & _PAGE_CPA_TEST;
32904 }
32905
32906 struct split_state {
32907 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32908 index bb32480..75f2f5e 100644
32909 --- a/arch/x86/mm/pageattr.c
32910 +++ b/arch/x86/mm/pageattr.c
32911 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32912 */
32913 #ifdef CONFIG_PCI_BIOS
32914 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32915 - pgprot_val(forbidden) |= _PAGE_NX;
32916 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32917 #endif
32918
32919 /*
32920 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32921 * Does not cover __inittext since that is gone later on. On
32922 * 64bit we do not enforce !NX on the low mapping
32923 */
32924 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
32925 - pgprot_val(forbidden) |= _PAGE_NX;
32926 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32927 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32928
32929 +#ifdef CONFIG_DEBUG_RODATA
32930 /*
32931 * The .rodata section needs to be read-only. Using the pfn
32932 * catches all aliases.
32933 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32934 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32935 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32936 pgprot_val(forbidden) |= _PAGE_RW;
32937 +#endif
32938
32939 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32940 /*
32941 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32942 }
32943 #endif
32944
32945 +#ifdef CONFIG_PAX_KERNEXEC
32946 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32947 + pgprot_val(forbidden) |= _PAGE_RW;
32948 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32949 + }
32950 +#endif
32951 +
32952 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32953
32954 return prot;
32955 @@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32956 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32957 {
32958 /* change init_mm */
32959 + pax_open_kernel();
32960 set_pte_atomic(kpte, pte);
32961 +
32962 #ifdef CONFIG_X86_32
32963 if (!SHARED_KERNEL_PMD) {
32964 +
32965 +#ifdef CONFIG_PAX_PER_CPU_PGD
32966 + unsigned long cpu;
32967 +#else
32968 struct page *page;
32969 +#endif
32970
32971 +#ifdef CONFIG_PAX_PER_CPU_PGD
32972 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32973 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32974 +#else
32975 list_for_each_entry(page, &pgd_list, lru) {
32976 - pgd_t *pgd;
32977 + pgd_t *pgd = (pgd_t *)page_address(page);
32978 +#endif
32979 +
32980 pud_t *pud;
32981 pmd_t *pmd;
32982
32983 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
32984 + pgd += pgd_index(address);
32985 pud = pud_offset(pgd, address);
32986 pmd = pmd_offset(pud, address);
32987 set_pte_atomic((pte_t *)pmd, pte);
32988 }
32989 }
32990 #endif
32991 + pax_close_kernel();
32992 }
32993
32994 static int
32995 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32996 index 6574388..87e9bef 100644
32997 --- a/arch/x86/mm/pat.c
32998 +++ b/arch/x86/mm/pat.c
32999 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33000
33001 if (!entry) {
33002 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33003 - current->comm, current->pid, start, end - 1);
33004 + current->comm, task_pid_nr(current), start, end - 1);
33005 return -EINVAL;
33006 }
33007
33008 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33009
33010 while (cursor < to) {
33011 if (!devmem_is_allowed(pfn)) {
33012 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33013 - current->comm, from, to - 1);
33014 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33015 + current->comm, from, to - 1, cursor);
33016 return 0;
33017 }
33018 cursor += PAGE_SIZE;
33019 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33020 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33021 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33022 "for [mem %#010Lx-%#010Lx]\n",
33023 - current->comm, current->pid,
33024 + current->comm, task_pid_nr(current),
33025 cattr_name(flags),
33026 base, (unsigned long long)(base + size-1));
33027 return -EINVAL;
33028 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33029 flags = lookup_memtype(paddr);
33030 if (want_flags != flags) {
33031 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33032 - current->comm, current->pid,
33033 + current->comm, task_pid_nr(current),
33034 cattr_name(want_flags),
33035 (unsigned long long)paddr,
33036 (unsigned long long)(paddr + size - 1),
33037 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33038 free_memtype(paddr, paddr + size);
33039 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33040 " for [mem %#010Lx-%#010Lx], got %s\n",
33041 - current->comm, current->pid,
33042 + current->comm, task_pid_nr(current),
33043 cattr_name(want_flags),
33044 (unsigned long long)paddr,
33045 (unsigned long long)(paddr + size - 1),
33046 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33047 index 415f6c4..d319983 100644
33048 --- a/arch/x86/mm/pat_rbtree.c
33049 +++ b/arch/x86/mm/pat_rbtree.c
33050 @@ -160,7 +160,7 @@ success:
33051
33052 failure:
33053 printk(KERN_INFO "%s:%d conflicting memory types "
33054 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33055 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33056 end, cattr_name(found_type), cattr_name(match->type));
33057 return -EBUSY;
33058 }
33059 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33060 index 9f0614d..92ae64a 100644
33061 --- a/arch/x86/mm/pf_in.c
33062 +++ b/arch/x86/mm/pf_in.c
33063 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33064 int i;
33065 enum reason_type rv = OTHERS;
33066
33067 - p = (unsigned char *)ins_addr;
33068 + p = (unsigned char *)ktla_ktva(ins_addr);
33069 p += skip_prefix(p, &prf);
33070 p += get_opcode(p, &opcode);
33071
33072 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33073 struct prefix_bits prf;
33074 int i;
33075
33076 - p = (unsigned char *)ins_addr;
33077 + p = (unsigned char *)ktla_ktva(ins_addr);
33078 p += skip_prefix(p, &prf);
33079 p += get_opcode(p, &opcode);
33080
33081 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33082 struct prefix_bits prf;
33083 int i;
33084
33085 - p = (unsigned char *)ins_addr;
33086 + p = (unsigned char *)ktla_ktva(ins_addr);
33087 p += skip_prefix(p, &prf);
33088 p += get_opcode(p, &opcode);
33089
33090 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33091 struct prefix_bits prf;
33092 int i;
33093
33094 - p = (unsigned char *)ins_addr;
33095 + p = (unsigned char *)ktla_ktva(ins_addr);
33096 p += skip_prefix(p, &prf);
33097 p += get_opcode(p, &opcode);
33098 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33099 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33100 struct prefix_bits prf;
33101 int i;
33102
33103 - p = (unsigned char *)ins_addr;
33104 + p = (unsigned char *)ktla_ktva(ins_addr);
33105 p += skip_prefix(p, &prf);
33106 p += get_opcode(p, &opcode);
33107 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33108 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33109 index c96314a..433b127 100644
33110 --- a/arch/x86/mm/pgtable.c
33111 +++ b/arch/x86/mm/pgtable.c
33112 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33113 list_del(&page->lru);
33114 }
33115
33116 -#define UNSHARED_PTRS_PER_PGD \
33117 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33118 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33119 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33120
33121 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33122 +{
33123 + unsigned int count = USER_PGD_PTRS;
33124
33125 + if (!pax_user_shadow_base)
33126 + return;
33127 +
33128 + while (count--)
33129 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33130 +}
33131 +#endif
33132 +
33133 +#ifdef CONFIG_PAX_PER_CPU_PGD
33134 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33135 +{
33136 + unsigned int count = USER_PGD_PTRS;
33137 +
33138 + while (count--) {
33139 + pgd_t pgd;
33140 +
33141 +#ifdef CONFIG_X86_64
33142 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33143 +#else
33144 + pgd = *src++;
33145 +#endif
33146 +
33147 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33148 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33149 +#endif
33150 +
33151 + *dst++ = pgd;
33152 + }
33153 +
33154 +}
33155 +#endif
33156 +
33157 +#ifdef CONFIG_X86_64
33158 +#define pxd_t pud_t
33159 +#define pyd_t pgd_t
33160 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33161 +#define pgtable_pxd_page_ctor(page) true
33162 +#define pgtable_pxd_page_dtor(page)
33163 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33164 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33165 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33166 +#define PYD_SIZE PGDIR_SIZE
33167 +#else
33168 +#define pxd_t pmd_t
33169 +#define pyd_t pud_t
33170 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33171 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33172 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33173 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33174 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33175 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33176 +#define PYD_SIZE PUD_SIZE
33177 +#endif
33178 +
33179 +#ifdef CONFIG_PAX_PER_CPU_PGD
33180 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33181 +static inline void pgd_dtor(pgd_t *pgd) {}
33182 +#else
33183 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33184 {
33185 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33186 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33187 pgd_list_del(pgd);
33188 spin_unlock(&pgd_lock);
33189 }
33190 +#endif
33191
33192 /*
33193 * List of all pgd's needed for non-PAE so it can invalidate entries
33194 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33195 * -- nyc
33196 */
33197
33198 -#ifdef CONFIG_X86_PAE
33199 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33200 /*
33201 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33202 * updating the top-level pagetable entries to guarantee the
33203 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33204 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33205 * and initialize the kernel pmds here.
33206 */
33207 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33208 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33209
33210 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33211 {
33212 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33213 */
33214 flush_tlb_mm(mm);
33215 }
33216 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33217 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33218 #else /* !CONFIG_X86_PAE */
33219
33220 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33221 -#define PREALLOCATED_PMDS 0
33222 +#define PREALLOCATED_PXDS 0
33223
33224 #endif /* CONFIG_X86_PAE */
33225
33226 -static void free_pmds(pmd_t *pmds[])
33227 +static void free_pxds(pxd_t *pxds[])
33228 {
33229 int i;
33230
33231 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33232 - if (pmds[i]) {
33233 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33234 - free_page((unsigned long)pmds[i]);
33235 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33236 + if (pxds[i]) {
33237 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33238 + free_page((unsigned long)pxds[i]);
33239 }
33240 }
33241
33242 -static int preallocate_pmds(pmd_t *pmds[])
33243 +static int preallocate_pxds(pxd_t *pxds[])
33244 {
33245 int i;
33246 bool failed = false;
33247
33248 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33249 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33250 - if (!pmd)
33251 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33252 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33253 + if (!pxd)
33254 failed = true;
33255 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33256 - free_page((unsigned long)pmd);
33257 - pmd = NULL;
33258 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33259 + free_page((unsigned long)pxd);
33260 + pxd = NULL;
33261 failed = true;
33262 }
33263 - pmds[i] = pmd;
33264 + pxds[i] = pxd;
33265 }
33266
33267 if (failed) {
33268 - free_pmds(pmds);
33269 + free_pxds(pxds);
33270 return -ENOMEM;
33271 }
33272
33273 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33274 * preallocate which never got a corresponding vma will need to be
33275 * freed manually.
33276 */
33277 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33278 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33279 {
33280 int i;
33281
33282 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33283 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33284 pgd_t pgd = pgdp[i];
33285
33286 if (pgd_val(pgd) != 0) {
33287 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33288 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33289
33290 - pgdp[i] = native_make_pgd(0);
33291 + set_pgd(pgdp + i, native_make_pgd(0));
33292
33293 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33294 - pmd_free(mm, pmd);
33295 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33296 + pxd_free(mm, pxd);
33297 }
33298 }
33299 }
33300
33301 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33302 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33303 {
33304 - pud_t *pud;
33305 + pyd_t *pyd;
33306 int i;
33307
33308 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33309 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33310 return;
33311
33312 - pud = pud_offset(pgd, 0);
33313 -
33314 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33315 - pmd_t *pmd = pmds[i];
33316 +#ifdef CONFIG_X86_64
33317 + pyd = pyd_offset(mm, 0L);
33318 +#else
33319 + pyd = pyd_offset(pgd, 0L);
33320 +#endif
33321
33322 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33323 + pxd_t *pxd = pxds[i];
33324 if (i >= KERNEL_PGD_BOUNDARY)
33325 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33326 - sizeof(pmd_t) * PTRS_PER_PMD);
33327 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33328 + sizeof(pxd_t) * PTRS_PER_PMD);
33329
33330 - pud_populate(mm, pud, pmd);
33331 + pyd_populate(mm, pyd, pxd);
33332 }
33333 }
33334
33335 pgd_t *pgd_alloc(struct mm_struct *mm)
33336 {
33337 pgd_t *pgd;
33338 - pmd_t *pmds[PREALLOCATED_PMDS];
33339 + pxd_t *pxds[PREALLOCATED_PXDS];
33340
33341 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33342
33343 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33344
33345 mm->pgd = pgd;
33346
33347 - if (preallocate_pmds(pmds) != 0)
33348 + if (preallocate_pxds(pxds) != 0)
33349 goto out_free_pgd;
33350
33351 if (paravirt_pgd_alloc(mm) != 0)
33352 - goto out_free_pmds;
33353 + goto out_free_pxds;
33354
33355 /*
33356 * Make sure that pre-populating the pmds is atomic with
33357 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33358 spin_lock(&pgd_lock);
33359
33360 pgd_ctor(mm, pgd);
33361 - pgd_prepopulate_pmd(mm, pgd, pmds);
33362 + pgd_prepopulate_pxd(mm, pgd, pxds);
33363
33364 spin_unlock(&pgd_lock);
33365
33366 return pgd;
33367
33368 -out_free_pmds:
33369 - free_pmds(pmds);
33370 +out_free_pxds:
33371 + free_pxds(pxds);
33372 out_free_pgd:
33373 free_page((unsigned long)pgd);
33374 out:
33375 @@ -313,7 +380,7 @@ out:
33376
33377 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33378 {
33379 - pgd_mop_up_pmds(mm, pgd);
33380 + pgd_mop_up_pxds(mm, pgd);
33381 pgd_dtor(pgd);
33382 paravirt_pgd_free(mm, pgd);
33383 free_page((unsigned long)pgd);
33384 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33385 index a69bcb8..19068ab 100644
33386 --- a/arch/x86/mm/pgtable_32.c
33387 +++ b/arch/x86/mm/pgtable_32.c
33388 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33389 return;
33390 }
33391 pte = pte_offset_kernel(pmd, vaddr);
33392 +
33393 + pax_open_kernel();
33394 if (pte_val(pteval))
33395 set_pte_at(&init_mm, vaddr, pte, pteval);
33396 else
33397 pte_clear(&init_mm, vaddr, pte);
33398 + pax_close_kernel();
33399
33400 /*
33401 * It's enough to flush this one mapping.
33402 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33403 index e666cbb..61788c45 100644
33404 --- a/arch/x86/mm/physaddr.c
33405 +++ b/arch/x86/mm/physaddr.c
33406 @@ -10,7 +10,7 @@
33407 #ifdef CONFIG_X86_64
33408
33409 #ifdef CONFIG_DEBUG_VIRTUAL
33410 -unsigned long __phys_addr(unsigned long x)
33411 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33412 {
33413 unsigned long y = x - __START_KERNEL_map;
33414
33415 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33416 #else
33417
33418 #ifdef CONFIG_DEBUG_VIRTUAL
33419 -unsigned long __phys_addr(unsigned long x)
33420 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33421 {
33422 unsigned long phys_addr = x - PAGE_OFFSET;
33423 /* VMALLOC_* aren't constants */
33424 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33425 index 90555bf..f5f1828 100644
33426 --- a/arch/x86/mm/setup_nx.c
33427 +++ b/arch/x86/mm/setup_nx.c
33428 @@ -5,8 +5,10 @@
33429 #include <asm/pgtable.h>
33430 #include <asm/proto.h>
33431
33432 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33433 static int disable_nx;
33434
33435 +#ifndef CONFIG_PAX_PAGEEXEC
33436 /*
33437 * noexec = on|off
33438 *
33439 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33440 return 0;
33441 }
33442 early_param("noexec", noexec_setup);
33443 +#endif
33444 +
33445 +#endif
33446
33447 void x86_configure_nx(void)
33448 {
33449 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33450 if (cpu_has_nx && !disable_nx)
33451 __supported_pte_mask |= _PAGE_NX;
33452 else
33453 +#endif
33454 __supported_pte_mask &= ~_PAGE_NX;
33455 }
33456
33457 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33458 index ae699b3..f1b2ad2 100644
33459 --- a/arch/x86/mm/tlb.c
33460 +++ b/arch/x86/mm/tlb.c
33461 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33462 BUG();
33463 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33464 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33465 +
33466 +#ifndef CONFIG_PAX_PER_CPU_PGD
33467 load_cr3(swapper_pg_dir);
33468 +#endif
33469 +
33470 }
33471 }
33472 EXPORT_SYMBOL_GPL(leave_mm);
33473 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33474 new file mode 100644
33475 index 0000000..dace51c
33476 --- /dev/null
33477 +++ b/arch/x86/mm/uderef_64.c
33478 @@ -0,0 +1,37 @@
33479 +#include <linux/mm.h>
33480 +#include <asm/pgtable.h>
33481 +#include <asm/uaccess.h>
33482 +
33483 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33484 +/* PaX: due to the special call convention these functions must
33485 + * - remain leaf functions under all configurations,
33486 + * - never be called directly, only dereferenced from the wrappers.
33487 + */
33488 +void __pax_open_userland(void)
33489 +{
33490 + unsigned int cpu;
33491 +
33492 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33493 + return;
33494 +
33495 + cpu = raw_get_cpu();
33496 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33497 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33498 + raw_put_cpu_no_resched();
33499 +}
33500 +EXPORT_SYMBOL(__pax_open_userland);
33501 +
33502 +void __pax_close_userland(void)
33503 +{
33504 + unsigned int cpu;
33505 +
33506 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33507 + return;
33508 +
33509 + cpu = raw_get_cpu();
33510 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33511 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33512 + raw_put_cpu_no_resched();
33513 +}
33514 +EXPORT_SYMBOL(__pax_close_userland);
33515 +#endif
33516 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33517 index 877b9a1..f746de8 100644
33518 --- a/arch/x86/net/bpf_jit.S
33519 +++ b/arch/x86/net/bpf_jit.S
33520 @@ -9,6 +9,7 @@
33521 */
33522 #include <linux/linkage.h>
33523 #include <asm/dwarf2.h>
33524 +#include <asm/alternative-asm.h>
33525
33526 /*
33527 * Calling convention :
33528 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33529 jle bpf_slow_path_word
33530 mov (SKBDATA,%rsi),%eax
33531 bswap %eax /* ntohl() */
33532 + pax_force_retaddr
33533 ret
33534
33535 sk_load_half:
33536 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33537 jle bpf_slow_path_half
33538 movzwl (SKBDATA,%rsi),%eax
33539 rol $8,%ax # ntohs()
33540 + pax_force_retaddr
33541 ret
33542
33543 sk_load_byte:
33544 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33545 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33546 jle bpf_slow_path_byte
33547 movzbl (SKBDATA,%rsi),%eax
33548 + pax_force_retaddr
33549 ret
33550
33551 /**
33552 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33553 movzbl (SKBDATA,%rsi),%ebx
33554 and $15,%bl
33555 shl $2,%bl
33556 + pax_force_retaddr
33557 ret
33558
33559 /* rsi contains offset and can be scratched */
33560 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33561 js bpf_error
33562 mov -12(%rbp),%eax
33563 bswap %eax
33564 + pax_force_retaddr
33565 ret
33566
33567 bpf_slow_path_half:
33568 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33569 mov -12(%rbp),%ax
33570 rol $8,%ax
33571 movzwl %ax,%eax
33572 + pax_force_retaddr
33573 ret
33574
33575 bpf_slow_path_byte:
33576 bpf_slow_path_common(1)
33577 js bpf_error
33578 movzbl -12(%rbp),%eax
33579 + pax_force_retaddr
33580 ret
33581
33582 bpf_slow_path_byte_msh:
33583 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33584 and $15,%al
33585 shl $2,%al
33586 xchg %eax,%ebx
33587 + pax_force_retaddr
33588 ret
33589
33590 #define sk_negative_common(SIZE) \
33591 @@ -140,7 +149,7 @@ bpf_slow_path_byte_msh:
33592 push %r9; \
33593 push SKBDATA; \
33594 /* rsi already has offset */ \
33595 - mov $SIZE,%ecx; /* size */ \
33596 + mov $SIZE,%edx; /* size */ \
33597 call bpf_internal_load_pointer_neg_helper; \
33598 test %rax,%rax; \
33599 pop SKBDATA; \
33600 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33601 sk_negative_common(4)
33602 mov (%rax), %eax
33603 bswap %eax
33604 + pax_force_retaddr
33605 ret
33606
33607 bpf_slow_path_half_neg:
33608 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33609 mov (%rax),%ax
33610 rol $8,%ax
33611 movzwl %ax,%eax
33612 + pax_force_retaddr
33613 ret
33614
33615 bpf_slow_path_byte_neg:
33616 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33617 .globl sk_load_byte_negative_offset
33618 sk_negative_common(1)
33619 movzbl (%rax), %eax
33620 + pax_force_retaddr
33621 ret
33622
33623 bpf_slow_path_byte_msh_neg:
33624 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33625 and $15,%al
33626 shl $2,%al
33627 xchg %eax,%ebx
33628 + pax_force_retaddr
33629 ret
33630
33631 bpf_error:
33632 @@ -197,4 +210,5 @@ bpf_error:
33633 xor %eax,%eax
33634 mov -8(%rbp),%rbx
33635 leaveq
33636 + pax_force_retaddr
33637 ret
33638 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33639 index 4ed75dd..3cf24f0b 100644
33640 --- a/arch/x86/net/bpf_jit_comp.c
33641 +++ b/arch/x86/net/bpf_jit_comp.c
33642 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33643 return ptr + len;
33644 }
33645
33646 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33647 +#define MAX_INSTR_CODE_SIZE 96
33648 +#else
33649 +#define MAX_INSTR_CODE_SIZE 64
33650 +#endif
33651 +
33652 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33653
33654 #define EMIT1(b1) EMIT(b1, 1)
33655 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33656 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33657 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33658 +
33659 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33660 +/* original constant will appear in ecx */
33661 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33662 +do { \
33663 + /* mov ecx, randkey */ \
33664 + EMIT1(0xb9); \
33665 + EMIT(_key, 4); \
33666 + /* xor ecx, randkey ^ off */ \
33667 + EMIT2(0x81, 0xf1); \
33668 + EMIT((_key) ^ (_off), 4); \
33669 +} while (0)
33670 +
33671 +#define EMIT1_off32(b1, _off) \
33672 +do { \
33673 + switch (b1) { \
33674 + case 0x05: /* add eax, imm32 */ \
33675 + case 0x2d: /* sub eax, imm32 */ \
33676 + case 0x25: /* and eax, imm32 */ \
33677 + case 0x0d: /* or eax, imm32 */ \
33678 + case 0xb8: /* mov eax, imm32 */ \
33679 + case 0x35: /* xor eax, imm32 */ \
33680 + case 0x3d: /* cmp eax, imm32 */ \
33681 + case 0xa9: /* test eax, imm32 */ \
33682 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33683 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33684 + break; \
33685 + case 0xbb: /* mov ebx, imm32 */ \
33686 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33687 + /* mov ebx, ecx */ \
33688 + EMIT2(0x89, 0xcb); \
33689 + break; \
33690 + case 0xbe: /* mov esi, imm32 */ \
33691 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33692 + /* mov esi, ecx */ \
33693 + EMIT2(0x89, 0xce); \
33694 + break; \
33695 + case 0xe8: /* call rel imm32, always to known funcs */ \
33696 + EMIT1(b1); \
33697 + EMIT(_off, 4); \
33698 + break; \
33699 + case 0xe9: /* jmp rel imm32 */ \
33700 + EMIT1(b1); \
33701 + EMIT(_off, 4); \
33702 + /* prevent fall-through, we're not called if off = 0 */ \
33703 + EMIT(0xcccccccc, 4); \
33704 + EMIT(0xcccccccc, 4); \
33705 + break; \
33706 + default: \
33707 + BUILD_BUG(); \
33708 + } \
33709 +} while (0)
33710 +
33711 +#define EMIT2_off32(b1, b2, _off) \
33712 +do { \
33713 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33714 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33715 + EMIT(randkey, 4); \
33716 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33717 + EMIT((_off) - randkey, 4); \
33718 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33719 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33720 + /* imul eax, ecx */ \
33721 + EMIT3(0x0f, 0xaf, 0xc1); \
33722 + } else { \
33723 + BUILD_BUG(); \
33724 + } \
33725 +} while (0)
33726 +#else
33727 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33728 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33729 +#endif
33730
33731 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33732 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33733 @@ -91,6 +168,24 @@ do { \
33734 #define X86_JBE 0x76
33735 #define X86_JA 0x77
33736
33737 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33738 +#define APPEND_FLOW_VERIFY() \
33739 +do { \
33740 + /* mov ecx, randkey */ \
33741 + EMIT1(0xb9); \
33742 + EMIT(randkey, 4); \
33743 + /* cmp ecx, randkey */ \
33744 + EMIT2(0x81, 0xf9); \
33745 + EMIT(randkey, 4); \
33746 + /* jz after 8 int 3s */ \
33747 + EMIT2(0x74, 0x08); \
33748 + EMIT(0xcccccccc, 4); \
33749 + EMIT(0xcccccccc, 4); \
33750 +} while (0)
33751 +#else
33752 +#define APPEND_FLOW_VERIFY() do { } while (0)
33753 +#endif
33754 +
33755 #define EMIT_COND_JMP(op, offset) \
33756 do { \
33757 if (is_near(offset)) \
33758 @@ -98,6 +193,7 @@ do { \
33759 else { \
33760 EMIT2(0x0f, op + 0x10); \
33761 EMIT(offset, 4); /* jxx .+off32 */ \
33762 + APPEND_FLOW_VERIFY(); \
33763 } \
33764 } while (0)
33765
33766 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33767 return -1;
33768 }
33769
33770 -struct bpf_binary_header {
33771 - unsigned int pages;
33772 - /* Note : for security reasons, bpf code will follow a randomly
33773 - * sized amount of int3 instructions
33774 - */
33775 - u8 image[];
33776 -};
33777 -
33778 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33779 +/* Note : for security reasons, bpf code will follow a randomly
33780 + * sized amount of int3 instructions
33781 + */
33782 +static u8 *bpf_alloc_binary(unsigned int proglen,
33783 u8 **image_ptr)
33784 {
33785 unsigned int sz, hole;
33786 - struct bpf_binary_header *header;
33787 + u8 *header;
33788
33789 /* Most of BPF filters are really small,
33790 * but if some of them fill a page, allow at least
33791 * 128 extra bytes to insert a random section of int3
33792 */
33793 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33794 - header = module_alloc(sz);
33795 + sz = round_up(proglen + 128, PAGE_SIZE);
33796 + header = module_alloc_exec(sz);
33797 if (!header)
33798 return NULL;
33799
33800 + pax_open_kernel();
33801 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33802 + pax_close_kernel();
33803
33804 - header->pages = sz / PAGE_SIZE;
33805 - hole = sz - (proglen + sizeof(*header));
33806 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33807
33808 /* insert a random number of int3 instructions before BPF code */
33809 - *image_ptr = &header->image[prandom_u32() % hole];
33810 + *image_ptr = &header[prandom_u32() % hole];
33811 return header;
33812 }
33813
33814 void bpf_jit_compile(struct sk_filter *fp)
33815 {
33816 - u8 temp[64];
33817 + u8 temp[MAX_INSTR_CODE_SIZE];
33818 u8 *prog;
33819 unsigned int proglen, oldproglen = 0;
33820 int ilen, i;
33821 int t_offset, f_offset;
33822 u8 t_op, f_op, seen = 0, pass;
33823 u8 *image = NULL;
33824 - struct bpf_binary_header *header = NULL;
33825 + u8 *header = NULL;
33826 u8 *func;
33827 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33828 unsigned int cleanup_addr; /* epilogue code offset */
33829 unsigned int *addrs;
33830 const struct sock_filter *filter = fp->insns;
33831 int flen = fp->len;
33832 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33833 + unsigned int randkey;
33834 +#endif
33835
33836 if (!bpf_jit_enable)
33837 return;
33838 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33839 return;
33840
33841 /* Before first pass, make a rough estimation of addrs[]
33842 - * each bpf instruction is translated to less than 64 bytes
33843 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33844 */
33845 for (proglen = 0, i = 0; i < flen; i++) {
33846 - proglen += 64;
33847 + proglen += MAX_INSTR_CODE_SIZE;
33848 addrs[i] = proglen;
33849 }
33850 cleanup_addr = proglen; /* epilogue address */
33851 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33852 for (i = 0; i < flen; i++) {
33853 unsigned int K = filter[i].k;
33854
33855 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33856 + randkey = prandom_u32();
33857 +#endif
33858 +
33859 switch (filter[i].code) {
33860 case BPF_S_ALU_ADD_X: /* A += X; */
33861 seen |= SEEN_XREG;
33862 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33863 case BPF_S_ALU_MUL_K: /* A *= K */
33864 if (is_imm8(K))
33865 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33866 - else {
33867 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33868 - EMIT(K, 4);
33869 - }
33870 + else
33871 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33872 break;
33873 case BPF_S_ALU_DIV_X: /* A /= X; */
33874 seen |= SEEN_XREG;
33875 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33876 break;
33877 }
33878 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33879 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33880 + DILUTE_CONST_SEQUENCE(K, randkey);
33881 +#else
33882 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33883 +#endif
33884 EMIT2(0xf7, 0xf1); /* div %ecx */
33885 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33886 break;
33887 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33888 if (K == 1)
33889 break;
33890 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33891 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33892 + DILUTE_CONST_SEQUENCE(K, randkey);
33893 +#else
33894 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33895 +#endif
33896 EMIT2(0xf7, 0xf1); /* div %ecx */
33897 break;
33898 case BPF_S_ALU_AND_X:
33899 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33900 if (is_imm8(K)) {
33901 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33902 } else {
33903 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33904 - EMIT(K, 4);
33905 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33906 }
33907 } else {
33908 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33909 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33910 if (unlikely(proglen + ilen > oldproglen)) {
33911 pr_err("bpb_jit_compile fatal error\n");
33912 kfree(addrs);
33913 - module_free(NULL, header);
33914 + module_free_exec(NULL, image);
33915 return;
33916 }
33917 + pax_open_kernel();
33918 memcpy(image + proglen, temp, ilen);
33919 + pax_close_kernel();
33920 }
33921 proglen += ilen;
33922 addrs[i] = proglen;
33923 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33924
33925 if (image) {
33926 bpf_flush_icache(header, image + proglen);
33927 - set_memory_ro((unsigned long)header, header->pages);
33928 fp->bpf_func = (void *)image;
33929 }
33930 out:
33931 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33932 {
33933 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33934 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33935 - struct bpf_binary_header *header = (void *)addr;
33936
33937 - set_memory_rw(addr, header->pages);
33938 - module_free(NULL, header);
33939 + set_memory_rw(addr, 1);
33940 + module_free_exec(NULL, (void *)addr);
33941 kfree(fp);
33942 }
33943
33944 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33945 index 5d04be5..2beeaa2 100644
33946 --- a/arch/x86/oprofile/backtrace.c
33947 +++ b/arch/x86/oprofile/backtrace.c
33948 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33949 struct stack_frame_ia32 *fp;
33950 unsigned long bytes;
33951
33952 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33953 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33954 if (bytes != 0)
33955 return NULL;
33956
33957 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33958 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33959
33960 oprofile_add_trace(bufhead[0].return_address);
33961
33962 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33963 struct stack_frame bufhead[2];
33964 unsigned long bytes;
33965
33966 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33967 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33968 if (bytes != 0)
33969 return NULL;
33970
33971 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33972 {
33973 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33974
33975 - if (!user_mode_vm(regs)) {
33976 + if (!user_mode(regs)) {
33977 unsigned long stack = kernel_stack_pointer(regs);
33978 if (depth)
33979 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33980 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33981 index 6890d84..1dad1f1 100644
33982 --- a/arch/x86/oprofile/nmi_int.c
33983 +++ b/arch/x86/oprofile/nmi_int.c
33984 @@ -23,6 +23,7 @@
33985 #include <asm/nmi.h>
33986 #include <asm/msr.h>
33987 #include <asm/apic.h>
33988 +#include <asm/pgtable.h>
33989
33990 #include "op_counter.h"
33991 #include "op_x86_model.h"
33992 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33993 if (ret)
33994 return ret;
33995
33996 - if (!model->num_virt_counters)
33997 - model->num_virt_counters = model->num_counters;
33998 + if (!model->num_virt_counters) {
33999 + pax_open_kernel();
34000 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34001 + pax_close_kernel();
34002 + }
34003
34004 mux_init(ops);
34005
34006 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34007 index 50d86c0..7985318 100644
34008 --- a/arch/x86/oprofile/op_model_amd.c
34009 +++ b/arch/x86/oprofile/op_model_amd.c
34010 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34011 num_counters = AMD64_NUM_COUNTERS;
34012 }
34013
34014 - op_amd_spec.num_counters = num_counters;
34015 - op_amd_spec.num_controls = num_counters;
34016 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34017 + pax_open_kernel();
34018 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34019 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34020 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34021 + pax_close_kernel();
34022
34023 return 0;
34024 }
34025 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34026 index d90528e..0127e2b 100644
34027 --- a/arch/x86/oprofile/op_model_ppro.c
34028 +++ b/arch/x86/oprofile/op_model_ppro.c
34029 @@ -19,6 +19,7 @@
34030 #include <asm/msr.h>
34031 #include <asm/apic.h>
34032 #include <asm/nmi.h>
34033 +#include <asm/pgtable.h>
34034
34035 #include "op_x86_model.h"
34036 #include "op_counter.h"
34037 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34038
34039 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34040
34041 - op_arch_perfmon_spec.num_counters = num_counters;
34042 - op_arch_perfmon_spec.num_controls = num_counters;
34043 + pax_open_kernel();
34044 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34045 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34046 + pax_close_kernel();
34047 }
34048
34049 static int arch_perfmon_init(struct oprofile_operations *ignore)
34050 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34051 index 71e8a67..6a313bb 100644
34052 --- a/arch/x86/oprofile/op_x86_model.h
34053 +++ b/arch/x86/oprofile/op_x86_model.h
34054 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34055 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34056 struct op_msrs const * const msrs);
34057 #endif
34058 -};
34059 +} __do_const;
34060
34061 struct op_counter_config;
34062
34063 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34064 index 51384ca..a25f51e 100644
34065 --- a/arch/x86/pci/intel_mid_pci.c
34066 +++ b/arch/x86/pci/intel_mid_pci.c
34067 @@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
34068 pr_info("Intel MID platform detected, using MID PCI ops\n");
34069 pci_mmcfg_late_init();
34070 pcibios_enable_irq = intel_mid_pci_irq_enable;
34071 - pci_root_ops = intel_mid_pci_ops;
34072 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34073 pci_soc_mode = 1;
34074 /* Continue with standard init */
34075 return 1;
34076 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34077 index 372e9b8..e775a6c 100644
34078 --- a/arch/x86/pci/irq.c
34079 +++ b/arch/x86/pci/irq.c
34080 @@ -50,7 +50,7 @@ struct irq_router {
34081 struct irq_router_handler {
34082 u16 vendor;
34083 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34084 -};
34085 +} __do_const;
34086
34087 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34088 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34089 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34090 return 0;
34091 }
34092
34093 -static __initdata struct irq_router_handler pirq_routers[] = {
34094 +static __initconst const struct irq_router_handler pirq_routers[] = {
34095 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34096 { PCI_VENDOR_ID_AL, ali_router_probe },
34097 { PCI_VENDOR_ID_ITE, ite_router_probe },
34098 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34099 static void __init pirq_find_router(struct irq_router *r)
34100 {
34101 struct irq_routing_table *rt = pirq_table;
34102 - struct irq_router_handler *h;
34103 + const struct irq_router_handler *h;
34104
34105 #ifdef CONFIG_PCI_BIOS
34106 if (!rt->signature) {
34107 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34108 return 0;
34109 }
34110
34111 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34112 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34113 {
34114 .callback = fix_broken_hp_bios_irq9,
34115 .ident = "HP Pavilion N5400 Series Laptop",
34116 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34117 index c77b24a..c979855 100644
34118 --- a/arch/x86/pci/pcbios.c
34119 +++ b/arch/x86/pci/pcbios.c
34120 @@ -79,7 +79,7 @@ union bios32 {
34121 static struct {
34122 unsigned long address;
34123 unsigned short segment;
34124 -} bios32_indirect = { 0, __KERNEL_CS };
34125 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34126
34127 /*
34128 * Returns the entry point for the given service, NULL on error
34129 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34130 unsigned long length; /* %ecx */
34131 unsigned long entry; /* %edx */
34132 unsigned long flags;
34133 + struct desc_struct d, *gdt;
34134
34135 local_irq_save(flags);
34136 - __asm__("lcall *(%%edi); cld"
34137 +
34138 + gdt = get_cpu_gdt_table(smp_processor_id());
34139 +
34140 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34141 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34142 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34143 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34144 +
34145 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34146 : "=a" (return_code),
34147 "=b" (address),
34148 "=c" (length),
34149 "=d" (entry)
34150 : "0" (service),
34151 "1" (0),
34152 - "D" (&bios32_indirect));
34153 + "D" (&bios32_indirect),
34154 + "r"(__PCIBIOS_DS)
34155 + : "memory");
34156 +
34157 + pax_open_kernel();
34158 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34159 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34160 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34161 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34162 + pax_close_kernel();
34163 +
34164 local_irq_restore(flags);
34165
34166 switch (return_code) {
34167 - case 0:
34168 - return address + entry;
34169 - case 0x80: /* Not present */
34170 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34171 - return 0;
34172 - default: /* Shouldn't happen */
34173 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34174 - service, return_code);
34175 + case 0: {
34176 + int cpu;
34177 + unsigned char flags;
34178 +
34179 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34180 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34181 + printk(KERN_WARNING "bios32_service: not valid\n");
34182 return 0;
34183 + }
34184 + address = address + PAGE_OFFSET;
34185 + length += 16UL; /* some BIOSs underreport this... */
34186 + flags = 4;
34187 + if (length >= 64*1024*1024) {
34188 + length >>= PAGE_SHIFT;
34189 + flags |= 8;
34190 + }
34191 +
34192 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34193 + gdt = get_cpu_gdt_table(cpu);
34194 + pack_descriptor(&d, address, length, 0x9b, flags);
34195 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34196 + pack_descriptor(&d, address, length, 0x93, flags);
34197 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34198 + }
34199 + return entry;
34200 + }
34201 + case 0x80: /* Not present */
34202 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34203 + return 0;
34204 + default: /* Shouldn't happen */
34205 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34206 + service, return_code);
34207 + return 0;
34208 }
34209 }
34210
34211 static struct {
34212 unsigned long address;
34213 unsigned short segment;
34214 -} pci_indirect = { 0, __KERNEL_CS };
34215 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34216
34217 -static int pci_bios_present;
34218 +static int pci_bios_present __read_only;
34219
34220 static int check_pcibios(void)
34221 {
34222 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34223 unsigned long flags, pcibios_entry;
34224
34225 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34226 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34227 + pci_indirect.address = pcibios_entry;
34228
34229 local_irq_save(flags);
34230 - __asm__(
34231 - "lcall *(%%edi); cld\n\t"
34232 + __asm__("movw %w6, %%ds\n\t"
34233 + "lcall *%%ss:(%%edi); cld\n\t"
34234 + "push %%ss\n\t"
34235 + "pop %%ds\n\t"
34236 "jc 1f\n\t"
34237 "xor %%ah, %%ah\n"
34238 "1:"
34239 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34240 "=b" (ebx),
34241 "=c" (ecx)
34242 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34243 - "D" (&pci_indirect)
34244 + "D" (&pci_indirect),
34245 + "r" (__PCIBIOS_DS)
34246 : "memory");
34247 local_irq_restore(flags);
34248
34249 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34250
34251 switch (len) {
34252 case 1:
34253 - __asm__("lcall *(%%esi); cld\n\t"
34254 + __asm__("movw %w6, %%ds\n\t"
34255 + "lcall *%%ss:(%%esi); cld\n\t"
34256 + "push %%ss\n\t"
34257 + "pop %%ds\n\t"
34258 "jc 1f\n\t"
34259 "xor %%ah, %%ah\n"
34260 "1:"
34261 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34262 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34263 "b" (bx),
34264 "D" ((long)reg),
34265 - "S" (&pci_indirect));
34266 + "S" (&pci_indirect),
34267 + "r" (__PCIBIOS_DS));
34268 /*
34269 * Zero-extend the result beyond 8 bits, do not trust the
34270 * BIOS having done it:
34271 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34272 *value &= 0xff;
34273 break;
34274 case 2:
34275 - __asm__("lcall *(%%esi); cld\n\t"
34276 + __asm__("movw %w6, %%ds\n\t"
34277 + "lcall *%%ss:(%%esi); cld\n\t"
34278 + "push %%ss\n\t"
34279 + "pop %%ds\n\t"
34280 "jc 1f\n\t"
34281 "xor %%ah, %%ah\n"
34282 "1:"
34283 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34284 : "1" (PCIBIOS_READ_CONFIG_WORD),
34285 "b" (bx),
34286 "D" ((long)reg),
34287 - "S" (&pci_indirect));
34288 + "S" (&pci_indirect),
34289 + "r" (__PCIBIOS_DS));
34290 /*
34291 * Zero-extend the result beyond 16 bits, do not trust the
34292 * BIOS having done it:
34293 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34294 *value &= 0xffff;
34295 break;
34296 case 4:
34297 - __asm__("lcall *(%%esi); cld\n\t"
34298 + __asm__("movw %w6, %%ds\n\t"
34299 + "lcall *%%ss:(%%esi); cld\n\t"
34300 + "push %%ss\n\t"
34301 + "pop %%ds\n\t"
34302 "jc 1f\n\t"
34303 "xor %%ah, %%ah\n"
34304 "1:"
34305 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34306 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34307 "b" (bx),
34308 "D" ((long)reg),
34309 - "S" (&pci_indirect));
34310 + "S" (&pci_indirect),
34311 + "r" (__PCIBIOS_DS));
34312 break;
34313 }
34314
34315 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34316
34317 switch (len) {
34318 case 1:
34319 - __asm__("lcall *(%%esi); cld\n\t"
34320 + __asm__("movw %w6, %%ds\n\t"
34321 + "lcall *%%ss:(%%esi); cld\n\t"
34322 + "push %%ss\n\t"
34323 + "pop %%ds\n\t"
34324 "jc 1f\n\t"
34325 "xor %%ah, %%ah\n"
34326 "1:"
34327 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34328 "c" (value),
34329 "b" (bx),
34330 "D" ((long)reg),
34331 - "S" (&pci_indirect));
34332 + "S" (&pci_indirect),
34333 + "r" (__PCIBIOS_DS));
34334 break;
34335 case 2:
34336 - __asm__("lcall *(%%esi); cld\n\t"
34337 + __asm__("movw %w6, %%ds\n\t"
34338 + "lcall *%%ss:(%%esi); cld\n\t"
34339 + "push %%ss\n\t"
34340 + "pop %%ds\n\t"
34341 "jc 1f\n\t"
34342 "xor %%ah, %%ah\n"
34343 "1:"
34344 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34345 "c" (value),
34346 "b" (bx),
34347 "D" ((long)reg),
34348 - "S" (&pci_indirect));
34349 + "S" (&pci_indirect),
34350 + "r" (__PCIBIOS_DS));
34351 break;
34352 case 4:
34353 - __asm__("lcall *(%%esi); cld\n\t"
34354 + __asm__("movw %w6, %%ds\n\t"
34355 + "lcall *%%ss:(%%esi); cld\n\t"
34356 + "push %%ss\n\t"
34357 + "pop %%ds\n\t"
34358 "jc 1f\n\t"
34359 "xor %%ah, %%ah\n"
34360 "1:"
34361 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34362 "c" (value),
34363 "b" (bx),
34364 "D" ((long)reg),
34365 - "S" (&pci_indirect));
34366 + "S" (&pci_indirect),
34367 + "r" (__PCIBIOS_DS));
34368 break;
34369 }
34370
34371 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34372
34373 DBG("PCI: Fetching IRQ routing table... ");
34374 __asm__("push %%es\n\t"
34375 + "movw %w8, %%ds\n\t"
34376 "push %%ds\n\t"
34377 "pop %%es\n\t"
34378 - "lcall *(%%esi); cld\n\t"
34379 + "lcall *%%ss:(%%esi); cld\n\t"
34380 "pop %%es\n\t"
34381 + "push %%ss\n\t"
34382 + "pop %%ds\n"
34383 "jc 1f\n\t"
34384 "xor %%ah, %%ah\n"
34385 "1:"
34386 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34387 "1" (0),
34388 "D" ((long) &opt),
34389 "S" (&pci_indirect),
34390 - "m" (opt)
34391 + "m" (opt),
34392 + "r" (__PCIBIOS_DS)
34393 : "memory");
34394 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34395 if (ret & 0xff00)
34396 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34397 {
34398 int ret;
34399
34400 - __asm__("lcall *(%%esi); cld\n\t"
34401 + __asm__("movw %w5, %%ds\n\t"
34402 + "lcall *%%ss:(%%esi); cld\n\t"
34403 + "push %%ss\n\t"
34404 + "pop %%ds\n"
34405 "jc 1f\n\t"
34406 "xor %%ah, %%ah\n"
34407 "1:"
34408 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34409 : "0" (PCIBIOS_SET_PCI_HW_INT),
34410 "b" ((dev->bus->number << 8) | dev->devfn),
34411 "c" ((irq << 8) | (pin + 10)),
34412 - "S" (&pci_indirect));
34413 + "S" (&pci_indirect),
34414 + "r" (__PCIBIOS_DS));
34415 return !(ret & 0xff00);
34416 }
34417 EXPORT_SYMBOL(pcibios_set_irq_routing);
34418 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34419 index 40e4469..d915bf9 100644
34420 --- a/arch/x86/platform/efi/efi_32.c
34421 +++ b/arch/x86/platform/efi/efi_32.c
34422 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
34423 {
34424 struct desc_ptr gdt_descr;
34425
34426 +#ifdef CONFIG_PAX_KERNEXEC
34427 + struct desc_struct d;
34428 +#endif
34429 +
34430 local_irq_save(efi_rt_eflags);
34431
34432 load_cr3(initial_page_table);
34433 __flush_tlb_all();
34434
34435 +#ifdef CONFIG_PAX_KERNEXEC
34436 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34437 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34438 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34439 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34440 +#endif
34441 +
34442 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34443 gdt_descr.size = GDT_SIZE - 1;
34444 load_gdt(&gdt_descr);
34445 @@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
34446 {
34447 struct desc_ptr gdt_descr;
34448
34449 +#ifdef CONFIG_PAX_KERNEXEC
34450 + struct desc_struct d;
34451 +
34452 + memset(&d, 0, sizeof d);
34453 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34454 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34455 +#endif
34456 +
34457 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34458 gdt_descr.size = GDT_SIZE - 1;
34459 load_gdt(&gdt_descr);
34460
34461 +#ifdef CONFIG_PAX_PER_CPU_PGD
34462 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34463 +#else
34464 load_cr3(swapper_pg_dir);
34465 +#endif
34466 +
34467 __flush_tlb_all();
34468
34469 local_irq_restore(efi_rt_eflags);
34470 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34471 index 39a0e7f1..872396e 100644
34472 --- a/arch/x86/platform/efi/efi_64.c
34473 +++ b/arch/x86/platform/efi/efi_64.c
34474 @@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
34475 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34476 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34477 }
34478 +
34479 +#ifdef CONFIG_PAX_PER_CPU_PGD
34480 + load_cr3(swapper_pg_dir);
34481 +#endif
34482 +
34483 __flush_tlb_all();
34484 }
34485
34486 @@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
34487 for (pgd = 0; pgd < n_pgds; pgd++)
34488 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34489 kfree(save_pgd);
34490 +
34491 +#ifdef CONFIG_PAX_PER_CPU_PGD
34492 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34493 +#endif
34494 +
34495 __flush_tlb_all();
34496 local_irq_restore(efi_flags);
34497 early_code_mapping_set_exec(0);
34498 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34499 index fbe66e6..eae5e38 100644
34500 --- a/arch/x86/platform/efi/efi_stub_32.S
34501 +++ b/arch/x86/platform/efi/efi_stub_32.S
34502 @@ -6,7 +6,9 @@
34503 */
34504
34505 #include <linux/linkage.h>
34506 +#include <linux/init.h>
34507 #include <asm/page_types.h>
34508 +#include <asm/segment.h>
34509
34510 /*
34511 * efi_call_phys(void *, ...) is a function with variable parameters.
34512 @@ -20,7 +22,7 @@
34513 * service functions will comply with gcc calling convention, too.
34514 */
34515
34516 -.text
34517 +__INIT
34518 ENTRY(efi_call_phys)
34519 /*
34520 * 0. The function can only be called in Linux kernel. So CS has been
34521 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34522 * The mapping of lower virtual memory has been created in prelog and
34523 * epilog.
34524 */
34525 - movl $1f, %edx
34526 - subl $__PAGE_OFFSET, %edx
34527 - jmp *%edx
34528 +#ifdef CONFIG_PAX_KERNEXEC
34529 + movl $(__KERNEXEC_EFI_DS), %edx
34530 + mov %edx, %ds
34531 + mov %edx, %es
34532 + mov %edx, %ss
34533 + addl $2f,(1f)
34534 + ljmp *(1f)
34535 +
34536 +__INITDATA
34537 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34538 +.previous
34539 +
34540 +2:
34541 + subl $2b,(1b)
34542 +#else
34543 + jmp 1f-__PAGE_OFFSET
34544 1:
34545 +#endif
34546
34547 /*
34548 * 2. Now on the top of stack is the return
34549 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34550 * parameter 2, ..., param n. To make things easy, we save the return
34551 * address of efi_call_phys in a global variable.
34552 */
34553 - popl %edx
34554 - movl %edx, saved_return_addr
34555 - /* get the function pointer into ECX*/
34556 - popl %ecx
34557 - movl %ecx, efi_rt_function_ptr
34558 - movl $2f, %edx
34559 - subl $__PAGE_OFFSET, %edx
34560 - pushl %edx
34561 + popl (saved_return_addr)
34562 + popl (efi_rt_function_ptr)
34563
34564 /*
34565 * 3. Clear PG bit in %CR0.
34566 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34567 /*
34568 * 5. Call the physical function.
34569 */
34570 - jmp *%ecx
34571 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34572
34573 -2:
34574 /*
34575 * 6. After EFI runtime service returns, control will return to
34576 * following instruction. We'd better readjust stack pointer first.
34577 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34578 movl %cr0, %edx
34579 orl $0x80000000, %edx
34580 movl %edx, %cr0
34581 - jmp 1f
34582 -1:
34583 +
34584 /*
34585 * 8. Now restore the virtual mode from flat mode by
34586 * adding EIP with PAGE_OFFSET.
34587 */
34588 - movl $1f, %edx
34589 - jmp *%edx
34590 +#ifdef CONFIG_PAX_KERNEXEC
34591 + movl $(__KERNEL_DS), %edx
34592 + mov %edx, %ds
34593 + mov %edx, %es
34594 + mov %edx, %ss
34595 + ljmp $(__KERNEL_CS),$1f
34596 +#else
34597 + jmp 1f+__PAGE_OFFSET
34598 +#endif
34599 1:
34600
34601 /*
34602 * 9. Balance the stack. And because EAX contain the return value,
34603 * we'd better not clobber it.
34604 */
34605 - leal efi_rt_function_ptr, %edx
34606 - movl (%edx), %ecx
34607 - pushl %ecx
34608 + pushl (efi_rt_function_ptr)
34609
34610 /*
34611 - * 10. Push the saved return address onto the stack and return.
34612 + * 10. Return to the saved return address.
34613 */
34614 - leal saved_return_addr, %edx
34615 - movl (%edx), %ecx
34616 - pushl %ecx
34617 - ret
34618 + jmpl *(saved_return_addr)
34619 ENDPROC(efi_call_phys)
34620 .previous
34621
34622 -.data
34623 +__INITDATA
34624 saved_return_addr:
34625 .long 0
34626 efi_rt_function_ptr:
34627 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34628 index 4c07cca..2c8427d 100644
34629 --- a/arch/x86/platform/efi/efi_stub_64.S
34630 +++ b/arch/x86/platform/efi/efi_stub_64.S
34631 @@ -7,6 +7,7 @@
34632 */
34633
34634 #include <linux/linkage.h>
34635 +#include <asm/alternative-asm.h>
34636
34637 #define SAVE_XMM \
34638 mov %rsp, %rax; \
34639 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
34640 call *%rdi
34641 addq $32, %rsp
34642 RESTORE_XMM
34643 + pax_force_retaddr 0, 1
34644 ret
34645 ENDPROC(efi_call0)
34646
34647 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
34648 call *%rdi
34649 addq $32, %rsp
34650 RESTORE_XMM
34651 + pax_force_retaddr 0, 1
34652 ret
34653 ENDPROC(efi_call1)
34654
34655 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
34656 call *%rdi
34657 addq $32, %rsp
34658 RESTORE_XMM
34659 + pax_force_retaddr 0, 1
34660 ret
34661 ENDPROC(efi_call2)
34662
34663 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
34664 call *%rdi
34665 addq $32, %rsp
34666 RESTORE_XMM
34667 + pax_force_retaddr 0, 1
34668 ret
34669 ENDPROC(efi_call3)
34670
34671 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
34672 call *%rdi
34673 addq $32, %rsp
34674 RESTORE_XMM
34675 + pax_force_retaddr 0, 1
34676 ret
34677 ENDPROC(efi_call4)
34678
34679 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
34680 call *%rdi
34681 addq $48, %rsp
34682 RESTORE_XMM
34683 + pax_force_retaddr 0, 1
34684 ret
34685 ENDPROC(efi_call5)
34686
34687 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
34688 call *%rdi
34689 addq $48, %rsp
34690 RESTORE_XMM
34691 + pax_force_retaddr 0, 1
34692 ret
34693 ENDPROC(efi_call6)
34694 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34695 index f90e290..435f0dd 100644
34696 --- a/arch/x86/platform/intel-mid/intel-mid.c
34697 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34698 @@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34699 {
34700 }
34701
34702 -static void intel_mid_reboot(void)
34703 +static void __noreturn intel_mid_reboot(void)
34704 {
34705 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34706 + BUG();
34707 }
34708
34709 static unsigned long __init intel_mid_calibrate_tsc(void)
34710 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34711 index d6ee929..3637cb5 100644
34712 --- a/arch/x86/platform/olpc/olpc_dt.c
34713 +++ b/arch/x86/platform/olpc/olpc_dt.c
34714 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34715 return res;
34716 }
34717
34718 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34719 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34720 .nextprop = olpc_dt_nextprop,
34721 .getproplen = olpc_dt_getproplen,
34722 .getproperty = olpc_dt_getproperty,
34723 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34724 index 424f4c9..f2a2988 100644
34725 --- a/arch/x86/power/cpu.c
34726 +++ b/arch/x86/power/cpu.c
34727 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34728 static void fix_processor_context(void)
34729 {
34730 int cpu = smp_processor_id();
34731 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34732 -#ifdef CONFIG_X86_64
34733 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34734 - tss_desc tss;
34735 -#endif
34736 + struct tss_struct *t = init_tss + cpu;
34737 +
34738 set_tss_desc(cpu, t); /*
34739 * This just modifies memory; should not be
34740 * necessary. But... This is necessary, because
34741 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34742 */
34743
34744 #ifdef CONFIG_X86_64
34745 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34746 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34747 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34748 -
34749 syscall_init(); /* This sets MSR_*STAR and related */
34750 #endif
34751 load_TR_desc(); /* This does ltr */
34752 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34753 index a44f457..9140171 100644
34754 --- a/arch/x86/realmode/init.c
34755 +++ b/arch/x86/realmode/init.c
34756 @@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34757 __va(real_mode_header->trampoline_header);
34758
34759 #ifdef CONFIG_X86_32
34760 - trampoline_header->start = __pa_symbol(startup_32_smp);
34761 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34762 +
34763 +#ifdef CONFIG_PAX_KERNEXEC
34764 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34765 +#endif
34766 +
34767 + trampoline_header->boot_cs = __BOOT_CS;
34768 trampoline_header->gdt_limit = __BOOT_DS + 7;
34769 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34770 #else
34771 @@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34772 *trampoline_cr4_features = read_cr4();
34773
34774 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34775 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34776 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34777 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34778 #endif
34779 }
34780 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34781 index 9cac825..4890b25 100644
34782 --- a/arch/x86/realmode/rm/Makefile
34783 +++ b/arch/x86/realmode/rm/Makefile
34784 @@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34785 $(call cc-option, -fno-unit-at-a-time)) \
34786 $(call cc-option, -fno-stack-protector) \
34787 $(call cc-option, -mpreferred-stack-boundary=2)
34788 +ifdef CONSTIFY_PLUGIN
34789 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34790 +endif
34791 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34792 GCOV_PROFILE := n
34793 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34794 index a28221d..93c40f1 100644
34795 --- a/arch/x86/realmode/rm/header.S
34796 +++ b/arch/x86/realmode/rm/header.S
34797 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34798 #endif
34799 /* APM/BIOS reboot */
34800 .long pa_machine_real_restart_asm
34801 -#ifdef CONFIG_X86_64
34802 +#ifdef CONFIG_X86_32
34803 + .long __KERNEL_CS
34804 +#else
34805 .long __KERNEL32_CS
34806 #endif
34807 END(real_mode_header)
34808 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34809 index c1b2791..f9e31c7 100644
34810 --- a/arch/x86/realmode/rm/trampoline_32.S
34811 +++ b/arch/x86/realmode/rm/trampoline_32.S
34812 @@ -25,6 +25,12 @@
34813 #include <asm/page_types.h>
34814 #include "realmode.h"
34815
34816 +#ifdef CONFIG_PAX_KERNEXEC
34817 +#define ta(X) (X)
34818 +#else
34819 +#define ta(X) (pa_ ## X)
34820 +#endif
34821 +
34822 .text
34823 .code16
34824
34825 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34826
34827 cli # We should be safe anyway
34828
34829 - movl tr_start, %eax # where we need to go
34830 -
34831 movl $0xA5A5A5A5, trampoline_status
34832 # write marker for master knows we're running
34833
34834 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34835 movw $1, %dx # protected mode (PE) bit
34836 lmsw %dx # into protected mode
34837
34838 - ljmpl $__BOOT_CS, $pa_startup_32
34839 + ljmpl *(trampoline_header)
34840
34841 .section ".text32","ax"
34842 .code32
34843 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34844 .balign 8
34845 GLOBAL(trampoline_header)
34846 tr_start: .space 4
34847 - tr_gdt_pad: .space 2
34848 + tr_boot_cs: .space 2
34849 tr_gdt: .space 6
34850 END(trampoline_header)
34851
34852 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34853 index bb360dc..d0fd8f8 100644
34854 --- a/arch/x86/realmode/rm/trampoline_64.S
34855 +++ b/arch/x86/realmode/rm/trampoline_64.S
34856 @@ -94,6 +94,7 @@ ENTRY(startup_32)
34857 movl %edx, %gs
34858
34859 movl pa_tr_cr4, %eax
34860 + andl $~X86_CR4_PCIDE, %eax
34861 movl %eax, %cr4 # Enable PAE mode
34862
34863 # Setup trampoline 4 level pagetables
34864 @@ -107,7 +108,7 @@ ENTRY(startup_32)
34865 wrmsr
34866
34867 # Enable paging and in turn activate Long Mode
34868 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34869 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
34870 movl %eax, %cr0
34871
34872 /*
34873 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34874 index e812034..c747134 100644
34875 --- a/arch/x86/tools/Makefile
34876 +++ b/arch/x86/tools/Makefile
34877 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34878
34879 $(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
34880
34881 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34882 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34883 hostprogs-y += relocs
34884 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34885 relocs: $(obj)/relocs
34886 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34887 index f7bab68..b6d9886 100644
34888 --- a/arch/x86/tools/relocs.c
34889 +++ b/arch/x86/tools/relocs.c
34890 @@ -1,5 +1,7 @@
34891 /* This is included from relocs_32/64.c */
34892
34893 +#include "../../../include/generated/autoconf.h"
34894 +
34895 #define ElfW(type) _ElfW(ELF_BITS, type)
34896 #define _ElfW(bits, type) __ElfW(bits, type)
34897 #define __ElfW(bits, type) Elf##bits##_##type
34898 @@ -11,6 +13,7 @@
34899 #define Elf_Sym ElfW(Sym)
34900
34901 static Elf_Ehdr ehdr;
34902 +static Elf_Phdr *phdr;
34903
34904 struct relocs {
34905 uint32_t *offset;
34906 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34907 }
34908 }
34909
34910 +static void read_phdrs(FILE *fp)
34911 +{
34912 + unsigned int i;
34913 +
34914 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34915 + if (!phdr) {
34916 + die("Unable to allocate %d program headers\n",
34917 + ehdr.e_phnum);
34918 + }
34919 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34920 + die("Seek to %d failed: %s\n",
34921 + ehdr.e_phoff, strerror(errno));
34922 + }
34923 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34924 + die("Cannot read ELF program headers: %s\n",
34925 + strerror(errno));
34926 + }
34927 + for(i = 0; i < ehdr.e_phnum; i++) {
34928 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34929 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34930 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34931 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34932 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34933 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34934 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34935 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34936 + }
34937 +
34938 +}
34939 +
34940 static void read_shdrs(FILE *fp)
34941 {
34942 - int i;
34943 + unsigned int i;
34944 Elf_Shdr shdr;
34945
34946 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34947 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34948
34949 static void read_strtabs(FILE *fp)
34950 {
34951 - int i;
34952 + unsigned int i;
34953 for (i = 0; i < ehdr.e_shnum; i++) {
34954 struct section *sec = &secs[i];
34955 if (sec->shdr.sh_type != SHT_STRTAB) {
34956 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34957
34958 static void read_symtabs(FILE *fp)
34959 {
34960 - int i,j;
34961 + unsigned int i,j;
34962 for (i = 0; i < ehdr.e_shnum; i++) {
34963 struct section *sec = &secs[i];
34964 if (sec->shdr.sh_type != SHT_SYMTAB) {
34965 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34966 }
34967
34968
34969 -static void read_relocs(FILE *fp)
34970 +static void read_relocs(FILE *fp, int use_real_mode)
34971 {
34972 - int i,j;
34973 + unsigned int i,j;
34974 + uint32_t base;
34975 +
34976 for (i = 0; i < ehdr.e_shnum; i++) {
34977 struct section *sec = &secs[i];
34978 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34979 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34980 die("Cannot read symbol table: %s\n",
34981 strerror(errno));
34982 }
34983 + base = 0;
34984 +
34985 +#ifdef CONFIG_X86_32
34986 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34987 + if (phdr[j].p_type != PT_LOAD )
34988 + continue;
34989 + 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)
34990 + continue;
34991 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34992 + break;
34993 + }
34994 +#endif
34995 +
34996 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34997 Elf_Rel *rel = &sec->reltab[j];
34998 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34999 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35000 rel->r_info = elf_xword_to_cpu(rel->r_info);
35001 #if (SHT_REL_TYPE == SHT_RELA)
35002 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35003 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35004
35005 static void print_absolute_symbols(void)
35006 {
35007 - int i;
35008 + unsigned int i;
35009 const char *format;
35010
35011 if (ELF_BITS == 64)
35012 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35013 for (i = 0; i < ehdr.e_shnum; i++) {
35014 struct section *sec = &secs[i];
35015 char *sym_strtab;
35016 - int j;
35017 + unsigned int j;
35018
35019 if (sec->shdr.sh_type != SHT_SYMTAB) {
35020 continue;
35021 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35022
35023 static void print_absolute_relocs(void)
35024 {
35025 - int i, printed = 0;
35026 + unsigned int i, printed = 0;
35027 const char *format;
35028
35029 if (ELF_BITS == 64)
35030 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35031 struct section *sec_applies, *sec_symtab;
35032 char *sym_strtab;
35033 Elf_Sym *sh_symtab;
35034 - int j;
35035 + unsigned int j;
35036 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35037 continue;
35038 }
35039 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35040 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35041 Elf_Sym *sym, const char *symname))
35042 {
35043 - int i;
35044 + unsigned int i;
35045 /* Walk through the relocations */
35046 for (i = 0; i < ehdr.e_shnum; i++) {
35047 char *sym_strtab;
35048 Elf_Sym *sh_symtab;
35049 struct section *sec_applies, *sec_symtab;
35050 - int j;
35051 + unsigned int j;
35052 struct section *sec = &secs[i];
35053
35054 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35055 @@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35056 {
35057 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35058 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35059 + char *sym_strtab = sec->link->link->strtab;
35060 +
35061 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35062 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35063 + return 0;
35064 +
35065 +#ifdef CONFIG_PAX_KERNEXEC
35066 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35067 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35068 + return 0;
35069 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35070 + return 0;
35071 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35072 + return 0;
35073 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35074 + return 0;
35075 +#endif
35076
35077 switch (r_type) {
35078 case R_386_NONE:
35079 @@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35080
35081 static void emit_relocs(int as_text, int use_real_mode)
35082 {
35083 - int i;
35084 + unsigned int i;
35085 int (*write_reloc)(uint32_t, FILE *) = write32;
35086 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35087 const char *symname);
35088 @@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35089 {
35090 regex_init(use_real_mode);
35091 read_ehdr(fp);
35092 + read_phdrs(fp);
35093 read_shdrs(fp);
35094 read_strtabs(fp);
35095 read_symtabs(fp);
35096 - read_relocs(fp);
35097 + read_relocs(fp, use_real_mode);
35098 if (ELF_BITS == 64)
35099 percpu_init();
35100 if (show_absolute_syms) {
35101 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35102 index 80ffa5b..a33bd15 100644
35103 --- a/arch/x86/um/tls_32.c
35104 +++ b/arch/x86/um/tls_32.c
35105 @@ -260,7 +260,7 @@ out:
35106 if (unlikely(task == current &&
35107 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35108 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35109 - "without flushed TLS.", current->pid);
35110 + "without flushed TLS.", task_pid_nr(current));
35111 }
35112
35113 return 0;
35114 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35115 index fd14be1..e3c79c0 100644
35116 --- a/arch/x86/vdso/Makefile
35117 +++ b/arch/x86/vdso/Makefile
35118 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35119 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35120 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35121
35122 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35123 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35124 GCOV_PROFILE := n
35125
35126 #
35127 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35128 index d6bfb87..876ee18 100644
35129 --- a/arch/x86/vdso/vdso32-setup.c
35130 +++ b/arch/x86/vdso/vdso32-setup.c
35131 @@ -25,6 +25,7 @@
35132 #include <asm/tlbflush.h>
35133 #include <asm/vdso.h>
35134 #include <asm/proto.h>
35135 +#include <asm/mman.h>
35136
35137 enum {
35138 VDSO_DISABLED = 0,
35139 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35140 void enable_sep_cpu(void)
35141 {
35142 int cpu = get_cpu();
35143 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35144 + struct tss_struct *tss = init_tss + cpu;
35145
35146 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35147 put_cpu();
35148 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35149 gate_vma.vm_start = FIXADDR_USER_START;
35150 gate_vma.vm_end = FIXADDR_USER_END;
35151 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35152 - gate_vma.vm_page_prot = __P101;
35153 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35154
35155 return 0;
35156 }
35157 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35158 if (compat)
35159 addr = VDSO_HIGH_BASE;
35160 else {
35161 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35162 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35163 if (IS_ERR_VALUE(addr)) {
35164 ret = addr;
35165 goto up_fail;
35166 }
35167 }
35168
35169 - current->mm->context.vdso = (void *)addr;
35170 + current->mm->context.vdso = addr;
35171
35172 if (compat_uses_vma || !compat) {
35173 /*
35174 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35175 }
35176
35177 current_thread_info()->sysenter_return =
35178 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35179 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35180
35181 up_fail:
35182 if (ret)
35183 - current->mm->context.vdso = NULL;
35184 + current->mm->context.vdso = 0;
35185
35186 up_write(&mm->mmap_sem);
35187
35188 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35189
35190 const char *arch_vma_name(struct vm_area_struct *vma)
35191 {
35192 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35193 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35194 return "[vdso]";
35195 +
35196 +#ifdef CONFIG_PAX_SEGMEXEC
35197 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35198 + return "[vdso]";
35199 +#endif
35200 +
35201 return NULL;
35202 }
35203
35204 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35205 * Check to see if the corresponding task was created in compat vdso
35206 * mode.
35207 */
35208 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35209 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35210 return &gate_vma;
35211 return NULL;
35212 }
35213 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35214 index 431e875..cbb23f3 100644
35215 --- a/arch/x86/vdso/vma.c
35216 +++ b/arch/x86/vdso/vma.c
35217 @@ -16,8 +16,6 @@
35218 #include <asm/vdso.h>
35219 #include <asm/page.h>
35220
35221 -unsigned int __read_mostly vdso_enabled = 1;
35222 -
35223 extern char vdso_start[], vdso_end[];
35224 extern unsigned short vdso_sync_cpuid;
35225
35226 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35227 * unaligned here as a result of stack start randomization.
35228 */
35229 addr = PAGE_ALIGN(addr);
35230 - addr = align_vdso_addr(addr);
35231
35232 return addr;
35233 }
35234 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35235 unsigned size)
35236 {
35237 struct mm_struct *mm = current->mm;
35238 - unsigned long addr;
35239 + unsigned long addr = 0;
35240 int ret;
35241
35242 - if (!vdso_enabled)
35243 - return 0;
35244 -
35245 down_write(&mm->mmap_sem);
35246 +
35247 +#ifdef CONFIG_PAX_RANDMMAP
35248 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35249 +#endif
35250 +
35251 addr = vdso_addr(mm->start_stack, size);
35252 + addr = align_vdso_addr(addr);
35253 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35254 if (IS_ERR_VALUE(addr)) {
35255 ret = addr;
35256 goto up_fail;
35257 }
35258
35259 - current->mm->context.vdso = (void *)addr;
35260 + mm->context.vdso = addr;
35261
35262 ret = install_special_mapping(mm, addr, size,
35263 VM_READ|VM_EXEC|
35264 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35265 pages);
35266 - if (ret) {
35267 - current->mm->context.vdso = NULL;
35268 - goto up_fail;
35269 - }
35270 + if (ret)
35271 + mm->context.vdso = 0;
35272
35273 up_fail:
35274 up_write(&mm->mmap_sem);
35275 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35276 vdsox32_size);
35277 }
35278 #endif
35279 -
35280 -static __init int vdso_setup(char *s)
35281 -{
35282 - vdso_enabled = simple_strtoul(s, NULL, 0);
35283 - return 0;
35284 -}
35285 -__setup("vdso=", vdso_setup);
35286 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35287 index 1a3c765..3d2e8d1 100644
35288 --- a/arch/x86/xen/Kconfig
35289 +++ b/arch/x86/xen/Kconfig
35290 @@ -9,6 +9,7 @@ config XEN
35291 select XEN_HAVE_PVMMU
35292 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35293 depends on X86_TSC
35294 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35295 help
35296 This is the Linux Xen port. Enabling this will allow the
35297 kernel to boot in a paravirtualized environment under the
35298 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35299 index fa6ade7..73da73a5 100644
35300 --- a/arch/x86/xen/enlighten.c
35301 +++ b/arch/x86/xen/enlighten.c
35302 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35303
35304 struct shared_info xen_dummy_shared_info;
35305
35306 -void *xen_initial_gdt;
35307 -
35308 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35309 __read_mostly int xen_have_vector_callback;
35310 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35311 @@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35312 {
35313 unsigned long va = dtr->address;
35314 unsigned int size = dtr->size + 1;
35315 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35316 - unsigned long frames[pages];
35317 + unsigned long frames[65536 / PAGE_SIZE];
35318 int f;
35319
35320 /*
35321 @@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35322 {
35323 unsigned long va = dtr->address;
35324 unsigned int size = dtr->size + 1;
35325 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35326 - unsigned long frames[pages];
35327 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35328 int f;
35329
35330 /*
35331 @@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35332 * 8-byte entries, or 16 4k pages..
35333 */
35334
35335 - BUG_ON(size > 65536);
35336 + BUG_ON(size > GDT_SIZE);
35337 BUG_ON(va & ~PAGE_MASK);
35338
35339 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35340 @@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35341 return 0;
35342 }
35343
35344 -static void set_xen_basic_apic_ops(void)
35345 +static void __init set_xen_basic_apic_ops(void)
35346 {
35347 apic->read = xen_apic_read;
35348 apic->write = xen_apic_write;
35349 @@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35350 #endif
35351 };
35352
35353 -static void xen_reboot(int reason)
35354 +static __noreturn void xen_reboot(int reason)
35355 {
35356 struct sched_shutdown r = { .reason = reason };
35357
35358 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35359 - BUG();
35360 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35361 + BUG();
35362 }
35363
35364 -static void xen_restart(char *msg)
35365 +static __noreturn void xen_restart(char *msg)
35366 {
35367 xen_reboot(SHUTDOWN_reboot);
35368 }
35369
35370 -static void xen_emergency_restart(void)
35371 +static __noreturn void xen_emergency_restart(void)
35372 {
35373 xen_reboot(SHUTDOWN_reboot);
35374 }
35375
35376 -static void xen_machine_halt(void)
35377 +static __noreturn void xen_machine_halt(void)
35378 {
35379 xen_reboot(SHUTDOWN_poweroff);
35380 }
35381
35382 -static void xen_machine_power_off(void)
35383 +static __noreturn void xen_machine_power_off(void)
35384 {
35385 if (pm_power_off)
35386 pm_power_off();
35387 @@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
35388 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35389
35390 /* Work out if we support NX */
35391 - x86_configure_nx();
35392 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35393 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35394 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35395 + unsigned l, h;
35396 +
35397 + __supported_pte_mask |= _PAGE_NX;
35398 + rdmsr(MSR_EFER, l, h);
35399 + l |= EFER_NX;
35400 + wrmsr(MSR_EFER, l, h);
35401 + }
35402 +#endif
35403
35404 xen_setup_features();
35405
35406 @@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
35407
35408 machine_ops = xen_machine_ops;
35409
35410 - /*
35411 - * The only reliable way to retain the initial address of the
35412 - * percpu gdt_page is to remember it here, so we can go and
35413 - * mark it RW later, when the initial percpu area is freed.
35414 - */
35415 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35416 -
35417 xen_smp_init();
35418
35419 #ifdef CONFIG_ACPI_NUMA
35420 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35421 index 3c76c3d..7871755 100644
35422 --- a/arch/x86/xen/mmu.c
35423 +++ b/arch/x86/xen/mmu.c
35424 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35425 return val;
35426 }
35427
35428 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35429 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35430 {
35431 if (pteval_present(val)) {
35432 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35433 @@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35434 /* L3_k[510] -> level2_kernel_pgt
35435 * L3_i[511] -> level2_fixmap_pgt */
35436 convert_pfn_mfn(level3_kernel_pgt);
35437 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35438 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35439 + convert_pfn_mfn(level3_vmemmap_pgt);
35440
35441 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35442 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35443 @@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35444 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35445 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35446 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35447 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35448 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35449 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35450 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35451 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35452 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35453 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35454 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35455
35456 @@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
35457 pv_mmu_ops.set_pud = xen_set_pud;
35458 #if PAGETABLE_LEVELS == 4
35459 pv_mmu_ops.set_pgd = xen_set_pgd;
35460 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35461 #endif
35462
35463 /* This will work as long as patching hasn't happened yet
35464 @@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35465 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35466 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35467 .set_pgd = xen_set_pgd_hyper,
35468 + .set_pgd_batched = xen_set_pgd_hyper,
35469
35470 .alloc_pud = xen_alloc_pmd_init,
35471 .release_pud = xen_release_pmd_init,
35472 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35473 index c36b325..b0f1518 100644
35474 --- a/arch/x86/xen/smp.c
35475 +++ b/arch/x86/xen/smp.c
35476 @@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35477 native_smp_prepare_boot_cpu();
35478
35479 if (xen_pv_domain()) {
35480 - /* We've switched to the "real" per-cpu gdt, so make sure the
35481 - old memory can be recycled */
35482 - make_lowmem_page_readwrite(xen_initial_gdt);
35483 -
35484 #ifdef CONFIG_X86_32
35485 /*
35486 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35487 * expects __USER_DS
35488 */
35489 - loadsegment(ds, __USER_DS);
35490 - loadsegment(es, __USER_DS);
35491 + loadsegment(ds, __KERNEL_DS);
35492 + loadsegment(es, __KERNEL_DS);
35493 #endif
35494
35495 xen_filter_cpu_maps();
35496 @@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35497 ctxt->user_regs.ss = __KERNEL_DS;
35498 #ifdef CONFIG_X86_32
35499 ctxt->user_regs.fs = __KERNEL_PERCPU;
35500 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35501 + savesegment(gs, ctxt->user_regs.gs);
35502 #else
35503 ctxt->gs_base_kernel = per_cpu_offset(cpu);
35504 #endif
35505 @@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35506
35507 {
35508 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35509 - ctxt->user_regs.ds = __USER_DS;
35510 - ctxt->user_regs.es = __USER_DS;
35511 + ctxt->user_regs.ds = __KERNEL_DS;
35512 + ctxt->user_regs.es = __KERNEL_DS;
35513
35514 xen_copy_trap_info(ctxt->trap_ctxt);
35515
35516 @@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35517 int rc;
35518
35519 per_cpu(current_task, cpu) = idle;
35520 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35521 #ifdef CONFIG_X86_32
35522 irq_ctx_init(cpu);
35523 #else
35524 clear_tsk_thread_flag(idle, TIF_FORK);
35525 - per_cpu(kernel_stack, cpu) =
35526 - (unsigned long)task_stack_page(idle) -
35527 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35528 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35529 #endif
35530 xen_setup_runstate_info(cpu);
35531 xen_setup_timer(cpu);
35532 @@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35533
35534 void __init xen_smp_init(void)
35535 {
35536 - smp_ops = xen_smp_ops;
35537 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35538 xen_fill_possible_map();
35539 }
35540
35541 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35542 index 33ca6e4..0ded929 100644
35543 --- a/arch/x86/xen/xen-asm_32.S
35544 +++ b/arch/x86/xen/xen-asm_32.S
35545 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
35546 ESP_OFFSET=4 # bytes pushed onto stack
35547
35548 /*
35549 - * Store vcpu_info pointer for easy access. Do it this way to
35550 - * avoid having to reload %fs
35551 + * Store vcpu_info pointer for easy access.
35552 */
35553 #ifdef CONFIG_SMP
35554 - GET_THREAD_INFO(%eax)
35555 - movl %ss:TI_cpu(%eax), %eax
35556 - movl %ss:__per_cpu_offset(,%eax,4), %eax
35557 - mov %ss:xen_vcpu(%eax), %eax
35558 + push %fs
35559 + mov $(__KERNEL_PERCPU), %eax
35560 + mov %eax, %fs
35561 + mov PER_CPU_VAR(xen_vcpu), %eax
35562 + pop %fs
35563 #else
35564 movl %ss:xen_vcpu, %eax
35565 #endif
35566 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35567 index 7faed58..ba4427c 100644
35568 --- a/arch/x86/xen/xen-head.S
35569 +++ b/arch/x86/xen/xen-head.S
35570 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
35571 #ifdef CONFIG_X86_32
35572 mov %esi,xen_start_info
35573 mov $init_thread_union+THREAD_SIZE,%esp
35574 +#ifdef CONFIG_SMP
35575 + movl $cpu_gdt_table,%edi
35576 + movl $__per_cpu_load,%eax
35577 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35578 + rorl $16,%eax
35579 + movb %al,__KERNEL_PERCPU + 4(%edi)
35580 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35581 + movl $__per_cpu_end - 1,%eax
35582 + subl $__per_cpu_start,%eax
35583 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35584 +#endif
35585 #else
35586 mov %rsi,xen_start_info
35587 mov $init_thread_union+THREAD_SIZE,%rsp
35588 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35589 index 95f8c61..611d6e8 100644
35590 --- a/arch/x86/xen/xen-ops.h
35591 +++ b/arch/x86/xen/xen-ops.h
35592 @@ -10,8 +10,6 @@
35593 extern const char xen_hypervisor_callback[];
35594 extern const char xen_failsafe_callback[];
35595
35596 -extern void *xen_initial_gdt;
35597 -
35598 struct trap_info;
35599 void xen_copy_trap_info(struct trap_info *traps);
35600
35601 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35602 index 525bd3d..ef888b1 100644
35603 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35604 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35605 @@ -119,9 +119,9 @@
35606 ----------------------------------------------------------------------*/
35607
35608 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35609 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35610 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35611 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35612 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35613
35614 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35615 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35616 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35617 index 2f33760..835e50a 100644
35618 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35619 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35620 @@ -11,6 +11,7 @@
35621 #ifndef _XTENSA_CORE_H
35622 #define _XTENSA_CORE_H
35623
35624 +#include <linux/const.h>
35625
35626 /****************************************************************************
35627 Parameters Useful for Any Code, USER or PRIVILEGED
35628 @@ -112,9 +113,9 @@
35629 ----------------------------------------------------------------------*/
35630
35631 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35632 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35633 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35634 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35635 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35636
35637 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35638 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35639 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35640 index af00795..2bb8105 100644
35641 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35642 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35643 @@ -11,6 +11,7 @@
35644 #ifndef _XTENSA_CORE_CONFIGURATION_H
35645 #define _XTENSA_CORE_CONFIGURATION_H
35646
35647 +#include <linux/const.h>
35648
35649 /****************************************************************************
35650 Parameters Useful for Any Code, USER or PRIVILEGED
35651 @@ -118,9 +119,9 @@
35652 ----------------------------------------------------------------------*/
35653
35654 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35655 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35656 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35657 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35658 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35659
35660 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35661 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35662 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35663 index 4e491d9..c8e18e4 100644
35664 --- a/block/blk-cgroup.c
35665 +++ b/block/blk-cgroup.c
35666 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35667 static struct cgroup_subsys_state *
35668 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35669 {
35670 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35671 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35672 struct blkcg *blkcg;
35673
35674 if (!parent_css) {
35675 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35676
35677 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35678 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35679 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35680 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35681 done:
35682 spin_lock_init(&blkcg->lock);
35683 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35684 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35685 index 1855bf5..af12b06 100644
35686 --- a/block/blk-iopoll.c
35687 +++ b/block/blk-iopoll.c
35688 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35689 }
35690 EXPORT_SYMBOL(blk_iopoll_complete);
35691
35692 -static void blk_iopoll_softirq(struct softirq_action *h)
35693 +static __latent_entropy void blk_iopoll_softirq(void)
35694 {
35695 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35696 int rearm = 0, budget = blk_iopoll_budget;
35697 diff --git a/block/blk-map.c b/block/blk-map.c
35698 index 623e1cd..ca1e109 100644
35699 --- a/block/blk-map.c
35700 +++ b/block/blk-map.c
35701 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35702 if (!len || !kbuf)
35703 return -EINVAL;
35704
35705 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35706 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35707 if (do_copy)
35708 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35709 else
35710 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35711 index 57790c1..5e988dd 100644
35712 --- a/block/blk-softirq.c
35713 +++ b/block/blk-softirq.c
35714 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35715 * Softirq action handler - move entries to local list and loop over them
35716 * while passing them to the queue registered handler.
35717 */
35718 -static void blk_done_softirq(struct softirq_action *h)
35719 +static __latent_entropy void blk_done_softirq(void)
35720 {
35721 struct list_head *cpu_list, local_list;
35722
35723 diff --git a/block/bsg.c b/block/bsg.c
35724 index 420a5a9..23834aa 100644
35725 --- a/block/bsg.c
35726 +++ b/block/bsg.c
35727 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35728 struct sg_io_v4 *hdr, struct bsg_device *bd,
35729 fmode_t has_write_perm)
35730 {
35731 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35732 + unsigned char *cmdptr;
35733 +
35734 if (hdr->request_len > BLK_MAX_CDB) {
35735 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35736 if (!rq->cmd)
35737 return -ENOMEM;
35738 - }
35739 + cmdptr = rq->cmd;
35740 + } else
35741 + cmdptr = tmpcmd;
35742
35743 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35744 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35745 hdr->request_len))
35746 return -EFAULT;
35747
35748 + if (cmdptr != rq->cmd)
35749 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35750 +
35751 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35752 if (blk_verify_command(rq->cmd, has_write_perm))
35753 return -EPERM;
35754 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35755 index fbd5a67..f24fd95 100644
35756 --- a/block/compat_ioctl.c
35757 +++ b/block/compat_ioctl.c
35758 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35759 cgc = compat_alloc_user_space(sizeof(*cgc));
35760 cgc32 = compat_ptr(arg);
35761
35762 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35763 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35764 get_user(data, &cgc32->buffer) ||
35765 put_user(compat_ptr(data), &cgc->buffer) ||
35766 copy_in_user(&cgc->buflen, &cgc32->buflen,
35767 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35768 err |= __get_user(f->spec1, &uf->spec1);
35769 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35770 err |= __get_user(name, &uf->name);
35771 - f->name = compat_ptr(name);
35772 + f->name = (void __force_kernel *)compat_ptr(name);
35773 if (err) {
35774 err = -EFAULT;
35775 goto out;
35776 diff --git a/block/genhd.c b/block/genhd.c
35777 index 791f419..89f21c4 100644
35778 --- a/block/genhd.c
35779 +++ b/block/genhd.c
35780 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35781
35782 /*
35783 * Register device numbers dev..(dev+range-1)
35784 - * range must be nonzero
35785 + * Noop if @range is zero.
35786 * The hash chain is sorted on range, so that subranges can override.
35787 */
35788 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35789 struct kobject *(*probe)(dev_t, int *, void *),
35790 int (*lock)(dev_t, void *), void *data)
35791 {
35792 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35793 + if (range)
35794 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35795 }
35796
35797 EXPORT_SYMBOL(blk_register_region);
35798
35799 +/* undo blk_register_region(), noop if @range is zero */
35800 void blk_unregister_region(dev_t devt, unsigned long range)
35801 {
35802 - kobj_unmap(bdev_map, devt, range);
35803 + if (range)
35804 + kobj_unmap(bdev_map, devt, range);
35805 }
35806
35807 EXPORT_SYMBOL(blk_unregister_region);
35808 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35809 index dc51f46..d5446a8 100644
35810 --- a/block/partitions/efi.c
35811 +++ b/block/partitions/efi.c
35812 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35813 if (!gpt)
35814 return NULL;
35815
35816 + if (!le32_to_cpu(gpt->num_partition_entries))
35817 + return NULL;
35818 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35819 + if (!pte)
35820 + return NULL;
35821 +
35822 count = le32_to_cpu(gpt->num_partition_entries) *
35823 le32_to_cpu(gpt->sizeof_partition_entry);
35824 - if (!count)
35825 - return NULL;
35826 - pte = kmalloc(count, GFP_KERNEL);
35827 - if (!pte)
35828 - return NULL;
35829 -
35830 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35831 (u8 *) pte, count) < count) {
35832 kfree(pte);
35833 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35834 index 625e3e4..b5339f9 100644
35835 --- a/block/scsi_ioctl.c
35836 +++ b/block/scsi_ioctl.c
35837 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35838 return put_user(0, p);
35839 }
35840
35841 -static int sg_get_timeout(struct request_queue *q)
35842 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35843 {
35844 return jiffies_to_clock_t(q->sg_timeout);
35845 }
35846 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35847 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35848 struct sg_io_hdr *hdr, fmode_t mode)
35849 {
35850 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35851 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35852 + unsigned char *cmdptr;
35853 +
35854 + if (rq->cmd != rq->__cmd)
35855 + cmdptr = rq->cmd;
35856 + else
35857 + cmdptr = tmpcmd;
35858 +
35859 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35860 return -EFAULT;
35861 +
35862 + if (cmdptr != rq->cmd)
35863 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35864 +
35865 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35866 return -EPERM;
35867
35868 @@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35869 int err;
35870 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35871 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35872 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35873 + unsigned char *cmdptr;
35874
35875 if (!sic)
35876 return -EINVAL;
35877 @@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35878 */
35879 err = -EFAULT;
35880 rq->cmd_len = cmdlen;
35881 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
35882 +
35883 + if (rq->cmd != rq->__cmd)
35884 + cmdptr = rq->cmd;
35885 + else
35886 + cmdptr = tmpcmd;
35887 +
35888 + if (copy_from_user(cmdptr, sic->data, cmdlen))
35889 goto error;
35890
35891 + if (rq->cmd != cmdptr)
35892 + memcpy(rq->cmd, cmdptr, cmdlen);
35893 +
35894 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35895 goto error;
35896
35897 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35898 index 7bdd61b..afec999 100644
35899 --- a/crypto/cryptd.c
35900 +++ b/crypto/cryptd.c
35901 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35902
35903 struct cryptd_blkcipher_request_ctx {
35904 crypto_completion_t complete;
35905 -};
35906 +} __no_const;
35907
35908 struct cryptd_hash_ctx {
35909 struct crypto_shash *child;
35910 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35911
35912 struct cryptd_aead_request_ctx {
35913 crypto_completion_t complete;
35914 -};
35915 +} __no_const;
35916
35917 static void cryptd_queue_worker(struct work_struct *work);
35918
35919 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35920 index f8c920c..ab2cb5a 100644
35921 --- a/crypto/pcrypt.c
35922 +++ b/crypto/pcrypt.c
35923 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35924 int ret;
35925
35926 pinst->kobj.kset = pcrypt_kset;
35927 - ret = kobject_add(&pinst->kobj, NULL, name);
35928 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35929 if (!ret)
35930 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35931
35932 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35933 index 15dddc1..b61cf0c 100644
35934 --- a/drivers/acpi/acpica/hwxfsleep.c
35935 +++ b/drivers/acpi/acpica/hwxfsleep.c
35936 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35937 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35938
35939 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35940 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35941 - acpi_hw_extended_sleep},
35942 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35943 - acpi_hw_extended_wake_prep},
35944 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35945 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35946 + .extended_function = acpi_hw_extended_sleep},
35947 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35948 + .extended_function = acpi_hw_extended_wake_prep},
35949 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35950 + .extended_function = acpi_hw_extended_wake}
35951 };
35952
35953 /*
35954 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35955 index 21ba34a..cb05966 100644
35956 --- a/drivers/acpi/apei/apei-internal.h
35957 +++ b/drivers/acpi/apei/apei-internal.h
35958 @@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35959 struct apei_exec_ins_type {
35960 u32 flags;
35961 apei_exec_ins_func_t run;
35962 -};
35963 +} __do_const;
35964
35965 struct apei_exec_context {
35966 u32 ip;
35967 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35968 index a30bc31..b91c4d5 100644
35969 --- a/drivers/acpi/apei/ghes.c
35970 +++ b/drivers/acpi/apei/ghes.c
35971 @@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35972 const struct acpi_hest_generic *generic,
35973 const struct acpi_generic_status *estatus)
35974 {
35975 - static atomic_t seqno;
35976 + static atomic_unchecked_t seqno;
35977 unsigned int curr_seqno;
35978 char pfx_seq[64];
35979
35980 @@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35981 else
35982 pfx = KERN_ERR;
35983 }
35984 - curr_seqno = atomic_inc_return(&seqno);
35985 + curr_seqno = atomic_inc_return_unchecked(&seqno);
35986 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35987 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35988 pfx_seq, generic->header.source_id);
35989 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35990 index a83e3c6..c3d617f 100644
35991 --- a/drivers/acpi/bgrt.c
35992 +++ b/drivers/acpi/bgrt.c
35993 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35994 if (!bgrt_image)
35995 return -ENODEV;
35996
35997 - bin_attr_image.private = bgrt_image;
35998 - bin_attr_image.size = bgrt_image_size;
35999 + pax_open_kernel();
36000 + *(void **)&bin_attr_image.private = bgrt_image;
36001 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36002 + pax_close_kernel();
36003
36004 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36005 if (!bgrt_kobj)
36006 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36007 index 078c4f7..410e272 100644
36008 --- a/drivers/acpi/blacklist.c
36009 +++ b/drivers/acpi/blacklist.c
36010 @@ -52,7 +52,7 @@ struct acpi_blacklist_item {
36011 u32 is_critical_error;
36012 };
36013
36014 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36015 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36016
36017 /*
36018 * POLICY: If *anything* doesn't work, put it on the blacklist.
36019 @@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36020 return 0;
36021 }
36022
36023 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36024 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36025 {
36026 .callback = dmi_disable_osi_vista,
36027 .ident = "Fujitsu Siemens",
36028 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36029 index 12b62f2..dc2aac8 100644
36030 --- a/drivers/acpi/custom_method.c
36031 +++ b/drivers/acpi/custom_method.c
36032 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36033 struct acpi_table_header table;
36034 acpi_status status;
36035
36036 +#ifdef CONFIG_GRKERNSEC_KMEM
36037 + return -EPERM;
36038 +#endif
36039 +
36040 if (!(*ppos)) {
36041 /* parse the table header to get the table length */
36042 if (count <= sizeof(struct acpi_table_header))
36043 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36044 index 644516d..643937e 100644
36045 --- a/drivers/acpi/processor_idle.c
36046 +++ b/drivers/acpi/processor_idle.c
36047 @@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36048 {
36049 int i, count = CPUIDLE_DRIVER_STATE_START;
36050 struct acpi_processor_cx *cx;
36051 - struct cpuidle_state *state;
36052 + cpuidle_state_no_const *state;
36053 struct cpuidle_driver *drv = &acpi_idle_driver;
36054
36055 if (!pr->flags.power_setup_done)
36056 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36057 index 6dbc3ca..b8b59a0 100644
36058 --- a/drivers/acpi/sysfs.c
36059 +++ b/drivers/acpi/sysfs.c
36060 @@ -425,11 +425,11 @@ static u32 num_counters;
36061 static struct attribute **all_attrs;
36062 static u32 acpi_gpe_count;
36063
36064 -static struct attribute_group interrupt_stats_attr_group = {
36065 +static attribute_group_no_const interrupt_stats_attr_group = {
36066 .name = "interrupts",
36067 };
36068
36069 -static struct kobj_attribute *counter_attrs;
36070 +static kobj_attribute_no_const *counter_attrs;
36071
36072 static void delete_gpe_attr_array(void)
36073 {
36074 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36075 index c482f8c..c832240 100644
36076 --- a/drivers/ata/libahci.c
36077 +++ b/drivers/ata/libahci.c
36078 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36079 }
36080 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36081
36082 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36083 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36084 struct ata_taskfile *tf, int is_cmd, u16 flags,
36085 unsigned long timeout_msec)
36086 {
36087 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36088 index 1a3dbd1..dfc6e5c 100644
36089 --- a/drivers/ata/libata-core.c
36090 +++ b/drivers/ata/libata-core.c
36091 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36092 static void ata_dev_xfermask(struct ata_device *dev);
36093 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36094
36095 -atomic_t ata_print_id = ATOMIC_INIT(0);
36096 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36097
36098 struct ata_force_param {
36099 const char *name;
36100 @@ -4850,7 +4850,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36101 struct ata_port *ap;
36102 unsigned int tag;
36103
36104 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36105 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36106 ap = qc->ap;
36107
36108 qc->flags = 0;
36109 @@ -4866,7 +4866,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36110 struct ata_port *ap;
36111 struct ata_link *link;
36112
36113 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36114 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36115 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36116 ap = qc->ap;
36117 link = qc->dev->link;
36118 @@ -5985,6 +5985,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36119 return;
36120
36121 spin_lock(&lock);
36122 + pax_open_kernel();
36123
36124 for (cur = ops->inherits; cur; cur = cur->inherits) {
36125 void **inherit = (void **)cur;
36126 @@ -5998,8 +5999,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36127 if (IS_ERR(*pp))
36128 *pp = NULL;
36129
36130 - ops->inherits = NULL;
36131 + *(struct ata_port_operations **)&ops->inherits = NULL;
36132
36133 + pax_close_kernel();
36134 spin_unlock(&lock);
36135 }
36136
36137 @@ -6192,7 +6194,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36138
36139 /* give ports names and add SCSI hosts */
36140 for (i = 0; i < host->n_ports; i++) {
36141 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36142 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36143 host->ports[i]->local_port_no = i + 1;
36144 }
36145
36146 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36147 index ef8567d..8bdbd03 100644
36148 --- a/drivers/ata/libata-scsi.c
36149 +++ b/drivers/ata/libata-scsi.c
36150 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36151
36152 if (rc)
36153 return rc;
36154 - ap->print_id = atomic_inc_return(&ata_print_id);
36155 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36156 return 0;
36157 }
36158 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36159 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36160 index 45b5ab3..98446b8 100644
36161 --- a/drivers/ata/libata.h
36162 +++ b/drivers/ata/libata.h
36163 @@ -53,7 +53,7 @@ enum {
36164 ATA_DNXFER_QUIET = (1 << 31),
36165 };
36166
36167 -extern atomic_t ata_print_id;
36168 +extern atomic_unchecked_t ata_print_id;
36169 extern int atapi_passthru16;
36170 extern int libata_fua;
36171 extern int libata_noacpi;
36172 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36173 index 73492dd..ca2bff5 100644
36174 --- a/drivers/ata/pata_arasan_cf.c
36175 +++ b/drivers/ata/pata_arasan_cf.c
36176 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36177 /* Handle platform specific quirks */
36178 if (quirk) {
36179 if (quirk & CF_BROKEN_PIO) {
36180 - ap->ops->set_piomode = NULL;
36181 + pax_open_kernel();
36182 + *(void **)&ap->ops->set_piomode = NULL;
36183 + pax_close_kernel();
36184 ap->pio_mask = 0;
36185 }
36186 if (quirk & CF_BROKEN_MWDMA)
36187 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36188 index f9b983a..887b9d8 100644
36189 --- a/drivers/atm/adummy.c
36190 +++ b/drivers/atm/adummy.c
36191 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36192 vcc->pop(vcc, skb);
36193 else
36194 dev_kfree_skb_any(skb);
36195 - atomic_inc(&vcc->stats->tx);
36196 + atomic_inc_unchecked(&vcc->stats->tx);
36197
36198 return 0;
36199 }
36200 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36201 index 62a7607..cc4be104 100644
36202 --- a/drivers/atm/ambassador.c
36203 +++ b/drivers/atm/ambassador.c
36204 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36205 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36206
36207 // VC layer stats
36208 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36209 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36210
36211 // free the descriptor
36212 kfree (tx_descr);
36213 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36214 dump_skb ("<<<", vc, skb);
36215
36216 // VC layer stats
36217 - atomic_inc(&atm_vcc->stats->rx);
36218 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36219 __net_timestamp(skb);
36220 // end of our responsibility
36221 atm_vcc->push (atm_vcc, skb);
36222 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36223 } else {
36224 PRINTK (KERN_INFO, "dropped over-size frame");
36225 // should we count this?
36226 - atomic_inc(&atm_vcc->stats->rx_drop);
36227 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36228 }
36229
36230 } else {
36231 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36232 }
36233
36234 if (check_area (skb->data, skb->len)) {
36235 - atomic_inc(&atm_vcc->stats->tx_err);
36236 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36237 return -ENOMEM; // ?
36238 }
36239
36240 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36241 index 0e3f8f9..765a7a5 100644
36242 --- a/drivers/atm/atmtcp.c
36243 +++ b/drivers/atm/atmtcp.c
36244 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36245 if (vcc->pop) vcc->pop(vcc,skb);
36246 else dev_kfree_skb(skb);
36247 if (dev_data) return 0;
36248 - atomic_inc(&vcc->stats->tx_err);
36249 + atomic_inc_unchecked(&vcc->stats->tx_err);
36250 return -ENOLINK;
36251 }
36252 size = skb->len+sizeof(struct atmtcp_hdr);
36253 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36254 if (!new_skb) {
36255 if (vcc->pop) vcc->pop(vcc,skb);
36256 else dev_kfree_skb(skb);
36257 - atomic_inc(&vcc->stats->tx_err);
36258 + atomic_inc_unchecked(&vcc->stats->tx_err);
36259 return -ENOBUFS;
36260 }
36261 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36262 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36263 if (vcc->pop) vcc->pop(vcc,skb);
36264 else dev_kfree_skb(skb);
36265 out_vcc->push(out_vcc,new_skb);
36266 - atomic_inc(&vcc->stats->tx);
36267 - atomic_inc(&out_vcc->stats->rx);
36268 + atomic_inc_unchecked(&vcc->stats->tx);
36269 + atomic_inc_unchecked(&out_vcc->stats->rx);
36270 return 0;
36271 }
36272
36273 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36274 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36275 read_unlock(&vcc_sklist_lock);
36276 if (!out_vcc) {
36277 - atomic_inc(&vcc->stats->tx_err);
36278 + atomic_inc_unchecked(&vcc->stats->tx_err);
36279 goto done;
36280 }
36281 skb_pull(skb,sizeof(struct atmtcp_hdr));
36282 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36283 __net_timestamp(new_skb);
36284 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36285 out_vcc->push(out_vcc,new_skb);
36286 - atomic_inc(&vcc->stats->tx);
36287 - atomic_inc(&out_vcc->stats->rx);
36288 + atomic_inc_unchecked(&vcc->stats->tx);
36289 + atomic_inc_unchecked(&out_vcc->stats->rx);
36290 done:
36291 if (vcc->pop) vcc->pop(vcc,skb);
36292 else dev_kfree_skb(skb);
36293 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36294 index b1955ba..b179940 100644
36295 --- a/drivers/atm/eni.c
36296 +++ b/drivers/atm/eni.c
36297 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36298 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36299 vcc->dev->number);
36300 length = 0;
36301 - atomic_inc(&vcc->stats->rx_err);
36302 + atomic_inc_unchecked(&vcc->stats->rx_err);
36303 }
36304 else {
36305 length = ATM_CELL_SIZE-1; /* no HEC */
36306 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36307 size);
36308 }
36309 eff = length = 0;
36310 - atomic_inc(&vcc->stats->rx_err);
36311 + atomic_inc_unchecked(&vcc->stats->rx_err);
36312 }
36313 else {
36314 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36315 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36316 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36317 vcc->dev->number,vcc->vci,length,size << 2,descr);
36318 length = eff = 0;
36319 - atomic_inc(&vcc->stats->rx_err);
36320 + atomic_inc_unchecked(&vcc->stats->rx_err);
36321 }
36322 }
36323 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36324 @@ -767,7 +767,7 @@ rx_dequeued++;
36325 vcc->push(vcc,skb);
36326 pushed++;
36327 }
36328 - atomic_inc(&vcc->stats->rx);
36329 + atomic_inc_unchecked(&vcc->stats->rx);
36330 }
36331 wake_up(&eni_dev->rx_wait);
36332 }
36333 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36334 PCI_DMA_TODEVICE);
36335 if (vcc->pop) vcc->pop(vcc,skb);
36336 else dev_kfree_skb_irq(skb);
36337 - atomic_inc(&vcc->stats->tx);
36338 + atomic_inc_unchecked(&vcc->stats->tx);
36339 wake_up(&eni_dev->tx_wait);
36340 dma_complete++;
36341 }
36342 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36343 index b41c948..a002b17 100644
36344 --- a/drivers/atm/firestream.c
36345 +++ b/drivers/atm/firestream.c
36346 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36347 }
36348 }
36349
36350 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36351 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36352
36353 fs_dprintk (FS_DEBUG_TXMEM, "i");
36354 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36355 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36356 #endif
36357 skb_put (skb, qe->p1 & 0xffff);
36358 ATM_SKB(skb)->vcc = atm_vcc;
36359 - atomic_inc(&atm_vcc->stats->rx);
36360 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36361 __net_timestamp(skb);
36362 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36363 atm_vcc->push (atm_vcc, skb);
36364 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36365 kfree (pe);
36366 }
36367 if (atm_vcc)
36368 - atomic_inc(&atm_vcc->stats->rx_drop);
36369 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36370 break;
36371 case 0x1f: /* Reassembly abort: no buffers. */
36372 /* Silently increment error counter. */
36373 if (atm_vcc)
36374 - atomic_inc(&atm_vcc->stats->rx_drop);
36375 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36376 break;
36377 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36378 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36379 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36380 index 204814e..cede831 100644
36381 --- a/drivers/atm/fore200e.c
36382 +++ b/drivers/atm/fore200e.c
36383 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36384 #endif
36385 /* check error condition */
36386 if (*entry->status & STATUS_ERROR)
36387 - atomic_inc(&vcc->stats->tx_err);
36388 + atomic_inc_unchecked(&vcc->stats->tx_err);
36389 else
36390 - atomic_inc(&vcc->stats->tx);
36391 + atomic_inc_unchecked(&vcc->stats->tx);
36392 }
36393 }
36394
36395 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36396 if (skb == NULL) {
36397 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36398
36399 - atomic_inc(&vcc->stats->rx_drop);
36400 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36401 return -ENOMEM;
36402 }
36403
36404 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36405
36406 dev_kfree_skb_any(skb);
36407
36408 - atomic_inc(&vcc->stats->rx_drop);
36409 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36410 return -ENOMEM;
36411 }
36412
36413 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36414
36415 vcc->push(vcc, skb);
36416 - atomic_inc(&vcc->stats->rx);
36417 + atomic_inc_unchecked(&vcc->stats->rx);
36418
36419 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36420
36421 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36422 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36423 fore200e->atm_dev->number,
36424 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36425 - atomic_inc(&vcc->stats->rx_err);
36426 + atomic_inc_unchecked(&vcc->stats->rx_err);
36427 }
36428 }
36429
36430 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36431 goto retry_here;
36432 }
36433
36434 - atomic_inc(&vcc->stats->tx_err);
36435 + atomic_inc_unchecked(&vcc->stats->tx_err);
36436
36437 fore200e->tx_sat++;
36438 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36439 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36440 index 8557adc..3fb5d55 100644
36441 --- a/drivers/atm/he.c
36442 +++ b/drivers/atm/he.c
36443 @@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36444
36445 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36446 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36447 - atomic_inc(&vcc->stats->rx_drop);
36448 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36449 goto return_host_buffers;
36450 }
36451
36452 @@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36453 RBRQ_LEN_ERR(he_dev->rbrq_head)
36454 ? "LEN_ERR" : "",
36455 vcc->vpi, vcc->vci);
36456 - atomic_inc(&vcc->stats->rx_err);
36457 + atomic_inc_unchecked(&vcc->stats->rx_err);
36458 goto return_host_buffers;
36459 }
36460
36461 @@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36462 vcc->push(vcc, skb);
36463 spin_lock(&he_dev->global_lock);
36464
36465 - atomic_inc(&vcc->stats->rx);
36466 + atomic_inc_unchecked(&vcc->stats->rx);
36467
36468 return_host_buffers:
36469 ++pdus_assembled;
36470 @@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36471 tpd->vcc->pop(tpd->vcc, tpd->skb);
36472 else
36473 dev_kfree_skb_any(tpd->skb);
36474 - atomic_inc(&tpd->vcc->stats->tx_err);
36475 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36476 }
36477 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36478 return;
36479 @@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36480 vcc->pop(vcc, skb);
36481 else
36482 dev_kfree_skb_any(skb);
36483 - atomic_inc(&vcc->stats->tx_err);
36484 + atomic_inc_unchecked(&vcc->stats->tx_err);
36485 return -EINVAL;
36486 }
36487
36488 @@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36489 vcc->pop(vcc, skb);
36490 else
36491 dev_kfree_skb_any(skb);
36492 - atomic_inc(&vcc->stats->tx_err);
36493 + atomic_inc_unchecked(&vcc->stats->tx_err);
36494 return -EINVAL;
36495 }
36496 #endif
36497 @@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36498 vcc->pop(vcc, skb);
36499 else
36500 dev_kfree_skb_any(skb);
36501 - atomic_inc(&vcc->stats->tx_err);
36502 + atomic_inc_unchecked(&vcc->stats->tx_err);
36503 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36504 return -ENOMEM;
36505 }
36506 @@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36507 vcc->pop(vcc, skb);
36508 else
36509 dev_kfree_skb_any(skb);
36510 - atomic_inc(&vcc->stats->tx_err);
36511 + atomic_inc_unchecked(&vcc->stats->tx_err);
36512 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36513 return -ENOMEM;
36514 }
36515 @@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36516 __enqueue_tpd(he_dev, tpd, cid);
36517 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36518
36519 - atomic_inc(&vcc->stats->tx);
36520 + atomic_inc_unchecked(&vcc->stats->tx);
36521
36522 return 0;
36523 }
36524 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36525 index 1dc0519..1aadaf7 100644
36526 --- a/drivers/atm/horizon.c
36527 +++ b/drivers/atm/horizon.c
36528 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36529 {
36530 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36531 // VC layer stats
36532 - atomic_inc(&vcc->stats->rx);
36533 + atomic_inc_unchecked(&vcc->stats->rx);
36534 __net_timestamp(skb);
36535 // end of our responsibility
36536 vcc->push (vcc, skb);
36537 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36538 dev->tx_iovec = NULL;
36539
36540 // VC layer stats
36541 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36542 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36543
36544 // free the skb
36545 hrz_kfree_skb (skb);
36546 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36547 index 1bdf104..9dc44b1 100644
36548 --- a/drivers/atm/idt77252.c
36549 +++ b/drivers/atm/idt77252.c
36550 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36551 else
36552 dev_kfree_skb(skb);
36553
36554 - atomic_inc(&vcc->stats->tx);
36555 + atomic_inc_unchecked(&vcc->stats->tx);
36556 }
36557
36558 atomic_dec(&scq->used);
36559 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36560 if ((sb = dev_alloc_skb(64)) == NULL) {
36561 printk("%s: Can't allocate buffers for aal0.\n",
36562 card->name);
36563 - atomic_add(i, &vcc->stats->rx_drop);
36564 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36565 break;
36566 }
36567 if (!atm_charge(vcc, sb->truesize)) {
36568 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36569 card->name);
36570 - atomic_add(i - 1, &vcc->stats->rx_drop);
36571 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36572 dev_kfree_skb(sb);
36573 break;
36574 }
36575 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36576 ATM_SKB(sb)->vcc = vcc;
36577 __net_timestamp(sb);
36578 vcc->push(vcc, sb);
36579 - atomic_inc(&vcc->stats->rx);
36580 + atomic_inc_unchecked(&vcc->stats->rx);
36581
36582 cell += ATM_CELL_PAYLOAD;
36583 }
36584 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36585 "(CDC: %08x)\n",
36586 card->name, len, rpp->len, readl(SAR_REG_CDC));
36587 recycle_rx_pool_skb(card, rpp);
36588 - atomic_inc(&vcc->stats->rx_err);
36589 + atomic_inc_unchecked(&vcc->stats->rx_err);
36590 return;
36591 }
36592 if (stat & SAR_RSQE_CRC) {
36593 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36594 recycle_rx_pool_skb(card, rpp);
36595 - atomic_inc(&vcc->stats->rx_err);
36596 + atomic_inc_unchecked(&vcc->stats->rx_err);
36597 return;
36598 }
36599 if (skb_queue_len(&rpp->queue) > 1) {
36600 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36601 RXPRINTK("%s: Can't alloc RX skb.\n",
36602 card->name);
36603 recycle_rx_pool_skb(card, rpp);
36604 - atomic_inc(&vcc->stats->rx_err);
36605 + atomic_inc_unchecked(&vcc->stats->rx_err);
36606 return;
36607 }
36608 if (!atm_charge(vcc, skb->truesize)) {
36609 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36610 __net_timestamp(skb);
36611
36612 vcc->push(vcc, skb);
36613 - atomic_inc(&vcc->stats->rx);
36614 + atomic_inc_unchecked(&vcc->stats->rx);
36615
36616 return;
36617 }
36618 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36619 __net_timestamp(skb);
36620
36621 vcc->push(vcc, skb);
36622 - atomic_inc(&vcc->stats->rx);
36623 + atomic_inc_unchecked(&vcc->stats->rx);
36624
36625 if (skb->truesize > SAR_FB_SIZE_3)
36626 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36627 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36628 if (vcc->qos.aal != ATM_AAL0) {
36629 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36630 card->name, vpi, vci);
36631 - atomic_inc(&vcc->stats->rx_drop);
36632 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36633 goto drop;
36634 }
36635
36636 if ((sb = dev_alloc_skb(64)) == NULL) {
36637 printk("%s: Can't allocate buffers for AAL0.\n",
36638 card->name);
36639 - atomic_inc(&vcc->stats->rx_err);
36640 + atomic_inc_unchecked(&vcc->stats->rx_err);
36641 goto drop;
36642 }
36643
36644 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36645 ATM_SKB(sb)->vcc = vcc;
36646 __net_timestamp(sb);
36647 vcc->push(vcc, sb);
36648 - atomic_inc(&vcc->stats->rx);
36649 + atomic_inc_unchecked(&vcc->stats->rx);
36650
36651 drop:
36652 skb_pull(queue, 64);
36653 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36654
36655 if (vc == NULL) {
36656 printk("%s: NULL connection in send().\n", card->name);
36657 - atomic_inc(&vcc->stats->tx_err);
36658 + atomic_inc_unchecked(&vcc->stats->tx_err);
36659 dev_kfree_skb(skb);
36660 return -EINVAL;
36661 }
36662 if (!test_bit(VCF_TX, &vc->flags)) {
36663 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36664 - atomic_inc(&vcc->stats->tx_err);
36665 + atomic_inc_unchecked(&vcc->stats->tx_err);
36666 dev_kfree_skb(skb);
36667 return -EINVAL;
36668 }
36669 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36670 break;
36671 default:
36672 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36673 - atomic_inc(&vcc->stats->tx_err);
36674 + atomic_inc_unchecked(&vcc->stats->tx_err);
36675 dev_kfree_skb(skb);
36676 return -EINVAL;
36677 }
36678
36679 if (skb_shinfo(skb)->nr_frags != 0) {
36680 printk("%s: No scatter-gather yet.\n", card->name);
36681 - atomic_inc(&vcc->stats->tx_err);
36682 + atomic_inc_unchecked(&vcc->stats->tx_err);
36683 dev_kfree_skb(skb);
36684 return -EINVAL;
36685 }
36686 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36687
36688 err = queue_skb(card, vc, skb, oam);
36689 if (err) {
36690 - atomic_inc(&vcc->stats->tx_err);
36691 + atomic_inc_unchecked(&vcc->stats->tx_err);
36692 dev_kfree_skb(skb);
36693 return err;
36694 }
36695 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36696 skb = dev_alloc_skb(64);
36697 if (!skb) {
36698 printk("%s: Out of memory in send_oam().\n", card->name);
36699 - atomic_inc(&vcc->stats->tx_err);
36700 + atomic_inc_unchecked(&vcc->stats->tx_err);
36701 return -ENOMEM;
36702 }
36703 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36704 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36705 index 4217f29..88f547a 100644
36706 --- a/drivers/atm/iphase.c
36707 +++ b/drivers/atm/iphase.c
36708 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36709 status = (u_short) (buf_desc_ptr->desc_mode);
36710 if (status & (RX_CER | RX_PTE | RX_OFL))
36711 {
36712 - atomic_inc(&vcc->stats->rx_err);
36713 + atomic_inc_unchecked(&vcc->stats->rx_err);
36714 IF_ERR(printk("IA: bad packet, dropping it");)
36715 if (status & RX_CER) {
36716 IF_ERR(printk(" cause: packet CRC error\n");)
36717 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36718 len = dma_addr - buf_addr;
36719 if (len > iadev->rx_buf_sz) {
36720 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36721 - atomic_inc(&vcc->stats->rx_err);
36722 + atomic_inc_unchecked(&vcc->stats->rx_err);
36723 goto out_free_desc;
36724 }
36725
36726 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36727 ia_vcc = INPH_IA_VCC(vcc);
36728 if (ia_vcc == NULL)
36729 {
36730 - atomic_inc(&vcc->stats->rx_err);
36731 + atomic_inc_unchecked(&vcc->stats->rx_err);
36732 atm_return(vcc, skb->truesize);
36733 dev_kfree_skb_any(skb);
36734 goto INCR_DLE;
36735 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36736 if ((length > iadev->rx_buf_sz) || (length >
36737 (skb->len - sizeof(struct cpcs_trailer))))
36738 {
36739 - atomic_inc(&vcc->stats->rx_err);
36740 + atomic_inc_unchecked(&vcc->stats->rx_err);
36741 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36742 length, skb->len);)
36743 atm_return(vcc, skb->truesize);
36744 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36745
36746 IF_RX(printk("rx_dle_intr: skb push");)
36747 vcc->push(vcc,skb);
36748 - atomic_inc(&vcc->stats->rx);
36749 + atomic_inc_unchecked(&vcc->stats->rx);
36750 iadev->rx_pkt_cnt++;
36751 }
36752 INCR_DLE:
36753 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36754 {
36755 struct k_sonet_stats *stats;
36756 stats = &PRIV(_ia_dev[board])->sonet_stats;
36757 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36758 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36759 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36760 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36761 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36762 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36763 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36764 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36765 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36766 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36767 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36768 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36769 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36770 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36771 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36772 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36773 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36774 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36775 }
36776 ia_cmds.status = 0;
36777 break;
36778 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36779 if ((desc == 0) || (desc > iadev->num_tx_desc))
36780 {
36781 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36782 - atomic_inc(&vcc->stats->tx);
36783 + atomic_inc_unchecked(&vcc->stats->tx);
36784 if (vcc->pop)
36785 vcc->pop(vcc, skb);
36786 else
36787 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36788 ATM_DESC(skb) = vcc->vci;
36789 skb_queue_tail(&iadev->tx_dma_q, skb);
36790
36791 - atomic_inc(&vcc->stats->tx);
36792 + atomic_inc_unchecked(&vcc->stats->tx);
36793 iadev->tx_pkt_cnt++;
36794 /* Increment transaction counter */
36795 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36796
36797 #if 0
36798 /* add flow control logic */
36799 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36800 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36801 if (iavcc->vc_desc_cnt > 10) {
36802 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36803 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36804 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36805 index fa7d701..1e404c7 100644
36806 --- a/drivers/atm/lanai.c
36807 +++ b/drivers/atm/lanai.c
36808 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36809 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36810 lanai_endtx(lanai, lvcc);
36811 lanai_free_skb(lvcc->tx.atmvcc, skb);
36812 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36813 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36814 }
36815
36816 /* Try to fill the buffer - don't call unless there is backlog */
36817 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36818 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36819 __net_timestamp(skb);
36820 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36821 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36822 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36823 out:
36824 lvcc->rx.buf.ptr = end;
36825 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36826 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36827 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36828 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36829 lanai->stats.service_rxnotaal5++;
36830 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36831 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36832 return 0;
36833 }
36834 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36835 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36836 int bytes;
36837 read_unlock(&vcc_sklist_lock);
36838 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36839 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36840 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36841 lvcc->stats.x.aal5.service_trash++;
36842 bytes = (SERVICE_GET_END(s) * 16) -
36843 (((unsigned long) lvcc->rx.buf.ptr) -
36844 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36845 }
36846 if (s & SERVICE_STREAM) {
36847 read_unlock(&vcc_sklist_lock);
36848 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36849 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36850 lvcc->stats.x.aal5.service_stream++;
36851 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36852 "PDU on VCI %d!\n", lanai->number, vci);
36853 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36854 return 0;
36855 }
36856 DPRINTK("got rx crc error on vci %d\n", vci);
36857 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36858 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36859 lvcc->stats.x.aal5.service_rxcrc++;
36860 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36861 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36862 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36863 index 5aca5f4..ce3a6b0 100644
36864 --- a/drivers/atm/nicstar.c
36865 +++ b/drivers/atm/nicstar.c
36866 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36867 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36868 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36869 card->index);
36870 - atomic_inc(&vcc->stats->tx_err);
36871 + atomic_inc_unchecked(&vcc->stats->tx_err);
36872 dev_kfree_skb_any(skb);
36873 return -EINVAL;
36874 }
36875 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36876 if (!vc->tx) {
36877 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36878 card->index);
36879 - atomic_inc(&vcc->stats->tx_err);
36880 + atomic_inc_unchecked(&vcc->stats->tx_err);
36881 dev_kfree_skb_any(skb);
36882 return -EINVAL;
36883 }
36884 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36885 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36886 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36887 card->index);
36888 - atomic_inc(&vcc->stats->tx_err);
36889 + atomic_inc_unchecked(&vcc->stats->tx_err);
36890 dev_kfree_skb_any(skb);
36891 return -EINVAL;
36892 }
36893
36894 if (skb_shinfo(skb)->nr_frags != 0) {
36895 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36896 - atomic_inc(&vcc->stats->tx_err);
36897 + atomic_inc_unchecked(&vcc->stats->tx_err);
36898 dev_kfree_skb_any(skb);
36899 return -EINVAL;
36900 }
36901 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36902 }
36903
36904 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36905 - atomic_inc(&vcc->stats->tx_err);
36906 + atomic_inc_unchecked(&vcc->stats->tx_err);
36907 dev_kfree_skb_any(skb);
36908 return -EIO;
36909 }
36910 - atomic_inc(&vcc->stats->tx);
36911 + atomic_inc_unchecked(&vcc->stats->tx);
36912
36913 return 0;
36914 }
36915 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36916 printk
36917 ("nicstar%d: Can't allocate buffers for aal0.\n",
36918 card->index);
36919 - atomic_add(i, &vcc->stats->rx_drop);
36920 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36921 break;
36922 }
36923 if (!atm_charge(vcc, sb->truesize)) {
36924 RXPRINTK
36925 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36926 card->index);
36927 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36928 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36929 dev_kfree_skb_any(sb);
36930 break;
36931 }
36932 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36933 ATM_SKB(sb)->vcc = vcc;
36934 __net_timestamp(sb);
36935 vcc->push(vcc, sb);
36936 - atomic_inc(&vcc->stats->rx);
36937 + atomic_inc_unchecked(&vcc->stats->rx);
36938 cell += ATM_CELL_PAYLOAD;
36939 }
36940
36941 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36942 if (iovb == NULL) {
36943 printk("nicstar%d: Out of iovec buffers.\n",
36944 card->index);
36945 - atomic_inc(&vcc->stats->rx_drop);
36946 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36947 recycle_rx_buf(card, skb);
36948 return;
36949 }
36950 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36951 small or large buffer itself. */
36952 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36953 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36954 - atomic_inc(&vcc->stats->rx_err);
36955 + atomic_inc_unchecked(&vcc->stats->rx_err);
36956 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36957 NS_MAX_IOVECS);
36958 NS_PRV_IOVCNT(iovb) = 0;
36959 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36960 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36961 card->index);
36962 which_list(card, skb);
36963 - atomic_inc(&vcc->stats->rx_err);
36964 + atomic_inc_unchecked(&vcc->stats->rx_err);
36965 recycle_rx_buf(card, skb);
36966 vc->rx_iov = NULL;
36967 recycle_iov_buf(card, iovb);
36968 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36969 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36970 card->index);
36971 which_list(card, skb);
36972 - atomic_inc(&vcc->stats->rx_err);
36973 + atomic_inc_unchecked(&vcc->stats->rx_err);
36974 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36975 NS_PRV_IOVCNT(iovb));
36976 vc->rx_iov = NULL;
36977 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36978 printk(" - PDU size mismatch.\n");
36979 else
36980 printk(".\n");
36981 - atomic_inc(&vcc->stats->rx_err);
36982 + atomic_inc_unchecked(&vcc->stats->rx_err);
36983 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36984 NS_PRV_IOVCNT(iovb));
36985 vc->rx_iov = NULL;
36986 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36987 /* skb points to a small buffer */
36988 if (!atm_charge(vcc, skb->truesize)) {
36989 push_rxbufs(card, skb);
36990 - atomic_inc(&vcc->stats->rx_drop);
36991 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36992 } else {
36993 skb_put(skb, len);
36994 dequeue_sm_buf(card, skb);
36995 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36996 ATM_SKB(skb)->vcc = vcc;
36997 __net_timestamp(skb);
36998 vcc->push(vcc, skb);
36999 - atomic_inc(&vcc->stats->rx);
37000 + atomic_inc_unchecked(&vcc->stats->rx);
37001 }
37002 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37003 struct sk_buff *sb;
37004 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37005 if (len <= NS_SMBUFSIZE) {
37006 if (!atm_charge(vcc, sb->truesize)) {
37007 push_rxbufs(card, sb);
37008 - atomic_inc(&vcc->stats->rx_drop);
37009 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37010 } else {
37011 skb_put(sb, len);
37012 dequeue_sm_buf(card, sb);
37013 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37014 ATM_SKB(sb)->vcc = vcc;
37015 __net_timestamp(sb);
37016 vcc->push(vcc, sb);
37017 - atomic_inc(&vcc->stats->rx);
37018 + atomic_inc_unchecked(&vcc->stats->rx);
37019 }
37020
37021 push_rxbufs(card, skb);
37022 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37023
37024 if (!atm_charge(vcc, skb->truesize)) {
37025 push_rxbufs(card, skb);
37026 - atomic_inc(&vcc->stats->rx_drop);
37027 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37028 } else {
37029 dequeue_lg_buf(card, skb);
37030 #ifdef NS_USE_DESTRUCTORS
37031 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37032 ATM_SKB(skb)->vcc = vcc;
37033 __net_timestamp(skb);
37034 vcc->push(vcc, skb);
37035 - atomic_inc(&vcc->stats->rx);
37036 + atomic_inc_unchecked(&vcc->stats->rx);
37037 }
37038
37039 push_rxbufs(card, sb);
37040 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37041 printk
37042 ("nicstar%d: Out of huge buffers.\n",
37043 card->index);
37044 - atomic_inc(&vcc->stats->rx_drop);
37045 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37046 recycle_iovec_rx_bufs(card,
37047 (struct iovec *)
37048 iovb->data,
37049 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37050 card->hbpool.count++;
37051 } else
37052 dev_kfree_skb_any(hb);
37053 - atomic_inc(&vcc->stats->rx_drop);
37054 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37055 } else {
37056 /* Copy the small buffer to the huge buffer */
37057 sb = (struct sk_buff *)iov->iov_base;
37058 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37059 #endif /* NS_USE_DESTRUCTORS */
37060 __net_timestamp(hb);
37061 vcc->push(vcc, hb);
37062 - atomic_inc(&vcc->stats->rx);
37063 + atomic_inc_unchecked(&vcc->stats->rx);
37064 }
37065 }
37066
37067 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37068 index 32784d1..4a8434a 100644
37069 --- a/drivers/atm/solos-pci.c
37070 +++ b/drivers/atm/solos-pci.c
37071 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37072 }
37073 atm_charge(vcc, skb->truesize);
37074 vcc->push(vcc, skb);
37075 - atomic_inc(&vcc->stats->rx);
37076 + atomic_inc_unchecked(&vcc->stats->rx);
37077 break;
37078
37079 case PKT_STATUS:
37080 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37081 vcc = SKB_CB(oldskb)->vcc;
37082
37083 if (vcc) {
37084 - atomic_inc(&vcc->stats->tx);
37085 + atomic_inc_unchecked(&vcc->stats->tx);
37086 solos_pop(vcc, oldskb);
37087 } else {
37088 dev_kfree_skb_irq(oldskb);
37089 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37090 index 0215934..ce9f5b1 100644
37091 --- a/drivers/atm/suni.c
37092 +++ b/drivers/atm/suni.c
37093 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37094
37095
37096 #define ADD_LIMITED(s,v) \
37097 - atomic_add((v),&stats->s); \
37098 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37099 + atomic_add_unchecked((v),&stats->s); \
37100 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37101
37102
37103 static void suni_hz(unsigned long from_timer)
37104 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37105 index 5120a96..e2572bd 100644
37106 --- a/drivers/atm/uPD98402.c
37107 +++ b/drivers/atm/uPD98402.c
37108 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37109 struct sonet_stats tmp;
37110 int error = 0;
37111
37112 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37113 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37114 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37115 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37116 if (zero && !error) {
37117 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37118
37119
37120 #define ADD_LIMITED(s,v) \
37121 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37122 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37123 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37124 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37125 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37126 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37127
37128
37129 static void stat_event(struct atm_dev *dev)
37130 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37131 if (reason & uPD98402_INT_PFM) stat_event(dev);
37132 if (reason & uPD98402_INT_PCO) {
37133 (void) GET(PCOCR); /* clear interrupt cause */
37134 - atomic_add(GET(HECCT),
37135 + atomic_add_unchecked(GET(HECCT),
37136 &PRIV(dev)->sonet_stats.uncorr_hcs);
37137 }
37138 if ((reason & uPD98402_INT_RFO) &&
37139 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37140 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37141 uPD98402_INT_LOS),PIMR); /* enable them */
37142 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37143 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37144 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37145 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37146 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37147 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37148 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37149 return 0;
37150 }
37151
37152 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37153 index 969c3c2..9b72956 100644
37154 --- a/drivers/atm/zatm.c
37155 +++ b/drivers/atm/zatm.c
37156 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37157 }
37158 if (!size) {
37159 dev_kfree_skb_irq(skb);
37160 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37161 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37162 continue;
37163 }
37164 if (!atm_charge(vcc,skb->truesize)) {
37165 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37166 skb->len = size;
37167 ATM_SKB(skb)->vcc = vcc;
37168 vcc->push(vcc,skb);
37169 - atomic_inc(&vcc->stats->rx);
37170 + atomic_inc_unchecked(&vcc->stats->rx);
37171 }
37172 zout(pos & 0xffff,MTA(mbx));
37173 #if 0 /* probably a stupid idea */
37174 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37175 skb_queue_head(&zatm_vcc->backlog,skb);
37176 break;
37177 }
37178 - atomic_inc(&vcc->stats->tx);
37179 + atomic_inc_unchecked(&vcc->stats->tx);
37180 wake_up(&zatm_vcc->tx_wait);
37181 }
37182
37183 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37184 index 73f6c29..b0c0e13 100644
37185 --- a/drivers/base/bus.c
37186 +++ b/drivers/base/bus.c
37187 @@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37188 return -EINVAL;
37189
37190 mutex_lock(&subsys->p->mutex);
37191 - list_add_tail(&sif->node, &subsys->p->interfaces);
37192 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37193 if (sif->add_dev) {
37194 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37195 while ((dev = subsys_dev_iter_next(&iter)))
37196 @@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37197 subsys = sif->subsys;
37198
37199 mutex_lock(&subsys->p->mutex);
37200 - list_del_init(&sif->node);
37201 + pax_list_del_init((struct list_head *)&sif->node);
37202 if (sif->remove_dev) {
37203 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37204 while ((dev = subsys_dev_iter_next(&iter)))
37205 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37206 index 0f38201..6c2b444 100644
37207 --- a/drivers/base/devtmpfs.c
37208 +++ b/drivers/base/devtmpfs.c
37209 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37210 if (!thread)
37211 return 0;
37212
37213 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37214 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37215 if (err)
37216 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37217 else
37218 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37219 *err = sys_unshare(CLONE_NEWNS);
37220 if (*err)
37221 goto out;
37222 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37223 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37224 if (*err)
37225 goto out;
37226 - sys_chdir("/.."); /* will traverse into overmounted root */
37227 - sys_chroot(".");
37228 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37229 + sys_chroot((char __force_user *)".");
37230 complete(&setup_done);
37231 while (1) {
37232 spin_lock(&req_lock);
37233 diff --git a/drivers/base/node.c b/drivers/base/node.c
37234 index bc9f43b..29703b8 100644
37235 --- a/drivers/base/node.c
37236 +++ b/drivers/base/node.c
37237 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37238 struct node_attr {
37239 struct device_attribute attr;
37240 enum node_states state;
37241 -};
37242 +} __do_const;
37243
37244 static ssize_t show_node_state(struct device *dev,
37245 struct device_attribute *attr, char *buf)
37246 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37247 index bfb8955..4ebff34 100644
37248 --- a/drivers/base/power/domain.c
37249 +++ b/drivers/base/power/domain.c
37250 @@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37251
37252 if (dev->power.subsys_data->domain_data) {
37253 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37254 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37255 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37256 if (clear_td)
37257 - gpd_data->td = (struct gpd_timing_data){ 0 };
37258 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37259
37260 if (--gpd_data->refcount == 0) {
37261 dev->power.subsys_data->domain_data = NULL;
37262 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37263 {
37264 struct cpuidle_driver *cpuidle_drv;
37265 struct gpd_cpu_data *cpu_data;
37266 - struct cpuidle_state *idle_state;
37267 + cpuidle_state_no_const *idle_state;
37268 int ret = 0;
37269
37270 if (IS_ERR_OR_NULL(genpd) || state < 0)
37271 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37272 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37273 {
37274 struct gpd_cpu_data *cpu_data;
37275 - struct cpuidle_state *idle_state;
37276 + cpuidle_state_no_const *idle_state;
37277 int ret = 0;
37278
37279 if (IS_ERR_OR_NULL(genpd))
37280 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37281 index 03e089a..0e9560c 100644
37282 --- a/drivers/base/power/sysfs.c
37283 +++ b/drivers/base/power/sysfs.c
37284 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37285 return -EIO;
37286 }
37287 }
37288 - return sprintf(buf, p);
37289 + return sprintf(buf, "%s", p);
37290 }
37291
37292 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37293 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37294 index 2d56f41..8830f19 100644
37295 --- a/drivers/base/power/wakeup.c
37296 +++ b/drivers/base/power/wakeup.c
37297 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37298 * They need to be modified together atomically, so it's better to use one
37299 * atomic variable to hold them both.
37300 */
37301 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37302 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37303
37304 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37305 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37306
37307 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37308 {
37309 - unsigned int comb = atomic_read(&combined_event_count);
37310 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37311
37312 *cnt = (comb >> IN_PROGRESS_BITS);
37313 *inpr = comb & MAX_IN_PROGRESS;
37314 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37315 ws->start_prevent_time = ws->last_time;
37316
37317 /* Increment the counter of events in progress. */
37318 - cec = atomic_inc_return(&combined_event_count);
37319 + cec = atomic_inc_return_unchecked(&combined_event_count);
37320
37321 trace_wakeup_source_activate(ws->name, cec);
37322 }
37323 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37324 * Increment the counter of registered wakeup events and decrement the
37325 * couter of wakeup events in progress simultaneously.
37326 */
37327 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37328 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37329 trace_wakeup_source_deactivate(ws->name, cec);
37330
37331 split_counters(&cnt, &inpr);
37332 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37333 index e8d11b6..7b1b36f 100644
37334 --- a/drivers/base/syscore.c
37335 +++ b/drivers/base/syscore.c
37336 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37337 void register_syscore_ops(struct syscore_ops *ops)
37338 {
37339 mutex_lock(&syscore_ops_lock);
37340 - list_add_tail(&ops->node, &syscore_ops_list);
37341 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37342 mutex_unlock(&syscore_ops_lock);
37343 }
37344 EXPORT_SYMBOL_GPL(register_syscore_ops);
37345 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37346 void unregister_syscore_ops(struct syscore_ops *ops)
37347 {
37348 mutex_lock(&syscore_ops_lock);
37349 - list_del(&ops->node);
37350 + pax_list_del((struct list_head *)&ops->node);
37351 mutex_unlock(&syscore_ops_lock);
37352 }
37353 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37354 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37355 index b35fc4f..c902870 100644
37356 --- a/drivers/block/cciss.c
37357 +++ b/drivers/block/cciss.c
37358 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37359 while (!list_empty(&h->reqQ)) {
37360 c = list_entry(h->reqQ.next, CommandList_struct, list);
37361 /* can't do anything if fifo is full */
37362 - if ((h->access.fifo_full(h))) {
37363 + if ((h->access->fifo_full(h))) {
37364 dev_warn(&h->pdev->dev, "fifo full\n");
37365 break;
37366 }
37367 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37368 h->Qdepth--;
37369
37370 /* Tell the controller execute command */
37371 - h->access.submit_command(h, c);
37372 + h->access->submit_command(h, c);
37373
37374 /* Put job onto the completed Q */
37375 addQ(&h->cmpQ, c);
37376 @@ -3447,17 +3447,17 @@ startio:
37377
37378 static inline unsigned long get_next_completion(ctlr_info_t *h)
37379 {
37380 - return h->access.command_completed(h);
37381 + return h->access->command_completed(h);
37382 }
37383
37384 static inline int interrupt_pending(ctlr_info_t *h)
37385 {
37386 - return h->access.intr_pending(h);
37387 + return h->access->intr_pending(h);
37388 }
37389
37390 static inline long interrupt_not_for_us(ctlr_info_t *h)
37391 {
37392 - return ((h->access.intr_pending(h) == 0) ||
37393 + return ((h->access->intr_pending(h) == 0) ||
37394 (h->interrupts_enabled == 0));
37395 }
37396
37397 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37398 u32 a;
37399
37400 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37401 - return h->access.command_completed(h);
37402 + return h->access->command_completed(h);
37403
37404 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37405 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37406 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37407 trans_support & CFGTBL_Trans_use_short_tags);
37408
37409 /* Change the access methods to the performant access methods */
37410 - h->access = SA5_performant_access;
37411 + h->access = &SA5_performant_access;
37412 h->transMethod = CFGTBL_Trans_Performant;
37413
37414 return;
37415 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37416 if (prod_index < 0)
37417 return -ENODEV;
37418 h->product_name = products[prod_index].product_name;
37419 - h->access = *(products[prod_index].access);
37420 + h->access = products[prod_index].access;
37421
37422 if (cciss_board_disabled(h)) {
37423 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37424 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37425 }
37426
37427 /* make sure the board interrupts are off */
37428 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37429 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37430 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37431 if (rc)
37432 goto clean2;
37433 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37434 * fake ones to scoop up any residual completions.
37435 */
37436 spin_lock_irqsave(&h->lock, flags);
37437 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37438 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37439 spin_unlock_irqrestore(&h->lock, flags);
37440 free_irq(h->intr[h->intr_mode], h);
37441 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37442 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37443 dev_info(&h->pdev->dev, "Board READY.\n");
37444 dev_info(&h->pdev->dev,
37445 "Waiting for stale completions to drain.\n");
37446 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37447 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37448 msleep(10000);
37449 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37450 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37451
37452 rc = controller_reset_failed(h->cfgtable);
37453 if (rc)
37454 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37455 cciss_scsi_setup(h);
37456
37457 /* Turn the interrupts on so we can service requests */
37458 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37459 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37460
37461 /* Get the firmware version */
37462 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37463 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37464 kfree(flush_buf);
37465 if (return_code != IO_OK)
37466 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37467 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37468 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37469 free_irq(h->intr[h->intr_mode], h);
37470 }
37471
37472 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37473 index 7fda30e..2f27946 100644
37474 --- a/drivers/block/cciss.h
37475 +++ b/drivers/block/cciss.h
37476 @@ -101,7 +101,7 @@ struct ctlr_info
37477 /* information about each logical volume */
37478 drive_info_struct *drv[CISS_MAX_LUN];
37479
37480 - struct access_method access;
37481 + struct access_method *access;
37482
37483 /* queue and queue Info */
37484 struct list_head reqQ;
37485 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37486 }
37487
37488 static struct access_method SA5_access = {
37489 - SA5_submit_command,
37490 - SA5_intr_mask,
37491 - SA5_fifo_full,
37492 - SA5_intr_pending,
37493 - SA5_completed,
37494 + .submit_command = SA5_submit_command,
37495 + .set_intr_mask = SA5_intr_mask,
37496 + .fifo_full = SA5_fifo_full,
37497 + .intr_pending = SA5_intr_pending,
37498 + .command_completed = SA5_completed,
37499 };
37500
37501 static struct access_method SA5B_access = {
37502 - SA5_submit_command,
37503 - SA5B_intr_mask,
37504 - SA5_fifo_full,
37505 - SA5B_intr_pending,
37506 - SA5_completed,
37507 + .submit_command = SA5_submit_command,
37508 + .set_intr_mask = SA5B_intr_mask,
37509 + .fifo_full = SA5_fifo_full,
37510 + .intr_pending = SA5B_intr_pending,
37511 + .command_completed = SA5_completed,
37512 };
37513
37514 static struct access_method SA5_performant_access = {
37515 - SA5_submit_command,
37516 - SA5_performant_intr_mask,
37517 - SA5_fifo_full,
37518 - SA5_performant_intr_pending,
37519 - SA5_performant_completed,
37520 + .submit_command = SA5_submit_command,
37521 + .set_intr_mask = SA5_performant_intr_mask,
37522 + .fifo_full = SA5_fifo_full,
37523 + .intr_pending = SA5_performant_intr_pending,
37524 + .command_completed = SA5_performant_completed,
37525 };
37526
37527 struct board_type {
37528 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37529 index 2b94403..fd6ad1f 100644
37530 --- a/drivers/block/cpqarray.c
37531 +++ b/drivers/block/cpqarray.c
37532 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37533 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37534 goto Enomem4;
37535 }
37536 - hba[i]->access.set_intr_mask(hba[i], 0);
37537 + hba[i]->access->set_intr_mask(hba[i], 0);
37538 if (request_irq(hba[i]->intr, do_ida_intr,
37539 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37540 {
37541 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37542 add_timer(&hba[i]->timer);
37543
37544 /* Enable IRQ now that spinlock and rate limit timer are set up */
37545 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37546 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37547
37548 for(j=0; j<NWD; j++) {
37549 struct gendisk *disk = ida_gendisk[i][j];
37550 @@ -694,7 +694,7 @@ DBGINFO(
37551 for(i=0; i<NR_PRODUCTS; i++) {
37552 if (board_id == products[i].board_id) {
37553 c->product_name = products[i].product_name;
37554 - c->access = *(products[i].access);
37555 + c->access = products[i].access;
37556 break;
37557 }
37558 }
37559 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37560 hba[ctlr]->intr = intr;
37561 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37562 hba[ctlr]->product_name = products[j].product_name;
37563 - hba[ctlr]->access = *(products[j].access);
37564 + hba[ctlr]->access = products[j].access;
37565 hba[ctlr]->ctlr = ctlr;
37566 hba[ctlr]->board_id = board_id;
37567 hba[ctlr]->pci_dev = NULL; /* not PCI */
37568 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37569
37570 while((c = h->reqQ) != NULL) {
37571 /* Can't do anything if we're busy */
37572 - if (h->access.fifo_full(h) == 0)
37573 + if (h->access->fifo_full(h) == 0)
37574 return;
37575
37576 /* Get the first entry from the request Q */
37577 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37578 h->Qdepth--;
37579
37580 /* Tell the controller to do our bidding */
37581 - h->access.submit_command(h, c);
37582 + h->access->submit_command(h, c);
37583
37584 /* Get onto the completion Q */
37585 addQ(&h->cmpQ, c);
37586 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37587 unsigned long flags;
37588 __u32 a,a1;
37589
37590 - istat = h->access.intr_pending(h);
37591 + istat = h->access->intr_pending(h);
37592 /* Is this interrupt for us? */
37593 if (istat == 0)
37594 return IRQ_NONE;
37595 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37596 */
37597 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37598 if (istat & FIFO_NOT_EMPTY) {
37599 - while((a = h->access.command_completed(h))) {
37600 + while((a = h->access->command_completed(h))) {
37601 a1 = a; a &= ~3;
37602 if ((c = h->cmpQ) == NULL)
37603 {
37604 @@ -1448,11 +1448,11 @@ static int sendcmd(
37605 /*
37606 * Disable interrupt
37607 */
37608 - info_p->access.set_intr_mask(info_p, 0);
37609 + info_p->access->set_intr_mask(info_p, 0);
37610 /* Make sure there is room in the command FIFO */
37611 /* Actually it should be completely empty at this time. */
37612 for (i = 200000; i > 0; i--) {
37613 - temp = info_p->access.fifo_full(info_p);
37614 + temp = info_p->access->fifo_full(info_p);
37615 if (temp != 0) {
37616 break;
37617 }
37618 @@ -1465,7 +1465,7 @@ DBG(
37619 /*
37620 * Send the cmd
37621 */
37622 - info_p->access.submit_command(info_p, c);
37623 + info_p->access->submit_command(info_p, c);
37624 complete = pollcomplete(ctlr);
37625
37626 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37627 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37628 * we check the new geometry. Then turn interrupts back on when
37629 * we're done.
37630 */
37631 - host->access.set_intr_mask(host, 0);
37632 + host->access->set_intr_mask(host, 0);
37633 getgeometry(ctlr);
37634 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37635 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37636
37637 for(i=0; i<NWD; i++) {
37638 struct gendisk *disk = ida_gendisk[ctlr][i];
37639 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37640 /* Wait (up to 2 seconds) for a command to complete */
37641
37642 for (i = 200000; i > 0; i--) {
37643 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37644 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37645 if (done == 0) {
37646 udelay(10); /* a short fixed delay */
37647 } else
37648 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37649 index be73e9d..7fbf140 100644
37650 --- a/drivers/block/cpqarray.h
37651 +++ b/drivers/block/cpqarray.h
37652 @@ -99,7 +99,7 @@ struct ctlr_info {
37653 drv_info_t drv[NWD];
37654 struct proc_dir_entry *proc;
37655
37656 - struct access_method access;
37657 + struct access_method *access;
37658
37659 cmdlist_t *reqQ;
37660 cmdlist_t *cmpQ;
37661 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37662 index 0e06f0c..c47b81d 100644
37663 --- a/drivers/block/drbd/drbd_int.h
37664 +++ b/drivers/block/drbd/drbd_int.h
37665 @@ -582,7 +582,7 @@ struct drbd_epoch {
37666 struct drbd_tconn *tconn;
37667 struct list_head list;
37668 unsigned int barrier_nr;
37669 - atomic_t epoch_size; /* increased on every request added. */
37670 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37671 atomic_t active; /* increased on every req. added, and dec on every finished. */
37672 unsigned long flags;
37673 };
37674 @@ -1022,7 +1022,7 @@ struct drbd_conf {
37675 unsigned int al_tr_number;
37676 int al_tr_cycle;
37677 wait_queue_head_t seq_wait;
37678 - atomic_t packet_seq;
37679 + atomic_unchecked_t packet_seq;
37680 unsigned int peer_seq;
37681 spinlock_t peer_seq_lock;
37682 unsigned int minor;
37683 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37684 char __user *uoptval;
37685 int err;
37686
37687 - uoptval = (char __user __force *)optval;
37688 + uoptval = (char __force_user *)optval;
37689
37690 set_fs(KERNEL_DS);
37691 if (level == SOL_SOCKET)
37692 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37693 index 89c497c..9c736ae 100644
37694 --- a/drivers/block/drbd/drbd_interval.c
37695 +++ b/drivers/block/drbd/drbd_interval.c
37696 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37697 }
37698
37699 static const struct rb_augment_callbacks augment_callbacks = {
37700 - augment_propagate,
37701 - augment_copy,
37702 - augment_rotate,
37703 + .propagate = augment_propagate,
37704 + .copy = augment_copy,
37705 + .rotate = augment_rotate,
37706 };
37707
37708 /**
37709 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37710 index 9e3818b..7b64c92 100644
37711 --- a/drivers/block/drbd/drbd_main.c
37712 +++ b/drivers/block/drbd/drbd_main.c
37713 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37714 p->sector = sector;
37715 p->block_id = block_id;
37716 p->blksize = blksize;
37717 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37718 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37719 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37720 }
37721
37722 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37723 return -EIO;
37724 p->sector = cpu_to_be64(req->i.sector);
37725 p->block_id = (unsigned long)req;
37726 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37727 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37728 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37729 if (mdev->state.conn >= C_SYNC_SOURCE &&
37730 mdev->state.conn <= C_PAUSED_SYNC_T)
37731 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37732 {
37733 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37734
37735 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37736 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37737 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37738 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37739 kfree(tconn->current_epoch);
37740
37741 idr_destroy(&tconn->volumes);
37742 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37743 index c706d50..5e1b472 100644
37744 --- a/drivers/block/drbd/drbd_nl.c
37745 +++ b/drivers/block/drbd/drbd_nl.c
37746 @@ -3440,7 +3440,7 @@ out:
37747
37748 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37749 {
37750 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37751 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37752 struct sk_buff *msg;
37753 struct drbd_genlmsghdr *d_out;
37754 unsigned seq;
37755 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37756 return;
37757 }
37758
37759 - seq = atomic_inc_return(&drbd_genl_seq);
37760 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37761 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37762 if (!msg)
37763 goto failed;
37764 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37765 index 6fa6673..b7f97e9 100644
37766 --- a/drivers/block/drbd/drbd_receiver.c
37767 +++ b/drivers/block/drbd/drbd_receiver.c
37768 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37769 {
37770 int err;
37771
37772 - atomic_set(&mdev->packet_seq, 0);
37773 + atomic_set_unchecked(&mdev->packet_seq, 0);
37774 mdev->peer_seq = 0;
37775
37776 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37777 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37778 do {
37779 next_epoch = NULL;
37780
37781 - epoch_size = atomic_read(&epoch->epoch_size);
37782 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37783
37784 switch (ev & ~EV_CLEANUP) {
37785 case EV_PUT:
37786 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37787 rv = FE_DESTROYED;
37788 } else {
37789 epoch->flags = 0;
37790 - atomic_set(&epoch->epoch_size, 0);
37791 + atomic_set_unchecked(&epoch->epoch_size, 0);
37792 /* atomic_set(&epoch->active, 0); is already zero */
37793 if (rv == FE_STILL_LIVE)
37794 rv = FE_RECYCLED;
37795 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37796 conn_wait_active_ee_empty(tconn);
37797 drbd_flush(tconn);
37798
37799 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37800 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37801 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37802 if (epoch)
37803 break;
37804 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37805 }
37806
37807 epoch->flags = 0;
37808 - atomic_set(&epoch->epoch_size, 0);
37809 + atomic_set_unchecked(&epoch->epoch_size, 0);
37810 atomic_set(&epoch->active, 0);
37811
37812 spin_lock(&tconn->epoch_lock);
37813 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37814 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37815 list_add(&epoch->list, &tconn->current_epoch->list);
37816 tconn->current_epoch = epoch;
37817 tconn->epochs++;
37818 @@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37819
37820 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37821 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37822 - atomic_inc(&tconn->current_epoch->epoch_size);
37823 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37824 err2 = drbd_drain_block(mdev, pi->size);
37825 if (!err)
37826 err = err2;
37827 @@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37828
37829 spin_lock(&tconn->epoch_lock);
37830 peer_req->epoch = tconn->current_epoch;
37831 - atomic_inc(&peer_req->epoch->epoch_size);
37832 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37833 atomic_inc(&peer_req->epoch->active);
37834 spin_unlock(&tconn->epoch_lock);
37835
37836 @@ -4344,7 +4344,7 @@ struct data_cmd {
37837 int expect_payload;
37838 size_t pkt_size;
37839 int (*fn)(struct drbd_tconn *, struct packet_info *);
37840 -};
37841 +} __do_const;
37842
37843 static struct data_cmd drbd_cmd_handler[] = {
37844 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37845 @@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37846 if (!list_empty(&tconn->current_epoch->list))
37847 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37848 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37849 - atomic_set(&tconn->current_epoch->epoch_size, 0);
37850 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37851 tconn->send.seen_any_write_yet = false;
37852
37853 conn_info(tconn, "Connection closed\n");
37854 @@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37855 struct asender_cmd {
37856 size_t pkt_size;
37857 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37858 -};
37859 +} __do_const;
37860
37861 static struct asender_cmd asender_tbl[] = {
37862 [P_PING] = { 0, got_Ping },
37863 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37864 index c8dac73..1800093 100644
37865 --- a/drivers/block/loop.c
37866 +++ b/drivers/block/loop.c
37867 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37868
37869 file_start_write(file);
37870 set_fs(get_ds());
37871 - bw = file->f_op->write(file, buf, len, &pos);
37872 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37873 set_fs(old_fs);
37874 file_end_write(file);
37875 if (likely(bw == len))
37876 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37877 index 83a598e..2de5ce3 100644
37878 --- a/drivers/block/null_blk.c
37879 +++ b/drivers/block/null_blk.c
37880 @@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37881 return 0;
37882 }
37883
37884 -static struct blk_mq_ops null_mq_ops = {
37885 - .queue_rq = null_queue_rq,
37886 - .map_queue = blk_mq_map_queue,
37887 +static struct blk_mq_ops null_mq_single_ops = {
37888 + .queue_rq = null_queue_rq,
37889 + .map_queue = blk_mq_map_queue,
37890 .init_hctx = null_init_hctx,
37891 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
37892 + .free_hctx = blk_mq_free_single_hw_queue,
37893 +};
37894 +
37895 +static struct blk_mq_ops null_mq_per_node_ops = {
37896 + .queue_rq = null_queue_rq,
37897 + .map_queue = blk_mq_map_queue,
37898 + .init_hctx = null_init_hctx,
37899 + .alloc_hctx = null_alloc_hctx,
37900 + .free_hctx = null_free_hctx,
37901 };
37902
37903 static struct blk_mq_reg null_mq_reg = {
37904 - .ops = &null_mq_ops,
37905 + .ops = &null_mq_single_ops,
37906 .queue_depth = 64,
37907 .cmd_size = sizeof(struct nullb_cmd),
37908 .flags = BLK_MQ_F_SHOULD_MERGE,
37909 @@ -545,13 +555,8 @@ static int null_add_dev(void)
37910 null_mq_reg.queue_depth = hw_queue_depth;
37911 null_mq_reg.nr_hw_queues = submit_queues;
37912
37913 - if (use_per_node_hctx) {
37914 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37915 - null_mq_reg.ops->free_hctx = null_free_hctx;
37916 - } else {
37917 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37918 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37919 - }
37920 + if (use_per_node_hctx)
37921 + null_mq_reg.ops = &null_mq_per_node_ops;
37922
37923 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37924 } else if (queue_mode == NULL_Q_BIO) {
37925 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37926 index ff8668c..f62167a 100644
37927 --- a/drivers/block/pktcdvd.c
37928 +++ b/drivers/block/pktcdvd.c
37929 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37930
37931 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37932 {
37933 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37934 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37935 }
37936
37937 /*
37938 @@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37939 return -EROFS;
37940 }
37941 pd->settings.fp = ti.fp;
37942 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37943 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37944
37945 if (ti.nwa_v) {
37946 pd->nwa = be32_to_cpu(ti.next_writable);
37947 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37948 index e5565fb..71be10b4 100644
37949 --- a/drivers/block/smart1,2.h
37950 +++ b/drivers/block/smart1,2.h
37951 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37952 }
37953
37954 static struct access_method smart4_access = {
37955 - smart4_submit_command,
37956 - smart4_intr_mask,
37957 - smart4_fifo_full,
37958 - smart4_intr_pending,
37959 - smart4_completed,
37960 + .submit_command = smart4_submit_command,
37961 + .set_intr_mask = smart4_intr_mask,
37962 + .fifo_full = smart4_fifo_full,
37963 + .intr_pending = smart4_intr_pending,
37964 + .command_completed = smart4_completed,
37965 };
37966
37967 /*
37968 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37969 }
37970
37971 static struct access_method smart2_access = {
37972 - smart2_submit_command,
37973 - smart2_intr_mask,
37974 - smart2_fifo_full,
37975 - smart2_intr_pending,
37976 - smart2_completed,
37977 + .submit_command = smart2_submit_command,
37978 + .set_intr_mask = smart2_intr_mask,
37979 + .fifo_full = smart2_fifo_full,
37980 + .intr_pending = smart2_intr_pending,
37981 + .command_completed = smart2_completed,
37982 };
37983
37984 /*
37985 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37986 }
37987
37988 static struct access_method smart2e_access = {
37989 - smart2e_submit_command,
37990 - smart2e_intr_mask,
37991 - smart2e_fifo_full,
37992 - smart2e_intr_pending,
37993 - smart2e_completed,
37994 + .submit_command = smart2e_submit_command,
37995 + .set_intr_mask = smart2e_intr_mask,
37996 + .fifo_full = smart2e_fifo_full,
37997 + .intr_pending = smart2e_intr_pending,
37998 + .command_completed = smart2e_completed,
37999 };
38000
38001 /*
38002 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38003 }
38004
38005 static struct access_method smart1_access = {
38006 - smart1_submit_command,
38007 - smart1_intr_mask,
38008 - smart1_fifo_full,
38009 - smart1_intr_pending,
38010 - smart1_completed,
38011 + .submit_command = smart1_submit_command,
38012 + .set_intr_mask = smart1_intr_mask,
38013 + .fifo_full = smart1_fifo_full,
38014 + .intr_pending = smart1_intr_pending,
38015 + .command_completed = smart1_completed,
38016 };
38017 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38018 index f038dba..bb74c08 100644
38019 --- a/drivers/bluetooth/btwilink.c
38020 +++ b/drivers/bluetooth/btwilink.c
38021 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38022
38023 static int bt_ti_probe(struct platform_device *pdev)
38024 {
38025 - static struct ti_st *hst;
38026 + struct ti_st *hst;
38027 struct hci_dev *hdev;
38028 int err;
38029
38030 diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
38031 index b6739cb..962fd35 100644
38032 --- a/drivers/bus/arm-cci.c
38033 +++ b/drivers/bus/arm-cci.c
38034 @@ -979,7 +979,7 @@ static int cci_probe(void)
38035
38036 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
38037
38038 - ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
38039 + ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
38040 if (!ports)
38041 return -ENOMEM;
38042
38043 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38044 index 8a3aff7..d7538c2 100644
38045 --- a/drivers/cdrom/cdrom.c
38046 +++ b/drivers/cdrom/cdrom.c
38047 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38048 ENSURE(reset, CDC_RESET);
38049 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38050 cdi->mc_flags = 0;
38051 - cdo->n_minors = 0;
38052 cdi->options = CDO_USE_FFLAGS;
38053
38054 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38055 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38056 else
38057 cdi->cdda_method = CDDA_OLD;
38058
38059 - if (!cdo->generic_packet)
38060 - cdo->generic_packet = cdrom_dummy_generic_packet;
38061 + if (!cdo->generic_packet) {
38062 + pax_open_kernel();
38063 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38064 + pax_close_kernel();
38065 + }
38066
38067 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38068 mutex_lock(&cdrom_mutex);
38069 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38070 if (cdi->exit)
38071 cdi->exit(cdi);
38072
38073 - cdi->ops->n_minors--;
38074 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38075 }
38076
38077 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38078 */
38079 nr = nframes;
38080 do {
38081 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38082 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38083 if (cgc.buffer)
38084 break;
38085
38086 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38087 struct cdrom_device_info *cdi;
38088 int ret;
38089
38090 - ret = scnprintf(info + *pos, max_size - *pos, header);
38091 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38092 if (!ret)
38093 return 1;
38094
38095 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38096 index 5980cb9..6d7bd7e 100644
38097 --- a/drivers/cdrom/gdrom.c
38098 +++ b/drivers/cdrom/gdrom.c
38099 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38100 .audio_ioctl = gdrom_audio_ioctl,
38101 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38102 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38103 - .n_minors = 1,
38104 };
38105
38106 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38107 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38108 index fa3243d..8c98297 100644
38109 --- a/drivers/char/Kconfig
38110 +++ b/drivers/char/Kconfig
38111 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38112
38113 config DEVKMEM
38114 bool "/dev/kmem virtual device support"
38115 - default y
38116 + default n
38117 + depends on !GRKERNSEC_KMEM
38118 help
38119 Say Y here if you want to support the /dev/kmem device. The
38120 /dev/kmem device is rarely used, but can be used for certain
38121 @@ -576,6 +577,7 @@ config DEVPORT
38122 bool
38123 depends on !M68K
38124 depends on ISA || PCI
38125 + depends on !GRKERNSEC_KMEM
38126 default y
38127
38128 source "drivers/s390/char/Kconfig"
38129 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38130 index a48e05b..6bac831 100644
38131 --- a/drivers/char/agp/compat_ioctl.c
38132 +++ b/drivers/char/agp/compat_ioctl.c
38133 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38134 return -ENOMEM;
38135 }
38136
38137 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38138 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38139 sizeof(*usegment) * ureserve.seg_count)) {
38140 kfree(usegment);
38141 kfree(ksegment);
38142 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38143 index 1b19239..b87b143 100644
38144 --- a/drivers/char/agp/frontend.c
38145 +++ b/drivers/char/agp/frontend.c
38146 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38147 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38148 return -EFAULT;
38149
38150 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38151 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38152 return -EFAULT;
38153
38154 client = agp_find_client_by_pid(reserve.pid);
38155 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38156 if (segment == NULL)
38157 return -ENOMEM;
38158
38159 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38160 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38161 sizeof(struct agp_segment) * reserve.seg_count)) {
38162 kfree(segment);
38163 return -EFAULT;
38164 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38165 index 4f94375..413694e 100644
38166 --- a/drivers/char/genrtc.c
38167 +++ b/drivers/char/genrtc.c
38168 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38169 switch (cmd) {
38170
38171 case RTC_PLL_GET:
38172 + memset(&pll, 0, sizeof(pll));
38173 if (get_rtc_pll(&pll))
38174 return -EINVAL;
38175 else
38176 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38177 index 5d9c31d..c94ccb5 100644
38178 --- a/drivers/char/hpet.c
38179 +++ b/drivers/char/hpet.c
38180 @@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38181 }
38182
38183 static int
38184 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38185 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38186 struct hpet_info *info)
38187 {
38188 struct hpet_timer __iomem *timer;
38189 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38190 index 86fe45c..c0ea948 100644
38191 --- a/drivers/char/hw_random/intel-rng.c
38192 +++ b/drivers/char/hw_random/intel-rng.c
38193 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38194
38195 if (no_fwh_detect)
38196 return -ENODEV;
38197 - printk(warning);
38198 + printk("%s", warning);
38199 return -EBUSY;
38200 }
38201
38202 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38203 index ec4e10f..f2a763b 100644
38204 --- a/drivers/char/ipmi/ipmi_msghandler.c
38205 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38206 @@ -420,7 +420,7 @@ struct ipmi_smi {
38207 struct proc_dir_entry *proc_dir;
38208 char proc_dir_name[10];
38209
38210 - atomic_t stats[IPMI_NUM_STATS];
38211 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38212
38213 /*
38214 * run_to_completion duplicate of smb_info, smi_info
38215 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38216
38217
38218 #define ipmi_inc_stat(intf, stat) \
38219 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38220 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38221 #define ipmi_get_stat(intf, stat) \
38222 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38223 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38224
38225 static int is_lan_addr(struct ipmi_addr *addr)
38226 {
38227 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38228 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38229 init_waitqueue_head(&intf->waitq);
38230 for (i = 0; i < IPMI_NUM_STATS; i++)
38231 - atomic_set(&intf->stats[i], 0);
38232 + atomic_set_unchecked(&intf->stats[i], 0);
38233
38234 intf->proc_dir = NULL;
38235
38236 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38237 index 15e4a60..b046093 100644
38238 --- a/drivers/char/ipmi/ipmi_si_intf.c
38239 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38240 @@ -280,7 +280,7 @@ struct smi_info {
38241 unsigned char slave_addr;
38242
38243 /* Counters and things for the proc filesystem. */
38244 - atomic_t stats[SI_NUM_STATS];
38245 + atomic_unchecked_t stats[SI_NUM_STATS];
38246
38247 struct task_struct *thread;
38248
38249 @@ -289,9 +289,9 @@ struct smi_info {
38250 };
38251
38252 #define smi_inc_stat(smi, stat) \
38253 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38254 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38255 #define smi_get_stat(smi, stat) \
38256 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38257 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38258
38259 #define SI_MAX_PARMS 4
38260
38261 @@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
38262 atomic_set(&new_smi->req_events, 0);
38263 new_smi->run_to_completion = 0;
38264 for (i = 0; i < SI_NUM_STATS; i++)
38265 - atomic_set(&new_smi->stats[i], 0);
38266 + atomic_set_unchecked(&new_smi->stats[i], 0);
38267
38268 new_smi->interrupt_disabled = 1;
38269 atomic_set(&new_smi->stop_operation, 0);
38270 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38271 index f895a8c..2bc9147 100644
38272 --- a/drivers/char/mem.c
38273 +++ b/drivers/char/mem.c
38274 @@ -18,6 +18,7 @@
38275 #include <linux/raw.h>
38276 #include <linux/tty.h>
38277 #include <linux/capability.h>
38278 +#include <linux/security.h>
38279 #include <linux/ptrace.h>
38280 #include <linux/device.h>
38281 #include <linux/highmem.h>
38282 @@ -37,6 +38,10 @@
38283
38284 #define DEVPORT_MINOR 4
38285
38286 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38287 +extern const struct file_operations grsec_fops;
38288 +#endif
38289 +
38290 static inline unsigned long size_inside_page(unsigned long start,
38291 unsigned long size)
38292 {
38293 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38294
38295 while (cursor < to) {
38296 if (!devmem_is_allowed(pfn)) {
38297 +#ifdef CONFIG_GRKERNSEC_KMEM
38298 + gr_handle_mem_readwrite(from, to);
38299 +#else
38300 printk(KERN_INFO
38301 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38302 current->comm, from, to);
38303 +#endif
38304 return 0;
38305 }
38306 cursor += PAGE_SIZE;
38307 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38308 }
38309 return 1;
38310 }
38311 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38312 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38313 +{
38314 + return 0;
38315 +}
38316 #else
38317 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38318 {
38319 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38320
38321 while (count > 0) {
38322 unsigned long remaining;
38323 + char *temp;
38324
38325 sz = size_inside_page(p, count);
38326
38327 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38328 if (!ptr)
38329 return -EFAULT;
38330
38331 - remaining = copy_to_user(buf, ptr, sz);
38332 +#ifdef CONFIG_PAX_USERCOPY
38333 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38334 + if (!temp) {
38335 + unxlate_dev_mem_ptr(p, ptr);
38336 + return -ENOMEM;
38337 + }
38338 + memcpy(temp, ptr, sz);
38339 +#else
38340 + temp = ptr;
38341 +#endif
38342 +
38343 + remaining = copy_to_user(buf, temp, sz);
38344 +
38345 +#ifdef CONFIG_PAX_USERCOPY
38346 + kfree(temp);
38347 +#endif
38348 +
38349 unxlate_dev_mem_ptr(p, ptr);
38350 if (remaining)
38351 return -EFAULT;
38352 @@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38353 size_t count, loff_t *ppos)
38354 {
38355 unsigned long p = *ppos;
38356 - ssize_t low_count, read, sz;
38357 + ssize_t low_count, read, sz, err = 0;
38358 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38359 - int err = 0;
38360
38361 read = 0;
38362 if (p < (unsigned long) high_memory) {
38363 @@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38364 }
38365 #endif
38366 while (low_count > 0) {
38367 + char *temp;
38368 +
38369 sz = size_inside_page(p, low_count);
38370
38371 /*
38372 @@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38373 */
38374 kbuf = xlate_dev_kmem_ptr((char *)p);
38375
38376 - if (copy_to_user(buf, kbuf, sz))
38377 +#ifdef CONFIG_PAX_USERCOPY
38378 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38379 + if (!temp)
38380 + return -ENOMEM;
38381 + memcpy(temp, kbuf, sz);
38382 +#else
38383 + temp = kbuf;
38384 +#endif
38385 +
38386 + err = copy_to_user(buf, temp, sz);
38387 +
38388 +#ifdef CONFIG_PAX_USERCOPY
38389 + kfree(temp);
38390 +#endif
38391 +
38392 + if (err)
38393 return -EFAULT;
38394 buf += sz;
38395 p += sz;
38396 @@ -822,6 +869,9 @@ static const struct memdev {
38397 #ifdef CONFIG_PRINTK
38398 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38399 #endif
38400 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38401 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38402 +#endif
38403 };
38404
38405 static int memory_open(struct inode *inode, struct file *filp)
38406 @@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
38407 continue;
38408
38409 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38410 - NULL, devlist[minor].name);
38411 + NULL, "%s", devlist[minor].name);
38412 }
38413
38414 return tty_init();
38415 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38416 index 9df78e2..01ba9ae 100644
38417 --- a/drivers/char/nvram.c
38418 +++ b/drivers/char/nvram.c
38419 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38420
38421 spin_unlock_irq(&rtc_lock);
38422
38423 - if (copy_to_user(buf, contents, tmp - contents))
38424 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38425 return -EFAULT;
38426
38427 *ppos = i;
38428 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38429 index d39cca6..8c1e269 100644
38430 --- a/drivers/char/pcmcia/synclink_cs.c
38431 +++ b/drivers/char/pcmcia/synclink_cs.c
38432 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38433
38434 if (debug_level >= DEBUG_LEVEL_INFO)
38435 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38436 - __FILE__, __LINE__, info->device_name, port->count);
38437 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38438
38439 - WARN_ON(!port->count);
38440 + WARN_ON(!atomic_read(&port->count));
38441
38442 if (tty_port_close_start(port, tty, filp) == 0)
38443 goto cleanup;
38444 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38445 cleanup:
38446 if (debug_level >= DEBUG_LEVEL_INFO)
38447 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38448 - tty->driver->name, port->count);
38449 + tty->driver->name, atomic_read(&port->count));
38450 }
38451
38452 /* Wait until the transmitter is empty.
38453 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38454
38455 if (debug_level >= DEBUG_LEVEL_INFO)
38456 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38457 - __FILE__, __LINE__, tty->driver->name, port->count);
38458 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38459
38460 /* If port is closing, signal caller to try again */
38461 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38462 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38463 goto cleanup;
38464 }
38465 spin_lock(&port->lock);
38466 - port->count++;
38467 + atomic_inc(&port->count);
38468 spin_unlock(&port->lock);
38469 spin_unlock_irqrestore(&info->netlock, flags);
38470
38471 - if (port->count == 1) {
38472 + if (atomic_read(&port->count) == 1) {
38473 /* 1st open on this device, init hardware */
38474 retval = startup(info, tty);
38475 if (retval < 0)
38476 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38477 unsigned short new_crctype;
38478
38479 /* return error if TTY interface open */
38480 - if (info->port.count)
38481 + if (atomic_read(&info->port.count))
38482 return -EBUSY;
38483
38484 switch (encoding)
38485 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38486
38487 /* arbitrate between network and tty opens */
38488 spin_lock_irqsave(&info->netlock, flags);
38489 - if (info->port.count != 0 || info->netcount != 0) {
38490 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38491 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38492 spin_unlock_irqrestore(&info->netlock, flags);
38493 return -EBUSY;
38494 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38495 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38496
38497 /* return error if TTY interface open */
38498 - if (info->port.count)
38499 + if (atomic_read(&info->port.count))
38500 return -EBUSY;
38501
38502 if (cmd != SIOCWANDEV)
38503 diff --git a/drivers/char/random.c b/drivers/char/random.c
38504 index 429b75b..a7f4145 100644
38505 --- a/drivers/char/random.c
38506 +++ b/drivers/char/random.c
38507 @@ -270,10 +270,17 @@
38508 /*
38509 * Configuration information
38510 */
38511 +#ifdef CONFIG_GRKERNSEC_RANDNET
38512 +#define INPUT_POOL_SHIFT 14
38513 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38514 +#define OUTPUT_POOL_SHIFT 12
38515 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38516 +#else
38517 #define INPUT_POOL_SHIFT 12
38518 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38519 #define OUTPUT_POOL_SHIFT 10
38520 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38521 +#endif
38522 #define SEC_XFER_SIZE 512
38523 #define EXTRACT_SIZE 10
38524
38525 @@ -284,9 +291,6 @@
38526 /*
38527 * To allow fractional bits to be tracked, the entropy_count field is
38528 * denominated in units of 1/8th bits.
38529 - *
38530 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38531 - * credit_entropy_bits() needs to be 64 bits wide.
38532 */
38533 #define ENTROPY_SHIFT 3
38534 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38535 @@ -361,12 +365,19 @@ static struct poolinfo {
38536 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38537 int tap1, tap2, tap3, tap4, tap5;
38538 } poolinfo_table[] = {
38539 +#ifdef CONFIG_GRKERNSEC_RANDNET
38540 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38541 + { S(512), 411, 308, 208, 104, 1 },
38542 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38543 + { S(128), 104, 76, 51, 25, 1 },
38544 +#else
38545 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38546 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38547 { S(128), 104, 76, 51, 25, 1 },
38548 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38549 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38550 { S(32), 26, 19, 14, 7, 1 },
38551 +#endif
38552 #if 0
38553 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38554 { S(2048), 1638, 1231, 819, 411, 1 },
38555 @@ -433,9 +444,9 @@ struct entropy_store {
38556 };
38557
38558 static void push_to_pool(struct work_struct *work);
38559 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38560 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38561 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38562 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38563 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38564 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38565
38566 static struct entropy_store input_pool = {
38567 .poolinfo = &poolinfo_table[0],
38568 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38569 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38570 }
38571
38572 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38573 - ACCESS_ONCE(r->add_ptr) = i;
38574 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38575 + ACCESS_ONCE_RW(r->add_ptr) = i;
38576 smp_wmb();
38577
38578 if (out)
38579 @@ -632,7 +643,7 @@ retry:
38580 /* The +2 corresponds to the /4 in the denominator */
38581
38582 do {
38583 - unsigned int anfrac = min(pnfrac, pool_size/2);
38584 + u64 anfrac = min(pnfrac, pool_size/2);
38585 unsigned int add =
38586 ((pool_size - entropy_count)*anfrac*3) >> s;
38587
38588 @@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38589
38590 extract_buf(r, tmp);
38591 i = min_t(int, nbytes, EXTRACT_SIZE);
38592 - if (copy_to_user(buf, tmp, i)) {
38593 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38594 ret = -EFAULT;
38595 break;
38596 }
38597 @@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38598 #include <linux/sysctl.h>
38599
38600 static int min_read_thresh = 8, min_write_thresh;
38601 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
38602 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38603 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38604 static char sysctl_bootid[16];
38605
38606 @@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38607 static int proc_do_uuid(struct ctl_table *table, int write,
38608 void __user *buffer, size_t *lenp, loff_t *ppos)
38609 {
38610 - struct ctl_table fake_table;
38611 + ctl_table_no_const fake_table;
38612 unsigned char buf[64], tmp_uuid[16], *uuid;
38613
38614 uuid = table->data;
38615 @@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38616 static int proc_do_entropy(ctl_table *table, int write,
38617 void __user *buffer, size_t *lenp, loff_t *ppos)
38618 {
38619 - ctl_table fake_table;
38620 + ctl_table_no_const fake_table;
38621 int entropy_count;
38622
38623 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38624 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38625 index 7cc1fe22..b602d6b 100644
38626 --- a/drivers/char/sonypi.c
38627 +++ b/drivers/char/sonypi.c
38628 @@ -54,6 +54,7 @@
38629
38630 #include <asm/uaccess.h>
38631 #include <asm/io.h>
38632 +#include <asm/local.h>
38633
38634 #include <linux/sonypi.h>
38635
38636 @@ -490,7 +491,7 @@ static struct sonypi_device {
38637 spinlock_t fifo_lock;
38638 wait_queue_head_t fifo_proc_list;
38639 struct fasync_struct *fifo_async;
38640 - int open_count;
38641 + local_t open_count;
38642 int model;
38643 struct input_dev *input_jog_dev;
38644 struct input_dev *input_key_dev;
38645 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38646 static int sonypi_misc_release(struct inode *inode, struct file *file)
38647 {
38648 mutex_lock(&sonypi_device.lock);
38649 - sonypi_device.open_count--;
38650 + local_dec(&sonypi_device.open_count);
38651 mutex_unlock(&sonypi_device.lock);
38652 return 0;
38653 }
38654 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38655 {
38656 mutex_lock(&sonypi_device.lock);
38657 /* Flush input queue on first open */
38658 - if (!sonypi_device.open_count)
38659 + if (!local_read(&sonypi_device.open_count))
38660 kfifo_reset(&sonypi_device.fifo);
38661 - sonypi_device.open_count++;
38662 + local_inc(&sonypi_device.open_count);
38663 mutex_unlock(&sonypi_device.lock);
38664
38665 return 0;
38666 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38667 index 64420b3..5c40b56 100644
38668 --- a/drivers/char/tpm/tpm_acpi.c
38669 +++ b/drivers/char/tpm/tpm_acpi.c
38670 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38671 virt = acpi_os_map_memory(start, len);
38672 if (!virt) {
38673 kfree(log->bios_event_log);
38674 + log->bios_event_log = NULL;
38675 printk("%s: ERROR - Unable to map memory\n", __func__);
38676 return -EIO;
38677 }
38678
38679 - memcpy_fromio(log->bios_event_log, virt, len);
38680 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38681
38682 acpi_os_unmap_memory(virt, len);
38683 return 0;
38684 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38685 index 59f7cb2..bac8b6d 100644
38686 --- a/drivers/char/tpm/tpm_eventlog.c
38687 +++ b/drivers/char/tpm/tpm_eventlog.c
38688 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38689 event = addr;
38690
38691 if ((event->event_type == 0 && event->event_size == 0) ||
38692 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38693 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38694 return NULL;
38695
38696 return addr;
38697 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38698 return NULL;
38699
38700 if ((event->event_type == 0 && event->event_size == 0) ||
38701 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38702 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38703 return NULL;
38704
38705 (*pos)++;
38706 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38707 int i;
38708
38709 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38710 - seq_putc(m, data[i]);
38711 + if (!seq_putc(m, data[i]))
38712 + return -EFAULT;
38713
38714 return 0;
38715 }
38716 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38717 index feea87c..18aefff 100644
38718 --- a/drivers/char/virtio_console.c
38719 +++ b/drivers/char/virtio_console.c
38720 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38721 if (to_user) {
38722 ssize_t ret;
38723
38724 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38725 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38726 if (ret)
38727 return -EFAULT;
38728 } else {
38729 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38730 if (!port_has_data(port) && !port->host_connected)
38731 return 0;
38732
38733 - return fill_readbuf(port, ubuf, count, true);
38734 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38735 }
38736
38737 static int wait_port_writable(struct port *port, bool nonblock)
38738 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38739 index a33f46f..a720eed 100644
38740 --- a/drivers/clk/clk-composite.c
38741 +++ b/drivers/clk/clk-composite.c
38742 @@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38743 struct clk *clk;
38744 struct clk_init_data init;
38745 struct clk_composite *composite;
38746 - struct clk_ops *clk_composite_ops;
38747 + clk_ops_no_const *clk_composite_ops;
38748
38749 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38750 if (!composite) {
38751 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38752 index 81dd31a..ef5c542 100644
38753 --- a/drivers/clk/socfpga/clk.c
38754 +++ b/drivers/clk/socfpga/clk.c
38755 @@ -22,6 +22,7 @@
38756 #include <linux/clk-provider.h>
38757 #include <linux/io.h>
38758 #include <linux/of.h>
38759 +#include <asm/pgtable.h>
38760
38761 /* Clock Manager offsets */
38762 #define CLKMGR_CTRL 0x0
38763 @@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38764 streq(clk_name, "periph_pll") ||
38765 streq(clk_name, "sdram_pll")) {
38766 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38767 - clk_pll_ops.enable = clk_gate_ops.enable;
38768 - clk_pll_ops.disable = clk_gate_ops.disable;
38769 + pax_open_kernel();
38770 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38771 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38772 + pax_close_kernel();
38773 }
38774
38775 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38776 @@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38777 return parent_rate / div;
38778 }
38779
38780 -static struct clk_ops gateclk_ops = {
38781 +static clk_ops_no_const gateclk_ops __read_only = {
38782 .recalc_rate = socfpga_clk_recalc_rate,
38783 .get_parent = socfpga_clk_get_parent,
38784 .set_parent = socfpga_clk_set_parent,
38785 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38786 index caf41eb..223d27a 100644
38787 --- a/drivers/cpufreq/acpi-cpufreq.c
38788 +++ b/drivers/cpufreq/acpi-cpufreq.c
38789 @@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38790 return sprintf(buf, "%u\n", boost_enabled);
38791 }
38792
38793 -static struct global_attr global_boost = __ATTR(boost, 0644,
38794 +static global_attr_no_const global_boost = __ATTR(boost, 0644,
38795 show_global_boost,
38796 store_global_boost);
38797
38798 @@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38799 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38800 per_cpu(acfreq_data, cpu) = data;
38801
38802 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38803 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38804 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38805 + pax_open_kernel();
38806 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38807 + pax_close_kernel();
38808 + }
38809
38810 result = acpi_processor_register_performance(data->acpi_data, cpu);
38811 if (result)
38812 @@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38813 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38814 break;
38815 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38816 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38817 + pax_open_kernel();
38818 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38819 + pax_close_kernel();
38820 break;
38821 default:
38822 break;
38823 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38824 index 8d19f7c..6bc2daa 100644
38825 --- a/drivers/cpufreq/cpufreq.c
38826 +++ b/drivers/cpufreq/cpufreq.c
38827 @@ -1885,7 +1885,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38828 #endif
38829
38830 mutex_lock(&cpufreq_governor_mutex);
38831 - list_del(&governor->governor_list);
38832 + pax_list_del(&governor->governor_list);
38833 mutex_unlock(&cpufreq_governor_mutex);
38834 return;
38835 }
38836 @@ -2115,7 +2115,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38837 return NOTIFY_OK;
38838 }
38839
38840 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
38841 +static struct notifier_block cpufreq_cpu_notifier = {
38842 .notifier_call = cpufreq_cpu_callback,
38843 };
38844
38845 @@ -2148,8 +2148,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38846
38847 pr_debug("trying to register driver %s\n", driver_data->name);
38848
38849 - if (driver_data->setpolicy)
38850 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
38851 + if (driver_data->setpolicy) {
38852 + pax_open_kernel();
38853 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38854 + pax_close_kernel();
38855 + }
38856
38857 write_lock_irqsave(&cpufreq_driver_lock, flags);
38858 if (cpufreq_driver) {
38859 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38860 index e6be635..f8a90dc 100644
38861 --- a/drivers/cpufreq/cpufreq_governor.c
38862 +++ b/drivers/cpufreq/cpufreq_governor.c
38863 @@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38864 struct dbs_data *dbs_data;
38865 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38866 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38867 - struct od_ops *od_ops = NULL;
38868 + const struct od_ops *od_ops = NULL;
38869 struct od_dbs_tuners *od_tuners = NULL;
38870 struct cs_dbs_tuners *cs_tuners = NULL;
38871 struct cpu_dbs_common_info *cpu_cdbs;
38872 @@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38873
38874 if ((cdata->governor == GOV_CONSERVATIVE) &&
38875 (!policy->governor->initialized)) {
38876 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38877 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38878
38879 cpufreq_register_notifier(cs_ops->notifier_block,
38880 CPUFREQ_TRANSITION_NOTIFIER);
38881 @@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38882
38883 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38884 (policy->governor->initialized == 1)) {
38885 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38886 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38887
38888 cpufreq_unregister_notifier(cs_ops->notifier_block,
38889 CPUFREQ_TRANSITION_NOTIFIER);
38890 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38891 index b5f2b86..daa801b 100644
38892 --- a/drivers/cpufreq/cpufreq_governor.h
38893 +++ b/drivers/cpufreq/cpufreq_governor.h
38894 @@ -205,7 +205,7 @@ struct common_dbs_data {
38895 void (*exit)(struct dbs_data *dbs_data);
38896
38897 /* Governor specific ops, see below */
38898 - void *gov_ops;
38899 + const void *gov_ops;
38900 };
38901
38902 /* Governor Per policy data */
38903 @@ -225,7 +225,7 @@ struct od_ops {
38904 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38905 unsigned int freq_next, unsigned int relation);
38906 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38907 -};
38908 +} __no_const;
38909
38910 struct cs_ops {
38911 struct notifier_block *notifier_block;
38912 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38913 index 18d4091..434be15 100644
38914 --- a/drivers/cpufreq/cpufreq_ondemand.c
38915 +++ b/drivers/cpufreq/cpufreq_ondemand.c
38916 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38917
38918 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38919
38920 -static struct od_ops od_ops = {
38921 +static struct od_ops od_ops __read_only = {
38922 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38923 .powersave_bias_target = generic_powersave_bias_target,
38924 .freq_increase = dbs_freq_increase,
38925 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38926 (struct cpufreq_policy *, unsigned int, unsigned int),
38927 unsigned int powersave_bias)
38928 {
38929 - od_ops.powersave_bias_target = f;
38930 + pax_open_kernel();
38931 + *(void **)&od_ops.powersave_bias_target = f;
38932 + pax_close_kernel();
38933 od_set_powersave_bias(powersave_bias);
38934 }
38935 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38936
38937 void od_unregister_powersave_bias_handler(void)
38938 {
38939 - od_ops.powersave_bias_target = generic_powersave_bias_target;
38940 + pax_open_kernel();
38941 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38942 + pax_close_kernel();
38943 od_set_powersave_bias(0);
38944 }
38945 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38946 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38947 index 4cf0d28..5830372 100644
38948 --- a/drivers/cpufreq/cpufreq_stats.c
38949 +++ b/drivers/cpufreq/cpufreq_stats.c
38950 @@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38951 }
38952
38953 /* priority=1 so this will get called before cpufreq_remove_dev */
38954 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38955 +static struct notifier_block cpufreq_stat_cpu_notifier = {
38956 .notifier_call = cpufreq_stat_cpu_callback,
38957 .priority = 1,
38958 };
38959 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38960 index aa366ec..f34f555 100644
38961 --- a/drivers/cpufreq/intel_pstate.c
38962 +++ b/drivers/cpufreq/intel_pstate.c
38963 @@ -112,10 +112,10 @@ struct pstate_funcs {
38964 struct cpu_defaults {
38965 struct pstate_adjust_policy pid_policy;
38966 struct pstate_funcs funcs;
38967 -};
38968 +} __do_const;
38969
38970 static struct pstate_adjust_policy pid_params;
38971 -static struct pstate_funcs pstate_funcs;
38972 +static struct pstate_funcs *pstate_funcs;
38973
38974 struct perf_limits {
38975 int no_turbo;
38976 @@ -462,7 +462,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38977
38978 cpu->pstate.current_pstate = pstate;
38979
38980 - pstate_funcs.set(pstate);
38981 + pstate_funcs->set(pstate);
38982 }
38983
38984 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38985 @@ -484,9 +484,9 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38986 {
38987 sprintf(cpu->name, "Intel 2nd generation core");
38988
38989 - cpu->pstate.min_pstate = pstate_funcs.get_min();
38990 - cpu->pstate.max_pstate = pstate_funcs.get_max();
38991 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
38992 + cpu->pstate.min_pstate = pstate_funcs->get_min();
38993 + cpu->pstate.max_pstate = pstate_funcs->get_max();
38994 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
38995
38996 /*
38997 * goto max pstate so we don't slow up boot if we are built-in if we are
38998 @@ -750,9 +750,9 @@ static int intel_pstate_msrs_not_valid(void)
38999 rdmsrl(MSR_IA32_APERF, aperf);
39000 rdmsrl(MSR_IA32_MPERF, mperf);
39001
39002 - if (!pstate_funcs.get_max() ||
39003 - !pstate_funcs.get_min() ||
39004 - !pstate_funcs.get_turbo())
39005 + if (!pstate_funcs->get_max() ||
39006 + !pstate_funcs->get_min() ||
39007 + !pstate_funcs->get_turbo())
39008 return -ENODEV;
39009
39010 rdmsrl(MSR_IA32_APERF, tmp);
39011 @@ -766,7 +766,7 @@ static int intel_pstate_msrs_not_valid(void)
39012 return 0;
39013 }
39014
39015 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39016 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39017 {
39018 pid_params.sample_rate_ms = policy->sample_rate_ms;
39019 pid_params.p_gain_pct = policy->p_gain_pct;
39020 @@ -778,10 +778,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39021
39022 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39023 {
39024 - pstate_funcs.get_max = funcs->get_max;
39025 - pstate_funcs.get_min = funcs->get_min;
39026 - pstate_funcs.get_turbo = funcs->get_turbo;
39027 - pstate_funcs.set = funcs->set;
39028 + pstate_funcs = funcs;
39029 }
39030
39031 #if IS_ENABLED(CONFIG_ACPI)
39032 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39033 index 3d1cba9..0ab21d2 100644
39034 --- a/drivers/cpufreq/p4-clockmod.c
39035 +++ b/drivers/cpufreq/p4-clockmod.c
39036 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39037 case 0x0F: /* Core Duo */
39038 case 0x16: /* Celeron Core */
39039 case 0x1C: /* Atom */
39040 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39041 + pax_open_kernel();
39042 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39043 + pax_close_kernel();
39044 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39045 case 0x0D: /* Pentium M (Dothan) */
39046 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39047 + pax_open_kernel();
39048 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39049 + pax_close_kernel();
39050 /* fall through */
39051 case 0x09: /* Pentium M (Banias) */
39052 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39053 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39054
39055 /* on P-4s, the TSC runs with constant frequency independent whether
39056 * throttling is active or not. */
39057 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39058 + pax_open_kernel();
39059 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39060 + pax_close_kernel();
39061
39062 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39063 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39064 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39065 index 724ffbd..ad83692 100644
39066 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39067 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39068 @@ -18,14 +18,12 @@
39069 #include <asm/head.h>
39070 #include <asm/timer.h>
39071
39072 -static struct cpufreq_driver *cpufreq_us3_driver;
39073 -
39074 struct us3_freq_percpu_info {
39075 struct cpufreq_frequency_table table[4];
39076 };
39077
39078 /* Indexed by cpu number. */
39079 -static struct us3_freq_percpu_info *us3_freq_table;
39080 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39081
39082 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39083 * in the Safari config register.
39084 @@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39085
39086 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39087 {
39088 - if (cpufreq_us3_driver) {
39089 - cpufreq_frequency_table_put_attr(policy->cpu);
39090 - us3_freq_target(policy, 0);
39091 - }
39092 + cpufreq_frequency_table_put_attr(policy->cpu);
39093 + us3_freq_target(policy, 0);
39094
39095 return 0;
39096 }
39097
39098 +static int __init us3_freq_init(void);
39099 +static void __exit us3_freq_exit(void);
39100 +
39101 +static struct cpufreq_driver cpufreq_us3_driver = {
39102 + .init = us3_freq_cpu_init,
39103 + .verify = cpufreq_generic_frequency_table_verify,
39104 + .target_index = us3_freq_target,
39105 + .get = us3_freq_get,
39106 + .exit = us3_freq_cpu_exit,
39107 + .owner = THIS_MODULE,
39108 + .name = "UltraSPARC-III",
39109 +
39110 +};
39111 +
39112 static int __init us3_freq_init(void)
39113 {
39114 unsigned long manuf, impl, ver;
39115 @@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39116 (impl == CHEETAH_IMPL ||
39117 impl == CHEETAH_PLUS_IMPL ||
39118 impl == JAGUAR_IMPL ||
39119 - impl == PANTHER_IMPL)) {
39120 - struct cpufreq_driver *driver;
39121 -
39122 - ret = -ENOMEM;
39123 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39124 - if (!driver)
39125 - goto err_out;
39126 -
39127 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39128 - GFP_KERNEL);
39129 - if (!us3_freq_table)
39130 - goto err_out;
39131 -
39132 - driver->init = us3_freq_cpu_init;
39133 - driver->verify = cpufreq_generic_frequency_table_verify;
39134 - driver->target_index = us3_freq_target;
39135 - driver->get = us3_freq_get;
39136 - driver->exit = us3_freq_cpu_exit;
39137 - strcpy(driver->name, "UltraSPARC-III");
39138 -
39139 - cpufreq_us3_driver = driver;
39140 - ret = cpufreq_register_driver(driver);
39141 - if (ret)
39142 - goto err_out;
39143 -
39144 - return 0;
39145 -
39146 -err_out:
39147 - if (driver) {
39148 - kfree(driver);
39149 - cpufreq_us3_driver = NULL;
39150 - }
39151 - kfree(us3_freq_table);
39152 - us3_freq_table = NULL;
39153 - return ret;
39154 - }
39155 + impl == PANTHER_IMPL))
39156 + return cpufreq_register_driver(&cpufreq_us3_driver);
39157
39158 return -ENODEV;
39159 }
39160
39161 static void __exit us3_freq_exit(void)
39162 {
39163 - if (cpufreq_us3_driver) {
39164 - cpufreq_unregister_driver(cpufreq_us3_driver);
39165 - kfree(cpufreq_us3_driver);
39166 - cpufreq_us3_driver = NULL;
39167 - kfree(us3_freq_table);
39168 - us3_freq_table = NULL;
39169 - }
39170 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39171 }
39172
39173 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39174 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39175 index 4e1daca..e707b61 100644
39176 --- a/drivers/cpufreq/speedstep-centrino.c
39177 +++ b/drivers/cpufreq/speedstep-centrino.c
39178 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39179 !cpu_has(cpu, X86_FEATURE_EST))
39180 return -ENODEV;
39181
39182 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39183 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39184 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39185 + pax_open_kernel();
39186 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39187 + pax_close_kernel();
39188 + }
39189
39190 if (policy->cpu != 0)
39191 return -ENODEV;
39192 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39193 index 06dbe7c..c2c8671 100644
39194 --- a/drivers/cpuidle/driver.c
39195 +++ b/drivers/cpuidle/driver.c
39196 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39197
39198 static void poll_idle_init(struct cpuidle_driver *drv)
39199 {
39200 - struct cpuidle_state *state = &drv->states[0];
39201 + cpuidle_state_no_const *state = &drv->states[0];
39202
39203 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39204 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39205 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39206 index ca89412..a7b9c49 100644
39207 --- a/drivers/cpuidle/governor.c
39208 +++ b/drivers/cpuidle/governor.c
39209 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39210 mutex_lock(&cpuidle_lock);
39211 if (__cpuidle_find_governor(gov->name) == NULL) {
39212 ret = 0;
39213 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39214 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39215 if (!cpuidle_curr_governor ||
39216 cpuidle_curr_governor->rating < gov->rating)
39217 cpuidle_switch_governor(gov);
39218 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39219 index e918b6d..f87ea80 100644
39220 --- a/drivers/cpuidle/sysfs.c
39221 +++ b/drivers/cpuidle/sysfs.c
39222 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39223 NULL
39224 };
39225
39226 -static struct attribute_group cpuidle_attr_group = {
39227 +static attribute_group_no_const cpuidle_attr_group = {
39228 .attrs = cpuidle_default_attrs,
39229 .name = "cpuidle",
39230 };
39231 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39232 index 12fea3e..1e28f47 100644
39233 --- a/drivers/crypto/hifn_795x.c
39234 +++ b/drivers/crypto/hifn_795x.c
39235 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39236 MODULE_PARM_DESC(hifn_pll_ref,
39237 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39238
39239 -static atomic_t hifn_dev_number;
39240 +static atomic_unchecked_t hifn_dev_number;
39241
39242 #define ACRYPTO_OP_DECRYPT 0
39243 #define ACRYPTO_OP_ENCRYPT 1
39244 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39245 goto err_out_disable_pci_device;
39246
39247 snprintf(name, sizeof(name), "hifn%d",
39248 - atomic_inc_return(&hifn_dev_number)-1);
39249 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39250
39251 err = pci_request_regions(pdev, name);
39252 if (err)
39253 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39254 index a0b2f7e..1b6f028 100644
39255 --- a/drivers/devfreq/devfreq.c
39256 +++ b/drivers/devfreq/devfreq.c
39257 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39258 goto err_out;
39259 }
39260
39261 - list_add(&governor->node, &devfreq_governor_list);
39262 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39263
39264 list_for_each_entry(devfreq, &devfreq_list, node) {
39265 int ret = 0;
39266 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39267 }
39268 }
39269
39270 - list_del(&governor->node);
39271 + pax_list_del((struct list_head *)&governor->node);
39272 err_out:
39273 mutex_unlock(&devfreq_list_lock);
39274
39275 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39276 index 0d765c0..60b7480 100644
39277 --- a/drivers/dma/sh/shdmac.c
39278 +++ b/drivers/dma/sh/shdmac.c
39279 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39280 return ret;
39281 }
39282
39283 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39284 +static struct notifier_block sh_dmae_nmi_notifier = {
39285 .notifier_call = sh_dmae_nmi_handler,
39286
39287 /* Run before NMI debug handler and KGDB */
39288 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39289 index 1026743..80b081c 100644
39290 --- a/drivers/edac/edac_device.c
39291 +++ b/drivers/edac/edac_device.c
39292 @@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39293 */
39294 int edac_device_alloc_index(void)
39295 {
39296 - static atomic_t device_indexes = ATOMIC_INIT(0);
39297 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39298
39299 - return atomic_inc_return(&device_indexes) - 1;
39300 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39301 }
39302 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39303
39304 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39305 index e5bdf21..b8f9055 100644
39306 --- a/drivers/edac/edac_mc_sysfs.c
39307 +++ b/drivers/edac/edac_mc_sysfs.c
39308 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39309 struct dev_ch_attribute {
39310 struct device_attribute attr;
39311 int channel;
39312 -};
39313 +} __do_const;
39314
39315 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39316 struct dev_ch_attribute dev_attr_legacy_##_name = \
39317 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39318 }
39319
39320 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39321 + pax_open_kernel();
39322 if (mci->get_sdram_scrub_rate) {
39323 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39324 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39325 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39326 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39327 }
39328 if (mci->set_sdram_scrub_rate) {
39329 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39330 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39331 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39332 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39333 }
39334 + pax_close_kernel();
39335 err = device_create_file(&mci->dev,
39336 &dev_attr_sdram_scrub_rate);
39337 if (err) {
39338 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39339 index 2cf44b4d..6dd2dc7 100644
39340 --- a/drivers/edac/edac_pci.c
39341 +++ b/drivers/edac/edac_pci.c
39342 @@ -29,7 +29,7 @@
39343
39344 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39345 static LIST_HEAD(edac_pci_list);
39346 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39347 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39348
39349 /*
39350 * edac_pci_alloc_ctl_info
39351 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39352 */
39353 int edac_pci_alloc_index(void)
39354 {
39355 - return atomic_inc_return(&pci_indexes) - 1;
39356 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39357 }
39358 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39359
39360 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39361 index e8658e4..22746d6 100644
39362 --- a/drivers/edac/edac_pci_sysfs.c
39363 +++ b/drivers/edac/edac_pci_sysfs.c
39364 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39365 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39366 static int edac_pci_poll_msec = 1000; /* one second workq period */
39367
39368 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39369 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39370 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39371 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39372
39373 static struct kobject *edac_pci_top_main_kobj;
39374 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39375 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39376 void *value;
39377 ssize_t(*show) (void *, char *);
39378 ssize_t(*store) (void *, const char *, size_t);
39379 -};
39380 +} __do_const;
39381
39382 /* Set of show/store abstract level functions for PCI Parity object */
39383 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39384 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39385 edac_printk(KERN_CRIT, EDAC_PCI,
39386 "Signaled System Error on %s\n",
39387 pci_name(dev));
39388 - atomic_inc(&pci_nonparity_count);
39389 + atomic_inc_unchecked(&pci_nonparity_count);
39390 }
39391
39392 if (status & (PCI_STATUS_PARITY)) {
39393 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39394 "Master Data Parity Error on %s\n",
39395 pci_name(dev));
39396
39397 - atomic_inc(&pci_parity_count);
39398 + atomic_inc_unchecked(&pci_parity_count);
39399 }
39400
39401 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39402 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39403 "Detected Parity Error on %s\n",
39404 pci_name(dev));
39405
39406 - atomic_inc(&pci_parity_count);
39407 + atomic_inc_unchecked(&pci_parity_count);
39408 }
39409 }
39410
39411 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39412 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39413 "Signaled System Error on %s\n",
39414 pci_name(dev));
39415 - atomic_inc(&pci_nonparity_count);
39416 + atomic_inc_unchecked(&pci_nonparity_count);
39417 }
39418
39419 if (status & (PCI_STATUS_PARITY)) {
39420 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39421 "Master Data Parity Error on "
39422 "%s\n", pci_name(dev));
39423
39424 - atomic_inc(&pci_parity_count);
39425 + atomic_inc_unchecked(&pci_parity_count);
39426 }
39427
39428 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39429 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39430 "Detected Parity Error on %s\n",
39431 pci_name(dev));
39432
39433 - atomic_inc(&pci_parity_count);
39434 + atomic_inc_unchecked(&pci_parity_count);
39435 }
39436 }
39437 }
39438 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39439 if (!check_pci_errors)
39440 return;
39441
39442 - before_count = atomic_read(&pci_parity_count);
39443 + before_count = atomic_read_unchecked(&pci_parity_count);
39444
39445 /* scan all PCI devices looking for a Parity Error on devices and
39446 * bridges.
39447 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39448 /* Only if operator has selected panic on PCI Error */
39449 if (edac_pci_get_panic_on_pe()) {
39450 /* If the count is different 'after' from 'before' */
39451 - if (before_count != atomic_read(&pci_parity_count))
39452 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39453 panic("EDAC: PCI Parity Error");
39454 }
39455 }
39456 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39457 index 51b7e3a..aa8a3e8 100644
39458 --- a/drivers/edac/mce_amd.h
39459 +++ b/drivers/edac/mce_amd.h
39460 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39461 bool (*mc0_mce)(u16, u8);
39462 bool (*mc1_mce)(u16, u8);
39463 bool (*mc2_mce)(u16, u8);
39464 -};
39465 +} __no_const;
39466
39467 void amd_report_gart_errors(bool);
39468 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39469 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39470 index 57ea7f4..af06b76 100644
39471 --- a/drivers/firewire/core-card.c
39472 +++ b/drivers/firewire/core-card.c
39473 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39474 const struct fw_card_driver *driver,
39475 struct device *device)
39476 {
39477 - static atomic_t index = ATOMIC_INIT(-1);
39478 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39479
39480 - card->index = atomic_inc_return(&index);
39481 + card->index = atomic_inc_return_unchecked(&index);
39482 card->driver = driver;
39483 card->device = device;
39484 card->current_tlabel = 0;
39485 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39486
39487 void fw_core_remove_card(struct fw_card *card)
39488 {
39489 - struct fw_card_driver dummy_driver = dummy_driver_template;
39490 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39491
39492 card->driver->update_phy_reg(card, 4,
39493 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39494 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39495 index de4aa40..49ab1f2 100644
39496 --- a/drivers/firewire/core-device.c
39497 +++ b/drivers/firewire/core-device.c
39498 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39499 struct config_rom_attribute {
39500 struct device_attribute attr;
39501 u32 key;
39502 -};
39503 +} __do_const;
39504
39505 static ssize_t show_immediate(struct device *dev,
39506 struct device_attribute *dattr, char *buf)
39507 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39508 index 0e79951..b180217 100644
39509 --- a/drivers/firewire/core-transaction.c
39510 +++ b/drivers/firewire/core-transaction.c
39511 @@ -38,6 +38,7 @@
39512 #include <linux/timer.h>
39513 #include <linux/types.h>
39514 #include <linux/workqueue.h>
39515 +#include <linux/sched.h>
39516
39517 #include <asm/byteorder.h>
39518
39519 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39520 index 515a42c..5ecf3ba 100644
39521 --- a/drivers/firewire/core.h
39522 +++ b/drivers/firewire/core.h
39523 @@ -111,6 +111,7 @@ struct fw_card_driver {
39524
39525 int (*stop_iso)(struct fw_iso_context *ctx);
39526 };
39527 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39528
39529 void fw_card_initialize(struct fw_card *card,
39530 const struct fw_card_driver *driver, struct device *device);
39531 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39532 index 94a58a0..f5eba42 100644
39533 --- a/drivers/firmware/dmi-id.c
39534 +++ b/drivers/firmware/dmi-id.c
39535 @@ -16,7 +16,7 @@
39536 struct dmi_device_attribute{
39537 struct device_attribute dev_attr;
39538 int field;
39539 -};
39540 +} __do_const;
39541 #define to_dmi_dev_attr(_dev_attr) \
39542 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39543
39544 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39545 index c7e81ff..94a7401 100644
39546 --- a/drivers/firmware/dmi_scan.c
39547 +++ b/drivers/firmware/dmi_scan.c
39548 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39549 if (buf == NULL)
39550 return -1;
39551
39552 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39553 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39554
39555 iounmap(buf);
39556 return 0;
39557 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39558 index 1491dd4..aa910db 100644
39559 --- a/drivers/firmware/efi/cper.c
39560 +++ b/drivers/firmware/efi/cper.c
39561 @@ -41,12 +41,12 @@
39562 */
39563 u64 cper_next_record_id(void)
39564 {
39565 - static atomic64_t seq;
39566 + static atomic64_unchecked_t seq;
39567
39568 - if (!atomic64_read(&seq))
39569 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39570 + if (!atomic64_read_unchecked(&seq))
39571 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39572
39573 - return atomic64_inc_return(&seq);
39574 + return atomic64_inc_return_unchecked(&seq);
39575 }
39576 EXPORT_SYMBOL_GPL(cper_next_record_id);
39577
39578 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39579 index 2e2fbde..7676c8b 100644
39580 --- a/drivers/firmware/efi/efi.c
39581 +++ b/drivers/firmware/efi/efi.c
39582 @@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
39583 };
39584
39585 static struct efivars generic_efivars;
39586 -static struct efivar_operations generic_ops;
39587 +static efivar_operations_no_const generic_ops __read_only;
39588
39589 static int generic_ops_register(void)
39590 {
39591 - generic_ops.get_variable = efi.get_variable;
39592 - generic_ops.set_variable = efi.set_variable;
39593 - generic_ops.get_next_variable = efi.get_next_variable;
39594 - generic_ops.query_variable_store = efi_query_variable_store;
39595 + pax_open_kernel();
39596 + *(void **)&generic_ops.get_variable = efi.get_variable;
39597 + *(void **)&generic_ops.set_variable = efi.set_variable;
39598 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39599 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39600 + pax_close_kernel();
39601
39602 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39603 }
39604 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39605 index 3dc2482..7bd2f61 100644
39606 --- a/drivers/firmware/efi/efivars.c
39607 +++ b/drivers/firmware/efi/efivars.c
39608 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39609 static int
39610 create_efivars_bin_attributes(void)
39611 {
39612 - struct bin_attribute *attr;
39613 + bin_attribute_no_const *attr;
39614 int error;
39615
39616 /* new_var */
39617 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39618 index 2a90ba6..07f3733 100644
39619 --- a/drivers/firmware/google/memconsole.c
39620 +++ b/drivers/firmware/google/memconsole.c
39621 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39622 if (!found_memconsole())
39623 return -ENODEV;
39624
39625 - memconsole_bin_attr.size = memconsole_length;
39626 + pax_open_kernel();
39627 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39628 + pax_close_kernel();
39629
39630 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39631
39632 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39633 index ec19036..8ffafc2 100644
39634 --- a/drivers/gpio/gpio-em.c
39635 +++ b/drivers/gpio/gpio-em.c
39636 @@ -257,7 +257,7 @@ static int em_gio_probe(struct platform_device *pdev)
39637 struct em_gio_priv *p;
39638 struct resource *io[2], *irq[2];
39639 struct gpio_chip *gpio_chip;
39640 - struct irq_chip *irq_chip;
39641 + irq_chip_no_const *irq_chip;
39642 const char *name = dev_name(&pdev->dev);
39643 int ret;
39644
39645 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39646 index 814addb..0937d7f 100644
39647 --- a/drivers/gpio/gpio-ich.c
39648 +++ b/drivers/gpio/gpio-ich.c
39649 @@ -71,7 +71,7 @@ struct ichx_desc {
39650 /* Some chipsets have quirks, let these use their own request/get */
39651 int (*request)(struct gpio_chip *chip, unsigned offset);
39652 int (*get)(struct gpio_chip *chip, unsigned offset);
39653 -};
39654 +} __do_const;
39655
39656 static struct {
39657 spinlock_t lock;
39658 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39659 index 8b7e719..dc089dc 100644
39660 --- a/drivers/gpio/gpio-rcar.c
39661 +++ b/drivers/gpio/gpio-rcar.c
39662 @@ -316,7 +316,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39663 struct gpio_rcar_priv *p;
39664 struct resource *io, *irq;
39665 struct gpio_chip *gpio_chip;
39666 - struct irq_chip *irq_chip;
39667 + irq_chip_no_const *irq_chip;
39668 const char *name = dev_name(&pdev->dev);
39669 int ret;
39670
39671 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39672 index 9902732..64b62dd 100644
39673 --- a/drivers/gpio/gpio-vr41xx.c
39674 +++ b/drivers/gpio/gpio-vr41xx.c
39675 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39676 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39677 maskl, pendl, maskh, pendh);
39678
39679 - atomic_inc(&irq_err_count);
39680 + atomic_inc_unchecked(&irq_err_count);
39681
39682 return -EINVAL;
39683 }
39684 diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c
39685 index 62d0ff3..073dbf3 100644
39686 --- a/drivers/gpu/drm/armada/armada_drv.c
39687 +++ b/drivers/gpu/drm/armada/armada_drv.c
39688 @@ -68,15 +68,7 @@ void __armada_drm_queue_unref_work(struct drm_device *dev,
39689 {
39690 struct armada_private *priv = dev->dev_private;
39691
39692 - /*
39693 - * Yes, we really must jump through these hoops just to store a
39694 - * _pointer_ to something into the kfifo. This is utterly insane
39695 - * and idiotic, because it kfifo requires the _data_ pointed to by
39696 - * the pointer const, not the pointer itself. Not only that, but
39697 - * you have to pass a pointer _to_ the pointer you want stored.
39698 - */
39699 - const struct drm_framebuffer *silly_api_alert = fb;
39700 - WARN_ON(!kfifo_put(&priv->fb_unref, &silly_api_alert));
39701 + WARN_ON(!kfifo_put(&priv->fb_unref, fb));
39702 schedule_work(&priv->fb_unref_work);
39703 }
39704
39705 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39706 index d6cf77c..2842146 100644
39707 --- a/drivers/gpu/drm/drm_crtc.c
39708 +++ b/drivers/gpu/drm/drm_crtc.c
39709 @@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39710 goto done;
39711 }
39712
39713 - if (copy_to_user(&enum_ptr[copied].name,
39714 + if (copy_to_user(enum_ptr[copied].name,
39715 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39716 ret = -EFAULT;
39717 goto done;
39718 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39719 index 01361ab..891e821 100644
39720 --- a/drivers/gpu/drm/drm_crtc_helper.c
39721 +++ b/drivers/gpu/drm/drm_crtc_helper.c
39722 @@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39723 struct drm_crtc *tmp;
39724 int crtc_mask = 1;
39725
39726 - WARN(!crtc, "checking null crtc?\n");
39727 + BUG_ON(!crtc);
39728
39729 dev = crtc->dev;
39730
39731 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39732 index d9137e4..69b73a0 100644
39733 --- a/drivers/gpu/drm/drm_drv.c
39734 +++ b/drivers/gpu/drm/drm_drv.c
39735 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39736 /**
39737 * Copy and IOCTL return string to user space
39738 */
39739 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39740 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39741 {
39742 int len;
39743
39744 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39745 struct drm_file *file_priv = filp->private_data;
39746 struct drm_device *dev;
39747 const struct drm_ioctl_desc *ioctl = NULL;
39748 - drm_ioctl_t *func;
39749 + drm_ioctl_no_const_t func;
39750 unsigned int nr = DRM_IOCTL_NR(cmd);
39751 int retcode = -EINVAL;
39752 char stack_kdata[128];
39753 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39754 index c5b929c..8a3b8be 100644
39755 --- a/drivers/gpu/drm/drm_fops.c
39756 +++ b/drivers/gpu/drm/drm_fops.c
39757 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39758 if (drm_device_is_unplugged(dev))
39759 return -ENODEV;
39760
39761 - if (!dev->open_count++)
39762 + if (local_inc_return(&dev->open_count) == 1)
39763 need_setup = 1;
39764 mutex_lock(&dev->struct_mutex);
39765 old_imapping = inode->i_mapping;
39766 @@ -127,7 +127,7 @@ err_undo:
39767 iput(container_of(dev->dev_mapping, struct inode, i_data));
39768 dev->dev_mapping = old_mapping;
39769 mutex_unlock(&dev->struct_mutex);
39770 - dev->open_count--;
39771 + local_dec(&dev->open_count);
39772 return retcode;
39773 }
39774 EXPORT_SYMBOL(drm_open);
39775 @@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39776
39777 mutex_lock(&drm_global_mutex);
39778
39779 - DRM_DEBUG("open_count = %d\n", dev->open_count);
39780 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39781
39782 if (dev->driver->preclose)
39783 dev->driver->preclose(dev, file_priv);
39784 @@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39785 * Begin inline drm_release
39786 */
39787
39788 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39789 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39790 task_pid_nr(current),
39791 (long)old_encode_dev(file_priv->minor->device),
39792 - dev->open_count);
39793 + local_read(&dev->open_count));
39794
39795 /* Release any auth tokens that might point to this file_priv,
39796 (do that under the drm_global_mutex) */
39797 @@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39798 * End inline drm_release
39799 */
39800
39801 - if (!--dev->open_count) {
39802 + if (local_dec_and_test(&dev->open_count)) {
39803 if (atomic_read(&dev->ioctl_count)) {
39804 DRM_ERROR("Device busy: %d\n",
39805 atomic_read(&dev->ioctl_count));
39806 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39807 index 3d2e91c..d31c4c9 100644
39808 --- a/drivers/gpu/drm/drm_global.c
39809 +++ b/drivers/gpu/drm/drm_global.c
39810 @@ -36,7 +36,7 @@
39811 struct drm_global_item {
39812 struct mutex mutex;
39813 void *object;
39814 - int refcount;
39815 + atomic_t refcount;
39816 };
39817
39818 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39819 @@ -49,7 +49,7 @@ void drm_global_init(void)
39820 struct drm_global_item *item = &glob[i];
39821 mutex_init(&item->mutex);
39822 item->object = NULL;
39823 - item->refcount = 0;
39824 + atomic_set(&item->refcount, 0);
39825 }
39826 }
39827
39828 @@ -59,7 +59,7 @@ void drm_global_release(void)
39829 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39830 struct drm_global_item *item = &glob[i];
39831 BUG_ON(item->object != NULL);
39832 - BUG_ON(item->refcount != 0);
39833 + BUG_ON(atomic_read(&item->refcount) != 0);
39834 }
39835 }
39836
39837 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39838 struct drm_global_item *item = &glob[ref->global_type];
39839
39840 mutex_lock(&item->mutex);
39841 - if (item->refcount == 0) {
39842 + if (atomic_read(&item->refcount) == 0) {
39843 item->object = kzalloc(ref->size, GFP_KERNEL);
39844 if (unlikely(item->object == NULL)) {
39845 ret = -ENOMEM;
39846 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39847 goto out_err;
39848
39849 }
39850 - ++item->refcount;
39851 + atomic_inc(&item->refcount);
39852 ref->object = item->object;
39853 mutex_unlock(&item->mutex);
39854 return 0;
39855 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39856 struct drm_global_item *item = &glob[ref->global_type];
39857
39858 mutex_lock(&item->mutex);
39859 - BUG_ON(item->refcount == 0);
39860 + BUG_ON(atomic_read(&item->refcount) == 0);
39861 BUG_ON(ref->object != item->object);
39862 - if (--item->refcount == 0) {
39863 + if (atomic_dec_and_test(&item->refcount)) {
39864 ref->release(ref);
39865 item->object = NULL;
39866 }
39867 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39868 index 7d5a152..d7186da 100644
39869 --- a/drivers/gpu/drm/drm_info.c
39870 +++ b/drivers/gpu/drm/drm_info.c
39871 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39872 struct drm_local_map *map;
39873 struct drm_map_list *r_list;
39874
39875 - /* Hardcoded from _DRM_FRAME_BUFFER,
39876 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39877 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39878 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39879 + static const char * const types[] = {
39880 + [_DRM_FRAME_BUFFER] = "FB",
39881 + [_DRM_REGISTERS] = "REG",
39882 + [_DRM_SHM] = "SHM",
39883 + [_DRM_AGP] = "AGP",
39884 + [_DRM_SCATTER_GATHER] = "SG",
39885 + [_DRM_CONSISTENT] = "PCI",
39886 + [_DRM_GEM] = "GEM" };
39887 const char *type;
39888 int i;
39889
39890 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39891 map = r_list->map;
39892 if (!map)
39893 continue;
39894 - if (map->type < 0 || map->type > 5)
39895 + if (map->type >= ARRAY_SIZE(types))
39896 type = "??";
39897 else
39898 type = types[map->type];
39899 @@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39900 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39901 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39902 vma->vm_flags & VM_IO ? 'i' : '-',
39903 +#ifdef CONFIG_GRKERNSEC_HIDESYM
39904 + 0);
39905 +#else
39906 vma->vm_pgoff);
39907 +#endif
39908
39909 #if defined(__i386__)
39910 pgprot = pgprot_val(vma->vm_page_prot);
39911 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39912 index 2f4c4343..dd12cd2 100644
39913 --- a/drivers/gpu/drm/drm_ioc32.c
39914 +++ b/drivers/gpu/drm/drm_ioc32.c
39915 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39916 request = compat_alloc_user_space(nbytes);
39917 if (!access_ok(VERIFY_WRITE, request, nbytes))
39918 return -EFAULT;
39919 - list = (struct drm_buf_desc *) (request + 1);
39920 + list = (struct drm_buf_desc __user *) (request + 1);
39921
39922 if (__put_user(count, &request->count)
39923 || __put_user(list, &request->list))
39924 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39925 request = compat_alloc_user_space(nbytes);
39926 if (!access_ok(VERIFY_WRITE, request, nbytes))
39927 return -EFAULT;
39928 - list = (struct drm_buf_pub *) (request + 1);
39929 + list = (struct drm_buf_pub __user *) (request + 1);
39930
39931 if (__put_user(count, &request->count)
39932 || __put_user(list, &request->list))
39933 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39934 return 0;
39935 }
39936
39937 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
39938 +drm_ioctl_compat_t drm_compat_ioctls[] = {
39939 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39940 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39941 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39942 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39943 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39944 {
39945 unsigned int nr = DRM_IOCTL_NR(cmd);
39946 - drm_ioctl_compat_t *fn;
39947 int ret;
39948
39949 /* Assume that ioctls without an explicit compat routine will just
39950 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39951 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39952 return drm_ioctl(filp, cmd, arg);
39953
39954 - fn = drm_compat_ioctls[nr];
39955 -
39956 - if (fn != NULL)
39957 - ret = (*fn) (filp, cmd, arg);
39958 + if (drm_compat_ioctls[nr] != NULL)
39959 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39960 else
39961 ret = drm_ioctl(filp, cmd, arg);
39962
39963 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39964 index 66dd3a0..3bed6c4 100644
39965 --- a/drivers/gpu/drm/drm_stub.c
39966 +++ b/drivers/gpu/drm/drm_stub.c
39967 @@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39968
39969 drm_device_set_unplugged(dev);
39970
39971 - if (dev->open_count == 0) {
39972 + if (local_read(&dev->open_count) == 0) {
39973 drm_put_dev(dev);
39974 }
39975 mutex_unlock(&drm_global_mutex);
39976 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39977 index c22c309..ae758c3 100644
39978 --- a/drivers/gpu/drm/drm_sysfs.c
39979 +++ b/drivers/gpu/drm/drm_sysfs.c
39980 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39981 */
39982 int drm_sysfs_device_add(struct drm_minor *minor)
39983 {
39984 - char *minor_str;
39985 + const char *minor_str;
39986 int r;
39987
39988 if (minor->type == DRM_MINOR_CONTROL)
39989 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39990 index d4d16ed..8fb0b51 100644
39991 --- a/drivers/gpu/drm/i810/i810_drv.h
39992 +++ b/drivers/gpu/drm/i810/i810_drv.h
39993 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39994 int page_flipping;
39995
39996 wait_queue_head_t irq_queue;
39997 - atomic_t irq_received;
39998 - atomic_t irq_emitted;
39999 + atomic_unchecked_t irq_received;
40000 + atomic_unchecked_t irq_emitted;
40001
40002 int front_offset;
40003 } drm_i810_private_t;
40004 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40005 index 6ed45a9..eb6dc41 100644
40006 --- a/drivers/gpu/drm/i915/i915_debugfs.c
40007 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
40008 @@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40009 I915_READ(GTIMR));
40010 }
40011 seq_printf(m, "Interrupts received: %d\n",
40012 - atomic_read(&dev_priv->irq_received));
40013 + atomic_read_unchecked(&dev_priv->irq_received));
40014 for_each_ring(ring, dev_priv, i) {
40015 if (INTEL_INFO(dev)->gen >= 6) {
40016 seq_printf(m,
40017 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40018 index e02266a..e3411aa 100644
40019 --- a/drivers/gpu/drm/i915/i915_dma.c
40020 +++ b/drivers/gpu/drm/i915/i915_dma.c
40021 @@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40022 bool can_switch;
40023
40024 spin_lock(&dev->count_lock);
40025 - can_switch = (dev->open_count == 0);
40026 + can_switch = (local_read(&dev->open_count) == 0);
40027 spin_unlock(&dev->count_lock);
40028 return can_switch;
40029 }
40030 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40031 index 221ac62..f56acc8 100644
40032 --- a/drivers/gpu/drm/i915/i915_drv.h
40033 +++ b/drivers/gpu/drm/i915/i915_drv.h
40034 @@ -1326,7 +1326,7 @@ typedef struct drm_i915_private {
40035 drm_dma_handle_t *status_page_dmah;
40036 struct resource mch_res;
40037
40038 - atomic_t irq_received;
40039 + atomic_unchecked_t irq_received;
40040
40041 /* protects the irq masks */
40042 spinlock_t irq_lock;
40043 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40044 index a3ba9a8..ee52ddd 100644
40045 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40046 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40047 @@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40048
40049 static int
40050 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40051 - int count)
40052 + unsigned int count)
40053 {
40054 - int i;
40055 + unsigned int i;
40056 unsigned relocs_total = 0;
40057 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40058
40059 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40060 index 3c59584..500f2e9 100644
40061 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40062 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40063 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40064 (unsigned long)request);
40065 }
40066
40067 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40068 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40069 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40070 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40071 [DRM_I915_GETPARAM] = compat_i915_getparam,
40072 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40073 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40074 {
40075 unsigned int nr = DRM_IOCTL_NR(cmd);
40076 - drm_ioctl_compat_t *fn = NULL;
40077 int ret;
40078
40079 if (nr < DRM_COMMAND_BASE)
40080 return drm_compat_ioctl(filp, cmd, arg);
40081
40082 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40083 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40084 -
40085 - if (fn != NULL)
40086 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40087 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40088 ret = (*fn) (filp, cmd, arg);
40089 - else
40090 + } else
40091 ret = drm_ioctl(filp, cmd, arg);
40092
40093 return ret;
40094 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40095 index a209177..842a89a 100644
40096 --- a/drivers/gpu/drm/i915/i915_irq.c
40097 +++ b/drivers/gpu/drm/i915/i915_irq.c
40098 @@ -1419,7 +1419,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40099 int pipe;
40100 u32 pipe_stats[I915_MAX_PIPES];
40101
40102 - atomic_inc(&dev_priv->irq_received);
40103 + atomic_inc_unchecked(&dev_priv->irq_received);
40104
40105 while (true) {
40106 iir = I915_READ(VLV_IIR);
40107 @@ -1729,7 +1729,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40108 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40109 irqreturn_t ret = IRQ_NONE;
40110
40111 - atomic_inc(&dev_priv->irq_received);
40112 + atomic_inc_unchecked(&dev_priv->irq_received);
40113
40114 /* We get interrupts on unclaimed registers, so check for this before we
40115 * do any I915_{READ,WRITE}. */
40116 @@ -1799,7 +1799,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40117 uint32_t tmp = 0;
40118 enum pipe pipe;
40119
40120 - atomic_inc(&dev_priv->irq_received);
40121 + atomic_inc_unchecked(&dev_priv->irq_received);
40122
40123 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40124 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40125 @@ -2623,7 +2623,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40126 {
40127 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40128
40129 - atomic_set(&dev_priv->irq_received, 0);
40130 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40131
40132 I915_WRITE(HWSTAM, 0xeffe);
40133
40134 @@ -2641,7 +2641,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40135 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40136 int pipe;
40137
40138 - atomic_set(&dev_priv->irq_received, 0);
40139 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40140
40141 /* VLV magic */
40142 I915_WRITE(VLV_IMR, 0);
40143 @@ -2672,7 +2672,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40144 struct drm_i915_private *dev_priv = dev->dev_private;
40145 int pipe;
40146
40147 - atomic_set(&dev_priv->irq_received, 0);
40148 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40149
40150 I915_WRITE(GEN8_MASTER_IRQ, 0);
40151 POSTING_READ(GEN8_MASTER_IRQ);
40152 @@ -2998,7 +2998,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40153 if (!dev_priv)
40154 return;
40155
40156 - atomic_set(&dev_priv->irq_received, 0);
40157 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40158
40159 I915_WRITE(GEN8_MASTER_IRQ, 0);
40160
40161 @@ -3092,7 +3092,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40162 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40163 int pipe;
40164
40165 - atomic_set(&dev_priv->irq_received, 0);
40166 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40167
40168 for_each_pipe(pipe)
40169 I915_WRITE(PIPESTAT(pipe), 0);
40170 @@ -3178,7 +3178,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40171 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40172 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40173
40174 - atomic_inc(&dev_priv->irq_received);
40175 + atomic_inc_unchecked(&dev_priv->irq_received);
40176
40177 iir = I915_READ16(IIR);
40178 if (iir == 0)
40179 @@ -3253,7 +3253,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40180 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40181 int pipe;
40182
40183 - atomic_set(&dev_priv->irq_received, 0);
40184 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40185
40186 if (I915_HAS_HOTPLUG(dev)) {
40187 I915_WRITE(PORT_HOTPLUG_EN, 0);
40188 @@ -3360,7 +3360,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40189 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40190 int pipe, ret = IRQ_NONE;
40191
40192 - atomic_inc(&dev_priv->irq_received);
40193 + atomic_inc_unchecked(&dev_priv->irq_received);
40194
40195 iir = I915_READ(IIR);
40196 do {
40197 @@ -3487,7 +3487,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40198 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40199 int pipe;
40200
40201 - atomic_set(&dev_priv->irq_received, 0);
40202 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40203
40204 I915_WRITE(PORT_HOTPLUG_EN, 0);
40205 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40206 @@ -3603,7 +3603,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40207 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40208 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40209
40210 - atomic_inc(&dev_priv->irq_received);
40211 + atomic_inc_unchecked(&dev_priv->irq_received);
40212
40213 iir = I915_READ(IIR);
40214
40215 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40216 index 3c5ff7a..ae759ca 100644
40217 --- a/drivers/gpu/drm/i915/intel_display.c
40218 +++ b/drivers/gpu/drm/i915/intel_display.c
40219 @@ -10506,13 +10506,13 @@ struct intel_quirk {
40220 int subsystem_vendor;
40221 int subsystem_device;
40222 void (*hook)(struct drm_device *dev);
40223 -};
40224 +} __do_const;
40225
40226 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40227 struct intel_dmi_quirk {
40228 void (*hook)(struct drm_device *dev);
40229 const struct dmi_system_id (*dmi_id_list)[];
40230 -};
40231 +} __do_const;
40232
40233 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40234 {
40235 @@ -10520,18 +10520,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40236 return 1;
40237 }
40238
40239 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40240 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40241 {
40242 - .dmi_id_list = &(const struct dmi_system_id[]) {
40243 - {
40244 - .callback = intel_dmi_reverse_brightness,
40245 - .ident = "NCR Corporation",
40246 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40247 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40248 - },
40249 - },
40250 - { } /* terminating entry */
40251 + .callback = intel_dmi_reverse_brightness,
40252 + .ident = "NCR Corporation",
40253 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40254 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40255 },
40256 + },
40257 + { } /* terminating entry */
40258 +};
40259 +
40260 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40261 + {
40262 + .dmi_id_list = &intel_dmi_quirks_table,
40263 .hook = quirk_invert_brightness,
40264 },
40265 };
40266 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40267 index ca4bc54..ee598a2 100644
40268 --- a/drivers/gpu/drm/mga/mga_drv.h
40269 +++ b/drivers/gpu/drm/mga/mga_drv.h
40270 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40271 u32 clear_cmd;
40272 u32 maccess;
40273
40274 - atomic_t vbl_received; /**< Number of vblanks received. */
40275 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40276 wait_queue_head_t fence_queue;
40277 - atomic_t last_fence_retired;
40278 + atomic_unchecked_t last_fence_retired;
40279 u32 next_fence_to_post;
40280
40281 unsigned int fb_cpp;
40282 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40283 index 709e90d..89a1c0d 100644
40284 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40285 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40286 @@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40287 return 0;
40288 }
40289
40290 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40291 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40292 [DRM_MGA_INIT] = compat_mga_init,
40293 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40294 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40295 @@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40296 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40297 {
40298 unsigned int nr = DRM_IOCTL_NR(cmd);
40299 - drm_ioctl_compat_t *fn = NULL;
40300 int ret;
40301
40302 if (nr < DRM_COMMAND_BASE)
40303 return drm_compat_ioctl(filp, cmd, arg);
40304
40305 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40306 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40307 -
40308 - if (fn != NULL)
40309 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40310 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40311 ret = (*fn) (filp, cmd, arg);
40312 - else
40313 + } else
40314 ret = drm_ioctl(filp, cmd, arg);
40315
40316 return ret;
40317 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40318 index 2b0ceb8..517e99e 100644
40319 --- a/drivers/gpu/drm/mga/mga_irq.c
40320 +++ b/drivers/gpu/drm/mga/mga_irq.c
40321 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40322 if (crtc != 0)
40323 return 0;
40324
40325 - return atomic_read(&dev_priv->vbl_received);
40326 + return atomic_read_unchecked(&dev_priv->vbl_received);
40327 }
40328
40329
40330 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40331 /* VBLANK interrupt */
40332 if (status & MGA_VLINEPEN) {
40333 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40334 - atomic_inc(&dev_priv->vbl_received);
40335 + atomic_inc_unchecked(&dev_priv->vbl_received);
40336 drm_handle_vblank(dev, 0);
40337 handled = 1;
40338 }
40339 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40340 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40341 MGA_WRITE(MGA_PRIMEND, prim_end);
40342
40343 - atomic_inc(&dev_priv->last_fence_retired);
40344 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40345 DRM_WAKEUP(&dev_priv->fence_queue);
40346 handled = 1;
40347 }
40348 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40349 * using fences.
40350 */
40351 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
40352 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40353 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40354 - *sequence) <= (1 << 23)));
40355
40356 *sequence = cur_fence;
40357 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40358 index 4c3feaa..26391ce 100644
40359 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40360 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40361 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40362 struct bit_table {
40363 const char id;
40364 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40365 -};
40366 +} __no_const;
40367
40368 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40369
40370 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40371 index 4b0fb6c..67667a9 100644
40372 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40373 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40374 @@ -96,7 +96,6 @@ struct nouveau_drm {
40375 struct drm_global_reference mem_global_ref;
40376 struct ttm_bo_global_ref bo_global_ref;
40377 struct ttm_bo_device bdev;
40378 - atomic_t validate_sequence;
40379 int (*move)(struct nouveau_channel *,
40380 struct ttm_buffer_object *,
40381 struct ttm_mem_reg *, struct ttm_mem_reg *);
40382 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40383 index c1a7e5a..38b8539 100644
40384 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40385 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40386 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40387 unsigned long arg)
40388 {
40389 unsigned int nr = DRM_IOCTL_NR(cmd);
40390 - drm_ioctl_compat_t *fn = NULL;
40391 + drm_ioctl_compat_t fn = NULL;
40392 int ret;
40393
40394 if (nr < DRM_COMMAND_BASE)
40395 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40396 index 19e3757..ad16478 100644
40397 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40398 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40399 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40400 }
40401
40402 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40403 - nouveau_vram_manager_init,
40404 - nouveau_vram_manager_fini,
40405 - nouveau_vram_manager_new,
40406 - nouveau_vram_manager_del,
40407 - nouveau_vram_manager_debug
40408 + .init = nouveau_vram_manager_init,
40409 + .takedown = nouveau_vram_manager_fini,
40410 + .get_node = nouveau_vram_manager_new,
40411 + .put_node = nouveau_vram_manager_del,
40412 + .debug = nouveau_vram_manager_debug
40413 };
40414
40415 static int
40416 @@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40417 }
40418
40419 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40420 - nouveau_gart_manager_init,
40421 - nouveau_gart_manager_fini,
40422 - nouveau_gart_manager_new,
40423 - nouveau_gart_manager_del,
40424 - nouveau_gart_manager_debug
40425 + .init = nouveau_gart_manager_init,
40426 + .takedown = nouveau_gart_manager_fini,
40427 + .get_node = nouveau_gart_manager_new,
40428 + .put_node = nouveau_gart_manager_del,
40429 + .debug = nouveau_gart_manager_debug
40430 };
40431
40432 #include <core/subdev/vm/nv04.h>
40433 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40434 }
40435
40436 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40437 - nv04_gart_manager_init,
40438 - nv04_gart_manager_fini,
40439 - nv04_gart_manager_new,
40440 - nv04_gart_manager_del,
40441 - nv04_gart_manager_debug
40442 + .init = nv04_gart_manager_init,
40443 + .takedown = nv04_gart_manager_fini,
40444 + .get_node = nv04_gart_manager_new,
40445 + .put_node = nv04_gart_manager_del,
40446 + .debug = nv04_gart_manager_debug
40447 };
40448
40449 int
40450 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40451 index 81638d7..2e45854 100644
40452 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40453 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40454 @@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40455 bool can_switch;
40456
40457 spin_lock(&dev->count_lock);
40458 - can_switch = (dev->open_count == 0);
40459 + can_switch = (local_read(&dev->open_count) == 0);
40460 spin_unlock(&dev->count_lock);
40461 return can_switch;
40462 }
40463 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40464 index eb89653..613cf71 100644
40465 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40466 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40467 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40468 int ret;
40469
40470 mutex_lock(&qdev->async_io_mutex);
40471 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40472 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40473 if (qdev->last_sent_io_cmd > irq_num) {
40474 if (intr)
40475 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40476 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40477 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40478 else
40479 ret = wait_event_timeout(qdev->io_cmd_event,
40480 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40481 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40482 /* 0 is timeout, just bail the "hw" has gone away */
40483 if (ret <= 0)
40484 goto out;
40485 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40486 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40487 }
40488 outb(val, addr);
40489 qdev->last_sent_io_cmd = irq_num + 1;
40490 if (intr)
40491 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40492 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40493 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40494 else
40495 ret = wait_event_timeout(qdev->io_cmd_event,
40496 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40497 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40498 out:
40499 if (ret > 0)
40500 ret = 0;
40501 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40502 index c3c2bbd..bc3c0fb 100644
40503 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40504 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40505 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40506 struct drm_info_node *node = (struct drm_info_node *) m->private;
40507 struct qxl_device *qdev = node->minor->dev->dev_private;
40508
40509 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40510 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40511 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40512 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40513 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40514 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40515 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40516 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40517 seq_printf(m, "%d\n", qdev->irq_received_error);
40518 return 0;
40519 }
40520 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40521 index 7bda32f..dd98fc5 100644
40522 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40523 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40524 @@ -290,10 +290,10 @@ struct qxl_device {
40525 unsigned int last_sent_io_cmd;
40526
40527 /* interrupt handling */
40528 - atomic_t irq_received;
40529 - atomic_t irq_received_display;
40530 - atomic_t irq_received_cursor;
40531 - atomic_t irq_received_io_cmd;
40532 + atomic_unchecked_t irq_received;
40533 + atomic_unchecked_t irq_received_display;
40534 + atomic_unchecked_t irq_received_cursor;
40535 + atomic_unchecked_t irq_received_io_cmd;
40536 unsigned irq_received_error;
40537 wait_queue_head_t display_event;
40538 wait_queue_head_t cursor_event;
40539 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40540 index 7b95c75..9cffb4f 100644
40541 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40542 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40543 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40544
40545 /* TODO copy slow path code from i915 */
40546 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40547 - 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);
40548 + 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);
40549
40550 {
40551 struct qxl_drawable *draw = fb_cmd;
40552 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40553 struct drm_qxl_reloc reloc;
40554
40555 if (DRM_COPY_FROM_USER(&reloc,
40556 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40557 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40558 sizeof(reloc))) {
40559 ret = -EFAULT;
40560 goto out_free_bos;
40561 @@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40562 struct drm_qxl_command *commands =
40563 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40564
40565 - if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
40566 + if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40567 sizeof(user_cmd)))
40568 return -EFAULT;
40569
40570 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40571 index 21393dc..329f3a9 100644
40572 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40573 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40574 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
40575
40576 pending = xchg(&qdev->ram_header->int_pending, 0);
40577
40578 - atomic_inc(&qdev->irq_received);
40579 + atomic_inc_unchecked(&qdev->irq_received);
40580
40581 if (pending & QXL_INTERRUPT_DISPLAY) {
40582 - atomic_inc(&qdev->irq_received_display);
40583 + atomic_inc_unchecked(&qdev->irq_received_display);
40584 wake_up_all(&qdev->display_event);
40585 qxl_queue_garbage_collect(qdev, false);
40586 }
40587 if (pending & QXL_INTERRUPT_CURSOR) {
40588 - atomic_inc(&qdev->irq_received_cursor);
40589 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40590 wake_up_all(&qdev->cursor_event);
40591 }
40592 if (pending & QXL_INTERRUPT_IO_CMD) {
40593 - atomic_inc(&qdev->irq_received_io_cmd);
40594 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40595 wake_up_all(&qdev->io_cmd_event);
40596 }
40597 if (pending & QXL_INTERRUPT_ERROR) {
40598 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40599 init_waitqueue_head(&qdev->io_cmd_event);
40600 INIT_WORK(&qdev->client_monitors_config_work,
40601 qxl_client_monitors_config_work_func);
40602 - atomic_set(&qdev->irq_received, 0);
40603 - atomic_set(&qdev->irq_received_display, 0);
40604 - atomic_set(&qdev->irq_received_cursor, 0);
40605 - atomic_set(&qdev->irq_received_io_cmd, 0);
40606 + atomic_set_unchecked(&qdev->irq_received, 0);
40607 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40608 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40609 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40610 qdev->irq_received_error = 0;
40611 ret = drm_irq_install(qdev->ddev);
40612 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40613 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40614 index c7e7e65..7dddd4d 100644
40615 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40616 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40617 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40618 }
40619 }
40620
40621 -static struct vm_operations_struct qxl_ttm_vm_ops;
40622 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40623 static const struct vm_operations_struct *ttm_vm_ops;
40624
40625 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40626 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40627 return r;
40628 if (unlikely(ttm_vm_ops == NULL)) {
40629 ttm_vm_ops = vma->vm_ops;
40630 + pax_open_kernel();
40631 qxl_ttm_vm_ops = *ttm_vm_ops;
40632 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40633 + pax_close_kernel();
40634 }
40635 vma->vm_ops = &qxl_ttm_vm_ops;
40636 return 0;
40637 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40638 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40639 {
40640 #if defined(CONFIG_DEBUG_FS)
40641 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40642 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40643 - unsigned i;
40644 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40645 + {
40646 + .name = "qxl_mem_mm",
40647 + .show = &qxl_mm_dump_table,
40648 + },
40649 + {
40650 + .name = "qxl_surf_mm",
40651 + .show = &qxl_mm_dump_table,
40652 + }
40653 + };
40654
40655 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40656 - if (i == 0)
40657 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40658 - else
40659 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40660 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40661 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40662 - qxl_mem_types_list[i].driver_features = 0;
40663 - if (i == 0)
40664 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40665 - else
40666 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40667 + pax_open_kernel();
40668 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40669 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40670 + pax_close_kernel();
40671
40672 - }
40673 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40674 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40675 #else
40676 return 0;
40677 #endif
40678 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40679 index c451257..0ad2134 100644
40680 --- a/drivers/gpu/drm/r128/r128_cce.c
40681 +++ b/drivers/gpu/drm/r128/r128_cce.c
40682 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40683
40684 /* GH: Simple idle check.
40685 */
40686 - atomic_set(&dev_priv->idle_count, 0);
40687 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40688
40689 /* We don't support anything other than bus-mastering ring mode,
40690 * but the ring can be in either AGP or PCI space for the ring
40691 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40692 index 56eb5e3..c4ec43d 100644
40693 --- a/drivers/gpu/drm/r128/r128_drv.h
40694 +++ b/drivers/gpu/drm/r128/r128_drv.h
40695 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40696 int is_pci;
40697 unsigned long cce_buffers_offset;
40698
40699 - atomic_t idle_count;
40700 + atomic_unchecked_t idle_count;
40701
40702 int page_flipping;
40703 int current_page;
40704 u32 crtc_offset;
40705 u32 crtc_offset_cntl;
40706
40707 - atomic_t vbl_received;
40708 + atomic_unchecked_t vbl_received;
40709
40710 u32 color_fmt;
40711 unsigned int front_offset;
40712 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40713 index a954c54..9cc595c 100644
40714 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40715 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40716 @@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40717 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40718 }
40719
40720 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40721 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40722 [DRM_R128_INIT] = compat_r128_init,
40723 [DRM_R128_DEPTH] = compat_r128_depth,
40724 [DRM_R128_STIPPLE] = compat_r128_stipple,
40725 @@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40726 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40727 {
40728 unsigned int nr = DRM_IOCTL_NR(cmd);
40729 - drm_ioctl_compat_t *fn = NULL;
40730 int ret;
40731
40732 if (nr < DRM_COMMAND_BASE)
40733 return drm_compat_ioctl(filp, cmd, arg);
40734
40735 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40736 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40737 -
40738 - if (fn != NULL)
40739 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40740 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40741 ret = (*fn) (filp, cmd, arg);
40742 - else
40743 + } else
40744 ret = drm_ioctl(filp, cmd, arg);
40745
40746 return ret;
40747 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40748 index 2ea4f09..d391371 100644
40749 --- a/drivers/gpu/drm/r128/r128_irq.c
40750 +++ b/drivers/gpu/drm/r128/r128_irq.c
40751 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40752 if (crtc != 0)
40753 return 0;
40754
40755 - return atomic_read(&dev_priv->vbl_received);
40756 + return atomic_read_unchecked(&dev_priv->vbl_received);
40757 }
40758
40759 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40760 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40761 /* VBLANK interrupt */
40762 if (status & R128_CRTC_VBLANK_INT) {
40763 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40764 - atomic_inc(&dev_priv->vbl_received);
40765 + atomic_inc_unchecked(&dev_priv->vbl_received);
40766 drm_handle_vblank(dev, 0);
40767 return IRQ_HANDLED;
40768 }
40769 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40770 index 01dd9ae..6352f04 100644
40771 --- a/drivers/gpu/drm/r128/r128_state.c
40772 +++ b/drivers/gpu/drm/r128/r128_state.c
40773 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40774
40775 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40776 {
40777 - if (atomic_read(&dev_priv->idle_count) == 0)
40778 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40779 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40780 else
40781 - atomic_set(&dev_priv->idle_count, 0);
40782 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40783 }
40784
40785 #endif
40786 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40787 index af85299..ed9ac8d 100644
40788 --- a/drivers/gpu/drm/radeon/mkregtable.c
40789 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40790 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40791 regex_t mask_rex;
40792 regmatch_t match[4];
40793 char buf[1024];
40794 - size_t end;
40795 + long end;
40796 int len;
40797 int done = 0;
40798 int r;
40799 unsigned o;
40800 struct offset *offset;
40801 char last_reg_s[10];
40802 - int last_reg;
40803 + unsigned long last_reg;
40804
40805 if (regcomp
40806 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40807 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40808 index 39b033b..6efc056 100644
40809 --- a/drivers/gpu/drm/radeon/radeon_device.c
40810 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40811 @@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40812 bool can_switch;
40813
40814 spin_lock(&dev->count_lock);
40815 - can_switch = (dev->open_count == 0);
40816 + can_switch = (local_read(&dev->open_count) == 0);
40817 spin_unlock(&dev->count_lock);
40818 return can_switch;
40819 }
40820 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40821 index 00e0d44..08381a4 100644
40822 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40823 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40824 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40825
40826 /* SW interrupt */
40827 wait_queue_head_t swi_queue;
40828 - atomic_t swi_emitted;
40829 + atomic_unchecked_t swi_emitted;
40830 int vblank_crtc;
40831 uint32_t irq_enable_reg;
40832 uint32_t r500_disp_irq_reg;
40833 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40834 index bdb0f93..5ff558f 100644
40835 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40836 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40837 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40838 request = compat_alloc_user_space(sizeof(*request));
40839 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40840 || __put_user(req32.param, &request->param)
40841 - || __put_user((void __user *)(unsigned long)req32.value,
40842 + || __put_user((unsigned long)req32.value,
40843 &request->value))
40844 return -EFAULT;
40845
40846 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40847 #define compat_radeon_cp_setparam NULL
40848 #endif /* X86_64 || IA64 */
40849
40850 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40851 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40852 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40853 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40854 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40855 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40856 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40857 {
40858 unsigned int nr = DRM_IOCTL_NR(cmd);
40859 - drm_ioctl_compat_t *fn = NULL;
40860 int ret;
40861
40862 if (nr < DRM_COMMAND_BASE)
40863 return drm_compat_ioctl(filp, cmd, arg);
40864
40865 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40866 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40867 -
40868 - if (fn != NULL)
40869 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40870 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40871 ret = (*fn) (filp, cmd, arg);
40872 - else
40873 + } else
40874 ret = drm_ioctl(filp, cmd, arg);
40875
40876 return ret;
40877 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40878 index 8d68e97..9dcfed8 100644
40879 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40880 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40881 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40882 unsigned int ret;
40883 RING_LOCALS;
40884
40885 - atomic_inc(&dev_priv->swi_emitted);
40886 - ret = atomic_read(&dev_priv->swi_emitted);
40887 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40888 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40889
40890 BEGIN_RING(4);
40891 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40892 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40893 drm_radeon_private_t *dev_priv =
40894 (drm_radeon_private_t *) dev->dev_private;
40895
40896 - atomic_set(&dev_priv->swi_emitted, 0);
40897 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40898 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40899
40900 dev->max_vblank_count = 0x001fffff;
40901 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40902 index 4d20910..6726b6d 100644
40903 --- a/drivers/gpu/drm/radeon/radeon_state.c
40904 +++ b/drivers/gpu/drm/radeon/radeon_state.c
40905 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40906 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40907 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40908
40909 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40910 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40911 sarea_priv->nbox * sizeof(depth_boxes[0])))
40912 return -EFAULT;
40913
40914 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40915 {
40916 drm_radeon_private_t *dev_priv = dev->dev_private;
40917 drm_radeon_getparam_t *param = data;
40918 - int value;
40919 + int value = 0;
40920
40921 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40922
40923 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40924 index 71245d6..94c556d 100644
40925 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
40926 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40927 @@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40928 man->size = size >> PAGE_SHIFT;
40929 }
40930
40931 -static struct vm_operations_struct radeon_ttm_vm_ops;
40932 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40933 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40934
40935 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40936 @@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40937 }
40938 if (unlikely(ttm_vm_ops == NULL)) {
40939 ttm_vm_ops = vma->vm_ops;
40940 + pax_open_kernel();
40941 radeon_ttm_vm_ops = *ttm_vm_ops;
40942 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40943 + pax_close_kernel();
40944 }
40945 vma->vm_ops = &radeon_ttm_vm_ops;
40946 return 0;
40947 @@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40948 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40949 {
40950 #if defined(CONFIG_DEBUG_FS)
40951 - static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40952 - static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40953 - unsigned i;
40954 + static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40955 + {
40956 + .name = "radeon_vram_mm",
40957 + .show = &radeon_mm_dump_table,
40958 + },
40959 + {
40960 + .name = "radeon_gtt_mm",
40961 + .show = &radeon_mm_dump_table,
40962 + },
40963 + {
40964 + .name = "ttm_page_pool",
40965 + .show = &ttm_page_alloc_debugfs,
40966 + },
40967 + {
40968 + .name = "ttm_dma_page_pool",
40969 + .show = &ttm_dma_page_alloc_debugfs,
40970 + },
40971 + };
40972 + unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40973
40974 - for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40975 - if (i == 0)
40976 - sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40977 - else
40978 - sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40979 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40980 - radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40981 - radeon_mem_types_list[i].driver_features = 0;
40982 - if (i == 0)
40983 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40984 - else
40985 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40986 -
40987 - }
40988 - /* Add ttm page pool to debugfs */
40989 - sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40990 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40991 - radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40992 - radeon_mem_types_list[i].driver_features = 0;
40993 - radeon_mem_types_list[i++].data = NULL;
40994 + pax_open_kernel();
40995 + *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40996 + *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40997 + pax_close_kernel();
40998 #ifdef CONFIG_SWIOTLB
40999 - if (swiotlb_nr_tbl()) {
41000 - sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
41001 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
41002 - radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
41003 - radeon_mem_types_list[i].driver_features = 0;
41004 - radeon_mem_types_list[i++].data = NULL;
41005 - }
41006 + if (swiotlb_nr_tbl())
41007 + i++;
41008 #endif
41009 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
41010
41011 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41012 index ae1cb31..5b5b6b7c 100644
41013 --- a/drivers/gpu/drm/tegra/dc.c
41014 +++ b/drivers/gpu/drm/tegra/dc.c
41015 @@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41016 }
41017
41018 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41019 - dc->debugfs_files[i].data = dc;
41020 + *(void **)&dc->debugfs_files[i].data = dc;
41021
41022 err = drm_debugfs_create_files(dc->debugfs_files,
41023 ARRAY_SIZE(debugfs_files),
41024 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41025 index 0cd9bc2..9759be4 100644
41026 --- a/drivers/gpu/drm/tegra/hdmi.c
41027 +++ b/drivers/gpu/drm/tegra/hdmi.c
41028 @@ -57,7 +57,7 @@ struct tegra_hdmi {
41029 bool stereo;
41030 bool dvi;
41031
41032 - struct drm_info_list *debugfs_files;
41033 + drm_info_list_no_const *debugfs_files;
41034 struct drm_minor *minor;
41035 struct dentry *debugfs;
41036 };
41037 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41038 index c58eba33..83c2728 100644
41039 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41040 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41041 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41042 }
41043
41044 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41045 - ttm_bo_man_init,
41046 - ttm_bo_man_takedown,
41047 - ttm_bo_man_get_node,
41048 - ttm_bo_man_put_node,
41049 - ttm_bo_man_debug
41050 + .init = ttm_bo_man_init,
41051 + .takedown = ttm_bo_man_takedown,
41052 + .get_node = ttm_bo_man_get_node,
41053 + .put_node = ttm_bo_man_put_node,
41054 + .debug = ttm_bo_man_debug
41055 };
41056 EXPORT_SYMBOL(ttm_bo_manager_func);
41057 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41058 index dbc2def..0a9f710 100644
41059 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41060 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41061 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41062 zone->glob = glob;
41063 glob->zone_kernel = zone;
41064 ret = kobject_init_and_add(
41065 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41066 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41067 if (unlikely(ret != 0)) {
41068 kobject_put(&zone->kobj);
41069 return ret;
41070 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41071 zone->glob = glob;
41072 glob->zone_dma32 = zone;
41073 ret = kobject_init_and_add(
41074 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41075 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41076 if (unlikely(ret != 0)) {
41077 kobject_put(&zone->kobj);
41078 return ret;
41079 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41080 index 863bef9..cba15cf 100644
41081 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41082 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41083 @@ -391,9 +391,9 @@ out:
41084 static unsigned long
41085 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41086 {
41087 - static atomic_t start_pool = ATOMIC_INIT(0);
41088 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41089 unsigned i;
41090 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41091 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41092 struct ttm_page_pool *pool;
41093 int shrink_pages = sc->nr_to_scan;
41094 unsigned long freed = 0;
41095 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41096 index 97e9d61..bf23c461 100644
41097 --- a/drivers/gpu/drm/udl/udl_fb.c
41098 +++ b/drivers/gpu/drm/udl/udl_fb.c
41099 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41100 fb_deferred_io_cleanup(info);
41101 kfree(info->fbdefio);
41102 info->fbdefio = NULL;
41103 - info->fbops->fb_mmap = udl_fb_mmap;
41104 }
41105
41106 pr_warn("released /dev/fb%d user=%d count=%d\n",
41107 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41108 index a811ef2..ff99b05 100644
41109 --- a/drivers/gpu/drm/via/via_drv.h
41110 +++ b/drivers/gpu/drm/via/via_drv.h
41111 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41112 typedef uint32_t maskarray_t[5];
41113
41114 typedef struct drm_via_irq {
41115 - atomic_t irq_received;
41116 + atomic_unchecked_t irq_received;
41117 uint32_t pending_mask;
41118 uint32_t enable_mask;
41119 wait_queue_head_t irq_queue;
41120 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41121 struct timeval last_vblank;
41122 int last_vblank_valid;
41123 unsigned usec_per_vblank;
41124 - atomic_t vbl_received;
41125 + atomic_unchecked_t vbl_received;
41126 drm_via_state_t hc_state;
41127 char pci_buf[VIA_PCI_BUF_SIZE];
41128 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41129 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41130 index ac98964..5dbf512 100644
41131 --- a/drivers/gpu/drm/via/via_irq.c
41132 +++ b/drivers/gpu/drm/via/via_irq.c
41133 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41134 if (crtc != 0)
41135 return 0;
41136
41137 - return atomic_read(&dev_priv->vbl_received);
41138 + return atomic_read_unchecked(&dev_priv->vbl_received);
41139 }
41140
41141 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41142 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41143
41144 status = VIA_READ(VIA_REG_INTERRUPT);
41145 if (status & VIA_IRQ_VBLANK_PENDING) {
41146 - atomic_inc(&dev_priv->vbl_received);
41147 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41148 + atomic_inc_unchecked(&dev_priv->vbl_received);
41149 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41150 do_gettimeofday(&cur_vblank);
41151 if (dev_priv->last_vblank_valid) {
41152 dev_priv->usec_per_vblank =
41153 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41154 dev_priv->last_vblank = cur_vblank;
41155 dev_priv->last_vblank_valid = 1;
41156 }
41157 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41158 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41159 DRM_DEBUG("US per vblank is: %u\n",
41160 dev_priv->usec_per_vblank);
41161 }
41162 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41163
41164 for (i = 0; i < dev_priv->num_irqs; ++i) {
41165 if (status & cur_irq->pending_mask) {
41166 - atomic_inc(&cur_irq->irq_received);
41167 + atomic_inc_unchecked(&cur_irq->irq_received);
41168 DRM_WAKEUP(&cur_irq->irq_queue);
41169 handled = 1;
41170 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41171 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41172 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41173 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41174 masks[irq][4]));
41175 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41176 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41177 } else {
41178 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41179 (((cur_irq_sequence =
41180 - atomic_read(&cur_irq->irq_received)) -
41181 + atomic_read_unchecked(&cur_irq->irq_received)) -
41182 *sequence) <= (1 << 23)));
41183 }
41184 *sequence = cur_irq_sequence;
41185 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41186 }
41187
41188 for (i = 0; i < dev_priv->num_irqs; ++i) {
41189 - atomic_set(&cur_irq->irq_received, 0);
41190 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41191 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41192 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41193 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
41194 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41195 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41196 case VIA_IRQ_RELATIVE:
41197 irqwait->request.sequence +=
41198 - atomic_read(&cur_irq->irq_received);
41199 + atomic_read_unchecked(&cur_irq->irq_received);
41200 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41201 case VIA_IRQ_ABSOLUTE:
41202 break;
41203 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41204 index c0b73b9..f6f7f34 100644
41205 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41206 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41207 @@ -341,7 +341,7 @@ struct vmw_private {
41208 * Fencing and IRQs.
41209 */
41210
41211 - atomic_t marker_seq;
41212 + atomic_unchecked_t marker_seq;
41213 wait_queue_head_t fence_queue;
41214 wait_queue_head_t fifo_queue;
41215 int fence_queue_waiters; /* Protected by hw_mutex */
41216 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41217 index 3eb1486..0a47ee9 100644
41218 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41219 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41220 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41221 (unsigned int) min,
41222 (unsigned int) fifo->capabilities);
41223
41224 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41225 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41226 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41227 vmw_marker_queue_init(&fifo->marker_queue);
41228 return vmw_fifo_send_fence(dev_priv, &dummy);
41229 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41230 if (reserveable)
41231 iowrite32(bytes, fifo_mem +
41232 SVGA_FIFO_RESERVED);
41233 - return fifo_mem + (next_cmd >> 2);
41234 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41235 } else {
41236 need_bounce = true;
41237 }
41238 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41239
41240 fm = vmw_fifo_reserve(dev_priv, bytes);
41241 if (unlikely(fm == NULL)) {
41242 - *seqno = atomic_read(&dev_priv->marker_seq);
41243 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41244 ret = -ENOMEM;
41245 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41246 false, 3*HZ);
41247 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41248 }
41249
41250 do {
41251 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41252 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41253 } while (*seqno == 0);
41254
41255 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41256 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41257 index c5c054a..46f0548 100644
41258 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41259 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41260 @@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41261 }
41262
41263 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41264 - vmw_gmrid_man_init,
41265 - vmw_gmrid_man_takedown,
41266 - vmw_gmrid_man_get_node,
41267 - vmw_gmrid_man_put_node,
41268 - vmw_gmrid_man_debug
41269 + .init = vmw_gmrid_man_init,
41270 + .takedown = vmw_gmrid_man_takedown,
41271 + .get_node = vmw_gmrid_man_get_node,
41272 + .put_node = vmw_gmrid_man_put_node,
41273 + .debug = vmw_gmrid_man_debug
41274 };
41275 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41276 index 45d5b5a..f3f5e4e 100644
41277 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41278 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41279 @@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41280 int ret;
41281
41282 num_clips = arg->num_clips;
41283 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41284 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41285
41286 if (unlikely(num_clips == 0))
41287 return 0;
41288 @@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41289 int ret;
41290
41291 num_clips = arg->num_clips;
41292 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41293 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41294
41295 if (unlikely(num_clips == 0))
41296 return 0;
41297 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41298 index 4640adb..e1384ed 100644
41299 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41300 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41301 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41302 * emitted. Then the fence is stale and signaled.
41303 */
41304
41305 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41306 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41307 > VMW_FENCE_WRAP);
41308
41309 return ret;
41310 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41311
41312 if (fifo_idle)
41313 down_read(&fifo_state->rwsem);
41314 - signal_seq = atomic_read(&dev_priv->marker_seq);
41315 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41316 ret = 0;
41317
41318 for (;;) {
41319 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41320 index 8a8725c2..afed796 100644
41321 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41322 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41323 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41324 while (!vmw_lag_lt(queue, us)) {
41325 spin_lock(&queue->lock);
41326 if (list_empty(&queue->head))
41327 - seqno = atomic_read(&dev_priv->marker_seq);
41328 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41329 else {
41330 marker = list_first_entry(&queue->head,
41331 struct vmw_marker, head);
41332 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41333 index ec0ae2d..dc0780b 100644
41334 --- a/drivers/gpu/vga/vga_switcheroo.c
41335 +++ b/drivers/gpu/vga/vga_switcheroo.c
41336 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41337
41338 /* this version is for the case where the power switch is separate
41339 to the device being powered down. */
41340 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41341 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41342 {
41343 /* copy over all the bus versions */
41344 if (dev->bus && dev->bus->pm) {
41345 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41346 return ret;
41347 }
41348
41349 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41350 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41351 {
41352 /* copy over all the bus versions */
41353 if (dev->bus && dev->bus->pm) {
41354 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41355 index 253fe23..0dfec5f 100644
41356 --- a/drivers/hid/hid-core.c
41357 +++ b/drivers/hid/hid-core.c
41358 @@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41359
41360 int hid_add_device(struct hid_device *hdev)
41361 {
41362 - static atomic_t id = ATOMIC_INIT(0);
41363 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41364 int ret;
41365
41366 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41367 @@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
41368 /* XXX hack, any other cleaner solution after the driver core
41369 * is converted to allow more than 20 bytes as the device name? */
41370 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41371 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41372 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41373
41374 hid_debug_register(hdev, dev_name(&hdev->dev));
41375 ret = device_add(&hdev->dev);
41376 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41377 index c13fb5b..55a3802 100644
41378 --- a/drivers/hid/hid-wiimote-debug.c
41379 +++ b/drivers/hid/hid-wiimote-debug.c
41380 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41381 else if (size == 0)
41382 return -EIO;
41383
41384 - if (copy_to_user(u, buf, size))
41385 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41386 return -EFAULT;
41387
41388 *off += size;
41389 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41390 index cedc6da..2c3da2a 100644
41391 --- a/drivers/hid/uhid.c
41392 +++ b/drivers/hid/uhid.c
41393 @@ -47,7 +47,7 @@ struct uhid_device {
41394 struct mutex report_lock;
41395 wait_queue_head_t report_wait;
41396 atomic_t report_done;
41397 - atomic_t report_id;
41398 + atomic_unchecked_t report_id;
41399 struct uhid_event report_buf;
41400 };
41401
41402 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41403
41404 spin_lock_irqsave(&uhid->qlock, flags);
41405 ev->type = UHID_FEATURE;
41406 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41407 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41408 ev->u.feature.rnum = rnum;
41409 ev->u.feature.rtype = report_type;
41410
41411 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41412 spin_lock_irqsave(&uhid->qlock, flags);
41413
41414 /* id for old report; drop it silently */
41415 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41416 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41417 goto unlock;
41418 if (atomic_read(&uhid->report_done))
41419 goto unlock;
41420 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41421 index cea623c..73011b0 100644
41422 --- a/drivers/hv/channel.c
41423 +++ b/drivers/hv/channel.c
41424 @@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41425 int ret = 0;
41426 int t;
41427
41428 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41429 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41430 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41431 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41432
41433 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41434 if (ret)
41435 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41436 index f0c5e07..399256e 100644
41437 --- a/drivers/hv/hv.c
41438 +++ b/drivers/hv/hv.c
41439 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41440 u64 output_address = (output) ? virt_to_phys(output) : 0;
41441 u32 output_address_hi = output_address >> 32;
41442 u32 output_address_lo = output_address & 0xFFFFFFFF;
41443 - void *hypercall_page = hv_context.hypercall_page;
41444 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41445
41446 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41447 "=a"(hv_status_lo) : "d" (control_hi),
41448 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41449 index 7e17a54..a50a33d 100644
41450 --- a/drivers/hv/hv_balloon.c
41451 +++ b/drivers/hv/hv_balloon.c
41452 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41453
41454 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41455 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41456 -static atomic_t trans_id = ATOMIC_INIT(0);
41457 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41458
41459 static int dm_ring_size = (5 * PAGE_SIZE);
41460
41461 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41462 pr_info("Memory hot add failed\n");
41463
41464 dm->state = DM_INITIALIZED;
41465 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41466 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41467 vmbus_sendpacket(dm->dev->channel, &resp,
41468 sizeof(struct dm_hot_add_response),
41469 (unsigned long)NULL,
41470 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41471 memset(&status, 0, sizeof(struct dm_status));
41472 status.hdr.type = DM_STATUS_REPORT;
41473 status.hdr.size = sizeof(struct dm_status);
41474 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41475 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41476
41477 /*
41478 * The host expects the guest to report free memory.
41479 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41480 * send the status. This can happen if we were interrupted
41481 * after we picked our transaction ID.
41482 */
41483 - if (status.hdr.trans_id != atomic_read(&trans_id))
41484 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41485 return;
41486
41487 vmbus_sendpacket(dm->dev->channel, &status,
41488 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41489 */
41490
41491 do {
41492 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41493 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41494 ret = vmbus_sendpacket(dm_device.dev->channel,
41495 bl_resp,
41496 bl_resp->hdr.size,
41497 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41498
41499 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41500 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41501 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41502 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41503 resp.hdr.size = sizeof(struct dm_unballoon_response);
41504
41505 vmbus_sendpacket(dm_device.dev->channel, &resp,
41506 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41507 memset(&version_req, 0, sizeof(struct dm_version_request));
41508 version_req.hdr.type = DM_VERSION_REQUEST;
41509 version_req.hdr.size = sizeof(struct dm_version_request);
41510 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41511 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41512 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41513 version_req.is_last_attempt = 1;
41514
41515 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41516 memset(&version_req, 0, sizeof(struct dm_version_request));
41517 version_req.hdr.type = DM_VERSION_REQUEST;
41518 version_req.hdr.size = sizeof(struct dm_version_request);
41519 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41520 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41521 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41522 version_req.is_last_attempt = 0;
41523
41524 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41525 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41526 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41527 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41528 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41529 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41530
41531 cap_msg.caps.cap_bits.balloon = 1;
41532 cap_msg.caps.cap_bits.hot_add = 1;
41533 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41534 index e055176..c22ff1f 100644
41535 --- a/drivers/hv/hyperv_vmbus.h
41536 +++ b/drivers/hv/hyperv_vmbus.h
41537 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41538 struct vmbus_connection {
41539 enum vmbus_connect_state conn_state;
41540
41541 - atomic_t next_gpadl_handle;
41542 + atomic_unchecked_t next_gpadl_handle;
41543
41544 /*
41545 * Represents channel interrupts. Each bit position represents a
41546 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41547 index 48aad4f..c768fb2 100644
41548 --- a/drivers/hv/vmbus_drv.c
41549 +++ b/drivers/hv/vmbus_drv.c
41550 @@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41551 {
41552 int ret = 0;
41553
41554 - static atomic_t device_num = ATOMIC_INIT(0);
41555 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41556
41557 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41558 - atomic_inc_return(&device_num));
41559 + atomic_inc_return_unchecked(&device_num));
41560
41561 child_device_obj->device.bus = &hv_bus;
41562 child_device_obj->device.parent = &hv_acpi_dev->dev;
41563 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41564 index 6a34f7f..aa4c3a6 100644
41565 --- a/drivers/hwmon/acpi_power_meter.c
41566 +++ b/drivers/hwmon/acpi_power_meter.c
41567 @@ -117,7 +117,7 @@ struct sensor_template {
41568 struct device_attribute *devattr,
41569 const char *buf, size_t count);
41570 int index;
41571 -};
41572 +} __do_const;
41573
41574 /* Averaging interval */
41575 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41576 @@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41577 struct sensor_template *attrs)
41578 {
41579 struct device *dev = &resource->acpi_dev->dev;
41580 - struct sensor_device_attribute *sensors =
41581 + sensor_device_attribute_no_const *sensors =
41582 &resource->sensors[resource->num_sensors];
41583 int res = 0;
41584
41585 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41586 index 3288f13..71cfb4e 100644
41587 --- a/drivers/hwmon/applesmc.c
41588 +++ b/drivers/hwmon/applesmc.c
41589 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41590 {
41591 struct applesmc_node_group *grp;
41592 struct applesmc_dev_attr *node;
41593 - struct attribute *attr;
41594 + attribute_no_const *attr;
41595 int ret, i;
41596
41597 for (grp = groups; grp->format; grp++) {
41598 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41599 index dafc63c..4abb96c 100644
41600 --- a/drivers/hwmon/asus_atk0110.c
41601 +++ b/drivers/hwmon/asus_atk0110.c
41602 @@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41603 struct atk_sensor_data {
41604 struct list_head list;
41605 struct atk_data *data;
41606 - struct device_attribute label_attr;
41607 - struct device_attribute input_attr;
41608 - struct device_attribute limit1_attr;
41609 - struct device_attribute limit2_attr;
41610 + device_attribute_no_const label_attr;
41611 + device_attribute_no_const input_attr;
41612 + device_attribute_no_const limit1_attr;
41613 + device_attribute_no_const limit2_attr;
41614 char label_attr_name[ATTR_NAME_SIZE];
41615 char input_attr_name[ATTR_NAME_SIZE];
41616 char limit1_attr_name[ATTR_NAME_SIZE];
41617 @@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
41618 static struct device_attribute atk_name_attr =
41619 __ATTR(name, 0444, atk_name_show, NULL);
41620
41621 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41622 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41623 sysfs_show_func show)
41624 {
41625 sysfs_attr_init(&attr->attr);
41626 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41627 index 9425098..7646cc5 100644
41628 --- a/drivers/hwmon/coretemp.c
41629 +++ b/drivers/hwmon/coretemp.c
41630 @@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41631 return NOTIFY_OK;
41632 }
41633
41634 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41635 +static struct notifier_block coretemp_cpu_notifier = {
41636 .notifier_call = coretemp_cpu_callback,
41637 };
41638
41639 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41640 index 632f1dc..57e6a58 100644
41641 --- a/drivers/hwmon/ibmaem.c
41642 +++ b/drivers/hwmon/ibmaem.c
41643 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41644 struct aem_rw_sensor_template *rw)
41645 {
41646 struct device *dev = &data->pdev->dev;
41647 - struct sensor_device_attribute *sensors = data->sensors;
41648 + sensor_device_attribute_no_const *sensors = data->sensors;
41649 int err;
41650
41651 /* Set up read-only sensors */
41652 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41653 index 708081b..fe2d4ab 100644
41654 --- a/drivers/hwmon/iio_hwmon.c
41655 +++ b/drivers/hwmon/iio_hwmon.c
41656 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41657 {
41658 struct device *dev = &pdev->dev;
41659 struct iio_hwmon_state *st;
41660 - struct sensor_device_attribute *a;
41661 + sensor_device_attribute_no_const *a;
41662 int ret, i;
41663 int in_i = 1, temp_i = 1, curr_i = 1;
41664 enum iio_chan_type type;
41665 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41666 index cf811c1..4c17110 100644
41667 --- a/drivers/hwmon/nct6775.c
41668 +++ b/drivers/hwmon/nct6775.c
41669 @@ -944,10 +944,10 @@ static struct attribute_group *
41670 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41671 int repeat)
41672 {
41673 - struct attribute_group *group;
41674 + attribute_group_no_const *group;
41675 struct sensor_device_attr_u *su;
41676 - struct sensor_device_attribute *a;
41677 - struct sensor_device_attribute_2 *a2;
41678 + sensor_device_attribute_no_const *a;
41679 + sensor_device_attribute_2_no_const *a2;
41680 struct attribute **attrs;
41681 struct sensor_device_template **t;
41682 int i, count;
41683 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41684 index 3cbf66e..8c5cc2a 100644
41685 --- a/drivers/hwmon/pmbus/pmbus_core.c
41686 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41687 @@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41688 return 0;
41689 }
41690
41691 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41692 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41693 const char *name,
41694 umode_t mode,
41695 ssize_t (*show)(struct device *dev,
41696 @@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41697 dev_attr->store = store;
41698 }
41699
41700 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41701 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41702 const char *name,
41703 umode_t mode,
41704 ssize_t (*show)(struct device *dev,
41705 @@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41706 u16 reg, u8 mask)
41707 {
41708 struct pmbus_boolean *boolean;
41709 - struct sensor_device_attribute *a;
41710 + sensor_device_attribute_no_const *a;
41711
41712 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41713 if (!boolean)
41714 @@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41715 bool update, bool readonly)
41716 {
41717 struct pmbus_sensor *sensor;
41718 - struct device_attribute *a;
41719 + device_attribute_no_const *a;
41720
41721 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41722 if (!sensor)
41723 @@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41724 const char *lstring, int index)
41725 {
41726 struct pmbus_label *label;
41727 - struct device_attribute *a;
41728 + device_attribute_no_const *a;
41729
41730 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41731 if (!label)
41732 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41733 index 97cd45a..ac54d8b 100644
41734 --- a/drivers/hwmon/sht15.c
41735 +++ b/drivers/hwmon/sht15.c
41736 @@ -169,7 +169,7 @@ struct sht15_data {
41737 int supply_uv;
41738 bool supply_uv_valid;
41739 struct work_struct update_supply_work;
41740 - atomic_t interrupt_handled;
41741 + atomic_unchecked_t interrupt_handled;
41742 };
41743
41744 /**
41745 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41746 ret = gpio_direction_input(data->pdata->gpio_data);
41747 if (ret)
41748 return ret;
41749 - atomic_set(&data->interrupt_handled, 0);
41750 + atomic_set_unchecked(&data->interrupt_handled, 0);
41751
41752 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41753 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41754 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41755 /* Only relevant if the interrupt hasn't occurred. */
41756 - if (!atomic_read(&data->interrupt_handled))
41757 + if (!atomic_read_unchecked(&data->interrupt_handled))
41758 schedule_work(&data->read_work);
41759 }
41760 ret = wait_event_timeout(data->wait_queue,
41761 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41762
41763 /* First disable the interrupt */
41764 disable_irq_nosync(irq);
41765 - atomic_inc(&data->interrupt_handled);
41766 + atomic_inc_unchecked(&data->interrupt_handled);
41767 /* Then schedule a reading work struct */
41768 if (data->state != SHT15_READING_NOTHING)
41769 schedule_work(&data->read_work);
41770 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41771 * If not, then start the interrupt again - care here as could
41772 * have gone low in meantime so verify it hasn't!
41773 */
41774 - atomic_set(&data->interrupt_handled, 0);
41775 + atomic_set_unchecked(&data->interrupt_handled, 0);
41776 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41777 /* If still not occurred or another handler was scheduled */
41778 if (gpio_get_value(data->pdata->gpio_data)
41779 - || atomic_read(&data->interrupt_handled))
41780 + || atomic_read_unchecked(&data->interrupt_handled))
41781 return;
41782 }
41783
41784 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41785 index 38944e9..ae9e5ed 100644
41786 --- a/drivers/hwmon/via-cputemp.c
41787 +++ b/drivers/hwmon/via-cputemp.c
41788 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41789 return NOTIFY_OK;
41790 }
41791
41792 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41793 +static struct notifier_block via_cputemp_cpu_notifier = {
41794 .notifier_call = via_cputemp_cpu_callback,
41795 };
41796
41797 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41798 index 07f01ac..d79ad3d 100644
41799 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41800 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41801 @@ -43,7 +43,7 @@
41802 extern struct i2c_adapter amd756_smbus;
41803
41804 static struct i2c_adapter *s4882_adapter;
41805 -static struct i2c_algorithm *s4882_algo;
41806 +static i2c_algorithm_no_const *s4882_algo;
41807
41808 /* Wrapper access functions for multiplexed SMBus */
41809 static DEFINE_MUTEX(amd756_lock);
41810 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41811 index 721f7eb..0fd2a09 100644
41812 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41813 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41814 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41815 /* usb layer */
41816
41817 /* Send command to device, and get response. */
41818 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41819 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41820 {
41821 int ret = 0;
41822 int actual;
41823 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41824 index 2ca268d..c6acbdf 100644
41825 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41826 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41827 @@ -41,7 +41,7 @@
41828 extern struct i2c_adapter *nforce2_smbus;
41829
41830 static struct i2c_adapter *s4985_adapter;
41831 -static struct i2c_algorithm *s4985_algo;
41832 +static i2c_algorithm_no_const *s4985_algo;
41833
41834 /* Wrapper access functions for multiplexed SMBus */
41835 static DEFINE_MUTEX(nforce2_lock);
41836 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41837 index 80b47e8..1a6040d9 100644
41838 --- a/drivers/i2c/i2c-dev.c
41839 +++ b/drivers/i2c/i2c-dev.c
41840 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41841 break;
41842 }
41843
41844 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41845 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41846 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41847 if (IS_ERR(rdwr_pa[i].buf)) {
41848 res = PTR_ERR(rdwr_pa[i].buf);
41849 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41850 index 0b510ba..4fbb5085 100644
41851 --- a/drivers/ide/ide-cd.c
41852 +++ b/drivers/ide/ide-cd.c
41853 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41854 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41855 if ((unsigned long)buf & alignment
41856 || blk_rq_bytes(rq) & q->dma_pad_mask
41857 - || object_is_on_stack(buf))
41858 + || object_starts_on_stack(buf))
41859 drive->dma = 0;
41860 }
41861 }
41862 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41863 index 18f72e3..3722327 100644
41864 --- a/drivers/iio/industrialio-core.c
41865 +++ b/drivers/iio/industrialio-core.c
41866 @@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41867 }
41868
41869 static
41870 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41871 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41872 const char *postfix,
41873 struct iio_chan_spec const *chan,
41874 ssize_t (*readfunc)(struct device *dev,
41875 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41876 index f2ef7ef..743d02f 100644
41877 --- a/drivers/infiniband/core/cm.c
41878 +++ b/drivers/infiniband/core/cm.c
41879 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41880
41881 struct cm_counter_group {
41882 struct kobject obj;
41883 - atomic_long_t counter[CM_ATTR_COUNT];
41884 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41885 };
41886
41887 struct cm_counter_attribute {
41888 @@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41889 struct ib_mad_send_buf *msg = NULL;
41890 int ret;
41891
41892 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41893 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41894 counter[CM_REQ_COUNTER]);
41895
41896 /* Quick state check to discard duplicate REQs. */
41897 @@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41898 if (!cm_id_priv)
41899 return;
41900
41901 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41902 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41903 counter[CM_REP_COUNTER]);
41904 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41905 if (ret)
41906 @@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41907 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41908 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41909 spin_unlock_irq(&cm_id_priv->lock);
41910 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41911 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41912 counter[CM_RTU_COUNTER]);
41913 goto out;
41914 }
41915 @@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41916 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41917 dreq_msg->local_comm_id);
41918 if (!cm_id_priv) {
41919 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41920 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41921 counter[CM_DREQ_COUNTER]);
41922 cm_issue_drep(work->port, work->mad_recv_wc);
41923 return -EINVAL;
41924 @@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41925 case IB_CM_MRA_REP_RCVD:
41926 break;
41927 case IB_CM_TIMEWAIT:
41928 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41929 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41930 counter[CM_DREQ_COUNTER]);
41931 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41932 goto unlock;
41933 @@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41934 cm_free_msg(msg);
41935 goto deref;
41936 case IB_CM_DREQ_RCVD:
41937 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41938 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41939 counter[CM_DREQ_COUNTER]);
41940 goto unlock;
41941 default:
41942 @@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41943 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41944 cm_id_priv->msg, timeout)) {
41945 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41946 - atomic_long_inc(&work->port->
41947 + atomic_long_inc_unchecked(&work->port->
41948 counter_group[CM_RECV_DUPLICATES].
41949 counter[CM_MRA_COUNTER]);
41950 goto out;
41951 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41952 break;
41953 case IB_CM_MRA_REQ_RCVD:
41954 case IB_CM_MRA_REP_RCVD:
41955 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41956 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41957 counter[CM_MRA_COUNTER]);
41958 /* fall through */
41959 default:
41960 @@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41961 case IB_CM_LAP_IDLE:
41962 break;
41963 case IB_CM_MRA_LAP_SENT:
41964 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41965 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41966 counter[CM_LAP_COUNTER]);
41967 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41968 goto unlock;
41969 @@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41970 cm_free_msg(msg);
41971 goto deref;
41972 case IB_CM_LAP_RCVD:
41973 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41974 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41975 counter[CM_LAP_COUNTER]);
41976 goto unlock;
41977 default:
41978 @@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41979 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41980 if (cur_cm_id_priv) {
41981 spin_unlock_irq(&cm.lock);
41982 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41983 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41984 counter[CM_SIDR_REQ_COUNTER]);
41985 goto out; /* Duplicate message. */
41986 }
41987 @@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41988 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41989 msg->retries = 1;
41990
41991 - atomic_long_add(1 + msg->retries,
41992 + atomic_long_add_unchecked(1 + msg->retries,
41993 &port->counter_group[CM_XMIT].counter[attr_index]);
41994 if (msg->retries)
41995 - atomic_long_add(msg->retries,
41996 + atomic_long_add_unchecked(msg->retries,
41997 &port->counter_group[CM_XMIT_RETRIES].
41998 counter[attr_index]);
41999
42000 @@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42001 }
42002
42003 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42004 - atomic_long_inc(&port->counter_group[CM_RECV].
42005 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42006 counter[attr_id - CM_ATTR_ID_OFFSET]);
42007
42008 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42009 @@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42010 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42011
42012 return sprintf(buf, "%ld\n",
42013 - atomic_long_read(&group->counter[cm_attr->index]));
42014 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42015 }
42016
42017 static const struct sysfs_ops cm_counter_ops = {
42018 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42019 index 9f5ad7c..588cd84 100644
42020 --- a/drivers/infiniband/core/fmr_pool.c
42021 +++ b/drivers/infiniband/core/fmr_pool.c
42022 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42023
42024 struct task_struct *thread;
42025
42026 - atomic_t req_ser;
42027 - atomic_t flush_ser;
42028 + atomic_unchecked_t req_ser;
42029 + atomic_unchecked_t flush_ser;
42030
42031 wait_queue_head_t force_wait;
42032 };
42033 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42034 struct ib_fmr_pool *pool = pool_ptr;
42035
42036 do {
42037 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42038 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42039 ib_fmr_batch_release(pool);
42040
42041 - atomic_inc(&pool->flush_ser);
42042 + atomic_inc_unchecked(&pool->flush_ser);
42043 wake_up_interruptible(&pool->force_wait);
42044
42045 if (pool->flush_function)
42046 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42047 }
42048
42049 set_current_state(TASK_INTERRUPTIBLE);
42050 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42051 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42052 !kthread_should_stop())
42053 schedule();
42054 __set_current_state(TASK_RUNNING);
42055 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42056 pool->dirty_watermark = params->dirty_watermark;
42057 pool->dirty_len = 0;
42058 spin_lock_init(&pool->pool_lock);
42059 - atomic_set(&pool->req_ser, 0);
42060 - atomic_set(&pool->flush_ser, 0);
42061 + atomic_set_unchecked(&pool->req_ser, 0);
42062 + atomic_set_unchecked(&pool->flush_ser, 0);
42063 init_waitqueue_head(&pool->force_wait);
42064
42065 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42066 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42067 }
42068 spin_unlock_irq(&pool->pool_lock);
42069
42070 - serial = atomic_inc_return(&pool->req_ser);
42071 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42072 wake_up_process(pool->thread);
42073
42074 if (wait_event_interruptible(pool->force_wait,
42075 - atomic_read(&pool->flush_ser) - serial >= 0))
42076 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42077 return -EINTR;
42078
42079 return 0;
42080 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42081 } else {
42082 list_add_tail(&fmr->list, &pool->dirty_list);
42083 if (++pool->dirty_len >= pool->dirty_watermark) {
42084 - atomic_inc(&pool->req_ser);
42085 + atomic_inc_unchecked(&pool->req_ser);
42086 wake_up_process(pool->thread);
42087 }
42088 }
42089 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42090 index 84e4500..2c9beeb 100644
42091 --- a/drivers/infiniband/hw/cxgb4/mem.c
42092 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42093 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42094 int err;
42095 struct fw_ri_tpte tpt;
42096 u32 stag_idx;
42097 - static atomic_t key;
42098 + static atomic_unchecked_t key;
42099
42100 if (c4iw_fatal_error(rdev))
42101 return -EIO;
42102 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42103 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42104 rdev->stats.stag.max = rdev->stats.stag.cur;
42105 mutex_unlock(&rdev->stats.lock);
42106 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42107 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42108 }
42109 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42110 __func__, stag_state, type, pdid, stag_idx);
42111 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42112 index 644c2c7..ecf0879 100644
42113 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
42114 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42115 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42116 }
42117
42118 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42119 - ipath_mapping_error,
42120 - ipath_dma_map_single,
42121 - ipath_dma_unmap_single,
42122 - ipath_dma_map_page,
42123 - ipath_dma_unmap_page,
42124 - ipath_map_sg,
42125 - ipath_unmap_sg,
42126 - ipath_sg_dma_address,
42127 - ipath_sg_dma_len,
42128 - ipath_sync_single_for_cpu,
42129 - ipath_sync_single_for_device,
42130 - ipath_dma_alloc_coherent,
42131 - ipath_dma_free_coherent
42132 + .mapping_error = ipath_mapping_error,
42133 + .map_single = ipath_dma_map_single,
42134 + .unmap_single = ipath_dma_unmap_single,
42135 + .map_page = ipath_dma_map_page,
42136 + .unmap_page = ipath_dma_unmap_page,
42137 + .map_sg = ipath_map_sg,
42138 + .unmap_sg = ipath_unmap_sg,
42139 + .dma_address = ipath_sg_dma_address,
42140 + .dma_len = ipath_sg_dma_len,
42141 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
42142 + .sync_single_for_device = ipath_sync_single_for_device,
42143 + .alloc_coherent = ipath_dma_alloc_coherent,
42144 + .free_coherent = ipath_dma_free_coherent
42145 };
42146 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42147 index 79b3dbc..96e5fcc 100644
42148 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42149 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42150 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42151 struct ib_atomic_eth *ateth;
42152 struct ipath_ack_entry *e;
42153 u64 vaddr;
42154 - atomic64_t *maddr;
42155 + atomic64_unchecked_t *maddr;
42156 u64 sdata;
42157 u32 rkey;
42158 u8 next;
42159 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42160 IB_ACCESS_REMOTE_ATOMIC)))
42161 goto nack_acc_unlck;
42162 /* Perform atomic OP and save result. */
42163 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42164 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42165 sdata = be64_to_cpu(ateth->swap_data);
42166 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42167 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42168 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42169 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42170 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42171 be64_to_cpu(ateth->compare_data),
42172 sdata);
42173 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42174 index 1f95bba..9530f87 100644
42175 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42176 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42177 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42178 unsigned long flags;
42179 struct ib_wc wc;
42180 u64 sdata;
42181 - atomic64_t *maddr;
42182 + atomic64_unchecked_t *maddr;
42183 enum ib_wc_status send_status;
42184
42185 /*
42186 @@ -382,11 +382,11 @@ again:
42187 IB_ACCESS_REMOTE_ATOMIC)))
42188 goto acc_err;
42189 /* Perform atomic OP and save result. */
42190 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42191 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42192 sdata = wqe->wr.wr.atomic.compare_add;
42193 *(u64 *) sqp->s_sge.sge.vaddr =
42194 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42195 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42196 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42197 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42198 sdata, wqe->wr.wr.atomic.swap);
42199 goto send_comp;
42200 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42201 index f2a3f48..673ec79 100644
42202 --- a/drivers/infiniband/hw/mlx4/mad.c
42203 +++ b/drivers/infiniband/hw/mlx4/mad.c
42204 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42205
42206 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42207 {
42208 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42209 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42210 cpu_to_be64(0xff00000000000000LL);
42211 }
42212
42213 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42214 index 25b2cdf..099ff97 100644
42215 --- a/drivers/infiniband/hw/mlx4/mcg.c
42216 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42217 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42218 {
42219 char name[20];
42220
42221 - atomic_set(&ctx->tid, 0);
42222 + atomic_set_unchecked(&ctx->tid, 0);
42223 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42224 ctx->mcg_wq = create_singlethread_workqueue(name);
42225 if (!ctx->mcg_wq)
42226 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42227 index 036b663..c9a8c73 100644
42228 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42229 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42230 @@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
42231 struct list_head mcg_mgid0_list;
42232 struct workqueue_struct *mcg_wq;
42233 struct mlx4_ib_demux_pv_ctx **tun;
42234 - atomic_t tid;
42235 + atomic_unchecked_t tid;
42236 int flushing; /* flushing the work queue */
42237 };
42238
42239 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42240 index 9d3e5c1..6f166df 100644
42241 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42242 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42243 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42244 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42245 }
42246
42247 -int mthca_QUERY_FW(struct mthca_dev *dev)
42248 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42249 {
42250 struct mthca_mailbox *mailbox;
42251 u32 *outbox;
42252 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42253 CMD_TIME_CLASS_B);
42254 }
42255
42256 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42257 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42258 int num_mtt)
42259 {
42260 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42261 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42262 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42263 }
42264
42265 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42266 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42267 int eq_num)
42268 {
42269 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42270 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42271 CMD_TIME_CLASS_B);
42272 }
42273
42274 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42275 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42276 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42277 void *in_mad, void *response_mad)
42278 {
42279 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42280 index 87897b9..7e79542 100644
42281 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42282 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42283 @@ -692,7 +692,7 @@ err_close:
42284 return err;
42285 }
42286
42287 -static int mthca_setup_hca(struct mthca_dev *dev)
42288 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42289 {
42290 int err;
42291
42292 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42293 index ed9a989..6aa5dc2 100644
42294 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42295 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42296 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42297 * through the bitmaps)
42298 */
42299
42300 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42301 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42302 {
42303 int o;
42304 int m;
42305 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42306 return key;
42307 }
42308
42309 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42310 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42311 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42312 {
42313 struct mthca_mailbox *mailbox;
42314 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42315 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42316 }
42317
42318 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42319 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42320 u64 *buffer_list, int buffer_size_shift,
42321 int list_len, u64 iova, u64 total_size,
42322 u32 access, struct mthca_mr *mr)
42323 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42324 index 5b71d43..35a9e14 100644
42325 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42326 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42327 @@ -763,7 +763,7 @@ unlock:
42328 return 0;
42329 }
42330
42331 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42332 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42333 {
42334 struct mthca_dev *dev = to_mdev(ibcq->device);
42335 struct mthca_cq *cq = to_mcq(ibcq);
42336 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42337 index 4291410..d2ab1fb 100644
42338 --- a/drivers/infiniband/hw/nes/nes.c
42339 +++ b/drivers/infiniband/hw/nes/nes.c
42340 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42341 LIST_HEAD(nes_adapter_list);
42342 static LIST_HEAD(nes_dev_list);
42343
42344 -atomic_t qps_destroyed;
42345 +atomic_unchecked_t qps_destroyed;
42346
42347 static unsigned int ee_flsh_adapter;
42348 static unsigned int sysfs_nonidx_addr;
42349 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42350 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42351 struct nes_adapter *nesadapter = nesdev->nesadapter;
42352
42353 - atomic_inc(&qps_destroyed);
42354 + atomic_inc_unchecked(&qps_destroyed);
42355
42356 /* Free the control structures */
42357
42358 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42359 index 33cc589..3bd6538 100644
42360 --- a/drivers/infiniband/hw/nes/nes.h
42361 +++ b/drivers/infiniband/hw/nes/nes.h
42362 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42363 extern unsigned int wqm_quanta;
42364 extern struct list_head nes_adapter_list;
42365
42366 -extern atomic_t cm_connects;
42367 -extern atomic_t cm_accepts;
42368 -extern atomic_t cm_disconnects;
42369 -extern atomic_t cm_closes;
42370 -extern atomic_t cm_connecteds;
42371 -extern atomic_t cm_connect_reqs;
42372 -extern atomic_t cm_rejects;
42373 -extern atomic_t mod_qp_timouts;
42374 -extern atomic_t qps_created;
42375 -extern atomic_t qps_destroyed;
42376 -extern atomic_t sw_qps_destroyed;
42377 +extern atomic_unchecked_t cm_connects;
42378 +extern atomic_unchecked_t cm_accepts;
42379 +extern atomic_unchecked_t cm_disconnects;
42380 +extern atomic_unchecked_t cm_closes;
42381 +extern atomic_unchecked_t cm_connecteds;
42382 +extern atomic_unchecked_t cm_connect_reqs;
42383 +extern atomic_unchecked_t cm_rejects;
42384 +extern atomic_unchecked_t mod_qp_timouts;
42385 +extern atomic_unchecked_t qps_created;
42386 +extern atomic_unchecked_t qps_destroyed;
42387 +extern atomic_unchecked_t sw_qps_destroyed;
42388 extern u32 mh_detected;
42389 extern u32 mh_pauses_sent;
42390 extern u32 cm_packets_sent;
42391 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42392 extern u32 cm_packets_received;
42393 extern u32 cm_packets_dropped;
42394 extern u32 cm_packets_retrans;
42395 -extern atomic_t cm_listens_created;
42396 -extern atomic_t cm_listens_destroyed;
42397 +extern atomic_unchecked_t cm_listens_created;
42398 +extern atomic_unchecked_t cm_listens_destroyed;
42399 extern u32 cm_backlog_drops;
42400 -extern atomic_t cm_loopbacks;
42401 -extern atomic_t cm_nodes_created;
42402 -extern atomic_t cm_nodes_destroyed;
42403 -extern atomic_t cm_accel_dropped_pkts;
42404 -extern atomic_t cm_resets_recvd;
42405 -extern atomic_t pau_qps_created;
42406 -extern atomic_t pau_qps_destroyed;
42407 +extern atomic_unchecked_t cm_loopbacks;
42408 +extern atomic_unchecked_t cm_nodes_created;
42409 +extern atomic_unchecked_t cm_nodes_destroyed;
42410 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42411 +extern atomic_unchecked_t cm_resets_recvd;
42412 +extern atomic_unchecked_t pau_qps_created;
42413 +extern atomic_unchecked_t pau_qps_destroyed;
42414
42415 extern u32 int_mod_timer_init;
42416 extern u32 int_mod_cq_depth_256;
42417 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42418 index 6b29249..461d143 100644
42419 --- a/drivers/infiniband/hw/nes/nes_cm.c
42420 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42421 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42422 u32 cm_packets_retrans;
42423 u32 cm_packets_created;
42424 u32 cm_packets_received;
42425 -atomic_t cm_listens_created;
42426 -atomic_t cm_listens_destroyed;
42427 +atomic_unchecked_t cm_listens_created;
42428 +atomic_unchecked_t cm_listens_destroyed;
42429 u32 cm_backlog_drops;
42430 -atomic_t cm_loopbacks;
42431 -atomic_t cm_nodes_created;
42432 -atomic_t cm_nodes_destroyed;
42433 -atomic_t cm_accel_dropped_pkts;
42434 -atomic_t cm_resets_recvd;
42435 +atomic_unchecked_t cm_loopbacks;
42436 +atomic_unchecked_t cm_nodes_created;
42437 +atomic_unchecked_t cm_nodes_destroyed;
42438 +atomic_unchecked_t cm_accel_dropped_pkts;
42439 +atomic_unchecked_t cm_resets_recvd;
42440
42441 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42442 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42443 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42444 /* instance of function pointers for client API */
42445 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42446 static struct nes_cm_ops nes_cm_api = {
42447 - mini_cm_accelerated,
42448 - mini_cm_listen,
42449 - mini_cm_del_listen,
42450 - mini_cm_connect,
42451 - mini_cm_close,
42452 - mini_cm_accept,
42453 - mini_cm_reject,
42454 - mini_cm_recv_pkt,
42455 - mini_cm_dealloc_core,
42456 - mini_cm_get,
42457 - mini_cm_set
42458 + .accelerated = mini_cm_accelerated,
42459 + .listen = mini_cm_listen,
42460 + .stop_listener = mini_cm_del_listen,
42461 + .connect = mini_cm_connect,
42462 + .close = mini_cm_close,
42463 + .accept = mini_cm_accept,
42464 + .reject = mini_cm_reject,
42465 + .recv_pkt = mini_cm_recv_pkt,
42466 + .destroy_cm_core = mini_cm_dealloc_core,
42467 + .get = mini_cm_get,
42468 + .set = mini_cm_set
42469 };
42470
42471 static struct nes_cm_core *g_cm_core;
42472
42473 -atomic_t cm_connects;
42474 -atomic_t cm_accepts;
42475 -atomic_t cm_disconnects;
42476 -atomic_t cm_closes;
42477 -atomic_t cm_connecteds;
42478 -atomic_t cm_connect_reqs;
42479 -atomic_t cm_rejects;
42480 +atomic_unchecked_t cm_connects;
42481 +atomic_unchecked_t cm_accepts;
42482 +atomic_unchecked_t cm_disconnects;
42483 +atomic_unchecked_t cm_closes;
42484 +atomic_unchecked_t cm_connecteds;
42485 +atomic_unchecked_t cm_connect_reqs;
42486 +atomic_unchecked_t cm_rejects;
42487
42488 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42489 {
42490 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42491 kfree(listener);
42492 listener = NULL;
42493 ret = 0;
42494 - atomic_inc(&cm_listens_destroyed);
42495 + atomic_inc_unchecked(&cm_listens_destroyed);
42496 } else {
42497 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42498 }
42499 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42500 cm_node->rem_mac);
42501
42502 add_hte_node(cm_core, cm_node);
42503 - atomic_inc(&cm_nodes_created);
42504 + atomic_inc_unchecked(&cm_nodes_created);
42505
42506 return cm_node;
42507 }
42508 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42509 }
42510
42511 atomic_dec(&cm_core->node_cnt);
42512 - atomic_inc(&cm_nodes_destroyed);
42513 + atomic_inc_unchecked(&cm_nodes_destroyed);
42514 nesqp = cm_node->nesqp;
42515 if (nesqp) {
42516 nesqp->cm_node = NULL;
42517 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42518
42519 static void drop_packet(struct sk_buff *skb)
42520 {
42521 - atomic_inc(&cm_accel_dropped_pkts);
42522 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42523 dev_kfree_skb_any(skb);
42524 }
42525
42526 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42527 {
42528
42529 int reset = 0; /* whether to send reset in case of err.. */
42530 - atomic_inc(&cm_resets_recvd);
42531 + atomic_inc_unchecked(&cm_resets_recvd);
42532 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42533 " refcnt=%d\n", cm_node, cm_node->state,
42534 atomic_read(&cm_node->ref_count));
42535 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42536 rem_ref_cm_node(cm_node->cm_core, cm_node);
42537 return NULL;
42538 }
42539 - atomic_inc(&cm_loopbacks);
42540 + atomic_inc_unchecked(&cm_loopbacks);
42541 loopbackremotenode->loopbackpartner = cm_node;
42542 loopbackremotenode->tcp_cntxt.rcv_wscale =
42543 NES_CM_DEFAULT_RCV_WND_SCALE;
42544 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42545 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42546 else {
42547 rem_ref_cm_node(cm_core, cm_node);
42548 - atomic_inc(&cm_accel_dropped_pkts);
42549 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42550 dev_kfree_skb_any(skb);
42551 }
42552 break;
42553 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42554
42555 if ((cm_id) && (cm_id->event_handler)) {
42556 if (issue_disconn) {
42557 - atomic_inc(&cm_disconnects);
42558 + atomic_inc_unchecked(&cm_disconnects);
42559 cm_event.event = IW_CM_EVENT_DISCONNECT;
42560 cm_event.status = disconn_status;
42561 cm_event.local_addr = cm_id->local_addr;
42562 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42563 }
42564
42565 if (issue_close) {
42566 - atomic_inc(&cm_closes);
42567 + atomic_inc_unchecked(&cm_closes);
42568 nes_disconnect(nesqp, 1);
42569
42570 cm_id->provider_data = nesqp;
42571 @@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42572
42573 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42574 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42575 - atomic_inc(&cm_accepts);
42576 + atomic_inc_unchecked(&cm_accepts);
42577
42578 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42579 netdev_refcnt_read(nesvnic->netdev));
42580 @@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42581 struct nes_cm_core *cm_core;
42582 u8 *start_buff;
42583
42584 - atomic_inc(&cm_rejects);
42585 + atomic_inc_unchecked(&cm_rejects);
42586 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42587 loopback = cm_node->loopbackpartner;
42588 cm_core = cm_node->cm_core;
42589 @@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42590 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42591 ntohs(laddr->sin_port));
42592
42593 - atomic_inc(&cm_connects);
42594 + atomic_inc_unchecked(&cm_connects);
42595 nesqp->active_conn = 1;
42596
42597 /* cache the cm_id in the qp */
42598 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42599 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42600 return err;
42601 }
42602 - atomic_inc(&cm_listens_created);
42603 + atomic_inc_unchecked(&cm_listens_created);
42604 }
42605
42606 cm_id->add_ref(cm_id);
42607 @@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42608
42609 if (nesqp->destroyed)
42610 return;
42611 - atomic_inc(&cm_connecteds);
42612 + atomic_inc_unchecked(&cm_connecteds);
42613 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42614 " local port 0x%04X. jiffies = %lu.\n",
42615 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42616 @@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42617
42618 cm_id->add_ref(cm_id);
42619 ret = cm_id->event_handler(cm_id, &cm_event);
42620 - atomic_inc(&cm_closes);
42621 + atomic_inc_unchecked(&cm_closes);
42622 cm_event.event = IW_CM_EVENT_CLOSE;
42623 cm_event.status = 0;
42624 cm_event.provider_data = cm_id->provider_data;
42625 @@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42626 return;
42627 cm_id = cm_node->cm_id;
42628
42629 - atomic_inc(&cm_connect_reqs);
42630 + atomic_inc_unchecked(&cm_connect_reqs);
42631 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42632 cm_node, cm_id, jiffies);
42633
42634 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42635 return;
42636 cm_id = cm_node->cm_id;
42637
42638 - atomic_inc(&cm_connect_reqs);
42639 + atomic_inc_unchecked(&cm_connect_reqs);
42640 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42641 cm_node, cm_id, jiffies);
42642
42643 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42644 index 4166452..fc952c3 100644
42645 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42646 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42647 @@ -40,8 +40,8 @@
42648 #include "nes.h"
42649 #include "nes_mgt.h"
42650
42651 -atomic_t pau_qps_created;
42652 -atomic_t pau_qps_destroyed;
42653 +atomic_unchecked_t pau_qps_created;
42654 +atomic_unchecked_t pau_qps_destroyed;
42655
42656 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42657 {
42658 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42659 {
42660 struct sk_buff *skb;
42661 unsigned long flags;
42662 - atomic_inc(&pau_qps_destroyed);
42663 + atomic_inc_unchecked(&pau_qps_destroyed);
42664
42665 /* Free packets that have not yet been forwarded */
42666 /* Lock is acquired by skb_dequeue when removing the skb */
42667 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42668 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42669 skb_queue_head_init(&nesqp->pau_list);
42670 spin_lock_init(&nesqp->pau_lock);
42671 - atomic_inc(&pau_qps_created);
42672 + atomic_inc_unchecked(&pau_qps_created);
42673 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42674 }
42675
42676 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42677 index 49eb511..a774366 100644
42678 --- a/drivers/infiniband/hw/nes/nes_nic.c
42679 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42680 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42681 target_stat_values[++index] = mh_detected;
42682 target_stat_values[++index] = mh_pauses_sent;
42683 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42684 - target_stat_values[++index] = atomic_read(&cm_connects);
42685 - target_stat_values[++index] = atomic_read(&cm_accepts);
42686 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42687 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42688 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42689 - target_stat_values[++index] = atomic_read(&cm_rejects);
42690 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42691 - target_stat_values[++index] = atomic_read(&qps_created);
42692 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42693 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42694 - target_stat_values[++index] = atomic_read(&cm_closes);
42695 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42696 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42697 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42698 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42699 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42700 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42701 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42702 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42703 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42704 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42705 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42706 target_stat_values[++index] = cm_packets_sent;
42707 target_stat_values[++index] = cm_packets_bounced;
42708 target_stat_values[++index] = cm_packets_created;
42709 target_stat_values[++index] = cm_packets_received;
42710 target_stat_values[++index] = cm_packets_dropped;
42711 target_stat_values[++index] = cm_packets_retrans;
42712 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42713 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42714 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42715 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42716 target_stat_values[++index] = cm_backlog_drops;
42717 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42718 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42719 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42720 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42721 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42722 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42723 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42724 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42725 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42726 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42727 target_stat_values[++index] = nesadapter->free_4kpbl;
42728 target_stat_values[++index] = nesadapter->free_256pbl;
42729 target_stat_values[++index] = int_mod_timer_init;
42730 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42731 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42732 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42733 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42734 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42735 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42736 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42737 }
42738
42739 /**
42740 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42741 index 8308e36..ae0d3b5 100644
42742 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42743 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42744 @@ -46,9 +46,9 @@
42745
42746 #include <rdma/ib_umem.h>
42747
42748 -atomic_t mod_qp_timouts;
42749 -atomic_t qps_created;
42750 -atomic_t sw_qps_destroyed;
42751 +atomic_unchecked_t mod_qp_timouts;
42752 +atomic_unchecked_t qps_created;
42753 +atomic_unchecked_t sw_qps_destroyed;
42754
42755 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42756
42757 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42758 if (init_attr->create_flags)
42759 return ERR_PTR(-EINVAL);
42760
42761 - atomic_inc(&qps_created);
42762 + atomic_inc_unchecked(&qps_created);
42763 switch (init_attr->qp_type) {
42764 case IB_QPT_RC:
42765 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42766 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42767 struct iw_cm_event cm_event;
42768 int ret = 0;
42769
42770 - atomic_inc(&sw_qps_destroyed);
42771 + atomic_inc_unchecked(&sw_qps_destroyed);
42772 nesqp->destroyed = 1;
42773
42774 /* Blow away the connection if it exists. */
42775 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42776 index 1946101..09766d2 100644
42777 --- a/drivers/infiniband/hw/qib/qib.h
42778 +++ b/drivers/infiniband/hw/qib/qib.h
42779 @@ -52,6 +52,7 @@
42780 #include <linux/kref.h>
42781 #include <linux/sched.h>
42782 #include <linux/kthread.h>
42783 +#include <linux/slab.h>
42784
42785 #include "qib_common.h"
42786 #include "qib_verbs.h"
42787 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42788 index 24c41ba..102d71f 100644
42789 --- a/drivers/input/gameport/gameport.c
42790 +++ b/drivers/input/gameport/gameport.c
42791 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42792 */
42793 static void gameport_init_port(struct gameport *gameport)
42794 {
42795 - static atomic_t gameport_no = ATOMIC_INIT(0);
42796 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42797
42798 __module_get(THIS_MODULE);
42799
42800 mutex_init(&gameport->drv_mutex);
42801 device_initialize(&gameport->dev);
42802 dev_set_name(&gameport->dev, "gameport%lu",
42803 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42804 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42805 gameport->dev.bus = &gameport_bus;
42806 gameport->dev.release = gameport_release_port;
42807 if (gameport->parent)
42808 diff --git a/drivers/input/input.c b/drivers/input/input.c
42809 index d2965e4..f52b7d7 100644
42810 --- a/drivers/input/input.c
42811 +++ b/drivers/input/input.c
42812 @@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42813 */
42814 struct input_dev *input_allocate_device(void)
42815 {
42816 - static atomic_t input_no = ATOMIC_INIT(0);
42817 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42818 struct input_dev *dev;
42819
42820 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42821 @@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42822 INIT_LIST_HEAD(&dev->node);
42823
42824 dev_set_name(&dev->dev, "input%ld",
42825 - (unsigned long) atomic_inc_return(&input_no) - 1);
42826 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42827
42828 __module_get(THIS_MODULE);
42829 }
42830 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42831 index 04c69af..5f92d00 100644
42832 --- a/drivers/input/joystick/sidewinder.c
42833 +++ b/drivers/input/joystick/sidewinder.c
42834 @@ -30,6 +30,7 @@
42835 #include <linux/kernel.h>
42836 #include <linux/module.h>
42837 #include <linux/slab.h>
42838 +#include <linux/sched.h>
42839 #include <linux/init.h>
42840 #include <linux/input.h>
42841 #include <linux/gameport.h>
42842 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42843 index 75e3b10..fb390fd 100644
42844 --- a/drivers/input/joystick/xpad.c
42845 +++ b/drivers/input/joystick/xpad.c
42846 @@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42847
42848 static int xpad_led_probe(struct usb_xpad *xpad)
42849 {
42850 - static atomic_t led_seq = ATOMIC_INIT(0);
42851 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42852 long led_no;
42853 struct xpad_led *led;
42854 struct led_classdev *led_cdev;
42855 @@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42856 if (!led)
42857 return -ENOMEM;
42858
42859 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42860 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42861
42862 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42863 led->xpad = xpad;
42864 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42865 index e204f26..8459f15 100644
42866 --- a/drivers/input/misc/ims-pcu.c
42867 +++ b/drivers/input/misc/ims-pcu.c
42868 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42869
42870 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42871 {
42872 - static atomic_t device_no = ATOMIC_INIT(0);
42873 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42874
42875 const struct ims_pcu_device_info *info;
42876 u8 device_id;
42877 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42878 }
42879
42880 /* Device appears to be operable, complete initialization */
42881 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42882 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42883
42884 error = ims_pcu_setup_backlight(pcu);
42885 if (error)
42886 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42887 index 2f0b39d..7370f13 100644
42888 --- a/drivers/input/mouse/psmouse.h
42889 +++ b/drivers/input/mouse/psmouse.h
42890 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42891 ssize_t (*set)(struct psmouse *psmouse, void *data,
42892 const char *buf, size_t count);
42893 bool protect;
42894 -};
42895 +} __do_const;
42896 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42897
42898 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42899 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42900 index 4c842c3..590b0bf 100644
42901 --- a/drivers/input/mousedev.c
42902 +++ b/drivers/input/mousedev.c
42903 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42904
42905 spin_unlock_irq(&client->packet_lock);
42906
42907 - if (copy_to_user(buffer, data, count))
42908 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42909 return -EFAULT;
42910
42911 return count;
42912 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42913 index 8f4c4ab..5fc8a45 100644
42914 --- a/drivers/input/serio/serio.c
42915 +++ b/drivers/input/serio/serio.c
42916 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42917 */
42918 static void serio_init_port(struct serio *serio)
42919 {
42920 - static atomic_t serio_no = ATOMIC_INIT(0);
42921 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42922
42923 __module_get(THIS_MODULE);
42924
42925 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42926 mutex_init(&serio->drv_mutex);
42927 device_initialize(&serio->dev);
42928 dev_set_name(&serio->dev, "serio%ld",
42929 - (long)atomic_inc_return(&serio_no) - 1);
42930 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42931 serio->dev.bus = &serio_bus;
42932 serio->dev.release = serio_release_port;
42933 serio->dev.groups = serio_device_attr_groups;
42934 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42935 index 59df2e7..8f1cafb 100644
42936 --- a/drivers/input/serio/serio_raw.c
42937 +++ b/drivers/input/serio/serio_raw.c
42938 @@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42939
42940 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42941 {
42942 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42943 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42944 struct serio_raw *serio_raw;
42945 int err;
42946
42947 @@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42948 }
42949
42950 snprintf(serio_raw->name, sizeof(serio_raw->name),
42951 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42952 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42953 kref_init(&serio_raw->kref);
42954 INIT_LIST_HEAD(&serio_raw->client_list);
42955 init_waitqueue_head(&serio_raw->wait);
42956 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42957 index e5555fc..937986d 100644
42958 --- a/drivers/iommu/iommu.c
42959 +++ b/drivers/iommu/iommu.c
42960 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42961 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42962 {
42963 bus_register_notifier(bus, &iommu_bus_nb);
42964 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42965 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42966 }
42967
42968 /**
42969 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42970 index 39f81ae..2660096 100644
42971 --- a/drivers/iommu/irq_remapping.c
42972 +++ b/drivers/iommu/irq_remapping.c
42973 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42974 void panic_if_irq_remap(const char *msg)
42975 {
42976 if (irq_remapping_enabled)
42977 - panic(msg);
42978 + panic("%s", msg);
42979 }
42980
42981 static void ir_ack_apic_edge(struct irq_data *data)
42982 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42983
42984 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42985 {
42986 - chip->irq_print_chip = ir_print_prefix;
42987 - chip->irq_ack = ir_ack_apic_edge;
42988 - chip->irq_eoi = ir_ack_apic_level;
42989 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42990 + pax_open_kernel();
42991 + *(void **)&chip->irq_print_chip = ir_print_prefix;
42992 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
42993 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
42994 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42995 + pax_close_kernel();
42996 }
42997
42998 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42999 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43000 index 341c601..e5f407e 100644
43001 --- a/drivers/irqchip/irq-gic.c
43002 +++ b/drivers/irqchip/irq-gic.c
43003 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43004 * Supported arch specific GIC irq extension.
43005 * Default make them NULL.
43006 */
43007 -struct irq_chip gic_arch_extn = {
43008 +irq_chip_no_const gic_arch_extn = {
43009 .irq_eoi = NULL,
43010 .irq_mask = NULL,
43011 .irq_unmask = NULL,
43012 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43013 chained_irq_exit(chip, desc);
43014 }
43015
43016 -static struct irq_chip gic_chip = {
43017 +static irq_chip_no_const gic_chip __read_only = {
43018 .name = "GIC",
43019 .irq_mask = gic_mask_irq,
43020 .irq_unmask = gic_unmask_irq,
43021 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43022 index ac6f72b..81150f2 100644
43023 --- a/drivers/isdn/capi/capi.c
43024 +++ b/drivers/isdn/capi/capi.c
43025 @@ -81,8 +81,8 @@ struct capiminor {
43026
43027 struct capi20_appl *ap;
43028 u32 ncci;
43029 - atomic_t datahandle;
43030 - atomic_t msgid;
43031 + atomic_unchecked_t datahandle;
43032 + atomic_unchecked_t msgid;
43033
43034 struct tty_port port;
43035 int ttyinstop;
43036 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43037 capimsg_setu16(s, 2, mp->ap->applid);
43038 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43039 capimsg_setu8 (s, 5, CAPI_RESP);
43040 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43041 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43042 capimsg_setu32(s, 8, mp->ncci);
43043 capimsg_setu16(s, 12, datahandle);
43044 }
43045 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43046 mp->outbytes -= len;
43047 spin_unlock_bh(&mp->outlock);
43048
43049 - datahandle = atomic_inc_return(&mp->datahandle);
43050 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43051 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43052 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43053 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43054 capimsg_setu16(skb->data, 2, mp->ap->applid);
43055 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43056 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43057 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43058 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43059 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43060 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43061 capimsg_setu16(skb->data, 16, len); /* Data length */
43062 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43063 index c44950d..10ac276 100644
43064 --- a/drivers/isdn/gigaset/bas-gigaset.c
43065 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43066 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43067
43068
43069 static const struct gigaset_ops gigops = {
43070 - gigaset_write_cmd,
43071 - gigaset_write_room,
43072 - gigaset_chars_in_buffer,
43073 - gigaset_brkchars,
43074 - gigaset_init_bchannel,
43075 - gigaset_close_bchannel,
43076 - gigaset_initbcshw,
43077 - gigaset_freebcshw,
43078 - gigaset_reinitbcshw,
43079 - gigaset_initcshw,
43080 - gigaset_freecshw,
43081 - gigaset_set_modem_ctrl,
43082 - gigaset_baud_rate,
43083 - gigaset_set_line_ctrl,
43084 - gigaset_isoc_send_skb,
43085 - gigaset_isoc_input,
43086 + .write_cmd = gigaset_write_cmd,
43087 + .write_room = gigaset_write_room,
43088 + .chars_in_buffer = gigaset_chars_in_buffer,
43089 + .brkchars = gigaset_brkchars,
43090 + .init_bchannel = gigaset_init_bchannel,
43091 + .close_bchannel = gigaset_close_bchannel,
43092 + .initbcshw = gigaset_initbcshw,
43093 + .freebcshw = gigaset_freebcshw,
43094 + .reinitbcshw = gigaset_reinitbcshw,
43095 + .initcshw = gigaset_initcshw,
43096 + .freecshw = gigaset_freecshw,
43097 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43098 + .baud_rate = gigaset_baud_rate,
43099 + .set_line_ctrl = gigaset_set_line_ctrl,
43100 + .send_skb = gigaset_isoc_send_skb,
43101 + .handle_input = gigaset_isoc_input,
43102 };
43103
43104 /* bas_gigaset_init
43105 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43106 index 600c79b..3752bab 100644
43107 --- a/drivers/isdn/gigaset/interface.c
43108 +++ b/drivers/isdn/gigaset/interface.c
43109 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43110 }
43111 tty->driver_data = cs;
43112
43113 - ++cs->port.count;
43114 + atomic_inc(&cs->port.count);
43115
43116 - if (cs->port.count == 1) {
43117 + if (atomic_read(&cs->port.count) == 1) {
43118 tty_port_tty_set(&cs->port, tty);
43119 cs->port.low_latency = 1;
43120 }
43121 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43122
43123 if (!cs->connected)
43124 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43125 - else if (!cs->port.count)
43126 + else if (!atomic_read(&cs->port.count))
43127 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43128 - else if (!--cs->port.count)
43129 + else if (!atomic_dec_return(&cs->port.count))
43130 tty_port_tty_set(&cs->port, NULL);
43131
43132 mutex_unlock(&cs->mutex);
43133 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43134 index 8c91fd5..14f13ce 100644
43135 --- a/drivers/isdn/gigaset/ser-gigaset.c
43136 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43137 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43138 }
43139
43140 static const struct gigaset_ops ops = {
43141 - gigaset_write_cmd,
43142 - gigaset_write_room,
43143 - gigaset_chars_in_buffer,
43144 - gigaset_brkchars,
43145 - gigaset_init_bchannel,
43146 - gigaset_close_bchannel,
43147 - gigaset_initbcshw,
43148 - gigaset_freebcshw,
43149 - gigaset_reinitbcshw,
43150 - gigaset_initcshw,
43151 - gigaset_freecshw,
43152 - gigaset_set_modem_ctrl,
43153 - gigaset_baud_rate,
43154 - gigaset_set_line_ctrl,
43155 - gigaset_m10x_send_skb, /* asyncdata.c */
43156 - gigaset_m10x_input, /* asyncdata.c */
43157 + .write_cmd = gigaset_write_cmd,
43158 + .write_room = gigaset_write_room,
43159 + .chars_in_buffer = gigaset_chars_in_buffer,
43160 + .brkchars = gigaset_brkchars,
43161 + .init_bchannel = gigaset_init_bchannel,
43162 + .close_bchannel = gigaset_close_bchannel,
43163 + .initbcshw = gigaset_initbcshw,
43164 + .freebcshw = gigaset_freebcshw,
43165 + .reinitbcshw = gigaset_reinitbcshw,
43166 + .initcshw = gigaset_initcshw,
43167 + .freecshw = gigaset_freecshw,
43168 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43169 + .baud_rate = gigaset_baud_rate,
43170 + .set_line_ctrl = gigaset_set_line_ctrl,
43171 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43172 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43173 };
43174
43175
43176 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43177 index d0a41cb..b953e50 100644
43178 --- a/drivers/isdn/gigaset/usb-gigaset.c
43179 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43180 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43181 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43182 memcpy(cs->hw.usb->bchars, buf, 6);
43183 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43184 - 0, 0, &buf, 6, 2000);
43185 + 0, 0, buf, 6, 2000);
43186 }
43187
43188 static void gigaset_freebcshw(struct bc_state *bcs)
43189 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43190 }
43191
43192 static const struct gigaset_ops ops = {
43193 - gigaset_write_cmd,
43194 - gigaset_write_room,
43195 - gigaset_chars_in_buffer,
43196 - gigaset_brkchars,
43197 - gigaset_init_bchannel,
43198 - gigaset_close_bchannel,
43199 - gigaset_initbcshw,
43200 - gigaset_freebcshw,
43201 - gigaset_reinitbcshw,
43202 - gigaset_initcshw,
43203 - gigaset_freecshw,
43204 - gigaset_set_modem_ctrl,
43205 - gigaset_baud_rate,
43206 - gigaset_set_line_ctrl,
43207 - gigaset_m10x_send_skb,
43208 - gigaset_m10x_input,
43209 + .write_cmd = gigaset_write_cmd,
43210 + .write_room = gigaset_write_room,
43211 + .chars_in_buffer = gigaset_chars_in_buffer,
43212 + .brkchars = gigaset_brkchars,
43213 + .init_bchannel = gigaset_init_bchannel,
43214 + .close_bchannel = gigaset_close_bchannel,
43215 + .initbcshw = gigaset_initbcshw,
43216 + .freebcshw = gigaset_freebcshw,
43217 + .reinitbcshw = gigaset_reinitbcshw,
43218 + .initcshw = gigaset_initcshw,
43219 + .freecshw = gigaset_freecshw,
43220 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43221 + .baud_rate = gigaset_baud_rate,
43222 + .set_line_ctrl = gigaset_set_line_ctrl,
43223 + .send_skb = gigaset_m10x_send_skb,
43224 + .handle_input = gigaset_m10x_input,
43225 };
43226
43227 /*
43228 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43229 index 4d9b195..455075c 100644
43230 --- a/drivers/isdn/hardware/avm/b1.c
43231 +++ b/drivers/isdn/hardware/avm/b1.c
43232 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43233 }
43234 if (left) {
43235 if (t4file->user) {
43236 - if (copy_from_user(buf, dp, left))
43237 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43238 return -EFAULT;
43239 } else {
43240 memcpy(buf, dp, left);
43241 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43242 }
43243 if (left) {
43244 if (config->user) {
43245 - if (copy_from_user(buf, dp, left))
43246 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43247 return -EFAULT;
43248 } else {
43249 memcpy(buf, dp, left);
43250 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43251 index 9bb12ba..d4262f7 100644
43252 --- a/drivers/isdn/i4l/isdn_common.c
43253 +++ b/drivers/isdn/i4l/isdn_common.c
43254 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43255 } else
43256 return -EINVAL;
43257 case IIOCDBGVAR:
43258 + if (!capable(CAP_SYS_RAWIO))
43259 + return -EPERM;
43260 if (arg) {
43261 if (copy_to_user(argp, &dev, sizeof(ulong)))
43262 return -EFAULT;
43263 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43264 index 91d5730..336523e 100644
43265 --- a/drivers/isdn/i4l/isdn_concap.c
43266 +++ b/drivers/isdn/i4l/isdn_concap.c
43267 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43268 }
43269
43270 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43271 - &isdn_concap_dl_data_req,
43272 - &isdn_concap_dl_connect_req,
43273 - &isdn_concap_dl_disconn_req
43274 + .data_req = &isdn_concap_dl_data_req,
43275 + .connect_req = &isdn_concap_dl_connect_req,
43276 + .disconn_req = &isdn_concap_dl_disconn_req
43277 };
43278
43279 /* The following should better go into a dedicated source file such that
43280 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43281 index 3c5f249..5fac4d0 100644
43282 --- a/drivers/isdn/i4l/isdn_tty.c
43283 +++ b/drivers/isdn/i4l/isdn_tty.c
43284 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43285
43286 #ifdef ISDN_DEBUG_MODEM_OPEN
43287 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43288 - port->count);
43289 + atomic_read(&port->count));
43290 #endif
43291 - port->count++;
43292 + atomic_inc(&port->count);
43293 port->tty = tty;
43294 /*
43295 * Start up serial port
43296 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43297 #endif
43298 return;
43299 }
43300 - if ((tty->count == 1) && (port->count != 1)) {
43301 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43302 /*
43303 * Uh, oh. tty->count is 1, which means that the tty
43304 * structure will be freed. Info->count should always
43305 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43306 * serial port won't be shutdown.
43307 */
43308 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43309 - "info->count is %d\n", port->count);
43310 - port->count = 1;
43311 + "info->count is %d\n", atomic_read(&port->count));
43312 + atomic_set(&port->count, 1);
43313 }
43314 - if (--port->count < 0) {
43315 + if (atomic_dec_return(&port->count) < 0) {
43316 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43317 - info->line, port->count);
43318 - port->count = 0;
43319 + info->line, atomic_read(&port->count));
43320 + atomic_set(&port->count, 0);
43321 }
43322 - if (port->count) {
43323 + if (atomic_read(&port->count)) {
43324 #ifdef ISDN_DEBUG_MODEM_OPEN
43325 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43326 #endif
43327 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43328 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43329 return;
43330 isdn_tty_shutdown(info);
43331 - port->count = 0;
43332 + atomic_set(&port->count, 0);
43333 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43334 port->tty = NULL;
43335 wake_up_interruptible(&port->open_wait);
43336 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43337 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43338 modem_info *info = &dev->mdm.info[i];
43339
43340 - if (info->port.count == 0)
43341 + if (atomic_read(&info->port.count) == 0)
43342 continue;
43343 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43344 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43345 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43346 index e2d4e58..40cd045 100644
43347 --- a/drivers/isdn/i4l/isdn_x25iface.c
43348 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43349 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43350
43351
43352 static struct concap_proto_ops ix25_pops = {
43353 - &isdn_x25iface_proto_new,
43354 - &isdn_x25iface_proto_del,
43355 - &isdn_x25iface_proto_restart,
43356 - &isdn_x25iface_proto_close,
43357 - &isdn_x25iface_xmit,
43358 - &isdn_x25iface_receive,
43359 - &isdn_x25iface_connect_ind,
43360 - &isdn_x25iface_disconn_ind
43361 + .proto_new = &isdn_x25iface_proto_new,
43362 + .proto_del = &isdn_x25iface_proto_del,
43363 + .restart = &isdn_x25iface_proto_restart,
43364 + .close = &isdn_x25iface_proto_close,
43365 + .encap_and_xmit = &isdn_x25iface_xmit,
43366 + .data_ind = &isdn_x25iface_receive,
43367 + .connect_ind = &isdn_x25iface_connect_ind,
43368 + .disconn_ind = &isdn_x25iface_disconn_ind
43369 };
43370
43371 /* error message helper function */
43372 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43373 index 53d487f..f020f41 100644
43374 --- a/drivers/isdn/icn/icn.c
43375 +++ b/drivers/isdn/icn/icn.c
43376 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43377 if (count > len)
43378 count = len;
43379 if (user) {
43380 - if (copy_from_user(msg, buf, count))
43381 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43382 return -EFAULT;
43383 } else
43384 memcpy(msg, buf, count);
43385 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43386 index a4f05c5..1433bc5 100644
43387 --- a/drivers/isdn/mISDN/dsp_cmx.c
43388 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43389 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43390 static u16 dsp_count; /* last sample count */
43391 static int dsp_count_valid; /* if we have last sample count */
43392
43393 -void
43394 +void __intentional_overflow(-1)
43395 dsp_cmx_send(void *arg)
43396 {
43397 struct dsp_conf *conf;
43398 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43399 index d93e245..e7ece6b 100644
43400 --- a/drivers/leds/leds-clevo-mail.c
43401 +++ b/drivers/leds/leds-clevo-mail.c
43402 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43403 * detected as working, but in reality it is not) as low as
43404 * possible.
43405 */
43406 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43407 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43408 {
43409 .callback = clevo_mail_led_dmi_callback,
43410 .ident = "Clevo D410J",
43411 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43412 index 5b8f938..b73d657 100644
43413 --- a/drivers/leds/leds-ss4200.c
43414 +++ b/drivers/leds/leds-ss4200.c
43415 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43416 * detected as working, but in reality it is not) as low as
43417 * possible.
43418 */
43419 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43420 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43421 {
43422 .callback = ss4200_led_dmi_callback,
43423 .ident = "Intel SS4200-E",
43424 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43425 index 0bf1e4e..b4bf44e 100644
43426 --- a/drivers/lguest/core.c
43427 +++ b/drivers/lguest/core.c
43428 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43429 * The end address needs +1 because __get_vm_area allocates an
43430 * extra guard page, so we need space for that.
43431 */
43432 +
43433 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43434 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43435 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43436 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43437 +#else
43438 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43439 VM_ALLOC, switcher_addr, switcher_addr
43440 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43441 +#endif
43442 +
43443 if (!switcher_vma) {
43444 err = -ENOMEM;
43445 printk("lguest: could not map switcher pages high\n");
43446 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43447 * Now the Switcher is mapped at the right address, we can't fail!
43448 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43449 */
43450 - memcpy(switcher_vma->addr, start_switcher_text,
43451 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43452 end_switcher_text - start_switcher_text);
43453
43454 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43455 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43456 index bfb39bb..08a603b 100644
43457 --- a/drivers/lguest/page_tables.c
43458 +++ b/drivers/lguest/page_tables.c
43459 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43460 /*:*/
43461
43462 #ifdef CONFIG_X86_PAE
43463 -static void release_pmd(pmd_t *spmd)
43464 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43465 {
43466 /* If the entry's not present, there's nothing to release. */
43467 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43468 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43469 index 922a1ac..9dd0c2a 100644
43470 --- a/drivers/lguest/x86/core.c
43471 +++ b/drivers/lguest/x86/core.c
43472 @@ -59,7 +59,7 @@ static struct {
43473 /* Offset from where switcher.S was compiled to where we've copied it */
43474 static unsigned long switcher_offset(void)
43475 {
43476 - return switcher_addr - (unsigned long)start_switcher_text;
43477 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43478 }
43479
43480 /* This cpu's struct lguest_pages (after the Switcher text page) */
43481 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43482 * These copies are pretty cheap, so we do them unconditionally: */
43483 /* Save the current Host top-level page directory.
43484 */
43485 +
43486 +#ifdef CONFIG_PAX_PER_CPU_PGD
43487 + pages->state.host_cr3 = read_cr3();
43488 +#else
43489 pages->state.host_cr3 = __pa(current->mm->pgd);
43490 +#endif
43491 +
43492 /*
43493 * Set up the Guest's page tables to see this CPU's pages (and no
43494 * other CPU's pages).
43495 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43496 * compiled-in switcher code and the high-mapped copy we just made.
43497 */
43498 for (i = 0; i < IDT_ENTRIES; i++)
43499 - default_idt_entries[i] += switcher_offset();
43500 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43501
43502 /*
43503 * Set up the Switcher's per-cpu areas.
43504 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43505 * it will be undisturbed when we switch. To change %cs and jump we
43506 * need this structure to feed to Intel's "lcall" instruction.
43507 */
43508 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43509 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43510 lguest_entry.segment = LGUEST_CS;
43511
43512 /*
43513 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43514 index 40634b0..4f5855e 100644
43515 --- a/drivers/lguest/x86/switcher_32.S
43516 +++ b/drivers/lguest/x86/switcher_32.S
43517 @@ -87,6 +87,7 @@
43518 #include <asm/page.h>
43519 #include <asm/segment.h>
43520 #include <asm/lguest.h>
43521 +#include <asm/processor-flags.h>
43522
43523 // We mark the start of the code to copy
43524 // It's placed in .text tho it's never run here
43525 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43526 // Changes type when we load it: damn Intel!
43527 // For after we switch over our page tables
43528 // That entry will be read-only: we'd crash.
43529 +
43530 +#ifdef CONFIG_PAX_KERNEXEC
43531 + mov %cr0, %edx
43532 + xor $X86_CR0_WP, %edx
43533 + mov %edx, %cr0
43534 +#endif
43535 +
43536 movl $(GDT_ENTRY_TSS*8), %edx
43537 ltr %dx
43538
43539 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43540 // Let's clear it again for our return.
43541 // The GDT descriptor of the Host
43542 // Points to the table after two "size" bytes
43543 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43544 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43545 // Clear "used" from type field (byte 5, bit 2)
43546 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43547 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43548 +
43549 +#ifdef CONFIG_PAX_KERNEXEC
43550 + mov %cr0, %eax
43551 + xor $X86_CR0_WP, %eax
43552 + mov %eax, %cr0
43553 +#endif
43554
43555 // Once our page table's switched, the Guest is live!
43556 // The Host fades as we run this final step.
43557 @@ -295,13 +309,12 @@ deliver_to_host:
43558 // I consulted gcc, and it gave
43559 // These instructions, which I gladly credit:
43560 leal (%edx,%ebx,8), %eax
43561 - movzwl (%eax),%edx
43562 - movl 4(%eax), %eax
43563 - xorw %ax, %ax
43564 - orl %eax, %edx
43565 + movl 4(%eax), %edx
43566 + movw (%eax), %dx
43567 // Now the address of the handler's in %edx
43568 // We call it now: its "iret" drops us home.
43569 - jmp *%edx
43570 + ljmp $__KERNEL_CS, $1f
43571 +1: jmp *%edx
43572
43573 // Every interrupt can come to us here
43574 // But we must truly tell each apart.
43575 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43576 index 9762f1b..3e79734 100644
43577 --- a/drivers/md/bcache/closure.h
43578 +++ b/drivers/md/bcache/closure.h
43579 @@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
43580 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43581 struct workqueue_struct *wq)
43582 {
43583 - BUG_ON(object_is_on_stack(cl));
43584 + BUG_ON(object_starts_on_stack(cl));
43585 closure_set_ip(cl);
43586 cl->fn = fn;
43587 cl->wq = wq;
43588 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43589 index 12dc29b..1596277 100644
43590 --- a/drivers/md/bitmap.c
43591 +++ b/drivers/md/bitmap.c
43592 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43593 chunk_kb ? "KB" : "B");
43594 if (bitmap->storage.file) {
43595 seq_printf(seq, ", file: ");
43596 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43597 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43598 }
43599
43600 seq_printf(seq, "\n");
43601 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43602 index 5152142..623d141 100644
43603 --- a/drivers/md/dm-ioctl.c
43604 +++ b/drivers/md/dm-ioctl.c
43605 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43606 cmd == DM_LIST_VERSIONS_CMD)
43607 return 0;
43608
43609 - if ((cmd == DM_DEV_CREATE_CMD)) {
43610 + if (cmd == DM_DEV_CREATE_CMD) {
43611 if (!*param->name) {
43612 DMWARN("name not supplied when creating device");
43613 return -EINVAL;
43614 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43615 index 9584443..9fc9ac9 100644
43616 --- a/drivers/md/dm-raid1.c
43617 +++ b/drivers/md/dm-raid1.c
43618 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43619
43620 struct mirror {
43621 struct mirror_set *ms;
43622 - atomic_t error_count;
43623 + atomic_unchecked_t error_count;
43624 unsigned long error_type;
43625 struct dm_dev *dev;
43626 sector_t offset;
43627 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43628 struct mirror *m;
43629
43630 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43631 - if (!atomic_read(&m->error_count))
43632 + if (!atomic_read_unchecked(&m->error_count))
43633 return m;
43634
43635 return NULL;
43636 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43637 * simple way to tell if a device has encountered
43638 * errors.
43639 */
43640 - atomic_inc(&m->error_count);
43641 + atomic_inc_unchecked(&m->error_count);
43642
43643 if (test_and_set_bit(error_type, &m->error_type))
43644 return;
43645 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43646 struct mirror *m = get_default_mirror(ms);
43647
43648 do {
43649 - if (likely(!atomic_read(&m->error_count)))
43650 + if (likely(!atomic_read_unchecked(&m->error_count)))
43651 return m;
43652
43653 if (m-- == ms->mirror)
43654 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43655 {
43656 struct mirror *default_mirror = get_default_mirror(m->ms);
43657
43658 - return !atomic_read(&default_mirror->error_count);
43659 + return !atomic_read_unchecked(&default_mirror->error_count);
43660 }
43661
43662 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43663 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43664 */
43665 if (likely(region_in_sync(ms, region, 1)))
43666 m = choose_mirror(ms, bio->bi_sector);
43667 - else if (m && atomic_read(&m->error_count))
43668 + else if (m && atomic_read_unchecked(&m->error_count))
43669 m = NULL;
43670
43671 if (likely(m))
43672 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43673 }
43674
43675 ms->mirror[mirror].ms = ms;
43676 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43677 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43678 ms->mirror[mirror].error_type = 0;
43679 ms->mirror[mirror].offset = offset;
43680
43681 @@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43682 */
43683 static char device_status_char(struct mirror *m)
43684 {
43685 - if (!atomic_read(&(m->error_count)))
43686 + if (!atomic_read_unchecked(&(m->error_count)))
43687 return 'A';
43688
43689 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43690 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43691 index 28a9012..9c0f6a5 100644
43692 --- a/drivers/md/dm-stats.c
43693 +++ b/drivers/md/dm-stats.c
43694 @@ -382,7 +382,7 @@ do_sync_free:
43695 synchronize_rcu_expedited();
43696 dm_stat_free(&s->rcu_head);
43697 } else {
43698 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43699 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43700 call_rcu(&s->rcu_head, dm_stat_free);
43701 }
43702 return 0;
43703 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43704 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43705 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43706 ));
43707 - ACCESS_ONCE(last->last_sector) = end_sector;
43708 - ACCESS_ONCE(last->last_rw) = bi_rw;
43709 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43710 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43711 }
43712
43713 rcu_read_lock();
43714 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43715 index 73c1712..7347292 100644
43716 --- a/drivers/md/dm-stripe.c
43717 +++ b/drivers/md/dm-stripe.c
43718 @@ -21,7 +21,7 @@ struct stripe {
43719 struct dm_dev *dev;
43720 sector_t physical_start;
43721
43722 - atomic_t error_count;
43723 + atomic_unchecked_t error_count;
43724 };
43725
43726 struct stripe_c {
43727 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43728 kfree(sc);
43729 return r;
43730 }
43731 - atomic_set(&(sc->stripe[i].error_count), 0);
43732 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43733 }
43734
43735 ti->private = sc;
43736 @@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43737 DMEMIT("%d ", sc->stripes);
43738 for (i = 0; i < sc->stripes; i++) {
43739 DMEMIT("%s ", sc->stripe[i].dev->name);
43740 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43741 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43742 'D' : 'A';
43743 }
43744 buffer[i] = '\0';
43745 @@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43746 */
43747 for (i = 0; i < sc->stripes; i++)
43748 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43749 - atomic_inc(&(sc->stripe[i].error_count));
43750 - if (atomic_read(&(sc->stripe[i].error_count)) <
43751 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43752 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43753 DM_IO_ERROR_THRESHOLD)
43754 schedule_work(&sc->trigger_event);
43755 }
43756 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43757 index 3ba6a38..b0fa9b0 100644
43758 --- a/drivers/md/dm-table.c
43759 +++ b/drivers/md/dm-table.c
43760 @@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43761 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43762 struct mapped_device *md)
43763 {
43764 - static char *_claim_ptr = "I belong to device-mapper";
43765 + static char _claim_ptr[] = "I belong to device-mapper";
43766 struct block_device *bdev;
43767
43768 int r;
43769 @@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43770 if (!dev_size)
43771 return 0;
43772
43773 - if ((start >= dev_size) || (start + len > dev_size)) {
43774 + if ((start >= dev_size) || (len > dev_size - start)) {
43775 DMWARN("%s: %s too small for target: "
43776 "start=%llu, len=%llu, dev_size=%llu",
43777 dm_device_name(ti->table->md), bdevname(bdev, b),
43778 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43779 index 3bb4506..56e20cc 100644
43780 --- a/drivers/md/dm-thin-metadata.c
43781 +++ b/drivers/md/dm-thin-metadata.c
43782 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43783 {
43784 pmd->info.tm = pmd->tm;
43785 pmd->info.levels = 2;
43786 - pmd->info.value_type.context = pmd->data_sm;
43787 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43788 pmd->info.value_type.size = sizeof(__le64);
43789 pmd->info.value_type.inc = data_block_inc;
43790 pmd->info.value_type.dec = data_block_dec;
43791 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43792
43793 pmd->bl_info.tm = pmd->tm;
43794 pmd->bl_info.levels = 1;
43795 - pmd->bl_info.value_type.context = pmd->data_sm;
43796 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43797 pmd->bl_info.value_type.size = sizeof(__le64);
43798 pmd->bl_info.value_type.inc = data_block_inc;
43799 pmd->bl_info.value_type.dec = data_block_dec;
43800 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43801 index b49c762..c9503cf 100644
43802 --- a/drivers/md/dm.c
43803 +++ b/drivers/md/dm.c
43804 @@ -185,9 +185,9 @@ struct mapped_device {
43805 /*
43806 * Event handling.
43807 */
43808 - atomic_t event_nr;
43809 + atomic_unchecked_t event_nr;
43810 wait_queue_head_t eventq;
43811 - atomic_t uevent_seq;
43812 + atomic_unchecked_t uevent_seq;
43813 struct list_head uevent_list;
43814 spinlock_t uevent_lock; /* Protect access to uevent_list */
43815
43816 @@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43817 spin_lock_init(&md->deferred_lock);
43818 atomic_set(&md->holders, 1);
43819 atomic_set(&md->open_count, 0);
43820 - atomic_set(&md->event_nr, 0);
43821 - atomic_set(&md->uevent_seq, 0);
43822 + atomic_set_unchecked(&md->event_nr, 0);
43823 + atomic_set_unchecked(&md->uevent_seq, 0);
43824 INIT_LIST_HEAD(&md->uevent_list);
43825 spin_lock_init(&md->uevent_lock);
43826
43827 @@ -2176,7 +2176,7 @@ static void event_callback(void *context)
43828
43829 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43830
43831 - atomic_inc(&md->event_nr);
43832 + atomic_inc_unchecked(&md->event_nr);
43833 wake_up(&md->eventq);
43834 }
43835
43836 @@ -2869,18 +2869,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43837
43838 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43839 {
43840 - return atomic_add_return(1, &md->uevent_seq);
43841 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43842 }
43843
43844 uint32_t dm_get_event_nr(struct mapped_device *md)
43845 {
43846 - return atomic_read(&md->event_nr);
43847 + return atomic_read_unchecked(&md->event_nr);
43848 }
43849
43850 int dm_wait_event(struct mapped_device *md, int event_nr)
43851 {
43852 return wait_event_interruptible(md->eventq,
43853 - (event_nr != atomic_read(&md->event_nr)));
43854 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43855 }
43856
43857 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43858 diff --git a/drivers/md/md.c b/drivers/md/md.c
43859 index 369d919..ba7049c 100644
43860 --- a/drivers/md/md.c
43861 +++ b/drivers/md/md.c
43862 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43863 * start build, activate spare
43864 */
43865 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43866 -static atomic_t md_event_count;
43867 +static atomic_unchecked_t md_event_count;
43868 void md_new_event(struct mddev *mddev)
43869 {
43870 - atomic_inc(&md_event_count);
43871 + atomic_inc_unchecked(&md_event_count);
43872 wake_up(&md_event_waiters);
43873 }
43874 EXPORT_SYMBOL_GPL(md_new_event);
43875 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43876 */
43877 static void md_new_event_inintr(struct mddev *mddev)
43878 {
43879 - atomic_inc(&md_event_count);
43880 + atomic_inc_unchecked(&md_event_count);
43881 wake_up(&md_event_waiters);
43882 }
43883
43884 @@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43885 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43886 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43887 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43888 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43889 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43890
43891 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43892 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43893 @@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43894 else
43895 sb->resync_offset = cpu_to_le64(0);
43896
43897 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43898 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43899
43900 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43901 sb->size = cpu_to_le64(mddev->dev_sectors);
43902 @@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43903 static ssize_t
43904 errors_show(struct md_rdev *rdev, char *page)
43905 {
43906 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43907 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43908 }
43909
43910 static ssize_t
43911 @@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43912 char *e;
43913 unsigned long n = simple_strtoul(buf, &e, 10);
43914 if (*buf && (*e == 0 || *e == '\n')) {
43915 - atomic_set(&rdev->corrected_errors, n);
43916 + atomic_set_unchecked(&rdev->corrected_errors, n);
43917 return len;
43918 }
43919 return -EINVAL;
43920 @@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43921 rdev->sb_loaded = 0;
43922 rdev->bb_page = NULL;
43923 atomic_set(&rdev->nr_pending, 0);
43924 - atomic_set(&rdev->read_errors, 0);
43925 - atomic_set(&rdev->corrected_errors, 0);
43926 + atomic_set_unchecked(&rdev->read_errors, 0);
43927 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43928
43929 INIT_LIST_HEAD(&rdev->same_set);
43930 init_waitqueue_head(&rdev->blocked_wait);
43931 @@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43932
43933 spin_unlock(&pers_lock);
43934 seq_printf(seq, "\n");
43935 - seq->poll_event = atomic_read(&md_event_count);
43936 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43937 return 0;
43938 }
43939 if (v == (void*)2) {
43940 @@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43941 return error;
43942
43943 seq = file->private_data;
43944 - seq->poll_event = atomic_read(&md_event_count);
43945 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43946 return error;
43947 }
43948
43949 @@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43950 /* always allow read */
43951 mask = POLLIN | POLLRDNORM;
43952
43953 - if (seq->poll_event != atomic_read(&md_event_count))
43954 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43955 mask |= POLLERR | POLLPRI;
43956 return mask;
43957 }
43958 @@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43959 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43960 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43961 (int)part_stat_read(&disk->part0, sectors[1]) -
43962 - atomic_read(&disk->sync_io);
43963 + atomic_read_unchecked(&disk->sync_io);
43964 /* sync IO will cause sync_io to increase before the disk_stats
43965 * as sync_io is counted when a request starts, and
43966 * disk_stats is counted when it completes.
43967 diff --git a/drivers/md/md.h b/drivers/md/md.h
43968 index 0095ec8..c89277a 100644
43969 --- a/drivers/md/md.h
43970 +++ b/drivers/md/md.h
43971 @@ -94,13 +94,13 @@ struct md_rdev {
43972 * only maintained for arrays that
43973 * support hot removal
43974 */
43975 - atomic_t read_errors; /* number of consecutive read errors that
43976 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
43977 * we have tried to ignore.
43978 */
43979 struct timespec last_read_error; /* monotonic time since our
43980 * last read error
43981 */
43982 - atomic_t corrected_errors; /* number of corrected read errors,
43983 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43984 * for reporting to userspace and storing
43985 * in superblock.
43986 */
43987 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43988
43989 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43990 {
43991 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43992 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43993 }
43994
43995 struct md_personality
43996 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
43997 index 3e6d115..ffecdeb 100644
43998 --- a/drivers/md/persistent-data/dm-space-map.h
43999 +++ b/drivers/md/persistent-data/dm-space-map.h
44000 @@ -71,6 +71,7 @@ struct dm_space_map {
44001 dm_sm_threshold_fn fn,
44002 void *context);
44003 };
44004 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44005
44006 /*----------------------------------------------------------------*/
44007
44008 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44009 index 63b2e8d..225f16b 100644
44010 --- a/drivers/md/raid1.c
44011 +++ b/drivers/md/raid1.c
44012 @@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44013 if (r1_sync_page_io(rdev, sect, s,
44014 bio->bi_io_vec[idx].bv_page,
44015 READ) != 0)
44016 - atomic_add(s, &rdev->corrected_errors);
44017 + atomic_add_unchecked(s, &rdev->corrected_errors);
44018 }
44019 sectors -= s;
44020 sect += s;
44021 @@ -2155,7 +2155,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44022 test_bit(In_sync, &rdev->flags)) {
44023 if (r1_sync_page_io(rdev, sect, s,
44024 conf->tmppage, READ)) {
44025 - atomic_add(s, &rdev->corrected_errors);
44026 + atomic_add_unchecked(s, &rdev->corrected_errors);
44027 printk(KERN_INFO
44028 "md/raid1:%s: read error corrected "
44029 "(%d sectors at %llu on %s)\n",
44030 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44031 index 06eeb99..770613e 100644
44032 --- a/drivers/md/raid10.c
44033 +++ b/drivers/md/raid10.c
44034 @@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
44035 /* The write handler will notice the lack of
44036 * R10BIO_Uptodate and record any errors etc
44037 */
44038 - atomic_add(r10_bio->sectors,
44039 + atomic_add_unchecked(r10_bio->sectors,
44040 &conf->mirrors[d].rdev->corrected_errors);
44041
44042 /* for reconstruct, we always reschedule after a read.
44043 @@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44044 {
44045 struct timespec cur_time_mon;
44046 unsigned long hours_since_last;
44047 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44048 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44049
44050 ktime_get_ts(&cur_time_mon);
44051
44052 @@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44053 * overflowing the shift of read_errors by hours_since_last.
44054 */
44055 if (hours_since_last >= 8 * sizeof(read_errors))
44056 - atomic_set(&rdev->read_errors, 0);
44057 + atomic_set_unchecked(&rdev->read_errors, 0);
44058 else
44059 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44060 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44061 }
44062
44063 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44064 @@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44065 return;
44066
44067 check_decay_read_errors(mddev, rdev);
44068 - atomic_inc(&rdev->read_errors);
44069 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44070 + atomic_inc_unchecked(&rdev->read_errors);
44071 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44072 char b[BDEVNAME_SIZE];
44073 bdevname(rdev->bdev, b);
44074
44075 @@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44076 "md/raid10:%s: %s: Raid device exceeded "
44077 "read_error threshold [cur %d:max %d]\n",
44078 mdname(mddev), b,
44079 - atomic_read(&rdev->read_errors), max_read_errors);
44080 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44081 printk(KERN_NOTICE
44082 "md/raid10:%s: %s: Failing raid device\n",
44083 mdname(mddev), b);
44084 @@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44085 sect +
44086 choose_data_offset(r10_bio, rdev)),
44087 bdevname(rdev->bdev, b));
44088 - atomic_add(s, &rdev->corrected_errors);
44089 + atomic_add_unchecked(s, &rdev->corrected_errors);
44090 }
44091
44092 rdev_dec_pending(rdev, mddev);
44093 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44094 index 48cdec8..c7726b1 100644
44095 --- a/drivers/md/raid5.c
44096 +++ b/drivers/md/raid5.c
44097 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44098 mdname(conf->mddev), STRIPE_SECTORS,
44099 (unsigned long long)s,
44100 bdevname(rdev->bdev, b));
44101 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44102 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44103 clear_bit(R5_ReadError, &sh->dev[i].flags);
44104 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44105 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44106 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44107
44108 - if (atomic_read(&rdev->read_errors))
44109 - atomic_set(&rdev->read_errors, 0);
44110 + if (atomic_read_unchecked(&rdev->read_errors))
44111 + atomic_set_unchecked(&rdev->read_errors, 0);
44112 } else {
44113 const char *bdn = bdevname(rdev->bdev, b);
44114 int retry = 0;
44115 int set_bad = 0;
44116
44117 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44118 - atomic_inc(&rdev->read_errors);
44119 + atomic_inc_unchecked(&rdev->read_errors);
44120 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44121 printk_ratelimited(
44122 KERN_WARNING
44123 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44124 mdname(conf->mddev),
44125 (unsigned long long)s,
44126 bdn);
44127 - } else if (atomic_read(&rdev->read_errors)
44128 + } else if (atomic_read_unchecked(&rdev->read_errors)
44129 > conf->max_nr_stripes)
44130 printk(KERN_WARNING
44131 "md/raid:%s: Too many read errors, failing device %s.\n",
44132 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44133 index 983db75..ef9248c 100644
44134 --- a/drivers/media/dvb-core/dvbdev.c
44135 +++ b/drivers/media/dvb-core/dvbdev.c
44136 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44137 const struct dvb_device *template, void *priv, int type)
44138 {
44139 struct dvb_device *dvbdev;
44140 - struct file_operations *dvbdevfops;
44141 + file_operations_no_const *dvbdevfops;
44142 struct device *clsdev;
44143 int minor;
44144 int id;
44145 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44146 index 9b6c3bb..baeb5c7 100644
44147 --- a/drivers/media/dvb-frontends/dib3000.h
44148 +++ b/drivers/media/dvb-frontends/dib3000.h
44149 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44150 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44151 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44152 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44153 -};
44154 +} __no_const;
44155
44156 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44157 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44158 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44159 index ed8cb90..5ef7f79 100644
44160 --- a/drivers/media/pci/cx88/cx88-video.c
44161 +++ b/drivers/media/pci/cx88/cx88-video.c
44162 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44163
44164 /* ------------------------------------------------------------------ */
44165
44166 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44167 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44168 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44169 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44170 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44171 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44172
44173 module_param_array(video_nr, int, NULL, 0444);
44174 module_param_array(vbi_nr, int, NULL, 0444);
44175 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44176 index 802642d..5534900 100644
44177 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44178 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44179 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44180 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44181
44182 /* ivtv instance counter */
44183 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44184 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44185
44186 /* Parameter declarations */
44187 static int cardtype[IVTV_MAX_CARDS];
44188 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44189 index dfd0a21..6bbb465 100644
44190 --- a/drivers/media/platform/omap/omap_vout.c
44191 +++ b/drivers/media/platform/omap/omap_vout.c
44192 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44193 OMAP_VIDEO2,
44194 };
44195
44196 -static struct videobuf_queue_ops video_vbq_ops;
44197 /* Variables configurable through module params*/
44198 static u32 video1_numbuffers = 3;
44199 static u32 video2_numbuffers = 3;
44200 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44201 {
44202 struct videobuf_queue *q;
44203 struct omap_vout_device *vout = NULL;
44204 + static struct videobuf_queue_ops video_vbq_ops = {
44205 + .buf_setup = omap_vout_buffer_setup,
44206 + .buf_prepare = omap_vout_buffer_prepare,
44207 + .buf_release = omap_vout_buffer_release,
44208 + .buf_queue = omap_vout_buffer_queue,
44209 + };
44210
44211 vout = video_drvdata(file);
44212 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44213 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44214 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44215
44216 q = &vout->vbq;
44217 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44218 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44219 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44220 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44221 spin_lock_init(&vout->vbq_lock);
44222
44223 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44224 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44225 index fb2acc5..a2fcbdc4 100644
44226 --- a/drivers/media/platform/s5p-tv/mixer.h
44227 +++ b/drivers/media/platform/s5p-tv/mixer.h
44228 @@ -156,7 +156,7 @@ struct mxr_layer {
44229 /** layer index (unique identifier) */
44230 int idx;
44231 /** callbacks for layer methods */
44232 - struct mxr_layer_ops ops;
44233 + struct mxr_layer_ops *ops;
44234 /** format array */
44235 const struct mxr_format **fmt_array;
44236 /** size of format array */
44237 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44238 index 74344c7..a39e70e 100644
44239 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44240 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44241 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44242 {
44243 struct mxr_layer *layer;
44244 int ret;
44245 - struct mxr_layer_ops ops = {
44246 + static struct mxr_layer_ops ops = {
44247 .release = mxr_graph_layer_release,
44248 .buffer_set = mxr_graph_buffer_set,
44249 .stream_set = mxr_graph_stream_set,
44250 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44251 index b713403..53cb5ad 100644
44252 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44253 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44254 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44255 layer->update_buf = next;
44256 }
44257
44258 - layer->ops.buffer_set(layer, layer->update_buf);
44259 + layer->ops->buffer_set(layer, layer->update_buf);
44260
44261 if (done && done != layer->shadow_buf)
44262 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44263 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44264 index 81b97db..b089ccd 100644
44265 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44266 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44267 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44268 layer->geo.src.height = layer->geo.src.full_height;
44269
44270 mxr_geometry_dump(mdev, &layer->geo);
44271 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44272 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44273 mxr_geometry_dump(mdev, &layer->geo);
44274 }
44275
44276 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44277 layer->geo.dst.full_width = mbus_fmt.width;
44278 layer->geo.dst.full_height = mbus_fmt.height;
44279 layer->geo.dst.field = mbus_fmt.field;
44280 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44281 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44282
44283 mxr_geometry_dump(mdev, &layer->geo);
44284 }
44285 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44286 /* set source size to highest accepted value */
44287 geo->src.full_width = max(geo->dst.full_width, pix->width);
44288 geo->src.full_height = max(geo->dst.full_height, pix->height);
44289 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44290 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44291 mxr_geometry_dump(mdev, &layer->geo);
44292 /* set cropping to total visible screen */
44293 geo->src.width = pix->width;
44294 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44295 geo->src.x_offset = 0;
44296 geo->src.y_offset = 0;
44297 /* assure consistency of geometry */
44298 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44299 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44300 mxr_geometry_dump(mdev, &layer->geo);
44301 /* set full size to lowest possible value */
44302 geo->src.full_width = 0;
44303 geo->src.full_height = 0;
44304 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44305 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44306 mxr_geometry_dump(mdev, &layer->geo);
44307
44308 /* returning results */
44309 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44310 target->width = s->r.width;
44311 target->height = s->r.height;
44312
44313 - layer->ops.fix_geometry(layer, stage, s->flags);
44314 + layer->ops->fix_geometry(layer, stage, s->flags);
44315
44316 /* retrieve update selection rectangle */
44317 res.left = target->x_offset;
44318 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44319 mxr_output_get(mdev);
44320
44321 mxr_layer_update_output(layer);
44322 - layer->ops.format_set(layer);
44323 + layer->ops->format_set(layer);
44324 /* enabling layer in hardware */
44325 spin_lock_irqsave(&layer->enq_slock, flags);
44326 layer->state = MXR_LAYER_STREAMING;
44327 spin_unlock_irqrestore(&layer->enq_slock, flags);
44328
44329 - layer->ops.stream_set(layer, MXR_ENABLE);
44330 + layer->ops->stream_set(layer, MXR_ENABLE);
44331 mxr_streamer_get(mdev);
44332
44333 return 0;
44334 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44335 spin_unlock_irqrestore(&layer->enq_slock, flags);
44336
44337 /* disabling layer in hardware */
44338 - layer->ops.stream_set(layer, MXR_DISABLE);
44339 + layer->ops->stream_set(layer, MXR_DISABLE);
44340 /* remove one streamer */
44341 mxr_streamer_put(mdev);
44342 /* allow changes in output configuration */
44343 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44344
44345 void mxr_layer_release(struct mxr_layer *layer)
44346 {
44347 - if (layer->ops.release)
44348 - layer->ops.release(layer);
44349 + if (layer->ops->release)
44350 + layer->ops->release(layer);
44351 }
44352
44353 void mxr_base_layer_release(struct mxr_layer *layer)
44354 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44355
44356 layer->mdev = mdev;
44357 layer->idx = idx;
44358 - layer->ops = *ops;
44359 + layer->ops = ops;
44360
44361 spin_lock_init(&layer->enq_slock);
44362 INIT_LIST_HEAD(&layer->enq_list);
44363 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44364 index c9388c4..ce71ece 100644
44365 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44366 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44367 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44368 {
44369 struct mxr_layer *layer;
44370 int ret;
44371 - struct mxr_layer_ops ops = {
44372 + static struct mxr_layer_ops ops = {
44373 .release = mxr_vp_layer_release,
44374 .buffer_set = mxr_vp_buffer_set,
44375 .stream_set = mxr_vp_stream_set,
44376 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44377 index 2d4e73b..8b4d5b6 100644
44378 --- a/drivers/media/platform/vivi.c
44379 +++ b/drivers/media/platform/vivi.c
44380 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44381 MODULE_LICENSE("Dual BSD/GPL");
44382 MODULE_VERSION(VIVI_VERSION);
44383
44384 -static unsigned video_nr = -1;
44385 -module_param(video_nr, uint, 0644);
44386 +static int video_nr = -1;
44387 +module_param(video_nr, int, 0644);
44388 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44389
44390 static unsigned n_devs = 1;
44391 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44392 index 545c04c..a14bded 100644
44393 --- a/drivers/media/radio/radio-cadet.c
44394 +++ b/drivers/media/radio/radio-cadet.c
44395 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44396 unsigned char readbuf[RDS_BUFFER];
44397 int i = 0;
44398
44399 + if (count > RDS_BUFFER)
44400 + return -EFAULT;
44401 mutex_lock(&dev->lock);
44402 if (dev->rdsstat == 0)
44403 cadet_start_rds(dev);
44404 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44405 while (i < count && dev->rdsin != dev->rdsout)
44406 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44407
44408 - if (i && copy_to_user(data, readbuf, i))
44409 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44410 i = -EFAULT;
44411 unlock:
44412 mutex_unlock(&dev->lock);
44413 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44414 index 5236035..c622c74 100644
44415 --- a/drivers/media/radio/radio-maxiradio.c
44416 +++ b/drivers/media/radio/radio-maxiradio.c
44417 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44418 /* TEA5757 pin mappings */
44419 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44420
44421 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44422 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44423
44424 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44425 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44426 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44427 index 050b3bb..79f62b9 100644
44428 --- a/drivers/media/radio/radio-shark.c
44429 +++ b/drivers/media/radio/radio-shark.c
44430 @@ -79,7 +79,7 @@ struct shark_device {
44431 u32 last_val;
44432 };
44433
44434 -static atomic_t shark_instance = ATOMIC_INIT(0);
44435 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44436
44437 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44438 {
44439 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44440 index 8654e0d..0608a64 100644
44441 --- a/drivers/media/radio/radio-shark2.c
44442 +++ b/drivers/media/radio/radio-shark2.c
44443 @@ -74,7 +74,7 @@ struct shark_device {
44444 u8 *transfer_buffer;
44445 };
44446
44447 -static atomic_t shark_instance = ATOMIC_INIT(0);
44448 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44449
44450 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44451 {
44452 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44453 index 2fd9009..278cc1e 100644
44454 --- a/drivers/media/radio/radio-si476x.c
44455 +++ b/drivers/media/radio/radio-si476x.c
44456 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44457 struct si476x_radio *radio;
44458 struct v4l2_ctrl *ctrl;
44459
44460 - static atomic_t instance = ATOMIC_INIT(0);
44461 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44462
44463 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44464 if (!radio)
44465 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
44466 index 46da365..3ba4206 100644
44467 --- a/drivers/media/rc/rc-main.c
44468 +++ b/drivers/media/rc/rc-main.c
44469 @@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
44470 int rc_register_device(struct rc_dev *dev)
44471 {
44472 static bool raw_init = false; /* raw decoders loaded? */
44473 - static atomic_t devno = ATOMIC_INIT(0);
44474 + static atomic_unchecked_t devno = ATOMIC_INIT(0);
44475 struct rc_map *rc_map;
44476 const char *path;
44477 int rc;
44478 @@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
44479 */
44480 mutex_lock(&dev->lock);
44481
44482 - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
44483 + dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
44484 dev_set_name(&dev->dev, "rc%ld", dev->devno);
44485 dev_set_drvdata(&dev->dev, dev);
44486 rc = device_add(&dev->dev);
44487 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44488 index 20e345d..da56fe4 100644
44489 --- a/drivers/media/usb/dvb-usb/cxusb.c
44490 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44491 @@ -1101,7 +1101,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44492
44493 struct dib0700_adapter_state {
44494 int (*set_param_save) (struct dvb_frontend *);
44495 -};
44496 +} __no_const;
44497
44498 static int dib7070_set_param_override(struct dvb_frontend *fe)
44499 {
44500 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44501 index c1a63b2..dbcbfb6 100644
44502 --- a/drivers/media/usb/dvb-usb/dw2102.c
44503 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44504 @@ -121,7 +121,7 @@ struct su3000_state {
44505
44506 struct s6x0_state {
44507 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44508 -};
44509 +} __no_const;
44510
44511 /* debug */
44512 static int dvb_usb_dw2102_debug;
44513 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44514 index 8f7a6a4..eb0e1d4 100644
44515 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44516 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44517 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44518 __u32 reserved;
44519 };
44520
44521 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44522 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44523 enum v4l2_memory memory)
44524 {
44525 void __user *up_pln;
44526 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44527 return 0;
44528 }
44529
44530 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44531 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44532 enum v4l2_memory memory)
44533 {
44534 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44535 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44536 * by passing a very big num_planes value */
44537 uplane = compat_alloc_user_space(num_planes *
44538 sizeof(struct v4l2_plane));
44539 - kp->m.planes = uplane;
44540 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44541
44542 while (--num_planes >= 0) {
44543 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44544 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44545 if (num_planes == 0)
44546 return 0;
44547
44548 - uplane = kp->m.planes;
44549 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44550 if (get_user(p, &up->m.planes))
44551 return -EFAULT;
44552 uplane32 = compat_ptr(p);
44553 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44554 get_user(kp->capability, &up->capability) ||
44555 get_user(kp->flags, &up->flags))
44556 return -EFAULT;
44557 - kp->base = compat_ptr(tmp);
44558 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44559 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44560 return 0;
44561 }
44562 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44563 n * sizeof(struct v4l2_ext_control32)))
44564 return -EFAULT;
44565 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44566 - kp->controls = kcontrols;
44567 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44568 while (--n >= 0) {
44569 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44570 return -EFAULT;
44571 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44572 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44573 {
44574 struct v4l2_ext_control32 __user *ucontrols;
44575 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44576 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44577 int n = kp->count;
44578 compat_caddr_t p;
44579
44580 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44581 put_user(kp->start_block, &up->start_block) ||
44582 put_user(kp->blocks, &up->blocks) ||
44583 put_user(tmp, &up->edid) ||
44584 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44585 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44586 return -EFAULT;
44587 return 0;
44588 }
44589 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44590 index fb46790..ae1f8fa 100644
44591 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
44592 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44593 @@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44594 return 0;
44595
44596 case V4L2_CTRL_TYPE_STRING:
44597 - len = strlen(c->string);
44598 - if (len < ctrl->minimum)
44599 + len = strlen_user(c->string);
44600 + if (!len || len < ctrl->minimum)
44601 return -ERANGE;
44602 if ((len - ctrl->minimum) % ctrl->step)
44603 return -ERANGE;
44604 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44605 index 02d1b63..5fd6b16 100644
44606 --- a/drivers/media/v4l2-core/v4l2-device.c
44607 +++ b/drivers/media/v4l2-core/v4l2-device.c
44608 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44609 EXPORT_SYMBOL_GPL(v4l2_device_put);
44610
44611 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44612 - atomic_t *instance)
44613 + atomic_unchecked_t *instance)
44614 {
44615 - int num = atomic_inc_return(instance) - 1;
44616 + int num = atomic_inc_return_unchecked(instance) - 1;
44617 int len = strlen(basename);
44618
44619 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44620 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44621 index 68e6b5e..8eb2aec 100644
44622 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44623 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44624 @@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
44625 struct file *file, void *fh, void *p);
44626 } u;
44627 void (*debug)(const void *arg, bool write_only);
44628 -};
44629 +} __do_const;
44630 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44631
44632 /* This control needs a priority check */
44633 #define INFO_FL_PRIO (1 << 0)
44634 @@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
44635 struct video_device *vfd = video_devdata(file);
44636 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44637 bool write_only = false;
44638 - struct v4l2_ioctl_info default_info;
44639 + v4l2_ioctl_info_no_const default_info;
44640 const struct v4l2_ioctl_info *info;
44641 void *fh = file->private_data;
44642 struct v4l2_fh *vfh = NULL;
44643 @@ -2194,7 +2195,7 @@ done:
44644 }
44645
44646 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44647 - void * __user *user_ptr, void ***kernel_ptr)
44648 + void __user **user_ptr, void ***kernel_ptr)
44649 {
44650 int ret = 0;
44651
44652 @@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44653 ret = -EINVAL;
44654 break;
44655 }
44656 - *user_ptr = (void __user *)buf->m.planes;
44657 + *user_ptr = (void __force_user *)buf->m.planes;
44658 *kernel_ptr = (void *)&buf->m.planes;
44659 *array_size = sizeof(struct v4l2_plane) * buf->length;
44660 ret = 1;
44661 @@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44662 ret = -EINVAL;
44663 break;
44664 }
44665 - *user_ptr = (void __user *)ctrls->controls;
44666 + *user_ptr = (void __force_user *)ctrls->controls;
44667 *kernel_ptr = (void *)&ctrls->controls;
44668 *array_size = sizeof(struct v4l2_ext_control)
44669 * ctrls->count;
44670 @@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44671 err = -ENOTTY;
44672
44673 if (has_array_args) {
44674 - *kernel_ptr = user_ptr;
44675 + *kernel_ptr = (void __force_kernel *)user_ptr;
44676 if (copy_to_user(user_ptr, mbuf, array_size))
44677 err = -EFAULT;
44678 goto out_array_args;
44679 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44680 index 767ff4d..c69d259 100644
44681 --- a/drivers/message/fusion/mptbase.c
44682 +++ b/drivers/message/fusion/mptbase.c
44683 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44684 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44685 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44686
44687 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44688 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44689 +#else
44690 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44691 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44692 +#endif
44693 +
44694 /*
44695 * Rounding UP to nearest 4-kB boundary here...
44696 */
44697 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44698 ioc->facts.GlobalCredits);
44699
44700 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44701 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44702 + NULL, NULL);
44703 +#else
44704 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44705 +#endif
44706 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44707 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44708 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44709 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44710 index dd239bd..689c4f7 100644
44711 --- a/drivers/message/fusion/mptsas.c
44712 +++ b/drivers/message/fusion/mptsas.c
44713 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44714 return 0;
44715 }
44716
44717 +static inline void
44718 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44719 +{
44720 + if (phy_info->port_details) {
44721 + phy_info->port_details->rphy = rphy;
44722 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44723 + ioc->name, rphy));
44724 + }
44725 +
44726 + if (rphy) {
44727 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44728 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44729 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44730 + ioc->name, rphy, rphy->dev.release));
44731 + }
44732 +}
44733 +
44734 /* no mutex */
44735 static void
44736 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44737 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44738 return NULL;
44739 }
44740
44741 -static inline void
44742 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44743 -{
44744 - if (phy_info->port_details) {
44745 - phy_info->port_details->rphy = rphy;
44746 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44747 - ioc->name, rphy));
44748 - }
44749 -
44750 - if (rphy) {
44751 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44752 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44753 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44754 - ioc->name, rphy, rphy->dev.release));
44755 - }
44756 -}
44757 -
44758 static inline struct sas_port *
44759 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44760 {
44761 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44762 index 727819c..ad74694 100644
44763 --- a/drivers/message/fusion/mptscsih.c
44764 +++ b/drivers/message/fusion/mptscsih.c
44765 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44766
44767 h = shost_priv(SChost);
44768
44769 - if (h) {
44770 - if (h->info_kbuf == NULL)
44771 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44772 - return h->info_kbuf;
44773 - h->info_kbuf[0] = '\0';
44774 + if (!h)
44775 + return NULL;
44776
44777 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44778 - h->info_kbuf[size-1] = '\0';
44779 - }
44780 + if (h->info_kbuf == NULL)
44781 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44782 + return h->info_kbuf;
44783 + h->info_kbuf[0] = '\0';
44784 +
44785 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44786 + h->info_kbuf[size-1] = '\0';
44787
44788 return h->info_kbuf;
44789 }
44790 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44791 index b7d87cd..3fb36da 100644
44792 --- a/drivers/message/i2o/i2o_proc.c
44793 +++ b/drivers/message/i2o/i2o_proc.c
44794 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44795 "Array Controller Device"
44796 };
44797
44798 -static char *chtostr(char *tmp, u8 *chars, int n)
44799 -{
44800 - tmp[0] = 0;
44801 - return strncat(tmp, (char *)chars, n);
44802 -}
44803 -
44804 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44805 char *group)
44806 {
44807 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44808 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44809 {
44810 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44811 - static u32 work32[5];
44812 - static u8 *work8 = (u8 *) work32;
44813 - static u16 *work16 = (u16 *) work32;
44814 + u32 work32[5];
44815 + u8 *work8 = (u8 *) work32;
44816 + u16 *work16 = (u16 *) work32;
44817 int token;
44818 u32 hwcap;
44819
44820 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44821 } *result;
44822
44823 i2o_exec_execute_ddm_table ddm_table;
44824 - char tmp[28 + 1];
44825
44826 result = kmalloc(sizeof(*result), GFP_KERNEL);
44827 if (!result)
44828 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44829
44830 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44831 seq_printf(seq, "%-#8x", ddm_table.module_id);
44832 - seq_printf(seq, "%-29s",
44833 - chtostr(tmp, ddm_table.module_name_version, 28));
44834 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44835 seq_printf(seq, "%9d ", ddm_table.data_size);
44836 seq_printf(seq, "%8d", ddm_table.code_size);
44837
44838 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44839
44840 i2o_driver_result_table *result;
44841 i2o_driver_store_table *dst;
44842 - char tmp[28 + 1];
44843
44844 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44845 if (result == NULL)
44846 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44847
44848 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44849 seq_printf(seq, "%-#8x", dst->module_id);
44850 - seq_printf(seq, "%-29s",
44851 - chtostr(tmp, dst->module_name_version, 28));
44852 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44853 + seq_printf(seq, "%-.28s", dst->module_name_version);
44854 + seq_printf(seq, "%-.8s", dst->date);
44855 seq_printf(seq, "%8d ", dst->module_size);
44856 seq_printf(seq, "%8d ", dst->mpb_size);
44857 seq_printf(seq, "0x%04x", dst->module_flags);
44858 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44859 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44860 {
44861 struct i2o_device *d = (struct i2o_device *)seq->private;
44862 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44863 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44864 // == (allow) 512d bytes (max)
44865 - static u16 *work16 = (u16 *) work32;
44866 + u16 *work16 = (u16 *) work32;
44867 int token;
44868 - char tmp[16 + 1];
44869
44870 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44871
44872 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44873 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44874 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44875 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44876 - seq_printf(seq, "Vendor info : %s\n",
44877 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44878 - seq_printf(seq, "Product info : %s\n",
44879 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44880 - seq_printf(seq, "Description : %s\n",
44881 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44882 - seq_printf(seq, "Product rev. : %s\n",
44883 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44884 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44885 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44886 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44887 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44888
44889 seq_printf(seq, "Serial number : ");
44890 print_serial_number(seq, (u8 *) (work32 + 16),
44891 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44892 u8 pad[256]; // allow up to 256 byte (max) serial number
44893 } result;
44894
44895 - char tmp[24 + 1];
44896 -
44897 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44898
44899 if (token < 0) {
44900 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44901 }
44902
44903 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44904 - seq_printf(seq, "Module name : %s\n",
44905 - chtostr(tmp, result.module_name, 24));
44906 - seq_printf(seq, "Module revision : %s\n",
44907 - chtostr(tmp, result.module_rev, 8));
44908 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
44909 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44910
44911 seq_printf(seq, "Serial number : ");
44912 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44913 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44914 u8 instance_number[4];
44915 } result;
44916
44917 - char tmp[64 + 1];
44918 -
44919 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44920
44921 if (token < 0) {
44922 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44923 return 0;
44924 }
44925
44926 - seq_printf(seq, "Device name : %s\n",
44927 - chtostr(tmp, result.device_name, 64));
44928 - seq_printf(seq, "Service name : %s\n",
44929 - chtostr(tmp, result.service_name, 64));
44930 - seq_printf(seq, "Physical name : %s\n",
44931 - chtostr(tmp, result.physical_location, 64));
44932 - seq_printf(seq, "Instance number : %s\n",
44933 - chtostr(tmp, result.instance_number, 4));
44934 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
44935 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
44936 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44937 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44938
44939 return 0;
44940 }
44941 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44942 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44943 {
44944 struct i2o_device *d = (struct i2o_device *)seq->private;
44945 - static u32 work32[12];
44946 - static u16 *work16 = (u16 *) work32;
44947 - static u8 *work8 = (u8 *) work32;
44948 + u32 work32[12];
44949 + u16 *work16 = (u16 *) work32;
44950 + u8 *work8 = (u8 *) work32;
44951 int token;
44952
44953 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44954 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44955 index a8c08f3..155fe3d 100644
44956 --- a/drivers/message/i2o/iop.c
44957 +++ b/drivers/message/i2o/iop.c
44958 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44959
44960 spin_lock_irqsave(&c->context_list_lock, flags);
44961
44962 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44963 - atomic_inc(&c->context_list_counter);
44964 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44965 + atomic_inc_unchecked(&c->context_list_counter);
44966
44967 - entry->context = atomic_read(&c->context_list_counter);
44968 + entry->context = atomic_read_unchecked(&c->context_list_counter);
44969
44970 list_add(&entry->list, &c->context_list);
44971
44972 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
44973
44974 #if BITS_PER_LONG == 64
44975 spin_lock_init(&c->context_list_lock);
44976 - atomic_set(&c->context_list_counter, 0);
44977 + atomic_set_unchecked(&c->context_list_counter, 0);
44978 INIT_LIST_HEAD(&c->context_list);
44979 #endif
44980
44981 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
44982 index e33e385..28dfd23 100644
44983 --- a/drivers/mfd/ab8500-debugfs.c
44984 +++ b/drivers/mfd/ab8500-debugfs.c
44985 @@ -100,7 +100,7 @@ static int irq_last;
44986 static u32 *irq_count;
44987 static int num_irqs;
44988
44989 -static struct device_attribute **dev_attr;
44990 +static device_attribute_no_const **dev_attr;
44991 static char **event_name;
44992
44993 static u8 avg_sample = SAMPLE_16;
44994 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
44995 index fcbb2e9..2635e11 100644
44996 --- a/drivers/mfd/janz-cmodio.c
44997 +++ b/drivers/mfd/janz-cmodio.c
44998 @@ -13,6 +13,7 @@
44999
45000 #include <linux/kernel.h>
45001 #include <linux/module.h>
45002 +#include <linux/slab.h>
45003 #include <linux/init.h>
45004 #include <linux/pci.h>
45005 #include <linux/interrupt.h>
45006 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45007 index 176aa26..27811b2 100644
45008 --- a/drivers/mfd/max8925-i2c.c
45009 +++ b/drivers/mfd/max8925-i2c.c
45010 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45011 const struct i2c_device_id *id)
45012 {
45013 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45014 - static struct max8925_chip *chip;
45015 + struct max8925_chip *chip;
45016 struct device_node *node = client->dev.of_node;
45017
45018 if (node && !pdata) {
45019 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45020 index c0f608e..286f8ec 100644
45021 --- a/drivers/mfd/tps65910.c
45022 +++ b/drivers/mfd/tps65910.c
45023 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45024 struct tps65910_platform_data *pdata)
45025 {
45026 int ret = 0;
45027 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45028 + struct regmap_irq_chip *tps6591x_irqs_chip;
45029
45030 if (!irq) {
45031 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45032 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45033 index 9aa6d1e..1631bfc 100644
45034 --- a/drivers/mfd/twl4030-irq.c
45035 +++ b/drivers/mfd/twl4030-irq.c
45036 @@ -35,6 +35,7 @@
45037 #include <linux/of.h>
45038 #include <linux/irqdomain.h>
45039 #include <linux/i2c/twl.h>
45040 +#include <asm/pgtable.h>
45041
45042 #include "twl-core.h"
45043
45044 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45045 * Install an irq handler for each of the SIH modules;
45046 * clone dummy irq_chip since PIH can't *do* anything
45047 */
45048 - twl4030_irq_chip = dummy_irq_chip;
45049 - twl4030_irq_chip.name = "twl4030";
45050 + pax_open_kernel();
45051 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45052 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45053
45054 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45055 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45056 + pax_close_kernel();
45057
45058 for (i = irq_base; i < irq_end; i++) {
45059 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45060 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45061 index 464419b..64bae8d 100644
45062 --- a/drivers/misc/c2port/core.c
45063 +++ b/drivers/misc/c2port/core.c
45064 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45065 goto error_idr_alloc;
45066 c2dev->id = ret;
45067
45068 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45069 + pax_open_kernel();
45070 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45071 + pax_close_kernel();
45072
45073 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45074 "c2port%d", c2dev->id);
45075 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45076 index 9c34e57..b981cda 100644
45077 --- a/drivers/misc/eeprom/sunxi_sid.c
45078 +++ b/drivers/misc/eeprom/sunxi_sid.c
45079 @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45080
45081 platform_set_drvdata(pdev, sid_data);
45082
45083 - sid_bin_attr.size = sid_data->keysize;
45084 + pax_open_kernel();
45085 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45086 + pax_close_kernel();
45087 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45088 return -ENODEV;
45089
45090 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45091 index 36f5d52..32311c3 100644
45092 --- a/drivers/misc/kgdbts.c
45093 +++ b/drivers/misc/kgdbts.c
45094 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45095 char before[BREAK_INSTR_SIZE];
45096 char after[BREAK_INSTR_SIZE];
45097
45098 - probe_kernel_read(before, (char *)kgdbts_break_test,
45099 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45100 BREAK_INSTR_SIZE);
45101 init_simple_test();
45102 ts.tst = plant_and_detach_test;
45103 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45104 /* Activate test with initial breakpoint */
45105 if (!is_early)
45106 kgdb_breakpoint();
45107 - probe_kernel_read(after, (char *)kgdbts_break_test,
45108 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45109 BREAK_INSTR_SIZE);
45110 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45111 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45112 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45113 index 036effe..b3a6336 100644
45114 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45115 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45116 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45117 * the lid is closed. This leads to interrupts as soon as a little move
45118 * is done.
45119 */
45120 - atomic_inc(&lis3->count);
45121 + atomic_inc_unchecked(&lis3->count);
45122
45123 wake_up_interruptible(&lis3->misc_wait);
45124 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45125 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45126 if (lis3->pm_dev)
45127 pm_runtime_get_sync(lis3->pm_dev);
45128
45129 - atomic_set(&lis3->count, 0);
45130 + atomic_set_unchecked(&lis3->count, 0);
45131 return 0;
45132 }
45133
45134 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45135 add_wait_queue(&lis3->misc_wait, &wait);
45136 while (true) {
45137 set_current_state(TASK_INTERRUPTIBLE);
45138 - data = atomic_xchg(&lis3->count, 0);
45139 + data = atomic_xchg_unchecked(&lis3->count, 0);
45140 if (data)
45141 break;
45142
45143 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45144 struct lis3lv02d, miscdev);
45145
45146 poll_wait(file, &lis3->misc_wait, wait);
45147 - if (atomic_read(&lis3->count))
45148 + if (atomic_read_unchecked(&lis3->count))
45149 return POLLIN | POLLRDNORM;
45150 return 0;
45151 }
45152 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45153 index c439c82..1f20f57 100644
45154 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45155 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45156 @@ -297,7 +297,7 @@ struct lis3lv02d {
45157 struct input_polled_dev *idev; /* input device */
45158 struct platform_device *pdev; /* platform device */
45159 struct regulator_bulk_data regulators[2];
45160 - atomic_t count; /* interrupt count after last read */
45161 + atomic_unchecked_t count; /* interrupt count after last read */
45162 union axis_conversion ac; /* hw -> logical axis */
45163 int mapped_btns[3];
45164
45165 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45166 index 2f30bad..c4c13d0 100644
45167 --- a/drivers/misc/sgi-gru/gruhandles.c
45168 +++ b/drivers/misc/sgi-gru/gruhandles.c
45169 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45170 unsigned long nsec;
45171
45172 nsec = CLKS2NSEC(clks);
45173 - atomic_long_inc(&mcs_op_statistics[op].count);
45174 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45175 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45176 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45177 if (mcs_op_statistics[op].max < nsec)
45178 mcs_op_statistics[op].max = nsec;
45179 }
45180 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45181 index 4f76359..cdfcb2e 100644
45182 --- a/drivers/misc/sgi-gru/gruprocfs.c
45183 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45184 @@ -32,9 +32,9 @@
45185
45186 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45187
45188 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45189 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45190 {
45191 - unsigned long val = atomic_long_read(v);
45192 + unsigned long val = atomic_long_read_unchecked(v);
45193
45194 seq_printf(s, "%16lu %s\n", val, id);
45195 }
45196 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45197
45198 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45199 for (op = 0; op < mcsop_last; op++) {
45200 - count = atomic_long_read(&mcs_op_statistics[op].count);
45201 - total = atomic_long_read(&mcs_op_statistics[op].total);
45202 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45203 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45204 max = mcs_op_statistics[op].max;
45205 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45206 count ? total / count : 0, max);
45207 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45208 index 5c3ce24..4915ccb 100644
45209 --- a/drivers/misc/sgi-gru/grutables.h
45210 +++ b/drivers/misc/sgi-gru/grutables.h
45211 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45212 * GRU statistics.
45213 */
45214 struct gru_stats_s {
45215 - atomic_long_t vdata_alloc;
45216 - atomic_long_t vdata_free;
45217 - atomic_long_t gts_alloc;
45218 - atomic_long_t gts_free;
45219 - atomic_long_t gms_alloc;
45220 - atomic_long_t gms_free;
45221 - atomic_long_t gts_double_allocate;
45222 - atomic_long_t assign_context;
45223 - atomic_long_t assign_context_failed;
45224 - atomic_long_t free_context;
45225 - atomic_long_t load_user_context;
45226 - atomic_long_t load_kernel_context;
45227 - atomic_long_t lock_kernel_context;
45228 - atomic_long_t unlock_kernel_context;
45229 - atomic_long_t steal_user_context;
45230 - atomic_long_t steal_kernel_context;
45231 - atomic_long_t steal_context_failed;
45232 - atomic_long_t nopfn;
45233 - atomic_long_t asid_new;
45234 - atomic_long_t asid_next;
45235 - atomic_long_t asid_wrap;
45236 - atomic_long_t asid_reuse;
45237 - atomic_long_t intr;
45238 - atomic_long_t intr_cbr;
45239 - atomic_long_t intr_tfh;
45240 - atomic_long_t intr_spurious;
45241 - atomic_long_t intr_mm_lock_failed;
45242 - atomic_long_t call_os;
45243 - atomic_long_t call_os_wait_queue;
45244 - atomic_long_t user_flush_tlb;
45245 - atomic_long_t user_unload_context;
45246 - atomic_long_t user_exception;
45247 - atomic_long_t set_context_option;
45248 - atomic_long_t check_context_retarget_intr;
45249 - atomic_long_t check_context_unload;
45250 - atomic_long_t tlb_dropin;
45251 - atomic_long_t tlb_preload_page;
45252 - atomic_long_t tlb_dropin_fail_no_asid;
45253 - atomic_long_t tlb_dropin_fail_upm;
45254 - atomic_long_t tlb_dropin_fail_invalid;
45255 - atomic_long_t tlb_dropin_fail_range_active;
45256 - atomic_long_t tlb_dropin_fail_idle;
45257 - atomic_long_t tlb_dropin_fail_fmm;
45258 - atomic_long_t tlb_dropin_fail_no_exception;
45259 - atomic_long_t tfh_stale_on_fault;
45260 - atomic_long_t mmu_invalidate_range;
45261 - atomic_long_t mmu_invalidate_page;
45262 - atomic_long_t flush_tlb;
45263 - atomic_long_t flush_tlb_gru;
45264 - atomic_long_t flush_tlb_gru_tgh;
45265 - atomic_long_t flush_tlb_gru_zero_asid;
45266 + atomic_long_unchecked_t vdata_alloc;
45267 + atomic_long_unchecked_t vdata_free;
45268 + atomic_long_unchecked_t gts_alloc;
45269 + atomic_long_unchecked_t gts_free;
45270 + atomic_long_unchecked_t gms_alloc;
45271 + atomic_long_unchecked_t gms_free;
45272 + atomic_long_unchecked_t gts_double_allocate;
45273 + atomic_long_unchecked_t assign_context;
45274 + atomic_long_unchecked_t assign_context_failed;
45275 + atomic_long_unchecked_t free_context;
45276 + atomic_long_unchecked_t load_user_context;
45277 + atomic_long_unchecked_t load_kernel_context;
45278 + atomic_long_unchecked_t lock_kernel_context;
45279 + atomic_long_unchecked_t unlock_kernel_context;
45280 + atomic_long_unchecked_t steal_user_context;
45281 + atomic_long_unchecked_t steal_kernel_context;
45282 + atomic_long_unchecked_t steal_context_failed;
45283 + atomic_long_unchecked_t nopfn;
45284 + atomic_long_unchecked_t asid_new;
45285 + atomic_long_unchecked_t asid_next;
45286 + atomic_long_unchecked_t asid_wrap;
45287 + atomic_long_unchecked_t asid_reuse;
45288 + atomic_long_unchecked_t intr;
45289 + atomic_long_unchecked_t intr_cbr;
45290 + atomic_long_unchecked_t intr_tfh;
45291 + atomic_long_unchecked_t intr_spurious;
45292 + atomic_long_unchecked_t intr_mm_lock_failed;
45293 + atomic_long_unchecked_t call_os;
45294 + atomic_long_unchecked_t call_os_wait_queue;
45295 + atomic_long_unchecked_t user_flush_tlb;
45296 + atomic_long_unchecked_t user_unload_context;
45297 + atomic_long_unchecked_t user_exception;
45298 + atomic_long_unchecked_t set_context_option;
45299 + atomic_long_unchecked_t check_context_retarget_intr;
45300 + atomic_long_unchecked_t check_context_unload;
45301 + atomic_long_unchecked_t tlb_dropin;
45302 + atomic_long_unchecked_t tlb_preload_page;
45303 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45304 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45305 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45306 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45307 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45308 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45309 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45310 + atomic_long_unchecked_t tfh_stale_on_fault;
45311 + atomic_long_unchecked_t mmu_invalidate_range;
45312 + atomic_long_unchecked_t mmu_invalidate_page;
45313 + atomic_long_unchecked_t flush_tlb;
45314 + atomic_long_unchecked_t flush_tlb_gru;
45315 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45316 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45317
45318 - atomic_long_t copy_gpa;
45319 - atomic_long_t read_gpa;
45320 + atomic_long_unchecked_t copy_gpa;
45321 + atomic_long_unchecked_t read_gpa;
45322
45323 - atomic_long_t mesq_receive;
45324 - atomic_long_t mesq_receive_none;
45325 - atomic_long_t mesq_send;
45326 - atomic_long_t mesq_send_failed;
45327 - atomic_long_t mesq_noop;
45328 - atomic_long_t mesq_send_unexpected_error;
45329 - atomic_long_t mesq_send_lb_overflow;
45330 - atomic_long_t mesq_send_qlimit_reached;
45331 - atomic_long_t mesq_send_amo_nacked;
45332 - atomic_long_t mesq_send_put_nacked;
45333 - atomic_long_t mesq_page_overflow;
45334 - atomic_long_t mesq_qf_locked;
45335 - atomic_long_t mesq_qf_noop_not_full;
45336 - atomic_long_t mesq_qf_switch_head_failed;
45337 - atomic_long_t mesq_qf_unexpected_error;
45338 - atomic_long_t mesq_noop_unexpected_error;
45339 - atomic_long_t mesq_noop_lb_overflow;
45340 - atomic_long_t mesq_noop_qlimit_reached;
45341 - atomic_long_t mesq_noop_amo_nacked;
45342 - atomic_long_t mesq_noop_put_nacked;
45343 - atomic_long_t mesq_noop_page_overflow;
45344 + atomic_long_unchecked_t mesq_receive;
45345 + atomic_long_unchecked_t mesq_receive_none;
45346 + atomic_long_unchecked_t mesq_send;
45347 + atomic_long_unchecked_t mesq_send_failed;
45348 + atomic_long_unchecked_t mesq_noop;
45349 + atomic_long_unchecked_t mesq_send_unexpected_error;
45350 + atomic_long_unchecked_t mesq_send_lb_overflow;
45351 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45352 + atomic_long_unchecked_t mesq_send_amo_nacked;
45353 + atomic_long_unchecked_t mesq_send_put_nacked;
45354 + atomic_long_unchecked_t mesq_page_overflow;
45355 + atomic_long_unchecked_t mesq_qf_locked;
45356 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45357 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45358 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45359 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45360 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45361 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45362 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45363 + atomic_long_unchecked_t mesq_noop_put_nacked;
45364 + atomic_long_unchecked_t mesq_noop_page_overflow;
45365
45366 };
45367
45368 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45369 tghop_invalidate, mcsop_last};
45370
45371 struct mcs_op_statistic {
45372 - atomic_long_t count;
45373 - atomic_long_t total;
45374 + atomic_long_unchecked_t count;
45375 + atomic_long_unchecked_t total;
45376 unsigned long max;
45377 };
45378
45379 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45380
45381 #define STAT(id) do { \
45382 if (gru_options & OPT_STATS) \
45383 - atomic_long_inc(&gru_stats.id); \
45384 + atomic_long_inc_unchecked(&gru_stats.id); \
45385 } while (0)
45386
45387 #ifdef CONFIG_SGI_GRU_DEBUG
45388 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45389 index c862cd4..0d176fe 100644
45390 --- a/drivers/misc/sgi-xp/xp.h
45391 +++ b/drivers/misc/sgi-xp/xp.h
45392 @@ -288,7 +288,7 @@ struct xpc_interface {
45393 xpc_notify_func, void *);
45394 void (*received) (short, int, void *);
45395 enum xp_retval (*partid_to_nasids) (short, void *);
45396 -};
45397 +} __no_const;
45398
45399 extern struct xpc_interface xpc_interface;
45400
45401 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45402 index 01be66d..e3a0c7e 100644
45403 --- a/drivers/misc/sgi-xp/xp_main.c
45404 +++ b/drivers/misc/sgi-xp/xp_main.c
45405 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45406 }
45407
45408 struct xpc_interface xpc_interface = {
45409 - (void (*)(int))xpc_notloaded,
45410 - (void (*)(int))xpc_notloaded,
45411 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45412 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45413 + .connect = (void (*)(int))xpc_notloaded,
45414 + .disconnect = (void (*)(int))xpc_notloaded,
45415 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45416 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45417 void *))xpc_notloaded,
45418 - (void (*)(short, int, void *))xpc_notloaded,
45419 - (enum xp_retval(*)(short, void *))xpc_notloaded
45420 + .received = (void (*)(short, int, void *))xpc_notloaded,
45421 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45422 };
45423 EXPORT_SYMBOL_GPL(xpc_interface);
45424
45425 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45426 index b94d5f7..7f494c5 100644
45427 --- a/drivers/misc/sgi-xp/xpc.h
45428 +++ b/drivers/misc/sgi-xp/xpc.h
45429 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45430 void (*received_payload) (struct xpc_channel *, void *);
45431 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45432 };
45433 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45434
45435 /* struct xpc_partition act_state values (for XPC HB) */
45436
45437 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45438 /* found in xpc_main.c */
45439 extern struct device *xpc_part;
45440 extern struct device *xpc_chan;
45441 -extern struct xpc_arch_operations xpc_arch_ops;
45442 +extern xpc_arch_operations_no_const xpc_arch_ops;
45443 extern int xpc_disengage_timelimit;
45444 extern int xpc_disengage_timedout;
45445 extern int xpc_activate_IRQ_rcvd;
45446 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45447 index 82dc574..8539ab2 100644
45448 --- a/drivers/misc/sgi-xp/xpc_main.c
45449 +++ b/drivers/misc/sgi-xp/xpc_main.c
45450 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45451 .notifier_call = xpc_system_die,
45452 };
45453
45454 -struct xpc_arch_operations xpc_arch_ops;
45455 +xpc_arch_operations_no_const xpc_arch_ops;
45456
45457 /*
45458 * Timer function to enforce the timelimit on the partition disengage.
45459 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45460
45461 if (((die_args->trapnr == X86_TRAP_MF) ||
45462 (die_args->trapnr == X86_TRAP_XF)) &&
45463 - !user_mode_vm(die_args->regs))
45464 + !user_mode(die_args->regs))
45465 xpc_die_deactivate();
45466
45467 break;
45468 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45469 index 7b5424f..ed1d6ac 100644
45470 --- a/drivers/mmc/card/block.c
45471 +++ b/drivers/mmc/card/block.c
45472 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45473 if (idata->ic.postsleep_min_us)
45474 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45475
45476 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45477 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45478 err = -EFAULT;
45479 goto cmd_rel_host;
45480 }
45481 diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
45482 index 357bbc5..3e049c1 100644
45483 --- a/drivers/mmc/card/queue.c
45484 +++ b/drivers/mmc/card/queue.c
45485 @@ -197,7 +197,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
45486 struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
45487
45488 if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
45489 - limit = dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
45490 + limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
45491
45492 mq->card = card;
45493 mq->queue = blk_init_queue(mmc_request_fn, lock);
45494 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45495 index e5b5eeb..7bf2212 100644
45496 --- a/drivers/mmc/core/mmc_ops.c
45497 +++ b/drivers/mmc/core/mmc_ops.c
45498 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45499 void *data_buf;
45500 int is_on_stack;
45501
45502 - is_on_stack = object_is_on_stack(buf);
45503 + is_on_stack = object_starts_on_stack(buf);
45504 if (is_on_stack) {
45505 /*
45506 * dma onto stack is unsafe/nonportable, but callers to this
45507 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45508 index 6bf24ab..13d0293b 100644
45509 --- a/drivers/mmc/host/dw_mmc.h
45510 +++ b/drivers/mmc/host/dw_mmc.h
45511 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45512 int (*parse_dt)(struct dw_mci *host);
45513 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45514 struct dw_mci_tuning_data *tuning_data);
45515 -};
45516 +} __do_const;
45517 #endif /* _DW_MMC_H_ */
45518 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45519 index f320579..7b7ebac 100644
45520 --- a/drivers/mmc/host/mmci.c
45521 +++ b/drivers/mmc/host/mmci.c
45522 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45523 }
45524
45525 if (variant->busy_detect) {
45526 - mmci_ops.card_busy = mmci_card_busy;
45527 + pax_open_kernel();
45528 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45529 + pax_close_kernel();
45530 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45531 }
45532
45533 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45534 index 1dcaf8a..025af25 100644
45535 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45536 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45537 @@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45538 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
45539 }
45540
45541 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45542 - sdhci_esdhc_ops.platform_execute_tuning =
45543 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45544 + pax_open_kernel();
45545 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45546 esdhc_executing_tuning;
45547 + pax_close_kernel();
45548 + }
45549 boarddata = &imx_data->boarddata;
45550 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
45551 if (!host->mmc->parent->platform_data) {
45552 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45553 index 6debda9..2ba7427 100644
45554 --- a/drivers/mmc/host/sdhci-s3c.c
45555 +++ b/drivers/mmc/host/sdhci-s3c.c
45556 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45557 * we can use overriding functions instead of default.
45558 */
45559 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45560 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45561 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45562 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45563 + pax_open_kernel();
45564 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45565 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45566 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45567 + pax_close_kernel();
45568 }
45569
45570 /* It supports additional host capabilities if needed */
45571 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45572 index 096993f..f02c23b 100644
45573 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45574 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45575 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45576 size_t totlen = 0, thislen;
45577 int ret = 0;
45578 size_t buflen = 0;
45579 - static char *buffer;
45580 + char *buffer;
45581
45582 if (!ECCBUF_SIZE) {
45583 /* We should fall back to a general writev implementation.
45584 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45585 index 370b9dd..1a1176b 100644
45586 --- a/drivers/mtd/nand/denali.c
45587 +++ b/drivers/mtd/nand/denali.c
45588 @@ -24,6 +24,7 @@
45589 #include <linux/slab.h>
45590 #include <linux/mtd/mtd.h>
45591 #include <linux/module.h>
45592 +#include <linux/slab.h>
45593
45594 #include "denali.h"
45595
45596 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45597 index 51b9d6a..52af9a7 100644
45598 --- a/drivers/mtd/nftlmount.c
45599 +++ b/drivers/mtd/nftlmount.c
45600 @@ -24,6 +24,7 @@
45601 #include <asm/errno.h>
45602 #include <linux/delay.h>
45603 #include <linux/slab.h>
45604 +#include <linux/sched.h>
45605 #include <linux/mtd/mtd.h>
45606 #include <linux/mtd/nand.h>
45607 #include <linux/mtd/nftl.h>
45608 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45609 index 4b8e895..6b3c498 100644
45610 --- a/drivers/mtd/sm_ftl.c
45611 +++ b/drivers/mtd/sm_ftl.c
45612 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45613 #define SM_CIS_VENDOR_OFFSET 0x59
45614 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45615 {
45616 - struct attribute_group *attr_group;
45617 + attribute_group_no_const *attr_group;
45618 struct attribute **attributes;
45619 struct sm_sysfs_attribute *vendor_attribute;
45620
45621 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45622 index 4b8c58b..a200546 100644
45623 --- a/drivers/net/bonding/bond_main.c
45624 +++ b/drivers/net/bonding/bond_main.c
45625 @@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
45626
45627 bond_netlink_fini();
45628 unregister_pernet_subsys(&bond_net_ops);
45629 + rtnl_link_unregister(&bond_link_ops);
45630
45631 #ifdef CONFIG_NET_POLL_CONTROLLER
45632 /*
45633 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45634 index 40e7b1c..6a70fff 100644
45635 --- a/drivers/net/bonding/bond_netlink.c
45636 +++ b/drivers/net/bonding/bond_netlink.c
45637 @@ -102,7 +102,7 @@ nla_put_failure:
45638 return -EMSGSIZE;
45639 }
45640
45641 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45642 +struct rtnl_link_ops bond_link_ops = {
45643 .kind = "bond",
45644 .priv_size = sizeof(struct bonding),
45645 .setup = bond_setup,
45646 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45647 index 3c06947..fd0e5de 100644
45648 --- a/drivers/net/can/Kconfig
45649 +++ b/drivers/net/can/Kconfig
45650 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45651
45652 config CAN_FLEXCAN
45653 tristate "Support for Freescale FLEXCAN based chips"
45654 - depends on ARM || PPC
45655 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45656 ---help---
45657 Say Y here if you want to support for Freescale FlexCAN.
45658
45659 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45660 index 36fa577..a158806 100644
45661 --- a/drivers/net/ethernet/8390/ax88796.c
45662 +++ b/drivers/net/ethernet/8390/ax88796.c
45663 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
45664 if (ax->plat->reg_offsets)
45665 ei_local->reg_offset = ax->plat->reg_offsets;
45666 else {
45667 + resource_size_t _mem_size = mem_size;
45668 + do_div(_mem_size, 0x18);
45669 ei_local->reg_offset = ax->reg_offsets;
45670 for (ret = 0; ret < 0x18; ret++)
45671 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45672 + ax->reg_offsets[ret] = _mem_size * ret;
45673 }
45674
45675 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45676 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45677 index 41f3ca5a..1ee5364 100644
45678 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45679 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45680 @@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45681 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45682 {
45683 /* RX_MODE controlling object */
45684 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45685 + bnx2x_init_rx_mode_obj(bp);
45686
45687 /* multicast configuration controlling object */
45688 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45689 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45690 index 18438a5..c923b8e 100644
45691 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45692 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45693 @@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45694 return rc;
45695 }
45696
45697 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45698 - struct bnx2x_rx_mode_obj *o)
45699 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45700 {
45701 if (CHIP_IS_E1x(bp)) {
45702 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45703 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45704 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45705 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45706 } else {
45707 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45708 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45709 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45710 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45711 }
45712 }
45713
45714 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45715 index 6a53c15..6e7d1e7 100644
45716 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45717 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45718 @@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45719
45720 /********************* RX MODE ****************/
45721
45722 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45723 - struct bnx2x_rx_mode_obj *o);
45724 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45725
45726 /**
45727 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45728 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45729 index 5c3835a..d18b952 100644
45730 --- a/drivers/net/ethernet/broadcom/tg3.h
45731 +++ b/drivers/net/ethernet/broadcom/tg3.h
45732 @@ -150,6 +150,7 @@
45733 #define CHIPREV_ID_5750_A0 0x4000
45734 #define CHIPREV_ID_5750_A1 0x4001
45735 #define CHIPREV_ID_5750_A3 0x4003
45736 +#define CHIPREV_ID_5750_C1 0x4201
45737 #define CHIPREV_ID_5750_C2 0x4202
45738 #define CHIPREV_ID_5752_A0_HW 0x5000
45739 #define CHIPREV_ID_5752_A0 0x6000
45740 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45741 index 3ca77fa..fcc015f 100644
45742 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45743 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45744 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45745 }
45746
45747 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45748 - bna_cb_ioceth_enable,
45749 - bna_cb_ioceth_disable,
45750 - bna_cb_ioceth_hbfail,
45751 - bna_cb_ioceth_reset
45752 + .enable_cbfn = bna_cb_ioceth_enable,
45753 + .disable_cbfn = bna_cb_ioceth_disable,
45754 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45755 + .reset_cbfn = bna_cb_ioceth_reset
45756 };
45757
45758 static void bna_attr_init(struct bna_ioceth *ioceth)
45759 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45760 index 8cffcdf..aadf043 100644
45761 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45762 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45763 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45764 */
45765 struct l2t_skb_cb {
45766 arp_failure_handler_func arp_failure_handler;
45767 -};
45768 +} __no_const;
45769
45770 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45771
45772 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45773 index fff02ed..d421412 100644
45774 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45775 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45776 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45777
45778 int i;
45779 struct adapter *ap = netdev2adap(dev);
45780 - static const unsigned int *reg_ranges;
45781 + const unsigned int *reg_ranges;
45782 int arr_size = 0, buf_size = 0;
45783
45784 if (is_t4(ap->params.chip)) {
45785 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45786 index c05b66d..ed69872 100644
45787 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45788 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45789 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45790 for (i=0; i<ETH_ALEN; i++) {
45791 tmp.addr[i] = dev->dev_addr[i];
45792 }
45793 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45794 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45795 break;
45796
45797 case DE4X5_SET_HWADDR: /* Set the hardware address */
45798 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45799 spin_lock_irqsave(&lp->lock, flags);
45800 memcpy(&statbuf, &lp->pktStats, ioc->len);
45801 spin_unlock_irqrestore(&lp->lock, flags);
45802 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45803 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45804 return -EFAULT;
45805 break;
45806 }
45807 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45808 index a37039d..a51d7e8 100644
45809 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45810 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45811 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45812
45813 if (wrapped)
45814 newacc += 65536;
45815 - ACCESS_ONCE(*acc) = newacc;
45816 + ACCESS_ONCE_RW(*acc) = newacc;
45817 }
45818
45819 static void populate_erx_stats(struct be_adapter *adapter,
45820 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45821 index 212f44b..fb69959 100644
45822 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45823 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45824 @@ -31,6 +31,8 @@
45825 #include <linux/netdevice.h>
45826 #include <linux/phy.h>
45827 #include <linux/platform_device.h>
45828 +#include <linux/interrupt.h>
45829 +#include <linux/irqreturn.h>
45830 #include <net/ip.h>
45831
45832 #include "ftgmac100.h"
45833 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45834 index 8be5b40..081bc1b 100644
45835 --- a/drivers/net/ethernet/faraday/ftmac100.c
45836 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45837 @@ -31,6 +31,8 @@
45838 #include <linux/module.h>
45839 #include <linux/netdevice.h>
45840 #include <linux/platform_device.h>
45841 +#include <linux/interrupt.h>
45842 +#include <linux/irqreturn.h>
45843
45844 #include "ftmac100.h"
45845
45846 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45847 index 5184e2a..acb28c3 100644
45848 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45849 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45850 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45851 }
45852
45853 /* update the base incval used to calculate frequency adjustment */
45854 - ACCESS_ONCE(adapter->base_incval) = incval;
45855 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45856 smp_mb();
45857
45858 /* need lock to prevent incorrect read while modifying cyclecounter */
45859 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45860 index fbe5363..266b4e3 100644
45861 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45862 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45863 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45864 struct __vxge_hw_fifo *fifo;
45865 struct vxge_hw_fifo_config *config;
45866 u32 txdl_size, txdl_per_memblock;
45867 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45868 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45869 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45870 + };
45871 +
45872 struct __vxge_hw_virtualpath *vpath;
45873
45874 if ((vp == NULL) || (attr == NULL)) {
45875 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45876 goto exit;
45877 }
45878
45879 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45880 -
45881 fifo->mempool =
45882 __vxge_hw_mempool_create(vpath->hldev,
45883 fifo->config->memblock_size,
45884 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45885 index 918e18d..4ca3650 100644
45886 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45887 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45888 @@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45889 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45890 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45891 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45892 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45893 + pax_open_kernel();
45894 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45895 + pax_close_kernel();
45896 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45897 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45898 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45899 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45900 index 734d286..b017bf5 100644
45901 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45902 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45903 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45904 case QLCNIC_NON_PRIV_FUNC:
45905 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45906 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45907 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45908 + pax_open_kernel();
45909 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45910 + pax_close_kernel();
45911 break;
45912 case QLCNIC_PRIV_FUNC:
45913 ahw->op_mode = QLCNIC_PRIV_FUNC;
45914 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45915 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45916 + pax_open_kernel();
45917 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45918 + pax_close_kernel();
45919 break;
45920 case QLCNIC_MGMT_FUNC:
45921 ahw->op_mode = QLCNIC_MGMT_FUNC;
45922 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45923 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45924 + pax_open_kernel();
45925 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45926 + pax_close_kernel();
45927 break;
45928 default:
45929 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45930 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45931 index 7763962..c3499a7 100644
45932 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45933 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45934 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45935 struct qlcnic_dump_entry *entry;
45936 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45937 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45938 - static const struct qlcnic_dump_operations *fw_dump_ops;
45939 + const struct qlcnic_dump_operations *fw_dump_ops;
45940 struct device *dev = &adapter->pdev->dev;
45941 struct qlcnic_hardware_context *ahw;
45942 void *temp_buffer;
45943 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45944 index c737f0e..32b8682 100644
45945 --- a/drivers/net/ethernet/realtek/r8169.c
45946 +++ b/drivers/net/ethernet/realtek/r8169.c
45947 @@ -759,22 +759,22 @@ struct rtl8169_private {
45948 struct mdio_ops {
45949 void (*write)(struct rtl8169_private *, int, int);
45950 int (*read)(struct rtl8169_private *, int);
45951 - } mdio_ops;
45952 + } __no_const mdio_ops;
45953
45954 struct pll_power_ops {
45955 void (*down)(struct rtl8169_private *);
45956 void (*up)(struct rtl8169_private *);
45957 - } pll_power_ops;
45958 + } __no_const pll_power_ops;
45959
45960 struct jumbo_ops {
45961 void (*enable)(struct rtl8169_private *);
45962 void (*disable)(struct rtl8169_private *);
45963 - } jumbo_ops;
45964 + } __no_const jumbo_ops;
45965
45966 struct csi_ops {
45967 void (*write)(struct rtl8169_private *, int, int);
45968 u32 (*read)(struct rtl8169_private *, int);
45969 - } csi_ops;
45970 + } __no_const csi_ops;
45971
45972 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45973 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45974 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45975 index 3dd39dc..85efa46 100644
45976 --- a/drivers/net/ethernet/sfc/ptp.c
45977 +++ b/drivers/net/ethernet/sfc/ptp.c
45978 @@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45979 ptp->start.dma_addr);
45980
45981 /* Clear flag that signals MC ready */
45982 - ACCESS_ONCE(*start) = 0;
45983 + ACCESS_ONCE_RW(*start) = 0;
45984 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
45985 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
45986 EFX_BUG_ON_PARANOID(rc);
45987 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45988 index 50617c5..b13724c 100644
45989 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45990 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45991 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
45992
45993 writel(value, ioaddr + MMC_CNTRL);
45994
45995 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45996 - MMC_CNTRL, value);
45997 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45998 +// MMC_CNTRL, value);
45999 }
46000
46001 /* To mask all all interrupts.*/
46002 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46003 index e6fe0d8..2b7d752 100644
46004 --- a/drivers/net/hyperv/hyperv_net.h
46005 +++ b/drivers/net/hyperv/hyperv_net.h
46006 @@ -101,7 +101,7 @@ struct rndis_device {
46007
46008 enum rndis_device_state state;
46009 bool link_state;
46010 - atomic_t new_req_id;
46011 + atomic_unchecked_t new_req_id;
46012
46013 spinlock_t request_lock;
46014 struct list_head req_list;
46015 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46016 index 0775f0a..d4fb316 100644
46017 --- a/drivers/net/hyperv/rndis_filter.c
46018 +++ b/drivers/net/hyperv/rndis_filter.c
46019 @@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46020 * template
46021 */
46022 set = &rndis_msg->msg.set_req;
46023 - set->req_id = atomic_inc_return(&dev->new_req_id);
46024 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46025
46026 /* Add to the request list */
46027 spin_lock_irqsave(&dev->request_lock, flags);
46028 @@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46029
46030 /* Setup the rndis set */
46031 halt = &request->request_msg.msg.halt_req;
46032 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46033 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46034
46035 /* Ignore return since this msg is optional. */
46036 rndis_filter_send_request(dev, request);
46037 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46038 index bf0d55e..82bcfbd1 100644
46039 --- a/drivers/net/ieee802154/fakehard.c
46040 +++ b/drivers/net/ieee802154/fakehard.c
46041 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46042 phy->transmit_power = 0xbf;
46043
46044 dev->netdev_ops = &fake_ops;
46045 - dev->ml_priv = &fake_mlme;
46046 + dev->ml_priv = (void *)&fake_mlme;
46047
46048 priv = netdev_priv(dev);
46049 priv->phy = phy;
46050 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46051 index bc8faae..e51e25d 100644
46052 --- a/drivers/net/macvlan.c
46053 +++ b/drivers/net/macvlan.c
46054 @@ -990,13 +990,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46055 int macvlan_link_register(struct rtnl_link_ops *ops)
46056 {
46057 /* common fields */
46058 - ops->priv_size = sizeof(struct macvlan_dev);
46059 - ops->validate = macvlan_validate;
46060 - ops->maxtype = IFLA_MACVLAN_MAX;
46061 - ops->policy = macvlan_policy;
46062 - ops->changelink = macvlan_changelink;
46063 - ops->get_size = macvlan_get_size;
46064 - ops->fill_info = macvlan_fill_info;
46065 + pax_open_kernel();
46066 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46067 + *(void **)&ops->validate = macvlan_validate;
46068 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46069 + *(const void **)&ops->policy = macvlan_policy;
46070 + *(void **)&ops->changelink = macvlan_changelink;
46071 + *(void **)&ops->get_size = macvlan_get_size;
46072 + *(void **)&ops->fill_info = macvlan_fill_info;
46073 + pax_close_kernel();
46074
46075 return rtnl_link_register(ops);
46076 };
46077 @@ -1051,7 +1053,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46078 return NOTIFY_DONE;
46079 }
46080
46081 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46082 +static struct notifier_block macvlan_notifier_block = {
46083 .notifier_call = macvlan_device_event,
46084 };
46085
46086 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46087 index 2a89da0..c17fe1d 100644
46088 --- a/drivers/net/macvtap.c
46089 +++ b/drivers/net/macvtap.c
46090 @@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46091 }
46092
46093 ret = 0;
46094 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46095 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46096 put_user(q->flags, &ifr->ifr_flags))
46097 ret = -EFAULT;
46098 macvtap_put_vlan(vlan);
46099 @@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46100 return NOTIFY_DONE;
46101 }
46102
46103 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46104 +static struct notifier_block macvtap_notifier_block = {
46105 .notifier_call = macvtap_device_event,
46106 };
46107
46108 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46109 index daec9b0..6428fcb 100644
46110 --- a/drivers/net/phy/mdio-bitbang.c
46111 +++ b/drivers/net/phy/mdio-bitbang.c
46112 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46113 struct mdiobb_ctrl *ctrl = bus->priv;
46114
46115 module_put(ctrl->ops->owner);
46116 + mdiobus_unregister(bus);
46117 mdiobus_free(bus);
46118 }
46119 EXPORT_SYMBOL(free_mdio_bitbang);
46120 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46121 index 72ff14b..11d442d 100644
46122 --- a/drivers/net/ppp/ppp_generic.c
46123 +++ b/drivers/net/ppp/ppp_generic.c
46124 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46125 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46126 struct ppp_stats stats;
46127 struct ppp_comp_stats cstats;
46128 - char *vers;
46129
46130 switch (cmd) {
46131 case SIOCGPPPSTATS:
46132 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46133 break;
46134
46135 case SIOCGPPPVER:
46136 - vers = PPP_VERSION;
46137 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46138 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46139 break;
46140 err = 0;
46141 break;
46142 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46143 index 1252d9c..80e660b 100644
46144 --- a/drivers/net/slip/slhc.c
46145 +++ b/drivers/net/slip/slhc.c
46146 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46147 register struct tcphdr *thp;
46148 register struct iphdr *ip;
46149 register struct cstate *cs;
46150 - int len, hdrlen;
46151 + long len, hdrlen;
46152 unsigned char *cp = icp;
46153
46154 /* We've got a compressed packet; read the change byte */
46155 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46156 index b75ae5b..953c157 100644
46157 --- a/drivers/net/team/team.c
46158 +++ b/drivers/net/team/team.c
46159 @@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
46160 return NOTIFY_DONE;
46161 }
46162
46163 -static struct notifier_block team_notifier_block __read_mostly = {
46164 +static struct notifier_block team_notifier_block = {
46165 .notifier_call = team_device_event,
46166 };
46167
46168 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46169 index ecec802..614f08f 100644
46170 --- a/drivers/net/tun.c
46171 +++ b/drivers/net/tun.c
46172 @@ -1839,7 +1839,7 @@ unlock:
46173 }
46174
46175 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46176 - unsigned long arg, int ifreq_len)
46177 + unsigned long arg, size_t ifreq_len)
46178 {
46179 struct tun_file *tfile = file->private_data;
46180 struct tun_struct *tun;
46181 @@ -1852,6 +1852,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46182 unsigned int ifindex;
46183 int ret;
46184
46185 + if (ifreq_len > sizeof ifr)
46186 + return -EFAULT;
46187 +
46188 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46189 if (copy_from_user(&ifr, argp, ifreq_len))
46190 return -EFAULT;
46191 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46192 index 1a48234..a555339 100644
46193 --- a/drivers/net/usb/hso.c
46194 +++ b/drivers/net/usb/hso.c
46195 @@ -71,7 +71,7 @@
46196 #include <asm/byteorder.h>
46197 #include <linux/serial_core.h>
46198 #include <linux/serial.h>
46199 -
46200 +#include <asm/local.h>
46201
46202 #define MOD_AUTHOR "Option Wireless"
46203 #define MOD_DESCRIPTION "USB High Speed Option driver"
46204 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46205 struct urb *urb;
46206
46207 urb = serial->rx_urb[0];
46208 - if (serial->port.count > 0) {
46209 + if (atomic_read(&serial->port.count) > 0) {
46210 count = put_rxbuf_data(urb, serial);
46211 if (count == -1)
46212 return;
46213 @@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46214 DUMP1(urb->transfer_buffer, urb->actual_length);
46215
46216 /* Anyone listening? */
46217 - if (serial->port.count == 0)
46218 + if (atomic_read(&serial->port.count) == 0)
46219 return;
46220
46221 if (status == 0) {
46222 @@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46223 tty_port_tty_set(&serial->port, tty);
46224
46225 /* check for port already opened, if not set the termios */
46226 - serial->port.count++;
46227 - if (serial->port.count == 1) {
46228 + if (atomic_inc_return(&serial->port.count) == 1) {
46229 serial->rx_state = RX_IDLE;
46230 /* Force default termio settings */
46231 _hso_serial_set_termios(tty, NULL);
46232 @@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46233 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46234 if (result) {
46235 hso_stop_serial_device(serial->parent);
46236 - serial->port.count--;
46237 + atomic_dec(&serial->port.count);
46238 kref_put(&serial->parent->ref, hso_serial_ref_free);
46239 }
46240 } else {
46241 @@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46242
46243 /* reset the rts and dtr */
46244 /* do the actual close */
46245 - serial->port.count--;
46246 + atomic_dec(&serial->port.count);
46247
46248 - if (serial->port.count <= 0) {
46249 - serial->port.count = 0;
46250 + if (atomic_read(&serial->port.count) <= 0) {
46251 + atomic_set(&serial->port.count, 0);
46252 tty_port_tty_set(&serial->port, NULL);
46253 if (!usb_gone)
46254 hso_stop_serial_device(serial->parent);
46255 @@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46256
46257 /* the actual setup */
46258 spin_lock_irqsave(&serial->serial_lock, flags);
46259 - if (serial->port.count)
46260 + if (atomic_read(&serial->port.count))
46261 _hso_serial_set_termios(tty, old);
46262 else
46263 tty->termios = *old;
46264 @@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
46265 D1("Pending read interrupt on port %d\n", i);
46266 spin_lock(&serial->serial_lock);
46267 if (serial->rx_state == RX_IDLE &&
46268 - serial->port.count > 0) {
46269 + atomic_read(&serial->port.count) > 0) {
46270 /* Setup and send a ctrl req read on
46271 * port i */
46272 if (!serial->rx_urb_filled[0]) {
46273 @@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
46274 /* Start all serial ports */
46275 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46276 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46277 - if (dev2ser(serial_table[i])->port.count) {
46278 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46279 result =
46280 hso_start_serial_device(serial_table[i], GFP_NOIO);
46281 hso_kick_transmit(dev2ser(serial_table[i]));
46282 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46283 index a79e9d3..78cd4fa 100644
46284 --- a/drivers/net/usb/sierra_net.c
46285 +++ b/drivers/net/usb/sierra_net.c
46286 @@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
46287 /* atomic counter partially included in MAC address to make sure 2 devices
46288 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46289 */
46290 -static atomic_t iface_counter = ATOMIC_INIT(0);
46291 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46292
46293 /*
46294 * SYNC Timer Delay definition used to set the expiry time
46295 @@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46296 dev->net->netdev_ops = &sierra_net_device_ops;
46297
46298 /* change MAC addr to include, ifacenum, and to be unique */
46299 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46300 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46301 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46302
46303 /* we will have to manufacture ethernet headers, prepare template */
46304 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46305 index 0247973..088193a 100644
46306 --- a/drivers/net/vxlan.c
46307 +++ b/drivers/net/vxlan.c
46308 @@ -2615,7 +2615,7 @@ nla_put_failure:
46309 return -EMSGSIZE;
46310 }
46311
46312 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46313 +static struct rtnl_link_ops vxlan_link_ops = {
46314 .kind = "vxlan",
46315 .maxtype = IFLA_VXLAN_MAX,
46316 .policy = vxlan_policy,
46317 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46318 index 5920c99..ff2e4a5 100644
46319 --- a/drivers/net/wan/lmc/lmc_media.c
46320 +++ b/drivers/net/wan/lmc/lmc_media.c
46321 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46322 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46323
46324 lmc_media_t lmc_ds3_media = {
46325 - lmc_ds3_init, /* special media init stuff */
46326 - lmc_ds3_default, /* reset to default state */
46327 - lmc_ds3_set_status, /* reset status to state provided */
46328 - lmc_dummy_set_1, /* set clock source */
46329 - lmc_dummy_set2_1, /* set line speed */
46330 - lmc_ds3_set_100ft, /* set cable length */
46331 - lmc_ds3_set_scram, /* set scrambler */
46332 - lmc_ds3_get_link_status, /* get link status */
46333 - lmc_dummy_set_1, /* set link status */
46334 - lmc_ds3_set_crc_length, /* set CRC length */
46335 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46336 - lmc_ds3_watchdog
46337 + .init = lmc_ds3_init, /* special media init stuff */
46338 + .defaults = lmc_ds3_default, /* reset to default state */
46339 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46340 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46341 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46342 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46343 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46344 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46345 + .set_link_status = lmc_dummy_set_1, /* set link status */
46346 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46347 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46348 + .watchdog = lmc_ds3_watchdog
46349 };
46350
46351 lmc_media_t lmc_hssi_media = {
46352 - lmc_hssi_init, /* special media init stuff */
46353 - lmc_hssi_default, /* reset to default state */
46354 - lmc_hssi_set_status, /* reset status to state provided */
46355 - lmc_hssi_set_clock, /* set clock source */
46356 - lmc_dummy_set2_1, /* set line speed */
46357 - lmc_dummy_set_1, /* set cable length */
46358 - lmc_dummy_set_1, /* set scrambler */
46359 - lmc_hssi_get_link_status, /* get link status */
46360 - lmc_hssi_set_link_status, /* set link status */
46361 - lmc_hssi_set_crc_length, /* set CRC length */
46362 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46363 - lmc_hssi_watchdog
46364 + .init = lmc_hssi_init, /* special media init stuff */
46365 + .defaults = lmc_hssi_default, /* reset to default state */
46366 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46367 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46368 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46369 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46370 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46371 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46372 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46373 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46374 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46375 + .watchdog = lmc_hssi_watchdog
46376 };
46377
46378 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46379 - lmc_ssi_default, /* reset to default state */
46380 - lmc_ssi_set_status, /* reset status to state provided */
46381 - lmc_ssi_set_clock, /* set clock source */
46382 - lmc_ssi_set_speed, /* set line speed */
46383 - lmc_dummy_set_1, /* set cable length */
46384 - lmc_dummy_set_1, /* set scrambler */
46385 - lmc_ssi_get_link_status, /* get link status */
46386 - lmc_ssi_set_link_status, /* set link status */
46387 - lmc_ssi_set_crc_length, /* set CRC length */
46388 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46389 - lmc_ssi_watchdog
46390 +lmc_media_t lmc_ssi_media = {
46391 + .init = lmc_ssi_init, /* special media init stuff */
46392 + .defaults = lmc_ssi_default, /* reset to default state */
46393 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46394 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46395 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46396 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46397 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46398 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46399 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46400 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46401 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46402 + .watchdog = lmc_ssi_watchdog
46403 };
46404
46405 lmc_media_t lmc_t1_media = {
46406 - lmc_t1_init, /* special media init stuff */
46407 - lmc_t1_default, /* reset to default state */
46408 - lmc_t1_set_status, /* reset status to state provided */
46409 - lmc_t1_set_clock, /* set clock source */
46410 - lmc_dummy_set2_1, /* set line speed */
46411 - lmc_dummy_set_1, /* set cable length */
46412 - lmc_dummy_set_1, /* set scrambler */
46413 - lmc_t1_get_link_status, /* get link status */
46414 - lmc_dummy_set_1, /* set link status */
46415 - lmc_t1_set_crc_length, /* set CRC length */
46416 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46417 - lmc_t1_watchdog
46418 + .init = lmc_t1_init, /* special media init stuff */
46419 + .defaults = lmc_t1_default, /* reset to default state */
46420 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46421 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46422 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46423 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46424 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46425 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46426 + .set_link_status = lmc_dummy_set_1, /* set link status */
46427 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46428 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46429 + .watchdog = lmc_t1_watchdog
46430 };
46431
46432 static void
46433 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46434 index feacc3b..5bac0de 100644
46435 --- a/drivers/net/wan/z85230.c
46436 +++ b/drivers/net/wan/z85230.c
46437 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46438
46439 struct z8530_irqhandler z8530_sync =
46440 {
46441 - z8530_rx,
46442 - z8530_tx,
46443 - z8530_status
46444 + .rx = z8530_rx,
46445 + .tx = z8530_tx,
46446 + .status = z8530_status
46447 };
46448
46449 EXPORT_SYMBOL(z8530_sync);
46450 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46451 }
46452
46453 static struct z8530_irqhandler z8530_dma_sync = {
46454 - z8530_dma_rx,
46455 - z8530_dma_tx,
46456 - z8530_dma_status
46457 + .rx = z8530_dma_rx,
46458 + .tx = z8530_dma_tx,
46459 + .status = z8530_dma_status
46460 };
46461
46462 static struct z8530_irqhandler z8530_txdma_sync = {
46463 - z8530_rx,
46464 - z8530_dma_tx,
46465 - z8530_dma_status
46466 + .rx = z8530_rx,
46467 + .tx = z8530_dma_tx,
46468 + .status = z8530_dma_status
46469 };
46470
46471 /**
46472 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46473
46474 struct z8530_irqhandler z8530_nop=
46475 {
46476 - z8530_rx_clear,
46477 - z8530_tx_clear,
46478 - z8530_status_clear
46479 + .rx = z8530_rx_clear,
46480 + .tx = z8530_tx_clear,
46481 + .status = z8530_status_clear
46482 };
46483
46484
46485 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46486 index 0b60295..b8bfa5b 100644
46487 --- a/drivers/net/wimax/i2400m/rx.c
46488 +++ b/drivers/net/wimax/i2400m/rx.c
46489 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46490 if (i2400m->rx_roq == NULL)
46491 goto error_roq_alloc;
46492
46493 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46494 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46495 GFP_KERNEL);
46496 if (rd == NULL) {
46497 result = -ENOMEM;
46498 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46499 index edf4b57..68b51c0 100644
46500 --- a/drivers/net/wireless/airo.c
46501 +++ b/drivers/net/wireless/airo.c
46502 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46503 struct airo_info *ai = dev->ml_priv;
46504 int ridcode;
46505 int enabled;
46506 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46507 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46508 unsigned char *iobuf;
46509
46510 /* Only super-user can write RIDs */
46511 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46512 index 34c8a33..3261fdc 100644
46513 --- a/drivers/net/wireless/at76c50x-usb.c
46514 +++ b/drivers/net/wireless/at76c50x-usb.c
46515 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46516 }
46517
46518 /* Convert timeout from the DFU status to jiffies */
46519 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
46520 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46521 {
46522 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46523 | (s->poll_timeout[1] << 8)
46524 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46525 index edae50b..b24278c 100644
46526 --- a/drivers/net/wireless/ath/ath10k/htc.c
46527 +++ b/drivers/net/wireless/ath/ath10k/htc.c
46528 @@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46529 /* registered target arrival callback from the HIF layer */
46530 int ath10k_htc_init(struct ath10k *ar)
46531 {
46532 - struct ath10k_hif_cb htc_callbacks;
46533 + static struct ath10k_hif_cb htc_callbacks = {
46534 + .rx_completion = ath10k_htc_rx_completion_handler,
46535 + .tx_completion = ath10k_htc_tx_completion_handler,
46536 + };
46537 struct ath10k_htc_ep *ep = NULL;
46538 struct ath10k_htc *htc = &ar->htc;
46539
46540 @@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
46541 ath10k_htc_reset_endpoint_states(htc);
46542
46543 /* setup HIF layer callbacks */
46544 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46545 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46546 htc->ar = ar;
46547
46548 /* Get HIF default pipe for HTC message exchange */
46549 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46550 index 4716d33..a688310 100644
46551 --- a/drivers/net/wireless/ath/ath10k/htc.h
46552 +++ b/drivers/net/wireless/ath/ath10k/htc.h
46553 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46554
46555 struct ath10k_htc_ops {
46556 void (*target_send_suspend_complete)(struct ath10k *ar);
46557 -};
46558 +} __no_const;
46559
46560 struct ath10k_htc_ep_ops {
46561 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46562 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46563 void (*ep_tx_credits)(struct ath10k *);
46564 -};
46565 +} __no_const;
46566
46567 /* service connection information */
46568 struct ath10k_htc_svc_conn_req {
46569 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46570 index a366d6b..b6f28f8 100644
46571 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46572 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46573 @@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46574 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46575 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46576
46577 - ACCESS_ONCE(ads->ds_link) = i->link;
46578 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46579 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
46580 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46581
46582 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46583 ctl6 = SM(i->keytype, AR_EncrType);
46584 @@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46585
46586 if ((i->is_first || i->is_last) &&
46587 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46588 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46589 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46590 | set11nTries(i->rates, 1)
46591 | set11nTries(i->rates, 2)
46592 | set11nTries(i->rates, 3)
46593 | (i->dur_update ? AR_DurUpdateEna : 0)
46594 | SM(0, AR_BurstDur);
46595
46596 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46597 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46598 | set11nRate(i->rates, 1)
46599 | set11nRate(i->rates, 2)
46600 | set11nRate(i->rates, 3);
46601 } else {
46602 - ACCESS_ONCE(ads->ds_ctl2) = 0;
46603 - ACCESS_ONCE(ads->ds_ctl3) = 0;
46604 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46605 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46606 }
46607
46608 if (!i->is_first) {
46609 - ACCESS_ONCE(ads->ds_ctl0) = 0;
46610 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46611 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46612 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46613 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46614 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46615 return;
46616 }
46617
46618 @@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46619 break;
46620 }
46621
46622 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46623 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46624 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46625 | SM(i->txpower, AR_XmitPower)
46626 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46627 @@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46628 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46629 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46630
46631 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46632 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46633 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46634 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46635
46636 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46637 return;
46638
46639 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46640 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46641 | set11nPktDurRTSCTS(i->rates, 1);
46642
46643 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46644 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46645 | set11nPktDurRTSCTS(i->rates, 3);
46646
46647 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46648 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46649 | set11nRateFlags(i->rates, 1)
46650 | set11nRateFlags(i->rates, 2)
46651 | set11nRateFlags(i->rates, 3)
46652 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46653 index f6c5c1b..6058354 100644
46654 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46655 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46656 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46657 (i->qcu << AR_TxQcuNum_S) | desc_len;
46658
46659 checksum += val;
46660 - ACCESS_ONCE(ads->info) = val;
46661 + ACCESS_ONCE_RW(ads->info) = val;
46662
46663 checksum += i->link;
46664 - ACCESS_ONCE(ads->link) = i->link;
46665 + ACCESS_ONCE_RW(ads->link) = i->link;
46666
46667 checksum += i->buf_addr[0];
46668 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46669 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46670 checksum += i->buf_addr[1];
46671 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46672 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46673 checksum += i->buf_addr[2];
46674 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46675 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46676 checksum += i->buf_addr[3];
46677 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46678 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46679
46680 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46681 - ACCESS_ONCE(ads->ctl3) = val;
46682 + ACCESS_ONCE_RW(ads->ctl3) = val;
46683 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46684 - ACCESS_ONCE(ads->ctl5) = val;
46685 + ACCESS_ONCE_RW(ads->ctl5) = val;
46686 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46687 - ACCESS_ONCE(ads->ctl7) = val;
46688 + ACCESS_ONCE_RW(ads->ctl7) = val;
46689 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46690 - ACCESS_ONCE(ads->ctl9) = val;
46691 + ACCESS_ONCE_RW(ads->ctl9) = val;
46692
46693 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46694 - ACCESS_ONCE(ads->ctl10) = checksum;
46695 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46696
46697 if (i->is_first || i->is_last) {
46698 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46699 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46700 | set11nTries(i->rates, 1)
46701 | set11nTries(i->rates, 2)
46702 | set11nTries(i->rates, 3)
46703 | (i->dur_update ? AR_DurUpdateEna : 0)
46704 | SM(0, AR_BurstDur);
46705
46706 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46707 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46708 | set11nRate(i->rates, 1)
46709 | set11nRate(i->rates, 2)
46710 | set11nRate(i->rates, 3);
46711 } else {
46712 - ACCESS_ONCE(ads->ctl13) = 0;
46713 - ACCESS_ONCE(ads->ctl14) = 0;
46714 + ACCESS_ONCE_RW(ads->ctl13) = 0;
46715 + ACCESS_ONCE_RW(ads->ctl14) = 0;
46716 }
46717
46718 ads->ctl20 = 0;
46719 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46720
46721 ctl17 = SM(i->keytype, AR_EncrType);
46722 if (!i->is_first) {
46723 - ACCESS_ONCE(ads->ctl11) = 0;
46724 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46725 - ACCESS_ONCE(ads->ctl15) = 0;
46726 - ACCESS_ONCE(ads->ctl16) = 0;
46727 - ACCESS_ONCE(ads->ctl17) = ctl17;
46728 - ACCESS_ONCE(ads->ctl18) = 0;
46729 - ACCESS_ONCE(ads->ctl19) = 0;
46730 + ACCESS_ONCE_RW(ads->ctl11) = 0;
46731 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46732 + ACCESS_ONCE_RW(ads->ctl15) = 0;
46733 + ACCESS_ONCE_RW(ads->ctl16) = 0;
46734 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46735 + ACCESS_ONCE_RW(ads->ctl18) = 0;
46736 + ACCESS_ONCE_RW(ads->ctl19) = 0;
46737 return;
46738 }
46739
46740 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46741 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46742 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46743 | SM(i->txpower, AR_XmitPower)
46744 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46745 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46746 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46747 ctl12 |= SM(val, AR_PAPRDChainMask);
46748
46749 - ACCESS_ONCE(ads->ctl12) = ctl12;
46750 - ACCESS_ONCE(ads->ctl17) = ctl17;
46751 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46752 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46753
46754 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46755 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46756 | set11nPktDurRTSCTS(i->rates, 1);
46757
46758 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46759 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46760 | set11nPktDurRTSCTS(i->rates, 3);
46761
46762 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46763 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46764 | set11nRateFlags(i->rates, 1)
46765 | set11nRateFlags(i->rates, 2)
46766 | set11nRateFlags(i->rates, 3)
46767 | SM(i->rtscts_rate, AR_RTSCTSRate);
46768
46769 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46770 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46771 }
46772
46773 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46774 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46775 index a2c9a5d..b52273e 100644
46776 --- a/drivers/net/wireless/ath/ath9k/hw.h
46777 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46778 @@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46779
46780 /* ANI */
46781 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46782 -};
46783 +} __no_const;
46784
46785 /**
46786 * struct ath_spec_scan - parameters for Atheros spectral scan
46787 @@ -711,7 +711,7 @@ struct ath_hw_ops {
46788 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46789 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46790 #endif
46791 -};
46792 +} __no_const;
46793
46794 struct ath_nf_limits {
46795 s16 max;
46796 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46797 index 92190da..f3a4c4c 100644
46798 --- a/drivers/net/wireless/b43/phy_lp.c
46799 +++ b/drivers/net/wireless/b43/phy_lp.c
46800 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46801 {
46802 struct ssb_bus *bus = dev->dev->sdev->bus;
46803
46804 - static const struct b206x_channel *chandata = NULL;
46805 + const struct b206x_channel *chandata = NULL;
46806 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46807 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46808 u16 old_comm15, scale;
46809 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46810 index dea3b50..543db99 100644
46811 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46812 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46813 @@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46814 */
46815 if (il3945_mod_params.disable_hw_scan) {
46816 D_INFO("Disabling hw_scan\n");
46817 - il3945_mac_ops.hw_scan = NULL;
46818 + pax_open_kernel();
46819 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46820 + pax_close_kernel();
46821 }
46822
46823 D_INFO("*** LOAD DRIVER ***\n");
46824 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46825 index d94f8ab..5b568c8 100644
46826 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46827 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46828 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46829 {
46830 struct iwl_priv *priv = file->private_data;
46831 char buf[64];
46832 - int buf_size;
46833 + size_t buf_size;
46834 u32 offset, len;
46835
46836 memset(buf, 0, sizeof(buf));
46837 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46838 struct iwl_priv *priv = file->private_data;
46839
46840 char buf[8];
46841 - int buf_size;
46842 + size_t buf_size;
46843 u32 reset_flag;
46844
46845 memset(buf, 0, sizeof(buf));
46846 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46847 {
46848 struct iwl_priv *priv = file->private_data;
46849 char buf[8];
46850 - int buf_size;
46851 + size_t buf_size;
46852 int ht40;
46853
46854 memset(buf, 0, sizeof(buf));
46855 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46856 {
46857 struct iwl_priv *priv = file->private_data;
46858 char buf[8];
46859 - int buf_size;
46860 + size_t buf_size;
46861 int value;
46862
46863 memset(buf, 0, sizeof(buf));
46864 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46865 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46866 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46867
46868 -static const char *fmt_value = " %-30s %10u\n";
46869 -static const char *fmt_hex = " %-30s 0x%02X\n";
46870 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46871 -static const char *fmt_header =
46872 +static const char fmt_value[] = " %-30s %10u\n";
46873 +static const char fmt_hex[] = " %-30s 0x%02X\n";
46874 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46875 +static const char fmt_header[] =
46876 "%-32s current cumulative delta max\n";
46877
46878 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46879 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46880 {
46881 struct iwl_priv *priv = file->private_data;
46882 char buf[8];
46883 - int buf_size;
46884 + size_t buf_size;
46885 int clear;
46886
46887 memset(buf, 0, sizeof(buf));
46888 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46889 {
46890 struct iwl_priv *priv = file->private_data;
46891 char buf[8];
46892 - int buf_size;
46893 + size_t buf_size;
46894 int trace;
46895
46896 memset(buf, 0, sizeof(buf));
46897 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46898 {
46899 struct iwl_priv *priv = file->private_data;
46900 char buf[8];
46901 - int buf_size;
46902 + size_t buf_size;
46903 int missed;
46904
46905 memset(buf, 0, sizeof(buf));
46906 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46907
46908 struct iwl_priv *priv = file->private_data;
46909 char buf[8];
46910 - int buf_size;
46911 + size_t buf_size;
46912 int plcp;
46913
46914 memset(buf, 0, sizeof(buf));
46915 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46916
46917 struct iwl_priv *priv = file->private_data;
46918 char buf[8];
46919 - int buf_size;
46920 + size_t buf_size;
46921 int flush;
46922
46923 memset(buf, 0, sizeof(buf));
46924 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46925
46926 struct iwl_priv *priv = file->private_data;
46927 char buf[8];
46928 - int buf_size;
46929 + size_t buf_size;
46930 int rts;
46931
46932 if (!priv->cfg->ht_params)
46933 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46934 {
46935 struct iwl_priv *priv = file->private_data;
46936 char buf[8];
46937 - int buf_size;
46938 + size_t buf_size;
46939
46940 memset(buf, 0, sizeof(buf));
46941 buf_size = min(count, sizeof(buf) - 1);
46942 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46943 struct iwl_priv *priv = file->private_data;
46944 u32 event_log_flag;
46945 char buf[8];
46946 - int buf_size;
46947 + size_t buf_size;
46948
46949 /* check that the interface is up */
46950 if (!iwl_is_ready(priv))
46951 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46952 struct iwl_priv *priv = file->private_data;
46953 char buf[8];
46954 u32 calib_disabled;
46955 - int buf_size;
46956 + size_t buf_size;
46957
46958 memset(buf, 0, sizeof(buf));
46959 buf_size = min(count, sizeof(buf) - 1);
46960 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46961 index 7aad766..06addb4 100644
46962 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
46963 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46964 @@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46965 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46966 {
46967 struct iwl_nvm_data *data = priv->nvm_data;
46968 - char *debug_msg;
46969 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46970
46971 if (data->sku_cap_11n_enable &&
46972 !priv->cfg->ht_params) {
46973 @@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46974 return -EINVAL;
46975 }
46976
46977 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46978 IWL_DEBUG_INFO(priv, debug_msg,
46979 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
46980 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
46981 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
46982 index f53ef83..5e34bcb 100644
46983 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
46984 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
46985 @@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
46986 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
46987
46988 char buf[8];
46989 - int buf_size;
46990 + size_t buf_size;
46991 u32 reset_flag;
46992
46993 memset(buf, 0, sizeof(buf));
46994 @@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
46995 {
46996 struct iwl_trans *trans = file->private_data;
46997 char buf[8];
46998 - int buf_size;
46999 + size_t buf_size;
47000 int csr;
47001
47002 memset(buf, 0, sizeof(buf));
47003 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47004 index a1b32ee..94b3c3d 100644
47005 --- a/drivers/net/wireless/mac80211_hwsim.c
47006 +++ b/drivers/net/wireless/mac80211_hwsim.c
47007 @@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
47008
47009 if (channels > 1) {
47010 hwsim_if_comb.num_different_channels = channels;
47011 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47012 - mac80211_hwsim_ops.cancel_hw_scan =
47013 - mac80211_hwsim_cancel_hw_scan;
47014 - mac80211_hwsim_ops.sw_scan_start = NULL;
47015 - mac80211_hwsim_ops.sw_scan_complete = NULL;
47016 - mac80211_hwsim_ops.remain_on_channel =
47017 - mac80211_hwsim_roc;
47018 - mac80211_hwsim_ops.cancel_remain_on_channel =
47019 - mac80211_hwsim_croc;
47020 - mac80211_hwsim_ops.add_chanctx =
47021 - mac80211_hwsim_add_chanctx;
47022 - mac80211_hwsim_ops.remove_chanctx =
47023 - mac80211_hwsim_remove_chanctx;
47024 - mac80211_hwsim_ops.change_chanctx =
47025 - mac80211_hwsim_change_chanctx;
47026 - mac80211_hwsim_ops.assign_vif_chanctx =
47027 - mac80211_hwsim_assign_vif_chanctx;
47028 - mac80211_hwsim_ops.unassign_vif_chanctx =
47029 - mac80211_hwsim_unassign_vif_chanctx;
47030 + pax_open_kernel();
47031 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47032 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47033 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
47034 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
47035 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
47036 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47037 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47038 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47039 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47040 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47041 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47042 + pax_close_kernel();
47043 }
47044
47045 spin_lock_init(&hwsim_radio_lock);
47046 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47047 index 8169a85..7fa3b47 100644
47048 --- a/drivers/net/wireless/rndis_wlan.c
47049 +++ b/drivers/net/wireless/rndis_wlan.c
47050 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47051
47052 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47053
47054 - if (rts_threshold < 0 || rts_threshold > 2347)
47055 + if (rts_threshold > 2347)
47056 rts_threshold = 2347;
47057
47058 tmp = cpu_to_le32(rts_threshold);
47059 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47060 index e4ba2ce..63d7417 100644
47061 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47062 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47063 @@ -377,7 +377,7 @@ struct rt2x00_intf {
47064 * for hardware which doesn't support hardware
47065 * sequence counting.
47066 */
47067 - atomic_t seqno;
47068 + atomic_unchecked_t seqno;
47069 };
47070
47071 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47072 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47073 index a5d38e8..d3c24ea 100644
47074 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47075 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47076 @@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47077 * sequence counter given by mac80211.
47078 */
47079 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47080 - seqno = atomic_add_return(0x10, &intf->seqno);
47081 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47082 else
47083 - seqno = atomic_read(&intf->seqno);
47084 + seqno = atomic_read_unchecked(&intf->seqno);
47085
47086 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47087 hdr->seq_ctrl |= cpu_to_le16(seqno);
47088 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47089 index e2b3d9c..67a5184 100644
47090 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47091 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47092 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47093
47094 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47095
47096 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47097 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47098 + pax_open_kernel();
47099 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47100 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47101 + pax_close_kernel();
47102
47103 wl1251_info("using dedicated interrupt line");
47104 } else {
47105 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47106 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47107 + pax_open_kernel();
47108 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47109 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47110 + pax_close_kernel();
47111
47112 wl1251_info("using SDIO interrupt");
47113 }
47114 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47115 index be7129b..4161356 100644
47116 --- a/drivers/net/wireless/ti/wl12xx/main.c
47117 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47118 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47119 sizeof(wl->conf.mem));
47120
47121 /* read data preparation is only needed by wl127x */
47122 - wl->ops->prepare_read = wl127x_prepare_read;
47123 + pax_open_kernel();
47124 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47125 + pax_close_kernel();
47126
47127 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47128 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47129 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47130 sizeof(wl->conf.mem));
47131
47132 /* read data preparation is only needed by wl127x */
47133 - wl->ops->prepare_read = wl127x_prepare_read;
47134 + pax_open_kernel();
47135 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47136 + pax_close_kernel();
47137
47138 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47139 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47140 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47141 index ec37b16..7e34d66 100644
47142 --- a/drivers/net/wireless/ti/wl18xx/main.c
47143 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47144 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47145 }
47146
47147 if (!checksum_param) {
47148 - wl18xx_ops.set_rx_csum = NULL;
47149 - wl18xx_ops.init_vif = NULL;
47150 + pax_open_kernel();
47151 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47152 + *(void **)&wl18xx_ops.init_vif = NULL;
47153 + pax_close_kernel();
47154 }
47155
47156 /* Enable 11a Band only if we have 5G antennas */
47157 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47158 index 84d94f5..bd6c61c 100644
47159 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47160 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47161 @@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
47162 {
47163 struct zd_usb *usb = urb->context;
47164 struct zd_usb_interrupt *intr = &usb->intr;
47165 - int len;
47166 + unsigned int len;
47167 u16 int_num;
47168
47169 ZD_ASSERT(in_interrupt());
47170 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47171 index 7130864..00e64de 100644
47172 --- a/drivers/nfc/nfcwilink.c
47173 +++ b/drivers/nfc/nfcwilink.c
47174 @@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
47175
47176 static int nfcwilink_probe(struct platform_device *pdev)
47177 {
47178 - static struct nfcwilink *drv;
47179 + struct nfcwilink *drv;
47180 int rc;
47181 __u32 protocols;
47182
47183 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47184 index d93b2b6..ae50401 100644
47185 --- a/drivers/oprofile/buffer_sync.c
47186 +++ b/drivers/oprofile/buffer_sync.c
47187 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47188 if (cookie == NO_COOKIE)
47189 offset = pc;
47190 if (cookie == INVALID_COOKIE) {
47191 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47192 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47193 offset = pc;
47194 }
47195 if (cookie != last_cookie) {
47196 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47197 /* add userspace sample */
47198
47199 if (!mm) {
47200 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47201 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47202 return 0;
47203 }
47204
47205 cookie = lookup_dcookie(mm, s->eip, &offset);
47206
47207 if (cookie == INVALID_COOKIE) {
47208 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47209 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47210 return 0;
47211 }
47212
47213 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47214 /* ignore backtraces if failed to add a sample */
47215 if (state == sb_bt_start) {
47216 state = sb_bt_ignore;
47217 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47218 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47219 }
47220 }
47221 release_mm(mm);
47222 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47223 index c0cc4e7..44d4e54 100644
47224 --- a/drivers/oprofile/event_buffer.c
47225 +++ b/drivers/oprofile/event_buffer.c
47226 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47227 }
47228
47229 if (buffer_pos == buffer_size) {
47230 - atomic_inc(&oprofile_stats.event_lost_overflow);
47231 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47232 return;
47233 }
47234
47235 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47236 index ed2c3ec..deda85a 100644
47237 --- a/drivers/oprofile/oprof.c
47238 +++ b/drivers/oprofile/oprof.c
47239 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47240 if (oprofile_ops.switch_events())
47241 return;
47242
47243 - atomic_inc(&oprofile_stats.multiplex_counter);
47244 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47245 start_switch_worker();
47246 }
47247
47248 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47249 index ee2cfce..7f8f699 100644
47250 --- a/drivers/oprofile/oprofile_files.c
47251 +++ b/drivers/oprofile/oprofile_files.c
47252 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47253
47254 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47255
47256 -static ssize_t timeout_read(struct file *file, char __user *buf,
47257 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47258 size_t count, loff_t *offset)
47259 {
47260 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47261 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47262 index 59659ce..6c860a0 100644
47263 --- a/drivers/oprofile/oprofile_stats.c
47264 +++ b/drivers/oprofile/oprofile_stats.c
47265 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47266 cpu_buf->sample_invalid_eip = 0;
47267 }
47268
47269 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47270 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47271 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47272 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47273 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47274 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47275 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47276 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47277 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47278 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47279 }
47280
47281
47282 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47283 index 1fc622b..8c48fc3 100644
47284 --- a/drivers/oprofile/oprofile_stats.h
47285 +++ b/drivers/oprofile/oprofile_stats.h
47286 @@ -13,11 +13,11 @@
47287 #include <linux/atomic.h>
47288
47289 struct oprofile_stat_struct {
47290 - atomic_t sample_lost_no_mm;
47291 - atomic_t sample_lost_no_mapping;
47292 - atomic_t bt_lost_no_mapping;
47293 - atomic_t event_lost_overflow;
47294 - atomic_t multiplex_counter;
47295 + atomic_unchecked_t sample_lost_no_mm;
47296 + atomic_unchecked_t sample_lost_no_mapping;
47297 + atomic_unchecked_t bt_lost_no_mapping;
47298 + atomic_unchecked_t event_lost_overflow;
47299 + atomic_unchecked_t multiplex_counter;
47300 };
47301
47302 extern struct oprofile_stat_struct oprofile_stats;
47303 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47304 index 3f49345..c750d0b 100644
47305 --- a/drivers/oprofile/oprofilefs.c
47306 +++ b/drivers/oprofile/oprofilefs.c
47307 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47308
47309 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47310 {
47311 - atomic_t *val = file->private_data;
47312 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47313 + atomic_unchecked_t *val = file->private_data;
47314 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47315 }
47316
47317
47318 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47319
47320
47321 int oprofilefs_create_ro_atomic(struct dentry *root,
47322 - char const *name, atomic_t *val)
47323 + char const *name, atomic_unchecked_t *val)
47324 {
47325 return __oprofilefs_create_file(root, name,
47326 &atomic_ro_fops, 0444, val);
47327 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47328 index 61be1d9..dec05d7 100644
47329 --- a/drivers/oprofile/timer_int.c
47330 +++ b/drivers/oprofile/timer_int.c
47331 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47332 return NOTIFY_OK;
47333 }
47334
47335 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47336 +static struct notifier_block oprofile_cpu_notifier = {
47337 .notifier_call = oprofile_cpu_notify,
47338 };
47339
47340 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47341 index 92ed045..62d39bd7 100644
47342 --- a/drivers/parport/procfs.c
47343 +++ b/drivers/parport/procfs.c
47344 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47345
47346 *ppos += len;
47347
47348 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47349 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47350 }
47351
47352 #ifdef CONFIG_PARPORT_1284
47353 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47354
47355 *ppos += len;
47356
47357 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47358 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47359 }
47360 #endif /* IEEE1284.3 support. */
47361
47362 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47363 index ecfac7e..41be7028 100644
47364 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47365 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47366 @@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
47367 goto init_cleanup;
47368 }
47369
47370 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47371 + pax_open_kernel();
47372 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47373 + pax_close_kernel();
47374 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47375
47376 return retval;
47377 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47378 index 7536eef..52dc8fa 100644
47379 --- a/drivers/pci/hotplug/cpcihp_generic.c
47380 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47381 @@ -73,7 +73,6 @@ static u16 port;
47382 static unsigned int enum_bit;
47383 static u8 enum_mask;
47384
47385 -static struct cpci_hp_controller_ops generic_hpc_ops;
47386 static struct cpci_hp_controller generic_hpc;
47387
47388 static int __init validate_parameters(void)
47389 @@ -139,6 +138,10 @@ static int query_enum(void)
47390 return ((value & enum_mask) == enum_mask);
47391 }
47392
47393 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47394 + .query_enum = query_enum,
47395 +};
47396 +
47397 static int __init cpcihp_generic_init(void)
47398 {
47399 int status;
47400 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47401 pci_dev_put(dev);
47402
47403 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47404 - generic_hpc_ops.query_enum = query_enum;
47405 generic_hpc.ops = &generic_hpc_ops;
47406
47407 status = cpci_hp_register_controller(&generic_hpc);
47408 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47409 index e8c4a7c..7046f5c 100644
47410 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47411 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47412 @@ -59,7 +59,6 @@
47413 /* local variables */
47414 static bool debug;
47415 static bool poll;
47416 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47417 static struct cpci_hp_controller zt5550_hpc;
47418
47419 /* Primary cPCI bus bridge device */
47420 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47421 return 0;
47422 }
47423
47424 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47425 + .query_enum = zt5550_hc_query_enum,
47426 +};
47427 +
47428 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47429 {
47430 int status;
47431 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47432 dbg("returned from zt5550_hc_config");
47433
47434 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47435 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47436 zt5550_hpc.ops = &zt5550_hpc_ops;
47437 if(!poll) {
47438 zt5550_hpc.irq = hc_dev->irq;
47439 zt5550_hpc.irq_flags = IRQF_SHARED;
47440 zt5550_hpc.dev_id = hc_dev;
47441
47442 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47443 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47444 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47445 + pax_open_kernel();
47446 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47447 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47448 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47449 + pax_open_kernel();
47450 } else {
47451 info("using ENUM# polling mode");
47452 }
47453 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47454 index 76ba8a1..20ca857 100644
47455 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47456 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47457 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47458
47459 void compaq_nvram_init (void __iomem *rom_start)
47460 {
47461 +
47462 +#ifndef CONFIG_PAX_KERNEXEC
47463 if (rom_start) {
47464 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47465 }
47466 +#endif
47467 +
47468 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47469
47470 /* initialize our int15 lock */
47471 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47472 index cfa92a9..29539c5 100644
47473 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47474 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47475 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47476 return -EINVAL;
47477 }
47478
47479 - slot->ops->owner = owner;
47480 - slot->ops->mod_name = mod_name;
47481 + pax_open_kernel();
47482 + *(struct module **)&slot->ops->owner = owner;
47483 + *(const char **)&slot->ops->mod_name = mod_name;
47484 + pax_close_kernel();
47485
47486 mutex_lock(&pci_hp_mutex);
47487 /*
47488 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47489 index bbd48bb..6907ef4 100644
47490 --- a/drivers/pci/hotplug/pciehp_core.c
47491 +++ b/drivers/pci/hotplug/pciehp_core.c
47492 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47493 struct slot *slot = ctrl->slot;
47494 struct hotplug_slot *hotplug = NULL;
47495 struct hotplug_slot_info *info = NULL;
47496 - struct hotplug_slot_ops *ops = NULL;
47497 + hotplug_slot_ops_no_const *ops = NULL;
47498 char name[SLOT_NAME_SIZE];
47499 int retval = -ENOMEM;
47500
47501 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47502 index c91e6c1..5c723ef 100644
47503 --- a/drivers/pci/pci-sysfs.c
47504 +++ b/drivers/pci/pci-sysfs.c
47505 @@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47506 {
47507 /* allocate attribute structure, piggyback attribute name */
47508 int name_len = write_combine ? 13 : 10;
47509 - struct bin_attribute *res_attr;
47510 + bin_attribute_no_const *res_attr;
47511 int retval;
47512
47513 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47514 @@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47515 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47516 {
47517 int retval;
47518 - struct bin_attribute *attr;
47519 + bin_attribute_no_const *attr;
47520
47521 /* If the device has VPD, try to expose it in sysfs. */
47522 if (dev->vpd) {
47523 @@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47524 {
47525 int retval;
47526 int rom_size = 0;
47527 - struct bin_attribute *attr;
47528 + bin_attribute_no_const *attr;
47529
47530 if (!sysfs_initialized)
47531 return -EACCES;
47532 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47533 index 9c91ecc..bda4796 100644
47534 --- a/drivers/pci/pci.h
47535 +++ b/drivers/pci/pci.h
47536 @@ -95,7 +95,7 @@ struct pci_vpd_ops {
47537 struct pci_vpd {
47538 unsigned int len;
47539 const struct pci_vpd_ops *ops;
47540 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47541 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47542 };
47543
47544 int pci_vpd_pci22_init(struct pci_dev *dev);
47545 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47546 index f1272dc..e92a1ac 100644
47547 --- a/drivers/pci/pcie/aspm.c
47548 +++ b/drivers/pci/pcie/aspm.c
47549 @@ -27,9 +27,9 @@
47550 #define MODULE_PARAM_PREFIX "pcie_aspm."
47551
47552 /* Note: those are not register definitions */
47553 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47554 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47555 -#define ASPM_STATE_L1 (4) /* L1 state */
47556 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47557 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47558 +#define ASPM_STATE_L1 (4U) /* L1 state */
47559 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47560 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47561
47562 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47563 index 38e403d..a2ce55a 100644
47564 --- a/drivers/pci/probe.c
47565 +++ b/drivers/pci/probe.c
47566 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47567 struct pci_bus_region region, inverted_region;
47568 bool bar_too_big = false, bar_disabled = false;
47569
47570 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47571 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47572
47573 /* No printks while decoding is disabled! */
47574 if (!dev->mmio_always_on) {
47575 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47576 index 46d1378..30e452b 100644
47577 --- a/drivers/pci/proc.c
47578 +++ b/drivers/pci/proc.c
47579 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47580 static int __init pci_proc_init(void)
47581 {
47582 struct pci_dev *dev = NULL;
47583 +
47584 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47585 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47586 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47587 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47588 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47589 +#endif
47590 +#else
47591 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47592 +#endif
47593 proc_create("devices", 0, proc_bus_pci_dir,
47594 &proc_bus_pci_dev_operations);
47595 proc_initialized = 1;
47596 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47597 index 3e5b4497..dcdfb70 100644
47598 --- a/drivers/platform/chrome/chromeos_laptop.c
47599 +++ b/drivers/platform/chrome/chromeos_laptop.c
47600 @@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
47601 return 0;
47602 }
47603
47604 -static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
47605 +static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
47606 {
47607 .ident = "Samsung Series 5 550 - Touchpad",
47608 .matches = {
47609 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47610 index 19c313b..ed28b38 100644
47611 --- a/drivers/platform/x86/asus-wmi.c
47612 +++ b/drivers/platform/x86/asus-wmi.c
47613 @@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
47614 int err;
47615 u32 retval = -1;
47616
47617 +#ifdef CONFIG_GRKERNSEC_KMEM
47618 + return -EPERM;
47619 +#endif
47620 +
47621 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47622
47623 if (err < 0)
47624 @@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
47625 int err;
47626 u32 retval = -1;
47627
47628 +#ifdef CONFIG_GRKERNSEC_KMEM
47629 + return -EPERM;
47630 +#endif
47631 +
47632 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47633 &retval);
47634
47635 @@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
47636 union acpi_object *obj;
47637 acpi_status status;
47638
47639 +#ifdef CONFIG_GRKERNSEC_KMEM
47640 + return -EPERM;
47641 +#endif
47642 +
47643 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47644 1, asus->debug.method_id,
47645 &input, &output);
47646 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47647 index 62f8030..c7f2a45 100644
47648 --- a/drivers/platform/x86/msi-laptop.c
47649 +++ b/drivers/platform/x86/msi-laptop.c
47650 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47651
47652 if (!quirks->ec_read_only) {
47653 /* allow userland write sysfs file */
47654 - dev_attr_bluetooth.store = store_bluetooth;
47655 - dev_attr_wlan.store = store_wlan;
47656 - dev_attr_threeg.store = store_threeg;
47657 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47658 - dev_attr_wlan.attr.mode |= S_IWUSR;
47659 - dev_attr_threeg.attr.mode |= S_IWUSR;
47660 + pax_open_kernel();
47661 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47662 + *(void **)&dev_attr_wlan.store = store_wlan;
47663 + *(void **)&dev_attr_threeg.store = store_threeg;
47664 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47665 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47666 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47667 + pax_close_kernel();
47668 }
47669
47670 /* disable hardware control by fn key */
47671 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47672 index 70222f2..8c8ce66 100644
47673 --- a/drivers/platform/x86/msi-wmi.c
47674 +++ b/drivers/platform/x86/msi-wmi.c
47675 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47676 static void msi_wmi_notify(u32 value, void *context)
47677 {
47678 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47679 - static struct key_entry *key;
47680 + struct key_entry *key;
47681 union acpi_object *obj;
47682 acpi_status status;
47683
47684 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47685 index fb233ae..23a325c 100644
47686 --- a/drivers/platform/x86/sony-laptop.c
47687 +++ b/drivers/platform/x86/sony-laptop.c
47688 @@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47689 }
47690
47691 /* High speed charging function */
47692 -static struct device_attribute *hsc_handle;
47693 +static device_attribute_no_const *hsc_handle;
47694
47695 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47696 struct device_attribute *attr,
47697 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47698 index 58b0274..6704626 100644
47699 --- a/drivers/platform/x86/thinkpad_acpi.c
47700 +++ b/drivers/platform/x86/thinkpad_acpi.c
47701 @@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
47702 return 0;
47703 }
47704
47705 -void static hotkey_mask_warn_incomplete_mask(void)
47706 +static void hotkey_mask_warn_incomplete_mask(void)
47707 {
47708 /* log only what the user can fix... */
47709 const u32 wantedmask = hotkey_driver_mask &
47710 @@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47711 }
47712 }
47713
47714 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47715 - struct tp_nvram_state *newn,
47716 - const u32 event_mask)
47717 -{
47718 -
47719 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47720 do { \
47721 if ((event_mask & (1 << __scancode)) && \
47722 @@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47723 tpacpi_hotkey_send_key(__scancode); \
47724 } while (0)
47725
47726 - void issue_volchange(const unsigned int oldvol,
47727 - const unsigned int newvol)
47728 - {
47729 - unsigned int i = oldvol;
47730 +static void issue_volchange(const unsigned int oldvol,
47731 + const unsigned int newvol,
47732 + const u32 event_mask)
47733 +{
47734 + unsigned int i = oldvol;
47735
47736 - while (i > newvol) {
47737 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47738 - i--;
47739 - }
47740 - while (i < newvol) {
47741 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47742 - i++;
47743 - }
47744 + while (i > newvol) {
47745 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47746 + i--;
47747 }
47748 + while (i < newvol) {
47749 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47750 + i++;
47751 + }
47752 +}
47753
47754 - void issue_brightnesschange(const unsigned int oldbrt,
47755 - const unsigned int newbrt)
47756 - {
47757 - unsigned int i = oldbrt;
47758 +static void issue_brightnesschange(const unsigned int oldbrt,
47759 + const unsigned int newbrt,
47760 + const u32 event_mask)
47761 +{
47762 + unsigned int i = oldbrt;
47763
47764 - while (i > newbrt) {
47765 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47766 - i--;
47767 - }
47768 - while (i < newbrt) {
47769 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47770 - i++;
47771 - }
47772 + while (i > newbrt) {
47773 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47774 + i--;
47775 + }
47776 + while (i < newbrt) {
47777 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47778 + i++;
47779 }
47780 +}
47781
47782 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47783 + struct tp_nvram_state *newn,
47784 + const u32 event_mask)
47785 +{
47786 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47787 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47788 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47789 @@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47790 oldn->volume_level != newn->volume_level) {
47791 /* recently muted, or repeated mute keypress, or
47792 * multiple presses ending in mute */
47793 - issue_volchange(oldn->volume_level, newn->volume_level);
47794 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47795 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47796 }
47797 } else {
47798 @@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47799 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47800 }
47801 if (oldn->volume_level != newn->volume_level) {
47802 - issue_volchange(oldn->volume_level, newn->volume_level);
47803 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47804 } else if (oldn->volume_toggle != newn->volume_toggle) {
47805 /* repeated vol up/down keypress at end of scale ? */
47806 if (newn->volume_level == 0)
47807 @@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47808 /* handle brightness */
47809 if (oldn->brightness_level != newn->brightness_level) {
47810 issue_brightnesschange(oldn->brightness_level,
47811 - newn->brightness_level);
47812 + newn->brightness_level,
47813 + event_mask);
47814 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47815 /* repeated key presses that didn't change state */
47816 if (newn->brightness_level == 0)
47817 @@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47818 && !tp_features.bright_unkfw)
47819 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47820 }
47821 +}
47822
47823 #undef TPACPI_COMPARE_KEY
47824 #undef TPACPI_MAY_SEND_KEY
47825 -}
47826
47827 /*
47828 * Polling driver
47829 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47830 index 769d265..a3a05ca 100644
47831 --- a/drivers/pnp/pnpbios/bioscalls.c
47832 +++ b/drivers/pnp/pnpbios/bioscalls.c
47833 @@ -58,7 +58,7 @@ do { \
47834 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47835 } while(0)
47836
47837 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47838 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47839 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47840
47841 /*
47842 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47843
47844 cpu = get_cpu();
47845 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47846 +
47847 + pax_open_kernel();
47848 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47849 + pax_close_kernel();
47850
47851 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47852 spin_lock_irqsave(&pnp_bios_lock, flags);
47853 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47854 :"memory");
47855 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47856
47857 + pax_open_kernel();
47858 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47859 + pax_close_kernel();
47860 +
47861 put_cpu();
47862
47863 /* If we get here and this is set then the PnP BIOS faulted on us. */
47864 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47865 return status;
47866 }
47867
47868 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
47869 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47870 {
47871 int i;
47872
47873 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47874 pnp_bios_callpoint.offset = header->fields.pm16offset;
47875 pnp_bios_callpoint.segment = PNP_CS16;
47876
47877 + pax_open_kernel();
47878 +
47879 for_each_possible_cpu(i) {
47880 struct desc_struct *gdt = get_cpu_gdt_table(i);
47881 if (!gdt)
47882 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47883 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47884 (unsigned long)__va(header->fields.pm16dseg));
47885 }
47886 +
47887 + pax_close_kernel();
47888 }
47889 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47890 index d95e101..67f0c3f 100644
47891 --- a/drivers/pnp/resource.c
47892 +++ b/drivers/pnp/resource.c
47893 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47894 return 1;
47895
47896 /* check if the resource is valid */
47897 - if (*irq < 0 || *irq > 15)
47898 + if (*irq > 15)
47899 return 0;
47900
47901 /* check if the resource is reserved */
47902 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47903 return 1;
47904
47905 /* check if the resource is valid */
47906 - if (*dma < 0 || *dma == 4 || *dma > 7)
47907 + if (*dma == 4 || *dma > 7)
47908 return 0;
47909
47910 /* check if the resource is reserved */
47911 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47912 index 0c52e2a..3421ab7 100644
47913 --- a/drivers/power/pda_power.c
47914 +++ b/drivers/power/pda_power.c
47915 @@ -37,7 +37,11 @@ static int polling;
47916
47917 #if IS_ENABLED(CONFIG_USB_PHY)
47918 static struct usb_phy *transceiver;
47919 -static struct notifier_block otg_nb;
47920 +static int otg_handle_notification(struct notifier_block *nb,
47921 + unsigned long event, void *unused);
47922 +static struct notifier_block otg_nb = {
47923 + .notifier_call = otg_handle_notification
47924 +};
47925 #endif
47926
47927 static struct regulator *ac_draw;
47928 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47929
47930 #if IS_ENABLED(CONFIG_USB_PHY)
47931 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47932 - otg_nb.notifier_call = otg_handle_notification;
47933 ret = usb_register_notifier(transceiver, &otg_nb);
47934 if (ret) {
47935 dev_err(dev, "failure to register otg notifier\n");
47936 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47937 index cc439fd..8fa30df 100644
47938 --- a/drivers/power/power_supply.h
47939 +++ b/drivers/power/power_supply.h
47940 @@ -16,12 +16,12 @@ struct power_supply;
47941
47942 #ifdef CONFIG_SYSFS
47943
47944 -extern void power_supply_init_attrs(struct device_type *dev_type);
47945 +extern void power_supply_init_attrs(void);
47946 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47947
47948 #else
47949
47950 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47951 +static inline void power_supply_init_attrs(void) {}
47952 #define power_supply_uevent NULL
47953
47954 #endif /* CONFIG_SYSFS */
47955 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47956 index 557af94..84dc1fe 100644
47957 --- a/drivers/power/power_supply_core.c
47958 +++ b/drivers/power/power_supply_core.c
47959 @@ -24,7 +24,10 @@
47960 struct class *power_supply_class;
47961 EXPORT_SYMBOL_GPL(power_supply_class);
47962
47963 -static struct device_type power_supply_dev_type;
47964 +extern const struct attribute_group *power_supply_attr_groups[];
47965 +static struct device_type power_supply_dev_type = {
47966 + .groups = power_supply_attr_groups,
47967 +};
47968
47969 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47970 struct power_supply *supply)
47971 @@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47972 return PTR_ERR(power_supply_class);
47973
47974 power_supply_class->dev_uevent = power_supply_uevent;
47975 - power_supply_init_attrs(&power_supply_dev_type);
47976 + power_supply_init_attrs();
47977
47978 return 0;
47979 }
47980 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
47981 index 44420d1..967126e 100644
47982 --- a/drivers/power/power_supply_sysfs.c
47983 +++ b/drivers/power/power_supply_sysfs.c
47984 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
47985 .is_visible = power_supply_attr_is_visible,
47986 };
47987
47988 -static const struct attribute_group *power_supply_attr_groups[] = {
47989 +const struct attribute_group *power_supply_attr_groups[] = {
47990 &power_supply_attr_group,
47991 NULL,
47992 };
47993
47994 -void power_supply_init_attrs(struct device_type *dev_type)
47995 +void power_supply_init_attrs(void)
47996 {
47997 int i;
47998
47999 - dev_type->groups = power_supply_attr_groups;
48000 -
48001 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48002 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48003 }
48004 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48005 index 84419af..268ede8 100644
48006 --- a/drivers/powercap/powercap_sys.c
48007 +++ b/drivers/powercap/powercap_sys.c
48008 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48009 struct device_attribute name_attr;
48010 };
48011
48012 +static ssize_t show_constraint_name(struct device *dev,
48013 + struct device_attribute *dev_attr,
48014 + char *buf);
48015 +
48016 static struct powercap_constraint_attr
48017 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48018 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48019 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48020 + .power_limit_attr = {
48021 + .attr = {
48022 + .name = NULL,
48023 + .mode = S_IWUSR | S_IRUGO
48024 + },
48025 + .show = show_constraint_power_limit_uw,
48026 + .store = store_constraint_power_limit_uw
48027 + },
48028 +
48029 + .time_window_attr = {
48030 + .attr = {
48031 + .name = NULL,
48032 + .mode = S_IWUSR | S_IRUGO
48033 + },
48034 + .show = show_constraint_time_window_us,
48035 + .store = store_constraint_time_window_us
48036 + },
48037 +
48038 + .max_power_attr = {
48039 + .attr = {
48040 + .name = NULL,
48041 + .mode = S_IRUGO
48042 + },
48043 + .show = show_constraint_max_power_uw,
48044 + .store = NULL
48045 + },
48046 +
48047 + .min_power_attr = {
48048 + .attr = {
48049 + .name = NULL,
48050 + .mode = S_IRUGO
48051 + },
48052 + .show = show_constraint_min_power_uw,
48053 + .store = NULL
48054 + },
48055 +
48056 + .max_time_window_attr = {
48057 + .attr = {
48058 + .name = NULL,
48059 + .mode = S_IRUGO
48060 + },
48061 + .show = show_constraint_max_time_window_us,
48062 + .store = NULL
48063 + },
48064 +
48065 + .min_time_window_attr = {
48066 + .attr = {
48067 + .name = NULL,
48068 + .mode = S_IRUGO
48069 + },
48070 + .show = show_constraint_min_time_window_us,
48071 + .store = NULL
48072 + },
48073 +
48074 + .name_attr = {
48075 + .attr = {
48076 + .name = NULL,
48077 + .mode = S_IRUGO
48078 + },
48079 + .show = show_constraint_name,
48080 + .store = NULL
48081 + }
48082 + }
48083 +};
48084
48085 /* A list of powercap control_types */
48086 static LIST_HEAD(powercap_cntrl_list);
48087 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48088 }
48089
48090 static int create_constraint_attribute(int id, const char *name,
48091 - int mode,
48092 - struct device_attribute *dev_attr,
48093 - ssize_t (*show)(struct device *,
48094 - struct device_attribute *, char *),
48095 - ssize_t (*store)(struct device *,
48096 - struct device_attribute *,
48097 - const char *, size_t)
48098 - )
48099 + struct device_attribute *dev_attr)
48100 {
48101 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48102
48103 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48104 - id, name);
48105 - if (!dev_attr->attr.name)
48106 + if (!name)
48107 return -ENOMEM;
48108 - dev_attr->attr.mode = mode;
48109 - dev_attr->show = show;
48110 - dev_attr->store = store;
48111 +
48112 + pax_open_kernel();
48113 + *(const char **)&dev_attr->attr.name = name;
48114 + pax_close_kernel();
48115
48116 return 0;
48117 }
48118 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48119
48120 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48121 ret = create_constraint_attribute(i, "power_limit_uw",
48122 - S_IWUSR | S_IRUGO,
48123 - &constraint_attrs[i].power_limit_attr,
48124 - show_constraint_power_limit_uw,
48125 - store_constraint_power_limit_uw);
48126 + &constraint_attrs[i].power_limit_attr);
48127 if (ret)
48128 goto err_alloc;
48129 ret = create_constraint_attribute(i, "time_window_us",
48130 - S_IWUSR | S_IRUGO,
48131 - &constraint_attrs[i].time_window_attr,
48132 - show_constraint_time_window_us,
48133 - store_constraint_time_window_us);
48134 + &constraint_attrs[i].time_window_attr);
48135 if (ret)
48136 goto err_alloc;
48137 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48138 - &constraint_attrs[i].name_attr,
48139 - show_constraint_name,
48140 - NULL);
48141 + ret = create_constraint_attribute(i, "name",
48142 + &constraint_attrs[i].name_attr);
48143 if (ret)
48144 goto err_alloc;
48145 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48146 - &constraint_attrs[i].max_power_attr,
48147 - show_constraint_max_power_uw,
48148 - NULL);
48149 + ret = create_constraint_attribute(i, "max_power_uw",
48150 + &constraint_attrs[i].max_power_attr);
48151 if (ret)
48152 goto err_alloc;
48153 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48154 - &constraint_attrs[i].min_power_attr,
48155 - show_constraint_min_power_uw,
48156 - NULL);
48157 + ret = create_constraint_attribute(i, "min_power_uw",
48158 + &constraint_attrs[i].min_power_attr);
48159 if (ret)
48160 goto err_alloc;
48161 ret = create_constraint_attribute(i, "max_time_window_us",
48162 - S_IRUGO,
48163 - &constraint_attrs[i].max_time_window_attr,
48164 - show_constraint_max_time_window_us,
48165 - NULL);
48166 + &constraint_attrs[i].max_time_window_attr);
48167 if (ret)
48168 goto err_alloc;
48169 ret = create_constraint_attribute(i, "min_time_window_us",
48170 - S_IRUGO,
48171 - &constraint_attrs[i].min_time_window_attr,
48172 - show_constraint_min_time_window_us,
48173 - NULL);
48174 + &constraint_attrs[i].min_time_window_attr);
48175 if (ret)
48176 goto err_alloc;
48177
48178 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48179 power_zone->zone_dev_attrs[count++] =
48180 &dev_attr_max_energy_range_uj.attr;
48181 if (power_zone->ops->get_energy_uj) {
48182 + pax_open_kernel();
48183 if (power_zone->ops->reset_energy_uj)
48184 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48185 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48186 else
48187 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48188 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48189 + pax_close_kernel();
48190 power_zone->zone_dev_attrs[count++] =
48191 &dev_attr_energy_uj.attr;
48192 }
48193 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48194 index 0186c1b..6491409 100644
48195 --- a/drivers/regulator/core.c
48196 +++ b/drivers/regulator/core.c
48197 @@ -3369,7 +3369,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48198 {
48199 const struct regulation_constraints *constraints = NULL;
48200 const struct regulator_init_data *init_data;
48201 - static atomic_t regulator_no = ATOMIC_INIT(0);
48202 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48203 struct regulator_dev *rdev;
48204 struct device *dev;
48205 int ret, i;
48206 @@ -3439,7 +3439,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48207 rdev->dev.of_node = config->of_node;
48208 rdev->dev.parent = dev;
48209 dev_set_name(&rdev->dev, "regulator.%d",
48210 - atomic_inc_return(&regulator_no) - 1);
48211 + atomic_inc_return_unchecked(&regulator_no) - 1);
48212 ret = device_register(&rdev->dev);
48213 if (ret != 0) {
48214 put_device(&rdev->dev);
48215 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48216 index 8d94d3d..653b623 100644
48217 --- a/drivers/regulator/max8660.c
48218 +++ b/drivers/regulator/max8660.c
48219 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48220 max8660->shadow_regs[MAX8660_OVER1] = 5;
48221 } else {
48222 /* Otherwise devices can be toggled via software */
48223 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48224 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48225 + pax_open_kernel();
48226 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48227 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48228 + pax_close_kernel();
48229 }
48230
48231 /*
48232 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48233 index 892aa1e..ebd1b9c 100644
48234 --- a/drivers/regulator/max8973-regulator.c
48235 +++ b/drivers/regulator/max8973-regulator.c
48236 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48237 if (!pdata || !pdata->enable_ext_control) {
48238 max->desc.enable_reg = MAX8973_VOUT;
48239 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48240 - max->ops.enable = regulator_enable_regmap;
48241 - max->ops.disable = regulator_disable_regmap;
48242 - max->ops.is_enabled = regulator_is_enabled_regmap;
48243 + pax_open_kernel();
48244 + *(void **)&max->ops.enable = regulator_enable_regmap;
48245 + *(void **)&max->ops.disable = regulator_disable_regmap;
48246 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48247 + pax_close_kernel();
48248 }
48249
48250 if (pdata) {
48251 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48252 index 96c9f80..90974ca 100644
48253 --- a/drivers/regulator/mc13892-regulator.c
48254 +++ b/drivers/regulator/mc13892-regulator.c
48255 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48256 }
48257 mc13xxx_unlock(mc13892);
48258
48259 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48260 + pax_open_kernel();
48261 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48262 = mc13892_vcam_set_mode;
48263 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48264 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48265 = mc13892_vcam_get_mode;
48266 + pax_close_kernel();
48267
48268 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48269 ARRAY_SIZE(mc13892_regulators));
48270 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48271 index a2325bc..04c549f 100644
48272 --- a/drivers/rtc/rtc-cmos.c
48273 +++ b/drivers/rtc/rtc-cmos.c
48274 @@ -779,7 +779,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48275 hpet_rtc_timer_init();
48276
48277 /* export at least the first block of NVRAM */
48278 - nvram.size = address_space - NVRAM_OFFSET;
48279 + pax_open_kernel();
48280 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48281 + pax_close_kernel();
48282 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48283 if (retval < 0) {
48284 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48285 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48286 index d049393..bb20be0 100644
48287 --- a/drivers/rtc/rtc-dev.c
48288 +++ b/drivers/rtc/rtc-dev.c
48289 @@ -16,6 +16,7 @@
48290 #include <linux/module.h>
48291 #include <linux/rtc.h>
48292 #include <linux/sched.h>
48293 +#include <linux/grsecurity.h>
48294 #include "rtc-core.h"
48295
48296 static dev_t rtc_devt;
48297 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48298 if (copy_from_user(&tm, uarg, sizeof(tm)))
48299 return -EFAULT;
48300
48301 + gr_log_timechange();
48302 +
48303 return rtc_set_time(rtc, &tm);
48304
48305 case RTC_PIE_ON:
48306 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48307 index 4e75345..09f8663 100644
48308 --- a/drivers/rtc/rtc-ds1307.c
48309 +++ b/drivers/rtc/rtc-ds1307.c
48310 @@ -107,7 +107,7 @@ struct ds1307 {
48311 u8 offset; /* register's offset */
48312 u8 regs[11];
48313 u16 nvram_offset;
48314 - struct bin_attribute *nvram;
48315 + bin_attribute_no_const *nvram;
48316 enum ds_type type;
48317 unsigned long flags;
48318 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48319 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48320 index 11880c1..b823aa4 100644
48321 --- a/drivers/rtc/rtc-m48t59.c
48322 +++ b/drivers/rtc/rtc-m48t59.c
48323 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48324 if (IS_ERR(m48t59->rtc))
48325 return PTR_ERR(m48t59->rtc);
48326
48327 - m48t59_nvram_attr.size = pdata->offset;
48328 + pax_open_kernel();
48329 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48330 + pax_close_kernel();
48331
48332 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48333 if (ret)
48334 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48335 index 14b5f8d..cc9bd26 100644
48336 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48337 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48338 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48339 for (bit = 0; bit < 8; bit++) {
48340
48341 if ((pci_status[i] & (0x1 << bit)) != 0) {
48342 - static const char *s;
48343 + const char *s;
48344
48345 s = pci_status_strings[bit];
48346 if (i == 7/*TARG*/ && bit == 3)
48347 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48348
48349 for (bit = 0; bit < 8; bit++) {
48350
48351 - if ((split_status[i] & (0x1 << bit)) != 0) {
48352 - static const char *s;
48353 -
48354 - s = split_status_strings[bit];
48355 - printk(s, ahd_name(ahd),
48356 + if ((split_status[i] & (0x1 << bit)) != 0)
48357 + printk(split_status_strings[bit], ahd_name(ahd),
48358 split_status_source[i]);
48359 - }
48360
48361 if (i > 1)
48362 continue;
48363
48364 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48365 - static const char *s;
48366 -
48367 - s = split_status_strings[bit];
48368 - printk(s, ahd_name(ahd), "SG");
48369 - }
48370 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48371 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48372 }
48373 }
48374 /*
48375 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48376 index e693af6..2e525b6 100644
48377 --- a/drivers/scsi/bfa/bfa_fcpim.h
48378 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48379 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48380
48381 struct bfa_itn_s {
48382 bfa_isr_func_t isr;
48383 -};
48384 +} __no_const;
48385
48386 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48387 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48388 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48389 index a3ab5cc..8143622 100644
48390 --- a/drivers/scsi/bfa/bfa_fcs.c
48391 +++ b/drivers/scsi/bfa/bfa_fcs.c
48392 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48393 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48394
48395 static struct bfa_fcs_mod_s fcs_modules[] = {
48396 - { bfa_fcs_port_attach, NULL, NULL },
48397 - { bfa_fcs_uf_attach, NULL, NULL },
48398 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48399 - bfa_fcs_fabric_modexit },
48400 + {
48401 + .attach = bfa_fcs_port_attach,
48402 + .modinit = NULL,
48403 + .modexit = NULL
48404 + },
48405 + {
48406 + .attach = bfa_fcs_uf_attach,
48407 + .modinit = NULL,
48408 + .modexit = NULL
48409 + },
48410 + {
48411 + .attach = bfa_fcs_fabric_attach,
48412 + .modinit = bfa_fcs_fabric_modinit,
48413 + .modexit = bfa_fcs_fabric_modexit
48414 + },
48415 };
48416
48417 /*
48418 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48419 index f5e4e61..a0acaf6 100644
48420 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48421 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48422 @@ -89,15 +89,26 @@ static struct {
48423 void (*offline) (struct bfa_fcs_lport_s *port);
48424 } __port_action[] = {
48425 {
48426 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48427 - bfa_fcs_lport_unknown_offline}, {
48428 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48429 - bfa_fcs_lport_fab_offline}, {
48430 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48431 - bfa_fcs_lport_n2n_offline}, {
48432 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48433 - bfa_fcs_lport_loop_offline},
48434 - };
48435 + .init = bfa_fcs_lport_unknown_init,
48436 + .online = bfa_fcs_lport_unknown_online,
48437 + .offline = bfa_fcs_lport_unknown_offline
48438 + },
48439 + {
48440 + .init = bfa_fcs_lport_fab_init,
48441 + .online = bfa_fcs_lport_fab_online,
48442 + .offline = bfa_fcs_lport_fab_offline
48443 + },
48444 + {
48445 + .init = bfa_fcs_lport_n2n_init,
48446 + .online = bfa_fcs_lport_n2n_online,
48447 + .offline = bfa_fcs_lport_n2n_offline
48448 + },
48449 + {
48450 + .init = bfa_fcs_lport_loop_init,
48451 + .online = bfa_fcs_lport_loop_online,
48452 + .offline = bfa_fcs_lport_loop_offline
48453 + },
48454 +};
48455
48456 /*
48457 * fcs_port_sm FCS logical port state machine
48458 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48459 index 90814fe..4384138 100644
48460 --- a/drivers/scsi/bfa/bfa_ioc.h
48461 +++ b/drivers/scsi/bfa/bfa_ioc.h
48462 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48463 bfa_ioc_disable_cbfn_t disable_cbfn;
48464 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48465 bfa_ioc_reset_cbfn_t reset_cbfn;
48466 -};
48467 +} __no_const;
48468
48469 /*
48470 * IOC event notification mechanism.
48471 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48472 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48473 enum bfi_ioc_state fwstate);
48474 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48475 -};
48476 +} __no_const;
48477
48478 /*
48479 * Queue element to wait for room in request queue. FIFO order is
48480 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48481 index a14c784..6de6790 100644
48482 --- a/drivers/scsi/bfa/bfa_modules.h
48483 +++ b/drivers/scsi/bfa/bfa_modules.h
48484 @@ -78,12 +78,12 @@ enum {
48485 \
48486 extern struct bfa_module_s hal_mod_ ## __mod; \
48487 struct bfa_module_s hal_mod_ ## __mod = { \
48488 - bfa_ ## __mod ## _meminfo, \
48489 - bfa_ ## __mod ## _attach, \
48490 - bfa_ ## __mod ## _detach, \
48491 - bfa_ ## __mod ## _start, \
48492 - bfa_ ## __mod ## _stop, \
48493 - bfa_ ## __mod ## _iocdisable, \
48494 + .meminfo = bfa_ ## __mod ## _meminfo, \
48495 + .attach = bfa_ ## __mod ## _attach, \
48496 + .detach = bfa_ ## __mod ## _detach, \
48497 + .start = bfa_ ## __mod ## _start, \
48498 + .stop = bfa_ ## __mod ## _stop, \
48499 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
48500 }
48501
48502 #define BFA_CACHELINE_SZ (256)
48503 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48504 index 045c4e1..13de803 100644
48505 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
48506 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48507 @@ -33,8 +33,8 @@
48508 */
48509 #include "libfcoe.h"
48510
48511 -static atomic_t ctlr_num;
48512 -static atomic_t fcf_num;
48513 +static atomic_unchecked_t ctlr_num;
48514 +static atomic_unchecked_t fcf_num;
48515
48516 /*
48517 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48518 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48519 if (!ctlr)
48520 goto out;
48521
48522 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48523 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48524 ctlr->f = f;
48525 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48526 INIT_LIST_HEAD(&ctlr->fcfs);
48527 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48528 fcf->dev.parent = &ctlr->dev;
48529 fcf->dev.bus = &fcoe_bus_type;
48530 fcf->dev.type = &fcoe_fcf_device_type;
48531 - fcf->id = atomic_inc_return(&fcf_num) - 1;
48532 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48533 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48534
48535 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48536 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48537 {
48538 int error;
48539
48540 - atomic_set(&ctlr_num, 0);
48541 - atomic_set(&fcf_num, 0);
48542 + atomic_set_unchecked(&ctlr_num, 0);
48543 + atomic_set_unchecked(&fcf_num, 0);
48544
48545 error = bus_register(&fcoe_bus_type);
48546 if (error)
48547 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48548 index f2c5005..db36c02 100644
48549 --- a/drivers/scsi/hosts.c
48550 +++ b/drivers/scsi/hosts.c
48551 @@ -42,7 +42,7 @@
48552 #include "scsi_logging.h"
48553
48554
48555 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48556 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48557
48558
48559 static void scsi_host_cls_release(struct device *dev)
48560 @@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48561 * subtract one because we increment first then return, but we need to
48562 * know what the next host number was before increment
48563 */
48564 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48565 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48566 shost->dma_channel = 0xff;
48567
48568 /* These three are default values which can be overridden */
48569 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48570 index 20a5e6e..8b23cea 100644
48571 --- a/drivers/scsi/hpsa.c
48572 +++ b/drivers/scsi/hpsa.c
48573 @@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48574 unsigned long flags;
48575
48576 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48577 - return h->access.command_completed(h, q);
48578 + return h->access->command_completed(h, q);
48579
48580 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48581 a = rq->head[rq->current_entry];
48582 @@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
48583 while (!list_empty(&h->reqQ)) {
48584 c = list_entry(h->reqQ.next, struct CommandList, list);
48585 /* can't do anything if fifo is full */
48586 - if ((h->access.fifo_full(h))) {
48587 + if ((h->access->fifo_full(h))) {
48588 dev_warn(&h->pdev->dev, "fifo full\n");
48589 break;
48590 }
48591 @@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
48592
48593 /* Tell the controller execute command */
48594 spin_unlock_irqrestore(&h->lock, flags);
48595 - h->access.submit_command(h, c);
48596 + h->access->submit_command(h, c);
48597 spin_lock_irqsave(&h->lock, flags);
48598 }
48599 spin_unlock_irqrestore(&h->lock, flags);
48600 @@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
48601
48602 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48603 {
48604 - return h->access.command_completed(h, q);
48605 + return h->access->command_completed(h, q);
48606 }
48607
48608 static inline bool interrupt_pending(struct ctlr_info *h)
48609 {
48610 - return h->access.intr_pending(h);
48611 + return h->access->intr_pending(h);
48612 }
48613
48614 static inline long interrupt_not_for_us(struct ctlr_info *h)
48615 {
48616 - return (h->access.intr_pending(h) == 0) ||
48617 + return (h->access->intr_pending(h) == 0) ||
48618 (h->interrupts_enabled == 0);
48619 }
48620
48621 @@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48622 if (prod_index < 0)
48623 return -ENODEV;
48624 h->product_name = products[prod_index].product_name;
48625 - h->access = *(products[prod_index].access);
48626 + h->access = products[prod_index].access;
48627
48628 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48629 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48630 @@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48631
48632 assert_spin_locked(&lockup_detector_lock);
48633 remove_ctlr_from_lockup_detector_list(h);
48634 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48635 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48636 spin_lock_irqsave(&h->lock, flags);
48637 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48638 spin_unlock_irqrestore(&h->lock, flags);
48639 @@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
48640 }
48641
48642 /* make sure the board interrupts are off */
48643 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48644 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48645
48646 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48647 goto clean2;
48648 @@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
48649 * fake ones to scoop up any residual completions.
48650 */
48651 spin_lock_irqsave(&h->lock, flags);
48652 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48653 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48654 spin_unlock_irqrestore(&h->lock, flags);
48655 free_irqs(h);
48656 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48657 @@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
48658 dev_info(&h->pdev->dev, "Board READY.\n");
48659 dev_info(&h->pdev->dev,
48660 "Waiting for stale completions to drain.\n");
48661 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48662 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48663 msleep(10000);
48664 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48665 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48666
48667 rc = controller_reset_failed(h->cfgtable);
48668 if (rc)
48669 @@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
48670 }
48671
48672 /* Turn the interrupts on so we can service requests */
48673 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48674 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48675
48676 hpsa_hba_inquiry(h);
48677 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48678 @@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48679 * To write all data in the battery backed cache to disks
48680 */
48681 hpsa_flush_cache(h);
48682 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48683 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48684 hpsa_free_irqs_and_disable_msix(h);
48685 }
48686
48687 @@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48688 return;
48689 }
48690 /* Change the access methods to the performant access methods */
48691 - h->access = SA5_performant_access;
48692 + h->access = &SA5_performant_access;
48693 h->transMethod = CFGTBL_Trans_Performant;
48694 }
48695
48696 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48697 index bc85e72..d463049 100644
48698 --- a/drivers/scsi/hpsa.h
48699 +++ b/drivers/scsi/hpsa.h
48700 @@ -79,7 +79,7 @@ struct ctlr_info {
48701 unsigned int msix_vector;
48702 unsigned int msi_vector;
48703 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48704 - struct access_method access;
48705 + struct access_method *access;
48706
48707 /* queue and queue Info */
48708 struct list_head reqQ;
48709 @@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48710 }
48711
48712 static struct access_method SA5_access = {
48713 - SA5_submit_command,
48714 - SA5_intr_mask,
48715 - SA5_fifo_full,
48716 - SA5_intr_pending,
48717 - SA5_completed,
48718 + .submit_command = SA5_submit_command,
48719 + .set_intr_mask = SA5_intr_mask,
48720 + .fifo_full = SA5_fifo_full,
48721 + .intr_pending = SA5_intr_pending,
48722 + .command_completed = SA5_completed,
48723 };
48724
48725 static struct access_method SA5_performant_access = {
48726 - SA5_submit_command,
48727 - SA5_performant_intr_mask,
48728 - SA5_fifo_full,
48729 - SA5_performant_intr_pending,
48730 - SA5_performant_completed,
48731 + .submit_command = SA5_submit_command,
48732 + .set_intr_mask = SA5_performant_intr_mask,
48733 + .fifo_full = SA5_fifo_full,
48734 + .intr_pending = SA5_performant_intr_pending,
48735 + .command_completed = SA5_performant_completed,
48736 };
48737
48738 struct board_type {
48739 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48740 index 1b3a094..068e683 100644
48741 --- a/drivers/scsi/libfc/fc_exch.c
48742 +++ b/drivers/scsi/libfc/fc_exch.c
48743 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
48744 u16 pool_max_index;
48745
48746 struct {
48747 - atomic_t no_free_exch;
48748 - atomic_t no_free_exch_xid;
48749 - atomic_t xid_not_found;
48750 - atomic_t xid_busy;
48751 - atomic_t seq_not_found;
48752 - atomic_t non_bls_resp;
48753 + atomic_unchecked_t no_free_exch;
48754 + atomic_unchecked_t no_free_exch_xid;
48755 + atomic_unchecked_t xid_not_found;
48756 + atomic_unchecked_t xid_busy;
48757 + atomic_unchecked_t seq_not_found;
48758 + atomic_unchecked_t non_bls_resp;
48759 } stats;
48760 };
48761
48762 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48763 /* allocate memory for exchange */
48764 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48765 if (!ep) {
48766 - atomic_inc(&mp->stats.no_free_exch);
48767 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48768 goto out;
48769 }
48770 memset(ep, 0, sizeof(*ep));
48771 @@ -874,7 +874,7 @@ out:
48772 return ep;
48773 err:
48774 spin_unlock_bh(&pool->lock);
48775 - atomic_inc(&mp->stats.no_free_exch_xid);
48776 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48777 mempool_free(ep, mp->ep_pool);
48778 return NULL;
48779 }
48780 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48781 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48782 ep = fc_exch_find(mp, xid);
48783 if (!ep) {
48784 - atomic_inc(&mp->stats.xid_not_found);
48785 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48786 reject = FC_RJT_OX_ID;
48787 goto out;
48788 }
48789 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48790 ep = fc_exch_find(mp, xid);
48791 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48792 if (ep) {
48793 - atomic_inc(&mp->stats.xid_busy);
48794 + atomic_inc_unchecked(&mp->stats.xid_busy);
48795 reject = FC_RJT_RX_ID;
48796 goto rel;
48797 }
48798 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48799 }
48800 xid = ep->xid; /* get our XID */
48801 } else if (!ep) {
48802 - atomic_inc(&mp->stats.xid_not_found);
48803 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48804 reject = FC_RJT_RX_ID; /* XID not found */
48805 goto out;
48806 }
48807 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48808 } else {
48809 sp = &ep->seq;
48810 if (sp->id != fh->fh_seq_id) {
48811 - atomic_inc(&mp->stats.seq_not_found);
48812 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48813 if (f_ctl & FC_FC_END_SEQ) {
48814 /*
48815 * Update sequence_id based on incoming last
48816 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48817
48818 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48819 if (!ep) {
48820 - atomic_inc(&mp->stats.xid_not_found);
48821 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48822 goto out;
48823 }
48824 if (ep->esb_stat & ESB_ST_COMPLETE) {
48825 - atomic_inc(&mp->stats.xid_not_found);
48826 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48827 goto rel;
48828 }
48829 if (ep->rxid == FC_XID_UNKNOWN)
48830 ep->rxid = ntohs(fh->fh_rx_id);
48831 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48832 - atomic_inc(&mp->stats.xid_not_found);
48833 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48834 goto rel;
48835 }
48836 if (ep->did != ntoh24(fh->fh_s_id) &&
48837 ep->did != FC_FID_FLOGI) {
48838 - atomic_inc(&mp->stats.xid_not_found);
48839 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48840 goto rel;
48841 }
48842 sof = fr_sof(fp);
48843 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48844 sp->ssb_stat |= SSB_ST_RESP;
48845 sp->id = fh->fh_seq_id;
48846 } else if (sp->id != fh->fh_seq_id) {
48847 - atomic_inc(&mp->stats.seq_not_found);
48848 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48849 goto rel;
48850 }
48851
48852 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48853 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48854
48855 if (!sp)
48856 - atomic_inc(&mp->stats.xid_not_found);
48857 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48858 else
48859 - atomic_inc(&mp->stats.non_bls_resp);
48860 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
48861
48862 fc_frame_free(fp);
48863 }
48864 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48865
48866 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48867 mp = ema->mp;
48868 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48869 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48870 st->fc_no_free_exch_xid +=
48871 - atomic_read(&mp->stats.no_free_exch_xid);
48872 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48873 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48874 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48875 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48876 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48877 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48878 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48879 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48880 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48881 }
48882 }
48883 EXPORT_SYMBOL(fc_exch_update_stats);
48884 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48885 index d289583..b745eec 100644
48886 --- a/drivers/scsi/libsas/sas_ata.c
48887 +++ b/drivers/scsi/libsas/sas_ata.c
48888 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48889 .postreset = ata_std_postreset,
48890 .error_handler = ata_std_error_handler,
48891 .post_internal_cmd = sas_ata_post_internal,
48892 - .qc_defer = ata_std_qc_defer,
48893 + .qc_defer = ata_std_qc_defer,
48894 .qc_prep = ata_noop_qc_prep,
48895 .qc_issue = sas_ata_qc_issue,
48896 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48897 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48898 index 4e1b75c..0bbdfa9 100644
48899 --- a/drivers/scsi/lpfc/lpfc.h
48900 +++ b/drivers/scsi/lpfc/lpfc.h
48901 @@ -432,7 +432,7 @@ struct lpfc_vport {
48902 struct dentry *debug_nodelist;
48903 struct dentry *vport_debugfs_root;
48904 struct lpfc_debugfs_trc *disc_trc;
48905 - atomic_t disc_trc_cnt;
48906 + atomic_unchecked_t disc_trc_cnt;
48907 #endif
48908 uint8_t stat_data_enabled;
48909 uint8_t stat_data_blocked;
48910 @@ -865,8 +865,8 @@ struct lpfc_hba {
48911 struct timer_list fabric_block_timer;
48912 unsigned long bit_flags;
48913 #define FABRIC_COMANDS_BLOCKED 0
48914 - atomic_t num_rsrc_err;
48915 - atomic_t num_cmd_success;
48916 + atomic_unchecked_t num_rsrc_err;
48917 + atomic_unchecked_t num_cmd_success;
48918 unsigned long last_rsrc_error_time;
48919 unsigned long last_ramp_down_time;
48920 unsigned long last_ramp_up_time;
48921 @@ -902,7 +902,7 @@ struct lpfc_hba {
48922
48923 struct dentry *debug_slow_ring_trc;
48924 struct lpfc_debugfs_trc *slow_ring_trc;
48925 - atomic_t slow_ring_trc_cnt;
48926 + atomic_unchecked_t slow_ring_trc_cnt;
48927 /* iDiag debugfs sub-directory */
48928 struct dentry *idiag_root;
48929 struct dentry *idiag_pci_cfg;
48930 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48931 index 60084e6..0e2e700 100644
48932 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
48933 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48934 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48935
48936 #include <linux/debugfs.h>
48937
48938 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48939 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48940 static unsigned long lpfc_debugfs_start_time = 0L;
48941
48942 /* iDiag */
48943 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48944 lpfc_debugfs_enable = 0;
48945
48946 len = 0;
48947 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48948 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48949 (lpfc_debugfs_max_disc_trc - 1);
48950 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48951 dtp = vport->disc_trc + i;
48952 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48953 lpfc_debugfs_enable = 0;
48954
48955 len = 0;
48956 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48957 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48958 (lpfc_debugfs_max_slow_ring_trc - 1);
48959 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48960 dtp = phba->slow_ring_trc + i;
48961 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48962 !vport || !vport->disc_trc)
48963 return;
48964
48965 - index = atomic_inc_return(&vport->disc_trc_cnt) &
48966 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48967 (lpfc_debugfs_max_disc_trc - 1);
48968 dtp = vport->disc_trc + index;
48969 dtp->fmt = fmt;
48970 dtp->data1 = data1;
48971 dtp->data2 = data2;
48972 dtp->data3 = data3;
48973 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48974 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48975 dtp->jif = jiffies;
48976 #endif
48977 return;
48978 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
48979 !phba || !phba->slow_ring_trc)
48980 return;
48981
48982 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
48983 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
48984 (lpfc_debugfs_max_slow_ring_trc - 1);
48985 dtp = phba->slow_ring_trc + index;
48986 dtp->fmt = fmt;
48987 dtp->data1 = data1;
48988 dtp->data2 = data2;
48989 dtp->data3 = data3;
48990 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48991 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48992 dtp->jif = jiffies;
48993 #endif
48994 return;
48995 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48996 "slow_ring buffer\n");
48997 goto debug_failed;
48998 }
48999 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49000 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49001 memset(phba->slow_ring_trc, 0,
49002 (sizeof(struct lpfc_debugfs_trc) *
49003 lpfc_debugfs_max_slow_ring_trc));
49004 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49005 "buffer\n");
49006 goto debug_failed;
49007 }
49008 - atomic_set(&vport->disc_trc_cnt, 0);
49009 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49010
49011 snprintf(name, sizeof(name), "discovery_trace");
49012 vport->debug_disc_trc =
49013 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49014 index 68c94cc..8c27be5 100644
49015 --- a/drivers/scsi/lpfc/lpfc_init.c
49016 +++ b/drivers/scsi/lpfc/lpfc_init.c
49017 @@ -10949,8 +10949,10 @@ lpfc_init(void)
49018 "misc_register returned with status %d", error);
49019
49020 if (lpfc_enable_npiv) {
49021 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49022 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49023 + pax_open_kernel();
49024 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49025 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49026 + pax_close_kernel();
49027 }
49028 lpfc_transport_template =
49029 fc_attach_transport(&lpfc_transport_functions);
49030 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49031 index b2ede05..aaf482ca 100644
49032 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49033 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49034 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49035 uint32_t evt_posted;
49036
49037 spin_lock_irqsave(&phba->hbalock, flags);
49038 - atomic_inc(&phba->num_rsrc_err);
49039 + atomic_inc_unchecked(&phba->num_rsrc_err);
49040 phba->last_rsrc_error_time = jiffies;
49041
49042 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49043 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49044 unsigned long flags;
49045 struct lpfc_hba *phba = vport->phba;
49046 uint32_t evt_posted;
49047 - atomic_inc(&phba->num_cmd_success);
49048 + atomic_inc_unchecked(&phba->num_cmd_success);
49049
49050 if (vport->cfg_lun_queue_depth <= queue_depth)
49051 return;
49052 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49053 unsigned long num_rsrc_err, num_cmd_success;
49054 int i;
49055
49056 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49057 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49058 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49059 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49060
49061 /*
49062 * The error and success command counters are global per
49063 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49064 }
49065 }
49066 lpfc_destroy_vport_work_array(phba, vports);
49067 - atomic_set(&phba->num_rsrc_err, 0);
49068 - atomic_set(&phba->num_cmd_success, 0);
49069 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49070 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49071 }
49072
49073 /**
49074 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49075 }
49076 }
49077 lpfc_destroy_vport_work_array(phba, vports);
49078 - atomic_set(&phba->num_rsrc_err, 0);
49079 - atomic_set(&phba->num_cmd_success, 0);
49080 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49081 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49082 }
49083
49084 /**
49085 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49086 index 7f0af4f..193ac3e 100644
49087 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49088 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49089 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49090 {
49091 struct scsi_device *sdev = to_scsi_device(dev);
49092 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49093 - static struct _raid_device *raid_device;
49094 + struct _raid_device *raid_device;
49095 unsigned long flags;
49096 Mpi2RaidVolPage0_t vol_pg0;
49097 Mpi2ConfigReply_t mpi_reply;
49098 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49099 {
49100 struct scsi_device *sdev = to_scsi_device(dev);
49101 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49102 - static struct _raid_device *raid_device;
49103 + struct _raid_device *raid_device;
49104 unsigned long flags;
49105 Mpi2RaidVolPage0_t vol_pg0;
49106 Mpi2ConfigReply_t mpi_reply;
49107 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49108 struct fw_event_work *fw_event)
49109 {
49110 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49111 - static struct _raid_device *raid_device;
49112 + struct _raid_device *raid_device;
49113 unsigned long flags;
49114 u16 handle;
49115
49116 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49117 u64 sas_address;
49118 struct _sas_device *sas_device;
49119 struct _sas_node *expander_device;
49120 - static struct _raid_device *raid_device;
49121 + struct _raid_device *raid_device;
49122 u8 retry_count;
49123 unsigned long flags;
49124
49125 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49126 index be8ce54..94ed33a 100644
49127 --- a/drivers/scsi/pmcraid.c
49128 +++ b/drivers/scsi/pmcraid.c
49129 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49130 res->scsi_dev = scsi_dev;
49131 scsi_dev->hostdata = res;
49132 res->change_detected = 0;
49133 - atomic_set(&res->read_failures, 0);
49134 - atomic_set(&res->write_failures, 0);
49135 + atomic_set_unchecked(&res->read_failures, 0);
49136 + atomic_set_unchecked(&res->write_failures, 0);
49137 rc = 0;
49138 }
49139 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49140 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49141
49142 /* If this was a SCSI read/write command keep count of errors */
49143 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49144 - atomic_inc(&res->read_failures);
49145 + atomic_inc_unchecked(&res->read_failures);
49146 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49147 - atomic_inc(&res->write_failures);
49148 + atomic_inc_unchecked(&res->write_failures);
49149
49150 if (!RES_IS_GSCSI(res->cfg_entry) &&
49151 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49152 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49153 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49154 * hrrq_id assigned here in queuecommand
49155 */
49156 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49157 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49158 pinstance->num_hrrq;
49159 cmd->cmd_done = pmcraid_io_done;
49160
49161 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49162 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49163 * hrrq_id assigned here in queuecommand
49164 */
49165 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49166 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49167 pinstance->num_hrrq;
49168
49169 if (request_size) {
49170 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49171
49172 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49173 /* add resources only after host is added into system */
49174 - if (!atomic_read(&pinstance->expose_resources))
49175 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49176 return;
49177
49178 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49179 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49180 init_waitqueue_head(&pinstance->reset_wait_q);
49181
49182 atomic_set(&pinstance->outstanding_cmds, 0);
49183 - atomic_set(&pinstance->last_message_id, 0);
49184 - atomic_set(&pinstance->expose_resources, 0);
49185 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49186 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49187
49188 INIT_LIST_HEAD(&pinstance->free_res_q);
49189 INIT_LIST_HEAD(&pinstance->used_res_q);
49190 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49191 /* Schedule worker thread to handle CCN and take care of adding and
49192 * removing devices to OS
49193 */
49194 - atomic_set(&pinstance->expose_resources, 1);
49195 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49196 schedule_work(&pinstance->worker_q);
49197 return rc;
49198
49199 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49200 index e1d150f..6c6df44 100644
49201 --- a/drivers/scsi/pmcraid.h
49202 +++ b/drivers/scsi/pmcraid.h
49203 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49204 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49205
49206 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49207 - atomic_t last_message_id;
49208 + atomic_unchecked_t last_message_id;
49209
49210 /* configuration table */
49211 struct pmcraid_config_table *cfg_table;
49212 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49213 atomic_t outstanding_cmds;
49214
49215 /* should add/delete resources to mid-layer now ?*/
49216 - atomic_t expose_resources;
49217 + atomic_unchecked_t expose_resources;
49218
49219
49220
49221 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49222 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49223 };
49224 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49225 - atomic_t read_failures; /* count of failed READ commands */
49226 - atomic_t write_failures; /* count of failed WRITE commands */
49227 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49228 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49229
49230 /* To indicate add/delete/modify during CCN */
49231 u8 change_detected;
49232 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49233 index 5f174b8..98d32b0 100644
49234 --- a/drivers/scsi/qla2xxx/qla_attr.c
49235 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49236 @@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49237 return 0;
49238 }
49239
49240 -struct fc_function_template qla2xxx_transport_functions = {
49241 +fc_function_template_no_const qla2xxx_transport_functions = {
49242
49243 .show_host_node_name = 1,
49244 .show_host_port_name = 1,
49245 @@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49246 .bsg_timeout = qla24xx_bsg_timeout,
49247 };
49248
49249 -struct fc_function_template qla2xxx_transport_vport_functions = {
49250 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49251
49252 .show_host_node_name = 1,
49253 .show_host_port_name = 1,
49254 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49255 index 4446bf5..9a3574d 100644
49256 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49257 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49258 @@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49259 struct device_attribute;
49260 extern struct device_attribute *qla2x00_host_attrs[];
49261 struct fc_function_template;
49262 -extern struct fc_function_template qla2xxx_transport_functions;
49263 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49264 +extern fc_function_template_no_const qla2xxx_transport_functions;
49265 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49266 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49267 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
49268 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49269 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49270 index 52be35e..b933907 100644
49271 --- a/drivers/scsi/qla2xxx/qla_os.c
49272 +++ b/drivers/scsi/qla2xxx/qla_os.c
49273 @@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49274 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49275 /* Ok, a 64bit DMA mask is applicable. */
49276 ha->flags.enable_64bit_addressing = 1;
49277 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49278 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49279 + pax_open_kernel();
49280 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49281 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49282 + pax_close_kernel();
49283 return;
49284 }
49285 }
49286 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49287 index 084d1fd..9f939eb 100644
49288 --- a/drivers/scsi/qla4xxx/ql4_def.h
49289 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49290 @@ -296,7 +296,7 @@ struct ddb_entry {
49291 * (4000 only) */
49292 atomic_t relogin_timer; /* Max Time to wait for
49293 * relogin to complete */
49294 - atomic_t relogin_retry_count; /* Num of times relogin has been
49295 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49296 * retried */
49297 uint32_t default_time2wait; /* Default Min time between
49298 * relogins (+aens) */
49299 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49300 index cf174a4..128a420 100644
49301 --- a/drivers/scsi/qla4xxx/ql4_os.c
49302 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49303 @@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49304 */
49305 if (!iscsi_is_session_online(cls_sess)) {
49306 /* Reset retry relogin timer */
49307 - atomic_inc(&ddb_entry->relogin_retry_count);
49308 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49309 DEBUG2(ql4_printk(KERN_INFO, ha,
49310 "%s: index[%d] relogin timed out-retrying"
49311 " relogin (%d), retry (%d)\n", __func__,
49312 ddb_entry->fw_ddb_index,
49313 - atomic_read(&ddb_entry->relogin_retry_count),
49314 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49315 ddb_entry->default_time2wait + 4));
49316 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49317 atomic_set(&ddb_entry->retry_relogin_timer,
49318 @@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49319
49320 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49321 atomic_set(&ddb_entry->relogin_timer, 0);
49322 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49323 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49324 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49325 ddb_entry->default_relogin_timeout =
49326 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49327 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49328 index fe0bcb1..c9255be 100644
49329 --- a/drivers/scsi/scsi.c
49330 +++ b/drivers/scsi/scsi.c
49331 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49332 struct Scsi_Host *host = cmd->device->host;
49333 int rtn = 0;
49334
49335 - atomic_inc(&cmd->device->iorequest_cnt);
49336 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49337
49338 /* check if the device is still usable */
49339 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49340 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49341 index 7bd7f0d..93159d8 100644
49342 --- a/drivers/scsi/scsi_lib.c
49343 +++ b/drivers/scsi/scsi_lib.c
49344 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49345 shost = sdev->host;
49346 scsi_init_cmd_errh(cmd);
49347 cmd->result = DID_NO_CONNECT << 16;
49348 - atomic_inc(&cmd->device->iorequest_cnt);
49349 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49350
49351 /*
49352 * SCSI request completion path will do scsi_device_unbusy(),
49353 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49354
49355 INIT_LIST_HEAD(&cmd->eh_entry);
49356
49357 - atomic_inc(&cmd->device->iodone_cnt);
49358 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49359 if (cmd->result)
49360 - atomic_inc(&cmd->device->ioerr_cnt);
49361 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49362
49363 disposition = scsi_decide_disposition(cmd);
49364 if (disposition != SUCCESS &&
49365 @@ -1684,7 +1684,7 @@ u64 scsi_calculate_bounce_limit(struct Scsi_Host *shost)
49366
49367 host_dev = scsi_get_device(shost);
49368 if (host_dev && host_dev->dma_mask)
49369 - bounce_limit = dma_max_pfn(host_dev) << PAGE_SHIFT;
49370 + bounce_limit = (u64)dma_max_pfn(host_dev) << PAGE_SHIFT;
49371
49372 return bounce_limit;
49373 }
49374 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49375 index 8ff62c2..693b6f7 100644
49376 --- a/drivers/scsi/scsi_sysfs.c
49377 +++ b/drivers/scsi/scsi_sysfs.c
49378 @@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49379 char *buf) \
49380 { \
49381 struct scsi_device *sdev = to_scsi_device(dev); \
49382 - unsigned long long count = atomic_read(&sdev->field); \
49383 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49384 return snprintf(buf, 20, "0x%llx\n", count); \
49385 } \
49386 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49387 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49388 index 84a1fdf..693b0d6 100644
49389 --- a/drivers/scsi/scsi_tgt_lib.c
49390 +++ b/drivers/scsi/scsi_tgt_lib.c
49391 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49392 int err;
49393
49394 dprintk("%lx %u\n", uaddr, len);
49395 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49396 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49397 if (err) {
49398 /*
49399 * TODO: need to fixup sg_tablesize, max_segment_size,
49400 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49401 index 4628fd5..a94a1c2 100644
49402 --- a/drivers/scsi/scsi_transport_fc.c
49403 +++ b/drivers/scsi/scsi_transport_fc.c
49404 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49405 * Netlink Infrastructure
49406 */
49407
49408 -static atomic_t fc_event_seq;
49409 +static atomic_unchecked_t fc_event_seq;
49410
49411 /**
49412 * fc_get_event_number - Obtain the next sequential FC event number
49413 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49414 u32
49415 fc_get_event_number(void)
49416 {
49417 - return atomic_add_return(1, &fc_event_seq);
49418 + return atomic_add_return_unchecked(1, &fc_event_seq);
49419 }
49420 EXPORT_SYMBOL(fc_get_event_number);
49421
49422 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49423 {
49424 int error;
49425
49426 - atomic_set(&fc_event_seq, 0);
49427 + atomic_set_unchecked(&fc_event_seq, 0);
49428
49429 error = transport_class_register(&fc_host_class);
49430 if (error)
49431 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49432 char *cp;
49433
49434 *val = simple_strtoul(buf, &cp, 0);
49435 - if ((*cp && (*cp != '\n')) || (*val < 0))
49436 + if (*cp && (*cp != '\n'))
49437 return -EINVAL;
49438 /*
49439 * Check for overflow; dev_loss_tmo is u32
49440 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49441 index 63a6ca4..5d5cadd 100644
49442 --- a/drivers/scsi/scsi_transport_iscsi.c
49443 +++ b/drivers/scsi/scsi_transport_iscsi.c
49444 @@ -79,7 +79,7 @@ struct iscsi_internal {
49445 struct transport_container session_cont;
49446 };
49447
49448 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49449 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49450 static struct workqueue_struct *iscsi_eh_timer_workq;
49451
49452 static DEFINE_IDA(iscsi_sess_ida);
49453 @@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49454 int err;
49455
49456 ihost = shost->shost_data;
49457 - session->sid = atomic_add_return(1, &iscsi_session_nr);
49458 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49459
49460 if (target_id == ISCSI_MAX_TARGET) {
49461 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49462 @@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
49463 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49464 ISCSI_TRANSPORT_VERSION);
49465
49466 - atomic_set(&iscsi_session_nr, 0);
49467 + atomic_set_unchecked(&iscsi_session_nr, 0);
49468
49469 err = class_register(&iscsi_transport_class);
49470 if (err)
49471 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49472 index 2700a5a..752ec38 100644
49473 --- a/drivers/scsi/scsi_transport_srp.c
49474 +++ b/drivers/scsi/scsi_transport_srp.c
49475 @@ -36,7 +36,7 @@
49476 #include "scsi_transport_srp_internal.h"
49477
49478 struct srp_host_attrs {
49479 - atomic_t next_port_id;
49480 + atomic_unchecked_t next_port_id;
49481 };
49482 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49483
49484 @@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49485 struct Scsi_Host *shost = dev_to_shost(dev);
49486 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49487
49488 - atomic_set(&srp_host->next_port_id, 0);
49489 + atomic_set_unchecked(&srp_host->next_port_id, 0);
49490 return 0;
49491 }
49492
49493 @@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49494 rport_fast_io_fail_timedout);
49495 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49496
49497 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49498 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49499 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49500
49501 transport_setup_device(&rport->dev);
49502 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49503 index 69725f7..03aaee1 100644
49504 --- a/drivers/scsi/sd.c
49505 +++ b/drivers/scsi/sd.c
49506 @@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
49507 sdkp->disk = gd;
49508 sdkp->index = index;
49509 atomic_set(&sdkp->openers, 0);
49510 - atomic_set(&sdkp->device->ioerr_cnt, 0);
49511 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49512
49513 if (!sdp->request_queue->rq_timeout) {
49514 if (sdp->type != TYPE_MOD)
49515 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49516 index df5e961..df6b97f 100644
49517 --- a/drivers/scsi/sg.c
49518 +++ b/drivers/scsi/sg.c
49519 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49520 sdp->disk->disk_name,
49521 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49522 NULL,
49523 - (char *)arg);
49524 + (char __user *)arg);
49525 case BLKTRACESTART:
49526 return blk_trace_startstop(sdp->device->request_queue, 1);
49527 case BLKTRACESTOP:
49528 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49529 index 349ebba..ff2a249 100644
49530 --- a/drivers/spi/spi.c
49531 +++ b/drivers/spi/spi.c
49532 @@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
49533 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49534
49535 /* portable code must never pass more than 32 bytes */
49536 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49537 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49538
49539 static u8 *buf;
49540
49541 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49542 index 2c61783..4d49e4e 100644
49543 --- a/drivers/staging/android/timed_output.c
49544 +++ b/drivers/staging/android/timed_output.c
49545 @@ -25,7 +25,7 @@
49546 #include "timed_output.h"
49547
49548 static struct class *timed_output_class;
49549 -static atomic_t device_count;
49550 +static atomic_unchecked_t device_count;
49551
49552 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49553 char *buf)
49554 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49555 timed_output_class = class_create(THIS_MODULE, "timed_output");
49556 if (IS_ERR(timed_output_class))
49557 return PTR_ERR(timed_output_class);
49558 - atomic_set(&device_count, 0);
49559 + atomic_set_unchecked(&device_count, 0);
49560 timed_output_class->dev_groups = timed_output_groups;
49561 }
49562
49563 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49564 if (ret < 0)
49565 return ret;
49566
49567 - tdev->index = atomic_inc_return(&device_count);
49568 + tdev->index = atomic_inc_return_unchecked(&device_count);
49569 tdev->dev = device_create(timed_output_class, NULL,
49570 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49571 if (IS_ERR(tdev->dev))
49572 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49573 index c0f7cd7..5424212 100644
49574 --- a/drivers/staging/gdm724x/gdm_tty.c
49575 +++ b/drivers/staging/gdm724x/gdm_tty.c
49576 @@ -45,7 +45,7 @@
49577 #define gdm_tty_send_control(n, r, v, d, l) (\
49578 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49579
49580 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49581 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49582
49583 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49584 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49585 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49586 index 96e4eee..6d7c37e 100644
49587 --- a/drivers/staging/imx-drm/imx-drm-core.c
49588 +++ b/drivers/staging/imx-drm/imx-drm-core.c
49589 @@ -510,7 +510,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49590 goto err_busy;
49591 }
49592
49593 - if (imxdrm->drm->open_count) {
49594 + if (local_read(&imxdrm->drm->open_count)) {
49595 ret = -EBUSY;
49596 goto err_busy;
49597 }
49598 @@ -590,7 +590,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49599
49600 mutex_lock(&imxdrm->mutex);
49601
49602 - if (imxdrm->drm->open_count) {
49603 + if (local_read(&imxdrm->drm->open_count)) {
49604 ret = -EBUSY;
49605 goto err_busy;
49606 }
49607 @@ -729,7 +729,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49608
49609 mutex_lock(&imxdrm->mutex);
49610
49611 - if (imxdrm->drm->open_count) {
49612 + if (local_read(&imxdrm->drm->open_count)) {
49613 ret = -EBUSY;
49614 goto err_busy;
49615 }
49616 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49617 index b7613c8..c302392 100644
49618 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49619 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49620 @@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49621 return 0;
49622 }
49623
49624 -sfw_test_client_ops_t brw_test_client;
49625 -void brw_init_test_client(void)
49626 -{
49627 - brw_test_client.tso_init = brw_client_init;
49628 - brw_test_client.tso_fini = brw_client_fini;
49629 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49630 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
49631 +sfw_test_client_ops_t brw_test_client = {
49632 + .tso_init = brw_client_init,
49633 + .tso_fini = brw_client_fini,
49634 + .tso_prep_rpc = brw_client_prep_rpc,
49635 + .tso_done_rpc = brw_client_done_rpc,
49636 };
49637
49638 srpc_service_t brw_test_service;
49639 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49640 index 483c785..e1a2a7b 100644
49641 --- a/drivers/staging/lustre/lnet/selftest/framework.c
49642 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
49643 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49644
49645 extern sfw_test_client_ops_t ping_test_client;
49646 extern srpc_service_t ping_test_service;
49647 -extern void ping_init_test_client(void);
49648 extern void ping_init_test_service(void);
49649
49650 extern sfw_test_client_ops_t brw_test_client;
49651 extern srpc_service_t brw_test_service;
49652 -extern void brw_init_test_client(void);
49653 extern void brw_init_test_service(void);
49654
49655
49656 @@ -1684,12 +1682,10 @@ sfw_startup (void)
49657 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49658 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49659
49660 - brw_init_test_client();
49661 brw_init_test_service();
49662 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49663 LASSERT (rc == 0);
49664
49665 - ping_init_test_client();
49666 ping_init_test_service();
49667 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49668 LASSERT (rc == 0);
49669 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49670 index f0f9194..b589047 100644
49671 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49672 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49673 @@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49674 return 0;
49675 }
49676
49677 -sfw_test_client_ops_t ping_test_client;
49678 -void ping_init_test_client(void)
49679 -{
49680 - ping_test_client.tso_init = ping_client_init;
49681 - ping_test_client.tso_fini = ping_client_fini;
49682 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49683 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49684 -}
49685 +sfw_test_client_ops_t ping_test_client = {
49686 + .tso_init = ping_client_init,
49687 + .tso_fini = ping_client_fini,
49688 + .tso_prep_rpc = ping_client_prep_rpc,
49689 + .tso_done_rpc = ping_client_done_rpc,
49690 +};
49691
49692 srpc_service_t ping_test_service;
49693 void ping_init_test_service(void)
49694 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49695 index bc2b82f..67fd598 100644
49696 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49697 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49698 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49699 ldlm_completion_callback lcs_completion;
49700 ldlm_blocking_callback lcs_blocking;
49701 ldlm_glimpse_callback lcs_glimpse;
49702 -};
49703 +} __no_const;
49704
49705 /* ldlm_lockd.c */
49706 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49707 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49708 index d0aea15..7af68e1 100644
49709 --- a/drivers/staging/lustre/lustre/include/obd.h
49710 +++ b/drivers/staging/lustre/lustre/include/obd.h
49711 @@ -1417,7 +1417,7 @@ struct md_ops {
49712 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49713 * wrapper function in include/linux/obd_class.h.
49714 */
49715 -};
49716 +} __no_const;
49717
49718 struct lsm_operations {
49719 void (*lsm_free)(struct lov_stripe_md *);
49720 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49721 index 39fcdac..222780f 100644
49722 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49723 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49724 @@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49725 int added = (mode == LCK_NL);
49726 int overlaps = 0;
49727 int splitted = 0;
49728 - const struct ldlm_callback_suite null_cbs = { NULL };
49729 + const struct ldlm_callback_suite null_cbs = { };
49730 int rc;
49731
49732 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49733 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49734 index fc6c977..df1f956 100644
49735 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49736 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49737 @@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49738 int LL_PROC_PROTO(proc_console_max_delay_cs)
49739 {
49740 int rc, max_delay_cs;
49741 - ctl_table_t dummy = *table;
49742 + ctl_table_no_const dummy = *table;
49743 cfs_duration_t d;
49744
49745 dummy.data = &max_delay_cs;
49746 @@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49747 int LL_PROC_PROTO(proc_console_min_delay_cs)
49748 {
49749 int rc, min_delay_cs;
49750 - ctl_table_t dummy = *table;
49751 + ctl_table_no_const dummy = *table;
49752 cfs_duration_t d;
49753
49754 dummy.data = &min_delay_cs;
49755 @@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49756 int LL_PROC_PROTO(proc_console_backoff)
49757 {
49758 int rc, backoff;
49759 - ctl_table_t dummy = *table;
49760 + ctl_table_no_const dummy = *table;
49761
49762 dummy.data = &backoff;
49763 dummy.proc_handler = &proc_dointvec;
49764 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49765 index f3108c7..cd4f9da 100644
49766 --- a/drivers/staging/lustre/lustre/libcfs/module.c
49767 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
49768 @@ -348,11 +348,11 @@ out:
49769
49770
49771 struct cfs_psdev_ops libcfs_psdev_ops = {
49772 - libcfs_psdev_open,
49773 - libcfs_psdev_release,
49774 - NULL,
49775 - NULL,
49776 - libcfs_ioctl
49777 + .p_open = libcfs_psdev_open,
49778 + .p_close = libcfs_psdev_release,
49779 + .p_read = NULL,
49780 + .p_write = NULL,
49781 + .p_ioctl = libcfs_ioctl
49782 };
49783
49784 extern int insert_proc(void);
49785 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49786 index a4e0472..05d854c 100644
49787 --- a/drivers/staging/lustre/lustre/llite/dir.c
49788 +++ b/drivers/staging/lustre/lustre/llite/dir.c
49789 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49790 int mode;
49791 int err;
49792
49793 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49794 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49795 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49796 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49797 lump);
49798 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49799 index 3675020..e80d92c 100644
49800 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
49801 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49802 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49803
49804 static int solo_sysfs_init(struct solo_dev *solo_dev)
49805 {
49806 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49807 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49808 struct device *dev = &solo_dev->dev;
49809 const char *driver;
49810 int i;
49811 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49812 index 1db18c7..35e6afc 100644
49813 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49814 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49815 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49816
49817 int solo_g723_init(struct solo_dev *solo_dev)
49818 {
49819 - static struct snd_device_ops ops = { NULL };
49820 + static struct snd_device_ops ops = { };
49821 struct snd_card *card;
49822 struct snd_kcontrol_new kctl;
49823 char name[32];
49824 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49825 index 7f2f247..d999137 100644
49826 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49827 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49828 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49829
49830 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49831 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49832 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49833 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49834 if (p2m_id < 0)
49835 p2m_id = -p2m_id;
49836 }
49837 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49838 index f1bbb8c..a73eaba 100644
49839 --- a/drivers/staging/media/solo6x10/solo6x10.h
49840 +++ b/drivers/staging/media/solo6x10/solo6x10.h
49841 @@ -237,7 +237,7 @@ struct solo_dev {
49842
49843 /* P2M DMA Engine */
49844 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49845 - atomic_t p2m_count;
49846 + atomic_unchecked_t p2m_count;
49847 int p2m_jiffies;
49848 unsigned int p2m_timeouts;
49849
49850 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49851 index 0315f60..ce93f406 100644
49852 --- a/drivers/staging/octeon/ethernet-rx.c
49853 +++ b/drivers/staging/octeon/ethernet-rx.c
49854 @@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49855 /* Increment RX stats for virtual ports */
49856 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49857 #ifdef CONFIG_64BIT
49858 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49859 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49860 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49861 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49862 #else
49863 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49864 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49865 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49866 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49867 #endif
49868 }
49869 netif_receive_skb(skb);
49870 @@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49871 dev->name);
49872 */
49873 #ifdef CONFIG_64BIT
49874 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49875 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49876 #else
49877 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49878 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49879 #endif
49880 dev_kfree_skb_irq(skb);
49881 }
49882 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49883 index bd6ca71..8f0961e 100644
49884 --- a/drivers/staging/octeon/ethernet.c
49885 +++ b/drivers/staging/octeon/ethernet.c
49886 @@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49887 * since the RX tasklet also increments it.
49888 */
49889 #ifdef CONFIG_64BIT
49890 - atomic64_add(rx_status.dropped_packets,
49891 - (atomic64_t *)&priv->stats.rx_dropped);
49892 + atomic64_add_unchecked(rx_status.dropped_packets,
49893 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49894 #else
49895 - atomic_add(rx_status.dropped_packets,
49896 - (atomic_t *)&priv->stats.rx_dropped);
49897 + atomic_add_unchecked(rx_status.dropped_packets,
49898 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
49899 #endif
49900 }
49901
49902 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49903 index 439c3c9..2d74293 100644
49904 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
49905 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49906 @@ -271,7 +271,7 @@ struct hal_ops {
49907 s32 (*c2h_handler)(struct adapter *padapter,
49908 struct c2h_evt_hdr *c2h_evt);
49909 c2h_id_filter c2h_id_filter_ccx;
49910 -};
49911 +} __no_const;
49912
49913 enum rt_eeprom_type {
49914 EEPROM_93C46,
49915 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49916 index eb6f0e5..e6a0958 100644
49917 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
49918 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49919 @@ -126,7 +126,7 @@ struct _io_ops {
49920 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
49921 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49922 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49923 -};
49924 +} __no_const;
49925
49926 struct io_req {
49927 struct list_head list;
49928 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49929 index dc23395..cf7e9b1 100644
49930 --- a/drivers/staging/rtl8712/rtl871x_io.h
49931 +++ b/drivers/staging/rtl8712/rtl871x_io.h
49932 @@ -108,7 +108,7 @@ struct _io_ops {
49933 u8 *pmem);
49934 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49935 u8 *pmem);
49936 -};
49937 +} __no_const;
49938
49939 struct io_req {
49940 struct list_head list;
49941 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49942 index 1f5088b..0e59820 100644
49943 --- a/drivers/staging/sbe-2t3e3/netdev.c
49944 +++ b/drivers/staging/sbe-2t3e3/netdev.c
49945 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49946 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49947
49948 if (rlen)
49949 - if (copy_to_user(data, &resp, rlen))
49950 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49951 return -EFAULT;
49952
49953 return 0;
49954 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49955 index a863a98..d272795 100644
49956 --- a/drivers/staging/usbip/vhci.h
49957 +++ b/drivers/staging/usbip/vhci.h
49958 @@ -83,7 +83,7 @@ struct vhci_hcd {
49959 unsigned resuming:1;
49960 unsigned long re_timeout;
49961
49962 - atomic_t seqnum;
49963 + atomic_unchecked_t seqnum;
49964
49965 /*
49966 * NOTE:
49967 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49968 index e810ad5..931336f 100644
49969 --- a/drivers/staging/usbip/vhci_hcd.c
49970 +++ b/drivers/staging/usbip/vhci_hcd.c
49971 @@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
49972
49973 spin_lock(&vdev->priv_lock);
49974
49975 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49976 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49977 if (priv->seqnum == 0xffff)
49978 dev_info(&urb->dev->dev, "seqnum max\n");
49979
49980 @@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49981 return -ENOMEM;
49982 }
49983
49984 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
49985 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49986 if (unlink->seqnum == 0xffff)
49987 pr_info("seqnum max\n");
49988
49989 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
49990 vdev->rhport = rhport;
49991 }
49992
49993 - atomic_set(&vhci->seqnum, 0);
49994 + atomic_set_unchecked(&vhci->seqnum, 0);
49995 spin_lock_init(&vhci->lock);
49996
49997 hcd->power_budget = 0; /* no limit */
49998 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
49999 index d07fcb5..358e1e1 100644
50000 --- a/drivers/staging/usbip/vhci_rx.c
50001 +++ b/drivers/staging/usbip/vhci_rx.c
50002 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50003 if (!urb) {
50004 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50005 pr_info("max seqnum %d\n",
50006 - atomic_read(&the_controller->seqnum));
50007 + atomic_read_unchecked(&the_controller->seqnum));
50008 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50009 return;
50010 }
50011 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50012 index ab8b2ba..99184aa 100644
50013 --- a/drivers/staging/vt6655/hostap.c
50014 +++ b/drivers/staging/vt6655/hostap.c
50015 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50016 *
50017 */
50018
50019 +static net_device_ops_no_const apdev_netdev_ops;
50020 +
50021 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50022 {
50023 PSDevice apdev_priv;
50024 struct net_device *dev = pDevice->dev;
50025 int ret;
50026 - const struct net_device_ops apdev_netdev_ops = {
50027 - .ndo_start_xmit = pDevice->tx_80211,
50028 - };
50029
50030 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50031
50032 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50033 *apdev_priv = *pDevice;
50034 eth_hw_addr_inherit(pDevice->apdev, dev);
50035
50036 + /* only half broken now */
50037 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50038 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50039
50040 pDevice->apdev->type = ARPHRD_IEEE80211;
50041 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50042 index 67ba48b..24e602f 100644
50043 --- a/drivers/staging/vt6656/hostap.c
50044 +++ b/drivers/staging/vt6656/hostap.c
50045 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50046 *
50047 */
50048
50049 +static net_device_ops_no_const apdev_netdev_ops;
50050 +
50051 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50052 {
50053 struct vnt_private *apdev_priv;
50054 struct net_device *dev = pDevice->dev;
50055 int ret;
50056 - const struct net_device_ops apdev_netdev_ops = {
50057 - .ndo_start_xmit = pDevice->tx_80211,
50058 - };
50059
50060 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50061
50062 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50063 *apdev_priv = *pDevice;
50064 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50065
50066 + /* only half broken now */
50067 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50068 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50069
50070 pDevice->apdev->type = ARPHRD_IEEE80211;
50071 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50072 index 24884ca..26c8220 100644
50073 --- a/drivers/target/sbp/sbp_target.c
50074 +++ b/drivers/target/sbp/sbp_target.c
50075 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50076
50077 #define SESSION_MAINTENANCE_INTERVAL HZ
50078
50079 -static atomic_t login_id = ATOMIC_INIT(0);
50080 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50081
50082 static void session_maintenance_work(struct work_struct *);
50083 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50084 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50085 login->lun = se_lun;
50086 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50087 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50088 - login->login_id = atomic_inc_return(&login_id);
50089 + login->login_id = atomic_inc_return_unchecked(&login_id);
50090
50091 login->tgt_agt = sbp_target_agent_register(login);
50092 if (IS_ERR(login->tgt_agt)) {
50093 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50094 index d06de84..fd38c9b 100644
50095 --- a/drivers/target/target_core_device.c
50096 +++ b/drivers/target/target_core_device.c
50097 @@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50098 spin_lock_init(&dev->se_tmr_lock);
50099 spin_lock_init(&dev->qf_cmd_lock);
50100 sema_init(&dev->caw_sem, 1);
50101 - atomic_set(&dev->dev_ordered_id, 0);
50102 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50103 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50104 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50105 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50106 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50107 index dee2be1..f5fd8ca 100644
50108 --- a/drivers/target/target_core_transport.c
50109 +++ b/drivers/target/target_core_transport.c
50110 @@ -1113,7 +1113,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50111 * Used to determine when ORDERED commands should go from
50112 * Dormant to Active status.
50113 */
50114 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50115 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50116 smp_mb__after_atomic_inc();
50117 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50118 cmd->se_ordered_id, cmd->sam_task_attr,
50119 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50120 index 33f83fe..d80f8e1 100644
50121 --- a/drivers/tty/cyclades.c
50122 +++ b/drivers/tty/cyclades.c
50123 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50124 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50125 info->port.count);
50126 #endif
50127 - info->port.count++;
50128 + atomic_inc(&info->port.count);
50129 #ifdef CY_DEBUG_COUNT
50130 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50131 - current->pid, info->port.count);
50132 + current->pid, atomic_read(&info->port.count));
50133 #endif
50134
50135 /*
50136 @@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50137 for (j = 0; j < cy_card[i].nports; j++) {
50138 info = &cy_card[i].ports[j];
50139
50140 - if (info->port.count) {
50141 + if (atomic_read(&info->port.count)) {
50142 /* XXX is the ldisc num worth this? */
50143 struct tty_struct *tty;
50144 struct tty_ldisc *ld;
50145 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50146 index 9eba119..5070303 100644
50147 --- a/drivers/tty/hvc/hvc_console.c
50148 +++ b/drivers/tty/hvc/hvc_console.c
50149 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50150
50151 spin_lock_irqsave(&hp->port.lock, flags);
50152 /* Check and then increment for fast path open. */
50153 - if (hp->port.count++ > 0) {
50154 + if (atomic_inc_return(&hp->port.count) > 1) {
50155 spin_unlock_irqrestore(&hp->port.lock, flags);
50156 hvc_kick();
50157 return 0;
50158 @@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50159
50160 spin_lock_irqsave(&hp->port.lock, flags);
50161
50162 - if (--hp->port.count == 0) {
50163 + if (atomic_dec_return(&hp->port.count) == 0) {
50164 spin_unlock_irqrestore(&hp->port.lock, flags);
50165 /* We are done with the tty pointer now. */
50166 tty_port_tty_set(&hp->port, NULL);
50167 @@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50168 */
50169 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50170 } else {
50171 - if (hp->port.count < 0)
50172 + if (atomic_read(&hp->port.count) < 0)
50173 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50174 - hp->vtermno, hp->port.count);
50175 + hp->vtermno, atomic_read(&hp->port.count));
50176 spin_unlock_irqrestore(&hp->port.lock, flags);
50177 }
50178 }
50179 @@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
50180 * open->hangup case this can be called after the final close so prevent
50181 * that from happening for now.
50182 */
50183 - if (hp->port.count <= 0) {
50184 + if (atomic_read(&hp->port.count) <= 0) {
50185 spin_unlock_irqrestore(&hp->port.lock, flags);
50186 return;
50187 }
50188
50189 - hp->port.count = 0;
50190 + atomic_set(&hp->port.count, 0);
50191 spin_unlock_irqrestore(&hp->port.lock, flags);
50192 tty_port_tty_set(&hp->port, NULL);
50193
50194 @@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50195 return -EPIPE;
50196
50197 /* FIXME what's this (unprotected) check for? */
50198 - if (hp->port.count <= 0)
50199 + if (atomic_read(&hp->port.count) <= 0)
50200 return -EIO;
50201
50202 spin_lock_irqsave(&hp->lock, flags);
50203 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50204 index 81e939e..95ead10 100644
50205 --- a/drivers/tty/hvc/hvcs.c
50206 +++ b/drivers/tty/hvc/hvcs.c
50207 @@ -83,6 +83,7 @@
50208 #include <asm/hvcserver.h>
50209 #include <asm/uaccess.h>
50210 #include <asm/vio.h>
50211 +#include <asm/local.h>
50212
50213 /*
50214 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50215 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50216
50217 spin_lock_irqsave(&hvcsd->lock, flags);
50218
50219 - if (hvcsd->port.count > 0) {
50220 + if (atomic_read(&hvcsd->port.count) > 0) {
50221 spin_unlock_irqrestore(&hvcsd->lock, flags);
50222 printk(KERN_INFO "HVCS: vterm state unchanged. "
50223 "The hvcs device node is still in use.\n");
50224 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50225 }
50226 }
50227
50228 - hvcsd->port.count = 0;
50229 + atomic_set(&hvcsd->port.count, 0);
50230 hvcsd->port.tty = tty;
50231 tty->driver_data = hvcsd;
50232
50233 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50234 unsigned long flags;
50235
50236 spin_lock_irqsave(&hvcsd->lock, flags);
50237 - hvcsd->port.count++;
50238 + atomic_inc(&hvcsd->port.count);
50239 hvcsd->todo_mask |= HVCS_SCHED_READ;
50240 spin_unlock_irqrestore(&hvcsd->lock, flags);
50241
50242 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50243 hvcsd = tty->driver_data;
50244
50245 spin_lock_irqsave(&hvcsd->lock, flags);
50246 - if (--hvcsd->port.count == 0) {
50247 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50248
50249 vio_disable_interrupts(hvcsd->vdev);
50250
50251 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50252
50253 free_irq(irq, hvcsd);
50254 return;
50255 - } else if (hvcsd->port.count < 0) {
50256 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50257 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50258 " is missmanaged.\n",
50259 - hvcsd->vdev->unit_address, hvcsd->port.count);
50260 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50261 }
50262
50263 spin_unlock_irqrestore(&hvcsd->lock, flags);
50264 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50265
50266 spin_lock_irqsave(&hvcsd->lock, flags);
50267 /* Preserve this so that we know how many kref refs to put */
50268 - temp_open_count = hvcsd->port.count;
50269 + temp_open_count = atomic_read(&hvcsd->port.count);
50270
50271 /*
50272 * Don't kref put inside the spinlock because the destruction
50273 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50274 tty->driver_data = NULL;
50275 hvcsd->port.tty = NULL;
50276
50277 - hvcsd->port.count = 0;
50278 + atomic_set(&hvcsd->port.count, 0);
50279
50280 /* This will drop any buffered data on the floor which is OK in a hangup
50281 * scenario. */
50282 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50283 * the middle of a write operation? This is a crummy place to do this
50284 * but we want to keep it all in the spinlock.
50285 */
50286 - if (hvcsd->port.count <= 0) {
50287 + if (atomic_read(&hvcsd->port.count) <= 0) {
50288 spin_unlock_irqrestore(&hvcsd->lock, flags);
50289 return -ENODEV;
50290 }
50291 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50292 {
50293 struct hvcs_struct *hvcsd = tty->driver_data;
50294
50295 - if (!hvcsd || hvcsd->port.count <= 0)
50296 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50297 return 0;
50298
50299 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50300 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50301 index 4190199..06d5bfa 100644
50302 --- a/drivers/tty/hvc/hvsi.c
50303 +++ b/drivers/tty/hvc/hvsi.c
50304 @@ -85,7 +85,7 @@ struct hvsi_struct {
50305 int n_outbuf;
50306 uint32_t vtermno;
50307 uint32_t virq;
50308 - atomic_t seqno; /* HVSI packet sequence number */
50309 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50310 uint16_t mctrl;
50311 uint8_t state; /* HVSI protocol state */
50312 uint8_t flags;
50313 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50314
50315 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50316 packet.hdr.len = sizeof(struct hvsi_query_response);
50317 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50318 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50319 packet.verb = VSV_SEND_VERSION_NUMBER;
50320 packet.u.version = HVSI_VERSION;
50321 packet.query_seqno = query_seqno+1;
50322 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50323
50324 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50325 packet.hdr.len = sizeof(struct hvsi_query);
50326 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50327 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50328 packet.verb = verb;
50329
50330 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50331 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50332 int wrote;
50333
50334 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50335 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50336 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50337 packet.hdr.len = sizeof(struct hvsi_control);
50338 packet.verb = VSV_SET_MODEM_CTL;
50339 packet.mask = HVSI_TSDTR;
50340 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50341 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50342
50343 packet.hdr.type = VS_DATA_PACKET_HEADER;
50344 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50345 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50346 packet.hdr.len = count + sizeof(struct hvsi_header);
50347 memcpy(&packet.data, buf, count);
50348
50349 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50350 struct hvsi_control packet __ALIGNED__;
50351
50352 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50353 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50354 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50355 packet.hdr.len = 6;
50356 packet.verb = VSV_CLOSE_PROTOCOL;
50357
50358 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50359
50360 tty_port_tty_set(&hp->port, tty);
50361 spin_lock_irqsave(&hp->lock, flags);
50362 - hp->port.count++;
50363 + atomic_inc(&hp->port.count);
50364 atomic_set(&hp->seqno, 0);
50365 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50366 spin_unlock_irqrestore(&hp->lock, flags);
50367 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50368
50369 spin_lock_irqsave(&hp->lock, flags);
50370
50371 - if (--hp->port.count == 0) {
50372 + if (atomic_dec_return(&hp->port.count) == 0) {
50373 tty_port_tty_set(&hp->port, NULL);
50374 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50375
50376 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50377
50378 spin_lock_irqsave(&hp->lock, flags);
50379 }
50380 - } else if (hp->port.count < 0)
50381 + } else if (atomic_read(&hp->port.count) < 0)
50382 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50383 - hp - hvsi_ports, hp->port.count);
50384 + hp - hvsi_ports, atomic_read(&hp->port.count));
50385
50386 spin_unlock_irqrestore(&hp->lock, flags);
50387 }
50388 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50389 tty_port_tty_set(&hp->port, NULL);
50390
50391 spin_lock_irqsave(&hp->lock, flags);
50392 - hp->port.count = 0;
50393 + atomic_set(&hp->port.count, 0);
50394 hp->n_outbuf = 0;
50395 spin_unlock_irqrestore(&hp->lock, flags);
50396 }
50397 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50398 index 347050e..14f8fbf 100644
50399 --- a/drivers/tty/hvc/hvsi_lib.c
50400 +++ b/drivers/tty/hvc/hvsi_lib.c
50401 @@ -9,7 +9,7 @@
50402
50403 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50404 {
50405 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50406 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50407
50408 /* Assumes that always succeeds, works in practice */
50409 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50410 @@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50411
50412 /* Reset state */
50413 pv->established = 0;
50414 - atomic_set(&pv->seqno, 0);
50415 + atomic_set_unchecked(&pv->seqno, 0);
50416
50417 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50418
50419 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50420 index 8fd72ff..34a0bed 100644
50421 --- a/drivers/tty/ipwireless/tty.c
50422 +++ b/drivers/tty/ipwireless/tty.c
50423 @@ -29,6 +29,7 @@
50424 #include <linux/tty_driver.h>
50425 #include <linux/tty_flip.h>
50426 #include <linux/uaccess.h>
50427 +#include <asm/local.h>
50428
50429 #include "tty.h"
50430 #include "network.h"
50431 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50432 mutex_unlock(&tty->ipw_tty_mutex);
50433 return -ENODEV;
50434 }
50435 - if (tty->port.count == 0)
50436 + if (atomic_read(&tty->port.count) == 0)
50437 tty->tx_bytes_queued = 0;
50438
50439 - tty->port.count++;
50440 + atomic_inc(&tty->port.count);
50441
50442 tty->port.tty = linux_tty;
50443 linux_tty->driver_data = tty;
50444 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50445
50446 static void do_ipw_close(struct ipw_tty *tty)
50447 {
50448 - tty->port.count--;
50449 -
50450 - if (tty->port.count == 0) {
50451 + if (atomic_dec_return(&tty->port.count) == 0) {
50452 struct tty_struct *linux_tty = tty->port.tty;
50453
50454 if (linux_tty != NULL) {
50455 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50456 return;
50457
50458 mutex_lock(&tty->ipw_tty_mutex);
50459 - if (tty->port.count == 0) {
50460 + if (atomic_read(&tty->port.count) == 0) {
50461 mutex_unlock(&tty->ipw_tty_mutex);
50462 return;
50463 }
50464 @@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50465
50466 mutex_lock(&tty->ipw_tty_mutex);
50467
50468 - if (!tty->port.count) {
50469 + if (!atomic_read(&tty->port.count)) {
50470 mutex_unlock(&tty->ipw_tty_mutex);
50471 return;
50472 }
50473 @@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50474 return -ENODEV;
50475
50476 mutex_lock(&tty->ipw_tty_mutex);
50477 - if (!tty->port.count) {
50478 + if (!atomic_read(&tty->port.count)) {
50479 mutex_unlock(&tty->ipw_tty_mutex);
50480 return -EINVAL;
50481 }
50482 @@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50483 if (!tty)
50484 return -ENODEV;
50485
50486 - if (!tty->port.count)
50487 + if (!atomic_read(&tty->port.count))
50488 return -EINVAL;
50489
50490 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50491 @@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50492 if (!tty)
50493 return 0;
50494
50495 - if (!tty->port.count)
50496 + if (!atomic_read(&tty->port.count))
50497 return 0;
50498
50499 return tty->tx_bytes_queued;
50500 @@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50501 if (!tty)
50502 return -ENODEV;
50503
50504 - if (!tty->port.count)
50505 + if (!atomic_read(&tty->port.count))
50506 return -EINVAL;
50507
50508 return get_control_lines(tty);
50509 @@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50510 if (!tty)
50511 return -ENODEV;
50512
50513 - if (!tty->port.count)
50514 + if (!atomic_read(&tty->port.count))
50515 return -EINVAL;
50516
50517 return set_control_lines(tty, set, clear);
50518 @@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50519 if (!tty)
50520 return -ENODEV;
50521
50522 - if (!tty->port.count)
50523 + if (!atomic_read(&tty->port.count))
50524 return -EINVAL;
50525
50526 /* FIXME: Exactly how is the tty object locked here .. */
50527 @@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50528 * are gone */
50529 mutex_lock(&ttyj->ipw_tty_mutex);
50530 }
50531 - while (ttyj->port.count)
50532 + while (atomic_read(&ttyj->port.count))
50533 do_ipw_close(ttyj);
50534 ipwireless_disassociate_network_ttys(network,
50535 ttyj->channel_idx);
50536 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50537 index 1deaca4..c8582d4 100644
50538 --- a/drivers/tty/moxa.c
50539 +++ b/drivers/tty/moxa.c
50540 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50541 }
50542
50543 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50544 - ch->port.count++;
50545 + atomic_inc(&ch->port.count);
50546 tty->driver_data = ch;
50547 tty_port_tty_set(&ch->port, tty);
50548 mutex_lock(&ch->port.mutex);
50549 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50550 index 5056090..c80ca04 100644
50551 --- a/drivers/tty/n_gsm.c
50552 +++ b/drivers/tty/n_gsm.c
50553 @@ -1643,7 +1643,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50554 spin_lock_init(&dlci->lock);
50555 mutex_init(&dlci->mutex);
50556 dlci->fifo = &dlci->_fifo;
50557 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50558 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50559 kfree(dlci);
50560 return NULL;
50561 }
50562 @@ -2946,7 +2946,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50563 struct gsm_dlci *dlci = tty->driver_data;
50564 struct tty_port *port = &dlci->port;
50565
50566 - port->count++;
50567 + atomic_inc(&port->count);
50568 dlci_get(dlci);
50569 dlci_get(dlci->gsm->dlci[0]);
50570 mux_get(dlci->gsm);
50571 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50572 index 4c10837..a40ec45 100644
50573 --- a/drivers/tty/n_tty.c
50574 +++ b/drivers/tty/n_tty.c
50575 @@ -114,7 +114,7 @@ struct n_tty_data {
50576 int minimum_to_wake;
50577
50578 /* consumer-published */
50579 - size_t read_tail;
50580 + size_t read_tail __intentional_overflow(-1);
50581 size_t line_start;
50582
50583 /* protected by output lock */
50584 @@ -2504,6 +2504,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50585 {
50586 *ops = tty_ldisc_N_TTY;
50587 ops->owner = NULL;
50588 - ops->refcount = ops->flags = 0;
50589 + atomic_set(&ops->refcount, 0);
50590 + ops->flags = 0;
50591 }
50592 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50593 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50594 index 25c9bc7..24077b7 100644
50595 --- a/drivers/tty/pty.c
50596 +++ b/drivers/tty/pty.c
50597 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50598 panic("Couldn't register Unix98 pts driver");
50599
50600 /* Now create the /dev/ptmx special device */
50601 + pax_open_kernel();
50602 tty_default_fops(&ptmx_fops);
50603 - ptmx_fops.open = ptmx_open;
50604 + *(void **)&ptmx_fops.open = ptmx_open;
50605 + pax_close_kernel();
50606
50607 cdev_init(&ptmx_cdev, &ptmx_fops);
50608 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50609 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50610 index 354564e..fe50d9a 100644
50611 --- a/drivers/tty/rocket.c
50612 +++ b/drivers/tty/rocket.c
50613 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50614 tty->driver_data = info;
50615 tty_port_tty_set(port, tty);
50616
50617 - if (port->count++ == 0) {
50618 + if (atomic_inc_return(&port->count) == 1) {
50619 atomic_inc(&rp_num_ports_open);
50620
50621 #ifdef ROCKET_DEBUG_OPEN
50622 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50623 #endif
50624 }
50625 #ifdef ROCKET_DEBUG_OPEN
50626 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50627 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50628 #endif
50629
50630 /*
50631 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50632 spin_unlock_irqrestore(&info->port.lock, flags);
50633 return;
50634 }
50635 - if (info->port.count)
50636 + if (atomic_read(&info->port.count))
50637 atomic_dec(&rp_num_ports_open);
50638 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50639 spin_unlock_irqrestore(&info->port.lock, flags);
50640 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50641 index 1274499..f541382 100644
50642 --- a/drivers/tty/serial/ioc4_serial.c
50643 +++ b/drivers/tty/serial/ioc4_serial.c
50644 @@ -437,7 +437,7 @@ struct ioc4_soft {
50645 } is_intr_info[MAX_IOC4_INTR_ENTS];
50646
50647 /* Number of entries active in the above array */
50648 - atomic_t is_num_intrs;
50649 + atomic_unchecked_t is_num_intrs;
50650 } is_intr_type[IOC4_NUM_INTR_TYPES];
50651
50652 /* is_ir_lock must be held while
50653 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50654 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50655 || (type == IOC4_OTHER_INTR_TYPE)));
50656
50657 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50658 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50659 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50660
50661 /* Save off the lower level interrupt handler */
50662 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50663
50664 soft = arg;
50665 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50666 - num_intrs = (int)atomic_read(
50667 + num_intrs = (int)atomic_read_unchecked(
50668 &soft->is_intr_type[intr_type].is_num_intrs);
50669
50670 this_mir = this_ir = pending_intrs(soft, intr_type);
50671 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50672 index a260cde..6b2b5ce 100644
50673 --- a/drivers/tty/serial/kgdboc.c
50674 +++ b/drivers/tty/serial/kgdboc.c
50675 @@ -24,8 +24,9 @@
50676 #define MAX_CONFIG_LEN 40
50677
50678 static struct kgdb_io kgdboc_io_ops;
50679 +static struct kgdb_io kgdboc_io_ops_console;
50680
50681 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50682 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50683 static int configured = -1;
50684
50685 static char config[MAX_CONFIG_LEN];
50686 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50687 kgdboc_unregister_kbd();
50688 if (configured == 1)
50689 kgdb_unregister_io_module(&kgdboc_io_ops);
50690 + else if (configured == 2)
50691 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
50692 }
50693
50694 static int configure_kgdboc(void)
50695 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50696 int err;
50697 char *cptr = config;
50698 struct console *cons;
50699 + int is_console = 0;
50700
50701 err = kgdboc_option_setup(config);
50702 if (err || !strlen(config) || isspace(config[0]))
50703 goto noconfig;
50704
50705 err = -ENODEV;
50706 - kgdboc_io_ops.is_console = 0;
50707 kgdb_tty_driver = NULL;
50708
50709 kgdboc_use_kms = 0;
50710 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50711 int idx;
50712 if (cons->device && cons->device(cons, &idx) == p &&
50713 idx == tty_line) {
50714 - kgdboc_io_ops.is_console = 1;
50715 + is_console = 1;
50716 break;
50717 }
50718 cons = cons->next;
50719 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50720 kgdb_tty_line = tty_line;
50721
50722 do_register:
50723 - err = kgdb_register_io_module(&kgdboc_io_ops);
50724 + if (is_console) {
50725 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
50726 + configured = 2;
50727 + } else {
50728 + err = kgdb_register_io_module(&kgdboc_io_ops);
50729 + configured = 1;
50730 + }
50731 if (err)
50732 goto noconfig;
50733
50734 @@ -205,8 +214,6 @@ do_register:
50735 if (err)
50736 goto nmi_con_failed;
50737
50738 - configured = 1;
50739 -
50740 return 0;
50741
50742 nmi_con_failed:
50743 @@ -223,7 +230,7 @@ noconfig:
50744 static int __init init_kgdboc(void)
50745 {
50746 /* Already configured? */
50747 - if (configured == 1)
50748 + if (configured >= 1)
50749 return 0;
50750
50751 return configure_kgdboc();
50752 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50753 if (config[len - 1] == '\n')
50754 config[len - 1] = '\0';
50755
50756 - if (configured == 1)
50757 + if (configured >= 1)
50758 cleanup_kgdboc();
50759
50760 /* Go and configure with the new params. */
50761 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50762 .post_exception = kgdboc_post_exp_handler,
50763 };
50764
50765 +static struct kgdb_io kgdboc_io_ops_console = {
50766 + .name = "kgdboc",
50767 + .read_char = kgdboc_get_char,
50768 + .write_char = kgdboc_put_char,
50769 + .pre_exception = kgdboc_pre_exp_handler,
50770 + .post_exception = kgdboc_post_exp_handler,
50771 + .is_console = 1
50772 +};
50773 +
50774 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50775 /* This is only available if kgdboc is a built in for early debugging */
50776 static int __init kgdboc_early_init(char *opt)
50777 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50778 index b5d779c..3622cfe 100644
50779 --- a/drivers/tty/serial/msm_serial.c
50780 +++ b/drivers/tty/serial/msm_serial.c
50781 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50782 .cons = MSM_CONSOLE,
50783 };
50784
50785 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50786 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50787
50788 static const struct of_device_id msm_uartdm_table[] = {
50789 { .compatible = "qcom,msm-uartdm" },
50790 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50791 int irq;
50792
50793 if (pdev->id == -1)
50794 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50795 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50796
50797 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50798 return -ENXIO;
50799 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50800 index c1af04d..0815c8a 100644
50801 --- a/drivers/tty/serial/samsung.c
50802 +++ b/drivers/tty/serial/samsung.c
50803 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50804 }
50805 }
50806
50807 +static int s3c64xx_serial_startup(struct uart_port *port);
50808 static int s3c24xx_serial_startup(struct uart_port *port)
50809 {
50810 struct s3c24xx_uart_port *ourport = to_ourport(port);
50811 int ret;
50812
50813 + /* Startup sequence is different for s3c64xx and higher SoC's */
50814 + if (s3c24xx_serial_has_interrupt_mask(port))
50815 + return s3c64xx_serial_startup(port);
50816 +
50817 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50818 port->mapbase, port->membase);
50819
50820 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50821 /* setup info for port */
50822 port->dev = &platdev->dev;
50823
50824 - /* Startup sequence is different for s3c64xx and higher SoC's */
50825 - if (s3c24xx_serial_has_interrupt_mask(port))
50826 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50827 -
50828 port->uartclk = 1;
50829
50830 if (cfg->uart_flags & UPF_CONS_FLOW) {
50831 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50832 index 0f02351..07c59c5 100644
50833 --- a/drivers/tty/serial/serial_core.c
50834 +++ b/drivers/tty/serial/serial_core.c
50835 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50836 uart_flush_buffer(tty);
50837 uart_shutdown(tty, state);
50838 spin_lock_irqsave(&port->lock, flags);
50839 - port->count = 0;
50840 + atomic_set(&port->count, 0);
50841 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50842 spin_unlock_irqrestore(&port->lock, flags);
50843 tty_port_tty_set(port, NULL);
50844 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50845 goto end;
50846 }
50847
50848 - port->count++;
50849 + atomic_inc(&port->count);
50850 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50851 retval = -ENXIO;
50852 goto err_dec_count;
50853 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50854 /*
50855 * Make sure the device is in D0 state.
50856 */
50857 - if (port->count == 1)
50858 + if (atomic_read(&port->count) == 1)
50859 uart_change_pm(state, UART_PM_STATE_ON);
50860
50861 /*
50862 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50863 end:
50864 return retval;
50865 err_dec_count:
50866 - port->count--;
50867 + atomic_inc(&port->count);
50868 mutex_unlock(&port->mutex);
50869 goto end;
50870 }
50871 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50872 index e1ce141..6d4ed80 100644
50873 --- a/drivers/tty/synclink.c
50874 +++ b/drivers/tty/synclink.c
50875 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50876
50877 if (debug_level >= DEBUG_LEVEL_INFO)
50878 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50879 - __FILE__,__LINE__, info->device_name, info->port.count);
50880 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50881
50882 if (tty_port_close_start(&info->port, tty, filp) == 0)
50883 goto cleanup;
50884 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50885 cleanup:
50886 if (debug_level >= DEBUG_LEVEL_INFO)
50887 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50888 - tty->driver->name, info->port.count);
50889 + tty->driver->name, atomic_read(&info->port.count));
50890
50891 } /* end of mgsl_close() */
50892
50893 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50894
50895 mgsl_flush_buffer(tty);
50896 shutdown(info);
50897 -
50898 - info->port.count = 0;
50899 +
50900 + atomic_set(&info->port.count, 0);
50901 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50902 info->port.tty = NULL;
50903
50904 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50905
50906 if (debug_level >= DEBUG_LEVEL_INFO)
50907 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50908 - __FILE__,__LINE__, tty->driver->name, port->count );
50909 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50910
50911 spin_lock_irqsave(&info->irq_spinlock, flags);
50912 if (!tty_hung_up_p(filp)) {
50913 extra_count = true;
50914 - port->count--;
50915 + atomic_dec(&port->count);
50916 }
50917 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50918 port->blocked_open++;
50919 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50920
50921 if (debug_level >= DEBUG_LEVEL_INFO)
50922 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50923 - __FILE__,__LINE__, tty->driver->name, port->count );
50924 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50925
50926 tty_unlock(tty);
50927 schedule();
50928 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50929
50930 /* FIXME: Racy on hangup during close wait */
50931 if (extra_count)
50932 - port->count++;
50933 + atomic_inc(&port->count);
50934 port->blocked_open--;
50935
50936 if (debug_level >= DEBUG_LEVEL_INFO)
50937 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50938 - __FILE__,__LINE__, tty->driver->name, port->count );
50939 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50940
50941 if (!retval)
50942 port->flags |= ASYNC_NORMAL_ACTIVE;
50943 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50944
50945 if (debug_level >= DEBUG_LEVEL_INFO)
50946 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50947 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50948 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50949
50950 /* If port is closing, signal caller to try again */
50951 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50952 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50953 spin_unlock_irqrestore(&info->netlock, flags);
50954 goto cleanup;
50955 }
50956 - info->port.count++;
50957 + atomic_inc(&info->port.count);
50958 spin_unlock_irqrestore(&info->netlock, flags);
50959
50960 - if (info->port.count == 1) {
50961 + if (atomic_read(&info->port.count) == 1) {
50962 /* 1st open on this device, init hardware */
50963 retval = startup(info);
50964 if (retval < 0)
50965 @@ -3446,8 +3446,8 @@ cleanup:
50966 if (retval) {
50967 if (tty->count == 1)
50968 info->port.tty = NULL; /* tty layer will release tty struct */
50969 - if(info->port.count)
50970 - info->port.count--;
50971 + if (atomic_read(&info->port.count))
50972 + atomic_dec(&info->port.count);
50973 }
50974
50975 return retval;
50976 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50977 unsigned short new_crctype;
50978
50979 /* return error if TTY interface open */
50980 - if (info->port.count)
50981 + if (atomic_read(&info->port.count))
50982 return -EBUSY;
50983
50984 switch (encoding)
50985 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
50986
50987 /* arbitrate between network and tty opens */
50988 spin_lock_irqsave(&info->netlock, flags);
50989 - if (info->port.count != 0 || info->netcount != 0) {
50990 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50991 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50992 spin_unlock_irqrestore(&info->netlock, flags);
50993 return -EBUSY;
50994 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50995 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50996
50997 /* return error if TTY interface open */
50998 - if (info->port.count)
50999 + if (atomic_read(&info->port.count))
51000 return -EBUSY;
51001
51002 if (cmd != SIOCWANDEV)
51003 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51004 index 1abf946..1ee34fc 100644
51005 --- a/drivers/tty/synclink_gt.c
51006 +++ b/drivers/tty/synclink_gt.c
51007 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51008 tty->driver_data = info;
51009 info->port.tty = tty;
51010
51011 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51012 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51013
51014 /* If port is closing, signal caller to try again */
51015 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51016 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51017 mutex_unlock(&info->port.mutex);
51018 goto cleanup;
51019 }
51020 - info->port.count++;
51021 + atomic_inc(&info->port.count);
51022 spin_unlock_irqrestore(&info->netlock, flags);
51023
51024 - if (info->port.count == 1) {
51025 + if (atomic_read(&info->port.count) == 1) {
51026 /* 1st open on this device, init hardware */
51027 retval = startup(info);
51028 if (retval < 0) {
51029 @@ -715,8 +715,8 @@ cleanup:
51030 if (retval) {
51031 if (tty->count == 1)
51032 info->port.tty = NULL; /* tty layer will release tty struct */
51033 - if(info->port.count)
51034 - info->port.count--;
51035 + if(atomic_read(&info->port.count))
51036 + atomic_dec(&info->port.count);
51037 }
51038
51039 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51040 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51041
51042 if (sanity_check(info, tty->name, "close"))
51043 return;
51044 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51045 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51046
51047 if (tty_port_close_start(&info->port, tty, filp) == 0)
51048 goto cleanup;
51049 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51050 tty_port_close_end(&info->port, tty);
51051 info->port.tty = NULL;
51052 cleanup:
51053 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51054 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51055 }
51056
51057 static void hangup(struct tty_struct *tty)
51058 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51059 shutdown(info);
51060
51061 spin_lock_irqsave(&info->port.lock, flags);
51062 - info->port.count = 0;
51063 + atomic_set(&info->port.count, 0);
51064 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51065 info->port.tty = NULL;
51066 spin_unlock_irqrestore(&info->port.lock, flags);
51067 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51068 unsigned short new_crctype;
51069
51070 /* return error if TTY interface open */
51071 - if (info->port.count)
51072 + if (atomic_read(&info->port.count))
51073 return -EBUSY;
51074
51075 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51076 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51077
51078 /* arbitrate between network and tty opens */
51079 spin_lock_irqsave(&info->netlock, flags);
51080 - if (info->port.count != 0 || info->netcount != 0) {
51081 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51082 DBGINFO(("%s hdlc_open busy\n", dev->name));
51083 spin_unlock_irqrestore(&info->netlock, flags);
51084 return -EBUSY;
51085 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51086 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51087
51088 /* return error if TTY interface open */
51089 - if (info->port.count)
51090 + if (atomic_read(&info->port.count))
51091 return -EBUSY;
51092
51093 if (cmd != SIOCWANDEV)
51094 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51095 if (port == NULL)
51096 continue;
51097 spin_lock(&port->lock);
51098 - if ((port->port.count || port->netcount) &&
51099 + if ((atomic_read(&port->port.count) || port->netcount) &&
51100 port->pending_bh && !port->bh_running &&
51101 !port->bh_requested) {
51102 DBGISR(("%s bh queued\n", port->device_name));
51103 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51104 spin_lock_irqsave(&info->lock, flags);
51105 if (!tty_hung_up_p(filp)) {
51106 extra_count = true;
51107 - port->count--;
51108 + atomic_dec(&port->count);
51109 }
51110 spin_unlock_irqrestore(&info->lock, flags);
51111 port->blocked_open++;
51112 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51113 remove_wait_queue(&port->open_wait, &wait);
51114
51115 if (extra_count)
51116 - port->count++;
51117 + atomic_inc(&port->count);
51118 port->blocked_open--;
51119
51120 if (!retval)
51121 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51122 index dc6e969..5dc8786 100644
51123 --- a/drivers/tty/synclinkmp.c
51124 +++ b/drivers/tty/synclinkmp.c
51125 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51126
51127 if (debug_level >= DEBUG_LEVEL_INFO)
51128 printk("%s(%d):%s open(), old ref count = %d\n",
51129 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51130 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51131
51132 /* If port is closing, signal caller to try again */
51133 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51134 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51135 spin_unlock_irqrestore(&info->netlock, flags);
51136 goto cleanup;
51137 }
51138 - info->port.count++;
51139 + atomic_inc(&info->port.count);
51140 spin_unlock_irqrestore(&info->netlock, flags);
51141
51142 - if (info->port.count == 1) {
51143 + if (atomic_read(&info->port.count) == 1) {
51144 /* 1st open on this device, init hardware */
51145 retval = startup(info);
51146 if (retval < 0)
51147 @@ -796,8 +796,8 @@ cleanup:
51148 if (retval) {
51149 if (tty->count == 1)
51150 info->port.tty = NULL; /* tty layer will release tty struct */
51151 - if(info->port.count)
51152 - info->port.count--;
51153 + if(atomic_read(&info->port.count))
51154 + atomic_dec(&info->port.count);
51155 }
51156
51157 return retval;
51158 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51159
51160 if (debug_level >= DEBUG_LEVEL_INFO)
51161 printk("%s(%d):%s close() entry, count=%d\n",
51162 - __FILE__,__LINE__, info->device_name, info->port.count);
51163 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51164
51165 if (tty_port_close_start(&info->port, tty, filp) == 0)
51166 goto cleanup;
51167 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51168 cleanup:
51169 if (debug_level >= DEBUG_LEVEL_INFO)
51170 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51171 - tty->driver->name, info->port.count);
51172 + tty->driver->name, atomic_read(&info->port.count));
51173 }
51174
51175 /* Called by tty_hangup() when a hangup is signaled.
51176 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51177 shutdown(info);
51178
51179 spin_lock_irqsave(&info->port.lock, flags);
51180 - info->port.count = 0;
51181 + atomic_set(&info->port.count, 0);
51182 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51183 info->port.tty = NULL;
51184 spin_unlock_irqrestore(&info->port.lock, flags);
51185 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51186 unsigned short new_crctype;
51187
51188 /* return error if TTY interface open */
51189 - if (info->port.count)
51190 + if (atomic_read(&info->port.count))
51191 return -EBUSY;
51192
51193 switch (encoding)
51194 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51195
51196 /* arbitrate between network and tty opens */
51197 spin_lock_irqsave(&info->netlock, flags);
51198 - if (info->port.count != 0 || info->netcount != 0) {
51199 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51200 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51201 spin_unlock_irqrestore(&info->netlock, flags);
51202 return -EBUSY;
51203 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51204 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51205
51206 /* return error if TTY interface open */
51207 - if (info->port.count)
51208 + if (atomic_read(&info->port.count))
51209 return -EBUSY;
51210
51211 if (cmd != SIOCWANDEV)
51212 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51213 * do not request bottom half processing if the
51214 * device is not open in a normal mode.
51215 */
51216 - if ( port && (port->port.count || port->netcount) &&
51217 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51218 port->pending_bh && !port->bh_running &&
51219 !port->bh_requested ) {
51220 if ( debug_level >= DEBUG_LEVEL_ISR )
51221 @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51222
51223 if (debug_level >= DEBUG_LEVEL_INFO)
51224 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51225 - __FILE__,__LINE__, tty->driver->name, port->count );
51226 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51227
51228 spin_lock_irqsave(&info->lock, flags);
51229 if (!tty_hung_up_p(filp)) {
51230 extra_count = true;
51231 - port->count--;
51232 + atomic_dec(&port->count);
51233 }
51234 spin_unlock_irqrestore(&info->lock, flags);
51235 port->blocked_open++;
51236 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51237
51238 if (debug_level >= DEBUG_LEVEL_INFO)
51239 printk("%s(%d):%s block_til_ready() count=%d\n",
51240 - __FILE__,__LINE__, tty->driver->name, port->count );
51241 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51242
51243 tty_unlock(tty);
51244 schedule();
51245 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51246 remove_wait_queue(&port->open_wait, &wait);
51247
51248 if (extra_count)
51249 - port->count++;
51250 + atomic_inc(&port->count);
51251 port->blocked_open--;
51252
51253 if (debug_level >= DEBUG_LEVEL_INFO)
51254 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51255 - __FILE__,__LINE__, tty->driver->name, port->count );
51256 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51257
51258 if (!retval)
51259 port->flags |= ASYNC_NORMAL_ACTIVE;
51260 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51261 index ce396ec..04a37be 100644
51262 --- a/drivers/tty/sysrq.c
51263 +++ b/drivers/tty/sysrq.c
51264 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51265 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51266 size_t count, loff_t *ppos)
51267 {
51268 - if (count) {
51269 + if (count && capable(CAP_SYS_ADMIN)) {
51270 char c;
51271
51272 if (get_user(c, buf))
51273 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51274 index c74a00a..02cf211a 100644
51275 --- a/drivers/tty/tty_io.c
51276 +++ b/drivers/tty/tty_io.c
51277 @@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51278
51279 void tty_default_fops(struct file_operations *fops)
51280 {
51281 - *fops = tty_fops;
51282 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51283 }
51284
51285 /*
51286 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51287 index 6458e11..6cfc218 100644
51288 --- a/drivers/tty/tty_ldisc.c
51289 +++ b/drivers/tty/tty_ldisc.c
51290 @@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51291 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51292 tty_ldiscs[disc] = new_ldisc;
51293 new_ldisc->num = disc;
51294 - new_ldisc->refcount = 0;
51295 + atomic_set(&new_ldisc->refcount, 0);
51296 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51297
51298 return ret;
51299 @@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
51300 return -EINVAL;
51301
51302 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51303 - if (tty_ldiscs[disc]->refcount)
51304 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51305 ret = -EBUSY;
51306 else
51307 tty_ldiscs[disc] = NULL;
51308 @@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51309 if (ldops) {
51310 ret = ERR_PTR(-EAGAIN);
51311 if (try_module_get(ldops->owner)) {
51312 - ldops->refcount++;
51313 + atomic_inc(&ldops->refcount);
51314 ret = ldops;
51315 }
51316 }
51317 @@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51318 unsigned long flags;
51319
51320 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51321 - ldops->refcount--;
51322 + atomic_dec(&ldops->refcount);
51323 module_put(ldops->owner);
51324 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51325 }
51326 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51327 index c94d234..8210f2d 100644
51328 --- a/drivers/tty/tty_port.c
51329 +++ b/drivers/tty/tty_port.c
51330 @@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
51331 unsigned long flags;
51332
51333 spin_lock_irqsave(&port->lock, flags);
51334 - port->count = 0;
51335 + atomic_set(&port->count, 0);
51336 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51337 tty = port->tty;
51338 if (tty)
51339 @@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51340 /* The port lock protects the port counts */
51341 spin_lock_irqsave(&port->lock, flags);
51342 if (!tty_hung_up_p(filp))
51343 - port->count--;
51344 + atomic_dec(&port->count);
51345 port->blocked_open++;
51346 spin_unlock_irqrestore(&port->lock, flags);
51347
51348 @@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51349 we must not mess that up further */
51350 spin_lock_irqsave(&port->lock, flags);
51351 if (!tty_hung_up_p(filp))
51352 - port->count++;
51353 + atomic_inc(&port->count);
51354 port->blocked_open--;
51355 if (retval == 0)
51356 port->flags |= ASYNC_NORMAL_ACTIVE;
51357 @@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
51358 return 0;
51359 }
51360
51361 - if (tty->count == 1 && port->count != 1) {
51362 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51363 printk(KERN_WARNING
51364 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51365 - port->count);
51366 - port->count = 1;
51367 + atomic_read(&port->count));
51368 + atomic_set(&port->count, 1);
51369 }
51370 - if (--port->count < 0) {
51371 + if (atomic_dec_return(&port->count) < 0) {
51372 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51373 - port->count);
51374 - port->count = 0;
51375 + atomic_read(&port->count));
51376 + atomic_set(&port->count, 0);
51377 }
51378
51379 - if (port->count) {
51380 + if (atomic_read(&port->count)) {
51381 spin_unlock_irqrestore(&port->lock, flags);
51382 return 0;
51383 }
51384 @@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51385 {
51386 spin_lock_irq(&port->lock);
51387 if (!tty_hung_up_p(filp))
51388 - ++port->count;
51389 + atomic_inc(&port->count);
51390 spin_unlock_irq(&port->lock);
51391 tty_port_tty_set(port, tty);
51392
51393 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51394 index d0e3a44..5f8b754 100644
51395 --- a/drivers/tty/vt/keyboard.c
51396 +++ b/drivers/tty/vt/keyboard.c
51397 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51398 kbd->kbdmode == VC_OFF) &&
51399 value != KVAL(K_SAK))
51400 return; /* SAK is allowed even in raw mode */
51401 +
51402 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51403 + {
51404 + void *func = fn_handler[value];
51405 + if (func == fn_show_state || func == fn_show_ptregs ||
51406 + func == fn_show_mem)
51407 + return;
51408 + }
51409 +#endif
51410 +
51411 fn_handler[value](vc);
51412 }
51413
51414 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51415 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51416 return -EFAULT;
51417
51418 - if (!capable(CAP_SYS_TTY_CONFIG))
51419 - perm = 0;
51420 -
51421 switch (cmd) {
51422 case KDGKBENT:
51423 /* Ensure another thread doesn't free it under us */
51424 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51425 spin_unlock_irqrestore(&kbd_event_lock, flags);
51426 return put_user(val, &user_kbe->kb_value);
51427 case KDSKBENT:
51428 + if (!capable(CAP_SYS_TTY_CONFIG))
51429 + perm = 0;
51430 +
51431 if (!perm)
51432 return -EPERM;
51433 if (!i && v == K_NOSUCHMAP) {
51434 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51435 int i, j, k;
51436 int ret;
51437
51438 - if (!capable(CAP_SYS_TTY_CONFIG))
51439 - perm = 0;
51440 -
51441 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51442 if (!kbs) {
51443 ret = -ENOMEM;
51444 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51445 kfree(kbs);
51446 return ((p && *p) ? -EOVERFLOW : 0);
51447 case KDSKBSENT:
51448 + if (!capable(CAP_SYS_TTY_CONFIG))
51449 + perm = 0;
51450 +
51451 if (!perm) {
51452 ret = -EPERM;
51453 goto reterr;
51454 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51455 index a673e5b..36e5d32 100644
51456 --- a/drivers/uio/uio.c
51457 +++ b/drivers/uio/uio.c
51458 @@ -25,6 +25,7 @@
51459 #include <linux/kobject.h>
51460 #include <linux/cdev.h>
51461 #include <linux/uio_driver.h>
51462 +#include <asm/local.h>
51463
51464 #define UIO_MAX_DEVICES (1U << MINORBITS)
51465
51466 @@ -32,7 +33,7 @@ struct uio_device {
51467 struct module *owner;
51468 struct device *dev;
51469 int minor;
51470 - atomic_t event;
51471 + atomic_unchecked_t event;
51472 struct fasync_struct *async_queue;
51473 wait_queue_head_t wait;
51474 struct uio_info *info;
51475 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51476 struct device_attribute *attr, char *buf)
51477 {
51478 struct uio_device *idev = dev_get_drvdata(dev);
51479 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51480 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51481 }
51482 static DEVICE_ATTR_RO(event);
51483
51484 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51485 {
51486 struct uio_device *idev = info->uio_dev;
51487
51488 - atomic_inc(&idev->event);
51489 + atomic_inc_unchecked(&idev->event);
51490 wake_up_interruptible(&idev->wait);
51491 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51492 }
51493 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51494 }
51495
51496 listener->dev = idev;
51497 - listener->event_count = atomic_read(&idev->event);
51498 + listener->event_count = atomic_read_unchecked(&idev->event);
51499 filep->private_data = listener;
51500
51501 if (idev->info->open) {
51502 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51503 return -EIO;
51504
51505 poll_wait(filep, &idev->wait, wait);
51506 - if (listener->event_count != atomic_read(&idev->event))
51507 + if (listener->event_count != atomic_read_unchecked(&idev->event))
51508 return POLLIN | POLLRDNORM;
51509 return 0;
51510 }
51511 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51512 do {
51513 set_current_state(TASK_INTERRUPTIBLE);
51514
51515 - event_count = atomic_read(&idev->event);
51516 + event_count = atomic_read_unchecked(&idev->event);
51517 if (event_count != listener->event_count) {
51518 if (copy_to_user(buf, &event_count, count))
51519 retval = -EFAULT;
51520 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51521 static int uio_find_mem_index(struct vm_area_struct *vma)
51522 {
51523 struct uio_device *idev = vma->vm_private_data;
51524 + unsigned long size;
51525
51526 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51527 - if (idev->info->mem[vma->vm_pgoff].size == 0)
51528 + size = idev->info->mem[vma->vm_pgoff].size;
51529 + if (size == 0)
51530 + return -1;
51531 + if (vma->vm_end - vma->vm_start > size)
51532 return -1;
51533 return (int)vma->vm_pgoff;
51534 }
51535 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51536 idev->owner = owner;
51537 idev->info = info;
51538 init_waitqueue_head(&idev->wait);
51539 - atomic_set(&idev->event, 0);
51540 + atomic_set_unchecked(&idev->event, 0);
51541
51542 ret = uio_get_minor(idev);
51543 if (ret)
51544 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51545 index 8a7eb77..c00402f 100644
51546 --- a/drivers/usb/atm/cxacru.c
51547 +++ b/drivers/usb/atm/cxacru.c
51548 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51549 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51550 if (ret < 2)
51551 return -EINVAL;
51552 - if (index < 0 || index > 0x7f)
51553 + if (index > 0x7f)
51554 return -EINVAL;
51555 pos += tmp;
51556
51557 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51558 index 25a7bfc..57f3cf5 100644
51559 --- a/drivers/usb/atm/usbatm.c
51560 +++ b/drivers/usb/atm/usbatm.c
51561 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51562 if (printk_ratelimit())
51563 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51564 __func__, vpi, vci);
51565 - atomic_inc(&vcc->stats->rx_err);
51566 + atomic_inc_unchecked(&vcc->stats->rx_err);
51567 return;
51568 }
51569
51570 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51571 if (length > ATM_MAX_AAL5_PDU) {
51572 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51573 __func__, length, vcc);
51574 - atomic_inc(&vcc->stats->rx_err);
51575 + atomic_inc_unchecked(&vcc->stats->rx_err);
51576 goto out;
51577 }
51578
51579 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51580 if (sarb->len < pdu_length) {
51581 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51582 __func__, pdu_length, sarb->len, vcc);
51583 - atomic_inc(&vcc->stats->rx_err);
51584 + atomic_inc_unchecked(&vcc->stats->rx_err);
51585 goto out;
51586 }
51587
51588 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51589 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51590 __func__, vcc);
51591 - atomic_inc(&vcc->stats->rx_err);
51592 + atomic_inc_unchecked(&vcc->stats->rx_err);
51593 goto out;
51594 }
51595
51596 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51597 if (printk_ratelimit())
51598 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51599 __func__, length);
51600 - atomic_inc(&vcc->stats->rx_drop);
51601 + atomic_inc_unchecked(&vcc->stats->rx_drop);
51602 goto out;
51603 }
51604
51605 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51606
51607 vcc->push(vcc, skb);
51608
51609 - atomic_inc(&vcc->stats->rx);
51610 + atomic_inc_unchecked(&vcc->stats->rx);
51611 out:
51612 skb_trim(sarb, 0);
51613 }
51614 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51615 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51616
51617 usbatm_pop(vcc, skb);
51618 - atomic_inc(&vcc->stats->tx);
51619 + atomic_inc_unchecked(&vcc->stats->tx);
51620
51621 skb = skb_dequeue(&instance->sndqueue);
51622 }
51623 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
51624 if (!left--)
51625 return sprintf(page,
51626 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51627 - atomic_read(&atm_dev->stats.aal5.tx),
51628 - atomic_read(&atm_dev->stats.aal5.tx_err),
51629 - atomic_read(&atm_dev->stats.aal5.rx),
51630 - atomic_read(&atm_dev->stats.aal5.rx_err),
51631 - atomic_read(&atm_dev->stats.aal5.rx_drop));
51632 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51633 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51634 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51635 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51636 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51637
51638 if (!left--) {
51639 if (instance->disconnected)
51640 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51641 index 2a3bbdf..91d72cf 100644
51642 --- a/drivers/usb/core/devices.c
51643 +++ b/drivers/usb/core/devices.c
51644 @@ -126,7 +126,7 @@ static const char format_endpt[] =
51645 * time it gets called.
51646 */
51647 static struct device_connect_event {
51648 - atomic_t count;
51649 + atomic_unchecked_t count;
51650 wait_queue_head_t wait;
51651 } device_event = {
51652 .count = ATOMIC_INIT(1),
51653 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51654
51655 void usbfs_conn_disc_event(void)
51656 {
51657 - atomic_add(2, &device_event.count);
51658 + atomic_add_unchecked(2, &device_event.count);
51659 wake_up(&device_event.wait);
51660 }
51661
51662 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51663
51664 poll_wait(file, &device_event.wait, wait);
51665
51666 - event_count = atomic_read(&device_event.count);
51667 + event_count = atomic_read_unchecked(&device_event.count);
51668 if (file->f_version != event_count) {
51669 file->f_version = event_count;
51670 return POLLIN | POLLRDNORM;
51671 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51672 index 967152a..16fa2e5 100644
51673 --- a/drivers/usb/core/devio.c
51674 +++ b/drivers/usb/core/devio.c
51675 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51676 struct dev_state *ps = file->private_data;
51677 struct usb_device *dev = ps->dev;
51678 ssize_t ret = 0;
51679 - unsigned len;
51680 + size_t len;
51681 loff_t pos;
51682 int i;
51683
51684 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51685 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51686 struct usb_config_descriptor *config =
51687 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51688 - unsigned int length = le16_to_cpu(config->wTotalLength);
51689 + size_t length = le16_to_cpu(config->wTotalLength);
51690
51691 if (*ppos < pos + length) {
51692
51693 /* The descriptor may claim to be longer than it
51694 * really is. Here is the actual allocated length. */
51695 - unsigned alloclen =
51696 + size_t alloclen =
51697 le16_to_cpu(dev->config[i].desc.wTotalLength);
51698
51699 - len = length - (*ppos - pos);
51700 + len = length + pos - *ppos;
51701 if (len > nbytes)
51702 len = nbytes;
51703
51704 /* Simply don't write (skip over) unallocated parts */
51705 if (alloclen > (*ppos - pos)) {
51706 - alloclen -= (*ppos - pos);
51707 + alloclen = alloclen + pos - *ppos;
51708 if (copy_to_user(buf,
51709 dev->rawdescriptors[i] + (*ppos - pos),
51710 min(len, alloclen))) {
51711 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51712 index d39106c..bfe13a4 100644
51713 --- a/drivers/usb/core/hcd.c
51714 +++ b/drivers/usb/core/hcd.c
51715 @@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51716 */
51717 usb_get_urb(urb);
51718 atomic_inc(&urb->use_count);
51719 - atomic_inc(&urb->dev->urbnum);
51720 + atomic_inc_unchecked(&urb->dev->urbnum);
51721 usbmon_urb_submit(&hcd->self, urb);
51722
51723 /* NOTE requirements on root-hub callers (usbfs and the hub
51724 @@ -1576,7 +1576,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51725 urb->hcpriv = NULL;
51726 INIT_LIST_HEAD(&urb->urb_list);
51727 atomic_dec(&urb->use_count);
51728 - atomic_dec(&urb->dev->urbnum);
51729 + atomic_dec_unchecked(&urb->dev->urbnum);
51730 if (atomic_read(&urb->reject))
51731 wake_up(&usb_kill_urb_queue);
51732 usb_put_urb(urb);
51733 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51734 index ebcd3bf..be93a64 100644
51735 --- a/drivers/usb/core/hub.c
51736 +++ b/drivers/usb/core/hub.c
51737 @@ -27,6 +27,7 @@
51738 #include <linux/freezer.h>
51739 #include <linux/random.h>
51740 #include <linux/pm_qos.h>
51741 +#include <linux/grsecurity.h>
51742
51743 #include <asm/uaccess.h>
51744 #include <asm/byteorder.h>
51745 @@ -4437,6 +4438,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51746 goto done;
51747 return;
51748 }
51749 +
51750 + if (gr_handle_new_usb())
51751 + goto done;
51752 +
51753 if (hub_is_superspeed(hub->hdev))
51754 unit_load = 150;
51755 else
51756 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51757 index bb31597..6c5ef8b 100644
51758 --- a/drivers/usb/core/message.c
51759 +++ b/drivers/usb/core/message.c
51760 @@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51761 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51762 * error number.
51763 */
51764 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51765 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51766 __u8 requesttype, __u16 value, __u16 index, void *data,
51767 __u16 size, int timeout)
51768 {
51769 @@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51770 * If successful, 0. Otherwise a negative error number. The number of actual
51771 * bytes transferred will be stored in the @actual_length paramater.
51772 */
51773 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51774 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51775 void *data, int len, int *actual_length, int timeout)
51776 {
51777 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51778 @@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51779 * bytes transferred will be stored in the @actual_length paramater.
51780 *
51781 */
51782 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51783 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51784 void *data, int len, int *actual_length, int timeout)
51785 {
51786 struct urb *urb;
51787 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51788 index 52a97ad..e73330f 100644
51789 --- a/drivers/usb/core/sysfs.c
51790 +++ b/drivers/usb/core/sysfs.c
51791 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51792 struct usb_device *udev;
51793
51794 udev = to_usb_device(dev);
51795 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51796 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51797 }
51798 static DEVICE_ATTR_RO(urbnum);
51799
51800 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51801 index 4d11449..f4ccabf 100644
51802 --- a/drivers/usb/core/usb.c
51803 +++ b/drivers/usb/core/usb.c
51804 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51805 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51806 dev->state = USB_STATE_ATTACHED;
51807 dev->lpm_disable_count = 1;
51808 - atomic_set(&dev->urbnum, 0);
51809 + atomic_set_unchecked(&dev->urbnum, 0);
51810
51811 INIT_LIST_HEAD(&dev->ep0.urb_list);
51812 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51813 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51814 index 02e44fc..3c4fe64 100644
51815 --- a/drivers/usb/dwc3/gadget.c
51816 +++ b/drivers/usb/dwc3/gadget.c
51817 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51818 if (!usb_endpoint_xfer_isoc(desc))
51819 return 0;
51820
51821 - memset(&trb_link, 0, sizeof(trb_link));
51822 -
51823 /* Link TRB for ISOC. The HWO bit is never reset */
51824 trb_st_hw = &dep->trb_pool[0];
51825
51826 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51827 index 8cfc319..4868255 100644
51828 --- a/drivers/usb/early/ehci-dbgp.c
51829 +++ b/drivers/usb/early/ehci-dbgp.c
51830 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51831
51832 #ifdef CONFIG_KGDB
51833 static struct kgdb_io kgdbdbgp_io_ops;
51834 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51835 +static struct kgdb_io kgdbdbgp_io_ops_console;
51836 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51837 #else
51838 #define dbgp_kgdb_mode (0)
51839 #endif
51840 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51841 .write_char = kgdbdbgp_write_char,
51842 };
51843
51844 +static struct kgdb_io kgdbdbgp_io_ops_console = {
51845 + .name = "kgdbdbgp",
51846 + .read_char = kgdbdbgp_read_char,
51847 + .write_char = kgdbdbgp_write_char,
51848 + .is_console = 1
51849 +};
51850 +
51851 static int kgdbdbgp_wait_time;
51852
51853 static int __init kgdbdbgp_parse_config(char *str)
51854 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51855 ptr++;
51856 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51857 }
51858 - kgdb_register_io_module(&kgdbdbgp_io_ops);
51859 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51860 + if (early_dbgp_console.index != -1)
51861 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51862 + else
51863 + kgdb_register_io_module(&kgdbdbgp_io_ops);
51864
51865 return 0;
51866 }
51867 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51868 index b369292..9f3ba40 100644
51869 --- a/drivers/usb/gadget/u_serial.c
51870 +++ b/drivers/usb/gadget/u_serial.c
51871 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51872 spin_lock_irq(&port->port_lock);
51873
51874 /* already open? Great. */
51875 - if (port->port.count) {
51876 + if (atomic_read(&port->port.count)) {
51877 status = 0;
51878 - port->port.count++;
51879 + atomic_inc(&port->port.count);
51880
51881 /* currently opening/closing? wait ... */
51882 } else if (port->openclose) {
51883 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51884 tty->driver_data = port;
51885 port->port.tty = tty;
51886
51887 - port->port.count = 1;
51888 + atomic_set(&port->port.count, 1);
51889 port->openclose = false;
51890
51891 /* if connected, start the I/O stream */
51892 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51893
51894 spin_lock_irq(&port->port_lock);
51895
51896 - if (port->port.count != 1) {
51897 - if (port->port.count == 0)
51898 + if (atomic_read(&port->port.count) != 1) {
51899 + if (atomic_read(&port->port.count) == 0)
51900 WARN_ON(1);
51901 else
51902 - --port->port.count;
51903 + atomic_dec(&port->port.count);
51904 goto exit;
51905 }
51906
51907 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51908 * and sleep if necessary
51909 */
51910 port->openclose = true;
51911 - port->port.count = 0;
51912 + atomic_set(&port->port.count, 0);
51913
51914 gser = port->port_usb;
51915 if (gser && gser->disconnect)
51916 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51917 int cond;
51918
51919 spin_lock_irq(&port->port_lock);
51920 - cond = (port->port.count == 0) && !port->openclose;
51921 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51922 spin_unlock_irq(&port->port_lock);
51923 return cond;
51924 }
51925 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51926 /* if it's already open, start I/O ... and notify the serial
51927 * protocol about open/close status (connect/disconnect).
51928 */
51929 - if (port->port.count) {
51930 + if (atomic_read(&port->port.count)) {
51931 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51932 gs_start_io(port);
51933 if (gser->connect)
51934 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51935
51936 port->port_usb = NULL;
51937 gser->ioport = NULL;
51938 - if (port->port.count > 0 || port->openclose) {
51939 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
51940 wake_up_interruptible(&port->drain_wait);
51941 if (port->port.tty)
51942 tty_hangup(port->port.tty);
51943 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51944
51945 /* finally, free any unused/unusable I/O buffers */
51946 spin_lock_irqsave(&port->port_lock, flags);
51947 - if (port->port.count == 0 && !port->openclose)
51948 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
51949 gs_buf_free(&port->port_write_buf);
51950 gs_free_requests(gser->out, &port->read_pool, NULL);
51951 gs_free_requests(gser->out, &port->read_queue, NULL);
51952 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51953 index 1bb85be..29e28d9 100644
51954 --- a/drivers/usb/host/ehci-hub.c
51955 +++ b/drivers/usb/host/ehci-hub.c
51956 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
51957 urb->transfer_flags = URB_DIR_IN;
51958 usb_get_urb(urb);
51959 atomic_inc(&urb->use_count);
51960 - atomic_inc(&urb->dev->urbnum);
51961 + atomic_inc_unchecked(&urb->dev->urbnum);
51962 urb->setup_dma = dma_map_single(
51963 hcd->self.controller,
51964 urb->setup_packet,
51965 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51966 urb->status = -EINPROGRESS;
51967 usb_get_urb(urb);
51968 atomic_inc(&urb->use_count);
51969 - atomic_inc(&urb->dev->urbnum);
51970 + atomic_inc_unchecked(&urb->dev->urbnum);
51971 retval = submit_single_step_set_feature(hcd, urb, 0);
51972 if (!retval && !wait_for_completion_timeout(&done,
51973 msecs_to_jiffies(2000))) {
51974 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51975 index ba6a5d6..f88f7f3 100644
51976 --- a/drivers/usb/misc/appledisplay.c
51977 +++ b/drivers/usb/misc/appledisplay.c
51978 @@ -83,7 +83,7 @@ struct appledisplay {
51979 spinlock_t lock;
51980 };
51981
51982 -static atomic_t count_displays = ATOMIC_INIT(0);
51983 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51984 static struct workqueue_struct *wq;
51985
51986 static void appledisplay_complete(struct urb *urb)
51987 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
51988
51989 /* Register backlight device */
51990 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
51991 - atomic_inc_return(&count_displays) - 1);
51992 + atomic_inc_return_unchecked(&count_displays) - 1);
51993 memset(&props, 0, sizeof(struct backlight_properties));
51994 props.type = BACKLIGHT_RAW;
51995 props.max_brightness = 0xff;
51996 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
51997 index c69bb50..215ef37 100644
51998 --- a/drivers/usb/serial/console.c
51999 +++ b/drivers/usb/serial/console.c
52000 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
52001
52002 info->port = port;
52003
52004 - ++port->port.count;
52005 + atomic_inc(&port->port.count);
52006 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52007 if (serial->type->set_termios) {
52008 /*
52009 @@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
52010 }
52011 /* Now that any required fake tty operations are completed restore
52012 * the tty port count */
52013 - --port->port.count;
52014 + atomic_dec(&port->port.count);
52015 /* The console is special in terms of closing the device so
52016 * indicate this port is now acting as a system console. */
52017 port->port.console = 1;
52018 @@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
52019 free_tty:
52020 kfree(tty);
52021 reset_open_count:
52022 - port->port.count = 0;
52023 + atomic_set(&port->port.count, 0);
52024 usb_autopm_put_interface(serial->interface);
52025 error_get_interface:
52026 usb_serial_put(serial);
52027 @@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
52028 static void usb_console_write(struct console *co,
52029 const char *buf, unsigned count)
52030 {
52031 - static struct usbcons_info *info = &usbcons_info;
52032 + struct usbcons_info *info = &usbcons_info;
52033 struct usb_serial_port *port = info->port;
52034 struct usb_serial *serial;
52035 int retval = -ENODEV;
52036 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52037 index 75f70f0..d467e1a 100644
52038 --- a/drivers/usb/storage/usb.h
52039 +++ b/drivers/usb/storage/usb.h
52040 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52041 __u8 useProtocol;
52042 __u8 useTransport;
52043 int (*initFunction)(struct us_data *);
52044 -};
52045 +} __do_const;
52046
52047
52048 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52049 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52050 index e614f02..3fd60e2 100644
52051 --- a/drivers/usb/wusbcore/wa-hc.h
52052 +++ b/drivers/usb/wusbcore/wa-hc.h
52053 @@ -225,7 +225,7 @@ struct wahc {
52054 spinlock_t xfer_list_lock;
52055 struct work_struct xfer_enqueue_work;
52056 struct work_struct xfer_error_work;
52057 - atomic_t xfer_id_count;
52058 + atomic_unchecked_t xfer_id_count;
52059
52060 kernel_ulong_t quirks;
52061 };
52062 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52063 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52064 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52065 wa->dto_in_use = 0;
52066 - atomic_set(&wa->xfer_id_count, 1);
52067 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52068 }
52069
52070 /**
52071 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52072 index ed5abe8..7036400 100644
52073 --- a/drivers/usb/wusbcore/wa-xfer.c
52074 +++ b/drivers/usb/wusbcore/wa-xfer.c
52075 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52076 */
52077 static void wa_xfer_id_init(struct wa_xfer *xfer)
52078 {
52079 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52080 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52081 }
52082
52083 /* Return the xfer's ID. */
52084 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52085 index 1eab4ac..e21efc9 100644
52086 --- a/drivers/vfio/vfio.c
52087 +++ b/drivers/vfio/vfio.c
52088 @@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52089 return 0;
52090
52091 /* TODO Prevent device auto probing */
52092 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52093 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52094 iommu_group_id(group->iommu_group));
52095
52096 return 0;
52097 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52098 index 5174eba..451e6bc 100644
52099 --- a/drivers/vhost/vringh.c
52100 +++ b/drivers/vhost/vringh.c
52101 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52102 /* Userspace access helpers: in this case, addresses are really userspace. */
52103 static inline int getu16_user(u16 *val, const u16 *p)
52104 {
52105 - return get_user(*val, (__force u16 __user *)p);
52106 + return get_user(*val, (u16 __force_user *)p);
52107 }
52108
52109 static inline int putu16_user(u16 *p, u16 val)
52110 {
52111 - return put_user(val, (__force u16 __user *)p);
52112 + return put_user(val, (u16 __force_user *)p);
52113 }
52114
52115 static inline int copydesc_user(void *dst, const void *src, size_t len)
52116 {
52117 - return copy_from_user(dst, (__force void __user *)src, len) ?
52118 + return copy_from_user(dst, (void __force_user *)src, len) ?
52119 -EFAULT : 0;
52120 }
52121
52122 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52123 const struct vring_used_elem *src,
52124 unsigned int num)
52125 {
52126 - return copy_to_user((__force void __user *)dst, src,
52127 + return copy_to_user((void __force_user *)dst, src,
52128 sizeof(*dst) * num) ? -EFAULT : 0;
52129 }
52130
52131 static inline int xfer_from_user(void *src, void *dst, size_t len)
52132 {
52133 - return copy_from_user(dst, (__force void __user *)src, len) ?
52134 + return copy_from_user(dst, (void __force_user *)src, len) ?
52135 -EFAULT : 0;
52136 }
52137
52138 static inline int xfer_to_user(void *dst, void *src, size_t len)
52139 {
52140 - return copy_to_user((__force void __user *)dst, src, len) ?
52141 + return copy_to_user((void __force_user *)dst, src, len) ?
52142 -EFAULT : 0;
52143 }
52144
52145 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52146 vrh->last_used_idx = 0;
52147 vrh->vring.num = num;
52148 /* vring expects kernel addresses, but only used via accessors. */
52149 - vrh->vring.desc = (__force struct vring_desc *)desc;
52150 - vrh->vring.avail = (__force struct vring_avail *)avail;
52151 - vrh->vring.used = (__force struct vring_used *)used;
52152 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52153 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52154 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52155 return 0;
52156 }
52157 EXPORT_SYMBOL(vringh_init_user);
52158 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52159
52160 static inline int putu16_kern(u16 *p, u16 val)
52161 {
52162 - ACCESS_ONCE(*p) = val;
52163 + ACCESS_ONCE_RW(*p) = val;
52164 return 0;
52165 }
52166
52167 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52168 index 1b0b233..6f34c2c 100644
52169 --- a/drivers/video/arcfb.c
52170 +++ b/drivers/video/arcfb.c
52171 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52172 return -ENOSPC;
52173
52174 err = 0;
52175 - if ((count + p) > fbmemlength) {
52176 + if (count > (fbmemlength - p)) {
52177 count = fbmemlength - p;
52178 err = -ENOSPC;
52179 }
52180 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52181 index 12ca031..84a8a74 100644
52182 --- a/drivers/video/aty/aty128fb.c
52183 +++ b/drivers/video/aty/aty128fb.c
52184 @@ -149,7 +149,7 @@ enum {
52185 };
52186
52187 /* Must match above enum */
52188 -static char * const r128_family[] = {
52189 +static const char * const r128_family[] = {
52190 "AGP",
52191 "PCI",
52192 "PRO AGP",
52193 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52194 index 28fafbf..ae91651 100644
52195 --- a/drivers/video/aty/atyfb_base.c
52196 +++ b/drivers/video/aty/atyfb_base.c
52197 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52198 par->accel_flags = var->accel_flags; /* hack */
52199
52200 if (var->accel_flags) {
52201 - info->fbops->fb_sync = atyfb_sync;
52202 + pax_open_kernel();
52203 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52204 + pax_close_kernel();
52205 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52206 } else {
52207 - info->fbops->fb_sync = NULL;
52208 + pax_open_kernel();
52209 + *(void **)&info->fbops->fb_sync = NULL;
52210 + pax_close_kernel();
52211 info->flags |= FBINFO_HWACCEL_DISABLED;
52212 }
52213
52214 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52215 index 95ec042..e6affdd 100644
52216 --- a/drivers/video/aty/mach64_cursor.c
52217 +++ b/drivers/video/aty/mach64_cursor.c
52218 @@ -7,6 +7,7 @@
52219 #include <linux/string.h>
52220
52221 #include <asm/io.h>
52222 +#include <asm/pgtable.h>
52223
52224 #ifdef __sparc__
52225 #include <asm/fbio.h>
52226 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52227 info->sprite.buf_align = 16; /* and 64 lines tall. */
52228 info->sprite.flags = FB_PIXMAP_IO;
52229
52230 - info->fbops->fb_cursor = atyfb_cursor;
52231 + pax_open_kernel();
52232 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52233 + pax_close_kernel();
52234
52235 return 0;
52236 }
52237 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52238 index 7592cc2..92feb56 100644
52239 --- a/drivers/video/backlight/kb3886_bl.c
52240 +++ b/drivers/video/backlight/kb3886_bl.c
52241 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52242 static unsigned long kb3886bl_flags;
52243 #define KB3886BL_SUSPENDED 0x01
52244
52245 -static struct dmi_system_id __initdata kb3886bl_device_table[] = {
52246 +static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
52247 {
52248 .ident = "Sahara Touch-iT",
52249 .matches = {
52250 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52251 index 900aa4e..6d49418 100644
52252 --- a/drivers/video/fb_defio.c
52253 +++ b/drivers/video/fb_defio.c
52254 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52255
52256 BUG_ON(!fbdefio);
52257 mutex_init(&fbdefio->lock);
52258 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52259 + pax_open_kernel();
52260 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52261 + pax_close_kernel();
52262 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52263 INIT_LIST_HEAD(&fbdefio->pagelist);
52264 if (fbdefio->delay == 0) /* set a default of 1 s */
52265 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52266 page->mapping = NULL;
52267 }
52268
52269 - info->fbops->fb_mmap = NULL;
52270 + *(void **)&info->fbops->fb_mmap = NULL;
52271 mutex_destroy(&fbdefio->lock);
52272 }
52273 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52274 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52275 index 010d191..7b8235a 100644
52276 --- a/drivers/video/fbmem.c
52277 +++ b/drivers/video/fbmem.c
52278 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52279 image->dx += image->width + 8;
52280 }
52281 } else if (rotate == FB_ROTATE_UD) {
52282 - for (x = 0; x < num && image->dx >= 0; x++) {
52283 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52284 info->fbops->fb_imageblit(info, image);
52285 image->dx -= image->width + 8;
52286 }
52287 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52288 image->dy += image->height + 8;
52289 }
52290 } else if (rotate == FB_ROTATE_CCW) {
52291 - for (x = 0; x < num && image->dy >= 0; x++) {
52292 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52293 info->fbops->fb_imageblit(info, image);
52294 image->dy -= image->height + 8;
52295 }
52296 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52297 return -EFAULT;
52298 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52299 return -EINVAL;
52300 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52301 + if (con2fb.framebuffer >= FB_MAX)
52302 return -EINVAL;
52303 if (!registered_fb[con2fb.framebuffer])
52304 request_module("fb%d", con2fb.framebuffer);
52305 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52306 __u32 data;
52307 int err;
52308
52309 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52310 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52311
52312 data = (__u32) (unsigned long) fix->smem_start;
52313 err |= put_user(data, &fix32->smem_start);
52314 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52315 index 130708f..cdac1a9 100644
52316 --- a/drivers/video/hyperv_fb.c
52317 +++ b/drivers/video/hyperv_fb.c
52318 @@ -233,7 +233,7 @@ static uint screen_fb_size;
52319 static inline int synthvid_send(struct hv_device *hdev,
52320 struct synthvid_msg *msg)
52321 {
52322 - static atomic64_t request_id = ATOMIC64_INIT(0);
52323 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52324 int ret;
52325
52326 msg->pipe_hdr.type = PIPE_MSG_DATA;
52327 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52328
52329 ret = vmbus_sendpacket(hdev->channel, msg,
52330 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52331 - atomic64_inc_return(&request_id),
52332 + atomic64_inc_return_unchecked(&request_id),
52333 VM_PKT_DATA_INBAND, 0);
52334
52335 if (ret)
52336 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52337 index 7672d2e..b56437f 100644
52338 --- a/drivers/video/i810/i810_accel.c
52339 +++ b/drivers/video/i810/i810_accel.c
52340 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52341 }
52342 }
52343 printk("ringbuffer lockup!!!\n");
52344 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52345 i810_report_error(mmio);
52346 par->dev_flags |= LOCKUP;
52347 info->pixmap.scan_align = 1;
52348 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52349 index 3c14e43..2630570 100644
52350 --- a/drivers/video/logo/logo_linux_clut224.ppm
52351 +++ b/drivers/video/logo/logo_linux_clut224.ppm
52352 @@ -2,1603 +2,1123 @@ P3
52353 # Standard 224-color Linux logo
52354 80 80
52355 255
52356 - 0 0 0 0 0 0 0 0 0 0 0 0
52357 - 0 0 0 0 0 0 0 0 0 0 0 0
52358 - 0 0 0 0 0 0 0 0 0 0 0 0
52359 - 0 0 0 0 0 0 0 0 0 0 0 0
52360 - 0 0 0 0 0 0 0 0 0 0 0 0
52361 - 0 0 0 0 0 0 0 0 0 0 0 0
52362 - 0 0 0 0 0 0 0 0 0 0 0 0
52363 - 0 0 0 0 0 0 0 0 0 0 0 0
52364 - 0 0 0 0 0 0 0 0 0 0 0 0
52365 - 6 6 6 6 6 6 10 10 10 10 10 10
52366 - 10 10 10 6 6 6 6 6 6 6 6 6
52367 - 0 0 0 0 0 0 0 0 0 0 0 0
52368 - 0 0 0 0 0 0 0 0 0 0 0 0
52369 - 0 0 0 0 0 0 0 0 0 0 0 0
52370 - 0 0 0 0 0 0 0 0 0 0 0 0
52371 - 0 0 0 0 0 0 0 0 0 0 0 0
52372 - 0 0 0 0 0 0 0 0 0 0 0 0
52373 - 0 0 0 0 0 0 0 0 0 0 0 0
52374 - 0 0 0 0 0 0 0 0 0 0 0 0
52375 - 0 0 0 0 0 0 0 0 0 0 0 0
52376 - 0 0 0 0 0 0 0 0 0 0 0 0
52377 - 0 0 0 0 0 0 0 0 0 0 0 0
52378 - 0 0 0 0 0 0 0 0 0 0 0 0
52379 - 0 0 0 0 0 0 0 0 0 0 0 0
52380 - 0 0 0 0 0 0 0 0 0 0 0 0
52381 - 0 0 0 0 0 0 0 0 0 0 0 0
52382 - 0 0 0 0 0 0 0 0 0 0 0 0
52383 - 0 0 0 0 0 0 0 0 0 0 0 0
52384 - 0 0 0 6 6 6 10 10 10 14 14 14
52385 - 22 22 22 26 26 26 30 30 30 34 34 34
52386 - 30 30 30 30 30 30 26 26 26 18 18 18
52387 - 14 14 14 10 10 10 6 6 6 0 0 0
52388 - 0 0 0 0 0 0 0 0 0 0 0 0
52389 - 0 0 0 0 0 0 0 0 0 0 0 0
52390 - 0 0 0 0 0 0 0 0 0 0 0 0
52391 - 0 0 0 0 0 0 0 0 0 0 0 0
52392 - 0 0 0 0 0 0 0 0 0 0 0 0
52393 - 0 0 0 0 0 0 0 0 0 0 0 0
52394 - 0 0 0 0 0 0 0 0 0 0 0 0
52395 - 0 0 0 0 0 0 0 0 0 0 0 0
52396 - 0 0 0 0 0 0 0 0 0 0 0 0
52397 - 0 0 0 0 0 1 0 0 1 0 0 0
52398 - 0 0 0 0 0 0 0 0 0 0 0 0
52399 - 0 0 0 0 0 0 0 0 0 0 0 0
52400 - 0 0 0 0 0 0 0 0 0 0 0 0
52401 - 0 0 0 0 0 0 0 0 0 0 0 0
52402 - 0 0 0 0 0 0 0 0 0 0 0 0
52403 - 0 0 0 0 0 0 0 0 0 0 0 0
52404 - 6 6 6 14 14 14 26 26 26 42 42 42
52405 - 54 54 54 66 66 66 78 78 78 78 78 78
52406 - 78 78 78 74 74 74 66 66 66 54 54 54
52407 - 42 42 42 26 26 26 18 18 18 10 10 10
52408 - 6 6 6 0 0 0 0 0 0 0 0 0
52409 - 0 0 0 0 0 0 0 0 0 0 0 0
52410 - 0 0 0 0 0 0 0 0 0 0 0 0
52411 - 0 0 0 0 0 0 0 0 0 0 0 0
52412 - 0 0 0 0 0 0 0 0 0 0 0 0
52413 - 0 0 0 0 0 0 0 0 0 0 0 0
52414 - 0 0 0 0 0 0 0 0 0 0 0 0
52415 - 0 0 0 0 0 0 0 0 0 0 0 0
52416 - 0 0 0 0 0 0 0 0 0 0 0 0
52417 - 0 0 1 0 0 0 0 0 0 0 0 0
52418 - 0 0 0 0 0 0 0 0 0 0 0 0
52419 - 0 0 0 0 0 0 0 0 0 0 0 0
52420 - 0 0 0 0 0 0 0 0 0 0 0 0
52421 - 0 0 0 0 0 0 0 0 0 0 0 0
52422 - 0 0 0 0 0 0 0 0 0 0 0 0
52423 - 0 0 0 0 0 0 0 0 0 10 10 10
52424 - 22 22 22 42 42 42 66 66 66 86 86 86
52425 - 66 66 66 38 38 38 38 38 38 22 22 22
52426 - 26 26 26 34 34 34 54 54 54 66 66 66
52427 - 86 86 86 70 70 70 46 46 46 26 26 26
52428 - 14 14 14 6 6 6 0 0 0 0 0 0
52429 - 0 0 0 0 0 0 0 0 0 0 0 0
52430 - 0 0 0 0 0 0 0 0 0 0 0 0
52431 - 0 0 0 0 0 0 0 0 0 0 0 0
52432 - 0 0 0 0 0 0 0 0 0 0 0 0
52433 - 0 0 0 0 0 0 0 0 0 0 0 0
52434 - 0 0 0 0 0 0 0 0 0 0 0 0
52435 - 0 0 0 0 0 0 0 0 0 0 0 0
52436 - 0 0 0 0 0 0 0 0 0 0 0 0
52437 - 0 0 1 0 0 1 0 0 1 0 0 0
52438 - 0 0 0 0 0 0 0 0 0 0 0 0
52439 - 0 0 0 0 0 0 0 0 0 0 0 0
52440 - 0 0 0 0 0 0 0 0 0 0 0 0
52441 - 0 0 0 0 0 0 0 0 0 0 0 0
52442 - 0 0 0 0 0 0 0 0 0 0 0 0
52443 - 0 0 0 0 0 0 10 10 10 26 26 26
52444 - 50 50 50 82 82 82 58 58 58 6 6 6
52445 - 2 2 6 2 2 6 2 2 6 2 2 6
52446 - 2 2 6 2 2 6 2 2 6 2 2 6
52447 - 6 6 6 54 54 54 86 86 86 66 66 66
52448 - 38 38 38 18 18 18 6 6 6 0 0 0
52449 - 0 0 0 0 0 0 0 0 0 0 0 0
52450 - 0 0 0 0 0 0 0 0 0 0 0 0
52451 - 0 0 0 0 0 0 0 0 0 0 0 0
52452 - 0 0 0 0 0 0 0 0 0 0 0 0
52453 - 0 0 0 0 0 0 0 0 0 0 0 0
52454 - 0 0 0 0 0 0 0 0 0 0 0 0
52455 - 0 0 0 0 0 0 0 0 0 0 0 0
52456 - 0 0 0 0 0 0 0 0 0 0 0 0
52457 - 0 0 0 0 0 0 0 0 0 0 0 0
52458 - 0 0 0 0 0 0 0 0 0 0 0 0
52459 - 0 0 0 0 0 0 0 0 0 0 0 0
52460 - 0 0 0 0 0 0 0 0 0 0 0 0
52461 - 0 0 0 0 0 0 0 0 0 0 0 0
52462 - 0 0 0 0 0 0 0 0 0 0 0 0
52463 - 0 0 0 6 6 6 22 22 22 50 50 50
52464 - 78 78 78 34 34 34 2 2 6 2 2 6
52465 - 2 2 6 2 2 6 2 2 6 2 2 6
52466 - 2 2 6 2 2 6 2 2 6 2 2 6
52467 - 2 2 6 2 2 6 6 6 6 70 70 70
52468 - 78 78 78 46 46 46 22 22 22 6 6 6
52469 - 0 0 0 0 0 0 0 0 0 0 0 0
52470 - 0 0 0 0 0 0 0 0 0 0 0 0
52471 - 0 0 0 0 0 0 0 0 0 0 0 0
52472 - 0 0 0 0 0 0 0 0 0 0 0 0
52473 - 0 0 0 0 0 0 0 0 0 0 0 0
52474 - 0 0 0 0 0 0 0 0 0 0 0 0
52475 - 0 0 0 0 0 0 0 0 0 0 0 0
52476 - 0 0 0 0 0 0 0 0 0 0 0 0
52477 - 0 0 1 0 0 1 0 0 1 0 0 0
52478 - 0 0 0 0 0 0 0 0 0 0 0 0
52479 - 0 0 0 0 0 0 0 0 0 0 0 0
52480 - 0 0 0 0 0 0 0 0 0 0 0 0
52481 - 0 0 0 0 0 0 0 0 0 0 0 0
52482 - 0 0 0 0 0 0 0 0 0 0 0 0
52483 - 6 6 6 18 18 18 42 42 42 82 82 82
52484 - 26 26 26 2 2 6 2 2 6 2 2 6
52485 - 2 2 6 2 2 6 2 2 6 2 2 6
52486 - 2 2 6 2 2 6 2 2 6 14 14 14
52487 - 46 46 46 34 34 34 6 6 6 2 2 6
52488 - 42 42 42 78 78 78 42 42 42 18 18 18
52489 - 6 6 6 0 0 0 0 0 0 0 0 0
52490 - 0 0 0 0 0 0 0 0 0 0 0 0
52491 - 0 0 0 0 0 0 0 0 0 0 0 0
52492 - 0 0 0 0 0 0 0 0 0 0 0 0
52493 - 0 0 0 0 0 0 0 0 0 0 0 0
52494 - 0 0 0 0 0 0 0 0 0 0 0 0
52495 - 0 0 0 0 0 0 0 0 0 0 0 0
52496 - 0 0 0 0 0 0 0 0 0 0 0 0
52497 - 0 0 1 0 0 0 0 0 1 0 0 0
52498 - 0 0 0 0 0 0 0 0 0 0 0 0
52499 - 0 0 0 0 0 0 0 0 0 0 0 0
52500 - 0 0 0 0 0 0 0 0 0 0 0 0
52501 - 0 0 0 0 0 0 0 0 0 0 0 0
52502 - 0 0 0 0 0 0 0 0 0 0 0 0
52503 - 10 10 10 30 30 30 66 66 66 58 58 58
52504 - 2 2 6 2 2 6 2 2 6 2 2 6
52505 - 2 2 6 2 2 6 2 2 6 2 2 6
52506 - 2 2 6 2 2 6 2 2 6 26 26 26
52507 - 86 86 86 101 101 101 46 46 46 10 10 10
52508 - 2 2 6 58 58 58 70 70 70 34 34 34
52509 - 10 10 10 0 0 0 0 0 0 0 0 0
52510 - 0 0 0 0 0 0 0 0 0 0 0 0
52511 - 0 0 0 0 0 0 0 0 0 0 0 0
52512 - 0 0 0 0 0 0 0 0 0 0 0 0
52513 - 0 0 0 0 0 0 0 0 0 0 0 0
52514 - 0 0 0 0 0 0 0 0 0 0 0 0
52515 - 0 0 0 0 0 0 0 0 0 0 0 0
52516 - 0 0 0 0 0 0 0 0 0 0 0 0
52517 - 0 0 1 0 0 1 0 0 1 0 0 0
52518 - 0 0 0 0 0 0 0 0 0 0 0 0
52519 - 0 0 0 0 0 0 0 0 0 0 0 0
52520 - 0 0 0 0 0 0 0 0 0 0 0 0
52521 - 0 0 0 0 0 0 0 0 0 0 0 0
52522 - 0 0 0 0 0 0 0 0 0 0 0 0
52523 - 14 14 14 42 42 42 86 86 86 10 10 10
52524 - 2 2 6 2 2 6 2 2 6 2 2 6
52525 - 2 2 6 2 2 6 2 2 6 2 2 6
52526 - 2 2 6 2 2 6 2 2 6 30 30 30
52527 - 94 94 94 94 94 94 58 58 58 26 26 26
52528 - 2 2 6 6 6 6 78 78 78 54 54 54
52529 - 22 22 22 6 6 6 0 0 0 0 0 0
52530 - 0 0 0 0 0 0 0 0 0 0 0 0
52531 - 0 0 0 0 0 0 0 0 0 0 0 0
52532 - 0 0 0 0 0 0 0 0 0 0 0 0
52533 - 0 0 0 0 0 0 0 0 0 0 0 0
52534 - 0 0 0 0 0 0 0 0 0 0 0 0
52535 - 0 0 0 0 0 0 0 0 0 0 0 0
52536 - 0 0 0 0 0 0 0 0 0 0 0 0
52537 - 0 0 0 0 0 0 0 0 0 0 0 0
52538 - 0 0 0 0 0 0 0 0 0 0 0 0
52539 - 0 0 0 0 0 0 0 0 0 0 0 0
52540 - 0 0 0 0 0 0 0 0 0 0 0 0
52541 - 0 0 0 0 0 0 0 0 0 0 0 0
52542 - 0 0 0 0 0 0 0 0 0 6 6 6
52543 - 22 22 22 62 62 62 62 62 62 2 2 6
52544 - 2 2 6 2 2 6 2 2 6 2 2 6
52545 - 2 2 6 2 2 6 2 2 6 2 2 6
52546 - 2 2 6 2 2 6 2 2 6 26 26 26
52547 - 54 54 54 38 38 38 18 18 18 10 10 10
52548 - 2 2 6 2 2 6 34 34 34 82 82 82
52549 - 38 38 38 14 14 14 0 0 0 0 0 0
52550 - 0 0 0 0 0 0 0 0 0 0 0 0
52551 - 0 0 0 0 0 0 0 0 0 0 0 0
52552 - 0 0 0 0 0 0 0 0 0 0 0 0
52553 - 0 0 0 0 0 0 0 0 0 0 0 0
52554 - 0 0 0 0 0 0 0 0 0 0 0 0
52555 - 0 0 0 0 0 0 0 0 0 0 0 0
52556 - 0 0 0 0 0 0 0 0 0 0 0 0
52557 - 0 0 0 0 0 1 0 0 1 0 0 0
52558 - 0 0 0 0 0 0 0 0 0 0 0 0
52559 - 0 0 0 0 0 0 0 0 0 0 0 0
52560 - 0 0 0 0 0 0 0 0 0 0 0 0
52561 - 0 0 0 0 0 0 0 0 0 0 0 0
52562 - 0 0 0 0 0 0 0 0 0 6 6 6
52563 - 30 30 30 78 78 78 30 30 30 2 2 6
52564 - 2 2 6 2 2 6 2 2 6 2 2 6
52565 - 2 2 6 2 2 6 2 2 6 2 2 6
52566 - 2 2 6 2 2 6 2 2 6 10 10 10
52567 - 10 10 10 2 2 6 2 2 6 2 2 6
52568 - 2 2 6 2 2 6 2 2 6 78 78 78
52569 - 50 50 50 18 18 18 6 6 6 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 - 0 0 1 0 0 0 0 0 0 0 0 0
52578 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
52583 - 38 38 38 86 86 86 14 14 14 2 2 6
52584 - 2 2 6 2 2 6 2 2 6 2 2 6
52585 - 2 2 6 2 2 6 2 2 6 2 2 6
52586 - 2 2 6 2 2 6 2 2 6 2 2 6
52587 - 2 2 6 2 2 6 2 2 6 2 2 6
52588 - 2 2 6 2 2 6 2 2 6 54 54 54
52589 - 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0 0 0 0
52597 - 0 0 0 0 0 1 0 0 1 0 0 0
52598 - 0 0 0 0 0 0 0 0 0 0 0 0
52599 - 0 0 0 0 0 0 0 0 0 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 14 14 14
52603 - 42 42 42 82 82 82 2 2 6 2 2 6
52604 - 2 2 6 6 6 6 10 10 10 2 2 6
52605 - 2 2 6 2 2 6 2 2 6 2 2 6
52606 - 2 2 6 2 2 6 2 2 6 6 6 6
52607 - 14 14 14 10 10 10 2 2 6 2 2 6
52608 - 2 2 6 2 2 6 2 2 6 18 18 18
52609 - 82 82 82 34 34 34 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
52617 - 0 0 1 0 0 0 0 0 0 0 0 0
52618 - 0 0 0 0 0 0 0 0 0 0 0 0
52619 - 0 0 0 0 0 0 0 0 0 0 0 0
52620 - 0 0 0 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 14 14 14
52623 - 46 46 46 86 86 86 2 2 6 2 2 6
52624 - 6 6 6 6 6 6 22 22 22 34 34 34
52625 - 6 6 6 2 2 6 2 2 6 2 2 6
52626 - 2 2 6 2 2 6 18 18 18 34 34 34
52627 - 10 10 10 50 50 50 22 22 22 2 2 6
52628 - 2 2 6 2 2 6 2 2 6 10 10 10
52629 - 86 86 86 42 42 42 14 14 14 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 0 0 0
52636 - 0 0 0 0 0 0 0 0 0 0 0 0
52637 - 0 0 1 0 0 1 0 0 1 0 0 0
52638 - 0 0 0 0 0 0 0 0 0 0 0 0
52639 - 0 0 0 0 0 0 0 0 0 0 0 0
52640 - 0 0 0 0 0 0 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 14 14 14
52643 - 46 46 46 86 86 86 2 2 6 2 2 6
52644 - 38 38 38 116 116 116 94 94 94 22 22 22
52645 - 22 22 22 2 2 6 2 2 6 2 2 6
52646 - 14 14 14 86 86 86 138 138 138 162 162 162
52647 -154 154 154 38 38 38 26 26 26 6 6 6
52648 - 2 2 6 2 2 6 2 2 6 2 2 6
52649 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0
52656 - 0 0 0 0 0 0 0 0 0 0 0 0
52657 - 0 0 0 0 0 0 0 0 0 0 0 0
52658 - 0 0 0 0 0 0 0 0 0 0 0 0
52659 - 0 0 0 0 0 0 0 0 0 0 0 0
52660 - 0 0 0 0 0 0 0 0 0 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 14 14 14
52663 - 46 46 46 86 86 86 2 2 6 14 14 14
52664 -134 134 134 198 198 198 195 195 195 116 116 116
52665 - 10 10 10 2 2 6 2 2 6 6 6 6
52666 -101 98 89 187 187 187 210 210 210 218 218 218
52667 -214 214 214 134 134 134 14 14 14 6 6 6
52668 - 2 2 6 2 2 6 2 2 6 2 2 6
52669 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0 0 0 0 0 0
52676 - 0 0 0 0 0 0 0 0 1 0 0 0
52677 - 0 0 1 0 0 1 0 0 1 0 0 0
52678 - 0 0 0 0 0 0 0 0 0 0 0 0
52679 - 0 0 0 0 0 0 0 0 0 0 0 0
52680 - 0 0 0 0 0 0 0 0 0 0 0 0
52681 - 0 0 0 0 0 0 0 0 0 0 0 0
52682 - 0 0 0 0 0 0 0 0 0 14 14 14
52683 - 46 46 46 86 86 86 2 2 6 54 54 54
52684 -218 218 218 195 195 195 226 226 226 246 246 246
52685 - 58 58 58 2 2 6 2 2 6 30 30 30
52686 -210 210 210 253 253 253 174 174 174 123 123 123
52687 -221 221 221 234 234 234 74 74 74 2 2 6
52688 - 2 2 6 2 2 6 2 2 6 2 2 6
52689 - 70 70 70 58 58 58 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
52696 - 0 0 0 0 0 0 0 0 0 0 0 0
52697 - 0 0 0 0 0 0 0 0 0 0 0 0
52698 - 0 0 0 0 0 0 0 0 0 0 0 0
52699 - 0 0 0 0 0 0 0 0 0 0 0 0
52700 - 0 0 0 0 0 0 0 0 0 0 0 0
52701 - 0 0 0 0 0 0 0 0 0 0 0 0
52702 - 0 0 0 0 0 0 0 0 0 14 14 14
52703 - 46 46 46 82 82 82 2 2 6 106 106 106
52704 -170 170 170 26 26 26 86 86 86 226 226 226
52705 -123 123 123 10 10 10 14 14 14 46 46 46
52706 -231 231 231 190 190 190 6 6 6 70 70 70
52707 - 90 90 90 238 238 238 158 158 158 2 2 6
52708 - 2 2 6 2 2 6 2 2 6 2 2 6
52709 - 70 70 70 58 58 58 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
52716 - 0 0 0 0 0 0 0 0 1 0 0 0
52717 - 0 0 1 0 0 1 0 0 1 0 0 0
52718 - 0 0 0 0 0 0 0 0 0 0 0 0
52719 - 0 0 0 0 0 0 0 0 0 0 0 0
52720 - 0 0 0 0 0 0 0 0 0 0 0 0
52721 - 0 0 0 0 0 0 0 0 0 0 0 0
52722 - 0 0 0 0 0 0 0 0 0 14 14 14
52723 - 42 42 42 86 86 86 6 6 6 116 116 116
52724 -106 106 106 6 6 6 70 70 70 149 149 149
52725 -128 128 128 18 18 18 38 38 38 54 54 54
52726 -221 221 221 106 106 106 2 2 6 14 14 14
52727 - 46 46 46 190 190 190 198 198 198 2 2 6
52728 - 2 2 6 2 2 6 2 2 6 2 2 6
52729 - 74 74 74 62 62 62 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
52736 - 0 0 0 0 0 0 0 0 1 0 0 0
52737 - 0 0 1 0 0 0 0 0 1 0 0 0
52738 - 0 0 0 0 0 0 0 0 0 0 0 0
52739 - 0 0 0 0 0 0 0 0 0 0 0 0
52740 - 0 0 0 0 0 0 0 0 0 0 0 0
52741 - 0 0 0 0 0 0 0 0 0 0 0 0
52742 - 0 0 0 0 0 0 0 0 0 14 14 14
52743 - 42 42 42 94 94 94 14 14 14 101 101 101
52744 -128 128 128 2 2 6 18 18 18 116 116 116
52745 -118 98 46 121 92 8 121 92 8 98 78 10
52746 -162 162 162 106 106 106 2 2 6 2 2 6
52747 - 2 2 6 195 195 195 195 195 195 6 6 6
52748 - 2 2 6 2 2 6 2 2 6 2 2 6
52749 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
52755 - 0 0 0 0 0 0 0 0 0 0 0 0
52756 - 0 0 0 0 0 0 0 0 1 0 0 1
52757 - 0 0 1 0 0 0 0 0 1 0 0 0
52758 - 0 0 0 0 0 0 0 0 0 0 0 0
52759 - 0 0 0 0 0 0 0 0 0 0 0 0
52760 - 0 0 0 0 0 0 0 0 0 0 0 0
52761 - 0 0 0 0 0 0 0 0 0 0 0 0
52762 - 0 0 0 0 0 0 0 0 0 10 10 10
52763 - 38 38 38 90 90 90 14 14 14 58 58 58
52764 -210 210 210 26 26 26 54 38 6 154 114 10
52765 -226 170 11 236 186 11 225 175 15 184 144 12
52766 -215 174 15 175 146 61 37 26 9 2 2 6
52767 - 70 70 70 246 246 246 138 138 138 2 2 6
52768 - 2 2 6 2 2 6 2 2 6 2 2 6
52769 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
52775 - 0 0 0 0 0 0 0 0 0 0 0 0
52776 - 0 0 0 0 0 0 0 0 0 0 0 0
52777 - 0 0 0 0 0 0 0 0 0 0 0 0
52778 - 0 0 0 0 0 0 0 0 0 0 0 0
52779 - 0 0 0 0 0 0 0 0 0 0 0 0
52780 - 0 0 0 0 0 0 0 0 0 0 0 0
52781 - 0 0 0 0 0 0 0 0 0 0 0 0
52782 - 0 0 0 0 0 0 0 0 0 10 10 10
52783 - 38 38 38 86 86 86 14 14 14 10 10 10
52784 -195 195 195 188 164 115 192 133 9 225 175 15
52785 -239 182 13 234 190 10 232 195 16 232 200 30
52786 -245 207 45 241 208 19 232 195 16 184 144 12
52787 -218 194 134 211 206 186 42 42 42 2 2 6
52788 - 2 2 6 2 2 6 2 2 6 2 2 6
52789 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
52795 - 0 0 0 0 0 0 0 0 0 0 0 0
52796 - 0 0 0 0 0 0 0 0 0 0 0 0
52797 - 0 0 0 0 0 0 0 0 0 0 0 0
52798 - 0 0 0 0 0 0 0 0 0 0 0 0
52799 - 0 0 0 0 0 0 0 0 0 0 0 0
52800 - 0 0 0 0 0 0 0 0 0 0 0 0
52801 - 0 0 0 0 0 0 0 0 0 0 0 0
52802 - 0 0 0 0 0 0 0 0 0 10 10 10
52803 - 34 34 34 86 86 86 14 14 14 2 2 6
52804 -121 87 25 192 133 9 219 162 10 239 182 13
52805 -236 186 11 232 195 16 241 208 19 244 214 54
52806 -246 218 60 246 218 38 246 215 20 241 208 19
52807 -241 208 19 226 184 13 121 87 25 2 2 6
52808 - 2 2 6 2 2 6 2 2 6 2 2 6
52809 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
52815 - 0 0 0 0 0 0 0 0 0 0 0 0
52816 - 0 0 0 0 0 0 0 0 0 0 0 0
52817 - 0 0 0 0 0 0 0 0 0 0 0 0
52818 - 0 0 0 0 0 0 0 0 0 0 0 0
52819 - 0 0 0 0 0 0 0 0 0 0 0 0
52820 - 0 0 0 0 0 0 0 0 0 0 0 0
52821 - 0 0 0 0 0 0 0 0 0 0 0 0
52822 - 0 0 0 0 0 0 0 0 0 10 10 10
52823 - 34 34 34 82 82 82 30 30 30 61 42 6
52824 -180 123 7 206 145 10 230 174 11 239 182 13
52825 -234 190 10 238 202 15 241 208 19 246 218 74
52826 -246 218 38 246 215 20 246 215 20 246 215 20
52827 -226 184 13 215 174 15 184 144 12 6 6 6
52828 - 2 2 6 2 2 6 2 2 6 2 2 6
52829 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
52835 - 0 0 0 0 0 0 0 0 0 0 0 0
52836 - 0 0 0 0 0 0 0 0 0 0 0 0
52837 - 0 0 0 0 0 0 0 0 0 0 0 0
52838 - 0 0 0 0 0 0 0 0 0 0 0 0
52839 - 0 0 0 0 0 0 0 0 0 0 0 0
52840 - 0 0 0 0 0 0 0 0 0 0 0 0
52841 - 0 0 0 0 0 0 0 0 0 0 0 0
52842 - 0 0 0 0 0 0 0 0 0 10 10 10
52843 - 30 30 30 78 78 78 50 50 50 104 69 6
52844 -192 133 9 216 158 10 236 178 12 236 186 11
52845 -232 195 16 241 208 19 244 214 54 245 215 43
52846 -246 215 20 246 215 20 241 208 19 198 155 10
52847 -200 144 11 216 158 10 156 118 10 2 2 6
52848 - 2 2 6 2 2 6 2 2 6 2 2 6
52849 - 6 6 6 90 90 90 54 54 54 18 18 18
52850 - 6 6 6 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 0 0 0
52855 - 0 0 0 0 0 0 0 0 0 0 0 0
52856 - 0 0 0 0 0 0 0 0 0 0 0 0
52857 - 0 0 0 0 0 0 0 0 0 0 0 0
52858 - 0 0 0 0 0 0 0 0 0 0 0 0
52859 - 0 0 0 0 0 0 0 0 0 0 0 0
52860 - 0 0 0 0 0 0 0 0 0 0 0 0
52861 - 0 0 0 0 0 0 0 0 0 0 0 0
52862 - 0 0 0 0 0 0 0 0 0 10 10 10
52863 - 30 30 30 78 78 78 46 46 46 22 22 22
52864 -137 92 6 210 162 10 239 182 13 238 190 10
52865 -238 202 15 241 208 19 246 215 20 246 215 20
52866 -241 208 19 203 166 17 185 133 11 210 150 10
52867 -216 158 10 210 150 10 102 78 10 2 2 6
52868 - 6 6 6 54 54 54 14 14 14 2 2 6
52869 - 2 2 6 62 62 62 74 74 74 30 30 30
52870 - 10 10 10 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 0 0 0
52875 - 0 0 0 0 0 0 0 0 0 0 0 0
52876 - 0 0 0 0 0 0 0 0 0 0 0 0
52877 - 0 0 0 0 0 0 0 0 0 0 0 0
52878 - 0 0 0 0 0 0 0 0 0 0 0 0
52879 - 0 0 0 0 0 0 0 0 0 0 0 0
52880 - 0 0 0 0 0 0 0 0 0 0 0 0
52881 - 0 0 0 0 0 0 0 0 0 0 0 0
52882 - 0 0 0 0 0 0 0 0 0 10 10 10
52883 - 34 34 34 78 78 78 50 50 50 6 6 6
52884 - 94 70 30 139 102 15 190 146 13 226 184 13
52885 -232 200 30 232 195 16 215 174 15 190 146 13
52886 -168 122 10 192 133 9 210 150 10 213 154 11
52887 -202 150 34 182 157 106 101 98 89 2 2 6
52888 - 2 2 6 78 78 78 116 116 116 58 58 58
52889 - 2 2 6 22 22 22 90 90 90 46 46 46
52890 - 18 18 18 6 6 6 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 0 0 0
52895 - 0 0 0 0 0 0 0 0 0 0 0 0
52896 - 0 0 0 0 0 0 0 0 0 0 0 0
52897 - 0 0 0 0 0 0 0 0 0 0 0 0
52898 - 0 0 0 0 0 0 0 0 0 0 0 0
52899 - 0 0 0 0 0 0 0 0 0 0 0 0
52900 - 0 0 0 0 0 0 0 0 0 0 0 0
52901 - 0 0 0 0 0 0 0 0 0 0 0 0
52902 - 0 0 0 0 0 0 0 0 0 10 10 10
52903 - 38 38 38 86 86 86 50 50 50 6 6 6
52904 -128 128 128 174 154 114 156 107 11 168 122 10
52905 -198 155 10 184 144 12 197 138 11 200 144 11
52906 -206 145 10 206 145 10 197 138 11 188 164 115
52907 -195 195 195 198 198 198 174 174 174 14 14 14
52908 - 2 2 6 22 22 22 116 116 116 116 116 116
52909 - 22 22 22 2 2 6 74 74 74 70 70 70
52910 - 30 30 30 10 10 10 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 0 0 0
52915 - 0 0 0 0 0 0 0 0 0 0 0 0
52916 - 0 0 0 0 0 0 0 0 0 0 0 0
52917 - 0 0 0 0 0 0 0 0 0 0 0 0
52918 - 0 0 0 0 0 0 0 0 0 0 0 0
52919 - 0 0 0 0 0 0 0 0 0 0 0 0
52920 - 0 0 0 0 0 0 0 0 0 0 0 0
52921 - 0 0 0 0 0 0 0 0 0 0 0 0
52922 - 0 0 0 0 0 0 6 6 6 18 18 18
52923 - 50 50 50 101 101 101 26 26 26 10 10 10
52924 -138 138 138 190 190 190 174 154 114 156 107 11
52925 -197 138 11 200 144 11 197 138 11 192 133 9
52926 -180 123 7 190 142 34 190 178 144 187 187 187
52927 -202 202 202 221 221 221 214 214 214 66 66 66
52928 - 2 2 6 2 2 6 50 50 50 62 62 62
52929 - 6 6 6 2 2 6 10 10 10 90 90 90
52930 - 50 50 50 18 18 18 6 6 6 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 0 0 0
52935 - 0 0 0 0 0 0 0 0 0 0 0 0
52936 - 0 0 0 0 0 0 0 0 0 0 0 0
52937 - 0 0 0 0 0 0 0 0 0 0 0 0
52938 - 0 0 0 0 0 0 0 0 0 0 0 0
52939 - 0 0 0 0 0 0 0 0 0 0 0 0
52940 - 0 0 0 0 0 0 0 0 0 0 0 0
52941 - 0 0 0 0 0 0 0 0 0 0 0 0
52942 - 0 0 0 0 0 0 10 10 10 34 34 34
52943 - 74 74 74 74 74 74 2 2 6 6 6 6
52944 -144 144 144 198 198 198 190 190 190 178 166 146
52945 -154 121 60 156 107 11 156 107 11 168 124 44
52946 -174 154 114 187 187 187 190 190 190 210 210 210
52947 -246 246 246 253 253 253 253 253 253 182 182 182
52948 - 6 6 6 2 2 6 2 2 6 2 2 6
52949 - 2 2 6 2 2 6 2 2 6 62 62 62
52950 - 74 74 74 34 34 34 14 14 14 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 0 0 0
52955 - 0 0 0 0 0 0 0 0 0 0 0 0
52956 - 0 0 0 0 0 0 0 0 0 0 0 0
52957 - 0 0 0 0 0 0 0 0 0 0 0 0
52958 - 0 0 0 0 0 0 0 0 0 0 0 0
52959 - 0 0 0 0 0 0 0 0 0 0 0 0
52960 - 0 0 0 0 0 0 0 0 0 0 0 0
52961 - 0 0 0 0 0 0 0 0 0 0 0 0
52962 - 0 0 0 10 10 10 22 22 22 54 54 54
52963 - 94 94 94 18 18 18 2 2 6 46 46 46
52964 -234 234 234 221 221 221 190 190 190 190 190 190
52965 -190 190 190 187 187 187 187 187 187 190 190 190
52966 -190 190 190 195 195 195 214 214 214 242 242 242
52967 -253 253 253 253 253 253 253 253 253 253 253 253
52968 - 82 82 82 2 2 6 2 2 6 2 2 6
52969 - 2 2 6 2 2 6 2 2 6 14 14 14
52970 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
52975 - 0 0 0 0 0 0 0 0 0 0 0 0
52976 - 0 0 0 0 0 0 0 0 0 0 0 0
52977 - 0 0 0 0 0 0 0 0 0 0 0 0
52978 - 0 0 0 0 0 0 0 0 0 0 0 0
52979 - 0 0 0 0 0 0 0 0 0 0 0 0
52980 - 0 0 0 0 0 0 0 0 0 0 0 0
52981 - 0 0 0 0 0 0 0 0 0 0 0 0
52982 - 6 6 6 18 18 18 46 46 46 90 90 90
52983 - 46 46 46 18 18 18 6 6 6 182 182 182
52984 -253 253 253 246 246 246 206 206 206 190 190 190
52985 -190 190 190 190 190 190 190 190 190 190 190 190
52986 -206 206 206 231 231 231 250 250 250 253 253 253
52987 -253 253 253 253 253 253 253 253 253 253 253 253
52988 -202 202 202 14 14 14 2 2 6 2 2 6
52989 - 2 2 6 2 2 6 2 2 6 2 2 6
52990 - 42 42 42 86 86 86 42 42 42 18 18 18
52991 - 6 6 6 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 0 0 0
52995 - 0 0 0 0 0 0 0 0 0 0 0 0
52996 - 0 0 0 0 0 0 0 0 0 0 0 0
52997 - 0 0 0 0 0 0 0 0 0 0 0 0
52998 - 0 0 0 0 0 0 0 0 0 0 0 0
52999 - 0 0 0 0 0 0 0 0 0 0 0 0
53000 - 0 0 0 0 0 0 0 0 0 0 0 0
53001 - 0 0 0 0 0 0 0 0 0 6 6 6
53002 - 14 14 14 38 38 38 74 74 74 66 66 66
53003 - 2 2 6 6 6 6 90 90 90 250 250 250
53004 -253 253 253 253 253 253 238 238 238 198 198 198
53005 -190 190 190 190 190 190 195 195 195 221 221 221
53006 -246 246 246 253 253 253 253 253 253 253 253 253
53007 -253 253 253 253 253 253 253 253 253 253 253 253
53008 -253 253 253 82 82 82 2 2 6 2 2 6
53009 - 2 2 6 2 2 6 2 2 6 2 2 6
53010 - 2 2 6 78 78 78 70 70 70 34 34 34
53011 - 14 14 14 6 6 6 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 0 0 0
53015 - 0 0 0 0 0 0 0 0 0 0 0 0
53016 - 0 0 0 0 0 0 0 0 0 0 0 0
53017 - 0 0 0 0 0 0 0 0 0 0 0 0
53018 - 0 0 0 0 0 0 0 0 0 0 0 0
53019 - 0 0 0 0 0 0 0 0 0 0 0 0
53020 - 0 0 0 0 0 0 0 0 0 0 0 0
53021 - 0 0 0 0 0 0 0 0 0 14 14 14
53022 - 34 34 34 66 66 66 78 78 78 6 6 6
53023 - 2 2 6 18 18 18 218 218 218 253 253 253
53024 -253 253 253 253 253 253 253 253 253 246 246 246
53025 -226 226 226 231 231 231 246 246 246 253 253 253
53026 -253 253 253 253 253 253 253 253 253 253 253 253
53027 -253 253 253 253 253 253 253 253 253 253 253 253
53028 -253 253 253 178 178 178 2 2 6 2 2 6
53029 - 2 2 6 2 2 6 2 2 6 2 2 6
53030 - 2 2 6 18 18 18 90 90 90 62 62 62
53031 - 30 30 30 10 10 10 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 0 0 0
53035 - 0 0 0 0 0 0 0 0 0 0 0 0
53036 - 0 0 0 0 0 0 0 0 0 0 0 0
53037 - 0 0 0 0 0 0 0 0 0 0 0 0
53038 - 0 0 0 0 0 0 0 0 0 0 0 0
53039 - 0 0 0 0 0 0 0 0 0 0 0 0
53040 - 0 0 0 0 0 0 0 0 0 0 0 0
53041 - 0 0 0 0 0 0 10 10 10 26 26 26
53042 - 58 58 58 90 90 90 18 18 18 2 2 6
53043 - 2 2 6 110 110 110 253 253 253 253 253 253
53044 -253 253 253 253 253 253 253 253 253 253 253 253
53045 -250 250 250 253 253 253 253 253 253 253 253 253
53046 -253 253 253 253 253 253 253 253 253 253 253 253
53047 -253 253 253 253 253 253 253 253 253 253 253 253
53048 -253 253 253 231 231 231 18 18 18 2 2 6
53049 - 2 2 6 2 2 6 2 2 6 2 2 6
53050 - 2 2 6 2 2 6 18 18 18 94 94 94
53051 - 54 54 54 26 26 26 10 10 10 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 0 0 0
53055 - 0 0 0 0 0 0 0 0 0 0 0 0
53056 - 0 0 0 0 0 0 0 0 0 0 0 0
53057 - 0 0 0 0 0 0 0 0 0 0 0 0
53058 - 0 0 0 0 0 0 0 0 0 0 0 0
53059 - 0 0 0 0 0 0 0 0 0 0 0 0
53060 - 0 0 0 0 0 0 0 0 0 0 0 0
53061 - 0 0 0 6 6 6 22 22 22 50 50 50
53062 - 90 90 90 26 26 26 2 2 6 2 2 6
53063 - 14 14 14 195 195 195 250 250 250 253 253 253
53064 -253 253 253 253 253 253 253 253 253 253 253 253
53065 -253 253 253 253 253 253 253 253 253 253 253 253
53066 -253 253 253 253 253 253 253 253 253 253 253 253
53067 -253 253 253 253 253 253 253 253 253 253 253 253
53068 -250 250 250 242 242 242 54 54 54 2 2 6
53069 - 2 2 6 2 2 6 2 2 6 2 2 6
53070 - 2 2 6 2 2 6 2 2 6 38 38 38
53071 - 86 86 86 50 50 50 22 22 22 6 6 6
53072 - 0 0 0 0 0 0 0 0 0 0 0 0
53073 - 0 0 0 0 0 0 0 0 0 0 0 0
53074 - 0 0 0 0 0 0 0 0 0 0 0 0
53075 - 0 0 0 0 0 0 0 0 0 0 0 0
53076 - 0 0 0 0 0 0 0 0 0 0 0 0
53077 - 0 0 0 0 0 0 0 0 0 0 0 0
53078 - 0 0 0 0 0 0 0 0 0 0 0 0
53079 - 0 0 0 0 0 0 0 0 0 0 0 0
53080 - 0 0 0 0 0 0 0 0 0 0 0 0
53081 - 6 6 6 14 14 14 38 38 38 82 82 82
53082 - 34 34 34 2 2 6 2 2 6 2 2 6
53083 - 42 42 42 195 195 195 246 246 246 253 253 253
53084 -253 253 253 253 253 253 253 253 253 250 250 250
53085 -242 242 242 242 242 242 250 250 250 253 253 253
53086 -253 253 253 253 253 253 253 253 253 253 253 253
53087 -253 253 253 250 250 250 246 246 246 238 238 238
53088 -226 226 226 231 231 231 101 101 101 6 6 6
53089 - 2 2 6 2 2 6 2 2 6 2 2 6
53090 - 2 2 6 2 2 6 2 2 6 2 2 6
53091 - 38 38 38 82 82 82 42 42 42 14 14 14
53092 - 6 6 6 0 0 0 0 0 0 0 0 0
53093 - 0 0 0 0 0 0 0 0 0 0 0 0
53094 - 0 0 0 0 0 0 0 0 0 0 0 0
53095 - 0 0 0 0 0 0 0 0 0 0 0 0
53096 - 0 0 0 0 0 0 0 0 0 0 0 0
53097 - 0 0 0 0 0 0 0 0 0 0 0 0
53098 - 0 0 0 0 0 0 0 0 0 0 0 0
53099 - 0 0 0 0 0 0 0 0 0 0 0 0
53100 - 0 0 0 0 0 0 0 0 0 0 0 0
53101 - 10 10 10 26 26 26 62 62 62 66 66 66
53102 - 2 2 6 2 2 6 2 2 6 6 6 6
53103 - 70 70 70 170 170 170 206 206 206 234 234 234
53104 -246 246 246 250 250 250 250 250 250 238 238 238
53105 -226 226 226 231 231 231 238 238 238 250 250 250
53106 -250 250 250 250 250 250 246 246 246 231 231 231
53107 -214 214 214 206 206 206 202 202 202 202 202 202
53108 -198 198 198 202 202 202 182 182 182 18 18 18
53109 - 2 2 6 2 2 6 2 2 6 2 2 6
53110 - 2 2 6 2 2 6 2 2 6 2 2 6
53111 - 2 2 6 62 62 62 66 66 66 30 30 30
53112 - 10 10 10 0 0 0 0 0 0 0 0 0
53113 - 0 0 0 0 0 0 0 0 0 0 0 0
53114 - 0 0 0 0 0 0 0 0 0 0 0 0
53115 - 0 0 0 0 0 0 0 0 0 0 0 0
53116 - 0 0 0 0 0 0 0 0 0 0 0 0
53117 - 0 0 0 0 0 0 0 0 0 0 0 0
53118 - 0 0 0 0 0 0 0 0 0 0 0 0
53119 - 0 0 0 0 0 0 0 0 0 0 0 0
53120 - 0 0 0 0 0 0 0 0 0 0 0 0
53121 - 14 14 14 42 42 42 82 82 82 18 18 18
53122 - 2 2 6 2 2 6 2 2 6 10 10 10
53123 - 94 94 94 182 182 182 218 218 218 242 242 242
53124 -250 250 250 253 253 253 253 253 253 250 250 250
53125 -234 234 234 253 253 253 253 253 253 253 253 253
53126 -253 253 253 253 253 253 253 253 253 246 246 246
53127 -238 238 238 226 226 226 210 210 210 202 202 202
53128 -195 195 195 195 195 195 210 210 210 158 158 158
53129 - 6 6 6 14 14 14 50 50 50 14 14 14
53130 - 2 2 6 2 2 6 2 2 6 2 2 6
53131 - 2 2 6 6 6 6 86 86 86 46 46 46
53132 - 18 18 18 6 6 6 0 0 0 0 0 0
53133 - 0 0 0 0 0 0 0 0 0 0 0 0
53134 - 0 0 0 0 0 0 0 0 0 0 0 0
53135 - 0 0 0 0 0 0 0 0 0 0 0 0
53136 - 0 0 0 0 0 0 0 0 0 0 0 0
53137 - 0 0 0 0 0 0 0 0 0 0 0 0
53138 - 0 0 0 0 0 0 0 0 0 0 0 0
53139 - 0 0 0 0 0 0 0 0 0 0 0 0
53140 - 0 0 0 0 0 0 0 0 0 6 6 6
53141 - 22 22 22 54 54 54 70 70 70 2 2 6
53142 - 2 2 6 10 10 10 2 2 6 22 22 22
53143 -166 166 166 231 231 231 250 250 250 253 253 253
53144 -253 253 253 253 253 253 253 253 253 250 250 250
53145 -242 242 242 253 253 253 253 253 253 253 253 253
53146 -253 253 253 253 253 253 253 253 253 253 253 253
53147 -253 253 253 253 253 253 253 253 253 246 246 246
53148 -231 231 231 206 206 206 198 198 198 226 226 226
53149 - 94 94 94 2 2 6 6 6 6 38 38 38
53150 - 30 30 30 2 2 6 2 2 6 2 2 6
53151 - 2 2 6 2 2 6 62 62 62 66 66 66
53152 - 26 26 26 10 10 10 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 0 0 0 0 0 0
53155 - 0 0 0 0 0 0 0 0 0 0 0 0
53156 - 0 0 0 0 0 0 0 0 0 0 0 0
53157 - 0 0 0 0 0 0 0 0 0 0 0 0
53158 - 0 0 0 0 0 0 0 0 0 0 0 0
53159 - 0 0 0 0 0 0 0 0 0 0 0 0
53160 - 0 0 0 0 0 0 0 0 0 10 10 10
53161 - 30 30 30 74 74 74 50 50 50 2 2 6
53162 - 26 26 26 26 26 26 2 2 6 106 106 106
53163 -238 238 238 253 253 253 253 253 253 253 253 253
53164 -253 253 253 253 253 253 253 253 253 253 253 253
53165 -253 253 253 253 253 253 253 253 253 253 253 253
53166 -253 253 253 253 253 253 253 253 253 253 253 253
53167 -253 253 253 253 253 253 253 253 253 253 253 253
53168 -253 253 253 246 246 246 218 218 218 202 202 202
53169 -210 210 210 14 14 14 2 2 6 2 2 6
53170 - 30 30 30 22 22 22 2 2 6 2 2 6
53171 - 2 2 6 2 2 6 18 18 18 86 86 86
53172 - 42 42 42 14 14 14 0 0 0 0 0 0
53173 - 0 0 0 0 0 0 0 0 0 0 0 0
53174 - 0 0 0 0 0 0 0 0 0 0 0 0
53175 - 0 0 0 0 0 0 0 0 0 0 0 0
53176 - 0 0 0 0 0 0 0 0 0 0 0 0
53177 - 0 0 0 0 0 0 0 0 0 0 0 0
53178 - 0 0 0 0 0 0 0 0 0 0 0 0
53179 - 0 0 0 0 0 0 0 0 0 0 0 0
53180 - 0 0 0 0 0 0 0 0 0 14 14 14
53181 - 42 42 42 90 90 90 22 22 22 2 2 6
53182 - 42 42 42 2 2 6 18 18 18 218 218 218
53183 -253 253 253 253 253 253 253 253 253 253 253 253
53184 -253 253 253 253 253 253 253 253 253 253 253 253
53185 -253 253 253 253 253 253 253 253 253 253 253 253
53186 -253 253 253 253 253 253 253 253 253 253 253 253
53187 -253 253 253 253 253 253 253 253 253 253 253 253
53188 -253 253 253 253 253 253 250 250 250 221 221 221
53189 -218 218 218 101 101 101 2 2 6 14 14 14
53190 - 18 18 18 38 38 38 10 10 10 2 2 6
53191 - 2 2 6 2 2 6 2 2 6 78 78 78
53192 - 58 58 58 22 22 22 6 6 6 0 0 0
53193 - 0 0 0 0 0 0 0 0 0 0 0 0
53194 - 0 0 0 0 0 0 0 0 0 0 0 0
53195 - 0 0 0 0 0 0 0 0 0 0 0 0
53196 - 0 0 0 0 0 0 0 0 0 0 0 0
53197 - 0 0 0 0 0 0 0 0 0 0 0 0
53198 - 0 0 0 0 0 0 0 0 0 0 0 0
53199 - 0 0 0 0 0 0 0 0 0 0 0 0
53200 - 0 0 0 0 0 0 6 6 6 18 18 18
53201 - 54 54 54 82 82 82 2 2 6 26 26 26
53202 - 22 22 22 2 2 6 123 123 123 253 253 253
53203 -253 253 253 253 253 253 253 253 253 253 253 253
53204 -253 253 253 253 253 253 253 253 253 253 253 253
53205 -253 253 253 253 253 253 253 253 253 253 253 253
53206 -253 253 253 253 253 253 253 253 253 253 253 253
53207 -253 253 253 253 253 253 253 253 253 253 253 253
53208 -253 253 253 253 253 253 253 253 253 250 250 250
53209 -238 238 238 198 198 198 6 6 6 38 38 38
53210 - 58 58 58 26 26 26 38 38 38 2 2 6
53211 - 2 2 6 2 2 6 2 2 6 46 46 46
53212 - 78 78 78 30 30 30 10 10 10 0 0 0
53213 - 0 0 0 0 0 0 0 0 0 0 0 0
53214 - 0 0 0 0 0 0 0 0 0 0 0 0
53215 - 0 0 0 0 0 0 0 0 0 0 0 0
53216 - 0 0 0 0 0 0 0 0 0 0 0 0
53217 - 0 0 0 0 0 0 0 0 0 0 0 0
53218 - 0 0 0 0 0 0 0 0 0 0 0 0
53219 - 0 0 0 0 0 0 0 0 0 0 0 0
53220 - 0 0 0 0 0 0 10 10 10 30 30 30
53221 - 74 74 74 58 58 58 2 2 6 42 42 42
53222 - 2 2 6 22 22 22 231 231 231 253 253 253
53223 -253 253 253 253 253 253 253 253 253 253 253 253
53224 -253 253 253 253 253 253 253 253 253 250 250 250
53225 -253 253 253 253 253 253 253 253 253 253 253 253
53226 -253 253 253 253 253 253 253 253 253 253 253 253
53227 -253 253 253 253 253 253 253 253 253 253 253 253
53228 -253 253 253 253 253 253 253 253 253 253 253 253
53229 -253 253 253 246 246 246 46 46 46 38 38 38
53230 - 42 42 42 14 14 14 38 38 38 14 14 14
53231 - 2 2 6 2 2 6 2 2 6 6 6 6
53232 - 86 86 86 46 46 46 14 14 14 0 0 0
53233 - 0 0 0 0 0 0 0 0 0 0 0 0
53234 - 0 0 0 0 0 0 0 0 0 0 0 0
53235 - 0 0 0 0 0 0 0 0 0 0 0 0
53236 - 0 0 0 0 0 0 0 0 0 0 0 0
53237 - 0 0 0 0 0 0 0 0 0 0 0 0
53238 - 0 0 0 0 0 0 0 0 0 0 0 0
53239 - 0 0 0 0 0 0 0 0 0 0 0 0
53240 - 0 0 0 6 6 6 14 14 14 42 42 42
53241 - 90 90 90 18 18 18 18 18 18 26 26 26
53242 - 2 2 6 116 116 116 253 253 253 253 253 253
53243 -253 253 253 253 253 253 253 253 253 253 253 253
53244 -253 253 253 253 253 253 250 250 250 238 238 238
53245 -253 253 253 253 253 253 253 253 253 253 253 253
53246 -253 253 253 253 253 253 253 253 253 253 253 253
53247 -253 253 253 253 253 253 253 253 253 253 253 253
53248 -253 253 253 253 253 253 253 253 253 253 253 253
53249 -253 253 253 253 253 253 94 94 94 6 6 6
53250 - 2 2 6 2 2 6 10 10 10 34 34 34
53251 - 2 2 6 2 2 6 2 2 6 2 2 6
53252 - 74 74 74 58 58 58 22 22 22 6 6 6
53253 - 0 0 0 0 0 0 0 0 0 0 0 0
53254 - 0 0 0 0 0 0 0 0 0 0 0 0
53255 - 0 0 0 0 0 0 0 0 0 0 0 0
53256 - 0 0 0 0 0 0 0 0 0 0 0 0
53257 - 0 0 0 0 0 0 0 0 0 0 0 0
53258 - 0 0 0 0 0 0 0 0 0 0 0 0
53259 - 0 0 0 0 0 0 0 0 0 0 0 0
53260 - 0 0 0 10 10 10 26 26 26 66 66 66
53261 - 82 82 82 2 2 6 38 38 38 6 6 6
53262 - 14 14 14 210 210 210 253 253 253 253 253 253
53263 -253 253 253 253 253 253 253 253 253 253 253 253
53264 -253 253 253 253 253 253 246 246 246 242 242 242
53265 -253 253 253 253 253 253 253 253 253 253 253 253
53266 -253 253 253 253 253 253 253 253 253 253 253 253
53267 -253 253 253 253 253 253 253 253 253 253 253 253
53268 -253 253 253 253 253 253 253 253 253 253 253 253
53269 -253 253 253 253 253 253 144 144 144 2 2 6
53270 - 2 2 6 2 2 6 2 2 6 46 46 46
53271 - 2 2 6 2 2 6 2 2 6 2 2 6
53272 - 42 42 42 74 74 74 30 30 30 10 10 10
53273 - 0 0 0 0 0 0 0 0 0 0 0 0
53274 - 0 0 0 0 0 0 0 0 0 0 0 0
53275 - 0 0 0 0 0 0 0 0 0 0 0 0
53276 - 0 0 0 0 0 0 0 0 0 0 0 0
53277 - 0 0 0 0 0 0 0 0 0 0 0 0
53278 - 0 0 0 0 0 0 0 0 0 0 0 0
53279 - 0 0 0 0 0 0 0 0 0 0 0 0
53280 - 6 6 6 14 14 14 42 42 42 90 90 90
53281 - 26 26 26 6 6 6 42 42 42 2 2 6
53282 - 74 74 74 250 250 250 253 253 253 253 253 253
53283 -253 253 253 253 253 253 253 253 253 253 253 253
53284 -253 253 253 253 253 253 242 242 242 242 242 242
53285 -253 253 253 253 253 253 253 253 253 253 253 253
53286 -253 253 253 253 253 253 253 253 253 253 253 253
53287 -253 253 253 253 253 253 253 253 253 253 253 253
53288 -253 253 253 253 253 253 253 253 253 253 253 253
53289 -253 253 253 253 253 253 182 182 182 2 2 6
53290 - 2 2 6 2 2 6 2 2 6 46 46 46
53291 - 2 2 6 2 2 6 2 2 6 2 2 6
53292 - 10 10 10 86 86 86 38 38 38 10 10 10
53293 - 0 0 0 0 0 0 0 0 0 0 0 0
53294 - 0 0 0 0 0 0 0 0 0 0 0 0
53295 - 0 0 0 0 0 0 0 0 0 0 0 0
53296 - 0 0 0 0 0 0 0 0 0 0 0 0
53297 - 0 0 0 0 0 0 0 0 0 0 0 0
53298 - 0 0 0 0 0 0 0 0 0 0 0 0
53299 - 0 0 0 0 0 0 0 0 0 0 0 0
53300 - 10 10 10 26 26 26 66 66 66 82 82 82
53301 - 2 2 6 22 22 22 18 18 18 2 2 6
53302 -149 149 149 253 253 253 253 253 253 253 253 253
53303 -253 253 253 253 253 253 253 253 253 253 253 253
53304 -253 253 253 253 253 253 234 234 234 242 242 242
53305 -253 253 253 253 253 253 253 253 253 253 253 253
53306 -253 253 253 253 253 253 253 253 253 253 253 253
53307 -253 253 253 253 253 253 253 253 253 253 253 253
53308 -253 253 253 253 253 253 253 253 253 253 253 253
53309 -253 253 253 253 253 253 206 206 206 2 2 6
53310 - 2 2 6 2 2 6 2 2 6 38 38 38
53311 - 2 2 6 2 2 6 2 2 6 2 2 6
53312 - 6 6 6 86 86 86 46 46 46 14 14 14
53313 - 0 0 0 0 0 0 0 0 0 0 0 0
53314 - 0 0 0 0 0 0 0 0 0 0 0 0
53315 - 0 0 0 0 0 0 0 0 0 0 0 0
53316 - 0 0 0 0 0 0 0 0 0 0 0 0
53317 - 0 0 0 0 0 0 0 0 0 0 0 0
53318 - 0 0 0 0 0 0 0 0 0 0 0 0
53319 - 0 0 0 0 0 0 0 0 0 6 6 6
53320 - 18 18 18 46 46 46 86 86 86 18 18 18
53321 - 2 2 6 34 34 34 10 10 10 6 6 6
53322 -210 210 210 253 253 253 253 253 253 253 253 253
53323 -253 253 253 253 253 253 253 253 253 253 253 253
53324 -253 253 253 253 253 253 234 234 234 242 242 242
53325 -253 253 253 253 253 253 253 253 253 253 253 253
53326 -253 253 253 253 253 253 253 253 253 253 253 253
53327 -253 253 253 253 253 253 253 253 253 253 253 253
53328 -253 253 253 253 253 253 253 253 253 253 253 253
53329 -253 253 253 253 253 253 221 221 221 6 6 6
53330 - 2 2 6 2 2 6 6 6 6 30 30 30
53331 - 2 2 6 2 2 6 2 2 6 2 2 6
53332 - 2 2 6 82 82 82 54 54 54 18 18 18
53333 - 6 6 6 0 0 0 0 0 0 0 0 0
53334 - 0 0 0 0 0 0 0 0 0 0 0 0
53335 - 0 0 0 0 0 0 0 0 0 0 0 0
53336 - 0 0 0 0 0 0 0 0 0 0 0 0
53337 - 0 0 0 0 0 0 0 0 0 0 0 0
53338 - 0 0 0 0 0 0 0 0 0 0 0 0
53339 - 0 0 0 0 0 0 0 0 0 10 10 10
53340 - 26 26 26 66 66 66 62 62 62 2 2 6
53341 - 2 2 6 38 38 38 10 10 10 26 26 26
53342 -238 238 238 253 253 253 253 253 253 253 253 253
53343 -253 253 253 253 253 253 253 253 253 253 253 253
53344 -253 253 253 253 253 253 231 231 231 238 238 238
53345 -253 253 253 253 253 253 253 253 253 253 253 253
53346 -253 253 253 253 253 253 253 253 253 253 253 253
53347 -253 253 253 253 253 253 253 253 253 253 253 253
53348 -253 253 253 253 253 253 253 253 253 253 253 253
53349 -253 253 253 253 253 253 231 231 231 6 6 6
53350 - 2 2 6 2 2 6 10 10 10 30 30 30
53351 - 2 2 6 2 2 6 2 2 6 2 2 6
53352 - 2 2 6 66 66 66 58 58 58 22 22 22
53353 - 6 6 6 0 0 0 0 0 0 0 0 0
53354 - 0 0 0 0 0 0 0 0 0 0 0 0
53355 - 0 0 0 0 0 0 0 0 0 0 0 0
53356 - 0 0 0 0 0 0 0 0 0 0 0 0
53357 - 0 0 0 0 0 0 0 0 0 0 0 0
53358 - 0 0 0 0 0 0 0 0 0 0 0 0
53359 - 0 0 0 0 0 0 0 0 0 10 10 10
53360 - 38 38 38 78 78 78 6 6 6 2 2 6
53361 - 2 2 6 46 46 46 14 14 14 42 42 42
53362 -246 246 246 253 253 253 253 253 253 253 253 253
53363 -253 253 253 253 253 253 253 253 253 253 253 253
53364 -253 253 253 253 253 253 231 231 231 242 242 242
53365 -253 253 253 253 253 253 253 253 253 253 253 253
53366 -253 253 253 253 253 253 253 253 253 253 253 253
53367 -253 253 253 253 253 253 253 253 253 253 253 253
53368 -253 253 253 253 253 253 253 253 253 253 253 253
53369 -253 253 253 253 253 253 234 234 234 10 10 10
53370 - 2 2 6 2 2 6 22 22 22 14 14 14
53371 - 2 2 6 2 2 6 2 2 6 2 2 6
53372 - 2 2 6 66 66 66 62 62 62 22 22 22
53373 - 6 6 6 0 0 0 0 0 0 0 0 0
53374 - 0 0 0 0 0 0 0 0 0 0 0 0
53375 - 0 0 0 0 0 0 0 0 0 0 0 0
53376 - 0 0 0 0 0 0 0 0 0 0 0 0
53377 - 0 0 0 0 0 0 0 0 0 0 0 0
53378 - 0 0 0 0 0 0 0 0 0 0 0 0
53379 - 0 0 0 0 0 0 6 6 6 18 18 18
53380 - 50 50 50 74 74 74 2 2 6 2 2 6
53381 - 14 14 14 70 70 70 34 34 34 62 62 62
53382 -250 250 250 253 253 253 253 253 253 253 253 253
53383 -253 253 253 253 253 253 253 253 253 253 253 253
53384 -253 253 253 253 253 253 231 231 231 246 246 246
53385 -253 253 253 253 253 253 253 253 253 253 253 253
53386 -253 253 253 253 253 253 253 253 253 253 253 253
53387 -253 253 253 253 253 253 253 253 253 253 253 253
53388 -253 253 253 253 253 253 253 253 253 253 253 253
53389 -253 253 253 253 253 253 234 234 234 14 14 14
53390 - 2 2 6 2 2 6 30 30 30 2 2 6
53391 - 2 2 6 2 2 6 2 2 6 2 2 6
53392 - 2 2 6 66 66 66 62 62 62 22 22 22
53393 - 6 6 6 0 0 0 0 0 0 0 0 0
53394 - 0 0 0 0 0 0 0 0 0 0 0 0
53395 - 0 0 0 0 0 0 0 0 0 0 0 0
53396 - 0 0 0 0 0 0 0 0 0 0 0 0
53397 - 0 0 0 0 0 0 0 0 0 0 0 0
53398 - 0 0 0 0 0 0 0 0 0 0 0 0
53399 - 0 0 0 0 0 0 6 6 6 18 18 18
53400 - 54 54 54 62 62 62 2 2 6 2 2 6
53401 - 2 2 6 30 30 30 46 46 46 70 70 70
53402 -250 250 250 253 253 253 253 253 253 253 253 253
53403 -253 253 253 253 253 253 253 253 253 253 253 253
53404 -253 253 253 253 253 253 231 231 231 246 246 246
53405 -253 253 253 253 253 253 253 253 253 253 253 253
53406 -253 253 253 253 253 253 253 253 253 253 253 253
53407 -253 253 253 253 253 253 253 253 253 253 253 253
53408 -253 253 253 253 253 253 253 253 253 253 253 253
53409 -253 253 253 253 253 253 226 226 226 10 10 10
53410 - 2 2 6 6 6 6 30 30 30 2 2 6
53411 - 2 2 6 2 2 6 2 2 6 2 2 6
53412 - 2 2 6 66 66 66 58 58 58 22 22 22
53413 - 6 6 6 0 0 0 0 0 0 0 0 0
53414 - 0 0 0 0 0 0 0 0 0 0 0 0
53415 - 0 0 0 0 0 0 0 0 0 0 0 0
53416 - 0 0 0 0 0 0 0 0 0 0 0 0
53417 - 0 0 0 0 0 0 0 0 0 0 0 0
53418 - 0 0 0 0 0 0 0 0 0 0 0 0
53419 - 0 0 0 0 0 0 6 6 6 22 22 22
53420 - 58 58 58 62 62 62 2 2 6 2 2 6
53421 - 2 2 6 2 2 6 30 30 30 78 78 78
53422 -250 250 250 253 253 253 253 253 253 253 253 253
53423 -253 253 253 253 253 253 253 253 253 253 253 253
53424 -253 253 253 253 253 253 231 231 231 246 246 246
53425 -253 253 253 253 253 253 253 253 253 253 253 253
53426 -253 253 253 253 253 253 253 253 253 253 253 253
53427 -253 253 253 253 253 253 253 253 253 253 253 253
53428 -253 253 253 253 253 253 253 253 253 253 253 253
53429 -253 253 253 253 253 253 206 206 206 2 2 6
53430 - 22 22 22 34 34 34 18 14 6 22 22 22
53431 - 26 26 26 18 18 18 6 6 6 2 2 6
53432 - 2 2 6 82 82 82 54 54 54 18 18 18
53433 - 6 6 6 0 0 0 0 0 0 0 0 0
53434 - 0 0 0 0 0 0 0 0 0 0 0 0
53435 - 0 0 0 0 0 0 0 0 0 0 0 0
53436 - 0 0 0 0 0 0 0 0 0 0 0 0
53437 - 0 0 0 0 0 0 0 0 0 0 0 0
53438 - 0 0 0 0 0 0 0 0 0 0 0 0
53439 - 0 0 0 0 0 0 6 6 6 26 26 26
53440 - 62 62 62 106 106 106 74 54 14 185 133 11
53441 -210 162 10 121 92 8 6 6 6 62 62 62
53442 -238 238 238 253 253 253 253 253 253 253 253 253
53443 -253 253 253 253 253 253 253 253 253 253 253 253
53444 -253 253 253 253 253 253 231 231 231 246 246 246
53445 -253 253 253 253 253 253 253 253 253 253 253 253
53446 -253 253 253 253 253 253 253 253 253 253 253 253
53447 -253 253 253 253 253 253 253 253 253 253 253 253
53448 -253 253 253 253 253 253 253 253 253 253 253 253
53449 -253 253 253 253 253 253 158 158 158 18 18 18
53450 - 14 14 14 2 2 6 2 2 6 2 2 6
53451 - 6 6 6 18 18 18 66 66 66 38 38 38
53452 - 6 6 6 94 94 94 50 50 50 18 18 18
53453 - 6 6 6 0 0 0 0 0 0 0 0 0
53454 - 0 0 0 0 0 0 0 0 0 0 0 0
53455 - 0 0 0 0 0 0 0 0 0 0 0 0
53456 - 0 0 0 0 0 0 0 0 0 0 0 0
53457 - 0 0 0 0 0 0 0 0 0 0 0 0
53458 - 0 0 0 0 0 0 0 0 0 6 6 6
53459 - 10 10 10 10 10 10 18 18 18 38 38 38
53460 - 78 78 78 142 134 106 216 158 10 242 186 14
53461 -246 190 14 246 190 14 156 118 10 10 10 10
53462 - 90 90 90 238 238 238 253 253 253 253 253 253
53463 -253 253 253 253 253 253 253 253 253 253 253 253
53464 -253 253 253 253 253 253 231 231 231 250 250 250
53465 -253 253 253 253 253 253 253 253 253 253 253 253
53466 -253 253 253 253 253 253 253 253 253 253 253 253
53467 -253 253 253 253 253 253 253 253 253 253 253 253
53468 -253 253 253 253 253 253 253 253 253 246 230 190
53469 -238 204 91 238 204 91 181 142 44 37 26 9
53470 - 2 2 6 2 2 6 2 2 6 2 2 6
53471 - 2 2 6 2 2 6 38 38 38 46 46 46
53472 - 26 26 26 106 106 106 54 54 54 18 18 18
53473 - 6 6 6 0 0 0 0 0 0 0 0 0
53474 - 0 0 0 0 0 0 0 0 0 0 0 0
53475 - 0 0 0 0 0 0 0 0 0 0 0 0
53476 - 0 0 0 0 0 0 0 0 0 0 0 0
53477 - 0 0 0 0 0 0 0 0 0 0 0 0
53478 - 0 0 0 6 6 6 14 14 14 22 22 22
53479 - 30 30 30 38 38 38 50 50 50 70 70 70
53480 -106 106 106 190 142 34 226 170 11 242 186 14
53481 -246 190 14 246 190 14 246 190 14 154 114 10
53482 - 6 6 6 74 74 74 226 226 226 253 253 253
53483 -253 253 253 253 253 253 253 253 253 253 253 253
53484 -253 253 253 253 253 253 231 231 231 250 250 250
53485 -253 253 253 253 253 253 253 253 253 253 253 253
53486 -253 253 253 253 253 253 253 253 253 253 253 253
53487 -253 253 253 253 253 253 253 253 253 253 253 253
53488 -253 253 253 253 253 253 253 253 253 228 184 62
53489 -241 196 14 241 208 19 232 195 16 38 30 10
53490 - 2 2 6 2 2 6 2 2 6 2 2 6
53491 - 2 2 6 6 6 6 30 30 30 26 26 26
53492 -203 166 17 154 142 90 66 66 66 26 26 26
53493 - 6 6 6 0 0 0 0 0 0 0 0 0
53494 - 0 0 0 0 0 0 0 0 0 0 0 0
53495 - 0 0 0 0 0 0 0 0 0 0 0 0
53496 - 0 0 0 0 0 0 0 0 0 0 0 0
53497 - 0 0 0 0 0 0 0 0 0 0 0 0
53498 - 6 6 6 18 18 18 38 38 38 58 58 58
53499 - 78 78 78 86 86 86 101 101 101 123 123 123
53500 -175 146 61 210 150 10 234 174 13 246 186 14
53501 -246 190 14 246 190 14 246 190 14 238 190 10
53502 -102 78 10 2 2 6 46 46 46 198 198 198
53503 -253 253 253 253 253 253 253 253 253 253 253 253
53504 -253 253 253 253 253 253 234 234 234 242 242 242
53505 -253 253 253 253 253 253 253 253 253 253 253 253
53506 -253 253 253 253 253 253 253 253 253 253 253 253
53507 -253 253 253 253 253 253 253 253 253 253 253 253
53508 -253 253 253 253 253 253 253 253 253 224 178 62
53509 -242 186 14 241 196 14 210 166 10 22 18 6
53510 - 2 2 6 2 2 6 2 2 6 2 2 6
53511 - 2 2 6 2 2 6 6 6 6 121 92 8
53512 -238 202 15 232 195 16 82 82 82 34 34 34
53513 - 10 10 10 0 0 0 0 0 0 0 0 0
53514 - 0 0 0 0 0 0 0 0 0 0 0 0
53515 - 0 0 0 0 0 0 0 0 0 0 0 0
53516 - 0 0 0 0 0 0 0 0 0 0 0 0
53517 - 0 0 0 0 0 0 0 0 0 0 0 0
53518 - 14 14 14 38 38 38 70 70 70 154 122 46
53519 -190 142 34 200 144 11 197 138 11 197 138 11
53520 -213 154 11 226 170 11 242 186 14 246 190 14
53521 -246 190 14 246 190 14 246 190 14 246 190 14
53522 -225 175 15 46 32 6 2 2 6 22 22 22
53523 -158 158 158 250 250 250 253 253 253 253 253 253
53524 -253 253 253 253 253 253 253 253 253 253 253 253
53525 -253 253 253 253 253 253 253 253 253 253 253 253
53526 -253 253 253 253 253 253 253 253 253 253 253 253
53527 -253 253 253 253 253 253 253 253 253 253 253 253
53528 -253 253 253 250 250 250 242 242 242 224 178 62
53529 -239 182 13 236 186 11 213 154 11 46 32 6
53530 - 2 2 6 2 2 6 2 2 6 2 2 6
53531 - 2 2 6 2 2 6 61 42 6 225 175 15
53532 -238 190 10 236 186 11 112 100 78 42 42 42
53533 - 14 14 14 0 0 0 0 0 0 0 0 0
53534 - 0 0 0 0 0 0 0 0 0 0 0 0
53535 - 0 0 0 0 0 0 0 0 0 0 0 0
53536 - 0 0 0 0 0 0 0 0 0 0 0 0
53537 - 0 0 0 0 0 0 0 0 0 6 6 6
53538 - 22 22 22 54 54 54 154 122 46 213 154 11
53539 -226 170 11 230 174 11 226 170 11 226 170 11
53540 -236 178 12 242 186 14 246 190 14 246 190 14
53541 -246 190 14 246 190 14 246 190 14 246 190 14
53542 -241 196 14 184 144 12 10 10 10 2 2 6
53543 - 6 6 6 116 116 116 242 242 242 253 253 253
53544 -253 253 253 253 253 253 253 253 253 253 253 253
53545 -253 253 253 253 253 253 253 253 253 253 253 253
53546 -253 253 253 253 253 253 253 253 253 253 253 253
53547 -253 253 253 253 253 253 253 253 253 253 253 253
53548 -253 253 253 231 231 231 198 198 198 214 170 54
53549 -236 178 12 236 178 12 210 150 10 137 92 6
53550 - 18 14 6 2 2 6 2 2 6 2 2 6
53551 - 6 6 6 70 47 6 200 144 11 236 178 12
53552 -239 182 13 239 182 13 124 112 88 58 58 58
53553 - 22 22 22 6 6 6 0 0 0 0 0 0
53554 - 0 0 0 0 0 0 0 0 0 0 0 0
53555 - 0 0 0 0 0 0 0 0 0 0 0 0
53556 - 0 0 0 0 0 0 0 0 0 0 0 0
53557 - 0 0 0 0 0 0 0 0 0 10 10 10
53558 - 30 30 30 70 70 70 180 133 36 226 170 11
53559 -239 182 13 242 186 14 242 186 14 246 186 14
53560 -246 190 14 246 190 14 246 190 14 246 190 14
53561 -246 190 14 246 190 14 246 190 14 246 190 14
53562 -246 190 14 232 195 16 98 70 6 2 2 6
53563 - 2 2 6 2 2 6 66 66 66 221 221 221
53564 -253 253 253 253 253 253 253 253 253 253 253 253
53565 -253 253 253 253 253 253 253 253 253 253 253 253
53566 -253 253 253 253 253 253 253 253 253 253 253 253
53567 -253 253 253 253 253 253 253 253 253 253 253 253
53568 -253 253 253 206 206 206 198 198 198 214 166 58
53569 -230 174 11 230 174 11 216 158 10 192 133 9
53570 -163 110 8 116 81 8 102 78 10 116 81 8
53571 -167 114 7 197 138 11 226 170 11 239 182 13
53572 -242 186 14 242 186 14 162 146 94 78 78 78
53573 - 34 34 34 14 14 14 6 6 6 0 0 0
53574 - 0 0 0 0 0 0 0 0 0 0 0 0
53575 - 0 0 0 0 0 0 0 0 0 0 0 0
53576 - 0 0 0 0 0 0 0 0 0 0 0 0
53577 - 0 0 0 0 0 0 0 0 0 6 6 6
53578 - 30 30 30 78 78 78 190 142 34 226 170 11
53579 -239 182 13 246 190 14 246 190 14 246 190 14
53580 -246 190 14 246 190 14 246 190 14 246 190 14
53581 -246 190 14 246 190 14 246 190 14 246 190 14
53582 -246 190 14 241 196 14 203 166 17 22 18 6
53583 - 2 2 6 2 2 6 2 2 6 38 38 38
53584 -218 218 218 253 253 253 253 253 253 253 253 253
53585 -253 253 253 253 253 253 253 253 253 253 253 253
53586 -253 253 253 253 253 253 253 253 253 253 253 253
53587 -253 253 253 253 253 253 253 253 253 253 253 253
53588 -250 250 250 206 206 206 198 198 198 202 162 69
53589 -226 170 11 236 178 12 224 166 10 210 150 10
53590 -200 144 11 197 138 11 192 133 9 197 138 11
53591 -210 150 10 226 170 11 242 186 14 246 190 14
53592 -246 190 14 246 186 14 225 175 15 124 112 88
53593 - 62 62 62 30 30 30 14 14 14 6 6 6
53594 - 0 0 0 0 0 0 0 0 0 0 0 0
53595 - 0 0 0 0 0 0 0 0 0 0 0 0
53596 - 0 0 0 0 0 0 0 0 0 0 0 0
53597 - 0 0 0 0 0 0 0 0 0 10 10 10
53598 - 30 30 30 78 78 78 174 135 50 224 166 10
53599 -239 182 13 246 190 14 246 190 14 246 190 14
53600 -246 190 14 246 190 14 246 190 14 246 190 14
53601 -246 190 14 246 190 14 246 190 14 246 190 14
53602 -246 190 14 246 190 14 241 196 14 139 102 15
53603 - 2 2 6 2 2 6 2 2 6 2 2 6
53604 - 78 78 78 250 250 250 253 253 253 253 253 253
53605 -253 253 253 253 253 253 253 253 253 253 253 253
53606 -253 253 253 253 253 253 253 253 253 253 253 253
53607 -253 253 253 253 253 253 253 253 253 253 253 253
53608 -250 250 250 214 214 214 198 198 198 190 150 46
53609 -219 162 10 236 178 12 234 174 13 224 166 10
53610 -216 158 10 213 154 11 213 154 11 216 158 10
53611 -226 170 11 239 182 13 246 190 14 246 190 14
53612 -246 190 14 246 190 14 242 186 14 206 162 42
53613 -101 101 101 58 58 58 30 30 30 14 14 14
53614 - 6 6 6 0 0 0 0 0 0 0 0 0
53615 - 0 0 0 0 0 0 0 0 0 0 0 0
53616 - 0 0 0 0 0 0 0 0 0 0 0 0
53617 - 0 0 0 0 0 0 0 0 0 10 10 10
53618 - 30 30 30 74 74 74 174 135 50 216 158 10
53619 -236 178 12 246 190 14 246 190 14 246 190 14
53620 -246 190 14 246 190 14 246 190 14 246 190 14
53621 -246 190 14 246 190 14 246 190 14 246 190 14
53622 -246 190 14 246 190 14 241 196 14 226 184 13
53623 - 61 42 6 2 2 6 2 2 6 2 2 6
53624 - 22 22 22 238 238 238 253 253 253 253 253 253
53625 -253 253 253 253 253 253 253 253 253 253 253 253
53626 -253 253 253 253 253 253 253 253 253 253 253 253
53627 -253 253 253 253 253 253 253 253 253 253 253 253
53628 -253 253 253 226 226 226 187 187 187 180 133 36
53629 -216 158 10 236 178 12 239 182 13 236 178 12
53630 -230 174 11 226 170 11 226 170 11 230 174 11
53631 -236 178 12 242 186 14 246 190 14 246 190 14
53632 -246 190 14 246 190 14 246 186 14 239 182 13
53633 -206 162 42 106 106 106 66 66 66 34 34 34
53634 - 14 14 14 6 6 6 0 0 0 0 0 0
53635 - 0 0 0 0 0 0 0 0 0 0 0 0
53636 - 0 0 0 0 0 0 0 0 0 0 0 0
53637 - 0 0 0 0 0 0 0 0 0 6 6 6
53638 - 26 26 26 70 70 70 163 133 67 213 154 11
53639 -236 178 12 246 190 14 246 190 14 246 190 14
53640 -246 190 14 246 190 14 246 190 14 246 190 14
53641 -246 190 14 246 190 14 246 190 14 246 190 14
53642 -246 190 14 246 190 14 246 190 14 241 196 14
53643 -190 146 13 18 14 6 2 2 6 2 2 6
53644 - 46 46 46 246 246 246 253 253 253 253 253 253
53645 -253 253 253 253 253 253 253 253 253 253 253 253
53646 -253 253 253 253 253 253 253 253 253 253 253 253
53647 -253 253 253 253 253 253 253 253 253 253 253 253
53648 -253 253 253 221 221 221 86 86 86 156 107 11
53649 -216 158 10 236 178 12 242 186 14 246 186 14
53650 -242 186 14 239 182 13 239 182 13 242 186 14
53651 -242 186 14 246 186 14 246 190 14 246 190 14
53652 -246 190 14 246 190 14 246 190 14 246 190 14
53653 -242 186 14 225 175 15 142 122 72 66 66 66
53654 - 30 30 30 10 10 10 0 0 0 0 0 0
53655 - 0 0 0 0 0 0 0 0 0 0 0 0
53656 - 0 0 0 0 0 0 0 0 0 0 0 0
53657 - 0 0 0 0 0 0 0 0 0 6 6 6
53658 - 26 26 26 70 70 70 163 133 67 210 150 10
53659 -236 178 12 246 190 14 246 190 14 246 190 14
53660 -246 190 14 246 190 14 246 190 14 246 190 14
53661 -246 190 14 246 190 14 246 190 14 246 190 14
53662 -246 190 14 246 190 14 246 190 14 246 190 14
53663 -232 195 16 121 92 8 34 34 34 106 106 106
53664 -221 221 221 253 253 253 253 253 253 253 253 253
53665 -253 253 253 253 253 253 253 253 253 253 253 253
53666 -253 253 253 253 253 253 253 253 253 253 253 253
53667 -253 253 253 253 253 253 253 253 253 253 253 253
53668 -242 242 242 82 82 82 18 14 6 163 110 8
53669 -216 158 10 236 178 12 242 186 14 246 190 14
53670 -246 190 14 246 190 14 246 190 14 246 190 14
53671 -246 190 14 246 190 14 246 190 14 246 190 14
53672 -246 190 14 246 190 14 246 190 14 246 190 14
53673 -246 190 14 246 190 14 242 186 14 163 133 67
53674 - 46 46 46 18 18 18 6 6 6 0 0 0
53675 - 0 0 0 0 0 0 0 0 0 0 0 0
53676 - 0 0 0 0 0 0 0 0 0 0 0 0
53677 - 0 0 0 0 0 0 0 0 0 10 10 10
53678 - 30 30 30 78 78 78 163 133 67 210 150 10
53679 -236 178 12 246 186 14 246 190 14 246 190 14
53680 -246 190 14 246 190 14 246 190 14 246 190 14
53681 -246 190 14 246 190 14 246 190 14 246 190 14
53682 -246 190 14 246 190 14 246 190 14 246 190 14
53683 -241 196 14 215 174 15 190 178 144 253 253 253
53684 -253 253 253 253 253 253 253 253 253 253 253 253
53685 -253 253 253 253 253 253 253 253 253 253 253 253
53686 -253 253 253 253 253 253 253 253 253 253 253 253
53687 -253 253 253 253 253 253 253 253 253 218 218 218
53688 - 58 58 58 2 2 6 22 18 6 167 114 7
53689 -216 158 10 236 178 12 246 186 14 246 190 14
53690 -246 190 14 246 190 14 246 190 14 246 190 14
53691 -246 190 14 246 190 14 246 190 14 246 190 14
53692 -246 190 14 246 190 14 246 190 14 246 190 14
53693 -246 190 14 246 186 14 242 186 14 190 150 46
53694 - 54 54 54 22 22 22 6 6 6 0 0 0
53695 - 0 0 0 0 0 0 0 0 0 0 0 0
53696 - 0 0 0 0 0 0 0 0 0 0 0 0
53697 - 0 0 0 0 0 0 0 0 0 14 14 14
53698 - 38 38 38 86 86 86 180 133 36 213 154 11
53699 -236 178 12 246 186 14 246 190 14 246 190 14
53700 -246 190 14 246 190 14 246 190 14 246 190 14
53701 -246 190 14 246 190 14 246 190 14 246 190 14
53702 -246 190 14 246 190 14 246 190 14 246 190 14
53703 -246 190 14 232 195 16 190 146 13 214 214 214
53704 -253 253 253 253 253 253 253 253 253 253 253 253
53705 -253 253 253 253 253 253 253 253 253 253 253 253
53706 -253 253 253 253 253 253 253 253 253 253 253 253
53707 -253 253 253 250 250 250 170 170 170 26 26 26
53708 - 2 2 6 2 2 6 37 26 9 163 110 8
53709 -219 162 10 239 182 13 246 186 14 246 190 14
53710 -246 190 14 246 190 14 246 190 14 246 190 14
53711 -246 190 14 246 190 14 246 190 14 246 190 14
53712 -246 190 14 246 190 14 246 190 14 246 190 14
53713 -246 186 14 236 178 12 224 166 10 142 122 72
53714 - 46 46 46 18 18 18 6 6 6 0 0 0
53715 - 0 0 0 0 0 0 0 0 0 0 0 0
53716 - 0 0 0 0 0 0 0 0 0 0 0 0
53717 - 0 0 0 0 0 0 6 6 6 18 18 18
53718 - 50 50 50 109 106 95 192 133 9 224 166 10
53719 -242 186 14 246 190 14 246 190 14 246 190 14
53720 -246 190 14 246 190 14 246 190 14 246 190 14
53721 -246 190 14 246 190 14 246 190 14 246 190 14
53722 -246 190 14 246 190 14 246 190 14 246 190 14
53723 -242 186 14 226 184 13 210 162 10 142 110 46
53724 -226 226 226 253 253 253 253 253 253 253 253 253
53725 -253 253 253 253 253 253 253 253 253 253 253 253
53726 -253 253 253 253 253 253 253 253 253 253 253 253
53727 -198 198 198 66 66 66 2 2 6 2 2 6
53728 - 2 2 6 2 2 6 50 34 6 156 107 11
53729 -219 162 10 239 182 13 246 186 14 246 190 14
53730 -246 190 14 246 190 14 246 190 14 246 190 14
53731 -246 190 14 246 190 14 246 190 14 246 190 14
53732 -246 190 14 246 190 14 246 190 14 242 186 14
53733 -234 174 13 213 154 11 154 122 46 66 66 66
53734 - 30 30 30 10 10 10 0 0 0 0 0 0
53735 - 0 0 0 0 0 0 0 0 0 0 0 0
53736 - 0 0 0 0 0 0 0 0 0 0 0 0
53737 - 0 0 0 0 0 0 6 6 6 22 22 22
53738 - 58 58 58 154 121 60 206 145 10 234 174 13
53739 -242 186 14 246 186 14 246 190 14 246 190 14
53740 -246 190 14 246 190 14 246 190 14 246 190 14
53741 -246 190 14 246 190 14 246 190 14 246 190 14
53742 -246 190 14 246 190 14 246 190 14 246 190 14
53743 -246 186 14 236 178 12 210 162 10 163 110 8
53744 - 61 42 6 138 138 138 218 218 218 250 250 250
53745 -253 253 253 253 253 253 253 253 253 250 250 250
53746 -242 242 242 210 210 210 144 144 144 66 66 66
53747 - 6 6 6 2 2 6 2 2 6 2 2 6
53748 - 2 2 6 2 2 6 61 42 6 163 110 8
53749 -216 158 10 236 178 12 246 190 14 246 190 14
53750 -246 190 14 246 190 14 246 190 14 246 190 14
53751 -246 190 14 246 190 14 246 190 14 246 190 14
53752 -246 190 14 239 182 13 230 174 11 216 158 10
53753 -190 142 34 124 112 88 70 70 70 38 38 38
53754 - 18 18 18 6 6 6 0 0 0 0 0 0
53755 - 0 0 0 0 0 0 0 0 0 0 0 0
53756 - 0 0 0 0 0 0 0 0 0 0 0 0
53757 - 0 0 0 0 0 0 6 6 6 22 22 22
53758 - 62 62 62 168 124 44 206 145 10 224 166 10
53759 -236 178 12 239 182 13 242 186 14 242 186 14
53760 -246 186 14 246 190 14 246 190 14 246 190 14
53761 -246 190 14 246 190 14 246 190 14 246 190 14
53762 -246 190 14 246 190 14 246 190 14 246 190 14
53763 -246 190 14 236 178 12 216 158 10 175 118 6
53764 - 80 54 7 2 2 6 6 6 6 30 30 30
53765 - 54 54 54 62 62 62 50 50 50 38 38 38
53766 - 14 14 14 2 2 6 2 2 6 2 2 6
53767 - 2 2 6 2 2 6 2 2 6 2 2 6
53768 - 2 2 6 6 6 6 80 54 7 167 114 7
53769 -213 154 11 236 178 12 246 190 14 246 190 14
53770 -246 190 14 246 190 14 246 190 14 246 190 14
53771 -246 190 14 242 186 14 239 182 13 239 182 13
53772 -230 174 11 210 150 10 174 135 50 124 112 88
53773 - 82 82 82 54 54 54 34 34 34 18 18 18
53774 - 6 6 6 0 0 0 0 0 0 0 0 0
53775 - 0 0 0 0 0 0 0 0 0 0 0 0
53776 - 0 0 0 0 0 0 0 0 0 0 0 0
53777 - 0 0 0 0 0 0 6 6 6 18 18 18
53778 - 50 50 50 158 118 36 192 133 9 200 144 11
53779 -216 158 10 219 162 10 224 166 10 226 170 11
53780 -230 174 11 236 178 12 239 182 13 239 182 13
53781 -242 186 14 246 186 14 246 190 14 246 190 14
53782 -246 190 14 246 190 14 246 190 14 246 190 14
53783 -246 186 14 230 174 11 210 150 10 163 110 8
53784 -104 69 6 10 10 10 2 2 6 2 2 6
53785 - 2 2 6 2 2 6 2 2 6 2 2 6
53786 - 2 2 6 2 2 6 2 2 6 2 2 6
53787 - 2 2 6 2 2 6 2 2 6 2 2 6
53788 - 2 2 6 6 6 6 91 60 6 167 114 7
53789 -206 145 10 230 174 11 242 186 14 246 190 14
53790 -246 190 14 246 190 14 246 186 14 242 186 14
53791 -239 182 13 230 174 11 224 166 10 213 154 11
53792 -180 133 36 124 112 88 86 86 86 58 58 58
53793 - 38 38 38 22 22 22 10 10 10 6 6 6
53794 - 0 0 0 0 0 0 0 0 0 0 0 0
53795 - 0 0 0 0 0 0 0 0 0 0 0 0
53796 - 0 0 0 0 0 0 0 0 0 0 0 0
53797 - 0 0 0 0 0 0 0 0 0 14 14 14
53798 - 34 34 34 70 70 70 138 110 50 158 118 36
53799 -167 114 7 180 123 7 192 133 9 197 138 11
53800 -200 144 11 206 145 10 213 154 11 219 162 10
53801 -224 166 10 230 174 11 239 182 13 242 186 14
53802 -246 186 14 246 186 14 246 186 14 246 186 14
53803 -239 182 13 216 158 10 185 133 11 152 99 6
53804 -104 69 6 18 14 6 2 2 6 2 2 6
53805 - 2 2 6 2 2 6 2 2 6 2 2 6
53806 - 2 2 6 2 2 6 2 2 6 2 2 6
53807 - 2 2 6 2 2 6 2 2 6 2 2 6
53808 - 2 2 6 6 6 6 80 54 7 152 99 6
53809 -192 133 9 219 162 10 236 178 12 239 182 13
53810 -246 186 14 242 186 14 239 182 13 236 178 12
53811 -224 166 10 206 145 10 192 133 9 154 121 60
53812 - 94 94 94 62 62 62 42 42 42 22 22 22
53813 - 14 14 14 6 6 6 0 0 0 0 0 0
53814 - 0 0 0 0 0 0 0 0 0 0 0 0
53815 - 0 0 0 0 0 0 0 0 0 0 0 0
53816 - 0 0 0 0 0 0 0 0 0 0 0 0
53817 - 0 0 0 0 0 0 0 0 0 6 6 6
53818 - 18 18 18 34 34 34 58 58 58 78 78 78
53819 -101 98 89 124 112 88 142 110 46 156 107 11
53820 -163 110 8 167 114 7 175 118 6 180 123 7
53821 -185 133 11 197 138 11 210 150 10 219 162 10
53822 -226 170 11 236 178 12 236 178 12 234 174 13
53823 -219 162 10 197 138 11 163 110 8 130 83 6
53824 - 91 60 6 10 10 10 2 2 6 2 2 6
53825 - 18 18 18 38 38 38 38 38 38 38 38 38
53826 - 38 38 38 38 38 38 38 38 38 38 38 38
53827 - 38 38 38 38 38 38 26 26 26 2 2 6
53828 - 2 2 6 6 6 6 70 47 6 137 92 6
53829 -175 118 6 200 144 11 219 162 10 230 174 11
53830 -234 174 13 230 174 11 219 162 10 210 150 10
53831 -192 133 9 163 110 8 124 112 88 82 82 82
53832 - 50 50 50 30 30 30 14 14 14 6 6 6
53833 - 0 0 0 0 0 0 0 0 0 0 0 0
53834 - 0 0 0 0 0 0 0 0 0 0 0 0
53835 - 0 0 0 0 0 0 0 0 0 0 0 0
53836 - 0 0 0 0 0 0 0 0 0 0 0 0
53837 - 0 0 0 0 0 0 0 0 0 0 0 0
53838 - 6 6 6 14 14 14 22 22 22 34 34 34
53839 - 42 42 42 58 58 58 74 74 74 86 86 86
53840 -101 98 89 122 102 70 130 98 46 121 87 25
53841 -137 92 6 152 99 6 163 110 8 180 123 7
53842 -185 133 11 197 138 11 206 145 10 200 144 11
53843 -180 123 7 156 107 11 130 83 6 104 69 6
53844 - 50 34 6 54 54 54 110 110 110 101 98 89
53845 - 86 86 86 82 82 82 78 78 78 78 78 78
53846 - 78 78 78 78 78 78 78 78 78 78 78 78
53847 - 78 78 78 82 82 82 86 86 86 94 94 94
53848 -106 106 106 101 101 101 86 66 34 124 80 6
53849 -156 107 11 180 123 7 192 133 9 200 144 11
53850 -206 145 10 200 144 11 192 133 9 175 118 6
53851 -139 102 15 109 106 95 70 70 70 42 42 42
53852 - 22 22 22 10 10 10 0 0 0 0 0 0
53853 - 0 0 0 0 0 0 0 0 0 0 0 0
53854 - 0 0 0 0 0 0 0 0 0 0 0 0
53855 - 0 0 0 0 0 0 0 0 0 0 0 0
53856 - 0 0 0 0 0 0 0 0 0 0 0 0
53857 - 0 0 0 0 0 0 0 0 0 0 0 0
53858 - 0 0 0 0 0 0 6 6 6 10 10 10
53859 - 14 14 14 22 22 22 30 30 30 38 38 38
53860 - 50 50 50 62 62 62 74 74 74 90 90 90
53861 -101 98 89 112 100 78 121 87 25 124 80 6
53862 -137 92 6 152 99 6 152 99 6 152 99 6
53863 -138 86 6 124 80 6 98 70 6 86 66 30
53864 -101 98 89 82 82 82 58 58 58 46 46 46
53865 - 38 38 38 34 34 34 34 34 34 34 34 34
53866 - 34 34 34 34 34 34 34 34 34 34 34 34
53867 - 34 34 34 34 34 34 38 38 38 42 42 42
53868 - 54 54 54 82 82 82 94 86 76 91 60 6
53869 -134 86 6 156 107 11 167 114 7 175 118 6
53870 -175 118 6 167 114 7 152 99 6 121 87 25
53871 -101 98 89 62 62 62 34 34 34 18 18 18
53872 - 6 6 6 0 0 0 0 0 0 0 0 0
53873 - 0 0 0 0 0 0 0 0 0 0 0 0
53874 - 0 0 0 0 0 0 0 0 0 0 0 0
53875 - 0 0 0 0 0 0 0 0 0 0 0 0
53876 - 0 0 0 0 0 0 0 0 0 0 0 0
53877 - 0 0 0 0 0 0 0 0 0 0 0 0
53878 - 0 0 0 0 0 0 0 0 0 0 0 0
53879 - 0 0 0 6 6 6 6 6 6 10 10 10
53880 - 18 18 18 22 22 22 30 30 30 42 42 42
53881 - 50 50 50 66 66 66 86 86 86 101 98 89
53882 -106 86 58 98 70 6 104 69 6 104 69 6
53883 -104 69 6 91 60 6 82 62 34 90 90 90
53884 - 62 62 62 38 38 38 22 22 22 14 14 14
53885 - 10 10 10 10 10 10 10 10 10 10 10 10
53886 - 10 10 10 10 10 10 6 6 6 10 10 10
53887 - 10 10 10 10 10 10 10 10 10 14 14 14
53888 - 22 22 22 42 42 42 70 70 70 89 81 66
53889 - 80 54 7 104 69 6 124 80 6 137 92 6
53890 -134 86 6 116 81 8 100 82 52 86 86 86
53891 - 58 58 58 30 30 30 14 14 14 6 6 6
53892 - 0 0 0 0 0 0 0 0 0 0 0 0
53893 - 0 0 0 0 0 0 0 0 0 0 0 0
53894 - 0 0 0 0 0 0 0 0 0 0 0 0
53895 - 0 0 0 0 0 0 0 0 0 0 0 0
53896 - 0 0 0 0 0 0 0 0 0 0 0 0
53897 - 0 0 0 0 0 0 0 0 0 0 0 0
53898 - 0 0 0 0 0 0 0 0 0 0 0 0
53899 - 0 0 0 0 0 0 0 0 0 0 0 0
53900 - 0 0 0 6 6 6 10 10 10 14 14 14
53901 - 18 18 18 26 26 26 38 38 38 54 54 54
53902 - 70 70 70 86 86 86 94 86 76 89 81 66
53903 - 89 81 66 86 86 86 74 74 74 50 50 50
53904 - 30 30 30 14 14 14 6 6 6 0 0 0
53905 - 0 0 0 0 0 0 0 0 0 0 0 0
53906 - 0 0 0 0 0 0 0 0 0 0 0 0
53907 - 0 0 0 0 0 0 0 0 0 0 0 0
53908 - 6 6 6 18 18 18 34 34 34 58 58 58
53909 - 82 82 82 89 81 66 89 81 66 89 81 66
53910 - 94 86 66 94 86 76 74 74 74 50 50 50
53911 - 26 26 26 14 14 14 6 6 6 0 0 0
53912 - 0 0 0 0 0 0 0 0 0 0 0 0
53913 - 0 0 0 0 0 0 0 0 0 0 0 0
53914 - 0 0 0 0 0 0 0 0 0 0 0 0
53915 - 0 0 0 0 0 0 0 0 0 0 0 0
53916 - 0 0 0 0 0 0 0 0 0 0 0 0
53917 - 0 0 0 0 0 0 0 0 0 0 0 0
53918 - 0 0 0 0 0 0 0 0 0 0 0 0
53919 - 0 0 0 0 0 0 0 0 0 0 0 0
53920 - 0 0 0 0 0 0 0 0 0 0 0 0
53921 - 6 6 6 6 6 6 14 14 14 18 18 18
53922 - 30 30 30 38 38 38 46 46 46 54 54 54
53923 - 50 50 50 42 42 42 30 30 30 18 18 18
53924 - 10 10 10 0 0 0 0 0 0 0 0 0
53925 - 0 0 0 0 0 0 0 0 0 0 0 0
53926 - 0 0 0 0 0 0 0 0 0 0 0 0
53927 - 0 0 0 0 0 0 0 0 0 0 0 0
53928 - 0 0 0 6 6 6 14 14 14 26 26 26
53929 - 38 38 38 50 50 50 58 58 58 58 58 58
53930 - 54 54 54 42 42 42 30 30 30 18 18 18
53931 - 10 10 10 0 0 0 0 0 0 0 0 0
53932 - 0 0 0 0 0 0 0 0 0 0 0 0
53933 - 0 0 0 0 0 0 0 0 0 0 0 0
53934 - 0 0 0 0 0 0 0 0 0 0 0 0
53935 - 0 0 0 0 0 0 0 0 0 0 0 0
53936 - 0 0 0 0 0 0 0 0 0 0 0 0
53937 - 0 0 0 0 0 0 0 0 0 0 0 0
53938 - 0 0 0 0 0 0 0 0 0 0 0 0
53939 - 0 0 0 0 0 0 0 0 0 0 0 0
53940 - 0 0 0 0 0 0 0 0 0 0 0 0
53941 - 0 0 0 0 0 0 0 0 0 6 6 6
53942 - 6 6 6 10 10 10 14 14 14 18 18 18
53943 - 18 18 18 14 14 14 10 10 10 6 6 6
53944 - 0 0 0 0 0 0 0 0 0 0 0 0
53945 - 0 0 0 0 0 0 0 0 0 0 0 0
53946 - 0 0 0 0 0 0 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 6 6 6
53949 - 14 14 14 18 18 18 22 22 22 22 22 22
53950 - 18 18 18 14 14 14 10 10 10 6 6 6
53951 - 0 0 0 0 0 0 0 0 0 0 0 0
53952 - 0 0 0 0 0 0 0 0 0 0 0 0
53953 - 0 0 0 0 0 0 0 0 0 0 0 0
53954 - 0 0 0 0 0 0 0 0 0 0 0 0
53955 - 0 0 0 0 0 0 0 0 0 0 0 0
53956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53969 +4 4 4 4 4 4
53970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53983 +4 4 4 4 4 4
53984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53997 +4 4 4 4 4 4
53998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54011 +4 4 4 4 4 4
54012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54025 +4 4 4 4 4 4
54026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54039 +4 4 4 4 4 4
54040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54044 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54045 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54049 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54050 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54051 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54053 +4 4 4 4 4 4
54054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54058 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54059 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54060 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54063 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54064 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54065 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54066 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54067 +4 4 4 4 4 4
54068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54072 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54073 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54074 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54077 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54078 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54079 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54080 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54081 +4 4 4 4 4 4
54082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54085 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54086 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54087 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54088 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54090 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54091 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54092 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54093 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54094 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54095 +4 4 4 4 4 4
54096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54099 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54100 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54101 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54102 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54103 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54104 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54105 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54106 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54107 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54108 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54109 +4 4 4 4 4 4
54110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54113 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54114 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54115 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54116 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54117 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54118 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54119 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54120 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54121 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54122 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54123 +4 4 4 4 4 4
54124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54126 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54127 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54128 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54129 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54130 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54131 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54132 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54133 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54134 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54135 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54136 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54137 +4 4 4 4 4 4
54138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54140 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54141 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54142 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54143 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54144 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54145 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54146 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54147 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54148 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54149 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54150 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54151 +4 4 4 4 4 4
54152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54154 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54155 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54156 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54157 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54158 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54159 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54160 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54161 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54162 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54163 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54164 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54165 +4 4 4 4 4 4
54166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54168 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54169 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54170 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54171 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54172 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54173 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54174 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54175 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54176 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54177 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54178 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54179 +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 4 4 4 4 4 4 3 3 3 0 0 0
54182 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54183 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54184 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54185 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54186 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54187 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54188 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54189 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54190 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54191 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54192 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54193 +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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54196 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54197 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54198 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54199 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54200 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54201 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54202 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54203 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54204 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54205 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54206 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54207 +0 0 0 4 4 4
54208 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54209 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54210 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54211 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54212 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54213 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54214 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54215 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54216 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54217 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54218 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54219 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54220 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54221 +2 0 0 0 0 0
54222 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54223 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54224 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54225 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54226 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54227 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54228 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54229 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54230 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54231 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54232 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54233 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54234 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54235 +37 38 37 0 0 0
54236 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54237 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54238 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54239 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54240 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54241 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54242 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54243 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54244 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54245 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54246 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54247 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54248 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54249 +85 115 134 4 0 0
54250 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54251 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54252 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54253 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54254 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54255 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54256 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54257 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54258 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54259 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54260 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54261 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54262 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54263 +60 73 81 4 0 0
54264 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54265 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54266 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54267 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54268 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54269 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54270 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54271 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54272 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54273 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54274 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54275 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54276 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54277 +16 19 21 4 0 0
54278 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54279 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54280 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54281 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54282 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54283 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54284 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54285 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54286 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54287 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54288 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54289 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54290 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54291 +4 0 0 4 3 3
54292 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54293 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54294 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54296 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54297 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54298 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54299 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54300 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54301 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54302 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54303 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54304 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54305 +3 2 2 4 4 4
54306 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54307 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54308 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54309 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54310 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54311 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54312 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54313 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54314 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54315 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54316 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54317 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54318 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54319 +4 4 4 4 4 4
54320 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54321 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54322 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54323 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54324 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54325 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54326 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54327 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54328 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54329 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54330 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54331 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54332 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54333 +4 4 4 4 4 4
54334 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54335 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54336 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54337 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54338 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54339 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54340 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54341 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54342 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54343 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54344 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54345 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54346 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54347 +5 5 5 5 5 5
54348 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54349 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54350 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54351 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54352 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54353 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54354 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54355 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54356 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54357 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54358 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54359 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54360 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54361 +5 5 5 4 4 4
54362 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54363 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54364 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54365 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54366 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54367 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54368 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54369 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54370 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54371 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54372 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54373 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54375 +4 4 4 4 4 4
54376 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54377 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54378 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54379 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54380 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54381 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54382 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54383 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54384 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54385 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54386 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54387 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54389 +4 4 4 4 4 4
54390 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54391 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54392 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54393 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54394 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54395 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54396 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54397 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54398 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54399 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54400 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54403 +4 4 4 4 4 4
54404 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54405 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54406 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54407 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54408 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54409 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54410 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54411 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54412 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54413 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54414 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54417 +4 4 4 4 4 4
54418 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54419 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54420 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54421 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54422 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54423 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54424 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54425 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54426 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54427 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54428 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54431 +4 4 4 4 4 4
54432 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54433 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54434 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54435 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54436 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54437 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54438 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54439 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54440 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54441 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54442 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
54443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54445 +4 4 4 4 4 4
54446 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54447 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54448 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54449 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54450 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54451 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54452 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54453 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54454 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54455 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54456 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
54457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54459 +4 4 4 4 4 4
54460 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54461 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54462 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54463 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54464 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54465 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54466 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54467 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54468 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54469 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54470 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54473 +4 4 4 4 4 4
54474 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54475 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54476 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54477 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54478 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54479 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54480 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54481 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54482 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54483 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54484 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54487 +4 4 4 4 4 4
54488 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54489 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54490 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54491 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54492 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54493 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54494 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54495 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54496 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54497 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54498 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54501 +4 4 4 4 4 4
54502 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54503 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54504 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54505 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54506 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54507 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54508 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54509 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54510 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54511 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54512 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54515 +4 4 4 4 4 4
54516 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54517 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54518 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54519 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54520 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54521 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54522 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54523 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54524 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54525 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54526 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54529 +4 4 4 4 4 4
54530 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54531 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54532 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54533 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54534 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54535 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54536 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54537 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54538 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54539 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54540 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54543 +4 4 4 4 4 4
54544 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54545 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54546 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54547 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54548 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54549 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54550 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54551 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54552 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54553 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54554 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54557 +4 4 4 4 4 4
54558 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54559 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54560 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54561 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54562 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54563 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54564 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54565 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54566 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54567 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54568 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54571 +4 4 4 4 4 4
54572 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54573 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54574 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54575 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54576 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54577 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54578 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54579 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54580 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54581 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54582 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54585 +4 4 4 4 4 4
54586 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54587 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54588 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54589 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54590 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54591 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54592 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54593 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54594 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54595 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54596 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54599 +4 4 4 4 4 4
54600 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54601 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54602 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54603 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54604 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54605 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54606 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54607 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54608 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54609 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54610 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54613 +4 4 4 4 4 4
54614 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54615 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54616 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54617 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54618 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54619 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54620 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54621 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54622 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54623 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54624 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54627 +4 4 4 4 4 4
54628 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54629 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54630 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54631 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54632 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54633 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54634 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54635 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54636 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54637 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54638 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54641 +4 4 4 4 4 4
54642 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54643 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54644 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54645 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54646 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54647 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54648 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54649 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54650 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54651 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54652 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54655 +4 4 4 4 4 4
54656 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54657 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54658 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54659 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54660 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54661 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54662 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54663 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54664 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54665 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54666 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54669 +4 4 4 4 4 4
54670 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54671 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54672 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54673 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54674 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54675 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54676 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54677 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54678 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54679 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54680 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54683 +4 4 4 4 4 4
54684 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54685 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54686 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54687 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54688 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54689 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54690 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54691 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54692 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54693 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54694 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54697 +4 4 4 4 4 4
54698 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54699 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54700 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54701 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54702 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54703 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54704 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54705 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54706 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54707 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54708 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54711 +4 4 4 4 4 4
54712 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54713 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54714 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54715 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54716 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54717 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54718 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54719 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54720 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54721 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54722 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54725 +4 4 4 4 4 4
54726 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54727 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54728 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54729 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54730 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54731 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54732 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54733 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54734 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54735 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54736 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54739 +4 4 4 4 4 4
54740 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54741 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54742 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54743 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54744 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54745 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54746 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54747 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54748 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54749 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54750 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54753 +4 4 4 4 4 4
54754 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54755 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54756 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54757 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54758 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54759 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54760 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54761 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54762 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54763 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54764 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54767 +4 4 4 4 4 4
54768 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54769 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54770 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54771 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54772 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54773 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54774 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54775 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54776 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54777 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54781 +4 4 4 4 4 4
54782 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54783 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54784 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54785 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54786 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54787 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54788 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54789 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54790 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54791 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54795 +4 4 4 4 4 4
54796 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54797 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54798 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54799 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54800 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54801 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54802 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54803 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54804 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54805 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54809 +4 4 4 4 4 4
54810 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54811 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54812 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54813 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54814 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54815 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54816 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54817 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54818 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54819 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54823 +4 4 4 4 4 4
54824 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54825 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54826 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54827 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54828 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54829 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54830 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54831 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54832 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
54833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54837 +4 4 4 4 4 4
54838 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54839 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54840 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54841 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54842 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54843 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54844 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54845 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54846 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
54847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54851 +4 4 4 4 4 4
54852 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54853 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54854 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54855 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54856 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54857 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54858 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54859 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54860 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54865 +4 4 4 4 4 4
54866 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54867 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54868 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54869 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54870 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54871 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54872 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54873 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
54874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54879 +4 4 4 4 4 4
54880 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54881 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54882 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54883 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54884 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54885 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54886 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54887 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54893 +4 4 4 4 4 4
54894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54895 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54896 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54897 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54898 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54899 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54900 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54901 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
54902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54907 +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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54910 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54911 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54912 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54913 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54914 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54915 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
54916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54921 +4 4 4 4 4 4
54922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54923 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54924 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54925 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54926 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54927 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54928 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54929 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54935 +4 4 4 4 4 4
54936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54938 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54939 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54940 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54941 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54942 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54943 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54949 +4 4 4 4 4 4
54950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54953 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54954 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54955 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54956 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
54957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54963 +4 4 4 4 4 4
54964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54967 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54968 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54969 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54970 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
54971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54977 +4 4 4 4 4 4
54978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54981 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54982 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54983 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54984 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
54985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54991 +4 4 4 4 4 4
54992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54995 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
54996 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
54997 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
54998 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
54999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55005 +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 4 4 4 4 4 4 4 4 4 4 4 4
55008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55010 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55011 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55012 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55019 +4 4 4 4 4 4
55020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55024 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55025 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55026 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55033 +4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
55036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55038 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55039 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55040 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55047 +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 4 4 4 4 4 4 4 4 4 4 4 4
55050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55052 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55053 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55058 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
55064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55066 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55067 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55072 +4 4 4 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
55076 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55077 index a01147f..5d896f8 100644
55078 --- a/drivers/video/matrox/matroxfb_DAC1064.c
55079 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
55080 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55081
55082 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55083 struct matrox_switch matrox_mystique = {
55084 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55085 + .preinit = MGA1064_preinit,
55086 + .reset = MGA1064_reset,
55087 + .init = MGA1064_init,
55088 + .restore = MGA1064_restore,
55089 };
55090 EXPORT_SYMBOL(matrox_mystique);
55091 #endif
55092
55093 #ifdef CONFIG_FB_MATROX_G
55094 struct matrox_switch matrox_G100 = {
55095 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55096 + .preinit = MGAG100_preinit,
55097 + .reset = MGAG100_reset,
55098 + .init = MGAG100_init,
55099 + .restore = MGAG100_restore,
55100 };
55101 EXPORT_SYMBOL(matrox_G100);
55102 #endif
55103 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55104 index 195ad7c..09743fc 100644
55105 --- a/drivers/video/matrox/matroxfb_Ti3026.c
55106 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
55107 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55108 }
55109
55110 struct matrox_switch matrox_millennium = {
55111 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55112 + .preinit = Ti3026_preinit,
55113 + .reset = Ti3026_reset,
55114 + .init = Ti3026_init,
55115 + .restore = Ti3026_restore
55116 };
55117 EXPORT_SYMBOL(matrox_millennium);
55118 #endif
55119 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55120 index fe92eed..106e085 100644
55121 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
55122 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55123 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55124 struct mb862xxfb_par *par = info->par;
55125
55126 if (info->var.bits_per_pixel == 32) {
55127 - info->fbops->fb_fillrect = cfb_fillrect;
55128 - info->fbops->fb_copyarea = cfb_copyarea;
55129 - info->fbops->fb_imageblit = cfb_imageblit;
55130 + pax_open_kernel();
55131 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55132 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55133 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55134 + pax_close_kernel();
55135 } else {
55136 outreg(disp, GC_L0EM, 3);
55137 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55138 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55139 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55140 + pax_open_kernel();
55141 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55142 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55143 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55144 + pax_close_kernel();
55145 }
55146 outreg(draw, GDC_REG_DRAW_BASE, 0);
55147 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55148 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55149 index ff22871..b129bed 100644
55150 --- a/drivers/video/nvidia/nvidia.c
55151 +++ b/drivers/video/nvidia/nvidia.c
55152 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55153 info->fix.line_length = (info->var.xres_virtual *
55154 info->var.bits_per_pixel) >> 3;
55155 if (info->var.accel_flags) {
55156 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55157 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55158 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55159 - info->fbops->fb_sync = nvidiafb_sync;
55160 + pax_open_kernel();
55161 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55162 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55163 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55164 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55165 + pax_close_kernel();
55166 info->pixmap.scan_align = 4;
55167 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55168 info->flags |= FBINFO_READS_FAST;
55169 NVResetGraphics(info);
55170 } else {
55171 - info->fbops->fb_imageblit = cfb_imageblit;
55172 - info->fbops->fb_fillrect = cfb_fillrect;
55173 - info->fbops->fb_copyarea = cfb_copyarea;
55174 - info->fbops->fb_sync = NULL;
55175 + pax_open_kernel();
55176 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55177 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55178 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55179 + *(void **)&info->fbops->fb_sync = NULL;
55180 + pax_close_kernel();
55181 info->pixmap.scan_align = 1;
55182 info->flags |= FBINFO_HWACCEL_DISABLED;
55183 info->flags &= ~FBINFO_READS_FAST;
55184 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55185 info->pixmap.size = 8 * 1024;
55186 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55187
55188 - if (!hwcur)
55189 - info->fbops->fb_cursor = NULL;
55190 + if (!hwcur) {
55191 + pax_open_kernel();
55192 + *(void **)&info->fbops->fb_cursor = NULL;
55193 + pax_close_kernel();
55194 + }
55195
55196 info->var.accel_flags = (!noaccel);
55197
55198 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55199 index 669a81f..e216d76 100644
55200 --- a/drivers/video/omap2/dss/display.c
55201 +++ b/drivers/video/omap2/dss/display.c
55202 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55203 snprintf(dssdev->alias, sizeof(dssdev->alias),
55204 "display%d", disp_num_counter++);
55205
55206 + pax_open_kernel();
55207 if (drv && drv->get_resolution == NULL)
55208 - drv->get_resolution = omapdss_default_get_resolution;
55209 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55210 if (drv && drv->get_recommended_bpp == NULL)
55211 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55212 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55213 if (drv && drv->get_timings == NULL)
55214 - drv->get_timings = omapdss_default_get_timings;
55215 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55216 + pax_close_kernel();
55217
55218 mutex_lock(&panel_list_mutex);
55219 list_add_tail(&dssdev->panel_list, &panel_list);
55220 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55221 index 83433cb..71e9b98 100644
55222 --- a/drivers/video/s1d13xxxfb.c
55223 +++ b/drivers/video/s1d13xxxfb.c
55224 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55225
55226 switch(prod_id) {
55227 case S1D13506_PROD_ID: /* activate acceleration */
55228 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55229 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55230 + pax_open_kernel();
55231 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55232 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55233 + pax_close_kernel();
55234 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55235 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55236 break;
55237 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55238 index d513ed6..90b0de9 100644
55239 --- a/drivers/video/smscufx.c
55240 +++ b/drivers/video/smscufx.c
55241 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55242 fb_deferred_io_cleanup(info);
55243 kfree(info->fbdefio);
55244 info->fbdefio = NULL;
55245 - info->fbops->fb_mmap = ufx_ops_mmap;
55246 + pax_open_kernel();
55247 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55248 + pax_close_kernel();
55249 }
55250
55251 pr_debug("released /dev/fb%d user=%d count=%d",
55252 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55253 index 025f14e..20eb4db 100644
55254 --- a/drivers/video/udlfb.c
55255 +++ b/drivers/video/udlfb.c
55256 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55257 dlfb_urb_completion(urb);
55258
55259 error:
55260 - atomic_add(bytes_sent, &dev->bytes_sent);
55261 - atomic_add(bytes_identical, &dev->bytes_identical);
55262 - atomic_add(width*height*2, &dev->bytes_rendered);
55263 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55264 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55265 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55266 end_cycles = get_cycles();
55267 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55268 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55269 >> 10)), /* Kcycles */
55270 &dev->cpu_kcycles_used);
55271
55272 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55273 dlfb_urb_completion(urb);
55274
55275 error:
55276 - atomic_add(bytes_sent, &dev->bytes_sent);
55277 - atomic_add(bytes_identical, &dev->bytes_identical);
55278 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55279 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55280 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55281 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55282 end_cycles = get_cycles();
55283 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55284 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55285 >> 10)), /* Kcycles */
55286 &dev->cpu_kcycles_used);
55287 }
55288 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55289 fb_deferred_io_cleanup(info);
55290 kfree(info->fbdefio);
55291 info->fbdefio = NULL;
55292 - info->fbops->fb_mmap = dlfb_ops_mmap;
55293 + pax_open_kernel();
55294 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55295 + pax_close_kernel();
55296 }
55297
55298 pr_warn("released /dev/fb%d user=%d count=%d\n",
55299 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55300 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55301 struct dlfb_data *dev = fb_info->par;
55302 return snprintf(buf, PAGE_SIZE, "%u\n",
55303 - atomic_read(&dev->bytes_rendered));
55304 + atomic_read_unchecked(&dev->bytes_rendered));
55305 }
55306
55307 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55308 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55309 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55310 struct dlfb_data *dev = fb_info->par;
55311 return snprintf(buf, PAGE_SIZE, "%u\n",
55312 - atomic_read(&dev->bytes_identical));
55313 + atomic_read_unchecked(&dev->bytes_identical));
55314 }
55315
55316 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55317 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55318 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55319 struct dlfb_data *dev = fb_info->par;
55320 return snprintf(buf, PAGE_SIZE, "%u\n",
55321 - atomic_read(&dev->bytes_sent));
55322 + atomic_read_unchecked(&dev->bytes_sent));
55323 }
55324
55325 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55326 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55327 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55328 struct dlfb_data *dev = fb_info->par;
55329 return snprintf(buf, PAGE_SIZE, "%u\n",
55330 - atomic_read(&dev->cpu_kcycles_used));
55331 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55332 }
55333
55334 static ssize_t edid_show(
55335 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55336 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55337 struct dlfb_data *dev = fb_info->par;
55338
55339 - atomic_set(&dev->bytes_rendered, 0);
55340 - atomic_set(&dev->bytes_identical, 0);
55341 - atomic_set(&dev->bytes_sent, 0);
55342 - atomic_set(&dev->cpu_kcycles_used, 0);
55343 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55344 + atomic_set_unchecked(&dev->bytes_identical, 0);
55345 + atomic_set_unchecked(&dev->bytes_sent, 0);
55346 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55347
55348 return count;
55349 }
55350 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55351 index 256fba7..6e75516 100644
55352 --- a/drivers/video/uvesafb.c
55353 +++ b/drivers/video/uvesafb.c
55354 @@ -19,6 +19,7 @@
55355 #include <linux/io.h>
55356 #include <linux/mutex.h>
55357 #include <linux/slab.h>
55358 +#include <linux/moduleloader.h>
55359 #include <video/edid.h>
55360 #include <video/uvesafb.h>
55361 #ifdef CONFIG_X86
55362 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55363 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55364 par->pmi_setpal = par->ypan = 0;
55365 } else {
55366 +
55367 +#ifdef CONFIG_PAX_KERNEXEC
55368 +#ifdef CONFIG_MODULES
55369 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55370 +#endif
55371 + if (!par->pmi_code) {
55372 + par->pmi_setpal = par->ypan = 0;
55373 + return 0;
55374 + }
55375 +#endif
55376 +
55377 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55378 + task->t.regs.edi);
55379 +
55380 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55381 + pax_open_kernel();
55382 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55383 + pax_close_kernel();
55384 +
55385 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55386 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55387 +#else
55388 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55389 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55390 +#endif
55391 +
55392 printk(KERN_INFO "uvesafb: protected mode interface info at "
55393 "%04x:%04x\n",
55394 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55395 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55396 par->ypan = ypan;
55397
55398 if (par->pmi_setpal || par->ypan) {
55399 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55400 if (__supported_pte_mask & _PAGE_NX) {
55401 par->pmi_setpal = par->ypan = 0;
55402 printk(KERN_WARNING "uvesafb: NX protection is active, "
55403 "better not use the PMI.\n");
55404 - } else {
55405 + } else
55406 +#endif
55407 uvesafb_vbe_getpmi(task, par);
55408 - }
55409 }
55410 #else
55411 /* The protected mode interface is not available on non-x86. */
55412 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55413 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55414
55415 /* Disable blanking if the user requested so. */
55416 - if (!blank)
55417 - info->fbops->fb_blank = NULL;
55418 + if (!blank) {
55419 + pax_open_kernel();
55420 + *(void **)&info->fbops->fb_blank = NULL;
55421 + pax_close_kernel();
55422 + }
55423
55424 /*
55425 * Find out how much IO memory is required for the mode with
55426 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55427 info->flags = FBINFO_FLAG_DEFAULT |
55428 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55429
55430 - if (!par->ypan)
55431 - info->fbops->fb_pan_display = NULL;
55432 + if (!par->ypan) {
55433 + pax_open_kernel();
55434 + *(void **)&info->fbops->fb_pan_display = NULL;
55435 + pax_close_kernel();
55436 + }
55437 }
55438
55439 static void uvesafb_init_mtrr(struct fb_info *info)
55440 @@ -1792,6 +1822,11 @@ out_mode:
55441 out:
55442 kfree(par->vbe_modes);
55443
55444 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55445 + if (par->pmi_code)
55446 + module_free_exec(NULL, par->pmi_code);
55447 +#endif
55448 +
55449 framebuffer_release(info);
55450 return err;
55451 }
55452 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55453 kfree(par->vbe_modes);
55454 kfree(par->vbe_state_orig);
55455 kfree(par->vbe_state_saved);
55456 +
55457 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55458 + if (par->pmi_code)
55459 + module_free_exec(NULL, par->pmi_code);
55460 +#endif
55461 +
55462 }
55463
55464 framebuffer_release(info);
55465 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55466 index 1c7da3b..56ea0bd 100644
55467 --- a/drivers/video/vesafb.c
55468 +++ b/drivers/video/vesafb.c
55469 @@ -9,6 +9,7 @@
55470 */
55471
55472 #include <linux/module.h>
55473 +#include <linux/moduleloader.h>
55474 #include <linux/kernel.h>
55475 #include <linux/errno.h>
55476 #include <linux/string.h>
55477 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55478 static int vram_total; /* Set total amount of memory */
55479 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55480 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55481 -static void (*pmi_start)(void) __read_mostly;
55482 -static void (*pmi_pal) (void) __read_mostly;
55483 +static void (*pmi_start)(void) __read_only;
55484 +static void (*pmi_pal) (void) __read_only;
55485 static int depth __read_mostly;
55486 static int vga_compat __read_mostly;
55487 /* --------------------------------------------------------------------- */
55488 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55489 unsigned int size_remap;
55490 unsigned int size_total;
55491 char *option = NULL;
55492 + void *pmi_code = NULL;
55493
55494 /* ignore error return of fb_get_options */
55495 fb_get_options("vesafb", &option);
55496 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55497 size_remap = size_total;
55498 vesafb_fix.smem_len = size_remap;
55499
55500 -#ifndef __i386__
55501 - screen_info.vesapm_seg = 0;
55502 -#endif
55503 -
55504 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55505 printk(KERN_WARNING
55506 "vesafb: cannot reserve video memory at 0x%lx\n",
55507 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55508 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55509 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55510
55511 +#ifdef __i386__
55512 +
55513 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55514 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55515 + if (!pmi_code)
55516 +#elif !defined(CONFIG_PAX_KERNEXEC)
55517 + if (0)
55518 +#endif
55519 +
55520 +#endif
55521 + screen_info.vesapm_seg = 0;
55522 +
55523 if (screen_info.vesapm_seg) {
55524 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55525 - screen_info.vesapm_seg,screen_info.vesapm_off);
55526 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55527 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55528 }
55529
55530 if (screen_info.vesapm_seg < 0xc000)
55531 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55532
55533 if (ypan || pmi_setpal) {
55534 unsigned short *pmi_base;
55535 +
55536 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55537 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55538 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55539 +
55540 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55541 + pax_open_kernel();
55542 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55543 +#else
55544 + pmi_code = pmi_base;
55545 +#endif
55546 +
55547 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55548 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55549 +
55550 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55551 + pmi_start = ktva_ktla(pmi_start);
55552 + pmi_pal = ktva_ktla(pmi_pal);
55553 + pax_close_kernel();
55554 +#endif
55555 +
55556 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55557 if (pmi_base[3]) {
55558 printk(KERN_INFO "vesafb: pmi: ports = ");
55559 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55560 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55561 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55562
55563 - if (!ypan)
55564 - info->fbops->fb_pan_display = NULL;
55565 + if (!ypan) {
55566 + pax_open_kernel();
55567 + *(void **)&info->fbops->fb_pan_display = NULL;
55568 + pax_close_kernel();
55569 + }
55570
55571 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55572 err = -ENOMEM;
55573 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55574 fb_info(info, "%s frame buffer device\n", info->fix.id);
55575 return 0;
55576 err:
55577 +
55578 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55579 + module_free_exec(NULL, pmi_code);
55580 +#endif
55581 +
55582 if (info->screen_base)
55583 iounmap(info->screen_base);
55584 framebuffer_release(info);
55585 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55586 index 88714ae..16c2e11 100644
55587 --- a/drivers/video/via/via_clock.h
55588 +++ b/drivers/video/via/via_clock.h
55589 @@ -56,7 +56,7 @@ struct via_clock {
55590
55591 void (*set_engine_pll_state)(u8 state);
55592 void (*set_engine_pll)(struct via_pll_config config);
55593 -};
55594 +} __no_const;
55595
55596
55597 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55598 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55599 index fef20db..d28b1ab 100644
55600 --- a/drivers/xen/xenfs/xenstored.c
55601 +++ b/drivers/xen/xenfs/xenstored.c
55602 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55603 static int xsd_kva_open(struct inode *inode, struct file *file)
55604 {
55605 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55606 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55607 + NULL);
55608 +#else
55609 xen_store_interface);
55610 +#endif
55611 +
55612 if (!file->private_data)
55613 return -ENOMEM;
55614 return 0;
55615 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55616 index 9ff073f..05cef23 100644
55617 --- a/fs/9p/vfs_addr.c
55618 +++ b/fs/9p/vfs_addr.c
55619 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55620
55621 retval = v9fs_file_write_internal(inode,
55622 v9inode->writeback_fid,
55623 - (__force const char __user *)buffer,
55624 + (const char __force_user *)buffer,
55625 len, &offset, 0);
55626 if (retval > 0)
55627 retval = 0;
55628 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55629 index 4e65aa9..043dc9a 100644
55630 --- a/fs/9p/vfs_inode.c
55631 +++ b/fs/9p/vfs_inode.c
55632 @@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55633 void
55634 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55635 {
55636 - char *s = nd_get_link(nd);
55637 + const char *s = nd_get_link(nd);
55638
55639 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55640 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55641 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55642 index 370b24c..ff0be7b 100644
55643 --- a/fs/Kconfig.binfmt
55644 +++ b/fs/Kconfig.binfmt
55645 @@ -103,7 +103,7 @@ config HAVE_AOUT
55646
55647 config BINFMT_AOUT
55648 tristate "Kernel support for a.out and ECOFF binaries"
55649 - depends on HAVE_AOUT
55650 + depends on HAVE_AOUT && BROKEN
55651 ---help---
55652 A.out (Assembler.OUTput) is a set of formats for libraries and
55653 executables used in the earliest versions of UNIX. Linux used
55654 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55655 index ce25d75..dc09eeb 100644
55656 --- a/fs/afs/inode.c
55657 +++ b/fs/afs/inode.c
55658 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55659 struct afs_vnode *vnode;
55660 struct super_block *sb;
55661 struct inode *inode;
55662 - static atomic_t afs_autocell_ino;
55663 + static atomic_unchecked_t afs_autocell_ino;
55664
55665 _enter("{%x:%u},%*.*s,",
55666 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55667 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55668 data.fid.unique = 0;
55669 data.fid.vnode = 0;
55670
55671 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55672 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55673 afs_iget5_autocell_test, afs_iget5_set,
55674 &data);
55675 if (!inode) {
55676 diff --git a/fs/aio.c b/fs/aio.c
55677 index 062a5f6..e5618e0 100644
55678 --- a/fs/aio.c
55679 +++ b/fs/aio.c
55680 @@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55681 size += sizeof(struct io_event) * nr_events;
55682
55683 nr_pages = PFN_UP(size);
55684 - if (nr_pages < 0)
55685 + if (nr_pages <= 0)
55686 return -EINVAL;
55687
55688 file = aio_private_file(ctx, nr_pages);
55689 diff --git a/fs/attr.c b/fs/attr.c
55690 index 5d4e59d..fd02418 100644
55691 --- a/fs/attr.c
55692 +++ b/fs/attr.c
55693 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55694 unsigned long limit;
55695
55696 limit = rlimit(RLIMIT_FSIZE);
55697 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55698 if (limit != RLIM_INFINITY && offset > limit)
55699 goto out_sig;
55700 if (offset > inode->i_sb->s_maxbytes)
55701 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55702 index 689e40d..515cac5 100644
55703 --- a/fs/autofs4/waitq.c
55704 +++ b/fs/autofs4/waitq.c
55705 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55706 {
55707 unsigned long sigpipe, flags;
55708 mm_segment_t fs;
55709 - const char *data = (const char *)addr;
55710 + const char __user *data = (const char __force_user *)addr;
55711 ssize_t wr = 0;
55712
55713 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55714 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55715 return 1;
55716 }
55717
55718 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55719 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55720 +#endif
55721 +
55722 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55723 enum autofs_notify notify)
55724 {
55725 @@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55726
55727 /* If this is a direct mount request create a dummy name */
55728 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55729 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55730 + /* this name does get written to userland via autofs4_write() */
55731 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55732 +#else
55733 qstr.len = sprintf(name, "%p", dentry);
55734 +#endif
55735 else {
55736 qstr.len = autofs4_getpath(sbi, dentry, &name);
55737 if (!qstr.len) {
55738 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55739 index 2722387..56059b5 100644
55740 --- a/fs/befs/endian.h
55741 +++ b/fs/befs/endian.h
55742 @@ -11,7 +11,7 @@
55743
55744 #include <asm/byteorder.h>
55745
55746 -static inline u64
55747 +static inline u64 __intentional_overflow(-1)
55748 fs64_to_cpu(const struct super_block *sb, fs64 n)
55749 {
55750 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55751 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55752 return (__force fs64)cpu_to_be64(n);
55753 }
55754
55755 -static inline u32
55756 +static inline u32 __intentional_overflow(-1)
55757 fs32_to_cpu(const struct super_block *sb, fs32 n)
55758 {
55759 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55760 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55761 return (__force fs32)cpu_to_be32(n);
55762 }
55763
55764 -static inline u16
55765 +static inline u16 __intentional_overflow(-1)
55766 fs16_to_cpu(const struct super_block *sb, fs16 n)
55767 {
55768 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55769 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55770 index ca0ba15..0fa3257 100644
55771 --- a/fs/binfmt_aout.c
55772 +++ b/fs/binfmt_aout.c
55773 @@ -16,6 +16,7 @@
55774 #include <linux/string.h>
55775 #include <linux/fs.h>
55776 #include <linux/file.h>
55777 +#include <linux/security.h>
55778 #include <linux/stat.h>
55779 #include <linux/fcntl.h>
55780 #include <linux/ptrace.h>
55781 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55782 #endif
55783 # define START_STACK(u) ((void __user *)u.start_stack)
55784
55785 + memset(&dump, 0, sizeof(dump));
55786 +
55787 fs = get_fs();
55788 set_fs(KERNEL_DS);
55789 has_dumped = 1;
55790 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55791
55792 /* If the size of the dump file exceeds the rlimit, then see what would happen
55793 if we wrote the stack, but not the data area. */
55794 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55795 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55796 dump.u_dsize = 0;
55797
55798 /* Make sure we have enough room to write the stack and data areas. */
55799 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55800 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55801 dump.u_ssize = 0;
55802
55803 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55804 rlim = rlimit(RLIMIT_DATA);
55805 if (rlim >= RLIM_INFINITY)
55806 rlim = ~0;
55807 +
55808 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55809 if (ex.a_data + ex.a_bss > rlim)
55810 return -ENOMEM;
55811
55812 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55813
55814 install_exec_creds(bprm);
55815
55816 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55817 + current->mm->pax_flags = 0UL;
55818 +#endif
55819 +
55820 +#ifdef CONFIG_PAX_PAGEEXEC
55821 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55822 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55823 +
55824 +#ifdef CONFIG_PAX_EMUTRAMP
55825 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55826 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55827 +#endif
55828 +
55829 +#ifdef CONFIG_PAX_MPROTECT
55830 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55831 + current->mm->pax_flags |= MF_PAX_MPROTECT;
55832 +#endif
55833 +
55834 + }
55835 +#endif
55836 +
55837 if (N_MAGIC(ex) == OMAGIC) {
55838 unsigned long text_addr, map_size;
55839 loff_t pos;
55840 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
55841 }
55842
55843 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
55844 - PROT_READ | PROT_WRITE | PROT_EXEC,
55845 + PROT_READ | PROT_WRITE,
55846 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55847 fd_offset + ex.a_text);
55848 if (error != N_DATADDR(ex)) {
55849 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55850 index 571a423..eed5754 100644
55851 --- a/fs/binfmt_elf.c
55852 +++ b/fs/binfmt_elf.c
55853 @@ -34,6 +34,7 @@
55854 #include <linux/utsname.h>
55855 #include <linux/coredump.h>
55856 #include <linux/sched.h>
55857 +#include <linux/xattr.h>
55858 #include <asm/uaccess.h>
55859 #include <asm/param.h>
55860 #include <asm/page.h>
55861 @@ -48,7 +49,7 @@
55862 static int load_elf_binary(struct linux_binprm *bprm);
55863 static int load_elf_library(struct file *);
55864 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
55865 - int, int, unsigned long);
55866 + int, int, unsigned long) __intentional_overflow(-1);
55867
55868 /*
55869 * If we don't support core dumping, then supply a NULL so we
55870 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55871 #define elf_core_dump NULL
55872 #endif
55873
55874 +#ifdef CONFIG_PAX_MPROTECT
55875 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55876 +#endif
55877 +
55878 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55879 +static void elf_handle_mmap(struct file *file);
55880 +#endif
55881 +
55882 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55883 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55884 #else
55885 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55886 .load_binary = load_elf_binary,
55887 .load_shlib = load_elf_library,
55888 .core_dump = elf_core_dump,
55889 +
55890 +#ifdef CONFIG_PAX_MPROTECT
55891 + .handle_mprotect= elf_handle_mprotect,
55892 +#endif
55893 +
55894 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55895 + .handle_mmap = elf_handle_mmap,
55896 +#endif
55897 +
55898 .min_coredump = ELF_EXEC_PAGESIZE,
55899 };
55900
55901 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55902
55903 static int set_brk(unsigned long start, unsigned long end)
55904 {
55905 + unsigned long e = end;
55906 +
55907 start = ELF_PAGEALIGN(start);
55908 end = ELF_PAGEALIGN(end);
55909 if (end > start) {
55910 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55911 if (BAD_ADDR(addr))
55912 return addr;
55913 }
55914 - current->mm->start_brk = current->mm->brk = end;
55915 + current->mm->start_brk = current->mm->brk = e;
55916 return 0;
55917 }
55918
55919 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55920 elf_addr_t __user *u_rand_bytes;
55921 const char *k_platform = ELF_PLATFORM;
55922 const char *k_base_platform = ELF_BASE_PLATFORM;
55923 - unsigned char k_rand_bytes[16];
55924 + u32 k_rand_bytes[4];
55925 int items;
55926 elf_addr_t *elf_info;
55927 int ei_index = 0;
55928 const struct cred *cred = current_cred();
55929 struct vm_area_struct *vma;
55930 + unsigned long saved_auxv[AT_VECTOR_SIZE];
55931
55932 /*
55933 * In some cases (e.g. Hyper-Threading), we want to avoid L1
55934 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55935 * Generate 16 random bytes for userspace PRNG seeding.
55936 */
55937 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
55938 - u_rand_bytes = (elf_addr_t __user *)
55939 - STACK_ALLOC(p, sizeof(k_rand_bytes));
55940 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
55941 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
55942 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
55943 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
55944 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
55945 + u_rand_bytes = (elf_addr_t __user *) p;
55946 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
55947 return -EFAULT;
55948
55949 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55950 return -EFAULT;
55951 current->mm->env_end = p;
55952
55953 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
55954 +
55955 /* Put the elf_info on the stack in the right place. */
55956 sp = (elf_addr_t __user *)envp + 1;
55957 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
55958 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
55959 return -EFAULT;
55960 return 0;
55961 }
55962 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
55963 an ELF header */
55964
55965 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55966 - struct file *interpreter, unsigned long *interp_map_addr,
55967 - unsigned long no_base)
55968 + struct file *interpreter, unsigned long no_base)
55969 {
55970 struct elf_phdr *elf_phdata;
55971 struct elf_phdr *eppnt;
55972 - unsigned long load_addr = 0;
55973 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
55974 int load_addr_set = 0;
55975 unsigned long last_bss = 0, elf_bss = 0;
55976 - unsigned long error = ~0UL;
55977 + unsigned long error = -EINVAL;
55978 unsigned long total_size;
55979 int retval, i, size;
55980
55981 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55982 goto out_close;
55983 }
55984
55985 +#ifdef CONFIG_PAX_SEGMEXEC
55986 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
55987 + pax_task_size = SEGMEXEC_TASK_SIZE;
55988 +#endif
55989 +
55990 eppnt = elf_phdata;
55991 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
55992 if (eppnt->p_type == PT_LOAD) {
55993 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55994 map_addr = elf_map(interpreter, load_addr + vaddr,
55995 eppnt, elf_prot, elf_type, total_size);
55996 total_size = 0;
55997 - if (!*interp_map_addr)
55998 - *interp_map_addr = map_addr;
55999 error = map_addr;
56000 if (BAD_ADDR(map_addr))
56001 goto out_close;
56002 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56003 k = load_addr + eppnt->p_vaddr;
56004 if (BAD_ADDR(k) ||
56005 eppnt->p_filesz > eppnt->p_memsz ||
56006 - eppnt->p_memsz > TASK_SIZE ||
56007 - TASK_SIZE - eppnt->p_memsz < k) {
56008 + eppnt->p_memsz > pax_task_size ||
56009 + pax_task_size - eppnt->p_memsz < k) {
56010 error = -ENOMEM;
56011 goto out_close;
56012 }
56013 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56014 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56015
56016 /* Map the last of the bss segment */
56017 - error = vm_brk(elf_bss, last_bss - elf_bss);
56018 - if (BAD_ADDR(error))
56019 - goto out_close;
56020 + if (last_bss > elf_bss) {
56021 + error = vm_brk(elf_bss, last_bss - elf_bss);
56022 + if (BAD_ADDR(error))
56023 + goto out_close;
56024 + }
56025 }
56026
56027 error = load_addr;
56028 @@ -538,6 +569,336 @@ out:
56029 return error;
56030 }
56031
56032 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56033 +#ifdef CONFIG_PAX_SOFTMODE
56034 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56035 +{
56036 + unsigned long pax_flags = 0UL;
56037 +
56038 +#ifdef CONFIG_PAX_PAGEEXEC
56039 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56040 + pax_flags |= MF_PAX_PAGEEXEC;
56041 +#endif
56042 +
56043 +#ifdef CONFIG_PAX_SEGMEXEC
56044 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56045 + pax_flags |= MF_PAX_SEGMEXEC;
56046 +#endif
56047 +
56048 +#ifdef CONFIG_PAX_EMUTRAMP
56049 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56050 + pax_flags |= MF_PAX_EMUTRAMP;
56051 +#endif
56052 +
56053 +#ifdef CONFIG_PAX_MPROTECT
56054 + if (elf_phdata->p_flags & PF_MPROTECT)
56055 + pax_flags |= MF_PAX_MPROTECT;
56056 +#endif
56057 +
56058 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56059 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56060 + pax_flags |= MF_PAX_RANDMMAP;
56061 +#endif
56062 +
56063 + return pax_flags;
56064 +}
56065 +#endif
56066 +
56067 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56068 +{
56069 + unsigned long pax_flags = 0UL;
56070 +
56071 +#ifdef CONFIG_PAX_PAGEEXEC
56072 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56073 + pax_flags |= MF_PAX_PAGEEXEC;
56074 +#endif
56075 +
56076 +#ifdef CONFIG_PAX_SEGMEXEC
56077 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56078 + pax_flags |= MF_PAX_SEGMEXEC;
56079 +#endif
56080 +
56081 +#ifdef CONFIG_PAX_EMUTRAMP
56082 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56083 + pax_flags |= MF_PAX_EMUTRAMP;
56084 +#endif
56085 +
56086 +#ifdef CONFIG_PAX_MPROTECT
56087 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56088 + pax_flags |= MF_PAX_MPROTECT;
56089 +#endif
56090 +
56091 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56092 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56093 + pax_flags |= MF_PAX_RANDMMAP;
56094 +#endif
56095 +
56096 + return pax_flags;
56097 +}
56098 +#endif
56099 +
56100 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56101 +#ifdef CONFIG_PAX_SOFTMODE
56102 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56103 +{
56104 + unsigned long pax_flags = 0UL;
56105 +
56106 +#ifdef CONFIG_PAX_PAGEEXEC
56107 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56108 + pax_flags |= MF_PAX_PAGEEXEC;
56109 +#endif
56110 +
56111 +#ifdef CONFIG_PAX_SEGMEXEC
56112 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56113 + pax_flags |= MF_PAX_SEGMEXEC;
56114 +#endif
56115 +
56116 +#ifdef CONFIG_PAX_EMUTRAMP
56117 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56118 + pax_flags |= MF_PAX_EMUTRAMP;
56119 +#endif
56120 +
56121 +#ifdef CONFIG_PAX_MPROTECT
56122 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56123 + pax_flags |= MF_PAX_MPROTECT;
56124 +#endif
56125 +
56126 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56127 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56128 + pax_flags |= MF_PAX_RANDMMAP;
56129 +#endif
56130 +
56131 + return pax_flags;
56132 +}
56133 +#endif
56134 +
56135 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56136 +{
56137 + unsigned long pax_flags = 0UL;
56138 +
56139 +#ifdef CONFIG_PAX_PAGEEXEC
56140 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56141 + pax_flags |= MF_PAX_PAGEEXEC;
56142 +#endif
56143 +
56144 +#ifdef CONFIG_PAX_SEGMEXEC
56145 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56146 + pax_flags |= MF_PAX_SEGMEXEC;
56147 +#endif
56148 +
56149 +#ifdef CONFIG_PAX_EMUTRAMP
56150 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56151 + pax_flags |= MF_PAX_EMUTRAMP;
56152 +#endif
56153 +
56154 +#ifdef CONFIG_PAX_MPROTECT
56155 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56156 + pax_flags |= MF_PAX_MPROTECT;
56157 +#endif
56158 +
56159 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56160 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56161 + pax_flags |= MF_PAX_RANDMMAP;
56162 +#endif
56163 +
56164 + return pax_flags;
56165 +}
56166 +#endif
56167 +
56168 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56169 +static unsigned long pax_parse_defaults(void)
56170 +{
56171 + unsigned long pax_flags = 0UL;
56172 +
56173 +#ifdef CONFIG_PAX_SOFTMODE
56174 + if (pax_softmode)
56175 + return pax_flags;
56176 +#endif
56177 +
56178 +#ifdef CONFIG_PAX_PAGEEXEC
56179 + pax_flags |= MF_PAX_PAGEEXEC;
56180 +#endif
56181 +
56182 +#ifdef CONFIG_PAX_SEGMEXEC
56183 + pax_flags |= MF_PAX_SEGMEXEC;
56184 +#endif
56185 +
56186 +#ifdef CONFIG_PAX_MPROTECT
56187 + pax_flags |= MF_PAX_MPROTECT;
56188 +#endif
56189 +
56190 +#ifdef CONFIG_PAX_RANDMMAP
56191 + if (randomize_va_space)
56192 + pax_flags |= MF_PAX_RANDMMAP;
56193 +#endif
56194 +
56195 + return pax_flags;
56196 +}
56197 +
56198 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56199 +{
56200 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56201 +
56202 +#ifdef CONFIG_PAX_EI_PAX
56203 +
56204 +#ifdef CONFIG_PAX_SOFTMODE
56205 + if (pax_softmode)
56206 + return pax_flags;
56207 +#endif
56208 +
56209 + pax_flags = 0UL;
56210 +
56211 +#ifdef CONFIG_PAX_PAGEEXEC
56212 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56213 + pax_flags |= MF_PAX_PAGEEXEC;
56214 +#endif
56215 +
56216 +#ifdef CONFIG_PAX_SEGMEXEC
56217 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56218 + pax_flags |= MF_PAX_SEGMEXEC;
56219 +#endif
56220 +
56221 +#ifdef CONFIG_PAX_EMUTRAMP
56222 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56223 + pax_flags |= MF_PAX_EMUTRAMP;
56224 +#endif
56225 +
56226 +#ifdef CONFIG_PAX_MPROTECT
56227 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56228 + pax_flags |= MF_PAX_MPROTECT;
56229 +#endif
56230 +
56231 +#ifdef CONFIG_PAX_ASLR
56232 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56233 + pax_flags |= MF_PAX_RANDMMAP;
56234 +#endif
56235 +
56236 +#endif
56237 +
56238 + return pax_flags;
56239 +
56240 +}
56241 +
56242 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56243 +{
56244 +
56245 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56246 + unsigned long i;
56247 +
56248 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56249 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56250 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56251 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56252 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56253 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56254 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56255 + return PAX_PARSE_FLAGS_FALLBACK;
56256 +
56257 +#ifdef CONFIG_PAX_SOFTMODE
56258 + if (pax_softmode)
56259 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56260 + else
56261 +#endif
56262 +
56263 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56264 + break;
56265 + }
56266 +#endif
56267 +
56268 + return PAX_PARSE_FLAGS_FALLBACK;
56269 +}
56270 +
56271 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56272 +{
56273 +
56274 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56275 + ssize_t xattr_size, i;
56276 + unsigned char xattr_value[sizeof("pemrs") - 1];
56277 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56278 +
56279 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56280 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56281 + return PAX_PARSE_FLAGS_FALLBACK;
56282 +
56283 + for (i = 0; i < xattr_size; i++)
56284 + switch (xattr_value[i]) {
56285 + default:
56286 + return PAX_PARSE_FLAGS_FALLBACK;
56287 +
56288 +#define parse_flag(option1, option2, flag) \
56289 + case option1: \
56290 + if (pax_flags_hardmode & MF_PAX_##flag) \
56291 + return PAX_PARSE_FLAGS_FALLBACK;\
56292 + pax_flags_hardmode |= MF_PAX_##flag; \
56293 + break; \
56294 + case option2: \
56295 + if (pax_flags_softmode & MF_PAX_##flag) \
56296 + return PAX_PARSE_FLAGS_FALLBACK;\
56297 + pax_flags_softmode |= MF_PAX_##flag; \
56298 + break;
56299 +
56300 + parse_flag('p', 'P', PAGEEXEC);
56301 + parse_flag('e', 'E', EMUTRAMP);
56302 + parse_flag('m', 'M', MPROTECT);
56303 + parse_flag('r', 'R', RANDMMAP);
56304 + parse_flag('s', 'S', SEGMEXEC);
56305 +
56306 +#undef parse_flag
56307 + }
56308 +
56309 + if (pax_flags_hardmode & pax_flags_softmode)
56310 + return PAX_PARSE_FLAGS_FALLBACK;
56311 +
56312 +#ifdef CONFIG_PAX_SOFTMODE
56313 + if (pax_softmode)
56314 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56315 + else
56316 +#endif
56317 +
56318 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56319 +#else
56320 + return PAX_PARSE_FLAGS_FALLBACK;
56321 +#endif
56322 +
56323 +}
56324 +
56325 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56326 +{
56327 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56328 +
56329 + pax_flags = pax_parse_defaults();
56330 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56331 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56332 + xattr_pax_flags = pax_parse_xattr_pax(file);
56333 +
56334 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56335 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56336 + pt_pax_flags != xattr_pax_flags)
56337 + return -EINVAL;
56338 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56339 + pax_flags = xattr_pax_flags;
56340 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56341 + pax_flags = pt_pax_flags;
56342 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56343 + pax_flags = ei_pax_flags;
56344 +
56345 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56346 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56347 + if ((__supported_pte_mask & _PAGE_NX))
56348 + pax_flags &= ~MF_PAX_SEGMEXEC;
56349 + else
56350 + pax_flags &= ~MF_PAX_PAGEEXEC;
56351 + }
56352 +#endif
56353 +
56354 + if (0 > pax_check_flags(&pax_flags))
56355 + return -EINVAL;
56356 +
56357 + current->mm->pax_flags = pax_flags;
56358 + return 0;
56359 +}
56360 +#endif
56361 +
56362 /*
56363 * These are the functions used to load ELF style executables and shared
56364 * libraries. There is no binary dependent code anywhere else.
56365 @@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56366 {
56367 unsigned int random_variable = 0;
56368
56369 +#ifdef CONFIG_PAX_RANDUSTACK
56370 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56371 + return stack_top - current->mm->delta_stack;
56372 +#endif
56373 +
56374 if ((current->flags & PF_RANDOMIZE) &&
56375 !(current->personality & ADDR_NO_RANDOMIZE)) {
56376 random_variable = get_random_int() & STACK_RND_MASK;
56377 @@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56378 unsigned long load_addr = 0, load_bias = 0;
56379 int load_addr_set = 0;
56380 char * elf_interpreter = NULL;
56381 - unsigned long error;
56382 + unsigned long error = 0;
56383 struct elf_phdr *elf_ppnt, *elf_phdata;
56384 unsigned long elf_bss, elf_brk;
56385 int retval, i;
56386 @@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56387 unsigned long start_code, end_code, start_data, end_data;
56388 unsigned long reloc_func_desc __maybe_unused = 0;
56389 int executable_stack = EXSTACK_DEFAULT;
56390 - unsigned long def_flags = 0;
56391 struct pt_regs *regs = current_pt_regs();
56392 struct {
56393 struct elfhdr elf_ex;
56394 struct elfhdr interp_elf_ex;
56395 } *loc;
56396 + unsigned long pax_task_size;
56397
56398 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56399 if (!loc) {
56400 @@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56401 goto out_free_dentry;
56402
56403 /* OK, This is the point of no return */
56404 - current->mm->def_flags = def_flags;
56405 + current->mm->def_flags = 0;
56406
56407 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56408 may depend on the personality. */
56409 SET_PERSONALITY(loc->elf_ex);
56410 +
56411 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56412 + current->mm->pax_flags = 0UL;
56413 +#endif
56414 +
56415 +#ifdef CONFIG_PAX_DLRESOLVE
56416 + current->mm->call_dl_resolve = 0UL;
56417 +#endif
56418 +
56419 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56420 + current->mm->call_syscall = 0UL;
56421 +#endif
56422 +
56423 +#ifdef CONFIG_PAX_ASLR
56424 + current->mm->delta_mmap = 0UL;
56425 + current->mm->delta_stack = 0UL;
56426 +#endif
56427 +
56428 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56429 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56430 + send_sig(SIGKILL, current, 0);
56431 + goto out_free_dentry;
56432 + }
56433 +#endif
56434 +
56435 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56436 + pax_set_initial_flags(bprm);
56437 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56438 + if (pax_set_initial_flags_func)
56439 + (pax_set_initial_flags_func)(bprm);
56440 +#endif
56441 +
56442 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56443 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56444 + current->mm->context.user_cs_limit = PAGE_SIZE;
56445 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56446 + }
56447 +#endif
56448 +
56449 +#ifdef CONFIG_PAX_SEGMEXEC
56450 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56451 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56452 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56453 + pax_task_size = SEGMEXEC_TASK_SIZE;
56454 + current->mm->def_flags |= VM_NOHUGEPAGE;
56455 + } else
56456 +#endif
56457 +
56458 + pax_task_size = TASK_SIZE;
56459 +
56460 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56461 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56462 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56463 + put_cpu();
56464 + }
56465 +#endif
56466 +
56467 +#ifdef CONFIG_PAX_ASLR
56468 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56469 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56470 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56471 + }
56472 +#endif
56473 +
56474 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56475 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56476 + executable_stack = EXSTACK_DISABLE_X;
56477 + current->personality &= ~READ_IMPLIES_EXEC;
56478 + } else
56479 +#endif
56480 +
56481 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56482 current->personality |= READ_IMPLIES_EXEC;
56483
56484 @@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56485 #else
56486 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56487 #endif
56488 +
56489 +#ifdef CONFIG_PAX_RANDMMAP
56490 + /* PaX: randomize base address at the default exe base if requested */
56491 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56492 +#ifdef CONFIG_SPARC64
56493 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56494 +#else
56495 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56496 +#endif
56497 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56498 + elf_flags |= MAP_FIXED;
56499 + }
56500 +#endif
56501 +
56502 }
56503
56504 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56505 @@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56506 * allowed task size. Note that p_filesz must always be
56507 * <= p_memsz so it is only necessary to check p_memsz.
56508 */
56509 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56510 - elf_ppnt->p_memsz > TASK_SIZE ||
56511 - TASK_SIZE - elf_ppnt->p_memsz < k) {
56512 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56513 + elf_ppnt->p_memsz > pax_task_size ||
56514 + pax_task_size - elf_ppnt->p_memsz < k) {
56515 /* set_brk can never work. Avoid overflows. */
56516 send_sig(SIGKILL, current, 0);
56517 retval = -EINVAL;
56518 @@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56519 goto out_free_dentry;
56520 }
56521 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56522 - send_sig(SIGSEGV, current, 0);
56523 - retval = -EFAULT; /* Nobody gets to see this, but.. */
56524 - goto out_free_dentry;
56525 + /*
56526 + * This bss-zeroing can fail if the ELF
56527 + * file specifies odd protections. So
56528 + * we don't check the return value
56529 + */
56530 }
56531
56532 +#ifdef CONFIG_PAX_RANDMMAP
56533 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56534 + unsigned long start, size, flags;
56535 + vm_flags_t vm_flags;
56536 +
56537 + start = ELF_PAGEALIGN(elf_brk);
56538 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56539 + flags = MAP_FIXED | MAP_PRIVATE;
56540 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56541 +
56542 + down_write(&current->mm->mmap_sem);
56543 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56544 + retval = -ENOMEM;
56545 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56546 +// if (current->personality & ADDR_NO_RANDOMIZE)
56547 +// vm_flags |= VM_READ | VM_MAYREAD;
56548 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56549 + retval = IS_ERR_VALUE(start) ? start : 0;
56550 + }
56551 + up_write(&current->mm->mmap_sem);
56552 + if (retval == 0)
56553 + retval = set_brk(start + size, start + size + PAGE_SIZE);
56554 + if (retval < 0) {
56555 + send_sig(SIGKILL, current, 0);
56556 + goto out_free_dentry;
56557 + }
56558 + }
56559 +#endif
56560 +
56561 if (elf_interpreter) {
56562 - unsigned long interp_map_addr = 0;
56563 -
56564 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56565 interpreter,
56566 - &interp_map_addr,
56567 load_bias);
56568 if (!IS_ERR((void *)elf_entry)) {
56569 /*
56570 @@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56571 * Decide what to dump of a segment, part, all or none.
56572 */
56573 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56574 - unsigned long mm_flags)
56575 + unsigned long mm_flags, long signr)
56576 {
56577 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56578
56579 @@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56580 if (vma->vm_file == NULL)
56581 return 0;
56582
56583 - if (FILTER(MAPPED_PRIVATE))
56584 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56585 goto whole;
56586
56587 /*
56588 @@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56589 {
56590 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56591 int i = 0;
56592 - do
56593 + do {
56594 i += 2;
56595 - while (auxv[i - 2] != AT_NULL);
56596 + } while (auxv[i - 2] != AT_NULL);
56597 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56598 }
56599
56600 @@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56601 {
56602 mm_segment_t old_fs = get_fs();
56603 set_fs(KERNEL_DS);
56604 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56605 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56606 set_fs(old_fs);
56607 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56608 }
56609 @@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56610 }
56611
56612 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56613 - unsigned long mm_flags)
56614 + struct coredump_params *cprm)
56615 {
56616 struct vm_area_struct *vma;
56617 size_t size = 0;
56618
56619 for (vma = first_vma(current, gate_vma); vma != NULL;
56620 vma = next_vma(vma, gate_vma))
56621 - size += vma_dump_size(vma, mm_flags);
56622 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56623 return size;
56624 }
56625
56626 @@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56627
56628 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56629
56630 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56631 + offset += elf_core_vma_data_size(gate_vma, cprm);
56632 offset += elf_core_extra_data_size();
56633 e_shoff = offset;
56634
56635 @@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56636 phdr.p_offset = offset;
56637 phdr.p_vaddr = vma->vm_start;
56638 phdr.p_paddr = 0;
56639 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56640 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56641 phdr.p_memsz = vma->vm_end - vma->vm_start;
56642 offset += phdr.p_filesz;
56643 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56644 @@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56645 unsigned long addr;
56646 unsigned long end;
56647
56648 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56649 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56650
56651 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56652 struct page *page;
56653 @@ -2202,6 +2681,167 @@ out:
56654
56655 #endif /* CONFIG_ELF_CORE */
56656
56657 +#ifdef CONFIG_PAX_MPROTECT
56658 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
56659 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56660 + * we'll remove VM_MAYWRITE for good on RELRO segments.
56661 + *
56662 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56663 + * basis because we want to allow the common case and not the special ones.
56664 + */
56665 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56666 +{
56667 + struct elfhdr elf_h;
56668 + struct elf_phdr elf_p;
56669 + unsigned long i;
56670 + unsigned long oldflags;
56671 + bool is_textrel_rw, is_textrel_rx, is_relro;
56672 +
56673 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56674 + return;
56675 +
56676 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56677 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56678 +
56679 +#ifdef CONFIG_PAX_ELFRELOCS
56680 + /* possible TEXTREL */
56681 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56682 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56683 +#else
56684 + is_textrel_rw = false;
56685 + is_textrel_rx = false;
56686 +#endif
56687 +
56688 + /* possible RELRO */
56689 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56690 +
56691 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56692 + return;
56693 +
56694 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56695 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56696 +
56697 +#ifdef CONFIG_PAX_ETEXECRELOCS
56698 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56699 +#else
56700 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56701 +#endif
56702 +
56703 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56704 + !elf_check_arch(&elf_h) ||
56705 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56706 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56707 + return;
56708 +
56709 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56710 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56711 + return;
56712 + switch (elf_p.p_type) {
56713 + case PT_DYNAMIC:
56714 + if (!is_textrel_rw && !is_textrel_rx)
56715 + continue;
56716 + i = 0UL;
56717 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56718 + elf_dyn dyn;
56719 +
56720 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56721 + break;
56722 + if (dyn.d_tag == DT_NULL)
56723 + break;
56724 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56725 + gr_log_textrel(vma);
56726 + if (is_textrel_rw)
56727 + vma->vm_flags |= VM_MAYWRITE;
56728 + else
56729 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56730 + vma->vm_flags &= ~VM_MAYWRITE;
56731 + break;
56732 + }
56733 + i++;
56734 + }
56735 + is_textrel_rw = false;
56736 + is_textrel_rx = false;
56737 + continue;
56738 +
56739 + case PT_GNU_RELRO:
56740 + if (!is_relro)
56741 + continue;
56742 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56743 + vma->vm_flags &= ~VM_MAYWRITE;
56744 + is_relro = false;
56745 + continue;
56746 +
56747 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56748 + case PT_PAX_FLAGS: {
56749 + const char *msg_mprotect = "", *msg_emutramp = "";
56750 + char *buffer_lib, *buffer_exe;
56751 +
56752 + if (elf_p.p_flags & PF_NOMPROTECT)
56753 + msg_mprotect = "MPROTECT disabled";
56754 +
56755 +#ifdef CONFIG_PAX_EMUTRAMP
56756 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56757 + msg_emutramp = "EMUTRAMP enabled";
56758 +#endif
56759 +
56760 + if (!msg_mprotect[0] && !msg_emutramp[0])
56761 + continue;
56762 +
56763 + if (!printk_ratelimit())
56764 + continue;
56765 +
56766 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56767 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56768 + if (buffer_lib && buffer_exe) {
56769 + char *path_lib, *path_exe;
56770 +
56771 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56772 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56773 +
56774 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56775 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56776 +
56777 + }
56778 + free_page((unsigned long)buffer_exe);
56779 + free_page((unsigned long)buffer_lib);
56780 + continue;
56781 + }
56782 +#endif
56783 +
56784 + }
56785 + }
56786 +}
56787 +#endif
56788 +
56789 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56790 +
56791 +extern int grsec_enable_log_rwxmaps;
56792 +
56793 +static void elf_handle_mmap(struct file *file)
56794 +{
56795 + struct elfhdr elf_h;
56796 + struct elf_phdr elf_p;
56797 + unsigned long i;
56798 +
56799 + if (!grsec_enable_log_rwxmaps)
56800 + return;
56801 +
56802 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56803 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56804 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56805 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56806 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56807 + return;
56808 +
56809 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56810 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56811 + return;
56812 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56813 + gr_log_ptgnustack(file);
56814 + }
56815 +}
56816 +#endif
56817 +
56818 static int __init init_elf_binfmt(void)
56819 {
56820 register_binfmt(&elf_format);
56821 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56822 index d50bbe5..af3b649 100644
56823 --- a/fs/binfmt_flat.c
56824 +++ b/fs/binfmt_flat.c
56825 @@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56826 realdatastart = (unsigned long) -ENOMEM;
56827 printk("Unable to allocate RAM for process data, errno %d\n",
56828 (int)-realdatastart);
56829 + down_write(&current->mm->mmap_sem);
56830 vm_munmap(textpos, text_len);
56831 + up_write(&current->mm->mmap_sem);
56832 ret = realdatastart;
56833 goto err;
56834 }
56835 @@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56836 }
56837 if (IS_ERR_VALUE(result)) {
56838 printk("Unable to read data+bss, errno %d\n", (int)-result);
56839 + down_write(&current->mm->mmap_sem);
56840 vm_munmap(textpos, text_len);
56841 vm_munmap(realdatastart, len);
56842 + up_write(&current->mm->mmap_sem);
56843 ret = result;
56844 goto err;
56845 }
56846 @@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56847 }
56848 if (IS_ERR_VALUE(result)) {
56849 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
56850 + down_write(&current->mm->mmap_sem);
56851 vm_munmap(textpos, text_len + data_len + extra +
56852 MAX_SHARED_LIBS * sizeof(unsigned long));
56853 + up_write(&current->mm->mmap_sem);
56854 ret = result;
56855 goto err;
56856 }
56857 diff --git a/fs/bio.c b/fs/bio.c
56858 index 33d79a4..c3c9893 100644
56859 --- a/fs/bio.c
56860 +++ b/fs/bio.c
56861 @@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56862 /*
56863 * Overflow, abort
56864 */
56865 - if (end < start)
56866 + if (end < start || end - start > INT_MAX - nr_pages)
56867 return ERR_PTR(-EINVAL);
56868
56869 nr_pages += end - start;
56870 @@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56871 /*
56872 * Overflow, abort
56873 */
56874 - if (end < start)
56875 + if (end < start || end - start > INT_MAX - nr_pages)
56876 return ERR_PTR(-EINVAL);
56877
56878 nr_pages += end - start;
56879 @@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56880 const int read = bio_data_dir(bio) == READ;
56881 struct bio_map_data *bmd = bio->bi_private;
56882 int i;
56883 - char *p = bmd->sgvecs[0].iov_base;
56884 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56885
56886 bio_for_each_segment_all(bvec, bio, i) {
56887 char *addr = page_address(bvec->bv_page);
56888 diff --git a/fs/block_dev.c b/fs/block_dev.c
56889 index 1e86823..8e34695 100644
56890 --- a/fs/block_dev.c
56891 +++ b/fs/block_dev.c
56892 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56893 else if (bdev->bd_contains == bdev)
56894 return true; /* is a whole device which isn't held */
56895
56896 - else if (whole->bd_holder == bd_may_claim)
56897 + else if (whole->bd_holder == (void *)bd_may_claim)
56898 return true; /* is a partition of a device that is being partitioned */
56899 else if (whole->bd_holder != NULL)
56900 return false; /* is a partition of a held device */
56901 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56902 index 316136b..e7a3a50 100644
56903 --- a/fs/btrfs/ctree.c
56904 +++ b/fs/btrfs/ctree.c
56905 @@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56906 free_extent_buffer(buf);
56907 add_root_to_dirty_list(root);
56908 } else {
56909 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56910 - parent_start = parent->start;
56911 - else
56912 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56913 + if (parent)
56914 + parent_start = parent->start;
56915 + else
56916 + parent_start = 0;
56917 + } else
56918 parent_start = 0;
56919
56920 WARN_ON(trans->transid != btrfs_header_generation(parent));
56921 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56922 index 8d292fb..bc205c2 100644
56923 --- a/fs/btrfs/delayed-inode.c
56924 +++ b/fs/btrfs/delayed-inode.c
56925 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56926
56927 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56928 {
56929 - int seq = atomic_inc_return(&delayed_root->items_seq);
56930 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
56931 if ((atomic_dec_return(&delayed_root->items) <
56932 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
56933 waitqueue_active(&delayed_root->wait))
56934 @@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
56935 static int refs_newer(struct btrfs_delayed_root *delayed_root,
56936 int seq, int count)
56937 {
56938 - int val = atomic_read(&delayed_root->items_seq);
56939 + int val = atomic_read_unchecked(&delayed_root->items_seq);
56940
56941 if (val < seq || val >= seq + count)
56942 return 1;
56943 @@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
56944 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
56945 return;
56946
56947 - seq = atomic_read(&delayed_root->items_seq);
56948 + seq = atomic_read_unchecked(&delayed_root->items_seq);
56949
56950 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
56951 int ret;
56952 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
56953 index a4b38f9..f86a509 100644
56954 --- a/fs/btrfs/delayed-inode.h
56955 +++ b/fs/btrfs/delayed-inode.h
56956 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
56957 */
56958 struct list_head prepare_list;
56959 atomic_t items; /* for delayed items */
56960 - atomic_t items_seq; /* for delayed items */
56961 + atomic_unchecked_t items_seq; /* for delayed items */
56962 int nodes; /* for delayed nodes */
56963 wait_queue_head_t wait;
56964 };
56965 @@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
56966 struct btrfs_delayed_root *delayed_root)
56967 {
56968 atomic_set(&delayed_root->items, 0);
56969 - atomic_set(&delayed_root->items_seq, 0);
56970 + atomic_set_unchecked(&delayed_root->items_seq, 0);
56971 delayed_root->nodes = 0;
56972 spin_lock_init(&delayed_root->lock);
56973 init_waitqueue_head(&delayed_root->wait);
56974 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
56975 index 9f831bb..14afde5 100644
56976 --- a/fs/btrfs/ioctl.c
56977 +++ b/fs/btrfs/ioctl.c
56978 @@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56979 for (i = 0; i < num_types; i++) {
56980 struct btrfs_space_info *tmp;
56981
56982 + /* Don't copy in more than we allocated */
56983 if (!slot_count)
56984 break;
56985
56986 + slot_count--;
56987 +
56988 info = NULL;
56989 rcu_read_lock();
56990 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
56991 @@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56992 memcpy(dest, &space, sizeof(space));
56993 dest++;
56994 space_args.total_spaces++;
56995 - slot_count--;
56996 }
56997 - if (!slot_count)
56998 - break;
56999 }
57000 up_read(&info->groups_sem);
57001 }
57002 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57003 index d71a11d..384e2c4 100644
57004 --- a/fs/btrfs/super.c
57005 +++ b/fs/btrfs/super.c
57006 @@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57007 function, line, errstr);
57008 return;
57009 }
57010 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57011 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57012 /* Wake up anybody who may be waiting on this transaction */
57013 wake_up(&root->fs_info->transaction_wait);
57014 wake_up(&root->fs_info->transaction_blocked_wait);
57015 diff --git a/fs/buffer.c b/fs/buffer.c
57016 index aeeea65..7651d590 100644
57017 --- a/fs/buffer.c
57018 +++ b/fs/buffer.c
57019 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57020 bh_cachep = kmem_cache_create("buffer_head",
57021 sizeof(struct buffer_head), 0,
57022 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57023 - SLAB_MEM_SPREAD),
57024 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57025 NULL);
57026
57027 /*
57028 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57029 index 622f469..e8d2d55 100644
57030 --- a/fs/cachefiles/bind.c
57031 +++ b/fs/cachefiles/bind.c
57032 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57033 args);
57034
57035 /* start by checking things over */
57036 - ASSERT(cache->fstop_percent >= 0 &&
57037 - cache->fstop_percent < cache->fcull_percent &&
57038 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57039 cache->fcull_percent < cache->frun_percent &&
57040 cache->frun_percent < 100);
57041
57042 - ASSERT(cache->bstop_percent >= 0 &&
57043 - cache->bstop_percent < cache->bcull_percent &&
57044 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57045 cache->bcull_percent < cache->brun_percent &&
57046 cache->brun_percent < 100);
57047
57048 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57049 index 0a1467b..6a53245 100644
57050 --- a/fs/cachefiles/daemon.c
57051 +++ b/fs/cachefiles/daemon.c
57052 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57053 if (n > buflen)
57054 return -EMSGSIZE;
57055
57056 - if (copy_to_user(_buffer, buffer, n) != 0)
57057 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57058 return -EFAULT;
57059
57060 return n;
57061 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57062 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57063 return -EIO;
57064
57065 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57066 + if (datalen > PAGE_SIZE - 1)
57067 return -EOPNOTSUPP;
57068
57069 /* drag the command string into the kernel so we can parse it */
57070 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57071 if (args[0] != '%' || args[1] != '\0')
57072 return -EINVAL;
57073
57074 - if (fstop < 0 || fstop >= cache->fcull_percent)
57075 + if (fstop >= cache->fcull_percent)
57076 return cachefiles_daemon_range_error(cache, args);
57077
57078 cache->fstop_percent = fstop;
57079 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57080 if (args[0] != '%' || args[1] != '\0')
57081 return -EINVAL;
57082
57083 - if (bstop < 0 || bstop >= cache->bcull_percent)
57084 + if (bstop >= cache->bcull_percent)
57085 return cachefiles_daemon_range_error(cache, args);
57086
57087 cache->bstop_percent = bstop;
57088 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57089 index 5349473..d6c0b93 100644
57090 --- a/fs/cachefiles/internal.h
57091 +++ b/fs/cachefiles/internal.h
57092 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57093 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57094 struct rb_root active_nodes; /* active nodes (can't be culled) */
57095 rwlock_t active_lock; /* lock for active_nodes */
57096 - atomic_t gravecounter; /* graveyard uniquifier */
57097 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57098 unsigned frun_percent; /* when to stop culling (% files) */
57099 unsigned fcull_percent; /* when to start culling (% files) */
57100 unsigned fstop_percent; /* when to stop allocating (% files) */
57101 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57102 * proc.c
57103 */
57104 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57105 -extern atomic_t cachefiles_lookup_histogram[HZ];
57106 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57107 -extern atomic_t cachefiles_create_histogram[HZ];
57108 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57109 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57110 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57111
57112 extern int __init cachefiles_proc_init(void);
57113 extern void cachefiles_proc_cleanup(void);
57114 static inline
57115 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57116 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57117 {
57118 unsigned long jif = jiffies - start_jif;
57119 if (jif >= HZ)
57120 jif = HZ - 1;
57121 - atomic_inc(&histogram[jif]);
57122 + atomic_inc_unchecked(&histogram[jif]);
57123 }
57124
57125 #else
57126 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57127 index ca65f39..48921e3 100644
57128 --- a/fs/cachefiles/namei.c
57129 +++ b/fs/cachefiles/namei.c
57130 @@ -317,7 +317,7 @@ try_again:
57131 /* first step is to make up a grave dentry in the graveyard */
57132 sprintf(nbuffer, "%08x%08x",
57133 (uint32_t) get_seconds(),
57134 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57135 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57136
57137 /* do the multiway lock magic */
57138 trap = lock_rename(cache->graveyard, dir);
57139 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57140 index eccd339..4c1d995 100644
57141 --- a/fs/cachefiles/proc.c
57142 +++ b/fs/cachefiles/proc.c
57143 @@ -14,9 +14,9 @@
57144 #include <linux/seq_file.h>
57145 #include "internal.h"
57146
57147 -atomic_t cachefiles_lookup_histogram[HZ];
57148 -atomic_t cachefiles_mkdir_histogram[HZ];
57149 -atomic_t cachefiles_create_histogram[HZ];
57150 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57151 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57152 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57153
57154 /*
57155 * display the latency histogram
57156 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57157 return 0;
57158 default:
57159 index = (unsigned long) v - 3;
57160 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57161 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57162 - z = atomic_read(&cachefiles_create_histogram[index]);
57163 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57164 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57165 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57166 if (x == 0 && y == 0 && z == 0)
57167 return 0;
57168
57169 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57170 index ebaff36..7e3ea26 100644
57171 --- a/fs/cachefiles/rdwr.c
57172 +++ b/fs/cachefiles/rdwr.c
57173 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57174 old_fs = get_fs();
57175 set_fs(KERNEL_DS);
57176 ret = file->f_op->write(
57177 - file, (const void __user *) data, len, &pos);
57178 + file, (const void __force_user *) data, len, &pos);
57179 set_fs(old_fs);
57180 kunmap(page);
57181 file_end_write(file);
57182 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57183 index 2a0bcae..34ec24e 100644
57184 --- a/fs/ceph/dir.c
57185 +++ b/fs/ceph/dir.c
57186 @@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57187 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57188 struct ceph_mds_client *mdsc = fsc->mdsc;
57189 unsigned frag = fpos_frag(ctx->pos);
57190 - int off = fpos_off(ctx->pos);
57191 + unsigned int off = fpos_off(ctx->pos);
57192 int err;
57193 u32 ftype;
57194 struct ceph_mds_reply_info_parsed *rinfo;
57195 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57196 index 6a0951e..03fac6d 100644
57197 --- a/fs/ceph/super.c
57198 +++ b/fs/ceph/super.c
57199 @@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57200 /*
57201 * construct our own bdi so we can control readahead, etc.
57202 */
57203 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57204 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57205
57206 static int ceph_register_bdi(struct super_block *sb,
57207 struct ceph_fs_client *fsc)
57208 @@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
57209 default_backing_dev_info.ra_pages;
57210
57211 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57212 - atomic_long_inc_return(&bdi_seq));
57213 + atomic_long_inc_return_unchecked(&bdi_seq));
57214 if (!err)
57215 sb->s_bdi = &fsc->backing_dev_info;
57216 return err;
57217 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57218 index f3ac415..3d2420c 100644
57219 --- a/fs/cifs/cifs_debug.c
57220 +++ b/fs/cifs/cifs_debug.c
57221 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57222
57223 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57224 #ifdef CONFIG_CIFS_STATS2
57225 - atomic_set(&totBufAllocCount, 0);
57226 - atomic_set(&totSmBufAllocCount, 0);
57227 + atomic_set_unchecked(&totBufAllocCount, 0);
57228 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57229 #endif /* CONFIG_CIFS_STATS2 */
57230 spin_lock(&cifs_tcp_ses_lock);
57231 list_for_each(tmp1, &cifs_tcp_ses_list) {
57232 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57233 tcon = list_entry(tmp3,
57234 struct cifs_tcon,
57235 tcon_list);
57236 - atomic_set(&tcon->num_smbs_sent, 0);
57237 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57238 if (server->ops->clear_stats)
57239 server->ops->clear_stats(tcon);
57240 }
57241 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57242 smBufAllocCount.counter, cifs_min_small);
57243 #ifdef CONFIG_CIFS_STATS2
57244 seq_printf(m, "Total Large %d Small %d Allocations\n",
57245 - atomic_read(&totBufAllocCount),
57246 - atomic_read(&totSmBufAllocCount));
57247 + atomic_read_unchecked(&totBufAllocCount),
57248 + atomic_read_unchecked(&totSmBufAllocCount));
57249 #endif /* CONFIG_CIFS_STATS2 */
57250
57251 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57252 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57253 if (tcon->need_reconnect)
57254 seq_puts(m, "\tDISCONNECTED ");
57255 seq_printf(m, "\nSMBs: %d",
57256 - atomic_read(&tcon->num_smbs_sent));
57257 + atomic_read_unchecked(&tcon->num_smbs_sent));
57258 if (server->ops->print_stats)
57259 server->ops->print_stats(m, tcon);
57260 }
57261 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57262 index 849f613..eae6dec 100644
57263 --- a/fs/cifs/cifsfs.c
57264 +++ b/fs/cifs/cifsfs.c
57265 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57266 */
57267 cifs_req_cachep = kmem_cache_create("cifs_request",
57268 CIFSMaxBufSize + max_hdr_size, 0,
57269 - SLAB_HWCACHE_ALIGN, NULL);
57270 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57271 if (cifs_req_cachep == NULL)
57272 return -ENOMEM;
57273
57274 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57275 efficient to alloc 1 per page off the slab compared to 17K (5page)
57276 alloc of large cifs buffers even when page debugging is on */
57277 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57278 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57279 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57280 NULL);
57281 if (cifs_sm_req_cachep == NULL) {
57282 mempool_destroy(cifs_req_poolp);
57283 @@ -1168,8 +1168,8 @@ init_cifs(void)
57284 atomic_set(&bufAllocCount, 0);
57285 atomic_set(&smBufAllocCount, 0);
57286 #ifdef CONFIG_CIFS_STATS2
57287 - atomic_set(&totBufAllocCount, 0);
57288 - atomic_set(&totSmBufAllocCount, 0);
57289 + atomic_set_unchecked(&totBufAllocCount, 0);
57290 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57291 #endif /* CONFIG_CIFS_STATS2 */
57292
57293 atomic_set(&midCount, 0);
57294 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57295 index 579c6d5..95b6d03353 100644
57296 --- a/fs/cifs/cifsglob.h
57297 +++ b/fs/cifs/cifsglob.h
57298 @@ -797,35 +797,35 @@ struct cifs_tcon {
57299 __u16 Flags; /* optional support bits */
57300 enum statusEnum tidStatus;
57301 #ifdef CONFIG_CIFS_STATS
57302 - atomic_t num_smbs_sent;
57303 + atomic_unchecked_t num_smbs_sent;
57304 union {
57305 struct {
57306 - atomic_t num_writes;
57307 - atomic_t num_reads;
57308 - atomic_t num_flushes;
57309 - atomic_t num_oplock_brks;
57310 - atomic_t num_opens;
57311 - atomic_t num_closes;
57312 - atomic_t num_deletes;
57313 - atomic_t num_mkdirs;
57314 - atomic_t num_posixopens;
57315 - atomic_t num_posixmkdirs;
57316 - atomic_t num_rmdirs;
57317 - atomic_t num_renames;
57318 - atomic_t num_t2renames;
57319 - atomic_t num_ffirst;
57320 - atomic_t num_fnext;
57321 - atomic_t num_fclose;
57322 - atomic_t num_hardlinks;
57323 - atomic_t num_symlinks;
57324 - atomic_t num_locks;
57325 - atomic_t num_acl_get;
57326 - atomic_t num_acl_set;
57327 + atomic_unchecked_t num_writes;
57328 + atomic_unchecked_t num_reads;
57329 + atomic_unchecked_t num_flushes;
57330 + atomic_unchecked_t num_oplock_brks;
57331 + atomic_unchecked_t num_opens;
57332 + atomic_unchecked_t num_closes;
57333 + atomic_unchecked_t num_deletes;
57334 + atomic_unchecked_t num_mkdirs;
57335 + atomic_unchecked_t num_posixopens;
57336 + atomic_unchecked_t num_posixmkdirs;
57337 + atomic_unchecked_t num_rmdirs;
57338 + atomic_unchecked_t num_renames;
57339 + atomic_unchecked_t num_t2renames;
57340 + atomic_unchecked_t num_ffirst;
57341 + atomic_unchecked_t num_fnext;
57342 + atomic_unchecked_t num_fclose;
57343 + atomic_unchecked_t num_hardlinks;
57344 + atomic_unchecked_t num_symlinks;
57345 + atomic_unchecked_t num_locks;
57346 + atomic_unchecked_t num_acl_get;
57347 + atomic_unchecked_t num_acl_set;
57348 } cifs_stats;
57349 #ifdef CONFIG_CIFS_SMB2
57350 struct {
57351 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57352 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57353 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57354 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57355 } smb2_stats;
57356 #endif /* CONFIG_CIFS_SMB2 */
57357 } stats;
57358 @@ -1155,7 +1155,7 @@ convert_delimiter(char *path, char delim)
57359 }
57360
57361 #ifdef CONFIG_CIFS_STATS
57362 -#define cifs_stats_inc atomic_inc
57363 +#define cifs_stats_inc atomic_inc_unchecked
57364
57365 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57366 unsigned int bytes)
57367 @@ -1521,8 +1521,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57368 /* Various Debug counters */
57369 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57370 #ifdef CONFIG_CIFS_STATS2
57371 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57372 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57373 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57374 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57375 #endif
57376 GLOBAL_EXTERN atomic_t smBufAllocCount;
57377 GLOBAL_EXTERN atomic_t midCount;
57378 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57379 index a1c9ead..63e4c62 100644
57380 --- a/fs/cifs/file.c
57381 +++ b/fs/cifs/file.c
57382 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57383 index = mapping->writeback_index; /* Start from prev offset */
57384 end = -1;
57385 } else {
57386 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
57387 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
57388 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57389 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57390 range_whole = true;
57391 + index = 0;
57392 + end = ULONG_MAX;
57393 + } else {
57394 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
57395 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
57396 + }
57397 scanned = true;
57398 }
57399 retry:
57400 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57401 index 2f9f379..43f8025 100644
57402 --- a/fs/cifs/misc.c
57403 +++ b/fs/cifs/misc.c
57404 @@ -170,7 +170,7 @@ cifs_buf_get(void)
57405 memset(ret_buf, 0, buf_size + 3);
57406 atomic_inc(&bufAllocCount);
57407 #ifdef CONFIG_CIFS_STATS2
57408 - atomic_inc(&totBufAllocCount);
57409 + atomic_inc_unchecked(&totBufAllocCount);
57410 #endif /* CONFIG_CIFS_STATS2 */
57411 }
57412
57413 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57414 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57415 atomic_inc(&smBufAllocCount);
57416 #ifdef CONFIG_CIFS_STATS2
57417 - atomic_inc(&totSmBufAllocCount);
57418 + atomic_inc_unchecked(&totSmBufAllocCount);
57419 #endif /* CONFIG_CIFS_STATS2 */
57420
57421 }
57422 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57423 index ffc9ef9..b3c992b 100644
57424 --- a/fs/cifs/smb1ops.c
57425 +++ b/fs/cifs/smb1ops.c
57426 @@ -609,27 +609,27 @@ static void
57427 cifs_clear_stats(struct cifs_tcon *tcon)
57428 {
57429 #ifdef CONFIG_CIFS_STATS
57430 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57431 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57432 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57433 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57434 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57435 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57436 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57437 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57438 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57439 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57440 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57441 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57442 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57443 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57444 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57445 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57446 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57447 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57448 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57449 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57450 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57451 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57452 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57453 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57454 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57455 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57456 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57457 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57458 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57459 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57460 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57461 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57462 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57463 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57464 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57465 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57466 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57467 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57468 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57469 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57470 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57471 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57472 #endif
57473 }
57474
57475 @@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57476 {
57477 #ifdef CONFIG_CIFS_STATS
57478 seq_printf(m, " Oplocks breaks: %d",
57479 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57480 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57481 seq_printf(m, "\nReads: %d Bytes: %llu",
57482 - atomic_read(&tcon->stats.cifs_stats.num_reads),
57483 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57484 (long long)(tcon->bytes_read));
57485 seq_printf(m, "\nWrites: %d Bytes: %llu",
57486 - atomic_read(&tcon->stats.cifs_stats.num_writes),
57487 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57488 (long long)(tcon->bytes_written));
57489 seq_printf(m, "\nFlushes: %d",
57490 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
57491 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57492 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57493 - atomic_read(&tcon->stats.cifs_stats.num_locks),
57494 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57495 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57496 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57497 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57498 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57499 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57500 - atomic_read(&tcon->stats.cifs_stats.num_opens),
57501 - atomic_read(&tcon->stats.cifs_stats.num_closes),
57502 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
57503 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57504 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57505 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57506 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57507 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57508 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57509 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57510 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57511 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57512 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57513 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57514 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57515 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57516 seq_printf(m, "\nRenames: %d T2 Renames %d",
57517 - atomic_read(&tcon->stats.cifs_stats.num_renames),
57518 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57519 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57520 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57521 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57522 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57523 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
57524 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
57525 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57526 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57527 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57528 #endif
57529 }
57530
57531 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57532 index 192f51a..539307e 100644
57533 --- a/fs/cifs/smb2ops.c
57534 +++ b/fs/cifs/smb2ops.c
57535 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57536 #ifdef CONFIG_CIFS_STATS
57537 int i;
57538 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57539 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57540 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57541 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57542 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57543 }
57544 #endif
57545 }
57546 @@ -405,65 +405,65 @@ static void
57547 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57548 {
57549 #ifdef CONFIG_CIFS_STATS
57550 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57551 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57552 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57553 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57554 seq_printf(m, "\nNegotiates: %d sent %d failed",
57555 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57556 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57557 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57558 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57559 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57560 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57561 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57562 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57563 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57564 seq_printf(m, "\nLogoffs: %d sent %d failed",
57565 - atomic_read(&sent[SMB2_LOGOFF_HE]),
57566 - atomic_read(&failed[SMB2_LOGOFF_HE]));
57567 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57568 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57569 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57570 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57571 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57572 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57573 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57574 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57575 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57576 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57577 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57578 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57579 seq_printf(m, "\nCreates: %d sent %d failed",
57580 - atomic_read(&sent[SMB2_CREATE_HE]),
57581 - atomic_read(&failed[SMB2_CREATE_HE]));
57582 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57583 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57584 seq_printf(m, "\nCloses: %d sent %d failed",
57585 - atomic_read(&sent[SMB2_CLOSE_HE]),
57586 - atomic_read(&failed[SMB2_CLOSE_HE]));
57587 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57588 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57589 seq_printf(m, "\nFlushes: %d sent %d failed",
57590 - atomic_read(&sent[SMB2_FLUSH_HE]),
57591 - atomic_read(&failed[SMB2_FLUSH_HE]));
57592 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57593 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57594 seq_printf(m, "\nReads: %d sent %d failed",
57595 - atomic_read(&sent[SMB2_READ_HE]),
57596 - atomic_read(&failed[SMB2_READ_HE]));
57597 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
57598 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
57599 seq_printf(m, "\nWrites: %d sent %d failed",
57600 - atomic_read(&sent[SMB2_WRITE_HE]),
57601 - atomic_read(&failed[SMB2_WRITE_HE]));
57602 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57603 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57604 seq_printf(m, "\nLocks: %d sent %d failed",
57605 - atomic_read(&sent[SMB2_LOCK_HE]),
57606 - atomic_read(&failed[SMB2_LOCK_HE]));
57607 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57608 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57609 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57610 - atomic_read(&sent[SMB2_IOCTL_HE]),
57611 - atomic_read(&failed[SMB2_IOCTL_HE]));
57612 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57613 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57614 seq_printf(m, "\nCancels: %d sent %d failed",
57615 - atomic_read(&sent[SMB2_CANCEL_HE]),
57616 - atomic_read(&failed[SMB2_CANCEL_HE]));
57617 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57618 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57619 seq_printf(m, "\nEchos: %d sent %d failed",
57620 - atomic_read(&sent[SMB2_ECHO_HE]),
57621 - atomic_read(&failed[SMB2_ECHO_HE]));
57622 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57623 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57624 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57625 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57626 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57627 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57628 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57629 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57630 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57631 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57632 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57633 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57634 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57635 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57636 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57637 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57638 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57639 seq_printf(m, "\nSetInfos: %d sent %d failed",
57640 - atomic_read(&sent[SMB2_SET_INFO_HE]),
57641 - atomic_read(&failed[SMB2_SET_INFO_HE]));
57642 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57643 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57644 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57645 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57646 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57647 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57648 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57649 #endif
57650 }
57651
57652 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57653 index 787e171..31dcd0a 100644
57654 --- a/fs/cifs/smb2pdu.c
57655 +++ b/fs/cifs/smb2pdu.c
57656 @@ -2093,8 +2093,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57657 default:
57658 cifs_dbg(VFS, "info level %u isn't supported\n",
57659 srch_inf->info_level);
57660 - rc = -EINVAL;
57661 - goto qdir_exit;
57662 + return -EINVAL;
57663 }
57664
57665 req->FileIndex = cpu_to_le32(index);
57666 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57667 index 1da168c..8bc7ff6 100644
57668 --- a/fs/coda/cache.c
57669 +++ b/fs/coda/cache.c
57670 @@ -24,7 +24,7 @@
57671 #include "coda_linux.h"
57672 #include "coda_cache.h"
57673
57674 -static atomic_t permission_epoch = ATOMIC_INIT(0);
57675 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57676
57677 /* replace or extend an acl cache hit */
57678 void coda_cache_enter(struct inode *inode, int mask)
57679 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57680 struct coda_inode_info *cii = ITOC(inode);
57681
57682 spin_lock(&cii->c_lock);
57683 - cii->c_cached_epoch = atomic_read(&permission_epoch);
57684 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57685 if (!uid_eq(cii->c_uid, current_fsuid())) {
57686 cii->c_uid = current_fsuid();
57687 cii->c_cached_perm = mask;
57688 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57689 {
57690 struct coda_inode_info *cii = ITOC(inode);
57691 spin_lock(&cii->c_lock);
57692 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57693 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57694 spin_unlock(&cii->c_lock);
57695 }
57696
57697 /* remove all acl caches */
57698 void coda_cache_clear_all(struct super_block *sb)
57699 {
57700 - atomic_inc(&permission_epoch);
57701 + atomic_inc_unchecked(&permission_epoch);
57702 }
57703
57704
57705 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57706 spin_lock(&cii->c_lock);
57707 hit = (mask & cii->c_cached_perm) == mask &&
57708 uid_eq(cii->c_uid, current_fsuid()) &&
57709 - cii->c_cached_epoch == atomic_read(&permission_epoch);
57710 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57711 spin_unlock(&cii->c_lock);
57712
57713 return hit;
57714 diff --git a/fs/compat.c b/fs/compat.c
57715 index 6af20de..fec3fbb 100644
57716 --- a/fs/compat.c
57717 +++ b/fs/compat.c
57718 @@ -54,7 +54,7 @@
57719 #include <asm/ioctls.h>
57720 #include "internal.h"
57721
57722 -int compat_log = 1;
57723 +int compat_log = 0;
57724
57725 int compat_printk(const char *fmt, ...)
57726 {
57727 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57728
57729 set_fs(KERNEL_DS);
57730 /* The __user pointer cast is valid because of the set_fs() */
57731 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57732 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57733 set_fs(oldfs);
57734 /* truncating is ok because it's a user address */
57735 if (!ret)
57736 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57737 goto out;
57738
57739 ret = -EINVAL;
57740 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57741 + if (nr_segs > UIO_MAXIOV)
57742 goto out;
57743 if (nr_segs > fast_segs) {
57744 ret = -ENOMEM;
57745 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57746 struct compat_readdir_callback {
57747 struct dir_context ctx;
57748 struct compat_old_linux_dirent __user *dirent;
57749 + struct file * file;
57750 int result;
57751 };
57752
57753 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57754 buf->result = -EOVERFLOW;
57755 return -EOVERFLOW;
57756 }
57757 +
57758 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57759 + return 0;
57760 +
57761 buf->result++;
57762 dirent = buf->dirent;
57763 if (!access_ok(VERIFY_WRITE, dirent,
57764 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57765 if (!f.file)
57766 return -EBADF;
57767
57768 + buf.file = f.file;
57769 error = iterate_dir(f.file, &buf.ctx);
57770 if (buf.result)
57771 error = buf.result;
57772 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
57773 struct dir_context ctx;
57774 struct compat_linux_dirent __user *current_dir;
57775 struct compat_linux_dirent __user *previous;
57776 + struct file * file;
57777 int count;
57778 int error;
57779 };
57780 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57781 buf->error = -EOVERFLOW;
57782 return -EOVERFLOW;
57783 }
57784 +
57785 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57786 + return 0;
57787 +
57788 dirent = buf->previous;
57789 if (dirent) {
57790 if (__put_user(offset, &dirent->d_off))
57791 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57792 if (!f.file)
57793 return -EBADF;
57794
57795 + buf.file = f.file;
57796 error = iterate_dir(f.file, &buf.ctx);
57797 if (error >= 0)
57798 error = buf.error;
57799 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57800 struct dir_context ctx;
57801 struct linux_dirent64 __user *current_dir;
57802 struct linux_dirent64 __user *previous;
57803 + struct file * file;
57804 int count;
57805 int error;
57806 };
57807 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57808 buf->error = -EINVAL; /* only used if we fail.. */
57809 if (reclen > buf->count)
57810 return -EINVAL;
57811 +
57812 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57813 + return 0;
57814 +
57815 dirent = buf->previous;
57816
57817 if (dirent) {
57818 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57819 if (!f.file)
57820 return -EBADF;
57821
57822 + buf.file = f.file;
57823 error = iterate_dir(f.file, &buf.ctx);
57824 if (error >= 0)
57825 error = buf.error;
57826 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57827 index a81147e..20bf2b5 100644
57828 --- a/fs/compat_binfmt_elf.c
57829 +++ b/fs/compat_binfmt_elf.c
57830 @@ -30,11 +30,13 @@
57831 #undef elf_phdr
57832 #undef elf_shdr
57833 #undef elf_note
57834 +#undef elf_dyn
57835 #undef elf_addr_t
57836 #define elfhdr elf32_hdr
57837 #define elf_phdr elf32_phdr
57838 #define elf_shdr elf32_shdr
57839 #define elf_note elf32_note
57840 +#define elf_dyn Elf32_Dyn
57841 #define elf_addr_t Elf32_Addr
57842
57843 /*
57844 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
57845 index dc52e13..ec61057 100644
57846 --- a/fs/compat_ioctl.c
57847 +++ b/fs/compat_ioctl.c
57848 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
57849 return -EFAULT;
57850 if (__get_user(udata, &ss32->iomem_base))
57851 return -EFAULT;
57852 - ss.iomem_base = compat_ptr(udata);
57853 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
57854 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
57855 __get_user(ss.port_high, &ss32->port_high))
57856 return -EFAULT;
57857 @@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
57858 for (i = 0; i < nmsgs; i++) {
57859 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
57860 return -EFAULT;
57861 - if (get_user(datap, &umsgs[i].buf) ||
57862 - put_user(compat_ptr(datap), &tmsgs[i].buf))
57863 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57864 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57865 return -EFAULT;
57866 }
57867 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57868 @@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
57869 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57870 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57871 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57872 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57873 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57874 return -EFAULT;
57875
57876 return ioctl_preallocate(file, p);
57877 @@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57878 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57879 {
57880 unsigned int a, b;
57881 - a = *(unsigned int *)p;
57882 - b = *(unsigned int *)q;
57883 + a = *(const unsigned int *)p;
57884 + b = *(const unsigned int *)q;
57885 if (a > b)
57886 return 1;
57887 if (a < b)
57888 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57889 index e081acb..911df21 100644
57890 --- a/fs/configfs/dir.c
57891 +++ b/fs/configfs/dir.c
57892 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57893 }
57894 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57895 struct configfs_dirent *next;
57896 - const char *name;
57897 + const unsigned char * name;
57898 + char d_name[sizeof(next->s_dentry->d_iname)];
57899 int len;
57900 struct inode *inode = NULL;
57901
57902 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57903 continue;
57904
57905 name = configfs_get_name(next);
57906 - len = strlen(name);
57907 + if (next->s_dentry && name == next->s_dentry->d_iname) {
57908 + len = next->s_dentry->d_name.len;
57909 + memcpy(d_name, name, len);
57910 + name = d_name;
57911 + } else
57912 + len = strlen(name);
57913
57914 /*
57915 * We'll have a dentry and an inode for
57916 diff --git a/fs/coredump.c b/fs/coredump.c
57917 index bc3fbcd..6031650 100644
57918 --- a/fs/coredump.c
57919 +++ b/fs/coredump.c
57920 @@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
57921 struct pipe_inode_info *pipe = file->private_data;
57922
57923 pipe_lock(pipe);
57924 - pipe->readers++;
57925 - pipe->writers--;
57926 + atomic_inc(&pipe->readers);
57927 + atomic_dec(&pipe->writers);
57928 wake_up_interruptible_sync(&pipe->wait);
57929 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57930 pipe_unlock(pipe);
57931 @@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
57932 * We actually want wait_event_freezable() but then we need
57933 * to clear TIF_SIGPENDING and improve dump_interrupted().
57934 */
57935 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
57936 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
57937
57938 pipe_lock(pipe);
57939 - pipe->readers--;
57940 - pipe->writers++;
57941 + atomic_dec(&pipe->readers);
57942 + atomic_inc(&pipe->writers);
57943 pipe_unlock(pipe);
57944 }
57945
57946 @@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
57947 struct files_struct *displaced;
57948 bool need_nonrelative = false;
57949 bool core_dumped = false;
57950 - static atomic_t core_dump_count = ATOMIC_INIT(0);
57951 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
57952 + long signr = siginfo->si_signo;
57953 + int dumpable;
57954 struct coredump_params cprm = {
57955 .siginfo = siginfo,
57956 .regs = signal_pt_regs(),
57957 @@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
57958 .mm_flags = mm->flags,
57959 };
57960
57961 - audit_core_dumps(siginfo->si_signo);
57962 + audit_core_dumps(signr);
57963 +
57964 + dumpable = __get_dumpable(cprm.mm_flags);
57965 +
57966 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
57967 + gr_handle_brute_attach(dumpable);
57968
57969 binfmt = mm->binfmt;
57970 if (!binfmt || !binfmt->core_dump)
57971 goto fail;
57972 - if (!__get_dumpable(cprm.mm_flags))
57973 + if (!dumpable)
57974 goto fail;
57975
57976 cred = prepare_creds();
57977 @@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
57978 need_nonrelative = true;
57979 }
57980
57981 - retval = coredump_wait(siginfo->si_signo, &core_state);
57982 + retval = coredump_wait(signr, &core_state);
57983 if (retval < 0)
57984 goto fail_creds;
57985
57986 @@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
57987 }
57988 cprm.limit = RLIM_INFINITY;
57989
57990 - dump_count = atomic_inc_return(&core_dump_count);
57991 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
57992 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
57993 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
57994 task_tgid_vnr(current), current->comm);
57995 @@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
57996 } else {
57997 struct inode *inode;
57998
57999 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58000 +
58001 if (cprm.limit < binfmt->min_coredump)
58002 goto fail_unlock;
58003
58004 @@ -669,7 +678,7 @@ close_fail:
58005 filp_close(cprm.file, NULL);
58006 fail_dropcount:
58007 if (ispipe)
58008 - atomic_dec(&core_dump_count);
58009 + atomic_dec_unchecked(&core_dump_count);
58010 fail_unlock:
58011 kfree(cn.corename);
58012 coredump_finish(mm, core_dumped);
58013 @@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58014 struct file *file = cprm->file;
58015 loff_t pos = file->f_pos;
58016 ssize_t n;
58017 +
58018 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58019 if (cprm->written + nr > cprm->limit)
58020 return 0;
58021 while (nr) {
58022 diff --git a/fs/dcache.c b/fs/dcache.c
58023 index fdbe230..ba17c1f 100644
58024 --- a/fs/dcache.c
58025 +++ b/fs/dcache.c
58026 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58027 */
58028 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58029 if (name->len > DNAME_INLINE_LEN-1) {
58030 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58031 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58032 if (!dname) {
58033 kmem_cache_free(dentry_cache, dentry);
58034 return NULL;
58035 @@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
58036 mempages -= reserve;
58037
58038 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58039 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58040 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58041 + SLAB_NO_SANITIZE, NULL);
58042
58043 dcache_init();
58044 inode_init();
58045 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58046 index 9c0444c..628490c 100644
58047 --- a/fs/debugfs/inode.c
58048 +++ b/fs/debugfs/inode.c
58049 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58050 */
58051 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58052 {
58053 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58054 + return __create_file(name, S_IFDIR | S_IRWXU,
58055 +#else
58056 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58057 +#endif
58058 parent, NULL, NULL);
58059 }
58060 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58061 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58062 index c36c448..fc96710 100644
58063 --- a/fs/ecryptfs/inode.c
58064 +++ b/fs/ecryptfs/inode.c
58065 @@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
58066 old_fs = get_fs();
58067 set_fs(get_ds());
58068 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58069 - (char __user *)lower_buf,
58070 + (char __force_user *)lower_buf,
58071 PATH_MAX);
58072 set_fs(old_fs);
58073 if (rc < 0)
58074 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58075 index e4141f2..d8263e8 100644
58076 --- a/fs/ecryptfs/miscdev.c
58077 +++ b/fs/ecryptfs/miscdev.c
58078 @@ -304,7 +304,7 @@ check_list:
58079 goto out_unlock_msg_ctx;
58080 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58081 if (msg_ctx->msg) {
58082 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58083 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58084 goto out_unlock_msg_ctx;
58085 i += packet_length_size;
58086 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58087 diff --git a/fs/exec.c b/fs/exec.c
58088 index 7ea097f..0158d8a 100644
58089 --- a/fs/exec.c
58090 +++ b/fs/exec.c
58091 @@ -55,8 +55,20 @@
58092 #include <linux/pipe_fs_i.h>
58093 #include <linux/oom.h>
58094 #include <linux/compat.h>
58095 +#include <linux/random.h>
58096 +#include <linux/seq_file.h>
58097 +#include <linux/coredump.h>
58098 +#include <linux/mman.h>
58099 +
58100 +#ifdef CONFIG_PAX_REFCOUNT
58101 +#include <linux/kallsyms.h>
58102 +#include <linux/kdebug.h>
58103 +#endif
58104 +
58105 +#include <trace/events/fs.h>
58106
58107 #include <asm/uaccess.h>
58108 +#include <asm/sections.h>
58109 #include <asm/mmu_context.h>
58110 #include <asm/tlb.h>
58111
58112 @@ -66,19 +78,34 @@
58113
58114 #include <trace/events/sched.h>
58115
58116 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58117 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58118 +{
58119 + 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");
58120 +}
58121 +#endif
58122 +
58123 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58124 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58125 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58126 +#endif
58127 +
58128 int suid_dumpable = 0;
58129
58130 static LIST_HEAD(formats);
58131 static DEFINE_RWLOCK(binfmt_lock);
58132
58133 +extern int gr_process_kernel_exec_ban(void);
58134 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58135 +
58136 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58137 {
58138 BUG_ON(!fmt);
58139 if (WARN_ON(!fmt->load_binary))
58140 return;
58141 write_lock(&binfmt_lock);
58142 - insert ? list_add(&fmt->lh, &formats) :
58143 - list_add_tail(&fmt->lh, &formats);
58144 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58145 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58146 write_unlock(&binfmt_lock);
58147 }
58148
58149 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58150 void unregister_binfmt(struct linux_binfmt * fmt)
58151 {
58152 write_lock(&binfmt_lock);
58153 - list_del(&fmt->lh);
58154 + pax_list_del((struct list_head *)&fmt->lh);
58155 write_unlock(&binfmt_lock);
58156 }
58157
58158 @@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58159 int write)
58160 {
58161 struct page *page;
58162 - int ret;
58163
58164 -#ifdef CONFIG_STACK_GROWSUP
58165 - if (write) {
58166 - ret = expand_downwards(bprm->vma, pos);
58167 - if (ret < 0)
58168 - return NULL;
58169 - }
58170 -#endif
58171 - ret = get_user_pages(current, bprm->mm, pos,
58172 - 1, write, 1, &page, NULL);
58173 - if (ret <= 0)
58174 + if (0 > expand_downwards(bprm->vma, pos))
58175 + return NULL;
58176 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58177 return NULL;
58178
58179 if (write) {
58180 @@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58181 if (size <= ARG_MAX)
58182 return page;
58183
58184 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58185 + // only allow 512KB for argv+env on suid/sgid binaries
58186 + // to prevent easy ASLR exhaustion
58187 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58188 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58189 + (size > (512 * 1024))) {
58190 + put_page(page);
58191 + return NULL;
58192 + }
58193 +#endif
58194 +
58195 /*
58196 * Limit to 1/4-th the stack size for the argv+env strings.
58197 * This ensures that:
58198 @@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58199 vma->vm_end = STACK_TOP_MAX;
58200 vma->vm_start = vma->vm_end - PAGE_SIZE;
58201 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58202 +
58203 +#ifdef CONFIG_PAX_SEGMEXEC
58204 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58205 +#endif
58206 +
58207 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58208 INIT_LIST_HEAD(&vma->anon_vma_chain);
58209
58210 @@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58211 mm->stack_vm = mm->total_vm = 1;
58212 up_write(&mm->mmap_sem);
58213 bprm->p = vma->vm_end - sizeof(void *);
58214 +
58215 +#ifdef CONFIG_PAX_RANDUSTACK
58216 + if (randomize_va_space)
58217 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58218 +#endif
58219 +
58220 return 0;
58221 err:
58222 up_write(&mm->mmap_sem);
58223 @@ -397,7 +438,7 @@ struct user_arg_ptr {
58224 } ptr;
58225 };
58226
58227 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58228 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58229 {
58230 const char __user *native;
58231
58232 @@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58233 compat_uptr_t compat;
58234
58235 if (get_user(compat, argv.ptr.compat + nr))
58236 - return ERR_PTR(-EFAULT);
58237 + return (const char __force_user *)ERR_PTR(-EFAULT);
58238
58239 return compat_ptr(compat);
58240 }
58241 #endif
58242
58243 if (get_user(native, argv.ptr.native + nr))
58244 - return ERR_PTR(-EFAULT);
58245 + return (const char __force_user *)ERR_PTR(-EFAULT);
58246
58247 return native;
58248 }
58249 @@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
58250 if (!p)
58251 break;
58252
58253 - if (IS_ERR(p))
58254 + if (IS_ERR((const char __force_kernel *)p))
58255 return -EFAULT;
58256
58257 if (i >= max)
58258 @@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58259
58260 ret = -EFAULT;
58261 str = get_user_arg_ptr(argv, argc);
58262 - if (IS_ERR(str))
58263 + if (IS_ERR((const char __force_kernel *)str))
58264 goto out;
58265
58266 len = strnlen_user(str, MAX_ARG_STRLEN);
58267 @@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58268 int r;
58269 mm_segment_t oldfs = get_fs();
58270 struct user_arg_ptr argv = {
58271 - .ptr.native = (const char __user *const __user *)__argv,
58272 + .ptr.native = (const char __user * const __force_user *)__argv,
58273 };
58274
58275 set_fs(KERNEL_DS);
58276 @@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58277 unsigned long new_end = old_end - shift;
58278 struct mmu_gather tlb;
58279
58280 - BUG_ON(new_start > new_end);
58281 + if (new_start >= new_end || new_start < mmap_min_addr)
58282 + return -ENOMEM;
58283
58284 /*
58285 * ensure there are no vmas between where we want to go
58286 @@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58287 if (vma != find_vma(mm, new_start))
58288 return -EFAULT;
58289
58290 +#ifdef CONFIG_PAX_SEGMEXEC
58291 + BUG_ON(pax_find_mirror_vma(vma));
58292 +#endif
58293 +
58294 /*
58295 * cover the whole range: [new_start, old_end)
58296 */
58297 @@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58298 stack_top = arch_align_stack(stack_top);
58299 stack_top = PAGE_ALIGN(stack_top);
58300
58301 - if (unlikely(stack_top < mmap_min_addr) ||
58302 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58303 - return -ENOMEM;
58304 -
58305 stack_shift = vma->vm_end - stack_top;
58306
58307 bprm->p -= stack_shift;
58308 @@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58309 bprm->exec -= stack_shift;
58310
58311 down_write(&mm->mmap_sem);
58312 +
58313 + /* Move stack pages down in memory. */
58314 + if (stack_shift) {
58315 + ret = shift_arg_pages(vma, stack_shift);
58316 + if (ret)
58317 + goto out_unlock;
58318 + }
58319 +
58320 vm_flags = VM_STACK_FLAGS;
58321
58322 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58323 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58324 + vm_flags &= ~VM_EXEC;
58325 +
58326 +#ifdef CONFIG_PAX_MPROTECT
58327 + if (mm->pax_flags & MF_PAX_MPROTECT)
58328 + vm_flags &= ~VM_MAYEXEC;
58329 +#endif
58330 +
58331 + }
58332 +#endif
58333 +
58334 /*
58335 * Adjust stack execute permissions; explicitly enable for
58336 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58337 @@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58338 goto out_unlock;
58339 BUG_ON(prev != vma);
58340
58341 - /* Move stack pages down in memory. */
58342 - if (stack_shift) {
58343 - ret = shift_arg_pages(vma, stack_shift);
58344 - if (ret)
58345 - goto out_unlock;
58346 - }
58347 -
58348 /* mprotect_fixup is overkill to remove the temporary stack flags */
58349 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58350
58351 @@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58352 #endif
58353 current->mm->start_stack = bprm->p;
58354 ret = expand_stack(vma, stack_base);
58355 +
58356 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58357 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58358 + unsigned long size;
58359 + vm_flags_t vm_flags;
58360 +
58361 + size = STACK_TOP - vma->vm_end;
58362 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58363 +
58364 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58365 +
58366 +#ifdef CONFIG_X86
58367 + if (!ret) {
58368 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58369 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58370 + }
58371 +#endif
58372 +
58373 + }
58374 +#endif
58375 +
58376 if (ret)
58377 ret = -EFAULT;
58378
58379 @@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
58380
58381 fsnotify_open(file);
58382
58383 + trace_open_exec(name);
58384 +
58385 err = deny_write_access(file);
58386 if (err)
58387 goto exit;
58388 @@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
58389 old_fs = get_fs();
58390 set_fs(get_ds());
58391 /* The cast to a user pointer is valid due to the set_fs() */
58392 - result = vfs_read(file, (void __user *)addr, count, &pos);
58393 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
58394 set_fs(old_fs);
58395 return result;
58396 }
58397 @@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
58398 }
58399 rcu_read_unlock();
58400
58401 - if (p->fs->users > n_fs) {
58402 + if (atomic_read(&p->fs->users) > n_fs) {
58403 bprm->unsafe |= LSM_UNSAFE_SHARE;
58404 } else {
58405 res = -EAGAIN;
58406 @@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58407 return ret;
58408 }
58409
58410 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58411 +static DEFINE_PER_CPU(u64, exec_counter);
58412 +static int __init init_exec_counters(void)
58413 +{
58414 + unsigned int cpu;
58415 +
58416 + for_each_possible_cpu(cpu) {
58417 + per_cpu(exec_counter, cpu) = (u64)cpu;
58418 + }
58419 +
58420 + return 0;
58421 +}
58422 +early_initcall(init_exec_counters);
58423 +static inline void increment_exec_counter(void)
58424 +{
58425 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
58426 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58427 +}
58428 +#else
58429 +static inline void increment_exec_counter(void) {}
58430 +#endif
58431 +
58432 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
58433 + struct user_arg_ptr argv);
58434 +
58435 /*
58436 * sys_execve() executes a new program.
58437 */
58438 @@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
58439 struct user_arg_ptr argv,
58440 struct user_arg_ptr envp)
58441 {
58442 +#ifdef CONFIG_GRKERNSEC
58443 + struct file *old_exec_file;
58444 + struct acl_subject_label *old_acl;
58445 + struct rlimit old_rlim[RLIM_NLIMITS];
58446 +#endif
58447 struct linux_binprm *bprm;
58448 struct file *file;
58449 struct files_struct *displaced;
58450 bool clear_in_exec;
58451 int retval;
58452
58453 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58454 +
58455 /*
58456 * We move the actual failure in case of RLIMIT_NPROC excess from
58457 * set*uid() to execve() because too many poorly written programs
58458 @@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
58459 if (IS_ERR(file))
58460 goto out_unmark;
58461
58462 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
58463 + retval = -EPERM;
58464 + goto out_file;
58465 + }
58466 +
58467 sched_exec();
58468
58469 bprm->file = file;
58470 bprm->filename = filename;
58471 bprm->interp = filename;
58472
58473 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58474 + retval = -EACCES;
58475 + goto out_file;
58476 + }
58477 +
58478 retval = bprm_mm_init(bprm);
58479 if (retval)
58480 goto out_file;
58481 @@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
58482 if (retval < 0)
58483 goto out;
58484
58485 +#ifdef CONFIG_GRKERNSEC
58486 + old_acl = current->acl;
58487 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58488 + old_exec_file = current->exec_file;
58489 + get_file(file);
58490 + current->exec_file = file;
58491 +#endif
58492 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58493 + /* limit suid stack to 8MB
58494 + * we saved the old limits above and will restore them if this exec fails
58495 + */
58496 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58497 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58498 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58499 +#endif
58500 +
58501 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58502 + retval = -EPERM;
58503 + goto out_fail;
58504 + }
58505 +
58506 + if (!gr_tpe_allow(file)) {
58507 + retval = -EACCES;
58508 + goto out_fail;
58509 + }
58510 +
58511 + if (gr_check_crash_exec(file)) {
58512 + retval = -EACCES;
58513 + goto out_fail;
58514 + }
58515 +
58516 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58517 + bprm->unsafe);
58518 + if (retval < 0)
58519 + goto out_fail;
58520 +
58521 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58522 if (retval < 0)
58523 - goto out;
58524 + goto out_fail;
58525
58526 bprm->exec = bprm->p;
58527 retval = copy_strings(bprm->envc, envp, bprm);
58528 if (retval < 0)
58529 - goto out;
58530 + goto out_fail;
58531
58532 retval = copy_strings(bprm->argc, argv, bprm);
58533 if (retval < 0)
58534 - goto out;
58535 + goto out_fail;
58536 +
58537 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58538 +
58539 + gr_handle_exec_args(bprm, argv);
58540
58541 retval = exec_binprm(bprm);
58542 if (retval < 0)
58543 - goto out;
58544 + goto out_fail;
58545 +#ifdef CONFIG_GRKERNSEC
58546 + if (old_exec_file)
58547 + fput(old_exec_file);
58548 +#endif
58549
58550 /* execve succeeded */
58551 +
58552 + increment_exec_counter();
58553 current->fs->in_exec = 0;
58554 current->in_execve = 0;
58555 acct_update_integrals(current);
58556 @@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
58557 put_files_struct(displaced);
58558 return retval;
58559
58560 +out_fail:
58561 +#ifdef CONFIG_GRKERNSEC
58562 + current->acl = old_acl;
58563 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58564 + fput(current->exec_file);
58565 + current->exec_file = old_exec_file;
58566 +#endif
58567 +
58568 out:
58569 if (bprm->mm) {
58570 acct_arg_size(bprm, 0);
58571 @@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58572 return error;
58573 }
58574 #endif
58575 +
58576 +int pax_check_flags(unsigned long *flags)
58577 +{
58578 + int retval = 0;
58579 +
58580 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58581 + if (*flags & MF_PAX_SEGMEXEC)
58582 + {
58583 + *flags &= ~MF_PAX_SEGMEXEC;
58584 + retval = -EINVAL;
58585 + }
58586 +#endif
58587 +
58588 + if ((*flags & MF_PAX_PAGEEXEC)
58589 +
58590 +#ifdef CONFIG_PAX_PAGEEXEC
58591 + && (*flags & MF_PAX_SEGMEXEC)
58592 +#endif
58593 +
58594 + )
58595 + {
58596 + *flags &= ~MF_PAX_PAGEEXEC;
58597 + retval = -EINVAL;
58598 + }
58599 +
58600 + if ((*flags & MF_PAX_MPROTECT)
58601 +
58602 +#ifdef CONFIG_PAX_MPROTECT
58603 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58604 +#endif
58605 +
58606 + )
58607 + {
58608 + *flags &= ~MF_PAX_MPROTECT;
58609 + retval = -EINVAL;
58610 + }
58611 +
58612 + if ((*flags & MF_PAX_EMUTRAMP)
58613 +
58614 +#ifdef CONFIG_PAX_EMUTRAMP
58615 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58616 +#endif
58617 +
58618 + )
58619 + {
58620 + *flags &= ~MF_PAX_EMUTRAMP;
58621 + retval = -EINVAL;
58622 + }
58623 +
58624 + return retval;
58625 +}
58626 +
58627 +EXPORT_SYMBOL(pax_check_flags);
58628 +
58629 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58630 +char *pax_get_path(const struct path *path, char *buf, int buflen)
58631 +{
58632 + char *pathname = d_path(path, buf, buflen);
58633 +
58634 + if (IS_ERR(pathname))
58635 + goto toolong;
58636 +
58637 + pathname = mangle_path(buf, pathname, "\t\n\\");
58638 + if (!pathname)
58639 + goto toolong;
58640 +
58641 + *pathname = 0;
58642 + return buf;
58643 +
58644 +toolong:
58645 + return "<path too long>";
58646 +}
58647 +EXPORT_SYMBOL(pax_get_path);
58648 +
58649 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58650 +{
58651 + struct task_struct *tsk = current;
58652 + struct mm_struct *mm = current->mm;
58653 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58654 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58655 + char *path_exec = NULL;
58656 + char *path_fault = NULL;
58657 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
58658 + siginfo_t info = { };
58659 +
58660 + if (buffer_exec && buffer_fault) {
58661 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58662 +
58663 + down_read(&mm->mmap_sem);
58664 + vma = mm->mmap;
58665 + while (vma && (!vma_exec || !vma_fault)) {
58666 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58667 + vma_exec = vma;
58668 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58669 + vma_fault = vma;
58670 + vma = vma->vm_next;
58671 + }
58672 + if (vma_exec)
58673 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58674 + if (vma_fault) {
58675 + start = vma_fault->vm_start;
58676 + end = vma_fault->vm_end;
58677 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58678 + if (vma_fault->vm_file)
58679 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58680 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58681 + path_fault = "<heap>";
58682 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58683 + path_fault = "<stack>";
58684 + else
58685 + path_fault = "<anonymous mapping>";
58686 + }
58687 + up_read(&mm->mmap_sem);
58688 + }
58689 + if (tsk->signal->curr_ip)
58690 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58691 + else
58692 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58693 + 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),
58694 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58695 + free_page((unsigned long)buffer_exec);
58696 + free_page((unsigned long)buffer_fault);
58697 + pax_report_insns(regs, pc, sp);
58698 + info.si_signo = SIGKILL;
58699 + info.si_errno = 0;
58700 + info.si_code = SI_KERNEL;
58701 + info.si_pid = 0;
58702 + info.si_uid = 0;
58703 + do_coredump(&info);
58704 +}
58705 +#endif
58706 +
58707 +#ifdef CONFIG_PAX_REFCOUNT
58708 +void pax_report_refcount_overflow(struct pt_regs *regs)
58709 +{
58710 + if (current->signal->curr_ip)
58711 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58712 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
58713 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58714 + else
58715 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58716 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58717 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58718 + preempt_disable();
58719 + show_regs(regs);
58720 + preempt_enable();
58721 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58722 +}
58723 +#endif
58724 +
58725 +#ifdef CONFIG_PAX_USERCOPY
58726 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58727 +static noinline int check_stack_object(const void *obj, unsigned long len)
58728 +{
58729 + const void * const stack = task_stack_page(current);
58730 + const void * const stackend = stack + THREAD_SIZE;
58731 +
58732 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58733 + const void *frame = NULL;
58734 + const void *oldframe;
58735 +#endif
58736 +
58737 + if (obj + len < obj)
58738 + return -1;
58739 +
58740 + if (obj + len <= stack || stackend <= obj)
58741 + return 0;
58742 +
58743 + if (obj < stack || stackend < obj + len)
58744 + return -1;
58745 +
58746 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58747 + oldframe = __builtin_frame_address(1);
58748 + if (oldframe)
58749 + frame = __builtin_frame_address(2);
58750 + /*
58751 + low ----------------------------------------------> high
58752 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
58753 + ^----------------^
58754 + allow copies only within here
58755 + */
58756 + while (stack <= frame && frame < stackend) {
58757 + /* if obj + len extends past the last frame, this
58758 + check won't pass and the next frame will be 0,
58759 + causing us to bail out and correctly report
58760 + the copy as invalid
58761 + */
58762 + if (obj + len <= frame)
58763 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58764 + oldframe = frame;
58765 + frame = *(const void * const *)frame;
58766 + }
58767 + return -1;
58768 +#else
58769 + return 1;
58770 +#endif
58771 +}
58772 +
58773 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58774 +{
58775 + if (current->signal->curr_ip)
58776 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58777 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58778 + else
58779 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58780 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58781 + dump_stack();
58782 + gr_handle_kernel_exploit();
58783 + do_group_exit(SIGKILL);
58784 +}
58785 +#endif
58786 +
58787 +#ifdef CONFIG_PAX_USERCOPY
58788 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58789 +{
58790 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58791 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
58792 +#ifdef CONFIG_MODULES
58793 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58794 +#else
58795 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58796 +#endif
58797 +
58798 +#else
58799 + unsigned long textlow = (unsigned long)_stext;
58800 + unsigned long texthigh = (unsigned long)_etext;
58801 +
58802 +#ifdef CONFIG_X86_64
58803 + /* check against linear mapping as well */
58804 + if (high > (unsigned long)__va(__pa(textlow)) &&
58805 + low <= (unsigned long)__va(__pa(texthigh)))
58806 + return true;
58807 +#endif
58808 +
58809 +#endif
58810 +
58811 + if (high <= textlow || low > texthigh)
58812 + return false;
58813 + else
58814 + return true;
58815 +}
58816 +#endif
58817 +
58818 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
58819 +{
58820 +
58821 +#ifdef CONFIG_PAX_USERCOPY
58822 + const char *type;
58823 +
58824 + if (!n)
58825 + return;
58826 +
58827 + type = check_heap_object(ptr, n);
58828 + if (!type) {
58829 + int ret = check_stack_object(ptr, n);
58830 + if (ret == 1 || ret == 2)
58831 + return;
58832 + if (ret == 0) {
58833 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
58834 + type = "<kernel text>";
58835 + else
58836 + return;
58837 + } else
58838 + type = "<process stack>";
58839 + }
58840 +
58841 + pax_report_usercopy(ptr, n, to_user, type);
58842 +#endif
58843 +
58844 +}
58845 +EXPORT_SYMBOL(__check_object_size);
58846 +
58847 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
58848 +void pax_track_stack(void)
58849 +{
58850 + unsigned long sp = (unsigned long)&sp;
58851 + if (sp < current_thread_info()->lowest_stack &&
58852 + sp > (unsigned long)task_stack_page(current))
58853 + current_thread_info()->lowest_stack = sp;
58854 +}
58855 +EXPORT_SYMBOL(pax_track_stack);
58856 +#endif
58857 +
58858 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
58859 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
58860 +{
58861 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58862 + dump_stack();
58863 + do_group_exit(SIGKILL);
58864 +}
58865 +EXPORT_SYMBOL(report_size_overflow);
58866 +#endif
58867 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58868 index 9f9992b..8b59411 100644
58869 --- a/fs/ext2/balloc.c
58870 +++ b/fs/ext2/balloc.c
58871 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58872
58873 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58874 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58875 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58876 + if (free_blocks < root_blocks + 1 &&
58877 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58878 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58879 - !in_group_p (sbi->s_resgid))) {
58880 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58881 return 0;
58882 }
58883 return 1;
58884 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58885 index 2d7557d..14e38f94 100644
58886 --- a/fs/ext2/xattr.c
58887 +++ b/fs/ext2/xattr.c
58888 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58889 struct buffer_head *bh = NULL;
58890 struct ext2_xattr_entry *entry;
58891 char *end;
58892 - size_t rest = buffer_size;
58893 + size_t rest = buffer_size, total_size = 0;
58894 int error;
58895
58896 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58897 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58898 buffer += size;
58899 }
58900 rest -= size;
58901 + total_size += size;
58902 }
58903 }
58904 - error = buffer_size - rest; /* total size */
58905 + error = total_size;
58906
58907 cleanup:
58908 brelse(bh);
58909 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58910 index 22548f5..41521d8 100644
58911 --- a/fs/ext3/balloc.c
58912 +++ b/fs/ext3/balloc.c
58913 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58914
58915 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58916 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58917 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58918 + if (free_blocks < root_blocks + 1 &&
58919 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58920 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58921 - !in_group_p (sbi->s_resgid))) {
58922 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58923 return 0;
58924 }
58925 return 1;
58926 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58927 index b1fc963..881228c 100644
58928 --- a/fs/ext3/xattr.c
58929 +++ b/fs/ext3/xattr.c
58930 @@ -330,7 +330,7 @@ static int
58931 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58932 char *buffer, size_t buffer_size)
58933 {
58934 - size_t rest = buffer_size;
58935 + size_t rest = buffer_size, total_size = 0;
58936
58937 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
58938 const struct xattr_handler *handler =
58939 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58940 buffer += size;
58941 }
58942 rest -= size;
58943 + total_size += size;
58944 }
58945 }
58946 - return buffer_size - rest;
58947 + return total_size;
58948 }
58949
58950 static int
58951 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
58952 index 6ea7b14..8fa16d9 100644
58953 --- a/fs/ext4/balloc.c
58954 +++ b/fs/ext4/balloc.c
58955 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
58956 /* Hm, nope. Are (enough) root reserved clusters available? */
58957 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
58958 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
58959 - capable(CAP_SYS_RESOURCE) ||
58960 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
58961 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
58962 + capable_nolog(CAP_SYS_RESOURCE)) {
58963
58964 if (free_clusters >= (nclusters + dirty_clusters +
58965 resv_clusters))
58966 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
58967 index d3a534f..242c50a 100644
58968 --- a/fs/ext4/ext4.h
58969 +++ b/fs/ext4/ext4.h
58970 @@ -1269,19 +1269,19 @@ struct ext4_sb_info {
58971 unsigned long s_mb_last_start;
58972
58973 /* stats for buddy allocator */
58974 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
58975 - atomic_t s_bal_success; /* we found long enough chunks */
58976 - atomic_t s_bal_allocated; /* in blocks */
58977 - atomic_t s_bal_ex_scanned; /* total extents scanned */
58978 - atomic_t s_bal_goals; /* goal hits */
58979 - atomic_t s_bal_breaks; /* too long searches */
58980 - atomic_t s_bal_2orders; /* 2^order hits */
58981 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
58982 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
58983 + atomic_unchecked_t s_bal_allocated; /* in blocks */
58984 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
58985 + atomic_unchecked_t s_bal_goals; /* goal hits */
58986 + atomic_unchecked_t s_bal_breaks; /* too long searches */
58987 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
58988 spinlock_t s_bal_lock;
58989 unsigned long s_mb_buddies_generated;
58990 unsigned long long s_mb_generation_time;
58991 - atomic_t s_mb_lost_chunks;
58992 - atomic_t s_mb_preallocated;
58993 - atomic_t s_mb_discarded;
58994 + atomic_unchecked_t s_mb_lost_chunks;
58995 + atomic_unchecked_t s_mb_preallocated;
58996 + atomic_unchecked_t s_mb_discarded;
58997 atomic_t s_lock_busy;
58998
58999 /* locality groups */
59000 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59001 index 04a5c75..09894fa 100644
59002 --- a/fs/ext4/mballoc.c
59003 +++ b/fs/ext4/mballoc.c
59004 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59005 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59006
59007 if (EXT4_SB(sb)->s_mb_stats)
59008 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59009 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59010
59011 break;
59012 }
59013 @@ -2189,7 +2189,7 @@ repeat:
59014 ac->ac_status = AC_STATUS_CONTINUE;
59015 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59016 cr = 3;
59017 - atomic_inc(&sbi->s_mb_lost_chunks);
59018 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59019 goto repeat;
59020 }
59021 }
59022 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59023 if (sbi->s_mb_stats) {
59024 ext4_msg(sb, KERN_INFO,
59025 "mballoc: %u blocks %u reqs (%u success)",
59026 - atomic_read(&sbi->s_bal_allocated),
59027 - atomic_read(&sbi->s_bal_reqs),
59028 - atomic_read(&sbi->s_bal_success));
59029 + atomic_read_unchecked(&sbi->s_bal_allocated),
59030 + atomic_read_unchecked(&sbi->s_bal_reqs),
59031 + atomic_read_unchecked(&sbi->s_bal_success));
59032 ext4_msg(sb, KERN_INFO,
59033 "mballoc: %u extents scanned, %u goal hits, "
59034 "%u 2^N hits, %u breaks, %u lost",
59035 - atomic_read(&sbi->s_bal_ex_scanned),
59036 - atomic_read(&sbi->s_bal_goals),
59037 - atomic_read(&sbi->s_bal_2orders),
59038 - atomic_read(&sbi->s_bal_breaks),
59039 - atomic_read(&sbi->s_mb_lost_chunks));
59040 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59041 + atomic_read_unchecked(&sbi->s_bal_goals),
59042 + atomic_read_unchecked(&sbi->s_bal_2orders),
59043 + atomic_read_unchecked(&sbi->s_bal_breaks),
59044 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59045 ext4_msg(sb, KERN_INFO,
59046 "mballoc: %lu generated and it took %Lu",
59047 sbi->s_mb_buddies_generated,
59048 sbi->s_mb_generation_time);
59049 ext4_msg(sb, KERN_INFO,
59050 "mballoc: %u preallocated, %u discarded",
59051 - atomic_read(&sbi->s_mb_preallocated),
59052 - atomic_read(&sbi->s_mb_discarded));
59053 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59054 + atomic_read_unchecked(&sbi->s_mb_discarded));
59055 }
59056
59057 free_percpu(sbi->s_locality_groups);
59058 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59059 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59060
59061 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59062 - atomic_inc(&sbi->s_bal_reqs);
59063 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59064 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59065 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59066 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59067 - atomic_inc(&sbi->s_bal_success);
59068 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59069 + atomic_inc_unchecked(&sbi->s_bal_success);
59070 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59071 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59072 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59073 - atomic_inc(&sbi->s_bal_goals);
59074 + atomic_inc_unchecked(&sbi->s_bal_goals);
59075 if (ac->ac_found > sbi->s_mb_max_to_scan)
59076 - atomic_inc(&sbi->s_bal_breaks);
59077 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59078 }
59079
59080 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59081 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59082 trace_ext4_mb_new_inode_pa(ac, pa);
59083
59084 ext4_mb_use_inode_pa(ac, pa);
59085 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59086 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59087
59088 ei = EXT4_I(ac->ac_inode);
59089 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59090 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59091 trace_ext4_mb_new_group_pa(ac, pa);
59092
59093 ext4_mb_use_group_pa(ac, pa);
59094 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59095 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59096
59097 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59098 lg = ac->ac_lg;
59099 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59100 * from the bitmap and continue.
59101 */
59102 }
59103 - atomic_add(free, &sbi->s_mb_discarded);
59104 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59105
59106 return err;
59107 }
59108 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59109 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59110 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59111 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59112 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59113 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59114 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59115
59116 return 0;
59117 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59118 index 04434ad..6404663 100644
59119 --- a/fs/ext4/mmp.c
59120 +++ b/fs/ext4/mmp.c
59121 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59122 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59123 const char *function, unsigned int line, const char *msg)
59124 {
59125 - __ext4_warning(sb, function, line, msg);
59126 + __ext4_warning(sb, function, line, "%s", msg);
59127 __ext4_warning(sb, function, line,
59128 "MMP failure info: last update time: %llu, last update "
59129 "node: %s, last update device: %s\n",
59130 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59131 index 710fed2..a82e4e8 100644
59132 --- a/fs/ext4/super.c
59133 +++ b/fs/ext4/super.c
59134 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59135 }
59136
59137 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59138 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59139 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59140 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59141
59142 #ifdef CONFIG_QUOTA
59143 @@ -2450,7 +2450,7 @@ struct ext4_attr {
59144 int offset;
59145 int deprecated_val;
59146 } u;
59147 -};
59148 +} __do_const;
59149
59150 static int parse_strtoull(const char *buf,
59151 unsigned long long max, unsigned long long *value)
59152 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59153 index 1423c48..9c0c6dc 100644
59154 --- a/fs/ext4/xattr.c
59155 +++ b/fs/ext4/xattr.c
59156 @@ -381,7 +381,7 @@ static int
59157 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59158 char *buffer, size_t buffer_size)
59159 {
59160 - size_t rest = buffer_size;
59161 + size_t rest = buffer_size, total_size = 0;
59162
59163 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59164 const struct xattr_handler *handler =
59165 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59166 buffer += size;
59167 }
59168 rest -= size;
59169 + total_size += size;
59170 }
59171 }
59172 - return buffer_size - rest;
59173 + return total_size;
59174 }
59175
59176 static int
59177 diff --git a/fs/fcntl.c b/fs/fcntl.c
59178 index ef68665..5deacdc 100644
59179 --- a/fs/fcntl.c
59180 +++ b/fs/fcntl.c
59181 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59182 if (err)
59183 return err;
59184
59185 + if (gr_handle_chroot_fowner(pid, type))
59186 + return -ENOENT;
59187 + if (gr_check_protected_task_fowner(pid, type))
59188 + return -EACCES;
59189 +
59190 f_modown(filp, pid, type, force);
59191 return 0;
59192 }
59193 diff --git a/fs/fhandle.c b/fs/fhandle.c
59194 index 999ff5c..41f4109 100644
59195 --- a/fs/fhandle.c
59196 +++ b/fs/fhandle.c
59197 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59198 } else
59199 retval = 0;
59200 /* copy the mount id */
59201 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59202 - sizeof(*mnt_id)) ||
59203 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59204 copy_to_user(ufh, handle,
59205 sizeof(struct file_handle) + handle_bytes))
59206 retval = -EFAULT;
59207 diff --git a/fs/file.c b/fs/file.c
59208 index 9de2026..8e334ca 100644
59209 --- a/fs/file.c
59210 +++ b/fs/file.c
59211 @@ -16,6 +16,7 @@
59212 #include <linux/slab.h>
59213 #include <linux/vmalloc.h>
59214 #include <linux/file.h>
59215 +#include <linux/security.h>
59216 #include <linux/fdtable.h>
59217 #include <linux/bitops.h>
59218 #include <linux/interrupt.h>
59219 @@ -141,7 +142,7 @@ out:
59220 * Return <0 error code on error; 1 on successful completion.
59221 * The files->file_lock should be held on entry, and will be held on exit.
59222 */
59223 -static int expand_fdtable(struct files_struct *files, int nr)
59224 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59225 __releases(files->file_lock)
59226 __acquires(files->file_lock)
59227 {
59228 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59229 * expanded and execution may have blocked.
59230 * The files->file_lock should be held on entry, and will be held on exit.
59231 */
59232 -static int expand_files(struct files_struct *files, int nr)
59233 +static int expand_files(struct files_struct *files, unsigned int nr)
59234 {
59235 struct fdtable *fdt;
59236
59237 @@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59238 if (!file)
59239 return __close_fd(files, fd);
59240
59241 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59242 if (fd >= rlimit(RLIMIT_NOFILE))
59243 return -EBADF;
59244
59245 @@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59246 if (unlikely(oldfd == newfd))
59247 return -EINVAL;
59248
59249 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59250 if (newfd >= rlimit(RLIMIT_NOFILE))
59251 return -EBADF;
59252
59253 @@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59254 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59255 {
59256 int err;
59257 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59258 if (from >= rlimit(RLIMIT_NOFILE))
59259 return -EINVAL;
59260 err = alloc_fd(from, flags);
59261 diff --git a/fs/filesystems.c b/fs/filesystems.c
59262 index 92567d9..fcd8cbf 100644
59263 --- a/fs/filesystems.c
59264 +++ b/fs/filesystems.c
59265 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59266 int len = dot ? dot - name : strlen(name);
59267
59268 fs = __get_fs_type(name, len);
59269 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
59270 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59271 +#else
59272 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59273 +#endif
59274 fs = __get_fs_type(name, len);
59275
59276 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59277 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59278 index 7dca743..543d620 100644
59279 --- a/fs/fs_struct.c
59280 +++ b/fs/fs_struct.c
59281 @@ -4,6 +4,7 @@
59282 #include <linux/path.h>
59283 #include <linux/slab.h>
59284 #include <linux/fs_struct.h>
59285 +#include <linux/grsecurity.h>
59286 #include "internal.h"
59287
59288 /*
59289 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59290 write_seqcount_begin(&fs->seq);
59291 old_root = fs->root;
59292 fs->root = *path;
59293 + gr_set_chroot_entries(current, path);
59294 write_seqcount_end(&fs->seq);
59295 spin_unlock(&fs->lock);
59296 if (old_root.dentry)
59297 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59298 int hits = 0;
59299 spin_lock(&fs->lock);
59300 write_seqcount_begin(&fs->seq);
59301 + /* this root replacement is only done by pivot_root,
59302 + leave grsec's chroot tagging alone for this task
59303 + so that a pivoted root isn't treated as a chroot
59304 + */
59305 hits += replace_path(&fs->root, old_root, new_root);
59306 hits += replace_path(&fs->pwd, old_root, new_root);
59307 write_seqcount_end(&fs->seq);
59308 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59309 task_lock(tsk);
59310 spin_lock(&fs->lock);
59311 tsk->fs = NULL;
59312 - kill = !--fs->users;
59313 + gr_clear_chroot_entries(tsk);
59314 + kill = !atomic_dec_return(&fs->users);
59315 spin_unlock(&fs->lock);
59316 task_unlock(tsk);
59317 if (kill)
59318 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59319 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59320 /* We don't need to lock fs - think why ;-) */
59321 if (fs) {
59322 - fs->users = 1;
59323 + atomic_set(&fs->users, 1);
59324 fs->in_exec = 0;
59325 spin_lock_init(&fs->lock);
59326 seqcount_init(&fs->seq);
59327 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59328 spin_lock(&old->lock);
59329 fs->root = old->root;
59330 path_get(&fs->root);
59331 + /* instead of calling gr_set_chroot_entries here,
59332 + we call it from every caller of this function
59333 + */
59334 fs->pwd = old->pwd;
59335 path_get(&fs->pwd);
59336 spin_unlock(&old->lock);
59337 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59338
59339 task_lock(current);
59340 spin_lock(&fs->lock);
59341 - kill = !--fs->users;
59342 + kill = !atomic_dec_return(&fs->users);
59343 current->fs = new_fs;
59344 + gr_set_chroot_entries(current, &new_fs->root);
59345 spin_unlock(&fs->lock);
59346 task_unlock(current);
59347
59348 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59349
59350 int current_umask(void)
59351 {
59352 - return current->fs->umask;
59353 + return current->fs->umask | gr_acl_umask();
59354 }
59355 EXPORT_SYMBOL(current_umask);
59356
59357 /* to be mentioned only in INIT_TASK */
59358 struct fs_struct init_fs = {
59359 - .users = 1,
59360 + .users = ATOMIC_INIT(1),
59361 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59362 .seq = SEQCNT_ZERO(init_fs.seq),
59363 .umask = 0022,
59364 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59365 index 29d7feb..303644d 100644
59366 --- a/fs/fscache/cookie.c
59367 +++ b/fs/fscache/cookie.c
59368 @@ -19,7 +19,7 @@
59369
59370 struct kmem_cache *fscache_cookie_jar;
59371
59372 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59373 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59374
59375 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59376 static int fscache_alloc_object(struct fscache_cache *cache,
59377 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59378 parent ? (char *) parent->def->name : "<no-parent>",
59379 def->name, netfs_data, enable);
59380
59381 - fscache_stat(&fscache_n_acquires);
59382 + fscache_stat_unchecked(&fscache_n_acquires);
59383
59384 /* if there's no parent cookie, then we don't create one here either */
59385 if (!parent) {
59386 - fscache_stat(&fscache_n_acquires_null);
59387 + fscache_stat_unchecked(&fscache_n_acquires_null);
59388 _leave(" [no parent]");
59389 return NULL;
59390 }
59391 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59392 /* allocate and initialise a cookie */
59393 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59394 if (!cookie) {
59395 - fscache_stat(&fscache_n_acquires_oom);
59396 + fscache_stat_unchecked(&fscache_n_acquires_oom);
59397 _leave(" [ENOMEM]");
59398 return NULL;
59399 }
59400 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59401
59402 switch (cookie->def->type) {
59403 case FSCACHE_COOKIE_TYPE_INDEX:
59404 - fscache_stat(&fscache_n_cookie_index);
59405 + fscache_stat_unchecked(&fscache_n_cookie_index);
59406 break;
59407 case FSCACHE_COOKIE_TYPE_DATAFILE:
59408 - fscache_stat(&fscache_n_cookie_data);
59409 + fscache_stat_unchecked(&fscache_n_cookie_data);
59410 break;
59411 default:
59412 - fscache_stat(&fscache_n_cookie_special);
59413 + fscache_stat_unchecked(&fscache_n_cookie_special);
59414 break;
59415 }
59416
59417 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59418 } else {
59419 atomic_dec(&parent->n_children);
59420 __fscache_cookie_put(cookie);
59421 - fscache_stat(&fscache_n_acquires_nobufs);
59422 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59423 _leave(" = NULL");
59424 return NULL;
59425 }
59426 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59427 }
59428 }
59429
59430 - fscache_stat(&fscache_n_acquires_ok);
59431 + fscache_stat_unchecked(&fscache_n_acquires_ok);
59432 _leave(" = %p", cookie);
59433 return cookie;
59434 }
59435 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59436 cache = fscache_select_cache_for_object(cookie->parent);
59437 if (!cache) {
59438 up_read(&fscache_addremove_sem);
59439 - fscache_stat(&fscache_n_acquires_no_cache);
59440 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59441 _leave(" = -ENOMEDIUM [no cache]");
59442 return -ENOMEDIUM;
59443 }
59444 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59445 object = cache->ops->alloc_object(cache, cookie);
59446 fscache_stat_d(&fscache_n_cop_alloc_object);
59447 if (IS_ERR(object)) {
59448 - fscache_stat(&fscache_n_object_no_alloc);
59449 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
59450 ret = PTR_ERR(object);
59451 goto error;
59452 }
59453
59454 - fscache_stat(&fscache_n_object_alloc);
59455 + fscache_stat_unchecked(&fscache_n_object_alloc);
59456
59457 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59458 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59459
59460 _debug("ALLOC OBJ%x: %s {%lx}",
59461 object->debug_id, cookie->def->name, object->events);
59462 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59463
59464 _enter("{%s}", cookie->def->name);
59465
59466 - fscache_stat(&fscache_n_invalidates);
59467 + fscache_stat_unchecked(&fscache_n_invalidates);
59468
59469 /* Only permit invalidation of data files. Invalidating an index will
59470 * require the caller to release all its attachments to the tree rooted
59471 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59472 {
59473 struct fscache_object *object;
59474
59475 - fscache_stat(&fscache_n_updates);
59476 + fscache_stat_unchecked(&fscache_n_updates);
59477
59478 if (!cookie) {
59479 - fscache_stat(&fscache_n_updates_null);
59480 + fscache_stat_unchecked(&fscache_n_updates_null);
59481 _leave(" [no cookie]");
59482 return;
59483 }
59484 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59485 */
59486 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59487 {
59488 - fscache_stat(&fscache_n_relinquishes);
59489 + fscache_stat_unchecked(&fscache_n_relinquishes);
59490 if (retire)
59491 - fscache_stat(&fscache_n_relinquishes_retire);
59492 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59493
59494 if (!cookie) {
59495 - fscache_stat(&fscache_n_relinquishes_null);
59496 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
59497 _leave(" [no cookie]");
59498 return;
59499 }
59500 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59501 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59502 goto inconsistent;
59503
59504 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59505 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59506
59507 __fscache_use_cookie(cookie);
59508 if (fscache_submit_op(object, op) < 0)
59509 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59510 index 4226f66..0fb3f45 100644
59511 --- a/fs/fscache/internal.h
59512 +++ b/fs/fscache/internal.h
59513 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59514 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59515 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59516 struct fscache_operation *,
59517 - atomic_t *,
59518 - atomic_t *,
59519 + atomic_unchecked_t *,
59520 + atomic_unchecked_t *,
59521 void (*)(struct fscache_operation *));
59522 extern void fscache_invalidate_writes(struct fscache_cookie *);
59523
59524 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59525 * stats.c
59526 */
59527 #ifdef CONFIG_FSCACHE_STATS
59528 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59529 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59530 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59531 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59532
59533 -extern atomic_t fscache_n_op_pend;
59534 -extern atomic_t fscache_n_op_run;
59535 -extern atomic_t fscache_n_op_enqueue;
59536 -extern atomic_t fscache_n_op_deferred_release;
59537 -extern atomic_t fscache_n_op_release;
59538 -extern atomic_t fscache_n_op_gc;
59539 -extern atomic_t fscache_n_op_cancelled;
59540 -extern atomic_t fscache_n_op_rejected;
59541 +extern atomic_unchecked_t fscache_n_op_pend;
59542 +extern atomic_unchecked_t fscache_n_op_run;
59543 +extern atomic_unchecked_t fscache_n_op_enqueue;
59544 +extern atomic_unchecked_t fscache_n_op_deferred_release;
59545 +extern atomic_unchecked_t fscache_n_op_release;
59546 +extern atomic_unchecked_t fscache_n_op_gc;
59547 +extern atomic_unchecked_t fscache_n_op_cancelled;
59548 +extern atomic_unchecked_t fscache_n_op_rejected;
59549
59550 -extern atomic_t fscache_n_attr_changed;
59551 -extern atomic_t fscache_n_attr_changed_ok;
59552 -extern atomic_t fscache_n_attr_changed_nobufs;
59553 -extern atomic_t fscache_n_attr_changed_nomem;
59554 -extern atomic_t fscache_n_attr_changed_calls;
59555 +extern atomic_unchecked_t fscache_n_attr_changed;
59556 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
59557 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59558 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59559 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
59560
59561 -extern atomic_t fscache_n_allocs;
59562 -extern atomic_t fscache_n_allocs_ok;
59563 -extern atomic_t fscache_n_allocs_wait;
59564 -extern atomic_t fscache_n_allocs_nobufs;
59565 -extern atomic_t fscache_n_allocs_intr;
59566 -extern atomic_t fscache_n_allocs_object_dead;
59567 -extern atomic_t fscache_n_alloc_ops;
59568 -extern atomic_t fscache_n_alloc_op_waits;
59569 +extern atomic_unchecked_t fscache_n_allocs;
59570 +extern atomic_unchecked_t fscache_n_allocs_ok;
59571 +extern atomic_unchecked_t fscache_n_allocs_wait;
59572 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
59573 +extern atomic_unchecked_t fscache_n_allocs_intr;
59574 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
59575 +extern atomic_unchecked_t fscache_n_alloc_ops;
59576 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
59577
59578 -extern atomic_t fscache_n_retrievals;
59579 -extern atomic_t fscache_n_retrievals_ok;
59580 -extern atomic_t fscache_n_retrievals_wait;
59581 -extern atomic_t fscache_n_retrievals_nodata;
59582 -extern atomic_t fscache_n_retrievals_nobufs;
59583 -extern atomic_t fscache_n_retrievals_intr;
59584 -extern atomic_t fscache_n_retrievals_nomem;
59585 -extern atomic_t fscache_n_retrievals_object_dead;
59586 -extern atomic_t fscache_n_retrieval_ops;
59587 -extern atomic_t fscache_n_retrieval_op_waits;
59588 +extern atomic_unchecked_t fscache_n_retrievals;
59589 +extern atomic_unchecked_t fscache_n_retrievals_ok;
59590 +extern atomic_unchecked_t fscache_n_retrievals_wait;
59591 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
59592 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59593 +extern atomic_unchecked_t fscache_n_retrievals_intr;
59594 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
59595 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59596 +extern atomic_unchecked_t fscache_n_retrieval_ops;
59597 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59598
59599 -extern atomic_t fscache_n_stores;
59600 -extern atomic_t fscache_n_stores_ok;
59601 -extern atomic_t fscache_n_stores_again;
59602 -extern atomic_t fscache_n_stores_nobufs;
59603 -extern atomic_t fscache_n_stores_oom;
59604 -extern atomic_t fscache_n_store_ops;
59605 -extern atomic_t fscache_n_store_calls;
59606 -extern atomic_t fscache_n_store_pages;
59607 -extern atomic_t fscache_n_store_radix_deletes;
59608 -extern atomic_t fscache_n_store_pages_over_limit;
59609 +extern atomic_unchecked_t fscache_n_stores;
59610 +extern atomic_unchecked_t fscache_n_stores_ok;
59611 +extern atomic_unchecked_t fscache_n_stores_again;
59612 +extern atomic_unchecked_t fscache_n_stores_nobufs;
59613 +extern atomic_unchecked_t fscache_n_stores_oom;
59614 +extern atomic_unchecked_t fscache_n_store_ops;
59615 +extern atomic_unchecked_t fscache_n_store_calls;
59616 +extern atomic_unchecked_t fscache_n_store_pages;
59617 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
59618 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59619
59620 -extern atomic_t fscache_n_store_vmscan_not_storing;
59621 -extern atomic_t fscache_n_store_vmscan_gone;
59622 -extern atomic_t fscache_n_store_vmscan_busy;
59623 -extern atomic_t fscache_n_store_vmscan_cancelled;
59624 -extern atomic_t fscache_n_store_vmscan_wait;
59625 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59626 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59627 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59628 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59629 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59630
59631 -extern atomic_t fscache_n_marks;
59632 -extern atomic_t fscache_n_uncaches;
59633 +extern atomic_unchecked_t fscache_n_marks;
59634 +extern atomic_unchecked_t fscache_n_uncaches;
59635
59636 -extern atomic_t fscache_n_acquires;
59637 -extern atomic_t fscache_n_acquires_null;
59638 -extern atomic_t fscache_n_acquires_no_cache;
59639 -extern atomic_t fscache_n_acquires_ok;
59640 -extern atomic_t fscache_n_acquires_nobufs;
59641 -extern atomic_t fscache_n_acquires_oom;
59642 +extern atomic_unchecked_t fscache_n_acquires;
59643 +extern atomic_unchecked_t fscache_n_acquires_null;
59644 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
59645 +extern atomic_unchecked_t fscache_n_acquires_ok;
59646 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
59647 +extern atomic_unchecked_t fscache_n_acquires_oom;
59648
59649 -extern atomic_t fscache_n_invalidates;
59650 -extern atomic_t fscache_n_invalidates_run;
59651 +extern atomic_unchecked_t fscache_n_invalidates;
59652 +extern atomic_unchecked_t fscache_n_invalidates_run;
59653
59654 -extern atomic_t fscache_n_updates;
59655 -extern atomic_t fscache_n_updates_null;
59656 -extern atomic_t fscache_n_updates_run;
59657 +extern atomic_unchecked_t fscache_n_updates;
59658 +extern atomic_unchecked_t fscache_n_updates_null;
59659 +extern atomic_unchecked_t fscache_n_updates_run;
59660
59661 -extern atomic_t fscache_n_relinquishes;
59662 -extern atomic_t fscache_n_relinquishes_null;
59663 -extern atomic_t fscache_n_relinquishes_waitcrt;
59664 -extern atomic_t fscache_n_relinquishes_retire;
59665 +extern atomic_unchecked_t fscache_n_relinquishes;
59666 +extern atomic_unchecked_t fscache_n_relinquishes_null;
59667 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59668 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
59669
59670 -extern atomic_t fscache_n_cookie_index;
59671 -extern atomic_t fscache_n_cookie_data;
59672 -extern atomic_t fscache_n_cookie_special;
59673 +extern atomic_unchecked_t fscache_n_cookie_index;
59674 +extern atomic_unchecked_t fscache_n_cookie_data;
59675 +extern atomic_unchecked_t fscache_n_cookie_special;
59676
59677 -extern atomic_t fscache_n_object_alloc;
59678 -extern atomic_t fscache_n_object_no_alloc;
59679 -extern atomic_t fscache_n_object_lookups;
59680 -extern atomic_t fscache_n_object_lookups_negative;
59681 -extern atomic_t fscache_n_object_lookups_positive;
59682 -extern atomic_t fscache_n_object_lookups_timed_out;
59683 -extern atomic_t fscache_n_object_created;
59684 -extern atomic_t fscache_n_object_avail;
59685 -extern atomic_t fscache_n_object_dead;
59686 +extern atomic_unchecked_t fscache_n_object_alloc;
59687 +extern atomic_unchecked_t fscache_n_object_no_alloc;
59688 +extern atomic_unchecked_t fscache_n_object_lookups;
59689 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
59690 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
59691 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59692 +extern atomic_unchecked_t fscache_n_object_created;
59693 +extern atomic_unchecked_t fscache_n_object_avail;
59694 +extern atomic_unchecked_t fscache_n_object_dead;
59695
59696 -extern atomic_t fscache_n_checkaux_none;
59697 -extern atomic_t fscache_n_checkaux_okay;
59698 -extern atomic_t fscache_n_checkaux_update;
59699 -extern atomic_t fscache_n_checkaux_obsolete;
59700 +extern atomic_unchecked_t fscache_n_checkaux_none;
59701 +extern atomic_unchecked_t fscache_n_checkaux_okay;
59702 +extern atomic_unchecked_t fscache_n_checkaux_update;
59703 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59704
59705 extern atomic_t fscache_n_cop_alloc_object;
59706 extern atomic_t fscache_n_cop_lookup_object;
59707 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59708 atomic_inc(stat);
59709 }
59710
59711 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59712 +{
59713 + atomic_inc_unchecked(stat);
59714 +}
59715 +
59716 static inline void fscache_stat_d(atomic_t *stat)
59717 {
59718 atomic_dec(stat);
59719 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59720
59721 #define __fscache_stat(stat) (NULL)
59722 #define fscache_stat(stat) do {} while (0)
59723 +#define fscache_stat_unchecked(stat) do {} while (0)
59724 #define fscache_stat_d(stat) do {} while (0)
59725 #endif
59726
59727 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59728 index 53d35c5..5d68ed4 100644
59729 --- a/fs/fscache/object.c
59730 +++ b/fs/fscache/object.c
59731 @@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59732 _debug("LOOKUP \"%s\" in \"%s\"",
59733 cookie->def->name, object->cache->tag->name);
59734
59735 - fscache_stat(&fscache_n_object_lookups);
59736 + fscache_stat_unchecked(&fscache_n_object_lookups);
59737 fscache_stat(&fscache_n_cop_lookup_object);
59738 ret = object->cache->ops->lookup_object(object);
59739 fscache_stat_d(&fscache_n_cop_lookup_object);
59740 @@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59741 if (ret == -ETIMEDOUT) {
59742 /* probably stuck behind another object, so move this one to
59743 * the back of the queue */
59744 - fscache_stat(&fscache_n_object_lookups_timed_out);
59745 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59746 _leave(" [timeout]");
59747 return NO_TRANSIT;
59748 }
59749 @@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59750 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59751
59752 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59753 - fscache_stat(&fscache_n_object_lookups_negative);
59754 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59755
59756 /* Allow write requests to begin stacking up and read requests to begin
59757 * returning ENODATA.
59758 @@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
59759 /* if we were still looking up, then we must have a positive lookup
59760 * result, in which case there may be data available */
59761 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59762 - fscache_stat(&fscache_n_object_lookups_positive);
59763 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59764
59765 /* We do (presumably) have data */
59766 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59767 @@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
59768 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59769 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59770 } else {
59771 - fscache_stat(&fscache_n_object_created);
59772 + fscache_stat_unchecked(&fscache_n_object_created);
59773 }
59774
59775 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59776 @@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59777 fscache_stat_d(&fscache_n_cop_lookup_complete);
59778
59779 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59780 - fscache_stat(&fscache_n_object_avail);
59781 + fscache_stat_unchecked(&fscache_n_object_avail);
59782
59783 _leave("");
59784 return transit_to(JUMPSTART_DEPS);
59785 @@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59786
59787 /* this just shifts the object release to the work processor */
59788 fscache_put_object(object);
59789 - fscache_stat(&fscache_n_object_dead);
59790 + fscache_stat_unchecked(&fscache_n_object_dead);
59791
59792 _leave("");
59793 return transit_to(OBJECT_DEAD);
59794 @@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59795 enum fscache_checkaux result;
59796
59797 if (!object->cookie->def->check_aux) {
59798 - fscache_stat(&fscache_n_checkaux_none);
59799 + fscache_stat_unchecked(&fscache_n_checkaux_none);
59800 return FSCACHE_CHECKAUX_OKAY;
59801 }
59802
59803 @@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59804 switch (result) {
59805 /* entry okay as is */
59806 case FSCACHE_CHECKAUX_OKAY:
59807 - fscache_stat(&fscache_n_checkaux_okay);
59808 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
59809 break;
59810
59811 /* entry requires update */
59812 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
59813 - fscache_stat(&fscache_n_checkaux_update);
59814 + fscache_stat_unchecked(&fscache_n_checkaux_update);
59815 break;
59816
59817 /* entry requires deletion */
59818 case FSCACHE_CHECKAUX_OBSOLETE:
59819 - fscache_stat(&fscache_n_checkaux_obsolete);
59820 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
59821 break;
59822
59823 default:
59824 @@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
59825 {
59826 const struct fscache_state *s;
59827
59828 - fscache_stat(&fscache_n_invalidates_run);
59829 + fscache_stat_unchecked(&fscache_n_invalidates_run);
59830 fscache_stat(&fscache_n_cop_invalidate_object);
59831 s = _fscache_invalidate_object(object, event);
59832 fscache_stat_d(&fscache_n_cop_invalidate_object);
59833 @@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
59834 {
59835 _enter("{OBJ%x},%d", object->debug_id, event);
59836
59837 - fscache_stat(&fscache_n_updates_run);
59838 + fscache_stat_unchecked(&fscache_n_updates_run);
59839 fscache_stat(&fscache_n_cop_update_object);
59840 object->cache->ops->update_object(object);
59841 fscache_stat_d(&fscache_n_cop_update_object);
59842 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
59843 index 318071a..379938b 100644
59844 --- a/fs/fscache/operation.c
59845 +++ b/fs/fscache/operation.c
59846 @@ -17,7 +17,7 @@
59847 #include <linux/slab.h>
59848 #include "internal.h"
59849
59850 -atomic_t fscache_op_debug_id;
59851 +atomic_unchecked_t fscache_op_debug_id;
59852 EXPORT_SYMBOL(fscache_op_debug_id);
59853
59854 /**
59855 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
59856 ASSERTCMP(atomic_read(&op->usage), >, 0);
59857 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
59858
59859 - fscache_stat(&fscache_n_op_enqueue);
59860 + fscache_stat_unchecked(&fscache_n_op_enqueue);
59861 switch (op->flags & FSCACHE_OP_TYPE) {
59862 case FSCACHE_OP_ASYNC:
59863 _debug("queue async");
59864 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59865 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59866 if (op->processor)
59867 fscache_enqueue_operation(op);
59868 - fscache_stat(&fscache_n_op_run);
59869 + fscache_stat_unchecked(&fscache_n_op_run);
59870 }
59871
59872 /*
59873 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59874 if (object->n_in_progress > 0) {
59875 atomic_inc(&op->usage);
59876 list_add_tail(&op->pend_link, &object->pending_ops);
59877 - fscache_stat(&fscache_n_op_pend);
59878 + fscache_stat_unchecked(&fscache_n_op_pend);
59879 } else if (!list_empty(&object->pending_ops)) {
59880 atomic_inc(&op->usage);
59881 list_add_tail(&op->pend_link, &object->pending_ops);
59882 - fscache_stat(&fscache_n_op_pend);
59883 + fscache_stat_unchecked(&fscache_n_op_pend);
59884 fscache_start_operations(object);
59885 } else {
59886 ASSERTCMP(object->n_in_progress, ==, 0);
59887 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59888 object->n_exclusive++; /* reads and writes must wait */
59889 atomic_inc(&op->usage);
59890 list_add_tail(&op->pend_link, &object->pending_ops);
59891 - fscache_stat(&fscache_n_op_pend);
59892 + fscache_stat_unchecked(&fscache_n_op_pend);
59893 ret = 0;
59894 } else {
59895 /* If we're in any other state, there must have been an I/O
59896 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59897 if (object->n_exclusive > 0) {
59898 atomic_inc(&op->usage);
59899 list_add_tail(&op->pend_link, &object->pending_ops);
59900 - fscache_stat(&fscache_n_op_pend);
59901 + fscache_stat_unchecked(&fscache_n_op_pend);
59902 } else if (!list_empty(&object->pending_ops)) {
59903 atomic_inc(&op->usage);
59904 list_add_tail(&op->pend_link, &object->pending_ops);
59905 - fscache_stat(&fscache_n_op_pend);
59906 + fscache_stat_unchecked(&fscache_n_op_pend);
59907 fscache_start_operations(object);
59908 } else {
59909 ASSERTCMP(object->n_exclusive, ==, 0);
59910 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59911 object->n_ops++;
59912 atomic_inc(&op->usage);
59913 list_add_tail(&op->pend_link, &object->pending_ops);
59914 - fscache_stat(&fscache_n_op_pend);
59915 + fscache_stat_unchecked(&fscache_n_op_pend);
59916 ret = 0;
59917 } else if (fscache_object_is_dying(object)) {
59918 - fscache_stat(&fscache_n_op_rejected);
59919 + fscache_stat_unchecked(&fscache_n_op_rejected);
59920 op->state = FSCACHE_OP_ST_CANCELLED;
59921 ret = -ENOBUFS;
59922 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59923 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59924 ret = -EBUSY;
59925 if (op->state == FSCACHE_OP_ST_PENDING) {
59926 ASSERT(!list_empty(&op->pend_link));
59927 - fscache_stat(&fscache_n_op_cancelled);
59928 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59929 list_del_init(&op->pend_link);
59930 if (do_cancel)
59931 do_cancel(op);
59932 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
59933 while (!list_empty(&object->pending_ops)) {
59934 op = list_entry(object->pending_ops.next,
59935 struct fscache_operation, pend_link);
59936 - fscache_stat(&fscache_n_op_cancelled);
59937 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59938 list_del_init(&op->pend_link);
59939
59940 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
59941 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
59942 op->state, ==, FSCACHE_OP_ST_CANCELLED);
59943 op->state = FSCACHE_OP_ST_DEAD;
59944
59945 - fscache_stat(&fscache_n_op_release);
59946 + fscache_stat_unchecked(&fscache_n_op_release);
59947
59948 if (op->release) {
59949 op->release(op);
59950 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
59951 * lock, and defer it otherwise */
59952 if (!spin_trylock(&object->lock)) {
59953 _debug("defer put");
59954 - fscache_stat(&fscache_n_op_deferred_release);
59955 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
59956
59957 cache = object->cache;
59958 spin_lock(&cache->op_gc_list_lock);
59959 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
59960
59961 _debug("GC DEFERRED REL OBJ%x OP%x",
59962 object->debug_id, op->debug_id);
59963 - fscache_stat(&fscache_n_op_gc);
59964 + fscache_stat_unchecked(&fscache_n_op_gc);
59965
59966 ASSERTCMP(atomic_read(&op->usage), ==, 0);
59967 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
59968 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
59969 index 7f5c658..6c1e164 100644
59970 --- a/fs/fscache/page.c
59971 +++ b/fs/fscache/page.c
59972 @@ -61,7 +61,7 @@ try_again:
59973 val = radix_tree_lookup(&cookie->stores, page->index);
59974 if (!val) {
59975 rcu_read_unlock();
59976 - fscache_stat(&fscache_n_store_vmscan_not_storing);
59977 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
59978 __fscache_uncache_page(cookie, page);
59979 return true;
59980 }
59981 @@ -91,11 +91,11 @@ try_again:
59982 spin_unlock(&cookie->stores_lock);
59983
59984 if (xpage) {
59985 - fscache_stat(&fscache_n_store_vmscan_cancelled);
59986 - fscache_stat(&fscache_n_store_radix_deletes);
59987 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
59988 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59989 ASSERTCMP(xpage, ==, page);
59990 } else {
59991 - fscache_stat(&fscache_n_store_vmscan_gone);
59992 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
59993 }
59994
59995 wake_up_bit(&cookie->flags, 0);
59996 @@ -110,11 +110,11 @@ page_busy:
59997 * sleeping on memory allocation, so we may need to impose a timeout
59998 * too. */
59999 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60000 - fscache_stat(&fscache_n_store_vmscan_busy);
60001 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60002 return false;
60003 }
60004
60005 - fscache_stat(&fscache_n_store_vmscan_wait);
60006 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60007 __fscache_wait_on_page_write(cookie, page);
60008 gfp &= ~__GFP_WAIT;
60009 goto try_again;
60010 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60011 FSCACHE_COOKIE_STORING_TAG);
60012 if (!radix_tree_tag_get(&cookie->stores, page->index,
60013 FSCACHE_COOKIE_PENDING_TAG)) {
60014 - fscache_stat(&fscache_n_store_radix_deletes);
60015 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60016 xpage = radix_tree_delete(&cookie->stores, page->index);
60017 }
60018 spin_unlock(&cookie->stores_lock);
60019 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60020
60021 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60022
60023 - fscache_stat(&fscache_n_attr_changed_calls);
60024 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60025
60026 if (fscache_object_is_active(object)) {
60027 fscache_stat(&fscache_n_cop_attr_changed);
60028 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60029
60030 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60031
60032 - fscache_stat(&fscache_n_attr_changed);
60033 + fscache_stat_unchecked(&fscache_n_attr_changed);
60034
60035 op = kzalloc(sizeof(*op), GFP_KERNEL);
60036 if (!op) {
60037 - fscache_stat(&fscache_n_attr_changed_nomem);
60038 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60039 _leave(" = -ENOMEM");
60040 return -ENOMEM;
60041 }
60042 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60043 if (fscache_submit_exclusive_op(object, op) < 0)
60044 goto nobufs;
60045 spin_unlock(&cookie->lock);
60046 - fscache_stat(&fscache_n_attr_changed_ok);
60047 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60048 fscache_put_operation(op);
60049 _leave(" = 0");
60050 return 0;
60051 @@ -225,7 +225,7 @@ nobufs:
60052 kfree(op);
60053 if (wake_cookie)
60054 __fscache_wake_unused_cookie(cookie);
60055 - fscache_stat(&fscache_n_attr_changed_nobufs);
60056 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60057 _leave(" = %d", -ENOBUFS);
60058 return -ENOBUFS;
60059 }
60060 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60061 /* allocate a retrieval operation and attempt to submit it */
60062 op = kzalloc(sizeof(*op), GFP_NOIO);
60063 if (!op) {
60064 - fscache_stat(&fscache_n_retrievals_nomem);
60065 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60066 return NULL;
60067 }
60068
60069 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60070 return 0;
60071 }
60072
60073 - fscache_stat(&fscache_n_retrievals_wait);
60074 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60075
60076 jif = jiffies;
60077 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60078 fscache_wait_bit_interruptible,
60079 TASK_INTERRUPTIBLE) != 0) {
60080 - fscache_stat(&fscache_n_retrievals_intr);
60081 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60082 _leave(" = -ERESTARTSYS");
60083 return -ERESTARTSYS;
60084 }
60085 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60086 */
60087 int fscache_wait_for_operation_activation(struct fscache_object *object,
60088 struct fscache_operation *op,
60089 - atomic_t *stat_op_waits,
60090 - atomic_t *stat_object_dead,
60091 + atomic_unchecked_t *stat_op_waits,
60092 + atomic_unchecked_t *stat_object_dead,
60093 void (*do_cancel)(struct fscache_operation *))
60094 {
60095 int ret;
60096 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60097
60098 _debug(">>> WT");
60099 if (stat_op_waits)
60100 - fscache_stat(stat_op_waits);
60101 + fscache_stat_unchecked(stat_op_waits);
60102 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60103 fscache_wait_bit_interruptible,
60104 TASK_INTERRUPTIBLE) != 0) {
60105 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60106 check_if_dead:
60107 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60108 if (stat_object_dead)
60109 - fscache_stat(stat_object_dead);
60110 + fscache_stat_unchecked(stat_object_dead);
60111 _leave(" = -ENOBUFS [cancelled]");
60112 return -ENOBUFS;
60113 }
60114 @@ -366,7 +366,7 @@ check_if_dead:
60115 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60116 fscache_cancel_op(op, do_cancel);
60117 if (stat_object_dead)
60118 - fscache_stat(stat_object_dead);
60119 + fscache_stat_unchecked(stat_object_dead);
60120 return -ENOBUFS;
60121 }
60122 return 0;
60123 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60124
60125 _enter("%p,%p,,,", cookie, page);
60126
60127 - fscache_stat(&fscache_n_retrievals);
60128 + fscache_stat_unchecked(&fscache_n_retrievals);
60129
60130 if (hlist_empty(&cookie->backing_objects))
60131 goto nobufs;
60132 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60133 goto nobufs_unlock_dec;
60134 spin_unlock(&cookie->lock);
60135
60136 - fscache_stat(&fscache_n_retrieval_ops);
60137 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60138
60139 /* pin the netfs read context in case we need to do the actual netfs
60140 * read because we've encountered a cache read failure */
60141 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60142
60143 error:
60144 if (ret == -ENOMEM)
60145 - fscache_stat(&fscache_n_retrievals_nomem);
60146 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60147 else if (ret == -ERESTARTSYS)
60148 - fscache_stat(&fscache_n_retrievals_intr);
60149 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60150 else if (ret == -ENODATA)
60151 - fscache_stat(&fscache_n_retrievals_nodata);
60152 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60153 else if (ret < 0)
60154 - fscache_stat(&fscache_n_retrievals_nobufs);
60155 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60156 else
60157 - fscache_stat(&fscache_n_retrievals_ok);
60158 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60159
60160 fscache_put_retrieval(op);
60161 _leave(" = %d", ret);
60162 @@ -490,7 +490,7 @@ nobufs_unlock:
60163 __fscache_wake_unused_cookie(cookie);
60164 kfree(op);
60165 nobufs:
60166 - fscache_stat(&fscache_n_retrievals_nobufs);
60167 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60168 _leave(" = -ENOBUFS");
60169 return -ENOBUFS;
60170 }
60171 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60172
60173 _enter("%p,,%d,,,", cookie, *nr_pages);
60174
60175 - fscache_stat(&fscache_n_retrievals);
60176 + fscache_stat_unchecked(&fscache_n_retrievals);
60177
60178 if (hlist_empty(&cookie->backing_objects))
60179 goto nobufs;
60180 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60181 goto nobufs_unlock_dec;
60182 spin_unlock(&cookie->lock);
60183
60184 - fscache_stat(&fscache_n_retrieval_ops);
60185 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60186
60187 /* pin the netfs read context in case we need to do the actual netfs
60188 * read because we've encountered a cache read failure */
60189 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60190
60191 error:
60192 if (ret == -ENOMEM)
60193 - fscache_stat(&fscache_n_retrievals_nomem);
60194 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60195 else if (ret == -ERESTARTSYS)
60196 - fscache_stat(&fscache_n_retrievals_intr);
60197 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60198 else if (ret == -ENODATA)
60199 - fscache_stat(&fscache_n_retrievals_nodata);
60200 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60201 else if (ret < 0)
60202 - fscache_stat(&fscache_n_retrievals_nobufs);
60203 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60204 else
60205 - fscache_stat(&fscache_n_retrievals_ok);
60206 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60207
60208 fscache_put_retrieval(op);
60209 _leave(" = %d", ret);
60210 @@ -621,7 +621,7 @@ nobufs_unlock:
60211 if (wake_cookie)
60212 __fscache_wake_unused_cookie(cookie);
60213 nobufs:
60214 - fscache_stat(&fscache_n_retrievals_nobufs);
60215 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60216 _leave(" = -ENOBUFS");
60217 return -ENOBUFS;
60218 }
60219 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60220
60221 _enter("%p,%p,,,", cookie, page);
60222
60223 - fscache_stat(&fscache_n_allocs);
60224 + fscache_stat_unchecked(&fscache_n_allocs);
60225
60226 if (hlist_empty(&cookie->backing_objects))
60227 goto nobufs;
60228 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60229 goto nobufs_unlock_dec;
60230 spin_unlock(&cookie->lock);
60231
60232 - fscache_stat(&fscache_n_alloc_ops);
60233 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60234
60235 ret = fscache_wait_for_operation_activation(
60236 object, &op->op,
60237 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60238
60239 error:
60240 if (ret == -ERESTARTSYS)
60241 - fscache_stat(&fscache_n_allocs_intr);
60242 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60243 else if (ret < 0)
60244 - fscache_stat(&fscache_n_allocs_nobufs);
60245 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60246 else
60247 - fscache_stat(&fscache_n_allocs_ok);
60248 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60249
60250 fscache_put_retrieval(op);
60251 _leave(" = %d", ret);
60252 @@ -715,7 +715,7 @@ nobufs_unlock:
60253 if (wake_cookie)
60254 __fscache_wake_unused_cookie(cookie);
60255 nobufs:
60256 - fscache_stat(&fscache_n_allocs_nobufs);
60257 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60258 _leave(" = -ENOBUFS");
60259 return -ENOBUFS;
60260 }
60261 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60262
60263 spin_lock(&cookie->stores_lock);
60264
60265 - fscache_stat(&fscache_n_store_calls);
60266 + fscache_stat_unchecked(&fscache_n_store_calls);
60267
60268 /* find a page to store */
60269 page = NULL;
60270 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60271 page = results[0];
60272 _debug("gang %d [%lx]", n, page->index);
60273 if (page->index > op->store_limit) {
60274 - fscache_stat(&fscache_n_store_pages_over_limit);
60275 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60276 goto superseded;
60277 }
60278
60279 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60280 spin_unlock(&cookie->stores_lock);
60281 spin_unlock(&object->lock);
60282
60283 - fscache_stat(&fscache_n_store_pages);
60284 + fscache_stat_unchecked(&fscache_n_store_pages);
60285 fscache_stat(&fscache_n_cop_write_page);
60286 ret = object->cache->ops->write_page(op, page);
60287 fscache_stat_d(&fscache_n_cop_write_page);
60288 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60289 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60290 ASSERT(PageFsCache(page));
60291
60292 - fscache_stat(&fscache_n_stores);
60293 + fscache_stat_unchecked(&fscache_n_stores);
60294
60295 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60296 _leave(" = -ENOBUFS [invalidating]");
60297 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60298 spin_unlock(&cookie->stores_lock);
60299 spin_unlock(&object->lock);
60300
60301 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60302 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60303 op->store_limit = object->store_limit;
60304
60305 __fscache_use_cookie(cookie);
60306 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60307
60308 spin_unlock(&cookie->lock);
60309 radix_tree_preload_end();
60310 - fscache_stat(&fscache_n_store_ops);
60311 - fscache_stat(&fscache_n_stores_ok);
60312 + fscache_stat_unchecked(&fscache_n_store_ops);
60313 + fscache_stat_unchecked(&fscache_n_stores_ok);
60314
60315 /* the work queue now carries its own ref on the object */
60316 fscache_put_operation(&op->op);
60317 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60318 return 0;
60319
60320 already_queued:
60321 - fscache_stat(&fscache_n_stores_again);
60322 + fscache_stat_unchecked(&fscache_n_stores_again);
60323 already_pending:
60324 spin_unlock(&cookie->stores_lock);
60325 spin_unlock(&object->lock);
60326 spin_unlock(&cookie->lock);
60327 radix_tree_preload_end();
60328 kfree(op);
60329 - fscache_stat(&fscache_n_stores_ok);
60330 + fscache_stat_unchecked(&fscache_n_stores_ok);
60331 _leave(" = 0");
60332 return 0;
60333
60334 @@ -1024,14 +1024,14 @@ nobufs:
60335 kfree(op);
60336 if (wake_cookie)
60337 __fscache_wake_unused_cookie(cookie);
60338 - fscache_stat(&fscache_n_stores_nobufs);
60339 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
60340 _leave(" = -ENOBUFS");
60341 return -ENOBUFS;
60342
60343 nomem_free:
60344 kfree(op);
60345 nomem:
60346 - fscache_stat(&fscache_n_stores_oom);
60347 + fscache_stat_unchecked(&fscache_n_stores_oom);
60348 _leave(" = -ENOMEM");
60349 return -ENOMEM;
60350 }
60351 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60352 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60353 ASSERTCMP(page, !=, NULL);
60354
60355 - fscache_stat(&fscache_n_uncaches);
60356 + fscache_stat_unchecked(&fscache_n_uncaches);
60357
60358 /* cache withdrawal may beat us to it */
60359 if (!PageFsCache(page))
60360 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60361 struct fscache_cookie *cookie = op->op.object->cookie;
60362
60363 #ifdef CONFIG_FSCACHE_STATS
60364 - atomic_inc(&fscache_n_marks);
60365 + atomic_inc_unchecked(&fscache_n_marks);
60366 #endif
60367
60368 _debug("- mark %p{%lx}", page, page->index);
60369 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60370 index 40d13c7..ddf52b9 100644
60371 --- a/fs/fscache/stats.c
60372 +++ b/fs/fscache/stats.c
60373 @@ -18,99 +18,99 @@
60374 /*
60375 * operation counters
60376 */
60377 -atomic_t fscache_n_op_pend;
60378 -atomic_t fscache_n_op_run;
60379 -atomic_t fscache_n_op_enqueue;
60380 -atomic_t fscache_n_op_requeue;
60381 -atomic_t fscache_n_op_deferred_release;
60382 -atomic_t fscache_n_op_release;
60383 -atomic_t fscache_n_op_gc;
60384 -atomic_t fscache_n_op_cancelled;
60385 -atomic_t fscache_n_op_rejected;
60386 +atomic_unchecked_t fscache_n_op_pend;
60387 +atomic_unchecked_t fscache_n_op_run;
60388 +atomic_unchecked_t fscache_n_op_enqueue;
60389 +atomic_unchecked_t fscache_n_op_requeue;
60390 +atomic_unchecked_t fscache_n_op_deferred_release;
60391 +atomic_unchecked_t fscache_n_op_release;
60392 +atomic_unchecked_t fscache_n_op_gc;
60393 +atomic_unchecked_t fscache_n_op_cancelled;
60394 +atomic_unchecked_t fscache_n_op_rejected;
60395
60396 -atomic_t fscache_n_attr_changed;
60397 -atomic_t fscache_n_attr_changed_ok;
60398 -atomic_t fscache_n_attr_changed_nobufs;
60399 -atomic_t fscache_n_attr_changed_nomem;
60400 -atomic_t fscache_n_attr_changed_calls;
60401 +atomic_unchecked_t fscache_n_attr_changed;
60402 +atomic_unchecked_t fscache_n_attr_changed_ok;
60403 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
60404 +atomic_unchecked_t fscache_n_attr_changed_nomem;
60405 +atomic_unchecked_t fscache_n_attr_changed_calls;
60406
60407 -atomic_t fscache_n_allocs;
60408 -atomic_t fscache_n_allocs_ok;
60409 -atomic_t fscache_n_allocs_wait;
60410 -atomic_t fscache_n_allocs_nobufs;
60411 -atomic_t fscache_n_allocs_intr;
60412 -atomic_t fscache_n_allocs_object_dead;
60413 -atomic_t fscache_n_alloc_ops;
60414 -atomic_t fscache_n_alloc_op_waits;
60415 +atomic_unchecked_t fscache_n_allocs;
60416 +atomic_unchecked_t fscache_n_allocs_ok;
60417 +atomic_unchecked_t fscache_n_allocs_wait;
60418 +atomic_unchecked_t fscache_n_allocs_nobufs;
60419 +atomic_unchecked_t fscache_n_allocs_intr;
60420 +atomic_unchecked_t fscache_n_allocs_object_dead;
60421 +atomic_unchecked_t fscache_n_alloc_ops;
60422 +atomic_unchecked_t fscache_n_alloc_op_waits;
60423
60424 -atomic_t fscache_n_retrievals;
60425 -atomic_t fscache_n_retrievals_ok;
60426 -atomic_t fscache_n_retrievals_wait;
60427 -atomic_t fscache_n_retrievals_nodata;
60428 -atomic_t fscache_n_retrievals_nobufs;
60429 -atomic_t fscache_n_retrievals_intr;
60430 -atomic_t fscache_n_retrievals_nomem;
60431 -atomic_t fscache_n_retrievals_object_dead;
60432 -atomic_t fscache_n_retrieval_ops;
60433 -atomic_t fscache_n_retrieval_op_waits;
60434 +atomic_unchecked_t fscache_n_retrievals;
60435 +atomic_unchecked_t fscache_n_retrievals_ok;
60436 +atomic_unchecked_t fscache_n_retrievals_wait;
60437 +atomic_unchecked_t fscache_n_retrievals_nodata;
60438 +atomic_unchecked_t fscache_n_retrievals_nobufs;
60439 +atomic_unchecked_t fscache_n_retrievals_intr;
60440 +atomic_unchecked_t fscache_n_retrievals_nomem;
60441 +atomic_unchecked_t fscache_n_retrievals_object_dead;
60442 +atomic_unchecked_t fscache_n_retrieval_ops;
60443 +atomic_unchecked_t fscache_n_retrieval_op_waits;
60444
60445 -atomic_t fscache_n_stores;
60446 -atomic_t fscache_n_stores_ok;
60447 -atomic_t fscache_n_stores_again;
60448 -atomic_t fscache_n_stores_nobufs;
60449 -atomic_t fscache_n_stores_oom;
60450 -atomic_t fscache_n_store_ops;
60451 -atomic_t fscache_n_store_calls;
60452 -atomic_t fscache_n_store_pages;
60453 -atomic_t fscache_n_store_radix_deletes;
60454 -atomic_t fscache_n_store_pages_over_limit;
60455 +atomic_unchecked_t fscache_n_stores;
60456 +atomic_unchecked_t fscache_n_stores_ok;
60457 +atomic_unchecked_t fscache_n_stores_again;
60458 +atomic_unchecked_t fscache_n_stores_nobufs;
60459 +atomic_unchecked_t fscache_n_stores_oom;
60460 +atomic_unchecked_t fscache_n_store_ops;
60461 +atomic_unchecked_t fscache_n_store_calls;
60462 +atomic_unchecked_t fscache_n_store_pages;
60463 +atomic_unchecked_t fscache_n_store_radix_deletes;
60464 +atomic_unchecked_t fscache_n_store_pages_over_limit;
60465
60466 -atomic_t fscache_n_store_vmscan_not_storing;
60467 -atomic_t fscache_n_store_vmscan_gone;
60468 -atomic_t fscache_n_store_vmscan_busy;
60469 -atomic_t fscache_n_store_vmscan_cancelled;
60470 -atomic_t fscache_n_store_vmscan_wait;
60471 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60472 +atomic_unchecked_t fscache_n_store_vmscan_gone;
60473 +atomic_unchecked_t fscache_n_store_vmscan_busy;
60474 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60475 +atomic_unchecked_t fscache_n_store_vmscan_wait;
60476
60477 -atomic_t fscache_n_marks;
60478 -atomic_t fscache_n_uncaches;
60479 +atomic_unchecked_t fscache_n_marks;
60480 +atomic_unchecked_t fscache_n_uncaches;
60481
60482 -atomic_t fscache_n_acquires;
60483 -atomic_t fscache_n_acquires_null;
60484 -atomic_t fscache_n_acquires_no_cache;
60485 -atomic_t fscache_n_acquires_ok;
60486 -atomic_t fscache_n_acquires_nobufs;
60487 -atomic_t fscache_n_acquires_oom;
60488 +atomic_unchecked_t fscache_n_acquires;
60489 +atomic_unchecked_t fscache_n_acquires_null;
60490 +atomic_unchecked_t fscache_n_acquires_no_cache;
60491 +atomic_unchecked_t fscache_n_acquires_ok;
60492 +atomic_unchecked_t fscache_n_acquires_nobufs;
60493 +atomic_unchecked_t fscache_n_acquires_oom;
60494
60495 -atomic_t fscache_n_invalidates;
60496 -atomic_t fscache_n_invalidates_run;
60497 +atomic_unchecked_t fscache_n_invalidates;
60498 +atomic_unchecked_t fscache_n_invalidates_run;
60499
60500 -atomic_t fscache_n_updates;
60501 -atomic_t fscache_n_updates_null;
60502 -atomic_t fscache_n_updates_run;
60503 +atomic_unchecked_t fscache_n_updates;
60504 +atomic_unchecked_t fscache_n_updates_null;
60505 +atomic_unchecked_t fscache_n_updates_run;
60506
60507 -atomic_t fscache_n_relinquishes;
60508 -atomic_t fscache_n_relinquishes_null;
60509 -atomic_t fscache_n_relinquishes_waitcrt;
60510 -atomic_t fscache_n_relinquishes_retire;
60511 +atomic_unchecked_t fscache_n_relinquishes;
60512 +atomic_unchecked_t fscache_n_relinquishes_null;
60513 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60514 +atomic_unchecked_t fscache_n_relinquishes_retire;
60515
60516 -atomic_t fscache_n_cookie_index;
60517 -atomic_t fscache_n_cookie_data;
60518 -atomic_t fscache_n_cookie_special;
60519 +atomic_unchecked_t fscache_n_cookie_index;
60520 +atomic_unchecked_t fscache_n_cookie_data;
60521 +atomic_unchecked_t fscache_n_cookie_special;
60522
60523 -atomic_t fscache_n_object_alloc;
60524 -atomic_t fscache_n_object_no_alloc;
60525 -atomic_t fscache_n_object_lookups;
60526 -atomic_t fscache_n_object_lookups_negative;
60527 -atomic_t fscache_n_object_lookups_positive;
60528 -atomic_t fscache_n_object_lookups_timed_out;
60529 -atomic_t fscache_n_object_created;
60530 -atomic_t fscache_n_object_avail;
60531 -atomic_t fscache_n_object_dead;
60532 +atomic_unchecked_t fscache_n_object_alloc;
60533 +atomic_unchecked_t fscache_n_object_no_alloc;
60534 +atomic_unchecked_t fscache_n_object_lookups;
60535 +atomic_unchecked_t fscache_n_object_lookups_negative;
60536 +atomic_unchecked_t fscache_n_object_lookups_positive;
60537 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
60538 +atomic_unchecked_t fscache_n_object_created;
60539 +atomic_unchecked_t fscache_n_object_avail;
60540 +atomic_unchecked_t fscache_n_object_dead;
60541
60542 -atomic_t fscache_n_checkaux_none;
60543 -atomic_t fscache_n_checkaux_okay;
60544 -atomic_t fscache_n_checkaux_update;
60545 -atomic_t fscache_n_checkaux_obsolete;
60546 +atomic_unchecked_t fscache_n_checkaux_none;
60547 +atomic_unchecked_t fscache_n_checkaux_okay;
60548 +atomic_unchecked_t fscache_n_checkaux_update;
60549 +atomic_unchecked_t fscache_n_checkaux_obsolete;
60550
60551 atomic_t fscache_n_cop_alloc_object;
60552 atomic_t fscache_n_cop_lookup_object;
60553 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60554 seq_puts(m, "FS-Cache statistics\n");
60555
60556 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60557 - atomic_read(&fscache_n_cookie_index),
60558 - atomic_read(&fscache_n_cookie_data),
60559 - atomic_read(&fscache_n_cookie_special));
60560 + atomic_read_unchecked(&fscache_n_cookie_index),
60561 + atomic_read_unchecked(&fscache_n_cookie_data),
60562 + atomic_read_unchecked(&fscache_n_cookie_special));
60563
60564 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60565 - atomic_read(&fscache_n_object_alloc),
60566 - atomic_read(&fscache_n_object_no_alloc),
60567 - atomic_read(&fscache_n_object_avail),
60568 - atomic_read(&fscache_n_object_dead));
60569 + atomic_read_unchecked(&fscache_n_object_alloc),
60570 + atomic_read_unchecked(&fscache_n_object_no_alloc),
60571 + atomic_read_unchecked(&fscache_n_object_avail),
60572 + atomic_read_unchecked(&fscache_n_object_dead));
60573 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60574 - atomic_read(&fscache_n_checkaux_none),
60575 - atomic_read(&fscache_n_checkaux_okay),
60576 - atomic_read(&fscache_n_checkaux_update),
60577 - atomic_read(&fscache_n_checkaux_obsolete));
60578 + atomic_read_unchecked(&fscache_n_checkaux_none),
60579 + atomic_read_unchecked(&fscache_n_checkaux_okay),
60580 + atomic_read_unchecked(&fscache_n_checkaux_update),
60581 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60582
60583 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60584 - atomic_read(&fscache_n_marks),
60585 - atomic_read(&fscache_n_uncaches));
60586 + atomic_read_unchecked(&fscache_n_marks),
60587 + atomic_read_unchecked(&fscache_n_uncaches));
60588
60589 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60590 " oom=%u\n",
60591 - atomic_read(&fscache_n_acquires),
60592 - atomic_read(&fscache_n_acquires_null),
60593 - atomic_read(&fscache_n_acquires_no_cache),
60594 - atomic_read(&fscache_n_acquires_ok),
60595 - atomic_read(&fscache_n_acquires_nobufs),
60596 - atomic_read(&fscache_n_acquires_oom));
60597 + atomic_read_unchecked(&fscache_n_acquires),
60598 + atomic_read_unchecked(&fscache_n_acquires_null),
60599 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
60600 + atomic_read_unchecked(&fscache_n_acquires_ok),
60601 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
60602 + atomic_read_unchecked(&fscache_n_acquires_oom));
60603
60604 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60605 - atomic_read(&fscache_n_object_lookups),
60606 - atomic_read(&fscache_n_object_lookups_negative),
60607 - atomic_read(&fscache_n_object_lookups_positive),
60608 - atomic_read(&fscache_n_object_created),
60609 - atomic_read(&fscache_n_object_lookups_timed_out));
60610 + atomic_read_unchecked(&fscache_n_object_lookups),
60611 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
60612 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
60613 + atomic_read_unchecked(&fscache_n_object_created),
60614 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60615
60616 seq_printf(m, "Invals : n=%u run=%u\n",
60617 - atomic_read(&fscache_n_invalidates),
60618 - atomic_read(&fscache_n_invalidates_run));
60619 + atomic_read_unchecked(&fscache_n_invalidates),
60620 + atomic_read_unchecked(&fscache_n_invalidates_run));
60621
60622 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60623 - atomic_read(&fscache_n_updates),
60624 - atomic_read(&fscache_n_updates_null),
60625 - atomic_read(&fscache_n_updates_run));
60626 + atomic_read_unchecked(&fscache_n_updates),
60627 + atomic_read_unchecked(&fscache_n_updates_null),
60628 + atomic_read_unchecked(&fscache_n_updates_run));
60629
60630 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60631 - atomic_read(&fscache_n_relinquishes),
60632 - atomic_read(&fscache_n_relinquishes_null),
60633 - atomic_read(&fscache_n_relinquishes_waitcrt),
60634 - atomic_read(&fscache_n_relinquishes_retire));
60635 + atomic_read_unchecked(&fscache_n_relinquishes),
60636 + atomic_read_unchecked(&fscache_n_relinquishes_null),
60637 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60638 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
60639
60640 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60641 - atomic_read(&fscache_n_attr_changed),
60642 - atomic_read(&fscache_n_attr_changed_ok),
60643 - atomic_read(&fscache_n_attr_changed_nobufs),
60644 - atomic_read(&fscache_n_attr_changed_nomem),
60645 - atomic_read(&fscache_n_attr_changed_calls));
60646 + atomic_read_unchecked(&fscache_n_attr_changed),
60647 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
60648 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60649 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60650 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
60651
60652 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60653 - atomic_read(&fscache_n_allocs),
60654 - atomic_read(&fscache_n_allocs_ok),
60655 - atomic_read(&fscache_n_allocs_wait),
60656 - atomic_read(&fscache_n_allocs_nobufs),
60657 - atomic_read(&fscache_n_allocs_intr));
60658 + atomic_read_unchecked(&fscache_n_allocs),
60659 + atomic_read_unchecked(&fscache_n_allocs_ok),
60660 + atomic_read_unchecked(&fscache_n_allocs_wait),
60661 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
60662 + atomic_read_unchecked(&fscache_n_allocs_intr));
60663 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60664 - atomic_read(&fscache_n_alloc_ops),
60665 - atomic_read(&fscache_n_alloc_op_waits),
60666 - atomic_read(&fscache_n_allocs_object_dead));
60667 + atomic_read_unchecked(&fscache_n_alloc_ops),
60668 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
60669 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
60670
60671 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60672 " int=%u oom=%u\n",
60673 - atomic_read(&fscache_n_retrievals),
60674 - atomic_read(&fscache_n_retrievals_ok),
60675 - atomic_read(&fscache_n_retrievals_wait),
60676 - atomic_read(&fscache_n_retrievals_nodata),
60677 - atomic_read(&fscache_n_retrievals_nobufs),
60678 - atomic_read(&fscache_n_retrievals_intr),
60679 - atomic_read(&fscache_n_retrievals_nomem));
60680 + atomic_read_unchecked(&fscache_n_retrievals),
60681 + atomic_read_unchecked(&fscache_n_retrievals_ok),
60682 + atomic_read_unchecked(&fscache_n_retrievals_wait),
60683 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
60684 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60685 + atomic_read_unchecked(&fscache_n_retrievals_intr),
60686 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
60687 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60688 - atomic_read(&fscache_n_retrieval_ops),
60689 - atomic_read(&fscache_n_retrieval_op_waits),
60690 - atomic_read(&fscache_n_retrievals_object_dead));
60691 + atomic_read_unchecked(&fscache_n_retrieval_ops),
60692 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60693 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60694
60695 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60696 - atomic_read(&fscache_n_stores),
60697 - atomic_read(&fscache_n_stores_ok),
60698 - atomic_read(&fscache_n_stores_again),
60699 - atomic_read(&fscache_n_stores_nobufs),
60700 - atomic_read(&fscache_n_stores_oom));
60701 + atomic_read_unchecked(&fscache_n_stores),
60702 + atomic_read_unchecked(&fscache_n_stores_ok),
60703 + atomic_read_unchecked(&fscache_n_stores_again),
60704 + atomic_read_unchecked(&fscache_n_stores_nobufs),
60705 + atomic_read_unchecked(&fscache_n_stores_oom));
60706 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60707 - atomic_read(&fscache_n_store_ops),
60708 - atomic_read(&fscache_n_store_calls),
60709 - atomic_read(&fscache_n_store_pages),
60710 - atomic_read(&fscache_n_store_radix_deletes),
60711 - atomic_read(&fscache_n_store_pages_over_limit));
60712 + atomic_read_unchecked(&fscache_n_store_ops),
60713 + atomic_read_unchecked(&fscache_n_store_calls),
60714 + atomic_read_unchecked(&fscache_n_store_pages),
60715 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
60716 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60717
60718 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60719 - atomic_read(&fscache_n_store_vmscan_not_storing),
60720 - atomic_read(&fscache_n_store_vmscan_gone),
60721 - atomic_read(&fscache_n_store_vmscan_busy),
60722 - atomic_read(&fscache_n_store_vmscan_cancelled),
60723 - atomic_read(&fscache_n_store_vmscan_wait));
60724 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60725 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60726 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60727 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60728 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60729
60730 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60731 - atomic_read(&fscache_n_op_pend),
60732 - atomic_read(&fscache_n_op_run),
60733 - atomic_read(&fscache_n_op_enqueue),
60734 - atomic_read(&fscache_n_op_cancelled),
60735 - atomic_read(&fscache_n_op_rejected));
60736 + atomic_read_unchecked(&fscache_n_op_pend),
60737 + atomic_read_unchecked(&fscache_n_op_run),
60738 + atomic_read_unchecked(&fscache_n_op_enqueue),
60739 + atomic_read_unchecked(&fscache_n_op_cancelled),
60740 + atomic_read_unchecked(&fscache_n_op_rejected));
60741 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60742 - atomic_read(&fscache_n_op_deferred_release),
60743 - atomic_read(&fscache_n_op_release),
60744 - atomic_read(&fscache_n_op_gc));
60745 + atomic_read_unchecked(&fscache_n_op_deferred_release),
60746 + atomic_read_unchecked(&fscache_n_op_release),
60747 + atomic_read_unchecked(&fscache_n_op_gc));
60748
60749 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60750 atomic_read(&fscache_n_cop_alloc_object),
60751 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60752 index b96a49b..9bfdc47 100644
60753 --- a/fs/fuse/cuse.c
60754 +++ b/fs/fuse/cuse.c
60755 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
60756 INIT_LIST_HEAD(&cuse_conntbl[i]);
60757
60758 /* inherit and extend fuse_dev_operations */
60759 - cuse_channel_fops = fuse_dev_operations;
60760 - cuse_channel_fops.owner = THIS_MODULE;
60761 - cuse_channel_fops.open = cuse_channel_open;
60762 - cuse_channel_fops.release = cuse_channel_release;
60763 + pax_open_kernel();
60764 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60765 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60766 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
60767 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
60768 + pax_close_kernel();
60769
60770 cuse_class = class_create(THIS_MODULE, "cuse");
60771 if (IS_ERR(cuse_class))
60772 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60773 index fa8cb4b..4acb935 100644
60774 --- a/fs/fuse/dev.c
60775 +++ b/fs/fuse/dev.c
60776 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60777 ret = 0;
60778 pipe_lock(pipe);
60779
60780 - if (!pipe->readers) {
60781 + if (!atomic_read(&pipe->readers)) {
60782 send_sig(SIGPIPE, current, 0);
60783 if (!ret)
60784 ret = -EPIPE;
60785 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60786 page_nr++;
60787 ret += buf->len;
60788
60789 - if (pipe->files)
60790 + if (atomic_read(&pipe->files))
60791 do_wakeup = 1;
60792 }
60793
60794 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60795 index c3eb2c4..98007d4 100644
60796 --- a/fs/fuse/dir.c
60797 +++ b/fs/fuse/dir.c
60798 @@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
60799 return link;
60800 }
60801
60802 -static void free_link(char *link)
60803 +static void free_link(const char *link)
60804 {
60805 if (!IS_ERR(link))
60806 free_page((unsigned long) link);
60807 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60808 index db23ce1..9e6cd9d 100644
60809 --- a/fs/hostfs/hostfs_kern.c
60810 +++ b/fs/hostfs/hostfs_kern.c
60811 @@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60812
60813 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60814 {
60815 - char *s = nd_get_link(nd);
60816 + const char *s = nd_get_link(nd);
60817 if (!IS_ERR(s))
60818 __putname(s);
60819 }
60820 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
60821 index d19b30a..ef89c36 100644
60822 --- a/fs/hugetlbfs/inode.c
60823 +++ b/fs/hugetlbfs/inode.c
60824 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60825 struct mm_struct *mm = current->mm;
60826 struct vm_area_struct *vma;
60827 struct hstate *h = hstate_file(file);
60828 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
60829 struct vm_unmapped_area_info info;
60830
60831 if (len & ~huge_page_mask(h))
60832 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60833 return addr;
60834 }
60835
60836 +#ifdef CONFIG_PAX_RANDMMAP
60837 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
60838 +#endif
60839 +
60840 if (addr) {
60841 addr = ALIGN(addr, huge_page_size(h));
60842 vma = find_vma(mm, addr);
60843 - if (TASK_SIZE - len >= addr &&
60844 - (!vma || addr + len <= vma->vm_start))
60845 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
60846 return addr;
60847 }
60848
60849 info.flags = 0;
60850 info.length = len;
60851 info.low_limit = TASK_UNMAPPED_BASE;
60852 +
60853 +#ifdef CONFIG_PAX_RANDMMAP
60854 + if (mm->pax_flags & MF_PAX_RANDMMAP)
60855 + info.low_limit += mm->delta_mmap;
60856 +#endif
60857 +
60858 info.high_limit = TASK_SIZE;
60859 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
60860 info.align_offset = 0;
60861 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60862 };
60863 MODULE_ALIAS_FS("hugetlbfs");
60864
60865 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60866 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60867
60868 static int can_do_hugetlb_shm(void)
60869 {
60870 diff --git a/fs/inode.c b/fs/inode.c
60871 index 4bcdad3..1883822 100644
60872 --- a/fs/inode.c
60873 +++ b/fs/inode.c
60874 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60875
60876 #ifdef CONFIG_SMP
60877 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60878 - static atomic_t shared_last_ino;
60879 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60880 + static atomic_unchecked_t shared_last_ino;
60881 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60882
60883 res = next - LAST_INO_BATCH;
60884 }
60885 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60886 index 4a6cf28..d3a29d3 100644
60887 --- a/fs/jffs2/erase.c
60888 +++ b/fs/jffs2/erase.c
60889 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60890 struct jffs2_unknown_node marker = {
60891 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60892 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60893 - .totlen = cpu_to_je32(c->cleanmarker_size)
60894 + .totlen = cpu_to_je32(c->cleanmarker_size),
60895 + .hdr_crc = cpu_to_je32(0)
60896 };
60897
60898 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60899 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60900 index a6597d6..41b30ec 100644
60901 --- a/fs/jffs2/wbuf.c
60902 +++ b/fs/jffs2/wbuf.c
60903 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60904 {
60905 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60906 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60907 - .totlen = constant_cpu_to_je32(8)
60908 + .totlen = constant_cpu_to_je32(8),
60909 + .hdr_crc = constant_cpu_to_je32(0)
60910 };
60911
60912 /*
60913 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60914 index 6669aa2..36b033d 100644
60915 --- a/fs/jfs/super.c
60916 +++ b/fs/jfs/super.c
60917 @@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
60918
60919 jfs_inode_cachep =
60920 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60921 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60922 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60923 init_once);
60924 if (jfs_inode_cachep == NULL)
60925 return -ENOMEM;
60926 diff --git a/fs/libfs.c b/fs/libfs.c
60927 index a184424..944ddce 100644
60928 --- a/fs/libfs.c
60929 +++ b/fs/libfs.c
60930 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60931
60932 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
60933 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
60934 + char d_name[sizeof(next->d_iname)];
60935 + const unsigned char *name;
60936 +
60937 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
60938 if (!simple_positive(next)) {
60939 spin_unlock(&next->d_lock);
60940 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60941
60942 spin_unlock(&next->d_lock);
60943 spin_unlock(&dentry->d_lock);
60944 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
60945 + name = next->d_name.name;
60946 + if (name == next->d_iname) {
60947 + memcpy(d_name, name, next->d_name.len);
60948 + name = d_name;
60949 + }
60950 + if (!dir_emit(ctx, name, next->d_name.len,
60951 next->d_inode->i_ino, dt_type(next->d_inode)))
60952 return 0;
60953 spin_lock(&dentry->d_lock);
60954 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
60955 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
60956 void *cookie)
60957 {
60958 - char *s = nd_get_link(nd);
60959 + const char *s = nd_get_link(nd);
60960 if (!IS_ERR(s))
60961 kfree(s);
60962 }
60963 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
60964 index acd3947..1f896e2 100644
60965 --- a/fs/lockd/clntproc.c
60966 +++ b/fs/lockd/clntproc.c
60967 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
60968 /*
60969 * Cookie counter for NLM requests
60970 */
60971 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
60972 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
60973
60974 void nlmclnt_next_cookie(struct nlm_cookie *c)
60975 {
60976 - u32 cookie = atomic_inc_return(&nlm_cookie);
60977 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
60978
60979 memcpy(c->data, &cookie, 4);
60980 c->len=4;
60981 diff --git a/fs/locks.c b/fs/locks.c
60982 index 92a0f0a..45a48f0 100644
60983 --- a/fs/locks.c
60984 +++ b/fs/locks.c
60985 @@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
60986 return;
60987
60988 if (filp->f_op->flock) {
60989 - struct file_lock fl = {
60990 + struct file_lock flock = {
60991 .fl_pid = current->tgid,
60992 .fl_file = filp,
60993 .fl_flags = FL_FLOCK,
60994 .fl_type = F_UNLCK,
60995 .fl_end = OFFSET_MAX,
60996 };
60997 - filp->f_op->flock(filp, F_SETLKW, &fl);
60998 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
60999 - fl.fl_ops->fl_release_private(&fl);
61000 + filp->f_op->flock(filp, F_SETLKW, &flock);
61001 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61002 + flock.fl_ops->fl_release_private(&flock);
61003 }
61004
61005 spin_lock(&inode->i_lock);
61006 diff --git a/fs/mount.h b/fs/mount.h
61007 index a17458c..e69fb5b 100644
61008 --- a/fs/mount.h
61009 +++ b/fs/mount.h
61010 @@ -11,7 +11,7 @@ struct mnt_namespace {
61011 u64 seq; /* Sequence number to prevent loops */
61012 wait_queue_head_t poll;
61013 int event;
61014 -};
61015 +} __randomize_layout;
61016
61017 struct mnt_pcp {
61018 int mnt_count;
61019 @@ -57,7 +57,7 @@ struct mount {
61020 int mnt_expiry_mark; /* true if marked for expiry */
61021 int mnt_pinned;
61022 struct path mnt_ex_mountpoint;
61023 -};
61024 +} __randomize_layout;
61025
61026 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61027
61028 diff --git a/fs/namei.c b/fs/namei.c
61029 index 3531dee..3177227 100644
61030 --- a/fs/namei.c
61031 +++ b/fs/namei.c
61032 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
61033 if (ret != -EACCES)
61034 return ret;
61035
61036 +#ifdef CONFIG_GRKERNSEC
61037 + /* we'll block if we have to log due to a denied capability use */
61038 + if (mask & MAY_NOT_BLOCK)
61039 + return -ECHILD;
61040 +#endif
61041 +
61042 if (S_ISDIR(inode->i_mode)) {
61043 /* DACs are overridable for directories */
61044 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
61045 - return 0;
61046 if (!(mask & MAY_WRITE))
61047 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61048 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61049 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61050 return 0;
61051 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
61052 + return 0;
61053 return -EACCES;
61054 }
61055 /*
61056 + * Searching includes executable on directories, else just read.
61057 + */
61058 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61059 + if (mask == MAY_READ)
61060 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61061 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61062 + return 0;
61063 +
61064 + /*
61065 * Read/write DACs are always overridable.
61066 * Executable DACs are overridable when there is
61067 * at least one exec bit set.
61068 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
61069 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61070 return 0;
61071
61072 - /*
61073 - * Searching includes executable on directories, else just read.
61074 - */
61075 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61076 - if (mask == MAY_READ)
61077 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61078 - return 0;
61079 -
61080 return -EACCES;
61081 }
61082
61083 @@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61084 {
61085 struct dentry *dentry = link->dentry;
61086 int error;
61087 - char *s;
61088 + const char *s;
61089
61090 BUG_ON(nd->flags & LOOKUP_RCU);
61091
61092 @@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61093 if (error)
61094 goto out_put_nd_path;
61095
61096 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61097 + dentry->d_inode, dentry, nd->path.mnt)) {
61098 + error = -EACCES;
61099 + goto out_put_nd_path;
61100 + }
61101 +
61102 nd->last_type = LAST_BIND;
61103 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61104 error = PTR_ERR(*p);
61105 @@ -1582,6 +1596,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61106 if (res)
61107 break;
61108 res = walk_component(nd, path, LOOKUP_FOLLOW);
61109 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61110 + res = -EACCES;
61111 put_link(nd, &link, cookie);
61112 } while (res > 0);
61113
61114 @@ -1655,7 +1671,7 @@ EXPORT_SYMBOL(full_name_hash);
61115 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61116 {
61117 unsigned long a, b, adata, bdata, mask, hash, len;
61118 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61119 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61120
61121 hash = a = 0;
61122 len = -sizeof(unsigned long);
61123 @@ -1939,6 +1955,8 @@ static int path_lookupat(int dfd, const char *name,
61124 if (err)
61125 break;
61126 err = lookup_last(nd, &path);
61127 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61128 + err = -EACCES;
61129 put_link(nd, &link, cookie);
61130 }
61131 }
61132 @@ -1946,6 +1964,13 @@ static int path_lookupat(int dfd, const char *name,
61133 if (!err)
61134 err = complete_walk(nd);
61135
61136 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61137 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61138 + path_put(&nd->path);
61139 + err = -ENOENT;
61140 + }
61141 + }
61142 +
61143 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61144 if (!d_is_directory(nd->path.dentry)) {
61145 path_put(&nd->path);
61146 @@ -1973,8 +1998,15 @@ static int filename_lookup(int dfd, struct filename *name,
61147 retval = path_lookupat(dfd, name->name,
61148 flags | LOOKUP_REVAL, nd);
61149
61150 - if (likely(!retval))
61151 + if (likely(!retval)) {
61152 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61153 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61154 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61155 + path_put(&nd->path);
61156 + return -ENOENT;
61157 + }
61158 + }
61159 + }
61160 return retval;
61161 }
61162
61163 @@ -2548,6 +2580,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61164 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61165 return -EPERM;
61166
61167 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61168 + return -EPERM;
61169 + if (gr_handle_rawio(inode))
61170 + return -EPERM;
61171 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61172 + return -EACCES;
61173 +
61174 return 0;
61175 }
61176
61177 @@ -2779,7 +2818,7 @@ looked_up:
61178 * cleared otherwise prior to returning.
61179 */
61180 static int lookup_open(struct nameidata *nd, struct path *path,
61181 - struct file *file,
61182 + struct path *link, struct file *file,
61183 const struct open_flags *op,
61184 bool got_write, int *opened)
61185 {
61186 @@ -2814,6 +2853,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61187 /* Negative dentry, just create the file */
61188 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61189 umode_t mode = op->mode;
61190 +
61191 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61192 + error = -EACCES;
61193 + goto out_dput;
61194 + }
61195 +
61196 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61197 + error = -EACCES;
61198 + goto out_dput;
61199 + }
61200 +
61201 if (!IS_POSIXACL(dir->d_inode))
61202 mode &= ~current_umask();
61203 /*
61204 @@ -2835,6 +2885,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61205 nd->flags & LOOKUP_EXCL);
61206 if (error)
61207 goto out_dput;
61208 + else
61209 + gr_handle_create(dentry, nd->path.mnt);
61210 }
61211 out_no_open:
61212 path->dentry = dentry;
61213 @@ -2849,7 +2901,7 @@ out_dput:
61214 /*
61215 * Handle the last step of open()
61216 */
61217 -static int do_last(struct nameidata *nd, struct path *path,
61218 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61219 struct file *file, const struct open_flags *op,
61220 int *opened, struct filename *name)
61221 {
61222 @@ -2899,6 +2951,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61223 if (error)
61224 return error;
61225
61226 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61227 + error = -ENOENT;
61228 + goto out;
61229 + }
61230 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61231 + error = -EACCES;
61232 + goto out;
61233 + }
61234 +
61235 audit_inode(name, dir, LOOKUP_PARENT);
61236 error = -EISDIR;
61237 /* trailing slashes? */
61238 @@ -2918,7 +2979,7 @@ retry_lookup:
61239 */
61240 }
61241 mutex_lock(&dir->d_inode->i_mutex);
61242 - error = lookup_open(nd, path, file, op, got_write, opened);
61243 + error = lookup_open(nd, path, link, file, op, got_write, opened);
61244 mutex_unlock(&dir->d_inode->i_mutex);
61245
61246 if (error <= 0) {
61247 @@ -2942,11 +3003,28 @@ retry_lookup:
61248 goto finish_open_created;
61249 }
61250
61251 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61252 + error = -ENOENT;
61253 + goto exit_dput;
61254 + }
61255 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61256 + error = -EACCES;
61257 + goto exit_dput;
61258 + }
61259 +
61260 /*
61261 * create/update audit record if it already exists.
61262 */
61263 - if (d_is_positive(path->dentry))
61264 + if (d_is_positive(path->dentry)) {
61265 + /* only check if O_CREAT is specified, all other checks need to go
61266 + into may_open */
61267 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61268 + error = -EACCES;
61269 + goto exit_dput;
61270 + }
61271 +
61272 audit_inode(name, path->dentry, 0);
61273 + }
61274
61275 /*
61276 * If atomic_open() acquired write access it is dropped now due to
61277 @@ -2987,6 +3065,11 @@ finish_lookup:
61278 }
61279 }
61280 BUG_ON(inode != path->dentry->d_inode);
61281 + /* if we're resolving a symlink to another symlink */
61282 + if (link && gr_handle_symlink_owner(link, inode)) {
61283 + error = -EACCES;
61284 + goto out;
61285 + }
61286 return 1;
61287 }
61288
61289 @@ -2996,7 +3079,6 @@ finish_lookup:
61290 save_parent.dentry = nd->path.dentry;
61291 save_parent.mnt = mntget(path->mnt);
61292 nd->path.dentry = path->dentry;
61293 -
61294 }
61295 nd->inode = inode;
61296 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61297 @@ -3006,7 +3088,18 @@ finish_open:
61298 path_put(&save_parent);
61299 return error;
61300 }
61301 +
61302 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61303 + error = -ENOENT;
61304 + goto out;
61305 + }
61306 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61307 + error = -EACCES;
61308 + goto out;
61309 + }
61310 +
61311 audit_inode(name, nd->path.dentry, 0);
61312 +
61313 error = -EISDIR;
61314 if ((open_flag & O_CREAT) &&
61315 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61316 @@ -3170,7 +3263,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61317 if (unlikely(error))
61318 goto out;
61319
61320 - error = do_last(nd, &path, file, op, &opened, pathname);
61321 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61322 while (unlikely(error > 0)) { /* trailing symlink */
61323 struct path link = path;
61324 void *cookie;
61325 @@ -3188,7 +3281,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61326 error = follow_link(&link, nd, &cookie);
61327 if (unlikely(error))
61328 break;
61329 - error = do_last(nd, &path, file, op, &opened, pathname);
61330 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
61331 put_link(nd, &link, cookie);
61332 }
61333 out:
61334 @@ -3288,9 +3381,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61335 goto unlock;
61336
61337 error = -EEXIST;
61338 - if (d_is_positive(dentry))
61339 + if (d_is_positive(dentry)) {
61340 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61341 + error = -ENOENT;
61342 goto fail;
61343 -
61344 + }
61345 /*
61346 * Special case - lookup gave negative, but... we had foo/bar/
61347 * From the vfs_mknod() POV we just have a negative dentry -
61348 @@ -3342,6 +3437,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61349 }
61350 EXPORT_SYMBOL(user_path_create);
61351
61352 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61353 +{
61354 + struct filename *tmp = getname(pathname);
61355 + struct dentry *res;
61356 + if (IS_ERR(tmp))
61357 + return ERR_CAST(tmp);
61358 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61359 + if (IS_ERR(res))
61360 + putname(tmp);
61361 + else
61362 + *to = tmp;
61363 + return res;
61364 +}
61365 +
61366 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61367 {
61368 int error = may_create(dir, dentry);
61369 @@ -3404,6 +3513,17 @@ retry:
61370
61371 if (!IS_POSIXACL(path.dentry->d_inode))
61372 mode &= ~current_umask();
61373 +
61374 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61375 + error = -EPERM;
61376 + goto out;
61377 + }
61378 +
61379 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61380 + error = -EACCES;
61381 + goto out;
61382 + }
61383 +
61384 error = security_path_mknod(&path, dentry, mode, dev);
61385 if (error)
61386 goto out;
61387 @@ -3420,6 +3540,8 @@ retry:
61388 break;
61389 }
61390 out:
61391 + if (!error)
61392 + gr_handle_create(dentry, path.mnt);
61393 done_path_create(&path, dentry);
61394 if (retry_estale(error, lookup_flags)) {
61395 lookup_flags |= LOOKUP_REVAL;
61396 @@ -3472,9 +3594,16 @@ retry:
61397
61398 if (!IS_POSIXACL(path.dentry->d_inode))
61399 mode &= ~current_umask();
61400 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61401 + error = -EACCES;
61402 + goto out;
61403 + }
61404 error = security_path_mkdir(&path, dentry, mode);
61405 if (!error)
61406 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61407 + if (!error)
61408 + gr_handle_create(dentry, path.mnt);
61409 +out:
61410 done_path_create(&path, dentry);
61411 if (retry_estale(error, lookup_flags)) {
61412 lookup_flags |= LOOKUP_REVAL;
61413 @@ -3555,6 +3684,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61414 struct filename *name;
61415 struct dentry *dentry;
61416 struct nameidata nd;
61417 + ino_t saved_ino = 0;
61418 + dev_t saved_dev = 0;
61419 unsigned int lookup_flags = 0;
61420 retry:
61421 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61422 @@ -3587,10 +3718,21 @@ retry:
61423 error = -ENOENT;
61424 goto exit3;
61425 }
61426 +
61427 + saved_ino = dentry->d_inode->i_ino;
61428 + saved_dev = gr_get_dev_from_dentry(dentry);
61429 +
61430 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61431 + error = -EACCES;
61432 + goto exit3;
61433 + }
61434 +
61435 error = security_path_rmdir(&nd.path, dentry);
61436 if (error)
61437 goto exit3;
61438 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61439 + if (!error && (saved_dev || saved_ino))
61440 + gr_handle_delete(saved_ino, saved_dev);
61441 exit3:
61442 dput(dentry);
61443 exit2:
61444 @@ -3680,6 +3822,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61445 struct nameidata nd;
61446 struct inode *inode = NULL;
61447 struct inode *delegated_inode = NULL;
61448 + ino_t saved_ino = 0;
61449 + dev_t saved_dev = 0;
61450 unsigned int lookup_flags = 0;
61451 retry:
61452 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61453 @@ -3706,10 +3850,22 @@ retry_deleg:
61454 if (d_is_negative(dentry))
61455 goto slashes;
61456 ihold(inode);
61457 +
61458 + if (inode->i_nlink <= 1) {
61459 + saved_ino = inode->i_ino;
61460 + saved_dev = gr_get_dev_from_dentry(dentry);
61461 + }
61462 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61463 + error = -EACCES;
61464 + goto exit2;
61465 + }
61466 +
61467 error = security_path_unlink(&nd.path, dentry);
61468 if (error)
61469 goto exit2;
61470 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61471 + if (!error && (saved_ino || saved_dev))
61472 + gr_handle_delete(saved_ino, saved_dev);
61473 exit2:
61474 dput(dentry);
61475 }
61476 @@ -3797,9 +3953,17 @@ retry:
61477 if (IS_ERR(dentry))
61478 goto out_putname;
61479
61480 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61481 + error = -EACCES;
61482 + goto out;
61483 + }
61484 +
61485 error = security_path_symlink(&path, dentry, from->name);
61486 if (!error)
61487 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61488 + if (!error)
61489 + gr_handle_create(dentry, path.mnt);
61490 +out:
61491 done_path_create(&path, dentry);
61492 if (retry_estale(error, lookup_flags)) {
61493 lookup_flags |= LOOKUP_REVAL;
61494 @@ -3902,6 +4066,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61495 struct dentry *new_dentry;
61496 struct path old_path, new_path;
61497 struct inode *delegated_inode = NULL;
61498 + struct filename *to = NULL;
61499 int how = 0;
61500 int error;
61501
61502 @@ -3925,7 +4090,7 @@ retry:
61503 if (error)
61504 return error;
61505
61506 - new_dentry = user_path_create(newdfd, newname, &new_path,
61507 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61508 (how & LOOKUP_REVAL));
61509 error = PTR_ERR(new_dentry);
61510 if (IS_ERR(new_dentry))
61511 @@ -3937,11 +4102,28 @@ retry:
61512 error = may_linkat(&old_path);
61513 if (unlikely(error))
61514 goto out_dput;
61515 +
61516 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61517 + old_path.dentry->d_inode,
61518 + old_path.dentry->d_inode->i_mode, to)) {
61519 + error = -EACCES;
61520 + goto out_dput;
61521 + }
61522 +
61523 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61524 + old_path.dentry, old_path.mnt, to)) {
61525 + error = -EACCES;
61526 + goto out_dput;
61527 + }
61528 +
61529 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61530 if (error)
61531 goto out_dput;
61532 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61533 + if (!error)
61534 + gr_handle_create(new_dentry, new_path.mnt);
61535 out_dput:
61536 + putname(to);
61537 done_path_create(&new_path, new_dentry);
61538 if (delegated_inode) {
61539 error = break_deleg_wait(&delegated_inode);
61540 @@ -4225,6 +4407,12 @@ retry_deleg:
61541 if (new_dentry == trap)
61542 goto exit5;
61543
61544 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61545 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
61546 + to);
61547 + if (error)
61548 + goto exit5;
61549 +
61550 error = security_path_rename(&oldnd.path, old_dentry,
61551 &newnd.path, new_dentry);
61552 if (error)
61553 @@ -4232,6 +4420,9 @@ retry_deleg:
61554 error = vfs_rename(old_dir->d_inode, old_dentry,
61555 new_dir->d_inode, new_dentry,
61556 &delegated_inode);
61557 + if (!error)
61558 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61559 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61560 exit5:
61561 dput(new_dentry);
61562 exit4:
61563 @@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61564
61565 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61566 {
61567 + char tmpbuf[64];
61568 + const char *newlink;
61569 int len;
61570
61571 len = PTR_ERR(link);
61572 @@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61573 len = strlen(link);
61574 if (len > (unsigned) buflen)
61575 len = buflen;
61576 - if (copy_to_user(buffer, link, len))
61577 +
61578 + if (len < sizeof(tmpbuf)) {
61579 + memcpy(tmpbuf, link, len);
61580 + newlink = tmpbuf;
61581 + } else
61582 + newlink = link;
61583 +
61584 + if (copy_to_user(buffer, newlink, len))
61585 len = -EFAULT;
61586 out:
61587 return len;
61588 diff --git a/fs/namespace.c b/fs/namespace.c
61589 index be32ebc..c595734 100644
61590 --- a/fs/namespace.c
61591 +++ b/fs/namespace.c
61592 @@ -1293,6 +1293,9 @@ static int do_umount(struct mount *mnt, int flags)
61593 if (!(sb->s_flags & MS_RDONLY))
61594 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61595 up_write(&sb->s_umount);
61596 +
61597 + gr_log_remount(mnt->mnt_devname, retval);
61598 +
61599 return retval;
61600 }
61601
61602 @@ -1315,6 +1318,9 @@ static int do_umount(struct mount *mnt, int flags)
61603 }
61604 unlock_mount_hash();
61605 namespace_unlock();
61606 +
61607 + gr_log_unmount(mnt->mnt_devname, retval);
61608 +
61609 return retval;
61610 }
61611
61612 @@ -1334,7 +1340,7 @@ static inline bool may_mount(void)
61613 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61614 */
61615
61616 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61617 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61618 {
61619 struct path path;
61620 struct mount *mnt;
61621 @@ -1376,7 +1382,7 @@ out:
61622 /*
61623 * The 2.0 compatible umount. No flags.
61624 */
61625 -SYSCALL_DEFINE1(oldumount, char __user *, name)
61626 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
61627 {
61628 return sys_umount(name, 0);
61629 }
61630 @@ -2379,6 +2385,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61631 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61632 MS_STRICTATIME);
61633
61634 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61635 + retval = -EPERM;
61636 + goto dput_out;
61637 + }
61638 +
61639 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61640 + retval = -EPERM;
61641 + goto dput_out;
61642 + }
61643 +
61644 if (flags & MS_REMOUNT)
61645 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61646 data_page);
61647 @@ -2393,6 +2409,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61648 dev_name, data_page);
61649 dput_out:
61650 path_put(&path);
61651 +
61652 + gr_log_mount(dev_name, dir_name, retval);
61653 +
61654 return retval;
61655 }
61656
61657 @@ -2410,7 +2429,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61658 * number incrementing at 10Ghz will take 12,427 years to wrap which
61659 * is effectively never, so we can ignore the possibility.
61660 */
61661 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61662 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61663
61664 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61665 {
61666 @@ -2425,7 +2444,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61667 kfree(new_ns);
61668 return ERR_PTR(ret);
61669 }
61670 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61671 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61672 atomic_set(&new_ns->count, 1);
61673 new_ns->root = NULL;
61674 INIT_LIST_HEAD(&new_ns->list);
61675 @@ -2435,7 +2454,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61676 return new_ns;
61677 }
61678
61679 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61680 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61681 struct user_namespace *user_ns, struct fs_struct *new_fs)
61682 {
61683 struct mnt_namespace *new_ns;
61684 @@ -2556,8 +2575,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61685 }
61686 EXPORT_SYMBOL(mount_subtree);
61687
61688 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61689 - char __user *, type, unsigned long, flags, void __user *, data)
61690 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61691 + const char __user *, type, unsigned long, flags, void __user *, data)
61692 {
61693 int ret;
61694 char *kernel_type;
61695 @@ -2670,6 +2689,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61696 if (error)
61697 goto out2;
61698
61699 + if (gr_handle_chroot_pivot()) {
61700 + error = -EPERM;
61701 + goto out2;
61702 + }
61703 +
61704 get_fs_root(current->fs, &root);
61705 old_mp = lock_mount(&old);
61706 error = PTR_ERR(old_mp);
61707 @@ -2930,7 +2954,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61708 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61709 return -EPERM;
61710
61711 - if (fs->users != 1)
61712 + if (atomic_read(&fs->users) != 1)
61713 return -EINVAL;
61714
61715 get_mnt_ns(mnt_ns);
61716 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61717 index f4ccfe6..a5cf064 100644
61718 --- a/fs/nfs/callback_xdr.c
61719 +++ b/fs/nfs/callback_xdr.c
61720 @@ -51,7 +51,7 @@ struct callback_op {
61721 callback_decode_arg_t decode_args;
61722 callback_encode_res_t encode_res;
61723 long res_maxsize;
61724 -};
61725 +} __do_const;
61726
61727 static struct callback_op callback_ops[];
61728
61729 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61730 index 5d94c02..630214f 100644
61731 --- a/fs/nfs/inode.c
61732 +++ b/fs/nfs/inode.c
61733 @@ -1153,16 +1153,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
61734 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
61735 }
61736
61737 -static atomic_long_t nfs_attr_generation_counter;
61738 +static atomic_long_unchecked_t nfs_attr_generation_counter;
61739
61740 static unsigned long nfs_read_attr_generation_counter(void)
61741 {
61742 - return atomic_long_read(&nfs_attr_generation_counter);
61743 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61744 }
61745
61746 unsigned long nfs_inc_attr_generation_counter(void)
61747 {
61748 - return atomic_long_inc_return(&nfs_attr_generation_counter);
61749 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61750 }
61751
61752 void nfs_fattr_init(struct nfs_fattr *fattr)
61753 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61754 index 419572f..5414a23 100644
61755 --- a/fs/nfsd/nfs4proc.c
61756 +++ b/fs/nfsd/nfs4proc.c
61757 @@ -1168,7 +1168,7 @@ struct nfsd4_operation {
61758 nfsd4op_rsize op_rsize_bop;
61759 stateid_getter op_get_currentstateid;
61760 stateid_setter op_set_currentstateid;
61761 -};
61762 +} __do_const;
61763
61764 static struct nfsd4_operation nfsd4_ops[];
61765
61766 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61767 index ee7237f..e3ae60a 100644
61768 --- a/fs/nfsd/nfs4xdr.c
61769 +++ b/fs/nfsd/nfs4xdr.c
61770 @@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61771
61772 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61773
61774 -static nfsd4_dec nfsd4_dec_ops[] = {
61775 +static const nfsd4_dec nfsd4_dec_ops[] = {
61776 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61777 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61778 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61779 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61780 index b6af150..f6ec5e3 100644
61781 --- a/fs/nfsd/nfscache.c
61782 +++ b/fs/nfsd/nfscache.c
61783 @@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61784 {
61785 struct svc_cacherep *rp = rqstp->rq_cacherep;
61786 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61787 - int len;
61788 + long len;
61789 size_t bufsize = 0;
61790
61791 if (!rp)
61792 return;
61793
61794 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61795 - len >>= 2;
61796 + if (statp) {
61797 + len = (char*)statp - (char*)resv->iov_base;
61798 + len = resv->iov_len - len;
61799 + len >>= 2;
61800 + }
61801
61802 /* Don't cache excessive amounts of data and XDR failures */
61803 if (!statp || len > (256 >> 2)) {
61804 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
61805 index 7eea63c..a35f4fb 100644
61806 --- a/fs/nfsd/vfs.c
61807 +++ b/fs/nfsd/vfs.c
61808 @@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61809 } else {
61810 oldfs = get_fs();
61811 set_fs(KERNEL_DS);
61812 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
61813 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
61814 set_fs(oldfs);
61815 }
61816
61817 @@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61818
61819 /* Write the data. */
61820 oldfs = get_fs(); set_fs(KERNEL_DS);
61821 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
61822 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
61823 set_fs(oldfs);
61824 if (host_err < 0)
61825 goto out_nfserr;
61826 @@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
61827 */
61828
61829 oldfs = get_fs(); set_fs(KERNEL_DS);
61830 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
61831 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
61832 set_fs(oldfs);
61833
61834 if (host_err < 0)
61835 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
61836 index fea6bd5..8ee9d81 100644
61837 --- a/fs/nls/nls_base.c
61838 +++ b/fs/nls/nls_base.c
61839 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
61840
61841 int register_nls(struct nls_table * nls)
61842 {
61843 - struct nls_table ** tmp = &tables;
61844 + struct nls_table *tmp = tables;
61845
61846 if (nls->next)
61847 return -EBUSY;
61848
61849 spin_lock(&nls_lock);
61850 - while (*tmp) {
61851 - if (nls == *tmp) {
61852 + while (tmp) {
61853 + if (nls == tmp) {
61854 spin_unlock(&nls_lock);
61855 return -EBUSY;
61856 }
61857 - tmp = &(*tmp)->next;
61858 + tmp = tmp->next;
61859 }
61860 - nls->next = tables;
61861 + pax_open_kernel();
61862 + *(struct nls_table **)&nls->next = tables;
61863 + pax_close_kernel();
61864 tables = nls;
61865 spin_unlock(&nls_lock);
61866 return 0;
61867 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
61868
61869 int unregister_nls(struct nls_table * nls)
61870 {
61871 - struct nls_table ** tmp = &tables;
61872 + struct nls_table * const * tmp = &tables;
61873
61874 spin_lock(&nls_lock);
61875 while (*tmp) {
61876 if (nls == *tmp) {
61877 - *tmp = nls->next;
61878 + pax_open_kernel();
61879 + *(struct nls_table **)tmp = nls->next;
61880 + pax_close_kernel();
61881 spin_unlock(&nls_lock);
61882 return 0;
61883 }
61884 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
61885 index 7424929..35f6be5 100644
61886 --- a/fs/nls/nls_euc-jp.c
61887 +++ b/fs/nls/nls_euc-jp.c
61888 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
61889 p_nls = load_nls("cp932");
61890
61891 if (p_nls) {
61892 - table.charset2upper = p_nls->charset2upper;
61893 - table.charset2lower = p_nls->charset2lower;
61894 + pax_open_kernel();
61895 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61896 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61897 + pax_close_kernel();
61898 return register_nls(&table);
61899 }
61900
61901 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
61902 index e7bc1d7..06bd4bb 100644
61903 --- a/fs/nls/nls_koi8-ru.c
61904 +++ b/fs/nls/nls_koi8-ru.c
61905 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
61906 p_nls = load_nls("koi8-u");
61907
61908 if (p_nls) {
61909 - table.charset2upper = p_nls->charset2upper;
61910 - table.charset2lower = p_nls->charset2lower;
61911 + pax_open_kernel();
61912 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61913 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61914 + pax_close_kernel();
61915 return register_nls(&table);
61916 }
61917
61918 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
61919 index 6663511..7668ca4 100644
61920 --- a/fs/notify/fanotify/fanotify_user.c
61921 +++ b/fs/notify/fanotify/fanotify_user.c
61922 @@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
61923
61924 fd = fanotify_event_metadata.fd;
61925 ret = -EFAULT;
61926 - if (copy_to_user(buf, &fanotify_event_metadata,
61927 - fanotify_event_metadata.event_len))
61928 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
61929 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
61930 goto out_close_fd;
61931
61932 ret = prepare_for_access_response(group, event, fd);
61933 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
61934 index 7b51b05..5ea5ef6 100644
61935 --- a/fs/notify/notification.c
61936 +++ b/fs/notify/notification.c
61937 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
61938 * get set to 0 so it will never get 'freed'
61939 */
61940 static struct fsnotify_event *q_overflow_event;
61941 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61942 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61943
61944 /**
61945 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
61946 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61947 */
61948 u32 fsnotify_get_cookie(void)
61949 {
61950 - return atomic_inc_return(&fsnotify_sync_cookie);
61951 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
61952 }
61953 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
61954
61955 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
61956 index 9e38daf..5727cae 100644
61957 --- a/fs/ntfs/dir.c
61958 +++ b/fs/ntfs/dir.c
61959 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
61960 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
61961 ~(s64)(ndir->itype.index.block_size - 1)));
61962 /* Bounds checks. */
61963 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61964 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61965 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
61966 "inode 0x%lx or driver bug.", vdir->i_ino);
61967 goto err_out;
61968 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
61969 index ea4ba9d..1e13d34 100644
61970 --- a/fs/ntfs/file.c
61971 +++ b/fs/ntfs/file.c
61972 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
61973 char *addr;
61974 size_t total = 0;
61975 unsigned len;
61976 - int left;
61977 + unsigned left;
61978
61979 do {
61980 len = PAGE_CACHE_SIZE - ofs;
61981 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
61982 index 82650d5..db37dcf 100644
61983 --- a/fs/ntfs/super.c
61984 +++ b/fs/ntfs/super.c
61985 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61986 if (!silent)
61987 ntfs_error(sb, "Primary boot sector is invalid.");
61988 } else if (!silent)
61989 - ntfs_error(sb, read_err_str, "primary");
61990 + ntfs_error(sb, read_err_str, "%s", "primary");
61991 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
61992 if (bh_primary)
61993 brelse(bh_primary);
61994 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61995 goto hotfix_primary_boot_sector;
61996 brelse(bh_backup);
61997 } else if (!silent)
61998 - ntfs_error(sb, read_err_str, "backup");
61999 + ntfs_error(sb, read_err_str, "%s", "backup");
62000 /* Try to read NT3.51- backup boot sector. */
62001 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62002 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62003 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62004 "sector.");
62005 brelse(bh_backup);
62006 } else if (!silent)
62007 - ntfs_error(sb, read_err_str, "backup");
62008 + ntfs_error(sb, read_err_str, "%s", "backup");
62009 /* We failed. Cleanup and return. */
62010 if (bh_primary)
62011 brelse(bh_primary);
62012 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62013 index cd5496b..26a1055 100644
62014 --- a/fs/ocfs2/localalloc.c
62015 +++ b/fs/ocfs2/localalloc.c
62016 @@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62017 goto bail;
62018 }
62019
62020 - atomic_inc(&osb->alloc_stats.moves);
62021 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62022
62023 bail:
62024 if (handle)
62025 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62026 index 3a90347..c40bef8 100644
62027 --- a/fs/ocfs2/ocfs2.h
62028 +++ b/fs/ocfs2/ocfs2.h
62029 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
62030
62031 struct ocfs2_alloc_stats
62032 {
62033 - atomic_t moves;
62034 - atomic_t local_data;
62035 - atomic_t bitmap_data;
62036 - atomic_t bg_allocs;
62037 - atomic_t bg_extends;
62038 + atomic_unchecked_t moves;
62039 + atomic_unchecked_t local_data;
62040 + atomic_unchecked_t bitmap_data;
62041 + atomic_unchecked_t bg_allocs;
62042 + atomic_unchecked_t bg_extends;
62043 };
62044
62045 enum ocfs2_local_alloc_state
62046 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62047 index 2c91452..77a3cd2 100644
62048 --- a/fs/ocfs2/suballoc.c
62049 +++ b/fs/ocfs2/suballoc.c
62050 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62051 mlog_errno(status);
62052 goto bail;
62053 }
62054 - atomic_inc(&osb->alloc_stats.bg_extends);
62055 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62056
62057 /* You should never ask for this much metadata */
62058 BUG_ON(bits_wanted >
62059 @@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62060 mlog_errno(status);
62061 goto bail;
62062 }
62063 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62064 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62065
62066 *suballoc_loc = res.sr_bg_blkno;
62067 *suballoc_bit_start = res.sr_bit_offset;
62068 @@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62069 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62070 res->sr_bits);
62071
62072 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62073 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62074
62075 BUG_ON(res->sr_bits != 1);
62076
62077 @@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62078 mlog_errno(status);
62079 goto bail;
62080 }
62081 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62082 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62083
62084 BUG_ON(res.sr_bits != 1);
62085
62086 @@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62087 cluster_start,
62088 num_clusters);
62089 if (!status)
62090 - atomic_inc(&osb->alloc_stats.local_data);
62091 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62092 } else {
62093 if (min_clusters > (osb->bitmap_cpg - 1)) {
62094 /* The only paths asking for contiguousness
62095 @@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62096 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62097 res.sr_bg_blkno,
62098 res.sr_bit_offset);
62099 - atomic_inc(&osb->alloc_stats.bitmap_data);
62100 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62101 *num_clusters = res.sr_bits;
62102 }
62103 }
62104 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62105 index c414929..5c9ee542 100644
62106 --- a/fs/ocfs2/super.c
62107 +++ b/fs/ocfs2/super.c
62108 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62109 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62110 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62111 "Stats",
62112 - atomic_read(&osb->alloc_stats.bitmap_data),
62113 - atomic_read(&osb->alloc_stats.local_data),
62114 - atomic_read(&osb->alloc_stats.bg_allocs),
62115 - atomic_read(&osb->alloc_stats.moves),
62116 - atomic_read(&osb->alloc_stats.bg_extends));
62117 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62118 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62119 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62120 + atomic_read_unchecked(&osb->alloc_stats.moves),
62121 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62122
62123 out += snprintf(buf + out, len - out,
62124 "%10s => State: %u Descriptor: %llu Size: %u bits "
62125 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62126 spin_lock_init(&osb->osb_xattr_lock);
62127 ocfs2_init_steal_slots(osb);
62128
62129 - atomic_set(&osb->alloc_stats.moves, 0);
62130 - atomic_set(&osb->alloc_stats.local_data, 0);
62131 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62132 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62133 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62134 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62135 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62136 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62137 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62138 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62139
62140 /* Copy the blockcheck stats from the superblock probe */
62141 osb->osb_ecc_stats = *stats;
62142 diff --git a/fs/open.c b/fs/open.c
62143 index 4b3e1ed..1c84599 100644
62144 --- a/fs/open.c
62145 +++ b/fs/open.c
62146 @@ -32,6 +32,8 @@
62147 #include <linux/dnotify.h>
62148 #include <linux/compat.h>
62149
62150 +#define CREATE_TRACE_POINTS
62151 +#include <trace/events/fs.h>
62152 #include "internal.h"
62153
62154 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62155 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62156 error = locks_verify_truncate(inode, NULL, length);
62157 if (!error)
62158 error = security_path_truncate(path);
62159 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62160 + error = -EACCES;
62161 if (!error)
62162 error = do_truncate(path->dentry, length, 0, NULL);
62163
62164 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62165 error = locks_verify_truncate(inode, f.file, length);
62166 if (!error)
62167 error = security_path_truncate(&f.file->f_path);
62168 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62169 + error = -EACCES;
62170 if (!error)
62171 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62172 sb_end_write(inode->i_sb);
62173 @@ -361,6 +367,9 @@ retry:
62174 if (__mnt_is_readonly(path.mnt))
62175 res = -EROFS;
62176
62177 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62178 + res = -EACCES;
62179 +
62180 out_path_release:
62181 path_put(&path);
62182 if (retry_estale(res, lookup_flags)) {
62183 @@ -392,6 +401,8 @@ retry:
62184 if (error)
62185 goto dput_and_out;
62186
62187 + gr_log_chdir(path.dentry, path.mnt);
62188 +
62189 set_fs_pwd(current->fs, &path);
62190
62191 dput_and_out:
62192 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62193 goto out_putf;
62194
62195 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62196 +
62197 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62198 + error = -EPERM;
62199 +
62200 + if (!error)
62201 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62202 +
62203 if (!error)
62204 set_fs_pwd(current->fs, &f.file->f_path);
62205 out_putf:
62206 @@ -450,7 +468,13 @@ retry:
62207 if (error)
62208 goto dput_and_out;
62209
62210 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62211 + goto dput_and_out;
62212 +
62213 set_fs_root(current->fs, &path);
62214 +
62215 + gr_handle_chroot_chdir(&path);
62216 +
62217 error = 0;
62218 dput_and_out:
62219 path_put(&path);
62220 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62221 return error;
62222 retry_deleg:
62223 mutex_lock(&inode->i_mutex);
62224 +
62225 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62226 + error = -EACCES;
62227 + goto out_unlock;
62228 + }
62229 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62230 + error = -EACCES;
62231 + goto out_unlock;
62232 + }
62233 +
62234 error = security_path_chmod(path, mode);
62235 if (error)
62236 goto out_unlock;
62237 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62238 uid = make_kuid(current_user_ns(), user);
62239 gid = make_kgid(current_user_ns(), group);
62240
62241 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
62242 + return -EACCES;
62243 +
62244 newattrs.ia_valid = ATTR_CTIME;
62245 if (user != (uid_t) -1) {
62246 if (!uid_valid(uid))
62247 @@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62248 } else {
62249 fsnotify_open(f);
62250 fd_install(fd, f);
62251 + trace_do_sys_open(tmp->name, flags, mode);
62252 }
62253 }
62254 putname(tmp);
62255 diff --git a/fs/pipe.c b/fs/pipe.c
62256 index 0e0752e..7cfdd50 100644
62257 --- a/fs/pipe.c
62258 +++ b/fs/pipe.c
62259 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62260
62261 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62262 {
62263 - if (pipe->files)
62264 + if (atomic_read(&pipe->files))
62265 mutex_lock_nested(&pipe->mutex, subclass);
62266 }
62267
62268 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62269
62270 void pipe_unlock(struct pipe_inode_info *pipe)
62271 {
62272 - if (pipe->files)
62273 + if (atomic_read(&pipe->files))
62274 mutex_unlock(&pipe->mutex);
62275 }
62276 EXPORT_SYMBOL(pipe_unlock);
62277 @@ -449,9 +449,9 @@ redo:
62278 }
62279 if (bufs) /* More to do? */
62280 continue;
62281 - if (!pipe->writers)
62282 + if (!atomic_read(&pipe->writers))
62283 break;
62284 - if (!pipe->waiting_writers) {
62285 + if (!atomic_read(&pipe->waiting_writers)) {
62286 /* syscall merging: Usually we must not sleep
62287 * if O_NONBLOCK is set, or if we got some data.
62288 * But if a writer sleeps in kernel space, then
62289 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62290 ret = 0;
62291 __pipe_lock(pipe);
62292
62293 - if (!pipe->readers) {
62294 + if (!atomic_read(&pipe->readers)) {
62295 send_sig(SIGPIPE, current, 0);
62296 ret = -EPIPE;
62297 goto out;
62298 @@ -562,7 +562,7 @@ redo1:
62299 for (;;) {
62300 int bufs;
62301
62302 - if (!pipe->readers) {
62303 + if (!atomic_read(&pipe->readers)) {
62304 send_sig(SIGPIPE, current, 0);
62305 if (!ret)
62306 ret = -EPIPE;
62307 @@ -653,9 +653,9 @@ redo2:
62308 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62309 do_wakeup = 0;
62310 }
62311 - pipe->waiting_writers++;
62312 + atomic_inc(&pipe->waiting_writers);
62313 pipe_wait(pipe);
62314 - pipe->waiting_writers--;
62315 + atomic_dec(&pipe->waiting_writers);
62316 }
62317 out:
62318 __pipe_unlock(pipe);
62319 @@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62320 mask = 0;
62321 if (filp->f_mode & FMODE_READ) {
62322 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62323 - if (!pipe->writers && filp->f_version != pipe->w_counter)
62324 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62325 mask |= POLLHUP;
62326 }
62327
62328 @@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62329 * Most Unices do not set POLLERR for FIFOs but on Linux they
62330 * behave exactly like pipes for poll().
62331 */
62332 - if (!pipe->readers)
62333 + if (!atomic_read(&pipe->readers))
62334 mask |= POLLERR;
62335 }
62336
62337 @@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62338 int kill = 0;
62339
62340 spin_lock(&inode->i_lock);
62341 - if (!--pipe->files) {
62342 + if (atomic_dec_and_test(&pipe->files)) {
62343 inode->i_pipe = NULL;
62344 kill = 1;
62345 }
62346 @@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
62347
62348 __pipe_lock(pipe);
62349 if (file->f_mode & FMODE_READ)
62350 - pipe->readers--;
62351 + atomic_dec(&pipe->readers);
62352 if (file->f_mode & FMODE_WRITE)
62353 - pipe->writers--;
62354 + atomic_dec(&pipe->writers);
62355
62356 - if (pipe->readers || pipe->writers) {
62357 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62358 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62359 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62360 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62361 @@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62362 kfree(pipe);
62363 }
62364
62365 -static struct vfsmount *pipe_mnt __read_mostly;
62366 +struct vfsmount *pipe_mnt __read_mostly;
62367
62368 /*
62369 * pipefs_dname() is called from d_path().
62370 @@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
62371 goto fail_iput;
62372
62373 inode->i_pipe = pipe;
62374 - pipe->files = 2;
62375 - pipe->readers = pipe->writers = 1;
62376 + atomic_set(&pipe->files, 2);
62377 + atomic_set(&pipe->readers, 1);
62378 + atomic_set(&pipe->writers, 1);
62379 inode->i_fop = &pipefifo_fops;
62380
62381 /*
62382 @@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62383 spin_lock(&inode->i_lock);
62384 if (inode->i_pipe) {
62385 pipe = inode->i_pipe;
62386 - pipe->files++;
62387 + atomic_inc(&pipe->files);
62388 spin_unlock(&inode->i_lock);
62389 } else {
62390 spin_unlock(&inode->i_lock);
62391 pipe = alloc_pipe_info();
62392 if (!pipe)
62393 return -ENOMEM;
62394 - pipe->files = 1;
62395 + atomic_set(&pipe->files, 1);
62396 spin_lock(&inode->i_lock);
62397 if (unlikely(inode->i_pipe)) {
62398 - inode->i_pipe->files++;
62399 + atomic_inc(&inode->i_pipe->files);
62400 spin_unlock(&inode->i_lock);
62401 free_pipe_info(pipe);
62402 pipe = inode->i_pipe;
62403 @@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62404 * opened, even when there is no process writing the FIFO.
62405 */
62406 pipe->r_counter++;
62407 - if (pipe->readers++ == 0)
62408 + if (atomic_inc_return(&pipe->readers) == 1)
62409 wake_up_partner(pipe);
62410
62411 - if (!is_pipe && !pipe->writers) {
62412 + if (!is_pipe && !atomic_read(&pipe->writers)) {
62413 if ((filp->f_flags & O_NONBLOCK)) {
62414 /* suppress POLLHUP until we have
62415 * seen a writer */
62416 @@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62417 * errno=ENXIO when there is no process reading the FIFO.
62418 */
62419 ret = -ENXIO;
62420 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62421 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62422 goto err;
62423
62424 pipe->w_counter++;
62425 - if (!pipe->writers++)
62426 + if (atomic_inc_return(&pipe->writers) == 1)
62427 wake_up_partner(pipe);
62428
62429 - if (!is_pipe && !pipe->readers) {
62430 + if (!is_pipe && !atomic_read(&pipe->readers)) {
62431 if (wait_for_partner(pipe, &pipe->r_counter))
62432 goto err_wr;
62433 }
62434 @@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62435 * the process can at least talk to itself.
62436 */
62437
62438 - pipe->readers++;
62439 - pipe->writers++;
62440 + atomic_inc(&pipe->readers);
62441 + atomic_inc(&pipe->writers);
62442 pipe->r_counter++;
62443 pipe->w_counter++;
62444 - if (pipe->readers == 1 || pipe->writers == 1)
62445 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62446 wake_up_partner(pipe);
62447 break;
62448
62449 @@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62450 return 0;
62451
62452 err_rd:
62453 - if (!--pipe->readers)
62454 + if (atomic_dec_and_test(&pipe->readers))
62455 wake_up_interruptible(&pipe->wait);
62456 ret = -ERESTARTSYS;
62457 goto err;
62458
62459 err_wr:
62460 - if (!--pipe->writers)
62461 + if (atomic_dec_and_test(&pipe->writers))
62462 wake_up_interruptible(&pipe->wait);
62463 ret = -ERESTARTSYS;
62464 goto err;
62465 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62466 index 8bd2135..eab9adb 100644
62467 --- a/fs/posix_acl.c
62468 +++ b/fs/posix_acl.c
62469 @@ -19,6 +19,7 @@
62470 #include <linux/sched.h>
62471 #include <linux/posix_acl.h>
62472 #include <linux/export.h>
62473 +#include <linux/grsecurity.h>
62474
62475 #include <linux/errno.h>
62476
62477 @@ -183,7 +184,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62478 }
62479 }
62480 if (mode_p)
62481 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62482 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62483 return not_equiv;
62484 }
62485
62486 @@ -331,7 +332,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62487 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62488 }
62489
62490 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62491 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62492 return not_equiv;
62493 }
62494
62495 @@ -389,6 +390,8 @@ posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62496 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62497 int err = -ENOMEM;
62498 if (clone) {
62499 + *mode_p &= ~gr_acl_umask();
62500 +
62501 err = posix_acl_create_masq(clone, mode_p);
62502 if (err < 0) {
62503 posix_acl_release(clone);
62504 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62505 index 2183fcf..3c32a98 100644
62506 --- a/fs/proc/Kconfig
62507 +++ b/fs/proc/Kconfig
62508 @@ -30,7 +30,7 @@ config PROC_FS
62509
62510 config PROC_KCORE
62511 bool "/proc/kcore support" if !ARM
62512 - depends on PROC_FS && MMU
62513 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62514 help
62515 Provides a virtual ELF core file of the live kernel. This can
62516 be read with gdb and other ELF tools. No modifications can be
62517 @@ -38,8 +38,8 @@ config PROC_KCORE
62518
62519 config PROC_VMCORE
62520 bool "/proc/vmcore support"
62521 - depends on PROC_FS && CRASH_DUMP
62522 - default y
62523 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62524 + default n
62525 help
62526 Exports the dump image of crashed kernel in ELF format.
62527
62528 @@ -63,8 +63,8 @@ config PROC_SYSCTL
62529 limited in memory.
62530
62531 config PROC_PAGE_MONITOR
62532 - default y
62533 - depends on PROC_FS && MMU
62534 + default n
62535 + depends on PROC_FS && MMU && !GRKERNSEC
62536 bool "Enable /proc page monitoring" if EXPERT
62537 help
62538 Various /proc files exist to monitor process memory utilization:
62539 diff --git a/fs/proc/array.c b/fs/proc/array.c
62540 index 1bd2077..2f7cfd5 100644
62541 --- a/fs/proc/array.c
62542 +++ b/fs/proc/array.c
62543 @@ -60,6 +60,7 @@
62544 #include <linux/tty.h>
62545 #include <linux/string.h>
62546 #include <linux/mman.h>
62547 +#include <linux/grsecurity.h>
62548 #include <linux/proc_fs.h>
62549 #include <linux/ioport.h>
62550 #include <linux/uaccess.h>
62551 @@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62552 seq_putc(m, '\n');
62553 }
62554
62555 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62556 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
62557 +{
62558 + if (p->mm)
62559 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62560 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62561 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62562 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62563 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62564 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62565 + else
62566 + seq_printf(m, "PaX:\t-----\n");
62567 +}
62568 +#endif
62569 +
62570 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62571 struct pid *pid, struct task_struct *task)
62572 {
62573 @@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62574 task_cpus_allowed(m, task);
62575 cpuset_task_status_allowed(m, task);
62576 task_context_switch_counts(m, task);
62577 +
62578 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62579 + task_pax(m, task);
62580 +#endif
62581 +
62582 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62583 + task_grsec_rbac(m, task);
62584 +#endif
62585 +
62586 return 0;
62587 }
62588
62589 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62590 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62591 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62592 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62593 +#endif
62594 +
62595 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62596 struct pid *pid, struct task_struct *task, int whole)
62597 {
62598 @@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62599 char tcomm[sizeof(task->comm)];
62600 unsigned long flags;
62601
62602 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62603 + if (current->exec_id != m->exec_id) {
62604 + gr_log_badprocpid("stat");
62605 + return 0;
62606 + }
62607 +#endif
62608 +
62609 state = *get_task_state(task);
62610 vsize = eip = esp = 0;
62611 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62612 @@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62613 gtime = task_gtime(task);
62614 }
62615
62616 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62617 + if (PAX_RAND_FLAGS(mm)) {
62618 + eip = 0;
62619 + esp = 0;
62620 + wchan = 0;
62621 + }
62622 +#endif
62623 +#ifdef CONFIG_GRKERNSEC_HIDESYM
62624 + wchan = 0;
62625 + eip =0;
62626 + esp =0;
62627 +#endif
62628 +
62629 /* scale priority and nice values from timeslices to -20..20 */
62630 /* to make it look like a "normal" Unix priority/nice value */
62631 priority = task_prio(task);
62632 @@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62633 seq_put_decimal_ull(m, ' ', vsize);
62634 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
62635 seq_put_decimal_ull(m, ' ', rsslim);
62636 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62637 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
62638 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
62639 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
62640 +#else
62641 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
62642 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
62643 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
62644 +#endif
62645 seq_put_decimal_ull(m, ' ', esp);
62646 seq_put_decimal_ull(m, ' ', eip);
62647 /* The signal information here is obsolete.
62648 @@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62649 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
62650 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
62651
62652 - if (mm && permitted) {
62653 + if (mm && permitted
62654 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62655 + && !PAX_RAND_FLAGS(mm)
62656 +#endif
62657 + ) {
62658 seq_put_decimal_ull(m, ' ', mm->start_data);
62659 seq_put_decimal_ull(m, ' ', mm->end_data);
62660 seq_put_decimal_ull(m, ' ', mm->start_brk);
62661 @@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62662 struct pid *pid, struct task_struct *task)
62663 {
62664 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
62665 - struct mm_struct *mm = get_task_mm(task);
62666 + struct mm_struct *mm;
62667
62668 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62669 + if (current->exec_id != m->exec_id) {
62670 + gr_log_badprocpid("statm");
62671 + return 0;
62672 + }
62673 +#endif
62674 + mm = get_task_mm(task);
62675 if (mm) {
62676 size = task_statm(mm, &shared, &text, &data, &resident);
62677 mmput(mm);
62678 @@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62679 return 0;
62680 }
62681
62682 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62683 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
62684 +{
62685 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
62686 +}
62687 +#endif
62688 +
62689 #ifdef CONFIG_CHECKPOINT_RESTORE
62690 static struct pid *
62691 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
62692 diff --git a/fs/proc/base.c b/fs/proc/base.c
62693 index 03c8d74..68a79e8 100644
62694 --- a/fs/proc/base.c
62695 +++ b/fs/proc/base.c
62696 @@ -113,6 +113,14 @@ struct pid_entry {
62697 union proc_op op;
62698 };
62699
62700 +struct getdents_callback {
62701 + struct linux_dirent __user * current_dir;
62702 + struct linux_dirent __user * previous;
62703 + struct file * file;
62704 + int count;
62705 + int error;
62706 +};
62707 +
62708 #define NOD(NAME, MODE, IOP, FOP, OP) { \
62709 .name = (NAME), \
62710 .len = sizeof(NAME) - 1, \
62711 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
62712 if (!mm->arg_end)
62713 goto out_mm; /* Shh! No looking before we're done */
62714
62715 + if (gr_acl_handle_procpidmem(task))
62716 + goto out_mm;
62717 +
62718 len = mm->arg_end - mm->arg_start;
62719
62720 if (len > PAGE_SIZE)
62721 @@ -237,12 +248,28 @@ out:
62722 return res;
62723 }
62724
62725 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62726 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62727 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62728 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62729 +#endif
62730 +
62731 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62732 {
62733 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62734 int res = PTR_ERR(mm);
62735 if (mm && !IS_ERR(mm)) {
62736 unsigned int nwords = 0;
62737 +
62738 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62739 + /* allow if we're currently ptracing this task */
62740 + if (PAX_RAND_FLAGS(mm) &&
62741 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62742 + mmput(mm);
62743 + return 0;
62744 + }
62745 +#endif
62746 +
62747 do {
62748 nwords += 2;
62749 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62750 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62751 }
62752
62753
62754 -#ifdef CONFIG_KALLSYMS
62755 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62756 /*
62757 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62758 * Returns the resolved symbol. If that fails, simply return the address.
62759 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62760 mutex_unlock(&task->signal->cred_guard_mutex);
62761 }
62762
62763 -#ifdef CONFIG_STACKTRACE
62764 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62765
62766 #define MAX_STACK_TRACE_DEPTH 64
62767
62768 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62769 return count;
62770 }
62771
62772 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62773 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62774 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62775 {
62776 long nr;
62777 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62778 /************************************************************************/
62779
62780 /* permission checks */
62781 -static int proc_fd_access_allowed(struct inode *inode)
62782 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62783 {
62784 struct task_struct *task;
62785 int allowed = 0;
62786 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62787 */
62788 task = get_proc_task(inode);
62789 if (task) {
62790 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62791 + if (log)
62792 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62793 + else
62794 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62795 put_task_struct(task);
62796 }
62797 return allowed;
62798 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
62799 struct task_struct *task,
62800 int hide_pid_min)
62801 {
62802 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62803 + return false;
62804 +
62805 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62806 + rcu_read_lock();
62807 + {
62808 + const struct cred *tmpcred = current_cred();
62809 + const struct cred *cred = __task_cred(task);
62810 +
62811 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
62812 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62813 + || in_group_p(grsec_proc_gid)
62814 +#endif
62815 + ) {
62816 + rcu_read_unlock();
62817 + return true;
62818 + }
62819 + }
62820 + rcu_read_unlock();
62821 +
62822 + if (!pid->hide_pid)
62823 + return false;
62824 +#endif
62825 +
62826 if (pid->hide_pid < hide_pid_min)
62827 return true;
62828 if (in_group_p(pid->pid_gid))
62829 return true;
62830 +
62831 return ptrace_may_access(task, PTRACE_MODE_READ);
62832 }
62833
62834 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
62835 put_task_struct(task);
62836
62837 if (!has_perms) {
62838 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62839 + {
62840 +#else
62841 if (pid->hide_pid == 2) {
62842 +#endif
62843 /*
62844 * Let's make getdents(), stat(), and open()
62845 * consistent with each other. If a process
62846 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62847 if (!task)
62848 return -ESRCH;
62849
62850 + if (gr_acl_handle_procpidmem(task)) {
62851 + put_task_struct(task);
62852 + return -EPERM;
62853 + }
62854 +
62855 mm = mm_access(task, mode);
62856 put_task_struct(task);
62857
62858 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62859
62860 file->private_data = mm;
62861
62862 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62863 + file->f_version = current->exec_id;
62864 +#endif
62865 +
62866 return 0;
62867 }
62868
62869 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62870 ssize_t copied;
62871 char *page;
62872
62873 +#ifdef CONFIG_GRKERNSEC
62874 + if (write)
62875 + return -EPERM;
62876 +#endif
62877 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62878 + if (file->f_version != current->exec_id) {
62879 + gr_log_badprocpid("mem");
62880 + return 0;
62881 + }
62882 +#endif
62883 +
62884 if (!mm)
62885 return 0;
62886
62887 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62888 goto free;
62889
62890 while (count > 0) {
62891 - int this_len = min_t(int, count, PAGE_SIZE);
62892 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
62893
62894 if (write && copy_from_user(page, buf, this_len)) {
62895 copied = -EFAULT;
62896 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62897 if (!mm)
62898 return 0;
62899
62900 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62901 + if (file->f_version != current->exec_id) {
62902 + gr_log_badprocpid("environ");
62903 + return 0;
62904 + }
62905 +#endif
62906 +
62907 page = (char *)__get_free_page(GFP_TEMPORARY);
62908 if (!page)
62909 return -ENOMEM;
62910 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62911 goto free;
62912 while (count > 0) {
62913 size_t this_len, max_len;
62914 - int retval;
62915 + ssize_t retval;
62916
62917 if (src >= (mm->env_end - mm->env_start))
62918 break;
62919 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
62920 int error = -EACCES;
62921
62922 /* Are we allowed to snoop on the tasks file descriptors? */
62923 - if (!proc_fd_access_allowed(inode))
62924 + if (!proc_fd_access_allowed(inode, 0))
62925 goto out;
62926
62927 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62928 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
62929 struct path path;
62930
62931 /* Are we allowed to snoop on the tasks file descriptors? */
62932 - if (!proc_fd_access_allowed(inode))
62933 - goto out;
62934 + /* logging this is needed for learning on chromium to work properly,
62935 + but we don't want to flood the logs from 'ps' which does a readlink
62936 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
62937 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
62938 + */
62939 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
62940 + if (!proc_fd_access_allowed(inode,0))
62941 + goto out;
62942 + } else {
62943 + if (!proc_fd_access_allowed(inode,1))
62944 + goto out;
62945 + }
62946
62947 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62948 if (error)
62949 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
62950 rcu_read_lock();
62951 cred = __task_cred(task);
62952 inode->i_uid = cred->euid;
62953 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62954 + inode->i_gid = grsec_proc_gid;
62955 +#else
62956 inode->i_gid = cred->egid;
62957 +#endif
62958 rcu_read_unlock();
62959 }
62960 security_task_to_inode(task, inode);
62961 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
62962 return -ENOENT;
62963 }
62964 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62965 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62966 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62967 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62968 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62969 +#endif
62970 task_dumpable(task)) {
62971 cred = __task_cred(task);
62972 stat->uid = cred->euid;
62973 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62974 + stat->gid = grsec_proc_gid;
62975 +#else
62976 stat->gid = cred->egid;
62977 +#endif
62978 }
62979 }
62980 rcu_read_unlock();
62981 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
62982
62983 if (task) {
62984 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62985 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62986 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62987 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62988 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62989 +#endif
62990 task_dumpable(task)) {
62991 rcu_read_lock();
62992 cred = __task_cred(task);
62993 inode->i_uid = cred->euid;
62994 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62995 + inode->i_gid = grsec_proc_gid;
62996 +#else
62997 inode->i_gid = cred->egid;
62998 +#endif
62999 rcu_read_unlock();
63000 } else {
63001 inode->i_uid = GLOBAL_ROOT_UID;
63002 @@ -1819,6 +1937,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
63003 if (rc)
63004 goto out_mmput;
63005
63006 + rc = -ENOENT;
63007 down_read(&mm->mmap_sem);
63008 vma = find_exact_vma(mm, vm_start, vm_end);
63009 if (vma && vma->vm_file) {
63010 @@ -2172,6 +2291,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63011 if (!task)
63012 goto out_no_task;
63013
63014 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63015 + goto out;
63016 +
63017 /*
63018 * Yes, it does not scale. And it should not. Don't add
63019 * new entries into /proc/<tgid>/ without very good reasons.
63020 @@ -2202,6 +2324,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63021 if (!task)
63022 return -ENOENT;
63023
63024 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63025 + goto out;
63026 +
63027 if (!dir_emit_dots(file, ctx))
63028 goto out;
63029
63030 @@ -2591,7 +2716,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63031 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63032 #endif
63033 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63034 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63035 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63036 INF("syscall", S_IRUGO, proc_pid_syscall),
63037 #endif
63038 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63039 @@ -2616,10 +2741,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63040 #ifdef CONFIG_SECURITY
63041 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63042 #endif
63043 -#ifdef CONFIG_KALLSYMS
63044 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63045 INF("wchan", S_IRUGO, proc_pid_wchan),
63046 #endif
63047 -#ifdef CONFIG_STACKTRACE
63048 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63049 ONE("stack", S_IRUGO, proc_pid_stack),
63050 #endif
63051 #ifdef CONFIG_SCHEDSTATS
63052 @@ -2653,6 +2778,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63053 #ifdef CONFIG_HARDWALL
63054 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63055 #endif
63056 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63057 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63058 +#endif
63059 #ifdef CONFIG_USER_NS
63060 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63061 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63062 @@ -2783,7 +2911,14 @@ static int proc_pid_instantiate(struct inode *dir,
63063 if (!inode)
63064 goto out;
63065
63066 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63067 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63068 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63069 + inode->i_gid = grsec_proc_gid;
63070 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63071 +#else
63072 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63073 +#endif
63074 inode->i_op = &proc_tgid_base_inode_operations;
63075 inode->i_fop = &proc_tgid_base_operations;
63076 inode->i_flags|=S_IMMUTABLE;
63077 @@ -2821,7 +2956,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63078 if (!task)
63079 goto out;
63080
63081 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63082 + goto out_put_task;
63083 +
63084 result = proc_pid_instantiate(dir, dentry, task, NULL);
63085 +out_put_task:
63086 put_task_struct(task);
63087 out:
63088 return ERR_PTR(result);
63089 @@ -2927,7 +3066,7 @@ static const struct pid_entry tid_base_stuff[] = {
63090 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63091 #endif
63092 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63093 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63094 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63095 INF("syscall", S_IRUGO, proc_pid_syscall),
63096 #endif
63097 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63098 @@ -2954,10 +3093,10 @@ static const struct pid_entry tid_base_stuff[] = {
63099 #ifdef CONFIG_SECURITY
63100 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63101 #endif
63102 -#ifdef CONFIG_KALLSYMS
63103 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63104 INF("wchan", S_IRUGO, proc_pid_wchan),
63105 #endif
63106 -#ifdef CONFIG_STACKTRACE
63107 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63108 ONE("stack", S_IRUGO, proc_pid_stack),
63109 #endif
63110 #ifdef CONFIG_SCHEDSTATS
63111 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63112 index 82676e3..5f8518a 100644
63113 --- a/fs/proc/cmdline.c
63114 +++ b/fs/proc/cmdline.c
63115 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63116
63117 static int __init proc_cmdline_init(void)
63118 {
63119 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63120 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63121 +#else
63122 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63123 +#endif
63124 return 0;
63125 }
63126 module_init(proc_cmdline_init);
63127 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63128 index b143471..bb105e5 100644
63129 --- a/fs/proc/devices.c
63130 +++ b/fs/proc/devices.c
63131 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63132
63133 static int __init proc_devices_init(void)
63134 {
63135 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63136 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63137 +#else
63138 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63139 +#endif
63140 return 0;
63141 }
63142 module_init(proc_devices_init);
63143 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63144 index 985ea88..d118a0a 100644
63145 --- a/fs/proc/fd.c
63146 +++ b/fs/proc/fd.c
63147 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63148 if (!task)
63149 return -ENOENT;
63150
63151 - files = get_files_struct(task);
63152 + if (!gr_acl_handle_procpidmem(task))
63153 + files = get_files_struct(task);
63154 put_task_struct(task);
63155
63156 if (files) {
63157 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63158 */
63159 int proc_fd_permission(struct inode *inode, int mask)
63160 {
63161 + struct task_struct *task;
63162 int rv = generic_permission(inode, mask);
63163 - if (rv == 0)
63164 - return 0;
63165 +
63166 if (task_tgid(current) == proc_pid(inode))
63167 rv = 0;
63168 +
63169 + task = get_proc_task(inode);
63170 + if (task == NULL)
63171 + return rv;
63172 +
63173 + if (gr_acl_handle_procpidmem(task))
63174 + rv = -EACCES;
63175 +
63176 + put_task_struct(task);
63177 +
63178 return rv;
63179 }
63180
63181 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63182 index 124fc43..8afbb02 100644
63183 --- a/fs/proc/inode.c
63184 +++ b/fs/proc/inode.c
63185 @@ -23,11 +23,17 @@
63186 #include <linux/slab.h>
63187 #include <linux/mount.h>
63188 #include <linux/magic.h>
63189 +#include <linux/grsecurity.h>
63190
63191 #include <asm/uaccess.h>
63192
63193 #include "internal.h"
63194
63195 +#ifdef CONFIG_PROC_SYSCTL
63196 +extern const struct inode_operations proc_sys_inode_operations;
63197 +extern const struct inode_operations proc_sys_dir_operations;
63198 +#endif
63199 +
63200 static void proc_evict_inode(struct inode *inode)
63201 {
63202 struct proc_dir_entry *de;
63203 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63204 ns = PROC_I(inode)->ns.ns;
63205 if (ns_ops && ns)
63206 ns_ops->put(ns);
63207 +
63208 +#ifdef CONFIG_PROC_SYSCTL
63209 + if (inode->i_op == &proc_sys_inode_operations ||
63210 + inode->i_op == &proc_sys_dir_operations)
63211 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63212 +#endif
63213 +
63214 }
63215
63216 static struct kmem_cache * proc_inode_cachep;
63217 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63218 if (de->mode) {
63219 inode->i_mode = de->mode;
63220 inode->i_uid = de->uid;
63221 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63222 + inode->i_gid = grsec_proc_gid;
63223 +#else
63224 inode->i_gid = de->gid;
63225 +#endif
63226 }
63227 if (de->size)
63228 inode->i_size = de->size;
63229 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63230 index 651d09a..3d7f0bf 100644
63231 --- a/fs/proc/internal.h
63232 +++ b/fs/proc/internal.h
63233 @@ -48,7 +48,7 @@ struct proc_dir_entry {
63234 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63235 u8 namelen;
63236 char name[];
63237 -};
63238 +} __randomize_layout;
63239
63240 union proc_op {
63241 int (*proc_get_link)(struct dentry *, struct path *);
63242 @@ -67,7 +67,7 @@ struct proc_inode {
63243 struct ctl_table *sysctl_entry;
63244 struct proc_ns ns;
63245 struct inode vfs_inode;
63246 -};
63247 +} __randomize_layout;
63248
63249 /*
63250 * General functions
63251 @@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63252 struct pid *, struct task_struct *);
63253 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63254 struct pid *, struct task_struct *);
63255 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63256 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63257 +#endif
63258
63259 /*
63260 * base.c
63261 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63262 index 05029c0..7ea1987 100644
63263 --- a/fs/proc/interrupts.c
63264 +++ b/fs/proc/interrupts.c
63265 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63266
63267 static int __init proc_interrupts_init(void)
63268 {
63269 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63270 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63271 +#else
63272 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63273 +#endif
63274 return 0;
63275 }
63276 module_init(proc_interrupts_init);
63277 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63278 index 5ed0e52..a1c1f2e 100644
63279 --- a/fs/proc/kcore.c
63280 +++ b/fs/proc/kcore.c
63281 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63282 * the addresses in the elf_phdr on our list.
63283 */
63284 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63285 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63286 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63287 + if (tsz > buflen)
63288 tsz = buflen;
63289 -
63290 +
63291 while (buflen) {
63292 struct kcore_list *m;
63293
63294 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63295 kfree(elf_buf);
63296 } else {
63297 if (kern_addr_valid(start)) {
63298 - unsigned long n;
63299 + char *elf_buf;
63300 + mm_segment_t oldfs;
63301
63302 - n = copy_to_user(buffer, (char *)start, tsz);
63303 - /*
63304 - * We cannot distinguish between fault on source
63305 - * and fault on destination. When this happens
63306 - * we clear too and hope it will trigger the
63307 - * EFAULT again.
63308 - */
63309 - if (n) {
63310 - if (clear_user(buffer + tsz - n,
63311 - n))
63312 + elf_buf = kmalloc(tsz, GFP_KERNEL);
63313 + if (!elf_buf)
63314 + return -ENOMEM;
63315 + oldfs = get_fs();
63316 + set_fs(KERNEL_DS);
63317 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63318 + set_fs(oldfs);
63319 + if (copy_to_user(buffer, elf_buf, tsz)) {
63320 + kfree(elf_buf);
63321 return -EFAULT;
63322 + }
63323 }
63324 + set_fs(oldfs);
63325 + kfree(elf_buf);
63326 } else {
63327 if (clear_user(buffer, tsz))
63328 return -EFAULT;
63329 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63330
63331 static int open_kcore(struct inode *inode, struct file *filp)
63332 {
63333 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63334 + return -EPERM;
63335 +#endif
63336 if (!capable(CAP_SYS_RAWIO))
63337 return -EPERM;
63338 if (kcore_need_update)
63339 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63340 index a77d2b2..a9153f0 100644
63341 --- a/fs/proc/meminfo.c
63342 +++ b/fs/proc/meminfo.c
63343 @@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63344 vmi.used >> 10,
63345 vmi.largest_chunk >> 10
63346 #ifdef CONFIG_MEMORY_FAILURE
63347 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63348 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63349 #endif
63350 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63351 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63352 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63353 index 5f9bc8a..5c35f08 100644
63354 --- a/fs/proc/nommu.c
63355 +++ b/fs/proc/nommu.c
63356 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63357
63358 if (file) {
63359 seq_pad(m, ' ');
63360 - seq_path(m, &file->f_path, "");
63361 + seq_path(m, &file->f_path, "\n\\");
63362 }
63363
63364 seq_putc(m, '\n');
63365 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63366 index 4677bb7..408e936 100644
63367 --- a/fs/proc/proc_net.c
63368 +++ b/fs/proc/proc_net.c
63369 @@ -23,6 +23,7 @@
63370 #include <linux/nsproxy.h>
63371 #include <net/net_namespace.h>
63372 #include <linux/seq_file.h>
63373 +#include <linux/grsecurity.h>
63374
63375 #include "internal.h"
63376
63377 @@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
63378 struct task_struct *task;
63379 struct nsproxy *ns;
63380 struct net *net = NULL;
63381 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63382 + const struct cred *cred = current_cred();
63383 +#endif
63384 +
63385 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63386 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
63387 + return net;
63388 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63389 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
63390 + return net;
63391 +#endif
63392
63393 rcu_read_lock();
63394 task = pid_task(proc_pid(dir), PIDTYPE_PID);
63395 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63396 index 7129046..6914844 100644
63397 --- a/fs/proc/proc_sysctl.c
63398 +++ b/fs/proc/proc_sysctl.c
63399 @@ -11,13 +11,21 @@
63400 #include <linux/namei.h>
63401 #include <linux/mm.h>
63402 #include <linux/module.h>
63403 +#include <linux/nsproxy.h>
63404 +#ifdef CONFIG_GRKERNSEC
63405 +#include <net/net_namespace.h>
63406 +#endif
63407 #include "internal.h"
63408
63409 +extern int gr_handle_chroot_sysctl(const int op);
63410 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63411 + const int op);
63412 +
63413 static const struct dentry_operations proc_sys_dentry_operations;
63414 static const struct file_operations proc_sys_file_operations;
63415 -static const struct inode_operations proc_sys_inode_operations;
63416 +const struct inode_operations proc_sys_inode_operations;
63417 static const struct file_operations proc_sys_dir_file_operations;
63418 -static const struct inode_operations proc_sys_dir_operations;
63419 +const struct inode_operations proc_sys_dir_operations;
63420
63421 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63422 {
63423 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63424
63425 err = NULL;
63426 d_set_d_op(dentry, &proc_sys_dentry_operations);
63427 +
63428 + gr_handle_proc_create(dentry, inode);
63429 +
63430 d_add(dentry, inode);
63431
63432 out:
63433 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63434 struct inode *inode = file_inode(filp);
63435 struct ctl_table_header *head = grab_header(inode);
63436 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63437 + int op = write ? MAY_WRITE : MAY_READ;
63438 ssize_t error;
63439 size_t res;
63440
63441 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63442 * and won't be until we finish.
63443 */
63444 error = -EPERM;
63445 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63446 + if (sysctl_perm(head, table, op))
63447 goto out;
63448
63449 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63450 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63451 if (!table->proc_handler)
63452 goto out;
63453
63454 +#ifdef CONFIG_GRKERNSEC
63455 + error = -EPERM;
63456 + if (gr_handle_chroot_sysctl(op))
63457 + goto out;
63458 + dget(filp->f_path.dentry);
63459 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63460 + dput(filp->f_path.dentry);
63461 + goto out;
63462 + }
63463 + dput(filp->f_path.dentry);
63464 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63465 + goto out;
63466 + if (write) {
63467 + if (current->nsproxy->net_ns != table->extra2) {
63468 + if (!capable(CAP_SYS_ADMIN))
63469 + goto out;
63470 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63471 + goto out;
63472 + }
63473 +#endif
63474 +
63475 /* careful: calling conventions are nasty here */
63476 res = count;
63477 error = table->proc_handler(table, write, buf, &res, ppos);
63478 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63479 return false;
63480 } else {
63481 d_set_d_op(child, &proc_sys_dentry_operations);
63482 +
63483 + gr_handle_proc_create(child, inode);
63484 +
63485 d_add(child, inode);
63486 }
63487 } else {
63488 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63489 if ((*pos)++ < ctx->pos)
63490 return true;
63491
63492 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63493 + return 0;
63494 +
63495 if (unlikely(S_ISLNK(table->mode)))
63496 res = proc_sys_link_fill_cache(file, ctx, head, table);
63497 else
63498 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
63499 if (IS_ERR(head))
63500 return PTR_ERR(head);
63501
63502 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
63503 + return -ENOENT;
63504 +
63505 generic_fillattr(inode, stat);
63506 if (table)
63507 stat->mode = (stat->mode & S_IFMT) | table->mode;
63508 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
63509 .llseek = generic_file_llseek,
63510 };
63511
63512 -static const struct inode_operations proc_sys_inode_operations = {
63513 +const struct inode_operations proc_sys_inode_operations = {
63514 .permission = proc_sys_permission,
63515 .setattr = proc_sys_setattr,
63516 .getattr = proc_sys_getattr,
63517 };
63518
63519 -static const struct inode_operations proc_sys_dir_operations = {
63520 +const struct inode_operations proc_sys_dir_operations = {
63521 .lookup = proc_sys_lookup,
63522 .permission = proc_sys_permission,
63523 .setattr = proc_sys_setattr,
63524 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
63525 static struct ctl_dir *new_dir(struct ctl_table_set *set,
63526 const char *name, int namelen)
63527 {
63528 - struct ctl_table *table;
63529 + ctl_table_no_const *table;
63530 struct ctl_dir *new;
63531 struct ctl_node *node;
63532 char *new_name;
63533 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
63534 return NULL;
63535
63536 node = (struct ctl_node *)(new + 1);
63537 - table = (struct ctl_table *)(node + 1);
63538 + table = (ctl_table_no_const *)(node + 1);
63539 new_name = (char *)(table + 2);
63540 memcpy(new_name, name, namelen);
63541 new_name[namelen] = '\0';
63542 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
63543 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
63544 struct ctl_table_root *link_root)
63545 {
63546 - struct ctl_table *link_table, *entry, *link;
63547 + ctl_table_no_const *link_table, *link;
63548 + struct ctl_table *entry;
63549 struct ctl_table_header *links;
63550 struct ctl_node *node;
63551 char *link_name;
63552 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
63553 return NULL;
63554
63555 node = (struct ctl_node *)(links + 1);
63556 - link_table = (struct ctl_table *)(node + nr_entries);
63557 + link_table = (ctl_table_no_const *)(node + nr_entries);
63558 link_name = (char *)&link_table[nr_entries + 1];
63559
63560 for (link = link_table, entry = table; entry->procname; link++, entry++) {
63561 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63562 struct ctl_table_header ***subheader, struct ctl_table_set *set,
63563 struct ctl_table *table)
63564 {
63565 - struct ctl_table *ctl_table_arg = NULL;
63566 - struct ctl_table *entry, *files;
63567 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
63568 + struct ctl_table *entry;
63569 int nr_files = 0;
63570 int nr_dirs = 0;
63571 int err = -ENOMEM;
63572 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63573 nr_files++;
63574 }
63575
63576 - files = table;
63577 /* If there are mixed files and directories we need a new table */
63578 if (nr_dirs && nr_files) {
63579 - struct ctl_table *new;
63580 + ctl_table_no_const *new;
63581 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
63582 GFP_KERNEL);
63583 if (!files)
63584 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63585 /* Register everything except a directory full of subdirectories */
63586 if (nr_files || !nr_dirs) {
63587 struct ctl_table_header *header;
63588 - header = __register_sysctl_table(set, path, files);
63589 + header = __register_sysctl_table(set, path, files ? files : table);
63590 if (!header) {
63591 kfree(ctl_table_arg);
63592 goto out;
63593 diff --git a/fs/proc/root.c b/fs/proc/root.c
63594 index 87dbcbe..55e1b4d 100644
63595 --- a/fs/proc/root.c
63596 +++ b/fs/proc/root.c
63597 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
63598 #ifdef CONFIG_PROC_DEVICETREE
63599 proc_device_tree_init();
63600 #endif
63601 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63602 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63603 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
63604 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63605 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
63606 +#endif
63607 +#else
63608 proc_mkdir("bus", NULL);
63609 +#endif
63610 proc_sys_init();
63611 }
63612
63613 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
63614 index 1cf86c0..0ee1ca5 100644
63615 --- a/fs/proc/stat.c
63616 +++ b/fs/proc/stat.c
63617 @@ -11,6 +11,7 @@
63618 #include <linux/irqnr.h>
63619 #include <asm/cputime.h>
63620 #include <linux/tick.h>
63621 +#include <linux/grsecurity.h>
63622
63623 #ifndef arch_irq_stat_cpu
63624 #define arch_irq_stat_cpu(cpu) 0
63625 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
63626 u64 sum_softirq = 0;
63627 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
63628 struct timespec boottime;
63629 + int unrestricted = 1;
63630 +
63631 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63632 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63633 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
63634 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63635 + && !in_group_p(grsec_proc_gid)
63636 +#endif
63637 + )
63638 + unrestricted = 0;
63639 +#endif
63640 +#endif
63641
63642 user = nice = system = idle = iowait =
63643 irq = softirq = steal = 0;
63644 @@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
63645 getboottime(&boottime);
63646 jif = boottime.tv_sec;
63647
63648 + if (unrestricted) {
63649 for_each_possible_cpu(i) {
63650 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
63651 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63652 @@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
63653 }
63654 }
63655 sum += arch_irq_stat();
63656 + }
63657
63658 seq_puts(p, "cpu ");
63659 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63660 @@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
63661 seq_putc(p, '\n');
63662
63663 for_each_online_cpu(i) {
63664 + if (unrestricted) {
63665 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
63666 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
63667 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63668 @@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
63669 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
63670 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
63671 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
63672 + }
63673 seq_printf(p, "cpu%d", i);
63674 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63675 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
63676 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
63677
63678 /* sum again ? it could be updated? */
63679 for_each_irq_nr(j)
63680 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
63681 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
63682
63683 seq_printf(p,
63684 "\nctxt %llu\n"
63685 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
63686 "processes %lu\n"
63687 "procs_running %lu\n"
63688 "procs_blocked %lu\n",
63689 - nr_context_switches(),
63690 + unrestricted ? nr_context_switches() : 0ULL,
63691 (unsigned long)jif,
63692 - total_forks,
63693 - nr_running(),
63694 - nr_iowait());
63695 + unrestricted ? total_forks : 0UL,
63696 + unrestricted ? nr_running() : 0UL,
63697 + unrestricted ? nr_iowait() : 0UL);
63698
63699 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
63700
63701 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
63702 index fb52b54..5fc7c14 100644
63703 --- a/fs/proc/task_mmu.c
63704 +++ b/fs/proc/task_mmu.c
63705 @@ -12,12 +12,19 @@
63706 #include <linux/swap.h>
63707 #include <linux/swapops.h>
63708 #include <linux/mmu_notifier.h>
63709 +#include <linux/grsecurity.h>
63710
63711 #include <asm/elf.h>
63712 #include <asm/uaccess.h>
63713 #include <asm/tlbflush.h>
63714 #include "internal.h"
63715
63716 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63717 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63718 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63719 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63720 +#endif
63721 +
63722 void task_mem(struct seq_file *m, struct mm_struct *mm)
63723 {
63724 unsigned long data, text, lib, swap;
63725 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63726 "VmExe:\t%8lu kB\n"
63727 "VmLib:\t%8lu kB\n"
63728 "VmPTE:\t%8lu kB\n"
63729 - "VmSwap:\t%8lu kB\n",
63730 - hiwater_vm << (PAGE_SHIFT-10),
63731 + "VmSwap:\t%8lu kB\n"
63732 +
63733 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63734 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63735 +#endif
63736 +
63737 + ,hiwater_vm << (PAGE_SHIFT-10),
63738 total_vm << (PAGE_SHIFT-10),
63739 mm->locked_vm << (PAGE_SHIFT-10),
63740 mm->pinned_vm << (PAGE_SHIFT-10),
63741 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63742 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63743 (PTRS_PER_PTE * sizeof(pte_t) *
63744 atomic_long_read(&mm->nr_ptes)) >> 10,
63745 - swap << (PAGE_SHIFT-10));
63746 + swap << (PAGE_SHIFT-10)
63747 +
63748 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63749 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63750 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63751 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63752 +#else
63753 + , mm->context.user_cs_base
63754 + , mm->context.user_cs_limit
63755 +#endif
63756 +#endif
63757 +
63758 + );
63759 }
63760
63761 unsigned long task_vsize(struct mm_struct *mm)
63762 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63763 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63764 }
63765
63766 - /* We don't show the stack guard page in /proc/maps */
63767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63768 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63769 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63770 +#else
63771 start = vma->vm_start;
63772 - if (stack_guard_page_start(vma, start))
63773 - start += PAGE_SIZE;
63774 end = vma->vm_end;
63775 - if (stack_guard_page_end(vma, end))
63776 - end -= PAGE_SIZE;
63777 +#endif
63778
63779 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63780 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63781 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63782 flags & VM_WRITE ? 'w' : '-',
63783 flags & VM_EXEC ? 'x' : '-',
63784 flags & VM_MAYSHARE ? 's' : 'p',
63785 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63786 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63787 +#else
63788 pgoff,
63789 +#endif
63790 MAJOR(dev), MINOR(dev), ino);
63791
63792 /*
63793 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63794 */
63795 if (file) {
63796 seq_pad(m, ' ');
63797 - seq_path(m, &file->f_path, "\n");
63798 + seq_path(m, &file->f_path, "\n\\");
63799 goto done;
63800 }
63801
63802 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63803 * Thread stack in /proc/PID/task/TID/maps or
63804 * the main process stack.
63805 */
63806 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
63807 - vma->vm_end >= mm->start_stack)) {
63808 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
63809 + (vma->vm_start <= mm->start_stack &&
63810 + vma->vm_end >= mm->start_stack)) {
63811 name = "[stack]";
63812 } else {
63813 /* Thread stack in /proc/PID/maps */
63814 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
63815 struct proc_maps_private *priv = m->private;
63816 struct task_struct *task = priv->task;
63817
63818 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63819 + if (current->exec_id != m->exec_id) {
63820 + gr_log_badprocpid("maps");
63821 + return 0;
63822 + }
63823 +#endif
63824 +
63825 show_map_vma(m, vma, is_pid);
63826
63827 if (m->count < m->size) /* vma is copied successfully */
63828 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63829 .private = &mss,
63830 };
63831
63832 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63833 + if (current->exec_id != m->exec_id) {
63834 + gr_log_badprocpid("smaps");
63835 + return 0;
63836 + }
63837 +#endif
63838 memset(&mss, 0, sizeof mss);
63839 - mss.vma = vma;
63840 - /* mmap_sem is held in m_start */
63841 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63842 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63843 -
63844 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63845 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
63846 +#endif
63847 + mss.vma = vma;
63848 + /* mmap_sem is held in m_start */
63849 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63850 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63851 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63852 + }
63853 +#endif
63854 show_map_vma(m, vma, is_pid);
63855
63856 seq_printf(m,
63857 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63858 "KernelPageSize: %8lu kB\n"
63859 "MMUPageSize: %8lu kB\n"
63860 "Locked: %8lu kB\n",
63861 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63862 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
63863 +#else
63864 (vma->vm_end - vma->vm_start) >> 10,
63865 +#endif
63866 mss.resident >> 10,
63867 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
63868 mss.shared_clean >> 10,
63869 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63870 char buffer[64];
63871 int nid;
63872
63873 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63874 + if (current->exec_id != m->exec_id) {
63875 + gr_log_badprocpid("numa_maps");
63876 + return 0;
63877 + }
63878 +#endif
63879 +
63880 if (!mm)
63881 return 0;
63882
63883 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63884 mpol_to_str(buffer, sizeof(buffer), pol);
63885 mpol_cond_put(pol);
63886
63887 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63888 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
63889 +#else
63890 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
63891 +#endif
63892
63893 if (file) {
63894 seq_printf(m, " file=");
63895 - seq_path(m, &file->f_path, "\n\t= ");
63896 + seq_path(m, &file->f_path, "\n\t\\= ");
63897 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
63898 seq_printf(m, " heap");
63899 } else {
63900 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
63901 index 678455d..ebd3245 100644
63902 --- a/fs/proc/task_nommu.c
63903 +++ b/fs/proc/task_nommu.c
63904 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63905 else
63906 bytes += kobjsize(mm);
63907
63908 - if (current->fs && current->fs->users > 1)
63909 + if (current->fs && atomic_read(&current->fs->users) > 1)
63910 sbytes += kobjsize(current->fs);
63911 else
63912 bytes += kobjsize(current->fs);
63913 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
63914
63915 if (file) {
63916 seq_pad(m, ' ');
63917 - seq_path(m, &file->f_path, "");
63918 + seq_path(m, &file->f_path, "\n\\");
63919 } else if (mm) {
63920 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
63921
63922 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
63923 index 9100d69..51cd925 100644
63924 --- a/fs/proc/vmcore.c
63925 +++ b/fs/proc/vmcore.c
63926 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
63927 nr_bytes = count;
63928
63929 /* If pfn is not ram, return zeros for sparse dump files */
63930 - if (pfn_is_ram(pfn) == 0)
63931 - memset(buf, 0, nr_bytes);
63932 - else {
63933 + if (pfn_is_ram(pfn) == 0) {
63934 + if (userbuf) {
63935 + if (clear_user((char __force_user *)buf, nr_bytes))
63936 + return -EFAULT;
63937 + } else
63938 + memset(buf, 0, nr_bytes);
63939 + } else {
63940 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
63941 offset, userbuf);
63942 if (tmp < 0)
63943 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
63944 static int copy_to(void *target, void *src, size_t size, int userbuf)
63945 {
63946 if (userbuf) {
63947 - if (copy_to_user((char __user *) target, src, size))
63948 + if (copy_to_user((char __force_user *) target, src, size))
63949 return -EFAULT;
63950 } else {
63951 memcpy(target, src, size);
63952 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63953 if (*fpos < m->offset + m->size) {
63954 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
63955 start = m->paddr + *fpos - m->offset;
63956 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
63957 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
63958 if (tmp < 0)
63959 return tmp;
63960 buflen -= tsz;
63961 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63962 static ssize_t read_vmcore(struct file *file, char __user *buffer,
63963 size_t buflen, loff_t *fpos)
63964 {
63965 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
63966 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
63967 }
63968
63969 /*
63970 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
63971 index b00fcc9..e0c6381 100644
63972 --- a/fs/qnx6/qnx6.h
63973 +++ b/fs/qnx6/qnx6.h
63974 @@ -74,7 +74,7 @@ enum {
63975 BYTESEX_BE,
63976 };
63977
63978 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63979 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63980 {
63981 if (sbi->s_bytesex == BYTESEX_LE)
63982 return le64_to_cpu((__force __le64)n);
63983 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
63984 return (__force __fs64)cpu_to_be64(n);
63985 }
63986
63987 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63988 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63989 {
63990 if (sbi->s_bytesex == BYTESEX_LE)
63991 return le32_to_cpu((__force __le32)n);
63992 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
63993 index 72d2917..c917c12 100644
63994 --- a/fs/quota/netlink.c
63995 +++ b/fs/quota/netlink.c
63996 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
63997 void quota_send_warning(struct kqid qid, dev_t dev,
63998 const char warntype)
63999 {
64000 - static atomic_t seq;
64001 + static atomic_unchecked_t seq;
64002 struct sk_buff *skb;
64003 void *msg_head;
64004 int ret;
64005 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64006 "VFS: Not enough memory to send quota warning.\n");
64007 return;
64008 }
64009 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64010 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64011 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64012 if (!msg_head) {
64013 printk(KERN_ERR
64014 diff --git a/fs/read_write.c b/fs/read_write.c
64015 index cfa18df..c110979 100644
64016 --- a/fs/read_write.c
64017 +++ b/fs/read_write.c
64018 @@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64019
64020 old_fs = get_fs();
64021 set_fs(get_ds());
64022 - p = (__force const char __user *)buf;
64023 + p = (const char __force_user *)buf;
64024 if (count > MAX_RW_COUNT)
64025 count = MAX_RW_COUNT;
64026 if (file->f_op->write)
64027 diff --git a/fs/readdir.c b/fs/readdir.c
64028 index 5b53d99..a6c3049 100644
64029 --- a/fs/readdir.c
64030 +++ b/fs/readdir.c
64031 @@ -17,6 +17,7 @@
64032 #include <linux/security.h>
64033 #include <linux/syscalls.h>
64034 #include <linux/unistd.h>
64035 +#include <linux/namei.h>
64036
64037 #include <asm/uaccess.h>
64038
64039 @@ -69,6 +70,7 @@ struct old_linux_dirent {
64040 struct readdir_callback {
64041 struct dir_context ctx;
64042 struct old_linux_dirent __user * dirent;
64043 + struct file * file;
64044 int result;
64045 };
64046
64047 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64048 buf->result = -EOVERFLOW;
64049 return -EOVERFLOW;
64050 }
64051 +
64052 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64053 + return 0;
64054 +
64055 buf->result++;
64056 dirent = buf->dirent;
64057 if (!access_ok(VERIFY_WRITE, dirent,
64058 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64059 if (!f.file)
64060 return -EBADF;
64061
64062 + buf.file = f.file;
64063 error = iterate_dir(f.file, &buf.ctx);
64064 if (buf.result)
64065 error = buf.result;
64066 @@ -142,6 +149,7 @@ struct getdents_callback {
64067 struct dir_context ctx;
64068 struct linux_dirent __user * current_dir;
64069 struct linux_dirent __user * previous;
64070 + struct file * file;
64071 int count;
64072 int error;
64073 };
64074 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64075 buf->error = -EOVERFLOW;
64076 return -EOVERFLOW;
64077 }
64078 +
64079 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64080 + return 0;
64081 +
64082 dirent = buf->previous;
64083 if (dirent) {
64084 if (__put_user(offset, &dirent->d_off))
64085 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64086 if (!f.file)
64087 return -EBADF;
64088
64089 + buf.file = f.file;
64090 error = iterate_dir(f.file, &buf.ctx);
64091 if (error >= 0)
64092 error = buf.error;
64093 @@ -226,6 +239,7 @@ struct getdents_callback64 {
64094 struct dir_context ctx;
64095 struct linux_dirent64 __user * current_dir;
64096 struct linux_dirent64 __user * previous;
64097 + struct file *file;
64098 int count;
64099 int error;
64100 };
64101 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64102 buf->error = -EINVAL; /* only used if we fail.. */
64103 if (reclen > buf->count)
64104 return -EINVAL;
64105 +
64106 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64107 + return 0;
64108 +
64109 dirent = buf->previous;
64110 if (dirent) {
64111 if (__put_user(offset, &dirent->d_off))
64112 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64113 if (!f.file)
64114 return -EBADF;
64115
64116 + buf.file = f.file;
64117 error = iterate_dir(f.file, &buf.ctx);
64118 if (error >= 0)
64119 error = buf.error;
64120 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64121 index 2b7882b..1c5ef48 100644
64122 --- a/fs/reiserfs/do_balan.c
64123 +++ b/fs/reiserfs/do_balan.c
64124 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64125 return;
64126 }
64127
64128 - atomic_inc(&(fs_generation(tb->tb_sb)));
64129 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64130 do_balance_starts(tb);
64131
64132 /* balance leaf returns 0 except if combining L R and S into
64133 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64134 index ee382ef..f4eb6eb5 100644
64135 --- a/fs/reiserfs/item_ops.c
64136 +++ b/fs/reiserfs/item_ops.c
64137 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64138 }
64139
64140 static struct item_operations errcatch_ops = {
64141 - errcatch_bytes_number,
64142 - errcatch_decrement_key,
64143 - errcatch_is_left_mergeable,
64144 - errcatch_print_item,
64145 - errcatch_check_item,
64146 + .bytes_number = errcatch_bytes_number,
64147 + .decrement_key = errcatch_decrement_key,
64148 + .is_left_mergeable = errcatch_is_left_mergeable,
64149 + .print_item = errcatch_print_item,
64150 + .check_item = errcatch_check_item,
64151
64152 - errcatch_create_vi,
64153 - errcatch_check_left,
64154 - errcatch_check_right,
64155 - errcatch_part_size,
64156 - errcatch_unit_num,
64157 - errcatch_print_vi
64158 + .create_vi = errcatch_create_vi,
64159 + .check_left = errcatch_check_left,
64160 + .check_right = errcatch_check_right,
64161 + .part_size = errcatch_part_size,
64162 + .unit_num = errcatch_unit_num,
64163 + .print_vi = errcatch_print_vi
64164 };
64165
64166 //////////////////////////////////////////////////////////////////////////////
64167 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64168 index a958444..42b2323 100644
64169 --- a/fs/reiserfs/procfs.c
64170 +++ b/fs/reiserfs/procfs.c
64171 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64172 "SMALL_TAILS " : "NO_TAILS ",
64173 replay_only(sb) ? "REPLAY_ONLY " : "",
64174 convert_reiserfs(sb) ? "CONV " : "",
64175 - atomic_read(&r->s_generation_counter),
64176 + atomic_read_unchecked(&r->s_generation_counter),
64177 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64178 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64179 SF(s_good_search_by_key_reada), SF(s_bmaps),
64180 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64181 index f8adaee..0eeeeca 100644
64182 --- a/fs/reiserfs/reiserfs.h
64183 +++ b/fs/reiserfs/reiserfs.h
64184 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64185 /* Comment? -Hans */
64186 wait_queue_head_t s_wait;
64187 /* To be obsoleted soon by per buffer seals.. -Hans */
64188 - atomic_t s_generation_counter; // increased by one every time the
64189 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64190 // tree gets re-balanced
64191 unsigned long s_properties; /* File system properties. Currently holds
64192 on-disk FS format */
64193 @@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64194 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64195
64196 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64197 -#define get_generation(s) atomic_read (&fs_generation(s))
64198 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64199 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64200 #define __fs_changed(gen,s) (gen != get_generation (s))
64201 #define fs_changed(gen,s) \
64202 diff --git a/fs/select.c b/fs/select.c
64203 index 467bb1c..cf9d65a 100644
64204 --- a/fs/select.c
64205 +++ b/fs/select.c
64206 @@ -20,6 +20,7 @@
64207 #include <linux/export.h>
64208 #include <linux/slab.h>
64209 #include <linux/poll.h>
64210 +#include <linux/security.h>
64211 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64212 #include <linux/file.h>
64213 #include <linux/fdtable.h>
64214 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64215 struct poll_list *walk = head;
64216 unsigned long todo = nfds;
64217
64218 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64219 if (nfds > rlimit(RLIMIT_NOFILE))
64220 return -EINVAL;
64221
64222 diff --git a/fs/seq_file.c b/fs/seq_file.c
64223 index 1d641bb..e600623 100644
64224 --- a/fs/seq_file.c
64225 +++ b/fs/seq_file.c
64226 @@ -10,6 +10,7 @@
64227 #include <linux/seq_file.h>
64228 #include <linux/slab.h>
64229 #include <linux/cred.h>
64230 +#include <linux/sched.h>
64231
64232 #include <asm/uaccess.h>
64233 #include <asm/page.h>
64234 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64235 #ifdef CONFIG_USER_NS
64236 p->user_ns = file->f_cred->user_ns;
64237 #endif
64238 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64239 + p->exec_id = current->exec_id;
64240 +#endif
64241
64242 /*
64243 * Wrappers around seq_open(e.g. swaps_open) need to be
64244 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64245 return 0;
64246 }
64247 if (!m->buf) {
64248 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64249 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64250 if (!m->buf)
64251 return -ENOMEM;
64252 }
64253 @@ -137,7 +141,7 @@ Eoverflow:
64254 m->op->stop(m, p);
64255 kfree(m->buf);
64256 m->count = 0;
64257 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64258 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64259 return !m->buf ? -ENOMEM : -EAGAIN;
64260 }
64261
64262 @@ -153,7 +157,7 @@ Eoverflow:
64263 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64264 {
64265 struct seq_file *m = file->private_data;
64266 - size_t copied = 0;
64267 + ssize_t copied = 0;
64268 loff_t pos;
64269 size_t n;
64270 void *p;
64271 @@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64272
64273 /* grab buffer if we didn't have one */
64274 if (!m->buf) {
64275 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64276 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64277 if (!m->buf)
64278 goto Enomem;
64279 }
64280 @@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64281 m->op->stop(m, p);
64282 kfree(m->buf);
64283 m->count = 0;
64284 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64285 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64286 if (!m->buf)
64287 goto Enomem;
64288 m->version = 0;
64289 @@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
64290 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64291 void *data)
64292 {
64293 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64294 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64295 int res = -ENOMEM;
64296
64297 if (op) {
64298 diff --git a/fs/splice.c b/fs/splice.c
64299 index 12028fa..a6f2619 100644
64300 --- a/fs/splice.c
64301 +++ b/fs/splice.c
64302 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64303 pipe_lock(pipe);
64304
64305 for (;;) {
64306 - if (!pipe->readers) {
64307 + if (!atomic_read(&pipe->readers)) {
64308 send_sig(SIGPIPE, current, 0);
64309 if (!ret)
64310 ret = -EPIPE;
64311 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64312 page_nr++;
64313 ret += buf->len;
64314
64315 - if (pipe->files)
64316 + if (atomic_read(&pipe->files))
64317 do_wakeup = 1;
64318
64319 if (!--spd->nr_pages)
64320 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64321 do_wakeup = 0;
64322 }
64323
64324 - pipe->waiting_writers++;
64325 + atomic_inc(&pipe->waiting_writers);
64326 pipe_wait(pipe);
64327 - pipe->waiting_writers--;
64328 + atomic_dec(&pipe->waiting_writers);
64329 }
64330
64331 pipe_unlock(pipe);
64332 @@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64333 old_fs = get_fs();
64334 set_fs(get_ds());
64335 /* The cast to a user pointer is valid due to the set_fs() */
64336 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64337 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64338 set_fs(old_fs);
64339
64340 return res;
64341 @@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64342 old_fs = get_fs();
64343 set_fs(get_ds());
64344 /* The cast to a user pointer is valid due to the set_fs() */
64345 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64346 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64347 set_fs(old_fs);
64348
64349 return res;
64350 @@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64351 goto err;
64352
64353 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64354 - vec[i].iov_base = (void __user *) page_address(page);
64355 + vec[i].iov_base = (void __force_user *) page_address(page);
64356 vec[i].iov_len = this_len;
64357 spd.pages[i] = page;
64358 spd.nr_pages++;
64359 @@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64360 ops->release(pipe, buf);
64361 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64362 pipe->nrbufs--;
64363 - if (pipe->files)
64364 + if (atomic_read(&pipe->files))
64365 sd->need_wakeup = true;
64366 }
64367
64368 @@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64369 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64370 {
64371 while (!pipe->nrbufs) {
64372 - if (!pipe->writers)
64373 + if (!atomic_read(&pipe->writers))
64374 return 0;
64375
64376 - if (!pipe->waiting_writers && sd->num_spliced)
64377 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64378 return 0;
64379
64380 if (sd->flags & SPLICE_F_NONBLOCK)
64381 @@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64382 * out of the pipe right after the splice_to_pipe(). So set
64383 * PIPE_READERS appropriately.
64384 */
64385 - pipe->readers = 1;
64386 + atomic_set(&pipe->readers, 1);
64387
64388 current->splice_pipe = pipe;
64389 }
64390 @@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64391
64392 partial[buffers].offset = off;
64393 partial[buffers].len = plen;
64394 + partial[buffers].private = 0;
64395
64396 off = 0;
64397 len -= plen;
64398 @@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64399 ret = -ERESTARTSYS;
64400 break;
64401 }
64402 - if (!pipe->writers)
64403 + if (!atomic_read(&pipe->writers))
64404 break;
64405 - if (!pipe->waiting_writers) {
64406 + if (!atomic_read(&pipe->waiting_writers)) {
64407 if (flags & SPLICE_F_NONBLOCK) {
64408 ret = -EAGAIN;
64409 break;
64410 @@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64411 pipe_lock(pipe);
64412
64413 while (pipe->nrbufs >= pipe->buffers) {
64414 - if (!pipe->readers) {
64415 + if (!atomic_read(&pipe->readers)) {
64416 send_sig(SIGPIPE, current, 0);
64417 ret = -EPIPE;
64418 break;
64419 @@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64420 ret = -ERESTARTSYS;
64421 break;
64422 }
64423 - pipe->waiting_writers++;
64424 + atomic_inc(&pipe->waiting_writers);
64425 pipe_wait(pipe);
64426 - pipe->waiting_writers--;
64427 + atomic_dec(&pipe->waiting_writers);
64428 }
64429
64430 pipe_unlock(pipe);
64431 @@ -1880,14 +1881,14 @@ retry:
64432 pipe_double_lock(ipipe, opipe);
64433
64434 do {
64435 - if (!opipe->readers) {
64436 + if (!atomic_read(&opipe->readers)) {
64437 send_sig(SIGPIPE, current, 0);
64438 if (!ret)
64439 ret = -EPIPE;
64440 break;
64441 }
64442
64443 - if (!ipipe->nrbufs && !ipipe->writers)
64444 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64445 break;
64446
64447 /*
64448 @@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64449 pipe_double_lock(ipipe, opipe);
64450
64451 do {
64452 - if (!opipe->readers) {
64453 + if (!atomic_read(&opipe->readers)) {
64454 send_sig(SIGPIPE, current, 0);
64455 if (!ret)
64456 ret = -EPIPE;
64457 @@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64458 * return EAGAIN if we have the potential of some data in the
64459 * future, otherwise just return 0
64460 */
64461 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
64462 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
64463 ret = -EAGAIN;
64464
64465 pipe_unlock(ipipe);
64466 diff --git a/fs/stat.c b/fs/stat.c
64467 index ae0c3ce..9ee641c 100644
64468 --- a/fs/stat.c
64469 +++ b/fs/stat.c
64470 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
64471 stat->gid = inode->i_gid;
64472 stat->rdev = inode->i_rdev;
64473 stat->size = i_size_read(inode);
64474 - stat->atime = inode->i_atime;
64475 - stat->mtime = inode->i_mtime;
64476 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64477 + stat->atime = inode->i_ctime;
64478 + stat->mtime = inode->i_ctime;
64479 + } else {
64480 + stat->atime = inode->i_atime;
64481 + stat->mtime = inode->i_mtime;
64482 + }
64483 stat->ctime = inode->i_ctime;
64484 stat->blksize = (1 << inode->i_blkbits);
64485 stat->blocks = inode->i_blocks;
64486 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
64487 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
64488 {
64489 struct inode *inode = path->dentry->d_inode;
64490 + int retval;
64491
64492 - if (inode->i_op->getattr)
64493 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
64494 + if (inode->i_op->getattr) {
64495 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
64496 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64497 + stat->atime = stat->ctime;
64498 + stat->mtime = stat->ctime;
64499 + }
64500 + return retval;
64501 + }
64502
64503 generic_fillattr(inode, stat);
64504 return 0;
64505 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
64506 index 5e73d66..4f165fd 100644
64507 --- a/fs/sysfs/dir.c
64508 +++ b/fs/sysfs/dir.c
64509 @@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
64510 *
64511 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64512 */
64513 -static unsigned int sysfs_name_hash(const char *name, const void *ns)
64514 +static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
64515 {
64516 unsigned long hash = init_name_hash();
64517 unsigned int len = strlen(name);
64518 @@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
64519 struct sysfs_dirent *sd;
64520 int rc;
64521
64522 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64523 + const char *parent_name = parent_sd->s_name;
64524 +
64525 + mode = S_IFDIR | S_IRWXU;
64526 +
64527 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
64528 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
64529 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
64530 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
64531 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
64532 +#endif
64533 +
64534 /* allocate */
64535 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
64536 if (!sd)
64537 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
64538 index 35e7d08..4d6e676 100644
64539 --- a/fs/sysfs/file.c
64540 +++ b/fs/sysfs/file.c
64541 @@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
64542
64543 struct sysfs_open_dirent {
64544 atomic_t refcnt;
64545 - atomic_t event;
64546 + atomic_unchecked_t event;
64547 wait_queue_head_t poll;
64548 struct list_head files; /* goes through sysfs_open_file.list */
64549 };
64550 @@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
64551 return -ENODEV;
64552 }
64553
64554 - of->event = atomic_read(&of->sd->s_attr.open->event);
64555 + of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
64556
64557 /*
64558 * Lookup @ops and invoke show(). Control may reach here via seq
64559 @@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
64560 return ret;
64561 }
64562
64563 -static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64564 - void *buf, int len, int write)
64565 +static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64566 + void *buf, size_t len, int write)
64567 {
64568 struct file *file = vma->vm_file;
64569 struct sysfs_open_file *of = sysfs_of(file);
64570 - int ret;
64571 + ssize_t ret;
64572
64573 if (!of->vm_ops)
64574 return -EINVAL;
64575 @@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
64576 return -ENOMEM;
64577
64578 atomic_set(&new_od->refcnt, 0);
64579 - atomic_set(&new_od->event, 1);
64580 + atomic_set_unchecked(&new_od->event, 1);
64581 init_waitqueue_head(&new_od->poll);
64582 INIT_LIST_HEAD(&new_od->files);
64583 goto retry;
64584 @@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
64585
64586 sysfs_put_active(attr_sd);
64587
64588 - if (of->event != atomic_read(&od->event))
64589 + if (of->event != atomic_read_unchecked(&od->event))
64590 goto trigger;
64591
64592 return DEFAULT_POLLMASK;
64593 @@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
64594 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
64595 od = sd->s_attr.open;
64596 if (od) {
64597 - atomic_inc(&od->event);
64598 + atomic_inc_unchecked(&od->event);
64599 wake_up_interruptible(&od->poll);
64600 }
64601 }
64602 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
64603 index 3ae3f1b..081a26c 100644
64604 --- a/fs/sysfs/symlink.c
64605 +++ b/fs/sysfs/symlink.c
64606 @@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64607 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
64608 void *cookie)
64609 {
64610 - char *page = nd_get_link(nd);
64611 + const char *page = nd_get_link(nd);
64612 if (!IS_ERR(page))
64613 free_page((unsigned long)page);
64614 }
64615 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
64616 index 69d4889..a810bd4 100644
64617 --- a/fs/sysv/sysv.h
64618 +++ b/fs/sysv/sysv.h
64619 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
64620 #endif
64621 }
64622
64623 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64624 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64625 {
64626 if (sbi->s_bytesex == BYTESEX_PDP)
64627 return PDP_swab((__force __u32)n);
64628 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
64629 index e18b988..f1d4ad0f 100644
64630 --- a/fs/ubifs/io.c
64631 +++ b/fs/ubifs/io.c
64632 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
64633 return err;
64634 }
64635
64636 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64637 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64638 {
64639 int err;
64640
64641 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
64642 index c175b4d..8f36a16 100644
64643 --- a/fs/udf/misc.c
64644 +++ b/fs/udf/misc.c
64645 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
64646
64647 u8 udf_tag_checksum(const struct tag *t)
64648 {
64649 - u8 *data = (u8 *)t;
64650 + const u8 *data = (const u8 *)t;
64651 u8 checksum = 0;
64652 int i;
64653 for (i = 0; i < sizeof(struct tag); ++i)
64654 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
64655 index 8d974c4..b82f6ec 100644
64656 --- a/fs/ufs/swab.h
64657 +++ b/fs/ufs/swab.h
64658 @@ -22,7 +22,7 @@ enum {
64659 BYTESEX_BE
64660 };
64661
64662 -static inline u64
64663 +static inline u64 __intentional_overflow(-1)
64664 fs64_to_cpu(struct super_block *sbp, __fs64 n)
64665 {
64666 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64667 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
64668 return (__force __fs64)cpu_to_be64(n);
64669 }
64670
64671 -static inline u32
64672 +static inline u32 __intentional_overflow(-1)
64673 fs32_to_cpu(struct super_block *sbp, __fs32 n)
64674 {
64675 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64676 diff --git a/fs/utimes.c b/fs/utimes.c
64677 index aa138d6..5f3a811 100644
64678 --- a/fs/utimes.c
64679 +++ b/fs/utimes.c
64680 @@ -1,6 +1,7 @@
64681 #include <linux/compiler.h>
64682 #include <linux/file.h>
64683 #include <linux/fs.h>
64684 +#include <linux/security.h>
64685 #include <linux/linkage.h>
64686 #include <linux/mount.h>
64687 #include <linux/namei.h>
64688 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
64689 }
64690 }
64691 retry_deleg:
64692 +
64693 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
64694 + error = -EACCES;
64695 + goto mnt_drop_write_and_out;
64696 + }
64697 +
64698 mutex_lock(&inode->i_mutex);
64699 error = notify_change(path->dentry, &newattrs, &delegated_inode);
64700 mutex_unlock(&inode->i_mutex);
64701 diff --git a/fs/xattr.c b/fs/xattr.c
64702 index 3377dff..f394815 100644
64703 --- a/fs/xattr.c
64704 +++ b/fs/xattr.c
64705 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
64706 return rc;
64707 }
64708
64709 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
64710 +ssize_t
64711 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
64712 +{
64713 + struct inode *inode = dentry->d_inode;
64714 + ssize_t error;
64715 +
64716 + error = inode_permission(inode, MAY_EXEC);
64717 + if (error)
64718 + return error;
64719 +
64720 + if (inode->i_op->getxattr)
64721 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
64722 + else
64723 + error = -EOPNOTSUPP;
64724 +
64725 + return error;
64726 +}
64727 +EXPORT_SYMBOL(pax_getxattr);
64728 +#endif
64729 +
64730 ssize_t
64731 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64732 {
64733 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64734 * Extended attribute SET operations
64735 */
64736 static long
64737 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
64738 +setxattr(struct path *path, const char __user *name, const void __user *value,
64739 size_t size, int flags)
64740 {
64741 int error;
64742 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64743 posix_acl_fix_xattr_from_user(kvalue, size);
64744 }
64745
64746 - error = vfs_setxattr(d, kname, kvalue, size, flags);
64747 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64748 + error = -EACCES;
64749 + goto out;
64750 + }
64751 +
64752 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64753 out:
64754 if (vvalue)
64755 vfree(vvalue);
64756 @@ -377,7 +403,7 @@ retry:
64757 return error;
64758 error = mnt_want_write(path.mnt);
64759 if (!error) {
64760 - error = setxattr(path.dentry, name, value, size, flags);
64761 + error = setxattr(&path, name, value, size, flags);
64762 mnt_drop_write(path.mnt);
64763 }
64764 path_put(&path);
64765 @@ -401,7 +427,7 @@ retry:
64766 return error;
64767 error = mnt_want_write(path.mnt);
64768 if (!error) {
64769 - error = setxattr(path.dentry, name, value, size, flags);
64770 + error = setxattr(&path, name, value, size, flags);
64771 mnt_drop_write(path.mnt);
64772 }
64773 path_put(&path);
64774 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64775 const void __user *,value, size_t, size, int, flags)
64776 {
64777 struct fd f = fdget(fd);
64778 - struct dentry *dentry;
64779 int error = -EBADF;
64780
64781 if (!f.file)
64782 return error;
64783 - dentry = f.file->f_path.dentry;
64784 - audit_inode(NULL, dentry, 0);
64785 + audit_inode(NULL, f.file->f_path.dentry, 0);
64786 error = mnt_want_write_file(f.file);
64787 if (!error) {
64788 - error = setxattr(dentry, name, value, size, flags);
64789 + error = setxattr(&f.file->f_path, name, value, size, flags);
64790 mnt_drop_write_file(f.file);
64791 }
64792 fdput(f);
64793 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64794 * Extended attribute REMOVE operations
64795 */
64796 static long
64797 -removexattr(struct dentry *d, const char __user *name)
64798 +removexattr(struct path *path, const char __user *name)
64799 {
64800 int error;
64801 char kname[XATTR_NAME_MAX + 1];
64802 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
64803 if (error < 0)
64804 return error;
64805
64806 - return vfs_removexattr(d, kname);
64807 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
64808 + return -EACCES;
64809 +
64810 + return vfs_removexattr(path->dentry, kname);
64811 }
64812
64813 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
64814 @@ -652,7 +679,7 @@ retry:
64815 return error;
64816 error = mnt_want_write(path.mnt);
64817 if (!error) {
64818 - error = removexattr(path.dentry, name);
64819 + error = removexattr(&path, name);
64820 mnt_drop_write(path.mnt);
64821 }
64822 path_put(&path);
64823 @@ -675,7 +702,7 @@ retry:
64824 return error;
64825 error = mnt_want_write(path.mnt);
64826 if (!error) {
64827 - error = removexattr(path.dentry, name);
64828 + error = removexattr(&path, name);
64829 mnt_drop_write(path.mnt);
64830 }
64831 path_put(&path);
64832 @@ -689,16 +716,16 @@ retry:
64833 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
64834 {
64835 struct fd f = fdget(fd);
64836 - struct dentry *dentry;
64837 + struct path *path;
64838 int error = -EBADF;
64839
64840 if (!f.file)
64841 return error;
64842 - dentry = f.file->f_path.dentry;
64843 - audit_inode(NULL, dentry, 0);
64844 + path = &f.file->f_path;
64845 + audit_inode(NULL, path->dentry, 0);
64846 error = mnt_want_write_file(f.file);
64847 if (!error) {
64848 - error = removexattr(dentry, name);
64849 + error = removexattr(path, name);
64850 mnt_drop_write_file(f.file);
64851 }
64852 fdput(f);
64853 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
64854 index 9fbea87..417b3c2 100644
64855 --- a/fs/xattr_acl.c
64856 +++ b/fs/xattr_acl.c
64857 @@ -10,6 +10,7 @@
64858 #include <linux/posix_acl_xattr.h>
64859 #include <linux/gfp.h>
64860 #include <linux/user_namespace.h>
64861 +#include <linux/grsecurity.h>
64862
64863 /*
64864 * Fix up the uids and gids in posix acl extended attributes in place.
64865 @@ -76,11 +77,12 @@ struct posix_acl *
64866 posix_acl_from_xattr(struct user_namespace *user_ns,
64867 const void *value, size_t size)
64868 {
64869 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
64870 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
64871 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
64872 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
64873 int count;
64874 struct posix_acl *acl;
64875 struct posix_acl_entry *acl_e;
64876 + umode_t umask = gr_acl_umask();
64877
64878 if (!value)
64879 return NULL;
64880 @@ -106,12 +108,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
64881
64882 switch(acl_e->e_tag) {
64883 case ACL_USER_OBJ:
64884 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
64885 + break;
64886 case ACL_GROUP_OBJ:
64887 case ACL_MASK:
64888 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
64889 + break;
64890 case ACL_OTHER:
64891 + acl_e->e_perm &= ~(umask & S_IRWXO);
64892 break;
64893
64894 case ACL_USER:
64895 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
64896 acl_e->e_uid =
64897 make_kuid(user_ns,
64898 le32_to_cpu(entry->e_id));
64899 @@ -119,6 +127,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
64900 goto fail;
64901 break;
64902 case ACL_GROUP:
64903 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
64904 acl_e->e_gid =
64905 make_kgid(user_ns,
64906 le32_to_cpu(entry->e_id));
64907 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
64908 index 3b2c14b..de031fe 100644
64909 --- a/fs/xfs/xfs_bmap.c
64910 +++ b/fs/xfs/xfs_bmap.c
64911 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
64912
64913 #else
64914 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
64915 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
64916 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
64917 #endif /* DEBUG */
64918
64919 /*
64920 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
64921 index c4e50c6..8ba93e3 100644
64922 --- a/fs/xfs/xfs_dir2_readdir.c
64923 +++ b/fs/xfs/xfs_dir2_readdir.c
64924 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
64925 ino = dp->d_ops->sf_get_ino(sfp, sfep);
64926 filetype = dp->d_ops->sf_get_ftype(sfep);
64927 ctx->pos = off & 0x7fffffff;
64928 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64929 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
64930 + char name[sfep->namelen];
64931 + memcpy(name, sfep->name, sfep->namelen);
64932 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
64933 + return 0;
64934 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64935 xfs_dir3_get_dtype(mp, filetype)))
64936 return 0;
64937 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
64938 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
64939 index 33ad9a7..82c18ba 100644
64940 --- a/fs/xfs/xfs_ioctl.c
64941 +++ b/fs/xfs/xfs_ioctl.c
64942 @@ -126,7 +126,7 @@ xfs_find_handle(
64943 }
64944
64945 error = -EFAULT;
64946 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
64947 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
64948 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
64949 goto out_put;
64950
64951 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
64952 index 104455b..764c512 100644
64953 --- a/fs/xfs/xfs_iops.c
64954 +++ b/fs/xfs/xfs_iops.c
64955 @@ -397,7 +397,7 @@ xfs_vn_put_link(
64956 struct nameidata *nd,
64957 void *p)
64958 {
64959 - char *s = nd_get_link(nd);
64960 + const char *s = nd_get_link(nd);
64961
64962 if (!IS_ERR(s))
64963 kfree(s);
64964 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
64965 new file mode 100644
64966 index 0000000..031e895
64967 --- /dev/null
64968 +++ b/grsecurity/Kconfig
64969 @@ -0,0 +1,1157 @@
64970 +#
64971 +# grecurity configuration
64972 +#
64973 +menu "Memory Protections"
64974 +depends on GRKERNSEC
64975 +
64976 +config GRKERNSEC_KMEM
64977 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
64978 + default y if GRKERNSEC_CONFIG_AUTO
64979 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
64980 + help
64981 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
64982 + be written to or read from to modify or leak the contents of the running
64983 + kernel. /dev/port will also not be allowed to be opened, and support
64984 + for /dev/cpu/*/msr and kexec will be removed. If you have module
64985 + support disabled, enabling this will close up six ways that are
64986 + currently used to insert malicious code into the running kernel.
64987 +
64988 + Even with this feature enabled, we still highly recommend that
64989 + you use the RBAC system, as it is still possible for an attacker to
64990 + modify the running kernel through other more obscure methods.
64991 +
64992 + Enabling this feature will prevent the "cpupower" and "powertop" tools
64993 + from working.
64994 +
64995 + It is highly recommended that you say Y here if you meet all the
64996 + conditions above.
64997 +
64998 +config GRKERNSEC_VM86
64999 + bool "Restrict VM86 mode"
65000 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65001 + depends on X86_32
65002 +
65003 + help
65004 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65005 + make use of a special execution mode on 32bit x86 processors called
65006 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65007 + video cards and will still work with this option enabled. The purpose
65008 + of the option is to prevent exploitation of emulation errors in
65009 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65010 + Nearly all users should be able to enable this option.
65011 +
65012 +config GRKERNSEC_IO
65013 + bool "Disable privileged I/O"
65014 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65015 + depends on X86
65016 + select RTC_CLASS
65017 + select RTC_INTF_DEV
65018 + select RTC_DRV_CMOS
65019 +
65020 + help
65021 + If you say Y here, all ioperm and iopl calls will return an error.
65022 + Ioperm and iopl can be used to modify the running kernel.
65023 + Unfortunately, some programs need this access to operate properly,
65024 + the most notable of which are XFree86 and hwclock. hwclock can be
65025 + remedied by having RTC support in the kernel, so real-time
65026 + clock support is enabled if this option is enabled, to ensure
65027 + that hwclock operates correctly.
65028 +
65029 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
65030 + you may not be able to boot into a graphical environment with this
65031 + option enabled. In this case, you should use the RBAC system instead.
65032 +
65033 +config GRKERNSEC_JIT_HARDEN
65034 + bool "Harden BPF JIT against spray attacks"
65035 + default y if GRKERNSEC_CONFIG_AUTO
65036 + depends on BPF_JIT && X86
65037 + help
65038 + If you say Y here, the native code generated by the kernel's Berkeley
65039 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65040 + attacks that attempt to fit attacker-beneficial instructions in
65041 + 32bit immediate fields of JIT-generated native instructions. The
65042 + attacker will generally aim to cause an unintended instruction sequence
65043 + of JIT-generated native code to execute by jumping into the middle of
65044 + a generated instruction. This feature effectively randomizes the 32bit
65045 + immediate constants present in the generated code to thwart such attacks.
65046 +
65047 + If you're using KERNEXEC, it's recommended that you enable this option
65048 + to supplement the hardening of the kernel.
65049 +
65050 +config GRKERNSEC_PERF_HARDEN
65051 + bool "Disable unprivileged PERF_EVENTS usage by default"
65052 + default y if GRKERNSEC_CONFIG_AUTO
65053 + depends on PERF_EVENTS
65054 + help
65055 + If you say Y here, the range of acceptable values for the
65056 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65057 + default to a new value: 3. When the sysctl is set to this value, no
65058 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65059 +
65060 + Though PERF_EVENTS can be used legitimately for performance monitoring
65061 + and low-level application profiling, it is forced on regardless of
65062 + configuration, has been at fault for several vulnerabilities, and
65063 + creates new opportunities for side channels and other information leaks.
65064 +
65065 + This feature puts PERF_EVENTS into a secure default state and permits
65066 + the administrator to change out of it temporarily if unprivileged
65067 + application profiling is needed.
65068 +
65069 +config GRKERNSEC_RAND_THREADSTACK
65070 + bool "Insert random gaps between thread stacks"
65071 + default y if GRKERNSEC_CONFIG_AUTO
65072 + depends on PAX_RANDMMAP && !PPC
65073 + help
65074 + If you say Y here, a random-sized gap will be enforced between allocated
65075 + thread stacks. Glibc's NPTL and other threading libraries that
65076 + pass MAP_STACK to the kernel for thread stack allocation are supported.
65077 + The implementation currently provides 8 bits of entropy for the gap.
65078 +
65079 + Many distributions do not compile threaded remote services with the
65080 + -fstack-check argument to GCC, causing the variable-sized stack-based
65081 + allocator, alloca(), to not probe the stack on allocation. This
65082 + permits an unbounded alloca() to skip over any guard page and potentially
65083 + modify another thread's stack reliably. An enforced random gap
65084 + reduces the reliability of such an attack and increases the chance
65085 + that such a read/write to another thread's stack instead lands in
65086 + an unmapped area, causing a crash and triggering grsecurity's
65087 + anti-bruteforcing logic.
65088 +
65089 +config GRKERNSEC_PROC_MEMMAP
65090 + bool "Harden ASLR against information leaks and entropy reduction"
65091 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65092 + depends on PAX_NOEXEC || PAX_ASLR
65093 + help
65094 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65095 + give no information about the addresses of its mappings if
65096 + PaX features that rely on random addresses are enabled on the task.
65097 + In addition to sanitizing this information and disabling other
65098 + dangerous sources of information, this option causes reads of sensitive
65099 + /proc/<pid> entries where the file descriptor was opened in a different
65100 + task than the one performing the read. Such attempts are logged.
65101 + This option also limits argv/env strings for suid/sgid binaries
65102 + to 512KB to prevent a complete exhaustion of the stack entropy provided
65103 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65104 + binaries to prevent alternative mmap layouts from being abused.
65105 +
65106 + If you use PaX it is essential that you say Y here as it closes up
65107 + several holes that make full ASLR useless locally.
65108 +
65109 +config GRKERNSEC_BRUTE
65110 + bool "Deter exploit bruteforcing"
65111 + default y if GRKERNSEC_CONFIG_AUTO
65112 + help
65113 + If you say Y here, attempts to bruteforce exploits against forking
65114 + daemons such as apache or sshd, as well as against suid/sgid binaries
65115 + will be deterred. When a child of a forking daemon is killed by PaX
65116 + or crashes due to an illegal instruction or other suspicious signal,
65117 + the parent process will be delayed 30 seconds upon every subsequent
65118 + fork until the administrator is able to assess the situation and
65119 + restart the daemon.
65120 + In the suid/sgid case, the attempt is logged, the user has all their
65121 + existing instances of the suid/sgid binary terminated and will
65122 + be unable to execute any suid/sgid binaries for 15 minutes.
65123 +
65124 + It is recommended that you also enable signal logging in the auditing
65125 + section so that logs are generated when a process triggers a suspicious
65126 + signal.
65127 + If the sysctl option is enabled, a sysctl option with name
65128 + "deter_bruteforce" is created.
65129 +
65130 +config GRKERNSEC_MODHARDEN
65131 + bool "Harden module auto-loading"
65132 + default y if GRKERNSEC_CONFIG_AUTO
65133 + depends on MODULES
65134 + help
65135 + If you say Y here, module auto-loading in response to use of some
65136 + feature implemented by an unloaded module will be restricted to
65137 + root users. Enabling this option helps defend against attacks
65138 + by unprivileged users who abuse the auto-loading behavior to
65139 + cause a vulnerable module to load that is then exploited.
65140 +
65141 + If this option prevents a legitimate use of auto-loading for a
65142 + non-root user, the administrator can execute modprobe manually
65143 + with the exact name of the module mentioned in the alert log.
65144 + Alternatively, the administrator can add the module to the list
65145 + of modules loaded at boot by modifying init scripts.
65146 +
65147 + Modification of init scripts will most likely be needed on
65148 + Ubuntu servers with encrypted home directory support enabled,
65149 + as the first non-root user logging in will cause the ecb(aes),
65150 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65151 +
65152 +config GRKERNSEC_HIDESYM
65153 + bool "Hide kernel symbols"
65154 + default y if GRKERNSEC_CONFIG_AUTO
65155 + select PAX_USERCOPY_SLABS
65156 + help
65157 + If you say Y here, getting information on loaded modules, and
65158 + displaying all kernel symbols through a syscall will be restricted
65159 + to users with CAP_SYS_MODULE. For software compatibility reasons,
65160 + /proc/kallsyms will be restricted to the root user. The RBAC
65161 + system can hide that entry even from root.
65162 +
65163 + This option also prevents leaking of kernel addresses through
65164 + several /proc entries.
65165 +
65166 + Note that this option is only effective provided the following
65167 + conditions are met:
65168 + 1) The kernel using grsecurity is not precompiled by some distribution
65169 + 2) You have also enabled GRKERNSEC_DMESG
65170 + 3) You are using the RBAC system and hiding other files such as your
65171 + kernel image and System.map. Alternatively, enabling this option
65172 + causes the permissions on /boot, /lib/modules, and the kernel
65173 + source directory to change at compile time to prevent
65174 + reading by non-root users.
65175 + If the above conditions are met, this option will aid in providing a
65176 + useful protection against local kernel exploitation of overflows
65177 + and arbitrary read/write vulnerabilities.
65178 +
65179 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65180 + in addition to this feature.
65181 +
65182 +config GRKERNSEC_RANDSTRUCT
65183 + bool "Randomize layout of sensitive kernel structures"
65184 + default y if GRKERNSEC_CONFIG_AUTO
65185 + select GRKERNSEC_HIDESYM
65186 + select MODVERSIONS if MODULES
65187 + help
65188 + If you say Y here, the layouts of a number of sensitive kernel
65189 + structures (task, fs, cred, etc) and all structures composed entirely
65190 + of function pointers (aka "ops" structs) will be randomized at compile-time.
65191 + This can introduce the requirement of an additional infoleak
65192 + vulnerability for exploits targeting these structure types.
65193 +
65194 + Enabling this feature will introduce some performance impact, slightly
65195 + increase memory usage, and prevent the use of forensic tools like
65196 + Volatility against the system (unless the kernel source tree isn't
65197 + cleaned after kernel installation).
65198 +
65199 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65200 + It remains after a make clean to allow for external modules to be compiled
65201 + with the existing seed and will be removed by a make mrproper or
65202 + make distclean.
65203 +
65204 + Note that the implementation requires gcc 4.6.4. or newer. You may need
65205 + to install the supporting headers explicitly in addition to the normal
65206 + gcc package.
65207 +
65208 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65209 + bool "Use cacheline-aware structure randomization"
65210 + depends on GRKERNSEC_RANDSTRUCT
65211 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65212 + help
65213 + If you say Y here, the RANDSTRUCT randomization will make a best effort
65214 + at restricting randomization to cacheline-sized groups of elements. It
65215 + will further not randomize bitfields in structures. This reduces the
65216 + performance hit of RANDSTRUCT at the cost of weakened randomization.
65217 +
65218 +config GRKERNSEC_KERN_LOCKOUT
65219 + bool "Active kernel exploit response"
65220 + default y if GRKERNSEC_CONFIG_AUTO
65221 + depends on X86 || ARM || PPC || SPARC
65222 + help
65223 + If you say Y here, when a PaX alert is triggered due to suspicious
65224 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65225 + or an OOPS occurs due to bad memory accesses, instead of just
65226 + terminating the offending process (and potentially allowing
65227 + a subsequent exploit from the same user), we will take one of two
65228 + actions:
65229 + If the user was root, we will panic the system
65230 + If the user was non-root, we will log the attempt, terminate
65231 + all processes owned by the user, then prevent them from creating
65232 + any new processes until the system is restarted
65233 + This deters repeated kernel exploitation/bruteforcing attempts
65234 + and is useful for later forensics.
65235 +
65236 +config GRKERNSEC_OLD_ARM_USERLAND
65237 + bool "Old ARM userland compatibility"
65238 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65239 + help
65240 + If you say Y here, stubs of executable code to perform such operations
65241 + as "compare-exchange" will be placed at fixed locations in the ARM vector
65242 + table. This is unfortunately needed for old ARM userland meant to run
65243 + across a wide range of processors. Without this option enabled,
65244 + the get_tls and data memory barrier stubs will be emulated by the kernel,
65245 + which is enough for Linaro userlands or other userlands designed for v6
65246 + and newer ARM CPUs. It's recommended that you try without this option enabled
65247 + first, and only enable it if your userland does not boot (it will likely fail
65248 + at init time).
65249 +
65250 +endmenu
65251 +menu "Role Based Access Control Options"
65252 +depends on GRKERNSEC
65253 +
65254 +config GRKERNSEC_RBAC_DEBUG
65255 + bool
65256 +
65257 +config GRKERNSEC_NO_RBAC
65258 + bool "Disable RBAC system"
65259 + help
65260 + If you say Y here, the /dev/grsec device will be removed from the kernel,
65261 + preventing the RBAC system from being enabled. You should only say Y
65262 + here if you have no intention of using the RBAC system, so as to prevent
65263 + an attacker with root access from misusing the RBAC system to hide files
65264 + and processes when loadable module support and /dev/[k]mem have been
65265 + locked down.
65266 +
65267 +config GRKERNSEC_ACL_HIDEKERN
65268 + bool "Hide kernel processes"
65269 + help
65270 + If you say Y here, all kernel threads will be hidden to all
65271 + processes but those whose subject has the "view hidden processes"
65272 + flag.
65273 +
65274 +config GRKERNSEC_ACL_MAXTRIES
65275 + int "Maximum tries before password lockout"
65276 + default 3
65277 + help
65278 + This option enforces the maximum number of times a user can attempt
65279 + to authorize themselves with the grsecurity RBAC system before being
65280 + denied the ability to attempt authorization again for a specified time.
65281 + The lower the number, the harder it will be to brute-force a password.
65282 +
65283 +config GRKERNSEC_ACL_TIMEOUT
65284 + int "Time to wait after max password tries, in seconds"
65285 + default 30
65286 + help
65287 + This option specifies the time the user must wait after attempting to
65288 + authorize to the RBAC system with the maximum number of invalid
65289 + passwords. The higher the number, the harder it will be to brute-force
65290 + a password.
65291 +
65292 +endmenu
65293 +menu "Filesystem Protections"
65294 +depends on GRKERNSEC
65295 +
65296 +config GRKERNSEC_PROC
65297 + bool "Proc restrictions"
65298 + default y if GRKERNSEC_CONFIG_AUTO
65299 + help
65300 + If you say Y here, the permissions of the /proc filesystem
65301 + will be altered to enhance system security and privacy. You MUST
65302 + choose either a user only restriction or a user and group restriction.
65303 + Depending upon the option you choose, you can either restrict users to
65304 + see only the processes they themselves run, or choose a group that can
65305 + view all processes and files normally restricted to root if you choose
65306 + the "restrict to user only" option. NOTE: If you're running identd or
65307 + ntpd as a non-root user, you will have to run it as the group you
65308 + specify here.
65309 +
65310 +config GRKERNSEC_PROC_USER
65311 + bool "Restrict /proc to user only"
65312 + depends on GRKERNSEC_PROC
65313 + help
65314 + If you say Y here, non-root users will only be able to view their own
65315 + processes, and restricts them from viewing network-related information,
65316 + and viewing kernel symbol and module information.
65317 +
65318 +config GRKERNSEC_PROC_USERGROUP
65319 + bool "Allow special group"
65320 + default y if GRKERNSEC_CONFIG_AUTO
65321 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65322 + help
65323 + If you say Y here, you will be able to select a group that will be
65324 + able to view all processes and network-related information. If you've
65325 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65326 + remain hidden. This option is useful if you want to run identd as
65327 + a non-root user. The group you select may also be chosen at boot time
65328 + via "grsec_proc_gid=" on the kernel commandline.
65329 +
65330 +config GRKERNSEC_PROC_GID
65331 + int "GID for special group"
65332 + depends on GRKERNSEC_PROC_USERGROUP
65333 + default 1001
65334 +
65335 +config GRKERNSEC_PROC_ADD
65336 + bool "Additional restrictions"
65337 + default y if GRKERNSEC_CONFIG_AUTO
65338 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65339 + help
65340 + If you say Y here, additional restrictions will be placed on
65341 + /proc that keep normal users from viewing device information and
65342 + slabinfo information that could be useful for exploits.
65343 +
65344 +config GRKERNSEC_LINK
65345 + bool "Linking restrictions"
65346 + default y if GRKERNSEC_CONFIG_AUTO
65347 + help
65348 + If you say Y here, /tmp race exploits will be prevented, since users
65349 + will no longer be able to follow symlinks owned by other users in
65350 + world-writable +t directories (e.g. /tmp), unless the owner of the
65351 + symlink is the owner of the directory. users will also not be
65352 + able to hardlink to files they do not own. If the sysctl option is
65353 + enabled, a sysctl option with name "linking_restrictions" is created.
65354 +
65355 +config GRKERNSEC_SYMLINKOWN
65356 + bool "Kernel-enforced SymlinksIfOwnerMatch"
65357 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65358 + help
65359 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
65360 + that prevents it from being used as a security feature. As Apache
65361 + verifies the symlink by performing a stat() against the target of
65362 + the symlink before it is followed, an attacker can setup a symlink
65363 + to point to a same-owned file, then replace the symlink with one
65364 + that targets another user's file just after Apache "validates" the
65365 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
65366 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65367 + will be in place for the group you specify. If the sysctl option
65368 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
65369 + created.
65370 +
65371 +config GRKERNSEC_SYMLINKOWN_GID
65372 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65373 + depends on GRKERNSEC_SYMLINKOWN
65374 + default 1006
65375 + help
65376 + Setting this GID determines what group kernel-enforced
65377 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65378 + is enabled, a sysctl option with name "symlinkown_gid" is created.
65379 +
65380 +config GRKERNSEC_FIFO
65381 + bool "FIFO restrictions"
65382 + default y if GRKERNSEC_CONFIG_AUTO
65383 + help
65384 + If you say Y here, users will not be able to write to FIFOs they don't
65385 + own in world-writable +t directories (e.g. /tmp), unless the owner of
65386 + the FIFO is the same owner of the directory it's held in. If the sysctl
65387 + option is enabled, a sysctl option with name "fifo_restrictions" is
65388 + created.
65389 +
65390 +config GRKERNSEC_SYSFS_RESTRICT
65391 + bool "Sysfs/debugfs restriction"
65392 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65393 + depends on SYSFS
65394 + help
65395 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65396 + any filesystem normally mounted under it (e.g. debugfs) will be
65397 + mostly accessible only by root. These filesystems generally provide access
65398 + to hardware and debug information that isn't appropriate for unprivileged
65399 + users of the system. Sysfs and debugfs have also become a large source
65400 + of new vulnerabilities, ranging from infoleaks to local compromise.
65401 + There has been very little oversight with an eye toward security involved
65402 + in adding new exporters of information to these filesystems, so their
65403 + use is discouraged.
65404 + For reasons of compatibility, a few directories have been whitelisted
65405 + for access by non-root users:
65406 + /sys/fs/selinux
65407 + /sys/fs/fuse
65408 + /sys/devices/system/cpu
65409 +
65410 +config GRKERNSEC_ROFS
65411 + bool "Runtime read-only mount protection"
65412 + depends on SYSCTL
65413 + help
65414 + If you say Y here, a sysctl option with name "romount_protect" will
65415 + be created. By setting this option to 1 at runtime, filesystems
65416 + will be protected in the following ways:
65417 + * No new writable mounts will be allowed
65418 + * Existing read-only mounts won't be able to be remounted read/write
65419 + * Write operations will be denied on all block devices
65420 + This option acts independently of grsec_lock: once it is set to 1,
65421 + it cannot be turned off. Therefore, please be mindful of the resulting
65422 + behavior if this option is enabled in an init script on a read-only
65423 + filesystem.
65424 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65425 + and GRKERNSEC_IO should be enabled and module loading disabled via
65426 + config or at runtime.
65427 + This feature is mainly intended for secure embedded systems.
65428 +
65429 +
65430 +config GRKERNSEC_DEVICE_SIDECHANNEL
65431 + bool "Eliminate stat/notify-based device sidechannels"
65432 + default y if GRKERNSEC_CONFIG_AUTO
65433 + help
65434 + If you say Y here, timing analyses on block or character
65435 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65436 + will be thwarted for unprivileged users. If a process without
65437 + CAP_MKNOD stats such a device, the last access and last modify times
65438 + will match the device's create time. No access or modify events
65439 + will be triggered through inotify/dnotify/fanotify for such devices.
65440 + This feature will prevent attacks that may at a minimum
65441 + allow an attacker to determine the administrator's password length.
65442 +
65443 +config GRKERNSEC_CHROOT
65444 + bool "Chroot jail restrictions"
65445 + default y if GRKERNSEC_CONFIG_AUTO
65446 + help
65447 + If you say Y here, you will be able to choose several options that will
65448 + make breaking out of a chrooted jail much more difficult. If you
65449 + encounter no software incompatibilities with the following options, it
65450 + is recommended that you enable each one.
65451 +
65452 +config GRKERNSEC_CHROOT_MOUNT
65453 + bool "Deny mounts"
65454 + default y if GRKERNSEC_CONFIG_AUTO
65455 + depends on GRKERNSEC_CHROOT
65456 + help
65457 + If you say Y here, processes inside a chroot will not be able to
65458 + mount or remount filesystems. If the sysctl option is enabled, a
65459 + sysctl option with name "chroot_deny_mount" is created.
65460 +
65461 +config GRKERNSEC_CHROOT_DOUBLE
65462 + bool "Deny double-chroots"
65463 + default y if GRKERNSEC_CONFIG_AUTO
65464 + depends on GRKERNSEC_CHROOT
65465 + help
65466 + If you say Y here, processes inside a chroot will not be able to chroot
65467 + again outside the chroot. This is a widely used method of breaking
65468 + out of a chroot jail and should not be allowed. If the sysctl
65469 + option is enabled, a sysctl option with name
65470 + "chroot_deny_chroot" is created.
65471 +
65472 +config GRKERNSEC_CHROOT_PIVOT
65473 + bool "Deny pivot_root in chroot"
65474 + default y if GRKERNSEC_CONFIG_AUTO
65475 + depends on GRKERNSEC_CHROOT
65476 + help
65477 + If you say Y here, processes inside a chroot will not be able to use
65478 + a function called pivot_root() that was introduced in Linux 2.3.41. It
65479 + works similar to chroot in that it changes the root filesystem. This
65480 + function could be misused in a chrooted process to attempt to break out
65481 + of the chroot, and therefore should not be allowed. If the sysctl
65482 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
65483 + created.
65484 +
65485 +config GRKERNSEC_CHROOT_CHDIR
65486 + bool "Enforce chdir(\"/\") on all chroots"
65487 + default y if GRKERNSEC_CONFIG_AUTO
65488 + depends on GRKERNSEC_CHROOT
65489 + help
65490 + If you say Y here, the current working directory of all newly-chrooted
65491 + applications will be set to the the root directory of the chroot.
65492 + The man page on chroot(2) states:
65493 + Note that this call does not change the current working
65494 + directory, so that `.' can be outside the tree rooted at
65495 + `/'. In particular, the super-user can escape from a
65496 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65497 +
65498 + It is recommended that you say Y here, since it's not known to break
65499 + any software. If the sysctl option is enabled, a sysctl option with
65500 + name "chroot_enforce_chdir" is created.
65501 +
65502 +config GRKERNSEC_CHROOT_CHMOD
65503 + bool "Deny (f)chmod +s"
65504 + default y if GRKERNSEC_CONFIG_AUTO
65505 + depends on GRKERNSEC_CHROOT
65506 + help
65507 + If you say Y here, processes inside a chroot will not be able to chmod
65508 + or fchmod files to make them have suid or sgid bits. This protects
65509 + against another published method of breaking a chroot. If the sysctl
65510 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
65511 + created.
65512 +
65513 +config GRKERNSEC_CHROOT_FCHDIR
65514 + bool "Deny fchdir out of chroot"
65515 + default y if GRKERNSEC_CONFIG_AUTO
65516 + depends on GRKERNSEC_CHROOT
65517 + help
65518 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
65519 + to a file descriptor of the chrooting process that points to a directory
65520 + outside the filesystem will be stopped. If the sysctl option
65521 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65522 +
65523 +config GRKERNSEC_CHROOT_MKNOD
65524 + bool "Deny mknod"
65525 + default y if GRKERNSEC_CONFIG_AUTO
65526 + depends on GRKERNSEC_CHROOT
65527 + help
65528 + If you say Y here, processes inside a chroot will not be allowed to
65529 + mknod. The problem with using mknod inside a chroot is that it
65530 + would allow an attacker to create a device entry that is the same
65531 + as one on the physical root of your system, which could range from
65532 + anything from the console device to a device for your harddrive (which
65533 + they could then use to wipe the drive or steal data). It is recommended
65534 + that you say Y here, unless you run into software incompatibilities.
65535 + If the sysctl option is enabled, a sysctl option with name
65536 + "chroot_deny_mknod" is created.
65537 +
65538 +config GRKERNSEC_CHROOT_SHMAT
65539 + bool "Deny shmat() out of chroot"
65540 + default y if GRKERNSEC_CONFIG_AUTO
65541 + depends on GRKERNSEC_CHROOT
65542 + help
65543 + If you say Y here, processes inside a chroot will not be able to attach
65544 + to shared memory segments that were created outside of the chroot jail.
65545 + It is recommended that you say Y here. If the sysctl option is enabled,
65546 + a sysctl option with name "chroot_deny_shmat" is created.
65547 +
65548 +config GRKERNSEC_CHROOT_UNIX
65549 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
65550 + default y if GRKERNSEC_CONFIG_AUTO
65551 + depends on GRKERNSEC_CHROOT
65552 + help
65553 + If you say Y here, processes inside a chroot will not be able to
65554 + connect to abstract (meaning not belonging to a filesystem) Unix
65555 + domain sockets that were bound outside of a chroot. It is recommended
65556 + that you say Y here. If the sysctl option is enabled, a sysctl option
65557 + with name "chroot_deny_unix" is created.
65558 +
65559 +config GRKERNSEC_CHROOT_FINDTASK
65560 + bool "Protect outside processes"
65561 + default y if GRKERNSEC_CONFIG_AUTO
65562 + depends on GRKERNSEC_CHROOT
65563 + help
65564 + If you say Y here, processes inside a chroot will not be able to
65565 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65566 + getsid, or view any process outside of the chroot. If the sysctl
65567 + option is enabled, a sysctl option with name "chroot_findtask" is
65568 + created.
65569 +
65570 +config GRKERNSEC_CHROOT_NICE
65571 + bool "Restrict priority changes"
65572 + default y if GRKERNSEC_CONFIG_AUTO
65573 + depends on GRKERNSEC_CHROOT
65574 + help
65575 + If you say Y here, processes inside a chroot will not be able to raise
65576 + the priority of processes in the chroot, or alter the priority of
65577 + processes outside the chroot. This provides more security than simply
65578 + removing CAP_SYS_NICE from the process' capability set. If the
65579 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65580 + is created.
65581 +
65582 +config GRKERNSEC_CHROOT_SYSCTL
65583 + bool "Deny sysctl writes"
65584 + default y if GRKERNSEC_CONFIG_AUTO
65585 + depends on GRKERNSEC_CHROOT
65586 + help
65587 + If you say Y here, an attacker in a chroot will not be able to
65588 + write to sysctl entries, either by sysctl(2) or through a /proc
65589 + interface. It is strongly recommended that you say Y here. If the
65590 + sysctl option is enabled, a sysctl option with name
65591 + "chroot_deny_sysctl" is created.
65592 +
65593 +config GRKERNSEC_CHROOT_CAPS
65594 + bool "Capability restrictions"
65595 + default y if GRKERNSEC_CONFIG_AUTO
65596 + depends on GRKERNSEC_CHROOT
65597 + help
65598 + If you say Y here, the capabilities on all processes within a
65599 + chroot jail will be lowered to stop module insertion, raw i/o,
65600 + system and net admin tasks, rebooting the system, modifying immutable
65601 + files, modifying IPC owned by another, and changing the system time.
65602 + This is left an option because it can break some apps. Disable this
65603 + if your chrooted apps are having problems performing those kinds of
65604 + tasks. If the sysctl option is enabled, a sysctl option with
65605 + name "chroot_caps" is created.
65606 +
65607 +config GRKERNSEC_CHROOT_INITRD
65608 + bool "Exempt initrd tasks from restrictions"
65609 + default y if GRKERNSEC_CONFIG_AUTO
65610 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
65611 + help
65612 + If you say Y here, tasks started prior to init will be exempted from
65613 + grsecurity's chroot restrictions. This option is mainly meant to
65614 + resolve Plymouth's performing privileged operations unnecessarily
65615 + in a chroot.
65616 +
65617 +endmenu
65618 +menu "Kernel Auditing"
65619 +depends on GRKERNSEC
65620 +
65621 +config GRKERNSEC_AUDIT_GROUP
65622 + bool "Single group for auditing"
65623 + help
65624 + If you say Y here, the exec and chdir logging features will only operate
65625 + on a group you specify. This option is recommended if you only want to
65626 + watch certain users instead of having a large amount of logs from the
65627 + entire system. If the sysctl option is enabled, a sysctl option with
65628 + name "audit_group" is created.
65629 +
65630 +config GRKERNSEC_AUDIT_GID
65631 + int "GID for auditing"
65632 + depends on GRKERNSEC_AUDIT_GROUP
65633 + default 1007
65634 +
65635 +config GRKERNSEC_EXECLOG
65636 + bool "Exec logging"
65637 + help
65638 + If you say Y here, all execve() calls will be logged (since the
65639 + other exec*() calls are frontends to execve(), all execution
65640 + will be logged). Useful for shell-servers that like to keep track
65641 + of their users. If the sysctl option is enabled, a sysctl option with
65642 + name "exec_logging" is created.
65643 + WARNING: This option when enabled will produce a LOT of logs, especially
65644 + on an active system.
65645 +
65646 +config GRKERNSEC_RESLOG
65647 + bool "Resource logging"
65648 + default y if GRKERNSEC_CONFIG_AUTO
65649 + help
65650 + If you say Y here, all attempts to overstep resource limits will
65651 + be logged with the resource name, the requested size, and the current
65652 + limit. It is highly recommended that you say Y here. If the sysctl
65653 + option is enabled, a sysctl option with name "resource_logging" is
65654 + created. If the RBAC system is enabled, the sysctl value is ignored.
65655 +
65656 +config GRKERNSEC_CHROOT_EXECLOG
65657 + bool "Log execs within chroot"
65658 + help
65659 + If you say Y here, all executions inside a chroot jail will be logged
65660 + to syslog. This can cause a large amount of logs if certain
65661 + applications (eg. djb's daemontools) are installed on the system, and
65662 + is therefore left as an option. If the sysctl option is enabled, a
65663 + sysctl option with name "chroot_execlog" is created.
65664 +
65665 +config GRKERNSEC_AUDIT_PTRACE
65666 + bool "Ptrace logging"
65667 + help
65668 + If you say Y here, all attempts to attach to a process via ptrace
65669 + will be logged. If the sysctl option is enabled, a sysctl option
65670 + with name "audit_ptrace" is created.
65671 +
65672 +config GRKERNSEC_AUDIT_CHDIR
65673 + bool "Chdir logging"
65674 + help
65675 + If you say Y here, all chdir() calls will be logged. If the sysctl
65676 + option is enabled, a sysctl option with name "audit_chdir" is created.
65677 +
65678 +config GRKERNSEC_AUDIT_MOUNT
65679 + bool "(Un)Mount logging"
65680 + help
65681 + If you say Y here, all mounts and unmounts will be logged. If the
65682 + sysctl option is enabled, a sysctl option with name "audit_mount" is
65683 + created.
65684 +
65685 +config GRKERNSEC_SIGNAL
65686 + bool "Signal logging"
65687 + default y if GRKERNSEC_CONFIG_AUTO
65688 + help
65689 + If you say Y here, certain important signals will be logged, such as
65690 + SIGSEGV, which will as a result inform you of when a error in a program
65691 + occurred, which in some cases could mean a possible exploit attempt.
65692 + If the sysctl option is enabled, a sysctl option with name
65693 + "signal_logging" is created.
65694 +
65695 +config GRKERNSEC_FORKFAIL
65696 + bool "Fork failure logging"
65697 + help
65698 + If you say Y here, all failed fork() attempts will be logged.
65699 + This could suggest a fork bomb, or someone attempting to overstep
65700 + their process limit. If the sysctl option is enabled, a sysctl option
65701 + with name "forkfail_logging" is created.
65702 +
65703 +config GRKERNSEC_TIME
65704 + bool "Time change logging"
65705 + default y if GRKERNSEC_CONFIG_AUTO
65706 + help
65707 + If you say Y here, any changes of the system clock will be logged.
65708 + If the sysctl option is enabled, a sysctl option with name
65709 + "timechange_logging" is created.
65710 +
65711 +config GRKERNSEC_PROC_IPADDR
65712 + bool "/proc/<pid>/ipaddr support"
65713 + default y if GRKERNSEC_CONFIG_AUTO
65714 + help
65715 + If you say Y here, a new entry will be added to each /proc/<pid>
65716 + directory that contains the IP address of the person using the task.
65717 + The IP is carried across local TCP and AF_UNIX stream sockets.
65718 + This information can be useful for IDS/IPSes to perform remote response
65719 + to a local attack. The entry is readable by only the owner of the
65720 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
65721 + the RBAC system), and thus does not create privacy concerns.
65722 +
65723 +config GRKERNSEC_RWXMAP_LOG
65724 + bool 'Denied RWX mmap/mprotect logging'
65725 + default y if GRKERNSEC_CONFIG_AUTO
65726 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
65727 + help
65728 + If you say Y here, calls to mmap() and mprotect() with explicit
65729 + usage of PROT_WRITE and PROT_EXEC together will be logged when
65730 + denied by the PAX_MPROTECT feature. This feature will also
65731 + log other problematic scenarios that can occur when PAX_MPROTECT
65732 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
65733 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
65734 + is created.
65735 +
65736 +endmenu
65737 +
65738 +menu "Executable Protections"
65739 +depends on GRKERNSEC
65740 +
65741 +config GRKERNSEC_DMESG
65742 + bool "Dmesg(8) restriction"
65743 + default y if GRKERNSEC_CONFIG_AUTO
65744 + help
65745 + If you say Y here, non-root users will not be able to use dmesg(8)
65746 + to view the contents of the kernel's circular log buffer.
65747 + The kernel's log buffer often contains kernel addresses and other
65748 + identifying information useful to an attacker in fingerprinting a
65749 + system for a targeted exploit.
65750 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
65751 + created.
65752 +
65753 +config GRKERNSEC_HARDEN_PTRACE
65754 + bool "Deter ptrace-based process snooping"
65755 + default y if GRKERNSEC_CONFIG_AUTO
65756 + help
65757 + If you say Y here, TTY sniffers and other malicious monitoring
65758 + programs implemented through ptrace will be defeated. If you
65759 + have been using the RBAC system, this option has already been
65760 + enabled for several years for all users, with the ability to make
65761 + fine-grained exceptions.
65762 +
65763 + This option only affects the ability of non-root users to ptrace
65764 + processes that are not a descendent of the ptracing process.
65765 + This means that strace ./binary and gdb ./binary will still work,
65766 + but attaching to arbitrary processes will not. If the sysctl
65767 + option is enabled, a sysctl option with name "harden_ptrace" is
65768 + created.
65769 +
65770 +config GRKERNSEC_PTRACE_READEXEC
65771 + bool "Require read access to ptrace sensitive binaries"
65772 + default y if GRKERNSEC_CONFIG_AUTO
65773 + help
65774 + If you say Y here, unprivileged users will not be able to ptrace unreadable
65775 + binaries. This option is useful in environments that
65776 + remove the read bits (e.g. file mode 4711) from suid binaries to
65777 + prevent infoleaking of their contents. This option adds
65778 + consistency to the use of that file mode, as the binary could normally
65779 + be read out when run without privileges while ptracing.
65780 +
65781 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65782 + is created.
65783 +
65784 +config GRKERNSEC_SETXID
65785 + bool "Enforce consistent multithreaded privileges"
65786 + default y if GRKERNSEC_CONFIG_AUTO
65787 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65788 + help
65789 + If you say Y here, a change from a root uid to a non-root uid
65790 + in a multithreaded application will cause the resulting uids,
65791 + gids, supplementary groups, and capabilities in that thread
65792 + to be propagated to the other threads of the process. In most
65793 + cases this is unnecessary, as glibc will emulate this behavior
65794 + on behalf of the application. Other libcs do not act in the
65795 + same way, allowing the other threads of the process to continue
65796 + running with root privileges. If the sysctl option is enabled,
65797 + a sysctl option with name "consistent_setxid" is created.
65798 +
65799 +config GRKERNSEC_HARDEN_IPC
65800 + bool "Disallow access to overly-permissive IPC objects"
65801 + default y if GRKERNSEC_CONFIG_AUTO
65802 + depends on SYSVIPC
65803 + help
65804 + If you say Y here, access to overly-permissive IPC objects (shared
65805 + memory, message queues, and semaphores) will be denied for processes
65806 + given the following criteria beyond normal permission checks:
65807 + 1) If the IPC object is world-accessible and the euid doesn't match
65808 + that of the creator or current uid for the IPC object
65809 + 2) If the IPC object is group-accessible and the egid doesn't
65810 + match that of the creator or current gid for the IPC object
65811 + It's a common error to grant too much permission to these objects,
65812 + with impact ranging from denial of service and information leaking to
65813 + privilege escalation. This feature was developed in response to
65814 + research by Tim Brown:
65815 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
65816 + who found hundreds of such insecure usages. Processes with
65817 + CAP_IPC_OWNER are still permitted to access these IPC objects.
65818 + If the sysctl option is enabled, a sysctl option with name
65819 + "harden_ipc" is created.
65820 +
65821 +config GRKERNSEC_TPE
65822 + bool "Trusted Path Execution (TPE)"
65823 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65824 + help
65825 + If you say Y here, you will be able to choose a gid to add to the
65826 + supplementary groups of users you want to mark as "untrusted."
65827 + These users will not be able to execute any files that are not in
65828 + root-owned directories writable only by root. If the sysctl option
65829 + is enabled, a sysctl option with name "tpe" is created.
65830 +
65831 +config GRKERNSEC_TPE_ALL
65832 + bool "Partially restrict all non-root users"
65833 + depends on GRKERNSEC_TPE
65834 + help
65835 + If you say Y here, all non-root users will be covered under
65836 + a weaker TPE restriction. This is separate from, and in addition to,
65837 + the main TPE options that you have selected elsewhere. Thus, if a
65838 + "trusted" GID is chosen, this restriction applies to even that GID.
65839 + Under this restriction, all non-root users will only be allowed to
65840 + execute files in directories they own that are not group or
65841 + world-writable, or in directories owned by root and writable only by
65842 + root. If the sysctl option is enabled, a sysctl option with name
65843 + "tpe_restrict_all" is created.
65844 +
65845 +config GRKERNSEC_TPE_INVERT
65846 + bool "Invert GID option"
65847 + depends on GRKERNSEC_TPE
65848 + help
65849 + If you say Y here, the group you specify in the TPE configuration will
65850 + decide what group TPE restrictions will be *disabled* for. This
65851 + option is useful if you want TPE restrictions to be applied to most
65852 + users on the system. If the sysctl option is enabled, a sysctl option
65853 + with name "tpe_invert" is created. Unlike other sysctl options, this
65854 + entry will default to on for backward-compatibility.
65855 +
65856 +config GRKERNSEC_TPE_GID
65857 + int
65858 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65859 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65860 +
65861 +config GRKERNSEC_TPE_UNTRUSTED_GID
65862 + int "GID for TPE-untrusted users"
65863 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65864 + default 1005
65865 + help
65866 + Setting this GID determines what group TPE restrictions will be
65867 + *enabled* for. If the sysctl option is enabled, a sysctl option
65868 + with name "tpe_gid" is created.
65869 +
65870 +config GRKERNSEC_TPE_TRUSTED_GID
65871 + int "GID for TPE-trusted users"
65872 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65873 + default 1005
65874 + help
65875 + Setting this GID determines what group TPE restrictions will be
65876 + *disabled* for. If the sysctl option is enabled, a sysctl option
65877 + with name "tpe_gid" is created.
65878 +
65879 +endmenu
65880 +menu "Network Protections"
65881 +depends on GRKERNSEC
65882 +
65883 +config GRKERNSEC_RANDNET
65884 + bool "Larger entropy pools"
65885 + default y if GRKERNSEC_CONFIG_AUTO
65886 + help
65887 + If you say Y here, the entropy pools used for many features of Linux
65888 + and grsecurity will be doubled in size. Since several grsecurity
65889 + features use additional randomness, it is recommended that you say Y
65890 + here. Saying Y here has a similar effect as modifying
65891 + /proc/sys/kernel/random/poolsize.
65892 +
65893 +config GRKERNSEC_BLACKHOLE
65894 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
65895 + default y if GRKERNSEC_CONFIG_AUTO
65896 + depends on NET
65897 + help
65898 + If you say Y here, neither TCP resets nor ICMP
65899 + destination-unreachable packets will be sent in response to packets
65900 + sent to ports for which no associated listening process exists.
65901 + This feature supports both IPV4 and IPV6 and exempts the
65902 + loopback interface from blackholing. Enabling this feature
65903 + makes a host more resilient to DoS attacks and reduces network
65904 + visibility against scanners.
65905 +
65906 + The blackhole feature as-implemented is equivalent to the FreeBSD
65907 + blackhole feature, as it prevents RST responses to all packets, not
65908 + just SYNs. Under most application behavior this causes no
65909 + problems, but applications (like haproxy) may not close certain
65910 + connections in a way that cleanly terminates them on the remote
65911 + end, leaving the remote host in LAST_ACK state. Because of this
65912 + side-effect and to prevent intentional LAST_ACK DoSes, this
65913 + feature also adds automatic mitigation against such attacks.
65914 + The mitigation drastically reduces the amount of time a socket
65915 + can spend in LAST_ACK state. If you're using haproxy and not
65916 + all servers it connects to have this option enabled, consider
65917 + disabling this feature on the haproxy host.
65918 +
65919 + If the sysctl option is enabled, two sysctl options with names
65920 + "ip_blackhole" and "lastack_retries" will be created.
65921 + While "ip_blackhole" takes the standard zero/non-zero on/off
65922 + toggle, "lastack_retries" uses the same kinds of values as
65923 + "tcp_retries1" and "tcp_retries2". The default value of 4
65924 + prevents a socket from lasting more than 45 seconds in LAST_ACK
65925 + state.
65926 +
65927 +config GRKERNSEC_NO_SIMULT_CONNECT
65928 + bool "Disable TCP Simultaneous Connect"
65929 + default y if GRKERNSEC_CONFIG_AUTO
65930 + depends on NET
65931 + help
65932 + If you say Y here, a feature by Willy Tarreau will be enabled that
65933 + removes a weakness in Linux's strict implementation of TCP that
65934 + allows two clients to connect to each other without either entering
65935 + a listening state. The weakness allows an attacker to easily prevent
65936 + a client from connecting to a known server provided the source port
65937 + for the connection is guessed correctly.
65938 +
65939 + As the weakness could be used to prevent an antivirus or IPS from
65940 + fetching updates, or prevent an SSL gateway from fetching a CRL,
65941 + it should be eliminated by enabling this option. Though Linux is
65942 + one of few operating systems supporting simultaneous connect, it
65943 + has no legitimate use in practice and is rarely supported by firewalls.
65944 +
65945 +config GRKERNSEC_SOCKET
65946 + bool "Socket restrictions"
65947 + depends on NET
65948 + help
65949 + If you say Y here, you will be able to choose from several options.
65950 + If you assign a GID on your system and add it to the supplementary
65951 + groups of users you want to restrict socket access to, this patch
65952 + will perform up to three things, based on the option(s) you choose.
65953 +
65954 +config GRKERNSEC_SOCKET_ALL
65955 + bool "Deny any sockets to group"
65956 + depends on GRKERNSEC_SOCKET
65957 + help
65958 + If you say Y here, you will be able to choose a GID of whose users will
65959 + be unable to connect to other hosts from your machine or run server
65960 + applications from your machine. If the sysctl option is enabled, a
65961 + sysctl option with name "socket_all" is created.
65962 +
65963 +config GRKERNSEC_SOCKET_ALL_GID
65964 + int "GID to deny all sockets for"
65965 + depends on GRKERNSEC_SOCKET_ALL
65966 + default 1004
65967 + help
65968 + Here you can choose the GID to disable socket access for. Remember to
65969 + add the users you want socket access disabled for to the GID
65970 + specified here. If the sysctl option is enabled, a sysctl option
65971 + with name "socket_all_gid" is created.
65972 +
65973 +config GRKERNSEC_SOCKET_CLIENT
65974 + bool "Deny client sockets to group"
65975 + depends on GRKERNSEC_SOCKET
65976 + help
65977 + If you say Y here, you will be able to choose a GID of whose users will
65978 + be unable to connect to other hosts from your machine, but will be
65979 + able to run servers. If this option is enabled, all users in the group
65980 + you specify will have to use passive mode when initiating ftp transfers
65981 + from the shell on your machine. If the sysctl option is enabled, a
65982 + sysctl option with name "socket_client" is created.
65983 +
65984 +config GRKERNSEC_SOCKET_CLIENT_GID
65985 + int "GID to deny client sockets for"
65986 + depends on GRKERNSEC_SOCKET_CLIENT
65987 + default 1003
65988 + help
65989 + Here you can choose the GID to disable client socket access for.
65990 + Remember to add the users you want client socket access disabled for to
65991 + the GID specified here. If the sysctl option is enabled, a sysctl
65992 + option with name "socket_client_gid" is created.
65993 +
65994 +config GRKERNSEC_SOCKET_SERVER
65995 + bool "Deny server sockets to group"
65996 + depends on GRKERNSEC_SOCKET
65997 + help
65998 + If you say Y here, you will be able to choose a GID of whose users will
65999 + be unable to run server applications from your machine. If the sysctl
66000 + option is enabled, a sysctl option with name "socket_server" is created.
66001 +
66002 +config GRKERNSEC_SOCKET_SERVER_GID
66003 + int "GID to deny server sockets for"
66004 + depends on GRKERNSEC_SOCKET_SERVER
66005 + default 1002
66006 + help
66007 + Here you can choose the GID to disable server socket access for.
66008 + Remember to add the users you want server socket access disabled for to
66009 + the GID specified here. If the sysctl option is enabled, a sysctl
66010 + option with name "socket_server_gid" is created.
66011 +
66012 +endmenu
66013 +
66014 +menu "Physical Protections"
66015 +depends on GRKERNSEC
66016 +
66017 +config GRKERNSEC_DENYUSB
66018 + bool "Deny new USB connections after toggle"
66019 + default y if GRKERNSEC_CONFIG_AUTO
66020 + depends on SYSCTL && USB_SUPPORT
66021 + help
66022 + If you say Y here, a new sysctl option with name "deny_new_usb"
66023 + will be created. Setting its value to 1 will prevent any new
66024 + USB devices from being recognized by the OS. Any attempted USB
66025 + device insertion will be logged. This option is intended to be
66026 + used against custom USB devices designed to exploit vulnerabilities
66027 + in various USB device drivers.
66028 +
66029 + For greatest effectiveness, this sysctl should be set after any
66030 + relevant init scripts. This option is safe to enable in distros
66031 + as each user can choose whether or not to toggle the sysctl.
66032 +
66033 +config GRKERNSEC_DENYUSB_FORCE
66034 + bool "Reject all USB devices not connected at boot"
66035 + select USB
66036 + depends on GRKERNSEC_DENYUSB
66037 + help
66038 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66039 + that doesn't involve a sysctl entry. This option should only be
66040 + enabled if you're sure you want to deny all new USB connections
66041 + at runtime and don't want to modify init scripts. This should not
66042 + be enabled by distros. It forces the core USB code to be built
66043 + into the kernel image so that all devices connected at boot time
66044 + can be recognized and new USB device connections can be prevented
66045 + prior to init running.
66046 +
66047 +endmenu
66048 +
66049 +menu "Sysctl Support"
66050 +depends on GRKERNSEC && SYSCTL
66051 +
66052 +config GRKERNSEC_SYSCTL
66053 + bool "Sysctl support"
66054 + default y if GRKERNSEC_CONFIG_AUTO
66055 + help
66056 + If you say Y here, you will be able to change the options that
66057 + grsecurity runs with at bootup, without having to recompile your
66058 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66059 + to enable (1) or disable (0) various features. All the sysctl entries
66060 + are mutable until the "grsec_lock" entry is set to a non-zero value.
66061 + All features enabled in the kernel configuration are disabled at boot
66062 + if you do not say Y to the "Turn on features by default" option.
66063 + All options should be set at startup, and the grsec_lock entry should
66064 + be set to a non-zero value after all the options are set.
66065 + *THIS IS EXTREMELY IMPORTANT*
66066 +
66067 +config GRKERNSEC_SYSCTL_DISTRO
66068 + bool "Extra sysctl support for distro makers (READ HELP)"
66069 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66070 + help
66071 + If you say Y here, additional sysctl options will be created
66072 + for features that affect processes running as root. Therefore,
66073 + it is critical when using this option that the grsec_lock entry be
66074 + enabled after boot. Only distros with prebuilt kernel packages
66075 + with this option enabled that can ensure grsec_lock is enabled
66076 + after boot should use this option.
66077 + *Failure to set grsec_lock after boot makes all grsec features
66078 + this option covers useless*
66079 +
66080 + Currently this option creates the following sysctl entries:
66081 + "Disable Privileged I/O": "disable_priv_io"
66082 +
66083 +config GRKERNSEC_SYSCTL_ON
66084 + bool "Turn on features by default"
66085 + default y if GRKERNSEC_CONFIG_AUTO
66086 + depends on GRKERNSEC_SYSCTL
66087 + help
66088 + If you say Y here, instead of having all features enabled in the
66089 + kernel configuration disabled at boot time, the features will be
66090 + enabled at boot time. It is recommended you say Y here unless
66091 + there is some reason you would want all sysctl-tunable features to
66092 + be disabled by default. As mentioned elsewhere, it is important
66093 + to enable the grsec_lock entry once you have finished modifying
66094 + the sysctl entries.
66095 +
66096 +endmenu
66097 +menu "Logging Options"
66098 +depends on GRKERNSEC
66099 +
66100 +config GRKERNSEC_FLOODTIME
66101 + int "Seconds in between log messages (minimum)"
66102 + default 10
66103 + help
66104 + This option allows you to enforce the number of seconds between
66105 + grsecurity log messages. The default should be suitable for most
66106 + people, however, if you choose to change it, choose a value small enough
66107 + to allow informative logs to be produced, but large enough to
66108 + prevent flooding.
66109 +
66110 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66111 + any rate limiting on grsecurity log messages.
66112 +
66113 +config GRKERNSEC_FLOODBURST
66114 + int "Number of messages in a burst (maximum)"
66115 + default 6
66116 + help
66117 + This option allows you to choose the maximum number of messages allowed
66118 + within the flood time interval you chose in a separate option. The
66119 + default should be suitable for most people, however if you find that
66120 + many of your logs are being interpreted as flooding, you may want to
66121 + raise this value.
66122 +
66123 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66124 + any rate limiting on grsecurity log messages.
66125 +
66126 +endmenu
66127 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66128 new file mode 100644
66129 index 0000000..5307c8a
66130 --- /dev/null
66131 +++ b/grsecurity/Makefile
66132 @@ -0,0 +1,54 @@
66133 +# grsecurity – access control and security hardening for Linux
66134 +# All code in this directory and various hooks located throughout the Linux kernel are
66135 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66136 +# http://www.grsecurity.net spender@grsecurity.net
66137 +#
66138 +# This program is free software; you can redistribute it and/or
66139 +# modify it under the terms of the GNU General Public License version 2
66140 +# as published by the Free Software Foundation.
66141 +#
66142 +# This program is distributed in the hope that it will be useful,
66143 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
66144 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66145 +# GNU General Public License for more details.
66146 +#
66147 +# You should have received a copy of the GNU General Public License
66148 +# along with this program; if not, write to the Free Software
66149 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66150 +
66151 +KBUILD_CFLAGS += -Werror
66152 +
66153 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66154 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
66155 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66156 + grsec_usb.o grsec_ipc.o
66157 +
66158 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66159 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66160 + gracl_learn.o grsec_log.o gracl_policy.o
66161 +ifdef CONFIG_COMPAT
66162 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66163 +endif
66164 +
66165 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66166 +
66167 +ifdef CONFIG_NET
66168 +obj-y += grsec_sock.o
66169 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66170 +endif
66171 +
66172 +ifndef CONFIG_GRKERNSEC
66173 +obj-y += grsec_disabled.o
66174 +endif
66175 +
66176 +ifdef CONFIG_GRKERNSEC_HIDESYM
66177 +extra-y := grsec_hidesym.o
66178 +$(obj)/grsec_hidesym.o:
66179 + @-chmod -f 500 /boot
66180 + @-chmod -f 500 /lib/modules
66181 + @-chmod -f 500 /lib64/modules
66182 + @-chmod -f 500 /lib32/modules
66183 + @-chmod -f 700 .
66184 + @-chmod -f 700 $(objtree)
66185 + @echo ' grsec: protected kernel image paths'
66186 +endif
66187 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66188 new file mode 100644
66189 index 0000000..e56396f
66190 --- /dev/null
66191 +++ b/grsecurity/gracl.c
66192 @@ -0,0 +1,2679 @@
66193 +#include <linux/kernel.h>
66194 +#include <linux/module.h>
66195 +#include <linux/sched.h>
66196 +#include <linux/mm.h>
66197 +#include <linux/file.h>
66198 +#include <linux/fs.h>
66199 +#include <linux/namei.h>
66200 +#include <linux/mount.h>
66201 +#include <linux/tty.h>
66202 +#include <linux/proc_fs.h>
66203 +#include <linux/lglock.h>
66204 +#include <linux/slab.h>
66205 +#include <linux/vmalloc.h>
66206 +#include <linux/types.h>
66207 +#include <linux/sysctl.h>
66208 +#include <linux/netdevice.h>
66209 +#include <linux/ptrace.h>
66210 +#include <linux/gracl.h>
66211 +#include <linux/gralloc.h>
66212 +#include <linux/security.h>
66213 +#include <linux/grinternal.h>
66214 +#include <linux/pid_namespace.h>
66215 +#include <linux/stop_machine.h>
66216 +#include <linux/fdtable.h>
66217 +#include <linux/percpu.h>
66218 +#include <linux/lglock.h>
66219 +#include <linux/hugetlb.h>
66220 +#include <linux/posix-timers.h>
66221 +#include <linux/prefetch.h>
66222 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66223 +#include <linux/magic.h>
66224 +#include <linux/pagemap.h>
66225 +#include "../fs/btrfs/async-thread.h"
66226 +#include "../fs/btrfs/ctree.h"
66227 +#include "../fs/btrfs/btrfs_inode.h"
66228 +#endif
66229 +#include "../fs/mount.h"
66230 +
66231 +#include <asm/uaccess.h>
66232 +#include <asm/errno.h>
66233 +#include <asm/mman.h>
66234 +
66235 +#define FOR_EACH_ROLE_START(role) \
66236 + role = running_polstate.role_list; \
66237 + while (role) {
66238 +
66239 +#define FOR_EACH_ROLE_END(role) \
66240 + role = role->prev; \
66241 + }
66242 +
66243 +extern struct path gr_real_root;
66244 +
66245 +static struct gr_policy_state running_polstate;
66246 +struct gr_policy_state *polstate = &running_polstate;
66247 +extern struct gr_alloc_state *current_alloc_state;
66248 +
66249 +extern char *gr_shared_page[4];
66250 +DEFINE_RWLOCK(gr_inode_lock);
66251 +
66252 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
66253 +
66254 +#ifdef CONFIG_NET
66255 +extern struct vfsmount *sock_mnt;
66256 +#endif
66257 +
66258 +extern struct vfsmount *pipe_mnt;
66259 +extern struct vfsmount *shm_mnt;
66260 +
66261 +#ifdef CONFIG_HUGETLBFS
66262 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66263 +#endif
66264 +
66265 +extern u16 acl_sp_role_value;
66266 +extern struct acl_object_label *fakefs_obj_rw;
66267 +extern struct acl_object_label *fakefs_obj_rwx;
66268 +
66269 +int gr_acl_is_enabled(void)
66270 +{
66271 + return (gr_status & GR_READY);
66272 +}
66273 +
66274 +void gr_enable_rbac_system(void)
66275 +{
66276 + pax_open_kernel();
66277 + gr_status |= GR_READY;
66278 + pax_close_kernel();
66279 +}
66280 +
66281 +int gr_rbac_disable(void *unused)
66282 +{
66283 + pax_open_kernel();
66284 + gr_status &= ~GR_READY;
66285 + pax_close_kernel();
66286 +
66287 + return 0;
66288 +}
66289 +
66290 +static inline dev_t __get_dev(const struct dentry *dentry)
66291 +{
66292 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66293 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66294 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
66295 + else
66296 +#endif
66297 + return dentry->d_sb->s_dev;
66298 +}
66299 +
66300 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66301 +{
66302 + return __get_dev(dentry);
66303 +}
66304 +
66305 +static char gr_task_roletype_to_char(struct task_struct *task)
66306 +{
66307 + switch (task->role->roletype &
66308 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66309 + GR_ROLE_SPECIAL)) {
66310 + case GR_ROLE_DEFAULT:
66311 + return 'D';
66312 + case GR_ROLE_USER:
66313 + return 'U';
66314 + case GR_ROLE_GROUP:
66315 + return 'G';
66316 + case GR_ROLE_SPECIAL:
66317 + return 'S';
66318 + }
66319 +
66320 + return 'X';
66321 +}
66322 +
66323 +char gr_roletype_to_char(void)
66324 +{
66325 + return gr_task_roletype_to_char(current);
66326 +}
66327 +
66328 +__inline__ int
66329 +gr_acl_tpe_check(void)
66330 +{
66331 + if (unlikely(!(gr_status & GR_READY)))
66332 + return 0;
66333 + if (current->role->roletype & GR_ROLE_TPE)
66334 + return 1;
66335 + else
66336 + return 0;
66337 +}
66338 +
66339 +int
66340 +gr_handle_rawio(const struct inode *inode)
66341 +{
66342 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66343 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66344 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66345 + !capable(CAP_SYS_RAWIO))
66346 + return 1;
66347 +#endif
66348 + return 0;
66349 +}
66350 +
66351 +int
66352 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66353 +{
66354 + if (likely(lena != lenb))
66355 + return 0;
66356 +
66357 + return !memcmp(a, b, lena);
66358 +}
66359 +
66360 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66361 +{
66362 + *buflen -= namelen;
66363 + if (*buflen < 0)
66364 + return -ENAMETOOLONG;
66365 + *buffer -= namelen;
66366 + memcpy(*buffer, str, namelen);
66367 + return 0;
66368 +}
66369 +
66370 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66371 +{
66372 + return prepend(buffer, buflen, name->name, name->len);
66373 +}
66374 +
66375 +static int prepend_path(const struct path *path, struct path *root,
66376 + char **buffer, int *buflen)
66377 +{
66378 + struct dentry *dentry = path->dentry;
66379 + struct vfsmount *vfsmnt = path->mnt;
66380 + struct mount *mnt = real_mount(vfsmnt);
66381 + bool slash = false;
66382 + int error = 0;
66383 +
66384 + while (dentry != root->dentry || vfsmnt != root->mnt) {
66385 + struct dentry * parent;
66386 +
66387 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66388 + /* Global root? */
66389 + if (!mnt_has_parent(mnt)) {
66390 + goto out;
66391 + }
66392 + dentry = mnt->mnt_mountpoint;
66393 + mnt = mnt->mnt_parent;
66394 + vfsmnt = &mnt->mnt;
66395 + continue;
66396 + }
66397 + parent = dentry->d_parent;
66398 + prefetch(parent);
66399 + spin_lock(&dentry->d_lock);
66400 + error = prepend_name(buffer, buflen, &dentry->d_name);
66401 + spin_unlock(&dentry->d_lock);
66402 + if (!error)
66403 + error = prepend(buffer, buflen, "/", 1);
66404 + if (error)
66405 + break;
66406 +
66407 + slash = true;
66408 + dentry = parent;
66409 + }
66410 +
66411 +out:
66412 + if (!error && !slash)
66413 + error = prepend(buffer, buflen, "/", 1);
66414 +
66415 + return error;
66416 +}
66417 +
66418 +/* this must be called with mount_lock and rename_lock held */
66419 +
66420 +static char *__our_d_path(const struct path *path, struct path *root,
66421 + char *buf, int buflen)
66422 +{
66423 + char *res = buf + buflen;
66424 + int error;
66425 +
66426 + prepend(&res, &buflen, "\0", 1);
66427 + error = prepend_path(path, root, &res, &buflen);
66428 + if (error)
66429 + return ERR_PTR(error);
66430 +
66431 + return res;
66432 +}
66433 +
66434 +static char *
66435 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66436 +{
66437 + char *retval;
66438 +
66439 + retval = __our_d_path(path, root, buf, buflen);
66440 + if (unlikely(IS_ERR(retval)))
66441 + retval = strcpy(buf, "<path too long>");
66442 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66443 + retval[1] = '\0';
66444 +
66445 + return retval;
66446 +}
66447 +
66448 +static char *
66449 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66450 + char *buf, int buflen)
66451 +{
66452 + struct path path;
66453 + char *res;
66454 +
66455 + path.dentry = (struct dentry *)dentry;
66456 + path.mnt = (struct vfsmount *)vfsmnt;
66457 +
66458 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66459 + by the RBAC system */
66460 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
66461 +
66462 + return res;
66463 +}
66464 +
66465 +static char *
66466 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66467 + char *buf, int buflen)
66468 +{
66469 + char *res;
66470 + struct path path;
66471 + struct path root;
66472 + struct task_struct *reaper = init_pid_ns.child_reaper;
66473 +
66474 + path.dentry = (struct dentry *)dentry;
66475 + path.mnt = (struct vfsmount *)vfsmnt;
66476 +
66477 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66478 + get_fs_root(reaper->fs, &root);
66479 +
66480 + read_seqlock_excl(&mount_lock);
66481 + write_seqlock(&rename_lock);
66482 + res = gen_full_path(&path, &root, buf, buflen);
66483 + write_sequnlock(&rename_lock);
66484 + read_sequnlock_excl(&mount_lock);
66485 +
66486 + path_put(&root);
66487 + return res;
66488 +}
66489 +
66490 +char *
66491 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66492 +{
66493 + char *ret;
66494 + read_seqlock_excl(&mount_lock);
66495 + write_seqlock(&rename_lock);
66496 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66497 + PAGE_SIZE);
66498 + write_sequnlock(&rename_lock);
66499 + read_sequnlock_excl(&mount_lock);
66500 + return ret;
66501 +}
66502 +
66503 +static char *
66504 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66505 +{
66506 + char *ret;
66507 + char *buf;
66508 + int buflen;
66509 +
66510 + read_seqlock_excl(&mount_lock);
66511 + write_seqlock(&rename_lock);
66512 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66513 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66514 + buflen = (int)(ret - buf);
66515 + if (buflen >= 5)
66516 + prepend(&ret, &buflen, "/proc", 5);
66517 + else
66518 + ret = strcpy(buf, "<path too long>");
66519 + write_sequnlock(&rename_lock);
66520 + read_sequnlock_excl(&mount_lock);
66521 + return ret;
66522 +}
66523 +
66524 +char *
66525 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66526 +{
66527 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66528 + PAGE_SIZE);
66529 +}
66530 +
66531 +char *
66532 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66533 +{
66534 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66535 + PAGE_SIZE);
66536 +}
66537 +
66538 +char *
66539 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66540 +{
66541 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66542 + PAGE_SIZE);
66543 +}
66544 +
66545 +char *
66546 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66547 +{
66548 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66549 + PAGE_SIZE);
66550 +}
66551 +
66552 +char *
66553 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66554 +{
66555 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66556 + PAGE_SIZE);
66557 +}
66558 +
66559 +__inline__ __u32
66560 +to_gr_audit(const __u32 reqmode)
66561 +{
66562 + /* masks off auditable permission flags, then shifts them to create
66563 + auditing flags, and adds the special case of append auditing if
66564 + we're requesting write */
66565 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66566 +}
66567 +
66568 +struct acl_role_label *
66569 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66570 + const gid_t gid)
66571 +{
66572 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66573 + struct acl_role_label *match;
66574 + struct role_allowed_ip *ipp;
66575 + unsigned int x;
66576 + u32 curr_ip = task->signal->saved_ip;
66577 +
66578 + match = state->acl_role_set.r_hash[index];
66579 +
66580 + while (match) {
66581 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66582 + for (x = 0; x < match->domain_child_num; x++) {
66583 + if (match->domain_children[x] == uid)
66584 + goto found;
66585 + }
66586 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66587 + break;
66588 + match = match->next;
66589 + }
66590 +found:
66591 + if (match == NULL) {
66592 + try_group:
66593 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
66594 + match = state->acl_role_set.r_hash[index];
66595 +
66596 + while (match) {
66597 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
66598 + for (x = 0; x < match->domain_child_num; x++) {
66599 + if (match->domain_children[x] == gid)
66600 + goto found2;
66601 + }
66602 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
66603 + break;
66604 + match = match->next;
66605 + }
66606 +found2:
66607 + if (match == NULL)
66608 + match = state->default_role;
66609 + if (match->allowed_ips == NULL)
66610 + return match;
66611 + else {
66612 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66613 + if (likely
66614 + ((ntohl(curr_ip) & ipp->netmask) ==
66615 + (ntohl(ipp->addr) & ipp->netmask)))
66616 + return match;
66617 + }
66618 + match = state->default_role;
66619 + }
66620 + } else if (match->allowed_ips == NULL) {
66621 + return match;
66622 + } else {
66623 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66624 + if (likely
66625 + ((ntohl(curr_ip) & ipp->netmask) ==
66626 + (ntohl(ipp->addr) & ipp->netmask)))
66627 + return match;
66628 + }
66629 + goto try_group;
66630 + }
66631 +
66632 + return match;
66633 +}
66634 +
66635 +static struct acl_role_label *
66636 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
66637 + const gid_t gid)
66638 +{
66639 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
66640 +}
66641 +
66642 +struct acl_subject_label *
66643 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
66644 + const struct acl_role_label *role)
66645 +{
66646 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66647 + struct acl_subject_label *match;
66648 +
66649 + match = role->subj_hash[index];
66650 +
66651 + while (match && (match->inode != ino || match->device != dev ||
66652 + (match->mode & GR_DELETED))) {
66653 + match = match->next;
66654 + }
66655 +
66656 + if (match && !(match->mode & GR_DELETED))
66657 + return match;
66658 + else
66659 + return NULL;
66660 +}
66661 +
66662 +struct acl_subject_label *
66663 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
66664 + const struct acl_role_label *role)
66665 +{
66666 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66667 + struct acl_subject_label *match;
66668 +
66669 + match = role->subj_hash[index];
66670 +
66671 + while (match && (match->inode != ino || match->device != dev ||
66672 + !(match->mode & GR_DELETED))) {
66673 + match = match->next;
66674 + }
66675 +
66676 + if (match && (match->mode & GR_DELETED))
66677 + return match;
66678 + else
66679 + return NULL;
66680 +}
66681 +
66682 +static struct acl_object_label *
66683 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
66684 + const struct acl_subject_label *subj)
66685 +{
66686 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66687 + struct acl_object_label *match;
66688 +
66689 + match = subj->obj_hash[index];
66690 +
66691 + while (match && (match->inode != ino || match->device != dev ||
66692 + (match->mode & GR_DELETED))) {
66693 + match = match->next;
66694 + }
66695 +
66696 + if (match && !(match->mode & GR_DELETED))
66697 + return match;
66698 + else
66699 + return NULL;
66700 +}
66701 +
66702 +static struct acl_object_label *
66703 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
66704 + const struct acl_subject_label *subj)
66705 +{
66706 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66707 + struct acl_object_label *match;
66708 +
66709 + match = subj->obj_hash[index];
66710 +
66711 + while (match && (match->inode != ino || match->device != dev ||
66712 + !(match->mode & GR_DELETED))) {
66713 + match = match->next;
66714 + }
66715 +
66716 + if (match && (match->mode & GR_DELETED))
66717 + return match;
66718 +
66719 + match = subj->obj_hash[index];
66720 +
66721 + while (match && (match->inode != ino || match->device != dev ||
66722 + (match->mode & GR_DELETED))) {
66723 + match = match->next;
66724 + }
66725 +
66726 + if (match && !(match->mode & GR_DELETED))
66727 + return match;
66728 + else
66729 + return NULL;
66730 +}
66731 +
66732 +struct name_entry *
66733 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
66734 +{
66735 + unsigned int len = strlen(name);
66736 + unsigned int key = full_name_hash(name, len);
66737 + unsigned int index = key % state->name_set.n_size;
66738 + struct name_entry *match;
66739 +
66740 + match = state->name_set.n_hash[index];
66741 +
66742 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
66743 + match = match->next;
66744 +
66745 + return match;
66746 +}
66747 +
66748 +static struct name_entry *
66749 +lookup_name_entry(const char *name)
66750 +{
66751 + return __lookup_name_entry(&running_polstate, name);
66752 +}
66753 +
66754 +static struct name_entry *
66755 +lookup_name_entry_create(const char *name)
66756 +{
66757 + unsigned int len = strlen(name);
66758 + unsigned int key = full_name_hash(name, len);
66759 + unsigned int index = key % running_polstate.name_set.n_size;
66760 + struct name_entry *match;
66761 +
66762 + match = running_polstate.name_set.n_hash[index];
66763 +
66764 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66765 + !match->deleted))
66766 + match = match->next;
66767 +
66768 + if (match && match->deleted)
66769 + return match;
66770 +
66771 + match = running_polstate.name_set.n_hash[index];
66772 +
66773 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66774 + match->deleted))
66775 + match = match->next;
66776 +
66777 + if (match && !match->deleted)
66778 + return match;
66779 + else
66780 + return NULL;
66781 +}
66782 +
66783 +static struct inodev_entry *
66784 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
66785 +{
66786 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66787 + struct inodev_entry *match;
66788 +
66789 + match = running_polstate.inodev_set.i_hash[index];
66790 +
66791 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66792 + match = match->next;
66793 +
66794 + return match;
66795 +}
66796 +
66797 +void
66798 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
66799 +{
66800 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
66801 + state->inodev_set.i_size);
66802 + struct inodev_entry **curr;
66803 +
66804 + entry->prev = NULL;
66805 +
66806 + curr = &state->inodev_set.i_hash[index];
66807 + if (*curr != NULL)
66808 + (*curr)->prev = entry;
66809 +
66810 + entry->next = *curr;
66811 + *curr = entry;
66812 +
66813 + return;
66814 +}
66815 +
66816 +static void
66817 +insert_inodev_entry(struct inodev_entry *entry)
66818 +{
66819 + __insert_inodev_entry(&running_polstate, entry);
66820 +}
66821 +
66822 +void
66823 +insert_acl_obj_label(struct acl_object_label *obj,
66824 + struct acl_subject_label *subj)
66825 +{
66826 + unsigned int index =
66827 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
66828 + struct acl_object_label **curr;
66829 +
66830 + obj->prev = NULL;
66831 +
66832 + curr = &subj->obj_hash[index];
66833 + if (*curr != NULL)
66834 + (*curr)->prev = obj;
66835 +
66836 + obj->next = *curr;
66837 + *curr = obj;
66838 +
66839 + return;
66840 +}
66841 +
66842 +void
66843 +insert_acl_subj_label(struct acl_subject_label *obj,
66844 + struct acl_role_label *role)
66845 +{
66846 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
66847 + struct acl_subject_label **curr;
66848 +
66849 + obj->prev = NULL;
66850 +
66851 + curr = &role->subj_hash[index];
66852 + if (*curr != NULL)
66853 + (*curr)->prev = obj;
66854 +
66855 + obj->next = *curr;
66856 + *curr = obj;
66857 +
66858 + return;
66859 +}
66860 +
66861 +/* derived from glibc fnmatch() 0: match, 1: no match*/
66862 +
66863 +static int
66864 +glob_match(const char *p, const char *n)
66865 +{
66866 + char c;
66867 +
66868 + while ((c = *p++) != '\0') {
66869 + switch (c) {
66870 + case '?':
66871 + if (*n == '\0')
66872 + return 1;
66873 + else if (*n == '/')
66874 + return 1;
66875 + break;
66876 + case '\\':
66877 + if (*n != c)
66878 + return 1;
66879 + break;
66880 + case '*':
66881 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
66882 + if (*n == '/')
66883 + return 1;
66884 + else if (c == '?') {
66885 + if (*n == '\0')
66886 + return 1;
66887 + else
66888 + ++n;
66889 + }
66890 + }
66891 + if (c == '\0') {
66892 + return 0;
66893 + } else {
66894 + const char *endp;
66895 +
66896 + if ((endp = strchr(n, '/')) == NULL)
66897 + endp = n + strlen(n);
66898 +
66899 + if (c == '[') {
66900 + for (--p; n < endp; ++n)
66901 + if (!glob_match(p, n))
66902 + return 0;
66903 + } else if (c == '/') {
66904 + while (*n != '\0' && *n != '/')
66905 + ++n;
66906 + if (*n == '/' && !glob_match(p, n + 1))
66907 + return 0;
66908 + } else {
66909 + for (--p; n < endp; ++n)
66910 + if (*n == c && !glob_match(p, n))
66911 + return 0;
66912 + }
66913 +
66914 + return 1;
66915 + }
66916 + case '[':
66917 + {
66918 + int not;
66919 + char cold;
66920 +
66921 + if (*n == '\0' || *n == '/')
66922 + return 1;
66923 +
66924 + not = (*p == '!' || *p == '^');
66925 + if (not)
66926 + ++p;
66927 +
66928 + c = *p++;
66929 + for (;;) {
66930 + unsigned char fn = (unsigned char)*n;
66931 +
66932 + if (c == '\0')
66933 + return 1;
66934 + else {
66935 + if (c == fn)
66936 + goto matched;
66937 + cold = c;
66938 + c = *p++;
66939 +
66940 + if (c == '-' && *p != ']') {
66941 + unsigned char cend = *p++;
66942 +
66943 + if (cend == '\0')
66944 + return 1;
66945 +
66946 + if (cold <= fn && fn <= cend)
66947 + goto matched;
66948 +
66949 + c = *p++;
66950 + }
66951 + }
66952 +
66953 + if (c == ']')
66954 + break;
66955 + }
66956 + if (!not)
66957 + return 1;
66958 + break;
66959 + matched:
66960 + while (c != ']') {
66961 + if (c == '\0')
66962 + return 1;
66963 +
66964 + c = *p++;
66965 + }
66966 + if (not)
66967 + return 1;
66968 + }
66969 + break;
66970 + default:
66971 + if (c != *n)
66972 + return 1;
66973 + }
66974 +
66975 + ++n;
66976 + }
66977 +
66978 + if (*n == '\0')
66979 + return 0;
66980 +
66981 + if (*n == '/')
66982 + return 0;
66983 +
66984 + return 1;
66985 +}
66986 +
66987 +static struct acl_object_label *
66988 +chk_glob_label(struct acl_object_label *globbed,
66989 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
66990 +{
66991 + struct acl_object_label *tmp;
66992 +
66993 + if (*path == NULL)
66994 + *path = gr_to_filename_nolock(dentry, mnt);
66995 +
66996 + tmp = globbed;
66997 +
66998 + while (tmp) {
66999 + if (!glob_match(tmp->filename, *path))
67000 + return tmp;
67001 + tmp = tmp->next;
67002 + }
67003 +
67004 + return NULL;
67005 +}
67006 +
67007 +static struct acl_object_label *
67008 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67009 + const ino_t curr_ino, const dev_t curr_dev,
67010 + const struct acl_subject_label *subj, char **path, const int checkglob)
67011 +{
67012 + struct acl_subject_label *tmpsubj;
67013 + struct acl_object_label *retval;
67014 + struct acl_object_label *retval2;
67015 +
67016 + tmpsubj = (struct acl_subject_label *) subj;
67017 + read_lock(&gr_inode_lock);
67018 + do {
67019 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67020 + if (retval) {
67021 + if (checkglob && retval->globbed) {
67022 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67023 + if (retval2)
67024 + retval = retval2;
67025 + }
67026 + break;
67027 + }
67028 + } while ((tmpsubj = tmpsubj->parent_subject));
67029 + read_unlock(&gr_inode_lock);
67030 +
67031 + return retval;
67032 +}
67033 +
67034 +static __inline__ struct acl_object_label *
67035 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67036 + struct dentry *curr_dentry,
67037 + const struct acl_subject_label *subj, char **path, const int checkglob)
67038 +{
67039 + int newglob = checkglob;
67040 + ino_t inode;
67041 + dev_t device;
67042 +
67043 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67044 + as we don't want a / * rule to match instead of the / object
67045 + don't do this for create lookups that call this function though, since they're looking up
67046 + on the parent and thus need globbing checks on all paths
67047 + */
67048 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67049 + newglob = GR_NO_GLOB;
67050 +
67051 + spin_lock(&curr_dentry->d_lock);
67052 + inode = curr_dentry->d_inode->i_ino;
67053 + device = __get_dev(curr_dentry);
67054 + spin_unlock(&curr_dentry->d_lock);
67055 +
67056 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67057 +}
67058 +
67059 +#ifdef CONFIG_HUGETLBFS
67060 +static inline bool
67061 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
67062 +{
67063 + int i;
67064 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67065 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67066 + return true;
67067 + }
67068 +
67069 + return false;
67070 +}
67071 +#endif
67072 +
67073 +static struct acl_object_label *
67074 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67075 + const struct acl_subject_label *subj, char *path, const int checkglob)
67076 +{
67077 + struct dentry *dentry = (struct dentry *) l_dentry;
67078 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67079 + struct mount *real_mnt = real_mount(mnt);
67080 + struct acl_object_label *retval;
67081 + struct dentry *parent;
67082 +
67083 + read_seqlock_excl(&mount_lock);
67084 + write_seqlock(&rename_lock);
67085 +
67086 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67087 +#ifdef CONFIG_NET
67088 + mnt == sock_mnt ||
67089 +#endif
67090 +#ifdef CONFIG_HUGETLBFS
67091 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67092 +#endif
67093 + /* ignore Eric Biederman */
67094 + IS_PRIVATE(l_dentry->d_inode))) {
67095 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67096 + goto out;
67097 + }
67098 +
67099 + for (;;) {
67100 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67101 + break;
67102 +
67103 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67104 + if (!mnt_has_parent(real_mnt))
67105 + break;
67106 +
67107 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67108 + if (retval != NULL)
67109 + goto out;
67110 +
67111 + dentry = real_mnt->mnt_mountpoint;
67112 + real_mnt = real_mnt->mnt_parent;
67113 + mnt = &real_mnt->mnt;
67114 + continue;
67115 + }
67116 +
67117 + parent = dentry->d_parent;
67118 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67119 + if (retval != NULL)
67120 + goto out;
67121 +
67122 + dentry = parent;
67123 + }
67124 +
67125 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67126 +
67127 + /* gr_real_root is pinned so we don't have to hold a reference */
67128 + if (retval == NULL)
67129 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67130 +out:
67131 + write_sequnlock(&rename_lock);
67132 + read_sequnlock_excl(&mount_lock);
67133 +
67134 + BUG_ON(retval == NULL);
67135 +
67136 + return retval;
67137 +}
67138 +
67139 +static __inline__ struct acl_object_label *
67140 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67141 + const struct acl_subject_label *subj)
67142 +{
67143 + char *path = NULL;
67144 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67145 +}
67146 +
67147 +static __inline__ struct acl_object_label *
67148 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67149 + const struct acl_subject_label *subj)
67150 +{
67151 + char *path = NULL;
67152 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67153 +}
67154 +
67155 +static __inline__ struct acl_object_label *
67156 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67157 + const struct acl_subject_label *subj, char *path)
67158 +{
67159 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67160 +}
67161 +
67162 +struct acl_subject_label *
67163 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67164 + const struct acl_role_label *role)
67165 +{
67166 + struct dentry *dentry = (struct dentry *) l_dentry;
67167 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67168 + struct mount *real_mnt = real_mount(mnt);
67169 + struct acl_subject_label *retval;
67170 + struct dentry *parent;
67171 +
67172 + read_seqlock_excl(&mount_lock);
67173 + write_seqlock(&rename_lock);
67174 +
67175 + for (;;) {
67176 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67177 + break;
67178 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67179 + if (!mnt_has_parent(real_mnt))
67180 + break;
67181 +
67182 + spin_lock(&dentry->d_lock);
67183 + read_lock(&gr_inode_lock);
67184 + retval =
67185 + lookup_acl_subj_label(dentry->d_inode->i_ino,
67186 + __get_dev(dentry), role);
67187 + read_unlock(&gr_inode_lock);
67188 + spin_unlock(&dentry->d_lock);
67189 + if (retval != NULL)
67190 + goto out;
67191 +
67192 + dentry = real_mnt->mnt_mountpoint;
67193 + real_mnt = real_mnt->mnt_parent;
67194 + mnt = &real_mnt->mnt;
67195 + continue;
67196 + }
67197 +
67198 + spin_lock(&dentry->d_lock);
67199 + read_lock(&gr_inode_lock);
67200 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67201 + __get_dev(dentry), role);
67202 + read_unlock(&gr_inode_lock);
67203 + parent = dentry->d_parent;
67204 + spin_unlock(&dentry->d_lock);
67205 +
67206 + if (retval != NULL)
67207 + goto out;
67208 +
67209 + dentry = parent;
67210 + }
67211 +
67212 + spin_lock(&dentry->d_lock);
67213 + read_lock(&gr_inode_lock);
67214 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67215 + __get_dev(dentry), role);
67216 + read_unlock(&gr_inode_lock);
67217 + spin_unlock(&dentry->d_lock);
67218 +
67219 + if (unlikely(retval == NULL)) {
67220 + /* gr_real_root is pinned, we don't need to hold a reference */
67221 + read_lock(&gr_inode_lock);
67222 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67223 + __get_dev(gr_real_root.dentry), role);
67224 + read_unlock(&gr_inode_lock);
67225 + }
67226 +out:
67227 + write_sequnlock(&rename_lock);
67228 + read_sequnlock_excl(&mount_lock);
67229 +
67230 + BUG_ON(retval == NULL);
67231 +
67232 + return retval;
67233 +}
67234 +
67235 +void
67236 +assign_special_role(const char *rolename)
67237 +{
67238 + struct acl_object_label *obj;
67239 + struct acl_role_label *r;
67240 + struct acl_role_label *assigned = NULL;
67241 + struct task_struct *tsk;
67242 + struct file *filp;
67243 +
67244 + FOR_EACH_ROLE_START(r)
67245 + if (!strcmp(rolename, r->rolename) &&
67246 + (r->roletype & GR_ROLE_SPECIAL)) {
67247 + assigned = r;
67248 + break;
67249 + }
67250 + FOR_EACH_ROLE_END(r)
67251 +
67252 + if (!assigned)
67253 + return;
67254 +
67255 + read_lock(&tasklist_lock);
67256 + read_lock(&grsec_exec_file_lock);
67257 +
67258 + tsk = current->real_parent;
67259 + if (tsk == NULL)
67260 + goto out_unlock;
67261 +
67262 + filp = tsk->exec_file;
67263 + if (filp == NULL)
67264 + goto out_unlock;
67265 +
67266 + tsk->is_writable = 0;
67267 + tsk->inherited = 0;
67268 +
67269 + tsk->acl_sp_role = 1;
67270 + tsk->acl_role_id = ++acl_sp_role_value;
67271 + tsk->role = assigned;
67272 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67273 +
67274 + /* ignore additional mmap checks for processes that are writable
67275 + by the default ACL */
67276 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67277 + if (unlikely(obj->mode & GR_WRITE))
67278 + tsk->is_writable = 1;
67279 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67280 + if (unlikely(obj->mode & GR_WRITE))
67281 + tsk->is_writable = 1;
67282 +
67283 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67284 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67285 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67286 +#endif
67287 +
67288 +out_unlock:
67289 + read_unlock(&grsec_exec_file_lock);
67290 + read_unlock(&tasklist_lock);
67291 + return;
67292 +}
67293 +
67294 +
67295 +static void
67296 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67297 +{
67298 + struct task_struct *task = current;
67299 + const struct cred *cred = current_cred();
67300 +
67301 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67302 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67303 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67304 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67305 +
67306 + return;
67307 +}
67308 +
67309 +static void
67310 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67311 +{
67312 + struct task_struct *task = current;
67313 + const struct cred *cred = current_cred();
67314 +
67315 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67316 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67317 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67318 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67319 +
67320 + return;
67321 +}
67322 +
67323 +static void
67324 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67325 +{
67326 + struct task_struct *task = current;
67327 + const struct cred *cred = current_cred();
67328 +
67329 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67330 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67331 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67332 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67333 +
67334 + return;
67335 +}
67336 +
67337 +static void
67338 +gr_set_proc_res(struct task_struct *task)
67339 +{
67340 + struct acl_subject_label *proc;
67341 + unsigned short i;
67342 +
67343 + proc = task->acl;
67344 +
67345 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67346 + return;
67347 +
67348 + for (i = 0; i < RLIM_NLIMITS; i++) {
67349 + if (!(proc->resmask & (1U << i)))
67350 + continue;
67351 +
67352 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67353 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67354 +
67355 + if (i == RLIMIT_CPU)
67356 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
67357 + }
67358 +
67359 + return;
67360 +}
67361 +
67362 +/* both of the below must be called with
67363 + rcu_read_lock();
67364 + read_lock(&tasklist_lock);
67365 + read_lock(&grsec_exec_file_lock);
67366 +*/
67367 +
67368 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67369 +{
67370 + char *tmpname;
67371 + struct acl_subject_label *tmpsubj;
67372 + struct file *filp;
67373 + struct name_entry *nmatch;
67374 +
67375 + filp = task->exec_file;
67376 + if (filp == NULL)
67377 + return NULL;
67378 +
67379 + /* the following is to apply the correct subject
67380 + on binaries running when the RBAC system
67381 + is enabled, when the binaries have been
67382 + replaced or deleted since their execution
67383 + -----
67384 + when the RBAC system starts, the inode/dev
67385 + from exec_file will be one the RBAC system
67386 + is unaware of. It only knows the inode/dev
67387 + of the present file on disk, or the absence
67388 + of it.
67389 + */
67390 +
67391 + if (filename)
67392 + nmatch = __lookup_name_entry(state, filename);
67393 + else {
67394 + preempt_disable();
67395 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67396 +
67397 + nmatch = __lookup_name_entry(state, tmpname);
67398 + preempt_enable();
67399 + }
67400 + tmpsubj = NULL;
67401 + if (nmatch) {
67402 + if (nmatch->deleted)
67403 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67404 + else
67405 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67406 + }
67407 + /* this also works for the reload case -- if we don't match a potentially inherited subject
67408 + then we fall back to a normal lookup based on the binary's ino/dev
67409 + */
67410 + if (tmpsubj == NULL)
67411 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67412 +
67413 + return tmpsubj;
67414 +}
67415 +
67416 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67417 +{
67418 + return __gr_get_subject_for_task(&running_polstate, task, filename);
67419 +}
67420 +
67421 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67422 +{
67423 + struct acl_object_label *obj;
67424 + struct file *filp;
67425 +
67426 + filp = task->exec_file;
67427 +
67428 + task->acl = subj;
67429 + task->is_writable = 0;
67430 + /* ignore additional mmap checks for processes that are writable
67431 + by the default ACL */
67432 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67433 + if (unlikely(obj->mode & GR_WRITE))
67434 + task->is_writable = 1;
67435 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67436 + if (unlikely(obj->mode & GR_WRITE))
67437 + task->is_writable = 1;
67438 +
67439 + gr_set_proc_res(task);
67440 +
67441 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67442 + 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);
67443 +#endif
67444 +}
67445 +
67446 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67447 +{
67448 + __gr_apply_subject_to_task(&running_polstate, task, subj);
67449 +}
67450 +
67451 +__u32
67452 +gr_search_file(const struct dentry * dentry, const __u32 mode,
67453 + const struct vfsmount * mnt)
67454 +{
67455 + __u32 retval = mode;
67456 + struct acl_subject_label *curracl;
67457 + struct acl_object_label *currobj;
67458 +
67459 + if (unlikely(!(gr_status & GR_READY)))
67460 + return (mode & ~GR_AUDITS);
67461 +
67462 + curracl = current->acl;
67463 +
67464 + currobj = chk_obj_label(dentry, mnt, curracl);
67465 + retval = currobj->mode & mode;
67466 +
67467 + /* if we're opening a specified transfer file for writing
67468 + (e.g. /dev/initctl), then transfer our role to init
67469 + */
67470 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67471 + current->role->roletype & GR_ROLE_PERSIST)) {
67472 + struct task_struct *task = init_pid_ns.child_reaper;
67473 +
67474 + if (task->role != current->role) {
67475 + struct acl_subject_label *subj;
67476 +
67477 + task->acl_sp_role = 0;
67478 + task->acl_role_id = current->acl_role_id;
67479 + task->role = current->role;
67480 + rcu_read_lock();
67481 + read_lock(&grsec_exec_file_lock);
67482 + subj = gr_get_subject_for_task(task, NULL);
67483 + gr_apply_subject_to_task(task, subj);
67484 + read_unlock(&grsec_exec_file_lock);
67485 + rcu_read_unlock();
67486 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67487 + }
67488 + }
67489 +
67490 + if (unlikely
67491 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67492 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67493 + __u32 new_mode = mode;
67494 +
67495 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67496 +
67497 + retval = new_mode;
67498 +
67499 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67500 + new_mode |= GR_INHERIT;
67501 +
67502 + if (!(mode & GR_NOLEARN))
67503 + gr_log_learn(dentry, mnt, new_mode);
67504 + }
67505 +
67506 + return retval;
67507 +}
67508 +
67509 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67510 + const struct dentry *parent,
67511 + const struct vfsmount *mnt)
67512 +{
67513 + struct name_entry *match;
67514 + struct acl_object_label *matchpo;
67515 + struct acl_subject_label *curracl;
67516 + char *path;
67517 +
67518 + if (unlikely(!(gr_status & GR_READY)))
67519 + return NULL;
67520 +
67521 + preempt_disable();
67522 + path = gr_to_filename_rbac(new_dentry, mnt);
67523 + match = lookup_name_entry_create(path);
67524 +
67525 + curracl = current->acl;
67526 +
67527 + if (match) {
67528 + read_lock(&gr_inode_lock);
67529 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67530 + read_unlock(&gr_inode_lock);
67531 +
67532 + if (matchpo) {
67533 + preempt_enable();
67534 + return matchpo;
67535 + }
67536 + }
67537 +
67538 + // lookup parent
67539 +
67540 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67541 +
67542 + preempt_enable();
67543 + return matchpo;
67544 +}
67545 +
67546 +__u32
67547 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67548 + const struct vfsmount * mnt, const __u32 mode)
67549 +{
67550 + struct acl_object_label *matchpo;
67551 + __u32 retval;
67552 +
67553 + if (unlikely(!(gr_status & GR_READY)))
67554 + return (mode & ~GR_AUDITS);
67555 +
67556 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
67557 +
67558 + retval = matchpo->mode & mode;
67559 +
67560 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67561 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67562 + __u32 new_mode = mode;
67563 +
67564 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67565 +
67566 + gr_log_learn(new_dentry, mnt, new_mode);
67567 + return new_mode;
67568 + }
67569 +
67570 + return retval;
67571 +}
67572 +
67573 +__u32
67574 +gr_check_link(const struct dentry * new_dentry,
67575 + const struct dentry * parent_dentry,
67576 + const struct vfsmount * parent_mnt,
67577 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67578 +{
67579 + struct acl_object_label *obj;
67580 + __u32 oldmode, newmode;
67581 + __u32 needmode;
67582 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67583 + GR_DELETE | GR_INHERIT;
67584 +
67585 + if (unlikely(!(gr_status & GR_READY)))
67586 + return (GR_CREATE | GR_LINK);
67587 +
67588 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
67589 + oldmode = obj->mode;
67590 +
67591 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
67592 + newmode = obj->mode;
67593 +
67594 + needmode = newmode & checkmodes;
67595 +
67596 + // old name for hardlink must have at least the permissions of the new name
67597 + if ((oldmode & needmode) != needmode)
67598 + goto bad;
67599 +
67600 + // if old name had restrictions/auditing, make sure the new name does as well
67601 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
67602 +
67603 + // don't allow hardlinking of suid/sgid/fcapped files without permission
67604 + if (is_privileged_binary(old_dentry))
67605 + needmode |= GR_SETID;
67606 +
67607 + if ((newmode & needmode) != needmode)
67608 + goto bad;
67609 +
67610 + // enforce minimum permissions
67611 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
67612 + return newmode;
67613 +bad:
67614 + needmode = oldmode;
67615 + if (is_privileged_binary(old_dentry))
67616 + needmode |= GR_SETID;
67617 +
67618 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
67619 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
67620 + return (GR_CREATE | GR_LINK);
67621 + } else if (newmode & GR_SUPPRESS)
67622 + return GR_SUPPRESS;
67623 + else
67624 + return 0;
67625 +}
67626 +
67627 +int
67628 +gr_check_hidden_task(const struct task_struct *task)
67629 +{
67630 + if (unlikely(!(gr_status & GR_READY)))
67631 + return 0;
67632 +
67633 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
67634 + return 1;
67635 +
67636 + return 0;
67637 +}
67638 +
67639 +int
67640 +gr_check_protected_task(const struct task_struct *task)
67641 +{
67642 + if (unlikely(!(gr_status & GR_READY) || !task))
67643 + return 0;
67644 +
67645 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67646 + task->acl != current->acl)
67647 + return 1;
67648 +
67649 + return 0;
67650 +}
67651 +
67652 +int
67653 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67654 +{
67655 + struct task_struct *p;
67656 + int ret = 0;
67657 +
67658 + if (unlikely(!(gr_status & GR_READY) || !pid))
67659 + return ret;
67660 +
67661 + read_lock(&tasklist_lock);
67662 + do_each_pid_task(pid, type, p) {
67663 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67664 + p->acl != current->acl) {
67665 + ret = 1;
67666 + goto out;
67667 + }
67668 + } while_each_pid_task(pid, type, p);
67669 +out:
67670 + read_unlock(&tasklist_lock);
67671 +
67672 + return ret;
67673 +}
67674 +
67675 +void
67676 +gr_copy_label(struct task_struct *tsk)
67677 +{
67678 + struct task_struct *p = current;
67679 +
67680 + tsk->inherited = p->inherited;
67681 + tsk->acl_sp_role = 0;
67682 + tsk->acl_role_id = p->acl_role_id;
67683 + tsk->acl = p->acl;
67684 + tsk->role = p->role;
67685 + tsk->signal->used_accept = 0;
67686 + tsk->signal->curr_ip = p->signal->curr_ip;
67687 + tsk->signal->saved_ip = p->signal->saved_ip;
67688 + if (p->exec_file)
67689 + get_file(p->exec_file);
67690 + tsk->exec_file = p->exec_file;
67691 + tsk->is_writable = p->is_writable;
67692 + if (unlikely(p->signal->used_accept)) {
67693 + p->signal->curr_ip = 0;
67694 + p->signal->saved_ip = 0;
67695 + }
67696 +
67697 + return;
67698 +}
67699 +
67700 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
67701 +
67702 +int
67703 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
67704 +{
67705 + unsigned int i;
67706 + __u16 num;
67707 + uid_t *uidlist;
67708 + uid_t curuid;
67709 + int realok = 0;
67710 + int effectiveok = 0;
67711 + int fsok = 0;
67712 + uid_t globalreal, globaleffective, globalfs;
67713 +
67714 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
67715 + struct user_struct *user;
67716 +
67717 + if (!uid_valid(real))
67718 + goto skipit;
67719 +
67720 + /* find user based on global namespace */
67721 +
67722 + globalreal = GR_GLOBAL_UID(real);
67723 +
67724 + user = find_user(make_kuid(&init_user_ns, globalreal));
67725 + if (user == NULL)
67726 + goto skipit;
67727 +
67728 + if (gr_process_kernel_setuid_ban(user)) {
67729 + /* for find_user */
67730 + free_uid(user);
67731 + return 1;
67732 + }
67733 +
67734 + /* for find_user */
67735 + free_uid(user);
67736 +
67737 +skipit:
67738 +#endif
67739 +
67740 + if (unlikely(!(gr_status & GR_READY)))
67741 + return 0;
67742 +
67743 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67744 + gr_log_learn_uid_change(real, effective, fs);
67745 +
67746 + num = current->acl->user_trans_num;
67747 + uidlist = current->acl->user_transitions;
67748 +
67749 + if (uidlist == NULL)
67750 + return 0;
67751 +
67752 + if (!uid_valid(real)) {
67753 + realok = 1;
67754 + globalreal = (uid_t)-1;
67755 + } else {
67756 + globalreal = GR_GLOBAL_UID(real);
67757 + }
67758 + if (!uid_valid(effective)) {
67759 + effectiveok = 1;
67760 + globaleffective = (uid_t)-1;
67761 + } else {
67762 + globaleffective = GR_GLOBAL_UID(effective);
67763 + }
67764 + if (!uid_valid(fs)) {
67765 + fsok = 1;
67766 + globalfs = (uid_t)-1;
67767 + } else {
67768 + globalfs = GR_GLOBAL_UID(fs);
67769 + }
67770 +
67771 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
67772 + for (i = 0; i < num; i++) {
67773 + curuid = uidlist[i];
67774 + if (globalreal == curuid)
67775 + realok = 1;
67776 + if (globaleffective == curuid)
67777 + effectiveok = 1;
67778 + if (globalfs == curuid)
67779 + fsok = 1;
67780 + }
67781 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
67782 + for (i = 0; i < num; i++) {
67783 + curuid = uidlist[i];
67784 + if (globalreal == curuid)
67785 + break;
67786 + if (globaleffective == curuid)
67787 + break;
67788 + if (globalfs == curuid)
67789 + break;
67790 + }
67791 + /* not in deny list */
67792 + if (i == num) {
67793 + realok = 1;
67794 + effectiveok = 1;
67795 + fsok = 1;
67796 + }
67797 + }
67798 +
67799 + if (realok && effectiveok && fsok)
67800 + return 0;
67801 + else {
67802 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67803 + return 1;
67804 + }
67805 +}
67806 +
67807 +int
67808 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
67809 +{
67810 + unsigned int i;
67811 + __u16 num;
67812 + gid_t *gidlist;
67813 + gid_t curgid;
67814 + int realok = 0;
67815 + int effectiveok = 0;
67816 + int fsok = 0;
67817 + gid_t globalreal, globaleffective, globalfs;
67818 +
67819 + if (unlikely(!(gr_status & GR_READY)))
67820 + return 0;
67821 +
67822 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67823 + gr_log_learn_gid_change(real, effective, fs);
67824 +
67825 + num = current->acl->group_trans_num;
67826 + gidlist = current->acl->group_transitions;
67827 +
67828 + if (gidlist == NULL)
67829 + return 0;
67830 +
67831 + if (!gid_valid(real)) {
67832 + realok = 1;
67833 + globalreal = (gid_t)-1;
67834 + } else {
67835 + globalreal = GR_GLOBAL_GID(real);
67836 + }
67837 + if (!gid_valid(effective)) {
67838 + effectiveok = 1;
67839 + globaleffective = (gid_t)-1;
67840 + } else {
67841 + globaleffective = GR_GLOBAL_GID(effective);
67842 + }
67843 + if (!gid_valid(fs)) {
67844 + fsok = 1;
67845 + globalfs = (gid_t)-1;
67846 + } else {
67847 + globalfs = GR_GLOBAL_GID(fs);
67848 + }
67849 +
67850 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
67851 + for (i = 0; i < num; i++) {
67852 + curgid = gidlist[i];
67853 + if (globalreal == curgid)
67854 + realok = 1;
67855 + if (globaleffective == curgid)
67856 + effectiveok = 1;
67857 + if (globalfs == curgid)
67858 + fsok = 1;
67859 + }
67860 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
67861 + for (i = 0; i < num; i++) {
67862 + curgid = gidlist[i];
67863 + if (globalreal == curgid)
67864 + break;
67865 + if (globaleffective == curgid)
67866 + break;
67867 + if (globalfs == curgid)
67868 + break;
67869 + }
67870 + /* not in deny list */
67871 + if (i == num) {
67872 + realok = 1;
67873 + effectiveok = 1;
67874 + fsok = 1;
67875 + }
67876 + }
67877 +
67878 + if (realok && effectiveok && fsok)
67879 + return 0;
67880 + else {
67881 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67882 + return 1;
67883 + }
67884 +}
67885 +
67886 +extern int gr_acl_is_capable(const int cap);
67887 +
67888 +void
67889 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
67890 +{
67891 + struct acl_role_label *role = task->role;
67892 + struct acl_subject_label *subj = NULL;
67893 + struct acl_object_label *obj;
67894 + struct file *filp;
67895 + uid_t uid;
67896 + gid_t gid;
67897 +
67898 + if (unlikely(!(gr_status & GR_READY)))
67899 + return;
67900 +
67901 + uid = GR_GLOBAL_UID(kuid);
67902 + gid = GR_GLOBAL_GID(kgid);
67903 +
67904 + filp = task->exec_file;
67905 +
67906 + /* kernel process, we'll give them the kernel role */
67907 + if (unlikely(!filp)) {
67908 + task->role = running_polstate.kernel_role;
67909 + task->acl = running_polstate.kernel_role->root_label;
67910 + return;
67911 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
67912 + /* save the current ip at time of role lookup so that the proper
67913 + IP will be learned for role_allowed_ip */
67914 + task->signal->saved_ip = task->signal->curr_ip;
67915 + role = lookup_acl_role_label(task, uid, gid);
67916 + }
67917 +
67918 + /* don't change the role if we're not a privileged process */
67919 + if (role && task->role != role &&
67920 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
67921 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
67922 + return;
67923 +
67924 + /* perform subject lookup in possibly new role
67925 + we can use this result below in the case where role == task->role
67926 + */
67927 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
67928 +
67929 + /* if we changed uid/gid, but result in the same role
67930 + and are using inheritance, don't lose the inherited subject
67931 + if current subject is other than what normal lookup
67932 + would result in, we arrived via inheritance, don't
67933 + lose subject
67934 + */
67935 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
67936 + (subj == task->acl)))
67937 + task->acl = subj;
67938 +
67939 + /* leave task->inherited unaffected */
67940 +
67941 + task->role = role;
67942 +
67943 + task->is_writable = 0;
67944 +
67945 + /* ignore additional mmap checks for processes that are writable
67946 + by the default ACL */
67947 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67948 + if (unlikely(obj->mode & GR_WRITE))
67949 + task->is_writable = 1;
67950 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67951 + if (unlikely(obj->mode & GR_WRITE))
67952 + task->is_writable = 1;
67953 +
67954 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67955 + 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);
67956 +#endif
67957 +
67958 + gr_set_proc_res(task);
67959 +
67960 + return;
67961 +}
67962 +
67963 +int
67964 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
67965 + const int unsafe_flags)
67966 +{
67967 + struct task_struct *task = current;
67968 + struct acl_subject_label *newacl;
67969 + struct acl_object_label *obj;
67970 + __u32 retmode;
67971 +
67972 + if (unlikely(!(gr_status & GR_READY)))
67973 + return 0;
67974 +
67975 + newacl = chk_subj_label(dentry, mnt, task->role);
67976 +
67977 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
67978 + did an exec
67979 + */
67980 + rcu_read_lock();
67981 + read_lock(&tasklist_lock);
67982 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
67983 + (task->parent->acl->mode & GR_POVERRIDE))) {
67984 + read_unlock(&tasklist_lock);
67985 + rcu_read_unlock();
67986 + goto skip_check;
67987 + }
67988 + read_unlock(&tasklist_lock);
67989 + rcu_read_unlock();
67990 +
67991 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
67992 + !(task->role->roletype & GR_ROLE_GOD) &&
67993 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
67994 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67995 + if (unsafe_flags & LSM_UNSAFE_SHARE)
67996 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
67997 + else
67998 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
67999 + return -EACCES;
68000 + }
68001 +
68002 +skip_check:
68003 +
68004 + obj = chk_obj_label(dentry, mnt, task->acl);
68005 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68006 +
68007 + if (!(task->acl->mode & GR_INHERITLEARN) &&
68008 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68009 + if (obj->nested)
68010 + task->acl = obj->nested;
68011 + else
68012 + task->acl = newacl;
68013 + task->inherited = 0;
68014 + } else {
68015 + task->inherited = 1;
68016 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68017 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68018 + }
68019 +
68020 + task->is_writable = 0;
68021 +
68022 + /* ignore additional mmap checks for processes that are writable
68023 + by the default ACL */
68024 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68025 + if (unlikely(obj->mode & GR_WRITE))
68026 + task->is_writable = 1;
68027 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
68028 + if (unlikely(obj->mode & GR_WRITE))
68029 + task->is_writable = 1;
68030 +
68031 + gr_set_proc_res(task);
68032 +
68033 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68034 + 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);
68035 +#endif
68036 + return 0;
68037 +}
68038 +
68039 +/* always called with valid inodev ptr */
68040 +static void
68041 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68042 +{
68043 + struct acl_object_label *matchpo;
68044 + struct acl_subject_label *matchps;
68045 + struct acl_subject_label *subj;
68046 + struct acl_role_label *role;
68047 + unsigned int x;
68048 +
68049 + FOR_EACH_ROLE_START(role)
68050 + FOR_EACH_SUBJECT_START(role, subj, x)
68051 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68052 + matchpo->mode |= GR_DELETED;
68053 + FOR_EACH_SUBJECT_END(subj,x)
68054 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68055 + /* nested subjects aren't in the role's subj_hash table */
68056 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68057 + matchpo->mode |= GR_DELETED;
68058 + FOR_EACH_NESTED_SUBJECT_END(subj)
68059 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68060 + matchps->mode |= GR_DELETED;
68061 + FOR_EACH_ROLE_END(role)
68062 +
68063 + inodev->nentry->deleted = 1;
68064 +
68065 + return;
68066 +}
68067 +
68068 +void
68069 +gr_handle_delete(const ino_t ino, const dev_t dev)
68070 +{
68071 + struct inodev_entry *inodev;
68072 +
68073 + if (unlikely(!(gr_status & GR_READY)))
68074 + return;
68075 +
68076 + write_lock(&gr_inode_lock);
68077 + inodev = lookup_inodev_entry(ino, dev);
68078 + if (inodev != NULL)
68079 + do_handle_delete(inodev, ino, dev);
68080 + write_unlock(&gr_inode_lock);
68081 +
68082 + return;
68083 +}
68084 +
68085 +static void
68086 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68087 + const ino_t newinode, const dev_t newdevice,
68088 + struct acl_subject_label *subj)
68089 +{
68090 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68091 + struct acl_object_label *match;
68092 +
68093 + match = subj->obj_hash[index];
68094 +
68095 + while (match && (match->inode != oldinode ||
68096 + match->device != olddevice ||
68097 + !(match->mode & GR_DELETED)))
68098 + match = match->next;
68099 +
68100 + if (match && (match->inode == oldinode)
68101 + && (match->device == olddevice)
68102 + && (match->mode & GR_DELETED)) {
68103 + if (match->prev == NULL) {
68104 + subj->obj_hash[index] = match->next;
68105 + if (match->next != NULL)
68106 + match->next->prev = NULL;
68107 + } else {
68108 + match->prev->next = match->next;
68109 + if (match->next != NULL)
68110 + match->next->prev = match->prev;
68111 + }
68112 + match->prev = NULL;
68113 + match->next = NULL;
68114 + match->inode = newinode;
68115 + match->device = newdevice;
68116 + match->mode &= ~GR_DELETED;
68117 +
68118 + insert_acl_obj_label(match, subj);
68119 + }
68120 +
68121 + return;
68122 +}
68123 +
68124 +static void
68125 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68126 + const ino_t newinode, const dev_t newdevice,
68127 + struct acl_role_label *role)
68128 +{
68129 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68130 + struct acl_subject_label *match;
68131 +
68132 + match = role->subj_hash[index];
68133 +
68134 + while (match && (match->inode != oldinode ||
68135 + match->device != olddevice ||
68136 + !(match->mode & GR_DELETED)))
68137 + match = match->next;
68138 +
68139 + if (match && (match->inode == oldinode)
68140 + && (match->device == olddevice)
68141 + && (match->mode & GR_DELETED)) {
68142 + if (match->prev == NULL) {
68143 + role->subj_hash[index] = match->next;
68144 + if (match->next != NULL)
68145 + match->next->prev = NULL;
68146 + } else {
68147 + match->prev->next = match->next;
68148 + if (match->next != NULL)
68149 + match->next->prev = match->prev;
68150 + }
68151 + match->prev = NULL;
68152 + match->next = NULL;
68153 + match->inode = newinode;
68154 + match->device = newdevice;
68155 + match->mode &= ~GR_DELETED;
68156 +
68157 + insert_acl_subj_label(match, role);
68158 + }
68159 +
68160 + return;
68161 +}
68162 +
68163 +static void
68164 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68165 + const ino_t newinode, const dev_t newdevice)
68166 +{
68167 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68168 + struct inodev_entry *match;
68169 +
68170 + match = running_polstate.inodev_set.i_hash[index];
68171 +
68172 + while (match && (match->nentry->inode != oldinode ||
68173 + match->nentry->device != olddevice || !match->nentry->deleted))
68174 + match = match->next;
68175 +
68176 + if (match && (match->nentry->inode == oldinode)
68177 + && (match->nentry->device == olddevice) &&
68178 + match->nentry->deleted) {
68179 + if (match->prev == NULL) {
68180 + running_polstate.inodev_set.i_hash[index] = match->next;
68181 + if (match->next != NULL)
68182 + match->next->prev = NULL;
68183 + } else {
68184 + match->prev->next = match->next;
68185 + if (match->next != NULL)
68186 + match->next->prev = match->prev;
68187 + }
68188 + match->prev = NULL;
68189 + match->next = NULL;
68190 + match->nentry->inode = newinode;
68191 + match->nentry->device = newdevice;
68192 + match->nentry->deleted = 0;
68193 +
68194 + insert_inodev_entry(match);
68195 + }
68196 +
68197 + return;
68198 +}
68199 +
68200 +static void
68201 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68202 +{
68203 + struct acl_subject_label *subj;
68204 + struct acl_role_label *role;
68205 + unsigned int x;
68206 +
68207 + FOR_EACH_ROLE_START(role)
68208 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68209 +
68210 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68211 + if ((subj->inode == ino) && (subj->device == dev)) {
68212 + subj->inode = ino;
68213 + subj->device = dev;
68214 + }
68215 + /* nested subjects aren't in the role's subj_hash table */
68216 + update_acl_obj_label(matchn->inode, matchn->device,
68217 + ino, dev, subj);
68218 + FOR_EACH_NESTED_SUBJECT_END(subj)
68219 + FOR_EACH_SUBJECT_START(role, subj, x)
68220 + update_acl_obj_label(matchn->inode, matchn->device,
68221 + ino, dev, subj);
68222 + FOR_EACH_SUBJECT_END(subj,x)
68223 + FOR_EACH_ROLE_END(role)
68224 +
68225 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68226 +
68227 + return;
68228 +}
68229 +
68230 +static void
68231 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68232 + const struct vfsmount *mnt)
68233 +{
68234 + ino_t ino = dentry->d_inode->i_ino;
68235 + dev_t dev = __get_dev(dentry);
68236 +
68237 + __do_handle_create(matchn, ino, dev);
68238 +
68239 + return;
68240 +}
68241 +
68242 +void
68243 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68244 +{
68245 + struct name_entry *matchn;
68246 +
68247 + if (unlikely(!(gr_status & GR_READY)))
68248 + return;
68249 +
68250 + preempt_disable();
68251 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68252 +
68253 + if (unlikely((unsigned long)matchn)) {
68254 + write_lock(&gr_inode_lock);
68255 + do_handle_create(matchn, dentry, mnt);
68256 + write_unlock(&gr_inode_lock);
68257 + }
68258 + preempt_enable();
68259 +
68260 + return;
68261 +}
68262 +
68263 +void
68264 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68265 +{
68266 + struct name_entry *matchn;
68267 +
68268 + if (unlikely(!(gr_status & GR_READY)))
68269 + return;
68270 +
68271 + preempt_disable();
68272 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68273 +
68274 + if (unlikely((unsigned long)matchn)) {
68275 + write_lock(&gr_inode_lock);
68276 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68277 + write_unlock(&gr_inode_lock);
68278 + }
68279 + preempt_enable();
68280 +
68281 + return;
68282 +}
68283 +
68284 +void
68285 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68286 + struct dentry *old_dentry,
68287 + struct dentry *new_dentry,
68288 + struct vfsmount *mnt, const __u8 replace)
68289 +{
68290 + struct name_entry *matchn;
68291 + struct inodev_entry *inodev;
68292 + struct inode *inode = new_dentry->d_inode;
68293 + ino_t old_ino = old_dentry->d_inode->i_ino;
68294 + dev_t old_dev = __get_dev(old_dentry);
68295 +
68296 + /* vfs_rename swaps the name and parent link for old_dentry and
68297 + new_dentry
68298 + at this point, old_dentry has the new name, parent link, and inode
68299 + for the renamed file
68300 + if a file is being replaced by a rename, new_dentry has the inode
68301 + and name for the replaced file
68302 + */
68303 +
68304 + if (unlikely(!(gr_status & GR_READY)))
68305 + return;
68306 +
68307 + preempt_disable();
68308 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68309 +
68310 + /* we wouldn't have to check d_inode if it weren't for
68311 + NFS silly-renaming
68312 + */
68313 +
68314 + write_lock(&gr_inode_lock);
68315 + if (unlikely(replace && inode)) {
68316 + ino_t new_ino = inode->i_ino;
68317 + dev_t new_dev = __get_dev(new_dentry);
68318 +
68319 + inodev = lookup_inodev_entry(new_ino, new_dev);
68320 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68321 + do_handle_delete(inodev, new_ino, new_dev);
68322 + }
68323 +
68324 + inodev = lookup_inodev_entry(old_ino, old_dev);
68325 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68326 + do_handle_delete(inodev, old_ino, old_dev);
68327 +
68328 + if (unlikely((unsigned long)matchn))
68329 + do_handle_create(matchn, old_dentry, mnt);
68330 +
68331 + write_unlock(&gr_inode_lock);
68332 + preempt_enable();
68333 +
68334 + return;
68335 +}
68336 +
68337 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68338 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68339 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68340 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68341 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68342 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68343 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68344 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68345 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68346 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68347 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68348 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68349 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68350 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68351 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68352 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68353 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68354 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68355 +};
68356 +
68357 +void
68358 +gr_learn_resource(const struct task_struct *task,
68359 + const int res, const unsigned long wanted, const int gt)
68360 +{
68361 + struct acl_subject_label *acl;
68362 + const struct cred *cred;
68363 +
68364 + if (unlikely((gr_status & GR_READY) &&
68365 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68366 + goto skip_reslog;
68367 +
68368 + gr_log_resource(task, res, wanted, gt);
68369 +skip_reslog:
68370 +
68371 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68372 + return;
68373 +
68374 + acl = task->acl;
68375 +
68376 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68377 + !(acl->resmask & (1U << (unsigned short) res))))
68378 + return;
68379 +
68380 + if (wanted >= acl->res[res].rlim_cur) {
68381 + unsigned long res_add;
68382 +
68383 + res_add = wanted + res_learn_bumps[res];
68384 +
68385 + acl->res[res].rlim_cur = res_add;
68386 +
68387 + if (wanted > acl->res[res].rlim_max)
68388 + acl->res[res].rlim_max = res_add;
68389 +
68390 + /* only log the subject filename, since resource logging is supported for
68391 + single-subject learning only */
68392 + rcu_read_lock();
68393 + cred = __task_cred(task);
68394 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68395 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68396 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68397 + "", (unsigned long) res, &task->signal->saved_ip);
68398 + rcu_read_unlock();
68399 + }
68400 +
68401 + return;
68402 +}
68403 +EXPORT_SYMBOL_GPL(gr_learn_resource);
68404 +#endif
68405 +
68406 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68407 +void
68408 +pax_set_initial_flags(struct linux_binprm *bprm)
68409 +{
68410 + struct task_struct *task = current;
68411 + struct acl_subject_label *proc;
68412 + unsigned long flags;
68413 +
68414 + if (unlikely(!(gr_status & GR_READY)))
68415 + return;
68416 +
68417 + flags = pax_get_flags(task);
68418 +
68419 + proc = task->acl;
68420 +
68421 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68422 + flags &= ~MF_PAX_PAGEEXEC;
68423 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68424 + flags &= ~MF_PAX_SEGMEXEC;
68425 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68426 + flags &= ~MF_PAX_RANDMMAP;
68427 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68428 + flags &= ~MF_PAX_EMUTRAMP;
68429 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68430 + flags &= ~MF_PAX_MPROTECT;
68431 +
68432 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68433 + flags |= MF_PAX_PAGEEXEC;
68434 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68435 + flags |= MF_PAX_SEGMEXEC;
68436 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68437 + flags |= MF_PAX_RANDMMAP;
68438 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68439 + flags |= MF_PAX_EMUTRAMP;
68440 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68441 + flags |= MF_PAX_MPROTECT;
68442 +
68443 + pax_set_flags(task, flags);
68444 +
68445 + return;
68446 +}
68447 +#endif
68448 +
68449 +int
68450 +gr_handle_proc_ptrace(struct task_struct *task)
68451 +{
68452 + struct file *filp;
68453 + struct task_struct *tmp = task;
68454 + struct task_struct *curtemp = current;
68455 + __u32 retmode;
68456 +
68457 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68458 + if (unlikely(!(gr_status & GR_READY)))
68459 + return 0;
68460 +#endif
68461 +
68462 + read_lock(&tasklist_lock);
68463 + read_lock(&grsec_exec_file_lock);
68464 + filp = task->exec_file;
68465 +
68466 + while (task_pid_nr(tmp) > 0) {
68467 + if (tmp == curtemp)
68468 + break;
68469 + tmp = tmp->real_parent;
68470 + }
68471 +
68472 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68473 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68474 + read_unlock(&grsec_exec_file_lock);
68475 + read_unlock(&tasklist_lock);
68476 + return 1;
68477 + }
68478 +
68479 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68480 + if (!(gr_status & GR_READY)) {
68481 + read_unlock(&grsec_exec_file_lock);
68482 + read_unlock(&tasklist_lock);
68483 + return 0;
68484 + }
68485 +#endif
68486 +
68487 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68488 + read_unlock(&grsec_exec_file_lock);
68489 + read_unlock(&tasklist_lock);
68490 +
68491 + if (retmode & GR_NOPTRACE)
68492 + return 1;
68493 +
68494 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68495 + && (current->acl != task->acl || (current->acl != current->role->root_label
68496 + && task_pid_nr(current) != task_pid_nr(task))))
68497 + return 1;
68498 +
68499 + return 0;
68500 +}
68501 +
68502 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68503 +{
68504 + if (unlikely(!(gr_status & GR_READY)))
68505 + return;
68506 +
68507 + if (!(current->role->roletype & GR_ROLE_GOD))
68508 + return;
68509 +
68510 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68511 + p->role->rolename, gr_task_roletype_to_char(p),
68512 + p->acl->filename);
68513 +}
68514 +
68515 +int
68516 +gr_handle_ptrace(struct task_struct *task, const long request)
68517 +{
68518 + struct task_struct *tmp = task;
68519 + struct task_struct *curtemp = current;
68520 + __u32 retmode;
68521 +
68522 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68523 + if (unlikely(!(gr_status & GR_READY)))
68524 + return 0;
68525 +#endif
68526 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68527 + read_lock(&tasklist_lock);
68528 + while (task_pid_nr(tmp) > 0) {
68529 + if (tmp == curtemp)
68530 + break;
68531 + tmp = tmp->real_parent;
68532 + }
68533 +
68534 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68535 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68536 + read_unlock(&tasklist_lock);
68537 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68538 + return 1;
68539 + }
68540 + read_unlock(&tasklist_lock);
68541 + }
68542 +
68543 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68544 + if (!(gr_status & GR_READY))
68545 + return 0;
68546 +#endif
68547 +
68548 + read_lock(&grsec_exec_file_lock);
68549 + if (unlikely(!task->exec_file)) {
68550 + read_unlock(&grsec_exec_file_lock);
68551 + return 0;
68552 + }
68553 +
68554 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68555 + read_unlock(&grsec_exec_file_lock);
68556 +
68557 + if (retmode & GR_NOPTRACE) {
68558 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68559 + return 1;
68560 + }
68561 +
68562 + if (retmode & GR_PTRACERD) {
68563 + switch (request) {
68564 + case PTRACE_SEIZE:
68565 + case PTRACE_POKETEXT:
68566 + case PTRACE_POKEDATA:
68567 + case PTRACE_POKEUSR:
68568 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68569 + case PTRACE_SETREGS:
68570 + case PTRACE_SETFPREGS:
68571 +#endif
68572 +#ifdef CONFIG_X86
68573 + case PTRACE_SETFPXREGS:
68574 +#endif
68575 +#ifdef CONFIG_ALTIVEC
68576 + case PTRACE_SETVRREGS:
68577 +#endif
68578 + return 1;
68579 + default:
68580 + return 0;
68581 + }
68582 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
68583 + !(current->role->roletype & GR_ROLE_GOD) &&
68584 + (current->acl != task->acl)) {
68585 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68586 + return 1;
68587 + }
68588 +
68589 + return 0;
68590 +}
68591 +
68592 +static int is_writable_mmap(const struct file *filp)
68593 +{
68594 + struct task_struct *task = current;
68595 + struct acl_object_label *obj, *obj2;
68596 +
68597 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
68598 + !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))) {
68599 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68600 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
68601 + task->role->root_label);
68602 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
68603 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
68604 + return 1;
68605 + }
68606 + }
68607 + return 0;
68608 +}
68609 +
68610 +int
68611 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
68612 +{
68613 + __u32 mode;
68614 +
68615 + if (unlikely(!file || !(prot & PROT_EXEC)))
68616 + return 1;
68617 +
68618 + if (is_writable_mmap(file))
68619 + return 0;
68620 +
68621 + mode =
68622 + gr_search_file(file->f_path.dentry,
68623 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68624 + file->f_path.mnt);
68625 +
68626 + if (!gr_tpe_allow(file))
68627 + return 0;
68628 +
68629 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68630 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68631 + return 0;
68632 + } else if (unlikely(!(mode & GR_EXEC))) {
68633 + return 0;
68634 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68635 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68636 + return 1;
68637 + }
68638 +
68639 + return 1;
68640 +}
68641 +
68642 +int
68643 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68644 +{
68645 + __u32 mode;
68646 +
68647 + if (unlikely(!file || !(prot & PROT_EXEC)))
68648 + return 1;
68649 +
68650 + if (is_writable_mmap(file))
68651 + return 0;
68652 +
68653 + mode =
68654 + gr_search_file(file->f_path.dentry,
68655 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68656 + file->f_path.mnt);
68657 +
68658 + if (!gr_tpe_allow(file))
68659 + return 0;
68660 +
68661 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68662 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68663 + return 0;
68664 + } else if (unlikely(!(mode & GR_EXEC))) {
68665 + return 0;
68666 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68667 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68668 + return 1;
68669 + }
68670 +
68671 + return 1;
68672 +}
68673 +
68674 +void
68675 +gr_acl_handle_psacct(struct task_struct *task, const long code)
68676 +{
68677 + unsigned long runtime, cputime;
68678 + cputime_t utime, stime;
68679 + unsigned int wday, cday;
68680 + __u8 whr, chr;
68681 + __u8 wmin, cmin;
68682 + __u8 wsec, csec;
68683 + struct timespec timeval;
68684 +
68685 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
68686 + !(task->acl->mode & GR_PROCACCT)))
68687 + return;
68688 +
68689 + do_posix_clock_monotonic_gettime(&timeval);
68690 + runtime = timeval.tv_sec - task->start_time.tv_sec;
68691 + wday = runtime / (60 * 60 * 24);
68692 + runtime -= wday * (60 * 60 * 24);
68693 + whr = runtime / (60 * 60);
68694 + runtime -= whr * (60 * 60);
68695 + wmin = runtime / 60;
68696 + runtime -= wmin * 60;
68697 + wsec = runtime;
68698 +
68699 + task_cputime(task, &utime, &stime);
68700 + cputime = cputime_to_secs(utime + stime);
68701 + cday = cputime / (60 * 60 * 24);
68702 + cputime -= cday * (60 * 60 * 24);
68703 + chr = cputime / (60 * 60);
68704 + cputime -= chr * (60 * 60);
68705 + cmin = cputime / 60;
68706 + cputime -= cmin * 60;
68707 + csec = cputime;
68708 +
68709 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
68710 +
68711 + return;
68712 +}
68713 +
68714 +#ifdef CONFIG_TASKSTATS
68715 +int gr_is_taskstats_denied(int pid)
68716 +{
68717 + struct task_struct *task;
68718 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68719 + const struct cred *cred;
68720 +#endif
68721 + int ret = 0;
68722 +
68723 + /* restrict taskstats viewing to un-chrooted root users
68724 + who have the 'view' subject flag if the RBAC system is enabled
68725 + */
68726 +
68727 + rcu_read_lock();
68728 + read_lock(&tasklist_lock);
68729 + task = find_task_by_vpid(pid);
68730 + if (task) {
68731 +#ifdef CONFIG_GRKERNSEC_CHROOT
68732 + if (proc_is_chrooted(task))
68733 + ret = -EACCES;
68734 +#endif
68735 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68736 + cred = __task_cred(task);
68737 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68738 + if (gr_is_global_nonroot(cred->uid))
68739 + ret = -EACCES;
68740 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68741 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
68742 + ret = -EACCES;
68743 +#endif
68744 +#endif
68745 + if (gr_status & GR_READY) {
68746 + if (!(task->acl->mode & GR_VIEW))
68747 + ret = -EACCES;
68748 + }
68749 + } else
68750 + ret = -ENOENT;
68751 +
68752 + read_unlock(&tasklist_lock);
68753 + rcu_read_unlock();
68754 +
68755 + return ret;
68756 +}
68757 +#endif
68758 +
68759 +/* AUXV entries are filled via a descendant of search_binary_handler
68760 + after we've already applied the subject for the target
68761 +*/
68762 +int gr_acl_enable_at_secure(void)
68763 +{
68764 + if (unlikely(!(gr_status & GR_READY)))
68765 + return 0;
68766 +
68767 + if (current->acl->mode & GR_ATSECURE)
68768 + return 1;
68769 +
68770 + return 0;
68771 +}
68772 +
68773 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
68774 +{
68775 + struct task_struct *task = current;
68776 + struct dentry *dentry = file->f_path.dentry;
68777 + struct vfsmount *mnt = file->f_path.mnt;
68778 + struct acl_object_label *obj, *tmp;
68779 + struct acl_subject_label *subj;
68780 + unsigned int bufsize;
68781 + int is_not_root;
68782 + char *path;
68783 + dev_t dev = __get_dev(dentry);
68784 +
68785 + if (unlikely(!(gr_status & GR_READY)))
68786 + return 1;
68787 +
68788 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68789 + return 1;
68790 +
68791 + /* ignore Eric Biederman */
68792 + if (IS_PRIVATE(dentry->d_inode))
68793 + return 1;
68794 +
68795 + subj = task->acl;
68796 + read_lock(&gr_inode_lock);
68797 + do {
68798 + obj = lookup_acl_obj_label(ino, dev, subj);
68799 + if (obj != NULL) {
68800 + read_unlock(&gr_inode_lock);
68801 + return (obj->mode & GR_FIND) ? 1 : 0;
68802 + }
68803 + } while ((subj = subj->parent_subject));
68804 + read_unlock(&gr_inode_lock);
68805 +
68806 + /* this is purely an optimization since we're looking for an object
68807 + for the directory we're doing a readdir on
68808 + if it's possible for any globbed object to match the entry we're
68809 + filling into the directory, then the object we find here will be
68810 + an anchor point with attached globbed objects
68811 + */
68812 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
68813 + if (obj->globbed == NULL)
68814 + return (obj->mode & GR_FIND) ? 1 : 0;
68815 +
68816 + is_not_root = ((obj->filename[0] == '/') &&
68817 + (obj->filename[1] == '\0')) ? 0 : 1;
68818 + bufsize = PAGE_SIZE - namelen - is_not_root;
68819 +
68820 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
68821 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
68822 + return 1;
68823 +
68824 + preempt_disable();
68825 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
68826 + bufsize);
68827 +
68828 + bufsize = strlen(path);
68829 +
68830 + /* if base is "/", don't append an additional slash */
68831 + if (is_not_root)
68832 + *(path + bufsize) = '/';
68833 + memcpy(path + bufsize + is_not_root, name, namelen);
68834 + *(path + bufsize + namelen + is_not_root) = '\0';
68835 +
68836 + tmp = obj->globbed;
68837 + while (tmp) {
68838 + if (!glob_match(tmp->filename, path)) {
68839 + preempt_enable();
68840 + return (tmp->mode & GR_FIND) ? 1 : 0;
68841 + }
68842 + tmp = tmp->next;
68843 + }
68844 + preempt_enable();
68845 + return (obj->mode & GR_FIND) ? 1 : 0;
68846 +}
68847 +
68848 +void gr_put_exec_file(struct task_struct *task)
68849 +{
68850 + struct file *filp;
68851 +
68852 + write_lock(&grsec_exec_file_lock);
68853 + filp = task->exec_file;
68854 + task->exec_file = NULL;
68855 + write_unlock(&grsec_exec_file_lock);
68856 +
68857 + if (filp)
68858 + fput(filp);
68859 +
68860 + return;
68861 +}
68862 +
68863 +
68864 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
68865 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
68866 +#endif
68867 +#ifdef CONFIG_SECURITY
68868 +EXPORT_SYMBOL_GPL(gr_check_user_change);
68869 +EXPORT_SYMBOL_GPL(gr_check_group_change);
68870 +#endif
68871 +
68872 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
68873 new file mode 100644
68874 index 0000000..18ffbbd
68875 --- /dev/null
68876 +++ b/grsecurity/gracl_alloc.c
68877 @@ -0,0 +1,105 @@
68878 +#include <linux/kernel.h>
68879 +#include <linux/mm.h>
68880 +#include <linux/slab.h>
68881 +#include <linux/vmalloc.h>
68882 +#include <linux/gracl.h>
68883 +#include <linux/grsecurity.h>
68884 +
68885 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
68886 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
68887 +
68888 +static __inline__ int
68889 +alloc_pop(void)
68890 +{
68891 + if (current_alloc_state->alloc_stack_next == 1)
68892 + return 0;
68893 +
68894 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
68895 +
68896 + current_alloc_state->alloc_stack_next--;
68897 +
68898 + return 1;
68899 +}
68900 +
68901 +static __inline__ int
68902 +alloc_push(void *buf)
68903 +{
68904 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
68905 + return 1;
68906 +
68907 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
68908 +
68909 + current_alloc_state->alloc_stack_next++;
68910 +
68911 + return 0;
68912 +}
68913 +
68914 +void *
68915 +acl_alloc(unsigned long len)
68916 +{
68917 + void *ret = NULL;
68918 +
68919 + if (!len || len > PAGE_SIZE)
68920 + goto out;
68921 +
68922 + ret = kmalloc(len, GFP_KERNEL);
68923 +
68924 + if (ret) {
68925 + if (alloc_push(ret)) {
68926 + kfree(ret);
68927 + ret = NULL;
68928 + }
68929 + }
68930 +
68931 +out:
68932 + return ret;
68933 +}
68934 +
68935 +void *
68936 +acl_alloc_num(unsigned long num, unsigned long len)
68937 +{
68938 + if (!len || (num > (PAGE_SIZE / len)))
68939 + return NULL;
68940 +
68941 + return acl_alloc(num * len);
68942 +}
68943 +
68944 +void
68945 +acl_free_all(void)
68946 +{
68947 + if (!current_alloc_state->alloc_stack)
68948 + return;
68949 +
68950 + while (alloc_pop()) ;
68951 +
68952 + if (current_alloc_state->alloc_stack) {
68953 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
68954 + kfree(current_alloc_state->alloc_stack);
68955 + else
68956 + vfree(current_alloc_state->alloc_stack);
68957 + }
68958 +
68959 + current_alloc_state->alloc_stack = NULL;
68960 + current_alloc_state->alloc_stack_size = 1;
68961 + current_alloc_state->alloc_stack_next = 1;
68962 +
68963 + return;
68964 +}
68965 +
68966 +int
68967 +acl_alloc_stack_init(unsigned long size)
68968 +{
68969 + if ((size * sizeof (void *)) <= PAGE_SIZE)
68970 + current_alloc_state->alloc_stack =
68971 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
68972 + else
68973 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
68974 +
68975 + current_alloc_state->alloc_stack_size = size;
68976 + current_alloc_state->alloc_stack_next = 1;
68977 +
68978 + if (!current_alloc_state->alloc_stack)
68979 + return 0;
68980 + else
68981 + return 1;
68982 +}
68983 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
68984 new file mode 100644
68985 index 0000000..bdd51ea
68986 --- /dev/null
68987 +++ b/grsecurity/gracl_cap.c
68988 @@ -0,0 +1,110 @@
68989 +#include <linux/kernel.h>
68990 +#include <linux/module.h>
68991 +#include <linux/sched.h>
68992 +#include <linux/gracl.h>
68993 +#include <linux/grsecurity.h>
68994 +#include <linux/grinternal.h>
68995 +
68996 +extern const char *captab_log[];
68997 +extern int captab_log_entries;
68998 +
68999 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69000 +{
69001 + struct acl_subject_label *curracl;
69002 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69003 + kernel_cap_t cap_audit = __cap_empty_set;
69004 +
69005 + if (!gr_acl_is_enabled())
69006 + return 1;
69007 +
69008 + curracl = task->acl;
69009 +
69010 + cap_drop = curracl->cap_lower;
69011 + cap_mask = curracl->cap_mask;
69012 + cap_audit = curracl->cap_invert_audit;
69013 +
69014 + while ((curracl = curracl->parent_subject)) {
69015 + /* if the cap isn't specified in the current computed mask but is specified in the
69016 + current level subject, and is lowered in the current level subject, then add
69017 + it to the set of dropped capabilities
69018 + otherwise, add the current level subject's mask to the current computed mask
69019 + */
69020 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69021 + cap_raise(cap_mask, cap);
69022 + if (cap_raised(curracl->cap_lower, cap))
69023 + cap_raise(cap_drop, cap);
69024 + if (cap_raised(curracl->cap_invert_audit, cap))
69025 + cap_raise(cap_audit, cap);
69026 + }
69027 + }
69028 +
69029 + if (!cap_raised(cap_drop, cap)) {
69030 + if (cap_raised(cap_audit, cap))
69031 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69032 + return 1;
69033 + }
69034 +
69035 + curracl = task->acl;
69036 +
69037 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69038 + && cap_raised(cred->cap_effective, cap)) {
69039 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69040 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
69041 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
69042 + gr_to_filename(task->exec_file->f_path.dentry,
69043 + task->exec_file->f_path.mnt) : curracl->filename,
69044 + curracl->filename, 0UL,
69045 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69046 + return 1;
69047 + }
69048 +
69049 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69050 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69051 +
69052 + return 0;
69053 +}
69054 +
69055 +int
69056 +gr_acl_is_capable(const int cap)
69057 +{
69058 + return gr_task_acl_is_capable(current, current_cred(), cap);
69059 +}
69060 +
69061 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69062 +{
69063 + struct acl_subject_label *curracl;
69064 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69065 +
69066 + if (!gr_acl_is_enabled())
69067 + return 1;
69068 +
69069 + curracl = task->acl;
69070 +
69071 + cap_drop = curracl->cap_lower;
69072 + cap_mask = curracl->cap_mask;
69073 +
69074 + while ((curracl = curracl->parent_subject)) {
69075 + /* if the cap isn't specified in the current computed mask but is specified in the
69076 + current level subject, and is lowered in the current level subject, then add
69077 + it to the set of dropped capabilities
69078 + otherwise, add the current level subject's mask to the current computed mask
69079 + */
69080 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69081 + cap_raise(cap_mask, cap);
69082 + if (cap_raised(curracl->cap_lower, cap))
69083 + cap_raise(cap_drop, cap);
69084 + }
69085 + }
69086 +
69087 + if (!cap_raised(cap_drop, cap))
69088 + return 1;
69089 +
69090 + return 0;
69091 +}
69092 +
69093 +int
69094 +gr_acl_is_capable_nolog(const int cap)
69095 +{
69096 + return gr_task_acl_is_capable_nolog(current, cap);
69097 +}
69098 +
69099 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69100 new file mode 100644
69101 index 0000000..ca25605
69102 --- /dev/null
69103 +++ b/grsecurity/gracl_compat.c
69104 @@ -0,0 +1,270 @@
69105 +#include <linux/kernel.h>
69106 +#include <linux/gracl.h>
69107 +#include <linux/compat.h>
69108 +#include <linux/gracl_compat.h>
69109 +
69110 +#include <asm/uaccess.h>
69111 +
69112 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69113 +{
69114 + struct gr_arg_wrapper_compat uwrapcompat;
69115 +
69116 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69117 + return -EFAULT;
69118 +
69119 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69120 + (uwrapcompat.version != 0x2901)) ||
69121 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69122 + return -EINVAL;
69123 +
69124 + uwrap->arg = compat_ptr(uwrapcompat.arg);
69125 + uwrap->version = uwrapcompat.version;
69126 + uwrap->size = sizeof(struct gr_arg);
69127 +
69128 + return 0;
69129 +}
69130 +
69131 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69132 +{
69133 + struct gr_arg_compat argcompat;
69134 +
69135 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69136 + return -EFAULT;
69137 +
69138 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69139 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69140 + arg->role_db.num_roles = argcompat.role_db.num_roles;
69141 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69142 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69143 + arg->role_db.num_objects = argcompat.role_db.num_objects;
69144 +
69145 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69146 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69147 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69148 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69149 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69150 + arg->segv_device = argcompat.segv_device;
69151 + arg->segv_inode = argcompat.segv_inode;
69152 + arg->segv_uid = argcompat.segv_uid;
69153 + arg->num_sprole_pws = argcompat.num_sprole_pws;
69154 + arg->mode = argcompat.mode;
69155 +
69156 + return 0;
69157 +}
69158 +
69159 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69160 +{
69161 + struct acl_object_label_compat objcompat;
69162 +
69163 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69164 + return -EFAULT;
69165 +
69166 + obj->filename = compat_ptr(objcompat.filename);
69167 + obj->inode = objcompat.inode;
69168 + obj->device = objcompat.device;
69169 + obj->mode = objcompat.mode;
69170 +
69171 + obj->nested = compat_ptr(objcompat.nested);
69172 + obj->globbed = compat_ptr(objcompat.globbed);
69173 +
69174 + obj->prev = compat_ptr(objcompat.prev);
69175 + obj->next = compat_ptr(objcompat.next);
69176 +
69177 + return 0;
69178 +}
69179 +
69180 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69181 +{
69182 + unsigned int i;
69183 + struct acl_subject_label_compat subjcompat;
69184 +
69185 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69186 + return -EFAULT;
69187 +
69188 + subj->filename = compat_ptr(subjcompat.filename);
69189 + subj->inode = subjcompat.inode;
69190 + subj->device = subjcompat.device;
69191 + subj->mode = subjcompat.mode;
69192 + subj->cap_mask = subjcompat.cap_mask;
69193 + subj->cap_lower = subjcompat.cap_lower;
69194 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
69195 +
69196 + for (i = 0; i < GR_NLIMITS; i++) {
69197 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69198 + subj->res[i].rlim_cur = RLIM_INFINITY;
69199 + else
69200 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69201 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69202 + subj->res[i].rlim_max = RLIM_INFINITY;
69203 + else
69204 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69205 + }
69206 + subj->resmask = subjcompat.resmask;
69207 +
69208 + subj->user_trans_type = subjcompat.user_trans_type;
69209 + subj->group_trans_type = subjcompat.group_trans_type;
69210 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69211 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69212 + subj->user_trans_num = subjcompat.user_trans_num;
69213 + subj->group_trans_num = subjcompat.group_trans_num;
69214 +
69215 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69216 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69217 + subj->ip_type = subjcompat.ip_type;
69218 + subj->ips = compat_ptr(subjcompat.ips);
69219 + subj->ip_num = subjcompat.ip_num;
69220 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
69221 +
69222 + subj->crashes = subjcompat.crashes;
69223 + subj->expires = subjcompat.expires;
69224 +
69225 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69226 + subj->hash = compat_ptr(subjcompat.hash);
69227 + subj->prev = compat_ptr(subjcompat.prev);
69228 + subj->next = compat_ptr(subjcompat.next);
69229 +
69230 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69231 + subj->obj_hash_size = subjcompat.obj_hash_size;
69232 + subj->pax_flags = subjcompat.pax_flags;
69233 +
69234 + return 0;
69235 +}
69236 +
69237 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69238 +{
69239 + struct acl_role_label_compat rolecompat;
69240 +
69241 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69242 + return -EFAULT;
69243 +
69244 + role->rolename = compat_ptr(rolecompat.rolename);
69245 + role->uidgid = rolecompat.uidgid;
69246 + role->roletype = rolecompat.roletype;
69247 +
69248 + role->auth_attempts = rolecompat.auth_attempts;
69249 + role->expires = rolecompat.expires;
69250 +
69251 + role->root_label = compat_ptr(rolecompat.root_label);
69252 + role->hash = compat_ptr(rolecompat.hash);
69253 +
69254 + role->prev = compat_ptr(rolecompat.prev);
69255 + role->next = compat_ptr(rolecompat.next);
69256 +
69257 + role->transitions = compat_ptr(rolecompat.transitions);
69258 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69259 + role->domain_children = compat_ptr(rolecompat.domain_children);
69260 + role->domain_child_num = rolecompat.domain_child_num;
69261 +
69262 + role->umask = rolecompat.umask;
69263 +
69264 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
69265 + role->subj_hash_size = rolecompat.subj_hash_size;
69266 +
69267 + return 0;
69268 +}
69269 +
69270 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69271 +{
69272 + struct role_allowed_ip_compat roleip_compat;
69273 +
69274 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69275 + return -EFAULT;
69276 +
69277 + roleip->addr = roleip_compat.addr;
69278 + roleip->netmask = roleip_compat.netmask;
69279 +
69280 + roleip->prev = compat_ptr(roleip_compat.prev);
69281 + roleip->next = compat_ptr(roleip_compat.next);
69282 +
69283 + return 0;
69284 +}
69285 +
69286 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69287 +{
69288 + struct role_transition_compat trans_compat;
69289 +
69290 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69291 + return -EFAULT;
69292 +
69293 + trans->rolename = compat_ptr(trans_compat.rolename);
69294 +
69295 + trans->prev = compat_ptr(trans_compat.prev);
69296 + trans->next = compat_ptr(trans_compat.next);
69297 +
69298 + return 0;
69299 +
69300 +}
69301 +
69302 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69303 +{
69304 + struct gr_hash_struct_compat hash_compat;
69305 +
69306 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69307 + return -EFAULT;
69308 +
69309 + hash->table = compat_ptr(hash_compat.table);
69310 + hash->nametable = compat_ptr(hash_compat.nametable);
69311 + hash->first = compat_ptr(hash_compat.first);
69312 +
69313 + hash->table_size = hash_compat.table_size;
69314 + hash->used_size = hash_compat.used_size;
69315 +
69316 + hash->type = hash_compat.type;
69317 +
69318 + return 0;
69319 +}
69320 +
69321 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69322 +{
69323 + compat_uptr_t ptrcompat;
69324 +
69325 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69326 + return -EFAULT;
69327 +
69328 + *(void **)ptr = compat_ptr(ptrcompat);
69329 +
69330 + return 0;
69331 +}
69332 +
69333 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69334 +{
69335 + struct acl_ip_label_compat ip_compat;
69336 +
69337 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69338 + return -EFAULT;
69339 +
69340 + ip->iface = compat_ptr(ip_compat.iface);
69341 + ip->addr = ip_compat.addr;
69342 + ip->netmask = ip_compat.netmask;
69343 + ip->low = ip_compat.low;
69344 + ip->high = ip_compat.high;
69345 + ip->mode = ip_compat.mode;
69346 + ip->type = ip_compat.type;
69347 +
69348 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69349 +
69350 + ip->prev = compat_ptr(ip_compat.prev);
69351 + ip->next = compat_ptr(ip_compat.next);
69352 +
69353 + return 0;
69354 +}
69355 +
69356 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69357 +{
69358 + struct sprole_pw_compat pw_compat;
69359 +
69360 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69361 + return -EFAULT;
69362 +
69363 + pw->rolename = compat_ptr(pw_compat.rolename);
69364 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69365 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69366 +
69367 + return 0;
69368 +}
69369 +
69370 +size_t get_gr_arg_wrapper_size_compat(void)
69371 +{
69372 + return sizeof(struct gr_arg_wrapper_compat);
69373 +}
69374 +
69375 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69376 new file mode 100644
69377 index 0000000..a89b1f4
69378 --- /dev/null
69379 +++ b/grsecurity/gracl_fs.c
69380 @@ -0,0 +1,437 @@
69381 +#include <linux/kernel.h>
69382 +#include <linux/sched.h>
69383 +#include <linux/types.h>
69384 +#include <linux/fs.h>
69385 +#include <linux/file.h>
69386 +#include <linux/stat.h>
69387 +#include <linux/grsecurity.h>
69388 +#include <linux/grinternal.h>
69389 +#include <linux/gracl.h>
69390 +
69391 +umode_t
69392 +gr_acl_umask(void)
69393 +{
69394 + if (unlikely(!gr_acl_is_enabled()))
69395 + return 0;
69396 +
69397 + return current->role->umask;
69398 +}
69399 +
69400 +__u32
69401 +gr_acl_handle_hidden_file(const struct dentry * dentry,
69402 + const struct vfsmount * mnt)
69403 +{
69404 + __u32 mode;
69405 +
69406 + if (unlikely(d_is_negative(dentry)))
69407 + return GR_FIND;
69408 +
69409 + mode =
69410 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69411 +
69412 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69413 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69414 + return mode;
69415 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69416 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69417 + return 0;
69418 + } else if (unlikely(!(mode & GR_FIND)))
69419 + return 0;
69420 +
69421 + return GR_FIND;
69422 +}
69423 +
69424 +__u32
69425 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69426 + int acc_mode)
69427 +{
69428 + __u32 reqmode = GR_FIND;
69429 + __u32 mode;
69430 +
69431 + if (unlikely(d_is_negative(dentry)))
69432 + return reqmode;
69433 +
69434 + if (acc_mode & MAY_APPEND)
69435 + reqmode |= GR_APPEND;
69436 + else if (acc_mode & MAY_WRITE)
69437 + reqmode |= GR_WRITE;
69438 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69439 + reqmode |= GR_READ;
69440 +
69441 + mode =
69442 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69443 + mnt);
69444 +
69445 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69446 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69447 + reqmode & GR_READ ? " reading" : "",
69448 + reqmode & GR_WRITE ? " writing" : reqmode &
69449 + GR_APPEND ? " appending" : "");
69450 + return reqmode;
69451 + } else
69452 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69453 + {
69454 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69455 + reqmode & GR_READ ? " reading" : "",
69456 + reqmode & GR_WRITE ? " writing" : reqmode &
69457 + GR_APPEND ? " appending" : "");
69458 + return 0;
69459 + } else if (unlikely((mode & reqmode) != reqmode))
69460 + return 0;
69461 +
69462 + return reqmode;
69463 +}
69464 +
69465 +__u32
69466 +gr_acl_handle_creat(const struct dentry * dentry,
69467 + const struct dentry * p_dentry,
69468 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69469 + const int imode)
69470 +{
69471 + __u32 reqmode = GR_WRITE | GR_CREATE;
69472 + __u32 mode;
69473 +
69474 + if (acc_mode & MAY_APPEND)
69475 + reqmode |= GR_APPEND;
69476 + // if a directory was required or the directory already exists, then
69477 + // don't count this open as a read
69478 + if ((acc_mode & MAY_READ) &&
69479 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69480 + reqmode |= GR_READ;
69481 + if ((open_flags & O_CREAT) &&
69482 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69483 + reqmode |= GR_SETID;
69484 +
69485 + mode =
69486 + gr_check_create(dentry, p_dentry, p_mnt,
69487 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69488 +
69489 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69490 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69491 + reqmode & GR_READ ? " reading" : "",
69492 + reqmode & GR_WRITE ? " writing" : reqmode &
69493 + GR_APPEND ? " appending" : "");
69494 + return reqmode;
69495 + } else
69496 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69497 + {
69498 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69499 + reqmode & GR_READ ? " reading" : "",
69500 + reqmode & GR_WRITE ? " writing" : reqmode &
69501 + GR_APPEND ? " appending" : "");
69502 + return 0;
69503 + } else if (unlikely((mode & reqmode) != reqmode))
69504 + return 0;
69505 +
69506 + return reqmode;
69507 +}
69508 +
69509 +__u32
69510 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69511 + const int fmode)
69512 +{
69513 + __u32 mode, reqmode = GR_FIND;
69514 +
69515 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69516 + reqmode |= GR_EXEC;
69517 + if (fmode & S_IWOTH)
69518 + reqmode |= GR_WRITE;
69519 + if (fmode & S_IROTH)
69520 + reqmode |= GR_READ;
69521 +
69522 + mode =
69523 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69524 + mnt);
69525 +
69526 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69527 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69528 + reqmode & GR_READ ? " reading" : "",
69529 + reqmode & GR_WRITE ? " writing" : "",
69530 + reqmode & GR_EXEC ? " executing" : "");
69531 + return reqmode;
69532 + } else
69533 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69534 + {
69535 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69536 + reqmode & GR_READ ? " reading" : "",
69537 + reqmode & GR_WRITE ? " writing" : "",
69538 + reqmode & GR_EXEC ? " executing" : "");
69539 + return 0;
69540 + } else if (unlikely((mode & reqmode) != reqmode))
69541 + return 0;
69542 +
69543 + return reqmode;
69544 +}
69545 +
69546 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69547 +{
69548 + __u32 mode;
69549 +
69550 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69551 +
69552 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69553 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69554 + return mode;
69555 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69556 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69557 + return 0;
69558 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69559 + return 0;
69560 +
69561 + return (reqmode);
69562 +}
69563 +
69564 +__u32
69565 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69566 +{
69567 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69568 +}
69569 +
69570 +__u32
69571 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69572 +{
69573 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69574 +}
69575 +
69576 +__u32
69577 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69578 +{
69579 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69580 +}
69581 +
69582 +__u32
69583 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69584 +{
69585 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69586 +}
69587 +
69588 +__u32
69589 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
69590 + umode_t *modeptr)
69591 +{
69592 + umode_t mode;
69593 +
69594 + *modeptr &= ~gr_acl_umask();
69595 + mode = *modeptr;
69596 +
69597 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
69598 + return 1;
69599 +
69600 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
69601 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
69602 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
69603 + GR_CHMOD_ACL_MSG);
69604 + } else {
69605 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
69606 + }
69607 +}
69608 +
69609 +__u32
69610 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
69611 +{
69612 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
69613 +}
69614 +
69615 +__u32
69616 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
69617 +{
69618 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
69619 +}
69620 +
69621 +__u32
69622 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
69623 +{
69624 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
69625 +}
69626 +
69627 +__u32
69628 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
69629 +{
69630 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
69631 +}
69632 +
69633 +__u32
69634 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
69635 +{
69636 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
69637 + GR_UNIXCONNECT_ACL_MSG);
69638 +}
69639 +
69640 +/* hardlinks require at minimum create and link permission,
69641 + any additional privilege required is based on the
69642 + privilege of the file being linked to
69643 +*/
69644 +__u32
69645 +gr_acl_handle_link(const struct dentry * new_dentry,
69646 + const struct dentry * parent_dentry,
69647 + const struct vfsmount * parent_mnt,
69648 + const struct dentry * old_dentry,
69649 + const struct vfsmount * old_mnt, const struct filename *to)
69650 +{
69651 + __u32 mode;
69652 + __u32 needmode = GR_CREATE | GR_LINK;
69653 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
69654 +
69655 + mode =
69656 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
69657 + old_mnt);
69658 +
69659 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
69660 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69661 + return mode;
69662 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69663 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69664 + return 0;
69665 + } else if (unlikely((mode & needmode) != needmode))
69666 + return 0;
69667 +
69668 + return 1;
69669 +}
69670 +
69671 +__u32
69672 +gr_acl_handle_symlink(const struct dentry * new_dentry,
69673 + const struct dentry * parent_dentry,
69674 + const struct vfsmount * parent_mnt, const struct filename *from)
69675 +{
69676 + __u32 needmode = GR_WRITE | GR_CREATE;
69677 + __u32 mode;
69678 +
69679 + mode =
69680 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
69681 + GR_CREATE | GR_AUDIT_CREATE |
69682 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
69683 +
69684 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
69685 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69686 + return mode;
69687 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69688 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69689 + return 0;
69690 + } else if (unlikely((mode & needmode) != needmode))
69691 + return 0;
69692 +
69693 + return (GR_WRITE | GR_CREATE);
69694 +}
69695 +
69696 +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)
69697 +{
69698 + __u32 mode;
69699 +
69700 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69701 +
69702 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69703 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
69704 + return mode;
69705 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69706 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
69707 + return 0;
69708 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69709 + return 0;
69710 +
69711 + return (reqmode);
69712 +}
69713 +
69714 +__u32
69715 +gr_acl_handle_mknod(const struct dentry * new_dentry,
69716 + const struct dentry * parent_dentry,
69717 + const struct vfsmount * parent_mnt,
69718 + const int mode)
69719 +{
69720 + __u32 reqmode = GR_WRITE | GR_CREATE;
69721 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69722 + reqmode |= GR_SETID;
69723 +
69724 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69725 + reqmode, GR_MKNOD_ACL_MSG);
69726 +}
69727 +
69728 +__u32
69729 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
69730 + const struct dentry *parent_dentry,
69731 + const struct vfsmount *parent_mnt)
69732 +{
69733 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69734 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
69735 +}
69736 +
69737 +#define RENAME_CHECK_SUCCESS(old, new) \
69738 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
69739 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
69740 +
69741 +int
69742 +gr_acl_handle_rename(struct dentry *new_dentry,
69743 + struct dentry *parent_dentry,
69744 + const struct vfsmount *parent_mnt,
69745 + struct dentry *old_dentry,
69746 + struct inode *old_parent_inode,
69747 + struct vfsmount *old_mnt, const struct filename *newname)
69748 +{
69749 + __u32 comp1, comp2;
69750 + int error = 0;
69751 +
69752 + if (unlikely(!gr_acl_is_enabled()))
69753 + return 0;
69754 +
69755 + if (d_is_negative(new_dentry)) {
69756 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
69757 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
69758 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
69759 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
69760 + GR_DELETE | GR_AUDIT_DELETE |
69761 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69762 + GR_SUPPRESS, old_mnt);
69763 + } else {
69764 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
69765 + GR_CREATE | GR_DELETE |
69766 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
69767 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69768 + GR_SUPPRESS, parent_mnt);
69769 + comp2 =
69770 + gr_search_file(old_dentry,
69771 + GR_READ | GR_WRITE | GR_AUDIT_READ |
69772 + GR_DELETE | GR_AUDIT_DELETE |
69773 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
69774 + }
69775 +
69776 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
69777 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69778 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69779 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69780 + && !(comp2 & GR_SUPPRESS)) {
69781 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69782 + error = -EACCES;
69783 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69784 + error = -EACCES;
69785 +
69786 + return error;
69787 +}
69788 +
69789 +void
69790 +gr_acl_handle_exit(void)
69791 +{
69792 + u16 id;
69793 + char *rolename;
69794 +
69795 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69796 + !(current->role->roletype & GR_ROLE_PERSIST))) {
69797 + id = current->acl_role_id;
69798 + rolename = current->role->rolename;
69799 + gr_set_acls(1);
69800 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
69801 + }
69802 +
69803 + gr_put_exec_file(current);
69804 + return;
69805 +}
69806 +
69807 +int
69808 +gr_acl_handle_procpidmem(const struct task_struct *task)
69809 +{
69810 + if (unlikely(!gr_acl_is_enabled()))
69811 + return 0;
69812 +
69813 + if (task != current && task->acl->mode & GR_PROTPROCFD)
69814 + return -EACCES;
69815 +
69816 + return 0;
69817 +}
69818 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
69819 new file mode 100644
69820 index 0000000..f056b81
69821 --- /dev/null
69822 +++ b/grsecurity/gracl_ip.c
69823 @@ -0,0 +1,386 @@
69824 +#include <linux/kernel.h>
69825 +#include <asm/uaccess.h>
69826 +#include <asm/errno.h>
69827 +#include <net/sock.h>
69828 +#include <linux/file.h>
69829 +#include <linux/fs.h>
69830 +#include <linux/net.h>
69831 +#include <linux/in.h>
69832 +#include <linux/skbuff.h>
69833 +#include <linux/ip.h>
69834 +#include <linux/udp.h>
69835 +#include <linux/types.h>
69836 +#include <linux/sched.h>
69837 +#include <linux/netdevice.h>
69838 +#include <linux/inetdevice.h>
69839 +#include <linux/gracl.h>
69840 +#include <linux/grsecurity.h>
69841 +#include <linux/grinternal.h>
69842 +
69843 +#define GR_BIND 0x01
69844 +#define GR_CONNECT 0x02
69845 +#define GR_INVERT 0x04
69846 +#define GR_BINDOVERRIDE 0x08
69847 +#define GR_CONNECTOVERRIDE 0x10
69848 +#define GR_SOCK_FAMILY 0x20
69849 +
69850 +static const char * gr_protocols[IPPROTO_MAX] = {
69851 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
69852 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
69853 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
69854 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
69855 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
69856 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
69857 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
69858 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
69859 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
69860 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
69861 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
69862 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
69863 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
69864 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
69865 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
69866 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
69867 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
69868 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
69869 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
69870 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
69871 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
69872 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
69873 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
69874 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
69875 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
69876 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69877 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69878 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69879 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69880 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69881 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
69882 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
69883 + };
69884 +
69885 +static const char * gr_socktypes[SOCK_MAX] = {
69886 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
69887 + "unknown:7", "unknown:8", "unknown:9", "packet"
69888 + };
69889 +
69890 +static const char * gr_sockfamilies[AF_MAX+1] = {
69891 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
69892 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
69893 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
69894 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
69895 + };
69896 +
69897 +const char *
69898 +gr_proto_to_name(unsigned char proto)
69899 +{
69900 + return gr_protocols[proto];
69901 +}
69902 +
69903 +const char *
69904 +gr_socktype_to_name(unsigned char type)
69905 +{
69906 + return gr_socktypes[type];
69907 +}
69908 +
69909 +const char *
69910 +gr_sockfamily_to_name(unsigned char family)
69911 +{
69912 + return gr_sockfamilies[family];
69913 +}
69914 +
69915 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
69916 +
69917 +int
69918 +gr_search_socket(const int domain, const int type, const int protocol)
69919 +{
69920 + struct acl_subject_label *curr;
69921 + const struct cred *cred = current_cred();
69922 +
69923 + if (unlikely(!gr_acl_is_enabled()))
69924 + goto exit;
69925 +
69926 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
69927 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
69928 + goto exit; // let the kernel handle it
69929 +
69930 + curr = current->acl;
69931 +
69932 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
69933 + /* the family is allowed, if this is PF_INET allow it only if
69934 + the extra sock type/protocol checks pass */
69935 + if (domain == PF_INET)
69936 + goto inet_check;
69937 + goto exit;
69938 + } else {
69939 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69940 + __u32 fakeip = 0;
69941 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69942 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69943 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69944 + gr_to_filename(current->exec_file->f_path.dentry,
69945 + current->exec_file->f_path.mnt) :
69946 + curr->filename, curr->filename,
69947 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
69948 + &current->signal->saved_ip);
69949 + goto exit;
69950 + }
69951 + goto exit_fail;
69952 + }
69953 +
69954 +inet_check:
69955 + /* the rest of this checking is for IPv4 only */
69956 + if (!curr->ips)
69957 + goto exit;
69958 +
69959 + if ((curr->ip_type & (1U << type)) &&
69960 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
69961 + goto exit;
69962 +
69963 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69964 + /* we don't place acls on raw sockets , and sometimes
69965 + dgram/ip sockets are opened for ioctl and not
69966 + bind/connect, so we'll fake a bind learn log */
69967 + if (type == SOCK_RAW || type == SOCK_PACKET) {
69968 + __u32 fakeip = 0;
69969 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69970 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69971 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69972 + gr_to_filename(current->exec_file->f_path.dentry,
69973 + current->exec_file->f_path.mnt) :
69974 + curr->filename, curr->filename,
69975 + &fakeip, 0, type,
69976 + protocol, GR_CONNECT, &current->signal->saved_ip);
69977 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
69978 + __u32 fakeip = 0;
69979 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69980 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69981 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69982 + gr_to_filename(current->exec_file->f_path.dentry,
69983 + current->exec_file->f_path.mnt) :
69984 + curr->filename, curr->filename,
69985 + &fakeip, 0, type,
69986 + protocol, GR_BIND, &current->signal->saved_ip);
69987 + }
69988 + /* we'll log when they use connect or bind */
69989 + goto exit;
69990 + }
69991 +
69992 +exit_fail:
69993 + if (domain == PF_INET)
69994 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
69995 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
69996 + else if (rcu_access_pointer(net_families[domain]) != NULL)
69997 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
69998 + gr_socktype_to_name(type), protocol);
69999 +
70000 + return 0;
70001 +exit:
70002 + return 1;
70003 +}
70004 +
70005 +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)
70006 +{
70007 + if ((ip->mode & mode) &&
70008 + (ip_port >= ip->low) &&
70009 + (ip_port <= ip->high) &&
70010 + ((ntohl(ip_addr) & our_netmask) ==
70011 + (ntohl(our_addr) & our_netmask))
70012 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70013 + && (ip->type & (1U << type))) {
70014 + if (ip->mode & GR_INVERT)
70015 + return 2; // specifically denied
70016 + else
70017 + return 1; // allowed
70018 + }
70019 +
70020 + return 0; // not specifically allowed, may continue parsing
70021 +}
70022 +
70023 +static int
70024 +gr_search_connectbind(const int full_mode, struct sock *sk,
70025 + struct sockaddr_in *addr, const int type)
70026 +{
70027 + char iface[IFNAMSIZ] = {0};
70028 + struct acl_subject_label *curr;
70029 + struct acl_ip_label *ip;
70030 + struct inet_sock *isk;
70031 + struct net_device *dev;
70032 + struct in_device *idev;
70033 + unsigned long i;
70034 + int ret;
70035 + int mode = full_mode & (GR_BIND | GR_CONNECT);
70036 + __u32 ip_addr = 0;
70037 + __u32 our_addr;
70038 + __u32 our_netmask;
70039 + char *p;
70040 + __u16 ip_port = 0;
70041 + const struct cred *cred = current_cred();
70042 +
70043 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70044 + return 0;
70045 +
70046 + curr = current->acl;
70047 + isk = inet_sk(sk);
70048 +
70049 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70050 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70051 + addr->sin_addr.s_addr = curr->inaddr_any_override;
70052 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70053 + struct sockaddr_in saddr;
70054 + int err;
70055 +
70056 + saddr.sin_family = AF_INET;
70057 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
70058 + saddr.sin_port = isk->inet_sport;
70059 +
70060 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70061 + if (err)
70062 + return err;
70063 +
70064 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70065 + if (err)
70066 + return err;
70067 + }
70068 +
70069 + if (!curr->ips)
70070 + return 0;
70071 +
70072 + ip_addr = addr->sin_addr.s_addr;
70073 + ip_port = ntohs(addr->sin_port);
70074 +
70075 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70076 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70077 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70078 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70079 + gr_to_filename(current->exec_file->f_path.dentry,
70080 + current->exec_file->f_path.mnt) :
70081 + curr->filename, curr->filename,
70082 + &ip_addr, ip_port, type,
70083 + sk->sk_protocol, mode, &current->signal->saved_ip);
70084 + return 0;
70085 + }
70086 +
70087 + for (i = 0; i < curr->ip_num; i++) {
70088 + ip = *(curr->ips + i);
70089 + if (ip->iface != NULL) {
70090 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
70091 + p = strchr(iface, ':');
70092 + if (p != NULL)
70093 + *p = '\0';
70094 + dev = dev_get_by_name(sock_net(sk), iface);
70095 + if (dev == NULL)
70096 + continue;
70097 + idev = in_dev_get(dev);
70098 + if (idev == NULL) {
70099 + dev_put(dev);
70100 + continue;
70101 + }
70102 + rcu_read_lock();
70103 + for_ifa(idev) {
70104 + if (!strcmp(ip->iface, ifa->ifa_label)) {
70105 + our_addr = ifa->ifa_address;
70106 + our_netmask = 0xffffffff;
70107 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70108 + if (ret == 1) {
70109 + rcu_read_unlock();
70110 + in_dev_put(idev);
70111 + dev_put(dev);
70112 + return 0;
70113 + } else if (ret == 2) {
70114 + rcu_read_unlock();
70115 + in_dev_put(idev);
70116 + dev_put(dev);
70117 + goto denied;
70118 + }
70119 + }
70120 + } endfor_ifa(idev);
70121 + rcu_read_unlock();
70122 + in_dev_put(idev);
70123 + dev_put(dev);
70124 + } else {
70125 + our_addr = ip->addr;
70126 + our_netmask = ip->netmask;
70127 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70128 + if (ret == 1)
70129 + return 0;
70130 + else if (ret == 2)
70131 + goto denied;
70132 + }
70133 + }
70134 +
70135 +denied:
70136 + if (mode == GR_BIND)
70137 + 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));
70138 + else if (mode == GR_CONNECT)
70139 + 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));
70140 +
70141 + return -EACCES;
70142 +}
70143 +
70144 +int
70145 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70146 +{
70147 + /* always allow disconnection of dgram sockets with connect */
70148 + if (addr->sin_family == AF_UNSPEC)
70149 + return 0;
70150 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70151 +}
70152 +
70153 +int
70154 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70155 +{
70156 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70157 +}
70158 +
70159 +int gr_search_listen(struct socket *sock)
70160 +{
70161 + struct sock *sk = sock->sk;
70162 + struct sockaddr_in addr;
70163 +
70164 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70165 + addr.sin_port = inet_sk(sk)->inet_sport;
70166 +
70167 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70168 +}
70169 +
70170 +int gr_search_accept(struct socket *sock)
70171 +{
70172 + struct sock *sk = sock->sk;
70173 + struct sockaddr_in addr;
70174 +
70175 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70176 + addr.sin_port = inet_sk(sk)->inet_sport;
70177 +
70178 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70179 +}
70180 +
70181 +int
70182 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70183 +{
70184 + if (addr)
70185 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70186 + else {
70187 + struct sockaddr_in sin;
70188 + const struct inet_sock *inet = inet_sk(sk);
70189 +
70190 + sin.sin_addr.s_addr = inet->inet_daddr;
70191 + sin.sin_port = inet->inet_dport;
70192 +
70193 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70194 + }
70195 +}
70196 +
70197 +int
70198 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70199 +{
70200 + struct sockaddr_in sin;
70201 +
70202 + if (unlikely(skb->len < sizeof (struct udphdr)))
70203 + return 0; // skip this packet
70204 +
70205 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70206 + sin.sin_port = udp_hdr(skb)->source;
70207 +
70208 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70209 +}
70210 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70211 new file mode 100644
70212 index 0000000..25f54ef
70213 --- /dev/null
70214 +++ b/grsecurity/gracl_learn.c
70215 @@ -0,0 +1,207 @@
70216 +#include <linux/kernel.h>
70217 +#include <linux/mm.h>
70218 +#include <linux/sched.h>
70219 +#include <linux/poll.h>
70220 +#include <linux/string.h>
70221 +#include <linux/file.h>
70222 +#include <linux/types.h>
70223 +#include <linux/vmalloc.h>
70224 +#include <linux/grinternal.h>
70225 +
70226 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70227 + size_t count, loff_t *ppos);
70228 +extern int gr_acl_is_enabled(void);
70229 +
70230 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70231 +static int gr_learn_attached;
70232 +
70233 +/* use a 512k buffer */
70234 +#define LEARN_BUFFER_SIZE (512 * 1024)
70235 +
70236 +static DEFINE_SPINLOCK(gr_learn_lock);
70237 +static DEFINE_MUTEX(gr_learn_user_mutex);
70238 +
70239 +/* we need to maintain two buffers, so that the kernel context of grlearn
70240 + uses a semaphore around the userspace copying, and the other kernel contexts
70241 + use a spinlock when copying into the buffer, since they cannot sleep
70242 +*/
70243 +static char *learn_buffer;
70244 +static char *learn_buffer_user;
70245 +static int learn_buffer_len;
70246 +static int learn_buffer_user_len;
70247 +
70248 +static ssize_t
70249 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70250 +{
70251 + DECLARE_WAITQUEUE(wait, current);
70252 + ssize_t retval = 0;
70253 +
70254 + add_wait_queue(&learn_wait, &wait);
70255 + set_current_state(TASK_INTERRUPTIBLE);
70256 + do {
70257 + mutex_lock(&gr_learn_user_mutex);
70258 + spin_lock(&gr_learn_lock);
70259 + if (learn_buffer_len)
70260 + break;
70261 + spin_unlock(&gr_learn_lock);
70262 + mutex_unlock(&gr_learn_user_mutex);
70263 + if (file->f_flags & O_NONBLOCK) {
70264 + retval = -EAGAIN;
70265 + goto out;
70266 + }
70267 + if (signal_pending(current)) {
70268 + retval = -ERESTARTSYS;
70269 + goto out;
70270 + }
70271 +
70272 + schedule();
70273 + } while (1);
70274 +
70275 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70276 + learn_buffer_user_len = learn_buffer_len;
70277 + retval = learn_buffer_len;
70278 + learn_buffer_len = 0;
70279 +
70280 + spin_unlock(&gr_learn_lock);
70281 +
70282 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70283 + retval = -EFAULT;
70284 +
70285 + mutex_unlock(&gr_learn_user_mutex);
70286 +out:
70287 + set_current_state(TASK_RUNNING);
70288 + remove_wait_queue(&learn_wait, &wait);
70289 + return retval;
70290 +}
70291 +
70292 +static unsigned int
70293 +poll_learn(struct file * file, poll_table * wait)
70294 +{
70295 + poll_wait(file, &learn_wait, wait);
70296 +
70297 + if (learn_buffer_len)
70298 + return (POLLIN | POLLRDNORM);
70299 +
70300 + return 0;
70301 +}
70302 +
70303 +void
70304 +gr_clear_learn_entries(void)
70305 +{
70306 + char *tmp;
70307 +
70308 + mutex_lock(&gr_learn_user_mutex);
70309 + spin_lock(&gr_learn_lock);
70310 + tmp = learn_buffer;
70311 + learn_buffer = NULL;
70312 + spin_unlock(&gr_learn_lock);
70313 + if (tmp)
70314 + vfree(tmp);
70315 + if (learn_buffer_user != NULL) {
70316 + vfree(learn_buffer_user);
70317 + learn_buffer_user = NULL;
70318 + }
70319 + learn_buffer_len = 0;
70320 + mutex_unlock(&gr_learn_user_mutex);
70321 +
70322 + return;
70323 +}
70324 +
70325 +void
70326 +gr_add_learn_entry(const char *fmt, ...)
70327 +{
70328 + va_list args;
70329 + unsigned int len;
70330 +
70331 + if (!gr_learn_attached)
70332 + return;
70333 +
70334 + spin_lock(&gr_learn_lock);
70335 +
70336 + /* leave a gap at the end so we know when it's "full" but don't have to
70337 + compute the exact length of the string we're trying to append
70338 + */
70339 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70340 + spin_unlock(&gr_learn_lock);
70341 + wake_up_interruptible(&learn_wait);
70342 + return;
70343 + }
70344 + if (learn_buffer == NULL) {
70345 + spin_unlock(&gr_learn_lock);
70346 + return;
70347 + }
70348 +
70349 + va_start(args, fmt);
70350 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70351 + va_end(args);
70352 +
70353 + learn_buffer_len += len + 1;
70354 +
70355 + spin_unlock(&gr_learn_lock);
70356 + wake_up_interruptible(&learn_wait);
70357 +
70358 + return;
70359 +}
70360 +
70361 +static int
70362 +open_learn(struct inode *inode, struct file *file)
70363 +{
70364 + if (file->f_mode & FMODE_READ && gr_learn_attached)
70365 + return -EBUSY;
70366 + if (file->f_mode & FMODE_READ) {
70367 + int retval = 0;
70368 + mutex_lock(&gr_learn_user_mutex);
70369 + if (learn_buffer == NULL)
70370 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70371 + if (learn_buffer_user == NULL)
70372 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70373 + if (learn_buffer == NULL) {
70374 + retval = -ENOMEM;
70375 + goto out_error;
70376 + }
70377 + if (learn_buffer_user == NULL) {
70378 + retval = -ENOMEM;
70379 + goto out_error;
70380 + }
70381 + learn_buffer_len = 0;
70382 + learn_buffer_user_len = 0;
70383 + gr_learn_attached = 1;
70384 +out_error:
70385 + mutex_unlock(&gr_learn_user_mutex);
70386 + return retval;
70387 + }
70388 + return 0;
70389 +}
70390 +
70391 +static int
70392 +close_learn(struct inode *inode, struct file *file)
70393 +{
70394 + if (file->f_mode & FMODE_READ) {
70395 + char *tmp = NULL;
70396 + mutex_lock(&gr_learn_user_mutex);
70397 + spin_lock(&gr_learn_lock);
70398 + tmp = learn_buffer;
70399 + learn_buffer = NULL;
70400 + spin_unlock(&gr_learn_lock);
70401 + if (tmp)
70402 + vfree(tmp);
70403 + if (learn_buffer_user != NULL) {
70404 + vfree(learn_buffer_user);
70405 + learn_buffer_user = NULL;
70406 + }
70407 + learn_buffer_len = 0;
70408 + learn_buffer_user_len = 0;
70409 + gr_learn_attached = 0;
70410 + mutex_unlock(&gr_learn_user_mutex);
70411 + }
70412 +
70413 + return 0;
70414 +}
70415 +
70416 +const struct file_operations grsec_fops = {
70417 + .read = read_learn,
70418 + .write = write_grsec_handler,
70419 + .open = open_learn,
70420 + .release = close_learn,
70421 + .poll = poll_learn,
70422 +};
70423 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70424 new file mode 100644
70425 index 0000000..361a099
70426 --- /dev/null
70427 +++ b/grsecurity/gracl_policy.c
70428 @@ -0,0 +1,1782 @@
70429 +#include <linux/kernel.h>
70430 +#include <linux/module.h>
70431 +#include <linux/sched.h>
70432 +#include <linux/mm.h>
70433 +#include <linux/file.h>
70434 +#include <linux/fs.h>
70435 +#include <linux/namei.h>
70436 +#include <linux/mount.h>
70437 +#include <linux/tty.h>
70438 +#include <linux/proc_fs.h>
70439 +#include <linux/lglock.h>
70440 +#include <linux/slab.h>
70441 +#include <linux/vmalloc.h>
70442 +#include <linux/types.h>
70443 +#include <linux/sysctl.h>
70444 +#include <linux/netdevice.h>
70445 +#include <linux/ptrace.h>
70446 +#include <linux/gracl.h>
70447 +#include <linux/gralloc.h>
70448 +#include <linux/security.h>
70449 +#include <linux/grinternal.h>
70450 +#include <linux/pid_namespace.h>
70451 +#include <linux/stop_machine.h>
70452 +#include <linux/fdtable.h>
70453 +#include <linux/percpu.h>
70454 +#include <linux/lglock.h>
70455 +#include <linux/hugetlb.h>
70456 +#include <linux/posix-timers.h>
70457 +#include "../fs/mount.h"
70458 +
70459 +#include <asm/uaccess.h>
70460 +#include <asm/errno.h>
70461 +#include <asm/mman.h>
70462 +
70463 +extern struct gr_policy_state *polstate;
70464 +
70465 +#define FOR_EACH_ROLE_START(role) \
70466 + role = polstate->role_list; \
70467 + while (role) {
70468 +
70469 +#define FOR_EACH_ROLE_END(role) \
70470 + role = role->prev; \
70471 + }
70472 +
70473 +struct path gr_real_root;
70474 +
70475 +extern struct gr_alloc_state *current_alloc_state;
70476 +
70477 +u16 acl_sp_role_value;
70478 +
70479 +static DEFINE_MUTEX(gr_dev_mutex);
70480 +
70481 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70482 +extern void gr_clear_learn_entries(void);
70483 +
70484 +static struct gr_arg gr_usermode;
70485 +static unsigned char gr_system_salt[GR_SALT_LEN];
70486 +static unsigned char gr_system_sum[GR_SHA_LEN];
70487 +
70488 +static unsigned int gr_auth_attempts = 0;
70489 +static unsigned long gr_auth_expires = 0UL;
70490 +
70491 +struct acl_object_label *fakefs_obj_rw;
70492 +struct acl_object_label *fakefs_obj_rwx;
70493 +
70494 +extern int gr_init_uidset(void);
70495 +extern void gr_free_uidset(void);
70496 +extern void gr_remove_uid(uid_t uid);
70497 +extern int gr_find_uid(uid_t uid);
70498 +
70499 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70500 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70501 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70502 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70503 +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);
70504 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70505 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70506 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70507 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70508 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70509 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70510 +extern void assign_special_role(const char *rolename);
70511 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70512 +extern int gr_rbac_disable(void *unused);
70513 +extern void gr_enable_rbac_system(void);
70514 +
70515 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70516 +{
70517 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70518 + return -EFAULT;
70519 +
70520 + return 0;
70521 +}
70522 +
70523 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70524 +{
70525 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70526 + return -EFAULT;
70527 +
70528 + return 0;
70529 +}
70530 +
70531 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70532 +{
70533 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70534 + return -EFAULT;
70535 +
70536 + return 0;
70537 +}
70538 +
70539 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70540 +{
70541 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70542 + return -EFAULT;
70543 +
70544 + return 0;
70545 +}
70546 +
70547 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70548 +{
70549 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70550 + return -EFAULT;
70551 +
70552 + return 0;
70553 +}
70554 +
70555 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70556 +{
70557 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70558 + return -EFAULT;
70559 +
70560 + return 0;
70561 +}
70562 +
70563 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70564 +{
70565 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70566 + return -EFAULT;
70567 +
70568 + return 0;
70569 +}
70570 +
70571 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70572 +{
70573 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70574 + return -EFAULT;
70575 +
70576 + return 0;
70577 +}
70578 +
70579 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70580 +{
70581 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70582 + return -EFAULT;
70583 +
70584 + return 0;
70585 +}
70586 +
70587 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
70588 +{
70589 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
70590 + return -EFAULT;
70591 +
70592 + if (((uwrap->version != GRSECURITY_VERSION) &&
70593 + (uwrap->version != 0x2901)) ||
70594 + (uwrap->size != sizeof(struct gr_arg)))
70595 + return -EINVAL;
70596 +
70597 + return 0;
70598 +}
70599 +
70600 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
70601 +{
70602 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
70603 + return -EFAULT;
70604 +
70605 + return 0;
70606 +}
70607 +
70608 +static size_t get_gr_arg_wrapper_size_normal(void)
70609 +{
70610 + return sizeof(struct gr_arg_wrapper);
70611 +}
70612 +
70613 +#ifdef CONFIG_COMPAT
70614 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
70615 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
70616 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
70617 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
70618 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
70619 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
70620 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
70621 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
70622 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
70623 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
70624 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
70625 +extern size_t get_gr_arg_wrapper_size_compat(void);
70626 +
70627 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
70628 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
70629 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
70630 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
70631 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
70632 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
70633 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
70634 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
70635 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
70636 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
70637 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
70638 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
70639 +
70640 +#else
70641 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
70642 +#define copy_gr_arg copy_gr_arg_normal
70643 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
70644 +#define copy_acl_object_label copy_acl_object_label_normal
70645 +#define copy_acl_subject_label copy_acl_subject_label_normal
70646 +#define copy_acl_role_label copy_acl_role_label_normal
70647 +#define copy_acl_ip_label copy_acl_ip_label_normal
70648 +#define copy_pointer_from_array copy_pointer_from_array_normal
70649 +#define copy_sprole_pw copy_sprole_pw_normal
70650 +#define copy_role_transition copy_role_transition_normal
70651 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
70652 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
70653 +#endif
70654 +
70655 +static struct acl_subject_label *
70656 +lookup_subject_map(const struct acl_subject_label *userp)
70657 +{
70658 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
70659 + struct subject_map *match;
70660 +
70661 + match = polstate->subj_map_set.s_hash[index];
70662 +
70663 + while (match && match->user != userp)
70664 + match = match->next;
70665 +
70666 + if (match != NULL)
70667 + return match->kernel;
70668 + else
70669 + return NULL;
70670 +}
70671 +
70672 +static void
70673 +insert_subj_map_entry(struct subject_map *subjmap)
70674 +{
70675 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
70676 + struct subject_map **curr;
70677 +
70678 + subjmap->prev = NULL;
70679 +
70680 + curr = &polstate->subj_map_set.s_hash[index];
70681 + if (*curr != NULL)
70682 + (*curr)->prev = subjmap;
70683 +
70684 + subjmap->next = *curr;
70685 + *curr = subjmap;
70686 +
70687 + return;
70688 +}
70689 +
70690 +static void
70691 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
70692 +{
70693 + unsigned int index =
70694 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
70695 + struct acl_role_label **curr;
70696 + struct acl_role_label *tmp, *tmp2;
70697 +
70698 + curr = &polstate->acl_role_set.r_hash[index];
70699 +
70700 + /* simple case, slot is empty, just set it to our role */
70701 + if (*curr == NULL) {
70702 + *curr = role;
70703 + } else {
70704 + /* example:
70705 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
70706 + 2 -> 3
70707 + */
70708 + /* first check to see if we can already be reached via this slot */
70709 + tmp = *curr;
70710 + while (tmp && tmp != role)
70711 + tmp = tmp->next;
70712 + if (tmp == role) {
70713 + /* we don't need to add ourselves to this slot's chain */
70714 + return;
70715 + }
70716 + /* we need to add ourselves to this chain, two cases */
70717 + if (role->next == NULL) {
70718 + /* simple case, append the current chain to our role */
70719 + role->next = *curr;
70720 + *curr = role;
70721 + } else {
70722 + /* 1 -> 2 -> 3 -> 4
70723 + 2 -> 3 -> 4
70724 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
70725 + */
70726 + /* trickier case: walk our role's chain until we find
70727 + the role for the start of the current slot's chain */
70728 + tmp = role;
70729 + tmp2 = *curr;
70730 + while (tmp->next && tmp->next != tmp2)
70731 + tmp = tmp->next;
70732 + if (tmp->next == tmp2) {
70733 + /* from example above, we found 3, so just
70734 + replace this slot's chain with ours */
70735 + *curr = role;
70736 + } else {
70737 + /* we didn't find a subset of our role's chain
70738 + in the current slot's chain, so append their
70739 + chain to ours, and set us as the first role in
70740 + the slot's chain
70741 +
70742 + we could fold this case with the case above,
70743 + but making it explicit for clarity
70744 + */
70745 + tmp->next = tmp2;
70746 + *curr = role;
70747 + }
70748 + }
70749 + }
70750 +
70751 + return;
70752 +}
70753 +
70754 +static void
70755 +insert_acl_role_label(struct acl_role_label *role)
70756 +{
70757 + int i;
70758 +
70759 + if (polstate->role_list == NULL) {
70760 + polstate->role_list = role;
70761 + role->prev = NULL;
70762 + } else {
70763 + role->prev = polstate->role_list;
70764 + polstate->role_list = role;
70765 + }
70766 +
70767 + /* used for hash chains */
70768 + role->next = NULL;
70769 +
70770 + if (role->roletype & GR_ROLE_DOMAIN) {
70771 + for (i = 0; i < role->domain_child_num; i++)
70772 + __insert_acl_role_label(role, role->domain_children[i]);
70773 + } else
70774 + __insert_acl_role_label(role, role->uidgid);
70775 +}
70776 +
70777 +static int
70778 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70779 +{
70780 + struct name_entry **curr, *nentry;
70781 + struct inodev_entry *ientry;
70782 + unsigned int len = strlen(name);
70783 + unsigned int key = full_name_hash(name, len);
70784 + unsigned int index = key % polstate->name_set.n_size;
70785 +
70786 + curr = &polstate->name_set.n_hash[index];
70787 +
70788 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70789 + curr = &((*curr)->next);
70790 +
70791 + if (*curr != NULL)
70792 + return 1;
70793 +
70794 + nentry = acl_alloc(sizeof (struct name_entry));
70795 + if (nentry == NULL)
70796 + return 0;
70797 + ientry = acl_alloc(sizeof (struct inodev_entry));
70798 + if (ientry == NULL)
70799 + return 0;
70800 + ientry->nentry = nentry;
70801 +
70802 + nentry->key = key;
70803 + nentry->name = name;
70804 + nentry->inode = inode;
70805 + nentry->device = device;
70806 + nentry->len = len;
70807 + nentry->deleted = deleted;
70808 +
70809 + nentry->prev = NULL;
70810 + curr = &polstate->name_set.n_hash[index];
70811 + if (*curr != NULL)
70812 + (*curr)->prev = nentry;
70813 + nentry->next = *curr;
70814 + *curr = nentry;
70815 +
70816 + /* insert us into the table searchable by inode/dev */
70817 + __insert_inodev_entry(polstate, ientry);
70818 +
70819 + return 1;
70820 +}
70821 +
70822 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
70823 +
70824 +static void *
70825 +create_table(__u32 * len, int elementsize)
70826 +{
70827 + unsigned int table_sizes[] = {
70828 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
70829 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
70830 + 4194301, 8388593, 16777213, 33554393, 67108859
70831 + };
70832 + void *newtable = NULL;
70833 + unsigned int pwr = 0;
70834 +
70835 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
70836 + table_sizes[pwr] <= *len)
70837 + pwr++;
70838 +
70839 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
70840 + return newtable;
70841 +
70842 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
70843 + newtable =
70844 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
70845 + else
70846 + newtable = vmalloc(table_sizes[pwr] * elementsize);
70847 +
70848 + *len = table_sizes[pwr];
70849 +
70850 + return newtable;
70851 +}
70852 +
70853 +static int
70854 +init_variables(const struct gr_arg *arg, bool reload)
70855 +{
70856 + struct task_struct *reaper = init_pid_ns.child_reaper;
70857 + unsigned int stacksize;
70858 +
70859 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
70860 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
70861 + polstate->name_set.n_size = arg->role_db.num_objects;
70862 + polstate->inodev_set.i_size = arg->role_db.num_objects;
70863 +
70864 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
70865 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
70866 + return 1;
70867 +
70868 + if (!reload) {
70869 + if (!gr_init_uidset())
70870 + return 1;
70871 + }
70872 +
70873 + /* set up the stack that holds allocation info */
70874 +
70875 + stacksize = arg->role_db.num_pointers + 5;
70876 +
70877 + if (!acl_alloc_stack_init(stacksize))
70878 + return 1;
70879 +
70880 + if (!reload) {
70881 + /* grab reference for the real root dentry and vfsmount */
70882 + get_fs_root(reaper->fs, &gr_real_root);
70883 +
70884 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70885 + 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);
70886 +#endif
70887 +
70888 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70889 + if (fakefs_obj_rw == NULL)
70890 + return 1;
70891 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
70892 +
70893 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70894 + if (fakefs_obj_rwx == NULL)
70895 + return 1;
70896 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
70897 + }
70898 +
70899 + polstate->subj_map_set.s_hash =
70900 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
70901 + polstate->acl_role_set.r_hash =
70902 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
70903 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
70904 + polstate->inodev_set.i_hash =
70905 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
70906 +
70907 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
70908 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
70909 + return 1;
70910 +
70911 + memset(polstate->subj_map_set.s_hash, 0,
70912 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
70913 + memset(polstate->acl_role_set.r_hash, 0,
70914 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
70915 + memset(polstate->name_set.n_hash, 0,
70916 + sizeof (struct name_entry *) * polstate->name_set.n_size);
70917 + memset(polstate->inodev_set.i_hash, 0,
70918 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
70919 +
70920 + return 0;
70921 +}
70922 +
70923 +/* free information not needed after startup
70924 + currently contains user->kernel pointer mappings for subjects
70925 +*/
70926 +
70927 +static void
70928 +free_init_variables(void)
70929 +{
70930 + __u32 i;
70931 +
70932 + if (polstate->subj_map_set.s_hash) {
70933 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
70934 + if (polstate->subj_map_set.s_hash[i]) {
70935 + kfree(polstate->subj_map_set.s_hash[i]);
70936 + polstate->subj_map_set.s_hash[i] = NULL;
70937 + }
70938 + }
70939 +
70940 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
70941 + PAGE_SIZE)
70942 + kfree(polstate->subj_map_set.s_hash);
70943 + else
70944 + vfree(polstate->subj_map_set.s_hash);
70945 + }
70946 +
70947 + return;
70948 +}
70949 +
70950 +static void
70951 +free_variables(bool reload)
70952 +{
70953 + struct acl_subject_label *s;
70954 + struct acl_role_label *r;
70955 + struct task_struct *task, *task2;
70956 + unsigned int x;
70957 +
70958 + if (!reload) {
70959 + gr_clear_learn_entries();
70960 +
70961 + read_lock(&tasklist_lock);
70962 + do_each_thread(task2, task) {
70963 + task->acl_sp_role = 0;
70964 + task->acl_role_id = 0;
70965 + task->inherited = 0;
70966 + task->acl = NULL;
70967 + task->role = NULL;
70968 + } while_each_thread(task2, task);
70969 + read_unlock(&tasklist_lock);
70970 +
70971 + kfree(fakefs_obj_rw);
70972 + fakefs_obj_rw = NULL;
70973 + kfree(fakefs_obj_rwx);
70974 + fakefs_obj_rwx = NULL;
70975 +
70976 + /* release the reference to the real root dentry and vfsmount */
70977 + path_put(&gr_real_root);
70978 + memset(&gr_real_root, 0, sizeof(gr_real_root));
70979 + }
70980 +
70981 + /* free all object hash tables */
70982 +
70983 + FOR_EACH_ROLE_START(r)
70984 + if (r->subj_hash == NULL)
70985 + goto next_role;
70986 + FOR_EACH_SUBJECT_START(r, s, x)
70987 + if (s->obj_hash == NULL)
70988 + break;
70989 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70990 + kfree(s->obj_hash);
70991 + else
70992 + vfree(s->obj_hash);
70993 + FOR_EACH_SUBJECT_END(s, x)
70994 + FOR_EACH_NESTED_SUBJECT_START(r, s)
70995 + if (s->obj_hash == NULL)
70996 + break;
70997 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70998 + kfree(s->obj_hash);
70999 + else
71000 + vfree(s->obj_hash);
71001 + FOR_EACH_NESTED_SUBJECT_END(s)
71002 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71003 + kfree(r->subj_hash);
71004 + else
71005 + vfree(r->subj_hash);
71006 + r->subj_hash = NULL;
71007 +next_role:
71008 + FOR_EACH_ROLE_END(r)
71009 +
71010 + acl_free_all();
71011 +
71012 + if (polstate->acl_role_set.r_hash) {
71013 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71014 + PAGE_SIZE)
71015 + kfree(polstate->acl_role_set.r_hash);
71016 + else
71017 + vfree(polstate->acl_role_set.r_hash);
71018 + }
71019 + if (polstate->name_set.n_hash) {
71020 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71021 + PAGE_SIZE)
71022 + kfree(polstate->name_set.n_hash);
71023 + else
71024 + vfree(polstate->name_set.n_hash);
71025 + }
71026 +
71027 + if (polstate->inodev_set.i_hash) {
71028 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71029 + PAGE_SIZE)
71030 + kfree(polstate->inodev_set.i_hash);
71031 + else
71032 + vfree(polstate->inodev_set.i_hash);
71033 + }
71034 +
71035 + if (!reload)
71036 + gr_free_uidset();
71037 +
71038 + memset(&polstate->name_set, 0, sizeof (struct name_db));
71039 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71040 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71041 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71042 +
71043 + polstate->default_role = NULL;
71044 + polstate->kernel_role = NULL;
71045 + polstate->role_list = NULL;
71046 +
71047 + return;
71048 +}
71049 +
71050 +static struct acl_subject_label *
71051 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71052 +
71053 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
71054 +{
71055 + unsigned int len = strnlen_user(*name, maxlen);
71056 + char *tmp;
71057 +
71058 + if (!len || len >= maxlen)
71059 + return -EINVAL;
71060 +
71061 + if ((tmp = (char *) acl_alloc(len)) == NULL)
71062 + return -ENOMEM;
71063 +
71064 + if (copy_from_user(tmp, *name, len))
71065 + return -EFAULT;
71066 +
71067 + tmp[len-1] = '\0';
71068 + *name = tmp;
71069 +
71070 + return 0;
71071 +}
71072 +
71073 +static int
71074 +copy_user_glob(struct acl_object_label *obj)
71075 +{
71076 + struct acl_object_label *g_tmp, **guser;
71077 + int error;
71078 +
71079 + if (obj->globbed == NULL)
71080 + return 0;
71081 +
71082 + guser = &obj->globbed;
71083 + while (*guser) {
71084 + g_tmp = (struct acl_object_label *)
71085 + acl_alloc(sizeof (struct acl_object_label));
71086 + if (g_tmp == NULL)
71087 + return -ENOMEM;
71088 +
71089 + if (copy_acl_object_label(g_tmp, *guser))
71090 + return -EFAULT;
71091 +
71092 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71093 + if (error)
71094 + return error;
71095 +
71096 + *guser = g_tmp;
71097 + guser = &(g_tmp->next);
71098 + }
71099 +
71100 + return 0;
71101 +}
71102 +
71103 +static int
71104 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71105 + struct acl_role_label *role)
71106 +{
71107 + struct acl_object_label *o_tmp;
71108 + int ret;
71109 +
71110 + while (userp) {
71111 + if ((o_tmp = (struct acl_object_label *)
71112 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
71113 + return -ENOMEM;
71114 +
71115 + if (copy_acl_object_label(o_tmp, userp))
71116 + return -EFAULT;
71117 +
71118 + userp = o_tmp->prev;
71119 +
71120 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71121 + if (ret)
71122 + return ret;
71123 +
71124 + insert_acl_obj_label(o_tmp, subj);
71125 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71126 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71127 + return -ENOMEM;
71128 +
71129 + ret = copy_user_glob(o_tmp);
71130 + if (ret)
71131 + return ret;
71132 +
71133 + if (o_tmp->nested) {
71134 + int already_copied;
71135 +
71136 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71137 + if (IS_ERR(o_tmp->nested))
71138 + return PTR_ERR(o_tmp->nested);
71139 +
71140 + /* insert into nested subject list if we haven't copied this one yet
71141 + to prevent duplicate entries */
71142 + if (!already_copied) {
71143 + o_tmp->nested->next = role->hash->first;
71144 + role->hash->first = o_tmp->nested;
71145 + }
71146 + }
71147 + }
71148 +
71149 + return 0;
71150 +}
71151 +
71152 +static __u32
71153 +count_user_subjs(struct acl_subject_label *userp)
71154 +{
71155 + struct acl_subject_label s_tmp;
71156 + __u32 num = 0;
71157 +
71158 + while (userp) {
71159 + if (copy_acl_subject_label(&s_tmp, userp))
71160 + break;
71161 +
71162 + userp = s_tmp.prev;
71163 + }
71164 +
71165 + return num;
71166 +}
71167 +
71168 +static int
71169 +copy_user_allowedips(struct acl_role_label *rolep)
71170 +{
71171 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71172 +
71173 + ruserip = rolep->allowed_ips;
71174 +
71175 + while (ruserip) {
71176 + rlast = rtmp;
71177 +
71178 + if ((rtmp = (struct role_allowed_ip *)
71179 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71180 + return -ENOMEM;
71181 +
71182 + if (copy_role_allowed_ip(rtmp, ruserip))
71183 + return -EFAULT;
71184 +
71185 + ruserip = rtmp->prev;
71186 +
71187 + if (!rlast) {
71188 + rtmp->prev = NULL;
71189 + rolep->allowed_ips = rtmp;
71190 + } else {
71191 + rlast->next = rtmp;
71192 + rtmp->prev = rlast;
71193 + }
71194 +
71195 + if (!ruserip)
71196 + rtmp->next = NULL;
71197 + }
71198 +
71199 + return 0;
71200 +}
71201 +
71202 +static int
71203 +copy_user_transitions(struct acl_role_label *rolep)
71204 +{
71205 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
71206 + int error;
71207 +
71208 + rusertp = rolep->transitions;
71209 +
71210 + while (rusertp) {
71211 + rlast = rtmp;
71212 +
71213 + if ((rtmp = (struct role_transition *)
71214 + acl_alloc(sizeof (struct role_transition))) == NULL)
71215 + return -ENOMEM;
71216 +
71217 + if (copy_role_transition(rtmp, rusertp))
71218 + return -EFAULT;
71219 +
71220 + rusertp = rtmp->prev;
71221 +
71222 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71223 + if (error)
71224 + return error;
71225 +
71226 + if (!rlast) {
71227 + rtmp->prev = NULL;
71228 + rolep->transitions = rtmp;
71229 + } else {
71230 + rlast->next = rtmp;
71231 + rtmp->prev = rlast;
71232 + }
71233 +
71234 + if (!rusertp)
71235 + rtmp->next = NULL;
71236 + }
71237 +
71238 + return 0;
71239 +}
71240 +
71241 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
71242 +{
71243 + struct acl_object_label o_tmp;
71244 + __u32 num = 0;
71245 +
71246 + while (userp) {
71247 + if (copy_acl_object_label(&o_tmp, userp))
71248 + break;
71249 +
71250 + userp = o_tmp.prev;
71251 + num++;
71252 + }
71253 +
71254 + return num;
71255 +}
71256 +
71257 +static struct acl_subject_label *
71258 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71259 +{
71260 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71261 + __u32 num_objs;
71262 + struct acl_ip_label **i_tmp, *i_utmp2;
71263 + struct gr_hash_struct ghash;
71264 + struct subject_map *subjmap;
71265 + unsigned int i_num;
71266 + int err;
71267 +
71268 + if (already_copied != NULL)
71269 + *already_copied = 0;
71270 +
71271 + s_tmp = lookup_subject_map(userp);
71272 +
71273 + /* we've already copied this subject into the kernel, just return
71274 + the reference to it, and don't copy it over again
71275 + */
71276 + if (s_tmp) {
71277 + if (already_copied != NULL)
71278 + *already_copied = 1;
71279 + return(s_tmp);
71280 + }
71281 +
71282 + if ((s_tmp = (struct acl_subject_label *)
71283 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71284 + return ERR_PTR(-ENOMEM);
71285 +
71286 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71287 + if (subjmap == NULL)
71288 + return ERR_PTR(-ENOMEM);
71289 +
71290 + subjmap->user = userp;
71291 + subjmap->kernel = s_tmp;
71292 + insert_subj_map_entry(subjmap);
71293 +
71294 + if (copy_acl_subject_label(s_tmp, userp))
71295 + return ERR_PTR(-EFAULT);
71296 +
71297 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71298 + if (err)
71299 + return ERR_PTR(err);
71300 +
71301 + if (!strcmp(s_tmp->filename, "/"))
71302 + role->root_label = s_tmp;
71303 +
71304 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71305 + return ERR_PTR(-EFAULT);
71306 +
71307 + /* copy user and group transition tables */
71308 +
71309 + if (s_tmp->user_trans_num) {
71310 + uid_t *uidlist;
71311 +
71312 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71313 + if (uidlist == NULL)
71314 + return ERR_PTR(-ENOMEM);
71315 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71316 + return ERR_PTR(-EFAULT);
71317 +
71318 + s_tmp->user_transitions = uidlist;
71319 + }
71320 +
71321 + if (s_tmp->group_trans_num) {
71322 + gid_t *gidlist;
71323 +
71324 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71325 + if (gidlist == NULL)
71326 + return ERR_PTR(-ENOMEM);
71327 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71328 + return ERR_PTR(-EFAULT);
71329 +
71330 + s_tmp->group_transitions = gidlist;
71331 + }
71332 +
71333 + /* set up object hash table */
71334 + num_objs = count_user_objs(ghash.first);
71335 +
71336 + s_tmp->obj_hash_size = num_objs;
71337 + s_tmp->obj_hash =
71338 + (struct acl_object_label **)
71339 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71340 +
71341 + if (!s_tmp->obj_hash)
71342 + return ERR_PTR(-ENOMEM);
71343 +
71344 + memset(s_tmp->obj_hash, 0,
71345 + s_tmp->obj_hash_size *
71346 + sizeof (struct acl_object_label *));
71347 +
71348 + /* add in objects */
71349 + err = copy_user_objs(ghash.first, s_tmp, role);
71350 +
71351 + if (err)
71352 + return ERR_PTR(err);
71353 +
71354 + /* set pointer for parent subject */
71355 + if (s_tmp->parent_subject) {
71356 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71357 +
71358 + if (IS_ERR(s_tmp2))
71359 + return s_tmp2;
71360 +
71361 + s_tmp->parent_subject = s_tmp2;
71362 + }
71363 +
71364 + /* add in ip acls */
71365 +
71366 + if (!s_tmp->ip_num) {
71367 + s_tmp->ips = NULL;
71368 + goto insert;
71369 + }
71370 +
71371 + i_tmp =
71372 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71373 + sizeof (struct acl_ip_label *));
71374 +
71375 + if (!i_tmp)
71376 + return ERR_PTR(-ENOMEM);
71377 +
71378 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71379 + *(i_tmp + i_num) =
71380 + (struct acl_ip_label *)
71381 + acl_alloc(sizeof (struct acl_ip_label));
71382 + if (!*(i_tmp + i_num))
71383 + return ERR_PTR(-ENOMEM);
71384 +
71385 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71386 + return ERR_PTR(-EFAULT);
71387 +
71388 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71389 + return ERR_PTR(-EFAULT);
71390 +
71391 + if ((*(i_tmp + i_num))->iface == NULL)
71392 + continue;
71393 +
71394 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71395 + if (err)
71396 + return ERR_PTR(err);
71397 + }
71398 +
71399 + s_tmp->ips = i_tmp;
71400 +
71401 +insert:
71402 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71403 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71404 + return ERR_PTR(-ENOMEM);
71405 +
71406 + return s_tmp;
71407 +}
71408 +
71409 +static int
71410 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71411 +{
71412 + struct acl_subject_label s_pre;
71413 + struct acl_subject_label * ret;
71414 + int err;
71415 +
71416 + while (userp) {
71417 + if (copy_acl_subject_label(&s_pre, userp))
71418 + return -EFAULT;
71419 +
71420 + ret = do_copy_user_subj(userp, role, NULL);
71421 +
71422 + err = PTR_ERR(ret);
71423 + if (IS_ERR(ret))
71424 + return err;
71425 +
71426 + insert_acl_subj_label(ret, role);
71427 +
71428 + userp = s_pre.prev;
71429 + }
71430 +
71431 + return 0;
71432 +}
71433 +
71434 +static int
71435 +copy_user_acl(struct gr_arg *arg)
71436 +{
71437 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71438 + struct acl_subject_label *subj_list;
71439 + struct sprole_pw *sptmp;
71440 + struct gr_hash_struct *ghash;
71441 + uid_t *domainlist;
71442 + unsigned int r_num;
71443 + int err = 0;
71444 + __u16 i;
71445 + __u32 num_subjs;
71446 +
71447 + /* we need a default and kernel role */
71448 + if (arg->role_db.num_roles < 2)
71449 + return -EINVAL;
71450 +
71451 + /* copy special role authentication info from userspace */
71452 +
71453 + polstate->num_sprole_pws = arg->num_sprole_pws;
71454 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71455 +
71456 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71457 + return -ENOMEM;
71458 +
71459 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71460 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71461 + if (!sptmp)
71462 + return -ENOMEM;
71463 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71464 + return -EFAULT;
71465 +
71466 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71467 + if (err)
71468 + return err;
71469 +
71470 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71471 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71472 +#endif
71473 +
71474 + polstate->acl_special_roles[i] = sptmp;
71475 + }
71476 +
71477 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71478 +
71479 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71480 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
71481 +
71482 + if (!r_tmp)
71483 + return -ENOMEM;
71484 +
71485 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71486 + return -EFAULT;
71487 +
71488 + if (copy_acl_role_label(r_tmp, r_utmp2))
71489 + return -EFAULT;
71490 +
71491 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71492 + if (err)
71493 + return err;
71494 +
71495 + if (!strcmp(r_tmp->rolename, "default")
71496 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71497 + polstate->default_role = r_tmp;
71498 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71499 + polstate->kernel_role = r_tmp;
71500 + }
71501 +
71502 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71503 + return -ENOMEM;
71504 +
71505 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
71506 + return -EFAULT;
71507 +
71508 + r_tmp->hash = ghash;
71509 +
71510 + num_subjs = count_user_subjs(r_tmp->hash->first);
71511 +
71512 + r_tmp->subj_hash_size = num_subjs;
71513 + r_tmp->subj_hash =
71514 + (struct acl_subject_label **)
71515 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71516 +
71517 + if (!r_tmp->subj_hash)
71518 + return -ENOMEM;
71519 +
71520 + err = copy_user_allowedips(r_tmp);
71521 + if (err)
71522 + return err;
71523 +
71524 + /* copy domain info */
71525 + if (r_tmp->domain_children != NULL) {
71526 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71527 + if (domainlist == NULL)
71528 + return -ENOMEM;
71529 +
71530 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71531 + return -EFAULT;
71532 +
71533 + r_tmp->domain_children = domainlist;
71534 + }
71535 +
71536 + err = copy_user_transitions(r_tmp);
71537 + if (err)
71538 + return err;
71539 +
71540 + memset(r_tmp->subj_hash, 0,
71541 + r_tmp->subj_hash_size *
71542 + sizeof (struct acl_subject_label *));
71543 +
71544 + /* acquire the list of subjects, then NULL out
71545 + the list prior to parsing the subjects for this role,
71546 + as during this parsing the list is replaced with a list
71547 + of *nested* subjects for the role
71548 + */
71549 + subj_list = r_tmp->hash->first;
71550 +
71551 + /* set nested subject list to null */
71552 + r_tmp->hash->first = NULL;
71553 +
71554 + err = copy_user_subjs(subj_list, r_tmp);
71555 +
71556 + if (err)
71557 + return err;
71558 +
71559 + insert_acl_role_label(r_tmp);
71560 + }
71561 +
71562 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71563 + return -EINVAL;
71564 +
71565 + return err;
71566 +}
71567 +
71568 +static int gracl_reload_apply_policies(void *reload)
71569 +{
71570 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71571 + struct task_struct *task, *task2;
71572 + struct acl_role_label *role, *rtmp;
71573 + struct acl_subject_label *subj;
71574 + const struct cred *cred;
71575 + int role_applied;
71576 + int ret = 0;
71577 +
71578 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71579 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71580 +
71581 + /* first make sure we'll be able to apply the new policy cleanly */
71582 + do_each_thread(task2, task) {
71583 + if (task->exec_file == NULL)
71584 + continue;
71585 + role_applied = 0;
71586 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71587 + /* preserve special roles */
71588 + FOR_EACH_ROLE_START(role)
71589 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71590 + rtmp = task->role;
71591 + task->role = role;
71592 + role_applied = 1;
71593 + break;
71594 + }
71595 + FOR_EACH_ROLE_END(role)
71596 + }
71597 + if (!role_applied) {
71598 + cred = __task_cred(task);
71599 + rtmp = task->role;
71600 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71601 + }
71602 + /* this handles non-nested inherited subjects, nested subjects will still
71603 + be dropped currently */
71604 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71605 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
71606 + /* change the role back so that we've made no modifications to the policy */
71607 + task->role = rtmp;
71608 +
71609 + if (subj == NULL || task->tmpacl == NULL) {
71610 + ret = -EINVAL;
71611 + goto out;
71612 + }
71613 + } while_each_thread(task2, task);
71614 +
71615 + /* now actually apply the policy */
71616 +
71617 + do_each_thread(task2, task) {
71618 + if (task->exec_file) {
71619 + role_applied = 0;
71620 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71621 + /* preserve special roles */
71622 + FOR_EACH_ROLE_START(role)
71623 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71624 + task->role = role;
71625 + role_applied = 1;
71626 + break;
71627 + }
71628 + FOR_EACH_ROLE_END(role)
71629 + }
71630 + if (!role_applied) {
71631 + cred = __task_cred(task);
71632 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71633 + }
71634 + /* this handles non-nested inherited subjects, nested subjects will still
71635 + be dropped currently */
71636 + if (!reload_state->oldmode && task->inherited)
71637 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71638 + else {
71639 + /* looked up and tagged to the task previously */
71640 + subj = task->tmpacl;
71641 + }
71642 + /* subj will be non-null */
71643 + __gr_apply_subject_to_task(polstate, task, subj);
71644 + if (reload_state->oldmode) {
71645 + task->acl_role_id = 0;
71646 + task->acl_sp_role = 0;
71647 + task->inherited = 0;
71648 + }
71649 + } else {
71650 + // it's a kernel process
71651 + task->role = polstate->kernel_role;
71652 + task->acl = polstate->kernel_role->root_label;
71653 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71654 + task->acl->mode &= ~GR_PROCFIND;
71655 +#endif
71656 + }
71657 + } while_each_thread(task2, task);
71658 +
71659 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
71660 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
71661 +
71662 +out:
71663 +
71664 + return ret;
71665 +}
71666 +
71667 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
71668 +{
71669 + struct gr_reload_state new_reload_state = { };
71670 + int err;
71671 +
71672 + new_reload_state.oldpolicy_ptr = polstate;
71673 + new_reload_state.oldalloc_ptr = current_alloc_state;
71674 + new_reload_state.oldmode = oldmode;
71675 +
71676 + current_alloc_state = &new_reload_state.newalloc;
71677 + polstate = &new_reload_state.newpolicy;
71678 +
71679 + /* everything relevant is now saved off, copy in the new policy */
71680 + if (init_variables(args, true)) {
71681 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71682 + err = -ENOMEM;
71683 + goto error;
71684 + }
71685 +
71686 + err = copy_user_acl(args);
71687 + free_init_variables();
71688 + if (err)
71689 + goto error;
71690 + /* the new policy is copied in, with the old policy available via saved_state
71691 + first go through applying roles, making sure to preserve special roles
71692 + then apply new subjects, making sure to preserve inherited and nested subjects,
71693 + though currently only inherited subjects will be preserved
71694 + */
71695 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
71696 + if (err)
71697 + goto error;
71698 +
71699 + /* we've now applied the new policy, so restore the old policy state to free it */
71700 + polstate = &new_reload_state.oldpolicy;
71701 + current_alloc_state = &new_reload_state.oldalloc;
71702 + free_variables(true);
71703 +
71704 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
71705 + to running_polstate/current_alloc_state inside stop_machine
71706 + */
71707 + err = 0;
71708 + goto out;
71709 +error:
71710 + /* on error of loading the new policy, we'll just keep the previous
71711 + policy set around
71712 + */
71713 + free_variables(true);
71714 +
71715 + /* doesn't affect runtime, but maintains consistent state */
71716 +out:
71717 + polstate = new_reload_state.oldpolicy_ptr;
71718 + current_alloc_state = new_reload_state.oldalloc_ptr;
71719 +
71720 + return err;
71721 +}
71722 +
71723 +static int
71724 +gracl_init(struct gr_arg *args)
71725 +{
71726 + int error = 0;
71727 +
71728 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
71729 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
71730 +
71731 + if (init_variables(args, false)) {
71732 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71733 + error = -ENOMEM;
71734 + goto out;
71735 + }
71736 +
71737 + error = copy_user_acl(args);
71738 + free_init_variables();
71739 + if (error)
71740 + goto out;
71741 +
71742 + error = gr_set_acls(0);
71743 + if (error)
71744 + goto out;
71745 +
71746 + gr_enable_rbac_system();
71747 +
71748 + return 0;
71749 +
71750 +out:
71751 + free_variables(false);
71752 + return error;
71753 +}
71754 +
71755 +static int
71756 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
71757 + unsigned char **sum)
71758 +{
71759 + struct acl_role_label *r;
71760 + struct role_allowed_ip *ipp;
71761 + struct role_transition *trans;
71762 + unsigned int i;
71763 + int found = 0;
71764 + u32 curr_ip = current->signal->curr_ip;
71765 +
71766 + current->signal->saved_ip = curr_ip;
71767 +
71768 + /* check transition table */
71769 +
71770 + for (trans = current->role->transitions; trans; trans = trans->next) {
71771 + if (!strcmp(rolename, trans->rolename)) {
71772 + found = 1;
71773 + break;
71774 + }
71775 + }
71776 +
71777 + if (!found)
71778 + return 0;
71779 +
71780 + /* handle special roles that do not require authentication
71781 + and check ip */
71782 +
71783 + FOR_EACH_ROLE_START(r)
71784 + if (!strcmp(rolename, r->rolename) &&
71785 + (r->roletype & GR_ROLE_SPECIAL)) {
71786 + found = 0;
71787 + if (r->allowed_ips != NULL) {
71788 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71789 + if ((ntohl(curr_ip) & ipp->netmask) ==
71790 + (ntohl(ipp->addr) & ipp->netmask))
71791 + found = 1;
71792 + }
71793 + } else
71794 + found = 2;
71795 + if (!found)
71796 + return 0;
71797 +
71798 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
71799 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
71800 + *salt = NULL;
71801 + *sum = NULL;
71802 + return 1;
71803 + }
71804 + }
71805 + FOR_EACH_ROLE_END(r)
71806 +
71807 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71808 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
71809 + *salt = polstate->acl_special_roles[i]->salt;
71810 + *sum = polstate->acl_special_roles[i]->sum;
71811 + return 1;
71812 + }
71813 + }
71814 +
71815 + return 0;
71816 +}
71817 +
71818 +int gr_check_secure_terminal(struct task_struct *task)
71819 +{
71820 + struct task_struct *p, *p2, *p3;
71821 + struct files_struct *files;
71822 + struct fdtable *fdt;
71823 + struct file *our_file = NULL, *file;
71824 + int i;
71825 +
71826 + if (task->signal->tty == NULL)
71827 + return 1;
71828 +
71829 + files = get_files_struct(task);
71830 + if (files != NULL) {
71831 + rcu_read_lock();
71832 + fdt = files_fdtable(files);
71833 + for (i=0; i < fdt->max_fds; i++) {
71834 + file = fcheck_files(files, i);
71835 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
71836 + get_file(file);
71837 + our_file = file;
71838 + }
71839 + }
71840 + rcu_read_unlock();
71841 + put_files_struct(files);
71842 + }
71843 +
71844 + if (our_file == NULL)
71845 + return 1;
71846 +
71847 + read_lock(&tasklist_lock);
71848 + do_each_thread(p2, p) {
71849 + files = get_files_struct(p);
71850 + if (files == NULL ||
71851 + (p->signal && p->signal->tty == task->signal->tty)) {
71852 + if (files != NULL)
71853 + put_files_struct(files);
71854 + continue;
71855 + }
71856 + rcu_read_lock();
71857 + fdt = files_fdtable(files);
71858 + for (i=0; i < fdt->max_fds; i++) {
71859 + file = fcheck_files(files, i);
71860 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
71861 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
71862 + p3 = task;
71863 + while (task_pid_nr(p3) > 0) {
71864 + if (p3 == p)
71865 + break;
71866 + p3 = p3->real_parent;
71867 + }
71868 + if (p3 == p)
71869 + break;
71870 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
71871 + gr_handle_alertkill(p);
71872 + rcu_read_unlock();
71873 + put_files_struct(files);
71874 + read_unlock(&tasklist_lock);
71875 + fput(our_file);
71876 + return 0;
71877 + }
71878 + }
71879 + rcu_read_unlock();
71880 + put_files_struct(files);
71881 + } while_each_thread(p2, p);
71882 + read_unlock(&tasklist_lock);
71883 +
71884 + fput(our_file);
71885 + return 1;
71886 +}
71887 +
71888 +ssize_t
71889 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
71890 +{
71891 + struct gr_arg_wrapper uwrap;
71892 + unsigned char *sprole_salt = NULL;
71893 + unsigned char *sprole_sum = NULL;
71894 + int error = 0;
71895 + int error2 = 0;
71896 + size_t req_count = 0;
71897 + unsigned char oldmode = 0;
71898 +
71899 + mutex_lock(&gr_dev_mutex);
71900 +
71901 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
71902 + error = -EPERM;
71903 + goto out;
71904 + }
71905 +
71906 +#ifdef CONFIG_COMPAT
71907 + pax_open_kernel();
71908 + if (is_compat_task()) {
71909 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
71910 + copy_gr_arg = &copy_gr_arg_compat;
71911 + copy_acl_object_label = &copy_acl_object_label_compat;
71912 + copy_acl_subject_label = &copy_acl_subject_label_compat;
71913 + copy_acl_role_label = &copy_acl_role_label_compat;
71914 + copy_acl_ip_label = &copy_acl_ip_label_compat;
71915 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
71916 + copy_role_transition = &copy_role_transition_compat;
71917 + copy_sprole_pw = &copy_sprole_pw_compat;
71918 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
71919 + copy_pointer_from_array = &copy_pointer_from_array_compat;
71920 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
71921 + } else {
71922 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
71923 + copy_gr_arg = &copy_gr_arg_normal;
71924 + copy_acl_object_label = &copy_acl_object_label_normal;
71925 + copy_acl_subject_label = &copy_acl_subject_label_normal;
71926 + copy_acl_role_label = &copy_acl_role_label_normal;
71927 + copy_acl_ip_label = &copy_acl_ip_label_normal;
71928 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
71929 + copy_role_transition = &copy_role_transition_normal;
71930 + copy_sprole_pw = &copy_sprole_pw_normal;
71931 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
71932 + copy_pointer_from_array = &copy_pointer_from_array_normal;
71933 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
71934 + }
71935 + pax_close_kernel();
71936 +#endif
71937 +
71938 + req_count = get_gr_arg_wrapper_size();
71939 +
71940 + if (count != req_count) {
71941 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
71942 + error = -EINVAL;
71943 + goto out;
71944 + }
71945 +
71946 +
71947 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
71948 + gr_auth_expires = 0;
71949 + gr_auth_attempts = 0;
71950 + }
71951 +
71952 + error = copy_gr_arg_wrapper(buf, &uwrap);
71953 + if (error)
71954 + goto out;
71955 +
71956 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
71957 + if (error)
71958 + goto out;
71959 +
71960 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71961 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71962 + time_after(gr_auth_expires, get_seconds())) {
71963 + error = -EBUSY;
71964 + goto out;
71965 + }
71966 +
71967 + /* if non-root trying to do anything other than use a special role,
71968 + do not attempt authentication, do not count towards authentication
71969 + locking
71970 + */
71971 +
71972 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
71973 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71974 + gr_is_global_nonroot(current_uid())) {
71975 + error = -EPERM;
71976 + goto out;
71977 + }
71978 +
71979 + /* ensure pw and special role name are null terminated */
71980 +
71981 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
71982 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
71983 +
71984 + /* Okay.
71985 + * We have our enough of the argument structure..(we have yet
71986 + * to copy_from_user the tables themselves) . Copy the tables
71987 + * only if we need them, i.e. for loading operations. */
71988 +
71989 + switch (gr_usermode.mode) {
71990 + case GR_STATUS:
71991 + if (gr_acl_is_enabled()) {
71992 + error = 1;
71993 + if (!gr_check_secure_terminal(current))
71994 + error = 3;
71995 + } else
71996 + error = 2;
71997 + goto out;
71998 + case GR_SHUTDOWN:
71999 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72000 + stop_machine(gr_rbac_disable, NULL, NULL);
72001 + free_variables(false);
72002 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72003 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72004 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72005 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72006 + } else if (gr_acl_is_enabled()) {
72007 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72008 + error = -EPERM;
72009 + } else {
72010 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72011 + error = -EAGAIN;
72012 + }
72013 + break;
72014 + case GR_ENABLE:
72015 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72016 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72017 + else {
72018 + if (gr_acl_is_enabled())
72019 + error = -EAGAIN;
72020 + else
72021 + error = error2;
72022 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72023 + }
72024 + break;
72025 + case GR_OLDRELOAD:
72026 + oldmode = 1;
72027 + case GR_RELOAD:
72028 + if (!gr_acl_is_enabled()) {
72029 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72030 + error = -EAGAIN;
72031 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72032 + error2 = gracl_reload(&gr_usermode, oldmode);
72033 + if (!error2)
72034 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72035 + else {
72036 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72037 + error = error2;
72038 + }
72039 + } else {
72040 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72041 + error = -EPERM;
72042 + }
72043 + break;
72044 + case GR_SEGVMOD:
72045 + if (unlikely(!gr_acl_is_enabled())) {
72046 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72047 + error = -EAGAIN;
72048 + break;
72049 + }
72050 +
72051 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72052 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72053 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72054 + struct acl_subject_label *segvacl;
72055 + segvacl =
72056 + lookup_acl_subj_label(gr_usermode.segv_inode,
72057 + gr_usermode.segv_device,
72058 + current->role);
72059 + if (segvacl) {
72060 + segvacl->crashes = 0;
72061 + segvacl->expires = 0;
72062 + }
72063 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72064 + gr_remove_uid(gr_usermode.segv_uid);
72065 + }
72066 + } else {
72067 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72068 + error = -EPERM;
72069 + }
72070 + break;
72071 + case GR_SPROLE:
72072 + case GR_SPROLEPAM:
72073 + if (unlikely(!gr_acl_is_enabled())) {
72074 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72075 + error = -EAGAIN;
72076 + break;
72077 + }
72078 +
72079 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72080 + current->role->expires = 0;
72081 + current->role->auth_attempts = 0;
72082 + }
72083 +
72084 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72085 + time_after(current->role->expires, get_seconds())) {
72086 + error = -EBUSY;
72087 + goto out;
72088 + }
72089 +
72090 + if (lookup_special_role_auth
72091 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72092 + && ((!sprole_salt && !sprole_sum)
72093 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72094 + char *p = "";
72095 + assign_special_role(gr_usermode.sp_role);
72096 + read_lock(&tasklist_lock);
72097 + if (current->real_parent)
72098 + p = current->real_parent->role->rolename;
72099 + read_unlock(&tasklist_lock);
72100 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72101 + p, acl_sp_role_value);
72102 + } else {
72103 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72104 + error = -EPERM;
72105 + if(!(current->role->auth_attempts++))
72106 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72107 +
72108 + goto out;
72109 + }
72110 + break;
72111 + case GR_UNSPROLE:
72112 + if (unlikely(!gr_acl_is_enabled())) {
72113 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72114 + error = -EAGAIN;
72115 + break;
72116 + }
72117 +
72118 + if (current->role->roletype & GR_ROLE_SPECIAL) {
72119 + char *p = "";
72120 + int i = 0;
72121 +
72122 + read_lock(&tasklist_lock);
72123 + if (current->real_parent) {
72124 + p = current->real_parent->role->rolename;
72125 + i = current->real_parent->acl_role_id;
72126 + }
72127 + read_unlock(&tasklist_lock);
72128 +
72129 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72130 + gr_set_acls(1);
72131 + } else {
72132 + error = -EPERM;
72133 + goto out;
72134 + }
72135 + break;
72136 + default:
72137 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72138 + error = -EINVAL;
72139 + break;
72140 + }
72141 +
72142 + if (error != -EPERM)
72143 + goto out;
72144 +
72145 + if(!(gr_auth_attempts++))
72146 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72147 +
72148 + out:
72149 + mutex_unlock(&gr_dev_mutex);
72150 +
72151 + if (!error)
72152 + error = req_count;
72153 +
72154 + return error;
72155 +}
72156 +
72157 +int
72158 +gr_set_acls(const int type)
72159 +{
72160 + struct task_struct *task, *task2;
72161 + struct acl_role_label *role = current->role;
72162 + struct acl_subject_label *subj;
72163 + __u16 acl_role_id = current->acl_role_id;
72164 + const struct cred *cred;
72165 + int ret;
72166 +
72167 + rcu_read_lock();
72168 + read_lock(&tasklist_lock);
72169 + read_lock(&grsec_exec_file_lock);
72170 + do_each_thread(task2, task) {
72171 + /* check to see if we're called from the exit handler,
72172 + if so, only replace ACLs that have inherited the admin
72173 + ACL */
72174 +
72175 + if (type && (task->role != role ||
72176 + task->acl_role_id != acl_role_id))
72177 + continue;
72178 +
72179 + task->acl_role_id = 0;
72180 + task->acl_sp_role = 0;
72181 + task->inherited = 0;
72182 +
72183 + if (task->exec_file) {
72184 + cred = __task_cred(task);
72185 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72186 + subj = __gr_get_subject_for_task(polstate, task, NULL);
72187 + if (subj == NULL) {
72188 + ret = -EINVAL;
72189 + read_unlock(&grsec_exec_file_lock);
72190 + read_unlock(&tasklist_lock);
72191 + rcu_read_unlock();
72192 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72193 + return ret;
72194 + }
72195 + __gr_apply_subject_to_task(polstate, task, subj);
72196 + } else {
72197 + // it's a kernel process
72198 + task->role = polstate->kernel_role;
72199 + task->acl = polstate->kernel_role->root_label;
72200 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72201 + task->acl->mode &= ~GR_PROCFIND;
72202 +#endif
72203 + }
72204 + } while_each_thread(task2, task);
72205 + read_unlock(&grsec_exec_file_lock);
72206 + read_unlock(&tasklist_lock);
72207 + rcu_read_unlock();
72208 +
72209 + return 0;
72210 +}
72211 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72212 new file mode 100644
72213 index 0000000..39645c9
72214 --- /dev/null
72215 +++ b/grsecurity/gracl_res.c
72216 @@ -0,0 +1,68 @@
72217 +#include <linux/kernel.h>
72218 +#include <linux/sched.h>
72219 +#include <linux/gracl.h>
72220 +#include <linux/grinternal.h>
72221 +
72222 +static const char *restab_log[] = {
72223 + [RLIMIT_CPU] = "RLIMIT_CPU",
72224 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72225 + [RLIMIT_DATA] = "RLIMIT_DATA",
72226 + [RLIMIT_STACK] = "RLIMIT_STACK",
72227 + [RLIMIT_CORE] = "RLIMIT_CORE",
72228 + [RLIMIT_RSS] = "RLIMIT_RSS",
72229 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
72230 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72231 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72232 + [RLIMIT_AS] = "RLIMIT_AS",
72233 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72234 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72235 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72236 + [RLIMIT_NICE] = "RLIMIT_NICE",
72237 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72238 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72239 + [GR_CRASH_RES] = "RLIMIT_CRASH"
72240 +};
72241 +
72242 +void
72243 +gr_log_resource(const struct task_struct *task,
72244 + const int res, const unsigned long wanted, const int gt)
72245 +{
72246 + const struct cred *cred;
72247 + unsigned long rlim;
72248 +
72249 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
72250 + return;
72251 +
72252 + // not yet supported resource
72253 + if (unlikely(!restab_log[res]))
72254 + return;
72255 +
72256 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72257 + rlim = task_rlimit_max(task, res);
72258 + else
72259 + rlim = task_rlimit(task, res);
72260 +
72261 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72262 + return;
72263 +
72264 + rcu_read_lock();
72265 + cred = __task_cred(task);
72266 +
72267 + if (res == RLIMIT_NPROC &&
72268 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72269 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72270 + goto out_rcu_unlock;
72271 + else if (res == RLIMIT_MEMLOCK &&
72272 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72273 + goto out_rcu_unlock;
72274 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72275 + goto out_rcu_unlock;
72276 + rcu_read_unlock();
72277 +
72278 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72279 +
72280 + return;
72281 +out_rcu_unlock:
72282 + rcu_read_unlock();
72283 + return;
72284 +}
72285 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72286 new file mode 100644
72287 index 0000000..2040e61
72288 --- /dev/null
72289 +++ b/grsecurity/gracl_segv.c
72290 @@ -0,0 +1,313 @@
72291 +#include <linux/kernel.h>
72292 +#include <linux/mm.h>
72293 +#include <asm/uaccess.h>
72294 +#include <asm/errno.h>
72295 +#include <asm/mman.h>
72296 +#include <net/sock.h>
72297 +#include <linux/file.h>
72298 +#include <linux/fs.h>
72299 +#include <linux/net.h>
72300 +#include <linux/in.h>
72301 +#include <linux/slab.h>
72302 +#include <linux/types.h>
72303 +#include <linux/sched.h>
72304 +#include <linux/timer.h>
72305 +#include <linux/gracl.h>
72306 +#include <linux/grsecurity.h>
72307 +#include <linux/grinternal.h>
72308 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72309 +#include <linux/magic.h>
72310 +#include <linux/pagemap.h>
72311 +#include "../fs/btrfs/async-thread.h"
72312 +#include "../fs/btrfs/ctree.h"
72313 +#include "../fs/btrfs/btrfs_inode.h"
72314 +#endif
72315 +
72316 +static struct crash_uid *uid_set;
72317 +static unsigned short uid_used;
72318 +static DEFINE_SPINLOCK(gr_uid_lock);
72319 +extern rwlock_t gr_inode_lock;
72320 +extern struct acl_subject_label *
72321 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72322 + struct acl_role_label *role);
72323 +
72324 +static inline dev_t __get_dev(const struct dentry *dentry)
72325 +{
72326 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72327 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72328 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
72329 + else
72330 +#endif
72331 + return dentry->d_sb->s_dev;
72332 +}
72333 +
72334 +int
72335 +gr_init_uidset(void)
72336 +{
72337 + uid_set =
72338 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72339 + uid_used = 0;
72340 +
72341 + return uid_set ? 1 : 0;
72342 +}
72343 +
72344 +void
72345 +gr_free_uidset(void)
72346 +{
72347 + if (uid_set) {
72348 + struct crash_uid *tmpset;
72349 + spin_lock(&gr_uid_lock);
72350 + tmpset = uid_set;
72351 + uid_set = NULL;
72352 + uid_used = 0;
72353 + spin_unlock(&gr_uid_lock);
72354 + if (tmpset)
72355 + kfree(tmpset);
72356 + }
72357 +
72358 + return;
72359 +}
72360 +
72361 +int
72362 +gr_find_uid(const uid_t uid)
72363 +{
72364 + struct crash_uid *tmp = uid_set;
72365 + uid_t buid;
72366 + int low = 0, high = uid_used - 1, mid;
72367 +
72368 + while (high >= low) {
72369 + mid = (low + high) >> 1;
72370 + buid = tmp[mid].uid;
72371 + if (buid == uid)
72372 + return mid;
72373 + if (buid > uid)
72374 + high = mid - 1;
72375 + if (buid < uid)
72376 + low = mid + 1;
72377 + }
72378 +
72379 + return -1;
72380 +}
72381 +
72382 +static __inline__ void
72383 +gr_insertsort(void)
72384 +{
72385 + unsigned short i, j;
72386 + struct crash_uid index;
72387 +
72388 + for (i = 1; i < uid_used; i++) {
72389 + index = uid_set[i];
72390 + j = i;
72391 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72392 + uid_set[j] = uid_set[j - 1];
72393 + j--;
72394 + }
72395 + uid_set[j] = index;
72396 + }
72397 +
72398 + return;
72399 +}
72400 +
72401 +static __inline__ void
72402 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72403 +{
72404 + int loc;
72405 + uid_t uid = GR_GLOBAL_UID(kuid);
72406 +
72407 + if (uid_used == GR_UIDTABLE_MAX)
72408 + return;
72409 +
72410 + loc = gr_find_uid(uid);
72411 +
72412 + if (loc >= 0) {
72413 + uid_set[loc].expires = expires;
72414 + return;
72415 + }
72416 +
72417 + uid_set[uid_used].uid = uid;
72418 + uid_set[uid_used].expires = expires;
72419 + uid_used++;
72420 +
72421 + gr_insertsort();
72422 +
72423 + return;
72424 +}
72425 +
72426 +void
72427 +gr_remove_uid(const unsigned short loc)
72428 +{
72429 + unsigned short i;
72430 +
72431 + for (i = loc + 1; i < uid_used; i++)
72432 + uid_set[i - 1] = uid_set[i];
72433 +
72434 + uid_used--;
72435 +
72436 + return;
72437 +}
72438 +
72439 +int
72440 +gr_check_crash_uid(const kuid_t kuid)
72441 +{
72442 + int loc;
72443 + int ret = 0;
72444 + uid_t uid;
72445 +
72446 + if (unlikely(!gr_acl_is_enabled()))
72447 + return 0;
72448 +
72449 + uid = GR_GLOBAL_UID(kuid);
72450 +
72451 + spin_lock(&gr_uid_lock);
72452 + loc = gr_find_uid(uid);
72453 +
72454 + if (loc < 0)
72455 + goto out_unlock;
72456 +
72457 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
72458 + gr_remove_uid(loc);
72459 + else
72460 + ret = 1;
72461 +
72462 +out_unlock:
72463 + spin_unlock(&gr_uid_lock);
72464 + return ret;
72465 +}
72466 +
72467 +static __inline__ int
72468 +proc_is_setxid(const struct cred *cred)
72469 +{
72470 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72471 + !uid_eq(cred->uid, cred->fsuid))
72472 + return 1;
72473 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72474 + !gid_eq(cred->gid, cred->fsgid))
72475 + return 1;
72476 +
72477 + return 0;
72478 +}
72479 +
72480 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
72481 +
72482 +void
72483 +gr_handle_crash(struct task_struct *task, const int sig)
72484 +{
72485 + struct acl_subject_label *curr;
72486 + struct task_struct *tsk, *tsk2;
72487 + const struct cred *cred;
72488 + const struct cred *cred2;
72489 +
72490 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72491 + return;
72492 +
72493 + if (unlikely(!gr_acl_is_enabled()))
72494 + return;
72495 +
72496 + curr = task->acl;
72497 +
72498 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
72499 + return;
72500 +
72501 + if (time_before_eq(curr->expires, get_seconds())) {
72502 + curr->expires = 0;
72503 + curr->crashes = 0;
72504 + }
72505 +
72506 + curr->crashes++;
72507 +
72508 + if (!curr->expires)
72509 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72510 +
72511 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72512 + time_after(curr->expires, get_seconds())) {
72513 + rcu_read_lock();
72514 + cred = __task_cred(task);
72515 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72516 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72517 + spin_lock(&gr_uid_lock);
72518 + gr_insert_uid(cred->uid, curr->expires);
72519 + spin_unlock(&gr_uid_lock);
72520 + curr->expires = 0;
72521 + curr->crashes = 0;
72522 + read_lock(&tasklist_lock);
72523 + do_each_thread(tsk2, tsk) {
72524 + cred2 = __task_cred(tsk);
72525 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
72526 + gr_fake_force_sig(SIGKILL, tsk);
72527 + } while_each_thread(tsk2, tsk);
72528 + read_unlock(&tasklist_lock);
72529 + } else {
72530 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72531 + read_lock(&tasklist_lock);
72532 + read_lock(&grsec_exec_file_lock);
72533 + do_each_thread(tsk2, tsk) {
72534 + if (likely(tsk != task)) {
72535 + // if this thread has the same subject as the one that triggered
72536 + // RES_CRASH and it's the same binary, kill it
72537 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72538 + gr_fake_force_sig(SIGKILL, tsk);
72539 + }
72540 + } while_each_thread(tsk2, tsk);
72541 + read_unlock(&grsec_exec_file_lock);
72542 + read_unlock(&tasklist_lock);
72543 + }
72544 + rcu_read_unlock();
72545 + }
72546 +
72547 + return;
72548 +}
72549 +
72550 +int
72551 +gr_check_crash_exec(const struct file *filp)
72552 +{
72553 + struct acl_subject_label *curr;
72554 +
72555 + if (unlikely(!gr_acl_is_enabled()))
72556 + return 0;
72557 +
72558 + read_lock(&gr_inode_lock);
72559 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72560 + __get_dev(filp->f_path.dentry),
72561 + current->role);
72562 + read_unlock(&gr_inode_lock);
72563 +
72564 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72565 + (!curr->crashes && !curr->expires))
72566 + return 0;
72567 +
72568 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72569 + time_after(curr->expires, get_seconds()))
72570 + return 1;
72571 + else if (time_before_eq(curr->expires, get_seconds())) {
72572 + curr->crashes = 0;
72573 + curr->expires = 0;
72574 + }
72575 +
72576 + return 0;
72577 +}
72578 +
72579 +void
72580 +gr_handle_alertkill(struct task_struct *task)
72581 +{
72582 + struct acl_subject_label *curracl;
72583 + __u32 curr_ip;
72584 + struct task_struct *p, *p2;
72585 +
72586 + if (unlikely(!gr_acl_is_enabled()))
72587 + return;
72588 +
72589 + curracl = task->acl;
72590 + curr_ip = task->signal->curr_ip;
72591 +
72592 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
72593 + read_lock(&tasklist_lock);
72594 + do_each_thread(p2, p) {
72595 + if (p->signal->curr_ip == curr_ip)
72596 + gr_fake_force_sig(SIGKILL, p);
72597 + } while_each_thread(p2, p);
72598 + read_unlock(&tasklist_lock);
72599 + } else if (curracl->mode & GR_KILLPROC)
72600 + gr_fake_force_sig(SIGKILL, task);
72601 +
72602 + return;
72603 +}
72604 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
72605 new file mode 100644
72606 index 0000000..98011b0
72607 --- /dev/null
72608 +++ b/grsecurity/gracl_shm.c
72609 @@ -0,0 +1,40 @@
72610 +#include <linux/kernel.h>
72611 +#include <linux/mm.h>
72612 +#include <linux/sched.h>
72613 +#include <linux/file.h>
72614 +#include <linux/ipc.h>
72615 +#include <linux/gracl.h>
72616 +#include <linux/grsecurity.h>
72617 +#include <linux/grinternal.h>
72618 +
72619 +int
72620 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72621 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72622 +{
72623 + struct task_struct *task;
72624 +
72625 + if (!gr_acl_is_enabled())
72626 + return 1;
72627 +
72628 + rcu_read_lock();
72629 + read_lock(&tasklist_lock);
72630 +
72631 + task = find_task_by_vpid(shm_cprid);
72632 +
72633 + if (unlikely(!task))
72634 + task = find_task_by_vpid(shm_lapid);
72635 +
72636 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
72637 + (task_pid_nr(task) == shm_lapid)) &&
72638 + (task->acl->mode & GR_PROTSHM) &&
72639 + (task->acl != current->acl))) {
72640 + read_unlock(&tasklist_lock);
72641 + rcu_read_unlock();
72642 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
72643 + return 0;
72644 + }
72645 + read_unlock(&tasklist_lock);
72646 + rcu_read_unlock();
72647 +
72648 + return 1;
72649 +}
72650 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
72651 new file mode 100644
72652 index 0000000..bc0be01
72653 --- /dev/null
72654 +++ b/grsecurity/grsec_chdir.c
72655 @@ -0,0 +1,19 @@
72656 +#include <linux/kernel.h>
72657 +#include <linux/sched.h>
72658 +#include <linux/fs.h>
72659 +#include <linux/file.h>
72660 +#include <linux/grsecurity.h>
72661 +#include <linux/grinternal.h>
72662 +
72663 +void
72664 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
72665 +{
72666 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72667 + if ((grsec_enable_chdir && grsec_enable_group &&
72668 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
72669 + !grsec_enable_group)) {
72670 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
72671 + }
72672 +#endif
72673 + return;
72674 +}
72675 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
72676 new file mode 100644
72677 index 0000000..651d6c2
72678 --- /dev/null
72679 +++ b/grsecurity/grsec_chroot.c
72680 @@ -0,0 +1,370 @@
72681 +#include <linux/kernel.h>
72682 +#include <linux/module.h>
72683 +#include <linux/sched.h>
72684 +#include <linux/file.h>
72685 +#include <linux/fs.h>
72686 +#include <linux/mount.h>
72687 +#include <linux/types.h>
72688 +#include "../fs/mount.h"
72689 +#include <linux/grsecurity.h>
72690 +#include <linux/grinternal.h>
72691 +
72692 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72693 +int gr_init_ran;
72694 +#endif
72695 +
72696 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
72697 +{
72698 +#ifdef CONFIG_GRKERNSEC
72699 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
72700 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
72701 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72702 + && gr_init_ran
72703 +#endif
72704 + )
72705 + task->gr_is_chrooted = 1;
72706 + else {
72707 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72708 + if (task_pid_nr(task) == 1 && !gr_init_ran)
72709 + gr_init_ran = 1;
72710 +#endif
72711 + task->gr_is_chrooted = 0;
72712 + }
72713 +
72714 + task->gr_chroot_dentry = path->dentry;
72715 +#endif
72716 + return;
72717 +}
72718 +
72719 +void gr_clear_chroot_entries(struct task_struct *task)
72720 +{
72721 +#ifdef CONFIG_GRKERNSEC
72722 + task->gr_is_chrooted = 0;
72723 + task->gr_chroot_dentry = NULL;
72724 +#endif
72725 + return;
72726 +}
72727 +
72728 +int
72729 +gr_handle_chroot_unix(const pid_t pid)
72730 +{
72731 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72732 + struct task_struct *p;
72733 +
72734 + if (unlikely(!grsec_enable_chroot_unix))
72735 + return 1;
72736 +
72737 + if (likely(!proc_is_chrooted(current)))
72738 + return 1;
72739 +
72740 + rcu_read_lock();
72741 + read_lock(&tasklist_lock);
72742 + p = find_task_by_vpid_unrestricted(pid);
72743 + if (unlikely(p && !have_same_root(current, p))) {
72744 + read_unlock(&tasklist_lock);
72745 + rcu_read_unlock();
72746 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
72747 + return 0;
72748 + }
72749 + read_unlock(&tasklist_lock);
72750 + rcu_read_unlock();
72751 +#endif
72752 + return 1;
72753 +}
72754 +
72755 +int
72756 +gr_handle_chroot_nice(void)
72757 +{
72758 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72759 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
72760 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
72761 + return -EPERM;
72762 + }
72763 +#endif
72764 + return 0;
72765 +}
72766 +
72767 +int
72768 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
72769 +{
72770 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72771 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
72772 + && proc_is_chrooted(current)) {
72773 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
72774 + return -EACCES;
72775 + }
72776 +#endif
72777 + return 0;
72778 +}
72779 +
72780 +int
72781 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72782 +{
72783 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72784 + struct task_struct *p;
72785 + int ret = 0;
72786 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72787 + return ret;
72788 +
72789 + read_lock(&tasklist_lock);
72790 + do_each_pid_task(pid, type, p) {
72791 + if (!have_same_root(current, p)) {
72792 + ret = 1;
72793 + goto out;
72794 + }
72795 + } while_each_pid_task(pid, type, p);
72796 +out:
72797 + read_unlock(&tasklist_lock);
72798 + return ret;
72799 +#endif
72800 + return 0;
72801 +}
72802 +
72803 +int
72804 +gr_pid_is_chrooted(struct task_struct *p)
72805 +{
72806 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72807 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
72808 + return 0;
72809 +
72810 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
72811 + !have_same_root(current, p)) {
72812 + return 1;
72813 + }
72814 +#endif
72815 + return 0;
72816 +}
72817 +
72818 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
72819 +
72820 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
72821 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
72822 +{
72823 + struct path path, currentroot;
72824 + int ret = 0;
72825 +
72826 + path.dentry = (struct dentry *)u_dentry;
72827 + path.mnt = (struct vfsmount *)u_mnt;
72828 + get_fs_root(current->fs, &currentroot);
72829 + if (path_is_under(&path, &currentroot))
72830 + ret = 1;
72831 + path_put(&currentroot);
72832 +
72833 + return ret;
72834 +}
72835 +#endif
72836 +
72837 +int
72838 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
72839 +{
72840 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72841 + if (!grsec_enable_chroot_fchdir)
72842 + return 1;
72843 +
72844 + if (!proc_is_chrooted(current))
72845 + return 1;
72846 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
72847 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
72848 + return 0;
72849 + }
72850 +#endif
72851 + return 1;
72852 +}
72853 +
72854 +int
72855 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72856 + const time_t shm_createtime)
72857 +{
72858 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72859 + struct task_struct *p;
72860 + time_t starttime;
72861 +
72862 + if (unlikely(!grsec_enable_chroot_shmat))
72863 + return 1;
72864 +
72865 + if (likely(!proc_is_chrooted(current)))
72866 + return 1;
72867 +
72868 + rcu_read_lock();
72869 + read_lock(&tasklist_lock);
72870 +
72871 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
72872 + starttime = p->start_time.tv_sec;
72873 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
72874 + if (have_same_root(current, p)) {
72875 + goto allow;
72876 + } else {
72877 + read_unlock(&tasklist_lock);
72878 + rcu_read_unlock();
72879 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72880 + return 0;
72881 + }
72882 + }
72883 + /* creator exited, pid reuse, fall through to next check */
72884 + }
72885 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
72886 + if (unlikely(!have_same_root(current, p))) {
72887 + read_unlock(&tasklist_lock);
72888 + rcu_read_unlock();
72889 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72890 + return 0;
72891 + }
72892 + }
72893 +
72894 +allow:
72895 + read_unlock(&tasklist_lock);
72896 + rcu_read_unlock();
72897 +#endif
72898 + return 1;
72899 +}
72900 +
72901 +void
72902 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
72903 +{
72904 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72905 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
72906 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
72907 +#endif
72908 + return;
72909 +}
72910 +
72911 +int
72912 +gr_handle_chroot_mknod(const struct dentry *dentry,
72913 + const struct vfsmount *mnt, const int mode)
72914 +{
72915 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72916 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
72917 + proc_is_chrooted(current)) {
72918 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
72919 + return -EPERM;
72920 + }
72921 +#endif
72922 + return 0;
72923 +}
72924 +
72925 +int
72926 +gr_handle_chroot_mount(const struct dentry *dentry,
72927 + const struct vfsmount *mnt, const char *dev_name)
72928 +{
72929 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72930 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
72931 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
72932 + return -EPERM;
72933 + }
72934 +#endif
72935 + return 0;
72936 +}
72937 +
72938 +int
72939 +gr_handle_chroot_pivot(void)
72940 +{
72941 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72942 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
72943 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
72944 + return -EPERM;
72945 + }
72946 +#endif
72947 + return 0;
72948 +}
72949 +
72950 +int
72951 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
72952 +{
72953 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72954 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
72955 + !gr_is_outside_chroot(dentry, mnt)) {
72956 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
72957 + return -EPERM;
72958 + }
72959 +#endif
72960 + return 0;
72961 +}
72962 +
72963 +extern const char *captab_log[];
72964 +extern int captab_log_entries;
72965 +
72966 +int
72967 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72968 +{
72969 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72970 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72971 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72972 + if (cap_raised(chroot_caps, cap)) {
72973 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
72974 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
72975 + }
72976 + return 0;
72977 + }
72978 + }
72979 +#endif
72980 + return 1;
72981 +}
72982 +
72983 +int
72984 +gr_chroot_is_capable(const int cap)
72985 +{
72986 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72987 + return gr_task_chroot_is_capable(current, current_cred(), cap);
72988 +#endif
72989 + return 1;
72990 +}
72991 +
72992 +int
72993 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
72994 +{
72995 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72996 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72997 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72998 + if (cap_raised(chroot_caps, cap)) {
72999 + return 0;
73000 + }
73001 + }
73002 +#endif
73003 + return 1;
73004 +}
73005 +
73006 +int
73007 +gr_chroot_is_capable_nolog(const int cap)
73008 +{
73009 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73010 + return gr_task_chroot_is_capable_nolog(current, cap);
73011 +#endif
73012 + return 1;
73013 +}
73014 +
73015 +int
73016 +gr_handle_chroot_sysctl(const int op)
73017 +{
73018 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73019 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73020 + proc_is_chrooted(current))
73021 + return -EACCES;
73022 +#endif
73023 + return 0;
73024 +}
73025 +
73026 +void
73027 +gr_handle_chroot_chdir(const struct path *path)
73028 +{
73029 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73030 + if (grsec_enable_chroot_chdir)
73031 + set_fs_pwd(current->fs, path);
73032 +#endif
73033 + return;
73034 +}
73035 +
73036 +int
73037 +gr_handle_chroot_chmod(const struct dentry *dentry,
73038 + const struct vfsmount *mnt, const int mode)
73039 +{
73040 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73041 + /* allow chmod +s on directories, but not files */
73042 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73043 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73044 + proc_is_chrooted(current)) {
73045 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73046 + return -EPERM;
73047 + }
73048 +#endif
73049 + return 0;
73050 +}
73051 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73052 new file mode 100644
73053 index 0000000..4d6fce8
73054 --- /dev/null
73055 +++ b/grsecurity/grsec_disabled.c
73056 @@ -0,0 +1,433 @@
73057 +#include <linux/kernel.h>
73058 +#include <linux/module.h>
73059 +#include <linux/sched.h>
73060 +#include <linux/file.h>
73061 +#include <linux/fs.h>
73062 +#include <linux/kdev_t.h>
73063 +#include <linux/net.h>
73064 +#include <linux/in.h>
73065 +#include <linux/ip.h>
73066 +#include <linux/skbuff.h>
73067 +#include <linux/sysctl.h>
73068 +
73069 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73070 +void
73071 +pax_set_initial_flags(struct linux_binprm *bprm)
73072 +{
73073 + return;
73074 +}
73075 +#endif
73076 +
73077 +#ifdef CONFIG_SYSCTL
73078 +__u32
73079 +gr_handle_sysctl(const struct ctl_table * table, const int op)
73080 +{
73081 + return 0;
73082 +}
73083 +#endif
73084 +
73085 +#ifdef CONFIG_TASKSTATS
73086 +int gr_is_taskstats_denied(int pid)
73087 +{
73088 + return 0;
73089 +}
73090 +#endif
73091 +
73092 +int
73093 +gr_acl_is_enabled(void)
73094 +{
73095 + return 0;
73096 +}
73097 +
73098 +void
73099 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73100 +{
73101 + return;
73102 +}
73103 +
73104 +int
73105 +gr_handle_rawio(const struct inode *inode)
73106 +{
73107 + return 0;
73108 +}
73109 +
73110 +void
73111 +gr_acl_handle_psacct(struct task_struct *task, const long code)
73112 +{
73113 + return;
73114 +}
73115 +
73116 +int
73117 +gr_handle_ptrace(struct task_struct *task, const long request)
73118 +{
73119 + return 0;
73120 +}
73121 +
73122 +int
73123 +gr_handle_proc_ptrace(struct task_struct *task)
73124 +{
73125 + return 0;
73126 +}
73127 +
73128 +int
73129 +gr_set_acls(const int type)
73130 +{
73131 + return 0;
73132 +}
73133 +
73134 +int
73135 +gr_check_hidden_task(const struct task_struct *tsk)
73136 +{
73137 + return 0;
73138 +}
73139 +
73140 +int
73141 +gr_check_protected_task(const struct task_struct *task)
73142 +{
73143 + return 0;
73144 +}
73145 +
73146 +int
73147 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73148 +{
73149 + return 0;
73150 +}
73151 +
73152 +void
73153 +gr_copy_label(struct task_struct *tsk)
73154 +{
73155 + return;
73156 +}
73157 +
73158 +void
73159 +gr_set_pax_flags(struct task_struct *task)
73160 +{
73161 + return;
73162 +}
73163 +
73164 +int
73165 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73166 + const int unsafe_share)
73167 +{
73168 + return 0;
73169 +}
73170 +
73171 +void
73172 +gr_handle_delete(const ino_t ino, const dev_t dev)
73173 +{
73174 + return;
73175 +}
73176 +
73177 +void
73178 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73179 +{
73180 + return;
73181 +}
73182 +
73183 +void
73184 +gr_handle_crash(struct task_struct *task, const int sig)
73185 +{
73186 + return;
73187 +}
73188 +
73189 +int
73190 +gr_check_crash_exec(const struct file *filp)
73191 +{
73192 + return 0;
73193 +}
73194 +
73195 +int
73196 +gr_check_crash_uid(const kuid_t uid)
73197 +{
73198 + return 0;
73199 +}
73200 +
73201 +void
73202 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73203 + struct dentry *old_dentry,
73204 + struct dentry *new_dentry,
73205 + struct vfsmount *mnt, const __u8 replace)
73206 +{
73207 + return;
73208 +}
73209 +
73210 +int
73211 +gr_search_socket(const int family, const int type, const int protocol)
73212 +{
73213 + return 1;
73214 +}
73215 +
73216 +int
73217 +gr_search_connectbind(const int mode, const struct socket *sock,
73218 + const struct sockaddr_in *addr)
73219 +{
73220 + return 0;
73221 +}
73222 +
73223 +void
73224 +gr_handle_alertkill(struct task_struct *task)
73225 +{
73226 + return;
73227 +}
73228 +
73229 +__u32
73230 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73231 +{
73232 + return 1;
73233 +}
73234 +
73235 +__u32
73236 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73237 + const struct vfsmount * mnt)
73238 +{
73239 + return 1;
73240 +}
73241 +
73242 +__u32
73243 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73244 + int acc_mode)
73245 +{
73246 + return 1;
73247 +}
73248 +
73249 +__u32
73250 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73251 +{
73252 + return 1;
73253 +}
73254 +
73255 +__u32
73256 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73257 +{
73258 + return 1;
73259 +}
73260 +
73261 +int
73262 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73263 + unsigned int *vm_flags)
73264 +{
73265 + return 1;
73266 +}
73267 +
73268 +__u32
73269 +gr_acl_handle_truncate(const struct dentry * dentry,
73270 + const struct vfsmount * mnt)
73271 +{
73272 + return 1;
73273 +}
73274 +
73275 +__u32
73276 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73277 +{
73278 + return 1;
73279 +}
73280 +
73281 +__u32
73282 +gr_acl_handle_access(const struct dentry * dentry,
73283 + const struct vfsmount * mnt, const int fmode)
73284 +{
73285 + return 1;
73286 +}
73287 +
73288 +__u32
73289 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73290 + umode_t *mode)
73291 +{
73292 + return 1;
73293 +}
73294 +
73295 +__u32
73296 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73297 +{
73298 + return 1;
73299 +}
73300 +
73301 +__u32
73302 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73303 +{
73304 + return 1;
73305 +}
73306 +
73307 +__u32
73308 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73309 +{
73310 + return 1;
73311 +}
73312 +
73313 +void
73314 +grsecurity_init(void)
73315 +{
73316 + return;
73317 +}
73318 +
73319 +umode_t gr_acl_umask(void)
73320 +{
73321 + return 0;
73322 +}
73323 +
73324 +__u32
73325 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73326 + const struct dentry * parent_dentry,
73327 + const struct vfsmount * parent_mnt,
73328 + const int mode)
73329 +{
73330 + return 1;
73331 +}
73332 +
73333 +__u32
73334 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
73335 + const struct dentry * parent_dentry,
73336 + const struct vfsmount * parent_mnt)
73337 +{
73338 + return 1;
73339 +}
73340 +
73341 +__u32
73342 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73343 + const struct dentry * parent_dentry,
73344 + const struct vfsmount * parent_mnt, const struct filename *from)
73345 +{
73346 + return 1;
73347 +}
73348 +
73349 +__u32
73350 +gr_acl_handle_link(const struct dentry * new_dentry,
73351 + const struct dentry * parent_dentry,
73352 + const struct vfsmount * parent_mnt,
73353 + const struct dentry * old_dentry,
73354 + const struct vfsmount * old_mnt, const struct filename *to)
73355 +{
73356 + return 1;
73357 +}
73358 +
73359 +int
73360 +gr_acl_handle_rename(const struct dentry *new_dentry,
73361 + const struct dentry *parent_dentry,
73362 + const struct vfsmount *parent_mnt,
73363 + const struct dentry *old_dentry,
73364 + const struct inode *old_parent_inode,
73365 + const struct vfsmount *old_mnt, const struct filename *newname)
73366 +{
73367 + return 0;
73368 +}
73369 +
73370 +int
73371 +gr_acl_handle_filldir(const struct file *file, const char *name,
73372 + const int namelen, const ino_t ino)
73373 +{
73374 + return 1;
73375 +}
73376 +
73377 +int
73378 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73379 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73380 +{
73381 + return 1;
73382 +}
73383 +
73384 +int
73385 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73386 +{
73387 + return 0;
73388 +}
73389 +
73390 +int
73391 +gr_search_accept(const struct socket *sock)
73392 +{
73393 + return 0;
73394 +}
73395 +
73396 +int
73397 +gr_search_listen(const struct socket *sock)
73398 +{
73399 + return 0;
73400 +}
73401 +
73402 +int
73403 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73404 +{
73405 + return 0;
73406 +}
73407 +
73408 +__u32
73409 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73410 +{
73411 + return 1;
73412 +}
73413 +
73414 +__u32
73415 +gr_acl_handle_creat(const struct dentry * dentry,
73416 + const struct dentry * p_dentry,
73417 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73418 + const int imode)
73419 +{
73420 + return 1;
73421 +}
73422 +
73423 +void
73424 +gr_acl_handle_exit(void)
73425 +{
73426 + return;
73427 +}
73428 +
73429 +int
73430 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73431 +{
73432 + return 1;
73433 +}
73434 +
73435 +void
73436 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
73437 +{
73438 + return;
73439 +}
73440 +
73441 +int
73442 +gr_acl_handle_procpidmem(const struct task_struct *task)
73443 +{
73444 + return 0;
73445 +}
73446 +
73447 +int
73448 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73449 +{
73450 + return 0;
73451 +}
73452 +
73453 +int
73454 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73455 +{
73456 + return 0;
73457 +}
73458 +
73459 +int
73460 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73461 +{
73462 + return 0;
73463 +}
73464 +
73465 +int
73466 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73467 +{
73468 + return 0;
73469 +}
73470 +
73471 +int gr_acl_enable_at_secure(void)
73472 +{
73473 + return 0;
73474 +}
73475 +
73476 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73477 +{
73478 + return dentry->d_sb->s_dev;
73479 +}
73480 +
73481 +void gr_put_exec_file(struct task_struct *task)
73482 +{
73483 + return;
73484 +}
73485 +
73486 +#ifdef CONFIG_SECURITY
73487 +EXPORT_SYMBOL_GPL(gr_check_user_change);
73488 +EXPORT_SYMBOL_GPL(gr_check_group_change);
73489 +#endif
73490 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73491 new file mode 100644
73492 index 0000000..f35f454
73493 --- /dev/null
73494 +++ b/grsecurity/grsec_exec.c
73495 @@ -0,0 +1,187 @@
73496 +#include <linux/kernel.h>
73497 +#include <linux/sched.h>
73498 +#include <linux/file.h>
73499 +#include <linux/binfmts.h>
73500 +#include <linux/fs.h>
73501 +#include <linux/types.h>
73502 +#include <linux/grdefs.h>
73503 +#include <linux/grsecurity.h>
73504 +#include <linux/grinternal.h>
73505 +#include <linux/capability.h>
73506 +#include <linux/module.h>
73507 +#include <linux/compat.h>
73508 +
73509 +#include <asm/uaccess.h>
73510 +
73511 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73512 +static char gr_exec_arg_buf[132];
73513 +static DEFINE_MUTEX(gr_exec_arg_mutex);
73514 +#endif
73515 +
73516 +struct user_arg_ptr {
73517 +#ifdef CONFIG_COMPAT
73518 + bool is_compat;
73519 +#endif
73520 + union {
73521 + const char __user *const __user *native;
73522 +#ifdef CONFIG_COMPAT
73523 + const compat_uptr_t __user *compat;
73524 +#endif
73525 + } ptr;
73526 +};
73527 +
73528 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73529 +
73530 +void
73531 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73532 +{
73533 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73534 + char *grarg = gr_exec_arg_buf;
73535 + unsigned int i, x, execlen = 0;
73536 + char c;
73537 +
73538 + if (!((grsec_enable_execlog && grsec_enable_group &&
73539 + in_group_p(grsec_audit_gid))
73540 + || (grsec_enable_execlog && !grsec_enable_group)))
73541 + return;
73542 +
73543 + mutex_lock(&gr_exec_arg_mutex);
73544 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
73545 +
73546 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
73547 + const char __user *p;
73548 + unsigned int len;
73549 +
73550 + p = get_user_arg_ptr(argv, i);
73551 + if (IS_ERR(p))
73552 + goto log;
73553 +
73554 + len = strnlen_user(p, 128 - execlen);
73555 + if (len > 128 - execlen)
73556 + len = 128 - execlen;
73557 + else if (len > 0)
73558 + len--;
73559 + if (copy_from_user(grarg + execlen, p, len))
73560 + goto log;
73561 +
73562 + /* rewrite unprintable characters */
73563 + for (x = 0; x < len; x++) {
73564 + c = *(grarg + execlen + x);
73565 + if (c < 32 || c > 126)
73566 + *(grarg + execlen + x) = ' ';
73567 + }
73568 +
73569 + execlen += len;
73570 + *(grarg + execlen) = ' ';
73571 + *(grarg + execlen + 1) = '\0';
73572 + execlen++;
73573 + }
73574 +
73575 + log:
73576 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73577 + bprm->file->f_path.mnt, grarg);
73578 + mutex_unlock(&gr_exec_arg_mutex);
73579 +#endif
73580 + return;
73581 +}
73582 +
73583 +#ifdef CONFIG_GRKERNSEC
73584 +extern int gr_acl_is_capable(const int cap);
73585 +extern int gr_acl_is_capable_nolog(const int cap);
73586 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73587 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
73588 +extern int gr_chroot_is_capable(const int cap);
73589 +extern int gr_chroot_is_capable_nolog(const int cap);
73590 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73591 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
73592 +#endif
73593 +
73594 +const char *captab_log[] = {
73595 + "CAP_CHOWN",
73596 + "CAP_DAC_OVERRIDE",
73597 + "CAP_DAC_READ_SEARCH",
73598 + "CAP_FOWNER",
73599 + "CAP_FSETID",
73600 + "CAP_KILL",
73601 + "CAP_SETGID",
73602 + "CAP_SETUID",
73603 + "CAP_SETPCAP",
73604 + "CAP_LINUX_IMMUTABLE",
73605 + "CAP_NET_BIND_SERVICE",
73606 + "CAP_NET_BROADCAST",
73607 + "CAP_NET_ADMIN",
73608 + "CAP_NET_RAW",
73609 + "CAP_IPC_LOCK",
73610 + "CAP_IPC_OWNER",
73611 + "CAP_SYS_MODULE",
73612 + "CAP_SYS_RAWIO",
73613 + "CAP_SYS_CHROOT",
73614 + "CAP_SYS_PTRACE",
73615 + "CAP_SYS_PACCT",
73616 + "CAP_SYS_ADMIN",
73617 + "CAP_SYS_BOOT",
73618 + "CAP_SYS_NICE",
73619 + "CAP_SYS_RESOURCE",
73620 + "CAP_SYS_TIME",
73621 + "CAP_SYS_TTY_CONFIG",
73622 + "CAP_MKNOD",
73623 + "CAP_LEASE",
73624 + "CAP_AUDIT_WRITE",
73625 + "CAP_AUDIT_CONTROL",
73626 + "CAP_SETFCAP",
73627 + "CAP_MAC_OVERRIDE",
73628 + "CAP_MAC_ADMIN",
73629 + "CAP_SYSLOG",
73630 + "CAP_WAKE_ALARM"
73631 +};
73632 +
73633 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
73634 +
73635 +int gr_is_capable(const int cap)
73636 +{
73637 +#ifdef CONFIG_GRKERNSEC
73638 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
73639 + return 1;
73640 + return 0;
73641 +#else
73642 + return 1;
73643 +#endif
73644 +}
73645 +
73646 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73647 +{
73648 +#ifdef CONFIG_GRKERNSEC
73649 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
73650 + return 1;
73651 + return 0;
73652 +#else
73653 + return 1;
73654 +#endif
73655 +}
73656 +
73657 +int gr_is_capable_nolog(const int cap)
73658 +{
73659 +#ifdef CONFIG_GRKERNSEC
73660 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
73661 + return 1;
73662 + return 0;
73663 +#else
73664 + return 1;
73665 +#endif
73666 +}
73667 +
73668 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
73669 +{
73670 +#ifdef CONFIG_GRKERNSEC
73671 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
73672 + return 1;
73673 + return 0;
73674 +#else
73675 + return 1;
73676 +#endif
73677 +}
73678 +
73679 +EXPORT_SYMBOL_GPL(gr_is_capable);
73680 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
73681 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
73682 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
73683 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
73684 new file mode 100644
73685 index 0000000..06cc6ea
73686 --- /dev/null
73687 +++ b/grsecurity/grsec_fifo.c
73688 @@ -0,0 +1,24 @@
73689 +#include <linux/kernel.h>
73690 +#include <linux/sched.h>
73691 +#include <linux/fs.h>
73692 +#include <linux/file.h>
73693 +#include <linux/grinternal.h>
73694 +
73695 +int
73696 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
73697 + const struct dentry *dir, const int flag, const int acc_mode)
73698 +{
73699 +#ifdef CONFIG_GRKERNSEC_FIFO
73700 + const struct cred *cred = current_cred();
73701 +
73702 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
73703 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
73704 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
73705 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
73706 + if (!inode_permission(dentry->d_inode, acc_mode))
73707 + 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));
73708 + return -EACCES;
73709 + }
73710 +#endif
73711 + return 0;
73712 +}
73713 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
73714 new file mode 100644
73715 index 0000000..8ca18bf
73716 --- /dev/null
73717 +++ b/grsecurity/grsec_fork.c
73718 @@ -0,0 +1,23 @@
73719 +#include <linux/kernel.h>
73720 +#include <linux/sched.h>
73721 +#include <linux/grsecurity.h>
73722 +#include <linux/grinternal.h>
73723 +#include <linux/errno.h>
73724 +
73725 +void
73726 +gr_log_forkfail(const int retval)
73727 +{
73728 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73729 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
73730 + switch (retval) {
73731 + case -EAGAIN:
73732 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
73733 + break;
73734 + case -ENOMEM:
73735 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
73736 + break;
73737 + }
73738 + }
73739 +#endif
73740 + return;
73741 +}
73742 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
73743 new file mode 100644
73744 index 0000000..ae6c028
73745 --- /dev/null
73746 +++ b/grsecurity/grsec_init.c
73747 @@ -0,0 +1,272 @@
73748 +#include <linux/kernel.h>
73749 +#include <linux/sched.h>
73750 +#include <linux/mm.h>
73751 +#include <linux/gracl.h>
73752 +#include <linux/slab.h>
73753 +#include <linux/vmalloc.h>
73754 +#include <linux/percpu.h>
73755 +#include <linux/module.h>
73756 +
73757 +int grsec_enable_ptrace_readexec;
73758 +int grsec_enable_setxid;
73759 +int grsec_enable_symlinkown;
73760 +kgid_t grsec_symlinkown_gid;
73761 +int grsec_enable_brute;
73762 +int grsec_enable_link;
73763 +int grsec_enable_dmesg;
73764 +int grsec_enable_harden_ptrace;
73765 +int grsec_enable_harden_ipc;
73766 +int grsec_enable_fifo;
73767 +int grsec_enable_execlog;
73768 +int grsec_enable_signal;
73769 +int grsec_enable_forkfail;
73770 +int grsec_enable_audit_ptrace;
73771 +int grsec_enable_time;
73772 +int grsec_enable_group;
73773 +kgid_t grsec_audit_gid;
73774 +int grsec_enable_chdir;
73775 +int grsec_enable_mount;
73776 +int grsec_enable_rofs;
73777 +int grsec_deny_new_usb;
73778 +int grsec_enable_chroot_findtask;
73779 +int grsec_enable_chroot_mount;
73780 +int grsec_enable_chroot_shmat;
73781 +int grsec_enable_chroot_fchdir;
73782 +int grsec_enable_chroot_double;
73783 +int grsec_enable_chroot_pivot;
73784 +int grsec_enable_chroot_chdir;
73785 +int grsec_enable_chroot_chmod;
73786 +int grsec_enable_chroot_mknod;
73787 +int grsec_enable_chroot_nice;
73788 +int grsec_enable_chroot_execlog;
73789 +int grsec_enable_chroot_caps;
73790 +int grsec_enable_chroot_sysctl;
73791 +int grsec_enable_chroot_unix;
73792 +int grsec_enable_tpe;
73793 +kgid_t grsec_tpe_gid;
73794 +int grsec_enable_blackhole;
73795 +#ifdef CONFIG_IPV6_MODULE
73796 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
73797 +#endif
73798 +int grsec_lastack_retries;
73799 +int grsec_enable_tpe_all;
73800 +int grsec_enable_tpe_invert;
73801 +int grsec_enable_socket_all;
73802 +kgid_t grsec_socket_all_gid;
73803 +int grsec_enable_socket_client;
73804 +kgid_t grsec_socket_client_gid;
73805 +int grsec_enable_socket_server;
73806 +kgid_t grsec_socket_server_gid;
73807 +int grsec_resource_logging;
73808 +int grsec_disable_privio;
73809 +int grsec_enable_log_rwxmaps;
73810 +int grsec_lock;
73811 +
73812 +DEFINE_SPINLOCK(grsec_alert_lock);
73813 +unsigned long grsec_alert_wtime = 0;
73814 +unsigned long grsec_alert_fyet = 0;
73815 +
73816 +DEFINE_SPINLOCK(grsec_audit_lock);
73817 +
73818 +DEFINE_RWLOCK(grsec_exec_file_lock);
73819 +
73820 +char *gr_shared_page[4];
73821 +
73822 +char *gr_alert_log_fmt;
73823 +char *gr_audit_log_fmt;
73824 +char *gr_alert_log_buf;
73825 +char *gr_audit_log_buf;
73826 +
73827 +void __init
73828 +grsecurity_init(void)
73829 +{
73830 + int j;
73831 + /* create the per-cpu shared pages */
73832 +
73833 +#ifdef CONFIG_X86
73834 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
73835 +#endif
73836 +
73837 + for (j = 0; j < 4; j++) {
73838 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
73839 + if (gr_shared_page[j] == NULL) {
73840 + panic("Unable to allocate grsecurity shared page");
73841 + return;
73842 + }
73843 + }
73844 +
73845 + /* allocate log buffers */
73846 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
73847 + if (!gr_alert_log_fmt) {
73848 + panic("Unable to allocate grsecurity alert log format buffer");
73849 + return;
73850 + }
73851 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
73852 + if (!gr_audit_log_fmt) {
73853 + panic("Unable to allocate grsecurity audit log format buffer");
73854 + return;
73855 + }
73856 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73857 + if (!gr_alert_log_buf) {
73858 + panic("Unable to allocate grsecurity alert log buffer");
73859 + return;
73860 + }
73861 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73862 + if (!gr_audit_log_buf) {
73863 + panic("Unable to allocate grsecurity audit log buffer");
73864 + return;
73865 + }
73866 +
73867 +#ifdef CONFIG_GRKERNSEC_IO
73868 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
73869 + grsec_disable_privio = 1;
73870 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73871 + grsec_disable_privio = 1;
73872 +#else
73873 + grsec_disable_privio = 0;
73874 +#endif
73875 +#endif
73876 +
73877 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73878 + /* for backward compatibility, tpe_invert always defaults to on if
73879 + enabled in the kernel
73880 + */
73881 + grsec_enable_tpe_invert = 1;
73882 +#endif
73883 +
73884 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73885 +#ifndef CONFIG_GRKERNSEC_SYSCTL
73886 + grsec_lock = 1;
73887 +#endif
73888 +
73889 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73890 + grsec_enable_log_rwxmaps = 1;
73891 +#endif
73892 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
73893 + grsec_enable_group = 1;
73894 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
73895 +#endif
73896 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73897 + grsec_enable_ptrace_readexec = 1;
73898 +#endif
73899 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73900 + grsec_enable_chdir = 1;
73901 +#endif
73902 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73903 + grsec_enable_harden_ptrace = 1;
73904 +#endif
73905 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73906 + grsec_enable_harden_ipc = 1;
73907 +#endif
73908 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73909 + grsec_enable_mount = 1;
73910 +#endif
73911 +#ifdef CONFIG_GRKERNSEC_LINK
73912 + grsec_enable_link = 1;
73913 +#endif
73914 +#ifdef CONFIG_GRKERNSEC_BRUTE
73915 + grsec_enable_brute = 1;
73916 +#endif
73917 +#ifdef CONFIG_GRKERNSEC_DMESG
73918 + grsec_enable_dmesg = 1;
73919 +#endif
73920 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73921 + grsec_enable_blackhole = 1;
73922 + grsec_lastack_retries = 4;
73923 +#endif
73924 +#ifdef CONFIG_GRKERNSEC_FIFO
73925 + grsec_enable_fifo = 1;
73926 +#endif
73927 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73928 + grsec_enable_execlog = 1;
73929 +#endif
73930 +#ifdef CONFIG_GRKERNSEC_SETXID
73931 + grsec_enable_setxid = 1;
73932 +#endif
73933 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73934 + grsec_enable_signal = 1;
73935 +#endif
73936 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73937 + grsec_enable_forkfail = 1;
73938 +#endif
73939 +#ifdef CONFIG_GRKERNSEC_TIME
73940 + grsec_enable_time = 1;
73941 +#endif
73942 +#ifdef CONFIG_GRKERNSEC_RESLOG
73943 + grsec_resource_logging = 1;
73944 +#endif
73945 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73946 + grsec_enable_chroot_findtask = 1;
73947 +#endif
73948 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73949 + grsec_enable_chroot_unix = 1;
73950 +#endif
73951 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73952 + grsec_enable_chroot_mount = 1;
73953 +#endif
73954 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73955 + grsec_enable_chroot_fchdir = 1;
73956 +#endif
73957 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73958 + grsec_enable_chroot_shmat = 1;
73959 +#endif
73960 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73961 + grsec_enable_audit_ptrace = 1;
73962 +#endif
73963 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73964 + grsec_enable_chroot_double = 1;
73965 +#endif
73966 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73967 + grsec_enable_chroot_pivot = 1;
73968 +#endif
73969 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73970 + grsec_enable_chroot_chdir = 1;
73971 +#endif
73972 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73973 + grsec_enable_chroot_chmod = 1;
73974 +#endif
73975 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73976 + grsec_enable_chroot_mknod = 1;
73977 +#endif
73978 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73979 + grsec_enable_chroot_nice = 1;
73980 +#endif
73981 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73982 + grsec_enable_chroot_execlog = 1;
73983 +#endif
73984 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73985 + grsec_enable_chroot_caps = 1;
73986 +#endif
73987 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73988 + grsec_enable_chroot_sysctl = 1;
73989 +#endif
73990 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73991 + grsec_enable_symlinkown = 1;
73992 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
73993 +#endif
73994 +#ifdef CONFIG_GRKERNSEC_TPE
73995 + grsec_enable_tpe = 1;
73996 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
73997 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
73998 + grsec_enable_tpe_all = 1;
73999 +#endif
74000 +#endif
74001 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74002 + grsec_enable_socket_all = 1;
74003 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74004 +#endif
74005 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74006 + grsec_enable_socket_client = 1;
74007 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74008 +#endif
74009 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74010 + grsec_enable_socket_server = 1;
74011 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74012 +#endif
74013 +#endif
74014 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74015 + grsec_deny_new_usb = 1;
74016 +#endif
74017 +
74018 + return;
74019 +}
74020 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74021 new file mode 100644
74022 index 0000000..1773300
74023 --- /dev/null
74024 +++ b/grsecurity/grsec_ipc.c
74025 @@ -0,0 +1,48 @@
74026 +#include <linux/kernel.h>
74027 +#include <linux/mm.h>
74028 +#include <linux/sched.h>
74029 +#include <linux/file.h>
74030 +#include <linux/ipc.h>
74031 +#include <linux/ipc_namespace.h>
74032 +#include <linux/grsecurity.h>
74033 +#include <linux/grinternal.h>
74034 +
74035 +int
74036 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74037 +{
74038 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74039 + int write;
74040 + int orig_granted_mode;
74041 + kuid_t euid;
74042 + kgid_t egid;
74043 +
74044 + if (!grsec_enable_harden_ipc)
74045 + return 1;
74046 +
74047 + euid = current_euid();
74048 + egid = current_egid();
74049 +
74050 + write = requested_mode & 00002;
74051 + orig_granted_mode = ipcp->mode;
74052 +
74053 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74054 + orig_granted_mode >>= 6;
74055 + else {
74056 + /* if likely wrong permissions, lock to user */
74057 + if (orig_granted_mode & 0007)
74058 + orig_granted_mode = 0;
74059 + /* otherwise do a egid-only check */
74060 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74061 + orig_granted_mode >>= 3;
74062 + /* otherwise, no access */
74063 + else
74064 + orig_granted_mode = 0;
74065 + }
74066 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74067 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74068 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74069 + return 0;
74070 + }
74071 +#endif
74072 + return 1;
74073 +}
74074 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74075 new file mode 100644
74076 index 0000000..5e05e20
74077 --- /dev/null
74078 +++ b/grsecurity/grsec_link.c
74079 @@ -0,0 +1,58 @@
74080 +#include <linux/kernel.h>
74081 +#include <linux/sched.h>
74082 +#include <linux/fs.h>
74083 +#include <linux/file.h>
74084 +#include <linux/grinternal.h>
74085 +
74086 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74087 +{
74088 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74089 + const struct inode *link_inode = link->dentry->d_inode;
74090 +
74091 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74092 + /* ignore root-owned links, e.g. /proc/self */
74093 + gr_is_global_nonroot(link_inode->i_uid) && target &&
74094 + !uid_eq(link_inode->i_uid, target->i_uid)) {
74095 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74096 + return 1;
74097 + }
74098 +#endif
74099 + return 0;
74100 +}
74101 +
74102 +int
74103 +gr_handle_follow_link(const struct inode *parent,
74104 + const struct inode *inode,
74105 + const struct dentry *dentry, const struct vfsmount *mnt)
74106 +{
74107 +#ifdef CONFIG_GRKERNSEC_LINK
74108 + const struct cred *cred = current_cred();
74109 +
74110 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74111 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74112 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74113 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74114 + return -EACCES;
74115 + }
74116 +#endif
74117 + return 0;
74118 +}
74119 +
74120 +int
74121 +gr_handle_hardlink(const struct dentry *dentry,
74122 + const struct vfsmount *mnt,
74123 + struct inode *inode, const int mode, const struct filename *to)
74124 +{
74125 +#ifdef CONFIG_GRKERNSEC_LINK
74126 + const struct cred *cred = current_cred();
74127 +
74128 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74129 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74130 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74131 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74132 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74133 + return -EPERM;
74134 + }
74135 +#endif
74136 + return 0;
74137 +}
74138 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74139 new file mode 100644
74140 index 0000000..dbe0a6b
74141 --- /dev/null
74142 +++ b/grsecurity/grsec_log.c
74143 @@ -0,0 +1,341 @@
74144 +#include <linux/kernel.h>
74145 +#include <linux/sched.h>
74146 +#include <linux/file.h>
74147 +#include <linux/tty.h>
74148 +#include <linux/fs.h>
74149 +#include <linux/mm.h>
74150 +#include <linux/grinternal.h>
74151 +
74152 +#ifdef CONFIG_TREE_PREEMPT_RCU
74153 +#define DISABLE_PREEMPT() preempt_disable()
74154 +#define ENABLE_PREEMPT() preempt_enable()
74155 +#else
74156 +#define DISABLE_PREEMPT()
74157 +#define ENABLE_PREEMPT()
74158 +#endif
74159 +
74160 +#define BEGIN_LOCKS(x) \
74161 + DISABLE_PREEMPT(); \
74162 + rcu_read_lock(); \
74163 + read_lock(&tasklist_lock); \
74164 + read_lock(&grsec_exec_file_lock); \
74165 + if (x != GR_DO_AUDIT) \
74166 + spin_lock(&grsec_alert_lock); \
74167 + else \
74168 + spin_lock(&grsec_audit_lock)
74169 +
74170 +#define END_LOCKS(x) \
74171 + if (x != GR_DO_AUDIT) \
74172 + spin_unlock(&grsec_alert_lock); \
74173 + else \
74174 + spin_unlock(&grsec_audit_lock); \
74175 + read_unlock(&grsec_exec_file_lock); \
74176 + read_unlock(&tasklist_lock); \
74177 + rcu_read_unlock(); \
74178 + ENABLE_PREEMPT(); \
74179 + if (x == GR_DONT_AUDIT) \
74180 + gr_handle_alertkill(current)
74181 +
74182 +enum {
74183 + FLOODING,
74184 + NO_FLOODING
74185 +};
74186 +
74187 +extern char *gr_alert_log_fmt;
74188 +extern char *gr_audit_log_fmt;
74189 +extern char *gr_alert_log_buf;
74190 +extern char *gr_audit_log_buf;
74191 +
74192 +static int gr_log_start(int audit)
74193 +{
74194 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74195 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74196 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74197 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74198 + unsigned long curr_secs = get_seconds();
74199 +
74200 + if (audit == GR_DO_AUDIT)
74201 + goto set_fmt;
74202 +
74203 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74204 + grsec_alert_wtime = curr_secs;
74205 + grsec_alert_fyet = 0;
74206 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74207 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74208 + grsec_alert_fyet++;
74209 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74210 + grsec_alert_wtime = curr_secs;
74211 + grsec_alert_fyet++;
74212 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74213 + return FLOODING;
74214 + }
74215 + else return FLOODING;
74216 +
74217 +set_fmt:
74218 +#endif
74219 + memset(buf, 0, PAGE_SIZE);
74220 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
74221 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74222 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74223 + } else if (current->signal->curr_ip) {
74224 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74225 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74226 + } else if (gr_acl_is_enabled()) {
74227 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74228 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74229 + } else {
74230 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
74231 + strcpy(buf, fmt);
74232 + }
74233 +
74234 + return NO_FLOODING;
74235 +}
74236 +
74237 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74238 + __attribute__ ((format (printf, 2, 0)));
74239 +
74240 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74241 +{
74242 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74243 + unsigned int len = strlen(buf);
74244 +
74245 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74246 +
74247 + return;
74248 +}
74249 +
74250 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74251 + __attribute__ ((format (printf, 2, 3)));
74252 +
74253 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74254 +{
74255 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74256 + unsigned int len = strlen(buf);
74257 + va_list ap;
74258 +
74259 + va_start(ap, msg);
74260 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74261 + va_end(ap);
74262 +
74263 + return;
74264 +}
74265 +
74266 +static void gr_log_end(int audit, int append_default)
74267 +{
74268 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74269 + if (append_default) {
74270 + struct task_struct *task = current;
74271 + struct task_struct *parent = task->real_parent;
74272 + const struct cred *cred = __task_cred(task);
74273 + const struct cred *pcred = __task_cred(parent);
74274 + unsigned int len = strlen(buf);
74275 +
74276 + 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));
74277 + }
74278 +
74279 + printk("%s\n", buf);
74280 +
74281 + return;
74282 +}
74283 +
74284 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74285 +{
74286 + int logtype;
74287 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74288 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74289 + void *voidptr = NULL;
74290 + int num1 = 0, num2 = 0;
74291 + unsigned long ulong1 = 0, ulong2 = 0;
74292 + struct dentry *dentry = NULL;
74293 + struct vfsmount *mnt = NULL;
74294 + struct file *file = NULL;
74295 + struct task_struct *task = NULL;
74296 + struct vm_area_struct *vma = NULL;
74297 + const struct cred *cred, *pcred;
74298 + va_list ap;
74299 +
74300 + BEGIN_LOCKS(audit);
74301 + logtype = gr_log_start(audit);
74302 + if (logtype == FLOODING) {
74303 + END_LOCKS(audit);
74304 + return;
74305 + }
74306 + va_start(ap, argtypes);
74307 + switch (argtypes) {
74308 + case GR_TTYSNIFF:
74309 + task = va_arg(ap, struct task_struct *);
74310 + 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));
74311 + break;
74312 + case GR_SYSCTL_HIDDEN:
74313 + str1 = va_arg(ap, char *);
74314 + gr_log_middle_varargs(audit, msg, result, str1);
74315 + break;
74316 + case GR_RBAC:
74317 + dentry = va_arg(ap, struct dentry *);
74318 + mnt = va_arg(ap, struct vfsmount *);
74319 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74320 + break;
74321 + case GR_RBAC_STR:
74322 + dentry = va_arg(ap, struct dentry *);
74323 + mnt = va_arg(ap, struct vfsmount *);
74324 + str1 = va_arg(ap, char *);
74325 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74326 + break;
74327 + case GR_STR_RBAC:
74328 + str1 = va_arg(ap, char *);
74329 + dentry = va_arg(ap, struct dentry *);
74330 + mnt = va_arg(ap, struct vfsmount *);
74331 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74332 + break;
74333 + case GR_RBAC_MODE2:
74334 + dentry = va_arg(ap, struct dentry *);
74335 + mnt = va_arg(ap, struct vfsmount *);
74336 + str1 = va_arg(ap, char *);
74337 + str2 = va_arg(ap, char *);
74338 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74339 + break;
74340 + case GR_RBAC_MODE3:
74341 + dentry = va_arg(ap, struct dentry *);
74342 + mnt = va_arg(ap, struct vfsmount *);
74343 + str1 = va_arg(ap, char *);
74344 + str2 = va_arg(ap, char *);
74345 + str3 = va_arg(ap, char *);
74346 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74347 + break;
74348 + case GR_FILENAME:
74349 + dentry = va_arg(ap, struct dentry *);
74350 + mnt = va_arg(ap, struct vfsmount *);
74351 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74352 + break;
74353 + case GR_STR_FILENAME:
74354 + str1 = va_arg(ap, char *);
74355 + dentry = va_arg(ap, struct dentry *);
74356 + mnt = va_arg(ap, struct vfsmount *);
74357 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74358 + break;
74359 + case GR_FILENAME_STR:
74360 + dentry = va_arg(ap, struct dentry *);
74361 + mnt = va_arg(ap, struct vfsmount *);
74362 + str1 = va_arg(ap, char *);
74363 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74364 + break;
74365 + case GR_FILENAME_TWO_INT:
74366 + dentry = va_arg(ap, struct dentry *);
74367 + mnt = va_arg(ap, struct vfsmount *);
74368 + num1 = va_arg(ap, int);
74369 + num2 = va_arg(ap, int);
74370 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74371 + break;
74372 + case GR_FILENAME_TWO_INT_STR:
74373 + dentry = va_arg(ap, struct dentry *);
74374 + mnt = va_arg(ap, struct vfsmount *);
74375 + num1 = va_arg(ap, int);
74376 + num2 = va_arg(ap, int);
74377 + str1 = va_arg(ap, char *);
74378 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74379 + break;
74380 + case GR_TEXTREL:
74381 + file = va_arg(ap, struct file *);
74382 + ulong1 = va_arg(ap, unsigned long);
74383 + ulong2 = va_arg(ap, unsigned long);
74384 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74385 + break;
74386 + case GR_PTRACE:
74387 + task = va_arg(ap, struct task_struct *);
74388 + 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));
74389 + break;
74390 + case GR_RESOURCE:
74391 + task = va_arg(ap, struct task_struct *);
74392 + cred = __task_cred(task);
74393 + pcred = __task_cred(task->real_parent);
74394 + ulong1 = va_arg(ap, unsigned long);
74395 + str1 = va_arg(ap, char *);
74396 + ulong2 = va_arg(ap, unsigned long);
74397 + 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));
74398 + break;
74399 + case GR_CAP:
74400 + task = va_arg(ap, struct task_struct *);
74401 + cred = __task_cred(task);
74402 + pcred = __task_cred(task->real_parent);
74403 + str1 = va_arg(ap, char *);
74404 + 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));
74405 + break;
74406 + case GR_SIG:
74407 + str1 = va_arg(ap, char *);
74408 + voidptr = va_arg(ap, void *);
74409 + gr_log_middle_varargs(audit, msg, str1, voidptr);
74410 + break;
74411 + case GR_SIG2:
74412 + task = va_arg(ap, struct task_struct *);
74413 + cred = __task_cred(task);
74414 + pcred = __task_cred(task->real_parent);
74415 + num1 = va_arg(ap, int);
74416 + 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));
74417 + break;
74418 + case GR_CRASH1:
74419 + task = va_arg(ap, struct task_struct *);
74420 + cred = __task_cred(task);
74421 + pcred = __task_cred(task->real_parent);
74422 + ulong1 = va_arg(ap, unsigned long);
74423 + 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);
74424 + break;
74425 + case GR_CRASH2:
74426 + task = va_arg(ap, struct task_struct *);
74427 + cred = __task_cred(task);
74428 + pcred = __task_cred(task->real_parent);
74429 + ulong1 = va_arg(ap, unsigned long);
74430 + 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);
74431 + break;
74432 + case GR_RWXMAP:
74433 + file = va_arg(ap, struct file *);
74434 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74435 + break;
74436 + case GR_RWXMAPVMA:
74437 + vma = va_arg(ap, struct vm_area_struct *);
74438 + if (vma->vm_file)
74439 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74440 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74441 + str1 = "<stack>";
74442 + else if (vma->vm_start <= current->mm->brk &&
74443 + vma->vm_end >= current->mm->start_brk)
74444 + str1 = "<heap>";
74445 + else
74446 + str1 = "<anonymous mapping>";
74447 + gr_log_middle_varargs(audit, msg, str1);
74448 + break;
74449 + case GR_PSACCT:
74450 + {
74451 + unsigned int wday, cday;
74452 + __u8 whr, chr;
74453 + __u8 wmin, cmin;
74454 + __u8 wsec, csec;
74455 + char cur_tty[64] = { 0 };
74456 + char parent_tty[64] = { 0 };
74457 +
74458 + task = va_arg(ap, struct task_struct *);
74459 + wday = va_arg(ap, unsigned int);
74460 + cday = va_arg(ap, unsigned int);
74461 + whr = va_arg(ap, int);
74462 + chr = va_arg(ap, int);
74463 + wmin = va_arg(ap, int);
74464 + cmin = va_arg(ap, int);
74465 + wsec = va_arg(ap, int);
74466 + csec = va_arg(ap, int);
74467 + ulong1 = va_arg(ap, unsigned long);
74468 + cred = __task_cred(task);
74469 + pcred = __task_cred(task->real_parent);
74470 +
74471 + 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));
74472 + }
74473 + break;
74474 + default:
74475 + gr_log_middle(audit, msg, ap);
74476 + }
74477 + va_end(ap);
74478 + // these don't need DEFAULTSECARGS printed on the end
74479 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74480 + gr_log_end(audit, 0);
74481 + else
74482 + gr_log_end(audit, 1);
74483 + END_LOCKS(audit);
74484 +}
74485 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74486 new file mode 100644
74487 index 0000000..0e39d8c
74488 --- /dev/null
74489 +++ b/grsecurity/grsec_mem.c
74490 @@ -0,0 +1,48 @@
74491 +#include <linux/kernel.h>
74492 +#include <linux/sched.h>
74493 +#include <linux/mm.h>
74494 +#include <linux/mman.h>
74495 +#include <linux/module.h>
74496 +#include <linux/grinternal.h>
74497 +
74498 +void gr_handle_msr_write(void)
74499 +{
74500 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74501 + return;
74502 +}
74503 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74504 +
74505 +void
74506 +gr_handle_ioperm(void)
74507 +{
74508 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74509 + return;
74510 +}
74511 +
74512 +void
74513 +gr_handle_iopl(void)
74514 +{
74515 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74516 + return;
74517 +}
74518 +
74519 +void
74520 +gr_handle_mem_readwrite(u64 from, u64 to)
74521 +{
74522 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74523 + return;
74524 +}
74525 +
74526 +void
74527 +gr_handle_vm86(void)
74528 +{
74529 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74530 + return;
74531 +}
74532 +
74533 +void
74534 +gr_log_badprocpid(const char *entry)
74535 +{
74536 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74537 + return;
74538 +}
74539 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74540 new file mode 100644
74541 index 0000000..cd9e124
74542 --- /dev/null
74543 +++ b/grsecurity/grsec_mount.c
74544 @@ -0,0 +1,65 @@
74545 +#include <linux/kernel.h>
74546 +#include <linux/sched.h>
74547 +#include <linux/mount.h>
74548 +#include <linux/major.h>
74549 +#include <linux/grsecurity.h>
74550 +#include <linux/grinternal.h>
74551 +
74552 +void
74553 +gr_log_remount(const char *devname, const int retval)
74554 +{
74555 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74556 + if (grsec_enable_mount && (retval >= 0))
74557 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74558 +#endif
74559 + return;
74560 +}
74561 +
74562 +void
74563 +gr_log_unmount(const char *devname, const int retval)
74564 +{
74565 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74566 + if (grsec_enable_mount && (retval >= 0))
74567 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74568 +#endif
74569 + return;
74570 +}
74571 +
74572 +void
74573 +gr_log_mount(const char *from, const char *to, const int retval)
74574 +{
74575 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74576 + if (grsec_enable_mount && (retval >= 0))
74577 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74578 +#endif
74579 + return;
74580 +}
74581 +
74582 +int
74583 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74584 +{
74585 +#ifdef CONFIG_GRKERNSEC_ROFS
74586 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74587 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
74588 + return -EPERM;
74589 + } else
74590 + return 0;
74591 +#endif
74592 + return 0;
74593 +}
74594 +
74595 +int
74596 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
74597 +{
74598 +#ifdef CONFIG_GRKERNSEC_ROFS
74599 + struct inode *inode = dentry->d_inode;
74600 +
74601 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
74602 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
74603 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
74604 + return -EPERM;
74605 + } else
74606 + return 0;
74607 +#endif
74608 + return 0;
74609 +}
74610 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
74611 new file mode 100644
74612 index 0000000..6ee9d50
74613 --- /dev/null
74614 +++ b/grsecurity/grsec_pax.c
74615 @@ -0,0 +1,45 @@
74616 +#include <linux/kernel.h>
74617 +#include <linux/sched.h>
74618 +#include <linux/mm.h>
74619 +#include <linux/file.h>
74620 +#include <linux/grinternal.h>
74621 +#include <linux/grsecurity.h>
74622 +
74623 +void
74624 +gr_log_textrel(struct vm_area_struct * vma)
74625 +{
74626 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74627 + if (grsec_enable_log_rwxmaps)
74628 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
74629 +#endif
74630 + return;
74631 +}
74632 +
74633 +void gr_log_ptgnustack(struct file *file)
74634 +{
74635 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74636 + if (grsec_enable_log_rwxmaps)
74637 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
74638 +#endif
74639 + return;
74640 +}
74641 +
74642 +void
74643 +gr_log_rwxmmap(struct file *file)
74644 +{
74645 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74646 + if (grsec_enable_log_rwxmaps)
74647 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
74648 +#endif
74649 + return;
74650 +}
74651 +
74652 +void
74653 +gr_log_rwxmprotect(struct vm_area_struct *vma)
74654 +{
74655 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74656 + if (grsec_enable_log_rwxmaps)
74657 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
74658 +#endif
74659 + return;
74660 +}
74661 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
74662 new file mode 100644
74663 index 0000000..f7f29aa
74664 --- /dev/null
74665 +++ b/grsecurity/grsec_ptrace.c
74666 @@ -0,0 +1,30 @@
74667 +#include <linux/kernel.h>
74668 +#include <linux/sched.h>
74669 +#include <linux/grinternal.h>
74670 +#include <linux/security.h>
74671 +
74672 +void
74673 +gr_audit_ptrace(struct task_struct *task)
74674 +{
74675 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74676 + if (grsec_enable_audit_ptrace)
74677 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
74678 +#endif
74679 + return;
74680 +}
74681 +
74682 +int
74683 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
74684 +{
74685 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74686 + const struct dentry *dentry = file->f_path.dentry;
74687 + const struct vfsmount *mnt = file->f_path.mnt;
74688 +
74689 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
74690 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
74691 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
74692 + return -EACCES;
74693 + }
74694 +#endif
74695 + return 0;
74696 +}
74697 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
74698 new file mode 100644
74699 index 0000000..3860c7e
74700 --- /dev/null
74701 +++ b/grsecurity/grsec_sig.c
74702 @@ -0,0 +1,236 @@
74703 +#include <linux/kernel.h>
74704 +#include <linux/sched.h>
74705 +#include <linux/fs.h>
74706 +#include <linux/delay.h>
74707 +#include <linux/grsecurity.h>
74708 +#include <linux/grinternal.h>
74709 +#include <linux/hardirq.h>
74710 +
74711 +char *signames[] = {
74712 + [SIGSEGV] = "Segmentation fault",
74713 + [SIGILL] = "Illegal instruction",
74714 + [SIGABRT] = "Abort",
74715 + [SIGBUS] = "Invalid alignment/Bus error"
74716 +};
74717 +
74718 +void
74719 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
74720 +{
74721 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74722 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
74723 + (sig == SIGABRT) || (sig == SIGBUS))) {
74724 + if (task_pid_nr(t) == task_pid_nr(current)) {
74725 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
74726 + } else {
74727 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
74728 + }
74729 + }
74730 +#endif
74731 + return;
74732 +}
74733 +
74734 +int
74735 +gr_handle_signal(const struct task_struct *p, const int sig)
74736 +{
74737 +#ifdef CONFIG_GRKERNSEC
74738 + /* ignore the 0 signal for protected task checks */
74739 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
74740 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
74741 + return -EPERM;
74742 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
74743 + return -EPERM;
74744 + }
74745 +#endif
74746 + return 0;
74747 +}
74748 +
74749 +#ifdef CONFIG_GRKERNSEC
74750 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
74751 +
74752 +int gr_fake_force_sig(int sig, struct task_struct *t)
74753 +{
74754 + unsigned long int flags;
74755 + int ret, blocked, ignored;
74756 + struct k_sigaction *action;
74757 +
74758 + spin_lock_irqsave(&t->sighand->siglock, flags);
74759 + action = &t->sighand->action[sig-1];
74760 + ignored = action->sa.sa_handler == SIG_IGN;
74761 + blocked = sigismember(&t->blocked, sig);
74762 + if (blocked || ignored) {
74763 + action->sa.sa_handler = SIG_DFL;
74764 + if (blocked) {
74765 + sigdelset(&t->blocked, sig);
74766 + recalc_sigpending_and_wake(t);
74767 + }
74768 + }
74769 + if (action->sa.sa_handler == SIG_DFL)
74770 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
74771 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
74772 +
74773 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
74774 +
74775 + return ret;
74776 +}
74777 +#endif
74778 +
74779 +#define GR_USER_BAN_TIME (15 * 60)
74780 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
74781 +
74782 +void gr_handle_brute_attach(int dumpable)
74783 +{
74784 +#ifdef CONFIG_GRKERNSEC_BRUTE
74785 + struct task_struct *p = current;
74786 + kuid_t uid = GLOBAL_ROOT_UID;
74787 + int daemon = 0;
74788 +
74789 + if (!grsec_enable_brute)
74790 + return;
74791 +
74792 + rcu_read_lock();
74793 + read_lock(&tasklist_lock);
74794 + read_lock(&grsec_exec_file_lock);
74795 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74796 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
74797 + p->real_parent->brute = 1;
74798 + daemon = 1;
74799 + } else {
74800 + const struct cred *cred = __task_cred(p), *cred2;
74801 + struct task_struct *tsk, *tsk2;
74802 +
74803 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
74804 + struct user_struct *user;
74805 +
74806 + uid = cred->uid;
74807 +
74808 + /* this is put upon execution past expiration */
74809 + user = find_user(uid);
74810 + if (user == NULL)
74811 + goto unlock;
74812 + user->suid_banned = 1;
74813 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
74814 + if (user->suid_ban_expires == ~0UL)
74815 + user->suid_ban_expires--;
74816 +
74817 + /* only kill other threads of the same binary, from the same user */
74818 + do_each_thread(tsk2, tsk) {
74819 + cred2 = __task_cred(tsk);
74820 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
74821 + gr_fake_force_sig(SIGKILL, tsk);
74822 + } while_each_thread(tsk2, tsk);
74823 + }
74824 + }
74825 +unlock:
74826 + read_unlock(&grsec_exec_file_lock);
74827 + read_unlock(&tasklist_lock);
74828 + rcu_read_unlock();
74829 +
74830 + if (gr_is_global_nonroot(uid))
74831 + 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);
74832 + else if (daemon)
74833 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
74834 +
74835 +#endif
74836 + return;
74837 +}
74838 +
74839 +void gr_handle_brute_check(void)
74840 +{
74841 +#ifdef CONFIG_GRKERNSEC_BRUTE
74842 + struct task_struct *p = current;
74843 +
74844 + if (unlikely(p->brute)) {
74845 + if (!grsec_enable_brute)
74846 + p->brute = 0;
74847 + else if (time_before(get_seconds(), p->brute_expires))
74848 + msleep(30 * 1000);
74849 + }
74850 +#endif
74851 + return;
74852 +}
74853 +
74854 +void gr_handle_kernel_exploit(void)
74855 +{
74856 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74857 + const struct cred *cred;
74858 + struct task_struct *tsk, *tsk2;
74859 + struct user_struct *user;
74860 + kuid_t uid;
74861 +
74862 + if (in_irq() || in_serving_softirq() || in_nmi())
74863 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
74864 +
74865 + uid = current_uid();
74866 +
74867 + if (gr_is_global_root(uid))
74868 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
74869 + else {
74870 + /* kill all the processes of this user, hold a reference
74871 + to their creds struct, and prevent them from creating
74872 + another process until system reset
74873 + */
74874 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
74875 + GR_GLOBAL_UID(uid));
74876 + /* we intentionally leak this ref */
74877 + user = get_uid(current->cred->user);
74878 + if (user)
74879 + user->kernel_banned = 1;
74880 +
74881 + /* kill all processes of this user */
74882 + read_lock(&tasklist_lock);
74883 + do_each_thread(tsk2, tsk) {
74884 + cred = __task_cred(tsk);
74885 + if (uid_eq(cred->uid, uid))
74886 + gr_fake_force_sig(SIGKILL, tsk);
74887 + } while_each_thread(tsk2, tsk);
74888 + read_unlock(&tasklist_lock);
74889 + }
74890 +#endif
74891 +}
74892 +
74893 +#ifdef CONFIG_GRKERNSEC_BRUTE
74894 +static bool suid_ban_expired(struct user_struct *user)
74895 +{
74896 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
74897 + user->suid_banned = 0;
74898 + user->suid_ban_expires = 0;
74899 + free_uid(user);
74900 + return true;
74901 + }
74902 +
74903 + return false;
74904 +}
74905 +#endif
74906 +
74907 +int gr_process_kernel_exec_ban(void)
74908 +{
74909 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74910 + if (unlikely(current->cred->user->kernel_banned))
74911 + return -EPERM;
74912 +#endif
74913 + return 0;
74914 +}
74915 +
74916 +int gr_process_kernel_setuid_ban(struct user_struct *user)
74917 +{
74918 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74919 + if (unlikely(user->kernel_banned))
74920 + gr_fake_force_sig(SIGKILL, current);
74921 +#endif
74922 + return 0;
74923 +}
74924 +
74925 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
74926 +{
74927 +#ifdef CONFIG_GRKERNSEC_BRUTE
74928 + struct user_struct *user = current->cred->user;
74929 + if (unlikely(user->suid_banned)) {
74930 + if (suid_ban_expired(user))
74931 + return 0;
74932 + /* disallow execution of suid binaries only */
74933 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
74934 + return -EPERM;
74935 + }
74936 +#endif
74937 + return 0;
74938 +}
74939 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
74940 new file mode 100644
74941 index 0000000..c0aef3a
74942 --- /dev/null
74943 +++ b/grsecurity/grsec_sock.c
74944 @@ -0,0 +1,244 @@
74945 +#include <linux/kernel.h>
74946 +#include <linux/module.h>
74947 +#include <linux/sched.h>
74948 +#include <linux/file.h>
74949 +#include <linux/net.h>
74950 +#include <linux/in.h>
74951 +#include <linux/ip.h>
74952 +#include <net/sock.h>
74953 +#include <net/inet_sock.h>
74954 +#include <linux/grsecurity.h>
74955 +#include <linux/grinternal.h>
74956 +#include <linux/gracl.h>
74957 +
74958 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
74959 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
74960 +
74961 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
74962 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
74963 +
74964 +#ifdef CONFIG_UNIX_MODULE
74965 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
74966 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
74967 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
74968 +EXPORT_SYMBOL_GPL(gr_handle_create);
74969 +#endif
74970 +
74971 +#ifdef CONFIG_GRKERNSEC
74972 +#define gr_conn_table_size 32749
74973 +struct conn_table_entry {
74974 + struct conn_table_entry *next;
74975 + struct signal_struct *sig;
74976 +};
74977 +
74978 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
74979 +DEFINE_SPINLOCK(gr_conn_table_lock);
74980 +
74981 +extern const char * gr_socktype_to_name(unsigned char type);
74982 +extern const char * gr_proto_to_name(unsigned char proto);
74983 +extern const char * gr_sockfamily_to_name(unsigned char family);
74984 +
74985 +static __inline__ int
74986 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
74987 +{
74988 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
74989 +}
74990 +
74991 +static __inline__ int
74992 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
74993 + __u16 sport, __u16 dport)
74994 +{
74995 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
74996 + sig->gr_sport == sport && sig->gr_dport == dport))
74997 + return 1;
74998 + else
74999 + return 0;
75000 +}
75001 +
75002 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75003 +{
75004 + struct conn_table_entry **match;
75005 + unsigned int index;
75006 +
75007 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75008 + sig->gr_sport, sig->gr_dport,
75009 + gr_conn_table_size);
75010 +
75011 + newent->sig = sig;
75012 +
75013 + match = &gr_conn_table[index];
75014 + newent->next = *match;
75015 + *match = newent;
75016 +
75017 + return;
75018 +}
75019 +
75020 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75021 +{
75022 + struct conn_table_entry *match, *last = NULL;
75023 + unsigned int index;
75024 +
75025 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75026 + sig->gr_sport, sig->gr_dport,
75027 + gr_conn_table_size);
75028 +
75029 + match = gr_conn_table[index];
75030 + while (match && !conn_match(match->sig,
75031 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75032 + sig->gr_dport)) {
75033 + last = match;
75034 + match = match->next;
75035 + }
75036 +
75037 + if (match) {
75038 + if (last)
75039 + last->next = match->next;
75040 + else
75041 + gr_conn_table[index] = NULL;
75042 + kfree(match);
75043 + }
75044 +
75045 + return;
75046 +}
75047 +
75048 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75049 + __u16 sport, __u16 dport)
75050 +{
75051 + struct conn_table_entry *match;
75052 + unsigned int index;
75053 +
75054 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75055 +
75056 + match = gr_conn_table[index];
75057 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75058 + match = match->next;
75059 +
75060 + if (match)
75061 + return match->sig;
75062 + else
75063 + return NULL;
75064 +}
75065 +
75066 +#endif
75067 +
75068 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75069 +{
75070 +#ifdef CONFIG_GRKERNSEC
75071 + struct signal_struct *sig = task->signal;
75072 + struct conn_table_entry *newent;
75073 +
75074 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75075 + if (newent == NULL)
75076 + return;
75077 + /* no bh lock needed since we are called with bh disabled */
75078 + spin_lock(&gr_conn_table_lock);
75079 + gr_del_task_from_ip_table_nolock(sig);
75080 + sig->gr_saddr = inet->inet_rcv_saddr;
75081 + sig->gr_daddr = inet->inet_daddr;
75082 + sig->gr_sport = inet->inet_sport;
75083 + sig->gr_dport = inet->inet_dport;
75084 + gr_add_to_task_ip_table_nolock(sig, newent);
75085 + spin_unlock(&gr_conn_table_lock);
75086 +#endif
75087 + return;
75088 +}
75089 +
75090 +void gr_del_task_from_ip_table(struct task_struct *task)
75091 +{
75092 +#ifdef CONFIG_GRKERNSEC
75093 + spin_lock_bh(&gr_conn_table_lock);
75094 + gr_del_task_from_ip_table_nolock(task->signal);
75095 + spin_unlock_bh(&gr_conn_table_lock);
75096 +#endif
75097 + return;
75098 +}
75099 +
75100 +void
75101 +gr_attach_curr_ip(const struct sock *sk)
75102 +{
75103 +#ifdef CONFIG_GRKERNSEC
75104 + struct signal_struct *p, *set;
75105 + const struct inet_sock *inet = inet_sk(sk);
75106 +
75107 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75108 + return;
75109 +
75110 + set = current->signal;
75111 +
75112 + spin_lock_bh(&gr_conn_table_lock);
75113 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75114 + inet->inet_dport, inet->inet_sport);
75115 + if (unlikely(p != NULL)) {
75116 + set->curr_ip = p->curr_ip;
75117 + set->used_accept = 1;
75118 + gr_del_task_from_ip_table_nolock(p);
75119 + spin_unlock_bh(&gr_conn_table_lock);
75120 + return;
75121 + }
75122 + spin_unlock_bh(&gr_conn_table_lock);
75123 +
75124 + set->curr_ip = inet->inet_daddr;
75125 + set->used_accept = 1;
75126 +#endif
75127 + return;
75128 +}
75129 +
75130 +int
75131 +gr_handle_sock_all(const int family, const int type, const int protocol)
75132 +{
75133 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75134 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75135 + (family != AF_UNIX)) {
75136 + if (family == AF_INET)
75137 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75138 + else
75139 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75140 + return -EACCES;
75141 + }
75142 +#endif
75143 + return 0;
75144 +}
75145 +
75146 +int
75147 +gr_handle_sock_server(const struct sockaddr *sck)
75148 +{
75149 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75150 + if (grsec_enable_socket_server &&
75151 + in_group_p(grsec_socket_server_gid) &&
75152 + sck && (sck->sa_family != AF_UNIX) &&
75153 + (sck->sa_family != AF_LOCAL)) {
75154 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75155 + return -EACCES;
75156 + }
75157 +#endif
75158 + return 0;
75159 +}
75160 +
75161 +int
75162 +gr_handle_sock_server_other(const struct sock *sck)
75163 +{
75164 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75165 + if (grsec_enable_socket_server &&
75166 + in_group_p(grsec_socket_server_gid) &&
75167 + sck && (sck->sk_family != AF_UNIX) &&
75168 + (sck->sk_family != AF_LOCAL)) {
75169 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75170 + return -EACCES;
75171 + }
75172 +#endif
75173 + return 0;
75174 +}
75175 +
75176 +int
75177 +gr_handle_sock_client(const struct sockaddr *sck)
75178 +{
75179 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75180 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75181 + sck && (sck->sa_family != AF_UNIX) &&
75182 + (sck->sa_family != AF_LOCAL)) {
75183 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75184 + return -EACCES;
75185 + }
75186 +#endif
75187 + return 0;
75188 +}
75189 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75190 new file mode 100644
75191 index 0000000..8159888
75192 --- /dev/null
75193 +++ b/grsecurity/grsec_sysctl.c
75194 @@ -0,0 +1,479 @@
75195 +#include <linux/kernel.h>
75196 +#include <linux/sched.h>
75197 +#include <linux/sysctl.h>
75198 +#include <linux/grsecurity.h>
75199 +#include <linux/grinternal.h>
75200 +
75201 +int
75202 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75203 +{
75204 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75205 + if (dirname == NULL || name == NULL)
75206 + return 0;
75207 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75208 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75209 + return -EACCES;
75210 + }
75211 +#endif
75212 + return 0;
75213 +}
75214 +
75215 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75216 +static int __maybe_unused __read_only one = 1;
75217 +#endif
75218 +
75219 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75220 + defined(CONFIG_GRKERNSEC_DENYUSB)
75221 +struct ctl_table grsecurity_table[] = {
75222 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75223 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75224 +#ifdef CONFIG_GRKERNSEC_IO
75225 + {
75226 + .procname = "disable_priv_io",
75227 + .data = &grsec_disable_privio,
75228 + .maxlen = sizeof(int),
75229 + .mode = 0600,
75230 + .proc_handler = &proc_dointvec,
75231 + },
75232 +#endif
75233 +#endif
75234 +#ifdef CONFIG_GRKERNSEC_LINK
75235 + {
75236 + .procname = "linking_restrictions",
75237 + .data = &grsec_enable_link,
75238 + .maxlen = sizeof(int),
75239 + .mode = 0600,
75240 + .proc_handler = &proc_dointvec,
75241 + },
75242 +#endif
75243 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75244 + {
75245 + .procname = "enforce_symlinksifowner",
75246 + .data = &grsec_enable_symlinkown,
75247 + .maxlen = sizeof(int),
75248 + .mode = 0600,
75249 + .proc_handler = &proc_dointvec,
75250 + },
75251 + {
75252 + .procname = "symlinkown_gid",
75253 + .data = &grsec_symlinkown_gid,
75254 + .maxlen = sizeof(int),
75255 + .mode = 0600,
75256 + .proc_handler = &proc_dointvec,
75257 + },
75258 +#endif
75259 +#ifdef CONFIG_GRKERNSEC_BRUTE
75260 + {
75261 + .procname = "deter_bruteforce",
75262 + .data = &grsec_enable_brute,
75263 + .maxlen = sizeof(int),
75264 + .mode = 0600,
75265 + .proc_handler = &proc_dointvec,
75266 + },
75267 +#endif
75268 +#ifdef CONFIG_GRKERNSEC_FIFO
75269 + {
75270 + .procname = "fifo_restrictions",
75271 + .data = &grsec_enable_fifo,
75272 + .maxlen = sizeof(int),
75273 + .mode = 0600,
75274 + .proc_handler = &proc_dointvec,
75275 + },
75276 +#endif
75277 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75278 + {
75279 + .procname = "ptrace_readexec",
75280 + .data = &grsec_enable_ptrace_readexec,
75281 + .maxlen = sizeof(int),
75282 + .mode = 0600,
75283 + .proc_handler = &proc_dointvec,
75284 + },
75285 +#endif
75286 +#ifdef CONFIG_GRKERNSEC_SETXID
75287 + {
75288 + .procname = "consistent_setxid",
75289 + .data = &grsec_enable_setxid,
75290 + .maxlen = sizeof(int),
75291 + .mode = 0600,
75292 + .proc_handler = &proc_dointvec,
75293 + },
75294 +#endif
75295 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75296 + {
75297 + .procname = "ip_blackhole",
75298 + .data = &grsec_enable_blackhole,
75299 + .maxlen = sizeof(int),
75300 + .mode = 0600,
75301 + .proc_handler = &proc_dointvec,
75302 + },
75303 + {
75304 + .procname = "lastack_retries",
75305 + .data = &grsec_lastack_retries,
75306 + .maxlen = sizeof(int),
75307 + .mode = 0600,
75308 + .proc_handler = &proc_dointvec,
75309 + },
75310 +#endif
75311 +#ifdef CONFIG_GRKERNSEC_EXECLOG
75312 + {
75313 + .procname = "exec_logging",
75314 + .data = &grsec_enable_execlog,
75315 + .maxlen = sizeof(int),
75316 + .mode = 0600,
75317 + .proc_handler = &proc_dointvec,
75318 + },
75319 +#endif
75320 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75321 + {
75322 + .procname = "rwxmap_logging",
75323 + .data = &grsec_enable_log_rwxmaps,
75324 + .maxlen = sizeof(int),
75325 + .mode = 0600,
75326 + .proc_handler = &proc_dointvec,
75327 + },
75328 +#endif
75329 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75330 + {
75331 + .procname = "signal_logging",
75332 + .data = &grsec_enable_signal,
75333 + .maxlen = sizeof(int),
75334 + .mode = 0600,
75335 + .proc_handler = &proc_dointvec,
75336 + },
75337 +#endif
75338 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
75339 + {
75340 + .procname = "forkfail_logging",
75341 + .data = &grsec_enable_forkfail,
75342 + .maxlen = sizeof(int),
75343 + .mode = 0600,
75344 + .proc_handler = &proc_dointvec,
75345 + },
75346 +#endif
75347 +#ifdef CONFIG_GRKERNSEC_TIME
75348 + {
75349 + .procname = "timechange_logging",
75350 + .data = &grsec_enable_time,
75351 + .maxlen = sizeof(int),
75352 + .mode = 0600,
75353 + .proc_handler = &proc_dointvec,
75354 + },
75355 +#endif
75356 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75357 + {
75358 + .procname = "chroot_deny_shmat",
75359 + .data = &grsec_enable_chroot_shmat,
75360 + .maxlen = sizeof(int),
75361 + .mode = 0600,
75362 + .proc_handler = &proc_dointvec,
75363 + },
75364 +#endif
75365 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75366 + {
75367 + .procname = "chroot_deny_unix",
75368 + .data = &grsec_enable_chroot_unix,
75369 + .maxlen = sizeof(int),
75370 + .mode = 0600,
75371 + .proc_handler = &proc_dointvec,
75372 + },
75373 +#endif
75374 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75375 + {
75376 + .procname = "chroot_deny_mount",
75377 + .data = &grsec_enable_chroot_mount,
75378 + .maxlen = sizeof(int),
75379 + .mode = 0600,
75380 + .proc_handler = &proc_dointvec,
75381 + },
75382 +#endif
75383 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75384 + {
75385 + .procname = "chroot_deny_fchdir",
75386 + .data = &grsec_enable_chroot_fchdir,
75387 + .maxlen = sizeof(int),
75388 + .mode = 0600,
75389 + .proc_handler = &proc_dointvec,
75390 + },
75391 +#endif
75392 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75393 + {
75394 + .procname = "chroot_deny_chroot",
75395 + .data = &grsec_enable_chroot_double,
75396 + .maxlen = sizeof(int),
75397 + .mode = 0600,
75398 + .proc_handler = &proc_dointvec,
75399 + },
75400 +#endif
75401 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75402 + {
75403 + .procname = "chroot_deny_pivot",
75404 + .data = &grsec_enable_chroot_pivot,
75405 + .maxlen = sizeof(int),
75406 + .mode = 0600,
75407 + .proc_handler = &proc_dointvec,
75408 + },
75409 +#endif
75410 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75411 + {
75412 + .procname = "chroot_enforce_chdir",
75413 + .data = &grsec_enable_chroot_chdir,
75414 + .maxlen = sizeof(int),
75415 + .mode = 0600,
75416 + .proc_handler = &proc_dointvec,
75417 + },
75418 +#endif
75419 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75420 + {
75421 + .procname = "chroot_deny_chmod",
75422 + .data = &grsec_enable_chroot_chmod,
75423 + .maxlen = sizeof(int),
75424 + .mode = 0600,
75425 + .proc_handler = &proc_dointvec,
75426 + },
75427 +#endif
75428 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75429 + {
75430 + .procname = "chroot_deny_mknod",
75431 + .data = &grsec_enable_chroot_mknod,
75432 + .maxlen = sizeof(int),
75433 + .mode = 0600,
75434 + .proc_handler = &proc_dointvec,
75435 + },
75436 +#endif
75437 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75438 + {
75439 + .procname = "chroot_restrict_nice",
75440 + .data = &grsec_enable_chroot_nice,
75441 + .maxlen = sizeof(int),
75442 + .mode = 0600,
75443 + .proc_handler = &proc_dointvec,
75444 + },
75445 +#endif
75446 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75447 + {
75448 + .procname = "chroot_execlog",
75449 + .data = &grsec_enable_chroot_execlog,
75450 + .maxlen = sizeof(int),
75451 + .mode = 0600,
75452 + .proc_handler = &proc_dointvec,
75453 + },
75454 +#endif
75455 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75456 + {
75457 + .procname = "chroot_caps",
75458 + .data = &grsec_enable_chroot_caps,
75459 + .maxlen = sizeof(int),
75460 + .mode = 0600,
75461 + .proc_handler = &proc_dointvec,
75462 + },
75463 +#endif
75464 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75465 + {
75466 + .procname = "chroot_deny_sysctl",
75467 + .data = &grsec_enable_chroot_sysctl,
75468 + .maxlen = sizeof(int),
75469 + .mode = 0600,
75470 + .proc_handler = &proc_dointvec,
75471 + },
75472 +#endif
75473 +#ifdef CONFIG_GRKERNSEC_TPE
75474 + {
75475 + .procname = "tpe",
75476 + .data = &grsec_enable_tpe,
75477 + .maxlen = sizeof(int),
75478 + .mode = 0600,
75479 + .proc_handler = &proc_dointvec,
75480 + },
75481 + {
75482 + .procname = "tpe_gid",
75483 + .data = &grsec_tpe_gid,
75484 + .maxlen = sizeof(int),
75485 + .mode = 0600,
75486 + .proc_handler = &proc_dointvec,
75487 + },
75488 +#endif
75489 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75490 + {
75491 + .procname = "tpe_invert",
75492 + .data = &grsec_enable_tpe_invert,
75493 + .maxlen = sizeof(int),
75494 + .mode = 0600,
75495 + .proc_handler = &proc_dointvec,
75496 + },
75497 +#endif
75498 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75499 + {
75500 + .procname = "tpe_restrict_all",
75501 + .data = &grsec_enable_tpe_all,
75502 + .maxlen = sizeof(int),
75503 + .mode = 0600,
75504 + .proc_handler = &proc_dointvec,
75505 + },
75506 +#endif
75507 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75508 + {
75509 + .procname = "socket_all",
75510 + .data = &grsec_enable_socket_all,
75511 + .maxlen = sizeof(int),
75512 + .mode = 0600,
75513 + .proc_handler = &proc_dointvec,
75514 + },
75515 + {
75516 + .procname = "socket_all_gid",
75517 + .data = &grsec_socket_all_gid,
75518 + .maxlen = sizeof(int),
75519 + .mode = 0600,
75520 + .proc_handler = &proc_dointvec,
75521 + },
75522 +#endif
75523 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75524 + {
75525 + .procname = "socket_client",
75526 + .data = &grsec_enable_socket_client,
75527 + .maxlen = sizeof(int),
75528 + .mode = 0600,
75529 + .proc_handler = &proc_dointvec,
75530 + },
75531 + {
75532 + .procname = "socket_client_gid",
75533 + .data = &grsec_socket_client_gid,
75534 + .maxlen = sizeof(int),
75535 + .mode = 0600,
75536 + .proc_handler = &proc_dointvec,
75537 + },
75538 +#endif
75539 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75540 + {
75541 + .procname = "socket_server",
75542 + .data = &grsec_enable_socket_server,
75543 + .maxlen = sizeof(int),
75544 + .mode = 0600,
75545 + .proc_handler = &proc_dointvec,
75546 + },
75547 + {
75548 + .procname = "socket_server_gid",
75549 + .data = &grsec_socket_server_gid,
75550 + .maxlen = sizeof(int),
75551 + .mode = 0600,
75552 + .proc_handler = &proc_dointvec,
75553 + },
75554 +#endif
75555 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75556 + {
75557 + .procname = "audit_group",
75558 + .data = &grsec_enable_group,
75559 + .maxlen = sizeof(int),
75560 + .mode = 0600,
75561 + .proc_handler = &proc_dointvec,
75562 + },
75563 + {
75564 + .procname = "audit_gid",
75565 + .data = &grsec_audit_gid,
75566 + .maxlen = sizeof(int),
75567 + .mode = 0600,
75568 + .proc_handler = &proc_dointvec,
75569 + },
75570 +#endif
75571 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75572 + {
75573 + .procname = "audit_chdir",
75574 + .data = &grsec_enable_chdir,
75575 + .maxlen = sizeof(int),
75576 + .mode = 0600,
75577 + .proc_handler = &proc_dointvec,
75578 + },
75579 +#endif
75580 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75581 + {
75582 + .procname = "audit_mount",
75583 + .data = &grsec_enable_mount,
75584 + .maxlen = sizeof(int),
75585 + .mode = 0600,
75586 + .proc_handler = &proc_dointvec,
75587 + },
75588 +#endif
75589 +#ifdef CONFIG_GRKERNSEC_DMESG
75590 + {
75591 + .procname = "dmesg",
75592 + .data = &grsec_enable_dmesg,
75593 + .maxlen = sizeof(int),
75594 + .mode = 0600,
75595 + .proc_handler = &proc_dointvec,
75596 + },
75597 +#endif
75598 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75599 + {
75600 + .procname = "chroot_findtask",
75601 + .data = &grsec_enable_chroot_findtask,
75602 + .maxlen = sizeof(int),
75603 + .mode = 0600,
75604 + .proc_handler = &proc_dointvec,
75605 + },
75606 +#endif
75607 +#ifdef CONFIG_GRKERNSEC_RESLOG
75608 + {
75609 + .procname = "resource_logging",
75610 + .data = &grsec_resource_logging,
75611 + .maxlen = sizeof(int),
75612 + .mode = 0600,
75613 + .proc_handler = &proc_dointvec,
75614 + },
75615 +#endif
75616 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75617 + {
75618 + .procname = "audit_ptrace",
75619 + .data = &grsec_enable_audit_ptrace,
75620 + .maxlen = sizeof(int),
75621 + .mode = 0600,
75622 + .proc_handler = &proc_dointvec,
75623 + },
75624 +#endif
75625 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75626 + {
75627 + .procname = "harden_ptrace",
75628 + .data = &grsec_enable_harden_ptrace,
75629 + .maxlen = sizeof(int),
75630 + .mode = 0600,
75631 + .proc_handler = &proc_dointvec,
75632 + },
75633 +#endif
75634 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75635 + {
75636 + .procname = "harden_ipc",
75637 + .data = &grsec_enable_harden_ipc,
75638 + .maxlen = sizeof(int),
75639 + .mode = 0600,
75640 + .proc_handler = &proc_dointvec,
75641 + },
75642 +#endif
75643 + {
75644 + .procname = "grsec_lock",
75645 + .data = &grsec_lock,
75646 + .maxlen = sizeof(int),
75647 + .mode = 0600,
75648 + .proc_handler = &proc_dointvec,
75649 + },
75650 +#endif
75651 +#ifdef CONFIG_GRKERNSEC_ROFS
75652 + {
75653 + .procname = "romount_protect",
75654 + .data = &grsec_enable_rofs,
75655 + .maxlen = sizeof(int),
75656 + .mode = 0600,
75657 + .proc_handler = &proc_dointvec_minmax,
75658 + .extra1 = &one,
75659 + .extra2 = &one,
75660 + },
75661 +#endif
75662 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
75663 + {
75664 + .procname = "deny_new_usb",
75665 + .data = &grsec_deny_new_usb,
75666 + .maxlen = sizeof(int),
75667 + .mode = 0600,
75668 + .proc_handler = &proc_dointvec,
75669 + },
75670 +#endif
75671 + { }
75672 +};
75673 +#endif
75674 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
75675 new file mode 100644
75676 index 0000000..61b514e
75677 --- /dev/null
75678 +++ b/grsecurity/grsec_time.c
75679 @@ -0,0 +1,16 @@
75680 +#include <linux/kernel.h>
75681 +#include <linux/sched.h>
75682 +#include <linux/grinternal.h>
75683 +#include <linux/module.h>
75684 +
75685 +void
75686 +gr_log_timechange(void)
75687 +{
75688 +#ifdef CONFIG_GRKERNSEC_TIME
75689 + if (grsec_enable_time)
75690 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
75691 +#endif
75692 + return;
75693 +}
75694 +
75695 +EXPORT_SYMBOL_GPL(gr_log_timechange);
75696 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
75697 new file mode 100644
75698 index 0000000..ee57dcf
75699 --- /dev/null
75700 +++ b/grsecurity/grsec_tpe.c
75701 @@ -0,0 +1,73 @@
75702 +#include <linux/kernel.h>
75703 +#include <linux/sched.h>
75704 +#include <linux/file.h>
75705 +#include <linux/fs.h>
75706 +#include <linux/grinternal.h>
75707 +
75708 +extern int gr_acl_tpe_check(void);
75709 +
75710 +int
75711 +gr_tpe_allow(const struct file *file)
75712 +{
75713 +#ifdef CONFIG_GRKERNSEC
75714 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
75715 + const struct cred *cred = current_cred();
75716 + char *msg = NULL;
75717 + char *msg2 = NULL;
75718 +
75719 + // never restrict root
75720 + if (gr_is_global_root(cred->uid))
75721 + return 1;
75722 +
75723 + if (grsec_enable_tpe) {
75724 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75725 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
75726 + msg = "not being in trusted group";
75727 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
75728 + msg = "being in untrusted group";
75729 +#else
75730 + if (in_group_p(grsec_tpe_gid))
75731 + msg = "being in untrusted group";
75732 +#endif
75733 + }
75734 + if (!msg && gr_acl_tpe_check())
75735 + msg = "being in untrusted role";
75736 +
75737 + // not in any affected group/role
75738 + if (!msg)
75739 + goto next_check;
75740 +
75741 + if (gr_is_global_nonroot(inode->i_uid))
75742 + msg2 = "file in non-root-owned directory";
75743 + else if (inode->i_mode & S_IWOTH)
75744 + msg2 = "file in world-writable directory";
75745 + else if (inode->i_mode & S_IWGRP)
75746 + msg2 = "file in group-writable directory";
75747 +
75748 + if (msg && msg2) {
75749 + char fullmsg[70] = {0};
75750 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
75751 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
75752 + return 0;
75753 + }
75754 + msg = NULL;
75755 +next_check:
75756 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75757 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
75758 + return 1;
75759 +
75760 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
75761 + msg = "directory not owned by user";
75762 + else if (inode->i_mode & S_IWOTH)
75763 + msg = "file in world-writable directory";
75764 + else if (inode->i_mode & S_IWGRP)
75765 + msg = "file in group-writable directory";
75766 +
75767 + if (msg) {
75768 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
75769 + return 0;
75770 + }
75771 +#endif
75772 +#endif
75773 + return 1;
75774 +}
75775 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
75776 new file mode 100644
75777 index 0000000..ae02d8e
75778 --- /dev/null
75779 +++ b/grsecurity/grsec_usb.c
75780 @@ -0,0 +1,15 @@
75781 +#include <linux/kernel.h>
75782 +#include <linux/grinternal.h>
75783 +#include <linux/module.h>
75784 +
75785 +int gr_handle_new_usb(void)
75786 +{
75787 +#ifdef CONFIG_GRKERNSEC_DENYUSB
75788 + if (grsec_deny_new_usb) {
75789 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75790 + return 1;
75791 + }
75792 +#endif
75793 + return 0;
75794 +}
75795 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75796 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
75797 new file mode 100644
75798 index 0000000..9f7b1ac
75799 --- /dev/null
75800 +++ b/grsecurity/grsum.c
75801 @@ -0,0 +1,61 @@
75802 +#include <linux/err.h>
75803 +#include <linux/kernel.h>
75804 +#include <linux/sched.h>
75805 +#include <linux/mm.h>
75806 +#include <linux/scatterlist.h>
75807 +#include <linux/crypto.h>
75808 +#include <linux/gracl.h>
75809 +
75810 +
75811 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
75812 +#error "crypto and sha256 must be built into the kernel"
75813 +#endif
75814 +
75815 +int
75816 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
75817 +{
75818 + char *p;
75819 + struct crypto_hash *tfm;
75820 + struct hash_desc desc;
75821 + struct scatterlist sg;
75822 + unsigned char temp_sum[GR_SHA_LEN];
75823 + volatile int retval = 0;
75824 + volatile int dummy = 0;
75825 + unsigned int i;
75826 +
75827 + sg_init_table(&sg, 1);
75828 +
75829 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
75830 + if (IS_ERR(tfm)) {
75831 + /* should never happen, since sha256 should be built in */
75832 + return 1;
75833 + }
75834 +
75835 + desc.tfm = tfm;
75836 + desc.flags = 0;
75837 +
75838 + crypto_hash_init(&desc);
75839 +
75840 + p = salt;
75841 + sg_set_buf(&sg, p, GR_SALT_LEN);
75842 + crypto_hash_update(&desc, &sg, sg.length);
75843 +
75844 + p = entry->pw;
75845 + sg_set_buf(&sg, p, strlen(p));
75846 +
75847 + crypto_hash_update(&desc, &sg, sg.length);
75848 +
75849 + crypto_hash_final(&desc, temp_sum);
75850 +
75851 + memset(entry->pw, 0, GR_PW_LEN);
75852 +
75853 + for (i = 0; i < GR_SHA_LEN; i++)
75854 + if (sum[i] != temp_sum[i])
75855 + retval = 1;
75856 + else
75857 + dummy = 1; // waste a cycle
75858 +
75859 + crypto_free_hash(tfm);
75860 +
75861 + return retval;
75862 +}
75863 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
75864 index 77ff547..181834f 100644
75865 --- a/include/asm-generic/4level-fixup.h
75866 +++ b/include/asm-generic/4level-fixup.h
75867 @@ -13,8 +13,10 @@
75868 #define pmd_alloc(mm, pud, address) \
75869 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
75870 NULL: pmd_offset(pud, address))
75871 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
75872
75873 #define pud_alloc(mm, pgd, address) (pgd)
75874 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
75875 #define pud_offset(pgd, start) (pgd)
75876 #define pud_none(pud) 0
75877 #define pud_bad(pud) 0
75878 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
75879 index b7babf0..97f4c4f 100644
75880 --- a/include/asm-generic/atomic-long.h
75881 +++ b/include/asm-generic/atomic-long.h
75882 @@ -22,6 +22,12 @@
75883
75884 typedef atomic64_t atomic_long_t;
75885
75886 +#ifdef CONFIG_PAX_REFCOUNT
75887 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
75888 +#else
75889 +typedef atomic64_t atomic_long_unchecked_t;
75890 +#endif
75891 +
75892 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
75893
75894 static inline long atomic_long_read(atomic_long_t *l)
75895 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75896 return (long)atomic64_read(v);
75897 }
75898
75899 +#ifdef CONFIG_PAX_REFCOUNT
75900 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75901 +{
75902 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75903 +
75904 + return (long)atomic64_read_unchecked(v);
75905 +}
75906 +#endif
75907 +
75908 static inline void atomic_long_set(atomic_long_t *l, long i)
75909 {
75910 atomic64_t *v = (atomic64_t *)l;
75911 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75912 atomic64_set(v, i);
75913 }
75914
75915 +#ifdef CONFIG_PAX_REFCOUNT
75916 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75917 +{
75918 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75919 +
75920 + atomic64_set_unchecked(v, i);
75921 +}
75922 +#endif
75923 +
75924 static inline void atomic_long_inc(atomic_long_t *l)
75925 {
75926 atomic64_t *v = (atomic64_t *)l;
75927 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75928 atomic64_inc(v);
75929 }
75930
75931 +#ifdef CONFIG_PAX_REFCOUNT
75932 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75933 +{
75934 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75935 +
75936 + atomic64_inc_unchecked(v);
75937 +}
75938 +#endif
75939 +
75940 static inline void atomic_long_dec(atomic_long_t *l)
75941 {
75942 atomic64_t *v = (atomic64_t *)l;
75943 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75944 atomic64_dec(v);
75945 }
75946
75947 +#ifdef CONFIG_PAX_REFCOUNT
75948 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75949 +{
75950 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75951 +
75952 + atomic64_dec_unchecked(v);
75953 +}
75954 +#endif
75955 +
75956 static inline void atomic_long_add(long i, atomic_long_t *l)
75957 {
75958 atomic64_t *v = (atomic64_t *)l;
75959 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75960 atomic64_add(i, v);
75961 }
75962
75963 +#ifdef CONFIG_PAX_REFCOUNT
75964 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75965 +{
75966 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75967 +
75968 + atomic64_add_unchecked(i, v);
75969 +}
75970 +#endif
75971 +
75972 static inline void atomic_long_sub(long i, atomic_long_t *l)
75973 {
75974 atomic64_t *v = (atomic64_t *)l;
75975 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75976 atomic64_sub(i, v);
75977 }
75978
75979 +#ifdef CONFIG_PAX_REFCOUNT
75980 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75981 +{
75982 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75983 +
75984 + atomic64_sub_unchecked(i, v);
75985 +}
75986 +#endif
75987 +
75988 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75989 {
75990 atomic64_t *v = (atomic64_t *)l;
75991 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
75992 return atomic64_add_negative(i, v);
75993 }
75994
75995 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
75996 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
75997 {
75998 atomic64_t *v = (atomic64_t *)l;
75999
76000 return (long)atomic64_add_return(i, v);
76001 }
76002
76003 +#ifdef CONFIG_PAX_REFCOUNT
76004 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76005 +{
76006 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76007 +
76008 + return (long)atomic64_add_return_unchecked(i, v);
76009 +}
76010 +#endif
76011 +
76012 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76013 {
76014 atomic64_t *v = (atomic64_t *)l;
76015 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76016 return (long)atomic64_inc_return(v);
76017 }
76018
76019 +#ifdef CONFIG_PAX_REFCOUNT
76020 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76021 +{
76022 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76023 +
76024 + return (long)atomic64_inc_return_unchecked(v);
76025 +}
76026 +#endif
76027 +
76028 static inline long atomic_long_dec_return(atomic_long_t *l)
76029 {
76030 atomic64_t *v = (atomic64_t *)l;
76031 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76032
76033 typedef atomic_t atomic_long_t;
76034
76035 +#ifdef CONFIG_PAX_REFCOUNT
76036 +typedef atomic_unchecked_t atomic_long_unchecked_t;
76037 +#else
76038 +typedef atomic_t atomic_long_unchecked_t;
76039 +#endif
76040 +
76041 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76042 static inline long atomic_long_read(atomic_long_t *l)
76043 {
76044 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76045 return (long)atomic_read(v);
76046 }
76047
76048 +#ifdef CONFIG_PAX_REFCOUNT
76049 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76050 +{
76051 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76052 +
76053 + return (long)atomic_read_unchecked(v);
76054 +}
76055 +#endif
76056 +
76057 static inline void atomic_long_set(atomic_long_t *l, long i)
76058 {
76059 atomic_t *v = (atomic_t *)l;
76060 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76061 atomic_set(v, i);
76062 }
76063
76064 +#ifdef CONFIG_PAX_REFCOUNT
76065 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76066 +{
76067 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76068 +
76069 + atomic_set_unchecked(v, i);
76070 +}
76071 +#endif
76072 +
76073 static inline void atomic_long_inc(atomic_long_t *l)
76074 {
76075 atomic_t *v = (atomic_t *)l;
76076 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76077 atomic_inc(v);
76078 }
76079
76080 +#ifdef CONFIG_PAX_REFCOUNT
76081 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76082 +{
76083 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76084 +
76085 + atomic_inc_unchecked(v);
76086 +}
76087 +#endif
76088 +
76089 static inline void atomic_long_dec(atomic_long_t *l)
76090 {
76091 atomic_t *v = (atomic_t *)l;
76092 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76093 atomic_dec(v);
76094 }
76095
76096 +#ifdef CONFIG_PAX_REFCOUNT
76097 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76098 +{
76099 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76100 +
76101 + atomic_dec_unchecked(v);
76102 +}
76103 +#endif
76104 +
76105 static inline void atomic_long_add(long i, atomic_long_t *l)
76106 {
76107 atomic_t *v = (atomic_t *)l;
76108 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76109 atomic_add(i, v);
76110 }
76111
76112 +#ifdef CONFIG_PAX_REFCOUNT
76113 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76114 +{
76115 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76116 +
76117 + atomic_add_unchecked(i, v);
76118 +}
76119 +#endif
76120 +
76121 static inline void atomic_long_sub(long i, atomic_long_t *l)
76122 {
76123 atomic_t *v = (atomic_t *)l;
76124 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76125 atomic_sub(i, v);
76126 }
76127
76128 +#ifdef CONFIG_PAX_REFCOUNT
76129 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76130 +{
76131 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76132 +
76133 + atomic_sub_unchecked(i, v);
76134 +}
76135 +#endif
76136 +
76137 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76138 {
76139 atomic_t *v = (atomic_t *)l;
76140 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76141 return (long)atomic_add_return(i, v);
76142 }
76143
76144 +#ifdef CONFIG_PAX_REFCOUNT
76145 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76146 +{
76147 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76148 +
76149 + return (long)atomic_add_return_unchecked(i, v);
76150 +}
76151 +
76152 +#endif
76153 +
76154 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76155 {
76156 atomic_t *v = (atomic_t *)l;
76157 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76158 return (long)atomic_inc_return(v);
76159 }
76160
76161 +#ifdef CONFIG_PAX_REFCOUNT
76162 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76163 +{
76164 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76165 +
76166 + return (long)atomic_inc_return_unchecked(v);
76167 +}
76168 +#endif
76169 +
76170 static inline long atomic_long_dec_return(atomic_long_t *l)
76171 {
76172 atomic_t *v = (atomic_t *)l;
76173 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76174
76175 #endif /* BITS_PER_LONG == 64 */
76176
76177 +#ifdef CONFIG_PAX_REFCOUNT
76178 +static inline void pax_refcount_needs_these_functions(void)
76179 +{
76180 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
76181 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76182 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76183 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76184 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76185 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76186 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76187 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76188 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76189 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76190 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76191 +#ifdef CONFIG_X86
76192 + atomic_clear_mask_unchecked(0, NULL);
76193 + atomic_set_mask_unchecked(0, NULL);
76194 +#endif
76195 +
76196 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76197 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76198 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76199 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76200 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76201 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76202 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76203 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76204 +}
76205 +#else
76206 +#define atomic_read_unchecked(v) atomic_read(v)
76207 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76208 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76209 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76210 +#define atomic_inc_unchecked(v) atomic_inc(v)
76211 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76212 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76213 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76214 +#define atomic_dec_unchecked(v) atomic_dec(v)
76215 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76216 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76217 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76218 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76219 +
76220 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
76221 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76222 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76223 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76224 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76225 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76226 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76227 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76228 +#endif
76229 +
76230 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76231 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76232 index 33bd2de..f31bff97 100644
76233 --- a/include/asm-generic/atomic.h
76234 +++ b/include/asm-generic/atomic.h
76235 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76236 * Atomically clears the bits set in @mask from @v
76237 */
76238 #ifndef atomic_clear_mask
76239 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76240 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76241 {
76242 unsigned long flags;
76243
76244 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76245 index b18ce4f..2ee2843 100644
76246 --- a/include/asm-generic/atomic64.h
76247 +++ b/include/asm-generic/atomic64.h
76248 @@ -16,6 +16,8 @@ typedef struct {
76249 long long counter;
76250 } atomic64_t;
76251
76252 +typedef atomic64_t atomic64_unchecked_t;
76253 +
76254 #define ATOMIC64_INIT(i) { (i) }
76255
76256 extern long long atomic64_read(const atomic64_t *v);
76257 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76258 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76259 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76260
76261 +#define atomic64_read_unchecked(v) atomic64_read(v)
76262 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76263 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76264 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76265 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76266 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
76267 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76268 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
76269 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76270 +
76271 #endif /* _ASM_GENERIC_ATOMIC64_H */
76272 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76273 index a60a7cc..0fe12f2 100644
76274 --- a/include/asm-generic/bitops/__fls.h
76275 +++ b/include/asm-generic/bitops/__fls.h
76276 @@ -9,7 +9,7 @@
76277 *
76278 * Undefined if no set bit exists, so code should check against 0 first.
76279 */
76280 -static __always_inline unsigned long __fls(unsigned long word)
76281 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76282 {
76283 int num = BITS_PER_LONG - 1;
76284
76285 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76286 index 0576d1f..dad6c71 100644
76287 --- a/include/asm-generic/bitops/fls.h
76288 +++ b/include/asm-generic/bitops/fls.h
76289 @@ -9,7 +9,7 @@
76290 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76291 */
76292
76293 -static __always_inline int fls(int x)
76294 +static __always_inline int __intentional_overflow(-1) fls(int x)
76295 {
76296 int r = 32;
76297
76298 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76299 index b097cf8..3d40e14 100644
76300 --- a/include/asm-generic/bitops/fls64.h
76301 +++ b/include/asm-generic/bitops/fls64.h
76302 @@ -15,7 +15,7 @@
76303 * at position 64.
76304 */
76305 #if BITS_PER_LONG == 32
76306 -static __always_inline int fls64(__u64 x)
76307 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76308 {
76309 __u32 h = x >> 32;
76310 if (h)
76311 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76312 return fls(x);
76313 }
76314 #elif BITS_PER_LONG == 64
76315 -static __always_inline int fls64(__u64 x)
76316 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76317 {
76318 if (x == 0)
76319 return 0;
76320 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76321 index 1bfcfe5..e04c5c9 100644
76322 --- a/include/asm-generic/cache.h
76323 +++ b/include/asm-generic/cache.h
76324 @@ -6,7 +6,7 @@
76325 * cache lines need to provide their own cache.h.
76326 */
76327
76328 -#define L1_CACHE_SHIFT 5
76329 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76330 +#define L1_CACHE_SHIFT 5UL
76331 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76332
76333 #endif /* __ASM_GENERIC_CACHE_H */
76334 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76335 index 0d68a1e..b74a761 100644
76336 --- a/include/asm-generic/emergency-restart.h
76337 +++ b/include/asm-generic/emergency-restart.h
76338 @@ -1,7 +1,7 @@
76339 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76340 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76341
76342 -static inline void machine_emergency_restart(void)
76343 +static inline __noreturn void machine_emergency_restart(void)
76344 {
76345 machine_restart(NULL);
76346 }
76347 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76348 index 90f99c7..00ce236 100644
76349 --- a/include/asm-generic/kmap_types.h
76350 +++ b/include/asm-generic/kmap_types.h
76351 @@ -2,9 +2,9 @@
76352 #define _ASM_GENERIC_KMAP_TYPES_H
76353
76354 #ifdef __WITH_KM_FENCE
76355 -# define KM_TYPE_NR 41
76356 +# define KM_TYPE_NR 42
76357 #else
76358 -# define KM_TYPE_NR 20
76359 +# define KM_TYPE_NR 21
76360 #endif
76361
76362 #endif
76363 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76364 index 9ceb03b..62b0b8f 100644
76365 --- a/include/asm-generic/local.h
76366 +++ b/include/asm-generic/local.h
76367 @@ -23,24 +23,37 @@ typedef struct
76368 atomic_long_t a;
76369 } local_t;
76370
76371 +typedef struct {
76372 + atomic_long_unchecked_t a;
76373 +} local_unchecked_t;
76374 +
76375 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76376
76377 #define local_read(l) atomic_long_read(&(l)->a)
76378 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76379 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76380 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76381 #define local_inc(l) atomic_long_inc(&(l)->a)
76382 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76383 #define local_dec(l) atomic_long_dec(&(l)->a)
76384 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76385 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76386 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76387 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76388 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76389
76390 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76391 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76392 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76393 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76394 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76395 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76396 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76397 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76398 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76399
76400 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76401 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76402 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76403 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76404 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76405 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76406 index 725612b..9cc513a 100644
76407 --- a/include/asm-generic/pgtable-nopmd.h
76408 +++ b/include/asm-generic/pgtable-nopmd.h
76409 @@ -1,14 +1,19 @@
76410 #ifndef _PGTABLE_NOPMD_H
76411 #define _PGTABLE_NOPMD_H
76412
76413 -#ifndef __ASSEMBLY__
76414 -
76415 #include <asm-generic/pgtable-nopud.h>
76416
76417 -struct mm_struct;
76418 -
76419 #define __PAGETABLE_PMD_FOLDED
76420
76421 +#define PMD_SHIFT PUD_SHIFT
76422 +#define PTRS_PER_PMD 1
76423 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76424 +#define PMD_MASK (~(PMD_SIZE-1))
76425 +
76426 +#ifndef __ASSEMBLY__
76427 +
76428 +struct mm_struct;
76429 +
76430 /*
76431 * Having the pmd type consist of a pud gets the size right, and allows
76432 * us to conceptually access the pud entry that this pmd is folded into
76433 @@ -16,11 +21,6 @@ struct mm_struct;
76434 */
76435 typedef struct { pud_t pud; } pmd_t;
76436
76437 -#define PMD_SHIFT PUD_SHIFT
76438 -#define PTRS_PER_PMD 1
76439 -#define PMD_SIZE (1UL << PMD_SHIFT)
76440 -#define PMD_MASK (~(PMD_SIZE-1))
76441 -
76442 /*
76443 * The "pud_xxx()" functions here are trivial for a folded two-level
76444 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76445 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76446 index 810431d..0ec4804f 100644
76447 --- a/include/asm-generic/pgtable-nopud.h
76448 +++ b/include/asm-generic/pgtable-nopud.h
76449 @@ -1,10 +1,15 @@
76450 #ifndef _PGTABLE_NOPUD_H
76451 #define _PGTABLE_NOPUD_H
76452
76453 -#ifndef __ASSEMBLY__
76454 -
76455 #define __PAGETABLE_PUD_FOLDED
76456
76457 +#define PUD_SHIFT PGDIR_SHIFT
76458 +#define PTRS_PER_PUD 1
76459 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76460 +#define PUD_MASK (~(PUD_SIZE-1))
76461 +
76462 +#ifndef __ASSEMBLY__
76463 +
76464 /*
76465 * Having the pud type consist of a pgd gets the size right, and allows
76466 * us to conceptually access the pgd entry that this pud is folded into
76467 @@ -12,11 +17,6 @@
76468 */
76469 typedef struct { pgd_t pgd; } pud_t;
76470
76471 -#define PUD_SHIFT PGDIR_SHIFT
76472 -#define PTRS_PER_PUD 1
76473 -#define PUD_SIZE (1UL << PUD_SHIFT)
76474 -#define PUD_MASK (~(PUD_SIZE-1))
76475 -
76476 /*
76477 * The "pgd_xxx()" functions here are trivial for a folded two-level
76478 * setup: the pud is never bad, and a pud always exists (as it's folded
76479 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76480 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76481
76482 #define pgd_populate(mm, pgd, pud) do { } while (0)
76483 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76484 /*
76485 * (puds are folded into pgds so this doesn't get actually called,
76486 * but the define is needed for a generic inline function.)
76487 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76488 index 8e4f41d..c5e9afd 100644
76489 --- a/include/asm-generic/pgtable.h
76490 +++ b/include/asm-generic/pgtable.h
76491 @@ -748,6 +748,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
76492 }
76493 #endif /* CONFIG_NUMA_BALANCING */
76494
76495 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76496 +#ifdef CONFIG_PAX_KERNEXEC
76497 +#error KERNEXEC requires pax_open_kernel
76498 +#else
76499 +static inline unsigned long pax_open_kernel(void) { return 0; }
76500 +#endif
76501 +#endif
76502 +
76503 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76504 +#ifdef CONFIG_PAX_KERNEXEC
76505 +#error KERNEXEC requires pax_close_kernel
76506 +#else
76507 +static inline unsigned long pax_close_kernel(void) { return 0; }
76508 +#endif
76509 +#endif
76510 +
76511 #endif /* CONFIG_MMU */
76512
76513 #endif /* !__ASSEMBLY__ */
76514 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76515 index dc1269c..48a4f51 100644
76516 --- a/include/asm-generic/uaccess.h
76517 +++ b/include/asm-generic/uaccess.h
76518 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76519 return __clear_user(to, n);
76520 }
76521
76522 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76523 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76524 +#error UDEREF requires pax_open_userland
76525 +#else
76526 +static inline unsigned long pax_open_userland(void) { return 0; }
76527 +#endif
76528 +#endif
76529 +
76530 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76531 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76532 +#error UDEREF requires pax_close_userland
76533 +#else
76534 +static inline unsigned long pax_close_userland(void) { return 0; }
76535 +#endif
76536 +#endif
76537 +
76538 #endif /* __ASM_GENERIC_UACCESS_H */
76539 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76540 index bc2121f..2f41f9a 100644
76541 --- a/include/asm-generic/vmlinux.lds.h
76542 +++ b/include/asm-generic/vmlinux.lds.h
76543 @@ -232,6 +232,7 @@
76544 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76545 VMLINUX_SYMBOL(__start_rodata) = .; \
76546 *(.rodata) *(.rodata.*) \
76547 + *(.data..read_only) \
76548 *(__vermagic) /* Kernel version magic */ \
76549 . = ALIGN(8); \
76550 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76551 @@ -716,17 +717,18 @@
76552 * section in the linker script will go there too. @phdr should have
76553 * a leading colon.
76554 *
76555 - * Note that this macros defines __per_cpu_load as an absolute symbol.
76556 + * Note that this macros defines per_cpu_load as an absolute symbol.
76557 * If there is no need to put the percpu section at a predetermined
76558 * address, use PERCPU_SECTION.
76559 */
76560 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76561 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
76562 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
76563 + per_cpu_load = .; \
76564 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
76565 - LOAD_OFFSET) { \
76566 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
76567 PERCPU_INPUT(cacheline) \
76568 } phdr \
76569 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
76570 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
76571
76572 /**
76573 * PERCPU_SECTION - define output section for percpu area, simple version
76574 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
76575 index e73c19e..5b89e00 100644
76576 --- a/include/crypto/algapi.h
76577 +++ b/include/crypto/algapi.h
76578 @@ -34,7 +34,7 @@ struct crypto_type {
76579 unsigned int maskclear;
76580 unsigned int maskset;
76581 unsigned int tfmsize;
76582 -};
76583 +} __do_const;
76584
76585 struct crypto_instance {
76586 struct crypto_alg alg;
76587 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
76588 index 1d4a920..da65658 100644
76589 --- a/include/drm/drmP.h
76590 +++ b/include/drm/drmP.h
76591 @@ -66,6 +66,7 @@
76592 #include <linux/workqueue.h>
76593 #include <linux/poll.h>
76594 #include <asm/pgalloc.h>
76595 +#include <asm/local.h>
76596 #include <drm/drm.h>
76597 #include <drm/drm_sarea.h>
76598 #include <drm/drm_vma_manager.h>
76599 @@ -278,10 +279,12 @@ do { \
76600 * \param cmd command.
76601 * \param arg argument.
76602 */
76603 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
76604 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
76605 + struct drm_file *file_priv);
76606 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
76607 struct drm_file *file_priv);
76608
76609 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76610 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
76611 unsigned long arg);
76612
76613 #define DRM_IOCTL_NR(n) _IOC_NR(n)
76614 @@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76615 struct drm_ioctl_desc {
76616 unsigned int cmd;
76617 int flags;
76618 - drm_ioctl_t *func;
76619 + drm_ioctl_t func;
76620 unsigned int cmd_drv;
76621 const char *name;
76622 -};
76623 +} __do_const;
76624
76625 /**
76626 * Creates a driver or general drm_ioctl_desc array entry for the given
76627 @@ -1013,7 +1016,8 @@ struct drm_info_list {
76628 int (*show)(struct seq_file*, void*); /** show callback */
76629 u32 driver_features; /**< Required driver features for this entry */
76630 void *data;
76631 -};
76632 +} __do_const;
76633 +typedef struct drm_info_list __no_const drm_info_list_no_const;
76634
76635 /**
76636 * debugfs node structure. This structure represents a debugfs file.
76637 @@ -1097,7 +1101,7 @@ struct drm_device {
76638
76639 /** \name Usage Counters */
76640 /*@{ */
76641 - int open_count; /**< Outstanding files open */
76642 + local_t open_count; /**< Outstanding files open */
76643 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
76644 atomic_t vma_count; /**< Outstanding vma areas open */
76645 int buf_use; /**< Buffers in use -- cannot alloc */
76646 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
76647 index ef6ad3a..be34b16 100644
76648 --- a/include/drm/drm_crtc_helper.h
76649 +++ b/include/drm/drm_crtc_helper.h
76650 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
76651 struct drm_connector *connector);
76652 /* disable encoder when not in use - more explicit than dpms off */
76653 void (*disable)(struct drm_encoder *encoder);
76654 -};
76655 +} __no_const;
76656
76657 /**
76658 * drm_connector_helper_funcs - helper operations for connectors
76659 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
76660 index 940ece4..8cb727f 100644
76661 --- a/include/drm/i915_pciids.h
76662 +++ b/include/drm/i915_pciids.h
76663 @@ -37,7 +37,7 @@
76664 */
76665 #define INTEL_VGA_DEVICE(id, info) { \
76666 0x8086, id, \
76667 - ~0, ~0, \
76668 + PCI_ANY_ID, PCI_ANY_ID, \
76669 0x030000, 0xff0000, \
76670 (unsigned long) info }
76671
76672 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
76673 index 72dcbe8..8db58d7 100644
76674 --- a/include/drm/ttm/ttm_memory.h
76675 +++ b/include/drm/ttm/ttm_memory.h
76676 @@ -48,7 +48,7 @@
76677
76678 struct ttm_mem_shrink {
76679 int (*do_shrink) (struct ttm_mem_shrink *);
76680 -};
76681 +} __no_const;
76682
76683 /**
76684 * struct ttm_mem_global - Global memory accounting structure.
76685 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
76686 index d1f61bf..2239439 100644
76687 --- a/include/drm/ttm/ttm_page_alloc.h
76688 +++ b/include/drm/ttm/ttm_page_alloc.h
76689 @@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
76690 */
76691 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
76692
76693 +struct device;
76694 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76695 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76696
76697 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
76698 index 4b840e8..155d235 100644
76699 --- a/include/keys/asymmetric-subtype.h
76700 +++ b/include/keys/asymmetric-subtype.h
76701 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
76702 /* Verify the signature on a key of this subtype (optional) */
76703 int (*verify_signature)(const struct key *key,
76704 const struct public_key_signature *sig);
76705 -};
76706 +} __do_const;
76707
76708 /**
76709 * asymmetric_key_subtype - Get the subtype from an asymmetric key
76710 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
76711 index c1da539..1dcec55 100644
76712 --- a/include/linux/atmdev.h
76713 +++ b/include/linux/atmdev.h
76714 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
76715 #endif
76716
76717 struct k_atm_aal_stats {
76718 -#define __HANDLE_ITEM(i) atomic_t i
76719 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
76720 __AAL_STAT_ITEMS
76721 #undef __HANDLE_ITEM
76722 };
76723 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
76724 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
76725 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
76726 struct module *owner;
76727 -};
76728 +} __do_const ;
76729
76730 struct atmphy_ops {
76731 int (*start)(struct atm_dev *dev);
76732 diff --git a/include/linux/audit.h b/include/linux/audit.h
76733 index bf1ef22..2a55e1b 100644
76734 --- a/include/linux/audit.h
76735 +++ b/include/linux/audit.h
76736 @@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
76737 extern unsigned int audit_serial(void);
76738 extern int auditsc_get_stamp(struct audit_context *ctx,
76739 struct timespec *t, unsigned int *serial);
76740 -extern int audit_set_loginuid(kuid_t loginuid);
76741 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
76742
76743 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
76744 {
76745 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
76746 index fd8bf32..2cccd5a 100644
76747 --- a/include/linux/binfmts.h
76748 +++ b/include/linux/binfmts.h
76749 @@ -74,8 +74,10 @@ struct linux_binfmt {
76750 int (*load_binary)(struct linux_binprm *);
76751 int (*load_shlib)(struct file *);
76752 int (*core_dump)(struct coredump_params *cprm);
76753 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
76754 + void (*handle_mmap)(struct file *);
76755 unsigned long min_coredump; /* minimal dump size */
76756 -};
76757 +} __do_const;
76758
76759 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
76760
76761 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
76762 index abc9ca7..e54ee27 100644
76763 --- a/include/linux/bitops.h
76764 +++ b/include/linux/bitops.h
76765 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
76766 * @word: value to rotate
76767 * @shift: bits to roll
76768 */
76769 -static inline __u32 rol32(__u32 word, unsigned int shift)
76770 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
76771 {
76772 return (word << shift) | (word >> (32 - shift));
76773 }
76774 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
76775 * @word: value to rotate
76776 * @shift: bits to roll
76777 */
76778 -static inline __u32 ror32(__u32 word, unsigned int shift)
76779 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76780 {
76781 return (word >> shift) | (word << (32 - shift));
76782 }
76783 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76784 return (__s32)(value << shift) >> shift;
76785 }
76786
76787 -static inline unsigned fls_long(unsigned long l)
76788 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76789 {
76790 if (sizeof(l) == 4)
76791 return fls(l);
76792 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
76793 index 1b135d4..59fc876 100644
76794 --- a/include/linux/blkdev.h
76795 +++ b/include/linux/blkdev.h
76796 @@ -1578,7 +1578,7 @@ struct block_device_operations {
76797 /* this callback is with swap_lock and sometimes page table lock held */
76798 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
76799 struct module *owner;
76800 -};
76801 +} __do_const;
76802
76803 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
76804 unsigned long);
76805 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
76806 index afc1343..9735539 100644
76807 --- a/include/linux/blktrace_api.h
76808 +++ b/include/linux/blktrace_api.h
76809 @@ -25,7 +25,7 @@ struct blk_trace {
76810 struct dentry *dropped_file;
76811 struct dentry *msg_file;
76812 struct list_head running_list;
76813 - atomic_t dropped;
76814 + atomic_unchecked_t dropped;
76815 };
76816
76817 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
76818 diff --git a/include/linux/cache.h b/include/linux/cache.h
76819 index 4c57065..40346da 100644
76820 --- a/include/linux/cache.h
76821 +++ b/include/linux/cache.h
76822 @@ -16,6 +16,14 @@
76823 #define __read_mostly
76824 #endif
76825
76826 +#ifndef __read_only
76827 +#ifdef CONFIG_PAX_KERNEXEC
76828 +#error KERNEXEC requires __read_only
76829 +#else
76830 +#define __read_only __read_mostly
76831 +#endif
76832 +#endif
76833 +
76834 #ifndef ____cacheline_aligned
76835 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
76836 #endif
76837 diff --git a/include/linux/capability.h b/include/linux/capability.h
76838 index a6ee1f9..e1ca49d 100644
76839 --- a/include/linux/capability.h
76840 +++ b/include/linux/capability.h
76841 @@ -212,8 +212,13 @@ extern bool capable(int cap);
76842 extern bool ns_capable(struct user_namespace *ns, int cap);
76843 extern bool inode_capable(const struct inode *inode, int cap);
76844 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
76845 +extern bool capable_nolog(int cap);
76846 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
76847 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
76848
76849 /* audit system wants to get cap info from files as well */
76850 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
76851
76852 +extern int is_privileged_binary(const struct dentry *dentry);
76853 +
76854 #endif /* !_LINUX_CAPABILITY_H */
76855 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
76856 index 8609d57..86e4d79 100644
76857 --- a/include/linux/cdrom.h
76858 +++ b/include/linux/cdrom.h
76859 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
76860
76861 /* driver specifications */
76862 const int capability; /* capability flags */
76863 - int n_minors; /* number of active minor devices */
76864 /* handle uniform packets for scsi type devices (scsi,atapi) */
76865 int (*generic_packet) (struct cdrom_device_info *,
76866 struct packet_command *);
76867 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
76868 index 4ce9056..86caac6 100644
76869 --- a/include/linux/cleancache.h
76870 +++ b/include/linux/cleancache.h
76871 @@ -31,7 +31,7 @@ struct cleancache_ops {
76872 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
76873 void (*invalidate_inode)(int, struct cleancache_filekey);
76874 void (*invalidate_fs)(int);
76875 -};
76876 +} __no_const;
76877
76878 extern struct cleancache_ops *
76879 cleancache_register_ops(struct cleancache_ops *ops);
76880 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
76881 index 7e59253..d6e4cae 100644
76882 --- a/include/linux/clk-provider.h
76883 +++ b/include/linux/clk-provider.h
76884 @@ -141,6 +141,7 @@ struct clk_ops {
76885 unsigned long);
76886 void (*init)(struct clk_hw *hw);
76887 };
76888 +typedef struct clk_ops __no_const clk_ops_no_const;
76889
76890 /**
76891 * struct clk_init_data - holds init data that's common to all clocks and is
76892 diff --git a/include/linux/compat.h b/include/linux/compat.h
76893 index 19f6003..90b64f4 100644
76894 --- a/include/linux/compat.h
76895 +++ b/include/linux/compat.h
76896 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
76897 compat_size_t __user *len_ptr);
76898
76899 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
76900 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
76901 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
76902 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
76903 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
76904 compat_ssize_t msgsz, int msgflg);
76905 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
76906 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
76907 compat_ulong_t addr, compat_ulong_t data);
76908 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76909 - compat_long_t addr, compat_long_t data);
76910 + compat_ulong_t addr, compat_ulong_t data);
76911
76912 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
76913 /*
76914 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
76915 index 2507fd2..55203f8 100644
76916 --- a/include/linux/compiler-gcc4.h
76917 +++ b/include/linux/compiler-gcc4.h
76918 @@ -39,9 +39,34 @@
76919 # define __compiletime_warning(message) __attribute__((warning(message)))
76920 # define __compiletime_error(message) __attribute__((error(message)))
76921 #endif /* __CHECKER__ */
76922 +
76923 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
76924 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
76925 +#define __bos0(ptr) __bos((ptr), 0)
76926 +#define __bos1(ptr) __bos((ptr), 1)
76927 #endif /* GCC_VERSION >= 40300 */
76928
76929 #if GCC_VERSION >= 40500
76930 +
76931 +#ifdef RANDSTRUCT_PLUGIN
76932 +#define __randomize_layout __attribute__((randomize_layout))
76933 +#define __no_randomize_layout __attribute__((no_randomize_layout))
76934 +#endif
76935 +
76936 +#ifdef CONSTIFY_PLUGIN
76937 +#define __no_const __attribute__((no_const))
76938 +#define __do_const __attribute__((do_const))
76939 +#endif
76940 +
76941 +#ifdef SIZE_OVERFLOW_PLUGIN
76942 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
76943 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
76944 +#endif
76945 +
76946 +#ifdef LATENT_ENTROPY_PLUGIN
76947 +#define __latent_entropy __attribute__((latent_entropy))
76948 +#endif
76949 +
76950 /*
76951 * Mark a position in code as unreachable. This can be used to
76952 * suppress control flow warnings after asm blocks that transfer
76953 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
76954 index 92669cd..cc564c0 100644
76955 --- a/include/linux/compiler.h
76956 +++ b/include/linux/compiler.h
76957 @@ -5,11 +5,14 @@
76958
76959 #ifdef __CHECKER__
76960 # define __user __attribute__((noderef, address_space(1)))
76961 +# define __force_user __force __user
76962 # define __kernel __attribute__((address_space(0)))
76963 +# define __force_kernel __force __kernel
76964 # define __safe __attribute__((safe))
76965 # define __force __attribute__((force))
76966 # define __nocast __attribute__((nocast))
76967 # define __iomem __attribute__((noderef, address_space(2)))
76968 +# define __force_iomem __force __iomem
76969 # define __must_hold(x) __attribute__((context(x,1,1)))
76970 # define __acquires(x) __attribute__((context(x,0,1)))
76971 # define __releases(x) __attribute__((context(x,1,0)))
76972 @@ -17,20 +20,37 @@
76973 # define __release(x) __context__(x,-1)
76974 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
76975 # define __percpu __attribute__((noderef, address_space(3)))
76976 +# define __force_percpu __force __percpu
76977 #ifdef CONFIG_SPARSE_RCU_POINTER
76978 # define __rcu __attribute__((noderef, address_space(4)))
76979 +# define __force_rcu __force __rcu
76980 #else
76981 # define __rcu
76982 +# define __force_rcu
76983 #endif
76984 extern void __chk_user_ptr(const volatile void __user *);
76985 extern void __chk_io_ptr(const volatile void __iomem *);
76986 #else
76987 -# define __user
76988 -# define __kernel
76989 +# ifdef CHECKER_PLUGIN
76990 +//# define __user
76991 +//# define __force_user
76992 +//# define __kernel
76993 +//# define __force_kernel
76994 +# else
76995 +# ifdef STRUCTLEAK_PLUGIN
76996 +# define __user __attribute__((user))
76997 +# else
76998 +# define __user
76999 +# endif
77000 +# define __force_user
77001 +# define __kernel
77002 +# define __force_kernel
77003 +# endif
77004 # define __safe
77005 # define __force
77006 # define __nocast
77007 # define __iomem
77008 +# define __force_iomem
77009 # define __chk_user_ptr(x) (void)0
77010 # define __chk_io_ptr(x) (void)0
77011 # define __builtin_warning(x, y...) (1)
77012 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77013 # define __release(x) (void)0
77014 # define __cond_lock(x,c) (c)
77015 # define __percpu
77016 +# define __force_percpu
77017 # define __rcu
77018 +# define __force_rcu
77019 #endif
77020
77021 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77022 @@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77023 # define __attribute_const__ /* unimplemented */
77024 #endif
77025
77026 +#ifndef __randomize_layout
77027 +# define __randomize_layout
77028 +#endif
77029 +
77030 +#ifndef __no_randomize_layout
77031 +# define __no_randomize_layout
77032 +#endif
77033 +
77034 +#ifndef __no_const
77035 +# define __no_const
77036 +#endif
77037 +
77038 +#ifndef __do_const
77039 +# define __do_const
77040 +#endif
77041 +
77042 +#ifndef __size_overflow
77043 +# define __size_overflow(...)
77044 +#endif
77045 +
77046 +#ifndef __intentional_overflow
77047 +# define __intentional_overflow(...)
77048 +#endif
77049 +
77050 +#ifndef __latent_entropy
77051 +# define __latent_entropy
77052 +#endif
77053 +
77054 /*
77055 * Tell gcc if a function is cold. The compiler will assume any path
77056 * directly leading to the call is unlikely.
77057 @@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77058 #define __cold
77059 #endif
77060
77061 +#ifndef __alloc_size
77062 +#define __alloc_size(...)
77063 +#endif
77064 +
77065 +#ifndef __bos
77066 +#define __bos(ptr, arg)
77067 +#endif
77068 +
77069 +#ifndef __bos0
77070 +#define __bos0(ptr)
77071 +#endif
77072 +
77073 +#ifndef __bos1
77074 +#define __bos1(ptr)
77075 +#endif
77076 +
77077 /* Simple shorthand for a section definition */
77078 #ifndef __section
77079 # define __section(S) __attribute__ ((__section__(#S)))
77080 @@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77081 * use is to mediate communication between process-level code and irq/NMI
77082 * handlers, all running on the same CPU.
77083 */
77084 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77085 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77086 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77087
77088 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77089 #ifdef CONFIG_KPROBES
77090 diff --git a/include/linux/completion.h b/include/linux/completion.h
77091 index 5d5aaae..0ea9b84 100644
77092 --- a/include/linux/completion.h
77093 +++ b/include/linux/completion.h
77094 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77095
77096 extern void wait_for_completion(struct completion *);
77097 extern void wait_for_completion_io(struct completion *);
77098 -extern int wait_for_completion_interruptible(struct completion *x);
77099 -extern int wait_for_completion_killable(struct completion *x);
77100 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77101 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77102 extern unsigned long wait_for_completion_timeout(struct completion *x,
77103 - unsigned long timeout);
77104 + unsigned long timeout) __intentional_overflow(-1);
77105 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77106 - unsigned long timeout);
77107 + unsigned long timeout) __intentional_overflow(-1);
77108 extern long wait_for_completion_interruptible_timeout(
77109 - struct completion *x, unsigned long timeout);
77110 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77111 extern long wait_for_completion_killable_timeout(
77112 - struct completion *x, unsigned long timeout);
77113 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77114 extern bool try_wait_for_completion(struct completion *x);
77115 extern bool completion_done(struct completion *x);
77116
77117 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77118 index 34025df..d94bbbc 100644
77119 --- a/include/linux/configfs.h
77120 +++ b/include/linux/configfs.h
77121 @@ -125,7 +125,7 @@ struct configfs_attribute {
77122 const char *ca_name;
77123 struct module *ca_owner;
77124 umode_t ca_mode;
77125 -};
77126 +} __do_const;
77127
77128 /*
77129 * Users often need to create attribute structures for their configurable
77130 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77131 index dc196bb..c55a50f 100644
77132 --- a/include/linux/cpufreq.h
77133 +++ b/include/linux/cpufreq.h
77134 @@ -189,6 +189,7 @@ struct global_attr {
77135 ssize_t (*store)(struct kobject *a, struct attribute *b,
77136 const char *c, size_t count);
77137 };
77138 +typedef struct global_attr __no_const global_attr_no_const;
77139
77140 #define define_one_global_ro(_name) \
77141 static struct global_attr _name = \
77142 @@ -225,7 +226,7 @@ struct cpufreq_driver {
77143 int (*suspend) (struct cpufreq_policy *policy);
77144 int (*resume) (struct cpufreq_policy *policy);
77145 struct freq_attr **attr;
77146 -};
77147 +} __do_const;
77148
77149 /* flags */
77150 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77151 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77152 index 50fcbb0..9d2dbd9 100644
77153 --- a/include/linux/cpuidle.h
77154 +++ b/include/linux/cpuidle.h
77155 @@ -50,7 +50,8 @@ struct cpuidle_state {
77156 int index);
77157
77158 int (*enter_dead) (struct cpuidle_device *dev, int index);
77159 -};
77160 +} __do_const;
77161 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77162
77163 /* Idle State Flags */
77164 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77165 @@ -192,7 +193,7 @@ struct cpuidle_governor {
77166 void (*reflect) (struct cpuidle_device *dev, int index);
77167
77168 struct module *owner;
77169 -};
77170 +} __do_const;
77171
77172 #ifdef CONFIG_CPU_IDLE
77173 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77174 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77175 index d08e4d2..95fad61 100644
77176 --- a/include/linux/cpumask.h
77177 +++ b/include/linux/cpumask.h
77178 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77179 }
77180
77181 /* Valid inputs for n are -1 and 0. */
77182 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77183 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77184 {
77185 return n+1;
77186 }
77187
77188 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77189 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77190 {
77191 return n+1;
77192 }
77193
77194 -static inline unsigned int cpumask_next_and(int n,
77195 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77196 const struct cpumask *srcp,
77197 const struct cpumask *andp)
77198 {
77199 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77200 *
77201 * Returns >= nr_cpu_ids if no further cpus set.
77202 */
77203 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77204 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77205 {
77206 /* -1 is a legal arg here. */
77207 if (n != -1)
77208 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77209 *
77210 * Returns >= nr_cpu_ids if no further cpus unset.
77211 */
77212 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77213 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77214 {
77215 /* -1 is a legal arg here. */
77216 if (n != -1)
77217 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77218 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77219 }
77220
77221 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77222 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77223 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77224
77225 /**
77226 diff --git a/include/linux/cred.h b/include/linux/cred.h
77227 index 04421e8..117e17a 100644
77228 --- a/include/linux/cred.h
77229 +++ b/include/linux/cred.h
77230 @@ -35,7 +35,7 @@ struct group_info {
77231 int nblocks;
77232 kgid_t small_block[NGROUPS_SMALL];
77233 kgid_t *blocks[0];
77234 -};
77235 +} __randomize_layout;
77236
77237 /**
77238 * get_group_info - Get a reference to a group info structure
77239 @@ -136,7 +136,7 @@ struct cred {
77240 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77241 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77242 struct rcu_head rcu; /* RCU deletion hook */
77243 -};
77244 +} __randomize_layout;
77245
77246 extern void __put_cred(struct cred *);
77247 extern void exit_creds(struct task_struct *);
77248 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77249 static inline void validate_process_creds(void)
77250 {
77251 }
77252 +static inline void validate_task_creds(struct task_struct *task)
77253 +{
77254 +}
77255 #endif
77256
77257 /**
77258 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77259 index b92eadf..b4ecdc1 100644
77260 --- a/include/linux/crypto.h
77261 +++ b/include/linux/crypto.h
77262 @@ -373,7 +373,7 @@ struct cipher_tfm {
77263 const u8 *key, unsigned int keylen);
77264 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77265 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77266 -};
77267 +} __no_const;
77268
77269 struct hash_tfm {
77270 int (*init)(struct hash_desc *desc);
77271 @@ -394,13 +394,13 @@ struct compress_tfm {
77272 int (*cot_decompress)(struct crypto_tfm *tfm,
77273 const u8 *src, unsigned int slen,
77274 u8 *dst, unsigned int *dlen);
77275 -};
77276 +} __no_const;
77277
77278 struct rng_tfm {
77279 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77280 unsigned int dlen);
77281 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77282 -};
77283 +} __no_const;
77284
77285 #define crt_ablkcipher crt_u.ablkcipher
77286 #define crt_aead crt_u.aead
77287 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77288 index 653589e..4ef254a 100644
77289 --- a/include/linux/ctype.h
77290 +++ b/include/linux/ctype.h
77291 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77292 * Fast implementation of tolower() for internal usage. Do not use in your
77293 * code.
77294 */
77295 -static inline char _tolower(const char c)
77296 +static inline unsigned char _tolower(const unsigned char c)
77297 {
77298 return c | 0x20;
77299 }
77300 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77301 index bf72e9a..4ca7927 100644
77302 --- a/include/linux/dcache.h
77303 +++ b/include/linux/dcache.h
77304 @@ -133,7 +133,7 @@ struct dentry {
77305 } d_u;
77306 struct list_head d_subdirs; /* our children */
77307 struct hlist_node d_alias; /* inode alias list */
77308 -};
77309 +} __randomize_layout;
77310
77311 /*
77312 * dentry->d_lock spinlock nesting subclasses:
77313 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77314 index 7925bf0..d5143d2 100644
77315 --- a/include/linux/decompress/mm.h
77316 +++ b/include/linux/decompress/mm.h
77317 @@ -77,7 +77,7 @@ static void free(void *where)
77318 * warnings when not needed (indeed large_malloc / large_free are not
77319 * needed by inflate */
77320
77321 -#define malloc(a) kmalloc(a, GFP_KERNEL)
77322 +#define malloc(a) kmalloc((a), GFP_KERNEL)
77323 #define free(a) kfree(a)
77324
77325 #define large_malloc(a) vmalloc(a)
77326 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77327 index d48dc00..211ee54 100644
77328 --- a/include/linux/devfreq.h
77329 +++ b/include/linux/devfreq.h
77330 @@ -114,7 +114,7 @@ struct devfreq_governor {
77331 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77332 int (*event_handler)(struct devfreq *devfreq,
77333 unsigned int event, void *data);
77334 -};
77335 +} __do_const;
77336
77337 /**
77338 * struct devfreq - Device devfreq structure
77339 diff --git a/include/linux/device.h b/include/linux/device.h
77340 index 952b010..d5b7691 100644
77341 --- a/include/linux/device.h
77342 +++ b/include/linux/device.h
77343 @@ -310,7 +310,7 @@ struct subsys_interface {
77344 struct list_head node;
77345 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77346 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77347 -};
77348 +} __do_const;
77349
77350 int subsys_interface_register(struct subsys_interface *sif);
77351 void subsys_interface_unregister(struct subsys_interface *sif);
77352 @@ -506,7 +506,7 @@ struct device_type {
77353 void (*release)(struct device *dev);
77354
77355 const struct dev_pm_ops *pm;
77356 -};
77357 +} __do_const;
77358
77359 /* interface for exporting device attributes */
77360 struct device_attribute {
77361 @@ -516,11 +516,12 @@ struct device_attribute {
77362 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77363 const char *buf, size_t count);
77364 };
77365 +typedef struct device_attribute __no_const device_attribute_no_const;
77366
77367 struct dev_ext_attribute {
77368 struct device_attribute attr;
77369 void *var;
77370 -};
77371 +} __do_const;
77372
77373 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77374 char *buf);
77375 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77376 index fd4aee2..1f28db9 100644
77377 --- a/include/linux/dma-mapping.h
77378 +++ b/include/linux/dma-mapping.h
77379 @@ -54,7 +54,7 @@ struct dma_map_ops {
77380 u64 (*get_required_mask)(struct device *dev);
77381 #endif
77382 int is_phys;
77383 -};
77384 +} __do_const;
77385
77386 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77387
77388 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77389 index 41cf0c3..f3b771c 100644
77390 --- a/include/linux/dmaengine.h
77391 +++ b/include/linux/dmaengine.h
77392 @@ -1114,9 +1114,9 @@ struct dma_pinned_list {
77393 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77394 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77395
77396 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77397 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77398 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77399 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77400 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77401 struct dma_pinned_list *pinned_list, struct page *page,
77402 unsigned int offset, size_t len);
77403
77404 diff --git a/include/linux/efi.h b/include/linux/efi.h
77405 index 11ce678..7b8c69c 100644
77406 --- a/include/linux/efi.h
77407 +++ b/include/linux/efi.h
77408 @@ -764,6 +764,7 @@ struct efivar_operations {
77409 efi_set_variable_t *set_variable;
77410 efi_query_variable_store_t *query_variable_store;
77411 };
77412 +typedef struct efivar_operations __no_const efivar_operations_no_const;
77413
77414 struct efivars {
77415 /*
77416 diff --git a/include/linux/elf.h b/include/linux/elf.h
77417 index 67a5fa7..b817372 100644
77418 --- a/include/linux/elf.h
77419 +++ b/include/linux/elf.h
77420 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77421 #define elf_note elf32_note
77422 #define elf_addr_t Elf32_Off
77423 #define Elf_Half Elf32_Half
77424 +#define elf_dyn Elf32_Dyn
77425
77426 #else
77427
77428 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77429 #define elf_note elf64_note
77430 #define elf_addr_t Elf64_Off
77431 #define Elf_Half Elf64_Half
77432 +#define elf_dyn Elf64_Dyn
77433
77434 #endif
77435
77436 diff --git a/include/linux/err.h b/include/linux/err.h
77437 index 15f92e0..e825a8e 100644
77438 --- a/include/linux/err.h
77439 +++ b/include/linux/err.h
77440 @@ -19,12 +19,12 @@
77441
77442 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77443
77444 -static inline void * __must_check ERR_PTR(long error)
77445 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77446 {
77447 return (void *) error;
77448 }
77449
77450 -static inline long __must_check PTR_ERR(__force const void *ptr)
77451 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77452 {
77453 return (long) ptr;
77454 }
77455 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77456 index 21c59af..6057a03 100644
77457 --- a/include/linux/extcon.h
77458 +++ b/include/linux/extcon.h
77459 @@ -135,7 +135,7 @@ struct extcon_dev {
77460 /* /sys/class/extcon/.../mutually_exclusive/... */
77461 struct attribute_group attr_g_muex;
77462 struct attribute **attrs_muex;
77463 - struct device_attribute *d_attrs_muex;
77464 + device_attribute_no_const *d_attrs_muex;
77465 };
77466
77467 /**
77468 diff --git a/include/linux/fb.h b/include/linux/fb.h
77469 index 70c4836..ff3daec 100644
77470 --- a/include/linux/fb.h
77471 +++ b/include/linux/fb.h
77472 @@ -304,7 +304,7 @@ struct fb_ops {
77473 /* called at KDB enter and leave time to prepare the console */
77474 int (*fb_debug_enter)(struct fb_info *info);
77475 int (*fb_debug_leave)(struct fb_info *info);
77476 -};
77477 +} __do_const;
77478
77479 #ifdef CONFIG_FB_TILEBLITTING
77480 #define FB_TILE_CURSOR_NONE 0
77481 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77482 index 085197b..0fa6f0b 100644
77483 --- a/include/linux/fdtable.h
77484 +++ b/include/linux/fdtable.h
77485 @@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77486 void put_files_struct(struct files_struct *fs);
77487 void reset_files_struct(struct files_struct *);
77488 int unshare_files(struct files_struct **);
77489 -struct files_struct *dup_fd(struct files_struct *, int *);
77490 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77491 void do_close_on_exec(struct files_struct *);
77492 int iterate_fd(struct files_struct *, unsigned,
77493 int (*)(const void *, struct file *, unsigned),
77494 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77495 index 8293262..2b3b8bd 100644
77496 --- a/include/linux/frontswap.h
77497 +++ b/include/linux/frontswap.h
77498 @@ -11,7 +11,7 @@ struct frontswap_ops {
77499 int (*load)(unsigned, pgoff_t, struct page *);
77500 void (*invalidate_page)(unsigned, pgoff_t);
77501 void (*invalidate_area)(unsigned);
77502 -};
77503 +} __no_const;
77504
77505 extern bool frontswap_enabled;
77506 extern struct frontswap_ops *
77507 diff --git a/include/linux/fs.h b/include/linux/fs.h
77508 index 121f11f..0f2a863 100644
77509 --- a/include/linux/fs.h
77510 +++ b/include/linux/fs.h
77511 @@ -423,7 +423,7 @@ struct address_space {
77512 spinlock_t private_lock; /* for use by the address_space */
77513 struct list_head private_list; /* ditto */
77514 void *private_data; /* ditto */
77515 -} __attribute__((aligned(sizeof(long))));
77516 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77517 /*
77518 * On most architectures that alignment is already the case; but
77519 * must be enforced here for CRIS, to let the least significant bit
77520 @@ -466,7 +466,7 @@ struct block_device {
77521 int bd_fsfreeze_count;
77522 /* Mutex for freeze */
77523 struct mutex bd_fsfreeze_mutex;
77524 -};
77525 +} __randomize_layout;
77526
77527 /*
77528 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77529 @@ -610,7 +610,7 @@ struct inode {
77530 atomic_t i_readcount; /* struct files open RO */
77531 #endif
77532 void *i_private; /* fs or device private pointer */
77533 -};
77534 +} __randomize_layout;
77535
77536 static inline int inode_unhashed(struct inode *inode)
77537 {
77538 @@ -808,7 +808,7 @@ struct file {
77539 #ifdef CONFIG_DEBUG_WRITECOUNT
77540 unsigned long f_mnt_write_state;
77541 #endif
77542 -};
77543 +} __randomize_layout;
77544
77545 struct file_handle {
77546 __u32 handle_bytes;
77547 @@ -978,7 +978,7 @@ struct file_lock {
77548 int state; /* state of grant or error if -ve */
77549 } afs;
77550 } fl_u;
77551 -};
77552 +} __randomize_layout;
77553
77554 /* The following constant reflects the upper bound of the file/locking space */
77555 #ifndef OFFSET_MAX
77556 @@ -1325,7 +1325,7 @@ struct super_block {
77557 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
77558 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
77559 struct rcu_head rcu;
77560 -};
77561 +} __randomize_layout;
77562
77563 extern struct timespec current_fs_time(struct super_block *sb);
77564
77565 @@ -1547,7 +1547,8 @@ struct file_operations {
77566 long (*fallocate)(struct file *file, int mode, loff_t offset,
77567 loff_t len);
77568 int (*show_fdinfo)(struct seq_file *m, struct file *f);
77569 -};
77570 +} __do_const __randomize_layout;
77571 +typedef struct file_operations __no_const file_operations_no_const;
77572
77573 struct inode_operations {
77574 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
77575 @@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
77576 return !IS_DEADDIR(inode);
77577 }
77578
77579 +static inline bool is_sidechannel_device(const struct inode *inode)
77580 +{
77581 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
77582 + umode_t mode = inode->i_mode;
77583 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
77584 +#else
77585 + return false;
77586 +#endif
77587 +}
77588 +
77589 #endif /* _LINUX_FS_H */
77590 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
77591 index 0efc3e6..fd23610 100644
77592 --- a/include/linux/fs_struct.h
77593 +++ b/include/linux/fs_struct.h
77594 @@ -6,13 +6,13 @@
77595 #include <linux/seqlock.h>
77596
77597 struct fs_struct {
77598 - int users;
77599 + atomic_t users;
77600 spinlock_t lock;
77601 seqcount_t seq;
77602 int umask;
77603 int in_exec;
77604 struct path root, pwd;
77605 -};
77606 +} __randomize_layout;
77607
77608 extern struct kmem_cache *fs_cachep;
77609
77610 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
77611 index 7714849..a4a5c7a 100644
77612 --- a/include/linux/fscache-cache.h
77613 +++ b/include/linux/fscache-cache.h
77614 @@ -113,7 +113,7 @@ struct fscache_operation {
77615 fscache_operation_release_t release;
77616 };
77617
77618 -extern atomic_t fscache_op_debug_id;
77619 +extern atomic_unchecked_t fscache_op_debug_id;
77620 extern void fscache_op_work_func(struct work_struct *work);
77621
77622 extern void fscache_enqueue_operation(struct fscache_operation *);
77623 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
77624 INIT_WORK(&op->work, fscache_op_work_func);
77625 atomic_set(&op->usage, 1);
77626 op->state = FSCACHE_OP_ST_INITIALISED;
77627 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
77628 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
77629 op->processor = processor;
77630 op->release = release;
77631 INIT_LIST_HEAD(&op->pend_link);
77632 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
77633 index 115bb81..e7b812b 100644
77634 --- a/include/linux/fscache.h
77635 +++ b/include/linux/fscache.h
77636 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
77637 * - this is mandatory for any object that may have data
77638 */
77639 void (*now_uncached)(void *cookie_netfs_data);
77640 -};
77641 +} __do_const;
77642
77643 /*
77644 * fscache cached network filesystem type
77645 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
77646 index 1c804b0..1432c2b 100644
77647 --- a/include/linux/fsnotify.h
77648 +++ b/include/linux/fsnotify.h
77649 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
77650 struct inode *inode = file_inode(file);
77651 __u32 mask = FS_ACCESS;
77652
77653 + if (is_sidechannel_device(inode))
77654 + return;
77655 +
77656 if (S_ISDIR(inode->i_mode))
77657 mask |= FS_ISDIR;
77658
77659 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
77660 struct inode *inode = file_inode(file);
77661 __u32 mask = FS_MODIFY;
77662
77663 + if (is_sidechannel_device(inode))
77664 + return;
77665 +
77666 if (S_ISDIR(inode->i_mode))
77667 mask |= FS_ISDIR;
77668
77669 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
77670 */
77671 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
77672 {
77673 - return kstrdup(name, GFP_KERNEL);
77674 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
77675 }
77676
77677 /*
77678 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
77679 index 9f3c275..8bdff5d 100644
77680 --- a/include/linux/genhd.h
77681 +++ b/include/linux/genhd.h
77682 @@ -194,7 +194,7 @@ struct gendisk {
77683 struct kobject *slave_dir;
77684
77685 struct timer_rand_state *random;
77686 - atomic_t sync_io; /* RAID */
77687 + atomic_unchecked_t sync_io; /* RAID */
77688 struct disk_events *ev;
77689 #ifdef CONFIG_BLK_DEV_INTEGRITY
77690 struct blk_integrity *integrity;
77691 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
77692 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
77693
77694 /* drivers/char/random.c */
77695 -extern void add_disk_randomness(struct gendisk *disk);
77696 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
77697 extern void rand_initialize_disk(struct gendisk *disk);
77698
77699 static inline sector_t get_start_sect(struct block_device *bdev)
77700 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
77701 index c0894dd..2fbf10c 100644
77702 --- a/include/linux/genl_magic_func.h
77703 +++ b/include/linux/genl_magic_func.h
77704 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
77705 },
77706
77707 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
77708 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
77709 +static struct genl_ops ZZZ_genl_ops[] = {
77710 #include GENL_MAGIC_INCLUDE_FILE
77711 };
77712
77713 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
77714 index 9b4dd49..61fd41d 100644
77715 --- a/include/linux/gfp.h
77716 +++ b/include/linux/gfp.h
77717 @@ -35,6 +35,13 @@ struct vm_area_struct;
77718 #define ___GFP_NO_KSWAPD 0x400000u
77719 #define ___GFP_OTHER_NODE 0x800000u
77720 #define ___GFP_WRITE 0x1000000u
77721 +
77722 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77723 +#define ___GFP_USERCOPY 0x2000000u
77724 +#else
77725 +#define ___GFP_USERCOPY 0
77726 +#endif
77727 +
77728 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
77729
77730 /*
77731 @@ -92,6 +99,7 @@ struct vm_area_struct;
77732 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
77733 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
77734 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
77735 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
77736
77737 /*
77738 * This may seem redundant, but it's a way of annotating false positives vs.
77739 @@ -99,7 +107,7 @@ struct vm_area_struct;
77740 */
77741 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
77742
77743 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
77744 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
77745 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
77746
77747 /* This equals 0, but use constants in case they ever change */
77748 @@ -153,6 +161,8 @@ struct vm_area_struct;
77749 /* 4GB DMA on some platforms */
77750 #define GFP_DMA32 __GFP_DMA32
77751
77752 +#define GFP_USERCOPY __GFP_USERCOPY
77753 +
77754 /* Convert GFP flags to their corresponding migrate type */
77755 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
77756 {
77757 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
77758 new file mode 100644
77759 index 0000000..edb2cb6
77760 --- /dev/null
77761 +++ b/include/linux/gracl.h
77762 @@ -0,0 +1,340 @@
77763 +#ifndef GR_ACL_H
77764 +#define GR_ACL_H
77765 +
77766 +#include <linux/grdefs.h>
77767 +#include <linux/resource.h>
77768 +#include <linux/capability.h>
77769 +#include <linux/dcache.h>
77770 +#include <asm/resource.h>
77771 +
77772 +/* Major status information */
77773 +
77774 +#define GR_VERSION "grsecurity 3.0"
77775 +#define GRSECURITY_VERSION 0x3000
77776 +
77777 +enum {
77778 + GR_SHUTDOWN = 0,
77779 + GR_ENABLE = 1,
77780 + GR_SPROLE = 2,
77781 + GR_OLDRELOAD = 3,
77782 + GR_SEGVMOD = 4,
77783 + GR_STATUS = 5,
77784 + GR_UNSPROLE = 6,
77785 + GR_PASSSET = 7,
77786 + GR_SPROLEPAM = 8,
77787 + GR_RELOAD = 9,
77788 +};
77789 +
77790 +/* Password setup definitions
77791 + * kernel/grhash.c */
77792 +enum {
77793 + GR_PW_LEN = 128,
77794 + GR_SALT_LEN = 16,
77795 + GR_SHA_LEN = 32,
77796 +};
77797 +
77798 +enum {
77799 + GR_SPROLE_LEN = 64,
77800 +};
77801 +
77802 +enum {
77803 + GR_NO_GLOB = 0,
77804 + GR_REG_GLOB,
77805 + GR_CREATE_GLOB
77806 +};
77807 +
77808 +#define GR_NLIMITS 32
77809 +
77810 +/* Begin Data Structures */
77811 +
77812 +struct sprole_pw {
77813 + unsigned char *rolename;
77814 + unsigned char salt[GR_SALT_LEN];
77815 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
77816 +};
77817 +
77818 +struct name_entry {
77819 + __u32 key;
77820 + ino_t inode;
77821 + dev_t device;
77822 + char *name;
77823 + __u16 len;
77824 + __u8 deleted;
77825 + struct name_entry *prev;
77826 + struct name_entry *next;
77827 +};
77828 +
77829 +struct inodev_entry {
77830 + struct name_entry *nentry;
77831 + struct inodev_entry *prev;
77832 + struct inodev_entry *next;
77833 +};
77834 +
77835 +struct acl_role_db {
77836 + struct acl_role_label **r_hash;
77837 + __u32 r_size;
77838 +};
77839 +
77840 +struct inodev_db {
77841 + struct inodev_entry **i_hash;
77842 + __u32 i_size;
77843 +};
77844 +
77845 +struct name_db {
77846 + struct name_entry **n_hash;
77847 + __u32 n_size;
77848 +};
77849 +
77850 +struct crash_uid {
77851 + uid_t uid;
77852 + unsigned long expires;
77853 +};
77854 +
77855 +struct gr_hash_struct {
77856 + void **table;
77857 + void **nametable;
77858 + void *first;
77859 + __u32 table_size;
77860 + __u32 used_size;
77861 + int type;
77862 +};
77863 +
77864 +/* Userspace Grsecurity ACL data structures */
77865 +
77866 +struct acl_subject_label {
77867 + char *filename;
77868 + ino_t inode;
77869 + dev_t device;
77870 + __u32 mode;
77871 + kernel_cap_t cap_mask;
77872 + kernel_cap_t cap_lower;
77873 + kernel_cap_t cap_invert_audit;
77874 +
77875 + struct rlimit res[GR_NLIMITS];
77876 + __u32 resmask;
77877 +
77878 + __u8 user_trans_type;
77879 + __u8 group_trans_type;
77880 + uid_t *user_transitions;
77881 + gid_t *group_transitions;
77882 + __u16 user_trans_num;
77883 + __u16 group_trans_num;
77884 +
77885 + __u32 sock_families[2];
77886 + __u32 ip_proto[8];
77887 + __u32 ip_type;
77888 + struct acl_ip_label **ips;
77889 + __u32 ip_num;
77890 + __u32 inaddr_any_override;
77891 +
77892 + __u32 crashes;
77893 + unsigned long expires;
77894 +
77895 + struct acl_subject_label *parent_subject;
77896 + struct gr_hash_struct *hash;
77897 + struct acl_subject_label *prev;
77898 + struct acl_subject_label *next;
77899 +
77900 + struct acl_object_label **obj_hash;
77901 + __u32 obj_hash_size;
77902 + __u16 pax_flags;
77903 +};
77904 +
77905 +struct role_allowed_ip {
77906 + __u32 addr;
77907 + __u32 netmask;
77908 +
77909 + struct role_allowed_ip *prev;
77910 + struct role_allowed_ip *next;
77911 +};
77912 +
77913 +struct role_transition {
77914 + char *rolename;
77915 +
77916 + struct role_transition *prev;
77917 + struct role_transition *next;
77918 +};
77919 +
77920 +struct acl_role_label {
77921 + char *rolename;
77922 + uid_t uidgid;
77923 + __u16 roletype;
77924 +
77925 + __u16 auth_attempts;
77926 + unsigned long expires;
77927 +
77928 + struct acl_subject_label *root_label;
77929 + struct gr_hash_struct *hash;
77930 +
77931 + struct acl_role_label *prev;
77932 + struct acl_role_label *next;
77933 +
77934 + struct role_transition *transitions;
77935 + struct role_allowed_ip *allowed_ips;
77936 + uid_t *domain_children;
77937 + __u16 domain_child_num;
77938 +
77939 + umode_t umask;
77940 +
77941 + struct acl_subject_label **subj_hash;
77942 + __u32 subj_hash_size;
77943 +};
77944 +
77945 +struct user_acl_role_db {
77946 + struct acl_role_label **r_table;
77947 + __u32 num_pointers; /* Number of allocations to track */
77948 + __u32 num_roles; /* Number of roles */
77949 + __u32 num_domain_children; /* Number of domain children */
77950 + __u32 num_subjects; /* Number of subjects */
77951 + __u32 num_objects; /* Number of objects */
77952 +};
77953 +
77954 +struct acl_object_label {
77955 + char *filename;
77956 + ino_t inode;
77957 + dev_t device;
77958 + __u32 mode;
77959 +
77960 + struct acl_subject_label *nested;
77961 + struct acl_object_label *globbed;
77962 +
77963 + /* next two structures not used */
77964 +
77965 + struct acl_object_label *prev;
77966 + struct acl_object_label *next;
77967 +};
77968 +
77969 +struct acl_ip_label {
77970 + char *iface;
77971 + __u32 addr;
77972 + __u32 netmask;
77973 + __u16 low, high;
77974 + __u8 mode;
77975 + __u32 type;
77976 + __u32 proto[8];
77977 +
77978 + /* next two structures not used */
77979 +
77980 + struct acl_ip_label *prev;
77981 + struct acl_ip_label *next;
77982 +};
77983 +
77984 +struct gr_arg {
77985 + struct user_acl_role_db role_db;
77986 + unsigned char pw[GR_PW_LEN];
77987 + unsigned char salt[GR_SALT_LEN];
77988 + unsigned char sum[GR_SHA_LEN];
77989 + unsigned char sp_role[GR_SPROLE_LEN];
77990 + struct sprole_pw *sprole_pws;
77991 + dev_t segv_device;
77992 + ino_t segv_inode;
77993 + uid_t segv_uid;
77994 + __u16 num_sprole_pws;
77995 + __u16 mode;
77996 +};
77997 +
77998 +struct gr_arg_wrapper {
77999 + struct gr_arg *arg;
78000 + __u32 version;
78001 + __u32 size;
78002 +};
78003 +
78004 +struct subject_map {
78005 + struct acl_subject_label *user;
78006 + struct acl_subject_label *kernel;
78007 + struct subject_map *prev;
78008 + struct subject_map *next;
78009 +};
78010 +
78011 +struct acl_subj_map_db {
78012 + struct subject_map **s_hash;
78013 + __u32 s_size;
78014 +};
78015 +
78016 +struct gr_policy_state {
78017 + struct sprole_pw **acl_special_roles;
78018 + __u16 num_sprole_pws;
78019 + struct acl_role_label *kernel_role;
78020 + struct acl_role_label *role_list;
78021 + struct acl_role_label *default_role;
78022 + struct acl_role_db acl_role_set;
78023 + struct acl_subj_map_db subj_map_set;
78024 + struct name_db name_set;
78025 + struct inodev_db inodev_set;
78026 +};
78027 +
78028 +struct gr_alloc_state {
78029 + unsigned long alloc_stack_next;
78030 + unsigned long alloc_stack_size;
78031 + void **alloc_stack;
78032 +};
78033 +
78034 +struct gr_reload_state {
78035 + struct gr_policy_state oldpolicy;
78036 + struct gr_alloc_state oldalloc;
78037 + struct gr_policy_state newpolicy;
78038 + struct gr_alloc_state newalloc;
78039 + struct gr_policy_state *oldpolicy_ptr;
78040 + struct gr_alloc_state *oldalloc_ptr;
78041 + unsigned char oldmode;
78042 +};
78043 +
78044 +/* End Data Structures Section */
78045 +
78046 +/* Hash functions generated by empirical testing by Brad Spengler
78047 + Makes good use of the low bits of the inode. Generally 0-1 times
78048 + in loop for successful match. 0-3 for unsuccessful match.
78049 + Shift/add algorithm with modulus of table size and an XOR*/
78050 +
78051 +static __inline__ unsigned int
78052 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78053 +{
78054 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
78055 +}
78056 +
78057 + static __inline__ unsigned int
78058 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78059 +{
78060 + return ((const unsigned long)userp % sz);
78061 +}
78062 +
78063 +static __inline__ unsigned int
78064 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78065 +{
78066 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78067 +}
78068 +
78069 +static __inline__ unsigned int
78070 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78071 +{
78072 + return full_name_hash((const unsigned char *)name, len) % sz;
78073 +}
78074 +
78075 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78076 + subj = NULL; \
78077 + iter = 0; \
78078 + while (iter < role->subj_hash_size) { \
78079 + if (subj == NULL) \
78080 + subj = role->subj_hash[iter]; \
78081 + if (subj == NULL) { \
78082 + iter++; \
78083 + continue; \
78084 + }
78085 +
78086 +#define FOR_EACH_SUBJECT_END(subj,iter) \
78087 + subj = subj->next; \
78088 + if (subj == NULL) \
78089 + iter++; \
78090 + }
78091 +
78092 +
78093 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78094 + subj = role->hash->first; \
78095 + while (subj != NULL) {
78096 +
78097 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78098 + subj = subj->next; \
78099 + }
78100 +
78101 +#endif
78102 +
78103 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78104 new file mode 100644
78105 index 0000000..33ebd1f
78106 --- /dev/null
78107 +++ b/include/linux/gracl_compat.h
78108 @@ -0,0 +1,156 @@
78109 +#ifndef GR_ACL_COMPAT_H
78110 +#define GR_ACL_COMPAT_H
78111 +
78112 +#include <linux/resource.h>
78113 +#include <asm/resource.h>
78114 +
78115 +struct sprole_pw_compat {
78116 + compat_uptr_t rolename;
78117 + unsigned char salt[GR_SALT_LEN];
78118 + unsigned char sum[GR_SHA_LEN];
78119 +};
78120 +
78121 +struct gr_hash_struct_compat {
78122 + compat_uptr_t table;
78123 + compat_uptr_t nametable;
78124 + compat_uptr_t first;
78125 + __u32 table_size;
78126 + __u32 used_size;
78127 + int type;
78128 +};
78129 +
78130 +struct acl_subject_label_compat {
78131 + compat_uptr_t filename;
78132 + compat_ino_t inode;
78133 + __u32 device;
78134 + __u32 mode;
78135 + kernel_cap_t cap_mask;
78136 + kernel_cap_t cap_lower;
78137 + kernel_cap_t cap_invert_audit;
78138 +
78139 + struct compat_rlimit res[GR_NLIMITS];
78140 + __u32 resmask;
78141 +
78142 + __u8 user_trans_type;
78143 + __u8 group_trans_type;
78144 + compat_uptr_t user_transitions;
78145 + compat_uptr_t group_transitions;
78146 + __u16 user_trans_num;
78147 + __u16 group_trans_num;
78148 +
78149 + __u32 sock_families[2];
78150 + __u32 ip_proto[8];
78151 + __u32 ip_type;
78152 + compat_uptr_t ips;
78153 + __u32 ip_num;
78154 + __u32 inaddr_any_override;
78155 +
78156 + __u32 crashes;
78157 + compat_ulong_t expires;
78158 +
78159 + compat_uptr_t parent_subject;
78160 + compat_uptr_t hash;
78161 + compat_uptr_t prev;
78162 + compat_uptr_t next;
78163 +
78164 + compat_uptr_t obj_hash;
78165 + __u32 obj_hash_size;
78166 + __u16 pax_flags;
78167 +};
78168 +
78169 +struct role_allowed_ip_compat {
78170 + __u32 addr;
78171 + __u32 netmask;
78172 +
78173 + compat_uptr_t prev;
78174 + compat_uptr_t next;
78175 +};
78176 +
78177 +struct role_transition_compat {
78178 + compat_uptr_t rolename;
78179 +
78180 + compat_uptr_t prev;
78181 + compat_uptr_t next;
78182 +};
78183 +
78184 +struct acl_role_label_compat {
78185 + compat_uptr_t rolename;
78186 + uid_t uidgid;
78187 + __u16 roletype;
78188 +
78189 + __u16 auth_attempts;
78190 + compat_ulong_t expires;
78191 +
78192 + compat_uptr_t root_label;
78193 + compat_uptr_t hash;
78194 +
78195 + compat_uptr_t prev;
78196 + compat_uptr_t next;
78197 +
78198 + compat_uptr_t transitions;
78199 + compat_uptr_t allowed_ips;
78200 + compat_uptr_t domain_children;
78201 + __u16 domain_child_num;
78202 +
78203 + umode_t umask;
78204 +
78205 + compat_uptr_t subj_hash;
78206 + __u32 subj_hash_size;
78207 +};
78208 +
78209 +struct user_acl_role_db_compat {
78210 + compat_uptr_t r_table;
78211 + __u32 num_pointers;
78212 + __u32 num_roles;
78213 + __u32 num_domain_children;
78214 + __u32 num_subjects;
78215 + __u32 num_objects;
78216 +};
78217 +
78218 +struct acl_object_label_compat {
78219 + compat_uptr_t filename;
78220 + compat_ino_t inode;
78221 + __u32 device;
78222 + __u32 mode;
78223 +
78224 + compat_uptr_t nested;
78225 + compat_uptr_t globbed;
78226 +
78227 + compat_uptr_t prev;
78228 + compat_uptr_t next;
78229 +};
78230 +
78231 +struct acl_ip_label_compat {
78232 + compat_uptr_t iface;
78233 + __u32 addr;
78234 + __u32 netmask;
78235 + __u16 low, high;
78236 + __u8 mode;
78237 + __u32 type;
78238 + __u32 proto[8];
78239 +
78240 + compat_uptr_t prev;
78241 + compat_uptr_t next;
78242 +};
78243 +
78244 +struct gr_arg_compat {
78245 + struct user_acl_role_db_compat role_db;
78246 + unsigned char pw[GR_PW_LEN];
78247 + unsigned char salt[GR_SALT_LEN];
78248 + unsigned char sum[GR_SHA_LEN];
78249 + unsigned char sp_role[GR_SPROLE_LEN];
78250 + compat_uptr_t sprole_pws;
78251 + __u32 segv_device;
78252 + compat_ino_t segv_inode;
78253 + uid_t segv_uid;
78254 + __u16 num_sprole_pws;
78255 + __u16 mode;
78256 +};
78257 +
78258 +struct gr_arg_wrapper_compat {
78259 + compat_uptr_t arg;
78260 + __u32 version;
78261 + __u32 size;
78262 +};
78263 +
78264 +#endif
78265 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78266 new file mode 100644
78267 index 0000000..323ecf2
78268 --- /dev/null
78269 +++ b/include/linux/gralloc.h
78270 @@ -0,0 +1,9 @@
78271 +#ifndef __GRALLOC_H
78272 +#define __GRALLOC_H
78273 +
78274 +void acl_free_all(void);
78275 +int acl_alloc_stack_init(unsigned long size);
78276 +void *acl_alloc(unsigned long len);
78277 +void *acl_alloc_num(unsigned long num, unsigned long len);
78278 +
78279 +#endif
78280 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78281 new file mode 100644
78282 index 0000000..be66033
78283 --- /dev/null
78284 +++ b/include/linux/grdefs.h
78285 @@ -0,0 +1,140 @@
78286 +#ifndef GRDEFS_H
78287 +#define GRDEFS_H
78288 +
78289 +/* Begin grsecurity status declarations */
78290 +
78291 +enum {
78292 + GR_READY = 0x01,
78293 + GR_STATUS_INIT = 0x00 // disabled state
78294 +};
78295 +
78296 +/* Begin ACL declarations */
78297 +
78298 +/* Role flags */
78299 +
78300 +enum {
78301 + GR_ROLE_USER = 0x0001,
78302 + GR_ROLE_GROUP = 0x0002,
78303 + GR_ROLE_DEFAULT = 0x0004,
78304 + GR_ROLE_SPECIAL = 0x0008,
78305 + GR_ROLE_AUTH = 0x0010,
78306 + GR_ROLE_NOPW = 0x0020,
78307 + GR_ROLE_GOD = 0x0040,
78308 + GR_ROLE_LEARN = 0x0080,
78309 + GR_ROLE_TPE = 0x0100,
78310 + GR_ROLE_DOMAIN = 0x0200,
78311 + GR_ROLE_PAM = 0x0400,
78312 + GR_ROLE_PERSIST = 0x0800
78313 +};
78314 +
78315 +/* ACL Subject and Object mode flags */
78316 +enum {
78317 + GR_DELETED = 0x80000000
78318 +};
78319 +
78320 +/* ACL Object-only mode flags */
78321 +enum {
78322 + GR_READ = 0x00000001,
78323 + GR_APPEND = 0x00000002,
78324 + GR_WRITE = 0x00000004,
78325 + GR_EXEC = 0x00000008,
78326 + GR_FIND = 0x00000010,
78327 + GR_INHERIT = 0x00000020,
78328 + GR_SETID = 0x00000040,
78329 + GR_CREATE = 0x00000080,
78330 + GR_DELETE = 0x00000100,
78331 + GR_LINK = 0x00000200,
78332 + GR_AUDIT_READ = 0x00000400,
78333 + GR_AUDIT_APPEND = 0x00000800,
78334 + GR_AUDIT_WRITE = 0x00001000,
78335 + GR_AUDIT_EXEC = 0x00002000,
78336 + GR_AUDIT_FIND = 0x00004000,
78337 + GR_AUDIT_INHERIT= 0x00008000,
78338 + GR_AUDIT_SETID = 0x00010000,
78339 + GR_AUDIT_CREATE = 0x00020000,
78340 + GR_AUDIT_DELETE = 0x00040000,
78341 + GR_AUDIT_LINK = 0x00080000,
78342 + GR_PTRACERD = 0x00100000,
78343 + GR_NOPTRACE = 0x00200000,
78344 + GR_SUPPRESS = 0x00400000,
78345 + GR_NOLEARN = 0x00800000,
78346 + GR_INIT_TRANSFER= 0x01000000
78347 +};
78348 +
78349 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78350 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78351 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78352 +
78353 +/* ACL subject-only mode flags */
78354 +enum {
78355 + GR_KILL = 0x00000001,
78356 + GR_VIEW = 0x00000002,
78357 + GR_PROTECTED = 0x00000004,
78358 + GR_LEARN = 0x00000008,
78359 + GR_OVERRIDE = 0x00000010,
78360 + /* just a placeholder, this mode is only used in userspace */
78361 + GR_DUMMY = 0x00000020,
78362 + GR_PROTSHM = 0x00000040,
78363 + GR_KILLPROC = 0x00000080,
78364 + GR_KILLIPPROC = 0x00000100,
78365 + /* just a placeholder, this mode is only used in userspace */
78366 + GR_NOTROJAN = 0x00000200,
78367 + GR_PROTPROCFD = 0x00000400,
78368 + GR_PROCACCT = 0x00000800,
78369 + GR_RELAXPTRACE = 0x00001000,
78370 + //GR_NESTED = 0x00002000,
78371 + GR_INHERITLEARN = 0x00004000,
78372 + GR_PROCFIND = 0x00008000,
78373 + GR_POVERRIDE = 0x00010000,
78374 + GR_KERNELAUTH = 0x00020000,
78375 + GR_ATSECURE = 0x00040000,
78376 + GR_SHMEXEC = 0x00080000
78377 +};
78378 +
78379 +enum {
78380 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78381 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78382 + GR_PAX_ENABLE_MPROTECT = 0x0004,
78383 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
78384 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78385 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78386 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78387 + GR_PAX_DISABLE_MPROTECT = 0x0400,
78388 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
78389 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78390 +};
78391 +
78392 +enum {
78393 + GR_ID_USER = 0x01,
78394 + GR_ID_GROUP = 0x02,
78395 +};
78396 +
78397 +enum {
78398 + GR_ID_ALLOW = 0x01,
78399 + GR_ID_DENY = 0x02,
78400 +};
78401 +
78402 +#define GR_CRASH_RES 31
78403 +#define GR_UIDTABLE_MAX 500
78404 +
78405 +/* begin resource learning section */
78406 +enum {
78407 + GR_RLIM_CPU_BUMP = 60,
78408 + GR_RLIM_FSIZE_BUMP = 50000,
78409 + GR_RLIM_DATA_BUMP = 10000,
78410 + GR_RLIM_STACK_BUMP = 1000,
78411 + GR_RLIM_CORE_BUMP = 10000,
78412 + GR_RLIM_RSS_BUMP = 500000,
78413 + GR_RLIM_NPROC_BUMP = 1,
78414 + GR_RLIM_NOFILE_BUMP = 5,
78415 + GR_RLIM_MEMLOCK_BUMP = 50000,
78416 + GR_RLIM_AS_BUMP = 500000,
78417 + GR_RLIM_LOCKS_BUMP = 2,
78418 + GR_RLIM_SIGPENDING_BUMP = 5,
78419 + GR_RLIM_MSGQUEUE_BUMP = 10000,
78420 + GR_RLIM_NICE_BUMP = 1,
78421 + GR_RLIM_RTPRIO_BUMP = 1,
78422 + GR_RLIM_RTTIME_BUMP = 1000000
78423 +};
78424 +
78425 +#endif
78426 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78427 new file mode 100644
78428 index 0000000..d25522e
78429 --- /dev/null
78430 +++ b/include/linux/grinternal.h
78431 @@ -0,0 +1,229 @@
78432 +#ifndef __GRINTERNAL_H
78433 +#define __GRINTERNAL_H
78434 +
78435 +#ifdef CONFIG_GRKERNSEC
78436 +
78437 +#include <linux/fs.h>
78438 +#include <linux/mnt_namespace.h>
78439 +#include <linux/nsproxy.h>
78440 +#include <linux/gracl.h>
78441 +#include <linux/grdefs.h>
78442 +#include <linux/grmsg.h>
78443 +
78444 +void gr_add_learn_entry(const char *fmt, ...)
78445 + __attribute__ ((format (printf, 1, 2)));
78446 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78447 + const struct vfsmount *mnt);
78448 +__u32 gr_check_create(const struct dentry *new_dentry,
78449 + const struct dentry *parent,
78450 + const struct vfsmount *mnt, const __u32 mode);
78451 +int gr_check_protected_task(const struct task_struct *task);
78452 +__u32 to_gr_audit(const __u32 reqmode);
78453 +int gr_set_acls(const int type);
78454 +int gr_acl_is_enabled(void);
78455 +char gr_roletype_to_char(void);
78456 +
78457 +void gr_handle_alertkill(struct task_struct *task);
78458 +char *gr_to_filename(const struct dentry *dentry,
78459 + const struct vfsmount *mnt);
78460 +char *gr_to_filename1(const struct dentry *dentry,
78461 + const struct vfsmount *mnt);
78462 +char *gr_to_filename2(const struct dentry *dentry,
78463 + const struct vfsmount *mnt);
78464 +char *gr_to_filename3(const struct dentry *dentry,
78465 + const struct vfsmount *mnt);
78466 +
78467 +extern int grsec_enable_ptrace_readexec;
78468 +extern int grsec_enable_harden_ptrace;
78469 +extern int grsec_enable_link;
78470 +extern int grsec_enable_fifo;
78471 +extern int grsec_enable_execve;
78472 +extern int grsec_enable_shm;
78473 +extern int grsec_enable_execlog;
78474 +extern int grsec_enable_signal;
78475 +extern int grsec_enable_audit_ptrace;
78476 +extern int grsec_enable_forkfail;
78477 +extern int grsec_enable_time;
78478 +extern int grsec_enable_rofs;
78479 +extern int grsec_deny_new_usb;
78480 +extern int grsec_enable_chroot_shmat;
78481 +extern int grsec_enable_chroot_mount;
78482 +extern int grsec_enable_chroot_double;
78483 +extern int grsec_enable_chroot_pivot;
78484 +extern int grsec_enable_chroot_chdir;
78485 +extern int grsec_enable_chroot_chmod;
78486 +extern int grsec_enable_chroot_mknod;
78487 +extern int grsec_enable_chroot_fchdir;
78488 +extern int grsec_enable_chroot_nice;
78489 +extern int grsec_enable_chroot_execlog;
78490 +extern int grsec_enable_chroot_caps;
78491 +extern int grsec_enable_chroot_sysctl;
78492 +extern int grsec_enable_chroot_unix;
78493 +extern int grsec_enable_symlinkown;
78494 +extern kgid_t grsec_symlinkown_gid;
78495 +extern int grsec_enable_tpe;
78496 +extern kgid_t grsec_tpe_gid;
78497 +extern int grsec_enable_tpe_all;
78498 +extern int grsec_enable_tpe_invert;
78499 +extern int grsec_enable_socket_all;
78500 +extern kgid_t grsec_socket_all_gid;
78501 +extern int grsec_enable_socket_client;
78502 +extern kgid_t grsec_socket_client_gid;
78503 +extern int grsec_enable_socket_server;
78504 +extern kgid_t grsec_socket_server_gid;
78505 +extern kgid_t grsec_audit_gid;
78506 +extern int grsec_enable_group;
78507 +extern int grsec_enable_log_rwxmaps;
78508 +extern int grsec_enable_mount;
78509 +extern int grsec_enable_chdir;
78510 +extern int grsec_resource_logging;
78511 +extern int grsec_enable_blackhole;
78512 +extern int grsec_lastack_retries;
78513 +extern int grsec_enable_brute;
78514 +extern int grsec_enable_harden_ipc;
78515 +extern int grsec_lock;
78516 +
78517 +extern spinlock_t grsec_alert_lock;
78518 +extern unsigned long grsec_alert_wtime;
78519 +extern unsigned long grsec_alert_fyet;
78520 +
78521 +extern spinlock_t grsec_audit_lock;
78522 +
78523 +extern rwlock_t grsec_exec_file_lock;
78524 +
78525 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78526 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78527 + (tsk)->exec_file->f_path.mnt) : "/")
78528 +
78529 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78530 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78531 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78532 +
78533 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78534 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
78535 + (tsk)->exec_file->f_path.mnt) : "/")
78536 +
78537 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78538 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78539 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78540 +
78541 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78542 +
78543 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78544 +
78545 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78546 +{
78547 + if (file1 && file2) {
78548 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
78549 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
78550 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78551 + return true;
78552 + }
78553 +
78554 + return false;
78555 +}
78556 +
78557 +#define GR_CHROOT_CAPS {{ \
78558 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
78559 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
78560 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
78561 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
78562 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
78563 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
78564 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
78565 +
78566 +#define security_learn(normal_msg,args...) \
78567 +({ \
78568 + read_lock(&grsec_exec_file_lock); \
78569 + gr_add_learn_entry(normal_msg "\n", ## args); \
78570 + read_unlock(&grsec_exec_file_lock); \
78571 +})
78572 +
78573 +enum {
78574 + GR_DO_AUDIT,
78575 + GR_DONT_AUDIT,
78576 + /* used for non-audit messages that we shouldn't kill the task on */
78577 + GR_DONT_AUDIT_GOOD
78578 +};
78579 +
78580 +enum {
78581 + GR_TTYSNIFF,
78582 + GR_RBAC,
78583 + GR_RBAC_STR,
78584 + GR_STR_RBAC,
78585 + GR_RBAC_MODE2,
78586 + GR_RBAC_MODE3,
78587 + GR_FILENAME,
78588 + GR_SYSCTL_HIDDEN,
78589 + GR_NOARGS,
78590 + GR_ONE_INT,
78591 + GR_ONE_INT_TWO_STR,
78592 + GR_ONE_STR,
78593 + GR_STR_INT,
78594 + GR_TWO_STR_INT,
78595 + GR_TWO_INT,
78596 + GR_TWO_U64,
78597 + GR_THREE_INT,
78598 + GR_FIVE_INT_TWO_STR,
78599 + GR_TWO_STR,
78600 + GR_THREE_STR,
78601 + GR_FOUR_STR,
78602 + GR_STR_FILENAME,
78603 + GR_FILENAME_STR,
78604 + GR_FILENAME_TWO_INT,
78605 + GR_FILENAME_TWO_INT_STR,
78606 + GR_TEXTREL,
78607 + GR_PTRACE,
78608 + GR_RESOURCE,
78609 + GR_CAP,
78610 + GR_SIG,
78611 + GR_SIG2,
78612 + GR_CRASH1,
78613 + GR_CRASH2,
78614 + GR_PSACCT,
78615 + GR_RWXMAP,
78616 + GR_RWXMAPVMA
78617 +};
78618 +
78619 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
78620 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
78621 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
78622 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
78623 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
78624 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
78625 +#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)
78626 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
78627 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
78628 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
78629 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
78630 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
78631 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
78632 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
78633 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
78634 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
78635 +#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)
78636 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
78637 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
78638 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
78639 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
78640 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
78641 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
78642 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
78643 +#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)
78644 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
78645 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
78646 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
78647 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
78648 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
78649 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
78650 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
78651 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
78652 +#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)
78653 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
78654 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
78655 +
78656 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
78657 +
78658 +#endif
78659 +
78660 +#endif
78661 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
78662 new file mode 100644
78663 index 0000000..ba93581
78664 --- /dev/null
78665 +++ b/include/linux/grmsg.h
78666 @@ -0,0 +1,116 @@
78667 +#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"
78668 +#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"
78669 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
78670 +#define GR_STOPMOD_MSG "denied modification of module state by "
78671 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
78672 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
78673 +#define GR_IOPERM_MSG "denied use of ioperm() by "
78674 +#define GR_IOPL_MSG "denied use of iopl() by "
78675 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
78676 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
78677 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
78678 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
78679 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
78680 +#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"
78681 +#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"
78682 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
78683 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
78684 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
78685 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
78686 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
78687 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
78688 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
78689 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
78690 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
78691 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
78692 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
78693 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
78694 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
78695 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
78696 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
78697 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
78698 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
78699 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
78700 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
78701 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
78702 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
78703 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
78704 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
78705 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
78706 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
78707 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
78708 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
78709 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
78710 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
78711 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
78712 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
78713 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
78714 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
78715 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
78716 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
78717 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
78718 +#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"
78719 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
78720 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
78721 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
78722 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
78723 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
78724 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
78725 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
78726 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
78727 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
78728 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
78729 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
78730 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
78731 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
78732 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
78733 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
78734 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
78735 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
78736 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
78737 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
78738 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
78739 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
78740 +#define GR_NICE_CHROOT_MSG "denied priority change by "
78741 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
78742 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
78743 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
78744 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
78745 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
78746 +#define GR_TIME_MSG "time set by "
78747 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
78748 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
78749 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
78750 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
78751 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
78752 +#define GR_BIND_MSG "denied bind() by "
78753 +#define GR_CONNECT_MSG "denied connect() by "
78754 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
78755 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
78756 +#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"
78757 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
78758 +#define GR_CAP_ACL_MSG "use of %s denied for "
78759 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
78760 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
78761 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
78762 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
78763 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
78764 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
78765 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
78766 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
78767 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
78768 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
78769 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
78770 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
78771 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
78772 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
78773 +#define GR_VM86_MSG "denied use of vm86 by "
78774 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
78775 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
78776 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
78777 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78778 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78779 +#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 "
78780 +#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 "
78781 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78782 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
78783 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78784 new file mode 100644
78785 index 0000000..8108301
78786 --- /dev/null
78787 +++ b/include/linux/grsecurity.h
78788 @@ -0,0 +1,246 @@
78789 +#ifndef GR_SECURITY_H
78790 +#define GR_SECURITY_H
78791 +#include <linux/fs.h>
78792 +#include <linux/fs_struct.h>
78793 +#include <linux/binfmts.h>
78794 +#include <linux/gracl.h>
78795 +
78796 +/* notify of brain-dead configs */
78797 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78798 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
78799 +#endif
78800 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
78801 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
78802 +#endif
78803 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
78804 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
78805 +#endif
78806 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
78807 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
78808 +#endif
78809 +
78810 +int gr_handle_new_usb(void);
78811 +
78812 +void gr_handle_brute_attach(int dumpable);
78813 +void gr_handle_brute_check(void);
78814 +void gr_handle_kernel_exploit(void);
78815 +
78816 +char gr_roletype_to_char(void);
78817 +
78818 +int gr_acl_enable_at_secure(void);
78819 +
78820 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
78821 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
78822 +
78823 +void gr_del_task_from_ip_table(struct task_struct *p);
78824 +
78825 +int gr_pid_is_chrooted(struct task_struct *p);
78826 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
78827 +int gr_handle_chroot_nice(void);
78828 +int gr_handle_chroot_sysctl(const int op);
78829 +int gr_handle_chroot_setpriority(struct task_struct *p,
78830 + const int niceval);
78831 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
78832 +int gr_handle_chroot_chroot(const struct dentry *dentry,
78833 + const struct vfsmount *mnt);
78834 +void gr_handle_chroot_chdir(const struct path *path);
78835 +int gr_handle_chroot_chmod(const struct dentry *dentry,
78836 + const struct vfsmount *mnt, const int mode);
78837 +int gr_handle_chroot_mknod(const struct dentry *dentry,
78838 + const struct vfsmount *mnt, const int mode);
78839 +int gr_handle_chroot_mount(const struct dentry *dentry,
78840 + const struct vfsmount *mnt,
78841 + const char *dev_name);
78842 +int gr_handle_chroot_pivot(void);
78843 +int gr_handle_chroot_unix(const pid_t pid);
78844 +
78845 +int gr_handle_rawio(const struct inode *inode);
78846 +
78847 +void gr_handle_ioperm(void);
78848 +void gr_handle_iopl(void);
78849 +void gr_handle_msr_write(void);
78850 +
78851 +umode_t gr_acl_umask(void);
78852 +
78853 +int gr_tpe_allow(const struct file *file);
78854 +
78855 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
78856 +void gr_clear_chroot_entries(struct task_struct *task);
78857 +
78858 +void gr_log_forkfail(const int retval);
78859 +void gr_log_timechange(void);
78860 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
78861 +void gr_log_chdir(const struct dentry *dentry,
78862 + const struct vfsmount *mnt);
78863 +void gr_log_chroot_exec(const struct dentry *dentry,
78864 + const struct vfsmount *mnt);
78865 +void gr_log_remount(const char *devname, const int retval);
78866 +void gr_log_unmount(const char *devname, const int retval);
78867 +void gr_log_mount(const char *from, const char *to, const int retval);
78868 +void gr_log_textrel(struct vm_area_struct *vma);
78869 +void gr_log_ptgnustack(struct file *file);
78870 +void gr_log_rwxmmap(struct file *file);
78871 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
78872 +
78873 +int gr_handle_follow_link(const struct inode *parent,
78874 + const struct inode *inode,
78875 + const struct dentry *dentry,
78876 + const struct vfsmount *mnt);
78877 +int gr_handle_fifo(const struct dentry *dentry,
78878 + const struct vfsmount *mnt,
78879 + const struct dentry *dir, const int flag,
78880 + const int acc_mode);
78881 +int gr_handle_hardlink(const struct dentry *dentry,
78882 + const struct vfsmount *mnt,
78883 + struct inode *inode,
78884 + const int mode, const struct filename *to);
78885 +
78886 +int gr_is_capable(const int cap);
78887 +int gr_is_capable_nolog(const int cap);
78888 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
78889 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
78890 +
78891 +void gr_copy_label(struct task_struct *tsk);
78892 +void gr_handle_crash(struct task_struct *task, const int sig);
78893 +int gr_handle_signal(const struct task_struct *p, const int sig);
78894 +int gr_check_crash_uid(const kuid_t uid);
78895 +int gr_check_protected_task(const struct task_struct *task);
78896 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
78897 +int gr_acl_handle_mmap(const struct file *file,
78898 + const unsigned long prot);
78899 +int gr_acl_handle_mprotect(const struct file *file,
78900 + const unsigned long prot);
78901 +int gr_check_hidden_task(const struct task_struct *tsk);
78902 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
78903 + const struct vfsmount *mnt);
78904 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
78905 + const struct vfsmount *mnt);
78906 +__u32 gr_acl_handle_access(const struct dentry *dentry,
78907 + const struct vfsmount *mnt, const int fmode);
78908 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
78909 + const struct vfsmount *mnt, umode_t *mode);
78910 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
78911 + const struct vfsmount *mnt);
78912 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
78913 + const struct vfsmount *mnt);
78914 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
78915 + const struct vfsmount *mnt);
78916 +int gr_handle_ptrace(struct task_struct *task, const long request);
78917 +int gr_handle_proc_ptrace(struct task_struct *task);
78918 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
78919 + const struct vfsmount *mnt);
78920 +int gr_check_crash_exec(const struct file *filp);
78921 +int gr_acl_is_enabled(void);
78922 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
78923 + const kgid_t gid);
78924 +int gr_set_proc_label(const struct dentry *dentry,
78925 + const struct vfsmount *mnt,
78926 + const int unsafe_flags);
78927 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
78928 + const struct vfsmount *mnt);
78929 +__u32 gr_acl_handle_open(const struct dentry *dentry,
78930 + const struct vfsmount *mnt, int acc_mode);
78931 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
78932 + const struct dentry *p_dentry,
78933 + const struct vfsmount *p_mnt,
78934 + int open_flags, int acc_mode, const int imode);
78935 +void gr_handle_create(const struct dentry *dentry,
78936 + const struct vfsmount *mnt);
78937 +void gr_handle_proc_create(const struct dentry *dentry,
78938 + const struct inode *inode);
78939 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
78940 + const struct dentry *parent_dentry,
78941 + const struct vfsmount *parent_mnt,
78942 + const int mode);
78943 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
78944 + const struct dentry *parent_dentry,
78945 + const struct vfsmount *parent_mnt);
78946 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
78947 + const struct vfsmount *mnt);
78948 +void gr_handle_delete(const ino_t ino, const dev_t dev);
78949 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
78950 + const struct vfsmount *mnt);
78951 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
78952 + const struct dentry *parent_dentry,
78953 + const struct vfsmount *parent_mnt,
78954 + const struct filename *from);
78955 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
78956 + const struct dentry *parent_dentry,
78957 + const struct vfsmount *parent_mnt,
78958 + const struct dentry *old_dentry,
78959 + const struct vfsmount *old_mnt, const struct filename *to);
78960 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
78961 +int gr_acl_handle_rename(struct dentry *new_dentry,
78962 + struct dentry *parent_dentry,
78963 + const struct vfsmount *parent_mnt,
78964 + struct dentry *old_dentry,
78965 + struct inode *old_parent_inode,
78966 + struct vfsmount *old_mnt, const struct filename *newname);
78967 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
78968 + struct dentry *old_dentry,
78969 + struct dentry *new_dentry,
78970 + struct vfsmount *mnt, const __u8 replace);
78971 +__u32 gr_check_link(const struct dentry *new_dentry,
78972 + const struct dentry *parent_dentry,
78973 + const struct vfsmount *parent_mnt,
78974 + const struct dentry *old_dentry,
78975 + const struct vfsmount *old_mnt);
78976 +int gr_acl_handle_filldir(const struct file *file, const char *name,
78977 + const unsigned int namelen, const ino_t ino);
78978 +
78979 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
78980 + const struct vfsmount *mnt);
78981 +void gr_acl_handle_exit(void);
78982 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
78983 +int gr_acl_handle_procpidmem(const struct task_struct *task);
78984 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
78985 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
78986 +void gr_audit_ptrace(struct task_struct *task);
78987 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
78988 +void gr_put_exec_file(struct task_struct *task);
78989 +
78990 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
78991 +
78992 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
78993 +extern void gr_learn_resource(const struct task_struct *task, const int res,
78994 + const unsigned long wanted, const int gt);
78995 +#else
78996 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
78997 + const unsigned long wanted, const int gt)
78998 +{
78999 +}
79000 +#endif
79001 +
79002 +#ifdef CONFIG_GRKERNSEC_RESLOG
79003 +extern void gr_log_resource(const struct task_struct *task, const int res,
79004 + const unsigned long wanted, const int gt);
79005 +#else
79006 +static inline void gr_log_resource(const struct task_struct *task, const int res,
79007 + const unsigned long wanted, const int gt)
79008 +{
79009 +}
79010 +#endif
79011 +
79012 +#ifdef CONFIG_GRKERNSEC
79013 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79014 +void gr_handle_vm86(void);
79015 +void gr_handle_mem_readwrite(u64 from, u64 to);
79016 +
79017 +void gr_log_badprocpid(const char *entry);
79018 +
79019 +extern int grsec_enable_dmesg;
79020 +extern int grsec_disable_privio;
79021 +
79022 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79023 +extern kgid_t grsec_proc_gid;
79024 +#endif
79025 +
79026 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79027 +extern int grsec_enable_chroot_findtask;
79028 +#endif
79029 +#ifdef CONFIG_GRKERNSEC_SETXID
79030 +extern int grsec_enable_setxid;
79031 +#endif
79032 +#endif
79033 +
79034 +#endif
79035 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79036 new file mode 100644
79037 index 0000000..e7ffaaf
79038 --- /dev/null
79039 +++ b/include/linux/grsock.h
79040 @@ -0,0 +1,19 @@
79041 +#ifndef __GRSOCK_H
79042 +#define __GRSOCK_H
79043 +
79044 +extern void gr_attach_curr_ip(const struct sock *sk);
79045 +extern int gr_handle_sock_all(const int family, const int type,
79046 + const int protocol);
79047 +extern int gr_handle_sock_server(const struct sockaddr *sck);
79048 +extern int gr_handle_sock_server_other(const struct sock *sck);
79049 +extern int gr_handle_sock_client(const struct sockaddr *sck);
79050 +extern int gr_search_connect(struct socket * sock,
79051 + struct sockaddr_in * addr);
79052 +extern int gr_search_bind(struct socket * sock,
79053 + struct sockaddr_in * addr);
79054 +extern int gr_search_listen(struct socket * sock);
79055 +extern int gr_search_accept(struct socket * sock);
79056 +extern int gr_search_socket(const int domain, const int type,
79057 + const int protocol);
79058 +
79059 +#endif
79060 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79061 index 7fb31da..08b5114 100644
79062 --- a/include/linux/highmem.h
79063 +++ b/include/linux/highmem.h
79064 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79065 kunmap_atomic(kaddr);
79066 }
79067
79068 +static inline void sanitize_highpage(struct page *page)
79069 +{
79070 + void *kaddr;
79071 + unsigned long flags;
79072 +
79073 + local_irq_save(flags);
79074 + kaddr = kmap_atomic(page);
79075 + clear_page(kaddr);
79076 + kunmap_atomic(kaddr);
79077 + local_irq_restore(flags);
79078 +}
79079 +
79080 static inline void zero_user_segments(struct page *page,
79081 unsigned start1, unsigned end1,
79082 unsigned start2, unsigned end2)
79083 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79084 index 1c7b89a..7dda400 100644
79085 --- a/include/linux/hwmon-sysfs.h
79086 +++ b/include/linux/hwmon-sysfs.h
79087 @@ -25,7 +25,8 @@
79088 struct sensor_device_attribute{
79089 struct device_attribute dev_attr;
79090 int index;
79091 -};
79092 +} __do_const;
79093 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79094 #define to_sensor_dev_attr(_dev_attr) \
79095 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79096
79097 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79098 struct device_attribute dev_attr;
79099 u8 index;
79100 u8 nr;
79101 -};
79102 +} __do_const;
79103 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79104 #define to_sensor_dev_attr_2(_dev_attr) \
79105 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79106
79107 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79108 index d9c8dbd3..def6e5a 100644
79109 --- a/include/linux/i2c.h
79110 +++ b/include/linux/i2c.h
79111 @@ -364,6 +364,7 @@ struct i2c_algorithm {
79112 /* To determine what the adapter supports */
79113 u32 (*functionality) (struct i2c_adapter *);
79114 };
79115 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79116
79117 /**
79118 * struct i2c_bus_recovery_info - I2C bus recovery information
79119 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79120 index d23c3c2..eb63c81 100644
79121 --- a/include/linux/i2o.h
79122 +++ b/include/linux/i2o.h
79123 @@ -565,7 +565,7 @@ struct i2o_controller {
79124 struct i2o_device *exec; /* Executive */
79125 #if BITS_PER_LONG == 64
79126 spinlock_t context_list_lock; /* lock for context_list */
79127 - atomic_t context_list_counter; /* needed for unique contexts */
79128 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79129 struct list_head context_list; /* list of context id's
79130 and pointers */
79131 #endif
79132 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79133 index aff7ad8..3942bbd 100644
79134 --- a/include/linux/if_pppox.h
79135 +++ b/include/linux/if_pppox.h
79136 @@ -76,7 +76,7 @@ struct pppox_proto {
79137 int (*ioctl)(struct socket *sock, unsigned int cmd,
79138 unsigned long arg);
79139 struct module *owner;
79140 -};
79141 +} __do_const;
79142
79143 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79144 extern void unregister_pppox_proto(int proto_num);
79145 diff --git a/include/linux/init.h b/include/linux/init.h
79146 index 8e68a64..3f977a0 100644
79147 --- a/include/linux/init.h
79148 +++ b/include/linux/init.h
79149 @@ -37,9 +37,17 @@
79150 * section.
79151 */
79152
79153 +#define add_init_latent_entropy __latent_entropy
79154 +
79155 +#ifdef CONFIG_MEMORY_HOTPLUG
79156 +#define add_meminit_latent_entropy
79157 +#else
79158 +#define add_meminit_latent_entropy __latent_entropy
79159 +#endif
79160 +
79161 /* These are for everybody (although not all archs will actually
79162 discard it in modules) */
79163 -#define __init __section(.init.text) __cold notrace
79164 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79165 #define __initdata __section(.init.data)
79166 #define __initconst __constsection(.init.rodata)
79167 #define __exitdata __section(.exit.data)
79168 @@ -100,7 +108,7 @@
79169 #define __cpuexitconst
79170
79171 /* Used for MEMORY_HOTPLUG */
79172 -#define __meminit __section(.meminit.text) __cold notrace
79173 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79174 #define __meminitdata __section(.meminit.data)
79175 #define __meminitconst __constsection(.meminit.rodata)
79176 #define __memexit __section(.memexit.text) __exitused __cold notrace
79177 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79178 index b0ed422..d79ea23 100644
79179 --- a/include/linux/init_task.h
79180 +++ b/include/linux/init_task.h
79181 @@ -154,6 +154,12 @@ extern struct task_group root_task_group;
79182
79183 #define INIT_TASK_COMM "swapper"
79184
79185 +#ifdef CONFIG_X86
79186 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79187 +#else
79188 +#define INIT_TASK_THREAD_INFO
79189 +#endif
79190 +
79191 /*
79192 * INIT_TASK is used to set up the first task table, touch at
79193 * your own risk!. Base=0, limit=0x1fffff (=2MB)
79194 @@ -193,6 +199,7 @@ extern struct task_group root_task_group;
79195 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79196 .comm = INIT_TASK_COMM, \
79197 .thread = INIT_THREAD, \
79198 + INIT_TASK_THREAD_INFO \
79199 .fs = &init_fs, \
79200 .files = &init_files, \
79201 .signal = &init_signals, \
79202 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79203 index db43b58..5d5084b 100644
79204 --- a/include/linux/interrupt.h
79205 +++ b/include/linux/interrupt.h
79206 @@ -360,7 +360,7 @@ enum
79207 /* map softirq index to softirq name. update 'softirq_to_name' in
79208 * kernel/softirq.c when adding a new softirq.
79209 */
79210 -extern char *softirq_to_name[NR_SOFTIRQS];
79211 +extern const char * const softirq_to_name[NR_SOFTIRQS];
79212
79213 /* softirq mask and active fields moved to irq_cpustat_t in
79214 * asm/hardirq.h to get better cache usage. KAO
79215 @@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
79216
79217 struct softirq_action
79218 {
79219 - void (*action)(struct softirq_action *);
79220 -};
79221 + void (*action)(void);
79222 +} __no_const;
79223
79224 asmlinkage void do_softirq(void);
79225 asmlinkage void __do_softirq(void);
79226 @@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
79227 }
79228 #endif
79229
79230 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79231 +extern void open_softirq(int nr, void (*action)(void));
79232 extern void softirq_init(void);
79233 extern void __raise_softirq_irqoff(unsigned int nr);
79234
79235 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79236 index a444c79..8c41ea9 100644
79237 --- a/include/linux/iommu.h
79238 +++ b/include/linux/iommu.h
79239 @@ -130,7 +130,7 @@ struct iommu_ops {
79240 u32 (*domain_get_windows)(struct iommu_domain *domain);
79241
79242 unsigned long pgsize_bitmap;
79243 -};
79244 +} __do_const;
79245
79246 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79247 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79248 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79249 index 89b7c24..382af74 100644
79250 --- a/include/linux/ioport.h
79251 +++ b/include/linux/ioport.h
79252 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79253 int adjust_resource(struct resource *res, resource_size_t start,
79254 resource_size_t size);
79255 resource_size_t resource_alignment(struct resource *res);
79256 -static inline resource_size_t resource_size(const struct resource *res)
79257 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79258 {
79259 return res->end - res->start + 1;
79260 }
79261 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79262 index d6ad91f..f10f279 100644
79263 --- a/include/linux/ipc_namespace.h
79264 +++ b/include/linux/ipc_namespace.h
79265 @@ -70,7 +70,7 @@ struct ipc_namespace {
79266 struct user_namespace *user_ns;
79267
79268 unsigned int proc_inum;
79269 -};
79270 +} __randomize_layout;
79271
79272 extern struct ipc_namespace init_ipc_ns;
79273 extern atomic_t nr_ipc_ns;
79274 diff --git a/include/linux/irq.h b/include/linux/irq.h
79275 index 7dc1003..407327b 100644
79276 --- a/include/linux/irq.h
79277 +++ b/include/linux/irq.h
79278 @@ -338,7 +338,8 @@ struct irq_chip {
79279 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79280
79281 unsigned long flags;
79282 -};
79283 +} __do_const;
79284 +typedef struct irq_chip __no_const irq_chip_no_const;
79285
79286 /*
79287 * irq_chip specific flags
79288 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79289 index cac496b..ffa0567 100644
79290 --- a/include/linux/irqchip/arm-gic.h
79291 +++ b/include/linux/irqchip/arm-gic.h
79292 @@ -61,9 +61,11 @@
79293
79294 #ifndef __ASSEMBLY__
79295
79296 +#include <linux/irq.h>
79297 +
79298 struct device_node;
79299
79300 -extern struct irq_chip gic_arch_extn;
79301 +extern irq_chip_no_const gic_arch_extn;
79302
79303 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79304 u32 offset, struct device_node *);
79305 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79306 index d235e88..8ccbe74 100644
79307 --- a/include/linux/jiffies.h
79308 +++ b/include/linux/jiffies.h
79309 @@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
79310 /*
79311 * Convert various time units to each other:
79312 */
79313 -extern unsigned int jiffies_to_msecs(const unsigned long j);
79314 -extern unsigned int jiffies_to_usecs(const unsigned long j);
79315 -extern unsigned long msecs_to_jiffies(const unsigned int m);
79316 -extern unsigned long usecs_to_jiffies(const unsigned int u);
79317 -extern unsigned long timespec_to_jiffies(const struct timespec *value);
79318 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79319 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79320 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79321 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79322 +extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
79323 extern void jiffies_to_timespec(const unsigned long jiffies,
79324 struct timespec *value);
79325 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
79326 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79327 extern void jiffies_to_timeval(const unsigned long jiffies,
79328 struct timeval *value);
79329
79330 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79331 index 6883e19..e854fcb 100644
79332 --- a/include/linux/kallsyms.h
79333 +++ b/include/linux/kallsyms.h
79334 @@ -15,7 +15,8 @@
79335
79336 struct module;
79337
79338 -#ifdef CONFIG_KALLSYMS
79339 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79340 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79341 /* Lookup the address for a symbol. Returns 0 if not found. */
79342 unsigned long kallsyms_lookup_name(const char *name);
79343
79344 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79345 /* Stupid that this does nothing, but I didn't create this mess. */
79346 #define __print_symbol(fmt, addr)
79347 #endif /*CONFIG_KALLSYMS*/
79348 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79349 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79350 +extern unsigned long kallsyms_lookup_name(const char *name);
79351 +extern void __print_symbol(const char *fmt, unsigned long address);
79352 +extern int sprint_backtrace(char *buffer, unsigned long address);
79353 +extern int sprint_symbol(char *buffer, unsigned long address);
79354 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79355 +const char *kallsyms_lookup(unsigned long addr,
79356 + unsigned long *symbolsize,
79357 + unsigned long *offset,
79358 + char **modname, char *namebuf);
79359 +extern int kallsyms_lookup_size_offset(unsigned long addr,
79360 + unsigned long *symbolsize,
79361 + unsigned long *offset);
79362 +#endif
79363
79364 /* This macro allows us to keep printk typechecking */
79365 static __printf(1, 2)
79366 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79367 index a74c3a8..28d3f21 100644
79368 --- a/include/linux/key-type.h
79369 +++ b/include/linux/key-type.h
79370 @@ -131,7 +131,7 @@ struct key_type {
79371 /* internal fields */
79372 struct list_head link; /* link in types list */
79373 struct lock_class_key lock_class; /* key->sem lock class */
79374 -};
79375 +} __do_const;
79376
79377 extern struct key_type key_type_keyring;
79378
79379 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79380 index dfb4f2f..7927e62 100644
79381 --- a/include/linux/kgdb.h
79382 +++ b/include/linux/kgdb.h
79383 @@ -52,7 +52,7 @@ extern int kgdb_connected;
79384 extern int kgdb_io_module_registered;
79385
79386 extern atomic_t kgdb_setting_breakpoint;
79387 -extern atomic_t kgdb_cpu_doing_single_step;
79388 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79389
79390 extern struct task_struct *kgdb_usethread;
79391 extern struct task_struct *kgdb_contthread;
79392 @@ -254,7 +254,7 @@ struct kgdb_arch {
79393 void (*correct_hw_break)(void);
79394
79395 void (*enable_nmi)(bool on);
79396 -};
79397 +} __do_const;
79398
79399 /**
79400 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79401 @@ -279,7 +279,7 @@ struct kgdb_io {
79402 void (*pre_exception) (void);
79403 void (*post_exception) (void);
79404 int is_console;
79405 -};
79406 +} __do_const;
79407
79408 extern struct kgdb_arch arch_kgdb_ops;
79409
79410 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79411 index 0555cc6..40116ce 100644
79412 --- a/include/linux/kmod.h
79413 +++ b/include/linux/kmod.h
79414 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79415 * usually useless though. */
79416 extern __printf(2, 3)
79417 int __request_module(bool wait, const char *name, ...);
79418 +extern __printf(3, 4)
79419 +int ___request_module(bool wait, char *param_name, const char *name, ...);
79420 #define request_module(mod...) __request_module(true, mod)
79421 #define request_module_nowait(mod...) __request_module(false, mod)
79422 #define try_then_request_module(x, mod...) \
79423 @@ -57,6 +59,9 @@ struct subprocess_info {
79424 struct work_struct work;
79425 struct completion *complete;
79426 char *path;
79427 +#ifdef CONFIG_GRKERNSEC
79428 + char *origpath;
79429 +#endif
79430 char **argv;
79431 char **envp;
79432 int wait;
79433 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79434 index e7ba650..0af3acb 100644
79435 --- a/include/linux/kobject.h
79436 +++ b/include/linux/kobject.h
79437 @@ -116,7 +116,7 @@ struct kobj_type {
79438 struct attribute **default_attrs;
79439 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79440 const void *(*namespace)(struct kobject *kobj);
79441 -};
79442 +} __do_const;
79443
79444 struct kobj_uevent_env {
79445 char *envp[UEVENT_NUM_ENVP];
79446 @@ -139,6 +139,7 @@ struct kobj_attribute {
79447 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79448 const char *buf, size_t count);
79449 };
79450 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79451
79452 extern const struct sysfs_ops kobj_sysfs_ops;
79453
79454 @@ -166,7 +167,7 @@ struct kset {
79455 spinlock_t list_lock;
79456 struct kobject kobj;
79457 const struct kset_uevent_ops *uevent_ops;
79458 -};
79459 +} __randomize_layout;
79460
79461 extern void kset_init(struct kset *kset);
79462 extern int __must_check kset_register(struct kset *kset);
79463 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79464 index df32d25..fb52e27 100644
79465 --- a/include/linux/kobject_ns.h
79466 +++ b/include/linux/kobject_ns.h
79467 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79468 const void *(*netlink_ns)(struct sock *sk);
79469 const void *(*initial_ns)(void);
79470 void (*drop_ns)(void *);
79471 -};
79472 +} __do_const;
79473
79474 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79475 int kobj_ns_type_registered(enum kobj_ns_type type);
79476 diff --git a/include/linux/kref.h b/include/linux/kref.h
79477 index 484604d..0f6c5b6 100644
79478 --- a/include/linux/kref.h
79479 +++ b/include/linux/kref.h
79480 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79481 static inline int kref_sub(struct kref *kref, unsigned int count,
79482 void (*release)(struct kref *kref))
79483 {
79484 - WARN_ON(release == NULL);
79485 + BUG_ON(release == NULL);
79486
79487 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79488 release(kref);
79489 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79490 index 9523d2a..16c0424 100644
79491 --- a/include/linux/kvm_host.h
79492 +++ b/include/linux/kvm_host.h
79493 @@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
79494 {
79495 }
79496 #endif
79497 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79498 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79499 struct module *module);
79500 void kvm_exit(void);
79501
79502 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79503 struct kvm_guest_debug *dbg);
79504 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79505
79506 -int kvm_arch_init(void *opaque);
79507 +int kvm_arch_init(const void *opaque);
79508 void kvm_arch_exit(void);
79509
79510 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79511 diff --git a/include/linux/libata.h b/include/linux/libata.h
79512 index bec6dbe..2873d64 100644
79513 --- a/include/linux/libata.h
79514 +++ b/include/linux/libata.h
79515 @@ -975,7 +975,7 @@ struct ata_port_operations {
79516 * fields must be pointers.
79517 */
79518 const struct ata_port_operations *inherits;
79519 -};
79520 +} __do_const;
79521
79522 struct ata_port_info {
79523 unsigned long flags;
79524 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79525 index d3e8ad2..a949f68 100644
79526 --- a/include/linux/linkage.h
79527 +++ b/include/linux/linkage.h
79528 @@ -31,6 +31,7 @@
79529 #endif
79530
79531 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79532 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79533 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79534
79535 /*
79536 diff --git a/include/linux/list.h b/include/linux/list.h
79537 index ef95941..82db65a 100644
79538 --- a/include/linux/list.h
79539 +++ b/include/linux/list.h
79540 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
79541 extern void list_del(struct list_head *entry);
79542 #endif
79543
79544 +extern void __pax_list_add(struct list_head *new,
79545 + struct list_head *prev,
79546 + struct list_head *next);
79547 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
79548 +{
79549 + __pax_list_add(new, head, head->next);
79550 +}
79551 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
79552 +{
79553 + __pax_list_add(new, head->prev, head);
79554 +}
79555 +extern void pax_list_del(struct list_head *entry);
79556 +
79557 /**
79558 * list_replace - replace old entry by new one
79559 * @old : the element to be replaced
79560 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
79561 INIT_LIST_HEAD(entry);
79562 }
79563
79564 +extern void pax_list_del_init(struct list_head *entry);
79565 +
79566 /**
79567 * list_move - delete from one list and add as another's head
79568 * @list: the entry to move
79569 diff --git a/include/linux/math64.h b/include/linux/math64.h
79570 index c45c089..298841c 100644
79571 --- a/include/linux/math64.h
79572 +++ b/include/linux/math64.h
79573 @@ -15,7 +15,7 @@
79574 * This is commonly provided by 32bit archs to provide an optimized 64bit
79575 * divide.
79576 */
79577 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79578 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79579 {
79580 *remainder = dividend % divisor;
79581 return dividend / divisor;
79582 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
79583 /**
79584 * div64_u64 - unsigned 64bit divide with 64bit divisor
79585 */
79586 -static inline u64 div64_u64(u64 dividend, u64 divisor)
79587 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79588 {
79589 return dividend / divisor;
79590 }
79591 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
79592 #define div64_ul(x, y) div_u64((x), (y))
79593
79594 #ifndef div_u64_rem
79595 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79596 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79597 {
79598 *remainder = do_div(dividend, divisor);
79599 return dividend;
79600 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
79601 #endif
79602
79603 #ifndef div64_u64
79604 -extern u64 div64_u64(u64 dividend, u64 divisor);
79605 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
79606 #endif
79607
79608 #ifndef div64_s64
79609 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
79610 * divide.
79611 */
79612 #ifndef div_u64
79613 -static inline u64 div_u64(u64 dividend, u32 divisor)
79614 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
79615 {
79616 u32 remainder;
79617 return div_u64_rem(dividend, divisor, &remainder);
79618 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
79619 index 9fe426b..8148be6 100644
79620 --- a/include/linux/mempolicy.h
79621 +++ b/include/linux/mempolicy.h
79622 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
79623 }
79624
79625 #define vma_policy(vma) ((vma)->vm_policy)
79626 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79627 +{
79628 + vma->vm_policy = pol;
79629 +}
79630
79631 static inline void mpol_get(struct mempolicy *pol)
79632 {
79633 @@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
79634 }
79635
79636 #define vma_policy(vma) NULL
79637 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79638 +{
79639 +}
79640
79641 static inline int
79642 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
79643 diff --git a/include/linux/mm.h b/include/linux/mm.h
79644 index 9fac6dd..158ca43 100644
79645 --- a/include/linux/mm.h
79646 +++ b/include/linux/mm.h
79647 @@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
79648 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
79649 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
79650 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
79651 +
79652 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
79653 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
79654 +#endif
79655 +
79656 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
79657
79658 #ifdef CONFIG_MEM_SOFT_DIRTY
79659 @@ -219,8 +224,8 @@ struct vm_operations_struct {
79660 /* called by access_process_vm when get_user_pages() fails, typically
79661 * for use by special VMAs that can switch between memory and hardware
79662 */
79663 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
79664 - void *buf, int len, int write);
79665 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
79666 + void *buf, size_t len, int write);
79667 #ifdef CONFIG_NUMA
79668 /*
79669 * set_policy() op must add a reference to any non-NULL @new mempolicy
79670 @@ -250,6 +255,7 @@ struct vm_operations_struct {
79671 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
79672 unsigned long size, pgoff_t pgoff);
79673 };
79674 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
79675
79676 struct mmu_gather;
79677 struct inode;
79678 @@ -1064,8 +1070,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
79679 unsigned long *pfn);
79680 int follow_phys(struct vm_area_struct *vma, unsigned long address,
79681 unsigned int flags, unsigned long *prot, resource_size_t *phys);
79682 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79683 - void *buf, int len, int write);
79684 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79685 + void *buf, size_t len, int write);
79686
79687 static inline void unmap_shared_mapping_range(struct address_space *mapping,
79688 loff_t const holebegin, loff_t const holelen)
79689 @@ -1104,9 +1110,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
79690 }
79691 #endif
79692
79693 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
79694 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
79695 - void *buf, int len, int write);
79696 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
79697 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
79698 + void *buf, size_t len, int write);
79699
79700 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79701 unsigned long start, unsigned long nr_pages,
79702 @@ -1138,34 +1144,6 @@ int set_page_dirty(struct page *page);
79703 int set_page_dirty_lock(struct page *page);
79704 int clear_page_dirty_for_io(struct page *page);
79705
79706 -/* Is the vma a continuation of the stack vma above it? */
79707 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
79708 -{
79709 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
79710 -}
79711 -
79712 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
79713 - unsigned long addr)
79714 -{
79715 - return (vma->vm_flags & VM_GROWSDOWN) &&
79716 - (vma->vm_start == addr) &&
79717 - !vma_growsdown(vma->vm_prev, addr);
79718 -}
79719 -
79720 -/* Is the vma a continuation of the stack vma below it? */
79721 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
79722 -{
79723 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
79724 -}
79725 -
79726 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
79727 - unsigned long addr)
79728 -{
79729 - return (vma->vm_flags & VM_GROWSUP) &&
79730 - (vma->vm_end == addr) &&
79731 - !vma_growsup(vma->vm_next, addr);
79732 -}
79733 -
79734 extern pid_t
79735 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
79736
79737 @@ -1265,6 +1243,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
79738 }
79739 #endif
79740
79741 +#ifdef CONFIG_MMU
79742 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
79743 +#else
79744 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
79745 +{
79746 + return __pgprot(0);
79747 +}
79748 +#endif
79749 +
79750 int vma_wants_writenotify(struct vm_area_struct *vma);
79751
79752 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
79753 @@ -1283,8 +1270,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
79754 {
79755 return 0;
79756 }
79757 +
79758 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
79759 + unsigned long address)
79760 +{
79761 + return 0;
79762 +}
79763 #else
79764 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79765 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79766 #endif
79767
79768 #ifdef __PAGETABLE_PMD_FOLDED
79769 @@ -1293,8 +1287,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
79770 {
79771 return 0;
79772 }
79773 +
79774 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
79775 + unsigned long address)
79776 +{
79777 + return 0;
79778 +}
79779 #else
79780 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79781 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79782 #endif
79783
79784 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79785 @@ -1312,11 +1313,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79786 NULL: pud_offset(pgd, address);
79787 }
79788
79789 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79790 +{
79791 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79792 + NULL: pud_offset(pgd, address);
79793 +}
79794 +
79795 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79796 {
79797 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
79798 NULL: pmd_offset(pud, address);
79799 }
79800 +
79801 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79802 +{
79803 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
79804 + NULL: pmd_offset(pud, address);
79805 +}
79806 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
79807
79808 #if USE_SPLIT_PTE_PTLOCKS
79809 @@ -1694,7 +1707,7 @@ extern int install_special_mapping(struct mm_struct *mm,
79810 unsigned long addr, unsigned long len,
79811 unsigned long flags, struct page **pages);
79812
79813 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
79814 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
79815
79816 extern unsigned long mmap_region(struct file *file, unsigned long addr,
79817 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
79818 @@ -1702,6 +1715,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
79819 unsigned long len, unsigned long prot, unsigned long flags,
79820 unsigned long pgoff, unsigned long *populate);
79821 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
79822 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
79823
79824 #ifdef CONFIG_MMU
79825 extern int __mm_populate(unsigned long addr, unsigned long len,
79826 @@ -1730,10 +1744,11 @@ struct vm_unmapped_area_info {
79827 unsigned long high_limit;
79828 unsigned long align_mask;
79829 unsigned long align_offset;
79830 + unsigned long threadstack_offset;
79831 };
79832
79833 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
79834 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79835 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
79836 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
79837
79838 /*
79839 * Search for an unmapped address range.
79840 @@ -1745,7 +1760,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79841 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
79842 */
79843 static inline unsigned long
79844 -vm_unmapped_area(struct vm_unmapped_area_info *info)
79845 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
79846 {
79847 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
79848 return unmapped_area(info);
79849 @@ -1808,6 +1823,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
79850 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
79851 struct vm_area_struct **pprev);
79852
79853 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
79854 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
79855 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
79856 +
79857 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
79858 NULL if none. Assume start_addr < end_addr. */
79859 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
79860 @@ -1836,15 +1855,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
79861 return vma;
79862 }
79863
79864 -#ifdef CONFIG_MMU
79865 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
79866 -#else
79867 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
79868 -{
79869 - return __pgprot(0);
79870 -}
79871 -#endif
79872 -
79873 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
79874 unsigned long change_prot_numa(struct vm_area_struct *vma,
79875 unsigned long start, unsigned long end);
79876 @@ -1896,6 +1906,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
79877 static inline void vm_stat_account(struct mm_struct *mm,
79878 unsigned long flags, struct file *file, long pages)
79879 {
79880 +
79881 +#ifdef CONFIG_PAX_RANDMMAP
79882 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
79883 +#endif
79884 +
79885 mm->total_vm += pages;
79886 }
79887 #endif /* CONFIG_PROC_FS */
79888 @@ -1977,7 +1992,7 @@ extern int unpoison_memory(unsigned long pfn);
79889 extern int sysctl_memory_failure_early_kill;
79890 extern int sysctl_memory_failure_recovery;
79891 extern void shake_page(struct page *p, int access);
79892 -extern atomic_long_t num_poisoned_pages;
79893 +extern atomic_long_unchecked_t num_poisoned_pages;
79894 extern int soft_offline_page(struct page *page, int flags);
79895
79896 extern void dump_page(struct page *page);
79897 @@ -2014,5 +2029,11 @@ void __init setup_nr_node_ids(void);
79898 static inline void setup_nr_node_ids(void) {}
79899 #endif
79900
79901 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
79902 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
79903 +#else
79904 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
79905 +#endif
79906 +
79907 #endif /* __KERNEL__ */
79908 #endif /* _LINUX_MM_H */
79909 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
79910 index 290901a..e99b01c 100644
79911 --- a/include/linux/mm_types.h
79912 +++ b/include/linux/mm_types.h
79913 @@ -307,7 +307,9 @@ struct vm_area_struct {
79914 #ifdef CONFIG_NUMA
79915 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
79916 #endif
79917 -};
79918 +
79919 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
79920 +} __randomize_layout;
79921
79922 struct core_thread {
79923 struct task_struct *task;
79924 @@ -453,7 +455,25 @@ struct mm_struct {
79925 bool tlb_flush_pending;
79926 #endif
79927 struct uprobes_state uprobes_state;
79928 -};
79929 +
79930 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
79931 + unsigned long pax_flags;
79932 +#endif
79933 +
79934 +#ifdef CONFIG_PAX_DLRESOLVE
79935 + unsigned long call_dl_resolve;
79936 +#endif
79937 +
79938 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
79939 + unsigned long call_syscall;
79940 +#endif
79941 +
79942 +#ifdef CONFIG_PAX_ASLR
79943 + unsigned long delta_mmap; /* randomized offset */
79944 + unsigned long delta_stack; /* randomized offset */
79945 +#endif
79946 +
79947 +} __randomize_layout;
79948
79949 static inline void mm_init_cpumask(struct mm_struct *mm)
79950 {
79951 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
79952 index c5d5278..f0b68c8 100644
79953 --- a/include/linux/mmiotrace.h
79954 +++ b/include/linux/mmiotrace.h
79955 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
79956 /* Called from ioremap.c */
79957 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
79958 void __iomem *addr);
79959 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
79960 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
79961
79962 /* For anyone to insert markers. Remember trailing newline. */
79963 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
79964 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
79965 {
79966 }
79967
79968 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
79969 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
79970 {
79971 }
79972
79973 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
79974 index bd791e4..8617c34f 100644
79975 --- a/include/linux/mmzone.h
79976 +++ b/include/linux/mmzone.h
79977 @@ -396,7 +396,7 @@ struct zone {
79978 unsigned long flags; /* zone flags, see below */
79979
79980 /* Zone statistics */
79981 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79982 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79983
79984 /*
79985 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
79986 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
79987 index 45e9214..a7227d6 100644
79988 --- a/include/linux/mod_devicetable.h
79989 +++ b/include/linux/mod_devicetable.h
79990 @@ -13,7 +13,7 @@
79991 typedef unsigned long kernel_ulong_t;
79992 #endif
79993
79994 -#define PCI_ANY_ID (~0)
79995 +#define PCI_ANY_ID ((__u16)~0)
79996
79997 struct pci_device_id {
79998 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
79999 @@ -139,7 +139,7 @@ struct usb_device_id {
80000 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80001 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80002
80003 -#define HID_ANY_ID (~0)
80004 +#define HID_ANY_ID (~0U)
80005 #define HID_BUS_ANY 0xffff
80006 #define HID_GROUP_ANY 0x0000
80007
80008 @@ -467,7 +467,7 @@ struct dmi_system_id {
80009 const char *ident;
80010 struct dmi_strmatch matches[4];
80011 void *driver_data;
80012 -};
80013 +} __do_const;
80014 /*
80015 * struct dmi_device_id appears during expansion of
80016 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80017 diff --git a/include/linux/module.h b/include/linux/module.h
80018 index 15cd6b1..f6e2e6a 100644
80019 --- a/include/linux/module.h
80020 +++ b/include/linux/module.h
80021 @@ -17,9 +17,11 @@
80022 #include <linux/moduleparam.h>
80023 #include <linux/tracepoint.h>
80024 #include <linux/export.h>
80025 +#include <linux/fs.h>
80026
80027 #include <linux/percpu.h>
80028 #include <asm/module.h>
80029 +#include <asm/pgtable.h>
80030
80031 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80032 #define MODULE_SIG_STRING "~Module signature appended~\n"
80033 @@ -43,7 +45,7 @@ struct module_kobject {
80034 struct kobject *drivers_dir;
80035 struct module_param_attrs *mp;
80036 struct completion *kobj_completion;
80037 -};
80038 +} __randomize_layout;
80039
80040 struct module_attribute {
80041 struct attribute attr;
80042 @@ -55,12 +57,13 @@ struct module_attribute {
80043 int (*test)(struct module *);
80044 void (*free)(struct module *);
80045 };
80046 +typedef struct module_attribute __no_const module_attribute_no_const;
80047
80048 struct module_version_attribute {
80049 struct module_attribute mattr;
80050 const char *module_name;
80051 const char *version;
80052 -} __attribute__ ((__aligned__(sizeof(void *))));
80053 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80054
80055 extern ssize_t __modver_version_show(struct module_attribute *,
80056 struct module_kobject *, char *);
80057 @@ -238,7 +241,7 @@ struct module
80058
80059 /* Sysfs stuff. */
80060 struct module_kobject mkobj;
80061 - struct module_attribute *modinfo_attrs;
80062 + module_attribute_no_const *modinfo_attrs;
80063 const char *version;
80064 const char *srcversion;
80065 struct kobject *holders_dir;
80066 @@ -287,19 +290,16 @@ struct module
80067 int (*init)(void);
80068
80069 /* If this is non-NULL, vfree after init() returns */
80070 - void *module_init;
80071 + void *module_init_rx, *module_init_rw;
80072
80073 /* Here is the actual code + data, vfree'd on unload. */
80074 - void *module_core;
80075 + void *module_core_rx, *module_core_rw;
80076
80077 /* Here are the sizes of the init and core sections */
80078 - unsigned int init_size, core_size;
80079 + unsigned int init_size_rw, core_size_rw;
80080
80081 /* The size of the executable code in each section. */
80082 - unsigned int init_text_size, core_text_size;
80083 -
80084 - /* Size of RO sections of the module (text+rodata) */
80085 - unsigned int init_ro_size, core_ro_size;
80086 + unsigned int init_size_rx, core_size_rx;
80087
80088 /* Arch-specific module values */
80089 struct mod_arch_specific arch;
80090 @@ -355,6 +355,10 @@ struct module
80091 #ifdef CONFIG_EVENT_TRACING
80092 struct ftrace_event_call **trace_events;
80093 unsigned int num_trace_events;
80094 + struct file_operations trace_id;
80095 + struct file_operations trace_enable;
80096 + struct file_operations trace_format;
80097 + struct file_operations trace_filter;
80098 #endif
80099 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80100 unsigned int num_ftrace_callsites;
80101 @@ -378,7 +382,7 @@ struct module
80102 ctor_fn_t *ctors;
80103 unsigned int num_ctors;
80104 #endif
80105 -};
80106 +} __randomize_layout;
80107 #ifndef MODULE_ARCH_INIT
80108 #define MODULE_ARCH_INIT {}
80109 #endif
80110 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80111 bool is_module_percpu_address(unsigned long addr);
80112 bool is_module_text_address(unsigned long addr);
80113
80114 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80115 +{
80116 +
80117 +#ifdef CONFIG_PAX_KERNEXEC
80118 + if (ktla_ktva(addr) >= (unsigned long)start &&
80119 + ktla_ktva(addr) < (unsigned long)start + size)
80120 + return 1;
80121 +#endif
80122 +
80123 + return ((void *)addr >= start && (void *)addr < start + size);
80124 +}
80125 +
80126 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80127 +{
80128 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80129 +}
80130 +
80131 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80132 +{
80133 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80134 +}
80135 +
80136 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80137 +{
80138 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80139 +}
80140 +
80141 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80142 +{
80143 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80144 +}
80145 +
80146 static inline int within_module_core(unsigned long addr, const struct module *mod)
80147 {
80148 - return (unsigned long)mod->module_core <= addr &&
80149 - addr < (unsigned long)mod->module_core + mod->core_size;
80150 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80151 }
80152
80153 static inline int within_module_init(unsigned long addr, const struct module *mod)
80154 {
80155 - return (unsigned long)mod->module_init <= addr &&
80156 - addr < (unsigned long)mod->module_init + mod->init_size;
80157 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80158 }
80159
80160 /* Search for module by name: must hold module_mutex. */
80161 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80162 index 560ca53..ef621ef 100644
80163 --- a/include/linux/moduleloader.h
80164 +++ b/include/linux/moduleloader.h
80165 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80166 sections. Returns NULL on failure. */
80167 void *module_alloc(unsigned long size);
80168
80169 +#ifdef CONFIG_PAX_KERNEXEC
80170 +void *module_alloc_exec(unsigned long size);
80171 +#else
80172 +#define module_alloc_exec(x) module_alloc(x)
80173 +#endif
80174 +
80175 /* Free memory returned from module_alloc. */
80176 void module_free(struct module *mod, void *module_region);
80177
80178 +#ifdef CONFIG_PAX_KERNEXEC
80179 +void module_free_exec(struct module *mod, void *module_region);
80180 +#else
80181 +#define module_free_exec(x, y) module_free((x), (y))
80182 +#endif
80183 +
80184 /*
80185 * Apply the given relocation to the (simplified) ELF. Return -error
80186 * or 0.
80187 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80188 unsigned int relsec,
80189 struct module *me)
80190 {
80191 +#ifdef CONFIG_MODULES
80192 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80193 +#endif
80194 return -ENOEXEC;
80195 }
80196 #endif
80197 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80198 unsigned int relsec,
80199 struct module *me)
80200 {
80201 +#ifdef CONFIG_MODULES
80202 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80203 +#endif
80204 return -ENOEXEC;
80205 }
80206 #endif
80207 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80208 index c3eb102..073c4a6 100644
80209 --- a/include/linux/moduleparam.h
80210 +++ b/include/linux/moduleparam.h
80211 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80212 * @len is usually just sizeof(string).
80213 */
80214 #define module_param_string(name, string, len, perm) \
80215 - static const struct kparam_string __param_string_##name \
80216 + static const struct kparam_string __param_string_##name __used \
80217 = { len, string }; \
80218 __module_param_call(MODULE_PARAM_PREFIX, name, \
80219 &param_ops_string, \
80220 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80221 */
80222 #define module_param_array_named(name, array, type, nump, perm) \
80223 param_check_##type(name, &(array)[0]); \
80224 - static const struct kparam_array __param_arr_##name \
80225 + static const struct kparam_array __param_arr_##name __used \
80226 = { .max = ARRAY_SIZE(array), .num = nump, \
80227 .ops = &param_ops_##type, \
80228 .elemsize = sizeof(array[0]), .elem = array }; \
80229 diff --git a/include/linux/mount.h b/include/linux/mount.h
80230 index 371d346..fba2819 100644
80231 --- a/include/linux/mount.h
80232 +++ b/include/linux/mount.h
80233 @@ -56,7 +56,7 @@ struct vfsmount {
80234 struct dentry *mnt_root; /* root of the mounted tree */
80235 struct super_block *mnt_sb; /* pointer to superblock */
80236 int mnt_flags;
80237 -};
80238 +} __randomize_layout;
80239
80240 struct file; /* forward dec */
80241
80242 diff --git a/include/linux/namei.h b/include/linux/namei.h
80243 index 492de72..1bddcd4 100644
80244 --- a/include/linux/namei.h
80245 +++ b/include/linux/namei.h
80246 @@ -19,7 +19,7 @@ struct nameidata {
80247 unsigned seq, m_seq;
80248 int last_type;
80249 unsigned depth;
80250 - char *saved_names[MAX_NESTED_LINKS + 1];
80251 + const char *saved_names[MAX_NESTED_LINKS + 1];
80252 };
80253
80254 /*
80255 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80256
80257 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80258
80259 -static inline void nd_set_link(struct nameidata *nd, char *path)
80260 +static inline void nd_set_link(struct nameidata *nd, const char *path)
80261 {
80262 nd->saved_names[nd->depth] = path;
80263 }
80264
80265 -static inline char *nd_get_link(struct nameidata *nd)
80266 +static inline const char *nd_get_link(const struct nameidata *nd)
80267 {
80268 return nd->saved_names[nd->depth];
80269 }
80270 diff --git a/include/linux/net.h b/include/linux/net.h
80271 index 69be3e6..0fb422d 100644
80272 --- a/include/linux/net.h
80273 +++ b/include/linux/net.h
80274 @@ -192,7 +192,7 @@ struct net_proto_family {
80275 int (*create)(struct net *net, struct socket *sock,
80276 int protocol, int kern);
80277 struct module *owner;
80278 -};
80279 +} __do_const;
80280
80281 struct iovec;
80282 struct kvec;
80283 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80284 index 2177a6b..67fc561 100644
80285 --- a/include/linux/netdevice.h
80286 +++ b/include/linux/netdevice.h
80287 @@ -1129,6 +1129,7 @@ struct net_device_ops {
80288 struct net_device *dev,
80289 void *priv);
80290 };
80291 +typedef struct net_device_ops __no_const net_device_ops_no_const;
80292
80293 /*
80294 * The DEVICE structure.
80295 @@ -1211,7 +1212,7 @@ struct net_device {
80296 int iflink;
80297
80298 struct net_device_stats stats;
80299 - atomic_long_t rx_dropped; /* dropped packets by core network
80300 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80301 * Do not use this in drivers.
80302 */
80303
80304 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80305 index 2077489..a15e561 100644
80306 --- a/include/linux/netfilter.h
80307 +++ b/include/linux/netfilter.h
80308 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80309 #endif
80310 /* Use the module struct to lock set/get code in place */
80311 struct module *owner;
80312 -};
80313 +} __do_const;
80314
80315 /* Function to register/unregister hook points. */
80316 int nf_register_hook(struct nf_hook_ops *reg);
80317 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80318 index 28c7436..2d6156a 100644
80319 --- a/include/linux/netfilter/nfnetlink.h
80320 +++ b/include/linux/netfilter/nfnetlink.h
80321 @@ -19,7 +19,7 @@ struct nfnl_callback {
80322 const struct nlattr * const cda[]);
80323 const struct nla_policy *policy; /* netlink attribute policy */
80324 const u_int16_t attr_count; /* number of nlattr's */
80325 -};
80326 +} __do_const;
80327
80328 struct nfnetlink_subsystem {
80329 const char *name;
80330 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80331 new file mode 100644
80332 index 0000000..33f4af8
80333 --- /dev/null
80334 +++ b/include/linux/netfilter/xt_gradm.h
80335 @@ -0,0 +1,9 @@
80336 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
80337 +#define _LINUX_NETFILTER_XT_GRADM_H 1
80338 +
80339 +struct xt_gradm_mtinfo {
80340 + __u16 flags;
80341 + __u16 invflags;
80342 +};
80343 +
80344 +#endif
80345 diff --git a/include/linux/nls.h b/include/linux/nls.h
80346 index 5dc635f..35f5e11 100644
80347 --- a/include/linux/nls.h
80348 +++ b/include/linux/nls.h
80349 @@ -31,7 +31,7 @@ struct nls_table {
80350 const unsigned char *charset2upper;
80351 struct module *owner;
80352 struct nls_table *next;
80353 -};
80354 +} __do_const;
80355
80356 /* this value hold the maximum octet of charset */
80357 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80358 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80359 index d14a4c3..a078786 100644
80360 --- a/include/linux/notifier.h
80361 +++ b/include/linux/notifier.h
80362 @@ -54,7 +54,8 @@ struct notifier_block {
80363 notifier_fn_t notifier_call;
80364 struct notifier_block __rcu *next;
80365 int priority;
80366 -};
80367 +} __do_const;
80368 +typedef struct notifier_block __no_const notifier_block_no_const;
80369
80370 struct atomic_notifier_head {
80371 spinlock_t lock;
80372 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80373 index b2a0f15..4d7da32 100644
80374 --- a/include/linux/oprofile.h
80375 +++ b/include/linux/oprofile.h
80376 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80377 int oprofilefs_create_ro_ulong(struct dentry * root,
80378 char const * name, ulong * val);
80379
80380 -/** Create a file for read-only access to an atomic_t. */
80381 +/** Create a file for read-only access to an atomic_unchecked_t. */
80382 int oprofilefs_create_ro_atomic(struct dentry * root,
80383 - char const * name, atomic_t * val);
80384 + char const * name, atomic_unchecked_t * val);
80385
80386 /** create a directory */
80387 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80388 diff --git a/include/linux/padata.h b/include/linux/padata.h
80389 index 4386946..f50c615 100644
80390 --- a/include/linux/padata.h
80391 +++ b/include/linux/padata.h
80392 @@ -129,7 +129,7 @@ struct parallel_data {
80393 struct padata_serial_queue __percpu *squeue;
80394 atomic_t reorder_objects;
80395 atomic_t refcnt;
80396 - atomic_t seq_nr;
80397 + atomic_unchecked_t seq_nr;
80398 struct padata_cpumask cpumask;
80399 spinlock_t lock ____cacheline_aligned;
80400 unsigned int processed;
80401 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80402 index a2e2f1d..8a391d2 100644
80403 --- a/include/linux/pci_hotplug.h
80404 +++ b/include/linux/pci_hotplug.h
80405 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80406 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80407 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80408 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80409 -};
80410 +} __do_const;
80411 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80412
80413 /**
80414 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80415 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80416 index 2e069d1..27054b8 100644
80417 --- a/include/linux/perf_event.h
80418 +++ b/include/linux/perf_event.h
80419 @@ -327,8 +327,8 @@ struct perf_event {
80420
80421 enum perf_event_active_state state;
80422 unsigned int attach_state;
80423 - local64_t count;
80424 - atomic64_t child_count;
80425 + local64_t count; /* PaX: fix it one day */
80426 + atomic64_unchecked_t child_count;
80427
80428 /*
80429 * These are the total time in nanoseconds that the event
80430 @@ -379,8 +379,8 @@ struct perf_event {
80431 * These accumulate total time (in nanoseconds) that children
80432 * events have been enabled and running, respectively.
80433 */
80434 - atomic64_t child_total_time_enabled;
80435 - atomic64_t child_total_time_running;
80436 + atomic64_unchecked_t child_total_time_enabled;
80437 + atomic64_unchecked_t child_total_time_running;
80438
80439 /*
80440 * Protect attach/detach and child_list:
80441 @@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80442 entry->ip[entry->nr++] = ip;
80443 }
80444
80445 -extern int sysctl_perf_event_paranoid;
80446 +extern int sysctl_perf_event_legitimately_concerned;
80447 extern int sysctl_perf_event_mlock;
80448 extern int sysctl_perf_event_sample_rate;
80449 extern int sysctl_perf_cpu_time_max_percent;
80450 @@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80451 loff_t *ppos);
80452
80453
80454 +static inline bool perf_paranoid_any(void)
80455 +{
80456 + return sysctl_perf_event_legitimately_concerned > 2;
80457 +}
80458 +
80459 static inline bool perf_paranoid_tracepoint_raw(void)
80460 {
80461 - return sysctl_perf_event_paranoid > -1;
80462 + return sysctl_perf_event_legitimately_concerned > -1;
80463 }
80464
80465 static inline bool perf_paranoid_cpu(void)
80466 {
80467 - return sysctl_perf_event_paranoid > 0;
80468 + return sysctl_perf_event_legitimately_concerned > 0;
80469 }
80470
80471 static inline bool perf_paranoid_kernel(void)
80472 {
80473 - return sysctl_perf_event_paranoid > 1;
80474 + return sysctl_perf_event_legitimately_concerned > 1;
80475 }
80476
80477 extern void perf_event_init(void);
80478 @@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
80479 struct device_attribute attr;
80480 u64 id;
80481 const char *event_str;
80482 -};
80483 +} __do_const;
80484
80485 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80486 static struct perf_pmu_events_attr _var = { \
80487 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80488 index 7246ef3..1539ea4 100644
80489 --- a/include/linux/pid_namespace.h
80490 +++ b/include/linux/pid_namespace.h
80491 @@ -43,7 +43,7 @@ struct pid_namespace {
80492 int hide_pid;
80493 int reboot; /* group exit code if this pidns was rebooted */
80494 unsigned int proc_inum;
80495 -};
80496 +} __randomize_layout;
80497
80498 extern struct pid_namespace init_pid_ns;
80499
80500 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80501 index ab57526..94598804 100644
80502 --- a/include/linux/pipe_fs_i.h
80503 +++ b/include/linux/pipe_fs_i.h
80504 @@ -47,10 +47,10 @@ struct pipe_inode_info {
80505 struct mutex mutex;
80506 wait_queue_head_t wait;
80507 unsigned int nrbufs, curbuf, buffers;
80508 - unsigned int readers;
80509 - unsigned int writers;
80510 - unsigned int files;
80511 - unsigned int waiting_writers;
80512 + atomic_t readers;
80513 + atomic_t writers;
80514 + atomic_t files;
80515 + atomic_t waiting_writers;
80516 unsigned int r_counter;
80517 unsigned int w_counter;
80518 struct page *tmp_page;
80519 diff --git a/include/linux/pm.h b/include/linux/pm.h
80520 index a224c7f..92d8a97 100644
80521 --- a/include/linux/pm.h
80522 +++ b/include/linux/pm.h
80523 @@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
80524 struct dev_pm_domain {
80525 struct dev_pm_ops ops;
80526 };
80527 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
80528
80529 /*
80530 * The PM_EVENT_ messages are also used by drivers implementing the legacy
80531 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
80532 index 7c1d252..0e7061d 100644
80533 --- a/include/linux/pm_domain.h
80534 +++ b/include/linux/pm_domain.h
80535 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
80536 int (*thaw_early)(struct device *dev);
80537 int (*thaw)(struct device *dev);
80538 bool (*active_wakeup)(struct device *dev);
80539 -};
80540 +} __no_const;
80541
80542 struct gpd_cpu_data {
80543 unsigned int saved_exit_latency;
80544 - struct cpuidle_state *idle_state;
80545 + cpuidle_state_no_const *idle_state;
80546 };
80547
80548 struct generic_pm_domain {
80549 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
80550 index 6fa7cea..7bf6415 100644
80551 --- a/include/linux/pm_runtime.h
80552 +++ b/include/linux/pm_runtime.h
80553 @@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
80554
80555 static inline void pm_runtime_mark_last_busy(struct device *dev)
80556 {
80557 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
80558 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
80559 }
80560
80561 #else /* !CONFIG_PM_RUNTIME */
80562 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
80563 index 195aafc..49a7bc2 100644
80564 --- a/include/linux/pnp.h
80565 +++ b/include/linux/pnp.h
80566 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
80567 struct pnp_fixup {
80568 char id[7];
80569 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
80570 -};
80571 +} __do_const;
80572
80573 /* config parameters */
80574 #define PNP_CONFIG_NORMAL 0x0001
80575 diff --git a/include/linux/poison.h b/include/linux/poison.h
80576 index 2110a81..13a11bb 100644
80577 --- a/include/linux/poison.h
80578 +++ b/include/linux/poison.h
80579 @@ -19,8 +19,8 @@
80580 * under normal circumstances, used to verify that nobody uses
80581 * non-initialized list entries.
80582 */
80583 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
80584 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80585 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
80586 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
80587
80588 /********** include/linux/timer.h **********/
80589 /*
80590 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
80591 index d8b187c3..9a9257a 100644
80592 --- a/include/linux/power/smartreflex.h
80593 +++ b/include/linux/power/smartreflex.h
80594 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
80595 int (*notify)(struct omap_sr *sr, u32 status);
80596 u8 notify_flags;
80597 u8 class_type;
80598 -};
80599 +} __do_const;
80600
80601 /**
80602 * struct omap_sr_nvalue_table - Smartreflex n-target value info
80603 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
80604 index 4ea1d37..80f4b33 100644
80605 --- a/include/linux/ppp-comp.h
80606 +++ b/include/linux/ppp-comp.h
80607 @@ -84,7 +84,7 @@ struct compressor {
80608 struct module *owner;
80609 /* Extra skb space needed by the compressor algorithm */
80610 unsigned int comp_extra;
80611 -};
80612 +} __do_const;
80613
80614 /*
80615 * The return value from decompress routine is the length of the
80616 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
80617 index a3d9dc8..8af9922 100644
80618 --- a/include/linux/preempt.h
80619 +++ b/include/linux/preempt.h
80620 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
80621 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
80622 #endif
80623
80624 +#define raw_preempt_count_add(val) __preempt_count_add(val)
80625 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
80626 +
80627 #define __preempt_count_inc() __preempt_count_add(1)
80628 #define __preempt_count_dec() __preempt_count_sub(1)
80629
80630 #define preempt_count_inc() preempt_count_add(1)
80631 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
80632 #define preempt_count_dec() preempt_count_sub(1)
80633 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
80634
80635 #ifdef CONFIG_PREEMPT_COUNT
80636
80637 @@ -41,6 +46,12 @@ do { \
80638 barrier(); \
80639 } while (0)
80640
80641 +#define raw_preempt_disable() \
80642 +do { \
80643 + raw_preempt_count_inc(); \
80644 + barrier(); \
80645 +} while (0)
80646 +
80647 #define sched_preempt_enable_no_resched() \
80648 do { \
80649 barrier(); \
80650 @@ -49,6 +60,12 @@ do { \
80651
80652 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
80653
80654 +#define raw_preempt_enable_no_resched() \
80655 +do { \
80656 + barrier(); \
80657 + raw_preempt_count_dec(); \
80658 +} while (0)
80659 +
80660 #ifdef CONFIG_PREEMPT
80661 #define preempt_enable() \
80662 do { \
80663 @@ -105,8 +122,10 @@ do { \
80664 * region.
80665 */
80666 #define preempt_disable() barrier()
80667 +#define raw_preempt_disable() barrier()
80668 #define sched_preempt_enable_no_resched() barrier()
80669 #define preempt_enable_no_resched() barrier()
80670 +#define raw_preempt_enable_no_resched() barrier()
80671 #define preempt_enable() barrier()
80672 #define preempt_check_resched() do { } while (0)
80673
80674 diff --git a/include/linux/printk.h b/include/linux/printk.h
80675 index 6949258..7c4730e 100644
80676 --- a/include/linux/printk.h
80677 +++ b/include/linux/printk.h
80678 @@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
80679 void early_printk(const char *s, ...) { }
80680 #endif
80681
80682 +extern int kptr_restrict;
80683 +
80684 #ifdef CONFIG_PRINTK
80685 asmlinkage __printf(5, 0)
80686 int vprintk_emit(int facility, int level,
80687 @@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
80688
80689 extern int printk_delay_msec;
80690 extern int dmesg_restrict;
80691 -extern int kptr_restrict;
80692
80693 extern void wake_up_klogd(void);
80694
80695 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
80696 index 608e60a..c26f864 100644
80697 --- a/include/linux/proc_fs.h
80698 +++ b/include/linux/proc_fs.h
80699 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
80700 return proc_create_data(name, mode, parent, proc_fops, NULL);
80701 }
80702
80703 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
80704 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
80705 +{
80706 +#ifdef CONFIG_GRKERNSEC_PROC_USER
80707 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
80708 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80709 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
80710 +#else
80711 + return proc_create_data(name, mode, parent, proc_fops, NULL);
80712 +#endif
80713 +}
80714 +
80715 +
80716 extern void proc_set_size(struct proc_dir_entry *, loff_t);
80717 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
80718 extern void *PDE_DATA(const struct inode *);
80719 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
80720 index 34a1e10..70f6bde 100644
80721 --- a/include/linux/proc_ns.h
80722 +++ b/include/linux/proc_ns.h
80723 @@ -14,7 +14,7 @@ struct proc_ns_operations {
80724 void (*put)(void *ns);
80725 int (*install)(struct nsproxy *nsproxy, void *ns);
80726 unsigned int (*inum)(void *ns);
80727 -};
80728 +} __do_const __randomize_layout;
80729
80730 struct proc_ns {
80731 void *ns;
80732 diff --git a/include/linux/quota.h b/include/linux/quota.h
80733 index cc7494a..1e27036 100644
80734 --- a/include/linux/quota.h
80735 +++ b/include/linux/quota.h
80736 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
80737
80738 extern bool qid_eq(struct kqid left, struct kqid right);
80739 extern bool qid_lt(struct kqid left, struct kqid right);
80740 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
80741 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
80742 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
80743 extern bool qid_valid(struct kqid qid);
80744
80745 diff --git a/include/linux/random.h b/include/linux/random.h
80746 index 4002b3d..d5ad855 100644
80747 --- a/include/linux/random.h
80748 +++ b/include/linux/random.h
80749 @@ -10,9 +10,19 @@
80750
80751
80752 extern void add_device_randomness(const void *, unsigned int);
80753 +
80754 +static inline void add_latent_entropy(void)
80755 +{
80756 +
80757 +#ifdef LATENT_ENTROPY_PLUGIN
80758 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80759 +#endif
80760 +
80761 +}
80762 +
80763 extern void add_input_randomness(unsigned int type, unsigned int code,
80764 - unsigned int value);
80765 -extern void add_interrupt_randomness(int irq, int irq_flags);
80766 + unsigned int value) __latent_entropy;
80767 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
80768
80769 extern void get_random_bytes(void *buf, int nbytes);
80770 extern void get_random_bytes_arch(void *buf, int nbytes);
80771 @@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
80772 extern const struct file_operations random_fops, urandom_fops;
80773 #endif
80774
80775 -unsigned int get_random_int(void);
80776 +unsigned int __intentional_overflow(-1) get_random_int(void);
80777 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
80778
80779 -u32 prandom_u32(void);
80780 +u32 prandom_u32(void) __intentional_overflow(-1);
80781 void prandom_bytes(void *buf, int nbytes);
80782 void prandom_seed(u32 seed);
80783 void prandom_reseed_late(void);
80784 @@ -38,6 +48,11 @@ struct rnd_state {
80785 u32 prandom_u32_state(struct rnd_state *state);
80786 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
80787
80788 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
80789 +{
80790 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
80791 +}
80792 +
80793 /*
80794 * Handle minimum values for seeds
80795 */
80796 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
80797 index fea49b5..2ac22bb 100644
80798 --- a/include/linux/rbtree_augmented.h
80799 +++ b/include/linux/rbtree_augmented.h
80800 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
80801 old->rbaugmented = rbcompute(old); \
80802 } \
80803 rbstatic const struct rb_augment_callbacks rbname = { \
80804 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
80805 + .propagate = rbname ## _propagate, \
80806 + .copy = rbname ## _copy, \
80807 + .rotate = rbname ## _rotate \
80808 };
80809
80810
80811 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
80812 index 45a0a9e..e83788e 100644
80813 --- a/include/linux/rculist.h
80814 +++ b/include/linux/rculist.h
80815 @@ -29,8 +29,8 @@
80816 */
80817 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
80818 {
80819 - ACCESS_ONCE(list->next) = list;
80820 - ACCESS_ONCE(list->prev) = list;
80821 + ACCESS_ONCE_RW(list->next) = list;
80822 + ACCESS_ONCE_RW(list->prev) = list;
80823 }
80824
80825 /*
80826 @@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
80827 struct list_head *prev, struct list_head *next);
80828 #endif
80829
80830 +extern void __pax_list_add_rcu(struct list_head *new,
80831 + struct list_head *prev, struct list_head *next);
80832 +
80833 /**
80834 * list_add_rcu - add a new entry to rcu-protected list
80835 * @new: new entry to be added
80836 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
80837 __list_add_rcu(new, head, head->next);
80838 }
80839
80840 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
80841 +{
80842 + __pax_list_add_rcu(new, head, head->next);
80843 +}
80844 +
80845 /**
80846 * list_add_tail_rcu - add a new entry to rcu-protected list
80847 * @new: new entry to be added
80848 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
80849 __list_add_rcu(new, head->prev, head);
80850 }
80851
80852 +static inline void pax_list_add_tail_rcu(struct list_head *new,
80853 + struct list_head *head)
80854 +{
80855 + __pax_list_add_rcu(new, head->prev, head);
80856 +}
80857 +
80858 /**
80859 * list_del_rcu - deletes entry from list without re-initialization
80860 * @entry: the element to delete from the list.
80861 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
80862 entry->prev = LIST_POISON2;
80863 }
80864
80865 +extern void pax_list_del_rcu(struct list_head *entry);
80866 +
80867 /**
80868 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
80869 * @n: the element to delete from the hash list.
80870 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
80871 index 9e7db9e..7d4fd72 100644
80872 --- a/include/linux/reboot.h
80873 +++ b/include/linux/reboot.h
80874 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
80875 */
80876
80877 extern void migrate_to_reboot_cpu(void);
80878 -extern void machine_restart(char *cmd);
80879 -extern void machine_halt(void);
80880 -extern void machine_power_off(void);
80881 +extern void machine_restart(char *cmd) __noreturn;
80882 +extern void machine_halt(void) __noreturn;
80883 +extern void machine_power_off(void) __noreturn;
80884
80885 extern void machine_shutdown(void);
80886 struct pt_regs;
80887 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
80888 */
80889
80890 extern void kernel_restart_prepare(char *cmd);
80891 -extern void kernel_restart(char *cmd);
80892 -extern void kernel_halt(void);
80893 -extern void kernel_power_off(void);
80894 +extern void kernel_restart(char *cmd) __noreturn;
80895 +extern void kernel_halt(void) __noreturn;
80896 +extern void kernel_power_off(void) __noreturn;
80897
80898 extern int C_A_D; /* for sysctl */
80899 void ctrl_alt_del(void);
80900 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
80901 * Emergency restart, callable from an interrupt handler.
80902 */
80903
80904 -extern void emergency_restart(void);
80905 +extern void emergency_restart(void) __noreturn;
80906 #include <asm/emergency-restart.h>
80907
80908 #endif /* _LINUX_REBOOT_H */
80909 diff --git a/include/linux/regset.h b/include/linux/regset.h
80910 index 8e0c9fe..ac4d221 100644
80911 --- a/include/linux/regset.h
80912 +++ b/include/linux/regset.h
80913 @@ -161,7 +161,8 @@ struct user_regset {
80914 unsigned int align;
80915 unsigned int bias;
80916 unsigned int core_note_type;
80917 -};
80918 +} __do_const;
80919 +typedef struct user_regset __no_const user_regset_no_const;
80920
80921 /**
80922 * struct user_regset_view - available regsets
80923 diff --git a/include/linux/relay.h b/include/linux/relay.h
80924 index d7c8359..818daf5 100644
80925 --- a/include/linux/relay.h
80926 +++ b/include/linux/relay.h
80927 @@ -157,7 +157,7 @@ struct rchan_callbacks
80928 * The callback should return 0 if successful, negative if not.
80929 */
80930 int (*remove_buf_file)(struct dentry *dentry);
80931 -};
80932 +} __no_const;
80933
80934 /*
80935 * CONFIG_RELAY kernel API, kernel/relay.c
80936 diff --git a/include/linux/rio.h b/include/linux/rio.h
80937 index b71d573..2f940bd 100644
80938 --- a/include/linux/rio.h
80939 +++ b/include/linux/rio.h
80940 @@ -355,7 +355,7 @@ struct rio_ops {
80941 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
80942 u64 rstart, u32 size, u32 flags);
80943 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
80944 -};
80945 +} __no_const;
80946
80947 #define RIO_RESOURCE_MEM 0x00000100
80948 #define RIO_RESOURCE_DOORBELL 0x00000200
80949 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
80950 index 6dacb93..6174423 100644
80951 --- a/include/linux/rmap.h
80952 +++ b/include/linux/rmap.h
80953 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
80954 void anon_vma_init(void); /* create anon_vma_cachep */
80955 int anon_vma_prepare(struct vm_area_struct *);
80956 void unlink_anon_vmas(struct vm_area_struct *);
80957 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
80958 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
80959 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
80960 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
80961
80962 static inline void anon_vma_merge(struct vm_area_struct *vma,
80963 struct vm_area_struct *next)
80964 diff --git a/include/linux/sched.h b/include/linux/sched.h
80965 index 53f97eb..1d90705 100644
80966 --- a/include/linux/sched.h
80967 +++ b/include/linux/sched.h
80968 @@ -63,6 +63,7 @@ struct bio_list;
80969 struct fs_struct;
80970 struct perf_event_context;
80971 struct blk_plug;
80972 +struct linux_binprm;
80973
80974 /*
80975 * List of flags we want to share for kernel threads,
80976 @@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
80977 extern int in_sched_functions(unsigned long addr);
80978
80979 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
80980 -extern signed long schedule_timeout(signed long timeout);
80981 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
80982 extern signed long schedule_timeout_interruptible(signed long timeout);
80983 extern signed long schedule_timeout_killable(signed long timeout);
80984 extern signed long schedule_timeout_uninterruptible(signed long timeout);
80985 @@ -315,6 +316,19 @@ struct nsproxy;
80986 struct user_namespace;
80987
80988 #ifdef CONFIG_MMU
80989 +
80990 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80991 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
80992 +#else
80993 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80994 +{
80995 + return 0;
80996 +}
80997 +#endif
80998 +
80999 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81000 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81001 +
81002 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81003 extern unsigned long
81004 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81005 @@ -600,6 +614,17 @@ struct signal_struct {
81006 #ifdef CONFIG_TASKSTATS
81007 struct taskstats *stats;
81008 #endif
81009 +
81010 +#ifdef CONFIG_GRKERNSEC
81011 + u32 curr_ip;
81012 + u32 saved_ip;
81013 + u32 gr_saddr;
81014 + u32 gr_daddr;
81015 + u16 gr_sport;
81016 + u16 gr_dport;
81017 + u8 used_accept:1;
81018 +#endif
81019 +
81020 #ifdef CONFIG_AUDIT
81021 unsigned audit_tty;
81022 unsigned audit_tty_log_passwd;
81023 @@ -626,7 +651,7 @@ struct signal_struct {
81024 struct mutex cred_guard_mutex; /* guard against foreign influences on
81025 * credential calculations
81026 * (notably. ptrace) */
81027 -};
81028 +} __randomize_layout;
81029
81030 /*
81031 * Bits in flags field of signal_struct.
81032 @@ -680,6 +705,14 @@ struct user_struct {
81033 struct key *session_keyring; /* UID's default session keyring */
81034 #endif
81035
81036 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81037 + unsigned char kernel_banned;
81038 +#endif
81039 +#ifdef CONFIG_GRKERNSEC_BRUTE
81040 + unsigned char suid_banned;
81041 + unsigned long suid_ban_expires;
81042 +#endif
81043 +
81044 /* Hash table maintenance information */
81045 struct hlist_node uidhash_node;
81046 kuid_t uid;
81047 @@ -687,7 +720,7 @@ struct user_struct {
81048 #ifdef CONFIG_PERF_EVENTS
81049 atomic_long_t locked_vm;
81050 #endif
81051 -};
81052 +} __randomize_layout;
81053
81054 extern int uids_sysfs_init(void);
81055
81056 @@ -1162,8 +1195,8 @@ struct task_struct {
81057 struct list_head thread_group;
81058
81059 struct completion *vfork_done; /* for vfork() */
81060 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81061 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81062 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81063 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81064
81065 cputime_t utime, stime, utimescaled, stimescaled;
81066 cputime_t gtime;
81067 @@ -1188,11 +1221,6 @@ struct task_struct {
81068 struct task_cputime cputime_expires;
81069 struct list_head cpu_timers[3];
81070
81071 -/* process credentials */
81072 - const struct cred __rcu *real_cred; /* objective and real subjective task
81073 - * credentials (COW) */
81074 - const struct cred __rcu *cred; /* effective (overridable) subjective task
81075 - * credentials (COW) */
81076 char comm[TASK_COMM_LEN]; /* executable name excluding path
81077 - access with [gs]et_task_comm (which lock
81078 it with task_lock())
81079 @@ -1209,6 +1237,10 @@ struct task_struct {
81080 #endif
81081 /* CPU-specific state of this task */
81082 struct thread_struct thread;
81083 +/* thread_info moved to task_struct */
81084 +#ifdef CONFIG_X86
81085 + struct thread_info tinfo;
81086 +#endif
81087 /* filesystem information */
81088 struct fs_struct *fs;
81089 /* open file information */
81090 @@ -1282,6 +1314,10 @@ struct task_struct {
81091 gfp_t lockdep_reclaim_gfp;
81092 #endif
81093
81094 +/* process credentials */
81095 + const struct cred __rcu *real_cred; /* objective and real subjective task
81096 + * credentials (COW) */
81097 +
81098 /* journalling filesystem info */
81099 void *journal_info;
81100
81101 @@ -1320,6 +1356,10 @@ struct task_struct {
81102 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81103 struct list_head cg_list;
81104 #endif
81105 +
81106 + const struct cred __rcu *cred; /* effective (overridable) subjective task
81107 + * credentials (COW) */
81108 +
81109 #ifdef CONFIG_FUTEX
81110 struct robust_list_head __user *robust_list;
81111 #ifdef CONFIG_COMPAT
81112 @@ -1454,7 +1494,78 @@ struct task_struct {
81113 unsigned int sequential_io;
81114 unsigned int sequential_io_avg;
81115 #endif
81116 -};
81117 +
81118 +#ifdef CONFIG_GRKERNSEC
81119 + /* grsecurity */
81120 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81121 + u64 exec_id;
81122 +#endif
81123 +#ifdef CONFIG_GRKERNSEC_SETXID
81124 + const struct cred *delayed_cred;
81125 +#endif
81126 + struct dentry *gr_chroot_dentry;
81127 + struct acl_subject_label *acl;
81128 + struct acl_subject_label *tmpacl;
81129 + struct acl_role_label *role;
81130 + struct file *exec_file;
81131 + unsigned long brute_expires;
81132 + u16 acl_role_id;
81133 + u8 inherited;
81134 + /* is this the task that authenticated to the special role */
81135 + u8 acl_sp_role;
81136 + u8 is_writable;
81137 + u8 brute;
81138 + u8 gr_is_chrooted;
81139 +#endif
81140 +
81141 +} __randomize_layout;
81142 +
81143 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81144 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81145 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81146 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81147 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81148 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81149 +
81150 +#ifdef CONFIG_PAX_SOFTMODE
81151 +extern int pax_softmode;
81152 +#endif
81153 +
81154 +extern int pax_check_flags(unsigned long *);
81155 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81156 +
81157 +/* if tsk != current then task_lock must be held on it */
81158 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81159 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
81160 +{
81161 + if (likely(tsk->mm))
81162 + return tsk->mm->pax_flags;
81163 + else
81164 + return 0UL;
81165 +}
81166 +
81167 +/* if tsk != current then task_lock must be held on it */
81168 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81169 +{
81170 + if (likely(tsk->mm)) {
81171 + tsk->mm->pax_flags = flags;
81172 + return 0;
81173 + }
81174 + return -EINVAL;
81175 +}
81176 +#endif
81177 +
81178 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81179 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
81180 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81181 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81182 +#endif
81183 +
81184 +struct path;
81185 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81186 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81187 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81188 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
81189
81190 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81191 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81192 @@ -1531,7 +1642,7 @@ struct pid_namespace;
81193 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81194 struct pid_namespace *ns);
81195
81196 -static inline pid_t task_pid_nr(struct task_struct *tsk)
81197 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
81198 {
81199 return tsk->pid;
81200 }
81201 @@ -1981,7 +2092,9 @@ void yield(void);
81202 extern struct exec_domain default_exec_domain;
81203
81204 union thread_union {
81205 +#ifndef CONFIG_X86
81206 struct thread_info thread_info;
81207 +#endif
81208 unsigned long stack[THREAD_SIZE/sizeof(long)];
81209 };
81210
81211 @@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
81212 */
81213
81214 extern struct task_struct *find_task_by_vpid(pid_t nr);
81215 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81216 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81217 struct pid_namespace *ns);
81218
81219 @@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81220 extern void exit_itimers(struct signal_struct *);
81221 extern void flush_itimer_signals(void);
81222
81223 -extern void do_group_exit(int);
81224 +extern __noreturn void do_group_exit(int);
81225
81226 extern int allow_signal(int);
81227 extern int disallow_signal(int);
81228 @@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81229
81230 #endif
81231
81232 -static inline int object_is_on_stack(void *obj)
81233 +static inline int object_starts_on_stack(void *obj)
81234 {
81235 - void *stack = task_stack_page(current);
81236 + const void *stack = task_stack_page(current);
81237
81238 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81239 }
81240 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81241 index e3347c5..f682891 100644
81242 --- a/include/linux/sched/sysctl.h
81243 +++ b/include/linux/sched/sysctl.h
81244 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81245 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81246
81247 extern int sysctl_max_map_count;
81248 +extern unsigned long sysctl_heap_stack_gap;
81249
81250 extern unsigned int sysctl_sched_latency;
81251 extern unsigned int sysctl_sched_min_granularity;
81252 diff --git a/include/linux/security.h b/include/linux/security.h
81253 index 5623a7f..b352409 100644
81254 --- a/include/linux/security.h
81255 +++ b/include/linux/security.h
81256 @@ -27,6 +27,7 @@
81257 #include <linux/slab.h>
81258 #include <linux/err.h>
81259 #include <linux/string.h>
81260 +#include <linux/grsecurity.h>
81261
81262 struct linux_binprm;
81263 struct cred;
81264 @@ -116,8 +117,6 @@ struct seq_file;
81265
81266 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81267
81268 -void reset_security_ops(void);
81269 -
81270 #ifdef CONFIG_MMU
81271 extern unsigned long mmap_min_addr;
81272 extern unsigned long dac_mmap_min_addr;
81273 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81274 index dc368b8..e895209 100644
81275 --- a/include/linux/semaphore.h
81276 +++ b/include/linux/semaphore.h
81277 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81278 }
81279
81280 extern void down(struct semaphore *sem);
81281 -extern int __must_check down_interruptible(struct semaphore *sem);
81282 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81283 extern int __must_check down_killable(struct semaphore *sem);
81284 extern int __must_check down_trylock(struct semaphore *sem);
81285 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81286 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81287 index 52e0097..09625ef 100644
81288 --- a/include/linux/seq_file.h
81289 +++ b/include/linux/seq_file.h
81290 @@ -27,6 +27,9 @@ struct seq_file {
81291 struct mutex lock;
81292 const struct seq_operations *op;
81293 int poll_event;
81294 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81295 + u64 exec_id;
81296 +#endif
81297 #ifdef CONFIG_USER_NS
81298 struct user_namespace *user_ns;
81299 #endif
81300 @@ -39,6 +42,7 @@ struct seq_operations {
81301 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81302 int (*show) (struct seq_file *m, void *v);
81303 };
81304 +typedef struct seq_operations __no_const seq_operations_no_const;
81305
81306 #define SEQ_SKIP 1
81307
81308 diff --git a/include/linux/shm.h b/include/linux/shm.h
81309 index 429c199..4d42e38 100644
81310 --- a/include/linux/shm.h
81311 +++ b/include/linux/shm.h
81312 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81313
81314 /* The task created the shm object. NULL if the task is dead. */
81315 struct task_struct *shm_creator;
81316 +#ifdef CONFIG_GRKERNSEC
81317 + time_t shm_createtime;
81318 + pid_t shm_lapid;
81319 +#endif
81320 };
81321
81322 /* shm_mode upper byte flags */
81323 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81324 index 37cb679..dbaebc0 100644
81325 --- a/include/linux/skbuff.h
81326 +++ b/include/linux/skbuff.h
81327 @@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81328 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81329 int node);
81330 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81331 -static inline struct sk_buff *alloc_skb(unsigned int size,
81332 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81333 gfp_t priority)
81334 {
81335 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81336 @@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
81337 */
81338 static inline int skb_queue_empty(const struct sk_buff_head *list)
81339 {
81340 - return list->next == (struct sk_buff *)list;
81341 + return list->next == (const struct sk_buff *)list;
81342 }
81343
81344 /**
81345 @@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
81346 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81347 const struct sk_buff *skb)
81348 {
81349 - return skb->next == (struct sk_buff *)list;
81350 + return skb->next == (const struct sk_buff *)list;
81351 }
81352
81353 /**
81354 @@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81355 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
81356 const struct sk_buff *skb)
81357 {
81358 - return skb->prev == (struct sk_buff *)list;
81359 + return skb->prev == (const struct sk_buff *)list;
81360 }
81361
81362 /**
81363 @@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81364 return skb->inner_transport_header - skb->inner_network_header;
81365 }
81366
81367 -static inline int skb_network_offset(const struct sk_buff *skb)
81368 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81369 {
81370 return skb_network_header(skb) - skb->data;
81371 }
81372 @@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81373 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81374 */
81375 #ifndef NET_SKB_PAD
81376 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81377 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81378 #endif
81379
81380 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81381 @@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81382 int *err);
81383 unsigned int datagram_poll(struct file *file, struct socket *sock,
81384 struct poll_table_struct *wait);
81385 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81386 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81387 struct iovec *to, int size);
81388 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81389 struct iovec *iov);
81390 @@ -2618,6 +2618,9 @@ static inline void nf_reset(struct sk_buff *skb)
81391 nf_bridge_put(skb->nf_bridge);
81392 skb->nf_bridge = NULL;
81393 #endif
81394 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81395 + skb->nf_trace = 0;
81396 +#endif
81397 }
81398
81399 static inline void nf_reset_trace(struct sk_buff *skb)
81400 diff --git a/include/linux/slab.h b/include/linux/slab.h
81401 index 1e2f4fe..df49ca6 100644
81402 --- a/include/linux/slab.h
81403 +++ b/include/linux/slab.h
81404 @@ -14,15 +14,29 @@
81405 #include <linux/gfp.h>
81406 #include <linux/types.h>
81407 #include <linux/workqueue.h>
81408 -
81409 +#include <linux/err.h>
81410
81411 /*
81412 * Flags to pass to kmem_cache_create().
81413 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81414 */
81415 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81416 +
81417 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81418 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81419 +#else
81420 +#define SLAB_USERCOPY 0x00000000UL
81421 +#endif
81422 +
81423 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81424 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81425 +
81426 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81427 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81428 +#else
81429 +#define SLAB_NO_SANITIZE 0x00000000UL
81430 +#endif
81431 +
81432 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81433 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81434 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81435 @@ -98,10 +112,13 @@
81436 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81437 * Both make kfree a no-op.
81438 */
81439 -#define ZERO_SIZE_PTR ((void *)16)
81440 +#define ZERO_SIZE_PTR \
81441 +({ \
81442 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81443 + (void *)(-MAX_ERRNO-1L); \
81444 +})
81445
81446 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81447 - (unsigned long)ZERO_SIZE_PTR)
81448 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81449
81450 #include <linux/kmemleak.h>
81451
81452 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81453 void kfree(const void *);
81454 void kzfree(const void *);
81455 size_t ksize(const void *);
81456 +const char *check_heap_object(const void *ptr, unsigned long n);
81457 +bool is_usercopy_object(const void *ptr);
81458
81459 /*
81460 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81461 @@ -174,7 +193,7 @@ struct kmem_cache {
81462 unsigned int align; /* Alignment as calculated */
81463 unsigned long flags; /* Active flags on the slab */
81464 const char *name; /* Slab name for sysfs */
81465 - int refcount; /* Use counter */
81466 + atomic_t refcount; /* Use counter */
81467 void (*ctor)(void *); /* Called on object slot creation */
81468 struct list_head list; /* List of all slab caches on the system */
81469 };
81470 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81471 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81472 #endif
81473
81474 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81475 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
81476 +#endif
81477 +
81478 /*
81479 * Figure out which kmalloc slab an allocation of a certain size
81480 * belongs to.
81481 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81482 * 2 = 120 .. 192 bytes
81483 * n = 2^(n-1) .. 2^n -1
81484 */
81485 -static __always_inline int kmalloc_index(size_t size)
81486 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
81487 {
81488 if (!size)
81489 return 0;
81490 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
81491 }
81492 #endif /* !CONFIG_SLOB */
81493
81494 -void *__kmalloc(size_t size, gfp_t flags);
81495 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
81496 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
81497
81498 #ifdef CONFIG_NUMA
81499 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
81500 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
81501 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
81502 #else
81503 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
81504 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
81505 index 09bfffb..4fc80fb 100644
81506 --- a/include/linux/slab_def.h
81507 +++ b/include/linux/slab_def.h
81508 @@ -36,7 +36,7 @@ struct kmem_cache {
81509 /* 4) cache creation/removal */
81510 const char *name;
81511 struct list_head list;
81512 - int refcount;
81513 + atomic_t refcount;
81514 int object_size;
81515 int align;
81516
81517 @@ -52,10 +52,14 @@ struct kmem_cache {
81518 unsigned long node_allocs;
81519 unsigned long node_frees;
81520 unsigned long node_overflow;
81521 - atomic_t allochit;
81522 - atomic_t allocmiss;
81523 - atomic_t freehit;
81524 - atomic_t freemiss;
81525 + atomic_unchecked_t allochit;
81526 + atomic_unchecked_t allocmiss;
81527 + atomic_unchecked_t freehit;
81528 + atomic_unchecked_t freemiss;
81529 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81530 + atomic_unchecked_t sanitized;
81531 + atomic_unchecked_t not_sanitized;
81532 +#endif
81533
81534 /*
81535 * If debugging is enabled, then the allocator can add additional
81536 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
81537 index f56bfa9..8378a26 100644
81538 --- a/include/linux/slub_def.h
81539 +++ b/include/linux/slub_def.h
81540 @@ -74,7 +74,7 @@ struct kmem_cache {
81541 struct kmem_cache_order_objects max;
81542 struct kmem_cache_order_objects min;
81543 gfp_t allocflags; /* gfp flags to use on each alloc */
81544 - int refcount; /* Refcount for slab cache destroy */
81545 + atomic_t refcount; /* Refcount for slab cache destroy */
81546 void (*ctor)(void *);
81547 int inuse; /* Offset to metadata */
81548 int align; /* Alignment */
81549 diff --git a/include/linux/smp.h b/include/linux/smp.h
81550 index 5da22ee..71d8a28 100644
81551 --- a/include/linux/smp.h
81552 +++ b/include/linux/smp.h
81553 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
81554 #endif
81555
81556 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
81557 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
81558 #define put_cpu() preempt_enable()
81559 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
81560
81561 /*
81562 * Callback to arch code if there's nosmp or maxcpus=0 on the
81563 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
81564 index 54f91d3..be2c379 100644
81565 --- a/include/linux/sock_diag.h
81566 +++ b/include/linux/sock_diag.h
81567 @@ -11,7 +11,7 @@ struct sock;
81568 struct sock_diag_handler {
81569 __u8 family;
81570 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
81571 -};
81572 +} __do_const;
81573
81574 int sock_diag_register(const struct sock_diag_handler *h);
81575 void sock_diag_unregister(const struct sock_diag_handler *h);
81576 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
81577 index 680f9a3..f13aeb0 100644
81578 --- a/include/linux/sonet.h
81579 +++ b/include/linux/sonet.h
81580 @@ -7,7 +7,7 @@
81581 #include <uapi/linux/sonet.h>
81582
81583 struct k_sonet_stats {
81584 -#define __HANDLE_ITEM(i) atomic_t i
81585 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
81586 __SONET_ITEMS
81587 #undef __HANDLE_ITEM
81588 };
81589 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
81590 index 07d8e53..dc934c9 100644
81591 --- a/include/linux/sunrpc/addr.h
81592 +++ b/include/linux/sunrpc/addr.h
81593 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
81594 {
81595 switch (sap->sa_family) {
81596 case AF_INET:
81597 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
81598 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
81599 case AF_INET6:
81600 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
81601 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
81602 }
81603 return 0;
81604 }
81605 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
81606 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
81607 const struct sockaddr *src)
81608 {
81609 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
81610 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
81611 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
81612
81613 dsin->sin_family = ssin->sin_family;
81614 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
81615 if (sa->sa_family != AF_INET6)
81616 return 0;
81617
81618 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
81619 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
81620 }
81621
81622 #endif /* _LINUX_SUNRPC_ADDR_H */
81623 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
81624 index 8af2804..c7414ef 100644
81625 --- a/include/linux/sunrpc/clnt.h
81626 +++ b/include/linux/sunrpc/clnt.h
81627 @@ -97,7 +97,7 @@ struct rpc_procinfo {
81628 unsigned int p_timer; /* Which RTT timer to use */
81629 u32 p_statidx; /* Which procedure to account */
81630 const char * p_name; /* name of procedure */
81631 -};
81632 +} __do_const;
81633
81634 #ifdef __KERNEL__
81635
81636 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
81637 index 6eecfc2..7ada79d 100644
81638 --- a/include/linux/sunrpc/svc.h
81639 +++ b/include/linux/sunrpc/svc.h
81640 @@ -410,7 +410,7 @@ struct svc_procedure {
81641 unsigned int pc_count; /* call count */
81642 unsigned int pc_cachetype; /* cache info (NFS) */
81643 unsigned int pc_xdrressize; /* maximum size of XDR reply */
81644 -};
81645 +} __do_const;
81646
81647 /*
81648 * Function prototypes.
81649 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
81650 index 0b8e3e6..33e0a01 100644
81651 --- a/include/linux/sunrpc/svc_rdma.h
81652 +++ b/include/linux/sunrpc/svc_rdma.h
81653 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
81654 extern unsigned int svcrdma_max_requests;
81655 extern unsigned int svcrdma_max_req_size;
81656
81657 -extern atomic_t rdma_stat_recv;
81658 -extern atomic_t rdma_stat_read;
81659 -extern atomic_t rdma_stat_write;
81660 -extern atomic_t rdma_stat_sq_starve;
81661 -extern atomic_t rdma_stat_rq_starve;
81662 -extern atomic_t rdma_stat_rq_poll;
81663 -extern atomic_t rdma_stat_rq_prod;
81664 -extern atomic_t rdma_stat_sq_poll;
81665 -extern atomic_t rdma_stat_sq_prod;
81666 +extern atomic_unchecked_t rdma_stat_recv;
81667 +extern atomic_unchecked_t rdma_stat_read;
81668 +extern atomic_unchecked_t rdma_stat_write;
81669 +extern atomic_unchecked_t rdma_stat_sq_starve;
81670 +extern atomic_unchecked_t rdma_stat_rq_starve;
81671 +extern atomic_unchecked_t rdma_stat_rq_poll;
81672 +extern atomic_unchecked_t rdma_stat_rq_prod;
81673 +extern atomic_unchecked_t rdma_stat_sq_poll;
81674 +extern atomic_unchecked_t rdma_stat_sq_prod;
81675
81676 #define RPCRDMA_VERSION 1
81677
81678 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
81679 index 8d71d65..f79586e 100644
81680 --- a/include/linux/sunrpc/svcauth.h
81681 +++ b/include/linux/sunrpc/svcauth.h
81682 @@ -120,7 +120,7 @@ struct auth_ops {
81683 int (*release)(struct svc_rqst *rq);
81684 void (*domain_release)(struct auth_domain *);
81685 int (*set_client)(struct svc_rqst *rq);
81686 -};
81687 +} __do_const;
81688
81689 #define SVC_GARBAGE 1
81690 #define SVC_SYSERR 2
81691 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
81692 index a5ffd32..0935dea 100644
81693 --- a/include/linux/swiotlb.h
81694 +++ b/include/linux/swiotlb.h
81695 @@ -60,7 +60,8 @@ extern void
81696
81697 extern void
81698 swiotlb_free_coherent(struct device *hwdev, size_t size,
81699 - void *vaddr, dma_addr_t dma_handle);
81700 + void *vaddr, dma_addr_t dma_handle,
81701 + struct dma_attrs *attrs);
81702
81703 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
81704 unsigned long offset, size_t size,
81705 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
81706 index 94273bb..c2e05fc 100644
81707 --- a/include/linux/syscalls.h
81708 +++ b/include/linux/syscalls.h
81709 @@ -97,8 +97,14 @@ struct sigaltstack;
81710 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
81711
81712 #define __SC_DECL(t, a) t a
81713 +#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))
81714 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
81715 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
81716 +#define __SC_LONG(t, a) __typeof( \
81717 + __builtin_choose_expr( \
81718 + sizeof(t) > sizeof(int), \
81719 + (t) 0, \
81720 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
81721 + )) a
81722 #define __SC_CAST(t, a) (t) a
81723 #define __SC_ARGS(t, a) a
81724 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
81725 @@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
81726 asmlinkage long sys_fsync(unsigned int fd);
81727 asmlinkage long sys_fdatasync(unsigned int fd);
81728 asmlinkage long sys_bdflush(int func, long data);
81729 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
81730 - char __user *type, unsigned long flags,
81731 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
81732 + const char __user *type, unsigned long flags,
81733 void __user *data);
81734 -asmlinkage long sys_umount(char __user *name, int flags);
81735 -asmlinkage long sys_oldumount(char __user *name);
81736 +asmlinkage long sys_umount(const char __user *name, int flags);
81737 +asmlinkage long sys_oldumount(const char __user *name);
81738 asmlinkage long sys_truncate(const char __user *path, long length);
81739 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
81740 asmlinkage long sys_stat(const char __user *filename,
81741 @@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
81742 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
81743 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
81744 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
81745 - struct sockaddr __user *, int);
81746 + struct sockaddr __user *, int) __intentional_overflow(0);
81747 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
81748 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
81749 unsigned int vlen, unsigned flags);
81750 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
81751 index 27b3b0b..e093dd9 100644
81752 --- a/include/linux/syscore_ops.h
81753 +++ b/include/linux/syscore_ops.h
81754 @@ -16,7 +16,7 @@ struct syscore_ops {
81755 int (*suspend)(void);
81756 void (*resume)(void);
81757 void (*shutdown)(void);
81758 -};
81759 +} __do_const;
81760
81761 extern void register_syscore_ops(struct syscore_ops *ops);
81762 extern void unregister_syscore_ops(struct syscore_ops *ops);
81763 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
81764 index 14a8ff2..fa95f3a 100644
81765 --- a/include/linux/sysctl.h
81766 +++ b/include/linux/sysctl.h
81767 @@ -34,13 +34,13 @@ struct ctl_table_root;
81768 struct ctl_table_header;
81769 struct ctl_dir;
81770
81771 -typedef struct ctl_table ctl_table;
81772 -
81773 typedef int proc_handler (struct ctl_table *ctl, int write,
81774 void __user *buffer, size_t *lenp, loff_t *ppos);
81775
81776 extern int proc_dostring(struct ctl_table *, int,
81777 void __user *, size_t *, loff_t *);
81778 +extern int proc_dostring_modpriv(struct ctl_table *, int,
81779 + void __user *, size_t *, loff_t *);
81780 extern int proc_dointvec(struct ctl_table *, int,
81781 void __user *, size_t *, loff_t *);
81782 extern int proc_dointvec_minmax(struct ctl_table *, int,
81783 @@ -115,7 +115,9 @@ struct ctl_table
81784 struct ctl_table_poll *poll;
81785 void *extra1;
81786 void *extra2;
81787 -};
81788 +} __do_const __randomize_layout;
81789 +typedef struct ctl_table __no_const ctl_table_no_const;
81790 +typedef struct ctl_table ctl_table;
81791
81792 struct ctl_node {
81793 struct rb_node node;
81794 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
81795 index 6695040..3d4192d 100644
81796 --- a/include/linux/sysfs.h
81797 +++ b/include/linux/sysfs.h
81798 @@ -33,7 +33,8 @@ struct attribute {
81799 struct lock_class_key *key;
81800 struct lock_class_key skey;
81801 #endif
81802 -};
81803 +} __do_const;
81804 +typedef struct attribute __no_const attribute_no_const;
81805
81806 /**
81807 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
81808 @@ -62,7 +63,8 @@ struct attribute_group {
81809 struct attribute *, int);
81810 struct attribute **attrs;
81811 struct bin_attribute **bin_attrs;
81812 -};
81813 +} __do_const;
81814 +typedef struct attribute_group __no_const attribute_group_no_const;
81815
81816 /**
81817 * Use these macros to make defining attributes easier. See include/linux/device.h
81818 @@ -126,7 +128,8 @@ struct bin_attribute {
81819 char *, loff_t, size_t);
81820 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
81821 struct vm_area_struct *vma);
81822 -};
81823 +} __do_const;
81824 +typedef struct bin_attribute __no_const bin_attribute_no_const;
81825
81826 /**
81827 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
81828 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
81829 index 387fa7d..3fcde6b 100644
81830 --- a/include/linux/sysrq.h
81831 +++ b/include/linux/sysrq.h
81832 @@ -16,6 +16,7 @@
81833
81834 #include <linux/errno.h>
81835 #include <linux/types.h>
81836 +#include <linux/compiler.h>
81837
81838 /* Possible values of bitmask for enabling sysrq functions */
81839 /* 0x0001 is reserved for enable everything */
81840 @@ -33,7 +34,7 @@ struct sysrq_key_op {
81841 char *help_msg;
81842 char *action_msg;
81843 int enable_mask;
81844 -};
81845 +} __do_const;
81846
81847 #ifdef CONFIG_MAGIC_SYSRQ
81848
81849 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
81850 index fddbe20..0312de8 100644
81851 --- a/include/linux/thread_info.h
81852 +++ b/include/linux/thread_info.h
81853 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
81854 #error "no set_restore_sigmask() provided and default one won't work"
81855 #endif
81856
81857 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
81858 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
81859 +{
81860 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
81861 + if (!__builtin_constant_p(n))
81862 +#endif
81863 + __check_object_size(ptr, n, to_user);
81864 +}
81865 +
81866 #endif /* __KERNEL__ */
81867
81868 #endif /* _LINUX_THREAD_INFO_H */
81869 diff --git a/include/linux/tty.h b/include/linux/tty.h
81870 index 97d660e..6356755 100644
81871 --- a/include/linux/tty.h
81872 +++ b/include/linux/tty.h
81873 @@ -196,7 +196,7 @@ struct tty_port {
81874 const struct tty_port_operations *ops; /* Port operations */
81875 spinlock_t lock; /* Lock protecting tty field */
81876 int blocked_open; /* Waiting to open */
81877 - int count; /* Usage count */
81878 + atomic_t count; /* Usage count */
81879 wait_queue_head_t open_wait; /* Open waiters */
81880 wait_queue_head_t close_wait; /* Close waiters */
81881 wait_queue_head_t delta_msr_wait; /* Modem status change */
81882 @@ -278,7 +278,7 @@ struct tty_struct {
81883 /* If the tty has a pending do_SAK, queue it here - akpm */
81884 struct work_struct SAK_work;
81885 struct tty_port *port;
81886 -};
81887 +} __randomize_layout;
81888
81889 /* Each of a tty's open files has private_data pointing to tty_file_private */
81890 struct tty_file_private {
81891 @@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
81892 struct tty_struct *tty, struct file *filp);
81893 static inline int tty_port_users(struct tty_port *port)
81894 {
81895 - return port->count + port->blocked_open;
81896 + return atomic_read(&port->count) + port->blocked_open;
81897 }
81898
81899 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
81900 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
81901 index 756a609..f61242d 100644
81902 --- a/include/linux/tty_driver.h
81903 +++ b/include/linux/tty_driver.h
81904 @@ -285,7 +285,7 @@ struct tty_operations {
81905 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
81906 #endif
81907 const struct file_operations *proc_fops;
81908 -};
81909 +} __do_const;
81910
81911 struct tty_driver {
81912 int magic; /* magic number for this structure */
81913 @@ -319,7 +319,7 @@ struct tty_driver {
81914
81915 const struct tty_operations *ops;
81916 struct list_head tty_drivers;
81917 -};
81918 +} __randomize_layout;
81919
81920 extern struct list_head tty_drivers;
81921
81922 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
81923 index f15c898..207b7d1 100644
81924 --- a/include/linux/tty_ldisc.h
81925 +++ b/include/linux/tty_ldisc.h
81926 @@ -211,7 +211,7 @@ struct tty_ldisc_ops {
81927
81928 struct module *owner;
81929
81930 - int refcount;
81931 + atomic_t refcount;
81932 };
81933
81934 struct tty_ldisc {
81935 diff --git a/include/linux/types.h b/include/linux/types.h
81936 index 4d118ba..c3ee9bf 100644
81937 --- a/include/linux/types.h
81938 +++ b/include/linux/types.h
81939 @@ -176,10 +176,26 @@ typedef struct {
81940 int counter;
81941 } atomic_t;
81942
81943 +#ifdef CONFIG_PAX_REFCOUNT
81944 +typedef struct {
81945 + int counter;
81946 +} atomic_unchecked_t;
81947 +#else
81948 +typedef atomic_t atomic_unchecked_t;
81949 +#endif
81950 +
81951 #ifdef CONFIG_64BIT
81952 typedef struct {
81953 long counter;
81954 } atomic64_t;
81955 +
81956 +#ifdef CONFIG_PAX_REFCOUNT
81957 +typedef struct {
81958 + long counter;
81959 +} atomic64_unchecked_t;
81960 +#else
81961 +typedef atomic64_t atomic64_unchecked_t;
81962 +#endif
81963 #endif
81964
81965 struct list_head {
81966 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
81967 index 9d8cf05..0ed74dd 100644
81968 --- a/include/linux/uaccess.h
81969 +++ b/include/linux/uaccess.h
81970 @@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
81971 long ret; \
81972 mm_segment_t old_fs = get_fs(); \
81973 \
81974 - set_fs(KERNEL_DS); \
81975 pagefault_disable(); \
81976 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
81977 - pagefault_enable(); \
81978 + set_fs(KERNEL_DS); \
81979 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
81980 set_fs(old_fs); \
81981 + pagefault_enable(); \
81982 ret; \
81983 })
81984
81985 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
81986 index 8e522cbc..aa8572d 100644
81987 --- a/include/linux/uidgid.h
81988 +++ b/include/linux/uidgid.h
81989 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
81990
81991 #endif /* CONFIG_USER_NS */
81992
81993 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
81994 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
81995 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
81996 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
81997 +
81998 #endif /* _LINUX_UIDGID_H */
81999 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82000 index 99c1b4d..562e6f3 100644
82001 --- a/include/linux/unaligned/access_ok.h
82002 +++ b/include/linux/unaligned/access_ok.h
82003 @@ -4,34 +4,34 @@
82004 #include <linux/kernel.h>
82005 #include <asm/byteorder.h>
82006
82007 -static inline u16 get_unaligned_le16(const void *p)
82008 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82009 {
82010 - return le16_to_cpup((__le16 *)p);
82011 + return le16_to_cpup((const __le16 *)p);
82012 }
82013
82014 -static inline u32 get_unaligned_le32(const void *p)
82015 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82016 {
82017 - return le32_to_cpup((__le32 *)p);
82018 + return le32_to_cpup((const __le32 *)p);
82019 }
82020
82021 -static inline u64 get_unaligned_le64(const void *p)
82022 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82023 {
82024 - return le64_to_cpup((__le64 *)p);
82025 + return le64_to_cpup((const __le64 *)p);
82026 }
82027
82028 -static inline u16 get_unaligned_be16(const void *p)
82029 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82030 {
82031 - return be16_to_cpup((__be16 *)p);
82032 + return be16_to_cpup((const __be16 *)p);
82033 }
82034
82035 -static inline u32 get_unaligned_be32(const void *p)
82036 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82037 {
82038 - return be32_to_cpup((__be32 *)p);
82039 + return be32_to_cpup((const __be32 *)p);
82040 }
82041
82042 -static inline u64 get_unaligned_be64(const void *p)
82043 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82044 {
82045 - return be64_to_cpup((__be64 *)p);
82046 + return be64_to_cpup((const __be64 *)p);
82047 }
82048
82049 static inline void put_unaligned_le16(u16 val, void *p)
82050 diff --git a/include/linux/usb.h b/include/linux/usb.h
82051 index 7454865..29f4bfa 100644
82052 --- a/include/linux/usb.h
82053 +++ b/include/linux/usb.h
82054 @@ -563,7 +563,7 @@ struct usb_device {
82055 int maxchild;
82056
82057 u32 quirks;
82058 - atomic_t urbnum;
82059 + atomic_unchecked_t urbnum;
82060
82061 unsigned long active_duration;
82062
82063 @@ -1641,7 +1641,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82064
82065 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82066 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82067 - void *data, __u16 size, int timeout);
82068 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
82069 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82070 void *data, int len, int *actual_length, int timeout);
82071 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82072 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82073 index e452ba6..78f8e80 100644
82074 --- a/include/linux/usb/renesas_usbhs.h
82075 +++ b/include/linux/usb/renesas_usbhs.h
82076 @@ -39,7 +39,7 @@ enum {
82077 */
82078 struct renesas_usbhs_driver_callback {
82079 int (*notify_hotplug)(struct platform_device *pdev);
82080 -};
82081 +} __no_const;
82082
82083 /*
82084 * callback functions for platform
82085 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82086 index 4836ba3..603f6ee 100644
82087 --- a/include/linux/user_namespace.h
82088 +++ b/include/linux/user_namespace.h
82089 @@ -33,7 +33,7 @@ struct user_namespace {
82090 struct key *persistent_keyring_register;
82091 struct rw_semaphore persistent_keyring_register_sem;
82092 #endif
82093 -};
82094 +} __randomize_layout;
82095
82096 extern struct user_namespace init_user_ns;
82097
82098 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82099 index 239e277..22a5cf5 100644
82100 --- a/include/linux/utsname.h
82101 +++ b/include/linux/utsname.h
82102 @@ -24,7 +24,7 @@ struct uts_namespace {
82103 struct new_utsname name;
82104 struct user_namespace *user_ns;
82105 unsigned int proc_inum;
82106 -};
82107 +} __randomize_layout;
82108 extern struct uts_namespace init_uts_ns;
82109
82110 #ifdef CONFIG_UTS_NS
82111 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82112 index 6f8fbcf..4efc177 100644
82113 --- a/include/linux/vermagic.h
82114 +++ b/include/linux/vermagic.h
82115 @@ -25,9 +25,42 @@
82116 #define MODULE_ARCH_VERMAGIC ""
82117 #endif
82118
82119 +#ifdef CONFIG_PAX_REFCOUNT
82120 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
82121 +#else
82122 +#define MODULE_PAX_REFCOUNT ""
82123 +#endif
82124 +
82125 +#ifdef CONSTIFY_PLUGIN
82126 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82127 +#else
82128 +#define MODULE_CONSTIFY_PLUGIN ""
82129 +#endif
82130 +
82131 +#ifdef STACKLEAK_PLUGIN
82132 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82133 +#else
82134 +#define MODULE_STACKLEAK_PLUGIN ""
82135 +#endif
82136 +
82137 +#ifdef RANDSTRUCT_PLUGIN
82138 +#include <generated/randomize_layout_hash.h>
82139 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82140 +#else
82141 +#define MODULE_RANDSTRUCT_PLUGIN
82142 +#endif
82143 +
82144 +#ifdef CONFIG_GRKERNSEC
82145 +#define MODULE_GRSEC "GRSEC "
82146 +#else
82147 +#define MODULE_GRSEC ""
82148 +#endif
82149 +
82150 #define VERMAGIC_STRING \
82151 UTS_RELEASE " " \
82152 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82153 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82154 - MODULE_ARCH_VERMAGIC
82155 + MODULE_ARCH_VERMAGIC \
82156 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82157 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82158
82159 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82160 index 502073a..a7de024 100644
82161 --- a/include/linux/vga_switcheroo.h
82162 +++ b/include/linux/vga_switcheroo.h
82163 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82164
82165 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82166
82167 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82168 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82169 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82170 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82171 #else
82172
82173 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82174 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82175
82176 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82177
82178 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82179 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82180 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82181 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82182
82183 #endif
82184 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82185 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82186 index 4b8a891..cb8df6e 100644
82187 --- a/include/linux/vmalloc.h
82188 +++ b/include/linux/vmalloc.h
82189 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82190 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82191 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82192 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82193 +
82194 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82195 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82196 +#endif
82197 +
82198 /* bits [20..32] reserved for arch specific ioremap internals */
82199
82200 /*
82201 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82202
82203 /* for /dev/kmem */
82204 extern long vread(char *buf, char *addr, unsigned long count);
82205 -extern long vwrite(char *buf, char *addr, unsigned long count);
82206 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82207
82208 /*
82209 * Internals. Dont't use..
82210 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82211 index a67b384..f52a537 100644
82212 --- a/include/linux/vmstat.h
82213 +++ b/include/linux/vmstat.h
82214 @@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
82215 /*
82216 * Zone based page accounting with per cpu differentials.
82217 */
82218 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82219 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82220
82221 static inline void zone_page_state_add(long x, struct zone *zone,
82222 enum zone_stat_item item)
82223 {
82224 - atomic_long_add(x, &zone->vm_stat[item]);
82225 - atomic_long_add(x, &vm_stat[item]);
82226 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82227 + atomic_long_add_unchecked(x, &vm_stat[item]);
82228 }
82229
82230 -static inline unsigned long global_page_state(enum zone_stat_item item)
82231 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82232 {
82233 - long x = atomic_long_read(&vm_stat[item]);
82234 + long x = atomic_long_read_unchecked(&vm_stat[item]);
82235 #ifdef CONFIG_SMP
82236 if (x < 0)
82237 x = 0;
82238 @@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82239 return x;
82240 }
82241
82242 -static inline unsigned long zone_page_state(struct zone *zone,
82243 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82244 enum zone_stat_item item)
82245 {
82246 - long x = atomic_long_read(&zone->vm_stat[item]);
82247 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82248 #ifdef CONFIG_SMP
82249 if (x < 0)
82250 x = 0;
82251 @@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82252 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82253 enum zone_stat_item item)
82254 {
82255 - long x = atomic_long_read(&zone->vm_stat[item]);
82256 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82257
82258 #ifdef CONFIG_SMP
82259 int cpu;
82260 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82261
82262 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82263 {
82264 - atomic_long_inc(&zone->vm_stat[item]);
82265 - atomic_long_inc(&vm_stat[item]);
82266 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
82267 + atomic_long_inc_unchecked(&vm_stat[item]);
82268 }
82269
82270 static inline void __inc_zone_page_state(struct page *page,
82271 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
82272
82273 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82274 {
82275 - atomic_long_dec(&zone->vm_stat[item]);
82276 - atomic_long_dec(&vm_stat[item]);
82277 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
82278 + atomic_long_dec_unchecked(&vm_stat[item]);
82279 }
82280
82281 static inline void __dec_zone_page_state(struct page *page,
82282 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82283 index 91b0a68..0e9adf6 100644
82284 --- a/include/linux/xattr.h
82285 +++ b/include/linux/xattr.h
82286 @@ -28,7 +28,7 @@ struct xattr_handler {
82287 size_t size, int handler_flags);
82288 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82289 size_t size, int flags, int handler_flags);
82290 -};
82291 +} __do_const;
82292
82293 struct xattr {
82294 const char *name;
82295 @@ -37,6 +37,9 @@ struct xattr {
82296 };
82297
82298 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82299 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82300 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
82301 +#endif
82302 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82303 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82304 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82305 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82306 index 9c5a6b4..09c9438 100644
82307 --- a/include/linux/zlib.h
82308 +++ b/include/linux/zlib.h
82309 @@ -31,6 +31,7 @@
82310 #define _ZLIB_H
82311
82312 #include <linux/zconf.h>
82313 +#include <linux/compiler.h>
82314
82315 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82316 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82317 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82318
82319 /* basic functions */
82320
82321 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82322 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82323 /*
82324 Returns the number of bytes that needs to be allocated for a per-
82325 stream workspace with the specified parameters. A pointer to this
82326 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82327 index c768c9f..bdcaa5a 100644
82328 --- a/include/media/v4l2-dev.h
82329 +++ b/include/media/v4l2-dev.h
82330 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
82331 int (*mmap) (struct file *, struct vm_area_struct *);
82332 int (*open) (struct file *);
82333 int (*release) (struct file *);
82334 -};
82335 +} __do_const;
82336
82337 /*
82338 * Newer version of video_device, handled by videodev2.c
82339 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82340 index c9b1593..a572459 100644
82341 --- a/include/media/v4l2-device.h
82342 +++ b/include/media/v4l2-device.h
82343 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82344 this function returns 0. If the name ends with a digit (e.g. cx18),
82345 then the name will be set to cx18-0 since cx180 looks really odd. */
82346 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82347 - atomic_t *instance);
82348 + atomic_unchecked_t *instance);
82349
82350 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82351 Since the parent disappears this ensures that v4l2_dev doesn't have an
82352 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82353 index 9a36d92..0aafe2a 100644
82354 --- a/include/net/9p/transport.h
82355 +++ b/include/net/9p/transport.h
82356 @@ -60,7 +60,7 @@ struct p9_trans_module {
82357 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82358 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82359 char *, char *, int , int, int, int);
82360 -};
82361 +} __do_const;
82362
82363 void v9fs_register_trans(struct p9_trans_module *m);
82364 void v9fs_unregister_trans(struct p9_trans_module *m);
82365 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82366 index c853b16d..37fccb7 100644
82367 --- a/include/net/bluetooth/l2cap.h
82368 +++ b/include/net/bluetooth/l2cap.h
82369 @@ -557,7 +557,7 @@ struct l2cap_ops {
82370 long (*get_sndtimeo) (struct l2cap_chan *chan);
82371 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82372 unsigned long len, int nb);
82373 -};
82374 +} __do_const;
82375
82376 struct l2cap_conn {
82377 struct hci_conn *hcon;
82378 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82379 index f2ae33d..c457cf0 100644
82380 --- a/include/net/caif/cfctrl.h
82381 +++ b/include/net/caif/cfctrl.h
82382 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
82383 void (*radioset_rsp)(void);
82384 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82385 struct cflayer *client_layer);
82386 -};
82387 +} __no_const;
82388
82389 /* Link Setup Parameters for CAIF-Links. */
82390 struct cfctrl_link_param {
82391 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
82392 struct cfctrl {
82393 struct cfsrvl serv;
82394 struct cfctrl_rsp res;
82395 - atomic_t req_seq_no;
82396 - atomic_t rsp_seq_no;
82397 + atomic_unchecked_t req_seq_no;
82398 + atomic_unchecked_t rsp_seq_no;
82399 struct list_head list;
82400 /* Protects from simultaneous access to first_req list */
82401 spinlock_t info_list_lock;
82402 diff --git a/include/net/flow.h b/include/net/flow.h
82403 index 65ce471..b7bbe9b 100644
82404 --- a/include/net/flow.h
82405 +++ b/include/net/flow.h
82406 @@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82407
82408 void flow_cache_flush(void);
82409 void flow_cache_flush_deferred(void);
82410 -extern atomic_t flow_cache_genid;
82411 +extern atomic_unchecked_t flow_cache_genid;
82412
82413 #endif
82414 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82415 index 1b177ed..a24a138 100644
82416 --- a/include/net/genetlink.h
82417 +++ b/include/net/genetlink.h
82418 @@ -118,7 +118,7 @@ struct genl_ops {
82419 u8 cmd;
82420 u8 internal_flags;
82421 u8 flags;
82422 -};
82423 +} __do_const;
82424
82425 int __genl_register_family(struct genl_family *family);
82426
82427 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82428 index 734d9b5..48a9a4b 100644
82429 --- a/include/net/gro_cells.h
82430 +++ b/include/net/gro_cells.h
82431 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82432 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82433
82434 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82435 - atomic_long_inc(&dev->rx_dropped);
82436 + atomic_long_inc_unchecked(&dev->rx_dropped);
82437 kfree_skb(skb);
82438 return;
82439 }
82440 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82441 index c55aeed..b3393f4 100644
82442 --- a/include/net/inet_connection_sock.h
82443 +++ b/include/net/inet_connection_sock.h
82444 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82445 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82446 int (*bind_conflict)(const struct sock *sk,
82447 const struct inet_bind_bucket *tb, bool relax);
82448 -};
82449 +} __do_const;
82450
82451 /** inet_connection_sock - INET connection oriented sock
82452 *
82453 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82454 index f4e127a..c3d5e9c 100644
82455 --- a/include/net/inetpeer.h
82456 +++ b/include/net/inetpeer.h
82457 @@ -47,8 +47,8 @@ struct inet_peer {
82458 */
82459 union {
82460 struct {
82461 - atomic_t rid; /* Frag reception counter */
82462 - atomic_t ip_id_count; /* IP ID for the next packet */
82463 + atomic_unchecked_t rid; /* Frag reception counter */
82464 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
82465 };
82466 struct rcu_head rcu;
82467 struct inet_peer *gc_next;
82468 @@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
82469 /* can be called with or without local BH being disabled */
82470 static inline int inet_getid(struct inet_peer *p, int more)
82471 {
82472 - int old, new;
82473 + int id;
82474 more++;
82475 inet_peer_refcheck(p);
82476 - do {
82477 - old = atomic_read(&p->ip_id_count);
82478 - new = old + more;
82479 - if (!new)
82480 - new = 1;
82481 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
82482 - return new;
82483 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
82484 + if (!id)
82485 + id = atomic_inc_return_unchecked(&p->ip_id_count);
82486 + return id;
82487 }
82488
82489 #endif /* _NET_INETPEER_H */
82490 diff --git a/include/net/ip.h b/include/net/ip.h
82491 index 5a25f36..2e73203 100644
82492 --- a/include/net/ip.h
82493 +++ b/include/net/ip.h
82494 @@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
82495
82496 void inet_get_local_port_range(struct net *net, int *low, int *high);
82497
82498 -extern unsigned long *sysctl_local_reserved_ports;
82499 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
82500 static inline int inet_is_reserved_local_port(int port)
82501 {
82502 return test_bit(port, sysctl_local_reserved_ports);
82503 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
82504 index 9922093..a1755d6 100644
82505 --- a/include/net/ip_fib.h
82506 +++ b/include/net/ip_fib.h
82507 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
82508
82509 #define FIB_RES_SADDR(net, res) \
82510 ((FIB_RES_NH(res).nh_saddr_genid == \
82511 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
82512 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
82513 FIB_RES_NH(res).nh_saddr : \
82514 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
82515 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
82516 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
82517 index 5679d92..2e7a690 100644
82518 --- a/include/net/ip_vs.h
82519 +++ b/include/net/ip_vs.h
82520 @@ -558,7 +558,7 @@ struct ip_vs_conn {
82521 struct ip_vs_conn *control; /* Master control connection */
82522 atomic_t n_control; /* Number of controlled ones */
82523 struct ip_vs_dest *dest; /* real server */
82524 - atomic_t in_pkts; /* incoming packet counter */
82525 + atomic_unchecked_t in_pkts; /* incoming packet counter */
82526
82527 /* packet transmitter for different forwarding methods. If it
82528 mangles the packet, it must return NF_DROP or better NF_STOLEN,
82529 @@ -705,7 +705,7 @@ struct ip_vs_dest {
82530 __be16 port; /* port number of the server */
82531 union nf_inet_addr addr; /* IP address of the server */
82532 volatile unsigned int flags; /* dest status flags */
82533 - atomic_t conn_flags; /* flags to copy to conn */
82534 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
82535 atomic_t weight; /* server weight */
82536
82537 atomic_t refcnt; /* reference counter */
82538 @@ -960,11 +960,11 @@ struct netns_ipvs {
82539 /* ip_vs_lblc */
82540 int sysctl_lblc_expiration;
82541 struct ctl_table_header *lblc_ctl_header;
82542 - struct ctl_table *lblc_ctl_table;
82543 + ctl_table_no_const *lblc_ctl_table;
82544 /* ip_vs_lblcr */
82545 int sysctl_lblcr_expiration;
82546 struct ctl_table_header *lblcr_ctl_header;
82547 - struct ctl_table *lblcr_ctl_table;
82548 + ctl_table_no_const *lblcr_ctl_table;
82549 /* ip_vs_est */
82550 struct list_head est_list; /* estimator list */
82551 spinlock_t est_lock;
82552 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
82553 index 0224402..dafaf94a 100644
82554 --- a/include/net/irda/ircomm_tty.h
82555 +++ b/include/net/irda/ircomm_tty.h
82556 @@ -35,6 +35,7 @@
82557 #include <linux/termios.h>
82558 #include <linux/timer.h>
82559 #include <linux/tty.h> /* struct tty_struct */
82560 +#include <asm/local.h>
82561
82562 #include <net/irda/irias_object.h>
82563 #include <net/irda/ircomm_core.h>
82564 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
82565 index 714cc9a..ea05f3e 100644
82566 --- a/include/net/iucv/af_iucv.h
82567 +++ b/include/net/iucv/af_iucv.h
82568 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
82569 struct iucv_sock_list {
82570 struct hlist_head head;
82571 rwlock_t lock;
82572 - atomic_t autobind_name;
82573 + atomic_unchecked_t autobind_name;
82574 };
82575
82576 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
82577 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
82578 index f3be818..bf46196 100644
82579 --- a/include/net/llc_c_ac.h
82580 +++ b/include/net/llc_c_ac.h
82581 @@ -87,7 +87,7 @@
82582 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
82583 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
82584
82585 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82586 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82587
82588 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
82589 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
82590 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
82591 index 3948cf1..83b28c4 100644
82592 --- a/include/net/llc_c_ev.h
82593 +++ b/include/net/llc_c_ev.h
82594 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
82595 return (struct llc_conn_state_ev *)skb->cb;
82596 }
82597
82598 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82599 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82600 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82601 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82602
82603 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
82604 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
82605 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
82606 index 0e79cfb..f46db31 100644
82607 --- a/include/net/llc_c_st.h
82608 +++ b/include/net/llc_c_st.h
82609 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
82610 u8 next_state;
82611 llc_conn_ev_qfyr_t *ev_qualifiers;
82612 llc_conn_action_t *ev_actions;
82613 -};
82614 +} __do_const;
82615
82616 struct llc_conn_state {
82617 u8 current_state;
82618 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
82619 index a61b98c..aade1eb 100644
82620 --- a/include/net/llc_s_ac.h
82621 +++ b/include/net/llc_s_ac.h
82622 @@ -23,7 +23,7 @@
82623 #define SAP_ACT_TEST_IND 9
82624
82625 /* All action functions must look like this */
82626 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82627 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82628
82629 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
82630 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
82631 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
82632 index 567c681..cd73ac0 100644
82633 --- a/include/net/llc_s_st.h
82634 +++ b/include/net/llc_s_st.h
82635 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
82636 llc_sap_ev_t ev;
82637 u8 next_state;
82638 llc_sap_action_t *ev_actions;
82639 -};
82640 +} __do_const;
82641
82642 struct llc_sap_state {
82643 u8 curr_state;
82644 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
82645 index 7ceed99..d3ffaa2 100644
82646 --- a/include/net/mac80211.h
82647 +++ b/include/net/mac80211.h
82648 @@ -4407,7 +4407,7 @@ struct rate_control_ops {
82649 void (*add_sta_debugfs)(void *priv, void *priv_sta,
82650 struct dentry *dir);
82651 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
82652 -};
82653 +} __do_const;
82654
82655 static inline int rate_supported(struct ieee80211_sta *sta,
82656 enum ieee80211_band band,
82657 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
82658 index 536501a..47b7982 100644
82659 --- a/include/net/neighbour.h
82660 +++ b/include/net/neighbour.h
82661 @@ -123,7 +123,7 @@ struct neigh_ops {
82662 void (*error_report)(struct neighbour *, struct sk_buff *);
82663 int (*output)(struct neighbour *, struct sk_buff *);
82664 int (*connected_output)(struct neighbour *, struct sk_buff *);
82665 -};
82666 +} __do_const;
82667
82668 struct pneigh_entry {
82669 struct pneigh_entry *next;
82670 @@ -163,7 +163,6 @@ struct neigh_table {
82671 void (*proxy_redo)(struct sk_buff *skb);
82672 char *id;
82673 struct neigh_parms parms;
82674 - /* HACK. gc_* should follow parms without a gap! */
82675 int gc_interval;
82676 int gc_thresh1;
82677 int gc_thresh2;
82678 @@ -178,7 +177,7 @@ struct neigh_table {
82679 struct neigh_statistics __percpu *stats;
82680 struct neigh_hash_table __rcu *nht;
82681 struct pneigh_entry **phash_buckets;
82682 -};
82683 +} __randomize_layout;
82684
82685 #define NEIGH_PRIV_ALIGN sizeof(long long)
82686 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
82687 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
82688 index da68c9a..c4a0720 100644
82689 --- a/include/net/net_namespace.h
82690 +++ b/include/net/net_namespace.h
82691 @@ -124,8 +124,8 @@ struct net {
82692 struct netns_ipvs *ipvs;
82693 #endif
82694 struct sock *diag_nlsk;
82695 - atomic_t fnhe_genid;
82696 -};
82697 + atomic_unchecked_t fnhe_genid;
82698 +} __randomize_layout;
82699
82700 /*
82701 * ifindex generation is per-net namespace, and loopback is
82702 @@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
82703 #define __net_init __init
82704 #define __net_exit __exit_refok
82705 #define __net_initdata __initdata
82706 +#ifdef CONSTIFY_PLUGIN
82707 #define __net_initconst __initconst
82708 +#else
82709 +#define __net_initconst __initdata
82710 +#endif
82711 #endif
82712
82713 struct pernet_operations {
82714 @@ -291,7 +295,7 @@ struct pernet_operations {
82715 void (*exit_batch)(struct list_head *net_exit_list);
82716 int *id;
82717 size_t size;
82718 -};
82719 +} __do_const;
82720
82721 /*
82722 * Use these carefully. If you implement a network device and it
82723 @@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
82724
82725 static inline int rt_genid_ipv4(struct net *net)
82726 {
82727 - return atomic_read(&net->ipv4.rt_genid);
82728 + return atomic_read_unchecked(&net->ipv4.rt_genid);
82729 }
82730
82731 static inline void rt_genid_bump_ipv4(struct net *net)
82732 {
82733 - atomic_inc(&net->ipv4.rt_genid);
82734 + atomic_inc_unchecked(&net->ipv4.rt_genid);
82735 }
82736
82737 #if IS_ENABLED(CONFIG_IPV6)
82738 static inline int rt_genid_ipv6(struct net *net)
82739 {
82740 - return atomic_read(&net->ipv6.rt_genid);
82741 + return atomic_read_unchecked(&net->ipv6.rt_genid);
82742 }
82743
82744 static inline void rt_genid_bump_ipv6(struct net *net)
82745 {
82746 - atomic_inc(&net->ipv6.rt_genid);
82747 + atomic_inc_unchecked(&net->ipv6.rt_genid);
82748 }
82749 #else
82750 static inline int rt_genid_ipv6(struct net *net)
82751 @@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
82752
82753 static inline int fnhe_genid(struct net *net)
82754 {
82755 - return atomic_read(&net->fnhe_genid);
82756 + return atomic_read_unchecked(&net->fnhe_genid);
82757 }
82758
82759 static inline void fnhe_genid_bump(struct net *net)
82760 {
82761 - atomic_inc(&net->fnhe_genid);
82762 + atomic_inc_unchecked(&net->fnhe_genid);
82763 }
82764
82765 #endif /* __NET_NET_NAMESPACE_H */
82766 diff --git a/include/net/netdma.h b/include/net/netdma.h
82767 index 8ba8ce2..99b7fff 100644
82768 --- a/include/net/netdma.h
82769 +++ b/include/net/netdma.h
82770 @@ -24,7 +24,7 @@
82771 #include <linux/dmaengine.h>
82772 #include <linux/skbuff.h>
82773
82774 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82775 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82776 struct sk_buff *skb, int offset, struct iovec *to,
82777 size_t len, struct dma_pinned_list *pinned_list);
82778
82779 diff --git a/include/net/netlink.h b/include/net/netlink.h
82780 index 2b47eaa..6d5bcc2 100644
82781 --- a/include/net/netlink.h
82782 +++ b/include/net/netlink.h
82783 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
82784 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
82785 {
82786 if (mark)
82787 - skb_trim(skb, (unsigned char *) mark - skb->data);
82788 + skb_trim(skb, (const unsigned char *) mark - skb->data);
82789 }
82790
82791 /**
82792 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
82793 index c9c0c53..53f24c3 100644
82794 --- a/include/net/netns/conntrack.h
82795 +++ b/include/net/netns/conntrack.h
82796 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
82797 struct nf_proto_net {
82798 #ifdef CONFIG_SYSCTL
82799 struct ctl_table_header *ctl_table_header;
82800 - struct ctl_table *ctl_table;
82801 + ctl_table_no_const *ctl_table;
82802 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
82803 struct ctl_table_header *ctl_compat_header;
82804 - struct ctl_table *ctl_compat_table;
82805 + ctl_table_no_const *ctl_compat_table;
82806 #endif
82807 #endif
82808 unsigned int users;
82809 @@ -58,7 +58,7 @@ struct nf_ip_net {
82810 struct nf_icmp_net icmpv6;
82811 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
82812 struct ctl_table_header *ctl_table_header;
82813 - struct ctl_table *ctl_table;
82814 + ctl_table_no_const *ctl_table;
82815 #endif
82816 };
82817
82818 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
82819 index ee520cb..9a0fd88 100644
82820 --- a/include/net/netns/ipv4.h
82821 +++ b/include/net/netns/ipv4.h
82822 @@ -72,7 +72,7 @@ struct netns_ipv4 {
82823
82824 kgid_t sysctl_ping_group_range[2];
82825
82826 - atomic_t dev_addr_genid;
82827 + atomic_unchecked_t dev_addr_genid;
82828
82829 #ifdef CONFIG_IP_MROUTE
82830 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
82831 @@ -82,6 +82,6 @@ struct netns_ipv4 {
82832 struct fib_rules_ops *mr_rules_ops;
82833 #endif
82834 #endif
82835 - atomic_t rt_genid;
82836 + atomic_unchecked_t rt_genid;
82837 };
82838 #endif
82839 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
82840 index 0fb2401..477d81c 100644
82841 --- a/include/net/netns/ipv6.h
82842 +++ b/include/net/netns/ipv6.h
82843 @@ -71,8 +71,8 @@ struct netns_ipv6 {
82844 struct fib_rules_ops *mr6_rules_ops;
82845 #endif
82846 #endif
82847 - atomic_t dev_addr_genid;
82848 - atomic_t rt_genid;
82849 + atomic_unchecked_t dev_addr_genid;
82850 + atomic_unchecked_t rt_genid;
82851 };
82852
82853 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
82854 diff --git a/include/net/ping.h b/include/net/ping.h
82855 index 90f4841..74446a8 100644
82856 --- a/include/net/ping.h
82857 +++ b/include/net/ping.h
82858 @@ -56,7 +56,7 @@ struct ping_iter_state {
82859 extern struct proto ping_prot;
82860 extern struct ping_table ping_table;
82861 #if IS_ENABLED(CONFIG_IPV6)
82862 -extern struct pingv6_ops pingv6_ops;
82863 +extern struct pingv6_ops *pingv6_ops;
82864 #endif
82865
82866 struct pingfakehdr {
82867 diff --git a/include/net/protocol.h b/include/net/protocol.h
82868 index fbf7676..a5e21c3 100644
82869 --- a/include/net/protocol.h
82870 +++ b/include/net/protocol.h
82871 @@ -44,7 +44,7 @@ struct net_protocol {
82872 void (*err_handler)(struct sk_buff *skb, u32 info);
82873 unsigned int no_policy:1,
82874 netns_ok:1;
82875 -};
82876 +} __do_const;
82877
82878 #if IS_ENABLED(CONFIG_IPV6)
82879 struct inet6_protocol {
82880 @@ -57,7 +57,7 @@ struct inet6_protocol {
82881 u8 type, u8 code, int offset,
82882 __be32 info);
82883 unsigned int flags; /* INET6_PROTO_xxx */
82884 -};
82885 +} __do_const;
82886
82887 #define INET6_PROTO_NOPOLICY 0x1
82888 #define INET6_PROTO_FINAL 0x2
82889 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
82890 index bb13a18..e734116 100644
82891 --- a/include/net/rtnetlink.h
82892 +++ b/include/net/rtnetlink.h
82893 @@ -79,7 +79,7 @@ struct rtnl_link_ops {
82894 const struct net_device *dev);
82895 unsigned int (*get_num_tx_queues)(void);
82896 unsigned int (*get_num_rx_queues)(void);
82897 -};
82898 +} __do_const;
82899
82900 int __rtnl_link_register(struct rtnl_link_ops *ops);
82901 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
82902 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
82903 index 6bd44fe..96f364e 100644
82904 --- a/include/net/sctp/checksum.h
82905 +++ b/include/net/sctp/checksum.h
82906 @@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
82907 unsigned int offset)
82908 {
82909 struct sctphdr *sh = sctp_hdr(skb);
82910 - __le32 ret, old = sh->checksum;
82911 - const struct skb_checksum_ops ops = {
82912 + __le32 ret, old = sh->checksum;
82913 + static const struct skb_checksum_ops ops = {
82914 .update = sctp_csum_update,
82915 .combine = sctp_csum_combine,
82916 };
82917 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
82918 index 4ef75af..5aa073a 100644
82919 --- a/include/net/sctp/sm.h
82920 +++ b/include/net/sctp/sm.h
82921 @@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
82922 typedef struct {
82923 sctp_state_fn_t *fn;
82924 const char *name;
82925 -} sctp_sm_table_entry_t;
82926 +} __do_const sctp_sm_table_entry_t;
82927
82928 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
82929 * currently in use.
82930 @@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
82931 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
82932
82933 /* Extern declarations for major data structures. */
82934 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82935 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82936
82937
82938 /* Get the size of a DATA chunk payload. */
82939 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
82940 index 0a248b3..4dcbe5c 100644
82941 --- a/include/net/sctp/structs.h
82942 +++ b/include/net/sctp/structs.h
82943 @@ -508,7 +508,7 @@ struct sctp_pf {
82944 struct sctp_association *asoc);
82945 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
82946 struct sctp_af *af;
82947 -};
82948 +} __do_const;
82949
82950
82951 /* Structure to track chunk fragments that have been acked, but peer
82952 diff --git a/include/net/sock.h b/include/net/sock.h
82953 index 2ef3c3e..e02013e 100644
82954 --- a/include/net/sock.h
82955 +++ b/include/net/sock.h
82956 @@ -348,7 +348,7 @@ struct sock {
82957 unsigned int sk_napi_id;
82958 unsigned int sk_ll_usec;
82959 #endif
82960 - atomic_t sk_drops;
82961 + atomic_unchecked_t sk_drops;
82962 int sk_rcvbuf;
82963
82964 struct sk_filter __rcu *sk_filter;
82965 @@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
82966 return ret >> PAGE_SHIFT;
82967 }
82968
82969 -static inline long
82970 +static inline long __intentional_overflow(-1)
82971 sk_memory_allocated(const struct sock *sk)
82972 {
82973 struct proto *prot = sk->sk_prot;
82974 @@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
82975 }
82976
82977 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
82978 - char __user *from, char *to,
82979 + char __user *from, unsigned char *to,
82980 int copy, int offset)
82981 {
82982 if (skb->ip_summed == CHECKSUM_NONE) {
82983 @@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
82984 }
82985 }
82986
82987 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82988 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82989
82990 /**
82991 * sk_page_frag - return an appropriate page_frag
82992 diff --git a/include/net/tcp.h b/include/net/tcp.h
82993 index 70e55d2..c5d8d53 100644
82994 --- a/include/net/tcp.h
82995 +++ b/include/net/tcp.h
82996 @@ -540,7 +540,7 @@ void tcp_retransmit_timer(struct sock *sk);
82997 void tcp_xmit_retransmit_queue(struct sock *);
82998 void tcp_simple_retransmit(struct sock *);
82999 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83000 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83001 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83002
83003 void tcp_send_probe0(struct sock *);
83004 void tcp_send_partial(struct sock *);
83005 @@ -711,8 +711,8 @@ struct tcp_skb_cb {
83006 struct inet6_skb_parm h6;
83007 #endif
83008 } header; /* For incoming frames */
83009 - __u32 seq; /* Starting sequence number */
83010 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83011 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
83012 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83013 __u32 when; /* used to compute rtt's */
83014 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83015
83016 @@ -726,7 +726,7 @@ struct tcp_skb_cb {
83017
83018 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83019 /* 1 byte hole */
83020 - __u32 ack_seq; /* Sequence number ACK'd */
83021 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83022 };
83023
83024 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83025 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83026 index 6b82fdf..14d74d2 100644
83027 --- a/include/net/xfrm.h
83028 +++ b/include/net/xfrm.h
83029 @@ -287,7 +287,6 @@ struct xfrm_dst;
83030 struct xfrm_policy_afinfo {
83031 unsigned short family;
83032 struct dst_ops *dst_ops;
83033 - void (*garbage_collect)(struct net *net);
83034 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83035 const xfrm_address_t *saddr,
83036 const xfrm_address_t *daddr);
83037 @@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
83038 struct net_device *dev,
83039 const struct flowi *fl);
83040 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83041 -};
83042 +} __do_const;
83043
83044 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83045 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83046 @@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
83047 int (*transport_finish)(struct sk_buff *skb,
83048 int async);
83049 void (*local_error)(struct sk_buff *skb, u32 mtu);
83050 -};
83051 +} __do_const;
83052
83053 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83054 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83055 @@ -429,7 +428,7 @@ struct xfrm_mode {
83056 struct module *owner;
83057 unsigned int encap;
83058 int flags;
83059 -};
83060 +} __do_const;
83061
83062 /* Flags for xfrm_mode. */
83063 enum {
83064 @@ -526,7 +525,7 @@ struct xfrm_policy {
83065 struct timer_list timer;
83066
83067 struct flow_cache_object flo;
83068 - atomic_t genid;
83069 + atomic_unchecked_t genid;
83070 u32 priority;
83071 u32 index;
83072 struct xfrm_mark mark;
83073 @@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83074 }
83075
83076 void xfrm_garbage_collect(struct net *net);
83077 +void xfrm_garbage_collect_deferred(struct net *net);
83078
83079 #else
83080
83081 @@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83082 static inline void xfrm_garbage_collect(struct net *net)
83083 {
83084 }
83085 +static inline void xfrm_garbage_collect_deferred(struct net *net)
83086 +{
83087 +}
83088 #endif
83089
83090 static __inline__
83091 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83092 index 1017e0b..227aa4d 100644
83093 --- a/include/rdma/iw_cm.h
83094 +++ b/include/rdma/iw_cm.h
83095 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
83096 int backlog);
83097
83098 int (*destroy_listen)(struct iw_cm_id *cm_id);
83099 -};
83100 +} __no_const;
83101
83102 /**
83103 * iw_create_cm_id - Create an IW CM identifier.
83104 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83105 index 52beadf..598734c 100644
83106 --- a/include/scsi/libfc.h
83107 +++ b/include/scsi/libfc.h
83108 @@ -771,6 +771,7 @@ struct libfc_function_template {
83109 */
83110 void (*disc_stop_final) (struct fc_lport *);
83111 };
83112 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83113
83114 /**
83115 * struct fc_disc - Discovery context
83116 @@ -875,7 +876,7 @@ struct fc_lport {
83117 struct fc_vport *vport;
83118
83119 /* Operational Information */
83120 - struct libfc_function_template tt;
83121 + libfc_function_template_no_const tt;
83122 u8 link_up;
83123 u8 qfull;
83124 enum fc_lport_state state;
83125 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83126 index d65fbec..f80fef2 100644
83127 --- a/include/scsi/scsi_device.h
83128 +++ b/include/scsi/scsi_device.h
83129 @@ -180,9 +180,9 @@ struct scsi_device {
83130 unsigned int max_device_blocked; /* what device_blocked counts down from */
83131 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83132
83133 - atomic_t iorequest_cnt;
83134 - atomic_t iodone_cnt;
83135 - atomic_t ioerr_cnt;
83136 + atomic_unchecked_t iorequest_cnt;
83137 + atomic_unchecked_t iodone_cnt;
83138 + atomic_unchecked_t ioerr_cnt;
83139
83140 struct device sdev_gendev,
83141 sdev_dev;
83142 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83143 index b797e8f..8e2c3aa 100644
83144 --- a/include/scsi/scsi_transport_fc.h
83145 +++ b/include/scsi/scsi_transport_fc.h
83146 @@ -751,7 +751,8 @@ struct fc_function_template {
83147 unsigned long show_host_system_hostname:1;
83148
83149 unsigned long disable_target_scan:1;
83150 -};
83151 +} __do_const;
83152 +typedef struct fc_function_template __no_const fc_function_template_no_const;
83153
83154
83155 /**
83156 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83157 index ae6c3b8..fd748ac 100644
83158 --- a/include/sound/compress_driver.h
83159 +++ b/include/sound/compress_driver.h
83160 @@ -128,7 +128,7 @@ struct snd_compr_ops {
83161 struct snd_compr_caps *caps);
83162 int (*get_codec_caps) (struct snd_compr_stream *stream,
83163 struct snd_compr_codec_caps *codec);
83164 -};
83165 +} __no_const;
83166
83167 /**
83168 * struct snd_compr: Compressed device
83169 diff --git a/include/sound/soc.h b/include/sound/soc.h
83170 index 1f741cb..8cefc08 100644
83171 --- a/include/sound/soc.h
83172 +++ b/include/sound/soc.h
83173 @@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
83174 /* probe ordering - for components with runtime dependencies */
83175 int probe_order;
83176 int remove_order;
83177 -};
83178 +} __do_const;
83179
83180 /* SoC platform interface */
83181 struct snd_soc_platform_driver {
83182 @@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
83183 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83184 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83185 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83186 -};
83187 +} __do_const;
83188
83189 struct snd_soc_platform {
83190 const char *name;
83191 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83192 index e3569f8..6544ffd 100644
83193 --- a/include/target/target_core_base.h
83194 +++ b/include/target/target_core_base.h
83195 @@ -687,7 +687,7 @@ struct se_device {
83196 atomic_long_t write_bytes;
83197 /* Active commands on this virtual SE device */
83198 atomic_t simple_cmds;
83199 - atomic_t dev_ordered_id;
83200 + atomic_unchecked_t dev_ordered_id;
83201 atomic_t dev_ordered_sync;
83202 atomic_t dev_qf_count;
83203 int export_count;
83204 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83205 new file mode 100644
83206 index 0000000..fb634b7
83207 --- /dev/null
83208 +++ b/include/trace/events/fs.h
83209 @@ -0,0 +1,53 @@
83210 +#undef TRACE_SYSTEM
83211 +#define TRACE_SYSTEM fs
83212 +
83213 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83214 +#define _TRACE_FS_H
83215 +
83216 +#include <linux/fs.h>
83217 +#include <linux/tracepoint.h>
83218 +
83219 +TRACE_EVENT(do_sys_open,
83220 +
83221 + TP_PROTO(const char *filename, int flags, int mode),
83222 +
83223 + TP_ARGS(filename, flags, mode),
83224 +
83225 + TP_STRUCT__entry(
83226 + __string( filename, filename )
83227 + __field( int, flags )
83228 + __field( int, mode )
83229 + ),
83230 +
83231 + TP_fast_assign(
83232 + __assign_str(filename, filename);
83233 + __entry->flags = flags;
83234 + __entry->mode = mode;
83235 + ),
83236 +
83237 + TP_printk("\"%s\" %x %o",
83238 + __get_str(filename), __entry->flags, __entry->mode)
83239 +);
83240 +
83241 +TRACE_EVENT(open_exec,
83242 +
83243 + TP_PROTO(const char *filename),
83244 +
83245 + TP_ARGS(filename),
83246 +
83247 + TP_STRUCT__entry(
83248 + __string( filename, filename )
83249 + ),
83250 +
83251 + TP_fast_assign(
83252 + __assign_str(filename, filename);
83253 + ),
83254 +
83255 + TP_printk("\"%s\"",
83256 + __get_str(filename))
83257 +);
83258 +
83259 +#endif /* _TRACE_FS_H */
83260 +
83261 +/* This part must be outside protection */
83262 +#include <trace/define_trace.h>
83263 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83264 index 1c09820..7f5ec79 100644
83265 --- a/include/trace/events/irq.h
83266 +++ b/include/trace/events/irq.h
83267 @@ -36,7 +36,7 @@ struct softirq_action;
83268 */
83269 TRACE_EVENT(irq_handler_entry,
83270
83271 - TP_PROTO(int irq, struct irqaction *action),
83272 + TP_PROTO(int irq, const struct irqaction *action),
83273
83274 TP_ARGS(irq, action),
83275
83276 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83277 */
83278 TRACE_EVENT(irq_handler_exit,
83279
83280 - TP_PROTO(int irq, struct irqaction *action, int ret),
83281 + TP_PROTO(int irq, const struct irqaction *action, int ret),
83282
83283 TP_ARGS(irq, action, ret),
83284
83285 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83286 index 7caf44c..23c6f27 100644
83287 --- a/include/uapi/linux/a.out.h
83288 +++ b/include/uapi/linux/a.out.h
83289 @@ -39,6 +39,14 @@ enum machine_type {
83290 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83291 };
83292
83293 +/* Constants for the N_FLAGS field */
83294 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83295 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83296 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83297 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83298 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83299 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83300 +
83301 #if !defined (N_MAGIC)
83302 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83303 #endif
83304 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83305 index d876736..ccce5c0 100644
83306 --- a/include/uapi/linux/byteorder/little_endian.h
83307 +++ b/include/uapi/linux/byteorder/little_endian.h
83308 @@ -42,51 +42,51 @@
83309
83310 static inline __le64 __cpu_to_le64p(const __u64 *p)
83311 {
83312 - return (__force __le64)*p;
83313 + return (__force const __le64)*p;
83314 }
83315 -static inline __u64 __le64_to_cpup(const __le64 *p)
83316 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83317 {
83318 - return (__force __u64)*p;
83319 + return (__force const __u64)*p;
83320 }
83321 static inline __le32 __cpu_to_le32p(const __u32 *p)
83322 {
83323 - return (__force __le32)*p;
83324 + return (__force const __le32)*p;
83325 }
83326 static inline __u32 __le32_to_cpup(const __le32 *p)
83327 {
83328 - return (__force __u32)*p;
83329 + return (__force const __u32)*p;
83330 }
83331 static inline __le16 __cpu_to_le16p(const __u16 *p)
83332 {
83333 - return (__force __le16)*p;
83334 + return (__force const __le16)*p;
83335 }
83336 static inline __u16 __le16_to_cpup(const __le16 *p)
83337 {
83338 - return (__force __u16)*p;
83339 + return (__force const __u16)*p;
83340 }
83341 static inline __be64 __cpu_to_be64p(const __u64 *p)
83342 {
83343 - return (__force __be64)__swab64p(p);
83344 + return (__force const __be64)__swab64p(p);
83345 }
83346 static inline __u64 __be64_to_cpup(const __be64 *p)
83347 {
83348 - return __swab64p((__u64 *)p);
83349 + return __swab64p((const __u64 *)p);
83350 }
83351 static inline __be32 __cpu_to_be32p(const __u32 *p)
83352 {
83353 - return (__force __be32)__swab32p(p);
83354 + return (__force const __be32)__swab32p(p);
83355 }
83356 -static inline __u32 __be32_to_cpup(const __be32 *p)
83357 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83358 {
83359 - return __swab32p((__u32 *)p);
83360 + return __swab32p((const __u32 *)p);
83361 }
83362 static inline __be16 __cpu_to_be16p(const __u16 *p)
83363 {
83364 - return (__force __be16)__swab16p(p);
83365 + return (__force const __be16)__swab16p(p);
83366 }
83367 static inline __u16 __be16_to_cpup(const __be16 *p)
83368 {
83369 - return __swab16p((__u16 *)p);
83370 + return __swab16p((const __u16 *)p);
83371 }
83372 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83373 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83374 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83375 index ef6103b..d4e65dd 100644
83376 --- a/include/uapi/linux/elf.h
83377 +++ b/include/uapi/linux/elf.h
83378 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83379 #define PT_GNU_EH_FRAME 0x6474e550
83380
83381 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83382 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83383 +
83384 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83385 +
83386 +/* Constants for the e_flags field */
83387 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83388 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83389 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83390 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83391 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83392 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83393
83394 /*
83395 * Extended Numbering
83396 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83397 #define DT_DEBUG 21
83398 #define DT_TEXTREL 22
83399 #define DT_JMPREL 23
83400 +#define DT_FLAGS 30
83401 + #define DF_TEXTREL 0x00000004
83402 #define DT_ENCODING 32
83403 #define OLD_DT_LOOS 0x60000000
83404 #define DT_LOOS 0x6000000d
83405 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
83406 #define PF_W 0x2
83407 #define PF_X 0x1
83408
83409 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
83410 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
83411 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
83412 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
83413 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
83414 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
83415 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
83416 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
83417 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
83418 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
83419 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
83420 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
83421 +
83422 typedef struct elf32_phdr{
83423 Elf32_Word p_type;
83424 Elf32_Off p_offset;
83425 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
83426 #define EI_OSABI 7
83427 #define EI_PAD 8
83428
83429 +#define EI_PAX 14
83430 +
83431 #define ELFMAG0 0x7f /* EI_MAG */
83432 #define ELFMAG1 'E'
83433 #define ELFMAG2 'L'
83434 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
83435 index aa169c4..6a2771d 100644
83436 --- a/include/uapi/linux/personality.h
83437 +++ b/include/uapi/linux/personality.h
83438 @@ -30,6 +30,7 @@ enum {
83439 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
83440 ADDR_NO_RANDOMIZE | \
83441 ADDR_COMPAT_LAYOUT | \
83442 + ADDR_LIMIT_3GB | \
83443 MMAP_PAGE_ZERO)
83444
83445 /*
83446 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
83447 index 7530e74..e714828 100644
83448 --- a/include/uapi/linux/screen_info.h
83449 +++ b/include/uapi/linux/screen_info.h
83450 @@ -43,7 +43,8 @@ struct screen_info {
83451 __u16 pages; /* 0x32 */
83452 __u16 vesa_attributes; /* 0x34 */
83453 __u32 capabilities; /* 0x36 */
83454 - __u8 _reserved[6]; /* 0x3a */
83455 + __u16 vesapm_size; /* 0x3a */
83456 + __u8 _reserved[4]; /* 0x3c */
83457 } __attribute__((packed));
83458
83459 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
83460 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
83461 index 0e011eb..82681b1 100644
83462 --- a/include/uapi/linux/swab.h
83463 +++ b/include/uapi/linux/swab.h
83464 @@ -43,7 +43,7 @@
83465 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
83466 */
83467
83468 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
83469 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
83470 {
83471 #ifdef __HAVE_BUILTIN_BSWAP16__
83472 return __builtin_bswap16(val);
83473 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
83474 #endif
83475 }
83476
83477 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
83478 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
83479 {
83480 #ifdef __HAVE_BUILTIN_BSWAP32__
83481 return __builtin_bswap32(val);
83482 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
83483 #endif
83484 }
83485
83486 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
83487 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
83488 {
83489 #ifdef __HAVE_BUILTIN_BSWAP64__
83490 return __builtin_bswap64(val);
83491 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
83492 index 6d67213..552fdd9 100644
83493 --- a/include/uapi/linux/sysctl.h
83494 +++ b/include/uapi/linux/sysctl.h
83495 @@ -155,8 +155,6 @@ enum
83496 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
83497 };
83498
83499 -
83500 -
83501 /* CTL_VM names: */
83502 enum
83503 {
83504 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
83505 index 437f1b0..0eeb38d 100644
83506 --- a/include/uapi/linux/videodev2.h
83507 +++ b/include/uapi/linux/videodev2.h
83508 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
83509 union {
83510 __s32 value;
83511 __s64 value64;
83512 - char *string;
83513 + char __user *string;
83514 };
83515 } __attribute__ ((packed));
83516
83517 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
83518 index e4629b9..6958086 100644
83519 --- a/include/uapi/linux/xattr.h
83520 +++ b/include/uapi/linux/xattr.h
83521 @@ -63,5 +63,9 @@
83522 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
83523 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
83524
83525 +/* User namespace */
83526 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
83527 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
83528 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
83529
83530 #endif /* _UAPI_LINUX_XATTR_H */
83531 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
83532 index f9466fa..f4e2b81 100644
83533 --- a/include/video/udlfb.h
83534 +++ b/include/video/udlfb.h
83535 @@ -53,10 +53,10 @@ struct dlfb_data {
83536 u32 pseudo_palette[256];
83537 int blank_mode; /*one of FB_BLANK_ */
83538 /* blit-only rendering path metrics, exposed through sysfs */
83539 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83540 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
83541 - atomic_t bytes_sent; /* to usb, after compression including overhead */
83542 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
83543 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83544 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
83545 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
83546 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
83547 };
83548
83549 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
83550 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
83551 index 30f5362..8ed8ac9 100644
83552 --- a/include/video/uvesafb.h
83553 +++ b/include/video/uvesafb.h
83554 @@ -122,6 +122,7 @@ struct uvesafb_par {
83555 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
83556 u8 pmi_setpal; /* PMI for palette changes */
83557 u16 *pmi_base; /* protected mode interface location */
83558 + u8 *pmi_code; /* protected mode code location */
83559 void *pmi_start;
83560 void *pmi_pal;
83561 u8 *vbe_state_orig; /*
83562 diff --git a/init/Kconfig b/init/Kconfig
83563 index 4e5d96a..93cd8a1 100644
83564 --- a/init/Kconfig
83565 +++ b/init/Kconfig
83566 @@ -1079,6 +1079,7 @@ endif # CGROUPS
83567
83568 config CHECKPOINT_RESTORE
83569 bool "Checkpoint/restore support" if EXPERT
83570 + depends on !GRKERNSEC
83571 default n
83572 help
83573 Enables additional kernel features in a sake of checkpoint/restore.
83574 @@ -1550,7 +1551,7 @@ config SLUB_DEBUG
83575
83576 config COMPAT_BRK
83577 bool "Disable heap randomization"
83578 - default y
83579 + default n
83580 help
83581 Randomizing heap placement makes heap exploits harder, but it
83582 also breaks ancient binaries (including anything libc5 based).
83583 @@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
83584 config STOP_MACHINE
83585 bool
83586 default y
83587 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
83588 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
83589 help
83590 Need stop_machine() primitive.
83591
83592 diff --git a/init/Makefile b/init/Makefile
83593 index 7bc47ee..6da2dc7 100644
83594 --- a/init/Makefile
83595 +++ b/init/Makefile
83596 @@ -2,6 +2,9 @@
83597 # Makefile for the linux kernel.
83598 #
83599
83600 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
83601 +asflags-y := $(GCC_PLUGINS_AFLAGS)
83602 +
83603 obj-y := main.o version.o mounts.o
83604 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
83605 obj-y += noinitramfs.o
83606 diff --git a/init/do_mounts.c b/init/do_mounts.c
83607 index 8e5addc..c96ea61 100644
83608 --- a/init/do_mounts.c
83609 +++ b/init/do_mounts.c
83610 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
83611 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
83612 {
83613 struct super_block *s;
83614 - int err = sys_mount(name, "/root", fs, flags, data);
83615 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
83616 if (err)
83617 return err;
83618
83619 - sys_chdir("/root");
83620 + sys_chdir((const char __force_user *)"/root");
83621 s = current->fs->pwd.dentry->d_sb;
83622 ROOT_DEV = s->s_dev;
83623 printk(KERN_INFO
83624 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
83625 va_start(args, fmt);
83626 vsprintf(buf, fmt, args);
83627 va_end(args);
83628 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
83629 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
83630 if (fd >= 0) {
83631 sys_ioctl(fd, FDEJECT, 0);
83632 sys_close(fd);
83633 }
83634 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
83635 - fd = sys_open("/dev/console", O_RDWR, 0);
83636 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
83637 if (fd >= 0) {
83638 sys_ioctl(fd, TCGETS, (long)&termios);
83639 termios.c_lflag &= ~ICANON;
83640 sys_ioctl(fd, TCSETSF, (long)&termios);
83641 - sys_read(fd, &c, 1);
83642 + sys_read(fd, (char __user *)&c, 1);
83643 termios.c_lflag |= ICANON;
83644 sys_ioctl(fd, TCSETSF, (long)&termios);
83645 sys_close(fd);
83646 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
83647 mount_root();
83648 out:
83649 devtmpfs_mount("dev");
83650 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
83651 - sys_chroot(".");
83652 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83653 + sys_chroot((const char __force_user *)".");
83654 }
83655
83656 static bool is_tmpfs;
83657 diff --git a/init/do_mounts.h b/init/do_mounts.h
83658 index f5b978a..69dbfe8 100644
83659 --- a/init/do_mounts.h
83660 +++ b/init/do_mounts.h
83661 @@ -15,15 +15,15 @@ extern int root_mountflags;
83662
83663 static inline int create_dev(char *name, dev_t dev)
83664 {
83665 - sys_unlink(name);
83666 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
83667 + sys_unlink((char __force_user *)name);
83668 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
83669 }
83670
83671 #if BITS_PER_LONG == 32
83672 static inline u32 bstat(char *name)
83673 {
83674 struct stat64 stat;
83675 - if (sys_stat64(name, &stat) != 0)
83676 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
83677 return 0;
83678 if (!S_ISBLK(stat.st_mode))
83679 return 0;
83680 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
83681 static inline u32 bstat(char *name)
83682 {
83683 struct stat stat;
83684 - if (sys_newstat(name, &stat) != 0)
83685 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
83686 return 0;
83687 if (!S_ISBLK(stat.st_mode))
83688 return 0;
83689 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
83690 index 3e0878e..8a9d7a0 100644
83691 --- a/init/do_mounts_initrd.c
83692 +++ b/init/do_mounts_initrd.c
83693 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
83694 {
83695 sys_unshare(CLONE_FS | CLONE_FILES);
83696 /* stdin/stdout/stderr for /linuxrc */
83697 - sys_open("/dev/console", O_RDWR, 0);
83698 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
83699 sys_dup(0);
83700 sys_dup(0);
83701 /* move initrd over / and chdir/chroot in initrd root */
83702 - sys_chdir("/root");
83703 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
83704 - sys_chroot(".");
83705 + sys_chdir((const char __force_user *)"/root");
83706 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83707 + sys_chroot((const char __force_user *)".");
83708 sys_setsid();
83709 return 0;
83710 }
83711 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
83712 create_dev("/dev/root.old", Root_RAM0);
83713 /* mount initrd on rootfs' /root */
83714 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
83715 - sys_mkdir("/old", 0700);
83716 - sys_chdir("/old");
83717 + sys_mkdir((const char __force_user *)"/old", 0700);
83718 + sys_chdir((const char __force_user *)"/old");
83719
83720 /* try loading default modules from initrd */
83721 load_default_modules();
83722 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
83723 current->flags &= ~PF_FREEZER_SKIP;
83724
83725 /* move initrd to rootfs' /old */
83726 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
83727 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
83728 /* switch root and cwd back to / of rootfs */
83729 - sys_chroot("..");
83730 + sys_chroot((const char __force_user *)"..");
83731
83732 if (new_decode_dev(real_root_dev) == Root_RAM0) {
83733 - sys_chdir("/old");
83734 + sys_chdir((const char __force_user *)"/old");
83735 return;
83736 }
83737
83738 - sys_chdir("/");
83739 + sys_chdir((const char __force_user *)"/");
83740 ROOT_DEV = new_decode_dev(real_root_dev);
83741 mount_root();
83742
83743 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
83744 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
83745 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
83746 if (!error)
83747 printk("okay\n");
83748 else {
83749 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
83750 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
83751 if (error == -ENOENT)
83752 printk("/initrd does not exist. Ignored.\n");
83753 else
83754 printk("failed\n");
83755 printk(KERN_NOTICE "Unmounting old root\n");
83756 - sys_umount("/old", MNT_DETACH);
83757 + sys_umount((char __force_user *)"/old", MNT_DETACH);
83758 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
83759 if (fd < 0) {
83760 error = fd;
83761 @@ -127,11 +127,11 @@ int __init initrd_load(void)
83762 * mounted in the normal path.
83763 */
83764 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
83765 - sys_unlink("/initrd.image");
83766 + sys_unlink((const char __force_user *)"/initrd.image");
83767 handle_initrd();
83768 return 1;
83769 }
83770 }
83771 - sys_unlink("/initrd.image");
83772 + sys_unlink((const char __force_user *)"/initrd.image");
83773 return 0;
83774 }
83775 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
83776 index 8cb6db5..d729f50 100644
83777 --- a/init/do_mounts_md.c
83778 +++ b/init/do_mounts_md.c
83779 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
83780 partitioned ? "_d" : "", minor,
83781 md_setup_args[ent].device_names);
83782
83783 - fd = sys_open(name, 0, 0);
83784 + fd = sys_open((char __force_user *)name, 0, 0);
83785 if (fd < 0) {
83786 printk(KERN_ERR "md: open failed - cannot start "
83787 "array %s\n", name);
83788 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
83789 * array without it
83790 */
83791 sys_close(fd);
83792 - fd = sys_open(name, 0, 0);
83793 + fd = sys_open((char __force_user *)name, 0, 0);
83794 sys_ioctl(fd, BLKRRPART, 0);
83795 }
83796 sys_close(fd);
83797 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
83798
83799 wait_for_device_probe();
83800
83801 - fd = sys_open("/dev/md0", 0, 0);
83802 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
83803 if (fd >= 0) {
83804 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
83805 sys_close(fd);
83806 diff --git a/init/init_task.c b/init/init_task.c
83807 index ba0a7f36..2bcf1d5 100644
83808 --- a/init/init_task.c
83809 +++ b/init/init_task.c
83810 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
83811 * Initial thread structure. Alignment of this is handled by a special
83812 * linker map entry.
83813 */
83814 +#ifdef CONFIG_X86
83815 +union thread_union init_thread_union __init_task_data;
83816 +#else
83817 union thread_union init_thread_union __init_task_data =
83818 { INIT_THREAD_INFO(init_task) };
83819 +#endif
83820 diff --git a/init/initramfs.c b/init/initramfs.c
83821 index a67ef9d..2d17ed9 100644
83822 --- a/init/initramfs.c
83823 +++ b/init/initramfs.c
83824 @@ -84,7 +84,7 @@ static void __init free_hash(void)
83825 }
83826 }
83827
83828 -static long __init do_utime(char *filename, time_t mtime)
83829 +static long __init do_utime(char __force_user *filename, time_t mtime)
83830 {
83831 struct timespec t[2];
83832
83833 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
83834 struct dir_entry *de, *tmp;
83835 list_for_each_entry_safe(de, tmp, &dir_list, list) {
83836 list_del(&de->list);
83837 - do_utime(de->name, de->mtime);
83838 + do_utime((char __force_user *)de->name, de->mtime);
83839 kfree(de->name);
83840 kfree(de);
83841 }
83842 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
83843 if (nlink >= 2) {
83844 char *old = find_link(major, minor, ino, mode, collected);
83845 if (old)
83846 - return (sys_link(old, collected) < 0) ? -1 : 1;
83847 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
83848 }
83849 return 0;
83850 }
83851 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
83852 {
83853 struct stat st;
83854
83855 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
83856 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
83857 if (S_ISDIR(st.st_mode))
83858 - sys_rmdir(path);
83859 + sys_rmdir((char __force_user *)path);
83860 else
83861 - sys_unlink(path);
83862 + sys_unlink((char __force_user *)path);
83863 }
83864 }
83865
83866 @@ -315,7 +315,7 @@ static int __init do_name(void)
83867 int openflags = O_WRONLY|O_CREAT;
83868 if (ml != 1)
83869 openflags |= O_TRUNC;
83870 - wfd = sys_open(collected, openflags, mode);
83871 + wfd = sys_open((char __force_user *)collected, openflags, mode);
83872
83873 if (wfd >= 0) {
83874 sys_fchown(wfd, uid, gid);
83875 @@ -327,17 +327,17 @@ static int __init do_name(void)
83876 }
83877 }
83878 } else if (S_ISDIR(mode)) {
83879 - sys_mkdir(collected, mode);
83880 - sys_chown(collected, uid, gid);
83881 - sys_chmod(collected, mode);
83882 + sys_mkdir((char __force_user *)collected, mode);
83883 + sys_chown((char __force_user *)collected, uid, gid);
83884 + sys_chmod((char __force_user *)collected, mode);
83885 dir_add(collected, mtime);
83886 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
83887 S_ISFIFO(mode) || S_ISSOCK(mode)) {
83888 if (maybe_link() == 0) {
83889 - sys_mknod(collected, mode, rdev);
83890 - sys_chown(collected, uid, gid);
83891 - sys_chmod(collected, mode);
83892 - do_utime(collected, mtime);
83893 + sys_mknod((char __force_user *)collected, mode, rdev);
83894 + sys_chown((char __force_user *)collected, uid, gid);
83895 + sys_chmod((char __force_user *)collected, mode);
83896 + do_utime((char __force_user *)collected, mtime);
83897 }
83898 }
83899 return 0;
83900 @@ -346,15 +346,15 @@ static int __init do_name(void)
83901 static int __init do_copy(void)
83902 {
83903 if (count >= body_len) {
83904 - sys_write(wfd, victim, body_len);
83905 + sys_write(wfd, (char __force_user *)victim, body_len);
83906 sys_close(wfd);
83907 - do_utime(vcollected, mtime);
83908 + do_utime((char __force_user *)vcollected, mtime);
83909 kfree(vcollected);
83910 eat(body_len);
83911 state = SkipIt;
83912 return 0;
83913 } else {
83914 - sys_write(wfd, victim, count);
83915 + sys_write(wfd, (char __force_user *)victim, count);
83916 body_len -= count;
83917 eat(count);
83918 return 1;
83919 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
83920 {
83921 collected[N_ALIGN(name_len) + body_len] = '\0';
83922 clean_path(collected, 0);
83923 - sys_symlink(collected + N_ALIGN(name_len), collected);
83924 - sys_lchown(collected, uid, gid);
83925 - do_utime(collected, mtime);
83926 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
83927 + sys_lchown((char __force_user *)collected, uid, gid);
83928 + do_utime((char __force_user *)collected, mtime);
83929 state = SkipIt;
83930 next_state = Reset;
83931 return 0;
83932 @@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
83933 {
83934 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
83935 if (err)
83936 - panic(err); /* Failed to decompress INTERNAL initramfs */
83937 + panic("%s", err); /* Failed to decompress INTERNAL initramfs */
83938 if (initrd_start) {
83939 #ifdef CONFIG_BLK_DEV_RAM
83940 int fd;
83941 diff --git a/init/main.c b/init/main.c
83942 index febc511..f0851763 100644
83943 --- a/init/main.c
83944 +++ b/init/main.c
83945 @@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
83946 extern void tc_init(void);
83947 #endif
83948
83949 +extern void grsecurity_init(void);
83950 +
83951 /*
83952 * Debug helper: via this flag we know that we are in 'early bootup code'
83953 * where only the boot processor is running with IRQ disabled. This means
83954 @@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
83955
83956 __setup("reset_devices", set_reset_devices);
83957
83958 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83959 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
83960 +static int __init setup_grsec_proc_gid(char *str)
83961 +{
83962 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
83963 + return 1;
83964 +}
83965 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
83966 +#endif
83967 +
83968 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
83969 +unsigned long pax_user_shadow_base __read_only;
83970 +EXPORT_SYMBOL(pax_user_shadow_base);
83971 +extern char pax_enter_kernel_user[];
83972 +extern char pax_exit_kernel_user[];
83973 +#endif
83974 +
83975 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
83976 +static int __init setup_pax_nouderef(char *str)
83977 +{
83978 +#ifdef CONFIG_X86_32
83979 + unsigned int cpu;
83980 + struct desc_struct *gdt;
83981 +
83982 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
83983 + gdt = get_cpu_gdt_table(cpu);
83984 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
83985 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
83986 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
83987 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
83988 + }
83989 + loadsegment(ds, __KERNEL_DS);
83990 + loadsegment(es, __KERNEL_DS);
83991 + loadsegment(ss, __KERNEL_DS);
83992 +#else
83993 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
83994 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
83995 + clone_pgd_mask = ~(pgdval_t)0UL;
83996 + pax_user_shadow_base = 0UL;
83997 + setup_clear_cpu_cap(X86_FEATURE_PCID);
83998 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
83999 +#endif
84000 +
84001 + return 0;
84002 +}
84003 +early_param("pax_nouderef", setup_pax_nouderef);
84004 +
84005 +#ifdef CONFIG_X86_64
84006 +static int __init setup_pax_weakuderef(char *str)
84007 +{
84008 + if (clone_pgd_mask != ~(pgdval_t)0UL)
84009 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84010 + return 1;
84011 +}
84012 +__setup("pax_weakuderef", setup_pax_weakuderef);
84013 +#endif
84014 +#endif
84015 +
84016 +#ifdef CONFIG_PAX_SOFTMODE
84017 +int pax_softmode;
84018 +
84019 +static int __init setup_pax_softmode(char *str)
84020 +{
84021 + get_option(&str, &pax_softmode);
84022 + return 1;
84023 +}
84024 +__setup("pax_softmode=", setup_pax_softmode);
84025 +#endif
84026 +
84027 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84028 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84029 static const char *panic_later, *panic_param;
84030 @@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84031 {
84032 int count = preempt_count();
84033 int ret;
84034 - char msgbuf[64];
84035 + const char *msg1 = "", *msg2 = "";
84036
84037 if (initcall_debug)
84038 ret = do_one_initcall_debug(fn);
84039 else
84040 ret = fn();
84041
84042 - msgbuf[0] = 0;
84043 -
84044 if (preempt_count() != count) {
84045 - sprintf(msgbuf, "preemption imbalance ");
84046 + msg1 = " preemption imbalance";
84047 preempt_count_set(count);
84048 }
84049 if (irqs_disabled()) {
84050 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84051 + msg2 = " disabled interrupts";
84052 local_irq_enable();
84053 }
84054 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84055 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84056
84057 + add_latent_entropy();
84058 return ret;
84059 }
84060
84061 @@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
84062 {
84063 argv_init[0] = init_filename;
84064 return do_execve(init_filename,
84065 - (const char __user *const __user *)argv_init,
84066 - (const char __user *const __user *)envp_init);
84067 + (const char __user *const __force_user *)argv_init,
84068 + (const char __user *const __force_user *)envp_init);
84069 }
84070
84071 static int try_to_run_init_process(const char *init_filename)
84072 @@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
84073 return ret;
84074 }
84075
84076 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84077 +extern int gr_init_ran;
84078 +#endif
84079 +
84080 static noinline void __init kernel_init_freeable(void);
84081
84082 static int __ref kernel_init(void *unused)
84083 @@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
84084 ramdisk_execute_command, ret);
84085 }
84086
84087 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84088 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
84089 + gr_init_ran = 1;
84090 +#endif
84091 +
84092 /*
84093 * We try each of these until one succeeds.
84094 *
84095 @@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
84096 do_basic_setup();
84097
84098 /* Open the /dev/console on the rootfs, this should never fail */
84099 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84100 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84101 pr_err("Warning: unable to open an initial console.\n");
84102
84103 (void) sys_dup(0);
84104 @@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
84105 if (!ramdisk_execute_command)
84106 ramdisk_execute_command = "/init";
84107
84108 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84109 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84110 ramdisk_execute_command = NULL;
84111 prepare_namespace();
84112 }
84113
84114 + grsecurity_init();
84115 +
84116 /*
84117 * Ok, we have completed the initial bootup, and
84118 * we're essentially up and running. Get rid of the
84119 diff --git a/ipc/compat.c b/ipc/compat.c
84120 index 892f658..e7c6320 100644
84121 --- a/ipc/compat.c
84122 +++ b/ipc/compat.c
84123 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84124 COMPAT_SHMLBA);
84125 if (err < 0)
84126 return err;
84127 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84128 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84129 }
84130 case SHMDT:
84131 return sys_shmdt(compat_ptr(ptr));
84132 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84133 index b0e99de..09f385c 100644
84134 --- a/ipc/ipc_sysctl.c
84135 +++ b/ipc/ipc_sysctl.c
84136 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84137 static int proc_ipc_dointvec(ctl_table *table, int write,
84138 void __user *buffer, size_t *lenp, loff_t *ppos)
84139 {
84140 - struct ctl_table ipc_table;
84141 + ctl_table_no_const ipc_table;
84142
84143 memcpy(&ipc_table, table, sizeof(ipc_table));
84144 ipc_table.data = get_ipc(table);
84145 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84146 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84147 void __user *buffer, size_t *lenp, loff_t *ppos)
84148 {
84149 - struct ctl_table ipc_table;
84150 + ctl_table_no_const ipc_table;
84151
84152 memcpy(&ipc_table, table, sizeof(ipc_table));
84153 ipc_table.data = get_ipc(table);
84154 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84155 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84156 void __user *buffer, size_t *lenp, loff_t *ppos)
84157 {
84158 - struct ctl_table ipc_table;
84159 + ctl_table_no_const ipc_table;
84160 size_t lenp_bef = *lenp;
84161 int rc;
84162
84163 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84164 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84165 void __user *buffer, size_t *lenp, loff_t *ppos)
84166 {
84167 - struct ctl_table ipc_table;
84168 + ctl_table_no_const ipc_table;
84169 memcpy(&ipc_table, table, sizeof(ipc_table));
84170 ipc_table.data = get_ipc(table);
84171
84172 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84173 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84174 void __user *buffer, size_t *lenp, loff_t *ppos)
84175 {
84176 - struct ctl_table ipc_table;
84177 + ctl_table_no_const ipc_table;
84178 size_t lenp_bef = *lenp;
84179 int oldval;
84180 int rc;
84181 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84182 index 5bb8bfe..a38ec05 100644
84183 --- a/ipc/mq_sysctl.c
84184 +++ b/ipc/mq_sysctl.c
84185 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84186 static int proc_mq_dointvec(ctl_table *table, int write,
84187 void __user *buffer, size_t *lenp, loff_t *ppos)
84188 {
84189 - struct ctl_table mq_table;
84190 + ctl_table_no_const mq_table;
84191 memcpy(&mq_table, table, sizeof(mq_table));
84192 mq_table.data = get_mq(table);
84193
84194 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84195 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84196 void __user *buffer, size_t *lenp, loff_t *ppos)
84197 {
84198 - struct ctl_table mq_table;
84199 + ctl_table_no_const mq_table;
84200 memcpy(&mq_table, table, sizeof(mq_table));
84201 mq_table.data = get_mq(table);
84202
84203 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84204 index b8d4aed..96a4fe8 100644
84205 --- a/ipc/mqueue.c
84206 +++ b/ipc/mqueue.c
84207 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84208 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84209 info->attr.mq_msgsize);
84210
84211 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84212 spin_lock(&mq_lock);
84213 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84214 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84215 diff --git a/ipc/msg.c b/ipc/msg.c
84216 index 558aa91..359e718 100644
84217 --- a/ipc/msg.c
84218 +++ b/ipc/msg.c
84219 @@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84220 return security_msg_queue_associate(msq, msgflg);
84221 }
84222
84223 +static struct ipc_ops msg_ops = {
84224 + .getnew = newque,
84225 + .associate = msg_security,
84226 + .more_checks = NULL
84227 +};
84228 +
84229 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84230 {
84231 struct ipc_namespace *ns;
84232 - struct ipc_ops msg_ops;
84233 struct ipc_params msg_params;
84234
84235 ns = current->nsproxy->ipc_ns;
84236
84237 - msg_ops.getnew = newque;
84238 - msg_ops.associate = msg_security;
84239 - msg_ops.more_checks = NULL;
84240 -
84241 msg_params.key = key;
84242 msg_params.flg = msgflg;
84243
84244 diff --git a/ipc/sem.c b/ipc/sem.c
84245 index db9d241..bc8427c 100644
84246 --- a/ipc/sem.c
84247 +++ b/ipc/sem.c
84248 @@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84249 return 0;
84250 }
84251
84252 +static struct ipc_ops sem_ops = {
84253 + .getnew = newary,
84254 + .associate = sem_security,
84255 + .more_checks = sem_more_checks
84256 +};
84257 +
84258 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84259 {
84260 struct ipc_namespace *ns;
84261 - struct ipc_ops sem_ops;
84262 struct ipc_params sem_params;
84263
84264 ns = current->nsproxy->ipc_ns;
84265 @@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84266 if (nsems < 0 || nsems > ns->sc_semmsl)
84267 return -EINVAL;
84268
84269 - sem_ops.getnew = newary;
84270 - sem_ops.associate = sem_security;
84271 - sem_ops.more_checks = sem_more_checks;
84272 -
84273 sem_params.key = key;
84274 sem_params.flg = semflg;
84275 sem_params.u.nsems = nsems;
84276 diff --git a/ipc/shm.c b/ipc/shm.c
84277 index 7a51443..3a257d8 100644
84278 --- a/ipc/shm.c
84279 +++ b/ipc/shm.c
84280 @@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
84281 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84282 #endif
84283
84284 +#ifdef CONFIG_GRKERNSEC
84285 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84286 + const time_t shm_createtime, const kuid_t cuid,
84287 + const int shmid);
84288 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84289 + const time_t shm_createtime);
84290 +#endif
84291 +
84292 void shm_init_ns(struct ipc_namespace *ns)
84293 {
84294 ns->shm_ctlmax = SHMMAX;
84295 @@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84296 shp->shm_lprid = 0;
84297 shp->shm_atim = shp->shm_dtim = 0;
84298 shp->shm_ctim = get_seconds();
84299 +#ifdef CONFIG_GRKERNSEC
84300 + {
84301 + struct timespec timeval;
84302 + do_posix_clock_monotonic_gettime(&timeval);
84303 +
84304 + shp->shm_createtime = timeval.tv_sec;
84305 + }
84306 +#endif
84307 shp->shm_segsz = size;
84308 shp->shm_nattch = 0;
84309 shp->shm_file = file;
84310 @@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84311 return 0;
84312 }
84313
84314 +static struct ipc_ops shm_ops = {
84315 + .getnew = newseg,
84316 + .associate = shm_security,
84317 + .more_checks = shm_more_checks
84318 +};
84319 +
84320 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84321 {
84322 struct ipc_namespace *ns;
84323 - struct ipc_ops shm_ops;
84324 struct ipc_params shm_params;
84325
84326 ns = current->nsproxy->ipc_ns;
84327
84328 - shm_ops.getnew = newseg;
84329 - shm_ops.associate = shm_security;
84330 - shm_ops.more_checks = shm_more_checks;
84331 -
84332 shm_params.key = key;
84333 shm_params.flg = shmflg;
84334 shm_params.u.size = size;
84335 @@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84336 f_mode = FMODE_READ | FMODE_WRITE;
84337 }
84338 if (shmflg & SHM_EXEC) {
84339 +
84340 +#ifdef CONFIG_PAX_MPROTECT
84341 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
84342 + goto out;
84343 +#endif
84344 +
84345 prot |= PROT_EXEC;
84346 acc_mode |= S_IXUGO;
84347 }
84348 @@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84349 if (err)
84350 goto out_unlock;
84351
84352 +#ifdef CONFIG_GRKERNSEC
84353 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84354 + shp->shm_perm.cuid, shmid) ||
84355 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84356 + err = -EACCES;
84357 + goto out_unlock;
84358 + }
84359 +#endif
84360 +
84361 ipc_lock_object(&shp->shm_perm);
84362
84363 /* check if shm_destroy() is tearing down shp */
84364 @@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84365 path = shp->shm_file->f_path;
84366 path_get(&path);
84367 shp->shm_nattch++;
84368 +#ifdef CONFIG_GRKERNSEC
84369 + shp->shm_lapid = current->pid;
84370 +#endif
84371 size = i_size_read(path.dentry->d_inode);
84372 ipc_unlock_object(&shp->shm_perm);
84373 rcu_read_unlock();
84374 diff --git a/ipc/util.c b/ipc/util.c
84375 index 3ae17a4..d67c32f 100644
84376 --- a/ipc/util.c
84377 +++ b/ipc/util.c
84378 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
84379 int (*show)(struct seq_file *, void *);
84380 };
84381
84382 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84383 +
84384 static void ipc_memory_notifier(struct work_struct *work)
84385 {
84386 ipcns_notify(IPCNS_MEMCHANGED);
84387 @@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84388 granted_mode >>= 6;
84389 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84390 granted_mode >>= 3;
84391 +
84392 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84393 + return -1;
84394 +
84395 /* is there some bit set in requested_mode but not in granted_mode? */
84396 if ((requested_mode & ~granted_mode & 0007) &&
84397 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84398 diff --git a/kernel/acct.c b/kernel/acct.c
84399 index 8d6e145..33e0b1e 100644
84400 --- a/kernel/acct.c
84401 +++ b/kernel/acct.c
84402 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84403 */
84404 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84405 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84406 - file->f_op->write(file, (char *)&ac,
84407 + file->f_op->write(file, (char __force_user *)&ac,
84408 sizeof(acct_t), &file->f_pos);
84409 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84410 set_fs(fs);
84411 diff --git a/kernel/audit.c b/kernel/audit.c
84412 index 15ec13a..986322e 100644
84413 --- a/kernel/audit.c
84414 +++ b/kernel/audit.c
84415 @@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
84416 3) suppressed due to audit_rate_limit
84417 4) suppressed due to audit_backlog_limit
84418 */
84419 -static atomic_t audit_lost = ATOMIC_INIT(0);
84420 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
84421
84422 /* The netlink socket. */
84423 static struct sock *audit_sock;
84424 @@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
84425 unsigned long now;
84426 int print;
84427
84428 - atomic_inc(&audit_lost);
84429 + atomic_inc_unchecked(&audit_lost);
84430
84431 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
84432
84433 @@ -270,7 +270,7 @@ void audit_log_lost(const char *message)
84434 printk(KERN_WARNING
84435 "audit: audit_lost=%d audit_rate_limit=%d "
84436 "audit_backlog_limit=%d\n",
84437 - atomic_read(&audit_lost),
84438 + atomic_read_unchecked(&audit_lost),
84439 audit_rate_limit,
84440 audit_backlog_limit);
84441 audit_panic(message);
84442 @@ -766,7 +766,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84443 status_set.pid = audit_pid;
84444 status_set.rate_limit = audit_rate_limit;
84445 status_set.backlog_limit = audit_backlog_limit;
84446 - status_set.lost = atomic_read(&audit_lost);
84447 + status_set.lost = atomic_read_unchecked(&audit_lost);
84448 status_set.backlog = skb_queue_len(&audit_skb_queue);
84449 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
84450 &status_set, sizeof(status_set));
84451 @@ -1359,7 +1359,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
84452 int i, avail, new_len;
84453 unsigned char *ptr;
84454 struct sk_buff *skb;
84455 - static const unsigned char *hex = "0123456789ABCDEF";
84456 + static const unsigned char hex[] = "0123456789ABCDEF";
84457
84458 if (!ab)
84459 return;
84460 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
84461 index 90594c9..abbeed7 100644
84462 --- a/kernel/auditsc.c
84463 +++ b/kernel/auditsc.c
84464 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
84465 }
84466
84467 /* global counter which is incremented every time something logs in */
84468 -static atomic_t session_id = ATOMIC_INIT(0);
84469 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
84470
84471 static int audit_set_loginuid_perm(kuid_t loginuid)
84472 {
84473 @@ -2008,7 +2008,7 @@ int audit_set_loginuid(kuid_t loginuid)
84474
84475 /* are we setting or clearing? */
84476 if (uid_valid(loginuid))
84477 - sessionid = atomic_inc_return(&session_id);
84478 + sessionid = atomic_inc_return_unchecked(&session_id);
84479
84480 task->sessionid = sessionid;
84481 task->loginuid = loginuid;
84482 diff --git a/kernel/capability.c b/kernel/capability.c
84483 index 4e66bf9..cdccecf 100644
84484 --- a/kernel/capability.c
84485 +++ b/kernel/capability.c
84486 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
84487 * before modification is attempted and the application
84488 * fails.
84489 */
84490 + if (tocopy > ARRAY_SIZE(kdata))
84491 + return -EFAULT;
84492 +
84493 if (copy_to_user(dataptr, kdata, tocopy
84494 * sizeof(struct __user_cap_data_struct))) {
84495 return -EFAULT;
84496 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
84497 int ret;
84498
84499 rcu_read_lock();
84500 - ret = security_capable(__task_cred(t), ns, cap);
84501 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
84502 + gr_task_is_capable(t, __task_cred(t), cap);
84503 rcu_read_unlock();
84504
84505 - return (ret == 0);
84506 + return ret;
84507 }
84508
84509 /**
84510 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
84511 int ret;
84512
84513 rcu_read_lock();
84514 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
84515 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
84516 rcu_read_unlock();
84517
84518 - return (ret == 0);
84519 + return ret;
84520 }
84521
84522 /**
84523 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
84524 BUG();
84525 }
84526
84527 - if (security_capable(current_cred(), ns, cap) == 0) {
84528 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
84529 current->flags |= PF_SUPERPRIV;
84530 return true;
84531 }
84532 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
84533 }
84534 EXPORT_SYMBOL(ns_capable);
84535
84536 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
84537 +{
84538 + if (unlikely(!cap_valid(cap))) {
84539 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
84540 + BUG();
84541 + }
84542 +
84543 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
84544 + current->flags |= PF_SUPERPRIV;
84545 + return true;
84546 + }
84547 + return false;
84548 +}
84549 +EXPORT_SYMBOL(ns_capable_nolog);
84550 +
84551 /**
84552 * file_ns_capable - Determine if the file's opener had a capability in effect
84553 * @file: The file we want to check
84554 @@ -432,6 +451,12 @@ bool capable(int cap)
84555 }
84556 EXPORT_SYMBOL(capable);
84557
84558 +bool capable_nolog(int cap)
84559 +{
84560 + return ns_capable_nolog(&init_user_ns, cap);
84561 +}
84562 +EXPORT_SYMBOL(capable_nolog);
84563 +
84564 /**
84565 * inode_capable - Check superior capability over inode
84566 * @inode: The inode in question
84567 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
84568 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84569 }
84570 EXPORT_SYMBOL(inode_capable);
84571 +
84572 +bool inode_capable_nolog(const struct inode *inode, int cap)
84573 +{
84574 + struct user_namespace *ns = current_user_ns();
84575 +
84576 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84577 +}
84578 +EXPORT_SYMBOL(inode_capable_nolog);
84579 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
84580 index 271acd8..54b70fe 100644
84581 --- a/kernel/cgroup.c
84582 +++ b/kernel/cgroup.c
84583 @@ -5609,7 +5609,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
84584 struct css_set *cset = link->cset;
84585 struct task_struct *task;
84586 int count = 0;
84587 - seq_printf(seq, "css_set %p\n", cset);
84588 + seq_printf(seq, "css_set %pK\n", cset);
84589 list_for_each_entry(task, &cset->tasks, cg_list) {
84590 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
84591 seq_puts(seq, " ...\n");
84592 diff --git a/kernel/compat.c b/kernel/compat.c
84593 index 0a09e48..b46b3d78 100644
84594 --- a/kernel/compat.c
84595 +++ b/kernel/compat.c
84596 @@ -13,6 +13,7 @@
84597
84598 #include <linux/linkage.h>
84599 #include <linux/compat.h>
84600 +#include <linux/module.h>
84601 #include <linux/errno.h>
84602 #include <linux/time.h>
84603 #include <linux/signal.h>
84604 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
84605 mm_segment_t oldfs;
84606 long ret;
84607
84608 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
84609 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
84610 oldfs = get_fs();
84611 set_fs(KERNEL_DS);
84612 ret = hrtimer_nanosleep_restart(restart);
84613 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
84614 oldfs = get_fs();
84615 set_fs(KERNEL_DS);
84616 ret = hrtimer_nanosleep(&tu,
84617 - rmtp ? (struct timespec __user *)&rmt : NULL,
84618 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
84619 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
84620 set_fs(oldfs);
84621
84622 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
84623 mm_segment_t old_fs = get_fs();
84624
84625 set_fs(KERNEL_DS);
84626 - ret = sys_sigpending((old_sigset_t __user *) &s);
84627 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
84628 set_fs(old_fs);
84629 if (ret == 0)
84630 ret = put_user(s, set);
84631 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
84632 mm_segment_t old_fs = get_fs();
84633
84634 set_fs(KERNEL_DS);
84635 - ret = sys_old_getrlimit(resource, &r);
84636 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
84637 set_fs(old_fs);
84638
84639 if (!ret) {
84640 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
84641 set_fs (KERNEL_DS);
84642 ret = sys_wait4(pid,
84643 (stat_addr ?
84644 - (unsigned int __user *) &status : NULL),
84645 - options, (struct rusage __user *) &r);
84646 + (unsigned int __force_user *) &status : NULL),
84647 + options, (struct rusage __force_user *) &r);
84648 set_fs (old_fs);
84649
84650 if (ret > 0) {
84651 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
84652 memset(&info, 0, sizeof(info));
84653
84654 set_fs(KERNEL_DS);
84655 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
84656 - uru ? (struct rusage __user *)&ru : NULL);
84657 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
84658 + uru ? (struct rusage __force_user *)&ru : NULL);
84659 set_fs(old_fs);
84660
84661 if ((ret < 0) || (info.si_signo == 0))
84662 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
84663 oldfs = get_fs();
84664 set_fs(KERNEL_DS);
84665 err = sys_timer_settime(timer_id, flags,
84666 - (struct itimerspec __user *) &newts,
84667 - (struct itimerspec __user *) &oldts);
84668 + (struct itimerspec __force_user *) &newts,
84669 + (struct itimerspec __force_user *) &oldts);
84670 set_fs(oldfs);
84671 if (!err && old && put_compat_itimerspec(old, &oldts))
84672 return -EFAULT;
84673 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
84674 oldfs = get_fs();
84675 set_fs(KERNEL_DS);
84676 err = sys_timer_gettime(timer_id,
84677 - (struct itimerspec __user *) &ts);
84678 + (struct itimerspec __force_user *) &ts);
84679 set_fs(oldfs);
84680 if (!err && put_compat_itimerspec(setting, &ts))
84681 return -EFAULT;
84682 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
84683 oldfs = get_fs();
84684 set_fs(KERNEL_DS);
84685 err = sys_clock_settime(which_clock,
84686 - (struct timespec __user *) &ts);
84687 + (struct timespec __force_user *) &ts);
84688 set_fs(oldfs);
84689 return err;
84690 }
84691 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
84692 oldfs = get_fs();
84693 set_fs(KERNEL_DS);
84694 err = sys_clock_gettime(which_clock,
84695 - (struct timespec __user *) &ts);
84696 + (struct timespec __force_user *) &ts);
84697 set_fs(oldfs);
84698 if (!err && put_compat_timespec(&ts, tp))
84699 return -EFAULT;
84700 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
84701
84702 oldfs = get_fs();
84703 set_fs(KERNEL_DS);
84704 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
84705 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
84706 set_fs(oldfs);
84707
84708 err = compat_put_timex(utp, &txc);
84709 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
84710 oldfs = get_fs();
84711 set_fs(KERNEL_DS);
84712 err = sys_clock_getres(which_clock,
84713 - (struct timespec __user *) &ts);
84714 + (struct timespec __force_user *) &ts);
84715 set_fs(oldfs);
84716 if (!err && tp && put_compat_timespec(&ts, tp))
84717 return -EFAULT;
84718 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
84719 long err;
84720 mm_segment_t oldfs;
84721 struct timespec tu;
84722 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
84723 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
84724
84725 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
84726 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
84727 oldfs = get_fs();
84728 set_fs(KERNEL_DS);
84729 err = clock_nanosleep_restart(restart);
84730 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
84731 oldfs = get_fs();
84732 set_fs(KERNEL_DS);
84733 err = sys_clock_nanosleep(which_clock, flags,
84734 - (struct timespec __user *) &in,
84735 - (struct timespec __user *) &out);
84736 + (struct timespec __force_user *) &in,
84737 + (struct timespec __force_user *) &out);
84738 set_fs(oldfs);
84739
84740 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
84741 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
84742 mm_segment_t old_fs = get_fs();
84743
84744 set_fs(KERNEL_DS);
84745 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
84746 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
84747 set_fs(old_fs);
84748 if (put_compat_timespec(&t, interval))
84749 return -EFAULT;
84750 diff --git a/kernel/configs.c b/kernel/configs.c
84751 index c18b1f1..b9a0132 100644
84752 --- a/kernel/configs.c
84753 +++ b/kernel/configs.c
84754 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
84755 struct proc_dir_entry *entry;
84756
84757 /* create the current config file */
84758 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
84759 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
84760 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
84761 + &ikconfig_file_ops);
84762 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84763 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
84764 + &ikconfig_file_ops);
84765 +#endif
84766 +#else
84767 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
84768 &ikconfig_file_ops);
84769 +#endif
84770 +
84771 if (!entry)
84772 return -ENOMEM;
84773
84774 diff --git a/kernel/cred.c b/kernel/cred.c
84775 index e0573a4..3874e41 100644
84776 --- a/kernel/cred.c
84777 +++ b/kernel/cred.c
84778 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
84779 validate_creds(cred);
84780 alter_cred_subscribers(cred, -1);
84781 put_cred(cred);
84782 +
84783 +#ifdef CONFIG_GRKERNSEC_SETXID
84784 + cred = (struct cred *) tsk->delayed_cred;
84785 + if (cred != NULL) {
84786 + tsk->delayed_cred = NULL;
84787 + validate_creds(cred);
84788 + alter_cred_subscribers(cred, -1);
84789 + put_cred(cred);
84790 + }
84791 +#endif
84792 }
84793
84794 /**
84795 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
84796 * Always returns 0 thus allowing this function to be tail-called at the end
84797 * of, say, sys_setgid().
84798 */
84799 -int commit_creds(struct cred *new)
84800 +static int __commit_creds(struct cred *new)
84801 {
84802 struct task_struct *task = current;
84803 const struct cred *old = task->real_cred;
84804 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
84805
84806 get_cred(new); /* we will require a ref for the subj creds too */
84807
84808 + gr_set_role_label(task, new->uid, new->gid);
84809 +
84810 /* dumpability changes */
84811 if (!uid_eq(old->euid, new->euid) ||
84812 !gid_eq(old->egid, new->egid) ||
84813 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
84814 put_cred(old);
84815 return 0;
84816 }
84817 +#ifdef CONFIG_GRKERNSEC_SETXID
84818 +extern int set_user(struct cred *new);
84819 +
84820 +void gr_delayed_cred_worker(void)
84821 +{
84822 + const struct cred *new = current->delayed_cred;
84823 + struct cred *ncred;
84824 +
84825 + current->delayed_cred = NULL;
84826 +
84827 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
84828 + // from doing get_cred on it when queueing this
84829 + put_cred(new);
84830 + return;
84831 + } else if (new == NULL)
84832 + return;
84833 +
84834 + ncred = prepare_creds();
84835 + if (!ncred)
84836 + goto die;
84837 + // uids
84838 + ncred->uid = new->uid;
84839 + ncred->euid = new->euid;
84840 + ncred->suid = new->suid;
84841 + ncred->fsuid = new->fsuid;
84842 + // gids
84843 + ncred->gid = new->gid;
84844 + ncred->egid = new->egid;
84845 + ncred->sgid = new->sgid;
84846 + ncred->fsgid = new->fsgid;
84847 + // groups
84848 + if (set_groups(ncred, new->group_info) < 0) {
84849 + abort_creds(ncred);
84850 + goto die;
84851 + }
84852 + // caps
84853 + ncred->securebits = new->securebits;
84854 + ncred->cap_inheritable = new->cap_inheritable;
84855 + ncred->cap_permitted = new->cap_permitted;
84856 + ncred->cap_effective = new->cap_effective;
84857 + ncred->cap_bset = new->cap_bset;
84858 +
84859 + if (set_user(ncred)) {
84860 + abort_creds(ncred);
84861 + goto die;
84862 + }
84863 +
84864 + // from doing get_cred on it when queueing this
84865 + put_cred(new);
84866 +
84867 + __commit_creds(ncred);
84868 + return;
84869 +die:
84870 + // from doing get_cred on it when queueing this
84871 + put_cred(new);
84872 + do_group_exit(SIGKILL);
84873 +}
84874 +#endif
84875 +
84876 +int commit_creds(struct cred *new)
84877 +{
84878 +#ifdef CONFIG_GRKERNSEC_SETXID
84879 + int ret;
84880 + int schedule_it = 0;
84881 + struct task_struct *t;
84882 +
84883 + /* we won't get called with tasklist_lock held for writing
84884 + and interrupts disabled as the cred struct in that case is
84885 + init_cred
84886 + */
84887 + if (grsec_enable_setxid && !current_is_single_threaded() &&
84888 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
84889 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
84890 + schedule_it = 1;
84891 + }
84892 + ret = __commit_creds(new);
84893 + if (schedule_it) {
84894 + rcu_read_lock();
84895 + read_lock(&tasklist_lock);
84896 + for (t = next_thread(current); t != current;
84897 + t = next_thread(t)) {
84898 + if (t->delayed_cred == NULL) {
84899 + t->delayed_cred = get_cred(new);
84900 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
84901 + set_tsk_need_resched(t);
84902 + }
84903 + }
84904 + read_unlock(&tasklist_lock);
84905 + rcu_read_unlock();
84906 + }
84907 + return ret;
84908 +#else
84909 + return __commit_creds(new);
84910 +#endif
84911 +}
84912 +
84913 EXPORT_SYMBOL(commit_creds);
84914
84915 /**
84916 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
84917 index 7d2f35e..1bafcd0 100644
84918 --- a/kernel/debug/debug_core.c
84919 +++ b/kernel/debug/debug_core.c
84920 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
84921 */
84922 static atomic_t masters_in_kgdb;
84923 static atomic_t slaves_in_kgdb;
84924 -static atomic_t kgdb_break_tasklet_var;
84925 +static atomic_unchecked_t kgdb_break_tasklet_var;
84926 atomic_t kgdb_setting_breakpoint;
84927
84928 struct task_struct *kgdb_usethread;
84929 @@ -133,7 +133,7 @@ int kgdb_single_step;
84930 static pid_t kgdb_sstep_pid;
84931
84932 /* to keep track of the CPU which is doing the single stepping*/
84933 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84934 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84935
84936 /*
84937 * If you are debugging a problem where roundup (the collection of
84938 @@ -541,7 +541,7 @@ return_normal:
84939 * kernel will only try for the value of sstep_tries before
84940 * giving up and continuing on.
84941 */
84942 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
84943 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
84944 (kgdb_info[cpu].task &&
84945 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
84946 atomic_set(&kgdb_active, -1);
84947 @@ -639,8 +639,8 @@ cpu_master_loop:
84948 }
84949
84950 kgdb_restore:
84951 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
84952 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
84953 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
84954 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
84955 if (kgdb_info[sstep_cpu].task)
84956 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
84957 else
84958 @@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
84959 static void kgdb_tasklet_bpt(unsigned long ing)
84960 {
84961 kgdb_breakpoint();
84962 - atomic_set(&kgdb_break_tasklet_var, 0);
84963 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
84964 }
84965
84966 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
84967
84968 void kgdb_schedule_breakpoint(void)
84969 {
84970 - if (atomic_read(&kgdb_break_tasklet_var) ||
84971 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
84972 atomic_read(&kgdb_active) != -1 ||
84973 atomic_read(&kgdb_setting_breakpoint))
84974 return;
84975 - atomic_inc(&kgdb_break_tasklet_var);
84976 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
84977 tasklet_schedule(&kgdb_tasklet_breakpoint);
84978 }
84979 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
84980 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
84981 index 0b097c8..11dd5c5 100644
84982 --- a/kernel/debug/kdb/kdb_main.c
84983 +++ b/kernel/debug/kdb/kdb_main.c
84984 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
84985 continue;
84986
84987 kdb_printf("%-20s%8u 0x%p ", mod->name,
84988 - mod->core_size, (void *)mod);
84989 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
84990 #ifdef CONFIG_MODULE_UNLOAD
84991 kdb_printf("%4ld ", module_refcount(mod));
84992 #endif
84993 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
84994 kdb_printf(" (Loading)");
84995 else
84996 kdb_printf(" (Live)");
84997 - kdb_printf(" 0x%p", mod->module_core);
84998 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
84999
85000 #ifdef CONFIG_MODULE_UNLOAD
85001 {
85002 diff --git a/kernel/events/core.c b/kernel/events/core.c
85003 index 6ed1163..f36346e 100644
85004 --- a/kernel/events/core.c
85005 +++ b/kernel/events/core.c
85006 @@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
85007 * 0 - disallow raw tracepoint access for unpriv
85008 * 1 - disallow cpu events for unpriv
85009 * 2 - disallow kernel profiling for unpriv
85010 + * 3 - disallow all unpriv perf event use
85011 */
85012 -int sysctl_perf_event_paranoid __read_mostly = 1;
85013 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85014 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85015 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85016 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85017 +#else
85018 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85019 +#endif
85020
85021 /* Minimum for 512 kiB + 1 user control page */
85022 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85023 @@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
85024
85025 tmp *= sysctl_perf_cpu_time_max_percent;
85026 do_div(tmp, 100);
85027 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85028 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85029 }
85030
85031 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85032 @@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85033 update_perf_cpu_limits();
85034 }
85035
85036 -static atomic64_t perf_event_id;
85037 +static atomic64_unchecked_t perf_event_id;
85038
85039 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85040 enum event_type_t event_type);
85041 @@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
85042
85043 static inline u64 perf_event_count(struct perf_event *event)
85044 {
85045 - return local64_read(&event->count) + atomic64_read(&event->child_count);
85046 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85047 }
85048
85049 static u64 perf_event_read(struct perf_event *event)
85050 @@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85051 mutex_lock(&event->child_mutex);
85052 total += perf_event_read(event);
85053 *enabled += event->total_time_enabled +
85054 - atomic64_read(&event->child_total_time_enabled);
85055 + atomic64_read_unchecked(&event->child_total_time_enabled);
85056 *running += event->total_time_running +
85057 - atomic64_read(&event->child_total_time_running);
85058 + atomic64_read_unchecked(&event->child_total_time_running);
85059
85060 list_for_each_entry(child, &event->child_list, child_list) {
85061 total += perf_event_read(child);
85062 @@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
85063 userpg->offset -= local64_read(&event->hw.prev_count);
85064
85065 userpg->time_enabled = enabled +
85066 - atomic64_read(&event->child_total_time_enabled);
85067 + atomic64_read_unchecked(&event->child_total_time_enabled);
85068
85069 userpg->time_running = running +
85070 - atomic64_read(&event->child_total_time_running);
85071 + atomic64_read_unchecked(&event->child_total_time_running);
85072
85073 arch_perf_update_userpage(userpg, now);
85074
85075 @@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85076
85077 /* Data. */
85078 sp = perf_user_stack_pointer(regs);
85079 - rem = __output_copy_user(handle, (void *) sp, dump_size);
85080 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85081 dyn_size = dump_size - rem;
85082
85083 perf_output_skip(handle, rem);
85084 @@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85085 values[n++] = perf_event_count(event);
85086 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85087 values[n++] = enabled +
85088 - atomic64_read(&event->child_total_time_enabled);
85089 + atomic64_read_unchecked(&event->child_total_time_enabled);
85090 }
85091 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85092 values[n++] = running +
85093 - atomic64_read(&event->child_total_time_running);
85094 + atomic64_read_unchecked(&event->child_total_time_running);
85095 }
85096 if (read_format & PERF_FORMAT_ID)
85097 values[n++] = primary_event_id(event);
85098 @@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85099 event->parent = parent_event;
85100
85101 event->ns = get_pid_ns(task_active_pid_ns(current));
85102 - event->id = atomic64_inc_return(&perf_event_id);
85103 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
85104
85105 event->state = PERF_EVENT_STATE_INACTIVE;
85106
85107 @@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
85108 if (flags & ~PERF_FLAG_ALL)
85109 return -EINVAL;
85110
85111 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85112 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85113 + return -EACCES;
85114 +#endif
85115 +
85116 err = perf_copy_attr(attr_uptr, &attr);
85117 if (err)
85118 return err;
85119 @@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
85120 /*
85121 * Add back the child's count to the parent's count:
85122 */
85123 - atomic64_add(child_val, &parent_event->child_count);
85124 - atomic64_add(child_event->total_time_enabled,
85125 + atomic64_add_unchecked(child_val, &parent_event->child_count);
85126 + atomic64_add_unchecked(child_event->total_time_enabled,
85127 &parent_event->child_total_time_enabled);
85128 - atomic64_add(child_event->total_time_running,
85129 + atomic64_add_unchecked(child_event->total_time_running,
85130 &parent_event->child_total_time_running);
85131
85132 /*
85133 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85134 index 569b2187..19940d9 100644
85135 --- a/kernel/events/internal.h
85136 +++ b/kernel/events/internal.h
85137 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85138 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85139 }
85140
85141 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85142 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85143 static inline unsigned long \
85144 func_name(struct perf_output_handle *handle, \
85145 - const void *buf, unsigned long len) \
85146 + const void user *buf, unsigned long len) \
85147 { \
85148 unsigned long size, written; \
85149 \
85150 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85151 return 0;
85152 }
85153
85154 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85155 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85156
85157 static inline unsigned long
85158 memcpy_skip(void *dst, const void *src, unsigned long n)
85159 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85160 return 0;
85161 }
85162
85163 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85164 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85165
85166 #ifndef arch_perf_out_copy_user
85167 #define arch_perf_out_copy_user arch_perf_out_copy_user
85168 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85169 }
85170 #endif
85171
85172 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85173 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85174
85175 /* Callchain handling */
85176 extern struct perf_callchain_entry *
85177 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85178 index 24b7d6c..40cf797 100644
85179 --- a/kernel/events/uprobes.c
85180 +++ b/kernel/events/uprobes.c
85181 @@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85182 {
85183 struct page *page;
85184 uprobe_opcode_t opcode;
85185 - int result;
85186 + long result;
85187
85188 pagefault_disable();
85189 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85190 diff --git a/kernel/exit.c b/kernel/exit.c
85191 index a949819..a5f127d 100644
85192 --- a/kernel/exit.c
85193 +++ b/kernel/exit.c
85194 @@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
85195 struct task_struct *leader;
85196 int zap_leader;
85197 repeat:
85198 +#ifdef CONFIG_NET
85199 + gr_del_task_from_ip_table(p);
85200 +#endif
85201 +
85202 /* don't need to get the RCU readlock here - the process is dead and
85203 * can't be modifying its own credentials. But shut RCU-lockdep up */
85204 rcu_read_lock();
85205 @@ -329,7 +333,7 @@ int allow_signal(int sig)
85206 * know it'll be handled, so that they don't get converted to
85207 * SIGKILL or just silently dropped.
85208 */
85209 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85210 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85211 recalc_sigpending();
85212 spin_unlock_irq(&current->sighand->siglock);
85213 return 0;
85214 @@ -698,6 +702,8 @@ void do_exit(long code)
85215 struct task_struct *tsk = current;
85216 int group_dead;
85217
85218 + set_fs(USER_DS);
85219 +
85220 profile_task_exit(tsk);
85221
85222 WARN_ON(blk_needs_flush_plug(tsk));
85223 @@ -714,7 +720,6 @@ void do_exit(long code)
85224 * mm_release()->clear_child_tid() from writing to a user-controlled
85225 * kernel address.
85226 */
85227 - set_fs(USER_DS);
85228
85229 ptrace_event(PTRACE_EVENT_EXIT, code);
85230
85231 @@ -773,6 +778,9 @@ void do_exit(long code)
85232 tsk->exit_code = code;
85233 taskstats_exit(tsk, group_dead);
85234
85235 + gr_acl_handle_psacct(tsk, code);
85236 + gr_acl_handle_exit();
85237 +
85238 exit_mm(tsk);
85239
85240 if (group_dead)
85241 @@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85242 * Take down every thread in the group. This is called by fatal signals
85243 * as well as by sys_exit_group (below).
85244 */
85245 -void
85246 +__noreturn void
85247 do_group_exit(int exit_code)
85248 {
85249 struct signal_struct *sig = current->signal;
85250 diff --git a/kernel/fork.c b/kernel/fork.c
85251 index dfa736c..d170f9b 100644
85252 --- a/kernel/fork.c
85253 +++ b/kernel/fork.c
85254 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85255 *stackend = STACK_END_MAGIC; /* for overflow detection */
85256
85257 #ifdef CONFIG_CC_STACKPROTECTOR
85258 - tsk->stack_canary = get_random_int();
85259 + tsk->stack_canary = pax_get_random_long();
85260 #endif
85261
85262 /*
85263 @@ -345,12 +345,80 @@ free_tsk:
85264 }
85265
85266 #ifdef CONFIG_MMU
85267 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85268 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85269 +{
85270 + struct vm_area_struct *tmp;
85271 + unsigned long charge;
85272 + struct file *file;
85273 + int retval;
85274 +
85275 + charge = 0;
85276 + if (mpnt->vm_flags & VM_ACCOUNT) {
85277 + unsigned long len = vma_pages(mpnt);
85278 +
85279 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85280 + goto fail_nomem;
85281 + charge = len;
85282 + }
85283 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85284 + if (!tmp)
85285 + goto fail_nomem;
85286 + *tmp = *mpnt;
85287 + tmp->vm_mm = mm;
85288 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
85289 + retval = vma_dup_policy(mpnt, tmp);
85290 + if (retval)
85291 + goto fail_nomem_policy;
85292 + if (anon_vma_fork(tmp, mpnt))
85293 + goto fail_nomem_anon_vma_fork;
85294 + tmp->vm_flags &= ~VM_LOCKED;
85295 + tmp->vm_next = tmp->vm_prev = NULL;
85296 + tmp->vm_mirror = NULL;
85297 + file = tmp->vm_file;
85298 + if (file) {
85299 + struct inode *inode = file_inode(file);
85300 + struct address_space *mapping = file->f_mapping;
85301 +
85302 + get_file(file);
85303 + if (tmp->vm_flags & VM_DENYWRITE)
85304 + atomic_dec(&inode->i_writecount);
85305 + mutex_lock(&mapping->i_mmap_mutex);
85306 + if (tmp->vm_flags & VM_SHARED)
85307 + mapping->i_mmap_writable++;
85308 + flush_dcache_mmap_lock(mapping);
85309 + /* insert tmp into the share list, just after mpnt */
85310 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85311 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85312 + else
85313 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85314 + flush_dcache_mmap_unlock(mapping);
85315 + mutex_unlock(&mapping->i_mmap_mutex);
85316 + }
85317 +
85318 + /*
85319 + * Clear hugetlb-related page reserves for children. This only
85320 + * affects MAP_PRIVATE mappings. Faults generated by the child
85321 + * are not guaranteed to succeed, even if read-only
85322 + */
85323 + if (is_vm_hugetlb_page(tmp))
85324 + reset_vma_resv_huge_pages(tmp);
85325 +
85326 + return tmp;
85327 +
85328 +fail_nomem_anon_vma_fork:
85329 + mpol_put(vma_policy(tmp));
85330 +fail_nomem_policy:
85331 + kmem_cache_free(vm_area_cachep, tmp);
85332 +fail_nomem:
85333 + vm_unacct_memory(charge);
85334 + return NULL;
85335 +}
85336 +
85337 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85338 {
85339 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85340 struct rb_node **rb_link, *rb_parent;
85341 int retval;
85342 - unsigned long charge;
85343
85344 uprobe_start_dup_mmap();
85345 down_write(&oldmm->mmap_sem);
85346 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85347
85348 prev = NULL;
85349 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85350 - struct file *file;
85351 -
85352 if (mpnt->vm_flags & VM_DONTCOPY) {
85353 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85354 -vma_pages(mpnt));
85355 continue;
85356 }
85357 - charge = 0;
85358 - if (mpnt->vm_flags & VM_ACCOUNT) {
85359 - unsigned long len = vma_pages(mpnt);
85360 -
85361 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85362 - goto fail_nomem;
85363 - charge = len;
85364 - }
85365 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85366 - if (!tmp)
85367 - goto fail_nomem;
85368 - *tmp = *mpnt;
85369 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
85370 - retval = vma_dup_policy(mpnt, tmp);
85371 - if (retval)
85372 - goto fail_nomem_policy;
85373 - tmp->vm_mm = mm;
85374 - if (anon_vma_fork(tmp, mpnt))
85375 - goto fail_nomem_anon_vma_fork;
85376 - tmp->vm_flags &= ~VM_LOCKED;
85377 - tmp->vm_next = tmp->vm_prev = NULL;
85378 - file = tmp->vm_file;
85379 - if (file) {
85380 - struct inode *inode = file_inode(file);
85381 - struct address_space *mapping = file->f_mapping;
85382 -
85383 - get_file(file);
85384 - if (tmp->vm_flags & VM_DENYWRITE)
85385 - atomic_dec(&inode->i_writecount);
85386 - mutex_lock(&mapping->i_mmap_mutex);
85387 - if (tmp->vm_flags & VM_SHARED)
85388 - mapping->i_mmap_writable++;
85389 - flush_dcache_mmap_lock(mapping);
85390 - /* insert tmp into the share list, just after mpnt */
85391 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85392 - vma_nonlinear_insert(tmp,
85393 - &mapping->i_mmap_nonlinear);
85394 - else
85395 - vma_interval_tree_insert_after(tmp, mpnt,
85396 - &mapping->i_mmap);
85397 - flush_dcache_mmap_unlock(mapping);
85398 - mutex_unlock(&mapping->i_mmap_mutex);
85399 + tmp = dup_vma(mm, oldmm, mpnt);
85400 + if (!tmp) {
85401 + retval = -ENOMEM;
85402 + goto out;
85403 }
85404
85405 /*
85406 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85407 if (retval)
85408 goto out;
85409 }
85410 +
85411 +#ifdef CONFIG_PAX_SEGMEXEC
85412 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85413 + struct vm_area_struct *mpnt_m;
85414 +
85415 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85416 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85417 +
85418 + if (!mpnt->vm_mirror)
85419 + continue;
85420 +
85421 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
85422 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
85423 + mpnt->vm_mirror = mpnt_m;
85424 + } else {
85425 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
85426 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
85427 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
85428 + mpnt->vm_mirror->vm_mirror = mpnt;
85429 + }
85430 + }
85431 + BUG_ON(mpnt_m);
85432 + }
85433 +#endif
85434 +
85435 /* a new mm has just been created */
85436 arch_dup_mmap(oldmm, mm);
85437 retval = 0;
85438 @@ -468,14 +521,6 @@ out:
85439 up_write(&oldmm->mmap_sem);
85440 uprobe_end_dup_mmap();
85441 return retval;
85442 -fail_nomem_anon_vma_fork:
85443 - mpol_put(vma_policy(tmp));
85444 -fail_nomem_policy:
85445 - kmem_cache_free(vm_area_cachep, tmp);
85446 -fail_nomem:
85447 - retval = -ENOMEM;
85448 - vm_unacct_memory(charge);
85449 - goto out;
85450 }
85451
85452 static inline int mm_alloc_pgd(struct mm_struct *mm)
85453 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
85454 return ERR_PTR(err);
85455
85456 mm = get_task_mm(task);
85457 - if (mm && mm != current->mm &&
85458 - !ptrace_may_access(task, mode)) {
85459 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
85460 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
85461 mmput(mm);
85462 mm = ERR_PTR(-EACCES);
85463 }
85464 @@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
85465 spin_unlock(&fs->lock);
85466 return -EAGAIN;
85467 }
85468 - fs->users++;
85469 + atomic_inc(&fs->users);
85470 spin_unlock(&fs->lock);
85471 return 0;
85472 }
85473 tsk->fs = copy_fs_struct(fs);
85474 if (!tsk->fs)
85475 return -ENOMEM;
85476 + /* Carry through gr_chroot_dentry and is_chrooted instead
85477 + of recomputing it here. Already copied when the task struct
85478 + is duplicated. This allows pivot_root to not be treated as
85479 + a chroot
85480 + */
85481 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
85482 +
85483 return 0;
85484 }
85485
85486 @@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
85487 * parts of the process environment (as per the clone
85488 * flags). The actual kick-off is left to the caller.
85489 */
85490 -static struct task_struct *copy_process(unsigned long clone_flags,
85491 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
85492 unsigned long stack_start,
85493 unsigned long stack_size,
85494 int __user *child_tidptr,
85495 @@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85496 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
85497 #endif
85498 retval = -EAGAIN;
85499 +
85500 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
85501 +
85502 if (atomic_read(&p->real_cred->user->processes) >=
85503 task_rlimit(p, RLIMIT_NPROC)) {
85504 if (p->real_cred->user != INIT_USER &&
85505 @@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85506 goto bad_fork_free_pid;
85507 }
85508
85509 + /* synchronizes with gr_set_acls()
85510 + we need to call this past the point of no return for fork()
85511 + */
85512 + gr_copy_label(p);
85513 +
85514 if (likely(p->pid)) {
85515 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
85516
85517 @@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
85518 bad_fork_free:
85519 free_task(p);
85520 fork_out:
85521 + gr_log_forkfail(retval);
85522 +
85523 return ERR_PTR(retval);
85524 }
85525
85526 @@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
85527
85528 p = copy_process(clone_flags, stack_start, stack_size,
85529 child_tidptr, NULL, trace);
85530 + add_latent_entropy();
85531 /*
85532 * Do this prior waking up the new thread - the thread pointer
85533 * might get invalid after that point, if the thread exits quickly.
85534 @@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
85535 if (clone_flags & CLONE_PARENT_SETTID)
85536 put_user(nr, parent_tidptr);
85537
85538 + gr_handle_brute_check();
85539 +
85540 if (clone_flags & CLONE_VFORK) {
85541 p->vfork_done = &vfork;
85542 init_completion(&vfork);
85543 @@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
85544 mm_cachep = kmem_cache_create("mm_struct",
85545 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
85546 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
85547 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
85548 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
85549 mmap_init();
85550 nsproxy_cache_init();
85551 }
85552 @@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
85553 return 0;
85554
85555 /* don't need lock here; in the worst case we'll do useless copy */
85556 - if (fs->users == 1)
85557 + if (atomic_read(&fs->users) == 1)
85558 return 0;
85559
85560 *new_fsp = copy_fs_struct(fs);
85561 @@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
85562 fs = current->fs;
85563 spin_lock(&fs->lock);
85564 current->fs = new_fs;
85565 - if (--fs->users)
85566 + gr_set_chroot_entries(current, &current->fs->root);
85567 + if (atomic_dec_return(&fs->users))
85568 new_fs = NULL;
85569 else
85570 new_fs = fs;
85571 diff --git a/kernel/futex.c b/kernel/futex.c
85572 index f6ff019..ac53307 100644
85573 --- a/kernel/futex.c
85574 +++ b/kernel/futex.c
85575 @@ -54,6 +54,7 @@
85576 #include <linux/mount.h>
85577 #include <linux/pagemap.h>
85578 #include <linux/syscalls.h>
85579 +#include <linux/ptrace.h>
85580 #include <linux/signal.h>
85581 #include <linux/export.h>
85582 #include <linux/magic.h>
85583 @@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
85584 struct page *page, *page_head;
85585 int err, ro = 0;
85586
85587 +#ifdef CONFIG_PAX_SEGMEXEC
85588 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
85589 + return -EFAULT;
85590 +#endif
85591 +
85592 /*
85593 * The futex address must be "naturally" aligned.
85594 */
85595 @@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
85596
85597 static int get_futex_value_locked(u32 *dest, u32 __user *from)
85598 {
85599 - int ret;
85600 + unsigned long ret;
85601
85602 pagefault_disable();
85603 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
85604 @@ -2735,6 +2741,7 @@ static int __init futex_init(void)
85605 {
85606 u32 curval;
85607 int i;
85608 + mm_segment_t oldfs;
85609
85610 /*
85611 * This will fail and we want it. Some arch implementations do
85612 @@ -2746,8 +2753,11 @@ static int __init futex_init(void)
85613 * implementation, the non-functional ones will return
85614 * -ENOSYS.
85615 */
85616 + oldfs = get_fs();
85617 + set_fs(USER_DS);
85618 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
85619 futex_cmpxchg_enabled = 1;
85620 + set_fs(oldfs);
85621
85622 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
85623 plist_head_init(&futex_queues[i].chain);
85624 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
85625 index f9f44fd..29885e4 100644
85626 --- a/kernel/futex_compat.c
85627 +++ b/kernel/futex_compat.c
85628 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
85629 return 0;
85630 }
85631
85632 -static void __user *futex_uaddr(struct robust_list __user *entry,
85633 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
85634 compat_long_t futex_offset)
85635 {
85636 compat_uptr_t base = ptr_to_compat(entry);
85637 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
85638 index f45b75b..bfac6d5 100644
85639 --- a/kernel/gcov/base.c
85640 +++ b/kernel/gcov/base.c
85641 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
85642 }
85643
85644 #ifdef CONFIG_MODULES
85645 -static inline int within(void *addr, void *start, unsigned long size)
85646 -{
85647 - return ((addr >= start) && (addr < start + size));
85648 -}
85649 -
85650 /* Update list and generate events when modules are unloaded. */
85651 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85652 void *data)
85653 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85654
85655 /* Remove entries located in module from linked list. */
85656 while ((info = gcov_info_next(info))) {
85657 - if (within(info, mod->module_core, mod->core_size)) {
85658 + if (within_module_core_rw((unsigned long)info, mod)) {
85659 gcov_info_unlink(prev, info);
85660 if (gcov_events_enabled)
85661 gcov_event(GCOV_REMOVE, info);
85662 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
85663 index 383319b..56ebb13 100644
85664 --- a/kernel/hrtimer.c
85665 +++ b/kernel/hrtimer.c
85666 @@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
85667 local_irq_restore(flags);
85668 }
85669
85670 -static void run_hrtimer_softirq(struct softirq_action *h)
85671 +static __latent_entropy void run_hrtimer_softirq(void)
85672 {
85673 hrtimer_peek_ahead_timers();
85674 }
85675 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
85676 index 55fcce6..0e4cf34 100644
85677 --- a/kernel/irq_work.c
85678 +++ b/kernel/irq_work.c
85679 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
85680 return NOTIFY_OK;
85681 }
85682
85683 -static struct notifier_block cpu_notify;
85684 +static struct notifier_block cpu_notify = {
85685 + .notifier_call = irq_work_cpu_notify,
85686 + .priority = 0,
85687 +};
85688
85689 static __init int irq_work_init_cpu_notifier(void)
85690 {
85691 - cpu_notify.notifier_call = irq_work_cpu_notify;
85692 - cpu_notify.priority = 0;
85693 register_cpu_notifier(&cpu_notify);
85694 return 0;
85695 }
85696 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
85697 index 9019f15..9a3c42e 100644
85698 --- a/kernel/jump_label.c
85699 +++ b/kernel/jump_label.c
85700 @@ -14,6 +14,7 @@
85701 #include <linux/err.h>
85702 #include <linux/static_key.h>
85703 #include <linux/jump_label_ratelimit.h>
85704 +#include <linux/mm.h>
85705
85706 #ifdef HAVE_JUMP_LABEL
85707
85708 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
85709
85710 size = (((unsigned long)stop - (unsigned long)start)
85711 / sizeof(struct jump_entry));
85712 + pax_open_kernel();
85713 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
85714 + pax_close_kernel();
85715 }
85716
85717 static void jump_label_update(struct static_key *key, int enable);
85718 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
85719 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
85720 struct jump_entry *iter;
85721
85722 + pax_open_kernel();
85723 for (iter = iter_start; iter < iter_stop; iter++) {
85724 if (within_module_init(iter->code, mod))
85725 iter->code = 0;
85726 }
85727 + pax_close_kernel();
85728 }
85729
85730 static int
85731 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
85732 index 3127ad5..159d880 100644
85733 --- a/kernel/kallsyms.c
85734 +++ b/kernel/kallsyms.c
85735 @@ -11,6 +11,9 @@
85736 * Changed the compression method from stem compression to "table lookup"
85737 * compression (see scripts/kallsyms.c for a more complete description)
85738 */
85739 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85740 +#define __INCLUDED_BY_HIDESYM 1
85741 +#endif
85742 #include <linux/kallsyms.h>
85743 #include <linux/module.h>
85744 #include <linux/init.h>
85745 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
85746
85747 static inline int is_kernel_inittext(unsigned long addr)
85748 {
85749 + if (system_state != SYSTEM_BOOTING)
85750 + return 0;
85751 +
85752 if (addr >= (unsigned long)_sinittext
85753 && addr <= (unsigned long)_einittext)
85754 return 1;
85755 return 0;
85756 }
85757
85758 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85759 +#ifdef CONFIG_MODULES
85760 +static inline int is_module_text(unsigned long addr)
85761 +{
85762 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
85763 + return 1;
85764 +
85765 + addr = ktla_ktva(addr);
85766 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
85767 +}
85768 +#else
85769 +static inline int is_module_text(unsigned long addr)
85770 +{
85771 + return 0;
85772 +}
85773 +#endif
85774 +#endif
85775 +
85776 static inline int is_kernel_text(unsigned long addr)
85777 {
85778 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
85779 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
85780
85781 static inline int is_kernel(unsigned long addr)
85782 {
85783 +
85784 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85785 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
85786 + return 1;
85787 +
85788 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
85789 +#else
85790 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
85791 +#endif
85792 +
85793 return 1;
85794 return in_gate_area_no_mm(addr);
85795 }
85796
85797 static int is_ksym_addr(unsigned long addr)
85798 {
85799 +
85800 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85801 + if (is_module_text(addr))
85802 + return 0;
85803 +#endif
85804 +
85805 if (all_var)
85806 return is_kernel(addr);
85807
85808 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
85809
85810 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
85811 {
85812 - iter->name[0] = '\0';
85813 iter->nameoff = get_symbol_offset(new_pos);
85814 iter->pos = new_pos;
85815 }
85816 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
85817 {
85818 struct kallsym_iter *iter = m->private;
85819
85820 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85821 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
85822 + return 0;
85823 +#endif
85824 +
85825 /* Some debugging symbols have no name. Ignore them. */
85826 if (!iter->name[0])
85827 return 0;
85828 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
85829 */
85830 type = iter->exported ? toupper(iter->type) :
85831 tolower(iter->type);
85832 +
85833 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
85834 type, iter->name, iter->module_name);
85835 } else
85836 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
85837 struct kallsym_iter *iter;
85838 int ret;
85839
85840 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
85841 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
85842 if (!iter)
85843 return -ENOMEM;
85844 reset_iter(iter, 0);
85845 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
85846 index e30ac0f..3528cac 100644
85847 --- a/kernel/kcmp.c
85848 +++ b/kernel/kcmp.c
85849 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
85850 struct task_struct *task1, *task2;
85851 int ret;
85852
85853 +#ifdef CONFIG_GRKERNSEC
85854 + return -ENOSYS;
85855 +#endif
85856 +
85857 rcu_read_lock();
85858
85859 /*
85860 diff --git a/kernel/kexec.c b/kernel/kexec.c
85861 index 9c97016..df438f8 100644
85862 --- a/kernel/kexec.c
85863 +++ b/kernel/kexec.c
85864 @@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
85865 unsigned long flags)
85866 {
85867 struct compat_kexec_segment in;
85868 - struct kexec_segment out, __user *ksegments;
85869 + struct kexec_segment out;
85870 + struct kexec_segment __user *ksegments;
85871 unsigned long i, result;
85872
85873 /* Don't allow clients that don't understand the native
85874 diff --git a/kernel/kmod.c b/kernel/kmod.c
85875 index b086006..b66f630 100644
85876 --- a/kernel/kmod.c
85877 +++ b/kernel/kmod.c
85878 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
85879 kfree(info->argv);
85880 }
85881
85882 -static int call_modprobe(char *module_name, int wait)
85883 +static int call_modprobe(char *module_name, char *module_param, int wait)
85884 {
85885 struct subprocess_info *info;
85886 static char *envp[] = {
85887 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
85888 NULL
85889 };
85890
85891 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
85892 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
85893 if (!argv)
85894 goto out;
85895
85896 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
85897 argv[1] = "-q";
85898 argv[2] = "--";
85899 argv[3] = module_name; /* check free_modprobe_argv() */
85900 - argv[4] = NULL;
85901 + argv[4] = module_param;
85902 + argv[5] = NULL;
85903
85904 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
85905 NULL, free_modprobe_argv, NULL);
85906 @@ -129,9 +130,8 @@ out:
85907 * If module auto-loading support is disabled then this function
85908 * becomes a no-operation.
85909 */
85910 -int __request_module(bool wait, const char *fmt, ...)
85911 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
85912 {
85913 - va_list args;
85914 char module_name[MODULE_NAME_LEN];
85915 unsigned int max_modprobes;
85916 int ret;
85917 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
85918 if (!modprobe_path[0])
85919 return 0;
85920
85921 - va_start(args, fmt);
85922 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
85923 - va_end(args);
85924 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
85925 if (ret >= MODULE_NAME_LEN)
85926 return -ENAMETOOLONG;
85927
85928 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
85929 if (ret)
85930 return ret;
85931
85932 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85933 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85934 + /* hack to workaround consolekit/udisks stupidity */
85935 + read_lock(&tasklist_lock);
85936 + if (!strcmp(current->comm, "mount") &&
85937 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
85938 + read_unlock(&tasklist_lock);
85939 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
85940 + return -EPERM;
85941 + }
85942 + read_unlock(&tasklist_lock);
85943 + }
85944 +#endif
85945 +
85946 /* If modprobe needs a service that is in a module, we get a recursive
85947 * loop. Limit the number of running kmod threads to max_threads/2 or
85948 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
85949 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
85950
85951 trace_module_request(module_name, wait, _RET_IP_);
85952
85953 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85954 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85955
85956 atomic_dec(&kmod_concurrent);
85957 return ret;
85958 }
85959 +
85960 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
85961 +{
85962 + va_list args;
85963 + int ret;
85964 +
85965 + va_start(args, fmt);
85966 + ret = ____request_module(wait, module_param, fmt, args);
85967 + va_end(args);
85968 +
85969 + return ret;
85970 +}
85971 +
85972 +int __request_module(bool wait, const char *fmt, ...)
85973 +{
85974 + va_list args;
85975 + int ret;
85976 +
85977 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85978 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85979 + char module_param[MODULE_NAME_LEN];
85980 +
85981 + memset(module_param, 0, sizeof(module_param));
85982 +
85983 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
85984 +
85985 + va_start(args, fmt);
85986 + ret = ____request_module(wait, module_param, fmt, args);
85987 + va_end(args);
85988 +
85989 + return ret;
85990 + }
85991 +#endif
85992 +
85993 + va_start(args, fmt);
85994 + ret = ____request_module(wait, NULL, fmt, args);
85995 + va_end(args);
85996 +
85997 + return ret;
85998 +}
85999 +
86000 EXPORT_SYMBOL(__request_module);
86001 #endif /* CONFIG_MODULES */
86002
86003 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86004 */
86005 set_user_nice(current, 0);
86006
86007 +#ifdef CONFIG_GRKERNSEC
86008 + /* this is race-free as far as userland is concerned as we copied
86009 + out the path to be used prior to this point and are now operating
86010 + on that copy
86011 + */
86012 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86013 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86014 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86015 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86016 + retval = -EPERM;
86017 + goto fail;
86018 + }
86019 +#endif
86020 +
86021 retval = -ENOMEM;
86022 new = prepare_kernel_cred(current);
86023 if (!new)
86024 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86025 commit_creds(new);
86026
86027 retval = do_execve(sub_info->path,
86028 - (const char __user *const __user *)sub_info->argv,
86029 - (const char __user *const __user *)sub_info->envp);
86030 + (const char __user *const __force_user *)sub_info->argv,
86031 + (const char __user *const __force_user *)sub_info->envp);
86032 if (!retval)
86033 return 0;
86034
86035 @@ -260,6 +327,10 @@ static int call_helper(void *data)
86036
86037 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86038 {
86039 +#ifdef CONFIG_GRKERNSEC
86040 + kfree(info->path);
86041 + info->path = info->origpath;
86042 +#endif
86043 if (info->cleanup)
86044 (*info->cleanup)(info);
86045 kfree(info);
86046 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86047 *
86048 * Thus the __user pointer cast is valid here.
86049 */
86050 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
86051 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86052
86053 /*
86054 * If ret is 0, either ____call_usermodehelper failed and the
86055 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86056 goto out;
86057
86058 INIT_WORK(&sub_info->work, __call_usermodehelper);
86059 +#ifdef CONFIG_GRKERNSEC
86060 + sub_info->origpath = path;
86061 + sub_info->path = kstrdup(path, gfp_mask);
86062 +#else
86063 sub_info->path = path;
86064 +#endif
86065 sub_info->argv = argv;
86066 sub_info->envp = envp;
86067
86068 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86069 static int proc_cap_handler(struct ctl_table *table, int write,
86070 void __user *buffer, size_t *lenp, loff_t *ppos)
86071 {
86072 - struct ctl_table t;
86073 + ctl_table_no_const t;
86074 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86075 kernel_cap_t new_cap;
86076 int err, i;
86077 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86078 index ceeadfc..11c18b6 100644
86079 --- a/kernel/kprobes.c
86080 +++ b/kernel/kprobes.c
86081 @@ -31,6 +31,9 @@
86082 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86083 * <prasanna@in.ibm.com> added function-return probes.
86084 */
86085 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86086 +#define __INCLUDED_BY_HIDESYM 1
86087 +#endif
86088 #include <linux/kprobes.h>
86089 #include <linux/hash.h>
86090 #include <linux/init.h>
86091 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
86092
86093 static void *alloc_insn_page(void)
86094 {
86095 - return module_alloc(PAGE_SIZE);
86096 + return module_alloc_exec(PAGE_SIZE);
86097 }
86098
86099 static void free_insn_page(void *page)
86100 {
86101 - module_free(NULL, page);
86102 + module_free_exec(NULL, page);
86103 }
86104
86105 struct kprobe_insn_cache kprobe_insn_slots = {
86106 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86107 kprobe_type = "k";
86108
86109 if (sym)
86110 - seq_printf(pi, "%p %s %s+0x%x %s ",
86111 + seq_printf(pi, "%pK %s %s+0x%x %s ",
86112 p->addr, kprobe_type, sym, offset,
86113 (modname ? modname : " "));
86114 else
86115 - seq_printf(pi, "%p %s %p ",
86116 + seq_printf(pi, "%pK %s %pK ",
86117 p->addr, kprobe_type, p->addr);
86118
86119 if (!pp)
86120 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86121 index 9659d38..bffd520 100644
86122 --- a/kernel/ksysfs.c
86123 +++ b/kernel/ksysfs.c
86124 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86125 {
86126 if (count+1 > UEVENT_HELPER_PATH_LEN)
86127 return -ENOENT;
86128 + if (!capable(CAP_SYS_ADMIN))
86129 + return -EPERM;
86130 memcpy(uevent_helper, buf, count);
86131 uevent_helper[count] = '\0';
86132 if (count && uevent_helper[count-1] == '\n')
86133 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86134 return count;
86135 }
86136
86137 -static struct bin_attribute notes_attr = {
86138 +static bin_attribute_no_const notes_attr __read_only = {
86139 .attr = {
86140 .name = "notes",
86141 .mode = S_IRUGO,
86142 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86143 index 576ba75..7c256e4 100644
86144 --- a/kernel/locking/lockdep.c
86145 +++ b/kernel/locking/lockdep.c
86146 @@ -596,6 +596,10 @@ static int static_obj(void *obj)
86147 end = (unsigned long) &_end,
86148 addr = (unsigned long) obj;
86149
86150 +#ifdef CONFIG_PAX_KERNEXEC
86151 + start = ktla_ktva(start);
86152 +#endif
86153 +
86154 /*
86155 * static variable?
86156 */
86157 @@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86158 if (!static_obj(lock->key)) {
86159 debug_locks_off();
86160 printk("INFO: trying to register non-static key.\n");
86161 + printk("lock:%pS key:%pS.\n", lock, lock->key);
86162 printk("the code is fine but needs lockdep annotation.\n");
86163 printk("turning off the locking correctness validator.\n");
86164 dump_stack();
86165 @@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86166 if (!class)
86167 return 0;
86168 }
86169 - atomic_inc((atomic_t *)&class->ops);
86170 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86171 if (very_verbose(class)) {
86172 printk("\nacquire class [%p] %s", class->key, class->name);
86173 if (class->name_version > 1)
86174 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86175 index ef43ac4..2720dfa 100644
86176 --- a/kernel/locking/lockdep_proc.c
86177 +++ b/kernel/locking/lockdep_proc.c
86178 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86179 return 0;
86180 }
86181
86182 - seq_printf(m, "%p", class->key);
86183 + seq_printf(m, "%pK", class->key);
86184 #ifdef CONFIG_DEBUG_LOCKDEP
86185 seq_printf(m, " OPS:%8ld", class->ops);
86186 #endif
86187 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86188
86189 list_for_each_entry(entry, &class->locks_after, entry) {
86190 if (entry->distance == 1) {
86191 - seq_printf(m, " -> [%p] ", entry->class->key);
86192 + seq_printf(m, " -> [%pK] ", entry->class->key);
86193 print_name(m, entry->class);
86194 seq_puts(m, "\n");
86195 }
86196 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86197 if (!class->key)
86198 continue;
86199
86200 - seq_printf(m, "[%p] ", class->key);
86201 + seq_printf(m, "[%pK] ", class->key);
86202 print_name(m, class);
86203 seq_puts(m, "\n");
86204 }
86205 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86206 if (!i)
86207 seq_line(m, '-', 40-namelen, namelen);
86208
86209 - snprintf(ip, sizeof(ip), "[<%p>]",
86210 + snprintf(ip, sizeof(ip), "[<%pK>]",
86211 (void *)class->contention_point[i]);
86212 seq_printf(m, "%40s %14lu %29s %pS\n",
86213 name, stats->contention_point[i],
86214 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86215 if (!i)
86216 seq_line(m, '-', 40-namelen, namelen);
86217
86218 - snprintf(ip, sizeof(ip), "[<%p>]",
86219 + snprintf(ip, sizeof(ip), "[<%pK>]",
86220 (void *)class->contending_point[i]);
86221 seq_printf(m, "%40s %14lu %29s %pS\n",
86222 name, stats->contending_point[i],
86223 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86224 index 7e3443f..b2a1e6b 100644
86225 --- a/kernel/locking/mutex-debug.c
86226 +++ b/kernel/locking/mutex-debug.c
86227 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86228 }
86229
86230 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86231 - struct thread_info *ti)
86232 + struct task_struct *task)
86233 {
86234 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86235
86236 /* Mark the current thread as blocked on the lock: */
86237 - ti->task->blocked_on = waiter;
86238 + task->blocked_on = waiter;
86239 }
86240
86241 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86242 - struct thread_info *ti)
86243 + struct task_struct *task)
86244 {
86245 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86246 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86247 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86248 - ti->task->blocked_on = NULL;
86249 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
86250 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86251 + task->blocked_on = NULL;
86252
86253 list_del_init(&waiter->list);
86254 waiter->task = NULL;
86255 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86256 index 0799fd3..d06ae3b 100644
86257 --- a/kernel/locking/mutex-debug.h
86258 +++ b/kernel/locking/mutex-debug.h
86259 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86260 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86261 extern void debug_mutex_add_waiter(struct mutex *lock,
86262 struct mutex_waiter *waiter,
86263 - struct thread_info *ti);
86264 + struct task_struct *task);
86265 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86266 - struct thread_info *ti);
86267 + struct task_struct *task);
86268 extern void debug_mutex_unlock(struct mutex *lock);
86269 extern void debug_mutex_init(struct mutex *lock, const char *name,
86270 struct lock_class_key *key);
86271 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86272 index 4dd6e4c..df52693 100644
86273 --- a/kernel/locking/mutex.c
86274 +++ b/kernel/locking/mutex.c
86275 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86276 node->locked = 1;
86277 return;
86278 }
86279 - ACCESS_ONCE(prev->next) = node;
86280 + ACCESS_ONCE_RW(prev->next) = node;
86281 smp_wmb();
86282 /* Wait until the lock holder passes the lock down */
86283 while (!ACCESS_ONCE(node->locked))
86284 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86285 while (!(next = ACCESS_ONCE(node->next)))
86286 arch_mutex_cpu_relax();
86287 }
86288 - ACCESS_ONCE(next->locked) = 1;
86289 + ACCESS_ONCE_RW(next->locked) = 1;
86290 smp_wmb();
86291 }
86292
86293 @@ -520,7 +520,7 @@ slowpath:
86294 goto skip_wait;
86295
86296 debug_mutex_lock_common(lock, &waiter);
86297 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86298 + debug_mutex_add_waiter(lock, &waiter, task);
86299
86300 /* add waiting tasks to the end of the waitqueue (FIFO): */
86301 list_add_tail(&waiter.list, &lock->wait_list);
86302 @@ -564,7 +564,7 @@ slowpath:
86303 schedule_preempt_disabled();
86304 spin_lock_mutex(&lock->wait_lock, flags);
86305 }
86306 - mutex_remove_waiter(lock, &waiter, current_thread_info());
86307 + mutex_remove_waiter(lock, &waiter, task);
86308 /* set it to 0 if there are no waiters left: */
86309 if (likely(list_empty(&lock->wait_list)))
86310 atomic_set(&lock->count, 0);
86311 @@ -601,7 +601,7 @@ skip_wait:
86312 return 0;
86313
86314 err:
86315 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86316 + mutex_remove_waiter(lock, &waiter, task);
86317 spin_unlock_mutex(&lock->wait_lock, flags);
86318 debug_mutex_free_waiter(&waiter);
86319 mutex_release(&lock->dep_map, 1, ip);
86320 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86321 index 1d96dd0..994ff19 100644
86322 --- a/kernel/locking/rtmutex-tester.c
86323 +++ b/kernel/locking/rtmutex-tester.c
86324 @@ -22,7 +22,7 @@
86325 #define MAX_RT_TEST_MUTEXES 8
86326
86327 static spinlock_t rttest_lock;
86328 -static atomic_t rttest_event;
86329 +static atomic_unchecked_t rttest_event;
86330
86331 struct test_thread_data {
86332 int opcode;
86333 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86334
86335 case RTTEST_LOCKCONT:
86336 td->mutexes[td->opdata] = 1;
86337 - td->event = atomic_add_return(1, &rttest_event);
86338 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86339 return 0;
86340
86341 case RTTEST_RESET:
86342 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86343 return 0;
86344
86345 case RTTEST_RESETEVENT:
86346 - atomic_set(&rttest_event, 0);
86347 + atomic_set_unchecked(&rttest_event, 0);
86348 return 0;
86349
86350 default:
86351 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86352 return ret;
86353
86354 td->mutexes[id] = 1;
86355 - td->event = atomic_add_return(1, &rttest_event);
86356 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86357 rt_mutex_lock(&mutexes[id]);
86358 - td->event = atomic_add_return(1, &rttest_event);
86359 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86360 td->mutexes[id] = 4;
86361 return 0;
86362
86363 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86364 return ret;
86365
86366 td->mutexes[id] = 1;
86367 - td->event = atomic_add_return(1, &rttest_event);
86368 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86369 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86370 - td->event = atomic_add_return(1, &rttest_event);
86371 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86372 td->mutexes[id] = ret ? 0 : 4;
86373 return ret ? -EINTR : 0;
86374
86375 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86376 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86377 return ret;
86378
86379 - td->event = atomic_add_return(1, &rttest_event);
86380 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86381 rt_mutex_unlock(&mutexes[id]);
86382 - td->event = atomic_add_return(1, &rttest_event);
86383 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86384 td->mutexes[id] = 0;
86385 return 0;
86386
86387 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86388 break;
86389
86390 td->mutexes[dat] = 2;
86391 - td->event = atomic_add_return(1, &rttest_event);
86392 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86393 break;
86394
86395 default:
86396 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86397 return;
86398
86399 td->mutexes[dat] = 3;
86400 - td->event = atomic_add_return(1, &rttest_event);
86401 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86402 break;
86403
86404 case RTTEST_LOCKNOWAIT:
86405 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86406 return;
86407
86408 td->mutexes[dat] = 1;
86409 - td->event = atomic_add_return(1, &rttest_event);
86410 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86411 return;
86412
86413 default:
86414 diff --git a/kernel/module.c b/kernel/module.c
86415 index f5a3b1e..97ebb15 100644
86416 --- a/kernel/module.c
86417 +++ b/kernel/module.c
86418 @@ -61,6 +61,7 @@
86419 #include <linux/pfn.h>
86420 #include <linux/bsearch.h>
86421 #include <linux/fips.h>
86422 +#include <linux/grsecurity.h>
86423 #include <uapi/linux/module.h>
86424 #include "module-internal.h"
86425
86426 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
86427
86428 /* Bounds of module allocation, for speeding __module_address.
86429 * Protected by module_mutex. */
86430 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
86431 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
86432 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
86433
86434 int register_module_notifier(struct notifier_block * nb)
86435 {
86436 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86437 return true;
86438
86439 list_for_each_entry_rcu(mod, &modules, list) {
86440 - struct symsearch arr[] = {
86441 + struct symsearch modarr[] = {
86442 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
86443 NOT_GPL_ONLY, false },
86444 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
86445 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86446 if (mod->state == MODULE_STATE_UNFORMED)
86447 continue;
86448
86449 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
86450 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
86451 return true;
86452 }
86453 return false;
86454 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
86455 if (!pcpusec->sh_size)
86456 return 0;
86457
86458 - if (align > PAGE_SIZE) {
86459 + if (align-1 >= PAGE_SIZE) {
86460 pr_warn("%s: per-cpu alignment %li > %li\n",
86461 mod->name, align, PAGE_SIZE);
86462 align = PAGE_SIZE;
86463 @@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
86464 static ssize_t show_coresize(struct module_attribute *mattr,
86465 struct module_kobject *mk, char *buffer)
86466 {
86467 - return sprintf(buffer, "%u\n", mk->mod->core_size);
86468 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
86469 }
86470
86471 static struct module_attribute modinfo_coresize =
86472 @@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
86473 static ssize_t show_initsize(struct module_attribute *mattr,
86474 struct module_kobject *mk, char *buffer)
86475 {
86476 - return sprintf(buffer, "%u\n", mk->mod->init_size);
86477 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
86478 }
86479
86480 static struct module_attribute modinfo_initsize =
86481 @@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
86482 goto bad_version;
86483 }
86484
86485 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86486 + /*
86487 + * avoid potentially printing jibberish on attempted load
86488 + * of a module randomized with a different seed
86489 + */
86490 + pr_warn("no symbol version for %s\n", symname);
86491 +#else
86492 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
86493 +#endif
86494 return 0;
86495
86496 bad_version:
86497 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86498 + /*
86499 + * avoid potentially printing jibberish on attempted load
86500 + * of a module randomized with a different seed
86501 + */
86502 + printk("attempted module disagrees about version of symbol %s\n",
86503 + symname);
86504 +#else
86505 printk("%s: disagrees about version of symbol %s\n",
86506 mod->name, symname);
86507 +#endif
86508 return 0;
86509 }
86510
86511 @@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
86512 */
86513 #ifdef CONFIG_SYSFS
86514
86515 -#ifdef CONFIG_KALLSYMS
86516 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
86517 static inline bool sect_empty(const Elf_Shdr *sect)
86518 {
86519 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
86520 @@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
86521 {
86522 unsigned int notes, loaded, i;
86523 struct module_notes_attrs *notes_attrs;
86524 - struct bin_attribute *nattr;
86525 + bin_attribute_no_const *nattr;
86526
86527 /* failed to create section attributes, so can't create notes */
86528 if (!mod->sect_attrs)
86529 @@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
86530 static int module_add_modinfo_attrs(struct module *mod)
86531 {
86532 struct module_attribute *attr;
86533 - struct module_attribute *temp_attr;
86534 + module_attribute_no_const *temp_attr;
86535 int error = 0;
86536 int i;
86537
86538 @@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
86539
86540 static void unset_module_core_ro_nx(struct module *mod)
86541 {
86542 - set_page_attributes(mod->module_core + mod->core_text_size,
86543 - mod->module_core + mod->core_size,
86544 + set_page_attributes(mod->module_core_rw,
86545 + mod->module_core_rw + mod->core_size_rw,
86546 set_memory_x);
86547 - set_page_attributes(mod->module_core,
86548 - mod->module_core + mod->core_ro_size,
86549 + set_page_attributes(mod->module_core_rx,
86550 + mod->module_core_rx + mod->core_size_rx,
86551 set_memory_rw);
86552 }
86553
86554 static void unset_module_init_ro_nx(struct module *mod)
86555 {
86556 - set_page_attributes(mod->module_init + mod->init_text_size,
86557 - mod->module_init + mod->init_size,
86558 + set_page_attributes(mod->module_init_rw,
86559 + mod->module_init_rw + mod->init_size_rw,
86560 set_memory_x);
86561 - set_page_attributes(mod->module_init,
86562 - mod->module_init + mod->init_ro_size,
86563 + set_page_attributes(mod->module_init_rx,
86564 + mod->module_init_rx + mod->init_size_rx,
86565 set_memory_rw);
86566 }
86567
86568 @@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
86569 list_for_each_entry_rcu(mod, &modules, list) {
86570 if (mod->state == MODULE_STATE_UNFORMED)
86571 continue;
86572 - if ((mod->module_core) && (mod->core_text_size)) {
86573 - set_page_attributes(mod->module_core,
86574 - mod->module_core + mod->core_text_size,
86575 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86576 + set_page_attributes(mod->module_core_rx,
86577 + mod->module_core_rx + mod->core_size_rx,
86578 set_memory_rw);
86579 }
86580 - if ((mod->module_init) && (mod->init_text_size)) {
86581 - set_page_attributes(mod->module_init,
86582 - mod->module_init + mod->init_text_size,
86583 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86584 + set_page_attributes(mod->module_init_rx,
86585 + mod->module_init_rx + mod->init_size_rx,
86586 set_memory_rw);
86587 }
86588 }
86589 @@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
86590 list_for_each_entry_rcu(mod, &modules, list) {
86591 if (mod->state == MODULE_STATE_UNFORMED)
86592 continue;
86593 - if ((mod->module_core) && (mod->core_text_size)) {
86594 - set_page_attributes(mod->module_core,
86595 - mod->module_core + mod->core_text_size,
86596 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86597 + set_page_attributes(mod->module_core_rx,
86598 + mod->module_core_rx + mod->core_size_rx,
86599 set_memory_ro);
86600 }
86601 - if ((mod->module_init) && (mod->init_text_size)) {
86602 - set_page_attributes(mod->module_init,
86603 - mod->module_init + mod->init_text_size,
86604 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86605 + set_page_attributes(mod->module_init_rx,
86606 + mod->module_init_rx + mod->init_size_rx,
86607 set_memory_ro);
86608 }
86609 }
86610 @@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
86611
86612 /* This may be NULL, but that's OK */
86613 unset_module_init_ro_nx(mod);
86614 - module_free(mod, mod->module_init);
86615 + module_free(mod, mod->module_init_rw);
86616 + module_free_exec(mod, mod->module_init_rx);
86617 kfree(mod->args);
86618 percpu_modfree(mod);
86619
86620 /* Free lock-classes: */
86621 - lockdep_free_key_range(mod->module_core, mod->core_size);
86622 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
86623 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
86624
86625 /* Finally, free the core (containing the module structure) */
86626 unset_module_core_ro_nx(mod);
86627 - module_free(mod, mod->module_core);
86628 + module_free_exec(mod, mod->module_core_rx);
86629 + module_free(mod, mod->module_core_rw);
86630
86631 #ifdef CONFIG_MPU
86632 update_protections(current->mm);
86633 @@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86634 int ret = 0;
86635 const struct kernel_symbol *ksym;
86636
86637 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86638 + int is_fs_load = 0;
86639 + int register_filesystem_found = 0;
86640 + char *p;
86641 +
86642 + p = strstr(mod->args, "grsec_modharden_fs");
86643 + if (p) {
86644 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
86645 + /* copy \0 as well */
86646 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
86647 + is_fs_load = 1;
86648 + }
86649 +#endif
86650 +
86651 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
86652 const char *name = info->strtab + sym[i].st_name;
86653
86654 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86655 + /* it's a real shame this will never get ripped and copied
86656 + upstream! ;(
86657 + */
86658 + if (is_fs_load && !strcmp(name, "register_filesystem"))
86659 + register_filesystem_found = 1;
86660 +#endif
86661 +
86662 switch (sym[i].st_shndx) {
86663 case SHN_COMMON:
86664 /* We compiled with -fno-common. These are not
86665 @@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86666 ksym = resolve_symbol_wait(mod, info, name);
86667 /* Ok if resolved. */
86668 if (ksym && !IS_ERR(ksym)) {
86669 + pax_open_kernel();
86670 sym[i].st_value = ksym->value;
86671 + pax_close_kernel();
86672 break;
86673 }
86674
86675 @@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86676 secbase = (unsigned long)mod_percpu(mod);
86677 else
86678 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
86679 + pax_open_kernel();
86680 sym[i].st_value += secbase;
86681 + pax_close_kernel();
86682 break;
86683 }
86684 }
86685
86686 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86687 + if (is_fs_load && !register_filesystem_found) {
86688 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
86689 + ret = -EPERM;
86690 + }
86691 +#endif
86692 +
86693 return ret;
86694 }
86695
86696 @@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
86697 || s->sh_entsize != ~0UL
86698 || strstarts(sname, ".init"))
86699 continue;
86700 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
86701 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86702 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
86703 + else
86704 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
86705 pr_debug("\t%s\n", sname);
86706 }
86707 - switch (m) {
86708 - case 0: /* executable */
86709 - mod->core_size = debug_align(mod->core_size);
86710 - mod->core_text_size = mod->core_size;
86711 - break;
86712 - case 1: /* RO: text and ro-data */
86713 - mod->core_size = debug_align(mod->core_size);
86714 - mod->core_ro_size = mod->core_size;
86715 - break;
86716 - case 3: /* whole core */
86717 - mod->core_size = debug_align(mod->core_size);
86718 - break;
86719 - }
86720 }
86721
86722 pr_debug("Init section allocation order:\n");
86723 @@ -2104,23 +2149,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
86724 || s->sh_entsize != ~0UL
86725 || !strstarts(sname, ".init"))
86726 continue;
86727 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
86728 - | INIT_OFFSET_MASK);
86729 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86730 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
86731 + else
86732 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
86733 + s->sh_entsize |= INIT_OFFSET_MASK;
86734 pr_debug("\t%s\n", sname);
86735 }
86736 - switch (m) {
86737 - case 0: /* executable */
86738 - mod->init_size = debug_align(mod->init_size);
86739 - mod->init_text_size = mod->init_size;
86740 - break;
86741 - case 1: /* RO: text and ro-data */
86742 - mod->init_size = debug_align(mod->init_size);
86743 - mod->init_ro_size = mod->init_size;
86744 - break;
86745 - case 3: /* whole init */
86746 - mod->init_size = debug_align(mod->init_size);
86747 - break;
86748 - }
86749 }
86750 }
86751
86752 @@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86753
86754 /* Put symbol section at end of init part of module. */
86755 symsect->sh_flags |= SHF_ALLOC;
86756 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
86757 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
86758 info->index.sym) | INIT_OFFSET_MASK;
86759 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
86760
86761 @@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86762 }
86763
86764 /* Append room for core symbols at end of core part. */
86765 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
86766 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
86767 - mod->core_size += strtab_size;
86768 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
86769 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
86770 + mod->core_size_rx += strtab_size;
86771
86772 /* Put string table section at end of init part of module. */
86773 strsect->sh_flags |= SHF_ALLOC;
86774 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
86775 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
86776 info->index.str) | INIT_OFFSET_MASK;
86777 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
86778 }
86779 @@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86780 /* Make sure we get permanent strtab: don't use info->strtab. */
86781 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
86782
86783 + pax_open_kernel();
86784 +
86785 /* Set types up while we still have access to sections. */
86786 for (i = 0; i < mod->num_symtab; i++)
86787 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
86788
86789 - mod->core_symtab = dst = mod->module_core + info->symoffs;
86790 - mod->core_strtab = s = mod->module_core + info->stroffs;
86791 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
86792 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
86793 src = mod->symtab;
86794 for (ndst = i = 0; i < mod->num_symtab; i++) {
86795 if (i == 0 ||
86796 @@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86797 }
86798 }
86799 mod->core_num_syms = ndst;
86800 +
86801 + pax_close_kernel();
86802 }
86803 #else
86804 static inline void layout_symtab(struct module *mod, struct load_info *info)
86805 @@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
86806 return vmalloc_exec(size);
86807 }
86808
86809 -static void *module_alloc_update_bounds(unsigned long size)
86810 +static void *module_alloc_update_bounds_rw(unsigned long size)
86811 {
86812 void *ret = module_alloc(size);
86813
86814 if (ret) {
86815 mutex_lock(&module_mutex);
86816 /* Update module bounds. */
86817 - if ((unsigned long)ret < module_addr_min)
86818 - module_addr_min = (unsigned long)ret;
86819 - if ((unsigned long)ret + size > module_addr_max)
86820 - module_addr_max = (unsigned long)ret + size;
86821 + if ((unsigned long)ret < module_addr_min_rw)
86822 + module_addr_min_rw = (unsigned long)ret;
86823 + if ((unsigned long)ret + size > module_addr_max_rw)
86824 + module_addr_max_rw = (unsigned long)ret + size;
86825 + mutex_unlock(&module_mutex);
86826 + }
86827 + return ret;
86828 +}
86829 +
86830 +static void *module_alloc_update_bounds_rx(unsigned long size)
86831 +{
86832 + void *ret = module_alloc_exec(size);
86833 +
86834 + if (ret) {
86835 + mutex_lock(&module_mutex);
86836 + /* Update module bounds. */
86837 + if ((unsigned long)ret < module_addr_min_rx)
86838 + module_addr_min_rx = (unsigned long)ret;
86839 + if ((unsigned long)ret + size > module_addr_max_rx)
86840 + module_addr_max_rx = (unsigned long)ret + size;
86841 mutex_unlock(&module_mutex);
86842 }
86843 return ret;
86844 @@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86845 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
86846
86847 if (info->index.sym == 0) {
86848 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86849 + /*
86850 + * avoid potentially printing jibberish on attempted load
86851 + * of a module randomized with a different seed
86852 + */
86853 + pr_warn("module has no symbols (stripped?)\n");
86854 +#else
86855 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
86856 +#endif
86857 return ERR_PTR(-ENOEXEC);
86858 }
86859
86860 @@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86861 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86862 {
86863 const char *modmagic = get_modinfo(info, "vermagic");
86864 + const char *license = get_modinfo(info, "license");
86865 int err;
86866
86867 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
86868 + if (!license || !license_is_gpl_compatible(license))
86869 + return -ENOEXEC;
86870 +#endif
86871 +
86872 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
86873 modmagic = NULL;
86874
86875 @@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86876 }
86877
86878 /* Set up license info based on the info section */
86879 - set_license(mod, get_modinfo(info, "license"));
86880 + set_license(mod, license);
86881
86882 return 0;
86883 }
86884 @@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
86885 void *ptr;
86886
86887 /* Do the allocs. */
86888 - ptr = module_alloc_update_bounds(mod->core_size);
86889 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
86890 /*
86891 * The pointer to this block is stored in the module structure
86892 * which is inside the block. Just mark it as not being a
86893 @@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
86894 if (!ptr)
86895 return -ENOMEM;
86896
86897 - memset(ptr, 0, mod->core_size);
86898 - mod->module_core = ptr;
86899 + memset(ptr, 0, mod->core_size_rw);
86900 + mod->module_core_rw = ptr;
86901
86902 - if (mod->init_size) {
86903 - ptr = module_alloc_update_bounds(mod->init_size);
86904 + if (mod->init_size_rw) {
86905 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
86906 /*
86907 * The pointer to this block is stored in the module structure
86908 * which is inside the block. This block doesn't need to be
86909 @@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
86910 */
86911 kmemleak_ignore(ptr);
86912 if (!ptr) {
86913 - module_free(mod, mod->module_core);
86914 + module_free(mod, mod->module_core_rw);
86915 return -ENOMEM;
86916 }
86917 - memset(ptr, 0, mod->init_size);
86918 - mod->module_init = ptr;
86919 + memset(ptr, 0, mod->init_size_rw);
86920 + mod->module_init_rw = ptr;
86921 } else
86922 - mod->module_init = NULL;
86923 + mod->module_init_rw = NULL;
86924 +
86925 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
86926 + kmemleak_not_leak(ptr);
86927 + if (!ptr) {
86928 + if (mod->module_init_rw)
86929 + module_free(mod, mod->module_init_rw);
86930 + module_free(mod, mod->module_core_rw);
86931 + return -ENOMEM;
86932 + }
86933 +
86934 + pax_open_kernel();
86935 + memset(ptr, 0, mod->core_size_rx);
86936 + pax_close_kernel();
86937 + mod->module_core_rx = ptr;
86938 +
86939 + if (mod->init_size_rx) {
86940 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
86941 + kmemleak_ignore(ptr);
86942 + if (!ptr && mod->init_size_rx) {
86943 + module_free_exec(mod, mod->module_core_rx);
86944 + if (mod->module_init_rw)
86945 + module_free(mod, mod->module_init_rw);
86946 + module_free(mod, mod->module_core_rw);
86947 + return -ENOMEM;
86948 + }
86949 +
86950 + pax_open_kernel();
86951 + memset(ptr, 0, mod->init_size_rx);
86952 + pax_close_kernel();
86953 + mod->module_init_rx = ptr;
86954 + } else
86955 + mod->module_init_rx = NULL;
86956
86957 /* Transfer each section which specifies SHF_ALLOC */
86958 pr_debug("final section addresses:\n");
86959 @@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
86960 if (!(shdr->sh_flags & SHF_ALLOC))
86961 continue;
86962
86963 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
86964 - dest = mod->module_init
86965 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86966 - else
86967 - dest = mod->module_core + shdr->sh_entsize;
86968 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
86969 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86970 + dest = mod->module_init_rw
86971 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86972 + else
86973 + dest = mod->module_init_rx
86974 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86975 + } else {
86976 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86977 + dest = mod->module_core_rw + shdr->sh_entsize;
86978 + else
86979 + dest = mod->module_core_rx + shdr->sh_entsize;
86980 + }
86981 +
86982 + if (shdr->sh_type != SHT_NOBITS) {
86983 +
86984 +#ifdef CONFIG_PAX_KERNEXEC
86985 +#ifdef CONFIG_X86_64
86986 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
86987 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
86988 +#endif
86989 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
86990 + pax_open_kernel();
86991 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86992 + pax_close_kernel();
86993 + } else
86994 +#endif
86995
86996 - if (shdr->sh_type != SHT_NOBITS)
86997 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86998 + }
86999 /* Update sh_addr to point to copy in image. */
87000 - shdr->sh_addr = (unsigned long)dest;
87001 +
87002 +#ifdef CONFIG_PAX_KERNEXEC
87003 + if (shdr->sh_flags & SHF_EXECINSTR)
87004 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
87005 + else
87006 +#endif
87007 +
87008 + shdr->sh_addr = (unsigned long)dest;
87009 pr_debug("\t0x%lx %s\n",
87010 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87011 }
87012 @@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
87013 * Do it before processing of module parameters, so the module
87014 * can provide parameter accessor functions of its own.
87015 */
87016 - if (mod->module_init)
87017 - flush_icache_range((unsigned long)mod->module_init,
87018 - (unsigned long)mod->module_init
87019 - + mod->init_size);
87020 - flush_icache_range((unsigned long)mod->module_core,
87021 - (unsigned long)mod->module_core + mod->core_size);
87022 + if (mod->module_init_rx)
87023 + flush_icache_range((unsigned long)mod->module_init_rx,
87024 + (unsigned long)mod->module_init_rx
87025 + + mod->init_size_rx);
87026 + flush_icache_range((unsigned long)mod->module_core_rx,
87027 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
87028
87029 set_fs(old_fs);
87030 }
87031 @@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87032 static void module_deallocate(struct module *mod, struct load_info *info)
87033 {
87034 percpu_modfree(mod);
87035 - module_free(mod, mod->module_init);
87036 - module_free(mod, mod->module_core);
87037 + module_free_exec(mod, mod->module_init_rx);
87038 + module_free_exec(mod, mod->module_core_rx);
87039 + module_free(mod, mod->module_init_rw);
87040 + module_free(mod, mod->module_core_rw);
87041 }
87042
87043 int __weak module_finalize(const Elf_Ehdr *hdr,
87044 @@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87045 static int post_relocation(struct module *mod, const struct load_info *info)
87046 {
87047 /* Sort exception table now relocations are done. */
87048 + pax_open_kernel();
87049 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87050 + pax_close_kernel();
87051
87052 /* Copy relocated percpu area over. */
87053 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87054 @@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
87055 MODULE_STATE_COMING, mod);
87056
87057 /* Set RO and NX regions for core */
87058 - set_section_ro_nx(mod->module_core,
87059 - mod->core_text_size,
87060 - mod->core_ro_size,
87061 - mod->core_size);
87062 + set_section_ro_nx(mod->module_core_rx,
87063 + mod->core_size_rx,
87064 + mod->core_size_rx,
87065 + mod->core_size_rx);
87066
87067 /* Set RO and NX regions for init */
87068 - set_section_ro_nx(mod->module_init,
87069 - mod->init_text_size,
87070 - mod->init_ro_size,
87071 - mod->init_size);
87072 + set_section_ro_nx(mod->module_init_rx,
87073 + mod->init_size_rx,
87074 + mod->init_size_rx,
87075 + mod->init_size_rx);
87076
87077 do_mod_ctors(mod);
87078 /* Start the module */
87079 @@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
87080 mod->strtab = mod->core_strtab;
87081 #endif
87082 unset_module_init_ro_nx(mod);
87083 - module_free(mod, mod->module_init);
87084 - mod->module_init = NULL;
87085 - mod->init_size = 0;
87086 - mod->init_ro_size = 0;
87087 - mod->init_text_size = 0;
87088 + module_free(mod, mod->module_init_rw);
87089 + module_free_exec(mod, mod->module_init_rx);
87090 + mod->module_init_rw = NULL;
87091 + mod->module_init_rx = NULL;
87092 + mod->init_size_rw = 0;
87093 + mod->init_size_rx = 0;
87094 mutex_unlock(&module_mutex);
87095 wake_up_all(&module_wq);
87096
87097 @@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87098 if (err)
87099 goto free_unload;
87100
87101 + /* Now copy in args */
87102 + mod->args = strndup_user(uargs, ~0UL >> 1);
87103 + if (IS_ERR(mod->args)) {
87104 + err = PTR_ERR(mod->args);
87105 + goto free_unload;
87106 + }
87107 +
87108 /* Set up MODINFO_ATTR fields */
87109 setup_modinfo(mod, info);
87110
87111 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87112 + {
87113 + char *p, *p2;
87114 +
87115 + if (strstr(mod->args, "grsec_modharden_netdev")) {
87116 + 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);
87117 + err = -EPERM;
87118 + goto free_modinfo;
87119 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87120 + p += sizeof("grsec_modharden_normal") - 1;
87121 + p2 = strstr(p, "_");
87122 + if (p2) {
87123 + *p2 = '\0';
87124 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87125 + *p2 = '_';
87126 + }
87127 + err = -EPERM;
87128 + goto free_modinfo;
87129 + }
87130 + }
87131 +#endif
87132 +
87133 /* Fix up syms, so that st_value is a pointer to location. */
87134 err = simplify_symbols(mod, info);
87135 if (err < 0)
87136 @@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87137
87138 flush_module_icache(mod);
87139
87140 - /* Now copy in args */
87141 - mod->args = strndup_user(uargs, ~0UL >> 1);
87142 - if (IS_ERR(mod->args)) {
87143 - err = PTR_ERR(mod->args);
87144 - goto free_arch_cleanup;
87145 - }
87146 -
87147 dynamic_debug_setup(info->debug, info->num_debug);
87148
87149 /* Finally it's fully formed, ready to start executing. */
87150 @@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87151 ddebug_cleanup:
87152 dynamic_debug_remove(info->debug);
87153 synchronize_sched();
87154 - kfree(mod->args);
87155 - free_arch_cleanup:
87156 module_arch_cleanup(mod);
87157 free_modinfo:
87158 free_modinfo(mod);
87159 + kfree(mod->args);
87160 free_unload:
87161 module_unload_free(mod);
87162 unlink_mod:
87163 @@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
87164 unsigned long nextval;
87165
87166 /* At worse, next value is at end of module */
87167 - if (within_module_init(addr, mod))
87168 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
87169 + if (within_module_init_rx(addr, mod))
87170 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87171 + else if (within_module_init_rw(addr, mod))
87172 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87173 + else if (within_module_core_rx(addr, mod))
87174 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87175 + else if (within_module_core_rw(addr, mod))
87176 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87177 else
87178 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
87179 + return NULL;
87180
87181 /* Scan for closest preceding symbol, and next symbol. (ELF
87182 starts real symbols at 1). */
87183 @@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
87184 return 0;
87185
87186 seq_printf(m, "%s %u",
87187 - mod->name, mod->init_size + mod->core_size);
87188 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87189 print_unload_info(m, mod);
87190
87191 /* Informative for users. */
87192 @@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
87193 mod->state == MODULE_STATE_COMING ? "Loading":
87194 "Live");
87195 /* Used by oprofile and other similar tools. */
87196 - seq_printf(m, " 0x%pK", mod->module_core);
87197 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87198
87199 /* Taints info */
87200 if (mod->taints)
87201 @@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
87202
87203 static int __init proc_modules_init(void)
87204 {
87205 +#ifndef CONFIG_GRKERNSEC_HIDESYM
87206 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87207 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87208 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87209 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87210 +#else
87211 proc_create("modules", 0, NULL, &proc_modules_operations);
87212 +#endif
87213 +#else
87214 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87215 +#endif
87216 return 0;
87217 }
87218 module_init(proc_modules_init);
87219 @@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
87220 {
87221 struct module *mod;
87222
87223 - if (addr < module_addr_min || addr > module_addr_max)
87224 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87225 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
87226 return NULL;
87227
87228 list_for_each_entry_rcu(mod, &modules, list) {
87229 if (mod->state == MODULE_STATE_UNFORMED)
87230 continue;
87231 - if (within_module_core(addr, mod)
87232 - || within_module_init(addr, mod))
87233 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
87234 return mod;
87235 }
87236 return NULL;
87237 @@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
87238 */
87239 struct module *__module_text_address(unsigned long addr)
87240 {
87241 - struct module *mod = __module_address(addr);
87242 + struct module *mod;
87243 +
87244 +#ifdef CONFIG_X86_32
87245 + addr = ktla_ktva(addr);
87246 +#endif
87247 +
87248 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87249 + return NULL;
87250 +
87251 + mod = __module_address(addr);
87252 +
87253 if (mod) {
87254 /* Make sure it's within the text section. */
87255 - if (!within(addr, mod->module_init, mod->init_text_size)
87256 - && !within(addr, mod->module_core, mod->core_text_size))
87257 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87258 mod = NULL;
87259 }
87260 return mod;
87261 diff --git a/kernel/notifier.c b/kernel/notifier.c
87262 index 2d5cc4c..d9ea600 100644
87263 --- a/kernel/notifier.c
87264 +++ b/kernel/notifier.c
87265 @@ -5,6 +5,7 @@
87266 #include <linux/rcupdate.h>
87267 #include <linux/vmalloc.h>
87268 #include <linux/reboot.h>
87269 +#include <linux/mm.h>
87270
87271 /*
87272 * Notifier list for kernel code which wants to be called
87273 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87274 while ((*nl) != NULL) {
87275 if (n->priority > (*nl)->priority)
87276 break;
87277 - nl = &((*nl)->next);
87278 + nl = (struct notifier_block **)&((*nl)->next);
87279 }
87280 - n->next = *nl;
87281 + pax_open_kernel();
87282 + *(const void **)&n->next = *nl;
87283 rcu_assign_pointer(*nl, n);
87284 + pax_close_kernel();
87285 return 0;
87286 }
87287
87288 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87289 return 0;
87290 if (n->priority > (*nl)->priority)
87291 break;
87292 - nl = &((*nl)->next);
87293 + nl = (struct notifier_block **)&((*nl)->next);
87294 }
87295 - n->next = *nl;
87296 + pax_open_kernel();
87297 + *(const void **)&n->next = *nl;
87298 rcu_assign_pointer(*nl, n);
87299 + pax_close_kernel();
87300 return 0;
87301 }
87302
87303 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87304 {
87305 while ((*nl) != NULL) {
87306 if ((*nl) == n) {
87307 + pax_open_kernel();
87308 rcu_assign_pointer(*nl, n->next);
87309 + pax_close_kernel();
87310 return 0;
87311 }
87312 - nl = &((*nl)->next);
87313 + nl = (struct notifier_block **)&((*nl)->next);
87314 }
87315 return -ENOENT;
87316 }
87317 diff --git a/kernel/padata.c b/kernel/padata.c
87318 index 2abd25d..02c4faa 100644
87319 --- a/kernel/padata.c
87320 +++ b/kernel/padata.c
87321 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87322 * seq_nr mod. number of cpus in use.
87323 */
87324
87325 - seq_nr = atomic_inc_return(&pd->seq_nr);
87326 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87327 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87328
87329 return padata_index_to_cpu(pd, cpu_index);
87330 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87331 padata_init_pqueues(pd);
87332 padata_init_squeues(pd);
87333 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87334 - atomic_set(&pd->seq_nr, -1);
87335 + atomic_set_unchecked(&pd->seq_nr, -1);
87336 atomic_set(&pd->reorder_objects, 0);
87337 atomic_set(&pd->refcnt, 0);
87338 pd->pinst = pinst;
87339 diff --git a/kernel/panic.c b/kernel/panic.c
87340 index c00b4ce..98c7d1a 100644
87341 --- a/kernel/panic.c
87342 +++ b/kernel/panic.c
87343 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87344 /*
87345 * Stop ourself in panic -- architecture code may override this
87346 */
87347 -void __weak panic_smp_self_stop(void)
87348 +void __weak __noreturn panic_smp_self_stop(void)
87349 {
87350 while (1)
87351 cpu_relax();
87352 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87353 disable_trace_on_warning();
87354
87355 pr_warn("------------[ cut here ]------------\n");
87356 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87357 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87358 raw_smp_processor_id(), current->pid, file, line, caller);
87359
87360 if (args)
87361 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87362 */
87363 void __stack_chk_fail(void)
87364 {
87365 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
87366 + dump_stack();
87367 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87368 __builtin_return_address(0));
87369 }
87370 EXPORT_SYMBOL(__stack_chk_fail);
87371 diff --git a/kernel/pid.c b/kernel/pid.c
87372 index 9b9a266..c20ef80 100644
87373 --- a/kernel/pid.c
87374 +++ b/kernel/pid.c
87375 @@ -33,6 +33,7 @@
87376 #include <linux/rculist.h>
87377 #include <linux/bootmem.h>
87378 #include <linux/hash.h>
87379 +#include <linux/security.h>
87380 #include <linux/pid_namespace.h>
87381 #include <linux/init_task.h>
87382 #include <linux/syscalls.h>
87383 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87384
87385 int pid_max = PID_MAX_DEFAULT;
87386
87387 -#define RESERVED_PIDS 300
87388 +#define RESERVED_PIDS 500
87389
87390 int pid_max_min = RESERVED_PIDS + 1;
87391 int pid_max_max = PID_MAX_LIMIT;
87392 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87393 */
87394 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87395 {
87396 + struct task_struct *task;
87397 +
87398 rcu_lockdep_assert(rcu_read_lock_held(),
87399 "find_task_by_pid_ns() needs rcu_read_lock()"
87400 " protection");
87401 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87402 +
87403 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87404 +
87405 + if (gr_pid_is_chrooted(task))
87406 + return NULL;
87407 +
87408 + return task;
87409 }
87410
87411 struct task_struct *find_task_by_vpid(pid_t vnr)
87412 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87413 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87414 }
87415
87416 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87417 +{
87418 + rcu_lockdep_assert(rcu_read_lock_held(),
87419 + "find_task_by_pid_ns() needs rcu_read_lock()"
87420 + " protection");
87421 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
87422 +}
87423 +
87424 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
87425 {
87426 struct pid *pid;
87427 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
87428 index 06c62de..b08cc6c 100644
87429 --- a/kernel/pid_namespace.c
87430 +++ b/kernel/pid_namespace.c
87431 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
87432 void __user *buffer, size_t *lenp, loff_t *ppos)
87433 {
87434 struct pid_namespace *pid_ns = task_active_pid_ns(current);
87435 - struct ctl_table tmp = *table;
87436 + ctl_table_no_const tmp = *table;
87437
87438 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
87439 return -EPERM;
87440 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
87441 index c7f31aa..2b44977 100644
87442 --- a/kernel/posix-cpu-timers.c
87443 +++ b/kernel/posix-cpu-timers.c
87444 @@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
87445
87446 static __init int init_posix_cpu_timers(void)
87447 {
87448 - struct k_clock process = {
87449 + static struct k_clock process = {
87450 .clock_getres = process_cpu_clock_getres,
87451 .clock_get = process_cpu_clock_get,
87452 .timer_create = process_cpu_timer_create,
87453 .nsleep = process_cpu_nsleep,
87454 .nsleep_restart = process_cpu_nsleep_restart,
87455 };
87456 - struct k_clock thread = {
87457 + static struct k_clock thread = {
87458 .clock_getres = thread_cpu_clock_getres,
87459 .clock_get = thread_cpu_clock_get,
87460 .timer_create = thread_cpu_timer_create,
87461 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
87462 index 424c2d4..679242f 100644
87463 --- a/kernel/posix-timers.c
87464 +++ b/kernel/posix-timers.c
87465 @@ -43,6 +43,7 @@
87466 #include <linux/hash.h>
87467 #include <linux/posix-clock.h>
87468 #include <linux/posix-timers.h>
87469 +#include <linux/grsecurity.h>
87470 #include <linux/syscalls.h>
87471 #include <linux/wait.h>
87472 #include <linux/workqueue.h>
87473 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
87474 * which we beg off on and pass to do_sys_settimeofday().
87475 */
87476
87477 -static struct k_clock posix_clocks[MAX_CLOCKS];
87478 +static struct k_clock *posix_clocks[MAX_CLOCKS];
87479
87480 /*
87481 * These ones are defined below.
87482 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
87483 */
87484 static __init int init_posix_timers(void)
87485 {
87486 - struct k_clock clock_realtime = {
87487 + static struct k_clock clock_realtime = {
87488 .clock_getres = hrtimer_get_res,
87489 .clock_get = posix_clock_realtime_get,
87490 .clock_set = posix_clock_realtime_set,
87491 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
87492 .timer_get = common_timer_get,
87493 .timer_del = common_timer_del,
87494 };
87495 - struct k_clock clock_monotonic = {
87496 + static struct k_clock clock_monotonic = {
87497 .clock_getres = hrtimer_get_res,
87498 .clock_get = posix_ktime_get_ts,
87499 .nsleep = common_nsleep,
87500 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
87501 .timer_get = common_timer_get,
87502 .timer_del = common_timer_del,
87503 };
87504 - struct k_clock clock_monotonic_raw = {
87505 + static struct k_clock clock_monotonic_raw = {
87506 .clock_getres = hrtimer_get_res,
87507 .clock_get = posix_get_monotonic_raw,
87508 };
87509 - struct k_clock clock_realtime_coarse = {
87510 + static struct k_clock clock_realtime_coarse = {
87511 .clock_getres = posix_get_coarse_res,
87512 .clock_get = posix_get_realtime_coarse,
87513 };
87514 - struct k_clock clock_monotonic_coarse = {
87515 + static struct k_clock clock_monotonic_coarse = {
87516 .clock_getres = posix_get_coarse_res,
87517 .clock_get = posix_get_monotonic_coarse,
87518 };
87519 - struct k_clock clock_tai = {
87520 + static struct k_clock clock_tai = {
87521 .clock_getres = hrtimer_get_res,
87522 .clock_get = posix_get_tai,
87523 .nsleep = common_nsleep,
87524 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
87525 .timer_get = common_timer_get,
87526 .timer_del = common_timer_del,
87527 };
87528 - struct k_clock clock_boottime = {
87529 + static struct k_clock clock_boottime = {
87530 .clock_getres = hrtimer_get_res,
87531 .clock_get = posix_get_boottime,
87532 .nsleep = common_nsleep,
87533 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
87534 return;
87535 }
87536
87537 - posix_clocks[clock_id] = *new_clock;
87538 + posix_clocks[clock_id] = new_clock;
87539 }
87540 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
87541
87542 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
87543 return (id & CLOCKFD_MASK) == CLOCKFD ?
87544 &clock_posix_dynamic : &clock_posix_cpu;
87545
87546 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
87547 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
87548 return NULL;
87549 - return &posix_clocks[id];
87550 + return posix_clocks[id];
87551 }
87552
87553 static int common_timer_create(struct k_itimer *new_timer)
87554 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
87555 struct k_clock *kc = clockid_to_kclock(which_clock);
87556 struct k_itimer *new_timer;
87557 int error, new_timer_id;
87558 - sigevent_t event;
87559 + sigevent_t event = { };
87560 int it_id_set = IT_ID_NOT_SET;
87561
87562 if (!kc)
87563 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
87564 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
87565 return -EFAULT;
87566
87567 + /* only the CLOCK_REALTIME clock can be set, all other clocks
87568 + have their clock_set fptr set to a nosettime dummy function
87569 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
87570 + call common_clock_set, which calls do_sys_settimeofday, which
87571 + we hook
87572 + */
87573 +
87574 return kc->clock_set(which_clock, &new_tp);
87575 }
87576
87577 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
87578 index 2fac9cc..56fef29 100644
87579 --- a/kernel/power/Kconfig
87580 +++ b/kernel/power/Kconfig
87581 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
87582 config HIBERNATION
87583 bool "Hibernation (aka 'suspend to disk')"
87584 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
87585 + depends on !GRKERNSEC_KMEM
87586 + depends on !PAX_MEMORY_SANITIZE
87587 select HIBERNATE_CALLBACKS
87588 select LZO_COMPRESS
87589 select LZO_DECOMPRESS
87590 diff --git a/kernel/power/process.c b/kernel/power/process.c
87591 index 06ec886..9dba35e 100644
87592 --- a/kernel/power/process.c
87593 +++ b/kernel/power/process.c
87594 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
87595 unsigned int elapsed_msecs;
87596 bool wakeup = false;
87597 int sleep_usecs = USEC_PER_MSEC;
87598 + bool timedout = false;
87599
87600 do_gettimeofday(&start);
87601
87602 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
87603
87604 while (true) {
87605 todo = 0;
87606 + if (time_after(jiffies, end_time))
87607 + timedout = true;
87608 read_lock(&tasklist_lock);
87609 do_each_thread(g, p) {
87610 if (p == current || !freeze_task(p))
87611 continue;
87612
87613 - if (!freezer_should_skip(p))
87614 + if (!freezer_should_skip(p)) {
87615 todo++;
87616 + if (timedout) {
87617 + printk(KERN_ERR "Task refusing to freeze:\n");
87618 + sched_show_task(p);
87619 + }
87620 + }
87621 } while_each_thread(g, p);
87622 read_unlock(&tasklist_lock);
87623
87624 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
87625 todo += wq_busy;
87626 }
87627
87628 - if (!todo || time_after(jiffies, end_time))
87629 + if (!todo || timedout)
87630 break;
87631
87632 if (pm_wakeup_pending()) {
87633 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
87634 index be7c86b..b972b27 100644
87635 --- a/kernel/printk/printk.c
87636 +++ b/kernel/printk/printk.c
87637 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
87638 if (from_file && type != SYSLOG_ACTION_OPEN)
87639 return 0;
87640
87641 +#ifdef CONFIG_GRKERNSEC_DMESG
87642 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
87643 + return -EPERM;
87644 +#endif
87645 +
87646 if (syslog_action_restricted(type)) {
87647 if (capable(CAP_SYSLOG))
87648 return 0;
87649 @@ -1080,7 +1085,6 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
87650 next_seq = log_next_seq;
87651
87652 len = 0;
87653 - prev = 0;
87654 while (len >= 0 && seq < next_seq) {
87655 struct printk_log *msg = log_from_idx(idx);
87656 int textlen;
87657 @@ -2789,7 +2793,6 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
87658 next_idx = idx;
87659
87660 l = 0;
87661 - prev = 0;
87662 while (seq < dumper->next_seq) {
87663 struct printk_log *msg = log_from_idx(idx);
87664
87665 diff --git a/kernel/profile.c b/kernel/profile.c
87666 index 6631e1e..310c266 100644
87667 --- a/kernel/profile.c
87668 +++ b/kernel/profile.c
87669 @@ -37,7 +37,7 @@ struct profile_hit {
87670 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
87671 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
87672
87673 -static atomic_t *prof_buffer;
87674 +static atomic_unchecked_t *prof_buffer;
87675 static unsigned long prof_len, prof_shift;
87676
87677 int prof_on __read_mostly;
87678 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
87679 hits[i].pc = 0;
87680 continue;
87681 }
87682 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87683 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87684 hits[i].hits = hits[i].pc = 0;
87685 }
87686 }
87687 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87688 * Add the current hit(s) and flush the write-queue out
87689 * to the global buffer:
87690 */
87691 - atomic_add(nr_hits, &prof_buffer[pc]);
87692 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
87693 for (i = 0; i < NR_PROFILE_HIT; ++i) {
87694 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87695 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87696 hits[i].pc = hits[i].hits = 0;
87697 }
87698 out:
87699 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87700 {
87701 unsigned long pc;
87702 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
87703 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87704 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87705 }
87706 #endif /* !CONFIG_SMP */
87707
87708 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
87709 return -EFAULT;
87710 buf++; p++; count--; read++;
87711 }
87712 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
87713 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
87714 if (copy_to_user(buf, (void *)pnt, count))
87715 return -EFAULT;
87716 read += count;
87717 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
87718 }
87719 #endif
87720 profile_discard_flip_buffers();
87721 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
87722 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
87723 return count;
87724 }
87725
87726 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
87727 index 1f4bcb3..99cf7ab 100644
87728 --- a/kernel/ptrace.c
87729 +++ b/kernel/ptrace.c
87730 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
87731 if (seize)
87732 flags |= PT_SEIZED;
87733 rcu_read_lock();
87734 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87735 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87736 flags |= PT_PTRACE_CAP;
87737 rcu_read_unlock();
87738 task->ptrace = flags;
87739 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
87740 break;
87741 return -EIO;
87742 }
87743 - if (copy_to_user(dst, buf, retval))
87744 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
87745 return -EFAULT;
87746 copied += retval;
87747 src += retval;
87748 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
87749 bool seized = child->ptrace & PT_SEIZED;
87750 int ret = -EIO;
87751 siginfo_t siginfo, *si;
87752 - void __user *datavp = (void __user *) data;
87753 + void __user *datavp = (__force void __user *) data;
87754 unsigned long __user *datalp = datavp;
87755 unsigned long flags;
87756
87757 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
87758 goto out;
87759 }
87760
87761 + if (gr_handle_ptrace(child, request)) {
87762 + ret = -EPERM;
87763 + goto out_put_task_struct;
87764 + }
87765 +
87766 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87767 ret = ptrace_attach(child, request, addr, data);
87768 /*
87769 * Some architectures need to do book-keeping after
87770 * a ptrace attach.
87771 */
87772 - if (!ret)
87773 + if (!ret) {
87774 arch_ptrace_attach(child);
87775 + gr_audit_ptrace(child);
87776 + }
87777 goto out_put_task_struct;
87778 }
87779
87780 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
87781 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
87782 if (copied != sizeof(tmp))
87783 return -EIO;
87784 - return put_user(tmp, (unsigned long __user *)data);
87785 + return put_user(tmp, (__force unsigned long __user *)data);
87786 }
87787
87788 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
87789 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
87790 }
87791
87792 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87793 - compat_long_t addr, compat_long_t data)
87794 + compat_ulong_t addr, compat_ulong_t data)
87795 {
87796 struct task_struct *child;
87797 long ret;
87798 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87799 goto out;
87800 }
87801
87802 + if (gr_handle_ptrace(child, request)) {
87803 + ret = -EPERM;
87804 + goto out_put_task_struct;
87805 + }
87806 +
87807 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87808 ret = ptrace_attach(child, request, addr, data);
87809 /*
87810 * Some architectures need to do book-keeping after
87811 * a ptrace attach.
87812 */
87813 - if (!ret)
87814 + if (!ret) {
87815 arch_ptrace_attach(child);
87816 + gr_audit_ptrace(child);
87817 + }
87818 goto out_put_task_struct;
87819 }
87820
87821 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
87822 index 01d5ccb..cdcbee6 100644
87823 --- a/kernel/rcu/srcu.c
87824 +++ b/kernel/rcu/srcu.c
87825 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
87826
87827 idx = ACCESS_ONCE(sp->completed) & 0x1;
87828 preempt_disable();
87829 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87830 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87831 smp_mb(); /* B */ /* Avoid leaking the critical section. */
87832 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87833 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87834 preempt_enable();
87835 return idx;
87836 }
87837 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
87838 index 1254f31..16258dc 100644
87839 --- a/kernel/rcu/tiny.c
87840 +++ b/kernel/rcu/tiny.c
87841 @@ -46,7 +46,7 @@
87842 /* Forward declarations for tiny_plugin.h. */
87843 struct rcu_ctrlblk;
87844 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
87845 -static void rcu_process_callbacks(struct softirq_action *unused);
87846 +static void rcu_process_callbacks(void);
87847 static void __call_rcu(struct rcu_head *head,
87848 void (*func)(struct rcu_head *rcu),
87849 struct rcu_ctrlblk *rcp);
87850 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
87851 false));
87852 }
87853
87854 -static void rcu_process_callbacks(struct softirq_action *unused)
87855 +static __latent_entropy void rcu_process_callbacks(void)
87856 {
87857 __rcu_process_callbacks(&rcu_sched_ctrlblk);
87858 __rcu_process_callbacks(&rcu_bh_ctrlblk);
87859 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
87860 index 3929cd4..421624d 100644
87861 --- a/kernel/rcu/torture.c
87862 +++ b/kernel/rcu/torture.c
87863 @@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
87864 { 0 };
87865 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
87866 { 0 };
87867 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87868 -static atomic_t n_rcu_torture_alloc;
87869 -static atomic_t n_rcu_torture_alloc_fail;
87870 -static atomic_t n_rcu_torture_free;
87871 -static atomic_t n_rcu_torture_mberror;
87872 -static atomic_t n_rcu_torture_error;
87873 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87874 +static atomic_unchecked_t n_rcu_torture_alloc;
87875 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
87876 +static atomic_unchecked_t n_rcu_torture_free;
87877 +static atomic_unchecked_t n_rcu_torture_mberror;
87878 +static atomic_unchecked_t n_rcu_torture_error;
87879 static long n_rcu_torture_barrier_error;
87880 static long n_rcu_torture_boost_ktrerror;
87881 static long n_rcu_torture_boost_rterror;
87882 @@ -299,11 +299,11 @@ rcu_torture_alloc(void)
87883
87884 spin_lock_bh(&rcu_torture_lock);
87885 if (list_empty(&rcu_torture_freelist)) {
87886 - atomic_inc(&n_rcu_torture_alloc_fail);
87887 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
87888 spin_unlock_bh(&rcu_torture_lock);
87889 return NULL;
87890 }
87891 - atomic_inc(&n_rcu_torture_alloc);
87892 + atomic_inc_unchecked(&n_rcu_torture_alloc);
87893 p = rcu_torture_freelist.next;
87894 list_del_init(p);
87895 spin_unlock_bh(&rcu_torture_lock);
87896 @@ -316,7 +316,7 @@ rcu_torture_alloc(void)
87897 static void
87898 rcu_torture_free(struct rcu_torture *p)
87899 {
87900 - atomic_inc(&n_rcu_torture_free);
87901 + atomic_inc_unchecked(&n_rcu_torture_free);
87902 spin_lock_bh(&rcu_torture_lock);
87903 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
87904 spin_unlock_bh(&rcu_torture_lock);
87905 @@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
87906 i = rp->rtort_pipe_count;
87907 if (i > RCU_TORTURE_PIPE_LEN)
87908 i = RCU_TORTURE_PIPE_LEN;
87909 - atomic_inc(&rcu_torture_wcount[i]);
87910 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
87911 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
87912 rp->rtort_mbtest = 0;
87913 rcu_torture_free(rp);
87914 @@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
87915 i = old_rp->rtort_pipe_count;
87916 if (i > RCU_TORTURE_PIPE_LEN)
87917 i = RCU_TORTURE_PIPE_LEN;
87918 - atomic_inc(&rcu_torture_wcount[i]);
87919 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
87920 old_rp->rtort_pipe_count++;
87921 if (gp_normal == gp_exp)
87922 exp = !!(rcu_random(&rand) & 0x80);
87923 @@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
87924 i = rp->rtort_pipe_count;
87925 if (i > RCU_TORTURE_PIPE_LEN)
87926 i = RCU_TORTURE_PIPE_LEN;
87927 - atomic_inc(&rcu_torture_wcount[i]);
87928 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
87929 if (++rp->rtort_pipe_count >=
87930 RCU_TORTURE_PIPE_LEN) {
87931 rp->rtort_mbtest = 0;
87932 @@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
87933 return;
87934 }
87935 if (p->rtort_mbtest == 0)
87936 - atomic_inc(&n_rcu_torture_mberror);
87937 + atomic_inc_unchecked(&n_rcu_torture_mberror);
87938 spin_lock(&rand_lock);
87939 cur_ops->read_delay(&rand);
87940 n_rcu_torture_timers++;
87941 @@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
87942 continue;
87943 }
87944 if (p->rtort_mbtest == 0)
87945 - atomic_inc(&n_rcu_torture_mberror);
87946 + atomic_inc_unchecked(&n_rcu_torture_mberror);
87947 cur_ops->read_delay(&rand);
87948 preempt_disable();
87949 pipe_count = p->rtort_pipe_count;
87950 @@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
87951 rcu_torture_current,
87952 rcu_torture_current_version,
87953 list_empty(&rcu_torture_freelist),
87954 - atomic_read(&n_rcu_torture_alloc),
87955 - atomic_read(&n_rcu_torture_alloc_fail),
87956 - atomic_read(&n_rcu_torture_free));
87957 + atomic_read_unchecked(&n_rcu_torture_alloc),
87958 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
87959 + atomic_read_unchecked(&n_rcu_torture_free));
87960 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
87961 - atomic_read(&n_rcu_torture_mberror),
87962 + atomic_read_unchecked(&n_rcu_torture_mberror),
87963 n_rcu_torture_boost_ktrerror,
87964 n_rcu_torture_boost_rterror);
87965 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
87966 @@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
87967 n_barrier_attempts,
87968 n_rcu_torture_barrier_error);
87969 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
87970 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
87971 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
87972 n_rcu_torture_barrier_error != 0 ||
87973 n_rcu_torture_boost_ktrerror != 0 ||
87974 n_rcu_torture_boost_rterror != 0 ||
87975 n_rcu_torture_boost_failure != 0 ||
87976 i > 1) {
87977 cnt += sprintf(&page[cnt], "!!! ");
87978 - atomic_inc(&n_rcu_torture_error);
87979 + atomic_inc_unchecked(&n_rcu_torture_error);
87980 WARN_ON_ONCE(1);
87981 }
87982 cnt += sprintf(&page[cnt], "Reader Pipe: ");
87983 @@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
87984 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
87985 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
87986 cnt += sprintf(&page[cnt], " %d",
87987 - atomic_read(&rcu_torture_wcount[i]));
87988 + atomic_read_unchecked(&rcu_torture_wcount[i]));
87989 }
87990 cnt += sprintf(&page[cnt], "\n");
87991 if (cur_ops->stats)
87992 @@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
87993
87994 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
87995
87996 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87997 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87998 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
87999 else if (n_online_successes != n_online_attempts ||
88000 n_offline_successes != n_offline_attempts)
88001 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
88002
88003 rcu_torture_current = NULL;
88004 rcu_torture_current_version = 0;
88005 - atomic_set(&n_rcu_torture_alloc, 0);
88006 - atomic_set(&n_rcu_torture_alloc_fail, 0);
88007 - atomic_set(&n_rcu_torture_free, 0);
88008 - atomic_set(&n_rcu_torture_mberror, 0);
88009 - atomic_set(&n_rcu_torture_error, 0);
88010 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88011 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88012 + atomic_set_unchecked(&n_rcu_torture_free, 0);
88013 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88014 + atomic_set_unchecked(&n_rcu_torture_error, 0);
88015 n_rcu_torture_barrier_error = 0;
88016 n_rcu_torture_boost_ktrerror = 0;
88017 n_rcu_torture_boost_rterror = 0;
88018 n_rcu_torture_boost_failure = 0;
88019 n_rcu_torture_boosts = 0;
88020 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88021 - atomic_set(&rcu_torture_wcount[i], 0);
88022 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88023 for_each_possible_cpu(cpu) {
88024 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88025 per_cpu(rcu_torture_count, cpu)[i] = 0;
88026 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88027 index dd08198..5ccccbe 100644
88028 --- a/kernel/rcu/tree.c
88029 +++ b/kernel/rcu/tree.c
88030 @@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88031 rcu_prepare_for_idle(smp_processor_id());
88032 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88033 smp_mb__before_atomic_inc(); /* See above. */
88034 - atomic_inc(&rdtp->dynticks);
88035 + atomic_inc_unchecked(&rdtp->dynticks);
88036 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88037 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88038 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88039
88040 /*
88041 * It is illegal to enter an extended quiescent state while
88042 @@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88043 int user)
88044 {
88045 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88046 - atomic_inc(&rdtp->dynticks);
88047 + atomic_inc_unchecked(&rdtp->dynticks);
88048 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88049 smp_mb__after_atomic_inc(); /* See above. */
88050 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88051 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88052 rcu_cleanup_after_idle(smp_processor_id());
88053 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88054 if (!user && !is_idle_task(current)) {
88055 @@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
88056 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88057
88058 if (rdtp->dynticks_nmi_nesting == 0 &&
88059 - (atomic_read(&rdtp->dynticks) & 0x1))
88060 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88061 return;
88062 rdtp->dynticks_nmi_nesting++;
88063 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88064 - atomic_inc(&rdtp->dynticks);
88065 + atomic_inc_unchecked(&rdtp->dynticks);
88066 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88067 smp_mb__after_atomic_inc(); /* See above. */
88068 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88069 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88070 }
88071
88072 /**
88073 @@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
88074 return;
88075 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88076 smp_mb__before_atomic_inc(); /* See above. */
88077 - atomic_inc(&rdtp->dynticks);
88078 + atomic_inc_unchecked(&rdtp->dynticks);
88079 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88080 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88081 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88082 }
88083
88084 /**
88085 @@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
88086 */
88087 bool notrace __rcu_is_watching(void)
88088 {
88089 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88090 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88091 }
88092
88093 /**
88094 @@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88095 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88096 bool *isidle, unsigned long *maxj)
88097 {
88098 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88099 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88100 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88101 return (rdp->dynticks_snap & 0x1) == 0;
88102 }
88103 @@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88104 unsigned int curr;
88105 unsigned int snap;
88106
88107 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88108 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88109 snap = (unsigned int)rdp->dynticks_snap;
88110
88111 /*
88112 @@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88113 rdp = this_cpu_ptr(rsp->rda);
88114 rcu_preempt_check_blocked_tasks(rnp);
88115 rnp->qsmask = rnp->qsmaskinit;
88116 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88117 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88118 WARN_ON_ONCE(rnp->completed != rsp->completed);
88119 - ACCESS_ONCE(rnp->completed) = rsp->completed;
88120 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88121 if (rnp == rdp->mynode)
88122 __note_gp_changes(rsp, rnp, rdp);
88123 rcu_preempt_boost_start_gp(rnp);
88124 @@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88125 */
88126 rcu_for_each_node_breadth_first(rsp, rnp) {
88127 raw_spin_lock_irq(&rnp->lock);
88128 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88129 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88130 rdp = this_cpu_ptr(rsp->rda);
88131 if (rnp == rdp->mynode)
88132 __note_gp_changes(rsp, rnp, rdp);
88133 @@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88134 rsp->qlen += rdp->qlen;
88135 rdp->n_cbs_orphaned += rdp->qlen;
88136 rdp->qlen_lazy = 0;
88137 - ACCESS_ONCE(rdp->qlen) = 0;
88138 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88139 }
88140
88141 /*
88142 @@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88143 }
88144 smp_mb(); /* List handling before counting for rcu_barrier(). */
88145 rdp->qlen_lazy -= count_lazy;
88146 - ACCESS_ONCE(rdp->qlen) -= count;
88147 + ACCESS_ONCE_RW(rdp->qlen) -= count;
88148 rdp->n_cbs_invoked += count;
88149
88150 /* Reinstate batch limit if we have worked down the excess. */
88151 @@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88152 /*
88153 * Do RCU core processing for the current CPU.
88154 */
88155 -static void rcu_process_callbacks(struct softirq_action *unused)
88156 +static void rcu_process_callbacks(void)
88157 {
88158 struct rcu_state *rsp;
88159
88160 @@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88161 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88162 if (debug_rcu_head_queue(head)) {
88163 /* Probable double call_rcu(), so leak the callback. */
88164 - ACCESS_ONCE(head->func) = rcu_leak_callback;
88165 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88166 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88167 return;
88168 }
88169 @@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88170 local_irq_restore(flags);
88171 return;
88172 }
88173 - ACCESS_ONCE(rdp->qlen)++;
88174 + ACCESS_ONCE_RW(rdp->qlen)++;
88175 if (lazy)
88176 rdp->qlen_lazy++;
88177 else
88178 @@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
88179 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88180 * course be required on a 64-bit system.
88181 */
88182 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88183 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88184 (ulong)atomic_long_read(&rsp->expedited_done) +
88185 ULONG_MAX / 8)) {
88186 synchronize_sched();
88187 - atomic_long_inc(&rsp->expedited_wrap);
88188 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
88189 return;
88190 }
88191
88192 @@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
88193 * Take a ticket. Note that atomic_inc_return() implies a
88194 * full memory barrier.
88195 */
88196 - snap = atomic_long_inc_return(&rsp->expedited_start);
88197 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88198 firstsnap = snap;
88199 get_online_cpus();
88200 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88201 @@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
88202 synchronize_sched_expedited_cpu_stop,
88203 NULL) == -EAGAIN) {
88204 put_online_cpus();
88205 - atomic_long_inc(&rsp->expedited_tryfail);
88206 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88207
88208 /* Check to see if someone else did our work for us. */
88209 s = atomic_long_read(&rsp->expedited_done);
88210 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88211 /* ensure test happens before caller kfree */
88212 smp_mb__before_atomic_inc(); /* ^^^ */
88213 - atomic_long_inc(&rsp->expedited_workdone1);
88214 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88215 return;
88216 }
88217
88218 @@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
88219 udelay(trycount * num_online_cpus());
88220 } else {
88221 wait_rcu_gp(call_rcu_sched);
88222 - atomic_long_inc(&rsp->expedited_normal);
88223 + atomic_long_inc_unchecked(&rsp->expedited_normal);
88224 return;
88225 }
88226
88227 @@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
88228 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88229 /* ensure test happens before caller kfree */
88230 smp_mb__before_atomic_inc(); /* ^^^ */
88231 - atomic_long_inc(&rsp->expedited_workdone2);
88232 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88233 return;
88234 }
88235
88236 @@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
88237 * period works for us.
88238 */
88239 get_online_cpus();
88240 - snap = atomic_long_read(&rsp->expedited_start);
88241 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
88242 smp_mb(); /* ensure read is before try_stop_cpus(). */
88243 }
88244 - atomic_long_inc(&rsp->expedited_stoppedcpus);
88245 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88246
88247 /*
88248 * Everyone up to our most recent fetch is covered by our grace
88249 @@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
88250 * than we did already did their update.
88251 */
88252 do {
88253 - atomic_long_inc(&rsp->expedited_done_tries);
88254 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88255 s = atomic_long_read(&rsp->expedited_done);
88256 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88257 /* ensure test happens before caller kfree */
88258 smp_mb__before_atomic_inc(); /* ^^^ */
88259 - atomic_long_inc(&rsp->expedited_done_lost);
88260 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88261 break;
88262 }
88263 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88264 - atomic_long_inc(&rsp->expedited_done_exit);
88265 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88266
88267 put_online_cpus();
88268 }
88269 @@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88270 * ACCESS_ONCE() to prevent the compiler from speculating
88271 * the increment to precede the early-exit check.
88272 */
88273 - ACCESS_ONCE(rsp->n_barrier_done)++;
88274 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88275 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88276 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88277 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88278 @@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88279
88280 /* Increment ->n_barrier_done to prevent duplicate work. */
88281 smp_mb(); /* Keep increment after above mechanism. */
88282 - ACCESS_ONCE(rsp->n_barrier_done)++;
88283 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88284 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88285 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88286 smp_mb(); /* Keep increment before caller's subsequent code. */
88287 @@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88288 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88289 init_callback_list(rdp);
88290 rdp->qlen_lazy = 0;
88291 - ACCESS_ONCE(rdp->qlen) = 0;
88292 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88293 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88294 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88295 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88296 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88297 rdp->cpu = cpu;
88298 rdp->rsp = rsp;
88299 rcu_boot_init_nocb_percpu_data(rdp);
88300 @@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88301 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88302 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88303 rcu_sysidle_init_percpu_data(rdp->dynticks);
88304 - atomic_set(&rdp->dynticks->dynticks,
88305 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88306 + atomic_set_unchecked(&rdp->dynticks->dynticks,
88307 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88308 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88309
88310 /* Add CPU to rcu_node bitmasks. */
88311 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88312 index 52be957..365ded3 100644
88313 --- a/kernel/rcu/tree.h
88314 +++ b/kernel/rcu/tree.h
88315 @@ -87,11 +87,11 @@ struct rcu_dynticks {
88316 long long dynticks_nesting; /* Track irq/process nesting level. */
88317 /* Process level is worth LLONG_MAX/2. */
88318 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88319 - atomic_t dynticks; /* Even value for idle, else odd. */
88320 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88321 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88322 long long dynticks_idle_nesting;
88323 /* irq/process nesting level from idle. */
88324 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
88325 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88326 /* "Idle" excludes userspace execution. */
88327 unsigned long dynticks_idle_jiffies;
88328 /* End of last non-NMI non-idle period. */
88329 @@ -429,17 +429,17 @@ struct rcu_state {
88330 /* _rcu_barrier(). */
88331 /* End of fields guarded by barrier_mutex. */
88332
88333 - atomic_long_t expedited_start; /* Starting ticket. */
88334 - atomic_long_t expedited_done; /* Done ticket. */
88335 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88336 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
88337 - atomic_long_t expedited_workdone1; /* # done by others #1. */
88338 - atomic_long_t expedited_workdone2; /* # done by others #2. */
88339 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
88340 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88341 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
88342 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88343 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88344 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88345 + atomic_long_t expedited_done; /* Done ticket. */
88346 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88347 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88348 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88349 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88350 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88351 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88352 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88353 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88354 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88355
88356 unsigned long jiffies_force_qs; /* Time at which to invoke */
88357 /* force_quiescent_state(). */
88358 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88359 index 08a7652..3598c7e 100644
88360 --- a/kernel/rcu/tree_plugin.h
88361 +++ b/kernel/rcu/tree_plugin.h
88362 @@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88363 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88364 {
88365 return !rcu_preempted_readers_exp(rnp) &&
88366 - ACCESS_ONCE(rnp->expmask) == 0;
88367 + ACCESS_ONCE_RW(rnp->expmask) == 0;
88368 }
88369
88370 /*
88371 @@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
88372
88373 /* Clean up and exit. */
88374 smp_mb(); /* ensure expedited GP seen before counter increment. */
88375 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88376 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88377 unlock_mb_ret:
88378 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88379 mb_ret:
88380 @@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88381 free_cpumask_var(cm);
88382 }
88383
88384 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88385 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88386 .store = &rcu_cpu_kthread_task,
88387 .thread_should_run = rcu_cpu_kthread_should_run,
88388 .thread_fn = rcu_cpu_kthread,
88389 @@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88390 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88391 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88392 cpu, ticks_value, ticks_title,
88393 - atomic_read(&rdtp->dynticks) & 0xfff,
88394 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88395 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88396 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88397 fast_no_hz);
88398 @@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88399
88400 /* Enqueue the callback on the nocb list and update counts. */
88401 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88402 - ACCESS_ONCE(*old_rhpp) = rhp;
88403 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
88404 atomic_long_add(rhcount, &rdp->nocb_q_count);
88405 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88406
88407 @@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
88408 * Extract queued callbacks, update counts, and wait
88409 * for a grace period to elapse.
88410 */
88411 - ACCESS_ONCE(rdp->nocb_head) = NULL;
88412 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88413 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88414 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88415 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88416 - ACCESS_ONCE(rdp->nocb_p_count) += c;
88417 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88418 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88419 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88420 rcu_nocb_wait_gp(rdp);
88421
88422 /* Each pass through the following loop invokes a callback. */
88423 @@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
88424 list = next;
88425 }
88426 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88427 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
88428 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88429 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88430 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88431 rdp->n_nocbs_invoked += c;
88432 }
88433 return 0;
88434 @@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
88435 t = kthread_run(rcu_nocb_kthread, rdp,
88436 "rcuo%c/%d", rsp->abbr, cpu);
88437 BUG_ON(IS_ERR(t));
88438 - ACCESS_ONCE(rdp->nocb_kthread) = t;
88439 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
88440 }
88441 }
88442
88443 @@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
88444
88445 /* Record start of fully idle period. */
88446 j = jiffies;
88447 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
88448 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
88449 smp_mb__before_atomic_inc();
88450 - atomic_inc(&rdtp->dynticks_idle);
88451 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88452 smp_mb__after_atomic_inc();
88453 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
88454 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
88455 }
88456
88457 /*
88458 @@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
88459
88460 /* Record end of idle period. */
88461 smp_mb__before_atomic_inc();
88462 - atomic_inc(&rdtp->dynticks_idle);
88463 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88464 smp_mb__after_atomic_inc();
88465 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
88466 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
88467
88468 /*
88469 * If we are the timekeeping CPU, we are permitted to be non-idle
88470 @@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
88471 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
88472
88473 /* Pick up current idle and NMI-nesting counter and check. */
88474 - cur = atomic_read(&rdtp->dynticks_idle);
88475 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
88476 if (cur & 0x1) {
88477 *isidle = false; /* We are not idle! */
88478 return;
88479 @@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
88480 case RCU_SYSIDLE_NOT:
88481
88482 /* First time all are idle, so note a short idle period. */
88483 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88484 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88485 break;
88486
88487 case RCU_SYSIDLE_SHORT:
88488 @@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
88489 static void rcu_sysidle_cancel(void)
88490 {
88491 smp_mb();
88492 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
88493 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
88494 }
88495
88496 /*
88497 @@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
88498 smp_mb(); /* grace period precedes setting inuse. */
88499
88500 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
88501 - ACCESS_ONCE(rshp->inuse) = 0;
88502 + ACCESS_ONCE_RW(rshp->inuse) = 0;
88503 }
88504
88505 /*
88506 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
88507 index 3596797..f78391c 100644
88508 --- a/kernel/rcu/tree_trace.c
88509 +++ b/kernel/rcu/tree_trace.c
88510 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
88511 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
88512 rdp->passed_quiesce, rdp->qs_pending);
88513 seq_printf(m, " dt=%d/%llx/%d df=%lu",
88514 - atomic_read(&rdp->dynticks->dynticks),
88515 + atomic_read_unchecked(&rdp->dynticks->dynticks),
88516 rdp->dynticks->dynticks_nesting,
88517 rdp->dynticks->dynticks_nmi_nesting,
88518 rdp->dynticks_fqs);
88519 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
88520 struct rcu_state *rsp = (struct rcu_state *)m->private;
88521
88522 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",
88523 - atomic_long_read(&rsp->expedited_start),
88524 + atomic_long_read_unchecked(&rsp->expedited_start),
88525 atomic_long_read(&rsp->expedited_done),
88526 - atomic_long_read(&rsp->expedited_wrap),
88527 - atomic_long_read(&rsp->expedited_tryfail),
88528 - atomic_long_read(&rsp->expedited_workdone1),
88529 - atomic_long_read(&rsp->expedited_workdone2),
88530 - atomic_long_read(&rsp->expedited_normal),
88531 - atomic_long_read(&rsp->expedited_stoppedcpus),
88532 - atomic_long_read(&rsp->expedited_done_tries),
88533 - atomic_long_read(&rsp->expedited_done_lost),
88534 - atomic_long_read(&rsp->expedited_done_exit));
88535 + atomic_long_read_unchecked(&rsp->expedited_wrap),
88536 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
88537 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
88538 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
88539 + atomic_long_read_unchecked(&rsp->expedited_normal),
88540 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
88541 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
88542 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
88543 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
88544 return 0;
88545 }
88546
88547 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
88548 index 6cb3dff..dc5710f 100644
88549 --- a/kernel/rcu/update.c
88550 +++ b/kernel/rcu/update.c
88551 @@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
88552 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
88553 */
88554 if (till_stall_check < 3) {
88555 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
88556 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
88557 till_stall_check = 3;
88558 } else if (till_stall_check > 300) {
88559 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
88560 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
88561 till_stall_check = 300;
88562 }
88563 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
88564 diff --git a/kernel/resource.c b/kernel/resource.c
88565 index 3f285dc..5755f62 100644
88566 --- a/kernel/resource.c
88567 +++ b/kernel/resource.c
88568 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
88569
88570 static int __init ioresources_init(void)
88571 {
88572 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88573 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88574 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
88575 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
88576 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88577 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
88578 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
88579 +#endif
88580 +#else
88581 proc_create("ioports", 0, NULL, &proc_ioports_operations);
88582 proc_create("iomem", 0, NULL, &proc_iomem_operations);
88583 +#endif
88584 return 0;
88585 }
88586 __initcall(ioresources_init);
88587 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
88588 index 4a07353..66b5291 100644
88589 --- a/kernel/sched/auto_group.c
88590 +++ b/kernel/sched/auto_group.c
88591 @@ -11,7 +11,7 @@
88592
88593 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
88594 static struct autogroup autogroup_default;
88595 -static atomic_t autogroup_seq_nr;
88596 +static atomic_unchecked_t autogroup_seq_nr;
88597
88598 void __init autogroup_init(struct task_struct *init_task)
88599 {
88600 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
88601
88602 kref_init(&ag->kref);
88603 init_rwsem(&ag->lock);
88604 - ag->id = atomic_inc_return(&autogroup_seq_nr);
88605 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
88606 ag->tg = tg;
88607 #ifdef CONFIG_RT_GROUP_SCHED
88608 /*
88609 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
88610 index a63f4dc..349bbb0 100644
88611 --- a/kernel/sched/completion.c
88612 +++ b/kernel/sched/completion.c
88613 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
88614 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88615 * or number of jiffies left till timeout) if completed.
88616 */
88617 -long __sched
88618 +long __sched __intentional_overflow(-1)
88619 wait_for_completion_interruptible_timeout(struct completion *x,
88620 unsigned long timeout)
88621 {
88622 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
88623 *
88624 * Return: -ERESTARTSYS if interrupted, 0 if completed.
88625 */
88626 -int __sched wait_for_completion_killable(struct completion *x)
88627 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
88628 {
88629 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
88630 if (t == -ERESTARTSYS)
88631 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
88632 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88633 * or number of jiffies left till timeout) if completed.
88634 */
88635 -long __sched
88636 +long __sched __intentional_overflow(-1)
88637 wait_for_completion_killable_timeout(struct completion *x,
88638 unsigned long timeout)
88639 {
88640 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
88641 index c677510..132bb14 100644
88642 --- a/kernel/sched/core.c
88643 +++ b/kernel/sched/core.c
88644 @@ -1768,7 +1768,7 @@ void set_numabalancing_state(bool enabled)
88645 int sysctl_numa_balancing(struct ctl_table *table, int write,
88646 void __user *buffer, size_t *lenp, loff_t *ppos)
88647 {
88648 - struct ctl_table t;
88649 + ctl_table_no_const t;
88650 int err;
88651 int state = numabalancing_enabled;
88652
88653 @@ -2893,6 +2893,8 @@ int can_nice(const struct task_struct *p, const int nice)
88654 /* convert nice value [19,-20] to rlimit style value [1,40] */
88655 int nice_rlim = 20 - nice;
88656
88657 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
88658 +
88659 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
88660 capable(CAP_SYS_NICE));
88661 }
88662 @@ -2926,7 +2928,8 @@ SYSCALL_DEFINE1(nice, int, increment)
88663 if (nice > 19)
88664 nice = 19;
88665
88666 - if (increment < 0 && !can_nice(current, nice))
88667 + if (increment < 0 && (!can_nice(current, nice) ||
88668 + gr_handle_chroot_nice()))
88669 return -EPERM;
88670
88671 retval = security_task_setnice(current, nice);
88672 @@ -3088,6 +3091,7 @@ recheck:
88673 unsigned long rlim_rtprio =
88674 task_rlimit(p, RLIMIT_RTPRIO);
88675
88676 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
88677 /* can't set/change the rt policy */
88678 if (policy != p->policy && !rlim_rtprio)
88679 return -EPERM;
88680 @@ -4254,7 +4258,7 @@ static void migrate_tasks(unsigned int dead_cpu)
88681
88682 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
88683
88684 -static struct ctl_table sd_ctl_dir[] = {
88685 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
88686 {
88687 .procname = "sched_domain",
88688 .mode = 0555,
88689 @@ -4271,17 +4275,17 @@ static struct ctl_table sd_ctl_root[] = {
88690 {}
88691 };
88692
88693 -static struct ctl_table *sd_alloc_ctl_entry(int n)
88694 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
88695 {
88696 - struct ctl_table *entry =
88697 + ctl_table_no_const *entry =
88698 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
88699
88700 return entry;
88701 }
88702
88703 -static void sd_free_ctl_entry(struct ctl_table **tablep)
88704 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
88705 {
88706 - struct ctl_table *entry;
88707 + ctl_table_no_const *entry;
88708
88709 /*
88710 * In the intermediate directories, both the child directory and
88711 @@ -4289,22 +4293,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
88712 * will always be set. In the lowest directory the names are
88713 * static strings and all have proc handlers.
88714 */
88715 - for (entry = *tablep; entry->mode; entry++) {
88716 - if (entry->child)
88717 - sd_free_ctl_entry(&entry->child);
88718 + for (entry = tablep; entry->mode; entry++) {
88719 + if (entry->child) {
88720 + sd_free_ctl_entry(entry->child);
88721 + pax_open_kernel();
88722 + entry->child = NULL;
88723 + pax_close_kernel();
88724 + }
88725 if (entry->proc_handler == NULL)
88726 kfree(entry->procname);
88727 }
88728
88729 - kfree(*tablep);
88730 - *tablep = NULL;
88731 + kfree(tablep);
88732 }
88733
88734 static int min_load_idx = 0;
88735 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
88736
88737 static void
88738 -set_table_entry(struct ctl_table *entry,
88739 +set_table_entry(ctl_table_no_const *entry,
88740 const char *procname, void *data, int maxlen,
88741 umode_t mode, proc_handler *proc_handler,
88742 bool load_idx)
88743 @@ -4324,7 +4331,7 @@ set_table_entry(struct ctl_table *entry,
88744 static struct ctl_table *
88745 sd_alloc_ctl_domain_table(struct sched_domain *sd)
88746 {
88747 - struct ctl_table *table = sd_alloc_ctl_entry(13);
88748 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
88749
88750 if (table == NULL)
88751 return NULL;
88752 @@ -4359,9 +4366,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
88753 return table;
88754 }
88755
88756 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
88757 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
88758 {
88759 - struct ctl_table *entry, *table;
88760 + ctl_table_no_const *entry, *table;
88761 struct sched_domain *sd;
88762 int domain_num = 0, i;
88763 char buf[32];
88764 @@ -4388,11 +4395,13 @@ static struct ctl_table_header *sd_sysctl_header;
88765 static void register_sched_domain_sysctl(void)
88766 {
88767 int i, cpu_num = num_possible_cpus();
88768 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
88769 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
88770 char buf[32];
88771
88772 WARN_ON(sd_ctl_dir[0].child);
88773 + pax_open_kernel();
88774 sd_ctl_dir[0].child = entry;
88775 + pax_close_kernel();
88776
88777 if (entry == NULL)
88778 return;
88779 @@ -4415,8 +4424,12 @@ static void unregister_sched_domain_sysctl(void)
88780 if (sd_sysctl_header)
88781 unregister_sysctl_table(sd_sysctl_header);
88782 sd_sysctl_header = NULL;
88783 - if (sd_ctl_dir[0].child)
88784 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
88785 + if (sd_ctl_dir[0].child) {
88786 + sd_free_ctl_entry(sd_ctl_dir[0].child);
88787 + pax_open_kernel();
88788 + sd_ctl_dir[0].child = NULL;
88789 + pax_close_kernel();
88790 + }
88791 }
88792 #else
88793 static void register_sched_domain_sysctl(void)
88794 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
88795 index e64b079..a46bd34 100644
88796 --- a/kernel/sched/fair.c
88797 +++ b/kernel/sched/fair.c
88798 @@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
88799
88800 static void reset_ptenuma_scan(struct task_struct *p)
88801 {
88802 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
88803 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
88804 p->mm->numa_scan_offset = 0;
88805 }
88806
88807 @@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
88808 * run_rebalance_domains is triggered when needed from the scheduler tick.
88809 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
88810 */
88811 -static void run_rebalance_domains(struct softirq_action *h)
88812 +static __latent_entropy void run_rebalance_domains(void)
88813 {
88814 int this_cpu = smp_processor_id();
88815 struct rq *this_rq = cpu_rq(this_cpu);
88816 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
88817 index 88c85b2..a1dec86 100644
88818 --- a/kernel/sched/sched.h
88819 +++ b/kernel/sched/sched.h
88820 @@ -1035,7 +1035,7 @@ struct sched_class {
88821 #ifdef CONFIG_FAIR_GROUP_SCHED
88822 void (*task_move_group) (struct task_struct *p, int on_rq);
88823 #endif
88824 -};
88825 +} __do_const;
88826
88827 #define sched_class_highest (&stop_sched_class)
88828 #define for_each_class(class) \
88829 diff --git a/kernel/signal.c b/kernel/signal.c
88830 index 940b30e..7fd6041 100644
88831 --- a/kernel/signal.c
88832 +++ b/kernel/signal.c
88833 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
88834
88835 int print_fatal_signals __read_mostly;
88836
88837 -static void __user *sig_handler(struct task_struct *t, int sig)
88838 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
88839 {
88840 return t->sighand->action[sig - 1].sa.sa_handler;
88841 }
88842
88843 -static int sig_handler_ignored(void __user *handler, int sig)
88844 +static int sig_handler_ignored(__sighandler_t handler, int sig)
88845 {
88846 /* Is it explicitly or implicitly ignored? */
88847 return handler == SIG_IGN ||
88848 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
88849
88850 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
88851 {
88852 - void __user *handler;
88853 + __sighandler_t handler;
88854
88855 handler = sig_handler(t, sig);
88856
88857 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
88858 atomic_inc(&user->sigpending);
88859 rcu_read_unlock();
88860
88861 + if (!override_rlimit)
88862 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
88863 +
88864 if (override_rlimit ||
88865 atomic_read(&user->sigpending) <=
88866 task_rlimit(t, RLIMIT_SIGPENDING)) {
88867 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
88868
88869 int unhandled_signal(struct task_struct *tsk, int sig)
88870 {
88871 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
88872 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
88873 if (is_global_init(tsk))
88874 return 1;
88875 if (handler != SIG_IGN && handler != SIG_DFL)
88876 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
88877 }
88878 }
88879
88880 + /* allow glibc communication via tgkill to other threads in our
88881 + thread group */
88882 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
88883 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
88884 + && gr_handle_signal(t, sig))
88885 + return -EPERM;
88886 +
88887 return security_task_kill(t, info, sig, 0);
88888 }
88889
88890 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
88891 return send_signal(sig, info, p, 1);
88892 }
88893
88894 -static int
88895 +int
88896 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88897 {
88898 return send_signal(sig, info, t, 0);
88899 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88900 unsigned long int flags;
88901 int ret, blocked, ignored;
88902 struct k_sigaction *action;
88903 + int is_unhandled = 0;
88904
88905 spin_lock_irqsave(&t->sighand->siglock, flags);
88906 action = &t->sighand->action[sig-1];
88907 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88908 }
88909 if (action->sa.sa_handler == SIG_DFL)
88910 t->signal->flags &= ~SIGNAL_UNKILLABLE;
88911 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
88912 + is_unhandled = 1;
88913 ret = specific_send_sig_info(sig, info, t);
88914 spin_unlock_irqrestore(&t->sighand->siglock, flags);
88915
88916 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
88917 + normal operation */
88918 + if (is_unhandled) {
88919 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
88920 + gr_handle_crash(t, sig);
88921 + }
88922 +
88923 return ret;
88924 }
88925
88926 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
88927 ret = check_kill_permission(sig, info, p);
88928 rcu_read_unlock();
88929
88930 - if (!ret && sig)
88931 + if (!ret && sig) {
88932 ret = do_send_sig_info(sig, info, p, true);
88933 + if (!ret)
88934 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
88935 + }
88936
88937 return ret;
88938 }
88939 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
88940 int error = -ESRCH;
88941
88942 rcu_read_lock();
88943 - p = find_task_by_vpid(pid);
88944 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
88945 + /* allow glibc communication via tgkill to other threads in our
88946 + thread group */
88947 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
88948 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
88949 + p = find_task_by_vpid_unrestricted(pid);
88950 + else
88951 +#endif
88952 + p = find_task_by_vpid(pid);
88953 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
88954 error = check_kill_permission(sig, info, p);
88955 /*
88956 @@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
88957 }
88958 seg = get_fs();
88959 set_fs(KERNEL_DS);
88960 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
88961 - (stack_t __force __user *) &uoss,
88962 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
88963 + (stack_t __force_user *) &uoss,
88964 compat_user_stack_pointer());
88965 set_fs(seg);
88966 if (ret >= 0 && uoss_ptr) {
88967 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
88968 index eb89e18..a4e6792 100644
88969 --- a/kernel/smpboot.c
88970 +++ b/kernel/smpboot.c
88971 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
88972 }
88973 smpboot_unpark_thread(plug_thread, cpu);
88974 }
88975 - list_add(&plug_thread->list, &hotplug_threads);
88976 + pax_list_add(&plug_thread->list, &hotplug_threads);
88977 out:
88978 mutex_unlock(&smpboot_threads_lock);
88979 return ret;
88980 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
88981 {
88982 get_online_cpus();
88983 mutex_lock(&smpboot_threads_lock);
88984 - list_del(&plug_thread->list);
88985 + pax_list_del(&plug_thread->list);
88986 smpboot_destroy_threads(plug_thread);
88987 mutex_unlock(&smpboot_threads_lock);
88988 put_online_cpus();
88989 diff --git a/kernel/softirq.c b/kernel/softirq.c
88990 index 11025cc..bc0e4dc 100644
88991 --- a/kernel/softirq.c
88992 +++ b/kernel/softirq.c
88993 @@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
88994 EXPORT_SYMBOL(irq_stat);
88995 #endif
88996
88997 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
88998 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
88999
89000 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89001
89002 -char *softirq_to_name[NR_SOFTIRQS] = {
89003 +const char * const softirq_to_name[NR_SOFTIRQS] = {
89004 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
89005 "TASKLET", "SCHED", "HRTIMER", "RCU"
89006 };
89007 @@ -250,7 +250,7 @@ restart:
89008 kstat_incr_softirqs_this_cpu(vec_nr);
89009
89010 trace_softirq_entry(vec_nr);
89011 - h->action(h);
89012 + h->action();
89013 trace_softirq_exit(vec_nr);
89014 if (unlikely(prev_count != preempt_count())) {
89015 printk(KERN_ERR "huh, entered softirq %u %s %p"
89016 @@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89017 or_softirq_pending(1UL << nr);
89018 }
89019
89020 -void open_softirq(int nr, void (*action)(struct softirq_action *))
89021 +void __init open_softirq(int nr, void (*action)(void))
89022 {
89023 softirq_vec[nr].action = action;
89024 }
89025 @@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89026
89027 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89028
89029 -static void tasklet_action(struct softirq_action *a)
89030 +static __latent_entropy void tasklet_action(void)
89031 {
89032 struct tasklet_struct *list;
89033
89034 @@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
89035 }
89036 }
89037
89038 -static void tasklet_hi_action(struct softirq_action *a)
89039 +static __latent_entropy void tasklet_hi_action(void)
89040 {
89041 struct tasklet_struct *list;
89042
89043 @@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
89044 .notifier_call = cpu_callback
89045 };
89046
89047 -static struct smp_hotplug_thread softirq_threads = {
89048 +static struct smp_hotplug_thread softirq_threads __read_only = {
89049 .store = &ksoftirqd,
89050 .thread_should_run = ksoftirqd_should_run,
89051 .thread_fn = run_ksoftirqd,
89052 diff --git a/kernel/sys.c b/kernel/sys.c
89053 index c723113..46bf922 100644
89054 --- a/kernel/sys.c
89055 +++ b/kernel/sys.c
89056 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89057 error = -EACCES;
89058 goto out;
89059 }
89060 +
89061 + if (gr_handle_chroot_setpriority(p, niceval)) {
89062 + error = -EACCES;
89063 + goto out;
89064 + }
89065 +
89066 no_nice = security_task_setnice(p, niceval);
89067 if (no_nice) {
89068 error = no_nice;
89069 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89070 goto error;
89071 }
89072
89073 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89074 + goto error;
89075 +
89076 if (rgid != (gid_t) -1 ||
89077 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89078 new->sgid = new->egid;
89079 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89080 old = current_cred();
89081
89082 retval = -EPERM;
89083 +
89084 + if (gr_check_group_change(kgid, kgid, kgid))
89085 + goto error;
89086 +
89087 if (ns_capable(old->user_ns, CAP_SETGID))
89088 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89089 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89090 @@ -403,7 +416,7 @@ error:
89091 /*
89092 * change the user struct in a credentials set to match the new UID
89093 */
89094 -static int set_user(struct cred *new)
89095 +int set_user(struct cred *new)
89096 {
89097 struct user_struct *new_user;
89098
89099 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89100 goto error;
89101 }
89102
89103 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89104 + goto error;
89105 +
89106 if (!uid_eq(new->uid, old->uid)) {
89107 retval = set_user(new);
89108 if (retval < 0)
89109 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89110 old = current_cred();
89111
89112 retval = -EPERM;
89113 +
89114 + if (gr_check_crash_uid(kuid))
89115 + goto error;
89116 + if (gr_check_user_change(kuid, kuid, kuid))
89117 + goto error;
89118 +
89119 if (ns_capable(old->user_ns, CAP_SETUID)) {
89120 new->suid = new->uid = kuid;
89121 if (!uid_eq(kuid, old->uid)) {
89122 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89123 goto error;
89124 }
89125
89126 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
89127 + goto error;
89128 +
89129 if (ruid != (uid_t) -1) {
89130 new->uid = kruid;
89131 if (!uid_eq(kruid, old->uid)) {
89132 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89133 goto error;
89134 }
89135
89136 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
89137 + goto error;
89138 +
89139 if (rgid != (gid_t) -1)
89140 new->gid = krgid;
89141 if (egid != (gid_t) -1)
89142 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89143 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89144 ns_capable(old->user_ns, CAP_SETUID)) {
89145 if (!uid_eq(kuid, old->fsuid)) {
89146 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89147 + goto error;
89148 +
89149 new->fsuid = kuid;
89150 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89151 goto change_okay;
89152 }
89153 }
89154
89155 +error:
89156 abort_creds(new);
89157 return old_fsuid;
89158
89159 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89160 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89161 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89162 ns_capable(old->user_ns, CAP_SETGID)) {
89163 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89164 + goto error;
89165 +
89166 if (!gid_eq(kgid, old->fsgid)) {
89167 new->fsgid = kgid;
89168 goto change_okay;
89169 }
89170 }
89171
89172 +error:
89173 abort_creds(new);
89174 return old_fsgid;
89175
89176 @@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89177 return -EFAULT;
89178
89179 down_read(&uts_sem);
89180 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
89181 + error = __copy_to_user(name->sysname, &utsname()->sysname,
89182 __OLD_UTS_LEN);
89183 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89184 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89185 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
89186 __OLD_UTS_LEN);
89187 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89188 - error |= __copy_to_user(&name->release, &utsname()->release,
89189 + error |= __copy_to_user(name->release, &utsname()->release,
89190 __OLD_UTS_LEN);
89191 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89192 - error |= __copy_to_user(&name->version, &utsname()->version,
89193 + error |= __copy_to_user(name->version, &utsname()->version,
89194 __OLD_UTS_LEN);
89195 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89196 - error |= __copy_to_user(&name->machine, &utsname()->machine,
89197 + error |= __copy_to_user(name->machine, &utsname()->machine,
89198 __OLD_UTS_LEN);
89199 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89200 up_read(&uts_sem);
89201 @@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89202 */
89203 new_rlim->rlim_cur = 1;
89204 }
89205 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89206 + is changed to a lower value. Since tasks can be created by the same
89207 + user in between this limit change and an execve by this task, force
89208 + a recheck only for this task by setting PF_NPROC_EXCEEDED
89209 + */
89210 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89211 + tsk->flags |= PF_NPROC_EXCEEDED;
89212 }
89213 if (!retval) {
89214 if (old_rlim)
89215 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89216 index 06962ba..a54d45e 100644
89217 --- a/kernel/sysctl.c
89218 +++ b/kernel/sysctl.c
89219 @@ -93,7 +93,6 @@
89220
89221
89222 #if defined(CONFIG_SYSCTL)
89223 -
89224 /* External variables not in a header file. */
89225 extern int sysctl_overcommit_memory;
89226 extern int sysctl_overcommit_ratio;
89227 @@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
89228
89229 /* Constants used for minimum and maximum */
89230 #ifdef CONFIG_LOCKUP_DETECTOR
89231 -static int sixty = 60;
89232 +static int sixty __read_only = 60;
89233 #endif
89234
89235 -static int zero;
89236 -static int __maybe_unused one = 1;
89237 -static int __maybe_unused two = 2;
89238 -static int __maybe_unused three = 3;
89239 -static unsigned long one_ul = 1;
89240 -static int one_hundred = 100;
89241 +static int neg_one __read_only = -1;
89242 +static int zero __read_only = 0;
89243 +static int __maybe_unused one __read_only = 1;
89244 +static int __maybe_unused two __read_only = 2;
89245 +static int __maybe_unused three __read_only = 3;
89246 +static unsigned long one_ul __read_only = 1;
89247 +static int one_hundred __read_only = 100;
89248 #ifdef CONFIG_PRINTK
89249 -static int ten_thousand = 10000;
89250 +static int ten_thousand __read_only = 10000;
89251 #endif
89252
89253 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89254 @@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
89255 void __user *buffer, size_t *lenp, loff_t *ppos);
89256 #endif
89257
89258 -#ifdef CONFIG_PRINTK
89259 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89260 void __user *buffer, size_t *lenp, loff_t *ppos);
89261 -#endif
89262
89263 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89264 void __user *buffer, size_t *lenp, loff_t *ppos);
89265 @@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89266
89267 #endif
89268
89269 +extern struct ctl_table grsecurity_table[];
89270 +
89271 static struct ctl_table kern_table[];
89272 static struct ctl_table vm_table[];
89273 static struct ctl_table fs_table[];
89274 @@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
89275 int sysctl_legacy_va_layout;
89276 #endif
89277
89278 +#ifdef CONFIG_PAX_SOFTMODE
89279 +static ctl_table pax_table[] = {
89280 + {
89281 + .procname = "softmode",
89282 + .data = &pax_softmode,
89283 + .maxlen = sizeof(unsigned int),
89284 + .mode = 0600,
89285 + .proc_handler = &proc_dointvec,
89286 + },
89287 +
89288 + { }
89289 +};
89290 +#endif
89291 +
89292 /* The default sysctl tables: */
89293
89294 static struct ctl_table sysctl_base_table[] = {
89295 @@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
89296 #endif
89297
89298 static struct ctl_table kern_table[] = {
89299 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89300 + {
89301 + .procname = "grsecurity",
89302 + .mode = 0500,
89303 + .child = grsecurity_table,
89304 + },
89305 +#endif
89306 +
89307 +#ifdef CONFIG_PAX_SOFTMODE
89308 + {
89309 + .procname = "pax",
89310 + .mode = 0500,
89311 + .child = pax_table,
89312 + },
89313 +#endif
89314 +
89315 {
89316 .procname = "sched_child_runs_first",
89317 .data = &sysctl_sched_child_runs_first,
89318 @@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
89319 .data = &modprobe_path,
89320 .maxlen = KMOD_PATH_LEN,
89321 .mode = 0644,
89322 - .proc_handler = proc_dostring,
89323 + .proc_handler = proc_dostring_modpriv,
89324 },
89325 {
89326 .procname = "modules_disabled",
89327 @@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
89328 .extra1 = &zero,
89329 .extra2 = &one,
89330 },
89331 +#endif
89332 {
89333 .procname = "kptr_restrict",
89334 .data = &kptr_restrict,
89335 .maxlen = sizeof(int),
89336 .mode = 0644,
89337 .proc_handler = proc_dointvec_minmax_sysadmin,
89338 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89339 + .extra1 = &two,
89340 +#else
89341 .extra1 = &zero,
89342 +#endif
89343 .extra2 = &two,
89344 },
89345 -#endif
89346 {
89347 .procname = "ngroups_max",
89348 .data = &ngroups_max,
89349 @@ -1048,10 +1082,17 @@ static struct ctl_table kern_table[] = {
89350 */
89351 {
89352 .procname = "perf_event_paranoid",
89353 - .data = &sysctl_perf_event_paranoid,
89354 - .maxlen = sizeof(sysctl_perf_event_paranoid),
89355 + .data = &sysctl_perf_event_legitimately_concerned,
89356 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89357 .mode = 0644,
89358 - .proc_handler = proc_dointvec,
89359 + /* go ahead, be a hero */
89360 + .proc_handler = proc_dointvec_minmax_sysadmin,
89361 + .extra1 = &neg_one,
89362 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89363 + .extra2 = &three,
89364 +#else
89365 + .extra2 = &two,
89366 +#endif
89367 },
89368 {
89369 .procname = "perf_event_mlock_kb",
89370 @@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
89371 .proc_handler = proc_dointvec_minmax,
89372 .extra1 = &zero,
89373 },
89374 + {
89375 + .procname = "heap_stack_gap",
89376 + .data = &sysctl_heap_stack_gap,
89377 + .maxlen = sizeof(sysctl_heap_stack_gap),
89378 + .mode = 0644,
89379 + .proc_handler = proc_doulongvec_minmax,
89380 + },
89381 #else
89382 {
89383 .procname = "nr_trim_pages",
89384 @@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
89385 buffer, lenp, ppos);
89386 }
89387
89388 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89389 + void __user *buffer, size_t *lenp, loff_t *ppos)
89390 +{
89391 + if (write && !capable(CAP_SYS_MODULE))
89392 + return -EPERM;
89393 +
89394 + return _proc_do_string(table->data, table->maxlen, write,
89395 + buffer, lenp, ppos);
89396 +}
89397 +
89398 static size_t proc_skip_spaces(char **buf)
89399 {
89400 size_t ret;
89401 @@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89402 len = strlen(tmp);
89403 if (len > *size)
89404 len = *size;
89405 + if (len > sizeof(tmp))
89406 + len = sizeof(tmp);
89407 if (copy_to_user(*buf, tmp, len))
89408 return -EFAULT;
89409 *size -= len;
89410 @@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89411 static int proc_taint(struct ctl_table *table, int write,
89412 void __user *buffer, size_t *lenp, loff_t *ppos)
89413 {
89414 - struct ctl_table t;
89415 + ctl_table_no_const t;
89416 unsigned long tmptaint = get_taint();
89417 int err;
89418
89419 @@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
89420 return err;
89421 }
89422
89423 -#ifdef CONFIG_PRINTK
89424 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89425 void __user *buffer, size_t *lenp, loff_t *ppos)
89426 {
89427 @@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89428
89429 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
89430 }
89431 -#endif
89432
89433 struct do_proc_dointvec_minmax_conv_param {
89434 int *min;
89435 @@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
89436 return -ENOSYS;
89437 }
89438
89439 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89440 + void __user *buffer, size_t *lenp, loff_t *ppos)
89441 +{
89442 + return -ENOSYS;
89443 +}
89444 +
89445 int proc_dointvec(struct ctl_table *table, int write,
89446 void __user *buffer, size_t *lenp, loff_t *ppos)
89447 {
89448 @@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
89449 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
89450 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
89451 EXPORT_SYMBOL(proc_dostring);
89452 +EXPORT_SYMBOL(proc_dostring_modpriv);
89453 EXPORT_SYMBOL(proc_doulongvec_minmax);
89454 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
89455 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
89456 index 13d2f7c..c93d0b0 100644
89457 --- a/kernel/taskstats.c
89458 +++ b/kernel/taskstats.c
89459 @@ -28,9 +28,12 @@
89460 #include <linux/fs.h>
89461 #include <linux/file.h>
89462 #include <linux/pid_namespace.h>
89463 +#include <linux/grsecurity.h>
89464 #include <net/genetlink.h>
89465 #include <linux/atomic.h>
89466
89467 +extern int gr_is_taskstats_denied(int pid);
89468 +
89469 /*
89470 * Maximum length of a cpumask that can be specified in
89471 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
89472 @@ -576,6 +579,9 @@ err:
89473
89474 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
89475 {
89476 + if (gr_is_taskstats_denied(current->pid))
89477 + return -EACCES;
89478 +
89479 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
89480 return cmd_attr_register_cpumask(info);
89481 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
89482 diff --git a/kernel/time.c b/kernel/time.c
89483 index 7c7964c..2a0d412 100644
89484 --- a/kernel/time.c
89485 +++ b/kernel/time.c
89486 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
89487 return error;
89488
89489 if (tz) {
89490 + /* we log in do_settimeofday called below, so don't log twice
89491 + */
89492 + if (!tv)
89493 + gr_log_timechange();
89494 +
89495 sys_tz = *tz;
89496 update_vsyscall_tz();
89497 if (firsttime) {
89498 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
89499 index 88c9c65..7497ebc 100644
89500 --- a/kernel/time/alarmtimer.c
89501 +++ b/kernel/time/alarmtimer.c
89502 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
89503 struct platform_device *pdev;
89504 int error = 0;
89505 int i;
89506 - struct k_clock alarm_clock = {
89507 + static struct k_clock alarm_clock = {
89508 .clock_getres = alarm_clock_getres,
89509 .clock_get = alarm_clock_get,
89510 .timer_create = alarm_timer_create,
89511 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
89512 index b415457..c26876d 100644
89513 --- a/kernel/time/timekeeping.c
89514 +++ b/kernel/time/timekeeping.c
89515 @@ -15,6 +15,7 @@
89516 #include <linux/init.h>
89517 #include <linux/mm.h>
89518 #include <linux/sched.h>
89519 +#include <linux/grsecurity.h>
89520 #include <linux/syscore_ops.h>
89521 #include <linux/clocksource.h>
89522 #include <linux/jiffies.h>
89523 @@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
89524 if (!timespec_valid_strict(tv))
89525 return -EINVAL;
89526
89527 + gr_log_timechange();
89528 +
89529 raw_spin_lock_irqsave(&timekeeper_lock, flags);
89530 write_seqcount_begin(&timekeeper_seq);
89531
89532 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
89533 index 61ed862..3b52c65 100644
89534 --- a/kernel/time/timer_list.c
89535 +++ b/kernel/time/timer_list.c
89536 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
89537
89538 static void print_name_offset(struct seq_file *m, void *sym)
89539 {
89540 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89541 + SEQ_printf(m, "<%p>", NULL);
89542 +#else
89543 char symname[KSYM_NAME_LEN];
89544
89545 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
89546 SEQ_printf(m, "<%pK>", sym);
89547 else
89548 SEQ_printf(m, "%s", symname);
89549 +#endif
89550 }
89551
89552 static void
89553 @@ -119,7 +123,11 @@ next_one:
89554 static void
89555 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
89556 {
89557 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89558 + SEQ_printf(m, " .base: %p\n", NULL);
89559 +#else
89560 SEQ_printf(m, " .base: %pK\n", base);
89561 +#endif
89562 SEQ_printf(m, " .index: %d\n",
89563 base->index);
89564 SEQ_printf(m, " .resolution: %Lu nsecs\n",
89565 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
89566 {
89567 struct proc_dir_entry *pe;
89568
89569 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89570 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
89571 +#else
89572 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
89573 +#endif
89574 if (!pe)
89575 return -ENOMEM;
89576 return 0;
89577 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
89578 index 1fb08f2..ca4bb1e 100644
89579 --- a/kernel/time/timer_stats.c
89580 +++ b/kernel/time/timer_stats.c
89581 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
89582 static unsigned long nr_entries;
89583 static struct entry entries[MAX_ENTRIES];
89584
89585 -static atomic_t overflow_count;
89586 +static atomic_unchecked_t overflow_count;
89587
89588 /*
89589 * The entries are in a hash-table, for fast lookup:
89590 @@ -140,7 +140,7 @@ static void reset_entries(void)
89591 nr_entries = 0;
89592 memset(entries, 0, sizeof(entries));
89593 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
89594 - atomic_set(&overflow_count, 0);
89595 + atomic_set_unchecked(&overflow_count, 0);
89596 }
89597
89598 static struct entry *alloc_entry(void)
89599 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89600 if (likely(entry))
89601 entry->count++;
89602 else
89603 - atomic_inc(&overflow_count);
89604 + atomic_inc_unchecked(&overflow_count);
89605
89606 out_unlock:
89607 raw_spin_unlock_irqrestore(lock, flags);
89608 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89609
89610 static void print_name_offset(struct seq_file *m, unsigned long addr)
89611 {
89612 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89613 + seq_printf(m, "<%p>", NULL);
89614 +#else
89615 char symname[KSYM_NAME_LEN];
89616
89617 if (lookup_symbol_name(addr, symname) < 0)
89618 - seq_printf(m, "<%p>", (void *)addr);
89619 + seq_printf(m, "<%pK>", (void *)addr);
89620 else
89621 seq_printf(m, "%s", symname);
89622 +#endif
89623 }
89624
89625 static int tstats_show(struct seq_file *m, void *v)
89626 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
89627
89628 seq_puts(m, "Timer Stats Version: v0.3\n");
89629 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
89630 - if (atomic_read(&overflow_count))
89631 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
89632 + if (atomic_read_unchecked(&overflow_count))
89633 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
89634 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
89635
89636 for (i = 0; i < nr_entries; i++) {
89637 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
89638 {
89639 struct proc_dir_entry *pe;
89640
89641 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89642 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
89643 +#else
89644 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
89645 +#endif
89646 if (!pe)
89647 return -ENOMEM;
89648 return 0;
89649 diff --git a/kernel/timer.c b/kernel/timer.c
89650 index accfd24..e00f0c0 100644
89651 --- a/kernel/timer.c
89652 +++ b/kernel/timer.c
89653 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
89654 /*
89655 * This function runs timers and the timer-tq in bottom half context.
89656 */
89657 -static void run_timer_softirq(struct softirq_action *h)
89658 +static __latent_entropy void run_timer_softirq(void)
89659 {
89660 struct tvec_base *base = __this_cpu_read(tvec_bases);
89661
89662 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
89663 *
89664 * In all cases the return value is guaranteed to be non-negative.
89665 */
89666 -signed long __sched schedule_timeout(signed long timeout)
89667 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
89668 {
89669 struct timer_list timer;
89670 unsigned long expire;
89671 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
89672 index f785aef..59f1b18 100644
89673 --- a/kernel/trace/blktrace.c
89674 +++ b/kernel/trace/blktrace.c
89675 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
89676 struct blk_trace *bt = filp->private_data;
89677 char buf[16];
89678
89679 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
89680 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
89681
89682 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
89683 }
89684 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
89685 return 1;
89686
89687 bt = buf->chan->private_data;
89688 - atomic_inc(&bt->dropped);
89689 + atomic_inc_unchecked(&bt->dropped);
89690 return 0;
89691 }
89692
89693 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
89694
89695 bt->dir = dir;
89696 bt->dev = dev;
89697 - atomic_set(&bt->dropped, 0);
89698 + atomic_set_unchecked(&bt->dropped, 0);
89699 INIT_LIST_HEAD(&bt->running_list);
89700
89701 ret = -EIO;
89702 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
89703 index 38463d2..68abe92 100644
89704 --- a/kernel/trace/ftrace.c
89705 +++ b/kernel/trace/ftrace.c
89706 @@ -1978,12 +1978,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
89707 if (unlikely(ftrace_disabled))
89708 return 0;
89709
89710 + ret = ftrace_arch_code_modify_prepare();
89711 + FTRACE_WARN_ON(ret);
89712 + if (ret)
89713 + return 0;
89714 +
89715 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
89716 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
89717 if (ret) {
89718 ftrace_bug(ret, ip);
89719 - return 0;
89720 }
89721 - return 1;
89722 + return ret ? 0 : 1;
89723 }
89724
89725 /*
89726 @@ -4190,8 +4195,10 @@ static int ftrace_process_locs(struct module *mod,
89727 if (!count)
89728 return 0;
89729
89730 + pax_open_kernel();
89731 sort(start, count, sizeof(*start),
89732 ftrace_cmp_ips, ftrace_swap_ips);
89733 + pax_close_kernel();
89734
89735 start_pg = ftrace_allocate_pages(count);
89736 if (!start_pg)
89737 @@ -4922,8 +4929,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
89738 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
89739
89740 static int ftrace_graph_active;
89741 -static struct notifier_block ftrace_suspend_notifier;
89742 -
89743 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
89744 {
89745 return 0;
89746 @@ -5099,6 +5104,10 @@ static void update_function_graph_func(void)
89747 ftrace_graph_entry = ftrace_graph_entry_test;
89748 }
89749
89750 +static struct notifier_block ftrace_suspend_notifier = {
89751 + .notifier_call = ftrace_suspend_notifier_call
89752 +};
89753 +
89754 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89755 trace_func_graph_ent_t entryfunc)
89756 {
89757 @@ -5112,7 +5121,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89758 goto out;
89759 }
89760
89761 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
89762 register_pm_notifier(&ftrace_suspend_notifier);
89763
89764 ftrace_graph_active++;
89765 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
89766 index 0e337ee..3370631 100644
89767 --- a/kernel/trace/ring_buffer.c
89768 +++ b/kernel/trace/ring_buffer.c
89769 @@ -352,9 +352,9 @@ struct buffer_data_page {
89770 */
89771 struct buffer_page {
89772 struct list_head list; /* list of buffer pages */
89773 - local_t write; /* index for next write */
89774 + local_unchecked_t write; /* index for next write */
89775 unsigned read; /* index for next read */
89776 - local_t entries; /* entries on this page */
89777 + local_unchecked_t entries; /* entries on this page */
89778 unsigned long real_end; /* real end of data */
89779 struct buffer_data_page *page; /* Actual data page */
89780 };
89781 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
89782 unsigned long last_overrun;
89783 local_t entries_bytes;
89784 local_t entries;
89785 - local_t overrun;
89786 - local_t commit_overrun;
89787 + local_unchecked_t overrun;
89788 + local_unchecked_t commit_overrun;
89789 local_t dropped_events;
89790 local_t committing;
89791 local_t commits;
89792 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
89793 *
89794 * We add a counter to the write field to denote this.
89795 */
89796 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
89797 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
89798 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
89799 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
89800
89801 /*
89802 * Just make sure we have seen our old_write and synchronize
89803 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
89804 * cmpxchg to only update if an interrupt did not already
89805 * do it for us. If the cmpxchg fails, we don't care.
89806 */
89807 - (void)local_cmpxchg(&next_page->write, old_write, val);
89808 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
89809 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
89810 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
89811
89812 /*
89813 * No need to worry about races with clearing out the commit.
89814 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
89815
89816 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
89817 {
89818 - return local_read(&bpage->entries) & RB_WRITE_MASK;
89819 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
89820 }
89821
89822 static inline unsigned long rb_page_write(struct buffer_page *bpage)
89823 {
89824 - return local_read(&bpage->write) & RB_WRITE_MASK;
89825 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
89826 }
89827
89828 static int
89829 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
89830 * bytes consumed in ring buffer from here.
89831 * Increment overrun to account for the lost events.
89832 */
89833 - local_add(page_entries, &cpu_buffer->overrun);
89834 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
89835 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89836 }
89837
89838 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
89839 * it is our responsibility to update
89840 * the counters.
89841 */
89842 - local_add(entries, &cpu_buffer->overrun);
89843 + local_add_unchecked(entries, &cpu_buffer->overrun);
89844 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89845
89846 /*
89847 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89848 if (tail == BUF_PAGE_SIZE)
89849 tail_page->real_end = 0;
89850
89851 - local_sub(length, &tail_page->write);
89852 + local_sub_unchecked(length, &tail_page->write);
89853 return;
89854 }
89855
89856 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89857 rb_event_set_padding(event);
89858
89859 /* Set the write back to the previous setting */
89860 - local_sub(length, &tail_page->write);
89861 + local_sub_unchecked(length, &tail_page->write);
89862 return;
89863 }
89864
89865 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89866
89867 /* Set write to end of buffer */
89868 length = (tail + length) - BUF_PAGE_SIZE;
89869 - local_sub(length, &tail_page->write);
89870 + local_sub_unchecked(length, &tail_page->write);
89871 }
89872
89873 /*
89874 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
89875 * about it.
89876 */
89877 if (unlikely(next_page == commit_page)) {
89878 - local_inc(&cpu_buffer->commit_overrun);
89879 + local_inc_unchecked(&cpu_buffer->commit_overrun);
89880 goto out_reset;
89881 }
89882
89883 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
89884 cpu_buffer->tail_page) &&
89885 (cpu_buffer->commit_page ==
89886 cpu_buffer->reader_page))) {
89887 - local_inc(&cpu_buffer->commit_overrun);
89888 + local_inc_unchecked(&cpu_buffer->commit_overrun);
89889 goto out_reset;
89890 }
89891 }
89892 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
89893 length += RB_LEN_TIME_EXTEND;
89894
89895 tail_page = cpu_buffer->tail_page;
89896 - write = local_add_return(length, &tail_page->write);
89897 + write = local_add_return_unchecked(length, &tail_page->write);
89898
89899 /* set write to only the index of the write */
89900 write &= RB_WRITE_MASK;
89901 @@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
89902 kmemcheck_annotate_bitfield(event, bitfield);
89903 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
89904
89905 - local_inc(&tail_page->entries);
89906 + local_inc_unchecked(&tail_page->entries);
89907
89908 /*
89909 * If this is the first commit on the page, then update
89910 @@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
89911
89912 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
89913 unsigned long write_mask =
89914 - local_read(&bpage->write) & ~RB_WRITE_MASK;
89915 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
89916 unsigned long event_length = rb_event_length(event);
89917 /*
89918 * This is on the tail page. It is possible that
89919 @@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
89920 */
89921 old_index += write_mask;
89922 new_index += write_mask;
89923 - index = local_cmpxchg(&bpage->write, old_index, new_index);
89924 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
89925 if (index == old_index) {
89926 /* update counters */
89927 local_sub(event_length, &cpu_buffer->entries_bytes);
89928 @@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
89929
89930 /* Do the likely case first */
89931 if (likely(bpage->page == (void *)addr)) {
89932 - local_dec(&bpage->entries);
89933 + local_dec_unchecked(&bpage->entries);
89934 return;
89935 }
89936
89937 @@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
89938 start = bpage;
89939 do {
89940 if (bpage->page == (void *)addr) {
89941 - local_dec(&bpage->entries);
89942 + local_dec_unchecked(&bpage->entries);
89943 return;
89944 }
89945 rb_inc_page(cpu_buffer, &bpage);
89946 @@ -3146,7 +3146,7 @@ static inline unsigned long
89947 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
89948 {
89949 return local_read(&cpu_buffer->entries) -
89950 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
89951 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
89952 }
89953
89954 /**
89955 @@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
89956 return 0;
89957
89958 cpu_buffer = buffer->buffers[cpu];
89959 - ret = local_read(&cpu_buffer->overrun);
89960 + ret = local_read_unchecked(&cpu_buffer->overrun);
89961
89962 return ret;
89963 }
89964 @@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
89965 return 0;
89966
89967 cpu_buffer = buffer->buffers[cpu];
89968 - ret = local_read(&cpu_buffer->commit_overrun);
89969 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
89970
89971 return ret;
89972 }
89973 @@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
89974 /* if you care about this being correct, lock the buffer */
89975 for_each_buffer_cpu(buffer, cpu) {
89976 cpu_buffer = buffer->buffers[cpu];
89977 - overruns += local_read(&cpu_buffer->overrun);
89978 + overruns += local_read_unchecked(&cpu_buffer->overrun);
89979 }
89980
89981 return overruns;
89982 @@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
89983 /*
89984 * Reset the reader page to size zero.
89985 */
89986 - local_set(&cpu_buffer->reader_page->write, 0);
89987 - local_set(&cpu_buffer->reader_page->entries, 0);
89988 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
89989 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
89990 local_set(&cpu_buffer->reader_page->page->commit, 0);
89991 cpu_buffer->reader_page->real_end = 0;
89992
89993 @@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
89994 * want to compare with the last_overrun.
89995 */
89996 smp_mb();
89997 - overwrite = local_read(&(cpu_buffer->overrun));
89998 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
89999
90000 /*
90001 * Here's the tricky part.
90002 @@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90003
90004 cpu_buffer->head_page
90005 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90006 - local_set(&cpu_buffer->head_page->write, 0);
90007 - local_set(&cpu_buffer->head_page->entries, 0);
90008 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
90009 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90010 local_set(&cpu_buffer->head_page->page->commit, 0);
90011
90012 cpu_buffer->head_page->read = 0;
90013 @@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90014
90015 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90016 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90017 - local_set(&cpu_buffer->reader_page->write, 0);
90018 - local_set(&cpu_buffer->reader_page->entries, 0);
90019 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90020 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90021 local_set(&cpu_buffer->reader_page->page->commit, 0);
90022 cpu_buffer->reader_page->read = 0;
90023
90024 local_set(&cpu_buffer->entries_bytes, 0);
90025 - local_set(&cpu_buffer->overrun, 0);
90026 - local_set(&cpu_buffer->commit_overrun, 0);
90027 + local_set_unchecked(&cpu_buffer->overrun, 0);
90028 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90029 local_set(&cpu_buffer->dropped_events, 0);
90030 local_set(&cpu_buffer->entries, 0);
90031 local_set(&cpu_buffer->committing, 0);
90032 @@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90033 rb_init_page(bpage);
90034 bpage = reader->page;
90035 reader->page = *data_page;
90036 - local_set(&reader->write, 0);
90037 - local_set(&reader->entries, 0);
90038 + local_set_unchecked(&reader->write, 0);
90039 + local_set_unchecked(&reader->entries, 0);
90040 reader->read = 0;
90041 *data_page = bpage;
90042
90043 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90044 index 0a360ce..7bd800e 100644
90045 --- a/kernel/trace/trace.c
90046 +++ b/kernel/trace/trace.c
90047 @@ -3352,7 +3352,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90048 return 0;
90049 }
90050
90051 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90052 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90053 {
90054 /* do nothing if flag is already set */
90055 if (!!(trace_flags & mask) == !!enabled)
90056 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90057 index ea189e0..a5b48c4 100644
90058 --- a/kernel/trace/trace.h
90059 +++ b/kernel/trace/trace.h
90060 @@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
90061 void trace_printk_init_buffers(void);
90062 void trace_printk_start_comm(void);
90063 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90064 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90065 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90066
90067 /*
90068 * Normal trace_printk() and friends allocates special buffers
90069 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90070 index 26dc348..8708ca7 100644
90071 --- a/kernel/trace/trace_clock.c
90072 +++ b/kernel/trace/trace_clock.c
90073 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90074 return now;
90075 }
90076
90077 -static atomic64_t trace_counter;
90078 +static atomic64_unchecked_t trace_counter;
90079
90080 /*
90081 * trace_clock_counter(): simply an atomic counter.
90082 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90083 */
90084 u64 notrace trace_clock_counter(void)
90085 {
90086 - return atomic64_add_return(1, &trace_counter);
90087 + return atomic64_inc_return_unchecked(&trace_counter);
90088 }
90089 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90090 index a11800a..3dafde5 100644
90091 --- a/kernel/trace/trace_events.c
90092 +++ b/kernel/trace/trace_events.c
90093 @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90094 return 0;
90095 }
90096
90097 -struct ftrace_module_file_ops;
90098 static void __add_event_to_tracers(struct ftrace_event_call *call);
90099
90100 /* Add an additional event_call dynamically */
90101 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90102 index 0abd9b8..6a663a2 100644
90103 --- a/kernel/trace/trace_mmiotrace.c
90104 +++ b/kernel/trace/trace_mmiotrace.c
90105 @@ -24,7 +24,7 @@ struct header_iter {
90106 static struct trace_array *mmio_trace_array;
90107 static bool overrun_detected;
90108 static unsigned long prev_overruns;
90109 -static atomic_t dropped_count;
90110 +static atomic_unchecked_t dropped_count;
90111
90112 static void mmio_reset_data(struct trace_array *tr)
90113 {
90114 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90115
90116 static unsigned long count_overruns(struct trace_iterator *iter)
90117 {
90118 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
90119 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90120 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90121
90122 if (over > prev_overruns)
90123 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90124 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90125 sizeof(*entry), 0, pc);
90126 if (!event) {
90127 - atomic_inc(&dropped_count);
90128 + atomic_inc_unchecked(&dropped_count);
90129 return;
90130 }
90131 entry = ring_buffer_event_data(event);
90132 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90133 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90134 sizeof(*entry), 0, pc);
90135 if (!event) {
90136 - atomic_inc(&dropped_count);
90137 + atomic_inc_unchecked(&dropped_count);
90138 return;
90139 }
90140 entry = ring_buffer_event_data(event);
90141 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90142 index ed32284..884d6c3 100644
90143 --- a/kernel/trace/trace_output.c
90144 +++ b/kernel/trace/trace_output.c
90145 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90146
90147 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90148 if (!IS_ERR(p)) {
90149 - p = mangle_path(s->buffer + s->len, p, "\n");
90150 + p = mangle_path(s->buffer + s->len, p, "\n\\");
90151 if (p) {
90152 s->len = p - s->buffer;
90153 return 1;
90154 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90155 goto out;
90156 }
90157
90158 + pax_open_kernel();
90159 if (event->funcs->trace == NULL)
90160 - event->funcs->trace = trace_nop_print;
90161 + *(void **)&event->funcs->trace = trace_nop_print;
90162 if (event->funcs->raw == NULL)
90163 - event->funcs->raw = trace_nop_print;
90164 + *(void **)&event->funcs->raw = trace_nop_print;
90165 if (event->funcs->hex == NULL)
90166 - event->funcs->hex = trace_nop_print;
90167 + *(void **)&event->funcs->hex = trace_nop_print;
90168 if (event->funcs->binary == NULL)
90169 - event->funcs->binary = trace_nop_print;
90170 + *(void **)&event->funcs->binary = trace_nop_print;
90171 + pax_close_kernel();
90172
90173 key = event->type & (EVENT_HASHSIZE - 1);
90174
90175 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90176 index b20428c..4845a10 100644
90177 --- a/kernel/trace/trace_stack.c
90178 +++ b/kernel/trace/trace_stack.c
90179 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90180 return;
90181
90182 /* we do not handle interrupt stacks yet */
90183 - if (!object_is_on_stack(stack))
90184 + if (!object_starts_on_stack(stack))
90185 return;
90186
90187 local_irq_save(flags);
90188 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90189 index 240fb62..583473e 100644
90190 --- a/kernel/user_namespace.c
90191 +++ b/kernel/user_namespace.c
90192 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90193 !kgid_has_mapping(parent_ns, group))
90194 return -EPERM;
90195
90196 +#ifdef CONFIG_GRKERNSEC
90197 + /*
90198 + * This doesn't really inspire confidence:
90199 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90200 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90201 + * Increases kernel attack surface in areas developers
90202 + * previously cared little about ("low importance due
90203 + * to requiring "root" capability")
90204 + * To be removed when this code receives *proper* review
90205 + */
90206 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90207 + !capable(CAP_SETGID))
90208 + return -EPERM;
90209 +#endif
90210 +
90211 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90212 if (!ns)
90213 return -ENOMEM;
90214 @@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90215 if (atomic_read(&current->mm->mm_users) > 1)
90216 return -EINVAL;
90217
90218 - if (current->fs->users != 1)
90219 + if (atomic_read(&current->fs->users) != 1)
90220 return -EINVAL;
90221
90222 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90223 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90224 index 4f69f9a..7c6f8f8 100644
90225 --- a/kernel/utsname_sysctl.c
90226 +++ b/kernel/utsname_sysctl.c
90227 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90228 static int proc_do_uts_string(ctl_table *table, int write,
90229 void __user *buffer, size_t *lenp, loff_t *ppos)
90230 {
90231 - struct ctl_table uts_table;
90232 + ctl_table_no_const uts_table;
90233 int r;
90234 memcpy(&uts_table, table, sizeof(uts_table));
90235 uts_table.data = get_uts(table, write);
90236 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90237 index 4431610..4265616 100644
90238 --- a/kernel/watchdog.c
90239 +++ b/kernel/watchdog.c
90240 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90241 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90242 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90243
90244 -static struct smp_hotplug_thread watchdog_threads = {
90245 +static struct smp_hotplug_thread watchdog_threads __read_only = {
90246 .store = &softlockup_watchdog,
90247 .thread_should_run = watchdog_should_run,
90248 .thread_fn = watchdog,
90249 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90250 index a8381cf..1ce1331 100644
90251 --- a/kernel/workqueue.c
90252 +++ b/kernel/workqueue.c
90253 @@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90254 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90255 worker_flags |= WORKER_REBOUND;
90256 worker_flags &= ~WORKER_UNBOUND;
90257 - ACCESS_ONCE(worker->flags) = worker_flags;
90258 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
90259 }
90260
90261 spin_unlock_irq(&pool->lock);
90262 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90263 index db25707..8b16430 100644
90264 --- a/lib/Kconfig.debug
90265 +++ b/lib/Kconfig.debug
90266 @@ -845,7 +845,7 @@ config DEBUG_MUTEXES
90267
90268 config DEBUG_WW_MUTEX_SLOWPATH
90269 bool "Wait/wound mutex debugging: Slowpath testing"
90270 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90271 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90272 select DEBUG_LOCK_ALLOC
90273 select DEBUG_SPINLOCK
90274 select DEBUG_MUTEXES
90275 @@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90276
90277 config DEBUG_LOCK_ALLOC
90278 bool "Lock debugging: detect incorrect freeing of live locks"
90279 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90280 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90281 select DEBUG_SPINLOCK
90282 select DEBUG_MUTEXES
90283 select LOCKDEP
90284 @@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
90285
90286 config PROVE_LOCKING
90287 bool "Lock debugging: prove locking correctness"
90288 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90289 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90290 select LOCKDEP
90291 select DEBUG_SPINLOCK
90292 select DEBUG_MUTEXES
90293 @@ -923,7 +923,7 @@ config LOCKDEP
90294
90295 config LOCK_STAT
90296 bool "Lock usage statistics"
90297 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90298 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90299 select LOCKDEP
90300 select DEBUG_SPINLOCK
90301 select DEBUG_MUTEXES
90302 @@ -1385,6 +1385,7 @@ config LATENCYTOP
90303 depends on DEBUG_KERNEL
90304 depends on STACKTRACE_SUPPORT
90305 depends on PROC_FS
90306 + depends on !GRKERNSEC_HIDESYM
90307 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90308 select KALLSYMS
90309 select KALLSYMS_ALL
90310 @@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90311 config DEBUG_STRICT_USER_COPY_CHECKS
90312 bool "Strict user copy size checks"
90313 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90314 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90315 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90316 help
90317 Enabling this option turns a certain set of sanity checks for user
90318 copy operations into compile time failures.
90319 @@ -1520,7 +1521,7 @@ endmenu # runtime tests
90320
90321 config PROVIDE_OHCI1394_DMA_INIT
90322 bool "Remote debugging over FireWire early on boot"
90323 - depends on PCI && X86
90324 + depends on PCI && X86 && !GRKERNSEC
90325 help
90326 If you want to debug problems which hang or crash the kernel early
90327 on boot and the crashing machine has a FireWire port, you can use
90328 @@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
90329
90330 config FIREWIRE_OHCI_REMOTE_DMA
90331 bool "Remote debugging over FireWire with firewire-ohci"
90332 - depends on FIREWIRE_OHCI
90333 + depends on FIREWIRE_OHCI && !GRKERNSEC
90334 help
90335 This option lets you use the FireWire bus for remote debugging
90336 with help of the firewire-ohci driver. It enables unfiltered
90337 diff --git a/lib/Makefile b/lib/Makefile
90338 index 04944e9..f43eabe 100644
90339 --- a/lib/Makefile
90340 +++ b/lib/Makefile
90341 @@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90342 obj-$(CONFIG_BTREE) += btree.o
90343 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90344 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90345 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90346 +obj-y += list_debug.o
90347 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90348
90349 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90350 diff --git a/lib/bitmap.c b/lib/bitmap.c
90351 index 06f7e4f..f3cf2b0 100644
90352 --- a/lib/bitmap.c
90353 +++ b/lib/bitmap.c
90354 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90355 {
90356 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90357 u32 chunk;
90358 - const char __user __force *ubuf = (const char __user __force *)buf;
90359 + const char __user *ubuf = (const char __force_user *)buf;
90360
90361 bitmap_zero(maskp, nmaskbits);
90362
90363 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90364 {
90365 if (!access_ok(VERIFY_READ, ubuf, ulen))
90366 return -EFAULT;
90367 - return __bitmap_parse((const char __force *)ubuf,
90368 + return __bitmap_parse((const char __force_kernel *)ubuf,
90369 ulen, 1, maskp, nmaskbits);
90370
90371 }
90372 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90373 {
90374 unsigned a, b;
90375 int c, old_c, totaldigits;
90376 - const char __user __force *ubuf = (const char __user __force *)buf;
90377 + const char __user *ubuf = (const char __force_user *)buf;
90378 int exp_digit, in_range;
90379
90380 totaldigits = c = 0;
90381 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90382 {
90383 if (!access_ok(VERIFY_READ, ubuf, ulen))
90384 return -EFAULT;
90385 - return __bitmap_parselist((const char __force *)ubuf,
90386 + return __bitmap_parselist((const char __force_kernel *)ubuf,
90387 ulen, 1, maskp, nmaskbits);
90388 }
90389 EXPORT_SYMBOL(bitmap_parselist_user);
90390 diff --git a/lib/bug.c b/lib/bug.c
90391 index 1686034..a9c00c8 100644
90392 --- a/lib/bug.c
90393 +++ b/lib/bug.c
90394 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90395 return BUG_TRAP_TYPE_NONE;
90396
90397 bug = find_bug(bugaddr);
90398 + if (!bug)
90399 + return BUG_TRAP_TYPE_NONE;
90400
90401 file = NULL;
90402 line = 0;
90403 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90404 index e0731c3..ad66444 100644
90405 --- a/lib/debugobjects.c
90406 +++ b/lib/debugobjects.c
90407 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90408 if (limit > 4)
90409 return;
90410
90411 - is_on_stack = object_is_on_stack(addr);
90412 + is_on_stack = object_starts_on_stack(addr);
90413 if (is_on_stack == onstack)
90414 return;
90415
90416 diff --git a/lib/devres.c b/lib/devres.c
90417 index 8235331..5881053 100644
90418 --- a/lib/devres.c
90419 +++ b/lib/devres.c
90420 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90421 void devm_iounmap(struct device *dev, void __iomem *addr)
90422 {
90423 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
90424 - (void *)addr));
90425 + (void __force *)addr));
90426 iounmap(addr);
90427 }
90428 EXPORT_SYMBOL(devm_iounmap);
90429 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
90430 {
90431 ioport_unmap(addr);
90432 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
90433 - devm_ioport_map_match, (void *)addr));
90434 + devm_ioport_map_match, (void __force *)addr));
90435 }
90436 EXPORT_SYMBOL(devm_ioport_unmap);
90437 #endif /* CONFIG_HAS_IOPORT */
90438 diff --git a/lib/div64.c b/lib/div64.c
90439 index 4382ad7..08aa558 100644
90440 --- a/lib/div64.c
90441 +++ b/lib/div64.c
90442 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
90443 EXPORT_SYMBOL(__div64_32);
90444
90445 #ifndef div_s64_rem
90446 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90447 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90448 {
90449 u64 quotient;
90450
90451 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
90452 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
90453 */
90454 #ifndef div64_u64
90455 -u64 div64_u64(u64 dividend, u64 divisor)
90456 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
90457 {
90458 u32 high = divisor >> 32;
90459 u64 quot;
90460 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
90461 index d87a17a..ac0d79a 100644
90462 --- a/lib/dma-debug.c
90463 +++ b/lib/dma-debug.c
90464 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
90465
90466 void dma_debug_add_bus(struct bus_type *bus)
90467 {
90468 - struct notifier_block *nb;
90469 + notifier_block_no_const *nb;
90470
90471 if (global_disable)
90472 return;
90473 @@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
90474
90475 static void check_for_stack(struct device *dev, void *addr)
90476 {
90477 - if (object_is_on_stack(addr))
90478 + if (object_starts_on_stack(addr))
90479 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
90480 "stack [addr=%p]\n", addr);
90481 }
90482 diff --git a/lib/inflate.c b/lib/inflate.c
90483 index 013a761..c28f3fc 100644
90484 --- a/lib/inflate.c
90485 +++ b/lib/inflate.c
90486 @@ -269,7 +269,7 @@ static void free(void *where)
90487 malloc_ptr = free_mem_ptr;
90488 }
90489 #else
90490 -#define malloc(a) kmalloc(a, GFP_KERNEL)
90491 +#define malloc(a) kmalloc((a), GFP_KERNEL)
90492 #define free(a) kfree(a)
90493 #endif
90494
90495 diff --git a/lib/ioremap.c b/lib/ioremap.c
90496 index 0c9216c..863bd89 100644
90497 --- a/lib/ioremap.c
90498 +++ b/lib/ioremap.c
90499 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
90500 unsigned long next;
90501
90502 phys_addr -= addr;
90503 - pmd = pmd_alloc(&init_mm, pud, addr);
90504 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90505 if (!pmd)
90506 return -ENOMEM;
90507 do {
90508 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
90509 unsigned long next;
90510
90511 phys_addr -= addr;
90512 - pud = pud_alloc(&init_mm, pgd, addr);
90513 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
90514 if (!pud)
90515 return -ENOMEM;
90516 do {
90517 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
90518 index bd2bea9..6b3c95e 100644
90519 --- a/lib/is_single_threaded.c
90520 +++ b/lib/is_single_threaded.c
90521 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
90522 struct task_struct *p, *t;
90523 bool ret;
90524
90525 + if (!mm)
90526 + return true;
90527 +
90528 if (atomic_read(&task->signal->live) != 1)
90529 return false;
90530
90531 diff --git a/lib/kobject.c b/lib/kobject.c
90532 index 5b4b888..c2950f7 100644
90533 --- a/lib/kobject.c
90534 +++ b/lib/kobject.c
90535 @@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
90536
90537
90538 static DEFINE_SPINLOCK(kobj_ns_type_lock);
90539 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
90540 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
90541
90542 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90543 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90544 {
90545 enum kobj_ns_type type = ops->type;
90546 int error;
90547 diff --git a/lib/list_debug.c b/lib/list_debug.c
90548 index c24c2f7..f0296f4 100644
90549 --- a/lib/list_debug.c
90550 +++ b/lib/list_debug.c
90551 @@ -11,7 +11,9 @@
90552 #include <linux/bug.h>
90553 #include <linux/kernel.h>
90554 #include <linux/rculist.h>
90555 +#include <linux/mm.h>
90556
90557 +#ifdef CONFIG_DEBUG_LIST
90558 /*
90559 * Insert a new entry between two known consecutive entries.
90560 *
90561 @@ -19,21 +21,40 @@
90562 * the prev/next entries already!
90563 */
90564
90565 +static bool __list_add_debug(struct list_head *new,
90566 + struct list_head *prev,
90567 + struct list_head *next)
90568 +{
90569 + if (unlikely(next->prev != prev)) {
90570 + printk(KERN_ERR "list_add corruption. next->prev should be "
90571 + "prev (%p), but was %p. (next=%p).\n",
90572 + prev, next->prev, next);
90573 + BUG();
90574 + return false;
90575 + }
90576 + if (unlikely(prev->next != next)) {
90577 + printk(KERN_ERR "list_add corruption. prev->next should be "
90578 + "next (%p), but was %p. (prev=%p).\n",
90579 + next, prev->next, prev);
90580 + BUG();
90581 + return false;
90582 + }
90583 + if (unlikely(new == prev || new == next)) {
90584 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
90585 + new, prev, next);
90586 + BUG();
90587 + return false;
90588 + }
90589 + return true;
90590 +}
90591 +
90592 void __list_add(struct list_head *new,
90593 - struct list_head *prev,
90594 - struct list_head *next)
90595 + struct list_head *prev,
90596 + struct list_head *next)
90597 {
90598 - WARN(next->prev != prev,
90599 - "list_add corruption. next->prev should be "
90600 - "prev (%p), but was %p. (next=%p).\n",
90601 - prev, next->prev, next);
90602 - WARN(prev->next != next,
90603 - "list_add corruption. prev->next should be "
90604 - "next (%p), but was %p. (prev=%p).\n",
90605 - next, prev->next, prev);
90606 - WARN(new == prev || new == next,
90607 - "list_add double add: new=%p, prev=%p, next=%p.\n",
90608 - new, prev, next);
90609 + if (!__list_add_debug(new, prev, next))
90610 + return;
90611 +
90612 next->prev = new;
90613 new->next = next;
90614 new->prev = prev;
90615 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
90616 }
90617 EXPORT_SYMBOL(__list_add);
90618
90619 -void __list_del_entry(struct list_head *entry)
90620 +static bool __list_del_entry_debug(struct list_head *entry)
90621 {
90622 struct list_head *prev, *next;
90623
90624 prev = entry->prev;
90625 next = entry->next;
90626
90627 - if (WARN(next == LIST_POISON1,
90628 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90629 - entry, LIST_POISON1) ||
90630 - WARN(prev == LIST_POISON2,
90631 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90632 - entry, LIST_POISON2) ||
90633 - WARN(prev->next != entry,
90634 - "list_del corruption. prev->next should be %p, "
90635 - "but was %p\n", entry, prev->next) ||
90636 - WARN(next->prev != entry,
90637 - "list_del corruption. next->prev should be %p, "
90638 - "but was %p\n", entry, next->prev))
90639 + if (unlikely(next == LIST_POISON1)) {
90640 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90641 + entry, LIST_POISON1);
90642 + BUG();
90643 + return false;
90644 + }
90645 + if (unlikely(prev == LIST_POISON2)) {
90646 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90647 + entry, LIST_POISON2);
90648 + BUG();
90649 + return false;
90650 + }
90651 + if (unlikely(entry->prev->next != entry)) {
90652 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
90653 + "but was %p\n", entry, prev->next);
90654 + BUG();
90655 + return false;
90656 + }
90657 + if (unlikely(entry->next->prev != entry)) {
90658 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
90659 + "but was %p\n", entry, next->prev);
90660 + BUG();
90661 + return false;
90662 + }
90663 + return true;
90664 +}
90665 +
90666 +void __list_del_entry(struct list_head *entry)
90667 +{
90668 + if (!__list_del_entry_debug(entry))
90669 return;
90670
90671 - __list_del(prev, next);
90672 + __list_del(entry->prev, entry->next);
90673 }
90674 EXPORT_SYMBOL(__list_del_entry);
90675
90676 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
90677 void __list_add_rcu(struct list_head *new,
90678 struct list_head *prev, struct list_head *next)
90679 {
90680 - WARN(next->prev != prev,
90681 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
90682 - prev, next->prev, next);
90683 - WARN(prev->next != next,
90684 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
90685 - next, prev->next, prev);
90686 + if (!__list_add_debug(new, prev, next))
90687 + return;
90688 +
90689 new->next = next;
90690 new->prev = prev;
90691 rcu_assign_pointer(list_next_rcu(prev), new);
90692 next->prev = new;
90693 }
90694 EXPORT_SYMBOL(__list_add_rcu);
90695 +#endif
90696 +
90697 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
90698 +{
90699 +#ifdef CONFIG_DEBUG_LIST
90700 + if (!__list_add_debug(new, prev, next))
90701 + return;
90702 +#endif
90703 +
90704 + pax_open_kernel();
90705 + next->prev = new;
90706 + new->next = next;
90707 + new->prev = prev;
90708 + prev->next = new;
90709 + pax_close_kernel();
90710 +}
90711 +EXPORT_SYMBOL(__pax_list_add);
90712 +
90713 +void pax_list_del(struct list_head *entry)
90714 +{
90715 +#ifdef CONFIG_DEBUG_LIST
90716 + if (!__list_del_entry_debug(entry))
90717 + return;
90718 +#endif
90719 +
90720 + pax_open_kernel();
90721 + __list_del(entry->prev, entry->next);
90722 + entry->next = LIST_POISON1;
90723 + entry->prev = LIST_POISON2;
90724 + pax_close_kernel();
90725 +}
90726 +EXPORT_SYMBOL(pax_list_del);
90727 +
90728 +void pax_list_del_init(struct list_head *entry)
90729 +{
90730 + pax_open_kernel();
90731 + __list_del(entry->prev, entry->next);
90732 + INIT_LIST_HEAD(entry);
90733 + pax_close_kernel();
90734 +}
90735 +EXPORT_SYMBOL(pax_list_del_init);
90736 +
90737 +void __pax_list_add_rcu(struct list_head *new,
90738 + struct list_head *prev, struct list_head *next)
90739 +{
90740 +#ifdef CONFIG_DEBUG_LIST
90741 + if (!__list_add_debug(new, prev, next))
90742 + return;
90743 +#endif
90744 +
90745 + pax_open_kernel();
90746 + new->next = next;
90747 + new->prev = prev;
90748 + rcu_assign_pointer(list_next_rcu(prev), new);
90749 + next->prev = new;
90750 + pax_close_kernel();
90751 +}
90752 +EXPORT_SYMBOL(__pax_list_add_rcu);
90753 +
90754 +void pax_list_del_rcu(struct list_head *entry)
90755 +{
90756 +#ifdef CONFIG_DEBUG_LIST
90757 + if (!__list_del_entry_debug(entry))
90758 + return;
90759 +#endif
90760 +
90761 + pax_open_kernel();
90762 + __list_del(entry->prev, entry->next);
90763 + entry->next = LIST_POISON1;
90764 + entry->prev = LIST_POISON2;
90765 + pax_close_kernel();
90766 +}
90767 +EXPORT_SYMBOL(pax_list_del_rcu);
90768 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
90769 index 1a53d49..ace934c 100644
90770 --- a/lib/percpu-refcount.c
90771 +++ b/lib/percpu-refcount.c
90772 @@ -29,7 +29,7 @@
90773 * can't hit 0 before we've added up all the percpu refs.
90774 */
90775
90776 -#define PCPU_COUNT_BIAS (1U << 31)
90777 +#define PCPU_COUNT_BIAS (1U << 30)
90778
90779 /**
90780 * percpu_ref_init - initialize a percpu refcount
90781 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
90782 index 7811ed3..f80ca19 100644
90783 --- a/lib/radix-tree.c
90784 +++ b/lib/radix-tree.c
90785 @@ -93,7 +93,7 @@ struct radix_tree_preload {
90786 int nr;
90787 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
90788 };
90789 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
90790 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
90791
90792 static inline void *ptr_to_indirect(void *ptr)
90793 {
90794 diff --git a/lib/random32.c b/lib/random32.c
90795 index 1e5b2df..fb616c7 100644
90796 --- a/lib/random32.c
90797 +++ b/lib/random32.c
90798 @@ -44,7 +44,7 @@
90799 static void __init prandom_state_selftest(void);
90800 #endif
90801
90802 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
90803 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
90804
90805 /**
90806 * prandom_u32_state - seeded pseudo-random number generator.
90807 diff --git a/lib/rbtree.c b/lib/rbtree.c
90808 index 65f4eff..2cfa167 100644
90809 --- a/lib/rbtree.c
90810 +++ b/lib/rbtree.c
90811 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
90812 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
90813
90814 static const struct rb_augment_callbacks dummy_callbacks = {
90815 - dummy_propagate, dummy_copy, dummy_rotate
90816 + .propagate = dummy_propagate,
90817 + .copy = dummy_copy,
90818 + .rotate = dummy_rotate
90819 };
90820
90821 void rb_insert_color(struct rb_node *node, struct rb_root *root)
90822 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
90823 index bb2b201..46abaf9 100644
90824 --- a/lib/strncpy_from_user.c
90825 +++ b/lib/strncpy_from_user.c
90826 @@ -21,7 +21,7 @@
90827 */
90828 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
90829 {
90830 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90831 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90832 long res = 0;
90833
90834 /*
90835 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
90836 index a28df52..3d55877 100644
90837 --- a/lib/strnlen_user.c
90838 +++ b/lib/strnlen_user.c
90839 @@ -26,7 +26,7 @@
90840 */
90841 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
90842 {
90843 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90844 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90845 long align, res = 0;
90846 unsigned long c;
90847
90848 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
90849 index e4399fa..5e8b214 100644
90850 --- a/lib/swiotlb.c
90851 +++ b/lib/swiotlb.c
90852 @@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
90853
90854 void
90855 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
90856 - dma_addr_t dev_addr)
90857 + dma_addr_t dev_addr, struct dma_attrs *attrs)
90858 {
90859 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
90860
90861 diff --git a/lib/usercopy.c b/lib/usercopy.c
90862 index 4f5b1dd..7cab418 100644
90863 --- a/lib/usercopy.c
90864 +++ b/lib/usercopy.c
90865 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
90866 WARN(1, "Buffer overflow detected!\n");
90867 }
90868 EXPORT_SYMBOL(copy_from_user_overflow);
90869 +
90870 +void copy_to_user_overflow(void)
90871 +{
90872 + WARN(1, "Buffer overflow detected!\n");
90873 +}
90874 +EXPORT_SYMBOL(copy_to_user_overflow);
90875 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
90876 index 10909c5..653e1b8 100644
90877 --- a/lib/vsprintf.c
90878 +++ b/lib/vsprintf.c
90879 @@ -16,6 +16,9 @@
90880 * - scnprintf and vscnprintf
90881 */
90882
90883 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90884 +#define __INCLUDED_BY_HIDESYM 1
90885 +#endif
90886 #include <stdarg.h>
90887 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
90888 #include <linux/types.h>
90889 @@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
90890 return number(buf, end, *(const netdev_features_t *)addr, spec);
90891 }
90892
90893 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90894 +int kptr_restrict __read_mostly = 2;
90895 +#else
90896 int kptr_restrict __read_mostly;
90897 +#endif
90898
90899 /*
90900 * Show a '%p' thing. A kernel extension is that the '%p' is followed
90901 @@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
90902 * - 'f' For simple symbolic function names without offset
90903 * - 'S' For symbolic direct pointers with offset
90904 * - 's' For symbolic direct pointers without offset
90905 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
90906 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
90907 * - 'B' For backtraced symbolic direct pointers with offset
90908 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
90909 @@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90910
90911 if (!ptr && *fmt != 'K') {
90912 /*
90913 - * Print (null) with the same width as a pointer so it makes
90914 + * Print (nil) with the same width as a pointer so it makes
90915 * tabular output look nice.
90916 */
90917 if (spec.field_width == -1)
90918 spec.field_width = default_width;
90919 - return string(buf, end, "(null)", spec);
90920 + return string(buf, end, "(nil)", spec);
90921 }
90922
90923 switch (*fmt) {
90924 @@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90925 /* Fallthrough */
90926 case 'S':
90927 case 's':
90928 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90929 + break;
90930 +#else
90931 + return symbol_string(buf, end, ptr, spec, fmt);
90932 +#endif
90933 + case 'A':
90934 case 'B':
90935 return symbol_string(buf, end, ptr, spec, fmt);
90936 case 'R':
90937 @@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90938 va_end(va);
90939 return buf;
90940 }
90941 + case 'P':
90942 + break;
90943 case 'K':
90944 /*
90945 * %pK cannot be used in IRQ context because its test
90946 @@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90947 ((const struct file *)ptr)->f_path.dentry,
90948 spec, fmt);
90949 }
90950 +
90951 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90952 + /* 'P' = approved pointers to copy to userland,
90953 + as in the /proc/kallsyms case, as we make it display nothing
90954 + for non-root users, and the real contents for root users
90955 + Also ignore 'K' pointers, since we force their NULLing for non-root users
90956 + above
90957 + */
90958 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
90959 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
90960 + dump_stack();
90961 + ptr = NULL;
90962 + }
90963 +#endif
90964 +
90965 spec.flags |= SMALL;
90966 if (spec.field_width == -1) {
90967 spec.field_width = default_width;
90968 @@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90969 typeof(type) value; \
90970 if (sizeof(type) == 8) { \
90971 args = PTR_ALIGN(args, sizeof(u32)); \
90972 - *(u32 *)&value = *(u32 *)args; \
90973 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
90974 + *(u32 *)&value = *(const u32 *)args; \
90975 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
90976 } else { \
90977 args = PTR_ALIGN(args, sizeof(type)); \
90978 - value = *(typeof(type) *)args; \
90979 + value = *(const typeof(type) *)args; \
90980 } \
90981 args += sizeof(type); \
90982 value; \
90983 @@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90984 case FORMAT_TYPE_STR: {
90985 const char *str_arg = args;
90986 args += strlen(str_arg) + 1;
90987 - str = string(str, end, (char *)str_arg, spec);
90988 + str = string(str, end, str_arg, spec);
90989 break;
90990 }
90991
90992 diff --git a/localversion-grsec b/localversion-grsec
90993 new file mode 100644
90994 index 0000000..7cd6065
90995 --- /dev/null
90996 +++ b/localversion-grsec
90997 @@ -0,0 +1 @@
90998 +-grsec
90999 diff --git a/mm/Kconfig b/mm/Kconfig
91000 index 723bbe0..ea624b1 100644
91001 --- a/mm/Kconfig
91002 +++ b/mm/Kconfig
91003 @@ -326,10 +326,11 @@ config KSM
91004 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91005
91006 config DEFAULT_MMAP_MIN_ADDR
91007 - int "Low address space to protect from user allocation"
91008 + int "Low address space to protect from user allocation"
91009 depends on MMU
91010 - default 4096
91011 - help
91012 + default 32768 if ALPHA || ARM || PARISC || SPARC32
91013 + default 65536
91014 + help
91015 This is the portion of low virtual memory which should be protected
91016 from userspace allocation. Keeping a user from writing to low pages
91017 can help reduce the impact of kernel NULL pointer bugs.
91018 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
91019
91020 config HWPOISON_INJECT
91021 tristate "HWPoison pages injector"
91022 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91023 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91024 select PROC_PAGE_MONITOR
91025
91026 config NOMMU_INITIAL_TRIM_EXCESS
91027 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91028 index ce682f7..1fb54f9 100644
91029 --- a/mm/backing-dev.c
91030 +++ b/mm/backing-dev.c
91031 @@ -12,7 +12,7 @@
91032 #include <linux/device.h>
91033 #include <trace/events/writeback.h>
91034
91035 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91036 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91037
91038 struct backing_dev_info default_backing_dev_info = {
91039 .name = "default",
91040 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91041 return err;
91042
91043 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91044 - atomic_long_inc_return(&bdi_seq));
91045 + atomic_long_inc_return_unchecked(&bdi_seq));
91046 if (err) {
91047 bdi_destroy(bdi);
91048 return err;
91049 diff --git a/mm/compaction.c b/mm/compaction.c
91050 index f58bcd0..b74dc61 100644
91051 --- a/mm/compaction.c
91052 +++ b/mm/compaction.c
91053 @@ -251,7 +251,6 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
91054 {
91055 int nr_scanned = 0, total_isolated = 0;
91056 struct page *cursor, *valid_page = NULL;
91057 - unsigned long nr_strict_required = end_pfn - blockpfn;
91058 unsigned long flags;
91059 bool locked = false;
91060
91061 @@ -264,11 +263,12 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
91062
91063 nr_scanned++;
91064 if (!pfn_valid_within(blockpfn))
91065 - continue;
91066 + goto isolate_fail;
91067 +
91068 if (!valid_page)
91069 valid_page = page;
91070 if (!PageBuddy(page))
91071 - continue;
91072 + goto isolate_fail;
91073
91074 /*
91075 * The zone lock must be held to isolate freepages.
91076 @@ -289,12 +289,10 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
91077
91078 /* Recheck this is a buddy page under lock */
91079 if (!PageBuddy(page))
91080 - continue;
91081 + goto isolate_fail;
91082
91083 /* Found a free page, break it into order-0 pages */
91084 isolated = split_free_page(page);
91085 - if (!isolated && strict)
91086 - break;
91087 total_isolated += isolated;
91088 for (i = 0; i < isolated; i++) {
91089 list_add(&page->lru, freelist);
91090 @@ -305,7 +303,15 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
91091 if (isolated) {
91092 blockpfn += isolated - 1;
91093 cursor += isolated - 1;
91094 + continue;
91095 }
91096 +
91097 +isolate_fail:
91098 + if (strict)
91099 + break;
91100 + else
91101 + continue;
91102 +
91103 }
91104
91105 trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated);
91106 @@ -315,7 +321,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
91107 * pages requested were isolated. If there were any failures, 0 is
91108 * returned and CMA will fail.
91109 */
91110 - if (strict && nr_strict_required > total_isolated)
91111 + if (strict && blockpfn < end_pfn)
91112 total_isolated = 0;
91113
91114 if (locked)
91115 diff --git a/mm/filemap.c b/mm/filemap.c
91116 index b7749a9..50d1123 100644
91117 --- a/mm/filemap.c
91118 +++ b/mm/filemap.c
91119 @@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91120 struct address_space *mapping = file->f_mapping;
91121
91122 if (!mapping->a_ops->readpage)
91123 - return -ENOEXEC;
91124 + return -ENODEV;
91125 file_accessed(file);
91126 vma->vm_ops = &generic_file_vm_ops;
91127 return 0;
91128 @@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91129
91130 while (bytes) {
91131 char __user *buf = iov->iov_base + base;
91132 - int copy = min(bytes, iov->iov_len - base);
91133 + size_t copy = min(bytes, iov->iov_len - base);
91134
91135 base = 0;
91136 left = __copy_from_user_inatomic(vaddr, buf, copy);
91137 @@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91138 BUG_ON(!in_atomic());
91139 kaddr = kmap_atomic(page);
91140 if (likely(i->nr_segs == 1)) {
91141 - int left;
91142 + size_t left;
91143 char __user *buf = i->iov->iov_base + i->iov_offset;
91144 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91145 copied = bytes - left;
91146 @@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91147
91148 kaddr = kmap(page);
91149 if (likely(i->nr_segs == 1)) {
91150 - int left;
91151 + size_t left;
91152 char __user *buf = i->iov->iov_base + i->iov_offset;
91153 left = __copy_from_user(kaddr + offset, buf, bytes);
91154 copied = bytes - left;
91155 @@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91156 * zero-length segments (without overruning the iovec).
91157 */
91158 while (bytes || unlikely(i->count && !iov->iov_len)) {
91159 - int copy;
91160 + size_t copy;
91161
91162 copy = min(bytes, iov->iov_len - base);
91163 BUG_ON(!i->count || i->count < copy);
91164 @@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91165 *pos = i_size_read(inode);
91166
91167 if (limit != RLIM_INFINITY) {
91168 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91169 if (*pos >= limit) {
91170 send_sig(SIGXFSZ, current, 0);
91171 return -EFBIG;
91172 diff --git a/mm/fremap.c b/mm/fremap.c
91173 index bbc4d66..117b798 100644
91174 --- a/mm/fremap.c
91175 +++ b/mm/fremap.c
91176 @@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91177 retry:
91178 vma = find_vma(mm, start);
91179
91180 +#ifdef CONFIG_PAX_SEGMEXEC
91181 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91182 + goto out;
91183 +#endif
91184 +
91185 /*
91186 * Make sure the vma is shared, that it supports prefaulting,
91187 * and that the remapped range is valid and fully within
91188 diff --git a/mm/highmem.c b/mm/highmem.c
91189 index b32b70c..e512eb0 100644
91190 --- a/mm/highmem.c
91191 +++ b/mm/highmem.c
91192 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91193 * So no dangers, even with speculative execution.
91194 */
91195 page = pte_page(pkmap_page_table[i]);
91196 + pax_open_kernel();
91197 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91198 -
91199 + pax_close_kernel();
91200 set_page_address(page, NULL);
91201 need_flush = 1;
91202 }
91203 @@ -198,9 +199,11 @@ start:
91204 }
91205 }
91206 vaddr = PKMAP_ADDR(last_pkmap_nr);
91207 +
91208 + pax_open_kernel();
91209 set_pte_at(&init_mm, vaddr,
91210 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91211 -
91212 + pax_close_kernel();
91213 pkmap_count[last_pkmap_nr] = 1;
91214 set_page_address(page, (void *)vaddr);
91215
91216 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91217 index dee6cf4..52b94f7 100644
91218 --- a/mm/hugetlb.c
91219 +++ b/mm/hugetlb.c
91220 @@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91221 struct hstate *h = &default_hstate;
91222 unsigned long tmp;
91223 int ret;
91224 + ctl_table_no_const hugetlb_table;
91225
91226 tmp = h->max_huge_pages;
91227
91228 if (write && h->order >= MAX_ORDER)
91229 return -EINVAL;
91230
91231 - table->data = &tmp;
91232 - table->maxlen = sizeof(unsigned long);
91233 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91234 + hugetlb_table = *table;
91235 + hugetlb_table.data = &tmp;
91236 + hugetlb_table.maxlen = sizeof(unsigned long);
91237 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91238 if (ret)
91239 goto out;
91240
91241 @@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91242 struct hstate *h = &default_hstate;
91243 unsigned long tmp;
91244 int ret;
91245 + ctl_table_no_const hugetlb_table;
91246
91247 tmp = h->nr_overcommit_huge_pages;
91248
91249 if (write && h->order >= MAX_ORDER)
91250 return -EINVAL;
91251
91252 - table->data = &tmp;
91253 - table->maxlen = sizeof(unsigned long);
91254 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91255 + hugetlb_table = *table;
91256 + hugetlb_table.data = &tmp;
91257 + hugetlb_table.maxlen = sizeof(unsigned long);
91258 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91259 if (ret)
91260 goto out;
91261
91262 @@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91263 return 1;
91264 }
91265
91266 +#ifdef CONFIG_PAX_SEGMEXEC
91267 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91268 +{
91269 + struct mm_struct *mm = vma->vm_mm;
91270 + struct vm_area_struct *vma_m;
91271 + unsigned long address_m;
91272 + pte_t *ptep_m;
91273 +
91274 + vma_m = pax_find_mirror_vma(vma);
91275 + if (!vma_m)
91276 + return;
91277 +
91278 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91279 + address_m = address + SEGMEXEC_TASK_SIZE;
91280 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91281 + get_page(page_m);
91282 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
91283 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91284 +}
91285 +#endif
91286 +
91287 /*
91288 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91289 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91290 @@ -2712,6 +2737,11 @@ retry_avoidcopy:
91291 make_huge_pte(vma, new_page, 1));
91292 page_remove_rmap(old_page);
91293 hugepage_add_new_anon_rmap(new_page, vma, address);
91294 +
91295 +#ifdef CONFIG_PAX_SEGMEXEC
91296 + pax_mirror_huge_pte(vma, address, new_page);
91297 +#endif
91298 +
91299 /* Make the old page be freed below */
91300 new_page = old_page;
91301 }
91302 @@ -2876,6 +2906,10 @@ retry:
91303 && (vma->vm_flags & VM_SHARED)));
91304 set_huge_pte_at(mm, address, ptep, new_pte);
91305
91306 +#ifdef CONFIG_PAX_SEGMEXEC
91307 + pax_mirror_huge_pte(vma, address, page);
91308 +#endif
91309 +
91310 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91311 /* Optimization, do the COW without a second fault */
91312 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91313 @@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91314 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91315 struct hstate *h = hstate_vma(vma);
91316
91317 +#ifdef CONFIG_PAX_SEGMEXEC
91318 + struct vm_area_struct *vma_m;
91319 +#endif
91320 +
91321 address &= huge_page_mask(h);
91322
91323 ptep = huge_pte_offset(mm, address);
91324 @@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91325 VM_FAULT_SET_HINDEX(hstate_index(h));
91326 }
91327
91328 +#ifdef CONFIG_PAX_SEGMEXEC
91329 + vma_m = pax_find_mirror_vma(vma);
91330 + if (vma_m) {
91331 + unsigned long address_m;
91332 +
91333 + if (vma->vm_start > vma_m->vm_start) {
91334 + address_m = address;
91335 + address -= SEGMEXEC_TASK_SIZE;
91336 + vma = vma_m;
91337 + h = hstate_vma(vma);
91338 + } else
91339 + address_m = address + SEGMEXEC_TASK_SIZE;
91340 +
91341 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91342 + return VM_FAULT_OOM;
91343 + address_m &= HPAGE_MASK;
91344 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91345 + }
91346 +#endif
91347 +
91348 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91349 if (!ptep)
91350 return VM_FAULT_OOM;
91351 diff --git a/mm/internal.h b/mm/internal.h
91352 index 8b6cfd6..ec809a6 100644
91353 --- a/mm/internal.h
91354 +++ b/mm/internal.h
91355 @@ -96,6 +96,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91356 * in mm/page_alloc.c
91357 */
91358 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91359 +extern void free_compound_page(struct page *page);
91360 extern void prep_compound_page(struct page *page, unsigned long order);
91361 #ifdef CONFIG_MEMORY_FAILURE
91362 extern bool is_free_buddy_page(struct page *page);
91363 @@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
91364
91365 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91366 unsigned long, unsigned long,
91367 - unsigned long, unsigned long);
91368 + unsigned long, unsigned long) __intentional_overflow(-1);
91369
91370 extern void set_pageblock_order(void);
91371 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91372 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91373 index 31f01c5..7015178 100644
91374 --- a/mm/kmemleak.c
91375 +++ b/mm/kmemleak.c
91376 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91377
91378 for (i = 0; i < object->trace_len; i++) {
91379 void *ptr = (void *)object->trace[i];
91380 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91381 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91382 }
91383 }
91384
91385 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91386 return -ENOMEM;
91387 }
91388
91389 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91390 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91391 &kmemleak_fops);
91392 if (!dentry)
91393 pr_warning("Failed to create the debugfs kmemleak file\n");
91394 diff --git a/mm/maccess.c b/mm/maccess.c
91395 index d53adf9..03a24bf 100644
91396 --- a/mm/maccess.c
91397 +++ b/mm/maccess.c
91398 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91399 set_fs(KERNEL_DS);
91400 pagefault_disable();
91401 ret = __copy_from_user_inatomic(dst,
91402 - (__force const void __user *)src, size);
91403 + (const void __force_user *)src, size);
91404 pagefault_enable();
91405 set_fs(old_fs);
91406
91407 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91408
91409 set_fs(KERNEL_DS);
91410 pagefault_disable();
91411 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91412 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91413 pagefault_enable();
91414 set_fs(old_fs);
91415
91416 diff --git a/mm/madvise.c b/mm/madvise.c
91417 index 539eeb9..e24a987 100644
91418 --- a/mm/madvise.c
91419 +++ b/mm/madvise.c
91420 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91421 pgoff_t pgoff;
91422 unsigned long new_flags = vma->vm_flags;
91423
91424 +#ifdef CONFIG_PAX_SEGMEXEC
91425 + struct vm_area_struct *vma_m;
91426 +#endif
91427 +
91428 switch (behavior) {
91429 case MADV_NORMAL:
91430 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91431 @@ -126,6 +130,13 @@ success:
91432 /*
91433 * vm_flags is protected by the mmap_sem held in write mode.
91434 */
91435 +
91436 +#ifdef CONFIG_PAX_SEGMEXEC
91437 + vma_m = pax_find_mirror_vma(vma);
91438 + if (vma_m)
91439 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91440 +#endif
91441 +
91442 vma->vm_flags = new_flags;
91443
91444 out:
91445 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91446 struct vm_area_struct **prev,
91447 unsigned long start, unsigned long end)
91448 {
91449 +
91450 +#ifdef CONFIG_PAX_SEGMEXEC
91451 + struct vm_area_struct *vma_m;
91452 +#endif
91453 +
91454 *prev = vma;
91455 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91456 return -EINVAL;
91457 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91458 zap_page_range(vma, start, end - start, &details);
91459 } else
91460 zap_page_range(vma, start, end - start, NULL);
91461 +
91462 +#ifdef CONFIG_PAX_SEGMEXEC
91463 + vma_m = pax_find_mirror_vma(vma);
91464 + if (vma_m) {
91465 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
91466 + struct zap_details details = {
91467 + .nonlinear_vma = vma_m,
91468 + .last_index = ULONG_MAX,
91469 + };
91470 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
91471 + } else
91472 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
91473 + }
91474 +#endif
91475 +
91476 return 0;
91477 }
91478
91479 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
91480 if (end < start)
91481 return error;
91482
91483 +#ifdef CONFIG_PAX_SEGMEXEC
91484 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
91485 + if (end > SEGMEXEC_TASK_SIZE)
91486 + return error;
91487 + } else
91488 +#endif
91489 +
91490 + if (end > TASK_SIZE)
91491 + return error;
91492 +
91493 error = 0;
91494 if (end == start)
91495 return error;
91496 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
91497 index 90977ac..487ab84 100644
91498 --- a/mm/memory-failure.c
91499 +++ b/mm/memory-failure.c
91500 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
91501
91502 int sysctl_memory_failure_recovery __read_mostly = 1;
91503
91504 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91505 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91506
91507 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
91508
91509 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
91510 pfn, t->comm, t->pid);
91511 si.si_signo = SIGBUS;
91512 si.si_errno = 0;
91513 - si.si_addr = (void *)addr;
91514 + si.si_addr = (void __user *)addr;
91515 #ifdef __ARCH_SI_TRAPNO
91516 si.si_trapno = trapno;
91517 #endif
91518 @@ -762,7 +762,7 @@ static struct page_state {
91519 unsigned long res;
91520 char *msg;
91521 int (*action)(struct page *p, unsigned long pfn);
91522 -} error_states[] = {
91523 +} __do_const error_states[] = {
91524 { reserved, reserved, "reserved kernel", me_kernel },
91525 /*
91526 * free pages are specially detected outside this table:
91527 @@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91528 nr_pages = 1 << compound_order(hpage);
91529 else /* normal page or thp */
91530 nr_pages = 1;
91531 - atomic_long_add(nr_pages, &num_poisoned_pages);
91532 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
91533
91534 /*
91535 * We need/can do nothing about count=0 pages.
91536 @@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91537 if (!PageHWPoison(hpage)
91538 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
91539 || (p != hpage && TestSetPageHWPoison(hpage))) {
91540 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91541 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91542 return 0;
91543 }
91544 set_page_hwpoison_huge_page(hpage);
91545 @@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91546 }
91547 if (hwpoison_filter(p)) {
91548 if (TestClearPageHWPoison(p))
91549 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91550 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91551 unlock_page(hpage);
91552 put_page(hpage);
91553 return 0;
91554 @@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
91555 return 0;
91556 }
91557 if (TestClearPageHWPoison(p))
91558 - atomic_long_dec(&num_poisoned_pages);
91559 + atomic_long_dec_unchecked(&num_poisoned_pages);
91560 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
91561 return 0;
91562 }
91563 @@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
91564 */
91565 if (TestClearPageHWPoison(page)) {
91566 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
91567 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91568 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91569 freeit = 1;
91570 if (PageHuge(page))
91571 clear_page_hwpoison_huge_page(page);
91572 @@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
91573 if (PageHuge(page)) {
91574 set_page_hwpoison_huge_page(hpage);
91575 dequeue_hwpoisoned_huge_page(hpage);
91576 - atomic_long_add(1 << compound_order(hpage),
91577 + atomic_long_add_unchecked(1 << compound_order(hpage),
91578 &num_poisoned_pages);
91579 } else {
91580 SetPageHWPoison(page);
91581 - atomic_long_inc(&num_poisoned_pages);
91582 + atomic_long_inc_unchecked(&num_poisoned_pages);
91583 }
91584 }
91585 return ret;
91586 @@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
91587 put_page(page);
91588 pr_info("soft_offline: %#lx: invalidated\n", pfn);
91589 SetPageHWPoison(page);
91590 - atomic_long_inc(&num_poisoned_pages);
91591 + atomic_long_inc_unchecked(&num_poisoned_pages);
91592 return 0;
91593 }
91594
91595 @@ -1610,7 +1610,7 @@ static int __soft_offline_page(struct page *page, int flags)
91596 if (!is_free_buddy_page(page))
91597 pr_info("soft offline: %#lx: page leaked\n",
91598 pfn);
91599 - atomic_long_inc(&num_poisoned_pages);
91600 + atomic_long_inc_unchecked(&num_poisoned_pages);
91601 }
91602 } else {
91603 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
91604 @@ -1684,11 +1684,11 @@ int soft_offline_page(struct page *page, int flags)
91605 if (PageHuge(page)) {
91606 set_page_hwpoison_huge_page(hpage);
91607 dequeue_hwpoisoned_huge_page(hpage);
91608 - atomic_long_add(1 << compound_order(hpage),
91609 + atomic_long_add_unchecked(1 << compound_order(hpage),
91610 &num_poisoned_pages);
91611 } else {
91612 SetPageHWPoison(page);
91613 - atomic_long_inc(&num_poisoned_pages);
91614 + atomic_long_inc_unchecked(&num_poisoned_pages);
91615 }
91616 }
91617 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
91618 diff --git a/mm/memory.c b/mm/memory.c
91619 index dda27b9..c56b9d6 100644
91620 --- a/mm/memory.c
91621 +++ b/mm/memory.c
91622 @@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91623 free_pte_range(tlb, pmd, addr);
91624 } while (pmd++, addr = next, addr != end);
91625
91626 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
91627 start &= PUD_MASK;
91628 if (start < floor)
91629 return;
91630 @@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91631 pmd = pmd_offset(pud, start);
91632 pud_clear(pud);
91633 pmd_free_tlb(tlb, pmd, start);
91634 +#endif
91635 +
91636 }
91637
91638 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91639 @@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91640 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
91641 } while (pud++, addr = next, addr != end);
91642
91643 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
91644 start &= PGDIR_MASK;
91645 if (start < floor)
91646 return;
91647 @@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91648 pud = pud_offset(pgd, start);
91649 pgd_clear(pgd);
91650 pud_free_tlb(tlb, pud, start);
91651 +#endif
91652 +
91653 }
91654
91655 /*
91656 @@ -1635,12 +1641,6 @@ no_page_table:
91657 return page;
91658 }
91659
91660 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
91661 -{
91662 - return stack_guard_page_start(vma, addr) ||
91663 - stack_guard_page_end(vma, addr+PAGE_SIZE);
91664 -}
91665 -
91666 /**
91667 * __get_user_pages() - pin user pages in memory
91668 * @tsk: task_struct of target task
91669 @@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91670
91671 i = 0;
91672
91673 - do {
91674 + while (nr_pages) {
91675 struct vm_area_struct *vma;
91676
91677 - vma = find_extend_vma(mm, start);
91678 + vma = find_vma(mm, start);
91679 if (!vma && in_gate_area(mm, start)) {
91680 unsigned long pg = start & PAGE_MASK;
91681 pgd_t *pgd;
91682 @@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91683 goto next_page;
91684 }
91685
91686 - if (!vma ||
91687 + if (!vma || start < vma->vm_start ||
91688 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
91689 !(vm_flags & vma->vm_flags))
91690 return i ? : -EFAULT;
91691 @@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91692 int ret;
91693 unsigned int fault_flags = 0;
91694
91695 - /* For mlock, just skip the stack guard page. */
91696 - if (foll_flags & FOLL_MLOCK) {
91697 - if (stack_guard_page(vma, start))
91698 - goto next_page;
91699 - }
91700 if (foll_flags & FOLL_WRITE)
91701 fault_flags |= FAULT_FLAG_WRITE;
91702 if (nonblocking)
91703 @@ -1892,7 +1887,7 @@ next_page:
91704 start += page_increm * PAGE_SIZE;
91705 nr_pages -= page_increm;
91706 } while (nr_pages && start < vma->vm_end);
91707 - } while (nr_pages);
91708 + }
91709 return i;
91710 }
91711 EXPORT_SYMBOL(__get_user_pages);
91712 @@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
91713 page_add_file_rmap(page);
91714 set_pte_at(mm, addr, pte, mk_pte(page, prot));
91715
91716 +#ifdef CONFIG_PAX_SEGMEXEC
91717 + pax_mirror_file_pte(vma, addr, page, ptl);
91718 +#endif
91719 +
91720 retval = 0;
91721 pte_unmap_unlock(pte, ptl);
91722 return retval;
91723 @@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
91724 if (!page_count(page))
91725 return -EINVAL;
91726 if (!(vma->vm_flags & VM_MIXEDMAP)) {
91727 +
91728 +#ifdef CONFIG_PAX_SEGMEXEC
91729 + struct vm_area_struct *vma_m;
91730 +#endif
91731 +
91732 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
91733 BUG_ON(vma->vm_flags & VM_PFNMAP);
91734 vma->vm_flags |= VM_MIXEDMAP;
91735 +
91736 +#ifdef CONFIG_PAX_SEGMEXEC
91737 + vma_m = pax_find_mirror_vma(vma);
91738 + if (vma_m)
91739 + vma_m->vm_flags |= VM_MIXEDMAP;
91740 +#endif
91741 +
91742 }
91743 return insert_page(vma, addr, page, vma->vm_page_prot);
91744 }
91745 @@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
91746 unsigned long pfn)
91747 {
91748 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
91749 + BUG_ON(vma->vm_mirror);
91750
91751 if (addr < vma->vm_start || addr >= vma->vm_end)
91752 return -EFAULT;
91753 @@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
91754
91755 BUG_ON(pud_huge(*pud));
91756
91757 - pmd = pmd_alloc(mm, pud, addr);
91758 + pmd = (mm == &init_mm) ?
91759 + pmd_alloc_kernel(mm, pud, addr) :
91760 + pmd_alloc(mm, pud, addr);
91761 if (!pmd)
91762 return -ENOMEM;
91763 do {
91764 @@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
91765 unsigned long next;
91766 int err;
91767
91768 - pud = pud_alloc(mm, pgd, addr);
91769 + pud = (mm == &init_mm) ?
91770 + pud_alloc_kernel(mm, pgd, addr) :
91771 + pud_alloc(mm, pgd, addr);
91772 if (!pud)
91773 return -ENOMEM;
91774 do {
91775 @@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
91776 copy_user_highpage(dst, src, va, vma);
91777 }
91778
91779 +#ifdef CONFIG_PAX_SEGMEXEC
91780 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
91781 +{
91782 + struct mm_struct *mm = vma->vm_mm;
91783 + spinlock_t *ptl;
91784 + pte_t *pte, entry;
91785 +
91786 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
91787 + entry = *pte;
91788 + if (!pte_present(entry)) {
91789 + if (!pte_none(entry)) {
91790 + BUG_ON(pte_file(entry));
91791 + free_swap_and_cache(pte_to_swp_entry(entry));
91792 + pte_clear_not_present_full(mm, address, pte, 0);
91793 + }
91794 + } else {
91795 + struct page *page;
91796 +
91797 + flush_cache_page(vma, address, pte_pfn(entry));
91798 + entry = ptep_clear_flush(vma, address, pte);
91799 + BUG_ON(pte_dirty(entry));
91800 + page = vm_normal_page(vma, address, entry);
91801 + if (page) {
91802 + update_hiwater_rss(mm);
91803 + if (PageAnon(page))
91804 + dec_mm_counter_fast(mm, MM_ANONPAGES);
91805 + else
91806 + dec_mm_counter_fast(mm, MM_FILEPAGES);
91807 + page_remove_rmap(page);
91808 + page_cache_release(page);
91809 + }
91810 + }
91811 + pte_unmap_unlock(pte, ptl);
91812 +}
91813 +
91814 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
91815 + *
91816 + * the ptl of the lower mapped page is held on entry and is not released on exit
91817 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
91818 + */
91819 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91820 +{
91821 + struct mm_struct *mm = vma->vm_mm;
91822 + unsigned long address_m;
91823 + spinlock_t *ptl_m;
91824 + struct vm_area_struct *vma_m;
91825 + pmd_t *pmd_m;
91826 + pte_t *pte_m, entry_m;
91827 +
91828 + BUG_ON(!page_m || !PageAnon(page_m));
91829 +
91830 + vma_m = pax_find_mirror_vma(vma);
91831 + if (!vma_m)
91832 + return;
91833 +
91834 + BUG_ON(!PageLocked(page_m));
91835 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91836 + address_m = address + SEGMEXEC_TASK_SIZE;
91837 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91838 + pte_m = pte_offset_map(pmd_m, address_m);
91839 + ptl_m = pte_lockptr(mm, pmd_m);
91840 + if (ptl != ptl_m) {
91841 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91842 + if (!pte_none(*pte_m))
91843 + goto out;
91844 + }
91845 +
91846 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
91847 + page_cache_get(page_m);
91848 + page_add_anon_rmap(page_m, vma_m, address_m);
91849 + inc_mm_counter_fast(mm, MM_ANONPAGES);
91850 + set_pte_at(mm, address_m, pte_m, entry_m);
91851 + update_mmu_cache(vma_m, address_m, pte_m);
91852 +out:
91853 + if (ptl != ptl_m)
91854 + spin_unlock(ptl_m);
91855 + pte_unmap(pte_m);
91856 + unlock_page(page_m);
91857 +}
91858 +
91859 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91860 +{
91861 + struct mm_struct *mm = vma->vm_mm;
91862 + unsigned long address_m;
91863 + spinlock_t *ptl_m;
91864 + struct vm_area_struct *vma_m;
91865 + pmd_t *pmd_m;
91866 + pte_t *pte_m, entry_m;
91867 +
91868 + BUG_ON(!page_m || PageAnon(page_m));
91869 +
91870 + vma_m = pax_find_mirror_vma(vma);
91871 + if (!vma_m)
91872 + return;
91873 +
91874 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91875 + address_m = address + SEGMEXEC_TASK_SIZE;
91876 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91877 + pte_m = pte_offset_map(pmd_m, address_m);
91878 + ptl_m = pte_lockptr(mm, pmd_m);
91879 + if (ptl != ptl_m) {
91880 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91881 + if (!pte_none(*pte_m))
91882 + goto out;
91883 + }
91884 +
91885 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
91886 + page_cache_get(page_m);
91887 + page_add_file_rmap(page_m);
91888 + inc_mm_counter_fast(mm, MM_FILEPAGES);
91889 + set_pte_at(mm, address_m, pte_m, entry_m);
91890 + update_mmu_cache(vma_m, address_m, pte_m);
91891 +out:
91892 + if (ptl != ptl_m)
91893 + spin_unlock(ptl_m);
91894 + pte_unmap(pte_m);
91895 +}
91896 +
91897 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
91898 +{
91899 + struct mm_struct *mm = vma->vm_mm;
91900 + unsigned long address_m;
91901 + spinlock_t *ptl_m;
91902 + struct vm_area_struct *vma_m;
91903 + pmd_t *pmd_m;
91904 + pte_t *pte_m, entry_m;
91905 +
91906 + vma_m = pax_find_mirror_vma(vma);
91907 + if (!vma_m)
91908 + return;
91909 +
91910 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91911 + address_m = address + SEGMEXEC_TASK_SIZE;
91912 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91913 + pte_m = pte_offset_map(pmd_m, address_m);
91914 + ptl_m = pte_lockptr(mm, pmd_m);
91915 + if (ptl != ptl_m) {
91916 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91917 + if (!pte_none(*pte_m))
91918 + goto out;
91919 + }
91920 +
91921 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
91922 + set_pte_at(mm, address_m, pte_m, entry_m);
91923 +out:
91924 + if (ptl != ptl_m)
91925 + spin_unlock(ptl_m);
91926 + pte_unmap(pte_m);
91927 +}
91928 +
91929 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
91930 +{
91931 + struct page *page_m;
91932 + pte_t entry;
91933 +
91934 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
91935 + goto out;
91936 +
91937 + entry = *pte;
91938 + page_m = vm_normal_page(vma, address, entry);
91939 + if (!page_m)
91940 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
91941 + else if (PageAnon(page_m)) {
91942 + if (pax_find_mirror_vma(vma)) {
91943 + pte_unmap_unlock(pte, ptl);
91944 + lock_page(page_m);
91945 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
91946 + if (pte_same(entry, *pte))
91947 + pax_mirror_anon_pte(vma, address, page_m, ptl);
91948 + else
91949 + unlock_page(page_m);
91950 + }
91951 + } else
91952 + pax_mirror_file_pte(vma, address, page_m, ptl);
91953 +
91954 +out:
91955 + pte_unmap_unlock(pte, ptl);
91956 +}
91957 +#endif
91958 +
91959 /*
91960 * This routine handles present pages, when users try to write
91961 * to a shared page. It is done by copying the page to a new address
91962 @@ -2807,6 +3003,12 @@ gotten:
91963 */
91964 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
91965 if (likely(pte_same(*page_table, orig_pte))) {
91966 +
91967 +#ifdef CONFIG_PAX_SEGMEXEC
91968 + if (pax_find_mirror_vma(vma))
91969 + BUG_ON(!trylock_page(new_page));
91970 +#endif
91971 +
91972 if (old_page) {
91973 if (!PageAnon(old_page)) {
91974 dec_mm_counter_fast(mm, MM_FILEPAGES);
91975 @@ -2858,6 +3060,10 @@ gotten:
91976 page_remove_rmap(old_page);
91977 }
91978
91979 +#ifdef CONFIG_PAX_SEGMEXEC
91980 + pax_mirror_anon_pte(vma, address, new_page, ptl);
91981 +#endif
91982 +
91983 /* Free the old page.. */
91984 new_page = old_page;
91985 ret |= VM_FAULT_WRITE;
91986 @@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91987 swap_free(entry);
91988 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
91989 try_to_free_swap(page);
91990 +
91991 +#ifdef CONFIG_PAX_SEGMEXEC
91992 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
91993 +#endif
91994 +
91995 unlock_page(page);
91996 if (page != swapcache) {
91997 /*
91998 @@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91999
92000 /* No need to invalidate - it was non-present before */
92001 update_mmu_cache(vma, address, page_table);
92002 +
92003 +#ifdef CONFIG_PAX_SEGMEXEC
92004 + pax_mirror_anon_pte(vma, address, page, ptl);
92005 +#endif
92006 +
92007 unlock:
92008 pte_unmap_unlock(page_table, ptl);
92009 out:
92010 @@ -3177,40 +3393,6 @@ out_release:
92011 }
92012
92013 /*
92014 - * This is like a special single-page "expand_{down|up}wards()",
92015 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
92016 - * doesn't hit another vma.
92017 - */
92018 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92019 -{
92020 - address &= PAGE_MASK;
92021 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92022 - struct vm_area_struct *prev = vma->vm_prev;
92023 -
92024 - /*
92025 - * Is there a mapping abutting this one below?
92026 - *
92027 - * That's only ok if it's the same stack mapping
92028 - * that has gotten split..
92029 - */
92030 - if (prev && prev->vm_end == address)
92031 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92032 -
92033 - expand_downwards(vma, address - PAGE_SIZE);
92034 - }
92035 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92036 - struct vm_area_struct *next = vma->vm_next;
92037 -
92038 - /* As VM_GROWSDOWN but s/below/above/ */
92039 - if (next && next->vm_start == address + PAGE_SIZE)
92040 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92041 -
92042 - expand_upwards(vma, address + PAGE_SIZE);
92043 - }
92044 - return 0;
92045 -}
92046 -
92047 -/*
92048 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92049 * but allow concurrent faults), and pte mapped but not yet locked.
92050 * We return with mmap_sem still held, but pte unmapped and unlocked.
92051 @@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92052 unsigned long address, pte_t *page_table, pmd_t *pmd,
92053 unsigned int flags)
92054 {
92055 - struct page *page;
92056 + struct page *page = NULL;
92057 spinlock_t *ptl;
92058 pte_t entry;
92059
92060 - pte_unmap(page_table);
92061 -
92062 - /* Check if we need to add a guard page to the stack */
92063 - if (check_stack_guard_page(vma, address) < 0)
92064 - return VM_FAULT_SIGBUS;
92065 -
92066 - /* Use the zero-page for reads */
92067 if (!(flags & FAULT_FLAG_WRITE)) {
92068 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92069 vma->vm_page_prot));
92070 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92071 + ptl = pte_lockptr(mm, pmd);
92072 + spin_lock(ptl);
92073 if (!pte_none(*page_table))
92074 goto unlock;
92075 goto setpte;
92076 }
92077
92078 /* Allocate our own private page. */
92079 + pte_unmap(page_table);
92080 +
92081 if (unlikely(anon_vma_prepare(vma)))
92082 goto oom;
92083 page = alloc_zeroed_user_highpage_movable(vma, address);
92084 @@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92085 if (!pte_none(*page_table))
92086 goto release;
92087
92088 +#ifdef CONFIG_PAX_SEGMEXEC
92089 + if (pax_find_mirror_vma(vma))
92090 + BUG_ON(!trylock_page(page));
92091 +#endif
92092 +
92093 inc_mm_counter_fast(mm, MM_ANONPAGES);
92094 page_add_new_anon_rmap(page, vma, address);
92095 setpte:
92096 @@ -3270,6 +3453,12 @@ setpte:
92097
92098 /* No need to invalidate - it was non-present before */
92099 update_mmu_cache(vma, address, page_table);
92100 +
92101 +#ifdef CONFIG_PAX_SEGMEXEC
92102 + if (page)
92103 + pax_mirror_anon_pte(vma, address, page, ptl);
92104 +#endif
92105 +
92106 unlock:
92107 pte_unmap_unlock(page_table, ptl);
92108 return 0;
92109 @@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92110 */
92111 /* Only go through if we didn't race with anybody else... */
92112 if (likely(pte_same(*page_table, orig_pte))) {
92113 +
92114 +#ifdef CONFIG_PAX_SEGMEXEC
92115 + if (anon && pax_find_mirror_vma(vma))
92116 + BUG_ON(!trylock_page(page));
92117 +#endif
92118 +
92119 flush_icache_page(vma, page);
92120 entry = mk_pte(page, vma->vm_page_prot);
92121 if (flags & FAULT_FLAG_WRITE)
92122 @@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92123
92124 /* no need to invalidate: a not-present page won't be cached */
92125 update_mmu_cache(vma, address, page_table);
92126 +
92127 +#ifdef CONFIG_PAX_SEGMEXEC
92128 + if (anon)
92129 + pax_mirror_anon_pte(vma, address, page, ptl);
92130 + else
92131 + pax_mirror_file_pte(vma, address, page, ptl);
92132 +#endif
92133 +
92134 } else {
92135 if (cow_page)
92136 mem_cgroup_uncharge_page(cow_page);
92137 @@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92138 if (flags & FAULT_FLAG_WRITE)
92139 flush_tlb_fix_spurious_fault(vma, address);
92140 }
92141 +
92142 +#ifdef CONFIG_PAX_SEGMEXEC
92143 + pax_mirror_pte(vma, address, pte, pmd, ptl);
92144 + return 0;
92145 +#endif
92146 +
92147 unlock:
92148 pte_unmap_unlock(pte, ptl);
92149 return 0;
92150 @@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92151 pmd_t *pmd;
92152 pte_t *pte;
92153
92154 +#ifdef CONFIG_PAX_SEGMEXEC
92155 + struct vm_area_struct *vma_m;
92156 +#endif
92157 +
92158 if (unlikely(is_vm_hugetlb_page(vma)))
92159 return hugetlb_fault(mm, vma, address, flags);
92160
92161 +#ifdef CONFIG_PAX_SEGMEXEC
92162 + vma_m = pax_find_mirror_vma(vma);
92163 + if (vma_m) {
92164 + unsigned long address_m;
92165 + pgd_t *pgd_m;
92166 + pud_t *pud_m;
92167 + pmd_t *pmd_m;
92168 +
92169 + if (vma->vm_start > vma_m->vm_start) {
92170 + address_m = address;
92171 + address -= SEGMEXEC_TASK_SIZE;
92172 + vma = vma_m;
92173 + } else
92174 + address_m = address + SEGMEXEC_TASK_SIZE;
92175 +
92176 + pgd_m = pgd_offset(mm, address_m);
92177 + pud_m = pud_alloc(mm, pgd_m, address_m);
92178 + if (!pud_m)
92179 + return VM_FAULT_OOM;
92180 + pmd_m = pmd_alloc(mm, pud_m, address_m);
92181 + if (!pmd_m)
92182 + return VM_FAULT_OOM;
92183 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92184 + return VM_FAULT_OOM;
92185 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92186 + }
92187 +#endif
92188 +
92189 pgd = pgd_offset(mm, address);
92190 pud = pud_alloc(mm, pgd, address);
92191 if (!pud)
92192 @@ -3830,6 +4071,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92193 spin_unlock(&mm->page_table_lock);
92194 return 0;
92195 }
92196 +
92197 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92198 +{
92199 + pud_t *new = pud_alloc_one(mm, address);
92200 + if (!new)
92201 + return -ENOMEM;
92202 +
92203 + smp_wmb(); /* See comment in __pte_alloc */
92204 +
92205 + spin_lock(&mm->page_table_lock);
92206 + if (pgd_present(*pgd)) /* Another has populated it */
92207 + pud_free(mm, new);
92208 + else
92209 + pgd_populate_kernel(mm, pgd, new);
92210 + spin_unlock(&mm->page_table_lock);
92211 + return 0;
92212 +}
92213 #endif /* __PAGETABLE_PUD_FOLDED */
92214
92215 #ifndef __PAGETABLE_PMD_FOLDED
92216 @@ -3860,6 +4118,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92217 spin_unlock(&mm->page_table_lock);
92218 return 0;
92219 }
92220 +
92221 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92222 +{
92223 + pmd_t *new = pmd_alloc_one(mm, address);
92224 + if (!new)
92225 + return -ENOMEM;
92226 +
92227 + smp_wmb(); /* See comment in __pte_alloc */
92228 +
92229 + spin_lock(&mm->page_table_lock);
92230 +#ifndef __ARCH_HAS_4LEVEL_HACK
92231 + if (pud_present(*pud)) /* Another has populated it */
92232 + pmd_free(mm, new);
92233 + else
92234 + pud_populate_kernel(mm, pud, new);
92235 +#else
92236 + if (pgd_present(*pud)) /* Another has populated it */
92237 + pmd_free(mm, new);
92238 + else
92239 + pgd_populate_kernel(mm, pud, new);
92240 +#endif /* __ARCH_HAS_4LEVEL_HACK */
92241 + spin_unlock(&mm->page_table_lock);
92242 + return 0;
92243 +}
92244 #endif /* __PAGETABLE_PMD_FOLDED */
92245
92246 #if !defined(__HAVE_ARCH_GATE_AREA)
92247 @@ -3873,7 +4155,7 @@ static int __init gate_vma_init(void)
92248 gate_vma.vm_start = FIXADDR_USER_START;
92249 gate_vma.vm_end = FIXADDR_USER_END;
92250 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92251 - gate_vma.vm_page_prot = __P101;
92252 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92253
92254 return 0;
92255 }
92256 @@ -4007,8 +4289,8 @@ out:
92257 return ret;
92258 }
92259
92260 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92261 - void *buf, int len, int write)
92262 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92263 + void *buf, size_t len, int write)
92264 {
92265 resource_size_t phys_addr;
92266 unsigned long prot = 0;
92267 @@ -4034,8 +4316,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92268 * Access another process' address space as given in mm. If non-NULL, use the
92269 * given task for page fault accounting.
92270 */
92271 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92272 - unsigned long addr, void *buf, int len, int write)
92273 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92274 + unsigned long addr, void *buf, size_t len, int write)
92275 {
92276 struct vm_area_struct *vma;
92277 void *old_buf = buf;
92278 @@ -4043,7 +4325,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92279 down_read(&mm->mmap_sem);
92280 /* ignore errors, just check how much was successfully transferred */
92281 while (len) {
92282 - int bytes, ret, offset;
92283 + ssize_t bytes, ret, offset;
92284 void *maddr;
92285 struct page *page = NULL;
92286
92287 @@ -4102,8 +4384,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92288 *
92289 * The caller must hold a reference on @mm.
92290 */
92291 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92292 - void *buf, int len, int write)
92293 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92294 + void *buf, size_t len, int write)
92295 {
92296 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92297 }
92298 @@ -4113,11 +4395,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92299 * Source/target buffer must be kernel space,
92300 * Do not walk the page table directly, use get_user_pages
92301 */
92302 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
92303 - void *buf, int len, int write)
92304 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92305 + void *buf, size_t len, int write)
92306 {
92307 struct mm_struct *mm;
92308 - int ret;
92309 + ssize_t ret;
92310
92311 mm = get_task_mm(tsk);
92312 if (!mm)
92313 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92314 index cb2f3dd..fb80468 100644
92315 --- a/mm/mempolicy.c
92316 +++ b/mm/mempolicy.c
92317 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92318 unsigned long vmstart;
92319 unsigned long vmend;
92320
92321 +#ifdef CONFIG_PAX_SEGMEXEC
92322 + struct vm_area_struct *vma_m;
92323 +#endif
92324 +
92325 vma = find_vma(mm, start);
92326 if (!vma || vma->vm_start > start)
92327 return -EFAULT;
92328 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92329 err = vma_replace_policy(vma, new_pol);
92330 if (err)
92331 goto out;
92332 +
92333 +#ifdef CONFIG_PAX_SEGMEXEC
92334 + vma_m = pax_find_mirror_vma(vma);
92335 + if (vma_m) {
92336 + err = vma_replace_policy(vma_m, new_pol);
92337 + if (err)
92338 + goto out;
92339 + }
92340 +#endif
92341 +
92342 }
92343
92344 out:
92345 @@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92346
92347 if (end < start)
92348 return -EINVAL;
92349 +
92350 +#ifdef CONFIG_PAX_SEGMEXEC
92351 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92352 + if (end > SEGMEXEC_TASK_SIZE)
92353 + return -EINVAL;
92354 + } else
92355 +#endif
92356 +
92357 + if (end > TASK_SIZE)
92358 + return -EINVAL;
92359 +
92360 if (end == start)
92361 return 0;
92362
92363 @@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92364 */
92365 tcred = __task_cred(task);
92366 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92367 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92368 - !capable(CAP_SYS_NICE)) {
92369 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92370 rcu_read_unlock();
92371 err = -EPERM;
92372 goto out_put;
92373 @@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92374 goto out;
92375 }
92376
92377 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92378 + if (mm != current->mm &&
92379 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92380 + mmput(mm);
92381 + err = -EPERM;
92382 + goto out;
92383 + }
92384 +#endif
92385 +
92386 err = do_migrate_pages(mm, old, new,
92387 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92388
92389 diff --git a/mm/migrate.c b/mm/migrate.c
92390 index 9194375..75c81e2 100644
92391 --- a/mm/migrate.c
92392 +++ b/mm/migrate.c
92393 @@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92394 */
92395 tcred = __task_cred(task);
92396 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92397 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92398 - !capable(CAP_SYS_NICE)) {
92399 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92400 rcu_read_unlock();
92401 err = -EPERM;
92402 goto out;
92403 diff --git a/mm/mlock.c b/mm/mlock.c
92404 index 192e6ee..b044449 100644
92405 --- a/mm/mlock.c
92406 +++ b/mm/mlock.c
92407 @@ -14,6 +14,7 @@
92408 #include <linux/pagevec.h>
92409 #include <linux/mempolicy.h>
92410 #include <linux/syscalls.h>
92411 +#include <linux/security.h>
92412 #include <linux/sched.h>
92413 #include <linux/export.h>
92414 #include <linux/rmap.h>
92415 @@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92416 {
92417 unsigned long nstart, end, tmp;
92418 struct vm_area_struct * vma, * prev;
92419 - int error;
92420 + int error = 0;
92421
92422 VM_BUG_ON(start & ~PAGE_MASK);
92423 VM_BUG_ON(len != PAGE_ALIGN(len));
92424 @@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92425 return -EINVAL;
92426 if (end == start)
92427 return 0;
92428 + if (end > TASK_SIZE)
92429 + return -EINVAL;
92430 +
92431 vma = find_vma(current->mm, start);
92432 if (!vma || vma->vm_start > start)
92433 return -ENOMEM;
92434 @@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92435 for (nstart = start ; ; ) {
92436 vm_flags_t newflags;
92437
92438 +#ifdef CONFIG_PAX_SEGMEXEC
92439 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92440 + break;
92441 +#endif
92442 +
92443 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92444
92445 newflags = vma->vm_flags & ~VM_LOCKED;
92446 @@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
92447 lock_limit >>= PAGE_SHIFT;
92448
92449 /* check against resource limits */
92450 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
92451 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
92452 error = do_mlock(start, len, 1);
92453 up_write(&current->mm->mmap_sem);
92454 @@ -754,6 +764,11 @@ static int do_mlockall(int flags)
92455 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
92456 vm_flags_t newflags;
92457
92458 +#ifdef CONFIG_PAX_SEGMEXEC
92459 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92460 + break;
92461 +#endif
92462 +
92463 newflags = vma->vm_flags & ~VM_LOCKED;
92464 if (flags & MCL_CURRENT)
92465 newflags |= VM_LOCKED;
92466 @@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
92467 lock_limit >>= PAGE_SHIFT;
92468
92469 ret = -ENOMEM;
92470 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
92471 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
92472 capable(CAP_IPC_LOCK))
92473 ret = do_mlockall(flags);
92474 diff --git a/mm/mmap.c b/mm/mmap.c
92475 index 546db74..650d1b9 100644
92476 --- a/mm/mmap.c
92477 +++ b/mm/mmap.c
92478 @@ -36,6 +36,7 @@
92479 #include <linux/sched/sysctl.h>
92480 #include <linux/notifier.h>
92481 #include <linux/memory.h>
92482 +#include <linux/random.h>
92483
92484 #include <asm/uaccess.h>
92485 #include <asm/cacheflush.h>
92486 @@ -52,6 +53,16 @@
92487 #define arch_rebalance_pgtables(addr, len) (addr)
92488 #endif
92489
92490 +static inline void verify_mm_writelocked(struct mm_struct *mm)
92491 +{
92492 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
92493 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92494 + up_read(&mm->mmap_sem);
92495 + BUG();
92496 + }
92497 +#endif
92498 +}
92499 +
92500 static void unmap_region(struct mm_struct *mm,
92501 struct vm_area_struct *vma, struct vm_area_struct *prev,
92502 unsigned long start, unsigned long end);
92503 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
92504 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
92505 *
92506 */
92507 -pgprot_t protection_map[16] = {
92508 +pgprot_t protection_map[16] __read_only = {
92509 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
92510 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
92511 };
92512
92513 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
92514 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
92515 {
92516 - return __pgprot(pgprot_val(protection_map[vm_flags &
92517 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
92518 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
92519 pgprot_val(arch_vm_get_page_prot(vm_flags)));
92520 +
92521 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92522 + if (!(__supported_pte_mask & _PAGE_NX) &&
92523 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
92524 + (vm_flags & (VM_READ | VM_WRITE)))
92525 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
92526 +#endif
92527 +
92528 + return prot;
92529 }
92530 EXPORT_SYMBOL(vm_get_page_prot);
92531
92532 @@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
92533 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
92534 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92535 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92536 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
92537 /*
92538 * Make sure vm_committed_as in one cacheline and not cacheline shared with
92539 * other variables. It can be updated by several CPUs frequently.
92540 @@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
92541 struct vm_area_struct *next = vma->vm_next;
92542
92543 might_sleep();
92544 + BUG_ON(vma->vm_mirror);
92545 if (vma->vm_ops && vma->vm_ops->close)
92546 vma->vm_ops->close(vma);
92547 if (vma->vm_file)
92548 @@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
92549 * not page aligned -Ram Gupta
92550 */
92551 rlim = rlimit(RLIMIT_DATA);
92552 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
92553 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
92554 (mm->end_data - mm->start_data) > rlim)
92555 goto out;
92556 @@ -939,6 +962,12 @@ static int
92557 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
92558 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92559 {
92560 +
92561 +#ifdef CONFIG_PAX_SEGMEXEC
92562 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
92563 + return 0;
92564 +#endif
92565 +
92566 if (is_mergeable_vma(vma, file, vm_flags) &&
92567 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92568 if (vma->vm_pgoff == vm_pgoff)
92569 @@ -958,6 +987,12 @@ static int
92570 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92571 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92572 {
92573 +
92574 +#ifdef CONFIG_PAX_SEGMEXEC
92575 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
92576 + return 0;
92577 +#endif
92578 +
92579 if (is_mergeable_vma(vma, file, vm_flags) &&
92580 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92581 pgoff_t vm_pglen;
92582 @@ -1000,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92583 struct vm_area_struct *vma_merge(struct mm_struct *mm,
92584 struct vm_area_struct *prev, unsigned long addr,
92585 unsigned long end, unsigned long vm_flags,
92586 - struct anon_vma *anon_vma, struct file *file,
92587 + struct anon_vma *anon_vma, struct file *file,
92588 pgoff_t pgoff, struct mempolicy *policy)
92589 {
92590 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
92591 struct vm_area_struct *area, *next;
92592 int err;
92593
92594 +#ifdef CONFIG_PAX_SEGMEXEC
92595 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
92596 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
92597 +
92598 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
92599 +#endif
92600 +
92601 /*
92602 * We later require that vma->vm_flags == vm_flags,
92603 * so this tests vma->vm_flags & VM_SPECIAL, too.
92604 @@ -1022,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92605 if (next && next->vm_end == end) /* cases 6, 7, 8 */
92606 next = next->vm_next;
92607
92608 +#ifdef CONFIG_PAX_SEGMEXEC
92609 + if (prev)
92610 + prev_m = pax_find_mirror_vma(prev);
92611 + if (area)
92612 + area_m = pax_find_mirror_vma(area);
92613 + if (next)
92614 + next_m = pax_find_mirror_vma(next);
92615 +#endif
92616 +
92617 /*
92618 * Can it merge with the predecessor?
92619 */
92620 @@ -1041,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92621 /* cases 1, 6 */
92622 err = vma_adjust(prev, prev->vm_start,
92623 next->vm_end, prev->vm_pgoff, NULL);
92624 - } else /* cases 2, 5, 7 */
92625 +
92626 +#ifdef CONFIG_PAX_SEGMEXEC
92627 + if (!err && prev_m)
92628 + err = vma_adjust(prev_m, prev_m->vm_start,
92629 + next_m->vm_end, prev_m->vm_pgoff, NULL);
92630 +#endif
92631 +
92632 + } else { /* cases 2, 5, 7 */
92633 err = vma_adjust(prev, prev->vm_start,
92634 end, prev->vm_pgoff, NULL);
92635 +
92636 +#ifdef CONFIG_PAX_SEGMEXEC
92637 + if (!err && prev_m)
92638 + err = vma_adjust(prev_m, prev_m->vm_start,
92639 + end_m, prev_m->vm_pgoff, NULL);
92640 +#endif
92641 +
92642 + }
92643 if (err)
92644 return NULL;
92645 khugepaged_enter_vma_merge(prev);
92646 @@ -1057,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92647 mpol_equal(policy, vma_policy(next)) &&
92648 can_vma_merge_before(next, vm_flags,
92649 anon_vma, file, pgoff+pglen)) {
92650 - if (prev && addr < prev->vm_end) /* case 4 */
92651 + if (prev && addr < prev->vm_end) { /* case 4 */
92652 err = vma_adjust(prev, prev->vm_start,
92653 addr, prev->vm_pgoff, NULL);
92654 - else /* cases 3, 8 */
92655 +
92656 +#ifdef CONFIG_PAX_SEGMEXEC
92657 + if (!err && prev_m)
92658 + err = vma_adjust(prev_m, prev_m->vm_start,
92659 + addr_m, prev_m->vm_pgoff, NULL);
92660 +#endif
92661 +
92662 + } else { /* cases 3, 8 */
92663 err = vma_adjust(area, addr, next->vm_end,
92664 next->vm_pgoff - pglen, NULL);
92665 +
92666 +#ifdef CONFIG_PAX_SEGMEXEC
92667 + if (!err && area_m)
92668 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
92669 + next_m->vm_pgoff - pglen, NULL);
92670 +#endif
92671 +
92672 + }
92673 if (err)
92674 return NULL;
92675 khugepaged_enter_vma_merge(area);
92676 @@ -1171,8 +1252,10 @@ none:
92677 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92678 struct file *file, long pages)
92679 {
92680 - const unsigned long stack_flags
92681 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
92682 +
92683 +#ifdef CONFIG_PAX_RANDMMAP
92684 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92685 +#endif
92686
92687 mm->total_vm += pages;
92688
92689 @@ -1180,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92690 mm->shared_vm += pages;
92691 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
92692 mm->exec_vm += pages;
92693 - } else if (flags & stack_flags)
92694 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
92695 mm->stack_vm += pages;
92696 }
92697 #endif /* CONFIG_PROC_FS */
92698 @@ -1218,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92699 * (the exception is when the underlying filesystem is noexec
92700 * mounted, in which case we dont add PROT_EXEC.)
92701 */
92702 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92703 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92704 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
92705 prot |= PROT_EXEC;
92706
92707 @@ -1244,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92708 /* Obtain the address to map to. we verify (or select) it and ensure
92709 * that it represents a valid section of the address space.
92710 */
92711 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
92712 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
92713 if (addr & ~PAGE_MASK)
92714 return addr;
92715
92716 @@ -1255,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92717 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
92718 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
92719
92720 +#ifdef CONFIG_PAX_MPROTECT
92721 + if (mm->pax_flags & MF_PAX_MPROTECT) {
92722 +
92723 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
92724 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
92725 + mm->binfmt->handle_mmap)
92726 + mm->binfmt->handle_mmap(file);
92727 +#endif
92728 +
92729 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
92730 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
92731 + gr_log_rwxmmap(file);
92732 +
92733 +#ifdef CONFIG_PAX_EMUPLT
92734 + vm_flags &= ~VM_EXEC;
92735 +#else
92736 + return -EPERM;
92737 +#endif
92738 +
92739 + }
92740 +
92741 + if (!(vm_flags & VM_EXEC))
92742 + vm_flags &= ~VM_MAYEXEC;
92743 +#else
92744 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92745 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92746 +#endif
92747 + else
92748 + vm_flags &= ~VM_MAYWRITE;
92749 + }
92750 +#endif
92751 +
92752 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92753 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
92754 + vm_flags &= ~VM_PAGEEXEC;
92755 +#endif
92756 +
92757 if (flags & MAP_LOCKED)
92758 if (!can_do_mlock())
92759 return -EPERM;
92760 @@ -1266,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92761 locked += mm->locked_vm;
92762 lock_limit = rlimit(RLIMIT_MEMLOCK);
92763 lock_limit >>= PAGE_SHIFT;
92764 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92765 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
92766 return -EAGAIN;
92767 }
92768 @@ -1350,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92769 vm_flags |= VM_NORESERVE;
92770 }
92771
92772 + if (!gr_acl_handle_mmap(file, prot))
92773 + return -EACCES;
92774 +
92775 addr = mmap_region(file, addr, len, vm_flags, pgoff);
92776 if (!IS_ERR_VALUE(addr) &&
92777 ((vm_flags & VM_LOCKED) ||
92778 @@ -1443,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
92779 vm_flags_t vm_flags = vma->vm_flags;
92780
92781 /* If it was private or non-writable, the write bit is already clear */
92782 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
92783 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
92784 return 0;
92785
92786 /* The backer wishes to know when pages are first written to? */
92787 @@ -1489,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92788 struct rb_node **rb_link, *rb_parent;
92789 unsigned long charged = 0;
92790
92791 +#ifdef CONFIG_PAX_SEGMEXEC
92792 + struct vm_area_struct *vma_m = NULL;
92793 +#endif
92794 +
92795 + /*
92796 + * mm->mmap_sem is required to protect against another thread
92797 + * changing the mappings in case we sleep.
92798 + */
92799 + verify_mm_writelocked(mm);
92800 +
92801 /* Check against address space limit. */
92802 +
92803 +#ifdef CONFIG_PAX_RANDMMAP
92804 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92805 +#endif
92806 +
92807 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
92808 unsigned long nr_pages;
92809
92810 @@ -1508,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92811
92812 /* Clear old maps */
92813 error = -ENOMEM;
92814 -munmap_back:
92815 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92816 if (do_munmap(mm, addr, len))
92817 return -ENOMEM;
92818 - goto munmap_back;
92819 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92820 }
92821
92822 /*
92823 @@ -1543,6 +1681,16 @@ munmap_back:
92824 goto unacct_error;
92825 }
92826
92827 +#ifdef CONFIG_PAX_SEGMEXEC
92828 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
92829 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92830 + if (!vma_m) {
92831 + error = -ENOMEM;
92832 + goto free_vma;
92833 + }
92834 + }
92835 +#endif
92836 +
92837 vma->vm_mm = mm;
92838 vma->vm_start = addr;
92839 vma->vm_end = addr + len;
92840 @@ -1562,6 +1710,13 @@ munmap_back:
92841 if (error)
92842 goto unmap_and_free_vma;
92843
92844 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92845 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
92846 + vma->vm_flags |= VM_PAGEEXEC;
92847 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92848 + }
92849 +#endif
92850 +
92851 /* Can addr have changed??
92852 *
92853 * Answer: Yes, several device drivers can do it in their
92854 @@ -1595,6 +1750,12 @@ munmap_back:
92855 }
92856
92857 vma_link(mm, vma, prev, rb_link, rb_parent);
92858 +
92859 +#ifdef CONFIG_PAX_SEGMEXEC
92860 + if (vma_m)
92861 + BUG_ON(pax_mirror_vma(vma_m, vma));
92862 +#endif
92863 +
92864 /* Once vma denies write, undo our temporary denial count */
92865 if (vm_flags & VM_DENYWRITE)
92866 allow_write_access(file);
92867 @@ -1603,6 +1764,7 @@ out:
92868 perf_event_mmap(vma);
92869
92870 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
92871 + track_exec_limit(mm, addr, addr + len, vm_flags);
92872 if (vm_flags & VM_LOCKED) {
92873 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
92874 vma == get_gate_vma(current->mm)))
92875 @@ -1635,6 +1797,12 @@ unmap_and_free_vma:
92876 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
92877 charged = 0;
92878 free_vma:
92879 +
92880 +#ifdef CONFIG_PAX_SEGMEXEC
92881 + if (vma_m)
92882 + kmem_cache_free(vm_area_cachep, vma_m);
92883 +#endif
92884 +
92885 kmem_cache_free(vm_area_cachep, vma);
92886 unacct_error:
92887 if (charged)
92888 @@ -1642,7 +1810,63 @@ unacct_error:
92889 return error;
92890 }
92891
92892 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
92893 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
92894 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
92895 +{
92896 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
92897 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
92898 +
92899 + return 0;
92900 +}
92901 +#endif
92902 +
92903 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
92904 +{
92905 + if (!vma) {
92906 +#ifdef CONFIG_STACK_GROWSUP
92907 + if (addr > sysctl_heap_stack_gap)
92908 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
92909 + else
92910 + vma = find_vma(current->mm, 0);
92911 + if (vma && (vma->vm_flags & VM_GROWSUP))
92912 + return false;
92913 +#endif
92914 + return true;
92915 + }
92916 +
92917 + if (addr + len > vma->vm_start)
92918 + return false;
92919 +
92920 + if (vma->vm_flags & VM_GROWSDOWN)
92921 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
92922 +#ifdef CONFIG_STACK_GROWSUP
92923 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
92924 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
92925 +#endif
92926 + else if (offset)
92927 + return offset <= vma->vm_start - addr - len;
92928 +
92929 + return true;
92930 +}
92931 +
92932 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
92933 +{
92934 + if (vma->vm_start < len)
92935 + return -ENOMEM;
92936 +
92937 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
92938 + if (offset <= vma->vm_start - len)
92939 + return vma->vm_start - len - offset;
92940 + else
92941 + return -ENOMEM;
92942 + }
92943 +
92944 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
92945 + return vma->vm_start - len - sysctl_heap_stack_gap;
92946 + return -ENOMEM;
92947 +}
92948 +
92949 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
92950 {
92951 /*
92952 * We implement the search by looking for an rbtree node that
92953 @@ -1690,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
92954 }
92955 }
92956
92957 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
92958 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
92959 check_current:
92960 /* Check if current node has a suitable gap */
92961 if (gap_start > high_limit)
92962 return -ENOMEM;
92963 +
92964 + if (gap_end - gap_start > info->threadstack_offset)
92965 + gap_start += info->threadstack_offset;
92966 + else
92967 + gap_start = gap_end;
92968 +
92969 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
92970 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92971 + gap_start += sysctl_heap_stack_gap;
92972 + else
92973 + gap_start = gap_end;
92974 + }
92975 + if (vma->vm_flags & VM_GROWSDOWN) {
92976 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92977 + gap_end -= sysctl_heap_stack_gap;
92978 + else
92979 + gap_end = gap_start;
92980 + }
92981 if (gap_end >= low_limit && gap_end - gap_start >= length)
92982 goto found;
92983
92984 @@ -1744,7 +1986,7 @@ found:
92985 return gap_start;
92986 }
92987
92988 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
92989 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
92990 {
92991 struct mm_struct *mm = current->mm;
92992 struct vm_area_struct *vma;
92993 @@ -1798,6 +2040,24 @@ check_current:
92994 gap_end = vma->vm_start;
92995 if (gap_end < low_limit)
92996 return -ENOMEM;
92997 +
92998 + if (gap_end - gap_start > info->threadstack_offset)
92999 + gap_end -= info->threadstack_offset;
93000 + else
93001 + gap_end = gap_start;
93002 +
93003 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93004 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93005 + gap_start += sysctl_heap_stack_gap;
93006 + else
93007 + gap_start = gap_end;
93008 + }
93009 + if (vma->vm_flags & VM_GROWSDOWN) {
93010 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93011 + gap_end -= sysctl_heap_stack_gap;
93012 + else
93013 + gap_end = gap_start;
93014 + }
93015 if (gap_start <= high_limit && gap_end - gap_start >= length)
93016 goto found;
93017
93018 @@ -1861,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93019 struct mm_struct *mm = current->mm;
93020 struct vm_area_struct *vma;
93021 struct vm_unmapped_area_info info;
93022 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93023
93024 if (len > TASK_SIZE - mmap_min_addr)
93025 return -ENOMEM;
93026 @@ -1868,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93027 if (flags & MAP_FIXED)
93028 return addr;
93029
93030 +#ifdef CONFIG_PAX_RANDMMAP
93031 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93032 +#endif
93033 +
93034 if (addr) {
93035 addr = PAGE_ALIGN(addr);
93036 vma = find_vma(mm, addr);
93037 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93038 - (!vma || addr + len <= vma->vm_start))
93039 + check_heap_stack_gap(vma, addr, len, offset))
93040 return addr;
93041 }
93042
93043 @@ -1881,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93044 info.low_limit = mm->mmap_base;
93045 info.high_limit = TASK_SIZE;
93046 info.align_mask = 0;
93047 + info.threadstack_offset = offset;
93048 return vm_unmapped_area(&info);
93049 }
93050 #endif
93051 @@ -1899,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93052 struct mm_struct *mm = current->mm;
93053 unsigned long addr = addr0;
93054 struct vm_unmapped_area_info info;
93055 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93056
93057 /* requested length too big for entire address space */
93058 if (len > TASK_SIZE - mmap_min_addr)
93059 @@ -1907,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93060 if (flags & MAP_FIXED)
93061 return addr;
93062
93063 +#ifdef CONFIG_PAX_RANDMMAP
93064 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93065 +#endif
93066 +
93067 /* requesting a specific address */
93068 if (addr) {
93069 addr = PAGE_ALIGN(addr);
93070 vma = find_vma(mm, addr);
93071 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93072 - (!vma || addr + len <= vma->vm_start))
93073 + check_heap_stack_gap(vma, addr, len, offset))
93074 return addr;
93075 }
93076
93077 @@ -1921,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93078 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93079 info.high_limit = mm->mmap_base;
93080 info.align_mask = 0;
93081 + info.threadstack_offset = offset;
93082 addr = vm_unmapped_area(&info);
93083
93084 /*
93085 @@ -1933,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93086 VM_BUG_ON(addr != -ENOMEM);
93087 info.flags = 0;
93088 info.low_limit = TASK_UNMAPPED_BASE;
93089 +
93090 +#ifdef CONFIG_PAX_RANDMMAP
93091 + if (mm->pax_flags & MF_PAX_RANDMMAP)
93092 + info.low_limit += mm->delta_mmap;
93093 +#endif
93094 +
93095 info.high_limit = TASK_SIZE;
93096 addr = vm_unmapped_area(&info);
93097 }
93098 @@ -2034,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93099 return vma;
93100 }
93101
93102 +#ifdef CONFIG_PAX_SEGMEXEC
93103 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93104 +{
93105 + struct vm_area_struct *vma_m;
93106 +
93107 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93108 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93109 + BUG_ON(vma->vm_mirror);
93110 + return NULL;
93111 + }
93112 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93113 + vma_m = vma->vm_mirror;
93114 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93115 + BUG_ON(vma->vm_file != vma_m->vm_file);
93116 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93117 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93118 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93119 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93120 + return vma_m;
93121 +}
93122 +#endif
93123 +
93124 /*
93125 * Verify that the stack growth is acceptable and
93126 * update accounting. This is shared with both the
93127 @@ -2050,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93128 return -ENOMEM;
93129
93130 /* Stack limit test */
93131 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
93132 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93133 return -ENOMEM;
93134
93135 @@ -2060,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93136 locked = mm->locked_vm + grow;
93137 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93138 limit >>= PAGE_SHIFT;
93139 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93140 if (locked > limit && !capable(CAP_IPC_LOCK))
93141 return -ENOMEM;
93142 }
93143 @@ -2089,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93144 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93145 * vma is the last one with address > vma->vm_end. Have to extend vma.
93146 */
93147 +#ifndef CONFIG_IA64
93148 +static
93149 +#endif
93150 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93151 {
93152 int error;
93153 + bool locknext;
93154
93155 if (!(vma->vm_flags & VM_GROWSUP))
93156 return -EFAULT;
93157
93158 + /* Also guard against wrapping around to address 0. */
93159 + if (address < PAGE_ALIGN(address+1))
93160 + address = PAGE_ALIGN(address+1);
93161 + else
93162 + return -ENOMEM;
93163 +
93164 /*
93165 * We must make sure the anon_vma is allocated
93166 * so that the anon_vma locking is not a noop.
93167 */
93168 if (unlikely(anon_vma_prepare(vma)))
93169 return -ENOMEM;
93170 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93171 + if (locknext && anon_vma_prepare(vma->vm_next))
93172 + return -ENOMEM;
93173 vma_lock_anon_vma(vma);
93174 + if (locknext)
93175 + vma_lock_anon_vma(vma->vm_next);
93176
93177 /*
93178 * vma->vm_start/vm_end cannot change under us because the caller
93179 * is required to hold the mmap_sem in read mode. We need the
93180 - * anon_vma lock to serialize against concurrent expand_stacks.
93181 - * Also guard against wrapping around to address 0.
93182 + * anon_vma locks to serialize against concurrent expand_stacks
93183 + * and expand_upwards.
93184 */
93185 - if (address < PAGE_ALIGN(address+4))
93186 - address = PAGE_ALIGN(address+4);
93187 - else {
93188 - vma_unlock_anon_vma(vma);
93189 - return -ENOMEM;
93190 - }
93191 error = 0;
93192
93193 /* Somebody else might have raced and expanded it already */
93194 - if (address > vma->vm_end) {
93195 + 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)
93196 + error = -ENOMEM;
93197 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93198 unsigned long size, grow;
93199
93200 size = address - vma->vm_start;
93201 @@ -2154,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93202 }
93203 }
93204 }
93205 + if (locknext)
93206 + vma_unlock_anon_vma(vma->vm_next);
93207 vma_unlock_anon_vma(vma);
93208 khugepaged_enter_vma_merge(vma);
93209 validate_mm(vma->vm_mm);
93210 @@ -2168,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
93211 unsigned long address)
93212 {
93213 int error;
93214 + bool lockprev = false;
93215 + struct vm_area_struct *prev;
93216
93217 /*
93218 * We must make sure the anon_vma is allocated
93219 @@ -2181,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
93220 if (error)
93221 return error;
93222
93223 + prev = vma->vm_prev;
93224 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93225 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93226 +#endif
93227 + if (lockprev && anon_vma_prepare(prev))
93228 + return -ENOMEM;
93229 + if (lockprev)
93230 + vma_lock_anon_vma(prev);
93231 +
93232 vma_lock_anon_vma(vma);
93233
93234 /*
93235 @@ -2190,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
93236 */
93237
93238 /* Somebody else might have raced and expanded it already */
93239 - if (address < vma->vm_start) {
93240 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93241 + error = -ENOMEM;
93242 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93243 unsigned long size, grow;
93244
93245 +#ifdef CONFIG_PAX_SEGMEXEC
93246 + struct vm_area_struct *vma_m;
93247 +
93248 + vma_m = pax_find_mirror_vma(vma);
93249 +#endif
93250 +
93251 size = vma->vm_end - address;
93252 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93253
93254 @@ -2217,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
93255 vma->vm_pgoff -= grow;
93256 anon_vma_interval_tree_post_update_vma(vma);
93257 vma_gap_update(vma);
93258 +
93259 +#ifdef CONFIG_PAX_SEGMEXEC
93260 + if (vma_m) {
93261 + anon_vma_interval_tree_pre_update_vma(vma_m);
93262 + vma_m->vm_start -= grow << PAGE_SHIFT;
93263 + vma_m->vm_pgoff -= grow;
93264 + anon_vma_interval_tree_post_update_vma(vma_m);
93265 + vma_gap_update(vma_m);
93266 + }
93267 +#endif
93268 +
93269 spin_unlock(&vma->vm_mm->page_table_lock);
93270
93271 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93272 perf_event_mmap(vma);
93273 }
93274 }
93275 }
93276 vma_unlock_anon_vma(vma);
93277 + if (lockprev)
93278 + vma_unlock_anon_vma(prev);
93279 khugepaged_enter_vma_merge(vma);
93280 validate_mm(vma->vm_mm);
93281 return error;
93282 @@ -2321,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93283 do {
93284 long nrpages = vma_pages(vma);
93285
93286 +#ifdef CONFIG_PAX_SEGMEXEC
93287 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93288 + vma = remove_vma(vma);
93289 + continue;
93290 + }
93291 +#endif
93292 +
93293 if (vma->vm_flags & VM_ACCOUNT)
93294 nr_accounted += nrpages;
93295 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93296 @@ -2365,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93297 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93298 vma->vm_prev = NULL;
93299 do {
93300 +
93301 +#ifdef CONFIG_PAX_SEGMEXEC
93302 + if (vma->vm_mirror) {
93303 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93304 + vma->vm_mirror->vm_mirror = NULL;
93305 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
93306 + vma->vm_mirror = NULL;
93307 + }
93308 +#endif
93309 +
93310 vma_rb_erase(vma, &mm->mm_rb);
93311 mm->map_count--;
93312 tail_vma = vma;
93313 @@ -2390,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93314 struct vm_area_struct *new;
93315 int err = -ENOMEM;
93316
93317 +#ifdef CONFIG_PAX_SEGMEXEC
93318 + struct vm_area_struct *vma_m, *new_m = NULL;
93319 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93320 +#endif
93321 +
93322 if (is_vm_hugetlb_page(vma) && (addr &
93323 ~(huge_page_mask(hstate_vma(vma)))))
93324 return -EINVAL;
93325
93326 +#ifdef CONFIG_PAX_SEGMEXEC
93327 + vma_m = pax_find_mirror_vma(vma);
93328 +#endif
93329 +
93330 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93331 if (!new)
93332 goto out_err;
93333
93334 +#ifdef CONFIG_PAX_SEGMEXEC
93335 + if (vma_m) {
93336 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93337 + if (!new_m) {
93338 + kmem_cache_free(vm_area_cachep, new);
93339 + goto out_err;
93340 + }
93341 + }
93342 +#endif
93343 +
93344 /* most fields are the same, copy all, and then fixup */
93345 *new = *vma;
93346
93347 @@ -2410,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93348 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93349 }
93350
93351 +#ifdef CONFIG_PAX_SEGMEXEC
93352 + if (vma_m) {
93353 + *new_m = *vma_m;
93354 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
93355 + new_m->vm_mirror = new;
93356 + new->vm_mirror = new_m;
93357 +
93358 + if (new_below)
93359 + new_m->vm_end = addr_m;
93360 + else {
93361 + new_m->vm_start = addr_m;
93362 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93363 + }
93364 + }
93365 +#endif
93366 +
93367 err = vma_dup_policy(vma, new);
93368 if (err)
93369 goto out_free_vma;
93370 @@ -2429,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93371 else
93372 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93373
93374 +#ifdef CONFIG_PAX_SEGMEXEC
93375 + if (!err && vma_m) {
93376 + struct mempolicy *pol = vma_policy(new);
93377 +
93378 + if (anon_vma_clone(new_m, vma_m))
93379 + goto out_free_mpol;
93380 +
93381 + mpol_get(pol);
93382 + set_vma_policy(new_m, pol);
93383 +
93384 + if (new_m->vm_file)
93385 + get_file(new_m->vm_file);
93386 +
93387 + if (new_m->vm_ops && new_m->vm_ops->open)
93388 + new_m->vm_ops->open(new_m);
93389 +
93390 + if (new_below)
93391 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93392 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93393 + else
93394 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93395 +
93396 + if (err) {
93397 + if (new_m->vm_ops && new_m->vm_ops->close)
93398 + new_m->vm_ops->close(new_m);
93399 + if (new_m->vm_file)
93400 + fput(new_m->vm_file);
93401 + mpol_put(pol);
93402 + }
93403 + }
93404 +#endif
93405 +
93406 /* Success. */
93407 if (!err)
93408 return 0;
93409 @@ -2438,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93410 new->vm_ops->close(new);
93411 if (new->vm_file)
93412 fput(new->vm_file);
93413 - unlink_anon_vmas(new);
93414 out_free_mpol:
93415 mpol_put(vma_policy(new));
93416 out_free_vma:
93417 +
93418 +#ifdef CONFIG_PAX_SEGMEXEC
93419 + if (new_m) {
93420 + unlink_anon_vmas(new_m);
93421 + kmem_cache_free(vm_area_cachep, new_m);
93422 + }
93423 +#endif
93424 +
93425 + unlink_anon_vmas(new);
93426 kmem_cache_free(vm_area_cachep, new);
93427 out_err:
93428 return err;
93429 @@ -2454,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93430 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93431 unsigned long addr, int new_below)
93432 {
93433 +
93434 +#ifdef CONFIG_PAX_SEGMEXEC
93435 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93436 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93437 + if (mm->map_count >= sysctl_max_map_count-1)
93438 + return -ENOMEM;
93439 + } else
93440 +#endif
93441 +
93442 if (mm->map_count >= sysctl_max_map_count)
93443 return -ENOMEM;
93444
93445 @@ -2465,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93446 * work. This now handles partial unmappings.
93447 * Jeremy Fitzhardinge <jeremy@goop.org>
93448 */
93449 +#ifdef CONFIG_PAX_SEGMEXEC
93450 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93451 {
93452 + int ret = __do_munmap(mm, start, len);
93453 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
93454 + return ret;
93455 +
93456 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
93457 +}
93458 +
93459 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93460 +#else
93461 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93462 +#endif
93463 +{
93464 unsigned long end;
93465 struct vm_area_struct *vma, *prev, *last;
93466
93467 + /*
93468 + * mm->mmap_sem is required to protect against another thread
93469 + * changing the mappings in case we sleep.
93470 + */
93471 + verify_mm_writelocked(mm);
93472 +
93473 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
93474 return -EINVAL;
93475
93476 @@ -2544,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93477 /* Fix up all other VM information */
93478 remove_vma_list(mm, vma);
93479
93480 + track_exec_limit(mm, start, end, 0UL);
93481 +
93482 return 0;
93483 }
93484
93485 @@ -2552,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
93486 int ret;
93487 struct mm_struct *mm = current->mm;
93488
93489 +
93490 +#ifdef CONFIG_PAX_SEGMEXEC
93491 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
93492 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
93493 + return -EINVAL;
93494 +#endif
93495 +
93496 down_write(&mm->mmap_sem);
93497 ret = do_munmap(mm, start, len);
93498 up_write(&mm->mmap_sem);
93499 @@ -2565,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
93500 return vm_munmap(addr, len);
93501 }
93502
93503 -static inline void verify_mm_writelocked(struct mm_struct *mm)
93504 -{
93505 -#ifdef CONFIG_DEBUG_VM
93506 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93507 - WARN_ON(1);
93508 - up_read(&mm->mmap_sem);
93509 - }
93510 -#endif
93511 -}
93512 -
93513 /*
93514 * this is really a simplified "do_mmap". it only handles
93515 * anonymous maps. eventually we may be able to do some
93516 @@ -2588,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93517 struct rb_node ** rb_link, * rb_parent;
93518 pgoff_t pgoff = addr >> PAGE_SHIFT;
93519 int error;
93520 + unsigned long charged;
93521
93522 len = PAGE_ALIGN(len);
93523 if (!len)
93524 @@ -2595,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93525
93526 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
93527
93528 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
93529 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
93530 + flags &= ~VM_EXEC;
93531 +
93532 +#ifdef CONFIG_PAX_MPROTECT
93533 + if (mm->pax_flags & MF_PAX_MPROTECT)
93534 + flags &= ~VM_MAYEXEC;
93535 +#endif
93536 +
93537 + }
93538 +#endif
93539 +
93540 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
93541 if (error & ~PAGE_MASK)
93542 return error;
93543
93544 + charged = len >> PAGE_SHIFT;
93545 +
93546 /*
93547 * mlock MCL_FUTURE?
93548 */
93549 if (mm->def_flags & VM_LOCKED) {
93550 unsigned long locked, lock_limit;
93551 - locked = len >> PAGE_SHIFT;
93552 + locked = charged;
93553 locked += mm->locked_vm;
93554 lock_limit = rlimit(RLIMIT_MEMLOCK);
93555 lock_limit >>= PAGE_SHIFT;
93556 @@ -2621,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93557 /*
93558 * Clear old maps. this also does some error checking for us
93559 */
93560 - munmap_back:
93561 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93562 if (do_munmap(mm, addr, len))
93563 return -ENOMEM;
93564 - goto munmap_back;
93565 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93566 }
93567
93568 /* Check against address space limits *after* clearing old maps... */
93569 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
93570 + if (!may_expand_vm(mm, charged))
93571 return -ENOMEM;
93572
93573 if (mm->map_count > sysctl_max_map_count)
93574 return -ENOMEM;
93575
93576 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
93577 + if (security_vm_enough_memory_mm(mm, charged))
93578 return -ENOMEM;
93579
93580 /* Can we just expand an old private anonymous mapping? */
93581 @@ -2649,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93582 */
93583 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93584 if (!vma) {
93585 - vm_unacct_memory(len >> PAGE_SHIFT);
93586 + vm_unacct_memory(charged);
93587 return -ENOMEM;
93588 }
93589
93590 @@ -2663,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93591 vma_link(mm, vma, prev, rb_link, rb_parent);
93592 out:
93593 perf_event_mmap(vma);
93594 - mm->total_vm += len >> PAGE_SHIFT;
93595 + mm->total_vm += charged;
93596 if (flags & VM_LOCKED)
93597 - mm->locked_vm += (len >> PAGE_SHIFT);
93598 + mm->locked_vm += charged;
93599 vma->vm_flags |= VM_SOFTDIRTY;
93600 + track_exec_limit(mm, addr, addr + len, flags);
93601 return addr;
93602 }
93603
93604 @@ -2728,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
93605 while (vma) {
93606 if (vma->vm_flags & VM_ACCOUNT)
93607 nr_accounted += vma_pages(vma);
93608 + vma->vm_mirror = NULL;
93609 vma = remove_vma(vma);
93610 }
93611 vm_unacct_memory(nr_accounted);
93612 @@ -2745,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93613 struct vm_area_struct *prev;
93614 struct rb_node **rb_link, *rb_parent;
93615
93616 +#ifdef CONFIG_PAX_SEGMEXEC
93617 + struct vm_area_struct *vma_m = NULL;
93618 +#endif
93619 +
93620 + if (security_mmap_addr(vma->vm_start))
93621 + return -EPERM;
93622 +
93623 /*
93624 * The vm_pgoff of a purely anonymous vma should be irrelevant
93625 * until its first write fault, when page's anon_vma and index
93626 @@ -2768,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93627 security_vm_enough_memory_mm(mm, vma_pages(vma)))
93628 return -ENOMEM;
93629
93630 +#ifdef CONFIG_PAX_SEGMEXEC
93631 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
93632 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93633 + if (!vma_m)
93634 + return -ENOMEM;
93635 + }
93636 +#endif
93637 +
93638 vma_link(mm, vma, prev, rb_link, rb_parent);
93639 +
93640 +#ifdef CONFIG_PAX_SEGMEXEC
93641 + if (vma_m)
93642 + BUG_ON(pax_mirror_vma(vma_m, vma));
93643 +#endif
93644 +
93645 return 0;
93646 }
93647
93648 @@ -2787,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93649 struct rb_node **rb_link, *rb_parent;
93650 bool faulted_in_anon_vma = true;
93651
93652 + BUG_ON(vma->vm_mirror);
93653 +
93654 /*
93655 * If anonymous vma has not yet been faulted, update new pgoff
93656 * to match new location, to increase its chance of merging.
93657 @@ -2851,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93658 return NULL;
93659 }
93660
93661 +#ifdef CONFIG_PAX_SEGMEXEC
93662 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
93663 +{
93664 + struct vm_area_struct *prev_m;
93665 + struct rb_node **rb_link_m, *rb_parent_m;
93666 + struct mempolicy *pol_m;
93667 +
93668 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
93669 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
93670 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
93671 + *vma_m = *vma;
93672 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
93673 + if (anon_vma_clone(vma_m, vma))
93674 + return -ENOMEM;
93675 + pol_m = vma_policy(vma_m);
93676 + mpol_get(pol_m);
93677 + set_vma_policy(vma_m, pol_m);
93678 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
93679 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
93680 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
93681 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
93682 + if (vma_m->vm_file)
93683 + get_file(vma_m->vm_file);
93684 + if (vma_m->vm_ops && vma_m->vm_ops->open)
93685 + vma_m->vm_ops->open(vma_m);
93686 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
93687 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
93688 + vma_m->vm_mirror = vma;
93689 + vma->vm_mirror = vma_m;
93690 + return 0;
93691 +}
93692 +#endif
93693 +
93694 /*
93695 * Return true if the calling process may expand its vm space by the passed
93696 * number of pages
93697 @@ -2862,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
93698
93699 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
93700
93701 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
93702 if (cur + npages > lim)
93703 return 0;
93704 return 1;
93705 @@ -2932,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
93706 vma->vm_start = addr;
93707 vma->vm_end = addr + len;
93708
93709 +#ifdef CONFIG_PAX_MPROTECT
93710 + if (mm->pax_flags & MF_PAX_MPROTECT) {
93711 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
93712 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
93713 + return -EPERM;
93714 + if (!(vm_flags & VM_EXEC))
93715 + vm_flags &= ~VM_MAYEXEC;
93716 +#else
93717 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93718 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93719 +#endif
93720 + else
93721 + vm_flags &= ~VM_MAYWRITE;
93722 + }
93723 +#endif
93724 +
93725 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
93726 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93727
93728 diff --git a/mm/mprotect.c b/mm/mprotect.c
93729 index bb53a65..249c052 100644
93730 --- a/mm/mprotect.c
93731 +++ b/mm/mprotect.c
93732 @@ -23,10 +23,18 @@
93733 #include <linux/mmu_notifier.h>
93734 #include <linux/migrate.h>
93735 #include <linux/perf_event.h>
93736 +#include <linux/sched/sysctl.h>
93737 +
93738 +#ifdef CONFIG_PAX_MPROTECT
93739 +#include <linux/elf.h>
93740 +#include <linux/binfmts.h>
93741 +#endif
93742 +
93743 #include <asm/uaccess.h>
93744 #include <asm/pgtable.h>
93745 #include <asm/cacheflush.h>
93746 #include <asm/tlbflush.h>
93747 +#include <asm/mmu_context.h>
93748
93749 #ifndef pgprot_modify
93750 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
93751 @@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
93752 return pages;
93753 }
93754
93755 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93756 +/* called while holding the mmap semaphor for writing except stack expansion */
93757 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
93758 +{
93759 + unsigned long oldlimit, newlimit = 0UL;
93760 +
93761 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
93762 + return;
93763 +
93764 + spin_lock(&mm->page_table_lock);
93765 + oldlimit = mm->context.user_cs_limit;
93766 + if ((prot & VM_EXEC) && oldlimit < end)
93767 + /* USER_CS limit moved up */
93768 + newlimit = end;
93769 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
93770 + /* USER_CS limit moved down */
93771 + newlimit = start;
93772 +
93773 + if (newlimit) {
93774 + mm->context.user_cs_limit = newlimit;
93775 +
93776 +#ifdef CONFIG_SMP
93777 + wmb();
93778 + cpus_clear(mm->context.cpu_user_cs_mask);
93779 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
93780 +#endif
93781 +
93782 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
93783 + }
93784 + spin_unlock(&mm->page_table_lock);
93785 + if (newlimit == end) {
93786 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
93787 +
93788 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
93789 + if (is_vm_hugetlb_page(vma))
93790 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
93791 + else
93792 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
93793 + }
93794 +}
93795 +#endif
93796 +
93797 int
93798 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93799 unsigned long start, unsigned long end, unsigned long newflags)
93800 @@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93801 int error;
93802 int dirty_accountable = 0;
93803
93804 +#ifdef CONFIG_PAX_SEGMEXEC
93805 + struct vm_area_struct *vma_m = NULL;
93806 + unsigned long start_m, end_m;
93807 +
93808 + start_m = start + SEGMEXEC_TASK_SIZE;
93809 + end_m = end + SEGMEXEC_TASK_SIZE;
93810 +#endif
93811 +
93812 if (newflags == oldflags) {
93813 *pprev = vma;
93814 return 0;
93815 }
93816
93817 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
93818 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
93819 +
93820 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
93821 + return -ENOMEM;
93822 +
93823 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
93824 + return -ENOMEM;
93825 + }
93826 +
93827 /*
93828 * If we make a private mapping writable we increase our commit;
93829 * but (without finer accounting) cannot reduce our commit if we
93830 @@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93831 }
93832 }
93833
93834 +#ifdef CONFIG_PAX_SEGMEXEC
93835 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
93836 + if (start != vma->vm_start) {
93837 + error = split_vma(mm, vma, start, 1);
93838 + if (error)
93839 + goto fail;
93840 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
93841 + *pprev = (*pprev)->vm_next;
93842 + }
93843 +
93844 + if (end != vma->vm_end) {
93845 + error = split_vma(mm, vma, end, 0);
93846 + if (error)
93847 + goto fail;
93848 + }
93849 +
93850 + if (pax_find_mirror_vma(vma)) {
93851 + error = __do_munmap(mm, start_m, end_m - start_m);
93852 + if (error)
93853 + goto fail;
93854 + } else {
93855 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93856 + if (!vma_m) {
93857 + error = -ENOMEM;
93858 + goto fail;
93859 + }
93860 + vma->vm_flags = newflags;
93861 + error = pax_mirror_vma(vma_m, vma);
93862 + if (error) {
93863 + vma->vm_flags = oldflags;
93864 + goto fail;
93865 + }
93866 + }
93867 + }
93868 +#endif
93869 +
93870 /*
93871 * First try to merge with previous and/or next vma.
93872 */
93873 @@ -285,9 +389,21 @@ success:
93874 * vm_flags and vm_page_prot are protected by the mmap_sem
93875 * held in write mode.
93876 */
93877 +
93878 +#ifdef CONFIG_PAX_SEGMEXEC
93879 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
93880 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
93881 +#endif
93882 +
93883 vma->vm_flags = newflags;
93884 +
93885 +#ifdef CONFIG_PAX_MPROTECT
93886 + if (mm->binfmt && mm->binfmt->handle_mprotect)
93887 + mm->binfmt->handle_mprotect(vma, newflags);
93888 +#endif
93889 +
93890 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
93891 - vm_get_page_prot(newflags));
93892 + vm_get_page_prot(vma->vm_flags));
93893
93894 if (vma_wants_writenotify(vma)) {
93895 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
93896 @@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93897 end = start + len;
93898 if (end <= start)
93899 return -ENOMEM;
93900 +
93901 +#ifdef CONFIG_PAX_SEGMEXEC
93902 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
93903 + if (end > SEGMEXEC_TASK_SIZE)
93904 + return -EINVAL;
93905 + } else
93906 +#endif
93907 +
93908 + if (end > TASK_SIZE)
93909 + return -EINVAL;
93910 +
93911 if (!arch_validate_prot(prot))
93912 return -EINVAL;
93913
93914 @@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93915 /*
93916 * Does the application expect PROT_READ to imply PROT_EXEC:
93917 */
93918 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93919 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93920 prot |= PROT_EXEC;
93921
93922 vm_flags = calc_vm_prot_bits(prot);
93923 @@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93924 if (start > vma->vm_start)
93925 prev = vma;
93926
93927 +#ifdef CONFIG_PAX_MPROTECT
93928 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
93929 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
93930 +#endif
93931 +
93932 for (nstart = start ; ; ) {
93933 unsigned long newflags;
93934
93935 @@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93936
93937 /* newflags >> 4 shift VM_MAY% in place of VM_% */
93938 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
93939 + if (prot & (PROT_WRITE | PROT_EXEC))
93940 + gr_log_rwxmprotect(vma);
93941 +
93942 + error = -EACCES;
93943 + goto out;
93944 + }
93945 +
93946 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
93947 error = -EACCES;
93948 goto out;
93949 }
93950 @@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93951 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
93952 if (error)
93953 goto out;
93954 +
93955 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
93956 +
93957 nstart = tmp;
93958
93959 if (nstart < prev->vm_end)
93960 diff --git a/mm/mremap.c b/mm/mremap.c
93961 index 0843feb..4f5b2e6 100644
93962 --- a/mm/mremap.c
93963 +++ b/mm/mremap.c
93964 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
93965 continue;
93966 pte = ptep_get_and_clear(mm, old_addr, old_pte);
93967 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
93968 +
93969 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93970 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
93971 + pte = pte_exprotect(pte);
93972 +#endif
93973 +
93974 pte = move_soft_dirty_pte(pte);
93975 set_pte_at(mm, new_addr, new_pte, pte);
93976 }
93977 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
93978 if (is_vm_hugetlb_page(vma))
93979 goto Einval;
93980
93981 +#ifdef CONFIG_PAX_SEGMEXEC
93982 + if (pax_find_mirror_vma(vma))
93983 + goto Einval;
93984 +#endif
93985 +
93986 /* We can't remap across vm area boundaries */
93987 if (old_len > vma->vm_end - addr)
93988 goto Efault;
93989 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
93990 unsigned long ret = -EINVAL;
93991 unsigned long charged = 0;
93992 unsigned long map_flags;
93993 + unsigned long pax_task_size = TASK_SIZE;
93994
93995 if (new_addr & ~PAGE_MASK)
93996 goto out;
93997
93998 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
93999 +#ifdef CONFIG_PAX_SEGMEXEC
94000 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94001 + pax_task_size = SEGMEXEC_TASK_SIZE;
94002 +#endif
94003 +
94004 + pax_task_size -= PAGE_SIZE;
94005 +
94006 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94007 goto out;
94008
94009 /* Check if the location we're moving into overlaps the
94010 * old location at all, and fail if it does.
94011 */
94012 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
94013 - goto out;
94014 -
94015 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
94016 + if (addr + old_len > new_addr && new_addr + new_len > addr)
94017 goto out;
94018
94019 ret = do_munmap(mm, new_addr, new_len);
94020 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94021 unsigned long ret = -EINVAL;
94022 unsigned long charged = 0;
94023 bool locked = false;
94024 + unsigned long pax_task_size = TASK_SIZE;
94025
94026 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94027 return ret;
94028 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94029 if (!new_len)
94030 return ret;
94031
94032 +#ifdef CONFIG_PAX_SEGMEXEC
94033 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94034 + pax_task_size = SEGMEXEC_TASK_SIZE;
94035 +#endif
94036 +
94037 + pax_task_size -= PAGE_SIZE;
94038 +
94039 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94040 + old_len > pax_task_size || addr > pax_task_size-old_len)
94041 + return ret;
94042 +
94043 down_write(&current->mm->mmap_sem);
94044
94045 if (flags & MREMAP_FIXED) {
94046 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94047 new_addr = addr;
94048 }
94049 ret = addr;
94050 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94051 goto out;
94052 }
94053 }
94054 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94055 goto out;
94056 }
94057
94058 + map_flags = vma->vm_flags;
94059 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94060 + if (!(ret & ~PAGE_MASK)) {
94061 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94062 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94063 + }
94064 }
94065 out:
94066 if (ret & ~PAGE_MASK)
94067 diff --git a/mm/nommu.c b/mm/nommu.c
94068 index fec093a..8162f74 100644
94069 --- a/mm/nommu.c
94070 +++ b/mm/nommu.c
94071 @@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94072 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94073 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94074 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94075 -int heap_stack_gap = 0;
94076
94077 atomic_long_t mmap_pages_allocated;
94078
94079 @@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94080 EXPORT_SYMBOL(find_vma);
94081
94082 /*
94083 - * find a VMA
94084 - * - we don't extend stack VMAs under NOMMU conditions
94085 - */
94086 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94087 -{
94088 - return find_vma(mm, addr);
94089 -}
94090 -
94091 -/*
94092 * expand a stack to a given address
94093 * - not supported under NOMMU conditions
94094 */
94095 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94096
94097 /* most fields are the same, copy all, and then fixup */
94098 *new = *vma;
94099 + INIT_LIST_HEAD(&new->anon_vma_chain);
94100 *region = *vma->vm_region;
94101 new->vm_region = region;
94102
94103 @@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94104 }
94105 EXPORT_SYMBOL(generic_file_remap_pages);
94106
94107 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94108 - unsigned long addr, void *buf, int len, int write)
94109 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94110 + unsigned long addr, void *buf, size_t len, int write)
94111 {
94112 struct vm_area_struct *vma;
94113
94114 @@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94115 *
94116 * The caller must hold a reference on @mm.
94117 */
94118 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94119 - void *buf, int len, int write)
94120 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94121 + void *buf, size_t len, int write)
94122 {
94123 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94124 }
94125 @@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94126 * Access another process' address space.
94127 * - source/target buffer must be kernel space
94128 */
94129 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94130 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94131 {
94132 struct mm_struct *mm;
94133
94134 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94135 index 7106cb1..0805f48 100644
94136 --- a/mm/page-writeback.c
94137 +++ b/mm/page-writeback.c
94138 @@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94139 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94140 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94141 */
94142 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94143 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94144 unsigned long thresh,
94145 unsigned long bg_thresh,
94146 unsigned long dirty,
94147 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94148 index 5248fe0..0f693aa 100644
94149 --- a/mm/page_alloc.c
94150 +++ b/mm/page_alloc.c
94151 @@ -61,6 +61,7 @@
94152 #include <linux/page-debug-flags.h>
94153 #include <linux/hugetlb.h>
94154 #include <linux/sched/rt.h>
94155 +#include <linux/random.h>
94156
94157 #include <asm/sections.h>
94158 #include <asm/tlbflush.h>
94159 @@ -354,7 +355,7 @@ out:
94160 * This usage means that zero-order pages may not be compound.
94161 */
94162
94163 -static void free_compound_page(struct page *page)
94164 +void free_compound_page(struct page *page)
94165 {
94166 __free_pages_ok(page, compound_order(page));
94167 }
94168 @@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94169 int i;
94170 int bad = 0;
94171
94172 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94173 + unsigned long index = 1UL << order;
94174 +#endif
94175 +
94176 trace_mm_page_free(page, order);
94177 kmemcheck_free_shadow(page, order);
94178
94179 @@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94180 debug_check_no_obj_freed(page_address(page),
94181 PAGE_SIZE << order);
94182 }
94183 +
94184 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94185 + for (; index; --index)
94186 + sanitize_highpage(page + index - 1);
94187 +#endif
94188 +
94189 arch_free_page(page, order);
94190 kernel_map_pages(page, 1 << order, 0);
94191
94192 @@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94193 local_irq_restore(flags);
94194 }
94195
94196 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94197 +bool __meminitdata extra_latent_entropy;
94198 +
94199 +static int __init setup_pax_extra_latent_entropy(char *str)
94200 +{
94201 + extra_latent_entropy = true;
94202 + return 0;
94203 +}
94204 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94205 +
94206 +volatile u64 latent_entropy __latent_entropy;
94207 +EXPORT_SYMBOL(latent_entropy);
94208 +#endif
94209 +
94210 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94211 {
94212 unsigned int nr_pages = 1 << order;
94213 @@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94214 __ClearPageReserved(p);
94215 set_page_count(p, 0);
94216
94217 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94218 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94219 + u64 hash = 0;
94220 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94221 + const u64 *data = lowmem_page_address(page);
94222 +
94223 + for (index = 0; index < end; index++)
94224 + hash ^= hash + data[index];
94225 + latent_entropy ^= hash;
94226 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94227 + }
94228 +#endif
94229 +
94230 page_zone(page)->managed_pages += nr_pages;
94231 set_page_refcounted(page);
94232 __free_pages(page, order);
94233 @@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94234 arch_alloc_page(page, order);
94235 kernel_map_pages(page, 1 << order, 1);
94236
94237 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
94238 if (gfp_flags & __GFP_ZERO)
94239 prep_zero_page(page, order, gfp_flags);
94240 +#endif
94241
94242 if (order && (gfp_flags & __GFP_COMP))
94243 prep_compound_page(page, order);
94244 diff --git a/mm/page_io.c b/mm/page_io.c
94245 index 8c79a47..a689e0d 100644
94246 --- a/mm/page_io.c
94247 +++ b/mm/page_io.c
94248 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94249 struct file *swap_file = sis->swap_file;
94250 struct address_space *mapping = swap_file->f_mapping;
94251 struct iovec iov = {
94252 - .iov_base = kmap(page),
94253 + .iov_base = (void __force_user *)kmap(page),
94254 .iov_len = PAGE_SIZE,
94255 };
94256
94257 diff --git a/mm/percpu.c b/mm/percpu.c
94258 index 0d10def..6dc822d 100644
94259 --- a/mm/percpu.c
94260 +++ b/mm/percpu.c
94261 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94262 static unsigned int pcpu_high_unit_cpu __read_mostly;
94263
94264 /* the address of the first chunk which starts with the kernel static area */
94265 -void *pcpu_base_addr __read_mostly;
94266 +void *pcpu_base_addr __read_only;
94267 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94268
94269 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94270 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94271 index fd26d04..0cea1b0 100644
94272 --- a/mm/process_vm_access.c
94273 +++ b/mm/process_vm_access.c
94274 @@ -13,6 +13,7 @@
94275 #include <linux/uio.h>
94276 #include <linux/sched.h>
94277 #include <linux/highmem.h>
94278 +#include <linux/security.h>
94279 #include <linux/ptrace.h>
94280 #include <linux/slab.h>
94281 #include <linux/syscalls.h>
94282 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94283 size_t iov_l_curr_offset = 0;
94284 ssize_t iov_len;
94285
94286 + return -ENOSYS; // PaX: until properly audited
94287 +
94288 /*
94289 * Work out how many pages of struct pages we're going to need
94290 * when eventually calling get_user_pages
94291 */
94292 for (i = 0; i < riovcnt; i++) {
94293 iov_len = rvec[i].iov_len;
94294 - if (iov_len > 0) {
94295 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
94296 - + iov_len)
94297 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94298 - / PAGE_SIZE + 1;
94299 - nr_pages = max(nr_pages, nr_pages_iov);
94300 - }
94301 + if (iov_len <= 0)
94302 + continue;
94303 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94304 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94305 + nr_pages = max(nr_pages, nr_pages_iov);
94306 }
94307
94308 if (nr_pages == 0)
94309 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94310 goto free_proc_pages;
94311 }
94312
94313 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94314 + rc = -EPERM;
94315 + goto put_task_struct;
94316 + }
94317 +
94318 mm = mm_access(task, PTRACE_MODE_ATTACH);
94319 if (!mm || IS_ERR(mm)) {
94320 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94321 diff --git a/mm/rmap.c b/mm/rmap.c
94322 index 068522d..f539f21 100644
94323 --- a/mm/rmap.c
94324 +++ b/mm/rmap.c
94325 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94326 struct anon_vma *anon_vma = vma->anon_vma;
94327 struct anon_vma_chain *avc;
94328
94329 +#ifdef CONFIG_PAX_SEGMEXEC
94330 + struct anon_vma_chain *avc_m = NULL;
94331 +#endif
94332 +
94333 might_sleep();
94334 if (unlikely(!anon_vma)) {
94335 struct mm_struct *mm = vma->vm_mm;
94336 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94337 if (!avc)
94338 goto out_enomem;
94339
94340 +#ifdef CONFIG_PAX_SEGMEXEC
94341 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94342 + if (!avc_m)
94343 + goto out_enomem_free_avc;
94344 +#endif
94345 +
94346 anon_vma = find_mergeable_anon_vma(vma);
94347 allocated = NULL;
94348 if (!anon_vma) {
94349 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94350 /* page_table_lock to protect against threads */
94351 spin_lock(&mm->page_table_lock);
94352 if (likely(!vma->anon_vma)) {
94353 +
94354 +#ifdef CONFIG_PAX_SEGMEXEC
94355 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94356 +
94357 + if (vma_m) {
94358 + BUG_ON(vma_m->anon_vma);
94359 + vma_m->anon_vma = anon_vma;
94360 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
94361 + avc_m = NULL;
94362 + }
94363 +#endif
94364 +
94365 vma->anon_vma = anon_vma;
94366 anon_vma_chain_link(vma, avc, anon_vma);
94367 allocated = NULL;
94368 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94369
94370 if (unlikely(allocated))
94371 put_anon_vma(allocated);
94372 +
94373 +#ifdef CONFIG_PAX_SEGMEXEC
94374 + if (unlikely(avc_m))
94375 + anon_vma_chain_free(avc_m);
94376 +#endif
94377 +
94378 if (unlikely(avc))
94379 anon_vma_chain_free(avc);
94380 }
94381 return 0;
94382
94383 out_enomem_free_avc:
94384 +
94385 +#ifdef CONFIG_PAX_SEGMEXEC
94386 + if (avc_m)
94387 + anon_vma_chain_free(avc_m);
94388 +#endif
94389 +
94390 anon_vma_chain_free(avc);
94391 out_enomem:
94392 return -ENOMEM;
94393 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94394 * Attach the anon_vmas from src to dst.
94395 * Returns 0 on success, -ENOMEM on failure.
94396 */
94397 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94398 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94399 {
94400 struct anon_vma_chain *avc, *pavc;
94401 struct anon_vma *root = NULL;
94402 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94403 * the corresponding VMA in the parent process is attached to.
94404 * Returns 0 on success, non-zero on failure.
94405 */
94406 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94407 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94408 {
94409 struct anon_vma_chain *avc;
94410 struct anon_vma *anon_vma;
94411 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94412 void __init anon_vma_init(void)
94413 {
94414 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94415 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94416 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94417 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94418 + anon_vma_ctor);
94419 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94420 + SLAB_PANIC|SLAB_NO_SANITIZE);
94421 }
94422
94423 /*
94424 diff --git a/mm/shmem.c b/mm/shmem.c
94425 index 902a148..58f9d59 100644
94426 --- a/mm/shmem.c
94427 +++ b/mm/shmem.c
94428 @@ -33,7 +33,7 @@
94429 #include <linux/swap.h>
94430 #include <linux/aio.h>
94431
94432 -static struct vfsmount *shm_mnt;
94433 +struct vfsmount *shm_mnt;
94434
94435 #ifdef CONFIG_SHMEM
94436 /*
94437 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94438 #define BOGO_DIRENT_SIZE 20
94439
94440 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94441 -#define SHORT_SYMLINK_LEN 128
94442 +#define SHORT_SYMLINK_LEN 64
94443
94444 /*
94445 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94446 @@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94447 static int shmem_xattr_validate(const char *name)
94448 {
94449 struct { const char *prefix; size_t len; } arr[] = {
94450 +
94451 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94452 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
94453 +#endif
94454 +
94455 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
94456 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
94457 };
94458 @@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
94459 if (err)
94460 return err;
94461
94462 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94463 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
94464 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
94465 + return -EOPNOTSUPP;
94466 + if (size > 8)
94467 + return -EINVAL;
94468 + }
94469 +#endif
94470 +
94471 return simple_xattr_set(&info->xattrs, name, value, size, flags);
94472 }
94473
94474 @@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
94475 int err = -ENOMEM;
94476
94477 /* Round up to L1_CACHE_BYTES to resist false sharing */
94478 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
94479 - L1_CACHE_BYTES), GFP_KERNEL);
94480 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
94481 if (!sbinfo)
94482 return -ENOMEM;
94483
94484 diff --git a/mm/slab.c b/mm/slab.c
94485 index eb043bf..d82f5a8 100644
94486 --- a/mm/slab.c
94487 +++ b/mm/slab.c
94488 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94489 if ((x)->max_freeable < i) \
94490 (x)->max_freeable = i; \
94491 } while (0)
94492 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
94493 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
94494 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
94495 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
94496 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
94497 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
94498 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
94499 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
94500 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
94501 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
94502 #else
94503 #define STATS_INC_ACTIVE(x) do { } while (0)
94504 #define STATS_DEC_ACTIVE(x) do { } while (0)
94505 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94506 #define STATS_INC_ALLOCMISS(x) do { } while (0)
94507 #define STATS_INC_FREEHIT(x) do { } while (0)
94508 #define STATS_INC_FREEMISS(x) do { } while (0)
94509 +#define STATS_INC_SANITIZED(x) do { } while (0)
94510 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
94511 #endif
94512
94513 #if DEBUG
94514 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
94515 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
94516 */
94517 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
94518 - const struct page *page, void *obj)
94519 + const struct page *page, const void *obj)
94520 {
94521 u32 offset = (obj - page->s_mem);
94522 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
94523 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
94524 */
94525
94526 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
94527 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
94528 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94529
94530 if (INDEX_AC != INDEX_NODE)
94531 kmalloc_caches[INDEX_NODE] =
94532 create_kmalloc_cache("kmalloc-node",
94533 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
94534 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94535
94536 slab_early_init = 0;
94537
94538 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
94539 struct array_cache *ac = cpu_cache_get(cachep);
94540
94541 check_irq_off();
94542 +
94543 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94544 + if (pax_sanitize_slab) {
94545 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
94546 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
94547 +
94548 + if (cachep->ctor)
94549 + cachep->ctor(objp);
94550 +
94551 + STATS_INC_SANITIZED(cachep);
94552 + } else
94553 + STATS_INC_NOT_SANITIZED(cachep);
94554 + }
94555 +#endif
94556 +
94557 kmemleak_free_recursive(objp, cachep->flags);
94558 objp = cache_free_debugcheck(cachep, objp, caller);
94559
94560 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
94561
94562 if (unlikely(ZERO_OR_NULL_PTR(objp)))
94563 return;
94564 + VM_BUG_ON(!virt_addr_valid(objp));
94565 local_irq_save(flags);
94566 kfree_debugcheck(objp);
94567 c = virt_to_cache(objp);
94568 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
94569 }
94570 /* cpu stats */
94571 {
94572 - unsigned long allochit = atomic_read(&cachep->allochit);
94573 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
94574 - unsigned long freehit = atomic_read(&cachep->freehit);
94575 - unsigned long freemiss = atomic_read(&cachep->freemiss);
94576 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
94577 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
94578 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
94579 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
94580
94581 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
94582 allochit, allocmiss, freehit, freemiss);
94583 }
94584 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94585 + {
94586 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
94587 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
94588 +
94589 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
94590 + }
94591 +#endif
94592 #endif
94593 }
94594
94595 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
94596 static int __init slab_proc_init(void)
94597 {
94598 #ifdef CONFIG_DEBUG_SLAB_LEAK
94599 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
94600 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
94601 #endif
94602 return 0;
94603 }
94604 module_init(slab_proc_init);
94605 #endif
94606
94607 +bool is_usercopy_object(const void *ptr)
94608 +{
94609 + struct page *page;
94610 + struct kmem_cache *cachep;
94611 +
94612 + if (ZERO_OR_NULL_PTR(ptr))
94613 + return false;
94614 +
94615 + if (!slab_is_available())
94616 + return false;
94617 +
94618 + if (!virt_addr_valid(ptr))
94619 + return false;
94620 +
94621 + page = virt_to_head_page(ptr);
94622 +
94623 + if (!PageSlab(page))
94624 + return false;
94625 +
94626 + cachep = page->slab_cache;
94627 + return cachep->flags & SLAB_USERCOPY;
94628 +}
94629 +
94630 +#ifdef CONFIG_PAX_USERCOPY
94631 +const char *check_heap_object(const void *ptr, unsigned long n)
94632 +{
94633 + struct page *page;
94634 + struct kmem_cache *cachep;
94635 + unsigned int objnr;
94636 + unsigned long offset;
94637 +
94638 + if (ZERO_OR_NULL_PTR(ptr))
94639 + return "<null>";
94640 +
94641 + if (!virt_addr_valid(ptr))
94642 + return NULL;
94643 +
94644 + page = virt_to_head_page(ptr);
94645 +
94646 + if (!PageSlab(page))
94647 + return NULL;
94648 +
94649 + cachep = page->slab_cache;
94650 + if (!(cachep->flags & SLAB_USERCOPY))
94651 + return cachep->name;
94652 +
94653 + objnr = obj_to_index(cachep, page, ptr);
94654 + BUG_ON(objnr >= cachep->num);
94655 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
94656 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
94657 + return NULL;
94658 +
94659 + return cachep->name;
94660 +}
94661 +#endif
94662 +
94663 /**
94664 * ksize - get the actual amount of memory allocated for a given object
94665 * @objp: Pointer to the object
94666 diff --git a/mm/slab.h b/mm/slab.h
94667 index 0859c42..2f7b737 100644
94668 --- a/mm/slab.h
94669 +++ b/mm/slab.h
94670 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
94671 /* The slab cache that manages slab cache information */
94672 extern struct kmem_cache *kmem_cache;
94673
94674 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94675 +#ifdef CONFIG_X86_64
94676 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
94677 +#else
94678 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
94679 +#endif
94680 +extern bool pax_sanitize_slab;
94681 +#endif
94682 +
94683 unsigned long calculate_alignment(unsigned long flags,
94684 unsigned long align, unsigned long size);
94685
94686 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94687
94688 /* Legal flag mask for kmem_cache_create(), for various configurations */
94689 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
94690 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
94691 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
94692 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
94693
94694 #if defined(CONFIG_DEBUG_SLAB)
94695 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
94696 @@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
94697 return s;
94698
94699 page = virt_to_head_page(x);
94700 +
94701 + BUG_ON(!PageSlab(page));
94702 +
94703 cachep = page->slab_cache;
94704 if (slab_equal_or_root(cachep, s))
94705 return cachep;
94706 diff --git a/mm/slab_common.c b/mm/slab_common.c
94707 index 0b7bb39..334c328 100644
94708 --- a/mm/slab_common.c
94709 +++ b/mm/slab_common.c
94710 @@ -23,11 +23,22 @@
94711
94712 #include "slab.h"
94713
94714 -enum slab_state slab_state;
94715 +enum slab_state slab_state __read_only;
94716 LIST_HEAD(slab_caches);
94717 DEFINE_MUTEX(slab_mutex);
94718 struct kmem_cache *kmem_cache;
94719
94720 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94721 +bool pax_sanitize_slab __read_only = true;
94722 +static int __init pax_sanitize_slab_setup(char *str)
94723 +{
94724 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
94725 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
94726 + return 1;
94727 +}
94728 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
94729 +#endif
94730 +
94731 #ifdef CONFIG_DEBUG_VM
94732 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
94733 size_t size)
94734 @@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
94735
94736 err = __kmem_cache_create(s, flags);
94737 if (!err) {
94738 - s->refcount = 1;
94739 + atomic_set(&s->refcount, 1);
94740 list_add(&s->list, &slab_caches);
94741 memcg_cache_list_add(memcg, s);
94742 } else {
94743 @@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
94744
94745 get_online_cpus();
94746 mutex_lock(&slab_mutex);
94747 - s->refcount--;
94748 - if (!s->refcount) {
94749 + if (atomic_dec_and_test(&s->refcount)) {
94750 list_del(&s->list);
94751
94752 if (!__kmem_cache_shutdown(s)) {
94753 @@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
94754 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
94755 name, size, err);
94756
94757 - s->refcount = -1; /* Exempt from merging for now */
94758 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
94759 }
94760
94761 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94762 @@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94763
94764 create_boot_cache(s, name, size, flags);
94765 list_add(&s->list, &slab_caches);
94766 - s->refcount = 1;
94767 + atomic_set(&s->refcount, 1);
94768 return s;
94769 }
94770
94771 @@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
94772 EXPORT_SYMBOL(kmalloc_dma_caches);
94773 #endif
94774
94775 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94776 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
94777 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
94778 +#endif
94779 +
94780 /*
94781 * Conversion table for small slabs sizes / 8 to the index in the
94782 * kmalloc array. This is necessary for slabs < 192 since we have non power
94783 @@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
94784 return kmalloc_dma_caches[index];
94785
94786 #endif
94787 +
94788 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94789 + if (unlikely((flags & GFP_USERCOPY)))
94790 + return kmalloc_usercopy_caches[index];
94791 +
94792 +#endif
94793 +
94794 return kmalloc_caches[index];
94795 }
94796
94797 @@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
94798 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
94799 if (!kmalloc_caches[i]) {
94800 kmalloc_caches[i] = create_kmalloc_cache(NULL,
94801 - 1 << i, flags);
94802 + 1 << i, SLAB_USERCOPY | flags);
94803 }
94804
94805 /*
94806 @@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
94807 * earlier power of two caches
94808 */
94809 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
94810 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
94811 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
94812
94813 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
94814 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
94815 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
94816 }
94817
94818 /* Kmalloc array is now usable */
94819 @@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
94820 }
94821 }
94822 #endif
94823 +
94824 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94825 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
94826 + struct kmem_cache *s = kmalloc_caches[i];
94827 +
94828 + if (s) {
94829 + int size = kmalloc_size(i);
94830 + char *n = kasprintf(GFP_NOWAIT,
94831 + "usercopy-kmalloc-%d", size);
94832 +
94833 + BUG_ON(!n);
94834 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
94835 + size, SLAB_USERCOPY | flags);
94836 + }
94837 + }
94838 +#endif
94839 +
94840 }
94841 #endif /* !CONFIG_SLOB */
94842
94843 @@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
94844 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
94845 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
94846 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
94847 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94848 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
94849 +#endif
94850 #endif
94851 seq_putc(m, '\n');
94852 }
94853 diff --git a/mm/slob.c b/mm/slob.c
94854 index 4bf8809..98a6914 100644
94855 --- a/mm/slob.c
94856 +++ b/mm/slob.c
94857 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
94858 /*
94859 * Return the size of a slob block.
94860 */
94861 -static slobidx_t slob_units(slob_t *s)
94862 +static slobidx_t slob_units(const slob_t *s)
94863 {
94864 if (s->units > 0)
94865 return s->units;
94866 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
94867 /*
94868 * Return the next free slob block pointer after this one.
94869 */
94870 -static slob_t *slob_next(slob_t *s)
94871 +static slob_t *slob_next(const slob_t *s)
94872 {
94873 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
94874 slobidx_t next;
94875 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
94876 /*
94877 * Returns true if s is the last free block in its page.
94878 */
94879 -static int slob_last(slob_t *s)
94880 +static int slob_last(const slob_t *s)
94881 {
94882 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
94883 }
94884
94885 -static void *slob_new_pages(gfp_t gfp, int order, int node)
94886 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
94887 {
94888 - void *page;
94889 + struct page *page;
94890
94891 #ifdef CONFIG_NUMA
94892 if (node != NUMA_NO_NODE)
94893 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
94894 if (!page)
94895 return NULL;
94896
94897 - return page_address(page);
94898 + __SetPageSlab(page);
94899 + return page;
94900 }
94901
94902 -static void slob_free_pages(void *b, int order)
94903 +static void slob_free_pages(struct page *sp, int order)
94904 {
94905 if (current->reclaim_state)
94906 current->reclaim_state->reclaimed_slab += 1 << order;
94907 - free_pages((unsigned long)b, order);
94908 + __ClearPageSlab(sp);
94909 + page_mapcount_reset(sp);
94910 + sp->private = 0;
94911 + __free_pages(sp, order);
94912 }
94913
94914 /*
94915 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
94916
94917 /* Not enough space: must allocate a new page */
94918 if (!b) {
94919 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
94920 - if (!b)
94921 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
94922 + if (!sp)
94923 return NULL;
94924 - sp = virt_to_page(b);
94925 - __SetPageSlab(sp);
94926 + b = page_address(sp);
94927
94928 spin_lock_irqsave(&slob_lock, flags);
94929 sp->units = SLOB_UNITS(PAGE_SIZE);
94930 sp->freelist = b;
94931 + sp->private = 0;
94932 INIT_LIST_HEAD(&sp->list);
94933 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
94934 set_slob_page_free(sp, slob_list);
94935 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
94936 if (slob_page_free(sp))
94937 clear_slob_page_free(sp);
94938 spin_unlock_irqrestore(&slob_lock, flags);
94939 - __ClearPageSlab(sp);
94940 - page_mapcount_reset(sp);
94941 - slob_free_pages(b, 0);
94942 + slob_free_pages(sp, 0);
94943 return;
94944 }
94945
94946 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94947 + if (pax_sanitize_slab)
94948 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
94949 +#endif
94950 +
94951 if (!slob_page_free(sp)) {
94952 /* This slob page is about to become partially free. Easy! */
94953 sp->units = units;
94954 @@ -424,11 +431,10 @@ out:
94955 */
94956
94957 static __always_inline void *
94958 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94959 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
94960 {
94961 - unsigned int *m;
94962 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94963 - void *ret;
94964 + slob_t *m;
94965 + void *ret = NULL;
94966
94967 gfp &= gfp_allowed_mask;
94968
94969 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94970
94971 if (!m)
94972 return NULL;
94973 - *m = size;
94974 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
94975 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
94976 + m[0].units = size;
94977 + m[1].units = align;
94978 ret = (void *)m + align;
94979
94980 trace_kmalloc_node(caller, ret,
94981 size, size + align, gfp, node);
94982 } else {
94983 unsigned int order = get_order(size);
94984 + struct page *page;
94985
94986 if (likely(order))
94987 gfp |= __GFP_COMP;
94988 - ret = slob_new_pages(gfp, order, node);
94989 + page = slob_new_pages(gfp, order, node);
94990 + if (page) {
94991 + ret = page_address(page);
94992 + page->private = size;
94993 + }
94994
94995 trace_kmalloc_node(caller, ret,
94996 size, PAGE_SIZE << order, gfp, node);
94997 }
94998
94999 - kmemleak_alloc(ret, size, 1, gfp);
95000 + return ret;
95001 +}
95002 +
95003 +static __always_inline void *
95004 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95005 +{
95006 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95007 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95008 +
95009 + if (!ZERO_OR_NULL_PTR(ret))
95010 + kmemleak_alloc(ret, size, 1, gfp);
95011 return ret;
95012 }
95013
95014 @@ -493,34 +517,112 @@ void kfree(const void *block)
95015 return;
95016 kmemleak_free(block);
95017
95018 + VM_BUG_ON(!virt_addr_valid(block));
95019 sp = virt_to_page(block);
95020 - if (PageSlab(sp)) {
95021 + VM_BUG_ON(!PageSlab(sp));
95022 + if (!sp->private) {
95023 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95024 - unsigned int *m = (unsigned int *)(block - align);
95025 - slob_free(m, *m + align);
95026 - } else
95027 + slob_t *m = (slob_t *)(block - align);
95028 + slob_free(m, m[0].units + align);
95029 + } else {
95030 + __ClearPageSlab(sp);
95031 + page_mapcount_reset(sp);
95032 + sp->private = 0;
95033 __free_pages(sp, compound_order(sp));
95034 + }
95035 }
95036 EXPORT_SYMBOL(kfree);
95037
95038 +bool is_usercopy_object(const void *ptr)
95039 +{
95040 + if (!slab_is_available())
95041 + return false;
95042 +
95043 + // PAX: TODO
95044 +
95045 + return false;
95046 +}
95047 +
95048 +#ifdef CONFIG_PAX_USERCOPY
95049 +const char *check_heap_object(const void *ptr, unsigned long n)
95050 +{
95051 + struct page *page;
95052 + const slob_t *free;
95053 + const void *base;
95054 + unsigned long flags;
95055 +
95056 + if (ZERO_OR_NULL_PTR(ptr))
95057 + return "<null>";
95058 +
95059 + if (!virt_addr_valid(ptr))
95060 + return NULL;
95061 +
95062 + page = virt_to_head_page(ptr);
95063 + if (!PageSlab(page))
95064 + return NULL;
95065 +
95066 + if (page->private) {
95067 + base = page;
95068 + if (base <= ptr && n <= page->private - (ptr - base))
95069 + return NULL;
95070 + return "<slob>";
95071 + }
95072 +
95073 + /* some tricky double walking to find the chunk */
95074 + spin_lock_irqsave(&slob_lock, flags);
95075 + base = (void *)((unsigned long)ptr & PAGE_MASK);
95076 + free = page->freelist;
95077 +
95078 + while (!slob_last(free) && (void *)free <= ptr) {
95079 + base = free + slob_units(free);
95080 + free = slob_next(free);
95081 + }
95082 +
95083 + while (base < (void *)free) {
95084 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95085 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
95086 + int offset;
95087 +
95088 + if (ptr < base + align)
95089 + break;
95090 +
95091 + offset = ptr - base - align;
95092 + if (offset >= m) {
95093 + base += size;
95094 + continue;
95095 + }
95096 +
95097 + if (n > m - offset)
95098 + break;
95099 +
95100 + spin_unlock_irqrestore(&slob_lock, flags);
95101 + return NULL;
95102 + }
95103 +
95104 + spin_unlock_irqrestore(&slob_lock, flags);
95105 + return "<slob>";
95106 +}
95107 +#endif
95108 +
95109 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95110 size_t ksize(const void *block)
95111 {
95112 struct page *sp;
95113 int align;
95114 - unsigned int *m;
95115 + slob_t *m;
95116
95117 BUG_ON(!block);
95118 if (unlikely(block == ZERO_SIZE_PTR))
95119 return 0;
95120
95121 sp = virt_to_page(block);
95122 - if (unlikely(!PageSlab(sp)))
95123 - return PAGE_SIZE << compound_order(sp);
95124 + VM_BUG_ON(!PageSlab(sp));
95125 + if (sp->private)
95126 + return sp->private;
95127
95128 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95129 - m = (unsigned int *)(block - align);
95130 - return SLOB_UNITS(*m) * SLOB_UNIT;
95131 + m = (slob_t *)(block - align);
95132 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95133 }
95134 EXPORT_SYMBOL(ksize);
95135
95136 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95137
95138 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95139 {
95140 - void *b;
95141 + void *b = NULL;
95142
95143 flags &= gfp_allowed_mask;
95144
95145 lockdep_trace_alloc(flags);
95146
95147 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95148 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95149 +#else
95150 if (c->size < PAGE_SIZE) {
95151 b = slob_alloc(c->size, flags, c->align, node);
95152 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95153 SLOB_UNITS(c->size) * SLOB_UNIT,
95154 flags, node);
95155 } else {
95156 - b = slob_new_pages(flags, get_order(c->size), node);
95157 + struct page *sp;
95158 +
95159 + sp = slob_new_pages(flags, get_order(c->size), node);
95160 + if (sp) {
95161 + b = page_address(sp);
95162 + sp->private = c->size;
95163 + }
95164 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95165 PAGE_SIZE << get_order(c->size),
95166 flags, node);
95167 }
95168 +#endif
95169
95170 if (b && c->ctor)
95171 c->ctor(b);
95172 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95173
95174 static void __kmem_cache_free(void *b, int size)
95175 {
95176 - if (size < PAGE_SIZE)
95177 + struct page *sp;
95178 +
95179 + sp = virt_to_page(b);
95180 + BUG_ON(!PageSlab(sp));
95181 + if (!sp->private)
95182 slob_free(b, size);
95183 else
95184 - slob_free_pages(b, get_order(size));
95185 + slob_free_pages(sp, get_order(size));
95186 }
95187
95188 static void kmem_rcu_free(struct rcu_head *head)
95189 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95190
95191 void kmem_cache_free(struct kmem_cache *c, void *b)
95192 {
95193 + int size = c->size;
95194 +
95195 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95196 + if (size + c->align < PAGE_SIZE) {
95197 + size += c->align;
95198 + b -= c->align;
95199 + }
95200 +#endif
95201 +
95202 kmemleak_free_recursive(b, c->flags);
95203 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95204 struct slob_rcu *slob_rcu;
95205 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95206 - slob_rcu->size = c->size;
95207 + slob_rcu = b + (size - sizeof(struct slob_rcu));
95208 + slob_rcu->size = size;
95209 call_rcu(&slob_rcu->head, kmem_rcu_free);
95210 } else {
95211 - __kmem_cache_free(b, c->size);
95212 + __kmem_cache_free(b, size);
95213 }
95214
95215 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95216 + trace_kfree(_RET_IP_, b);
95217 +#else
95218 trace_kmem_cache_free(_RET_IP_, b);
95219 +#endif
95220 +
95221 }
95222 EXPORT_SYMBOL(kmem_cache_free);
95223
95224 diff --git a/mm/slub.c b/mm/slub.c
95225 index 89490d9..c7b226a 100644
95226 --- a/mm/slub.c
95227 +++ b/mm/slub.c
95228 @@ -207,7 +207,7 @@ struct track {
95229
95230 enum track_item { TRACK_ALLOC, TRACK_FREE };
95231
95232 -#ifdef CONFIG_SYSFS
95233 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95234 static int sysfs_slab_add(struct kmem_cache *);
95235 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95236 static void sysfs_slab_remove(struct kmem_cache *);
95237 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
95238 if (!t->addr)
95239 return;
95240
95241 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95242 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95243 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95244 #ifdef CONFIG_STACKTRACE
95245 {
95246 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95247
95248 slab_free_hook(s, x);
95249
95250 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95251 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95252 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95253 + if (s->ctor)
95254 + s->ctor(x);
95255 + }
95256 +#endif
95257 +
95258 redo:
95259 /*
95260 * Determine the currently cpus per cpu slab.
95261 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
95262 * Merge control. If this is set then no merging of slab caches will occur.
95263 * (Could be removed. This was introduced to pacify the merge skeptics.)
95264 */
95265 -static int slub_nomerge;
95266 +static int slub_nomerge = 1;
95267
95268 /*
95269 * Calculate the order of allocation given an slab object size.
95270 @@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95271 s->inuse = size;
95272
95273 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95274 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95275 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95276 +#endif
95277 s->ctor)) {
95278 /*
95279 * Relocate free pointer after the object if it is not
95280 @@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95281 EXPORT_SYMBOL(__kmalloc_node);
95282 #endif
95283
95284 +bool is_usercopy_object(const void *ptr)
95285 +{
95286 + struct page *page;
95287 + struct kmem_cache *s;
95288 +
95289 + if (ZERO_OR_NULL_PTR(ptr))
95290 + return false;
95291 +
95292 + if (!slab_is_available())
95293 + return false;
95294 +
95295 + if (!virt_addr_valid(ptr))
95296 + return false;
95297 +
95298 + page = virt_to_head_page(ptr);
95299 +
95300 + if (!PageSlab(page))
95301 + return false;
95302 +
95303 + s = page->slab_cache;
95304 + return s->flags & SLAB_USERCOPY;
95305 +}
95306 +
95307 +#ifdef CONFIG_PAX_USERCOPY
95308 +const char *check_heap_object(const void *ptr, unsigned long n)
95309 +{
95310 + struct page *page;
95311 + struct kmem_cache *s;
95312 + unsigned long offset;
95313 +
95314 + if (ZERO_OR_NULL_PTR(ptr))
95315 + return "<null>";
95316 +
95317 + if (!virt_addr_valid(ptr))
95318 + return NULL;
95319 +
95320 + page = virt_to_head_page(ptr);
95321 +
95322 + if (!PageSlab(page))
95323 + return NULL;
95324 +
95325 + s = page->slab_cache;
95326 + if (!(s->flags & SLAB_USERCOPY))
95327 + return s->name;
95328 +
95329 + offset = (ptr - page_address(page)) % s->size;
95330 + if (offset <= s->object_size && n <= s->object_size - offset)
95331 + return NULL;
95332 +
95333 + return s->name;
95334 +}
95335 +#endif
95336 +
95337 size_t ksize(const void *object)
95338 {
95339 struct page *page;
95340 @@ -3360,6 +3424,7 @@ void kfree(const void *x)
95341 if (unlikely(ZERO_OR_NULL_PTR(x)))
95342 return;
95343
95344 + VM_BUG_ON(!virt_addr_valid(x));
95345 page = virt_to_head_page(x);
95346 if (unlikely(!PageSlab(page))) {
95347 BUG_ON(!PageCompound(page));
95348 @@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95349 /*
95350 * We may have set a slab to be unmergeable during bootstrap.
95351 */
95352 - if (s->refcount < 0)
95353 + if (atomic_read(&s->refcount) < 0)
95354 return 1;
95355
95356 return 0;
95357 @@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95358
95359 s = find_mergeable(memcg, size, align, flags, name, ctor);
95360 if (s) {
95361 - s->refcount++;
95362 + atomic_inc(&s->refcount);
95363 /*
95364 * Adjust the object sizes so that we clear
95365 * the complete object on kzalloc.
95366 @@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95367 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95368
95369 if (sysfs_slab_alias(s, name)) {
95370 - s->refcount--;
95371 + atomic_dec(&s->refcount);
95372 s = NULL;
95373 }
95374 }
95375 @@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95376 }
95377 #endif
95378
95379 -#ifdef CONFIG_SYSFS
95380 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95381 static int count_inuse(struct page *page)
95382 {
95383 return page->inuse;
95384 @@ -4241,12 +4306,12 @@ static void resiliency_test(void)
95385 validate_slab_cache(kmalloc_caches[9]);
95386 }
95387 #else
95388 -#ifdef CONFIG_SYSFS
95389 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95390 static void resiliency_test(void) {};
95391 #endif
95392 #endif
95393
95394 -#ifdef CONFIG_SYSFS
95395 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95396 enum slab_stat_type {
95397 SL_ALL, /* All slabs */
95398 SL_PARTIAL, /* Only partially allocated slabs */
95399 @@ -4492,7 +4557,7 @@ SLAB_ATTR_RO(ctor);
95400
95401 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95402 {
95403 - return sprintf(buf, "%d\n", s->refcount - 1);
95404 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95405 }
95406 SLAB_ATTR_RO(aliases);
95407
95408 @@ -4580,6 +4645,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95409 SLAB_ATTR_RO(cache_dma);
95410 #endif
95411
95412 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95413 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95414 +{
95415 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95416 +}
95417 +SLAB_ATTR_RO(usercopy);
95418 +#endif
95419 +
95420 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95421 {
95422 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95423 @@ -4914,6 +4987,9 @@ static struct attribute *slab_attrs[] = {
95424 #ifdef CONFIG_ZONE_DMA
95425 &cache_dma_attr.attr,
95426 #endif
95427 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95428 + &usercopy_attr.attr,
95429 +#endif
95430 #ifdef CONFIG_NUMA
95431 &remote_node_defrag_ratio_attr.attr,
95432 #endif
95433 @@ -5146,6 +5222,7 @@ static char *create_unique_id(struct kmem_cache *s)
95434 return name;
95435 }
95436
95437 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95438 static int sysfs_slab_add(struct kmem_cache *s)
95439 {
95440 int err;
95441 @@ -5169,7 +5246,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
95442 }
95443
95444 s->kobj.kset = slab_kset;
95445 - err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
95446 + err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
95447 if (err) {
95448 kobject_put(&s->kobj);
95449 return err;
95450 @@ -5203,6 +5280,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95451 kobject_del(&s->kobj);
95452 kobject_put(&s->kobj);
95453 }
95454 +#endif
95455
95456 /*
95457 * Need to buffer aliases during bootup until sysfs becomes
95458 @@ -5216,6 +5294,7 @@ struct saved_alias {
95459
95460 static struct saved_alias *alias_list;
95461
95462 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95463 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95464 {
95465 struct saved_alias *al;
95466 @@ -5238,6 +5317,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95467 alias_list = al;
95468 return 0;
95469 }
95470 +#endif
95471
95472 static int __init slab_sysfs_init(void)
95473 {
95474 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
95475 index 27eeab3..7c3f7f2 100644
95476 --- a/mm/sparse-vmemmap.c
95477 +++ b/mm/sparse-vmemmap.c
95478 @@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
95479 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95480 if (!p)
95481 return NULL;
95482 - pud_populate(&init_mm, pud, p);
95483 + pud_populate_kernel(&init_mm, pud, p);
95484 }
95485 return pud;
95486 }
95487 @@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
95488 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95489 if (!p)
95490 return NULL;
95491 - pgd_populate(&init_mm, pgd, p);
95492 + pgd_populate_kernel(&init_mm, pgd, p);
95493 }
95494 return pgd;
95495 }
95496 diff --git a/mm/sparse.c b/mm/sparse.c
95497 index 8cc7be0..d0f7d7a 100644
95498 --- a/mm/sparse.c
95499 +++ b/mm/sparse.c
95500 @@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
95501
95502 for (i = 0; i < PAGES_PER_SECTION; i++) {
95503 if (PageHWPoison(&memmap[i])) {
95504 - atomic_long_sub(1, &num_poisoned_pages);
95505 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
95506 ClearPageHWPoison(&memmap[i]);
95507 }
95508 }
95509 diff --git a/mm/swap.c b/mm/swap.c
95510 index 84b26aa..ce39899 100644
95511 --- a/mm/swap.c
95512 +++ b/mm/swap.c
95513 @@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
95514
95515 __page_cache_release(page);
95516 dtor = get_compound_page_dtor(page);
95517 + if (!PageHuge(page))
95518 + BUG_ON(dtor != free_compound_page);
95519 (*dtor)(page);
95520 }
95521
95522 diff --git a/mm/swapfile.c b/mm/swapfile.c
95523 index 461fce2..363ae44 100644
95524 --- a/mm/swapfile.c
95525 +++ b/mm/swapfile.c
95526 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
95527
95528 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
95529 /* Activity counter to indicate that a swapon or swapoff has occurred */
95530 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
95531 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
95532
95533 static inline unsigned char swap_count(unsigned char ent)
95534 {
95535 @@ -1958,7 +1958,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
95536 spin_unlock(&swap_lock);
95537
95538 err = 0;
95539 - atomic_inc(&proc_poll_event);
95540 + atomic_inc_unchecked(&proc_poll_event);
95541 wake_up_interruptible(&proc_poll_wait);
95542
95543 out_dput:
95544 @@ -1975,8 +1975,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
95545
95546 poll_wait(file, &proc_poll_wait, wait);
95547
95548 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
95549 - seq->poll_event = atomic_read(&proc_poll_event);
95550 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
95551 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95552 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
95553 }
95554
95555 @@ -2074,7 +2074,7 @@ static int swaps_open(struct inode *inode, struct file *file)
95556 return ret;
95557
95558 seq = file->private_data;
95559 - seq->poll_event = atomic_read(&proc_poll_event);
95560 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95561 return 0;
95562 }
95563
95564 @@ -2533,7 +2533,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
95565 (frontswap_map) ? "FS" : "");
95566
95567 mutex_unlock(&swapon_mutex);
95568 - atomic_inc(&proc_poll_event);
95569 + atomic_inc_unchecked(&proc_poll_event);
95570 wake_up_interruptible(&proc_poll_wait);
95571
95572 if (S_ISREG(inode->i_mode))
95573 diff --git a/mm/util.c b/mm/util.c
95574 index 808f375..e4764b5 100644
95575 --- a/mm/util.c
95576 +++ b/mm/util.c
95577 @@ -297,6 +297,12 @@ done:
95578 void arch_pick_mmap_layout(struct mm_struct *mm)
95579 {
95580 mm->mmap_base = TASK_UNMAPPED_BASE;
95581 +
95582 +#ifdef CONFIG_PAX_RANDMMAP
95583 + if (mm->pax_flags & MF_PAX_RANDMMAP)
95584 + mm->mmap_base += mm->delta_mmap;
95585 +#endif
95586 +
95587 mm->get_unmapped_area = arch_get_unmapped_area;
95588 }
95589 #endif
95590 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
95591 index 0fdf968..d6686e8 100644
95592 --- a/mm/vmalloc.c
95593 +++ b/mm/vmalloc.c
95594 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
95595
95596 pte = pte_offset_kernel(pmd, addr);
95597 do {
95598 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95599 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95600 +
95601 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95602 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
95603 + BUG_ON(!pte_exec(*pte));
95604 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
95605 + continue;
95606 + }
95607 +#endif
95608 +
95609 + {
95610 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95611 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95612 + }
95613 } while (pte++, addr += PAGE_SIZE, addr != end);
95614 }
95615
95616 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
95617 pte = pte_alloc_kernel(pmd, addr);
95618 if (!pte)
95619 return -ENOMEM;
95620 +
95621 + pax_open_kernel();
95622 do {
95623 struct page *page = pages[*nr];
95624
95625 - if (WARN_ON(!pte_none(*pte)))
95626 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95627 + if (pgprot_val(prot) & _PAGE_NX)
95628 +#endif
95629 +
95630 + if (!pte_none(*pte)) {
95631 + pax_close_kernel();
95632 + WARN_ON(1);
95633 return -EBUSY;
95634 - if (WARN_ON(!page))
95635 + }
95636 + if (!page) {
95637 + pax_close_kernel();
95638 + WARN_ON(1);
95639 return -ENOMEM;
95640 + }
95641 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
95642 (*nr)++;
95643 } while (pte++, addr += PAGE_SIZE, addr != end);
95644 + pax_close_kernel();
95645 return 0;
95646 }
95647
95648 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
95649 pmd_t *pmd;
95650 unsigned long next;
95651
95652 - pmd = pmd_alloc(&init_mm, pud, addr);
95653 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95654 if (!pmd)
95655 return -ENOMEM;
95656 do {
95657 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
95658 pud_t *pud;
95659 unsigned long next;
95660
95661 - pud = pud_alloc(&init_mm, pgd, addr);
95662 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95663 if (!pud)
95664 return -ENOMEM;
95665 do {
95666 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
95667 if (addr >= MODULES_VADDR && addr < MODULES_END)
95668 return 1;
95669 #endif
95670 +
95671 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95672 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
95673 + return 1;
95674 +#endif
95675 +
95676 return is_vmalloc_addr(x);
95677 }
95678
95679 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
95680
95681 if (!pgd_none(*pgd)) {
95682 pud_t *pud = pud_offset(pgd, addr);
95683 +#ifdef CONFIG_X86
95684 + if (!pud_large(*pud))
95685 +#endif
95686 if (!pud_none(*pud)) {
95687 pmd_t *pmd = pmd_offset(pud, addr);
95688 +#ifdef CONFIG_X86
95689 + if (!pmd_large(*pmd))
95690 +#endif
95691 if (!pmd_none(*pmd)) {
95692 pte_t *ptep, pte;
95693
95694 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
95695 struct vm_struct *area;
95696
95697 BUG_ON(in_interrupt());
95698 +
95699 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95700 + if (flags & VM_KERNEXEC) {
95701 + if (start != VMALLOC_START || end != VMALLOC_END)
95702 + return NULL;
95703 + start = (unsigned long)MODULES_EXEC_VADDR;
95704 + end = (unsigned long)MODULES_EXEC_END;
95705 + }
95706 +#endif
95707 +
95708 if (flags & VM_IOREMAP)
95709 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
95710
95711 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
95712 if (count > totalram_pages)
95713 return NULL;
95714
95715 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95716 + if (!(pgprot_val(prot) & _PAGE_NX))
95717 + flags |= VM_KERNEXEC;
95718 +#endif
95719 +
95720 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
95721 __builtin_return_address(0));
95722 if (!area)
95723 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
95724 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
95725 goto fail;
95726
95727 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95728 + if (!(pgprot_val(prot) & _PAGE_NX))
95729 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
95730 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
95731 + else
95732 +#endif
95733 +
95734 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
95735 start, end, node, gfp_mask, caller);
95736 if (!area)
95737 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
95738 * For tight control over page level allocator and protection flags
95739 * use __vmalloc() instead.
95740 */
95741 -
95742 void *vmalloc_exec(unsigned long size)
95743 {
95744 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
95745 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
95746 NUMA_NO_NODE, __builtin_return_address(0));
95747 }
95748
95749 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
95750 {
95751 struct vm_struct *area;
95752
95753 + BUG_ON(vma->vm_mirror);
95754 +
95755 size = PAGE_ALIGN(size);
95756
95757 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
95758 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
95759 v->addr, v->addr + v->size, v->size);
95760
95761 if (v->caller)
95762 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95763 + seq_printf(m, " %pK", v->caller);
95764 +#else
95765 seq_printf(m, " %pS", v->caller);
95766 +#endif
95767
95768 if (v->nr_pages)
95769 seq_printf(m, " pages=%d", v->nr_pages);
95770 diff --git a/mm/vmstat.c b/mm/vmstat.c
95771 index 7249614..2639fc7 100644
95772 --- a/mm/vmstat.c
95773 +++ b/mm/vmstat.c
95774 @@ -20,6 +20,7 @@
95775 #include <linux/writeback.h>
95776 #include <linux/compaction.h>
95777 #include <linux/mm_inline.h>
95778 +#include <linux/grsecurity.h>
95779
95780 #include "internal.h"
95781
95782 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
95783 *
95784 * vm_stat contains the global counters
95785 */
95786 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95787 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95788 EXPORT_SYMBOL(vm_stat);
95789
95790 #ifdef CONFIG_SMP
95791 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
95792
95793 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95794 if (diff[i])
95795 - atomic_long_add(diff[i], &vm_stat[i]);
95796 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
95797 }
95798
95799 /*
95800 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
95801 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
95802 if (v) {
95803
95804 - atomic_long_add(v, &zone->vm_stat[i]);
95805 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95806 global_diff[i] += v;
95807 #ifdef CONFIG_NUMA
95808 /* 3 seconds idle till flush */
95809 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
95810
95811 v = p->vm_stat_diff[i];
95812 p->vm_stat_diff[i] = 0;
95813 - atomic_long_add(v, &zone->vm_stat[i]);
95814 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95815 global_diff[i] += v;
95816 }
95817 }
95818 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
95819 if (pset->vm_stat_diff[i]) {
95820 int v = pset->vm_stat_diff[i];
95821 pset->vm_stat_diff[i] = 0;
95822 - atomic_long_add(v, &zone->vm_stat[i]);
95823 - atomic_long_add(v, &vm_stat[i]);
95824 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95825 + atomic_long_add_unchecked(v, &vm_stat[i]);
95826 }
95827 }
95828 #endif
95829 @@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
95830 stat_items_size += sizeof(struct vm_event_state);
95831 #endif
95832
95833 - v = kmalloc(stat_items_size, GFP_KERNEL);
95834 + v = kzalloc(stat_items_size, GFP_KERNEL);
95835 m->private = v;
95836 if (!v)
95837 return ERR_PTR(-ENOMEM);
95838 +
95839 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95840 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
95841 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
95842 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
95843 + && !in_group_p(grsec_proc_gid)
95844 +#endif
95845 + )
95846 + return (unsigned long *)m->private + *pos;
95847 +#endif
95848 +#endif
95849 +
95850 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95851 v[i] = global_page_state(i);
95852 v += NR_VM_ZONE_STAT_ITEMS;
95853 @@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
95854 put_online_cpus();
95855 #endif
95856 #ifdef CONFIG_PROC_FS
95857 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
95858 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
95859 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
95860 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
95861 + {
95862 + mode_t gr_mode = S_IRUGO;
95863 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95864 + gr_mode = S_IRUSR;
95865 +#endif
95866 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
95867 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
95868 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
95869 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
95870 + }
95871 #endif
95872 return 0;
95873 }
95874 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
95875 index b3d17d1..e8e4cdd 100644
95876 --- a/net/8021q/vlan.c
95877 +++ b/net/8021q/vlan.c
95878 @@ -472,7 +472,7 @@ out:
95879 return NOTIFY_DONE;
95880 }
95881
95882 -static struct notifier_block vlan_notifier_block __read_mostly = {
95883 +static struct notifier_block vlan_notifier_block = {
95884 .notifier_call = vlan_device_event,
95885 };
95886
95887 @@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
95888 err = -EPERM;
95889 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
95890 break;
95891 - if ((args.u.name_type >= 0) &&
95892 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
95893 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
95894 struct vlan_net *vn;
95895
95896 vn = net_generic(net, vlan_net_id);
95897 diff --git a/net/9p/client.c b/net/9p/client.c
95898 index ee8fd6b..0469d50 100644
95899 --- a/net/9p/client.c
95900 +++ b/net/9p/client.c
95901 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
95902 len - inline_len);
95903 } else {
95904 err = copy_from_user(ename + inline_len,
95905 - uidata, len - inline_len);
95906 + (char __force_user *)uidata, len - inline_len);
95907 if (err) {
95908 err = -EFAULT;
95909 goto out_err;
95910 @@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
95911 kernel_buf = 1;
95912 indata = data;
95913 } else
95914 - indata = (__force char *)udata;
95915 + indata = (__force_kernel char *)udata;
95916 /*
95917 * response header len is 11
95918 * PDU Header(7) + IO Size (4)
95919 @@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
95920 kernel_buf = 1;
95921 odata = data;
95922 } else
95923 - odata = (char *)udata;
95924 + odata = (char __force_kernel *)udata;
95925 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
95926 P9_ZC_HDR_SZ, kernel_buf, "dqd",
95927 fid->fid, offset, rsize);
95928 diff --git a/net/9p/mod.c b/net/9p/mod.c
95929 index 6ab36ae..6f1841b 100644
95930 --- a/net/9p/mod.c
95931 +++ b/net/9p/mod.c
95932 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
95933 void v9fs_register_trans(struct p9_trans_module *m)
95934 {
95935 spin_lock(&v9fs_trans_lock);
95936 - list_add_tail(&m->list, &v9fs_trans_list);
95937 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
95938 spin_unlock(&v9fs_trans_lock);
95939 }
95940 EXPORT_SYMBOL(v9fs_register_trans);
95941 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
95942 void v9fs_unregister_trans(struct p9_trans_module *m)
95943 {
95944 spin_lock(&v9fs_trans_lock);
95945 - list_del_init(&m->list);
95946 + pax_list_del_init((struct list_head *)&m->list);
95947 spin_unlock(&v9fs_trans_lock);
95948 }
95949 EXPORT_SYMBOL(v9fs_unregister_trans);
95950 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
95951 index 9321a77..ed2f256 100644
95952 --- a/net/9p/trans_fd.c
95953 +++ b/net/9p/trans_fd.c
95954 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
95955 oldfs = get_fs();
95956 set_fs(get_ds());
95957 /* The cast to a user pointer is valid due to the set_fs() */
95958 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
95959 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
95960 set_fs(oldfs);
95961
95962 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
95963 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
95964 index 876fbe8..8bbea9f 100644
95965 --- a/net/atm/atm_misc.c
95966 +++ b/net/atm/atm_misc.c
95967 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
95968 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
95969 return 1;
95970 atm_return(vcc, truesize);
95971 - atomic_inc(&vcc->stats->rx_drop);
95972 + atomic_inc_unchecked(&vcc->stats->rx_drop);
95973 return 0;
95974 }
95975 EXPORT_SYMBOL(atm_charge);
95976 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
95977 }
95978 }
95979 atm_return(vcc, guess);
95980 - atomic_inc(&vcc->stats->rx_drop);
95981 + atomic_inc_unchecked(&vcc->stats->rx_drop);
95982 return NULL;
95983 }
95984 EXPORT_SYMBOL(atm_alloc_charge);
95985 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
95986
95987 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95988 {
95989 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95990 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95991 __SONET_ITEMS
95992 #undef __HANDLE_ITEM
95993 }
95994 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
95995
95996 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95997 {
95998 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95999 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96000 __SONET_ITEMS
96001 #undef __HANDLE_ITEM
96002 }
96003 diff --git a/net/atm/lec.c b/net/atm/lec.c
96004 index f23916b..dd4d26b 100644
96005 --- a/net/atm/lec.c
96006 +++ b/net/atm/lec.c
96007 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96008 }
96009
96010 static struct lane2_ops lane2_ops = {
96011 - lane2_resolve, /* resolve, spec 3.1.3 */
96012 - lane2_associate_req, /* associate_req, spec 3.1.4 */
96013 - NULL /* associate indicator, spec 3.1.5 */
96014 + .resolve = lane2_resolve,
96015 + .associate_req = lane2_associate_req,
96016 + .associate_indicator = NULL
96017 };
96018
96019 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96020 diff --git a/net/atm/lec.h b/net/atm/lec.h
96021 index 4149db1..f2ab682 100644
96022 --- a/net/atm/lec.h
96023 +++ b/net/atm/lec.h
96024 @@ -48,7 +48,7 @@ struct lane2_ops {
96025 const u8 *tlvs, u32 sizeoftlvs);
96026 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96027 const u8 *tlvs, u32 sizeoftlvs);
96028 -};
96029 +} __no_const;
96030
96031 /*
96032 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96033 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96034 index d1b2d9a..d549f7f 100644
96035 --- a/net/atm/mpoa_caches.c
96036 +++ b/net/atm/mpoa_caches.c
96037 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96038
96039
96040 static struct in_cache_ops ingress_ops = {
96041 - in_cache_add_entry, /* add_entry */
96042 - in_cache_get, /* get */
96043 - in_cache_get_with_mask, /* get_with_mask */
96044 - in_cache_get_by_vcc, /* get_by_vcc */
96045 - in_cache_put, /* put */
96046 - in_cache_remove_entry, /* remove_entry */
96047 - cache_hit, /* cache_hit */
96048 - clear_count_and_expired, /* clear_count */
96049 - check_resolving_entries, /* check_resolving */
96050 - refresh_entries, /* refresh */
96051 - in_destroy_cache /* destroy_cache */
96052 + .add_entry = in_cache_add_entry,
96053 + .get = in_cache_get,
96054 + .get_with_mask = in_cache_get_with_mask,
96055 + .get_by_vcc = in_cache_get_by_vcc,
96056 + .put = in_cache_put,
96057 + .remove_entry = in_cache_remove_entry,
96058 + .cache_hit = cache_hit,
96059 + .clear_count = clear_count_and_expired,
96060 + .check_resolving = check_resolving_entries,
96061 + .refresh = refresh_entries,
96062 + .destroy_cache = in_destroy_cache
96063 };
96064
96065 static struct eg_cache_ops egress_ops = {
96066 - eg_cache_add_entry, /* add_entry */
96067 - eg_cache_get_by_cache_id, /* get_by_cache_id */
96068 - eg_cache_get_by_tag, /* get_by_tag */
96069 - eg_cache_get_by_vcc, /* get_by_vcc */
96070 - eg_cache_get_by_src_ip, /* get_by_src_ip */
96071 - eg_cache_put, /* put */
96072 - eg_cache_remove_entry, /* remove_entry */
96073 - update_eg_cache_entry, /* update */
96074 - clear_expired, /* clear_expired */
96075 - eg_destroy_cache /* destroy_cache */
96076 + .add_entry = eg_cache_add_entry,
96077 + .get_by_cache_id = eg_cache_get_by_cache_id,
96078 + .get_by_tag = eg_cache_get_by_tag,
96079 + .get_by_vcc = eg_cache_get_by_vcc,
96080 + .get_by_src_ip = eg_cache_get_by_src_ip,
96081 + .put = eg_cache_put,
96082 + .remove_entry = eg_cache_remove_entry,
96083 + .update = update_eg_cache_entry,
96084 + .clear_expired = clear_expired,
96085 + .destroy_cache = eg_destroy_cache
96086 };
96087
96088
96089 diff --git a/net/atm/proc.c b/net/atm/proc.c
96090 index bbb6461..cf04016 100644
96091 --- a/net/atm/proc.c
96092 +++ b/net/atm/proc.c
96093 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96094 const struct k_atm_aal_stats *stats)
96095 {
96096 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96097 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96098 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96099 - atomic_read(&stats->rx_drop));
96100 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96101 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96102 + atomic_read_unchecked(&stats->rx_drop));
96103 }
96104
96105 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96106 diff --git a/net/atm/resources.c b/net/atm/resources.c
96107 index 0447d5d..3cf4728 100644
96108 --- a/net/atm/resources.c
96109 +++ b/net/atm/resources.c
96110 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96111 static void copy_aal_stats(struct k_atm_aal_stats *from,
96112 struct atm_aal_stats *to)
96113 {
96114 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96115 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96116 __AAL_STAT_ITEMS
96117 #undef __HANDLE_ITEM
96118 }
96119 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96120 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96121 struct atm_aal_stats *to)
96122 {
96123 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96124 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96125 __AAL_STAT_ITEMS
96126 #undef __HANDLE_ITEM
96127 }
96128 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96129 index 919a5ce..cc6b444 100644
96130 --- a/net/ax25/sysctl_net_ax25.c
96131 +++ b/net/ax25/sysctl_net_ax25.c
96132 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96133 {
96134 char path[sizeof("net/ax25/") + IFNAMSIZ];
96135 int k;
96136 - struct ctl_table *table;
96137 + ctl_table_no_const *table;
96138
96139 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96140 if (!table)
96141 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96142 index f7270b9..cd0d879 100644
96143 --- a/net/batman-adv/bat_iv_ogm.c
96144 +++ b/net/batman-adv/bat_iv_ogm.c
96145 @@ -307,7 +307,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96146
96147 /* randomize initial seqno to avoid collision */
96148 get_random_bytes(&random_seqno, sizeof(random_seqno));
96149 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96150 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96151
96152 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96153 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96154 @@ -894,9 +894,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96155 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96156
96157 /* change sequence number to network order */
96158 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96159 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96160 batadv_ogm_packet->seqno = htonl(seqno);
96161 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96162 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96163
96164 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96165 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
96166 @@ -1261,7 +1261,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
96167 return;
96168
96169 /* could be changed by schedule_own_packet() */
96170 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96171 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96172
96173 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
96174 has_directlink_flag = 1;
96175 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96176 index 6ddb614..ca7e886 100644
96177 --- a/net/batman-adv/fragmentation.c
96178 +++ b/net/batman-adv/fragmentation.c
96179 @@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96180 frag_header.packet_type = BATADV_UNICAST_FRAG;
96181 frag_header.version = BATADV_COMPAT_VERSION;
96182 frag_header.ttl = BATADV_TTL;
96183 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96184 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96185 frag_header.reserved = 0;
96186 frag_header.no = 0;
96187 frag_header.total_size = htons(skb->len);
96188 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96189 index a8f99d1..11797ef 100644
96190 --- a/net/batman-adv/soft-interface.c
96191 +++ b/net/batman-adv/soft-interface.c
96192 @@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
96193 primary_if->net_dev->dev_addr, ETH_ALEN);
96194
96195 /* set broadcast sequence number */
96196 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96197 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96198 bcast_packet->seqno = htonl(seqno);
96199
96200 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96201 @@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96202 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96203
96204 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96205 - atomic_set(&bat_priv->bcast_seqno, 1);
96206 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96207 atomic_set(&bat_priv->tt.vn, 0);
96208 atomic_set(&bat_priv->tt.local_changes, 0);
96209 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96210 @@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96211
96212 /* randomize initial seqno to avoid collision */
96213 get_random_bytes(&random_seqno, sizeof(random_seqno));
96214 - atomic_set(&bat_priv->frag_seqno, random_seqno);
96215 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96216
96217 bat_priv->primary_if = NULL;
96218 bat_priv->num_ifaces = 0;
96219 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96220 index 91dd369..9c25750 100644
96221 --- a/net/batman-adv/types.h
96222 +++ b/net/batman-adv/types.h
96223 @@ -56,7 +56,7 @@
96224 struct batadv_hard_iface_bat_iv {
96225 unsigned char *ogm_buff;
96226 int ogm_buff_len;
96227 - atomic_t ogm_seqno;
96228 + atomic_unchecked_t ogm_seqno;
96229 };
96230
96231 /**
96232 @@ -673,7 +673,7 @@ struct batadv_priv {
96233 atomic_t bonding;
96234 atomic_t fragmentation;
96235 atomic_t packet_size_max;
96236 - atomic_t frag_seqno;
96237 + atomic_unchecked_t frag_seqno;
96238 #ifdef CONFIG_BATMAN_ADV_BLA
96239 atomic_t bridge_loop_avoidance;
96240 #endif
96241 @@ -687,7 +687,7 @@ struct batadv_priv {
96242 #ifdef CONFIG_BATMAN_ADV_DEBUG
96243 atomic_t log_level;
96244 #endif
96245 - atomic_t bcast_seqno;
96246 + atomic_unchecked_t bcast_seqno;
96247 atomic_t bcast_queue_left;
96248 atomic_t batman_queue_left;
96249 char num_ifaces;
96250 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96251 index 7552f9e..074ce29 100644
96252 --- a/net/bluetooth/hci_sock.c
96253 +++ b/net/bluetooth/hci_sock.c
96254 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96255 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96256 }
96257
96258 - len = min_t(unsigned int, len, sizeof(uf));
96259 + len = min((size_t)len, sizeof(uf));
96260 if (copy_from_user(&uf, optval, len)) {
96261 err = -EFAULT;
96262 break;
96263 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96264 index 4af3821..f2ba46c 100644
96265 --- a/net/bluetooth/l2cap_core.c
96266 +++ b/net/bluetooth/l2cap_core.c
96267 @@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96268 break;
96269
96270 case L2CAP_CONF_RFC:
96271 - if (olen == sizeof(rfc))
96272 - memcpy(&rfc, (void *)val, olen);
96273 + if (olen != sizeof(rfc))
96274 + break;
96275 +
96276 + memcpy(&rfc, (void *)val, olen);
96277
96278 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96279 rfc.mode != chan->mode)
96280 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96281 index 7cc24d2..e83f531 100644
96282 --- a/net/bluetooth/l2cap_sock.c
96283 +++ b/net/bluetooth/l2cap_sock.c
96284 @@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96285 struct sock *sk = sock->sk;
96286 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96287 struct l2cap_options opts;
96288 - int len, err = 0;
96289 + int err = 0;
96290 + size_t len = optlen;
96291 u32 opt;
96292
96293 BT_DBG("sk %p", sk);
96294 @@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96295 opts.max_tx = chan->max_tx;
96296 opts.txwin_size = chan->tx_win;
96297
96298 - len = min_t(unsigned int, sizeof(opts), optlen);
96299 + len = min(sizeof(opts), len);
96300 if (copy_from_user((char *) &opts, optval, len)) {
96301 err = -EFAULT;
96302 break;
96303 @@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96304 struct bt_security sec;
96305 struct bt_power pwr;
96306 struct l2cap_conn *conn;
96307 - int len, err = 0;
96308 + int err = 0;
96309 + size_t len = optlen;
96310 u32 opt;
96311
96312 BT_DBG("sk %p", sk);
96313 @@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96314
96315 sec.level = BT_SECURITY_LOW;
96316
96317 - len = min_t(unsigned int, sizeof(sec), optlen);
96318 + len = min(sizeof(sec), len);
96319 if (copy_from_user((char *) &sec, optval, len)) {
96320 err = -EFAULT;
96321 break;
96322 @@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96323
96324 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96325
96326 - len = min_t(unsigned int, sizeof(pwr), optlen);
96327 + len = min(sizeof(pwr), len);
96328 if (copy_from_user((char *) &pwr, optval, len)) {
96329 err = -EFAULT;
96330 break;
96331 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96332 index 3c2d3e4..884855a 100644
96333 --- a/net/bluetooth/rfcomm/sock.c
96334 +++ b/net/bluetooth/rfcomm/sock.c
96335 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96336 struct sock *sk = sock->sk;
96337 struct bt_security sec;
96338 int err = 0;
96339 - size_t len;
96340 + size_t len = optlen;
96341 u32 opt;
96342
96343 BT_DBG("sk %p", sk);
96344 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96345
96346 sec.level = BT_SECURITY_LOW;
96347
96348 - len = min_t(unsigned int, sizeof(sec), optlen);
96349 + len = min(sizeof(sec), len);
96350 if (copy_from_user((char *) &sec, optval, len)) {
96351 err = -EFAULT;
96352 break;
96353 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96354 index 84fcf9f..e389b27 100644
96355 --- a/net/bluetooth/rfcomm/tty.c
96356 +++ b/net/bluetooth/rfcomm/tty.c
96357 @@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96358 BT_DBG("tty %p id %d", tty, tty->index);
96359
96360 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96361 - dev->channel, dev->port.count);
96362 + dev->channel, atomic_read(&dev->port.count));
96363
96364 err = tty_port_open(&dev->port, tty, filp);
96365 if (err)
96366 @@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96367 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96368
96369 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96370 - dev->port.count);
96371 + atomic_read(&dev->port.count));
96372
96373 tty_port_close(&dev->port, tty, filp);
96374 }
96375 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96376 index ac78024..161a80c 100644
96377 --- a/net/bridge/netfilter/ebtables.c
96378 +++ b/net/bridge/netfilter/ebtables.c
96379 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96380 tmp.valid_hooks = t->table->valid_hooks;
96381 }
96382 mutex_unlock(&ebt_mutex);
96383 - if (copy_to_user(user, &tmp, *len) != 0){
96384 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
96385 BUGPRINT("c2u Didn't work\n");
96386 ret = -EFAULT;
96387 break;
96388 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96389 goto out;
96390 tmp.valid_hooks = t->valid_hooks;
96391
96392 - if (copy_to_user(user, &tmp, *len) != 0) {
96393 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96394 ret = -EFAULT;
96395 break;
96396 }
96397 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96398 tmp.entries_size = t->table->entries_size;
96399 tmp.valid_hooks = t->table->valid_hooks;
96400
96401 - if (copy_to_user(user, &tmp, *len) != 0) {
96402 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96403 ret = -EFAULT;
96404 break;
96405 }
96406 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96407 index 0f45522..dab651f 100644
96408 --- a/net/caif/cfctrl.c
96409 +++ b/net/caif/cfctrl.c
96410 @@ -10,6 +10,7 @@
96411 #include <linux/spinlock.h>
96412 #include <linux/slab.h>
96413 #include <linux/pkt_sched.h>
96414 +#include <linux/sched.h>
96415 #include <net/caif/caif_layer.h>
96416 #include <net/caif/cfpkt.h>
96417 #include <net/caif/cfctrl.h>
96418 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96419 memset(&dev_info, 0, sizeof(dev_info));
96420 dev_info.id = 0xff;
96421 cfsrvl_init(&this->serv, 0, &dev_info, false);
96422 - atomic_set(&this->req_seq_no, 1);
96423 - atomic_set(&this->rsp_seq_no, 1);
96424 + atomic_set_unchecked(&this->req_seq_no, 1);
96425 + atomic_set_unchecked(&this->rsp_seq_no, 1);
96426 this->serv.layer.receive = cfctrl_recv;
96427 sprintf(this->serv.layer.name, "ctrl");
96428 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96429 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96430 struct cfctrl_request_info *req)
96431 {
96432 spin_lock_bh(&ctrl->info_list_lock);
96433 - atomic_inc(&ctrl->req_seq_no);
96434 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
96435 + atomic_inc_unchecked(&ctrl->req_seq_no);
96436 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
96437 list_add_tail(&req->list, &ctrl->list);
96438 spin_unlock_bh(&ctrl->info_list_lock);
96439 }
96440 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
96441 if (p != first)
96442 pr_warn("Requests are not received in order\n");
96443
96444 - atomic_set(&ctrl->rsp_seq_no,
96445 + atomic_set_unchecked(&ctrl->rsp_seq_no,
96446 p->sequence_no);
96447 list_del(&p->list);
96448 goto out;
96449 diff --git a/net/can/af_can.c b/net/can/af_can.c
96450 index a27f8aa..67174a3 100644
96451 --- a/net/can/af_can.c
96452 +++ b/net/can/af_can.c
96453 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
96454 };
96455
96456 /* notifier block for netdevice event */
96457 -static struct notifier_block can_netdev_notifier __read_mostly = {
96458 +static struct notifier_block can_netdev_notifier = {
96459 .notifier_call = can_notifier,
96460 };
96461
96462 diff --git a/net/can/gw.c b/net/can/gw.c
96463 index 3f9b0f3..fc6d4fa 100644
96464 --- a/net/can/gw.c
96465 +++ b/net/can/gw.c
96466 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
96467 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
96468
96469 static HLIST_HEAD(cgw_list);
96470 -static struct notifier_block notifier;
96471
96472 static struct kmem_cache *cgw_cache __read_mostly;
96473
96474 @@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
96475 return err;
96476 }
96477
96478 +static struct notifier_block notifier = {
96479 + .notifier_call = cgw_notifier
96480 +};
96481 +
96482 static __init int cgw_module_init(void)
96483 {
96484 /* sanitize given module parameter */
96485 @@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
96486 return -ENOMEM;
96487
96488 /* set notifier */
96489 - notifier.notifier_call = cgw_notifier;
96490 register_netdevice_notifier(&notifier);
96491
96492 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
96493 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
96494 index 4a5df7b..9ad1f1d 100644
96495 --- a/net/ceph/messenger.c
96496 +++ b/net/ceph/messenger.c
96497 @@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
96498 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
96499
96500 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
96501 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
96502 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
96503
96504 static struct page *zero_page; /* used in certain error cases */
96505
96506 @@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
96507 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
96508 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
96509
96510 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96511 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96512 s = addr_str[i];
96513
96514 switch (ss->ss_family) {
96515 diff --git a/net/compat.c b/net/compat.c
96516 index f50161f..94fa415 100644
96517 --- a/net/compat.c
96518 +++ b/net/compat.c
96519 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
96520 return -EFAULT;
96521 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
96522 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
96523 - kmsg->msg_name = compat_ptr(tmp1);
96524 - kmsg->msg_iov = compat_ptr(tmp2);
96525 - kmsg->msg_control = compat_ptr(tmp3);
96526 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
96527 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
96528 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
96529 return 0;
96530 }
96531
96532 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96533
96534 if (kern_msg->msg_namelen) {
96535 if (mode == VERIFY_READ) {
96536 - int err = move_addr_to_kernel(kern_msg->msg_name,
96537 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
96538 kern_msg->msg_namelen,
96539 kern_address);
96540 if (err < 0)
96541 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96542 kern_msg->msg_name = NULL;
96543
96544 tot_len = iov_from_user_compat_to_kern(kern_iov,
96545 - (struct compat_iovec __user *)kern_msg->msg_iov,
96546 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
96547 kern_msg->msg_iovlen);
96548 if (tot_len >= 0)
96549 kern_msg->msg_iov = kern_iov;
96550 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96551
96552 #define CMSG_COMPAT_FIRSTHDR(msg) \
96553 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96554 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
96555 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
96556 (struct compat_cmsghdr __user *)NULL)
96557
96558 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
96559 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
96560 (ucmlen) <= (unsigned long) \
96561 ((mhdr)->msg_controllen - \
96562 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
96563 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
96564
96565 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
96566 struct compat_cmsghdr __user *cmsg, int cmsg_len)
96567 {
96568 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
96569 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
96570 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
96571 msg->msg_controllen)
96572 return NULL;
96573 return (struct compat_cmsghdr __user *)ptr;
96574 @@ -222,7 +222,7 @@ Efault:
96575
96576 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
96577 {
96578 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96579 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96580 struct compat_cmsghdr cmhdr;
96581 struct compat_timeval ctv;
96582 struct compat_timespec cts[3];
96583 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
96584
96585 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
96586 {
96587 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96588 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96589 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
96590 int fdnum = scm->fp->count;
96591 struct file **fp = scm->fp->fp;
96592 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
96593 return -EFAULT;
96594 old_fs = get_fs();
96595 set_fs(KERNEL_DS);
96596 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
96597 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
96598 set_fs(old_fs);
96599
96600 return err;
96601 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
96602 len = sizeof(ktime);
96603 old_fs = get_fs();
96604 set_fs(KERNEL_DS);
96605 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
96606 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
96607 set_fs(old_fs);
96608
96609 if (!err) {
96610 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96611 case MCAST_JOIN_GROUP:
96612 case MCAST_LEAVE_GROUP:
96613 {
96614 - struct compat_group_req __user *gr32 = (void *)optval;
96615 + struct compat_group_req __user *gr32 = (void __user *)optval;
96616 struct group_req __user *kgr =
96617 compat_alloc_user_space(sizeof(struct group_req));
96618 u32 interface;
96619 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96620 case MCAST_BLOCK_SOURCE:
96621 case MCAST_UNBLOCK_SOURCE:
96622 {
96623 - struct compat_group_source_req __user *gsr32 = (void *)optval;
96624 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
96625 struct group_source_req __user *kgsr = compat_alloc_user_space(
96626 sizeof(struct group_source_req));
96627 u32 interface;
96628 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96629 }
96630 case MCAST_MSFILTER:
96631 {
96632 - struct compat_group_filter __user *gf32 = (void *)optval;
96633 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96634 struct group_filter __user *kgf;
96635 u32 interface, fmode, numsrc;
96636
96637 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
96638 char __user *optval, int __user *optlen,
96639 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
96640 {
96641 - struct compat_group_filter __user *gf32 = (void *)optval;
96642 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96643 struct group_filter __user *kgf;
96644 int __user *koptlen;
96645 u32 interface, fmode, numsrc;
96646 @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
96647
96648 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
96649 return -EINVAL;
96650 - if (copy_from_user(a, args, nas[call]))
96651 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
96652 return -EFAULT;
96653 a0 = a[0];
96654 a1 = a[1];
96655 diff --git a/net/core/datagram.c b/net/core/datagram.c
96656 index a16ed7b..eb44d17 100644
96657 --- a/net/core/datagram.c
96658 +++ b/net/core/datagram.c
96659 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
96660 }
96661
96662 kfree_skb(skb);
96663 - atomic_inc(&sk->sk_drops);
96664 + atomic_inc_unchecked(&sk->sk_drops);
96665 sk_mem_reclaim_partial(sk);
96666
96667 return err;
96668 diff --git a/net/core/dev.c b/net/core/dev.c
96669 index 616eccf..31832d38 100644
96670 --- a/net/core/dev.c
96671 +++ b/net/core/dev.c
96672 @@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
96673 {
96674 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
96675 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
96676 - atomic_long_inc(&dev->rx_dropped);
96677 + atomic_long_inc_unchecked(&dev->rx_dropped);
96678 kfree_skb(skb);
96679 return NET_RX_DROP;
96680 }
96681 }
96682
96683 if (unlikely(!is_skb_forwardable(dev, skb))) {
96684 - atomic_long_inc(&dev->rx_dropped);
96685 + atomic_long_inc_unchecked(&dev->rx_dropped);
96686 kfree_skb(skb);
96687 return NET_RX_DROP;
96688 }
96689 @@ -2434,7 +2434,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
96690
96691 struct dev_gso_cb {
96692 void (*destructor)(struct sk_buff *skb);
96693 -};
96694 +} __no_const;
96695
96696 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
96697
96698 @@ -3224,7 +3224,7 @@ enqueue:
96699
96700 local_irq_restore(flags);
96701
96702 - atomic_long_inc(&skb->dev->rx_dropped);
96703 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96704 kfree_skb(skb);
96705 return NET_RX_DROP;
96706 }
96707 @@ -3296,7 +3296,7 @@ int netif_rx_ni(struct sk_buff *skb)
96708 }
96709 EXPORT_SYMBOL(netif_rx_ni);
96710
96711 -static void net_tx_action(struct softirq_action *h)
96712 +static __latent_entropy void net_tx_action(void)
96713 {
96714 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96715
96716 @@ -3630,7 +3630,7 @@ ncls:
96717 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
96718 } else {
96719 drop:
96720 - atomic_long_inc(&skb->dev->rx_dropped);
96721 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96722 kfree_skb(skb);
96723 /* Jamal, now you will not able to escape explaining
96724 * me how you were going to use this. :-)
96725 @@ -4290,7 +4290,7 @@ void netif_napi_del(struct napi_struct *napi)
96726 }
96727 EXPORT_SYMBOL(netif_napi_del);
96728
96729 -static void net_rx_action(struct softirq_action *h)
96730 +static __latent_entropy void net_rx_action(void)
96731 {
96732 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96733 unsigned long time_limit = jiffies + 2;
96734 @@ -6179,7 +6179,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
96735 } else {
96736 netdev_stats_to_stats64(storage, &dev->stats);
96737 }
96738 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
96739 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
96740 return storage;
96741 }
96742 EXPORT_SYMBOL(dev_get_stats);
96743 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
96744 index 5b7d0e1..cb960fc 100644
96745 --- a/net/core/dev_ioctl.c
96746 +++ b/net/core/dev_ioctl.c
96747 @@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
96748 if (no_module && capable(CAP_NET_ADMIN))
96749 no_module = request_module("netdev-%s", name);
96750 if (no_module && capable(CAP_SYS_MODULE)) {
96751 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
96752 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
96753 +#else
96754 if (!request_module("%s", name))
96755 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
96756 name);
96757 +#endif
96758 }
96759 }
96760 EXPORT_SYMBOL(dev_load);
96761 diff --git a/net/core/filter.c b/net/core/filter.c
96762 index ad30d62..c2757df 100644
96763 --- a/net/core/filter.c
96764 +++ b/net/core/filter.c
96765 @@ -679,7 +679,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
96766 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
96767 if (!fp)
96768 return -ENOMEM;
96769 - memcpy(fp->insns, fprog->filter, fsize);
96770 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
96771
96772 atomic_set(&fp->refcnt, 1);
96773 fp->len = fprog->len;
96774 diff --git a/net/core/flow.c b/net/core/flow.c
96775 index dfa602c..3103d88 100644
96776 --- a/net/core/flow.c
96777 +++ b/net/core/flow.c
96778 @@ -61,7 +61,7 @@ struct flow_cache {
96779 struct timer_list rnd_timer;
96780 };
96781
96782 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
96783 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
96784 EXPORT_SYMBOL(flow_cache_genid);
96785 static struct flow_cache flow_cache_global;
96786 static struct kmem_cache *flow_cachep __read_mostly;
96787 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
96788
96789 static int flow_entry_valid(struct flow_cache_entry *fle)
96790 {
96791 - if (atomic_read(&flow_cache_genid) != fle->genid)
96792 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
96793 return 0;
96794 if (fle->object && !fle->object->ops->check(fle->object))
96795 return 0;
96796 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
96797 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
96798 fcp->hash_count++;
96799 }
96800 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
96801 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
96802 flo = fle->object;
96803 if (!flo)
96804 goto ret_object;
96805 @@ -279,7 +279,7 @@ nocache:
96806 }
96807 flo = resolver(net, key, family, dir, flo, ctx);
96808 if (fle) {
96809 - fle->genid = atomic_read(&flow_cache_genid);
96810 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
96811 if (!IS_ERR(flo))
96812 fle->object = flo;
96813 else
96814 diff --git a/net/core/iovec.c b/net/core/iovec.c
96815 index b618694..192bbba 100644
96816 --- a/net/core/iovec.c
96817 +++ b/net/core/iovec.c
96818 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
96819 if (m->msg_namelen) {
96820 if (mode == VERIFY_READ) {
96821 void __user *namep;
96822 - namep = (void __user __force *) m->msg_name;
96823 + namep = (void __force_user *) m->msg_name;
96824 err = move_addr_to_kernel(namep, m->msg_namelen,
96825 address);
96826 if (err < 0)
96827 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
96828 }
96829
96830 size = m->msg_iovlen * sizeof(struct iovec);
96831 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
96832 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
96833 return -EFAULT;
96834
96835 m->msg_iov = iov;
96836 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
96837 index 932c6d7..71fd94a 100644
96838 --- a/net/core/neighbour.c
96839 +++ b/net/core/neighbour.c
96840 @@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
96841 void __user *buffer, size_t *lenp, loff_t *ppos)
96842 {
96843 int size, ret;
96844 - struct ctl_table tmp = *ctl;
96845 + ctl_table_no_const tmp = *ctl;
96846
96847 tmp.extra1 = &zero;
96848 tmp.extra2 = &unres_qlen_max;
96849 @@ -2983,11 +2983,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
96850 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
96851 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
96852 } else {
96853 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
96854 dev_name_source = "default";
96855 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
96856 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
96857 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
96858 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
96859 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
96860 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
96861 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
96862 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
96863 }
96864
96865
96866 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
96867 index 2bf8329..7960607 100644
96868 --- a/net/core/net-procfs.c
96869 +++ b/net/core/net-procfs.c
96870 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
96871 else
96872 seq_printf(seq, "%04x", ntohs(pt->type));
96873
96874 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96875 + seq_printf(seq, " %-8s %pf\n",
96876 + pt->dev ? pt->dev->name : "", NULL);
96877 +#else
96878 seq_printf(seq, " %-8s %pf\n",
96879 pt->dev ? pt->dev->name : "", pt->func);
96880 +#endif
96881 }
96882
96883 return 0;
96884 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
96885 index f3edf96..3cd8b40 100644
96886 --- a/net/core/net-sysfs.c
96887 +++ b/net/core/net-sysfs.c
96888 @@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
96889 }
96890 EXPORT_SYMBOL(netdev_class_remove_file_ns);
96891
96892 -int netdev_kobject_init(void)
96893 +int __init netdev_kobject_init(void)
96894 {
96895 kobj_ns_type_register(&net_ns_type_operations);
96896 return class_register(&net_class);
96897 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
96898 index 81d3a9a..a0bd7a8 100644
96899 --- a/net/core/net_namespace.c
96900 +++ b/net/core/net_namespace.c
96901 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
96902 int error;
96903 LIST_HEAD(net_exit_list);
96904
96905 - list_add_tail(&ops->list, list);
96906 + pax_list_add_tail((struct list_head *)&ops->list, list);
96907 if (ops->init || (ops->id && ops->size)) {
96908 for_each_net(net) {
96909 error = ops_init(ops, net);
96910 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
96911
96912 out_undo:
96913 /* If I have an error cleanup all namespaces I initialized */
96914 - list_del(&ops->list);
96915 + pax_list_del((struct list_head *)&ops->list);
96916 ops_exit_list(ops, &net_exit_list);
96917 ops_free_list(ops, &net_exit_list);
96918 return error;
96919 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
96920 struct net *net;
96921 LIST_HEAD(net_exit_list);
96922
96923 - list_del(&ops->list);
96924 + pax_list_del((struct list_head *)&ops->list);
96925 for_each_net(net)
96926 list_add_tail(&net->exit_list, &net_exit_list);
96927 ops_exit_list(ops, &net_exit_list);
96928 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
96929 mutex_lock(&net_mutex);
96930 error = register_pernet_operations(&pernet_list, ops);
96931 if (!error && (first_device == &pernet_list))
96932 - first_device = &ops->list;
96933 + first_device = (struct list_head *)&ops->list;
96934 mutex_unlock(&net_mutex);
96935 return error;
96936 }
96937 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
96938 index 81975f2..9ef3531 100644
96939 --- a/net/core/netpoll.c
96940 +++ b/net/core/netpoll.c
96941 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96942 struct udphdr *udph;
96943 struct iphdr *iph;
96944 struct ethhdr *eth;
96945 - static atomic_t ip_ident;
96946 + static atomic_unchecked_t ip_ident;
96947 struct ipv6hdr *ip6h;
96948
96949 udp_len = len + sizeof(*udph);
96950 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96951 put_unaligned(0x45, (unsigned char *)iph);
96952 iph->tos = 0;
96953 put_unaligned(htons(ip_len), &(iph->tot_len));
96954 - iph->id = htons(atomic_inc_return(&ip_ident));
96955 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
96956 iph->frag_off = 0;
96957 iph->ttl = 64;
96958 iph->protocol = IPPROTO_UDP;
96959 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
96960 index cf67144..12bf94c 100644
96961 --- a/net/core/rtnetlink.c
96962 +++ b/net/core/rtnetlink.c
96963 @@ -58,7 +58,7 @@ struct rtnl_link {
96964 rtnl_doit_func doit;
96965 rtnl_dumpit_func dumpit;
96966 rtnl_calcit_func calcit;
96967 -};
96968 +} __no_const;
96969
96970 static DEFINE_MUTEX(rtnl_mutex);
96971
96972 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
96973 if (rtnl_link_ops_get(ops->kind))
96974 return -EEXIST;
96975
96976 - if (!ops->dellink)
96977 - ops->dellink = unregister_netdevice_queue;
96978 + if (!ops->dellink) {
96979 + pax_open_kernel();
96980 + *(void **)&ops->dellink = unregister_netdevice_queue;
96981 + pax_close_kernel();
96982 + }
96983
96984 - list_add_tail(&ops->list, &link_ops);
96985 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
96986 return 0;
96987 }
96988 EXPORT_SYMBOL_GPL(__rtnl_link_register);
96989 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
96990 for_each_net(net) {
96991 __rtnl_kill_links(net, ops);
96992 }
96993 - list_del(&ops->list);
96994 + pax_list_del((struct list_head *)&ops->list);
96995 }
96996 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
96997
96998 diff --git a/net/core/scm.c b/net/core/scm.c
96999 index b442e7e..6f5b5a2 100644
97000 --- a/net/core/scm.c
97001 +++ b/net/core/scm.c
97002 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97003 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97004 {
97005 struct cmsghdr __user *cm
97006 - = (__force struct cmsghdr __user *)msg->msg_control;
97007 + = (struct cmsghdr __force_user *)msg->msg_control;
97008 struct cmsghdr cmhdr;
97009 int cmlen = CMSG_LEN(len);
97010 int err;
97011 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97012 err = -EFAULT;
97013 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97014 goto out;
97015 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97016 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97017 goto out;
97018 cmlen = CMSG_SPACE(len);
97019 if (msg->msg_controllen < cmlen)
97020 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97021 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97022 {
97023 struct cmsghdr __user *cm
97024 - = (__force struct cmsghdr __user*)msg->msg_control;
97025 + = (struct cmsghdr __force_user *)msg->msg_control;
97026
97027 int fdmax = 0;
97028 int fdnum = scm->fp->count;
97029 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97030 if (fdnum < fdmax)
97031 fdmax = fdnum;
97032
97033 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97034 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97035 i++, cmfptr++)
97036 {
97037 struct socket *sock;
97038 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97039 index deffb37..213db0a 100644
97040 --- a/net/core/skbuff.c
97041 +++ b/net/core/skbuff.c
97042 @@ -2006,7 +2006,7 @@ EXPORT_SYMBOL(__skb_checksum);
97043 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97044 int len, __wsum csum)
97045 {
97046 - const struct skb_checksum_ops ops = {
97047 + static const struct skb_checksum_ops ops = {
97048 .update = csum_partial_ext,
97049 .combine = csum_block_add_ext,
97050 };
97051 @@ -3119,13 +3119,15 @@ void __init skb_init(void)
97052 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97053 sizeof(struct sk_buff),
97054 0,
97055 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97056 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97057 + SLAB_NO_SANITIZE,
97058 NULL);
97059 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97060 (2*sizeof(struct sk_buff)) +
97061 sizeof(atomic_t),
97062 0,
97063 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97064 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97065 + SLAB_NO_SANITIZE,
97066 NULL);
97067 }
97068
97069 diff --git a/net/core/sock.c b/net/core/sock.c
97070 index fbc5cfb..6d7e8c3 100644
97071 --- a/net/core/sock.c
97072 +++ b/net/core/sock.c
97073 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97074 struct sk_buff_head *list = &sk->sk_receive_queue;
97075
97076 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97077 - atomic_inc(&sk->sk_drops);
97078 + atomic_inc_unchecked(&sk->sk_drops);
97079 trace_sock_rcvqueue_full(sk, skb);
97080 return -ENOMEM;
97081 }
97082 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97083 return err;
97084
97085 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97086 - atomic_inc(&sk->sk_drops);
97087 + atomic_inc_unchecked(&sk->sk_drops);
97088 return -ENOBUFS;
97089 }
97090
97091 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97092 skb_dst_force(skb);
97093
97094 spin_lock_irqsave(&list->lock, flags);
97095 - skb->dropcount = atomic_read(&sk->sk_drops);
97096 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97097 __skb_queue_tail(list, skb);
97098 spin_unlock_irqrestore(&list->lock, flags);
97099
97100 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97101 skb->dev = NULL;
97102
97103 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97104 - atomic_inc(&sk->sk_drops);
97105 + atomic_inc_unchecked(&sk->sk_drops);
97106 goto discard_and_relse;
97107 }
97108 if (nested)
97109 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97110 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97111 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97112 bh_unlock_sock(sk);
97113 - atomic_inc(&sk->sk_drops);
97114 + atomic_inc_unchecked(&sk->sk_drops);
97115 goto discard_and_relse;
97116 }
97117
97118 @@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97119 struct timeval tm;
97120 } v;
97121
97122 - int lv = sizeof(int);
97123 - int len;
97124 + unsigned int lv = sizeof(int);
97125 + unsigned int len;
97126
97127 if (get_user(len, optlen))
97128 return -EFAULT;
97129 - if (len < 0)
97130 + if (len > INT_MAX)
97131 return -EINVAL;
97132
97133 memset(&v, 0, sizeof(v));
97134 @@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97135
97136 case SO_PEERNAME:
97137 {
97138 - char address[128];
97139 + char address[_K_SS_MAXSIZE];
97140
97141 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97142 return -ENOTCONN;
97143 - if (lv < len)
97144 + if (lv < len || sizeof address < len)
97145 return -EINVAL;
97146 if (copy_to_user(optval, address, len))
97147 return -EFAULT;
97148 @@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97149
97150 if (len > lv)
97151 len = lv;
97152 - if (copy_to_user(optval, &v, len))
97153 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
97154 return -EFAULT;
97155 lenout:
97156 if (put_user(len, optlen))
97157 @@ -2353,7 +2353,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97158 */
97159 smp_wmb();
97160 atomic_set(&sk->sk_refcnt, 1);
97161 - atomic_set(&sk->sk_drops, 0);
97162 + atomic_set_unchecked(&sk->sk_drops, 0);
97163 }
97164 EXPORT_SYMBOL(sock_init_data);
97165
97166 @@ -2478,6 +2478,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97167 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97168 int level, int type)
97169 {
97170 + struct sock_extended_err ee;
97171 struct sock_exterr_skb *serr;
97172 struct sk_buff *skb, *skb2;
97173 int copied, err;
97174 @@ -2499,7 +2500,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97175 sock_recv_timestamp(msg, sk, skb);
97176
97177 serr = SKB_EXT_ERR(skb);
97178 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97179 + ee = serr->ee;
97180 + put_cmsg(msg, level, type, sizeof ee, &ee);
97181
97182 msg->msg_flags |= MSG_ERRQUEUE;
97183 err = copied;
97184 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97185 index a0e9cf6..ef7f9ed 100644
97186 --- a/net/core/sock_diag.c
97187 +++ b/net/core/sock_diag.c
97188 @@ -9,26 +9,33 @@
97189 #include <linux/inet_diag.h>
97190 #include <linux/sock_diag.h>
97191
97192 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97193 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97194 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97195 static DEFINE_MUTEX(sock_diag_table_mutex);
97196
97197 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97198 {
97199 +#ifndef CONFIG_GRKERNSEC_HIDESYM
97200 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97201 cookie[1] != INET_DIAG_NOCOOKIE) &&
97202 ((u32)(unsigned long)sk != cookie[0] ||
97203 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97204 return -ESTALE;
97205 else
97206 +#endif
97207 return 0;
97208 }
97209 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97210
97211 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97212 {
97213 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97214 + cookie[0] = 0;
97215 + cookie[1] = 0;
97216 +#else
97217 cookie[0] = (u32)(unsigned long)sk;
97218 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97219 +#endif
97220 }
97221 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97222
97223 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97224 mutex_lock(&sock_diag_table_mutex);
97225 if (sock_diag_handlers[hndl->family])
97226 err = -EBUSY;
97227 - else
97228 + else {
97229 + pax_open_kernel();
97230 sock_diag_handlers[hndl->family] = hndl;
97231 + pax_close_kernel();
97232 + }
97233 mutex_unlock(&sock_diag_table_mutex);
97234
97235 return err;
97236 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97237
97238 mutex_lock(&sock_diag_table_mutex);
97239 BUG_ON(sock_diag_handlers[family] != hnld);
97240 + pax_open_kernel();
97241 sock_diag_handlers[family] = NULL;
97242 + pax_close_kernel();
97243 mutex_unlock(&sock_diag_table_mutex);
97244 }
97245 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97246 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97247 index cca4441..5e616de 100644
97248 --- a/net/core/sysctl_net_core.c
97249 +++ b/net/core/sysctl_net_core.c
97250 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97251 {
97252 unsigned int orig_size, size;
97253 int ret, i;
97254 - struct ctl_table tmp = {
97255 + ctl_table_no_const tmp = {
97256 .data = &size,
97257 .maxlen = sizeof(size),
97258 .mode = table->mode
97259 @@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97260 void __user *buffer, size_t *lenp, loff_t *ppos)
97261 {
97262 char id[IFNAMSIZ];
97263 - struct ctl_table tbl = {
97264 + ctl_table_no_const tbl = {
97265 .data = id,
97266 .maxlen = IFNAMSIZ,
97267 };
97268 @@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
97269
97270 static __net_init int sysctl_core_net_init(struct net *net)
97271 {
97272 - struct ctl_table *tbl;
97273 + ctl_table_no_const *tbl = NULL;
97274
97275 net->core.sysctl_somaxconn = SOMAXCONN;
97276
97277 - tbl = netns_core_table;
97278 if (!net_eq(net, &init_net)) {
97279 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97280 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97281 if (tbl == NULL)
97282 goto err_dup;
97283
97284 @@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
97285 if (net->user_ns != &init_user_ns) {
97286 tbl[0].procname = NULL;
97287 }
97288 - }
97289 -
97290 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97291 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97292 + } else
97293 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
97294 if (net->core.sysctl_hdr == NULL)
97295 goto err_reg;
97296
97297 return 0;
97298
97299 err_reg:
97300 - if (tbl != netns_core_table)
97301 - kfree(tbl);
97302 + kfree(tbl);
97303 err_dup:
97304 return -ENOMEM;
97305 }
97306 @@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
97307 kfree(tbl);
97308 }
97309
97310 -static __net_initdata struct pernet_operations sysctl_core_ops = {
97311 +static __net_initconst struct pernet_operations sysctl_core_ops = {
97312 .init = sysctl_core_net_init,
97313 .exit = sysctl_core_net_exit,
97314 };
97315 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
97316 index dd4d506..fb2fb87 100644
97317 --- a/net/decnet/af_decnet.c
97318 +++ b/net/decnet/af_decnet.c
97319 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
97320 .sysctl_rmem = sysctl_decnet_rmem,
97321 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
97322 .obj_size = sizeof(struct dn_sock),
97323 + .slab_flags = SLAB_USERCOPY,
97324 };
97325
97326 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
97327 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
97328 index dd0dfb2..fdbc764 100644
97329 --- a/net/decnet/dn_dev.c
97330 +++ b/net/decnet/dn_dev.c
97331 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
97332 .extra1 = &min_t3,
97333 .extra2 = &max_t3
97334 },
97335 - {0}
97336 + { }
97337 },
97338 };
97339
97340 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
97341 index 5325b54..a0d4d69 100644
97342 --- a/net/decnet/sysctl_net_decnet.c
97343 +++ b/net/decnet/sysctl_net_decnet.c
97344 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
97345
97346 if (len > *lenp) len = *lenp;
97347
97348 - if (copy_to_user(buffer, addr, len))
97349 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
97350 return -EFAULT;
97351
97352 *lenp = len;
97353 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
97354
97355 if (len > *lenp) len = *lenp;
97356
97357 - if (copy_to_user(buffer, devname, len))
97358 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
97359 return -EFAULT;
97360
97361 *lenp = len;
97362 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
97363 index 1865fdf..581a595 100644
97364 --- a/net/ieee802154/dgram.c
97365 +++ b/net/ieee802154/dgram.c
97366 @@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
97367 if (saddr) {
97368 saddr->family = AF_IEEE802154;
97369 saddr->addr = mac_cb(skb)->sa;
97370 + }
97371 + if (addr_len)
97372 *addr_len = sizeof(*saddr);
97373 - }
97374
97375 if (flags & MSG_TRUNC)
97376 copied = skb->len;
97377 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
97378 index 70011e0..454ca6a 100644
97379 --- a/net/ipv4/af_inet.c
97380 +++ b/net/ipv4/af_inet.c
97381 @@ -1683,13 +1683,9 @@ static int __init inet_init(void)
97382
97383 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
97384
97385 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
97386 - if (!sysctl_local_reserved_ports)
97387 - goto out;
97388 -
97389 rc = proto_register(&tcp_prot, 1);
97390 if (rc)
97391 - goto out_free_reserved_ports;
97392 + goto out;
97393
97394 rc = proto_register(&udp_prot, 1);
97395 if (rc)
97396 @@ -1796,8 +1792,6 @@ out_unregister_udp_proto:
97397 proto_unregister(&udp_prot);
97398 out_unregister_tcp_proto:
97399 proto_unregister(&tcp_prot);
97400 -out_free_reserved_ports:
97401 - kfree(sysctl_local_reserved_ports);
97402 goto out;
97403 }
97404
97405 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
97406 index f4b34d8..c54a163 100644
97407 --- a/net/ipv4/devinet.c
97408 +++ b/net/ipv4/devinet.c
97409 @@ -1534,7 +1534,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
97410 idx = 0;
97411 head = &net->dev_index_head[h];
97412 rcu_read_lock();
97413 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97414 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97415 net->dev_base_seq;
97416 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97417 if (idx < s_idx)
97418 @@ -1845,7 +1845,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
97419 idx = 0;
97420 head = &net->dev_index_head[h];
97421 rcu_read_lock();
97422 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97423 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97424 net->dev_base_seq;
97425 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97426 if (idx < s_idx)
97427 @@ -2070,7 +2070,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
97428 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
97429 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
97430
97431 -static struct devinet_sysctl_table {
97432 +static const struct devinet_sysctl_table {
97433 struct ctl_table_header *sysctl_header;
97434 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
97435 } devinet_sysctl = {
97436 @@ -2192,7 +2192,7 @@ static __net_init int devinet_init_net(struct net *net)
97437 int err;
97438 struct ipv4_devconf *all, *dflt;
97439 #ifdef CONFIG_SYSCTL
97440 - struct ctl_table *tbl = ctl_forward_entry;
97441 + ctl_table_no_const *tbl = NULL;
97442 struct ctl_table_header *forw_hdr;
97443 #endif
97444
97445 @@ -2210,7 +2210,7 @@ static __net_init int devinet_init_net(struct net *net)
97446 goto err_alloc_dflt;
97447
97448 #ifdef CONFIG_SYSCTL
97449 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
97450 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
97451 if (tbl == NULL)
97452 goto err_alloc_ctl;
97453
97454 @@ -2230,7 +2230,10 @@ static __net_init int devinet_init_net(struct net *net)
97455 goto err_reg_dflt;
97456
97457 err = -ENOMEM;
97458 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97459 + if (!net_eq(net, &init_net))
97460 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97461 + else
97462 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
97463 if (forw_hdr == NULL)
97464 goto err_reg_ctl;
97465 net->ipv4.forw_hdr = forw_hdr;
97466 @@ -2246,8 +2249,7 @@ err_reg_ctl:
97467 err_reg_dflt:
97468 __devinet_sysctl_unregister(all);
97469 err_reg_all:
97470 - if (tbl != ctl_forward_entry)
97471 - kfree(tbl);
97472 + kfree(tbl);
97473 err_alloc_ctl:
97474 #endif
97475 if (dflt != &ipv4_devconf_dflt)
97476 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
97477 index c7539e2..b455e51 100644
97478 --- a/net/ipv4/fib_frontend.c
97479 +++ b/net/ipv4/fib_frontend.c
97480 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
97481 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97482 fib_sync_up(dev);
97483 #endif
97484 - atomic_inc(&net->ipv4.dev_addr_genid);
97485 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97486 rt_cache_flush(dev_net(dev));
97487 break;
97488 case NETDEV_DOWN:
97489 fib_del_ifaddr(ifa, NULL);
97490 - atomic_inc(&net->ipv4.dev_addr_genid);
97491 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97492 if (ifa->ifa_dev->ifa_list == NULL) {
97493 /* Last address was deleted from this interface.
97494 * Disable IP.
97495 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
97496 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97497 fib_sync_up(dev);
97498 #endif
97499 - atomic_inc(&net->ipv4.dev_addr_genid);
97500 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97501 rt_cache_flush(net);
97502 break;
97503 case NETDEV_DOWN:
97504 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
97505 index e63f47a..e5c531d 100644
97506 --- a/net/ipv4/fib_semantics.c
97507 +++ b/net/ipv4/fib_semantics.c
97508 @@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
97509 nh->nh_saddr = inet_select_addr(nh->nh_dev,
97510 nh->nh_gw,
97511 nh->nh_parent->fib_scope);
97512 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
97513 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
97514
97515 return nh->nh_saddr;
97516 }
97517 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
97518 index fc0e649..febfa65 100644
97519 --- a/net/ipv4/inet_connection_sock.c
97520 +++ b/net/ipv4/inet_connection_sock.c
97521 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
97522 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
97523 #endif
97524
97525 -unsigned long *sysctl_local_reserved_ports;
97526 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
97527 EXPORT_SYMBOL(sysctl_local_reserved_ports);
97528
97529 void inet_get_local_port_range(struct net *net, int *low, int *high)
97530 diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
97531 index bb075fc..322dceb 100644
97532 --- a/net/ipv4/inet_fragment.c
97533 +++ b/net/ipv4/inet_fragment.c
97534 @@ -278,9 +278,10 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
97535
97536 atomic_inc(&qp->refcnt);
97537 hlist_add_head(&qp->list, &hb->chain);
97538 - spin_unlock(&hb->chain_lock);
97539 - read_unlock(&f->lock);
97540 inet_frag_lru_add(nf, qp);
97541 + spin_unlock(&hb->chain_lock);
97542 + read_unlock(&f->lock);
97543 +
97544 return qp;
97545 }
97546
97547 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
97548 index 8b9cf27..0d8d592 100644
97549 --- a/net/ipv4/inet_hashtables.c
97550 +++ b/net/ipv4/inet_hashtables.c
97551 @@ -18,6 +18,7 @@
97552 #include <linux/sched.h>
97553 #include <linux/slab.h>
97554 #include <linux/wait.h>
97555 +#include <linux/security.h>
97556
97557 #include <net/inet_connection_sock.h>
97558 #include <net/inet_hashtables.h>
97559 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
97560 return inet_ehashfn(net, laddr, lport, faddr, fport);
97561 }
97562
97563 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
97564 +
97565 /*
97566 * Allocate and initialize a new local port bind bucket.
97567 * The bindhash mutex for snum's hash chain must be held here.
97568 @@ -554,6 +557,8 @@ ok:
97569 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
97570 spin_unlock(&head->lock);
97571
97572 + gr_update_task_in_ip_table(current, inet_sk(sk));
97573 +
97574 if (tw) {
97575 inet_twsk_deschedule(tw, death_row);
97576 while (twrefcnt) {
97577 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
97578 index 33d5537..da337a4 100644
97579 --- a/net/ipv4/inetpeer.c
97580 +++ b/net/ipv4/inetpeer.c
97581 @@ -503,8 +503,8 @@ relookup:
97582 if (p) {
97583 p->daddr = *daddr;
97584 atomic_set(&p->refcnt, 1);
97585 - atomic_set(&p->rid, 0);
97586 - atomic_set(&p->ip_id_count,
97587 + atomic_set_unchecked(&p->rid, 0);
97588 + atomic_set_unchecked(&p->ip_id_count,
97589 (daddr->family == AF_INET) ?
97590 secure_ip_id(daddr->addr.a4) :
97591 secure_ipv6_id(daddr->addr.a6));
97592 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
97593 index 2481993..2d9a7a7 100644
97594 --- a/net/ipv4/ip_fragment.c
97595 +++ b/net/ipv4/ip_fragment.c
97596 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
97597 return 0;
97598
97599 start = qp->rid;
97600 - end = atomic_inc_return(&peer->rid);
97601 + end = atomic_inc_return_unchecked(&peer->rid);
97602 qp->rid = end;
97603
97604 rc = qp->q.fragments && (end - start) > max;
97605 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
97606
97607 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97608 {
97609 - struct ctl_table *table;
97610 + ctl_table_no_const *table = NULL;
97611 struct ctl_table_header *hdr;
97612
97613 - table = ip4_frags_ns_ctl_table;
97614 if (!net_eq(net, &init_net)) {
97615 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97616 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97617 if (table == NULL)
97618 goto err_alloc;
97619
97620 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97621 /* Don't export sysctls to unprivileged users */
97622 if (net->user_ns != &init_user_ns)
97623 table[0].procname = NULL;
97624 - }
97625 + hdr = register_net_sysctl(net, "net/ipv4", table);
97626 + } else
97627 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
97628
97629 - hdr = register_net_sysctl(net, "net/ipv4", table);
97630 if (hdr == NULL)
97631 goto err_reg;
97632
97633 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97634 return 0;
97635
97636 err_reg:
97637 - if (!net_eq(net, &init_net))
97638 - kfree(table);
97639 + kfree(table);
97640 err_alloc:
97641 return -ENOMEM;
97642 }
97643 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
97644 index d306360..1c1a1f1 100644
97645 --- a/net/ipv4/ip_gre.c
97646 +++ b/net/ipv4/ip_gre.c
97647 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
97648 module_param(log_ecn_error, bool, 0644);
97649 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97650
97651 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
97652 +static struct rtnl_link_ops ipgre_link_ops;
97653 static int ipgre_tunnel_init(struct net_device *dev);
97654
97655 static int ipgre_net_id __read_mostly;
97656 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
97657 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
97658 };
97659
97660 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97661 +static struct rtnl_link_ops ipgre_link_ops = {
97662 .kind = "gre",
97663 .maxtype = IFLA_GRE_MAX,
97664 .policy = ipgre_policy,
97665 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97666 .fill_info = ipgre_fill_info,
97667 };
97668
97669 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
97670 +static struct rtnl_link_ops ipgre_tap_ops = {
97671 .kind = "gretap",
97672 .maxtype = IFLA_GRE_MAX,
97673 .policy = ipgre_policy,
97674 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
97675 index ddf32a6..3fdeea9 100644
97676 --- a/net/ipv4/ip_sockglue.c
97677 +++ b/net/ipv4/ip_sockglue.c
97678 @@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97679 len = min_t(unsigned int, len, opt->optlen);
97680 if (put_user(len, optlen))
97681 return -EFAULT;
97682 - if (copy_to_user(optval, opt->__data, len))
97683 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
97684 + copy_to_user(optval, opt->__data, len))
97685 return -EFAULT;
97686 return 0;
97687 }
97688 @@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97689 if (sk->sk_type != SOCK_STREAM)
97690 return -ENOPROTOOPT;
97691
97692 - msg.msg_control = optval;
97693 + msg.msg_control = (void __force_kernel *)optval;
97694 msg.msg_controllen = len;
97695 msg.msg_flags = flags;
97696
97697 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
97698 index 52b802a..b725179 100644
97699 --- a/net/ipv4/ip_vti.c
97700 +++ b/net/ipv4/ip_vti.c
97701 @@ -44,7 +44,7 @@
97702 #include <net/net_namespace.h>
97703 #include <net/netns/generic.h>
97704
97705 -static struct rtnl_link_ops vti_link_ops __read_mostly;
97706 +static struct rtnl_link_ops vti_link_ops;
97707
97708 static int vti_net_id __read_mostly;
97709 static int vti_tunnel_init(struct net_device *dev);
97710 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
97711 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
97712 };
97713
97714 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
97715 +static struct rtnl_link_ops vti_link_ops = {
97716 .kind = "vti",
97717 .maxtype = IFLA_VTI_MAX,
97718 .policy = vti_policy,
97719 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
97720 index efa1138..20dbba0 100644
97721 --- a/net/ipv4/ipconfig.c
97722 +++ b/net/ipv4/ipconfig.c
97723 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
97724
97725 mm_segment_t oldfs = get_fs();
97726 set_fs(get_ds());
97727 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97728 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97729 set_fs(oldfs);
97730 return res;
97731 }
97732 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
97733
97734 mm_segment_t oldfs = get_fs();
97735 set_fs(get_ds());
97736 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97737 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97738 set_fs(oldfs);
97739 return res;
97740 }
97741 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
97742
97743 mm_segment_t oldfs = get_fs();
97744 set_fs(get_ds());
97745 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
97746 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
97747 set_fs(oldfs);
97748 return res;
97749 }
97750 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
97751 index fe3e9f7..4956990 100644
97752 --- a/net/ipv4/ipip.c
97753 +++ b/net/ipv4/ipip.c
97754 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97755 static int ipip_net_id __read_mostly;
97756
97757 static int ipip_tunnel_init(struct net_device *dev);
97758 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
97759 +static struct rtnl_link_ops ipip_link_ops;
97760
97761 static int ipip_err(struct sk_buff *skb, u32 info)
97762 {
97763 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
97764 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
97765 };
97766
97767 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
97768 +static struct rtnl_link_ops ipip_link_ops = {
97769 .kind = "ipip",
97770 .maxtype = IFLA_IPTUN_MAX,
97771 .policy = ipip_policy,
97772 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
97773 index 59da7cd..e318de1 100644
97774 --- a/net/ipv4/netfilter/arp_tables.c
97775 +++ b/net/ipv4/netfilter/arp_tables.c
97776 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
97777 #endif
97778
97779 static int get_info(struct net *net, void __user *user,
97780 - const int *len, int compat)
97781 + int len, int compat)
97782 {
97783 char name[XT_TABLE_MAXNAMELEN];
97784 struct xt_table *t;
97785 int ret;
97786
97787 - if (*len != sizeof(struct arpt_getinfo)) {
97788 - duprintf("length %u != %Zu\n", *len,
97789 + if (len != sizeof(struct arpt_getinfo)) {
97790 + duprintf("length %u != %Zu\n", len,
97791 sizeof(struct arpt_getinfo));
97792 return -EINVAL;
97793 }
97794 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
97795 info.size = private->size;
97796 strcpy(info.name, name);
97797
97798 - if (copy_to_user(user, &info, *len) != 0)
97799 + if (copy_to_user(user, &info, len) != 0)
97800 ret = -EFAULT;
97801 else
97802 ret = 0;
97803 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
97804
97805 switch (cmd) {
97806 case ARPT_SO_GET_INFO:
97807 - ret = get_info(sock_net(sk), user, len, 1);
97808 + ret = get_info(sock_net(sk), user, *len, 1);
97809 break;
97810 case ARPT_SO_GET_ENTRIES:
97811 ret = compat_get_entries(sock_net(sk), user, len);
97812 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
97813
97814 switch (cmd) {
97815 case ARPT_SO_GET_INFO:
97816 - ret = get_info(sock_net(sk), user, len, 0);
97817 + ret = get_info(sock_net(sk), user, *len, 0);
97818 break;
97819
97820 case ARPT_SO_GET_ENTRIES:
97821 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
97822 index 718dfbd..cef4152 100644
97823 --- a/net/ipv4/netfilter/ip_tables.c
97824 +++ b/net/ipv4/netfilter/ip_tables.c
97825 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
97826 #endif
97827
97828 static int get_info(struct net *net, void __user *user,
97829 - const int *len, int compat)
97830 + int len, int compat)
97831 {
97832 char name[XT_TABLE_MAXNAMELEN];
97833 struct xt_table *t;
97834 int ret;
97835
97836 - if (*len != sizeof(struct ipt_getinfo)) {
97837 - duprintf("length %u != %zu\n", *len,
97838 + if (len != sizeof(struct ipt_getinfo)) {
97839 + duprintf("length %u != %zu\n", len,
97840 sizeof(struct ipt_getinfo));
97841 return -EINVAL;
97842 }
97843 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
97844 info.size = private->size;
97845 strcpy(info.name, name);
97846
97847 - if (copy_to_user(user, &info, *len) != 0)
97848 + if (copy_to_user(user, &info, len) != 0)
97849 ret = -EFAULT;
97850 else
97851 ret = 0;
97852 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97853
97854 switch (cmd) {
97855 case IPT_SO_GET_INFO:
97856 - ret = get_info(sock_net(sk), user, len, 1);
97857 + ret = get_info(sock_net(sk), user, *len, 1);
97858 break;
97859 case IPT_SO_GET_ENTRIES:
97860 ret = compat_get_entries(sock_net(sk), user, len);
97861 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97862
97863 switch (cmd) {
97864 case IPT_SO_GET_INFO:
97865 - ret = get_info(sock_net(sk), user, len, 0);
97866 + ret = get_info(sock_net(sk), user, *len, 0);
97867 break;
97868
97869 case IPT_SO_GET_ENTRIES:
97870 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
97871 index 242e7f4..a084e95 100644
97872 --- a/net/ipv4/ping.c
97873 +++ b/net/ipv4/ping.c
97874 @@ -55,7 +55,7 @@
97875
97876
97877 struct ping_table ping_table;
97878 -struct pingv6_ops pingv6_ops;
97879 +struct pingv6_ops *pingv6_ops;
97880 EXPORT_SYMBOL_GPL(pingv6_ops);
97881
97882 static u16 ping_port_rover;
97883 @@ -334,7 +334,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
97884 return -ENODEV;
97885 }
97886 }
97887 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
97888 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
97889 scoped);
97890 rcu_read_unlock();
97891
97892 @@ -542,7 +542,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
97893 }
97894 #if IS_ENABLED(CONFIG_IPV6)
97895 } else if (skb->protocol == htons(ETH_P_IPV6)) {
97896 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
97897 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
97898 #endif
97899 }
97900
97901 @@ -560,7 +560,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
97902 info, (u8 *)icmph);
97903 #if IS_ENABLED(CONFIG_IPV6)
97904 } else if (family == AF_INET6) {
97905 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
97906 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
97907 info, (u8 *)icmph);
97908 #endif
97909 }
97910 @@ -830,6 +830,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97911 {
97912 struct inet_sock *isk = inet_sk(sk);
97913 int family = sk->sk_family;
97914 + struct sockaddr_in *sin;
97915 + struct sockaddr_in6 *sin6;
97916 struct sk_buff *skb;
97917 int copied, err;
97918
97919 @@ -839,12 +841,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97920 if (flags & MSG_OOB)
97921 goto out;
97922
97923 + if (addr_len) {
97924 + if (family == AF_INET)
97925 + *addr_len = sizeof(*sin);
97926 + else if (family == AF_INET6 && addr_len)
97927 + *addr_len = sizeof(*sin6);
97928 + }
97929 +
97930 if (flags & MSG_ERRQUEUE) {
97931 if (family == AF_INET) {
97932 return ip_recv_error(sk, msg, len, addr_len);
97933 #if IS_ENABLED(CONFIG_IPV6)
97934 } else if (family == AF_INET6) {
97935 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
97936 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
97937 addr_len);
97938 #endif
97939 }
97940 @@ -876,7 +885,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97941 sin->sin_port = 0 /* skb->h.uh->source */;
97942 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97943 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97944 - *addr_len = sizeof(*sin);
97945 }
97946
97947 if (isk->cmsg_flags)
97948 @@ -899,11 +907,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97949 sin6->sin6_scope_id =
97950 ipv6_iface_scope_id(&sin6->sin6_addr,
97951 IP6CB(skb)->iif);
97952 - *addr_len = sizeof(*sin6);
97953 }
97954
97955 if (inet6_sk(sk)->rxopt.all)
97956 - pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
97957 + pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
97958 #endif
97959 } else {
97960 BUG();
97961 @@ -1093,7 +1100,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
97962 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97963 0, sock_i_ino(sp),
97964 atomic_read(&sp->sk_refcnt), sp,
97965 - atomic_read(&sp->sk_drops));
97966 + atomic_read_unchecked(&sp->sk_drops));
97967 }
97968
97969 static int ping_v4_seq_show(struct seq_file *seq, void *v)
97970 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
97971 index 23c3e5b..cdb8b36 100644
97972 --- a/net/ipv4/raw.c
97973 +++ b/net/ipv4/raw.c
97974 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
97975 int raw_rcv(struct sock *sk, struct sk_buff *skb)
97976 {
97977 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
97978 - atomic_inc(&sk->sk_drops);
97979 + atomic_inc_unchecked(&sk->sk_drops);
97980 kfree_skb(skb);
97981 return NET_RX_DROP;
97982 }
97983 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97984 if (flags & MSG_OOB)
97985 goto out;
97986
97987 + if (addr_len)
97988 + *addr_len = sizeof(*sin);
97989 +
97990 if (flags & MSG_ERRQUEUE) {
97991 err = ip_recv_error(sk, msg, len, addr_len);
97992 goto out;
97993 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97994 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97995 sin->sin_port = 0;
97996 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
97997 - *addr_len = sizeof(*sin);
97998 }
97999 if (inet->cmsg_flags)
98000 ip_cmsg_recv(msg, skb);
98001 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98002
98003 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98004 {
98005 + struct icmp_filter filter;
98006 +
98007 if (optlen > sizeof(struct icmp_filter))
98008 optlen = sizeof(struct icmp_filter);
98009 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98010 + if (copy_from_user(&filter, optval, optlen))
98011 return -EFAULT;
98012 + raw_sk(sk)->filter = filter;
98013 return 0;
98014 }
98015
98016 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98017 {
98018 int len, ret = -EFAULT;
98019 + struct icmp_filter filter;
98020
98021 if (get_user(len, optlen))
98022 goto out;
98023 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98024 if (len > sizeof(struct icmp_filter))
98025 len = sizeof(struct icmp_filter);
98026 ret = -EFAULT;
98027 - if (put_user(len, optlen) ||
98028 - copy_to_user(optval, &raw_sk(sk)->filter, len))
98029 + filter = raw_sk(sk)->filter;
98030 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98031 goto out;
98032 ret = 0;
98033 out: return ret;
98034 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98035 0, 0L, 0,
98036 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98037 0, sock_i_ino(sp),
98038 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98039 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98040 }
98041
98042 static int raw_seq_show(struct seq_file *seq, void *v)
98043 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98044 index e611651f..0c17263 100644
98045 --- a/net/ipv4/route.c
98046 +++ b/net/ipv4/route.c
98047 @@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98048 .maxlen = sizeof(int),
98049 .mode = 0200,
98050 .proc_handler = ipv4_sysctl_rtcache_flush,
98051 + .extra1 = &init_net,
98052 },
98053 { },
98054 };
98055
98056 static __net_init int sysctl_route_net_init(struct net *net)
98057 {
98058 - struct ctl_table *tbl;
98059 + ctl_table_no_const *tbl = NULL;
98060
98061 - tbl = ipv4_route_flush_table;
98062 if (!net_eq(net, &init_net)) {
98063 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98064 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98065 if (tbl == NULL)
98066 goto err_dup;
98067
98068 /* Don't export sysctls to unprivileged users */
98069 if (net->user_ns != &init_user_ns)
98070 tbl[0].procname = NULL;
98071 - }
98072 - tbl[0].extra1 = net;
98073 + tbl[0].extra1 = net;
98074 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98075 + } else
98076 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98077
98078 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98079 if (net->ipv4.route_hdr == NULL)
98080 goto err_reg;
98081 return 0;
98082
98083 err_reg:
98084 - if (tbl != ipv4_route_flush_table)
98085 - kfree(tbl);
98086 + kfree(tbl);
98087 err_dup:
98088 return -ENOMEM;
98089 }
98090 @@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98091
98092 static __net_init int rt_genid_init(struct net *net)
98093 {
98094 - atomic_set(&net->ipv4.rt_genid, 0);
98095 - atomic_set(&net->fnhe_genid, 0);
98096 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98097 + atomic_set_unchecked(&net->fnhe_genid, 0);
98098 get_random_bytes(&net->ipv4.dev_addr_genid,
98099 sizeof(net->ipv4.dev_addr_genid));
98100 return 0;
98101 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98102 index 3d69ec8..57207b4 100644
98103 --- a/net/ipv4/sysctl_net_ipv4.c
98104 +++ b/net/ipv4/sysctl_net_ipv4.c
98105 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98106 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98107 int ret;
98108 int range[2];
98109 - struct ctl_table tmp = {
98110 + ctl_table_no_const tmp = {
98111 .data = &range,
98112 .maxlen = sizeof(range),
98113 .mode = table->mode,
98114 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98115 int ret;
98116 gid_t urange[2];
98117 kgid_t low, high;
98118 - struct ctl_table tmp = {
98119 + ctl_table_no_const tmp = {
98120 .data = &urange,
98121 .maxlen = sizeof(urange),
98122 .mode = table->mode,
98123 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98124 void __user *buffer, size_t *lenp, loff_t *ppos)
98125 {
98126 char val[TCP_CA_NAME_MAX];
98127 - struct ctl_table tbl = {
98128 + ctl_table_no_const tbl = {
98129 .data = val,
98130 .maxlen = TCP_CA_NAME_MAX,
98131 };
98132 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98133 void __user *buffer, size_t *lenp,
98134 loff_t *ppos)
98135 {
98136 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98137 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98138 int ret;
98139
98140 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98141 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98142 void __user *buffer, size_t *lenp,
98143 loff_t *ppos)
98144 {
98145 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98146 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98147 int ret;
98148
98149 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98150 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98151 void __user *buffer, size_t *lenp,
98152 loff_t *ppos)
98153 {
98154 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98155 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98156 struct tcp_fastopen_context *ctxt;
98157 int ret;
98158 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98159 @@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
98160 },
98161 {
98162 .procname = "ip_local_reserved_ports",
98163 - .data = NULL, /* initialized in sysctl_ipv4_init */
98164 + .data = sysctl_local_reserved_ports,
98165 .maxlen = 65536,
98166 .mode = 0644,
98167 .proc_handler = proc_do_large_bitmap,
98168 @@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
98169
98170 static __net_init int ipv4_sysctl_init_net(struct net *net)
98171 {
98172 - struct ctl_table *table;
98173 + ctl_table_no_const *table = NULL;
98174
98175 - table = ipv4_net_table;
98176 if (!net_eq(net, &init_net)) {
98177 int i;
98178
98179 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98180 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98181 if (table == NULL)
98182 goto err_alloc;
98183
98184 @@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98185 net->ipv4.sysctl_local_ports.range[0] = 32768;
98186 net->ipv4.sysctl_local_ports.range[1] = 61000;
98187
98188 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98189 + if (!net_eq(net, &init_net))
98190 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98191 + else
98192 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98193 if (net->ipv4.ipv4_hdr == NULL)
98194 goto err_reg;
98195
98196 return 0;
98197
98198 err_reg:
98199 - if (!net_eq(net, &init_net))
98200 - kfree(table);
98201 + kfree(table);
98202 err_alloc:
98203 return -ENOMEM;
98204 }
98205 @@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98206 static __init int sysctl_ipv4_init(void)
98207 {
98208 struct ctl_table_header *hdr;
98209 - struct ctl_table *i;
98210 -
98211 - for (i = ipv4_table; i->procname; i++) {
98212 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98213 - i->data = sysctl_local_reserved_ports;
98214 - break;
98215 - }
98216 - }
98217 - if (!i->procname)
98218 - return -EINVAL;
98219
98220 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98221 if (hdr == NULL)
98222 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98223 index c53b7f3..a89aadd 100644
98224 --- a/net/ipv4/tcp_input.c
98225 +++ b/net/ipv4/tcp_input.c
98226 @@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
98227 * without any lock. We want to make sure compiler wont store
98228 * intermediate values in this location.
98229 */
98230 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
98231 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
98232 sk->sk_max_pacing_rate);
98233 }
98234
98235 @@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
98236 * simplifies code)
98237 */
98238 static void
98239 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98240 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98241 struct sk_buff *head, struct sk_buff *tail,
98242 u32 start, u32 end)
98243 {
98244 @@ -5559,6 +5559,7 @@ discard:
98245 tcp_paws_reject(&tp->rx_opt, 0))
98246 goto discard_and_undo;
98247
98248 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
98249 if (th->syn) {
98250 /* We see SYN without ACK. It is attempt of
98251 * simultaneous connect with crossed SYNs.
98252 @@ -5609,6 +5610,7 @@ discard:
98253 goto discard;
98254 #endif
98255 }
98256 +#endif
98257 /* "fifth, if neither of the SYN or RST bits is set then
98258 * drop the segment and return."
98259 */
98260 @@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
98261 goto discard;
98262
98263 if (th->syn) {
98264 - if (th->fin)
98265 + if (th->fin || th->urg || th->psh)
98266 goto discard;
98267 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
98268 return 1;
98269 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
98270 index 0672139..cacc17d 100644
98271 --- a/net/ipv4/tcp_ipv4.c
98272 +++ b/net/ipv4/tcp_ipv4.c
98273 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
98274 EXPORT_SYMBOL(sysctl_tcp_low_latency);
98275
98276
98277 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98278 +extern int grsec_enable_blackhole;
98279 +#endif
98280 +
98281 #ifdef CONFIG_TCP_MD5SIG
98282 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
98283 __be32 daddr, __be32 saddr, const struct tcphdr *th);
98284 @@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
98285 return 0;
98286
98287 reset:
98288 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98289 + if (!grsec_enable_blackhole)
98290 +#endif
98291 tcp_v4_send_reset(rsk, skb);
98292 discard:
98293 kfree_skb(skb);
98294 @@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
98295 TCP_SKB_CB(skb)->sacked = 0;
98296
98297 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98298 - if (!sk)
98299 + if (!sk) {
98300 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98301 + ret = 1;
98302 +#endif
98303 goto no_tcp_socket;
98304 -
98305 + }
98306 process:
98307 - if (sk->sk_state == TCP_TIME_WAIT)
98308 + if (sk->sk_state == TCP_TIME_WAIT) {
98309 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98310 + ret = 2;
98311 +#endif
98312 goto do_time_wait;
98313 + }
98314
98315 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
98316 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98317 @@ -2034,6 +2048,10 @@ csum_error:
98318 bad_packet:
98319 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98320 } else {
98321 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98322 + if (!grsec_enable_blackhole || (ret == 1 &&
98323 + (skb->dev->flags & IFF_LOOPBACK)))
98324 +#endif
98325 tcp_v4_send_reset(NULL, skb);
98326 }
98327
98328 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
98329 index 97b6841..0893357 100644
98330 --- a/net/ipv4/tcp_minisocks.c
98331 +++ b/net/ipv4/tcp_minisocks.c
98332 @@ -27,6 +27,10 @@
98333 #include <net/inet_common.h>
98334 #include <net/xfrm.h>
98335
98336 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98337 +extern int grsec_enable_blackhole;
98338 +#endif
98339 +
98340 int sysctl_tcp_syncookies __read_mostly = 1;
98341 EXPORT_SYMBOL(sysctl_tcp_syncookies);
98342
98343 @@ -708,7 +712,10 @@ embryonic_reset:
98344 * avoid becoming vulnerable to outside attack aiming at
98345 * resetting legit local connections.
98346 */
98347 - req->rsk_ops->send_reset(sk, skb);
98348 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98349 + if (!grsec_enable_blackhole)
98350 +#endif
98351 + req->rsk_ops->send_reset(sk, skb);
98352 } else if (fastopen) { /* received a valid RST pkt */
98353 reqsk_fastopen_remove(sk, req, true);
98354 tcp_reset(sk);
98355 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
98356 index 8b97d71..9d7ccf5 100644
98357 --- a/net/ipv4/tcp_probe.c
98358 +++ b/net/ipv4/tcp_probe.c
98359 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
98360 if (cnt + width >= len)
98361 break;
98362
98363 - if (copy_to_user(buf + cnt, tbuf, width))
98364 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
98365 return -EFAULT;
98366 cnt += width;
98367 }
98368 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
98369 index 64f0354..a81b39d 100644
98370 --- a/net/ipv4/tcp_timer.c
98371 +++ b/net/ipv4/tcp_timer.c
98372 @@ -22,6 +22,10 @@
98373 #include <linux/gfp.h>
98374 #include <net/tcp.h>
98375
98376 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98377 +extern int grsec_lastack_retries;
98378 +#endif
98379 +
98380 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
98381 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
98382 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
98383 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
98384 }
98385 }
98386
98387 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98388 + if ((sk->sk_state == TCP_LAST_ACK) &&
98389 + (grsec_lastack_retries > 0) &&
98390 + (grsec_lastack_retries < retry_until))
98391 + retry_until = grsec_lastack_retries;
98392 +#endif
98393 +
98394 if (retransmits_timed_out(sk, retry_until,
98395 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
98396 /* Has it gone just too far? */
98397 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
98398 index a7e4729..2758946 100644
98399 --- a/net/ipv4/udp.c
98400 +++ b/net/ipv4/udp.c
98401 @@ -87,6 +87,7 @@
98402 #include <linux/types.h>
98403 #include <linux/fcntl.h>
98404 #include <linux/module.h>
98405 +#include <linux/security.h>
98406 #include <linux/socket.h>
98407 #include <linux/sockios.h>
98408 #include <linux/igmp.h>
98409 @@ -113,6 +114,10 @@
98410 #include <net/busy_poll.h>
98411 #include "udp_impl.h"
98412
98413 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98414 +extern int grsec_enable_blackhole;
98415 +#endif
98416 +
98417 struct udp_table udp_table __read_mostly;
98418 EXPORT_SYMBOL(udp_table);
98419
98420 @@ -615,6 +620,9 @@ found:
98421 return s;
98422 }
98423
98424 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
98425 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
98426 +
98427 /*
98428 * This routine is called by the ICMP module when it gets some
98429 * sort of error condition. If err < 0 then the socket should
98430 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98431 dport = usin->sin_port;
98432 if (dport == 0)
98433 return -EINVAL;
98434 +
98435 + err = gr_search_udp_sendmsg(sk, usin);
98436 + if (err)
98437 + return err;
98438 } else {
98439 if (sk->sk_state != TCP_ESTABLISHED)
98440 return -EDESTADDRREQ;
98441 +
98442 + err = gr_search_udp_sendmsg(sk, NULL);
98443 + if (err)
98444 + return err;
98445 +
98446 daddr = inet->inet_daddr;
98447 dport = inet->inet_dport;
98448 /* Open fast path for connected socket.
98449 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
98450 IS_UDPLITE(sk));
98451 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98452 IS_UDPLITE(sk));
98453 - atomic_inc(&sk->sk_drops);
98454 + atomic_inc_unchecked(&sk->sk_drops);
98455 __skb_unlink(skb, rcvq);
98456 __skb_queue_tail(&list_kill, skb);
98457 }
98458 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98459 int is_udplite = IS_UDPLITE(sk);
98460 bool slow;
98461
98462 + /*
98463 + * Check any passed addresses
98464 + */
98465 + if (addr_len)
98466 + *addr_len = sizeof(*sin);
98467 +
98468 if (flags & MSG_ERRQUEUE)
98469 return ip_recv_error(sk, msg, len, addr_len);
98470
98471 @@ -1243,6 +1266,10 @@ try_again:
98472 if (!skb)
98473 goto out;
98474
98475 + err = gr_search_udp_recvmsg(sk, skb);
98476 + if (err)
98477 + goto out_free;
98478 +
98479 ulen = skb->len - sizeof(struct udphdr);
98480 copied = len;
98481 if (copied > ulen)
98482 @@ -1276,7 +1303,7 @@ try_again:
98483 if (unlikely(err)) {
98484 trace_kfree_skb(skb, udp_recvmsg);
98485 if (!peeked) {
98486 - atomic_inc(&sk->sk_drops);
98487 + atomic_inc_unchecked(&sk->sk_drops);
98488 UDP_INC_STATS_USER(sock_net(sk),
98489 UDP_MIB_INERRORS, is_udplite);
98490 }
98491 @@ -1295,7 +1322,6 @@ try_again:
98492 sin->sin_port = udp_hdr(skb)->source;
98493 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98494 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98495 - *addr_len = sizeof(*sin);
98496 }
98497 if (inet->cmsg_flags)
98498 ip_cmsg_recv(msg, skb);
98499 @@ -1566,7 +1592,7 @@ csum_error:
98500 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98501 drop:
98502 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98503 - atomic_inc(&sk->sk_drops);
98504 + atomic_inc_unchecked(&sk->sk_drops);
98505 kfree_skb(skb);
98506 return -1;
98507 }
98508 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98509 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98510
98511 if (!skb1) {
98512 - atomic_inc(&sk->sk_drops);
98513 + atomic_inc_unchecked(&sk->sk_drops);
98514 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98515 IS_UDPLITE(sk));
98516 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98517 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98518 goto csum_error;
98519
98520 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98521 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98522 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98523 +#endif
98524 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
98525
98526 /*
98527 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
98528 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98529 0, sock_i_ino(sp),
98530 atomic_read(&sp->sk_refcnt), sp,
98531 - atomic_read(&sp->sk_drops));
98532 + atomic_read_unchecked(&sp->sk_drops));
98533 }
98534
98535 int udp4_seq_show(struct seq_file *seq, void *v)
98536 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
98537 index e1a6393..f634ce5 100644
98538 --- a/net/ipv4/xfrm4_policy.c
98539 +++ b/net/ipv4/xfrm4_policy.c
98540 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
98541 fl4->flowi4_tos = iph->tos;
98542 }
98543
98544 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
98545 +static int xfrm4_garbage_collect(struct dst_ops *ops)
98546 {
98547 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
98548
98549 - xfrm4_policy_afinfo.garbage_collect(net);
98550 + xfrm_garbage_collect_deferred(net);
98551 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
98552 }
98553
98554 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
98555
98556 static int __net_init xfrm4_net_init(struct net *net)
98557 {
98558 - struct ctl_table *table;
98559 + ctl_table_no_const *table = NULL;
98560 struct ctl_table_header *hdr;
98561
98562 - table = xfrm4_policy_table;
98563 if (!net_eq(net, &init_net)) {
98564 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98565 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98566 if (!table)
98567 goto err_alloc;
98568
98569 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
98570 - }
98571 -
98572 - hdr = register_net_sysctl(net, "net/ipv4", table);
98573 + hdr = register_net_sysctl(net, "net/ipv4", table);
98574 + } else
98575 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
98576 if (!hdr)
98577 goto err_reg;
98578
98579 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
98580 return 0;
98581
98582 err_reg:
98583 - if (!net_eq(net, &init_net))
98584 - kfree(table);
98585 + kfree(table);
98586 err_alloc:
98587 return -ENOMEM;
98588 }
98589 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
98590 index 9c05d77..9cfa714 100644
98591 --- a/net/ipv6/addrconf.c
98592 +++ b/net/ipv6/addrconf.c
98593 @@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
98594 idx = 0;
98595 head = &net->dev_index_head[h];
98596 rcu_read_lock();
98597 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
98598 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
98599 net->dev_base_seq;
98600 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98601 if (idx < s_idx)
98602 @@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
98603 p.iph.ihl = 5;
98604 p.iph.protocol = IPPROTO_IPV6;
98605 p.iph.ttl = 64;
98606 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
98607 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
98608
98609 if (ops->ndo_do_ioctl) {
98610 mm_segment_t oldfs = get_fs();
98611 @@ -3964,7 +3964,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
98612 s_ip_idx = ip_idx = cb->args[2];
98613
98614 rcu_read_lock();
98615 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98616 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98617 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
98618 idx = 0;
98619 head = &net->dev_index_head[h];
98620 @@ -4571,7 +4571,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
98621 dst_free(&ifp->rt->dst);
98622 break;
98623 }
98624 - atomic_inc(&net->ipv6.dev_addr_genid);
98625 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
98626 rt_genid_bump_ipv6(net);
98627 }
98628
98629 @@ -4592,7 +4592,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
98630 int *valp = ctl->data;
98631 int val = *valp;
98632 loff_t pos = *ppos;
98633 - struct ctl_table lctl;
98634 + ctl_table_no_const lctl;
98635 int ret;
98636
98637 /*
98638 @@ -4677,7 +4677,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
98639 int *valp = ctl->data;
98640 int val = *valp;
98641 loff_t pos = *ppos;
98642 - struct ctl_table lctl;
98643 + ctl_table_no_const lctl;
98644 int ret;
98645
98646 /*
98647 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
98648 index 4fbdb70..f6411f2 100644
98649 --- a/net/ipv6/af_inet6.c
98650 +++ b/net/ipv6/af_inet6.c
98651 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
98652
98653 net->ipv6.sysctl.bindv6only = 0;
98654 net->ipv6.sysctl.icmpv6_time = 1*HZ;
98655 - atomic_set(&net->ipv6.rt_genid, 0);
98656 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
98657
98658 err = ipv6_init_mibs(net);
98659 if (err)
98660 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
98661 index 93b1aa3..e902855 100644
98662 --- a/net/ipv6/datagram.c
98663 +++ b/net/ipv6/datagram.c
98664 @@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
98665 0,
98666 sock_i_ino(sp),
98667 atomic_read(&sp->sk_refcnt), sp,
98668 - atomic_read(&sp->sk_drops));
98669 + atomic_read_unchecked(&sp->sk_drops));
98670 }
98671 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
98672 index eef8d94..cfa1852 100644
98673 --- a/net/ipv6/icmp.c
98674 +++ b/net/ipv6/icmp.c
98675 @@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
98676
98677 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
98678 {
98679 - struct ctl_table *table;
98680 + ctl_table_no_const *table;
98681
98682 table = kmemdup(ipv6_icmp_table_template,
98683 sizeof(ipv6_icmp_table_template),
98684 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
98685 index 8acb286..840dd06 100644
98686 --- a/net/ipv6/ip6_gre.c
98687 +++ b/net/ipv6/ip6_gre.c
98688 @@ -74,7 +74,7 @@ struct ip6gre_net {
98689 struct net_device *fb_tunnel_dev;
98690 };
98691
98692 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
98693 +static struct rtnl_link_ops ip6gre_link_ops;
98694 static int ip6gre_tunnel_init(struct net_device *dev);
98695 static void ip6gre_tunnel_setup(struct net_device *dev);
98696 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
98697 @@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
98698 }
98699
98700
98701 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
98702 +static struct inet6_protocol ip6gre_protocol = {
98703 .handler = ip6gre_rcv,
98704 .err_handler = ip6gre_err,
98705 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
98706 @@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
98707 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
98708 };
98709
98710 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98711 +static struct rtnl_link_ops ip6gre_link_ops = {
98712 .kind = "ip6gre",
98713 .maxtype = IFLA_GRE_MAX,
98714 .policy = ip6gre_policy,
98715 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98716 .fill_info = ip6gre_fill_info,
98717 };
98718
98719 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
98720 +static struct rtnl_link_ops ip6gre_tap_ops = {
98721 .kind = "ip6gretap",
98722 .maxtype = IFLA_GRE_MAX,
98723 .policy = ip6gre_policy,
98724 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
98725 index 7881965..9cf62c4 100644
98726 --- a/net/ipv6/ip6_tunnel.c
98727 +++ b/net/ipv6/ip6_tunnel.c
98728 @@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98729
98730 static int ip6_tnl_dev_init(struct net_device *dev);
98731 static void ip6_tnl_dev_setup(struct net_device *dev);
98732 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
98733 +static struct rtnl_link_ops ip6_link_ops;
98734
98735 static int ip6_tnl_net_id __read_mostly;
98736 struct ip6_tnl_net {
98737 @@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
98738 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
98739 };
98740
98741 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
98742 +static struct rtnl_link_ops ip6_link_ops = {
98743 .kind = "ip6tnl",
98744 .maxtype = IFLA_IPTUN_MAX,
98745 .policy = ip6_tnl_policy,
98746 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
98747 index 7b42d5e..1eff693 100644
98748 --- a/net/ipv6/ip6_vti.c
98749 +++ b/net/ipv6/ip6_vti.c
98750 @@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98751
98752 static int vti6_dev_init(struct net_device *dev);
98753 static void vti6_dev_setup(struct net_device *dev);
98754 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
98755 +static struct rtnl_link_ops vti6_link_ops;
98756
98757 static int vti6_net_id __read_mostly;
98758 struct vti6_net {
98759 @@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
98760 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
98761 };
98762
98763 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
98764 +static struct rtnl_link_ops vti6_link_ops = {
98765 .kind = "vti6",
98766 .maxtype = IFLA_VTI_MAX,
98767 .policy = vti6_policy,
98768 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
98769 index 1c6ce31..299e566 100644
98770 --- a/net/ipv6/ipv6_sockglue.c
98771 +++ b/net/ipv6/ipv6_sockglue.c
98772 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
98773 if (sk->sk_type != SOCK_STREAM)
98774 return -ENOPROTOOPT;
98775
98776 - msg.msg_control = optval;
98777 + msg.msg_control = (void __force_kernel *)optval;
98778 msg.msg_controllen = len;
98779 msg.msg_flags = flags;
98780
98781 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
98782 index 710238f..0fd1816 100644
98783 --- a/net/ipv6/netfilter/ip6_tables.c
98784 +++ b/net/ipv6/netfilter/ip6_tables.c
98785 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
98786 #endif
98787
98788 static int get_info(struct net *net, void __user *user,
98789 - const int *len, int compat)
98790 + int len, int compat)
98791 {
98792 char name[XT_TABLE_MAXNAMELEN];
98793 struct xt_table *t;
98794 int ret;
98795
98796 - if (*len != sizeof(struct ip6t_getinfo)) {
98797 - duprintf("length %u != %zu\n", *len,
98798 + if (len != sizeof(struct ip6t_getinfo)) {
98799 + duprintf("length %u != %zu\n", len,
98800 sizeof(struct ip6t_getinfo));
98801 return -EINVAL;
98802 }
98803 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
98804 info.size = private->size;
98805 strcpy(info.name, name);
98806
98807 - if (copy_to_user(user, &info, *len) != 0)
98808 + if (copy_to_user(user, &info, len) != 0)
98809 ret = -EFAULT;
98810 else
98811 ret = 0;
98812 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98813
98814 switch (cmd) {
98815 case IP6T_SO_GET_INFO:
98816 - ret = get_info(sock_net(sk), user, len, 1);
98817 + ret = get_info(sock_net(sk), user, *len, 1);
98818 break;
98819 case IP6T_SO_GET_ENTRIES:
98820 ret = compat_get_entries(sock_net(sk), user, len);
98821 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98822
98823 switch (cmd) {
98824 case IP6T_SO_GET_INFO:
98825 - ret = get_info(sock_net(sk), user, len, 0);
98826 + ret = get_info(sock_net(sk), user, *len, 0);
98827 break;
98828
98829 case IP6T_SO_GET_ENTRIES:
98830 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
98831 index 767ab8d..c5ec70a 100644
98832 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
98833 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
98834 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
98835
98836 static int nf_ct_frag6_sysctl_register(struct net *net)
98837 {
98838 - struct ctl_table *table;
98839 + ctl_table_no_const *table = NULL;
98840 struct ctl_table_header *hdr;
98841
98842 - table = nf_ct_frag6_sysctl_table;
98843 if (!net_eq(net, &init_net)) {
98844 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
98845 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
98846 GFP_KERNEL);
98847 if (table == NULL)
98848 goto err_alloc;
98849 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
98850 table[0].data = &net->nf_frag.frags.timeout;
98851 table[1].data = &net->nf_frag.frags.low_thresh;
98852 table[2].data = &net->nf_frag.frags.high_thresh;
98853 - }
98854 -
98855 - hdr = register_net_sysctl(net, "net/netfilter", table);
98856 + hdr = register_net_sysctl(net, "net/netfilter", table);
98857 + } else
98858 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
98859 if (hdr == NULL)
98860 goto err_reg;
98861
98862 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
98863 return 0;
98864
98865 err_reg:
98866 - if (!net_eq(net, &init_net))
98867 - kfree(table);
98868 + kfree(table);
98869 err_alloc:
98870 return -ENOMEM;
98871 }
98872 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
98873 index 827f795..7e28e82 100644
98874 --- a/net/ipv6/output_core.c
98875 +++ b/net/ipv6/output_core.c
98876 @@ -9,8 +9,8 @@
98877
98878 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
98879 {
98880 - static atomic_t ipv6_fragmentation_id;
98881 - int old, new;
98882 + static atomic_unchecked_t ipv6_fragmentation_id;
98883 + int id;
98884
98885 #if IS_ENABLED(CONFIG_IPV6)
98886 if (rt && !(rt->dst.flags & DST_NOPEER)) {
98887 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
98888 }
98889 }
98890 #endif
98891 - do {
98892 - old = atomic_read(&ipv6_fragmentation_id);
98893 - new = old + 1;
98894 - if (!new)
98895 - new = 1;
98896 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
98897 - fhdr->identification = htonl(new);
98898 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
98899 + if (!id)
98900 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
98901 + fhdr->identification = htonl(id);
98902 }
98903 EXPORT_SYMBOL(ipv6_select_ident);
98904
98905 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
98906 index a83243c..a1ca589 100644
98907 --- a/net/ipv6/ping.c
98908 +++ b/net/ipv6/ping.c
98909 @@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
98910 };
98911 #endif
98912
98913 +static struct pingv6_ops real_pingv6_ops = {
98914 + .ipv6_recv_error = ipv6_recv_error,
98915 + .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
98916 + .icmpv6_err_convert = icmpv6_err_convert,
98917 + .ipv6_icmp_error = ipv6_icmp_error,
98918 + .ipv6_chk_addr = ipv6_chk_addr,
98919 +};
98920 +
98921 +static struct pingv6_ops dummy_pingv6_ops = {
98922 + .ipv6_recv_error = dummy_ipv6_recv_error,
98923 + .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
98924 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
98925 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
98926 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
98927 +};
98928 +
98929 int __init pingv6_init(void)
98930 {
98931 #ifdef CONFIG_PROC_FS
98932 @@ -253,11 +269,7 @@ int __init pingv6_init(void)
98933 if (ret)
98934 return ret;
98935 #endif
98936 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
98937 - pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
98938 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
98939 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
98940 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
98941 + pingv6_ops = &real_pingv6_ops;
98942 return inet6_register_protosw(&pingv6_protosw);
98943 }
98944
98945 @@ -266,11 +278,7 @@ int __init pingv6_init(void)
98946 */
98947 void pingv6_exit(void)
98948 {
98949 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
98950 - pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
98951 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
98952 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
98953 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
98954 + pingv6_ops = &dummy_pingv6_ops;
98955 #ifdef CONFIG_PROC_FS
98956 unregister_pernet_subsys(&ping_v6_net_ops);
98957 #endif
98958 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
98959 index b6bb87e..06cc9ed 100644
98960 --- a/net/ipv6/raw.c
98961 +++ b/net/ipv6/raw.c
98962 @@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
98963 {
98964 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
98965 skb_checksum_complete(skb)) {
98966 - atomic_inc(&sk->sk_drops);
98967 + atomic_inc_unchecked(&sk->sk_drops);
98968 kfree_skb(skb);
98969 return NET_RX_DROP;
98970 }
98971 @@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98972 struct raw6_sock *rp = raw6_sk(sk);
98973
98974 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
98975 - atomic_inc(&sk->sk_drops);
98976 + atomic_inc_unchecked(&sk->sk_drops);
98977 kfree_skb(skb);
98978 return NET_RX_DROP;
98979 }
98980 @@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98981
98982 if (inet->hdrincl) {
98983 if (skb_checksum_complete(skb)) {
98984 - atomic_inc(&sk->sk_drops);
98985 + atomic_inc_unchecked(&sk->sk_drops);
98986 kfree_skb(skb);
98987 return NET_RX_DROP;
98988 }
98989 @@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98990 if (flags & MSG_OOB)
98991 return -EOPNOTSUPP;
98992
98993 + if (addr_len)
98994 + *addr_len=sizeof(*sin6);
98995 +
98996 if (flags & MSG_ERRQUEUE)
98997 return ipv6_recv_error(sk, msg, len, addr_len);
98998
98999 @@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99000 sin6->sin6_flowinfo = 0;
99001 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99002 IP6CB(skb)->iif);
99003 - *addr_len = sizeof(*sin6);
99004 }
99005
99006 sock_recv_ts_and_drops(msg, sk, skb);
99007 @@ -606,7 +608,7 @@ out:
99008 return err;
99009 }
99010
99011 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99012 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99013 struct flowi6 *fl6, struct dst_entry **dstp,
99014 unsigned int flags)
99015 {
99016 @@ -918,12 +920,15 @@ do_confirm:
99017 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99018 char __user *optval, int optlen)
99019 {
99020 + struct icmp6_filter filter;
99021 +
99022 switch (optname) {
99023 case ICMPV6_FILTER:
99024 if (optlen > sizeof(struct icmp6_filter))
99025 optlen = sizeof(struct icmp6_filter);
99026 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99027 + if (copy_from_user(&filter, optval, optlen))
99028 return -EFAULT;
99029 + raw6_sk(sk)->filter = filter;
99030 return 0;
99031 default:
99032 return -ENOPROTOOPT;
99033 @@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99034 char __user *optval, int __user *optlen)
99035 {
99036 int len;
99037 + struct icmp6_filter filter;
99038
99039 switch (optname) {
99040 case ICMPV6_FILTER:
99041 @@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99042 len = sizeof(struct icmp6_filter);
99043 if (put_user(len, optlen))
99044 return -EFAULT;
99045 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99046 + filter = raw6_sk(sk)->filter;
99047 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
99048 return -EFAULT;
99049 return 0;
99050 default:
99051 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99052 index cc85a9b..526a133 100644
99053 --- a/net/ipv6/reassembly.c
99054 +++ b/net/ipv6/reassembly.c
99055 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99056
99057 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99058 {
99059 - struct ctl_table *table;
99060 + ctl_table_no_const *table = NULL;
99061 struct ctl_table_header *hdr;
99062
99063 - table = ip6_frags_ns_ctl_table;
99064 if (!net_eq(net, &init_net)) {
99065 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99066 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99067 if (table == NULL)
99068 goto err_alloc;
99069
99070 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99071 /* Don't export sysctls to unprivileged users */
99072 if (net->user_ns != &init_user_ns)
99073 table[0].procname = NULL;
99074 - }
99075 + hdr = register_net_sysctl(net, "net/ipv6", table);
99076 + } else
99077 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99078
99079 - hdr = register_net_sysctl(net, "net/ipv6", table);
99080 if (hdr == NULL)
99081 goto err_reg;
99082
99083 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99084 return 0;
99085
99086 err_reg:
99087 - if (!net_eq(net, &init_net))
99088 - kfree(table);
99089 + kfree(table);
99090 err_alloc:
99091 return -ENOMEM;
99092 }
99093 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99094 index 4b4944c..d346b14 100644
99095 --- a/net/ipv6/route.c
99096 +++ b/net/ipv6/route.c
99097 @@ -1495,7 +1495,7 @@ int ip6_route_add(struct fib6_config *cfg)
99098 if (!table)
99099 goto out;
99100
99101 - rt = ip6_dst_alloc(net, NULL, DST_NOCOUNT, table);
99102 + rt = ip6_dst_alloc(net, NULL, (cfg->fc_flags & RTF_ADDRCONF) ? 0 : DST_NOCOUNT, table);
99103
99104 if (!rt) {
99105 err = -ENOMEM;
99106 @@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
99107
99108 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99109 {
99110 - struct ctl_table *table;
99111 + ctl_table_no_const *table;
99112
99113 table = kmemdup(ipv6_route_table_template,
99114 sizeof(ipv6_route_table_template),
99115 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99116 index d3005b3..b36df4a 100644
99117 --- a/net/ipv6/sit.c
99118 +++ b/net/ipv6/sit.c
99119 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99120 static void ipip6_dev_free(struct net_device *dev);
99121 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99122 __be32 *v4dst);
99123 -static struct rtnl_link_ops sit_link_ops __read_mostly;
99124 +static struct rtnl_link_ops sit_link_ops;
99125
99126 static int sit_net_id __read_mostly;
99127 struct sit_net {
99128 @@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99129 unregister_netdevice_queue(dev, head);
99130 }
99131
99132 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
99133 +static struct rtnl_link_ops sit_link_ops = {
99134 .kind = "sit",
99135 .maxtype = IFLA_IPTUN_MAX,
99136 .policy = ipip6_policy,
99137 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99138 index 107b2f1..72741a9 100644
99139 --- a/net/ipv6/sysctl_net_ipv6.c
99140 +++ b/net/ipv6/sysctl_net_ipv6.c
99141 @@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
99142
99143 static int __net_init ipv6_sysctl_net_init(struct net *net)
99144 {
99145 - struct ctl_table *ipv6_table;
99146 + ctl_table_no_const *ipv6_table;
99147 struct ctl_table *ipv6_route_table;
99148 struct ctl_table *ipv6_icmp_table;
99149 int err;
99150 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99151 index f67033b..6f974fc 100644
99152 --- a/net/ipv6/tcp_ipv6.c
99153 +++ b/net/ipv6/tcp_ipv6.c
99154 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99155 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99156 }
99157
99158 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99159 +extern int grsec_enable_blackhole;
99160 +#endif
99161 +
99162 static void tcp_v6_hash(struct sock *sk)
99163 {
99164 if (sk->sk_state != TCP_CLOSE) {
99165 @@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99166 return 0;
99167
99168 reset:
99169 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99170 + if (!grsec_enable_blackhole)
99171 +#endif
99172 tcp_v6_send_reset(sk, skb);
99173 discard:
99174 if (opt_skb)
99175 @@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99176 TCP_SKB_CB(skb)->sacked = 0;
99177
99178 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99179 - if (!sk)
99180 + if (!sk) {
99181 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99182 + ret = 1;
99183 +#endif
99184 goto no_tcp_socket;
99185 + }
99186
99187 process:
99188 - if (sk->sk_state == TCP_TIME_WAIT)
99189 + if (sk->sk_state == TCP_TIME_WAIT) {
99190 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99191 + ret = 2;
99192 +#endif
99193 goto do_time_wait;
99194 + }
99195
99196 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99197 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99198 @@ -1536,6 +1551,10 @@ csum_error:
99199 bad_packet:
99200 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99201 } else {
99202 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99203 + if (!grsec_enable_blackhole || (ret == 1 &&
99204 + (skb->dev->flags & IFF_LOOPBACK)))
99205 +#endif
99206 tcp_v6_send_reset(NULL, skb);
99207 }
99208
99209 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99210 index 089c741..cfee117 100644
99211 --- a/net/ipv6/udp.c
99212 +++ b/net/ipv6/udp.c
99213 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99214 udp_ipv6_hash_secret + net_hash_mix(net));
99215 }
99216
99217 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99218 +extern int grsec_enable_blackhole;
99219 +#endif
99220 +
99221 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
99222 {
99223 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
99224 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99225 int is_udp4;
99226 bool slow;
99227
99228 + if (addr_len)
99229 + *addr_len = sizeof(struct sockaddr_in6);
99230 +
99231 if (flags & MSG_ERRQUEUE)
99232 return ipv6_recv_error(sk, msg, len, addr_len);
99233
99234 @@ -435,7 +442,7 @@ try_again:
99235 if (unlikely(err)) {
99236 trace_kfree_skb(skb, udpv6_recvmsg);
99237 if (!peeked) {
99238 - atomic_inc(&sk->sk_drops);
99239 + atomic_inc_unchecked(&sk->sk_drops);
99240 if (is_udp4)
99241 UDP_INC_STATS_USER(sock_net(sk),
99242 UDP_MIB_INERRORS,
99243 @@ -477,7 +484,7 @@ try_again:
99244 ipv6_iface_scope_id(&sin6->sin6_addr,
99245 IP6CB(skb)->iif);
99246 }
99247 - *addr_len = sizeof(*sin6);
99248 +
99249 }
99250 if (is_udp4) {
99251 if (inet->cmsg_flags)
99252 @@ -685,7 +692,7 @@ csum_error:
99253 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99254 drop:
99255 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99256 - atomic_inc(&sk->sk_drops);
99257 + atomic_inc_unchecked(&sk->sk_drops);
99258 kfree_skb(skb);
99259 return -1;
99260 }
99261 @@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99262 if (likely(skb1 == NULL))
99263 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99264 if (!skb1) {
99265 - atomic_inc(&sk->sk_drops);
99266 + atomic_inc_unchecked(&sk->sk_drops);
99267 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99268 IS_UDPLITE(sk));
99269 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99270 @@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99271 goto csum_error;
99272
99273 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99274 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99275 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99276 +#endif
99277 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
99278
99279 kfree_skb(skb);
99280 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
99281 index 5f8e128..865d38e 100644
99282 --- a/net/ipv6/xfrm6_policy.c
99283 +++ b/net/ipv6/xfrm6_policy.c
99284 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
99285 }
99286 }
99287
99288 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
99289 +static int xfrm6_garbage_collect(struct dst_ops *ops)
99290 {
99291 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
99292
99293 - xfrm6_policy_afinfo.garbage_collect(net);
99294 + xfrm_garbage_collect_deferred(net);
99295 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
99296 }
99297
99298 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
99299
99300 static int __net_init xfrm6_net_init(struct net *net)
99301 {
99302 - struct ctl_table *table;
99303 + ctl_table_no_const *table = NULL;
99304 struct ctl_table_header *hdr;
99305
99306 - table = xfrm6_policy_table;
99307 if (!net_eq(net, &init_net)) {
99308 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99309 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99310 if (!table)
99311 goto err_alloc;
99312
99313 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
99314 - }
99315 + hdr = register_net_sysctl(net, "net/ipv6", table);
99316 + } else
99317 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
99318
99319 - hdr = register_net_sysctl(net, "net/ipv6", table);
99320 if (!hdr)
99321 goto err_reg;
99322
99323 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
99324 return 0;
99325
99326 err_reg:
99327 - if (!net_eq(net, &init_net))
99328 - kfree(table);
99329 + kfree(table);
99330 err_alloc:
99331 return -ENOMEM;
99332 }
99333 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
99334 index 41ac7938..75e3bb1 100644
99335 --- a/net/irda/ircomm/ircomm_tty.c
99336 +++ b/net/irda/ircomm/ircomm_tty.c
99337 @@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99338 add_wait_queue(&port->open_wait, &wait);
99339
99340 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
99341 - __FILE__, __LINE__, tty->driver->name, port->count);
99342 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99343
99344 spin_lock_irqsave(&port->lock, flags);
99345 if (!tty_hung_up_p(filp))
99346 - port->count--;
99347 + atomic_dec(&port->count);
99348 port->blocked_open++;
99349 spin_unlock_irqrestore(&port->lock, flags);
99350
99351 @@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99352 }
99353
99354 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
99355 - __FILE__, __LINE__, tty->driver->name, port->count);
99356 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99357
99358 schedule();
99359 }
99360 @@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99361
99362 spin_lock_irqsave(&port->lock, flags);
99363 if (!tty_hung_up_p(filp))
99364 - port->count++;
99365 + atomic_inc(&port->count);
99366 port->blocked_open--;
99367 spin_unlock_irqrestore(&port->lock, flags);
99368
99369 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
99370 - __FILE__, __LINE__, tty->driver->name, port->count);
99371 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99372
99373 if (!retval)
99374 port->flags |= ASYNC_NORMAL_ACTIVE;
99375 @@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
99376
99377 /* ++ is not atomic, so this should be protected - Jean II */
99378 spin_lock_irqsave(&self->port.lock, flags);
99379 - self->port.count++;
99380 + atomic_inc(&self->port.count);
99381 spin_unlock_irqrestore(&self->port.lock, flags);
99382 tty_port_tty_set(&self->port, tty);
99383
99384 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
99385 - self->line, self->port.count);
99386 + self->line, atomic_read(&self->port.count));
99387
99388 /* Not really used by us, but lets do it anyway */
99389 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
99390 @@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
99391 tty_kref_put(port->tty);
99392 }
99393 port->tty = NULL;
99394 - port->count = 0;
99395 + atomic_set(&port->count, 0);
99396 spin_unlock_irqrestore(&port->lock, flags);
99397
99398 wake_up_interruptible(&port->open_wait);
99399 @@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
99400 seq_putc(m, '\n');
99401
99402 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
99403 - seq_printf(m, "Open count: %d\n", self->port.count);
99404 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
99405 seq_printf(m, "Max data size: %d\n", self->max_data_size);
99406 seq_printf(m, "Max header size: %d\n", self->max_header_size);
99407
99408 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
99409 index c4b7218..3e83259 100644
99410 --- a/net/iucv/af_iucv.c
99411 +++ b/net/iucv/af_iucv.c
99412 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
99413
99414 write_lock_bh(&iucv_sk_list.lock);
99415
99416 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
99417 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99418 while (__iucv_get_sock_by_name(name)) {
99419 sprintf(name, "%08x",
99420 - atomic_inc_return(&iucv_sk_list.autobind_name));
99421 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99422 }
99423
99424 write_unlock_bh(&iucv_sk_list.lock);
99425 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
99426 index cd5b8ec..f205e6b 100644
99427 --- a/net/iucv/iucv.c
99428 +++ b/net/iucv/iucv.c
99429 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
99430 return NOTIFY_OK;
99431 }
99432
99433 -static struct notifier_block __refdata iucv_cpu_notifier = {
99434 +static struct notifier_block iucv_cpu_notifier = {
99435 .notifier_call = iucv_cpu_notify,
99436 };
99437
99438 diff --git a/net/key/af_key.c b/net/key/af_key.c
99439 index 545f047..9757a9d 100644
99440 --- a/net/key/af_key.c
99441 +++ b/net/key/af_key.c
99442 @@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
99443 static u32 get_acqseq(void)
99444 {
99445 u32 res;
99446 - static atomic_t acqseq;
99447 + static atomic_unchecked_t acqseq;
99448
99449 do {
99450 - res = atomic_inc_return(&acqseq);
99451 + res = atomic_inc_return_unchecked(&acqseq);
99452 } while (!res);
99453 return res;
99454 }
99455 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
99456 index da1a1ce..571db8d 100644
99457 --- a/net/l2tp/l2tp_ip.c
99458 +++ b/net/l2tp/l2tp_ip.c
99459 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99460 if (flags & MSG_OOB)
99461 goto out;
99462
99463 + if (addr_len)
99464 + *addr_len = sizeof(*sin);
99465 +
99466 skb = skb_recv_datagram(sk, flags, noblock, &err);
99467 if (!skb)
99468 goto out;
99469 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99470 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99471 sin->sin_port = 0;
99472 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99473 - *addr_len = sizeof(*sin);
99474 }
99475 if (inet->cmsg_flags)
99476 ip_cmsg_recv(msg, skb);
99477 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
99478 index b4b61b2..ac84a257 100644
99479 --- a/net/mac80211/cfg.c
99480 +++ b/net/mac80211/cfg.c
99481 @@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
99482 ret = ieee80211_vif_use_channel(sdata, chandef,
99483 IEEE80211_CHANCTX_EXCLUSIVE);
99484 }
99485 - } else if (local->open_count == local->monitors) {
99486 + } else if (local_read(&local->open_count) == local->monitors) {
99487 local->_oper_chandef = *chandef;
99488 ieee80211_hw_config(local, 0);
99489 }
99490 @@ -3311,7 +3311,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
99491 else
99492 local->probe_req_reg--;
99493
99494 - if (!local->open_count)
99495 + if (!local_read(&local->open_count))
99496 break;
99497
99498 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
99499 @@ -3774,8 +3774,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
99500 if (chanctx_conf) {
99501 *chandef = chanctx_conf->def;
99502 ret = 0;
99503 - } else if (local->open_count > 0 &&
99504 - local->open_count == local->monitors &&
99505 + } else if (local_read(&local->open_count) > 0 &&
99506 + local_read(&local->open_count) == local->monitors &&
99507 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
99508 if (local->use_chanctx)
99509 *chandef = local->monitor_chandef;
99510 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
99511 index 4aea4e7..9e698d1 100644
99512 --- a/net/mac80211/ieee80211_i.h
99513 +++ b/net/mac80211/ieee80211_i.h
99514 @@ -28,6 +28,7 @@
99515 #include <net/ieee80211_radiotap.h>
99516 #include <net/cfg80211.h>
99517 #include <net/mac80211.h>
99518 +#include <asm/local.h>
99519 #include "key.h"
99520 #include "sta_info.h"
99521 #include "debug.h"
99522 @@ -961,7 +962,7 @@ struct ieee80211_local {
99523 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
99524 spinlock_t queue_stop_reason_lock;
99525
99526 - int open_count;
99527 + local_t open_count;
99528 int monitors, cooked_mntrs;
99529 /* number of interfaces with corresponding FIF_ flags */
99530 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
99531 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
99532 index a075791..1d0027f 100644
99533 --- a/net/mac80211/iface.c
99534 +++ b/net/mac80211/iface.c
99535 @@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99536 break;
99537 }
99538
99539 - if (local->open_count == 0) {
99540 + if (local_read(&local->open_count) == 0) {
99541 res = drv_start(local);
99542 if (res)
99543 goto err_del_bss;
99544 @@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99545 res = drv_add_interface(local, sdata);
99546 if (res)
99547 goto err_stop;
99548 - } else if (local->monitors == 0 && local->open_count == 0) {
99549 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
99550 res = ieee80211_add_virtual_monitor(local);
99551 if (res)
99552 goto err_stop;
99553 @@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99554 atomic_inc(&local->iff_promiscs);
99555
99556 if (coming_up)
99557 - local->open_count++;
99558 + local_inc(&local->open_count);
99559
99560 if (hw_reconf_flags)
99561 ieee80211_hw_config(local, hw_reconf_flags);
99562 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99563 err_del_interface:
99564 drv_remove_interface(local, sdata);
99565 err_stop:
99566 - if (!local->open_count)
99567 + if (!local_read(&local->open_count))
99568 drv_stop(local);
99569 err_del_bss:
99570 sdata->bss = NULL;
99571 @@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99572 }
99573
99574 if (going_down)
99575 - local->open_count--;
99576 + local_dec(&local->open_count);
99577
99578 switch (sdata->vif.type) {
99579 case NL80211_IFTYPE_AP_VLAN:
99580 @@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99581 }
99582 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
99583
99584 - if (local->open_count == 0)
99585 + if (local_read(&local->open_count) == 0)
99586 ieee80211_clear_tx_pending(local);
99587
99588 /*
99589 @@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99590
99591 ieee80211_recalc_ps(local, -1);
99592
99593 - if (local->open_count == 0) {
99594 + if (local_read(&local->open_count) == 0) {
99595 ieee80211_stop_device(local);
99596
99597 /* no reconfiguring after stop! */
99598 @@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99599 ieee80211_configure_filter(local);
99600 ieee80211_hw_config(local, hw_reconf_flags);
99601
99602 - if (local->monitors == local->open_count)
99603 + if (local->monitors == local_read(&local->open_count))
99604 ieee80211_add_virtual_monitor(local);
99605 }
99606
99607 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
99608 index 7d1c3ac..b62dd29 100644
99609 --- a/net/mac80211/main.c
99610 +++ b/net/mac80211/main.c
99611 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
99612 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
99613 IEEE80211_CONF_CHANGE_POWER);
99614
99615 - if (changed && local->open_count) {
99616 + if (changed && local_read(&local->open_count)) {
99617 ret = drv_config(local, changed);
99618 /*
99619 * Goal:
99620 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
99621 index 3401262..d5cd68d 100644
99622 --- a/net/mac80211/pm.c
99623 +++ b/net/mac80211/pm.c
99624 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99625 struct ieee80211_sub_if_data *sdata;
99626 struct sta_info *sta;
99627
99628 - if (!local->open_count)
99629 + if (!local_read(&local->open_count))
99630 goto suspend;
99631
99632 ieee80211_scan_cancel(local);
99633 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99634 cancel_work_sync(&local->dynamic_ps_enable_work);
99635 del_timer_sync(&local->dynamic_ps_timer);
99636
99637 - local->wowlan = wowlan && local->open_count;
99638 + local->wowlan = wowlan && local_read(&local->open_count);
99639 if (local->wowlan) {
99640 int err = drv_suspend(local, wowlan);
99641 if (err < 0) {
99642 @@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99643 WARN_ON(!list_empty(&local->chanctx_list));
99644
99645 /* stop hardware - this must stop RX */
99646 - if (local->open_count)
99647 + if (local_read(&local->open_count))
99648 ieee80211_stop_device(local);
99649
99650 suspend:
99651 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
99652 index 22b223f..ab70070 100644
99653 --- a/net/mac80211/rate.c
99654 +++ b/net/mac80211/rate.c
99655 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
99656
99657 ASSERT_RTNL();
99658
99659 - if (local->open_count)
99660 + if (local_read(&local->open_count))
99661 return -EBUSY;
99662
99663 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
99664 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
99665 index 6ff1346..936ca9a 100644
99666 --- a/net/mac80211/rc80211_pid_debugfs.c
99667 +++ b/net/mac80211/rc80211_pid_debugfs.c
99668 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
99669
99670 spin_unlock_irqrestore(&events->lock, status);
99671
99672 - if (copy_to_user(buf, pb, p))
99673 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
99674 return -EFAULT;
99675
99676 return p;
99677 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
99678 index 9f9b9bd..d6fcf59 100644
99679 --- a/net/mac80211/util.c
99680 +++ b/net/mac80211/util.c
99681 @@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99682 }
99683 #endif
99684 /* everything else happens only if HW was up & running */
99685 - if (!local->open_count)
99686 + if (!local_read(&local->open_count))
99687 goto wake_up;
99688
99689 /*
99690 @@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99691 local->in_reconfig = false;
99692 barrier();
99693
99694 - if (local->monitors == local->open_count && local->monitors > 0)
99695 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
99696 ieee80211_add_virtual_monitor(local);
99697
99698 /*
99699 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
99700 index c3398cd..98ad3b4 100644
99701 --- a/net/netfilter/Kconfig
99702 +++ b/net/netfilter/Kconfig
99703 @@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
99704
99705 To compile it as a module, choose M here. If unsure, say N.
99706
99707 +config NETFILTER_XT_MATCH_GRADM
99708 + tristate '"gradm" match support'
99709 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
99710 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
99711 + ---help---
99712 + The gradm match allows to match on grsecurity RBAC being enabled.
99713 + It is useful when iptables rules are applied early on bootup to
99714 + prevent connections to the machine (except from a trusted host)
99715 + while the RBAC system is disabled.
99716 +
99717 config NETFILTER_XT_MATCH_HASHLIMIT
99718 tristate '"hashlimit" match support'
99719 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
99720 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
99721 index 394483b..ed51f2d 100644
99722 --- a/net/netfilter/Makefile
99723 +++ b/net/netfilter/Makefile
99724 @@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
99725 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
99726 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
99727 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
99728 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
99729 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
99730 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
99731 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
99732 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
99733 index bac7e01..1d7a31a 100644
99734 --- a/net/netfilter/ipset/ip_set_core.c
99735 +++ b/net/netfilter/ipset/ip_set_core.c
99736 @@ -1950,7 +1950,7 @@ done:
99737 return ret;
99738 }
99739
99740 -static struct nf_sockopt_ops so_set __read_mostly = {
99741 +static struct nf_sockopt_ops so_set = {
99742 .pf = PF_INET,
99743 .get_optmin = SO_IP_SET,
99744 .get_optmax = SO_IP_SET + 1,
99745 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
99746 index 4c8e5c0..5a79b4d 100644
99747 --- a/net/netfilter/ipvs/ip_vs_conn.c
99748 +++ b/net/netfilter/ipvs/ip_vs_conn.c
99749 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
99750 /* Increase the refcnt counter of the dest */
99751 ip_vs_dest_hold(dest);
99752
99753 - conn_flags = atomic_read(&dest->conn_flags);
99754 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
99755 if (cp->protocol != IPPROTO_UDP)
99756 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
99757 flags = cp->flags;
99758 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
99759
99760 cp->control = NULL;
99761 atomic_set(&cp->n_control, 0);
99762 - atomic_set(&cp->in_pkts, 0);
99763 + atomic_set_unchecked(&cp->in_pkts, 0);
99764
99765 cp->packet_xmit = NULL;
99766 cp->app = NULL;
99767 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
99768
99769 /* Don't drop the entry if its number of incoming packets is not
99770 located in [0, 8] */
99771 - i = atomic_read(&cp->in_pkts);
99772 + i = atomic_read_unchecked(&cp->in_pkts);
99773 if (i > 8 || i < 0) return 0;
99774
99775 if (!todrop_rate[i]) return 0;
99776 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
99777 index 4f26ee4..6a9d7c3 100644
99778 --- a/net/netfilter/ipvs/ip_vs_core.c
99779 +++ b/net/netfilter/ipvs/ip_vs_core.c
99780 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
99781 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
99782 /* do not touch skb anymore */
99783
99784 - atomic_inc(&cp->in_pkts);
99785 + atomic_inc_unchecked(&cp->in_pkts);
99786 ip_vs_conn_put(cp);
99787 return ret;
99788 }
99789 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
99790 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
99791 pkts = sysctl_sync_threshold(ipvs);
99792 else
99793 - pkts = atomic_add_return(1, &cp->in_pkts);
99794 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
99795
99796 if (ipvs->sync_state & IP_VS_STATE_MASTER)
99797 ip_vs_sync_conn(net, cp, pkts);
99798 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
99799 index 35be035..50f8834 100644
99800 --- a/net/netfilter/ipvs/ip_vs_ctl.c
99801 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
99802 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
99803 */
99804 ip_vs_rs_hash(ipvs, dest);
99805 }
99806 - atomic_set(&dest->conn_flags, conn_flags);
99807 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
99808
99809 /* bind the service */
99810 old_svc = rcu_dereference_protected(dest->svc, 1);
99811 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
99812 * align with netns init in ip_vs_control_net_init()
99813 */
99814
99815 -static struct ctl_table vs_vars[] = {
99816 +static ctl_table_no_const vs_vars[] __read_only = {
99817 {
99818 .procname = "amemthresh",
99819 .maxlen = sizeof(int),
99820 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
99821 " %-7s %-6d %-10d %-10d\n",
99822 &dest->addr.in6,
99823 ntohs(dest->port),
99824 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
99825 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
99826 atomic_read(&dest->weight),
99827 atomic_read(&dest->activeconns),
99828 atomic_read(&dest->inactconns));
99829 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
99830 "%-7s %-6d %-10d %-10d\n",
99831 ntohl(dest->addr.ip),
99832 ntohs(dest->port),
99833 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
99834 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
99835 atomic_read(&dest->weight),
99836 atomic_read(&dest->activeconns),
99837 atomic_read(&dest->inactconns));
99838 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
99839
99840 entry.addr = dest->addr.ip;
99841 entry.port = dest->port;
99842 - entry.conn_flags = atomic_read(&dest->conn_flags);
99843 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
99844 entry.weight = atomic_read(&dest->weight);
99845 entry.u_threshold = dest->u_threshold;
99846 entry.l_threshold = dest->l_threshold;
99847 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
99848 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
99849 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
99850 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
99851 - (atomic_read(&dest->conn_flags) &
99852 + (atomic_read_unchecked(&dest->conn_flags) &
99853 IP_VS_CONN_F_FWD_MASK)) ||
99854 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
99855 atomic_read(&dest->weight)) ||
99856 @@ -3580,7 +3580,7 @@ out:
99857 }
99858
99859
99860 -static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
99861 +static const struct genl_ops ip_vs_genl_ops[] = {
99862 {
99863 .cmd = IPVS_CMD_NEW_SERVICE,
99864 .flags = GENL_ADMIN_PERM,
99865 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
99866 {
99867 int idx;
99868 struct netns_ipvs *ipvs = net_ipvs(net);
99869 - struct ctl_table *tbl;
99870 + ctl_table_no_const *tbl;
99871
99872 atomic_set(&ipvs->dropentry, 0);
99873 spin_lock_init(&ipvs->dropentry_lock);
99874 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
99875 index ca056a3..9cf01ef 100644
99876 --- a/net/netfilter/ipvs/ip_vs_lblc.c
99877 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
99878 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
99879 * IPVS LBLC sysctl table
99880 */
99881 #ifdef CONFIG_SYSCTL
99882 -static struct ctl_table vs_vars_table[] = {
99883 +static ctl_table_no_const vs_vars_table[] __read_only = {
99884 {
99885 .procname = "lblc_expiration",
99886 .data = NULL,
99887 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
99888 index 3f21a2f..a112e85 100644
99889 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
99890 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
99891 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
99892 * IPVS LBLCR sysctl table
99893 */
99894
99895 -static struct ctl_table vs_vars_table[] = {
99896 +static ctl_table_no_const vs_vars_table[] __read_only = {
99897 {
99898 .procname = "lblcr_expiration",
99899 .data = NULL,
99900 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
99901 index f63c238..1b87f8a 100644
99902 --- a/net/netfilter/ipvs/ip_vs_sync.c
99903 +++ b/net/netfilter/ipvs/ip_vs_sync.c
99904 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
99905 cp = cp->control;
99906 if (cp) {
99907 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
99908 - pkts = atomic_add_return(1, &cp->in_pkts);
99909 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
99910 else
99911 pkts = sysctl_sync_threshold(ipvs);
99912 ip_vs_sync_conn(net, cp->control, pkts);
99913 @@ -771,7 +771,7 @@ control:
99914 if (!cp)
99915 return;
99916 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
99917 - pkts = atomic_add_return(1, &cp->in_pkts);
99918 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
99919 else
99920 pkts = sysctl_sync_threshold(ipvs);
99921 goto sloop;
99922 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
99923
99924 if (opt)
99925 memcpy(&cp->in_seq, opt, sizeof(*opt));
99926 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
99927 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
99928 cp->state = state;
99929 cp->old_state = cp->state;
99930 /*
99931 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
99932 index c47444e..b0961c6 100644
99933 --- a/net/netfilter/ipvs/ip_vs_xmit.c
99934 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
99935 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
99936 else
99937 rc = NF_ACCEPT;
99938 /* do not touch skb anymore */
99939 - atomic_inc(&cp->in_pkts);
99940 + atomic_inc_unchecked(&cp->in_pkts);
99941 goto out;
99942 }
99943
99944 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
99945 else
99946 rc = NF_ACCEPT;
99947 /* do not touch skb anymore */
99948 - atomic_inc(&cp->in_pkts);
99949 + atomic_inc_unchecked(&cp->in_pkts);
99950 goto out;
99951 }
99952
99953 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
99954 index a4b5e2a..13b1de3 100644
99955 --- a/net/netfilter/nf_conntrack_acct.c
99956 +++ b/net/netfilter/nf_conntrack_acct.c
99957 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
99958 #ifdef CONFIG_SYSCTL
99959 static int nf_conntrack_acct_init_sysctl(struct net *net)
99960 {
99961 - struct ctl_table *table;
99962 + ctl_table_no_const *table;
99963
99964 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
99965 GFP_KERNEL);
99966 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
99967 index 43549eb..0bbeace 100644
99968 --- a/net/netfilter/nf_conntrack_core.c
99969 +++ b/net/netfilter/nf_conntrack_core.c
99970 @@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
99971 #define DYING_NULLS_VAL ((1<<30)+1)
99972 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
99973
99974 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99975 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
99976 +#endif
99977 +
99978 int nf_conntrack_init_net(struct net *net)
99979 {
99980 int ret;
99981 @@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
99982 goto err_stat;
99983 }
99984
99985 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99986 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
99987 +#else
99988 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
99989 +#endif
99990 if (!net->ct.slabname) {
99991 ret = -ENOMEM;
99992 goto err_slabname;
99993 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
99994 index 1df1761..ce8b88a 100644
99995 --- a/net/netfilter/nf_conntrack_ecache.c
99996 +++ b/net/netfilter/nf_conntrack_ecache.c
99997 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
99998 #ifdef CONFIG_SYSCTL
99999 static int nf_conntrack_event_init_sysctl(struct net *net)
100000 {
100001 - struct ctl_table *table;
100002 + ctl_table_no_const *table;
100003
100004 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100005 GFP_KERNEL);
100006 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100007 index 974a2a4..52cc6ff 100644
100008 --- a/net/netfilter/nf_conntrack_helper.c
100009 +++ b/net/netfilter/nf_conntrack_helper.c
100010 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100011
100012 static int nf_conntrack_helper_init_sysctl(struct net *net)
100013 {
100014 - struct ctl_table *table;
100015 + ctl_table_no_const *table;
100016
100017 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100018 GFP_KERNEL);
100019 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100020 index ce30041..3861b5d 100644
100021 --- a/net/netfilter/nf_conntrack_proto.c
100022 +++ b/net/netfilter/nf_conntrack_proto.c
100023 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100024
100025 static void
100026 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100027 - struct ctl_table **table,
100028 + ctl_table_no_const **table,
100029 unsigned int users)
100030 {
100031 if (users > 0)
100032 diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
100033 index a99b6c3..cb372f9 100644
100034 --- a/net/netfilter/nf_conntrack_proto_dccp.c
100035 +++ b/net/netfilter/nf_conntrack_proto_dccp.c
100036 @@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
100037 const char *msg;
100038 u_int8_t state;
100039
100040 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
100041 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
100042 BUG_ON(dh == NULL);
100043
100044 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
100045 @@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
100046 out_invalid:
100047 if (LOG_INVALID(net, IPPROTO_DCCP))
100048 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
100049 - NULL, msg);
100050 + NULL, "%s", msg);
100051 return false;
100052 }
100053
100054 @@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
100055 u_int8_t type, old_state, new_state;
100056 enum ct_dccp_roles role;
100057
100058 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
100059 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
100060 BUG_ON(dh == NULL);
100061 type = dh->dccph_type;
100062
100063 @@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
100064 unsigned int cscov;
100065 const char *msg;
100066
100067 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
100068 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
100069 if (dh == NULL) {
100070 msg = "nf_ct_dccp: short packet ";
100071 goto out_invalid;
100072 @@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
100073
100074 out_invalid:
100075 if (LOG_INVALID(net, IPPROTO_DCCP))
100076 - nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
100077 + nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
100078 return -NF_ACCEPT;
100079 }
100080
100081 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100082 index f641751..d3c5b51 100644
100083 --- a/net/netfilter/nf_conntrack_standalone.c
100084 +++ b/net/netfilter/nf_conntrack_standalone.c
100085 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100086
100087 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100088 {
100089 - struct ctl_table *table;
100090 + ctl_table_no_const *table;
100091
100092 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100093 GFP_KERNEL);
100094 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100095 index 7a394df..bd91a8a 100644
100096 --- a/net/netfilter/nf_conntrack_timestamp.c
100097 +++ b/net/netfilter/nf_conntrack_timestamp.c
100098 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100099 #ifdef CONFIG_SYSCTL
100100 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100101 {
100102 - struct ctl_table *table;
100103 + ctl_table_no_const *table;
100104
100105 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100106 GFP_KERNEL);
100107 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100108 index 85296d4..8becdec 100644
100109 --- a/net/netfilter/nf_log.c
100110 +++ b/net/netfilter/nf_log.c
100111 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100112
100113 #ifdef CONFIG_SYSCTL
100114 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100115 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100116 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100117
100118 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100119 void __user *buffer, size_t *lenp, loff_t *ppos)
100120 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100121 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100122 mutex_unlock(&nf_log_mutex);
100123 } else {
100124 + ctl_table_no_const nf_log_table = *table;
100125 +
100126 mutex_lock(&nf_log_mutex);
100127 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100128 lockdep_is_held(&nf_log_mutex));
100129 if (!logger)
100130 - table->data = "NONE";
100131 + nf_log_table.data = "NONE";
100132 else
100133 - table->data = logger->name;
100134 - r = proc_dostring(table, write, buffer, lenp, ppos);
100135 + nf_log_table.data = logger->name;
100136 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100137 mutex_unlock(&nf_log_mutex);
100138 }
100139
100140 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100141 index f042ae5..30ea486 100644
100142 --- a/net/netfilter/nf_sockopt.c
100143 +++ b/net/netfilter/nf_sockopt.c
100144 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100145 }
100146 }
100147
100148 - list_add(&reg->list, &nf_sockopts);
100149 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100150 out:
100151 mutex_unlock(&nf_sockopt_mutex);
100152 return ret;
100153 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100154 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100155 {
100156 mutex_lock(&nf_sockopt_mutex);
100157 - list_del(&reg->list);
100158 + pax_list_del((struct list_head *)&reg->list);
100159 mutex_unlock(&nf_sockopt_mutex);
100160 }
100161 EXPORT_SYMBOL(nf_unregister_sockopt);
100162 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100163 index a155d19..726b0f2 100644
100164 --- a/net/netfilter/nfnetlink_log.c
100165 +++ b/net/netfilter/nfnetlink_log.c
100166 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100167 struct nfnl_log_net {
100168 spinlock_t instances_lock;
100169 struct hlist_head instance_table[INSTANCE_BUCKETS];
100170 - atomic_t global_seq;
100171 + atomic_unchecked_t global_seq;
100172 };
100173
100174 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100175 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100176 /* global sequence number */
100177 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100178 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100179 - htonl(atomic_inc_return(&log->global_seq))))
100180 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
100181 goto nla_put_failure;
100182
100183 if (data_len) {
100184 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100185 index da0c1f4..f79737a 100644
100186 --- a/net/netfilter/nft_compat.c
100187 +++ b/net/netfilter/nft_compat.c
100188 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100189 /* We want to reuse existing compat_to_user */
100190 old_fs = get_fs();
100191 set_fs(KERNEL_DS);
100192 - t->compat_to_user(out, in);
100193 + t->compat_to_user((void __force_user *)out, in);
100194 set_fs(old_fs);
100195 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100196 kfree(out);
100197 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100198 /* We want to reuse existing compat_to_user */
100199 old_fs = get_fs();
100200 set_fs(KERNEL_DS);
100201 - m->compat_to_user(out, in);
100202 + m->compat_to_user((void __force_user *)out, in);
100203 set_fs(old_fs);
100204 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
100205 kfree(out);
100206 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
100207 new file mode 100644
100208 index 0000000..c566332
100209 --- /dev/null
100210 +++ b/net/netfilter/xt_gradm.c
100211 @@ -0,0 +1,51 @@
100212 +/*
100213 + * gradm match for netfilter
100214 + * Copyright © Zbigniew Krzystolik, 2010
100215 + *
100216 + * This program is free software; you can redistribute it and/or modify
100217 + * it under the terms of the GNU General Public License; either version
100218 + * 2 or 3 as published by the Free Software Foundation.
100219 + */
100220 +#include <linux/module.h>
100221 +#include <linux/moduleparam.h>
100222 +#include <linux/skbuff.h>
100223 +#include <linux/netfilter/x_tables.h>
100224 +#include <linux/grsecurity.h>
100225 +#include <linux/netfilter/xt_gradm.h>
100226 +
100227 +static bool
100228 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
100229 +{
100230 + const struct xt_gradm_mtinfo *info = par->matchinfo;
100231 + bool retval = false;
100232 + if (gr_acl_is_enabled())
100233 + retval = true;
100234 + return retval ^ info->invflags;
100235 +}
100236 +
100237 +static struct xt_match gradm_mt_reg __read_mostly = {
100238 + .name = "gradm",
100239 + .revision = 0,
100240 + .family = NFPROTO_UNSPEC,
100241 + .match = gradm_mt,
100242 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
100243 + .me = THIS_MODULE,
100244 +};
100245 +
100246 +static int __init gradm_mt_init(void)
100247 +{
100248 + return xt_register_match(&gradm_mt_reg);
100249 +}
100250 +
100251 +static void __exit gradm_mt_exit(void)
100252 +{
100253 + xt_unregister_match(&gradm_mt_reg);
100254 +}
100255 +
100256 +module_init(gradm_mt_init);
100257 +module_exit(gradm_mt_exit);
100258 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
100259 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
100260 +MODULE_LICENSE("GPL");
100261 +MODULE_ALIAS("ipt_gradm");
100262 +MODULE_ALIAS("ip6t_gradm");
100263 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
100264 index 4fe4fb4..87a89e5 100644
100265 --- a/net/netfilter/xt_statistic.c
100266 +++ b/net/netfilter/xt_statistic.c
100267 @@ -19,7 +19,7 @@
100268 #include <linux/module.h>
100269
100270 struct xt_statistic_priv {
100271 - atomic_t count;
100272 + atomic_unchecked_t count;
100273 } ____cacheline_aligned_in_smp;
100274
100275 MODULE_LICENSE("GPL");
100276 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
100277 break;
100278 case XT_STATISTIC_MODE_NTH:
100279 do {
100280 - oval = atomic_read(&info->master->count);
100281 + oval = atomic_read_unchecked(&info->master->count);
100282 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
100283 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
100284 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
100285 if (nval == 0)
100286 ret = !ret;
100287 break;
100288 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
100289 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
100290 if (info->master == NULL)
100291 return -ENOMEM;
100292 - atomic_set(&info->master->count, info->u.nth.count);
100293 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
100294
100295 return 0;
100296 }
100297 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
100298 index bca50b9..782ec12 100644
100299 --- a/net/netlink/af_netlink.c
100300 +++ b/net/netlink/af_netlink.c
100301 @@ -249,7 +249,7 @@ static void netlink_overrun(struct sock *sk)
100302 sk->sk_error_report(sk);
100303 }
100304 }
100305 - atomic_inc(&sk->sk_drops);
100306 + atomic_inc_unchecked(&sk->sk_drops);
100307 }
100308
100309 static void netlink_rcv_wake(struct sock *sk)
100310 @@ -1481,8 +1481,8 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
100311 if (addr->sa_family != AF_NETLINK)
100312 return -EINVAL;
100313
100314 - /* Only superuser is allowed to send multicasts */
100315 - if (nladdr->nl_groups && !netlink_capable(sock, NL_CFG_F_NONROOT_SEND))
100316 + if ((nladdr->nl_groups || nladdr->nl_pid) &&
100317 + !netlink_capable(sock, NL_CFG_F_NONROOT_SEND))
100318 return -EPERM;
100319
100320 if (!nlk->portid)
100321 @@ -2940,7 +2940,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
100322 sk_wmem_alloc_get(s),
100323 nlk->cb_running,
100324 atomic_read(&s->sk_refcnt),
100325 - atomic_read(&s->sk_drops),
100326 + atomic_read_unchecked(&s->sk_drops),
100327 sock_i_ino(s)
100328 );
100329
100330 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
100331 index 53c19a3..b0ac04a 100644
100332 --- a/net/netrom/af_netrom.c
100333 +++ b/net/netrom/af_netrom.c
100334 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
100335 *uaddr_len = sizeof(struct full_sockaddr_ax25);
100336 } else {
100337 sax->fsa_ax25.sax25_family = AF_NETROM;
100338 - sax->fsa_ax25.sax25_ndigis = 0;
100339 sax->fsa_ax25.sax25_call = nr->source_addr;
100340 *uaddr_len = sizeof(struct sockaddr_ax25);
100341 }
100342 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
100343 index 88cfbc1..05d73f5 100644
100344 --- a/net/packet/af_packet.c
100345 +++ b/net/packet/af_packet.c
100346 @@ -1720,7 +1720,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100347
100348 spin_lock(&sk->sk_receive_queue.lock);
100349 po->stats.stats1.tp_packets++;
100350 - skb->dropcount = atomic_read(&sk->sk_drops);
100351 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
100352 __skb_queue_tail(&sk->sk_receive_queue, skb);
100353 spin_unlock(&sk->sk_receive_queue.lock);
100354 sk->sk_data_ready(sk, skb->len);
100355 @@ -1729,7 +1729,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100356 drop_n_acct:
100357 spin_lock(&sk->sk_receive_queue.lock);
100358 po->stats.stats1.tp_drops++;
100359 - atomic_inc(&sk->sk_drops);
100360 + atomic_inc_unchecked(&sk->sk_drops);
100361 spin_unlock(&sk->sk_receive_queue.lock);
100362
100363 drop_n_restore:
100364 @@ -3275,7 +3275,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100365 case PACKET_HDRLEN:
100366 if (len > sizeof(int))
100367 len = sizeof(int);
100368 - if (copy_from_user(&val, optval, len))
100369 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
100370 return -EFAULT;
100371 switch (val) {
100372 case TPACKET_V1:
100373 @@ -3318,7 +3318,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100374 len = lv;
100375 if (put_user(len, optlen))
100376 return -EFAULT;
100377 - if (copy_to_user(optval, data, len))
100378 + if (len > sizeof(st) || copy_to_user(optval, data, len))
100379 return -EFAULT;
100380 return 0;
100381 }
100382 diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
100383 index 38946b2..12c30f3 100644
100384 --- a/net/phonet/datagram.c
100385 +++ b/net/phonet/datagram.c
100386 @@ -139,6 +139,9 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
100387 MSG_CMSG_COMPAT))
100388 goto out_nofree;
100389
100390 + if (addr_len)
100391 + *addr_len = sizeof(sa);
100392 +
100393 skb = skb_recv_datagram(sk, flags, noblock, &rval);
100394 if (skb == NULL)
100395 goto out_nofree;
100396 @@ -159,10 +162,8 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
100397
100398 rval = (flags & MSG_TRUNC) ? skb->len : copylen;
100399
100400 - if (msg->msg_name != NULL) {
100401 - memcpy(msg->msg_name, &sa, sizeof(sa));
100402 - *addr_len = sizeof(sa);
100403 - }
100404 + if (msg->msg_name != NULL)
100405 + memcpy(msg->msg_name, &sa, sizeof(struct sockaddr_pn));
100406
100407 out:
100408 skb_free_datagram(sk, skb);
100409 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
100410 index e774117..900b8b7 100644
100411 --- a/net/phonet/pep.c
100412 +++ b/net/phonet/pep.c
100413 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100414
100415 case PNS_PEP_CTRL_REQ:
100416 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
100417 - atomic_inc(&sk->sk_drops);
100418 + atomic_inc_unchecked(&sk->sk_drops);
100419 break;
100420 }
100421 __skb_pull(skb, 4);
100422 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100423 }
100424
100425 if (pn->rx_credits == 0) {
100426 - atomic_inc(&sk->sk_drops);
100427 + atomic_inc_unchecked(&sk->sk_drops);
100428 err = -ENOBUFS;
100429 break;
100430 }
100431 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
100432 }
100433
100434 if (pn->rx_credits == 0) {
100435 - atomic_inc(&sk->sk_drops);
100436 + atomic_inc_unchecked(&sk->sk_drops);
100437 err = NET_RX_DROP;
100438 break;
100439 }
100440 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
100441 index 008214a..bb68240 100644
100442 --- a/net/phonet/socket.c
100443 +++ b/net/phonet/socket.c
100444 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
100445 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
100446 sock_i_ino(sk),
100447 atomic_read(&sk->sk_refcnt), sk,
100448 - atomic_read(&sk->sk_drops));
100449 + atomic_read_unchecked(&sk->sk_drops));
100450 }
100451 seq_pad(seq, '\n');
100452 return 0;
100453 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
100454 index c02a8c4..3c5b600 100644
100455 --- a/net/phonet/sysctl.c
100456 +++ b/net/phonet/sysctl.c
100457 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
100458 {
100459 int ret;
100460 int range[2] = {local_port_range[0], local_port_range[1]};
100461 - struct ctl_table tmp = {
100462 + ctl_table_no_const tmp = {
100463 .data = &range,
100464 .maxlen = sizeof(range),
100465 .mode = table->mode,
100466 diff --git a/net/rds/cong.c b/net/rds/cong.c
100467 index e5b65ac..f3b6fb7 100644
100468 --- a/net/rds/cong.c
100469 +++ b/net/rds/cong.c
100470 @@ -78,7 +78,7 @@
100471 * finds that the saved generation number is smaller than the global generation
100472 * number, it wakes up the process.
100473 */
100474 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
100475 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
100476
100477 /*
100478 * Congestion monitoring
100479 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
100480 rdsdebug("waking map %p for %pI4\n",
100481 map, &map->m_addr);
100482 rds_stats_inc(s_cong_update_received);
100483 - atomic_inc(&rds_cong_generation);
100484 + atomic_inc_unchecked(&rds_cong_generation);
100485 if (waitqueue_active(&map->m_waitq))
100486 wake_up(&map->m_waitq);
100487 if (waitqueue_active(&rds_poll_waitq))
100488 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
100489
100490 int rds_cong_updated_since(unsigned long *recent)
100491 {
100492 - unsigned long gen = atomic_read(&rds_cong_generation);
100493 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
100494
100495 if (likely(*recent == gen))
100496 return 0;
100497 diff --git a/net/rds/ib.h b/net/rds/ib.h
100498 index 7280ab8..e04f4ea 100644
100499 --- a/net/rds/ib.h
100500 +++ b/net/rds/ib.h
100501 @@ -128,7 +128,7 @@ struct rds_ib_connection {
100502 /* sending acks */
100503 unsigned long i_ack_flags;
100504 #ifdef KERNEL_HAS_ATOMIC64
100505 - atomic64_t i_ack_next; /* next ACK to send */
100506 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100507 #else
100508 spinlock_t i_ack_lock; /* protect i_ack_next */
100509 u64 i_ack_next; /* next ACK to send */
100510 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
100511 index 31b74f5..dc1fbfa 100644
100512 --- a/net/rds/ib_cm.c
100513 +++ b/net/rds/ib_cm.c
100514 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
100515 /* Clear the ACK state */
100516 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100517 #ifdef KERNEL_HAS_ATOMIC64
100518 - atomic64_set(&ic->i_ack_next, 0);
100519 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100520 #else
100521 ic->i_ack_next = 0;
100522 #endif
100523 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
100524 index b7ebe23..b6352f6 100644
100525 --- a/net/rds/ib_recv.c
100526 +++ b/net/rds/ib_recv.c
100527 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100528 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
100529 int ack_required)
100530 {
100531 - atomic64_set(&ic->i_ack_next, seq);
100532 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100533 if (ack_required) {
100534 smp_mb__before_clear_bit();
100535 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100536 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100537 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100538 smp_mb__after_clear_bit();
100539
100540 - return atomic64_read(&ic->i_ack_next);
100541 + return atomic64_read_unchecked(&ic->i_ack_next);
100542 }
100543 #endif
100544
100545 diff --git a/net/rds/iw.h b/net/rds/iw.h
100546 index 04ce3b1..48119a6 100644
100547 --- a/net/rds/iw.h
100548 +++ b/net/rds/iw.h
100549 @@ -134,7 +134,7 @@ struct rds_iw_connection {
100550 /* sending acks */
100551 unsigned long i_ack_flags;
100552 #ifdef KERNEL_HAS_ATOMIC64
100553 - atomic64_t i_ack_next; /* next ACK to send */
100554 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100555 #else
100556 spinlock_t i_ack_lock; /* protect i_ack_next */
100557 u64 i_ack_next; /* next ACK to send */
100558 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
100559 index a91e1db..cf3053f 100644
100560 --- a/net/rds/iw_cm.c
100561 +++ b/net/rds/iw_cm.c
100562 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
100563 /* Clear the ACK state */
100564 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100565 #ifdef KERNEL_HAS_ATOMIC64
100566 - atomic64_set(&ic->i_ack_next, 0);
100567 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100568 #else
100569 ic->i_ack_next = 0;
100570 #endif
100571 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
100572 index 4503335..db566b4 100644
100573 --- a/net/rds/iw_recv.c
100574 +++ b/net/rds/iw_recv.c
100575 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100576 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
100577 int ack_required)
100578 {
100579 - atomic64_set(&ic->i_ack_next, seq);
100580 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100581 if (ack_required) {
100582 smp_mb__before_clear_bit();
100583 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100584 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100585 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100586 smp_mb__after_clear_bit();
100587
100588 - return atomic64_read(&ic->i_ack_next);
100589 + return atomic64_read_unchecked(&ic->i_ack_next);
100590 }
100591 #endif
100592
100593 diff --git a/net/rds/rds.h b/net/rds/rds.h
100594 index 48f8ffc..0ef3eec 100644
100595 --- a/net/rds/rds.h
100596 +++ b/net/rds/rds.h
100597 @@ -449,7 +449,7 @@ struct rds_transport {
100598 void (*sync_mr)(void *trans_private, int direction);
100599 void (*free_mr)(void *trans_private, int invalidate);
100600 void (*flush_mrs)(void);
100601 -};
100602 +} __do_const;
100603
100604 struct rds_sock {
100605 struct sock rs_sk;
100606 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
100607 index edac9ef..16bcb98 100644
100608 --- a/net/rds/tcp.c
100609 +++ b/net/rds/tcp.c
100610 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
100611 int val = 1;
100612
100613 set_fs(KERNEL_DS);
100614 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
100615 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
100616 sizeof(val));
100617 set_fs(oldfs);
100618 }
100619 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
100620 index 81cf5a4..b5826ff 100644
100621 --- a/net/rds/tcp_send.c
100622 +++ b/net/rds/tcp_send.c
100623 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
100624
100625 oldfs = get_fs();
100626 set_fs(KERNEL_DS);
100627 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
100628 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
100629 sizeof(val));
100630 set_fs(oldfs);
100631 }
100632 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
100633 index e61aa60..f07cc89 100644
100634 --- a/net/rxrpc/af_rxrpc.c
100635 +++ b/net/rxrpc/af_rxrpc.c
100636 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
100637 __be32 rxrpc_epoch;
100638
100639 /* current debugging ID */
100640 -atomic_t rxrpc_debug_id;
100641 +atomic_unchecked_t rxrpc_debug_id;
100642
100643 /* count of skbs currently in use */
100644 atomic_t rxrpc_n_skbs;
100645 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
100646 index e4d9cbc..b229649 100644
100647 --- a/net/rxrpc/ar-ack.c
100648 +++ b/net/rxrpc/ar-ack.c
100649 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
100650
100651 _enter("{%d,%d,%d,%d},",
100652 call->acks_hard, call->acks_unacked,
100653 - atomic_read(&call->sequence),
100654 + atomic_read_unchecked(&call->sequence),
100655 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
100656
100657 stop = 0;
100658 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
100659
100660 /* each Tx packet has a new serial number */
100661 sp->hdr.serial =
100662 - htonl(atomic_inc_return(&call->conn->serial));
100663 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
100664
100665 hdr = (struct rxrpc_header *) txb->head;
100666 hdr->serial = sp->hdr.serial;
100667 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
100668 */
100669 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
100670 {
100671 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
100672 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
100673 }
100674
100675 /*
100676 @@ -629,7 +629,7 @@ process_further:
100677
100678 latest = ntohl(sp->hdr.serial);
100679 hard = ntohl(ack.firstPacket);
100680 - tx = atomic_read(&call->sequence);
100681 + tx = atomic_read_unchecked(&call->sequence);
100682
100683 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
100684 latest,
100685 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
100686 goto maybe_reschedule;
100687
100688 send_ACK_with_skew:
100689 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
100690 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
100691 ntohl(ack.serial));
100692 send_ACK:
100693 mtu = call->conn->trans->peer->if_mtu;
100694 @@ -1173,7 +1173,7 @@ send_ACK:
100695 ackinfo.rxMTU = htonl(5692);
100696 ackinfo.jumbo_max = htonl(4);
100697
100698 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
100699 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
100700 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
100701 ntohl(hdr.serial),
100702 ntohs(ack.maxSkew),
100703 @@ -1191,7 +1191,7 @@ send_ACK:
100704 send_message:
100705 _debug("send message");
100706
100707 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
100708 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
100709 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
100710 send_message_2:
100711
100712 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
100713 index a3bbb36..3341fb9 100644
100714 --- a/net/rxrpc/ar-call.c
100715 +++ b/net/rxrpc/ar-call.c
100716 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
100717 spin_lock_init(&call->lock);
100718 rwlock_init(&call->state_lock);
100719 atomic_set(&call->usage, 1);
100720 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
100721 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100722 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
100723
100724 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
100725 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
100726 index 4106ca9..a338d7a 100644
100727 --- a/net/rxrpc/ar-connection.c
100728 +++ b/net/rxrpc/ar-connection.c
100729 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
100730 rwlock_init(&conn->lock);
100731 spin_lock_init(&conn->state_lock);
100732 atomic_set(&conn->usage, 1);
100733 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
100734 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100735 conn->avail_calls = RXRPC_MAXCALLS;
100736 conn->size_align = 4;
100737 conn->header_size = sizeof(struct rxrpc_header);
100738 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
100739 index e7ed43a..6afa140 100644
100740 --- a/net/rxrpc/ar-connevent.c
100741 +++ b/net/rxrpc/ar-connevent.c
100742 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
100743
100744 len = iov[0].iov_len + iov[1].iov_len;
100745
100746 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
100747 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
100748 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
100749
100750 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
100751 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
100752 index 529572f..c758ca7 100644
100753 --- a/net/rxrpc/ar-input.c
100754 +++ b/net/rxrpc/ar-input.c
100755 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
100756 /* track the latest serial number on this connection for ACK packet
100757 * information */
100758 serial = ntohl(sp->hdr.serial);
100759 - hi_serial = atomic_read(&call->conn->hi_serial);
100760 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
100761 while (serial > hi_serial)
100762 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
100763 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
100764 serial);
100765
100766 /* request ACK generation for any ACK or DATA packet that requests
100767 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
100768 index 5f43675..ca07817 100644
100769 --- a/net/rxrpc/ar-internal.h
100770 +++ b/net/rxrpc/ar-internal.h
100771 @@ -272,8 +272,8 @@ struct rxrpc_connection {
100772 int error; /* error code for local abort */
100773 int debug_id; /* debug ID for printks */
100774 unsigned int call_counter; /* call ID counter */
100775 - atomic_t serial; /* packet serial number counter */
100776 - atomic_t hi_serial; /* highest serial number received */
100777 + atomic_unchecked_t serial; /* packet serial number counter */
100778 + atomic_unchecked_t hi_serial; /* highest serial number received */
100779 u8 avail_calls; /* number of calls available */
100780 u8 size_align; /* data size alignment (for security) */
100781 u8 header_size; /* rxrpc + security header size */
100782 @@ -346,7 +346,7 @@ struct rxrpc_call {
100783 spinlock_t lock;
100784 rwlock_t state_lock; /* lock for state transition */
100785 atomic_t usage;
100786 - atomic_t sequence; /* Tx data packet sequence counter */
100787 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
100788 u32 abort_code; /* local/remote abort code */
100789 enum { /* current state of call */
100790 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
100791 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
100792 */
100793 extern atomic_t rxrpc_n_skbs;
100794 extern __be32 rxrpc_epoch;
100795 -extern atomic_t rxrpc_debug_id;
100796 +extern atomic_unchecked_t rxrpc_debug_id;
100797 extern struct workqueue_struct *rxrpc_workqueue;
100798
100799 /*
100800 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
100801 index 87f7135..74d3703 100644
100802 --- a/net/rxrpc/ar-local.c
100803 +++ b/net/rxrpc/ar-local.c
100804 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
100805 spin_lock_init(&local->lock);
100806 rwlock_init(&local->services_lock);
100807 atomic_set(&local->usage, 1);
100808 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
100809 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100810 memcpy(&local->srx, srx, sizeof(*srx));
100811 }
100812
100813 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
100814 index e1ac183..b43e10e 100644
100815 --- a/net/rxrpc/ar-output.c
100816 +++ b/net/rxrpc/ar-output.c
100817 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
100818 sp->hdr.cid = call->cid;
100819 sp->hdr.callNumber = call->call_id;
100820 sp->hdr.seq =
100821 - htonl(atomic_inc_return(&call->sequence));
100822 + htonl(atomic_inc_return_unchecked(&call->sequence));
100823 sp->hdr.serial =
100824 - htonl(atomic_inc_return(&conn->serial));
100825 + htonl(atomic_inc_return_unchecked(&conn->serial));
100826 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
100827 sp->hdr.userStatus = 0;
100828 sp->hdr.securityIndex = conn->security_ix;
100829 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
100830 index bebaa43..2644591 100644
100831 --- a/net/rxrpc/ar-peer.c
100832 +++ b/net/rxrpc/ar-peer.c
100833 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
100834 INIT_LIST_HEAD(&peer->error_targets);
100835 spin_lock_init(&peer->lock);
100836 atomic_set(&peer->usage, 1);
100837 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
100838 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100839 memcpy(&peer->srx, srx, sizeof(*srx));
100840
100841 rxrpc_assess_MTU_size(peer);
100842 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
100843 index 38047f7..9f48511 100644
100844 --- a/net/rxrpc/ar-proc.c
100845 +++ b/net/rxrpc/ar-proc.c
100846 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
100847 atomic_read(&conn->usage),
100848 rxrpc_conn_states[conn->state],
100849 key_serial(conn->key),
100850 - atomic_read(&conn->serial),
100851 - atomic_read(&conn->hi_serial));
100852 + atomic_read_unchecked(&conn->serial),
100853 + atomic_read_unchecked(&conn->hi_serial));
100854
100855 return 0;
100856 }
100857 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
100858 index 92df566..87ec1bf 100644
100859 --- a/net/rxrpc/ar-transport.c
100860 +++ b/net/rxrpc/ar-transport.c
100861 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
100862 spin_lock_init(&trans->client_lock);
100863 rwlock_init(&trans->conn_lock);
100864 atomic_set(&trans->usage, 1);
100865 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
100866 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100867
100868 if (peer->srx.transport.family == AF_INET) {
100869 switch (peer->srx.transport_type) {
100870 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
100871 index f226709..0e735a8 100644
100872 --- a/net/rxrpc/rxkad.c
100873 +++ b/net/rxrpc/rxkad.c
100874 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
100875
100876 len = iov[0].iov_len + iov[1].iov_len;
100877
100878 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
100879 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
100880 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
100881
100882 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
100883 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
100884
100885 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
100886
100887 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
100888 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
100889 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
100890
100891 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
100892 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
100893 index 7567e6f..299382b 100644
100894 --- a/net/sctp/ipv6.c
100895 +++ b/net/sctp/ipv6.c
100896 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
100897 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
100898 };
100899
100900 -static struct sctp_af sctp_af_inet6 = {
100901 +static struct sctp_af sctp_af_inet6 __read_only = {
100902 .sa_family = AF_INET6,
100903 .sctp_xmit = sctp_v6_xmit,
100904 .setsockopt = ipv6_setsockopt,
100905 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
100906 #endif
100907 };
100908
100909 -static struct sctp_pf sctp_pf_inet6 = {
100910 +static struct sctp_pf sctp_pf_inet6 __read_only = {
100911 .event_msgname = sctp_inet6_event_msgname,
100912 .skb_msgname = sctp_inet6_skb_msgname,
100913 .af_supported = sctp_inet6_af_supported,
100914 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
100915
100916 void sctp_v6_pf_exit(void)
100917 {
100918 - list_del(&sctp_af_inet6.list);
100919 + pax_list_del(&sctp_af_inet6.list);
100920 }
100921
100922 /* Initialize IPv6 support and register with socket layer. */
100923 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
100924 index 5e17092..19be1d4 100644
100925 --- a/net/sctp/protocol.c
100926 +++ b/net/sctp/protocol.c
100927 @@ -832,8 +832,10 @@ int sctp_register_af(struct sctp_af *af)
100928 return 0;
100929 }
100930
100931 + pax_open_kernel();
100932 INIT_LIST_HEAD(&af->list);
100933 - list_add_tail(&af->list, &sctp_address_families);
100934 + pax_close_kernel();
100935 + pax_list_add_tail(&af->list, &sctp_address_families);
100936 return 1;
100937 }
100938
100939 @@ -963,7 +965,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
100940
100941 static struct sctp_af sctp_af_inet;
100942
100943 -static struct sctp_pf sctp_pf_inet = {
100944 +static struct sctp_pf sctp_pf_inet __read_only = {
100945 .event_msgname = sctp_inet_event_msgname,
100946 .skb_msgname = sctp_inet_skb_msgname,
100947 .af_supported = sctp_inet_af_supported,
100948 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
100949 };
100950
100951 /* IPv4 address related functions. */
100952 -static struct sctp_af sctp_af_inet = {
100953 +static struct sctp_af sctp_af_inet __read_only = {
100954 .sa_family = AF_INET,
100955 .sctp_xmit = sctp_v4_xmit,
100956 .setsockopt = ip_setsockopt,
100957 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
100958
100959 static void sctp_v4_pf_exit(void)
100960 {
100961 - list_del(&sctp_af_inet.list);
100962 + pax_list_del(&sctp_af_inet.list);
100963 }
100964
100965 static int sctp_v4_protosw_init(void)
100966 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
100967 index 1a6eef3..17e898f 100644
100968 --- a/net/sctp/sm_sideeffect.c
100969 +++ b/net/sctp/sm_sideeffect.c
100970 @@ -440,7 +440,7 @@ static void sctp_generate_sack_event(unsigned long data)
100971 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
100972 }
100973
100974 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
100975 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
100976 NULL,
100977 sctp_generate_t1_cookie_event,
100978 sctp_generate_t1_init_event,
100979 diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
100980 index a26065b..af7be05 100644
100981 --- a/net/sctp/sm_statefuns.c
100982 +++ b/net/sctp/sm_statefuns.c
100983 @@ -759,6 +759,13 @@ sctp_disposition_t sctp_sf_do_5_1D_ce(struct net *net,
100984 struct sctp_chunk auth;
100985 sctp_ierror_t ret;
100986
100987 + /* Make sure that we and the peer are AUTH capable */
100988 + if (!net->sctp.auth_enable || !new_asoc->peer.auth_capable) {
100989 + kfree_skb(chunk->auth_chunk);
100990 + sctp_association_free(new_asoc);
100991 + return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
100992 + }
100993 +
100994 /* set-up our fake chunk so that we can process it */
100995 auth.skb = chunk->auth_chunk;
100996 auth.asoc = chunk->asoc;
100997 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
100998 index 146b35d..1021a34 100644
100999 --- a/net/sctp/socket.c
101000 +++ b/net/sctp/socket.c
101001 @@ -2176,11 +2176,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
101002 {
101003 struct sctp_association *asoc;
101004 struct sctp_ulpevent *event;
101005 + struct sctp_event_subscribe subscribe;
101006
101007 if (optlen > sizeof(struct sctp_event_subscribe))
101008 return -EINVAL;
101009 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
101010 + if (copy_from_user(&subscribe, optval, optlen))
101011 return -EFAULT;
101012 + sctp_sk(sk)->subscribe = subscribe;
101013
101014 /*
101015 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
101016 @@ -4252,13 +4254,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
101017 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101018 int __user *optlen)
101019 {
101020 + struct sctp_event_subscribe subscribe;
101021 +
101022 if (len <= 0)
101023 return -EINVAL;
101024 if (len > sizeof(struct sctp_event_subscribe))
101025 len = sizeof(struct sctp_event_subscribe);
101026 if (put_user(len, optlen))
101027 return -EFAULT;
101028 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
101029 + subscribe = sctp_sk(sk)->subscribe;
101030 + if (copy_to_user(optval, &subscribe, len))
101031 return -EFAULT;
101032 return 0;
101033 }
101034 @@ -4276,6 +4281,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101035 */
101036 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
101037 {
101038 + __u32 autoclose;
101039 +
101040 /* Applicable to UDP-style socket only */
101041 if (sctp_style(sk, TCP))
101042 return -EOPNOTSUPP;
101043 @@ -4284,7 +4291,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
101044 len = sizeof(int);
101045 if (put_user(len, optlen))
101046 return -EFAULT;
101047 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
101048 + autoclose = sctp_sk(sk)->autoclose;
101049 + if (copy_to_user(optval, &autoclose, sizeof(int)))
101050 return -EFAULT;
101051 return 0;
101052 }
101053 @@ -4656,12 +4664,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
101054 */
101055 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
101056 {
101057 + struct sctp_initmsg initmsg;
101058 +
101059 if (len < sizeof(struct sctp_initmsg))
101060 return -EINVAL;
101061 len = sizeof(struct sctp_initmsg);
101062 if (put_user(len, optlen))
101063 return -EFAULT;
101064 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
101065 + initmsg = sctp_sk(sk)->initmsg;
101066 + if (copy_to_user(optval, &initmsg, len))
101067 return -EFAULT;
101068 return 0;
101069 }
101070 @@ -4702,6 +4713,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
101071 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
101072 if (space_left < addrlen)
101073 return -ENOMEM;
101074 + if (addrlen > sizeof(temp) || addrlen < 0)
101075 + return -EFAULT;
101076 if (copy_to_user(to, &temp, addrlen))
101077 return -EFAULT;
101078 to += addrlen;
101079 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
101080 index b0565af..d135e6e 100644
101081 --- a/net/sctp/sysctl.c
101082 +++ b/net/sctp/sysctl.c
101083 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
101084 {
101085 struct net *net = current->nsproxy->net_ns;
101086 char tmp[8];
101087 - struct ctl_table tbl;
101088 + ctl_table_no_const tbl;
101089 int ret;
101090 int changed = 0;
101091 char *none = "none";
101092 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
101093 {
101094 struct net *net = current->nsproxy->net_ns;
101095 int new_value;
101096 - struct ctl_table tbl;
101097 + ctl_table_no_const tbl;
101098 unsigned int min = *(unsigned int *) ctl->extra1;
101099 unsigned int max = *(unsigned int *) ctl->extra2;
101100 int ret;
101101 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101102 {
101103 struct net *net = current->nsproxy->net_ns;
101104 int new_value;
101105 - struct ctl_table tbl;
101106 + ctl_table_no_const tbl;
101107 unsigned int min = *(unsigned int *) ctl->extra1;
101108 unsigned int max = *(unsigned int *) ctl->extra2;
101109 int ret;
101110 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101111
101112 int sctp_sysctl_net_register(struct net *net)
101113 {
101114 - struct ctl_table *table;
101115 + ctl_table_no_const *table;
101116 int i;
101117
101118 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
101119 diff --git a/net/socket.c b/net/socket.c
101120 index e83c416..f87df4c 100644
101121 --- a/net/socket.c
101122 +++ b/net/socket.c
101123 @@ -88,6 +88,7 @@
101124 #include <linux/magic.h>
101125 #include <linux/slab.h>
101126 #include <linux/xattr.h>
101127 +#include <linux/in.h>
101128
101129 #include <asm/uaccess.h>
101130 #include <asm/unistd.h>
101131 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
101132 unsigned int sysctl_net_busy_poll __read_mostly;
101133 #endif
101134
101135 +#include <linux/grsock.h>
101136 +
101137 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
101138 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
101139 unsigned long nr_segs, loff_t pos);
101140 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
101141 */
101142
101143 static DEFINE_SPINLOCK(net_family_lock);
101144 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101145 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101146
101147 /*
101148 * Statistics counters of the socket lists
101149 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
101150 &sockfs_dentry_operations, SOCKFS_MAGIC);
101151 }
101152
101153 -static struct vfsmount *sock_mnt __read_mostly;
101154 +struct vfsmount *sock_mnt __read_mostly;
101155
101156 static struct file_system_type sock_fs_type = {
101157 .name = "sockfs",
101158 @@ -1255,6 +1258,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101159 return -EAFNOSUPPORT;
101160 if (type < 0 || type >= SOCK_MAX)
101161 return -EINVAL;
101162 + if (protocol < 0)
101163 + return -EINVAL;
101164
101165 /* Compatibility.
101166
101167 @@ -1275,6 +1280,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101168 if (err)
101169 return err;
101170
101171 + if(!kern && !gr_search_socket(family, type, protocol)) {
101172 + if (rcu_access_pointer(net_families[family]) == NULL)
101173 + return -EAFNOSUPPORT;
101174 + else
101175 + return -EACCES;
101176 + }
101177 +
101178 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
101179 + if (rcu_access_pointer(net_families[family]) == NULL)
101180 + return -EAFNOSUPPORT;
101181 + else
101182 + return -EACCES;
101183 + }
101184 +
101185 /*
101186 * Allocate the socket and allow the family to set things up. if
101187 * the protocol is 0, the family is instructed to select an appropriate
101188 @@ -1513,6 +1532,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101189 if (sock) {
101190 err = move_addr_to_kernel(umyaddr, addrlen, &address);
101191 if (err >= 0) {
101192 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
101193 + err = -EACCES;
101194 + goto error;
101195 + }
101196 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
101197 + if (err)
101198 + goto error;
101199 +
101200 err = security_socket_bind(sock,
101201 (struct sockaddr *)&address,
101202 addrlen);
101203 @@ -1521,6 +1548,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101204 (struct sockaddr *)
101205 &address, addrlen);
101206 }
101207 +error:
101208 fput_light(sock->file, fput_needed);
101209 }
101210 return err;
101211 @@ -1544,10 +1572,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
101212 if ((unsigned int)backlog > somaxconn)
101213 backlog = somaxconn;
101214
101215 + if (gr_handle_sock_server_other(sock->sk)) {
101216 + err = -EPERM;
101217 + goto error;
101218 + }
101219 +
101220 + err = gr_search_listen(sock);
101221 + if (err)
101222 + goto error;
101223 +
101224 err = security_socket_listen(sock, backlog);
101225 if (!err)
101226 err = sock->ops->listen(sock, backlog);
101227
101228 +error:
101229 fput_light(sock->file, fput_needed);
101230 }
101231 return err;
101232 @@ -1591,6 +1629,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101233 newsock->type = sock->type;
101234 newsock->ops = sock->ops;
101235
101236 + if (gr_handle_sock_server_other(sock->sk)) {
101237 + err = -EPERM;
101238 + sock_release(newsock);
101239 + goto out_put;
101240 + }
101241 +
101242 + err = gr_search_accept(sock);
101243 + if (err) {
101244 + sock_release(newsock);
101245 + goto out_put;
101246 + }
101247 +
101248 /*
101249 * We don't need try_module_get here, as the listening socket (sock)
101250 * has the protocol module (sock->ops->owner) held.
101251 @@ -1636,6 +1686,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101252 fd_install(newfd, newfile);
101253 err = newfd;
101254
101255 + gr_attach_curr_ip(newsock->sk);
101256 +
101257 out_put:
101258 fput_light(sock->file, fput_needed);
101259 out:
101260 @@ -1668,6 +1720,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101261 int, addrlen)
101262 {
101263 struct socket *sock;
101264 + struct sockaddr *sck;
101265 struct sockaddr_storage address;
101266 int err, fput_needed;
101267
101268 @@ -1678,6 +1731,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101269 if (err < 0)
101270 goto out_put;
101271
101272 + sck = (struct sockaddr *)&address;
101273 +
101274 + if (gr_handle_sock_client(sck)) {
101275 + err = -EACCES;
101276 + goto out_put;
101277 + }
101278 +
101279 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
101280 + if (err)
101281 + goto out_put;
101282 +
101283 err =
101284 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
101285 if (err)
101286 @@ -1759,6 +1823,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
101287 * the protocol.
101288 */
101289
101290 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
101291 +
101292 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
101293 unsigned int, flags, struct sockaddr __user *, addr,
101294 int, addr_len)
101295 @@ -1972,6 +2038,10 @@ static int copy_msghdr_from_user(struct msghdr *kmsg,
101296 {
101297 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
101298 return -EFAULT;
101299 +
101300 + if (kmsg->msg_namelen < 0)
101301 + return -EINVAL;
101302 +
101303 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101304 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101305 return 0;
101306 @@ -2047,7 +2117,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
101307 * checking falls down on this.
101308 */
101309 if (copy_from_user(ctl_buf,
101310 - (void __user __force *)msg_sys->msg_control,
101311 + (void __force_user *)msg_sys->msg_control,
101312 ctl_len))
101313 goto out_freectl;
101314 msg_sys->msg_control = ctl_buf;
101315 @@ -2227,7 +2297,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101316 /* Save the user-mode address (verify_iovec will change the
101317 * kernel msghdr to use the kernel address space)
101318 */
101319 - uaddr = (__force void __user *)msg_sys->msg_name;
101320 + uaddr = (void __force_user *)msg_sys->msg_name;
101321 uaddr_len = COMPAT_NAMELEN(msg);
101322 if (MSG_CMSG_COMPAT & flags)
101323 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
101324 @@ -2871,7 +2941,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
101325 ifr = compat_alloc_user_space(buf_size);
101326 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
101327
101328 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
101329 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
101330 return -EFAULT;
101331
101332 if (put_user(convert_in ? rxnfc : compat_ptr(data),
101333 @@ -2985,14 +3055,14 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
101334 old_fs = get_fs();
101335 set_fs(KERNEL_DS);
101336 err = dev_ioctl(net, cmd,
101337 - (struct ifreq __user __force *) &kifr);
101338 + (struct ifreq __force_user *) &kifr);
101339 set_fs(old_fs);
101340
101341 return err;
101342 case SIOCBONDSLAVEINFOQUERY:
101343 case SIOCBONDINFOQUERY:
101344 uifr = compat_alloc_user_space(sizeof(*uifr));
101345 - if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
101346 + if (copy_in_user(uifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
101347 return -EFAULT;
101348
101349 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
101350 @@ -3094,7 +3164,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
101351
101352 old_fs = get_fs();
101353 set_fs(KERNEL_DS);
101354 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
101355 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
101356 set_fs(old_fs);
101357
101358 if (cmd == SIOCGIFMAP && !err) {
101359 @@ -3199,7 +3269,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
101360 ret |= get_user(rtdev, &(ur4->rt_dev));
101361 if (rtdev) {
101362 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
101363 - r4.rt_dev = (char __user __force *)devname;
101364 + r4.rt_dev = (char __force_user *)devname;
101365 devname[15] = 0;
101366 } else
101367 r4.rt_dev = NULL;
101368 @@ -3425,8 +3495,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
101369 int __user *uoptlen;
101370 int err;
101371
101372 - uoptval = (char __user __force *) optval;
101373 - uoptlen = (int __user __force *) optlen;
101374 + uoptval = (char __force_user *) optval;
101375 + uoptlen = (int __force_user *) optlen;
101376
101377 set_fs(KERNEL_DS);
101378 if (level == SOL_SOCKET)
101379 @@ -3446,7 +3516,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
101380 char __user *uoptval;
101381 int err;
101382
101383 - uoptval = (char __user __force *) optval;
101384 + uoptval = (char __force_user *) optval;
101385
101386 set_fs(KERNEL_DS);
101387 if (level == SOL_SOCKET)
101388 diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
101389 index a642fd616..1eebf22 100644
101390 --- a/net/sunrpc/auth_gss/auth_gss.c
101391 +++ b/net/sunrpc/auth_gss/auth_gss.c
101392 @@ -500,10 +500,12 @@ gss_alloc_msg(struct gss_auth *gss_auth,
101393 default:
101394 err = gss_encode_v1_msg(gss_msg, service_name, gss_auth->target_name);
101395 if (err)
101396 - goto err_free_msg;
101397 + goto err_put_pipe_version;
101398 };
101399 kref_get(&gss_auth->kref);
101400 return gss_msg;
101401 +err_put_pipe_version:
101402 + put_pipe_version(gss_auth->net);
101403 err_free_msg:
101404 kfree(gss_msg);
101405 err:
101406 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
101407 index 1b94a9c..496f7f5 100644
101408 --- a/net/sunrpc/auth_gss/svcauth_gss.c
101409 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
101410 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101411 uint64_t *handle)
101412 {
101413 struct rsc rsci, *rscp = NULL;
101414 - static atomic64_t ctxhctr;
101415 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
101416 long long ctxh;
101417 struct gss_api_mech *gm = NULL;
101418 time_t expiry;
101419 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101420 status = -ENOMEM;
101421 /* the handle needs to be just a unique id,
101422 * use a static counter */
101423 - ctxh = atomic64_inc_return(&ctxhctr);
101424 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
101425
101426 /* make a copy for the caller */
101427 *handle = ctxh;
101428 diff --git a/net/sunrpc/backchannel_rqst.c b/net/sunrpc/backchannel_rqst.c
101429 index 890a299..e860d4f 100644
101430 --- a/net/sunrpc/backchannel_rqst.c
101431 +++ b/net/sunrpc/backchannel_rqst.c
101432 @@ -64,7 +64,6 @@ static void xprt_free_allocation(struct rpc_rqst *req)
101433 free_page((unsigned long)xbufp->head[0].iov_base);
101434 xbufp = &req->rq_snd_buf;
101435 free_page((unsigned long)xbufp->head[0].iov_base);
101436 - list_del(&req->rq_bc_pa_list);
101437 kfree(req);
101438 }
101439
101440 @@ -168,8 +167,10 @@ out_free:
101441 /*
101442 * Memory allocation failed, free the temporary list
101443 */
101444 - list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list)
101445 + list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list) {
101446 + list_del(&req->rq_bc_pa_list);
101447 xprt_free_allocation(req);
101448 + }
101449
101450 dprintk("RPC: setup backchannel transport failed\n");
101451 return -ENOMEM;
101452 @@ -198,6 +199,7 @@ void xprt_destroy_backchannel(struct rpc_xprt *xprt, unsigned int max_reqs)
101453 xprt_dec_alloc_count(xprt, max_reqs);
101454 list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) {
101455 dprintk("RPC: req=%p\n", req);
101456 + list_del(&req->rq_bc_pa_list);
101457 xprt_free_allocation(req);
101458 if (--max_reqs == 0)
101459 break;
101460 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
101461 index e726e16..393c39e 100644
101462 --- a/net/sunrpc/clnt.c
101463 +++ b/net/sunrpc/clnt.c
101464 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
101465 (RPC_IS_ASYNC(task) ? "async" : "sync"));
101466
101467 /* Increment call count */
101468 - task->tk_msg.rpc_proc->p_count++;
101469 + pax_open_kernel();
101470 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
101471 + pax_close_kernel();
101472 clnt->cl_stats->rpccnt++;
101473 task->tk_action = call_reserve;
101474 }
101475 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
101476 index ff3cc4b..7612a9e 100644
101477 --- a/net/sunrpc/sched.c
101478 +++ b/net/sunrpc/sched.c
101479 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
101480 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
101481 static void rpc_task_set_debuginfo(struct rpc_task *task)
101482 {
101483 - static atomic_t rpc_pid;
101484 + static atomic_unchecked_t rpc_pid;
101485
101486 - task->tk_pid = atomic_inc_return(&rpc_pid);
101487 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
101488 }
101489 #else
101490 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
101491 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
101492 index e7fbe36..8052603 100644
101493 --- a/net/sunrpc/svc.c
101494 +++ b/net/sunrpc/svc.c
101495 @@ -1158,7 +1158,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
101496 svc_putnl(resv, RPC_SUCCESS);
101497
101498 /* Bump per-procedure stats counter */
101499 - procp->pc_count++;
101500 + pax_open_kernel();
101501 + (*(unsigned int *)&procp->pc_count)++;
101502 + pax_close_kernel();
101503
101504 /* Initialize storage for argp and resp */
101505 memset(rqstp->rq_argp, 0, procp->pc_argsize);
101506 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
101507 index 621ca7b..59421dd 100644
101508 --- a/net/sunrpc/svcauth_unix.c
101509 +++ b/net/sunrpc/svcauth_unix.c
101510 @@ -414,7 +414,7 @@ struct unix_gid {
101511 struct group_info *gi;
101512 };
101513
101514 -static int unix_gid_hash(kuid_t uid)
101515 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
101516 {
101517 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
101518 }
101519 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
101520 (*bpp)[-1] = '\n';
101521 }
101522
101523 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101524 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101525
101526 static int unix_gid_parse(struct cache_detail *cd,
101527 char *mesg, int mlen)
101528 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
101529 index c1b6270..05089c1 100644
101530 --- a/net/sunrpc/xprtrdma/svc_rdma.c
101531 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
101532 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
101533 static unsigned int min_max_inline = 4096;
101534 static unsigned int max_max_inline = 65536;
101535
101536 -atomic_t rdma_stat_recv;
101537 -atomic_t rdma_stat_read;
101538 -atomic_t rdma_stat_write;
101539 -atomic_t rdma_stat_sq_starve;
101540 -atomic_t rdma_stat_rq_starve;
101541 -atomic_t rdma_stat_rq_poll;
101542 -atomic_t rdma_stat_rq_prod;
101543 -atomic_t rdma_stat_sq_poll;
101544 -atomic_t rdma_stat_sq_prod;
101545 +atomic_unchecked_t rdma_stat_recv;
101546 +atomic_unchecked_t rdma_stat_read;
101547 +atomic_unchecked_t rdma_stat_write;
101548 +atomic_unchecked_t rdma_stat_sq_starve;
101549 +atomic_unchecked_t rdma_stat_rq_starve;
101550 +atomic_unchecked_t rdma_stat_rq_poll;
101551 +atomic_unchecked_t rdma_stat_rq_prod;
101552 +atomic_unchecked_t rdma_stat_sq_poll;
101553 +atomic_unchecked_t rdma_stat_sq_prod;
101554
101555 /* Temporary NFS request map and context caches */
101556 struct kmem_cache *svc_rdma_map_cachep;
101557 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
101558 len -= *ppos;
101559 if (len > *lenp)
101560 len = *lenp;
101561 - if (len && copy_to_user(buffer, str_buf, len))
101562 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
101563 return -EFAULT;
101564 *lenp = len;
101565 *ppos += len;
101566 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
101567 {
101568 .procname = "rdma_stat_read",
101569 .data = &rdma_stat_read,
101570 - .maxlen = sizeof(atomic_t),
101571 + .maxlen = sizeof(atomic_unchecked_t),
101572 .mode = 0644,
101573 .proc_handler = read_reset_stat,
101574 },
101575 {
101576 .procname = "rdma_stat_recv",
101577 .data = &rdma_stat_recv,
101578 - .maxlen = sizeof(atomic_t),
101579 + .maxlen = sizeof(atomic_unchecked_t),
101580 .mode = 0644,
101581 .proc_handler = read_reset_stat,
101582 },
101583 {
101584 .procname = "rdma_stat_write",
101585 .data = &rdma_stat_write,
101586 - .maxlen = sizeof(atomic_t),
101587 + .maxlen = sizeof(atomic_unchecked_t),
101588 .mode = 0644,
101589 .proc_handler = read_reset_stat,
101590 },
101591 {
101592 .procname = "rdma_stat_sq_starve",
101593 .data = &rdma_stat_sq_starve,
101594 - .maxlen = sizeof(atomic_t),
101595 + .maxlen = sizeof(atomic_unchecked_t),
101596 .mode = 0644,
101597 .proc_handler = read_reset_stat,
101598 },
101599 {
101600 .procname = "rdma_stat_rq_starve",
101601 .data = &rdma_stat_rq_starve,
101602 - .maxlen = sizeof(atomic_t),
101603 + .maxlen = sizeof(atomic_unchecked_t),
101604 .mode = 0644,
101605 .proc_handler = read_reset_stat,
101606 },
101607 {
101608 .procname = "rdma_stat_rq_poll",
101609 .data = &rdma_stat_rq_poll,
101610 - .maxlen = sizeof(atomic_t),
101611 + .maxlen = sizeof(atomic_unchecked_t),
101612 .mode = 0644,
101613 .proc_handler = read_reset_stat,
101614 },
101615 {
101616 .procname = "rdma_stat_rq_prod",
101617 .data = &rdma_stat_rq_prod,
101618 - .maxlen = sizeof(atomic_t),
101619 + .maxlen = sizeof(atomic_unchecked_t),
101620 .mode = 0644,
101621 .proc_handler = read_reset_stat,
101622 },
101623 {
101624 .procname = "rdma_stat_sq_poll",
101625 .data = &rdma_stat_sq_poll,
101626 - .maxlen = sizeof(atomic_t),
101627 + .maxlen = sizeof(atomic_unchecked_t),
101628 .mode = 0644,
101629 .proc_handler = read_reset_stat,
101630 },
101631 {
101632 .procname = "rdma_stat_sq_prod",
101633 .data = &rdma_stat_sq_prod,
101634 - .maxlen = sizeof(atomic_t),
101635 + .maxlen = sizeof(atomic_unchecked_t),
101636 .mode = 0644,
101637 .proc_handler = read_reset_stat,
101638 },
101639 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101640 index 0ce7552..d074459 100644
101641 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101642 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101643 @@ -501,7 +501,7 @@ next_sge:
101644 svc_rdma_put_context(ctxt, 0);
101645 goto out;
101646 }
101647 - atomic_inc(&rdma_stat_read);
101648 + atomic_inc_unchecked(&rdma_stat_read);
101649
101650 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
101651 chl_map->ch[ch_no].count -= read_wr.num_sge;
101652 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101653 dto_q);
101654 list_del_init(&ctxt->dto_q);
101655 } else {
101656 - atomic_inc(&rdma_stat_rq_starve);
101657 + atomic_inc_unchecked(&rdma_stat_rq_starve);
101658 clear_bit(XPT_DATA, &xprt->xpt_flags);
101659 ctxt = NULL;
101660 }
101661 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101662 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
101663 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
101664 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
101665 - atomic_inc(&rdma_stat_recv);
101666 + atomic_inc_unchecked(&rdma_stat_recv);
101667
101668 /* Build up the XDR from the receive buffers. */
101669 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
101670 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101671 index c1d124d..acfc59e 100644
101672 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101673 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101674 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
101675 write_wr.wr.rdma.remote_addr = to;
101676
101677 /* Post It */
101678 - atomic_inc(&rdma_stat_write);
101679 + atomic_inc_unchecked(&rdma_stat_write);
101680 if (svc_rdma_send(xprt, &write_wr))
101681 goto err;
101682 return 0;
101683 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101684 index 62e4f9b..dd3f2d7 100644
101685 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
101686 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101687 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101688 return;
101689
101690 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
101691 - atomic_inc(&rdma_stat_rq_poll);
101692 + atomic_inc_unchecked(&rdma_stat_rq_poll);
101693
101694 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
101695 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
101696 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101697 }
101698
101699 if (ctxt)
101700 - atomic_inc(&rdma_stat_rq_prod);
101701 + atomic_inc_unchecked(&rdma_stat_rq_prod);
101702
101703 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
101704 /*
101705 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
101706 return;
101707
101708 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
101709 - atomic_inc(&rdma_stat_sq_poll);
101710 + atomic_inc_unchecked(&rdma_stat_sq_poll);
101711 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
101712 if (wc.status != IB_WC_SUCCESS)
101713 /* Close the transport */
101714 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
101715 }
101716
101717 if (ctxt)
101718 - atomic_inc(&rdma_stat_sq_prod);
101719 + atomic_inc_unchecked(&rdma_stat_sq_prod);
101720 }
101721
101722 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
101723 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
101724 spin_lock_bh(&xprt->sc_lock);
101725 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
101726 spin_unlock_bh(&xprt->sc_lock);
101727 - atomic_inc(&rdma_stat_sq_starve);
101728 + atomic_inc_unchecked(&rdma_stat_sq_starve);
101729
101730 /* See if we can opportunistically reap SQ WR to make room */
101731 sq_cq_reap(xprt);
101732 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
101733 index e7000be..e3b0ba7 100644
101734 --- a/net/sysctl_net.c
101735 +++ b/net/sysctl_net.c
101736 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
101737 kgid_t root_gid = make_kgid(net->user_ns, 0);
101738
101739 /* Allow network administrator to have same access as root. */
101740 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
101741 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
101742 uid_eq(root_uid, current_euid())) {
101743 int mode = (table->mode >> 6) & 7;
101744 return (mode << 6) | (mode << 3) | mode;
101745 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
101746 index d38bb45..38d5df5 100644
101747 --- a/net/tipc/subscr.c
101748 +++ b/net/tipc/subscr.c
101749 @@ -98,7 +98,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
101750 struct kvec msg_sect;
101751 int ret;
101752
101753 - msg_sect.iov_base = (void *)&sub->evt;
101754 + msg_sect.iov_base = &sub->evt;
101755 msg_sect.iov_len = sizeof(struct tipc_event);
101756
101757 sub->evt.event = htohl(event, sub->swap);
101758 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
101759 index a427623..387c80b 100644
101760 --- a/net/unix/af_unix.c
101761 +++ b/net/unix/af_unix.c
101762 @@ -790,6 +790,12 @@ static struct sock *unix_find_other(struct net *net,
101763 err = -ECONNREFUSED;
101764 if (!S_ISSOCK(inode->i_mode))
101765 goto put_fail;
101766 +
101767 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
101768 + err = -EACCES;
101769 + goto put_fail;
101770 + }
101771 +
101772 u = unix_find_socket_byinode(inode);
101773 if (!u)
101774 goto put_fail;
101775 @@ -810,6 +816,13 @@ static struct sock *unix_find_other(struct net *net,
101776 if (u) {
101777 struct dentry *dentry;
101778 dentry = unix_sk(u)->path.dentry;
101779 +
101780 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
101781 + err = -EPERM;
101782 + sock_put(u);
101783 + goto fail;
101784 + }
101785 +
101786 if (dentry)
101787 touch_atime(&unix_sk(u)->path);
101788 } else
101789 @@ -843,12 +856,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
101790 */
101791 err = security_path_mknod(&path, dentry, mode, 0);
101792 if (!err) {
101793 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
101794 + err = -EACCES;
101795 + goto out;
101796 + }
101797 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
101798 if (!err) {
101799 res->mnt = mntget(path.mnt);
101800 res->dentry = dget(dentry);
101801 + gr_handle_create(dentry, path.mnt);
101802 }
101803 }
101804 +out:
101805 done_path_create(&path, dentry);
101806 return err;
101807 }
101808 @@ -2336,9 +2355,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
101809 seq_puts(seq, "Num RefCount Protocol Flags Type St "
101810 "Inode Path\n");
101811 else {
101812 - struct sock *s = v;
101813 + struct sock *s = v, *peer;
101814 struct unix_sock *u = unix_sk(s);
101815 unix_state_lock(s);
101816 + peer = unix_peer(s);
101817 + unix_state_unlock(s);
101818 +
101819 + unix_state_double_lock(s, peer);
101820
101821 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
101822 s,
101823 @@ -2365,8 +2388,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
101824 }
101825 for ( ; i < len; i++)
101826 seq_putc(seq, u->addr->name->sun_path[i]);
101827 - }
101828 - unix_state_unlock(s);
101829 + } else if (peer)
101830 + seq_printf(seq, " P%lu", sock_i_ino(peer));
101831 +
101832 + unix_state_double_unlock(s, peer);
101833 seq_putc(seq, '\n');
101834 }
101835
101836 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
101837 index b3d5150..ff3a837 100644
101838 --- a/net/unix/sysctl_net_unix.c
101839 +++ b/net/unix/sysctl_net_unix.c
101840 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
101841
101842 int __net_init unix_sysctl_register(struct net *net)
101843 {
101844 - struct ctl_table *table;
101845 + ctl_table_no_const *table;
101846
101847 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
101848 if (table == NULL)
101849 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
101850 index 9a73074..aecba9a 100644
101851 --- a/net/vmw_vsock/vmci_transport_notify.c
101852 +++ b/net/vmw_vsock/vmci_transport_notify.c
101853 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
101854
101855 /* Socket control packet based operations. */
101856 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
101857 - vmci_transport_notify_pkt_socket_init,
101858 - vmci_transport_notify_pkt_socket_destruct,
101859 - vmci_transport_notify_pkt_poll_in,
101860 - vmci_transport_notify_pkt_poll_out,
101861 - vmci_transport_notify_pkt_handle_pkt,
101862 - vmci_transport_notify_pkt_recv_init,
101863 - vmci_transport_notify_pkt_recv_pre_block,
101864 - vmci_transport_notify_pkt_recv_pre_dequeue,
101865 - vmci_transport_notify_pkt_recv_post_dequeue,
101866 - vmci_transport_notify_pkt_send_init,
101867 - vmci_transport_notify_pkt_send_pre_block,
101868 - vmci_transport_notify_pkt_send_pre_enqueue,
101869 - vmci_transport_notify_pkt_send_post_enqueue,
101870 - vmci_transport_notify_pkt_process_request,
101871 - vmci_transport_notify_pkt_process_negotiate,
101872 + .socket_init = vmci_transport_notify_pkt_socket_init,
101873 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
101874 + .poll_in = vmci_transport_notify_pkt_poll_in,
101875 + .poll_out = vmci_transport_notify_pkt_poll_out,
101876 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
101877 + .recv_init = vmci_transport_notify_pkt_recv_init,
101878 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
101879 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
101880 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
101881 + .send_init = vmci_transport_notify_pkt_send_init,
101882 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
101883 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
101884 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
101885 + .process_request = vmci_transport_notify_pkt_process_request,
101886 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
101887 };
101888 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
101889 index 622bd7a..b92086c 100644
101890 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
101891 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
101892 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
101893
101894 /* Socket always on control packet based operations. */
101895 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
101896 - vmci_transport_notify_pkt_socket_init,
101897 - vmci_transport_notify_pkt_socket_destruct,
101898 - vmci_transport_notify_pkt_poll_in,
101899 - vmci_transport_notify_pkt_poll_out,
101900 - vmci_transport_notify_pkt_handle_pkt,
101901 - vmci_transport_notify_pkt_recv_init,
101902 - vmci_transport_notify_pkt_recv_pre_block,
101903 - vmci_transport_notify_pkt_recv_pre_dequeue,
101904 - vmci_transport_notify_pkt_recv_post_dequeue,
101905 - vmci_transport_notify_pkt_send_init,
101906 - vmci_transport_notify_pkt_send_pre_block,
101907 - vmci_transport_notify_pkt_send_pre_enqueue,
101908 - vmci_transport_notify_pkt_send_post_enqueue,
101909 - vmci_transport_notify_pkt_process_request,
101910 - vmci_transport_notify_pkt_process_negotiate,
101911 + .socket_init = vmci_transport_notify_pkt_socket_init,
101912 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
101913 + .poll_in = vmci_transport_notify_pkt_poll_in,
101914 + .poll_out = vmci_transport_notify_pkt_poll_out,
101915 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
101916 + .recv_init = vmci_transport_notify_pkt_recv_init,
101917 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
101918 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
101919 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
101920 + .send_init = vmci_transport_notify_pkt_send_init,
101921 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
101922 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
101923 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
101924 + .process_request = vmci_transport_notify_pkt_process_request,
101925 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
101926 };
101927 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
101928 index c8717c1..08539f5 100644
101929 --- a/net/wireless/wext-core.c
101930 +++ b/net/wireless/wext-core.c
101931 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
101932 */
101933
101934 /* Support for very large requests */
101935 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
101936 - (user_length > descr->max_tokens)) {
101937 + if (user_length > descr->max_tokens) {
101938 /* Allow userspace to GET more than max so
101939 * we can support any size GET requests.
101940 * There is still a limit : -ENOMEM.
101941 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
101942 }
101943 }
101944
101945 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
101946 - /*
101947 - * If this is a GET, but not NOMAX, it means that the extra
101948 - * data is not bounded by userspace, but by max_tokens. Thus
101949 - * set the length to max_tokens. This matches the extra data
101950 - * allocation.
101951 - * The driver should fill it with the number of tokens it
101952 - * provided, and it may check iwp->length rather than having
101953 - * knowledge of max_tokens. If the driver doesn't change the
101954 - * iwp->length, this ioctl just copies back max_token tokens
101955 - * filled with zeroes. Hopefully the driver isn't claiming
101956 - * them to be valid data.
101957 - */
101958 - iwp->length = descr->max_tokens;
101959 - }
101960 -
101961 err = handler(dev, info, (union iwreq_data *) iwp, extra);
101962
101963 iwp->length += essid_compat;
101964 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
101965 index 4323952..a06dfe1 100644
101966 --- a/net/x25/sysctl_net_x25.c
101967 +++ b/net/x25/sysctl_net_x25.c
101968 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
101969 .mode = 0644,
101970 .proc_handler = proc_dointvec,
101971 },
101972 - { 0, },
101973 + { },
101974 };
101975
101976 void __init x25_register_sysctl(void)
101977 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
101978 index 9a91f74..502f6605 100644
101979 --- a/net/xfrm/xfrm_policy.c
101980 +++ b/net/xfrm/xfrm_policy.c
101981 @@ -332,7 +332,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
101982 {
101983 policy->walk.dead = 1;
101984
101985 - atomic_inc(&policy->genid);
101986 + atomic_inc_unchecked(&policy->genid);
101987
101988 if (del_timer(&policy->polq.hold_timer))
101989 xfrm_pol_put(policy);
101990 @@ -660,7 +660,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
101991 hlist_add_head(&policy->bydst, chain);
101992 xfrm_pol_hold(policy);
101993 net->xfrm.policy_count[dir]++;
101994 - atomic_inc(&flow_cache_genid);
101995 + atomic_inc_unchecked(&flow_cache_genid);
101996
101997 /* After previous checking, family can either be AF_INET or AF_INET6 */
101998 if (policy->family == AF_INET)
101999 @@ -1636,7 +1636,7 @@ free_dst:
102000 goto out;
102001 }
102002
102003 -static int inline
102004 +static inline int
102005 xfrm_dst_alloc_copy(void **target, const void *src, int size)
102006 {
102007 if (!*target) {
102008 @@ -1648,7 +1648,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
102009 return 0;
102010 }
102011
102012 -static int inline
102013 +static inline int
102014 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
102015 {
102016 #ifdef CONFIG_XFRM_SUB_POLICY
102017 @@ -1660,7 +1660,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
102018 #endif
102019 }
102020
102021 -static int inline
102022 +static inline int
102023 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
102024 {
102025 #ifdef CONFIG_XFRM_SUB_POLICY
102026 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
102027
102028 xdst->num_pols = num_pols;
102029 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
102030 - xdst->policy_genid = atomic_read(&pols[0]->genid);
102031 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
102032
102033 return xdst;
102034 }
102035 @@ -2582,11 +2582,12 @@ void xfrm_garbage_collect(struct net *net)
102036 }
102037 EXPORT_SYMBOL(xfrm_garbage_collect);
102038
102039 -static void xfrm_garbage_collect_deferred(struct net *net)
102040 +void xfrm_garbage_collect_deferred(struct net *net)
102041 {
102042 flow_cache_flush_deferred();
102043 __xfrm_garbage_collect(net);
102044 }
102045 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
102046
102047 static void xfrm_init_pmtu(struct dst_entry *dst)
102048 {
102049 @@ -2636,7 +2637,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
102050 if (xdst->xfrm_genid != dst->xfrm->genid)
102051 return 0;
102052 if (xdst->num_pols > 0 &&
102053 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
102054 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
102055 return 0;
102056
102057 mtu = dst_mtu(dst->child);
102058 @@ -2724,8 +2725,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
102059 dst_ops->link_failure = xfrm_link_failure;
102060 if (likely(dst_ops->neigh_lookup == NULL))
102061 dst_ops->neigh_lookup = xfrm_neigh_lookup;
102062 - if (likely(afinfo->garbage_collect == NULL))
102063 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
102064 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
102065 }
102066 spin_unlock(&xfrm_policy_afinfo_lock);
102067 @@ -2779,7 +2778,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
102068 dst_ops->check = NULL;
102069 dst_ops->negative_advice = NULL;
102070 dst_ops->link_failure = NULL;
102071 - afinfo->garbage_collect = NULL;
102072 }
102073 return err;
102074 }
102075 @@ -3162,7 +3160,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
102076 sizeof(pol->xfrm_vec[i].saddr));
102077 pol->xfrm_vec[i].encap_family = mp->new_family;
102078 /* flush bundles */
102079 - atomic_inc(&pol->genid);
102080 + atomic_inc_unchecked(&pol->genid);
102081 }
102082 }
102083
102084 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
102085 index 68c2f35..9eb05ca 100644
102086 --- a/net/xfrm/xfrm_state.c
102087 +++ b/net/xfrm/xfrm_state.c
102088 @@ -174,12 +174,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
102089
102090 if (unlikely(afinfo == NULL))
102091 return -EAFNOSUPPORT;
102092 - typemap = afinfo->type_map;
102093 + typemap = (const struct xfrm_type **)afinfo->type_map;
102094 spin_lock_bh(&xfrm_type_lock);
102095
102096 - if (likely(typemap[type->proto] == NULL))
102097 + if (likely(typemap[type->proto] == NULL)) {
102098 + pax_open_kernel();
102099 typemap[type->proto] = type;
102100 - else
102101 + pax_close_kernel();
102102 + } else
102103 err = -EEXIST;
102104 spin_unlock_bh(&xfrm_type_lock);
102105 xfrm_state_put_afinfo(afinfo);
102106 @@ -195,13 +197,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
102107
102108 if (unlikely(afinfo == NULL))
102109 return -EAFNOSUPPORT;
102110 - typemap = afinfo->type_map;
102111 + typemap = (const struct xfrm_type **)afinfo->type_map;
102112 spin_lock_bh(&xfrm_type_lock);
102113
102114 if (unlikely(typemap[type->proto] != type))
102115 err = -ENOENT;
102116 - else
102117 + else {
102118 + pax_open_kernel();
102119 typemap[type->proto] = NULL;
102120 + pax_close_kernel();
102121 + }
102122 spin_unlock_bh(&xfrm_type_lock);
102123 xfrm_state_put_afinfo(afinfo);
102124 return err;
102125 @@ -211,7 +216,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
102126 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
102127 {
102128 struct xfrm_state_afinfo *afinfo;
102129 - const struct xfrm_type **typemap;
102130 const struct xfrm_type *type;
102131 int modload_attempted = 0;
102132
102133 @@ -219,9 +223,8 @@ retry:
102134 afinfo = xfrm_state_get_afinfo(family);
102135 if (unlikely(afinfo == NULL))
102136 return NULL;
102137 - typemap = afinfo->type_map;
102138
102139 - type = typemap[proto];
102140 + type = afinfo->type_map[proto];
102141 if (unlikely(type && !try_module_get(type->owner)))
102142 type = NULL;
102143 if (!type && !modload_attempted) {
102144 @@ -255,7 +258,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102145 return -EAFNOSUPPORT;
102146
102147 err = -EEXIST;
102148 - modemap = afinfo->mode_map;
102149 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102150 spin_lock_bh(&xfrm_mode_lock);
102151 if (modemap[mode->encap])
102152 goto out;
102153 @@ -264,8 +267,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102154 if (!try_module_get(afinfo->owner))
102155 goto out;
102156
102157 - mode->afinfo = afinfo;
102158 + pax_open_kernel();
102159 + *(const void **)&mode->afinfo = afinfo;
102160 modemap[mode->encap] = mode;
102161 + pax_close_kernel();
102162 err = 0;
102163
102164 out:
102165 @@ -289,10 +294,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
102166 return -EAFNOSUPPORT;
102167
102168 err = -ENOENT;
102169 - modemap = afinfo->mode_map;
102170 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102171 spin_lock_bh(&xfrm_mode_lock);
102172 if (likely(modemap[mode->encap] == mode)) {
102173 + pax_open_kernel();
102174 modemap[mode->encap] = NULL;
102175 + pax_close_kernel();
102176 module_put(mode->afinfo->owner);
102177 err = 0;
102178 }
102179 @@ -1486,10 +1493,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
102180 u32 xfrm_get_acqseq(void)
102181 {
102182 u32 res;
102183 - static atomic_t acqseq;
102184 + static atomic_unchecked_t acqseq;
102185
102186 do {
102187 - res = atomic_inc_return(&acqseq);
102188 + res = atomic_inc_return_unchecked(&acqseq);
102189 } while (!res);
102190
102191 return res;
102192 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
102193 index 05a6e3d..6716ec9 100644
102194 --- a/net/xfrm/xfrm_sysctl.c
102195 +++ b/net/xfrm/xfrm_sysctl.c
102196 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
102197
102198 int __net_init xfrm_sysctl_init(struct net *net)
102199 {
102200 - struct ctl_table *table;
102201 + ctl_table_no_const *table;
102202
102203 __xfrm_sysctl_init(net);
102204
102205 diff --git a/scripts/Makefile b/scripts/Makefile
102206 index 01e7adb..6176d5d 100644
102207 --- a/scripts/Makefile
102208 +++ b/scripts/Makefile
102209 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
102210
102211 # Let clean descend into subdirs
102212 subdir- += basic kconfig package selinux
102213 +
102214 +clean-files := randstruct.seed
102215 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
102216 index d5d859c..781cbcb 100644
102217 --- a/scripts/Makefile.build
102218 +++ b/scripts/Makefile.build
102219 @@ -111,7 +111,7 @@ endif
102220 endif
102221
102222 # Do not include host rules unless needed
102223 -ifneq ($(hostprogs-y)$(hostprogs-m),)
102224 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
102225 include scripts/Makefile.host
102226 endif
102227
102228 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
102229 index 686cb0d..9d653bf 100644
102230 --- a/scripts/Makefile.clean
102231 +++ b/scripts/Makefile.clean
102232 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
102233 __clean-files := $(extra-y) $(always) \
102234 $(targets) $(clean-files) \
102235 $(host-progs) \
102236 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
102237 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
102238 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
102239
102240 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
102241
102242 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
102243 index 1ac414f..38575f7 100644
102244 --- a/scripts/Makefile.host
102245 +++ b/scripts/Makefile.host
102246 @@ -31,6 +31,8 @@
102247 # Note: Shared libraries consisting of C++ files are not supported
102248
102249 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
102250 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
102251 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
102252
102253 # C code
102254 # Executables compiled from a single .c file
102255 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
102256 # Shared libaries (only .c supported)
102257 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
102258 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
102259 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
102260 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
102261 # Remove .so files from "xxx-objs"
102262 host-cobjs := $(filter-out %.so,$(host-cobjs))
102263 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
102264
102265 -#Object (.o) files used by the shared libaries
102266 +# Object (.o) files used by the shared libaries
102267 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
102268 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
102269
102270 # output directory for programs/.o files
102271 # hostprogs-y := tools/build may have been specified. Retrieve directory
102272 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
102273 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
102274 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
102275 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
102276 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
102277 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
102278 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
102279 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
102280
102281 obj-dirs += $(host-objdirs)
102282 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
102283 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
102284 $(call if_changed_dep,host-cshobjs)
102285
102286 +# Compile .c file, create position independent .o file
102287 +# host-cxxshobjs -> .o
102288 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
102289 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
102290 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
102291 + $(call if_changed_dep,host-cxxshobjs)
102292 +
102293 # Link a shared library, based on position independent .o files
102294 # *.o -> .so shared library (host-cshlib)
102295 quiet_cmd_host-cshlib = HOSTLLD -shared $@
102296 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
102297 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
102298 $(call if_changed,host-cshlib)
102299
102300 +# Link a shared library, based on position independent .o files
102301 +# *.o -> .so shared library (host-cxxshlib)
102302 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
102303 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
102304 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
102305 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
102306 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
102307 + $(call if_changed,host-cxxshlib)
102308 +
102309 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
102310 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
102311 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
102312
102313 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
102314 index 078fe1d..fbdb363 100644
102315 --- a/scripts/basic/fixdep.c
102316 +++ b/scripts/basic/fixdep.c
102317 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
102318 /*
102319 * Lookup a value in the configuration string.
102320 */
102321 -static int is_defined_config(const char *name, int len, unsigned int hash)
102322 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
102323 {
102324 struct item *aux;
102325
102326 @@ -211,10 +211,10 @@ static void clear_config(void)
102327 /*
102328 * Record the use of a CONFIG_* word.
102329 */
102330 -static void use_config(const char *m, int slen)
102331 +static void use_config(const char *m, unsigned int slen)
102332 {
102333 unsigned int hash = strhash(m, slen);
102334 - int c, i;
102335 + unsigned int c, i;
102336
102337 if (is_defined_config(m, slen, hash))
102338 return;
102339 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
102340
102341 static void parse_config_file(const char *map, size_t len)
102342 {
102343 - const int *end = (const int *) (map + len);
102344 + const unsigned int *end = (const unsigned int *) (map + len);
102345 /* start at +1, so that p can never be < map */
102346 - const int *m = (const int *) map + 1;
102347 + const unsigned int *m = (const unsigned int *) map + 1;
102348 const char *p, *q;
102349
102350 for (; m < end; m++) {
102351 @@ -435,7 +435,7 @@ static void print_deps(void)
102352 static void traps(void)
102353 {
102354 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
102355 - int *p = (int *)test;
102356 + unsigned int *p = (unsigned int *)test;
102357
102358 if (*p != INT_CONF) {
102359 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
102360 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
102361 new file mode 100644
102362 index 0000000..5e0222d
102363 --- /dev/null
102364 +++ b/scripts/gcc-plugin.sh
102365 @@ -0,0 +1,17 @@
102366 +#!/bin/bash
102367 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
102368 +#include "gcc-plugin.h"
102369 +#include "tree.h"
102370 +#include "tm.h"
102371 +#include "rtl.h"
102372 +#ifdef ENABLE_BUILD_WITH_CXX
102373 +#warning $2
102374 +#else
102375 +#warning $1
102376 +#endif
102377 +EOF`
102378 +if [ $? -eq 0 ]
102379 +then
102380 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
102381 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
102382 +fi
102383 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
102384 index 5de5660..d3deb89 100644
102385 --- a/scripts/headers_install.sh
102386 +++ b/scripts/headers_install.sh
102387 @@ -32,6 +32,7 @@ do
102388 FILE="$(basename "$i")"
102389 sed -r \
102390 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
102391 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
102392 -e 's/__attribute_const__([ \t]|$)/\1/g' \
102393 -e 's@^#include <linux/compiler.h>@@' \
102394 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
102395 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
102396 index 2dcb377..a82c500 100644
102397 --- a/scripts/link-vmlinux.sh
102398 +++ b/scripts/link-vmlinux.sh
102399 @@ -162,7 +162,7 @@ else
102400 fi;
102401
102402 # final build of init/
102403 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
102404 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
102405
102406 kallsymso=""
102407 kallsyms_vmlinux=""
102408 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
102409 index 25e5cb0..6e85821 100644
102410 --- a/scripts/mod/file2alias.c
102411 +++ b/scripts/mod/file2alias.c
102412 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
102413 unsigned long size, unsigned long id_size,
102414 void *symval)
102415 {
102416 - int i;
102417 + unsigned int i;
102418
102419 if (size % id_size || size < id_size) {
102420 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
102421 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
102422 /* USB is special because the bcdDevice can be matched against a numeric range */
102423 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
102424 static void do_usb_entry(void *symval,
102425 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
102426 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
102427 unsigned char range_lo, unsigned char range_hi,
102428 unsigned char max, struct module *mod)
102429 {
102430 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
102431 {
102432 unsigned int devlo, devhi;
102433 unsigned char chi, clo, max;
102434 - int ndigits;
102435 + unsigned int ndigits;
102436
102437 DEF_FIELD(symval, usb_device_id, match_flags);
102438 DEF_FIELD(symval, usb_device_id, idVendor);
102439 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
102440 for (i = 0; i < count; i++) {
102441 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
102442 char acpi_id[sizeof(*id)];
102443 - int j;
102444 + unsigned int j;
102445
102446 buf_printf(&mod->dev_table_buf,
102447 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
102448 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102449
102450 for (j = 0; j < PNP_MAX_DEVICES; j++) {
102451 const char *id = (char *)(*devs)[j].id;
102452 - int i2, j2;
102453 + unsigned int i2, j2;
102454 int dup = 0;
102455
102456 if (!id[0])
102457 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102458 /* add an individual alias for every device entry */
102459 if (!dup) {
102460 char acpi_id[PNP_ID_LEN];
102461 - int k;
102462 + unsigned int k;
102463
102464 buf_printf(&mod->dev_table_buf,
102465 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
102466 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
102467 static int do_dmi_entry(const char *filename, void *symval,
102468 char *alias)
102469 {
102470 - int i, j;
102471 + unsigned int i, j;
102472 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
102473 sprintf(alias, "dmi*");
102474
102475 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
102476 index 1785576..5e8e06a 100644
102477 --- a/scripts/mod/modpost.c
102478 +++ b/scripts/mod/modpost.c
102479 @@ -941,6 +941,7 @@ enum mismatch {
102480 ANY_INIT_TO_ANY_EXIT,
102481 ANY_EXIT_TO_ANY_INIT,
102482 EXPORT_TO_INIT_EXIT,
102483 + DATA_TO_TEXT
102484 };
102485
102486 struct sectioncheck {
102487 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
102488 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
102489 .mismatch = EXPORT_TO_INIT_EXIT,
102490 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
102491 +},
102492 +/* Do not reference code from writable data */
102493 +{
102494 + .fromsec = { DATA_SECTIONS, NULL },
102495 + .tosec = { TEXT_SECTIONS, NULL },
102496 + .mismatch = DATA_TO_TEXT
102497 }
102498 };
102499
102500 @@ -1147,10 +1154,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
102501 continue;
102502 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
102503 continue;
102504 - if (sym->st_value == addr)
102505 - return sym;
102506 /* Find a symbol nearby - addr are maybe negative */
102507 d = sym->st_value - addr;
102508 + if (d == 0)
102509 + return sym;
102510 if (d < 0)
102511 d = addr - sym->st_value;
102512 if (d < distance) {
102513 @@ -1428,6 +1435,14 @@ static void report_sec_mismatch(const char *modname,
102514 tosym, prl_to, prl_to, tosym);
102515 free(prl_to);
102516 break;
102517 + case DATA_TO_TEXT:
102518 +#if 0
102519 + fprintf(stderr,
102520 + "The %s %s:%s references\n"
102521 + "the %s %s:%s%s\n",
102522 + from, fromsec, fromsym, to, tosec, tosym, to_p);
102523 +#endif
102524 + break;
102525 }
102526 fprintf(stderr, "\n");
102527 }
102528 @@ -1662,7 +1677,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
102529 static void check_sec_ref(struct module *mod, const char *modname,
102530 struct elf_info *elf)
102531 {
102532 - int i;
102533 + unsigned int i;
102534 Elf_Shdr *sechdrs = elf->sechdrs;
102535
102536 /* Walk through all sections */
102537 @@ -1781,7 +1796,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
102538 va_end(ap);
102539 }
102540
102541 -void buf_write(struct buffer *buf, const char *s, int len)
102542 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
102543 {
102544 if (buf->size - buf->pos < len) {
102545 buf->size += len + SZ;
102546 @@ -2000,7 +2015,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
102547 if (fstat(fileno(file), &st) < 0)
102548 goto close_write;
102549
102550 - if (st.st_size != b->pos)
102551 + if (st.st_size != (off_t)b->pos)
102552 goto close_write;
102553
102554 tmp = NOFAIL(malloc(b->pos));
102555 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
102556 index 51207e4..f7d603d 100644
102557 --- a/scripts/mod/modpost.h
102558 +++ b/scripts/mod/modpost.h
102559 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
102560
102561 struct buffer {
102562 char *p;
102563 - int pos;
102564 - int size;
102565 + unsigned int pos;
102566 + unsigned int size;
102567 };
102568
102569 void __attribute__((format(printf, 2, 3)))
102570 buf_printf(struct buffer *buf, const char *fmt, ...);
102571
102572 void
102573 -buf_write(struct buffer *buf, const char *s, int len);
102574 +buf_write(struct buffer *buf, const char *s, unsigned int len);
102575
102576 struct module {
102577 struct module *next;
102578 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
102579 index deb2994..af4f63e 100644
102580 --- a/scripts/mod/sumversion.c
102581 +++ b/scripts/mod/sumversion.c
102582 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
102583 goto out;
102584 }
102585
102586 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
102587 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
102588 warn("writing sum in %s failed: %s\n",
102589 filename, strerror(errno));
102590 goto out;
102591 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
102592 index 0865b3e..7235dd4 100644
102593 --- a/scripts/module-common.lds
102594 +++ b/scripts/module-common.lds
102595 @@ -6,6 +6,10 @@
102596 SECTIONS {
102597 /DISCARD/ : { *(.discard) }
102598
102599 + .rodata : {
102600 + *(.rodata) *(.rodata.*)
102601 + *(.data..read_only)
102602 + }
102603 __ksymtab : { *(SORT(___ksymtab+*)) }
102604 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
102605 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
102606 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
102607 index 90e521f..e9eaf8f 100644
102608 --- a/scripts/package/builddeb
102609 +++ b/scripts/package/builddeb
102610 @@ -281,6 +281,7 @@ fi
102611 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
102612 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
102613 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
102614 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
102615 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
102616 mkdir -p "$destdir"
102617 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
102618 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
102619 index 68bb4ef..2f419e1 100644
102620 --- a/scripts/pnmtologo.c
102621 +++ b/scripts/pnmtologo.c
102622 @@ -244,14 +244,14 @@ static void write_header(void)
102623 fprintf(out, " * Linux logo %s\n", logoname);
102624 fputs(" */\n\n", out);
102625 fputs("#include <linux/linux_logo.h>\n\n", out);
102626 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
102627 + fprintf(out, "static unsigned char %s_data[] = {\n",
102628 logoname);
102629 }
102630
102631 static void write_footer(void)
102632 {
102633 fputs("\n};\n\n", out);
102634 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
102635 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
102636 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
102637 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
102638 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
102639 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
102640 fputs("\n};\n\n", out);
102641
102642 /* write logo clut */
102643 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
102644 + fprintf(out, "static unsigned char %s_clut[] = {\n",
102645 logoname);
102646 write_hex_cnt = 0;
102647 for (i = 0; i < logo_clutsize; i++) {
102648 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
102649 index 8fac3fd..32ff38d 100644
102650 --- a/scripts/sortextable.h
102651 +++ b/scripts/sortextable.h
102652 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
102653 const char *secstrtab;
102654 const char *strtab;
102655 char *extab_image;
102656 - int extab_index = 0;
102657 - int i;
102658 - int idx;
102659 + unsigned int extab_index = 0;
102660 + unsigned int i;
102661 + unsigned int idx;
102662 unsigned int num_sections;
102663 unsigned int secindex_strings;
102664
102665 diff --git a/security/Kconfig b/security/Kconfig
102666 index e9c6ac7..75578c4 100644
102667 --- a/security/Kconfig
102668 +++ b/security/Kconfig
102669 @@ -4,6 +4,960 @@
102670
102671 menu "Security options"
102672
102673 +menu "Grsecurity"
102674 +
102675 + config ARCH_TRACK_EXEC_LIMIT
102676 + bool
102677 +
102678 + config PAX_KERNEXEC_PLUGIN
102679 + bool
102680 +
102681 + config PAX_PER_CPU_PGD
102682 + bool
102683 +
102684 + config TASK_SIZE_MAX_SHIFT
102685 + int
102686 + depends on X86_64
102687 + default 47 if !PAX_PER_CPU_PGD
102688 + default 42 if PAX_PER_CPU_PGD
102689 +
102690 + config PAX_ENABLE_PAE
102691 + bool
102692 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
102693 +
102694 + config PAX_USERCOPY_SLABS
102695 + bool
102696 +
102697 +config GRKERNSEC
102698 + bool "Grsecurity"
102699 + select CRYPTO
102700 + select CRYPTO_SHA256
102701 + select PROC_FS
102702 + select STOP_MACHINE
102703 + select TTY
102704 + select DEBUG_KERNEL
102705 + select DEBUG_LIST
102706 + help
102707 + If you say Y here, you will be able to configure many features
102708 + that will enhance the security of your system. It is highly
102709 + recommended that you say Y here and read through the help
102710 + for each option so that you fully understand the features and
102711 + can evaluate their usefulness for your machine.
102712 +
102713 +choice
102714 + prompt "Configuration Method"
102715 + depends on GRKERNSEC
102716 + default GRKERNSEC_CONFIG_CUSTOM
102717 + help
102718 +
102719 +config GRKERNSEC_CONFIG_AUTO
102720 + bool "Automatic"
102721 + help
102722 + If you choose this configuration method, you'll be able to answer a small
102723 + number of simple questions about how you plan to use this kernel.
102724 + The settings of grsecurity and PaX will be automatically configured for
102725 + the highest commonly-used settings within the provided constraints.
102726 +
102727 + If you require additional configuration, custom changes can still be made
102728 + from the "custom configuration" menu.
102729 +
102730 +config GRKERNSEC_CONFIG_CUSTOM
102731 + bool "Custom"
102732 + help
102733 + If you choose this configuration method, you'll be able to configure all
102734 + grsecurity and PaX settings manually. Via this method, no options are
102735 + automatically enabled.
102736 +
102737 +endchoice
102738 +
102739 +choice
102740 + prompt "Usage Type"
102741 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102742 + default GRKERNSEC_CONFIG_SERVER
102743 + help
102744 +
102745 +config GRKERNSEC_CONFIG_SERVER
102746 + bool "Server"
102747 + help
102748 + Choose this option if you plan to use this kernel on a server.
102749 +
102750 +config GRKERNSEC_CONFIG_DESKTOP
102751 + bool "Desktop"
102752 + help
102753 + Choose this option if you plan to use this kernel on a desktop.
102754 +
102755 +endchoice
102756 +
102757 +choice
102758 + prompt "Virtualization Type"
102759 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
102760 + default GRKERNSEC_CONFIG_VIRT_NONE
102761 + help
102762 +
102763 +config GRKERNSEC_CONFIG_VIRT_NONE
102764 + bool "None"
102765 + help
102766 + Choose this option if this kernel will be run on bare metal.
102767 +
102768 +config GRKERNSEC_CONFIG_VIRT_GUEST
102769 + bool "Guest"
102770 + help
102771 + Choose this option if this kernel will be run as a VM guest.
102772 +
102773 +config GRKERNSEC_CONFIG_VIRT_HOST
102774 + bool "Host"
102775 + help
102776 + Choose this option if this kernel will be run as a VM host.
102777 +
102778 +endchoice
102779 +
102780 +choice
102781 + prompt "Virtualization Hardware"
102782 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
102783 + help
102784 +
102785 +config GRKERNSEC_CONFIG_VIRT_EPT
102786 + bool "EPT/RVI Processor Support"
102787 + depends on X86
102788 + help
102789 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
102790 + hardware virtualization. This allows for additional kernel hardening protections
102791 + to operate without additional performance impact.
102792 +
102793 + To see if your Intel processor supports EPT, see:
102794 + http://ark.intel.com/Products/VirtualizationTechnology
102795 + (Most Core i3/5/7 support EPT)
102796 +
102797 + To see if your AMD processor supports RVI, see:
102798 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
102799 +
102800 +config GRKERNSEC_CONFIG_VIRT_SOFT
102801 + bool "First-gen/No Hardware Virtualization"
102802 + help
102803 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
102804 + support hardware virtualization or doesn't support the EPT/RVI extensions.
102805 +
102806 +endchoice
102807 +
102808 +choice
102809 + prompt "Virtualization Software"
102810 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
102811 + help
102812 +
102813 +config GRKERNSEC_CONFIG_VIRT_XEN
102814 + bool "Xen"
102815 + help
102816 + Choose this option if this kernel is running as a Xen guest or host.
102817 +
102818 +config GRKERNSEC_CONFIG_VIRT_VMWARE
102819 + bool "VMWare"
102820 + help
102821 + Choose this option if this kernel is running as a VMWare guest or host.
102822 +
102823 +config GRKERNSEC_CONFIG_VIRT_KVM
102824 + bool "KVM"
102825 + help
102826 + Choose this option if this kernel is running as a KVM guest or host.
102827 +
102828 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
102829 + bool "VirtualBox"
102830 + help
102831 + Choose this option if this kernel is running as a VirtualBox guest or host.
102832 +
102833 +endchoice
102834 +
102835 +choice
102836 + prompt "Required Priorities"
102837 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102838 + default GRKERNSEC_CONFIG_PRIORITY_PERF
102839 + help
102840 +
102841 +config GRKERNSEC_CONFIG_PRIORITY_PERF
102842 + bool "Performance"
102843 + help
102844 + Choose this option if performance is of highest priority for this deployment
102845 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
102846 + clearing of structures intended for userland, and freed memory sanitizing will
102847 + be disabled.
102848 +
102849 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
102850 + bool "Security"
102851 + help
102852 + Choose this option if security is of highest priority for this deployment of
102853 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
102854 + for userland, and freed memory sanitizing will be enabled for this kernel.
102855 + In a worst-case scenario, these features can introduce a 20% performance hit
102856 + (UDEREF on x64 contributing half of this hit).
102857 +
102858 +endchoice
102859 +
102860 +menu "Default Special Groups"
102861 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102862 +
102863 +config GRKERNSEC_PROC_GID
102864 + int "GID exempted from /proc restrictions"
102865 + default 1001
102866 + help
102867 + Setting this GID determines which group will be exempted from
102868 + grsecurity's /proc restrictions, allowing users of the specified
102869 + group to view network statistics and the existence of other users'
102870 + processes on the system. This GID may also be chosen at boot time
102871 + via "grsec_proc_gid=" on the kernel commandline.
102872 +
102873 +config GRKERNSEC_TPE_UNTRUSTED_GID
102874 + int "GID for TPE-untrusted users"
102875 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
102876 + default 1005
102877 + help
102878 + Setting this GID determines which group untrusted users should
102879 + be added to. These users will be placed under grsecurity's Trusted Path
102880 + Execution mechanism, preventing them from executing their own binaries.
102881 + The users will only be able to execute binaries in directories owned and
102882 + writable only by the root user. If the sysctl option is enabled, a sysctl
102883 + option with name "tpe_gid" is created.
102884 +
102885 +config GRKERNSEC_TPE_TRUSTED_GID
102886 + int "GID for TPE-trusted users"
102887 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
102888 + default 1005
102889 + help
102890 + Setting this GID determines what group TPE restrictions will be
102891 + *disabled* for. If the sysctl option is enabled, a sysctl option
102892 + with name "tpe_gid" is created.
102893 +
102894 +config GRKERNSEC_SYMLINKOWN_GID
102895 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
102896 + depends on GRKERNSEC_CONFIG_SERVER
102897 + default 1006
102898 + help
102899 + Setting this GID determines what group kernel-enforced
102900 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
102901 + is enabled, a sysctl option with name "symlinkown_gid" is created.
102902 +
102903 +
102904 +endmenu
102905 +
102906 +menu "Customize Configuration"
102907 +depends on GRKERNSEC
102908 +
102909 +menu "PaX"
102910 +
102911 +config PAX
102912 + bool "Enable various PaX features"
102913 + default y if GRKERNSEC_CONFIG_AUTO
102914 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
102915 + help
102916 + This allows you to enable various PaX features. PaX adds
102917 + intrusion prevention mechanisms to the kernel that reduce
102918 + the risks posed by exploitable memory corruption bugs.
102919 +
102920 +menu "PaX Control"
102921 + depends on PAX
102922 +
102923 +config PAX_SOFTMODE
102924 + bool 'Support soft mode'
102925 + help
102926 + Enabling this option will allow you to run PaX in soft mode, that
102927 + is, PaX features will not be enforced by default, only on executables
102928 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
102929 + support as they are the only way to mark executables for soft mode use.
102930 +
102931 + Soft mode can be activated by using the "pax_softmode=1" kernel command
102932 + line option on boot. Furthermore you can control various PaX features
102933 + at runtime via the entries in /proc/sys/kernel/pax.
102934 +
102935 +config PAX_EI_PAX
102936 + bool 'Use legacy ELF header marking'
102937 + default y if GRKERNSEC_CONFIG_AUTO
102938 + help
102939 + Enabling this option will allow you to control PaX features on
102940 + a per executable basis via the 'chpax' utility available at
102941 + http://pax.grsecurity.net/. The control flags will be read from
102942 + an otherwise reserved part of the ELF header. This marking has
102943 + numerous drawbacks (no support for soft-mode, toolchain does not
102944 + know about the non-standard use of the ELF header) therefore it
102945 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
102946 + support.
102947 +
102948 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
102949 + support as well, they will override the legacy EI_PAX marks.
102950 +
102951 + If you enable none of the marking options then all applications
102952 + will run with PaX enabled on them by default.
102953 +
102954 +config PAX_PT_PAX_FLAGS
102955 + bool 'Use ELF program header marking'
102956 + default y if GRKERNSEC_CONFIG_AUTO
102957 + help
102958 + Enabling this option will allow you to control PaX features on
102959 + a per executable basis via the 'paxctl' utility available at
102960 + http://pax.grsecurity.net/. The control flags will be read from
102961 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
102962 + has the benefits of supporting both soft mode and being fully
102963 + integrated into the toolchain (the binutils patch is available
102964 + from http://pax.grsecurity.net).
102965 +
102966 + Note that if you enable the legacy EI_PAX marking support as well,
102967 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
102968 +
102969 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
102970 + must make sure that the marks are the same if a binary has both marks.
102971 +
102972 + If you enable none of the marking options then all applications
102973 + will run with PaX enabled on them by default.
102974 +
102975 +config PAX_XATTR_PAX_FLAGS
102976 + bool 'Use filesystem extended attributes marking'
102977 + default y if GRKERNSEC_CONFIG_AUTO
102978 + select CIFS_XATTR if CIFS
102979 + select EXT2_FS_XATTR if EXT2_FS
102980 + select EXT3_FS_XATTR if EXT3_FS
102981 + select JFFS2_FS_XATTR if JFFS2_FS
102982 + select REISERFS_FS_XATTR if REISERFS_FS
102983 + select SQUASHFS_XATTR if SQUASHFS
102984 + select TMPFS_XATTR if TMPFS
102985 + select UBIFS_FS_XATTR if UBIFS_FS
102986 + help
102987 + Enabling this option will allow you to control PaX features on
102988 + a per executable basis via the 'setfattr' utility. The control
102989 + flags will be read from the user.pax.flags extended attribute of
102990 + the file. This marking has the benefit of supporting binary-only
102991 + applications that self-check themselves (e.g., skype) and would
102992 + not tolerate chpax/paxctl changes. The main drawback is that
102993 + extended attributes are not supported by some filesystems (e.g.,
102994 + isofs, udf, vfat) so copying files through such filesystems will
102995 + lose the extended attributes and these PaX markings.
102996 +
102997 + Note that if you enable the legacy EI_PAX marking support as well,
102998 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
102999 +
103000 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103001 + must make sure that the marks are the same if a binary has both marks.
103002 +
103003 + If you enable none of the marking options then all applications
103004 + will run with PaX enabled on them by default.
103005 +
103006 +choice
103007 + prompt 'MAC system integration'
103008 + default PAX_HAVE_ACL_FLAGS
103009 + help
103010 + Mandatory Access Control systems have the option of controlling
103011 + PaX flags on a per executable basis, choose the method supported
103012 + by your particular system.
103013 +
103014 + - "none": if your MAC system does not interact with PaX,
103015 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
103016 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
103017 +
103018 + NOTE: this option is for developers/integrators only.
103019 +
103020 + config PAX_NO_ACL_FLAGS
103021 + bool 'none'
103022 +
103023 + config PAX_HAVE_ACL_FLAGS
103024 + bool 'direct'
103025 +
103026 + config PAX_HOOK_ACL_FLAGS
103027 + bool 'hook'
103028 +endchoice
103029 +
103030 +endmenu
103031 +
103032 +menu "Non-executable pages"
103033 + depends on PAX
103034 +
103035 +config PAX_NOEXEC
103036 + bool "Enforce non-executable pages"
103037 + default y if GRKERNSEC_CONFIG_AUTO
103038 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
103039 + help
103040 + By design some architectures do not allow for protecting memory
103041 + pages against execution or even if they do, Linux does not make
103042 + use of this feature. In practice this means that if a page is
103043 + readable (such as the stack or heap) it is also executable.
103044 +
103045 + There is a well known exploit technique that makes use of this
103046 + fact and a common programming mistake where an attacker can
103047 + introduce code of his choice somewhere in the attacked program's
103048 + memory (typically the stack or the heap) and then execute it.
103049 +
103050 + If the attacked program was running with different (typically
103051 + higher) privileges than that of the attacker, then he can elevate
103052 + his own privilege level (e.g. get a root shell, write to files for
103053 + which he does not have write access to, etc).
103054 +
103055 + Enabling this option will let you choose from various features
103056 + that prevent the injection and execution of 'foreign' code in
103057 + a program.
103058 +
103059 + This will also break programs that rely on the old behaviour and
103060 + expect that dynamically allocated memory via the malloc() family
103061 + of functions is executable (which it is not). Notable examples
103062 + are the XFree86 4.x server, the java runtime and wine.
103063 +
103064 +config PAX_PAGEEXEC
103065 + bool "Paging based non-executable pages"
103066 + default y if GRKERNSEC_CONFIG_AUTO
103067 + 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)
103068 + select ARCH_TRACK_EXEC_LIMIT if X86_32
103069 + help
103070 + This implementation is based on the paging feature of the CPU.
103071 + On i386 without hardware non-executable bit support there is a
103072 + variable but usually low performance impact, however on Intel's
103073 + P4 core based CPUs it is very high so you should not enable this
103074 + for kernels meant to be used on such CPUs.
103075 +
103076 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
103077 + with hardware non-executable bit support there is no performance
103078 + impact, on ppc the impact is negligible.
103079 +
103080 + Note that several architectures require various emulations due to
103081 + badly designed userland ABIs, this will cause a performance impact
103082 + but will disappear as soon as userland is fixed. For example, ppc
103083 + userland MUST have been built with secure-plt by a recent toolchain.
103084 +
103085 +config PAX_SEGMEXEC
103086 + bool "Segmentation based non-executable pages"
103087 + default y if GRKERNSEC_CONFIG_AUTO
103088 + depends on PAX_NOEXEC && X86_32
103089 + help
103090 + This implementation is based on the segmentation feature of the
103091 + CPU and has a very small performance impact, however applications
103092 + will be limited to a 1.5 GB address space instead of the normal
103093 + 3 GB.
103094 +
103095 +config PAX_EMUTRAMP
103096 + bool "Emulate trampolines"
103097 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
103098 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
103099 + help
103100 + There are some programs and libraries that for one reason or
103101 + another attempt to execute special small code snippets from
103102 + non-executable memory pages. Most notable examples are the
103103 + signal handler return code generated by the kernel itself and
103104 + the GCC trampolines.
103105 +
103106 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
103107 + such programs will no longer work under your kernel.
103108 +
103109 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
103110 + utilities to enable trampoline emulation for the affected programs
103111 + yet still have the protection provided by the non-executable pages.
103112 +
103113 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
103114 + your system will not even boot.
103115 +
103116 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
103117 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
103118 + for the affected files.
103119 +
103120 + NOTE: enabling this feature *may* open up a loophole in the
103121 + protection provided by non-executable pages that an attacker
103122 + could abuse. Therefore the best solution is to not have any
103123 + files on your system that would require this option. This can
103124 + be achieved by not using libc5 (which relies on the kernel
103125 + signal handler return code) and not using or rewriting programs
103126 + that make use of the nested function implementation of GCC.
103127 + Skilled users can just fix GCC itself so that it implements
103128 + nested function calls in a way that does not interfere with PaX.
103129 +
103130 +config PAX_EMUSIGRT
103131 + bool "Automatically emulate sigreturn trampolines"
103132 + depends on PAX_EMUTRAMP && PARISC
103133 + default y
103134 + help
103135 + Enabling this option will have the kernel automatically detect
103136 + and emulate signal return trampolines executing on the stack
103137 + that would otherwise lead to task termination.
103138 +
103139 + This solution is intended as a temporary one for users with
103140 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
103141 + Modula-3 runtime, etc) or executables linked to such, basically
103142 + everything that does not specify its own SA_RESTORER function in
103143 + normal executable memory like glibc 2.1+ does.
103144 +
103145 + On parisc you MUST enable this option, otherwise your system will
103146 + not even boot.
103147 +
103148 + NOTE: this feature cannot be disabled on a per executable basis
103149 + and since it *does* open up a loophole in the protection provided
103150 + by non-executable pages, the best solution is to not have any
103151 + files on your system that would require this option.
103152 +
103153 +config PAX_MPROTECT
103154 + bool "Restrict mprotect()"
103155 + default y if GRKERNSEC_CONFIG_AUTO
103156 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
103157 + help
103158 + Enabling this option will prevent programs from
103159 + - changing the executable status of memory pages that were
103160 + not originally created as executable,
103161 + - making read-only executable pages writable again,
103162 + - creating executable pages from anonymous memory,
103163 + - making read-only-after-relocations (RELRO) data pages writable again.
103164 +
103165 + You should say Y here to complete the protection provided by
103166 + the enforcement of non-executable pages.
103167 +
103168 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103169 + this feature on a per file basis.
103170 +
103171 +config PAX_MPROTECT_COMPAT
103172 + bool "Use legacy/compat protection demoting (read help)"
103173 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103174 + depends on PAX_MPROTECT
103175 + help
103176 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
103177 + by sending the proper error code to the application. For some broken
103178 + userland, this can cause problems with Python or other applications. The
103179 + current implementation however allows for applications like clamav to
103180 + detect if JIT compilation/execution is allowed and to fall back gracefully
103181 + to an interpreter-based mode if it does not. While we encourage everyone
103182 + to use the current implementation as-is and push upstream to fix broken
103183 + userland (note that the RWX logging option can assist with this), in some
103184 + environments this may not be possible. Having to disable MPROTECT
103185 + completely on certain binaries reduces the security benefit of PaX,
103186 + so this option is provided for those environments to revert to the old
103187 + behavior.
103188 +
103189 +config PAX_ELFRELOCS
103190 + bool "Allow ELF text relocations (read help)"
103191 + depends on PAX_MPROTECT
103192 + default n
103193 + help
103194 + Non-executable pages and mprotect() restrictions are effective
103195 + in preventing the introduction of new executable code into an
103196 + attacked task's address space. There remain only two venues
103197 + for this kind of attack: if the attacker can execute already
103198 + existing code in the attacked task then he can either have it
103199 + create and mmap() a file containing his code or have it mmap()
103200 + an already existing ELF library that does not have position
103201 + independent code in it and use mprotect() on it to make it
103202 + writable and copy his code there. While protecting against
103203 + the former approach is beyond PaX, the latter can be prevented
103204 + by having only PIC ELF libraries on one's system (which do not
103205 + need to relocate their code). If you are sure this is your case,
103206 + as is the case with all modern Linux distributions, then leave
103207 + this option disabled. You should say 'n' here.
103208 +
103209 +config PAX_ETEXECRELOCS
103210 + bool "Allow ELF ET_EXEC text relocations"
103211 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
103212 + select PAX_ELFRELOCS
103213 + default y
103214 + help
103215 + On some architectures there are incorrectly created applications
103216 + that require text relocations and would not work without enabling
103217 + this option. If you are an alpha, ia64 or parisc user, you should
103218 + enable this option and disable it once you have made sure that
103219 + none of your applications need it.
103220 +
103221 +config PAX_EMUPLT
103222 + bool "Automatically emulate ELF PLT"
103223 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
103224 + default y
103225 + help
103226 + Enabling this option will have the kernel automatically detect
103227 + and emulate the Procedure Linkage Table entries in ELF files.
103228 + On some architectures such entries are in writable memory, and
103229 + become non-executable leading to task termination. Therefore
103230 + it is mandatory that you enable this option on alpha, parisc,
103231 + sparc and sparc64, otherwise your system would not even boot.
103232 +
103233 + NOTE: this feature *does* open up a loophole in the protection
103234 + provided by the non-executable pages, therefore the proper
103235 + solution is to modify the toolchain to produce a PLT that does
103236 + not need to be writable.
103237 +
103238 +config PAX_DLRESOLVE
103239 + bool 'Emulate old glibc resolver stub'
103240 + depends on PAX_EMUPLT && SPARC
103241 + default n
103242 + help
103243 + This option is needed if userland has an old glibc (before 2.4)
103244 + that puts a 'save' instruction into the runtime generated resolver
103245 + stub that needs special emulation.
103246 +
103247 +config PAX_KERNEXEC
103248 + bool "Enforce non-executable kernel pages"
103249 + 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))
103250 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
103251 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
103252 + select PAX_KERNEXEC_PLUGIN if X86_64
103253 + help
103254 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
103255 + that is, enabling this option will make it harder to inject
103256 + and execute 'foreign' code in kernel memory itself.
103257 +
103258 +choice
103259 + prompt "Return Address Instrumentation Method"
103260 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
103261 + depends on PAX_KERNEXEC_PLUGIN
103262 + help
103263 + Select the method used to instrument function pointer dereferences.
103264 + Note that binary modules cannot be instrumented by this approach.
103265 +
103266 + Note that the implementation requires a gcc with plugin support,
103267 + i.e., gcc 4.5 or newer. You may need to install the supporting
103268 + headers explicitly in addition to the normal gcc package.
103269 +
103270 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
103271 + bool "bts"
103272 + help
103273 + This method is compatible with binary only modules but has
103274 + a higher runtime overhead.
103275 +
103276 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
103277 + bool "or"
103278 + depends on !PARAVIRT
103279 + help
103280 + This method is incompatible with binary only modules but has
103281 + a lower runtime overhead.
103282 +endchoice
103283 +
103284 +config PAX_KERNEXEC_PLUGIN_METHOD
103285 + string
103286 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
103287 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
103288 + default ""
103289 +
103290 +config PAX_KERNEXEC_MODULE_TEXT
103291 + int "Minimum amount of memory reserved for module code"
103292 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
103293 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103294 + depends on PAX_KERNEXEC && X86_32
103295 + help
103296 + Due to implementation details the kernel must reserve a fixed
103297 + amount of memory for runtime allocated code (such as modules)
103298 + at compile time that cannot be changed at runtime. Here you
103299 + can specify the minimum amount in MB that will be reserved.
103300 + Due to the same implementation details this size will always
103301 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
103302 + the actually available memory for runtime allocated code will
103303 + usually be more than this minimum.
103304 +
103305 + The default 4 MB should be enough for most users but if you have
103306 + an excessive number of modules (e.g., most distribution configs
103307 + compile many drivers as modules) or use huge modules such as
103308 + nvidia's kernel driver, you will need to adjust this amount.
103309 + A good rule of thumb is to look at your currently loaded kernel
103310 + modules and add up their sizes.
103311 +
103312 +endmenu
103313 +
103314 +menu "Address Space Layout Randomization"
103315 + depends on PAX
103316 +
103317 +config PAX_ASLR
103318 + bool "Address Space Layout Randomization"
103319 + default y if GRKERNSEC_CONFIG_AUTO
103320 + help
103321 + Many if not most exploit techniques rely on the knowledge of
103322 + certain addresses in the attacked program. The following options
103323 + will allow the kernel to apply a certain amount of randomization
103324 + to specific parts of the program thereby forcing an attacker to
103325 + guess them in most cases. Any failed guess will most likely crash
103326 + the attacked program which allows the kernel to detect such attempts
103327 + and react on them. PaX itself provides no reaction mechanisms,
103328 + instead it is strongly encouraged that you make use of Nergal's
103329 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
103330 + (http://www.grsecurity.net/) built-in crash detection features or
103331 + develop one yourself.
103332 +
103333 + By saying Y here you can choose to randomize the following areas:
103334 + - top of the task's kernel stack
103335 + - top of the task's userland stack
103336 + - base address for mmap() requests that do not specify one
103337 + (this includes all libraries)
103338 + - base address of the main executable
103339 +
103340 + It is strongly recommended to say Y here as address space layout
103341 + randomization has negligible impact on performance yet it provides
103342 + a very effective protection.
103343 +
103344 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103345 + this feature on a per file basis.
103346 +
103347 +config PAX_RANDKSTACK
103348 + bool "Randomize kernel stack base"
103349 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
103350 + depends on X86_TSC && X86
103351 + help
103352 + By saying Y here the kernel will randomize every task's kernel
103353 + stack on every system call. This will not only force an attacker
103354 + to guess it but also prevent him from making use of possible
103355 + leaked information about it.
103356 +
103357 + Since the kernel stack is a rather scarce resource, randomization
103358 + may cause unexpected stack overflows, therefore you should very
103359 + carefully test your system. Note that once enabled in the kernel
103360 + configuration, this feature cannot be disabled on a per file basis.
103361 +
103362 +config PAX_RANDUSTACK
103363 + bool "Randomize user stack base"
103364 + default y if GRKERNSEC_CONFIG_AUTO
103365 + depends on PAX_ASLR
103366 + help
103367 + By saying Y here the kernel will randomize every task's userland
103368 + stack. The randomization is done in two steps where the second
103369 + one may apply a big amount of shift to the top of the stack and
103370 + cause problems for programs that want to use lots of memory (more
103371 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
103372 + For this reason the second step can be controlled by 'chpax' or
103373 + 'paxctl' on a per file basis.
103374 +
103375 +config PAX_RANDMMAP
103376 + bool "Randomize mmap() base"
103377 + default y if GRKERNSEC_CONFIG_AUTO
103378 + depends on PAX_ASLR
103379 + help
103380 + By saying Y here the kernel will use a randomized base address for
103381 + mmap() requests that do not specify one themselves. As a result
103382 + all dynamically loaded libraries will appear at random addresses
103383 + and therefore be harder to exploit by a technique where an attacker
103384 + attempts to execute library code for his purposes (e.g. spawn a
103385 + shell from an exploited program that is running at an elevated
103386 + privilege level).
103387 +
103388 + Furthermore, if a program is relinked as a dynamic ELF file, its
103389 + base address will be randomized as well, completing the full
103390 + randomization of the address space layout. Attacking such programs
103391 + becomes a guess game. You can find an example of doing this at
103392 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
103393 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
103394 +
103395 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
103396 + feature on a per file basis.
103397 +
103398 +endmenu
103399 +
103400 +menu "Miscellaneous hardening features"
103401 +
103402 +config PAX_MEMORY_SANITIZE
103403 + bool "Sanitize all freed memory"
103404 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103405 + help
103406 + By saying Y here the kernel will erase memory pages and slab objects
103407 + as soon as they are freed. This in turn reduces the lifetime of data
103408 + stored in them, making it less likely that sensitive information such
103409 + as passwords, cryptographic secrets, etc stay in memory for too long.
103410 +
103411 + This is especially useful for programs whose runtime is short, long
103412 + lived processes and the kernel itself benefit from this as long as
103413 + they ensure timely freeing of memory that may hold sensitive
103414 + information.
103415 +
103416 + A nice side effect of the sanitization of slab objects is the
103417 + reduction of possible info leaks caused by padding bytes within the
103418 + leaky structures. Use-after-free bugs for structures containing
103419 + pointers can also be detected as dereferencing the sanitized pointer
103420 + will generate an access violation.
103421 +
103422 + The tradeoff is performance impact, on a single CPU system kernel
103423 + compilation sees a 3% slowdown, other systems and workloads may vary
103424 + and you are advised to test this feature on your expected workload
103425 + before deploying it.
103426 +
103427 + To reduce the performance penalty by sanitizing pages only, albeit
103428 + limiting the effectiveness of this feature at the same time, slab
103429 + sanitization can be disabled with the kernel commandline parameter
103430 + "pax_sanitize_slab=0".
103431 +
103432 + Note that this feature does not protect data stored in live pages,
103433 + e.g., process memory swapped to disk may stay there for a long time.
103434 +
103435 +config PAX_MEMORY_STACKLEAK
103436 + bool "Sanitize kernel stack"
103437 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103438 + depends on X86
103439 + help
103440 + By saying Y here the kernel will erase the kernel stack before it
103441 + returns from a system call. This in turn reduces the information
103442 + that a kernel stack leak bug can reveal.
103443 +
103444 + Note that such a bug can still leak information that was put on
103445 + the stack by the current system call (the one eventually triggering
103446 + the bug) but traces of earlier system calls on the kernel stack
103447 + cannot leak anymore.
103448 +
103449 + The tradeoff is performance impact: on a single CPU system kernel
103450 + compilation sees a 1% slowdown, other systems and workloads may vary
103451 + and you are advised to test this feature on your expected workload
103452 + before deploying it.
103453 +
103454 + Note that the full feature requires a gcc with plugin support,
103455 + i.e., gcc 4.5 or newer. You may need to install the supporting
103456 + headers explicitly in addition to the normal gcc package. Using
103457 + older gcc versions means that functions with large enough stack
103458 + frames may leave uninitialized memory behind that may be exposed
103459 + to a later syscall leaking the stack.
103460 +
103461 +config PAX_MEMORY_STRUCTLEAK
103462 + bool "Forcibly initialize local variables copied to userland"
103463 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103464 + help
103465 + By saying Y here the kernel will zero initialize some local
103466 + variables that are going to be copied to userland. This in
103467 + turn prevents unintended information leakage from the kernel
103468 + stack should later code forget to explicitly set all parts of
103469 + the copied variable.
103470 +
103471 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
103472 + at a much smaller coverage.
103473 +
103474 + Note that the implementation requires a gcc with plugin support,
103475 + i.e., gcc 4.5 or newer. You may need to install the supporting
103476 + headers explicitly in addition to the normal gcc package.
103477 +
103478 +config PAX_MEMORY_UDEREF
103479 + bool "Prevent invalid userland pointer dereference"
103480 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
103481 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
103482 + select PAX_PER_CPU_PGD if X86_64
103483 + help
103484 + By saying Y here the kernel will be prevented from dereferencing
103485 + userland pointers in contexts where the kernel expects only kernel
103486 + pointers. This is both a useful runtime debugging feature and a
103487 + security measure that prevents exploiting a class of kernel bugs.
103488 +
103489 + The tradeoff is that some virtualization solutions may experience
103490 + a huge slowdown and therefore you should not enable this feature
103491 + for kernels meant to run in such environments. Whether a given VM
103492 + solution is affected or not is best determined by simply trying it
103493 + out, the performance impact will be obvious right on boot as this
103494 + mechanism engages from very early on. A good rule of thumb is that
103495 + VMs running on CPUs without hardware virtualization support (i.e.,
103496 + the majority of IA-32 CPUs) will likely experience the slowdown.
103497 +
103498 + On X86_64 the kernel will make use of PCID support when available
103499 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
103500 + or performance impact. Pass pax_weakuderef on the kernel command
103501 + line to choose the latter.
103502 +
103503 +config PAX_REFCOUNT
103504 + bool "Prevent various kernel object reference counter overflows"
103505 + default y if GRKERNSEC_CONFIG_AUTO
103506 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
103507 + help
103508 + By saying Y here the kernel will detect and prevent overflowing
103509 + various (but not all) kinds of object reference counters. Such
103510 + overflows can normally occur due to bugs only and are often, if
103511 + not always, exploitable.
103512 +
103513 + The tradeoff is that data structures protected by an overflowed
103514 + refcount will never be freed and therefore will leak memory. Note
103515 + that this leak also happens even without this protection but in
103516 + that case the overflow can eventually trigger the freeing of the
103517 + data structure while it is still being used elsewhere, resulting
103518 + in the exploitable situation that this feature prevents.
103519 +
103520 + Since this has a negligible performance impact, you should enable
103521 + this feature.
103522 +
103523 +config PAX_CONSTIFY_PLUGIN
103524 + bool "Automatically constify eligible structures"
103525 + default y
103526 + depends on !UML && PAX_KERNEXEC
103527 + help
103528 + By saying Y here the compiler will automatically constify a class
103529 + of types that contain only function pointers. This reduces the
103530 + kernel's attack surface and also produces a better memory layout.
103531 +
103532 + Note that the implementation requires a gcc with plugin support,
103533 + i.e., gcc 4.5 or newer. You may need to install the supporting
103534 + headers explicitly in addition to the normal gcc package.
103535 +
103536 + Note that if some code really has to modify constified variables
103537 + then the source code will have to be patched to allow it. Examples
103538 + can be found in PaX itself (the no_const attribute) and for some
103539 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
103540 +
103541 +config PAX_USERCOPY
103542 + bool "Harden heap object copies between kernel and userland"
103543 + default y if GRKERNSEC_CONFIG_AUTO
103544 + depends on ARM || IA64 || PPC || SPARC || X86
103545 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
103546 + select PAX_USERCOPY_SLABS
103547 + help
103548 + By saying Y here the kernel will enforce the size of heap objects
103549 + when they are copied in either direction between the kernel and
103550 + userland, even if only a part of the heap object is copied.
103551 +
103552 + Specifically, this checking prevents information leaking from the
103553 + kernel heap during kernel to userland copies (if the kernel heap
103554 + object is otherwise fully initialized) and prevents kernel heap
103555 + overflows during userland to kernel copies.
103556 +
103557 + Note that the current implementation provides the strictest bounds
103558 + checks for the SLUB allocator.
103559 +
103560 + Enabling this option also enables per-slab cache protection against
103561 + data in a given cache being copied into/out of via userland
103562 + accessors. Though the whitelist of regions will be reduced over
103563 + time, it notably protects important data structures like task structs.
103564 +
103565 + If frame pointers are enabled on x86, this option will also restrict
103566 + copies into and out of the kernel stack to local variables within a
103567 + single frame.
103568 +
103569 + Since this has a negligible performance impact, you should enable
103570 + this feature.
103571 +
103572 +config PAX_USERCOPY_DEBUG
103573 + bool
103574 + depends on X86 && PAX_USERCOPY
103575 + default n
103576 +
103577 +config PAX_SIZE_OVERFLOW
103578 + bool "Prevent various integer overflows in function size parameters"
103579 + default y if GRKERNSEC_CONFIG_AUTO
103580 + depends on X86
103581 + help
103582 + By saying Y here the kernel recomputes expressions of function
103583 + arguments marked by a size_overflow attribute with double integer
103584 + precision (DImode/TImode for 32/64 bit integer types).
103585 +
103586 + The recomputed argument is checked against TYPE_MAX and an event
103587 + is logged on overflow and the triggering process is killed.
103588 +
103589 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
103590 +
103591 + Note that the implementation requires a gcc with plugin support,
103592 + i.e., gcc 4.5 or newer. You may need to install the supporting
103593 + headers explicitly in addition to the normal gcc package.
103594 +
103595 +config PAX_LATENT_ENTROPY
103596 + bool "Generate some entropy during boot and runtime"
103597 + default y if GRKERNSEC_CONFIG_AUTO
103598 + help
103599 + By saying Y here the kernel will instrument some kernel code to
103600 + extract some entropy from both original and artificially created
103601 + program state. This will help especially embedded systems where
103602 + there is little 'natural' source of entropy normally. The cost
103603 + is some slowdown of the boot process and fork and irq processing.
103604 +
103605 + When pax_extra_latent_entropy is passed on the kernel command line,
103606 + entropy will be extracted from up to the first 4GB of RAM while the
103607 + runtime memory allocator is being initialized. This costs even more
103608 + slowdown of the boot process.
103609 +
103610 + Note that the implementation requires a gcc with plugin support,
103611 + i.e., gcc 4.5 or newer. You may need to install the supporting
103612 + headers explicitly in addition to the normal gcc package.
103613 +
103614 + Note that entropy extracted this way is not cryptographically
103615 + secure!
103616 +
103617 +endmenu
103618 +
103619 +endmenu
103620 +
103621 +source grsecurity/Kconfig
103622 +
103623 +endmenu
103624 +
103625 +endmenu
103626 +
103627 source security/keys/Kconfig
103628
103629 config SECURITY_DMESG_RESTRICT
103630 @@ -103,7 +1057,7 @@ config INTEL_TXT
103631 config LSM_MMAP_MIN_ADDR
103632 int "Low address space for LSM to protect from user allocation"
103633 depends on SECURITY && SECURITY_SELINUX
103634 - default 32768 if ARM
103635 + default 32768 if ALPHA || ARM || PARISC || SPARC32
103636 default 65536
103637 help
103638 This is the portion of low virtual memory which should be protected
103639 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
103640 index 4257b7e..f0c9438 100644
103641 --- a/security/apparmor/lsm.c
103642 +++ b/security/apparmor/lsm.c
103643 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
103644 return error;
103645 }
103646
103647 -static struct security_operations apparmor_ops = {
103648 +static struct security_operations apparmor_ops __read_only = {
103649 .name = "apparmor",
103650
103651 .ptrace_access_check = apparmor_ptrace_access_check,
103652 diff --git a/security/commoncap.c b/security/commoncap.c
103653 index b9d613e..f68305c 100644
103654 --- a/security/commoncap.c
103655 +++ b/security/commoncap.c
103656 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
103657 return 0;
103658 }
103659
103660 +/* returns:
103661 + 1 for suid privilege
103662 + 2 for sgid privilege
103663 + 3 for fscap privilege
103664 +*/
103665 +int is_privileged_binary(const struct dentry *dentry)
103666 +{
103667 + struct cpu_vfs_cap_data capdata;
103668 + struct inode *inode = dentry->d_inode;
103669 +
103670 + if (!inode || S_ISDIR(inode->i_mode))
103671 + return 0;
103672 +
103673 + if (inode->i_mode & S_ISUID)
103674 + return 1;
103675 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
103676 + return 2;
103677 +
103678 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
103679 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
103680 + return 3;
103681 + }
103682 +
103683 + return 0;
103684 +}
103685 +
103686 /*
103687 * Attempt to get the on-exec apply capability sets for an executable file from
103688 * its xattrs and, if present, apply them to the proposed credentials being
103689 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
103690 const struct cred *cred = current_cred();
103691 kuid_t root_uid = make_kuid(cred->user_ns, 0);
103692
103693 + if (gr_acl_enable_at_secure())
103694 + return 1;
103695 +
103696 if (!uid_eq(cred->uid, root_uid)) {
103697 if (bprm->cap_effective)
103698 return 1;
103699 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
103700 index 0356e1d..72332ab 100644
103701 --- a/security/integrity/ima/ima.h
103702 +++ b/security/integrity/ima/ima.h
103703 @@ -118,8 +118,8 @@ int ima_init_template(void);
103704 extern spinlock_t ima_queue_lock;
103705
103706 struct ima_h_table {
103707 - atomic_long_t len; /* number of stored measurements in the list */
103708 - atomic_long_t violations;
103709 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
103710 + atomic_long_unchecked_t violations;
103711 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
103712 };
103713 extern struct ima_h_table ima_htable;
103714 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
103715 index c38bbce..f45133d 100644
103716 --- a/security/integrity/ima/ima_api.c
103717 +++ b/security/integrity/ima/ima_api.c
103718 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
103719 int result;
103720
103721 /* can overflow, only indicator */
103722 - atomic_long_inc(&ima_htable.violations);
103723 + atomic_long_inc_unchecked(&ima_htable.violations);
103724
103725 result = ima_alloc_init_template(NULL, file, filename,
103726 NULL, 0, &entry);
103727 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
103728 index db01125..61f6597 100644
103729 --- a/security/integrity/ima/ima_fs.c
103730 +++ b/security/integrity/ima/ima_fs.c
103731 @@ -28,12 +28,12 @@
103732 static int valid_policy = 1;
103733 #define TMPBUFLEN 12
103734 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
103735 - loff_t *ppos, atomic_long_t *val)
103736 + loff_t *ppos, atomic_long_unchecked_t *val)
103737 {
103738 char tmpbuf[TMPBUFLEN];
103739 ssize_t len;
103740
103741 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
103742 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
103743 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
103744 }
103745
103746 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
103747 index d85e997..6992813 100644
103748 --- a/security/integrity/ima/ima_queue.c
103749 +++ b/security/integrity/ima/ima_queue.c
103750 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
103751 INIT_LIST_HEAD(&qe->later);
103752 list_add_tail_rcu(&qe->later, &ima_measurements);
103753
103754 - atomic_long_inc(&ima_htable.len);
103755 + atomic_long_inc_unchecked(&ima_htable.len);
103756 key = ima_hash_key(entry->digest);
103757 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
103758 return 0;
103759 diff --git a/security/keys/compat.c b/security/keys/compat.c
103760 index bbd32c7..c60c927 100644
103761 --- a/security/keys/compat.c
103762 +++ b/security/keys/compat.c
103763 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
103764 if (ret == 0)
103765 goto no_payload_free;
103766
103767 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
103768 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
103769 err:
103770 if (iov != iovstack)
103771 kfree(iov);
103772 diff --git a/security/keys/internal.h b/security/keys/internal.h
103773 index 80b2aac..bb7ee65 100644
103774 --- a/security/keys/internal.h
103775 +++ b/security/keys/internal.h
103776 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
103777 extern long keyctl_invalidate_key(key_serial_t);
103778
103779 extern long keyctl_instantiate_key_common(key_serial_t,
103780 - const struct iovec *,
103781 + const struct iovec __user *,
103782 unsigned, size_t, key_serial_t);
103783 #ifdef CONFIG_PERSISTENT_KEYRINGS
103784 extern long keyctl_get_persistent(uid_t, key_serial_t);
103785 diff --git a/security/keys/key.c b/security/keys/key.c
103786 index 6e21c11..9ed67ca 100644
103787 --- a/security/keys/key.c
103788 +++ b/security/keys/key.c
103789 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
103790
103791 atomic_set(&key->usage, 1);
103792 init_rwsem(&key->sem);
103793 - lockdep_set_class(&key->sem, &type->lock_class);
103794 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
103795 key->index_key.type = type;
103796 key->user = user;
103797 key->quotalen = quotalen;
103798 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
103799 struct key_type *p;
103800 int ret;
103801
103802 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
103803 + pax_open_kernel();
103804 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
103805 + pax_close_kernel();
103806
103807 ret = -EEXIST;
103808 down_write(&key_types_sem);
103809 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
103810 }
103811
103812 /* store the type */
103813 - list_add(&ktype->link, &key_types_list);
103814 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
103815
103816 pr_notice("Key type %s registered\n", ktype->name);
103817 ret = 0;
103818 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
103819 void unregister_key_type(struct key_type *ktype)
103820 {
103821 down_write(&key_types_sem);
103822 - list_del_init(&ktype->link);
103823 + pax_list_del_init((struct list_head *)&ktype->link);
103824 downgrade_write(&key_types_sem);
103825 key_gc_keytype(ktype);
103826 pr_notice("Key type %s unregistered\n", ktype->name);
103827 @@ -1088,10 +1090,10 @@ void __init key_init(void)
103828 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
103829
103830 /* add the special key types */
103831 - list_add_tail(&key_type_keyring.link, &key_types_list);
103832 - list_add_tail(&key_type_dead.link, &key_types_list);
103833 - list_add_tail(&key_type_user.link, &key_types_list);
103834 - list_add_tail(&key_type_logon.link, &key_types_list);
103835 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
103836 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
103837 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
103838 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
103839
103840 /* record the root user tracking */
103841 rb_link_node(&root_key_user.node,
103842 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
103843 index cee72ce..e46074a 100644
103844 --- a/security/keys/keyctl.c
103845 +++ b/security/keys/keyctl.c
103846 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
103847 /*
103848 * Copy the iovec data from userspace
103849 */
103850 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
103851 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
103852 unsigned ioc)
103853 {
103854 for (; ioc > 0; ioc--) {
103855 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
103856 * If successful, 0 will be returned.
103857 */
103858 long keyctl_instantiate_key_common(key_serial_t id,
103859 - const struct iovec *payload_iov,
103860 + const struct iovec __user *payload_iov,
103861 unsigned ioc,
103862 size_t plen,
103863 key_serial_t ringid)
103864 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
103865 [0].iov_len = plen
103866 };
103867
103868 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
103869 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
103870 }
103871
103872 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
103873 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
103874 if (ret == 0)
103875 goto no_payload_free;
103876
103877 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
103878 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
103879 err:
103880 if (iov != iovstack)
103881 kfree(iov);
103882 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
103883 index d46cbc5..2fb2576 100644
103884 --- a/security/keys/keyring.c
103885 +++ b/security/keys/keyring.c
103886 @@ -1000,7 +1000,11 @@ static int keyring_detect_cycle_iterator(const void *object,
103887
103888 kenter("{%d}", key->serial);
103889
103890 - BUG_ON(key != ctx->match_data);
103891 + /* We might get a keyring with matching index-key that is nonetheless a
103892 + * different keyring. */
103893 + if (key != ctx->match_data)
103894 + return 0;
103895 +
103896 ctx->result = ERR_PTR(-EDEADLK);
103897 return 1;
103898 }
103899 diff --git a/security/min_addr.c b/security/min_addr.c
103900 index f728728..6457a0c 100644
103901 --- a/security/min_addr.c
103902 +++ b/security/min_addr.c
103903 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
103904 */
103905 static void update_mmap_min_addr(void)
103906 {
103907 +#ifndef SPARC
103908 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
103909 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
103910 mmap_min_addr = dac_mmap_min_addr;
103911 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
103912 #else
103913 mmap_min_addr = dac_mmap_min_addr;
103914 #endif
103915 +#endif
103916 }
103917
103918 /*
103919 diff --git a/security/security.c b/security/security.c
103920 index 15b6928..60d03ec 100644
103921 --- a/security/security.c
103922 +++ b/security/security.c
103923 @@ -33,8 +33,8 @@
103924 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
103925 CONFIG_DEFAULT_SECURITY;
103926
103927 -static struct security_operations *security_ops;
103928 -static struct security_operations default_security_ops = {
103929 +struct security_operations *security_ops __read_only;
103930 +struct security_operations default_security_ops __read_only = {
103931 .name = "default",
103932 };
103933
103934 @@ -73,11 +73,6 @@ int __init security_init(void)
103935 return 0;
103936 }
103937
103938 -void reset_security_ops(void)
103939 -{
103940 - security_ops = &default_security_ops;
103941 -}
103942 -
103943 /* Save user chosen LSM */
103944 static int __init choose_lsm(char *str)
103945 {
103946 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
103947 index fc3e662..7844c60 100644
103948 --- a/security/selinux/avc.c
103949 +++ b/security/selinux/avc.c
103950 @@ -59,7 +59,7 @@ struct avc_node {
103951 struct avc_cache {
103952 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
103953 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
103954 - atomic_t lru_hint; /* LRU hint for reclaim scan */
103955 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
103956 atomic_t active_nodes;
103957 u32 latest_notif; /* latest revocation notification */
103958 };
103959 @@ -167,7 +167,7 @@ void __init avc_init(void)
103960 spin_lock_init(&avc_cache.slots_lock[i]);
103961 }
103962 atomic_set(&avc_cache.active_nodes, 0);
103963 - atomic_set(&avc_cache.lru_hint, 0);
103964 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
103965
103966 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
103967 0, SLAB_PANIC, NULL);
103968 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
103969 spinlock_t *lock;
103970
103971 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
103972 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
103973 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
103974 head = &avc_cache.slots[hvalue];
103975 lock = &avc_cache.slots_lock[hvalue];
103976
103977 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
103978 index 57b0b49..402063e 100644
103979 --- a/security/selinux/hooks.c
103980 +++ b/security/selinux/hooks.c
103981 @@ -96,8 +96,6 @@
103982 #include "audit.h"
103983 #include "avc_ss.h"
103984
103985 -extern struct security_operations *security_ops;
103986 -
103987 /* SECMARK reference count */
103988 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
103989
103990 @@ -5745,7 +5743,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
103991
103992 #endif
103993
103994 -static struct security_operations selinux_ops = {
103995 +static struct security_operations selinux_ops __read_only = {
103996 .name = "selinux",
103997
103998 .ptrace_access_check = selinux_ptrace_access_check,
103999 @@ -6098,6 +6096,9 @@ static void selinux_nf_ip_exit(void)
104000 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
104001 static int selinux_disabled;
104002
104003 +extern struct security_operations *security_ops;
104004 +extern struct security_operations default_security_ops;
104005 +
104006 int selinux_disable(void)
104007 {
104008 if (ss_initialized) {
104009 @@ -6115,7 +6116,9 @@ int selinux_disable(void)
104010 selinux_disabled = 1;
104011 selinux_enabled = 0;
104012
104013 - reset_security_ops();
104014 + pax_open_kernel();
104015 + security_ops = &default_security_ops;
104016 + pax_close_kernel();
104017
104018 /* Try to destroy the avc node cache */
104019 avc_disable();
104020 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
104021 index 48c3cc9..8022cf7 100644
104022 --- a/security/selinux/include/xfrm.h
104023 +++ b/security/selinux/include/xfrm.h
104024 @@ -45,7 +45,7 @@ static inline void selinux_xfrm_notify_policyload(void)
104025 {
104026 struct net *net;
104027
104028 - atomic_inc(&flow_cache_genid);
104029 + atomic_inc_unchecked(&flow_cache_genid);
104030 rtnl_lock();
104031 for_each_net(net)
104032 rt_genid_bump_all(net);
104033 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
104034 index b0be893..646bd94 100644
104035 --- a/security/smack/smack_lsm.c
104036 +++ b/security/smack/smack_lsm.c
104037 @@ -3731,7 +3731,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
104038 return 0;
104039 }
104040
104041 -struct security_operations smack_ops = {
104042 +struct security_operations smack_ops __read_only = {
104043 .name = "smack",
104044
104045 .ptrace_access_check = smack_ptrace_access_check,
104046 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
104047 index 390c646..f2f8db3 100644
104048 --- a/security/tomoyo/mount.c
104049 +++ b/security/tomoyo/mount.c
104050 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
104051 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
104052 need_dev = -1; /* dev_name is a directory */
104053 } else {
104054 + if (!capable(CAP_SYS_ADMIN)) {
104055 + error = -EPERM;
104056 + goto out;
104057 + }
104058 fstype = get_fs_type(type);
104059 if (!fstype) {
104060 error = -ENODEV;
104061 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
104062 index f0b756e..b129202 100644
104063 --- a/security/tomoyo/tomoyo.c
104064 +++ b/security/tomoyo/tomoyo.c
104065 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
104066 * tomoyo_security_ops is a "struct security_operations" which is used for
104067 * registering TOMOYO.
104068 */
104069 -static struct security_operations tomoyo_security_ops = {
104070 +static struct security_operations tomoyo_security_ops __read_only = {
104071 .name = "tomoyo",
104072 .cred_alloc_blank = tomoyo_cred_alloc_blank,
104073 .cred_prepare = tomoyo_cred_prepare,
104074 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
104075 index 20ef514..4182bed 100644
104076 --- a/security/yama/Kconfig
104077 +++ b/security/yama/Kconfig
104078 @@ -1,6 +1,6 @@
104079 config SECURITY_YAMA
104080 bool "Yama support"
104081 - depends on SECURITY
104082 + depends on SECURITY && !GRKERNSEC
104083 select SECURITYFS
104084 select SECURITY_PATH
104085 default n
104086 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
104087 index 13c88fbc..f8c115e 100644
104088 --- a/security/yama/yama_lsm.c
104089 +++ b/security/yama/yama_lsm.c
104090 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
104091 }
104092
104093 #ifndef CONFIG_SECURITY_YAMA_STACKED
104094 -static struct security_operations yama_ops = {
104095 +static struct security_operations yama_ops __read_only = {
104096 .name = "yama",
104097
104098 .ptrace_access_check = yama_ptrace_access_check,
104099 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
104100 #endif
104101
104102 #ifdef CONFIG_SYSCTL
104103 +static int zero __read_only;
104104 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
104105 +
104106 static int yama_dointvec_minmax(struct ctl_table *table, int write,
104107 void __user *buffer, size_t *lenp, loff_t *ppos)
104108 {
104109 - int rc;
104110 + ctl_table_no_const yama_table;
104111
104112 if (write && !capable(CAP_SYS_PTRACE))
104113 return -EPERM;
104114
104115 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
104116 - if (rc)
104117 - return rc;
104118 -
104119 + yama_table = *table;
104120 /* Lock the max value if it ever gets set. */
104121 - if (write && *(int *)table->data == *(int *)table->extra2)
104122 - table->extra1 = table->extra2;
104123 -
104124 - return rc;
104125 + if (ptrace_scope == max_scope)
104126 + yama_table.extra1 = &max_scope;
104127 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
104128 }
104129
104130 -static int zero;
104131 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
104132 -
104133 struct ctl_path yama_sysctl_path[] = {
104134 { .procname = "kernel", },
104135 { .procname = "yama", },
104136 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
104137 index 4cedc69..e59d8a3 100644
104138 --- a/sound/aoa/codecs/onyx.c
104139 +++ b/sound/aoa/codecs/onyx.c
104140 @@ -54,7 +54,7 @@ struct onyx {
104141 spdif_locked:1,
104142 analog_locked:1,
104143 original_mute:2;
104144 - int open_count;
104145 + local_t open_count;
104146 struct codec_info *codec_info;
104147
104148 /* mutex serializes concurrent access to the device
104149 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
104150 struct onyx *onyx = cii->codec_data;
104151
104152 mutex_lock(&onyx->mutex);
104153 - onyx->open_count++;
104154 + local_inc(&onyx->open_count);
104155 mutex_unlock(&onyx->mutex);
104156
104157 return 0;
104158 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
104159 struct onyx *onyx = cii->codec_data;
104160
104161 mutex_lock(&onyx->mutex);
104162 - onyx->open_count--;
104163 - if (!onyx->open_count)
104164 + if (local_dec_and_test(&onyx->open_count))
104165 onyx->spdif_locked = onyx->analog_locked = 0;
104166 mutex_unlock(&onyx->mutex);
104167
104168 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
104169 index ffd2025..df062c9 100644
104170 --- a/sound/aoa/codecs/onyx.h
104171 +++ b/sound/aoa/codecs/onyx.h
104172 @@ -11,6 +11,7 @@
104173 #include <linux/i2c.h>
104174 #include <asm/pmac_low_i2c.h>
104175 #include <asm/prom.h>
104176 +#include <asm/local.h>
104177
104178 /* PCM3052 register definitions */
104179
104180 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
104181 index 4c1cc51..16040040 100644
104182 --- a/sound/core/oss/pcm_oss.c
104183 +++ b/sound/core/oss/pcm_oss.c
104184 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
104185 if (in_kernel) {
104186 mm_segment_t fs;
104187 fs = snd_enter_user();
104188 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104189 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104190 snd_leave_user(fs);
104191 } else {
104192 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104193 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104194 }
104195 if (ret != -EPIPE && ret != -ESTRPIPE)
104196 break;
104197 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
104198 if (in_kernel) {
104199 mm_segment_t fs;
104200 fs = snd_enter_user();
104201 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104202 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104203 snd_leave_user(fs);
104204 } else {
104205 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104206 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104207 }
104208 if (ret == -EPIPE) {
104209 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
104210 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
104211 struct snd_pcm_plugin_channel *channels;
104212 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
104213 if (!in_kernel) {
104214 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
104215 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
104216 return -EFAULT;
104217 buf = runtime->oss.buffer;
104218 }
104219 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
104220 }
104221 } else {
104222 tmp = snd_pcm_oss_write2(substream,
104223 - (const char __force *)buf,
104224 + (const char __force_kernel *)buf,
104225 runtime->oss.period_bytes, 0);
104226 if (tmp <= 0)
104227 goto err;
104228 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
104229 struct snd_pcm_runtime *runtime = substream->runtime;
104230 snd_pcm_sframes_t frames, frames1;
104231 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
104232 - char __user *final_dst = (char __force __user *)buf;
104233 + char __user *final_dst = (char __force_user *)buf;
104234 if (runtime->oss.plugin_first) {
104235 struct snd_pcm_plugin_channel *channels;
104236 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
104237 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
104238 xfer += tmp;
104239 runtime->oss.buffer_used -= tmp;
104240 } else {
104241 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
104242 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
104243 runtime->oss.period_bytes, 0);
104244 if (tmp <= 0)
104245 goto err;
104246 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
104247 size1);
104248 size1 /= runtime->channels; /* frames */
104249 fs = snd_enter_user();
104250 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
104251 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
104252 snd_leave_user(fs);
104253 }
104254 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
104255 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
104256 index af49721..e85058e 100644
104257 --- a/sound/core/pcm_compat.c
104258 +++ b/sound/core/pcm_compat.c
104259 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
104260 int err;
104261
104262 fs = snd_enter_user();
104263 - err = snd_pcm_delay(substream, &delay);
104264 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
104265 snd_leave_user(fs);
104266 if (err < 0)
104267 return err;
104268 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
104269 index 01a5e05..c6bb425 100644
104270 --- a/sound/core/pcm_native.c
104271 +++ b/sound/core/pcm_native.c
104272 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
104273 switch (substream->stream) {
104274 case SNDRV_PCM_STREAM_PLAYBACK:
104275 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
104276 - (void __user *)arg);
104277 + (void __force_user *)arg);
104278 break;
104279 case SNDRV_PCM_STREAM_CAPTURE:
104280 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
104281 - (void __user *)arg);
104282 + (void __force_user *)arg);
104283 break;
104284 default:
104285 result = -EINVAL;
104286 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
104287 index 8d4d5e8..fdd0826 100644
104288 --- a/sound/core/seq/oss/seq_oss.c
104289 +++ b/sound/core/seq/oss/seq_oss.c
104290 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
104291 {
104292 int rc;
104293 static struct snd_seq_dev_ops ops = {
104294 - snd_seq_oss_synth_register,
104295 - snd_seq_oss_synth_unregister,
104296 + .init_device = snd_seq_oss_synth_register,
104297 + .free_device = snd_seq_oss_synth_unregister,
104298 };
104299
104300 snd_seq_autoload_lock();
104301 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
104302 index 040c60e..989a19a 100644
104303 --- a/sound/core/seq/seq_device.c
104304 +++ b/sound/core/seq/seq_device.c
104305 @@ -64,7 +64,7 @@ struct ops_list {
104306 int argsize; /* argument size */
104307
104308 /* operators */
104309 - struct snd_seq_dev_ops ops;
104310 + struct snd_seq_dev_ops *ops;
104311
104312 /* registered devices */
104313 struct list_head dev_list; /* list of devices */
104314 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
104315
104316 mutex_lock(&ops->reg_mutex);
104317 /* copy driver operators */
104318 - ops->ops = *entry;
104319 + ops->ops = entry;
104320 ops->driver |= DRIVER_LOADED;
104321 ops->argsize = argsize;
104322
104323 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
104324 dev->name, ops->id, ops->argsize, dev->argsize);
104325 return -EINVAL;
104326 }
104327 - if (ops->ops.init_device(dev) >= 0) {
104328 + if (ops->ops->init_device(dev) >= 0) {
104329 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
104330 ops->num_init_devices++;
104331 } else {
104332 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
104333 dev->name, ops->id, ops->argsize, dev->argsize);
104334 return -EINVAL;
104335 }
104336 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
104337 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
104338 dev->status = SNDRV_SEQ_DEVICE_FREE;
104339 dev->driver_data = NULL;
104340 ops->num_init_devices--;
104341 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
104342 index 64069db..3c6d392 100644
104343 --- a/sound/core/seq/seq_midi.c
104344 +++ b/sound/core/seq/seq_midi.c
104345 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
104346 static int __init alsa_seq_midi_init(void)
104347 {
104348 static struct snd_seq_dev_ops ops = {
104349 - snd_seq_midisynth_register_port,
104350 - snd_seq_midisynth_unregister_port,
104351 + .init_device = snd_seq_midisynth_register_port,
104352 + .free_device = snd_seq_midisynth_unregister_port,
104353 };
104354 memset(&synths, 0, sizeof(synths));
104355 snd_seq_autoload_lock();
104356 diff --git a/sound/core/sound.c b/sound/core/sound.c
104357 index 437c25e..cd040ab 100644
104358 --- a/sound/core/sound.c
104359 +++ b/sound/core/sound.c
104360 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
104361 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
104362 default: return;
104363 }
104364 - request_module(str);
104365 + request_module("%s", str);
104366 }
104367
104368 #endif /* modular kernel */
104369 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
104370 index 4e0dd22..7a1f32c 100644
104371 --- a/sound/drivers/mts64.c
104372 +++ b/sound/drivers/mts64.c
104373 @@ -29,6 +29,7 @@
104374 #include <sound/initval.h>
104375 #include <sound/rawmidi.h>
104376 #include <sound/control.h>
104377 +#include <asm/local.h>
104378
104379 #define CARD_NAME "Miditerminal 4140"
104380 #define DRIVER_NAME "MTS64"
104381 @@ -67,7 +68,7 @@ struct mts64 {
104382 struct pardevice *pardev;
104383 int pardev_claimed;
104384
104385 - int open_count;
104386 + local_t open_count;
104387 int current_midi_output_port;
104388 int current_midi_input_port;
104389 u8 mode[MTS64_NUM_INPUT_PORTS];
104390 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104391 {
104392 struct mts64 *mts = substream->rmidi->private_data;
104393
104394 - if (mts->open_count == 0) {
104395 + if (local_read(&mts->open_count) == 0) {
104396 /* We don't need a spinlock here, because this is just called
104397 if the device has not been opened before.
104398 So there aren't any IRQs from the device */
104399 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104400
104401 msleep(50);
104402 }
104403 - ++(mts->open_count);
104404 + local_inc(&mts->open_count);
104405
104406 return 0;
104407 }
104408 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104409 struct mts64 *mts = substream->rmidi->private_data;
104410 unsigned long flags;
104411
104412 - --(mts->open_count);
104413 - if (mts->open_count == 0) {
104414 + if (local_dec_return(&mts->open_count) == 0) {
104415 /* We need the spinlock_irqsave here because we can still
104416 have IRQs at this point */
104417 spin_lock_irqsave(&mts->lock, flags);
104418 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104419
104420 msleep(500);
104421
104422 - } else if (mts->open_count < 0)
104423 - mts->open_count = 0;
104424 + } else if (local_read(&mts->open_count) < 0)
104425 + local_set(&mts->open_count, 0);
104426
104427 return 0;
104428 }
104429 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
104430 index 6839953..7a0f4b9 100644
104431 --- a/sound/drivers/opl3/opl3_seq.c
104432 +++ b/sound/drivers/opl3/opl3_seq.c
104433 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
104434 {
104435 static struct snd_seq_dev_ops ops =
104436 {
104437 - snd_opl3_seq_new_device,
104438 - snd_opl3_seq_delete_device
104439 + .init_device = snd_opl3_seq_new_device,
104440 + .free_device = snd_opl3_seq_delete_device
104441 };
104442
104443 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
104444 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
104445 index b953fb4..1999c01 100644
104446 --- a/sound/drivers/opl4/opl4_lib.c
104447 +++ b/sound/drivers/opl4/opl4_lib.c
104448 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
104449 MODULE_DESCRIPTION("OPL4 driver");
104450 MODULE_LICENSE("GPL");
104451
104452 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
104453 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
104454 {
104455 int timeout = 10;
104456 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
104457 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
104458 index 9919769..d7de36c 100644
104459 --- a/sound/drivers/opl4/opl4_seq.c
104460 +++ b/sound/drivers/opl4/opl4_seq.c
104461 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
104462 static int __init alsa_opl4_synth_init(void)
104463 {
104464 static struct snd_seq_dev_ops ops = {
104465 - snd_opl4_seq_new_device,
104466 - snd_opl4_seq_delete_device
104467 + .init_device = snd_opl4_seq_new_device,
104468 + .free_device = snd_opl4_seq_delete_device
104469 };
104470
104471 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
104472 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
104473 index 991018d..8984740 100644
104474 --- a/sound/drivers/portman2x4.c
104475 +++ b/sound/drivers/portman2x4.c
104476 @@ -48,6 +48,7 @@
104477 #include <sound/initval.h>
104478 #include <sound/rawmidi.h>
104479 #include <sound/control.h>
104480 +#include <asm/local.h>
104481
104482 #define CARD_NAME "Portman 2x4"
104483 #define DRIVER_NAME "portman"
104484 @@ -85,7 +86,7 @@ struct portman {
104485 struct pardevice *pardev;
104486 int pardev_claimed;
104487
104488 - int open_count;
104489 + local_t open_count;
104490 int mode[PORTMAN_NUM_INPUT_PORTS];
104491 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
104492 };
104493 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
104494 index 9048777..2d8b1fc 100644
104495 --- a/sound/firewire/amdtp.c
104496 +++ b/sound/firewire/amdtp.c
104497 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
104498 ptr = s->pcm_buffer_pointer + data_blocks;
104499 if (ptr >= pcm->runtime->buffer_size)
104500 ptr -= pcm->runtime->buffer_size;
104501 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
104502 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
104503
104504 s->pcm_period_pointer += data_blocks;
104505 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
104506 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
104507 */
104508 void amdtp_out_stream_update(struct amdtp_out_stream *s)
104509 {
104510 - ACCESS_ONCE(s->source_node_id_field) =
104511 + ACCESS_ONCE_RW(s->source_node_id_field) =
104512 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
104513 }
104514 EXPORT_SYMBOL(amdtp_out_stream_update);
104515 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
104516 index 2746ecd..c35dedd 100644
104517 --- a/sound/firewire/amdtp.h
104518 +++ b/sound/firewire/amdtp.h
104519 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
104520 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
104521 struct snd_pcm_substream *pcm)
104522 {
104523 - ACCESS_ONCE(s->pcm) = pcm;
104524 + ACCESS_ONCE_RW(s->pcm) = pcm;
104525 }
104526
104527 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
104528 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
104529 index fd42e6b..c041971 100644
104530 --- a/sound/firewire/isight.c
104531 +++ b/sound/firewire/isight.c
104532 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
104533 ptr += count;
104534 if (ptr >= runtime->buffer_size)
104535 ptr -= runtime->buffer_size;
104536 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
104537 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
104538
104539 isight->period_counter += count;
104540 if (isight->period_counter >= runtime->period_size) {
104541 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
104542 if (err < 0)
104543 return err;
104544
104545 - ACCESS_ONCE(isight->pcm_active) = true;
104546 + ACCESS_ONCE_RW(isight->pcm_active) = true;
104547
104548 return 0;
104549 }
104550 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
104551 {
104552 struct isight *isight = substream->private_data;
104553
104554 - ACCESS_ONCE(isight->pcm_active) = false;
104555 + ACCESS_ONCE_RW(isight->pcm_active) = false;
104556
104557 mutex_lock(&isight->mutex);
104558 isight_stop_streaming(isight);
104559 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
104560
104561 switch (cmd) {
104562 case SNDRV_PCM_TRIGGER_START:
104563 - ACCESS_ONCE(isight->pcm_running) = true;
104564 + ACCESS_ONCE_RW(isight->pcm_running) = true;
104565 break;
104566 case SNDRV_PCM_TRIGGER_STOP:
104567 - ACCESS_ONCE(isight->pcm_running) = false;
104568 + ACCESS_ONCE_RW(isight->pcm_running) = false;
104569 break;
104570 default:
104571 return -EINVAL;
104572 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
104573 index 858023c..83b3d3c 100644
104574 --- a/sound/firewire/scs1x.c
104575 +++ b/sound/firewire/scs1x.c
104576 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
104577 {
104578 struct scs *scs = stream->rmidi->private_data;
104579
104580 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
104581 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
104582 if (up) {
104583 scs->output_idle = false;
104584 tasklet_schedule(&scs->tasklet);
104585 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
104586 {
104587 struct scs *scs = stream->rmidi->private_data;
104588
104589 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
104590 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
104591 }
104592
104593 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
104594 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
104595
104596 snd_card_disconnect(scs->card);
104597
104598 - ACCESS_ONCE(scs->output) = NULL;
104599 - ACCESS_ONCE(scs->input) = NULL;
104600 + ACCESS_ONCE_RW(scs->output) = NULL;
104601 + ACCESS_ONCE_RW(scs->input) = NULL;
104602
104603 wait_event(scs->idle_wait, scs->output_idle);
104604
104605 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
104606 index 4e3fcfb..ab45a9d 100644
104607 --- a/sound/isa/sb/emu8000_synth.c
104608 +++ b/sound/isa/sb/emu8000_synth.c
104609 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
104610 {
104611
104612 static struct snd_seq_dev_ops ops = {
104613 - snd_emu8000_new_device,
104614 - snd_emu8000_delete_device,
104615 + .init_device = snd_emu8000_new_device,
104616 + .free_device = snd_emu8000_delete_device,
104617 };
104618 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
104619 sizeof(struct snd_emu8000*));
104620 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
104621 index 048439a..3be9f6f 100644
104622 --- a/sound/oss/sb_audio.c
104623 +++ b/sound/oss/sb_audio.c
104624 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
104625 buf16 = (signed short *)(localbuf + localoffs);
104626 while (c)
104627 {
104628 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
104629 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
104630 if (copy_from_user(lbuf8,
104631 userbuf+useroffs + p,
104632 locallen))
104633 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
104634 index 7d8803a..559f8d0 100644
104635 --- a/sound/oss/swarm_cs4297a.c
104636 +++ b/sound/oss/swarm_cs4297a.c
104637 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
104638 {
104639 struct cs4297a_state *s;
104640 u32 pwr, id;
104641 - mm_segment_t fs;
104642 int rval;
104643 #ifndef CONFIG_BCM_CS4297A_CSWARM
104644 u64 cfg;
104645 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
104646 if (!rval) {
104647 char *sb1250_duart_present;
104648
104649 +#if 0
104650 + mm_segment_t fs;
104651 fs = get_fs();
104652 set_fs(KERNEL_DS);
104653 -#if 0
104654 val = SOUND_MASK_LINE;
104655 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
104656 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
104657 val = initvol[i].vol;
104658 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
104659 }
104660 + set_fs(fs);
104661 // cs4297a_write_ac97(s, 0x18, 0x0808);
104662 #else
104663 // cs4297a_write_ac97(s, 0x5e, 0x180);
104664 cs4297a_write_ac97(s, 0x02, 0x0808);
104665 cs4297a_write_ac97(s, 0x18, 0x0808);
104666 #endif
104667 - set_fs(fs);
104668
104669 list_add(&s->list, &cs4297a_devs);
104670
104671 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
104672 index 4c41c90..37f3631 100644
104673 --- a/sound/pci/emu10k1/emu10k1_synth.c
104674 +++ b/sound/pci/emu10k1/emu10k1_synth.c
104675 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
104676 {
104677
104678 static struct snd_seq_dev_ops ops = {
104679 - snd_emu10k1_synth_new_device,
104680 - snd_emu10k1_synth_delete_device,
104681 + .init_device = snd_emu10k1_synth_new_device,
104682 + .free_device = snd_emu10k1_synth_delete_device,
104683 };
104684 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
104685 sizeof(struct snd_emu10k1_synth_arg));
104686 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
104687 index 69178c4..4493d52 100644
104688 --- a/sound/pci/hda/hda_codec.c
104689 +++ b/sound/pci/hda/hda_codec.c
104690 @@ -976,14 +976,10 @@ find_codec_preset(struct hda_codec *codec)
104691 mutex_unlock(&preset_mutex);
104692
104693 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
104694 - char name[32];
104695 if (!mod_requested)
104696 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
104697 - codec->vendor_id);
104698 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
104699 else
104700 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
104701 - (codec->vendor_id >> 16) & 0xffff);
104702 - request_module(name);
104703 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
104704 mod_requested++;
104705 goto again;
104706 }
104707 @@ -2668,7 +2664,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
104708 /* FIXME: set_fs() hack for obtaining user-space TLV data */
104709 mm_segment_t fs = get_fs();
104710 set_fs(get_ds());
104711 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
104712 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
104713 tlv = _tlv;
104714 set_fs(fs);
104715 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
104716 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
104717 index 4631a23..001ae57 100644
104718 --- a/sound/pci/ymfpci/ymfpci.h
104719 +++ b/sound/pci/ymfpci/ymfpci.h
104720 @@ -358,7 +358,7 @@ struct snd_ymfpci {
104721 spinlock_t reg_lock;
104722 spinlock_t voice_lock;
104723 wait_queue_head_t interrupt_sleep;
104724 - atomic_t interrupt_sleep_count;
104725 + atomic_unchecked_t interrupt_sleep_count;
104726 struct snd_info_entry *proc_entry;
104727 const struct firmware *dsp_microcode;
104728 const struct firmware *controller_microcode;
104729 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
104730 index d591c15..8cb8f94 100644
104731 --- a/sound/pci/ymfpci/ymfpci_main.c
104732 +++ b/sound/pci/ymfpci/ymfpci_main.c
104733 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
104734 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
104735 break;
104736 }
104737 - if (atomic_read(&chip->interrupt_sleep_count)) {
104738 - atomic_set(&chip->interrupt_sleep_count, 0);
104739 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
104740 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
104741 wake_up(&chip->interrupt_sleep);
104742 }
104743 __end:
104744 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
104745 continue;
104746 init_waitqueue_entry(&wait, current);
104747 add_wait_queue(&chip->interrupt_sleep, &wait);
104748 - atomic_inc(&chip->interrupt_sleep_count);
104749 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
104750 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
104751 remove_wait_queue(&chip->interrupt_sleep, &wait);
104752 }
104753 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
104754 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
104755 spin_unlock(&chip->reg_lock);
104756
104757 - if (atomic_read(&chip->interrupt_sleep_count)) {
104758 - atomic_set(&chip->interrupt_sleep_count, 0);
104759 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
104760 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
104761 wake_up(&chip->interrupt_sleep);
104762 }
104763 }
104764 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
104765 spin_lock_init(&chip->reg_lock);
104766 spin_lock_init(&chip->voice_lock);
104767 init_waitqueue_head(&chip->interrupt_sleep);
104768 - atomic_set(&chip->interrupt_sleep_count, 0);
104769 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
104770 chip->card = card;
104771 chip->pci = pci;
104772 chip->irq = -1;
104773 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
104774 index 35e2773..6d6ceee 100644
104775 --- a/sound/soc/fsl/fsl_ssi.c
104776 +++ b/sound/soc/fsl/fsl_ssi.c
104777 @@ -857,7 +857,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
104778 {
104779 struct fsl_ssi_private *ssi_private;
104780 int ret = 0;
104781 - struct device_attribute *dev_attr = NULL;
104782 + device_attribute_no_const *dev_attr = NULL;
104783 struct device_node *np = pdev->dev.of_node;
104784 const char *p, *sprop;
104785 const uint32_t *iprop;
104786 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
104787 index a66783e..ed1d791 100644
104788 --- a/sound/soc/soc-core.c
104789 +++ b/sound/soc/soc-core.c
104790 @@ -2253,8 +2253,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
104791 if (ret)
104792 return ret;
104793
104794 - ops->warm_reset = snd_soc_ac97_warm_reset;
104795 - ops->reset = snd_soc_ac97_reset;
104796 + pax_open_kernel();
104797 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
104798 + *(void **)&ops->reset = snd_soc_ac97_reset;
104799 + pax_close_kernel();
104800
104801 snd_ac97_rst_cfg = cfg;
104802 return 0;
104803 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
104804 index 7778b8e..3d619fc 100644
104805 --- a/sound/synth/emux/emux_seq.c
104806 +++ b/sound/synth/emux/emux_seq.c
104807 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
104808 * MIDI emulation operators
104809 */
104810 static struct snd_midi_op emux_ops = {
104811 - snd_emux_note_on,
104812 - snd_emux_note_off,
104813 - snd_emux_key_press,
104814 - snd_emux_terminate_note,
104815 - snd_emux_control,
104816 - snd_emux_nrpn,
104817 - snd_emux_sysex,
104818 + .note_on = snd_emux_note_on,
104819 + .note_off = snd_emux_note_off,
104820 + .key_press = snd_emux_key_press,
104821 + .note_terminate = snd_emux_terminate_note,
104822 + .control = snd_emux_control,
104823 + .nrpn = snd_emux_nrpn,
104824 + .sysex = snd_emux_sysex,
104825 };
104826
104827
104828 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
104829 new file mode 100644
104830 index 0000000..4c2c45c
104831 --- /dev/null
104832 +++ b/tools/gcc/.gitignore
104833 @@ -0,0 +1,2 @@
104834 +randomize_layout_seed.h
104835 +size_overflow_hash.h
104836 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
104837 new file mode 100644
104838 index 0000000..b198b6d
104839 --- /dev/null
104840 +++ b/tools/gcc/Makefile
104841 @@ -0,0 +1,54 @@
104842 +#CC := gcc
104843 +#PLUGIN_SOURCE_FILES := pax_plugin.c
104844 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
104845 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
104846 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
104847 +
104848 +ifeq ($(PLUGINCC),$(HOSTCC))
104849 +HOSTLIBS := hostlibs
104850 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
104851 +else
104852 +HOSTLIBS := hostcxxlibs
104853 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing
104854 +endif
104855 +
104856 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
104857 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
104858 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
104859 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
104860 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
104861 +$(HOSTLIBS)-y += colorize_plugin.so
104862 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
104863 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
104864 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
104865 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
104866 +
104867 +always := $($(HOSTLIBS)-y)
104868 +
104869 +constify_plugin-objs := constify_plugin.o
104870 +stackleak_plugin-objs := stackleak_plugin.o
104871 +kallocstat_plugin-objs := kallocstat_plugin.o
104872 +kernexec_plugin-objs := kernexec_plugin.o
104873 +checker_plugin-objs := checker_plugin.o
104874 +colorize_plugin-objs := colorize_plugin.o
104875 +size_overflow_plugin-objs := size_overflow_plugin.o
104876 +latent_entropy_plugin-objs := latent_entropy_plugin.o
104877 +structleak_plugin-objs := structleak_plugin.o
104878 +randomize_layout_plugin-objs := randomize_layout_plugin.o
104879 +
104880 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
104881 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
104882 +
104883 +quiet_cmd_build_size_overflow_hash = GENHASH $@
104884 + cmd_build_size_overflow_hash = \
104885 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
104886 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
104887 + $(call if_changed,build_size_overflow_hash)
104888 +
104889 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
104890 + cmd_create_randomize_layout_seed = \
104891 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
104892 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
104893 + $(call if_changed,create_randomize_layout_seed)
104894 +
104895 +targets += size_overflow_hash.h randomize_layout_seed.h randomize_layout_hash.h
104896 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
104897 new file mode 100644
104898 index 0000000..5452feea
104899 --- /dev/null
104900 +++ b/tools/gcc/checker_plugin.c
104901 @@ -0,0 +1,150 @@
104902 +/*
104903 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
104904 + * Licensed under the GPL v2
104905 + *
104906 + * Note: the choice of the license means that the compilation process is
104907 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
104908 + * but for the kernel it doesn't matter since it doesn't link against
104909 + * any of the gcc libraries
104910 + *
104911 + * gcc plugin to implement various sparse (source code checker) features
104912 + *
104913 + * TODO:
104914 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
104915 + *
104916 + * BUGS:
104917 + * - none known
104918 + */
104919 +
104920 +#include "gcc-common.h"
104921 +
104922 +extern void c_register_addr_space (const char *str, addr_space_t as);
104923 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
104924 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
104925 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
104926 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
104927 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
104928 +
104929 +int plugin_is_GPL_compatible;
104930 +
104931 +static struct plugin_info checker_plugin_info = {
104932 + .version = "201304082245",
104933 + .help = NULL,
104934 +};
104935 +
104936 +#define ADDR_SPACE_KERNEL 0
104937 +#define ADDR_SPACE_FORCE_KERNEL 1
104938 +#define ADDR_SPACE_USER 2
104939 +#define ADDR_SPACE_FORCE_USER 3
104940 +#define ADDR_SPACE_IOMEM 0
104941 +#define ADDR_SPACE_FORCE_IOMEM 0
104942 +#define ADDR_SPACE_PERCPU 0
104943 +#define ADDR_SPACE_FORCE_PERCPU 0
104944 +#define ADDR_SPACE_RCU 0
104945 +#define ADDR_SPACE_FORCE_RCU 0
104946 +
104947 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
104948 +{
104949 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
104950 +}
104951 +
104952 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
104953 +{
104954 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
104955 +}
104956 +
104957 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
104958 +{
104959 + return default_addr_space_valid_pointer_mode(mode, as);
104960 +}
104961 +
104962 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
104963 +{
104964 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
104965 +}
104966 +
104967 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
104968 +{
104969 + return default_addr_space_legitimize_address(x, oldx, mode, as);
104970 +}
104971 +
104972 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
104973 +{
104974 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
104975 + return true;
104976 +
104977 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
104978 + return true;
104979 +
104980 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
104981 + return true;
104982 +
104983 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
104984 + return true;
104985 +
104986 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
104987 + return true;
104988 +
104989 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
104990 + return true;
104991 +
104992 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
104993 + return true;
104994 +
104995 + return subset == superset;
104996 +}
104997 +
104998 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
104999 +{
105000 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
105001 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
105002 +
105003 + return op;
105004 +}
105005 +
105006 +static void register_checker_address_spaces(void *event_data, void *data)
105007 +{
105008 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
105009 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
105010 + c_register_addr_space("__user", ADDR_SPACE_USER);
105011 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
105012 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
105013 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
105014 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
105015 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
105016 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
105017 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
105018 +
105019 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
105020 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
105021 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
105022 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
105023 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
105024 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
105025 + targetm.addr_space.convert = checker_addr_space_convert;
105026 +}
105027 +
105028 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105029 +{
105030 + const char * const plugin_name = plugin_info->base_name;
105031 + const int argc = plugin_info->argc;
105032 + const struct plugin_argument * const argv = plugin_info->argv;
105033 + int i;
105034 +
105035 + if (!plugin_default_version_check(version, &gcc_version)) {
105036 + error(G_("incompatible gcc/plugin versions"));
105037 + return 1;
105038 + }
105039 +
105040 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
105041 +
105042 + for (i = 0; i < argc; ++i)
105043 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105044 +
105045 + if (TARGET_64BIT == 0)
105046 + return 0;
105047 +
105048 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
105049 +
105050 + return 0;
105051 +}
105052 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
105053 new file mode 100644
105054 index 0000000..06dcfda
105055 --- /dev/null
105056 +++ b/tools/gcc/colorize_plugin.c
105057 @@ -0,0 +1,169 @@
105058 +/*
105059 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
105060 + * Licensed under the GPL v2
105061 + *
105062 + * Note: the choice of the license means that the compilation process is
105063 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105064 + * but for the kernel it doesn't matter since it doesn't link against
105065 + * any of the gcc libraries
105066 + *
105067 + * gcc plugin to colorize diagnostic output
105068 + *
105069 + */
105070 +
105071 +#include "gcc-common.h"
105072 +
105073 +int plugin_is_GPL_compatible;
105074 +
105075 +static struct plugin_info colorize_plugin_info = {
105076 + .version = "201401260140",
105077 + .help = NULL,
105078 +};
105079 +
105080 +#define GREEN "\033[32m\033[2m"
105081 +#define LIGHTGREEN "\033[32m\033[1m"
105082 +#define YELLOW "\033[33m\033[2m"
105083 +#define LIGHTYELLOW "\033[33m\033[1m"
105084 +#define RED "\033[31m\033[2m"
105085 +#define LIGHTRED "\033[31m\033[1m"
105086 +#define BLUE "\033[34m\033[2m"
105087 +#define LIGHTBLUE "\033[34m\033[1m"
105088 +#define BRIGHT "\033[m\033[1m"
105089 +#define NORMAL "\033[m"
105090 +
105091 +static diagnostic_starter_fn old_starter;
105092 +static diagnostic_finalizer_fn old_finalizer;
105093 +
105094 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105095 +{
105096 + const char *color;
105097 + char *newprefix;
105098 +
105099 + switch (diagnostic->kind) {
105100 + case DK_NOTE:
105101 + color = LIGHTBLUE;
105102 + break;
105103 +
105104 + case DK_PEDWARN:
105105 + case DK_WARNING:
105106 + color = LIGHTYELLOW;
105107 + break;
105108 +
105109 + case DK_ERROR:
105110 + case DK_FATAL:
105111 + case DK_ICE:
105112 + case DK_PERMERROR:
105113 + case DK_SORRY:
105114 + color = LIGHTRED;
105115 + break;
105116 +
105117 + default:
105118 + color = NORMAL;
105119 + }
105120 +
105121 + old_starter(context, diagnostic);
105122 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
105123 + return;
105124 + pp_destroy_prefix(context->printer);
105125 + pp_set_prefix(context->printer, newprefix);
105126 +}
105127 +
105128 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105129 +{
105130 + old_finalizer(context, diagnostic);
105131 +}
105132 +
105133 +static void colorize_arm(void)
105134 +{
105135 + old_starter = diagnostic_starter(global_dc);
105136 + old_finalizer = diagnostic_finalizer(global_dc);
105137 +
105138 + diagnostic_starter(global_dc) = start_colorize;
105139 + diagnostic_finalizer(global_dc) = finalize_colorize;
105140 +}
105141 +
105142 +static unsigned int execute_colorize_rearm(void)
105143 +{
105144 + if (diagnostic_starter(global_dc) == start_colorize)
105145 + return 0;
105146 +
105147 + colorize_arm();
105148 + return 0;
105149 +}
105150 +
105151 +#if BUILDING_GCC_VERSION >= 4009
105152 +static const struct pass_data colorize_rearm_pass_data = {
105153 +#else
105154 +struct simple_ipa_opt_pass colorize_rearm_pass = {
105155 + .pass = {
105156 +#endif
105157 + .type = SIMPLE_IPA_PASS,
105158 + .name = "colorize_rearm",
105159 +#if BUILDING_GCC_VERSION >= 4008
105160 + .optinfo_flags = OPTGROUP_NONE,
105161 +#endif
105162 +#if BUILDING_GCC_VERSION >= 4009
105163 + .has_gate = false,
105164 + .has_execute = true,
105165 +#else
105166 + .gate = NULL,
105167 + .execute = execute_colorize_rearm,
105168 + .sub = NULL,
105169 + .next = NULL,
105170 + .static_pass_number = 0,
105171 +#endif
105172 + .tv_id = TV_NONE,
105173 + .properties_required = 0,
105174 + .properties_provided = 0,
105175 + .properties_destroyed = 0,
105176 + .todo_flags_start = 0,
105177 + .todo_flags_finish = 0
105178 +#if BUILDING_GCC_VERSION < 4009
105179 + }
105180 +#endif
105181 +};
105182 +
105183 +#if BUILDING_GCC_VERSION >= 4009
105184 +namespace {
105185 +class colorize_rearm_pass : public simple_ipa_opt_pass {
105186 +public:
105187 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
105188 + unsigned int execute() { return execute_colorize_rearm(); }
105189 +};
105190 +}
105191 +#endif
105192 +
105193 +static struct opt_pass *make_colorize_rearm_pass(void)
105194 +{
105195 +#if BUILDING_GCC_VERSION >= 4009
105196 + return new colorize_rearm_pass();
105197 +#else
105198 + return &colorize_rearm_pass.pass;
105199 +#endif
105200 +}
105201 +
105202 +static void colorize_start_unit(void *gcc_data, void *user_data)
105203 +{
105204 + colorize_arm();
105205 +}
105206 +
105207 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105208 +{
105209 + const char * const plugin_name = plugin_info->base_name;
105210 + struct register_pass_info colorize_rearm_pass_info;
105211 +
105212 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
105213 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
105214 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
105215 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105216 +
105217 + if (!plugin_default_version_check(version, &gcc_version)) {
105218 + error(G_("incompatible gcc/plugin versions"));
105219 + return 1;
105220 + }
105221 +
105222 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
105223 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
105224 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
105225 + return 0;
105226 +}
105227 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
105228 new file mode 100644
105229 index 0000000..4f67ac1
105230 --- /dev/null
105231 +++ b/tools/gcc/constify_plugin.c
105232 @@ -0,0 +1,552 @@
105233 +/*
105234 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
105235 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
105236 + * Licensed under the GPL v2, or (at your option) v3
105237 + *
105238 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
105239 + *
105240 + * Homepage:
105241 + * http://www.grsecurity.net/~ephox/const_plugin/
105242 + *
105243 + * Usage:
105244 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
105245 + * $ gcc -fplugin=constify_plugin.so test.c -O2
105246 + */
105247 +
105248 +#include "gcc-common.h"
105249 +
105250 +// unused C type flag in all versions 4.5-4.9
105251 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
105252 +
105253 +int plugin_is_GPL_compatible;
105254 +
105255 +static struct plugin_info const_plugin_info = {
105256 + .version = "201401270210",
105257 + .help = "no-constify\tturn off constification\n",
105258 +};
105259 +
105260 +typedef struct {
105261 + bool has_fptr_field;
105262 + bool has_writable_field;
105263 + bool has_do_const_field;
105264 + bool has_no_const_field;
105265 +} constify_info;
105266 +
105267 +static const_tree get_field_type(const_tree field)
105268 +{
105269 + return strip_array_types(TREE_TYPE(field));
105270 +}
105271 +
105272 +static bool is_fptr(const_tree field)
105273 +{
105274 + const_tree ptr = get_field_type(field);
105275 +
105276 + if (TREE_CODE(ptr) != POINTER_TYPE)
105277 + return false;
105278 +
105279 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
105280 +}
105281 +
105282 +/*
105283 + * determine whether the given structure type meets the requirements for automatic constification,
105284 + * including the constification attributes on nested structure types
105285 + */
105286 +static void constifiable(const_tree node, constify_info *cinfo)
105287 +{
105288 + const_tree field;
105289 +
105290 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105291 +
105292 + // e.g., pointer to structure fields while still constructing the structure type
105293 + if (TYPE_FIELDS(node) == NULL_TREE)
105294 + return;
105295 +
105296 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
105297 + const_tree type = get_field_type(field);
105298 + enum tree_code code = TREE_CODE(type);
105299 +
105300 + if (node == type)
105301 + continue;
105302 +
105303 + if (is_fptr(field))
105304 + cinfo->has_fptr_field = true;
105305 + else if (!TREE_READONLY(field))
105306 + cinfo->has_writable_field = true;
105307 +
105308 + if (code == RECORD_TYPE || code == UNION_TYPE) {
105309 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105310 + cinfo->has_do_const_field = true;
105311 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
105312 + cinfo->has_no_const_field = true;
105313 + else
105314 + constifiable(type, cinfo);
105315 + }
105316 + }
105317 +}
105318 +
105319 +static bool constified(const_tree node)
105320 +{
105321 + constify_info cinfo = {
105322 + .has_fptr_field = false,
105323 + .has_writable_field = false,
105324 + .has_do_const_field = false,
105325 + .has_no_const_field = false
105326 + };
105327 +
105328 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105329 +
105330 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
105331 +// gcc_assert(!TYPE_READONLY(node));
105332 + return false;
105333 + }
105334 +
105335 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
105336 + gcc_assert(TYPE_READONLY(node));
105337 + return true;
105338 + }
105339 +
105340 + constifiable(node, &cinfo);
105341 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
105342 + return false;
105343 +
105344 + return TYPE_READONLY(node);
105345 +}
105346 +
105347 +static void deconstify_tree(tree node);
105348 +
105349 +static void deconstify_type(tree type)
105350 +{
105351 + tree field;
105352 +
105353 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
105354 +
105355 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
105356 + const_tree fieldtype = get_field_type(field);
105357 +
105358 + // special case handling of simple ptr-to-same-array-type members
105359 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
105360 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
105361 +
105362 + if (TREE_TYPE(TREE_TYPE(field)) == type)
105363 + continue;
105364 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
105365 + continue;
105366 + if (!constified(ptrtype))
105367 + continue;
105368 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
105369 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
105370 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
105371 + }
105372 + continue;
105373 + }
105374 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
105375 + continue;
105376 + if (!constified(fieldtype))
105377 + continue;
105378 +
105379 + deconstify_tree(field);
105380 + TREE_READONLY(field) = 0;
105381 + }
105382 + TYPE_READONLY(type) = 0;
105383 + C_TYPE_FIELDS_READONLY(type) = 0;
105384 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105385 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105386 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
105387 + }
105388 +}
105389 +
105390 +static void deconstify_tree(tree node)
105391 +{
105392 + tree old_type, new_type, field;
105393 +
105394 + old_type = TREE_TYPE(node);
105395 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
105396 + node = TREE_TYPE(node) = copy_node(old_type);
105397 + old_type = TREE_TYPE(old_type);
105398 + }
105399 +
105400 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
105401 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
105402 +
105403 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
105404 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
105405 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
105406 + DECL_FIELD_CONTEXT(field) = new_type;
105407 +
105408 + deconstify_type(new_type);
105409 +
105410 + TREE_TYPE(node) = new_type;
105411 +}
105412 +
105413 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105414 +{
105415 + tree type;
105416 + constify_info cinfo = {
105417 + .has_fptr_field = false,
105418 + .has_writable_field = false,
105419 + .has_do_const_field = false,
105420 + .has_no_const_field = false
105421 + };
105422 +
105423 + *no_add_attrs = true;
105424 + if (TREE_CODE(*node) == FUNCTION_DECL) {
105425 + error("%qE attribute does not apply to functions (%qF)", name, *node);
105426 + return NULL_TREE;
105427 + }
105428 +
105429 + if (TREE_CODE(*node) == PARM_DECL) {
105430 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
105431 + return NULL_TREE;
105432 + }
105433 +
105434 + if (TREE_CODE(*node) == VAR_DECL) {
105435 + error("%qE attribute does not apply to variables (%qD)", name, *node);
105436 + return NULL_TREE;
105437 + }
105438 +
105439 + if (TYPE_P(*node)) {
105440 + type = *node;
105441 + } else {
105442 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
105443 + type = TREE_TYPE(*node);
105444 + }
105445 +
105446 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
105447 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
105448 + return NULL_TREE;
105449 + }
105450 +
105451 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
105452 + error("%qE attribute is already applied to the type %qT", name, type);
105453 + return NULL_TREE;
105454 + }
105455 +
105456 + if (TYPE_P(*node)) {
105457 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105458 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
105459 + else
105460 + *no_add_attrs = false;
105461 + return NULL_TREE;
105462 + }
105463 +
105464 + constifiable(type, &cinfo);
105465 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105466 + deconstify_tree(*node);
105467 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
105468 + return NULL_TREE;
105469 + }
105470 +
105471 + error("%qE attribute used on type %qT that is not constified", name, type);
105472 + return NULL_TREE;
105473 +}
105474 +
105475 +static void constify_type(tree type)
105476 +{
105477 + TYPE_READONLY(type) = 1;
105478 + C_TYPE_FIELDS_READONLY(type) = 1;
105479 + TYPE_CONSTIFY_VISITED(type) = 1;
105480 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105481 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
105482 +}
105483 +
105484 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105485 +{
105486 + *no_add_attrs = true;
105487 + if (!TYPE_P(*node)) {
105488 + error("%qE attribute applies to types only (%qD)", name, *node);
105489 + return NULL_TREE;
105490 + }
105491 +
105492 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
105493 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
105494 + return NULL_TREE;
105495 + }
105496 +
105497 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
105498 + error("%qE attribute used on %qT is already applied to the type", name, *node);
105499 + return NULL_TREE;
105500 + }
105501 +
105502 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
105503 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
105504 + return NULL_TREE;
105505 + }
105506 +
105507 + *no_add_attrs = false;
105508 + return NULL_TREE;
105509 +}
105510 +
105511 +static struct attribute_spec no_const_attr = {
105512 + .name = "no_const",
105513 + .min_length = 0,
105514 + .max_length = 0,
105515 + .decl_required = false,
105516 + .type_required = false,
105517 + .function_type_required = false,
105518 + .handler = handle_no_const_attribute,
105519 +#if BUILDING_GCC_VERSION >= 4007
105520 + .affects_type_identity = true
105521 +#endif
105522 +};
105523 +
105524 +static struct attribute_spec do_const_attr = {
105525 + .name = "do_const",
105526 + .min_length = 0,
105527 + .max_length = 0,
105528 + .decl_required = false,
105529 + .type_required = false,
105530 + .function_type_required = false,
105531 + .handler = handle_do_const_attribute,
105532 +#if BUILDING_GCC_VERSION >= 4007
105533 + .affects_type_identity = true
105534 +#endif
105535 +};
105536 +
105537 +static void register_attributes(void *event_data, void *data)
105538 +{
105539 + register_attribute(&no_const_attr);
105540 + register_attribute(&do_const_attr);
105541 +}
105542 +
105543 +static void finish_type(void *event_data, void *data)
105544 +{
105545 + tree type = (tree)event_data;
105546 + constify_info cinfo = {
105547 + .has_fptr_field = false,
105548 + .has_writable_field = false,
105549 + .has_do_const_field = false,
105550 + .has_no_const_field = false
105551 + };
105552 +
105553 + if (type == NULL_TREE || type == error_mark_node)
105554 + return;
105555 +
105556 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
105557 + return;
105558 +
105559 + constifiable(type, &cinfo);
105560 +
105561 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
105562 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
105563 + deconstify_type(type);
105564 + TYPE_CONSTIFY_VISITED(type) = 1;
105565 + } else
105566 + error("'no_const' attribute used on type %qT that is not constified", type);
105567 + return;
105568 + }
105569 +
105570 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105571 + if (!cinfo.has_writable_field) {
105572 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
105573 + return;
105574 + }
105575 + constify_type(type);
105576 + return;
105577 + }
105578 +
105579 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
105580 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105581 + error("'do_const' attribute used on type %qT that is constified", type);
105582 + return;
105583 + }
105584 + constify_type(type);
105585 + return;
105586 + }
105587 +
105588 + deconstify_type(type);
105589 + TYPE_CONSTIFY_VISITED(type) = 1;
105590 +}
105591 +
105592 +static void check_global_variables(void *event_data, void *data)
105593 +{
105594 + struct varpool_node *node;
105595 +
105596 + FOR_EACH_VARIABLE(node) {
105597 + tree var = NODE_DECL(node);
105598 + tree type = TREE_TYPE(var);
105599 +
105600 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
105601 + continue;
105602 +
105603 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
105604 + continue;
105605 +
105606 + if (!TYPE_CONSTIFY_VISITED(type))
105607 + continue;
105608 +
105609 + if (DECL_EXTERNAL(var))
105610 + continue;
105611 +
105612 + if (DECL_INITIAL(var))
105613 + continue;
105614 +
105615 + // this works around a gcc bug/feature where uninitialized globals
105616 + // are moved into the .bss section regardless of any constification
105617 + DECL_INITIAL(var) = build_constructor(type, NULL);
105618 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
105619 + }
105620 +}
105621 +
105622 +static unsigned int check_local_variables(void)
105623 +{
105624 + unsigned int ret = 0;
105625 + tree var;
105626 +
105627 + unsigned int i;
105628 +
105629 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
105630 + tree type = TREE_TYPE(var);
105631 +
105632 + gcc_assert(DECL_P(var));
105633 + if (is_global_var(var))
105634 + continue;
105635 +
105636 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
105637 + continue;
105638 +
105639 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
105640 + continue;
105641 +
105642 + if (!TYPE_CONSTIFY_VISITED(type))
105643 + continue;
105644 +
105645 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
105646 + ret = 1;
105647 + }
105648 + return ret;
105649 +}
105650 +
105651 +#if BUILDING_GCC_VERSION >= 4009
105652 +static const struct pass_data check_local_variables_pass_data = {
105653 +#else
105654 +static struct gimple_opt_pass check_local_variables_pass = {
105655 + .pass = {
105656 +#endif
105657 + .type = GIMPLE_PASS,
105658 + .name = "check_local_variables",
105659 +#if BUILDING_GCC_VERSION >= 4008
105660 + .optinfo_flags = OPTGROUP_NONE,
105661 +#endif
105662 +#if BUILDING_GCC_VERSION >= 4009
105663 + .has_gate = false,
105664 + .has_execute = true,
105665 +#else
105666 + .gate = NULL,
105667 + .execute = check_local_variables,
105668 + .sub = NULL,
105669 + .next = NULL,
105670 + .static_pass_number = 0,
105671 +#endif
105672 + .tv_id = TV_NONE,
105673 + .properties_required = 0,
105674 + .properties_provided = 0,
105675 + .properties_destroyed = 0,
105676 + .todo_flags_start = 0,
105677 + .todo_flags_finish = 0
105678 +#if BUILDING_GCC_VERSION < 4009
105679 + }
105680 +#endif
105681 +};
105682 +
105683 +#if BUILDING_GCC_VERSION >= 4009
105684 +namespace {
105685 +class check_local_variables_pass : public gimple_opt_pass {
105686 +public:
105687 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
105688 + unsigned int execute() { return check_local_variables(); }
105689 +};
105690 +}
105691 +#endif
105692 +
105693 +static struct opt_pass *make_check_local_variables_pass(void)
105694 +{
105695 +#if BUILDING_GCC_VERSION >= 4009
105696 + return new check_local_variables_pass();
105697 +#else
105698 + return &check_local_variables_pass.pass;
105699 +#endif
105700 +}
105701 +
105702 +static struct {
105703 + const char *name;
105704 + const char *asm_op;
105705 +} sections[] = {
105706 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
105707 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
105708 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
105709 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
105710 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
105711 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
105712 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
105713 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
105714 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
105715 +};
105716 +
105717 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
105718 +
105719 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
105720 +{
105721 + size_t i;
105722 +
105723 + for (i = 0; i < ARRAY_SIZE(sections); i++)
105724 + if (!strcmp(sections[i].name, name))
105725 + return 0;
105726 + return old_section_type_flags(decl, name, reloc);
105727 +}
105728 +
105729 +static void constify_start_unit(void *gcc_data, void *user_data)
105730 +{
105731 +// size_t i;
105732 +
105733 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
105734 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
105735 +// sections[i].section = get_section(sections[i].name, 0, NULL);
105736 +
105737 + old_section_type_flags = targetm.section_type_flags;
105738 + targetm.section_type_flags = constify_section_type_flags;
105739 +}
105740 +
105741 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105742 +{
105743 + const char * const plugin_name = plugin_info->base_name;
105744 + const int argc = plugin_info->argc;
105745 + const struct plugin_argument * const argv = plugin_info->argv;
105746 + int i;
105747 + bool constify = true;
105748 +
105749 + struct register_pass_info check_local_variables_pass_info;
105750 +
105751 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
105752 + check_local_variables_pass_info.reference_pass_name = "ssa";
105753 + check_local_variables_pass_info.ref_pass_instance_number = 1;
105754 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
105755 +
105756 + if (!plugin_default_version_check(version, &gcc_version)) {
105757 + error(G_("incompatible gcc/plugin versions"));
105758 + return 1;
105759 + }
105760 +
105761 + for (i = 0; i < argc; ++i) {
105762 + if (!(strcmp(argv[i].key, "no-constify"))) {
105763 + constify = false;
105764 + continue;
105765 + }
105766 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105767 + }
105768 +
105769 + if (strcmp(lang_hooks.name, "GNU C")) {
105770 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
105771 + constify = false;
105772 + }
105773 +
105774 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
105775 + if (constify) {
105776 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
105777 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
105778 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
105779 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
105780 + }
105781 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
105782 +
105783 + return 0;
105784 +}
105785 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
105786 new file mode 100644
105787 index 0000000..6dbb502
105788 --- /dev/null
105789 +++ b/tools/gcc/gcc-common.h
105790 @@ -0,0 +1,286 @@
105791 +#ifndef GCC_COMMON_H_INCLUDED
105792 +#define GCC_COMMON_H_INCLUDED
105793 +
105794 +#include "plugin.h"
105795 +#include "bversion.h"
105796 +#include "plugin-version.h"
105797 +#include "config.h"
105798 +#include "system.h"
105799 +#include "coretypes.h"
105800 +#include "tm.h"
105801 +#include "line-map.h"
105802 +#include "input.h"
105803 +#include "tree.h"
105804 +
105805 +#include "tree-inline.h"
105806 +#include "version.h"
105807 +#include "rtl.h"
105808 +#include "tm_p.h"
105809 +#include "flags.h"
105810 +//#include "insn-attr.h"
105811 +//#include "insn-config.h"
105812 +//#include "insn-flags.h"
105813 +#include "hard-reg-set.h"
105814 +//#include "recog.h"
105815 +#include "output.h"
105816 +#include "except.h"
105817 +#include "function.h"
105818 +#include "toplev.h"
105819 +//#include "expr.h"
105820 +#include "basic-block.h"
105821 +#include "intl.h"
105822 +#include "ggc.h"
105823 +//#include "regs.h"
105824 +#include "timevar.h"
105825 +
105826 +#include "params.h"
105827 +#include "pointer-set.h"
105828 +#include "emit-rtl.h"
105829 +//#include "reload.h"
105830 +//#include "ira.h"
105831 +//#include "dwarf2asm.h"
105832 +#include "debug.h"
105833 +#include "target.h"
105834 +#include "langhooks.h"
105835 +#include "cfgloop.h"
105836 +//#include "hosthooks.h"
105837 +#include "cgraph.h"
105838 +#include "opts.h"
105839 +//#include "coverage.h"
105840 +//#include "value-prof.h"
105841 +
105842 +#if BUILDING_GCC_VERSION >= 4007
105843 +#include "tree-pretty-print.h"
105844 +#include "gimple-pretty-print.h"
105845 +#include "c-tree.h"
105846 +//#include "alloc-pool.h"
105847 +#endif
105848 +
105849 +#if BUILDING_GCC_VERSION <= 4008
105850 +#include "tree-flow.h"
105851 +#else
105852 +#include "tree-cfgcleanup.h"
105853 +#endif
105854 +
105855 +#include "diagnostic.h"
105856 +//#include "tree-diagnostic.h"
105857 +#include "tree-dump.h"
105858 +#include "tree-pass.h"
105859 +//#include "df.h"
105860 +#include "predict.h"
105861 +//#include "lto-streamer.h"
105862 +#include "ipa-utils.h"
105863 +
105864 +#if BUILDING_GCC_VERSION >= 4009
105865 +#include "varasm.h"
105866 +#include "stor-layout.h"
105867 +#include "internal-fn.h"
105868 +#include "gimple-expr.h"
105869 +//#include "diagnostic-color.h"
105870 +#include "context.h"
105871 +#include "tree-ssa-alias.h"
105872 +#include "stringpool.h"
105873 +#include "tree-ssanames.h"
105874 +#include "print-tree.h"
105875 +#include "tree-eh.h"
105876 +#endif
105877 +
105878 +#include "gimple.h"
105879 +
105880 +#if BUILDING_GCC_VERSION >= 4009
105881 +#include "tree-ssa-operands.h"
105882 +#include "tree-phinodes.h"
105883 +#include "tree-cfg.h"
105884 +#include "gimple-iterator.h"
105885 +#include "gimple-ssa.h"
105886 +#include "ssa-iterators.h"
105887 +#endif
105888 +
105889 +//#include "expr.h" where are you...
105890 +extern rtx emit_move_insn(rtx x, rtx y);
105891 +
105892 +// missing from basic_block.h...
105893 +extern void debug_dominance_info(enum cdi_direction dir);
105894 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
105895 +
105896 +#define __unused __attribute__((__unused__))
105897 +
105898 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
105899 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
105900 +
105901 +#if BUILDING_GCC_VERSION == 4005
105902 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
105903 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
105904 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
105905 +
105906 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
105907 +{
105908 + tree fndecl;
105909 +
105910 + if (!is_gimple_call(stmt))
105911 + return false;
105912 + fndecl = gimple_call_fndecl(stmt);
105913 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
105914 + return false;
105915 +// print_node(stderr, "pax", fndecl, 4);
105916 + return DECL_FUNCTION_CODE(fndecl) == code;
105917 +}
105918 +
105919 +static inline bool is_simple_builtin(tree decl)
105920 +{
105921 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
105922 + return false;
105923 +
105924 + switch (DECL_FUNCTION_CODE(decl)) {
105925 + /* Builtins that expand to constants. */
105926 + case BUILT_IN_CONSTANT_P:
105927 + case BUILT_IN_EXPECT:
105928 + case BUILT_IN_OBJECT_SIZE:
105929 + case BUILT_IN_UNREACHABLE:
105930 + /* Simple register moves or loads from stack. */
105931 + case BUILT_IN_RETURN_ADDRESS:
105932 + case BUILT_IN_EXTRACT_RETURN_ADDR:
105933 + case BUILT_IN_FROB_RETURN_ADDR:
105934 + case BUILT_IN_RETURN:
105935 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
105936 + case BUILT_IN_FRAME_ADDRESS:
105937 + case BUILT_IN_VA_END:
105938 + case BUILT_IN_STACK_SAVE:
105939 + case BUILT_IN_STACK_RESTORE:
105940 + /* Exception state returns or moves registers around. */
105941 + case BUILT_IN_EH_FILTER:
105942 + case BUILT_IN_EH_POINTER:
105943 + case BUILT_IN_EH_COPY_VALUES:
105944 + return true;
105945 +
105946 + default:
105947 + return false;
105948 + }
105949 +}
105950 +#endif
105951 +
105952 +#if BUILDING_GCC_VERSION <= 4006
105953 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
105954 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
105955 +
105956 +// should come from c-tree.h if only it were installed for gcc 4.5...
105957 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
105958 +
105959 +#define get_random_seed(noinit) ({ \
105960 + unsigned HOST_WIDE_INT seed; \
105961 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
105962 + seed * seed; })
105963 +
105964 +static inline bool gimple_clobber_p(gimple s)
105965 +{
105966 + return false;
105967 +}
105968 +
105969 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
105970 +{
105971 + return implicit_built_in_decls[fncode];
105972 +}
105973 +
105974 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
105975 +{
105976 + struct cgraph_node *node = cgraph_get_node(decl);
105977 +
105978 + return node ? node : cgraph_node(decl);
105979 +}
105980 +
105981 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
105982 +{
105983 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
105984 +}
105985 +
105986 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
105987 +{
105988 + struct cgraph_node *node;
105989 +
105990 + for (node = cgraph_nodes; node; node = node->next)
105991 + if (cgraph_function_with_gimple_body_p(node))
105992 + return node;
105993 + return NULL;
105994 +}
105995 +
105996 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
105997 +{
105998 + for (node = node->next; node; node = node->next)
105999 + if (cgraph_function_with_gimple_body_p(node))
106000 + return node;
106001 + return NULL;
106002 +}
106003 +
106004 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
106005 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
106006 + (node) = cgraph_next_function_with_gimple_body(node))
106007 +#endif
106008 +
106009 +#if BUILDING_GCC_VERSION == 4006
106010 +extern void debug_gimple_stmt(gimple);
106011 +extern void debug_gimple_seq(gimple_seq);
106012 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
106013 +extern void print_gimple_stmt(FILE *, gimple, int, int);
106014 +extern void print_gimple_expr(FILE *, gimple, int, int);
106015 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
106016 +#endif
106017 +
106018 +#if BUILDING_GCC_VERSION <= 4007
106019 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
106020 +#define PROP_loops 0
106021 +
106022 +static inline int bb_loop_depth(const_basic_block bb)
106023 +{
106024 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
106025 +}
106026 +
106027 +static inline bool gimple_store_p(gimple gs)
106028 +{
106029 + tree lhs = gimple_get_lhs(gs);
106030 + return lhs && !is_gimple_reg(lhs);
106031 +}
106032 +#endif
106033 +
106034 +#if BUILDING_GCC_VERSION >= 4007
106035 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
106036 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
106037 +#endif
106038 +
106039 +#if BUILDING_GCC_VERSION <= 4008
106040 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
106041 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
106042 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
106043 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
106044 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
106045 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
106046 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
106047 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
106048 +
106049 +static inline const char *get_tree_code_name(enum tree_code code)
106050 +{
106051 + gcc_assert(code < MAX_TREE_CODES);
106052 + return tree_code_name[code];
106053 +}
106054 +
106055 +#define ipa_remove_stmt_references(cnode, stmt)
106056 +#endif
106057 +
106058 +#if BUILDING_GCC_VERSION == 4008
106059 +#define NODE_DECL(node) node->symbol.decl
106060 +#else
106061 +#define NODE_DECL(node) node->decl
106062 +#endif
106063 +
106064 +#if BUILDING_GCC_VERSION >= 4008
106065 +#define add_referenced_var(var)
106066 +#define mark_sym_for_renaming(var)
106067 +#define varpool_mark_needed_node(node)
106068 +#define TODO_dump_func 0
106069 +#define TODO_dump_cgraph 0
106070 +#endif
106071 +
106072 +#if BUILDING_GCC_VERSION >= 4009
106073 +#define TODO_ggc_collect 0
106074 +#endif
106075 +
106076 +#endif
106077 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
106078 new file mode 100644
106079 index 0000000..7514850
106080 --- /dev/null
106081 +++ b/tools/gcc/gen-random-seed.sh
106082 @@ -0,0 +1,8 @@
106083 +#!/bin/sh
106084 +
106085 +if [ ! -f "$1" ]; then
106086 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
106087 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
106088 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
106089 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
106090 +fi
106091 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
106092 new file mode 100644
106093 index 0000000..e518932
106094 --- /dev/null
106095 +++ b/tools/gcc/generate_size_overflow_hash.sh
106096 @@ -0,0 +1,94 @@
106097 +#!/bin/bash
106098 +
106099 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
106100 +
106101 +header1="size_overflow_hash.h"
106102 +database="size_overflow_hash.data"
106103 +n=65536
106104 +
106105 +usage() {
106106 +cat <<EOF
106107 +usage: $0 options
106108 +OPTIONS:
106109 + -h|--help help
106110 + -o header file
106111 + -d database file
106112 + -n hash array size
106113 +EOF
106114 + return 0
106115 +}
106116 +
106117 +while true
106118 +do
106119 + case "$1" in
106120 + -h|--help) usage && exit 0;;
106121 + -n) n=$2; shift 2;;
106122 + -o) header1="$2"; shift 2;;
106123 + -d) database="$2"; shift 2;;
106124 + --) shift 1; break ;;
106125 + *) break ;;
106126 + esac
106127 +done
106128 +
106129 +create_defines() {
106130 + for i in `seq 0 31`
106131 + do
106132 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
106133 + done
106134 + echo >> "$header1"
106135 +}
106136 +
106137 +create_structs() {
106138 + rm -f "$header1"
106139 +
106140 + create_defines
106141 +
106142 + cat "$database" | while read data
106143 + do
106144 + data_array=($data)
106145 + struct_hash_name="${data_array[0]}"
106146 + funcn="${data_array[1]}"
106147 + params="${data_array[2]}"
106148 + next="${data_array[4]}"
106149 +
106150 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
106151 +
106152 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
106153 + echo -en "\t.param\t= " >> "$header1"
106154 + line=
106155 + for param_num in ${params//-/ };
106156 + do
106157 + line="${line}PARAM"$param_num"|"
106158 + done
106159 +
106160 + echo -e "${line%?},\n};\n" >> "$header1"
106161 + done
106162 +}
106163 +
106164 +create_headers() {
106165 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
106166 +}
106167 +
106168 +create_array_elements() {
106169 + index=0
106170 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
106171 + do
106172 + data_array=($data)
106173 + i="${data_array[3]}"
106174 + hash="${data_array[0]}"
106175 + while [[ $index -lt $i ]]
106176 + do
106177 + echo -e "\t["$index"]\t= NULL," >> "$header1"
106178 + index=$(($index + 1))
106179 + done
106180 + index=$(($index + 1))
106181 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
106182 + done
106183 + echo '};' >> $header1
106184 +}
106185 +
106186 +create_structs
106187 +create_headers
106188 +create_array_elements
106189 +
106190 +exit 0
106191 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
106192 new file mode 100644
106193 index 0000000..b559327
106194 --- /dev/null
106195 +++ b/tools/gcc/kallocstat_plugin.c
106196 @@ -0,0 +1,182 @@
106197 +/*
106198 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106199 + * Licensed under the GPL v2
106200 + *
106201 + * Note: the choice of the license means that the compilation process is
106202 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106203 + * but for the kernel it doesn't matter since it doesn't link against
106204 + * any of the gcc libraries
106205 + *
106206 + * gcc plugin to find the distribution of k*alloc sizes
106207 + *
106208 + * TODO:
106209 + *
106210 + * BUGS:
106211 + * - none known
106212 + */
106213 +
106214 +#include "gcc-common.h"
106215 +
106216 +int plugin_is_GPL_compatible;
106217 +
106218 +static struct plugin_info kallocstat_plugin_info = {
106219 + .version = "201401260140",
106220 + .help = NULL
106221 +};
106222 +
106223 +static const char * const kalloc_functions[] = {
106224 + "__kmalloc",
106225 + "kmalloc",
106226 + "kmalloc_large",
106227 + "kmalloc_node",
106228 + "kmalloc_order",
106229 + "kmalloc_order_trace",
106230 + "kmalloc_slab",
106231 + "kzalloc",
106232 + "kzalloc_node",
106233 +};
106234 +
106235 +static bool is_kalloc(const char *fnname)
106236 +{
106237 + size_t i;
106238 +
106239 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
106240 + if (!strcmp(fnname, kalloc_functions[i]))
106241 + return true;
106242 + return false;
106243 +}
106244 +
106245 +static unsigned int execute_kallocstat(void)
106246 +{
106247 + basic_block bb;
106248 +
106249 + // 1. loop through BBs and GIMPLE statements
106250 + FOR_EACH_BB_FN(bb, cfun) {
106251 + gimple_stmt_iterator gsi;
106252 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106253 + // gimple match:
106254 + tree fndecl, size;
106255 + gimple stmt;
106256 + const char *fnname;
106257 +
106258 + // is it a call
106259 + stmt = gsi_stmt(gsi);
106260 + if (!is_gimple_call(stmt))
106261 + continue;
106262 + fndecl = gimple_call_fndecl(stmt);
106263 + if (fndecl == NULL_TREE)
106264 + continue;
106265 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
106266 + continue;
106267 +
106268 + // is it a call to k*alloc
106269 + fnname = DECL_NAME_POINTER(fndecl);
106270 + if (!is_kalloc(fnname))
106271 + continue;
106272 +
106273 + // is the size arg const or the result of a simple const assignment
106274 + size = gimple_call_arg(stmt, 0);
106275 + while (true) {
106276 + expanded_location xloc;
106277 + size_t size_val;
106278 +
106279 + if (TREE_CONSTANT(size)) {
106280 + xloc = expand_location(gimple_location(stmt));
106281 + if (!xloc.file)
106282 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
106283 + size_val = TREE_INT_CST_LOW(size);
106284 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
106285 + break;
106286 + }
106287 +
106288 + if (TREE_CODE(size) != SSA_NAME)
106289 + break;
106290 + stmt = SSA_NAME_DEF_STMT(size);
106291 +//debug_gimple_stmt(stmt);
106292 +//debug_tree(size);
106293 + if (!stmt || !is_gimple_assign(stmt))
106294 + break;
106295 + if (gimple_num_ops(stmt) != 2)
106296 + break;
106297 + size = gimple_assign_rhs1(stmt);
106298 + }
106299 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
106300 +//debug_tree(gimple_call_fn(call_stmt));
106301 +//print_node(stderr, "pax", fndecl, 4);
106302 + }
106303 + }
106304 +
106305 + return 0;
106306 +}
106307 +
106308 +#if BUILDING_GCC_VERSION >= 4009
106309 +static const struct pass_data kallocstat_pass_data = {
106310 +#else
106311 +static struct gimple_opt_pass kallocstat_pass = {
106312 + .pass = {
106313 +#endif
106314 + .type = GIMPLE_PASS,
106315 + .name = "kallocstat",
106316 +#if BUILDING_GCC_VERSION >= 4008
106317 + .optinfo_flags = OPTGROUP_NONE,
106318 +#endif
106319 +#if BUILDING_GCC_VERSION >= 4009
106320 + .has_gate = false,
106321 + .has_execute = true,
106322 +#else
106323 + .gate = NULL,
106324 + .execute = execute_kallocstat,
106325 + .sub = NULL,
106326 + .next = NULL,
106327 + .static_pass_number = 0,
106328 +#endif
106329 + .tv_id = TV_NONE,
106330 + .properties_required = 0,
106331 + .properties_provided = 0,
106332 + .properties_destroyed = 0,
106333 + .todo_flags_start = 0,
106334 + .todo_flags_finish = 0
106335 +#if BUILDING_GCC_VERSION < 4009
106336 + }
106337 +#endif
106338 +};
106339 +
106340 +#if BUILDING_GCC_VERSION >= 4009
106341 +namespace {
106342 +class kallocstat_pass : public gimple_opt_pass {
106343 +public:
106344 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
106345 + unsigned int execute() { return execute_kallocstat(); }
106346 +};
106347 +}
106348 +#endif
106349 +
106350 +static struct opt_pass *make_kallocstat_pass(void)
106351 +{
106352 +#if BUILDING_GCC_VERSION >= 4009
106353 + return new kallocstat_pass();
106354 +#else
106355 + return &kallocstat_pass.pass;
106356 +#endif
106357 +}
106358 +
106359 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106360 +{
106361 + const char * const plugin_name = plugin_info->base_name;
106362 + struct register_pass_info kallocstat_pass_info;
106363 +
106364 + kallocstat_pass_info.pass = make_kallocstat_pass();
106365 + kallocstat_pass_info.reference_pass_name = "ssa";
106366 + kallocstat_pass_info.ref_pass_instance_number = 1;
106367 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
106368 +
106369 + if (!plugin_default_version_check(version, &gcc_version)) {
106370 + error(G_("incompatible gcc/plugin versions"));
106371 + return 1;
106372 + }
106373 +
106374 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
106375 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
106376 +
106377 + return 0;
106378 +}
106379 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
106380 new file mode 100644
106381 index 0000000..dd73713
106382 --- /dev/null
106383 +++ b/tools/gcc/kernexec_plugin.c
106384 @@ -0,0 +1,519 @@
106385 +/*
106386 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106387 + * Licensed under the GPL v2
106388 + *
106389 + * Note: the choice of the license means that the compilation process is
106390 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106391 + * but for the kernel it doesn't matter since it doesn't link against
106392 + * any of the gcc libraries
106393 + *
106394 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
106395 + *
106396 + * TODO:
106397 + *
106398 + * BUGS:
106399 + * - none known
106400 + */
106401 +
106402 +#include "gcc-common.h"
106403 +
106404 +int plugin_is_GPL_compatible;
106405 +
106406 +static struct plugin_info kernexec_plugin_info = {
106407 + .version = "201401260140",
106408 + .help = "method=[bts|or]\tinstrumentation method\n"
106409 +};
106410 +
106411 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
106412 +static void (*kernexec_instrument_retaddr)(rtx);
106413 +
106414 +/*
106415 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
106416 + */
106417 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
106418 +{
106419 + gimple asm_movabs_stmt;
106420 +
106421 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
106422 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
106423 + gimple_asm_set_volatile(asm_movabs_stmt, true);
106424 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
106425 + update_stmt(asm_movabs_stmt);
106426 +}
106427 +
106428 +/*
106429 + * find all asm() stmts that clobber r12 and add a reload of r12
106430 + */
106431 +static unsigned int execute_kernexec_reload(void)
106432 +{
106433 + basic_block bb;
106434 +
106435 + // 1. loop through BBs and GIMPLE statements
106436 + FOR_EACH_BB_FN(bb, cfun) {
106437 + gimple_stmt_iterator gsi;
106438 +
106439 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106440 + // gimple match: __asm__ ("" : : : "r12");
106441 + gimple asm_stmt;
106442 + size_t nclobbers;
106443 +
106444 + // is it an asm ...
106445 + asm_stmt = gsi_stmt(gsi);
106446 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
106447 + continue;
106448 +
106449 + // ... clobbering r12
106450 + nclobbers = gimple_asm_nclobbers(asm_stmt);
106451 + while (nclobbers--) {
106452 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
106453 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
106454 + continue;
106455 + kernexec_reload_fptr_mask(&gsi);
106456 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
106457 + break;
106458 + }
106459 + }
106460 + }
106461 +
106462 + return 0;
106463 +}
106464 +
106465 +/*
106466 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
106467 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
106468 + */
106469 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
106470 +{
106471 + gimple assign_intptr, assign_new_fptr, call_stmt;
106472 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
106473 +
106474 + call_stmt = gsi_stmt(*gsi);
106475 + old_fptr = gimple_call_fn(call_stmt);
106476 +
106477 + // create temporary unsigned long variable used for bitops and cast fptr to it
106478 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
106479 + add_referenced_var(intptr);
106480 + intptr = make_ssa_name(intptr, NULL);
106481 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
106482 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106483 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106484 + update_stmt(assign_intptr);
106485 +
106486 + // apply logical or to temporary unsigned long and bitmask
106487 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
106488 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
106489 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
106490 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
106491 + assign_intptr = gimple_build_assign(intptr, orptr);
106492 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106493 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106494 + update_stmt(assign_intptr);
106495 +
106496 + // cast temporary unsigned long back to a temporary fptr variable
106497 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
106498 + add_referenced_var(new_fptr);
106499 + new_fptr = make_ssa_name(new_fptr, NULL);
106500 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
106501 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
106502 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
106503 + update_stmt(assign_new_fptr);
106504 +
106505 + // replace call stmt fn with the new fptr
106506 + gimple_call_set_fn(call_stmt, new_fptr);
106507 + update_stmt(call_stmt);
106508 +}
106509 +
106510 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
106511 +{
106512 + gimple asm_or_stmt, call_stmt;
106513 + tree old_fptr, new_fptr, input, output;
106514 +#if BUILDING_GCC_VERSION <= 4007
106515 + VEC(tree, gc) *inputs = NULL;
106516 + VEC(tree, gc) *outputs = NULL;
106517 +#else
106518 + vec<tree, va_gc> *inputs = NULL;
106519 + vec<tree, va_gc> *outputs = NULL;
106520 +#endif
106521 +
106522 + call_stmt = gsi_stmt(*gsi);
106523 + old_fptr = gimple_call_fn(call_stmt);
106524 +
106525 + // create temporary fptr variable
106526 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
106527 + add_referenced_var(new_fptr);
106528 + new_fptr = make_ssa_name(new_fptr, NULL);
106529 +
106530 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
106531 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
106532 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
106533 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
106534 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
106535 +#if BUILDING_GCC_VERSION <= 4007
106536 + VEC_safe_push(tree, gc, inputs, input);
106537 + VEC_safe_push(tree, gc, outputs, output);
106538 +#else
106539 + vec_safe_push(inputs, input);
106540 + vec_safe_push(outputs, output);
106541 +#endif
106542 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
106543 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
106544 + gimple_asm_set_volatile(asm_or_stmt, true);
106545 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
106546 + update_stmt(asm_or_stmt);
106547 +
106548 + // replace call stmt fn with the new fptr
106549 + gimple_call_set_fn(call_stmt, new_fptr);
106550 + update_stmt(call_stmt);
106551 +}
106552 +
106553 +/*
106554 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
106555 + */
106556 +static unsigned int execute_kernexec_fptr(void)
106557 +{
106558 + basic_block bb;
106559 +
106560 + // 1. loop through BBs and GIMPLE statements
106561 + FOR_EACH_BB_FN(bb, cfun) {
106562 + gimple_stmt_iterator gsi;
106563 +
106564 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106565 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
106566 + tree fn;
106567 + gimple call_stmt;
106568 +
106569 + // is it a call ...
106570 + call_stmt = gsi_stmt(gsi);
106571 + if (!is_gimple_call(call_stmt))
106572 + continue;
106573 + fn = gimple_call_fn(call_stmt);
106574 + if (TREE_CODE(fn) == ADDR_EXPR)
106575 + continue;
106576 + if (TREE_CODE(fn) != SSA_NAME)
106577 + gcc_unreachable();
106578 +
106579 + // ... through a function pointer
106580 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
106581 + fn = SSA_NAME_VAR(fn);
106582 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
106583 + debug_tree(fn);
106584 + gcc_unreachable();
106585 + }
106586 + }
106587 + fn = TREE_TYPE(fn);
106588 + if (TREE_CODE(fn) != POINTER_TYPE)
106589 + continue;
106590 + fn = TREE_TYPE(fn);
106591 + if (TREE_CODE(fn) != FUNCTION_TYPE)
106592 + continue;
106593 +
106594 + kernexec_instrument_fptr(&gsi);
106595 +
106596 +//debug_tree(gimple_call_fn(call_stmt));
106597 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
106598 + }
106599 + }
106600 +
106601 + return 0;
106602 +}
106603 +
106604 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
106605 +static void kernexec_instrument_retaddr_bts(rtx insn)
106606 +{
106607 + rtx btsq;
106608 + rtvec argvec, constraintvec, labelvec;
106609 + int line;
106610 +
106611 + // create asm volatile("btsq $63,(%%rsp)":::)
106612 + argvec = rtvec_alloc(0);
106613 + constraintvec = rtvec_alloc(0);
106614 + labelvec = rtvec_alloc(0);
106615 + line = expand_location(RTL_LOCATION(insn)).line;
106616 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
106617 + MEM_VOLATILE_P(btsq) = 1;
106618 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
106619 + emit_insn_before(btsq, insn);
106620 +}
106621 +
106622 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
106623 +static void kernexec_instrument_retaddr_or(rtx insn)
106624 +{
106625 + rtx orq;
106626 + rtvec argvec, constraintvec, labelvec;
106627 + int line;
106628 +
106629 + // create asm volatile("orq %%r12,(%%rsp)":::)
106630 + argvec = rtvec_alloc(0);
106631 + constraintvec = rtvec_alloc(0);
106632 + labelvec = rtvec_alloc(0);
106633 + line = expand_location(RTL_LOCATION(insn)).line;
106634 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
106635 + MEM_VOLATILE_P(orq) = 1;
106636 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
106637 + emit_insn_before(orq, insn);
106638 +}
106639 +
106640 +/*
106641 + * find all asm level function returns and forcibly set the highest bit of the return address
106642 + */
106643 +static unsigned int execute_kernexec_retaddr(void)
106644 +{
106645 + rtx insn;
106646 +
106647 +// if (stack_realign_drap)
106648 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
106649 +
106650 + // 1. find function returns
106651 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
106652 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
106653 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
106654 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
106655 + rtx body;
106656 +
106657 + // is it a retn
106658 + if (!JUMP_P(insn))
106659 + continue;
106660 + body = PATTERN(insn);
106661 + if (GET_CODE(body) == PARALLEL)
106662 + body = XVECEXP(body, 0, 0);
106663 + if (!ANY_RETURN_P(body))
106664 + continue;
106665 + kernexec_instrument_retaddr(insn);
106666 + }
106667 +
106668 +// print_simple_rtl(stderr, get_insns());
106669 +// print_rtl(stderr, get_insns());
106670 +
106671 + return 0;
106672 +}
106673 +
106674 +static bool kernexec_cmodel_check(void)
106675 +{
106676 + tree section;
106677 +
106678 + if (ix86_cmodel != CM_KERNEL)
106679 + return false;
106680 +
106681 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
106682 + if (!section || !TREE_VALUE(section))
106683 + return true;
106684 +
106685 + section = TREE_VALUE(TREE_VALUE(section));
106686 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
106687 + return true;
106688 +
106689 + return false;
106690 +}
106691 +
106692 +#if BUILDING_GCC_VERSION >= 4009
106693 +static const struct pass_data kernexec_reload_pass_data = {
106694 +#else
106695 +static struct gimple_opt_pass kernexec_reload_pass = {
106696 + .pass = {
106697 +#endif
106698 + .type = GIMPLE_PASS,
106699 + .name = "kernexec_reload",
106700 +#if BUILDING_GCC_VERSION >= 4008
106701 + .optinfo_flags = OPTGROUP_NONE,
106702 +#endif
106703 +#if BUILDING_GCC_VERSION >= 4009
106704 + .has_gate = true,
106705 + .has_execute = true,
106706 +#else
106707 + .gate = kernexec_cmodel_check,
106708 + .execute = execute_kernexec_reload,
106709 + .sub = NULL,
106710 + .next = NULL,
106711 + .static_pass_number = 0,
106712 +#endif
106713 + .tv_id = TV_NONE,
106714 + .properties_required = 0,
106715 + .properties_provided = 0,
106716 + .properties_destroyed = 0,
106717 + .todo_flags_start = 0,
106718 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
106719 +#if BUILDING_GCC_VERSION < 4009
106720 + }
106721 +#endif
106722 +};
106723 +
106724 +#if BUILDING_GCC_VERSION >= 4009
106725 +static const struct pass_data kernexec_fptr_pass_data = {
106726 +#else
106727 +static struct gimple_opt_pass kernexec_fptr_pass = {
106728 + .pass = {
106729 +#endif
106730 + .type = GIMPLE_PASS,
106731 + .name = "kernexec_fptr",
106732 +#if BUILDING_GCC_VERSION >= 4008
106733 + .optinfo_flags = OPTGROUP_NONE,
106734 +#endif
106735 +#if BUILDING_GCC_VERSION >= 4009
106736 + .has_gate = true,
106737 + .has_execute = true,
106738 +#else
106739 + .gate = kernexec_cmodel_check,
106740 + .execute = execute_kernexec_fptr,
106741 + .sub = NULL,
106742 + .next = NULL,
106743 + .static_pass_number = 0,
106744 +#endif
106745 + .tv_id = TV_NONE,
106746 + .properties_required = 0,
106747 + .properties_provided = 0,
106748 + .properties_destroyed = 0,
106749 + .todo_flags_start = 0,
106750 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
106751 +#if BUILDING_GCC_VERSION < 4009
106752 + }
106753 +#endif
106754 +};
106755 +
106756 +#if BUILDING_GCC_VERSION >= 4009
106757 +static const struct pass_data kernexec_retaddr_pass_data = {
106758 +#else
106759 +static struct rtl_opt_pass kernexec_retaddr_pass = {
106760 + .pass = {
106761 +#endif
106762 + .type = RTL_PASS,
106763 + .name = "kernexec_retaddr",
106764 +#if BUILDING_GCC_VERSION >= 4008
106765 + .optinfo_flags = OPTGROUP_NONE,
106766 +#endif
106767 +#if BUILDING_GCC_VERSION >= 4009
106768 + .has_gate = true,
106769 + .has_execute = true,
106770 +#else
106771 + .gate = kernexec_cmodel_check,
106772 + .execute = execute_kernexec_retaddr,
106773 + .sub = NULL,
106774 + .next = NULL,
106775 + .static_pass_number = 0,
106776 +#endif
106777 + .tv_id = TV_NONE,
106778 + .properties_required = 0,
106779 + .properties_provided = 0,
106780 + .properties_destroyed = 0,
106781 + .todo_flags_start = 0,
106782 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
106783 +#if BUILDING_GCC_VERSION < 4009
106784 + }
106785 +#endif
106786 +};
106787 +
106788 +#if BUILDING_GCC_VERSION >= 4009
106789 +namespace {
106790 +class kernexec_reload_pass : public gimple_opt_pass {
106791 +public:
106792 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
106793 + bool gate() { return kernexec_cmodel_check(); }
106794 + unsigned int execute() { return execute_kernexec_reload(); }
106795 +};
106796 +
106797 +class kernexec_fptr_pass : public gimple_opt_pass {
106798 +public:
106799 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
106800 + bool gate() { return kernexec_cmodel_check(); }
106801 + unsigned int execute() { return execute_kernexec_fptr(); }
106802 +};
106803 +
106804 +class kernexec_retaddr_pass : public rtl_opt_pass {
106805 +public:
106806 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
106807 + bool gate() { return kernexec_cmodel_check(); }
106808 + unsigned int execute() { return execute_kernexec_retaddr(); }
106809 +};
106810 +}
106811 +#endif
106812 +
106813 +static struct opt_pass *make_kernexec_reload_pass(void)
106814 +{
106815 +#if BUILDING_GCC_VERSION >= 4009
106816 + return new kernexec_reload_pass();
106817 +#else
106818 + return &kernexec_reload_pass.pass;
106819 +#endif
106820 +}
106821 +
106822 +static struct opt_pass *make_kernexec_fptr_pass(void)
106823 +{
106824 +#if BUILDING_GCC_VERSION >= 4009
106825 + return new kernexec_fptr_pass();
106826 +#else
106827 + return &kernexec_fptr_pass.pass;
106828 +#endif
106829 +}
106830 +
106831 +static struct opt_pass *make_kernexec_retaddr_pass(void)
106832 +{
106833 +#if BUILDING_GCC_VERSION >= 4009
106834 + return new kernexec_retaddr_pass();
106835 +#else
106836 + return &kernexec_retaddr_pass.pass;
106837 +#endif
106838 +}
106839 +
106840 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106841 +{
106842 + const char * const plugin_name = plugin_info->base_name;
106843 + const int argc = plugin_info->argc;
106844 + const struct plugin_argument * const argv = plugin_info->argv;
106845 + int i;
106846 + struct register_pass_info kernexec_reload_pass_info;
106847 + struct register_pass_info kernexec_fptr_pass_info;
106848 + struct register_pass_info kernexec_retaddr_pass_info;
106849 +
106850 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
106851 + kernexec_reload_pass_info.reference_pass_name = "ssa";
106852 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
106853 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
106854 +
106855 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
106856 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
106857 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
106858 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
106859 +
106860 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
106861 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
106862 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
106863 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
106864 +
106865 + if (!plugin_default_version_check(version, &gcc_version)) {
106866 + error(G_("incompatible gcc/plugin versions"));
106867 + return 1;
106868 + }
106869 +
106870 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
106871 +
106872 + if (TARGET_64BIT == 0)
106873 + return 0;
106874 +
106875 + for (i = 0; i < argc; ++i) {
106876 + if (!strcmp(argv[i].key, "method")) {
106877 + if (!argv[i].value) {
106878 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106879 + continue;
106880 + }
106881 + if (!strcmp(argv[i].value, "bts")) {
106882 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
106883 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
106884 + } else if (!strcmp(argv[i].value, "or")) {
106885 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
106886 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
106887 + fix_register("r12", 1, 1);
106888 + } else
106889 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
106890 + continue;
106891 + }
106892 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106893 + }
106894 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
106895 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
106896 +
106897 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
106898 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
106899 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
106900 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
106901 +
106902 + return 0;
106903 +}
106904 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
106905 new file mode 100644
106906 index 0000000..1a98bed
106907 --- /dev/null
106908 +++ b/tools/gcc/latent_entropy_plugin.c
106909 @@ -0,0 +1,451 @@
106910 +/*
106911 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
106912 + * Licensed under the GPL v2
106913 + *
106914 + * Note: the choice of the license means that the compilation process is
106915 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106916 + * but for the kernel it doesn't matter since it doesn't link against
106917 + * any of the gcc libraries
106918 + *
106919 + * gcc plugin to help generate a little bit of entropy from program state,
106920 + * used throughout the uptime of the kernel
106921 + *
106922 + * TODO:
106923 + * - add ipa pass to identify not explicitly marked candidate functions
106924 + * - mix in more program state (function arguments/return values, loop variables, etc)
106925 + * - more instrumentation control via attribute parameters
106926 + *
106927 + * BUGS:
106928 + * - LTO needs -flto-partition=none for now
106929 + */
106930 +
106931 +#include "gcc-common.h"
106932 +
106933 +int plugin_is_GPL_compatible;
106934 +
106935 +static tree latent_entropy_decl;
106936 +
106937 +static struct plugin_info latent_entropy_plugin_info = {
106938 + .version = "201402240545",
106939 + .help = NULL
106940 +};
106941 +
106942 +static unsigned HOST_WIDE_INT seed;
106943 +static unsigned HOST_WIDE_INT get_random_const(void)
106944 +{
106945 + unsigned int i;
106946 + unsigned HOST_WIDE_INT ret = 0;
106947 +
106948 + for (i = 0; i < 8 * sizeof ret; i++) {
106949 + ret = (ret << 1) | (seed & 1);
106950 + seed >>= 1;
106951 + if (ret & 1)
106952 + seed ^= 0xD800000000000000ULL;
106953 + }
106954 +
106955 + return ret;
106956 +}
106957 +
106958 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106959 +{
106960 + tree type;
106961 + unsigned long long mask;
106962 +#if BUILDING_GCC_VERSION <= 4007
106963 + VEC(constructor_elt, gc) *vals;
106964 +#else
106965 + vec<constructor_elt, va_gc> *vals;
106966 +#endif
106967 +
106968 + switch (TREE_CODE(*node)) {
106969 + default:
106970 + *no_add_attrs = true;
106971 + error("%qE attribute only applies to functions and variables", name);
106972 + break;
106973 +
106974 + case VAR_DECL:
106975 + if (DECL_INITIAL(*node)) {
106976 + *no_add_attrs = true;
106977 + error("variable %qD with %qE attribute must not be initialized", *node, name);
106978 + break;
106979 + }
106980 +
106981 + if (!TREE_STATIC(*node)) {
106982 + *no_add_attrs = true;
106983 + error("variable %qD with %qE attribute must not be local", *node, name);
106984 + break;
106985 + }
106986 +
106987 + type = TREE_TYPE(*node);
106988 + switch (TREE_CODE(type)) {
106989 + default:
106990 + *no_add_attrs = true;
106991 + 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);
106992 + break;
106993 +
106994 + case RECORD_TYPE: {
106995 + tree field;
106996 + unsigned int nelt = 0;
106997 +
106998 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
106999 + tree fieldtype;
107000 +
107001 + fieldtype = TREE_TYPE(field);
107002 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
107003 + *no_add_attrs = true;
107004 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
107005 + break;
107006 + }
107007 + }
107008 +
107009 + if (field)
107010 + break;
107011 +
107012 +#if BUILDING_GCC_VERSION <= 4007
107013 + vals = VEC_alloc(constructor_elt, gc, nelt);
107014 +#else
107015 + vec_alloc(vals, nelt);
107016 +#endif
107017 +
107018 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107019 + tree fieldtype;
107020 +
107021 + fieldtype = TREE_TYPE(field);
107022 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
107023 + mask = 2 * (mask - 1) + 1;
107024 +
107025 + if (TYPE_UNSIGNED(fieldtype))
107026 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
107027 + else
107028 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
107029 + }
107030 +
107031 + DECL_INITIAL(*node) = build_constructor(type, vals);
107032 +//debug_tree(DECL_INITIAL(*node));
107033 + break;
107034 + }
107035 +
107036 + case INTEGER_TYPE:
107037 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
107038 + mask = 2 * (mask - 1) + 1;
107039 +
107040 + if (TYPE_UNSIGNED(type))
107041 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
107042 + else
107043 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
107044 + break;
107045 +
107046 + case ARRAY_TYPE: {
107047 + tree elt_type, array_size, elt_size;
107048 + unsigned int i, nelt;
107049 +
107050 + elt_type = TREE_TYPE(type);
107051 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
107052 + array_size = TYPE_SIZE_UNIT(type);
107053 +
107054 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
107055 + *no_add_attrs = true;
107056 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
107057 + break;
107058 + }
107059 +
107060 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
107061 +#if BUILDING_GCC_VERSION <= 4007
107062 + vals = VEC_alloc(constructor_elt, gc, nelt);
107063 +#else
107064 + vec_alloc(vals, nelt);
107065 +#endif
107066 +
107067 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
107068 + mask = 2 * (mask - 1) + 1;
107069 +
107070 + for (i = 0; i < nelt; i++)
107071 + if (TYPE_UNSIGNED(elt_type))
107072 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
107073 + else
107074 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
107075 +
107076 + DECL_INITIAL(*node) = build_constructor(type, vals);
107077 +//debug_tree(DECL_INITIAL(*node));
107078 + break;
107079 + }
107080 + }
107081 + break;
107082 +
107083 + case FUNCTION_DECL:
107084 + break;
107085 + }
107086 +
107087 + return NULL_TREE;
107088 +}
107089 +
107090 +static struct attribute_spec latent_entropy_attr = {
107091 + .name = "latent_entropy",
107092 + .min_length = 0,
107093 + .max_length = 0,
107094 + .decl_required = true,
107095 + .type_required = false,
107096 + .function_type_required = false,
107097 + .handler = handle_latent_entropy_attribute,
107098 +#if BUILDING_GCC_VERSION >= 4007
107099 + .affects_type_identity = false
107100 +#endif
107101 +};
107102 +
107103 +static void register_attributes(void *event_data, void *data)
107104 +{
107105 + register_attribute(&latent_entropy_attr);
107106 +}
107107 +
107108 +static bool gate_latent_entropy(void)
107109 +{
107110 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
107111 +}
107112 +
107113 +static enum tree_code get_op(tree *rhs)
107114 +{
107115 + static enum tree_code op;
107116 + unsigned HOST_WIDE_INT random_const;
107117 +
107118 + random_const = get_random_const();
107119 +
107120 + switch (op) {
107121 + case BIT_XOR_EXPR:
107122 + op = PLUS_EXPR;
107123 + break;
107124 +
107125 + case PLUS_EXPR:
107126 + if (rhs) {
107127 + op = LROTATE_EXPR;
107128 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
107129 + break;
107130 + }
107131 +
107132 + case LROTATE_EXPR:
107133 + default:
107134 + op = BIT_XOR_EXPR;
107135 + break;
107136 + }
107137 + if (rhs)
107138 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
107139 + return op;
107140 +}
107141 +
107142 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
107143 +{
107144 + gimple_stmt_iterator gsi;
107145 + gimple assign;
107146 + tree addxorrol, rhs;
107147 + enum tree_code op;
107148 +
107149 + op = get_op(&rhs);
107150 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
107151 + assign = gimple_build_assign(local_entropy, addxorrol);
107152 + gsi = gsi_after_labels(bb);
107153 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
107154 + update_stmt(assign);
107155 +//debug_bb(bb);
107156 +}
107157 +
107158 +static void perturb_latent_entropy(basic_block bb, tree rhs)
107159 +{
107160 + gimple_stmt_iterator gsi;
107161 + gimple assign;
107162 + tree addxorrol, temp;
107163 +
107164 + // 1. create temporary copy of latent_entropy
107165 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
107166 + add_referenced_var(temp);
107167 +
107168 + // 2. read...
107169 + temp = make_ssa_name(temp, NULL);
107170 + assign = gimple_build_assign(temp, latent_entropy_decl);
107171 + SSA_NAME_DEF_STMT(temp) = assign;
107172 + add_referenced_var(latent_entropy_decl);
107173 + gsi = gsi_after_labels(bb);
107174 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107175 + update_stmt(assign);
107176 +
107177 + // 3. ...modify...
107178 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
107179 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
107180 + assign = gimple_build_assign(temp, addxorrol);
107181 + SSA_NAME_DEF_STMT(temp) = assign;
107182 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107183 + update_stmt(assign);
107184 +
107185 + // 4. ...write latent_entropy
107186 + assign = gimple_build_assign(latent_entropy_decl, temp);
107187 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107188 + update_stmt(assign);
107189 +}
107190 +
107191 +static unsigned int execute_latent_entropy(void)
107192 +{
107193 + basic_block bb;
107194 + gimple assign;
107195 + gimple_stmt_iterator gsi;
107196 + tree local_entropy;
107197 +
107198 + if (!latent_entropy_decl) {
107199 + struct varpool_node *node;
107200 +
107201 + FOR_EACH_VARIABLE(node) {
107202 + tree var = NODE_DECL(node);
107203 +
107204 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
107205 + continue;
107206 + latent_entropy_decl = var;
107207 +// debug_tree(var);
107208 + break;
107209 + }
107210 + if (!latent_entropy_decl) {
107211 +// debug_tree(current_function_decl);
107212 + return 0;
107213 + }
107214 + }
107215 +
107216 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
107217 +
107218 + // 1. create local entropy variable
107219 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
107220 + add_referenced_var(local_entropy);
107221 + mark_sym_for_renaming(local_entropy);
107222 +
107223 + // 2. initialize local entropy variable
107224 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
107225 + if (dom_info_available_p(CDI_DOMINATORS))
107226 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
107227 + gsi = gsi_start_bb(bb);
107228 +
107229 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
107230 +// gimple_set_location(assign, loc);
107231 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107232 + update_stmt(assign);
107233 +//debug_bb(bb);
107234 + bb = bb->next_bb;
107235 +
107236 + // 3. instrument each BB with an operation on the local entropy variable
107237 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
107238 + perturb_local_entropy(bb, local_entropy);
107239 +//debug_bb(bb);
107240 + bb = bb->next_bb;
107241 + };
107242 +
107243 + // 4. mix local entropy into the global entropy variable
107244 + perturb_latent_entropy(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb, local_entropy);
107245 +//debug_bb(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb);
107246 + return 0;
107247 +}
107248 +
107249 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
107250 +{
107251 + tree latent_entropy_type;
107252 +
107253 + seed = get_random_seed(false);
107254 +
107255 + if (in_lto_p)
107256 + return;
107257 +
107258 + // extern volatile u64 latent_entropy
107259 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
107260 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
107261 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
107262 +
107263 + TREE_STATIC(latent_entropy_decl) = 1;
107264 + TREE_PUBLIC(latent_entropy_decl) = 1;
107265 + TREE_USED(latent_entropy_decl) = 1;
107266 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
107267 + DECL_EXTERNAL(latent_entropy_decl) = 1;
107268 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
107269 + lang_hooks.decls.pushdecl(latent_entropy_decl);
107270 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
107271 +// varpool_finalize_decl(latent_entropy_decl);
107272 +// varpool_mark_needed_node(latent_entropy_decl);
107273 +}
107274 +
107275 +#if BUILDING_GCC_VERSION >= 4009
107276 +static const struct pass_data latent_entropy_pass_data = {
107277 +#else
107278 +static struct gimple_opt_pass latent_entropy_pass = {
107279 + .pass = {
107280 +#endif
107281 + .type = GIMPLE_PASS,
107282 + .name = "latent_entropy",
107283 +#if BUILDING_GCC_VERSION >= 4008
107284 + .optinfo_flags = OPTGROUP_NONE,
107285 +#endif
107286 +#if BUILDING_GCC_VERSION >= 4009
107287 + .has_gate = true,
107288 + .has_execute = true,
107289 +#else
107290 + .gate = gate_latent_entropy,
107291 + .execute = execute_latent_entropy,
107292 + .sub = NULL,
107293 + .next = NULL,
107294 + .static_pass_number = 0,
107295 +#endif
107296 + .tv_id = TV_NONE,
107297 + .properties_required = PROP_gimple_leh | PROP_cfg,
107298 + .properties_provided = 0,
107299 + .properties_destroyed = 0,
107300 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
107301 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
107302 +#if BUILDING_GCC_VERSION < 4009
107303 + }
107304 +#endif
107305 +};
107306 +
107307 +#if BUILDING_GCC_VERSION >= 4009
107308 +namespace {
107309 +class latent_entropy_pass : public gimple_opt_pass {
107310 +public:
107311 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
107312 + bool gate() { return gate_latent_entropy(); }
107313 + unsigned int execute() { return execute_latent_entropy(); }
107314 +};
107315 +}
107316 +#endif
107317 +
107318 +static struct opt_pass *make_latent_entropy_pass(void)
107319 +{
107320 +#if BUILDING_GCC_VERSION >= 4009
107321 + return new latent_entropy_pass();
107322 +#else
107323 + return &latent_entropy_pass.pass;
107324 +#endif
107325 +}
107326 +
107327 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107328 +{
107329 + const char * const plugin_name = plugin_info->base_name;
107330 + struct register_pass_info latent_entropy_pass_info;
107331 +
107332 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
107333 + latent_entropy_pass_info.reference_pass_name = "optimized";
107334 + latent_entropy_pass_info.ref_pass_instance_number = 1;
107335 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
107336 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
107337 + {
107338 + .base = &latent_entropy_decl,
107339 + .nelt = 1,
107340 + .stride = sizeof(latent_entropy_decl),
107341 + .cb = &gt_ggc_mx_tree_node,
107342 + .pchw = &gt_pch_nx_tree_node
107343 + },
107344 + LAST_GGC_ROOT_TAB
107345 + };
107346 +
107347 + if (!plugin_default_version_check(version, &gcc_version)) {
107348 + error(G_("incompatible gcc/plugin versions"));
107349 + return 1;
107350 + }
107351 +
107352 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
107353 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
107354 + if (!in_lto_p)
107355 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
107356 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
107357 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107358 +
107359 + return 0;
107360 +}
107361 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
107362 new file mode 100644
107363 index 0000000..8dafb22
107364 --- /dev/null
107365 +++ b/tools/gcc/randomize_layout_plugin.c
107366 @@ -0,0 +1,910 @@
107367 +/*
107368 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
107369 + * and PaX Team <pageexec@freemail.hu>
107370 + * Licensed under the GPL v2
107371 + *
107372 + * Usage:
107373 + * $ # for 4.5/4.6/C based 4.7
107374 + * $ 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
107375 + * $ # for C++ based 4.7/4.8+
107376 + * $ 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
107377 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
107378 + */
107379 +
107380 +#include "gcc-common.h"
107381 +#include "randomize_layout_seed.h"
107382 +
107383 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
107384 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
107385 +#endif
107386 +
107387 +#define ORIG_TYPE_NAME(node) \
107388 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
107389 +
107390 +int plugin_is_GPL_compatible;
107391 +
107392 +static int performance_mode;
107393 +
107394 +static struct plugin_info randomize_layout_plugin_info = {
107395 + .version = "201402201816",
107396 + .help = "disable\t\t\tdo not activate plugin\n"
107397 + "performance-mode\tenable cacheline-aware layout randomization\n"
107398 +};
107399 +
107400 +/* from old Linux dcache.h */
107401 +static inline unsigned long
107402 +partial_name_hash(unsigned long c, unsigned long prevhash)
107403 +{
107404 + return (prevhash + (c << 4) + (c >> 4)) * 11;
107405 +}
107406 +static inline unsigned int
107407 +name_hash(const unsigned char *name)
107408 +{
107409 + unsigned long hash = 0;
107410 + unsigned int len = strlen((const char *)name);
107411 + while (len--)
107412 + hash = partial_name_hash(*name++, hash);
107413 + return (unsigned int)hash;
107414 +}
107415 +
107416 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107417 +{
107418 + tree type;
107419 +
107420 + *no_add_attrs = true;
107421 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107422 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107423 + return NULL_TREE;
107424 + }
107425 +
107426 + if (TREE_CODE(*node) == PARM_DECL) {
107427 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107428 + return NULL_TREE;
107429 + }
107430 +
107431 + if (TREE_CODE(*node) == VAR_DECL) {
107432 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107433 + return NULL_TREE;
107434 + }
107435 +
107436 + if (TYPE_P(*node)) {
107437 + type = *node;
107438 + } else {
107439 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107440 + type = TREE_TYPE(*node);
107441 + }
107442 +
107443 + if (TREE_CODE(type) != RECORD_TYPE) {
107444 + error("%qE attribute used on %qT applies to struct types only", name, type);
107445 + return NULL_TREE;
107446 + }
107447 +
107448 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107449 + error("%qE attribute is already applied to the type %qT", name, type);
107450 + return NULL_TREE;
107451 + }
107452 +
107453 + *no_add_attrs = false;
107454 +
107455 + return NULL_TREE;
107456 +}
107457 +
107458 +/* set on complete types that we don't need to inspect further at all */
107459 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107460 +{
107461 + *no_add_attrs = false;
107462 + return NULL_TREE;
107463 +}
107464 +
107465 +/*
107466 + * set on types that we've performed a shuffle on, to prevent re-shuffling
107467 + * this does not preclude us from inspecting its fields for potential shuffles
107468 + */
107469 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107470 +{
107471 + *no_add_attrs = false;
107472 + return NULL_TREE;
107473 +}
107474 +
107475 +/*
107476 + * 64bit variant of Bob Jenkins' public domain PRNG
107477 + * 256 bits of internal state
107478 + */
107479 +
107480 +typedef unsigned long long u64;
107481 +
107482 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
107483 +
107484 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
107485 +static u64 ranval(ranctx *x) {
107486 + u64 e = x->a - rot(x->b, 7);
107487 + x->a = x->b ^ rot(x->c, 13);
107488 + x->b = x->c + rot(x->d, 37);
107489 + x->c = x->d + e;
107490 + x->d = e + x->a;
107491 + return x->d;
107492 +}
107493 +
107494 +static void raninit(ranctx *x, u64 *seed) {
107495 + int i;
107496 +
107497 + x->a = seed[0];
107498 + x->b = seed[1];
107499 + x->c = seed[2];
107500 + x->d = seed[3];
107501 +
107502 + for (i=0; i < 30; ++i)
107503 + (void)ranval(x);
107504 +}
107505 +
107506 +static u64 shuffle_seed[4];
107507 +
107508 +struct partition_group {
107509 + tree tree_start;
107510 + unsigned long start;
107511 + unsigned long length;
107512 +};
107513 +
107514 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
107515 +{
107516 + unsigned long i;
107517 + unsigned long accum_size = 0;
107518 + unsigned long accum_length = 0;
107519 + unsigned long group_idx = 0;
107520 +
107521 + gcc_assert(length < INT_MAX);
107522 +
107523 + memset(size_groups, 0, sizeof(struct partition_group) * length);
107524 +
107525 + for (i = 0; i < length; i++) {
107526 + if (size_groups[group_idx].tree_start == NULL_TREE) {
107527 + size_groups[group_idx].tree_start = fields[i];
107528 + size_groups[group_idx].start = i;
107529 + accum_length = 0;
107530 + accum_size = 0;
107531 + }
107532 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
107533 + accum_length++;
107534 + if (accum_size >= 64) {
107535 + size_groups[group_idx].length = accum_length;
107536 + accum_length = 0;
107537 + group_idx++;
107538 + }
107539 + }
107540 +
107541 + if (size_groups[group_idx].tree_start != NULL_TREE &&
107542 + !size_groups[group_idx].length) {
107543 + size_groups[group_idx].length = accum_length;
107544 + group_idx++;
107545 + }
107546 +
107547 + *num_groups = group_idx;
107548 +}
107549 +
107550 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
107551 +{
107552 + unsigned long i, x;
107553 + struct partition_group size_group[length];
107554 + unsigned long num_groups = 0;
107555 + unsigned long randnum;
107556 +
107557 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
107558 + for (i = num_groups - 1; i > 0; i--) {
107559 + struct partition_group tmp;
107560 + randnum = ranval(prng_state) % (i + 1);
107561 + tmp = size_group[i];
107562 + size_group[i] = size_group[randnum];
107563 + size_group[randnum] = tmp;
107564 + }
107565 +
107566 + for (x = 0; x < num_groups; x++) {
107567 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
107568 + tree tmp;
107569 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
107570 + continue;
107571 + randnum = ranval(prng_state) % (i + 1);
107572 + // we could handle this case differently if desired
107573 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
107574 + continue;
107575 + tmp = newtree[i];
107576 + newtree[i] = newtree[randnum];
107577 + newtree[randnum] = tmp;
107578 + }
107579 + }
107580 +}
107581 +
107582 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
107583 +{
107584 + unsigned long i, randnum;
107585 +
107586 + for (i = length - 1; i > 0; i--) {
107587 + tree tmp;
107588 + randnum = ranval(prng_state) % (i + 1);
107589 + tmp = newtree[i];
107590 + newtree[i] = newtree[randnum];
107591 + newtree[randnum] = tmp;
107592 + }
107593 +}
107594 +
107595 +/* modern in-place Fisher-Yates shuffle */
107596 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
107597 +{
107598 + unsigned long i;
107599 + u64 seed[4];
107600 + ranctx prng_state;
107601 + const unsigned char *structname;
107602 +
107603 + if (length == 0)
107604 + return;
107605 +
107606 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
107607 +
107608 + structname = ORIG_TYPE_NAME(type);
107609 +
107610 +#ifdef __DEBUG_PLUGIN
107611 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
107612 +#ifdef __DEBUG_VERBOSE
107613 + debug_tree((tree)type);
107614 +#endif
107615 +#endif
107616 +
107617 + for (i = 0; i < 4; i++) {
107618 + seed[i] = shuffle_seed[i];
107619 + seed[i] ^= name_hash(structname);
107620 + }
107621 +
107622 + raninit(&prng_state, (u64 *)&seed);
107623 +
107624 + if (performance_mode)
107625 + performance_shuffle(newtree, length, &prng_state);
107626 + else
107627 + full_shuffle(newtree, length, &prng_state);
107628 +}
107629 +
107630 +static bool is_flexible_array(const_tree field)
107631 +{
107632 + const_tree fieldtype;
107633 + const_tree typesize;
107634 + const_tree elemtype;
107635 + const_tree elemsize;
107636 +
107637 + fieldtype = TREE_TYPE(field);
107638 + typesize = TYPE_SIZE(fieldtype);
107639 +
107640 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
107641 + return false;
107642 +
107643 + elemtype = TREE_TYPE(fieldtype);
107644 + elemsize = TYPE_SIZE(elemtype);
107645 +
107646 + /* size of type is represented in bits */
107647 +
107648 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
107649 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
107650 + return true;
107651 +
107652 + if (typesize != NULL_TREE &&
107653 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
107654 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
107655 + return true;
107656 +
107657 + return false;
107658 +}
107659 +
107660 +static int relayout_struct(tree type)
107661 +{
107662 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
107663 + unsigned long shuffle_length = num_fields;
107664 + tree field;
107665 + tree newtree[num_fields];
107666 + unsigned long i;
107667 + tree list;
107668 + tree variant;
107669 + expanded_location xloc;
107670 +
107671 + if (TYPE_FIELDS(type) == NULL_TREE)
107672 + return 0;
107673 +
107674 + if (num_fields < 2)
107675 + return 0;
107676 +
107677 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
107678 +
107679 + gcc_assert(num_fields < INT_MAX);
107680 +
107681 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
107682 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
107683 + return 0;
107684 +
107685 + /* throw out any structs in uapi */
107686 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
107687 +
107688 + if (strstr(xloc.file, "/uapi/"))
107689 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
107690 +
107691 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
107692 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
107693 + newtree[i] = field;
107694 + }
107695 +
107696 + /*
107697 + * enforce that we don't randomize the layout of the last
107698 + * element of a struct if it's a 0 or 1-length array
107699 + * or a proper flexible array
107700 + */
107701 + if (is_flexible_array(newtree[num_fields - 1]))
107702 + shuffle_length--;
107703 +
107704 + shuffle(type, (tree *)newtree, shuffle_length);
107705 +
107706 + /*
107707 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
107708 + * as gcc provides no other way to detect such code
107709 + */
107710 + list = make_node(FIELD_DECL);
107711 + TREE_CHAIN(list) = newtree[0];
107712 + TREE_TYPE(list) = void_type_node;
107713 + DECL_SIZE(list) = bitsize_zero_node;
107714 + DECL_NONADDRESSABLE_P(list) = 1;
107715 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
107716 + DECL_SIZE_UNIT(list) = size_zero_node;
107717 + DECL_FIELD_OFFSET(list) = size_zero_node;
107718 + // to satisfy the constify plugin
107719 + TREE_READONLY(list) = 1;
107720 +
107721 + for (i = 0; i < num_fields - 1; i++)
107722 + TREE_CHAIN(newtree[i]) = newtree[i+1];
107723 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
107724 +
107725 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
107726 + TYPE_FIELDS(variant) = list;
107727 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
107728 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
107729 + // force a re-layout
107730 + TYPE_SIZE(variant) = NULL_TREE;
107731 + layout_type(variant);
107732 + }
107733 +
107734 + return 1;
107735 +}
107736 +
107737 +/* from constify plugin */
107738 +static const_tree get_field_type(const_tree field)
107739 +{
107740 + return strip_array_types(TREE_TYPE(field));
107741 +}
107742 +
107743 +/* from constify plugin */
107744 +static bool is_fptr(const_tree fieldtype)
107745 +{
107746 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
107747 + return false;
107748 +
107749 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
107750 +}
107751 +
107752 +/* derived from constify plugin */
107753 +static int is_pure_ops_struct(const_tree node)
107754 +{
107755 + const_tree field;
107756 +
107757 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107758 +
107759 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
107760 + const_tree fieldtype = get_field_type(field);
107761 + enum tree_code code = TREE_CODE(fieldtype);
107762 +
107763 + if (node == fieldtype)
107764 + continue;
107765 +
107766 + if (!is_fptr(fieldtype))
107767 + return 0;
107768 +
107769 + if (code != RECORD_TYPE && code != UNION_TYPE)
107770 + continue;
107771 +
107772 + if (!is_pure_ops_struct(fieldtype))
107773 + return 0;
107774 + }
107775 +
107776 + return 1;
107777 +}
107778 +
107779 +static void randomize_type(tree type)
107780 +{
107781 + tree variant;
107782 +
107783 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
107784 +
107785 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
107786 + return;
107787 +
107788 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
107789 + relayout_struct(type);
107790 +
107791 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
107792 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107793 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
107794 + }
107795 +#ifdef __DEBUG_PLUGIN
107796 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
107797 +#ifdef __DEBUG_VERBOSE
107798 + debug_tree(type);
107799 +#endif
107800 +#endif
107801 +}
107802 +
107803 +static void randomize_layout_finish_decl(void *event_data, void *data)
107804 +{
107805 + tree decl = (tree)event_data;
107806 + tree type;
107807 +
107808 + if (decl == NULL_TREE || decl == error_mark_node)
107809 + return;
107810 +
107811 + type = TREE_TYPE(decl);
107812 +
107813 + if (TREE_CODE(decl) != VAR_DECL)
107814 + return;
107815 +
107816 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
107817 + return;
107818 +
107819 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
107820 + return;
107821 +
107822 + relayout_decl(decl);
107823 +}
107824 +
107825 +static void finish_type(void *event_data, void *data)
107826 +{
107827 + tree type = (tree)event_data;
107828 +
107829 + if (type == NULL_TREE || type == error_mark_node)
107830 + return;
107831 +
107832 + if (TREE_CODE(type) != RECORD_TYPE)
107833 + return;
107834 +
107835 + if (TYPE_FIELDS(type) == NULL_TREE)
107836 + return;
107837 +
107838 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
107839 + return;
107840 +
107841 +#ifdef __DEBUG_PLUGIN
107842 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
107843 +#endif
107844 +#ifdef __DEBUG_VERBOSE
107845 + debug_tree(type);
107846 +#endif
107847 + randomize_type(type);
107848 +
107849 + return;
107850 +}
107851 +
107852 +static struct attribute_spec randomize_layout_attr = {
107853 + .name = "randomize_layout",
107854 + // related to args
107855 + .min_length = 0,
107856 + .max_length = 0,
107857 + .decl_required = false,
107858 + // need type declaration
107859 + .type_required = true,
107860 + .function_type_required = false,
107861 + .handler = handle_randomize_layout_attr,
107862 +#if BUILDING_GCC_VERSION >= 4007
107863 + .affects_type_identity = true
107864 +#endif
107865 +};
107866 +
107867 +static struct attribute_spec no_randomize_layout_attr = {
107868 + .name = "no_randomize_layout",
107869 + // related to args
107870 + .min_length = 0,
107871 + .max_length = 0,
107872 + .decl_required = false,
107873 + // need type declaration
107874 + .type_required = true,
107875 + .function_type_required = false,
107876 + .handler = handle_randomize_layout_attr,
107877 +#if BUILDING_GCC_VERSION >= 4007
107878 + .affects_type_identity = true
107879 +#endif
107880 +};
107881 +
107882 +static struct attribute_spec randomize_considered_attr = {
107883 + .name = "randomize_considered",
107884 + // related to args
107885 + .min_length = 0,
107886 + .max_length = 0,
107887 + .decl_required = false,
107888 + // need type declaration
107889 + .type_required = true,
107890 + .function_type_required = false,
107891 + .handler = handle_randomize_considered_attr,
107892 +#if BUILDING_GCC_VERSION >= 4007
107893 + .affects_type_identity = false
107894 +#endif
107895 +};
107896 +
107897 +static struct attribute_spec randomize_performed_attr = {
107898 + .name = "randomize_performed",
107899 + // related to args
107900 + .min_length = 0,
107901 + .max_length = 0,
107902 + .decl_required = false,
107903 + // need type declaration
107904 + .type_required = true,
107905 + .function_type_required = false,
107906 + .handler = handle_randomize_performed_attr,
107907 +#if BUILDING_GCC_VERSION >= 4007
107908 + .affects_type_identity = false
107909 +#endif
107910 +};
107911 +
107912 +static void register_attributes(void *event_data, void *data)
107913 +{
107914 + register_attribute(&randomize_layout_attr);
107915 + register_attribute(&no_randomize_layout_attr);
107916 + register_attribute(&randomize_considered_attr);
107917 + register_attribute(&randomize_performed_attr);
107918 +}
107919 +
107920 +static void check_bad_casts_in_constructor(tree var, tree init)
107921 +{
107922 + unsigned HOST_WIDE_INT idx;
107923 + tree field, val;
107924 + tree field_type, val_type;
107925 +
107926 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
107927 + if (TREE_CODE(val) == CONSTRUCTOR) {
107928 + check_bad_casts_in_constructor(var, val);
107929 + continue;
107930 + }
107931 +
107932 + /* pipacs' plugin creates franken-arrays that differ from those produced by
107933 + normal code which all have valid 'field' trees. work around this */
107934 + if (field == NULL_TREE)
107935 + continue;
107936 + field_type = TREE_TYPE(field);
107937 + val_type = TREE_TYPE(val);
107938 +
107939 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
107940 + continue;
107941 +
107942 + if (field_type == val_type)
107943 + continue;
107944 +
107945 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
107946 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
107947 +
107948 + if (field_type == void_type_node)
107949 + continue;
107950 + if (field_type == val_type)
107951 + continue;
107952 + if (TREE_CODE(val_type) != RECORD_TYPE)
107953 + continue;
107954 +
107955 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
107956 + continue;
107957 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
107958 + }
107959 +}
107960 +
107961 +/* derived from the constify plugin */
107962 +static void check_global_variables(void *event_data, void *data)
107963 +{
107964 + struct varpool_node *node;
107965 + tree init;
107966 +
107967 + FOR_EACH_VARIABLE(node) {
107968 + tree var = NODE_DECL(node);
107969 + init = DECL_INITIAL(var);
107970 + if (init == NULL_TREE)
107971 + continue;
107972 +
107973 + if (TREE_CODE(init) != CONSTRUCTOR)
107974 + continue;
107975 +
107976 + check_bad_casts_in_constructor(var, init);
107977 + }
107978 +}
107979 +
107980 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
107981 +{
107982 + basic_block dom;
107983 + gimple dom_stmt;
107984 + gimple call_stmt;
107985 + const_tree dom_lhs;
107986 + const_tree poss_is_err_cond;
107987 + const_tree poss_is_err_func;
107988 + const_tree is_err_arg;
107989 +
107990 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
107991 + if (!dom)
107992 + return false;
107993 +
107994 + dom_stmt = last_stmt(dom);
107995 + if (!dom_stmt)
107996 + return false;
107997 +
107998 + if (gimple_code(dom_stmt) != GIMPLE_COND)
107999 + return false;
108000 +
108001 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
108002 + return false;
108003 +
108004 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
108005 + return false;
108006 +
108007 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
108008 +
108009 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
108010 + return false;
108011 +
108012 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
108013 +
108014 + if (gimple_code(call_stmt) != GIMPLE_CALL)
108015 + return false;
108016 +
108017 + dom_lhs = gimple_get_lhs(call_stmt);
108018 + poss_is_err_func = gimple_call_fndecl(call_stmt);
108019 + if (!poss_is_err_func)
108020 + return false;
108021 + if (dom_lhs != poss_is_err_cond)
108022 + return false;
108023 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
108024 + return false;
108025 +
108026 + is_err_arg = gimple_call_arg(call_stmt, 0);
108027 + if (!is_err_arg)
108028 + return false;
108029 +
108030 + if (is_err_arg != rhs)
108031 + return false;
108032 +
108033 + return true;
108034 +}
108035 +
108036 +static void handle_local_var_initializers(void)
108037 +{
108038 + tree var;
108039 + unsigned int i;
108040 +
108041 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
108042 + tree init = DECL_INITIAL(var);
108043 + if (!init)
108044 + continue;
108045 + if (TREE_CODE(init) != CONSTRUCTOR)
108046 + continue;
108047 + check_bad_casts_in_constructor(var, init);
108048 + }
108049 +}
108050 +
108051 +/*
108052 + * iterate over all statements to find "bad" casts:
108053 + * those where the address of the start of a structure is cast
108054 + * to a pointer of a structure of a different type, or a
108055 + * structure pointer type is cast to a different structure pointer type
108056 + */
108057 +static unsigned int find_bad_casts(void)
108058 +{
108059 + basic_block bb;
108060 +
108061 + handle_local_var_initializers();
108062 +
108063 + FOR_ALL_BB_FN(bb, cfun) {
108064 + gimple_stmt_iterator gsi;
108065 +
108066 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108067 + gimple stmt;
108068 + const_tree lhs;
108069 + const_tree lhs_type;
108070 + const_tree rhs1;
108071 + const_tree rhs_type;
108072 + const_tree ptr_lhs_type;
108073 + const_tree ptr_rhs_type;
108074 + const_tree op0;
108075 + const_tree op0_type;
108076 + enum tree_code rhs_code;
108077 +
108078 + stmt = gsi_stmt(gsi);
108079 +
108080 +#ifdef __DEBUG_PLUGIN
108081 +#ifdef __DEBUG_VERBOSE
108082 + debug_gimple_stmt(stmt);
108083 + debug_tree(gimple_get_lhs(stmt));
108084 +#endif
108085 +#endif
108086 +
108087 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
108088 + continue;
108089 +
108090 +#ifdef __DEBUG_PLUGIN
108091 +#ifdef __DEBUG_VERBOSE
108092 + debug_tree(gimple_assign_rhs1(stmt));
108093 +#endif
108094 +#endif
108095 +
108096 + rhs_code = gimple_assign_rhs_code(stmt);
108097 +
108098 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
108099 + continue;
108100 +
108101 + lhs = gimple_get_lhs(stmt);
108102 + lhs_type = TREE_TYPE(lhs);
108103 + rhs1 = gimple_assign_rhs1(stmt);
108104 + rhs_type = TREE_TYPE(rhs1);
108105 +
108106 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
108107 + TREE_CODE(lhs_type) != POINTER_TYPE)
108108 + continue;
108109 +
108110 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
108111 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
108112 +
108113 + if (ptr_rhs_type == void_type_node)
108114 + continue;
108115 +
108116 + if (ptr_lhs_type == void_type_node)
108117 + continue;
108118 +
108119 + if (dominated_by_is_err(rhs1, bb))
108120 + continue;
108121 +
108122 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
108123 +#ifndef __DEBUG_PLUGIN
108124 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
108125 +#endif
108126 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108127 + continue;
108128 + }
108129 +
108130 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
108131 + continue;
108132 +
108133 + if (rhs_code == ADDR_EXPR) {
108134 + op0 = TREE_OPERAND(rhs1, 0);
108135 +
108136 + if (op0 == NULL_TREE)
108137 + continue;
108138 +
108139 + if (TREE_CODE(op0) != VAR_DECL)
108140 + continue;
108141 +
108142 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
108143 + if (op0_type == ptr_lhs_type)
108144 + continue;
108145 +
108146 +#ifndef __DEBUG_PLUGIN
108147 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
108148 +#endif
108149 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
108150 + } else {
108151 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
108152 + /* skip bogus type casts introduced by container_of */
108153 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
108154 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
108155 + continue;
108156 +#ifndef __DEBUG_PLUGIN
108157 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
108158 +#endif
108159 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108160 + }
108161 +
108162 + }
108163 + }
108164 + return 0;
108165 +}
108166 +
108167 +#if BUILDING_GCC_VERSION >= 4009
108168 +static const struct pass_data randomize_layout_bad_cast_data = {
108169 +#else
108170 +static struct gimple_opt_pass randomize_layout_bad_cast = {
108171 + .pass = {
108172 +#endif
108173 + .type = GIMPLE_PASS,
108174 + .name = "randomize_layout_bad_cast",
108175 +#if BUILDING_GCC_VERSION >= 4008
108176 + .optinfo_flags = OPTGROUP_NONE,
108177 +#endif
108178 +#if BUILDING_GCC_VERSION >= 4009
108179 + .has_gate = false,
108180 + .has_execute = true,
108181 +#else
108182 + .gate = NULL,
108183 + .execute = find_bad_casts,
108184 + .sub = NULL,
108185 + .next = NULL,
108186 + .static_pass_number = 0,
108187 +#endif
108188 + .tv_id = TV_NONE,
108189 + .properties_required = PROP_cfg,
108190 + .properties_provided = 0,
108191 + .properties_destroyed = 0,
108192 + .todo_flags_start = 0,
108193 + .todo_flags_finish = TODO_dump_func
108194 +#if BUILDING_GCC_VERSION < 4009
108195 + }
108196 +#endif
108197 +};
108198 +
108199 +#if BUILDING_GCC_VERSION >= 4009
108200 +namespace {
108201 +class randomize_layout_bad_cast : public gimple_opt_pass {
108202 +public:
108203 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
108204 + unsigned int execute() { return find_bad_casts(); }
108205 +};
108206 +}
108207 +#endif
108208 +
108209 +static struct opt_pass *make_randomize_layout_bad_cast(void)
108210 +{
108211 +#if BUILDING_GCC_VERSION >= 4009
108212 + return new randomize_layout_bad_cast();
108213 +#else
108214 + return &randomize_layout_bad_cast.pass;
108215 +#endif
108216 +}
108217 +
108218 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108219 +{
108220 + int i;
108221 + const char * const plugin_name = plugin_info->base_name;
108222 + const int argc = plugin_info->argc;
108223 + const struct plugin_argument * const argv = plugin_info->argv;
108224 + bool enable = true;
108225 + int obtained_seed = 0;
108226 + struct register_pass_info randomize_layout_bad_cast_info;
108227 +
108228 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
108229 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
108230 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
108231 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
108232 +
108233 + if (!plugin_default_version_check(version, &gcc_version)) {
108234 + error(G_("incompatible gcc/plugin versions"));
108235 + return 1;
108236 + }
108237 +
108238 + if (strcmp(lang_hooks.name, "GNU C")) {
108239 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
108240 + enable = false;
108241 + }
108242 +
108243 + for (i = 0; i < argc; ++i) {
108244 + if (!strcmp(argv[i].key, "disable")) {
108245 + enable = false;
108246 + continue;
108247 + }
108248 + if (!strcmp(argv[i].key, "performance-mode")) {
108249 + performance_mode = 1;
108250 + continue;
108251 + }
108252 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108253 + }
108254 +
108255 + if (strlen(randstruct_seed) != 64) {
108256 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
108257 + return 1;
108258 + }
108259 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
108260 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
108261 + if (obtained_seed != 4) {
108262 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
108263 + return 1;
108264 + }
108265 +
108266 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
108267 + if (enable) {
108268 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
108269 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
108270 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
108271 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
108272 + }
108273 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108274 +
108275 + return 0;
108276 +}
108277 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
108278 new file mode 100644
108279 index 0000000..102f0d6
108280 --- /dev/null
108281 +++ b/tools/gcc/size_overflow_hash.data
108282 @@ -0,0 +1,5703 @@
108283 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
108284 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
108285 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
108286 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
108287 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
108288 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
108289 +padzero_55 padzero 1 55 &sel_read_policyvers_55
108290 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
108291 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
108292 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
108293 +load_msg_95 load_msg 2 95 NULL
108294 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
108295 +init_q_132 init_q 4 132 NULL
108296 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
108297 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
108298 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
108299 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
108300 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
108301 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
108302 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
108303 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
108304 +br_port_info_size_268 br_port_info_size 0 268 NULL
108305 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
108306 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
108307 +SYSC_connect_304 SYSC_connect 3 304 NULL
108308 +syslog_print_307 syslog_print 2 307 NULL
108309 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
108310 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
108311 +hw_device_state_409 hw_device_state 0 409 NULL
108312 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
108313 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
108314 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
108315 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
108316 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
108317 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
108318 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
108319 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
108320 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
108321 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
108322 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
108323 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
108324 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
108325 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
108326 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
108327 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
108328 +osl_pktget_590 osl_pktget 2 590 NULL
108329 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
108330 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
108331 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
108332 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
108333 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
108334 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
108335 +clone_split_bio_633 clone_split_bio 6 633 NULL
108336 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
108337 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
108338 +unlink_queued_645 unlink_queued 4 645 NULL
108339 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
108340 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
108341 +persistent_ram_vmap_709 persistent_ram_vmap 1-2 709 NULL
108342 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
108343 +dvb_video_write_754 dvb_video_write 3 754 NULL
108344 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
108345 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
108346 +if_writecmd_815 if_writecmd 2 815 NULL
108347 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
108348 +error_state_read_859 error_state_read 6 859 NULL
108349 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
108350 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
108351 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
108352 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
108353 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
108354 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
108355 +memcmp_990 memcmp 0 990 NULL
108356 +readreg_1017 readreg 0-1 1017 NULL
108357 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
108358 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
108359 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
108360 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
108361 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
108362 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
108363 +llc_mac_hdr_init_1094 llc_mac_hdr_init 0 1094 NULL
108364 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
108365 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
108366 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
108367 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
108368 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
108369 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
108370 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
108371 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
108372 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
108373 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
108374 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
108375 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
108376 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
108377 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
108378 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
108379 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
108380 +ffs_1322 ffs 0 1322 NULL
108381 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
108382 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
108383 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
108384 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
108385 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
108386 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
108387 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
108388 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
108389 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
108390 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
108391 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
108392 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
108393 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
108394 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
108395 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
108396 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
108397 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
108398 +fpregs_set_1497 fpregs_set 4 1497 NULL
108399 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
108400 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
108401 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
108402 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
108403 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
108404 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
108405 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
108406 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
108407 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
108408 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
108409 +rmap_add_1677 rmap_add 3 1677 NULL
108410 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
108411 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
108412 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
108413 +internal_create_group_1733 internal_create_group 0 1733 NULL
108414 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
108415 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
108416 +cosa_write_1774 cosa_write 3 1774 NULL
108417 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
108418 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
108419 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
108420 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
108421 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
108422 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
108423 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
108424 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
108425 +bdev_erase_1933 bdev_erase 3 1933 NULL
108426 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
108427 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
108428 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
108429 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
108430 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
108431 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
108432 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
108433 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
108434 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
108435 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
108436 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
108437 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
108438 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
108439 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
108440 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
108441 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
108442 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
108443 +audit_expand_2098 audit_expand 0 2098 NULL
108444 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
108445 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
108446 +enable_read_2117 enable_read 3 2117 NULL
108447 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
108448 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
108449 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
108450 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
108451 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
108452 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
108453 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
108454 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
108455 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
108456 +vhci_write_2224 vhci_write 3 2224 NULL
108457 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
108458 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
108459 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
108460 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
108461 +do_update_counters_2259 do_update_counters 4 2259 NULL
108462 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
108463 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
108464 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
108465 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
108466 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
108467 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
108468 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
108469 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
108470 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
108471 +sysfs_add_file_mode_ns_2362 sysfs_add_file_mode_ns 0 2362 NULL
108472 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
108473 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
108474 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
108475 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
108476 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
108477 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
108478 +raid1_size_2419 raid1_size 0-2 2419 NULL
108479 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
108480 +wiphy_new_2482 wiphy_new 2 2482 NULL
108481 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
108482 +hfsplus_user_setxattr_2485 hfsplus_user_setxattr 4 2485 NULL
108483 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
108484 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
108485 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
108486 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
108487 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
108488 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
108489 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
108490 +slot_bytes_2609 slot_bytes 0 2609 NULL
108491 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
108492 +switch_status_2629 switch_status 5 2629 NULL
108493 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
108494 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
108495 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
108496 +oti6858_write_2692 oti6858_write 4 2692 NULL
108497 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
108498 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
108499 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
108500 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
108501 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
108502 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
108503 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
108504 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
108505 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
108506 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
108507 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
108508 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
108509 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
108510 +nla_padlen_2883 nla_padlen 1 2883 NULL
108511 +cmm_write_2896 cmm_write 3 2896 NULL
108512 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
108513 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
108514 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
108515 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
108516 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
108517 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
108518 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
108519 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
108520 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
108521 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
108522 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
108523 +depth_write_3021 depth_write 3 3021 NULL
108524 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
108525 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
108526 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
108527 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
108528 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
108529 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
108530 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
108531 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
108532 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
108533 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
108534 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
108535 +clone_bio_3100 clone_bio 6 3100 NULL nohasharray
108536 +ttusb2_msg_3100 ttusb2_msg 4 3100 &clone_bio_3100
108537 +rb_alloc_3102 rb_alloc 1 3102 NULL
108538 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
108539 +print_time_3132 print_time 0 3132 NULL
108540 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
108541 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
108542 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
108543 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
108544 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
108545 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
108546 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
108547 +alloc_context_3194 alloc_context 1 3194 NULL
108548 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
108549 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
108550 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
108551 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
108552 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
108553 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
108554 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
108555 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
108556 +key_key_read_3241 key_key_read 3 3241 NULL
108557 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
108558 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
108559 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
108560 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
108561 +ocfs2_extend_xattr_bucket_3328 ocfs2_extend_xattr_bucket 4 3328 NULL
108562 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
108563 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
108564 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
108565 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
108566 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
108567 +scnprintf_3360 scnprintf 0-2 3360 NULL
108568 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
108569 +sr_read_3366 sr_read 3 3366 NULL
108570 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
108571 +send_stream_3397 send_stream 4 3397 NULL
108572 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
108573 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
108574 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
108575 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
108576 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
108577 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
108578 +s3fb_ddc_read_3451 s3fb_ddc_read 0 3451 NULL
108579 +softsynth_write_3455 softsynth_write 3 3455 NULL
108580 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL nohasharray
108581 +jffs2_acl_setxattr_3464 jffs2_acl_setxattr 4 3464 &snd_pcm_lib_readv_transfer_3464
108582 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
108583 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
108584 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
108585 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
108586 +SyS_readv_3539 SyS_readv 3 3539 NULL
108587 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
108588 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
108589 +evtchn_read_3569 evtchn_read 3 3569 NULL
108590 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
108591 +vc_resize_3585 vc_resize 3-2 3585 NULL
108592 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
108593 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
108594 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
108595 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
108596 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
108597 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
108598 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
108599 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
108600 +ci_ll_write_3740 ci_ll_write 4 3740 NULL nohasharray
108601 +ath6kl_mgmt_tx_3740 ath6kl_mgmt_tx 7 3740 &ci_ll_write_3740
108602 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
108603 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
108604 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
108605 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
108606 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
108607 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
108608 +get_fd_set_3866 get_fd_set 1 3866 NULL
108609 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
108610 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
108611 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
108612 +nvram_write_3894 nvram_write 3 3894 NULL
108613 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
108614 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
108615 +vcs_write_3910 vcs_write 3 3910 NULL
108616 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
108617 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
108618 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
108619 +ll_get_max_mdsize_3962 ll_get_max_mdsize 0 3962 NULL
108620 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
108621 +do_add_counters_3992 do_add_counters 3 3992 NULL
108622 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
108623 +userspace_status_4004 userspace_status 4 4004 NULL
108624 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
108625 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
108626 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
108627 +blk_end_request_4024 blk_end_request 3 4024 NULL
108628 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
108629 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
108630 +read_file_queues_4078 read_file_queues 3 4078 NULL
108631 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
108632 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
108633 +tm6000_read_4151 tm6000_read 3 4151 NULL
108634 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
108635 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
108636 +get_alua_req_4166 get_alua_req 3 4166 NULL
108637 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
108638 +read_file_bool_4180 read_file_bool 3 4180 NULL
108639 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
108640 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
108641 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
108642 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
108643 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
108644 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
108645 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
108646 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
108647 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 3-2-5 4303 NULL
108648 +count_strings_4315 count_strings 0 4315 NULL
108649 +__sysfs_add_one_4326 __sysfs_add_one 0 4326 NULL
108650 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
108651 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
108652 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
108653 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
108654 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
108655 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
108656 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
108657 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
108658 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
108659 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
108660 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
108661 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
108662 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
108663 +set_link_security_4502 set_link_security 4 4502 NULL
108664 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
108665 +tty_register_device_4544 tty_register_device 2 4544 NULL
108666 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
108667 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
108668 +bch_alloc_4593 bch_alloc 1 4593 NULL
108669 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
108670 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
108671 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
108672 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
108673 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
108674 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
108675 +kone_receive_4690 kone_receive 4 4690 NULL
108676 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
108677 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
108678 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
108679 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
108680 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
108681 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
108682 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
108683 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
108684 +create_subvol_4791 create_subvol 4 4791 NULL
108685 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
108686 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
108687 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
108688 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
108689 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
108690 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
108691 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
108692 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
108693 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
108694 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
108695 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
108696 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
108697 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
108698 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
108699 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
108700 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
108701 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
108702 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
108703 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
108704 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
108705 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
108706 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
108707 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
108708 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
108709 +sound_write_5102 sound_write 3 5102 NULL
108710 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
108711 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
108712 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
108713 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
108714 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
108715 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
108716 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
108717 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
108718 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
108719 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
108720 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
108721 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
108722 +cq_free_res_5355 cq_free_res 5 5355 NULL
108723 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
108724 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
108725 +__split_bvec_across_targets_5454 __split_bvec_across_targets 3 5454 NULL
108726 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
108727 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
108728 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
108729 +tty_write_5494 tty_write 3 5494 NULL
108730 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
108731 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
108732 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
108733 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
108734 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
108735 +le_readq_5557 le_readq 0 5557 NULL
108736 +inw_5558 inw 0 5558 NULL
108737 +bioset_create_5580 bioset_create 1 5580 NULL
108738 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
108739 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
108740 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
108741 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
108742 +get_arg_5694 get_arg 3 5694 NULL
108743 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
108744 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
108745 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
108746 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
108747 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
108748 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
108749 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
108750 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
108751 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
108752 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
108753 +setup_req_5848 setup_req 3-0 5848 NULL
108754 +ria_page_count_5849 ria_page_count 0 5849 NULL
108755 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
108756 +config_buf_5862 config_buf 0 5862 NULL
108757 +iwl_dbgfs_scan_ant_rxchain_write_5877 iwl_dbgfs_scan_ant_rxchain_write 3 5877 NULL
108758 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
108759 +port_show_regs_5904 port_show_regs 3 5904 NULL
108760 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
108761 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
108762 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
108763 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
108764 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
108765 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
108766 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
108767 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
108768 +SyS_semop_5980 SyS_semop 3 5980 NULL
108769 +alloc_msg_6072 alloc_msg 1 6072 NULL
108770 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
108771 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
108772 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
108773 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
108774 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
108775 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
108776 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
108777 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
108778 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
108779 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
108780 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
108781 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
108782 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
108783 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
108784 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
108785 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
108786 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
108787 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
108788 +serial_port_in_6291 serial_port_in 0 6291 NULL
108789 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
108790 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
108791 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
108792 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
108793 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
108794 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
108795 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
108796 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
108797 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
108798 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
108799 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
108800 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
108801 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
108802 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
108803 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
108804 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
108805 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
108806 +mei_read_6507 mei_read 3 6507 NULL
108807 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
108808 +wdm_read_6549 wdm_read 3 6549 NULL
108809 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
108810 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
108811 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
108812 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
108813 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
108814 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
108815 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
108816 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
108817 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
108818 +mpeg_read_6708 mpeg_read 3 6708 NULL
108819 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
108820 +video_proc_write_6724 video_proc_write 3 6724 NULL
108821 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
108822 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
108823 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
108824 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
108825 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
108826 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
108827 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
108828 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
108829 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
108830 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
108831 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
108832 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
108833 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
108834 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
108835 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
108836 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
108837 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
108838 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
108839 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
108840 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
108841 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
108842 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
108843 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
108844 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
108845 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
108846 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
108847 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
108848 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
108849 +request_key_async_6990 request_key_async 4 6990 NULL
108850 +tpl_write_6998 tpl_write 3 6998 NULL
108851 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
108852 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
108853 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
108854 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
108855 +wimax_msg_7030 wimax_msg 4 7030 NULL
108856 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
108857 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
108858 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
108859 +event_enable_read_7074 event_enable_read 3 7074 NULL
108860 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
108861 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
108862 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
108863 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
108864 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
108865 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
108866 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
108867 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
108868 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
108869 +get_string_7302 get_string 0 7302 NULL
108870 +mgmt_control_7349 mgmt_control 3 7349 NULL
108871 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
108872 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
108873 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
108874 +hweight_long_7388 hweight_long 1-0 7388 NULL
108875 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
108876 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
108877 +readb_7401 readb 0 7401 NULL
108878 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
108879 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
108880 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
108881 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
108882 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
108883 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
108884 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
108885 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
108886 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
108887 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
108888 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
108889 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
108890 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
108891 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
108892 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
108893 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
108894 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
108895 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
108896 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
108897 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
108898 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
108899 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
108900 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
108901 +dev_write_7708 dev_write 3 7708 NULL
108902 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
108903 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
108904 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
108905 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
108906 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
108907 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
108908 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
108909 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
108910 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
108911 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
108912 +config_desc_7878 config_desc 0 7878 NULL
108913 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
108914 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
108915 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
108916 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
108917 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
108918 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
108919 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
108920 +vcs_read_8017 vcs_read 3 8017 NULL
108921 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
108922 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
108923 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
108924 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
108925 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
108926 +venus_lookup_8121 venus_lookup 4 8121 NULL
108927 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
108928 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
108929 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
108930 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
108931 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
108932 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
108933 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
108934 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
108935 +play_iframe_8219 play_iframe 3 8219 NULL
108936 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
108937 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
108938 +ceph_sync_write_8233 ceph_sync_write 4 8233 NULL
108939 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
108940 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
108941 +init_cdev_8274 init_cdev 1 8274 NULL
108942 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
108943 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
108944 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
108945 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
108946 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
108947 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
108948 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
108949 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
108950 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
108951 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
108952 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
108953 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
108954 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
108955 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
108956 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
108957 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
108958 +dev_config_8506 dev_config 3 8506 NULL
108959 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
108960 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
108961 +user_on_off_8552 user_on_off 2 8552 NULL
108962 +profile_remove_8556 profile_remove 3 8556 NULL
108963 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
108964 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
108965 +tower_write_8580 tower_write 3 8580 NULL
108966 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
108967 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
108968 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
108969 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
108970 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
108971 +generic_acl_set_8658 generic_acl_set 4 8658 NULL
108972 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
108973 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
108974 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
108975 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
108976 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
108977 +arcfb_write_8702 arcfb_write 3 8702 NULL
108978 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
108979 +init_header_8703 init_header 0 8703 &i_size_read_8703
108980 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
108981 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
108982 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
108983 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
108984 +__create_irqs_8733 __create_irqs 2 8733 NULL
108985 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
108986 +compound_order_8750 compound_order 0 8750 NULL
108987 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
108988 +yurex_write_8761 yurex_write 3 8761 NULL
108989 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
108990 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
108991 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
108992 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
108993 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
108994 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
108995 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
108996 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
108997 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
108998 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
108999 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
109000 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
109001 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
109002 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
109003 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
109004 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
109005 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
109006 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
109007 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
109008 +write_file_ani_8918 write_file_ani 3 8918 NULL
109009 +layout_commit_8926 layout_commit 3 8926 NULL
109010 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
109011 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
109012 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
109013 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
109014 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
109015 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
109016 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
109017 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
109018 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
109019 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
109020 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
109021 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
109022 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
109023 +nla_put_9042 nla_put 3 9042 NULL
109024 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
109025 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
109026 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
109027 +create_queues_9088 create_queues 2-3 9088 NULL
109028 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
109029 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
109030 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
109031 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110
109032 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
109033 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
109034 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
109035 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
109036 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
109037 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
109038 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
109039 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
109040 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
109041 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
109042 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
109043 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
109044 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
109045 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
109046 +flakey_status_9274 flakey_status 5 9274 NULL
109047 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
109048 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
109049 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
109050 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
109051 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
109052 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
109053 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
109054 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
109055 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
109056 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
109057 +read_9397 read 3 9397 NULL
109058 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
109059 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
109060 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
109061 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
109062 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
109063 +ext3_xattr_set_acl_9467 ext3_xattr_set_acl 4 9467 NULL
109064 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
109065 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
109066 +crypt_status_9492 crypt_status 5 9492 NULL
109067 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
109068 +lp_write_9511 lp_write 3 9511 NULL
109069 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
109070 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
109071 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
109072 +read_file_dma_9530 read_file_dma 3 9530 NULL
109073 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
109074 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
109075 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
109076 +fw_node_create_9559 fw_node_create 2 9559 NULL
109077 +kobj_map_9566 kobj_map 2-3 9566 NULL
109078 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
109079 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
109080 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
109081 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
109082 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
109083 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
109084 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
109085 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
109086 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
109087 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
109088 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
109089 +dns_query_9676 dns_query 3 9676 NULL
109090 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
109091 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
109092 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
109093 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
109094 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
109095 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
109096 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
109097 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
109098 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
109099 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
109100 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
109101 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
109102 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
109103 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
109104 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
109105 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
109106 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
109107 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
109108 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
109109 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
109110 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
109111 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
109112 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
109113 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
109114 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
109115 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
109116 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
109117 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
109118 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
109119 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
109120 +read_file_misc_9948 read_file_misc 3 9948 NULL
109121 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
109122 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
109123 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
109124 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
109125 +gameport_read_9983 gameport_read 0 9983 NULL
109126 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
109127 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
109128 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
109129 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
109130 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
109131 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
109132 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
109133 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
109134 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
109135 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
109136 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
109137 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
109138 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
109139 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
109140 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
109141 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
109142 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
109143 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
109144 +read_emulate_10310 read_emulate 2-4 10310 NULL
109145 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
109146 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
109147 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
109148 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
109149 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
109150 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
109151 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
109152 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
109153 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
109154 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
109155 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
109156 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
109157 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
109158 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
109159 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
109160 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
109161 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
109162 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
109163 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
109164 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
109165 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
109166 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
109167 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
109168 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
109169 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
109170 +otp_read_10594 otp_read 2-4-5 10594 NULL
109171 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
109172 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
109173 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
109174 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
109175 +parport_write_10669 parport_write 0 10669 NULL
109176 +edge_write_10692 edge_write 4 10692 NULL
109177 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
109178 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
109179 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
109180 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
109181 +spi_sync_10731 spi_sync 0 10731 NULL
109182 +apu_get_register_10737 apu_get_register 0 10737 NULL nohasharray
109183 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 &apu_get_register_10737
109184 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
109185 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
109186 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
109187 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
109188 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
109189 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
109190 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
109191 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
109192 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
109193 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
109194 +get_scq_10897 get_scq 2 10897 NULL
109195 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
109196 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
109197 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
109198 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
109199 +kobject_add_10919 kobject_add 0 10919 NULL
109200 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
109201 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
109202 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
109203 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
109204 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
109205 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
109206 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
109207 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
109208 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
109209 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
109210 +count_argc_11083 count_argc 0 11083 NULL
109211 +ocfs2_blocks_per_xattr_bucket_11099 ocfs2_blocks_per_xattr_bucket 0 11099 NULL
109212 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
109213 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
109214 +page_offset_11120 page_offset 0 11120 NULL
109215 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
109216 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
109217 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
109218 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
109219 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
109220 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
109221 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
109222 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
109223 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
109224 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
109225 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
109226 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
109227 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
109228 +construct_key_11329 construct_key 3 11329 NULL nohasharray
109229 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
109230 +next_segment_11330 next_segment 0-2-1 11330 NULL
109231 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 2-1 11332 NULL
109232 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
109233 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
109234 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
109235 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
109236 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
109237 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
109238 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
109239 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
109240 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
109241 +str_to_user_11411 str_to_user 2 11411 NULL
109242 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
109243 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
109244 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL nohasharray
109245 +import_sec_validate_get_11417 import_sec_validate_get 0 11417 &adis16480_show_firmware_revision_11417
109246 +trace_options_read_11419 trace_options_read 3 11419 NULL
109247 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
109248 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
109249 +bttv_read_11432 bttv_read 3 11432 NULL
109250 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
109251 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
109252 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
109253 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
109254 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
109255 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
109256 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
109257 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
109258 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
109259 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
109260 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
109261 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
109262 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
109263 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
109264 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
109265 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
109266 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
109267 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
109268 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
109269 +slab_ksize_11664 slab_ksize 0 11664 NULL
109270 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
109271 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
109272 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
109273 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
109274 +split_11691 split 2 11691 NULL
109275 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
109276 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
109277 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
109278 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
109279 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
109280 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
109281 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
109282 +umc_device_register_11824 umc_device_register 0 11824 NULL
109283 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
109284 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
109285 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
109286 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
109287 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
109288 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
109289 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
109290 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
109291 +ti_write_11916 ti_write 4 11916 NULL
109292 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
109293 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
109294 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
109295 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
109296 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
109297 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
109298 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
109299 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
109300 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
109301 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
109302 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
109303 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
109304 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
109305 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
109306 +set_powered_12129 set_powered 4 12129 NULL
109307 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
109308 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
109309 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
109310 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
109311 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
109312 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
109313 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
109314 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
109315 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
109316 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
109317 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
109318 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
109319 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
109320 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
109321 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
109322 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
109323 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
109324 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
109325 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
109326 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
109327 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
109328 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
109329 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
109330 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
109331 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
109332 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
109333 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 NULL nohasharray
109334 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391 nohasharray
109335 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
109336 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
109337 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
109338 +ptlrpc_set_wait_12426 ptlrpc_set_wait 0 12426 NULL
109339 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
109340 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
109341 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
109342 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
109343 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
109344 +xfs_get_extsz_hint_12531 xfs_get_extsz_hint 0 12531 NULL
109345 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
109346 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
109347 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
109348 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
109349 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
109350 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
109351 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
109352 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
109353 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
109354 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
109355 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
109356 +lustre_pack_request_v2_12665 lustre_pack_request_v2 0 12665 NULL
109357 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
109358 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
109359 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
109360 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
109361 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
109362 +ivtv_write_12721 ivtv_write 3 12721 NULL
109363 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
109364 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
109365 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
109366 +listxattr_12769 listxattr 3 12769 NULL
109367 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
109368 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
109369 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
109370 +readq_12825 readq 0 12825 NULL
109371 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
109372 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
109373 +spidev_sync_12842 spidev_sync 0 12842 NULL
109374 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
109375 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
109376 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
109377 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
109378 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
109379 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
109380 +bm_status_write_12964 bm_status_write 3 12964 NULL
109381 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
109382 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
109383 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
109384 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
109385 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
109386 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
109387 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
109388 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
109389 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
109390 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
109391 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
109392 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
109393 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
109394 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
109395 +blk_update_request_13146 blk_update_request 3 13146 NULL
109396 +ocfs2_quota_trans_credits_13150 ocfs2_quota_trans_credits 0 13150 NULL
109397 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
109398 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
109399 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
109400 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
109401 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
109402 +comedi_read_13199 comedi_read 3 13199 NULL
109403 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
109404 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
109405 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
109406 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
109407 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
109408 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
109409 +bio_integrity_trim_13259 bio_integrity_trim 3 13259 NULL
109410 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
109411 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
109412 +il4965_stats_flag_13281 il4965_stats_flag 3-0 13281 NULL
109413 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
109414 +sd_major_13294 sd_major 0-1 13294 NULL
109415 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
109416 +__clone_and_map_data_bio_13334 __clone_and_map_data_bio 4-8 13334 NULL
109417 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
109418 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
109419 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
109420 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
109421 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
109422 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
109423 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
109424 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
109425 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
109426 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
109427 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
109428 +data_read_13494 data_read 3 13494 NULL
109429 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
109430 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
109431 +core_status_13515 core_status 4 13515 NULL
109432 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
109433 +bm_init_13529 bm_init 2 13529 NULL
109434 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
109435 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
109436 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
109437 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
109438 +cache_write_13589 cache_write 3 13589 NULL
109439 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
109440 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
109441 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
109442 +packet_snd_13634 packet_snd 3 13634 NULL
109443 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
109444 +cache_downcall_13666 cache_downcall 3 13666 NULL
109445 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
109446 +nv94_aux_13689 nv94_aux 2-5 13689 NULL
109447 +usb_get_string_13693 usb_get_string 0 13693 NULL
109448 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
109449 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
109450 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
109451 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
109452 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
109453 +random_read_13815 random_read 3 13815 NULL
109454 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
109455 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
109456 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
109457 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
109458 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
109459 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
109460 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
109461 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
109462 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
109463 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
109464 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
109465 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
109466 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
109467 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
109468 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
109469 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
109470 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
109471 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
109472 +qcam_read_13977 qcam_read 3 13977 NULL
109473 +dsp_read_13980 dsp_read 2 13980 NULL
109474 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
109475 +create_files_14003 create_files 0 14003 NULL
109476 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
109477 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
109478 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
109479 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
109480 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
109481 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
109482 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
109483 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
109484 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
109485 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
109486 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
109487 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
109488 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
109489 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
109490 +em_canid_change_14150 em_canid_change 3 14150 NULL
109491 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
109492 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
109493 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
109494 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
109495 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
109496 +alloc_async_14208 alloc_async 1 14208 NULL
109497 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
109498 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
109499 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
109500 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
109501 +rr_status_14293 rr_status 5 14293 NULL
109502 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
109503 +oo_objects_14319 oo_objects 0 14319 NULL
109504 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
109505 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
109506 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
109507 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
109508 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
109509 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
109510 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
109511 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
109512 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
109513 +block_size_14443 block_size 0 14443 NULL
109514 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
109515 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
109516 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
109517 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
109518 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
109519 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
109520 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
109521 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
109522 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
109523 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
109524 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
109525 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
109526 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
109527 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
109528 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
109529 +dbJoin_14644 dbJoin 0 14644 NULL
109530 +profile_replace_14652 profile_replace 3 14652 NULL
109531 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
109532 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
109533 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
109534 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
109535 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
109536 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
109537 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
109538 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
109539 +cgroup_path_14713 cgroup_path 3 14713 NULL
109540 +vfd_write_14717 vfd_write 3 14717 NULL
109541 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
109542 +raid1_resize_14740 raid1_resize 2 14740 NULL
109543 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
109544 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
109545 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
109546 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
109547 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
109548 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
109549 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
109550 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
109551 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
109552 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
109553 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
109554 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
109555 +lcd_write_14857 lcd_write 3 14857 NULL
109556 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
109557 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
109558 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
109559 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
109560 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
109561 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
109562 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
109563 +queue_cnt_14951 queue_cnt 0 14951 NULL
109564 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
109565 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
109566 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
109567 +setkey_14987 setkey 3 14987 NULL nohasharray
109568 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
109569 +xfs_dinode_size_14996 xfs_dinode_size 0 14996 NULL
109570 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
109571 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
109572 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
109573 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
109574 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
109575 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
109576 +ceph_calc_ceph_pg_15075 ceph_calc_ceph_pg 0 15075 NULL
109577 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
109578 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
109579 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
109580 +start_port_15124 start_port 0 15124 NULL
109581 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
109582 +iwl_dbgfs_sta_drain_write_15167 iwl_dbgfs_sta_drain_write 3 15167 NULL
109583 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
109584 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
109585 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
109586 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
109587 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
109588 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
109589 +simple_strtol_15273 simple_strtol 0 15273 NULL
109590 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
109591 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
109592 +xlog_ticket_alloc_15335 xlog_ticket_alloc 2 15335 NULL
109593 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
109594 +ioread16_15342 ioread16 0 15342 NULL
109595 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
109596 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
109597 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
109598 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
109599 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
109600 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
109601 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
109602 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
109603 +get_modalias_15406 get_modalias 2 15406 NULL
109604 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
109605 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
109606 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
109607 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
109608 +memweight_15450 memweight 2 15450 NULL
109609 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
109610 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
109611 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
109612 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
109613 +persistent_status_15574 persistent_status 4 15574 NULL
109614 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
109615 +vme_user_write_15587 vme_user_write 3 15587 NULL
109616 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
109617 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
109618 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
109619 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
109620 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
109621 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
109622 +fs_path_add_15648 fs_path_add 3 15648 NULL
109623 +xsd_read_15653 xsd_read 3 15653 NULL
109624 +unix_bind_15668 unix_bind 3 15668 NULL
109625 +dm_read_15674 dm_read 3 15674 NULL nohasharray
109626 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
109627 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
109628 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
109629 +bio_map_15794 bio_map 3-0 15794 NULL
109630 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
109631 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
109632 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
109633 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
109634 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
109635 +table_size_15851 table_size 0-1-2 15851 NULL
109636 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
109637 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
109638 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
109639 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
109640 +native_read_msr_15905 native_read_msr 0 15905 NULL
109641 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
109642 +power_read_15939 power_read 3 15939 NULL
109643 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
109644 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
109645 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
109646 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
109647 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
109648 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
109649 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
109650 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
109651 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
109652 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
109653 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
109654 +fsm_init_16134 fsm_init 2 16134 NULL
109655 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
109656 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
109657 +mapping_level_16188 mapping_level 2-0 16188 NULL
109658 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
109659 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
109660 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
109661 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
109662 +create_table_16213 create_table 2 16213 NULL
109663 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
109664 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
109665 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
109666 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
109667 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
109668 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
109669 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
109670 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
109671 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
109672 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
109673 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
109674 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
109675 +account_16283 account 0-4-2 16283 NULL nohasharray
109676 +mirror_status_16283 mirror_status 5 16283 &account_16283
109677 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
109678 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
109679 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
109680 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
109681 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
109682 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
109683 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
109684 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
109685 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
109686 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
109687 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
109688 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
109689 +cmdline_store_16442 cmdline_store 4 16442 NULL
109690 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
109691 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
109692 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
109693 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
109694 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
109695 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
109696 +raid10_resize_16537 raid10_resize 2 16537 NULL
109697 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
109698 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
109699 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
109700 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
109701 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
109702 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
109703 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
109704 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
109705 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
109706 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
109707 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
109708 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
109709 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
109710 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
109711 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
109712 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
109713 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
109714 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
109715 +st_write_16874 st_write 3 16874 NULL
109716 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
109717 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
109718 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
109719 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
109720 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
109721 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
109722 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
109723 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
109724 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
109725 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
109726 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
109727 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
109728 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
109729 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
109730 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
109731 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
109732 +entry_length_17093 entry_length 0 17093 NULL
109733 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
109734 +write_mem_17114 write_mem 3 17114 NULL
109735 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
109736 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
109737 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
109738 +sep_read_17161 sep_read 3 17161 NULL
109739 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
109740 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
109741 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
109742 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
109743 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
109744 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
109745 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
109746 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
109747 +sync_request_17208 sync_request 2 17208 NULL
109748 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
109749 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
109750 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
109751 +alloc_ep_17269 alloc_ep 1 17269 NULL
109752 +pg_read_17276 pg_read 3 17276 NULL
109753 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
109754 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
109755 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
109756 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
109757 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 0 17298 NULL
109758 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
109759 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
109760 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
109761 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
109762 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
109763 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
109764 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
109765 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
109766 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
109767 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
109768 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
109769 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
109770 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
109771 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
109772 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
109773 +qp_free_res_17541 qp_free_res 5 17541 NULL
109774 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
109775 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
109776 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
109777 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
109778 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
109779 +osst_execute_17607 osst_execute 7-6 17607 NULL
109780 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
109781 +dma_map_page_17628 dma_map_page 0 17628 NULL
109782 +ocfs2_rotate_subtree_left_17634 ocfs2_rotate_subtree_left 5 17634 NULL
109783 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
109784 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
109785 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
109786 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
109787 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
109788 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
109789 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
109790 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
109791 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
109792 +brcmf_sdio_chip_verifynvram_17776 brcmf_sdio_chip_verifynvram 4 17776 NULL
109793 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
109794 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
109795 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
109796 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
109797 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
109798 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
109799 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
109800 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
109801 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
109802 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
109803 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
109804 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
109805 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
109806 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
109807 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
109808 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
109809 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
109810 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
109811 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
109812 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
109813 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
109814 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
109815 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
109816 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
109817 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
109818 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
109819 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
109820 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
109821 +fpregs_get_18066 fpregs_get 4 18066 NULL
109822 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
109823 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
109824 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
109825 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
109826 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
109827 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
109828 +svc_getnl_18120 svc_getnl 0 18120 NULL
109829 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
109830 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
109831 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
109832 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
109833 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
109834 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
109835 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
109836 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
109837 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
109838 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
109839 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
109840 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
109841 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
109842 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
109843 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
109844 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
109845 +um_idi_write_18293 um_idi_write 3 18293 NULL
109846 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
109847 +vga_r_18310 vga_r 0 18310 NULL
109848 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
109849 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
109850 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
109851 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
109852 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
109853 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
109854 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
109855 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
109856 +ep_io_18367 ep_io 0 18367 NULL
109857 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
109858 +ci_role_write_18388 ci_role_write 3 18388 NULL
109859 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
109860 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
109861 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
109862 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
109863 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
109864 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
109865 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
109866 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
109867 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
109868 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
109869 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
109870 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
109871 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
109872 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
109873 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
109874 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
109875 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
109876 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
109877 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
109878 +debug_output_18575 debug_output 3 18575 NULL
109879 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
109880 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
109881 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
109882 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL nohasharray
109883 +audio_get_endpoint_req_18624 audio_get_endpoint_req 0 18624 &nvc0_ram_create__18624
109884 +from_buffer_18625 from_buffer 3 18625 NULL
109885 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
109886 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
109887 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
109888 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
109889 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
109890 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
109891 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
109892 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
109893 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
109894 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
109895 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
109896 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
109897 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
109898 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
109899 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
109900 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
109901 +prealloc_18800 prealloc 0 18800 NULL
109902 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
109903 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
109904 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
109905 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
109906 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
109907 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
109908 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
109909 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
109910 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
109911 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
109912 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
109913 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
109914 +huge_page_size_19008 huge_page_size 0 19008 NULL
109915 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
109916 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
109917 +revalidate_19043 revalidate 2 19043 NULL
109918 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
109919 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
109920 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
109921 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
109922 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
109923 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
109924 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
109925 +ATOMIC_SUB_RETURN_19115 ATOMIC_SUB_RETURN 2 19115 NULL
109926 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
109927 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
109928 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
109929 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
109930 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
109931 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
109932 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
109933 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
109934 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
109935 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
109936 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
109937 +ucma_query_19260 ucma_query 4 19260 NULL
109938 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
109939 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
109940 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
109941 +qc_capture_19298 qc_capture 3 19298 NULL
109942 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
109943 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
109944 +debug_read_19322 debug_read 3 19322 NULL
109945 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
109946 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
109947 +closure_sub_19359 closure_sub 2 19359 NULL
109948 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
109949 +read_zero_19366 read_zero 3 19366 NULL
109950 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
109951 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
109952 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
109953 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
109954 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
109955 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
109956 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
109957 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
109958 +sky2_read16_19475 sky2_read16 0 19475 NULL
109959 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
109960 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
109961 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
109962 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
109963 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
109964 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
109965 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
109966 +howmany_64_19548 howmany_64 2 19548 NULL
109967 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
109968 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
109969 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
109970 +nfsd_read_19568 nfsd_read 5 19568 NULL
109971 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
109972 +bm_status_read_19583 bm_status_read 3 19583 NULL
109973 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
109974 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
109975 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
109976 +iwl_dbgfs_pm_params_write_19660 iwl_dbgfs_pm_params_write 3 19660 NULL
109977 +read_reg_19723 read_reg 0 19723 NULL
109978 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
109979 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
109980 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
109981 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
109982 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
109983 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
109984 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
109985 +readhscx_19769 readhscx 0 19769 NULL
109986 +__set_print_fmt_19776 __set_print_fmt 0 19776 NULL
109987 +iwl_dbgfs_disable_power_off_write_19823 iwl_dbgfs_disable_power_off_write 3 19823 NULL
109988 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
109989 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
109990 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
109991 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
109992 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
109993 +__nla_put_19857 __nla_put 3 19857 NULL
109994 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
109995 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
109996 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
109997 +mangle_name_19923 mangle_name 0 19923 NULL
109998 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
109999 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
110000 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
110001 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
110002 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
110003 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
110004 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
110005 +lustre_pack_request_19992 lustre_pack_request 0 19992 NULL
110006 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
110007 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL
110008 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
110009 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
110010 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
110011 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
110012 +target_message_20072 target_message 2 20072 NULL
110013 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
110014 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
110015 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
110016 +team_options_register_20091 team_options_register 3 20091 NULL
110017 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
110018 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
110019 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
110020 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
110021 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
110022 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
110023 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
110024 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
110025 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
110026 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
110027 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
110028 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
110029 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
110030 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
110031 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
110032 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
110033 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
110034 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
110035 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
110036 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
110037 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
110038 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
110039 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
110040 +nfs3_setxattr_20458 nfs3_setxattr 4 20458 NULL
110041 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
110042 +read_buf_20469 read_buf 2 20469 NULL
110043 +bio_trim_20472 bio_trim 2 20472 NULL
110044 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
110045 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
110046 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
110047 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
110048 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
110049 +venus_create_20555 venus_create 4 20555 NULL
110050 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
110051 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
110052 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
110053 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
110054 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
110055 +lirc_write_20604 lirc_write 3 20604 NULL
110056 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
110057 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
110058 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
110059 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
110060 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
110061 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
110062 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
110063 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
110064 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
110065 +cpumask_size_20683 cpumask_size 0 20683 NULL
110066 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
110067 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
110068 +__maestro_read_20700 __maestro_read 0 20700 NULL
110069 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
110070 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
110071 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
110072 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
110073 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
110074 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
110075 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
110076 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
110077 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
110078 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
110079 +strndup_user_20819 strndup_user 2 20819 NULL
110080 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
110081 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
110082 +uvc_alloc_entity_20836 uvc_alloc_entity 3-4 20836 NULL
110083 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
110084 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
110085 +get_name_20855 get_name 4 20855 NULL
110086 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
110087 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
110088 +srq_free_res_20868 srq_free_res 5 20868 NULL
110089 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
110090 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
110091 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
110092 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
110093 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
110094 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
110095 +htable_bits_20933 htable_bits 0 20933 NULL
110096 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
110097 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
110098 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
110099 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
110100 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
110101 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
110102 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
110103 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
110104 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
110105 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
110106 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
110107 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
110108 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
110109 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
110110 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
110111 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
110112 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
110113 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
110114 +ocfs2_extend_meta_needed_21104 ocfs2_extend_meta_needed 0 21104 NULL
110115 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
110116 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
110117 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
110118 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
110119 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
110120 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
110121 +input_ff_create_21240 input_ff_create 2 21240 NULL
110122 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
110123 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
110124 +fru_length_21257 fru_length 0 21257 NULL
110125 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
110126 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
110127 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
110128 +add_res_range_21310 add_res_range 4 21310 NULL
110129 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
110130 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
110131 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
110132 +ocfs2_find_subtree_root_21351 ocfs2_find_subtree_root 0 21351 NULL
110133 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
110134 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
110135 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
110136 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
110137 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
110138 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
110139 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
110140 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
110141 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
110142 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
110143 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
110144 +ReadISAR_21453 ReadISAR 0 21453 NULL
110145 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
110146 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
110147 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
110148 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
110149 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
110150 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
110151 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
110152 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
110153 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
110154 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
110155 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
110156 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
110157 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
110158 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
110159 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
110160 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
110161 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
110162 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
110163 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
110164 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
110165 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
110166 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
110167 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
110168 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
110169 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
110170 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
110171 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
110172 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
110173 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
110174 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
110175 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
110176 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
110177 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
110178 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
110179 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
110180 +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
110181 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
110182 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
110183 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
110184 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
110185 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
110186 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
110187 +mem_rw_22085 mem_rw 3 22085 NULL
110188 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
110189 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
110190 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
110191 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
110192 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
110193 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
110194 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
110195 +mem_write_22232 mem_write 3 22232 NULL
110196 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
110197 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
110198 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
110199 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
110200 +add_res_tree_22263 add_res_tree 7 22263 NULL
110201 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
110202 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
110203 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
110204 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
110205 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
110206 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
110207 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
110208 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
110209 +atomic_read_22342 atomic_read 0 22342 NULL
110210 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
110211 +memcg_size_22360 memcg_size 0 22360 NULL
110212 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
110213 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
110214 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
110215 +zoran_write_22404 zoran_write 3 22404 NULL
110216 +ATOMIC_ADD_RETURN_22413 ATOMIC_ADD_RETURN 2 22413 NULL
110217 +queue_reply_22416 queue_reply 3 22416 NULL
110218 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
110219 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
110220 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
110221 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
110222 +source_sink_start_ep_22472 source_sink_start_ep 0 22472 NULL
110223 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
110224 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
110225 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
110226 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
110227 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
110228 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
110229 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
110230 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
110231 +snapshot_read_22601 snapshot_read 3 22601 NULL
110232 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
110233 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
110234 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
110235 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
110236 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
110237 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
110238 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
110239 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
110240 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
110241 +reg_umr_22686 reg_umr 5 22686 NULL
110242 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
110243 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
110244 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
110245 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
110246 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
110247 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
110248 +print_frame_22769 print_frame 0 22769 NULL
110249 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
110250 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
110251 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
110252 +clone_bio_integrity_22842 clone_bio_integrity 4 22842 NULL
110253 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
110254 +create_attr_set_22861 create_attr_set 1 22861 NULL
110255 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
110256 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
110257 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
110258 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
110259 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 NULL
110260 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
110261 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
110262 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
110263 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
110264 +vme_get_size_22964 vme_get_size 0 22964 NULL
110265 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
110266 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
110267 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
110268 +brcmf_sdio_chip_exit_download_23001 brcmf_sdio_chip_exit_download 4 23001 NULL
110269 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
110270 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
110271 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0-6-7 23029 NULL
110272 +st_status_23032 st_status 5 23032 NULL
110273 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
110274 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
110275 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
110276 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
110277 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
110278 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
110279 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
110280 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
110281 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
110282 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
110283 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
110284 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
110285 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
110286 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
110287 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL
110288 +__clear_user_23118 __clear_user 0-2 23118 NULL
110289 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
110290 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
110291 +read_file_ani_23161 read_file_ani 3 23161 NULL
110292 +usblp_write_23178 usblp_write 3 23178 NULL
110293 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
110294 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
110295 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
110296 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
110297 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
110298 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
110299 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
110300 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
110301 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
110302 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
110303 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
110304 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
110305 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
110306 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
110307 +page_readlink_23346 page_readlink 3 23346 NULL
110308 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
110309 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
110310 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
110311 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
110312 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
110313 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
110314 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
110315 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
110316 +linear_conf_23485 linear_conf 2 23485 NULL
110317 +event_filter_read_23494 event_filter_read 3 23494 NULL
110318 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
110319 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
110320 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
110321 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
110322 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
110323 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
110324 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
110325 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
110326 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
110327 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
110328 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
110329 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
110330 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
110331 +sInW_23663 sInW 0 23663 NULL
110332 +SyS_connect_23669 SyS_connect 3 23669 NULL
110333 +cx18_read_23699 cx18_read 3 23699 NULL
110334 +at_get_23708 at_get 0 23708 NULL
110335 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
110336 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
110337 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
110338 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
110339 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
110340 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
110341 +map_write_23795 map_write 3 23795 NULL
110342 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
110343 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
110344 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
110345 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
110346 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 3-4 23829 NULL
110347 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
110348 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
110349 +p54_init_common_23850 p54_init_common 1 23850 NULL
110350 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
110351 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
110352 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
110353 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL
110354 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
110355 +usbg_prepare_w_request_23895 usbg_prepare_w_request 0 23895 NULL
110356 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
110357 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
110358 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
110359 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
110360 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
110361 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
110362 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
110363 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
110364 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
110365 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
110366 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
110367 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
110368 +give_pages_24021 give_pages 3 24021 NULL
110369 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
110370 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
110371 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
110372 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
110373 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
110374 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
110375 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
110376 +lov_brw_24122 lov_brw 4 24122 NULL
110377 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
110378 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
110379 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
110380 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
110381 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
110382 +adu_read_24177 adu_read 3 24177 NULL
110383 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
110384 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
110385 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
110386 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
110387 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
110388 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
110389 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
110390 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
110391 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
110392 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
110393 +thin_status_24278 thin_status 5 24278 NULL
110394 +msg_size_24288 msg_size 0 24288 NULL
110395 +gserial_connect_24302 gserial_connect 0 24302 NULL
110396 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
110397 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
110398 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
110399 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
110400 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
110401 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
110402 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
110403 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
110404 +igetword_24373 igetword 0 24373 NULL
110405 +max_io_len_24384 max_io_len 0-1 24384 NULL
110406 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
110407 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
110408 +getxattr_24398 getxattr 4 24398 NULL nohasharray
110409 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
110410 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
110411 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
110412 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
110413 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
110414 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
110415 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
110416 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
110417 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
110418 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
110419 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
110420 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
110421 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
110422 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
110423 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
110424 +pd_video_read_24510 pd_video_read 3 24510 NULL
110425 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
110426 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
110427 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
110428 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
110429 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
110430 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
110431 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
110432 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
110433 +SyS_poll_24620 SyS_poll 2 24620 NULL
110434 +context_alloc_24645 context_alloc 3 24645 NULL
110435 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
110436 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
110437 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
110438 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
110439 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
110440 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
110441 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
110442 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
110443 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
110444 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
110445 +cache_read_24790 cache_read 3 24790 NULL
110446 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
110447 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
110448 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
110449 +net2272_read_24825 net2272_read 0 24825 NULL
110450 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
110451 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
110452 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
110453 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
110454 +queues_read_24877 queues_read 3 24877 NULL
110455 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
110456 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
110457 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
110458 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
110459 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
110460 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
110461 +ll_layout_fetch_24961 ll_layout_fetch 0 24961 NULL
110462 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
110463 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
110464 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
110465 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
110466 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
110467 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
110468 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
110469 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
110470 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
110471 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
110472 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
110473 +iwl_dbgfs_tx_flush_write_25091 iwl_dbgfs_tx_flush_write 3 25091 NULL
110474 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
110475 +blkg_path_25099 blkg_path 3 25099 NULL
110476 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
110477 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
110478 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
110479 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
110480 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
110481 +stripe_status_25259 stripe_status 5 25259 NULL
110482 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
110483 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
110484 +vfs_writev_25278 vfs_writev 3 25278 NULL
110485 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
110486 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
110487 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
110488 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
110489 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
110490 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
110491 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
110492 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
110493 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
110494 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
110495 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
110496 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
110497 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
110498 +sb_permission_25523 sb_permission 0 25523 NULL
110499 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
110500 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
110501 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
110502 +ht_print_chan_25556 ht_print_chan 3-4-0 25556 NULL
110503 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
110504 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
110505 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
110506 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
110507 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
110508 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
110509 +__direct_map_25647 __direct_map 6-5 25647 NULL
110510 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
110511 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
110512 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
110513 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
110514 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
110515 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
110516 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
110517 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
110518 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
110519 +sg_read_25799 sg_read 3 25799 NULL
110520 +system_enable_read_25815 system_enable_read 3 25815 NULL
110521 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
110522 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
110523 +parport_read_25855 parport_read 0 25855 NULL
110524 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
110525 +key_attr_size_25865 key_attr_size 0 25865 NULL
110526 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
110527 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
110528 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
110529 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
110530 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
110531 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
110532 +rcname_read_25919 rcname_read 3 25919 NULL
110533 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
110534 +key_flags_read_25931 key_flags_read 3 25931 NULL
110535 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
110536 +flush_25957 flush 2 25957 NULL
110537 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
110538 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
110539 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
110540 +xfs_xattr_acl_set_26028 xfs_xattr_acl_set 4 26028 NULL
110541 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
110542 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
110543 +tun_do_read_26047 tun_do_read 5 26047 NULL
110544 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
110545 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
110546 +read_sb_page_26119 read_sb_page 5 26119 NULL
110547 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
110548 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
110549 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
110550 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
110551 +disk_devt_26180 disk_devt 0 26180 NULL
110552 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
110553 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
110554 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
110555 +mce_write_26201 mce_write 3 26201 NULL
110556 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
110557 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
110558 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
110559 +bio_split_26235 bio_split 2 26235 NULL
110560 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
110561 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
110562 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
110563 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL nohasharray
110564 +pax_get_random_long_26309 pax_get_random_long 0 26309 &snd_pcm_plug_client_channels_buf_26309
110565 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
110566 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
110567 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
110568 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
110569 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
110570 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
110571 +ntty_write_26404 ntty_write 3 26404 NULL
110572 +firmware_store_26408 firmware_store 4 26408 NULL
110573 +pagemap_read_26441 pagemap_read 3 26441 NULL
110574 +tower_read_26461 tower_read 3 26461 NULL nohasharray
110575 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
110576 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
110577 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
110578 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
110579 +read_vmcore_26501 read_vmcore 3 26501 NULL
110580 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
110581 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
110582 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
110583 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
110584 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
110585 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
110586 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
110587 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
110588 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
110589 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
110590 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
110591 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
110592 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
110593 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
110594 +bos_desc_26752 bos_desc 0 26752 NULL
110595 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
110596 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
110597 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
110598 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
110599 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
110600 +smk_write_load_26829 smk_write_load 3 26829 NULL
110601 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
110602 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
110603 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
110604 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
110605 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
110606 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
110607 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
110608 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
110609 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
110610 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
110611 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
110612 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
110613 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
110614 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
110615 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
110616 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
110617 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
110618 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
110619 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
110620 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
110621 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
110622 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
110623 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
110624 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
110625 +pms_capture_27142 pms_capture 4 27142 NULL
110626 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
110627 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
110628 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
110629 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
110630 +write_kmem_27225 write_kmem 3 27225 NULL
110631 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
110632 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
110633 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
110634 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
110635 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
110636 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
110637 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
110638 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
110639 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
110640 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
110641 +seq_read_27411 seq_read 3 27411 NULL
110642 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
110643 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
110644 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0-3-4 27422 NULL
110645 +cypress_write_27423 cypress_write 4 27423 NULL
110646 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
110647 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
110648 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
110649 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
110650 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
110651 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
110652 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
110653 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
110654 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
110655 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
110656 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
110657 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
110658 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
110659 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
110660 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
110661 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642
110662 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
110663 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
110664 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
110665 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
110666 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
110667 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
110668 +evm_write_key_27715 evm_write_key 3 27715 NULL
110669 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
110670 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
110671 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
110672 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
110673 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
110674 +SyS_readv_27804 SyS_readv 3 27804 NULL
110675 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
110676 +fwtty_buffer_rx_27821 fwtty_buffer_rx 3 27821 NULL
110677 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
110678 +init_header_complete_27833 init_header_complete 0 27833 NULL
110679 +read_profile_27859 read_profile 3 27859 NULL
110680 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
110681 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
110682 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
110683 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
110684 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
110685 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
110686 +device_register_27972 device_register 0 27972 NULL nohasharray
110687 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
110688 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
110689 +f2fs_bio_alloc_27983 f2fs_bio_alloc 2 27983 NULL
110690 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
110691 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
110692 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
110693 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
110694 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
110695 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
110696 +pool_status_28055 pool_status 5 28055 NULL
110697 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
110698 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
110699 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
110700 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
110701 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
110702 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
110703 +video_read_28148 video_read 3 28148 NULL
110704 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
110705 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
110706 +vread_28173 vread 0-3 28173 NULL
110707 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
110708 +counter_free_res_28187 counter_free_res 5 28187 NULL
110709 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
110710 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
110711 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
110712 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
110713 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
110714 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
110715 +usemap_size_28281 usemap_size 0 28281 NULL
110716 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
110717 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
110718 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
110719 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
110720 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
110721 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
110722 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
110723 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
110724 +snapshot_write_28351 snapshot_write 3 28351 NULL
110725 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
110726 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
110727 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
110728 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
110729 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
110730 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
110731 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
110732 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
110733 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
110734 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
110735 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
110736 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
110737 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
110738 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
110739 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
110740 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
110741 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
110742 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
110743 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
110744 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
110745 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
110746 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
110747 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
110748 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
110749 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
110750 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
110751 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
110752 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
110753 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
110754 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
110755 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
110756 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
110757 +spi_execute_28736 spi_execute 5 28736 NULL
110758 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
110759 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
110760 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
110761 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
110762 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
110763 +sel_write_member_28800 sel_write_member 3 28800 NULL
110764 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
110765 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
110766 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
110767 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
110768 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
110769 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
110770 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
110771 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
110772 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
110773 +push_rx_28939 push_rx 3 28939 NULL
110774 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
110775 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
110776 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
110777 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
110778 +bin_uuid_28999 bin_uuid 3 28999 NULL
110779 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
110780 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
110781 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
110782 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
110783 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
110784 +roundup_64_29066 roundup_64 2-0-1 29066 NULL
110785 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
110786 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
110787 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
110788 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
110789 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
110790 +snprintf_29125 snprintf 0 29125 NULL
110791 +iov_shorten_29130 iov_shorten 0 29130 NULL
110792 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
110793 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
110794 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
110795 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
110796 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
110797 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
110798 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
110799 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
110800 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
110801 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
110802 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
110803 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
110804 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
110805 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
110806 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
110807 +tun_put_user_29337 tun_put_user 5 29337 NULL
110808 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
110809 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
110810 +mwifiex_cfg80211_mgmt_tx_29387 mwifiex_cfg80211_mgmt_tx 7 29387 NULL
110811 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
110812 +mempool_create_29437 mempool_create 1 29437 NULL
110813 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
110814 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
110815 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
110816 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
110817 +do_register_entry_29478 do_register_entry 4 29478 NULL
110818 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
110819 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
110820 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
110821 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
110822 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
110823 +ftrace_write_29551 ftrace_write 3 29551 NULL
110824 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
110825 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
110826 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
110827 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
110828 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
110829 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
110830 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
110831 +slots_per_page_29601 slots_per_page 0 29601 NULL
110832 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
110833 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
110834 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
110835 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
110836 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
110837 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
110838 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
110839 +probes_write_29711 probes_write 3 29711 NULL
110840 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
110841 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
110842 +std_nic_write_29752 std_nic_write 3 29752 NULL
110843 +dbAlloc_29794 dbAlloc 0 29794 NULL
110844 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
110845 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
110846 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
110847 +count_partial_29850 count_partial 0 29850 NULL
110848 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
110849 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
110850 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
110851 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
110852 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
110853 +write_file_queue_29922 write_file_queue 3 29922 NULL
110854 +ext4_xattr_set_acl_29930 ext4_xattr_set_acl 4 29930 NULL
110855 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
110856 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
110857 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
110858 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
110859 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
110860 +drp_wmove_30043 drp_wmove 4 30043 NULL
110861 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
110862 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
110863 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
110864 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
110865 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
110866 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
110867 +recv_stream_30138 recv_stream 4 30138 NULL
110868 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
110869 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
110870 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
110871 +expand_inode_data_30169 expand_inode_data 2-3 30169 NULL
110872 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
110873 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
110874 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
110875 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
110876 +SyS_semop_30227 SyS_semop 3 30227 NULL
110877 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
110878 +ocfs2_calc_bg_discontig_credits_30230 ocfs2_calc_bg_discontig_credits 0 30230 NULL
110879 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
110880 +hfsplus_trusted_setxattr_30270 hfsplus_trusted_setxattr 4 30270 NULL
110881 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
110882 +compat_readv_30273 compat_readv 3 30273 NULL
110883 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
110884 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
110885 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
110886 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
110887 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
110888 +i8254_read_30330 i8254_read 0 30330 NULL
110889 +resource_from_user_30341 resource_from_user 3 30341 NULL
110890 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
110891 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
110892 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
110893 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
110894 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
110895 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
110896 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
110897 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
110898 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
110899 +enable_write_30456 enable_write 3 30456 NULL
110900 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
110901 +urandom_read_30462 urandom_read 3 30462 NULL
110902 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
110903 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
110904 +adu_write_30487 adu_write 3 30487 NULL
110905 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
110906 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
110907 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
110908 +set_config_30526 set_config 0 30526 NULL nohasharray
110909 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
110910 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
110911 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
110912 +set_le_30581 set_le 4 30581 NULL
110913 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
110914 +i2c_hid_get_report_length_30598 i2c_hid_get_report_length 0 30598 NULL
110915 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL nohasharray
110916 +cpufreq_get_global_kobject_30610 cpufreq_get_global_kobject 0 30610 &sgl_map_user_pages_30610
110917 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
110918 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
110919 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
110920 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
110921 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
110922 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
110923 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
110924 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
110925 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
110926 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
110927 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
110928 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
110929 +snapshot_status_30744 snapshot_status 5 30744 NULL
110930 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
110931 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
110932 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
110933 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
110934 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
110935 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
110936 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
110937 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
110938 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
110939 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
110940 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
110941 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
110942 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
110943 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
110944 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
110945 +stride_pg_count_31053 stride_pg_count 0-2-1-4-3-5 31053 NULL
110946 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
110947 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
110948 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
110949 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
110950 +depth_read_31112 depth_read 3 31112 NULL
110951 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
110952 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
110953 +size_inside_page_31141 size_inside_page 0 31141 NULL
110954 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
110955 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
110956 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
110957 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
110958 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
110959 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
110960 +__read_reg_31216 __read_reg 0 31216 NULL
110961 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
110962 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
110963 +cyy_readb_31240 cyy_readb 0 31240 NULL
110964 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
110965 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
110966 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
110967 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
110968 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
110969 +command_file_write_31318 command_file_write 3 31318 NULL
110970 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
110971 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
110972 +outlen_write_31358 outlen_write 3 31358 NULL
110973 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
110974 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
110975 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
110976 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
110977 +inb_31388 inb 0 31388 NULL
110978 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
110979 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
110980 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
110981 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
110982 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
110983 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
110984 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
110985 +alg_setkey_31485 alg_setkey 3 31485 NULL
110986 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
110987 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
110988 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
110989 +hidraw_write_31536 hidraw_write 3 31536 NULL
110990 +usbvision_read_31555 usbvision_read 3 31555 NULL
110991 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
110992 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
110993 +osst_write_31581 osst_write 3 31581 NULL
110994 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
110995 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
110996 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
110997 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
110998 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
110999 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
111000 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
111001 +__lgread_31668 __lgread 4 31668 NULL
111002 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
111003 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
111004 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
111005 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
111006 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
111007 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
111008 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
111009 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
111010 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
111011 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
111012 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
111013 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
111014 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
111015 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
111016 +data_write_31805 data_write 3 31805 NULL
111017 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
111018 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
111019 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
111020 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
111021 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
111022 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
111023 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
111024 +xattr_permission_31907 xattr_permission 0 31907 NULL
111025 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
111026 +new_dir_31919 new_dir 3 31919 NULL
111027 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
111028 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
111029 +read_mem_31942 read_mem 3 31942 NULL nohasharray
111030 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
111031 +vb2_write_31948 vb2_write 3 31948 NULL
111032 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
111033 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
111034 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
111035 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
111036 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
111037 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
111038 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
111039 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
111040 +calc_hmac_32010 calc_hmac 3 32010 NULL
111041 +aead_len_32021 aead_len 0 32021 NULL
111042 +posix_acl_set_32037 posix_acl_set 4 32037 NULL
111043 +stk_read_32038 stk_read 3 32038 NULL
111044 +ocfs2_update_edge_lengths_32046 ocfs2_update_edge_lengths 3 32046 NULL
111045 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
111046 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
111047 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
111048 +bio_alloc_32095 bio_alloc 2 32095 NULL
111049 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
111050 +disk_status_32120 disk_status 4 32120 NULL
111051 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
111052 +venus_link_32165 venus_link 5 32165 NULL
111053 +do_writepages_32173 do_writepages 0 32173 NULL
111054 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
111055 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
111056 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
111057 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
111058 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
111059 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
111060 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
111061 +SyS_select_32319 SyS_select 1 32319 NULL
111062 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
111063 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
111064 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
111065 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
111066 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
111067 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
111068 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
111069 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
111070 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
111071 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
111072 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
111073 +cache_status_32462 cache_status 5 32462 NULL
111074 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
111075 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
111076 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
111077 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
111078 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
111079 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
111080 +disconnect_32521 disconnect 4 32521 NULL
111081 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
111082 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL nohasharray
111083 +audio_get_intf_req_32524 audio_get_intf_req 0 32524 &ocfs2_refresh_qinfo_32524
111084 +ilo_read_32531 ilo_read 3 32531 NULL
111085 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
111086 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
111087 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
111088 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
111089 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
111090 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
111091 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
111092 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
111093 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
111094 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
111095 +kvmalloc_32646 kvmalloc 1 32646 NULL
111096 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
111097 +generic_readlink_32654 generic_readlink 3 32654 NULL
111098 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
111099 +apei_res_add_32674 apei_res_add 0 32674 NULL
111100 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
111101 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
111102 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
111103 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
111104 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
111105 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
111106 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
111107 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
111108 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
111109 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
111110 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
111111 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
111112 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 6-4 32884 NULL
111113 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
111114 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
111115 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
111116 +xfs_log_reserve_32959 xfs_log_reserve 2 32959 NULL
111117 +ocfs2_check_dir_trailer_32968 ocfs2_check_dir_trailer 0 32968 NULL
111118 +compat_filldir_32999 compat_filldir 3 32999 NULL
111119 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
111120 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
111121 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
111122 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
111123 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
111124 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
111125 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
111126 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
111127 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
111128 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
111129 +alloc_tio_33077 alloc_tio 3 33077 NULL
111130 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
111131 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
111132 +__len_within_target_33132 __len_within_target 0 33132 NULL
111133 +SyS_poll_33152 SyS_poll 2 33152 NULL
111134 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
111135 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
111136 +pp_read_33210 pp_read 3 33210 NULL
111137 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
111138 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
111139 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
111140 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
111141 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
111142 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
111143 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
111144 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
111145 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
111146 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
111147 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
111148 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
111149 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
111150 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
111151 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
111152 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
111153 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
111154 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
111155 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
111156 +message_stats_list_33440 message_stats_list 5 33440 NULL
111157 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
111158 +create_entry_33479 create_entry 2 33479 NULL
111159 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL nohasharray
111160 +elf_map_33487 elf_map 0-2 33487 &ip_setsockopt_33487
111161 +res_counter_read_33499 res_counter_read 4 33499 NULL
111162 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
111163 +fb_read_33506 fb_read 3 33506 NULL
111164 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
111165 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
111166 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
111167 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
111168 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
111169 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
111170 +count_subheaders_33591 count_subheaders 0 33591 NULL
111171 +scsi_execute_33596 scsi_execute 5 33596 NULL
111172 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
111173 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
111174 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
111175 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
111176 +stride_page_count_33641 stride_page_count 2 33641 NULL
111177 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
111178 +inw_p_33668 inw_p 0 33668 NULL
111179 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
111180 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
111181 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
111182 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
111183 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
111184 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
111185 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
111186 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
111187 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
111188 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
111189 +hashtab_create_33769 hashtab_create 3 33769 NULL
111190 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
111191 +filter_write_33819 filter_write 3 33819 NULL
111192 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
111193 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
111194 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
111195 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
111196 +get_user_pages_33908 get_user_pages 0 33908 NULL
111197 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
111198 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
111199 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
111200 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
111201 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
111202 +hfsplus_osx_setxattr_33952 hfsplus_osx_setxattr 4 33952 NULL
111203 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
111204 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
111205 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
111206 +ppp_write_34034 ppp_write 3 34034 NULL
111207 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
111208 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
111209 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
111210 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
111211 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
111212 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
111213 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
111214 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
111215 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
111216 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
111217 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
111218 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
111219 +sysfs_bin_read_34228 sysfs_bin_read 3 34228 NULL
111220 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
111221 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
111222 +device_private_init_34279 device_private_init 0 34279 NULL
111223 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
111224 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
111225 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
111226 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
111227 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
111228 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
111229 +ea_read_34378 ea_read 0 34378 NULL
111230 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
111231 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
111232 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
111233 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
111234 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
111235 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
111236 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
111237 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
111238 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
111239 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
111240 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
111241 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
111242 +ocfs2_mv_xattr_buckets_34484 ocfs2_mv_xattr_buckets 6 34484 NULL
111243 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
111244 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
111245 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
111246 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
111247 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
111248 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
111249 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
111250 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
111251 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
111252 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
111253 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
111254 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
111255 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
111256 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
111257 +brcmf_cfg80211_mgmt_tx_34608 brcmf_cfg80211_mgmt_tx 7 34608 NULL
111258 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
111259 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
111260 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
111261 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
111262 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
111263 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
111264 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
111265 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
111266 +port_print_34704 port_print 3 34704 NULL
111267 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
111268 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
111269 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
111270 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
111271 +bootmode_store_34762 bootmode_store 4 34762 NULL
111272 +device_add_34766 device_add 0 34766 NULL
111273 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
111274 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
111275 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
111276 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
111277 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
111278 +file_page_index_34820 file_page_index 0-2 34820 NULL
111279 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
111280 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
111281 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
111282 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
111283 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
111284 +msg_print_text_34889 msg_print_text 0 34889 NULL
111285 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
111286 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
111287 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
111288 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
111289 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
111290 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
111291 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
111292 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
111293 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
111294 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
111295 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
111296 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
111297 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
111298 +brcmf_sdio_chip_writenvram_35042 brcmf_sdio_chip_writenvram 4 35042 NULL
111299 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
111300 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
111301 +capi_write_35104 capi_write 3 35104 NULL nohasharray
111302 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
111303 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
111304 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
111305 +message_stats_print_35158 message_stats_print 6 35158 NULL
111306 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
111307 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
111308 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
111309 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
111310 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
111311 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
111312 +set_fd_set_35249 set_fd_set 1 35249 NULL
111313 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
111314 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
111315 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
111316 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
111317 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
111318 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
111319 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
111320 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
111321 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
111322 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
111323 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
111324 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
111325 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
111326 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
111327 +read_kmem_35372 read_kmem 3 35372 NULL
111328 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
111329 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
111330 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
111331 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
111332 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
111333 +async_setkey_35521 async_setkey 3 35521 NULL
111334 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
111335 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
111336 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
111337 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
111338 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
111339 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
111340 +sysfs_create_subdir_35567 sysfs_create_subdir 0 35567 NULL
111341 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
111342 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
111343 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
111344 +kernel_readv_35617 kernel_readv 3 35617 NULL
111345 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
111346 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
111347 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
111348 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
111349 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
111350 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
111351 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
111352 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
111353 +md_super_write_35703 md_super_write 4 35703 NULL
111354 +ocfs2_extent_recs_per_gd_35710 ocfs2_extent_recs_per_gd 0 35710 NULL
111355 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
111356 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
111357 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
111358 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
111359 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
111360 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
111361 +fls64_35862 fls64 0 35862 NULL
111362 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
111363 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
111364 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
111365 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
111366 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
111367 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
111368 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
111369 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
111370 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
111371 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
111372 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
111373 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
111374 +acl_alloc_35979 acl_alloc 1 35979 NULL
111375 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
111376 +generic_file_aio_read_35987 generic_file_aio_read 0 35987 NULL
111377 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
111378 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
111379 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
111380 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
111381 +account_shadowed_36048 account_shadowed 2 36048 NULL
111382 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
111383 +write_emulate_36065 write_emulate 2-4 36065 NULL
111384 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
111385 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
111386 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
111387 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
111388 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
111389 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
111390 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
111391 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
111392 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
111393 +twl_set_36154 twl_set 2 36154 NULL
111394 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
111395 +btrfs_file_extent_inline_len_36158 btrfs_file_extent_inline_len 0 36158 NULL
111396 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
111397 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
111398 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
111399 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
111400 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
111401 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
111402 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
111403 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
111404 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
111405 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
111406 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
111407 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
111408 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
111409 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
111410 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
111411 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
111412 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
111413 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
111414 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
111415 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
111416 +lc_create_36332 lc_create 4 36332 NULL
111417 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
111418 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
111419 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
111420 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
111421 +to_sector_36361 to_sector 0-1 36361 NULL
111422 +tunables_read_36385 tunables_read 3 36385 NULL
111423 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
111424 +sierra_write_36402 sierra_write 4 36402 NULL
111425 +iwl_dbgfs_d3_sram_write_36403 iwl_dbgfs_d3_sram_write 3 36403 NULL
111426 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
111427 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
111428 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
111429 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
111430 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
111431 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
111432 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
111433 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
111434 +cmd_loop_36491 cmd_loop 0 36491 NULL
111435 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
111436 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
111437 +get_param_l_36518 get_param_l 0 36518 NULL
111438 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
111439 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
111440 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
111441 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL nohasharray
111442 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
111443 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
111444 +__erst_read_36579 __erst_read 0 36579 NULL
111445 +put_cmsg_36589 put_cmsg 4 36589 NULL
111446 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
111447 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
111448 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
111449 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
111450 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
111451 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
111452 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
111453 +xillybus_read_36678 xillybus_read 3 36678 NULL
111454 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
111455 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
111456 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
111457 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
111458 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
111459 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 2-3-4-5 36796 NULL
111460 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
111461 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
111462 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
111463 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
111464 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
111465 +cm_write_36858 cm_write 3 36858 NULL
111466 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
111467 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
111468 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
111469 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
111470 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
111471 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
111472 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
111473 +audio_set_endpoint_req_36918 audio_set_endpoint_req 0 36918 NULL
111474 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
111475 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
111476 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
111477 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
111478 +setxattr_37006 setxattr 4 37006 NULL
111479 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
111480 +command_file_read_37038 command_file_read 3 37038 NULL
111481 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
111482 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
111483 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
111484 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
111485 +parse_command_37079 parse_command 2 37079 NULL
111486 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
111487 +tun_get_user_37094 tun_get_user 5 37094 NULL
111488 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
111489 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
111490 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
111491 +msg_word_37164 msg_word 0 37164 NULL
111492 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
111493 +can_set_xattr_37182 can_set_xattr 4 37182 NULL
111494 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
111495 +sysfs_add_file_37200 sysfs_add_file 0 37200 NULL
111496 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
111497 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
111498 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
111499 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
111500 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
111501 +__do_replace_37227 __do_replace 5 37227 NULL
111502 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
111503 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
111504 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
111505 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
111506 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
111507 +ocfs2_calc_extend_credits_37310 ocfs2_calc_extend_credits 0 37310 NULL
111508 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
111509 +send_msg_37323 send_msg 4 37323 NULL
111510 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
111511 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
111512 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
111513 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
111514 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
111515 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
111516 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
111517 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
111518 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 7-9-0 37433 NULL
111519 +fru_alloc_37442 fru_alloc 1 37442 NULL
111520 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
111521 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
111522 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
111523 +get_est_timing_37484 get_est_timing 0 37484 NULL
111524 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
111525 +__hfsplus_setxattr_37499 __hfsplus_setxattr 4 37499 NULL
111526 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
111527 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
111528 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
111529 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
111530 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
111531 +hdr_size_37536 hdr_size 0 37536 NULL
111532 +extent_map_end_37550 extent_map_end 0 37550 NULL
111533 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
111534 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
111535 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
111536 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
111537 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
111538 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
111539 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
111540 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
111541 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
111542 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
111543 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
111544 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
111545 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
111546 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
111547 +page_chain_free_37697 page_chain_free 0 37697 NULL
111548 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
111549 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
111550 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
111551 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
111552 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
111553 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
111554 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
111555 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
111556 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
111557 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
111558 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
111559 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
111560 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
111561 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
111562 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
111563 +set_registers_37883 set_registers 4 37883 NULL
111564 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
111565 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
111566 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
111567 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
111568 +write_file_bool_37957 write_file_bool 3 37957 NULL
111569 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
111570 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
111571 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
111572 +vfs_readv_38011 vfs_readv 3 38011 NULL
111573 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
111574 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
111575 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
111576 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
111577 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
111578 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
111579 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
111580 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
111581 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
111582 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
111583 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
111584 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
111585 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
111586 +ep0_read_38095 ep0_read 3 38095 NULL
111587 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
111588 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
111589 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
111590 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
111591 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
111592 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
111593 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
111594 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
111595 +cdev_add_38176 cdev_add 2-3 38176 NULL
111596 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
111597 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
111598 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
111599 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
111600 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
111601 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
111602 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
111603 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
111604 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
111605 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
111606 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
111607 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
111608 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
111609 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
111610 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
111611 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
111612 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
111613 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
111614 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
111615 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
111616 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
111617 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
111618 +dev_names_read_38509 dev_names_read 3 38509 NULL
111619 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
111620 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
111621 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
111622 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
111623 +kuc_len_38557 kuc_len 0-1 38557 NULL
111624 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
111625 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
111626 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
111627 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
111628 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
111629 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
111630 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
111631 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
111632 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
111633 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
111634 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
111635 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
111636 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
111637 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
111638 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
111639 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
111640 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
111641 +udf_readpages_38761 udf_readpages 4 38761 NULL
111642 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
111643 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
111644 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
111645 +slab_order_38794 slab_order 0 38794 NULL
111646 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
111647 +err_decode_38804 err_decode 2 38804 NULL
111648 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
111649 +direct_entry_38836 direct_entry 3 38836 NULL
111650 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
111651 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
111652 +interfaces_38859 interfaces 2 38859 NULL
111653 +pci_msix_table_size_38867 pci_msix_table_size 0 38867 NULL
111654 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
111655 +f2fs_xattr_set_acl_38895 f2fs_xattr_set_acl 4 38895 NULL
111656 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
111657 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
111658 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
111659 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
111660 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
111661 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
111662 +get_nodes_39012 get_nodes 3 39012 NULL
111663 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
111664 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
111665 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
111666 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
111667 +ReadHFC_39104 ReadHFC 0 39104 NULL
111668 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
111669 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
111670 +ea_foreach_39133 ea_foreach 0 39133 NULL
111671 +generic_permission_39150 generic_permission 0 39150 NULL
111672 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
111673 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
111674 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
111675 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
111676 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
111677 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
111678 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
111679 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
111680 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
111681 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
111682 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
111683 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
111684 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
111685 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
111686 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
111687 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
111688 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
111689 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
111690 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
111691 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
111692 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
111693 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
111694 +__send_to_port_39386 __send_to_port 3 39386 NULL
111695 +user_power_read_39414 user_power_read 3 39414 NULL
111696 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
111697 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
111698 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
111699 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
111700 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
111701 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
111702 +int_proc_write_39542 int_proc_write 3 39542 NULL
111703 +mdc_unpack_capa_39553 mdc_unpack_capa 0 39553 NULL
111704 +pp_write_39554 pp_write 3 39554 NULL
111705 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
111706 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
111707 +ext_depth_39607 ext_depth 0 39607 NULL
111708 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
111709 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
111710 +sdio_readb_39618 sdio_readb 0 39618 NULL
111711 +set_dev_class_39645 set_dev_class 4 39645 NULL
111712 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
111713 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
111714 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
111715 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
111716 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
111717 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
111718 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
111719 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
111720 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
111721 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
111722 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
111723 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
111724 +pkt_add_39897 pkt_add 3 39897 NULL
111725 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
111726 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
111727 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
111728 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
111729 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
111730 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
111731 +__spi_async_39932 __spi_async 0 39932 NULL
111732 +__get_order_39935 __get_order 0 39935 NULL
111733 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
111734 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
111735 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
111736 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
111737 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
111738 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
111739 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
111740 +server_name2svname_39998 server_name2svname 4 39998 NULL
111741 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
111742 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
111743 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
111744 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
111745 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
111746 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
111747 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
111748 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
111749 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
111750 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
111751 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
111752 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
111753 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
111754 +pt_write_40159 pt_write 3 40159 NULL
111755 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
111756 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
111757 +allocate_probes_40204 allocate_probes 1 40204 NULL
111758 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
111759 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
111760 +osst_read_40237 osst_read 3 40237 NULL
111761 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
111762 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
111763 +ptlrpc_queue_wait_40252 ptlrpc_queue_wait 0 40252 NULL
111764 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
111765 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
111766 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
111767 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
111768 +SyS_bind_40303 SyS_bind 3 40303 NULL
111769 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
111770 +mmio_read_40348 mmio_read 4 40348 NULL
111771 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
111772 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
111773 +get_chars_40373 get_chars 3 40373 NULL
111774 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
111775 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
111776 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
111777 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
111778 +SyS_writev_40467 SyS_writev 3 40467 NULL
111779 +SyS_select_40473 SyS_select 1 40473 NULL
111780 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
111781 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
111782 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
111783 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
111784 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
111785 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
111786 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
111787 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
111788 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
111789 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
111790 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
111791 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
111792 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
111793 +fops_read_40672 fops_read 3 40672 NULL
111794 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
111795 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
111796 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
111797 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
111798 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
111799 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
111800 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
111801 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
111802 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
111803 +card_send_command_40757 card_send_command 3 40757 NULL
111804 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
111805 +pg_write_40766 pg_write 3 40766 NULL
111806 +show_list_40775 show_list 3-0 40775 NULL
111807 +kfifo_out_copy_r_40784 kfifo_out_copy_r 3-0 40784 NULL
111808 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
111809 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
111810 +add_action_40811 add_action 4 40811 NULL
111811 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
111812 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
111813 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
111814 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
111815 +read_file_queue_40895 read_file_queue 3 40895 NULL
111816 +waiters_read_40902 waiters_read 3 40902 NULL
111817 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
111818 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
111819 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
111820 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
111821 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
111822 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
111823 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
111824 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
111825 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
111826 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
111827 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
111828 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
111829 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
111830 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
111831 +calculate_order_41061 calculate_order 0 41061 NULL
111832 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
111833 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
111834 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
111835 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
111836 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
111837 +dma_attach_41094 dma_attach 5-6 41094 NULL
111838 +provide_user_output_41105 provide_user_output 3 41105 NULL
111839 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
111840 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
111841 +ocfs2_extend_trans_41116 ocfs2_extend_trans 2 41116 NULL
111842 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
111843 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
111844 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
111845 +dgap_driver_kzmalloc_41189 dgap_driver_kzmalloc 1 41189 NULL
111846 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
111847 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
111848 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
111849 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
111850 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
111851 +erst_read_41260 erst_read 0 41260 NULL
111852 +alloc_context_41283 alloc_context 1 41283 NULL
111853 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
111854 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
111855 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
111856 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
111857 +kmp_init_41373 kmp_init 2 41373 NULL
111858 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
111859 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
111860 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
111861 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
111862 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
111863 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
111864 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
111865 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
111866 +se_io_cb_41461 se_io_cb 3 41461 NULL
111867 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
111868 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
111869 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
111870 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
111871 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
111872 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
111873 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
111874 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
111875 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
111876 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
111877 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
111878 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
111879 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
111880 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
111881 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
111882 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
111883 +vga_io_r_41609 vga_io_r 0 41609 NULL
111884 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
111885 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
111886 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
111887 +a2mp_send_41615 a2mp_send 4 41615 NULL
111888 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
111889 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
111890 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
111891 +get_std_timing_41654 get_std_timing 0 41654 NULL
111892 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
111893 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
111894 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
111895 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
111896 +fillonedir_41746 fillonedir 3 41746 NULL
111897 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
111898 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
111899 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
111900 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
111901 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
111902 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
111903 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
111904 +pci_map_single_41869 pci_map_single 0 41869 NULL
111905 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
111906 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
111907 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
111908 +nfsd_getxattr_41934 nfsd_getxattr 0 41934 NULL
111909 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
111910 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
111911 +read_gssp_41947 read_gssp 3 41947 NULL
111912 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
111913 +portnames_read_41958 portnames_read 3 41958 NULL
111914 +dst_mtu_41969 dst_mtu 0 41969 NULL
111915 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
111916 +pool_allocate_42012 pool_allocate 3 42012 NULL
111917 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
111918 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
111919 +create_dir_42025 create_dir 0 42025 NULL
111920 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
111921 +__btrfs_drop_extents_42032 __btrfs_drop_extents 5 42032 NULL
111922 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
111923 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
111924 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
111925 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
111926 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
111927 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
111928 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
111929 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
111930 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
111931 +obd_get_info_42156 obd_get_info 0 42156 NULL
111932 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
111933 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
111934 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
111935 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
111936 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
111937 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
111938 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
111939 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
111940 +find_last_bit_42260 find_last_bit 0 42260 NULL
111941 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
111942 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
111943 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
111944 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
111945 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
111946 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
111947 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
111948 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
111949 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
111950 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
111951 +tipc_send_42374 tipc_send 3 42374 NULL
111952 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
111953 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
111954 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
111955 +krng_get_random_42420 krng_get_random 3 42420 NULL
111956 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
111957 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
111958 +alloc_request_42448 alloc_request 0 42448 NULL
111959 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
111960 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
111961 +kuc_free_42455 kuc_free 2 42455 NULL
111962 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
111963 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
111964 +bypass_write_42498 bypass_write 3 42498 NULL
111965 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
111966 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
111967 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
111968 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
111969 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
111970 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
111971 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
111972 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
111973 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
111974 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
111975 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
111976 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
111977 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
111978 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
111979 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
111980 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
111981 +vb2_read_42703 vb2_read 3 42703 NULL
111982 +read_status_42722 read_status 0 42722 NULL
111983 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
111984 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
111985 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
111986 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
111987 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
111988 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
111989 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
111990 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
111991 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
111992 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
111993 +ptlrpc_request_bufs_pack_42793 ptlrpc_request_bufs_pack 0 42793 NULL
111994 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
111995 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
111996 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
111997 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
111998 +set_arg_42824 set_arg 3 42824 NULL
111999 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
112000 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
112001 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
112002 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
112003 +hd_end_request_42904 hd_end_request 2 42904 NULL
112004 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
112005 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL nohasharray
112006 +mdc_unpack_acl_42941 mdc_unpack_acl 0 42941 &sctp_getsockopt_maxburst_42941
112007 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
112008 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
112009 +read_file_node_stat_42964 read_file_node_stat 3 42964 NULL
112010 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
112011 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
112012 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
112013 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
112014 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
112015 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
112016 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
112017 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
112018 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
112019 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
112020 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
112021 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
112022 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
112023 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
112024 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
112025 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
112026 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
112027 +uio_write_43202 uio_write 3 43202 NULL
112028 +iso_callback_43208 iso_callback 3 43208 NULL
112029 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
112030 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
112031 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
112032 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
112033 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
112034 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
112035 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
112036 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
112037 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
112038 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
112039 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
112040 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
112041 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
112042 +xenfb_write_43412 xenfb_write 3 43412 NULL
112043 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
112044 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
112045 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
112046 +usb_string_43443 usb_string 0 43443 NULL nohasharray
112047 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
112048 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
112049 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
112050 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
112051 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
112052 +do_readlink_43518 do_readlink 2 43518 NULL
112053 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
112054 +read_events_43534 read_events 3 43534 NULL
112055 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
112056 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
112057 +request_resource_43548 request_resource 0 43548 NULL
112058 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
112059 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
112060 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
112061 +proc_read_43614 proc_read 3 43614 NULL
112062 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
112063 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
112064 +random_write_43656 random_write 3 43656 NULL
112065 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
112066 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
112067 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
112068 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
112069 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
112070 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
112071 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
112072 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
112073 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
112074 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
112075 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
112076 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
112077 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
112078 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
112079 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
112080 +read_flush_43851 read_flush 3 43851 NULL
112081 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
112082 +SendString_43928 SendString 3 43928 NULL
112083 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
112084 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
112085 +nla_reserve_43984 nla_reserve 3 43984 NULL
112086 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
112087 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
112088 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
112089 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
112090 +emit_flags_44006 emit_flags 4-3 44006 NULL
112091 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
112092 +fru_strlen_44046 fru_strlen 0 44046 NULL
112093 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
112094 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
112095 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 NULL
112096 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
112097 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
112098 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
112099 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
112100 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
112101 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
112102 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
112103 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
112104 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
112105 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
112106 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
112107 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
112108 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
112109 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
112110 +device_create_file_44285 device_create_file 0 44285 NULL
112111 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
112112 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
112113 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
112114 +rs_init_44327 rs_init 1 44327 NULL
112115 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
112116 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
112117 +alloc_requests_44372 alloc_requests 0 44372 NULL
112118 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
112119 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
112120 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
112121 +strlcpy_44400 strlcpy 3 44400 NULL
112122 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
112123 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
112124 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
112125 +iwl_dbgfs_bf_params_write_44450 iwl_dbgfs_bf_params_write 3 44450 NULL
112126 +write_file_debug_44476 write_file_debug 3 44476 NULL
112127 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
112128 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
112129 +bio_advance_44496 bio_advance 2 44496 NULL
112130 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
112131 +ac_register_board_44504 ac_register_board 3 44504 NULL
112132 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
112133 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
112134 +spidev_write_44510 spidev_write 3 44510 NULL
112135 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
112136 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
112137 +comm_write_44537 comm_write 3 44537 NULL
112138 +xfs_log_calc_unit_res_44540 xfs_log_calc_unit_res 0-2 44540 NULL
112139 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
112140 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
112141 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
112142 +mpi_resize_44674 mpi_resize 2 44674 NULL
112143 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
112144 +ts_read_44687 ts_read 3 44687 NULL
112145 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
112146 +__ocfs2_rotate_tree_left_44705 __ocfs2_rotate_tree_left 3 44705 NULL
112147 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
112148 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
112149 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
112150 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
112151 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
112152 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
112153 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
112154 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
112155 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
112156 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
112157 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
112158 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
112159 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
112160 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
112161 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
112162 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
112163 +sisusb_write_44834 sisusb_write 3 44834 NULL
112164 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
112165 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
112166 +copydesc_user_44855 copydesc_user 3 44855 NULL
112167 +set_advertising_44870 set_advertising 4 44870 NULL
112168 +init_rs_44873 init_rs 1 44873 NULL
112169 +skb_availroom_44883 skb_availroom 0 44883 NULL
112170 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
112171 +do_tty_write_44896 do_tty_write 5 44896 NULL
112172 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
112173 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
112174 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
112175 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
112176 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
112177 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
112178 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
112179 +sel_write_user_45060 sel_write_user 3 45060 NULL
112180 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
112181 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
112182 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
112183 +usbdev_read_45114 usbdev_read 3 45114 NULL
112184 +send_to_tty_45141 send_to_tty 3 45141 NULL
112185 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
112186 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
112187 +device_write_45156 device_write 3 45156 NULL nohasharray
112188 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
112189 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
112190 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
112191 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
112192 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
112193 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
112194 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
112195 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
112196 +event_enable_write_45238 event_enable_write 3 45238 NULL
112197 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
112198 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
112199 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
112200 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
112201 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
112202 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
112203 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
112204 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
112205 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
112206 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
112207 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
112208 +__node_remap_45458 __node_remap 4 45458 NULL
112209 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
112210 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
112211 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
112212 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
112213 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
112214 +copy_macs_45534 copy_macs 4 45534 NULL
112215 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
112216 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
112217 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
112218 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
112219 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
112220 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
112221 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
112222 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
112223 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
112224 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
112225 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
112226 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
112227 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
112228 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
112229 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
112230 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL nohasharray
112231 +task_cgroup_path_45734 task_cgroup_path 3 45734 &snd_cs46xx_io_read_45734
112232 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
112233 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
112234 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
112235 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
112236 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
112237 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
112238 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
112239 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
112240 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
112241 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
112242 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
112243 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
112244 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
112245 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
112246 +isdn_write_45863 isdn_write 3 45863 NULL
112247 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
112248 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
112249 +ima_eventdigest_init_common_45889 ima_eventdigest_init_common 2 45889 NULL
112250 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
112251 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
112252 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
112253 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
112254 +alloc_mr_45935 alloc_mr 1 45935 NULL
112255 +copy_to_45969 copy_to 3 45969 NULL
112256 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
112257 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
112258 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
112259 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
112260 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
112261 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
112262 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
112263 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
112264 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
112265 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
112266 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
112267 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
112268 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
112269 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
112270 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
112271 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
112272 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
112273 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
112274 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
112275 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
112276 +fq_resize_46195 fq_resize 2 46195 NULL
112277 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
112278 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
112279 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
112280 +dsp_write_46218 dsp_write 2 46218 NULL
112281 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
112282 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
112283 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
112284 +ReadReg_46277 ReadReg 0 46277 NULL
112285 +sptlrpc_req_get_ctx_46303 sptlrpc_req_get_ctx 0 46303 NULL
112286 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
112287 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
112288 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
112289 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
112290 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
112291 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
112292 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
112293 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
112294 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
112295 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
112296 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
112297 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
112298 +filldir64_46469 filldir64 3 46469 NULL
112299 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
112300 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
112301 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
112302 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
112303 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
112304 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
112305 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
112306 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
112307 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
112308 +il3945_stats_flag_46606 il3945_stats_flag 3-0 46606 NULL
112309 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
112310 +__kfifo_out_r_46623 __kfifo_out_r 3-0 46623 NULL
112311 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
112312 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
112313 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
112314 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
112315 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
112316 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
112317 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
112318 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
112319 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
112320 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
112321 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
112322 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
112323 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
112324 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
112325 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
112326 +readreg_46845 readreg 0 46845 NULL
112327 +spi_async_46857 spi_async 0 46857 NULL
112328 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
112329 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
112330 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
112331 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
112332 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
112333 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
112334 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
112335 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
112336 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
112337 +fb_write_46924 fb_write 3 46924 NULL
112338 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
112339 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
112340 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
112341 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
112342 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
112343 +strlcat_46985 strlcat 3 46985 NULL
112344 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
112345 +sel_write_bool_46996 sel_write_bool 3 46996 NULL nohasharray
112346 +gfs2_xattr_system_set_46996 gfs2_xattr_system_set 4 46996 &sel_write_bool_46996
112347 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
112348 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
112349 +fs_path_len_47060 fs_path_len 0 47060 NULL
112350 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
112351 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
112352 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
112353 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
112354 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
112355 +mousedev_read_47123 mousedev_read 3 47123 NULL
112356 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
112357 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
112358 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
112359 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
112360 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
112361 +can_set_system_xattr_47182 can_set_system_xattr 4 47182 NULL
112362 +options_write_47243 options_write 3 47243 NULL
112363 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
112364 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
112365 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
112366 +vsnprintf_47291 vsnprintf 0 47291 NULL
112367 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
112368 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
112369 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
112370 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
112371 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
112372 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
112373 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
112374 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
112375 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
112376 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
112377 +nametbl_list_47391 nametbl_list 2 47391 NULL
112378 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
112379 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
112380 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
112381 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
112382 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
112383 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
112384 +posix_acl_from_disk_47445 posix_acl_from_disk 2 47445 NULL
112385 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
112386 +newpart_47485 newpart 6-4 47485 NULL
112387 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
112388 +core_sys_select_47494 core_sys_select 1 47494 NULL
112389 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
112390 +unlink_simple_47506 unlink_simple 3 47506 NULL
112391 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
112392 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
112393 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
112394 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
112395 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
112396 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
112397 +read_ldt_47570 read_ldt 2 47570 NULL
112398 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
112399 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
112400 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
112401 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
112402 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
112403 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
112404 +get_size_47644 get_size 1-2 47644 NULL
112405 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
112406 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
112407 +save_microcode_47717 save_microcode 3 47717 NULL
112408 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
112409 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
112410 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
112411 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
112412 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
112413 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
112414 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
112415 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
112416 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
112417 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
112418 +lov_packmd_47810 lov_packmd 0 47810 NULL
112419 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
112420 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
112421 +vhci_read_47878 vhci_read 3 47878 NULL
112422 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
112423 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
112424 +comedi_write_47926 comedi_write 3 47926 NULL
112425 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
112426 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
112427 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
112428 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
112429 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
112430 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
112431 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
112432 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
112433 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
112434 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
112435 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
112436 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
112437 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
112438 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
112439 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
112440 +disc_write_48070 disc_write 3 48070 NULL
112441 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
112442 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
112443 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
112444 +set_discoverable_48141 set_discoverable 4 48141 NULL
112445 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
112446 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
112447 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
112448 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
112449 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
112450 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
112451 +brcmf_sdio_chip_cm3_exitdl_48192 brcmf_sdio_chip_cm3_exitdl 4 48192 NULL
112452 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
112453 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
112454 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
112455 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
112456 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
112457 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
112458 +read_file_recv_48232 read_file_recv 3 48232 NULL
112459 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
112460 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
112461 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
112462 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
112463 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
112464 +trace_options_write_48275 trace_options_write 3 48275 NULL
112465 +send_set_info_48288 send_set_info 7 48288 NULL
112466 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
112467 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
112468 +hash_setkey_48310 hash_setkey 3 48310 NULL
112469 +audio_set_intf_req_48319 audio_set_intf_req 0 48319 NULL
112470 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
112471 +skb_add_data_48363 skb_add_data 3 48363 NULL
112472 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
112473 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
112474 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
112475 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
112476 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
112477 +print_filtered_48442 print_filtered 2-0 48442 NULL
112478 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
112479 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
112480 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
112481 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
112482 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
112483 +send_control_msg_48498 send_control_msg 6 48498 NULL
112484 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
112485 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
112486 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
112487 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
112488 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
112489 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
112490 +llog_data_len_48607 llog_data_len 1 48607 NULL
112491 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
112492 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
112493 +mtd_read_48655 mtd_read 0 48655 NULL
112494 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
112495 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
112496 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
112497 +altera_drscan_48698 altera_drscan 2 48698 NULL
112498 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
112499 +recv_msg_48709 recv_msg 4 48709 NULL
112500 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
112501 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
112502 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
112503 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
112504 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
112505 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
112506 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
112507 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
112508 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
112509 +azx_get_position_48841 azx_get_position 0 48841 NULL
112510 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
112511 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
112512 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
112513 +sptlrpc_cli_alloc_reqbuf_48855 sptlrpc_cli_alloc_reqbuf 0 48855 NULL
112514 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
112515 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
112516 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
112517 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
112518 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
112519 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
112520 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
112521 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
112522 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
112523 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
112524 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
112525 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
112526 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
112527 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
112528 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
112529 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
112530 +aic_inb_49023 aic_inb 0 49023 NULL
112531 +transient_status_49027 transient_status 4 49027 NULL
112532 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
112533 +aic7xxx_rem_scb_from_disc_list_49041 aic7xxx_rem_scb_from_disc_list 0 49041 NULL
112534 +scsi_register_49094 scsi_register 2 49094 NULL
112535 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
112536 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
112537 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
112538 +pt_read_49136 pt_read 3 49136 NULL
112539 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
112540 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
112541 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
112542 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
112543 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
112544 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
112545 +print_queue_49191 print_queue 4-0 49191 NULL
112546 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
112547 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
112548 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
112549 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
112550 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
112551 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
112552 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
112553 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
112554 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
112555 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
112556 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
112557 +uio_read_49300 uio_read 3 49300 NULL
112558 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
112559 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
112560 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
112561 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
112562 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
112563 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
112564 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
112565 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
112566 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
112567 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
112568 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
112569 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
112570 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
112571 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
112572 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
112573 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
112574 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
112575 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
112576 +smk_write_access_49561 smk_write_access 3 49561 NULL
112577 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
112578 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
112579 +ptlrpc_request_pack_49581 ptlrpc_request_pack 0 49581 NULL
112580 +readfifo_49583 readfifo 1 49583 NULL
112581 +tap_write_49595 tap_write 3 49595 NULL
112582 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
112583 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
112584 +heap_init_49617 heap_init 2 49617 NULL
112585 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
112586 +port_fops_read_49626 port_fops_read 3 49626 NULL
112587 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
112588 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
112589 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
112590 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
112591 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
112592 +write_pool_49718 write_pool 3 49718 NULL
112593 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
112594 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
112595 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
112596 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
112597 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
112598 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
112599 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
112600 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
112601 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
112602 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
112603 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
112604 +add_uuid_49831 add_uuid 4 49831 NULL
112605 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
112606 +twl4030_write_49846 twl4030_write 2 49846 NULL
112607 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
112608 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
112609 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
112610 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
112611 +ceph_get_caps_49890 ceph_get_caps 0 49890 NULL
112612 +osc_brw_49896 osc_brw 4 49896 NULL
112613 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
112614 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
112615 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
112616 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
112617 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
112618 +isdn_read_50021 isdn_read 3 50021 NULL
112619 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
112620 +ioread8_50049 ioread8 0 50049 NULL
112621 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
112622 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
112623 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
112624 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
112625 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
112626 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
112627 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
112628 +read_file_slot_50111 read_file_slot 3 50111 NULL
112629 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
112630 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
112631 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
112632 +copy_items_50140 copy_items 6 50140 NULL
112633 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
112634 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
112635 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
112636 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
112637 +odev_update_50169 odev_update 2 50169 NULL
112638 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
112639 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
112640 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
112641 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
112642 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
112643 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
112644 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
112645 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
112646 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
112647 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
112648 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
112649 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
112650 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
112651 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
112652 +do_launder_page_50329 do_launder_page 0 50329 NULL
112653 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
112654 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
112655 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
112656 +tpm_read_50344 tpm_read 3 50344 NULL
112657 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
112658 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
112659 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
112660 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
112661 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
112662 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
112663 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
112664 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
112665 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
112666 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
112667 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
112668 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
112669 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
112670 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
112671 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
112672 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
112673 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
112674 +fat_readpages_50582 fat_readpages 4 50582 NULL
112675 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
112676 +xillybus_write_50605 xillybus_write 3 50605 NULL
112677 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
112678 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
112679 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
112680 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
112681 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
112682 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
112683 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
112684 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
112685 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
112686 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
112687 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
112688 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
112689 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
112690 +tpm_write_50798 tpm_write 3 50798 NULL
112691 +write_flush_50803 write_flush 3 50803 NULL
112692 +dvb_play_50814 dvb_play 3 50814 NULL
112693 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
112694 +SetArea_50835 SetArea 4 50835 NULL
112695 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
112696 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
112697 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
112698 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
112699 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
112700 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
112701 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
112702 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
112703 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
112704 +show_device_status_50947 show_device_status 0 50947 NULL
112705 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
112706 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
112707 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
112708 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
112709 +iwl_statistics_flag_50981 iwl_statistics_flag 3-0 50981 NULL
112710 +timeout_write_50991 timeout_write 3 50991 NULL
112711 +proc_write_51003 proc_write 3 51003 NULL
112712 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
112713 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
112714 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
112715 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
112716 +dump_midi_51040 dump_midi 3 51040 NULL
112717 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
112718 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
112719 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
112720 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
112721 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
112722 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
112723 +ti_recv_51110 ti_recv 3 51110 NULL
112724 +uasp_prepare_r_request_51124 uasp_prepare_r_request 0 51124 NULL
112725 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
112726 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
112727 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
112728 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
112729 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
112730 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
112731 +drm_property_create_51239 drm_property_create 4 51239 NULL
112732 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
112733 +st_read_51251 st_read 3 51251 NULL
112734 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
112735 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
112736 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
112737 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
112738 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
112739 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
112740 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
112741 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
112742 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
112743 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
112744 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
112745 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
112746 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
112747 +ceph_sync_read_51410 ceph_sync_read 3-0 51410 NULL
112748 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
112749 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
112750 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
112751 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
112752 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
112753 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
112754 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
112755 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
112756 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
112757 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
112758 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
112759 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
112760 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
112761 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
112762 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
112763 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
112764 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
112765 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
112766 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
112767 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
112768 +sel_write_access_51704 sel_write_access 3 51704 NULL
112769 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
112770 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
112771 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
112772 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
112773 +cm4040_read_51732 cm4040_read 3 51732 NULL
112774 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
112775 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
112776 +if_write_51756 if_write 3 51756 NULL
112777 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
112778 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
112779 +ioread32_51847 ioread32 0 51847 NULL nohasharray
112780 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
112781 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
112782 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
112783 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
112784 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
112785 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
112786 +user_read_51881 user_read 3 51881 NULL
112787 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
112788 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
112789 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
112790 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
112791 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
112792 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
112793 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
112794 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
112795 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
112796 +get_zone_51981 get_zone 0-1 51981 NULL
112797 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
112798 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
112799 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
112800 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
112801 +rdmalt_52022 rdmalt 0 52022 NULL
112802 +override_release_52032 override_release 2 52032 NULL
112803 +end_port_52042 end_port 0 52042 NULL
112804 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
112805 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
112806 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
112807 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
112808 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
112809 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
112810 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
112811 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
112812 +retry_count_read_52129 retry_count_read 3 52129 NULL
112813 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
112814 +sub_alloc_52140 sub_alloc 0 52140 NULL
112815 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
112816 +htable_size_52148 htable_size 0-1 52148 NULL
112817 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
112818 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
112819 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
112820 +print_prefix_52176 print_prefix 0 52176 NULL
112821 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
112822 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
112823 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
112824 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 3 52243 &fuse_request_alloc_52243
112825 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
112826 +shrink_slab_52261 shrink_slab 2 52261 NULL
112827 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
112828 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
112829 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
112830 +read_file_reset_52310 read_file_reset 3 52310 NULL
112831 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
112832 +hwflags_read_52318 hwflags_read 3 52318 NULL
112833 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
112834 +hur_len_52339 hur_len 0 52339 NULL
112835 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
112836 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
112837 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
112838 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
112839 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
112840 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
112841 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
112842 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
112843 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
112844 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
112845 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
112846 +delay_status_52431 delay_status 5 52431 NULL
112847 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
112848 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
112849 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
112850 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
112851 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
112852 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
112853 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
112854 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
112855 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
112856 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
112857 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
112858 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
112859 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
112860 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
112861 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
112862 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
112863 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
112864 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
112865 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
112866 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
112867 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
112868 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
112869 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
112870 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
112871 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
112872 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
112873 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
112874 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
112875 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
112876 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
112877 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
112878 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
112879 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
112880 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
112881 +ext2_xattr_set_acl_52857 ext2_xattr_set_acl 4 52857 NULL
112882 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
112883 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
112884 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
112885 +twlreg_write_52880 twlreg_write 3 52880 NULL
112886 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
112887 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
112888 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
112889 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
112890 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
112891 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
112892 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
112893 +send_packet_52960 send_packet 4 52960 NULL
112894 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
112895 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
112896 +num_node_state_52989 num_node_state 0 52989 NULL
112897 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
112898 +uasp_alloc_stream_res_53015 uasp_alloc_stream_res 0 53015 NULL
112899 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
112900 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
112901 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
112902 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
112903 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
112904 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
112905 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
112906 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
112907 +verity_status_53120 verity_status 5 53120 NULL
112908 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
112909 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
112910 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
112911 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
112912 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
112913 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
112914 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
112915 +hfsplus_xattr_set_posix_acl_53249 hfsplus_xattr_set_posix_acl 4 53249 NULL
112916 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
112917 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
112918 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
112919 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
112920 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
112921 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
112922 +vm_mmap_53339 vm_mmap 0 53339 NULL
112923 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
112924 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
112925 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
112926 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
112927 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
112928 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
112929 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
112930 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL
112931 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
112932 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
112933 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
112934 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
112935 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
112936 +ocfs2_xattr_set_acl_53508 ocfs2_xattr_set_acl 4 53508 NULL
112937 +check_acl_53512 check_acl 0 53512 NULL
112938 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
112939 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
112940 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
112941 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
112942 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
112943 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
112944 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
112945 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
112946 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
112947 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
112948 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
112949 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
112950 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
112951 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
112952 +bio_integrity_split_53714 bio_integrity_split 3 53714 NULL
112953 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
112954 +wdm_write_53735 wdm_write 3 53735 NULL
112955 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
112956 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
112957 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
112958 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
112959 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
112960 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
112961 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
112962 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
112963 +setup_data_read_53822 setup_data_read 3 53822 NULL
112964 +pms_read_53873 pms_read 3 53873 NULL
112965 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
112966 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
112967 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
112968 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
112969 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
112970 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
112971 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
112972 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
112973 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
112974 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
112975 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
112976 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
112977 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
112978 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
112979 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
112980 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
112981 +_malloc_54077 _malloc 1 54077 NULL
112982 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
112983 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
112984 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
112985 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
112986 +strn_len_54122 strn_len 0 54122 NULL
112987 +isku_receive_54130 isku_receive 4 54130 NULL
112988 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
112989 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
112990 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
112991 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
112992 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
112993 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
112994 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
112995 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
112996 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
112997 +reada_add_block_54247 reada_add_block 2 54247 NULL
112998 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
112999 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
113000 +audio_write_54261 audio_write 4 54261 NULL nohasharray
113001 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
113002 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
113003 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
113004 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
113005 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
113006 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
113007 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
113008 +sprintf_54306 sprintf 0 54306 NULL
113009 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
113010 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
113011 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
113012 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
113013 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
113014 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
113015 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
113016 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
113017 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
113018 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
113019 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
113020 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
113021 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
113022 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
113023 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
113024 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
113025 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
113026 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
113027 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
113028 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
113029 +viacam_read_54526 viacam_read 3 54526 NULL
113030 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
113031 +setsockopt_54539 setsockopt 5 54539 NULL
113032 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
113033 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
113034 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
113035 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
113036 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
113037 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
113038 +port_fops_write_54627 port_fops_write 3 54627 NULL
113039 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
113040 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
113041 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
113042 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
113043 +bus_add_device_54665 bus_add_device 0 54665 NULL
113044 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
113045 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
113046 +evm_read_key_54674 evm_read_key 3 54674 NULL
113047 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
113048 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
113049 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
113050 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
113051 +kzalloc_54740 kzalloc 1 54740 NULL
113052 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
113053 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
113054 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
113055 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
113056 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
113057 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
113058 +nfsd_write_54809 nfsd_write 6 54809 NULL
113059 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
113060 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
113061 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
113062 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
113063 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
113064 +write_rio_54837 write_rio 3 54837 NULL
113065 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
113066 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
113067 +ll_layout_conf_54841 ll_layout_conf 0 54841 NULL
113068 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
113069 +printer_read_54851 printer_read 3 54851 NULL
113070 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
113071 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
113072 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
113073 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
113074 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
113075 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
113076 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
113077 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
113078 +add_port_54941 add_port 2 54941 NULL
113079 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
113080 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
113081 +c4_add_card_54968 c4_add_card 3 54968 NULL
113082 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
113083 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
113084 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
113085 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
113086 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
113087 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
113088 +read_dma_55086 read_dma 3 55086 NULL
113089 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
113090 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
113091 +filldir_55137 filldir 3 55137 NULL
113092 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
113093 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
113094 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
113095 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
113096 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
113097 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
113098 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
113099 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
113100 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
113101 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
113102 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
113103 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
113104 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
113105 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
113106 +persistent_ram_new_55286 persistent_ram_new 2-1 55286 NULL
113107 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
113108 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
113109 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
113110 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
113111 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
113112 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
113113 +vme_user_read_55338 vme_user_read 3 55338 NULL
113114 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
113115 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
113116 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
113117 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
113118 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
113119 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
113120 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
113121 +sysfs_sd_setattr_55437 sysfs_sd_setattr 0 55437 NULL
113122 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
113123 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
113124 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
113125 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
113126 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
113127 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
113128 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
113129 +ea_get_55522 ea_get 3-0 55522 NULL
113130 +buffer_size_55534 buffer_size 0 55534 NULL
113131 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
113132 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
113133 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
113134 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
113135 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
113136 +__vdev_disk_physio_55568 __vdev_disk_physio 4 55568 NULL
113137 +add_partition_55588 add_partition 2 55588 NULL
113138 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
113139 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL nohasharray
113140 +config_buf_55602 config_buf 0 55602 &SyS_keyctl_55602
113141 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
113142 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
113143 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
113144 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
113145 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
113146 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
113147 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
113148 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
113149 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
113150 +get_info_55681 get_info 3 55681 NULL
113151 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
113152 +echo_big_lmm_get_55690 echo_big_lmm_get 0 55690 NULL
113153 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
113154 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
113155 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
113156 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
113157 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
113158 +set_local_name_55757 set_local_name 4 55757 NULL
113159 +strlen_55778 strlen 0 55778 NULL
113160 +set_spte_55783 set_spte 4-5 55783 NULL
113161 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
113162 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
113163 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
113164 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
113165 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
113166 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
113167 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
113168 +hsc_write_55875 hsc_write 3 55875 NULL
113169 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
113170 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
113171 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
113172 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
113173 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
113174 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
113175 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
113176 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
113177 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
113178 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
113179 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
113180 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
113181 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
113182 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
113183 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
113184 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
113185 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
113186 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
113187 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
113188 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
113189 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
113190 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
113191 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
113192 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
113193 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
113194 +fd_copyin_56247 fd_copyin 3 56247 NULL
113195 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
113196 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
113197 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
113198 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
113199 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
113200 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
113201 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
113202 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
113203 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
113204 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
113205 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
113206 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
113207 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
113208 +dev_read_56369 dev_read 3 56369 NULL
113209 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
113210 +write_gssp_56404 write_gssp 3 56404 NULL
113211 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
113212 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
113213 +store_msg_56417 store_msg 3 56417 NULL
113214 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
113215 +fl_create_56435 fl_create 5 56435 NULL
113216 +gnttab_map_56439 gnttab_map 2 56439 NULL
113217 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
113218 +set_connectable_56458 set_connectable 4 56458 NULL
113219 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
113220 +putused_user_56467 putused_user 3 56467 NULL
113221 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
113222 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
113223 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
113224 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
113225 +init_map_ip_56508 init_map_ip 5 56508 NULL
113226 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
113227 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
113228 +ip_options_get_56538 ip_options_get 4 56538 NULL
113229 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
113230 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
113231 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
113232 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
113233 +event_filter_write_56609 event_filter_write 3 56609 NULL
113234 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
113235 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
113236 +gather_array_56641 gather_array 3 56641 NULL
113237 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
113238 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
113239 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
113240 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
113241 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
113242 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
113243 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
113244 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
113245 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
113246 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
113247 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
113248 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
113249 +do_syslog_56807 do_syslog 3 56807 NULL
113250 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
113251 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
113252 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
113253 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
113254 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
113255 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
113256 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
113257 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
113258 +hfsplus_setxattr_56902 hfsplus_setxattr 4 56902 NULL
113259 +strcspn_56913 strcspn 0 56913 NULL
113260 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
113261 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
113262 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
113263 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
113264 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
113265 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
113266 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
113267 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
113268 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
113269 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
113270 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
113271 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
113272 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
113273 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
113274 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
113275 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
113276 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
113277 +altera_get_note_57099 altera_get_note 6 57099 NULL
113278 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
113279 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
113280 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
113281 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
113282 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
113283 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
113284 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
113285 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
113286 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
113287 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
113288 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
113289 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
113290 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
113291 +dma_fifo_alloc_57236 dma_fifo_alloc 5-3-2 57236 NULL
113292 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
113293 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
113294 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
113295 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
113296 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
113297 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
113298 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
113299 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
113300 +write_file_regval_57313 write_file_regval 3 57313 NULL
113301 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
113302 +usblp_read_57342 usblp_read 3 57342 NULL
113303 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
113304 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
113305 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
113306 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
113307 +read_file_blob_57406 read_file_blob 3 57406 NULL
113308 +enclosure_register_57412 enclosure_register 3 57412 NULL
113309 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
113310 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
113311 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
113312 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
113313 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
113314 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
113315 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
113316 +skb_headlen_57501 skb_headlen 0 57501 NULL
113317 +copy_in_user_57502 copy_in_user 3 57502 NULL
113318 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
113319 +init_tag_map_57515 init_tag_map 3 57515 NULL
113320 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
113321 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
113322 +cmm_read_57520 cmm_read 3 57520 NULL
113323 +inode_permission_57531 inode_permission 0 57531 NULL
113324 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
113325 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
113326 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
113327 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
113328 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
113329 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
113330 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
113331 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
113332 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
113333 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
113334 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
113335 +mem_read_57631 mem_read 3 57631 NULL
113336 +r3964_write_57662 r3964_write 4 57662 NULL
113337 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
113338 +__lgwrite_57669 __lgwrite 4 57669 NULL
113339 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
113340 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
113341 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
113342 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
113343 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
113344 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
113345 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
113346 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
113347 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
113348 +ld2_57794 ld2 0 57794 NULL
113349 +ivtv_read_57796 ivtv_read 3 57796 NULL
113350 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
113351 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
113352 +flash_read_57843 flash_read 3 57843 NULL
113353 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
113354 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
113355 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
113356 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
113357 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
113358 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
113359 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
113360 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
113361 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
113362 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
113363 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
113364 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
113365 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
113366 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
113367 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
113368 +mce_async_out_58056 mce_async_out 3 58056 NULL
113369 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
113370 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
113371 +cm4040_write_58079 cm4040_write 3 58079 NULL
113372 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
113373 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
113374 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
113375 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
113376 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
113377 +read_file_debug_58256 read_file_debug 3 58256 NULL
113378 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
113379 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
113380 +profile_load_58267 profile_load 3 58267 NULL
113381 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
113382 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
113383 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
113384 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
113385 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
113386 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
113387 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
113388 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
113389 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
113390 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
113391 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
113392 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
113393 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
113394 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
113395 +capabilities_read_58457 capabilities_read 3 58457 NULL
113396 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
113397 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
113398 +nv_rd08_58472 nv_rd08 0 58472 NULL
113399 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
113400 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
113401 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
113402 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
113403 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
113404 +ldlm_srv_pool_shrink_58554 ldlm_srv_pool_shrink 0 58554 NULL
113405 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
113406 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
113407 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
113408 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
113409 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
113410 +xip_file_read_58592 xip_file_read 3 58592 NULL
113411 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
113412 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
113413 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
113414 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
113415 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
113416 +find_zero_58685 find_zero 0-1 58685 NULL
113417 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
113418 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
113419 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
113420 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
113421 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
113422 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
113423 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
113424 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
113425 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
113426 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
113427 +ep_read_58813 ep_read 3 58813 NULL
113428 +command_write_58841 command_write 3 58841 NULL
113429 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
113430 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
113431 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
113432 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
113433 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
113434 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
113435 +sptlrpc_import_sec_adapt_58948 sptlrpc_import_sec_adapt 0 58948 NULL
113436 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
113437 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
113438 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
113439 +init_list_set_59005 init_list_set 3 59005 NULL
113440 +ep_write_59008 ep_write 3 59008 NULL
113441 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
113442 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
113443 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
113444 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
113445 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
113446 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
113447 +sysfs_link_sibling_59078 sysfs_link_sibling 0 59078 NULL
113448 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
113449 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL
113450 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
113451 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
113452 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
113453 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
113454 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
113455 +md_getxattr_59161 md_getxattr 0 59161 NULL
113456 +ksize_59176 ksize 0 59176 NULL
113457 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
113458 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
113459 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
113460 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
113461 +dt3155_read_59226 dt3155_read 3 59226 NULL
113462 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
113463 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
113464 +nla_len_59258 nla_len 0 59258 NULL
113465 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
113466 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
113467 +fd_copyout_59323 fd_copyout 3 59323 NULL
113468 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
113469 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
113470 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
113471 +__map_request_59350 __map_request 0 59350 NULL
113472 +f2fs_fallocate_59377 f2fs_fallocate 3-4 59377 NULL
113473 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
113474 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
113475 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
113476 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
113477 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
113478 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
113479 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
113480 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
113481 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
113482 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
113483 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
113484 +tunables_write_59563 tunables_write 3 59563 NULL
113485 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
113486 +write_pbl_59583 write_pbl 4 59583 NULL
113487 +memdup_user_59590 memdup_user 2 59590 NULL
113488 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
113489 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
113490 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
113491 +mtrr_write_59622 mtrr_write 3 59622 NULL
113492 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
113493 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
113494 +hidraw_read_59650 hidraw_read 3 59650 NULL
113495 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
113496 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
113497 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
113498 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
113499 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
113500 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
113501 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
113502 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
113503 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
113504 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
113505 +strnlen_59746 strnlen 0 59746 NULL
113506 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
113507 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
113508 +venus_remove_59781 venus_remove 4 59781 NULL
113509 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
113510 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
113511 +ipw_write_59807 ipw_write 3 59807 NULL
113512 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
113513 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
113514 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
113515 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
113516 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
113517 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
113518 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
113519 +ocfs2_extend_rotate_transaction_59894 ocfs2_extend_rotate_transaction 2-3 59894 NULL
113520 +aic7xxx_abort_waiting_scb_59932 aic7xxx_abort_waiting_scb 0 59932 NULL
113521 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
113522 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
113523 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
113524 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
113525 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
113526 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
113527 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
113528 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
113529 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
113530 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
113531 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
113532 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
113533 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
113534 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
113535 +vcs_size_60050 vcs_size 0 60050 NULL
113536 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
113537 +compat_writev_60063 compat_writev 3 60063 NULL
113538 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
113539 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
113540 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
113541 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
113542 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
113543 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
113544 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
113545 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
113546 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
113547 +init_state_60165 init_state 2 60165 NULL
113548 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
113549 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
113550 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
113551 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
113552 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
113553 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
113554 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
113555 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
113556 +printer_write_60276 printer_write 3 60276 NULL
113557 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
113558 +getDataLength_60301 getDataLength 0 60301 NULL
113559 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
113560 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
113561 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
113562 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
113563 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
113564 +driver_names_read_60399 driver_names_read 3 60399 NULL
113565 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
113566 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
113567 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
113568 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
113569 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
113570 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
113571 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
113572 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
113573 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
113574 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
113575 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
113576 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
113577 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
113578 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
113579 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
113580 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
113581 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
113582 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
113583 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
113584 +raid_status_60755 raid_status 5 60755 NULL
113585 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
113586 +opticon_write_60775 opticon_write 4 60775 NULL
113587 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
113588 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
113589 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
113590 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
113591 +generic_writepages_60871 generic_writepages 0 60871 NULL
113592 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
113593 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
113594 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
113595 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
113596 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
113597 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
113598 +pti_char_write_60960 pti_char_write 3 60960 NULL
113599 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
113600 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
113601 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
113602 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
113603 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
113604 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
113605 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
113606 +symtab_init_61050 symtab_init 2 61050 NULL
113607 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
113608 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
113609 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
113610 +get_derived_key_61100 get_derived_key 4 61100 NULL
113611 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-1-2-3-4 61104 NULL
113612 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
113613 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
113614 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
113615 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
113616 +brcmf_sdio_chip_cr4_exitdl_61143 brcmf_sdio_chip_cr4_exitdl 4 61143 NULL
113617 +osl_malloc_61156 osl_malloc 2 61156 NULL
113618 +pair_device_61175 pair_device 4 61175 NULL nohasharray
113619 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
113620 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
113621 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
113622 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
113623 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
113624 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
113625 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
113626 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
113627 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
113628 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
113629 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
113630 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
113631 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
113632 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
113633 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
113634 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
113635 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
113636 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
113637 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
113638 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
113639 +system_enable_write_61396 system_enable_write 3 61396 NULL
113640 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
113641 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
113642 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
113643 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
113644 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
113645 +erst_errno_61526 erst_errno 0 61526 NULL
113646 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
113647 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
113648 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
113649 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
113650 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
113651 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
113652 +seq_open_private_61589 seq_open_private 3 61589 NULL
113653 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
113654 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
113655 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
113656 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
113657 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
113658 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
113659 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL
113660 +resize_stripes_61650 resize_stripes 2 61650 NULL
113661 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
113662 +insert_one_name_61668 insert_one_name 7 61668 NULL
113663 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
113664 +lock_loop_61681 lock_loop 1 61681 NULL
113665 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
113666 +filter_read_61692 filter_read 3 61692 NULL
113667 +iov_length_61716 iov_length 0 61716 NULL
113668 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
113669 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
113670 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
113671 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
113672 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
113673 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
113674 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
113675 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
113676 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
113677 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
113678 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
113679 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
113680 +get_fw_name_61874 get_fw_name 3 61874 NULL
113681 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
113682 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
113683 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
113684 +clear_refs_write_61904 clear_refs_write 3 61904 NULL nohasharray
113685 +import_sec_check_expire_61904 import_sec_check_expire 0 61904 &clear_refs_write_61904
113686 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
113687 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
113688 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
113689 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
113690 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
113691 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
113692 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
113693 +fix_read_error_61965 fix_read_error 4 61965 NULL
113694 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
113695 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
113696 +cow_file_range_61979 cow_file_range 3 61979 NULL
113697 +dequeue_event_62000 dequeue_event 3 62000 NULL
113698 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
113699 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
113700 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
113701 +SYSC_select_62024 SYSC_select 1 62024 NULL
113702 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
113703 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
113704 +do_pselect_62061 do_pselect 1 62061 NULL
113705 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
113706 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
113707 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
113708 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
113709 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
113710 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
113711 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
113712 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
113713 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
113714 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
113715 +video_usercopy_62151 video_usercopy 2 62151 NULL
113716 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
113717 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
113718 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
113719 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
113720 +btrfs_xattr_acl_set_62203 btrfs_xattr_acl_set 4 62203 NULL
113721 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
113722 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
113723 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
113724 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
113725 +get_random_int_62279 get_random_int 0 62279 NULL
113726 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
113727 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
113728 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
113729 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
113730 +ocfs2_xattr_buckets_per_cluster_62330 ocfs2_xattr_buckets_per_cluster 0 62330 NULL
113731 +subseq_list_62332 subseq_list 3-0 62332 NULL
113732 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
113733 +flash_write_62354 flash_write 3 62354 NULL
113734 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
113735 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
113736 +altera_irscan_62396 altera_irscan 2 62396 NULL
113737 +set_ssp_62411 set_ssp 4 62411 NULL
113738 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
113739 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
113740 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
113741 +debugfs_read_62535 debugfs_read 3 62535 NULL
113742 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
113743 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
113744 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
113745 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
113746 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
113747 +get_subdir_62581 get_subdir 3 62581 NULL
113748 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
113749 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
113750 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
113751 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
113752 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
113753 +ocfs2_wait_for_mask_interruptible_62675 ocfs2_wait_for_mask_interruptible 0 62675 NULL
113754 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
113755 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
113756 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
113757 +rdm_62719 rdm 0 62719 NULL
113758 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
113759 +key_replays_read_62746 key_replays_read 3 62746 NULL
113760 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
113761 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
113762 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
113763 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
113764 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
113765 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
113766 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
113767 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
113768 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
113769 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
113770 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
113771 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
113772 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
113773 +aoechr_write_62883 aoechr_write 3 62883 NULL
113774 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
113775 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
113776 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
113777 +getdqbuf_62908 getdqbuf 1 62908 NULL
113778 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
113779 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
113780 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
113781 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
113782 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
113783 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
113784 +unlink1_63059 unlink1 3 63059 NULL
113785 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
113786 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
113787 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
113788 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
113789 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
113790 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
113791 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
113792 +vme_master_read_63221 vme_master_read 0 63221 NULL
113793 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
113794 +ptp_read_63251 ptp_read 4 63251 NULL
113795 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
113796 +raid5_resize_63306 raid5_resize 2 63306 NULL
113797 +proc_info_read_63344 proc_info_read 3 63344 NULL
113798 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
113799 +idmouse_read_63374 idmouse_read 3 63374 NULL
113800 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
113801 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
113802 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
113803 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
113804 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
113805 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
113806 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
113807 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
113808 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
113809 +read_kcore_63488 read_kcore 3 63488 NULL
113810 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
113811 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
113812 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
113813 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
113814 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
113815 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
113816 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
113817 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
113818 +write_debug_level_63613 write_debug_level 3 63613 NULL
113819 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
113820 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
113821 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
113822 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
113823 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
113824 +vbi_read_63673 vbi_read 3 63673 NULL
113825 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
113826 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
113827 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
113828 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
113829 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
113830 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
113831 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
113832 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
113833 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
113834 +prepare_copy_63826 prepare_copy 2 63826 NULL
113835 +sel_write_load_63830 sel_write_load 3 63830 NULL
113836 +ll_readlink_63836 ll_readlink 3 63836 NULL
113837 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
113838 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
113839 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
113840 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
113841 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
113842 +__team_options_register_63941 __team_options_register 3 63941 NULL
113843 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
113844 +sysfs_add_one_63969 sysfs_add_one 0 63969 NULL
113845 +set_bredr_63975 set_bredr 4 63975 NULL
113846 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
113847 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
113848 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
113849 +hfsplus_security_setxattr_64009 hfsplus_security_setxattr 4 64009 NULL
113850 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
113851 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
113852 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
113853 +get_u8_64076 get_u8 0 64076 NULL
113854 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
113855 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
113856 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
113857 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
113858 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
113859 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
113860 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
113861 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
113862 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
113863 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
113864 +init_bch_64130 init_bch 1-2 64130 NULL
113865 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
113866 +read_div_64147 read_div 0 64147 NULL
113867 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
113868 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
113869 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
113870 +read_pulse_64227 read_pulse 0-3 64227 NULL
113871 +ea_len_64229 ea_len 0 64229 NULL
113872 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
113873 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
113874 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
113875 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
113876 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
113877 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
113878 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
113879 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
113880 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
113881 +ts_write_64336 ts_write 3 64336 NULL
113882 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
113883 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
113884 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
113885 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
113886 +reg_create_64372 reg_create 5 64372 NULL
113887 +ilo_write_64378 ilo_write 3 64378 NULL
113888 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
113889 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
113890 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
113891 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
113892 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
113893 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
113894 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
113895 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
113896 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
113897 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
113898 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
113899 +single_open_size_64483 single_open_size 4 64483 NULL
113900 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
113901 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
113902 +remove_uuid_64505 remove_uuid 4 64505 NULL
113903 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
113904 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
113905 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
113906 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
113907 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
113908 +SyS_bind_64544 SyS_bind 3 64544 NULL
113909 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
113910 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
113911 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
113912 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
113913 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
113914 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
113915 +do_erase_64574 do_erase 4 64574 NULL
113916 +fanotify_write_64623 fanotify_write 3 64623 NULL
113917 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
113918 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
113919 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
113920 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
113921 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
113922 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
113923 +sec_bulk_write_64691 sec_bulk_write 2-3 64691 NULL
113924 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
113925 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
113926 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
113927 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
113928 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
113929 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
113930 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
113931 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
113932 +message_for_md_64777 message_for_md 5 64777 NULL
113933 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
113934 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
113935 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
113936 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
113937 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
113938 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
113939 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
113940 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
113941 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
113942 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
113943 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
113944 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
113945 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
113946 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
113947 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
113948 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
113949 +insert_dent_65034 insert_dent 7 65034 NULL
113950 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
113951 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
113952 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
113953 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
113954 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
113955 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
113956 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
113957 +uasp_alloc_cmd_65097 uasp_alloc_cmd 0 65097 NULL
113958 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
113959 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
113960 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
113961 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
113962 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
113963 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
113964 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
113965 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
113966 +get_var_len_65304 get_var_len 0 65304 NULL
113967 +unpack_array_65318 unpack_array 0 65318 NULL
113968 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
113969 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
113970 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
113971 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
113972 +SyS_writev_65372 SyS_writev 3 65372 NULL
113973 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
113974 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
113975 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
113976 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
113977 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
113978 +device_add_groups_65423 device_add_groups 0 65423 NULL
113979 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
113980 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
113981 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
113982 +clear_user_65470 clear_user 2 65470 NULL
113983 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
113984 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
113985 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
113986 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
113987 new file mode 100644
113988 index 0000000..fa0524c
113989 --- /dev/null
113990 +++ b/tools/gcc/size_overflow_plugin.c
113991 @@ -0,0 +1,4101 @@
113992 +/*
113993 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113994 + * Licensed under the GPL v2, or (at your option) v3
113995 + *
113996 + * Homepage:
113997 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113998 + *
113999 + * Documentation:
114000 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114001 + *
114002 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114003 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114004 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114005 + *
114006 + * Usage:
114007 + * $ # for 4.5/4.6/C based 4.7
114008 + * $ 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
114009 + * $ # for C++ based 4.7/4.8+
114010 + * $ 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
114011 + *
114012 + * $ gcc -fplugin=./size_overflow_plugin.so test.c -O2
114013 + */
114014 +
114015 +#include "gcc-common.h"
114016 +
114017 +int plugin_is_GPL_compatible;
114018 +
114019 +static struct plugin_info size_overflow_plugin_info = {
114020 + .version = "20140317",
114021 + .help = "no-size-overflow\tturn off size overflow checking\n",
114022 +};
114023 +
114024 +#define BEFORE_STMT true
114025 +#define AFTER_STMT false
114026 +#define CREATE_NEW_VAR NULL_TREE
114027 +#define CODES_LIMIT 32
114028 +#define MAX_PARAM 31
114029 +#define VEC_LEN 128
114030 +#define RET_CHECK NULL_TREE
114031 +#define CANNOT_FIND_ARG 32
114032 +#define WRONG_NODE 32
114033 +#define NOT_INTENTIONAL_ASM NULL
114034 +#define MIN_CHECK true
114035 +#define MAX_CHECK false
114036 +
114037 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114038 +#define YES_ASM_STR "# size_overflow MARK_YES "
114039 +#define OK_ASM_STR "# size_overflow "
114040 +
114041 +struct size_overflow_hash {
114042 + const struct size_overflow_hash * const next;
114043 + const char * const name;
114044 + const unsigned int param;
114045 +};
114046 +
114047 +#include "size_overflow_hash.h"
114048 +
114049 +enum mark {
114050 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114051 +};
114052 +
114053 +static unsigned int call_count;
114054 +
114055 +enum stmt_flags {
114056 + MY_STMT, NO_CAST_CHECK, VISITED_STMT, NO_FLAGS
114057 +};
114058 +
114059 +struct visited {
114060 + struct visited *next;
114061 + const_tree fndecl;
114062 + unsigned int num;
114063 +};
114064 +
114065 +struct next_cgraph_node {
114066 + struct next_cgraph_node *next;
114067 + struct cgraph_node *current_function;
114068 + tree callee_fndecl;
114069 + unsigned int num;
114070 +};
114071 +
114072 +struct interesting_node {
114073 + struct interesting_node *next;
114074 + gimple first_stmt;
114075 + const_tree fndecl;
114076 + tree node;
114077 +#if BUILDING_GCC_VERSION <= 4007
114078 + VEC(tree, gc) *last_nodes;
114079 +#else
114080 + vec<tree, va_gc> *last_nodes;
114081 +#endif
114082 + unsigned int num;
114083 + enum mark intentional_attr_decl;
114084 + enum mark intentional_attr_cur_fndecl;
114085 + gimple intentional_mark_from_gimple;
114086 +};
114087 +
114088 +static tree report_size_overflow_decl;
114089 +
114090 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
114091 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
114092 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
114093 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114094 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114095 +
114096 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114097 +static tree get_size_overflow_type(gimple stmt, const_tree node);
114098 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114099 +
114100 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114101 +{
114102 + unsigned int arg_count;
114103 + enum tree_code code = TREE_CODE(*node);
114104 +
114105 + switch (code) {
114106 + case FUNCTION_DECL:
114107 + arg_count = type_num_arguments(TREE_TYPE(*node));
114108 + break;
114109 + case FUNCTION_TYPE:
114110 + case METHOD_TYPE:
114111 + arg_count = type_num_arguments(*node);
114112 + break;
114113 + default:
114114 + *no_add_attrs = true;
114115 + error("%s: %qE attribute only applies to functions", __func__, name);
114116 + return NULL_TREE;
114117 + }
114118 +
114119 + for (; args; args = TREE_CHAIN(args)) {
114120 + tree position = TREE_VALUE(args);
114121 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114122 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114123 + *no_add_attrs = true;
114124 + }
114125 + }
114126 + return NULL_TREE;
114127 +}
114128 +
114129 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114130 +{
114131 + unsigned int arg_count;
114132 + enum tree_code code = TREE_CODE(*node);
114133 +
114134 + switch (code) {
114135 + case FUNCTION_DECL:
114136 + arg_count = type_num_arguments(TREE_TYPE(*node));
114137 + break;
114138 + case FUNCTION_TYPE:
114139 + case METHOD_TYPE:
114140 + arg_count = type_num_arguments(*node);
114141 + break;
114142 + case FIELD_DECL:
114143 + return NULL_TREE;
114144 + default:
114145 + *no_add_attrs = true;
114146 + error("%qE attribute only applies to functions", name);
114147 + return NULL_TREE;
114148 + }
114149 +
114150 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
114151 + return NULL_TREE;
114152 +
114153 + for (; args; args = TREE_CHAIN(args)) {
114154 + tree position = TREE_VALUE(args);
114155 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114156 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114157 + *no_add_attrs = true;
114158 + }
114159 + }
114160 + return NULL_TREE;
114161 +}
114162 +
114163 +static struct attribute_spec size_overflow_attr = {
114164 + .name = "size_overflow",
114165 + .min_length = 1,
114166 + .max_length = -1,
114167 + .decl_required = true,
114168 + .type_required = false,
114169 + .function_type_required = false,
114170 + .handler = handle_size_overflow_attribute,
114171 +#if BUILDING_GCC_VERSION >= 4007
114172 + .affects_type_identity = false
114173 +#endif
114174 +};
114175 +
114176 +static struct attribute_spec intentional_overflow_attr = {
114177 + .name = "intentional_overflow",
114178 + .min_length = 1,
114179 + .max_length = -1,
114180 + .decl_required = true,
114181 + .type_required = false,
114182 + .function_type_required = false,
114183 + .handler = handle_intentional_overflow_attribute,
114184 +#if BUILDING_GCC_VERSION >= 4007
114185 + .affects_type_identity = false
114186 +#endif
114187 +};
114188 +
114189 +static void register_attributes(void __unused *event_data, void __unused *data)
114190 +{
114191 + register_attribute(&size_overflow_attr);
114192 + register_attribute(&intentional_overflow_attr);
114193 +}
114194 +
114195 +static enum stmt_flags get_stmt_flag(gimple stmt)
114196 +{
114197 + bool bit_1, bit_2;
114198 +
114199 + bit_1 = gimple_plf(stmt, GF_PLF_1);
114200 + bit_2 = gimple_plf(stmt, GF_PLF_2);
114201 +
114202 + if (!bit_1 && !bit_2)
114203 + return NO_FLAGS;
114204 + if (bit_1 && bit_2)
114205 + return MY_STMT;
114206 + if (!bit_1 && bit_2)
114207 + return VISITED_STMT;
114208 + return NO_CAST_CHECK;
114209 +}
114210 +
114211 +static void set_stmt_flag(gimple stmt, enum stmt_flags new_flag)
114212 +{
114213 + bool bit_1, bit_2;
114214 +
114215 + switch (new_flag) {
114216 + case NO_FLAGS:
114217 + bit_1 = bit_2 = false;
114218 + break;
114219 + case MY_STMT:
114220 + bit_1 = bit_2 = true;
114221 + break;
114222 + case VISITED_STMT:
114223 + bit_1 = false;
114224 + bit_2 = true;
114225 + break;
114226 + case NO_CAST_CHECK:
114227 + bit_1 = true;
114228 + bit_2 = false;
114229 + break;
114230 + default:
114231 + gcc_unreachable();
114232 + }
114233 +
114234 + gimple_set_plf(stmt, GF_PLF_1, bit_1);
114235 + gimple_set_plf(stmt, GF_PLF_2, bit_2);
114236 +}
114237 +
114238 +static bool is_bool(const_tree node)
114239 +{
114240 + const_tree type;
114241 +
114242 + if (node == NULL_TREE)
114243 + return false;
114244 +
114245 + type = TREE_TYPE(node);
114246 + if (!INTEGRAL_TYPE_P(type))
114247 + return false;
114248 + if (TREE_CODE(type) == BOOLEAN_TYPE)
114249 + return true;
114250 + if (TYPE_PRECISION(type) == 1)
114251 + return true;
114252 + return false;
114253 +}
114254 +
114255 +static bool skip_types(const_tree var)
114256 +{
114257 + tree type;
114258 + enum tree_code code;
114259 +
114260 + if (is_gimple_constant(var))
114261 + return true;
114262 +
114263 + switch (TREE_CODE(var)) {
114264 + case ADDR_EXPR:
114265 +#if BUILDING_GCC_VERSION >= 4006
114266 + case MEM_REF:
114267 +#endif
114268 + case ARRAY_REF:
114269 + case BIT_FIELD_REF:
114270 + case INDIRECT_REF:
114271 + case TARGET_MEM_REF:
114272 + case COMPONENT_REF:
114273 + case VAR_DECL:
114274 + case VIEW_CONVERT_EXPR:
114275 + return true;
114276 + default:
114277 + break;
114278 + }
114279 +
114280 + code = TREE_CODE(var);
114281 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
114282 +
114283 + type = TREE_TYPE(var);
114284 + switch (TREE_CODE(type)) {
114285 + case INTEGER_TYPE:
114286 + case ENUMERAL_TYPE:
114287 + return false;
114288 + case BOOLEAN_TYPE:
114289 + return is_bool(var);
114290 + default:
114291 + return true;
114292 + }
114293 +}
114294 +
114295 +static inline gimple get_def_stmt(const_tree node)
114296 +{
114297 + gcc_assert(node != NULL_TREE);
114298 +
114299 + if (skip_types(node))
114300 + return NULL;
114301 +
114302 + if (TREE_CODE(node) != SSA_NAME)
114303 + return NULL;
114304 + return SSA_NAME_DEF_STMT(node);
114305 +}
114306 +
114307 +static unsigned char get_tree_code(const_tree type)
114308 +{
114309 + switch (TREE_CODE(type)) {
114310 + case ARRAY_TYPE:
114311 + return 0;
114312 + case BOOLEAN_TYPE:
114313 + return 1;
114314 + case ENUMERAL_TYPE:
114315 + return 2;
114316 + case FUNCTION_TYPE:
114317 + return 3;
114318 + case INTEGER_TYPE:
114319 + return 4;
114320 + case POINTER_TYPE:
114321 + return 5;
114322 + case RECORD_TYPE:
114323 + return 6;
114324 + case UNION_TYPE:
114325 + return 7;
114326 + case VOID_TYPE:
114327 + return 8;
114328 + case REAL_TYPE:
114329 + return 9;
114330 + case VECTOR_TYPE:
114331 + return 10;
114332 + case REFERENCE_TYPE:
114333 + return 11;
114334 + case OFFSET_TYPE:
114335 + return 12;
114336 + case COMPLEX_TYPE:
114337 + return 13;
114338 + default:
114339 + debug_tree((tree)type);
114340 + gcc_unreachable();
114341 + }
114342 +}
114343 +
114344 +struct function_hash {
114345 + size_t tree_codes_len;
114346 + unsigned char tree_codes[CODES_LIMIT];
114347 + const_tree fndecl;
114348 + unsigned int hash;
114349 +};
114350 +
114351 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
114352 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
114353 +{
114354 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
114355 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
114356 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
114357 +
114358 + unsigned int m = 0x57559429;
114359 + unsigned int n = 0x5052acdb;
114360 + const unsigned int *key4 = (const unsigned int *)key;
114361 + unsigned int h = len;
114362 + unsigned int k = len + seed + n;
114363 + unsigned long long p;
114364 +
114365 + while (len >= 8) {
114366 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
114367 + len -= 8;
114368 + }
114369 + if (len >= 4) {
114370 + cwmixb(key4[0]) key4 += 1;
114371 + len -= 4;
114372 + }
114373 + if (len)
114374 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
114375 + cwmixb(h ^ (k + n));
114376 + return k ^ h;
114377 +
114378 +#undef cwfold
114379 +#undef cwmixa
114380 +#undef cwmixb
114381 +}
114382 +
114383 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
114384 +{
114385 + unsigned int fn, codes, seed = 0;
114386 +
114387 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
114388 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
114389 +
114390 + fn_hash_data->hash = fn ^ codes;
114391 +}
114392 +
114393 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
114394 +{
114395 + gcc_assert(type != NULL_TREE);
114396 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
114397 +
114398 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
114399 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
114400 + fn_hash_data->tree_codes_len++;
114401 + type = TREE_TYPE(type);
114402 + }
114403 +}
114404 +
114405 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
114406 +{
114407 + const_tree result;
114408 +
114409 + gcc_assert(node != NULL_TREE);
114410 +
114411 + if (DECL_P(node)) {
114412 + result = DECL_RESULT(node);
114413 + if (result != NULL_TREE)
114414 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
114415 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
114416 + }
114417 +
114418 + gcc_assert(TYPE_P(node));
114419 +
114420 + if (TREE_CODE(node) == FUNCTION_TYPE)
114421 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
114422 +
114423 + return set_node_codes(node, fn_hash_data);
114424 +}
114425 +
114426 +static void set_function_codes(struct function_hash *fn_hash_data)
114427 +{
114428 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
114429 + enum tree_code code = TREE_CODE(type);
114430 +
114431 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
114432 +
114433 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
114434 +
114435 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
114436 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
114437 +}
114438 +
114439 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
114440 +{
114441 + const struct size_overflow_hash *entry;
114442 + struct function_hash fn_hash_data;
114443 + const char *func_name;
114444 +
114445 + // skip builtins __builtin_constant_p
114446 + if (DECL_BUILT_IN(fndecl))
114447 + return NULL;
114448 +
114449 + fn_hash_data.fndecl = fndecl;
114450 + fn_hash_data.tree_codes_len = 0;
114451 +
114452 + set_function_codes(&fn_hash_data);
114453 + gcc_assert(fn_hash_data.tree_codes_len != 0);
114454 +
114455 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
114456 + set_hash(func_name, &fn_hash_data);
114457 +
114458 + entry = size_overflow_hash[fn_hash_data.hash];
114459 +
114460 + while (entry) {
114461 + if (!strcmp(entry->name, func_name))
114462 + return entry;
114463 + entry = entry->next;
114464 + }
114465 + return NULL;
114466 +}
114467 +
114468 +static void print_missing_msg(const_tree func, unsigned int argnum)
114469 +{
114470 + location_t loc;
114471 + const char *curfunc;
114472 + struct function_hash fn_hash_data;
114473 +
114474 + fn_hash_data.fndecl = DECL_ORIGIN(func);
114475 + fn_hash_data.tree_codes_len = 0;
114476 +
114477 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
114478 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
114479 +
114480 + set_function_codes(&fn_hash_data);
114481 + set_hash(curfunc, &fn_hash_data);
114482 +
114483 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
114484 +}
114485 +
114486 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
114487 +{
114488 + tree var;
114489 + unsigned int argnum = 1;
114490 +
114491 + if (TREE_CODE(arg) == SSA_NAME)
114492 + arg = SSA_NAME_VAR(arg);
114493 +
114494 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
114495 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
114496 + continue;
114497 + if (!skip_types(var))
114498 + return argnum;
114499 + }
114500 +
114501 + return CANNOT_FIND_ARG;
114502 +}
114503 +
114504 +static tree create_new_var(tree type)
114505 +{
114506 + tree new_var = create_tmp_var(type, "cicus");
114507 +
114508 + add_referenced_var(new_var);
114509 + return new_var;
114510 +}
114511 +
114512 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
114513 +{
114514 + gimple assign;
114515 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114516 + tree type = TREE_TYPE(rhs1);
114517 + tree lhs = create_new_var(type);
114518 +
114519 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
114520 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
114521 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
114522 +
114523 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114524 + update_stmt(assign);
114525 + set_stmt_flag(assign, MY_STMT);
114526 + return assign;
114527 +}
114528 +
114529 +static tree cast_a_tree(tree type, tree var)
114530 +{
114531 + gcc_assert(type != NULL_TREE);
114532 + gcc_assert(var != NULL_TREE);
114533 + gcc_assert(fold_convertible_p(type, var));
114534 +
114535 + return fold_convert(type, var);
114536 +}
114537 +
114538 +static tree get_lhs(const_gimple stmt)
114539 +{
114540 + switch (gimple_code(stmt)) {
114541 + case GIMPLE_ASSIGN:
114542 + case GIMPLE_CALL:
114543 + return gimple_get_lhs(stmt);
114544 + case GIMPLE_PHI:
114545 + return gimple_phi_result(stmt);
114546 + default:
114547 + return NULL_TREE;
114548 + }
114549 +}
114550 +
114551 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
114552 +{
114553 + const_gimple def_stmt = get_def_stmt(rhs);
114554 +
114555 + if (force)
114556 + return false;
114557 +
114558 + if (is_gimple_constant(rhs))
114559 + return false;
114560 +
114561 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114562 + return false;
114563 +
114564 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
114565 + return false;
114566 +
114567 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
114568 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114569 + return false;
114570 +
114571 + return true;
114572 +}
114573 +
114574 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
114575 +{
114576 + gimple assign, def_stmt;
114577 +
114578 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
114579 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
114580 + gcc_unreachable();
114581 +
114582 + def_stmt = get_def_stmt(rhs);
114583 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && get_stmt_flag(def_stmt) == MY_STMT)
114584 + return def_stmt;
114585 +
114586 + if (lhs == CREATE_NEW_VAR)
114587 + lhs = create_new_var(dst_type);
114588 +
114589 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
114590 +
114591 + if (!gsi_end_p(*gsi)) {
114592 + location_t loc = gimple_location(gsi_stmt(*gsi));
114593 + gimple_set_location(assign, loc);
114594 + }
114595 +
114596 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
114597 +
114598 + if (before)
114599 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
114600 + else
114601 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
114602 + update_stmt(assign);
114603 + return assign;
114604 +}
114605 +
114606 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
114607 +{
114608 + gimple_stmt_iterator gsi;
114609 + tree lhs;
114610 + gimple new_stmt;
114611 +
114612 + if (rhs == NULL_TREE)
114613 + return NULL_TREE;
114614 +
114615 + gsi = gsi_for_stmt(stmt);
114616 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
114617 + set_stmt_flag(new_stmt, MY_STMT);
114618 +
114619 + lhs = get_lhs(new_stmt);
114620 + gcc_assert(lhs != NULL_TREE);
114621 + return lhs;
114622 +}
114623 +
114624 +static tree cast_to_TI_type(gimple stmt, tree node)
114625 +{
114626 + gimple_stmt_iterator gsi;
114627 + gimple cast_stmt;
114628 + tree type = TREE_TYPE(node);
114629 +
114630 + if (types_compatible_p(type, intTI_type_node))
114631 + return node;
114632 +
114633 + gsi = gsi_for_stmt(stmt);
114634 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114635 + set_stmt_flag(cast_stmt, MY_STMT);
114636 + return gimple_assign_lhs(cast_stmt);
114637 +}
114638 +
114639 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
114640 +{
114641 + tree lhs, new_lhs;
114642 + gimple_stmt_iterator gsi;
114643 +
114644 + if (rhs1 == NULL_TREE) {
114645 + debug_gimple_stmt(oldstmt);
114646 + error("%s: rhs1 is NULL_TREE", __func__);
114647 + gcc_unreachable();
114648 + }
114649 +
114650 + switch (gimple_code(oldstmt)) {
114651 + case GIMPLE_ASM:
114652 + lhs = rhs1;
114653 + break;
114654 + case GIMPLE_CALL:
114655 + case GIMPLE_ASSIGN:
114656 + lhs = gimple_get_lhs(oldstmt);
114657 + break;
114658 + default:
114659 + debug_gimple_stmt(oldstmt);
114660 + gcc_unreachable();
114661 + }
114662 +
114663 + gsi = gsi_for_stmt(oldstmt);
114664 + pointer_set_insert(visited, oldstmt);
114665 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
114666 + basic_block next_bb, cur_bb;
114667 + const_edge e;
114668 +
114669 + gcc_assert(before == false);
114670 + gcc_assert(stmt_can_throw_internal(oldstmt));
114671 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
114672 + gcc_assert(!gsi_end_p(gsi));
114673 +
114674 + cur_bb = gimple_bb(oldstmt);
114675 + next_bb = cur_bb->next_bb;
114676 + e = find_edge(cur_bb, next_bb);
114677 + gcc_assert(e != NULL);
114678 + gcc_assert(e->flags & EDGE_FALLTHRU);
114679 +
114680 + gsi = gsi_after_labels(next_bb);
114681 + gcc_assert(!gsi_end_p(gsi));
114682 +
114683 + before = true;
114684 + oldstmt = gsi_stmt(gsi);
114685 + }
114686 +
114687 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
114688 + return new_lhs;
114689 +}
114690 +
114691 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
114692 +{
114693 + gimple stmt;
114694 + gimple_stmt_iterator gsi;
114695 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
114696 +
114697 + if (get_stmt_flag(oldstmt) == MY_STMT)
114698 + return lhs;
114699 +
114700 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
114701 + rhs1 = gimple_assign_rhs1(oldstmt);
114702 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
114703 + }
114704 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
114705 + rhs2 = gimple_assign_rhs2(oldstmt);
114706 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
114707 + }
114708 +
114709 + stmt = gimple_copy(oldstmt);
114710 + gimple_set_location(stmt, gimple_location(oldstmt));
114711 + set_stmt_flag(stmt, MY_STMT);
114712 +
114713 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
114714 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
114715 +
114716 + size_overflow_type = get_size_overflow_type(oldstmt, node);
114717 +
114718 + new_var = create_new_var(size_overflow_type);
114719 + new_var = make_ssa_name(new_var, stmt);
114720 + gimple_assign_set_lhs(stmt, new_var);
114721 +
114722 + if (rhs1 != NULL_TREE)
114723 + gimple_assign_set_rhs1(stmt, rhs1);
114724 +
114725 + if (rhs2 != NULL_TREE)
114726 + gimple_assign_set_rhs2(stmt, rhs2);
114727 +#if BUILDING_GCC_VERSION >= 4006
114728 + if (rhs3 != NULL_TREE)
114729 + gimple_assign_set_rhs3(stmt, rhs3);
114730 +#endif
114731 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
114732 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
114733 +
114734 + gsi = gsi_for_stmt(oldstmt);
114735 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
114736 + update_stmt(stmt);
114737 + pointer_set_insert(visited, oldstmt);
114738 + return gimple_assign_lhs(stmt);
114739 +}
114740 +
114741 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
114742 +{
114743 + gimple assign;
114744 + gimple_stmt_iterator gsi;
114745 + basic_block first_bb;
114746 +
114747 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
114748 +
114749 + if (bb->index == 0) {
114750 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
114751 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114752 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
114753 + bb = first_bb;
114754 + }
114755 +
114756 + gsi = gsi_after_labels(bb);
114757 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
114758 + set_stmt_flag(assign, MY_STMT);
114759 +
114760 + return gimple_assign_lhs(assign);
114761 +}
114762 +
114763 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
114764 +{
114765 + gimple_stmt_iterator gsi;
114766 + gimple assign, def_stmt = get_def_stmt(new_arg);
114767 +
114768 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
114769 + gsi = gsi_after_labels(gimple_bb(def_stmt));
114770 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
114771 + } else {
114772 + gsi = gsi_for_stmt(def_stmt);
114773 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
114774 + }
114775 +
114776 + set_stmt_flag(assign, MY_STMT);
114777 + return gimple_assign_lhs(assign);
114778 +}
114779 +
114780 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
114781 +{
114782 + basic_block bb;
114783 + gimple_stmt_iterator gsi;
114784 + const_gimple def_stmt;
114785 + gimple assign;
114786 +
114787 + def_stmt = get_def_stmt(arg);
114788 + bb = gimple_bb(def_stmt);
114789 + gcc_assert(bb->index != 0);
114790 + gsi = gsi_after_labels(bb);
114791 +
114792 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
114793 + set_stmt_flag(assign, MY_STMT);
114794 + return gimple_assign_lhs(assign);
114795 +}
114796 +
114797 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
114798 +{
114799 + tree size_overflow_type;
114800 + tree arg;
114801 + const_gimple def_stmt;
114802 +
114803 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
114804 + return new_arg;
114805 +
114806 + arg = gimple_phi_arg_def(oldstmt, i);
114807 + def_stmt = get_def_stmt(arg);
114808 + gcc_assert(def_stmt != NULL);
114809 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
114810 +
114811 + switch (gimple_code(def_stmt)) {
114812 + case GIMPLE_PHI:
114813 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
114814 + case GIMPLE_NOP: {
114815 + basic_block bb;
114816 +
114817 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
114818 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
114819 + }
114820 + case GIMPLE_ASM: {
114821 + gimple_stmt_iterator gsi;
114822 + gimple assign, stmt = get_def_stmt(arg);
114823 +
114824 + gsi = gsi_for_stmt(stmt);
114825 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
114826 + set_stmt_flag(assign, MY_STMT);
114827 + return gimple_assign_lhs(assign);
114828 + }
114829 + default:
114830 + gcc_assert(new_arg != NULL_TREE);
114831 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
114832 + return use_phi_ssa_name(ssa_name_var, new_arg);
114833 + }
114834 +}
114835 +
114836 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
114837 +{
114838 + basic_block bb;
114839 + gimple phi;
114840 + gimple_seq seq;
114841 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
114842 +
114843 + bb = gsi_bb(gsi);
114844 +
114845 + if (result == NULL_TREE) {
114846 + tree old_result = gimple_phi_result(oldstmt);
114847 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
114848 +
114849 + result = create_new_var(size_overflow_type);
114850 + }
114851 +
114852 + phi = create_phi_node(result, bb);
114853 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
114854 + seq = phi_nodes(bb);
114855 + gsi = gsi_last(seq);
114856 + gsi_remove(&gsi, false);
114857 +
114858 + gsi = gsi_for_stmt(oldstmt);
114859 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
114860 + gimple_set_bb(phi, bb);
114861 + set_stmt_flag(phi, MY_STMT);
114862 + return phi;
114863 +}
114864 +
114865 +#if BUILDING_GCC_VERSION <= 4007
114866 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
114867 +#else
114868 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
114869 +#endif
114870 +{
114871 + gimple new_phi;
114872 + unsigned int i;
114873 + tree arg, result;
114874 + location_t loc = gimple_location(oldstmt);
114875 +
114876 +#if BUILDING_GCC_VERSION <= 4007
114877 + gcc_assert(!VEC_empty(tree, *args));
114878 +#else
114879 + gcc_assert(!args->is_empty());
114880 +#endif
114881 +
114882 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
114883 + result = gimple_phi_result(new_phi);
114884 + ssa_name_var = SSA_NAME_VAR(result);
114885 +
114886 +#if BUILDING_GCC_VERSION <= 4007
114887 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
114888 +#else
114889 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
114890 +#endif
114891 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
114892 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
114893 + }
114894 +
114895 +#if BUILDING_GCC_VERSION <= 4007
114896 + VEC_free(tree, heap, *args);
114897 +#else
114898 + vec_free(args);
114899 +#endif
114900 + update_stmt(new_phi);
114901 + return result;
114902 +}
114903 +
114904 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
114905 +{
114906 + tree ssa_name_var = NULL_TREE;
114907 +#if BUILDING_GCC_VERSION <= 4007
114908 + VEC(tree, heap) *args = NULL;
114909 +#else
114910 + vec<tree, va_heap, vl_embed> *args = NULL;
114911 +#endif
114912 + gimple oldstmt = get_def_stmt(orig_result);
114913 + unsigned int i, len = gimple_phi_num_args(oldstmt);
114914 +
114915 + pointer_set_insert(visited, oldstmt);
114916 + for (i = 0; i < len; i++) {
114917 + tree arg, new_arg;
114918 +
114919 + arg = gimple_phi_arg_def(oldstmt, i);
114920 + new_arg = expand(visited, caller_node, arg);
114921 +
114922 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
114923 + ssa_name_var = SSA_NAME_VAR(new_arg);
114924 +
114925 + if (is_gimple_constant(arg)) {
114926 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
114927 +
114928 + new_arg = cast_a_tree(size_overflow_type, arg);
114929 + }
114930 +
114931 +#if BUILDING_GCC_VERSION <= 4007
114932 + VEC_safe_push(tree, heap, args, new_arg);
114933 +#else
114934 + vec_safe_push(args, new_arg);
114935 +#endif
114936 + }
114937 +
114938 +#if BUILDING_GCC_VERSION <= 4007
114939 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
114940 +#else
114941 + return create_new_phi_node(args, ssa_name_var, oldstmt);
114942 +#endif
114943 +}
114944 +
114945 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
114946 +{
114947 + gimple assign;
114948 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114949 + tree origtype = TREE_TYPE(orig_rhs);
114950 +
114951 + gcc_assert(is_gimple_assign(stmt));
114952 +
114953 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114954 + set_stmt_flag(assign, MY_STMT);
114955 + return gimple_assign_lhs(assign);
114956 +}
114957 +
114958 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
114959 +{
114960 + const_tree rhs1, lhs, rhs1_type, lhs_type;
114961 + enum machine_mode lhs_mode, rhs_mode;
114962 + gimple def_stmt = get_def_stmt(no_const_rhs);
114963 +
114964 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
114965 + return false;
114966 +
114967 + rhs1 = gimple_assign_rhs1(def_stmt);
114968 + lhs = gimple_assign_lhs(def_stmt);
114969 + rhs1_type = TREE_TYPE(rhs1);
114970 + lhs_type = TREE_TYPE(lhs);
114971 + rhs_mode = TYPE_MODE(rhs1_type);
114972 + lhs_mode = TYPE_MODE(lhs_type);
114973 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
114974 + return false;
114975 +
114976 + return true;
114977 +}
114978 +
114979 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
114980 +{
114981 + tree rhs1 = gimple_assign_rhs1(stmt);
114982 + tree lhs = gimple_assign_lhs(stmt);
114983 + const_tree rhs1_type = TREE_TYPE(rhs1);
114984 + const_tree lhs_type = TREE_TYPE(lhs);
114985 +
114986 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
114987 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114988 +
114989 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
114990 +}
114991 +
114992 +static bool no_uses(tree node)
114993 +{
114994 + imm_use_iterator imm_iter;
114995 + use_operand_p use_p;
114996 +
114997 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
114998 + const_gimple use_stmt = USE_STMT(use_p);
114999 +
115000 + if (use_stmt == NULL)
115001 + return true;
115002 + if (is_gimple_debug(use_stmt))
115003 + continue;
115004 + return false;
115005 + }
115006 + return true;
115007 +}
115008 +
115009 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
115010 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
115011 +{
115012 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
115013 + gimple def_stmt = get_def_stmt(lhs);
115014 +
115015 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115016 + return false;
115017 +
115018 + rhs1 = gimple_assign_rhs1(def_stmt);
115019 + rhs_type = TREE_TYPE(rhs1);
115020 + lhs_type = TREE_TYPE(lhs);
115021 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
115022 + return false;
115023 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
115024 + return false;
115025 +
115026 + def_stmt = get_def_stmt(rhs1);
115027 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
115028 + return false;
115029 +
115030 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
115031 + return false;
115032 +
115033 + rhs1 = gimple_assign_rhs1(def_stmt);
115034 + rhs2 = gimple_assign_rhs2(def_stmt);
115035 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
115036 + return false;
115037 +
115038 + if (is_gimple_constant(rhs2))
115039 + not_const_rhs = rhs1;
115040 + else
115041 + not_const_rhs = rhs2;
115042 +
115043 + return no_uses(not_const_rhs);
115044 +}
115045 +
115046 +static bool skip_lhs_cast_check(const_gimple stmt)
115047 +{
115048 + const_tree rhs = gimple_assign_rhs1(stmt);
115049 + const_gimple def_stmt = get_def_stmt(rhs);
115050 +
115051 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115052 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115053 + return true;
115054 +
115055 + if (is_const_plus_unsigned_signed_truncation(rhs))
115056 + return true;
115057 +
115058 + return false;
115059 +}
115060 +
115061 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115062 +{
115063 + bool cast_lhs, cast_rhs;
115064 + tree lhs = gimple_assign_lhs(stmt);
115065 + tree rhs = gimple_assign_rhs1(stmt);
115066 + const_tree lhs_type = TREE_TYPE(lhs);
115067 + const_tree rhs_type = TREE_TYPE(rhs);
115068 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115069 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115070 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115071 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115072 +
115073 + static bool check_lhs[3][4] = {
115074 + // ss su us uu
115075 + { false, true, true, false }, // lhs > rhs
115076 + { false, false, false, false }, // lhs = rhs
115077 + { true, true, true, true }, // lhs < rhs
115078 + };
115079 +
115080 + static bool check_rhs[3][4] = {
115081 + // ss su us uu
115082 + { true, false, true, true }, // lhs > rhs
115083 + { true, false, true, true }, // lhs = rhs
115084 + { true, false, true, true }, // lhs < rhs
115085 + };
115086 +
115087 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115088 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115089 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115090 +
115091 + if (lhs_size > rhs_size) {
115092 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115093 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115094 + } else if (lhs_size == rhs_size) {
115095 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115096 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115097 + } else {
115098 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115099 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115100 + }
115101 +
115102 + if (!cast_lhs && !cast_rhs)
115103 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115104 +
115105 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115106 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115107 +
115108 + if (cast_rhs)
115109 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115110 +
115111 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115112 +}
115113 +
115114 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115115 +{
115116 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115117 +
115118 + if (get_stmt_flag(stmt) == MY_STMT)
115119 + return lhs;
115120 +
115121 + rhs1 = gimple_assign_rhs1(stmt);
115122 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115123 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115124 +
115125 + new_rhs1 = expand(visited, caller_node, rhs1);
115126 +
115127 + if (new_rhs1 == NULL_TREE)
115128 + return create_cast_assign(visited, stmt);
115129 +
115130 + if (get_stmt_flag(stmt) == NO_CAST_CHECK)
115131 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115132 +
115133 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
115134 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
115135 +
115136 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115137 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115138 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115139 + }
115140 +
115141 + if (!gimple_assign_cast_p(stmt))
115142 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115143 +
115144 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115145 +}
115146 +
115147 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115148 +{
115149 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115150 + gimple def_stmt = get_def_stmt(lhs);
115151 +
115152 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115153 + rhs1 = gimple_assign_rhs1(def_stmt);
115154 +
115155 + if (is_gimple_constant(rhs1))
115156 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115157 +
115158 + switch (TREE_CODE(rhs1)) {
115159 + case SSA_NAME:
115160 + return handle_unary_rhs(visited, caller_node, def_stmt);
115161 + case ARRAY_REF:
115162 + case BIT_FIELD_REF:
115163 + case ADDR_EXPR:
115164 + case COMPONENT_REF:
115165 + case INDIRECT_REF:
115166 +#if BUILDING_GCC_VERSION >= 4006
115167 + case MEM_REF:
115168 +#endif
115169 + case TARGET_MEM_REF:
115170 + case VIEW_CONVERT_EXPR:
115171 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115172 + case PARM_DECL:
115173 + case VAR_DECL:
115174 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115175 +
115176 + default:
115177 + debug_gimple_stmt(def_stmt);
115178 + debug_tree(rhs1);
115179 + gcc_unreachable();
115180 + }
115181 +}
115182 +
115183 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115184 +{
115185 + gimple cond_stmt;
115186 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115187 +
115188 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115189 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115190 + update_stmt(cond_stmt);
115191 +}
115192 +
115193 +static tree create_string_param(tree string)
115194 +{
115195 + tree i_type, a_type;
115196 + const int length = TREE_STRING_LENGTH(string);
115197 +
115198 + gcc_assert(length > 0);
115199 +
115200 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115201 + a_type = build_array_type(char_type_node, i_type);
115202 +
115203 + TREE_TYPE(string) = a_type;
115204 + TREE_CONSTANT(string) = 1;
115205 + TREE_READONLY(string) = 1;
115206 +
115207 + return build1(ADDR_EXPR, ptr_type_node, string);
115208 +}
115209 +
115210 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115211 +{
115212 + gimple func_stmt;
115213 + const_gimple def_stmt;
115214 + const_tree loc_line;
115215 + tree loc_file, ssa_name, current_func;
115216 + expanded_location xloc;
115217 + char *ssa_name_buf;
115218 + int len;
115219 + struct cgraph_edge *edge;
115220 + struct cgraph_node *callee_node;
115221 + int frequency;
115222 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115223 +
115224 + def_stmt = get_def_stmt(arg);
115225 + xloc = expand_location(gimple_location(def_stmt));
115226 +
115227 + if (!gimple_has_location(def_stmt)) {
115228 + xloc = expand_location(gimple_location(stmt));
115229 + if (!gimple_has_location(stmt))
115230 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115231 + }
115232 +
115233 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115234 +
115235 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115236 + loc_file = create_string_param(loc_file);
115237 +
115238 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115239 + current_func = create_string_param(current_func);
115240 +
115241 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115242 + call_count++;
115243 + 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);
115244 + gcc_assert(len > 0);
115245 + ssa_name = build_string(len + 1, ssa_name_buf);
115246 + free(ssa_name_buf);
115247 + ssa_name = create_string_param(ssa_name);
115248 +
115249 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115250 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115251 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115252 +
115253 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115254 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115255 +
115256 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115257 + gcc_assert(edge != NULL);
115258 +}
115259 +
115260 +static void __unused print_the_code_insertions(const_gimple stmt)
115261 +{
115262 + location_t loc = gimple_location(stmt);
115263 +
115264 + inform(loc, "Integer size_overflow check applied here.");
115265 +}
115266 +
115267 +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)
115268 +{
115269 + basic_block cond_bb, join_bb, bb_true;
115270 + edge e;
115271 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115272 +
115273 + cond_bb = gimple_bb(stmt);
115274 + if (before)
115275 + gsi_prev(&gsi);
115276 + if (gsi_end_p(gsi))
115277 + e = split_block_after_labels(cond_bb);
115278 + else
115279 + e = split_block(cond_bb, gsi_stmt(gsi));
115280 + cond_bb = e->src;
115281 + join_bb = e->dest;
115282 + e->flags = EDGE_FALSE_VALUE;
115283 + e->probability = REG_BR_PROB_BASE;
115284 +
115285 + bb_true = create_empty_bb(cond_bb);
115286 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115287 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115288 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115289 +
115290 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115291 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115292 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115293 +
115294 + if (current_loops != NULL) {
115295 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115296 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115297 + }
115298 +
115299 + insert_cond(cond_bb, arg, cond_code, type_value);
115300 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115301 +
115302 +// print_the_code_insertions(stmt);
115303 +}
115304 +
115305 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115306 +{
115307 + const_tree rhs_type = TREE_TYPE(rhs);
115308 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115309 +
115310 + gcc_assert(rhs_type != NULL_TREE);
115311 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115312 + return;
115313 +
115314 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115315 +
115316 + if (is_const_plus_unsigned_signed_truncation(rhs))
115317 + return;
115318 +
115319 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115320 + // typemax (-1) < typemin (0)
115321 + if (TREE_OVERFLOW(type_max))
115322 + return;
115323 +
115324 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115325 +
115326 + cast_rhs_type = TREE_TYPE(cast_rhs);
115327 + type_max_type = TREE_TYPE(type_max);
115328 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115329 +
115330 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115331 +
115332 + // special case: get_size_overflow_type(), 32, u64->s
115333 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115334 + return;
115335 +
115336 + type_min_type = TREE_TYPE(type_min);
115337 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115338 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115339 +}
115340 +
115341 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
115342 +{
115343 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
115344 + return false;
115345 + if (!is_gimple_constant(rhs))
115346 + return false;
115347 + return true;
115348 +}
115349 +
115350 +static tree get_def_stmt_rhs(const_tree var)
115351 +{
115352 + tree rhs1, def_stmt_rhs1;
115353 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
115354 +
115355 + def_stmt = get_def_stmt(var);
115356 + if (!gimple_assign_cast_p(def_stmt))
115357 + return NULL_TREE;
115358 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && get_stmt_flag(def_stmt) == MY_STMT && gimple_assign_cast_p(def_stmt));
115359 +
115360 + rhs1 = gimple_assign_rhs1(def_stmt);
115361 + rhs1_def_stmt = get_def_stmt(rhs1);
115362 + if (!gimple_assign_cast_p(rhs1_def_stmt))
115363 + return rhs1;
115364 +
115365 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
115366 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
115367 +
115368 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
115369 + case GIMPLE_CALL:
115370 + case GIMPLE_NOP:
115371 + case GIMPLE_ASM:
115372 + case GIMPLE_PHI:
115373 + return def_stmt_rhs1;
115374 + case GIMPLE_ASSIGN:
115375 + return rhs1;
115376 + default:
115377 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
115378 + gcc_unreachable();
115379 + }
115380 +}
115381 +
115382 +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)
115383 +{
115384 + tree new_rhs, orig_rhs;
115385 + void (*gimple_assign_set_rhs)(gimple, tree);
115386 + tree rhs1 = gimple_assign_rhs1(stmt);
115387 + tree rhs2 = gimple_assign_rhs2(stmt);
115388 + tree lhs = gimple_assign_lhs(stmt);
115389 +
115390 + if (!check_overflow)
115391 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115392 +
115393 + if (change_rhs == NULL_TREE)
115394 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115395 +
115396 + if (new_rhs2 == NULL_TREE) {
115397 + orig_rhs = rhs1;
115398 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
115399 + } else {
115400 + orig_rhs = rhs2;
115401 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
115402 + }
115403 +
115404 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
115405 +
115406 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
115407 + gimple_assign_set_rhs(stmt, new_rhs);
115408 + update_stmt(stmt);
115409 +
115410 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115411 +}
115412 +
115413 +static bool is_subtraction_special(const_gimple stmt)
115414 +{
115415 + gimple rhs1_def_stmt, rhs2_def_stmt;
115416 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
115417 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
115418 + const_tree rhs1 = gimple_assign_rhs1(stmt);
115419 + const_tree rhs2 = gimple_assign_rhs2(stmt);
115420 +
115421 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
115422 + return false;
115423 +
115424 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
115425 +
115426 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115427 + return false;
115428 +
115429 + rhs1_def_stmt = get_def_stmt(rhs1);
115430 + rhs2_def_stmt = get_def_stmt(rhs2);
115431 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
115432 + return false;
115433 +
115434 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
115435 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
115436 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
115437 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
115438 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
115439 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
115440 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
115441 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
115442 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
115443 + return false;
115444 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
115445 + return false;
115446 +
115447 + set_stmt_flag(rhs1_def_stmt, NO_CAST_CHECK);
115448 + set_stmt_flag(rhs2_def_stmt, NO_CAST_CHECK);
115449 + return true;
115450 +}
115451 +
115452 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
115453 +{
115454 + tree new_rhs1, new_rhs2;
115455 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
115456 + gimple assign, stmt = get_def_stmt(lhs);
115457 + tree rhs1 = gimple_assign_rhs1(stmt);
115458 + tree rhs2 = gimple_assign_rhs2(stmt);
115459 +
115460 + if (!is_subtraction_special(stmt))
115461 + return NULL_TREE;
115462 +
115463 + new_rhs1 = expand(visited, caller_node, rhs1);
115464 + new_rhs2 = expand(visited, caller_node, rhs2);
115465 +
115466 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
115467 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
115468 +
115469 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
115470 + return NULL_TREE;
115471 +
115472 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
115473 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
115474 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
115475 + }
115476 +
115477 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
115478 + new_lhs = gimple_assign_lhs(assign);
115479 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
115480 +
115481 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115482 +}
115483 +
115484 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
115485 +{
115486 + const_gimple def_stmt;
115487 +
115488 + if (TREE_CODE(rhs) != SSA_NAME)
115489 + return false;
115490 +
115491 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
115492 + return false;
115493 +
115494 + def_stmt = get_def_stmt(rhs);
115495 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
115496 + return false;
115497 +
115498 + return true;
115499 +}
115500 +
115501 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
115502 +{
115503 + tree rhs1, rhs2, new_lhs;
115504 + gimple def_stmt = get_def_stmt(lhs);
115505 + tree new_rhs1 = NULL_TREE;
115506 + tree new_rhs2 = NULL_TREE;
115507 +
115508 + rhs1 = gimple_assign_rhs1(def_stmt);
115509 + rhs2 = gimple_assign_rhs2(def_stmt);
115510 +
115511 + /* no DImode/TImode division in the 32/64 bit kernel */
115512 + switch (gimple_assign_rhs_code(def_stmt)) {
115513 + case RDIV_EXPR:
115514 + case TRUNC_DIV_EXPR:
115515 + case CEIL_DIV_EXPR:
115516 + case FLOOR_DIV_EXPR:
115517 + case ROUND_DIV_EXPR:
115518 + case TRUNC_MOD_EXPR:
115519 + case CEIL_MOD_EXPR:
115520 + case FLOOR_MOD_EXPR:
115521 + case ROUND_MOD_EXPR:
115522 + case EXACT_DIV_EXPR:
115523 + case POINTER_PLUS_EXPR:
115524 + case BIT_AND_EXPR:
115525 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115526 + default:
115527 + break;
115528 + }
115529 +
115530 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115531 + if (new_lhs != NULL_TREE)
115532 + return new_lhs;
115533 +
115534 + if (TREE_CODE(rhs1) == SSA_NAME)
115535 + new_rhs1 = expand(visited, caller_node, rhs1);
115536 + if (TREE_CODE(rhs2) == SSA_NAME)
115537 + new_rhs2 = expand(visited, caller_node, rhs2);
115538 +
115539 + if (is_a_neg_overflow(def_stmt, rhs2))
115540 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115541 + if (is_a_neg_overflow(def_stmt, rhs1))
115542 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115543 +
115544 +
115545 + if (is_a_constant_overflow(def_stmt, rhs2))
115546 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115547 + if (is_a_constant_overflow(def_stmt, rhs1))
115548 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115549 +
115550 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115551 +}
115552 +
115553 +#if BUILDING_GCC_VERSION >= 4006
115554 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115555 +{
115556 + if (is_gimple_constant(rhs))
115557 + return cast_a_tree(size_overflow_type, rhs);
115558 + if (TREE_CODE(rhs) != SSA_NAME)
115559 + return NULL_TREE;
115560 + return expand(visited, caller_node, rhs);
115561 +}
115562 +
115563 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
115564 +{
115565 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115566 + gimple def_stmt = get_def_stmt(lhs);
115567 +
115568 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
115569 +
115570 + rhs1 = gimple_assign_rhs1(def_stmt);
115571 + rhs2 = gimple_assign_rhs2(def_stmt);
115572 + rhs3 = gimple_assign_rhs3(def_stmt);
115573 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115574 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115575 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115576 +
115577 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115578 +}
115579 +#endif
115580 +
115581 +static tree get_size_overflow_type(gimple stmt, const_tree node)
115582 +{
115583 + const_tree type;
115584 + tree new_type;
115585 +
115586 + gcc_assert(node != NULL_TREE);
115587 +
115588 + type = TREE_TYPE(node);
115589 +
115590 + if (get_stmt_flag(stmt) == MY_STMT)
115591 + return TREE_TYPE(node);
115592 +
115593 + switch (TYPE_MODE(type)) {
115594 + case QImode:
115595 + new_type = intHI_type_node;
115596 + break;
115597 + case HImode:
115598 + new_type = intSI_type_node;
115599 + break;
115600 + case SImode:
115601 + new_type = intDI_type_node;
115602 + break;
115603 + case DImode:
115604 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
115605 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
115606 + else
115607 + new_type = intTI_type_node;
115608 + break;
115609 + case TImode:
115610 + gcc_assert(!TYPE_UNSIGNED(type));
115611 + new_type = intTI_type_node;
115612 + break;
115613 + default:
115614 + debug_tree((tree)node);
115615 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
115616 + gcc_unreachable();
115617 + }
115618 +
115619 + if (TYPE_QUALS(type) != 0)
115620 + return build_qualified_type(new_type, TYPE_QUALS(type));
115621 + return new_type;
115622 +}
115623 +
115624 +static tree expand_visited(gimple def_stmt)
115625 +{
115626 + const_gimple next_stmt;
115627 + gimple_stmt_iterator gsi;
115628 + enum gimple_code code = gimple_code(def_stmt);
115629 +
115630 + if (code == GIMPLE_ASM)
115631 + return NULL_TREE;
115632 +
115633 + gsi = gsi_for_stmt(def_stmt);
115634 + gsi_next(&gsi);
115635 +
115636 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115637 + return NULL_TREE;
115638 + gcc_assert(!gsi_end_p(gsi));
115639 + next_stmt = gsi_stmt(gsi);
115640 +
115641 + if (gimple_code(def_stmt) == GIMPLE_PHI && get_stmt_flag((gimple)next_stmt) != MY_STMT)
115642 + return NULL_TREE;
115643 + gcc_assert(get_stmt_flag((gimple)next_stmt) == MY_STMT);
115644 +
115645 + return get_lhs(next_stmt);
115646 +}
115647 +
115648 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
115649 +{
115650 + gimple def_stmt;
115651 +
115652 + def_stmt = get_def_stmt(lhs);
115653 +
115654 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115655 + return NULL_TREE;
115656 +
115657 + if (get_stmt_flag(def_stmt) == MY_STMT)
115658 + return lhs;
115659 +
115660 + if (pointer_set_contains(visited, def_stmt))
115661 + return expand_visited(def_stmt);
115662 +
115663 + switch (gimple_code(def_stmt)) {
115664 + case GIMPLE_PHI:
115665 + return handle_phi(visited, caller_node, lhs);
115666 + case GIMPLE_CALL:
115667 + case GIMPLE_ASM:
115668 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115669 + case GIMPLE_ASSIGN:
115670 + switch (gimple_num_ops(def_stmt)) {
115671 + case 2:
115672 + return handle_unary_ops(visited, caller_node, def_stmt);
115673 + case 3:
115674 + return handle_binary_ops(visited, caller_node, lhs);
115675 +#if BUILDING_GCC_VERSION >= 4006
115676 + case 4:
115677 + return handle_ternary_ops(visited, caller_node, lhs);
115678 +#endif
115679 + }
115680 + default:
115681 + debug_gimple_stmt(def_stmt);
115682 + error("%s: unknown gimple code", __func__);
115683 + gcc_unreachable();
115684 + }
115685 +}
115686 +
115687 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
115688 +{
115689 + const_gimple assign;
115690 + tree orig_type = TREE_TYPE(orig_node);
115691 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115692 +
115693 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115694 + return gimple_assign_lhs(assign);
115695 +}
115696 +
115697 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
115698 +{
115699 + void (*set_rhs)(gimple, tree);
115700 + gimple stmt = cur_node->first_stmt;
115701 + const_tree orig_node = cur_node->node;
115702 +
115703 + switch (gimple_code(stmt)) {
115704 + case GIMPLE_RETURN:
115705 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
115706 + break;
115707 + case GIMPLE_CALL:
115708 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
115709 + break;
115710 + case GIMPLE_ASSIGN:
115711 + switch (cur_node->num) {
115712 + case 1:
115713 + set_rhs = &gimple_assign_set_rhs1;
115714 + break;
115715 + case 2:
115716 + set_rhs = &gimple_assign_set_rhs2;
115717 + break;
115718 +#if BUILDING_GCC_VERSION >= 4006
115719 + case 3:
115720 + set_rhs = &gimple_assign_set_rhs3;
115721 + break;
115722 +#endif
115723 + default:
115724 + gcc_unreachable();
115725 + }
115726 +
115727 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
115728 + break;
115729 + default:
115730 + debug_gimple_stmt(stmt);
115731 + gcc_unreachable();
115732 + }
115733 +
115734 + update_stmt(stmt);
115735 +}
115736 +
115737 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
115738 +{
115739 + const struct size_overflow_hash *hash;
115740 + unsigned int new_argnum;
115741 + tree arg;
115742 + const_tree origarg;
115743 +
115744 + if (argnum == 0)
115745 + return argnum;
115746 +
115747 + hash = get_function_hash(fndecl);
115748 + if (hash && hash->param & (1U << argnum))
115749 + return argnum;
115750 +
115751 + if (DECL_EXTERNAL(fndecl))
115752 + return argnum;
115753 +
115754 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
115755 + argnum--;
115756 + while (origarg && argnum) {
115757 + origarg = TREE_CHAIN(origarg);
115758 + argnum--;
115759 + }
115760 + gcc_assert(argnum == 0);
115761 + gcc_assert(origarg != NULL_TREE);
115762 +
115763 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
115764 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
115765 + return new_argnum;
115766 +
115767 + return CANNOT_FIND_ARG;
115768 +}
115769 +
115770 +// Don't want to duplicate entries in next_cgraph_node
115771 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
115772 +{
115773 + const_tree new_callee_fndecl;
115774 + struct next_cgraph_node *cur_node;
115775 +
115776 + if (fndecl == RET_CHECK)
115777 + new_callee_fndecl = NODE_DECL(node);
115778 + else
115779 + new_callee_fndecl = fndecl;
115780 +
115781 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115782 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
115783 + continue;
115784 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
115785 + continue;
115786 + if (num == cur_node->num)
115787 + return true;
115788 + }
115789 + return false;
115790 +}
115791 +
115792 +/* Add a next_cgraph_node into the list for handle_function().
115793 + * handle_function() iterates over all the next cgraph nodes and
115794 + * starts the overflow check insertion process.
115795 + */
115796 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
115797 +{
115798 + struct next_cgraph_node *new_node;
115799 +
115800 + if (is_in_next_cgraph_node(head, node, fndecl, num))
115801 + return head;
115802 +
115803 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
115804 + new_node->current_function = node;
115805 + new_node->next = NULL;
115806 + new_node->num = num;
115807 + if (fndecl == RET_CHECK)
115808 + new_node->callee_fndecl = NODE_DECL(node);
115809 + else
115810 + new_node->callee_fndecl = fndecl;
115811 +
115812 + if (!head)
115813 + return new_node;
115814 +
115815 + new_node->next = head;
115816 + return new_node;
115817 +}
115818 +
115819 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
115820 +{
115821 + struct cgraph_edge *e;
115822 +
115823 + if (num == 0)
115824 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
115825 +
115826 + for (e = node->callers; e; e = e->next_caller) {
115827 + tree fndecl = gimple_call_fndecl(e->call_stmt);
115828 +
115829 + gcc_assert(fndecl != NULL_TREE);
115830 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
115831 + }
115832 +
115833 + return head;
115834 +}
115835 +
115836 +static bool is_a_return_check(const_tree node)
115837 +{
115838 + if (TREE_CODE(node) == FUNCTION_DECL)
115839 + return true;
115840 +
115841 + gcc_assert(TREE_CODE(node) == PARM_DECL);
115842 + return false;
115843 +}
115844 +
115845 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
115846 +{
115847 + const struct size_overflow_hash *hash;
115848 +
115849 + hash = get_function_hash(fndecl);
115850 + if (hash && (hash->param & (1U << num)))
115851 + return true;
115852 + return false;
115853 +}
115854 +
115855 +struct missing_functions {
115856 + struct missing_functions *next;
115857 + const_tree node;
115858 + tree fndecl;
115859 +};
115860 +
115861 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
115862 +{
115863 + struct missing_functions *new_function;
115864 +
115865 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
115866 + new_function->node = node;
115867 + new_function->next = NULL;
115868 +
115869 + if (TREE_CODE(node) == FUNCTION_DECL)
115870 + new_function->fndecl = node;
115871 + else
115872 + new_function->fndecl = current_function_decl;
115873 + gcc_assert(new_function->fndecl);
115874 +
115875 + if (!missing_fn_head)
115876 + return new_function;
115877 +
115878 + new_function->next = missing_fn_head;
115879 + return new_function;
115880 +}
115881 +
115882 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
115883 + * If the function is missing everywhere then print the missing message into stderr.
115884 + */
115885 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
115886 +{
115887 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
115888 +#if BUILDING_GCC_VERSION >= 4008
115889 + case BUILT_IN_BSWAP16:
115890 +#endif
115891 + case BUILT_IN_BSWAP32:
115892 + case BUILT_IN_BSWAP64:
115893 + case BUILT_IN_EXPECT:
115894 + case BUILT_IN_MEMCMP:
115895 + return false;
115896 + default:
115897 + break;
115898 + }
115899 +
115900 + // skip test.c
115901 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
115902 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
115903 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
115904 + }
115905 +
115906 + if (is_in_hash_table(orig_fndecl, num))
115907 + return false;
115908 +
115909 + print_missing_msg(orig_fndecl, num);
115910 + return true;
115911 +}
115912 +
115913 +// Get the argnum of a function decl, if node is a return then the argnum is 0
115914 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
115915 +{
115916 + if (is_a_return_check(node))
115917 + return 0;
115918 + else
115919 + return find_arg_number_tree(node, orig_fndecl);
115920 +}
115921 +
115922 +/* If the function is missing from the hash table and it is a static function
115923 + * then create a next_cgraph_node from it for handle_function()
115924 + */
115925 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
115926 +{
115927 + unsigned int num;
115928 + const_tree orig_fndecl;
115929 + struct cgraph_node *next_node = NULL;
115930 +
115931 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
115932 +
115933 + num = get_function_num(missing_fn_head->node, orig_fndecl);
115934 + if (num == CANNOT_FIND_ARG)
115935 + return cnodes;
115936 +
115937 + if (!is_missing_function(orig_fndecl, num))
115938 + return cnodes;
115939 +
115940 + next_node = cgraph_get_node(missing_fn_head->fndecl);
115941 + if (next_node && next_node->local.local)
115942 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
115943 + return cnodes;
115944 +}
115945 +
115946 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
115947 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
115948 + */
115949 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
115950 +{
115951 + unsigned int i;
115952 + tree node;
115953 + struct missing_functions *cur, *missing_fn_head = NULL;
115954 +
115955 +#if BUILDING_GCC_VERSION <= 4007
115956 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
115957 +#else
115958 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
115959 +#endif
115960 + switch (TREE_CODE(node)) {
115961 + case PARM_DECL:
115962 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
115963 + break;
115964 + case FUNCTION_DECL:
115965 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
115966 + break;
115967 + default:
115968 + break;
115969 + }
115970 + }
115971 +
115972 + while (missing_fn_head) {
115973 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
115974 +
115975 + cur = missing_fn_head->next;
115976 + free(missing_fn_head);
115977 + missing_fn_head = cur;
115978 + }
115979 +
115980 + return cnodes;
115981 +}
115982 +
115983 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
115984 +{
115985 + gimple phi = get_def_stmt(result);
115986 + unsigned int i, n = gimple_phi_num_args(phi);
115987 +
115988 + pointer_set_insert(visited, phi);
115989 + for (i = 0; i < n; i++) {
115990 + const_tree arg = gimple_phi_arg_def(phi, i);
115991 +
115992 + set_conditions(visited, interesting_conditions, arg);
115993 + }
115994 +}
115995 +
115996 +enum conditions {
115997 + FROM_CONST, NOT_UNARY, CAST
115998 +};
115999 +
116000 +// Search for constants, cast assignments and binary/ternary assignments
116001 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116002 +{
116003 + gimple def_stmt = get_def_stmt(lhs);
116004 +
116005 + if (is_gimple_constant(lhs)) {
116006 + interesting_conditions[FROM_CONST] = true;
116007 + return;
116008 + }
116009 +
116010 + if (!def_stmt)
116011 + return;
116012 +
116013 + if (pointer_set_contains(visited, def_stmt))
116014 + return;
116015 +
116016 + switch (gimple_code(def_stmt)) {
116017 + case GIMPLE_NOP:
116018 + case GIMPLE_CALL:
116019 + case GIMPLE_ASM:
116020 + return;
116021 + case GIMPLE_PHI:
116022 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116023 + case GIMPLE_ASSIGN:
116024 + if (gimple_num_ops(def_stmt) == 2) {
116025 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116026 +
116027 + if (gimple_assign_cast_p(def_stmt))
116028 + interesting_conditions[CAST] = true;
116029 +
116030 + return set_conditions(visited, interesting_conditions, rhs);
116031 + } else {
116032 + interesting_conditions[NOT_UNARY] = true;
116033 + return;
116034 + }
116035 + default:
116036 + debug_gimple_stmt(def_stmt);
116037 + gcc_unreachable();
116038 + }
116039 +}
116040 +
116041 +// determine whether duplication will be necessary or not.
116042 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116043 +{
116044 + struct pointer_set_t *visited;
116045 +
116046 + if (gimple_assign_cast_p(cur_node->first_stmt))
116047 + interesting_conditions[CAST] = true;
116048 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116049 + interesting_conditions[NOT_UNARY] = true;
116050 +
116051 + visited = pointer_set_create();
116052 + set_conditions(visited, interesting_conditions, cur_node->node);
116053 + pointer_set_destroy(visited);
116054 +}
116055 +
116056 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116057 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116058 +{
116059 + gimple assign;
116060 + gimple_stmt_iterator gsi;
116061 +
116062 + // already removed
116063 + if (gimple_bb(asm_stmt) == NULL)
116064 + return;
116065 + gsi = gsi_for_stmt(asm_stmt);
116066 +
116067 + assign = gimple_build_assign(lhs, rhs);
116068 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116069 + SSA_NAME_DEF_STMT(lhs) = assign;
116070 +
116071 + gsi_remove(&gsi, true);
116072 +}
116073 +
116074 +// Get the field decl of a component ref for intentional_overflow checking
116075 +static const_tree search_field_decl(const_tree comp_ref)
116076 +{
116077 + const_tree field = NULL_TREE;
116078 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116079 +
116080 + for (i = 0; i < len; i++) {
116081 + field = TREE_OPERAND(comp_ref, i);
116082 + if (TREE_CODE(field) == FIELD_DECL)
116083 + break;
116084 + }
116085 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116086 + return field;
116087 +}
116088 +
116089 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116090 + * stmt is a return otherwise it is the callee function.
116091 + */
116092 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116093 +{
116094 + const_tree fndecl;
116095 +
116096 + if (argnum == 0)
116097 + fndecl = current_function_decl;
116098 + else
116099 + fndecl = gimple_call_fndecl(stmt);
116100 +
116101 + if (fndecl == NULL_TREE)
116102 + return NULL_TREE;
116103 +
116104 + return DECL_ORIGIN(fndecl);
116105 +}
116106 +
116107 +/* Get the param of the intentional_overflow attribute.
116108 + * * 0: MARK_NOT_INTENTIONAL
116109 + * * 1..MAX_PARAM: MARK_YES
116110 + * * -1: MARK_TURN_OFF
116111 + */
116112 +static tree get_attribute_param(const_tree decl)
116113 +{
116114 + const_tree attr;
116115 +
116116 + if (decl == NULL_TREE)
116117 + return NULL_TREE;
116118 +
116119 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116120 + if (!attr || !TREE_VALUE(attr))
116121 + return NULL_TREE;
116122 +
116123 + return TREE_VALUE(attr);
116124 +}
116125 +
116126 +// MARK_TURN_OFF
116127 +static bool is_turn_off_intentional_attr(const_tree decl)
116128 +{
116129 + const_tree param_head;
116130 +
116131 + param_head = get_attribute_param(decl);
116132 + if (param_head == NULL_TREE)
116133 + return false;
116134 +
116135 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116136 + return true;
116137 + return false;
116138 +}
116139 +
116140 +// MARK_NOT_INTENTIONAL
116141 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116142 +{
116143 + const_tree param_head;
116144 +
116145 + if (argnum == 0)
116146 + return false;
116147 +
116148 + param_head = get_attribute_param(decl);
116149 + if (param_head == NULL_TREE)
116150 + return false;
116151 +
116152 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116153 + return true;
116154 + return false;
116155 +}
116156 +
116157 +// MARK_YES
116158 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116159 +{
116160 + tree param, param_head;
116161 +
116162 + if (argnum == 0)
116163 + return false;
116164 +
116165 + param_head = get_attribute_param(decl);
116166 + for (param = param_head; param; param = TREE_CHAIN(param))
116167 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
116168 + return true;
116169 + return false;
116170 +}
116171 +
116172 +static const char *get_asm_string(const_gimple stmt)
116173 +{
116174 + if (!stmt)
116175 + return NULL;
116176 + if (gimple_code(stmt) != GIMPLE_ASM)
116177 + return NULL;
116178 +
116179 + return gimple_asm_string(stmt);
116180 +}
116181 +
116182 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
116183 +{
116184 + const char *str;
116185 +
116186 + str = get_asm_string(stmt);
116187 + if (!str)
116188 + return false;
116189 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
116190 +}
116191 +
116192 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
116193 +{
116194 + const char *str;
116195 +
116196 + str = get_asm_string(stmt);
116197 + if (!str)
116198 + return false;
116199 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
116200 +}
116201 +
116202 +static bool is_size_overflow_asm(const_gimple stmt)
116203 +{
116204 + const char *str;
116205 +
116206 + str = get_asm_string(stmt);
116207 + if (!str)
116208 + return false;
116209 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
116210 +}
116211 +
116212 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
116213 +{
116214 + location_t loc;
116215 +
116216 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
116217 + return;
116218 +
116219 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
116220 + return;
116221 +
116222 + loc = DECL_SOURCE_LOCATION(decl);
116223 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
116224 +}
116225 +
116226 +/* Get the type of the intentional_overflow attribute of a node
116227 + * * MARK_TURN_OFF
116228 + * * MARK_YES
116229 + * * MARK_NO
116230 + * * MARK_NOT_INTENTIONAL
116231 + */
116232 +static enum mark get_intentional_attr_type(const_tree node)
116233 +{
116234 + const_tree cur_decl;
116235 +
116236 + if (node == NULL_TREE)
116237 + return MARK_NO;
116238 +
116239 + switch (TREE_CODE(node)) {
116240 + case COMPONENT_REF:
116241 + cur_decl = search_field_decl(node);
116242 + if (is_turn_off_intentional_attr(cur_decl))
116243 + return MARK_TURN_OFF;
116244 + if (is_end_intentional_intentional_attr(cur_decl, 1))
116245 + return MARK_YES;
116246 + break;
116247 + case PARM_DECL: {
116248 + unsigned int argnum;
116249 +
116250 + cur_decl = DECL_ORIGIN(current_function_decl);
116251 + argnum = find_arg_number_tree(node, cur_decl);
116252 + if (argnum == CANNOT_FIND_ARG)
116253 + return MARK_NO;
116254 + if (is_yes_intentional_attr(cur_decl, argnum))
116255 + return MARK_YES;
116256 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
116257 + return MARK_NOT_INTENTIONAL;
116258 + break;
116259 + }
116260 + case FUNCTION_DECL:
116261 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
116262 + return MARK_TURN_OFF;
116263 + break;
116264 + default:
116265 + break;
116266 + }
116267 + return MARK_NO;
116268 +}
116269 +
116270 +// Search for the intentional_overflow attribute on the last nodes
116271 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
116272 +{
116273 + unsigned int i;
116274 + tree last_node;
116275 + enum mark mark = MARK_NO;
116276 +
116277 +#if BUILDING_GCC_VERSION <= 4007
116278 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
116279 +#else
116280 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
116281 +#endif
116282 + mark = get_intentional_attr_type(last_node);
116283 + if (mark != MARK_NO)
116284 + break;
116285 + }
116286 + return mark;
116287 +}
116288 +
116289 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
116290 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
116291 + */
116292 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
116293 +{
116294 + if (!cur_node->intentional_mark_from_gimple)
116295 + return false;
116296 +
116297 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
116298 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
116299 + else
116300 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116301 +
116302 + // skip param decls
116303 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
116304 + return true;
116305 + return true;
116306 +}
116307 +
116308 +/* Search intentional_overflow attribute on caller and on callee too.
116309 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
116310 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
116311 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
116312 +*/
116313 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
116314 +{
116315 + const_tree fndecl;
116316 +
116317 + if (is_intentional_attribute_from_gimple(cur_node))
116318 + return;
116319 +
116320 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116321 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116322 + return;
116323 + }
116324 +
116325 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
116326 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
116327 + return;
116328 + }
116329 +
116330 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
116331 + return;
116332 +
116333 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
116334 + if (is_turn_off_intentional_attr(fndecl)) {
116335 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
116336 + return;
116337 + }
116338 +
116339 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
116340 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
116341 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
116342 + cur_node->intentional_attr_decl = MARK_YES;
116343 +
116344 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
116345 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
116346 +}
116347 +
116348 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
116349 +static bool skip_asm(const_tree arg)
116350 +{
116351 + gimple def_stmt = get_def_stmt(arg);
116352 +
116353 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116354 + return false;
116355 +
116356 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
116357 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
116358 +}
116359 +
116360 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
116361 +{
116362 + gimple phi = get_def_stmt(result);
116363 + unsigned int i, n = gimple_phi_num_args(phi);
116364 +
116365 + pointer_set_insert(visited, phi);
116366 + for (i = 0; i < n; i++) {
116367 + tree arg = gimple_phi_arg_def(phi, i);
116368 +
116369 + walk_use_def(visited, cur_node, arg);
116370 + }
116371 +}
116372 +
116373 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116374 +{
116375 + gimple def_stmt = get_def_stmt(lhs);
116376 + tree rhs1, rhs2;
116377 +
116378 + rhs1 = gimple_assign_rhs1(def_stmt);
116379 + rhs2 = gimple_assign_rhs2(def_stmt);
116380 +
116381 + walk_use_def(visited, cur_node, rhs1);
116382 + walk_use_def(visited, cur_node, rhs2);
116383 +}
116384 +
116385 +static void insert_last_node(struct interesting_node *cur_node, tree node)
116386 +{
116387 + unsigned int i;
116388 + tree element;
116389 + enum tree_code code;
116390 +
116391 + gcc_assert(node != NULL_TREE);
116392 +
116393 + if (is_gimple_constant(node))
116394 + return;
116395 +
116396 + code = TREE_CODE(node);
116397 + if (code == VAR_DECL) {
116398 + node = DECL_ORIGIN(node);
116399 + code = TREE_CODE(node);
116400 + }
116401 +
116402 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
116403 + return;
116404 +
116405 +#if BUILDING_GCC_VERSION <= 4007
116406 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
116407 +#else
116408 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
116409 +#endif
116410 + if (operand_equal_p(node, element, 0))
116411 + return;
116412 + }
116413 +
116414 +#if BUILDING_GCC_VERSION <= 4007
116415 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
116416 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
116417 +#else
116418 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
116419 + vec_safe_push(cur_node->last_nodes, node);
116420 +#endif
116421 +}
116422 +
116423 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
116424 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
116425 +{
116426 + if (!is_size_overflow_asm(stmt))
116427 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116428 +}
116429 +
116430 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
116431 + * and component refs (for checking the intentional_overflow attribute).
116432 + */
116433 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116434 +{
116435 + const_gimple def_stmt;
116436 +
116437 + if (TREE_CODE(lhs) != SSA_NAME) {
116438 + insert_last_node(cur_node, lhs);
116439 + return;
116440 + }
116441 +
116442 + def_stmt = get_def_stmt(lhs);
116443 + if (!def_stmt)
116444 + return;
116445 +
116446 + if (pointer_set_insert(visited, def_stmt))
116447 + return;
116448 +
116449 + switch (gimple_code(def_stmt)) {
116450 + case GIMPLE_NOP:
116451 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116452 + case GIMPLE_ASM:
116453 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
116454 + case GIMPLE_CALL: {
116455 + tree fndecl = gimple_call_fndecl(def_stmt);
116456 +
116457 + if (fndecl == NULL_TREE)
116458 + return;
116459 + insert_last_node(cur_node, fndecl);
116460 + return;
116461 + }
116462 + case GIMPLE_PHI:
116463 + return walk_use_def_phi(visited, cur_node, lhs);
116464 + case GIMPLE_ASSIGN:
116465 + switch (gimple_num_ops(def_stmt)) {
116466 + case 2:
116467 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
116468 + case 3:
116469 + return walk_use_def_binary(visited, cur_node, lhs);
116470 + }
116471 + default:
116472 + debug_gimple_stmt((gimple)def_stmt);
116473 + error("%s: unknown gimple code", __func__);
116474 + gcc_unreachable();
116475 + }
116476 +}
116477 +
116478 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
116479 +static void set_last_nodes(struct interesting_node *cur_node)
116480 +{
116481 + struct pointer_set_t *visited;
116482 +
116483 + visited = pointer_set_create();
116484 + walk_use_def(visited, cur_node, cur_node->node);
116485 + pointer_set_destroy(visited);
116486 +}
116487 +
116488 +enum precond {
116489 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
116490 +};
116491 +
116492 +/* 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.
116493 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
116494 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
116495 + * 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.
116496 + */
116497 +static enum precond check_preconditions(struct interesting_node *cur_node)
116498 +{
116499 + bool interesting_conditions[3] = {false, false, false};
116500 +
116501 + set_last_nodes(cur_node);
116502 +
116503 + check_intentional_attribute_ipa(cur_node);
116504 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
116505 + return NO_ATTRIBUTE_SEARCH;
116506 +
116507 + search_interesting_conditions(cur_node, interesting_conditions);
116508 +
116509 + // error code
116510 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
116511 + return NO_ATTRIBUTE_SEARCH;
116512 +
116513 + // unnecessary overflow check
116514 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
116515 + return NO_CHECK_INSERT;
116516 +
116517 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
116518 + return NO_CHECK_INSERT;
116519 +
116520 + return NONE;
116521 +}
116522 +
116523 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
116524 + * 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
116525 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
116526 + */
116527 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
116528 +{
116529 + enum precond ret;
116530 + struct pointer_set_t *visited;
116531 + tree new_node, orig_node = cur_node->node;
116532 +
116533 + ret = check_preconditions(cur_node);
116534 + if (ret == NO_ATTRIBUTE_SEARCH)
116535 + return cnodes;
116536 +
116537 + cnodes = search_overflow_attribute(cnodes, cur_node);
116538 +
116539 + if (ret == NO_CHECK_INSERT)
116540 + return cnodes;
116541 +
116542 + visited = pointer_set_create();
116543 + new_node = expand(visited, caller_node, orig_node);
116544 + pointer_set_destroy(visited);
116545 +
116546 + if (new_node == NULL_TREE)
116547 + return cnodes;
116548 +
116549 + change_orig_node(cur_node, new_node);
116550 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
116551 +
116552 + return cnodes;
116553 +}
116554 +
116555 +// Check visited interesting nodes.
116556 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
116557 +{
116558 + struct interesting_node *cur;
116559 +
116560 + for (cur = head; cur; cur = cur->next) {
116561 + if (!operand_equal_p(node, cur->node, 0))
116562 + continue;
116563 + if (num != cur->num)
116564 + continue;
116565 + if (first_stmt == cur->first_stmt)
116566 + return true;
116567 + }
116568 + return false;
116569 +}
116570 +
116571 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
116572 + 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
116573 + 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
116574 + the intentional_overflow attribute check. They are collected by set_last_nodes().
116575 + num: arg count of a call stmt or 0 when it is a ret
116576 + node: the recursion starts from here, it is a call arg or a return value
116577 + 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.
116578 + intentional_attr_decl: intentional_overflow attribute of the callee function
116579 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
116580 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
116581 + */
116582 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
116583 +{
116584 + struct interesting_node *new_node;
116585 + tree fndecl;
116586 + enum gimple_code code;
116587 +
116588 + gcc_assert(node != NULL_TREE);
116589 + code = gimple_code(first_stmt);
116590 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
116591 +
116592 + if (num == CANNOT_FIND_ARG)
116593 + return head;
116594 +
116595 + if (skip_types(node))
116596 + return head;
116597 +
116598 + if (skip_asm(node))
116599 + return head;
116600 +
116601 + if (is_gimple_call(first_stmt))
116602 + fndecl = gimple_call_fndecl(first_stmt);
116603 + else
116604 + fndecl = current_function_decl;
116605 +
116606 + if (fndecl == NULL_TREE)
116607 + return head;
116608 +
116609 + if (is_in_interesting_node(head, first_stmt, node, num))
116610 + return head;
116611 +
116612 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
116613 +
116614 + new_node->next = NULL;
116615 + new_node->first_stmt = first_stmt;
116616 +#if BUILDING_GCC_VERSION <= 4007
116617 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
116618 +#else
116619 + vec_alloc(new_node->last_nodes, VEC_LEN);
116620 +#endif
116621 + new_node->num = num;
116622 + new_node->node = node;
116623 + new_node->fndecl = fndecl;
116624 + new_node->intentional_attr_decl = MARK_NO;
116625 + new_node->intentional_attr_cur_fndecl = MARK_NO;
116626 + new_node->intentional_mark_from_gimple = asm_stmt;
116627 +
116628 + if (!head)
116629 + return new_node;
116630 +
116631 + new_node->next = head;
116632 + return new_node;
116633 +}
116634 +
116635 +/* 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).
116636 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
116637 + */
116638 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116639 +{
116640 + struct next_cgraph_node *cur_node;
116641 + tree ret = gimple_return_retval(stmt);
116642 +
116643 + if (ret == NULL_TREE)
116644 + return head;
116645 +
116646 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116647 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
116648 + continue;
116649 + if (cur_node->num == 0)
116650 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
116651 + }
116652 +
116653 + return head;
116654 +}
116655 +
116656 +/* 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).
116657 + * If the call stmt is in the next cgraph node list then it's an interesting call.
116658 + */
116659 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116660 +{
116661 + unsigned int argnum;
116662 + tree arg;
116663 + const_tree fndecl;
116664 + struct next_cgraph_node *cur_node;
116665 +
116666 + fndecl = gimple_call_fndecl(stmt);
116667 + if (fndecl == NULL_TREE)
116668 + return head;
116669 +
116670 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116671 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
116672 + continue;
116673 + argnum = get_correct_arg_count(cur_node->num, fndecl);
116674 + gcc_assert(argnum != CANNOT_FIND_ARG);
116675 + if (argnum == 0)
116676 + continue;
116677 +
116678 + arg = gimple_call_arg(stmt, argnum - 1);
116679 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
116680 + }
116681 +
116682 + return head;
116683 +}
116684 +
116685 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
116686 +{
116687 + if (!operand_equal_p(orig_node, node, 0))
116688 + return WRONG_NODE;
116689 + if (skip_types(node))
116690 + return WRONG_NODE;
116691 + return ret_count;
116692 +}
116693 +
116694 +// Get the index of the rhs node in an assignment
116695 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
116696 +{
116697 + const_tree rhs1, rhs2;
116698 + unsigned int ret;
116699 +
116700 + gcc_assert(stmt);
116701 + gcc_assert(is_gimple_assign(stmt));
116702 +
116703 + rhs1 = gimple_assign_rhs1(stmt);
116704 + gcc_assert(rhs1 != NULL_TREE);
116705 +
116706 + switch (gimple_num_ops(stmt)) {
116707 + case 2:
116708 + return check_ops(node, rhs1, 1);
116709 + case 3:
116710 + ret = check_ops(node, rhs1, 1);
116711 + if (ret != WRONG_NODE)
116712 + return ret;
116713 +
116714 + rhs2 = gimple_assign_rhs2(stmt);
116715 + gcc_assert(rhs2 != NULL_TREE);
116716 + return check_ops(node, rhs2, 2);
116717 + default:
116718 + gcc_unreachable();
116719 + }
116720 +}
116721 +
116722 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
116723 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
116724 +{
116725 + unsigned int i;
116726 +
116727 + if (gimple_call_fndecl(stmt) == NULL_TREE)
116728 + return CANNOT_FIND_ARG;
116729 +
116730 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
116731 + tree node;
116732 +
116733 + node = gimple_call_arg(stmt, i);
116734 + if (!operand_equal_p(arg, node, 0))
116735 + continue;
116736 + if (!skip_types(node))
116737 + return i + 1;
116738 + }
116739 +
116740 + return CANNOT_FIND_ARG;
116741 +}
116742 +
116743 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
116744 + * any of return, call or assignment stmts (because of inlining).
116745 + */
116746 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
116747 +{
116748 + use_operand_p use_p;
116749 + imm_use_iterator imm_iter;
116750 + unsigned int argnum;
116751 +
116752 + gcc_assert(TREE_CODE(node) == SSA_NAME);
116753 +
116754 + if (pointer_set_insert(visited, node))
116755 + return head;
116756 +
116757 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116758 + gimple stmt = USE_STMT(use_p);
116759 +
116760 + if (stmt == NULL)
116761 + return head;
116762 + if (is_gimple_debug(stmt))
116763 + continue;
116764 +
116765 + switch (gimple_code(stmt)) {
116766 + case GIMPLE_CALL:
116767 + argnum = find_arg_number_gimple(node, stmt);
116768 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116769 + break;
116770 + case GIMPLE_RETURN:
116771 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116772 + break;
116773 + case GIMPLE_ASSIGN:
116774 + argnum = get_assign_ops_count(stmt, node);
116775 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116776 + break;
116777 + case GIMPLE_PHI: {
116778 + tree result = gimple_phi_result(stmt);
116779 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116780 + break;
116781 + }
116782 + case GIMPLE_ASM:
116783 + if (gimple_asm_noutputs(stmt) != 0)
116784 + break;
116785 + if (!is_size_overflow_asm(stmt))
116786 + break;
116787 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116788 + break;
116789 + case GIMPLE_COND:
116790 + case GIMPLE_SWITCH:
116791 + break;
116792 + default:
116793 + debug_gimple_stmt(stmt);
116794 + gcc_unreachable();
116795 + break;
116796 + }
116797 + }
116798 + return head;
116799 +}
116800 +
116801 +static void remove_size_overflow_asm(gimple stmt)
116802 +{
116803 + gimple_stmt_iterator gsi;
116804 + tree input, output;
116805 +
116806 + if (!is_size_overflow_asm(stmt))
116807 + return;
116808 +
116809 + if (gimple_asm_noutputs(stmt) == 0) {
116810 + gsi = gsi_for_stmt(stmt);
116811 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116812 + gsi_remove(&gsi, true);
116813 + return;
116814 + }
116815 +
116816 + input = gimple_asm_input_op(stmt, 0);
116817 + output = gimple_asm_output_op(stmt, 0);
116818 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116819 +}
116820 +
116821 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116822 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116823 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116824 + */
116825 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116826 +{
116827 + const_tree output;
116828 + struct pointer_set_t *visited;
116829 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116830 +
116831 + if (!is_size_overflow_asm(stmt))
116832 + return head;
116833 +
116834 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116835 + intentional_asm = stmt;
116836 +
116837 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116838 +
116839 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116840 + return head;
116841 +
116842 + if (gimple_asm_noutputs(stmt) == 0) {
116843 + const_tree input;
116844 +
116845 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116846 + return head;
116847 +
116848 + input = gimple_asm_input_op(stmt, 0);
116849 + remove_size_overflow_asm(stmt);
116850 + if (is_gimple_constant(TREE_VALUE(input)))
116851 + return head;
116852 + visited = pointer_set_create();
116853 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116854 + pointer_set_destroy(visited);
116855 + return head;
116856 + }
116857 +
116858 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116859 + remove_size_overflow_asm(stmt);
116860 +
116861 + visited = pointer_set_create();
116862 + output = gimple_asm_output_op(stmt, 0);
116863 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116864 + pointer_set_destroy(visited);
116865 + return head;
116866 +}
116867 +
116868 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116869 + * or a call stmt or a return stmt and store them in the interesting_node list
116870 + */
116871 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116872 +{
116873 + basic_block bb;
116874 + struct interesting_node *head = NULL;
116875 +
116876 + FOR_ALL_BB_FN(bb, cfun) {
116877 + gimple_stmt_iterator gsi;
116878 +
116879 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116880 + enum gimple_code code;
116881 + gimple stmt = gsi_stmt(gsi);
116882 +
116883 + code = gimple_code(stmt);
116884 +
116885 + if (code == GIMPLE_ASM)
116886 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116887 +
116888 + if (!next_node)
116889 + continue;
116890 + if (code == GIMPLE_CALL)
116891 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116892 + if (code == GIMPLE_RETURN)
116893 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116894 + }
116895 + }
116896 + return head;
116897 +}
116898 +
116899 +static void set_current_function_decl(tree fndecl)
116900 +{
116901 + gcc_assert(fndecl != NULL_TREE);
116902 +
116903 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
116904 + calculate_dominance_info(CDI_DOMINATORS);
116905 + current_function_decl = fndecl;
116906 +}
116907 +
116908 +static void unset_current_function_decl(void)
116909 +{
116910 + free_dominance_info(CDI_DOMINATORS);
116911 + pop_cfun();
116912 + current_function_decl = NULL_TREE;
116913 +}
116914 +
116915 +static void free_interesting_node(struct interesting_node *head)
116916 +{
116917 + struct interesting_node *cur;
116918 +
116919 + while (head) {
116920 + cur = head->next;
116921 +#if BUILDING_GCC_VERSION <= 4007
116922 + VEC_free(tree, gc, head->last_nodes);
116923 +#else
116924 + vec_free(head->last_nodes);
116925 +#endif
116926 + free(head);
116927 + head = cur;
116928 + }
116929 +}
116930 +
116931 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
116932 +{
116933 + struct visited *new_visited;
116934 +
116935 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
116936 + new_visited->fndecl = cur_node->fndecl;
116937 + new_visited->num = cur_node->num;
116938 + new_visited->next = NULL;
116939 +
116940 + if (!head)
116941 + return new_visited;
116942 +
116943 + new_visited->next = head;
116944 + return new_visited;
116945 +}
116946 +
116947 +/* 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
116948 + * it is a visited function.
116949 + */
116950 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
116951 +{
116952 + struct visited *cur;
116953 +
116954 + if (!head)
116955 + return false;
116956 +
116957 + if (get_stmt_flag(cur_node->first_stmt) != VISITED_STMT)
116958 + return false;
116959 +
116960 + for (cur = head; cur; cur = cur->next) {
116961 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
116962 + continue;
116963 + if (cur_node->num == cur->num)
116964 + return true;
116965 + }
116966 + return false;
116967 +}
116968 +
116969 +static void free_next_cgraph_node(struct next_cgraph_node *head)
116970 +{
116971 + struct next_cgraph_node *cur;
116972 +
116973 + while (head) {
116974 + cur = head->next;
116975 + free(head);
116976 + head = cur;
116977 + }
116978 +}
116979 +
116980 +static void remove_all_size_overflow_asm(void)
116981 +{
116982 + basic_block bb;
116983 +
116984 + FOR_ALL_BB_FN(bb, cfun) {
116985 + gimple_stmt_iterator si;
116986 +
116987 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116988 + remove_size_overflow_asm(gsi_stmt(si));
116989 + }
116990 +}
116991 +
116992 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
116993 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
116994 + * the newly collected interesting functions (they are interesting if there is control flow between
116995 + * the interesting stmts and them).
116996 + */
116997 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
116998 +{
116999 + struct interesting_node *head, *cur_node;
117000 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
117001 +
117002 + set_current_function_decl(NODE_DECL(node));
117003 + call_count = 0;
117004 +
117005 + head = collect_interesting_stmts(next_node);
117006 +
117007 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
117008 + if (is_visited_function(visited, cur_node))
117009 + continue;
117010 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
117011 + set_stmt_flag(cur_node->first_stmt, VISITED_STMT);
117012 + visited = insert_visited_function(visited, cur_node);
117013 + }
117014 +
117015 + free_interesting_node(head);
117016 + remove_all_size_overflow_asm();
117017 + unset_current_function_decl();
117018 +
117019 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
117020 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
117021 +
117022 + free_next_cgraph_node(cnodes_head);
117023 + return visited;
117024 +}
117025 +
117026 +static void free_visited(struct visited *head)
117027 +{
117028 + struct visited *cur;
117029 +
117030 + while (head) {
117031 + cur = head->next;
117032 + free(head);
117033 + head = cur;
117034 + }
117035 +}
117036 +
117037 +// erase the local flag
117038 +static void set_plf_false(void)
117039 +{
117040 + basic_block bb;
117041 +
117042 + FOR_ALL_BB_FN(bb, cfun) {
117043 + gimple_stmt_iterator si;
117044 +
117045 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117046 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117047 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117048 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117049 + }
117050 +}
117051 +
117052 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
117053 +static unsigned int search_function(void)
117054 +{
117055 + struct cgraph_node *node;
117056 + struct visited *visited = NULL;
117057 +
117058 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117059 + set_current_function_decl(NODE_DECL(node));
117060 + set_plf_false();
117061 + unset_current_function_decl();
117062 + }
117063 +
117064 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117065 + gcc_assert(cgraph_function_flags_ready);
117066 +#if BUILDING_GCC_VERSION <= 4007
117067 + gcc_assert(node->reachable);
117068 +#endif
117069 +
117070 + visited = handle_function(node, NULL, visited);
117071 + }
117072 +
117073 + free_visited(visited);
117074 + return 0;
117075 +}
117076 +
117077 +#if BUILDING_GCC_VERSION >= 4009
117078 +static const struct pass_data ipa_pass_data = {
117079 +#else
117080 +static struct ipa_opt_pass_d ipa_pass = {
117081 + .pass = {
117082 +#endif
117083 + .type = SIMPLE_IPA_PASS,
117084 + .name = "size_overflow",
117085 +#if BUILDING_GCC_VERSION >= 4008
117086 + .optinfo_flags = OPTGROUP_NONE,
117087 +#endif
117088 +#if BUILDING_GCC_VERSION >= 4009
117089 + .has_gate = false,
117090 + .has_execute = true,
117091 +#else
117092 + .gate = NULL,
117093 + .execute = search_function,
117094 + .sub = NULL,
117095 + .next = NULL,
117096 + .static_pass_number = 0,
117097 +#endif
117098 + .tv_id = TV_NONE,
117099 + .properties_required = 0,
117100 + .properties_provided = 0,
117101 + .properties_destroyed = 0,
117102 + .todo_flags_start = 0,
117103 + .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,
117104 +#if BUILDING_GCC_VERSION < 4009
117105 + },
117106 + .generate_summary = NULL,
117107 + .write_summary = NULL,
117108 + .read_summary = NULL,
117109 +#if BUILDING_GCC_VERSION >= 4006
117110 + .write_optimization_summary = NULL,
117111 + .read_optimization_summary = NULL,
117112 +#endif
117113 + .stmt_fixup = NULL,
117114 + .function_transform_todo_flags_start = 0,
117115 + .function_transform = NULL,
117116 + .variable_transform = NULL,
117117 +#endif
117118 +};
117119 +
117120 +#if BUILDING_GCC_VERSION >= 4009
117121 +namespace {
117122 +class ipa_pass : public ipa_opt_pass_d {
117123 +public:
117124 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117125 + unsigned int execute() { return search_function(); }
117126 +};
117127 +}
117128 +#endif
117129 +
117130 +static struct opt_pass *make_ipa_pass(void)
117131 +{
117132 +#if BUILDING_GCC_VERSION >= 4009
117133 + return new ipa_pass();
117134 +#else
117135 + return &ipa_pass.pass;
117136 +#endif
117137 +}
117138 +
117139 +// data for the size_overflow asm stmt
117140 +struct asm_data {
117141 + gimple def_stmt;
117142 + tree input;
117143 + tree output;
117144 +};
117145 +
117146 +#if BUILDING_GCC_VERSION <= 4007
117147 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
117148 +#else
117149 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
117150 +#endif
117151 +{
117152 + tree list;
117153 +#if BUILDING_GCC_VERSION <= 4007
117154 + VEC(tree, gc) *vec_list = NULL;
117155 +#else
117156 + vec<tree, va_gc> *vec_list = NULL;
117157 +#endif
117158 +
117159 + list = build_tree_list(NULL_TREE, string);
117160 + list = chainon(NULL_TREE, build_tree_list(list, io));
117161 +#if BUILDING_GCC_VERSION <= 4007
117162 + VEC_safe_push(tree, gc, vec_list, list);
117163 +#else
117164 + vec_safe_push(vec_list, list);
117165 +#endif
117166 + return vec_list;
117167 +}
117168 +
117169 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
117170 +{
117171 + gimple asm_stmt;
117172 + gimple_stmt_iterator gsi;
117173 +#if BUILDING_GCC_VERSION <= 4007
117174 + VEC(tree, gc) *input, *output = NULL;
117175 +#else
117176 + vec<tree, va_gc> *input, *output = NULL;
117177 +#endif
117178 +
117179 + input = create_asm_io_list(str_input, asm_data->input);
117180 +
117181 + if (asm_data->output)
117182 + output = create_asm_io_list(str_output, asm_data->output);
117183 +
117184 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
117185 + gsi = gsi_for_stmt(asm_data->def_stmt);
117186 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
117187 +
117188 + if (asm_data->output)
117189 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
117190 +}
117191 +
117192 +static void replace_call_lhs(const struct asm_data *asm_data)
117193 +{
117194 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
117195 + update_stmt(asm_data->def_stmt);
117196 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
117197 +}
117198 +
117199 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
117200 +{
117201 + enum mark cur_fndecl_attr;
117202 + gimple phi = get_def_stmt(result);
117203 + unsigned int i, n = gimple_phi_num_args(phi);
117204 +
117205 + pointer_set_insert(visited, phi);
117206 + for (i = 0; i < n; i++) {
117207 + tree arg = gimple_phi_arg_def(phi, i);
117208 +
117209 + cur_fndecl_attr = search_intentional(visited, arg);
117210 + if (cur_fndecl_attr != MARK_NO)
117211 + return cur_fndecl_attr;
117212 + }
117213 + return MARK_NO;
117214 +}
117215 +
117216 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
117217 +{
117218 + enum mark cur_fndecl_attr;
117219 + const_tree rhs1, rhs2;
117220 + gimple def_stmt = get_def_stmt(lhs);
117221 +
117222 + rhs1 = gimple_assign_rhs1(def_stmt);
117223 + rhs2 = gimple_assign_rhs2(def_stmt);
117224 +
117225 + cur_fndecl_attr = search_intentional(visited, rhs1);
117226 + if (cur_fndecl_attr != MARK_NO)
117227 + return cur_fndecl_attr;
117228 + return search_intentional(visited, rhs2);
117229 +}
117230 +
117231 +// Look up the intentional_overflow attribute on the caller and the callee functions.
117232 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
117233 +{
117234 + const_gimple def_stmt;
117235 +
117236 + if (TREE_CODE(lhs) != SSA_NAME)
117237 + return get_intentional_attr_type(lhs);
117238 +
117239 + def_stmt = get_def_stmt(lhs);
117240 + if (!def_stmt)
117241 + return MARK_NO;
117242 +
117243 + if (pointer_set_contains(visited, def_stmt))
117244 + return MARK_NO;
117245 +
117246 + switch (gimple_code(def_stmt)) {
117247 + case GIMPLE_NOP:
117248 + return search_intentional(visited, SSA_NAME_VAR(lhs));
117249 + case GIMPLE_ASM:
117250 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
117251 + return MARK_TURN_OFF;
117252 + return MARK_NO;
117253 + case GIMPLE_CALL:
117254 + return MARK_NO;
117255 + case GIMPLE_PHI:
117256 + return search_intentional_phi(visited, lhs);
117257 + case GIMPLE_ASSIGN:
117258 + switch (gimple_num_ops(def_stmt)) {
117259 + case 2:
117260 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
117261 + case 3:
117262 + return search_intentional_binary(visited, lhs);
117263 + }
117264 + case GIMPLE_RETURN:
117265 + return MARK_NO;
117266 + default:
117267 + debug_gimple_stmt((gimple)def_stmt);
117268 + error("%s: unknown gimple code", __func__);
117269 + gcc_unreachable();
117270 + }
117271 +}
117272 +
117273 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
117274 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
117275 +{
117276 + const_tree fndecl;
117277 + struct pointer_set_t *visited;
117278 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
117279 +
117280 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
117281 + if (is_end_intentional_intentional_attr(fndecl, argnum))
117282 + decl_attr = MARK_NOT_INTENTIONAL;
117283 + else if (is_yes_intentional_attr(fndecl, argnum))
117284 + decl_attr = MARK_YES;
117285 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117286 + return MARK_TURN_OFF;
117287 + }
117288 +
117289 + visited = pointer_set_create();
117290 + cur_fndecl_attr = search_intentional(visited, arg);
117291 + pointer_set_destroy(visited);
117292 +
117293 + switch (cur_fndecl_attr) {
117294 + case MARK_NO:
117295 + case MARK_TURN_OFF:
117296 + return cur_fndecl_attr;
117297 + default:
117298 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
117299 + return MARK_YES;
117300 + }
117301 +}
117302 +
117303 +static void check_missing_size_overflow_attribute(tree var)
117304 +{
117305 + tree orig_fndecl;
117306 + unsigned int num;
117307 +
117308 + if (is_a_return_check(var))
117309 + orig_fndecl = DECL_ORIGIN(var);
117310 + else
117311 + orig_fndecl = DECL_ORIGIN(current_function_decl);
117312 +
117313 + num = get_function_num(var, orig_fndecl);
117314 + if (num == CANNOT_FIND_ARG)
117315 + return;
117316 +
117317 + is_missing_function(orig_fndecl, num);
117318 +}
117319 +
117320 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
117321 +{
117322 + gimple phi = get_def_stmt(result);
117323 + unsigned int i, n = gimple_phi_num_args(phi);
117324 +
117325 + pointer_set_insert(visited, phi);
117326 + for (i = 0; i < n; i++) {
117327 + tree arg = gimple_phi_arg_def(phi, i);
117328 +
117329 + search_size_overflow_attribute(visited, arg);
117330 + }
117331 +}
117332 +
117333 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
117334 +{
117335 + const_gimple def_stmt = get_def_stmt(lhs);
117336 + tree rhs1, rhs2;
117337 +
117338 + rhs1 = gimple_assign_rhs1(def_stmt);
117339 + rhs2 = gimple_assign_rhs2(def_stmt);
117340 +
117341 + search_size_overflow_attribute(visited, rhs1);
117342 + search_size_overflow_attribute(visited, rhs2);
117343 +}
117344 +
117345 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
117346 +{
117347 + const_gimple def_stmt;
117348 +
117349 + if (TREE_CODE(lhs) == PARM_DECL) {
117350 + check_missing_size_overflow_attribute(lhs);
117351 + return;
117352 + }
117353 +
117354 + def_stmt = get_def_stmt(lhs);
117355 + if (!def_stmt)
117356 + return;
117357 +
117358 + if (pointer_set_insert(visited, def_stmt))
117359 + return;
117360 +
117361 + switch (gimple_code(def_stmt)) {
117362 + case GIMPLE_NOP:
117363 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
117364 + case GIMPLE_ASM:
117365 + return;
117366 + case GIMPLE_CALL: {
117367 + tree fndecl = gimple_call_fndecl(def_stmt);
117368 +
117369 + if (fndecl == NULL_TREE)
117370 + return;
117371 + check_missing_size_overflow_attribute(fndecl);
117372 + return;
117373 + }
117374 + case GIMPLE_PHI:
117375 + return search_size_overflow_attribute_phi(visited, lhs);
117376 + case GIMPLE_ASSIGN:
117377 + switch (gimple_num_ops(def_stmt)) {
117378 + case 2:
117379 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
117380 + case 3:
117381 + return search_size_overflow_attribute_binary(visited, lhs);
117382 + }
117383 + default:
117384 + debug_gimple_stmt((gimple)def_stmt);
117385 + error("%s: unknown gimple code", __func__);
117386 + gcc_unreachable();
117387 + }
117388 +}
117389 +
117390 +// Search missing entries in the hash table (invoked from the gimple pass)
117391 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
117392 +{
117393 + tree fndecl = NULL_TREE;
117394 + tree lhs;
117395 + struct pointer_set_t *visited;
117396 +
117397 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
117398 + return;
117399 +
117400 + if (num == 0) {
117401 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
117402 + lhs = gimple_return_retval(stmt);
117403 + } else {
117404 + gcc_assert(is_gimple_call(stmt));
117405 + lhs = gimple_call_arg(stmt, num - 1);
117406 + fndecl = gimple_call_fndecl(stmt);
117407 + }
117408 +
117409 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
117410 + return;
117411 +
117412 + visited = pointer_set_create();
117413 + search_size_overflow_attribute(visited, lhs);
117414 + pointer_set_destroy(visited);
117415 +}
117416 +
117417 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
117418 +{
117419 + gimple_stmt_iterator gsi;
117420 + gimple assign;
117421 +
117422 + assign = gimple_build_assign(asm_data->input, asm_data->output);
117423 + gsi = gsi_for_stmt(stmt);
117424 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117425 + asm_data->def_stmt = assign;
117426 +
117427 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
117428 + asm_data->output = make_ssa_name(asm_data->output, stmt);
117429 + if (gimple_code(stmt) == GIMPLE_RETURN)
117430 + gimple_return_set_retval(stmt, asm_data->output);
117431 + else
117432 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
117433 + update_stmt(stmt);
117434 +}
117435 +
117436 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
117437 +{
117438 + const char *fn_name;
117439 + char *asm_comment;
117440 + unsigned int len;
117441 +
117442 + if (argnum == 0)
117443 + fn_name = DECL_NAME_POINTER(current_function_decl);
117444 + else
117445 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
117446 +
117447 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
117448 + gcc_assert(len > 0);
117449 +
117450 + return asm_comment;
117451 +}
117452 +
117453 +static const char *convert_mark_to_str(enum mark mark)
117454 +{
117455 + switch (mark) {
117456 + case MARK_NO:
117457 + return OK_ASM_STR;
117458 + case MARK_YES:
117459 + case MARK_NOT_INTENTIONAL:
117460 + return YES_ASM_STR;
117461 + case MARK_TURN_OFF:
117462 + return TURN_OFF_ASM_STR;
117463 + }
117464 +
117465 + gcc_unreachable();
117466 +}
117467 +
117468 +/* Create the input of the size_overflow asm stmt.
117469 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
117470 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
117471 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
117472 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
117473 + */
117474 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
117475 +{
117476 + if (!asm_data->def_stmt) {
117477 + asm_data->input = NULL_TREE;
117478 + return;
117479 + }
117480 +
117481 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
117482 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
117483 +
117484 + switch (gimple_code(asm_data->def_stmt)) {
117485 + case GIMPLE_ASSIGN:
117486 + case GIMPLE_CALL:
117487 + replace_call_lhs(asm_data);
117488 + break;
117489 + case GIMPLE_PHI:
117490 + create_output_from_phi(stmt, argnum, asm_data);
117491 + break;
117492 + case GIMPLE_NOP: {
117493 + enum mark mark;
117494 + const char *mark_str;
117495 + char *asm_comment;
117496 +
117497 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
117498 +
117499 + asm_data->input = asm_data->output;
117500 + asm_data->output = NULL;
117501 + asm_data->def_stmt = stmt;
117502 +
117503 + mark_str = convert_mark_to_str(mark);
117504 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
117505 +
117506 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
117507 + free(asm_comment);
117508 + asm_data->input = NULL_TREE;
117509 + break;
117510 + }
117511 + case GIMPLE_ASM:
117512 + if (is_size_overflow_asm(asm_data->def_stmt)) {
117513 + asm_data->input = NULL_TREE;
117514 + break;
117515 + }
117516 + default:
117517 + debug_gimple_stmt(asm_data->def_stmt);
117518 + gcc_unreachable();
117519 + }
117520 +}
117521 +
117522 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
117523 + * is of the right kind create the appropriate size_overflow asm stmts:
117524 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
117525 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
117526 + */
117527 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
117528 +{
117529 + struct asm_data asm_data;
117530 + const char *mark_str;
117531 + char *asm_comment;
117532 + enum mark mark;
117533 +
117534 + if (is_gimple_constant(output_node))
117535 + return;
117536 +
117537 + asm_data.output = output_node;
117538 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
117539 + if (mark != MARK_TURN_OFF)
117540 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
117541 +
117542 + asm_data.def_stmt = get_def_stmt(asm_data.output);
117543 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
117544 + return;
117545 +
117546 + create_asm_input(stmt, argnum, &asm_data);
117547 + if (asm_data.input == NULL_TREE)
117548 + return;
117549 +
117550 + mark_str = convert_mark_to_str(mark);
117551 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
117552 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
117553 + free(asm_comment);
117554 +}
117555 +
117556 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
117557 +static bool create_mark_asm(gimple stmt, enum mark mark)
117558 +{
117559 + struct asm_data asm_data;
117560 + const char *asm_str;
117561 +
117562 + switch (mark) {
117563 + case MARK_TURN_OFF:
117564 + asm_str = TURN_OFF_ASM_STR;
117565 + break;
117566 + case MARK_NOT_INTENTIONAL:
117567 + case MARK_YES:
117568 + asm_str = YES_ASM_STR;
117569 + break;
117570 + default:
117571 + gcc_unreachable();
117572 + }
117573 +
117574 + asm_data.def_stmt = stmt;
117575 + asm_data.output = gimple_call_lhs(stmt);
117576 +
117577 + if (asm_data.output == NULL_TREE) {
117578 + asm_data.input = gimple_call_arg(stmt, 0);
117579 + if (is_gimple_constant(asm_data.input))
117580 + return false;
117581 + asm_data.output = NULL;
117582 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
117583 + return true;
117584 + }
117585 +
117586 + create_asm_input(stmt, 0, &asm_data);
117587 + gcc_assert(asm_data.input != NULL_TREE);
117588 +
117589 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
117590 + return true;
117591 +}
117592 +
117593 +static bool is_from_cast(const_tree node)
117594 +{
117595 + gimple def_stmt = get_def_stmt(node);
117596 +
117597 + if (!def_stmt)
117598 + return false;
117599 +
117600 + if (gimple_assign_cast_p(def_stmt))
117601 + return true;
117602 +
117603 + return false;
117604 +}
117605 +
117606 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
117607 +static bool skip_ptr_minus(gimple stmt)
117608 +{
117609 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
117610 +
117611 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
117612 + return false;
117613 +
117614 + rhs1 = gimple_assign_rhs1(stmt);
117615 + if (!is_from_cast(rhs1))
117616 + return false;
117617 +
117618 + rhs2 = gimple_assign_rhs2(stmt);
117619 + if (!is_from_cast(rhs2))
117620 + return false;
117621 +
117622 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
117623 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
117624 +
117625 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
117626 + return false;
117627 +
117628 + create_mark_asm(stmt, MARK_YES);
117629 + return true;
117630 +}
117631 +
117632 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
117633 +{
117634 + gimple def_stmt;
117635 +
117636 + def_stmt = get_def_stmt(lhs);
117637 + if (!def_stmt)
117638 + return;
117639 +
117640 + if (pointer_set_insert(visited, def_stmt))
117641 + return;
117642 +
117643 + switch (gimple_code(def_stmt)) {
117644 + case GIMPLE_NOP:
117645 + case GIMPLE_ASM:
117646 + case GIMPLE_CALL:
117647 + break;
117648 + case GIMPLE_PHI: {
117649 + unsigned int i, n = gimple_phi_num_args(def_stmt);
117650 +
117651 + pointer_set_insert(visited, def_stmt);
117652 +
117653 + for (i = 0; i < n; i++) {
117654 + tree arg = gimple_phi_arg_def(def_stmt, i);
117655 +
117656 + walk_use_def_ptr(visited, arg);
117657 + }
117658 + }
117659 + case GIMPLE_ASSIGN:
117660 + switch (gimple_num_ops(def_stmt)) {
117661 + case 2:
117662 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
117663 + return;
117664 + case 3:
117665 + if (skip_ptr_minus(def_stmt))
117666 + return;
117667 +
117668 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
117669 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
117670 + return;
117671 + default:
117672 + return;
117673 + }
117674 + default:
117675 + debug_gimple_stmt((gimple)def_stmt);
117676 + error("%s: unknown gimple code", __func__);
117677 + gcc_unreachable();
117678 + }
117679 +}
117680 +
117681 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
117682 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
117683 +{
117684 + struct pointer_set_t *visited;
117685 +
117686 + visited = pointer_set_create();
117687 + walk_use_def_ptr(visited, arg);
117688 + pointer_set_destroy(visited);
117689 +}
117690 +
117691 +// Determine the return value and insert the asm stmt to mark the return stmt.
117692 +static void insert_asm_ret(gimple stmt)
117693 +{
117694 + tree ret;
117695 +
117696 + ret = gimple_return_retval(stmt);
117697 + create_size_overflow_asm(stmt, ret, 0);
117698 +}
117699 +
117700 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
117701 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
117702 +{
117703 + tree arg;
117704 + unsigned int argnum;
117705 +
117706 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
117707 + gcc_assert(argnum != 0);
117708 + if (argnum == CANNOT_FIND_ARG)
117709 + return;
117710 +
117711 + arg = gimple_call_arg(stmt, argnum - 1);
117712 + gcc_assert(arg != NULL_TREE);
117713 +
117714 + // skip all ptr - ptr expressions
117715 + insert_mark_not_intentional_asm_at_ptr(arg);
117716 +
117717 + create_size_overflow_asm(stmt, arg, argnum);
117718 +}
117719 +
117720 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
117721 +static void set_argnum_attribute(const_tree attr, bool *argnums)
117722 +{
117723 + unsigned int argnum;
117724 + tree attr_value;
117725 +
117726 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
117727 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
117728 + argnums[argnum] = true;
117729 + }
117730 +}
117731 +
117732 +// If a function arg or the return value is in the hash table then set its index in the array.
117733 +static void set_argnum_hash(tree fndecl, bool *argnums)
117734 +{
117735 + unsigned int num;
117736 + const struct size_overflow_hash *hash;
117737 +
117738 + hash = get_function_hash(DECL_ORIGIN(fndecl));
117739 + if (!hash)
117740 + return;
117741 +
117742 + for (num = 0; num <= MAX_PARAM; num++) {
117743 + if (!(hash->param & (1U << num)))
117744 + continue;
117745 +
117746 + argnums[num] = true;
117747 + }
117748 +}
117749 +
117750 +static bool is_all_the_argnums_empty(bool *argnums)
117751 +{
117752 + unsigned int i;
117753 +
117754 + for (i = 0; i <= MAX_PARAM; i++)
117755 + if (argnums[i])
117756 + return false;
117757 + return true;
117758 +}
117759 +
117760 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
117761 +static void search_interesting_args(tree fndecl, bool *argnums)
117762 +{
117763 + const_tree attr;
117764 +
117765 + set_argnum_hash(fndecl, argnums);
117766 + if (!is_all_the_argnums_empty(argnums))
117767 + return;
117768 +
117769 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
117770 + if (attr && TREE_VALUE(attr))
117771 + set_argnum_attribute(attr, argnums);
117772 +}
117773 +
117774 +/*
117775 + * Look up the intentional_overflow attribute that turns off ipa based duplication
117776 + * on the callee function.
117777 + */
117778 +static bool is_mark_turn_off_attribute(gimple stmt)
117779 +{
117780 + enum mark mark;
117781 + const_tree fndecl = gimple_call_fndecl(stmt);
117782 +
117783 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
117784 + if (mark == MARK_TURN_OFF)
117785 + return true;
117786 + return false;
117787 +}
117788 +
117789 +// 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
117790 +static void handle_interesting_function(gimple stmt)
117791 +{
117792 + unsigned int argnum;
117793 + tree fndecl;
117794 + bool orig_argnums[MAX_PARAM + 1] = {false};
117795 +
117796 + if (gimple_call_num_args(stmt) == 0)
117797 + return;
117798 + fndecl = gimple_call_fndecl(stmt);
117799 + if (fndecl == NULL_TREE)
117800 + return;
117801 + fndecl = DECL_ORIGIN(fndecl);
117802 +
117803 + if (is_mark_turn_off_attribute(stmt)) {
117804 + create_mark_asm(stmt, MARK_TURN_OFF);
117805 + return;
117806 + }
117807 +
117808 + search_interesting_args(fndecl, orig_argnums);
117809 +
117810 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
117811 + if (orig_argnums[argnum])
117812 + insert_asm_arg(stmt, argnum);
117813 +}
117814 +
117815 +// 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
117816 +static void handle_interesting_ret(gimple stmt)
117817 +{
117818 + bool orig_argnums[MAX_PARAM + 1] = {false};
117819 +
117820 + search_interesting_args(current_function_decl, orig_argnums);
117821 +
117822 + if (orig_argnums[0])
117823 + insert_asm_ret(stmt);
117824 +}
117825 +
117826 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
117827 +static unsigned int search_interesting_functions(void)
117828 +{
117829 + basic_block bb;
117830 +
117831 + FOR_ALL_BB_FN(bb, cfun) {
117832 + gimple_stmt_iterator gsi;
117833 +
117834 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117835 + gimple stmt = gsi_stmt(gsi);
117836 +
117837 + if (is_size_overflow_asm(stmt))
117838 + continue;
117839 +
117840 + if (is_gimple_call(stmt))
117841 + handle_interesting_function(stmt);
117842 + else if (gimple_code(stmt) == GIMPLE_RETURN)
117843 + handle_interesting_ret(stmt);
117844 + }
117845 + }
117846 + return 0;
117847 +}
117848 +
117849 +/*
117850 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
117851 + * this pass inserts asm stmts to mark the interesting args
117852 + * that the ipa pass will detect and insert the size overflow checks for.
117853 + */
117854 +#if BUILDING_GCC_VERSION >= 4009
117855 +static const struct pass_data insert_size_overflow_asm_pass_data = {
117856 +#else
117857 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
117858 + .pass = {
117859 +#endif
117860 + .type = GIMPLE_PASS,
117861 + .name = "insert_size_overflow_asm",
117862 +#if BUILDING_GCC_VERSION >= 4008
117863 + .optinfo_flags = OPTGROUP_NONE,
117864 +#endif
117865 +#if BUILDING_GCC_VERSION >= 4009
117866 + .has_gate = false,
117867 + .has_execute = true,
117868 +#else
117869 + .gate = NULL,
117870 + .execute = search_interesting_functions,
117871 + .sub = NULL,
117872 + .next = NULL,
117873 + .static_pass_number = 0,
117874 +#endif
117875 + .tv_id = TV_NONE,
117876 + .properties_required = PROP_cfg,
117877 + .properties_provided = 0,
117878 + .properties_destroyed = 0,
117879 + .todo_flags_start = 0,
117880 + .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
117881 +#if BUILDING_GCC_VERSION < 4009
117882 + }
117883 +#endif
117884 +};
117885 +
117886 +#if BUILDING_GCC_VERSION >= 4009
117887 +namespace {
117888 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
117889 +public:
117890 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
117891 + unsigned int execute() { return search_interesting_functions(); }
117892 +};
117893 +}
117894 +#endif
117895 +
117896 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
117897 +{
117898 +#if BUILDING_GCC_VERSION >= 4009
117899 + return new insert_size_overflow_asm_pass();
117900 +#else
117901 + return &insert_size_overflow_asm_pass.pass;
117902 +#endif
117903 +}
117904 +
117905 +// Create the noreturn report_size_overflow() function decl.
117906 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
117907 +{
117908 + tree const_char_ptr_type_node;
117909 + tree fntype;
117910 +
117911 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
117912 +
117913 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
117914 + fntype = build_function_type_list(void_type_node,
117915 + const_char_ptr_type_node,
117916 + unsigned_type_node,
117917 + const_char_ptr_type_node,
117918 + const_char_ptr_type_node,
117919 + NULL_TREE);
117920 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
117921 +
117922 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
117923 + TREE_PUBLIC(report_size_overflow_decl) = 1;
117924 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
117925 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
117926 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
117927 +}
117928 +
117929 +static unsigned int dump_functions(void)
117930 +{
117931 + struct cgraph_node *node;
117932 +
117933 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117934 + basic_block bb;
117935 +
117936 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
117937 + current_function_decl = NODE_DECL(node);
117938 +
117939 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
117940 +
117941 + FOR_ALL_BB_FN(bb, cfun) {
117942 + gimple_stmt_iterator si;
117943 +
117944 + fprintf(stderr, "<bb %u>:\n", bb->index);
117945 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117946 + debug_gimple_stmt(gsi_stmt(si));
117947 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117948 + debug_gimple_stmt(gsi_stmt(si));
117949 + fprintf(stderr, "\n");
117950 + }
117951 +
117952 + fprintf(stderr, "-------------------------------------------------------------------------\n");
117953 +
117954 + pop_cfun();
117955 + current_function_decl = NULL_TREE;
117956 + }
117957 +
117958 + fprintf(stderr, "###############################################################################\n");
117959 +
117960 + return 0;
117961 +}
117962 +
117963 +#if BUILDING_GCC_VERSION >= 4009
117964 +static const struct pass_data dump_pass_data = {
117965 +#else
117966 +static struct ipa_opt_pass_d dump_pass = {
117967 + .pass = {
117968 +#endif
117969 + .type = SIMPLE_IPA_PASS,
117970 + .name = "dump",
117971 +#if BUILDING_GCC_VERSION >= 4008
117972 + .optinfo_flags = OPTGROUP_NONE,
117973 +#endif
117974 +#if BUILDING_GCC_VERSION >= 4009
117975 + .has_gate = false,
117976 + .has_execute = true,
117977 +#else
117978 + .gate = NULL,
117979 + .execute = dump_functions,
117980 + .sub = NULL,
117981 + .next = NULL,
117982 + .static_pass_number = 0,
117983 +#endif
117984 + .tv_id = TV_NONE,
117985 + .properties_required = 0,
117986 + .properties_provided = 0,
117987 + .properties_destroyed = 0,
117988 + .todo_flags_start = 0,
117989 + .todo_flags_finish = 0,
117990 +#if BUILDING_GCC_VERSION < 4009
117991 + },
117992 + .generate_summary = NULL,
117993 + .write_summary = NULL,
117994 + .read_summary = NULL,
117995 +#if BUILDING_GCC_VERSION >= 4006
117996 + .write_optimization_summary = NULL,
117997 + .read_optimization_summary = NULL,
117998 +#endif
117999 + .stmt_fixup = NULL,
118000 + .function_transform_todo_flags_start = 0,
118001 + .function_transform = NULL,
118002 + .variable_transform = NULL,
118003 +#endif
118004 +};
118005 +
118006 +#if BUILDING_GCC_VERSION >= 4009
118007 +namespace {
118008 +class dump_pass : public ipa_opt_pass_d {
118009 +public:
118010 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118011 + unsigned int execute() { return dump_functions(); }
118012 +};
118013 +}
118014 +#endif
118015 +
118016 +static struct opt_pass *make_dump_pass(void)
118017 +{
118018 +#if BUILDING_GCC_VERSION >= 4009
118019 + return new dump_pass();
118020 +#else
118021 + return &dump_pass.pass;
118022 +#endif
118023 +}
118024 +
118025 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118026 +{
118027 + int i;
118028 + const char * const plugin_name = plugin_info->base_name;
118029 + const int argc = plugin_info->argc;
118030 + const struct plugin_argument * const argv = plugin_info->argv;
118031 + bool enable = true;
118032 + struct register_pass_info insert_size_overflow_asm_pass_info;
118033 + struct register_pass_info __unused dump_before_pass_info;
118034 + struct register_pass_info __unused dump_after_pass_info;
118035 + struct register_pass_info ipa_pass_info;
118036 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
118037 + {
118038 + .base = &report_size_overflow_decl,
118039 + .nelt = 1,
118040 + .stride = sizeof(report_size_overflow_decl),
118041 + .cb = &gt_ggc_mx_tree_node,
118042 + .pchw = &gt_pch_nx_tree_node
118043 + },
118044 + LAST_GGC_ROOT_TAB
118045 + };
118046 +
118047 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
118048 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
118049 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
118050 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118051 +
118052 + dump_before_pass_info.pass = make_dump_pass();
118053 + dump_before_pass_info.reference_pass_name = "increase_alignment";
118054 + dump_before_pass_info.ref_pass_instance_number = 1;
118055 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118056 +
118057 + ipa_pass_info.pass = make_ipa_pass();
118058 + ipa_pass_info.reference_pass_name = "increase_alignment";
118059 + ipa_pass_info.ref_pass_instance_number = 1;
118060 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118061 +
118062 + dump_after_pass_info.pass = make_dump_pass();
118063 + dump_after_pass_info.reference_pass_name = "increase_alignment";
118064 + dump_after_pass_info.ref_pass_instance_number = 1;
118065 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118066 +
118067 + if (!plugin_default_version_check(version, &gcc_version)) {
118068 + error(G_("incompatible gcc/plugin versions"));
118069 + return 1;
118070 + }
118071 +
118072 + for (i = 0; i < argc; ++i) {
118073 + if (!strcmp(argv[i].key, "no-size-overflow")) {
118074 + enable = false;
118075 + continue;
118076 + }
118077 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118078 + }
118079 +
118080 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
118081 + if (enable) {
118082 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
118083 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
118084 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
118085 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
118086 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
118087 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
118088 + }
118089 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
118090 +
118091 + return 0;
118092 +}
118093 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
118094 new file mode 100644
118095 index 0000000..5c0b937
118096 --- /dev/null
118097 +++ b/tools/gcc/stackleak_plugin.c
118098 @@ -0,0 +1,374 @@
118099 +/*
118100 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
118101 + * Licensed under the GPL v2
118102 + *
118103 + * Note: the choice of the license means that the compilation process is
118104 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
118105 + * but for the kernel it doesn't matter since it doesn't link against
118106 + * any of the gcc libraries
118107 + *
118108 + * gcc plugin to help implement various PaX features
118109 + *
118110 + * - track lowest stack pointer
118111 + *
118112 + * TODO:
118113 + * - initialize all local variables
118114 + *
118115 + * BUGS:
118116 + * - none known
118117 + */
118118 +
118119 +#include "gcc-common.h"
118120 +
118121 +int plugin_is_GPL_compatible;
118122 +
118123 +static int track_frame_size = -1;
118124 +static const char track_function[] = "pax_track_stack";
118125 +static const char check_function[] = "pax_check_alloca";
118126 +static tree track_function_decl, check_function_decl;
118127 +static bool init_locals;
118128 +
118129 +static struct plugin_info stackleak_plugin_info = {
118130 + .version = "201402131920",
118131 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
118132 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
118133 +};
118134 +
118135 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
118136 +{
118137 + gimple check_alloca;
118138 + tree alloca_size;
118139 +
118140 + // insert call to void pax_check_alloca(unsigned long size)
118141 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
118142 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
118143 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
118144 +}
118145 +
118146 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
118147 +{
118148 + gimple track_stack;
118149 +
118150 + // insert call to void pax_track_stack(void)
118151 + track_stack = gimple_build_call(track_function_decl, 0);
118152 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
118153 +}
118154 +
118155 +static bool is_alloca(gimple stmt)
118156 +{
118157 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
118158 + return true;
118159 +
118160 +#if BUILDING_GCC_VERSION >= 4007
118161 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
118162 + return true;
118163 +#endif
118164 +
118165 + return false;
118166 +}
118167 +
118168 +static unsigned int execute_stackleak_tree_instrument(void)
118169 +{
118170 + basic_block bb, entry_bb;
118171 + bool prologue_instrumented = false, is_leaf = true;
118172 +
118173 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
118174 +
118175 + // 1. loop through BBs and GIMPLE statements
118176 + FOR_EACH_BB_FN(bb, cfun) {
118177 + gimple_stmt_iterator gsi;
118178 +
118179 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118180 + gimple stmt;
118181 +
118182 + stmt = gsi_stmt(gsi);
118183 +
118184 + if (is_gimple_call(stmt))
118185 + is_leaf = false;
118186 +
118187 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
118188 + if (!is_alloca(stmt))
118189 + continue;
118190 +
118191 + // 2. insert stack overflow check before each __builtin_alloca call
118192 + stackleak_check_alloca(&gsi);
118193 +
118194 + // 3. insert track call after each __builtin_alloca call
118195 + stackleak_add_instrumentation(&gsi);
118196 + if (bb == entry_bb)
118197 + prologue_instrumented = true;
118198 + }
118199 + }
118200 +
118201 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
118202 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
118203 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
118204 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
118205 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
118206 + return 0;
118207 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
118208 + return 0;
118209 +
118210 + // 4. insert track call at the beginning
118211 + if (!prologue_instrumented) {
118212 + gimple_stmt_iterator gsi;
118213 +
118214 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
118215 + if (dom_info_available_p(CDI_DOMINATORS))
118216 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
118217 + gsi = gsi_start_bb(bb);
118218 + stackleak_add_instrumentation(&gsi);
118219 + }
118220 +
118221 + return 0;
118222 +}
118223 +
118224 +static unsigned int execute_stackleak_final(void)
118225 +{
118226 + rtx insn, next;
118227 +
118228 + if (cfun->calls_alloca)
118229 + return 0;
118230 +
118231 + // keep calls only if function frame is big enough
118232 + if (get_frame_size() >= track_frame_size)
118233 + return 0;
118234 +
118235 + // 1. find pax_track_stack calls
118236 + for (insn = get_insns(); insn; insn = next) {
118237 + // 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))
118238 + rtx body;
118239 +
118240 + next = NEXT_INSN(insn);
118241 + if (!CALL_P(insn))
118242 + continue;
118243 + body = PATTERN(insn);
118244 + if (GET_CODE(body) != CALL)
118245 + continue;
118246 + body = XEXP(body, 0);
118247 + if (GET_CODE(body) != MEM)
118248 + continue;
118249 + body = XEXP(body, 0);
118250 + if (GET_CODE(body) != SYMBOL_REF)
118251 + continue;
118252 +// if (strcmp(XSTR(body, 0), track_function))
118253 + if (SYMBOL_REF_DECL(body) != track_function_decl)
118254 + continue;
118255 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
118256 + // 2. delete call
118257 + delete_insn_and_edges(insn);
118258 +#if BUILDING_GCC_VERSION >= 4007
118259 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
118260 + insn = next;
118261 + next = NEXT_INSN(insn);
118262 + delete_insn_and_edges(insn);
118263 + }
118264 +#endif
118265 + }
118266 +
118267 +// print_simple_rtl(stderr, get_insns());
118268 +// print_rtl(stderr, get_insns());
118269 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
118270 +
118271 + return 0;
118272 +}
118273 +
118274 +static bool gate_stackleak_track_stack(void)
118275 +{
118276 + return track_frame_size >= 0;
118277 +}
118278 +
118279 +static void stackleak_start_unit(void *gcc_data, void *user_data)
118280 +{
118281 + tree fntype;
118282 +
118283 + // void pax_track_stack(void)
118284 + fntype = build_function_type_list(void_type_node, NULL_TREE);
118285 + track_function_decl = build_fn_decl(track_function, fntype);
118286 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
118287 + TREE_PUBLIC(track_function_decl) = 1;
118288 + DECL_EXTERNAL(track_function_decl) = 1;
118289 + DECL_ARTIFICIAL(track_function_decl) = 1;
118290 +
118291 + // void pax_check_alloca(unsigned long)
118292 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
118293 + check_function_decl = build_fn_decl(check_function, fntype);
118294 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
118295 + TREE_PUBLIC(check_function_decl) = 1;
118296 + DECL_EXTERNAL(check_function_decl) = 1;
118297 + DECL_ARTIFICIAL(check_function_decl) = 1;
118298 +}
118299 +
118300 +#if BUILDING_GCC_VERSION >= 4009
118301 +static const struct pass_data stackleak_tree_instrument_pass_data = {
118302 +#else
118303 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
118304 + .pass = {
118305 +#endif
118306 + .type = GIMPLE_PASS,
118307 + .name = "stackleak_tree_instrument",
118308 +#if BUILDING_GCC_VERSION >= 4008
118309 + .optinfo_flags = OPTGROUP_NONE,
118310 +#endif
118311 +#if BUILDING_GCC_VERSION >= 4009
118312 + .has_gate = true,
118313 + .has_execute = true,
118314 +#else
118315 + .gate = gate_stackleak_track_stack,
118316 + .execute = execute_stackleak_tree_instrument,
118317 + .sub = NULL,
118318 + .next = NULL,
118319 + .static_pass_number = 0,
118320 +#endif
118321 + .tv_id = TV_NONE,
118322 + .properties_required = PROP_gimple_leh | PROP_cfg,
118323 + .properties_provided = 0,
118324 + .properties_destroyed = 0,
118325 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
118326 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
118327 +#if BUILDING_GCC_VERSION < 4009
118328 + }
118329 +#endif
118330 +};
118331 +
118332 +#if BUILDING_GCC_VERSION >= 4009
118333 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
118334 +#else
118335 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
118336 + .pass = {
118337 +#endif
118338 + .type = RTL_PASS,
118339 + .name = "stackleak_final",
118340 +#if BUILDING_GCC_VERSION >= 4008
118341 + .optinfo_flags = OPTGROUP_NONE,
118342 +#endif
118343 +#if BUILDING_GCC_VERSION >= 4009
118344 + .has_gate = true,
118345 + .has_execute = true,
118346 +#else
118347 + .gate = gate_stackleak_track_stack,
118348 + .execute = execute_stackleak_final,
118349 + .sub = NULL,
118350 + .next = NULL,
118351 + .static_pass_number = 0,
118352 +#endif
118353 + .tv_id = TV_NONE,
118354 + .properties_required = 0,
118355 + .properties_provided = 0,
118356 + .properties_destroyed = 0,
118357 + .todo_flags_start = 0,
118358 + .todo_flags_finish = TODO_dump_func
118359 +#if BUILDING_GCC_VERSION < 4009
118360 + }
118361 +#endif
118362 +};
118363 +
118364 +#if BUILDING_GCC_VERSION >= 4009
118365 +namespace {
118366 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
118367 +public:
118368 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
118369 + bool gate() { return gate_stackleak_track_stack(); }
118370 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
118371 +};
118372 +
118373 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
118374 +public:
118375 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
118376 + bool gate() { return gate_stackleak_track_stack(); }
118377 + unsigned int execute() { return execute_stackleak_final(); }
118378 +};
118379 +}
118380 +#endif
118381 +
118382 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
118383 +{
118384 +#if BUILDING_GCC_VERSION >= 4009
118385 + return new stackleak_tree_instrument_pass();
118386 +#else
118387 + return &stackleak_tree_instrument_pass.pass;
118388 +#endif
118389 +}
118390 +
118391 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
118392 +{
118393 +#if BUILDING_GCC_VERSION >= 4009
118394 + return new stackleak_final_rtl_opt_pass();
118395 +#else
118396 + return &stackleak_final_rtl_opt_pass.pass;
118397 +#endif
118398 +}
118399 +
118400 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118401 +{
118402 + const char * const plugin_name = plugin_info->base_name;
118403 + const int argc = plugin_info->argc;
118404 + const struct plugin_argument * const argv = plugin_info->argv;
118405 + int i;
118406 + struct register_pass_info stackleak_tree_instrument_pass_info;
118407 + struct register_pass_info stackleak_final_pass_info;
118408 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
118409 + {
118410 + .base = &track_function_decl,
118411 + .nelt = 1,
118412 + .stride = sizeof(track_function_decl),
118413 + .cb = &gt_ggc_mx_tree_node,
118414 + .pchw = &gt_pch_nx_tree_node
118415 + },
118416 + {
118417 + .base = &check_function_decl,
118418 + .nelt = 1,
118419 + .stride = sizeof(check_function_decl),
118420 + .cb = &gt_ggc_mx_tree_node,
118421 + .pchw = &gt_pch_nx_tree_node
118422 + },
118423 + LAST_GGC_ROOT_TAB
118424 + };
118425 +
118426 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
118427 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
118428 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
118429 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
118430 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118431 +
118432 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
118433 + stackleak_final_pass_info.reference_pass_name = "final";
118434 + stackleak_final_pass_info.ref_pass_instance_number = 1;
118435 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118436 +
118437 + if (!plugin_default_version_check(version, &gcc_version)) {
118438 + error(G_("incompatible gcc/plugin versions"));
118439 + return 1;
118440 + }
118441 +
118442 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
118443 +
118444 + for (i = 0; i < argc; ++i) {
118445 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
118446 + if (!argv[i].value) {
118447 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118448 + continue;
118449 + }
118450 + track_frame_size = atoi(argv[i].value);
118451 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
118452 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
118453 + continue;
118454 + }
118455 + if (!strcmp(argv[i].key, "initialize-locals")) {
118456 + if (argv[i].value) {
118457 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
118458 + continue;
118459 + }
118460 + init_locals = true;
118461 + continue;
118462 + }
118463 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118464 + }
118465 +
118466 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
118467 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
118468 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
118469 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
118470 +
118471 + return 0;
118472 +}
118473 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
118474 new file mode 100644
118475 index 0000000..796569a
118476 --- /dev/null
118477 +++ b/tools/gcc/structleak_plugin.c
118478 @@ -0,0 +1,273 @@
118479 +/*
118480 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
118481 + * Licensed under the GPL v2
118482 + *
118483 + * Note: the choice of the license means that the compilation process is
118484 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
118485 + * but for the kernel it doesn't matter since it doesn't link against
118486 + * any of the gcc libraries
118487 + *
118488 + * gcc plugin to forcibly initialize certain local variables that could
118489 + * otherwise leak kernel stack to userland if they aren't properly initialized
118490 + * by later code
118491 + *
118492 + * Homepage: http://pax.grsecurity.net/
118493 + *
118494 + * Usage:
118495 + * $ # for 4.5/4.6/C based 4.7
118496 + * $ 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
118497 + * $ # for C++ based 4.7/4.8+
118498 + * $ 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
118499 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
118500 + *
118501 + * TODO: eliminate redundant initializers
118502 + * increase type coverage
118503 + */
118504 +
118505 +#include "gcc-common.h"
118506 +
118507 +// unused C type flag in all versions 4.5-4.9
118508 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
118509 +
118510 +int plugin_is_GPL_compatible;
118511 +
118512 +static struct plugin_info structleak_plugin_info = {
118513 + .version = "201401260140",
118514 + .help = "disable\tdo not activate plugin\n",
118515 +};
118516 +
118517 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
118518 +{
118519 + *no_add_attrs = true;
118520 +
118521 + // check for types? for now accept everything linux has to offer
118522 + if (TREE_CODE(*node) != FIELD_DECL)
118523 + return NULL_TREE;
118524 +
118525 + *no_add_attrs = false;
118526 + return NULL_TREE;
118527 +}
118528 +
118529 +static struct attribute_spec user_attr = {
118530 + .name = "user",
118531 + .min_length = 0,
118532 + .max_length = 0,
118533 + .decl_required = false,
118534 + .type_required = false,
118535 + .function_type_required = false,
118536 + .handler = handle_user_attribute,
118537 +#if BUILDING_GCC_VERSION >= 4007
118538 + .affects_type_identity = true
118539 +#endif
118540 +};
118541 +
118542 +static void register_attributes(void *event_data, void *data)
118543 +{
118544 + register_attribute(&user_attr);
118545 +// register_attribute(&force_attr);
118546 +}
118547 +
118548 +static tree get_field_type(tree field)
118549 +{
118550 + return strip_array_types(TREE_TYPE(field));
118551 +}
118552 +
118553 +static bool is_userspace_type(tree type)
118554 +{
118555 + tree field;
118556 +
118557 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
118558 + tree fieldtype = get_field_type(field);
118559 + enum tree_code code = TREE_CODE(fieldtype);
118560 +
118561 + if (code == RECORD_TYPE || code == UNION_TYPE)
118562 + if (is_userspace_type(fieldtype))
118563 + return true;
118564 +
118565 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
118566 + return true;
118567 + }
118568 + return false;
118569 +}
118570 +
118571 +static void finish_type(void *event_data, void *data)
118572 +{
118573 + tree type = (tree)event_data;
118574 +
118575 + if (TYPE_USERSPACE(type))
118576 + return;
118577 +
118578 + if (is_userspace_type(type))
118579 + TYPE_USERSPACE(type) = 1;
118580 +}
118581 +
118582 +static void initialize(tree var)
118583 +{
118584 + basic_block bb;
118585 + gimple_stmt_iterator gsi;
118586 + tree initializer;
118587 + gimple init_stmt;
118588 +
118589 + // this is the original entry bb before the forced split
118590 + // TODO: check further BBs in case more splits occured before us
118591 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
118592 +
118593 + // first check if the variable is already initialized, warn otherwise
118594 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118595 + gimple stmt = gsi_stmt(gsi);
118596 + tree rhs1;
118597 +
118598 + // we're looking for an assignment of a single rhs...
118599 + if (!gimple_assign_single_p(stmt))
118600 + continue;
118601 + rhs1 = gimple_assign_rhs1(stmt);
118602 +#if BUILDING_GCC_VERSION >= 4007
118603 + // ... of a non-clobbering expression...
118604 + if (TREE_CLOBBER_P(rhs1))
118605 + continue;
118606 +#endif
118607 + // ... to our variable...
118608 + if (gimple_get_lhs(stmt) != var)
118609 + continue;
118610 + // if it's an initializer then we're good
118611 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
118612 + return;
118613 + }
118614 +
118615 + // these aren't the 0days you're looking for
118616 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
118617 +
118618 + // build the initializer expression
118619 + initializer = build_constructor(TREE_TYPE(var), NULL);
118620 +
118621 + // build the initializer stmt
118622 + init_stmt = gimple_build_assign(var, initializer);
118623 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
118624 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
118625 + update_stmt(init_stmt);
118626 +}
118627 +
118628 +static unsigned int handle_function(void)
118629 +{
118630 + basic_block bb;
118631 + unsigned int ret = 0;
118632 + tree var;
118633 + unsigned int i;
118634 +
118635 + // split the first bb where we can put the forced initializers
118636 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
118637 + if (dom_info_available_p(CDI_DOMINATORS))
118638 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
118639 +
118640 + // enumarate all local variables and forcibly initialize our targets
118641 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
118642 + tree type = TREE_TYPE(var);
118643 +
118644 + gcc_assert(DECL_P(var));
118645 + if (!auto_var_in_fn_p(var, current_function_decl))
118646 + continue;
118647 +
118648 + // only care about structure types
118649 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
118650 + continue;
118651 +
118652 + // if the type is of interest, examine the variable
118653 + if (TYPE_USERSPACE(type))
118654 + initialize(var);
118655 + }
118656 +
118657 + return ret;
118658 +}
118659 +
118660 +#if BUILDING_GCC_VERSION >= 4009
118661 +static const struct pass_data structleak_pass_data = {
118662 +#else
118663 +static struct gimple_opt_pass structleak_pass = {
118664 + .pass = {
118665 +#endif
118666 + .type = GIMPLE_PASS,
118667 + .name = "structleak",
118668 +#if BUILDING_GCC_VERSION >= 4008
118669 + .optinfo_flags = OPTGROUP_NONE,
118670 +#endif
118671 +#if BUILDING_GCC_VERSION >= 4009
118672 + .has_gate = false,
118673 + .has_execute = true,
118674 +#else
118675 + .gate = NULL,
118676 + .execute = handle_function,
118677 + .sub = NULL,
118678 + .next = NULL,
118679 + .static_pass_number = 0,
118680 +#endif
118681 + .tv_id = TV_NONE,
118682 + .properties_required = PROP_cfg,
118683 + .properties_provided = 0,
118684 + .properties_destroyed = 0,
118685 + .todo_flags_start = 0,
118686 + .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
118687 +#if BUILDING_GCC_VERSION < 4009
118688 + }
118689 +#endif
118690 +};
118691 +
118692 +#if BUILDING_GCC_VERSION >= 4009
118693 +namespace {
118694 +class structleak_pass : public gimple_opt_pass {
118695 +public:
118696 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
118697 + unsigned int execute() { return handle_function(); }
118698 +};
118699 +}
118700 +#endif
118701 +
118702 +static struct opt_pass *make_structleak_pass(void)
118703 +{
118704 +#if BUILDING_GCC_VERSION >= 4009
118705 + return new structleak_pass();
118706 +#else
118707 + return &structleak_pass.pass;
118708 +#endif
118709 +}
118710 +
118711 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118712 +{
118713 + int i;
118714 + const char * const plugin_name = plugin_info->base_name;
118715 + const int argc = plugin_info->argc;
118716 + const struct plugin_argument * const argv = plugin_info->argv;
118717 + bool enable = true;
118718 + struct register_pass_info structleak_pass_info;
118719 +
118720 + structleak_pass_info.pass = make_structleak_pass();
118721 + structleak_pass_info.reference_pass_name = "ssa";
118722 + structleak_pass_info.ref_pass_instance_number = 1;
118723 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118724 +
118725 + if (!plugin_default_version_check(version, &gcc_version)) {
118726 + error(G_("incompatible gcc/plugin versions"));
118727 + return 1;
118728 + }
118729 +
118730 + if (strcmp(lang_hooks.name, "GNU C")) {
118731 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
118732 + enable = false;
118733 + }
118734 +
118735 + for (i = 0; i < argc; ++i) {
118736 + if (!strcmp(argv[i].key, "disable")) {
118737 + enable = false;
118738 + continue;
118739 + }
118740 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118741 + }
118742 +
118743 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
118744 + if (enable) {
118745 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
118746 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
118747 + }
118748 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
118749 +
118750 + return 0;
118751 +}
118752 diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
118753 index 3dba0a4..97175dc 100644
118754 --- a/tools/lib/lk/Makefile
118755 +++ b/tools/lib/lk/Makefile
118756 @@ -13,7 +13,7 @@ LIB_OBJS += $(OUTPUT)debugfs.o
118757
118758 LIBFILE = liblk.a
118759
118760 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
118761 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
118762 EXTLIBS = -lelf -lpthread -lrt -lm
118763 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
118764 ALL_LDFLAGS = $(LDFLAGS)
118765 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
118766 index 6789d78..4afd019e 100644
118767 --- a/tools/perf/util/include/asm/alternative-asm.h
118768 +++ b/tools/perf/util/include/asm/alternative-asm.h
118769 @@ -5,4 +5,7 @@
118770
118771 #define altinstruction_entry #
118772
118773 + .macro pax_force_retaddr rip=0, reload=0
118774 + .endm
118775 +
118776 #endif
118777 diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
118778 index b003ad7..c0a02f8 100644
118779 --- a/tools/perf/util/include/linux/compiler.h
118780 +++ b/tools/perf/util/include/linux/compiler.h
118781 @@ -27,4 +27,12 @@
118782 # define __weak __attribute__((weak))
118783 #endif
118784
118785 +#ifndef __size_overflow
118786 +# define __size_overflow(...)
118787 +#endif
118788 +
118789 +#ifndef __intentional_overflow
118790 +# define __intentional_overflow(...)
118791 +#endif
118792 +
118793 #endif
118794 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
118795 index 4f588bc..a543c97 100644
118796 --- a/virt/kvm/kvm_main.c
118797 +++ b/virt/kvm/kvm_main.c
118798 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
118799
118800 static cpumask_var_t cpus_hardware_enabled;
118801 static int kvm_usage_count = 0;
118802 -static atomic_t hardware_enable_failed;
118803 +static atomic_unchecked_t hardware_enable_failed;
118804
118805 struct kmem_cache *kvm_vcpu_cache;
118806 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
118807
118808 -static __read_mostly struct preempt_ops kvm_preempt_ops;
118809 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
118810 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
118811 +static struct preempt_ops kvm_preempt_ops = {
118812 + .sched_in = kvm_sched_in,
118813 + .sched_out = kvm_sched_out,
118814 +};
118815
118816 struct dentry *kvm_debugfs_dir;
118817
118818 @@ -751,7 +756,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
118819 /* We can read the guest memory with __xxx_user() later on. */
118820 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
118821 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
118822 - !access_ok(VERIFY_WRITE,
118823 + !access_ok_noprefault(VERIFY_WRITE,
118824 (void __user *)(unsigned long)mem->userspace_addr,
118825 mem->memory_size)))
118826 goto out;
118827 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
118828
118829 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
118830 {
118831 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
118832 + int r;
118833 + unsigned long addr;
118834
118835 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
118836 + addr = gfn_to_hva(kvm, gfn);
118837 + if (kvm_is_error_hva(addr))
118838 + return -EFAULT;
118839 + r = __clear_user((void __user *)addr + offset, len);
118840 + if (r)
118841 + return -EFAULT;
118842 + mark_page_dirty(kvm, gfn);
118843 + return 0;
118844 }
118845 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
118846
118847 @@ -1872,7 +1885,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
118848 return 0;
118849 }
118850
118851 -static struct file_operations kvm_vcpu_fops = {
118852 +static file_operations_no_const kvm_vcpu_fops __read_only = {
118853 .release = kvm_vcpu_release,
118854 .unlocked_ioctl = kvm_vcpu_ioctl,
118855 #ifdef CONFIG_COMPAT
118856 @@ -2532,7 +2545,7 @@ out:
118857 }
118858 #endif
118859
118860 -static struct file_operations kvm_vm_fops = {
118861 +static file_operations_no_const kvm_vm_fops __read_only = {
118862 .release = kvm_vm_release,
118863 .unlocked_ioctl = kvm_vm_ioctl,
118864 #ifdef CONFIG_COMPAT
118865 @@ -2632,7 +2645,7 @@ out:
118866 return r;
118867 }
118868
118869 -static struct file_operations kvm_chardev_ops = {
118870 +static file_operations_no_const kvm_chardev_ops __read_only = {
118871 .unlocked_ioctl = kvm_dev_ioctl,
118872 .compat_ioctl = kvm_dev_ioctl,
118873 .llseek = noop_llseek,
118874 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
118875
118876 if (r) {
118877 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
118878 - atomic_inc(&hardware_enable_failed);
118879 + atomic_inc_unchecked(&hardware_enable_failed);
118880 printk(KERN_INFO "kvm: enabling virtualization on "
118881 "CPU%d failed\n", cpu);
118882 }
118883 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
118884
118885 kvm_usage_count++;
118886 if (kvm_usage_count == 1) {
118887 - atomic_set(&hardware_enable_failed, 0);
118888 + atomic_set_unchecked(&hardware_enable_failed, 0);
118889 on_each_cpu(hardware_enable_nolock, NULL, 1);
118890
118891 - if (atomic_read(&hardware_enable_failed)) {
118892 + if (atomic_read_unchecked(&hardware_enable_failed)) {
118893 hardware_disable_all_nolock();
118894 r = -EBUSY;
118895 }
118896 @@ -3148,7 +3161,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
118897 kvm_arch_vcpu_put(vcpu);
118898 }
118899
118900 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
118901 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
118902 struct module *module)
118903 {
118904 int r;
118905 @@ -3195,7 +3208,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
118906 if (!vcpu_align)
118907 vcpu_align = __alignof__(struct kvm_vcpu);
118908 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
118909 - 0, NULL);
118910 + SLAB_USERCOPY, NULL);
118911 if (!kvm_vcpu_cache) {
118912 r = -ENOMEM;
118913 goto out_free_3;
118914 @@ -3205,9 +3218,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
118915 if (r)
118916 goto out_free;
118917
118918 + pax_open_kernel();
118919 kvm_chardev_ops.owner = module;
118920 kvm_vm_fops.owner = module;
118921 kvm_vcpu_fops.owner = module;
118922 + pax_close_kernel();
118923
118924 r = misc_register(&kvm_dev);
118925 if (r) {
118926 @@ -3217,9 +3232,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
118927
118928 register_syscore_ops(&kvm_syscore_ops);
118929
118930 - kvm_preempt_ops.sched_in = kvm_sched_in;
118931 - kvm_preempt_ops.sched_out = kvm_sched_out;
118932 -
118933 r = kvm_init_debug();
118934 if (r) {
118935 printk(KERN_ERR "kvm: create debugfs files failed\n");